Move parameters class in its own file.
Move some code from stratagus.cpp to utils.cpp
This commit is contained in:
parent
26d00cd82a
commit
3c0a1ee386
15 changed files with 189 additions and 95 deletions
|
@ -283,6 +283,7 @@ set(stratagusmain_SRCS
|
|||
src/stratagus/iolib.cpp
|
||||
src/stratagus/luacallback.cpp
|
||||
src/stratagus/mainloop.cpp
|
||||
src/stratagus/parameters.cpp
|
||||
src/stratagus/player.cpp
|
||||
src/stratagus/script.cpp
|
||||
src/stratagus/script_player.cpp
|
||||
|
@ -530,6 +531,7 @@ set(stratagus_generic_HDRS
|
|||
src/include/netconnect.h
|
||||
src/include/net_lowlevel.h
|
||||
src/include/network.h
|
||||
src/include/parameters.h
|
||||
src/include/particle.h
|
||||
src/include/pathfinder.h
|
||||
src/include/player.h
|
||||
|
|
|
@ -50,6 +50,7 @@
|
|||
#include "menus.h"
|
||||
#include "minimap.h"
|
||||
#include "network.h"
|
||||
#include "parameters.h"
|
||||
#include "replay.h"
|
||||
#include "script.h"
|
||||
#include "settings.h"
|
||||
|
|
|
@ -56,6 +56,7 @@
|
|||
#include "missile.h"
|
||||
#include "netconnect.h"
|
||||
#include "network.h"
|
||||
#include "parameters.h"
|
||||
#include "pathfinder.h"
|
||||
#include "player.h"
|
||||
#include "replay.h"
|
||||
|
|
|
@ -45,6 +45,7 @@
|
|||
#include "map.h"
|
||||
#include "netconnect.h"
|
||||
#include "network.h"
|
||||
#include "parameters.h"
|
||||
#include "player.h"
|
||||
#include "script.h"
|
||||
#include "settings.h"
|
||||
|
|
|
@ -43,6 +43,7 @@
|
|||
#include "iolib.h"
|
||||
#include "map.h"
|
||||
#include "missile.h"
|
||||
#include "parameters.h"
|
||||
#include "player.h"
|
||||
#include "replay.h"
|
||||
#include "spells.h"
|
||||
|
|
55
src/include/parameters.h
Normal file
55
src/include/parameters.h
Normal file
|
@ -0,0 +1,55 @@
|
|||
// _________ __ __
|
||||
// / _____// |_____________ _/ |______ ____ __ __ ______
|
||||
// \_____ \\ __\_ __ \__ \\ __\__ \ / ___\| | \/ ___/
|
||||
// / \| | | | \// __ \| | / __ \_/ /_/ > | /\___ |
|
||||
// /_______ /|__| |__| (____ /__| (____ /\___ /|____//____ >
|
||||
// \/ \/ \//_____/ \/
|
||||
// ______________________ ______________________
|
||||
// T H E W A R B E G I N S
|
||||
// Stratagus - A free fantasy real time strategy game engine
|
||||
//
|
||||
/**@name parameters.h - General parameters. */
|
||||
//
|
||||
// (c) Copyright 1998-2013 by Joris Dauphin
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation; only version 2 of the License.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
|
||||
// 02111-1307, USA.
|
||||
//
|
||||
|
||||
#ifndef PARAMATERS_H
|
||||
#define PARAMATERS_H
|
||||
|
||||
class Parameters
|
||||
{
|
||||
public:
|
||||
void SetDefaultValues();
|
||||
void SetLocalPlayerNameFromEnv();
|
||||
|
||||
const std::string &GetUserDirectory() const { return UserDirectory; }
|
||||
|
||||
private:
|
||||
void SetUserDirectory();
|
||||
|
||||
public:
|
||||
std::string applicationName;
|
||||
std::string luaStartFilename;
|
||||
std::string luaEditorStartFilename;
|
||||
std::string LocalPlayerName; /// Name of local player
|
||||
private:
|
||||
std::string UserDirectory; /// Directory containing user settings and data
|
||||
public:
|
||||
static Parameters Instance;
|
||||
};
|
||||
|
||||
#endif /* PARAMATERS_H */
|
|
@ -182,27 +182,6 @@ extern const char NameLine[];
|
|||
-- stratagus.c
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
class Parameters
|
||||
{
|
||||
public:
|
||||
void SetDefaultValues();
|
||||
|
||||
const std::string &GetUserDirectory() { return UserDirectory; }
|
||||
|
||||
private:
|
||||
void SetUserDirectory();
|
||||
|
||||
public:
|
||||
std::string applicationName;
|
||||
std::string luaStartFilename;
|
||||
std::string luaEditorStartFilename;
|
||||
std::string LocalPlayerName; /// Name of local player
|
||||
private:
|
||||
std::string UserDirectory; /// Directory containing user settings and data
|
||||
public:
|
||||
static Parameters Instance;
|
||||
};
|
||||
|
||||
extern std::string StratagusLibPath; /// Location of stratagus data
|
||||
extern std::string MenuRace;
|
||||
|
||||
|
|
|
@ -49,6 +49,7 @@
|
|||
#include "netconnect.h"
|
||||
#include "network.h"
|
||||
#include "net_lowlevel.h"
|
||||
#include "parameters.h"
|
||||
#include "script.h"
|
||||
#include "version.h"
|
||||
|
||||
|
|
|
@ -42,6 +42,7 @@
|
|||
#include "master.h"
|
||||
#include "net_lowlevel.h"
|
||||
#include "network.h"
|
||||
#include "parameters.h"
|
||||
#include "player.h"
|
||||
#include "script.h"
|
||||
#include "settings.h"
|
||||
|
|
|
@ -41,6 +41,7 @@
|
|||
#include "game.h"
|
||||
#include "iocompat.h"
|
||||
#include "map.h"
|
||||
#include "parameters.h"
|
||||
#include "util.h"
|
||||
|
||||
#include <stdarg.h>
|
||||
|
|
93
src/stratagus/parameters.cpp
Normal file
93
src/stratagus/parameters.cpp
Normal file
|
@ -0,0 +1,93 @@
|
|||
// _________ __ __
|
||||
// / _____// |_____________ _/ |______ ____ __ __ ______
|
||||
// \_____ \\ __\_ __ \__ \\ __\__ \ / ___\| | \/ ___/
|
||||
// / \| | | | \// __ \| | / __ \_/ /_/ > | /\___ |
|
||||
// /_______ /|__| |__| (____ /__| (____ /\___ /|____//____ >
|
||||
// \/ \/ \//_____/ \/
|
||||
// ______________________ ______________________
|
||||
// T H E W A R B E G I N S
|
||||
// Stratagus - A free fantasy real time strategy game engine
|
||||
//
|
||||
/**@name action_train.cpp - The building train action. */
|
||||
//
|
||||
// (c) Copyright 1998-2013 by Joris Dauphin
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation; only version 2 of the License.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
|
||||
// 02111-1307, USA.
|
||||
//
|
||||
|
||||
//@{
|
||||
|
||||
#include "stratagus.h"
|
||||
|
||||
#include "parameters.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
/* static */ Parameters Parameters::Instance;
|
||||
|
||||
|
||||
void Parameters::SetDefaultValues()
|
||||
{
|
||||
applicationName = "stratagus";
|
||||
luaStartFilename = "scripts/stratagus.lua";
|
||||
luaEditorStartFilename = "scripts/editor.lua";
|
||||
SetUserDirectory();
|
||||
}
|
||||
|
||||
void Parameters::SetUserDirectory()
|
||||
{
|
||||
#ifdef USE_WIN32
|
||||
UserDirectory = getenv("APPDATA");
|
||||
#else
|
||||
UserDirectory = getenv("HOME");
|
||||
#endif
|
||||
|
||||
if (!UserDirectory.empty()) {
|
||||
UserDirectory += "/";
|
||||
}
|
||||
|
||||
#ifdef USE_WIN32
|
||||
UserDirectory += "Stratagus";
|
||||
#elif defined(USE_MAC)
|
||||
UserDirectory += "Library/Stratagus";
|
||||
#else
|
||||
UserDirectory += ".stratagus";
|
||||
#endif
|
||||
}
|
||||
|
||||
static std::string GetLocalPlayerNameFromEnv()
|
||||
{
|
||||
const char *userName = NULL;
|
||||
|
||||
#ifdef USE_WIN32
|
||||
userName = getenv("USERNAME");
|
||||
#elif !defined(USE_MAEMO)
|
||||
userName = getenv("USER");
|
||||
#endif
|
||||
|
||||
if (userName && userName[0]) {
|
||||
return userName;
|
||||
} else {
|
||||
return "Anonymous";
|
||||
}
|
||||
}
|
||||
|
||||
void Parameters::SetLocalPlayerNameFromEnv()
|
||||
{
|
||||
LocalPlayerName = GetLocalPlayerNameFromEnv();
|
||||
}
|
||||
|
||||
|
||||
//@}
|
|
@ -44,6 +44,7 @@
|
|||
#include "iocompat.h"
|
||||
#include "iolib.h"
|
||||
#include "map.h"
|
||||
#include "parameters.h"
|
||||
#include "trigger.h"
|
||||
#include "ui.h"
|
||||
#include "unit.h"
|
||||
|
|
|
@ -189,6 +189,7 @@ extern void beos_init(int argc, char **argv);
|
|||
#include "map.h"
|
||||
#include "netconnect.h"
|
||||
#include "network.h"
|
||||
#include "parameters.h"
|
||||
#include "player.h"
|
||||
#include "replay.h"
|
||||
#include "results.h"
|
||||
|
@ -215,38 +216,6 @@ extern void beos_init(int argc, char **argv);
|
|||
#define REDIRECT_OUTPUT
|
||||
#endif
|
||||
|
||||
void Parameters::SetDefaultValues()
|
||||
{
|
||||
applicationName = "stratagus";
|
||||
luaStartFilename = "scripts/stratagus.lua";
|
||||
luaEditorStartFilename = "scripts/editor.lua";
|
||||
SetUserDirectory();
|
||||
}
|
||||
|
||||
void Parameters::SetUserDirectory()
|
||||
{
|
||||
#ifdef USE_WIN32
|
||||
UserDirectory = getenv("APPDATA");
|
||||
#else
|
||||
UserDirectory = getenv("HOME");
|
||||
#endif
|
||||
|
||||
if (!UserDirectory.empty()) {
|
||||
UserDirectory += "/";
|
||||
}
|
||||
|
||||
#ifdef USE_WIN32
|
||||
UserDirectory += "Stratagus";
|
||||
#elif defined(USE_MAC)
|
||||
UserDirectory += "Library/Stratagus";
|
||||
#else
|
||||
UserDirectory += ".stratagus";
|
||||
#endif
|
||||
}
|
||||
|
||||
/* static */ Parameters Parameters::Instance;
|
||||
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
-- Variables
|
||||
----------------------------------------------------------------------------*/
|
||||
|
@ -263,29 +232,6 @@ std::string MenuRace;
|
|||
== MAIN
|
||||
============================================================================*/
|
||||
|
||||
void PrintLocation(const char *file, int line, const char *funcName)
|
||||
{
|
||||
fprintf(stdout, "%s:%d: %s: ", file, line, funcName);
|
||||
}
|
||||
|
||||
#ifdef DEBUG
|
||||
|
||||
void AbortAt(const char *file, int line, const char *funcName, const char *conditionStr)
|
||||
{
|
||||
fprintf(stderr, "Assertion failed at %s:%d: %s: %s\n", file, line, funcName, conditionStr);
|
||||
abort();
|
||||
}
|
||||
|
||||
void PrintOnStdOut(const char *format, ...)
|
||||
{
|
||||
va_list valist;
|
||||
va_start(valist, format);
|
||||
vprintf(format, valist);
|
||||
va_end(valist);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
/**
|
||||
** Pre menu setup.
|
||||
*/
|
||||
|
@ -661,24 +607,6 @@ void ParseCommandLine(int argc, char **argv, Parameters ¶meters)
|
|||
while ((index = CliMapName.find('\\')) != std::string::npos) {
|
||||
CliMapName[index] = '/';
|
||||
}
|
||||
--argc;
|
||||
}
|
||||
}
|
||||
|
||||
std::string GetLocalPlayerNameFromEnv()
|
||||
{
|
||||
const char *userName = NULL;
|
||||
|
||||
#ifdef USE_WIN32
|
||||
userName = getenv("USERNAME");
|
||||
#elif !defined(USE_MAEMO)
|
||||
userName = getenv("USER");
|
||||
#endif
|
||||
|
||||
if (userName && userName[0]) {
|
||||
return userName;
|
||||
} else {
|
||||
return "Anonymous";
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -717,7 +645,7 @@ int main(int argc, char **argv)
|
|||
|
||||
Parameters ¶meters = Parameters::Instance;
|
||||
parameters.SetDefaultValues();
|
||||
parameters.LocalPlayerName = GetLocalPlayerNameFromEnv();
|
||||
parameters.SetLocalPlayerNameFromEnv();
|
||||
|
||||
if (argc > 0) {
|
||||
parameters.applicationName = argv[0];
|
||||
|
|
|
@ -481,3 +481,31 @@ int UTF8GetNext(const std::string &text, int curpos)
|
|||
return text.size();
|
||||
}
|
||||
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
-- others
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
void PrintLocation(const char *file, int line, const char *funcName)
|
||||
{
|
||||
fprintf(stdout, "%s:%d: %s: ", file, line, funcName);
|
||||
}
|
||||
|
||||
#ifdef DEBUG
|
||||
|
||||
void AbortAt(const char *file, int line, const char *funcName, const char *conditionStr)
|
||||
{
|
||||
fprintf(stderr, "Assertion failed at %s:%d: %s: %s\n", file, line, funcName, conditionStr);
|
||||
abort();
|
||||
}
|
||||
|
||||
void PrintOnStdOut(const char *format, ...)
|
||||
{
|
||||
va_list valist;
|
||||
va_start(valist, format);
|
||||
vprintf(format, valist);
|
||||
va_end(valist);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
|
|
@ -81,6 +81,7 @@
|
|||
#include "interface.h"
|
||||
#include "minimap.h"
|
||||
#include "network.h"
|
||||
#include "parameters.h"
|
||||
#include "sound.h"
|
||||
#include "sound_server.h"
|
||||
#include "translate.h"
|
||||
|
|
Loading…
Reference in a new issue