b3view/main.cpp

68 lines
1.4 KiB
C++
Raw Normal View History

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"
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
{
2010-04-22 05:16:15 -07:00
// Parse commandline to check if a filename argument has been passed
#ifdef WIN32
int argc;
char **argv;
LPWSTR *args;
args = CommandLineToArgvW( GetCommandLineW(), &argc );
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] );
}
LocalFree( args );
#endif
2010-04-21 07:48:36 -07:00
Engine *engine = new Engine();
2010-04-22 05:16:15 -07:00
if( argc >= 2 )
{
wchar_t *initialFileName = getWideCharString( argv[1] );
engine->loadMesh( wstring( initialFileName ));
free( initialFileName );
}
else
engine->loadMesh( L"test.b3d" );
2010-04-21 07:48:36 -07:00
engine->run();
delete engine;
2010-04-22 05:16:15 -07:00
#ifdef WIN32
for( int index = 0; index < argc; index ++ )
free( argv[index] );
free( argv );
#endif
}
wchar_t * getWideCharString( char *str )
{
wchar_t *dest = ( wchar_t * ) malloc( sizeof( wchar_t ) * ( strlen( str ) + 1 ));
int resultSize = mbstowcs( 0, str, strlen( str ));
mbstowcs( dest, str, strlen( str ));
dest[resultSize] = '\0';
2010-04-22 05:16:15 -07:00
return dest;
2010-04-21 07:48:36 -07:00
}
2010-04-22 01:44:10 -07:00