diff --git a/Engine.cpp b/Engine.cpp index 7544826..d209da3 100644 --- a/Engine.cpp +++ b/Engine.cpp @@ -72,14 +72,6 @@ void Engine::drawBackground() SColor( 255, 224, 224, 255 )); } -void Engine::loadMesh( const wstring &fileName ) -{ - if( m_LoadedMesh != 0 ) - m_LoadedMesh->remove(); - - m_LoadedMesh = m_Scene->addAnimatedMeshSceneNode( m_Scene->getMesh( fileName.c_str() )); -} - void Engine::checkResize() { if(( m_WindowSize->Width != m_Driver->getScreenSize().Width ) || ( m_WindowSize->Height != m_Driver->getScreenSize().Height )) @@ -131,10 +123,7 @@ Engine::Engine() // Set Engine enabled m_RunEngine = true; - - // Load test model m_LoadedMesh = 0; - loadMesh( L"test.b3d" ); // Store actual window size m_WindowSize = new dimension2d(); @@ -148,6 +137,14 @@ Engine::~Engine() delete m_WindowSize; } +void Engine::loadMesh( const wstring &fileName ) +{ + if( m_LoadedMesh != 0 ) + m_LoadedMesh->remove(); + + m_LoadedMesh = m_Scene->addAnimatedMeshSceneNode( m_Scene->getMesh( fileName.c_str() )); +} + void Engine::run() { u32 timePerFrame = ( u32 ) ( 1000.0f / 60 ); diff --git a/Engine.h b/Engine.h index f2422b1..2e0b879 100644 --- a/Engine.h +++ b/Engine.h @@ -55,14 +55,14 @@ private: void drawAxisLines(); void drawBackground(); void checkResize(); - IGUIEnvironment *getGUIEnvironment() const; - void loadMesh( const wstring &fileName ); + IGUIEnvironment *getGUIEnvironment() const; public: Engine(); ~Engine(); - void run(); + void run(); + void loadMesh( const wstring &fileName ); }; #endif // ENGINE_H diff --git a/UserInterface.cpp b/UserInterface.cpp index d816a82..47eeb8a 100644 --- a/UserInterface.cpp +++ b/UserInterface.cpp @@ -3,14 +3,15 @@ // PRIVATE void UserInterface::setupUserInterface() { + // Menu IGUIContextMenu *menu = m_Gui->addMenu(); menu->addItem( L"File", UIE_FILEMENU, true, true ); + // File Menu IGUIContextMenu *fileMenu = menu->getSubMenu( 0 ); fileMenu->addItem( L"Load", UIC_FILE_LOAD ); fileMenu->addItem( L"Quit", UIC_FILE_QUIT ); - // Set Font for UI Elements m_GuiFont = m_Gui->getFont( "arial.xml" ); m_Gui->getSkin()->setFont( m_GuiFont ); diff --git a/View.cpp b/View.cpp index fe318b9..bf8598c 100644 --- a/View.cpp +++ b/View.cpp @@ -52,6 +52,7 @@ View::~View() // IEventReceiver bool View::OnEvent( const SEvent &event ) { + // If it's not a mouse event, just return unhandled if( event.EventType != EET_MOUSE_INPUT_EVENT ) return false; diff --git a/main.cpp b/main.cpp index efeb046..3771f13 100644 --- a/main.cpp +++ b/main.cpp @@ -1,5 +1,11 @@ +#include +#include +#include + #include "Engine.h" +wchar_t * getWideCharString( char *str ); + #ifdef WIN32 #include int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow ) @@ -7,9 +13,51 @@ int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLin int main( int argc, char **argv ) #endif { + // 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 + Engine *engine = new Engine(); + if( argc >= 2 ) + { + wchar_t *initialFileName = getWideCharString( argv[1] ); + engine->loadMesh( wstring( initialFileName )); + free( initialFileName ); + } + else + engine->loadMesh( L"test.b3d" ); + engine->run(); delete engine; + +#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 )); + mbstowcs( dest, str, strlen( str )); + + return dest; } diff --git a/win32/b3view.suo b/win32/b3view.suo index d5987bf..81a3434 100644 Binary files a/win32/b3view.suo and b/win32/b3view.suo differ diff --git a/win32/b3view.vcxproj b/win32/b3view.vcxproj index 3abcd4c..e55d824 100644 --- a/win32/b3view.vcxproj +++ b/win32/b3view.vcxproj @@ -54,7 +54,7 @@ Level3 Disabled - WIN32;_DEBUG;_WINDOWS;%(PreprocessorDefinitions) + WIN32;_DEBUG;_WINDOWS;%(PreprocessorDefinitions);_CRT_SECURE_NO_WARNINGS D:\Prj\irrlicht-1.7.1\include;%(AdditionalIncludeDirectories) @@ -72,16 +72,17 @@ MaxSpeed true true - WIN32;NDEBUG;_WINDOWS;%(PreprocessorDefinitions) + WIN32;NDEBUG;_WINDOWS;%(PreprocessorDefinitions);_CRT_SECURE_NO_WARNINGS D:\Prj\irrlicht-1.7.1\include;%(AdditionalIncludeDirectories) - Windows + Console true true true D:\Prj\irrlicht-1.7.1\lib\Win32-visualstudio;%(AdditionalLibraryDirectories) Irrlicht.lib;%(AdditionalDependencies) + WinMain