void Game::RenderThreadloop() { CA_TRACE("Renderer initialized\n"); Initialize(); CA_TRACE("Game initialized\n"); LoadContent(); CA_TRACE("Game load content done\n"); try { BeginRun(); #if CA_PLATFORM_DESKTOP FrameLoop(); EndRun(); #endif // #if CA_PLATFORM_DESKTOP } catch (const std::exception& ex) { CA_FATAL("Error during game running : %s", ex.what()); return; } catch (...) { CA_FATAL("Error during game running : generic exception"); return; } }
void Game::Run() { sassert(!inRun, "Run Method called more than once."); inRun = true; BeginRun(); graphicsManager = (IGraphicsDeviceManager*)((GraphicsDeviceManager*)services.GetService(IGraphicsDeviceManager::GetType())); if (graphicsManager != null) graphicsManager->CreateDevice(); #if DEBUG else debugPrint("graphicsManager is NULL.\n"); #endif Initialize(); while(1) Tick(); EndRun(); inRun = false; }
void CStrategyGrid::checkOrder() { //添加完策略需要先睡眠,因为参数还未设置 std::this_thread::sleep_for(std::chrono::milliseconds(100)); while(!m_Exit) { //BeginRun(); //return; if(m_Exit) { CString str; str.Format("%s:策略终止,退出",m_strModelName); this->AddLog(str.GetBuffer(0)); return; } if(!m_bRun) { CString str; str.Format("%s:策略暂停,等待",m_strModelName); this->AddLog(str.GetBuffer(0)); std::this_thread::sleep_for(std::chrono::milliseconds(3*1000)); continue; } if(reLogintime()) { //m_SPTrade->relogin(); ::SendMessage(CStrategyBase::m_hMsgWnd,WM_MESSAGE_ENTRUST,3,0); std::this_thread::sleep_for(std::chrono::milliseconds(3*1000)); } if(check_in_jihe()) { if(isNewModel) { this->AddLog("集合竞价下单,等待开盘"); BeginRun(); isNewModel = false; std::this_thread::sleep_for(std::chrono::milliseconds(10*1000)); continue; } if(isAnohterDay && !isNewModel && !isLoad) { this->AddLog("reload..."); reload(); isLoad = true; isSave = false; isAnohterDay = false; std::this_thread::sleep_for(std::chrono::milliseconds(10*1000)); } std::this_thread::sleep_for(std::chrono::milliseconds(1*1000)); } if( checkpanzhong() ) { if(isNewModel) { this->AddLog("盘中添加策略"); BeginRun(); isNewModel = false; } std::this_thread::sleep_for(std::chrono::milliseconds(3*1000)); } //收盘 if(checksavetime()) { //如果盘后添加则等待 if(isNewModel) { std::this_thread::sleep_for(std::chrono::milliseconds(10*1000)); continue; } if(!isSave && !isAnohterDay) { this->AddLog("save..."); saveModel(); isSave = true; isAnohterDay = true; isLoad = false; this->m_listOrderRef.RemoveAll(); this->m_orderinfo.clear(); //if(m_kp==1) setHoldinfo(); } std::this_thread::sleep_for(std::chrono::milliseconds(10*1000)); } //接近集合竞价或者开盘时间添加策略,休眠100ms,比如 8:50过后 if(checkbefore()) { std::this_thread::sleep_for(std::chrono::milliseconds(100)); continue; } if(check_b_jihe()) { this->AddLog("集合竞价前下单,等待触发"); std::this_thread::sleep_for(std::chrono::milliseconds(3*1000)); continue; } //一般非交易时间 if(checkothertime()) { std::this_thread::sleep_for(std::chrono::milliseconds(3*1000)); //continue; } //没有就强制睡3秒 string prefix = Tool::getCodePrefix(m_strInstrument.GetBuffer(0)); if(m_codestatus[prefix].status==0) std::this_thread::sleep_for(std::chrono::milliseconds(3*1000)); } if(m_Exit) { CString str; str.Format("%s:策略终止,退出",m_strModelName); this->AddLog(str.GetBuffer(0)); return; } }
/* Main function */ int main(int argc, char** argv) { if( BeginJob( argc, argv ) == 0 ) { cout<<"BeginJob failed"<<endl; return 0; } /* Layer 1. The main loop over every stream entries */ /* ------------------------------------------------ */ CurrRun.Run = -1; cout<<"StreamChain add "<<StreamChain<<endl; unsigned int entries = StreamChain->GetEntries(); for( unsigned int entry=0; entry<entries; entry++ ) { unsigned int localentry = StreamChain->LoadTree(entry); int ret = Reader->GetEntry( localentry ); if( ret==0 ) { cout<<"Error: Read error"<<endl; return 1; } /* Process run information and possible long time jump */ if( Reader->Run != CurrRun.Run ) { if( CurrRun.Run != -1 ) { /* End Run */ if( EndRun( Reader ) == 0 ) { cout<<"EndRun failed"<<endl; return 0; } } /* Begin Run */ if( BeginRun( Reader ) == 0 ) { cout<<"BeginRun failed"<<endl; return 0; } } /*** Test each entry here ***/ SubEvt* pSubEvt = new SubEvt( Reader ); TimeStamp NewTime( pSubEvt->TrigSec, pSubEvt->TrigNano ); if( (NewTime - CurrRun.CurrTime).GetSeconds() > 120 /* Two minutes */ ) { CurrRun.Breaks.push_back( CurrRun.CurrTime ); CurrRun.Breaks.push_back( NewTime ); CurrRun.SkipTime.Add( (NewTime - CurrRun.CurrTime).GetSeconds() ); } CurrRun.CurrTime = NewTime; /* Cache all temporal related event. Give a chance to clean up the queue and do muon Id */ SubEvtQueue PassedQueue = CachedQueueInsert( NewTime, pSubEvt ); /* Layer 2. The main loop over every non-muon SubEvt */ /* ------------------------------------------------- */ SubEvtQueueIterator it, it_end = PassedQueue.end(); for( it = PassedQueue.begin(); it != it_end; it++ ) { /* Build delay coincident event */ SubEvt* pSubEvt = it->second; int ret = BuildEvent( pSubEvt ); if( ret == 0 ) { cout<<"Error in BuildEvent"<<endl; } delete pSubEvt; } /*** End of SubEvt loop ***/ } /*** End of stream entry loop ***/ if( EndRun( Reader ) == 0 ) { cout<<"EndRun failed"<<endl; return 0; } /* End Job */ /* ------- */ if( EndJob() == 0 ) { cout<<"BeginJob failed"<<endl; return 0; } return 1; }