void MyGameManager::OnHandleCallback(IVisCallbackDataObject_cl *pData) { if (pData->m_pSender==&Vision::Callbacks.OnUpdateSceneBegin) { //This callback will be triggered at the beginning of every frame //You can add your own per frame logic here // [...] if (m_bPlayingTheGame) { Vision::Message.Print(1, 200, 100, "The game is running"); } return; } if (pData->m_pSender==&Vision::Callbacks.OnEditorModeChanged) { // when vForge switches back from EDITORMODE_PLAYING_IN_GAME, turn off our play the game mode if (((VisEditorModeChangedDataObject_cl *)pData)->m_eNewMode != VisEditorManager_cl::EDITORMODE_PLAYING_IN_GAME) SetPlayTheGame(false); return; } if (pData->m_pSender==&Vision::Callbacks.OnBeforeSceneLoaded) { //here you can add you specific code before the scene is loaded return; } if (pData->m_pSender==&Vision::Callbacks.OnAfterSceneLoaded) { //gets triggered when the play-the-game vForge is started or outside vForge after loading the scene if (Vision::Editor.IsPlayingTheGame()) SetPlayTheGame(true); return; } if (pData->m_pSender==&Vision::Callbacks.OnWorldDeInit) { // this is important when running outside vForge SetPlayTheGame(false); return; } }
void MyGameManager::OnHandleCallback(IVisCallbackDataObject_cl *pData) { //physics callbacks if (pData->m_pSender == &vHavokPhysicsModule::OnBeforeInitializePhysics) { vHavokPhysicsModuleCallbackData* pHavokData = static_cast<vHavokPhysicsModuleCallbackData*>(pData); VISION_HAVOK_SYNC_STATICS(); VISION_HAVOK_SYNC_PER_THREAD_STATICS(pHavokData->GetHavokModule()); // hkaiCharacter created by this dll will have a different vtable than the one expected by the AI module (for vdb viewer) // The vtable-class(?) mapping is apparently many-to-one, so re-register here with our vtable // (Actually the vtables in this module and the vtables elsewhere are unique, so being many-to-one is a happy accident) // TODO redundant in the statically linked case hkVtableClassRegistry::getInstance().registerList(hkBuiltinTypeRegistry::StaticLinkedTypeInfos, hkBuiltinTypeRegistry::StaticLinkedClasses); mStaticsSynced = true; } else if(pData->m_pSender == &vHavokPhysicsModule::OnBeforeWorldCreated) { vHavokPhysicsModule *const havok_module = static_cast<vHavokBeforeWorldCreateDataObject_cl *>(pData)->GetHavokModule(); { havok_module->SetUseAsynchronousPhysics(false); havok_module->SetEnabledVisualDebugger(true); } // Disable validation checks (that are also performed in dev build) vHavokAiModule::GetInstance()->GetAiWorld()->getNavMeshCutter()->m_performValidationChecks = false; } else if (pData->m_pSender == &vHavokPhysicsModule::OnAfterDeInitializePhysics) { vHavokAiModule::GetInstance()->getCharacterBehaviors().clearAndDeallocate(); vHavokPhysicsModuleCallbackData* pHavokData = static_cast<vHavokPhysicsModuleCallbackData*>(pData); VISION_HAVOK_UNSYNC_STATICS(); VISION_HAVOK_UNSYNC_PER_THREAD_STATICS(pHavokData->GetHavokModule()); mStaticsSynced = false; } if (pData->m_pSender==&Vision::Callbacks.OnUpdateSceneBegin) { //This callback will be triggered at the beginning of every frame //You can add your own per frame logic here // [...] if (m_bPlayingTheGame) { // Vision::Message.Print(1, 200, 100, "The game is running"); } return; } if(pData->m_pSender==&Vision::Callbacks.OnWorldInit) { vHavokPhysicsModule* pPhysicsModule = vHavokPhysicsModule::GetInstance(); if (pPhysicsModule != NULL && !mStaticsSynced) { // Havok Physics Plugin has already been initialized. // Reinitialize the physics integration to be able to synchronize static variables properly. pPhysicsModule->OnDeInitPhysics(); pPhysicsModule->OnInitPhysics(); } } if (pData->m_pSender==&Vision::Callbacks.OnEditorModeChanged) { // when vForge switches back from EDITORMODE_PLAYING_IN_GAME, turn off our play the game mode if (((VisEditorModeChangedDataObject_cl *)pData)->m_eNewMode != VisEditorManager_cl::EDITORMODE_PLAYING_IN_GAME) SetPlayTheGame(false); return; } if (pData->m_pSender==&Vision::Callbacks.OnBeforeSceneLoaded) { // Add our own Havok Behavior world listener in order to listen to Behavior events vHavokBehaviorModule *const havok_behavior_module = vHavokBehaviorModule::GetInstance(); havok_behavior_module->getBehaviorWorld()->addListener(&MyHavokBehaviorWorldListener::s_instance); return; } if (pData->m_pSender==&Vision::Callbacks.OnAfterSceneLoaded) { //spawn player charecter from prefab SpawnPlayer(PLAYER_PREFAB_NAME,hkvVec3(100,-400,30) , hkvVec3::ZeroVector()); //gets triggered when the play-the-game vForge is started or outside vForge after loading the scene if (Vision::Editor.IsPlayingTheGame()) SetPlayTheGame(true); return; } if (pData->m_pSender==&Vision::Callbacks.OnWorldDeInit) { // this is important when running outside vForge SetPlayTheGame(false); return; } if (pData->m_pSender==&Vision::Callbacks.OnBeforeSceneUnloaded) { return; } if (pData->m_pSender==&Vision::Callbacks.OnAfterSceneUnloaded) { // Only try to remove the listener if a scene was actually loaded vHavokBehaviorModule *const havok_behavior_module = vHavokBehaviorModule::GetInstance(); havok_behavior_module->getBehaviorWorld()->removeListener(&MyHavokBehaviorWorldListener::s_instance); return; } }
void MyGameManager::OnHandleCallback(IVisCallbackDataObject_cl *pData) { if (pData->m_pSender == &Vision::Callbacks.OnUpdateSceneBegin) { //This callback will be triggered at the beginning of every frame //You can add your own per frame logic here // [...] if (m_bPlayingTheGame) { Vision::Message.Print(1, 200, 100, "The game is running"); } return; } if (pData->m_pSender == &Vision::Callbacks.OnEditorModeChanged) { // when vForge switches back from EDITORMODE_PLAYING_IN_GAME, turn off our play the game mode if (((VisEditorModeChangedDataObject_cl *) pData)->m_eNewMode != VisEditorManager_cl::EDITORMODE_PLAYING_IN_GAME) SetPlayTheGame(false); return; } if (pData->m_pSender == &Vision::Callbacks.OnBeforeSceneLoaded) { //here you can add you specific code before the scene is loaded return; } if (pData->m_pSender == &Vision::Callbacks.OnAfterSceneLoaded) { //gets triggered when the play-the-game vForge is started or outside vForge after loading the scene if (Vision::Editor.IsPlayingTheGame()) SetPlayTheGame(true); /* spGUIContext = new VGUIMainContext(NULL); // Load some default resource (like the image for our cursor) VGUIManager::GlobalManager().LoadResourceFile("Dialogs\\MenuSystem.xml"); spGUIContext->SetActivate(true); spMainDlg = spGUIContext->ShowDialog("Dialogs\\MainMenu.xml"); VASSERT(spMainDlg); */ return; } if (pData->m_pSender == &Vision::Callbacks.OnWorldDeInit) { // this is important when running outside vForge SetPlayTheGame(false); return; } if (pData->m_pSender == &Vision::Callbacks.OnBeforeSceneUnloaded) { /* spMainDlg = NULL; // destroy the MainDlg Object spGUIContext->SetActivate(false); // Don't forget to deinit the GUI context spGUIContext = NULL; // destroy the GUI context */ return; } if (pData->m_pSender == &Vision::Callbacks.OnFrameUpdatePreRender) { // Holds packets RakNet::Packet* p; for (p=client->Receive(); p; client->DeallocatePacket(p), p=client->Receive()) { // We got a packet, get the identifier with our handy function auto packetIdentifier = GetPacketIdentifier(p); VString str; // Check if this is a network message packet switch (packetIdentifier) { case ID_DISCONNECTION_NOTIFICATION: // Connection lost normally Vision::Message.Add("ID_DISCONNECTION_NOTIFICATION\n"); break; case ID_INCOMPATIBLE_PROTOCOL_VERSION: Vision::Message.Add("ID_INCOMPATIBLE_PROTOCOL_VERSION\n"); break; case ID_REMOTE_DISCONNECTION_NOTIFICATION: // Server telling the clients of another client disconnecting gracefully. You can manually broadcast this in a peer to peer enviroment if you want. Vision::Message.Add("ID_REMOTE_DISCONNECTION_NOTIFICATION\n"); break; case ID_REMOTE_CONNECTION_LOST: // Server telling the clients of another client disconnecting forcefully. You can manually broadcast this in a peer to peer enviroment if you want. Vision::Message.Add("ID_REMOTE_CONNECTION_LOST\n"); break; case ID_REMOTE_NEW_INCOMING_CONNECTION: // Server telling the clients of another client connecting. You can manually broadcast this in a peer to peer enviroment if you want. Vision::Message.Add("ID_REMOTE_NEW_INCOMING_CONNECTION\n"); break; case ID_CONNECTION_BANNED: // Banned from this server Vision::Message.Add("We are banned from this server.\n"); break; case ID_CONNECTION_ATTEMPT_FAILED: Vision::Message.Add("Connection attempt failed\n"); break; case ID_NO_FREE_INCOMING_CONNECTIONS: // Sorry, the server is full. I don't do anything here but // A real app should tell the user Vision::Message.Add("ID_NO_FREE_INCOMING_CONNECTIONS\n"); break; case ID_INVALID_PASSWORD: Vision::Message.Add("ID_INVALID_PASSWORD\n"); break; case ID_CONNECTION_LOST: // Couldn't deliver a reliable packet - i.e. the other system was abnormally // terminated Vision::Message.Add("ID_CONNECTION_LOST\n"); break; case ID_CONNECTION_REQUEST_ACCEPTED: // This tells the client they have connected str.Format("ID_CONNECTION_REQUEST_ACCEPTED to %s with GUID %s\n",p->systemAddress.ToString(true), p->guid.ToString()); Vision::Message.Add(str); str.Format("My external address is %s\n", client->GetExternalID(p->systemAddress).ToString(true)); Vision::Message.Add(str); break; default: // It's a client, so just show the message //printf("%s\n", p->data); str.Format("Incoming message: %s",p->data); Vision::Message.Add(str); break; } } return; } }