// TODO: This should return a bool specifying if the level was successfully opened. void OpenLevel(BSTR fullPathLevelFile) { // We need to strip off the project directory from the filename first. std::string levelFile = ws2s(std::wstring(fullPathLevelFile, SysStringLen(fullPathLevelFile))); EditorLogic* pEditorLogic = (EditorLogic*)g_pApp->GetGameLogic(); if (pEditorLogic) { std::string assetsDir = "\\Assets\\"; int projDirLength = pEditorLogic->GetProjectDirectory().length() + assetsDir.length(); g_pApp->GetSettings()->level = levelFile.substr(projDirLength, levelFile.length()-projDirLength); pEditorLogic->ChangeGameState(GS_LoadingGameEnvironment); } }
void GetActorList( int *ptr, int numActors ) { // To keep things simple, we pass the actor ids to the C# app // the C# app iterates through the actor ids, and calls back into // the unmanaged dll to get the appropriate information about each // actor EditorLogic* pGame = (EditorLogic*)g_pApp->GetGameLogic(); if ( pGame ) { ActorMap::const_iterator itr; int actorArrayIndex; for ( itr = pGame->GetActorMap().begin(), actorArrayIndex = 0; itr != pGame->GetActorMap().end() && actorArrayIndex < numActors; itr++, actorArrayIndex++ ) { ActorId actorId = itr->first; ptr[actorArrayIndex] = actorId; } } }
// // PickActor - Chapter 22, page 760 // int PickActor(int *hWndPtrAddress) { HWND hWnd = (HWND)hWndPtrAddress; POINT ptCursor; GetCursorPos( &ptCursor ); // Convert the screen coordinates of the mouse cursor into // coordinates relative to the client window ScreenToClient( hWnd, &ptCursor ); RayCast rayCast(ptCursor); EditorLogic* pGame = (EditorLogic*)g_pApp->m_pGame; if (!pGame) { return INVALID_ACTOR_ID; } shared_ptr<EditorHumanView> pView = pGame->GetHumanView(); if (!pView) { return INVALID_ACTOR_ID; } // Cast a ray through the scene. The RayCast object contains an array of Intersection // objects. pView->GetScene()->Pick(&rayCast); rayCast.Sort(); // If there are any intersections, get information from the first intersection. if (!rayCast.m_NumIntersections) { return INVALID_ACTOR_ID; } Intersection firstIntersection = rayCast.m_IntersectionArray[0]; return firstIntersection.m_actorId; }
int GetNumActors() { EditorLogic* pGame = (EditorLogic*)g_pApp->GetGameLogic(); return (pGame) ? pGame->GetNumActors() : 0; }
int IsGameRunning() { EditorLogic* game = (EditorLogic*)g_pApp->GetGameLogic(); return (game) ? game->IsRunning() : false; }
// // IsGameRunning - Chapter 22 // int IsGameRunning() { EditorLogic* game = (EditorLogic*)g_pApp->m_pGame; return (game) ? game->IsRunning() : false; }