Example #1
0
void ModelViewer::Run(const std::string &modelName)
{
	ScopedPtr<GameConfig> config(new GameConfig);

	Graphics::Renderer *renderer;
	ModelViewer *viewer;

	//init components
	FileSystem::Init();
	FileSystem::userFiles.MakeDirectory(""); // ensure the config directory exists
	if (SDL_Init(SDL_INIT_VIDEO) < 0)
		OS::Error("SDL initialization failed: %s\n", SDL_GetError());
	Lua::Init();

	// needed for the UI
	SDL_EnableUNICODE(1);

	//video
	Graphics::Settings videoSettings = {};
	videoSettings.width = config->Int("ScrWidth");
	videoSettings.height = config->Int("ScrHeight");
	videoSettings.fullscreen = (config->Int("StartFullscreen") != 0);
	videoSettings.shaders = (config->Int("DisableShaders") == 0);
	videoSettings.requestedSamples = config->Int("AntiAliasingMode");
	videoSettings.vsync = (config->Int("VSync") != 0);
	videoSettings.useTextureCompression = (config->Int("UseTextureCompression") != 0);
	renderer = Graphics::Init(videoSettings);

	OS::LoadWindowIcon();
	SDL_WM_SetCaption("Model viewer","Model viewer");

	//run main loop until quit
	viewer = new ModelViewer(renderer, Lua::manager);
	viewer->SetModel(modelName);
	viewer->MainLoop();

	//uninit components
	delete viewer;
	Lua::Uninit();
	delete renderer;
	Graphics::Uninit();
	FileSystem::Uninit();
	SDL_Quit();
}
Example #2
0
File: rboot.cpp Project: skopp/rush
bool RBoot::Init( const CommandLine& cmd )
{
    import( rb_core         );

    JCore* m_pCore = new JCore();
    m_pCore->SetName( "core" );

    if (m_pCore != JCore::s_pInstance)
    {
        return false;
    }

    uint32_t hwnd = 0;
    const char* pHandle = cmd.GetValue( "window" );
    if (pHandle)
    {
        sscanf( pHandle, "%d", &hwnd );
    }

    import( rb_draw         );
    //import( rb_extui        );
    import( rb_particle     );
    ImportRenderLib();
    import( rb_scene        );
    import( rb_script_lua   );
    //import( rb_sound        );
    //import( rb_texture      );
    import( rb_ui           );
    //import( rb_video        );
    //import( rb_physics      );

    link_class( ModelViewer );
    link_class( TestDriver  );

    m_pCore->Init();

    AddCommonMediaPath();

    const char* scriptFile = cmd.GetValue( "script" );
    JObject* pRoot = NULL;
    if (scriptFile)
    {
        //  find script's media directory and add it
        AddScriptMediaPath( scriptFile );
        //  load script
        pRoot = g_pPersistServer->LoadObject( scriptFile );
    }
    else
    {
        AddModuleMediaPath();
    }

    const char* mediaDir = cmd.GetValue( "media" );
    g_pFileServer->AddMediaPath( mediaDir );

    m_pCore->AddServer( "animserver"      );
    m_pCore->AddServer( "stringserver"    );
    m_pCore->AddServer( "windowserver"    );
    m_pCore->AddServer( c_RenderServerName );
    m_pCore->AddServer( "drawserver"      );
    m_pCore->AddServer( "modelserver"     );
    m_pCore->AddServer( "particleserver"  );
    m_pCore->AddServer( "luaserver"       );
    m_pCore->AddServer( "soundserver"     );
    m_pCore->AddServer( "physicsserver"   );
    m_pCore->AddServer( "videoserver"     );

    g_pWindowServer->SetRootHandle( reinterpret_cast<void*>( hwnd ) );

    m_pCore->InitTree();

    if (!pRoot)
    {
        pRoot = g_pPersistServer->LoadObject( "rboot" );
    }
    if (!pRoot)
    {
        return false;
    }

    JString objPath;
    pRoot->GetPath( objPath );
    m_pCore->SetRootObject( objPath.c_str() );

    g_pWindowServer->AddWindow( pRoot );
    pRoot->InitTree();

    ModelViewer* pModelViewer = obj_cast<ModelViewer>( pRoot );
    Path animPath, modelPath;
    if (pModelViewer)
    {
        pModelViewer->SetAnim( cmd.GetValue( "anim" ) );
        pModelViewer->SetModel( cmd.GetValue( "model" ) );
    }

    JDialog* pRootDlg = obj_cast<JDialog>( pRoot );
    if (pRootDlg)
    {
        pRootDlg->Show();
    }

    return true;
}