GameWindow::GameWindow() : Gosu::Window(1200, 675, false), _am(AssetManager::instance()), _im(InputManager::instance()), _p1(graphics(), L"Player 1", 0x88FF00FF, LH_U, LH_D, RH_E, RH_W), _p2(graphics(), L"Player 2", 0x88FF0000, LH_N, LH_S, LH_L, LH_R), _p3(graphics(), L"Player 3", 0x8800FF00, RH_U, RH_D, LH_E, LH_W), _p4(graphics(), L"Player 4", 0x8800FFFF, RH_N, RH_S, RH_L, RH_R) { setCaption(L"Hello World!"); _ms = _dt = 0; _am.init(this); _im.init(this); // load assets _am.add_image(L"assets/images/ship.png"); _am.add_sound(L"assets/sounds/collect.wav"); // this should be a physics manager b2Vec2 gravity(0.0f, -10.0f); b2World world(gravity); // and this should be a network manager zctx_t* ctx = zctx_new(); listen(EXIT, PRESSED); _p1.warp(400, 150); _p2.warp(800, 150); _p3.warp(400, 550); _p4.warp(800, 550); _tick(); }
ZCountdown::ZCountdown(const ZConfig &el, QObject *parent) : QObject(parent), ZConfigurable(el,this) { _tracker = NULL; _startMsec = ZDateTime::nowMsec_t(); parse(_config); if(_tracker){ connect(_tracker, SIGNAL(timeout()), this, SLOT(_tick())); connect(_tracker, SIGNAL(started()), this, SIGNAL(started())); connect(_tracker, SIGNAL(stopped()), this, SIGNAL(stopped())); } zEvent->registerSignal(this, SIGNAL(started())); zEvent->registerSignal(this, SIGNAL(stopped())); zEvent->registerSignal(this, SIGNAL(tick())); zEvent->registerSignal(this, SIGNAL(timeout())); zEvent->registerSignal(this, SIGNAL(elapsed(qint64))); zEvent->registerSignal(this, SIGNAL(remaining(qint64))); zEvent->registerSlot(this, SLOT(start())); zEvent->registerSlot(this, SLOT(stop())); zEvent->registerSlot(this, SLOT(reset())); }
void GameWindow::update() { _tick(); _im.update(_dt); _p1.update(_dt); _p2.update(_dt); _p3.update(_dt); _p4.update(_dt); }
int ADC::open_first(struct file *filp) { /* get fresh data */ _tick(); /* and schedule regular updates */ hrt_call_every(&_call, _tickrate, _tickrate, _tick_trampoline, this); return 0; }
static void _write_byte(struct sol_flow_node *node, unsigned char byte) { int i; struct segments_ctl_data *mdata = sol_flow_node_get_private_data(node); if (mdata->needs_clear) { _clear(node); mdata->needs_clear = false; } // Unless we set active_low on the data gpio, it expects 1 for the led // to be off, and 0 for on, so we invert the byte here. byte = ~byte; for (i = 0; i < 8; i++) { int val = (byte >> i) & 1; sol_flow_send_boolean_packet(node, SOL_FLOW_NODE_TYPE_CALAMARI_SEGMENTS_CTL__OUT__DATA, val); _tick(node); } _latch(node); }
void FrameAnimation::_tick() { /* Decide which canvas should be updated */ // 30 FPS canvas must be draw once every 2x if (_counter % 2 == 0) _blue_canvas->draw(); // 10 FPS canvas must be draw once every 6x if (_counter % 10 == 0) _red_canvas->draw(); _counter++; _counter = _counter % 60; // Ranges from 0 to 59 // 60 FPS canvas must be draw every time, so we ignore _counter _black_canvas->draw(); // Reset the timer QTimer::singleShot(1000/_max_fps, this, SLOT(_tick())); }
TimeAnimationImproved::TimeAnimationImproved(QWidget* parent) : QWidget(parent) { _counter = 0; _accumulator60 = _accumulator30 = _accumulator10 = 0; _max_fps = 60; _constant_dt = 1000 / _max_fps; _last_time_60fps = _last_time_30fps = _last_time_10fps = QDateTime::currentMSecsSinceEpoch(); _black_canvas = new TimeCanvas((QFrame*)this, Qt::black); _blue_canvas = new TimeCanvas((QFrame*)this, Qt::blue); _red_canvas = new TimeCanvas((QFrame*)this, Qt::red); _black_label = new QLabel(this); _black_label->setText("60 FPS"); _blue_label = new QLabel(this); _blue_label->setText("30 FPS"); _red_label = new QLabel(this); _red_label->setText("10 FPS"); _h_layout = new QGridLayout(this); _h_layout->addWidget(_black_canvas, 0, 0, 1, 1); _h_layout->addWidget(_blue_canvas, 0, 1, 1, 1); _h_layout->addWidget(_red_canvas, 0, 2, 1, 1); _h_layout->addWidget(_black_label, 3, 0, 1, 1); _h_layout->addWidget(_blue_label, 3, 1, 1, 1); _h_layout->addWidget(_red_label, 3, 2, 1, 1); _group_box = new QGroupBox(this); _group_box->setTitle("Time-based Animation Improved"); _group_box->setLayout(_h_layout); _main_layout = new QVBoxLayout(this); _main_layout->addWidget(_group_box); setLayout(_main_layout); // Start timer QTimer::singleShot(1000/_max_fps, this, SLOT(_tick())); }
FrameAnimation::FrameAnimation(QWidget* parent) : QWidget(parent) { _max_fps = 60; _counter = 0; _black_canvas = new FpsCanvas((QFrame*)this); _blue_canvas = new FpsCanvas((QFrame*)this, Qt::blue); _red_canvas = new FpsCanvas((QFrame*)this, Qt::red); _black_label = new QLabel(this); _black_label->setText("60 FPS"); _blue_label = new QLabel(this); _blue_label->setText("30 FPS"); _red_label = new QLabel(this); _red_label->setText("10 FPS"); _h_layout = new QGridLayout(this); _h_layout->addWidget(_black_canvas, 0, 0, 1, 1); _h_layout->addWidget(_blue_canvas, 0, 1, 1, 1); _h_layout->addWidget(_red_canvas, 0, 2, 1, 1); _h_layout->addWidget(_black_label, 3, 0, 1, 1); _h_layout->addWidget(_blue_label, 3, 1, 1, 1); _h_layout->addWidget(_red_label, 3, 2, 1, 1); _group_box = new QGroupBox(this); _group_box->setTitle("Frame-based Animation"); _group_box->setLayout(_h_layout); _main_layout = new QVBoxLayout(this); _main_layout->addWidget(_group_box); setLayout(_main_layout); // Start timer QTimer::singleShot(1000/_max_fps, this, SLOT(_tick())); }
void TimeAnimationImproved::_tick() { /* Decide which canvas should be updated */ qint64 now = QDateTime::currentMSecsSinceEpoch(); // 30 FPS canvas must be draw once every 2x if (_counter % 2 == 0) { // Compute how much time passed since the last update qint64 passed = now - _last_time_30fps; _accumulator30 += passed; while (_accumulator30 >= _constant_dt) { _blue_canvas->move(_constant_dt); _accumulator30 -= _constant_dt; } _blue_canvas->draw(); _last_time_30fps = now; } // 10 FPS canvas must be draw once every 6x if (_counter % 10 == 0) { // Compute how much time passed since the last update qint64 passed = now - _last_time_10fps; _accumulator10 += passed; while (_accumulator10 >= _constant_dt) { _red_canvas->move(_constant_dt); _accumulator10 -= _constant_dt; } _red_canvas->draw(); _last_time_10fps = now; } // 60 FPS canvas must be draw every time, so we ignore _counter { // Compute how much time passed since the last update qint64 passed = now - _last_time_60fps; _accumulator60 += passed; while (_accumulator60 >= _constant_dt) { _black_canvas->move(_constant_dt); _accumulator60 -= _constant_dt; } _black_canvas->draw(); _last_time_60fps = now; } _counter++; _counter = _counter % 60; // Ranges from 0 to 59 // Reset the timer QTimer::singleShot(1000/_max_fps, this, SLOT(_tick())); }