/*! * Load a savegame and start into the game loop * Game data should be initialised afterwards, so that startGameLoop is not necessary anymore. */ static bool initSaveGameLoad(void) { // NOTE: always setGameMode correctly before *any* loading routines! SetGameMode(GS_NORMAL); screen_RestartBackDrop(); // load up a save game if (!loadGameInit(saveGameName)) { // FIXME: we really should throw up a error window, but we can't (easily) so I won't. debug(LOG_ERROR, "Trying to load Game %s failed!", saveGameName); debug(LOG_POPUP, "Failed to load a save game! It is either corrupted or a unsupported format.\n\nRestarting main menu."); // FIXME: If we bomb out on a in game load, then we would crash if we don't do the next two calls // Doesn't seem to be a way to tell where we are in game loop to determine if/when we should do the two calls. gameLoopStatus = GAMECODE_FASTEXIT; // clear out all old data stopGameLoop(); startTitleLoop(); // Restart into titleloop SetGameMode(GS_TITLE_SCREEN); return false; } screen_StopBackDrop(); closeLoadingScreen(); // Trap the cursor if cursor snapping is enabled if (war_GetTrapCursor()) { wzGrabMouse(); } if (challengeActive) { addMissionTimerInterface(); } return true; }
void VoxGame::GameModeChanged() { GameMode gameMode = GetGameMode(); if (m_pGameOptionBox->GetToggled() && gameMode != GameMode_Game) { SetGameMode(GameMode_Game); m_pMouseRotateCameraOptionBox->SetDisabled(false); m_pAutoCameraOptionBox->SetDisabled(false); // Allow switching to frontend mode m_allowToChangeToFrontend = false; m_allowToChangeToGame = true; m_pGameOptionBox->SetDisabled(false); m_pFrontEndOptionBox->SetDisabled(false); } else if (m_pFrontEndOptionBox->GetToggled() && gameMode != GameMode_FrontEnd) { SetGameMode(GameMode_FrontEnd); // Set front-end page to intro m_pFrontendManager->SetFrontendScreen(FrontendScreen_MainMenu); m_pMouseRotateCameraOptionBox->SetDisabled(true); m_pAutoCameraOptionBox->SetDisabled(true); // Allow switching to game mode m_allowToChangeToFrontend = true; m_allowToChangeToGame = false; m_pGameOptionBox->SetDisabled(false); m_pFrontEndOptionBox->SetDisabled(false); } else if (m_pDebugOptionBox->GetToggled() && gameMode != GameMode_Debug) { SetGameMode(GameMode_Debug); m_cameraMode = CameraMode_Debug; m_pDebugCameraOptionBox->SetToggled(true); m_pMouseRotateCameraOptionBox->SetDisabled(true); m_pAutoCameraOptionBox->SetDisabled(true); m_pFrontendCameraOptionBox->SetDisabled(true); // Decide if we came into debug mode from either game or front-end and then only allow to go back to that previous mode // This prevents us getting into a weird state were we go something like: game -> debug -> frontend. m_pGameOptionBox->SetDisabled(true); if(m_allowToChangeToGame == true) { m_pGameOptionBox->SetDisabled(false); } m_pFrontEndOptionBox->SetDisabled(true); if (m_allowToChangeToFrontend == true) { m_pFrontEndOptionBox->SetDisabled(false); } } }
//------------------------------------------------------------------------ void CEditorGame::Shutdown() { gEnv->pConsole->RemoveCommand("net_reseteditorclient"); EnablePlayer(false); SetGameMode(false); m_pGameStartup->Shutdown(); }
/*! * Preparations before entering the game loop * Would start the timer in an event based mainloop */ static void startGameLoop(void) { SetGameMode(GS_NORMAL); // Not sure what aLevelName is, in relation to game.map. But need to use aLevelName here, to be able to start the right map for campaign, and need game.hash, to start the right non-campaign map, if there are multiple identically named maps. if (!levLoadData(aLevelName, &game.hash, NULL, GTYPE_SCENARIO_START)) { debug( LOG_FATAL, "Shutting down after failure" ); exit(EXIT_FAILURE); } screen_StopBackDrop(); // Trap the cursor if cursor snapping is enabled if (war_GetTrapCursor()) { wzGrabMouse(); } // set a flag for the trigger/event system to indicate initialisation is complete gameInitialised = true; if (challengeActive) { addMissionTimerInterface(); } if (game.type == SKIRMISH) { eventFireCallbackTrigger((TRIGGER_TYPE)CALL_START_NEXT_LEVEL); } triggerEvent(TRIGGER_START_LEVEL); screen_disableMapPreview(); }
static void OnQuickStartButton() { SetGameMode(AMJU_MODE_NONE); static PlayerInfoManager* pim = ThePlayerInfoManager::Instance(); PlayerInfo* pi = pim->GetPI(); Assert(pi); std::string email = pi->PIGetString(PI_KEY("email")); TheGSLoginWaiting::Instance()->SetEmail(email); TheGame::Instance()->SetCurrentState(TheGSLoginWaiting::Instance()); }
// Game functions void VoxGame::QuitToFrontEnd() { m_pVoxWindow->TurnCursorOn(true); SetGameMode(GameMode_FrontEnd); m_pFrontEndOptionBox->SetToggled(true); m_pDebugCameraOptionBox->SetToggled(true); m_pVoxWindow->Update(m_deltaTime); GameModeChanged(); CameraModeChanged(); }
/*! * Preparations before entering the title (mainmenu) loop * Would start the timer in an event based mainloop */ static void startTitleLoop(void) { SetGameMode(GS_TITLE_SCREEN); initLoadingScreen(true); if (!frontendInitialise("wrf/frontend.wrf")) { debug( LOG_FATAL, "Shutting down after failure" ); exit(EXIT_FAILURE); } closeLoadingScreen(); }
/*! * Preparations before entering the title (mainmenu) loop * Would start the timer in an event based mainloop */ static void startTitleLoop(void) { SetGameMode(GS_TITLE_SCREEN); screen_RestartBackDrop(); if (!frontendInitialise("wrf/frontend.wrf")) { debug( LOG_FATAL, "Shutting down after failure" ); exit(EXIT_FAILURE); } frontendInitVars(); }
void AProjectTapGameMode::StartPlay() { Super::StartPlay(); auto gameState = GetGameState<AProjectTapGameState>(); ABallPawn* ball = nullptr; if ( UWorld* world = GetWorld() ) { AActor* playerStart = FindPlayerStart( 0 , FString( "Player" ) ); FTransform playerTransform = playerStart->GetTransform(); if ( ABallPlayerStart* realPlayerStart = Cast<ABallPlayerStart>( playerStart ) ) { auto possibleCamera = realPlayerStart->camera == nullptr ? nullptr : Cast<UProjectTapCameraComponent>( realPlayerStart->camera->GetComponentByClass( UProjectTapCameraComponent::StaticClass() ) ); FActorSpawnParameters params; ball = world->SpawnActor<ABallPawn>( ABallPawn::StaticClass() , playerTransform.GetTranslation() , FRotator( playerTransform.GetRotation() ) , params ); if ( ball != nullptr ) { ball->AddVelocity( realPlayerStart->initialVelocity , realPlayerStart->GetActorLocation() ); if ( possibleCamera != nullptr && realPlayerStart->followPlayer ) { ball->setCamera( realPlayerStart ); possibleCamera = ball->GetCamera(); } } gameState->SetCamera( possibleCamera ); isMenu = realPlayerStart->GameMode == CustomGameMode::GAME_MODE_MAIN_MENU; if ( realPlayerStart->music != nullptr )musicPlayer->SetSound( realPlayerStart->music ); } else { FActorSpawnParameters params; ball = world->SpawnActor<ABallPawn>( ABallPawn::StaticClass() , playerTransform.GetTranslation() , FRotator( playerTransform.GetRotation() ) , params ); } gameState->SetPlayer(ball); } musicPlayer->Play(); musicPlayer->SetVolumeMultiplier( 0 ); gameState->SetGameState( CustomGameState::GAME_STATE_PLAYING ); if ( isMenu ) gameState->SetGameMode( CustomGameMode::GAME_MODE_MAIN_MENU ); }
//------------------------------------------------------------------------ void CEditorGame::EnablePlayer(bool bPlayer) { bool spawnPlayer = false; if (m_bPlayer != bPlayer) { spawnPlayer = m_bPlayer = bPlayer; } if (!SetGameMode( m_bGameMode )) { GameWarning("Failed setting game mode"); } else if (m_bEnabled && spawnPlayer) { if (!m_pGame->GetIGameFramework()->BlockingSpawnPlayer()) GameWarning("Failed spawning player"); } }
bool CEditorGame::Init(ISystem *pSystem,IGameToEditorInterface *pGameToEditorInterface) { assert(pSystem); SSystemInitParams startupParams; startupParams.bEditor = true; startupParams.pSystem = pSystem; startupParams.bExecuteCommandLine=false; // in editor we do it later - after other things are initialized m_pGameStartup = CreateGameStartup(); m_pGame = m_pGameStartup->Init(startupParams); if (!m_pGame) { return false; } IGameFramework* pGameFramework = m_pGame->GetIGameFramework(); if ( pGameFramework != NULL ) { pGameFramework->InitEditor( pGameToEditorInterface ); } InitUIEnums(pGameToEditorInterface); gEnv->bServer = true; gEnv->bMultiplayer = false; #if !defined(XENON) && !defined(PS3) && !defined(GRINGO) gEnv->SetIsClient(true); #endif m_bUsingMultiplayerGameRules = false; s_pEditorGameMode = REGISTER_INT( "net_gamemode", 0, 0, "Should editor connect a new client?"); s_pEditorGameMode->SetOnChangeCallback(&OnChangeEditorMode); SetGameMode(false); REGISTER_COMMAND( "net_reseteditorclient", ResetClient, 0, "Resets player and gamerules!" ); ConfigureNetContext(true); return true; }
/*! * Preparations before entering the game loop * Would start the timer in an event based mainloop */ static void startGameLoop(void) { SetGameMode(GS_NORMAL); if (!levLoadData(aLevelName, NULL, GTYPE_SCENARIO_START)) { debug( LOG_FATAL, "Shutting down after failure" ); exit(EXIT_FAILURE); } //after data is loaded check the research stats are valid if (!checkResearchStats()) { debug( LOG_FATAL, "Invalid Research Stats" ); debug( LOG_FATAL, "Shutting down after failure" ); exit(EXIT_FAILURE); } //and check the structure stats are valid if (!checkStructureStats()) { debug( LOG_FATAL, "Invalid Structure Stats" ); debug( LOG_FATAL, "Shutting down after failure" ); exit(EXIT_FAILURE); } screen_StopBackDrop(); // Trap the cursor if cursor snapping is enabled if (war_GetTrapCursor()) { wzGrabMouse(); } // set a flag for the trigger/event system to indicate initialisation is complete gameInitialised = true; if (challengeActive) { addMissionTimerInterface(); } if (game.type == SKIRMISH) { eventFireCallbackTrigger((TRIGGER_TYPE)CALL_START_NEXT_LEVEL); } screen_disableMapPreview(); }
bool CEditorGame::Init(ISystem *pSystem,IGameToEditorInterface *pGameToEditorInterface) { assert(pSystem); SSystemInitParams startupParams; FillSystemInitParams(startupParams, pSystem); m_pGameStartup = CreateGameStartup(); m_pGame = m_pGameStartup->Init(startupParams); if (!m_pGame) { return false; } InitUIEnums(pGameToEditorInterface); m_pGame->GetIGameFramework()->InitEditor(pGameToEditorInterface); m_pEquipmentSystemInterface = new CEquipmentSystemInterface(this, pGameToEditorInterface); gEnv->bServer = true; gEnv->bMultiplayer = false; #if !defined(CONSOLE) gEnv->SetIsClient(true); #endif m_bUsingMultiplayerGameRules = (g_pGameCVars->g_multiplayerDefault != 0); if (IConsole* pConsole = gEnv->pConsole) s_pEditorGameMode = REGISTER_INT_CB("net_gamemode", 0, VF_NULL, "Should editor connect a new client?", &OnChangeEditorMode); SetGameMode(false); REGISTER_COMMAND( "net_reseteditorclient", ResetClient, VF_NULL, "Resets player and gamerules!" ); ConfigureNetContext(true); g_pGame->OnEditorGameInitComplete(); return true; }
void CreateGameScreen::MapSelected(RefPtr<XmlDocument>& mapDoc) { _currentMapDoc = mapDoc; _currentMapDir = _mapList->GetCurrentDir(); _buttonStart->setEnabled(false); try { // Read and set preview image and start locations XmlNode* mapNode = mapDoc->first_node("Map"); Vector2 mapSize = XmlUtility::XmlGetXY(mapNode->first_node("Size")); string previewImage = XmlUtility::XmlGetString(mapNode->first_node("PreviewImage"), "value"); XmlNode* startLocListNode = mapNode->first_node("AvailableStartLocations"); XmlNode* startLocNode = startLocListNode->first_node(); while( startLocNode != 0 ) { _startLocPositions.push_back(XmlUtility::XmlGetXY(startLocNode)); startLocNode = startLocNode->next_sibling(); } _mapPreview->SetNewMap(mapSize, _mapList->GetCurrentDir() + previewImage, previewImage, _startLocPositions.size()); for(unsigned int i = 0; i < _startLocPositions.size(); ++i) { _mapPreview->MoveStartingPosition(i, _startLocPositions[i]); _mapPreview->SetStartingPositionColor(i, PlayersColorsList[NoColorIndex]); } AddGameModes(mapNode); int defMode = _currentMode; _currentMode = -1; SetGameMode(defMode); _comboGameMode->setEnabled(true); _comboResourcesMode->setEnabled(true); _comboStartLocMode->setEnabled(true); _comboVisibilityMode->setEnabled(true); } catch(...) { _ASSERT(false); // Map file is corrupted, maybe show some info on it } }
void GSStartMenu::OnActive() { SetGameMode(AMJU_MODE_NONE); GSGui::OnActive(); m_gui = LoadGui("gui-startmenu.txt"); Assert(m_gui); GuiButton* start = (GuiButton*)GetElementByName(m_gui, "start-button"); start->SetCommand(Amju::OnStartButton); GuiButton* guest = (GuiButton*)GetElementByName(m_gui, "guest-button"); // not supported currently //guest->SetCommand(Amju::OnGuestButton); GuiButton* options = (GuiButton*)GetElementByName(m_gui, "options-button"); options->SetCommand(Amju::OnOptionsButton); GuiButton* admin = (GuiButton*)GetElementByName(m_gui, "admin-button"); #ifdef _DEBUG admin->SetCommand(Amju::OnAdminButton); #else admin->SetVisible(false); #endif GuiButton* cancel = (GuiButton*)GetElementByName(m_gui, "cancel-button"); cancel->SetCommand(Amju::OnCancelButton); cancel->SetIsCancelButton(true); // TODO remember last choice and keep highlighted start->SetHasFocus(true); #ifdef PLAY_MUSIC TheSoundManager::Instance()->PlaySong("Sound/piano.it"); #endif }
void StarServer::GameState() { if (lobby_server) { lobby_server->ExecFrame(); if (lobby_server->GetStatus() == NetServerInfo::PERSISTENT) paused = NetGame::NumPlayers() < 1; } if (game_mode == MENU_MODE) { Sleep(30); } else if (game_mode == LOAD_MODE) { CreateWorld(); InstantiateMission(); SetGameMode(PLAY_MODE); } else if (game_mode == PLAY_MODE) { if (Game::GameTime() - time_mark > 60000) { time_mark = Game::GameTime(); minutes++; if (minutes > 60) Print(" TIME %2d:%02d:00\n", minutes/60, minutes%60); else Print(" TIME %2d:00\n", minutes); } Sleep(10); } Memory::Check(); }
/** * Second half of command line parsing. See ParseCommandLineEarly() for * the first half. Note that render mode must come before resolution flag. * \param argc number of arguments given * \param argv string array of the arguments * \return Returns true on success, false on error */ bool ParseCommandLine(int argc, const char **argv) { poptContext poptCon = poptGetContext(nullptr, argc, argv, getOptionsTable(), 0); int iOption; /* loop through command line */ while ((iOption = poptGetNextOpt(poptCon)) > 0) { const char *token; CLI_OPTIONS option = (CLI_OPTIONS)iOption; switch (option) { case CLI_DEBUG: case CLI_DEBUGFILE: case CLI_FLUSHDEBUGSTDERR: case CLI_CONFIGDIR: case CLI_HELP: case CLI_HELP_ALL: case CLI_VERSION: // These options are parsed in ParseCommandLineEarly() already, so ignore them break; case CLI_NOASSERT: kf_NoAssert(); break; // NOTE: The sole purpose of this is to test the crash handler. case CLI_CRASH: CauseCrash = true; NetPlay.bComms = false; sstrcpy(aLevelName, "CAM_3A"); SetGameMode(GS_NORMAL); break; case CLI_DATADIR: // retrieve the quoted path name token = poptGetOptArg(poptCon); if (token == nullptr) { qFatal("Unrecognised datadir"); } sstrcpy(datadir, token); break; case CLI_FULLSCREEN: war_setFullscreen(true); break; case CLI_CONNECTTOIP: //get the ip we want to connect with, and go directly to join screen. token = poptGetOptArg(poptCon); if (token == nullptr) { qFatal("No IP/hostname given"); } sstrcpy(iptoconnect, token); break; case CLI_HOSTLAUNCH: // go directly to host screen, bypass all others. hostlaunch = 1; break; case CLI_GAME: // retrieve the game name token = poptGetOptArg(poptCon); if (token == nullptr || (strcmp(token, "CAM_1A") && strcmp(token, "CAM_2A") && strcmp(token, "CAM_3A") && strcmp(token, "TUTORIAL3") && strcmp(token, "FASTPLAY"))) { qFatal("The game parameter requires one of the following keywords:" "CAM_1A, CAM_2A, CAM_3A, TUTORIAL3, or FASTPLAY."); } NetPlay.bComms = false; bMultiPlayer = false; bMultiMessages = false; for (int i = 0; i < MAX_PLAYERS; i++) { NET_InitPlayer(i, true, false); } //NET_InitPlayer deallocates Player 0, who must be allocated so that a later invocation of processDebugMappings does not trigger DEBUG mode NetPlay.players[0].allocated = true; if (!strcmp(token, "CAM_1A") || !strcmp(token, "CAM_2A") || !strcmp(token, "CAM_3A")) { game.type = CAMPAIGN; } else { game.type = SKIRMISH; // tutorial is skirmish for some reason } sstrcpy(aLevelName, token); SetGameMode(GS_NORMAL); break; case CLI_MOD_GLOB: { // retrieve the file name token = poptGetOptArg(poptCon); if (token == nullptr) { qFatal("Missing mod name?"); } global_mods.push_back(token); break; } case CLI_MOD_CA: { // retrieve the file name token = poptGetOptArg(poptCon); if (token == nullptr) { qFatal("Missing mod name?"); } campaign_mods.push_back(token); break; } case CLI_MOD_MP: { // retrieve the file name token = poptGetOptArg(poptCon); if (token == nullptr) { qFatal("Missing mod name?"); } multiplay_mods.push_back(token); break; } case CLI_RESOLUTION: { unsigned int width, height; token = poptGetOptArg(poptCon); if (sscanf(token, "%ix%i", &width, &height) != 2) { qFatal("Invalid parameter specified (format is WIDTHxHEIGHT, e.g. 800x600)"); } if (width < 640) { debug(LOG_ERROR, "Screen width < 640 unsupported, using 640"); width = 640; } if (height < 480) { debug(LOG_ERROR, "Screen height < 480 unsupported, using 480"); height = 480; } // tell the display system of the desired resolution pie_SetVideoBufferWidth(width); pie_SetVideoBufferHeight(height); // and update the configuration war_SetWidth(width); war_SetHeight(height); break; } case CLI_LOADSKIRMISH: // retrieve the game name token = poptGetOptArg(poptCon); if (token == nullptr) { qFatal("Unrecognised skirmish savegame name"); } snprintf(saveGameName, sizeof(saveGameName), "%s/skirmish/%s.gam", SaveGamePath, token); SPinit(); bMultiPlayer = true; game.type = SKIRMISH; // tutorial is skirmish for some reason SetGameMode(GS_SAVEGAMELOAD); break; case CLI_LOADCAMPAIGN: // retrieve the game name token = poptGetOptArg(poptCon); if (token == nullptr) { qFatal("Unrecognised campaign savegame name"); } snprintf(saveGameName, sizeof(saveGameName), "%s/campaign/%s.gam", SaveGamePath, token); SPinit(); SetGameMode(GS_SAVEGAMELOAD); break; case CLI_WINDOW: war_setFullscreen(false); break; case CLI_SHADOWS: setDrawShadows(true); break; case CLI_NOSHADOWS: setDrawShadows(false); break; case CLI_SOUND: war_setSoundEnabled(true); break; case CLI_NOSOUND: war_setSoundEnabled(false); break; case CLI_TEXTURECOMPRESSION: wz_texture_compression = true; break; case CLI_NOTEXTURECOMPRESSION: wz_texture_compression = false; break; case CLI_AUTOGAME: wz_autogame = true; break; case CLI_SAVEANDQUIT: token = poptGetOptArg(poptCon); if (token == nullptr || !strchr(token, '/')) { qFatal("Bad savegame name (needs to be a full path)"); } wz_saveandquit = token; break; case CLI_SKIRMISH: hostlaunch = 2; token = poptGetOptArg(poptCon); if (token == nullptr) { qFatal("Bad test key"); } wz_test = token; break; }; } return true; }
void ReqLogin::ChooseMode() { TheResearchCalendar::Instance()->Clear(); GameMode gm = AMJU_MODE_NO_GAME; bool doCogTests = false; PXml research = m_xml.getChildNode(5); if (SafeStrCmp(research.getName(), "research")) { // Schedule - for calendar PXml p = research.getChildNode(4); if (SafeStrCmp(p.getName(), "dates")) { Time today(Time::Now()); today.RoundDown(TimePeriod(ONE_DAY_IN_SECONDS)); // Bunch of dates - add to TheResearchCal int numDates = p.nChildNode(); for (int i = 0; i < numDates; i++) { PXml date = p.getChildNode(i); if (SafeStrCmp(date.getName(), "date")) { if (SafeStrCmp(date.getChildNode(0).getName(), "timestamp") && SafeStrCmp(date.getChildNode(1).getName(), "cogtest") && SafeStrCmp(date.getChildNode(2).getName(), "play")) { std::string dateStr = date.getChildNode(0).getText(); bool cogtest = SafeStrCmp(date.getChildNode(1).getText(), "1"); bool play = SafeStrCmp(date.getChildNode(2).getText(), "1"); Time t(dateStr); t.RoundDown(TimePeriod(ONE_DAY_IN_SECONDS)); if (t == today) { // Cog tests already done today ? Results results = TheCogTestResults::Instance()->GetResultsForDate(Time::Now()); if (results.empty()) { doCogTests = cogtest; } else { doCogTests = false; std::cout << "Test results for today are here already.\n"; } if (play) { gm = AMJU_MODE_MULTI; } if (doCogTests && !play) { // Create dummy target for heart count, etc CreateDummyLocalPlayer(); } } TheResearchCalendar::Instance()->AddResearchDate(ResearchDate(Time(dateStr), cogtest, play)); } else { std::cout << "Login: unexpected format for session dates.\n"; Assert(0); } } } } else { std::cout << "Login: found research element but no schedule.\n"; } } else { std::cout << "No research element in login.pl response?!?\n"; Assert(0); } // Now we can look up today on the calendar to get game mode flags. ResetLocalPlayerFuelCount(); SetGameMode(gm); // TODO handle edit mode - send extra flag to login.pl ?? SetDoCogTests(doCogTests); // mode, in GameMode TheGSCalendar::Instance()->SetPrevState(TheGSToday::Instance()); TheGSThanks::Instance()->SetPrevState(TheGSToday::Instance()); TheGame::Instance()->SetCurrentState(TheGSThanks::Instance()); TheGSMain::Instance()->ResetHud(); }
// Creation void VoxGame::Create(VoxSettings* pVoxSettings) { m_pRenderer = NULL; m_pGameCamera = NULL; m_pQubicleBinaryManager = NULL; m_pPlayer = NULL; m_pChunkManager = NULL; m_GUICreated = false; m_pVoxSettings = pVoxSettings; m_pVoxApplication = new VoxApplication(this, m_pVoxSettings); m_pVoxWindow = new VoxWindow(this, m_pVoxSettings); // Create application and window m_pVoxApplication->Create(); m_pVoxWindow->Create(); /* Setup the FPS and deltatime counters */ #ifdef _WIN32 QueryPerformanceCounter(&m_fpsPreviousTicks); QueryPerformanceCounter(&m_fpsCurrentTicks); QueryPerformanceFrequency(&m_fpsTicksPerSecond); #else struct timeval tm; gettimeofday(&tm, NULL); m_fpsCurrentTicks = (double)tm.tv_sec + (double)tm.tv_usec / 1000000.0; m_fpsPreviousTicks = (double)tm.tv_sec + (double)tm.tv_usec / 1000000.0; #endif //_WIN32 m_deltaTime = 0.0f; m_fps = 0.0f; /* Setup the initial starting wait timing */ m_initialWaitTimer = 0.0f; m_initialWaitTime = 0.5f; m_initialStartWait = true; /* Create the renderer */ m_windowWidth = m_pVoxWindow->GetWindowWidth(); m_windowHeight = m_pVoxWindow->GetWindowHeight(); m_pRenderer = new Renderer(m_windowWidth, m_windowHeight, 32, 8); /* Create the GUI */ m_pGUI = new OpenGLGUI(m_pRenderer); /* Create cameras */ m_pGameCamera = new Camera(m_pRenderer); m_pGameCamera->SetPosition(vec3(8.0f, 8.25f, 15.5f)); m_pGameCamera->SetFakePosition(m_pGameCamera->GetPosition()); m_pGameCamera->SetFacing(vec3(0.0f, 0.0f, -1.0f)); m_pGameCamera->SetUp(vec3(0.0f, 1.0f, 0.0f)); m_pGameCamera->SetRight(vec3(1.0f, 0.0f, 0.0f)); /* Create viewports */ m_pRenderer->CreateViewport(0, 0, m_windowWidth, m_windowHeight, 60.0f, &m_defaultViewport); /* Create fonts */ m_pRenderer->CreateFreeTypeFont("media/fonts/arial.ttf", 12, &m_defaultFont); /* Create lights */ m_defaultLightPosition = vec3(300.0f, 300.0f, 300.0f); m_defaultLightView = vec3(0.0f, 0.0f, 0.0f); vec3 lightDirection = m_defaultLightView - m_defaultLightPosition; m_pRenderer->CreateLight(Colour(1.0f, 1.0f, 1.0f, 1.0f), Colour(1.0f, 1.0f, 1.0f, 1.0f), Colour(0.0f, 0.0f, 0.0f, 1.0f), m_defaultLightPosition, lightDirection, 0.0f, 0.0f, 2.0f, 0.001f, 0.0f, true, false, &m_defaultLight); /* Create materials */ m_pRenderer->CreateMaterial(Colour(1.0f, 1.0f, 1.0f, 1.0f), Colour(1.0f, 1.0f, 1.0f, 1.0f), Colour(1.0f, 1.0f, 1.0f, 1.0f), Colour(0.0f, 0.0f, 0.0f, 1.0f), 64, &m_defaultMaterial); /* Create the frame buffers */ bool frameBufferCreated = false; frameBufferCreated = m_pRenderer->CreateFrameBuffer(-1, true, true, true, true, m_windowWidth, m_windowHeight, 1.0f, "SSAO", &m_SSAOFrameBuffer); frameBufferCreated = m_pRenderer->CreateFrameBuffer(-1, true, true, true, true, m_windowWidth, m_windowHeight, 5.0f, "Shadow", &m_shadowFrameBuffer); frameBufferCreated = m_pRenderer->CreateFrameBuffer(-1, true, true, true, true, m_windowWidth, m_windowHeight, 1.0f, "Deferred Lighting", &m_lightingFrameBuffer); frameBufferCreated = m_pRenderer->CreateFrameBuffer(-1, true, true, true, true, m_windowWidth, m_windowHeight, 1.0f, "Transparency", &m_transparencyFrameBuffer); frameBufferCreated = m_pRenderer->CreateFrameBuffer(-1, true, true, true, true, m_windowWidth, m_windowHeight, 1.0f, "FXAA", &m_FXAAFrameBuffer); frameBufferCreated = m_pRenderer->CreateFrameBuffer(-1, true, true, true, true, m_windowWidth, m_windowHeight, 1.0f, "FullScreen 1st Pass", &m_firstPassFullscreenBuffer); frameBufferCreated = m_pRenderer->CreateFrameBuffer(-1, true, true, true, true, m_windowWidth, m_windowHeight, 1.0f, "FullScreen 2nd Pass", &m_secondPassFullscreenBuffer); /* Create the shaders */ bool shaderLoaded = false; m_defaultShader = -1; m_phongShader = -1; m_SSAOShader = -1; m_shadowShader = -1; m_lightingShader = -1; m_textureShader = -1; m_fxaaShader = -1; m_blurVerticalShader = -1; m_blurHorizontalShader = -1; shaderLoaded = m_pRenderer->LoadGLSLShader("media/shaders/default.vertex", "media/shaders/default.pixel", &m_defaultShader); shaderLoaded = m_pRenderer->LoadGLSLShader("media/shaders/phong.vertex", "media/shaders/phong.pixel", &m_phongShader); shaderLoaded = m_pRenderer->LoadGLSLShader("media/shaders/shadow.vertex", "media/shaders/shadow.pixel", &m_shadowShader); shaderLoaded = m_pRenderer->LoadGLSLShader("media/shaders/texture.vertex", "media/shaders/texture.pixel", &m_textureShader); shaderLoaded = m_pRenderer->LoadGLSLShader("media/shaders/fullscreen/SSAO.vertex", "media/shaders/fullscreen/SSAO.pixel", &m_SSAOShader); shaderLoaded = m_pRenderer->LoadGLSLShader("media/shaders/fullscreen/fxaa.vertex", "media/shaders/fullscreen/fxaa.pixel", &m_fxaaShader); shaderLoaded = m_pRenderer->LoadGLSLShader("media/shaders/fullscreen/lighting.vertex", "media/shaders/fullscreen/lighting.pixel", &m_lightingShader); shaderLoaded = m_pRenderer->LoadGLSLShader("media/shaders/fullscreen/blur_vertical.vertex", "media/shaders/fullscreen/blur_vertical.pixel", &m_blurVerticalShader); shaderLoaded = m_pRenderer->LoadGLSLShader("media/shaders/fullscreen/blur_horizontal.vertex", "media/shaders/fullscreen/blur_horizontal.pixel", &m_blurHorizontalShader); /* Create the chunk manager*/ m_pChunkManager = new ChunkManager(m_pRenderer, m_pVoxSettings); m_pChunkManager->SetStepLockEnabled(m_pVoxSettings->m_stepUpdating); /* Create the qubicle binary file manager */ m_pQubicleBinaryManager = new QubicleBinaryManager(m_pRenderer); /* Create the lighting manager */ m_pLightingManager = new LightingManager(m_pRenderer); /* Create the block particle manager */ m_pBlockParticleManager = new BlockParticleManager(m_pRenderer); /* Create the player */ m_pPlayer = new Player(m_pRenderer, m_pChunkManager, m_pQubicleBinaryManager, m_pLightingManager, m_pBlockParticleManager); /* Create the frontend manager */ m_pFrontendManager = new FrontendManager(m_pRenderer); /* Create module and manager linkage */ m_pChunkManager->SetPlayer(m_pPlayer); /* Initial chunk creation (Must be after player pointer sent to chunks) */ m_pChunkManager->InitializeChunkCreation(); // Keyboard movement m_bKeyboardForward = false; m_bKeyboardBackward = false; m_bKeyboardStrafeLeft = false; m_bKeyboardStrafeRight = false; m_bKeyboardLeft = false; m_bKeyboardRight = false; m_bKeyboardUp = false; m_bKeyboardDown = false; m_bKeyboardSpace = false; // Joystick flags m_bJoystickJump = false; // Combat flags m_bAttackPressed_Mouse = false; m_bAttackReleased_Mouse = false; m_bAttackPressed_Joystick = false; m_bAttackReleased_Joystick = false; m_bCanDoAttack_Mouse = true; m_bCanDoAttack_Joystick = true; // Camera movement m_bCameraRotate = false; m_pressedX = 0; m_pressedY = 0; m_currentX = 0; m_currentY = 0; m_cameraDistance = m_pGameCamera->GetZoomAmount(); m_maxCameraDistance = m_cameraDistance; m_autoCameraMovingModifier = 1.0f; // Player movement m_keyboardMovement = false; m_gamepadMovement = false; m_movementSpeed = 0.0f; m_movementDragTime = 0.45f; m_movementIncreaseTime = 0.25f; m_maxMovementSpeed = 10.0f; m_movementStopThreshold = 0.05f; // Toggle flags m_deferredRendering = true; m_modelWireframe = false; m_modelAnimationIndex = 0; m_multiSampling = true; m_ssao = true; m_blur = false; m_shadows = true; m_dynamicLighting = true; m_animationUpdate = true; m_fullscreen = m_pVoxSettings->m_fullscreen; m_debugRender = false; m_instanceRender = true; // Camera mode m_cameraMode = CameraMode_Debug; m_previousCameraMode = CameraMode_Debug; // Game mode m_gameMode = GameMode_Debug; SetGameMode(m_gameMode); /* Create, setup and skin the GUI components */ CreateGUI(); SetupGUI(); SkinGUI(); }
/** * Second half of command line parsing. See ParseCommandLineEarly() for * the first half. Note that render mode must come before resolution flag. * \param argc number of arguments given * \param argv string array of the arguments * \return Returns true on success, false on error */ bool ParseCommandLine(int argc, const char **argv) { poptContext poptCon = poptGetContext(NULL, argc, argv, getOptionsTable(), 0); int iOption; /* loop through command line */ while ((iOption = poptGetNextOpt(poptCon)) > 0) { const char *token; CLI_OPTIONS option = (CLI_OPTIONS)iOption; switch (option) { case CLI_DEBUG: case CLI_DEBUGFILE: case CLI_FLUSHDEBUGSTDERR: case CLI_CONFIGDIR: case CLI_HELP: case CLI_VERSION: // These options are parsed in ParseCommandLineEarly() already, so ignore them break; case CLI_NOASSERT: kf_NoAssert(); break; // NOTE: The sole purpose of this is to test the crash handler. case CLI_CRASH: CauseCrash = true; NetPlay.bComms = false; sstrcpy(aLevelName, "CAM_3A"); SetGameMode(GS_NORMAL); break; case CLI_DATADIR: // retrieve the quoted path name token = poptGetOptArg(poptCon); if (token == NULL) { qFatal("Unrecognised datadir"); } sstrcpy(datadir, token); break; case CLI_FULLSCREEN: war_setFullscreen(true); break; case CLI_CONNECTTOIP: //get the ip we want to connect with, and go directly to join screen. token = poptGetOptArg(poptCon); if (token == NULL) { qFatal("No IP/hostname given"); } sstrcpy(iptoconnect, token); break; case CLI_HOSTLAUNCH: // go directly to host screen, bypass all others. hostlaunch = true; break; case CLI_GAME: // retrieve the game name token = poptGetOptArg(poptCon); if (token == NULL || (strcmp(token, "CAM_1A") && strcmp(token, "CAM_2A") && strcmp(token, "CAM_3A") && strcmp(token, "TUTORIAL3") && strcmp(token, "FASTPLAY"))) { qFatal("The game parameter requires one of the following keywords:" "CAM_1A, CAM_2A, CAM_3A, TUTORIAL3, or FASTPLAY."); } NetPlay.bComms = false; bMultiPlayer = false; bMultiMessages = false; NetPlay.players[0].allocated = true; if (!strcmp(token, "CAM_1A") || !strcmp(token, "CAM_2A") || !strcmp(token, "CAM_3A")) { game.type = CAMPAIGN; } else { game.type = SKIRMISH; // tutorial is skirmish for some reason } sstrcpy(aLevelName, token); SetGameMode(GS_NORMAL); break; case CLI_MOD_GLOB: { unsigned int i; // retrieve the file name token = poptGetOptArg(poptCon); if (token == NULL) { qFatal("Missing mod name?"); } // Find an empty place in the global_mods list for (i = 0; i < 100 && global_mods[i] != NULL; ++i) {} if (i >= 100 || global_mods[i] != NULL) { qFatal("Too many mods registered! Aborting!"); } global_mods[i] = strdup(token); break; } case CLI_MOD_CA: { unsigned int i; // retrieve the file name token = poptGetOptArg(poptCon); if (token == NULL) { qFatal("Missing mod name?"); } // Find an empty place in the campaign_mods list for (i = 0; i < 100 && campaign_mods[i] != NULL; ++i) {} if (i >= 100 || campaign_mods[i] != NULL) { qFatal("Too many mods registered! Aborting!"); } campaign_mods[i] = strdup(token); break; } case CLI_MOD_MP: { unsigned int i; // retrieve the file name token = poptGetOptArg(poptCon); if (token == NULL) { qFatal("Missing mod name?"); } for (i = 0; i < 100 && multiplay_mods[i] != NULL; ++i) {} if (i >= 100 || multiplay_mods[i] != NULL) { qFatal("Too many mods registered! Aborting!"); } multiplay_mods[i] = strdup(token); break; } case CLI_RESOLUTION: { unsigned int width, height; token = poptGetOptArg(poptCon); if (sscanf(token, "%ix%i", &width, &height) != 2) { qFatal("Invalid parameter specified (format is WIDTHxHEIGHT, e.g. 800x600)"); } if (width < 640) { debug(LOG_ERROR, "Screen width < 640 unsupported, using 640"); width = 640; } if (height < 480) { debug(LOG_ERROR, "Screen height < 480 unsupported, using 480"); height = 480; } // tell the display system of the desired resolution pie_SetVideoBufferWidth(width); pie_SetVideoBufferHeight(height); // and update the configuration war_SetWidth(width); war_SetHeight(height); break; } case CLI_SAVEGAME: // retrieve the game name token = poptGetOptArg(poptCon); if (token == NULL) { qFatal("Unrecognised savegame name"); } snprintf(saveGameName, sizeof(saveGameName), "%s/%s", SaveGamePath, token); SetGameMode(GS_SAVEGAMELOAD); break; case CLI_WINDOW: war_setFullscreen(false); break; case CLI_SHADOWS: setDrawShadows(true); break; case CLI_NOSHADOWS: setDrawShadows(false); break; case CLI_SOUND: war_setSoundEnabled(true); break; case CLI_NOSOUND: war_setSoundEnabled(false); break; case CLI_TEXTURECOMPRESSION: wz_texture_compression = GL_COMPRESSED_RGBA_ARB; break; case CLI_NOTEXTURECOMPRESSION: wz_texture_compression = GL_RGBA; break; }; } return true; }
static void OnEditButton() { SetGameMode(AMJU_MODE_EDIT); TheGame::Instance()->SetCurrentState(TheGSChoosePlayer::Instance()); }
void CreateGameScreen::ModeSelected(MyGUI::ComboBox* sender, size_t index) { int newMode = *_comboGameMode->getItemDataAt<int>(index, false); SetGameMode(newMode); }