mirror of
https://github.com/glest/glest-source.git
synced 2025-08-10 02:16:31 +02:00
Fixed the god-awful indentation
This commit is contained in:
@@ -36,61 +36,67 @@ using std::string;
|
||||
|
||||
using Shared::Graphics::FontMetrics;
|
||||
|
||||
namespace Shared{ namespace Platform{
|
||||
namespace Shared {
|
||||
namespace Platform {
|
||||
|
||||
// =====================================================
|
||||
// class PlatformContextGl
|
||||
// =====================================================
|
||||
// =====================================================
|
||||
// class PlatformContextGl
|
||||
// =====================================================
|
||||
|
||||
class PlatformContextGl {
|
||||
protected:
|
||||
SDL_Surface *icon;
|
||||
SDL_Window *window;
|
||||
SDL_GLContext glcontext;
|
||||
class PlatformContextGl {
|
||||
protected:
|
||||
SDL_Surface *icon;
|
||||
SDL_Window *window;
|
||||
SDL_GLContext glcontext;
|
||||
|
||||
public:
|
||||
// Example values:
|
||||
// DEFAULT_CHARSET (English) = 1
|
||||
// GB2312_CHARSET (Chinese) = 134
|
||||
#ifdef WIN32
|
||||
static DWORD charSet;
|
||||
#else
|
||||
static int charSet;
|
||||
#endif
|
||||
public:
|
||||
// Example values:
|
||||
// DEFAULT_CHARSET (English) = 1
|
||||
// GB2312_CHARSET (Chinese) = 134
|
||||
#ifdef WIN32
|
||||
static DWORD charSet;
|
||||
#else
|
||||
static int charSet;
|
||||
#endif
|
||||
|
||||
public:
|
||||
PlatformContextGl();
|
||||
virtual ~PlatformContextGl();
|
||||
public:
|
||||
PlatformContextGl();
|
||||
virtual ~PlatformContextGl();
|
||||
|
||||
virtual void init(int colorBits, int depthBits, int stencilBits,
|
||||
bool hardware_acceleration, bool fullscreen_anti_aliasing,
|
||||
float gammaValue);
|
||||
virtual void end();
|
||||
virtual void init(int colorBits, int depthBits, int stencilBits,
|
||||
bool hardware_acceleration, bool fullscreen_anti_aliasing,
|
||||
float gammaValue);
|
||||
virtual void end();
|
||||
|
||||
virtual void makeCurrent();
|
||||
virtual void swapBuffers();
|
||||
virtual void makeCurrent();
|
||||
virtual void swapBuffers();
|
||||
|
||||
SDL_Window * getScreenWindow() { return window; }
|
||||
SDL_Surface * getScreenSurface();
|
||||
SDL_Window * getScreenWindow() {
|
||||
return window;
|
||||
}
|
||||
SDL_Surface * getScreenSurface();
|
||||
|
||||
DeviceContextHandle getHandle() const { return 0; }
|
||||
};
|
||||
DeviceContextHandle getHandle() const {
|
||||
return 0;
|
||||
}
|
||||
};
|
||||
|
||||
// =====================================================
|
||||
// Global Fcs
|
||||
// =====================================================
|
||||
// =====================================================
|
||||
// Global Fcs
|
||||
// =====================================================
|
||||
|
||||
#if defined(__APPLE__)
|
||||
void createGlFontBitmaps(uint32 &base, const string &type, int size, int width, int charCount, FontMetrics &metrics);
|
||||
void createGlFontOutlines(uint32 &base, const string &type, int width, float depth, int charCount, FontMetrics &metrics);
|
||||
void createGlFontBitmaps(uint32 &base, const string &type, int size, int width, int charCount, FontMetrics &metrics);
|
||||
void createGlFontOutlines(uint32 &base, const string &type, int width, float depth, int charCount, FontMetrics &metrics);
|
||||
#else
|
||||
void createGlFontBitmaps(uint32 &base, const string &type, int size, int width, int charCount, FontMetrics &metrics);
|
||||
void createGlFontOutlines(uint32 &base, const string &type, int width, float depth, int charCount, FontMetrics &metrics);
|
||||
void createGlFontBitmaps(uint32 &base, const string &type, int size, int width, int charCount, FontMetrics &metrics);
|
||||
void createGlFontOutlines(uint32 &base, const string &type, int width, float depth, int charCount, FontMetrics &metrics);
|
||||
#endif
|
||||
|
||||
const char *getPlatformExtensions(const PlatformContextGl *pcgl);
|
||||
void* getGlProcAddress(const char *procName);
|
||||
const char *getPlatformExtensions(const PlatformContextGl *pcgl);
|
||||
void* getGlProcAddress(const char *procName);
|
||||
|
||||
}}//end namespace
|
||||
}
|
||||
}//end namespace
|
||||
|
||||
#endif
|
||||
|
@@ -17,9 +17,9 @@
|
||||
#include "leak_dumper.h"
|
||||
|
||||
#ifndef WIN32
|
||||
#define stricmp strcasecmp
|
||||
#define strnicmp strncasecmp
|
||||
#define _strnicmp strncasecmp
|
||||
#define stricmp strcasecmp
|
||||
#define strnicmp strncasecmp
|
||||
#define _strnicmp strncasecmp
|
||||
#endif
|
||||
|
||||
const char *GAME_ARGS[] = {
|
||||
@@ -197,22 +197,22 @@ enum GAME_ARG_TYPE {
|
||||
void printParameterHelp(const char *argv0, bool foundInvalidArgs) {
|
||||
// MAX WIDTH FOR MAN PAGE
|
||||
// "================================================================================"
|
||||
if(foundInvalidArgs == true) {
|
||||
printf("\n");
|
||||
if (foundInvalidArgs == true) {
|
||||
printf("\n");
|
||||
}
|
||||
printf("\n%s, usage",extractFileFromDirectoryPath(argv0).c_str());
|
||||
printf("\n%s, usage", extractFileFromDirectoryPath(argv0).c_str());
|
||||
printf("\n\nCommandline Parameter: Description:");
|
||||
printf("\n\n- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -");
|
||||
printf("\n\n%s \t\tDisplays this help text.",GAME_ARGS[GAME_ARG_HELP]);
|
||||
printf("\n\n%s \t\tDisplays this help text.", GAME_ARGS[GAME_ARG_HELP]);
|
||||
|
||||
printf("\n\n%s \tAutomatically starts a game with the last game",GAME_ARGS[GAME_ARG_AUTOSTART_LASTGAME]);
|
||||
printf("\n\n%s \tAutomatically starts a game with the last game", GAME_ARGS[GAME_ARG_AUTOSTART_LASTGAME]);
|
||||
printf("\n\n \tsettings you played.");
|
||||
|
||||
printf("\n\n%s=x \tLoads the last saved game.",GAME_ARGS[GAME_ARG_AUTOSTART_LAST_SAVED_GAME]);
|
||||
printf("\n\n%s=x \tLoads the last saved game.", GAME_ARGS[GAME_ARG_AUTOSTART_LAST_SAVED_GAME]);
|
||||
printf("\n\n \tWhere x is an optional name of the saved game file to load.");
|
||||
printf("\n\n \tIf x is not specified we load the last game that was saved.");
|
||||
|
||||
printf("\n\n%s=x,y,z \tRun in auto test mode.",GAME_ARGS[GAME_ARG_AUTO_TEST]);
|
||||
printf("\n\n%s=x,y,z \tRun in auto test mode.", GAME_ARGS[GAME_ARG_AUTO_TEST]);
|
||||
printf("\n\n \tWhere x is an optional maximum # seconds to play.");
|
||||
printf("\n\n \tIf x is not specified the default is 1200 seconds (20 minutes).");
|
||||
printf("\n\n \tWhere y is an optional game settings file to play.");
|
||||
@@ -222,18 +222,18 @@ void printParameterHelp(const char *argv0, bool foundInvalidArgs) {
|
||||
printf("\n\n \tafter the game is finished or the time runs out. If z is");
|
||||
printf("\n\n \tnot specified (or is empty) then auto test continues to cycle.");
|
||||
|
||||
printf("\n\n%s=x:y \t\tAuto connect to host server at IP or hostname x using",GAME_ARGS[GAME_ARG_CONNECT]);
|
||||
printf("\n\n \t port y. Shortcut version of using %s and %s.",GAME_ARGS[GAME_ARG_CLIENT],GAME_ARGS[GAME_ARG_USE_PORTS]);
|
||||
printf("\n\n%s=x:y \t\tAuto connect to host server at IP or hostname x using", GAME_ARGS[GAME_ARG_CONNECT]);
|
||||
printf("\n\n \t port y. Shortcut version of using %s and %s.", GAME_ARGS[GAME_ARG_CLIENT], GAME_ARGS[GAME_ARG_USE_PORTS]);
|
||||
printf("\n\n \t*NOTE: to automatically connect to the first LAN host you may");
|
||||
printf("\n\n \t use: %s=auto-connect",GAME_ARGS[GAME_ARG_CONNECT]);
|
||||
printf("\n\n \t use: %s=auto-connect", GAME_ARGS[GAME_ARG_CONNECT]);
|
||||
|
||||
printf("\n\n%s=x \tAuto connect to host server at IP or hostname x.",GAME_ARGS[GAME_ARG_CLIENT]);
|
||||
printf("\n\n%s=x \tAuto connect to host server at IP or hostname x.", GAME_ARGS[GAME_ARG_CLIENT]);
|
||||
printf("\n\n \t*NOTE: to automatically connect to the first LAN host you may");
|
||||
printf("\n\n \t use: %s=auto-connect",GAME_ARGS[GAME_ARG_CLIENT]);
|
||||
printf("\n\n \t use: %s=auto-connect", GAME_ARGS[GAME_ARG_CLIENT]);
|
||||
|
||||
printf("\n\n%s \t\tAuto create a host server.",GAME_ARGS[GAME_ARG_SERVER]);
|
||||
printf("\n\n%s \t\tAuto create a host server.", GAME_ARGS[GAME_ARG_SERVER]);
|
||||
|
||||
printf("\n\n%s=x,x ",GAME_ARGS[GAME_ARG_MASTERSERVER_MODE]);
|
||||
printf("\n\n%s=x,x ", GAME_ARGS[GAME_ARG_MASTERSERVER_MODE]);
|
||||
printf("\n\n \tRun as a headless server.");
|
||||
printf("\n\n \tWhere x is an optional comma delimited command list of one or");
|
||||
printf("\n\n \t more of the following: ");
|
||||
@@ -244,10 +244,10 @@ void printParameterHelp(const char *argv0, bool foundInvalidArgs) {
|
||||
printf("\n\n \t'lan' - which does not broadcast the hosting server to the");
|
||||
printf("\n\n \t masterserver (for local LAN games).");
|
||||
|
||||
printf("\n\n%s ",GAME_ARGS[GAME_ARG_MASTERSERVER_STATUS]);
|
||||
printf("\n\n%s ", GAME_ARGS[GAME_ARG_MASTERSERVER_STATUS]);
|
||||
printf("\n\n \tCheck the current status of a headless server.");
|
||||
|
||||
printf("\n\n%s=x,y,z \tForce hosted games to listen internally on port",GAME_ARGS[GAME_ARG_USE_PORTS]);
|
||||
printf("\n\n%s=x,y,z \tForce hosted games to listen internally on port", GAME_ARGS[GAME_ARG_USE_PORTS]);
|
||||
printf("\n\n \t x, externally on port y and for game status on port z.");
|
||||
printf("\n\n \tWhere x is the internal port # on the local machine to");
|
||||
printf("\n\n \t listen for connects.");
|
||||
@@ -258,23 +258,23 @@ void printParameterHelp(const char *argv0, bool foundInvalidArgs) {
|
||||
printf("\n\n \t*NOTE: If enabled the FTP Server port #'s will be set");
|
||||
printf("\n\n \t to x+1 to x+9.");
|
||||
|
||||
printf("\n\n%s=x \tSet server title.",GAME_ARGS[GAME_ARG_SERVER_TITLE]);
|
||||
printf("\n\n%s=x \tSet server title.", GAME_ARGS[GAME_ARG_SERVER_TITLE]);
|
||||
|
||||
printf("\n\n%s=x \tAuto load a scenario by scenario name.",GAME_ARGS[GAME_ARG_LOADSCENARIO]);
|
||||
printf("\n\n%s=x \t\tAuto load a mod by mod pathname.",GAME_ARGS[GAME_ARG_MOD]);
|
||||
printf("\n\n%s=x \tAuto load a scenario by scenario name.", GAME_ARGS[GAME_ARG_LOADSCENARIO]);
|
||||
printf("\n\n%s=x \t\tAuto load a mod by mod pathname.", GAME_ARGS[GAME_ARG_MOD]);
|
||||
|
||||
// "================================================================================"
|
||||
printf("\n\n%s=Map,Tileset ",GAME_ARGS[GAME_ARG_PREVIEW_MAP]);
|
||||
printf("\n\n%s=Map,Tileset ", GAME_ARGS[GAME_ARG_PREVIEW_MAP]);
|
||||
printf("\n\n \tAuto Preview a map by map name. (tileset is optional)");
|
||||
printf("\n\n%s \t\tDisplays the version string of this program.",GAME_ARGS[GAME_ARG_VERSION]);
|
||||
printf("\n\n%s \t\tDisplays your video driver's OpenGL info.",GAME_ARGS[GAME_ARG_OPENGL_INFO]);
|
||||
printf("\n\n%s \t\tDisplays your SDL version information.",GAME_ARGS[GAME_ARG_SDL_INFO]);
|
||||
printf("\n\n%s \t\tDisplays your LUA version information.",GAME_ARGS[GAME_ARG_LUA_INFO]);
|
||||
printf("\n\n%s \t\tDisplays LUA debug information.",GAME_ARGS[GAME_ARG_LUA_DEBUG]);
|
||||
printf("\n\n%s \t\tDisplays your CURL version information.",GAME_ARGS[GAME_ARG_CURL_INFO]);
|
||||
printf("\n\n%s \t\tDisplays your XERCES version information.",GAME_ARGS[GAME_ARG_XERCES_INFO]);
|
||||
printf("\n\n%s \t\tDisplays the version string of this program.", GAME_ARGS[GAME_ARG_VERSION]);
|
||||
printf("\n\n%s \t\tDisplays your video driver's OpenGL info.", GAME_ARGS[GAME_ARG_OPENGL_INFO]);
|
||||
printf("\n\n%s \t\tDisplays your SDL version information.", GAME_ARGS[GAME_ARG_SDL_INFO]);
|
||||
printf("\n\n%s \t\tDisplays your LUA version information.", GAME_ARGS[GAME_ARG_LUA_INFO]);
|
||||
printf("\n\n%s \t\tDisplays LUA debug information.", GAME_ARGS[GAME_ARG_LUA_DEBUG]);
|
||||
printf("\n\n%s \t\tDisplays your CURL version information.", GAME_ARGS[GAME_ARG_CURL_INFO]);
|
||||
printf("\n\n%s \t\tDisplays your XERCES version information.", GAME_ARGS[GAME_ARG_XERCES_INFO]);
|
||||
|
||||
printf("\n\n%s=x=purgeunused=purgeduplicates=gitdelete=hideduplicates ",GAME_ARGS[GAME_ARG_VALIDATE_TECHTREES]);
|
||||
printf("\n\n%s=x=purgeunused=purgeduplicates=gitdelete=hideduplicates ", GAME_ARGS[GAME_ARG_VALIDATE_TECHTREES]);
|
||||
printf("\n\n \tDisplay a report detailing any known problems related to");
|
||||
printf("\n\n \t your selected techtrees game data.");
|
||||
printf("\n\n \tWhere x is a comma-delimited list of techtrees to validate.");
|
||||
@@ -291,9 +291,9 @@ void printParameterHelp(const char *argv0, bool foundInvalidArgs) {
|
||||
printf("\n\n \t*NOTE: This only applies when files are purged due to the");
|
||||
printf("\n\n \t above flags being set.");
|
||||
printf("\n\n \texample:");
|
||||
printf("\n\n \t%s %s=megapack,vbros_pack_5",extractFileFromDirectoryPath(argv0).c_str(),GAME_ARGS[GAME_ARG_VALIDATE_TECHTREES]);
|
||||
printf("\n\n \t%s %s=megapack,vbros_pack_5", extractFileFromDirectoryPath(argv0).c_str(), GAME_ARGS[GAME_ARG_VALIDATE_TECHTREES]);
|
||||
|
||||
printf("\n\n%s=x=purgeunused=purgeduplicates=hideduplicates ",GAME_ARGS[GAME_ARG_VALIDATE_FACTIONS]);
|
||||
printf("\n\n%s=x=purgeunused=purgeduplicates=hideduplicates ", GAME_ARGS[GAME_ARG_VALIDATE_FACTIONS]);
|
||||
printf("\n\n \tDisplay a report detailing any known problems related to");
|
||||
printf("\n\n \t your selected factions game data.");
|
||||
printf("\n\n \tWhere x is a comma-delimited list of factions to validate.");
|
||||
@@ -305,72 +305,72 @@ void printParameterHelp(const char *argv0, bool foundInvalidArgs) {
|
||||
printf("\n\n \tWhere 'hideduplicates' is an optional parameter telling the");
|
||||
printf("\n\n \t validation to NOT SHOW duplicate files in the techtree.");
|
||||
printf("\n\n \t*NOTE: leaving the list empty is the same as running:");
|
||||
printf("\n\n \t %s",GAME_ARGS[GAME_ARG_VALIDATE_TECHTREES]);
|
||||
printf("\n\n \texample: %s %s=tech,egypt",extractFileFromDirectoryPath(argv0).c_str(),GAME_ARGS[GAME_ARG_VALIDATE_FACTIONS]);
|
||||
printf("\n\n \t %s", GAME_ARGS[GAME_ARG_VALIDATE_TECHTREES]);
|
||||
printf("\n\n \texample: %s %s=tech,egypt", extractFileFromDirectoryPath(argv0).c_str(), GAME_ARGS[GAME_ARG_VALIDATE_FACTIONS]);
|
||||
|
||||
printf("\n\n%s=x=purgeunused=gitdelete ",GAME_ARGS[GAME_ARG_VALIDATE_SCENARIO]);
|
||||
printf("\n\n%s=x=purgeunused=gitdelete ", GAME_ARGS[GAME_ARG_VALIDATE_SCENARIO]);
|
||||
printf("\n\n \tDisplay a report detailing any known problems related to");
|
||||
printf("\n\n \t your selected scenario game data.");
|
||||
printf("\n\n \tWhere x is a single scenario to validate.");
|
||||
printf("\n\n \tWhere 'purgeunused' is an optional parameter telling the");
|
||||
printf("\n\n \t validation to delete extra files in the scenario that");
|
||||
printf("\n\n \t are not used.");
|
||||
printf("\n\n \texample: %s %s=stranded",extractFileFromDirectoryPath(argv0).c_str(),GAME_ARGS[GAME_ARG_VALIDATE_SCENARIO]);
|
||||
printf("\n\n \texample: %s %s=stranded", extractFileFromDirectoryPath(argv0).c_str(), GAME_ARGS[GAME_ARG_VALIDATE_SCENARIO]);
|
||||
|
||||
printf("\n\n%s=x=purgeunused=gitdelete ",GAME_ARGS[GAME_ARG_VALIDATE_TILESET]);
|
||||
printf("\n\n%s=x=purgeunused=gitdelete ", GAME_ARGS[GAME_ARG_VALIDATE_TILESET]);
|
||||
printf("\n\n \tDisplay a report detailing any known problems related to");
|
||||
printf("\n\n \t your selected tileset game data.");
|
||||
printf("\n\n \tWhere x is a single tileset to validate.");
|
||||
printf("\n\n \tWhere 'purgeunused' is an optional parameter telling the");
|
||||
printf("\n\n \t validation to delete extra files in the tileset that");
|
||||
printf("\n\n \t are not used.");
|
||||
printf("\n\n \texample: %s %s=desert2",extractFileFromDirectoryPath(argv0).c_str(),GAME_ARGS[GAME_ARG_VALIDATE_TILESET]);
|
||||
printf("\n\n \texample: %s %s=desert2", extractFileFromDirectoryPath(argv0).c_str(), GAME_ARGS[GAME_ARG_VALIDATE_TILESET]);
|
||||
|
||||
printf("\n\n%s=x ",GAME_ARGS[GAME_ARG_TRANSLATE_TECHTREES]);
|
||||
printf("\n\n%s=x ", GAME_ARGS[GAME_ARG_TRANSLATE_TECHTREES]);
|
||||
printf("\n\n \tProduces a default lng file for the specified techtree to");
|
||||
printf("\n\n \t prepare for translation into other languages.");
|
||||
printf("\n\n \tWhere x is a techtree name.");
|
||||
|
||||
printf("\n\n%s=x \t\tDisplay a list of game content: maps.",GAME_ARGS[GAME_ARG_LIST_MAPS]);
|
||||
printf("\n\n%s=x \t\tDisplay a list of game content: maps.", GAME_ARGS[GAME_ARG_LIST_MAPS]);
|
||||
printf("\n\n \tWhere x is an optional name filter.");
|
||||
printf("\n\n \texample: %s %s=island*",extractFileFromDirectoryPath(argv0).c_str(),GAME_ARGS[GAME_ARG_LIST_MAPS]);
|
||||
printf("\n\n \texample: %s %s=island*", extractFileFromDirectoryPath(argv0).c_str(), GAME_ARGS[GAME_ARG_LIST_MAPS]);
|
||||
|
||||
printf("\n\n%s=showfactions ",GAME_ARGS[GAME_ARG_LIST_TECHTRESS]);
|
||||
printf("\n\n%s=showfactions ", GAME_ARGS[GAME_ARG_LIST_TECHTRESS]);
|
||||
printf("\n\n \tDisplay a list of game content: techtrees.");
|
||||
printf("\n\n \tWhere 'showfactions' is an optional parameter to display");
|
||||
printf("\n\n \t factions in each techtree.");
|
||||
printf("\n\n \texample: %s %s=showfactions",extractFileFromDirectoryPath(argv0).c_str(),GAME_ARGS[GAME_ARG_LIST_TECHTRESS]);
|
||||
printf("\n\n \texample: %s %s=showfactions", extractFileFromDirectoryPath(argv0).c_str(), GAME_ARGS[GAME_ARG_LIST_TECHTRESS]);
|
||||
|
||||
printf("\n\n%s=x \tDisplay a list of game content: scenarios.",GAME_ARGS[GAME_ARG_LIST_SCENARIOS]);
|
||||
printf("\n\n%s=x \tDisplay a list of game content: scenarios.", GAME_ARGS[GAME_ARG_LIST_SCENARIOS]);
|
||||
printf("\n\n \tWhere x is an optional name filter.");
|
||||
printf("\n\n \texample: %s %s=beginner*",extractFileFromDirectoryPath(argv0).c_str(),GAME_ARGS[GAME_ARG_LIST_SCENARIOS]);
|
||||
printf("\n\n \texample: %s %s=beginner*", extractFileFromDirectoryPath(argv0).c_str(), GAME_ARGS[GAME_ARG_LIST_SCENARIOS]);
|
||||
|
||||
printf("\n\n%s=x \tDisplay a list of game content: tilesets.",GAME_ARGS[GAME_ARG_LIST_TILESETS]);
|
||||
printf("\n\n%s=x \tDisplay a list of game content: tilesets.", GAME_ARGS[GAME_ARG_LIST_TILESETS]);
|
||||
printf("\n\n \tWhere x is an optional name filter.");
|
||||
printf("\n\n \texample: %s %s=f*",extractFileFromDirectoryPath(argv0).c_str(),GAME_ARGS[GAME_ARG_LIST_TILESETS]);
|
||||
printf("\n\n \texample: %s %s=f*", extractFileFromDirectoryPath(argv0).c_str(), GAME_ARGS[GAME_ARG_LIST_TILESETS]);
|
||||
|
||||
printf("\n\n%s=x \tDisplay a list of game content: tutorials.",GAME_ARGS[GAME_ARG_LIST_TUTORIALS]);
|
||||
printf("\n\n%s=x \tDisplay a list of game content: tutorials.", GAME_ARGS[GAME_ARG_LIST_TUTORIALS]);
|
||||
printf("\n\n \tWhere x is an optional name filter.");
|
||||
printf("\n\n \texample: %s %s=*",extractFileFromDirectoryPath(argv0).c_str(),GAME_ARGS[GAME_ARG_LIST_TUTORIALS]);
|
||||
printf("\n\n \texample: %s %s=*", extractFileFromDirectoryPath(argv0).c_str(), GAME_ARGS[GAME_ARG_LIST_TUTORIALS]);
|
||||
|
||||
// "================================================================================"
|
||||
printf("\n\n%s=x \t\tSets the game data path to x.",GAME_ARGS[GAME_ARG_DATA_PATH]);
|
||||
printf("\n\n%s=x \t\tSets the game data path to x.", GAME_ARGS[GAME_ARG_DATA_PATH]);
|
||||
printf("\n\n \texample:");
|
||||
printf("\n\n \t%s %s=/usr/local/game_data/",extractFileFromDirectoryPath(argv0).c_str(),GAME_ARGS[GAME_ARG_DATA_PATH]);
|
||||
printf("\n\n%s=x \t\tSets the game ini path to x.",GAME_ARGS[GAME_ARG_INI_PATH]);
|
||||
printf("\n\n \texample: %s %s=~/game_config/",extractFileFromDirectoryPath(argv0).c_str(),GAME_ARGS[GAME_ARG_INI_PATH]);
|
||||
printf("\n\n%s=x \t\tSets the game logs path to x.",GAME_ARGS[GAME_ARG_LOG_PATH]);
|
||||
printf("\n\n \texample: %s %s=~/game_logs/",extractFileFromDirectoryPath(argv0).c_str(),GAME_ARGS[GAME_ARG_LOG_PATH]);
|
||||
printf("\n\n%s=x \t\tSets the game fonts path to x.",GAME_ARGS[GAME_ARG_FONT_PATH]);
|
||||
printf("\n\n \texample: %s %s=~/myfonts/",extractFileFromDirectoryPath(argv0).c_str(),GAME_ARGS[GAME_ARG_FONT_PATH]);
|
||||
printf("\n\n \t%s %s=/usr/local/game_data/", extractFileFromDirectoryPath(argv0).c_str(), GAME_ARGS[GAME_ARG_DATA_PATH]);
|
||||
printf("\n\n%s=x \t\tSets the game ini path to x.", GAME_ARGS[GAME_ARG_INI_PATH]);
|
||||
printf("\n\n \texample: %s %s=~/game_config/", extractFileFromDirectoryPath(argv0).c_str(), GAME_ARGS[GAME_ARG_INI_PATH]);
|
||||
printf("\n\n%s=x \t\tSets the game logs path to x.", GAME_ARGS[GAME_ARG_LOG_PATH]);
|
||||
printf("\n\n \texample: %s %s=~/game_logs/", extractFileFromDirectoryPath(argv0).c_str(), GAME_ARGS[GAME_ARG_LOG_PATH]);
|
||||
printf("\n\n%s=x \t\tSets the game fonts path to x.", GAME_ARGS[GAME_ARG_FONT_PATH]);
|
||||
printf("\n\n \texample: %s %s=~/myfonts/", extractFileFromDirectoryPath(argv0).c_str(), GAME_ARGS[GAME_ARG_FONT_PATH]);
|
||||
|
||||
printf("\n\n%s=x \tDisplay merged ini settings information.",GAME_ARGS[GAME_ARG_SHOW_INI_SETTINGS]);
|
||||
printf("\n\n%s=x \tDisplay merged ini settings information.", GAME_ARGS[GAME_ARG_SHOW_INI_SETTINGS]);
|
||||
printf("\n\n \tWhere x is an optional property name to filter (default");
|
||||
printf("\n\n \t shows all).");
|
||||
printf("\n\n \texample:");
|
||||
printf("\n\n \t%s %s=DebugMode",extractFileFromDirectoryPath(argv0).c_str(),GAME_ARGS[GAME_ARG_SHOW_INI_SETTINGS]);
|
||||
printf("\n\n \t%s %s=DebugMode", extractFileFromDirectoryPath(argv0).c_str(), GAME_ARGS[GAME_ARG_SHOW_INI_SETTINGS]);
|
||||
|
||||
printf("\n\n%s=x=textureformat=keepsmallest ",GAME_ARGS[GAME_ARG_CONVERT_MODELS]);
|
||||
printf("\n\n%s=x=textureformat=keepsmallest ", GAME_ARGS[GAME_ARG_CONVERT_MODELS]);
|
||||
printf("\n\n \tConvert a model file or folder to the current g3d version");
|
||||
printf("\n\n \t format.");
|
||||
printf("\n\n \tWhere x is a filename or folder containing the g3d model(s).");
|
||||
@@ -380,116 +380,116 @@ void printParameterHelp(const char *argv0, bool foundInvalidArgs) {
|
||||
printf("\n\n \t the original texture if its filesize is smaller than the");
|
||||
printf("\n\n \t converted format.");
|
||||
printf("\n\n \texample:");
|
||||
printf("\n\n \t%s %s=techs/megapack/factions/tech/",extractFileFromDirectoryPath(argv0).c_str(),GAME_ARGS[GAME_ARG_CONVERT_MODELS]);
|
||||
printf("\n\n \t%s %s=techs/megapack/factions/tech/", extractFileFromDirectoryPath(argv0).c_str(), GAME_ARGS[GAME_ARG_CONVERT_MODELS]);
|
||||
printf("\n\n \tunits/castle/models/castle.g3d=png=keepsmallest");
|
||||
|
||||
printf("\n\n%s=x \tForce the language to be the language specified",GAME_ARGS[GAME_ARG_USE_LANGUAGE]);
|
||||
printf("\n\n%s=x \tForce the language to be the language specified", GAME_ARGS[GAME_ARG_USE_LANGUAGE]);
|
||||
printf("\n\n \t by x. Where x is a language filename or ISO639-1 code.");
|
||||
printf("\n\n \texample: %s %s=english",extractFileFromDirectoryPath(argv0).c_str(),GAME_ARGS[GAME_ARG_USE_LANGUAGE]);
|
||||
printf("\n\n \texample: %s %s=en",extractFileFromDirectoryPath(argv0).c_str(),GAME_ARGS[GAME_ARG_USE_LANGUAGE]);
|
||||
printf("\n\n \texample: %s %s=english", extractFileFromDirectoryPath(argv0).c_str(), GAME_ARGS[GAME_ARG_USE_LANGUAGE]);
|
||||
printf("\n\n \texample: %s %s=en", extractFileFromDirectoryPath(argv0).c_str(), GAME_ARGS[GAME_ARG_USE_LANGUAGE]);
|
||||
|
||||
printf("\n\n%s=x \tShow the calculated CRC for the map named x.",GAME_ARGS[GAME_ARG_SHOW_MAP_CRC]);
|
||||
printf("\n\n%s=x \tShow the calculated CRC for the map named x.", GAME_ARGS[GAME_ARG_SHOW_MAP_CRC]);
|
||||
printf("\n\n \tWhere x is a map name.");
|
||||
printf("\n\n \texample: %s %s=four_rivers",extractFileFromDirectoryPath(argv0).c_str(),GAME_ARGS[GAME_ARG_SHOW_MAP_CRC]);
|
||||
printf("\n\n \texample: %s %s=four_rivers", extractFileFromDirectoryPath(argv0).c_str(), GAME_ARGS[GAME_ARG_SHOW_MAP_CRC]);
|
||||
|
||||
printf("\n\n%s=x \tShow the calculated CRC for the tileset named x.",GAME_ARGS[GAME_ARG_SHOW_TILESET_CRC]);
|
||||
printf("\n\n%s=x \tShow the calculated CRC for the tileset named x.", GAME_ARGS[GAME_ARG_SHOW_TILESET_CRC]);
|
||||
printf("\n\n \tWhere x is a tileset name.");
|
||||
printf("\n\n \texample: %s %s=forest",extractFileFromDirectoryPath(argv0).c_str(),GAME_ARGS[GAME_ARG_SHOW_TILESET_CRC]);
|
||||
printf("\n\n \texample: %s %s=forest", extractFileFromDirectoryPath(argv0).c_str(), GAME_ARGS[GAME_ARG_SHOW_TILESET_CRC]);
|
||||
|
||||
printf("\n\n%s=x \tShow the calculated CRC for the techtree named x.",GAME_ARGS[GAME_ARG_SHOW_TECHTREE_CRC]);
|
||||
printf("\n\n%s=x \tShow the calculated CRC for the techtree named x.", GAME_ARGS[GAME_ARG_SHOW_TECHTREE_CRC]);
|
||||
printf("\n\n \tWhere x is a techtree name.");
|
||||
printf("\n\n \texample: %s %s=megapack",extractFileFromDirectoryPath(argv0).c_str(),GAME_ARGS[GAME_ARG_SHOW_TECHTREE_CRC]);
|
||||
printf("\n\n \texample: %s %s=megapack", extractFileFromDirectoryPath(argv0).c_str(), GAME_ARGS[GAME_ARG_SHOW_TECHTREE_CRC]);
|
||||
|
||||
printf("\n\n%s=x \tShow the calculated CRC for the scenario named x.",GAME_ARGS[GAME_ARG_SHOW_SCENARIO_CRC]);
|
||||
printf("\n\n%s=x \tShow the calculated CRC for the scenario named x.", GAME_ARGS[GAME_ARG_SHOW_SCENARIO_CRC]);
|
||||
printf("\n\n \tWhere x is a scenario name.");
|
||||
printf("\n\n \texample: %s %s=storming",extractFileFromDirectoryPath(argv0).c_str(),GAME_ARGS[GAME_ARG_SHOW_SCENARIO_CRC]);
|
||||
printf("\n\n \texample: %s %s=storming", extractFileFromDirectoryPath(argv0).c_str(), GAME_ARGS[GAME_ARG_SHOW_SCENARIO_CRC]);
|
||||
|
||||
// "================================================================================"
|
||||
printf("\n\n%s=x=y \tShow the calculated CRC for files in the path",GAME_ARGS[GAME_ARG_SHOW_PATH_CRC]);
|
||||
printf("\n\n%s=x=y \tShow the calculated CRC for files in the path", GAME_ARGS[GAME_ARG_SHOW_PATH_CRC]);
|
||||
printf("\n\n \t located in x using file filter y.");
|
||||
printf("\n\n \tWhere x is a path name and y is file(s) filter.");
|
||||
printf("\n\n \texample: %s %s=techs/=megapack.7z",extractFileFromDirectoryPath(argv0).c_str(),GAME_ARGS[GAME_ARG_SHOW_PATH_CRC]);
|
||||
printf("\n\n \texample: %s %s=techs/=megapack.7z", extractFileFromDirectoryPath(argv0).c_str(), GAME_ARGS[GAME_ARG_SHOW_PATH_CRC]);
|
||||
|
||||
printf("\n\n%s \tDisables stack backtrace on errors.",GAME_ARGS[GAME_ARG_DISABLE_BACKTRACE]);
|
||||
printf("\n\n%s \tDisables stack backtrace on errors.", GAME_ARGS[GAME_ARG_DISABLE_BACKTRACE]);
|
||||
|
||||
printf("\n\n%s ",GAME_ARGS[GAME_ARG_DISABLE_SIGSEGV_HANDLER]);
|
||||
printf("\n\n%s ", GAME_ARGS[GAME_ARG_DISABLE_SIGSEGV_HANDLER]);
|
||||
printf("\n\n \tDisables the sigsegv error handler.");
|
||||
|
||||
printf("\n\n%s \t\tDisables trying to use Vertex Buffer Objects.",GAME_ARGS[GAME_ARG_DISABLE_VBO]);
|
||||
printf("\n\n%s ",GAME_ARGS[GAME_ARG_DISABLE_VERTEX_INTERPOLATION]);
|
||||
printf("\n\n%s \t\tDisables trying to use Vertex Buffer Objects.", GAME_ARGS[GAME_ARG_DISABLE_VBO]);
|
||||
printf("\n\n%s ", GAME_ARGS[GAME_ARG_DISABLE_VERTEX_INTERPOLATION]);
|
||||
printf("\n\n \tDisables interpolating animations to make them smoother.");
|
||||
printf("\n\n%s \tDisables the sound system.",GAME_ARGS[GAME_ARG_DISABLE_SOUND]);
|
||||
printf("\n\n%s \tDisables the sound system.", GAME_ARGS[GAME_ARG_DISABLE_SOUND]);
|
||||
|
||||
printf("\n\n%s \tEnables using the legacy font system.",GAME_ARGS[GAME_ARG_ENABLE_LEGACYFONTS]);
|
||||
printf("\n\n%s \tEnables using the legacy font system.", GAME_ARGS[GAME_ARG_ENABLE_LEGACYFONTS]);
|
||||
|
||||
// "================================================================================"
|
||||
printf("\n\n%s=x \tOverride the video resolution.",GAME_ARGS[GAME_ARG_USE_RESOLUTION]);
|
||||
printf("\n\n%s=x \tOverride the video resolution.", GAME_ARGS[GAME_ARG_USE_RESOLUTION]);
|
||||
printf("\n\n \tWhere x is a string with the following format: 'width x height'.");
|
||||
printf("\n\n \texample: %s %s=1024x768",extractFileFromDirectoryPath(argv0).c_str(),GAME_ARGS[GAME_ARG_USE_RESOLUTION]);
|
||||
printf("\n\n \texample: %s %s=1024x768", extractFileFromDirectoryPath(argv0).c_str(), GAME_ARGS[GAME_ARG_USE_RESOLUTION]);
|
||||
|
||||
printf("\n\n%s=x \t\tOverride the video colorbits.",GAME_ARGS[GAME_ARG_USE_COLORBITS]);
|
||||
printf("\n\n%s=x \t\tOverride the video colorbits.", GAME_ARGS[GAME_ARG_USE_COLORBITS]);
|
||||
printf("\n\n \tWhere x is a valid colorbits value supported by your video");
|
||||
printf("\n\n \t driver.");
|
||||
printf("\n\n \texample: %s %s=32",extractFileFromDirectoryPath(argv0).c_str(),GAME_ARGS[GAME_ARG_USE_COLORBITS]);
|
||||
printf("\n\n \texample: %s %s=32", extractFileFromDirectoryPath(argv0).c_str(), GAME_ARGS[GAME_ARG_USE_COLORBITS]);
|
||||
|
||||
printf("\n\n%s=x \t\tOverride the video depthbits.",GAME_ARGS[GAME_ARG_USE_DEPTHBITS]);
|
||||
printf("\n\n%s=x \t\tOverride the video depthbits.", GAME_ARGS[GAME_ARG_USE_DEPTHBITS]);
|
||||
printf("\n\n \tWhere x is a valid depthbits value supported by your video");
|
||||
printf("\n\n \t driver.");
|
||||
printf("\n\n \texample: %s %s=24",extractFileFromDirectoryPath(argv0).c_str(),GAME_ARGS[GAME_ARG_USE_DEPTHBITS]);
|
||||
printf("\n\n \texample: %s %s=24", extractFileFromDirectoryPath(argv0).c_str(), GAME_ARGS[GAME_ARG_USE_DEPTHBITS]);
|
||||
|
||||
printf("\n\n%s=x \tOverride the video fullscreen mode.",GAME_ARGS[GAME_ARG_USE_FULLSCREEN]);
|
||||
printf("\n\n%s=x \tOverride the video fullscreen mode.", GAME_ARGS[GAME_ARG_USE_FULLSCREEN]);
|
||||
printf("\n\n \tWhere x either true or false.");
|
||||
printf("\n\n \texample: %s %s=true",extractFileFromDirectoryPath(argv0).c_str(),GAME_ARGS[GAME_ARG_USE_FULLSCREEN]);
|
||||
printf("\n\n \texample: %s %s=true", extractFileFromDirectoryPath(argv0).c_str(), GAME_ARGS[GAME_ARG_USE_FULLSCREEN]);
|
||||
|
||||
printf("\n\n%s=x \t\tOverride the video gamma (contrast) value.",GAME_ARGS[GAME_ARG_SET_GAMMA]);
|
||||
printf("\n\n%s=x \t\tOverride the video gamma (contrast) value.", GAME_ARGS[GAME_ARG_SET_GAMMA]);
|
||||
printf("\n\n \tWhere x is a floating point value.");
|
||||
printf("\n\n \texample: %s %s=1.5",extractFileFromDirectoryPath(argv0).c_str(),GAME_ARGS[GAME_ARG_SET_GAMMA]);
|
||||
printf("\n\n \texample: %s %s=1.5", extractFileFromDirectoryPath(argv0).c_str(), GAME_ARGS[GAME_ARG_SET_GAMMA]);
|
||||
|
||||
printf("\n\n%s=x \t\tOverride the font to use.",GAME_ARGS[GAME_ARG_USE_FONT]);
|
||||
printf("\n\n%s=x \t\tOverride the font to use.", GAME_ARGS[GAME_ARG_USE_FONT]);
|
||||
printf("\n\n \tWhere x is the path and name of a font file supported by");
|
||||
printf("\n\n \t freetype2.");
|
||||
printf("\n\n \texample:");
|
||||
printf("\n\n \t%s %s=$APPLICATIONDATAPATH/data/core/fonts/Vera.ttf",extractFileFromDirectoryPath(argv0).c_str(),GAME_ARGS[GAME_ARG_USE_FONT]);
|
||||
printf("\n\n \t%s %s=$APPLICATIONDATAPATH/data/core/fonts/Vera.ttf", extractFileFromDirectoryPath(argv0).c_str(), GAME_ARGS[GAME_ARG_USE_FONT]);
|
||||
|
||||
printf("\n\n%s=x \tOverride the font base size.",GAME_ARGS[GAME_ARG_FONT_BASESIZE]);
|
||||
printf("\n\n%s=x \tOverride the font base size.", GAME_ARGS[GAME_ARG_FONT_BASESIZE]);
|
||||
printf("\n\n \tWhere x is the numeric base font size to use.");
|
||||
printf("\n\n \texample: %s %s=5",extractFileFromDirectoryPath(argv0).c_str(),GAME_ARGS[GAME_ARG_FONT_BASESIZE]);
|
||||
printf("\n\n \texample: %s %s=5", extractFileFromDirectoryPath(argv0).c_str(), GAME_ARGS[GAME_ARG_FONT_BASESIZE]);
|
||||
|
||||
printf("\n\n%s \tDisables video playback.",GAME_ARGS[GAME_ARG_DISABLE_VIDEOS]);
|
||||
printf("\n\n%s \tDisables video playback.", GAME_ARGS[GAME_ARG_DISABLE_VIDEOS]);
|
||||
|
||||
printf("\n\n%s ",GAME_ARGS[GAME_ARG_DISABLE_OPENGL_CAPS_CHECK]);
|
||||
printf("\n\n%s ", GAME_ARGS[GAME_ARG_DISABLE_OPENGL_CAPS_CHECK]);
|
||||
printf("\n\n \tDisables opengl capability checks (for corrupt or flaky video");
|
||||
printf("\n\n \t drivers).");
|
||||
|
||||
printf("\n\n%s=x=y ",GAME_ARGS[GAME_ARG_CREATE_DATA_ARCHIVES]);
|
||||
printf("\n\n%s=x=y ", GAME_ARGS[GAME_ARG_CREATE_DATA_ARCHIVES]);
|
||||
printf("\n\n \tCompress selected game data into archives for network sharing.");
|
||||
printf("\n\n \tWhere x is one of the following data items to compress:");
|
||||
printf("\n\n \t techtrees, tilesets or all.");
|
||||
printf("\n\n \tWhere y = include_main to include main (non mod) data.");
|
||||
printf("\n\n \texample: %s %s=all",extractFileFromDirectoryPath(argv0).c_str(),GAME_ARGS[GAME_ARG_CREATE_DATA_ARCHIVES]);
|
||||
printf("\n\n \texample: %s %s=all", extractFileFromDirectoryPath(argv0).c_str(), GAME_ARGS[GAME_ARG_CREATE_DATA_ARCHIVES]);
|
||||
|
||||
printf("\n\n%s=x=y ",GAME_ARGS[GAME_ARG_STEAM]);
|
||||
printf("\n\n%s=x=y ", GAME_ARGS[GAME_ARG_STEAM]);
|
||||
printf("\n\n \tRun with Steam Client Integration.");
|
||||
|
||||
printf("\n\n%s \t\tDisplays verbose information in the console.",GAME_ARGS[GAME_ARG_VERBOSE_MODE]);
|
||||
printf("\n\n%s \t\tDisplays verbose information in the console.", GAME_ARGS[GAME_ARG_VERBOSE_MODE]);
|
||||
printf("\n\n");
|
||||
}
|
||||
|
||||
bool hasCommandArgument(int argc, char** argv,const string argName, int *foundIndex=NULL, int startLookupIndex=1,bool useArgParamLen=false) {
|
||||
bool hasCommandArgument(int argc, char** argv, const string argName, int *foundIndex = NULL, int startLookupIndex = 1, bool useArgParamLen = false) {
|
||||
bool result = false;
|
||||
|
||||
if(foundIndex != NULL) {
|
||||
if (foundIndex != NULL) {
|
||||
*foundIndex = -1;
|
||||
}
|
||||
int compareLen = (int)strlen(argName.c_str());
|
||||
int compareLen = (int) strlen(argName.c_str());
|
||||
|
||||
for(int idx = startLookupIndex; idx < argc; idx++) {
|
||||
if(useArgParamLen == true) {
|
||||
compareLen = (int)strlen(argv[idx]);
|
||||
for (int idx = startLookupIndex; idx < argc; idx++) {
|
||||
if (useArgParamLen == true) {
|
||||
compareLen = (int) strlen(argv[idx]);
|
||||
}
|
||||
if(_strnicmp(argName.c_str(),argv[idx],compareLen) == 0) {
|
||||
if (_strnicmp(argName.c_str(), argv[idx], compareLen) == 0) {
|
||||
result = true;
|
||||
if(foundIndex != NULL) {
|
||||
if (foundIndex != NULL) {
|
||||
*foundIndex = idx;
|
||||
}
|
||||
|
||||
@@ -500,87 +500,87 @@ bool hasCommandArgument(int argc, char** argv,const string argName, int *foundIn
|
||||
}
|
||||
|
||||
int mainSetup(int argc, char **argv) {
|
||||
bool haveSpecialOutputCommandLineOption = false;
|
||||
bool haveSpecialOutputCommandLineOption = false;
|
||||
|
||||
const int knownArgCount = sizeof(GAME_ARGS) / sizeof(GAME_ARGS[0]);
|
||||
if(knownArgCount != GAME_ARG_END) {
|
||||
char szBuf[8096]="";
|
||||
snprintf(szBuf,8096,"Internal arg count mismatch knownArgCount = %d, GAME_ARG_END = %d",knownArgCount,GAME_ARG_END);
|
||||
throw megaglest_runtime_error(szBuf);
|
||||
}
|
||||
const int knownArgCount = sizeof(GAME_ARGS) / sizeof(GAME_ARGS[0]);
|
||||
if (knownArgCount != GAME_ARG_END) {
|
||||
char szBuf[8096] = "";
|
||||
snprintf(szBuf, 8096, "Internal arg count mismatch knownArgCount = %d, GAME_ARG_END = %d", knownArgCount, GAME_ARG_END);
|
||||
throw megaglest_runtime_error(szBuf);
|
||||
}
|
||||
|
||||
SystemFlags::VERBOSE_MODE_ENABLED = false;
|
||||
if(hasCommandArgument(argc, argv,GAME_ARGS[GAME_ARG_VERBOSE_MODE]) == true) {
|
||||
SystemFlags::VERBOSE_MODE_ENABLED = true;
|
||||
}
|
||||
SystemFlags::VERBOSE_MODE_ENABLED = false;
|
||||
if (hasCommandArgument(argc, argv, GAME_ARGS[GAME_ARG_VERBOSE_MODE]) == true) {
|
||||
SystemFlags::VERBOSE_MODE_ENABLED = true;
|
||||
}
|
||||
|
||||
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||
if (SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line: %d]\n", __FILE__, __FUNCTION__, __LINE__);
|
||||
|
||||
|
||||
if(hasCommandArgument(argc, argv,string(GAME_ARGS[GAME_ARG_DISABLE_STREFLOP_CAPS_CHECK])) == false) {
|
||||
// Ensure at runtime that the client has SSE
|
||||
if (hasCommandArgument(argc, argv, string(GAME_ARGS[GAME_ARG_DISABLE_STREFLOP_CAPS_CHECK])) == false) {
|
||||
// Ensure at runtime that the client has SSE
|
||||
#if defined(STREFLOP_SSE)
|
||||
#if defined(WIN32)
|
||||
|
||||
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line: %d] About to validate SSE support\n",__FILE__,__FUNCTION__,__LINE__);
|
||||
if (SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line: %d] About to validate SSE support\n", __FILE__, __FUNCTION__, __LINE__);
|
||||
|
||||
int has_x64 = false;
|
||||
int has_MMX = false;
|
||||
int has_SSE = false;
|
||||
int has_SSE2 = false;
|
||||
int has_SSE3 = false;
|
||||
int has_SSSE3 = false;
|
||||
int has_SSE41 = false;
|
||||
int has_SSE42 = false;
|
||||
int has_SSE4a = false;
|
||||
int has_AVX = false;
|
||||
int has_XOP = false;
|
||||
int has_FMA3 = false;
|
||||
int has_FMA4 = false;
|
||||
int has_x64 = false;
|
||||
int has_MMX = false;
|
||||
int has_SSE = false;
|
||||
int has_SSE2 = false;
|
||||
int has_SSE3 = false;
|
||||
int has_SSSE3 = false;
|
||||
int has_SSE41 = false;
|
||||
int has_SSE42 = false;
|
||||
int has_SSE4a = false;
|
||||
int has_AVX = false;
|
||||
int has_XOP = false;
|
||||
int has_FMA3 = false;
|
||||
int has_FMA4 = false;
|
||||
|
||||
int info[4];
|
||||
__cpuid(info, 0);
|
||||
int nIds = info[0];
|
||||
int info[4];
|
||||
__cpuid(info, 0);
|
||||
int nIds = info[0];
|
||||
|
||||
__cpuid(info, 0x80000000);
|
||||
int nExIds = info[0];
|
||||
__cpuid(info, 0x80000000);
|
||||
int nExIds = info[0];
|
||||
|
||||
// Detect Instruction Set
|
||||
if (nIds >= 1){
|
||||
__cpuid(info,0x00000001);
|
||||
has_MMX = (info[3] & ((int)1 << 23)) != 0;
|
||||
has_SSE = (info[3] & ((int)1 << 25)) != 0;
|
||||
has_SSE2 = (info[3] & ((int)1 << 26)) != 0;
|
||||
has_SSE3 = (info[2] & ((int)1 << 0)) != 0;
|
||||
// Detect Instruction Set
|
||||
if (nIds >= 1) {
|
||||
__cpuid(info, 0x00000001);
|
||||
has_MMX = (info[3] & ((int) 1 << 23)) != 0;
|
||||
has_SSE = (info[3] & ((int) 1 << 25)) != 0;
|
||||
has_SSE2 = (info[3] & ((int) 1 << 26)) != 0;
|
||||
has_SSE3 = (info[2] & ((int) 1 << 0)) != 0;
|
||||
|
||||
has_SSSE3 = (info[2] & ((int)1 << 9)) != 0;
|
||||
has_SSE41 = (info[2] & ((int)1 << 19)) != 0;
|
||||
has_SSE42 = (info[2] & ((int)1 << 20)) != 0;
|
||||
has_SSSE3 = (info[2] & ((int) 1 << 9)) != 0;
|
||||
has_SSE41 = (info[2] & ((int) 1 << 19)) != 0;
|
||||
has_SSE42 = (info[2] & ((int) 1 << 20)) != 0;
|
||||
|
||||
has_AVX = (info[2] & ((int)1 << 28)) != 0;
|
||||
has_FMA3 = (info[2] & ((int)1 << 12)) != 0;
|
||||
}
|
||||
has_AVX = (info[2] & ((int) 1 << 28)) != 0;
|
||||
has_FMA3 = (info[2] & ((int) 1 << 12)) != 0;
|
||||
}
|
||||
|
||||
if (nExIds >= 0x80000001){
|
||||
__cpuid(info,0x80000001);
|
||||
has_x64 = (info[3] & ((int)1 << 29)) != 0;
|
||||
has_SSE4a = (info[2] & ((int)1 << 6)) != 0;
|
||||
has_FMA4 = (info[2] & ((int)1 << 16)) != 0;
|
||||
has_XOP = (info[2] & ((int)1 << 11)) != 0;
|
||||
}
|
||||
if (nExIds >= 0x80000001) {
|
||||
__cpuid(info, 0x80000001);
|
||||
has_x64 = (info[3] & ((int) 1 << 29)) != 0;
|
||||
has_SSE4a = (info[2] & ((int) 1 << 6)) != 0;
|
||||
has_FMA4 = (info[2] & ((int) 1 << 16)) != 0;
|
||||
has_XOP = (info[2] & ((int) 1 << 11)) != 0;
|
||||
}
|
||||
|
||||
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line: %d] sse check got [%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d]\n",__FILE__,__FUNCTION__,__LINE__,has_x64,has_MMX,has_SSE,has_SSE2,has_SSE3,has_SSSE3,has_SSE41,has_SSE42,has_SSE4a,has_AVX,has_XOP,has_FMA3,has_FMA4);
|
||||
if (SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line: %d] sse check got [%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d]\n", __FILE__, __FUNCTION__, __LINE__, has_x64, has_MMX, has_SSE, has_SSE2, has_SSE3, has_SSSE3, has_SSE41, has_SSE42, has_SSE4a, has_AVX, has_XOP, has_FMA3, has_FMA4);
|
||||
|
||||
if( has_SSE == false && has_SSE2 == false && has_SSE3 == false &&
|
||||
has_SSSE3 == false && has_SSE41 == false && has_SSE42 == false &&
|
||||
has_SSE4a == false) {
|
||||
char szBuf[8096]="";
|
||||
snprintf(szBuf,8096,"Error detected, your CPU does not seem to support SSE: [%d]\n",has_SSE);
|
||||
throw megaglest_runtime_error(szBuf);
|
||||
}
|
||||
if (has_SSE == false && has_SSE2 == false && has_SSE3 == false &&
|
||||
has_SSSE3 == false && has_SSE41 == false && has_SSE42 == false &&
|
||||
has_SSE4a == false) {
|
||||
char szBuf[8096] = "";
|
||||
snprintf(szBuf, 8096, "Error detected, your CPU does not seem to support SSE: [%d]\n", has_SSE);
|
||||
throw megaglest_runtime_error(szBuf);
|
||||
}
|
||||
#elif defined (__GNUC__) && !defined(__APPLE__)
|
||||
|
||||
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line: %d] About to validate SSE support\n",__FILE__,__FUNCTION__,__LINE__);
|
||||
if (SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line: %d] About to validate SSE support\n", __FILE__, __FUNCTION__, __LINE__);
|
||||
|
||||
#define CHECK_BIT(var,pos) ((var) & (1<<(pos)))
|
||||
|
||||
@@ -588,80 +588,79 @@ int mainSetup(int argc, char **argv) {
|
||||
__asm__ __volatile__ ("cpuid":\
|
||||
"=a" (ax), "=b" (bx), "=c" (cx), "=d" (dx) : "a" (func));
|
||||
|
||||
int ax=0,bx=0,cx=0,dx=0;
|
||||
cpuid(0x0000001,ax,bx,cx,dx)
|
||||
int ax = 0, bx = 0, cx = 0, dx = 0;
|
||||
cpuid(0x0000001, ax, bx, cx, dx)
|
||||
|
||||
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line: %d] sse check got [%d,%d,%d,%d]\n",__FILE__,__FUNCTION__,__LINE__,ax,bx,cx,dx);
|
||||
if (SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line: %d] sse check got [%d,%d,%d,%d]\n", __FILE__, __FUNCTION__, __LINE__, ax, bx, cx, dx);
|
||||
|
||||
// Check SSE, SSE2 and SSE3 support (if all 3 fail throw exception)
|
||||
if( !CHECK_BIT(dx,25) && !CHECK_BIT(dx,26) && !CHECK_BIT(cx,0) ) {
|
||||
char szBuf[8096]="";
|
||||
snprintf(szBuf,8096,"Error detected, your CPU does not seem to support SSE: [%d]\n",CHECK_BIT(dx,25));
|
||||
throw megaglest_runtime_error(szBuf);
|
||||
}
|
||||
// Check SSE, SSE2 and SSE3 support (if all 3 fail throw exception)
|
||||
if (!CHECK_BIT(dx, 25) && !CHECK_BIT(dx, 26) && !CHECK_BIT(cx, 0)) {
|
||||
char szBuf[8096] = "";
|
||||
snprintf(szBuf, 8096, "Error detected, your CPU does not seem to support SSE: [%d]\n", CHECK_BIT(dx, 25));
|
||||
throw megaglest_runtime_error(szBuf);
|
||||
}
|
||||
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
||||
if( hasCommandArgument(argc, argv,GAME_ARGS[GAME_ARG_OPENGL_INFO]) == true ||
|
||||
hasCommandArgument(argc, argv,GAME_ARGS[GAME_ARG_SDL_INFO]) == true ||
|
||||
hasCommandArgument(argc, argv,GAME_ARGS[GAME_ARG_LUA_INFO]) == true ||
|
||||
hasCommandArgument(argc, argv,GAME_ARGS[GAME_ARG_CURL_INFO]) == true ||
|
||||
hasCommandArgument(argc, argv,GAME_ARGS[GAME_ARG_XERCES_INFO]) == true ||
|
||||
hasCommandArgument(argc, argv,GAME_ARGS[GAME_ARG_VERSION]) == true ||
|
||||
hasCommandArgument(argc, argv,GAME_ARGS[GAME_ARG_SHOW_INI_SETTINGS]) == true ||
|
||||
hasCommandArgument(argc, argv,GAME_ARGS[GAME_ARG_VALIDATE_TECHTREES]) == true ||
|
||||
hasCommandArgument(argc, argv,GAME_ARGS[GAME_ARG_VALIDATE_FACTIONS]) == true ||
|
||||
hasCommandArgument(argc, argv,GAME_ARGS[GAME_ARG_VALIDATE_SCENARIO]) == true ||
|
||||
hasCommandArgument(argc, argv,GAME_ARGS[GAME_ARG_VALIDATE_TILESET]) == true ||
|
||||
hasCommandArgument(argc, argv,GAME_ARGS[GAME_ARG_LIST_MAPS]) == true ||
|
||||
hasCommandArgument(argc, argv,GAME_ARGS[GAME_ARG_LIST_TECHTRESS]) == true ||
|
||||
hasCommandArgument(argc, argv,GAME_ARGS[GAME_ARG_LIST_SCENARIOS]) == true ||
|
||||
hasCommandArgument(argc, argv,GAME_ARGS[GAME_ARG_LIST_TILESETS]) == true ||
|
||||
hasCommandArgument(argc, argv,GAME_ARGS[GAME_ARG_LIST_TUTORIALS]) == true) {
|
||||
if (hasCommandArgument(argc, argv, GAME_ARGS[GAME_ARG_OPENGL_INFO]) == true ||
|
||||
hasCommandArgument(argc, argv, GAME_ARGS[GAME_ARG_SDL_INFO]) == true ||
|
||||
hasCommandArgument(argc, argv, GAME_ARGS[GAME_ARG_LUA_INFO]) == true ||
|
||||
hasCommandArgument(argc, argv, GAME_ARGS[GAME_ARG_CURL_INFO]) == true ||
|
||||
hasCommandArgument(argc, argv, GAME_ARGS[GAME_ARG_XERCES_INFO]) == true ||
|
||||
hasCommandArgument(argc, argv, GAME_ARGS[GAME_ARG_VERSION]) == true ||
|
||||
hasCommandArgument(argc, argv, GAME_ARGS[GAME_ARG_SHOW_INI_SETTINGS]) == true ||
|
||||
hasCommandArgument(argc, argv, GAME_ARGS[GAME_ARG_VALIDATE_TECHTREES]) == true ||
|
||||
hasCommandArgument(argc, argv, GAME_ARGS[GAME_ARG_VALIDATE_FACTIONS]) == true ||
|
||||
hasCommandArgument(argc, argv, GAME_ARGS[GAME_ARG_VALIDATE_SCENARIO]) == true ||
|
||||
hasCommandArgument(argc, argv, GAME_ARGS[GAME_ARG_VALIDATE_TILESET]) == true ||
|
||||
hasCommandArgument(argc, argv, GAME_ARGS[GAME_ARG_LIST_MAPS]) == true ||
|
||||
hasCommandArgument(argc, argv, GAME_ARGS[GAME_ARG_LIST_TECHTRESS]) == true ||
|
||||
hasCommandArgument(argc, argv, GAME_ARGS[GAME_ARG_LIST_SCENARIOS]) == true ||
|
||||
hasCommandArgument(argc, argv, GAME_ARGS[GAME_ARG_LIST_TILESETS]) == true ||
|
||||
hasCommandArgument(argc, argv, GAME_ARGS[GAME_ARG_LIST_TUTORIALS]) == true) {
|
||||
haveSpecialOutputCommandLineOption = true;
|
||||
}
|
||||
|
||||
if( haveSpecialOutputCommandLineOption == false) {
|
||||
if (haveSpecialOutputCommandLineOption == false) {
|
||||
#ifdef USE_STREFLOP
|
||||
#define STREFLOP_NO_DENORMALS
|
||||
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||
if (SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line: %d]\n", __FILE__, __FUNCTION__, __LINE__);
|
||||
|
||||
streflop_init<streflop::Simple>();
|
||||
streflop_init<streflop::Simple>();
|
||||
|
||||
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||
if (SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line: %d]\n", __FILE__, __FUNCTION__, __LINE__);
|
||||
#endif
|
||||
}
|
||||
|
||||
if(hasCommandArgument(argc, argv,string(GAME_ARGS[GAME_ARG_HELP])) == true ||
|
||||
hasCommandArgument(argc, argv,string(GAME_ARGS[GAME_ARG_VERSION])) == true ||
|
||||
hasCommandArgument(argc, argv,string(GAME_ARGS[GAME_ARG_SHOW_INI_SETTINGS])) == true ||
|
||||
hasCommandArgument(argc, argv,string(GAME_ARGS[GAME_ARG_MASTERSERVER_MODE])) == true ||
|
||||
hasCommandArgument(argc, argv,string(GAME_ARGS[GAME_ARG_MASTERSERVER_STATUS]))) {
|
||||
// Use this for masterserver mode for timers like Chrono
|
||||
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||
if (hasCommandArgument(argc, argv, string(GAME_ARGS[GAME_ARG_HELP])) == true ||
|
||||
hasCommandArgument(argc, argv, string(GAME_ARGS[GAME_ARG_VERSION])) == true ||
|
||||
hasCommandArgument(argc, argv, string(GAME_ARGS[GAME_ARG_SHOW_INI_SETTINGS])) == true ||
|
||||
hasCommandArgument(argc, argv, string(GAME_ARGS[GAME_ARG_MASTERSERVER_MODE])) == true ||
|
||||
hasCommandArgument(argc, argv, string(GAME_ARGS[GAME_ARG_MASTERSERVER_STATUS]))) {
|
||||
// Use this for masterserver mode for timers like Chrono
|
||||
if (SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line: %d]\n", __FILE__, __FUNCTION__, __LINE__);
|
||||
|
||||
if(SDL_Init(SDL_INIT_TIMER) < 0) {
|
||||
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||
std::cerr << "Couldn't initialize SDL: " << SDL_GetError() << "\n";
|
||||
return 3;
|
||||
}
|
||||
}
|
||||
else {
|
||||
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||
if(SDL_Init(SDL_INIT_TIMER | SDL_INIT_AUDIO | SDL_INIT_VIDEO | SDL_INIT_JOYSTICK | \
|
||||
SDL_INIT_GAMECONTROLLER | SDL_INIT_EVENTS) < 0) {
|
||||
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||
if (SDL_Init(SDL_INIT_TIMER) < 0) {
|
||||
if (SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line: %d]\n", __FILE__, __FUNCTION__, __LINE__);
|
||||
std::cerr << "Couldn't initialize SDL: " << SDL_GetError() << "\n";
|
||||
return 3;
|
||||
}
|
||||
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||
//SDL_EnableUNICODE(1);
|
||||
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||
//SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL);
|
||||
}
|
||||
} else {
|
||||
if (SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line: %d]\n", __FILE__, __FUNCTION__, __LINE__);
|
||||
if (SDL_Init(SDL_INIT_TIMER | SDL_INIT_AUDIO | SDL_INIT_VIDEO | SDL_INIT_JOYSTICK | \
|
||||
SDL_INIT_GAMECONTROLLER | SDL_INIT_EVENTS) < 0) {
|
||||
if (SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line: %d]\n", __FILE__, __FUNCTION__, __LINE__);
|
||||
std::cerr << "Couldn't initialize SDL: " << SDL_GetError() << "\n";
|
||||
return 3;
|
||||
}
|
||||
if (SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line: %d]\n", __FILE__, __FUNCTION__, __LINE__);
|
||||
//SDL_EnableUNICODE(1);
|
||||
if (SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line: %d]\n", __FILE__, __FUNCTION__, __LINE__);
|
||||
//SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL);
|
||||
}
|
||||
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||
if (SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line: %d]\n", __FILE__, __FUNCTION__, __LINE__);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@@ -16,13 +16,17 @@
|
||||
|
||||
#include "leak_dumper.h"
|
||||
|
||||
namespace Shared{ namespace PlatformCommon { namespace Private {
|
||||
namespace Shared {
|
||||
namespace PlatformCommon {
|
||||
namespace Private {
|
||||
|
||||
extern bool shouldBeFullscreen;
|
||||
extern int ScreenWidth;
|
||||
extern int ScreenHeight;
|
||||
extern bool shouldBeFullscreen;
|
||||
extern int ScreenWidth;
|
||||
extern int ScreenHeight;
|
||||
|
||||
}}}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
@@ -38,503 +38,519 @@ using namespace std;
|
||||
using namespace Shared::PlatformCommon;
|
||||
#endif
|
||||
|
||||
namespace Shared { namespace PlatformCommon {
|
||||
class Chrono;
|
||||
}};
|
||||
|
||||
namespace Shared { namespace Platform {
|
||||
|
||||
class Mutex;
|
||||
//class uint32;
|
||||
|
||||
enum ThreadState {
|
||||
thrsNew,
|
||||
thrsStarting,
|
||||
thrsExecuteStart,
|
||||
thrsExecuting,
|
||||
thrsExecuted,
|
||||
thrsExecuteAutoClean,
|
||||
thrsExecuteComplete
|
||||
|
||||
namespace Shared {
|
||||
namespace PlatformCommon {
|
||||
class Chrono;
|
||||
}
|
||||
};
|
||||
|
||||
class Thread {
|
||||
public:
|
||||
enum Priority {
|
||||
pIdle = 0,
|
||||
pLow = 1,
|
||||
pNormal = 2,
|
||||
pHigh = 3,
|
||||
pRealTime = 4
|
||||
};
|
||||
namespace Shared {
|
||||
namespace Platform {
|
||||
|
||||
private:
|
||||
SDL_Thread* thread;
|
||||
//std::auto_ptr<Mutex> mutexthreadAccessor;
|
||||
Mutex *mutexthreadAccessor;
|
||||
ThreadState currentState;
|
||||
bool threadObjectValid();
|
||||
class Mutex;
|
||||
//class uint32;
|
||||
|
||||
bool deleteAfterExecute;
|
||||
static Mutex mutexthreadList;
|
||||
static vector<Thread *> threadList;
|
||||
static bool enableVerboseMode;
|
||||
static unsigned long mainThreadId;
|
||||
enum ThreadState {
|
||||
thrsNew,
|
||||
thrsStarting,
|
||||
thrsExecuteStart,
|
||||
thrsExecuting,
|
||||
thrsExecuted,
|
||||
thrsExecuteAutoClean,
|
||||
thrsExecuteComplete
|
||||
|
||||
protected:
|
||||
void addThreadToList();
|
||||
void removeThreadFromList();
|
||||
void queueAutoCleanThread();
|
||||
bool isThreadExecuteCompleteStatus();
|
||||
};
|
||||
|
||||
public:
|
||||
Thread();
|
||||
virtual ~Thread();
|
||||
class Thread {
|
||||
public:
|
||||
enum Priority {
|
||||
pIdle = 0,
|
||||
pLow = 1,
|
||||
pNormal = 2,
|
||||
pHigh = 3,
|
||||
pRealTime = 4
|
||||
};
|
||||
|
||||
static unsigned long getCurrentThreadId();
|
||||
static unsigned long getMainThreadId() { return mainThreadId; }
|
||||
static void setMainThreadId();
|
||||
static bool isCurrentThreadMainThread();
|
||||
private:
|
||||
SDL_Thread* thread;
|
||||
//std::auto_ptr<Mutex> mutexthreadAccessor;
|
||||
Mutex *mutexthreadAccessor;
|
||||
ThreadState currentState;
|
||||
bool threadObjectValid();
|
||||
|
||||
static void setEnableVerboseMode(bool value) { enableVerboseMode = value; }
|
||||
static bool getEnableVerboseMode() { return enableVerboseMode; }
|
||||
bool deleteAfterExecute;
|
||||
static Mutex mutexthreadList;
|
||||
static vector<Thread *> threadList;
|
||||
static bool enableVerboseMode;
|
||||
static unsigned long mainThreadId;
|
||||
|
||||
static std::vector<Thread *> getThreadList();
|
||||
static void shutdownThreads();
|
||||
protected:
|
||||
void addThreadToList();
|
||||
void removeThreadFromList();
|
||||
void queueAutoCleanThread();
|
||||
bool isThreadExecuteCompleteStatus();
|
||||
|
||||
void setDeleteAfterExecute(bool value) { deleteAfterExecute = value; }
|
||||
bool getDeleteAfterExecute() const { return deleteAfterExecute; }
|
||||
public:
|
||||
Thread();
|
||||
virtual ~Thread();
|
||||
|
||||
void start();
|
||||
virtual void execute()=0;
|
||||
void setPriority(Thread::Priority threadPriority);
|
||||
void suspend();
|
||||
void resume();
|
||||
void kill();
|
||||
static unsigned long getCurrentThreadId();
|
||||
static unsigned long getMainThreadId() {
|
||||
return mainThreadId;
|
||||
}
|
||||
static void setMainThreadId();
|
||||
static bool isCurrentThreadMainThread();
|
||||
|
||||
private:
|
||||
static int beginExecution(void *param);
|
||||
};
|
||||
|
||||
// =====================================================
|
||||
// class Mutex
|
||||
// =====================================================
|
||||
|
||||
class Mutex {
|
||||
private:
|
||||
|
||||
SDL_mutex* mutex;
|
||||
int refCount;
|
||||
string ownerId;
|
||||
string deleteownerId;
|
||||
|
||||
SDL_mutex* mutexAccessor;
|
||||
string lastownerId;
|
||||
|
||||
int maxRefCount;
|
||||
Shared::PlatformCommon::Chrono *chronoPerf;
|
||||
|
||||
bool isStaticMutexListMutex;
|
||||
static auto_ptr<Mutex> mutexMutexList;
|
||||
static vector<Mutex *> mutexList;
|
||||
|
||||
public:
|
||||
Mutex(string ownerId="");
|
||||
~Mutex();
|
||||
inline void setOwnerId(string ownerId) {
|
||||
if(this->ownerId != ownerId) {
|
||||
this->ownerId = ownerId;
|
||||
}
|
||||
}
|
||||
inline void p() {
|
||||
SDL_LockMutex(mutex);
|
||||
refCount++;
|
||||
}
|
||||
// Returns return 0, SDL_MUTEX_TIMEDOUT, or -1 on error;
|
||||
// call SDL_GetError() for more information.
|
||||
inline int TryLock(int millisecondsToWait=0) {
|
||||
int result = SDL_TryLockMutex(mutex);
|
||||
if(result == 0) {
|
||||
refCount++;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
inline void v() {
|
||||
refCount--;
|
||||
SDL_UnlockMutex(mutex);
|
||||
}
|
||||
inline int getRefCount() const { return refCount; }
|
||||
|
||||
inline SDL_mutex* getMutex() { return mutex; }
|
||||
};
|
||||
|
||||
class MutexSafeWrapper {
|
||||
protected:
|
||||
Mutex *mutex;
|
||||
string ownerId;
|
||||
#ifdef DEBUG_PERFORMANCE_MUTEXES
|
||||
Chrono chrono;
|
||||
#endif
|
||||
|
||||
public:
|
||||
|
||||
MutexSafeWrapper(Mutex *mutex,string ownerId="") {
|
||||
this->mutex = mutex;
|
||||
if(this->ownerId != ownerId) {
|
||||
this->ownerId = ownerId;
|
||||
}
|
||||
Lock();
|
||||
}
|
||||
~MutexSafeWrapper() {
|
||||
ReleaseLock();
|
||||
}
|
||||
|
||||
inline void setMutex(Mutex *mutex,string ownerId="") {
|
||||
this->mutex = mutex;
|
||||
if(this->ownerId != ownerId) {
|
||||
this->ownerId = ownerId;
|
||||
}
|
||||
Lock();
|
||||
}
|
||||
inline int setMutexAndTryLock(Mutex *mutex,string ownerId="") {
|
||||
this->mutex = mutex;
|
||||
if(this->ownerId != ownerId) {
|
||||
this->ownerId = ownerId;
|
||||
}
|
||||
return this->mutex->TryLock();
|
||||
}
|
||||
|
||||
inline bool isValidMutex() const {
|
||||
return(this->mutex != NULL);
|
||||
}
|
||||
|
||||
inline void Lock() {
|
||||
if(this->mutex != NULL) {
|
||||
#ifdef DEBUG_MUTEXES
|
||||
if(this->ownerId != "") {
|
||||
printf("Locking Mutex [%s] refCount: %d\n",this->ownerId.c_str(),this->mutex->getRefCount());
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef DEBUG_PERFORMANCE_MUTEXES
|
||||
chrono.start();
|
||||
#endif
|
||||
|
||||
this->mutex->p();
|
||||
if(this->mutex != NULL) {
|
||||
this->mutex->setOwnerId(ownerId);
|
||||
static void setEnableVerboseMode(bool value) {
|
||||
enableVerboseMode = value;
|
||||
}
|
||||
static bool getEnableVerboseMode() {
|
||||
return enableVerboseMode;
|
||||
}
|
||||
|
||||
#ifdef DEBUG_PERFORMANCE_MUTEXES
|
||||
if(chrono.getMillis() > 5) printf("In [%s::%s Line: %d] MUTEX LOCK took msecs: %lld, this->mutex->getRefCount() = %d ownerId [%s]\n",__FILE__,__FUNCTION__,__LINE__,(long long int)chrono.getMillis(),this->mutex->getRefCount(),ownerId.c_str());
|
||||
chrono.start();
|
||||
#endif
|
||||
static std::vector<Thread *> getThreadList();
|
||||
static void shutdownThreads();
|
||||
|
||||
#ifdef DEBUG_MUTEXES
|
||||
if(this->ownerId != "") {
|
||||
printf("Locked Mutex [%s] refCount: %d\n",this->ownerId.c_str(),this->mutex->getRefCount());
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
inline int TryLock(int millisecondsToWait=0) {
|
||||
if(this->mutex != NULL) {
|
||||
#ifdef DEBUG_MUTEXES
|
||||
if(this->ownerId != "") {
|
||||
printf("TryLocking Mutex [%s] refCount: %d\n",this->ownerId.c_str(),this->mutex->getRefCount());
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef DEBUG_PERFORMANCE_MUTEXES
|
||||
chrono.start();
|
||||
#endif
|
||||
|
||||
int result = this->mutex->TryLock(millisecondsToWait);
|
||||
if(result == 0 && this->mutex != NULL) {
|
||||
this->mutex->setOwnerId(ownerId);
|
||||
void setDeleteAfterExecute(bool value) {
|
||||
deleteAfterExecute = value;
|
||||
}
|
||||
bool getDeleteAfterExecute() const {
|
||||
return deleteAfterExecute;
|
||||
}
|
||||
|
||||
#ifdef DEBUG_PERFORMANCE_MUTEXES
|
||||
if(chrono.getMillis() > 5) printf("In [%s::%s Line: %d] MUTEX LOCK took msecs: %lld, this->mutex->getRefCount() = %d ownerId [%s]\n",__FILE__,__FUNCTION__,__LINE__,(long long int)chrono.getMillis(),this->mutex->getRefCount(),ownerId.c_str());
|
||||
chrono.start();
|
||||
#endif
|
||||
void start();
|
||||
virtual void execute() = 0;
|
||||
void setPriority(Thread::Priority threadPriority);
|
||||
void suspend();
|
||||
void resume();
|
||||
void kill();
|
||||
|
||||
#ifdef DEBUG_MUTEXES
|
||||
if(this->ownerId != "") {
|
||||
printf("Locked Mutex [%s] refCount: %d\n",this->ownerId.c_str(),this->mutex->getRefCount());
|
||||
}
|
||||
#endif
|
||||
private:
|
||||
static int beginExecution(void *param);
|
||||
};
|
||||
|
||||
return result;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
// =====================================================
|
||||
// class Mutex
|
||||
// =====================================================
|
||||
|
||||
inline void ReleaseLock(bool keepMutex=false,bool deleteMutexOnRelease=false) {
|
||||
if(this->mutex != NULL) {
|
||||
#ifdef DEBUG_MUTEXES
|
||||
if(this->ownerId != "") {
|
||||
printf("UnLocking Mutex [%s] refCount: %d\n",this->ownerId.c_str(),this->mutex->getRefCount());
|
||||
}
|
||||
#endif
|
||||
class Mutex {
|
||||
private:
|
||||
|
||||
this->mutex->v();
|
||||
SDL_mutex* mutex;
|
||||
int refCount;
|
||||
string ownerId;
|
||||
string deleteownerId;
|
||||
|
||||
#ifdef DEBUG_PERFORMANCE_MUTEXES
|
||||
if(chrono.getMillis() > 100) printf("In [%s::%s Line: %d] MUTEX UNLOCKED and held locked for msecs: %lld, this->mutex->getRefCount() = %d ownerId [%s]\n",__FILE__,__FUNCTION__,__LINE__,(long long int)chrono.getMillis(),this->mutex->getRefCount(),ownerId.c_str());
|
||||
#endif
|
||||
SDL_mutex* mutexAccessor;
|
||||
string lastownerId;
|
||||
|
||||
#ifdef DEBUG_MUTEXES
|
||||
if(this->ownerId != "") {
|
||||
printf("UnLocked Mutex [%s] refCount: %d\n",this->ownerId.c_str(),this->mutex->getRefCount());
|
||||
}
|
||||
#endif
|
||||
int maxRefCount;
|
||||
Shared::PlatformCommon::Chrono *chronoPerf;
|
||||
|
||||
if(deleteMutexOnRelease == true) {
|
||||
delete this->mutex;
|
||||
this->mutex = NULL;
|
||||
bool isStaticMutexListMutex;
|
||||
static auto_ptr<Mutex> mutexMutexList;
|
||||
static vector<Mutex *> mutexList;
|
||||
|
||||
public:
|
||||
Mutex(string ownerId = "");
|
||||
~Mutex();
|
||||
inline void setOwnerId(string ownerId) {
|
||||
if (this->ownerId != ownerId) {
|
||||
this->ownerId = ownerId;
|
||||
}
|
||||
}
|
||||
inline void p() {
|
||||
SDL_LockMutex(mutex);
|
||||
refCount++;
|
||||
}
|
||||
// Returns return 0, SDL_MUTEX_TIMEDOUT, or -1 on error;
|
||||
// call SDL_GetError() for more information.
|
||||
inline int TryLock(int millisecondsToWait = 0) {
|
||||
int result = SDL_TryLockMutex(mutex);
|
||||
if (result == 0) {
|
||||
refCount++;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
inline void v() {
|
||||
refCount--;
|
||||
SDL_UnlockMutex(mutex);
|
||||
}
|
||||
inline int getRefCount() const {
|
||||
return refCount;
|
||||
}
|
||||
|
||||
if(keepMutex == false) {
|
||||
this->mutex = NULL;
|
||||
inline SDL_mutex* getMutex() {
|
||||
return mutex;
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// =====================================================
|
||||
// class Semaphore
|
||||
// =====================================================
|
||||
|
||||
class Semaphore {
|
||||
private:
|
||||
SDL_sem* semaphore;
|
||||
|
||||
public:
|
||||
Semaphore(Uint32 initialValue = 0);
|
||||
~Semaphore();
|
||||
void signal();
|
||||
int waitTillSignalled(int waitMilliseconds=-1);
|
||||
bool tryDecrement();
|
||||
|
||||
uint32 getSemValue();
|
||||
void resetSemValue(Uint32 initialValue);
|
||||
};
|
||||
|
||||
|
||||
class ReadWriteMutex
|
||||
{
|
||||
public:
|
||||
ReadWriteMutex(int maxReaders = 32);
|
||||
|
||||
void LockRead();
|
||||
void UnLockRead();
|
||||
|
||||
void LockWrite();
|
||||
void UnLockWrite();
|
||||
|
||||
int maxReaders();
|
||||
void setOwnerId(string ownerId) {
|
||||
if(this->ownerId != ownerId) {
|
||||
this->ownerId = ownerId;
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
Semaphore semaphore;
|
||||
Mutex mutex;
|
||||
int maxReadersCount;
|
||||
|
||||
string ownerId;
|
||||
};
|
||||
|
||||
|
||||
class ReadWriteMutexSafeWrapper {
|
||||
protected:
|
||||
ReadWriteMutex *mutex;
|
||||
string ownerId;
|
||||
bool isReadLock;
|
||||
};
|
||||
|
||||
class MutexSafeWrapper {
|
||||
protected:
|
||||
Mutex *mutex;
|
||||
string ownerId;
|
||||
#ifdef DEBUG_PERFORMANCE_MUTEXES
|
||||
Chrono chrono;
|
||||
Chrono chrono;
|
||||
#endif
|
||||
|
||||
public:
|
||||
public:
|
||||
|
||||
ReadWriteMutexSafeWrapper(ReadWriteMutex *mutex,bool isReadLock=true, string ownerId="") {
|
||||
this->mutex = mutex;
|
||||
if(this->isReadLock != isReadLock) {
|
||||
this->isReadLock = isReadLock;
|
||||
}
|
||||
if(this->ownerId != ownerId) {
|
||||
this->ownerId = ownerId;
|
||||
}
|
||||
Lock();
|
||||
}
|
||||
~ReadWriteMutexSafeWrapper() {
|
||||
ReleaseLock();
|
||||
}
|
||||
|
||||
void setReadWriteMutex(ReadWriteMutex *mutex,bool isReadLock=true,string ownerId="") {
|
||||
this->mutex = mutex;
|
||||
if(this->isReadLock != isReadLock) {
|
||||
this->isReadLock = isReadLock;
|
||||
}
|
||||
if(this->ownerId != ownerId) {
|
||||
this->ownerId = ownerId;
|
||||
}
|
||||
Lock();
|
||||
}
|
||||
bool isValidReadWriteMutex() const {
|
||||
return(this->mutex != NULL);
|
||||
}
|
||||
|
||||
void Lock() {
|
||||
if(this->mutex != NULL) {
|
||||
#ifdef DEBUG_MUTEXES
|
||||
if(this->ownerId != "") {
|
||||
printf("Locking Mutex [%s] refCount: %d\n",this->ownerId.c_str(),this->mutex->getRefCount());
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef DEBUG_PERFORMANCE_MUTEXES
|
||||
chrono.start();
|
||||
#endif
|
||||
|
||||
if(this->isReadLock == true) {
|
||||
this->mutex->LockRead();
|
||||
}
|
||||
else {
|
||||
this->mutex->LockWrite();
|
||||
}
|
||||
|
||||
#ifdef DEBUG_PERFORMANCE_MUTEXES
|
||||
if(chrono.getMillis() > 5) printf("In [%s::%s Line: %d] MUTEX LOCK took msecs: %lld, this->mutex->getRefCount() = %d ownerId [%s]\n",__FILE__,__FUNCTION__,__LINE__,(long long int)chrono.getMillis(),this->mutex->getRefCount(),ownerId.c_str());
|
||||
chrono.start();
|
||||
#endif
|
||||
|
||||
#ifdef DEBUG_MUTEXES
|
||||
if(this->ownerId != "") {
|
||||
printf("Locked Mutex [%s] refCount: %d\n",this->ownerId.c_str(),this->mutex->getRefCount());
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
void ReleaseLock(bool keepMutex=false) {
|
||||
if(this->mutex != NULL) {
|
||||
#ifdef DEBUG_MUTEXES
|
||||
if(this->ownerId != "") {
|
||||
printf("UnLocking Mutex [%s] refCount: %d\n",this->ownerId.c_str(),this->mutex->getRefCount());
|
||||
}
|
||||
#endif
|
||||
|
||||
if(this->isReadLock == true) {
|
||||
this->mutex->UnLockRead();
|
||||
}
|
||||
else {
|
||||
this->mutex->UnLockWrite();
|
||||
}
|
||||
|
||||
#ifdef DEBUG_PERFORMANCE_MUTEXES
|
||||
if(chrono.getMillis() > 100) printf("In [%s::%s Line: %d] MUTEX UNLOCKED and held locked for msecs: %lld, this->mutex->getRefCount() = %d ownerId [%s]\n",__FILE__,__FUNCTION__,__LINE__,(long long int)chrono.getMillis(),this->mutex->getRefCount(),ownerId.c_str());
|
||||
#endif
|
||||
|
||||
#ifdef DEBUG_MUTEXES
|
||||
if(this->ownerId != "") {
|
||||
printf("UnLocked Mutex [%s] refCount: %d\n",this->ownerId.c_str(),this->mutex->getRefCount());
|
||||
}
|
||||
#endif
|
||||
|
||||
if(keepMutex == false) {
|
||||
this->mutex = NULL;
|
||||
MutexSafeWrapper(Mutex *mutex, string ownerId = "") {
|
||||
this->mutex = mutex;
|
||||
if (this->ownerId != ownerId) {
|
||||
this->ownerId = ownerId;
|
||||
}
|
||||
Lock();
|
||||
}
|
||||
}
|
||||
~MutexSafeWrapper() {
|
||||
ReleaseLock();
|
||||
}
|
||||
|
||||
inline void setMutex(Mutex *mutex, string ownerId = "") {
|
||||
this->mutex = mutex;
|
||||
if (this->ownerId != ownerId) {
|
||||
this->ownerId = ownerId;
|
||||
}
|
||||
Lock();
|
||||
}
|
||||
inline int setMutexAndTryLock(Mutex *mutex, string ownerId = "") {
|
||||
this->mutex = mutex;
|
||||
if (this->ownerId != ownerId) {
|
||||
this->ownerId = ownerId;
|
||||
}
|
||||
return this->mutex->TryLock();
|
||||
}
|
||||
|
||||
inline bool isValidMutex() const {
|
||||
return(this->mutex != NULL);
|
||||
}
|
||||
|
||||
inline void Lock() {
|
||||
if (this->mutex != NULL) {
|
||||
#ifdef DEBUG_MUTEXES
|
||||
if (this->ownerId != "") {
|
||||
printf("Locking Mutex [%s] refCount: %d\n", this->ownerId.c_str(), this->mutex->getRefCount());
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef DEBUG_PERFORMANCE_MUTEXES
|
||||
chrono.start();
|
||||
#endif
|
||||
|
||||
this->mutex->p();
|
||||
if (this->mutex != NULL) {
|
||||
this->mutex->setOwnerId(ownerId);
|
||||
}
|
||||
|
||||
#ifdef DEBUG_PERFORMANCE_MUTEXES
|
||||
if (chrono.getMillis() > 5) printf("In [%s::%s Line: %d] MUTEX LOCK took msecs: %lld, this->mutex->getRefCount() = %d ownerId [%s]\n", __FILE__, __FUNCTION__, __LINE__, (long long int)chrono.getMillis(), this->mutex->getRefCount(), ownerId.c_str());
|
||||
chrono.start();
|
||||
#endif
|
||||
|
||||
#ifdef DEBUG_MUTEXES
|
||||
if (this->ownerId != "") {
|
||||
printf("Locked Mutex [%s] refCount: %d\n", this->ownerId.c_str(), this->mutex->getRefCount());
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
inline int TryLock(int millisecondsToWait = 0) {
|
||||
if (this->mutex != NULL) {
|
||||
#ifdef DEBUG_MUTEXES
|
||||
if (this->ownerId != "") {
|
||||
printf("TryLocking Mutex [%s] refCount: %d\n", this->ownerId.c_str(), this->mutex->getRefCount());
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef DEBUG_PERFORMANCE_MUTEXES
|
||||
chrono.start();
|
||||
#endif
|
||||
|
||||
int result = this->mutex->TryLock(millisecondsToWait);
|
||||
if (result == 0 && this->mutex != NULL) {
|
||||
this->mutex->setOwnerId(ownerId);
|
||||
}
|
||||
|
||||
#ifdef DEBUG_PERFORMANCE_MUTEXES
|
||||
if (chrono.getMillis() > 5) printf("In [%s::%s Line: %d] MUTEX LOCK took msecs: %lld, this->mutex->getRefCount() = %d ownerId [%s]\n", __FILE__, __FUNCTION__, __LINE__, (long long int)chrono.getMillis(), this->mutex->getRefCount(), ownerId.c_str());
|
||||
chrono.start();
|
||||
#endif
|
||||
|
||||
#ifdef DEBUG_MUTEXES
|
||||
if (this->ownerId != "") {
|
||||
printf("Locked Mutex [%s] refCount: %d\n", this->ownerId.c_str(), this->mutex->getRefCount());
|
||||
}
|
||||
#endif
|
||||
|
||||
return result;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
inline void ReleaseLock(bool keepMutex = false, bool deleteMutexOnRelease = false) {
|
||||
if (this->mutex != NULL) {
|
||||
#ifdef DEBUG_MUTEXES
|
||||
if (this->ownerId != "") {
|
||||
printf("UnLocking Mutex [%s] refCount: %d\n", this->ownerId.c_str(), this->mutex->getRefCount());
|
||||
}
|
||||
#endif
|
||||
|
||||
this->mutex->v();
|
||||
|
||||
#ifdef DEBUG_PERFORMANCE_MUTEXES
|
||||
if (chrono.getMillis() > 100) printf("In [%s::%s Line: %d] MUTEX UNLOCKED and held locked for msecs: %lld, this->mutex->getRefCount() = %d ownerId [%s]\n", __FILE__, __FUNCTION__, __LINE__, (long long int)chrono.getMillis(), this->mutex->getRefCount(), ownerId.c_str());
|
||||
#endif
|
||||
|
||||
#ifdef DEBUG_MUTEXES
|
||||
if (this->ownerId != "") {
|
||||
printf("UnLocked Mutex [%s] refCount: %d\n", this->ownerId.c_str(), this->mutex->getRefCount());
|
||||
}
|
||||
#endif
|
||||
|
||||
if (deleteMutexOnRelease == true) {
|
||||
delete this->mutex;
|
||||
this->mutex = NULL;
|
||||
}
|
||||
|
||||
if (keepMutex == false) {
|
||||
this->mutex = NULL;
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// =====================================================
|
||||
// class Semaphore
|
||||
// =====================================================
|
||||
|
||||
class Semaphore {
|
||||
private:
|
||||
SDL_sem* semaphore;
|
||||
|
||||
public:
|
||||
Semaphore(Uint32 initialValue = 0);
|
||||
~Semaphore();
|
||||
void signal();
|
||||
int waitTillSignalled(int waitMilliseconds = -1);
|
||||
bool tryDecrement();
|
||||
|
||||
uint32 getSemValue();
|
||||
void resetSemValue(Uint32 initialValue);
|
||||
};
|
||||
|
||||
|
||||
class ReadWriteMutex {
|
||||
public:
|
||||
ReadWriteMutex(int maxReaders = 32);
|
||||
|
||||
void LockRead();
|
||||
void UnLockRead();
|
||||
|
||||
void LockWrite();
|
||||
void UnLockWrite();
|
||||
|
||||
int maxReaders();
|
||||
void setOwnerId(string ownerId) {
|
||||
if (this->ownerId != ownerId) {
|
||||
this->ownerId = ownerId;
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
Semaphore semaphore;
|
||||
Mutex mutex;
|
||||
int maxReadersCount;
|
||||
|
||||
string ownerId;
|
||||
};
|
||||
|
||||
|
||||
class ReadWriteMutexSafeWrapper {
|
||||
protected:
|
||||
ReadWriteMutex *mutex;
|
||||
string ownerId;
|
||||
bool isReadLock;
|
||||
|
||||
#ifdef DEBUG_PERFORMANCE_MUTEXES
|
||||
Chrono chrono;
|
||||
#endif
|
||||
|
||||
public:
|
||||
|
||||
ReadWriteMutexSafeWrapper(ReadWriteMutex *mutex, bool isReadLock = true, string ownerId = "") {
|
||||
this->mutex = mutex;
|
||||
if (this->isReadLock != isReadLock) {
|
||||
this->isReadLock = isReadLock;
|
||||
}
|
||||
if (this->ownerId != ownerId) {
|
||||
this->ownerId = ownerId;
|
||||
}
|
||||
Lock();
|
||||
}
|
||||
~ReadWriteMutexSafeWrapper() {
|
||||
ReleaseLock();
|
||||
}
|
||||
|
||||
void setReadWriteMutex(ReadWriteMutex *mutex, bool isReadLock = true, string ownerId = "") {
|
||||
this->mutex = mutex;
|
||||
if (this->isReadLock != isReadLock) {
|
||||
this->isReadLock = isReadLock;
|
||||
}
|
||||
if (this->ownerId != ownerId) {
|
||||
this->ownerId = ownerId;
|
||||
}
|
||||
Lock();
|
||||
}
|
||||
bool isValidReadWriteMutex() const {
|
||||
return(this->mutex != NULL);
|
||||
}
|
||||
|
||||
void Lock() {
|
||||
if (this->mutex != NULL) {
|
||||
#ifdef DEBUG_MUTEXES
|
||||
if (this->ownerId != "") {
|
||||
printf("Locking Mutex [%s] refCount: %d\n", this->ownerId.c_str(), this->mutex->getRefCount());
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef DEBUG_PERFORMANCE_MUTEXES
|
||||
chrono.start();
|
||||
#endif
|
||||
|
||||
if (this->isReadLock == true) {
|
||||
this->mutex->LockRead();
|
||||
} else {
|
||||
this->mutex->LockWrite();
|
||||
}
|
||||
|
||||
#ifdef DEBUG_PERFORMANCE_MUTEXES
|
||||
if (chrono.getMillis() > 5) printf("In [%s::%s Line: %d] MUTEX LOCK took msecs: %lld, this->mutex->getRefCount() = %d ownerId [%s]\n", __FILE__, __FUNCTION__, __LINE__, (long long int)chrono.getMillis(), this->mutex->getRefCount(), ownerId.c_str());
|
||||
chrono.start();
|
||||
#endif
|
||||
|
||||
#ifdef DEBUG_MUTEXES
|
||||
if (this->ownerId != "") {
|
||||
printf("Locked Mutex [%s] refCount: %d\n", this->ownerId.c_str(), this->mutex->getRefCount());
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
void ReleaseLock(bool keepMutex = false) {
|
||||
if (this->mutex != NULL) {
|
||||
#ifdef DEBUG_MUTEXES
|
||||
if (this->ownerId != "") {
|
||||
printf("UnLocking Mutex [%s] refCount: %d\n", this->ownerId.c_str(), this->mutex->getRefCount());
|
||||
}
|
||||
#endif
|
||||
|
||||
if (this->isReadLock == true) {
|
||||
this->mutex->UnLockRead();
|
||||
} else {
|
||||
this->mutex->UnLockWrite();
|
||||
}
|
||||
|
||||
#ifdef DEBUG_PERFORMANCE_MUTEXES
|
||||
if (chrono.getMillis() > 100) printf("In [%s::%s Line: %d] MUTEX UNLOCKED and held locked for msecs: %lld, this->mutex->getRefCount() = %d ownerId [%s]\n", __FILE__, __FUNCTION__, __LINE__, (long long int)chrono.getMillis(), this->mutex->getRefCount(), ownerId.c_str());
|
||||
#endif
|
||||
|
||||
#ifdef DEBUG_MUTEXES
|
||||
if (this->ownerId != "") {
|
||||
printf("UnLocked Mutex [%s] refCount: %d\n", this->ownerId.c_str(), this->mutex->getRefCount());
|
||||
}
|
||||
#endif
|
||||
|
||||
if (keepMutex == false) {
|
||||
this->mutex = NULL;
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
const bool debugMasterSlaveThreadController = false;
|
||||
// =====================================================
|
||||
// class Trigger
|
||||
// =====================================================
|
||||
|
||||
class Trigger {
|
||||
private:
|
||||
SDL_cond* trigger;
|
||||
Mutex *mutex;
|
||||
|
||||
public:
|
||||
Trigger(Mutex *mutex);
|
||||
~Trigger();
|
||||
void signal(bool allThreads = false);
|
||||
int waitTillSignalled(Mutex *mutex, int waitMilliseconds = -1);
|
||||
};
|
||||
|
||||
class MasterSlaveThreadController;
|
||||
|
||||
class SlaveThreadControllerInterface {
|
||||
public:
|
||||
virtual void setMasterController(MasterSlaveThreadController *master) = 0;
|
||||
virtual void signalSlave(void *userdata) = 0;
|
||||
virtual ~SlaveThreadControllerInterface() {
|
||||
}
|
||||
};
|
||||
|
||||
class MasterSlaveThreadController {
|
||||
private:
|
||||
static const int triggerBaseCount = 1;
|
||||
|
||||
Mutex *mutex;
|
||||
Semaphore *slaveTriggerSem;
|
||||
int slaveTriggerCounter;
|
||||
|
||||
std::vector<SlaveThreadControllerInterface *> slaveThreadList;
|
||||
|
||||
void init(std::vector<SlaveThreadControllerInterface *> &newSlaveThreadList);
|
||||
public:
|
||||
|
||||
MasterSlaveThreadController();
|
||||
MasterSlaveThreadController(std::vector<SlaveThreadControllerInterface *> &slaveThreadList);
|
||||
~MasterSlaveThreadController();
|
||||
|
||||
void setSlaves(std::vector<SlaveThreadControllerInterface *> &slaveThreadList);
|
||||
void clearSlaves(bool clearListOnly = false);
|
||||
|
||||
void signalSlaves(void *userdata);
|
||||
void triggerMaster(int waitMilliseconds = -1);
|
||||
bool waitTillSlavesTrigger(int waitMilliseconds = -1);
|
||||
|
||||
};
|
||||
|
||||
class MasterSlaveThreadControllerSafeWrapper {
|
||||
protected:
|
||||
MasterSlaveThreadController *master;
|
||||
string ownerId;
|
||||
int waitMilliseconds;
|
||||
|
||||
public:
|
||||
|
||||
MasterSlaveThreadControllerSafeWrapper(MasterSlaveThreadController *master, int waitMilliseconds = -1, string ownerId = "") {
|
||||
if (debugMasterSlaveThreadController) printf("In [%s::%s Line: %d]\n", __FILE__, __FUNCTION__, __LINE__);
|
||||
|
||||
this->master = master;
|
||||
this->waitMilliseconds = waitMilliseconds;
|
||||
this->ownerId = ownerId;
|
||||
|
||||
if (debugMasterSlaveThreadController) printf("In [%s::%s Line: %d]\n", __FILE__, __FUNCTION__, __LINE__);
|
||||
}
|
||||
~MasterSlaveThreadControllerSafeWrapper() {
|
||||
if (debugMasterSlaveThreadController) printf("In [%s::%s Line: %d]\n", __FILE__, __FUNCTION__, __LINE__);
|
||||
|
||||
if (master != NULL) {
|
||||
if (debugMasterSlaveThreadController) printf("In [%s::%s Line: %d]\n", __FILE__, __FUNCTION__, __LINE__);
|
||||
|
||||
master->triggerMaster(this->waitMilliseconds);
|
||||
}
|
||||
|
||||
if (debugMasterSlaveThreadController) printf("In [%s::%s Line: %d]\n", __FILE__, __FUNCTION__, __LINE__);
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
const bool debugMasterSlaveThreadController = false;
|
||||
// =====================================================
|
||||
// class Trigger
|
||||
// =====================================================
|
||||
|
||||
class Trigger {
|
||||
private:
|
||||
SDL_cond* trigger;
|
||||
Mutex *mutex;
|
||||
|
||||
public:
|
||||
Trigger(Mutex *mutex);
|
||||
~Trigger();
|
||||
void signal(bool allThreads=false);
|
||||
int waitTillSignalled(Mutex *mutex, int waitMilliseconds=-1);
|
||||
};
|
||||
|
||||
class MasterSlaveThreadController;
|
||||
|
||||
class SlaveThreadControllerInterface {
|
||||
public:
|
||||
virtual void setMasterController(MasterSlaveThreadController *master) = 0;
|
||||
virtual void signalSlave(void *userdata) = 0;
|
||||
virtual ~SlaveThreadControllerInterface() {}
|
||||
};
|
||||
|
||||
class MasterSlaveThreadController {
|
||||
private:
|
||||
static const int triggerBaseCount = 1;
|
||||
|
||||
Mutex *mutex;
|
||||
Semaphore *slaveTriggerSem;
|
||||
int slaveTriggerCounter;
|
||||
|
||||
std::vector<SlaveThreadControllerInterface *> slaveThreadList;
|
||||
|
||||
void init(std::vector<SlaveThreadControllerInterface *> &newSlaveThreadList);
|
||||
public:
|
||||
|
||||
MasterSlaveThreadController();
|
||||
MasterSlaveThreadController(std::vector<SlaveThreadControllerInterface *> &slaveThreadList);
|
||||
~MasterSlaveThreadController();
|
||||
|
||||
void setSlaves(std::vector<SlaveThreadControllerInterface *> &slaveThreadList);
|
||||
void clearSlaves(bool clearListOnly=false);
|
||||
|
||||
void signalSlaves(void *userdata);
|
||||
void triggerMaster(int waitMilliseconds=-1);
|
||||
bool waitTillSlavesTrigger(int waitMilliseconds=-1);
|
||||
|
||||
};
|
||||
|
||||
class MasterSlaveThreadControllerSafeWrapper {
|
||||
protected:
|
||||
MasterSlaveThreadController *master;
|
||||
string ownerId;
|
||||
int waitMilliseconds;
|
||||
|
||||
public:
|
||||
|
||||
MasterSlaveThreadControllerSafeWrapper(MasterSlaveThreadController *master, int waitMilliseconds=-1, string ownerId="") {
|
||||
if(debugMasterSlaveThreadController) printf("In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||
|
||||
this->master = master;
|
||||
this->waitMilliseconds = waitMilliseconds;
|
||||
this->ownerId = ownerId;
|
||||
|
||||
if(debugMasterSlaveThreadController) printf("In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||
}
|
||||
~MasterSlaveThreadControllerSafeWrapper() {
|
||||
if(debugMasterSlaveThreadController) printf("In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||
|
||||
if(master != NULL) {
|
||||
if(debugMasterSlaveThreadController) printf("In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||
|
||||
master->triggerMaster(this->waitMilliseconds);
|
||||
}
|
||||
|
||||
if(debugMasterSlaveThreadController) printf("In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||
}
|
||||
};
|
||||
|
||||
}}//end namespace
|
||||
}//end namespace
|
||||
|
||||
#endif
|
||||
|
@@ -33,217 +33,290 @@ typedef SDL_Keysym SDL_keysym;
|
||||
|
||||
#endif
|
||||
|
||||
namespace Shared{ namespace Platform{
|
||||
namespace Shared {
|
||||
namespace Platform {
|
||||
|
||||
class Timer;
|
||||
//class PlatformContextGl;
|
||||
class Timer;
|
||||
//class PlatformContextGl;
|
||||
|
||||
enum MouseButton {
|
||||
mbUnknown,
|
||||
mbLeft,
|
||||
mbCenter,
|
||||
mbRight,
|
||||
mbButtonX1,
|
||||
mbButtonX2,
|
||||
enum MouseButton {
|
||||
mbUnknown,
|
||||
mbLeft,
|
||||
mbCenter,
|
||||
mbRight,
|
||||
mbButtonX1,
|
||||
mbButtonX2,
|
||||
|
||||
mbCount
|
||||
};
|
||||
mbCount
|
||||
};
|
||||
|
||||
enum SizeState{
|
||||
ssMaximized,
|
||||
ssMinimized,
|
||||
ssRestored
|
||||
};
|
||||
enum SizeState {
|
||||
ssMaximized,
|
||||
ssMinimized,
|
||||
ssRestored
|
||||
};
|
||||
|
||||
class MouseState {
|
||||
private:
|
||||
bool states[mbCount];
|
||||
class MouseState {
|
||||
private:
|
||||
bool states[mbCount];
|
||||
|
||||
|
||||
public:
|
||||
MouseState() {
|
||||
clear();
|
||||
public:
|
||||
MouseState() {
|
||||
clear();
|
||||
}
|
||||
//MouseState(const MouseState &);
|
||||
//MouseState &operator=(const MouseState &);
|
||||
void clear() {
|
||||
memset(this, 0, sizeof(MouseState));
|
||||
}
|
||||
|
||||
bool get(MouseButton b) const {
|
||||
if (b > 0 && b < mbCount) {
|
||||
return states[b];
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void set(MouseButton b, bool state) {
|
||||
if (b > 0 && b < mbCount) {
|
||||
states[b] = state;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
enum WindowStyle {
|
||||
wsFullscreen,
|
||||
wsWindowedFixed,
|
||||
wsWindowedResizable
|
||||
};
|
||||
|
||||
// =====================================================
|
||||
// class Window
|
||||
// =====================================================
|
||||
|
||||
class Window {
|
||||
private:
|
||||
static SDL_Window *sdlWindow;
|
||||
Uint32 lastMouseDown[mbCount];
|
||||
int lastMouseX[mbCount];
|
||||
int lastMouseY[mbCount];
|
||||
|
||||
static int64 lastMouseEvent; /** for use in mouse hover calculations */
|
||||
static MouseState mouseState;
|
||||
static Vec2i mousePos;
|
||||
static bool isKeyPressedDown;
|
||||
static bool isFullScreen;
|
||||
static SDL_keysym keystate;
|
||||
static bool tryVSynch;
|
||||
static int64 lastToggle;
|
||||
|
||||
static void setLastToggle(int64 lastToggle) {
|
||||
Window::lastToggle = lastToggle;
|
||||
}
|
||||
static int64 getLastToggle() {
|
||||
return Window::lastToggle;
|
||||
}
|
||||
|
||||
static void setLastMouseEvent(int64 lastMouseEvent) {
|
||||
Window::lastMouseEvent = lastMouseEvent;
|
||||
}
|
||||
static int64 getLastMouseEvent() {
|
||||
return Window::lastMouseEvent;
|
||||
}
|
||||
|
||||
static const MouseState &getMouseState() {
|
||||
return Window::mouseState;
|
||||
}
|
||||
static void setMouseState(MouseButton b, bool state) {
|
||||
Window::mouseState.set(b, state);
|
||||
}
|
||||
|
||||
static const Vec2i &getMousePos() {
|
||||
return Window::mousePos;
|
||||
}
|
||||
static void setMousePos(const Vec2i &mousePos) {
|
||||
Window::mousePos = mousePos;
|
||||
}
|
||||
|
||||
static void setKeystate(SDL_keysym state) {
|
||||
keystate = state;
|
||||
}
|
||||
|
||||
//static bool masterserverMode;
|
||||
static map<wchar_t, bool> mapAllowedKeys;
|
||||
|
||||
protected:
|
||||
//int w, h;
|
||||
static bool isActive;
|
||||
static bool allowAltEnterFullscreenToggle;
|
||||
static int lastShowMouseState;
|
||||
|
||||
public:
|
||||
static SDL_Window *getSDLWindow();
|
||||
static bool handleEvent();
|
||||
static void revertMousePos();
|
||||
static Vec2i getOldMousePos();
|
||||
static bool isKeyDown() {
|
||||
return isKeyPressedDown;
|
||||
}
|
||||
static void setupGraphicsScreen(int depthBits = -1, int stencilBits = -1, bool hardware_acceleration = false, bool fullscreen_anti_aliasing = false);
|
||||
static const bool getIsFullScreen() {
|
||||
return isFullScreen;
|
||||
}
|
||||
static void setIsFullScreen(bool value) {
|
||||
isFullScreen = value;
|
||||
}
|
||||
//static SDL_keysym getKeystate() { return keystate; }
|
||||
static bool isKeyStateModPressed(int mod);
|
||||
static wchar_t extractLastKeyPressed();
|
||||
|
||||
Window();
|
||||
Window(SDL_Window *sdlWindow);
|
||||
virtual ~Window();
|
||||
|
||||
static void addAllowedKeys(string keyList);
|
||||
static void clearAllowedKeys();
|
||||
static bool isAllowedKey(wchar_t key);
|
||||
|
||||
virtual int getScreenWidth() = 0;
|
||||
virtual int getScreenHeight() = 0;
|
||||
|
||||
virtual bool ChangeVideoMode(bool preserveContext, int resWidth, int resHeight,
|
||||
bool fullscreenWindow, int colorBits, int depthBits, int stencilBits,
|
||||
bool hardware_acceleration, bool fullscreen_anti_aliasing,
|
||||
float gammaValue) = 0;
|
||||
//static void setMasterserverMode(bool value) { Window::masterserverMode = value;}
|
||||
//static bool getMasterserverMode() { return Window::masterserverMode;}
|
||||
|
||||
static bool getTryVSynch() {
|
||||
return tryVSynch;
|
||||
}
|
||||
static void setTryVSynch(bool value) {
|
||||
tryVSynch = value;
|
||||
}
|
||||
|
||||
WindowHandle getHandle() {
|
||||
return 0;
|
||||
}
|
||||
string getText();
|
||||
int getX() {
|
||||
return 0;
|
||||
}
|
||||
int getY() {
|
||||
return 0;
|
||||
}
|
||||
int getW() {
|
||||
return getScreenWidth();
|
||||
}
|
||||
int getH() {
|
||||
return getScreenHeight();
|
||||
}
|
||||
|
||||
//component state
|
||||
int getClientW() {
|
||||
return getW();
|
||||
}
|
||||
int getClientH() {
|
||||
return getH();
|
||||
}
|
||||
float getAspect();
|
||||
|
||||
//object state
|
||||
void setText(string text);
|
||||
void setStyle(WindowStyle windowStyle);
|
||||
void setSize(int w, int h);
|
||||
void setPos(int x, int y);
|
||||
void setEnabled(bool enabled);
|
||||
void setVisible(bool visible);
|
||||
|
||||
//misc
|
||||
void create();
|
||||
void destroy();
|
||||
void minimize();
|
||||
|
||||
static void setAllowAltEnterFullscreenToggle(bool value) {
|
||||
allowAltEnterFullscreenToggle = value;
|
||||
}
|
||||
static bool getAllowAltEnterFullscreenToggle() {
|
||||
return allowAltEnterFullscreenToggle;
|
||||
}
|
||||
|
||||
static char getRawKey(SDL_keysym keysym);
|
||||
|
||||
protected:
|
||||
|
||||
void setSDLWindow(SDL_Window *window);
|
||||
|
||||
virtual void eventCreate() {
|
||||
}
|
||||
virtual void eventMouseDown(int x, int y, MouseButton mouseButton) {
|
||||
}
|
||||
virtual void eventMouseUp(int x, int y, MouseButton mouseButton) {
|
||||
}
|
||||
virtual void eventMouseMove(int x, int y, const MouseState* mouseState) {
|
||||
}
|
||||
virtual void eventMouseDoubleClick(int x, int y, MouseButton mouseButton) {
|
||||
}
|
||||
virtual void eventMouseWheel(int x, int y, int zDelta) {
|
||||
}
|
||||
virtual void eventKeyDown(SDL_KeyboardEvent key) {
|
||||
}
|
||||
virtual void eventKeyUp(SDL_KeyboardEvent key) {
|
||||
}
|
||||
virtual void eventKeyPress(SDL_KeyboardEvent c) {
|
||||
}
|
||||
virtual bool eventTextInput(std::string text) {
|
||||
return false;
|
||||
}
|
||||
virtual bool eventSdlKeyDown(SDL_KeyboardEvent key) {
|
||||
return false;
|
||||
}
|
||||
virtual void eventResize() {
|
||||
};
|
||||
virtual void eventPaint() {
|
||||
}
|
||||
virtual void eventTimer(int timerId) {
|
||||
}
|
||||
virtual void eventActivate(bool activated) {
|
||||
};
|
||||
virtual void eventResize(SizeState sizeState) {
|
||||
};
|
||||
virtual void eventMenu(int menuId) {
|
||||
}
|
||||
virtual void eventClose() {
|
||||
};
|
||||
virtual void eventDestroy() {
|
||||
};
|
||||
virtual void eventToggleFullScreen(bool isFullscreen) {
|
||||
};
|
||||
virtual void eventWindowEvent(SDL_WindowEvent event) {
|
||||
}
|
||||
|
||||
private:
|
||||
/// needed to detect double clicks
|
||||
void handleMouseDown(SDL_Event event);
|
||||
void handleMouseWheel(SDL_Event event);
|
||||
|
||||
static MouseButton getMouseButton(int sdlButton);
|
||||
//static char getKey(SDL_keysym keysym, bool skipSpecialKeys=false);
|
||||
//static char getNormalKey(SDL_keysym keysym,bool skipSpecialKeys=false);
|
||||
static void toggleFullscreen();
|
||||
|
||||
static wchar_t convertStringtoSDLKey(const string &value);
|
||||
};
|
||||
|
||||
bool isKeyPressed(SDL_Keycode compareKey, SDL_KeyboardEvent input, vector<int> modifiersToCheck);
|
||||
bool isKeyPressed(SDL_Keycode compareKey, SDL_KeyboardEvent input, bool modifiersAllowed = true);
|
||||
|
||||
SDL_Keycode extractKeyPressed(SDL_KeyboardEvent input);
|
||||
//bool isAllowedInputTextKey(SDL_Keycode key);
|
||||
|
||||
//wchar_t extractKeyPressedUnicode(SDL_KeyboardEvent input);
|
||||
vector<int> extractKeyPressedUnicodeLength(string text);
|
||||
bool isAllowedInputTextKey(wchar_t &key);
|
||||
|
||||
}
|
||||
//MouseState(const MouseState &);
|
||||
//MouseState &operator=(const MouseState &);
|
||||
void clear() { memset(this, 0, sizeof(MouseState)); }
|
||||
|
||||
bool get(MouseButton b) const {
|
||||
if(b > 0 && b < mbCount) {
|
||||
return states[b];
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void set(MouseButton b, bool state) {
|
||||
if(b > 0 && b < mbCount) {
|
||||
states[b] = state;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
enum WindowStyle{
|
||||
wsFullscreen,
|
||||
wsWindowedFixed,
|
||||
wsWindowedResizable
|
||||
};
|
||||
|
||||
// =====================================================
|
||||
// class Window
|
||||
// =====================================================
|
||||
|
||||
class Window {
|
||||
private:
|
||||
static SDL_Window *sdlWindow;
|
||||
Uint32 lastMouseDown[mbCount];
|
||||
int lastMouseX[mbCount];
|
||||
int lastMouseY[mbCount];
|
||||
|
||||
static int64 lastMouseEvent; /** for use in mouse hover calculations */
|
||||
static MouseState mouseState;
|
||||
static Vec2i mousePos;
|
||||
static bool isKeyPressedDown;
|
||||
static bool isFullScreen;
|
||||
static SDL_keysym keystate;
|
||||
static bool tryVSynch;
|
||||
static int64 lastToggle ;
|
||||
|
||||
static void setLastToggle(int64 lastToggle) {Window::lastToggle = lastToggle;}
|
||||
static int64 getLastToggle() {return Window::lastToggle;}
|
||||
|
||||
static void setLastMouseEvent(int64 lastMouseEvent) {Window::lastMouseEvent = lastMouseEvent;}
|
||||
static int64 getLastMouseEvent() {return Window::lastMouseEvent;}
|
||||
|
||||
static const MouseState &getMouseState() {return Window::mouseState;}
|
||||
static void setMouseState(MouseButton b, bool state) {Window::mouseState.set(b, state);}
|
||||
|
||||
static const Vec2i &getMousePos() {return Window::mousePos;}
|
||||
static void setMousePos(const Vec2i &mousePos) {Window::mousePos = mousePos;}
|
||||
|
||||
static void setKeystate(SDL_keysym state) { keystate = state; }
|
||||
|
||||
//static bool masterserverMode;
|
||||
static map<wchar_t,bool> mapAllowedKeys;
|
||||
|
||||
protected:
|
||||
//int w, h;
|
||||
static bool isActive;
|
||||
static bool allowAltEnterFullscreenToggle;
|
||||
static int lastShowMouseState;
|
||||
|
||||
public:
|
||||
static SDL_Window *getSDLWindow();
|
||||
static bool handleEvent();
|
||||
static void revertMousePos();
|
||||
static Vec2i getOldMousePos();
|
||||
static bool isKeyDown() { return isKeyPressedDown; }
|
||||
static void setupGraphicsScreen(int depthBits=-1, int stencilBits=-1, bool hardware_acceleration=false, bool fullscreen_anti_aliasing=false);
|
||||
static const bool getIsFullScreen() { return isFullScreen; }
|
||||
static void setIsFullScreen(bool value) { isFullScreen = value; }
|
||||
//static SDL_keysym getKeystate() { return keystate; }
|
||||
static bool isKeyStateModPressed(int mod);
|
||||
static wchar_t extractLastKeyPressed();
|
||||
|
||||
Window();
|
||||
Window(SDL_Window *sdlWindow);
|
||||
virtual ~Window();
|
||||
|
||||
static void addAllowedKeys(string keyList);
|
||||
static void clearAllowedKeys();
|
||||
static bool isAllowedKey(wchar_t key);
|
||||
|
||||
virtual int getScreenWidth() = 0;
|
||||
virtual int getScreenHeight() = 0;
|
||||
|
||||
virtual bool ChangeVideoMode(bool preserveContext,int resWidth, int resHeight,
|
||||
bool fullscreenWindow, int colorBits, int depthBits, int stencilBits,
|
||||
bool hardware_acceleration, bool fullscreen_anti_aliasing,
|
||||
float gammaValue) = 0;
|
||||
//static void setMasterserverMode(bool value) { Window::masterserverMode = value;}
|
||||
//static bool getMasterserverMode() { return Window::masterserverMode;}
|
||||
|
||||
static bool getTryVSynch() { return tryVSynch; }
|
||||
static void setTryVSynch(bool value) { tryVSynch = value; }
|
||||
|
||||
WindowHandle getHandle() {return 0;}
|
||||
string getText();
|
||||
int getX() { return 0; }
|
||||
int getY() { return 0; }
|
||||
int getW() { return getScreenWidth(); }
|
||||
int getH() { return getScreenHeight(); }
|
||||
|
||||
//component state
|
||||
int getClientW() { return getW(); }
|
||||
int getClientH() { return getH(); }
|
||||
float getAspect();
|
||||
|
||||
//object state
|
||||
void setText(string text);
|
||||
void setStyle(WindowStyle windowStyle);
|
||||
void setSize(int w, int h);
|
||||
void setPos(int x, int y);
|
||||
void setEnabled(bool enabled);
|
||||
void setVisible(bool visible);
|
||||
|
||||
//misc
|
||||
void create();
|
||||
void destroy();
|
||||
void minimize();
|
||||
|
||||
static void setAllowAltEnterFullscreenToggle(bool value) { allowAltEnterFullscreenToggle = value; }
|
||||
static bool getAllowAltEnterFullscreenToggle() { return allowAltEnterFullscreenToggle; }
|
||||
|
||||
static char getRawKey(SDL_keysym keysym);
|
||||
|
||||
protected:
|
||||
|
||||
void setSDLWindow(SDL_Window *window);
|
||||
|
||||
virtual void eventCreate(){}
|
||||
virtual void eventMouseDown(int x, int y, MouseButton mouseButton){}
|
||||
virtual void eventMouseUp(int x, int y, MouseButton mouseButton){}
|
||||
virtual void eventMouseMove(int x, int y, const MouseState* mouseState){}
|
||||
virtual void eventMouseDoubleClick(int x, int y, MouseButton mouseButton){}
|
||||
virtual void eventMouseWheel(int x, int y, int zDelta) {}
|
||||
virtual void eventKeyDown(SDL_KeyboardEvent key) {}
|
||||
virtual void eventKeyUp(SDL_KeyboardEvent key) {}
|
||||
virtual void eventKeyPress(SDL_KeyboardEvent c) {}
|
||||
virtual bool eventTextInput(std::string text) { return false; }
|
||||
virtual bool eventSdlKeyDown(SDL_KeyboardEvent key) { return false; }
|
||||
virtual void eventResize() {};
|
||||
virtual void eventPaint() {}
|
||||
virtual void eventTimer(int timerId) {}
|
||||
virtual void eventActivate(bool activated) {};
|
||||
virtual void eventResize(SizeState sizeState) {};
|
||||
virtual void eventMenu(int menuId) {}
|
||||
virtual void eventClose() {};
|
||||
virtual void eventDestroy() {};
|
||||
virtual void eventToggleFullScreen(bool isFullscreen) {};
|
||||
virtual void eventWindowEvent(SDL_WindowEvent event) {}
|
||||
|
||||
private:
|
||||
/// needed to detect double clicks
|
||||
void handleMouseDown(SDL_Event event);
|
||||
void handleMouseWheel(SDL_Event event);
|
||||
|
||||
static MouseButton getMouseButton(int sdlButton);
|
||||
//static char getKey(SDL_keysym keysym, bool skipSpecialKeys=false);
|
||||
//static char getNormalKey(SDL_keysym keysym,bool skipSpecialKeys=false);
|
||||
static void toggleFullscreen();
|
||||
|
||||
static wchar_t convertStringtoSDLKey(const string &value);
|
||||
};
|
||||
|
||||
bool isKeyPressed(SDL_Keycode compareKey, SDL_KeyboardEvent input, vector<int> modifiersToCheck);
|
||||
bool isKeyPressed(SDL_Keycode compareKey, SDL_KeyboardEvent input, bool modifiersAllowed=true);
|
||||
|
||||
SDL_Keycode extractKeyPressed(SDL_KeyboardEvent input);
|
||||
//bool isAllowedInputTextKey(SDL_Keycode key);
|
||||
|
||||
//wchar_t extractKeyPressedUnicode(SDL_KeyboardEvent input);
|
||||
vector<int> extractKeyPressedUnicodeLength(string text);
|
||||
bool isAllowedInputTextKey(wchar_t &key);
|
||||
|
||||
}}//end namespace
|
||||
}//end namespace
|
||||
|
||||
#endif
|
||||
|
@@ -18,45 +18,51 @@
|
||||
|
||||
using Shared::Graphics::Gl::ContextGl;
|
||||
|
||||
namespace Shared{ namespace Platform{
|
||||
namespace Shared {
|
||||
namespace Platform {
|
||||
|
||||
// =====================================================
|
||||
// class WindowGl
|
||||
// =====================================================
|
||||
// =====================================================
|
||||
// class WindowGl
|
||||
// =====================================================
|
||||
|
||||
class WindowGl: public Window {
|
||||
private:
|
||||
ContextGl context;
|
||||
class WindowGl : public Window {
|
||||
private:
|
||||
ContextGl context;
|
||||
|
||||
static void setGamma(SDL_Window *window,float gammaValue);
|
||||
public:
|
||||
WindowGl();
|
||||
WindowGl(SDL_Window *sdlWindow);
|
||||
virtual ~WindowGl();
|
||||
static void setGamma(SDL_Window *window, float gammaValue);
|
||||
public:
|
||||
WindowGl();
|
||||
WindowGl(SDL_Window *sdlWindow);
|
||||
virtual ~WindowGl();
|
||||
|
||||
void initGl(int colorBits, int depthBits, int stencilBits,
|
||||
bool hardware_acceleration, bool fullscreen_anti_aliasing,
|
||||
float gammaValue);
|
||||
void makeCurrentGl();
|
||||
void swapBuffersGl();
|
||||
void setGamma(float gammaValue);
|
||||
void initGl(int colorBits, int depthBits, int stencilBits,
|
||||
bool hardware_acceleration, bool fullscreen_anti_aliasing,
|
||||
float gammaValue);
|
||||
void makeCurrentGl();
|
||||
void swapBuffersGl();
|
||||
void setGamma(float gammaValue);
|
||||
|
||||
SDL_Window * getScreenWindow();
|
||||
SDL_Surface * getScreenSurface();
|
||||
virtual int getScreenWidth();
|
||||
virtual int getScreenHeight();
|
||||
virtual int getDesiredScreenWidth() { return getScreenWidth(); }
|
||||
virtual int getDesiredScreenHeight() { return getScreenHeight(); }
|
||||
SDL_Window * getScreenWindow();
|
||||
SDL_Surface * getScreenSurface();
|
||||
virtual int getScreenWidth();
|
||||
virtual int getScreenHeight();
|
||||
virtual int getDesiredScreenWidth() {
|
||||
return getScreenWidth();
|
||||
}
|
||||
virtual int getDesiredScreenHeight() {
|
||||
return getScreenHeight();
|
||||
}
|
||||
|
||||
virtual bool ChangeVideoMode(bool preserveContext, int resWidth, int resHeight,
|
||||
bool fullscreenWindow, int colorBits, int depthBits, int stencilBits,
|
||||
bool hardware_acceleration, bool fullscreen_anti_aliasing,
|
||||
float gammaValue);
|
||||
virtual bool ChangeVideoMode(bool preserveContext, int resWidth, int resHeight,
|
||||
bool fullscreenWindow, int colorBits, int depthBits, int stencilBits,
|
||||
bool hardware_acceleration, bool fullscreen_anti_aliasing,
|
||||
float gammaValue);
|
||||
|
||||
protected:
|
||||
virtual void eventToggleFullScreen(bool isFullscreen);
|
||||
};
|
||||
protected:
|
||||
virtual void eventToggleFullScreen(bool isFullscreen);
|
||||
};
|
||||
|
||||
}}//end namespace
|
||||
}
|
||||
}//end namespace
|
||||
|
||||
#endif
|
||||
|
Reference in New Issue
Block a user