- added more debug statements to try to track beta bugs

- added safer customization of ini files
- added ability to customize game keys
- added more error checking for ogg file loading
- added faction loader progress
- added a few more thread protections on custom menu
This commit is contained in:
Mark Vejvoda 2010-06-12 18:27:39 +00:00
parent 25bc515466
commit 085d4e4bfe
25 changed files with 538 additions and 125 deletions

43
mk/linux/glestkeys.ini Normal file
View File

@ -0,0 +1,43 @@
; === propertyMap File ===
RenderNetworkStatus=N
ShowFullConsole=M
Screenshot=E
FreeCameraMode=F
ResetCameraMode=32
CameraModeLeft=vkLeft
CameraModeRight=vkRight
CameraModeUp=vkUp
CameraModeDown=vkDown
PauseGame=P
ChangeFontColor=C
GameSpeedIncrease=vkAdd
GameSpeedDecrease=vkSubtract
ExitKey=vkEscape
GroupUnitsKey1=0
GroupUnitsKey2=1
GroupUnitsKey3=2
GroupUnitsKey4=3
GroupUnitsKey5=4
GroupUnitsKey6=5
GroupUnitsKey7=6
GroupUnitsKey8=7
GroupUnitsKey9=8
GroupUnitsKey10=9
CameraRotateLeft=A
CameraRotateRight=D
CameraRotateUp=S
CameraRotateDown=W
HotKeyCenterCameraOnSelection=G
HotKeySelectIdleHarvesterUnit=I
HotKeySelectBuiltBuilding=B
HotKeyShowDebug=?
HotKeyDumpWorldToLog=|
HotKeyRotateUnitDuringPlacement=R
HotKeySelectDamagedUnit=D
HotKeySelectStoreUnit=T
HotKeySelectedUnitsAttack=A
HotKeySelectedUnitsStop=S
; === propertyMap File ===

3
mk/linux/glestuser.ini Normal file
View File

@ -0,0 +1,3 @@
; === propertyMap File ===

View File

@ -0,0 +1,3 @@
; === propertyMap File ===

View File

