void BBWin8Game::Run(){ if( CFG_WIN8_SCREEN_ORIENTATION & 1 ){ _deviceRotation=0; }else if( CFG_WIN8_SCREEN_ORIENTATION & 2 ){ _deviceRotation=1; }else if( CFG_WIN8_SCREEN_ORIENTATION & 4 ){ _deviceRotation=2; }else if( CFG_WIN8_SCREEN_ORIENTATION & 8 ){ _deviceRotation=3; }else{ _deviceRotation=0; } ValidateOrientation(); StartGame(); for(;;){ if( _updateRate==60 ){ PollEvents(); UpdateGame(); RenderGame(); continue; } if( !_updateRate || _suspended ){ RenderGame(); WaitEvents(); continue; } double time=GetTime(); if( time<_nextUpdate ){ Sleep( _nextUpdate-time ); continue; } PollEvents(); int updates=0; for(;;){ _nextUpdate+=_updatePeriod; UpdateGame(); if( !_updateRate ) break; if( _nextUpdate>GetTime() ){ break; } if( ++updates==8 ) break; } RenderGame(); if( updates==8 ) _nextUpdate=GetTime(); } }
void GLFramework::Run() { m_cShaderProgram = new GLShaderProgram(); LOG_DBG("ShaderProgram=%d\n", m_cShaderProgram->GetProgram()); m_cShaderProgram->LinkProgram(); LOG_DBG("Link Shader Program success.\n"); m_cShaderProgram->RegisterVertexArray(vertices, sizeof(vertices), indices, sizeof(indices)); m_cTexture1 = new GLTexture(); m_cTexture1->GenerateMipMap("container.jpg", GL_REPEAT); m_cTexture2 = new GLTexture(); m_cTexture2->GenerateMipMap("awesomeface.png", GL_MIRRORED_REPEAT); // Game loop while (!WindowShouldClose()) { // Check if any events have been activiated (key pressed, mouse moved etc.) and call corresponding response functions PollEvents(); // Render Render(); // Swap the screen buffers SwapBuffers(); } m_cShaderProgram->UnregisterVertexArray(); }
bool FirewirePort::WriteAllBoards(void) { if (!handle) { outStr << "WriteAllBoards: handle for port " << PortNum << " is NULL" << std::endl; return false; } bool allOK = true; bool noneWritten = true; for (int board = 0; board < max_board; board++) { if (BoardList[board]) { quadlet_t *buf = BoardList[board]->GetWriteBuffer(); unsigned int numBytes = BoardList[board]->GetWriteNumBytes(); unsigned int numQuads = numBytes/4; // Currently (Rev 1 firmware), the last quadlet (Status/Control register) // is done as a separate quadlet write. bool ret = WriteBlock(board, 0, buf, numBytes-4); if (ret) noneWritten = false; else allOK = false; quadlet_t ctrl = buf[numQuads-1]; // Get last quadlet bool ret2 = true; if (ctrl) { // if anything non-zero, write it ret2 = WriteQuadlet(board, 0, ctrl); if (ret2) noneWritten = false; else allOK = false; } // SetWriteValid clears the buffer if the write was valid BoardList[board]->SetWriteValid(ret&&ret2); } } if (noneWritten) PollEvents(); return allOK; }
bool FirewirePort::ReadAllBoards(void) { if (Protocol_ == FirewirePort::PROTOCOL_BC_QRW) { return ReadAllBoardsBroadcast(); } if (!handle) { outStr << "ReadAllBoards: handle for port " << PortNum << " is NULL" << std::endl; return false; } bool allOK = true; bool noneRead = true; for (int board = 0; board < max_board; board++) { if (BoardList[board]) { bool ret = ReadBlock(board, 0, BoardList[board]->GetReadBuffer(), BoardList[board]->GetReadNumBytes()); if (ret) { noneRead = false; } else { allOK = false; } BoardList[board]->SetReadValid(ret); if (!ret) { outStr << "ReadAllBoards: read failed on port " << PortNum << ", board " << board << std::endl; } } } if (noneRead) { PollEvents(); } return allOK; }
void Viewer::PickModel() { Gui::Fixed *f = new Gui::Fixed(); f->SetSizeRequest(Gui::Screen::GetWidth()*0.5f, Gui::Screen::GetHeight()*0.5); Gui::Screen::AddBaseWidget(f, Gui::Screen::GetWidth()*0.25f, Gui::Screen::GetHeight()*0.25f); f->Add(new Gui::Label("Enter the name of the model you want to view:"), 0, 0); Gui::Label *errormsg = new Gui::Label(""); f->Add(errormsg, 0, 64); Gui::TextEntry *entry = new Gui::TextEntry(); entry->onKeyPress.connect(sigc::bind(sigc::mem_fun(this, &Viewer::TryModel), entry, errormsg)); entry->Show(); f->Add(entry, 0, 32); m_model = 0; while (!m_model) { this->Hide(); f->ShowAll(); PollEvents(); Render::PrepareFrame(); glClearColor(0,0,0,0); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); Render::PostProcess(); Gui::Draw(); glError(); Render::SwapBuffers(); } Gui::Screen::RemoveBaseWidget(f); delete f; this->Show(); }
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR pCmdLine, int nCmdShow) { g_hInstance = hInstance; InitializeContext(); InitializeWindow(); g_VkSwapchain.Initialize(); g_VkSwapchain.InitializeSwapchain(kScreenWidth, kScreenHeight, false); InitializeRenderSettings(); while (true) { PollEvents(); if (g_CloseRequest) { break; } DrawScene(); } DestroyRenderSettings(); g_VkSwapchain.Destroy(); DestroyWindow(); DestroyContext(); return 0; }
/** ** @brief Update load progress. */ void UpdateLoadProgress() { if (Video.Depth && IsGameFontReady() && GetGameFont().IsLoaded()) { UpdateLoadingBar(); } PollEvents(); }
void moIODeviceManager::Update() { PollEvents(); for(MOuint i = 0; i < m_IODevices.Count(); i++) { moIODevice* piodevice = m_IODevices.Get(i); if(piodevice!=NULL) piodevice->Update(Events); } }
bool MainMenu::Loop() { //Handle keypresses if( PollEvents() == false ) return false; UpdateDisplay(); return true; }
bool HeartsHelp::Loop() { //Handle keypresses if( PollEvents() == false ) return false; UpdateDisplay(); return true; }
bool Game::Loop() { //Handle keypresses if( PollEvents() == false ) return false; //Update screen UpdateDisplay(); SDL_Delay(30); return true; }
/** ** Show load progress. ** ** @param fmt printf format string. */ void ShowLoadProgress(const char *fmt, ...) { static unsigned int lastProgressUpdate = SDL_GetTicks(); if (SDL_GetTicks() < lastProgressUpdate + 16) { // Only show progress updates every c. 1/60th of a second, otherwise we're waiting for the screen too much return; } lastProgressUpdate = SDL_GetTicks(); UpdateLoadProgress(); va_list va; char temp[4096]; va_start(va, fmt); vsnprintf(temp, sizeof(temp) - 1, fmt, va); temp[sizeof(temp) - 1] = '\0'; va_end(va); if (Video.Depth && IsGameFontReady() && GetGameFont().IsLoaded()) { // Remove non printable chars for (unsigned char *s = (unsigned char *)temp; *s; ++s) { if (*s < 32) { *s = ' '; } } //Wyrmgus start // Video.FillRectangle(ColorBlack, 5, Video.Height - 18, Video.Width - 10, 18); if (loadingBackground == nullptr) { Video.FillRectangle(ColorBlack, 0, Video.Height - 18, Video.Width, 18); } //Wyrmgus end CLabel(GetGameFont()).DrawCentered(Video.Width / 2, Video.Height - 16, temp); //Wyrmgus start // InvalidateArea(5, Video.Height - 18, Video.Width - 10, 18); if (loadingBackground == nullptr) { InvalidateArea(0, Video.Height - 18, Video.Width, 18); } else { InvalidateArea(0, 0, Video.Width, Video.Height); } //Wyrmgus end RealizeVideoMemory(); } else { DebugPrint("!!!!%s\n" _C_ temp); } PollEvents(); }
void GLFramework::Run() { // Game loop while (!WindowShouldClose()) { // Check if any events have been activiated (key pressed, mouse moved etc.) and call corresponding response functions PollEvents(); // Render Render(); // Swap the screen buffers SwapBuffers(); } }
void AhrsPoll() { if(programReceive) { AhrsProgramReceive(); programReceive = false; } PollEvents(); if (PIOS_SPI_Busy(PIOS_SPI_OP) != 0) { //Everything is working correctly return; } txPacket.status.kickStarts++; //comms have broken down - try kick starting it. txPacket.command = COMMS_NULL; //we must send something so default to null PIOS_SPI_TransferBlock(PIOS_SPI_OP, (uint8_t *) & txPacket, (uint8_t *) & rxPacket, sizeof(CommsDataPacket), &CommsCallback); }
bool Game::Loop() { //Handle keypresses if( PollEvents() == false ) return false; //Check for state changes if( CheckStateConditions() == false ) return false; //Update screen UpdateDisplay(); SDL_Delay(30); return true; }
// Run void Game::Run() { while (window.isOpen()) { // Get the delta time float deltatime = clock.getElapsedTime().asSeconds(); clock.restart(); // Update Update(deltatime); // Draw Draw(deltatime); // Poll Events PollEvents(); // Remove any entities that are dead. entities.RemoveDead(); } }
bool InitializeWindow() { { WNDCLASSEXW wc; ZeroMemory(&wc, sizeof(wc)); wc.cbSize = sizeof(wc); wc.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC; wc.lpfnWndProc = (WNDPROC)windowProc; wc.hInstance = g_hInstance; wc.hIcon = LoadIcon(nullptr, IDI_APPLICATION); wc.hCursor = LoadCursor(nullptr, IDC_ARROW); wc.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH); wc.lpszClassName = kClassName; if (!RegisterClassEx(&wc)) { return false; } RECT wr = { 0, 0, kScreenWidth, kScreenHeight }; AdjustWindowRect(&wr, WS_OVERLAPPEDWINDOW, FALSE); g_hWnd = CreateWindowEx(0, kClassName, kAppName, WS_OVERLAPPEDWINDOW | WS_VISIBLE | WS_SYSMENU, 100, 100, // window x,y wr.right - wr.left, // width wr.bottom - wr.top, // height nullptr, // handle to parent nullptr, // handle to menu g_hInstance, // hInstance nullptr); if (!g_hWnd) { return false; } } PollEvents(); return true; }
bool FirewirePort::ReadAllBoards(void) { if (!handle) { outStr << "ReadAllBoards: handle for port " << PortNum << " is NULL" << std::endl; return false; } bool allOK = true; bool noneRead = true; for (int board = 0; board < max_board; board++) { if (BoardList[board]) { bool ret = ReadBlock(board, 0, BoardList[board]->GetReadBuffer(), BoardList[board]->GetReadNumBytes()); if (ret) noneRead = false; else allOK = false; BoardList[board]->SetReadValid(ret); } } if (noneRead) PollEvents(); return allOK; }
void Scene::RenderScene() { // Poll input PollEvents(); // Clear screen glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Update Matrices CreateProjectionMatrix(); CreateViewMatrix(); // Set uniforms glUniformMatrix4fv(glGetUniformLocation(shader->Program(), "viewMatrix"), 1, false, glm::value_ptr(viewMatrix)); glUniformMatrix4fv(glGetUniformLocation(shader->Program(), "projMatrix"), 1, false, glm::value_ptr(projMatrix)); // Draw dino modelMatrix = glm::translate(glm::mat4(), glm::vec3(50.0f, 00.0f, 0.0f)); modelMatrix = glm::rotate(modelMatrix, glm::radians(90.0f), glm::vec3(0, -1, 0)); modelMatrix = glm::scale(modelMatrix, glm::vec3(20.0f, 20.0f, 20.0f)); glUniformMatrix4fv(glGetUniformLocation(shader->Program(), "modelMatrix"), 1, false, glm::value_ptr(modelMatrix)); (*meshes)["dino"]->Draw(); // Draw box modelMatrix = glm::translate(glm::mat4(), glm::vec3(0.0f, 0.0f, 0.0f)); modelMatrix = glm::scale(modelMatrix, glm::vec3(10.0f, 10.0f, 10.0f)); glUniformMatrix4fv(glGetUniformLocation(shader->Program(), "modelMatrix"), 1, false, glm::value_ptr(modelMatrix)); (*meshes)["box"]->Draw(); // Draw death star modelMatrix = glm::translate(glm::mat4(), glm::vec3(0.0f, 750.0f, 0.0f)); modelMatrix = glm::scale(modelMatrix, glm::vec3(0.5f, 0.5f, 0.5f)); glUniformMatrix4fv(glGetUniformLocation(shader->Program(), "modelMatrix"), 1, false, glm::value_ptr(modelMatrix)); (*meshes)["deathstar"]->Draw(); // Swap buffers SwapBuffers(); }
void AhrsSendObjects(void) { static bool oldLink = false; PollEvents(); if (oldLink != linkOk) { oldLink = linkOk; if (linkOk) { for (int ct = 0; ct < MAX_AHRS_OBJECTS; ct++) { AhrsObjHandle hdl = AhrsFromIndex(ct); if (!hdl) { //paranoid - shouldn't ever happen continue; } AhrsSharedData data; UAVObjGetData(hdl->uavHandle, &data); AhrsSetData(hdl, &data); SetObjectDirty(ct); //force even unchanged data to be sent } } } FillObjectPacket(); SendPacket(); }
void Viewer::MainLoop() { Uint32 lastTurd = SDL_GetTicks(); Uint32 t = SDL_GetTicks(); int numFrames = 0; Uint32 lastFpsReadout = SDL_GetTicks(); g_campos = vector3f(0.0f, 0.0f, m_cmesh->GetBoundingRadius()); g_camorient = matrix4x4f::Identity(); matrix4x4f modelRot = matrix4x4f::Identity(); printf("Geom tree build in %dms\n", SDL_GetTicks() - t); Render::State::SetZnearZfar(1.0f, 10000.0f); for (;;) { PollEvents(); Render::PrepareFrame(); if (g_keyState[SDLK_LSHIFT] || g_keyState[SDLK_RSHIFT]) { if (g_keyState[SDLK_UP]) g_camorient = g_camorient * matrix4x4f::RotateXMatrix(g_frameTime); if (g_keyState[SDLK_DOWN]) g_camorient = g_camorient * matrix4x4f::RotateXMatrix(-g_frameTime); if (g_keyState[SDLK_LEFT]) g_camorient = g_camorient * matrix4x4f::RotateYMatrix(-g_frameTime); if (g_keyState[SDLK_RIGHT]) g_camorient = g_camorient * matrix4x4f::RotateYMatrix(g_frameTime); if (g_mouseButton[3]) { float rx = 0.01f*g_mouseMotion[1]; float ry = 0.01f*g_mouseMotion[0]; g_camorient = g_camorient * matrix4x4f::RotateXMatrix(rx); g_camorient = g_camorient * matrix4x4f::RotateYMatrix(ry); if (g_mouseButton[1]) { g_campos = g_campos - g_camorient * vector3f(0.0f,0.0f,1.0f) * 0.01 * m_model->GetDrawClipRadius(); } } } else { if (g_keyState[SDLK_UP]) modelRot = modelRot * matrix4x4f::RotateXMatrix(g_frameTime); if (g_keyState[SDLK_DOWN]) modelRot = modelRot * matrix4x4f::RotateXMatrix(-g_frameTime); if (g_keyState[SDLK_LEFT]) modelRot = modelRot * matrix4x4f::RotateYMatrix(-g_frameTime); if (g_keyState[SDLK_RIGHT]) modelRot = modelRot * matrix4x4f::RotateYMatrix(g_frameTime); if (g_mouseButton[3]) { float rx = 0.01f*g_mouseMotion[1]; float ry = 0.01f*g_mouseMotion[0]; modelRot = modelRot * matrix4x4f::RotateXMatrix(rx); modelRot = modelRot * matrix4x4f::RotateYMatrix(ry); } } if (g_keyState[SDLK_EQUALS]) g_campos = g_campos - g_camorient * vector3f(0.0f,0.0f,1.0f); if (g_keyState[SDLK_MINUS]) g_campos = g_campos + g_camorient * vector3f(0.0f,0.0f,1.0f); if (g_keyState[SDLK_PAGEUP]) g_campos = g_campos - g_camorient * vector3f(0.0f,0.0f,1.0f); if (g_keyState[SDLK_PAGEDOWN]) g_campos = g_campos + g_camorient * vector3f(0.0f,0.0f,1.0f); // geom->MoveTo(modelRot, vector3d(0.0,0.0,0.0)); glMatrixMode(GL_PROJECTION); glLoadIdentity(); float fracH = g_height / (float)g_width; glFrustum(-1, 1, -fracH, fracH, 1.0f, 10000.0f); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glClearColor(0,0,0,0); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); SetSbreParams(); int beforeDrawTriStats = LmrModelGetStatsTris(); if (g_renderType == 0) { glPushAttrib(GL_ALL_ATTRIB_BITS); matrix4x4f m = g_camorient.InverseOf() * matrix4x4f::Translation(-g_campos) * modelRot.InverseOf(); if (g_doBenchmark) { for (int i=0; i<1000; i++) m_model->Render(m, ¶ms); } else { m_model->Render(m, ¶ms); } glPopAttrib(); } else if (g_renderType == 1) { glPushMatrix(); matrix4x4f m = g_camorient.InverseOf() * matrix4x4f::Translation(-g_campos) * modelRot.InverseOf(); glMultMatrixf(&m[0]); render_coll_mesh(m_cmesh); glPopMatrix(); } else { matrix4x4f tran = modelRot * g_camorient;//.InverseOf(); vector3d forward = tran * vector3d(0.0,0.0,-1.0); vector3d up = tran * vector3d(0.0,1.0,0.0); raytraceCollMesh(modelRot * g_campos, up, forward, m_space); } Render::State::UseProgram(0); Render::UnbindAllBuffers(); { char buf[128]; Aabb aabb = m_cmesh->GetAabb(); snprintf(buf, sizeof(buf), "%d triangles, collision mesh size: %.1fx%.1fx%.1f (radius %.1f)", (g_renderType == 0 ? LmrModelGetStatsTris() - beforeDrawTriStats : m_cmesh->m_numTris), aabb.max.x-aabb.min.x, aabb.max.y-aabb.min.y, aabb.max.z-aabb.min.z, aabb.GetBoundingRadius()); m_trisReadout->SetText(buf); } Render::PostProcess(); Gui::Draw(); glError(); Render::SwapBuffers(); numFrames++; g_frameTime = (SDL_GetTicks() - lastTurd) * 0.001f; lastTurd = SDL_GetTicks(); if (SDL_GetTicks() - lastFpsReadout > 1000) { int numTris = LmrModelGetStatsTris(); LmrModelClearStatsTris(); printf("%d fps, %.3f Million tris/sec\n", numFrames, numTris/1000000.0f); numFrames = 0; lastFpsReadout = SDL_GetTicks(); } //space->Collide(onCollision); } }
bool FirewirePort::WriteAllBoardsBroadcast(void) { // check hanle if (!handle) { outStr << "WriteAllBoardsBroadcast: handle for port " << PortNum << " is NULL" << std::endl; return false; } // sanity check vars bool allOK = true; bool noneWritten = true; // loop 1: broadcast write block // construct broadcast write buffer const int numOfChannel = 4; quadlet_t bcBuffer[numOfChannel * MAX_NODES]; memset(bcBuffer, 0, sizeof(bcBuffer)); int bcBufferOffset = 0; // the offset for new data to be stored in bcBuffer (bytes) int numOfBoards = 0; for (int board = 0; board < max_board; board++) { if (BoardList[board]) { numOfBoards++; quadlet_t *buf = BoardList[board]->GetWriteBuffer(); unsigned int numBytes = BoardList[board]->GetWriteNumBytes(); memcpy(bcBuffer + bcBufferOffset/4, buf, numBytes-4); // -4 for ctrl offset // bcBufferOffset equals total numBytes to write, when the loop ends bcBufferOffset = bcBufferOffset + numBytes - 4; } } // now broadcast out the huge packet bool ret = true; #if FAKEBC ret = !raw1394_write(handle, baseNodeId, 0xffffffff0000, bcBufferOffset, bcBuffer); #else ret = WriteBlockBroadcast(0xffffff000000, // now the address is hardcoded bcBuffer, bcBufferOffset); #endif // loop 2: send out control quadlet if necessary for (int board = 0; board < max_board; board++) { if (BoardList[board]) { quadlet_t *buf = BoardList[board]->GetWriteBuffer(); unsigned int numBytes = BoardList[board]->GetWriteNumBytes(); unsigned int numQuads = numBytes/4; quadlet_t ctrl = buf[numQuads-1]; // Get last quedlet bool ret2 = true; if (ctrl) { // if anything non-zero, write it ret2 = WriteQuadlet(board, 0x00, ctrl); if (ret2) noneWritten = false; else allOK = false; } // SetWriteValid clears the buffer if the write was valid BoardList[board]->SetWriteValid(ret&&ret2); } } // pullEvents if (noneWritten) { PollEvents(); } // return return allOK; }
bool FirewirePort::ReadAllBoardsBroadcast(void) { if (!handle || !handle_bc) { outStr << "ReadAllBoardsBroadcast: handle for port " << PortNum << " is NULL" << std::endl; return false; } bool ret; bool allOK = true; bool noneRead = true; int hub_node_id = GetNodeId(HubBoard_->BoardId); // ZC: NOT USE PLACEHOLDER //--- send out broadcast read request ----- #if 0 quadlet_t debugData; nodeaddr_t debugAddr = 0x03; bool retdebug = !raw1394_read(handle, baseNodeId + hub_node_id, // boardid 7 debugAddr, // read from hub addr 4, // read all 16 boards &debugData); if (!retdebug) { raw1394_errcode_t ecode = raw1394_get_errcode(handle); std::cerr << "debug read ecode = " << ecode << " to_errno = " << raw1394_errcode_to_errno(ecode) << " " << strerror(raw1394_errcode_to_errno(ecode)) << std::endl; } #endif // sequence number from 16 bits 0 to 65535 ReadSequence_++; if (ReadSequence_ == 65536) { ReadSequence_ = 1; } quadlet_t bcReqData = bswap_32((ReadSequence_ << 16) + BoardExistMask_); nodeaddr_t bcReqAddr = 0xffffffff000F; // special address to trigger broadcast read #if FAKEBC ret = !raw1394_write(handle, baseNodeId, bcReqAddr, 4, &bcReqData); if (!ret) { raw1394_errcode_t ecode = raw1394_get_errcode(handle); std::cerr << "bbbbbbb fake ecode = " << ecode << " to_errno = " << raw1394_errcode_to_errno(ecode) << " " << strerror(raw1394_errcode_to_errno(ecode)) << std::endl; } #else WriteQuadletBroadcast(bcReqAddr, bcReqData); #endif // // Manual sleep 50 us timeval start, check; gettimeofday(&start, NULL); while(true) { gettimeofday(&check, NULL); if (((check.tv_sec-start.tv_sec)*1000000 + check.tv_usec-start.tv_usec) > (5.0*NumOfNodes_+10.0)) { break; } } // initialize max buffer const int hubReadSize = 272; // 16 * 17 = 272 max quadlet_t hubReadBuffer[hubReadSize]; memset(hubReadBuffer, 0, sizeof(hubReadBuffer)); // raw1394_read 0 = SUCCESS, -1 = FAIL, flip return value ret = !raw1394_read(handle, baseNodeId + hub_node_id, 0x1000, // read from hub addr 272 * 4, // read all 16 boards hubReadBuffer); // ----- DEBUG ----------- static int raw1394readCounter = 0; if (!ret) { raw1394readCounter++; raw1394_errcode_t ecode = raw1394_get_errcode(handle); std::cerr << "ecode = " << ecode << " to_errno = " << raw1394_errcode_to_errno(ecode) << " " << strerror(raw1394_errcode_to_errno(ecode)) << std::endl; std::cerr << "raw1394_read failed " << raw1394readCounter << ": " << strerror(errno) << std::endl; } // ----------------------- for (int board = 0; board < max_board; board++) { if (BoardList[board]) { const int readSize = 17; // 1 seq + 16 data, unit quadlet quadlet_t readBuffer[readSize]; memcpy(readBuffer, &(hubReadBuffer[readSize * board + 0]), readSize * 4); unsigned int seq = (bswap_32(readBuffer[0]) >> 16); static int errorcounter = 0; if (ReadSequence_ != seq) { errorcounter++; outStr << "errorcounter = " << errorcounter << std::endl; outStr << std::hex << seq << " " << ReadSequence_ << " " << (int)board << std::endl; } memcpy(BoardList[board]->GetReadBuffer(), &(readBuffer[1]), (readSize-1) * 4); if (ret) noneRead = false; else allOK = false; BoardList[board]->SetReadValid(ret); } } if (noneRead) { PollEvents(); } return allOK; }
void BBWin8Game::Run(){ DisplayOrientations prefs=DisplayOrientations::None; if( CFG_WIN8_SCREEN_ORIENTATION & 1 ) prefs=prefs|DisplayOrientations::Portrait; if( CFG_WIN8_SCREEN_ORIENTATION & 2 ) prefs=prefs|DisplayOrientations::Landscape; if( CFG_WIN8_SCREEN_ORIENTATION & 4 ) prefs=prefs|DisplayOrientations::PortraitFlipped; if( CFG_WIN8_SCREEN_ORIENTATION & 8 ) prefs=prefs|DisplayOrientations::LandscapeFlipped; if( prefs==DisplayOrientations::None ) prefs=DisplayProperties::CurrentOrientation; Windows::Graphics::Display::DisplayProperties::AutoRotationPreferences=prefs; int orientation; for( orientation=0;orientation<4 && !(CFG_WIN8_SCREEN_ORIENTATION & (1<<orientation));++orientation ) {} if( orientation==4 ) orientation=DeviceOrientation(); #if WINDOWS_8 _deviceRotation=(orientation-1)&3; #elif WINDOWS_PHONE_8 _deviceRotation=orientation; #endif ValidateOrientation(); StartGame(); for(;;){ if( _updateRate==60 ){ PollEvents(); UpdateGame(); RenderGame(); continue; } if( !_updateRate || _suspended ){ RenderGame(); WaitEvents(); continue; } double time=GetTime(); if( time<_nextUpdate ){ Sleep( _nextUpdate-time ); continue; } PollEvents(); int updates=0; for(;;){ _nextUpdate+=_updatePeriod; UpdateGame(); if( !_updateRate ) break; if( _nextUpdate>GetTime() ){ break; } if( ++updates==8 ) break; } RenderGame(); if( updates==8 ) _nextUpdate=GetTime(); } }
// General functions int Game::Run( int p_Argc, char ** p_Argv ) { // Load the game // No errors? Let's run the game loop if( Load( ) ) { // Create a game timer LDE::Timer timer; timer.Start( ); // Loop until we break it m_Running = true; while( m_Running ) { // Get the delta time timer.Stop( ); timer.DeltaLock( 256.0f ); double deltaTime = timer.GetTime( ); //std::cout << 1.0f / deltaTime << " FPS." << std::endl; // Sleep some time if the delta time is day too much /*const float fpslock = 1000.0; if( (1.0f / deltaTime ) > fpslock ) { float time = 1.0f / deltaTime; Sleep( 0 ); }*/ timer.Start( ); // Poll events PollEvents( ); // Update everything if( Update( deltaTime ) != 0 ) { // Break the game loop break; } //Render everything in the window Render( ); } } // We couldn't load the game else { // Wait for any input to close the program. std::cin.get( ); } // Unload everything Unload( ); return 0; }