2010-04-22 05:16:15 -07:00
|
|
|
#include <string.h>
|
|
|
|
#include <malloc.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
2010-04-21 07:48:36 -07:00
|
|
|
#include "Engine.h"
|
|
|
|
|
2019-03-07 19:18:07 -08:00
|
|
|
using std::wstring;
|
|
|
|
|
|
|
|
using namespace irr;
|
|
|
|
using namespace irr::core;
|
|
|
|
|
2010-04-22 05:16:15 -07:00
|
|
|
wchar_t * getWideCharString( char *str );
|
|
|
|
|
2010-04-22 01:44:10 -07:00
|
|
|
#ifdef WIN32
|
|
|
|
#include <Windows.h>
|
|
|
|
int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow )
|
|
|
|
#else
|
2010-04-21 07:48:36 -07:00
|
|
|
int main( int argc, char **argv )
|
2010-04-22 01:44:10 -07:00
|
|
|
#endif
|
2010-04-21 07:48:36 -07:00
|
|
|
{
|
2019-03-07 10:23:54 -08:00
|
|
|
// Parse commandline to check if a filename argument has been passed
|
2010-04-22 05:16:15 -07:00
|
|
|
#ifdef WIN32
|
2019-03-07 10:23:54 -08:00
|
|
|
int argc;
|
|
|
|
char **argv;
|
2010-04-22 05:16:15 -07:00
|
|
|
|
2019-03-07 10:23:54 -08:00
|
|
|
LPWSTR *args;
|
|
|
|
args = CommandLineToArgvW( GetCommandLineW(), &argc );
|
2010-04-22 05:16:15 -07:00
|
|
|
|
2019-03-07 10:23:54 -08:00
|
|
|
argv = ( char ** ) malloc( sizeof( char * ) * argc );
|
|
|
|
for( int index = 0; index < argc; index ++ )
|
|
|
|
{
|
|
|
|
int argumentBufferLength = wcslen( args[index] ) + 1;
|
|
|
|
argv[index] = ( char * ) malloc( sizeof( char ) * argumentBufferLength );
|
|
|
|
sprintf_s( argv[index], argumentBufferLength, "%ws", args[index] );
|
|
|
|
}
|
2010-04-22 05:16:15 -07:00
|
|
|
|
2019-03-07 10:23:54 -08:00
|
|
|
LocalFree( args );
|
2010-04-22 05:16:15 -07:00
|
|
|
#endif
|
|
|
|
|
2010-04-21 07:48:36 -07:00
|
|
|
Engine *engine = new Engine();
|
2019-03-07 10:23:54 -08:00
|
|
|
if( argc >= 2 )
|
|
|
|
{
|
|
|
|
wchar_t *initialFileName = getWideCharString( argv[1] );
|
|
|
|
engine->loadMesh( wstring( initialFileName ));
|
|
|
|
free( initialFileName );
|
|
|
|
}
|
2019-03-09 12:42:40 -08:00
|
|
|
// else
|
|
|
|
// engine->loadMesh( L"test.b3d" );
|
2010-04-22 05:16:15 -07:00
|
|
|
|
2010-04-21 07:48:36 -07:00
|
|
|
engine->run();
|
|
|
|
|
|
|
|
delete engine;
|
2010-04-22 05:16:15 -07:00
|
|
|
|
|
|
|
#ifdef WIN32
|
2019-03-07 10:23:54 -08:00
|
|
|
for( int index = 0; index < argc; index ++ )
|
|
|
|
free( argv[index] );
|
|
|
|
free( argv );
|
2010-04-22 05:16:15 -07:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
wchar_t * getWideCharString( char *str )
|
|
|
|
{
|
2019-03-07 10:23:54 -08:00
|
|
|
wchar_t *dest = ( wchar_t * ) malloc( sizeof( wchar_t ) * ( strlen( str ) + 1 ));
|
2010-04-23 00:28:59 -07:00
|
|
|
|
2019-03-07 10:23:54 -08:00
|
|
|
int resultSize = mbstowcs( nullptr, str, strlen( str ));
|
2010-04-23 00:28:59 -07:00
|
|
|
mbstowcs( dest, str, strlen( str ));
|
|
|
|
|
|
|
|
dest[resultSize] = '\0';
|
2010-04-22 05:16:15 -07:00
|
|
|
|
2019-03-07 10:23:54 -08:00
|
|
|
return dest;
|
2010-04-21 07:48:36 -07:00
|
|
|
}
|
2010-04-22 01:44:10 -07:00
|
|
|
|