---------- Player.cpp -------------------------------------------------------- CPlayerApp theApp; BOOL CPlayerApp::InitInstance() { CMDIFrameWnd* pFrame = new CMainFrame; m_pMainWnd = pFrame; } void CPlayerApp::OnFileNew() { m_pMainWnd->CreateNewChild(...); } ---------- MainFrm.cpp ------------------------------------------------------- class CMainFrame : public CMDIFrameWnd { CWinThread* m_pCoordinatorThread; } void CMainFrame::OnServerConnect() { m_pCoordinatorThread = AfxBeginThread(...); } ---------- Coordinator.cpp --------------------------------------------------- class CCoordinator : public CWinThread { CGameState *m_pGameState; CPerceptionSeq *m_pPerceptionSeq; CSystemClock* m_pSystemClock; CServerConnection* m_pServerConnection; CServerMsgTranslator *m_pServerMsgTranslator; CServerCommunicator *m_pServerCommunicator; } CEventDispatcher EventDispatcher; class CEventDispatcher { void Handle(); // -> CCoordinator::Handle(); } BOOL CCoordinator::InitInstance() { m_pSystemClock = new CSystemClock(); // + Initialize(); m_pServerMsgTranslator = new CServerMsgTranslator(); // + Initialize(); m_pServerConnection = new CServerConnection(); // + Initialize(); m_pServerCommunicator = new CServerCommunicator(); // + Initialize(); m_pServerConnection->Connect("localhost", 6000); m_pServerConnection->SendMsg(CServerMsg("(init tim4 (version 5.00))")); } void CCoordinator::Handle() { switch (eType) { case ET__RECEIVED_MSG: m_pServerCommunicator->OnReceiveServerMsg(); break; case ET__START_DELIBERATION: Deliberate(pDeliberationEvent->m_pPerceptionSeq); break; case ET__SEND_COMMANDS: m_pServerCommunicator->SendCommands(pSendEvent->m_pGameCommandSeq); break; } } void Deliberate(CPerceptionSeq *pPerceptionSeq) { while (pPerceptionSeq->GetPerception(&rPerception)) { if (rPerception.GetMsgType() == MT_See) { { aLocalAgent.UpdatePlayerPosition(rPerception.m_fFlags, rPerception.m_gGoals, rPerception.m_lLines); CChildView->Invalidate(); // -> CChildView::OnDraw() } cSendCommands.Add(CT__KICK); EventDispatcher.SendEvent(ET__SEND_COMMANDS); } } } ---------- ServerCommunicator.cpp -------------------------------------------- class CGameState // v GameState.h { EPlayMode m_nPlayMode; CGameTime m_tGameTime; } class CServerCommunicator { private: CGameState *m_pGameState; CPerceptionSeq *m_pPerceptionSeq; // perception sequence CGameCommandSeq *m_pSendCommandSeq; // FIXME - mozu byt aj vo vlastnej rezii CGameCommandSeq *m_pSentCommandSeq; CSystemClock *m_pSystemClock; CServerConnection *m_pServerConnection; CServerMsgTranslator *m_pServerMsgTranslator; public: void OnReceiveServerMsg(); void OnSynchTimer(int nTimeToNextCall = 0); } void CServerCommunicator::OnReceiveServerMsg() { ProcessReceivedSrvMsgs(); OnSynchTimer(0); } void CServerCommunicator::ProcessReceivedSrvMsgs() { while (...) { res = m_pServerMsgTranslator->ParseServerMsg(pSrvMsg, &rPerception); UpdateGameState(&rPerception); rPerception.SetGameTime(m_pGameState->GetGameTime()); m_pPerceptionSeq->AddPerception(&rPerception); } } void CServerCommunicator::OnSynchTimer(int nTimeToNextCall) { nStepTime = UpdateGameTime(m_pSystemClock->GetTime()); if (...) EventDispatcher.SendEvent(ET__START_DELIBERATION); if (...) { m_pServerMsgTranslator->GenerateServerMsg(pGameCommand, &mSrvMsg); m_pServerConnection->SendMsg(mSrvMsg); } } void CServerCommunicator::SendCommands(CGameCommandSeq *pSendCommands) { m_pSendCommandSeq->Add(pSendCommands->GetFirst()); OnSynchTimer(0); } ---------- ServerMsgTranslator.cpp ------------------------------------------- class CServerMsgTranslator { CParser m_Parser; public: int ParseServerMsg(CServerMsg *pServerMsg, CPerception *pPerception) { m_Parser.Parse((char *)pServerMsg->m_sMessage.c_str(), pPerception); } int GenerateServerMsg(CGameCommand *pCommand, CServerMsg *pServerMsg); } ---------- ServerConnection.cpp ---------------------------------------------- BOOL CServerConnection::Connect(LPCTSTR lpszHostAddress, UINT nHostPort) { } void CServerConnection::OnReceive(int nErrorCode) { EventDispatcher.SendEvent(ET__RECEIVED_MSG); EventDispatcher.Handle(); } ---------- ChildView.cpp ----------------------------------------------------- void CChildView::OnDraw( CDC* pDC ) { DrawField( pDC, m_nAllFieldPosXPixel, m_nAllFieldPosYPixel ); DrawOwnAgent( pDC, &fooObject ); for(...) { DrawPerceptionFlag( pDC, &fooObject ); DrawPerceptionPlayer( pDC, &fooObject ); } DrawPerceptionBall( pDC, &fooObject ); } ---------- WorldObjects.cpp -------------------------------------------------- bool CLocalAgent::UpdatePlayerPosition(seenFlagsVect &_fFlags,seenGoalsVect &_gGoals,seenLinesVect &_lLines)//nasty&ughly { // lokalizacia() position.Set(_x, _y, 0.1f/N); neck_direction = _a; }