//clicks and mice player related void ADA2UE4Creature::OnClick(UPrimitiveComponent* HitComp, FKey ButtonClicked) { if (GetGameMode() == EGameMode::GM_COMBAT || IsObjectHostile(this, GetHero())) { #ifdef DEBUG LogWarning("player attacks " + this->GetName()); #endif // DEBUG } else if (GetGameMode() == EGameMode::GM_EXPLORE && CONVERSATION != 0) { #ifdef DEBUG LogWarning("clicked on " + this->GetName() + " with conv ID " + IntToString(CONVERSATION) + " | time for GM_CONVERSATION"); #endif // DEBUG FGameEvent ev = FGameEvent(EVENT_TYPE_CONVERSATION); ev = SetEventObject(ev, this); SignalEvent(GetHero(), ev); } #ifdef DEBUG else LogError("unknown click action with game mode " + IntToString(static_cast<uint8>(GetGameMode()))); #endif // DEBUG }
void FuelCellManager::OnLocationEntry() { if (GetGameMode() == AMJU_MODE_EDIT) { // Add node to Scene Graph m_sceneNode = new Ve1Node(this); SceneNode* root = GetVe1SceneGraph()->GetRootNode(SceneGraph::AMJU_OPAQUE); Assert(root); root->AddChild(m_sceneNode); m_sceneNode->SetAABB(m_aabb); } // else... ???? // Create fuel cells static int id = 20000; for (int i = 0; i < 10; i++) { FuelCell* f = new FuelCell; f->SetId(id++); float s = ROConfig()->GetFloat("fuel-cell-spread", 200.0f); Vec3f r(Rnd(-s, s), Rnd(0, s), Rnd(-s, s)); Vec3f p = GetPos() + r; if (TerrainReady()) { GetTerrain()->GetCollisionMesh()->GetY(Vec2f(p.x, p.z), &p.y); // TODO TEMP TEST Set all food to y = 0 } f->SetPos(p); f->Load(0); TheGame::Instance()->AddGameObject(f); f->OnLocationEntry(); } }
/*! * The mainloop. * Fetches events, executes appropriate code */ void mainLoop(void) { frameUpdate(); // General housekeeping // Screenshot key is now available globally if (keyPressed(KEY_F10)) { kf_ScreenDump(); inputLoseFocus(); // remove it from input stream } if (NetPlay.bComms || focusState == FOCUS_IN || !war_GetPauseOnFocusLoss()) { if (loop_GetVideoStatus()) { videoLoop(); // Display the video if neccessary } else switch (GetGameMode()) { case GS_NORMAL: // Run the gameloop code runGameLoop(); break; case GS_TITLE_SCREEN: // Run the titleloop code runTitleLoop(); break; default: break; } realTimeUpdate(); // Update realTime. } // Feed a bit of randomness into libcrypto. unsigned buf[] = {mouseX(), mouseY(), realTime, graphicsTime, gameTime, (unsigned) rand(), 4}; // http://xkcd.com/221/ RAND_add(buf, sizeof(buf), 1); }
void VoxGame::UpdateMouseControls(float dt) { GameMode gameMode = GetGameMode(); if (gameMode == GameMode_Debug || m_cameraMode == CameraMode_Debug) { if (m_bCameraRotate) { MouseCameraRotate(); } } else if (gameMode == GameMode_Game) { if (m_cameraMode == CameraMode_MouseRotate) { MouseCameraRotate(); } if (m_cameraMode == CameraMode_AutoCamera) { /* Do nothing, camera rotation is not controlled by player. */ } else if (m_cameraMode == CameraMode_FirstPerson) { MouseCameraRotate(); } } }
/** Sets console text color depending on message type */ static void setConsoleTextColor(SDWORD player) { // System messages if(player == SYSTEM_MESSAGE) { iV_SetTextColour(WZCOL_CONS_TEXT_SYSTEM); } else if (player == NOTIFY_MESSAGE) { iV_SetTextColour(WZCOL_YELLOW); } else { // Don't use friend-foe colors in the lobby if(bEnemyAllyRadarColor && (GetGameMode() == GS_NORMAL)) { if(aiCheckAlliances(player,selectedPlayer)) { iV_SetTextColour(WZCOL_CONS_TEXT_USER_ALLY); } else { iV_SetTextColour(WZCOL_CONS_TEXT_USER_ENEMY); } } else { // Friend-foe is off iV_SetTextColour(WZCOL_CONS_TEXT_USER); } } }
void VoxGame::MouseScroll(double x, double y) { GameMode gameMode = GetGameMode(); if (m_pPlayer->IsDead() == false || (gameMode == GameMode_Debug || m_cameraMode == CameraMode_Debug)) { if (m_bPaused == false) { if (m_pPlayer->GetTargetEnemy() == NULL) // Don't allow mouse zooming when we are an enemy target. { if (IsCursorOn() == false || !m_pGUI->IsMouseInteractingWithGUIComponent(false)) { if (m_cameraMode != CameraMode_FirstPerson) { m_maxCameraDistance += (float)(-y*0.5f); WrapCameraZoomValue(); } else { if (y < 0.0f) { m_cameraDistance = 2.0f; m_maxCameraDistance = 2.0f; } } } } } } }
//============================================================================= // 更新処理 //============================================================================= void UpdateTimeCounter(void) { if(*GetIsPlay() == true && !*GetIsPause()) { g_nFrameCounter++; if(g_nFrameCounter % 6 == 0) { g_nTimeCounter.fCurrentTime += 0.1f; g_nTimeCounter.fPlaybarTime += 0.1f; } } else if(*GetIsStop() == true) { g_nTimeCounter.fCurrentTime = 0; g_nTimeCounter.fPlaybarTime = 0; } // 添加时间轴判断进行时间复位 if(g_nTimeCounter.fCurrentTime >= *PlaybarNum() * TIME_5) { g_nTimeCounter.fCurrentTime = 0; //g_nTimeCounter.fPlaybarTime = 0; bIsTimeReCount = true; } // ゲームモードだけ表示する if(*GetGameMode() == SELECTMODE_PLAY) { PrintDebugProc("SystemTime : %f\n", g_nTimeCounter.fCurrentTime); PrintDebugProc("PlaybarTime : %f\n", g_nTimeCounter.fPlaybarTime); } }
/*! * The mainloop. * Fetches events, executes appropriate code */ void mainLoop(void) { frameUpdate(); // General housekeeping // Screenshot key is now available globally if (keyPressed(KEY_F10)) { kf_ScreenDump(); inputLoseFocus(); // remove it from input stream } if (NetPlay.bComms || focusState == FOCUS_IN || !war_GetPauseOnFocusLoss()) { if (loop_GetVideoStatus()) { videoLoop(); // Display the video if neccessary } else switch (GetGameMode()) { case GS_NORMAL: // Run the gameloop code runGameLoop(); break; case GS_TITLE_SCREEN: // Run the titleloop code runTitleLoop(); break; default: break; } realTimeUpdate(); // Update realTime. } }
void VoxGame::UpdateMouseControls(float dt) { GameMode gameMode = GetGameMode(); if (gameMode == GameMode_Debug || m_cameraMode == CameraMode_Debug) { if (m_bCameraRotate) { MouseCameraRotate(); } } else if (gameMode == GameMode_Game) { if (m_pPlayer->IsDead() == false) { if (m_bPaused == false) // If we are paused, don't allow gameplay control movements { if (IsGUIWindowStillDisplayed() == false) { if (m_cameraMode == CameraMode_MouseRotate) { MouseCameraRotate(); } else if (m_cameraMode == CameraMode_AutoCamera) { /* Do nothing, camera rotation is not controlled by player. */ } else if (m_cameraMode == CameraMode_FirstPerson) { MouseCameraRotate(); } } } } } }
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 cPlayer::UseEquippedItem(void) { if (GetGameMode() == gmCreative) // No damage in creative { return; } GetInventory().DamageEquippedItem(); }
void ObjectManager::SetLocalPlayerLocation(int newLocation) { if (m_location == newLocation) { std::cout << "Er, setting location to current value!\n"; // We want to download new location mesh etc.... if (GetGameMode() != AMJU_MODE_EDIT) { //return; } } // Why not do this ?? if (GetLocalPlayer()) { GetLocalPlayer()->SetLocation(newLocation); } m_location = newLocation; TheGame::Instance()->ClearGameObjects(); // If using Sweep and Prune for collisions, clear list of objects ////TheSAP::Instance()->Clear(); ClearVe1SceneGraph(); // Clear the current terrain, which is the important thing the new location must have! ClearTerrain(); //std::cout << " ..old location trashed, adding game objects in new location...\n"; for (GameObjects::iterator it = m_allGameObjects.begin(); it != m_allGameObjects.end(); ++it) { PGameObject go = it->second; Ve1Object* v = dynamic_cast<Ve1Object*>(go.GetPtr()); if (v) { if (v->GetLocation() == m_location) { //std::cout << " ..Game object: " << go->GetTypeName() << ", id: " << go->GetId() << "\n"; AddGameObjectToGame(go); ////TheGame::Instance()->AddGameObject(go); ////TheSAP::Instance()->AddBox(go); v->OnLocationEntry(); } } else { std::cout << "Rather unexpected type of game object: " << go->GetTypeName() << ", id: " << go->GetId() << "\n"; AddGameObjectToGame(go); ////TheGame::Instance()->AddGameObject(go); } } // Change to waiting state: some objects required for this new location might not exist yet TheGame::Instance()->SetCurrentState(TheGSFileUpdateCheck::Instance()); //TheGSWaitForNewLocation::Instance()); }
void ADA2UE4Creature::BeginCursorOver(UPrimitiveComponent* HitComp) { if (GetCurrentWorld()) { if (GROUP == GROUP_HOSTILE || GROUP == GROUP_HOSTILE_ON_GROUND) { SetOutline(STENCIL_ENEMY_OUTLINE, true); GetCurrentPlayerController()->HandleCursorUpdate("attack"); } else if (GROUP == GROUP_FRIENDLY || GROUP == GROUP_PC) { if (GetGameMode() == EGameMode::GM_EXPLORE || GetGameMode() == EGameMode::GM_COMBAT) { SetOutline(STENCIL_FRIENDLY_OUTLINE, true); } if (GetGameMode() == EGameMode::GM_EXPLORE && CONVERSATION != 0) { GetCurrentPlayerController()->HandleCursorUpdate("conversation"); } } else //if (GROUP == GROUP_NEUTRAL) { if (GetGameMode() == EGameMode::GM_EXPLORE || GetGameMode() == EGameMode::GM_COMBAT) { SetOutline(STENCIL_NEUTRAL_OUTLINE, true); } if (GetGameMode() == EGameMode::GM_EXPLORE && CONVERSATION != 0) { GetCurrentPlayerController()->HandleCursorUpdate("conversation"); } } } }
void OnCogTestsAllDone() { GameMode gm = GetGameMode(); if (gm == AMJU_MODE_NO_GAME || gm == AMJU_MODE_NONE) { TheGame::Instance()->SetCurrentState(TheGSFinishedTests::Instance()); } else { TheGame::Instance()->SetCurrentState(TheGSStartGame::Instance()); } TheGSCogTestMenu::Instance()->ResetTests(); }
void FuelCellManager::Update() { Ve1Object::Update(); m_aabb.Set( m_pos.x - XSIZE, m_pos.x + XSIZE, m_pos.y, m_pos.y + YSIZE, m_pos.z - XSIZE, m_pos.z + XSIZE); if (GetGameMode() == AMJU_MODE_EDIT) { m_sceneNode->SetAABB(m_aabb); } }
/** Displays all the console messages */ void displayConsoleMessages(void) { // Check if we have any messages we want to show if (!getNumberConsoleMessages() && !bConsoleDropped && !InfoMessages.size()) { return; } // scripts can disable the console if (!bConsoleDisplayEnabled && !InfoMessages.size()) { return; } iV_SetFont(font_regular); pie_SetDepthBufferStatus(DEPTH_CMP_ALWAYS_WRT_ON); pie_SetFogStatus(false); if (bConsoleDropped) { displayOldMessages(HistoryMode); } std::lock_guard<wz::mutex> lck(mtx); // Don't iterate without a lock. if (InfoMessages.size()) { auto i = InfoMessages.end() - 1; // we can only show the last one... setConsoleTextColor(i->player); int tmp = pie_GetVideoBufferWidth(); drawBlueBox(0, 0,tmp, 18); tmp -= iV_GetTextWidth(i->text.c_str()); iV_DrawFormattedText(i->text.c_str(), tmp - 6, linePitch - 2, iV_GetTextWidth(i->text.c_str()), i->JustifyType); } int TextYpos = mainConsole.topY; // Draw the blue background for the text (only in game, not lobby) if (bTextBoxActive && GetGameMode() == GS_NORMAL) { iV_TransBoxFill(mainConsole.topX - CON_BORDER_WIDTH, mainConsole.topY - mainConsole.textDepth - CON_BORDER_HEIGHT, mainConsole.topX + mainConsole.width, mainConsole.topY + (getNumberConsoleMessages() * linePitch) + CON_BORDER_HEIGHT - linePitch); } for (auto i = ActiveMessages.begin(); i != ActiveMessages.end(); ++i) { setConsoleTextColor(i->player); TextYpos = iV_DrawFormattedText(i->text.c_str(), mainConsole.topX, TextYpos, mainConsole.width, i->JustifyType); } }
void ObjectManager::OnObjectChangeLocation(int objId) { // No such object - OK if we are in edit mode and have just created it if (m_allGameObjects.find(objId) == m_allGameObjects.end()) { return; } // TODO Handle objects leaving the local player location Assert(m_allGameObjects.find(objId) != m_allGameObjects.end()); PGameObject go = m_allGameObjects[objId]; Ve1Object* v = dynamic_cast<Ve1Object*>(go.GetPtr()); if (v) { if (v->GetLocation() == m_location) { AddGameObjectToGame(go); #ifdef LOCATION_DEBUG std::cout << "Added game object " << go->GetId() << " (" << go->GetTypeName() << ") to our location (" << m_location << ")\n"; #endif if (GetGameMode() == AMJU_MODE_EDIT) { v->CreateEditNode(); } v->OnLocationEntry(); } else { #ifdef LOCATION_DEBUG std::cout << "Game object " << objId << " changed location but is not in our location (" << m_location << ")\n"; #endif TheGame::Instance()->EraseGameObject(objId); v->OnLocationExit(); } } else { AddGameObjectToGame(go); ////TheGame::Instance()->AddGameObject(go); } }
static void OnQuitYes() { GameMode gm = GetGameMode(); if (gm == AMJU_MODE_NO_GAME || gm == AMJU_MODE_NONE) { // Log out, you can't go to the game. Or go to GSThanks/GSToday? TheGSLogout::Instance()->SetPrevState(TheGSTitle::Instance()); TheGame::Instance()->SetCurrentState(TheGSLogout::Instance()); } else { // Go back to Main, will nag again later. TheGame::Instance()->SetCurrentState(TheGSStartGame::Instance()); LurkMsg lm("OK, but please finish taking the tests soon! I will ask you again later.", LURK_FG, LURK_BG, AMJU_CENTRE); TheLurker::Instance()->Queue(lm); } }
void ObjectManager::AddObject(PObject obj) { if (m_objects.find(obj) != m_objects.end()) { // Shouldn't happen because we are supposed to be getting new objects since the last time // we checked, right ? if (GetGameMode() == AMJU_MODE_EDIT) { std::cout << "*** INFO: Overwriting object " << obj->m_id << " in ObjectManager\n"; } else { std::cout << "Trying to add duplicate object to object manager list!\n"; return; } } m_objects.insert(obj); // Get the asset list and data file if we haven't already if (!obj->m_datafile.empty() && obj->m_datafile != "none") { QGetFile(obj->m_datafile); } // See if we have already got the asset list (because we already found another object of the same type, etc.) const std::string& assetlistname = obj->m_assetlist; if (!assetlistname.empty() && assetlistname != "none") { if (m_assetLists.find(assetlistname) == m_assetLists.end()) { // Asset List not yet created AssetList* assetlist = new AssetList(assetlistname); m_assetLists[assetlistname] = assetlist; QGetFile(assetlistname); } } // Later we check state of asset list and datafile... }
void ADA2UE4Creature::Tick(float DeltaSeconds) { if (CursorToWorld != nullptr) { if (APlayerController* PC = Cast<APlayerController>(GetController())) { FHitResult TraceHitResult; PC->GetHitResultUnderCursor(ECC_Visibility, true, TraceHitResult); FVector CursorFV = TraceHitResult.ImpactNormal; FRotator CursorR = CursorFV.Rotation(); CursorToWorld->SetWorldLocation(TraceHitResult.Location); CursorToWorld->SetWorldRotation(CursorR); } } UDA2UE4AnimInstance* AnimInstance = Cast<UDA2UE4AnimInstance>(MeshHEDComponent->GetAnimInstance()); if (AnimInstance && AnimInstance->NotifyQueue.AnimNotifies.Num() > 0 && GetGameMode() == EGameMode::GM_CONVERSATION && bBlend == FALSE_) { LogWarning("!"); } }
void OnCogTestStopPartWayThrough() { GameMode gm = GetGameMode(); if (gm == AMJU_MODE_NO_GAME || gm == AMJU_MODE_NONE) { // You can't play the game, you have to finish the tests. TheGSDoThoseCogTests::Instance()->SetPrevState(TheGSCogTestMenu::Instance()); TheGame::Instance()->SetCurrentState(TheGSDoThoseCogTests::Instance()); } else { // Go back to Main, will nag again later. TheGame::Instance()->SetCurrentState(TheGSStartGame::Instance()); // TODO Log number of declines for research stops++; LurkMsg lm("OK, but please finish taking the tests soon! I will ask you again in a few minutes.", LURK_FG, LURK_BG, AMJU_CENTRE); TheLurker::Instance()->Queue(lm); nagdone = false; cogtesttime = 0; } }
void * EiC_ymalloc(char *file, int lineno, size_t nbytes) { void * pheap; if(GetGameMode()) { unsigned long total = EiC_tot_memory + nbytes; if(total > gedMaxGameMem) //maks { //Don't alloc more then gedMaxGameMem EiC_error("Attempt to access %lu bytes.\n If is correct, set the variable gedMaxGameMem=%lu or more\n in an action before the allocation", nbytes, total); nbytes = 4; } } realAllocatedMem = nbytes; pheap = (malloc)(nbytes); if(pheap) memset(pheap,0, realAllocatedMem/*nelems * elems*/); //maks assertp(pheap==NULL,STDMSG); install(file,lineno,pheap,nbytes); return pheap; }
void VoxGame::KeyReleased(int key, int scancode, int mods) { m_pGUI->KeyReleased(key, mods); if (m_pGUI->IsKeyboardInteractingWithGUIComponent() && key != GLFW_KEY_ESCAPE) { return; // For textbox entry } switch (key) { // Player movement case GLFW_KEY_W: { m_bKeyboardForward = false; break; } case GLFW_KEY_S: { m_bKeyboardBackward = false; break; } case GLFW_KEY_A: { m_bKeyboardLeft = false; m_bKeyboardStrafeLeft = false; break; } case GLFW_KEY_D: { m_bKeyboardRight = false; m_bKeyboardStrafeRight = false; break; } case GLFW_KEY_F: { m_bKeyboardUp = false; break; } case GLFW_KEY_V: { m_bKeyboardDown = false; break; } case GLFW_KEY_SPACE: { m_bKeyboardSpace = false; break; } case GLFW_KEY_ESCAPE: { m_bKeyboardMenu = false; break; } case GLFW_KEY_O: { if (STEAM_BUILD == false) { m_pDebugCameraOptionBox->SetToggled(true); CameraModeChanged(); } break; } case GLFW_KEY_L: { if (STEAM_BUILD == false) { SetPaused(!IsPaused()); } break; } case GLFW_KEY_P: { if (STEAM_BUILD == false) { if (m_pGUI->IsKeyboardInteractingWithGUIComponent() == false) { if (m_pMainWindow->IsVisible() == false) { ShowGUI(); } else { HideGUI(); } } } break; } // Game GUI case GLFW_KEY_I: { if (GetGameMode() == GameMode_Game) { if (m_pPlayer->IsDead() == false) { if (m_pInventoryGUI->IsLoaded()) { m_pInventoryGUI->Unload(); if (VoxGame::GetInstance()->IsGUIWindowStillDisplayed() == false) { TurnCursorOff(false); } } else if (m_pFrontendManager->GetFrontendScreen() == FrontendScreen_None) { m_pInventoryGUI->Load(); m_pPlayer->StopMoving(); TurnCursorOn(false, false); } } } break; } case GLFW_KEY_C: { if (GetGameMode() == GameMode_Game) { if (m_pPlayer->IsDead() == false) { if (m_pCharacterGUI->IsLoaded()) { m_pCharacterGUI->Unload(); if (VoxGame::GetInstance()->IsGUIWindowStillDisplayed() == false) { TurnCursorOff(false); } } else if (m_pFrontendManager->GetFrontendScreen() == FrontendScreen_None) { m_pCharacterGUI->Load(); m_pPlayer->StopMoving(); TurnCursorOn(false, false); } } } break; } case GLFW_KEY_K: { if (GetGameMode() == GameMode_Game) { if (m_pPlayer->IsDead() == false) { if (m_pQuestGUI->IsLoaded()) { m_pQuestGUI->Unload(); if (VoxGame::GetInstance()->IsGUIWindowStillDisplayed() == false) { TurnCursorOff(false); } } else if (m_pFrontendManager->GetFrontendScreen() == FrontendScreen_None) { m_pQuestGUI->Load(); m_pPlayer->StopMoving(); TurnCursorOn(false, false); } } } break; } // Number keys case GLFW_KEY_1: { m_pActionBar->UseActionBarslot(0); break; } case GLFW_KEY_2: { m_pActionBar->UseActionBarslot(1); break; } case GLFW_KEY_3: { m_pActionBar->UseActionBarslot(2); break; } case GLFW_KEY_4: { m_pActionBar->UseActionBarslot(3); break; } case GLFW_KEY_5: { m_pActionBar->UseActionBarslot(4); break; } case GLFW_KEY_6: { m_pActionBar->UseActionBarslot(5); break; } case GLFW_KEY_7: { m_pActionBar->UseActionBarslot(6); break; } case GLFW_KEY_8: { m_pActionBar->UseActionBarslot(7); break; } case GLFW_KEY_9: { m_pActionBar->UseActionBarslot(8); break; } case GLFW_KEY_0: { m_pActionBar->UseActionBarslot(9); break; } } }
int realmain(int argc, char *argv[]) { // The libcrypto startup stuff... May or may not actually be needed for anything at all. ERR_load_crypto_strings(); // This is needed for descriptive error messages. OpenSSL_add_all_algorithms(); // Don't actually use the EVP functions, so probably not needed. OPENSSL_config(nullptr); // What does this actually do? #ifdef WZ_OS_WIN RAND_screen(); // Uses a screenshot as a random seed, on systems lacking /dev/random. #endif wzMain(argc, argv); int utfargc = argc; const char** utfargv = (const char**)argv; #ifdef WZ_OS_MAC cocoaInit(); #endif debug_init(); debug_register_callback( debug_callback_stderr, NULL, NULL, NULL ); #if defined(WZ_OS_WIN) && defined(DEBUG_INSANE) debug_register_callback( debug_callback_win32debug, NULL, NULL, NULL ); #endif // WZ_OS_WIN && DEBUG_INSANE // ***** // NOTE: Try *NOT* to use debug() output routines without some other method of informing the user. All this output is sent to /dev/nul at this point on some platforms! // ***** if (!getUTF8CmdLine(&utfargc, &utfargv)) { return EXIT_FAILURE; } QTextCodec::setCodecForCStrings(QTextCodec::codecForName("UTF-8")); // make Qt treat all C strings in Warzone as UTF-8 setupExceptionHandler(utfargc, utfargv, version_getFormattedVersionString()); /*** Initialize PhysicsFS ***/ initialize_PhysicsFS(utfargv[0]); /*** Initialize translations ***/ initI18n(); // find early boot info if (!ParseCommandLineEarly(utfargc, utfargv)) { return EXIT_FAILURE; } /* Initialize the write/config directory for PhysicsFS. * This needs to be done __after__ the early commandline parsing, * because the user might tell us to use an alternative configuration * directory. */ initialize_ConfigDir(); /*** Initialize directory structure ***/ make_dir(ScreenDumpPath, "screenshots", NULL); make_dir(SaveGamePath, "savegames", NULL); PHYSFS_mkdir("savegames/campaign"); PHYSFS_mkdir("savegames/skirmish"); make_dir(MultiCustomMapsPath, "maps", NULL); // MUST have this to prevent crashes when getting map PHYSFS_mkdir("music"); PHYSFS_mkdir("logs"); // a place to hold our netplay, mingw crash reports & WZ logs PHYSFS_mkdir("userdata"); // a place to store per-mod data user generated data memset(rulesettag, 0, sizeof(rulesettag)); // tag to add to userdata to find user generated stuff make_dir(MultiPlayersPath, "multiplay", NULL); make_dir(MultiPlayersPath, "multiplay", "players"); if (!customDebugfile) { // there was no custom debug file specified (--debug-file=blah) // so we use our write directory to store our logs. time_t aclock; struct tm *newtime; char buf[PATH_MAX]; time( &aclock ); // Get time in seconds newtime = localtime( &aclock ); // Convert time to struct // Note: We are using fopen(), and not physfs routines to open the file // log name is logs/(or \)WZlog-MMDD_HHMMSS.txt snprintf(buf, sizeof(buf), "%slogs%sWZlog-%02d%02d_%02d%02d%02d.txt", PHYSFS_getWriteDir(), PHYSFS_getDirSeparator(), newtime->tm_mon + 1, newtime->tm_mday, newtime->tm_hour, newtime->tm_min, newtime->tm_sec ); debug_register_callback( debug_callback_file, debug_callback_file_init, debug_callback_file_exit, buf ); // FIXME: Change this to LOG_WZ on next release debug(LOG_INFO, "Using %s debug file", buf); } // NOTE: it is now safe to use debug() calls to make sure output gets captured. check_Physfs(); debug(LOG_WZ, "Warzone 2100 - %s", version_getFormattedVersionString()); debug(LOG_WZ, "Using language: %s", getLanguage()); debug(LOG_WZ, "Backend: %s", BACKEND); debug(LOG_MEMORY, "sizeof: SIMPLE_OBJECT=%ld, BASE_OBJECT=%ld, DROID=%ld, STRUCTURE=%ld, FEATURE=%ld, PROJECTILE=%ld", (long)sizeof(SIMPLE_OBJECT), (long)sizeof(BASE_OBJECT), (long)sizeof(DROID), (long)sizeof(STRUCTURE), (long)sizeof(FEATURE), (long)sizeof(PROJECTILE)); /* Put in the writedir root */ sstrcpy(KeyMapPath, "keymap.map"); // initialise all the command line states war_SetDefaultStates(); debug(LOG_MAIN, "initializing"); PhysicsEngineHandler engine; // register abstract physfs filesystem loadConfig(); // parse the command line if (!ParseCommandLine(utfargc, utfargv)) { return EXIT_FAILURE; } // Save new (commandline) settings saveConfig(); // Find out where to find the data scanDataDirs(); // Now we check the mods to see if they exist or not (specified on the command line) // They are all capped at 100 mods max(see clparse.c) // FIX ME: I know this is a bit hackish, but better than nothing for now? { char *modname; char modtocheck[256]; int i = 0; int result = 0; // check global mods for(i=0; i < 100; i++) { modname = global_mods[i]; if (modname == NULL) { break; } ssprintf(modtocheck, "mods/global/%s", modname); result = PHYSFS_exists(modtocheck); result |= PHYSFS_isDirectory(modtocheck); if (!result) { debug(LOG_ERROR, "The (global) mod (%s) you have specified doesn't exist!", modname); } else { info("(global) mod (%s) is enabled", modname); } } // check campaign mods for(i=0; i < 100; i++) { modname = campaign_mods[i]; if (modname == NULL) { break; } ssprintf(modtocheck, "mods/campaign/%s", modname); result = PHYSFS_exists(modtocheck); result |= PHYSFS_isDirectory(modtocheck); if (!result) { debug(LOG_ERROR, "The mod_ca (%s) you have specified doesn't exist!", modname); } else { info("mod_ca (%s) is enabled", modname); } } // check multiplay mods for(i=0; i < 100; i++) { modname = multiplay_mods[i]; if (modname == NULL) { break; } ssprintf(modtocheck, "mods/multiplay/%s", modname); result = PHYSFS_exists(modtocheck); result |= PHYSFS_isDirectory(modtocheck); if (!result) { debug(LOG_ERROR, "The mod_mp (%s) you have specified doesn't exist!", modname); } else { info("mod_mp (%s) is enabled", modname); } } } if (!wzMain2(war_getFSAA(), war_getFullscreen(), war_GetVsync())) { return EXIT_FAILURE; } int w = pie_GetVideoBufferWidth(); int h = pie_GetVideoBufferHeight(); char buf[256]; ssprintf(buf, "Video Mode %d x %d (%s)", w, h, war_getFullscreen() ? "fullscreen" : "window"); addDumpInfo(buf); debug(LOG_MAIN, "Final initialization"); if (!frameInitialise()) { return EXIT_FAILURE; } if (!screenInitialise()) { return EXIT_FAILURE; } if (!pie_LoadShaders()) { return EXIT_FAILURE; } war_SetWidth(pie_GetVideoBufferWidth()); war_SetHeight(pie_GetVideoBufferHeight()); pie_SetFogStatus(false); pie_ScreenFlip(CLEAR_BLACK); pal_Init(); pie_LoadBackDrop(SCREEN_RANDOMBDROP); pie_SetFogStatus(false); pie_ScreenFlip(CLEAR_BLACK); if (!systemInitialise()) { return EXIT_FAILURE; } //set all the pause states to false setAllPauseStates(false); // Copy this info to be used by the crash handler for the dump file ssprintf(buf,"Using Backend: %s", BACKEND); addDumpInfo(buf); ssprintf(buf,"Using language: %s", getLanguageName()); addDumpInfo(buf); // Do the game mode specific initialisation. switch(GetGameMode()) { case GS_TITLE_SCREEN: startTitleLoop(); break; case GS_SAVEGAMELOAD: initSaveGameLoad(); break; case GS_NORMAL: startGameLoop(); break; default: debug(LOG_ERROR, "Weirdy game status, I'm afraid!!"); break; } #if defined(WZ_CC_MSVC) && defined(DEBUG) debug_MEMSTATS(); #endif debug(LOG_MAIN, "Entering main loop"); wzMain3(); saveConfig(); systemShutdown(); #ifdef WZ_OS_WIN // clean up the memory allocated for the command line conversion for (int i=0; i<argc; i++) { const char*** const utfargvF = &utfargv; free((void *)(*utfargvF)[i]); } free(utfargv); #endif wzShutdown(); debug(LOG_MAIN, "Completed shutting down Warzone 2100"); return EXIT_SUCCESS; }
//**************************************************************************************** // Load menu/save menu? //***************************************************************************************** static BOOL _addLoadSave(BOOL bLoad, const char *sSearchPath, const char *sExtension, const char *title) { W_FORMINIT sFormInit; W_BUTINIT sButInit; W_LABINIT sLabInit; UDWORD slotCount; // removed hardcoded values! change with the defines above! -Q static char sSlotCaps[totalslots][totalslotspace]; static char sSlotTips[totalslots][totalslotspace]; char **i, **files; const char* checkExtension; mode = bLoad; debug(LOG_SAVE, "called (%d, %s, %s, %s)", bLoad, sSearchPath, sExtension, title); if ((bLoadSaveMode == LOAD_INGAME) || (bLoadSaveMode == SAVE_INGAME)) { if (!bMultiPlayer || (NetPlay.bComms ==0)) { gameTimeStop(); if(GetGameMode() == GS_NORMAL) { BOOL radOnScreen = radarOnScreen; // Only do this in main game. bRender3DOnly = true; radarOnScreen = false; displayWorld(); // Just display the 3d, no interface pie_UploadDisplayBuffer(); // Upload the current display back buffer into system memory. radarOnScreen = radOnScreen; bRender3DOnly = false; } setGamePauseStatus( true ); setGameUpdatePause(true); setScriptPause(true); setScrollPause(true); setConsolePause(true); } forceHidePowerBar(); intRemoveReticule(); } (void) PHYSFS_mkdir(sSearchPath); // just in case psRequestScreen = widgCreateScreen(); // init the screen widgSetTipFont(psRequestScreen,font_regular); /* add a form to place the tabbed form on */ memset(&sFormInit, 0, sizeof(W_FORMINIT)); sFormInit.formID = 0; //this adds the blue background, and the "box" behind the buttons -Q sFormInit.id = LOADSAVE_FORM; sFormInit.style = WFORM_PLAIN; sFormInit.x = (SWORD) LOADSAVE_X; sFormInit.y = (SWORD) LOADSAVE_Y; sFormInit.width = LOADSAVE_W; // we need the form to be long enough for all resolutions, so we take the total number of items * height // and * the gaps, add the banner, and finally, the fudge factor ;) sFormInit.height = (slotsInColumn * LOADENTRY_H + LOADSAVE_HGAP* slotsInColumn)+ LOADSAVE_BANNER_DEPTH+20; sFormInit.disableChildren = true; sFormInit.pDisplay = intOpenPlainForm; widgAddForm(psRequestScreen, &sFormInit); // Add Banner sFormInit.formID = LOADSAVE_FORM; sFormInit.id = LOADSAVE_BANNER; sFormInit.x = LOADSAVE_HGAP; sFormInit.y = LOADSAVE_VGAP; sFormInit.width = LOADSAVE_W-(2*LOADSAVE_HGAP); sFormInit.height = LOADSAVE_BANNER_DEPTH; sFormInit.disableChildren = false; sFormInit.pDisplay = displayLoadBanner; sFormInit.UserData = bLoad; widgAddForm(psRequestScreen, &sFormInit); // Add Banner Label memset(&sLabInit, 0, sizeof(W_LABINIT)); sLabInit.formID = LOADSAVE_BANNER; sLabInit.id = LOADSAVE_LABEL; sLabInit.style = WLAB_ALIGNCENTRE; sLabInit.x = 0; sLabInit.y = 3; sLabInit.width = LOADSAVE_W-(2*LOADSAVE_HGAP); //LOADSAVE_W; sLabInit.height = LOADSAVE_BANNER_DEPTH; //This looks right -Q sLabInit.pText = title; sLabInit.FontID = font_regular; widgAddLabel(psRequestScreen, &sLabInit); // add cancel. memset(&sButInit, 0, sizeof(W_BUTINIT)); sButInit.formID = LOADSAVE_BANNER; sButInit.x = 8; sButInit.y = 8; sButInit.width = iV_GetImageWidth(IntImages,IMAGE_NRUTER); sButInit.height = iV_GetImageHeight(IntImages,IMAGE_NRUTER); sButInit.UserData = PACKDWORD_TRI(0,IMAGE_NRUTER , IMAGE_NRUTER); sButInit.id = LOADSAVE_CANCEL; sButInit.style = WBUT_PLAIN; sButInit.pTip = _("Close"); sButInit.FontID = font_regular; sButInit.pDisplay = intDisplayImageHilight; widgAddButton(psRequestScreen, &sButInit); // add slots memset(&sButInit, 0, sizeof(W_BUTINIT)); sButInit.formID = LOADSAVE_FORM; sButInit.style = WBUT_PLAIN; sButInit.width = LOADENTRY_W; sButInit.height = LOADENTRY_H; sButInit.pDisplay = displayLoadSlot; sButInit.FontID = font_regular; for(slotCount = 0; slotCount< totalslots; slotCount++) { sButInit.id = slotCount+LOADENTRY_START; if(slotCount < slotsInColumn) { sButInit.x = 22 + LOADSAVE_HGAP; sButInit.y = (SWORD)((LOADSAVE_BANNER_DEPTH +(2*LOADSAVE_VGAP)) + ( slotCount*(LOADSAVE_VGAP+LOADENTRY_H))); } else if (slotCount >= slotsInColumn && (slotCount < (slotsInColumn *2))) { sButInit.x = 22 + (2*LOADSAVE_HGAP + LOADENTRY_W); sButInit.y = (SWORD)((LOADSAVE_BANNER_DEPTH +(2* LOADSAVE_VGAP)) + ( (slotCount % slotsInColumn)*(LOADSAVE_VGAP+LOADENTRY_H))); } else { sButInit.x = 22 + (3*LOADSAVE_HGAP + (2*LOADENTRY_W)); sButInit.y = (SWORD)((LOADSAVE_BANNER_DEPTH +(2* LOADSAVE_VGAP)) + ( (slotCount % slotsInColumn)*(LOADSAVE_VGAP+LOADENTRY_H))); } widgAddButton(psRequestScreen, &sButInit); } // fill slots. slotCount = 0; sstrcpy(sPath, sSearchPath); // setup locals. sstrcpy(sExt, sExtension); debug(LOG_SAVE, "Searching \"%s\" for savegames", sSearchPath); // Check for an extension like ".ext", not "ext" sasprintf((char**)&checkExtension, ".%s", sExtension); // add savegame filenames minus extensions to buttons files = PHYSFS_enumerateFiles(sSearchPath); for (i = files; *i != NULL; ++i) { W_BUTTON *button; char savefile[256]; time_t savetime; // See if this filename contains the extension we're looking for if (!strstr(*i, checkExtension)) { // If it doesn't, move on to the next filename continue; } button = (W_BUTTON*)widgGetFromID(psRequestScreen, LOADENTRY_START + slotCount); debug(LOG_SAVE, "We found [%s]", *i); /* Figure save-time */ snprintf(savefile, sizeof(savefile), "%s/%s", sSearchPath, *i); savetime = PHYSFS_getLastModTime(savefile); sstrcpy(sSlotTips[slotCount], ctime(&savetime)); /* Set the button-text */ (*i)[strlen(*i) - 4] = '\0'; // remove .gam extension sstrcpy(sSlotCaps[slotCount], *i); //store it! /* Add button */ button->pTip = sSlotTips[slotCount]; button->pText = sSlotCaps[slotCount]; slotCount++; // goto next but... if (slotCount == totalslots) { break; } } PHYSFS_freeList(files); bLoadSaveUp = true; return true; }
// //////////////////////////////////////////////////// static BOOL _addLoadSave(BOOL bLoad,CHAR *sSearchPath,CHAR *sExtension, CHAR *title) { W_FORMINIT sFormInit; W_BUTINIT sButInit; W_LABINIT sLabInit; UDWORD slotCount; static STRING sSlots[10][64]; STRING sTemp[255]; WIN32_FIND_DATA found; HANDLE dir; mode = bLoad; if(GetCurrentDirectory(255,(char*)&sTemp) == 0) { return FALSE; // failed, directory probably didn't exist. } if ((bLoadSaveMode == LOAD_INGAME) || (bLoadSaveMode == SAVE_INGAME)) { if (!bMultiPlayer || (NetPlay.bComms ==0)) { gameTimeStop(); if(GetGameMode() == GS_NORMAL) { BOOL radOnScreen = radarOnScreen; // Only do this in main game. bRender3DOnly = TRUE; radarOnScreen = FALSE; displayWorld(); // Just display the 3d, no interface pie_UploadDisplayBuffer(DisplayBuffer); // Upload the current display back buffer into system memory. iV_ScaleBitmapRGB(DisplayBuffer,iV_GetDisplayWidth(), iV_GetDisplayHeight(),2,2,2); // Make it darker. radarOnScreen = radOnScreen; bRender3DOnly = FALSE; } setGamePauseStatus( TRUE ); setGameUpdatePause(TRUE); setScriptPause(TRUE); setScrollPause(TRUE); setConsolePause(TRUE); } forceHidePowerBar(); intRemoveReticule(); } CreateDirectory(sSearchPath,NULL); // create the directory required... fails if already there, so no problem. widgCreateScreen(&psRequestScreen); // init the screen. widgSetTipFont(psRequestScreen,WFont); /* add a form to place the tabbed form on */ memset(&sFormInit, 0, sizeof(W_FORMINIT)); sFormInit.formID = 0; sFormInit.id = LOADSAVE_FORM; sFormInit.style = WFORM_PLAIN; sFormInit.x = (SWORD)(LOADSAVE_X); sFormInit.y = (SWORD)(LOADSAVE_Y); sFormInit.width = LOADSAVE_W; sFormInit.height = LOADSAVE_H; sFormInit.disableChildren = TRUE; sFormInit.pDisplay = intOpenPlainForm; widgAddForm(psRequestScreen, &sFormInit); // Add Banner sFormInit.formID = LOADSAVE_FORM; sFormInit.id = LOADSAVE_BANNER; sFormInit.x = LOADSAVE_HGAP; sFormInit.y = LOADSAVE_VGAP; sFormInit.width = LOADSAVE_W-(2*LOADSAVE_HGAP); sFormInit.height = LOADSAVE_BANNER_DEPTH; sFormInit.disableChildren = FALSE; sFormInit.pDisplay = displayLoadBanner; sFormInit.pUserData = (VOID *)bLoad; widgAddForm(psRequestScreen, &sFormInit); // Add Banner Label memset(&sLabInit, 0, sizeof(W_LABINIT)); sLabInit.formID = LOADSAVE_BANNER; sLabInit.id = LOADSAVE_LABEL; sLabInit.style = WLAB_ALIGNCENTRE; sLabInit.x = 0; sLabInit.y = 4; sLabInit.width = LOADSAVE_W-(2*LOADSAVE_HGAP); //LOADSAVE_W; sLabInit.height = 20; sLabInit.pText = title; sLabInit.FontID = WFont; widgAddLabel(psRequestScreen, &sLabInit); // add cancel. memset(&sButInit, 0, sizeof(W_BUTINIT)); sButInit.formID = LOADSAVE_BANNER; sButInit.x = 4; sButInit.y = 3; sButInit.width = iV_GetImageWidth(IntImages,IMAGE_NRUTER); sButInit.height = iV_GetImageHeight(IntImages,IMAGE_NRUTER); sButInit.pUserData = (void*)PACKDWORD_TRI(0,IMAGE_NRUTER , IMAGE_NRUTER); sButInit.id = LOADSAVE_CANCEL; sButInit.style = WBUT_PLAIN; sButInit.pTip = strresGetString(psStringRes, STR_MISC_CLOSE); sButInit.FontID = WFont; sButInit.pDisplay = intDisplayImageHilight; widgAddButton(psRequestScreen, &sButInit); // add slots memset(&sButInit, 0, sizeof(W_BUTINIT)); sButInit.formID = LOADSAVE_FORM; sButInit.style = WBUT_PLAIN; sButInit.width = LOADENTRY_W; sButInit.height = LOADENTRY_H; sButInit.pDisplay = displayLoadSlot; sButInit.FontID = WFont; for(slotCount = 0; slotCount< 10 ; slotCount++) { sButInit.id = slotCount+LOADENTRY_START; if(slotCount<5) { sButInit.x = LOADSAVE_HGAP; sButInit.y = (SWORD)((LOADSAVE_BANNER_DEPTH +(2*LOADSAVE_VGAP)) + ( slotCount*(LOADSAVE_VGAP+LOADENTRY_H))); } else { sButInit.x = (2*LOADSAVE_HGAP)+LOADENTRY_W; sButInit.y = (SWORD)((LOADSAVE_BANNER_DEPTH +(2* LOADSAVE_VGAP)) + ( (slotCount-5) *(LOADSAVE_VGAP+LOADENTRY_H))); } widgAddButton(psRequestScreen, &sButInit); } // fill slots. slotCount = 0; sprintf(sTemp,"%s*.%s",sSearchPath,sExtension); // form search string. strcpy(sPath,sSearchPath); // setup locals. strcpy(sExt,sExtension); dir =FindFirstFile(sTemp,&found); if(dir != INVALID_HANDLE_VALUE) { while( TRUE ) { /* Set the tip and add the button */ found.cFileName[strlen(found.cFileName) -4 ] = '\0'; // chop extension strcpy(sSlots[slotCount],found.cFileName); //store it! ((W_BUTTON *)widgGetFromID(psRequestScreen,LOADENTRY_START+slotCount))->pTip = sSlots[slotCount]; ((W_BUTTON *)widgGetFromID(psRequestScreen,LOADENTRY_START+slotCount))->pText = sSlots[slotCount]; slotCount++; // goto next but. if(!FindNextFile(dir,&found ) || slotCount == 10 )// only show upto 10 entrys. { break; } } } FindClose(dir); bLoadSaveUp = TRUE; return TRUE; }
// //////////////////////////////////////////////////////////////////////////// bool addLoadSave(LOADSAVE_MODE savemode, const char *title) { bool bLoad = true; char NewSaveGamePath[PATH_MAX] = {'\0'}; bLoadSaveMode = savemode; UDWORD slotCount; static char sSlotCaps[totalslots][totalslotspace]; static char sSlotTips[totalslots][totalslotspace]; char **i, **files; switch(savemode) { case LOAD_FRONTEND_MISSION: case LOAD_INGAME_MISSION: case LOAD_MISSIONEND: ssprintf(NewSaveGamePath, "%s%s/", SaveGamePath, "campaign"); break; case LOAD_FRONTEND_SKIRMISH: case LOAD_INGAME_SKIRMISH: ssprintf(NewSaveGamePath, "%s%s/", SaveGamePath, "skirmish"); break; case SAVE_MISSIONEND: case SAVE_INGAME_MISSION: ssprintf(NewSaveGamePath, "%s%s/", SaveGamePath, "campaign"); bLoad = false; break; case SAVE_INGAME_SKIRMISH: ssprintf(NewSaveGamePath, "%s%s/", SaveGamePath, "skirmish"); bLoad = false; break; default: ASSERT("Invalid load/save mode!", "Invalid load/save mode!"); ssprintf(NewSaveGamePath, "%s%s/", SaveGamePath, "campaign"); break; } mode = bLoad; debug(LOG_SAVE, "called (%d, %s)", bLoad, title); if ((bLoadSaveMode == LOAD_INGAME_MISSION) || (bLoadSaveMode == SAVE_INGAME_MISSION) || (bLoadSaveMode == LOAD_INGAME_SKIRMISH) || (bLoadSaveMode == SAVE_INGAME_SKIRMISH)) { if (!bMultiPlayer || (NetPlay.bComms ==0)) { gameTimeStop(); if(GetGameMode() == GS_NORMAL) { bool radOnScreen = radarOnScreen; // Only do this in main game. bRender3DOnly = true; radarOnScreen = false; displayWorld(); // Just display the 3d, no interface radarOnScreen = radOnScreen; bRender3DOnly = false; } setGamePauseStatus( true ); setGameUpdatePause(true); setScriptPause(true); setScrollPause(true); setConsolePause(true); } forceHidePowerBar(); intRemoveReticule(); } psRequestScreen = new W_SCREEN; WIDGET *parent = psRequestScreen->psForm; /* add a form to place the tabbed form on */ // we need the form to be long enough for all resolutions, so we take the total number of items * height // and * the gaps, add the banner, and finally, the fudge factor ;) IntFormAnimated *loadSaveForm = new IntFormAnimated(parent); loadSaveForm->id = LOADSAVE_FORM; loadSaveForm->setGeometry(LOADSAVE_X, LOADSAVE_Y, LOADSAVE_W, slotsInColumn*(LOADENTRY_H + LOADSAVE_HGAP) + LOADSAVE_BANNER_DEPTH + 20); // Add Banner W_FORMINIT sFormInit; sFormInit.formID = LOADSAVE_FORM; sFormInit.id = LOADSAVE_BANNER; sFormInit.x = LOADSAVE_HGAP; sFormInit.y = LOADSAVE_VGAP; sFormInit.width = LOADSAVE_W-(2*LOADSAVE_HGAP); sFormInit.height = LOADSAVE_BANNER_DEPTH; sFormInit.pDisplay = displayLoadBanner; sFormInit.UserData = bLoad; widgAddForm(psRequestScreen, &sFormInit); // Add Banner Label W_LABINIT sLabInit; sLabInit.formID = LOADSAVE_BANNER; sLabInit.FontID = font_large; sLabInit.id = LOADSAVE_LABEL; sLabInit.style = WLAB_ALIGNCENTRE; sLabInit.x = 0; sLabInit.y = 0; sLabInit.width = LOADSAVE_W-(2*LOADSAVE_HGAP); //LOADSAVE_W; sLabInit.height = LOADSAVE_BANNER_DEPTH; //This looks right -Q sLabInit.pText = title; widgAddLabel(psRequestScreen, &sLabInit); // add cancel. W_BUTINIT sButInit; sButInit.formID = LOADSAVE_BANNER; sButInit.x = 8; sButInit.y = 10; sButInit.width = iV_GetImageWidth(IntImages,IMAGE_NRUTER); sButInit.height = iV_GetImageHeight(IntImages,IMAGE_NRUTER); sButInit.UserData = PACKDWORD_TRI(0,IMAGE_NRUTER , IMAGE_NRUTER); sButInit.id = LOADSAVE_CANCEL; sButInit.style = WBUT_PLAIN; sButInit.pTip = _("Close"); sButInit.pDisplay = intDisplayImageHilight; widgAddButton(psRequestScreen, &sButInit); // add slots sButInit = W_BUTINIT(); sButInit.formID = LOADSAVE_FORM; sButInit.style = WBUT_PLAIN; sButInit.width = LOADENTRY_W; sButInit.height = LOADENTRY_H; sButInit.pDisplay = displayLoadSlot; for(slotCount = 0; slotCount< totalslots; slotCount++) { sButInit.id = slotCount+LOADENTRY_START; if(slotCount < slotsInColumn) { sButInit.x = 22 + LOADSAVE_HGAP; sButInit.y = (SWORD)((LOADSAVE_BANNER_DEPTH +(2*LOADSAVE_VGAP)) + ( slotCount*(LOADSAVE_VGAP+LOADENTRY_H))); } else if (slotCount >= slotsInColumn && (slotCount < (slotsInColumn *2))) { sButInit.x = 22 + (2*LOADSAVE_HGAP + LOADENTRY_W); sButInit.y = (SWORD)((LOADSAVE_BANNER_DEPTH +(2* LOADSAVE_VGAP)) + ( (slotCount % slotsInColumn)*(LOADSAVE_VGAP+LOADENTRY_H))); } else { sButInit.x = 22 + (3*LOADSAVE_HGAP + (2*LOADENTRY_W)); sButInit.y = (SWORD)((LOADSAVE_BANNER_DEPTH +(2* LOADSAVE_VGAP)) + ( (slotCount % slotsInColumn)*(LOADSAVE_VGAP+LOADENTRY_H))); } widgAddButton(psRequestScreen, &sButInit); } // fill slots. slotCount = 0; debug(LOG_SAVE, "Searching \"%s\" for savegames", NewSaveGamePath); // add savegame filenames minus extensions to buttons files = PHYSFS_enumerateFiles(NewSaveGamePath); for (i = files; *i != NULL; ++i) { W_BUTTON *button; char savefile[256]; time_t savetime; struct tm *timeinfo; // See if this filename contains the extension we're looking for if (!strstr(*i, sExt)) { // If it doesn't, move on to the next filename continue; } button = (W_BUTTON*)widgGetFromID(psRequestScreen, LOADENTRY_START + slotCount); debug(LOG_SAVE, "We found [%s]", *i); /* Figure save-time */ snprintf(savefile, sizeof(savefile), "%s/%s", NewSaveGamePath, *i); savetime = PHYSFS_getLastModTime(savefile); timeinfo = localtime(&savetime); strftime(sSlotTips[slotCount], sizeof(sSlotTips[slotCount]), "%x %X", timeinfo); /* Set the button-text */ (*i)[strlen(*i) - 4] = '\0'; // remove .gam extension sstrcpy(sSlotCaps[slotCount], *i); //store it! /* Add button */ button->pTip = sSlotTips[slotCount]; button->pText = sSlotCaps[slotCount]; slotCount++; // goto next but... if (slotCount == totalslots) { break; } } PHYSFS_freeList(files); bLoadSaveUp = true; return true; }
void * EiC_yrealloc(char *file, int lineno, void *oldp, size_t nbytes) { void *newp; int found = 0, d, bOld = 0, bno = 0; //maks if(nbytes <= 0 && oldp) { //maks: realloc definition EiC_yfree(file, lineno, oldp); return 0; } if(oldp != NULL) { found = xlookup(oldp); assertp(found < 0,STDMSG); bOld = 1; //maks bno = BNO(oldp); } if(GetGameMode()) { unsigned long total = EiC_tot_memory + nbytes; if(total > gedMaxGameMem) //maks { //Don't alloc more then gedMaxGameMem EiC_error("Attempt to access %lu bytes.\n If is correct, set the variable gedMaxGameMem=%lu or more\n in an action before the allocation", nbytes, total); nbytes = 4; } } realAllocatedMem = nbytes; newp = realloc(oldp,nbytes); assertp(nbytes && newp == NULL,("line %d in file %s\n",lineno,file)); if(bOld) //maks { d = nbytes - MTAB[bno].dbuf[found].nbytes; EiC_tot_memory -= MTAB[bno].dbuf[found].nbytes; //maks if(bno != BNO(newp)) { int i; MTAB[bno].dbuf[found].p = NULL; MTAB[bno].dbuf[found].mark = freemark; i = install(file,lineno,newp,nbytes); /* retain creation time stamp */ MTAB[BNO(newp)].dbuf[i].alloc_num = MTAB[bno].dbuf[found].alloc_num; } else { MTAB[bno].dbuf[found].p = newp; MTAB[bno].dbuf[found].nbytes = nbytes; MTAB[bno].dbuf[found].crt_file = file; MTAB[bno].dbuf[found].crt_lineno = lineno; EiC_tot_memory += nbytes; //maks } } else { install(file,lineno,newp,nbytes); } return newp; }
void VoxGame::UpdateGamePadControls(float dt) { JoystickCameraZoom(dt); m_bJoystickJump = m_pVoxWindow->GetJoystickButton(0, 0); if (m_bAttackPressed_Joystick) { m_bCanDoAttack_Joystick = m_pVoxWindow->GetJoystickAxisValue(0, 2) >= -0.75f; m_bAttackReleased_Joystick = m_pVoxWindow->GetJoystickAxisValue(0, 2) >= -0.75f; } m_bAttackPressed_Joystick = m_pVoxWindow->GetJoystickAxisValue(0, 2) <= -0.75f; m_bTargetEnemyPressed_Joystick = false; // TODO : Need to get newer version of glfw to support different triggers for LT, RT m_bTargetEnemyReleased_Joystick = false; // TODO : Need to get newer version of glfw to support different triggers for LT, RT GameMode gameMode = GetGameMode(); if (gameMode == GameMode_Debug || m_cameraMode == CameraMode_Debug) { JoystickCameraMove(dt); JoystickCameraRotate(dt); } else if (gameMode == GameMode_Game) { if (m_pPlayer->IsDead() == false) { if (m_bPaused == false) // If we are paused, don't allow gameplay control movements { if (IsGUIWindowStillDisplayed() == true) { // Reset movement speed since we have a GUI window open m_movementSpeed = 0.0f; } else { if (m_cameraMode == CameraMode_MouseRotate) { JoystickCameraRotate(dt); } else if (m_cameraMode == CameraMode_AutoCamera) { /* Do nothing, camera rotation is not controlled by player. */ } else if (m_cameraMode == CameraMode_FirstPerson) { JoystickCameraRotate(dt); } // Jumping if (m_bJoystickJump) { m_pPlayer->Jump(); } // Enemy targetting if (m_cameraMode != CameraMode_FirstPerson) { if (m_bTargetEnemyPressed_Joystick) { if(m_pPlayer->GetTargetEnemy() == NULL) { SetEnemyTarget(); } } if (m_bTargetEnemyReleased_Joystick) { if (m_pPlayer->GetTargetEnemy() != NULL) { ReleaseEnemyTarget(); } } } // Attacking if (m_bAttackPressed_Joystick && m_bCanDoAttack_Joystick) { // Check interactions bool interaction = CheckInteractions(); if (interaction == false) { m_pPlayer->PressAttack(); } m_bCanDoAttack_Joystick = false; } if (m_bAttackReleased_Joystick) { m_pPlayer->ReleaseAttack(); m_bAttackReleased_Joystick = false; } // Player movements float axisX = m_pVoxWindow->GetJoystickAxisValue(0, 0); float axisY = m_pVoxWindow->GetJoystickAxisValue(0, 1); // Dead zones if (fabs(axisX) < m_pVoxWindow->GetJoystickAnalogDeadZone()) { axisX = 0.0f; } if (fabs(axisY) < m_pVoxWindow->GetJoystickAnalogDeadZone()) { axisY = 0.0f; } if (fabs(axisX) <= 0.0f && fabs(axisY) <= 0.0f) { // Reduce the movement speed (drag) m_movementSpeed -= m_maxMovementSpeed / (m_movementDragTime / dt); if (m_movementSpeed <= 0.0f) { m_movementSpeed = 0.0f; m_gamepadMovement = false; m_pPlayer->StopMoving(); } } else { m_gamepadMovement = true; // Increase the movement speed since we are pressing a movement key m_movementSpeed += m_maxMovementSpeed / (m_movementIncreaseTime / dt); // Don't allow faster than max movement if (m_movementSpeed > m_maxMovementSpeed) { m_movementSpeed = m_maxMovementSpeed; } } if (m_pPlayer->GetTargetEnemy() == NULL) { vec3 cameraRight = m_pGameCamera->GetRight(); vec3 playerUp = m_pPlayer->GetUpVector(); vec3 moveDirection = normalize(cross(cameraRight, playerUp)); m_movementDirection += moveDirection * axisY; m_movementDirection += cameraRight * axisX; if (length(m_movementDirection) > 0.001f && m_movementSpeed > m_movementStopThreshold) { bool shouldChangePlayerFacing = (m_cameraMode != CameraMode_FirstPerson); m_movementDirection = normalize(m_movementDirection); vec3 amountMoved = m_pPlayer->MoveAbsolute(m_movementDirection, m_movementSpeed * dt, shouldChangePlayerFacing); m_pGameCamera->SetFakePosition(m_pGameCamera->GetFakePosition() + amountMoved); } } else { m_targetCameraXAxisAmount_Target -= (axisX * dt); if (m_targetCameraXAxisAmount_Target > 1.0f) { m_targetCameraXAxisAmount_Target = 1.0f; } if (m_targetCameraXAxisAmount_Target < -1.0f) { m_targetCameraXAxisAmount_Target = -1.0f; } m_pPlayer->Move(-axisY * 10.0f * dt); // TODO : Is this a good value for gamepad movement speed? m_pPlayer->Strafe(-axisX * 10.0f * dt); // TODO : Is this a good value for gamepad movement speed? } } } } } }
void VoxGame::UpdateKeyboardControls(float dt) { GameMode gameMode = GetGameMode(); if (gameMode == GameMode_Debug || m_cameraMode == CameraMode_Debug) { // Keyboard camera movements if (m_bKeyboardForward) { m_pGameCamera->Fly(20.0f * dt, true); } if (m_bKeyboardBackward) { m_pGameCamera->Fly(-20.0f * dt, true); } if (m_bKeyboardStrafeLeft) { m_pGameCamera->Strafe(-20.0f * dt, true); } if (m_bKeyboardStrafeRight) { m_pGameCamera->Strafe(20.0f * dt, true); } if (m_bKeyboardUp) { m_pGameCamera->Levitate(20.0f * dt, true); } if (m_bKeyboardDown) { m_pGameCamera->Levitate(-20.0f * dt, true); } } else if (gameMode == GameMode_Game) { // Pause menu if (m_bKeyboardMenu) { m_bKeyboardMenu = false; if (IsGUIWindowStillDisplayed()) { CloseAllGUIWindows(); if (IsGUIWindowStillDisplayed() == false) { TurnCursorOff(false); } } else { if (m_pFrontendManager->GetFrontendScreen() == FrontendScreen_None) { SetPauseMenu(); } else if (m_pFrontendManager->GetFrontendScreen() == FrontendScreen_PauseMenu) { UnsetPauseMenu(); } else if (m_pFrontendManager->GetFrontendScreen() == FrontendScreen_OptionsMenu) { m_pFrontendManager->SetFrontendScreen(FrontendScreen_PauseMenu); } else if (m_pFrontendManager->GetFrontendScreen() == FrontendScreen_ModMenu) { m_pFrontendManager->SetFrontendScreen(FrontendScreen_PauseMenu); } } // Cancel quit popup menu with escape button if (m_pFrontendManager->GetFrontendScreen() == FrontendScreen_QuitPopup) { VoxGame::GetInstance()->CancelQuitPopup(); } } if (m_pPlayer->IsDead() == false) { if (m_bPaused == false) // If we are paused, don't allow gameplay control movements { if (IsGUIWindowStillDisplayed() == true) { // Reset movement speed since we have a GUI window open m_movementSpeed = 0.0f; } else { // Jumping if (m_bKeyboardSpace) { m_pPlayer->Jump(); } // Attacking if (m_bAttackPressed_Mouse && m_bCanDoAttack_Mouse) { // Check interactions bool interaction = CheckInteractions(); if (interaction == false) { m_pPlayer->PressAttack(); } m_bCanDoAttack_Mouse = false; } if (m_bAttackReleased_Mouse) { m_pPlayer->ReleaseAttack(); m_bAttackReleased_Mouse = false; } // Player movements bool resetMovementVector = false; if (m_bKeyboardForward == false && m_bKeyboardBackward == false && m_bKeyboardStrafeLeft == false && m_bKeyboardStrafeRight == false) { // Reduce the movement speed (drag) m_movementSpeed -= m_maxMovementSpeed / (m_movementDragTime / dt); if (m_movementSpeed <= 0.0f) { m_movementSpeed = 0.0f; m_keyboardMovement = false; m_pPlayer->StopMoving(); } } else { m_keyboardMovement = true; // Increase the movement speed since we are pressing a movement key m_movementSpeed += m_maxMovementSpeed / (m_movementIncreaseTime / dt); // Don't allow faster than max movement if (m_movementSpeed > m_maxMovementSpeed) { m_movementSpeed = m_maxMovementSpeed; } } float targetModeMovementRatio = 0.65f; // Forwards, backwards, strafe, left, right directional movement if (m_bKeyboardForward) { if (resetMovementVector == false) { m_movementDirection = vec3(0.0f, 0.0f, 0.0f); resetMovementVector = true; } if (m_pPlayer->GetTargetEnemy() == NULL) { vec3 cameraRight = m_pGameCamera->GetRight(); vec3 playerUp = m_pPlayer->GetUpVector(); vec3 moveDirection = normalize(cross(cameraRight, playerUp)); m_movementDirection -= moveDirection; } else { m_pPlayer->Move(m_movementSpeed * targetModeMovementRatio * dt); } } if (m_bKeyboardBackward) { if (resetMovementVector == false) { m_movementDirection = vec3(0.0f, 0.0f, 0.0f); resetMovementVector = true; } if (m_pPlayer->GetTargetEnemy() == NULL) { vec3 cameraRight = m_pGameCamera->GetRight(); vec3 playerUp = m_pPlayer->GetUpVector(); vec3 moveDirection = normalize(cross(cameraRight, playerUp)); m_movementDirection += moveDirection; } else { m_pPlayer->Move(-m_movementSpeed * targetModeMovementRatio * dt); } } if (m_bKeyboardStrafeLeft) { if (resetMovementVector == false) { m_movementDirection = vec3(0.0f, 0.0f, 0.0f); resetMovementVector = true; } if (m_pPlayer->GetTargetEnemy() == NULL) { vec3 cameraRight = m_pGameCamera->GetRight(); vec3 moveDirection = -cameraRight; m_movementDirection += moveDirection; } else { m_targetCameraXAxisAmount_Target += (0.75f * dt); if (m_targetCameraXAxisAmount_Target > 1.0f) { m_targetCameraXAxisAmount_Target = 1.0f; } m_pPlayer->Strafe(m_movementSpeed * targetModeMovementRatio * dt); } } if (m_bKeyboardStrafeRight) { if (resetMovementVector == false) { m_movementDirection = vec3(0.0f, 0.0f, 0.0f); resetMovementVector = true; } if (m_pPlayer->GetTargetEnemy() == NULL) { vec3 cameraRight = m_pGameCamera->GetRight(); vec3 moveDirection = -cameraRight; m_movementDirection -= moveDirection; } else { m_targetCameraXAxisAmount_Target -= (0.75f * dt); if (m_targetCameraXAxisAmount_Target < -1.0f) { m_targetCameraXAxisAmount_Target = -1.0f; } m_pPlayer->Strafe(-m_movementSpeed * targetModeMovementRatio * dt); } } if (length(m_movementDirection) > 0.001f && m_movementSpeed > m_movementStopThreshold) { bool shouldChangePlayerFacing = (m_cameraMode != CameraMode_FirstPerson); m_movementDirection = normalize(m_movementDirection); vec3 amountMoved = m_pPlayer->MoveAbsolute(m_movementDirection, m_movementSpeed * dt, shouldChangePlayerFacing); m_pGameCamera->SetFakePosition(m_pGameCamera->GetFakePosition() + amountMoved); } } } } } }