void main_loop() { bool quit = false; while (!quit) { SDL_Event e; while (SDL_PollEvent(&e) != 0) { if (e.type == SDL_QUIT) { quit = true; } } const double freq = double(bx::getHPFrequency()); const double toMs = 1000.0 / freq; static int64_t totalMeasureTime = 0; int64_t measureTimeLast = bx::getHPCounter(); transform_system.update(); solid_quads.draw(transform_system, renderer); totalMeasureTime = ((bx::getHPCounter() - measureTimeLast) * 0.01 + totalMeasureTime * 0.99); renderer.begin_frame(); renderer.render(); bgfx::dbgTextPrintf(1, 1, 0x0f, "frame time: %f[ms]", 16.0f); bgfx::dbgTextPrintf(1, 2, 0x0f, "transform & draw time: %7.3f[ms]", double(totalMeasureTime)*toMs); bgfx::dbgTextPrintf(1, 3, 0x0f, "total entities: %d", entity_system.count()); renderer.end_frame(); T::main_loop(0.016f); SDL_Delay(16); } shutdown(); }
virtual void render() { copy_to_inner(); inner->render(); ++framesNotPrinted; int gfps = enabler->calculated_gfps; if (gfps == 0) gfps = 1; // send a frame roughly every 128 mibiseconds (1 second = 1024 mibiseconds) if ((framesNotPrinted * 1024) / gfps <= 128) return; client_pool::lock lock(clients); if (!clients.has_clients()) return; framesNotPrinted = 0; std::stringstream frame; frame << gps->dimx << ' ' << gps->dimy << " 0 0 " << gps->dimx << ' ' << gps->dimy << '\n'; unsigned char * sc_ = gps->screen; for (int y = 0; y < gps->dimy; ++y) { unsigned char * sc = sc_; for (int x = 0; x < gps->dimx; ++x) { unsigned char ch = sc[0]; unsigned char bold = (sc[3] != 0) * 8; unsigned char translate[] = { 0, 4, 2, 6, 1, 5, 3, 7, 8, 12, 10, 14, 9, 13, 11, 15 }; unsigned char fg = translate[(sc[1] + bold) % 16]; unsigned char bg = translate[sc[2] % 16]*16; frame.put(ch); frame.put(fg+bg); sc += 4*gps->dimy; } sc_ += 4; } clients.broadcast(frame.str()); }
//--Implementations void render() { //abort execution here if we are to stop running if(!keepRunning) { cleanUp(); exit(0); } //call renderer's render simRenderer.render(); }