3 Copyright (C) 2010-2011 celeron55, Perttu Ahola <celeron55@gmail.com>
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License along
16 with this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 #include "common_irrlicht.h"
24 #include "guiPauseMenu.h"
25 #include "guiInventoryMenu.h"
26 #include "guiTextInputMenu.h"
27 #include "guiFurnaceMenu.h"
28 #include "materials.h"
33 Setting this to 1 enables a special camera mode that forces
34 the renderers to think that the camera statically points from
35 the starting place to a static direction.
37 This allows one to move around with the player and see what
38 is actually drawn behind solid things and behind the player.
40 #define FIELD_OF_VIEW_TEST 0
43 MapDrawControl draw_control;
52 ChatLine(const std::wstring &a_text):
65 // Inventory actions from the menu are buffered here before sending
66 Queue<InventoryAction*> inventory_action_queue;
67 // This is a copy of the inventory that the client's environment has
68 Inventory local_inventory;
70 u16 g_selected_item = 0;
76 struct TextDestSign : public TextDest
78 TextDestSign(v3s16 blockpos, s16 id, Client *client)
80 m_blockpos = blockpos;
84 void gotText(std::wstring text)
86 std::string ntext = wide_to_narrow(text);
87 dstream<<"Changing text of a sign object: "
89 m_client->sendSignText(m_blockpos, m_id, ntext);
97 struct TextDestChat : public TextDest
99 TextDestChat(Client *client)
103 void gotText(std::wstring text)
105 // Discard empty line
109 // Parse command (server command starts with "/#")
110 if(text[0] == L'/' && text[1] != L'#')
112 std::wstring reply = L"Local: ";
114 reply += L"Local commands not yet supported. "
115 L"Server prefix is \"/#\".";
117 m_client->addChatMessage(reply);
122 m_client->sendChatMessage(text);
124 m_client->addChatMessage(text);
130 struct TextDestSignNode : public TextDest
132 TextDestSignNode(v3s16 p, Client *client)
137 void gotText(std::wstring text)
139 std::string ntext = wide_to_narrow(text);
140 dstream<<"Changing text of a sign node: "
142 m_client->sendSignNodeText(m_p, ntext);
150 Render distance feedback loop
152 void updateViewingRange(f32 frametime_in, Client *client)
154 if(draw_control.range_all == true)
157 static f32 added_frametime = 0;
158 static s16 added_frames = 0;
160 added_frametime += frametime_in;
163 // Actually this counter kind of sucks because frametime is busytime
164 static f32 counter = 0;
165 counter -= frametime_in;
171 /*dstream<<__FUNCTION_NAME
172 <<": Collected "<<added_frames<<" frames, total of "
173 <<added_frametime<<"s."<<std::endl;*/
175 /*dstream<<"draw_control.blocks_drawn="
176 <<draw_control.blocks_drawn
177 <<", draw_control.blocks_would_have_drawn="
178 <<draw_control.blocks_would_have_drawn
181 float range_min = g_settings.getS16("viewing_range_nodes_min");
182 float range_max = g_settings.getS16("viewing_range_nodes_max");
184 // Limit minimum to keep the feedback loop stable
188 draw_control.wanted_min_range = range_min;
189 //draw_control.wanted_max_blocks = (1.5*draw_control.blocks_drawn)+1;
190 draw_control.wanted_max_blocks = (1.5*draw_control.blocks_would_have_drawn)+1;
191 if(draw_control.wanted_max_blocks < 10)
192 draw_control.wanted_max_blocks = 10;
194 float block_draw_ratio = 1.0;
195 if(draw_control.blocks_would_have_drawn != 0)
197 block_draw_ratio = (float)draw_control.blocks_drawn
198 / (float)draw_control.blocks_would_have_drawn;
201 // Calculate the average frametime in the case that all wanted
202 // blocks had been drawn
203 f32 frametime = added_frametime / added_frames / block_draw_ratio;
205 added_frametime = 0.0;
208 float wanted_fps = g_settings.getFloat("wanted_fps");
209 float wanted_frametime = 1.0 / wanted_fps;
211 f32 wanted_frametime_change = wanted_frametime - frametime;
212 //dstream<<"wanted_frametime_change="<<wanted_frametime_change<<std::endl;
214 // If needed frametime change is small, just return
215 if(fabs(wanted_frametime_change) < wanted_frametime*0.4)
217 //dstream<<"ignoring small wanted_frametime_change"<<std::endl;
221 float range = draw_control.wanted_range;
222 float new_range = range;
224 static s16 range_old = 0;
225 static f32 frametime_old = 0;
227 float d_range = range - range_old;
228 f32 d_frametime = frametime - frametime_old;
229 // A sane default of 30ms per 50 nodes of range
230 static f32 time_per_range = 30. / 50;
233 time_per_range = d_frametime / d_range;
236 // The minimum allowed calculated frametime-range derivative:
237 // Practically this sets the maximum speed of changing the range.
238 // The lower this value, the higher the maximum changing speed.
239 // A low value here results in wobbly range (0.001)
240 // A high value here results in slow changing range (0.0025)
241 // SUGG: This could be dynamically adjusted so that when
242 // the camera is turning, this is lower
243 //float min_time_per_range = 0.0015;
244 float min_time_per_range = 0.0010;
245 //float min_time_per_range = 0.05 / range;
246 if(time_per_range < min_time_per_range)
248 time_per_range = min_time_per_range;
249 //dstream<<"time_per_range="<<time_per_range<<" (min)"<<std::endl;
253 //dstream<<"time_per_range="<<time_per_range<<std::endl;
256 f32 wanted_range_change = wanted_frametime_change / time_per_range;
257 // Dampen the change a bit to kill oscillations
258 //wanted_range_change *= 0.9;
259 //wanted_range_change *= 0.75;
260 wanted_range_change *= 0.5;
261 //dstream<<"wanted_range_change="<<wanted_range_change<<std::endl;
263 // If needed range change is very small, just return
264 if(fabs(wanted_range_change) < 0.001)
266 //dstream<<"ignoring small wanted_range_change"<<std::endl;
270 new_range += wanted_range_change;
272 float new_range_unclamped = new_range;
273 if(new_range < range_min)
274 new_range = range_min;
275 if(new_range > range_max)
276 new_range = range_max;
278 dstream<<"new_range="<<new_range_unclamped
279 <<", clamped to "<<new_range<<std::endl;
281 draw_control.wanted_range = new_range;
283 range_old = new_range;
284 frametime_old = frametime;
290 void draw_hotbar(video::IVideoDriver *driver, gui::IGUIFont *font,
291 v2s32 centerlowerpos, s32 imgsize, s32 itemcount,
292 Inventory *inventory, s32 halfheartcount)
294 InventoryList *mainlist = inventory->getList("main");
297 dstream<<"WARNING: draw_hotbar(): mainlist == NULL"<<std::endl;
301 s32 padding = imgsize/12;
302 //s32 height = imgsize + padding*2;
303 s32 width = itemcount*(imgsize+padding*2);
305 // Position of upper left corner of bar
306 v2s32 pos = centerlowerpos - v2s32(width/2, imgsize+padding*2);
308 // Draw background color
309 /*core::rect<s32> barrect(0,0,width,height);
311 video::SColor bgcolor(255,128,128,128);
312 driver->draw2DRectangle(bgcolor, barrect, NULL);*/
314 core::rect<s32> imgrect(0,0,imgsize,imgsize);
316 for(s32 i=0; i<itemcount; i++)
318 InventoryItem *item = mainlist->getItem(i);
320 core::rect<s32> rect = imgrect + pos
321 + v2s32(padding+i*(imgsize+padding*2), padding);
323 if(g_selected_item == i)
325 driver->draw2DRectangle(video::SColor(255,255,0,0),
326 core::rect<s32>(rect.UpperLeftCorner - v2s32(1,1)*padding,
327 rect.LowerRightCorner + v2s32(1,1)*padding),
332 video::SColor bgcolor2(128,0,0,0);
333 driver->draw2DRectangle(bgcolor2, rect, NULL);
338 drawInventoryItem(driver, font, item, rect, NULL);
346 video::ITexture *heart_texture =
347 driver->getTexture(porting::getDataPath("heart.png").c_str());
348 v2s32 p = pos + v2s32(0, -20);
349 for(s32 i=0; i<halfheartcount/2; i++)
351 const video::SColor color(255,255,255,255);
352 const video::SColor colors[] = {color,color,color,color};
353 core::rect<s32> rect(0,0,16,16);
355 driver->draw2DImage(heart_texture, rect,
356 core::rect<s32>(core::position2d<s32>(0,0),
357 core::dimension2di(heart_texture->getOriginalSize())),
361 if(halfheartcount % 2 == 1)
363 const video::SColor color(255,255,255,255);
364 const video::SColor colors[] = {color,color,color,color};
365 core::rect<s32> rect(0,0,16/2,16);
367 core::dimension2di srcd(heart_texture->getOriginalSize());
369 driver->draw2DImage(heart_texture, rect,
370 core::rect<s32>(core::position2d<s32>(0,0), srcd),
378 Find what the player is pointing at
380 void getPointedNode(Client *client, v3f player_position,
381 v3f camera_direction, v3f camera_position,
382 bool &nodefound, core::line3d<f32> shootline,
383 v3s16 &nodepos, v3s16 &neighbourpos,
384 core::aabbox3d<f32> &nodehilightbox,
387 f32 mindistance = BS * 1001;
389 v3s16 pos_i = floatToInt(player_position, BS);
391 /*std::cout<<"pos_i=("<<pos_i.X<<","<<pos_i.Y<<","<<pos_i.Z<<")"
395 s16 ystart = pos_i.Y + 0 - (camera_direction.Y<0 ? a : 1);
396 s16 zstart = pos_i.Z - (camera_direction.Z<0 ? a : 1);
397 s16 xstart = pos_i.X - (camera_direction.X<0 ? a : 1);
398 s16 yend = pos_i.Y + 1 + (camera_direction.Y>0 ? a : 1);
399 s16 zend = pos_i.Z + (camera_direction.Z>0 ? a : 1);
400 s16 xend = pos_i.X + (camera_direction.X>0 ? a : 1);
402 for(s16 y = ystart; y <= yend; y++)
403 for(s16 z = zstart; z <= zend; z++)
404 for(s16 x = xstart; x <= xend; x++)
409 n = client->getNode(v3s16(x,y,z));
410 if(content_pointable(n.d) == false)
413 catch(InvalidPositionException &e)
419 v3f npf = intToFloat(np, BS);
424 v3s16(0,0,1), // back
426 v3s16(1,0,0), // right
427 v3s16(0,0,-1), // front
428 v3s16(0,-1,0), // bottom
429 v3s16(-1,0,0), // left
435 if(n.d == CONTENT_TORCH)
437 v3s16 dir = unpackDir(n.dir);
438 v3f dir_f = v3f(dir.X, dir.Y, dir.Z);
439 dir_f *= BS/2 - BS/6 - BS/20;
440 v3f cpf = npf + dir_f;
441 f32 distance = (cpf - camera_position).getLength();
443 core::aabbox3d<f32> box;
446 if(dir == v3s16(0,-1,0))
448 box = core::aabbox3d<f32>(
449 npf - v3f(BS/6, BS/2, BS/6),
450 npf + v3f(BS/6, -BS/2+BS/3*2, BS/6)
454 else if(dir == v3s16(0,1,0))
456 box = core::aabbox3d<f32>(
457 npf - v3f(BS/6, -BS/2+BS/3*2, BS/6),
458 npf + v3f(BS/6, BS/2, BS/6)
464 box = core::aabbox3d<f32>(
465 cpf - v3f(BS/6, BS/3, BS/6),
466 cpf + v3f(BS/6, BS/3, BS/6)
470 if(distance < mindistance)
472 if(box.intersectsWithLine(shootline))
477 mindistance = distance;
478 nodehilightbox = box;
482 else if(n.d == CONTENT_SIGN_WALL)
484 v3s16 dir = unpackDir(n.dir);
485 v3f dir_f = v3f(dir.X, dir.Y, dir.Z);
486 dir_f *= BS/2 - BS/6 - BS/20;
487 v3f cpf = npf + dir_f;
488 f32 distance = (cpf - camera_position).getLength();
492 v3f(BS*0.42,-BS*0.35,-BS*0.4),
493 v3f(BS*0.49, BS*0.35, BS*0.4),
496 for(s32 i=0; i<2; i++)
498 if(dir == v3s16(1,0,0))
499 vertices[i].rotateXZBy(0);
500 if(dir == v3s16(-1,0,0))
501 vertices[i].rotateXZBy(180);
502 if(dir == v3s16(0,0,1))
503 vertices[i].rotateXZBy(90);
504 if(dir == v3s16(0,0,-1))
505 vertices[i].rotateXZBy(-90);
506 if(dir == v3s16(0,-1,0))
507 vertices[i].rotateXYBy(-90);
508 if(dir == v3s16(0,1,0))
509 vertices[i].rotateXYBy(90);
514 core::aabbox3d<f32> box;
516 box = core::aabbox3d<f32>(vertices[0]);
517 box.addInternalPoint(vertices[1]);
519 if(distance < mindistance)
521 if(box.intersectsWithLine(shootline))
526 mindistance = distance;
527 nodehilightbox = box;
536 for(u16 i=0; i<6; i++)
538 v3f dir_f = v3f(dirs[i].X,
539 dirs[i].Y, dirs[i].Z);
540 v3f centerpoint = npf + dir_f * BS/2;
542 (centerpoint - camera_position).getLength();
544 if(distance < mindistance)
546 core::CMatrix4<f32> m;
547 m.buildRotateFromTo(v3f(0,0,1), dir_f);
549 // This is the back face
551 v3f(BS/2, BS/2, BS/2),
552 v3f(-BS/2, -BS/2, BS/2+d)
555 for(u16 j=0; j<2; j++)
557 m.rotateVect(corners[j]);
561 core::aabbox3d<f32> facebox(corners[0]);
562 facebox.addInternalPoint(corners[1]);
564 if(facebox.intersectsWithLine(shootline))
568 neighbourpos = np + dirs[i];
569 mindistance = distance;
571 //nodehilightbox = facebox;
573 const float d = 0.502;
574 core::aabbox3d<f32> nodebox
575 (-BS*d, -BS*d, -BS*d, BS*d, BS*d, BS*d);
576 v3f nodepos_f = intToFloat(nodepos, BS);
577 nodebox.MinEdge += nodepos_f;
578 nodebox.MaxEdge += nodepos_f;
579 nodehilightbox = nodebox;
581 } // if distance < mindistance
587 void update_skybox(video::IVideoDriver* driver,
588 scene::ISceneManager* smgr, scene::ISceneNode* &skybox,
596 if(brightness >= 0.5)
598 skybox = smgr->addSkyBoxSceneNode(
599 driver->getTexture(porting::getDataPath("skybox2.png").c_str()),
600 driver->getTexture(porting::getDataPath("skybox3.png").c_str()),
601 driver->getTexture(porting::getDataPath("skybox1.png").c_str()),
602 driver->getTexture(porting::getDataPath("skybox1.png").c_str()),
603 driver->getTexture(porting::getDataPath("skybox1.png").c_str()),
604 driver->getTexture(porting::getDataPath("skybox1.png").c_str()));
606 else if(brightness >= 0.2)
608 skybox = smgr->addSkyBoxSceneNode(
609 driver->getTexture(porting::getDataPath("skybox2_dawn.png").c_str()),
610 driver->getTexture(porting::getDataPath("skybox3_dawn.png").c_str()),
611 driver->getTexture(porting::getDataPath("skybox1_dawn.png").c_str()),
612 driver->getTexture(porting::getDataPath("skybox1_dawn.png").c_str()),
613 driver->getTexture(porting::getDataPath("skybox1_dawn.png").c_str()),
614 driver->getTexture(porting::getDataPath("skybox1_dawn.png").c_str()));
618 skybox = smgr->addSkyBoxSceneNode(
619 driver->getTexture(porting::getDataPath("skybox2_night.png").c_str()),
620 driver->getTexture(porting::getDataPath("skybox3_night.png").c_str()),
621 driver->getTexture(porting::getDataPath("skybox1_night.png").c_str()),
622 driver->getTexture(porting::getDataPath("skybox1_night.png").c_str()),
623 driver->getTexture(porting::getDataPath("skybox1_night.png").c_str()),
624 driver->getTexture(porting::getDataPath("skybox1_night.png").c_str()));
632 IrrlichtDevice *device,
635 std::string playername,
638 std::wstring &error_message
641 video::IVideoDriver* driver = device->getVideoDriver();
642 scene::ISceneManager* smgr = device->getSceneManager();
644 v2u32 screensize(0,0);
645 v2u32 last_screensize(0,0);
646 screensize = driver->getScreenSize();
648 const s32 hotbar_itemcount = 8;
649 const s32 hotbar_imagesize = 36;
651 // The color of the sky
653 //video::SColor skycolor = video::SColor(255,140,186,250);
655 video::SColor bgcolor_bright = video::SColor(255,170,200,230);
658 Draw "Loading" screen
660 const wchar_t *loadingtext = L"Loading and connecting...";
661 u32 text_height = font->getDimension(loadingtext).Height;
662 core::vector2d<s32> center(screensize.X/2, screensize.Y/2);
663 core::vector2d<s32> textsize(300, text_height);
664 core::rect<s32> textrect(center - textsize/2, center + textsize/2);
666 gui::IGUIStaticText *gui_loadingtext = guienv->addStaticText(
667 loadingtext, textrect, false, false);
668 gui_loadingtext->setTextAlignment(gui::EGUIA_CENTER, gui::EGUIA_UPPERLEFT);
670 driver->beginScene(true, true, video::SColor(255,0,0,0));
674 std::cout<<DTIME<<"Creating server and client"<<std::endl;
678 SharedPtr will delete it when it goes out of scope.
680 SharedPtr<Server> server;
682 server = new Server(map_dir);
690 Client client(device, playername.c_str(), draw_control);
692 Address connect_address(0,0,0,0, port);
695 //connect_address.Resolve("localhost");
696 connect_address.setAddress(127,0,0,1);
698 connect_address.Resolve(address.c_str());
700 catch(ResolveError &e)
702 std::cout<<DTIME<<"Couldn't resolve address"<<std::endl;
704 error_message = L"Couldn't resolve address";
705 gui_loadingtext->remove();
710 Attempt to connect to the server
713 dstream<<DTIME<<"Connecting to server at ";
714 connect_address.print(&dstream);
716 client.connect(connect_address);
718 bool could_connect = false;
721 float time_counter = 0.0;
724 if(client.connectedAndInitialized())
726 could_connect = true;
729 // Wait for 10 seconds
730 if(time_counter >= 10.0)
736 driver->beginScene(true, true, video::SColor(255,0,0,0));
740 // Update client and server
752 catch(con::PeerNotFoundException &e)
755 if(could_connect == false)
757 std::cout<<DTIME<<"Timed out."<<std::endl;
758 error_message = L"Connection timed out.";
759 gui_loadingtext->remove();
766 float old_brightness = 1.0;
767 scene::ISceneNode* skybox = NULL;
768 update_skybox(driver, smgr, skybox, 1.0);
771 Create the camera node
774 scene::ICameraSceneNode* camera = smgr->addCameraSceneNode(
776 v3f(BS*100, BS*2, BS*100), // Look from
777 v3f(BS*100+1, BS*2, BS*100), // Look to
783 error_message = L"Failed to create the camera node";
787 camera->setFOV(FOV_ANGLE);
789 // Just so big a value that everything rendered is visible
790 camera->setFarValue(100000*BS);
792 f32 camera_yaw = 0; // "right/left"
793 f32 camera_pitch = 0; // "up/down"
799 float cloud_height = BS*100;
800 Clouds *clouds = NULL;
801 clouds = new Clouds(smgr->getRootSceneNode(), smgr, -1,
802 cloud_height, time(0));
808 gui_loadingtext->remove();
814 // First line of debug text
815 gui::IGUIStaticText *guitext = guienv->addStaticText(
817 core::rect<s32>(5, 5, 795, 5+text_height),
819 // Second line of debug text
820 gui::IGUIStaticText *guitext2 = guienv->addStaticText(
822 core::rect<s32>(5, 5+(text_height+5)*1, 795, (5+text_height)*2),
825 // At the middle of the screen
826 // Object infos are shown in this
827 gui::IGUIStaticText *guitext_info = guienv->addStaticText(
829 core::rect<s32>(0,0,400,text_height+5) + v2s32(100,200),
833 gui::IGUIStaticText *guitext_chat = guienv->addStaticText(
835 core::rect<s32>(0,0,0,0),
836 false, false); // Disable word wrap as of now
838 //guitext_chat->setBackgroundColor(video::SColor(96,0,0,0));
839 core::list<ChatLine> chat_lines;
841 /*GUIQuickInventory *quick_inventory = new GUIQuickInventory
842 (guienv, NULL, v2s32(10, 70), 5, &local_inventory);*/
843 /*GUIQuickInventory *quick_inventory = new GUIQuickInventory
844 (guienv, NULL, v2s32(0, 0), quickinv_itemcount, &local_inventory);*/
846 // Test the text input system
847 /*(new GUITextInputMenu(guienv, guiroot, -1, &g_menumgr,
849 /*GUIMessageMenu *menu =
850 new GUIMessageMenu(guienv, guiroot, -1,
856 (new GUIPauseMenu(guienv, guiroot, -1, g_gamecallback,
857 &g_menumgr))->drop();
860 /*guitext2->setVisible(true);
861 guitext_info->setVisible(true);
862 guitext_chat->setVisible(true);*/
864 //s32 guitext_chat_pad_bottom = 70;
867 Some statistics are collected in these
870 u32 beginscenetime = 0;
872 u32 endscenetime = 0;
875 //throw con::PeerNotFoundException("lol");
877 core::list<float> frametime_log;
879 float damage_flash_timer = 0;
885 bool first_loop_after_window_activation = true;
887 // Time is in milliseconds
888 // NOTE: getRealTime() causes strange problems in wine (imprecision?)
889 // NOTE: So we have to use getTime() and call run()s between them
890 u32 lasttime = device->getTimer()->getTime();
892 while(device->run() && kill == false)
894 if(g_gamecallback->disconnect_requested)
896 g_gamecallback->disconnect_requested = false;
901 Process TextureSource's queue
903 ((TextureSource*)g_texturesource)->processQueue();
908 last_screensize = screensize;
909 screensize = driver->getScreenSize();
910 v2s32 displaycenter(screensize.X/2,screensize.Y/2);
911 //bool screensize_changed = screensize != last_screensize;
913 // Hilight boxes collected during the loop and displayed
914 core::list< core::aabbox3d<f32> > hilightboxes;
917 std::wstring infotext;
919 // When screen size changes, update positions and sizes of stuff
920 /*if(screensize_changed)
922 v2s32 pos(displaycenter.X-((quickinv_itemcount-1)*quickinv_spacing+quickinv_size)/2, screensize.Y-quickinv_spacing);
923 quick_inventory->updatePosition(pos);
926 //TimeTaker //timer1("//timer1");
928 // Time of frame without fps limit
932 // not using getRealTime is necessary for wine
933 u32 time = device->getTimer()->getTime();
935 busytime_u32 = time - lasttime;
938 busytime = busytime_u32 / 1000.0;
941 //std::cout<<"busytime_u32="<<busytime_u32<<std::endl;
943 // Necessary for device->getTimer()->getTime()
950 updateViewingRange(busytime, &client);
957 float fps_max = g_settings.getFloat("fps_max");
958 u32 frametime_min = 1000./fps_max;
960 if(busytime_u32 < frametime_min)
962 u32 sleeptime = frametime_min - busytime_u32;
963 device->sleep(sleeptime);
967 // Necessary for device->getTimer()->getTime()
971 Time difference calculation
973 f32 dtime; // in seconds
975 u32 time = device->getTimer()->getTime();
977 dtime = (time - lasttime) / 1000.0;
983 Log frametime for visualization
985 frametime_log.push_back(dtime);
986 if(frametime_log.size() > 100)
988 core::list<float>::Iterator i = frametime_log.begin();
989 frametime_log.erase(i);
993 Visualize frametime in terminal
995 /*for(u32 i=0; i<dtime*400; i++)
997 std::cout<<std::endl;*/
1000 Time average and jitter calculation
1003 static f32 dtime_avg1 = 0.0;
1004 dtime_avg1 = dtime_avg1 * 0.98 + dtime * 0.02;
1005 f32 dtime_jitter1 = dtime - dtime_avg1;
1007 static f32 dtime_jitter1_max_sample = 0.0;
1008 static f32 dtime_jitter1_max_fraction = 0.0;
1010 static f32 jitter1_max = 0.0;
1011 static f32 counter = 0.0;
1012 if(dtime_jitter1 > jitter1_max)
1013 jitter1_max = dtime_jitter1;
1018 dtime_jitter1_max_sample = jitter1_max;
1019 dtime_jitter1_max_fraction
1020 = dtime_jitter1_max_sample / (dtime_avg1+0.001);
1026 Busytime average and jitter calculation
1029 static f32 busytime_avg1 = 0.0;
1030 busytime_avg1 = busytime_avg1 * 0.98 + busytime * 0.02;
1031 f32 busytime_jitter1 = busytime - busytime_avg1;
1033 static f32 busytime_jitter1_max_sample = 0.0;
1034 static f32 busytime_jitter1_min_sample = 0.0;
1036 static f32 jitter1_max = 0.0;
1037 static f32 jitter1_min = 0.0;
1038 static f32 counter = 0.0;
1039 if(busytime_jitter1 > jitter1_max)
1040 jitter1_max = busytime_jitter1;
1041 if(busytime_jitter1 < jitter1_min)
1042 jitter1_min = busytime_jitter1;
1046 busytime_jitter1_max_sample = jitter1_max;
1047 busytime_jitter1_min_sample = jitter1_min;
1054 Debug info for client
1057 static float counter = 0.0;
1062 client.printDebugInfo(std::cout);
1067 Direct handling of user input
1070 // Reset input if window not active or some menu is active
1071 if(device->isWindowActive() == false || noMenuActive() == false)
1076 // Input handler step() (used by the random input generator)
1080 Launch menus according to keys
1082 if(input->wasKeyDown(irr::KEY_KEY_I))
1084 dstream<<DTIME<<"the_game: "
1085 <<"Launching inventory"<<std::endl;
1087 GUIInventoryMenu *menu =
1088 new GUIInventoryMenu(guienv, guiroot, -1,
1089 &g_menumgr, v2s16(8,7),
1090 client.getInventoryContext(),
1093 core::array<GUIInventoryMenu::DrawSpec> draw_spec;
1094 draw_spec.push_back(GUIInventoryMenu::DrawSpec(
1095 "list", "current_player", "main",
1096 v2s32(0, 3), v2s32(8, 4)));
1097 draw_spec.push_back(GUIInventoryMenu::DrawSpec(
1098 "list", "current_player", "craft",
1099 v2s32(3, 0), v2s32(3, 3)));
1100 draw_spec.push_back(GUIInventoryMenu::DrawSpec(
1101 "list", "current_player", "craftresult",
1102 v2s32(7, 1), v2s32(1, 1)));
1104 menu->setDrawSpec(draw_spec);
1108 else if(input->wasKeyDown(irr::KEY_ESCAPE))
1110 dstream<<DTIME<<"the_game: "
1111 <<"Launching pause menu"<<std::endl;
1112 // It will delete itself by itself
1113 (new GUIPauseMenu(guienv, guiroot, -1, g_gamecallback,
1114 &g_menumgr))->drop();
1116 else if(input->wasKeyDown(irr::KEY_KEY_T))
1118 TextDest *dest = new TextDestChat(&client);
1120 (new GUITextInputMenu(guienv, guiroot, -1,
1125 // Item selection with mouse wheel
1127 s32 wheel = input->getMouseWheel();
1128 u16 max_item = MYMIN(PLAYER_INVENTORY_SIZE-1,
1129 hotbar_itemcount-1);
1133 if(g_selected_item < max_item)
1136 g_selected_item = 0;
1140 if(g_selected_item > 0)
1143 g_selected_item = max_item;
1148 for(u16 i=0; i<10; i++)
1150 s32 keycode = irr::KEY_KEY_1 + i;
1152 keycode = irr::KEY_KEY_0;
1153 if(input->wasKeyDown((irr::EKEY_CODE)keycode))
1155 if(i < PLAYER_INVENTORY_SIZE && i < hotbar_itemcount)
1157 g_selected_item = i;
1159 dstream<<DTIME<<"Selected item: "
1160 <<g_selected_item<<std::endl;
1165 // Viewing range selection
1166 if(input->wasKeyDown(irr::KEY_KEY_R))
1168 if(draw_control.range_all)
1170 draw_control.range_all = false;
1171 dstream<<DTIME<<"Disabled full viewing range"<<std::endl;
1175 draw_control.range_all = true;
1176 dstream<<DTIME<<"Enabled full viewing range"<<std::endl;
1180 // Print debug stacks
1181 if(input->wasKeyDown(irr::KEY_KEY_P))
1183 dstream<<"-----------------------------------------"
1185 dstream<<DTIME<<"Printing debug stacks:"<<std::endl;
1186 dstream<<"-----------------------------------------"
1188 debug_stacks_print();
1192 Player speed control
1205 PlayerControl control(
1206 input->isKeyDown(irr::KEY_KEY_W),
1207 input->isKeyDown(irr::KEY_KEY_S),
1208 input->isKeyDown(irr::KEY_KEY_A),
1209 input->isKeyDown(irr::KEY_KEY_D),
1210 input->isKeyDown(irr::KEY_SPACE),
1211 input->isKeyDown(irr::KEY_KEY_E),
1212 input->isKeyDown(irr::KEY_LSHIFT)
1213 || input->isKeyDown(irr::KEY_RSHIFT),
1217 client.setPlayerControl(control);
1226 //TimeTaker timer("server->step(dtime)");
1227 server->step(dtime);
1235 //TimeTaker timer("client.step(dtime)");
1237 //client.step(dtime_avg1);
1240 // Read client events
1243 ClientEvent event = client.getClientEvent();
1244 if(event.type == CE_NONE)
1248 else if(event.type == CE_PLAYER_DAMAGE)
1250 //u16 damage = event.player_damage.amount;
1251 //dstream<<"Player damage: "<<damage<<std::endl;
1252 damage_flash_timer = 0.05;
1254 else if(event.type == CE_PLAYER_FORCE_MOVE)
1256 camera_yaw = event.player_force_move.yaw;
1257 camera_pitch = event.player_force_move.pitch;
1261 // Get player position
1262 v3f player_position = client.getPlayerPosition();
1264 //TimeTaker //timer2("//timer2");
1267 Mouse and camera control
1270 if((device->isWindowActive() && noMenuActive()) || random_input)
1273 device->getCursorControl()->setVisible(false);
1275 if(first_loop_after_window_activation){
1276 //std::cout<<"window active, first loop"<<std::endl;
1277 first_loop_after_window_activation = false;
1280 s32 dx = input->getMousePos().X - displaycenter.X;
1281 s32 dy = input->getMousePos().Y - displaycenter.Y;
1282 //std::cout<<"window active, pos difference "<<dx<<","<<dy<<std::endl;
1284 const float keyspeed = 500;
1285 if(input->isKeyDown(irr::KEY_UP))
1286 dy -= dtime * keyspeed;
1287 if(input->isKeyDown(irr::KEY_DOWN))
1288 dy += dtime * keyspeed;
1289 if(input->isKeyDown(irr::KEY_LEFT))
1290 dx -= dtime * keyspeed;
1291 if(input->isKeyDown(irr::KEY_RIGHT))
1292 dx += dtime * keyspeed;
1294 camera_yaw -= dx*0.2;
1295 camera_pitch += dy*0.2;
1296 if(camera_pitch < -89.5) camera_pitch = -89.5;
1297 if(camera_pitch > 89.5) camera_pitch = 89.5;
1299 input->setMousePos(displaycenter.X, displaycenter.Y);
1302 device->getCursorControl()->setVisible(true);
1304 //std::cout<<"window inactive"<<std::endl;
1305 first_loop_after_window_activation = true;
1308 camera_yaw = wrapDegrees(camera_yaw);
1309 camera_pitch = wrapDegrees(camera_pitch);
1311 v3f camera_direction = v3f(0,0,1);
1312 camera_direction.rotateYZBy(camera_pitch);
1313 camera_direction.rotateXZBy(camera_yaw);
1315 // This is at the height of the eyes of the current figure
1316 //v3f camera_position = player_position + v3f(0, BS+BS/2, 0);
1317 // This is more like in minecraft
1318 v3f camera_position = player_position + v3f(0, BS+BS*0.625, 0);
1320 camera->setPosition(camera_position);
1321 // *100.0 helps in large map coordinates
1322 camera->setTarget(camera_position + camera_direction * 100.0);
1324 if(FIELD_OF_VIEW_TEST){
1325 client.updateCamera(v3f(0,0,0), v3f(0,0,1));
1328 //TimeTaker timer("client.updateCamera");
1329 client.updateCamera(camera_position, camera_direction);
1333 //TimeTaker //timer3("//timer3");
1336 Calculate what block is the crosshair pointing to
1339 //u32 t1 = device->getTimer()->getRealTime();
1341 //f32 d = 4; // max. distance
1342 f32 d = 4; // max. distance
1343 core::line3d<f32> shootline(camera_position,
1344 camera_position + camera_direction * BS * (d+1));
1346 MapBlockObject *selected_object = client.getSelectedObject
1347 (d*BS, camera_position, shootline);
1349 ClientActiveObject *selected_active_object
1350 = client.getSelectedActiveObject
1351 (d*BS, camera_position, shootline);
1353 if(selected_object != NULL)
1355 //dstream<<"Client returned selected_object != NULL"<<std::endl;
1357 core::aabbox3d<f32> box_on_map
1358 = selected_object->getSelectionBoxOnMap();
1360 hilightboxes.push_back(box_on_map);
1362 infotext = narrow_to_wide(selected_object->infoText());
1364 if(input->getLeftClicked())
1366 std::cout<<DTIME<<"Left-clicked object"<<std::endl;
1367 client.clickObject(0, selected_object->getBlock()->getPos(),
1368 selected_object->getId(), g_selected_item);
1370 else if(input->getRightClicked())
1372 std::cout<<DTIME<<"Right-clicked object"<<std::endl;
1374 Check if we want to modify the object ourselves
1376 if(selected_object->getTypeId() == MAPBLOCKOBJECT_TYPE_SIGN)
1378 dstream<<"Sign object right-clicked"<<std::endl;
1380 if(random_input == false)
1382 // Get a new text for it
1384 TextDest *dest = new TextDestSign(
1385 selected_object->getBlock()->getPos(),
1386 selected_object->getId(),
1389 SignObject *sign_object = (SignObject*)selected_object;
1391 std::wstring wtext =
1392 narrow_to_wide(sign_object->getText());
1394 (new GUITextInputMenu(guienv, guiroot, -1,
1400 Otherwise pass the event to the server as-is
1404 client.clickObject(1, selected_object->getBlock()->getPos(),
1405 selected_object->getId(), g_selected_item);
1409 else if(selected_active_object != NULL)
1411 //dstream<<"Client returned selected_active_object != NULL"<<std::endl;
1413 core::aabbox3d<f32> *selection_box
1414 = selected_active_object->getSelectionBox();
1415 // Box should exist because object was returned in the
1417 assert(selection_box);
1419 v3f pos = selected_active_object->getPosition();
1421 core::aabbox3d<f32> box_on_map(
1422 selection_box->MinEdge + pos,
1423 selection_box->MaxEdge + pos
1426 hilightboxes.push_back(box_on_map);
1428 //infotext = narrow_to_wide("A ClientActiveObject");
1429 infotext = narrow_to_wide(selected_active_object->infoText());
1431 if(input->getLeftClicked())
1433 std::cout<<DTIME<<"Left-clicked object"<<std::endl;
1434 client.clickActiveObject(0,
1435 selected_active_object->getId(), g_selected_item);
1437 else if(input->getRightClicked())
1439 std::cout<<DTIME<<"Right-clicked object"<<std::endl;
1442 else // selected_object == NULL
1446 Find out which node we are pointing at
1449 bool nodefound = false;
1452 core::aabbox3d<f32> nodehilightbox;
1454 getPointedNode(&client, player_position,
1455 camera_direction, camera_position,
1456 nodefound, shootline,
1457 nodepos, neighbourpos,
1460 static float nodig_delay_counter = 0.0;
1464 static v3s16 nodepos_old(-32768,-32768,-32768);
1466 static float dig_time = 0.0;
1467 static u16 dig_index = 0;
1473 hilightboxes.push_back(nodehilightbox);
1476 Check information text of node
1479 NodeMetadata *meta = client.getNodeMetadata(nodepos);
1482 infotext = narrow_to_wide(meta->infoText());
1485 //MapNode node = client.getNode(nodepos);
1491 if(input->getLeftReleased())
1493 client.clearTempMod(nodepos);
1497 if(nodig_delay_counter > 0.0)
1499 nodig_delay_counter -= dtime;
1503 if(nodepos != nodepos_old)
1505 std::cout<<DTIME<<"Pointing at ("<<nodepos.X<<","
1506 <<nodepos.Y<<","<<nodepos.Z<<")"<<std::endl;
1508 if(nodepos_old != v3s16(-32768,-32768,-32768))
1510 client.clearTempMod(nodepos_old);
1515 if(input->getLeftClicked() ||
1516 (input->getLeftState() && nodepos != nodepos_old))
1518 dstream<<DTIME<<"Started digging"<<std::endl;
1519 client.groundAction(0, nodepos, neighbourpos, g_selected_item);
1521 if(input->getLeftClicked())
1523 client.setTempMod(nodepos, NodeMod(NODEMOD_CRACK, 0));
1525 if(input->getLeftState())
1527 MapNode n = client.getNode(nodepos);
1529 // Get tool name. Default is "" = bare hands
1530 std::string toolname = "";
1531 InventoryList *mlist = local_inventory.getList("main");
1534 InventoryItem *item = mlist->getItem(g_selected_item);
1535 if(item && (std::string)item->getName() == "ToolItem")
1537 ToolItem *titem = (ToolItem*)item;
1538 toolname = titem->getToolName();
1542 // Get digging properties for material and tool
1544 DiggingProperties prop =
1545 getDiggingProperties(material, toolname);
1547 float dig_time_complete = 0.0;
1549 if(prop.diggable == false)
1551 /*dstream<<"Material "<<(int)material
1552 <<" not diggable with \""
1553 <<toolname<<"\""<<std::endl;*/
1554 // I guess nobody will wait for this long
1555 dig_time_complete = 10000000.0;
1559 dig_time_complete = prop.time;
1562 if(dig_time_complete >= 0.001)
1564 dig_index = (u16)((float)CRACK_ANIMATION_LENGTH
1565 * dig_time/dig_time_complete);
1567 // This is for torches
1570 dig_index = CRACK_ANIMATION_LENGTH;
1573 if(dig_index < CRACK_ANIMATION_LENGTH)
1575 //TimeTaker timer("client.setTempMod");
1576 //dstream<<"dig_index="<<dig_index<<std::endl;
1577 client.setTempMod(nodepos, NodeMod(NODEMOD_CRACK, dig_index));
1581 dstream<<DTIME<<"Digging completed"<<std::endl;
1582 client.groundAction(3, nodepos, neighbourpos, g_selected_item);
1583 client.clearTempMod(nodepos);
1584 client.removeNode(nodepos);
1588 nodig_delay_counter = dig_time_complete
1589 / (float)CRACK_ANIMATION_LENGTH;
1591 // We don't want a corresponding delay to
1592 // very time consuming nodes
1593 if(nodig_delay_counter > 0.5)
1595 nodig_delay_counter = 0.5;
1597 // We want a slight delay to very little
1598 // time consuming nodes
1599 float mindelay = 0.15;
1600 if(nodig_delay_counter < mindelay)
1602 nodig_delay_counter = mindelay;
1610 if(input->getRightClicked())
1612 std::cout<<DTIME<<"Ground right-clicked"<<std::endl;
1614 if(meta && meta->typeId() == CONTENT_SIGN_WALL && !random_input)
1616 dstream<<"Sign node right-clicked"<<std::endl;
1618 SignNodeMetadata *signmeta = (SignNodeMetadata*)meta;
1620 // Get a new text for it
1622 TextDest *dest = new TextDestSignNode(nodepos, &client);
1624 std::wstring wtext =
1625 narrow_to_wide(signmeta->getText());
1627 (new GUITextInputMenu(guienv, guiroot, -1,
1631 else if(meta && meta->typeId() == CONTENT_CHEST && !random_input)
1633 dstream<<"Chest node right-clicked"<<std::endl;
1635 //ChestNodeMetadata *chestmeta = (ChestNodeMetadata*)meta;
1637 std::string chest_inv_id;
1638 chest_inv_id += "nodemeta:";
1639 chest_inv_id += itos(nodepos.X);
1640 chest_inv_id += ",";
1641 chest_inv_id += itos(nodepos.Y);
1642 chest_inv_id += ",";
1643 chest_inv_id += itos(nodepos.Z);
1645 GUIInventoryMenu *menu =
1646 new GUIInventoryMenu(guienv, guiroot, -1,
1647 &g_menumgr, v2s16(8,9),
1648 client.getInventoryContext(),
1651 core::array<GUIInventoryMenu::DrawSpec> draw_spec;
1653 draw_spec.push_back(GUIInventoryMenu::DrawSpec(
1654 "list", chest_inv_id, "0",
1655 v2s32(0, 0), v2s32(8, 4)));
1656 draw_spec.push_back(GUIInventoryMenu::DrawSpec(
1657 "list", "current_player", "main",
1658 v2s32(0, 5), v2s32(8, 4)));
1660 menu->setDrawSpec(draw_spec);
1665 else if(meta && meta->typeId() == CONTENT_FURNACE && !random_input)
1667 dstream<<"Furnace node right-clicked"<<std::endl;
1669 GUIFurnaceMenu *menu =
1670 new GUIFurnaceMenu(guienv, guiroot, -1,
1671 &g_menumgr, nodepos, &client);
1678 client.groundAction(1, nodepos, neighbourpos, g_selected_item);
1682 nodepos_old = nodepos;
1687 } // selected_object == NULL
1689 input->resetLeftClicked();
1690 input->resetRightClicked();
1692 if(input->getLeftReleased())
1694 std::cout<<DTIME<<"Left button released (stopped digging)"
1696 client.groundAction(2, v3s16(0,0,0), v3s16(0,0,0), 0);
1698 if(input->getRightReleased())
1700 //std::cout<<DTIME<<"Right released"<<std::endl;
1704 input->resetLeftReleased();
1705 input->resetRightReleased();
1708 Calculate stuff for drawing
1711 camera->setAspectRatio((f32)screensize.X / (f32)screensize.Y);
1713 u32 daynight_ratio = client.getDayNightRatio();
1714 u8 l = decode_light((daynight_ratio * LIGHT_SUN) / 1000);
1715 video::SColor bgcolor = video::SColor(
1717 bgcolor_bright.getRed() * l / 255,
1718 bgcolor_bright.getGreen() * l / 255,
1719 bgcolor_bright.getBlue() * l / 255);
1720 /*skycolor.getRed() * l / 255,
1721 skycolor.getGreen() * l / 255,
1722 skycolor.getBlue() * l / 255);*/
1724 float brightness = (float)l/255.0;
1729 if(fabs(brightness - old_brightness) > 0.01)
1730 update_skybox(driver, smgr, skybox, brightness);
1737 clouds->step(dtime);
1738 clouds->update(v2f(player_position.X, player_position.Z),
1739 0.05+brightness*0.95);
1742 // Store brightness value
1743 old_brightness = brightness;
1749 if(g_settings.getBool("enable_fog") == true)
1751 f32 range = draw_control.wanted_range*BS + MAP_BLOCKSIZE*BS*1.5;
1752 if(draw_control.range_all)
1755 range = range * 0.5 + 25*BS;
1759 video::EFT_FOG_LINEAR,
1771 video::EFT_FOG_LINEAR,
1782 Update gui stuff (0ms)
1785 //TimeTaker guiupdatetimer("Gui updating");
1788 static float drawtime_avg = 0;
1789 drawtime_avg = drawtime_avg * 0.95 + (float)drawtime*0.05;
1790 static float beginscenetime_avg = 0;
1791 beginscenetime_avg = beginscenetime_avg * 0.95 + (float)beginscenetime*0.05;
1792 static float scenetime_avg = 0;
1793 scenetime_avg = scenetime_avg * 0.95 + (float)scenetime*0.05;
1794 static float endscenetime_avg = 0;
1795 endscenetime_avg = endscenetime_avg * 0.95 + (float)endscenetime*0.05;
1798 snprintf(temptext, 300, "Minetest-c55 %s ("
1801 " drawtime=%.0f, beginscenetime=%.0f"
1802 ", scenetime=%.0f, endscenetime=%.0f",
1804 draw_control.range_all,
1811 guitext->setText(narrow_to_wide(temptext).c_str());
1816 snprintf(temptext, 300,
1817 "(% .1f, % .1f, % .1f)"
1818 " (% .3f < btime_jitter < % .3f"
1819 ", dtime_jitter = % .1f %%"
1820 ", v_range = %.1f)",
1821 player_position.X/BS,
1822 player_position.Y/BS,
1823 player_position.Z/BS,
1824 busytime_jitter1_min_sample,
1825 busytime_jitter1_max_sample,
1826 dtime_jitter1_max_fraction * 100.0,
1827 draw_control.wanted_range
1830 guitext2->setText(narrow_to_wide(temptext).c_str());
1834 guitext_info->setText(infotext.c_str());
1838 Get chat messages from client
1842 std::wstring message;
1843 while(client.getChatMessage(message))
1845 chat_lines.push_back(ChatLine(message));
1846 /*if(chat_lines.size() > 6)
1848 core::list<ChatLine>::Iterator
1849 i = chat_lines.begin();
1850 chat_lines.erase(i);
1853 // Append them to form the whole static text and throw
1854 // it to the gui element
1856 // This will correspond to the line number counted from
1857 // top to bottom, from size-1 to 0
1858 s16 line_number = chat_lines.size();
1859 // Count of messages to be removed from the top
1860 u16 to_be_removed_count = 0;
1861 for(core::list<ChatLine>::Iterator
1862 i = chat_lines.begin();
1863 i != chat_lines.end(); i++)
1865 // After this, line number is valid for this loop
1870 This results in a maximum age of 60*6 to the
1871 lowermost line and a maximum of 6 lines
1873 float allowed_age = (6-line_number) * 60.0;
1875 if((*i).age > allowed_age)
1877 to_be_removed_count++;
1880 whole += (*i).text + L'\n';
1882 for(u16 i=0; i<to_be_removed_count; i++)
1884 core::list<ChatLine>::Iterator
1885 it = chat_lines.begin();
1886 chat_lines.erase(it);
1888 guitext_chat->setText(whole.c_str());
1890 // Update gui element size and position
1892 /*core::rect<s32> rect(
1894 screensize.Y - guitext_chat_pad_bottom
1895 - text_height*chat_lines.size(),
1897 screensize.Y - guitext_chat_pad_bottom
1899 core::rect<s32> rect(
1903 50 + text_height*chat_lines.size()
1906 guitext_chat->setRelativePosition(rect);
1908 if(chat_lines.size() == 0)
1909 guitext_chat->setVisible(false);
1911 guitext_chat->setVisible(true);
1918 static u16 old_selected_item = 65535;
1919 if(client.getLocalInventoryUpdated()
1920 || g_selected_item != old_selected_item)
1922 old_selected_item = g_selected_item;
1923 //std::cout<<"Updating local inventory"<<std::endl;
1924 client.getLocalInventory(local_inventory);
1928 Send actions returned by the inventory menu
1930 while(inventory_action_queue.size() != 0)
1932 InventoryAction *a = inventory_action_queue.pop_front();
1934 client.sendInventoryAction(a);
1943 TimeTaker drawtimer("Drawing");
1947 TimeTaker timer("beginScene");
1948 driver->beginScene(true, true, bgcolor);
1949 //driver->beginScene(false, true, bgcolor);
1950 beginscenetime = timer.stop(true);
1955 //std::cout<<DTIME<<"smgr->drawAll()"<<std::endl;
1958 TimeTaker timer("smgr");
1960 scenetime = timer.stop(true);
1964 //TimeTaker timer9("auxiliary drawings");
1968 //TimeTaker //timer10("//timer10");
1974 driver->setMaterial(m);
1976 driver->setTransform(video::ETS_WORLD, core::IdentityMatrix);
1978 for(core::list< core::aabbox3d<f32> >::Iterator i=hilightboxes.begin();
1979 i != hilightboxes.end(); i++)
1981 /*std::cout<<"hilightbox min="
1982 <<"("<<i->MinEdge.X<<","<<i->MinEdge.Y<<","<<i->MinEdge.Z<<")"
1984 <<"("<<i->MaxEdge.X<<","<<i->MaxEdge.Y<<","<<i->MaxEdge.Z<<")"
1986 driver->draw3DBox(*i, video::SColor(255,0,0,0));
1992 if(g_settings.getBool("frametime_graph") == true)
1995 for(core::list<float>::Iterator
1996 i = frametime_log.begin();
1997 i != frametime_log.end();
2000 driver->draw2DLine(v2s32(x,50),
2001 v2s32(x,50+(*i)*1000),
2002 video::SColor(255,255,255,255));
2010 driver->draw2DLine(displaycenter - core::vector2d<s32>(10,0),
2011 displaycenter + core::vector2d<s32>(10,0),
2012 video::SColor(255,255,255,255));
2013 driver->draw2DLine(displaycenter - core::vector2d<s32>(0,10),
2014 displaycenter + core::vector2d<s32>(0,10),
2015 video::SColor(255,255,255,255));
2020 //TimeTaker //timer11("//timer11");
2032 draw_hotbar(driver, font, v2s32(displaycenter.X, screensize.Y),
2033 hotbar_imagesize, hotbar_itemcount, &local_inventory,
2040 if(damage_flash_timer > 0.0)
2042 damage_flash_timer -= dtime;
2044 video::SColor color(128,255,0,0);
2045 driver->draw2DRectangle(color,
2046 core::rect<s32>(0,0,screensize.X,screensize.Y),
2054 TimeTaker timer("endScene");
2056 endscenetime = timer.stop(true);
2059 drawtime = drawtimer.stop(true);
2065 static s16 lastFPS = 0;
2066 //u16 fps = driver->getFPS();
2067 u16 fps = (1.0/dtime_avg1);
2071 core::stringw str = L"Minetest [";
2072 str += driver->getName();
2076 device->setWindowCaption(str.c_str());
2082 Draw a "shutting down" screen, which will be shown while the map
2083 generator and other stuff quits
2086 const wchar_t *shuttingdowntext = L"Shutting down stuff...";
2087 gui::IGUIStaticText *gui_shuttingdowntext = guienv->addStaticText(
2088 shuttingdowntext, textrect, false, false);
2089 gui_shuttingdowntext->setTextAlignment(gui::EGUIA_CENTER,
2090 gui::EGUIA_UPPERLEFT);
2091 driver->beginScene(true, true, video::SColor(255,0,0,0));
2094 gui_shuttingdowntext->remove();