摘要: #pragma once#include struct scope_guard { typedef std::function Fn; Fn action; bool active; scope_guard(Fn action) : action(action), active(true) {} void dismiss() { active = false; } ~scope_guard () { if(active) action(); }};test:#include #include using namespace std;#include "scope_gua... 阅读全文
posted @ 2013-05-28 22:16 aj3423 阅读(392) 评论(0) 推荐(0) 编辑
摘要: 用来限制 fps#pragma once#include struct fps_limit { int previous_time; int tpf_limit; int tpf; fps_limit(int fps = 60) : previous_time(GetTickCount()), tpf(0) { limit_fps(fps); } void reset() { previous_time = GetTickCount(), tpf = 0; tpf_limit = 60; } void limit_fps(int fps) { tpf_limit = (int)(10... 阅读全文
posted @ 2013-05-28 22:00 aj3423 阅读(808) 评论(0) 推荐(0) 编辑
摘要: #pragma once#include #include using namespace std;templatestruct signal;template struct signal { typedef int key_t; // typedef function func_t; key_t nextkey_t; map connections; key_t operator+=(func_t f) { key_t k = nextkey_t++; connections[k] = f; return k; } void operator-=(key_t k){ connecti... 阅读全文
posted @ 2013-05-28 21:22 aj3423 阅读(290) 评论(0) 推荐(0) 编辑