mirror of
https://github.com/The-Powder-Toy/The-Powder-Toy.git
synced 2025-08-11 19:04:05 +02:00
Parsing commandline arguments
This commit is contained in:
@@ -1,5 +1,7 @@
|
|||||||
#ifdef USE_SDL
|
#ifdef USE_SDL
|
||||||
|
|
||||||
|
#include <map>
|
||||||
|
#include <string>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
#include "SDL.h"
|
#include "SDL.h"
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
@@ -22,6 +24,7 @@
|
|||||||
#include "interface/Label.h"
|
#include "interface/Label.h"
|
||||||
#include "simulation/SaveRenderer.h"
|
#include "simulation/SaveRenderer.h"
|
||||||
#include "client/Client.h"
|
#include "client/Client.h"
|
||||||
|
#include "Misc.h"
|
||||||
|
|
||||||
#include "game/GameController.h"
|
#include "game/GameController.h"
|
||||||
#include "game/GameView.h"
|
#include "game/GameView.h"
|
||||||
@@ -128,6 +131,67 @@ SDL_Surface * SDLOpen()
|
|||||||
return surface;
|
return surface;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::map<std::string, std::string> readArguments(int argc, char * argv[])
|
||||||
|
{
|
||||||
|
std::map<std::string, std::string> arguments;
|
||||||
|
|
||||||
|
//Defaults
|
||||||
|
arguments["scale"] = "";
|
||||||
|
arguments["proxy"] = "";
|
||||||
|
arguments["nohud"] = "false";
|
||||||
|
arguments["sound"] = "false";
|
||||||
|
arguments["kiosk"] = "false";
|
||||||
|
arguments["scripts"] = "false";
|
||||||
|
arguments["open"] = "";
|
||||||
|
arguments["ddir"] = "";
|
||||||
|
arguments["ptsave"] = "";
|
||||||
|
|
||||||
|
for (int i=1; i<argc; i++)
|
||||||
|
{
|
||||||
|
if (!strncmp(argv[i], "scale:", 6) && argv[i]+6)
|
||||||
|
{
|
||||||
|
arguments["scale"] = std::string(argv[i]+6);
|
||||||
|
}
|
||||||
|
else if (!strncmp(argv[i], "proxy:", 6) && argv[i]+6)
|
||||||
|
{
|
||||||
|
arguments["proxy"] = std::string(argv[i]+6);
|
||||||
|
}
|
||||||
|
else if (!strncmp(argv[i], "nohud", 5))
|
||||||
|
{
|
||||||
|
arguments["nohud"] = "true";
|
||||||
|
}
|
||||||
|
else if (!strncmp(argv[i], "kiosk", 5))
|
||||||
|
{
|
||||||
|
arguments["kiosk"] = "true";
|
||||||
|
}
|
||||||
|
else if (!strncmp(argv[i], "sound", 5))
|
||||||
|
{
|
||||||
|
arguments["sound"] = "true";
|
||||||
|
}
|
||||||
|
else if (!strncmp(argv[i], "scripts", 8))
|
||||||
|
{
|
||||||
|
arguments["scripts"] = "true";
|
||||||
|
}
|
||||||
|
else if (!strncmp(argv[i], "open", 5) && i+1<argc)
|
||||||
|
{
|
||||||
|
arguments["open"] = std::string(argv[i+1]);;
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
else if (!strncmp(argv[i], "ddir", 5) && i+1<argc)
|
||||||
|
{
|
||||||
|
arguments["ddir"] = std::string(argv[i+1]);
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
else if (!strncmp(argv[i], "ptsave", 7) && i+1<argc)
|
||||||
|
{
|
||||||
|
arguments["ptsave"] = std::string(argv[i+1]);
|
||||||
|
i++;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return arguments;
|
||||||
|
}
|
||||||
|
|
||||||
int main(int argc, char * argv[])
|
int main(int argc, char * argv[])
|
||||||
{
|
{
|
||||||
int elapsedTime = 0, currentTime = 0, lastTime = 0, currentFrame = 0;
|
int elapsedTime = 0, currentTime = 0, lastTime = 0, currentFrame = 0;
|
||||||
@@ -135,6 +199,8 @@ int main(int argc, char * argv[])
|
|||||||
float fps = 0, delta = 1.0f, inputScale = 1.0f;
|
float fps = 0, delta = 1.0f, inputScale = 1.0f;
|
||||||
float currentWidth = XRES+BARSIZE, currentHeight = YRES+MENUSIZE;
|
float currentWidth = XRES+BARSIZE, currentHeight = YRES+MENUSIZE;
|
||||||
|
|
||||||
|
std::map<std::string, std::string> arguments = readArguments(argc, argv);
|
||||||
|
|
||||||
sdl_scrn = SDLOpen();
|
sdl_scrn = SDLOpen();
|
||||||
#ifdef OGLI
|
#ifdef OGLI
|
||||||
SDL_GL_SetAttribute (SDL_GL_DOUBLEBUFFER, 1);
|
SDL_GL_SetAttribute (SDL_GL_DOUBLEBUFFER, 1);
|
||||||
@@ -151,8 +217,6 @@ int main(int argc, char * argv[])
|
|||||||
GameController * gameController = new GameController();
|
GameController * gameController = new GameController();
|
||||||
engine->ShowWindow(gameController->GetView());
|
engine->ShowWindow(gameController->GetView());
|
||||||
|
|
||||||
//new ErrorMessage("Error", "This is a test error message");
|
|
||||||
|
|
||||||
SDL_Event event;
|
SDL_Event event;
|
||||||
while(engine->Running())
|
while(engine->Running())
|
||||||
{
|
{
|
||||||
|
Reference in New Issue
Block a user