inline void spawn( spawn_type spw, actor<stackless>& sire, match_t func, SpawnHandler h, match_t ctxid = ctxid_nil, link_type type = no_link, std::size_t stack_size = default_stacksize(), seconds_t tmo = seconds_t(GCE_DEFAULT_REQUEST_TIMEOUT_SEC) ) { aid_t aid; sid_t sid = sire.spawn(spw, func, ctxid, stack_size); boost::uint16_t err = 0; sid_t ret_sid = sid_nil; duration_t curr_tmo = tmo; typedef boost::chrono::system_clock clock_t; clock_t::time_point begin_tp = clock_t::now(); match mach(curr_tmo); mach.match_list_.push_back(detail::msg_spawn_ret); sire.recv( boost::bind( &handle_remote_spawn, _1, _2, _3, type, begin_tp, sid, tmo, curr_tmo, spawn_handler_t(h) ), mach ); }
static void my_thr(context& ctx) { mixin_t mix = spawn(ctx); std::size_t size = 10; std::vector<response_t> res_list(size); for (std::size_t i=0; i<size; ++i) { aid_t aid = spawn( mix, boost::bind(&mixin_ut::my_child, _1) ); res_list[i] = request(mix, aid); } for (std::size_t i=0; i<size; ++i) { aid_t aid; do { aid = recv(mix, res_list[i], seconds_t(1)); } while (!aid); } }
/// Brief: Calculates deltaTime, smoothDeltaTime and accumulates the frame time. /// When 1 second has passed the FPS is calculated and saved and counters are reset. /// Before doing any calculations startFrame() calls waitForEndOfFrame in /// order to fix the frame time before starting the next. void GameTimer::startFrame() { waitUntilEndOfFrame(); m_deltaTime = calculateDeltaTime(); m_frameStart = m_getTimeFunc(); if((m_timeAcc) > seconds_t(1.0f)) { m_fps = m_frameAcc; m_timeAcc = seconds_t(0.0f); m_frameAcc = 0; } m_timeAcc += m_deltaTime; ++m_frameAcc; m_smoothDeltaTime = calculateSmoothDeltaTime(); }
GameTimer::seconds_t GameTimer::calculateSmoothDeltaTime() { seconds_t accum = seconds_t(0.0f); for(unsigned int i = 0; i < NUM_SAVED_DELTA_TIMES - 1; ++i) { accum += m_savedDeltaTime[i]; m_savedDeltaTime[i + 1] = m_savedDeltaTime[i]; } accum += m_deltaTime; m_savedDeltaTime[0] = m_deltaTime; return accum / static_cast<seconds_t>(NUM_SAVED_DELTA_TIMES); }
GameTimer::GameTimer() : m_frameStart(), m_deltaTime(), m_smoothDeltaTime(), m_timeAcc(), m_targetDeltaTime(seconds_t(1.0f / 60.0f)), m_fps(), m_frameAcc(), m_getTimeFunc(), m_stallFunc() { for(auto i = 0; i < NUM_SAVED_DELTA_TIMES; ++i) { m_savedDeltaTime[i] = 0; } }
static void test_base() { try { std::size_t echo_num = 100; attributes attrs; attrs.id_ = atom("one"); context ctx1(attrs); attrs.id_ = atom("two"); context ctx2(attrs); mixin_t base1 = spawn(ctx1); mixin_t base2 = spawn(ctx2); gce::bind(base2, "tcp://127.0.0.1:14923"); aid_t echo_aid = spawn( base2, boost::bind( &socket_ut::echo, _1 ), monitored ); wait(base1, boost::chrono::milliseconds(100)); net_option opt; opt.reconn_period_ = seconds_t(1); connect(base1, atom("two"), "tcp://127.0.0.1:14923", false, opt); for (std::size_t i=0; i<echo_num; ++i) { send(base1, echo_aid, atom("echo")); recv(base1, atom("echo")); } send(base1, echo_aid, atom("end")); recv(base2); } catch (std::exception& ex) { std::cerr << "test_base except: " << ex.what() << std::endl; } }