X-Git-Url: https://git.jsancho.org/?a=blobdiff_plain;f=Source%2Fmain.cpp;h=8463907b00b2aee8a91d2c3c2117f3a77546b76f;hb=3326a4860ff8b052e7abfe86698ce7e51cfc441a;hp=09f6960be03b6dfd8ca9b4100984c542001d433a;hpb=ff29f47f799d99cec7c2a6aa2cf818da2b931fc5;p=lugaru.git
diff --git a/Source/main.cpp b/Source/main.cpp
index 09f6960..8463907 100644
--- a/Source/main.cpp
+++ b/Source/main.cpp
@@ -18,31 +18,30 @@ You should have received a copy of the GNU General Public License
along with Lugaru. If not, see .
*/
+#include "Game.hpp"
+
+#include "Audio/openal_wrapper.hpp"
+#include "Graphic/gamegl.hpp"
+#include "MacCompatibility.hpp"
+#include "User/Settings.hpp"
+
+#include
+#include
#include
+#include
#include
#include
-#include
-#include
#include
-#include
-#include "gamegl.h"
-#include "MacCompatibility.h"
-#include "Settings.h"
-
-#include "Game.h"
using namespace Game;
-#include "openal_wrapper.h"
-
#ifdef WIN32
-#include
#include
-#include "win-res/resource.h"
+#include
+#include "win-res/resource.hpp"
#endif
extern float multiplier;
-extern float sps;
extern float realmultiplier;
extern int slomo;
extern bool cellophane;
@@ -56,6 +55,8 @@ extern float slomospeed;
extern float slomofreq;
extern bool visibleloading;
+extern int difficulty;
+
extern SDL_Window *sdlwindow;
using namespace std;
@@ -64,59 +65,6 @@ set> resolutions;
// statics/globals (internal only) ------------------------------------------
-#ifdef _MSC_VER
-#pragma warning(push)
-#pragma warning(disable: 4273)
-#endif
-
-#ifndef __MINGW32__ // FIXME: Temporary workaround for GL-8
-#define GL_FUNC(ret,fn,params,call,rt) \
- extern "C" { \
- static ret (GLAPIENTRY *p##fn) params = NULL; \
- ret GLAPIENTRY fn params { rt p##fn call; } \
- }
-#include "glstubs.h"
-#undef GL_FUNC
-#endif // __MINGW32__
-
-#ifdef _MSC_VER
-#pragma warning(pop)
-#endif
-
-static bool lookup_glsym(const char *funcname, void **func)
-{
- *func = SDL_GL_GetProcAddress(funcname);
- if (*func == NULL) {
- fprintf(stderr, "Failed to find OpenGL symbol \"%s\"\n", funcname);
- return false;
- }
- return true;
-}
-
-static bool lookup_all_glsyms(void)
-{
- bool retval = true;
-#ifndef __MINGW32__ // FIXME: Temporary workaround for GL-8
-#define GL_FUNC(ret,fn,params,call,rt) \
- if (!lookup_glsym(#fn, (void **) &p##fn)) retval = false;
-#include "glstubs.h"
-#undef GL_FUNC
-#endif // __MINGW32__
- return retval;
-}
-
-#ifndef __MINGW32__ // FIXME: Temporary workaround for GL-8
-static void GLAPIENTRY glDeleteTextures_doNothing(GLsizei n, const GLuint *textures)
-{
- // no-op.
-}
-#endif // __MINGW32__
-
-#ifdef MessageBox
-#undef MessageBox
-#endif
-#define MessageBox(hwnd,text,title,flags) STUBBED("msgbox")
-
// Menu defs
int kContextWidth;
@@ -243,9 +191,6 @@ bool SetUp ()
fprintf(stderr, "Failed to load config, creating default\n");
SaveSettings();
}
- if (kBitsPerPixel != 32 && kBitsPerPixel != 16) {
- kBitsPerPixel = 16;
- }
if (SDL_GL_LoadLibrary(NULL) == -1) {
fprintf(stderr, "SDL_GL_LoadLibrary() failed: %s\n", SDL_GetError());
@@ -327,12 +272,6 @@ bool SetUp ()
SDL_GL_MakeCurrent(sdlwindow, glctx);
- if (!lookup_all_glsyms()) {
- fprintf(stderr, "Missing required OpenGL functions.\n");
- SDL_Quit();
- return false;
- }
-
int dblbuf = 0;
if ((SDL_GL_GetAttribute(SDL_GL_DOUBLEBUFFER, &dblbuf) == -1) || (!dblbuf))
{
@@ -521,16 +460,9 @@ void CleanUp (void)
{
LOGFUNC;
- SDL_Quit();
-#ifndef __MINGW32__ // FIXME: Temporary workaround for GL-8
-#define GL_FUNC(ret,fn,params,call,rt) p##fn = NULL;
-#include "glstubs.h"
-#undef GL_FUNC
- // cheat here...static destructors are calling glDeleteTexture() after
- // the context is destroyed and libGL unloaded by SDL_Quit().
- pglDeleteTextures = glDeleteTextures_doNothing;
-#endif // __MINGW32__
+ delete[] commandLineOptionsBuffer;
+ SDL_Quit();
}
// --------------------------------------------------------------------------
@@ -651,10 +583,12 @@ const option::Descriptor usage[] =
{SOUND, OPENAL_OUTPUT_OSS, "", "force-oss", option::Arg::None, " --force-oss Force use of OSS back-end." },
{OPENALINFO, 0, "", "openal-info", option::Arg::None, " --openal-info Print info about OpenAL at launch." },
{SHOWRESOLUTIONS, 0, "", "showresolutions", option::Arg::None, " --showresolutions List the resolutions found by SDL at launch." },
+ {DEVTOOLS, 0, "d", "devtools", option::Arg::None, " -d, --devtools Enable dev tools: console, level editor and debug info." },
{0,0,0,0,0,0}
};
option::Option commandLineOptions[commandLineOptionsNumber];
+option::Option* commandLineOptionsBuffer;
int main(int argc, char **argv)
{
@@ -664,21 +598,24 @@ int main(int argc, char **argv)
std::cerr << "Found incorrect command line option number" << std::endl;
return 1;
}
- option::Option buffer[stats.buffer_max];
- option::Parser parse(true, usage, argc, argv, commandLineOptions, buffer);
+ commandLineOptionsBuffer = new option::Option[stats.buffer_max];
+ option::Parser parse(true, usage, argc, argv, commandLineOptions, commandLineOptionsBuffer);
if (parse.error()) {
+ delete[] commandLineOptionsBuffer;
return 1;
}
if (commandLineOptions[HELP]) {
option::printUsage(std::cout, usage);
+ delete[] commandLineOptionsBuffer;
return 0;
}
if (option::Option* opt = commandLineOptions[UNKNOWN]) {
std::cerr << "Unknown option: " << opt->name << "\n";
option::printUsage(std::cerr, usage);
+ delete[] commandLineOptionsBuffer;
return 1;
}
@@ -689,12 +626,20 @@ int main(int argc, char **argv)
LOGFUNC;
+#ifdef NDEBUG
try {
+#endif
{
newGame();
- if (!SetUp ())
+ if (!SetUp ()) {
+ delete[] commandLineOptionsBuffer;
return 42;
+ }
+
+ if (commandLineOptions[DEVTOOLS]) {
+ devtools = true;
+ }
bool gameDone = false;
bool gameFocused = true;
@@ -738,6 +683,7 @@ int main(int argc, char **argv)
CleanUp ();
return 0;
+#ifdef NDEBUG
} catch (const std::exception& error) {
CleanUp();
@@ -746,8 +692,9 @@ int main(int argc, char **argv)
LOG(e);
- MessageBox(g_windowHandle, error.what(), "ERROR", MB_OK | MB_ICONEXCLAMATION);
+ SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "Exception catched", error.what(), NULL);
return -1;
}
+#endif
}