2010-03-13 10:39:22 +00:00
# include "main.h"
# include <stdexcept>
2010-03-13 22:00:01 +00:00
# include "model_gl.h"
2010-03-13 10:39:22 +00:00
# include "graphics_interface.h"
# include "util.h"
# include "conversion.h"
2010-05-25 18:06:42 +00:00
# include "platform_common.h"
# include "xml_parser.h"
2010-05-25 18:51:35 +00:00
# include <iostream>
2010-06-24 14:00:20 +00:00
# include <wx/event.h>
2011-03-10 17:59:40 +00:00
# include "config.h"
2010-08-25 18:26:17 +00:00
# include "game_constants.h"
2011-03-12 02:28:00 +00:00
# include <wx/stdpaths.h>
//#include <wx/filename.h>
2011-01-29 03:53:05 +00:00
2011-01-28 01:41:30 +00:00
# ifndef WIN32
# define stricmp strcasecmp
# define strnicmp strncasecmp
# define _strnicmp strncasecmp
# endif
2010-03-13 10:39:22 +00:00
using namespace Shared : : Platform ;
2010-05-25 18:06:42 +00:00
using namespace Shared : : PlatformCommon ;
2010-03-13 10:39:22 +00:00
using namespace Shared : : Graphics ;
using namespace Shared : : Graphics : : Gl ;
using namespace Shared : : Util ;
2010-05-25 18:06:42 +00:00
using namespace Shared : : Xml ;
2010-03-13 10:39:22 +00:00
using namespace std ;
2010-08-25 18:26:17 +00:00
using namespace Glest : : Game ;
2010-03-13 10:39:22 +00:00
2010-06-24 13:18:11 +00:00
# ifdef _WIN32
const char * folderDelimiter = " \\ " ;
# else
const char * folderDelimiter = " / " ;
# endif
2011-03-10 17:59:40 +00:00
//int GameConstants::updateFps= 40;
//int GameConstants::cameraFps= 100;
2010-08-25 18:26:17 +00:00
2011-01-28 01:41:30 +00:00
const string g3dviewerVersionString = " v1.3.6 " ;
2011-03-10 17:59:40 +00:00
namespace Glest { namespace Game {
string getGameReadWritePath ( string lookupKey ) {
string path = " " ;
if ( path = = " " & & getenv ( " GLESTHOME " ) ! = NULL ) {
path = getenv ( " GLESTHOME " ) ;
if ( path ! = " " & & EndsWith ( path , " / " ) = = false & & EndsWith ( path , " \\ " ) = = false ) {
path + = " / " ;
}
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] path to be used for read/write files [%s]\n",__FILE__,__FUNCTION__,__LINE__,path.c_str());
}
return path ;
}
} }
2010-03-13 10:39:22 +00:00
namespace Shared { namespace G3dViewer {
// ===============================================
// class Global functions
// ===============================================
wxString ToUnicode ( const char * str ) {
return wxString ( str , wxConvUTF8 ) ;
}
wxString ToUnicode ( const string & str ) {
return wxString ( str . c_str ( ) , wxConvUTF8 ) ;
}
2011-01-28 01:41:30 +00:00
const wxChar * GAME_ARGS [ ] = {
wxT ( " --help " ) ,
2011-01-28 05:49:52 +00:00
wxT ( " --auto-screenshot " ) ,
2011-01-29 03:53:05 +00:00
wxT ( " --load-unit " ) ,
2011-01-28 05:49:52 +00:00
wxT ( " --load-model " ) ,
wxT ( " --load-model-animation-value " ) ,
wxT ( " --load-particle " ) ,
wxT ( " --load-projectile-particle " ) ,
wxT ( " --load-splash-particle " ) ,
wxT ( " --load-particle-loop-value " ) ,
wxT ( " --zoom-value " ) ,
wxT ( " --rotate-x-value " ) ,
wxT ( " --rotate-y-value " ) ,
2011-01-28 01:41:30 +00:00
} ;
enum GAME_ARG_TYPE {
GAME_ARG_HELP = 0 ,
GAME_ARG_AUTO_SCREENSHOT ,
2011-01-29 03:53:05 +00:00
GAME_ARG_LOAD_UNIT ,
2011-01-28 05:49:52 +00:00
GAME_ARG_LOAD_MODEL ,
GAME_ARG_LOAD_MODEL_ANIMATION_VALUE ,
GAME_ARG_LOAD_PARTICLE ,
GAME_ARG_LOAD_PARTICLE_PROJECTILE ,
GAME_ARG_LOAD_PARTICLE_SPLASH ,
GAME_ARG_LOAD_PARTICLE_LOOP_VALUE ,
GAME_ARG_ZOOM_VALUE ,
GAME_ARG_ROTATE_X_VALUE ,
GAME_ARG_ROTATE_Y_VALUE ,
2011-01-28 01:41:30 +00:00
} ;
bool hasCommandArgument ( int argc , wxChar * * argv , const string argName ,
int * foundIndex = NULL , int startLookupIndex = 1 ,
bool useArgParamLen = false ) {
bool result = false ;
if ( foundIndex ! = NULL ) {
* foundIndex = - 1 ;
}
2011-03-12 02:28:00 +00:00
size_t compareLen = strlen ( argName . c_str ( ) ) ;
2011-01-28 01:41:30 +00:00
for ( int idx = startLookupIndex ; idx < argc ; idx + + ) {
const wxWX2MBbuf tmp_buf = wxConvCurrent - > cWX2MB ( argv [ idx ] ) ;
//printf("tmp_buf [%s]\n",(const char *)tmp_buf);
if ( useArgParamLen = = true ) {
compareLen = strlen ( tmp_buf ) ;
}
if ( _strnicmp ( argName . c_str ( ) , tmp_buf , compareLen ) = = 0 ) {
result = true ;
if ( foundIndex ! = NULL ) {
* foundIndex = idx ;
}
break ;
}
}
return result ;
}
void printParameterHelp ( const char * argv0 , bool foundInvalidArgs ) {
if ( foundInvalidArgs = = true ) {
printf ( " \n " ) ;
}
2011-01-29 21:20:33 +00:00
printf ( " \n %s %s, [Using %s] usage: \n " , argv0 , g3dviewerVersionString . c_str ( ) , ( const char * ) wxConvCurrent - > cWX2MB ( wxVERSION_STRING ) ) ;
2011-01-28 01:41:30 +00:00
printf ( " \n %s [G3D FILE] \n \n " , argv0 ) ;
printf ( " Displays glest 3D-models and unit/projectile/splash particle systems. \n " ) ;
printf ( " rotate with left mouse button, zoom with right mouse button or mousewheel. \n " ) ;
printf ( " Use ctrl to load more than one particle system. \n " ) ;
printf ( " Press R to restart particles, this also reloads all files if they are changed. \n \n " ) ;
printf ( " optionally you may use any of the following: \n " ) ;
2011-01-28 05:49:52 +00:00
printf ( " Parameter: \t \t \t Description: " ) ;
printf ( " \n ---------------------- \t \t ------------ " ) ;
printf ( " \n %s \t \t \t \t displays this help text. " , ( const char * ) wxConvCurrent - > cWX2MB ( GAME_ARGS [ GAME_ARG_HELP ] ) ) ;
2011-01-29 03:53:05 +00:00
printf ( " \n %s=x \t \t \t Auto load the unit / skill information specified in path/filename x " , ( const char * ) wxConvCurrent - > cWX2MB ( GAME_ARGS [ GAME_ARG_LOAD_UNIT ] ) ) ;
2011-01-29 04:35:55 +00:00
printf ( " \n \t \t Where x is a g3d filename to load seperated with a comma and one or more skill names to try loading: " ) ;
2011-01-29 08:46:28 +00:00
printf ( " \n \t \t example: %s %s=techs/megapack/factions/tech/units/battle_machine,attack_skill,stop_skill " , argv0 , ( const char * ) wxConvCurrent - > cWX2MB ( GAME_ARGS [ GAME_ARG_LOAD_UNIT ] ) ) ;
2011-01-29 03:53:05 +00:00
2011-01-28 05:49:52 +00:00
printf ( " \n %s=x \t \t \t Auto load the model specified in path/filename x " , ( const char * ) wxConvCurrent - > cWX2MB ( GAME_ARGS [ GAME_ARG_LOAD_MODEL ] ) ) ;
2011-01-29 03:53:05 +00:00
printf ( " \n \t \t Where x is a g3d filename to load: " ) ;
2011-01-28 05:49:52 +00:00
printf ( " \n \t \t example: %s %s=techs/megapack/factions/tech/units/battle_machine/models/battle_machine_dying.g3d " , argv0 , ( const char * ) wxConvCurrent - > cWX2MB ( GAME_ARGS [ GAME_ARG_LOAD_MODEL ] ) ) ;
printf ( " \n %s=x \t \t Animation value when loading a model " , ( const char * ) wxConvCurrent - > cWX2MB ( GAME_ARGS [ GAME_ARG_LOAD_MODEL_ANIMATION_VALUE ] ) ) ;
printf ( " \n \t \t Where x is a decimal value from -1.0 to 1.0: " ) ;
printf ( " \n \t \t example: %s %s=0.5 " , argv0 , ( const char * ) wxConvCurrent - > cWX2MB ( GAME_ARGS [ GAME_ARG_LOAD_MODEL_ANIMATION_VALUE ] ) ) ;
printf ( " \n %s=x \t \t Automatically takes a screenshot of the items you are loading. " , ( const char * ) wxConvCurrent - > cWX2MB ( GAME_ARGS [ GAME_ARG_AUTO_SCREENSHOT ] ) ) ;
printf ( " \n \t \t Where x is a comma-delimited list of one or more of the optional settings: " ) ;
printf ( " \n \t \t transparent, enable_grid, enable_wireframe, enable_normals, " ) ;
printf ( " \n \t \t disable_grid, disable_wireframe, disable_normals, saveas-<filename> " ) ;
printf ( " \n \t \t example: %s %s=transparent,disable_grid,saveas-test.png %s=techs/megapack/factions/tech/units/battle_machine/models/battle_machine_dying.g3d " , argv0 , ( const char * ) wxConvCurrent - > cWX2MB ( GAME_ARGS [ GAME_ARG_AUTO_SCREENSHOT ] ) , ( const char * ) wxConvCurrent - > cWX2MB ( GAME_ARGS [ GAME_ARG_LOAD_MODEL ] ) ) ;
printf ( " \n %s=x \t \t Auto load the particle specified in path/filename x " , ( const char * ) wxConvCurrent - > cWX2MB ( GAME_ARGS [ GAME_ARG_LOAD_PARTICLE ] ) ) ;
printf ( " \n \t \t Where x is a Particle Definition XML filename to load: " ) ;
printf ( " \n \t \t example: %s %s=techs/megapack/factions/persian/units/genie/glow_particles.xml " , argv0 , ( const char * ) wxConvCurrent - > cWX2MB ( GAME_ARGS [ GAME_ARG_LOAD_PARTICLE ] ) ) ;
printf ( " \n %s=x \t Auto load the projectile particle specified in path/filename x " , ( const char * ) wxConvCurrent - > cWX2MB ( GAME_ARGS [ GAME_ARG_LOAD_PARTICLE_PROJECTILE ] ) ) ;
printf ( " \n \t \t Where x is a Projectile Particle Definition XML filename to load: " ) ;
printf ( " \n \t \t example: %s %s=techs/megapack/factions/persian/units/genie/particle_proj.xml " , argv0 , ( const char * ) wxConvCurrent - > cWX2MB ( GAME_ARGS [ GAME_ARG_LOAD_PARTICLE_PROJECTILE ] ) ) ;
printf ( " \n %s=x \t Auto load the splash particle specified in path/filename x " , ( const char * ) wxConvCurrent - > cWX2MB ( GAME_ARGS [ GAME_ARG_LOAD_PARTICLE_SPLASH ] ) ) ;
printf ( " \n \t \t Where x is a Splash Particle Definition XML filename to load: " ) ;
printf ( " \n \t \t example: %s %s=techs/megapack/factions/persian/units/genie/particle_splash.xml " , argv0 , ( const char * ) wxConvCurrent - > cWX2MB ( GAME_ARGS [ GAME_ARG_LOAD_PARTICLE_SPLASH ] ) ) ;
printf ( " \n %s=x \t Particle loop value when loading one or more particles " , ( const char * ) wxConvCurrent - > cWX2MB ( GAME_ARGS [ GAME_ARG_LOAD_PARTICLE_LOOP_VALUE ] ) ) ;
printf ( " \n \t \t Where x is an integer value from 1 to particle count: " ) ;
printf ( " \n \t \t example: %s %s=25 " , argv0 , ( const char * ) wxConvCurrent - > cWX2MB ( GAME_ARGS [ GAME_ARG_LOAD_PARTICLE_LOOP_VALUE ] ) ) ;
printf ( " \n %s=x \t \t \t Zoom value when loading a model " , ( const char * ) wxConvCurrent - > cWX2MB ( GAME_ARGS [ GAME_ARG_ZOOM_VALUE ] ) ) ;
printf ( " \n \t \t Where x is a decimal value from 0.1 to 10.0: " ) ;
printf ( " \n \t \t example: %s %s=4.2 " , argv0 , ( const char * ) wxConvCurrent - > cWX2MB ( GAME_ARGS [ GAME_ARG_ZOOM_VALUE ] ) ) ;
printf ( " \n %s=x \t \t X Coordinate Rotation value when loading a model " , ( const char * ) wxConvCurrent - > cWX2MB ( GAME_ARGS [ GAME_ARG_ROTATE_X_VALUE ] ) ) ;
printf ( " \n \t \t Where x is a decimal value from -10.0 to 10.0: " ) ;
printf ( " \n \t \t example: %s %s=2.2 " , argv0 , ( const char * ) wxConvCurrent - > cWX2MB ( GAME_ARGS [ GAME_ARG_ROTATE_X_VALUE ] ) ) ;
printf ( " \n %s=x \t \t Y Coordinate Rotation value when loading a model " , ( const char * ) wxConvCurrent - > cWX2MB ( GAME_ARGS [ GAME_ARG_ROTATE_Y_VALUE ] ) ) ;
printf ( " \n \t \t Where x is a decimal value from -10.0 to 10.0: " ) ;
printf ( " \n \t \t example: %s %s=2.2 " , argv0 , ( const char * ) wxConvCurrent - > cWX2MB ( GAME_ARGS [ GAME_ARG_ROTATE_Y_VALUE ] ) ) ;
2011-01-28 01:41:30 +00:00
printf ( " \n \n " ) ;
}
bool autoScreenShotAndExit = false ;
vector < string > autoScreenShotParams ;
2010-03-13 10:39:22 +00:00
// ===============================================
// class MainWindow
// ===============================================
2010-12-03 05:07:42 +00:00
const string MainWindow : : winHeader = " G3D viewer " + g3dviewerVersionString ;
2010-03-13 10:39:22 +00:00
2011-01-29 04:35:55 +00:00
MainWindow : : MainWindow ( std : : pair < string , vector < string > > unitToLoad ,
2011-01-29 03:53:05 +00:00
const string modelPath ,
2011-01-28 05:49:52 +00:00
const string particlePath ,
const string projectileParticlePath ,
const string splashParticlePath ,
float defaultAnimation ,
int defaultParticleLoopStart ,
2011-03-05 23:15:07 +00:00
float defaultZoom , float defaultXRot , float defaultYRot ,
string appPath )
2011-01-29 08:46:28 +00:00
: wxFrame ( NULL , - 1 , ToUnicode ( winHeader ) ,
wxPoint ( Renderer : : windowX , Renderer : : windowY ) ,
2011-03-20 06:05:09 +00:00
wxSize ( Renderer : : windowW , Renderer : : windowH ) ) ,
model ( NULL ) , glCanvas ( NULL ) , renderer ( NULL ) ,
initTextureManager ( true ) , timer ( NULL ) ,
startupSettingsInited ( false )
2010-03-13 10:39:22 +00:00
{
2011-03-05 23:15:07 +00:00
this - > appPath = appPath ;
2011-03-10 19:19:14 +00:00
Properties : : setApplicationPath ( extractDirectoryPathFromFile ( appPath ) ) ;
2011-03-10 17:59:40 +00:00
Config & config = Config : : getInstance ( ) ;
2010-03-13 10:39:22 +00:00
//getGlPlatformExtensions();
2011-03-20 06:05:09 +00:00
2011-01-29 22:06:05 +00:00
int args [ ] = { WX_GL_RGBA , WX_GL_DOUBLEBUFFER , WX_GL_MIN_ALPHA , 8 } ; // to prevent flicker
glCanvas = new GlCanvas ( this , args ) ;
2011-03-20 00:59:17 +00:00
# if wxCHECK_VERSION(2, 9, 1)
2011-03-20 06:05:09 +00:00
//glCanvas->setCurrentGLContext();
2011-03-20 00:59:17 +00:00
# else
2011-01-29 22:39:57 +00:00
glCanvas - > SetCurrent ( ) ;
2011-03-20 00:59:17 +00:00
# endif
2011-01-29 22:06:05 +00:00
2011-01-29 08:46:28 +00:00
model = NULL ;
2011-01-29 04:35:55 +00:00
unitPath = unitToLoad ;
2011-01-29 03:53:05 +00:00
2010-05-25 18:06:42 +00:00
if ( modelPath ! = " " ) {
this - > modelPathList . push_back ( modelPath ) ;
2011-01-29 12:42:18 +00:00
printf ( " Startup Adding model [%s] list size %lu \n " , modelPath . c_str ( ) , this - > modelPathList . size ( ) ) ;
2010-05-25 18:06:42 +00:00
}
2011-01-28 05:49:52 +00:00
if ( particlePath ! = " " ) {
this - > particlePathList . push_back ( particlePath ) ;
}
if ( projectileParticlePath ! = " " ) {
this - > particleProjectilePathList . push_back ( projectileParticlePath ) ;
}
if ( splashParticlePath ! = " " ) {
this - > particleSplashPathList . push_back ( splashParticlePath ) ;
}
2011-01-29 03:53:05 +00:00
resetAnimation = false ;
2011-01-28 05:49:52 +00:00
anim = defaultAnimation ;
particleLoopStart = defaultParticleLoopStart ;
2011-01-29 03:53:05 +00:00
resetAnim = anim ;
resetParticleLoopStart = particleLoopStart ;
2011-01-28 05:49:52 +00:00
rotX = defaultXRot ;
rotY = defaultYRot ;
zoom = defaultZoom ;
2010-03-13 10:39:22 +00:00
playerColor = Renderer : : pcRed ;
speed = 0.025f ;
//getGlPlatformExtensions();
menu = new wxMenuBar ( ) ;
//menu
menuFile = new wxMenu ( ) ;
2011-01-28 05:49:52 +00:00
menuFile - > Append ( miFileLoad , wxT ( " &Load G3d model \t Ctrl+L " ) , wxT ( " Load 3D model " ) ) ;
menuFile - > Append ( miFileLoadParticleXML , wxT ( " Load &Particle XML \t Ctrl+P " ) , wxT ( " Press ctrl before menu for keeping current particles " ) ) ;
menuFile - > Append ( miFileLoadProjectileParticleXML , wxT ( " Load Pro&jectile Particle XML \t Ctrl+J " ) , wxT ( " Press ctrl before menu for keeping current projectile particles " ) ) ;
menuFile - > Append ( miFileLoadSplashParticleXML , wxT ( " Load &Splash Particle XML \t Ctrl+S " ) , wxT ( " Press ctrl before menu for keeping current splash particles " ) ) ;
menuFile - > Append ( miFileClearAll , wxT ( " &Clear All \t Ctrl+C " ) ) ;
menuFile - > AppendCheckItem ( miFileToggleScreenshotTransparent , wxT ( " &Transparent Screenshots \t Ctrl+T " ) ) ;
menuFile - > Append ( miFileSaveScreenshot , wxT ( " Sa&ve a Screenshot \t Ctrl+V " ) ) ;
2010-11-03 19:03:25 +00:00
menuFile - > AppendSeparator ( ) ;
menuFile - > Append ( wxID_EXIT ) ;
menu - > Append ( menuFile , wxT ( " &File " ) ) ;
2010-03-13 10:39:22 +00:00
//mode
menuMode = new wxMenu ( ) ;
2010-11-03 19:03:25 +00:00
menuMode - > AppendCheckItem ( miModeNormals , wxT ( " &Normals " ) ) ;
menuMode - > AppendCheckItem ( miModeWireframe , wxT ( " &Wireframe " ) ) ;
menuMode - > AppendCheckItem ( miModeGrid , wxT ( " &Grid " ) ) ;
menu - > Append ( menuMode , wxT ( " &Mode " ) ) ;
2010-03-13 10:39:22 +00:00
//mode
menuSpeed = new wxMenu ( ) ;
2010-11-03 19:03:25 +00:00
menuSpeed - > Append ( miSpeedSlower , wxT ( " &Slower \t - " ) ) ;
menuSpeed - > Append ( miSpeedFaster , wxT ( " &Faster \t + " ) ) ;
menuSpeed - > AppendSeparator ( ) ;
2010-12-05 01:33:28 +00:00
menuSpeed - > Append ( miRestart , wxT ( " &Restart particles \t R " ) , wxT ( " Restart particle animations, this also reloads model and particle files if they are changed " ) ) ;
2010-11-03 19:03:25 +00:00
menu - > Append ( menuSpeed , wxT ( " &Speed " ) ) ;
2010-03-13 10:39:22 +00:00
//custom color
menuCustomColor = new wxMenu ( ) ;
2011-01-21 16:34:33 +00:00
menuCustomColor - > Append ( miChangeBackgroundColor , wxT ( " Change Background Color " ) ) ;
2010-11-03 19:03:25 +00:00
menuCustomColor - > AppendCheckItem ( miColorRed , wxT ( " &Red \t 0 " ) ) ;
menuCustomColor - > AppendCheckItem ( miColorBlue , wxT ( " &Blue \t 1 " ) ) ;
menuCustomColor - > AppendCheckItem ( miColorGreen , wxT ( " &Green \t 2 " ) ) ;
menuCustomColor - > AppendCheckItem ( miColorYellow , wxT ( " &Yellow \t 3 " ) ) ;
menuCustomColor - > AppendCheckItem ( miColorWhite , wxT ( " &White \t 4 " ) ) ;
menuCustomColor - > AppendCheckItem ( miColorCyan , wxT ( " &Cyan \t 5 " ) ) ;
menuCustomColor - > AppendCheckItem ( miColorOrange , wxT ( " &Orange \t 6 " ) ) ;
2010-12-03 05:07:42 +00:00
menuCustomColor - > AppendCheckItem ( miColorMagenta , wxT ( " &Pink \t 7 " ) ) ; // it is called Pink everywhere else so...
2010-11-03 19:03:25 +00:00
menu - > Append ( menuCustomColor , wxT ( " &Custom Color " ) ) ;
2010-03-13 10:39:22 +00:00
menuMode - > Check ( miModeGrid , true ) ;
menuCustomColor - > Check ( miColorRed , true ) ;
SetMenuBar ( menu ) ;
//misc
2010-12-03 05:07:42 +00:00
backBrightness = 0.3f ;
gridBrightness = 1.0f ;
lightBrightness = 0.3f ;
2010-03-13 10:39:22 +00:00
lastX = 0 ;
lastY = 0 ;
2011-01-28 05:49:52 +00:00
2011-01-13 19:27:26 +00:00
statusbarText = " " ;
2010-03-13 10:39:22 +00:00
CreateStatusBar ( ) ;
2011-01-29 23:12:20 +00:00
this - > Layout ( ) ;
2010-06-25 22:54:00 +00:00
wxInitAllImageHandlers ( ) ;
2010-06-25 22:04:40 +00:00
# ifdef WIN32
2010-12-08 20:03:15 +00:00
# if defined(__MINGW32__)
wxIcon icon ( ToUnicode ( " IDI_ICON1 " ) ) ;
# else
wxIcon icon ( " IDI_ICON1 " ) ;
# endif
2010-06-25 22:54:00 +00:00
# else
wxIcon icon ;
2010-10-07 18:13:17 +00:00
std : : ifstream testFile ( " g3dviewer.ico " ) ;
if ( testFile . good ( ) ) {
testFile . close ( ) ;
icon . LoadFile ( wxT ( " g3dviewer.ico " ) , wxBITMAP_TYPE_ICO ) ;
}
2010-06-25 22:04:40 +00:00
# endif
2010-06-25 22:54:00 +00:00
SetIcon ( icon ) ;
2010-06-25 22:04:40 +00:00
2011-01-18 21:17:48 +00:00
fileDialog = new wxFileDialog ( this ) ;
if ( modelPath ! = " " ) {
fileDialog - > SetPath ( ToUnicode ( modelPath ) ) ;
}
2011-04-05 04:49:48 +00:00
string userData = Config : : getInstance ( ) . getString ( " UserData_Root " , " " ) ;
if ( userData ! = " " ) {
endPathWithSlash ( userData ) ;
}
string defaultPath = userData + " techs/ " ;
2011-04-05 07:10:12 +00:00
fileDialog - > SetDirectory ( ToUnicode ( defaultPath . c_str ( ) ) ) ;
2011-04-05 04:49:48 +00:00
2011-01-29 22:59:33 +00:00
glCanvas - > SetFocus ( ) ;
2011-03-20 06:05:09 +00:00
//timer = new wxTimer(this);
//timer->Start(100);
2011-03-12 02:28:00 +00:00
// For windows register g3d file extension to launch this app
2011-04-05 07:32:36 +00:00
# if defined(WIN32) && !defined(__MINGW32__)
2011-03-12 02:28:00 +00:00
// example from: http://stackoverflow.com/questions/1387769/create-registry-entry-to-associate-file-extension-with-application-in-c
//[HKEY_CURRENT_USER\Software\Classes\blergcorp.blergapp.v1\shell\open\command]
//@="c:\path\to\app.exe \"%1\""
//[HKEY_CURRENT_USER\Software\Classes\.blerg]
//@="blergcorp.blergapp.v1"
2011-04-05 07:32:36 +00:00
//Open the registry key.
2011-03-12 02:28:00 +00:00
string subKey = " Software \\ Classes \\ megaglest.g3d \\ shell \\ open \\ command " ;
HKEY keyHandle ;
DWORD dwDisposition ;
RegCreateKeyEx ( HKEY_CURRENT_USER , subKey . c_str ( ) , 0 , NULL , 0 , KEY_ALL_ACCESS , NULL , & keyHandle , & dwDisposition ) ;
//Set the value.
string launchApp = appPath + " \" %1 \" " ;
DWORD len = launchApp . length ( ) + 1 ;
RegSetValueEx ( keyHandle , NULL , 0 , REG_SZ , ( PBYTE ) launchApp . c_str ( ) , len ) ;
RegCloseKey ( keyHandle ) ;
subKey = " Software \\ Classes \\ .g3d " ;
RegCreateKeyEx ( HKEY_CURRENT_USER , subKey . c_str ( ) , 0 , NULL , 0 , KEY_ALL_ACCESS , NULL , & keyHandle , & dwDisposition ) ;
//Set the value.
launchApp = " megaglest.g3d " ;
len = launchApp . length ( ) + 1 ;
RegSetValueEx ( keyHandle , NULL , 0 , REG_SZ , ( PBYTE ) launchApp . c_str ( ) , len ) ;
RegCloseKey ( keyHandle ) ;
# endif
2010-03-13 10:39:22 +00:00
}
2011-03-20 06:05:09 +00:00
void MainWindow : : setupTimer ( ) {
timer = new wxTimer ( this ) ;
timer - > Start ( 100 ) ;
}
void MainWindow : : setupStartupSettings ( ) {
renderer = Renderer : : getInstance ( ) ;
for ( unsigned int i = 0 ; i < autoScreenShotParams . size ( ) ; + + i ) {
if ( autoScreenShotParams [ i ] = = " transparent " ) {
printf ( " Screenshot option [%s] \n " , autoScreenShotParams [ i ] . c_str ( ) ) ;
menuFile - > Check ( miFileToggleScreenshotTransparent , true ) ;
float alpha = 0.0f ;
renderer - > setAlphaColor ( alpha ) ;
}
if ( autoScreenShotParams [ i ] = = " enable_grid " ) {
printf ( " Screenshot option [%s] \n " , autoScreenShotParams [ i ] . c_str ( ) ) ;
menuMode - > Check ( miModeGrid , true ) ;
if ( renderer - > getGrid ( ) = = false ) {
renderer - > toggleGrid ( ) ;
}
}
if ( autoScreenShotParams [ i ] = = " enable_wireframe " ) {
printf ( " Screenshot option [%s] \n " , autoScreenShotParams [ i ] . c_str ( ) ) ;
menuMode - > Check ( miModeWireframe , true ) ;
if ( renderer - > getWireframe ( ) = = false ) {
renderer - > toggleWireframe ( ) ;
}
}
if ( autoScreenShotParams [ i ] = = " enable_normals " ) {
printf ( " Screenshot option [%s] \n " , autoScreenShotParams [ i ] . c_str ( ) ) ;
menuMode - > Check ( miModeNormals , true ) ;
if ( renderer - > getNormals ( ) = = false ) {
renderer - > toggleNormals ( ) ;
}
}
if ( autoScreenShotParams [ i ] = = " disable_grid " ) {
printf ( " Screenshot option [%s] \n " , autoScreenShotParams [ i ] . c_str ( ) ) ;
menuMode - > Check ( miModeGrid , false ) ;
if ( renderer - > getGrid ( ) = = true ) {
renderer - > toggleGrid ( ) ;
}
}
if ( autoScreenShotParams [ i ] = = " enable_wireframe " ) {
printf ( " Screenshot option [%s] \n " , autoScreenShotParams [ i ] . c_str ( ) ) ;
menuMode - > Check ( miModeWireframe , false ) ;
if ( renderer - > getWireframe ( ) = = true ) {
renderer - > toggleWireframe ( ) ;
}
}
if ( autoScreenShotParams [ i ] = = " enable_normals " ) {
printf ( " Screenshot option [%s] \n " , autoScreenShotParams [ i ] . c_str ( ) ) ;
menuMode - > Check ( miModeNormals , false ) ;
if ( renderer - > getNormals ( ) = = true ) {
renderer - > toggleNormals ( ) ;
}
}
}
renderer - > init ( ) ;
wxCommandEvent event ;
onMenuRestart ( event ) ;
}
2010-03-13 10:39:22 +00:00
MainWindow : : ~ MainWindow ( ) {
delete renderer ;
2011-01-29 08:46:28 +00:00
renderer = NULL ;
2010-03-13 10:39:22 +00:00
delete model ;
2011-01-29 08:46:28 +00:00
model = NULL ;
2010-03-13 10:39:22 +00:00
delete timer ;
2011-01-29 08:46:28 +00:00
timer = NULL ;
2010-03-13 10:39:22 +00:00
delete glCanvas ;
2011-01-29 08:46:28 +00:00
glCanvas = NULL ;
2010-06-25 22:04:40 +00:00
2010-03-13 10:39:22 +00:00
}
2011-01-28 01:41:30 +00:00
void MainWindow : : init ( ) {
2011-03-20 00:59:17 +00:00
# if wxCHECK_VERSION(2, 9, 1)
2011-03-20 06:05:09 +00:00
2011-03-20 00:59:17 +00:00
# else
2010-03-13 10:39:22 +00:00
glCanvas - > SetCurrent ( ) ;
2011-03-20 00:59:17 +00:00
# endif
2011-03-20 06:05:09 +00:00
//renderer->init();
2010-03-13 10:39:22 +00:00
2011-03-20 06:05:09 +00:00
//wxCommandEvent event;
//onMenuRestart(event);
2010-03-13 10:39:22 +00:00
}
2011-03-20 06:05:09 +00:00
void MainWindow : : onPaint ( wxPaintEvent & event ) {
if ( ! IsShown ( ) ) return ;
# if wxCHECK_VERSION(2, 9, 1)
glCanvas - > setCurrentGLContext ( ) ;
# endif
if ( startupSettingsInited = = false ) {
startupSettingsInited = true ;
setupStartupSettings ( ) ;
}
2011-01-29 08:46:28 +00:00
2010-03-13 10:39:22 +00:00
renderer - > reset ( GetClientSize ( ) . x , GetClientSize ( ) . y , playerColor ) ;
renderer - > transform ( rotX , rotY , zoom ) ;
renderer - > renderGrid ( ) ;
2011-01-28 05:49:52 +00:00
//printf("anim [%f] particleLoopStart [%d]\n",anim,particleLoopStart);
2010-03-13 10:39:22 +00:00
renderer - > renderTheModel ( model , anim ) ;
2011-01-28 05:49:52 +00:00
int updateLoops = particleLoopStart ;
particleLoopStart = 1 ;
2010-05-25 18:06:42 +00:00
for ( int i = 0 ; i < updateLoops ; + + i ) {
renderer - > updateParticleManager ( ) ;
}
renderer - > renderParticleManager ( ) ;
2010-03-13 10:39:22 +00:00
glCanvas - > SwapBuffers ( ) ;
2011-01-28 01:41:30 +00:00
2011-01-29 08:46:28 +00:00
bool haveLoadedParticles = ( particleProjectilePathList . size ( ) > 0 | | particleSplashPathList . size ( ) > 0 ) ;
2011-01-28 01:41:30 +00:00
if ( autoScreenShotAndExit = = true ) {
2011-01-29 08:46:28 +00:00
printf ( " Auto exiting app... \n " ) ;
fflush ( stdout ) ;
2011-01-28 01:41:30 +00:00
autoScreenShotAndExit = false ;
saveScreenshot ( ) ;
Close ( ) ;
2011-01-29 08:46:28 +00:00
return ;
2011-01-28 01:41:30 +00:00
}
2011-01-29 08:46:28 +00:00
else if ( ( modelPathList . size ( ) > 0 ) & & resetAnimation & & haveLoadedParticles ) {
if ( anim > = resetAnim & & resetAnim > 0 ) {
printf ( " RESETTING EVERYTHING [%f][%f]... \n " , anim , resetAnim ) ;
fflush ( stdout ) ;
resetAnimation = false ;
particleLoopStart = resetParticleLoopStart ;
2011-01-29 03:53:05 +00:00
2011-01-29 08:46:28 +00:00
wxCommandEvent event ;
if ( unitPath . first ! = " " ) {
//onMenuFileClearAll(event);
2011-01-29 03:53:05 +00:00
2011-01-29 08:46:28 +00:00
modelPathList . clear ( ) ;
particlePathList . clear ( ) ;
particleProjectilePathList . clear ( ) ;
particleSplashPathList . clear ( ) ; // as above
onMenuRestart ( event ) ;
}
else {
2011-01-29 03:53:05 +00:00
onMenuRestart ( event ) ;
}
}
}
2011-01-29 08:46:28 +00:00
else if ( modelPathList . size ( ) = = 0 & & haveLoadedParticles ) {
if ( renderer - > hasActiveParticleSystem ( ParticleSystem : : pst_ProjectileParticleSystem ) = = false & &
renderer - > hasActiveParticleSystem ( ParticleSystem : : pst_SplashParticleSystem ) = = false ) {
printf ( " RESETTING PARTICLES... \n " ) ;
fflush ( stdout ) ;
resetAnimation = false ;
anim = 0.f ;
particleLoopStart = resetParticleLoopStart ;
wxCommandEvent event ;
onMenuRestart ( event ) ;
}
}
2010-03-13 10:39:22 +00:00
}
void MainWindow : : onClose ( wxCloseEvent & event ) {
2010-11-03 19:03:25 +00:00
// release memory first (from onMenuFileClearAll)
2011-01-29 08:46:28 +00:00
printf ( " OnClose START \n " ) ;
fflush ( stdout ) ;
2010-11-03 19:03:25 +00:00
modelPathList . clear ( ) ;
particlePathList . clear ( ) ;
particleProjectilePathList . clear ( ) ;
particleSplashPathList . clear ( ) ; // as above
2011-01-29 22:59:33 +00:00
if ( timer ) timer - > Stop ( ) ;
if ( renderer ) renderer - > end ( ) ;
2010-11-03 19:03:25 +00:00
unitParticleSystems . clear ( ) ;
unitParticleSystemTypes . clear ( ) ;
2010-12-03 05:07:42 +00:00
2010-11-03 19:03:25 +00:00
projectileParticleSystems . clear ( ) ;
projectileParticleSystemTypes . clear ( ) ;
splashParticleSystems . clear ( ) ; // as above
splashParticleSystemTypes . clear ( ) ;
delete model ;
model = NULL ;
2011-01-29 08:46:28 +00:00
printf ( " OnClose about to END \n " ) ;
fflush ( stdout ) ;
2010-03-13 10:39:22 +00:00
delete this ;
}
2010-12-03 05:07:42 +00:00
// for the mousewheel
2010-11-03 19:03:25 +00:00
void MainWindow : : onMouseWheelDown ( wxMouseEvent & event ) {
2011-01-20 19:47:33 +00:00
try {
wxPaintEvent paintEvent ;
zoom * = 1.1f ;
zoom = clamp ( zoom , 0.1f , 10.0f ) ;
2011-01-28 05:49:52 +00:00
string statusTextValue = statusbarText + " animation speed: " + floatToStr ( speed * 1000.0 ) + " zoom: " + floatToStr ( zoom ) + " rotX: " + floatToStr ( rotX ) + " rotY: " + floatToStr ( rotY ) ;
GetStatusBar ( ) - > SetStatusText ( ToUnicode ( statusTextValue . c_str ( ) ) ) ;
2011-01-20 19:47:33 +00:00
onPaint ( paintEvent ) ;
}
catch ( std : : runtime_error e ) {
std : : cout < < e . what ( ) < < std : : endl ;
wxMessageDialog ( NULL , ToUnicode ( e . what ( ) ) , ToUnicode ( " Error " ) , wxOK | wxICON_ERROR ) . ShowModal ( ) ;
}
2010-11-03 19:03:25 +00:00
}
void MainWindow : : onMouseWheelUp ( wxMouseEvent & event ) {
2011-01-20 19:47:33 +00:00
try {
wxPaintEvent paintEvent ;
zoom * = 0.90909f ;
zoom = clamp ( zoom , 0.1f , 10.0f ) ;
2011-01-28 05:49:52 +00:00
string statusTextValue = statusbarText + " animation speed: " + floatToStr ( speed * 1000.0 ) + " zoom: " + floatToStr ( zoom ) + " rotX: " + floatToStr ( rotX ) + " rotY: " + floatToStr ( rotY ) ;
GetStatusBar ( ) - > SetStatusText ( ToUnicode ( statusTextValue . c_str ( ) ) ) ;
2011-01-20 19:47:33 +00:00
onPaint ( paintEvent ) ;
}
catch ( std : : runtime_error e ) {
std : : cout < < e . what ( ) < < std : : endl ;
wxMessageDialog ( NULL , ToUnicode ( e . what ( ) ) , ToUnicode ( " Error " ) , wxOK | wxICON_ERROR ) . ShowModal ( ) ;
}
2010-11-03 19:03:25 +00:00
}
2010-03-13 10:39:22 +00:00
void MainWindow : : onMouseMove ( wxMouseEvent & event ) {
2011-01-20 19:47:33 +00:00
try {
int x = event . GetX ( ) ;
int y = event . GetY ( ) ;
wxPaintEvent paintEvent ;
if ( event . LeftIsDown ( ) ) {
rotX + = clamp ( lastX - x , - 10 , 10 ) ;
rotY + = clamp ( lastY - y , - 10 , 10 ) ;
2011-01-28 05:49:52 +00:00
string statusTextValue = statusbarText + " animation speed: " + floatToStr ( speed * 1000.0 ) + " zoom: " + floatToStr ( zoom ) + " rotX: " + floatToStr ( rotX ) + " rotY: " + floatToStr ( rotY ) ;
GetStatusBar ( ) - > SetStatusText ( ToUnicode ( statusTextValue . c_str ( ) ) ) ;
2011-01-20 19:47:33 +00:00
onPaint ( paintEvent ) ;
}
else if ( event . RightIsDown ( ) ) {
zoom * = 1.0f + ( lastX - x + lastY - y ) / 100.0f ;
zoom = clamp ( zoom , 0.1f , 10.0f ) ;
2011-01-28 05:49:52 +00:00
string statusTextValue = statusbarText + " animation speed: " + floatToStr ( speed * 1000.0 ) + " zoom: " + floatToStr ( zoom ) + " rotX: " + floatToStr ( rotX ) + " rotY: " + floatToStr ( rotY ) ;
GetStatusBar ( ) - > SetStatusText ( ToUnicode ( statusTextValue . c_str ( ) ) ) ;
2011-01-20 19:47:33 +00:00
onPaint ( paintEvent ) ;
}
2010-03-13 10:39:22 +00:00
2011-01-20 19:47:33 +00:00
lastX = x ;
lastY = y ;
2010-03-13 10:39:22 +00:00
}
2011-01-20 19:47:33 +00:00
catch ( std : : runtime_error e ) {
std : : cout < < e . what ( ) < < std : : endl ;
wxMessageDialog ( NULL , ToUnicode ( e . what ( ) ) , ToUnicode ( " Error " ) , wxOK | wxICON_ERROR ) . ShowModal ( ) ;
2010-03-13 10:39:22 +00:00
}
}
void MainWindow : : onMenuFileLoad ( wxCommandEvent & event ) {
2011-01-20 19:47:33 +00:00
try {
string fileName ;
2011-01-21 01:53:58 +00:00
fileDialog - > SetWildcard ( wxT ( " G3D files (*.g3d)|*.g3d;*.G3D " ) ) ;
2011-01-20 19:47:33 +00:00
fileDialog - > SetMessage ( wxT ( " Selecting Glest Model for current view. " ) ) ;
2010-06-24 17:47:28 +00:00
2011-01-20 19:47:33 +00:00
if ( fileDialog - > ShowModal ( ) = = wxID_OK ) {
modelPathList . clear ( ) ;
loadModel ( ( const char * ) wxFNCONV ( fileDialog - > GetPath ( ) . c_str ( ) ) ) ;
}
isControlKeyPressed = false ;
}
catch ( std : : runtime_error e ) {
std : : cout < < e . what ( ) < < std : : endl ;
wxMessageDialog ( NULL , ToUnicode ( e . what ( ) ) , ToUnicode ( " Error " ) , wxOK | wxICON_ERROR ) . ShowModal ( ) ;
2010-05-25 18:06:42 +00:00
}
}
void MainWindow : : onMenuFileLoadParticleXML ( wxCommandEvent & event ) {
2011-01-20 19:47:33 +00:00
try {
string fileName ;
fileDialog - > SetWildcard ( wxT ( " XML files (*.xml)|*.xml " ) ) ;
2010-06-24 17:47:28 +00:00
2011-01-20 19:47:33 +00:00
if ( isControlKeyPressed = = true ) {
fileDialog - > SetMessage ( wxT ( " Adding Mega-Glest particle to current view. " ) ) ;
}
else {
fileDialog - > SetMessage ( wxT ( " Selecting Mega-Glest particle for current view. " ) ) ;
}
2010-06-24 17:47:28 +00:00
2011-01-20 19:47:33 +00:00
if ( fileDialog - > ShowModal ( ) = = wxID_OK ) {
string path = ( const char * ) wxFNCONV ( fileDialog - > GetPath ( ) . c_str ( ) ) ;
loadParticle ( path ) ;
}
isControlKeyPressed = false ;
}
catch ( std : : runtime_error e ) {
std : : cout < < e . what ( ) < < std : : endl ;
wxMessageDialog ( NULL , ToUnicode ( e . what ( ) ) , ToUnicode ( " Error " ) , wxOK | wxICON_ERROR ) . ShowModal ( ) ;
2010-05-25 18:06:42 +00:00
}
}
2010-06-24 10:52:58 +00:00
void MainWindow : : onMenuFileLoadProjectileParticleXML ( wxCommandEvent & event ) {
2011-01-20 19:47:33 +00:00
try {
string fileName ;
fileDialog - > SetWildcard ( wxT ( " XML files (*.xml)|*.xml " ) ) ;
2010-06-24 17:47:28 +00:00
2011-01-20 19:47:33 +00:00
if ( isControlKeyPressed = = true ) {
fileDialog - > SetMessage ( wxT ( " Adding Mega-Glest projectile particle to current view. " ) ) ;
}
else {
fileDialog - > SetMessage ( wxT ( " Selecting Mega-Glest projectile particle for current view. " ) ) ;
}
2010-06-24 17:47:28 +00:00
2011-01-20 19:47:33 +00:00
if ( fileDialog - > ShowModal ( ) = = wxID_OK ) {
string path = ( const char * ) wxFNCONV ( fileDialog - > GetPath ( ) . c_str ( ) ) ;
loadProjectileParticle ( path ) ;
}
isControlKeyPressed = false ;
}
catch ( std : : runtime_error e ) {
std : : cout < < e . what ( ) < < std : : endl ;
wxMessageDialog ( NULL , ToUnicode ( e . what ( ) ) , ToUnicode ( " Error " ) , wxOK | wxICON_ERROR ) . ShowModal ( ) ;
2010-06-24 10:52:58 +00:00
}
}
2010-11-03 19:03:25 +00:00
void MainWindow : : onMenuFileLoadSplashParticleXML ( wxCommandEvent & event ) {
2011-01-20 19:47:33 +00:00
try {
string fileName ;
fileDialog - > SetWildcard ( wxT ( " XML files (*.xml)|*.xml " ) ) ;
2010-11-03 19:03:25 +00:00
2011-01-20 19:47:33 +00:00
if ( isControlKeyPressed = = true ) {
fileDialog - > SetMessage ( wxT ( " Adding Mega-Glest splash particle to current view. " ) ) ;
}
else {
fileDialog - > SetMessage ( wxT ( " Selecting Mega-Glest splash particle for current view. " ) ) ;
}
2010-11-03 19:03:25 +00:00
2011-01-20 19:47:33 +00:00
if ( fileDialog - > ShowModal ( ) = = wxID_OK ) {
string path = ( const char * ) wxFNCONV ( fileDialog - > GetPath ( ) . c_str ( ) ) ;
loadSplashParticle ( path ) ;
}
isControlKeyPressed = false ;
}
catch ( std : : runtime_error e ) {
std : : cout < < e . what ( ) < < std : : endl ;
wxMessageDialog ( NULL , ToUnicode ( e . what ( ) ) , ToUnicode ( " Error " ) , wxOK | wxICON_ERROR ) . ShowModal ( ) ;
2010-11-03 19:03:25 +00:00
}
2010-12-03 05:07:42 +00:00
} // is it possible to join loadParticle(), loadProjectileParticle() and loadSplashParticle() to one method?
2010-11-03 19:03:25 +00:00
2011-01-21 16:34:33 +00:00
void MainWindow : : OnChangeColor ( wxCommandEvent & event ) {
try {
//wxColour color = colorPicker->GetColour();
wxColourData data ;
data . SetChooseFull ( true ) ;
for ( int i = 0 ; i < 16 ; i + + )
{
wxColour colour ( i * 16 , i * 16 , i * 16 ) ;
data . SetCustomColour ( i , colour ) ;
}
wxColourDialog dialog ( this , & data ) ;
if ( dialog . ShowModal ( ) = = wxID_OK )
{
wxColourData retData = dialog . GetColourData ( ) ;
wxColour col = retData . GetColour ( ) ;
renderer - > setBackgroundColor ( col . Red ( ) / 255.0f , col . Green ( ) / 255.0f , col . Blue ( ) / 255.0f ) ;
}
}
catch ( std : : runtime_error e ) {
std : : cout < < e . what ( ) < < std : : endl ;
wxMessageDialog ( NULL , ToUnicode ( e . what ( ) ) , ToUnicode ( " Error " ) , wxOK | wxICON_ERROR ) . ShowModal ( ) ;
}
}
void MainWindow : : onMenumFileToggleScreenshotTransparent ( wxCommandEvent & event ) {
try {
float alpha = ( event . IsChecked ( ) = = true ? 0.0f : 1.0f ) ;
renderer - > setAlphaColor ( alpha ) ;
}
catch ( std : : runtime_error e ) {
std : : cout < < e . what ( ) < < std : : endl ;
wxMessageDialog ( NULL , ToUnicode ( e . what ( ) ) , ToUnicode ( " Error " ) , wxOK | wxICON_ERROR ) . ShowModal ( ) ;
}
}
2011-01-28 01:41:30 +00:00
void MainWindow : : saveScreenshot ( ) {
2011-01-20 19:47:33 +00:00
try {
2011-01-28 01:41:30 +00:00
int autoSaveScreenshotIndex = - 1 ;
2011-01-29 17:42:34 +00:00
for ( unsigned int i = 0 ; i < autoScreenShotParams . size ( ) ; + + i ) {
2011-01-28 01:41:30 +00:00
if ( _strnicmp ( autoScreenShotParams [ i ] . c_str ( ) , " saveas- " , 7 ) = = 0 ) {
printf ( " Screenshot option [%s] \n " , autoScreenShotParams [ i ] . c_str ( ) ) ;
autoSaveScreenshotIndex = i ;
break ;
}
}
if ( autoSaveScreenshotIndex > = 0 ) {
string saveAsFilename = autoScreenShotParams [ autoSaveScreenshotIndex ] ;
saveAsFilename . erase ( 0 , 7 ) ;
FILE * f = fopen ( saveAsFilename . c_str ( ) , " rb " ) ;
if ( f = = NULL ) {
renderer - > saveScreen ( saveAsFilename . c_str ( ) ) ;
}
else {
fclose ( f ) ;
}
}
else {
2011-03-10 17:59:40 +00:00
//string screenShotsPath = extractDirectoryPathFromFile(appPath) + string("screens/");
string userData = Config : : getInstance ( ) . getString ( " UserData_Root " , " " ) ;
if ( userData ! = " " ) {
2011-03-13 08:23:43 +00:00
endPathWithSlash ( userData ) ;
2011-03-10 17:59:40 +00:00
}
string screenShotsPath = userData + string ( " screens/ " ) ;
2011-03-05 23:15:07 +00:00
printf ( " screenShotsPath [%s] \n " , screenShotsPath . c_str ( ) ) ;
if ( isdir ( screenShotsPath . c_str ( ) ) = = false ) {
createDirectoryPaths ( screenShotsPath ) ;
}
string path = screenShotsPath ;
2011-01-28 01:41:30 +00:00
if ( isdir ( path . c_str ( ) ) = = true ) {
2011-03-13 22:43:44 +00:00
Config & config = Config : : getInstance ( ) ;
2011-04-04 23:11:59 +00:00
string fileFormat = config . getString ( " ScreenShotFileType " , " jpg " ) ;
2011-03-13 22:43:44 +00:00
//string fileFormat = "png";
2011-01-28 01:41:30 +00:00
2011-03-10 17:31:55 +00:00
for ( int i = 0 ; i < 5000 ; + + i ) {
2011-03-05 23:15:07 +00:00
path = screenShotsPath ;
2011-01-28 01:41:30 +00:00
path + = string ( " screen " ) + intToStr ( i ) + string ( " . " ) + fileFormat ;
FILE * f = fopen ( path . c_str ( ) , " rb " ) ;
if ( f = = NULL ) {
renderer - > saveScreen ( path ) ;
break ;
}
else {
fclose ( f ) ;
}
2011-01-20 19:47:33 +00:00
}
2011-01-20 18:05:07 +00:00
}
}
}
2011-01-20 19:47:33 +00:00
catch ( std : : runtime_error e ) {
std : : cout < < e . what ( ) < < std : : endl ;
wxMessageDialog ( NULL , ToUnicode ( e . what ( ) ) , ToUnicode ( " Error " ) , wxOK | wxICON_ERROR ) . ShowModal ( ) ;
}
2011-01-20 18:05:07 +00:00
}
2011-01-28 01:41:30 +00:00
void MainWindow : : onMenuFileSaveScreenshot ( wxCommandEvent & event ) {
saveScreenshot ( ) ;
}
2011-01-20 18:05:07 +00:00
void MainWindow : : onMenuFileClearAll ( wxCommandEvent & event ) {
2011-01-20 19:47:33 +00:00
try {
2011-01-29 08:46:28 +00:00
printf ( " Start onMenuFileClearAll \n " ) ;
fflush ( stdout ) ;
2011-01-20 19:47:33 +00:00
modelPathList . clear ( ) ;
particlePathList . clear ( ) ;
particleProjectilePathList . clear ( ) ;
particleSplashPathList . clear ( ) ; // as above
2010-11-03 19:03:25 +00:00
2011-01-29 22:59:33 +00:00
if ( timer ) timer - > Stop ( ) ;
if ( renderer ) renderer - > end ( ) ;
2010-06-24 14:00:20 +00:00
2011-01-20 19:47:33 +00:00
unitParticleSystems . clear ( ) ;
unitParticleSystemTypes . clear ( ) ;
2010-12-03 05:07:42 +00:00
2011-01-20 19:47:33 +00:00
projectileParticleSystems . clear ( ) ;
projectileParticleSystemTypes . clear ( ) ;
splashParticleSystems . clear ( ) ; // as above
splashParticleSystemTypes . clear ( ) ;
2010-06-24 14:00:20 +00:00
2011-01-20 19:47:33 +00:00
delete model ;
model = NULL ;
2010-06-24 14:00:20 +00:00
2011-01-29 08:46:28 +00:00
loadUnit ( " " , " " ) ;
2011-01-20 19:47:33 +00:00
loadModel ( " " ) ;
loadParticle ( " " ) ;
loadProjectileParticle ( " " ) ;
loadSplashParticle ( " " ) ; // as above
2010-06-24 14:00:20 +00:00
2011-01-20 19:47:33 +00:00
GetStatusBar ( ) - > SetStatusText ( ToUnicode ( statusbarText . c_str ( ) ) ) ;
isControlKeyPressed = false ;
2011-01-29 08:46:28 +00:00
printf ( " END onMenuFileClearAll \n " ) ;
fflush ( stdout ) ;
2011-01-29 22:59:33 +00:00
if ( timer ) timer - > Start ( 100 ) ;
2011-01-20 19:47:33 +00:00
}
catch ( std : : runtime_error e ) {
std : : cout < < e . what ( ) < < std : : endl ;
wxMessageDialog ( NULL , ToUnicode ( e . what ( ) ) , ToUnicode ( " Error " ) , wxOK | wxICON_ERROR ) . ShowModal ( ) ;
}
2010-06-24 14:00:20 +00:00
}
2010-11-03 19:03:25 +00:00
void MainWindow : : onMenuFileExit ( wxCommandEvent & event ) {
Close ( ) ;
}
2011-01-29 03:53:05 +00:00
void MainWindow : : loadUnit ( string path , string skillName ) {
if ( path ! = " " & & fileExists ( path ) = = true ) {
// std::cout << "Clearing list..." << std::endl;
2011-01-29 04:35:55 +00:00
this - > unitPath . first = path ;
this - > unitPath . second . push_back ( skillName ) ;
2011-01-29 03:53:05 +00:00
}
try {
2011-01-29 04:35:55 +00:00
if ( this - > unitPath . first ! = " " ) {
2011-01-29 22:59:33 +00:00
if ( timer ) timer - > Stop ( ) ;
if ( renderer ) renderer - > end ( ) ;
2011-01-29 08:46:28 +00:00
string titlestring = winHeader ;
2011-01-29 03:53:05 +00:00
2011-01-29 04:35:55 +00:00
string unitPath = this - > unitPath . first ;
2011-01-29 03:53:05 +00:00
string dir = unitPath ;
string name = lastDir ( dir ) ;
string path = dir + " / " + name + " .xml " ;
titlestring = unitPath + " - " + titlestring ;
std : : string unitXML = path ;
string skillModelFile = " " ;
string skillParticleFile = " " ;
string skillParticleProjectileFile = " " ;
string skillParticleSplashFile = " " ;
2011-01-29 04:35:55 +00:00
printf ( " Loading unit from file [%s] \n " , unitXML . c_str ( ) ) ;
2011-01-29 03:53:05 +00:00
if ( fileExists ( unitXML ) = = true ) {
XmlTree xmlTree ;
xmlTree . load ( unitXML ) ;
const XmlNode * unitNode = xmlTree . getRootNode ( ) ;
2011-01-29 04:35:55 +00:00
bool foundSkillName = false ;
2011-01-29 17:42:34 +00:00
for ( unsigned int skillIdx = 0 ; foundSkillName = = false & & skillIdx < this - > unitPath . second . size ( ) ; + + skillIdx ) {
2011-01-29 04:35:55 +00:00
string lookipForSkillName = this - > unitPath . second [ skillIdx ] ;
const XmlNode * skillsNode = unitNode - > getChild ( " skills " ) ;
2011-01-29 17:42:34 +00:00
for ( unsigned int i = 0 ; foundSkillName = = false & & i < skillsNode - > getChildCount ( ) ; + + i ) {
2011-01-29 04:35:55 +00:00
const XmlNode * sn = skillsNode - > getChild ( " skill " , i ) ;
const XmlNode * typeNode = sn - > getChild ( " type " ) ;
const XmlNode * nameNode = sn - > getChild ( " name " ) ;
string skillXmlName = nameNode - > getAttribute ( " value " ) - > getRestrictedValue ( ) ;
if ( skillXmlName = = lookipForSkillName ) {
2011-01-29 08:46:28 +00:00
printf ( " Found skill [%s] \n " , lookipForSkillName . c_str ( ) ) ;
2011-01-29 04:35:55 +00:00
foundSkillName = true ;
2011-01-29 08:46:28 +00:00
2011-01-29 04:35:55 +00:00
if ( sn - > getChild ( " animation " ) ! = NULL ) {
skillModelFile = unitPath + ' / ' + sn - > getChild ( " animation " ) - > getAttribute ( " path " ) - > getRestrictedValue ( ) ;
2011-01-29 08:46:28 +00:00
printf ( " Found skill model [%s] \n " , skillModelFile . c_str ( ) ) ;
2011-01-29 03:53:05 +00:00
}
2011-01-29 04:35:55 +00:00
if ( sn - > hasChild ( " particles " ) = = true ) {
const XmlNode * particlesNode = sn - > getChild ( " particles " ) ;
//for(int j = 0; particlesNode != NULL && particlesNode->getAttribute("value")->getRestrictedValue() == "true" &&
// j < particlesNode->getChildCount(); ++j) {
if ( particlesNode ! = NULL & & particlesNode - > getAttribute ( " value " ) - > getRestrictedValue ( ) = = " true " & &
particlesNode - > hasChild ( " particle-file " ) = = true ) {
const XmlNode * pf = particlesNode - > getChild ( " particle-file " ) ;
if ( pf ! = NULL ) {
skillParticleFile = unitPath + ' / ' + pf - > getAttribute ( " path " ) - > getRestrictedValue ( ) ;
2011-01-29 08:46:28 +00:00
printf ( " Found skill skill particle [%s] \n " , skillParticleFile . c_str ( ) ) ;
2011-01-29 04:35:55 +00:00
}
}
2011-01-29 03:53:05 +00:00
}
2011-01-29 04:35:55 +00:00
if ( sn - > hasChild ( " projectile " ) = = true ) {
const XmlNode * particlesProjectileNode = sn - > getChild ( " projectile " ) ;
//for(int j = 0; particlesProjectileNode != NULL && particlesProjectileNode->getAttribute("value")->getRestrictedValue() == "true" &&
// j < particlesProjectileNode->getChildCount(); ++j) {
if ( particlesProjectileNode ! = NULL & & particlesProjectileNode - > getAttribute ( " value " ) - > getRestrictedValue ( ) = = " true " & &
particlesProjectileNode - > hasChild ( " particle " ) = = true ) {
const XmlNode * pf = particlesProjectileNode - > getChild ( " particle " ) ;
if ( pf ! = NULL & & pf - > getAttribute ( " value " ) - > getRestrictedValue ( ) = = " true " ) {
skillParticleProjectileFile = unitPath + ' / ' + pf - > getAttribute ( " path " ) - > getRestrictedValue ( ) ;
2011-01-29 08:46:28 +00:00
printf ( " Found skill skill projectile particle [%s] \n " , skillParticleProjectileFile . c_str ( ) ) ;
2011-01-29 04:35:55 +00:00
}
}
}
if ( sn - > hasChild ( " splash " ) = = true ) {
const XmlNode * particlesSplashNode = sn - > getChild ( " splash " ) ;
//for(int j = 0; particlesSplashNode != NULL && particlesSplashNode->getAttribute("value")->getRestrictedValue() == "true" &&
// j < particlesSplashNode->getChildCount(); ++j) {
if ( particlesSplashNode ! = NULL & & particlesSplashNode - > getAttribute ( " value " ) - > getRestrictedValue ( ) = = " true " & &
particlesSplashNode - > hasChild ( " particle " ) = = true ) {
const XmlNode * pf = particlesSplashNode - > getChild ( " particle " ) ;
if ( pf ! = NULL & & pf - > getAttribute ( " value " ) - > getRestrictedValue ( ) = = " true " ) {
skillParticleSplashFile = unitPath + ' / ' + pf - > getAttribute ( " path " ) - > getRestrictedValue ( ) ;
2011-01-29 08:46:28 +00:00
printf ( " Found skill skill splash particle [%s] \n " , skillParticleSplashFile . c_str ( ) ) ;
2011-01-29 04:35:55 +00:00
}
}
2011-01-29 03:53:05 +00:00
}
}
}
}
if ( skillModelFile ! = " " ) {
this - > modelPathList . push_back ( skillModelFile ) ;
2011-01-29 08:46:28 +00:00
printf ( " Added skill model [%s] \n " , skillModelFile . c_str ( ) ) ;
2011-01-29 03:53:05 +00:00
}
if ( skillParticleFile ! = " " ) {
this - > particlePathList . push_back ( skillParticleFile ) ;
2011-01-29 08:46:28 +00:00
printf ( " Added skill particle [%s] \n " , skillParticleFile . c_str ( ) ) ;
2011-01-29 03:53:05 +00:00
}
if ( skillParticleProjectileFile ! = " " ) {
this - > particleProjectilePathList . push_back ( skillParticleProjectileFile ) ;
2011-01-29 08:46:28 +00:00
printf ( " Added skill projectile particle [%s] \n " , skillParticleProjectileFile . c_str ( ) ) ;
2011-01-29 03:53:05 +00:00
}
if ( skillParticleSplashFile ! = " " ) {
this - > particleSplashPathList . push_back ( skillParticleSplashFile ) ;
2011-01-29 08:46:28 +00:00
printf ( " Added skill splash particle [%s] \n " , skillParticleSplashFile . c_str ( ) ) ;
2011-01-29 03:53:05 +00:00
}
2011-01-29 08:46:28 +00:00
//glCanvas->SetCurrent();
//renderer->init();
2011-01-29 03:53:05 +00:00
//wxCommandEvent event;
//onMenuRestart(event);
}
SetTitle ( ToUnicode ( titlestring ) ) ;
}
}
catch ( std : : runtime_error e ) {
std : : cout < < e . what ( ) < < std : : endl ;
wxMessageDialog ( NULL , ToUnicode ( e . what ( ) ) , ToUnicode ( " Not a Mega-Glest particle XML file, or broken " ) , wxOK | wxICON_ERROR ) . ShowModal ( ) ;
}
2011-01-29 08:46:28 +00:00
//timer->Start(100);
2011-01-29 03:53:05 +00:00
}
2010-05-25 18:06:42 +00:00
void MainWindow : : loadModel ( string path ) {
2011-01-21 01:53:58 +00:00
try {
if ( path ! = " " & & fileExists ( path ) = = true ) {
this - > modelPathList . push_back ( path ) ;
2011-01-29 12:42:18 +00:00
printf ( " Adding model [%s] list size %lu \n " , path . c_str ( ) , this - > modelPathList . size ( ) ) ;
2011-01-21 01:53:58 +00:00
}
2011-01-13 19:27:26 +00:00
2011-01-21 01:53:58 +00:00
string titlestring = winHeader ;
for ( unsigned int idx = 0 ; idx < this - > modelPathList . size ( ) ; idx + + ) {
string modelPath = this - > modelPathList [ idx ] ;
2011-03-20 06:05:09 +00:00
//printf("Loading model [%s] %u of %lu\n",modelPath.c_str(),idx, this->modelPathList.size());
2011-01-29 08:46:28 +00:00
2011-01-29 22:59:33 +00:00
if ( timer ) timer - > Stop ( ) ;
2011-01-21 01:53:58 +00:00
delete model ;
Model * tmpModel = new ModelGl ( ) ;
2011-01-29 22:59:33 +00:00
if ( renderer ) renderer - > loadTheModel ( tmpModel , modelPath ) ;
2011-01-21 01:53:58 +00:00
model = tmpModel ;
statusbarText = getModelInfo ( ) ;
2011-01-28 05:49:52 +00:00
string statusTextValue = statusbarText + " animation speed: " + floatToStr ( speed * 1000.0 ) + " zoom: " + floatToStr ( zoom ) + " rotX: " + floatToStr ( rotX ) + " rotY: " + floatToStr ( rotY ) ;
2011-01-21 01:53:58 +00:00
GetStatusBar ( ) - > SetStatusText ( ToUnicode ( statusTextValue . c_str ( ) ) ) ;
2011-01-29 22:59:33 +00:00
if ( timer ) timer - > Start ( 100 ) ;
2011-01-21 01:53:58 +00:00
titlestring = extractFileFromDirectoryPath ( modelPath ) + " - " + titlestring ;
}
SetTitle ( ToUnicode ( titlestring ) ) ;
}
catch ( std : : runtime_error e ) {
std : : cout < < e . what ( ) < < std : : endl ;
wxMessageDialog ( NULL , ToUnicode ( e . what ( ) ) , ToUnicode ( " Error " ) , wxOK | wxICON_ERROR ) . ShowModal ( ) ;
2010-03-13 10:39:22 +00:00
}
}
2010-05-25 18:06:42 +00:00
void MainWindow : : loadParticle ( string path ) {
2011-01-29 22:59:33 +00:00
if ( timer ) timer - > Stop ( ) ;
2010-05-25 18:06:42 +00:00
if ( path ! = " " & & fileExists ( path ) = = true ) {
2010-06-24 17:47:28 +00:00
renderer - > end ( ) ;
unitParticleSystems . clear ( ) ;
unitParticleSystemTypes . clear ( ) ;
2010-06-24 10:52:58 +00:00
2010-06-24 14:00:20 +00:00
if ( isControlKeyPressed = = true ) {
2010-12-03 05:07:42 +00:00
// std::cout << "Adding to list..." << std::endl;
2010-06-24 14:00:20 +00:00
this - > particlePathList . push_back ( path ) ;
}
else {
2010-12-03 05:07:42 +00:00
// std::cout << "Clearing list..." << std::endl;
2010-06-24 14:00:20 +00:00
this - > particlePathList . clear ( ) ;
this - > particlePathList . push_back ( path ) ;
}
2010-06-24 17:47:28 +00:00
}
2010-05-25 18:06:42 +00:00
2010-11-03 19:03:25 +00:00
try {
2010-06-24 17:47:28 +00:00
if ( this - > particlePathList . size ( ) > 0 ) {
2010-12-03 05:07:42 +00:00
string titlestring = winHeader ;
2010-10-21 07:20:17 +00:00
for ( unsigned int idx = 0 ; idx < this - > particlePathList . size ( ) ; idx + + ) {
2010-06-24 17:47:28 +00:00
string particlePath = this - > particlePathList [ idx ] ;
string dir = extractDirectoryPathFromFile ( particlePath ) ;
2010-05-25 18:06:42 +00:00
2010-06-24 17:47:28 +00:00
size_t pos = dir . find_last_of ( folderDelimiter ) ;
2011-01-29 08:46:28 +00:00
if ( pos = = dir . length ( ) - 1 & & dir . length ( ) > 0 ) {
2010-06-24 17:47:28 +00:00
dir . erase ( dir . length ( ) - 1 ) ;
}
2010-05-25 18:06:42 +00:00
2010-06-24 17:47:28 +00:00
particlePath = extractFileFromDirectoryPath ( particlePath ) ;
2010-12-03 05:07:42 +00:00
titlestring = particlePath + " - " + titlestring ;
2010-05-25 18:06:42 +00:00
2010-06-24 17:47:28 +00:00
std : : string unitXML = dir + folderDelimiter + extractFileFromDirectoryPath ( dir ) + " .xml " ;
2010-05-25 18:06:42 +00:00
2010-06-24 17:47:28 +00:00
int size = - 1 ;
int height = - 1 ;
2010-05-25 18:06:42 +00:00
2010-06-24 17:47:28 +00:00
if ( fileExists ( unitXML ) = = true ) {
XmlTree xmlTree ;
xmlTree . load ( unitXML ) ;
const XmlNode * unitNode = xmlTree . getRootNode ( ) ;
const XmlNode * parametersNode = unitNode - > getChild ( " parameters " ) ;
//size
size = parametersNode - > getChild ( " size " ) - > getAttribute ( " value " ) - > getIntValue ( ) ;
//height
height = parametersNode - > getChild ( " height " ) - > getAttribute ( " value " ) - > getIntValue ( ) ;
2010-05-25 18:06:42 +00:00
2011-01-29 08:46:28 +00:00
// std::cout << "About to load [" << particlePath << "] from [" << dir << "] unit [" << unitXML << "]" << std::endl;
2011-03-15 15:30:28 +00:00
std : : map < string , int > loadedFileList ;
2011-01-29 08:46:28 +00:00
UnitParticleSystemType * unitParticleSystemType = new UnitParticleSystemType ( ) ;
2011-03-15 15:30:28 +00:00
unitParticleSystemType - > load ( dir , dir + folderDelimiter + particlePath ,
renderer , loadedFileList ) ;
2011-01-29 08:46:28 +00:00
unitParticleSystemTypes . push_back ( unitParticleSystemType ) ;
for ( std : : vector < UnitParticleSystemType * > : : const_iterator it = unitParticleSystemTypes . begin ( ) ; it ! = unitParticleSystemTypes . end ( ) ; + + it ) {
UnitParticleSystem * ups = new UnitParticleSystem ( 200 ) ;
( * it ) - > setValues ( ups ) ;
if ( size > 0 ) {
//getCurrVectorFlat() + Vec3f(0.f, type->getHeight()/2.f, 0.f);
Vec3f vec = Vec3f ( 0.f , height / 2.f , 0.f ) ;
ups - > setPos ( vec ) ;
}
//ups->setFactionColor(getFaction()->getTexture()->getPixmap()->getPixel3f(0,0));
ups - > setFactionColor ( renderer - > getPlayerColorTexture ( playerColor ) - > getPixmap ( ) - > getPixel3f ( 0 , 0 ) ) ;
unitParticleSystems . push_back ( ups ) ;
renderer - > manageParticleSystem ( ups ) ;
ups - > setVisible ( true ) ;
}
if ( path ! = " " & & fileExists ( path ) = = true ) {
renderer - > initModelManager ( ) ;
2011-01-29 22:17:37 +00:00
if ( initTextureManager ) {
renderer - > initTextureManager ( ) ;
}
2011-01-29 08:46:28 +00:00
}
2010-05-25 18:06:42 +00:00
}
}
2010-12-03 05:07:42 +00:00
SetTitle ( ToUnicode ( titlestring ) ) ;
2010-05-25 18:06:42 +00:00
}
2010-11-03 19:03:25 +00:00
}
2010-12-03 05:07:42 +00:00
catch ( std : : runtime_error e ) {
2010-11-03 19:03:25 +00:00
std : : cout < < e . what ( ) < < std : : endl ;
2011-01-20 19:47:33 +00:00
wxMessageDialog ( NULL , ToUnicode ( e . what ( ) ) , ToUnicode ( " Not a Mega-Glest particle XML file, or broken " ) , wxOK | wxICON_ERROR ) . ShowModal ( ) ;
2010-11-03 19:03:25 +00:00
}
2011-01-29 22:59:33 +00:00
if ( timer ) timer - > Start ( 100 ) ;
2010-05-25 18:06:42 +00:00
}
2010-06-24 10:52:58 +00:00
void MainWindow : : loadProjectileParticle ( string path ) {
2011-01-29 22:59:33 +00:00
if ( timer ) timer - > Stop ( ) ;
2010-06-24 10:52:58 +00:00
if ( path ! = " " & & fileExists ( path ) = = true ) {
2010-06-24 17:47:28 +00:00
renderer - > end ( ) ;
projectileParticleSystems . clear ( ) ;
projectileParticleSystemTypes . clear ( ) ;
2010-06-24 10:52:58 +00:00
2010-06-24 14:00:20 +00:00
if ( isControlKeyPressed = = true ) {
2010-12-03 05:07:42 +00:00
// std::cout << "Adding to list..." << std::endl;
2010-06-24 14:00:20 +00:00
this - > particleProjectilePathList . push_back ( path ) ;
}
else {
2010-12-03 05:07:42 +00:00
// std::cout << "Clearing list..." << std::endl;
2010-06-24 14:00:20 +00:00
this - > particleProjectilePathList . clear ( ) ;
this - > particleProjectilePathList . push_back ( path ) ;
}
2010-06-24 17:47:28 +00:00
}
2010-06-24 10:52:58 +00:00
2010-11-03 19:03:25 +00:00
try {
2010-06-24 17:47:28 +00:00
if ( this - > particleProjectilePathList . size ( ) > 0 ) {
2010-12-03 05:07:42 +00:00
string titlestring = winHeader ;
2010-10-21 07:20:17 +00:00
for ( unsigned int idx = 0 ; idx < this - > particleProjectilePathList . size ( ) ; idx + + ) {
2010-06-24 17:47:28 +00:00
string particlePath = this - > particleProjectilePathList [ idx ] ;
string dir = extractDirectoryPathFromFile ( particlePath ) ;
2010-06-24 10:52:58 +00:00
2010-06-24 17:47:28 +00:00
size_t pos = dir . find_last_of ( folderDelimiter ) ;
if ( pos = = dir . length ( ) - 1 ) {
dir . erase ( dir . length ( ) - 1 ) ;
}
2010-06-24 10:52:58 +00:00
2010-06-24 17:47:28 +00:00
particlePath = extractFileFromDirectoryPath ( particlePath ) ;
2010-12-03 05:07:42 +00:00
titlestring = particlePath + " - " + titlestring ;
2010-06-24 10:52:58 +00:00
2010-06-24 17:47:28 +00:00
std : : string unitXML = dir + folderDelimiter + extractFileFromDirectoryPath ( dir ) + " .xml " ;
2010-06-24 10:52:58 +00:00
2010-06-24 17:47:28 +00:00
int size = - 1 ;
int height = - 1 ;
2010-06-24 10:52:58 +00:00
2010-06-24 17:47:28 +00:00
if ( fileExists ( unitXML ) = = true ) {
2010-06-24 14:00:20 +00:00
XmlTree xmlTree ;
2010-06-24 17:47:28 +00:00
xmlTree . load ( unitXML ) ;
const XmlNode * unitNode = xmlTree . getRootNode ( ) ;
const XmlNode * parametersNode = unitNode - > getChild ( " parameters " ) ;
//size
size = parametersNode - > getChild ( " size " ) - > getAttribute ( " value " ) - > getIntValue ( ) ;
//height
height = parametersNode - > getChild ( " height " ) - > getAttribute ( " value " ) - > getIntValue ( ) ;
}
2010-06-24 10:52:58 +00:00
2010-12-03 05:07:42 +00:00
// std::cout << "About to load [" << particlePath << "] from [" << dir << "] unit [" << unitXML << "]" << std::endl;
2010-06-24 10:52:58 +00:00
2010-06-24 17:47:28 +00:00
XmlTree xmlTree ;
xmlTree . load ( dir + folderDelimiter + particlePath ) ;
const XmlNode * particleSystemNode = xmlTree . getRootNode ( ) ;
2010-06-24 10:52:58 +00:00
2010-12-03 05:07:42 +00:00
// std::cout << "Loaded successfully, loading values..." << std::endl;
2010-06-24 10:52:58 +00:00
2011-03-15 15:30:28 +00:00
std : : map < string , int > loadedFileList ;
2010-06-24 17:47:28 +00:00
ParticleSystemTypeProjectile * projectileParticleSystemType = new ParticleSystemTypeProjectile ( ) ;
2011-03-15 15:30:28 +00:00
projectileParticleSystemType - > load ( dir ,
dir + folderDelimiter + particlePath , renderer , loadedFileList ) ;
2010-06-24 10:52:58 +00:00
2010-12-03 05:07:42 +00:00
// std::cout << "Values loaded, about to read..." << std::endl;
2010-06-24 10:52:58 +00:00
2010-06-24 17:47:28 +00:00
projectileParticleSystemTypes . push_back ( projectileParticleSystemType ) ;
2010-06-24 14:00:20 +00:00
2010-06-24 17:47:28 +00:00
for ( std : : vector < ParticleSystemTypeProjectile * > : : const_iterator it = projectileParticleSystemTypes . begin ( ) ; it ! = projectileParticleSystemTypes . end ( ) ; + + it ) {
2010-06-24 14:00:20 +00:00
2010-06-24 17:47:28 +00:00
ProjectileParticleSystem * ps = ( * it ) - > create ( ) ;
2010-06-24 10:52:58 +00:00
2010-06-24 17:47:28 +00:00
if ( size > 0 ) {
Vec3f vec = Vec3f ( 0.f , height / 2.f , 0.f ) ;
//ps->setPos(vec);
2010-06-24 14:00:20 +00:00
2010-06-24 17:47:28 +00:00
Vec3f vec2 = Vec3f ( size * 2.f , height * 2.f , height * 2.f ) ;
ps - > setPath ( vec , vec2 ) ;
2010-06-24 14:00:20 +00:00
}
2010-06-24 17:47:28 +00:00
ps - > setFactionColor ( renderer - > getPlayerColorTexture ( playerColor ) - > getPixmap ( ) - > getPixel3f ( 0 , 0 ) ) ;
2010-06-24 14:00:20 +00:00
2010-06-24 17:47:28 +00:00
projectileParticleSystems . push_back ( ps ) ;
ps - > setVisible ( true ) ;
renderer - > manageParticleSystem ( ps ) ;
2010-06-24 14:00:20 +00:00
}
2010-06-24 10:52:58 +00:00
}
2010-12-03 05:07:42 +00:00
SetTitle ( ToUnicode ( titlestring ) ) ;
2010-06-24 17:47:28 +00:00
if ( path ! = " " & & fileExists ( path ) = = true ) {
renderer - > initModelManager ( ) ;
2011-01-29 22:17:37 +00:00
if ( initTextureManager ) {
renderer - > initTextureManager ( ) ;
}
2010-06-24 17:47:28 +00:00
}
2010-06-24 10:52:58 +00:00
}
2010-11-03 19:03:25 +00:00
}
2010-12-03 05:07:42 +00:00
catch ( std : : runtime_error e ) {
2010-11-03 19:03:25 +00:00
std : : cout < < e . what ( ) < < std : : endl ;
2011-01-20 19:47:33 +00:00
wxMessageDialog ( NULL , ToUnicode ( e . what ( ) ) , ToUnicode ( " Not a Mega-Glest projectile particle XML file, or broken " ) , wxOK | wxICON_ERROR ) . ShowModal ( ) ;
2010-11-03 19:03:25 +00:00
}
2011-01-29 22:59:33 +00:00
if ( timer ) timer - > Start ( 100 ) ;
2010-11-03 19:03:25 +00:00
}
void MainWindow : : loadSplashParticle ( string path ) { // uses ParticleSystemTypeSplash::load (and own list...)
2011-01-29 22:59:33 +00:00
if ( timer ) timer - > Stop ( ) ;
2010-11-03 19:03:25 +00:00
if ( path ! = " " & & fileExists ( path ) = = true ) {
renderer - > end ( ) ;
splashParticleSystems . clear ( ) ;
2010-12-03 05:07:42 +00:00
splashParticleSystemTypes . clear ( ) ;
2010-11-03 19:03:25 +00:00
if ( isControlKeyPressed = = true ) {
2010-12-03 05:07:42 +00:00
// std::cout << "Adding to list..." << std::endl;
2010-11-03 19:03:25 +00:00
this - > particleSplashPathList . push_back ( path ) ;
}
else {
2010-12-03 05:07:42 +00:00
// std::cout << "Clearing list..." << std::endl;
2010-11-03 19:03:25 +00:00
this - > particleSplashPathList . clear ( ) ;
this - > particleSplashPathList . push_back ( path ) ;
}
}
try {
if ( this - > particleSplashPathList . size ( ) > 0 ) {
2010-12-03 05:07:42 +00:00
string titlestring = winHeader ;
2010-11-03 19:03:25 +00:00
for ( unsigned int idx = 0 ; idx < this - > particleSplashPathList . size ( ) ; idx + + ) {
string particlePath = this - > particleSplashPathList [ idx ] ;
string dir = extractDirectoryPathFromFile ( particlePath ) ;
size_t pos = dir . find_last_of ( folderDelimiter ) ;
if ( pos = = dir . length ( ) - 1 ) {
dir . erase ( dir . length ( ) - 1 ) ;
}
particlePath = extractFileFromDirectoryPath ( particlePath ) ;
2010-12-03 05:07:42 +00:00
titlestring = particlePath + " - " + titlestring ;
2010-11-03 19:03:25 +00:00
std : : string unitXML = dir + folderDelimiter + extractFileFromDirectoryPath ( dir ) + " .xml " ;
int size = - 1 ;
int height = - 1 ;
if ( fileExists ( unitXML ) = = true ) {
XmlTree xmlTree ;
xmlTree . load ( unitXML ) ;
const XmlNode * unitNode = xmlTree . getRootNode ( ) ;
const XmlNode * parametersNode = unitNode - > getChild ( " parameters " ) ;
//size
size = parametersNode - > getChild ( " size " ) - > getAttribute ( " value " ) - > getIntValue ( ) ;
//height
height = parametersNode - > getChild ( " height " ) - > getAttribute ( " value " ) - > getIntValue ( ) ;
}
2010-12-03 05:07:42 +00:00
// std::cout << "About to load [" << particlePath << "] from [" << dir << "] unit [" << unitXML << "]" << std::endl;
2010-11-03 19:03:25 +00:00
XmlTree xmlTree ;
xmlTree . load ( dir + folderDelimiter + particlePath ) ;
const XmlNode * particleSystemNode = xmlTree . getRootNode ( ) ;
2010-12-03 05:07:42 +00:00
// std::cout << "Loaded successfully, loading values..." << std::endl;
2010-11-03 19:03:25 +00:00
2011-03-15 15:30:28 +00:00
std : : map < string , int > loadedFileList ;
2010-12-03 05:07:42 +00:00
ParticleSystemTypeSplash * splashParticleSystemType = new ParticleSystemTypeSplash ( ) ;
2011-03-15 15:30:28 +00:00
splashParticleSystemType - > load ( dir , dir + folderDelimiter + particlePath , renderer ,
loadedFileList ) ; // <---- only that must be splash...
2010-11-03 19:03:25 +00:00
2010-12-03 05:07:42 +00:00
// std::cout << "Values loaded, about to read..." << std::endl;
2010-11-03 19:03:25 +00:00
splashParticleSystemTypes . push_back ( splashParticleSystemType ) ;
//ParticleSystemTypeSplash
for ( std : : vector < ParticleSystemTypeSplash * > : : const_iterator it = splashParticleSystemTypes . begin ( ) ; it ! = splashParticleSystemTypes . end ( ) ; + + it ) {
SplashParticleSystem * ps = ( * it ) - > create ( ) ;
if ( size > 0 ) {
Vec3f vec = Vec3f ( 0.f , height / 2.f , 0.f ) ;
//ps->setPos(vec);
//Vec3f vec2 = Vec3f(size * 2.f, height * 2.f, height * 2.f); // <------- removed relative projectile
//ps->setPath(vec, vec2); // <------- removed relative projectile
}
ps - > setFactionColor ( renderer - > getPlayerColorTexture ( playerColor ) - > getPixmap ( ) - > getPixel3f ( 0 , 0 ) ) ;
splashParticleSystems . push_back ( ps ) ;
ps - > setVisible ( true ) ;
renderer - > manageParticleSystem ( ps ) ;
}
}
2010-12-03 05:07:42 +00:00
SetTitle ( ToUnicode ( titlestring ) ) ;
2010-11-03 19:03:25 +00:00
if ( path ! = " " & & fileExists ( path ) = = true ) {
renderer - > initModelManager ( ) ;
2011-01-29 22:17:37 +00:00
if ( initTextureManager ) {
renderer - > initTextureManager ( ) ;
}
2010-11-03 19:03:25 +00:00
}
}
}
2010-12-03 05:07:42 +00:00
catch ( std : : runtime_error e ) {
2010-11-03 19:03:25 +00:00
std : : cout < < e . what ( ) < < std : : endl ;
2011-01-20 19:47:33 +00:00
wxMessageDialog ( NULL , ToUnicode ( e . what ( ) ) , ToUnicode ( " Not a Mega-Glest projectile particle XML file, or broken " ) , wxOK | wxICON_ERROR ) . ShowModal ( ) ;
2010-11-03 19:03:25 +00:00
}
2011-01-29 22:59:33 +00:00
if ( timer ) timer - > Start ( 100 ) ;
2010-06-24 10:52:58 +00:00
}
2010-03-13 10:39:22 +00:00
void MainWindow : : onMenuModeNormals ( wxCommandEvent & event ) {
2011-01-20 19:47:33 +00:00
try {
renderer - > toggleNormals ( ) ;
menuMode - > Check ( miModeNormals , renderer - > getNormals ( ) ) ;
}
catch ( std : : runtime_error e ) {
std : : cout < < e . what ( ) < < std : : endl ;
wxMessageDialog ( NULL , ToUnicode ( e . what ( ) ) , ToUnicode ( " Error " ) , wxOK | wxICON_ERROR ) . ShowModal ( ) ;
}
2010-03-13 10:39:22 +00:00
}
void MainWindow : : onMenuModeWireframe ( wxCommandEvent & event ) {
2011-01-20 19:47:33 +00:00
try {
renderer - > toggleWireframe ( ) ;
menuMode - > Check ( miModeWireframe , renderer - > getWireframe ( ) ) ;
}
catch ( std : : runtime_error e ) {
std : : cout < < e . what ( ) < < std : : endl ;
wxMessageDialog ( NULL , ToUnicode ( e . what ( ) ) , ToUnicode ( " Error " ) , wxOK | wxICON_ERROR ) . ShowModal ( ) ;
}
2010-03-13 10:39:22 +00:00
}
void MainWindow : : onMenuModeGrid ( wxCommandEvent & event ) {
2011-01-20 19:47:33 +00:00
try {
renderer - > toggleGrid ( ) ;
menuMode - > Check ( miModeGrid , renderer - > getGrid ( ) ) ;
}
catch ( std : : runtime_error e ) {
std : : cout < < e . what ( ) < < std : : endl ;
wxMessageDialog ( NULL , ToUnicode ( e . what ( ) ) , ToUnicode ( " Error " ) , wxOK | wxICON_ERROR ) . ShowModal ( ) ;
}
2010-03-13 10:39:22 +00:00
}
void MainWindow : : onMenuSpeedSlower ( wxCommandEvent & event ) {
2011-01-20 19:47:33 +00:00
try {
speed / = 1.5f ;
if ( speed < 0 ) {
speed = 0 ;
}
2011-01-13 19:27:26 +00:00
2011-01-28 05:49:52 +00:00
string statusTextValue = statusbarText + " animation speed: " + floatToStr ( speed * 1000.0 ) + " zoom: " + floatToStr ( zoom ) + " rotX: " + floatToStr ( rotX ) + " rotY: " + floatToStr ( rotY ) ;
2011-01-20 19:47:33 +00:00
GetStatusBar ( ) - > SetStatusText ( ToUnicode ( statusTextValue . c_str ( ) ) ) ;
}
catch ( std : : runtime_error e ) {
std : : cout < < e . what ( ) < < std : : endl ;
wxMessageDialog ( NULL , ToUnicode ( e . what ( ) ) , ToUnicode ( " Error " ) , wxOK | wxICON_ERROR ) . ShowModal ( ) ;
}
2010-03-13 10:39:22 +00:00
}
void MainWindow : : onMenuSpeedFaster ( wxCommandEvent & event ) {
2011-01-20 19:47:33 +00:00
try {
speed * = 1.5f ;
if ( speed > 1 ) {
speed = 1 ;
}
2011-01-13 19:27:26 +00:00
2011-01-28 05:49:52 +00:00
string statusTextValue = statusbarText + " animation speed: " + floatToStr ( speed * 1000.0 ) + " zoom: " + floatToStr ( zoom ) + " rotX: " + floatToStr ( rotX ) + " rotY: " + floatToStr ( rotY ) ;
2011-01-20 19:47:33 +00:00
GetStatusBar ( ) - > SetStatusText ( ToUnicode ( statusTextValue . c_str ( ) ) ) ;
}
catch ( std : : runtime_error e ) {
std : : cout < < e . what ( ) < < std : : endl ;
wxMessageDialog ( NULL , ToUnicode ( e . what ( ) ) , ToUnicode ( " Error " ) , wxOK | wxICON_ERROR ) . ShowModal ( ) ;
}
2010-03-13 10:39:22 +00:00
}
2010-11-03 19:03:25 +00:00
// set menu checkboxes to what player color is used
2011-01-20 19:47:33 +00:00
void MainWindow : : onMenuColorRed ( wxCommandEvent & event ) {
try {
playerColor = Renderer : : pcRed ;
menuCustomColor - > Check ( miColorRed , true ) ;
menuCustomColor - > Check ( miColorBlue , false ) ;
menuCustomColor - > Check ( miColorGreen , false ) ;
menuCustomColor - > Check ( miColorYellow , false ) ;
menuCustomColor - > Check ( miColorWhite , false ) ;
menuCustomColor - > Check ( miColorCyan , false ) ;
menuCustomColor - > Check ( miColorOrange , false ) ;
menuCustomColor - > Check ( miColorMagenta , false ) ;
}
catch ( std : : runtime_error e ) {
std : : cout < < e . what ( ) < < std : : endl ;
wxMessageDialog ( NULL , ToUnicode ( e . what ( ) ) , ToUnicode ( " Error " ) , wxOK | wxICON_ERROR ) . ShowModal ( ) ;
}
}
void MainWindow : : onMenuColorBlue ( wxCommandEvent & event ) {
try {
playerColor = Renderer : : pcBlue ;
menuCustomColor - > Check ( miColorRed , false ) ;
menuCustomColor - > Check ( miColorBlue , true ) ;
menuCustomColor - > Check ( miColorGreen , false ) ;
menuCustomColor - > Check ( miColorYellow , false ) ;
menuCustomColor - > Check ( miColorWhite , false ) ;
menuCustomColor - > Check ( miColorCyan , false ) ;
menuCustomColor - > Check ( miColorOrange , false ) ;
menuCustomColor - > Check ( miColorMagenta , false ) ;
}
catch ( std : : runtime_error e ) {
std : : cout < < e . what ( ) < < std : : endl ;
wxMessageDialog ( NULL , ToUnicode ( e . what ( ) ) , ToUnicode ( " Error " ) , wxOK | wxICON_ERROR ) . ShowModal ( ) ;
}
}
void MainWindow : : onMenuColorGreen ( wxCommandEvent & event ) {
try {
playerColor = Renderer : : pcGreen ;
menuCustomColor - > Check ( miColorRed , false ) ;
menuCustomColor - > Check ( miColorBlue , false ) ;
menuCustomColor - > Check ( miColorGreen , true ) ;
menuCustomColor - > Check ( miColorYellow , false ) ;
menuCustomColor - > Check ( miColorWhite , false ) ;
menuCustomColor - > Check ( miColorCyan , false ) ;
menuCustomColor - > Check ( miColorOrange , false ) ;
menuCustomColor - > Check ( miColorMagenta , false ) ;
}
catch ( std : : runtime_error e ) {
std : : cout < < e . what ( ) < < std : : endl ;
wxMessageDialog ( NULL , ToUnicode ( e . what ( ) ) , ToUnicode ( " Error " ) , wxOK | wxICON_ERROR ) . ShowModal ( ) ;
}
}
void MainWindow : : onMenuColorYellow ( wxCommandEvent & event ) {
try {
playerColor = Renderer : : pcYellow ;
menuCustomColor - > Check ( miColorRed , false ) ;
menuCustomColor - > Check ( miColorBlue , false ) ;
menuCustomColor - > Check ( miColorGreen , false ) ;
menuCustomColor - > Check ( miColorYellow , true ) ;
menuCustomColor - > Check ( miColorWhite , false ) ;
menuCustomColor - > Check ( miColorCyan , false ) ;
menuCustomColor - > Check ( miColorOrange , false ) ;
menuCustomColor - > Check ( miColorMagenta , false ) ;
}
catch ( std : : runtime_error e ) {
std : : cout < < e . what ( ) < < std : : endl ;
wxMessageDialog ( NULL , ToUnicode ( e . what ( ) ) , ToUnicode ( " Error " ) , wxOK | wxICON_ERROR ) . ShowModal ( ) ;
}
}
void MainWindow : : onMenuColorWhite ( wxCommandEvent & event ) {
try {
playerColor = Renderer : : pcWhite ;
menuCustomColor - > Check ( miColorRed , false ) ;
menuCustomColor - > Check ( miColorBlue , false ) ;
menuCustomColor - > Check ( miColorGreen , false ) ;
menuCustomColor - > Check ( miColorYellow , false ) ;
menuCustomColor - > Check ( miColorWhite , true ) ;
menuCustomColor - > Check ( miColorCyan , false ) ;
menuCustomColor - > Check ( miColorOrange , false ) ;
menuCustomColor - > Check ( miColorMagenta , false ) ;
}
catch ( std : : runtime_error e ) {
std : : cout < < e . what ( ) < < std : : endl ;
wxMessageDialog ( NULL , ToUnicode ( e . what ( ) ) , ToUnicode ( " Error " ) , wxOK | wxICON_ERROR ) . ShowModal ( ) ;
}
}
void MainWindow : : onMenuColorCyan ( wxCommandEvent & event ) {
try {
playerColor = Renderer : : pcCyan ;
menuCustomColor - > Check ( miColorRed , false ) ;
menuCustomColor - > Check ( miColorBlue , false ) ;
menuCustomColor - > Check ( miColorGreen , false ) ;
menuCustomColor - > Check ( miColorYellow , false ) ;
menuCustomColor - > Check ( miColorWhite , false ) ;
menuCustomColor - > Check ( miColorCyan , true ) ;
menuCustomColor - > Check ( miColorOrange , false ) ;
menuCustomColor - > Check ( miColorMagenta , false ) ;
}
catch ( std : : runtime_error e ) {
std : : cout < < e . what ( ) < < std : : endl ;
wxMessageDialog ( NULL , ToUnicode ( e . what ( ) ) , ToUnicode ( " Error " ) , wxOK | wxICON_ERROR ) . ShowModal ( ) ;
}
}
void MainWindow : : onMenuColorOrange ( wxCommandEvent & event ) {
try {
playerColor = Renderer : : pcOrange ;
menuCustomColor - > Check ( miColorRed , false ) ;
menuCustomColor - > Check ( miColorBlue , false ) ;
menuCustomColor - > Check ( miColorGreen , false ) ;
menuCustomColor - > Check ( miColorYellow , false ) ;
menuCustomColor - > Check ( miColorWhite , false ) ;
menuCustomColor - > Check ( miColorCyan , false ) ;
menuCustomColor - > Check ( miColorOrange , true ) ;
menuCustomColor - > Check ( miColorMagenta , false ) ;
}
catch ( std : : runtime_error e ) {
std : : cout < < e . what ( ) < < std : : endl ;
wxMessageDialog ( NULL , ToUnicode ( e . what ( ) ) , ToUnicode ( " Error " ) , wxOK | wxICON_ERROR ) . ShowModal ( ) ;
}
}
void MainWindow : : onMenuColorMagenta ( wxCommandEvent & event ) {
try {
playerColor = Renderer : : pcMagenta ;
menuCustomColor - > Check ( miColorRed , false ) ;
menuCustomColor - > Check ( miColorBlue , false ) ;
menuCustomColor - > Check ( miColorGreen , false ) ;
menuCustomColor - > Check ( miColorYellow , false ) ;
menuCustomColor - > Check ( miColorWhite , false ) ;
menuCustomColor - > Check ( miColorCyan , false ) ;
menuCustomColor - > Check ( miColorOrange , false ) ;
menuCustomColor - > Check ( miColorMagenta , true ) ;
}
catch ( std : : runtime_error e ) {
std : : cout < < e . what ( ) < < std : : endl ;
wxMessageDialog ( NULL , ToUnicode ( e . what ( ) ) , ToUnicode ( " Error " ) , wxOK | wxICON_ERROR ) . ShowModal ( ) ;
}
}
void MainWindow : : onTimer ( wxTimerEvent & event ) {
2011-01-13 19:27:26 +00:00
anim = anim + speed ;
if ( anim > 1.0f ) {
anim - = 1.f ;
2011-01-29 03:53:05 +00:00
resetAnimation = true ;
2010-03-13 10:39:22 +00:00
}
2011-01-28 05:49:52 +00:00
wxPaintEvent paintEvent ;
2010-03-13 10:39:22 +00:00
onPaint ( paintEvent ) ;
}
2011-01-20 19:47:33 +00:00
string MainWindow : : getModelInfo ( ) {
2010-03-13 10:39:22 +00:00
string str ;
if ( model ! = NULL ) {
str + = " Meshes: " + intToStr ( model - > getMeshCount ( ) ) ;
str + = " , Vertices: " + intToStr ( model - > getVertexCount ( ) ) ;
str + = " , Triangles: " + intToStr ( model - > getTriangleCount ( ) ) ;
str + = " , Version: " + intToStr ( model - > getFileVersion ( ) ) ;
}
return str ;
}
2010-05-25 18:06:42 +00:00
void MainWindow : : onKeyDown ( wxKeyEvent & e ) {
2010-06-24 17:47:28 +00:00
2011-01-20 19:47:33 +00:00
try {
// std::cout << "e.ControlDown() = " << e.ControlDown() << " e.GetKeyCode() = " << e.GetKeyCode() << " isCtrl = " << (e.GetKeyCode() == WXK_CONTROL) << std::endl;
2010-06-24 17:47:28 +00:00
2011-01-29 08:46:28 +00:00
// Note: This ctrl-key handling is buggy since it never resets when ctrl is released later, so I reset it at end of loadcommands for now.
2011-01-20 19:47:33 +00:00
if ( e . ControlDown ( ) = = true | | e . GetKeyCode ( ) = = WXK_CONTROL ) {
isControlKeyPressed = true ;
}
else {
isControlKeyPressed = false ;
}
2010-06-24 14:00:20 +00:00
2011-01-20 19:47:33 +00:00
// std::cout << "isControlKeyPressed = " << isControlKeyPressed << std::endl;
2010-06-24 17:47:28 +00:00
2011-01-20 19:47:33 +00:00
// here also because + and - hotkeys don't work for numpad automaticly
if ( e . GetKeyCode ( ) = = 388 ) {
speed * = 1.5f ; //numpad+
if ( speed > 1.0 ) {
speed = 1.0 ;
}
2011-01-13 19:27:26 +00:00
2011-01-28 05:49:52 +00:00
string statusTextValue = statusbarText + " animation speed: " + floatToStr ( speed * 1000.0 ) + " zoom: " + floatToStr ( zoom ) + " rotX: " + floatToStr ( rotX ) + " rotY: " + floatToStr ( rotY ) ;
2011-01-20 19:47:33 +00:00
GetStatusBar ( ) - > SetStatusText ( ToUnicode ( statusTextValue . c_str ( ) ) ) ;
2011-01-13 19:27:26 +00:00
}
2011-01-20 19:47:33 +00:00
else if ( e . GetKeyCode ( ) = = 390 ) {
speed / = 1.5f ; //numpad-
if ( speed < 0 ) {
speed = 0 ;
}
2011-01-28 05:49:52 +00:00
string statusTextValue = statusbarText + " animation speed: " + floatToStr ( speed * 1000.0 ) + " zoom: " + floatToStr ( zoom ) + " rotX: " + floatToStr ( rotX ) + " rotY: " + floatToStr ( rotY ) ;
2011-01-20 19:47:33 +00:00
GetStatusBar ( ) - > SetStatusText ( ToUnicode ( statusTextValue . c_str ( ) ) ) ;
}
2011-01-29 08:46:28 +00:00
else if ( e . GetKeyCode ( ) = = ' W ' ) {
2011-01-20 19:47:33 +00:00
glClearColor ( 0.6f , 0.6f , 0.6f , 1.0f ) ; //w key //backgroundcolor constant 0.3 -> 0.6
2010-12-03 05:07:42 +00:00
2011-01-20 19:47:33 +00:00
}
2010-12-03 05:07:42 +00:00
2011-01-20 19:47:33 +00:00
// some posibility to adjust brightness:
/*
else if ( e . GetKeyCode ( ) = = 322 ) { // Ins - Grid
gridBrightness + = 0.1f ; if ( gridBrightness > 1.0 ) gridBrightness = 1.0 ;
}
else if ( e . GetKeyCode ( ) = = 127 ) { // Del
gridBrightness - = 0.1f ; if ( gridBrightness < 0 ) gridBrightness = 0 ;
}
*/
else if ( e . GetKeyCode ( ) = = 313 ) { // Home - Background
backBrightness + = 0.1f ; if ( backBrightness > 1.0 ) backBrightness = 1.0 ;
glClearColor ( backBrightness , backBrightness , backBrightness , 1.0f ) ;
}
else if ( e . GetKeyCode ( ) = = 312 ) { // End
backBrightness - = 0.1f ; if ( backBrightness < 0 ) backBrightness = 0 ;
glClearColor ( backBrightness , backBrightness , backBrightness , 1.0f ) ;
}
else if ( e . GetKeyCode ( ) = = 366 ) { // PgUp - Lightning of model
lightBrightness + = 0.1f ; if ( lightBrightness > 1.0 ) lightBrightness = 1.0 ;
Vec4f ambientNEW = Vec4f ( lightBrightness , lightBrightness , lightBrightness , 1.0f ) ;
glLightfv ( GL_LIGHT0 , GL_AMBIENT , ambientNEW . ptr ( ) ) ;
}
else if ( e . GetKeyCode ( ) = = 367 ) { // pgDn
lightBrightness - = 0.1f ; if ( lightBrightness < 0 ) lightBrightness = 0 ;
Vec4f ambientNEW = Vec4f ( lightBrightness , lightBrightness , lightBrightness , 1.0f ) ;
glLightfv ( GL_LIGHT0 , GL_AMBIENT , ambientNEW . ptr ( ) ) ;
}
2011-01-29 08:46:28 +00:00
std : : cout < < " pressed " < < e . GetKeyCode ( ) < < std : : endl ;
2010-12-03 05:07:42 +00:00
}
2011-01-20 19:47:33 +00:00
catch ( std : : runtime_error e ) {
std : : cout < < e . what ( ) < < std : : endl ;
wxMessageDialog ( NULL , ToUnicode ( e . what ( ) ) , ToUnicode ( " Error " ) , wxOK | wxICON_ERROR ) . ShowModal ( ) ;
2010-12-03 05:07:42 +00:00
}
2010-11-03 19:03:25 +00:00
}
2010-05-25 18:06:42 +00:00
2011-01-20 19:47:33 +00:00
void MainWindow : : onMenuRestart ( wxCommandEvent & event ) {
try {
// std::cout << "pressed R (restart particle animation)" << std::endl;
2011-01-29 22:59:33 +00:00
if ( timer ) timer - > Stop ( ) ;
if ( renderer ) renderer - > end ( ) ;
2010-06-24 17:47:28 +00:00
2011-01-20 19:47:33 +00:00
unitParticleSystems . clear ( ) ;
unitParticleSystemTypes . clear ( ) ;
projectileParticleSystems . clear ( ) ;
projectileParticleSystemTypes . clear ( ) ;
splashParticleSystems . clear ( ) ; // as above
splashParticleSystemTypes . clear ( ) ;
2010-05-25 18:06:42 +00:00
2011-01-29 03:53:05 +00:00
loadUnit ( " " , " " ) ;
2011-01-20 19:47:33 +00:00
loadModel ( " " ) ;
loadParticle ( " " ) ;
loadProjectileParticle ( " " ) ;
loadSplashParticle ( " " ) ; // as above
2010-06-24 17:47:28 +00:00
2011-01-20 19:47:33 +00:00
renderer - > initModelManager ( ) ;
2011-01-29 22:17:37 +00:00
if ( initTextureManager ) {
renderer - > initTextureManager ( ) ;
}
2011-01-29 22:59:33 +00:00
if ( timer ) timer - > Start ( 100 ) ;
2011-01-20 19:47:33 +00:00
}
catch ( std : : runtime_error e ) {
std : : cout < < e . what ( ) < < std : : endl ;
wxMessageDialog ( NULL , ToUnicode ( e . what ( ) ) , ToUnicode ( " Error " ) , wxOK | wxICON_ERROR ) . ShowModal ( ) ;
}
2010-05-25 18:06:42 +00:00
}
2010-03-13 10:39:22 +00:00
BEGIN_EVENT_TABLE ( MainWindow , wxFrame )
EVT_TIMER ( - 1 , MainWindow : : onTimer )
EVT_CLOSE ( MainWindow : : onClose )
EVT_MENU ( miFileLoad , MainWindow : : onMenuFileLoad )
2010-05-25 18:06:42 +00:00
EVT_MENU ( miFileLoadParticleXML , MainWindow : : onMenuFileLoadParticleXML )
2010-06-24 10:52:58 +00:00
EVT_MENU ( miFileLoadProjectileParticleXML , MainWindow : : onMenuFileLoadProjectileParticleXML )
2010-11-03 19:03:25 +00:00
EVT_MENU ( miFileLoadSplashParticleXML , MainWindow : : onMenuFileLoadSplashParticleXML )
2010-06-24 14:00:20 +00:00
EVT_MENU ( miFileClearAll , MainWindow : : onMenuFileClearAll )
2011-01-21 16:34:33 +00:00
EVT_MENU ( miFileToggleScreenshotTransparent , MainWindow : : onMenumFileToggleScreenshotTransparent )
2011-01-20 18:05:07 +00:00
EVT_MENU ( miFileSaveScreenshot , MainWindow : : onMenuFileSaveScreenshot )
2010-11-03 19:03:25 +00:00
EVT_MENU ( wxID_EXIT , MainWindow : : onMenuFileExit )
2010-03-13 10:39:22 +00:00
EVT_MENU ( miModeWireframe , MainWindow : : onMenuModeWireframe )
EVT_MENU ( miModeNormals , MainWindow : : onMenuModeNormals )
EVT_MENU ( miModeGrid , MainWindow : : onMenuModeGrid )
EVT_MENU ( miSpeedFaster , MainWindow : : onMenuSpeedFaster )
EVT_MENU ( miSpeedSlower , MainWindow : : onMenuSpeedSlower )
2010-11-03 19:03:25 +00:00
EVT_MENU ( miRestart , MainWindow : : onMenuRestart )
2010-03-13 10:39:22 +00:00
EVT_MENU ( miColorRed , MainWindow : : onMenuColorRed )
EVT_MENU ( miColorBlue , MainWindow : : onMenuColorBlue )
EVT_MENU ( miColorGreen , MainWindow : : onMenuColorGreen )
2010-11-03 19:03:25 +00:00
EVT_MENU ( miColorYellow , MainWindow : : onMenuColorYellow )
EVT_MENU ( miColorWhite , MainWindow : : onMenuColorWhite )
EVT_MENU ( miColorCyan , MainWindow : : onMenuColorCyan )
EVT_MENU ( miColorOrange , MainWindow : : onMenuColorOrange )
EVT_MENU ( miColorMagenta , MainWindow : : onMenuColorMagenta )
2011-01-20 18:05:07 +00:00
EVT_MENU ( miChangeBackgroundColor , MainWindow : : OnChangeColor )
2010-03-13 10:39:22 +00:00
END_EVENT_TABLE ( )
// =====================================================
// class GlCanvas
// =====================================================
2010-05-25 18:06:42 +00:00
void translateCoords ( wxWindow * wnd , int & x , int & y ) {
# ifdef WIN32
int cx , cy ;
wnd - > GetPosition ( & cx , & cy ) ;
x + = cx ;
y + = cy ;
# endif
}
2010-12-03 05:07:42 +00:00
// to prevent flicker
GlCanvas : : GlCanvas ( MainWindow * mainWindow , int * args )
2011-03-20 06:05:09 +00:00
# if wxCHECK_VERSION(2, 9, 1)
: wxGLCanvas ( mainWindow , - 1 , args , wxDefaultPosition , wxDefaultSize , 0 , wxT ( " GLCanvas " ) ) {
this - > context = new wxGLContext ( this ) ;
# else
2010-12-03 05:07:42 +00:00
: wxGLCanvas ( mainWindow , - 1 , wxDefaultPosition , wxDefaultSize , 0 , wxT ( " GLCanvas " ) , args ) {
2011-03-20 06:05:09 +00:00
this - > context = NULL ;
# endif
2010-12-03 05:07:42 +00:00
this - > mainWindow = mainWindow ;
2011-03-20 06:05:09 +00:00
}
GlCanvas : : ~ GlCanvas ( ) {
delete this - > context ;
this - > context = NULL ;
}
void GlCanvas : : setCurrentGLContext ( ) {
if ( this - > context ) {
this - > SetCurrent ( * this - > context ) ;
}
2010-12-03 05:07:42 +00:00
}
2010-11-03 19:03:25 +00:00
// for the mousewheel
void GlCanvas : : onMouseWheel ( wxMouseEvent & event ) {
if ( event . GetWheelRotation ( ) > 0 ) mainWindow - > onMouseWheelDown ( event ) ;
else mainWindow - > onMouseWheelUp ( event ) ;
}
2010-03-13 10:39:22 +00:00
void GlCanvas : : onMouseMove ( wxMouseEvent & event ) {
mainWindow - > onMouseMove ( event ) ;
}
2010-05-25 18:06:42 +00:00
void GlCanvas : : onKeyDown ( wxKeyEvent & event ) {
int x , y ;
event . GetPosition ( & x , & y ) ;
translateCoords ( this , x , y ) ;
mainWindow - > onKeyDown ( event ) ;
}
2010-11-03 19:03:25 +00:00
// EVT_SPIN_DOWN(GlCanvas::onMouseDown)
// EVT_SPIN_UP(GlCanvas::onMouseDown)
// EVT_MIDDLE_DOWN(GlCanvas::onMouseWheel)
// EVT_MIDDLE_UP(GlCanvas::onMouseWheel)
2010-03-13 10:39:22 +00:00
BEGIN_EVENT_TABLE ( GlCanvas , wxGLCanvas )
2010-11-03 19:03:25 +00:00
EVT_MOUSEWHEEL ( GlCanvas : : onMouseWheel )
2010-03-13 10:39:22 +00:00
EVT_MOTION ( GlCanvas : : onMouseMove )
2010-05-25 18:06:42 +00:00
EVT_KEY_DOWN ( GlCanvas : : onKeyDown )
2010-03-13 10:39:22 +00:00
END_EVENT_TABLE ( )
// ===============================================
// class App
// ===============================================
bool App : : OnInit ( ) {
2011-01-28 05:49:52 +00:00
string modelPath = " " ;
string particlePath = " " ;
string projectileParticlePath = " " ;
string splashParticlePath = " " ;
2011-01-28 01:41:30 +00:00
bool foundInvalidArgs = false ;
const int knownArgCount = sizeof ( GAME_ARGS ) / sizeof ( GAME_ARGS [ 0 ] ) ;
for ( int idx = 1 ; idx < argc ; + + idx ) {
const wxWX2MBbuf tmp_buf = wxConvCurrent - > cWX2MB ( argv [ idx ] ) ;
if ( hasCommandArgument ( knownArgCount , ( wxChar * * ) & GAME_ARGS [ 0 ] , ( const char * ) tmp_buf , NULL , 0 , true ) = = false & &
argv [ idx ] [ 0 ] = = ' - ' ) {
foundInvalidArgs = true ;
printf ( " \n Invalid argument: %s " , ( const char * ) tmp_buf ) ;
2010-11-03 19:03:25 +00:00
}
2011-01-28 01:41:30 +00:00
}
if ( foundInvalidArgs = = true | |
hasCommandArgument ( argc , argv , ( const char * ) wxConvCurrent - > cWX2MB ( GAME_ARGS [ GAME_ARG_HELP ] ) ) = = true ) {
printParameterHelp ( wxConvCurrent - > cWX2MB ( argv [ 0 ] ) , foundInvalidArgs ) ;
return false ;
}
if ( hasCommandArgument ( argc , argv , ( const char * ) wxConvCurrent - > cWX2MB ( GAME_ARGS [ GAME_ARG_AUTO_SCREENSHOT ] ) ) = = true ) {
autoScreenShotAndExit = true ;
const wxWX2MBbuf param = ( const char * ) wxConvCurrent - > cWX2MB ( GAME_ARGS [ GAME_ARG_AUTO_SCREENSHOT ] ) ;
//printf("param = [%s]\n",(const char*)param);
int foundParamIndIndex = - 1 ;
hasCommandArgument ( argc , argv , string ( ( const char * ) param ) + string ( " = " ) , & foundParamIndIndex ) ;
if ( foundParamIndIndex < 0 ) {
hasCommandArgument ( argc , argv , ( const char * ) param , & foundParamIndIndex ) ;
}
//printf("foundParamIndIndex = %d\n",foundParamIndIndex);
string options = ( const char * ) wxConvCurrent - > cWX2MB ( argv [ foundParamIndIndex ] ) ;
vector < string > paramPartTokens ;
Tokenize ( options , paramPartTokens , " = " ) ;
if ( paramPartTokens . size ( ) > = 2 & & paramPartTokens [ 1 ] . length ( ) > 0 ) {
string optionsValue = paramPartTokens [ 1 ] ;
autoScreenShotParams . clear ( ) ;
Tokenize ( optionsValue , autoScreenShotParams , " , " ) ;
}
}
2011-01-29 04:35:55 +00:00
std : : pair < string , vector < string > > unitToLoad ;
2011-01-29 03:53:05 +00:00
if ( hasCommandArgument ( argc , argv , ( const char * ) wxConvCurrent - > cWX2MB ( GAME_ARGS [ GAME_ARG_LOAD_UNIT ] ) ) = = true ) {
const wxWX2MBbuf param = ( const char * ) wxConvCurrent - > cWX2MB ( GAME_ARGS [ GAME_ARG_LOAD_UNIT ] ) ;
//printf("param = [%s]\n",(const char*)param);
int foundParamIndIndex = - 1 ;
hasCommandArgument ( argc , argv , string ( ( const char * ) param ) + string ( " = " ) , & foundParamIndIndex ) ;
if ( foundParamIndIndex < 0 ) {
hasCommandArgument ( argc , argv , ( const char * ) param , & foundParamIndIndex ) ;
}
//printf("foundParamIndIndex = %d\n",foundParamIndIndex);
string customPath = ( const char * ) wxConvCurrent - > cWX2MB ( argv [ foundParamIndIndex ] ) ;
vector < string > paramPartTokens ;
Tokenize ( customPath , paramPartTokens , " = " ) ;
if ( paramPartTokens . size ( ) > = 2 & & paramPartTokens [ 1 ] . length ( ) > 0 ) {
string customPathValue = paramPartTokens [ 1 ] ;
std : : vector < string > delimitedList ;
Tokenize ( customPathValue , delimitedList , " , " ) ;
if ( delimitedList . size ( ) > = 2 ) {
unitToLoad . first = delimitedList [ 0 ] ;
2011-01-29 17:42:34 +00:00
for ( unsigned int i = 1 ; i < delimitedList . size ( ) ; + + i ) {
2011-01-29 04:35:55 +00:00
unitToLoad . second . push_back ( delimitedList [ i ] ) ;
}
2011-01-29 03:53:05 +00:00
}
else {
printf ( " \n Invalid path specified on commandline [%s] value [%s] \n \n " , ( const char * ) wxConvCurrent - > cWX2MB ( argv [ foundParamIndIndex ] ) , ( paramPartTokens . size ( ) > = 2 ? paramPartTokens [ 1 ] . c_str ( ) : NULL ) ) ;
printParameterHelp ( wxConvCurrent - > cWX2MB ( argv [ 0 ] ) , false ) ;
return false ;
}
}
else {
printf ( " \n Invalid path specified on commandline [%s] value [%s] \n \n " , ( const char * ) wxConvCurrent - > cWX2MB ( argv [ foundParamIndIndex ] ) , ( paramPartTokens . size ( ) > = 2 ? paramPartTokens [ 1 ] . c_str ( ) : NULL ) ) ;
printParameterHelp ( wxConvCurrent - > cWX2MB ( argv [ 0 ] ) , false ) ;
return false ;
}
}
2011-01-29 08:46:28 +00:00
if ( hasCommandArgument ( argc , argv , ( const char * ) wxConvCurrent - > cWX2MB ( GAME_ARGS [ GAME_ARG_LOAD_MODEL ] ) ) = = true & &
hasCommandArgument ( argc , argv , ( const char * ) wxConvCurrent - > cWX2MB ( GAME_ARGS [ GAME_ARG_LOAD_MODEL_ANIMATION_VALUE ] ) ) = = false ) {
2011-01-28 01:41:30 +00:00
const wxWX2MBbuf param = ( const char * ) wxConvCurrent - > cWX2MB ( GAME_ARGS [ GAME_ARG_LOAD_MODEL ] ) ;
//printf("param = [%s]\n",(const char*)param);
int foundParamIndIndex = - 1 ;
hasCommandArgument ( argc , argv , string ( ( const char * ) param ) + string ( " = " ) , & foundParamIndIndex ) ;
if ( foundParamIndIndex < 0 ) {
hasCommandArgument ( argc , argv , ( const char * ) param , & foundParamIndIndex ) ;
}
//printf("foundParamIndIndex = %d\n",foundParamIndIndex);
string customPath = ( const char * ) wxConvCurrent - > cWX2MB ( argv [ foundParamIndIndex ] ) ;
vector < string > paramPartTokens ;
Tokenize ( customPath , paramPartTokens , " = " ) ;
if ( paramPartTokens . size ( ) > = 2 & & paramPartTokens [ 1 ] . length ( ) > 0 ) {
string customPathValue = paramPartTokens [ 1 ] ;
modelPath = customPathValue ;
}
else {
printf ( " \n Invalid path specified on commandline [%s] value [%s] \n \n " , ( const char * ) wxConvCurrent - > cWX2MB ( argv [ foundParamIndIndex ] ) , ( paramPartTokens . size ( ) > = 2 ? paramPartTokens [ 1 ] . c_str ( ) : NULL ) ) ;
printParameterHelp ( wxConvCurrent - > cWX2MB ( argv [ 0 ] ) , false ) ;
return false ;
}
}
2011-01-29 08:46:28 +00:00
if ( hasCommandArgument ( argc , argv , ( const char * ) wxConvCurrent - > cWX2MB ( GAME_ARGS [ GAME_ARG_LOAD_PARTICLE ] ) ) = = true & &
hasCommandArgument ( argc , argv , ( const char * ) wxConvCurrent - > cWX2MB ( GAME_ARGS [ GAME_ARG_LOAD_PARTICLE_LOOP_VALUE ] ) ) = = false ) {
2011-01-28 05:49:52 +00:00
const wxWX2MBbuf param = ( const char * ) wxConvCurrent - > cWX2MB ( GAME_ARGS [ GAME_ARG_LOAD_PARTICLE ] ) ;
//printf("param = [%s]\n",(const char*)param);
int foundParamIndIndex = - 1 ;
hasCommandArgument ( argc , argv , string ( ( const char * ) param ) + string ( " = " ) , & foundParamIndIndex ) ;
if ( foundParamIndIndex < 0 ) {
hasCommandArgument ( argc , argv , ( const char * ) param , & foundParamIndIndex ) ;
}
//printf("foundParamIndIndex = %d\n",foundParamIndIndex);
string customPath = ( const char * ) wxConvCurrent - > cWX2MB ( argv [ foundParamIndIndex ] ) ;
vector < string > paramPartTokens ;
Tokenize ( customPath , paramPartTokens , " = " ) ;
if ( paramPartTokens . size ( ) > = 2 & & paramPartTokens [ 1 ] . length ( ) > 0 ) {
string customPathValue = paramPartTokens [ 1 ] ;
particlePath = customPathValue ;
}
else {
printf ( " \n Invalid path specified on commandline [%s] value [%s] \n \n " , ( const char * ) wxConvCurrent - > cWX2MB ( argv [ foundParamIndIndex ] ) , ( paramPartTokens . size ( ) > = 2 ? paramPartTokens [ 1 ] . c_str ( ) : NULL ) ) ;
printParameterHelp ( wxConvCurrent - > cWX2MB ( argv [ 0 ] ) , false ) ;
return false ;
}
}
if ( hasCommandArgument ( argc , argv , ( const char * ) wxConvCurrent - > cWX2MB ( GAME_ARGS [ GAME_ARG_LOAD_PARTICLE_PROJECTILE ] ) ) = = true ) {
const wxWX2MBbuf param = ( const char * ) wxConvCurrent - > cWX2MB ( GAME_ARGS [ GAME_ARG_LOAD_PARTICLE_PROJECTILE ] ) ;
//printf("param = [%s]\n",(const char*)param);
int foundParamIndIndex = - 1 ;
hasCommandArgument ( argc , argv , string ( ( const char * ) param ) + string ( " = " ) , & foundParamIndIndex ) ;
if ( foundParamIndIndex < 0 ) {
hasCommandArgument ( argc , argv , ( const char * ) param , & foundParamIndIndex ) ;
}
//printf("foundParamIndIndex = %d\n",foundParamIndIndex);
string customPath = ( const char * ) wxConvCurrent - > cWX2MB ( argv [ foundParamIndIndex ] ) ;
vector < string > paramPartTokens ;
Tokenize ( customPath , paramPartTokens , " = " ) ;
if ( paramPartTokens . size ( ) > = 2 & & paramPartTokens [ 1 ] . length ( ) > 0 ) {
string customPathValue = paramPartTokens [ 1 ] ;
projectileParticlePath = customPathValue ;
}
else {
printf ( " \n Invalid path specified on commandline [%s] value [%s] \n \n " , ( const char * ) wxConvCurrent - > cWX2MB ( argv [ foundParamIndIndex ] ) , ( paramPartTokens . size ( ) > = 2 ? paramPartTokens [ 1 ] . c_str ( ) : NULL ) ) ;
printParameterHelp ( wxConvCurrent - > cWX2MB ( argv [ 0 ] ) , false ) ;
return false ;
}
}
if ( hasCommandArgument ( argc , argv , ( const char * ) wxConvCurrent - > cWX2MB ( GAME_ARGS [ GAME_ARG_LOAD_PARTICLE_SPLASH ] ) ) = = true ) {
const wxWX2MBbuf param = ( const char * ) wxConvCurrent - > cWX2MB ( GAME_ARGS [ GAME_ARG_LOAD_PARTICLE_SPLASH ] ) ;
//printf("param = [%s]\n",(const char*)param);
int foundParamIndIndex = - 1 ;
hasCommandArgument ( argc , argv , string ( ( const char * ) param ) + string ( " = " ) , & foundParamIndIndex ) ;
if ( foundParamIndIndex < 0 ) {
hasCommandArgument ( argc , argv , ( const char * ) param , & foundParamIndIndex ) ;
}
//printf("foundParamIndIndex = %d\n",foundParamIndIndex);
string customPath = ( const char * ) wxConvCurrent - > cWX2MB ( argv [ foundParamIndIndex ] ) ;
vector < string > paramPartTokens ;
Tokenize ( customPath , paramPartTokens , " = " ) ;
if ( paramPartTokens . size ( ) > = 2 & & paramPartTokens [ 1 ] . length ( ) > 0 ) {
string customPathValue = paramPartTokens [ 1 ] ;
splashParticlePath = customPathValue ;
}
else {
printf ( " \n Invalid path specified on commandline [%s] value [%s] \n \n " , ( const char * ) wxConvCurrent - > cWX2MB ( argv [ foundParamIndIndex ] ) , ( paramPartTokens . size ( ) > = 2 ? paramPartTokens [ 1 ] . c_str ( ) : NULL ) ) ;
printParameterHelp ( wxConvCurrent - > cWX2MB ( argv [ 0 ] ) , false ) ;
return false ;
}
}
float newAnimValue = 0.0f ;
if ( hasCommandArgument ( argc , argv , ( const char * ) wxConvCurrent - > cWX2MB ( GAME_ARGS [ GAME_ARG_LOAD_MODEL_ANIMATION_VALUE ] ) ) = = true ) {
const wxWX2MBbuf param = ( const char * ) wxConvCurrent - > cWX2MB ( GAME_ARGS [ GAME_ARG_LOAD_MODEL_ANIMATION_VALUE ] ) ;
int foundParamIndIndex = - 1 ;
hasCommandArgument ( argc , argv , string ( ( const char * ) param ) + string ( " = " ) , & foundParamIndIndex ) ;
if ( foundParamIndIndex < 0 ) {
hasCommandArgument ( argc , argv , ( const char * ) param , & foundParamIndIndex ) ;
}
//printf("foundParamIndIndex = %d\n",foundParamIndIndex);
string value = ( const char * ) wxConvCurrent - > cWX2MB ( argv [ foundParamIndIndex ] ) ;
vector < string > paramPartTokens ;
Tokenize ( value , paramPartTokens , " = " ) ;
if ( paramPartTokens . size ( ) > = 2 & & paramPartTokens [ 1 ] . length ( ) > 0 ) {
newAnimValue = strToFloat ( paramPartTokens [ 1 ] ) ;
2011-01-29 08:46:28 +00:00
printf ( " newAnimValue = %f \n " , newAnimValue ) ;
2011-01-28 05:49:52 +00:00
}
else {
printf ( " \n Invalid path specified on commandline [%s] value [%s] \n \n " , ( const char * ) wxConvCurrent - > cWX2MB ( argv [ foundParamIndIndex ] ) , ( paramPartTokens . size ( ) > = 2 ? paramPartTokens [ 1 ] . c_str ( ) : NULL ) ) ;
printParameterHelp ( wxConvCurrent - > cWX2MB ( argv [ 0 ] ) , false ) ;
return false ;
}
}
int newParticleLoopValue = 1 ;
if ( hasCommandArgument ( argc , argv , ( const char * ) wxConvCurrent - > cWX2MB ( GAME_ARGS [ GAME_ARG_LOAD_PARTICLE_LOOP_VALUE ] ) ) = = true ) {
const wxWX2MBbuf param = ( const char * ) wxConvCurrent - > cWX2MB ( GAME_ARGS [ GAME_ARG_LOAD_PARTICLE_LOOP_VALUE ] ) ;
int foundParamIndIndex = - 1 ;
hasCommandArgument ( argc , argv , string ( ( const char * ) param ) + string ( " = " ) , & foundParamIndIndex ) ;
if ( foundParamIndIndex < 0 ) {
hasCommandArgument ( argc , argv , ( const char * ) param , & foundParamIndIndex ) ;
}
//printf("foundParamIndIndex = %d\n",foundParamIndIndex);
string value = ( const char * ) wxConvCurrent - > cWX2MB ( argv [ foundParamIndIndex ] ) ;
vector < string > paramPartTokens ;
Tokenize ( value , paramPartTokens , " = " ) ;
if ( paramPartTokens . size ( ) > = 2 & & paramPartTokens [ 1 ] . length ( ) > 0 ) {
newParticleLoopValue = strToInt ( paramPartTokens [ 1 ] ) ;
//printf("newParticleLoopValue = %d\n",newParticleLoopValue);
}
else {
printf ( " \n Invalid path specified on commandline [%s] value [%s] \n \n " , ( const char * ) wxConvCurrent - > cWX2MB ( argv [ foundParamIndIndex ] ) , ( paramPartTokens . size ( ) > = 2 ? paramPartTokens [ 1 ] . c_str ( ) : NULL ) ) ;
printParameterHelp ( wxConvCurrent - > cWX2MB ( argv [ 0 ] ) , false ) ;
return false ;
}
}
float newZoomValue = 1.0f ;
if ( hasCommandArgument ( argc , argv , ( const char * ) wxConvCurrent - > cWX2MB ( GAME_ARGS [ GAME_ARG_ZOOM_VALUE ] ) ) = = true ) {
const wxWX2MBbuf param = ( const char * ) wxConvCurrent - > cWX2MB ( GAME_ARGS [ GAME_ARG_ZOOM_VALUE ] ) ;
int foundParamIndIndex = - 1 ;
hasCommandArgument ( argc , argv , string ( ( const char * ) param ) + string ( " = " ) , & foundParamIndIndex ) ;
if ( foundParamIndIndex < 0 ) {
hasCommandArgument ( argc , argv , ( const char * ) param , & foundParamIndIndex ) ;
}
//printf("foundParamIndIndex = %d\n",foundParamIndIndex);
string value = ( const char * ) wxConvCurrent - > cWX2MB ( argv [ foundParamIndIndex ] ) ;
vector < string > paramPartTokens ;
Tokenize ( value , paramPartTokens , " = " ) ;
if ( paramPartTokens . size ( ) > = 2 & & paramPartTokens [ 1 ] . length ( ) > 0 ) {
newZoomValue = strToFloat ( paramPartTokens [ 1 ] ) ;
//printf("newAnimValue = %f\n",newAnimValue);
}
else {
printf ( " \n Invalid path specified on commandline [%s] value [%s] \n \n " , ( const char * ) wxConvCurrent - > cWX2MB ( argv [ foundParamIndIndex ] ) , ( paramPartTokens . size ( ) > = 2 ? paramPartTokens [ 1 ] . c_str ( ) : NULL ) ) ;
printParameterHelp ( wxConvCurrent - > cWX2MB ( argv [ 0 ] ) , false ) ;
return false ;
}
}
float newXRotValue = 0.0f ;
if ( hasCommandArgument ( argc , argv , ( const char * ) wxConvCurrent - > cWX2MB ( GAME_ARGS [ GAME_ARG_ROTATE_X_VALUE ] ) ) = = true ) {
const wxWX2MBbuf param = ( const char * ) wxConvCurrent - > cWX2MB ( GAME_ARGS [ GAME_ARG_ROTATE_X_VALUE ] ) ;
int foundParamIndIndex = - 1 ;
hasCommandArgument ( argc , argv , string ( ( const char * ) param ) + string ( " = " ) , & foundParamIndIndex ) ;
if ( foundParamIndIndex < 0 ) {
hasCommandArgument ( argc , argv , ( const char * ) param , & foundParamIndIndex ) ;
}
//printf("foundParamIndIndex = %d\n",foundParamIndIndex);
string value = ( const char * ) wxConvCurrent - > cWX2MB ( argv [ foundParamIndIndex ] ) ;
vector < string > paramPartTokens ;
Tokenize ( value , paramPartTokens , " = " ) ;
if ( paramPartTokens . size ( ) > = 2 & & paramPartTokens [ 1 ] . length ( ) > 0 ) {
newXRotValue = strToFloat ( paramPartTokens [ 1 ] ) ;
//printf("newAnimValue = %f\n",newAnimValue);
}
else {
printf ( " \n Invalid path specified on commandline [%s] value [%s] \n \n " , ( const char * ) wxConvCurrent - > cWX2MB ( argv [ foundParamIndIndex ] ) , ( paramPartTokens . size ( ) > = 2 ? paramPartTokens [ 1 ] . c_str ( ) : NULL ) ) ;
printParameterHelp ( wxConvCurrent - > cWX2MB ( argv [ 0 ] ) , false ) ;
return false ;
}
}
float newYRotValue = 0.0f ;
if ( hasCommandArgument ( argc , argv , ( const char * ) wxConvCurrent - > cWX2MB ( GAME_ARGS [ GAME_ARG_ROTATE_Y_VALUE ] ) ) = = true ) {
const wxWX2MBbuf param = ( const char * ) wxConvCurrent - > cWX2MB ( GAME_ARGS [ GAME_ARG_ROTATE_Y_VALUE ] ) ;
int foundParamIndIndex = - 1 ;
hasCommandArgument ( argc , argv , string ( ( const char * ) param ) + string ( " = " ) , & foundParamIndIndex ) ;
if ( foundParamIndIndex < 0 ) {
hasCommandArgument ( argc , argv , ( const char * ) param , & foundParamIndIndex ) ;
}
//printf("foundParamIndIndex = %d\n",foundParamIndIndex);
string value = ( const char * ) wxConvCurrent - > cWX2MB ( argv [ foundParamIndIndex ] ) ;
vector < string > paramPartTokens ;
Tokenize ( value , paramPartTokens , " = " ) ;
if ( paramPartTokens . size ( ) > = 2 & & paramPartTokens [ 1 ] . length ( ) > 0 ) {
newYRotValue = strToFloat ( paramPartTokens [ 1 ] ) ;
//printf("newAnimValue = %f\n",newAnimValue);
}
else {
printf ( " \n Invalid path specified on commandline [%s] value [%s] \n \n " , ( const char * ) wxConvCurrent - > cWX2MB ( argv [ foundParamIndIndex ] ) , ( paramPartTokens . size ( ) > = 2 ? paramPartTokens [ 1 ] . c_str ( ) : NULL ) ) ;
printParameterHelp ( wxConvCurrent - > cWX2MB ( argv [ 0 ] ) , false ) ;
return false ;
}
}
2011-01-28 01:41:30 +00:00
if ( argc = = 2 & & argv [ 1 ] [ 0 ] ! = ' - ' ) {
2010-12-08 20:03:15 +00:00
# if defined(__MINGW32__)
const wxWX2MBbuf tmp_buf = wxConvCurrent - > cWX2MB ( wxFNCONV ( argv [ 1 ] ) ) ;
modelPath = tmp_buf ;
# else
modelPath = wxFNCONV ( argv [ 1 ] ) ;
# endif
2010-03-13 10:39:22 +00:00
}
2011-03-05 23:15:07 +00:00
string appPath = " " ;
2011-03-12 02:28:00 +00:00
//#if defined(__MINGW32__)
// const wxWX2MBbuf tmp_buf = wxConvCurrent->cWX2MB(wxFNCONV(argv[0]));
// appPath = tmp_buf;
//#else
// appPath = wxFNCONV(argv[0]);
//#endif
// printf("appPath [%s]\n",argv[0]);
wxString exe_path = wxStandardPaths : : Get ( ) . GetExecutablePath ( ) ;
//wxString path_separator = wxFileName::GetPathSeparator();
//exe_path = exe_path.BeforeLast(path_separator[0]);
//exe_path += path_separator;
2011-03-05 23:15:07 +00:00
# if defined(__MINGW32__)
2011-03-12 02:28:00 +00:00
const wxWX2MBbuf tmp_buf = wxConvCurrent - > cWX2MB ( wxFNCONV ( exe_path ) ) ;
2011-03-05 23:15:07 +00:00
appPath = tmp_buf ;
# else
2011-03-12 02:28:00 +00:00
appPath = wxFNCONV ( exe_path ) ;
2011-03-05 23:15:07 +00:00
# endif
2011-03-12 02:28:00 +00:00
// printf("#2 appPath [%s]\n",appPath.c_str());
2011-01-29 03:53:05 +00:00
mainWindow = new MainWindow ( unitToLoad ,
modelPath ,
2011-01-28 05:49:52 +00:00
particlePath ,
projectileParticlePath ,
splashParticlePath ,
newAnimValue ,
newParticleLoopValue ,
newZoomValue ,
newXRotValue ,
2011-03-05 23:15:07 +00:00
newYRotValue ,
appPath ) ;
2010-03-13 10:39:22 +00:00
mainWindow - > Show ( ) ;
mainWindow - > init ( ) ;
2011-01-29 23:03:56 +00:00
mainWindow - > Update ( ) ;
2011-03-20 06:05:09 +00:00
mainWindow - > setupTimer ( ) ;
2010-03-13 10:39:22 +00:00
return true ;
}
int App : : MainLoop ( ) {
try {
return wxApp : : MainLoop ( ) ;
}
catch ( const exception & e ) {
wxMessageDialog ( NULL , ToUnicode ( e . what ( ) ) , ToUnicode ( " Exception " ) , wxOK | wxICON_ERROR ) . ShowModal ( ) ;
return 0 ;
}
}
int App : : OnExit ( ) {
2011-03-11 23:48:16 +00:00
SystemFlags : : Close ( ) ;
SystemFlags : : SHUTDOWN_PROGRAM_MODE = true ;
2010-03-13 10:39:22 +00:00
return 0 ;
}
} } //end namespace
2011-03-12 02:28:00 +00:00
IMPLEMENT_APP_CONSOLE ( Shared : : G3dViewer : : App )