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 "guiPasswordChange.h"
26 #include "guiInventoryMenu.h"
27 #include "guiTextInputMenu.h"
28 #include "guiFurnaceMenu.h"
29 #include "materials.h"
35 Setting this to 1 enables a special camera mode that forces
36 the renderers to think that the camera statically points from
37 the starting place to a static direction.
39 This allows one to move around with the player and see what
40 is actually drawn behind solid things and behind the player.
42 #define FIELD_OF_VIEW_TEST 0
45 MapDrawControl draw_control;
54 ChatLine(const std::wstring &a_text):
67 // Inventory actions from the menu are buffered here before sending
68 Queue<InventoryAction*> inventory_action_queue;
69 // This is a copy of the inventory that the client's environment has
70 Inventory local_inventory;
72 u16 g_selected_item = 0;
78 struct TextDestSign : public TextDest
80 TextDestSign(v3s16 blockpos, s16 id, Client *client)
82 m_blockpos = blockpos;
86 void gotText(std::wstring text)
88 std::string ntext = wide_to_narrow(text);
89 dstream<<"Changing text of a sign object: "
91 m_client->sendSignText(m_blockpos, m_id, ntext);
99 struct TextDestChat : public TextDest
101 TextDestChat(Client *client)
105 void gotText(std::wstring text)
107 // Discard empty line
111 // Parse command (server command starts with "/#")
112 if(text[0] == L'/' && text[1] != L'#')
114 std::wstring reply = L"Local: ";
116 reply += L"Local commands not yet supported. "
117 L"Server prefix is \"/#\".";
119 m_client->addChatMessage(reply);
124 m_client->sendChatMessage(text);
126 m_client->addChatMessage(text);
132 struct TextDestSignNode : public TextDest
134 TextDestSignNode(v3s16 p, Client *client)
139 void gotText(std::wstring text)
141 std::string ntext = wide_to_narrow(text);
142 dstream<<"Changing text of a sign node: "
144 m_client->sendSignNodeText(m_p, ntext);
152 Render distance feedback loop
154 void updateViewingRange(f32 frametime_in, Client *client)
156 if(draw_control.range_all == true)
159 static f32 added_frametime = 0;
160 static s16 added_frames = 0;
162 added_frametime += frametime_in;
165 // Actually this counter kind of sucks because frametime is busytime
166 static f32 counter = 0;
167 counter -= frametime_in;
173 /*dstream<<__FUNCTION_NAME
174 <<": Collected "<<added_frames<<" frames, total of "
175 <<added_frametime<<"s."<<std::endl;*/
177 /*dstream<<"draw_control.blocks_drawn="
178 <<draw_control.blocks_drawn
179 <<", draw_control.blocks_would_have_drawn="
180 <<draw_control.blocks_would_have_drawn
183 float range_min = g_settings.getS16("viewing_range_nodes_min");
184 float range_max = g_settings.getS16("viewing_range_nodes_max");
186 // Limit minimum to keep the feedback loop stable
190 draw_control.wanted_min_range = range_min;
191 //draw_control.wanted_max_blocks = (1.5*draw_control.blocks_drawn)+1;
192 draw_control.wanted_max_blocks = (1.5*draw_control.blocks_would_have_drawn)+1;
193 if(draw_control.wanted_max_blocks < 10)
194 draw_control.wanted_max_blocks = 10;
196 float block_draw_ratio = 1.0;
197 if(draw_control.blocks_would_have_drawn != 0)
199 block_draw_ratio = (float)draw_control.blocks_drawn
200 / (float)draw_control.blocks_would_have_drawn;
203 // Calculate the average frametime in the case that all wanted
204 // blocks had been drawn
205 f32 frametime = added_frametime / added_frames / block_draw_ratio;
207 added_frametime = 0.0;
210 float wanted_fps = g_settings.getFloat("wanted_fps");
211 float wanted_frametime = 1.0 / wanted_fps;
213 f32 wanted_frametime_change = wanted_frametime - frametime;
214 //dstream<<"wanted_frametime_change="<<wanted_frametime_change<<std::endl;
216 // If needed frametime change is small, just return
217 if(fabs(wanted_frametime_change) < wanted_frametime*0.4)
219 //dstream<<"ignoring small wanted_frametime_change"<<std::endl;
223 float range = draw_control.wanted_range;
224 float new_range = range;
226 static s16 range_old = 0;
227 static f32 frametime_old = 0;
229 float d_range = range - range_old;
230 f32 d_frametime = frametime - frametime_old;
231 // A sane default of 30ms per 50 nodes of range
232 static f32 time_per_range = 30. / 50;
235 time_per_range = d_frametime / d_range;
238 // The minimum allowed calculated frametime-range derivative:
239 // Practically this sets the maximum speed of changing the range.
240 // The lower this value, the higher the maximum changing speed.
241 // A low value here results in wobbly range (0.001)
242 // A high value here results in slow changing range (0.0025)
243 // SUGG: This could be dynamically adjusted so that when
244 // the camera is turning, this is lower
245 //float min_time_per_range = 0.0015;
246 float min_time_per_range = 0.0010;
247 //float min_time_per_range = 0.05 / range;
248 if(time_per_range < min_time_per_range)
250 time_per_range = min_time_per_range;
251 //dstream<<"time_per_range="<<time_per_range<<" (min)"<<std::endl;
255 //dstream<<"time_per_range="<<time_per_range<<std::endl;
258 f32 wanted_range_change = wanted_frametime_change / time_per_range;
259 // Dampen the change a bit to kill oscillations
260 //wanted_range_change *= 0.9;
261 //wanted_range_change *= 0.75;
262 wanted_range_change *= 0.5;
263 //dstream<<"wanted_range_change="<<wanted_range_change<<std::endl;
265 // If needed range change is very small, just return
266 if(fabs(wanted_range_change) < 0.001)
268 //dstream<<"ignoring small wanted_range_change"<<std::endl;
272 new_range += wanted_range_change;
274 //float new_range_unclamped = new_range;
275 if(new_range < range_min)
276 new_range = range_min;
277 if(new_range > range_max)
278 new_range = range_max;
280 /*dstream<<"new_range="<<new_range_unclamped
281 <<", clamped to "<<new_range<<std::endl;*/
283 draw_control.wanted_range = new_range;
285 range_old = new_range;
286 frametime_old = frametime;
292 void draw_hotbar(video::IVideoDriver *driver, gui::IGUIFont *font,
293 v2s32 centerlowerpos, s32 imgsize, s32 itemcount,
294 Inventory *inventory, s32 halfheartcount)
296 InventoryList *mainlist = inventory->getList("main");
299 dstream<<"WARNING: draw_hotbar(): mainlist == NULL"<<std::endl;
303 s32 padding = imgsize/12;
304 //s32 height = imgsize + padding*2;
305 s32 width = itemcount*(imgsize+padding*2);
307 // Position of upper left corner of bar
308 v2s32 pos = centerlowerpos - v2s32(width/2, imgsize+padding*2);
310 // Draw background color
311 /*core::rect<s32> barrect(0,0,width,height);
313 video::SColor bgcolor(255,128,128,128);
314 driver->draw2DRectangle(bgcolor, barrect, NULL);*/
316 core::rect<s32> imgrect(0,0,imgsize,imgsize);
318 for(s32 i=0; i<itemcount; i++)
320 InventoryItem *item = mainlist->getItem(i);
322 core::rect<s32> rect = imgrect + pos
323 + v2s32(padding+i*(imgsize+padding*2), padding);
325 if(g_selected_item == i)
327 driver->draw2DRectangle(video::SColor(255,255,0,0),
328 core::rect<s32>(rect.UpperLeftCorner - v2s32(1,1)*padding,
329 rect.LowerRightCorner + v2s32(1,1)*padding),
334 video::SColor bgcolor2(128,0,0,0);
335 driver->draw2DRectangle(bgcolor2, rect, NULL);
340 drawInventoryItem(driver, font, item, rect, NULL);
348 video::ITexture *heart_texture =
349 driver->getTexture(getTexturePath("heart.png").c_str());
350 v2s32 p = pos + v2s32(0, -20);
351 for(s32 i=0; i<halfheartcount/2; i++)
353 const video::SColor color(255,255,255,255);
354 const video::SColor colors[] = {color,color,color,color};
355 core::rect<s32> rect(0,0,16,16);
357 driver->draw2DImage(heart_texture, rect,
358 core::rect<s32>(core::position2d<s32>(0,0),
359 core::dimension2di(heart_texture->getOriginalSize())),
363 if(halfheartcount % 2 == 1)
365 const video::SColor color(255,255,255,255);
366 const video::SColor colors[] = {color,color,color,color};
367 core::rect<s32> rect(0,0,16/2,16);
369 core::dimension2di srcd(heart_texture->getOriginalSize());
371 driver->draw2DImage(heart_texture, rect,
372 core::rect<s32>(core::position2d<s32>(0,0), srcd),
380 Find what the player is pointing at
382 void getPointedNode(Client *client, v3f player_position,
383 v3f camera_direction, v3f camera_position,
384 bool &nodefound, core::line3d<f32> shootline,
385 v3s16 &nodepos, v3s16 &neighbourpos,
386 core::aabbox3d<f32> &nodehilightbox,
389 f32 mindistance = BS * 1001;
391 v3s16 pos_i = floatToInt(player_position, BS);
393 /*std::cout<<"pos_i=("<<pos_i.X<<","<<pos_i.Y<<","<<pos_i.Z<<")"
397 s16 ystart = pos_i.Y + 0 - (camera_direction.Y<0 ? a : 1);
398 s16 zstart = pos_i.Z - (camera_direction.Z<0 ? a : 1);
399 s16 xstart = pos_i.X - (camera_direction.X<0 ? a : 1);
400 s16 yend = pos_i.Y + 1 + (camera_direction.Y>0 ? a : 1);
401 s16 zend = pos_i.Z + (camera_direction.Z>0 ? a : 1);
402 s16 xend = pos_i.X + (camera_direction.X>0 ? a : 1);
404 for(s16 y = ystart; y <= yend; y++)
405 for(s16 z = zstart; z <= zend; z++)
406 for(s16 x = xstart; x <= xend; x++)
411 n = client->getNode(v3s16(x,y,z));
412 if(content_pointable(n.d) == false)
415 catch(InvalidPositionException &e)
421 v3f npf = intToFloat(np, BS);
426 v3s16(0,0,1), // back
428 v3s16(1,0,0), // right
429 v3s16(0,0,-1), // front
430 v3s16(0,-1,0), // bottom
431 v3s16(-1,0,0), // left
437 if(n.d == CONTENT_TORCH)
439 v3s16 dir = unpackDir(n.dir);
440 v3f dir_f = v3f(dir.X, dir.Y, dir.Z);
441 dir_f *= BS/2 - BS/6 - BS/20;
442 v3f cpf = npf + dir_f;
443 f32 distance = (cpf - camera_position).getLength();
445 core::aabbox3d<f32> box;
448 if(dir == v3s16(0,-1,0))
450 box = core::aabbox3d<f32>(
451 npf - v3f(BS/6, BS/2, BS/6),
452 npf + v3f(BS/6, -BS/2+BS/3*2, BS/6)
456 else if(dir == v3s16(0,1,0))
458 box = core::aabbox3d<f32>(
459 npf - v3f(BS/6, -BS/2+BS/3*2, BS/6),
460 npf + v3f(BS/6, BS/2, BS/6)
466 box = core::aabbox3d<f32>(
467 cpf - v3f(BS/6, BS/3, BS/6),
468 cpf + v3f(BS/6, BS/3, BS/6)
472 if(distance < mindistance)
474 if(box.intersectsWithLine(shootline))
479 mindistance = distance;
480 nodehilightbox = box;
484 else if(n.d == CONTENT_SIGN_WALL)
486 v3s16 dir = unpackDir(n.dir);
487 v3f dir_f = v3f(dir.X, dir.Y, dir.Z);
488 dir_f *= BS/2 - BS/6 - BS/20;
489 v3f cpf = npf + dir_f;
490 f32 distance = (cpf - camera_position).getLength();
494 v3f(BS*0.42,-BS*0.35,-BS*0.4),
495 v3f(BS*0.49, BS*0.35, BS*0.4),
498 for(s32 i=0; i<2; i++)
500 if(dir == v3s16(1,0,0))
501 vertices[i].rotateXZBy(0);
502 if(dir == v3s16(-1,0,0))
503 vertices[i].rotateXZBy(180);
504 if(dir == v3s16(0,0,1))
505 vertices[i].rotateXZBy(90);
506 if(dir == v3s16(0,0,-1))
507 vertices[i].rotateXZBy(-90);
508 if(dir == v3s16(0,-1,0))
509 vertices[i].rotateXYBy(-90);
510 if(dir == v3s16(0,1,0))
511 vertices[i].rotateXYBy(90);
516 core::aabbox3d<f32> box;
518 box = core::aabbox3d<f32>(vertices[0]);
519 box.addInternalPoint(vertices[1]);
521 if(distance < mindistance)
523 if(box.intersectsWithLine(shootline))
528 mindistance = distance;
529 nodehilightbox = box;
538 for(u16 i=0; i<6; i++)
540 v3f dir_f = v3f(dirs[i].X,
541 dirs[i].Y, dirs[i].Z);
542 v3f centerpoint = npf + dir_f * BS/2;
544 (centerpoint - camera_position).getLength();
546 if(distance < mindistance)
548 core::CMatrix4<f32> m;
549 m.buildRotateFromTo(v3f(0,0,1), dir_f);
551 // This is the back face
553 v3f(BS/2, BS/2, BS/2),
554 v3f(-BS/2, -BS/2, BS/2+d)
557 for(u16 j=0; j<2; j++)
559 m.rotateVect(corners[j]);
563 core::aabbox3d<f32> facebox(corners[0]);
564 facebox.addInternalPoint(corners[1]);
566 if(facebox.intersectsWithLine(shootline))
570 neighbourpos = np + dirs[i];
571 mindistance = distance;
573 //nodehilightbox = facebox;
575 const float d = 0.502;
576 core::aabbox3d<f32> nodebox
577 (-BS*d, -BS*d, -BS*d, BS*d, BS*d, BS*d);
578 v3f nodepos_f = intToFloat(nodepos, BS);
579 nodebox.MinEdge += nodepos_f;
580 nodebox.MaxEdge += nodepos_f;
581 nodehilightbox = nodebox;
583 } // if distance < mindistance
589 void update_skybox(video::IVideoDriver* driver,
590 scene::ISceneManager* smgr, scene::ISceneNode* &skybox,
598 if(brightness >= 0.5)
600 skybox = smgr->addSkyBoxSceneNode(
601 driver->getTexture(getTexturePath("skybox2.png").c_str()),
602 driver->getTexture(getTexturePath("skybox3.png").c_str()),
603 driver->getTexture(getTexturePath("skybox1.png").c_str()),
604 driver->getTexture(getTexturePath("skybox1.png").c_str()),
605 driver->getTexture(getTexturePath("skybox1.png").c_str()),
606 driver->getTexture(getTexturePath("skybox1.png").c_str()));
608 else if(brightness >= 0.2)
610 skybox = smgr->addSkyBoxSceneNode(
611 driver->getTexture(getTexturePath("skybox2_dawn.png").c_str()),
612 driver->getTexture(getTexturePath("skybox3_dawn.png").c_str()),
613 driver->getTexture(getTexturePath("skybox1_dawn.png").c_str()),
614 driver->getTexture(getTexturePath("skybox1_dawn.png").c_str()),
615 driver->getTexture(getTexturePath("skybox1_dawn.png").c_str()),
616 driver->getTexture(getTexturePath("skybox1_dawn.png").c_str()));
620 skybox = smgr->addSkyBoxSceneNode(
621 driver->getTexture(getTexturePath("skybox2_night.png").c_str()),
622 driver->getTexture(getTexturePath("skybox3_night.png").c_str()),
623 driver->getTexture(getTexturePath("skybox1_night.png").c_str()),
624 driver->getTexture(getTexturePath("skybox1_night.png").c_str()),
625 driver->getTexture(getTexturePath("skybox1_night.png").c_str()),
626 driver->getTexture(getTexturePath("skybox1_night.png").c_str()));
634 IrrlichtDevice *device,
637 std::string playername,
638 std::string password,
641 std::wstring &error_message
644 video::IVideoDriver* driver = device->getVideoDriver();
645 scene::ISceneManager* smgr = device->getSceneManager();
647 v2u32 screensize(0,0);
648 v2u32 last_screensize(0,0);
649 screensize = driver->getScreenSize();
651 const s32 hotbar_itemcount = 8;
652 const s32 hotbar_imagesize = 36;
654 // The color of the sky
656 //video::SColor skycolor = video::SColor(255,140,186,250);
658 video::SColor bgcolor_bright = video::SColor(255,170,200,230);
661 Draw "Loading" screen
663 const wchar_t *loadingtext = L"Loading and connecting...";
664 u32 text_height = font->getDimension(loadingtext).Height;
665 core::vector2d<s32> center(screensize.X/2, screensize.Y/2);
666 core::vector2d<s32> textsize(300, text_height);
667 core::rect<s32> textrect(center - textsize/2, center + textsize/2);
669 gui::IGUIStaticText *gui_loadingtext = guienv->addStaticText(
670 loadingtext, textrect, false, false);
671 gui_loadingtext->setTextAlignment(gui::EGUIA_CENTER, gui::EGUIA_UPPERLEFT);
673 driver->beginScene(true, true, video::SColor(255,0,0,0));
680 SharedPtr will delete it when it goes out of scope.
682 SharedPtr<Server> server;
684 std::cout<<DTIME<<"Creating server"<<std::endl;
685 server = new Server(map_dir);
693 std::cout<<DTIME<<"Creating client"<<std::endl;
694 Client client(device, playername.c_str(), password, draw_control);
696 Address connect_address(0,0,0,0, port);
699 //connect_address.Resolve("localhost");
700 connect_address.setAddress(127,0,0,1);
702 connect_address.Resolve(address.c_str());
704 catch(ResolveError &e)
706 std::cout<<DTIME<<"Couldn't resolve address"<<std::endl;
708 error_message = L"Couldn't resolve address";
709 gui_loadingtext->remove();
714 Attempt to connect to the server
717 dstream<<DTIME<<"Connecting to server at ";
718 connect_address.print(&dstream);
720 client.connect(connect_address);
722 bool could_connect = false;
725 float time_counter = 0.0;
728 if(client.connectedAndInitialized())
730 could_connect = true;
733 if(client.accessDenied())
737 // Wait for 10 seconds
738 if(time_counter >= 10.0)
744 driver->beginScene(true, true, video::SColor(255,0,0,0));
748 // Update client and server
760 catch(con::PeerNotFoundException &e)
763 if(could_connect == false)
765 if(client.accessDenied())
767 error_message = L"Access denied. Check your password and try again.";
768 std::cout<<DTIME<<"Access denied."<<std::endl;
772 error_message = L"Connection timed out.";
773 std::cout<<DTIME<<"Timed out."<<std::endl;
775 gui_loadingtext->remove();
782 float old_brightness = 1.0;
783 scene::ISceneNode* skybox = NULL;
784 update_skybox(driver, smgr, skybox, 1.0);
787 Create the camera node
790 scene::ICameraSceneNode* camera = smgr->addCameraSceneNode(
792 v3f(BS*100, BS*2, BS*100), // Look from
793 v3f(BS*100+1, BS*2, BS*100), // Look to
799 error_message = L"Failed to create the camera node";
803 camera->setFOV(FOV_ANGLE);
805 // Just so big a value that everything rendered is visible
806 camera->setFarValue(100000*BS);
808 f32 camera_yaw = 0; // "right/left"
809 f32 camera_pitch = 0; // "up/down"
815 float cloud_height = BS*100;
816 Clouds *clouds = NULL;
817 clouds = new Clouds(smgr->getRootSceneNode(), smgr, -1,
818 cloud_height, time(0));
824 gui_loadingtext->remove();
830 // First line of debug text
831 gui::IGUIStaticText *guitext = guienv->addStaticText(
833 core::rect<s32>(5, 5, 795, 5+text_height),
835 // Second line of debug text
836 gui::IGUIStaticText *guitext2 = guienv->addStaticText(
838 core::rect<s32>(5, 5+(text_height+5)*1, 795, (5+text_height)*2),
841 // At the middle of the screen
842 // Object infos are shown in this
843 gui::IGUIStaticText *guitext_info = guienv->addStaticText(
845 core::rect<s32>(0,0,400,text_height+5) + v2s32(100,200),
849 gui::IGUIStaticText *guitext_chat = guienv->addStaticText(
851 core::rect<s32>(0,0,0,0),
852 false, false); // Disable word wrap as of now
854 //guitext_chat->setBackgroundColor(video::SColor(96,0,0,0));
855 core::list<ChatLine> chat_lines;
857 /*GUIQuickInventory *quick_inventory = new GUIQuickInventory
858 (guienv, NULL, v2s32(10, 70), 5, &local_inventory);*/
859 /*GUIQuickInventory *quick_inventory = new GUIQuickInventory
860 (guienv, NULL, v2s32(0, 0), quickinv_itemcount, &local_inventory);*/
862 // Test the text input system
863 /*(new GUITextInputMenu(guienv, guiroot, -1, &g_menumgr,
865 /*GUIMessageMenu *menu =
866 new GUIMessageMenu(guienv, guiroot, -1,
872 (new GUIPauseMenu(guienv, guiroot, -1, g_gamecallback,
873 &g_menumgr))->drop();
876 /*guitext2->setVisible(true);
877 guitext_info->setVisible(true);
878 guitext_chat->setVisible(true);*/
880 //s32 guitext_chat_pad_bottom = 70;
883 Some statistics are collected in these
886 u32 beginscenetime = 0;
888 u32 endscenetime = 0;
891 //throw con::PeerNotFoundException("lol");
893 core::list<float> frametime_log;
895 float damage_flash_timer = 0;
901 bool first_loop_after_window_activation = true;
903 // Time is in milliseconds
904 // NOTE: getRealTime() causes strange problems in wine (imprecision?)
905 // NOTE: So we have to use getTime() and call run()s between them
906 u32 lasttime = device->getTimer()->getTime();
908 while(device->run() && kill == false)
910 if(g_gamecallback->disconnect_requested)
912 g_gamecallback->disconnect_requested = false;
916 if(g_gamecallback->changepassword_requested)
918 (new GUIPasswordChange(guienv, guiroot, -1,
919 &g_menumgr, &client))->drop();
920 g_gamecallback->changepassword_requested = false;
924 Process TextureSource's queue
926 ((TextureSource*)g_texturesource)->processQueue();
931 last_screensize = screensize;
932 screensize = driver->getScreenSize();
933 v2s32 displaycenter(screensize.X/2,screensize.Y/2);
934 //bool screensize_changed = screensize != last_screensize;
936 // Hilight boxes collected during the loop and displayed
937 core::list< core::aabbox3d<f32> > hilightboxes;
940 std::wstring infotext;
942 // When screen size changes, update positions and sizes of stuff
943 /*if(screensize_changed)
945 v2s32 pos(displaycenter.X-((quickinv_itemcount-1)*quickinv_spacing+quickinv_size)/2, screensize.Y-quickinv_spacing);
946 quick_inventory->updatePosition(pos);
949 //TimeTaker //timer1("//timer1");
951 // Time of frame without fps limit
955 // not using getRealTime is necessary for wine
956 u32 time = device->getTimer()->getTime();
958 busytime_u32 = time - lasttime;
961 busytime = busytime_u32 / 1000.0;
964 //std::cout<<"busytime_u32="<<busytime_u32<<std::endl;
966 // Necessary for device->getTimer()->getTime()
973 updateViewingRange(busytime, &client);
980 float fps_max = g_settings.getFloat("fps_max");
981 u32 frametime_min = 1000./fps_max;
983 if(busytime_u32 < frametime_min)
985 u32 sleeptime = frametime_min - busytime_u32;
986 device->sleep(sleeptime);
990 // Necessary for device->getTimer()->getTime()
994 Time difference calculation
996 f32 dtime; // in seconds
998 u32 time = device->getTimer()->getTime();
1000 dtime = (time - lasttime) / 1000.0;
1006 Log frametime for visualization
1008 frametime_log.push_back(dtime);
1009 if(frametime_log.size() > 100)
1011 core::list<float>::Iterator i = frametime_log.begin();
1012 frametime_log.erase(i);
1016 Visualize frametime in terminal
1018 /*for(u32 i=0; i<dtime*400; i++)
1020 std::cout<<std::endl;*/
1023 Time average and jitter calculation
1026 static f32 dtime_avg1 = 0.0;
1027 dtime_avg1 = dtime_avg1 * 0.98 + dtime * 0.02;
1028 f32 dtime_jitter1 = dtime - dtime_avg1;
1030 static f32 dtime_jitter1_max_sample = 0.0;
1031 static f32 dtime_jitter1_max_fraction = 0.0;
1033 static f32 jitter1_max = 0.0;
1034 static f32 counter = 0.0;
1035 if(dtime_jitter1 > jitter1_max)
1036 jitter1_max = dtime_jitter1;
1041 dtime_jitter1_max_sample = jitter1_max;
1042 dtime_jitter1_max_fraction
1043 = dtime_jitter1_max_sample / (dtime_avg1+0.001);
1049 Busytime average and jitter calculation
1052 static f32 busytime_avg1 = 0.0;
1053 busytime_avg1 = busytime_avg1 * 0.98 + busytime * 0.02;
1054 f32 busytime_jitter1 = busytime - busytime_avg1;
1056 static f32 busytime_jitter1_max_sample = 0.0;
1057 static f32 busytime_jitter1_min_sample = 0.0;
1059 static f32 jitter1_max = 0.0;
1060 static f32 jitter1_min = 0.0;
1061 static f32 counter = 0.0;
1062 if(busytime_jitter1 > jitter1_max)
1063 jitter1_max = busytime_jitter1;
1064 if(busytime_jitter1 < jitter1_min)
1065 jitter1_min = busytime_jitter1;
1069 busytime_jitter1_max_sample = jitter1_max;
1070 busytime_jitter1_min_sample = jitter1_min;
1077 Debug info for client
1080 static float counter = 0.0;
1085 client.printDebugInfo(std::cout);
1090 Direct handling of user input
1093 // Reset input if window not active or some menu is active
1094 if(device->isWindowActive() == false || noMenuActive() == false)
1099 // Input handler step() (used by the random input generator)
1103 Launch menus according to keys
1105 if(input->wasKeyDown(getKeySetting("keymap_inventory")))
1107 dstream<<DTIME<<"the_game: "
1108 <<"Launching inventory"<<std::endl;
1110 GUIInventoryMenu *menu =
1111 new GUIInventoryMenu(guienv, guiroot, -1,
1112 &g_menumgr, v2s16(8,7),
1113 client.getInventoryContext(),
1116 core::array<GUIInventoryMenu::DrawSpec> draw_spec;
1117 draw_spec.push_back(GUIInventoryMenu::DrawSpec(
1118 "list", "current_player", "main",
1119 v2s32(0, 3), v2s32(8, 4)));
1120 draw_spec.push_back(GUIInventoryMenu::DrawSpec(
1121 "list", "current_player", "craft",
1122 v2s32(3, 0), v2s32(3, 3)));
1123 draw_spec.push_back(GUIInventoryMenu::DrawSpec(
1124 "list", "current_player", "craftresult",
1125 v2s32(7, 1), v2s32(1, 1)));
1127 menu->setDrawSpec(draw_spec);
1131 else if(input->wasKeyDown(KEY_ESCAPE))
1133 dstream<<DTIME<<"the_game: "
1134 <<"Launching pause menu"<<std::endl;
1135 // It will delete itself by itself
1136 (new GUIPauseMenu(guienv, guiroot, -1, g_gamecallback,
1137 &g_menumgr))->drop();
1139 // Move mouse cursor on top of the disconnect button
1140 input->setMousePos(displaycenter.X, displaycenter.Y+25);
1142 else if(input->wasKeyDown(getKeySetting("keymap_chat")))
1144 TextDest *dest = new TextDestChat(&client);
1146 (new GUITextInputMenu(guienv, guiroot, -1,
1150 else if(input->wasKeyDown(getKeySetting("keymap_freemove")))
1152 if(g_settings.getBool("free_move"))
1154 g_settings.set("free_move","false");
1158 g_settings.set("free_move","true");
1161 else if(input->wasKeyDown(getKeySetting("keymap_fastmove")))
1163 if(g_settings.getBool("fast_move"))
1165 g_settings.set("fast_move","false");
1169 g_settings.set("fast_move","true");
1173 // Item selection with mouse wheel
1175 s32 wheel = input->getMouseWheel();
1176 u16 max_item = MYMIN(PLAYER_INVENTORY_SIZE-1,
1177 hotbar_itemcount-1);
1181 if(g_selected_item < max_item)
1184 g_selected_item = 0;
1188 if(g_selected_item > 0)
1191 g_selected_item = max_item;
1196 for(u16 i=0; i<10; i++)
1198 s32 keycode = irr::KEY_KEY_1 + i;
1200 keycode = irr::KEY_KEY_0;
1201 if(input->wasKeyDown((irr::EKEY_CODE)keycode))
1203 if(i < PLAYER_INVENTORY_SIZE && i < hotbar_itemcount)
1205 g_selected_item = i;
1207 dstream<<DTIME<<"Selected item: "
1208 <<g_selected_item<<std::endl;
1213 // Viewing range selection
1214 if(input->wasKeyDown(getKeySetting("keymap_rangeselect")))
1216 if(draw_control.range_all)
1218 draw_control.range_all = false;
1219 dstream<<DTIME<<"Disabled full viewing range"<<std::endl;
1223 draw_control.range_all = true;
1224 dstream<<DTIME<<"Enabled full viewing range"<<std::endl;
1228 // Print debug stacks
1229 if(input->wasKeyDown(getKeySetting("keymap_print_debug_stacks")))
1231 dstream<<"-----------------------------------------"
1233 dstream<<DTIME<<"Printing debug stacks:"<<std::endl;
1234 dstream<<"-----------------------------------------"
1236 debug_stacks_print();
1240 Player speed control
1241 TODO: Cache the keycodes from getKeySetting
1254 PlayerControl control(
1255 input->isKeyDown(getKeySetting("keymap_forward")),
1256 input->isKeyDown(getKeySetting("keymap_backward")),
1257 input->isKeyDown(getKeySetting("keymap_left")),
1258 input->isKeyDown(getKeySetting("keymap_right")),
1259 input->isKeyDown(getKeySetting("keymap_jump")),
1260 input->isKeyDown(getKeySetting("keymap_special1")),
1261 input->isKeyDown(getKeySetting("keymap_sneak")),
1265 client.setPlayerControl(control);
1274 //TimeTaker timer("server->step(dtime)");
1275 server->step(dtime);
1283 //TimeTaker timer("client.step(dtime)");
1285 //client.step(dtime_avg1);
1288 // Read client events
1291 ClientEvent event = client.getClientEvent();
1292 if(event.type == CE_NONE)
1296 else if(event.type == CE_PLAYER_DAMAGE)
1298 //u16 damage = event.player_damage.amount;
1299 //dstream<<"Player damage: "<<damage<<std::endl;
1300 damage_flash_timer = 0.05;
1302 else if(event.type == CE_PLAYER_FORCE_MOVE)
1304 camera_yaw = event.player_force_move.yaw;
1305 camera_pitch = event.player_force_move.pitch;
1309 // Get player position
1310 v3f player_position = client.getPlayerPosition();
1312 //TimeTaker //timer2("//timer2");
1315 Mouse and camera control
1318 if((device->isWindowActive() && noMenuActive()) || random_input)
1321 device->getCursorControl()->setVisible(false);
1323 if(first_loop_after_window_activation){
1324 //std::cout<<"window active, first loop"<<std::endl;
1325 first_loop_after_window_activation = false;
1328 s32 dx = input->getMousePos().X - displaycenter.X;
1329 s32 dy = input->getMousePos().Y - displaycenter.Y;
1330 //std::cout<<"window active, pos difference "<<dx<<","<<dy<<std::endl;
1332 /*const float keyspeed = 500;
1333 if(input->isKeyDown(irr::KEY_UP))
1334 dy -= dtime * keyspeed;
1335 if(input->isKeyDown(irr::KEY_DOWN))
1336 dy += dtime * keyspeed;
1337 if(input->isKeyDown(irr::KEY_LEFT))
1338 dx -= dtime * keyspeed;
1339 if(input->isKeyDown(irr::KEY_RIGHT))
1340 dx += dtime * keyspeed;*/
1342 camera_yaw -= dx*0.2;
1343 camera_pitch += dy*0.2;
1344 if(camera_pitch < -89.5) camera_pitch = -89.5;
1345 if(camera_pitch > 89.5) camera_pitch = 89.5;
1347 input->setMousePos(displaycenter.X, displaycenter.Y);
1350 device->getCursorControl()->setVisible(true);
1352 //std::cout<<"window inactive"<<std::endl;
1353 first_loop_after_window_activation = true;
1356 camera_yaw = wrapDegrees(camera_yaw);
1357 camera_pitch = wrapDegrees(camera_pitch);
1359 v3f camera_direction = v3f(0,0,1);
1360 camera_direction.rotateYZBy(camera_pitch);
1361 camera_direction.rotateXZBy(camera_yaw);
1363 // This is at the height of the eyes of the current figure
1364 //v3f camera_position = player_position + v3f(0, BS+BS/2, 0);
1365 // This is more like in minecraft
1366 v3f camera_position = player_position + v3f(0, BS+BS*0.625, 0);
1368 camera->setPosition(camera_position);
1369 // *100.0 helps in large map coordinates
1370 camera->setTarget(camera_position + camera_direction * 100.0);
1372 if(FIELD_OF_VIEW_TEST){
1373 client.updateCamera(v3f(0,0,0), v3f(0,0,1));
1376 //TimeTaker timer("client.updateCamera");
1377 client.updateCamera(camera_position, camera_direction);
1381 //TimeTaker //timer3("//timer3");
1384 Calculate what block is the crosshair pointing to
1387 //u32 t1 = device->getTimer()->getRealTime();
1389 //f32 d = 4; // max. distance
1390 f32 d = 4; // max. distance
1391 core::line3d<f32> shootline(camera_position,
1392 camera_position + camera_direction * BS * (d+1));
1394 MapBlockObject *selected_object = client.getSelectedObject
1395 (d*BS, camera_position, shootline);
1397 ClientActiveObject *selected_active_object
1398 = client.getSelectedActiveObject
1399 (d*BS, camera_position, shootline);
1401 if(selected_object != NULL)
1403 //dstream<<"Client returned selected_object != NULL"<<std::endl;
1405 core::aabbox3d<f32> box_on_map
1406 = selected_object->getSelectionBoxOnMap();
1408 hilightboxes.push_back(box_on_map);
1410 infotext = narrow_to_wide(selected_object->infoText());
1412 if(input->getLeftClicked())
1414 std::cout<<DTIME<<"Left-clicked object"<<std::endl;
1415 client.clickObject(0, selected_object->getBlock()->getPos(),
1416 selected_object->getId(), g_selected_item);
1418 else if(input->getRightClicked())
1420 std::cout<<DTIME<<"Right-clicked object"<<std::endl;
1422 Check if we want to modify the object ourselves
1424 if(selected_object->getTypeId() == MAPBLOCKOBJECT_TYPE_SIGN)
1426 dstream<<"Sign object right-clicked"<<std::endl;
1428 if(random_input == false)
1430 // Get a new text for it
1432 TextDest *dest = new TextDestSign(
1433 selected_object->getBlock()->getPos(),
1434 selected_object->getId(),
1437 SignObject *sign_object = (SignObject*)selected_object;
1439 std::wstring wtext =
1440 narrow_to_wide(sign_object->getText());
1442 (new GUITextInputMenu(guienv, guiroot, -1,
1448 Otherwise pass the event to the server as-is
1452 client.clickObject(1, selected_object->getBlock()->getPos(),
1453 selected_object->getId(), g_selected_item);
1457 else if(selected_active_object != NULL)
1459 //dstream<<"Client returned selected_active_object != NULL"<<std::endl;
1461 core::aabbox3d<f32> *selection_box
1462 = selected_active_object->getSelectionBox();
1463 // Box should exist because object was returned in the
1465 assert(selection_box);
1467 v3f pos = selected_active_object->getPosition();
1469 core::aabbox3d<f32> box_on_map(
1470 selection_box->MinEdge + pos,
1471 selection_box->MaxEdge + pos
1474 hilightboxes.push_back(box_on_map);
1476 //infotext = narrow_to_wide("A ClientActiveObject");
1477 infotext = narrow_to_wide(selected_active_object->infoText());
1479 if(input->getLeftClicked())
1481 std::cout<<DTIME<<"Left-clicked object"<<std::endl;
1482 client.clickActiveObject(0,
1483 selected_active_object->getId(), g_selected_item);
1485 else if(input->getRightClicked())
1487 std::cout<<DTIME<<"Right-clicked object"<<std::endl;
1490 else // selected_object == NULL
1494 Find out which node we are pointing at
1497 bool nodefound = false;
1500 core::aabbox3d<f32> nodehilightbox;
1502 getPointedNode(&client, player_position,
1503 camera_direction, camera_position,
1504 nodefound, shootline,
1505 nodepos, neighbourpos,
1508 static float nodig_delay_counter = 0.0;
1512 static v3s16 nodepos_old(-32768,-32768,-32768);
1514 static float dig_time = 0.0;
1515 static u16 dig_index = 0;
1521 hilightboxes.push_back(nodehilightbox);
1524 Check information text of node
1527 NodeMetadata *meta = client.getNodeMetadata(nodepos);
1530 infotext = narrow_to_wide(meta->infoText());
1533 //MapNode node = client.getNode(nodepos);
1539 if(input->getLeftReleased())
1541 client.clearTempMod(nodepos);
1545 if(nodig_delay_counter > 0.0)
1547 nodig_delay_counter -= dtime;
1551 if(nodepos != nodepos_old)
1553 std::cout<<DTIME<<"Pointing at ("<<nodepos.X<<","
1554 <<nodepos.Y<<","<<nodepos.Z<<")"<<std::endl;
1556 if(nodepos_old != v3s16(-32768,-32768,-32768))
1558 client.clearTempMod(nodepos_old);
1563 if(input->getLeftClicked() ||
1564 (input->getLeftState() && nodepos != nodepos_old))
1566 dstream<<DTIME<<"Started digging"<<std::endl;
1567 client.groundAction(0, nodepos, neighbourpos, g_selected_item);
1569 if(input->getLeftClicked())
1571 client.setTempMod(nodepos, NodeMod(NODEMOD_CRACK, 0));
1573 if(input->getLeftState())
1575 MapNode n = client.getNode(nodepos);
1577 // Get tool name. Default is "" = bare hands
1578 std::string toolname = "";
1579 InventoryList *mlist = local_inventory.getList("main");
1582 InventoryItem *item = mlist->getItem(g_selected_item);
1583 if(item && (std::string)item->getName() == "ToolItem")
1585 ToolItem *titem = (ToolItem*)item;
1586 toolname = titem->getToolName();
1590 // Get digging properties for material and tool
1592 DiggingProperties prop =
1593 getDiggingProperties(material, toolname);
1595 float dig_time_complete = 0.0;
1597 if(prop.diggable == false)
1599 /*dstream<<"Material "<<(int)material
1600 <<" not diggable with \""
1601 <<toolname<<"\""<<std::endl;*/
1602 // I guess nobody will wait for this long
1603 dig_time_complete = 10000000.0;
1607 dig_time_complete = prop.time;
1610 if(dig_time_complete >= 0.001)
1612 dig_index = (u16)((float)CRACK_ANIMATION_LENGTH
1613 * dig_time/dig_time_complete);
1615 // This is for torches
1618 dig_index = CRACK_ANIMATION_LENGTH;
1621 if(dig_index < CRACK_ANIMATION_LENGTH)
1623 //TimeTaker timer("client.setTempMod");
1624 //dstream<<"dig_index="<<dig_index<<std::endl;
1625 client.setTempMod(nodepos, NodeMod(NODEMOD_CRACK, dig_index));
1629 dstream<<DTIME<<"Digging completed"<<std::endl;
1630 client.groundAction(3, nodepos, neighbourpos, g_selected_item);
1631 client.clearTempMod(nodepos);
1632 client.removeNode(nodepos);
1636 nodig_delay_counter = dig_time_complete
1637 / (float)CRACK_ANIMATION_LENGTH;
1639 // We don't want a corresponding delay to
1640 // very time consuming nodes
1641 if(nodig_delay_counter > 0.5)
1643 nodig_delay_counter = 0.5;
1645 // We want a slight delay to very little
1646 // time consuming nodes
1647 float mindelay = 0.15;
1648 if(nodig_delay_counter < mindelay)
1650 nodig_delay_counter = mindelay;
1658 if(input->getRightClicked())
1660 std::cout<<DTIME<<"Ground right-clicked"<<std::endl;
1662 if(meta && meta->typeId() == CONTENT_SIGN_WALL && !random_input)
1664 dstream<<"Sign node right-clicked"<<std::endl;
1666 SignNodeMetadata *signmeta = (SignNodeMetadata*)meta;
1668 // Get a new text for it
1670 TextDest *dest = new TextDestSignNode(nodepos, &client);
1672 std::wstring wtext =
1673 narrow_to_wide(signmeta->getText());
1675 (new GUITextInputMenu(guienv, guiroot, -1,
1679 else if(meta && meta->typeId() == CONTENT_CHEST && !random_input)
1681 dstream<<"Chest node right-clicked"<<std::endl;
1683 //ChestNodeMetadata *chestmeta = (ChestNodeMetadata*)meta;
1685 std::string chest_inv_id;
1686 chest_inv_id += "nodemeta:";
1687 chest_inv_id += itos(nodepos.X);
1688 chest_inv_id += ",";
1689 chest_inv_id += itos(nodepos.Y);
1690 chest_inv_id += ",";
1691 chest_inv_id += itos(nodepos.Z);
1693 GUIInventoryMenu *menu =
1694 new GUIInventoryMenu(guienv, guiroot, -1,
1695 &g_menumgr, v2s16(8,9),
1696 client.getInventoryContext(),
1699 core::array<GUIInventoryMenu::DrawSpec> draw_spec;
1701 draw_spec.push_back(GUIInventoryMenu::DrawSpec(
1702 "list", chest_inv_id, "0",
1703 v2s32(0, 0), v2s32(8, 4)));
1704 draw_spec.push_back(GUIInventoryMenu::DrawSpec(
1705 "list", "current_player", "main",
1706 v2s32(0, 5), v2s32(8, 4)));
1708 menu->setDrawSpec(draw_spec);
1713 else if(meta && meta->typeId() == CONTENT_FURNACE && !random_input)
1715 dstream<<"Furnace node right-clicked"<<std::endl;
1717 GUIFurnaceMenu *menu =
1718 new GUIFurnaceMenu(guienv, guiroot, -1,
1719 &g_menumgr, nodepos, &client);
1726 client.groundAction(1, nodepos, neighbourpos, g_selected_item);
1730 nodepos_old = nodepos;
1735 } // selected_object == NULL
1737 input->resetLeftClicked();
1738 input->resetRightClicked();
1740 if(input->getLeftReleased())
1742 std::cout<<DTIME<<"Left button released (stopped digging)"
1744 client.groundAction(2, v3s16(0,0,0), v3s16(0,0,0), 0);
1746 if(input->getRightReleased())
1748 //std::cout<<DTIME<<"Right released"<<std::endl;
1752 input->resetLeftReleased();
1753 input->resetRightReleased();
1756 Calculate stuff for drawing
1759 camera->setAspectRatio((f32)screensize.X / (f32)screensize.Y);
1761 u32 daynight_ratio = client.getDayNightRatio();
1762 u8 l = decode_light((daynight_ratio * LIGHT_SUN) / 1000);
1763 video::SColor bgcolor = video::SColor(
1765 bgcolor_bright.getRed() * l / 255,
1766 bgcolor_bright.getGreen() * l / 255,
1767 bgcolor_bright.getBlue() * l / 255);
1768 /*skycolor.getRed() * l / 255,
1769 skycolor.getGreen() * l / 255,
1770 skycolor.getBlue() * l / 255);*/
1772 float brightness = (float)l/255.0;
1777 if(fabs(brightness - old_brightness) > 0.01)
1778 update_skybox(driver, smgr, skybox, brightness);
1785 clouds->step(dtime);
1786 clouds->update(v2f(player_position.X, player_position.Z),
1787 0.05+brightness*0.95);
1790 // Store brightness value
1791 old_brightness = brightness;
1797 if(g_settings.getBool("enable_fog") == true)
1799 f32 range = draw_control.wanted_range*BS + MAP_BLOCKSIZE*BS*1.5;
1800 if(draw_control.range_all)
1803 range = range * 0.5 + 25*BS;
1807 video::EFT_FOG_LINEAR,
1819 video::EFT_FOG_LINEAR,
1830 Update gui stuff (0ms)
1833 //TimeTaker guiupdatetimer("Gui updating");
1836 static float drawtime_avg = 0;
1837 drawtime_avg = drawtime_avg * 0.95 + (float)drawtime*0.05;
1838 static float beginscenetime_avg = 0;
1839 beginscenetime_avg = beginscenetime_avg * 0.95 + (float)beginscenetime*0.05;
1840 static float scenetime_avg = 0;
1841 scenetime_avg = scenetime_avg * 0.95 + (float)scenetime*0.05;
1842 static float endscenetime_avg = 0;
1843 endscenetime_avg = endscenetime_avg * 0.95 + (float)endscenetime*0.05;
1846 snprintf(temptext, 300, "Minetest-c55 %s ("
1849 " drawtime=%.0f, beginscenetime=%.0f"
1850 ", scenetime=%.0f, endscenetime=%.0f",
1852 draw_control.range_all,
1859 guitext->setText(narrow_to_wide(temptext).c_str());
1864 snprintf(temptext, 300,
1865 "(% .1f, % .1f, % .1f)"
1866 " (% .3f < btime_jitter < % .3f"
1867 ", dtime_jitter = % .1f %%"
1868 ", v_range = %.1f)",
1869 player_position.X/BS,
1870 player_position.Y/BS,
1871 player_position.Z/BS,
1872 busytime_jitter1_min_sample,
1873 busytime_jitter1_max_sample,
1874 dtime_jitter1_max_fraction * 100.0,
1875 draw_control.wanted_range
1878 guitext2->setText(narrow_to_wide(temptext).c_str());
1882 guitext_info->setText(infotext.c_str());
1886 Get chat messages from client
1890 std::wstring message;
1891 while(client.getChatMessage(message))
1893 chat_lines.push_back(ChatLine(message));
1894 /*if(chat_lines.size() > 6)
1896 core::list<ChatLine>::Iterator
1897 i = chat_lines.begin();
1898 chat_lines.erase(i);
1901 // Append them to form the whole static text and throw
1902 // it to the gui element
1904 // This will correspond to the line number counted from
1905 // top to bottom, from size-1 to 0
1906 s16 line_number = chat_lines.size();
1907 // Count of messages to be removed from the top
1908 u16 to_be_removed_count = 0;
1909 for(core::list<ChatLine>::Iterator
1910 i = chat_lines.begin();
1911 i != chat_lines.end(); i++)
1913 // After this, line number is valid for this loop
1918 This results in a maximum age of 60*6 to the
1919 lowermost line and a maximum of 6 lines
1921 float allowed_age = (6-line_number) * 60.0;
1923 if((*i).age > allowed_age)
1925 to_be_removed_count++;
1928 whole += (*i).text + L'\n';
1930 for(u16 i=0; i<to_be_removed_count; i++)
1932 core::list<ChatLine>::Iterator
1933 it = chat_lines.begin();
1934 chat_lines.erase(it);
1936 guitext_chat->setText(whole.c_str());
1938 // Update gui element size and position
1940 /*core::rect<s32> rect(
1942 screensize.Y - guitext_chat_pad_bottom
1943 - text_height*chat_lines.size(),
1945 screensize.Y - guitext_chat_pad_bottom
1947 core::rect<s32> rect(
1951 50 + text_height*chat_lines.size()
1954 guitext_chat->setRelativePosition(rect);
1956 if(chat_lines.size() == 0)
1957 guitext_chat->setVisible(false);
1959 guitext_chat->setVisible(true);
1966 static u16 old_selected_item = 65535;
1967 if(client.getLocalInventoryUpdated()
1968 || g_selected_item != old_selected_item)
1970 old_selected_item = g_selected_item;
1971 //std::cout<<"Updating local inventory"<<std::endl;
1972 client.getLocalInventory(local_inventory);
1976 Send actions returned by the inventory menu
1978 while(inventory_action_queue.size() != 0)
1980 InventoryAction *a = inventory_action_queue.pop_front();
1982 client.sendInventoryAction(a);
1991 TimeTaker drawtimer("Drawing");
1995 TimeTaker timer("beginScene");
1996 driver->beginScene(true, true, bgcolor);
1997 //driver->beginScene(false, true, bgcolor);
1998 beginscenetime = timer.stop(true);
2003 //std::cout<<DTIME<<"smgr->drawAll()"<<std::endl;
2006 TimeTaker timer("smgr");
2008 scenetime = timer.stop(true);
2012 //TimeTaker timer9("auxiliary drawings");
2016 //TimeTaker //timer10("//timer10");
2022 driver->setMaterial(m);
2024 driver->setTransform(video::ETS_WORLD, core::IdentityMatrix);
2026 for(core::list< core::aabbox3d<f32> >::Iterator i=hilightboxes.begin();
2027 i != hilightboxes.end(); i++)
2029 /*std::cout<<"hilightbox min="
2030 <<"("<<i->MinEdge.X<<","<<i->MinEdge.Y<<","<<i->MinEdge.Z<<")"
2032 <<"("<<i->MaxEdge.X<<","<<i->MaxEdge.Y<<","<<i->MaxEdge.Z<<")"
2034 driver->draw3DBox(*i, video::SColor(255,0,0,0));
2040 if(g_settings.getBool("frametime_graph") == true)
2043 for(core::list<float>::Iterator
2044 i = frametime_log.begin();
2045 i != frametime_log.end();
2048 driver->draw2DLine(v2s32(x,50),
2049 v2s32(x,50+(*i)*1000),
2050 video::SColor(255,255,255,255));
2058 driver->draw2DLine(displaycenter - core::vector2d<s32>(10,0),
2059 displaycenter + core::vector2d<s32>(10,0),
2060 video::SColor(255,255,255,255));
2061 driver->draw2DLine(displaycenter - core::vector2d<s32>(0,10),
2062 displaycenter + core::vector2d<s32>(0,10),
2063 video::SColor(255,255,255,255));
2068 //TimeTaker //timer11("//timer11");
2080 draw_hotbar(driver, font, v2s32(displaycenter.X, screensize.Y),
2081 hotbar_imagesize, hotbar_itemcount, &local_inventory,
2088 if(damage_flash_timer > 0.0)
2090 damage_flash_timer -= dtime;
2092 video::SColor color(128,255,0,0);
2093 driver->draw2DRectangle(color,
2094 core::rect<s32>(0,0,screensize.X,screensize.Y),
2102 TimeTaker timer("endScene");
2104 endscenetime = timer.stop(true);
2107 drawtime = drawtimer.stop(true);
2113 static s16 lastFPS = 0;
2114 //u16 fps = driver->getFPS();
2115 u16 fps = (1.0/dtime_avg1);
2119 core::stringw str = L"Minetest [";
2120 str += driver->getName();
2124 device->setWindowCaption(str.c_str());
2135 Draw a "shutting down" screen, which will be shown while the map
2136 generator and other stuff quits
2139 const wchar_t *shuttingdowntext = L"Shutting down stuff...";
2140 gui::IGUIStaticText *gui_shuttingdowntext = guienv->addStaticText(
2141 shuttingdowntext, textrect, false, false);
2142 gui_shuttingdowntext->setTextAlignment(gui::EGUIA_CENTER,
2143 gui::EGUIA_UPPERLEFT);
2144 driver->beginScene(true, true, video::SColor(255,0,0,0));
2147 gui_shuttingdowntext->remove();