@ -26,7 +26,7 @@ using namespace Shared::Platform;
namespace Glest{ namespace Game{
const string mailString= "contact_game@glest.org";
const string glestVersionString= "v3.3.5-beta1";
const string glestVersionString= "v3.3.5-beta3";
string getCrashDumpFileName(){
return "glest" + glestVersionString + ".dmp";
@ -100,11 +100,11 @@ string getAboutString2(int i){
string getTeammateName(int i){
switch(i){
case 0: return "Marti<EFBFBD>o Figueroa";
case 1: return "Jos<EFBFBD> Luis Gonz<6E>lez";
case 2: return "Tucho Fern<EFBFBD>ndez";
case 3: return "Jos<EFBFBD> Zanni";
case 4: return "F<EFBFBD>lix Men<65>ndez";
case 0: return "Martiño Figueroa";
case 1: return "José Luis González";
case 2: return "Tucho Fernández";
case 3: return "José Zanni";
case 4: return "Félix Menéndez";
case 5: return "Marcos Caruncho";
case 6: return "Matthias Braun";
case 7: return "Titus Tscharntke";

View File

@ -162,6 +162,8 @@ void Game::load(){
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());
}
// give CPU time to update other things to avoid apperance of hanging
sleep(0);
if(loadingImageUsed == false){
// try to use a faction related loading screen
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] Searching for faction loading screen\n",__FILE__,__FUNCTION__);
@ -238,6 +240,9 @@ void Game::load(){
//tileset
world.loadTileset(config.getPathListForType(ptTilesets,scenarioDir), tilesetName, &checksum);
// give CPU time to update other things to avoid apperance of hanging
sleep(0);
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
set<string> factions;
@ -249,12 +254,18 @@ void Game::load(){
//tech, load before map because of resources
world.loadTech(config.getPathListForType(ptTechs,scenarioDir), techName, factions, &checksum);
// give CPU time to update other things to avoid apperance of hanging
sleep(0);
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
//map
world.loadMap(Map::getMapPath(mapName,scenarioDir), &checksum);
// give CPU time to update other things to avoid apperance of hanging
sleep(0);
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
//scenario
@ -263,6 +274,9 @@ void Game::load(){
world.loadScenario(gameSettings.getScenarioDir(), &checksum);
}
// give CPU time to update other things to avoid apperance of hanging
sleep(0);
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
//good_fpu_control_registers(NULL,__FILE__,__FUNCTION__,__LINE__);
}
@ -287,13 +301,29 @@ void Game::init()
//init world, and place camera
commander.init(&world);
// give CPU time to update other things to avoid apperance of hanging
sleep(0);
world.init(this, gameSettings.getDefaultUnits());
// give CPU time to update other things to avoid apperance of hanging
sleep(0);
gui.init(this);
// give CPU time to update other things to avoid apperance of hanging
sleep(0);
chatManager.init(&console, world.getThisTeamIndex());
console.clearStoredLines();
const Vec2i &v= map->getStartLocation(world.getThisFaction()->getStartLocationIndex());
gameCamera.init(map->getW(), map->getH());
gameCamera.setPos(Vec2f(v.x, v.y));
// give CPU time to update other things to avoid apperance of hanging
sleep(0);
scriptManager.init(&world, &gameCamera);
//good_fpu_control_registers(NULL,__FILE__,__FUNCTION__,__LINE__);
@ -313,6 +343,9 @@ void Game::init()
}
}
// give CPU time to update other things to avoid apperance of hanging
sleep(0);
//wheather particle systems
if(world.getTileset()->getWeather() == wRainy){
logger.add("Creating rain particle system", true);
@ -337,6 +370,9 @@ void Game::init()
//good_fpu_control_registers(NULL,__FILE__,__FUNCTION__,__LINE__);
// give CPU time to update other things to avoid apperance of hanging
sleep(0);
//sounds
SoundRenderer &soundRenderer= SoundRenderer::getInstance();
@ -359,10 +395,21 @@ void Game::init()
logger.add("Waiting for network players", true);
networkManager.getGameNetworkInterface()->waitUntilReady(&checksum);
std::string worldLog = world.DumpWorldToLog(true);
//std::string worldLog = world.DumpWorldToLog(true);
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] Starting music stream\n",__FILE__,__FUNCTION__);
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] Starting music stream\n",__FILE__,__FUNCTION__,__LINE__);
logger.add("Starting music stream", true);
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");
//}
StrSound *gameMusic= world.getThisFaction()->getType()->getMusic();
soundRenderer.playMusic(gameMusic);
@ -762,13 +809,15 @@ void Game::keyDown(char key){
if(!chatManager.getEditEnabled()){
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] key = %d\n",__FILE__,__FUNCTION__,__LINE__,key);
if(key=='N'){
Config &configKeys = Config::getInstance(std::pair<ConfigType,ConfigType>(cfgMainKeys,cfgUserKeys));
if(key == configKeys.getCharKey("RenderNetworkStatus")) {
renderNetworkStatus= true;
}
else if(key=='M'){
else if(key == configKeys.getCharKey("ShowFullConsole")) {
showFullConsole= true;
}
else if(key=='E'){
else if(key == configKeys.getCharKey("Screenshot")) {
for(int i=0; i<100; ++i){
string path= "screens/screen" + intToStr(i) + ".tga";
@ -782,40 +831,34 @@ void Game::keyDown(char key){
}
}
}
//move camera left
else if(key==vkLeft){
else if(key == configKeys.getCharKey("CameraModeLeft")) {
gameCamera.setMoveX(-1);
}
//move camera right
else if(key==vkRight){
else if(key == configKeys.getCharKey("CameraModeRight")) {
gameCamera.setMoveX(1);
}
//move camera up
else if(key==vkUp){
else if(key == configKeys.getCharKey("CameraModeUp")) {
gameCamera.setMoveZ(1);
}
//move camera down
else if(key==vkDown){
else if(key == configKeys.getCharKey("CameraModeDown")) {
gameCamera.setMoveZ(-1);
}
//change camera mode
else if(key=='F'){
else if(key == configKeys.getCharKey("FreeCameraMode")) {
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
else if(key==' '){
else if(key == configKeys.getCharKey("ResetCameraMode")) {
gameCamera.resetPosition();
}
//pause
else if(key=='P'){
else if(key == configKeys.getCharKey("PauseGame")) {
if(speedChangesAllowed){
if(paused){
console.addLine(lang.get("GameResumed"));
@ -828,34 +871,39 @@ void Game::keyDown(char key){
}
}
//switch display color
else if(key=='C'){
else if(key == configKeys.getCharKey("ChangeFontColor")) {
gui.switchToNextDisplayColor();
}
//increment speed
else if(key==vkAdd){
else if(key == configKeys.getCharKey("GameSpeedIncrease")) {
if(speedChangesAllowed){
incSpeed();
}
}
//decrement speed
else if(key==vkSubtract){
else if(key == configKeys.getCharKey("GameSpeedDecrease")) {
if(speedChangesAllowed){
decSpeed();
}
}
//exit
else if(key==vkEscape){
else if(key == configKeys.getCharKey("ExitKey")) {
showMessageBox(lang.get("ExitGame?"), "", true);
}
//group
else if(key>='0' && key<'0'+Selection::maxGroups){
//else if(key>='0' && key<'0'+Selection::maxGroups){
else {
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] key = %d\n",__FILE__,__FUNCTION__,__LINE__,key);
gui.groupKey(key-'0');
for(int idx = 1; idx <= Selection::maxGroups; idx++) {
string keyName = "GroupUnitsKey" + intToStr(idx);
if(key == configKeys.getCharKey(keyName.c_str())) {
//gui.groupKey(key-'0');
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] key = %d\n",__FILE__,__FUNCTION__,__LINE__,key);
gui.groupKey(idx-1);
break;
}
}
}
//hotkeys
@ -866,24 +914,21 @@ void Game::keyDown(char key){
gui.hotKey(key);
}
else{
else {
//rotate camera leftt
if(key=='A'){
if(key == configKeys.getCharKey("CameraRotateLeft")) {
gameCamera.setRotate(-1);
}
//rotate camera right
else if(key=='D'){
else if(key == configKeys.getCharKey("CameraRotateRight")){
gameCamera.setRotate(1);
}
//camera up
else if(key=='S'){
else if(key == configKeys.getCharKey("CameraRotateUp")) {
gameCamera.setMoveY(1);
}
//camera down
else if(key=='W'){
else if(key == configKeys.getCharKey("CameraRotateDown")) {
gameCamera.setMoveY(-1);
}
}
@ -1181,6 +1226,9 @@ void Game::checkWinnerStandard(){
if(this->gameSettings.getEnableObserverModeAtEndGame() == true) {
// Let the poor user watch everything unfold
world.setFogOfWar(false);
//gameCamera.setClampBounds(false);
Renderer::getInstance().setPhotoMode(true);
gameCamera.setMaxHeight(500);
// but don't let him cheat via teamchat
chatManager.setDisableTeamMode(true);
}
@ -1209,6 +1257,9 @@ void Game::checkWinnerStandard(){
if(this->gameSettings.getEnableObserverModeAtEndGame() == true) {
// Let the happy winner view everything left in the world
world.setFogOfWar(false);
//gameCamera.setClampBounds(false);
Renderer::getInstance().setPhotoMode(true);
gameCamera.setMaxHeight(500);
}
showWinMessageBox();

View File

@ -56,11 +56,11 @@ GameCamera::GameCamera() : pos(0.f, defaultHeight, 0.f),
move= Vec3f(0.f);
maxRenderDistance = Config::getInstance().getFloat("RenderDistanceMax","64");
//maxRenderDistance = Config::getInstance().getFloat("RenderDistanceMax","64");
maxHeight = Config::getInstance().getFloat("CameraMaxDistance","20");
minHeight = Config::getInstance().getFloat("CameraMinDistance","7");
maxCameraDist = maxHeight;
minCameraDist = minHeight;
//maxCameraDist = maxHeight;
//minCameraDist = minHeight;
minVAng = -Config::getInstance().getFloat("CameraMaxYaw","77.5");
maxVAng = -Config::getInstance().getFloat("CameraMinYaw","20");
fov = Config::getInstance().getFloat("CameraFov","45");

View File

@ -71,11 +71,11 @@ private:
//config
float speed;
bool clampBounds;
float maxRenderDistance;
//float maxRenderDistance;
float maxHeight;
float minHeight;
float maxCameraDist;
float minCameraDist;
//float maxCameraDist;
//float minCameraDist;
float minVAng;
float maxVAng;
float fov;
@ -122,6 +122,12 @@ public:
void load(const XmlNode *node);
void save(XmlNode *node) const;
bool setClampBounds(bool value) { clampBounds = value; }
bool setMaxHeight(float value) { maxHeight = value; }
bool setFov(float value) { fov = value; }
bool setMinVAng(float value) { minVAng = value; }
bool setMaxVAng(float value) { maxVAng = value; }
private:
void clampPosXYZ(float x1, float x2, float y1, float y2, float z1, float z2);
void clampPosXZ(float x1, float x2, float z1, float z2);

View File

@ -15,10 +15,17 @@
#include "game_constants.h"
#include "platform_util.h"
#include "game_util.h"
#include <map>
#include "conversion.h"
#include "window.h"
#include <stdexcept>
//#include <cstdio>
//#include <cstdlib>
#include "leak_dumper.h"
using namespace Shared::Platform;
using namespace Shared::Util;
using namespace std;
namespace Glest{ namespace Game{
@ -35,77 +42,236 @@ const char *GameConstants::folder_path_tutorials = "tutorials";
// class Config
// =====================================================
Config::Config(){
const string defaultNotFoundValue = "~~NOT FOUND~~";
string cfgFile = "glest.ini";
map<ConfigType,Config> Config::configList;
Config::Config(std::pair<ConfigType,ConfigType> type, std::pair<string,string> file, std::pair<bool,bool> fileMustExist) {
fileLoaded.first = false;
fileLoaded.second = false;
cfgType = type;
fileName = file;
if(getGameReadWritePath() != "") {
cfgFile = getGameReadWritePath() + cfgFile;
fileName.first = getGameReadWritePath() + fileName.first;
fileName.second = getGameReadWritePath() + fileName.second;
}
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] cfgFile = [%s]\n",__FILE__,__FUNCTION__,__LINE__,cfgFile.c_str());
properties.load(cfgFile);
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] cfgFile = [%s]\n",__FILE__,__FUNCTION__,__LINE__,cfgFile.c_str());
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] cfgFile.first = [%s]\n",__FILE__,__FUNCTION__,__LINE__,fileName.first.c_str());
if(fileMustExist.first == true ||
(fileMustExist.first == false && fileExists(fileName.first) == true)) {
properties.first.load(fileName.first);
fileLoaded.first = true;
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] cfgFile.first = [%s]\n",__FILE__,__FUNCTION__,__LINE__,fileName.first.c_str());
}
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] cfgFile.first = [%s]\n",__FILE__,__FUNCTION__,__LINE__,fileName.first.c_str());
if(properties.first.getString("UserOverrideFile", defaultNotFoundValue.c_str()) != defaultNotFoundValue) {
fileName.second = properties.first.getString("UserOverrideFile");
}
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] cfgFile.second = [%s]\n",__FILE__,__FUNCTION__,__LINE__,fileName.second.c_str());
if(fileMustExist.second == true ||
(fileMustExist.second == false && fileExists(fileName.second) == true)) {
properties.second.load(fileName.second);
fileLoaded.second = true;
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] cfgFile.second = [%s]\n",__FILE__,__FUNCTION__,__LINE__,fileName.second.c_str());
}
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] cfgFile.second = [%s]\n",__FILE__,__FUNCTION__,__LINE__,fileName.second.c_str());
}
Config &Config::getInstance(){
static Config config;
return config;
Config &Config::getInstance(std::pair<ConfigType,ConfigType> type, std::pair<string,string> file, std::pair<bool,bool> fileMustExist) {
if(configList.find(type.first) == configList.end()) {
Config config(type, file, fileMustExist);
configList.insert(map<ConfigType,Config>::value_type(type.first,config));
}
return configList.find(type.first)->second;
}
void Config::save(const string &path){
properties.save(path);
if(fileLoaded.second == true) {
if(path != "") {
fileName.second = path;
}
properties.second.save(fileName.second);
return;
}
if(path != "") {
fileName.first = path;
}
properties.first.save(fileName.first);
}
int Config::getInt(const char *key,const char *defaultValueIfNotFound) const {
return properties.getInt(key,defaultValueIfNotFound);
if(fileLoaded.second == true &&
properties.second.getString(key, defaultNotFoundValue.c_str()) != defaultNotFoundValue) {
return properties.second.getInt(key,defaultValueIfNotFound);
}
return properties.first.getInt(key,defaultValueIfNotFound);
}
bool Config::getBool(const char *key,const char *defaultValueIfNotFound) const {
return properties.getBool(key,defaultValueIfNotFound);
if(fileLoaded.second == true &&
properties.second.getString(key, defaultNotFoundValue.c_str()) != defaultNotFoundValue) {
return properties.second.getBool(key,defaultValueIfNotFound);
}
return properties.first.getBool(key,defaultValueIfNotFound);
}
float Config::getFloat(const char *key,const char *defaultValueIfNotFound) const {
return properties.getFloat(key,defaultValueIfNotFound);
if(fileLoaded.second == true &&
properties.second.getString(key, defaultNotFoundValue.c_str()) != defaultNotFoundValue) {
return properties.second.getFloat(key,defaultValueIfNotFound);
}
return properties.first.getFloat(key,defaultValueIfNotFound);
}
const string Config::getString(const char *key,const char *defaultValueIfNotFound) const {
return properties.getString(key,defaultValueIfNotFound);
if(fileLoaded.second == true &&
properties.second.getString(key, defaultNotFoundValue.c_str()) != defaultNotFoundValue) {
return properties.second.getString(key,defaultValueIfNotFound);
}
return properties.first.getString(key,defaultValueIfNotFound);
}
int Config::getInt(const string &key,const char *defaultValueIfNotFound) const{
return properties.getInt(key,defaultValueIfNotFound);
if(fileLoaded.second == true &&
properties.second.getString(key, defaultNotFoundValue.c_str()) != defaultNotFoundValue) {
return properties.second.getInt(key,defaultValueIfNotFound);
}
return properties.first.getInt(key,defaultValueIfNotFound);
}
bool Config::getBool(const string &key,const char *defaultValueIfNotFound) const{
return properties.getBool(key,defaultValueIfNotFound);
if(fileLoaded.second == true &&
properties.second.getString(key, defaultNotFoundValue.c_str()) != defaultNotFoundValue) {
return properties.second.getBool(key,defaultValueIfNotFound);
}
return properties.first.getBool(key,defaultValueIfNotFound);
}
float Config::getFloat(const string &key,const char *defaultValueIfNotFound) const{
return properties.getFloat(key,defaultValueIfNotFound);
if(fileLoaded.second == true &&
properties.second.getString(key, defaultNotFoundValue.c_str()) != defaultNotFoundValue) {
return properties.second.getFloat(key,defaultValueIfNotFound);
}
return properties.first.getFloat(key,defaultValueIfNotFound);
}
const string Config::getString(const string &key,const char *defaultValueIfNotFound) const{
return properties.getString(key,defaultValueIfNotFound);
if(fileLoaded.second == true &&
properties.second.getString(key, defaultNotFoundValue.c_str()) != defaultNotFoundValue) {
return properties.second.getString(key,defaultValueIfNotFound);
}
return properties.first.getString(key,defaultValueIfNotFound);
}
char Config::translateStringToCharKey(const string &value) const {
char result = 0;
if(IsNumeric(value.c_str()) == true) {
result = strToInt(value);
}
else if(value.substr(0,2) == "vk") {
if(value == "vkLeft") {
result = vkLeft;
}
else if(value == "vkRight") {
result = vkRight;
}
else if(value == "vkUp") {
result = vkUp;
}
else if(value == "vkDown") {
result = vkDown;
}
else if(value == "vkAdd") {
result = vkAdd;
}
else if(value == "vkSubtract") {
result = vkSubtract;
}
else if(value == "vkEscape") {
result = vkEscape;
}
else {
string sError = "Unsupported key translation" + value;
throw runtime_error(sError.c_str());
}
}
else if(value.length() >= 1) {
result = value[0];
}
else {
string sError = "Unsupported key translation" + value;
throw runtime_error(sError.c_str());
}
return result;
}
char Config::getCharKey(const char *key) const {
if(fileLoaded.second == true &&
properties.second.getString(key, defaultNotFoundValue.c_str()) != defaultNotFoundValue) {
string value = properties.second.getString(key);
return translateStringToCharKey(value);
}
string value = properties.first.getString(key);
return translateStringToCharKey(value);
}
void Config::setInt(const string &key, int value){
properties.setInt(key, value);
if(fileLoaded.second == true) {
properties.second.setInt(key, value);
return;
}
properties.first.setInt(key, value);
}
void Config::setBool(const string &key, bool value){
properties.setBool(key, value);
if(fileLoaded.second == true) {
properties.second.setBool(key, value);
return;
}
properties.first.setBool(key, value);
}
void Config::setFloat(const string &key, float value){
properties.setFloat(key, value);
if(fileLoaded.second == true) {
properties.second.setFloat(key, value);
return;
}
properties.first.setFloat(key, value);
}
void Config::setString(const string &key, const string &value){
properties.setString(key, value);
if(fileLoaded.second == true) {
properties.second.setString(key, value);
return;
}
properties.first.setString(key, value);
}
string Config::toString(){
return properties.toString();
return properties.first.toString();
}
vector<string> Config::getPathListForType(PathType type, string scenarioDir) {

View File

@ -1,7 +1,7 @@
// ==============================================================
// This file is part of Glest (www.glest.org)
//
// Copyright (C) 2001-2008 Martiño Figueroa
// Copyright (C) 2001-2008 Martio Figueroa
//
// You can redistribute this code and/or modify it under
// the terms of the GNU General Public License as published
@ -26,16 +26,38 @@ using Shared::Util::Properties;
// Game configuration
// =====================================================
class Config{
enum ConfigType {
cfgMainGame,
cfgUserGame,
cfgMainKeys,
cfgUserKeys
};
class Config {
private:
Properties properties;
//Properties properties;
//ConfigType cfgType;
//string fileName;
//bool fileLoaded;
std::pair<Properties,Properties> properties;
std::pair<ConfigType,ConfigType> cfgType;
std::pair<string,string> fileName;
std::pair<bool,bool> fileLoaded;
static map<ConfigType,Config> configList;
private:
Config();
Config(std::pair<ConfigType,ConfigType> type, std::pair<string,string> file, std::pair<bool,bool> fileMustExist);
char translateStringToCharKey(const string &value) const;
public:
static Config &getInstance();
void save(const string &path="glest.ini");
static Config &getInstance(std::pair<ConfigType,ConfigType> type = std::pair<ConfigType,ConfigType>(cfgMainGame,cfgUserGame),
std::pair<string,string> file = std::pair<string,string>("glest.ini","glestuser.ini"),
std::pair<bool,bool> fileMustExist = std::pair<bool,bool>(true,false));
void save(const string &path="");
int getInt(const string &key,const char *defaultValueIfNotFound=NULL) const;
bool getBool(const string &key,const char *defaultValueIfNotFound=NULL) const;
@ -46,6 +68,7 @@ public:
bool getBool(const char *key,const char *defaultValueIfNotFound=NULL) const;
float getFloat(const char *key,const char *defaultValueIfNotFound=NULL) const;
const string getString(const char *key,const char *defaultValueIfNotFound=NULL) const;
char getCharKey(const char *key) const;
void setInt(const string &key, int value);
void setBool(const string &key, bool value);

View File

@ -124,7 +124,8 @@ const float Renderer::magicCircleRadius= 1.f;
//perspective values
const float Renderer::perspFov= 60.f;
const float Renderer::perspNearPlane= 1.f;
const float Renderer::perspFarPlane= 50.f;
//const float Renderer::perspFarPlane= 50.f;
const float Renderer::perspFarPlane= 1000.f;
const float Renderer::ambFactor= 0.7f;
const Vec4f Renderer::fowColor= Vec4f(0.0f, 0.0f, 0.0f, 1.0f);
@ -133,7 +134,7 @@ const Vec4f Renderer::defDiffuseColor= Vec4f(1.f, 1.f, 1.f, 1.f);
const Vec4f Renderer::defAmbientColor= Vec4f(1.f * ambFactor, 1.f * ambFactor, 1.f * ambFactor, 1.f);
const Vec4f Renderer::defColor= Vec4f(1.f, 1.f, 1.f, 1.f);
const float Renderer::maxLightDist= 50.f;
const float Renderer::maxLightDist= 1000.f;
// ==================== constructor and destructor ====================

View File

@ -381,6 +381,8 @@ public:
void renderUnitTitles(Font2D *font, Vec3f color);
Vec3f computeScreenPosition(const Vec3f &worldPos);
bool setPhotoMode(bool value) { photoMode = value; }
private:
//private misc
float computeSunAngle(float time);

View File

@ -326,27 +326,28 @@ void Gui::groupKey(int groupIndex){
}
}
void Gui::hotKey(char key){
void Gui::hotKey(char key) {
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] key = [%c][%d]\n",__FILE__,__FUNCTION__,key,key);
if(key=='G'){
Config &configKeys = Config::getInstance(std::pair<ConfigType,ConfigType>(cfgMainKeys,cfgUserKeys));
if(key == configKeys.getCharKey("HotKeyCenterCameraOnSelection")) {
centerCameraOnSelection();
}
else if(key=='I'){
else if(key == configKeys.getCharKey("HotKeySelectIdleHarvesterUnit")) {
selectInterestingUnit(iutIdleHarvester);
}
else if(key=='B'){
else if(key == configKeys.getCharKey("HotKeySelectBuiltBuilding")) {
selectInterestingUnit(iutBuiltBuilding);
}
else if(key=='?') {
else if(key == configKeys.getCharKey("HotKeyShowDebug")) {
this->showDebugUI = !this->showDebugUI;
}
else if(key=='|') {
else if(key == configKeys.getCharKey("HotKeyDumpWorldToLog")) {
std::string worldLog = world->DumpWorldToLog();
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] worldLog dumped to [%s]\n",__FILE__,__FUNCTION__,__LINE__,worldLog.c_str());
}
else if(key=='R'){
else if(key == configKeys.getCharKey("HotKeyRotateUnitDuringPlacement")){
// Here the user triggers a unit rotation while placing a unit
if(allowRotateUnits == true && isPlacingBuilding()) {
if(getBuilding()->getRotationAllowed()){
@ -354,16 +355,16 @@ void Gui::hotKey(char key){
}
}
}
else if(key=='D'){
else if(key == configKeys.getCharKey("HotKeySelectDamagedUnit")) {
selectInterestingUnit(iutDamaged);
}
else if(key=='T'){
else if(key == configKeys.getCharKey("HotKeySelectStoreUnit")) {
selectInterestingUnit(iutStore);
}
else if(key=='A'){
else if(key == configKeys.getCharKey("HotKeySelectedUnitsAttack")) {
clickCommonCommand(ccAttack);
}
else if(key=='S'){
else if(key == configKeys.getCharKey("HotKeySelectedUnitsStop")) {
clickCommonCommand(ccStop);
}
}

View File

@ -352,6 +352,11 @@ int glestMain(int argc, char** argv){
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] Font::charCount = %d, Font::fontTypeName [%s] Shared::Platform::charSet = %d\n",__FILE__,__FUNCTION__,__LINE__,Font::charCount,Font::fontTypeName.c_str(),Shared::Platform::charSet);
Config &configKeys = Config::getInstance(
std::pair<ConfigType,ConfigType>(cfgMainKeys,cfgUserKeys),
std::pair<string,string>("glestkeys.ini","glestuserkeys.ini"),
std::pair<bool,bool>(true,false));
//showCursor(config.getBool("Windowed"));
showCursor(false);

View File

@ -1,7 +1,7 @@
// ==============================================================
// This file is part of Glest (www.glest.org)
//
// Copyright (C) 2001-2005 Marti<EFBFBD>o Figueroa
// Copyright (C) 2001-2005 Martiño Figueroa
//
// You can redistribute this code and/or modify it under
// the terms of the GNU General Public License as published

View File

@ -385,16 +385,6 @@ void MenuStateCustomGame::mouseClick(int x, int y, MouseButton mouseButton){
soundRenderer.playFx(coreData.getClickSoundA());
/*
if( listBoxPublishServer.getEditable() &&
listBoxPublishServer.getSelectedItemIndex() == 0) {
needToRepublishToMasterserver = true;
lastMasterserverPublishing = 0;
publishToMasterserver();
simpleTask();
}
*/
MutexSafeWrapper safeMutex(&masterServerThreadAccessor);
needToBroadcastServerSettings = false;
needToRepublishToMasterserver = false;
@ -448,8 +438,6 @@ void MenuStateCustomGame::mouseClick(int x, int y, MouseButton mouseButton){
needToRepublishToMasterserver = true;
lastMasterserverPublishing = 0;
//publishToMasterserver();
//simpleTask();
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
}
@ -1108,6 +1096,9 @@ void MenuStateCustomGame::simpleTask() {
MutexSafeWrapper safeMutex(&masterServerThreadAccessor);
bool republish = (needToRepublishToMasterserver == true && publishToServerInfo != "");
if(publishToMasterserverThread == NULL || publishToMasterserverThread->getQuitStatus() == true || publishToMasterserverThread->getRunningStatus() == false) {
return;
}
safeMutex.ReleaseLock(true);
if(republish == true) {
@ -1126,8 +1117,11 @@ void MenuStateCustomGame::simpleTask() {
//printf("the request is:\n%s\n",request.c_str());
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d] the request is:\n%s\n",__FILE__,__FUNCTION__,__LINE__,request.c_str());
if(publishToMasterserverThread == NULL || publishToMasterserverThread->getQuitStatus() == true || publishToMasterserverThread->getRunningStatus() == false) {
return;
}
std::string serverInfo = SystemFlags::getHTTP(request);
//printf("the result is:\n'%s'\n",serverInfo.c_str());
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d] the result is:\n'%s'\n",__FILE__,__FUNCTION__,__LINE__,serverInfo.c_str());
@ -1146,6 +1140,11 @@ void MenuStateCustomGame::simpleTask() {
safeMutex.Lock();
bool broadCastSettings = needToBroadcastServerSettings;
if(publishToMasterserverThread == NULL || publishToMasterserverThread->getQuitStatus() == true || publishToMasterserverThread->getRunningStatus() == false) {
return;
}
safeMutex.ReleaseLock(true);
if(broadCastSettings)
@ -1160,9 +1159,17 @@ void MenuStateCustomGame::simpleTask() {
if(serverInterface->hasClientConnection() == true) {
//printf("Sending game settings broadcast since we have at least 1 client connected'\n");
if(publishToMasterserverThread == NULL || publishToMasterserverThread->getQuitStatus() == true || publishToMasterserverThread->getRunningStatus() == false) {
return;
}
GameSettings gameSettings;
loadGameSettings(&gameSettings);
if(publishToMasterserverThread == NULL || publishToMasterserverThread->getQuitStatus() == true || publishToMasterserverThread->getRunningStatus() == false) {
return;
}
serverInterface->setGameSettings(&gameSettings);
serverInterface->broadcastGameSetup(&gameSettings);
}

View File

@ -42,6 +42,9 @@ ServerInterface::ServerInterface(){
gameHasBeenInitiated = false;
gameSettingsUpdateCount = 0;
enabledThreadedClientCommandBroadcast = Config::getInstance().getBool("EnableThreadedClientCommandBroadcast","false");
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] enabledThreadedClientCommandBroadcast = %d\n",__FILE__,__FUNCTION__,__LINE__,enabledThreadedClientCommandBroadcast);
for(int i= 0; i<GameConstants::maxPlayers; ++i){
slots[i]= NULL;
switchSetupRequests[i]= NULL;

View File

@ -96,26 +96,32 @@ void SoundRenderer::update(){
// ======================= Music ============================
void SoundRenderer::playMusic(StrSound *strSound){
strSound->setVolume(musicVolume);
strSound->restart();
if(soundPlayer != NULL) {
if(runThreadSafe == true) mutex.p();
soundPlayer->play(strSound);
if(runThreadSafe == true) mutex.v();
if(strSound != NULL) {
strSound->setVolume(musicVolume);
strSound->restart();
if(soundPlayer != NULL) {
if(runThreadSafe == true) mutex.p();
soundPlayer->play(strSound);
if(runThreadSafe == true) mutex.v();
}
}
}
void SoundRenderer::setMusicVolume(StrSound *strSound){
strSound->setVolume(musicVolume);
if(strSound != NULL) {
strSound->setVolume(musicVolume);
}
}
void SoundRenderer::stopMusic(StrSound *strSound){
if(soundPlayer != NULL) {
if(runThreadSafe == true) mutex.p();
soundPlayer->stop(strSound);
if(strSound->getNext() != NULL) {
soundPlayer->stop(strSound->getNext());
}
if(strSound != NULL) {
if(strSound->getNext() != NULL) {
soundPlayer->stop(strSound->getNext());
}
}
if(runThreadSafe == true) mutex.v();
}
}
@ -154,11 +160,13 @@ void SoundRenderer::playFx(StaticSound *staticSound){
// ======================= Ambient ============================
void SoundRenderer::playAmbient(StrSound *strSound){
strSound->setVolume(ambientVolume);
if(soundPlayer != NULL) {
if(runThreadSafe == true) mutex.p();
soundPlayer->play(strSound, ambientFade);
if(runThreadSafe == true) mutex.v();
if(strSound != NULL) {
strSound->setVolume(ambientVolume);
if(soundPlayer != NULL) {
if(runThreadSafe == true) mutex.p();
soundPlayer->play(strSound, ambientFade);
if(runThreadSafe == true) mutex.v();
}
}
}

View File

@ -1083,17 +1083,34 @@ void Unit::clearCommands(){
CommandResult Unit::checkCommand(Command *command) const{
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
if(command == NULL) {
char szBuf[1024]="";
sprintf(szBuf,"In [%s::%s Line: %d] ERROR: command == NULL\n",__FILE__,__FUNCTION__,__LINE__);
throw runtime_error(szBuf);
}
//if not operative or has not command type => fail
if(!isOperative() || command->getUnit()==this || !getType()->hasCommandType(command->getCommandType())){
return crFailUndefined;
}
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
//if pos is not inside the world (if comand has not a pos, pos is (0, 0) and is inside world
if(!map->isInside(command->getPos())){
return crFailUndefined;
}
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
//check produced
if(command->getCommandType() == NULL) {
char szBuf[1024]="";
sprintf(szBuf,"In [%s::%s Line: %d] ERROR: command->getCommandType() == NULL\n",__FILE__,__FUNCTION__,__LINE__);
throw runtime_error(szBuf);
}
const ProducibleType *produced= command->getCommandType()->getProduced();
if(produced!=NULL){
if(!faction->reqsOk(produced)){
@ -1104,9 +1121,18 @@ CommandResult Unit::checkCommand(Command *command) const{
}
}
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
//build command specific, check resources and requirements for building
if(command->getCommandType()->getClass()==ccBuild){
const UnitType *builtUnit= command->getUnitType();
if(builtUnit == NULL) {
char szBuf[1024]="";
sprintf(szBuf,"In [%s::%s Line: %d] ERROR: builtUnit == NULL\n",__FILE__,__FUNCTION__,__LINE__);
throw runtime_error(szBuf);
}
if(!faction->reqsOk(builtUnit)){
return crFailReqs;
}
@ -1118,11 +1144,20 @@ CommandResult Unit::checkCommand(Command *command) const{
//upgrade command specific, check that upgrade is not upgraded
else if(command->getCommandType()->getClass()==ccUpgrade){
const UpgradeCommandType *uct= static_cast<const UpgradeCommandType*>(command->getCommandType());
if(uct == NULL) {
char szBuf[1024]="";
sprintf(szBuf,"In [%s::%s Line: %d] ERROR: uct == NULL\n",__FILE__,__FUNCTION__,__LINE__);
throw runtime_error(szBuf);
}
if(faction->getUpgradeManager()->isUpgradingOrUpgraded(uct->getProducedUpgrade())){
return crFailUndefined;
}
}
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
return crSuccess;
}

View File

@ -66,6 +66,9 @@ void TechTree::load(const string &dir, set<string> &factions, Checksum* checksum
throw runtime_error("Error loading Resource Types: "+ dir + "\n" + e.what());
}
// give CPU time to update other things to avoid apperance of hanging
sleep(0);
//load tech tree xml info
try{
XmlTree xmlTree;
@ -85,6 +88,9 @@ void TechTree::load(const string &dir, set<string> &factions, Checksum* checksum
attackTypes[i].setId(i);
}
// give CPU time to update other things to avoid apperance of hanging
sleep(0);
//armor types
const XmlNode *armorTypesNode= techTreeNode->getChild("armor-types");
armorTypes.resize(armorTypesNode->getChildCount());
@ -109,6 +115,9 @@ void TechTree::load(const string &dir, set<string> &factions, Checksum* checksum
throw runtime_error("Error loading Tech Tree: "+ dir + "\n" + e.what());
}
// give CPU time to update other things to avoid apperance of hanging
sleep(0);
//load factions
str= dir+"/factions/*.";
try{
@ -116,8 +125,18 @@ void TechTree::load(const string &dir, set<string> &factions, Checksum* checksum
int i=0;
for ( set<string>::iterator it = factions.begin(); it != factions.end(); ++it ) {
char szBuf[1024]="";
sprintf(szBuf,"%s %s %d / %d",Lang::getInstance().get("Loading").c_str(),Lang::getInstance().get("Faction").c_str(),i+1,factions.size());
Logger &logger= Logger::getInstance();
logger.setState(szBuf);
str=dir+"/factions/" + *it;
factionTypes[i++].load(str, this, checksum);
// give CPU time to update other things to avoid apperance of hanging
sleep(0);
}
}
catch(const exception &e){

View File

@ -16,7 +16,7 @@
using std::string;
namespace Shared{ namespace Util{
namespace Shared { namespace Util {
bool strToBool(const string &s);
int strToInt(const string &s);
@ -32,6 +32,8 @@ string intToHex(int i);
string floatToStr(float f,int precsion=2);
string doubleToStr(double f,int precsion=2);
bool IsNumeric(const char *p, bool allowNegative=true);
}}//end namespace
#endif

View File

@ -93,11 +93,11 @@ void BaseThread::shutdownAndWait(BaseThread *pThread) {
if(pThread != NULL && pThread->getRunningStatus() == true) {
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
pThread->signalQuit();
for( time_t elapsed = time(NULL); difftime(time(NULL),elapsed) <= 10; ) {
for( time_t elapsed = time(NULL); difftime(time(NULL),elapsed) <= 7; ) {
if(pThread->getRunningStatus() == false) {
break;
}
sleep(10);
sleep(0);
//SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
}
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);

View File

@ -108,6 +108,7 @@ void createGlFontBitmaps(uint32 &base, const string &type, int size, int width,
XFontStruct* fontInfo = XLoadQueryFont(display, type.c_str());
if(!fontInfo) {
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] CANNOT load font %s, falling back to default\n",__FILE__,__FUNCTION__,__LINE__,type.c_str());
fontInfo = XLoadQueryFont(display, "fixed");
if(!fontInfo) {
throw std::runtime_error("Font not found: " + type);

View File

@ -543,6 +543,8 @@ char Window::getKey(SDL_keysym keysym) {
return '8';
case SDLK_9:
return '9';
case SDLK_QUESTION:
return '?';
case SDLK_a:
return 'A';
case SDLK_b:

View File

@ -15,10 +15,12 @@
#include <vorbis/vorbisfile.h>
#include "sound.h"
#include "util.h"
#include "leak_dumper.h"
using namespace Shared::Platform;
using namespace std;
using namespace Shared::Util;
namespace Shared{ namespace Sound{
@ -146,14 +148,31 @@ void OggSoundFileLoader::open(const string &path, SoundInfo *soundInfo){
}
vf= new OggVorbis_File();
if(vf==NULL) {
throw runtime_error("Can't create ogg object for file: "+path);
}
ov_open(f, vf, NULL, 0);
vorbis_info *vi= ov_info(vf, -1);
if(vi==NULL) {
throw runtime_error("Can't read ogg header info for file: "+path);
}
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] path = [%s] vi->version = %d, vi->channels = %d, vi->rate = %d, vi->bitrate_upper = %d, vi->bitrate_nominal = %d, vi->bitrate_lower = %d, vi->bitrate_window = %d\n",__FILE__,__FUNCTION__,__LINE__,path.c_str(),vi->version,vi->channels,vi->rate,vi->bitrate_upper,vi->bitrate_nominal,vi->bitrate_lower,vi->bitrate_window);
soundInfo->setChannels(vi->channels);
soundInfo->setsamplesPerSecond(vi->rate);
soundInfo->setBitsPerSample(16);
soundInfo->setSize(static_cast<uint32>(ov_pcm_total(vf, -1))*2);
uint32 samples = static_cast<uint32>(ov_pcm_total(vf, -1));
//if(vi->channels == 1) {
soundInfo->setSize(samples * 2);
//}
//else {
// soundInfo->setSize(samples * 4);
//}
}
uint32 OggSoundFileLoader::read(int8 *samples, uint32 size){

View File

@ -128,5 +128,18 @@ string doubleToStr(double d,int precsion){
return str;
}
bool IsNumeric(const char *p, bool allowNegative)
{
int index = 0;
for ( ; *p; p++) {
if (*p < '0' || *p > '9') {
if(allowNegative == false || (*p != '-' && index == 0)) {
return false;
}
}
index++;
}
return true;
}
}}//end namespace