2010-03-17 07:25:19 +01:00
// This file is part of Glest (www.glest.org)
//
2010-03-31 19:30:12 +02:00
// Copyright (C) 2001-2008 Martio Figueroa
2010-03-17 07:25:19 +01:00
//
// You can redistribute this code and/or modify it under
// the terms of the GNU General Public License as published
// by the Free Software Foundation; either version 2 of the
// License, or (at your option) any later version
// ==============================================================
2010-05-01 22:14:25 +02:00
# include "math_wrapper.h"
2010-03-17 07:25:19 +01:00
# include "main.h"
# include <string>
# include <cstdlib>
# include "game.h"
# include "main_menu.h"
# include "program.h"
# include "config.h"
# include "metrics.h"
# include "game_util.h"
# include "platform_util.h"
# include "platform_main.h"
# include "network_interface.h"
2010-03-24 14:39:08 +01:00
# include "ImageReaders.h"
2010-04-02 19:37:04 +02:00
# include "renderer.h"
2010-05-01 00:54:24 +02:00
# include "simple_threads.h"
2010-05-01 11:10:52 +02:00
# include <memory>
2010-05-03 08:16:32 +02:00
# include "font.h"
2010-05-11 07:39:00 +02:00
# include <curl/curl.h>
2010-05-16 05:31:12 +02:00
# include "menu_state_masterserver.h"
2010-07-30 09:51:39 +02:00
# include "checksum.h"
2010-08-21 03:54:04 +02:00
# include <algorithm>
2010-03-27 19:35:47 +01:00
# include "leak_dumper.h"
2010-06-26 21:08:34 +02:00
# ifndef WIN32
# define stricmp strcasecmp
# define strnicmp strncasecmp
# endif
2010-03-17 07:25:19 +01:00
using namespace std ;
using namespace Shared : : Platform ;
using namespace Shared : : Util ;
2010-05-03 08:16:32 +02:00
using namespace Shared : : Graphics ;
2010-03-17 07:25:19 +01:00
namespace Glest { namespace Game {
2010-03-23 09:56:41 +01:00
bool gameInitialized = false ;
2010-03-23 08:59:24 +01:00
2010-08-21 08:11:45 +02:00
const char * GAME_ARGS [ ] = {
" --help " ,
2010-08-21 15:06:59 +02:00
" --connecthost " ,
" --starthost " ,
2010-08-21 08:11:45 +02:00
" --version " ,
" --opengl-info " ,
2010-08-26 18:03:54 +02:00
" --sdl-info " ,
2010-08-21 08:11:45 +02:00
" --validate-techtrees " ,
" --validate-factions "
} ;
enum GAME_ARG_TYPE {
GAME_ARG_HELP = 0 ,
2010-08-21 08:47:00 +02:00
GAME_ARG_CLIENT ,
GAME_ARG_SERVER ,
2010-08-21 08:11:45 +02:00
GAME_ARG_VERSION ,
GAME_ARG_OPENGL_INFO ,
2010-08-26 18:03:54 +02:00
GAME_ARG_SDL_INFO ,
2010-08-21 08:11:45 +02:00
GAME_ARG_VALIDATE_TECHTREES ,
GAME_ARG_VALIDATE_FACTIONS
} ;
2010-03-17 07:25:19 +01:00
// =====================================================
// class ExceptionHandler
// =====================================================
class ExceptionHandler : public PlatformExceptionHandler {
public :
virtual void handle ( ) {
2010-08-12 02:07:16 +02:00
string msg = " #1 An error ocurred and Glest will close. \n Please report this bug to " + mailString ;
# ifdef WIN32
msg + = " , attaching the generated " + getCrashDumpFileName ( ) + " file. " ;
# endif
2010-03-23 08:59:24 +01:00
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " %s \n " , msg . c_str ( ) ) ;
2010-03-17 07:25:19 +01:00
Program * program = Program : : getInstance ( ) ;
2010-03-23 09:56:41 +01:00
if ( program & & gameInitialized = = true ) {
2010-03-23 08:59:24 +01:00
//SystemFlags::Close();
2010-03-17 07:25:19 +01:00
program - > showMessage ( msg . c_str ( ) ) ;
}
message ( msg . c_str ( ) ) ;
}
static void handleRuntimeError ( const char * msg ) {
2010-03-23 08:59:24 +01:00
Program * program = Program : : getInstance ( ) ;
2010-04-12 22:32:47 +02:00
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] [%s] gameInitialized = %d, program = %p \n " , __FILE__ , __FUNCTION__ , __LINE__ , msg , gameInitialized , program ) ;
2010-03-23 09:56:41 +01:00
if ( program & & gameInitialized = = true ) {
2010-03-23 08:59:24 +01:00
//SystemFlags::Close();
2010-03-17 07:25:19 +01:00
program - > showMessage ( msg ) ;
}
else {
2010-08-12 02:39:14 +02:00
string err = " #2 An error ocurred and Glest will close. \n Error msg = [ " + ( msg ! = NULL ? string ( msg ) : string ( " ? " ) ) + " ] \n \n Please report this bug to " + mailString ;
2010-08-12 02:07:16 +02:00
# ifdef WIN32
2010-08-12 02:39:14 +02:00
err + = string ( " , attaching the generated " ) + getCrashDumpFileName ( ) + string ( " file. " ) ;
2010-08-12 02:07:16 +02:00
# endif
2010-08-12 02:39:14 +02:00
message ( err ) ;
2010-03-17 07:25:19 +01:00
}
2010-04-12 22:32:47 +02:00
showCursor ( true ) ;
2010-03-23 07:03:16 +01:00
restoreVideoMode ( true ) ;
2010-03-23 08:59:24 +01:00
//SystemFlags::Close();
2010-03-17 07:25:19 +01:00
exit ( 0 ) ;
}
static int DisplayMessage ( const char * msg , bool exitApp ) {
2010-07-08 10:29:51 +02:00
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] msg [%s] exitApp = %d \n " , __FILE__ , __FUNCTION__ , __LINE__ , msg , exitApp ) ;
2010-03-17 07:25:19 +01:00
Program * program = Program : : getInstance ( ) ;
2010-03-23 09:56:41 +01:00
if ( program & & gameInitialized = = true ) {
2010-03-17 07:25:19 +01:00
program - > showMessage ( msg ) ;
}
else {
message ( msg ) ;
}
if ( exitApp = = true ) {
2010-04-12 22:32:47 +02:00
showCursor ( true ) ;
2010-03-23 07:03:16 +01:00
restoreVideoMode ( true ) ;
2010-03-23 08:59:24 +01:00
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " %s \n " , msg ) ;
//SystemFlags::Close();
2010-03-17 07:25:19 +01:00
exit ( 0 ) ;
}
return 0 ;
}
} ;
// =====================================================
// class MainWindow
// =====================================================
MainWindow : : MainWindow ( Program * program ) {
this - > program = program ;
}
MainWindow : : ~ MainWindow ( ) {
delete program ;
2010-07-06 07:30:34 +02:00
program = NULL ;
2010-03-17 07:25:19 +01:00
}
void MainWindow : : eventMouseDown ( int x , int y , MouseButton mouseButton ) {
2010-03-24 02:28:48 +01:00
const Metrics & metrics = Metrics : : getInstance ( ) ;
int vx = metrics . toVirtualX ( x ) ;
int vy = metrics . toVirtualY ( getH ( ) - y ) ;
2010-07-06 07:30:34 +02:00
if ( program = = NULL ) {
throw runtime_error ( " In [MainWindow::eventMouseDown] ERROR, program == NULL! " ) ;
}
2010-03-24 02:28:48 +01:00
2010-07-30 00:08:45 +02:00
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2010-07-08 10:29:51 +02:00
switch ( mouseButton ) {
case mbLeft :
program - > mouseDownLeft ( vx , vy ) ;
break ;
case mbRight :
//program->mouseDownRight(vx, vy);
break ;
case mbCenter :
//program->mouseDownCenter(vx, vy);
break ;
default :
break ;
}
2010-07-30 00:08:45 +02:00
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2010-07-06 07:30:34 +02:00
ProgramState * programState = program - > getState ( ) ;
if ( programState ! = NULL ) {
switch ( mouseButton ) {
case mbLeft :
programState - > mouseDownLeft ( vx , vy ) ;
break ;
case mbRight :
programState - > mouseDownRight ( vx , vy ) ;
break ;
case mbCenter :
programState - > mouseDownCenter ( vx , vy ) ;
break ;
default :
break ;
}
2010-07-30 00:08:45 +02:00
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2010-03-24 02:28:48 +01:00
}
2010-07-30 00:08:45 +02:00
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2010-03-17 07:25:19 +01:00
}
void MainWindow : : eventMouseUp ( int x , int y , MouseButton mouseButton ) {
2010-07-30 00:08:45 +02:00
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2010-03-24 02:28:48 +01:00
const Metrics & metrics = Metrics : : getInstance ( ) ;
int vx = metrics . toVirtualX ( x ) ;
int vy = metrics . toVirtualY ( getH ( ) - y ) ;
2010-07-06 07:30:34 +02:00
if ( program = = NULL ) {
throw runtime_error ( " In [MainWindow::eventMouseUp] ERROR, program == NULL! " ) ;
}
2010-07-30 00:08:45 +02:00
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2010-03-24 02:28:48 +01:00
ProgramState * programState = program - > getState ( ) ;
2010-07-30 00:08:45 +02:00
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2010-07-06 07:30:34 +02:00
if ( programState ! = NULL ) {
2010-07-30 00:08:45 +02:00
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2010-07-06 07:30:34 +02:00
switch ( mouseButton ) {
case mbLeft :
programState - > mouseUpLeft ( vx , vy ) ;
break ;
case mbRight :
programState - > mouseUpRight ( vx , vy ) ;
break ;
case mbCenter :
programState - > mouseUpCenter ( vx , vy ) ;
break ;
default :
break ;
}
2010-07-30 00:08:45 +02:00
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2010-03-24 02:28:48 +01:00
}
2010-07-30 00:08:45 +02:00
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2010-03-17 07:25:19 +01:00
}
2010-07-30 00:08:45 +02:00
void MainWindow : : eventMouseDoubleClick ( int x , int y , MouseButton mouseButton ) {
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2010-03-24 02:28:48 +01:00
const Metrics & metrics = Metrics : : getInstance ( ) ;
int vx = metrics . toVirtualX ( x ) ;
int vy = metrics . toVirtualY ( getH ( ) - y ) ;
2010-07-06 07:30:34 +02:00
if ( program = = NULL ) {
throw runtime_error ( " In [MainWindow::eventMouseDoubleClick] ERROR, program == NULL! " ) ;
}
2010-07-30 00:08:45 +02:00
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2010-03-24 02:28:48 +01:00
ProgramState * programState = program - > getState ( ) ;
2010-07-30 00:08:45 +02:00
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2010-07-06 07:30:34 +02:00
if ( programState ! = NULL ) {
2010-07-30 00:08:45 +02:00
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2010-07-06 07:30:34 +02:00
switch ( mouseButton ) {
case mbLeft :
programState - > mouseDoubleClickLeft ( vx , vy ) ;
break ;
case mbRight :
programState - > mouseDoubleClickRight ( vx , vy ) ;
break ;
case mbCenter :
programState - > mouseDoubleClickCenter ( vx , vy ) ;
break ;
default :
break ;
}
2010-07-30 00:08:45 +02:00
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2010-03-24 02:28:48 +01:00
}
2010-07-30 00:08:45 +02:00
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2010-03-17 07:25:19 +01:00
}
void MainWindow : : eventMouseMove ( int x , int y , const MouseState * ms ) {
2010-03-24 02:28:48 +01:00
const Metrics & metrics = Metrics : : getInstance ( ) ;
int vx = metrics . toVirtualX ( x ) ;
int vy = metrics . toVirtualY ( getH ( ) - y ) ;
2010-07-06 07:30:34 +02:00
if ( program = = NULL ) {
throw runtime_error ( " In [MainWindow::eventMouseMove] ERROR, program == NULL! " ) ;
}
2010-07-08 10:29:51 +02:00
program - > eventMouseMove ( vx , vy , ms ) ;
2010-03-24 02:28:48 +01:00
ProgramState * programState = program - > getState ( ) ;
2010-07-06 07:30:34 +02:00
if ( programState ! = NULL ) {
programState - > mouseMove ( vx , vy , ms ) ;
}
2010-03-24 02:28:48 +01:00
}
void MainWindow : : eventMouseWheel ( int x , int y , int zDelta ) {
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
const Metrics & metrics = Metrics : : getInstance ( ) ;
int vx = metrics . toVirtualX ( x ) ;
int vy = metrics . toVirtualY ( getH ( ) - y ) ;
2010-07-06 07:30:34 +02:00
if ( program = = NULL ) {
throw runtime_error ( " In [MainWindow::eventMouseMove] ERROR, program == NULL! " ) ;
}
2010-03-24 02:28:48 +01:00
ProgramState * programState = program - > getState ( ) ;
2010-07-06 07:30:34 +02:00
if ( programState ! = NULL ) {
programState - > eventMouseWheel ( vx , vy , zDelta ) ;
}
2010-03-24 02:28:48 +01:00
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2010-03-17 07:25:19 +01:00
}
void MainWindow : : eventKeyDown ( char key ) {
2010-07-08 00:25:29 +02:00
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] [%d] \n " , __FILE__ , __FUNCTION__ , __LINE__ , key ) ;
SDL_keysym keystate = Window : : getKeystate ( ) ;
2010-04-06 16:25:00 +02:00
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] key = [%c][%d] \n " , __FILE__ , __FUNCTION__ , __LINE__ , key , key ) ;
2010-07-06 07:30:34 +02:00
if ( program = = NULL ) {
throw runtime_error ( " In [MainWindow::eventKeyDown] ERROR, program == NULL! " ) ;
}
2010-03-17 07:25:19 +01:00
program - > keyDown ( key ) ;
2010-04-02 19:37:04 +02:00
2010-04-06 16:25:00 +02:00
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2010-04-02 19:37:04 +02:00
2010-07-08 00:25:29 +02:00
if ( keystate . mod & ( KMOD_LALT | KMOD_RALT ) ) {
if ( key = = vkReturn ) {
2010-04-02 19:37:04 +02:00
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] ALT-ENTER pressed \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2010-04-05 22:42:05 +02:00
// This stupidity only required in win32.
// We reload the textures so that
# ifdef WIN32
2010-06-30 21:27:07 +02:00
if ( Window : : getAllowAltEnterFullscreenToggle ( ) = = true ) {
Renderer & renderer = Renderer : : getInstance ( ) ;
renderer . reinitAll ( ) ;
}
2010-04-05 22:42:05 +02:00
# endif
2010-04-02 19:37:04 +02:00
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
}
}
2010-04-11 03:25:06 +02:00
2010-07-29 07:24:51 +02:00
if ( program ! = NULL & & program - > isInSpecialKeyCaptureEvent ( ) = = false ) {
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
Config & configKeys = Config : : getInstance ( std : : pair < ConfigType , ConfigType > ( cfgMainKeys , cfgUserKeys ) ) ;
if ( key = = configKeys . getCharKey ( " HotKeyShowDebug " ) ) {
Renderer & renderer = Renderer : : getInstance ( ) ;
bool showDebugUI = renderer . getShowDebugUI ( ) ;
renderer . setShowDebugUI ( ! showDebugUI ) ;
}
2010-07-06 17:11:10 +02:00
}
2010-04-11 03:25:06 +02:00
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2010-03-17 07:25:19 +01:00
}
void MainWindow : : eventKeyUp ( char key ) {
2010-07-06 07:30:34 +02:00
if ( program = = NULL ) {
throw runtime_error ( " In [MainWindow::eventKeyUp] ERROR, program == NULL! " ) ;
}
2010-03-17 07:25:19 +01:00
program - > keyUp ( key ) ;
}
void MainWindow : : eventKeyPress ( char c ) {
2010-07-06 07:30:34 +02:00
if ( program = = NULL ) {
throw runtime_error ( " In [MainWindow::eventKeyPress] ERROR, program == NULL! " ) ;
}
2010-03-17 07:25:19 +01:00
program - > keyPress ( c ) ;
2010-06-30 09:03:04 +02:00
2010-07-29 17:49:06 +02:00
if ( program ! = NULL & & program - > isInSpecialKeyCaptureEvent ( ) = = false ) {
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
Config & configKeys = Config : : getInstance ( std : : pair < ConfigType , ConfigType > ( cfgMainKeys , cfgUserKeys ) ) ;
if ( c = = configKeys . getCharKey ( " HotKeyToggleOSMouseEnabled " ) ) {
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2010-06-30 09:03:04 +02:00
2010-07-29 17:49:06 +02:00
bool showCursorState = false ;
int state = SDL_ShowCursor ( SDL_QUERY ) ;
if ( state = = SDL_DISABLE ) {
showCursorState = true ;
}
2010-07-08 00:25:29 +02:00
2010-07-29 17:49:06 +02:00
showCursor ( showCursorState ) ;
Renderer & renderer = Renderer : : getInstance ( ) ;
renderer . setNo2DMouseRendering ( showCursorState ) ;
Window : : lastShowMouseState = SDL_ShowCursor ( SDL_QUERY ) ;
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] Window::lastShowMouseState = %d \n " , __FILE__ , __FUNCTION__ , __LINE__ , Window : : lastShowMouseState ) ;
}
2010-06-30 09:03:04 +02:00
}
2010-03-17 07:25:19 +01:00
}
void MainWindow : : eventActivate ( bool active ) {
if ( ! active ) {
//minimize();
}
}
void MainWindow : : eventResize ( SizeState sizeState ) {
2010-07-06 07:30:34 +02:00
if ( program = = NULL ) {
throw runtime_error ( " In [MainWindow::eventResize] ERROR, program == NULL! " ) ;
}
2010-03-17 07:25:19 +01:00
program - > resize ( sizeState ) ;
}
void MainWindow : : eventClose ( ) {
delete program ;
program = NULL ;
}
2010-04-01 09:46:14 +02:00
void MainWindow : : setProgram ( Program * program ) {
this - > program = program ;
}
2010-03-17 07:25:19 +01:00
// =====================================================
// Main
// =====================================================
2010-04-13 18:00:19 +02:00
SystemFlags debugger ;
2010-03-17 07:25:19 +01:00
2010-08-22 11:06:26 +02:00
bool hasCommandArgument ( int argc , char * * argv , const string argName , int * foundIndex = NULL , int startLookupIndex = 1 , bool useArgParamLen = false ) {
2010-06-15 18:27:52 +02:00
bool result = false ;
2010-08-21 03:54:04 +02:00
if ( foundIndex ! = NULL ) {
* foundIndex = - 1 ;
}
int compareLen = strlen ( argName . c_str ( ) ) ;
2010-08-22 10:54:12 +02:00
2010-08-22 10:40:18 +02:00
for ( int idx = startLookupIndex ; idx < argc ; idx + + ) {
2010-08-22 10:54:12 +02:00
if ( useArgParamLen = = true ) {
compareLen = strlen ( argv [ idx ] ) ;
}
2010-08-21 05:18:10 +02:00
if ( strnicmp ( argName . c_str ( ) , argv [ idx ] , compareLen ) = = 0 ) {
2010-06-15 18:27:52 +02:00
result = true ;
2010-08-21 03:54:04 +02:00
if ( foundIndex ! = NULL ) {
* foundIndex = idx ;
}
2010-06-15 18:27:52 +02:00
break ;
}
}
return result ;
}
2010-08-26 18:03:54 +02:00
void print_SDL_version ( char * preamble , SDL_version * v ) {
printf ( " %s %u.%u.%u \n " , preamble , v - > major , v - > minor , v - > patch ) ;
}
2010-08-22 11:06:26 +02:00
int glestMain ( int argc , char * * argv ) {
2010-05-01 11:10:52 +02:00
# ifdef SL_LEAK_DUMP
AllocRegistry memoryLeaks = AllocRegistry : : getInstance ( ) ;
# endif
2010-08-22 10:40:18 +02:00
bool foundInvalidArgs = false ;
const int knownArgCount = sizeof ( GAME_ARGS ) / sizeof ( GAME_ARGS [ 0 ] ) ;
for ( int idx = 1 ; idx < argc ; + + idx ) {
2010-08-22 11:06:26 +02:00
if ( hasCommandArgument ( knownArgCount , ( char * * ) & GAME_ARGS [ 0 ] , argv [ idx ] , NULL , 0 , true ) = = false ) {
2010-08-22 10:40:18 +02:00
foundInvalidArgs = true ;
2010-08-22 10:45:19 +02:00
printf ( " \n Invalid argument: %s " , argv [ idx ] ) ;
2010-08-22 10:40:18 +02:00
}
}
if ( hasCommandArgument ( argc , argv , GAME_ARGS [ GAME_ARG_HELP ] ) = = true | |
foundInvalidArgs = = true ) {
2010-08-22 10:45:19 +02:00
if ( foundInvalidArgs = = true ) {
printf ( " \n " ) ;
}
2010-08-21 03:54:04 +02:00
printf ( " \n %s, usage \n \n " , argv [ 0 ] ) ;
printf ( " Commandline Parameter: \t \t Description: " ) ;
printf ( " \n ---------------------- \t \t ------------ " ) ;
2010-08-21 08:11:45 +02:00
printf ( " \n %s \t \t \t \t displays this help text. " , GAME_ARGS [ GAME_ARG_HELP ] ) ;
2010-08-21 08:47:00 +02:00
printf ( " \n %s=x \t \t \t Auto connects to a network server at IP or hostname x " , GAME_ARGS [ GAME_ARG_CLIENT ] ) ;
printf ( " \n %s \t \t \t Auto creates a network server. " , GAME_ARGS [ GAME_ARG_SERVER ] ) ;
2010-08-21 08:11:45 +02:00
printf ( " \n %s \t \t \t displays the version string of this program. " , GAME_ARGS [ GAME_ARG_VERSION ] ) ;
printf ( " \n %s \t \t \t displays your video driver's OpenGL information. " , GAME_ARGS [ GAME_ARG_OPENGL_INFO ] ) ;
2010-08-26 18:03:54 +02:00
printf ( " \n %s \t \t \t displays your SDL version information. " , GAME_ARGS [ GAME_ARG_SDL_INFO ] ) ;
2010-08-21 08:11:45 +02:00
printf ( " \n %s=x \t \t displays a report detailing any known problems related " , GAME_ARGS [ GAME_ARG_VALIDATE_TECHTREES ] ) ;
2010-08-21 04:13:50 +02:00
printf ( " \n \t \t to your selected techtrees game data. " ) ;
printf ( " \n \t \t Where x is a comma-delimited list of techtrees to validate. " ) ;
2010-08-21 08:11:45 +02:00
printf ( " \n \t \t example: %s %s=megapack,vbros_pack_5 " , argv [ 0 ] , GAME_ARGS [ GAME_ARG_VALIDATE_TECHTREES ] ) ;
printf ( " \n %s=x \t \t displays a report detailing any known problems related " , GAME_ARGS [ GAME_ARG_VALIDATE_FACTIONS ] ) ;
2010-08-21 03:54:04 +02:00
printf ( " \n \t \t to your selected factions game data. " ) ;
printf ( " \n \t \t Where x is a comma-delimited list of factions to validate. " ) ;
2010-08-21 04:13:50 +02:00
printf ( " \n \t \t *NOTE: leaving the list empty is the same as running " ) ;
2010-08-21 08:11:45 +02:00
printf ( " \n \t \t %s " , GAME_ARGS [ GAME_ARG_VALIDATE_TECHTREES ] ) ;
printf ( " \n \t \t example: %s %s=tech,egypt " , argv [ 0 ] , GAME_ARGS [ GAME_ARG_VALIDATE_FACTIONS ] ) ;
2010-08-21 03:54:04 +02:00
printf ( " \n \n " ) ;
return - 1 ;
}
2010-07-12 08:30:54 +02:00
bool haveSpecialOutputCommandLineOption = false ;
2010-08-21 03:54:04 +02:00
2010-08-21 08:11:45 +02:00
if ( hasCommandArgument ( argc , argv , GAME_ARGS [ GAME_ARG_OPENGL_INFO ] ) = = true | |
2010-08-26 18:03:54 +02:00
hasCommandArgument ( argc , argv , GAME_ARGS [ GAME_ARG_SDL_INFO ] ) = = true | |
2010-08-21 08:11:45 +02:00
hasCommandArgument ( argc , argv , GAME_ARGS [ GAME_ARG_VERSION ] ) = = true | |
hasCommandArgument ( argc , argv , GAME_ARGS [ GAME_ARG_VALIDATE_TECHTREES ] ) = = true | |
hasCommandArgument ( argc , argv , GAME_ARGS [ GAME_ARG_VALIDATE_FACTIONS ] ) = = true ) {
2010-07-12 08:30:54 +02:00
haveSpecialOutputCommandLineOption = true ;
}
if ( haveSpecialOutputCommandLineOption = = false | |
2010-08-21 08:11:45 +02:00
hasCommandArgument ( argc , argv , GAME_ARGS [ GAME_ARG_VERSION ] ) = = true ) {
2010-05-01 22:14:25 +02:00
# ifdef USE_STREFLOP
2010-05-02 05:48:40 +02:00
streflop_init < streflop : : Simple > ( ) ;
2010-04-24 05:57:38 +02:00
printf ( " %s, STREFLOP enabled. \n " , getNetworkVersionString ( ) . c_str ( ) ) ;
# else
2010-05-01 22:14:25 +02:00
printf ( " %s, STREFLOP NOT enabled. \n " , getNetworkVersionString ( ) . c_str ( ) ) ;
2010-04-24 05:57:38 +02:00
# endif
2010-07-12 08:30:54 +02:00
}
2010-04-24 05:57:38 +02:00
2010-08-26 18:03:54 +02:00
if ( hasCommandArgument ( argc , argv , GAME_ARGS [ GAME_ARG_SDL_INFO ] ) = = true ) {
SDL_version ver ;
// Prints the compile time version
SDL_VERSION ( & ver ) ;
print_SDL_version ( " SDL compile-time version " , & ver ) ;
// Prints the run-time version
ver = * SDL_Linked_Version ( ) ;
print_SDL_version ( " SDL runtime version " , & ver ) ;
}
if ( ( hasCommandArgument ( argc , argv , GAME_ARGS [ GAME_ARG_VERSION ] ) = = true | |
hasCommandArgument ( argc , argv , GAME_ARGS [ GAME_ARG_SDL_INFO ] ) = = true ) & &
2010-08-21 08:11:45 +02:00
hasCommandArgument ( argc , argv , GAME_ARGS [ GAME_ARG_OPENGL_INFO ] ) = = false & &
hasCommandArgument ( argc , argv , GAME_ARGS [ GAME_ARG_VALIDATE_TECHTREES ] ) = = false & &
hasCommandArgument ( argc , argv , GAME_ARGS [ GAME_ARG_VALIDATE_FACTIONS ] ) = = false ) {
2010-06-15 18:27:52 +02:00
return - 1 ;
}
2010-07-12 08:30:54 +02:00
SystemFlags : : init ( haveSpecialOutputCommandLineOption ) ;
2010-04-27 05:36:36 +02:00
SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled = true ;
SystemFlags : : getSystemSettingType ( SystemFlags : : debugNetwork ) . enabled = true ;
2010-03-22 00:40:35 +01:00
2010-03-17 07:25:19 +01:00
MainWindow * mainWindow = NULL ;
Program * program = NULL ;
ExceptionHandler exceptionHandler ;
exceptionHandler . install ( getCrashDumpFileName ( ) ) ;
try {
2010-05-01 11:10:52 +02:00
std : : auto_ptr < FileCRCPreCacheThread > preCacheThread ;
2010-03-17 07:25:19 +01:00
Config & config = Config : : getInstance ( ) ;
2010-04-29 00:34:10 +02:00
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
2010-03-22 00:40:35 +01:00
2010-04-27 05:36:36 +02:00
SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled = config . getBool ( " DebugMode " , " false " ) ;
SystemFlags : : getSystemSettingType ( SystemFlags : : debugNetwork ) . enabled = config . getBool ( " DebugNetwork " , " false " ) ;
SystemFlags : : getSystemSettingType ( SystemFlags : : debugPerformance ) . enabled = config . getBool ( " DebugPerformance " , " false " ) ;
SystemFlags : : getSystemSettingType ( SystemFlags : : debugWorldSynch ) . enabled = config . getBool ( " DebugWorldSynch " , " false " ) ;
2010-06-08 09:40:32 +02:00
SystemFlags : : getSystemSettingType ( SystemFlags : : debugUnitCommands ) . enabled = config . getBool ( " DebugUnitCommands " , " false " ) ;
2010-07-24 13:43:03 +02:00
SystemFlags : : getSystemSettingType ( SystemFlags : : debugPathFinder ) . enabled = config . getBool ( " DebugPathFinder " , " false " ) ;
2010-04-27 05:36:36 +02:00
string debugLogFile = config . getString ( " DebugLogFile " , " " ) ;
2010-03-23 07:57:41 +01:00
if ( getGameReadWritePath ( ) ! = " " ) {
debugLogFile = getGameReadWritePath ( ) + debugLogFile ;
}
2010-04-29 00:34:10 +02:00
string debugWorldSynchLogFile = config . getString ( " DebugLogFileWorldSynch " , " " ) ;
2010-04-27 05:36:36 +02:00
if ( debugWorldSynchLogFile = = " " ) {
debugWorldSynchLogFile = debugLogFile ;
}
2010-05-06 23:29:46 +02:00
string debugPerformanceLogFile = config . getString ( " DebugLogFilePerformance " , " " ) ;
if ( debugPerformanceLogFile = = " " ) {
debugPerformanceLogFile = debugLogFile ;
}
string debugNetworkLogFile = config . getString ( " DebugLogFileNetwork " , " " ) ;
if ( debugNetworkLogFile = = " " ) {
debugNetworkLogFile = debugLogFile ;
}
2010-06-08 09:40:32 +02:00
string debugUnitCommandsLogFile = config . getString ( " DebugLogFileUnitCommands " , " " ) ;
if ( debugUnitCommandsLogFile = = " " ) {
debugUnitCommandsLogFile = debugLogFile ;
}
2010-07-24 13:43:03 +02:00
string debugPathFinderLogFile = config . getString ( " DebugLogFilePathFinder " , " " ) ;
if ( debugUnitCommandsLogFile = = " " ) {
debugUnitCommandsLogFile = debugLogFile ;
}
2010-04-27 05:36:36 +02:00
SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . debugLogFileName = debugLogFile ;
2010-05-06 23:29:46 +02:00
SystemFlags : : getSystemSettingType ( SystemFlags : : debugNetwork ) . debugLogFileName = debugNetworkLogFile ;
SystemFlags : : getSystemSettingType ( SystemFlags : : debugPerformance ) . debugLogFileName = debugPerformanceLogFile ;
2010-04-27 05:36:36 +02:00
SystemFlags : : getSystemSettingType ( SystemFlags : : debugWorldSynch ) . debugLogFileName = debugWorldSynchLogFile ;
2010-06-08 09:40:32 +02:00
SystemFlags : : getSystemSettingType ( SystemFlags : : debugUnitCommands ) . debugLogFileName = debugUnitCommandsLogFile ;
2010-07-24 13:43:03 +02:00
SystemFlags : : getSystemSettingType ( SystemFlags : : debugPathFinder ) . debugLogFileName = debugPathFinderLogFile ;
2010-03-20 00:26:00 +01:00
2010-07-12 08:30:54 +02:00
if ( haveSpecialOutputCommandLineOption = = false ) {
2010-07-24 13:43:03 +02:00
printf ( " Startup settings are: debugSystem [%d], debugNetwork [%d], debugPerformance [%d], debugWorldSynch [%d], debugUnitCommands[%d], debugPathFinder[%d] \n " ,
2010-07-12 08:30:54 +02:00
SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ,
SystemFlags : : getSystemSettingType ( SystemFlags : : debugNetwork ) . enabled ,
SystemFlags : : getSystemSettingType ( SystemFlags : : debugPerformance ) . enabled ,
SystemFlags : : getSystemSettingType ( SystemFlags : : debugWorldSynch ) . enabled ,
2010-07-24 13:43:03 +02:00
SystemFlags : : getSystemSettingType ( SystemFlags : : debugUnitCommands ) . enabled ,
SystemFlags : : getSystemSettingType ( SystemFlags : : debugPathFinder ) . enabled ) ;
2010-07-12 08:30:54 +02:00
}
2010-04-29 00:34:10 +02:00
2010-03-17 07:25:19 +01:00
NetworkInterface : : setDisplayMessageFunction ( ExceptionHandler : : DisplayMessage ) ;
2010-05-16 05:31:12 +02:00
MenuStateMasterserver : : setDisplayMessageFunction ( ExceptionHandler : : DisplayMessage ) ;
2010-07-08 00:25:29 +02:00
# ifdef USE_STREFLOP
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " %s, STREFLOP enabled. \n " , getNetworkVersionString ( ) . c_str ( ) ) ;
# else
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " %s, STREFLOP NOT enabled. \n " , getNetworkVersionString ( ) . c_str ( ) ) ;
# endif
2010-03-30 02:25:35 +02:00
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2010-06-08 09:40:32 +02:00
SystemFlags : : OutputDebug ( SystemFlags : : debugUnitCommands , " START \n " ) ;
2010-07-24 13:43:03 +02:00
SystemFlags : : OutputDebug ( SystemFlags : : debugPathFinder , " START \n " ) ;
2010-06-08 09:40:32 +02:00
2010-05-03 08:16:32 +02:00
// 256 for English
// 30000 for Chinese
2010-05-03 08:25:54 +02:00
Font : : charCount = config . getInt ( " FONT_CHARCOUNT " , intToStr ( Font : : charCount ) . c_str ( ) ) ;
Font : : fontTypeName = config . getString ( " FONT_TYPENAME " , Font : : fontTypeName . c_str ( ) ) ;
2010-05-03 08:16:32 +02:00
// Example values:
// DEFAULT_CHARSET (English) = 1
// GB2312_CHARSET (Chinese) = 134
2010-05-03 08:25:54 +02:00
Shared : : Platform : : charSet = config . getInt ( " FONT_CHARSET " , intToStr ( Shared : : Platform : : charSet ) . c_str ( ) ) ;
2010-05-03 08:16:32 +02:00
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] Font::charCount = %d, Font::fontTypeName [%s] Shared::Platform::charSet = %d \n " , __FILE__ , __FUNCTION__ , __LINE__ , Font : : charCount , Font : : fontTypeName . c_str ( ) , Shared : : Platform : : charSet ) ;
2010-06-12 20:27:39 +02:00
Config & configKeys = Config : : getInstance (
std : : pair < ConfigType , ConfigType > ( cfgMainKeys , cfgUserKeys ) ,
std : : pair < string , string > ( " glestkeys.ini " , " glestuserkeys.ini " ) ,
std : : pair < bool , bool > ( true , false ) ) ;
2010-06-24 03:23:18 +02:00
if ( config . getBool ( " No2DMouseRendering " , " false " ) = = false ) {
showCursor ( false ) ;
}
2010-07-07 20:50:55 +02:00
if ( config . getInt ( " DEFAULT_HTTP_TIMEOUT " , intToStr ( SystemFlags : : DEFAULT_HTTP_TIMEOUT ) . c_str ( ) ) > = 0 ) {
SystemFlags : : DEFAULT_HTTP_TIMEOUT = config . getInt ( " DEFAULT_HTTP_TIMEOUT " , intToStr ( SystemFlags : : DEFAULT_HTTP_TIMEOUT ) . c_str ( ) ) ;
}
2010-06-30 21:27:07 +02:00
bool allowAltEnterFullscreenToggle = config . getBool ( " AllowAltEnterFullscreenToggle " , boolToStr ( Window : : getAllowAltEnterFullscreenToggle ( ) ) . c_str ( ) ) ;
Window : : setAllowAltEnterFullscreenToggle ( allowAltEnterFullscreenToggle ) ;
2010-03-17 07:25:19 +01:00
2010-05-21 18:36:08 +02:00
if ( config . getBool ( " noTeamColors " , " false " ) = = true ) {
MeshCallbackTeamColor : : noTeamColors = true ;
}
2010-06-05 09:52:14 +02:00
// Over-ride default network command framecount
2010-07-27 20:56:12 +02:00
//GameConstants::networkFramePeriod = config.getInt("NetworkFramePeriod",intToStr(GameConstants::networkFramePeriod).c_str());
2010-06-05 09:52:14 +02:00
2010-06-04 21:42:58 +02:00
//float pingTime = Socket::getAveragePingMS("soft-haus.com");
//printf("Ping time = %f\n",pingTime);
2010-03-17 07:25:19 +01:00
program = new Program ( ) ;
2010-03-30 02:25:35 +02:00
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2010-03-17 07:25:19 +01:00
mainWindow = new MainWindow ( program ) ;
2010-06-24 03:23:18 +02:00
mainWindow - > setUseDefaultCursorOnly ( config . getBool ( " No2DMouseRendering " , " false " ) ) ;
2010-03-30 02:25:35 +02:00
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2010-03-17 07:25:19 +01:00
//parse command line
2010-08-21 08:47:00 +02:00
if ( hasCommandArgument ( argc , argv , GAME_ARGS [ GAME_ARG_SERVER ] ) = = true ) {
2010-03-17 07:25:19 +01:00
program - > initServer ( mainWindow ) ;
}
2010-08-21 08:47:00 +02:00
else if ( hasCommandArgument ( argc , argv , string ( GAME_ARGS [ GAME_ARG_CLIENT ] ) + string ( " = " ) ) = = true ) {
int foundParamIndIndex = - 1 ;
hasCommandArgument ( argc , argv , string ( GAME_ARGS [ GAME_ARG_CLIENT ] ) + string ( " = " ) , & foundParamIndIndex ) ;
string serverToConnectTo = argv [ foundParamIndIndex ] ;
vector < string > paramPartTokens ;
Tokenize ( serverToConnectTo , paramPartTokens , " = " ) ;
if ( paramPartTokens . size ( ) > = 2 ) {
string autoConnectServer = paramPartTokens [ 1 ] ;
program - > initClient ( mainWindow , autoConnectServer ) ;
}
2010-03-17 07:25:19 +01:00
}
else {
program - > initNormal ( mainWindow ) ;
}
2010-03-27 19:35:47 +01:00
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2010-07-22 00:42:06 +02:00
Renderer & renderer = Renderer : : getInstance ( ) ;
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] OpenGL Info: \n %s \n " , __FILE__ , __FUNCTION__ , __LINE__ , renderer . getGlInfo ( ) . c_str ( ) ) ;
2010-08-21 08:11:45 +02:00
if ( hasCommandArgument ( argc , argv , GAME_ARGS [ GAME_ARG_OPENGL_INFO ] ) = = true ) {
2010-08-21 08:47:00 +02:00
//Renderer &renderer= Renderer::getInstance();
2010-07-22 00:42:06 +02:00
printf ( " %s " , renderer . getGlInfo ( ) . c_str ( ) ) ;
2010-08-03 03:58:43 +02:00
delete mainWindow ;
2010-07-22 00:42:06 +02:00
return - 1 ;
}
2010-08-21 08:11:45 +02:00
if ( hasCommandArgument ( argc , argv , GAME_ARGS [ GAME_ARG_VALIDATE_TECHTREES ] ) = = true | |
hasCommandArgument ( argc , argv , GAME_ARGS [ GAME_ARG_VALIDATE_FACTIONS ] ) = = true ) {
2010-07-30 09:51:39 +02:00
2010-07-30 20:20:20 +02:00
printf ( " ====== Started Validation ====== \n " ) ;
2010-08-21 03:54:04 +02:00
// Did the user pass a specific list of factions to validate?
std : : vector < string > filteredFactionList ;
2010-08-24 21:33:10 +02:00
if ( hasCommandArgument ( argc , argv , string ( GAME_ARGS [ GAME_ARG_VALIDATE_FACTIONS ] ) + string ( " = " ) ) = = true ) {
2010-08-21 03:54:04 +02:00
int foundParamIndIndex = - 1 ;
2010-08-21 08:11:45 +02:00
hasCommandArgument ( argc , argv , string ( GAME_ARGS [ GAME_ARG_VALIDATE_FACTIONS ] ) + string ( " = " ) , & foundParamIndIndex ) ;
2010-08-24 21:33:10 +02:00
2010-08-21 03:54:04 +02:00
string filterList = argv [ foundParamIndIndex ] ;
vector < string > paramPartTokens ;
Tokenize ( filterList , paramPartTokens , " = " ) ;
2010-08-24 21:33:10 +02:00
2010-08-21 03:54:04 +02:00
if ( paramPartTokens . size ( ) > = 2 ) {
string factionList = paramPartTokens [ 1 ] ;
Tokenize ( factionList , filteredFactionList , " , " ) ;
if ( filteredFactionList . size ( ) > 0 ) {
printf ( " Filtering factions and only looking for the following: \n " ) ;
for ( int idx = 0 ; idx < filteredFactionList . size ( ) ; + + idx ) {
filteredFactionList [ idx ] = trim ( filteredFactionList [ idx ] ) ;
printf ( " %s \n " , filteredFactionList [ idx ] . c_str ( ) ) ;
}
}
}
}
2010-07-30 09:51:39 +02:00
Config & config = Config : : getInstance ( ) ;
vector < string > results ;
findDirs ( config . getPathListForType ( ptTechs ) , results ) ;
vector < string > techTreeFiles = results ;
2010-08-21 04:13:50 +02:00
// Did the user pass a specific list of techtrees to validate?
std : : vector < string > filteredTechTreeList ;
2010-08-21 08:11:45 +02:00
if ( hasCommandArgument ( argc , argv , string ( GAME_ARGS [ GAME_ARG_VALIDATE_TECHTREES ] ) + string ( " = " ) ) = = true ) {
2010-08-21 04:13:50 +02:00
int foundParamIndIndex = - 1 ;
2010-08-21 08:11:45 +02:00
hasCommandArgument ( argc , argv , string ( GAME_ARGS [ GAME_ARG_VALIDATE_TECHTREES ] ) + string ( " = " ) , & foundParamIndIndex ) ;
2010-08-21 04:13:50 +02:00
string filterList = argv [ foundParamIndIndex ] ;
vector < string > paramPartTokens ;
Tokenize ( filterList , paramPartTokens , " = " ) ;
if ( paramPartTokens . size ( ) > = 2 ) {
string techtreeList = paramPartTokens [ 1 ] ;
Tokenize ( techtreeList , filteredTechTreeList , " , " ) ;
if ( filteredTechTreeList . size ( ) > 0 ) {
printf ( " Filtering techtrees and only looking for the following: \n " ) ;
for ( int idx = 0 ; idx < filteredTechTreeList . size ( ) ; + + idx ) {
filteredTechTreeList [ idx ] = trim ( filteredTechTreeList [ idx ] ) ;
printf ( " %s \n " , filteredTechTreeList [ idx ] . c_str ( ) ) ;
}
}
}
}
2010-08-03 03:58:43 +02:00
{
2010-08-26 06:17:09 +02:00
printf ( " \n ---------------- Loading factions inside world ---------------- " ) ;
2010-07-30 09:51:39 +02:00
World world ;
vector < string > techPaths = config . getPathListForType ( ptTechs ) ;
for ( int idx = 0 ; idx < techPaths . size ( ) ; idx + + ) {
string & techPath = techPaths [ idx ] ;
for ( int idx2 = 0 ; idx2 < techTreeFiles . size ( ) ; idx2 + + ) {
string & techName = techTreeFiles [ idx2 ] ;
2010-08-21 04:13:50 +02:00
if ( filteredTechTreeList . size ( ) = = 0 | |
std : : find ( filteredTechTreeList . begin ( ) , filteredTechTreeList . end ( ) , techName ) ! = filteredTechTreeList . end ( ) ) {
vector < string > factionsList ;
findAll ( techPath + " / " + techName + " /factions/*. " , factionsList , false , false ) ;
2010-07-30 09:51:39 +02:00
2010-08-21 04:13:50 +02:00
if ( factionsList . size ( ) > 0 ) {
Checksum checksum ;
set < string > factions ;
for ( int j = 0 ; j < factionsList . size ( ) ; + + j ) {
if ( filteredFactionList . size ( ) = = 0 | |
std : : find ( filteredFactionList . begin ( ) , filteredFactionList . end ( ) , factionsList [ j ] ) ! = filteredFactionList . end ( ) ) {
factions . insert ( factionsList [ j ] ) ;
}
2010-08-21 03:54:04 +02:00
}
2010-07-30 09:51:39 +02:00
2010-08-26 06:31:48 +02:00
printf ( " \n ---------------------------------------------------------------- " ) ;
2010-08-26 06:17:09 +02:00
printf ( " \n Checking techPath [%s] techName [%s] total faction count = %d \n " , techPath . c_str ( ) , techName . c_str ( ) , factionsList . size ( ) ) ;
2010-08-21 04:13:50 +02:00
for ( int j = 0 ; j < factionsList . size ( ) ; + + j ) {
if ( filteredFactionList . size ( ) = = 0 | |
std : : find ( filteredFactionList . begin ( ) , filteredFactionList . end ( ) , factionsList [ j ] ) ! = filteredFactionList . end ( ) ) {
2010-08-26 06:17:09 +02:00
printf ( " Using faction [%s] \n " , factionsList [ j ] . c_str ( ) ) ;
2010-08-21 04:13:50 +02:00
}
2010-08-21 03:54:04 +02:00
}
2010-07-30 09:51:39 +02:00
2010-08-26 06:31:48 +02:00
if ( factions . size ( ) > 0 ) {
bool techtree_errors = false ;
world . loadTech ( config . getPathListForType ( ptTechs , " " ) , techName , factions , & checksum ) ;
// Validate the faction setup to ensure we don't have any bad associations
std : : vector < std : : string > resultErrors = world . validateFactionTypes ( ) ;
if ( resultErrors . size ( ) > 0 ) {
techtree_errors = true ;
// Display the validation errors
string errorText = " \n Errors were detected: \n ===================== \n " ;
for ( int i = 0 ; i < resultErrors . size ( ) ; + + i ) {
if ( i > 0 ) {
errorText + = " \n " ;
}
errorText + = resultErrors [ i ] ;
2010-08-21 04:13:50 +02:00
}
2010-08-26 06:31:48 +02:00
errorText + = " \n ===================== \n " ;
//throw runtime_error(errorText);
printf ( " %s " , errorText . c_str ( ) ) ;
2010-07-30 09:51:39 +02:00
}
2010-08-26 06:31:48 +02:00
// Validate the faction resource setup to ensure we don't have any bad associations
printf ( " \n Checking resources, count = %d \n " , world . getTechTree ( ) - > getResourceTypeCount ( ) ) ;
2010-07-30 09:51:39 +02:00
2010-08-26 06:31:48 +02:00
for ( int i = 0 ; i < world . getTechTree ( ) - > getResourceTypeCount ( ) ; + + i ) {
printf ( " Found techtree resource [%s] \n " , world . getTechTree ( ) - > getResourceType ( i ) - > getName ( ) . c_str ( ) ) ;
}
2010-07-30 09:51:39 +02:00
2010-08-26 06:31:48 +02:00
resultErrors = world . validateResourceTypes ( ) ;
if ( resultErrors . size ( ) > 0 ) {
techtree_errors = true ;
// Display the validation errors
string errorText = " \n Errors were detected: \n ===================== \n " ;
for ( int i = 0 ; i < resultErrors . size ( ) ; + + i ) {
if ( i > 0 ) {
errorText + = " \n " ;
}
errorText + = resultErrors [ i ] ;
2010-08-21 04:13:50 +02:00
}
2010-08-26 06:31:48 +02:00
errorText + = " \n ===================== \n " ;
//throw runtime_error(errorText);
printf ( " %s " , errorText . c_str ( ) ) ;
2010-07-30 09:51:39 +02:00
}
2010-08-26 06:17:09 +02:00
2010-08-26 06:31:48 +02:00
if ( techtree_errors = = false ) {
printf ( " \n Validation found NO ERRORS for techPath [%s] techName [%s] factions checked (count = %d): \n " , techPath . c_str ( ) , techName . c_str ( ) , factions . size ( ) ) ;
for ( set < string > : : iterator it = factions . begin ( ) ; it ! = factions . end ( ) ; + + it ) {
printf ( " Faction [%s] \n " , ( * it ) . c_str ( ) ) ;
}
2010-08-26 06:17:09 +02:00
}
}
2010-08-26 06:31:48 +02:00
printf ( " ---------------------------------------------------------------- " ) ;
2010-07-30 09:51:39 +02:00
}
}
}
}
2010-07-30 20:20:20 +02:00
printf ( " \n ====== Finished Validation ====== \n " ) ;
2010-08-03 03:58:43 +02:00
}
2010-07-30 20:20:20 +02:00
2010-08-03 03:58:43 +02:00
delete mainWindow ;
2010-07-30 09:51:39 +02:00
return - 1 ;
}
2010-07-22 00:42:06 +02:00
2010-07-30 19:20:13 +02:00
gameInitialized = true ;
2010-08-02 05:15:11 +02:00
string screenShotsPath = GameConstants : : folder_path_screenshots ;
2010-08-17 22:58:30 +02:00
//printf("In [%s::%s Line: %d] screenShotsPath [%s]\n",__FILE__,__FUNCTION__,__LINE__,screenShotsPath.c_str());
2010-08-02 05:15:11 +02:00
if ( isdir ( screenShotsPath . c_str ( ) ) = = false ) {
createDirectoryPaths ( screenShotsPath ) ;
2010-08-17 22:58:30 +02:00
//printf("In [%s::%s Line: %d] screenShotsPath [%s]\n",__FILE__,__FUNCTION__,__LINE__,screenShotsPath.c_str());
2010-08-02 05:15:11 +02:00
}
2010-04-30 08:45:30 +02:00
if ( config . getBool ( " AllowGameDataSynchCheck " , " false " ) = = true ) {
2010-05-01 00:54:24 +02:00
vector < string > techDataPaths = config . getPathListForType ( ptTechs ) ;
2010-05-01 11:10:52 +02:00
preCacheThread . reset ( new FileCRCPreCacheThread ( ) ) ;
2010-06-18 22:04:05 +02:00
preCacheThread - > setUniqueID ( __FILE__ ) ;
2010-05-01 11:10:52 +02:00
preCacheThread - > setTechDataPaths ( techDataPaths ) ;
preCacheThread - > start ( ) ;
2010-04-30 08:45:30 +02:00
}
2010-03-17 07:25:19 +01:00
// test
//Shared::Platform::MessageBox(NULL,"Mark's test.","Test",0);
//throw runtime_error("test!");
//ExceptionHandler::DisplayMessage("test!", false);
2010-07-03 08:48:24 +02:00
//Lang &lang= Lang::getInstance();
//string test = lang.get("ExitGameServer?");
//printf("[%s]",test.c_str());
2010-03-17 07:25:19 +01:00
//main loop
while ( Window : : handleEvent ( ) ) {
program - > loop ( ) ;
}
2010-05-01 11:10:52 +02:00
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2010-03-17 07:25:19 +01:00
}
catch ( const exception & e ) {
ExceptionHandler : : handleRuntimeError ( e . what ( ) ) ;
}
2010-04-09 09:44:23 +02:00
catch ( const char * e ) {
ExceptionHandler : : handleRuntimeError ( e ) ;
}
catch ( const string & ex ) {
ExceptionHandler : : handleRuntimeError ( ex . c_str ( ) ) ;
}
catch ( . . . ) {
ExceptionHandler : : handleRuntimeError ( " Unknown error! " ) ;
}
2010-03-17 07:25:19 +01:00
2010-05-01 11:10:52 +02:00
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2010-04-30 08:45:30 +02:00
2010-03-27 19:35:47 +01:00
//SoundRenderer &soundRenderer= SoundRenderer::getInstance();
//soundRenderer.stopAllSounds();
2010-03-17 07:25:19 +01:00
delete mainWindow ;
2010-03-27 19:35:47 +01:00
2010-05-01 11:10:52 +02:00
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2010-03-23 08:59:24 +01:00
//SystemFlags::Close();
2010-03-17 07:25:19 +01:00
return 0 ;
}
} } //end namespace
MAIN_FUNCTION ( Glest : : Game : : glestMain )