void PlatformDesktop::SingleLoop() { if( mEventRecorder ) mEventRecorder->StartOfFrame( GetTime() ); HandleEvents(); poro_assert( GetApplication() ); poro_assert( mGraphics ); types::Double32 dt = mOneFrameShouldLast; if( mFixedTimeStep == false ) { static types::Double32 last_time_update_called = 0; dt = (types::Double32)( GetUpTime() - last_time_update_called ); last_time_update_called = GetUpTime(); } GetApplication()->Update( (types::Float32)(dt) ); mGraphics->BeginRendering(); GetApplication()->Draw(mGraphics); mGraphics->EndRendering(); if( mEventRecorder ) mEventRecorder->EndOfFrame( GetTime() ); }
void PlatformDesktop::StartMainLoop() { mRunning = true; // just render the screen black before initializing the application if( mGraphics && true ) { mGraphics->BeginRendering(); mGraphics->EndRendering(); } if( mApplication ) mApplication->Init(); types::Double32 mFrameCountLastTime = 0; int mFrameRateUpdateCounter = 0; types::Double32 mProcessorRate = 0; while( mRunning ) { const types::Double32 time_before = GetUpTime(); SingleLoop(); if( mApplication && mApplication->IsDead() == true ) mRunning = false; const types::Double32 time_after = GetUpTime(); const types::Double32 elapsed_time = ( time_after - time_before ); if( elapsed_time < mOneFrameShouldLast ) Sleep( mOneFrameShouldLast - elapsed_time ); while( ( GetUpTime() - time_before ) < mOneFrameShouldLast ) { Sleep( 0 ); } // frame-rate check mProcessorRate += ( elapsed_time / mOneFrameShouldLast ); mFrameCount++; mFrameRateUpdateCounter++; mLastFrameExecutionTime = time_after - time_before; if( ( GetUpTime() - mFrameCountLastTime ) >= 1.0 ) { mFrameCountLastTime = GetUpTime(); mFrameRate = mFrameRateUpdateCounter; mFrameRateUpdateCounter = 0; if( mPrintFramerate ) std::cout << "Fps: " << mFrameRate << " (CPU): " << ( mProcessorRate / (types::Double32)mFrameRate ) * 100.f << "%" << std::endl; mProcessorRate = 0; } } if( mApplication ) mApplication->Exit(); }
bool __CALLOUT InitializeShell() { Clear(BLUE); const char* str = "PRICE of HONOR!"; DrawTextString(40,60,str,Length(str),RED,BLUE); GetBatteryLevel(); SetScreenBrightness(100); char buff[200]; int res = snprintf(buff,sizeof(buff),"test %d",0); DrawPixel(1,1,WHITE); DoVibroAndBeep(500); ubyte_t l = GetLustraId(); SendRadioPacket(NULL,0); uword_t a = GetArmletId(); FILE log; OpenFile(&log, "log.txt", true); char* s = "log test"; WriteFile(&log, s, Length(s)); /* //int i = 0; //Color area[100]; //for (i=0; i<100; i++) area[i] = 0xF0F; //DrawArea(5,5,area,100,10,10); //WriteFile(&log, (char*)area, 100); //for (i=0; i<100; i++) area[i] = 0x0; //ReadFile(&log, (char*)area, 100); //AppendFile(&log, (char*)area, 100); //DrawArea(5,5,area,100,10,10); */ RequestTimer(TimerProc,100); int up = GetUpTime(); int rnd = GetRandom(50); //SetCureName is checked in AppMainThread //WritePill is checked in AppMainThread //StartThread(AppMainThread,NULL); return true; //TODO }
//__SYSCALL returns 0-100% unsigned char __SYSCALL GetBatteryLevel() { unsigned char p = (unsigned char)(100 - (GetUpTime() / 1000)); //1% per sec if (p>100) p = 100; return p; }
ShutDownType Master::Run(int argc, char **argv) { new Config; std::vector<const char*> files; files.push_back("server.properties"), files.push_back("misc.properties"), files.push_back("character.properties"); std::string path = "./config"; if(argc >= 2) path = argv[1]; Config::Instance().Init(path, files); new Log(m_service); Log::Instance().Init(Config::Instance().GetParam<std::string>(LOGS_PATH_STRING, LOGS_PATH_DEFAULT).c_str(), Config::Instance().GetParam<uint8>(LOGS_LEVEL_STRING, LOGS_LEVEL_DEFAULT)); SetApplicationTitle("Desperion GameServer v%u.%u.%u", GAME_VERSION_MAJOR, GAME_VERSION_MINOR, GAME_VERSION_REVISION); Log::Instance().OutColor(TBLUE, ",------, ,-----. ,-----, ,------. ,-----. ,------. ,------. ,------, ,, ,,"); Log::Instance().OutColor(TBLUE, "| ,--, ` | .---' | ,--` | ,--, | | .---' | ,--, | `--||--' | ,--, | ||\\ ||"); Log::Instance().OutColor(TBLUE, "| | | | | |--. | `--, | | | | | |--. | | | | || | | | | || \\ ||"); Log::Instance().OutColor(TBLUE, "| | | | | |--' `---, | | `--` | | |--' | `--` , || | | | | || \\ ||"); Log::Instance().OutColor(TBLUE, "| '--' , | '---, ,---| | | ,----` | '---, | ,-\\ \\ .--||--, | '--' | || \\||"); Log::Instance().OutColor(TBLUE, "`------` `-----' `-----` `-` `-----' `-` '--' `------` `------` `` `'\n"); Log::Instance().OutColor(TWHITE, "Dofus v%u.%u.%u.%u.%u.%u, protocol %u/%u", DOFUS_VERSION_MAJOR, DOFUS_VERSION_MINOR, DOFUS_VERSION_RELEASE, DOFUS_VERSION_REVISION, DOFUS_VERSION_PATCH, DOFUS_VERSION_BUILD_TYPE, PROTOCOL_BUILD, PROTOCOL_REQUIRED_BUILD); Log::Instance().OutColor(TWHITE, "GameServer v%u.%u.%u", GAME_VERSION_MAJOR, GAME_VERSION_MINOR, GAME_VERSION_REVISION); Log::Instance().OutColor(TWHITE, "Shared v%u.%u.%u\n\n", SHARED_VERSION_MAJOR, SHARED_VERSION_MINOR, SHARED_VERSION_REVISION); if(!StartUpDatabase()) return SHUTDOWN_NORMAL; /*ResultPtr QR = sDatabase->Query("SELECT id, effects FROM d2o_item_set;"); barGoLink go(QR->GetRowCount()); while(QR->NextRow()) { Field* fields = QR->Fetch(); std::vector<std::string> table; std::ostringstream effects; Desperion::FastSplitString<':'>(table, std::string(fields[1].GetString())); effects<<table.size(); for(size_t a = 0; a < table.size(); ++a) { effects<<":"; std::vector<std::string> table2; Desperion::FastSplitString<';'>(table2, table[a]); effects<<table2.size(); for(size_t b = 0; b < table2.size(); ++b) { effects<<";"; std::vector<int> table3; Desperion::FastSplit<','>(table3, table2[b], Desperion::SplitInt); effects<<3<<","<<OBJECT_EFFECT_INTEGER<<","<<table3[2]<<","<<table3[6]; } } sDatabase->Execute("UPDATE d2o_item_set SET effects='%s' WHERE id=%u;", effects.str().c_str(), fields[0].GetInt32()); go.step(); } return SHUTDOWN_NORMAL;*/ new World; World::Instance().Init(); SocketListener<Session> sListener(ThreadPool::Instance().GetService(), Config::Instance().GetParam(LOCAL_SERVER_PORT_STRING, LOCAL_SERVER_PORT_DEFAULT)); Log::Instance().OutNotice("Network", "Listening for Dofus clients on port %u", Config::Instance().GetParam(LOCAL_SERVER_PORT_STRING, LOCAL_SERVER_PORT_DEFAULT)); new GameClient(ThreadPool::Instance().GetService()); GameClient::Instance().Launch(); std::cout<<std::endl; Log::Instance().OutString("Uptime: %ums", GetUpTime()); Log::Instance().OutColor(TBLUE, "Type Ctrl+C to safely shutdown the server.\n"); HookSignals(); HookSignals(); while(m_shutdown == SHUTDOWN_NOT_REQUESTED) { m_service.reset(); ThreadPool::Instance().SpawnWorkerThreads(); m_service.run(); ThreadPool::Instance().ClearWorkerThreads(); } UnHookSignals(); return m_shutdown; }