global:reformat source

indent -i2 -nut -bl -bli0 -ppi3 -nce -npsl
This commit is contained in:
andy5995
2018-02-19 07:41:13 -06:00
parent a6a02af157
commit 7f44a83c87
8 changed files with 4648 additions and 3225 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -21,22 +21,25 @@
// along with this program. If not, see <https://www.gnu.org/licenses/> // along with this program. If not, see <https://www.gnu.org/licenses/>
#ifndef _GLEST_GAME_CONFIG_H_ #ifndef _GLEST_GAME_CONFIG_H_
#define _GLEST_GAME_CONFIG_H_ # define _GLEST_GAME_CONFIG_H_
#ifdef WIN32 # ifdef WIN32
#include <winsock2.h> # include <winsock2.h>
#include <winsock.h> # include <winsock.h>
#endif # endif
#include "properties.h" # include "properties.h"
#include <vector> # include <vector>
#include "game_constants.h" # include "game_constants.h"
#include <SDL.h> # include <SDL.h>
#include "leak_dumper.h" # include "leak_dumper.h"
namespace Glest{ namespace Game{ namespace Glest
{
namespace Game
{
using Shared::Util::Properties; using Shared::Util::Properties;
// ===================================================== // =====================================================
// class Config // class Config
@@ -44,34 +47,36 @@ using Shared::Util::Properties;
// Game configuration // Game configuration
// ===================================================== // =====================================================
enum ConfigType { enum ConfigType
{
cfgMainGame, cfgMainGame,
cfgUserGame, cfgUserGame,
cfgTempGame, cfgTempGame,
cfgMainKeys, cfgMainKeys,
cfgUserKeys, cfgUserKeys,
cfgTempKeys cfgTempKeys
}; };
class Config { class Config
private: {
private:
std::pair<Properties,Properties> properties; std::pair < Properties, Properties > properties;
Properties tempProperties; Properties tempProperties;
std::pair<ConfigType,ConfigType> cfgType; std::pair < ConfigType, ConfigType > cfgType;
std::pair<string,string> fileNameParameter; std::pair < string, string > fileNameParameter;
std::pair<string,string> fileName; std::pair < string, string > fileName;
std::pair<bool,bool> fileLoaded; std::pair < bool, bool > fileLoaded;
string custom_path_parameter; string custom_path_parameter;
static map<ConfigType,Config> configList; static map < ConfigType, Config > configList;
static const char *glest_ini_filename; static const char *glest_ini_filename;
static const char *glestuser_ini_filename; static const char *glestuser_ini_filename;
static map<string,string> customRuntimeProperties; static map < string, string > customRuntimeProperties;
public: public:
static const char *glestkeys_ini_filename; static const char *glestkeys_ini_filename;
static const char *glestuserkeys_ini_filename; static const char *glestuserkeys_ini_filename;
@@ -82,61 +87,95 @@ public:
static const char *selectBufPicking; static const char *selectBufPicking;
static const char *frustumPicking; static const char *frustumPicking;
protected: protected:
Config(); Config ();
Config(std::pair<ConfigType,ConfigType> type, std::pair<string,string> file, std::pair<bool,bool> fileMustExist,string custom_path=""); Config (std::pair < ConfigType, ConfigType > type, std::pair < string,
bool tryCustomPath(std::pair<ConfigType,ConfigType> &type, std::pair<string,string> &file, string custom_path); string > file, std::pair < bool, bool > fileMustExist,
static void CopyAll(Config *src,Config *dest); string custom_path = "");
vector<pair<string,string> > getPropertiesFromContainer(const Properties &propertiesObj) const; bool tryCustomPath (std::pair < ConfigType, ConfigType > &type,
static bool replaceFileWithLocalFile(const vector<string> &dirList, string fileNamePart, string &resultToReplace); std::pair < string, string > &file,
string custom_path);
static void CopyAll (Config * src, Config * dest);
vector < pair < string,
string >
>getPropertiesFromContainer (const Properties & propertiesObj) const;
static bool replaceFileWithLocalFile (const vector < string > &dirList,
string fileNamePart,
string & resultToReplace);
public: public:
static Config &getInstance(std::pair<ConfigType,ConfigType> type = std::make_pair(cfgMainGame,cfgUserGame) , static Config & getInstance (std::pair < ConfigType, ConfigType > type =
std::pair<string,string> file = std::make_pair(glest_ini_filename,glestuser_ini_filename) , std::make_pair (cfgMainGame, cfgUserGame),
std::pair<bool,bool> fileMustExist = std::make_pair(true,false),string custom_path="" ); std::pair < string, string > file =
void save(const string &path=""); std::make_pair (glest_ini_filename,
void reload(); glestuser_ini_filename),
std::pair < bool, bool > fileMustExist =
std::make_pair (true, false),
string custom_path = "");
void save (const string & path = "");
void reload ();
int getInt(const string &key,const char *defaultValueIfNotFound=NULL) const; int getInt (const string & key, const char *defaultValueIfNotFound =
bool getBool(const string &key,const char *defaultValueIfNotFound=NULL) const; NULL) const;
float getFloat(const string &key,const char *defaultValueIfNotFound=NULL) const; bool getBool (const string & key, const char *defaultValueIfNotFound =
const string getString(const string &key,const char *defaultValueIfNotFound=NULL) const; NULL) const;
float getFloat (const string & key, const char *defaultValueIfNotFound =
NULL) const;
const string getString (const string & key,
const char *defaultValueIfNotFound =
NULL) const;
int getInt(const char *key,const char *defaultValueIfNotFound=NULL) const; int getInt (const char *key, const char *defaultValueIfNotFound =
bool getBool(const char *key,const char *defaultValueIfNotFound=NULL) const; NULL) const;
float getFloat(const char *key,const char *defaultValueIfNotFound=NULL) const; bool getBool (const char *key, const char *defaultValueIfNotFound =
const string getString(const char *key,const char *defaultValueIfNotFound=NULL) const; 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; //char getCharKey(const char *key) const;
SDL_Keycode getSDLKey(const char *key) const; SDL_Keycode getSDLKey (const char *key) const;
void setInt(const string &key, int value, bool tempBuffer=false); void setInt (const string & key, int value, bool tempBuffer = false);
void setBool(const string &key, bool value, bool tempBuffer=false); void setBool (const string & key, bool value, bool tempBuffer = false);
void setFloat(const string &key, float value, bool tempBuffer=false); void setFloat (const string & key, float value, bool tempBuffer =
void setString(const string &key, const string &value, bool tempBuffer=false); false);
void setString (const string & key, const string & value,
bool tempBuffer = false);
vector<string> getPathListForType(PathType type, string scenarioDir = ""); vector < string > getPathListForType (PathType type,
string scenarioDir = "");
vector<pair<string,string> > getMergedProperties() const; vector < pair < string, string > >getMergedProperties () const;
vector<pair<string,string> > getMasterProperties() const; vector < pair < string, string > >getMasterProperties () const;
vector<pair<string,string> > getUserProperties() const; vector < pair < string, string > >getUserProperties () const;
void setUserProperties(const vector<pair<string,string> > &valueList); void setUserProperties (const vector < pair < string,
string > >&valueList);
string getFileName(bool userFilename) const; string getFileName (bool userFilename) const;
SDL_Keycode translateStringToSDLKey(const string &value) const; SDL_Keycode translateStringToSDLKey (const string & value) const;
string toString(); string toString ();
static string getCustomRuntimeProperty(string key) { return customRuntimeProperties[key]; } static string getCustomRuntimeProperty (string key)
static void setCustomRuntimeProperty(string key, string value) { customRuntimeProperties[key] = value; } {
return customRuntimeProperties[key];
}
static void setCustomRuntimeProperty (string key, string value)
{
customRuntimeProperties[key] = value;
}
static string findValidLocalFileFromPath(string fileName); static string findValidLocalFileFromPath (string fileName);
static string getMapPath(const string &mapName, string scenarioDir="", bool errorOnNotFound=true); static string getMapPath (const string & mapName, string scenarioDir =
}; "", bool errorOnNotFound = true);
};
}}//end namespace }} //end namespace
#endif #endif

File diff suppressed because it is too large Load Diff

View File

@@ -19,30 +19,33 @@
// along with this program. If not, see <https://www.gnu.org/licenses/>. // along with this program. If not, see <https://www.gnu.org/licenses/>.
#ifndef _GLEST_GAME_COREDATA_H_ #ifndef _GLEST_GAME_COREDATA_H_
#define _GLEST_GAME_COREDATA_H_ # define _GLEST_GAME_COREDATA_H_
#ifdef WIN32 # ifdef WIN32
#include <winsock2.h> # include <winsock2.h>
#include <winsock.h> # include <winsock.h>
#endif # endif
#include <string> # include <string>
#include "sound.h" # include "sound.h"
#include "font.h" # include "font.h"
#include "texture.h" # include "texture.h"
#include "sound_container.h" # include "sound_container.h"
#include "leak_dumper.h" # include "leak_dumper.h"
namespace Glest{ namespace Game{ namespace Glest
{
namespace Game
{
using ::Shared::Graphics::Texture2D; using::Shared::Graphics::Texture2D;
using ::Shared::Graphics::Texture3D; using::Shared::Graphics::Texture3D;
using ::Shared::Graphics::Font; using::Shared::Graphics::Font;
using ::Shared::Graphics::Font2D; using::Shared::Graphics::Font2D;
using ::Shared::Graphics::Font3D; using::Shared::Graphics::Font3D;
using ::Shared::Graphics::FontChangedCallbackInterface; using::Shared::Graphics::FontChangedCallbackInterface;
using ::Shared::Sound::StrSound; using::Shared::Sound::StrSound;
using ::Shared::Sound::StaticSound; using::Shared::Sound::StaticSound;
// ===================================================== // =====================================================
@@ -51,11 +54,12 @@ using ::Shared::Sound::StaticSound;
/// Data shared among all the ProgramStates /// Data shared among all the ProgramStates
// ===================================================== // =====================================================
class GameSettings; class GameSettings;
class CoreData { class CoreData
private: {
std::map<int,bool> itemLoadAttempted; private:
std::map < int, bool > itemLoadAttempted;
StrSound introMusic; StrSound introMusic;
StrSound menuMusic; StrSound menuMusic;
@@ -68,7 +72,7 @@ private:
SoundContainer waterSounds; SoundContainer waterSounds;
Texture2D *logoTexture; Texture2D *logoTexture;
std::vector<Texture2D *> logoTextureList; std::vector < Texture2D * >logoTextureList;
Texture2D *backgroundTexture; Texture2D *backgroundTexture;
Texture2D *fireTexture; Texture2D *fireTexture;
Texture2D *teamColorTexture; Texture2D *teamColorTexture;
@@ -93,7 +97,7 @@ private:
Texture2D *healthbarTexture; Texture2D *healthbarTexture;
Texture2D *healthbarBackgroundTexture; Texture2D *healthbarBackgroundTexture;
std::vector<Texture2D *> miscTextureList; std::vector < Texture2D * >miscTextureList;
Font2D *displayFont; Font2D *displayFont;
Font2D *menuFontNormal; Font2D *menuFontNormal;
@@ -123,10 +127,13 @@ private:
string battleEndLoseVideoFilenameFallback; string battleEndLoseVideoFilenameFallback;
string battleEndLoseMusicFilename; string battleEndLoseMusicFilename;
std::map<std::string,std::vector<FontChangedCallbackInterface *> > registeredFontChangedCallbacks; std::map < std::string,
public: std::vector <
FontChangedCallbackInterface * >>registeredFontChangedCallbacks;
public:
enum TextureSystemType { enum TextureSystemType
{
tsyst_NONE, tsyst_NONE,
tsyst_logoTexture, tsyst_logoTexture,
tsyst_backgroundTexture, tsyst_backgroundTexture,
@@ -155,126 +162,198 @@ public:
tsyst_COUNT tsyst_COUNT
}; };
public: public:
~CoreData(); ~CoreData ();
static CoreData &getInstance(); static CoreData & getInstance ();
void load(); void load ();
void cleanup(); void cleanup ();
void loadFonts(); void loadFonts ();
// Textures // Textures
Texture2D *getTextureBySystemId(TextureSystemType type); Texture2D *getTextureBySystemId (TextureSystemType type);
Texture2D *getBackgroundTexture(); Texture2D *getBackgroundTexture ();
Texture2D *getFireTexture(); Texture2D *getFireTexture ();
Texture2D *getTeamColorTexture(); Texture2D *getTeamColorTexture ();
Texture2D *getSnowTexture(); Texture2D *getSnowTexture ();
Texture2D *getLogoTexture(); Texture2D *getLogoTexture ();
Texture2D *getWaterSplashTexture(); Texture2D *getWaterSplashTexture ();
Texture2D *getCustomTexture(); Texture2D *getCustomTexture ();
Texture2D *getButtonSmallTexture(); Texture2D *getButtonSmallTexture ();
Texture2D *getButtonBigTexture(); Texture2D *getButtonBigTexture ();
Texture2D *getHorizontalLineTexture(); Texture2D *getHorizontalLineTexture ();
Texture2D *getVerticalLineTexture(); Texture2D *getVerticalLineTexture ();
Texture2D *getCheckBoxTexture(); Texture2D *getCheckBoxTexture ();
Texture2D *getCheckedCheckBoxTexture(); Texture2D *getCheckedCheckBoxTexture ();
Texture2D *getNotOnServerTexture(); Texture2D *getNotOnServerTexture ();
Texture2D *getOnServerDifferentTexture(); Texture2D *getOnServerDifferentTexture ();
Texture2D *getOnServerTexture(); Texture2D *getOnServerTexture ();
Texture2D *getOnServerInstalledTexture(); Texture2D *getOnServerInstalledTexture ();
Texture2D *getStatusReadyTexture(); Texture2D *getStatusReadyTexture ();
Texture2D *getStatusNotReadyTexture(); Texture2D *getStatusNotReadyTexture ();
Texture2D *getStatusBRBTexture(); Texture2D *getStatusBRBTexture ();
Texture2D *getGameWinnerTexture(); Texture2D *getGameWinnerTexture ();
Texture2D *getHealthbarTexture(); Texture2D *getHealthbarTexture ();
Texture2D *getHealthbarBackgroundTexture(); Texture2D *getHealthbarBackgroundTexture ();
size_t getLogoTextureExtraCount(); size_t getLogoTextureExtraCount ();
Texture2D *getLogoTextureExtra(int idx); Texture2D *getLogoTextureExtra (int idx);
std::vector<Texture2D *> & getMiscTextureList(); std::vector < Texture2D * >&getMiscTextureList ();
// Sounds and Music // Sounds and Music
StrSound *getIntroMusic(); StrSound *getIntroMusic ();
StrSound *getMenuMusic(); StrSound *getMenuMusic ();
StaticSound *getClickSoundA(); StaticSound *getClickSoundA ();
StaticSound *getClickSoundB(); StaticSound *getClickSoundB ();
StaticSound *getClickSoundC(); StaticSound *getClickSoundC ();
StaticSound *getAttentionSound(); StaticSound *getAttentionSound ();
StaticSound *getHighlightSound(); StaticSound *getHighlightSound ();
StaticSound *getMarkerSound(); StaticSound *getMarkerSound ();
StaticSound *getWaterSound(); StaticSound *getWaterSound ();
// Fonts // Fonts
Font2D *getDisplayFont() const {return displayFont;} Font2D *getDisplayFont () const
Font2D *getDisplayFontSmall() const {return displayFontSmall;} {
Font2D *getMenuFontNormal() const {return menuFontNormal;} return displayFont;
Font2D *getMenuFontBig() const {return menuFontBig;} }
Font2D *getMenuFontVeryBig() const {return menuFontVeryBig;} Font2D *getDisplayFontSmall () const
Font2D *getConsoleFont() const {return consoleFont;} {
return displayFontSmall;
}
Font2D *getMenuFontNormal () const
{
return menuFontNormal;
}
Font2D *getMenuFontBig () const
{
return menuFontBig;
}
Font2D *getMenuFontVeryBig () const
{
return menuFontVeryBig;
}
Font2D *getConsoleFont () const
{
return consoleFont;
}
Font3D *getDisplayFont3D() const {return displayFont3D;} Font3D *getDisplayFont3D () const
Font3D *getDisplayFontSmall3D() const {return displayFontSmall3D;} {
Font3D *getMenuFontNormal3D() const {return menuFontNormal3D;} return displayFont3D;
Font3D *getMenuFontBig3D() const {return menuFontBig3D;} }
Font3D *getMenuFontVeryBig3D() const {return menuFontVeryBig3D;} Font3D *getDisplayFontSmall3D () const
Font3D *getConsoleFont3D() const {return consoleFont3D;} {
return displayFontSmall3D;
}
Font3D *getMenuFontNormal3D () const
{
return menuFontNormal3D;
}
Font3D *getMenuFontBig3D () const
{
return menuFontBig3D;
}
Font3D *getMenuFontVeryBig3D () const
{
return menuFontVeryBig3D;
}
Font3D *getConsoleFont3D () const
{
return consoleFont3D;
}
// Helper functions // Helper functions
string getMainMenuVideoFilename() const { return mainMenuVideoFilename; } string getMainMenuVideoFilename () const
bool hasMainMenuVideoFilename() const; {
string getMainMenuVideoFilenameFallback() const { return mainMenuVideoFilenameFallback; } return mainMenuVideoFilename;
bool hasMainMenuVideoFilenameFallback() const; }
bool hasMainMenuVideoFilename () const;
string getMainMenuVideoFilenameFallback () const
{
return mainMenuVideoFilenameFallback;
}
bool hasMainMenuVideoFilenameFallback () const;
string getIntroVideoFilename() const { return introVideoFilename; } string getIntroVideoFilename () const
bool hasIntroVideoFilename() const; {
string getIntroVideoFilenameFallback() const { return introVideoFilenameFallback; } return introVideoFilename;
bool hasIntroVideoFilenameFallback() const; }
bool hasIntroVideoFilename () const;
string getIntroVideoFilenameFallback () const
{
return introVideoFilenameFallback;
}
bool hasIntroVideoFilenameFallback () const;
string getBattleEndVideoFilename(bool won) const { return won == true ? battleEndWinVideoFilename : battleEndLoseVideoFilename; } string getBattleEndVideoFilename (bool won) const
{
return won ==
true ? battleEndWinVideoFilename : battleEndLoseVideoFilename;
}
//bool hasBattleEndVideoFilename(bool won) const; //bool hasBattleEndVideoFilename(bool won) const;
string getBattleEndVideoFilenameFallback(bool won) const { return won == true ? battleEndWinVideoFilenameFallback : battleEndLoseVideoFilenameFallback; } string getBattleEndVideoFilenameFallback (bool won) const
bool hasBattleEndVideoFilenameFallback(bool won) const; {
return won ==
true ? battleEndWinVideoFilenameFallback :
battleEndLoseVideoFilenameFallback;
}
bool hasBattleEndVideoFilenameFallback (bool won) const;
string getBattleEndMusicFilename(bool won) const { return won == true ? battleEndWinMusicFilename : battleEndLoseMusicFilename; } string getBattleEndMusicFilename (bool won) const
{
return won ==
true ? battleEndWinMusicFilename : battleEndLoseMusicFilename;
}
void saveGameSettingsToFile(std::string fileName, GameSettings *gameSettings,int advancedIndex=0); void saveGameSettingsToFile (std::string fileName,
bool loadGameSettingsFromFile(std::string fileName, GameSettings *gameSettings); GameSettings * gameSettings,
int advancedIndex = 0);
bool loadGameSettingsFromFile (std::string fileName,
GameSettings * gameSettings);
void registerFontChangedCallback(std::string entityName, FontChangedCallbackInterface *cb); void registerFontChangedCallback (std::string entityName,
void unRegisterFontChangedCallback(std::string entityName); FontChangedCallbackInterface * cb);
private: void unRegisterFontChangedCallback (std::string entityName);
private:
CoreData(); CoreData ();
int computeFontSize(int size); int computeFontSize (int size);
void cleanupTexture(Texture2D **texture); void cleanupTexture (Texture2D ** texture);
void loadTextures(string data_path); void loadTextures (string data_path);
void loadSounds(string data_path); void loadSounds (string data_path);
void loadMusic(string data_path); void loadMusic (string data_path);
void loadIntroMedia(string data_path); void loadIntroMedia (string data_path);
void loadMainMenuMedia(string data_path); void loadMainMenuMedia (string data_path);
void loadBattleEndMedia(string data_path); void loadBattleEndMedia (string data_path);
string getDataPath(); string getDataPath ();
void loadTextureIfRequired(Texture2D **tex,string data_path, void loadTextureIfRequired (Texture2D ** tex, string data_path,
string uniqueFilePath, int texSystemId, bool setMipMap, string uniqueFilePath, int texSystemId,
bool setAlpha, bool loadUniqueFilePath, bool setMipMap, bool setAlpha,
bool loadUniqueFilePath,
bool compressionDisabled = false); bool compressionDisabled = false);
void loadLogoTextureExtraIfRequired(); void loadLogoTextureExtraIfRequired ();
void loadMiscTextureListIfRequired(); void loadMiscTextureListIfRequired ();
void loadWaterSoundsIfRequired(); void loadWaterSoundsIfRequired ();
void loadMusicIfRequired(); void loadMusicIfRequired ();
void triggerFontChangedCallbacks(std::string fontUniqueId, Font *font); void triggerFontChangedCallbacks (std::string fontUniqueId,
template<typename T> T * loadFont(Font *menuFontNormal, string menuFontNameNormal, int menuFontNameNormalSize, string fontType, string fontTypeFamily, string fontUniqueKey); Font * font);
}; template < typename T > T * loadFont (Font * menuFontNormal,
string menuFontNameNormal,
int menuFontNameNormalSize,
string fontType,
string fontTypeFamily,
string fontUniqueKey);
};
}} //end namespace }} //end namespace

File diff suppressed because it is too large Load Diff

View File

@@ -10,19 +10,22 @@
// ============================================================== // ==============================================================
#ifndef _GLEST_GAME_LANG_H_ #ifndef _GLEST_GAME_LANG_H_
#define _GLEST_GAME_LANG_H_ # define _GLEST_GAME_LANG_H_
#ifdef WIN32 # ifdef WIN32
#include <winsock2.h> # include <winsock2.h>
#include <winsock.h> # include <winsock.h>
#endif # endif
#include "properties.h" # include "properties.h"
#include "leak_dumper.h" # include "leak_dumper.h"
namespace Glest{ namespace Game{ namespace Glest
{
namespace Game
{
using Shared::Util::Properties; using Shared::Util::Properties;
// ===================================================== // =====================================================
// class Lang // class Lang
@@ -30,62 +33,88 @@ using Shared::Util::Properties;
// String table // String table
// ===================================================== // =====================================================
class Lang { class Lang
private: {
private:
bool is_utf8_language; bool is_utf8_language;
string language; string language;
std::map<string,Properties> gameStringsAllLanguages; std::map < string, Properties > gameStringsAllLanguages;
Properties scenarioStrings; Properties scenarioStrings;
Properties tilesetStrings; Properties tilesetStrings;
Properties tilesetStringsDefault; Properties tilesetStringsDefault;
std::map<string, std::map<string, Properties> > techTreeStringsAllLanguages; std::map < string, std::map < string,
Properties > >techTreeStringsAllLanguages;
string techNameLoaded; string techNameLoaded;
bool allowNativeLanguageTechtree; bool allowNativeLanguageTechtree;
private: private:
Lang(); Lang ();
void loadGameStringProperties(string language, Properties &properties, bool fileMustExist,bool fallbackToDefault=false); void loadGameStringProperties (string language, Properties & properties,
bool fileMatchesISO630Code(string uselanguage, string testLanguageFile); bool fileMustExist,
string getNativeLanguageName(string uselanguage, string testLanguageFile); bool fallbackToDefault = false);
bool fileMatchesISO630Code (string uselanguage,
string testLanguageFile);
string getNativeLanguageName (string uselanguage,
string testLanguageFile);
string parseResult(const string &key, const string &value); string parseResult (const string & key, const string & value);
public: public:
static Lang &getInstance(); static Lang & getInstance ();
string getTechNameLoaded() const { return techNameLoaded; } string getTechNameLoaded () const
bool getAllowNativeLanguageTechtree() const { return allowNativeLanguageTechtree; } {
void setAllowNativeLanguageTechtree(bool value) { allowNativeLanguageTechtree = value; } return techNameLoaded;
}
bool getAllowNativeLanguageTechtree () const
{
return allowNativeLanguageTechtree;
}
void setAllowNativeLanguageTechtree (bool value)
{
allowNativeLanguageTechtree = value;
}
void loadGameStrings(string uselanguage, bool loadFonts=true, bool fallbackToDefault=false); void loadGameStrings (string uselanguage, bool loadFonts =
void loadScenarioStrings(string scenarioDir, string scenarioName, bool isTutorial); true, bool fallbackToDefault = false);
bool loadTechTreeStrings(string techTree, bool forceLoad=false); void loadScenarioStrings (string scenarioDir, string scenarioName,
void loadTilesetStrings(string tileset); bool isTutorial);
bool loadTechTreeStrings (string techTree, bool forceLoad = false);
void loadTilesetStrings (string tileset);
string getString(const string &s,string uselanguage="", bool fallbackToDefault=false); string getString (const string & s, string uselanguage =
bool hasString(const string &s, string uselanguage="", bool fallbackToDefault=false); "", bool fallbackToDefault = false);
bool hasString (const string & s, string uselanguage =
"", bool fallbackToDefault = false);
string getScenarioString(const string &s); string getScenarioString (const string & s);
bool hasScenarioString(const string &s); bool hasScenarioString (const string & s);
string getTechTreeString(const string &s, const char *defaultValue=NULL); string getTechTreeString (const string & s, const char *defaultValue =
string getTilesetString(const string &s, const char *defaultValue=NULL); NULL);
string getTilesetString (const string & s, const char *defaultValue =
NULL);
string getLanguage() const { return language; } string getLanguage () const
bool isLanguageLocal(string compareLanguage) const; {
return language;
}
bool isLanguageLocal (string compareLanguage) const;
//bool isUTF8Language() const; //bool isUTF8Language() const;
string getDefaultLanguage() const; string getDefaultLanguage () const;
map<string,string> getDiscoveredLanguageList(bool searchKeyIsLangName=false); map < string,
pair<string,string> getNavtiveNameFromLanguageName(string langName); string > getDiscoveredLanguageList (bool searchKeyIsLangName = false);
pair < string,
string > getNavtiveNameFromLanguageName (string langName);
string getLanguageFile(string uselanguage); string getLanguageFile (string uselanguage);
}; };
}}//end namespace }} //end namespace
#endif #endif

View File

@@ -16,100 +16,117 @@
using namespace std; using namespace std;
namespace Glest{ namespace Game{ namespace Glest
{
namespace Game
{
// ===================================================== // =====================================================
// class Metrics // class Metrics
// ===================================================== // =====================================================
Metrics::Metrics() { Metrics::Metrics ()
reloadData(); {
} reloadData ();
void Metrics::reload(int resWidth, int resHeight) {
Metrics *metrics = getInstancePtr();
metrics->reloadData(resWidth, resHeight);
}
void Metrics::reloadData(int resWidth, int resHeight) {
Config &config = Config::getInstance();
virtualW= 1000;
virtualH= 750;
if(resWidth > 0) {
screenW= resWidth;
}
else {
screenW= config.getInt("ScreenWidth");
}
if(resHeight > 0) {
screenH= resHeight;
}
else {
screenH= config.getInt("ScreenHeight");
} }
minimapX= 10; void Metrics::reload (int resWidth, int resHeight)
minimapY= 750-128-30+16; {
minimapW= 128; Metrics *metrics = getInstancePtr ();
minimapH= 128; metrics->reloadData (resWidth, resHeight);
}
displayX= 800; void Metrics::reloadData (int resWidth, int resHeight)
displayY= 250; {
displayW= 128; Config & config = Config::getInstance ();
displayH= 480;
}
Metrics * Metrics::getInstancePtr() { virtualW = 1000;
virtualH = 750;
if (resWidth > 0)
{
screenW = resWidth;
}
else
{
screenW = config.getInt ("ScreenWidth");
}
if (resHeight > 0)
{
screenH = resHeight;
}
else
{
screenH = config.getInt ("ScreenHeight");
}
minimapX = 10;
minimapY = 750 - 128 - 30 + 16;
minimapW = 128;
minimapH = 128;
displayX = 800;
displayY = 250;
displayW = 128;
displayH = 480;
}
Metrics *Metrics::getInstancePtr ()
{
static Metrics metrics; static Metrics metrics;
return &metrics; return &metrics;
} }
const Metrics &Metrics::getInstance(){ const Metrics & Metrics::getInstance ()
Metrics *metrics = getInstancePtr(); {
Metrics *metrics = getInstancePtr ();
return *metrics; return *metrics;
}
float Metrics::getAspectRatio() const{
if(screenH == 0) {
throw megaglest_runtime_error("div by 0 screenH == 0");
} }
return static_cast<float>(screenW)/screenH;
}
int Metrics::toVirtualX(int w) const{ float Metrics::getAspectRatio () const
if(screenW == 0) { {
throw megaglest_runtime_error("div by 0 screenW == 0"); if (screenH == 0)
{
throw megaglest_runtime_error ("div by 0 screenH == 0");
}
return static_cast < float >(screenW) / screenH;
} }
return w*virtualW/screenW;
}
int Metrics::toVirtualY(int h) const{ int Metrics::toVirtualX (int w) const
if(screenH == 0) { {
throw megaglest_runtime_error("div by 0 screenH == 0"); if (screenW == 0)
{
throw megaglest_runtime_error ("div by 0 screenW == 0");
}
return w * virtualW / screenW;
}
int Metrics::toVirtualY (int h) const
{
if (screenH == 0)
{
throw megaglest_runtime_error ("div by 0 screenH == 0");
} }
//printf("h [%d] virtualH [%d] screenH [%d] result = %d\n",h,virtualH,screenH,(h*virtualH/screenH)); //printf("h [%d] virtualH [%d] screenH [%d] result = %d\n",h,virtualH,screenH,(h*virtualH/screenH));
return h*virtualH/screenH; return h * virtualH / screenH;
} }
bool Metrics::isInDisplay(int x, int y) const{ bool Metrics::isInDisplay (int x, int y) const
{
return return
x > displayX && x > displayX &&
y > displayY && y > displayY && x < displayX + displayW && y < displayY + displayH;
x < displayX+displayW && }
y < displayY+displayH;
}
bool Metrics::isInMinimap(int x, int y) const{ bool Metrics::isInMinimap (int x, int y) const
{
return return
x > minimapX && x > minimapX &&
y > minimapY && y > minimapY && x < minimapX + minimapW && y < minimapY + minimapH;
x < minimapX+minimapW && }
y < minimapY+minimapH;
}
}}// end namespace }
} // end namespace

View File

@@ -10,24 +10,28 @@
// ============================================================== // ==============================================================
#ifndef _GLEST_GAME_METRICS_H_ #ifndef _GLEST_GAME_METRICS_H_
#define _GLEST_GAME_METRICS_H_ # define _GLEST_GAME_METRICS_H_
#ifdef WIN32 # ifdef WIN32
#include <winsock2.h> # include <winsock2.h>
#include <winsock.h> # include <winsock.h>
#endif # endif
#include "config.h" # include "config.h"
#include "leak_dumper.h" # include "leak_dumper.h"
namespace Glest{ namespace Game{ namespace Glest
{
namespace Game
{
// ===================================================== // =====================================================
// class Metrics // class Metrics
// ===================================================== // =====================================================
class Metrics{ class Metrics
private: {
private:
int virtualW; int virtualW;
int virtualH; int virtualH;
int screenW; int screenW;
@@ -41,37 +45,73 @@ private:
int displayH; int displayH;
int displayW; int displayW;
private: private:
Metrics(); Metrics ();
static Metrics *getInstancePtr(); static Metrics *getInstancePtr ();
void reloadData(int resWidth=-1, int resHeight=-1); void reloadData (int resWidth = -1, int resHeight = -1);
public: public:
static const Metrics &getInstance(); static const Metrics & getInstance ();
int getVirtualW() const {return virtualW;} int getVirtualW () const
int getVirtualH() const {return virtualH;} {
int getScreenW() const {return screenW;} return virtualW;
int getScreenH() const {return screenH;} }
int getMinimapX() const {return minimapX;} int getVirtualH () const
int getMinimapY() const {return minimapY;} {
int getMinimapW() const {return minimapW;} return virtualH;
int getMinimapH() const {return minimapH;} }
int getDisplayX() const {return displayX;} int getScreenW () const
int getDisplayY() const {return displayY;} {
int getDisplayH() const {return displayH;} return screenW;
int getDisplayW() const {return displayW;} }
float getAspectRatio() const; int getScreenH () const
{
return screenH;
}
int getMinimapX () const
{
return minimapX;
}
int getMinimapY () const
{
return minimapY;
}
int getMinimapW () const
{
return minimapW;
}
int getMinimapH () const
{
return minimapH;
}
int getDisplayX () const
{
return displayX;
}
int getDisplayY () const
{
return displayY;
}
int getDisplayH () const
{
return displayH;
}
int getDisplayW () const
{
return displayW;
}
float getAspectRatio () const;
int toVirtualX(int w) const; int toVirtualX (int w) const;
int toVirtualY(int h) const; int toVirtualY (int h) const;
bool isInDisplay(int x, int y) const; bool isInDisplay (int x, int y) const;
bool isInMinimap(int x, int y) const; bool isInMinimap (int x, int y) const;
static void reload(int resWidth=-1, int resHeight=-1); static void reload (int resWidth = -1, int resHeight = -1);
}; };
}}//end namespace }} //end namespace
#endif #endif