2010-03-13 22:10:45 +01:00
|
|
|
|
// This file is part of Glest (www.glest.org)
|
|
|
|
|
//
|
2010-03-25 01:19:49 +01:00
|
|
|
|
// Copyright (C) 2001-2008 Marti<74>o Figueroa
|
2010-03-13 22:10:45 +01:00
|
|
|
|
//
|
|
|
|
|
// You can redistribute this code and/or modify it under
|
|
|
|
|
// the terms of the GNU General Public License as published
|
|
|
|
|
// by the Free Software Foundation; either version 2 of the
|
|
|
|
|
// License, or (at your option) any later version
|
|
|
|
|
// ==============================================================
|
|
|
|
|
|
|
|
|
|
#include "game.h"
|
|
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
#include "renderer.h"
|
|
|
|
|
#include "particle_renderer.h"
|
|
|
|
|
#include "commander.h"
|
|
|
|
|
#include "battle_end.h"
|
|
|
|
|
#include "sound_renderer.h"
|
|
|
|
|
#include "profiler.h"
|
|
|
|
|
#include "core_data.h"
|
|
|
|
|
#include "metrics.h"
|
|
|
|
|
#include "faction.h"
|
|
|
|
|
#include "network_manager.h"
|
|
|
|
|
#include "checksum.h"
|
|
|
|
|
#include "auto_test.h"
|
2010-04-24 14:22:35 +02:00
|
|
|
|
#include "FPUCheck.h"
|
2010-03-13 22:10:45 +01:00
|
|
|
|
#include "leak_dumper.h"
|
|
|
|
|
|
|
|
|
|
using namespace Shared::Graphics;
|
|
|
|
|
using namespace Shared::Util;
|
|
|
|
|
using namespace Shared::Platform;
|
|
|
|
|
|
|
|
|
|
namespace Glest{ namespace Game{
|
|
|
|
|
|
2010-05-29 08:56:32 +02:00
|
|
|
|
Game *thisGamePtr = NULL;
|
|
|
|
|
|
2010-03-13 22:10:45 +01:00
|
|
|
|
// =====================================================
|
|
|
|
|
// class Game
|
|
|
|
|
// =====================================================
|
|
|
|
|
|
|
|
|
|
// ===================== PUBLIC ========================
|
|
|
|
|
|
|
|
|
|
Game::Game(Program *program, const GameSettings *gameSettings):
|
2010-06-24 03:23:18 +02:00
|
|
|
|
ProgramState(program), lastMousePos(0), isFirstRender(true)
|
2010-03-13 22:10:45 +01:00
|
|
|
|
{
|
2010-06-01 18:54:44 +02:00
|
|
|
|
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
|
|
|
|
|
2010-05-29 08:56:32 +02:00
|
|
|
|
originalDisplayMsgCallback = NULL;
|
|
|
|
|
thisGamePtr = this;
|
|
|
|
|
|
2010-03-13 22:10:45 +01:00
|
|
|
|
this->gameSettings= *gameSettings;
|
2010-03-23 03:35:55 +01:00
|
|
|
|
scrollSpeed = Config::getInstance().getFloat("UiScrollSpeed","1.5");
|
2010-03-13 22:10:45 +01:00
|
|
|
|
|
2010-06-15 18:27:52 +02:00
|
|
|
|
//MIN_RENDER_FPS_ALLOWED = Config::getInstance().getInt("MIN_RENDER_FPS_ALLOWED",intToStr(MIN_RENDER_FPS_ALLOWED).c_str());
|
2010-06-15 07:36:07 +02:00
|
|
|
|
|
2010-06-15 18:27:52 +02:00
|
|
|
|
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] MIN_RENDER_FPS_ALLOWED = %d\n",__FILE__,__FUNCTION__,__LINE__,MIN_RENDER_FPS_ALLOWED);
|
2010-06-01 18:54:44 +02:00
|
|
|
|
|
2010-03-13 22:10:45 +01:00
|
|
|
|
mouseX=0;
|
|
|
|
|
mouseY=0;
|
|
|
|
|
mouse2d= 0;
|
|
|
|
|
loadingText="";
|
|
|
|
|
weatherParticleSystem= NULL;
|
|
|
|
|
updateFps=0;
|
|
|
|
|
renderFps=0;
|
|
|
|
|
lastUpdateFps=0;
|
2010-06-17 02:08:27 +02:00
|
|
|
|
lastRenderFps=-1;
|
2010-03-13 22:10:45 +01:00
|
|
|
|
paused= false;
|
|
|
|
|
gameOver= false;
|
|
|
|
|
renderNetworkStatus= false;
|
|
|
|
|
speed= sNormal;
|
2010-04-14 22:49:14 +02:00
|
|
|
|
showFullConsole= false;
|
2010-06-01 18:54:44 +02:00
|
|
|
|
|
|
|
|
|
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
2010-03-13 22:10:45 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Game::~Game(){
|
2010-06-01 18:54:44 +02:00
|
|
|
|
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
|
|
|
|
|
2010-03-13 22:10:45 +01:00
|
|
|
|
Logger &logger= Logger::getInstance();
|
|
|
|
|
Renderer &renderer= Renderer::getInstance();
|
2010-04-05 19:43:04 +02:00
|
|
|
|
|
|
|
|
|
logger.loadLoadingScreen("");
|
2010-03-13 22:10:45 +01:00
|
|
|
|
logger.setState(Lang::getInstance().get("Deleting"));
|
|
|
|
|
logger.add("Game", true);
|
|
|
|
|
|
2010-06-01 18:54:44 +02:00
|
|
|
|
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
2010-05-07 08:46:55 +02:00
|
|
|
|
|
2010-03-13 22:10:45 +01:00
|
|
|
|
renderer.endGame();
|
|
|
|
|
SoundRenderer::getInstance().stopAllSounds();
|
|
|
|
|
|
|
|
|
|
deleteValues(aiInterfaces.begin(), aiInterfaces.end());
|
|
|
|
|
|
2010-06-01 18:54:44 +02:00
|
|
|
|
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
|
|
|
|
|
2010-03-13 22:10:45 +01:00
|
|
|
|
gui.end(); //selection must be cleared before deleting units
|
|
|
|
|
world.end(); //must die before selection because of referencers
|
2010-05-29 08:56:32 +02:00
|
|
|
|
|
2010-06-01 18:54:44 +02:00
|
|
|
|
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
|
|
|
|
|
2010-05-29 08:56:32 +02:00
|
|
|
|
thisGamePtr = NULL;
|
|
|
|
|
if(originalDisplayMsgCallback != NULL) {
|
|
|
|
|
NetworkInterface::setDisplayMessageFunction(originalDisplayMsgCallback);
|
|
|
|
|
}
|
2010-03-13 22:10:45 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ==================== init and load ====================
|
|
|
|
|
|
2010-05-29 08:56:32 +02:00
|
|
|
|
int Game::ErrorDisplayMessage(const char *msg, bool exitApp) {
|
|
|
|
|
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] %s\n",__FILE__,__FUNCTION__,__LINE__,msg);
|
|
|
|
|
|
|
|
|
|
if(thisGamePtr != NULL) {
|
|
|
|
|
string text = msg;
|
|
|
|
|
thisGamePtr->showMessageBox(text, "Error detected", false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2010-03-13 22:10:45 +01:00
|
|
|
|
void Game::load(){
|
2010-05-29 08:56:32 +02:00
|
|
|
|
originalDisplayMsgCallback = NetworkInterface::getDisplayMessageFunction();
|
|
|
|
|
NetworkInterface::setDisplayMessageFunction(ErrorDisplayMessage);
|
2010-05-01 22:14:25 +02:00
|
|
|
|
|
2010-06-03 09:52:17 +02:00
|
|
|
|
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] gameSettings = [%s]\n",__FILE__,__FUNCTION__,__LINE__,this->gameSettings.toString().c_str());
|
|
|
|
|
|
2010-03-13 22:10:45 +01:00
|
|
|
|
Logger &logger= Logger::getInstance();
|
|
|
|
|
string mapName= gameSettings.getMap();
|
|
|
|
|
string tilesetName= gameSettings.getTileset();
|
|
|
|
|
string techName= gameSettings.getTech();
|
|
|
|
|
string scenarioName= gameSettings.getScenario();
|
2010-04-06 22:15:06 +02:00
|
|
|
|
bool loadingImageUsed=false;
|
2010-04-05 19:43:04 +02:00
|
|
|
|
|
2010-03-13 22:10:45 +01:00
|
|
|
|
logger.setState(Lang::getInstance().get("Loading"));
|
|
|
|
|
|
|
|
|
|
if(scenarioName.empty()){
|
|
|
|
|
logger.setSubtitle(formatString(mapName)+" - "+formatString(tilesetName)+" - "+formatString(techName));
|
|
|
|
|
}
|
|
|
|
|
else{
|
|
|
|
|
logger.setSubtitle(formatString(scenarioName));
|
|
|
|
|
}
|
|
|
|
|
|
2010-03-18 22:26:40 +01:00
|
|
|
|
Config &config = Config::getInstance();
|
2010-05-01 22:14:25 +02:00
|
|
|
|
//good_fpu_control_registers(NULL,__FILE__,__FUNCTION__,__LINE__);
|
2010-03-18 22:26:40 +01:00
|
|
|
|
|
2010-06-24 12:52:58 +02:00
|
|
|
|
//bool skipCustomLoadScreen = true;
|
|
|
|
|
bool skipCustomLoadScreen = false;
|
|
|
|
|
|
2010-03-21 06:33:13 +01:00
|
|
|
|
string scenarioDir = "";
|
2010-06-24 12:52:58 +02:00
|
|
|
|
if(skipCustomLoadScreen == false && gameSettings.getScenarioDir() != "") {
|
2010-03-21 06:33:13 +01:00
|
|
|
|
scenarioDir = gameSettings.getScenarioDir();
|
|
|
|
|
if(EndsWith(scenarioDir, ".xml") == true) {
|
|
|
|
|
scenarioDir = scenarioDir.erase(scenarioDir.size() - 4, 4);
|
|
|
|
|
scenarioDir = scenarioDir.erase(scenarioDir.size() - gameSettings.getScenario().size(), gameSettings.getScenario().size() + 1);
|
|
|
|
|
}
|
2010-04-05 22:16:49 +02:00
|
|
|
|
// use a scenario based loading screen
|
2010-04-05 23:41:33 +02:00
|
|
|
|
vector<string> loadScreenList;
|
2010-04-09 08:51:13 +02:00
|
|
|
|
findAll(scenarioDir + "loading_screen.*", loadScreenList, false, false);
|
2010-04-05 23:41:33 +02:00
|
|
|
|
if(loadScreenList.size() > 0) {
|
|
|
|
|
//string senarioLogo = scenarioDir + "/" + "loading_screen.jpg";
|
2010-04-09 08:51:13 +02:00
|
|
|
|
string senarioLogo = scenarioDir + loadScreenList[0];
|
2010-04-05 23:41:33 +02:00
|
|
|
|
if(fileExists(senarioLogo) == true) {
|
|
|
|
|
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] found scenario loading screen '%s'\n",__FILE__,__FUNCTION__,senarioLogo.c_str());
|
|
|
|
|
|
|
|
|
|
logger.loadLoadingScreen(senarioLogo);
|
2010-04-06 22:15:06 +02:00
|
|
|
|
loadingImageUsed=true;
|
2010-04-05 23:41:33 +02:00
|
|
|
|
}
|
2010-04-05 22:16:49 +02:00
|
|
|
|
}
|
2010-03-21 06:33:13 +01:00
|
|
|
|
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] gameSettings.getScenarioDir() = [%s] gameSettings.getScenario() = [%s] scenarioDir = [%s]\n",__FILE__,__FUNCTION__,__LINE__,gameSettings.getScenarioDir().c_str(),gameSettings.getScenario().c_str(),scenarioDir.c_str());
|
|
|
|
|
}
|
2010-04-06 22:15:06 +02:00
|
|
|
|
|
2010-06-12 20:27:39 +02:00
|
|
|
|
// give CPU time to update other things to avoid apperance of hanging
|
|
|
|
|
sleep(0);
|
2010-06-15 18:27:52 +02:00
|
|
|
|
//SDL_PumpEvents();
|
2010-06-13 02:59:56 +02:00
|
|
|
|
|
2010-06-24 12:52:58 +02:00
|
|
|
|
if(skipCustomLoadScreen == false && loadingImageUsed == false){
|
2010-04-05 22:16:49 +02:00
|
|
|
|
// try to use a faction related loading screen
|
2010-04-06 22:15:06 +02:00
|
|
|
|
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] Searching for faction loading screen\n",__FILE__,__FUNCTION__);
|
2010-04-05 22:16:49 +02:00
|
|
|
|
for ( int i=0; i < gameSettings.getFactionCount(); ++i ) {
|
2010-04-08 03:12:55 +02:00
|
|
|
|
if( gameSettings.getFactionControl(i) == ctHuman ||
|
|
|
|
|
(gameSettings.getFactionControl(i) == ctNetwork && gameSettings.getThisFactionIndex() == i)){
|
2010-04-05 22:16:49 +02:00
|
|
|
|
vector<string> pathList=config.getPathListForType(ptTechs,scenarioDir);
|
|
|
|
|
for(int idx = 0; idx < pathList.size(); idx++) {
|
2010-04-05 23:41:33 +02:00
|
|
|
|
const string path = pathList[idx]+ "/" +techName+ "/"+ "factions"+ "/"+ gameSettings.getFactionTypeName(i);
|
2010-04-05 22:16:49 +02:00
|
|
|
|
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] possible loading screen dir '%s'\n",__FILE__,__FUNCTION__,path.c_str());
|
|
|
|
|
if(isdir(path.c_str()) == true) {
|
2010-04-05 23:41:33 +02:00
|
|
|
|
vector<string> loadScreenList;
|
|
|
|
|
findAll(path + "/" + "loading_screen.*", loadScreenList, false, false);
|
|
|
|
|
if(loadScreenList.size() > 0) {
|
|
|
|
|
//string factionLogo = path + "/" + "loading_screen.jpg";
|
|
|
|
|
string factionLogo = path + "/" + loadScreenList[0];
|
|
|
|
|
|
|
|
|
|
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] looking for loading screen '%s'\n",__FILE__,__FUNCTION__,factionLogo.c_str());
|
|
|
|
|
|
|
|
|
|
if(fileExists(factionLogo) == true) {
|
|
|
|
|
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] found loading screen '%s'\n",__FILE__,__FUNCTION__,factionLogo.c_str());
|
|
|
|
|
|
|
|
|
|
logger.loadLoadingScreen(factionLogo);
|
2010-04-06 22:15:06 +02:00
|
|
|
|
loadingImageUsed = true;
|
2010-04-05 23:41:33 +02:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2010-04-06 22:15:06 +02:00
|
|
|
|
if(loadingImageUsed == true) {
|
2010-04-05 23:41:33 +02:00
|
|
|
|
break;
|
2010-04-05 22:16:49 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2010-06-24 12:52:58 +02:00
|
|
|
|
if(skipCustomLoadScreen == false && loadingImageUsed == false){
|
2010-04-06 22:15:06 +02:00
|
|
|
|
// try to use a tech related loading screen
|
|
|
|
|
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] Searching for tech loading screen\n",__FILE__,__FUNCTION__);
|
|
|
|
|
|
|
|
|
|
vector<string> pathList=config.getPathListForType(ptTechs,scenarioDir);
|
|
|
|
|
for(int idx = 0; idx < pathList.size(); idx++) {
|
|
|
|
|
const string path = pathList[idx]+ "/" +techName;
|
|
|
|
|
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] possible loading screen dir '%s'\n",__FILE__,__FUNCTION__,path.c_str());
|
|
|
|
|
if(isdir(path.c_str()) == true) {
|
|
|
|
|
vector<string> loadScreenList;
|
|
|
|
|
findAll(path + "/" + "loading_screen.*", loadScreenList, false, false);
|
|
|
|
|
if(loadScreenList.size() > 0) {
|
|
|
|
|
//string factionLogo = path + "/" + "loading_screen.jpg";
|
|
|
|
|
string factionLogo = path + "/" + loadScreenList[0];
|
|
|
|
|
|
|
|
|
|
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] looking for loading screen '%s'\n",__FILE__,__FUNCTION__,factionLogo.c_str());
|
|
|
|
|
|
|
|
|
|
if(fileExists(factionLogo) == true) {
|
|
|
|
|
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] found loading screen '%s'\n",__FILE__,__FUNCTION__,factionLogo.c_str());
|
|
|
|
|
|
|
|
|
|
logger.loadLoadingScreen(factionLogo);
|
|
|
|
|
loadingImageUsed = true;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if(loadingImageUsed == true) {
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2010-04-05 19:43:04 +02:00
|
|
|
|
|
2010-04-12 22:32:47 +02:00
|
|
|
|
//throw runtime_error("Test!");
|
2010-04-05 19:43:04 +02:00
|
|
|
|
|
2010-06-25 07:05:52 +02:00
|
|
|
|
SDL_PumpEvents();
|
|
|
|
|
|
2010-05-03 08:25:54 +02:00
|
|
|
|
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
|
|
|
|
|
2010-03-13 22:10:45 +01:00
|
|
|
|
//tileset
|
2010-03-21 06:33:13 +01:00
|
|
|
|
world.loadTileset(config.getPathListForType(ptTilesets,scenarioDir), tilesetName, &checksum);
|
2010-03-13 22:10:45 +01:00
|
|
|
|
|
2010-06-12 20:27:39 +02:00
|
|
|
|
// give CPU time to update other things to avoid apperance of hanging
|
|
|
|
|
sleep(0);
|
2010-06-25 07:05:52 +02:00
|
|
|
|
SDL_PumpEvents();
|
2010-06-12 20:27:39 +02:00
|
|
|
|
|
2010-05-03 08:25:54 +02:00
|
|
|
|
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
|
|
|
|
|
2010-03-13 22:10:45 +01:00
|
|
|
|
set<string> factions;
|
|
|
|
|
for ( int i=0; i < gameSettings.getFactionCount(); ++i ) {
|
|
|
|
|
factions.insert(gameSettings.getFactionTypeName(i));
|
|
|
|
|
}
|
|
|
|
|
|
2010-05-03 08:25:54 +02:00
|
|
|
|
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
|
|
|
|
|
2010-03-13 22:10:45 +01:00
|
|
|
|
//tech, load before map because of resources
|
2010-03-21 06:33:13 +01:00
|
|
|
|
world.loadTech(config.getPathListForType(ptTechs,scenarioDir), techName, factions, &checksum);
|
2010-06-12 20:27:39 +02:00
|
|
|
|
|
|
|
|
|
// give CPU time to update other things to avoid apperance of hanging
|
|
|
|
|
sleep(0);
|
2010-06-25 07:05:52 +02:00
|
|
|
|
SDL_PumpEvents();
|
2010-06-12 20:27:39 +02:00
|
|
|
|
|
2010-05-03 08:25:54 +02:00
|
|
|
|
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
|
|
|
|
|
2010-03-13 22:10:45 +01:00
|
|
|
|
//map
|
2010-03-21 06:33:13 +01:00
|
|
|
|
world.loadMap(Map::getMapPath(mapName,scenarioDir), &checksum);
|
2010-03-13 22:10:45 +01:00
|
|
|
|
|
2010-06-12 20:27:39 +02:00
|
|
|
|
// give CPU time to update other things to avoid apperance of hanging
|
|
|
|
|
sleep(0);
|
2010-06-25 07:05:52 +02:00
|
|
|
|
SDL_PumpEvents();
|
2010-06-12 20:27:39 +02:00
|
|
|
|
|
2010-05-03 08:25:54 +02:00
|
|
|
|
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
|
|
|
|
|
2010-03-13 22:10:45 +01:00
|
|
|
|
//scenario
|
|
|
|
|
if(!scenarioName.empty()){
|
|
|
|
|
Lang::getInstance().loadScenarioStrings(gameSettings.getScenarioDir(), scenarioName);
|
2010-03-18 22:26:40 +01:00
|
|
|
|
world.loadScenario(gameSettings.getScenarioDir(), &checksum);
|
2010-03-13 22:10:45 +01:00
|
|
|
|
}
|
2010-04-24 14:22:35 +02:00
|
|
|
|
|
2010-06-12 20:27:39 +02:00
|
|
|
|
// give CPU time to update other things to avoid apperance of hanging
|
|
|
|
|
sleep(0);
|
2010-06-25 07:05:52 +02:00
|
|
|
|
SDL_PumpEvents();
|
2010-06-12 20:27:39 +02:00
|
|
|
|
|
2010-05-03 08:25:54 +02:00
|
|
|
|
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
2010-05-01 22:14:25 +02:00
|
|
|
|
//good_fpu_control_registers(NULL,__FILE__,__FUNCTION__,__LINE__);
|
2010-03-13 22:10:45 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Game::init()
|
|
|
|
|
{
|
2010-05-03 08:25:54 +02:00
|
|
|
|
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
2010-03-13 22:10:45 +01:00
|
|
|
|
|
|
|
|
|
Lang &lang= Lang::getInstance();
|
|
|
|
|
Logger &logger= Logger::getInstance();
|
|
|
|
|
CoreData &coreData= CoreData::getInstance();
|
|
|
|
|
Renderer &renderer= Renderer::getInstance();
|
|
|
|
|
Map *map= world.getMap();
|
|
|
|
|
NetworkManager &networkManager= NetworkManager::getInstance();
|
|
|
|
|
|
2010-05-03 08:25:54 +02:00
|
|
|
|
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
2010-03-13 22:10:45 +01:00
|
|
|
|
logger.setState(lang.get("Initializing"));
|
|
|
|
|
|
|
|
|
|
//mesage box
|
|
|
|
|
mainMessageBox.init(lang.get("Yes"), lang.get("No"));
|
|
|
|
|
mainMessageBox.setEnabled(false);
|
|
|
|
|
|
|
|
|
|
//init world, and place camera
|
|
|
|
|
commander.init(&world);
|
2010-06-12 20:27:39 +02:00
|
|
|
|
|
|
|
|
|
// give CPU time to update other things to avoid apperance of hanging
|
|
|
|
|
sleep(0);
|
2010-06-25 07:05:52 +02:00
|
|
|
|
SDL_PumpEvents();
|
2010-06-12 20:27:39 +02:00
|
|
|
|
|
2010-03-13 22:10:45 +01:00
|
|
|
|
world.init(this, gameSettings.getDefaultUnits());
|
2010-06-12 20:27:39 +02:00
|
|
|
|
|
|
|
|
|
// give CPU time to update other things to avoid apperance of hanging
|
|
|
|
|
sleep(0);
|
2010-06-25 07:05:52 +02:00
|
|
|
|
SDL_PumpEvents();
|
2010-06-12 20:27:39 +02:00
|
|
|
|
|
2010-03-13 22:10:45 +01:00
|
|
|
|
gui.init(this);
|
2010-06-12 20:27:39 +02:00
|
|
|
|
|
|
|
|
|
// give CPU time to update other things to avoid apperance of hanging
|
|
|
|
|
sleep(0);
|
2010-06-15 18:27:52 +02:00
|
|
|
|
//SDL_PumpEvents();
|
2010-06-12 20:27:39 +02:00
|
|
|
|
|
2010-03-13 22:10:45 +01:00
|
|
|
|
chatManager.init(&console, world.getThisTeamIndex());
|
2010-04-14 22:49:14 +02:00
|
|
|
|
console.clearStoredLines();
|
2010-06-24 03:23:18 +02:00
|
|
|
|
|
2010-03-13 22:10:45 +01:00
|
|
|
|
const Vec2i &v= map->getStartLocation(world.getThisFaction()->getStartLocationIndex());
|
|
|
|
|
gameCamera.init(map->getW(), map->getH());
|
|
|
|
|
gameCamera.setPos(Vec2f(v.x, v.y));
|
2010-06-12 20:27:39 +02:00
|
|
|
|
|
|
|
|
|
// give CPU time to update other things to avoid apperance of hanging
|
|
|
|
|
sleep(0);
|
2010-06-25 07:05:52 +02:00
|
|
|
|
SDL_PumpEvents();
|
2010-06-12 20:27:39 +02:00
|
|
|
|
|
2010-03-13 22:10:45 +01:00
|
|
|
|
scriptManager.init(&world, &gameCamera);
|
|
|
|
|
|
2010-05-01 22:14:25 +02:00
|
|
|
|
//good_fpu_control_registers(NULL,__FILE__,__FUNCTION__,__LINE__);
|
2010-04-24 14:22:35 +02:00
|
|
|
|
|
2010-03-20 00:26:00 +01:00
|
|
|
|
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] creating AI's\n",__FILE__,__FUNCTION__);
|
2010-03-13 22:10:45 +01:00
|
|
|
|
|
|
|
|
|
//create IAs
|
|
|
|
|
aiInterfaces.resize(world.getFactionCount());
|
|
|
|
|
for(int i=0; i<world.getFactionCount(); ++i){
|
|
|
|
|
Faction *faction= world.getFaction(i);
|
|
|
|
|
if(faction->getCpuControl()){
|
|
|
|
|
aiInterfaces[i]= new AiInterface(*this, i, faction->getTeam());
|
|
|
|
|
logger.add("Creating AI for faction " + intToStr(i), true);
|
|
|
|
|
}
|
|
|
|
|
else{
|
|
|
|
|
aiInterfaces[i]= NULL;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2010-06-12 20:27:39 +02:00
|
|
|
|
// give CPU time to update other things to avoid apperance of hanging
|
|
|
|
|
sleep(0);
|
2010-06-25 07:05:52 +02:00
|
|
|
|
SDL_PumpEvents();
|
2010-06-12 20:27:39 +02:00
|
|
|
|
|
2010-03-13 22:10:45 +01:00
|
|
|
|
//wheather particle systems
|
|
|
|
|
if(world.getTileset()->getWeather() == wRainy){
|
|
|
|
|
logger.add("Creating rain particle system", true);
|
|
|
|
|
weatherParticleSystem= new RainParticleSystem();
|
|
|
|
|
weatherParticleSystem->setSpeed(12.f/GameConstants::updateFps);
|
|
|
|
|
weatherParticleSystem->setPos(gameCamera.getPos());
|
|
|
|
|
renderer.manageParticleSystem(weatherParticleSystem, rsGame);
|
|
|
|
|
}
|
|
|
|
|
else if(world.getTileset()->getWeather() == wSnowy){
|
|
|
|
|
logger.add("Creating snow particle system", true);
|
|
|
|
|
weatherParticleSystem= new SnowParticleSystem(1200);
|
|
|
|
|
weatherParticleSystem->setSpeed(1.5f/GameConstants::updateFps);
|
|
|
|
|
weatherParticleSystem->setPos(gameCamera.getPos());
|
|
|
|
|
weatherParticleSystem->setTexture(coreData.getSnowTexture());
|
|
|
|
|
renderer.manageParticleSystem(weatherParticleSystem, rsGame);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//init renderer state
|
2010-03-20 00:26:00 +01:00
|
|
|
|
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] Initializing renderer\n",__FILE__,__FUNCTION__);
|
2010-03-13 22:10:45 +01:00
|
|
|
|
logger.add("Initializing renderer", true);
|
|
|
|
|
renderer.initGame(this);
|
|
|
|
|
|
2010-05-01 22:14:25 +02:00
|
|
|
|
//good_fpu_control_registers(NULL,__FILE__,__FUNCTION__,__LINE__);
|
2010-04-24 14:22:35 +02:00
|
|
|
|
|
2010-06-12 20:27:39 +02:00
|
|
|
|
// give CPU time to update other things to avoid apperance of hanging
|
|
|
|
|
sleep(0);
|
2010-06-25 07:05:52 +02:00
|
|
|
|
SDL_PumpEvents();
|
2010-06-12 20:27:39 +02:00
|
|
|
|
|
2010-03-13 22:10:45 +01:00
|
|
|
|
//sounds
|
|
|
|
|
SoundRenderer &soundRenderer= SoundRenderer::getInstance();
|
|
|
|
|
|
|
|
|
|
Tileset *tileset= world.getTileset();
|
|
|
|
|
AmbientSounds *ambientSounds= tileset->getAmbientSounds();
|
|
|
|
|
|
|
|
|
|
//rain
|
|
|
|
|
if(tileset->getWeather()==wRainy && ambientSounds->isEnabledRain()){
|
|
|
|
|
logger.add("Starting ambient stream", true);
|
|
|
|
|
soundRenderer.playAmbient(ambientSounds->getRain());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//snow
|
|
|
|
|
if(tileset->getWeather()==wSnowy && ambientSounds->isEnabledSnow()){
|
|
|
|
|
logger.add("Starting ambient stream", true);
|
|
|
|
|
soundRenderer.playAmbient(ambientSounds->getSnow());
|
|
|
|
|
}
|
|
|
|
|
|
2010-03-20 00:26:00 +01:00
|
|
|
|
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] Waiting for network\n",__FILE__,__FUNCTION__);
|
2010-06-01 18:54:44 +02:00
|
|
|
|
logger.add("Waiting for network players", true);
|
2010-03-13 22:10:45 +01:00
|
|
|
|
networkManager.getGameNetworkInterface()->waitUntilReady(&checksum);
|
|
|
|
|
|
2010-06-12 20:27:39 +02:00
|
|
|
|
//std::string worldLog = world.DumpWorldToLog(true);
|
2010-05-20 22:19:34 +02:00
|
|
|
|
|
2010-06-12 20:27:39 +02:00
|
|
|
|
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] Starting music stream\n",__FILE__,__FUNCTION__,__LINE__);
|
2010-03-13 22:10:45 +01:00
|
|
|
|
logger.add("Starting music stream", true);
|
2010-06-12 20:27:39 +02:00
|
|
|
|
|
|
|
|
|
if(world.getThisFaction() == NULL) {
|
|
|
|
|
throw runtime_error("world.getThisFaction() == NULL");
|
|
|
|
|
}
|
|
|
|
|
if(world.getThisFaction()->getType() == NULL) {
|
|
|
|
|
throw runtime_error("world.getThisFaction()->getType() == NULL");
|
|
|
|
|
}
|
|
|
|
|
//if(world.getThisFaction()->getType()->getMusic() == NULL) {
|
|
|
|
|
// throw runtime_error("world.getThisFaction()->getType()->getMusic() == NULL");
|
|
|
|
|
//}
|
|
|
|
|
|
2010-03-13 22:10:45 +01:00
|
|
|
|
StrSound *gameMusic= world.getThisFaction()->getType()->getMusic();
|
|
|
|
|
soundRenderer.playMusic(gameMusic);
|
|
|
|
|
|
|
|
|
|
logger.add("Launching game");
|
|
|
|
|
|
2010-05-03 08:25:54 +02:00
|
|
|
|
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
2010-03-13 22:10:45 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ==================== update ====================
|
|
|
|
|
|
|
|
|
|
//update
|
|
|
|
|
void Game::update(){
|
2010-05-03 08:25:54 +02:00
|
|
|
|
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
2010-03-13 22:10:45 +01:00
|
|
|
|
|
2010-05-29 09:58:58 +02:00
|
|
|
|
try {
|
2010-06-15 18:27:52 +02:00
|
|
|
|
Chrono chrono;
|
|
|
|
|
chrono.start();
|
2010-03-13 22:10:45 +01:00
|
|
|
|
|
2010-05-29 09:58:58 +02:00
|
|
|
|
// a) Updates non dependent on speed
|
2010-03-13 22:10:45 +01:00
|
|
|
|
|
2010-05-29 09:58:58 +02:00
|
|
|
|
//misc
|
|
|
|
|
updateFps++;
|
|
|
|
|
mouse2d= (mouse2d+1) % Renderer::maxMouse2dAnim;
|
2010-03-13 22:10:45 +01:00
|
|
|
|
|
2010-05-29 09:58:58 +02:00
|
|
|
|
//console
|
|
|
|
|
console.update();
|
2010-03-13 22:10:45 +01:00
|
|
|
|
|
2010-05-29 09:58:58 +02:00
|
|
|
|
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
|
|
|
|
// b) Updates depandant on speed
|
2010-05-03 08:25:54 +02:00
|
|
|
|
|
2010-05-29 09:58:58 +02:00
|
|
|
|
int updateLoops= getUpdateLoops();
|
2010-03-13 22:10:45 +01:00
|
|
|
|
|
2010-05-03 08:25:54 +02:00
|
|
|
|
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
2010-05-29 09:58:58 +02:00
|
|
|
|
|
2010-06-15 18:27:52 +02:00
|
|
|
|
if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d took msecs: %d\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis());
|
|
|
|
|
|
2010-06-01 18:54:44 +02:00
|
|
|
|
NetworkManager &networkManager= NetworkManager::getInstance();
|
2010-05-29 09:58:58 +02:00
|
|
|
|
//update
|
|
|
|
|
for(int i=0; i<updateLoops; ++i){
|
|
|
|
|
Renderer &renderer= Renderer::getInstance();
|
|
|
|
|
|
|
|
|
|
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
2010-06-03 03:10:40 +02:00
|
|
|
|
if( this->gameSettings.getEnableServerControlledAI() == false ||
|
|
|
|
|
this->gameSettings.isNetworkGame() == false ||
|
2010-06-01 18:54:44 +02:00
|
|
|
|
(this->gameSettings.isNetworkGame() == true && networkManager.getNetworkRole() == nrServer)) {
|
|
|
|
|
//AiInterface
|
|
|
|
|
for(int i=0; i<world.getFactionCount(); ++i){
|
|
|
|
|
if(world.getFaction(i)->getCpuControl() && scriptManager.getPlayerModifiers(i)->getAiEnabled()){
|
|
|
|
|
aiInterfaces[i]->update();
|
|
|
|
|
}
|
2010-05-29 09:58:58 +02:00
|
|
|
|
}
|
2010-03-13 22:10:45 +01:00
|
|
|
|
}
|
2010-06-15 18:27:52 +02:00
|
|
|
|
if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d took msecs: %d\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis());
|
2010-03-13 22:10:45 +01:00
|
|
|
|
|
2010-05-29 09:58:58 +02:00
|
|
|
|
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
|
|
|
|
//World
|
|
|
|
|
world.update();
|
2010-06-15 18:27:52 +02:00
|
|
|
|
if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d took msecs: %d\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis());
|
2010-03-13 22:10:45 +01:00
|
|
|
|
|
2010-05-29 09:58:58 +02:00
|
|
|
|
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
|
|
|
|
// Commander
|
|
|
|
|
commander.updateNetwork();
|
2010-06-15 18:27:52 +02:00
|
|
|
|
if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d took msecs: %d\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis());
|
2010-03-13 22:10:45 +01:00
|
|
|
|
|
2010-05-29 09:58:58 +02:00
|
|
|
|
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
|
|
|
|
//Gui
|
|
|
|
|
gui.update();
|
2010-06-15 18:27:52 +02:00
|
|
|
|
if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d took msecs: %d\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis());
|
2010-03-13 22:10:45 +01:00
|
|
|
|
|
2010-05-29 09:58:58 +02:00
|
|
|
|
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
|
|
|
|
//Particle systems
|
|
|
|
|
if(weatherParticleSystem != NULL){
|
|
|
|
|
weatherParticleSystem->setPos(gameCamera.getPos());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
|
|
|
|
renderer.updateParticleManager(rsGame);
|
2010-06-15 18:27:52 +02:00
|
|
|
|
if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d took msecs: %d\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis());
|
2010-05-29 09:58:58 +02:00
|
|
|
|
|
|
|
|
|
//good_fpu_control_registers(NULL,__FILE__,__FUNCTION__,__LINE__);
|
2010-03-13 22:10:45 +01:00
|
|
|
|
}
|
2010-05-03 08:25:54 +02:00
|
|
|
|
|
|
|
|
|
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
2010-05-29 09:58:58 +02:00
|
|
|
|
//call the chat manager
|
|
|
|
|
chatManager.updateNetwork();
|
2010-04-24 14:22:35 +02:00
|
|
|
|
|
2010-05-29 09:58:58 +02:00
|
|
|
|
//check for quiting status
|
|
|
|
|
if(NetworkManager::getInstance().getGameNetworkInterface()->getQuit() && mainMessageBox.getEnabled() == false) {
|
|
|
|
|
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
|
|
|
|
quitGame();
|
|
|
|
|
}
|
2010-03-13 22:10:45 +01:00
|
|
|
|
|
2010-05-29 09:58:58 +02:00
|
|
|
|
//update auto test
|
|
|
|
|
if(Config::getInstance().getBool("AutoTest")){
|
|
|
|
|
AutoTest::getInstance().updateGame(this);
|
|
|
|
|
}
|
2010-03-13 22:10:45 +01:00
|
|
|
|
|
2010-05-29 09:58:58 +02:00
|
|
|
|
//throw runtime_error("Test!");
|
2010-03-13 22:10:45 +01:00
|
|
|
|
|
2010-05-29 09:58:58 +02:00
|
|
|
|
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
|
|
|
|
}
|
|
|
|
|
catch(const exception &ex) {
|
|
|
|
|
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] Error [%s]\n",__FILE__,__FUNCTION__,__LINE__,ex.what());
|
|
|
|
|
NetworkManager &networkManager= NetworkManager::getInstance();
|
|
|
|
|
networkManager.getGameNetworkInterface()->quitGame(true);
|
|
|
|
|
ErrorDisplayMessage(ex.what(),true);
|
2010-03-13 22:10:45 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Game::updateCamera(){
|
|
|
|
|
gameCamera.update();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// ==================== render ====================
|
|
|
|
|
|
|
|
|
|
//render
|
2010-05-06 23:29:46 +02:00
|
|
|
|
void Game::render() {
|
2010-05-07 08:46:55 +02:00
|
|
|
|
//SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d renderFps = %d\n",__FILE__,__FUNCTION__,__LINE__,renderFps);
|
|
|
|
|
|
2010-06-24 03:23:18 +02:00
|
|
|
|
// Ensure the camera starts in the right position
|
|
|
|
|
if(isFirstRender == true) {
|
|
|
|
|
isFirstRender = false;
|
2010-06-25 02:45:46 +02:00
|
|
|
|
|
|
|
|
|
/*
|
2010-06-24 03:23:18 +02:00
|
|
|
|
Map *map= world.getMap();
|
|
|
|
|
const Vec2i &v= map->getStartLocation(world.getThisFaction()->getStartLocationIndex());
|
|
|
|
|
gameCamera.init(map->getW(), map->getH());
|
|
|
|
|
gameCamera.setPos(Vec2f(v.x, v.y));
|
2010-06-25 02:45:46 +02:00
|
|
|
|
|
|
|
|
|
//const Vec2i &mapPos = Map::toSurfCoords(v);
|
|
|
|
|
Renderer &renderer= Renderer::getInstance();
|
|
|
|
|
Vec3f screenPos = renderer.computeScreenPosition(gameCamera.getPos());
|
|
|
|
|
SDL_WarpMouse(v.x, v.y);
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
gameCamera.resetPosition();
|
|
|
|
|
this->restoreToStartXY();
|
2010-06-24 03:23:18 +02:00
|
|
|
|
}
|
|
|
|
|
|
2010-05-07 08:46:55 +02:00
|
|
|
|
renderFps++;
|
2010-06-01 18:54:44 +02:00
|
|
|
|
renderWorker();
|
2010-05-07 08:46:55 +02:00
|
|
|
|
//SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d renderFps = %d\n",__FILE__,__FUNCTION__,__LINE__,renderFps);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Game::renderWorker() {
|
2010-06-15 07:36:07 +02:00
|
|
|
|
//Chrono chrono;
|
|
|
|
|
//chrono.start();
|
2010-05-06 23:29:46 +02:00
|
|
|
|
|
2010-05-03 08:25:54 +02:00
|
|
|
|
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
|
|
|
|
|
2010-05-07 08:46:55 +02:00
|
|
|
|
//program->getWindow()->makeCurrentGl();
|
|
|
|
|
|
|
|
|
|
//renderFps++;
|
2010-06-15 18:27:52 +02:00
|
|
|
|
//if(renderFps >= MIN_RENDER_FPS_ALLOWED) {
|
|
|
|
|
render3d();
|
|
|
|
|
//}
|
2010-05-07 08:46:55 +02:00
|
|
|
|
//if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d renderFps = %d took msecs: %d\n",__FILE__,__FUNCTION__,__LINE__,renderFps,chrono.getMillis());
|
2010-05-03 08:25:54 +02:00
|
|
|
|
|
|
|
|
|
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
|
|
|
|
|
2010-06-15 07:36:07 +02:00
|
|
|
|
//chrono.start();
|
2010-03-13 22:10:45 +01:00
|
|
|
|
render2d();
|
2010-05-07 08:46:55 +02:00
|
|
|
|
//if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d renderFps = %d took msecs: %d\n",__FILE__,__FUNCTION__,__LINE__,renderFps,chrono.getMillis());
|
2010-05-03 08:25:54 +02:00
|
|
|
|
|
|
|
|
|
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
|
|
|
|
|
2010-06-15 07:36:07 +02:00
|
|
|
|
//chrono.start();
|
2010-03-13 22:10:45 +01:00
|
|
|
|
Renderer::getInstance().swapBuffers();
|
2010-05-07 08:46:55 +02:00
|
|
|
|
//if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d renderFps = %d took msecs: %d\n",__FILE__,__FUNCTION__,__LINE__,renderFps,chrono.getMillis());
|
2010-05-03 08:25:54 +02:00
|
|
|
|
|
|
|
|
|
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
2010-03-13 22:10:45 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ==================== tick ====================
|
|
|
|
|
|
|
|
|
|
void Game::tick(){
|
|
|
|
|
lastUpdateFps= updateFps;
|
|
|
|
|
lastRenderFps= renderFps;
|
|
|
|
|
updateFps= 0;
|
|
|
|
|
renderFps= 0;
|
|
|
|
|
|
|
|
|
|
//Win/lose check
|
|
|
|
|
checkWinner();
|
|
|
|
|
gui.tick();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// ==================== events ====================
|
|
|
|
|
|
|
|
|
|
void Game::mouseDownLeft(int x, int y){
|
|
|
|
|
|
2010-05-29 09:58:58 +02:00
|
|
|
|
try {
|
|
|
|
|
Map *map= world.getMap();
|
|
|
|
|
const Metrics &metrics= Metrics::getInstance();
|
|
|
|
|
NetworkManager &networkManager= NetworkManager::getInstance();
|
|
|
|
|
bool messageBoxClick= false;
|
|
|
|
|
|
|
|
|
|
//scrip message box, only if the exit box is not enabled
|
|
|
|
|
if(!mainMessageBox.getEnabled() && scriptManager.getMessageBox()->getEnabled()){
|
|
|
|
|
int button= 1;
|
|
|
|
|
if(scriptManager.getMessageBox()->mouseClick(x, y, button)){
|
|
|
|
|
scriptManager.onMessageBoxOk();
|
|
|
|
|
messageBoxClick= true;
|
|
|
|
|
}
|
2010-03-13 22:10:45 +01:00
|
|
|
|
}
|
|
|
|
|
|
2010-05-29 09:58:58 +02:00
|
|
|
|
//minimap panel
|
|
|
|
|
if(!messageBoxClick){
|
|
|
|
|
if(metrics.isInMinimap(x, y) && !gui.isSelectingPos()){
|
2010-03-13 22:10:45 +01:00
|
|
|
|
|
2010-05-29 09:58:58 +02:00
|
|
|
|
int xm= x - metrics.getMinimapX();
|
|
|
|
|
int ym= y - metrics.getMinimapY();
|
|
|
|
|
int xCell= static_cast<int>(xm * (static_cast<float>(map->getW()) / metrics.getMinimapW()));
|
|
|
|
|
int yCell= static_cast<int>(map->getH() - ym * (static_cast<float>(map->getH()) / metrics.getMinimapH()));
|
2010-03-13 22:10:45 +01:00
|
|
|
|
|
2010-05-29 09:58:58 +02:00
|
|
|
|
if(map->isInside(xCell, yCell)){
|
|
|
|
|
if(!gui.isSelectingPos()){
|
|
|
|
|
gameCamera.setPos(Vec2f(static_cast<float>(xCell), static_cast<float>(yCell)));
|
|
|
|
|
}
|
2010-03-13 22:10:45 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2010-05-29 09:58:58 +02:00
|
|
|
|
//display panel
|
|
|
|
|
else if(metrics.isInDisplay(x, y) && !gui.isSelectingPos()){
|
|
|
|
|
int xd= x - metrics.getDisplayX();
|
|
|
|
|
int yd= y - metrics.getDisplayY();
|
|
|
|
|
if(gui.mouseValid(xd, yd)){
|
|
|
|
|
gui.mouseDownLeftDisplay(xd, yd);
|
|
|
|
|
}
|
|
|
|
|
else{
|
|
|
|
|
gui.mouseDownLeftGraphics(x, y);
|
|
|
|
|
}
|
2010-03-13 22:10:45 +01:00
|
|
|
|
}
|
2010-05-29 09:58:58 +02:00
|
|
|
|
|
|
|
|
|
//graphics panel
|
2010-03-13 22:10:45 +01:00
|
|
|
|
else{
|
|
|
|
|
gui.mouseDownLeftGraphics(x, y);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2010-05-29 09:58:58 +02:00
|
|
|
|
//exit message box, has to be the last thing to do in this function
|
|
|
|
|
if(mainMessageBox.getEnabled()){
|
|
|
|
|
int button= 1;
|
|
|
|
|
if(mainMessageBox.mouseClick(x, y, button)) {
|
|
|
|
|
if(button==1) {
|
|
|
|
|
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
|
|
|
|
networkManager.getGameNetworkInterface()->quitGame(true);
|
|
|
|
|
quitGame();
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
|
|
|
|
//close message box
|
|
|
|
|
mainMessageBox.setEnabled(false);
|
|
|
|
|
}
|
2010-03-13 22:10:45 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2010-05-29 09:58:58 +02:00
|
|
|
|
catch(const exception &ex) {
|
|
|
|
|
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] Error [%s]\n",__FILE__,__FUNCTION__,__LINE__,ex.what());
|
|
|
|
|
NetworkManager &networkManager= NetworkManager::getInstance();
|
|
|
|
|
networkManager.getGameNetworkInterface()->quitGame(true);
|
|
|
|
|
ErrorDisplayMessage(ex.what(),true);
|
|
|
|
|
}
|
2010-03-13 22:10:45 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Game::mouseDownRight(int x, int y){
|
2010-05-29 09:58:58 +02:00
|
|
|
|
try {
|
|
|
|
|
gui.mouseDownRightGraphics(x, y);
|
|
|
|
|
}
|
|
|
|
|
catch(const exception &ex) {
|
|
|
|
|
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] Error [%s]\n",__FILE__,__FUNCTION__,__LINE__,ex.what());
|
|
|
|
|
NetworkManager &networkManager= NetworkManager::getInstance();
|
|
|
|
|
networkManager.getGameNetworkInterface()->quitGame(true);
|
|
|
|
|
ErrorDisplayMessage(ex.what(),true);
|
|
|
|
|
}
|
2010-03-13 22:10:45 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Game::mouseUpLeft(int x, int y){
|
2010-05-29 09:58:58 +02:00
|
|
|
|
try {
|
|
|
|
|
gui.mouseUpLeftGraphics(x, y);
|
|
|
|
|
}
|
|
|
|
|
catch(const exception &ex) {
|
|
|
|
|
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] Error [%s]\n",__FILE__,__FUNCTION__,__LINE__,ex.what());
|
|
|
|
|
NetworkManager &networkManager= NetworkManager::getInstance();
|
|
|
|
|
networkManager.getGameNetworkInterface()->quitGame(true);
|
|
|
|
|
ErrorDisplayMessage(ex.what(),true);
|
|
|
|
|
}
|
2010-03-13 22:10:45 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Game::mouseDoubleClickLeft(int x, int y){
|
2010-05-29 09:58:58 +02:00
|
|
|
|
try {
|
|
|
|
|
const Metrics &metrics= Metrics::getInstance();
|
|
|
|
|
|
|
|
|
|
//display panel
|
|
|
|
|
if(metrics.isInDisplay(x, y) && !gui.isSelectingPos()){
|
|
|
|
|
int xd= x - metrics.getDisplayX();
|
|
|
|
|
int yd= y - metrics.getDisplayY();
|
|
|
|
|
if(gui.mouseValid(xd, yd)){
|
|
|
|
|
return;
|
|
|
|
|
}
|
2010-03-13 22:10:45 +01:00
|
|
|
|
}
|
|
|
|
|
|
2010-05-29 09:58:58 +02:00
|
|
|
|
//graphics panel
|
|
|
|
|
gui.mouseDoubleClickLeftGraphics(x, y);
|
|
|
|
|
}
|
|
|
|
|
catch(const exception &ex) {
|
|
|
|
|
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] Error [%s]\n",__FILE__,__FUNCTION__,__LINE__,ex.what());
|
|
|
|
|
NetworkManager &networkManager= NetworkManager::getInstance();
|
|
|
|
|
networkManager.getGameNetworkInterface()->quitGame(true);
|
|
|
|
|
ErrorDisplayMessage(ex.what(),true);
|
|
|
|
|
}
|
2010-03-13 22:10:45 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Game::mouseMove(int x, int y, const MouseState *ms){
|
2010-05-29 09:58:58 +02:00
|
|
|
|
try {
|
|
|
|
|
const Metrics &metrics = Metrics::getInstance();
|
|
|
|
|
|
|
|
|
|
mouseX = x;
|
|
|
|
|
mouseY = y;
|
|
|
|
|
|
|
|
|
|
if (ms->get(mbCenter)) {
|
|
|
|
|
//if (input.isCtrlDown()) {
|
|
|
|
|
// float speed = input.isShiftDown() ? 1.f : 0.125f;
|
|
|
|
|
// float response = input.isShiftDown() ? 0.1875f : 0.0625f;
|
|
|
|
|
// gameCamera.moveForwardH((y - lastMousePos.y) * speed, response);
|
|
|
|
|
// gameCamera.moveSideH((x - lastMousePos.x) * speed, response);
|
|
|
|
|
//} else
|
|
|
|
|
{
|
|
|
|
|
//float ymult = Config::getInstance().getCameraInvertYAxis() ? -0.2f : 0.2f;
|
|
|
|
|
//float xmult = Config::getInstance().getCameraInvertXAxis() ? -0.2f : 0.2f;
|
|
|
|
|
float ymult = 0.2f;
|
|
|
|
|
float xmult = 0.2f;
|
2010-03-23 03:35:55 +01:00
|
|
|
|
|
2010-05-29 09:58:58 +02:00
|
|
|
|
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
2010-03-30 02:25:35 +02:00
|
|
|
|
|
2010-05-29 09:58:58 +02:00
|
|
|
|
gameCamera.transitionVH(-(y - lastMousePos.y) * ymult, (lastMousePos.x - x) * xmult);
|
|
|
|
|
mouseX=lastMousePos.x;
|
|
|
|
|
mouseY=lastMousePos.y;
|
|
|
|
|
Window::revertMousePos();
|
2010-03-30 02:25:35 +02:00
|
|
|
|
|
2010-05-29 09:58:58 +02:00
|
|
|
|
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
2010-03-30 02:25:35 +02:00
|
|
|
|
|
2010-05-29 09:58:58 +02:00
|
|
|
|
return;
|
2010-03-27 22:32:33 +01:00
|
|
|
|
}
|
2010-05-29 09:58:58 +02:00
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
//main window
|
|
|
|
|
if(Window::isKeyDown() == false) {
|
|
|
|
|
if (y < 10) {
|
|
|
|
|
gameCamera.setMoveZ(-scrollSpeed);
|
|
|
|
|
}
|
|
|
|
|
else if (y > metrics.getVirtualH() - 10) {
|
|
|
|
|
gameCamera.setMoveZ(scrollSpeed);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
gameCamera.setMoveZ(0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (x < 10) {
|
|
|
|
|
gameCamera.setMoveX(-scrollSpeed);
|
|
|
|
|
}
|
|
|
|
|
else if (x > metrics.getVirtualW() - 10) {
|
|
|
|
|
gameCamera.setMoveX(scrollSpeed);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
gameCamera.setMoveX(0);
|
|
|
|
|
}
|
2010-03-27 22:32:33 +01:00
|
|
|
|
}
|
2010-03-13 22:10:45 +01:00
|
|
|
|
|
2010-05-29 09:58:58 +02:00
|
|
|
|
if (mainMessageBox.getEnabled()) {
|
|
|
|
|
mainMessageBox.mouseMove(x, y);
|
2010-03-27 22:32:33 +01:00
|
|
|
|
}
|
2010-05-29 09:58:58 +02:00
|
|
|
|
if (scriptManager.getMessageBox()->getEnabled()) {
|
|
|
|
|
scriptManager.getMessageBox()->mouseMove(x, y);
|
2010-03-27 22:32:33 +01:00
|
|
|
|
}
|
2010-05-29 09:58:58 +02:00
|
|
|
|
//else if (saveBox) {
|
|
|
|
|
// saveBox->mouseMove(x, y);
|
|
|
|
|
//} else {
|
|
|
|
|
// //graphics
|
|
|
|
|
gui.mouseMoveGraphics(x, y);
|
|
|
|
|
//}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//display
|
|
|
|
|
if (metrics.isInDisplay(x, y) && !gui.isSelecting() && !gui.isSelectingPos()) {
|
|
|
|
|
if (!gui.isSelectingPos()) {
|
|
|
|
|
gui.mouseMoveDisplay(x - metrics.getDisplayX(), y - metrics.getDisplayY());
|
2010-03-27 22:32:33 +01:00
|
|
|
|
}
|
2010-03-23 03:35:55 +01:00
|
|
|
|
}
|
2010-03-13 22:10:45 +01:00
|
|
|
|
|
2010-05-29 09:58:58 +02:00
|
|
|
|
lastMousePos.x = mouseX;
|
|
|
|
|
lastMousePos.y = mouseY;
|
|
|
|
|
}
|
|
|
|
|
catch(const exception &ex) {
|
|
|
|
|
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] Error [%s]\n",__FILE__,__FUNCTION__,__LINE__,ex.what());
|
|
|
|
|
NetworkManager &networkManager= NetworkManager::getInstance();
|
|
|
|
|
networkManager.getGameNetworkInterface()->quitGame(true);
|
|
|
|
|
ErrorDisplayMessage(ex.what(),true);
|
2010-03-13 22:10:45 +01:00
|
|
|
|
}
|
2010-03-23 03:35:55 +01:00
|
|
|
|
}
|
2010-03-13 22:10:45 +01:00
|
|
|
|
|
2010-03-23 03:35:55 +01:00
|
|
|
|
void Game::eventMouseWheel(int x, int y, int zDelta) {
|
2010-05-29 09:58:58 +02:00
|
|
|
|
try {
|
|
|
|
|
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
|
|
|
|
//gameCamera.transitionXYZ(0.0f, -(float)zDelta / 30.0f, 0.0f);
|
|
|
|
|
gameCamera.zoom((float)zDelta / 60.0f);
|
|
|
|
|
//gameCamera.setMoveY(1);
|
|
|
|
|
}
|
|
|
|
|
catch(const exception &ex) {
|
|
|
|
|
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] Error [%s]\n",__FILE__,__FUNCTION__,__LINE__,ex.what());
|
|
|
|
|
NetworkManager &networkManager= NetworkManager::getInstance();
|
|
|
|
|
networkManager.getGameNetworkInterface()->quitGame(true);
|
|
|
|
|
ErrorDisplayMessage(ex.what(),true);
|
|
|
|
|
}
|
2010-03-13 22:10:45 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Game::keyDown(char key){
|
2010-05-29 09:58:58 +02:00
|
|
|
|
try {
|
2010-06-13 19:55:39 +02:00
|
|
|
|
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] key = [%c] [%d]\n",__FILE__,__FUNCTION__,__LINE__,key,key);
|
2010-03-13 22:10:45 +01:00
|
|
|
|
|
2010-05-29 09:58:58 +02:00
|
|
|
|
Lang &lang= Lang::getInstance();
|
|
|
|
|
bool speedChangesAllowed= !NetworkManager::getInstance().isNetworkGame();
|
2010-04-06 16:09:42 +02:00
|
|
|
|
|
2010-05-29 09:58:58 +02:00
|
|
|
|
//send key to the chat manager
|
|
|
|
|
chatManager.keyDown(key);
|
2010-03-13 22:10:45 +01:00
|
|
|
|
|
2010-05-29 09:58:58 +02:00
|
|
|
|
if(!chatManager.getEditEnabled()){
|
|
|
|
|
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] key = %d\n",__FILE__,__FUNCTION__,__LINE__,key);
|
2010-03-13 22:10:45 +01:00
|
|
|
|
|
2010-06-12 20:27:39 +02:00
|
|
|
|
Config &configKeys = Config::getInstance(std::pair<ConfigType,ConfigType>(cfgMainKeys,cfgUserKeys));
|
|
|
|
|
|
|
|
|
|
if(key == configKeys.getCharKey("RenderNetworkStatus")) {
|
2010-06-15 07:36:07 +02:00
|
|
|
|
renderNetworkStatus= !renderNetworkStatus;
|
2010-05-29 09:58:58 +02:00
|
|
|
|
}
|
2010-06-12 20:27:39 +02:00
|
|
|
|
else if(key == configKeys.getCharKey("ShowFullConsole")) {
|
2010-05-29 09:58:58 +02:00
|
|
|
|
showFullConsole= true;
|
|
|
|
|
}
|
2010-06-12 20:27:39 +02:00
|
|
|
|
else if(key == configKeys.getCharKey("Screenshot")) {
|
2010-05-29 09:58:58 +02:00
|
|
|
|
for(int i=0; i<100; ++i){
|
|
|
|
|
string path= "screens/screen" + intToStr(i) + ".tga";
|
2010-03-13 22:10:45 +01:00
|
|
|
|
|
2010-05-29 09:58:58 +02:00
|
|
|
|
FILE *f= fopen(path.c_str(), "rb");
|
|
|
|
|
if(f==NULL){
|
|
|
|
|
Renderer::getInstance().saveScreen(path);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
else{
|
|
|
|
|
fclose(f);
|
|
|
|
|
}
|
2010-03-13 22:10:45 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
2010-05-29 09:58:58 +02:00
|
|
|
|
//move camera left
|
2010-06-12 20:27:39 +02:00
|
|
|
|
else if(key == configKeys.getCharKey("CameraModeLeft")) {
|
2010-05-29 09:58:58 +02:00
|
|
|
|
gameCamera.setMoveX(-1);
|
|
|
|
|
}
|
|
|
|
|
//move camera right
|
2010-06-12 20:27:39 +02:00
|
|
|
|
else if(key == configKeys.getCharKey("CameraModeRight")) {
|
2010-05-29 09:58:58 +02:00
|
|
|
|
gameCamera.setMoveX(1);
|
|
|
|
|
}
|
|
|
|
|
//move camera up
|
2010-06-12 20:27:39 +02:00
|
|
|
|
else if(key == configKeys.getCharKey("CameraModeUp")) {
|
2010-05-29 09:58:58 +02:00
|
|
|
|
gameCamera.setMoveZ(1);
|
|
|
|
|
}
|
|
|
|
|
//move camera down
|
2010-06-12 20:27:39 +02:00
|
|
|
|
else if(key == configKeys.getCharKey("CameraModeDown")) {
|
2010-05-29 09:58:58 +02:00
|
|
|
|
gameCamera.setMoveZ(-1);
|
|
|
|
|
}
|
|
|
|
|
//change camera mode
|
2010-06-12 20:27:39 +02:00
|
|
|
|
else if(key == configKeys.getCharKey("FreeCameraMode")) {
|
2010-05-29 09:58:58 +02:00
|
|
|
|
gameCamera.switchState();
|
|
|
|
|
string stateString= gameCamera.getState()==GameCamera::sGame? lang.get("GameCamera"): lang.get("FreeCamera");
|
|
|
|
|
console.addLine(lang.get("CameraModeSet")+" "+ stateString);
|
|
|
|
|
}
|
|
|
|
|
//reset camera mode to normal
|
2010-06-12 20:27:39 +02:00
|
|
|
|
else if(key == configKeys.getCharKey("ResetCameraMode")) {
|
2010-05-29 09:58:58 +02:00
|
|
|
|
gameCamera.resetPosition();
|
|
|
|
|
}
|
|
|
|
|
//pause
|
2010-06-12 20:27:39 +02:00
|
|
|
|
else if(key == configKeys.getCharKey("PauseGame")) {
|
2010-05-29 09:58:58 +02:00
|
|
|
|
if(speedChangesAllowed){
|
|
|
|
|
if(paused){
|
|
|
|
|
console.addLine(lang.get("GameResumed"));
|
|
|
|
|
paused= false;
|
|
|
|
|
}
|
|
|
|
|
else{
|
|
|
|
|
console.addLine(lang.get("GamePaused"));
|
|
|
|
|
paused= true;
|
|
|
|
|
}
|
2010-03-13 22:10:45 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
2010-05-29 09:58:58 +02:00
|
|
|
|
//switch display color
|
2010-06-12 20:27:39 +02:00
|
|
|
|
else if(key == configKeys.getCharKey("ChangeFontColor")) {
|
2010-05-29 09:58:58 +02:00
|
|
|
|
gui.switchToNextDisplayColor();
|
2010-03-13 22:10:45 +01:00
|
|
|
|
}
|
2010-05-29 09:58:58 +02:00
|
|
|
|
//increment speed
|
2010-06-12 20:27:39 +02:00
|
|
|
|
else if(key == configKeys.getCharKey("GameSpeedIncrease")) {
|
2010-05-29 09:58:58 +02:00
|
|
|
|
if(speedChangesAllowed){
|
|
|
|
|
incSpeed();
|
|
|
|
|
}
|
2010-03-13 22:10:45 +01:00
|
|
|
|
}
|
2010-05-29 09:58:58 +02:00
|
|
|
|
//decrement speed
|
2010-06-12 20:27:39 +02:00
|
|
|
|
else if(key == configKeys.getCharKey("GameSpeedDecrease")) {
|
2010-05-29 09:58:58 +02:00
|
|
|
|
if(speedChangesAllowed){
|
|
|
|
|
decSpeed();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
//exit
|
2010-06-12 20:27:39 +02:00
|
|
|
|
else if(key == configKeys.getCharKey("ExitKey")) {
|
2010-05-29 09:58:58 +02:00
|
|
|
|
showMessageBox(lang.get("ExitGame?"), "", true);
|
|
|
|
|
}
|
|
|
|
|
//group
|
2010-06-12 20:27:39 +02:00
|
|
|
|
//else if(key>='0' && key<'0'+Selection::maxGroups){
|
|
|
|
|
else {
|
2010-05-29 09:58:58 +02:00
|
|
|
|
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] key = %d\n",__FILE__,__FUNCTION__,__LINE__,key);
|
2010-03-13 22:10:45 +01:00
|
|
|
|
|
2010-06-12 20:27:39 +02:00
|
|
|
|
for(int idx = 1; idx <= Selection::maxGroups; idx++) {
|
|
|
|
|
string keyName = "GroupUnitsKey" + intToStr(idx);
|
2010-06-13 19:55:39 +02:00
|
|
|
|
char groupHotKey = configKeys.getCharKey(keyName.c_str());
|
|
|
|
|
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] keyName [%s] group index = %d, key = [%c] [%d]\n",__FILE__,__FUNCTION__,__LINE__,keyName.c_str(),idx,groupHotKey,groupHotKey);
|
|
|
|
|
|
|
|
|
|
if(key == groupHotKey) {
|
2010-06-12 20:27:39 +02:00
|
|
|
|
//gui.groupKey(key-'0');
|
2010-06-13 19:55:39 +02:00
|
|
|
|
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
2010-06-12 20:27:39 +02:00
|
|
|
|
gui.groupKey(idx-1);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
2010-05-29 09:58:58 +02:00
|
|
|
|
}
|
2010-04-06 16:09:42 +02:00
|
|
|
|
|
2010-05-29 09:58:58 +02:00
|
|
|
|
//hotkeys
|
|
|
|
|
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] gameCamera.getState() = %d\n",__FILE__,__FUNCTION__,__LINE__,gameCamera.getState());
|
2010-04-06 16:09:42 +02:00
|
|
|
|
|
2010-05-29 09:58:58 +02:00
|
|
|
|
if(gameCamera.getState() == GameCamera::sGame){
|
|
|
|
|
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] key = %d\n",__FILE__,__FUNCTION__,__LINE__,key);
|
2010-03-13 22:10:45 +01:00
|
|
|
|
|
2010-05-29 09:58:58 +02:00
|
|
|
|
gui.hotKey(key);
|
2010-03-13 22:10:45 +01:00
|
|
|
|
}
|
2010-06-12 20:27:39 +02:00
|
|
|
|
else {
|
2010-05-29 09:58:58 +02:00
|
|
|
|
//rotate camera leftt
|
2010-06-12 20:27:39 +02:00
|
|
|
|
if(key == configKeys.getCharKey("CameraRotateLeft")) {
|
2010-05-29 09:58:58 +02:00
|
|
|
|
gameCamera.setRotate(-1);
|
|
|
|
|
}
|
|
|
|
|
//rotate camera right
|
2010-06-12 20:27:39 +02:00
|
|
|
|
else if(key == configKeys.getCharKey("CameraRotateRight")){
|
2010-05-29 09:58:58 +02:00
|
|
|
|
gameCamera.setRotate(1);
|
|
|
|
|
}
|
|
|
|
|
//camera up
|
2010-06-12 20:27:39 +02:00
|
|
|
|
else if(key == configKeys.getCharKey("CameraRotateUp")) {
|
2010-05-29 09:58:58 +02:00
|
|
|
|
gameCamera.setMoveY(1);
|
|
|
|
|
}
|
|
|
|
|
//camera down
|
2010-06-12 20:27:39 +02:00
|
|
|
|
else if(key == configKeys.getCharKey("CameraRotateDown")) {
|
2010-05-29 09:58:58 +02:00
|
|
|
|
gameCamera.setMoveY(-1);
|
|
|
|
|
}
|
2010-03-13 22:10:45 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2010-05-29 09:58:58 +02:00
|
|
|
|
catch(const exception &ex) {
|
|
|
|
|
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] Error [%s]\n",__FILE__,__FUNCTION__,__LINE__,ex.what());
|
|
|
|
|
NetworkManager &networkManager= NetworkManager::getInstance();
|
|
|
|
|
networkManager.getGameNetworkInterface()->quitGame(true);
|
|
|
|
|
ErrorDisplayMessage(ex.what(),true);
|
|
|
|
|
}
|
2010-03-13 22:10:45 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Game::keyUp(char key){
|
2010-05-29 09:58:58 +02:00
|
|
|
|
try {
|
|
|
|
|
if(chatManager.getEditEnabled()){
|
|
|
|
|
//send key to the chat manager
|
|
|
|
|
chatManager.keyUp(key);
|
|
|
|
|
}
|
2010-06-15 07:36:07 +02:00
|
|
|
|
else {
|
|
|
|
|
Config &configKeys = Config::getInstance(std::pair<ConfigType,ConfigType>(cfgMainKeys,cfgUserKeys));
|
|
|
|
|
|
|
|
|
|
if(key == configKeys.getCharKey("RenderNetworkStatus")) {
|
|
|
|
|
//renderNetworkStatus= false;
|
|
|
|
|
}
|
|
|
|
|
else if(key == configKeys.getCharKey("ShowFullConsole")) {
|
2010-05-29 09:58:58 +02:00
|
|
|
|
showFullConsole= false;
|
2010-06-15 07:36:07 +02:00
|
|
|
|
}
|
|
|
|
|
else if(key == configKeys.getCharKey("CameraRotateLeft") ||
|
|
|
|
|
key == configKeys.getCharKey("CameraRotateRight")) {
|
2010-05-29 09:58:58 +02:00
|
|
|
|
gameCamera.setRotate(0);
|
2010-06-15 07:36:07 +02:00
|
|
|
|
}
|
|
|
|
|
else if(key == configKeys.getCharKey("CameraRotateDown") ||
|
|
|
|
|
key == configKeys.getCharKey("CameraRotateUp")) {
|
2010-05-29 09:58:58 +02:00
|
|
|
|
gameCamera.setMoveY(0);
|
2010-06-15 07:36:07 +02:00
|
|
|
|
}
|
|
|
|
|
else if(key == configKeys.getCharKey("CameraModeUp") ||
|
|
|
|
|
key == configKeys.getCharKey("CameraModeDown")) {
|
2010-05-29 09:58:58 +02:00
|
|
|
|
gameCamera.setMoveZ(0);
|
2010-06-15 07:36:07 +02:00
|
|
|
|
}
|
|
|
|
|
else if(key == configKeys.getCharKey("CameraModeLeft") ||
|
|
|
|
|
key == configKeys.getCharKey("CameraModeRight")) {
|
2010-05-29 09:58:58 +02:00
|
|
|
|
gameCamera.setMoveX(0);
|
|
|
|
|
}
|
2010-03-13 22:10:45 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
2010-05-29 09:58:58 +02:00
|
|
|
|
catch(const exception &ex) {
|
|
|
|
|
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] Error [%s]\n",__FILE__,__FUNCTION__,__LINE__,ex.what());
|
|
|
|
|
NetworkManager &networkManager= NetworkManager::getInstance();
|
|
|
|
|
networkManager.getGameNetworkInterface()->quitGame(true);
|
|
|
|
|
ErrorDisplayMessage(ex.what(),true);
|
|
|
|
|
}
|
2010-03-13 22:10:45 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Game::keyPress(char c){
|
|
|
|
|
chatManager.keyPress(c);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Game::quitGame(){
|
2010-05-29 08:56:32 +02:00
|
|
|
|
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
2010-06-24 03:23:18 +02:00
|
|
|
|
|
|
|
|
|
Stats stats = *(world.getStats());
|
|
|
|
|
|
|
|
|
|
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
|
|
|
|
|
2010-06-24 13:27:21 +02:00
|
|
|
|
NetworkManager::getInstance().end();
|
|
|
|
|
|
2010-06-24 03:23:18 +02:00
|
|
|
|
program->setState(new BattleEnd(program, &stats));
|
2010-03-13 22:10:45 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ==================== PRIVATE ====================
|
|
|
|
|
|
|
|
|
|
// ==================== render ====================
|
|
|
|
|
|
|
|
|
|
void Game::render3d(){
|
2010-05-06 23:29:46 +02:00
|
|
|
|
Chrono chrono;
|
|
|
|
|
chrono.start();
|
|
|
|
|
|
2010-05-03 08:25:54 +02:00
|
|
|
|
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
2010-03-13 22:10:45 +01:00
|
|
|
|
Renderer &renderer= Renderer::getInstance();
|
|
|
|
|
|
|
|
|
|
//init
|
2010-05-03 08:25:54 +02:00
|
|
|
|
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
2010-03-13 22:10:45 +01:00
|
|
|
|
renderer.reset3d();
|
2010-05-06 23:29:46 +02:00
|
|
|
|
if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d renderFps = %d took msecs: %d\n",__FILE__,__FUNCTION__,__LINE__,renderFps,chrono.getMillis());
|
|
|
|
|
|
2010-05-03 08:25:54 +02:00
|
|
|
|
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
2010-05-06 23:29:46 +02:00
|
|
|
|
chrono.start();
|
2010-03-13 22:10:45 +01:00
|
|
|
|
renderer.computeVisibleQuad();
|
2010-05-06 23:29:46 +02:00
|
|
|
|
if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d renderFps = %d took msecs: %d\n",__FILE__,__FUNCTION__,__LINE__,renderFps,chrono.getMillis());
|
|
|
|
|
|
2010-05-03 08:25:54 +02:00
|
|
|
|
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
2010-05-06 23:29:46 +02:00
|
|
|
|
chrono.start();
|
2010-03-13 22:10:45 +01:00
|
|
|
|
renderer.loadGameCameraMatrix();
|
2010-05-06 23:29:46 +02:00
|
|
|
|
if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d renderFps = %d took msecs: %d\n",__FILE__,__FUNCTION__,__LINE__,renderFps,chrono.getMillis());
|
|
|
|
|
|
2010-05-03 08:25:54 +02:00
|
|
|
|
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
2010-05-06 23:29:46 +02:00
|
|
|
|
chrono.start();
|
2010-03-13 22:10:45 +01:00
|
|
|
|
renderer.setupLighting();
|
2010-05-06 23:29:46 +02:00
|
|
|
|
if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d renderFps = %d took msecs: %d\n",__FILE__,__FUNCTION__,__LINE__,renderFps,chrono.getMillis());
|
2010-03-13 22:10:45 +01:00
|
|
|
|
|
|
|
|
|
//shadow map
|
2010-05-03 08:25:54 +02:00
|
|
|
|
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
2010-05-06 23:29:46 +02:00
|
|
|
|
chrono.start();
|
2010-06-17 02:08:27 +02:00
|
|
|
|
renderer.renderShadowsToTexture(lastRenderFps);
|
2010-05-06 23:29:46 +02:00
|
|
|
|
if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d renderFps = %d took msecs: %d\n",__FILE__,__FUNCTION__,__LINE__,renderFps,chrono.getMillis());
|
2010-03-13 22:10:45 +01:00
|
|
|
|
|
|
|
|
|
//clear buffers
|
2010-05-03 08:25:54 +02:00
|
|
|
|
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
2010-05-06 23:29:46 +02:00
|
|
|
|
chrono.start();
|
2010-03-13 22:10:45 +01:00
|
|
|
|
renderer.clearBuffers();
|
2010-05-06 23:29:46 +02:00
|
|
|
|
if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d renderFps = %d took msecs: %d\n",__FILE__,__FUNCTION__,__LINE__,renderFps,chrono.getMillis());
|
2010-03-13 22:10:45 +01:00
|
|
|
|
|
|
|
|
|
//surface
|
2010-05-03 08:25:54 +02:00
|
|
|
|
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
2010-05-06 23:29:46 +02:00
|
|
|
|
chrono.start();
|
2010-03-13 22:10:45 +01:00
|
|
|
|
renderer.renderSurface();
|
2010-05-06 23:29:46 +02:00
|
|
|
|
if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d renderFps = %d took msecs: %d\n",__FILE__,__FUNCTION__,__LINE__,renderFps,chrono.getMillis());
|
2010-03-13 22:10:45 +01:00
|
|
|
|
|
|
|
|
|
//selection circles
|
2010-05-03 08:25:54 +02:00
|
|
|
|
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
2010-05-06 23:29:46 +02:00
|
|
|
|
chrono.start();
|
2010-03-13 22:10:45 +01:00
|
|
|
|
renderer.renderSelectionEffects();
|
2010-05-06 23:29:46 +02:00
|
|
|
|
if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d renderFps = %d took msecs: %d\n",__FILE__,__FUNCTION__,__LINE__,renderFps,chrono.getMillis());
|
2010-03-13 22:10:45 +01:00
|
|
|
|
|
|
|
|
|
//units
|
2010-05-03 08:25:54 +02:00
|
|
|
|
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
2010-05-06 23:29:46 +02:00
|
|
|
|
chrono.start();
|
2010-06-17 02:08:27 +02:00
|
|
|
|
renderer.renderUnits(lastRenderFps,world.getFrameCount());
|
2010-05-06 23:29:46 +02:00
|
|
|
|
if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d renderFps = %d took msecs: %d\n",__FILE__,__FUNCTION__,__LINE__,renderFps,chrono.getMillis());
|
2010-03-13 22:10:45 +01:00
|
|
|
|
|
|
|
|
|
//objects
|
2010-05-03 08:25:54 +02:00
|
|
|
|
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
2010-05-06 23:29:46 +02:00
|
|
|
|
chrono.start();
|
2010-06-17 02:08:27 +02:00
|
|
|
|
renderer.renderObjects(lastRenderFps,world.getFrameCount());
|
2010-05-06 23:29:46 +02:00
|
|
|
|
if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d renderFps = %d took msecs: %d\n",__FILE__,__FUNCTION__,__LINE__,renderFps,chrono.getMillis());
|
2010-03-13 22:10:45 +01:00
|
|
|
|
|
|
|
|
|
//water
|
2010-05-03 08:25:54 +02:00
|
|
|
|
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
2010-05-06 23:29:46 +02:00
|
|
|
|
chrono.start();
|
2010-03-13 22:10:45 +01:00
|
|
|
|
renderer.renderWater();
|
|
|
|
|
renderer.renderWaterEffects();
|
2010-05-06 23:29:46 +02:00
|
|
|
|
if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d renderFps = %d took msecs: %d\n",__FILE__,__FUNCTION__,__LINE__,renderFps,chrono.getMillis());
|
2010-03-13 22:10:45 +01:00
|
|
|
|
|
|
|
|
|
//particles
|
2010-05-03 08:25:54 +02:00
|
|
|
|
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
2010-05-06 23:29:46 +02:00
|
|
|
|
chrono.start();
|
2010-03-13 22:10:45 +01:00
|
|
|
|
renderer.renderParticleManager(rsGame);
|
2010-05-06 23:29:46 +02:00
|
|
|
|
if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d renderFps = %d took msecs: %d\n",__FILE__,__FUNCTION__,__LINE__,renderFps,chrono.getMillis());
|
2010-03-13 22:10:45 +01:00
|
|
|
|
|
|
|
|
|
//mouse 3d
|
2010-05-03 08:25:54 +02:00
|
|
|
|
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
2010-05-06 23:29:46 +02:00
|
|
|
|
chrono.start();
|
2010-03-13 22:10:45 +01:00
|
|
|
|
renderer.renderMouse3d();
|
2010-05-06 23:29:46 +02:00
|
|
|
|
if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d renderFps = %d took msecs: %d\n",__FILE__,__FUNCTION__,__LINE__,renderFps,chrono.getMillis());
|
2010-03-13 22:10:45 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Game::render2d(){
|
|
|
|
|
Renderer &renderer= Renderer::getInstance();
|
|
|
|
|
Config &config= Config::getInstance();
|
|
|
|
|
CoreData &coreData= CoreData::getInstance();
|
|
|
|
|
|
|
|
|
|
//init
|
|
|
|
|
renderer.reset2d();
|
|
|
|
|
|
|
|
|
|
//display
|
|
|
|
|
renderer.renderDisplay();
|
|
|
|
|
|
|
|
|
|
//minimap
|
|
|
|
|
if(!config.getBool("PhotoMode")){
|
|
|
|
|
renderer.renderMinimap();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//selection
|
|
|
|
|
renderer.renderSelectionQuad();
|
|
|
|
|
|
|
|
|
|
//exit message box
|
|
|
|
|
if(mainMessageBox.getEnabled()){
|
|
|
|
|
renderer.renderMessageBox(&mainMessageBox);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//script message box
|
|
|
|
|
if(!mainMessageBox.getEnabled() && scriptManager.getMessageBoxEnabled()){
|
|
|
|
|
renderer.renderMessageBox(scriptManager.getMessageBox());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//script display text
|
|
|
|
|
if(!scriptManager.getDisplayText().empty() && !scriptManager.getMessageBoxEnabled()){
|
|
|
|
|
renderer.renderText(
|
|
|
|
|
scriptManager.getDisplayText(), coreData.getMenuFontNormal(),
|
|
|
|
|
Vec3f(1.0f), 200, 680, false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
renderer.renderChatManager(&chatManager);
|
|
|
|
|
|
|
|
|
|
//debug info
|
2010-04-15 03:19:00 +02:00
|
|
|
|
|
|
|
|
|
string str;
|
2010-06-16 09:18:06 +02:00
|
|
|
|
if(gui.getShowDebugUI() == true || difftime(time(NULL),lastRenderLog2d) >= 1) {
|
2010-04-15 03:19:00 +02:00
|
|
|
|
str+= "MouseXY: " + intToStr(mouseX) + "," + intToStr(mouseY)+"\n";
|
2010-03-13 22:10:45 +01:00
|
|
|
|
str+= "PosObjWord: " + intToStr(gui.getPosObjWorld().x) + "," + intToStr(gui.getPosObjWorld().y)+"\n";
|
2010-04-15 03:19:00 +02:00
|
|
|
|
str+= "Render FPS: "+intToStr(lastRenderFps)+"\n";
|
|
|
|
|
str+= "Update FPS: "+intToStr(lastUpdateFps)+"\n";
|
|
|
|
|
str+= "GameCamera pos: "+floatToStr(gameCamera.getPos().x)+","+floatToStr(gameCamera.getPos().y)+","+floatToStr(gameCamera.getPos().z)+"\n";
|
2010-06-05 17:48:50 +02:00
|
|
|
|
str+= "Time: "+floatToStr(world.getTimeFlow()->getTime(),8)+"\n";
|
2010-03-13 22:10:45 +01:00
|
|
|
|
str+= "Triangle count: "+intToStr(renderer.getTriangleCount())+"\n";
|
|
|
|
|
str+= "Vertex count: "+intToStr(renderer.getPointCount())+"\n";
|
|
|
|
|
str+= "Frame count:"+intToStr(world.getFrameCount())+"\n";
|
|
|
|
|
|
|
|
|
|
//visible quad
|
|
|
|
|
Quad2i visibleQuad= renderer.getVisibleQuad();
|
|
|
|
|
|
|
|
|
|
str+= "Visible quad: ";
|
|
|
|
|
for(int i= 0; i<4; ++i){
|
|
|
|
|
str+= "(" + intToStr(visibleQuad.p[i].x) + "," +intToStr(visibleQuad.p[i].y) + ") ";
|
|
|
|
|
}
|
|
|
|
|
str+= "\n";
|
|
|
|
|
str+= "Visible quad area: " + floatToStr(visibleQuad.area()) +"\n";
|
|
|
|
|
|
2010-06-15 18:27:52 +02:00
|
|
|
|
int visibleUnitCount = 0;
|
|
|
|
|
for(int i=0; i< world.getFactionCount(); ++i){
|
|
|
|
|
for(int j=0; j< world.getFaction(i)->getUnitCount(); ++j){
|
|
|
|
|
Unit *unit = world.getFaction(i)->getUnit(j);
|
|
|
|
|
if(world.toRenderUnit(unit, visibleQuad)) {
|
|
|
|
|
visibleUnitCount++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
str+= "Visible unit count: " + intToStr(visibleUnitCount) +"\n";
|
|
|
|
|
|
|
|
|
|
int visibleObjectCount = 0;
|
|
|
|
|
Map *map= world.getMap();
|
|
|
|
|
int thisTeamIndex= world.getThisTeamIndex();
|
|
|
|
|
PosQuadIterator pqi(map, visibleQuad, Map::cellScale);
|
|
|
|
|
while(pqi.next()){
|
|
|
|
|
const Vec2i &pos= pqi.getPos();
|
|
|
|
|
bool isPosVisible = map->isInside(pos.x, pos.y);
|
|
|
|
|
if(isPosVisible == true) {
|
|
|
|
|
Vec2i mapPos = Map::toSurfCoords(pos);
|
|
|
|
|
SurfaceCell *sc= map->getSurfaceCell(mapPos.x, mapPos.y);
|
|
|
|
|
Object *o= sc->getObject();
|
|
|
|
|
bool isExplored = (sc->isExplored(thisTeamIndex) && o!=NULL);
|
2010-06-18 00:09:25 +02:00
|
|
|
|
//bool isVisible = (sc->isVisible(thisTeamIndex) && o!=NULL);
|
|
|
|
|
bool isVisible = true;
|
2010-06-16 09:18:06 +02:00
|
|
|
|
if(isExplored == true && isVisible == true) {
|
2010-06-15 18:27:52 +02:00
|
|
|
|
visibleObjectCount++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
str+= "Visible object count: " + intToStr(visibleObjectCount) +"\n";
|
|
|
|
|
|
2010-03-13 22:10:45 +01:00
|
|
|
|
// resources
|
2010-04-15 03:19:00 +02:00
|
|
|
|
for(int i=0; i<world.getFactionCount(); ++i){
|
|
|
|
|
str+= "Player "+intToStr(i)+" res: ";
|
|
|
|
|
for(int j=0; j<world.getTechTree()->getResourceTypeCount(); ++j){
|
|
|
|
|
str+= intToStr(world.getFaction(i)->getResource(j)->getAmount());
|
|
|
|
|
str+=" ";
|
|
|
|
|
}
|
|
|
|
|
str+="\n";
|
|
|
|
|
}
|
|
|
|
|
}
|
2010-03-13 22:10:45 +01:00
|
|
|
|
|
2010-06-16 09:18:06 +02:00
|
|
|
|
if(gui.getShowDebugUI() == true) {
|
2010-05-15 21:51:58 +02:00
|
|
|
|
renderer.renderText(str, coreData.getMenuFontNormal(),
|
|
|
|
|
Vec3f(1.0f), 10, 500, false);
|
2010-05-29 07:41:40 +02:00
|
|
|
|
|
2010-05-29 09:07:46 +02:00
|
|
|
|
if(renderer.getAllowRenderUnitTitles() == false) {
|
|
|
|
|
renderer.setAllowRenderUnitTitles(true);
|
|
|
|
|
}
|
2010-05-29 07:41:40 +02:00
|
|
|
|
renderer.renderUnitTitles(coreData.getMenuFontNormal(),Vec3f(1.0f));
|
2010-03-13 22:10:45 +01:00
|
|
|
|
}
|
2010-05-29 09:07:46 +02:00
|
|
|
|
else {
|
|
|
|
|
if(renderer.getAllowRenderUnitTitles() == true) {
|
|
|
|
|
renderer.setAllowRenderUnitTitles(false);
|
|
|
|
|
}
|
|
|
|
|
}
|
2010-03-13 22:10:45 +01:00
|
|
|
|
|
|
|
|
|
//network status
|
2010-05-15 21:51:58 +02:00
|
|
|
|
if(renderNetworkStatus) {
|
2010-03-13 22:10:45 +01:00
|
|
|
|
renderer.renderText(
|
|
|
|
|
NetworkManager::getInstance().getGameNetworkInterface()->getNetworkStatus(),
|
|
|
|
|
coreData.getMenuFontNormal(),
|
|
|
|
|
Vec3f(1.0f), 20, 500, false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//resource info
|
2010-06-16 09:18:06 +02:00
|
|
|
|
if(config.getBool("PhotoMode") == false) {
|
2010-03-13 22:10:45 +01:00
|
|
|
|
renderer.renderResourceStatus();
|
2010-04-14 22:49:14 +02:00
|
|
|
|
renderer.renderConsole(&console,showFullConsole);
|
2010-03-13 22:10:45 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//2d mouse
|
|
|
|
|
renderer.renderMouse2d(mouseX, mouseY, mouse2d, gui.isSelectingPos()? 1.f: 0.f);
|
2010-04-15 03:19:00 +02:00
|
|
|
|
|
|
|
|
|
if(difftime(time(NULL),lastRenderLog2d) >= 1) {
|
|
|
|
|
lastRenderLog2d = time(NULL);
|
|
|
|
|
SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d Statistics: %s\n",__FILE__,__FUNCTION__,__LINE__,str.c_str());
|
2010-04-27 05:36:36 +02:00
|
|
|
|
|
|
|
|
|
SystemFlags::OutputDebug(SystemFlags::debugWorldSynch,"In [%s::%s] Line: %d Statistics: %s\n",__FILE__,__FUNCTION__,__LINE__,str.c_str());
|
2010-04-15 03:19:00 +02:00
|
|
|
|
}
|
2010-03-13 22:10:45 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// ==================== misc ====================
|
|
|
|
|
|
|
|
|
|
void Game::checkWinner(){
|
|
|
|
|
if(!gameOver){
|
|
|
|
|
if(gameSettings.getDefaultVictoryConditions()){
|
|
|
|
|
checkWinnerStandard();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
checkWinnerScripted();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Game::checkWinnerStandard(){
|
|
|
|
|
//lose
|
|
|
|
|
bool lose= false;
|
2010-05-15 20:59:17 +02:00
|
|
|
|
if(hasBuilding(world.getThisFaction()) == false) {
|
2010-03-13 22:10:45 +01:00
|
|
|
|
lose= true;
|
2010-05-15 20:59:17 +02:00
|
|
|
|
for(int i=0; i<world.getFactionCount(); ++i) {
|
|
|
|
|
if(world.getFaction(i)->isAlly(world.getThisFaction()) == false) {
|
2010-03-13 22:10:45 +01:00
|
|
|
|
world.getStats()->setVictorious(i);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
gameOver= true;
|
2010-05-31 12:20:18 +02:00
|
|
|
|
if(this->gameSettings.getEnableObserverModeAtEndGame() == true) {
|
|
|
|
|
// Let the poor user watch everything unfold
|
|
|
|
|
world.setFogOfWar(false);
|
2010-06-12 20:27:39 +02:00
|
|
|
|
//gameCamera.setClampBounds(false);
|
|
|
|
|
Renderer::getInstance().setPhotoMode(true);
|
|
|
|
|
gameCamera.setMaxHeight(500);
|
2010-05-31 12:20:18 +02:00
|
|
|
|
// but don't let him cheat via teamchat
|
|
|
|
|
chatManager.setDisableTeamMode(true);
|
|
|
|
|
}
|
2010-03-13 22:10:45 +01:00
|
|
|
|
showLoseMessageBox();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//win
|
2010-05-15 20:59:17 +02:00
|
|
|
|
if(lose == false) {
|
2010-03-13 22:10:45 +01:00
|
|
|
|
bool win= true;
|
2010-05-15 20:59:17 +02:00
|
|
|
|
for(int i=0; i<world.getFactionCount(); ++i) {
|
2010-03-13 22:10:45 +01:00
|
|
|
|
if(i!=world.getThisFactionIndex()){
|
2010-05-15 20:59:17 +02:00
|
|
|
|
if(hasBuilding(world.getFaction(i)) && world.getFaction(i)->isAlly(world.getThisFaction()) == false) {
|
2010-03-13 22:10:45 +01:00
|
|
|
|
win= false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//if win
|
2010-05-15 20:59:17 +02:00
|
|
|
|
if(win) {
|
|
|
|
|
for(int i=0; i< world.getFactionCount(); ++i) {
|
|
|
|
|
if(world.getFaction(i)->isAlly(world.getThisFaction())) {
|
2010-03-13 22:10:45 +01:00
|
|
|
|
world.getStats()->setVictorious(i);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
gameOver= true;
|
2010-05-31 12:20:18 +02:00
|
|
|
|
if(this->gameSettings.getEnableObserverModeAtEndGame() == true) {
|
|
|
|
|
// Let the happy winner view everything left in the world
|
|
|
|
|
world.setFogOfWar(false);
|
2010-06-12 20:27:39 +02:00
|
|
|
|
//gameCamera.setClampBounds(false);
|
|
|
|
|
Renderer::getInstance().setPhotoMode(true);
|
|
|
|
|
gameCamera.setMaxHeight(500);
|
2010-05-31 12:20:18 +02:00
|
|
|
|
}
|
2010-05-15 20:59:17 +02:00
|
|
|
|
|
2010-03-13 22:10:45 +01:00
|
|
|
|
showWinMessageBox();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Game::checkWinnerScripted(){
|
|
|
|
|
if(scriptManager.getGameOver()){
|
|
|
|
|
gameOver= true;
|
|
|
|
|
for(int i= 0; i<world.getFactionCount(); ++i){
|
|
|
|
|
if(scriptManager.getPlayerModifiers(i)->getWinner()){
|
|
|
|
|
world.getStats()->setVictorious(i);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if(scriptManager.getPlayerModifiers(world.getThisFactionIndex())->getWinner()){
|
|
|
|
|
showWinMessageBox();
|
|
|
|
|
}
|
|
|
|
|
else{
|
|
|
|
|
showLoseMessageBox();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool Game::hasBuilding(const Faction *faction){
|
|
|
|
|
for(int i=0; i<faction->getUnitCount(); ++i){
|
|
|
|
|
if(faction->getUnit(i)->getType()->hasSkillClass(scBeBuilt)){
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Game::incSpeed(){
|
|
|
|
|
Lang &lang= Lang::getInstance();
|
|
|
|
|
switch(speed){
|
|
|
|
|
case sSlow:
|
|
|
|
|
speed= sNormal;
|
|
|
|
|
console.addLine(lang.get("GameSpeedSet")+" "+lang.get("Normal"));
|
|
|
|
|
break;
|
|
|
|
|
case sNormal:
|
|
|
|
|
speed= sFast;
|
|
|
|
|
console.addLine(lang.get("GameSpeedSet")+" "+lang.get("Fast"));
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Game::decSpeed(){
|
|
|
|
|
Lang &lang= Lang::getInstance();
|
|
|
|
|
switch(speed){
|
|
|
|
|
case sNormal:
|
|
|
|
|
speed= sSlow;
|
|
|
|
|
console.addLine(lang.get("GameSpeedSet")+" "+lang.get("Slow"));
|
|
|
|
|
break;
|
|
|
|
|
case sFast:
|
|
|
|
|
speed= sNormal;
|
|
|
|
|
console.addLine(lang.get("GameSpeedSet")+" "+lang.get("Normal"));
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int Game::getUpdateLoops(){
|
|
|
|
|
if(paused){
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
else if(speed==sFast){
|
|
|
|
|
return Config::getInstance().getInt("FastSpeedLoops");
|
|
|
|
|
}
|
|
|
|
|
else if(speed==sSlow){
|
|
|
|
|
return updateFps % 2 == 0? 1: 0;
|
|
|
|
|
}
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Game::showLoseMessageBox(){
|
|
|
|
|
Lang &lang= Lang::getInstance();
|
2010-05-15 20:59:17 +02:00
|
|
|
|
|
|
|
|
|
NetworkManager &networkManager= NetworkManager::getInstance();
|
|
|
|
|
if(networkManager.isNetworkGame() == true && networkManager.getNetworkRole() == nrServer) {
|
|
|
|
|
showMessageBox(lang.get("YouLose")+", "+lang.get("ExitGameServer?"), lang.get("BattleOver"), false);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
showMessageBox(lang.get("YouLose")+", "+lang.get("ExitGame?"), lang.get("BattleOver"), false);
|
|
|
|
|
}
|
2010-03-13 22:10:45 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Game::showWinMessageBox(){
|
|
|
|
|
Lang &lang= Lang::getInstance();
|
|
|
|
|
showMessageBox(lang.get("YouWin")+", "+lang.get("ExitGame?"), lang.get("BattleOver"), false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Game::showMessageBox(const string &text, const string &header, bool toggle){
|
|
|
|
|
if(!toggle){
|
|
|
|
|
mainMessageBox.setEnabled(false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(!mainMessageBox.getEnabled()){
|
|
|
|
|
mainMessageBox.setText(text);
|
|
|
|
|
mainMessageBox.setHeader(header);
|
|
|
|
|
mainMessageBox.setEnabled(true);
|
|
|
|
|
}
|
|
|
|
|
else{
|
|
|
|
|
mainMessageBox.setEnabled(false);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}}//end namespace
|