switching resolution multiple times now works (i.e. you get no more [?] boxes and 'hello's

git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/branches/irrlicht@3478 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
auria 2009-05-11 00:23:40 +00:00
parent e7836dab60
commit b03f45605b
4 changed files with 54 additions and 44 deletions

View File

@ -59,37 +59,42 @@ IrrDriver::~IrrDriver()
void IrrDriver::initDevice() void IrrDriver::initDevice()
{ {
// ----------- static bool firstTime = true;
// attempt to detect available video modes. fails miserably for the moment, please test on other platforms...
m_device = createDevice(EDT_NULL);
video::IVideoModeList* modes = m_device->getVideoModeList(); // ---- the first time, get a list of available video modes
const int count = modes->getVideoModeCount(); if(firstTime)
std::cout << "--------------\n allowed modes \n--------------\n";
std::cout << "Desktop depth : " << modes->getDesktopDepth() << std::endl;
std::cout << "Desktop resolution : " << modes->getDesktopResolution().Width << "," << modes->getDesktopResolution().Height << std::endl;
std::cout << "Found " << count << " valid modes\n";
for(int i=0; i<count; i++)
{ {
// only consider 32-bit resolutions for now m_device = createDevice(EDT_NULL);
if(modes->getVideoModeDepth(i) >= 24)
video::IVideoModeList* modes = m_device->getVideoModeList();
const int count = modes->getVideoModeCount();
std::cout << "--------------\n allowed modes \n--------------\n";
std::cout << "Desktop depth : " << modes->getDesktopDepth() << std::endl;
std::cout << "Desktop resolution : " << modes->getDesktopResolution().Width << "," << modes->getDesktopResolution().Height << std::endl;
std::cout << "Found " << count << " valid modes\n";
for(int i=0; i<count; i++)
{ {
VideoMode mode; // only consider 32-bit resolutions for now
mode.width = modes->getVideoModeResolution(i).Width; if(modes->getVideoModeDepth(i) >= 24)
mode.height = modes->getVideoModeResolution(i).Height; {
m_modes.push_back( mode ); VideoMode mode;
mode.width = modes->getVideoModeResolution(i).Width;
mode.height = modes->getVideoModeResolution(i).Height;
m_modes.push_back( mode );
}
std::cout <<
"bits : " << modes->getVideoModeDepth(i) <<
" resolution=" << modes->getVideoModeResolution(i).Width <<
"x" << modes->getVideoModeResolution(i).Height << std::endl;
} }
m_device->closeDevice();
std::cout <<
"bits : " << modes->getVideoModeDepth(i) << firstTime = false;
" resolution=" << modes->getVideoModeResolution(i).Width << } // end if firstTime
"x" << modes->getVideoModeResolution(i).Height << std::endl;
} // ---- open device
m_device->closeDevice();
// ------------
// Try different drivers: start with opengl, then DirectX // Try different drivers: start with opengl, then DirectX
for(int driver_type=0; driver_type<3; driver_type++) for(int driver_type=0; driver_type<3; driver_type++)
{ {

View File

@ -27,6 +27,7 @@ Screen::Screen(const char* file)
this->m_filename = file; this->m_filename = file;
m_loaded = false; m_loaded = false;
loadFromFile(); loadFromFile();
m_inited = false;
} }
#if 0 #if 0

View File

@ -36,11 +36,18 @@ namespace GUIEngine
// current mouse position, read-only... // current mouse position, read-only...
int m_mouse_x, m_mouse_y; int m_mouse_x, m_mouse_y;
/** this variable is not used by the Screen object itself; it's the routines creating
* screens that may use it to perform some operations only once. initialized to false.
*/
bool m_inited;
Screen(const char* filename); Screen(const char* filename);
bool operator ==(const char* filename) const { return m_filename == filename; } bool operator ==(const char* filename) const { return m_filename == filename; }
/** returns an object by name, or NULL if not found */
Widget* getWidget(const char* name); Widget* getWidget(const char* name);
/** returns an object by name, casted to specified type, or NULL if not found/wrong type */
template <typename T> T* getWidget(const char* name) template <typename T> T* getWidget(const char* name)
{ {
return dynamic_cast<T*>( getWidget(name) ); return dynamic_cast<T*>( getWidget(name) );

View File

@ -70,13 +70,12 @@ namespace StateManager
*/ */
void menuEventKarts(Widget* widget, std::string& name) void menuEventKarts(Widget* widget, std::string& name)
{ {
static bool karts_menu_inited = false; if(name == "init")
if(name == "init" /*&& !karts_menu_inited*/)
{ {
RibbonGridWidget* w = getCurrentScreen()->getWidget<RibbonGridWidget>("karts"); RibbonGridWidget* w = getCurrentScreen()->getWidget<RibbonGridWidget>("karts");
assert( w != NULL ); assert( w != NULL );
if(!karts_menu_inited) if(!getCurrentScreen()->m_inited)
{ {
w->addItem("Gnu","k1","gui/gnu.png"); w->addItem("Gnu","k1","gui/gnu.png");
w->addItem("Wilber","k2","gui/gnu.png"); w->addItem("Wilber","k2","gui/gnu.png");
@ -86,7 +85,7 @@ namespace StateManager
w->addItem("Sushi","k6","gui/gnu.png"); w->addItem("Sushi","k6","gui/gnu.png");
w->addItem("Nolok","k7","gui/gnu.png"); w->addItem("Nolok","k7","gui/gnu.png");
w->addItem("Mozilla","k8","gui/gnu.png"); w->addItem("Mozilla","k8","gui/gnu.png");
karts_menu_inited = true; getCurrentScreen()->m_inited = true;
} }
w->updateItemDisplay(); w->updateItemDisplay();
@ -108,7 +107,9 @@ namespace StateManager
//test->setMaterialFlag(EMF_LIGHTING , false); //test->setMaterialFlag(EMF_LIGHTING , false);
w3->setModel(test); w3->setModel(test);
}
getCurrentScreen()->m_inited = true;
} // end if init
// TODO - actually check which kart was selected // TODO - actually check which kart was selected
else if(name == "karts") else if(name == "karts")
{ {
@ -207,13 +208,12 @@ namespace StateManager
*/ */
void menuEventTracks(Widget* widget, std::string& name) void menuEventTracks(Widget* widget, std::string& name)
{ {
static bool track_menu_inited = false;
if(name == "init") if(name == "init")
{ {
RibbonGridWidget* w = getCurrentScreen()->getWidget<RibbonGridWidget>("tracks"); RibbonGridWidget* w = getCurrentScreen()->getWidget<RibbonGridWidget>("tracks");
assert( w != NULL ); assert( w != NULL );
if(!track_menu_inited) if(!getCurrentScreen()->m_inited)
{ {
w->addItem("Track 1","t1","gui/track1.png"); w->addItem("Track 1","t1","gui/track1.png");
w->addItem("Track 2","t2","gui/track2.png"); w->addItem("Track 2","t2","gui/track2.png");
@ -223,7 +223,7 @@ namespace StateManager
w->addItem("Track 6","t6","gui/track6.png"); w->addItem("Track 6","t6","gui/track6.png");
w->addItem("Track 7","t7","gui/track7.png"); w->addItem("Track 7","t7","gui/track7.png");
w->addItem("Track 8","t8","gui/track8.png"); w->addItem("Track 8","t8","gui/track8.png");
track_menu_inited = true; getCurrentScreen()->m_inited = true;
} }
w->updateItemDisplay(); w->updateItemDisplay();
@ -270,7 +270,7 @@ namespace StateManager
if(name == "init") if(name == "init")
{ {
const std::string& screen_name = getCurrentScreen()->getName(); const std::string& screen_name = getCurrentScreen()->getName();
RibbonWidget* ribbon = getCurrentScreen()->getWidget<RibbonWidget>("options_choice"); RibbonWidget* ribbon = getCurrentScreen()->getWidget<RibbonWidget>("options_choice");
if(ribbon != NULL) if(ribbon != NULL)
{ {
@ -293,7 +293,6 @@ namespace StateManager
assert(gauge != NULL); assert(gauge != NULL);
gauge->setValue( sound_manager->getMasterMusicVolume()*10.f ); gauge->setValue( sound_manager->getMasterMusicVolume()*10.f );
// ---- music volume // ---- music volume
CheckBoxWidget* sfx = getCurrentScreen()->getWidget<CheckBoxWidget>("sfx_enabled"); CheckBoxWidget* sfx = getCurrentScreen()->getWidget<CheckBoxWidget>("sfx_enabled");
@ -313,10 +312,8 @@ namespace StateManager
assert( full != NULL ); assert( full != NULL );
full->setState( user_config->m_fullscreen ); full->setState( user_config->m_fullscreen );
static bool resolutions_inited = false;
// --- get resolution list from irrlicht the first time // --- get resolution list from irrlicht the first time
if(!resolutions_inited) if(!getCurrentScreen()->m_inited)
{ {
const std::vector<VideoMode>& modes = irr_driver->getVideoModes(); const std::vector<VideoMode>& modes = irr_driver->getVideoModes();
const int amount = modes.size(); const int amount = modes.size();
@ -344,12 +341,12 @@ namespace StateManager
else else
{ {
std::cout << "Unknown screen size ratio : " << ratio << std::endl; std::cout << "Unknown screen size ratio : " << ratio << std::endl;
// FIXME - do something better than showing a random icon
res->addItem(name,name,"gui/screen1610.png"); res->addItem(name,name,"gui/screen1610.png");
} }
#undef ABOUT_EQUAL #undef ABOUT_EQUAL
} // next resolution } // next resolution
resolutions_inited = true;
} // end if not inited } // end if not inited
res->updateItemDisplay(); res->updateItemDisplay();
@ -382,8 +379,7 @@ namespace StateManager
RibbonGridWidget* devices = getCurrentScreen()->getWidget<RibbonGridWidget>("devices"); RibbonGridWidget* devices = getCurrentScreen()->getWidget<RibbonGridWidget>("devices");
assert( devices != NULL ); assert( devices != NULL );
static bool devices_inited = false; if(!getCurrentScreen()->m_inited)
if(!devices_inited)
{ {
devices->addItem("Keyboard","keyboard","gui/keyboard.png"); devices->addItem("Keyboard","keyboard","gui/keyboard.png");
@ -397,10 +393,11 @@ namespace StateManager
devices->addItem(name,internal_name,"gui/gamepad.png"); devices->addItem(name,internal_name,"gui/gamepad.png");
} }
devices_inited = true;
} }
devices->updateItemDisplay(); devices->updateItemDisplay();
} }
getCurrentScreen()->m_inited;
} // end init } // end init
// -- options // -- options