aboutsummaryrefslogtreecommitdiff
path: root/src/game.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/game.cpp')
-rw-r--r--src/game.cpp188
1 files changed, 127 insertions, 61 deletions
diff --git a/src/game.cpp b/src/game.cpp
index 61e4963c0..81f35d4c0 100644
--- a/src/game.cpp
+++ b/src/game.cpp
@@ -396,12 +396,11 @@ PointedThing getPointedThing(Client *client, v3f player_position,
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();
@@ -415,11 +414,13 @@ void draw_load_screen(const std::wstring &text,
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));
@@ -428,7 +429,7 @@ void draw_load_screen(const std::wstring &text,
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> (
@@ -907,7 +908,11 @@ void the_game(
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);
@@ -964,7 +969,9 @@ void the_game(
*/
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);
@@ -977,7 +984,11 @@ void the_game(
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;
@@ -987,8 +998,12 @@ void the_game(
// 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 == "")
@@ -1020,15 +1035,26 @@ void the_game(
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()){
@@ -1049,15 +1075,37 @@ void the_game(
}
// 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)
@@ -1081,32 +1129,26 @@ void the_game(
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() &&
@@ -1128,30 +1170,52 @@ void the_game(
}
// 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;
}
}
@@ -3278,7 +3342,9 @@ void the_game(
*/
{
/*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();