Draws a screen with a single text on it.
Text will be removed when the screen is drawn the next time.
Additionally, a progressbar can be drawn when percent is set between 0 and 100.
- With drawsmgr, you can for example draw clouds
*/
/*gui::IGUIStaticText **/
void draw_load_screen(const std::wstring &text,
IrrlichtDevice* device, gui::IGUIFont* font,
- int percent=-1, bool drawsmgr=false)
+ float dtime=0 ,int percent=0, bool clouds=true)
{
video::IVideoDriver* driver = device->getVideoDriver();
v2u32 screensize = driver->getScreenSize();
loadingtext, textrect, false, false);
guitext->setTextAlignment(gui::EGUIA_CENTER, gui::EGUIA_UPPERLEFT);
- if (drawsmgr)
+ bool cloud_menu_background = clouds && g_settings->getBool("menu_clouds");
+ if (cloud_menu_background)
{
+ g_menuclouds->step(dtime*3);
+ g_menuclouds->render();
driver->beginScene(true, true, video::SColor(255,140,186,250));
- scene::ISceneManager* smgr = device->getSceneManager();
- smgr->drawAll();
+ g_menucloudsmgr->drawAll();
}
else
driver->beginScene(true, true, video::SColor(255,0,0,0));
core::vector2d<s32> barsize(256,32);
core::rect<s32> barrect(center-barsize/2, center+barsize/2);
driver->draw2DRectangle(video::SColor(255,255,255,255),barrect, NULL); // border
- driver->draw2DRectangle(video::SColor(255,0,0,0), core::rect<s32> (
+ driver->draw2DRectangle(video::SColor(255,64,64,64), core::rect<s32> (
barrect.UpperLeftCorner+1,
barrect.LowerRightCorner-1), NULL); // black inside the bar
driver->draw2DRectangle(video::SColor(255,128,128,128), core::rect<s32> (
Draw "Loading" screen
*/
- draw_load_screen(L"Loading...", device, font);
+ {
+ wchar_t* text = wgettext("Loading...");
+ draw_load_screen(text, device, font,0,0);
+ delete[] text;
+ }
// Create texture source
IWritableTextureSource *tsrc = createTextureSource(device);
*/
if(address == ""){
- draw_load_screen(L"Creating server...", device, font);
+ wchar_t* text = wgettext("Creating server....");
+ draw_load_screen(text, device, font,0,25);
+ delete[] text;
infostream<<"Creating server"<<std::endl;
server = new Server(map_dir, configpath, gamespec,
simple_singleplayer_mode);
Create client
*/
- draw_load_screen(L"Creating client...", device, font);
+ {
+ wchar_t* text = wgettext("Creating client...");
+ draw_load_screen(text, device, font,0,50);
+ delete[] text;
+ }
infostream<<"Creating client"<<std::endl;
MapDrawControl draw_control;
// Client acts as our GameDef
IGameDef *gamedef = &client;
-
- draw_load_screen(L"Resolving address...", device, font);
+
+ {
+ wchar_t* text = wgettext("Resolving address...");
+ draw_load_screen(text, device, font,0,75);
+ delete[] text;
+ }
Address connect_address(0,0,0,0, port);
try{
if(address == "")
bool could_connect = false;
bool connect_aborted = false;
try{
- float frametime = 0.033;
float time_counter = 0.0;
input->clear();
+ float fps_max = g_settings->getFloat("fps_max");
+ bool cloud_menu_background = g_settings->getBool("menu_clouds");
+ u32 lasttime = device->getTimer()->getTime();
while(device->run())
{
+ f32 dtime=0; // in seconds
+ if (cloud_menu_background) {
+ u32 time = device->getTimer()->getTime();
+ if(time > lasttime)
+ dtime = (time - lasttime) / 1000.0;
+ else
+ dtime = 0;
+ lasttime = time;
+ }
// Update client and server
- client.step(frametime);
+ client.step(dtime);
if(server != NULL)
- server->step(frametime);
+ server->step(dtime);
// End condition
if(client.connectedAndInitialized()){
}
// Display status
- std::wostringstream ss;
- ss<<L"Connecting to server... (press Escape to cancel)\n";
- std::wstring animation = L"/-\\|";
- ss<<animation[(int)(time_counter/0.2)%4];
- draw_load_screen(ss.str(), device, font);
+ {
+ wchar_t* text = wgettext("Connecting to server...");
+ draw_load_screen(text, device, font, dtime, 100);
+ delete[] text;
+ }
- // Delay a bit
- sleep_ms(1000*frametime);
- time_counter += frametime;
+ // On some computers framerate doesn't seem to be
+ // automatically limited
+ if (cloud_menu_background) {
+ // Time of frame without fps limit
+ float busytime;
+ u32 busytime_u32;
+ // not using getRealTime is necessary for wine
+ u32 time = device->getTimer()->getTime();
+ if(time > lasttime)
+ busytime_u32 = time - lasttime;
+ else
+ busytime_u32 = 0;
+ busytime = busytime_u32 / 1000.0;
+
+ // FPS limiter
+ u32 frametime_min = 1000./fps_max;
+
+ if(busytime_u32 < frametime_min) {
+ u32 sleeptime = frametime_min - busytime_u32;
+ device->sleep(sleeptime);
+ }
+ } else {
+ sleep_ms(25);
+ }
+ time_counter += dtime;
}
}
catch(con::PeerNotFoundException &e)
bool got_content = false;
bool content_aborted = false;
{
- float frametime = 0.033;
float time_counter = 0.0;
input->clear();
-
- scene::ISceneManager* smgr = device->getSceneManager();
- Clouds *clouds = 0;
- if (g_settings->getBool("menu_clouds"))
- {
- // add clouds
- clouds = new Clouds(smgr->getRootSceneNode(),
- smgr, -1, rand(), 100);
- clouds->update(v2f(0, 0), video::SColor(255,200,200,255));
-
- // A camera to see the clouds
- scene::ICameraSceneNode* camera;
- camera = smgr->addCameraSceneNode(0,
- v3f(0,0,0), v3f(0, 60, 100));
- camera->setFarValue(10000);
- }
-
+ float fps_max = g_settings->getFloat("fps_max");
+ bool cloud_menu_background = g_settings->getBool("menu_clouds");
+ u32 lasttime = device->getTimer()->getTime();
while(device->run())
{
+ f32 dtime=0; // in seconds
+ if (cloud_menu_background) {
+ u32 time = device->getTimer()->getTime();
+ if(time > lasttime)
+ dtime = (time - lasttime) / 1000.0;
+ else
+ dtime = 0;
+ lasttime = time;
+ }
// Update client and server
- client.step(frametime);
+ client.step(dtime);
if(server != NULL)
- server->step(frametime);
+ server->step(dtime);
// End condition
if(client.texturesReceived() &&
}
// Display status
- std::wostringstream ss;
+ std::ostringstream ss;
+ int progress=0;
if (!client.itemdefReceived())
- ss << L"Item definitions...";
+ {
+ ss << "Item definitions...";
+ progress = 0;
+ }
else if (!client.nodedefReceived())
- ss << L"Node definitions...";
+ {
+ ss << "Node definitions...";
+ progress = 25;
+ }
else
- ss << L"Media (" << (int)(client.mediaReceiveProgress()*100+0.5) << L"%)...";
-
- if (clouds != 0)
{
- clouds->step(frametime*3);
- clouds->render();
+ ss << "Media...";
+ progress = 50+client.mediaReceiveProgress()*50+0.5;
}
+ wchar_t* text = wgettext(ss.str().c_str());
+ draw_load_screen(text, device, font, dtime, progress);
+ delete[] text;
- draw_load_screen(ss.str(), device, font, client.mediaReceiveProgress()*100+0.5, clouds!=0);
-
- // Delay a bit
- sleep_ms(1000*frametime);
- time_counter += frametime;
- }
- if (clouds != 0)
- {
- smgr->addToDeletionQueue(clouds);
- clouds->drop();
+ // On some computers framerate doesn't seem to be
+ // automatically limited
+ if (cloud_menu_background) {
+ // Time of frame without fps limit
+ float busytime;
+ u32 busytime_u32;
+ // not using getRealTime is necessary for wine
+ u32 time = device->getTimer()->getTime();
+ if(time > lasttime)
+ busytime_u32 = time - lasttime;
+ else
+ busytime_u32 = 0;
+ busytime = busytime_u32 / 1000.0;
+
+ // FPS limiter
+ u32 frametime_min = 1000./fps_max;
+
+ if(busytime_u32 < frametime_min) {
+ u32 sleeptime = frametime_min - busytime_u32;
+ device->sleep(sleeptime);
+ }
+ } else {
+ sleep_ms(25);
+ }
+ time_counter += dtime;
}
}
*/
{
/*gui::IGUIStaticText *gui_shuttingdowntext = */
- draw_load_screen(L"Shutting down stuff...", device, font);
+ wchar_t* text = wgettext("Shutting down stuff...");
+ draw_load_screen(text, device, font, 0, -1, false);
+ delete[] text;
/*driver->beginScene(true, true, video::SColor(255,0,0,0));
guienv->drawAll();
driver->endScene();
Profiler main_profiler;
Profiler *g_profiler = &main_profiler;
+// Menu clouds are created later
+Clouds *g_menuclouds = 0;
+irr::scene::ISceneManager *g_menucloudsmgr = 0;
+
/*
Debug streams
*/
skin->setColor(gui::EGDC_FOCUSED_EDITABLE, video::SColor(255,96,134,49));
#endif
+
+ // Create the menu clouds
+ if (!g_menucloudsmgr)
+ g_menucloudsmgr = smgr->createNewSceneManager();
+ if (!g_menuclouds)
+ g_menuclouds = new Clouds(g_menucloudsmgr->getRootSceneNode(),
+ g_menucloudsmgr, -1, rand(), 100);
+ g_menuclouds->update(v2f(0, 0), video::SColor(255,200,200,255));
+ scene::ICameraSceneNode* camera;
+ camera = g_menucloudsmgr->addCameraSceneNode(0,
+ v3f(0,0,0), v3f(0, 60, 100));
+ camera->setFarValue(10000);
+
/*
GUI stuff
*/
&g_menumgr, &menudata, g_gamecallback);
menu->allowFocusRemoval(true);
- // Always create clouds because they may or may not be
- // needed based on the game selected
- Clouds *clouds = new Clouds(smgr->getRootSceneNode(),
- smgr, -1, rand(), 100);
- clouds->update(v2f(0, 0), video::SColor(255,200,200,255));
-
- // A camera to see the clouds
- scene::ICameraSceneNode* camera;
- camera = smgr->addCameraSceneNode(0,
- v3f(0,0,0), v3f(0, 60, 100));
- camera->setFarValue(10000);
-
if(error_message != L"")
{
verbosestream<<"error_message = "
}
// Time calc for the clouds
- f32 dtime; // in seconds
+ f32 dtime=0; // in seconds
if (cloud_menu_background) {
u32 time = device->getTimer()->getTime();
if(time > lasttime)
if (cloud_menu_background) {
// *3 otherwise the clouds would move very slowly
- clouds->step(dtime*3);
- clouds->render();
- smgr->drawAll();
+ g_menuclouds->step(dtime*3);
+ g_menuclouds->render();
+ g_menucloudsmgr->drawAll();
drawMenuOverlay(driver, menutextures);
drawMenuHeader(driver, menutextures);
drawMenuFooter(driver, menutextures);
infostream<<"Dropping main menu"<<std::endl;
menu->drop();
- clouds->drop();
- smgr->clear();
}
playername = wide_to_narrow(menudata.name);
gamespec,
simple_singleplayer_mode
);
+ smgr->clear();
} //try
catch(con::PeerNotFoundException &e)
}
} // Menu-game loop
+
+ g_menuclouds->drop();
+ g_menucloudsmgr->drop();
+
delete input;
/*