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"
34 Setting this to 1 enables a special camera mode that forces
35 the renderers to think that the camera statically points from
36 the starting place to a static direction.
38 This allows one to move around with the player and see what
39 is actually drawn behind solid things and behind the player.
41 #define FIELD_OF_VIEW_TEST 0
44 MapDrawControl draw_control;
53 ChatLine(const std::wstring &a_text):
66 // Inventory actions from the menu are buffered here before sending
67 Queue<InventoryAction*> inventory_action_queue;
68 // This is a copy of the inventory that the client's environment has
69 Inventory local_inventory;
71 u16 g_selected_item = 0;
77 struct TextDestSign : public TextDest
79 TextDestSign(v3s16 blockpos, s16 id, Client *client)
81 m_blockpos = blockpos;
85 void gotText(std::wstring text)
87 std::string ntext = wide_to_narrow(text);
88 dstream<<"Changing text of a sign object: "
90 m_client->sendSignText(m_blockpos, m_id, ntext);
98 struct TextDestChat : public TextDest
100 TextDestChat(Client *client)
104 void gotText(std::wstring text)
106 // Discard empty line
110 // Parse command (server command starts with "/#")
111 if(text[0] == L'/' && text[1] != L'#')
113 std::wstring reply = L"Local: ";
115 reply += L"Local commands not yet supported. "
116 L"Server prefix is \"/#\".";
118 m_client->addChatMessage(reply);
123 m_client->sendChatMessage(text);
125 m_client->addChatMessage(text);
131 struct TextDestSignNode : public TextDest
133 TextDestSignNode(v3s16 p, Client *client)
138 void gotText(std::wstring text)
140 std::string ntext = wide_to_narrow(text);
141 dstream<<"Changing text of a sign node: "
143 m_client->sendSignNodeText(m_p, ntext);
151 Render distance feedback loop
153 void updateViewingRange(f32 frametime_in, Client *client)
155 if(draw_control.range_all == true)
158 static f32 added_frametime = 0;
159 static s16 added_frames = 0;
161 added_frametime += frametime_in;
164 // Actually this counter kind of sucks because frametime is busytime
165 static f32 counter = 0;
166 counter -= frametime_in;
172 /*dstream<<__FUNCTION_NAME
173 <<": Collected "<<added_frames<<" frames, total of "
174 <<added_frametime<<"s."<<std::endl;*/
176 /*dstream<<"draw_control.blocks_drawn="
177 <<draw_control.blocks_drawn
178 <<", draw_control.blocks_would_have_drawn="
179 <<draw_control.blocks_would_have_drawn
182 float range_min = g_settings.getS16("viewing_range_nodes_min");
183 float range_max = g_settings.getS16("viewing_range_nodes_max");
185 // Limit minimum to keep the feedback loop stable
189 draw_control.wanted_min_range = range_min;
190 //draw_control.wanted_max_blocks = (1.5*draw_control.blocks_drawn)+1;
191 draw_control.wanted_max_blocks = (1.5*draw_control.blocks_would_have_drawn)+1;
192 if(draw_control.wanted_max_blocks < 10)
193 draw_control.wanted_max_blocks = 10;
195 float block_draw_ratio = 1.0;
196 if(draw_control.blocks_would_have_drawn != 0)
198 block_draw_ratio = (float)draw_control.blocks_drawn
199 / (float)draw_control.blocks_would_have_drawn;
202 // Calculate the average frametime in the case that all wanted
203 // blocks had been drawn
204 f32 frametime = added_frametime / added_frames / block_draw_ratio;
206 added_frametime = 0.0;
209 float wanted_fps = g_settings.getFloat("wanted_fps");
210 float wanted_frametime = 1.0 / wanted_fps;
212 f32 wanted_frametime_change = wanted_frametime - frametime;
213 //dstream<<"wanted_frametime_change="<<wanted_frametime_change<<std::endl;
215 // If needed frametime change is small, just return
216 if(fabs(wanted_frametime_change) < wanted_frametime*0.4)
218 //dstream<<"ignoring small wanted_frametime_change"<<std::endl;
222 float range = draw_control.wanted_range;
223 float new_range = range;
225 static s16 range_old = 0;
226 static f32 frametime_old = 0;
228 float d_range = range - range_old;
229 f32 d_frametime = frametime - frametime_old;
230 // A sane default of 30ms per 50 nodes of range
231 static f32 time_per_range = 30. / 50;
234 time_per_range = d_frametime / d_range;
237 // The minimum allowed calculated frametime-range derivative:
238 // Practically this sets the maximum speed of changing the range.
239 // The lower this value, the higher the maximum changing speed.
240 // A low value here results in wobbly range (0.001)
241 // A high value here results in slow changing range (0.0025)
242 // SUGG: This could be dynamically adjusted so that when
243 // the camera is turning, this is lower
244 //float min_time_per_range = 0.0015;
245 float min_time_per_range = 0.0010;
246 //float min_time_per_range = 0.05 / range;
247 if(time_per_range < min_time_per_range)
249 time_per_range = min_time_per_range;
250 //dstream<<"time_per_range="<<time_per_range<<" (min)"<<std::endl;
254 //dstream<<"time_per_range="<<time_per_range<<std::endl;
257 f32 wanted_range_change = wanted_frametime_change / time_per_range;
258 // Dampen the change a bit to kill oscillations
259 //wanted_range_change *= 0.9;
260 //wanted_range_change *= 0.75;
261 wanted_range_change *= 0.5;
262 //dstream<<"wanted_range_change="<<wanted_range_change<<std::endl;
264 // If needed range change is very small, just return
265 if(fabs(wanted_range_change) < 0.001)
267 //dstream<<"ignoring small wanted_range_change"<<std::endl;
271 new_range += wanted_range_change;
273 //float new_range_unclamped = new_range;
274 if(new_range < range_min)
275 new_range = range_min;
276 if(new_range > range_max)
277 new_range = range_max;
279 /*dstream<<"new_range="<<new_range_unclamped
280 <<", clamped to "<<new_range<<std::endl;*/
282 draw_control.wanted_range = new_range;
284 range_old = new_range;
285 frametime_old = frametime;
291 void draw_hotbar(video::IVideoDriver *driver, gui::IGUIFont *font,
292 v2s32 centerlowerpos, s32 imgsize, s32 itemcount,
293 Inventory *inventory, s32 halfheartcount)
295 InventoryList *mainlist = inventory->getList("main");
298 dstream<<"WARNING: draw_hotbar(): mainlist == NULL"<<std::endl;
302 s32 padding = imgsize/12;
303 //s32 height = imgsize + padding*2;
304 s32 width = itemcount*(imgsize+padding*2);
306 // Position of upper left corner of bar
307 v2s32 pos = centerlowerpos - v2s32(width/2, imgsize+padding*2);
309 // Draw background color
310 /*core::rect<s32> barrect(0,0,width,height);
312 video::SColor bgcolor(255,128,128,128);
313 driver->draw2DRectangle(bgcolor, barrect, NULL);*/
315 core::rect<s32> imgrect(0,0,imgsize,imgsize);
317 for(s32 i=0; i<itemcount; i++)
319 InventoryItem *item = mainlist->getItem(i);
321 core::rect<s32> rect = imgrect + pos
322 + v2s32(padding+i*(imgsize+padding*2), padding);
324 if(g_selected_item == i)
326 driver->draw2DRectangle(video::SColor(255,255,0,0),
327 core::rect<s32>(rect.UpperLeftCorner - v2s32(1,1)*padding,
328 rect.LowerRightCorner + v2s32(1,1)*padding),
333 video::SColor bgcolor2(128,0,0,0);
334 driver->draw2DRectangle(bgcolor2, rect, NULL);
339 drawInventoryItem(driver, font, item, rect, NULL);
347 video::ITexture *heart_texture =
348 driver->getTexture(porting::getDataPath("heart.png").c_str());
349 v2s32 p = pos + v2s32(0, -20);
350 for(s32 i=0; i<halfheartcount/2; i++)
352 const video::SColor color(255,255,255,255);
353 const video::SColor colors[] = {color,color,color,color};
354 core::rect<s32> rect(0,0,16,16);
356 driver->draw2DImage(heart_texture, rect,
357 core::rect<s32>(core::position2d<s32>(0,0),
358 core::dimension2di(heart_texture->getOriginalSize())),
362 if(halfheartcount % 2 == 1)
364 const video::SColor color(255,255,255,255);
365 const video::SColor colors[] = {color,color,color,color};
366 core::rect<s32> rect(0,0,16/2,16);
368 core::dimension2di srcd(heart_texture->getOriginalSize());
370 driver->draw2DImage(heart_texture, rect,
371 core::rect<s32>(core::position2d<s32>(0,0), srcd),
379 Find what the player is pointing at
381 void getPointedNode(Client *client, v3f player_position,
382 v3f camera_direction, v3f camera_position,
383 bool &nodefound, core::line3d<f32> shootline,
384 v3s16 &nodepos, v3s16 &neighbourpos,
385 core::aabbox3d<f32> &nodehilightbox,
388 f32 mindistance = BS * 1001;
390 v3s16 pos_i = floatToInt(player_position, BS);
392 /*std::cout<<"pos_i=("<<pos_i.X<<","<<pos_i.Y<<","<<pos_i.Z<<")"
396 s16 ystart = pos_i.Y + 0 - (camera_direction.Y<0 ? a : 1);
397 s16 zstart = pos_i.Z - (camera_direction.Z<0 ? a : 1);
398 s16 xstart = pos_i.X - (camera_direction.X<0 ? a : 1);
399 s16 yend = pos_i.Y + 1 + (camera_direction.Y>0 ? a : 1);
400 s16 zend = pos_i.Z + (camera_direction.Z>0 ? a : 1);
401 s16 xend = pos_i.X + (camera_direction.X>0 ? a : 1);
403 for(s16 y = ystart; y <= yend; y++)
404 for(s16 z = zstart; z <= zend; z++)
405 for(s16 x = xstart; x <= xend; x++)
410 n = client->getNode(v3s16(x,y,z));
411 if(content_pointable(n.d) == false)
414 catch(InvalidPositionException &e)
420 v3f npf = intToFloat(np, BS);
425 v3s16(0,0,1), // back
427 v3s16(1,0,0), // right
428 v3s16(0,0,-1), // front
429 v3s16(0,-1,0), // bottom
430 v3s16(-1,0,0), // left
436 if(n.d == CONTENT_TORCH)
438 v3s16 dir = unpackDir(n.dir);
439 v3f dir_f = v3f(dir.X, dir.Y, dir.Z);
440 dir_f *= BS/2 - BS/6 - BS/20;
441 v3f cpf = npf + dir_f;
442 f32 distance = (cpf - camera_position).getLength();
444 core::aabbox3d<f32> box;
447 if(dir == v3s16(0,-1,0))
449 box = core::aabbox3d<f32>(
450 npf - v3f(BS/6, BS/2, BS/6),
451 npf + v3f(BS/6, -BS/2+BS/3*2, BS/6)
455 else if(dir == v3s16(0,1,0))
457 box = core::aabbox3d<f32>(
458 npf - v3f(BS/6, -BS/2+BS/3*2, BS/6),
459 npf + v3f(BS/6, BS/2, BS/6)
465 box = core::aabbox3d<f32>(
466 cpf - v3f(BS/6, BS/3, BS/6),
467 cpf + v3f(BS/6, BS/3, BS/6)
471 if(distance < mindistance)
473 if(box.intersectsWithLine(shootline))
478 mindistance = distance;
479 nodehilightbox = box;
483 else if(n.d == CONTENT_SIGN_WALL)
485 v3s16 dir = unpackDir(n.dir);
486 v3f dir_f = v3f(dir.X, dir.Y, dir.Z);
487 dir_f *= BS/2 - BS/6 - BS/20;
488 v3f cpf = npf + dir_f;
489 f32 distance = (cpf - camera_position).getLength();
493 v3f(BS*0.42,-BS*0.35,-BS*0.4),
494 v3f(BS*0.49, BS*0.35, BS*0.4),
497 for(s32 i=0; i<2; i++)
499 if(dir == v3s16(1,0,0))
500 vertices[i].rotateXZBy(0);
501 if(dir == v3s16(-1,0,0))
502 vertices[i].rotateXZBy(180);
503 if(dir == v3s16(0,0,1))
504 vertices[i].rotateXZBy(90);
505 if(dir == v3s16(0,0,-1))
506 vertices[i].rotateXZBy(-90);
507 if(dir == v3s16(0,-1,0))
508 vertices[i].rotateXYBy(-90);
509 if(dir == v3s16(0,1,0))
510 vertices[i].rotateXYBy(90);
515 core::aabbox3d<f32> box;
517 box = core::aabbox3d<f32>(vertices[0]);
518 box.addInternalPoint(vertices[1]);
520 if(distance < mindistance)
522 if(box.intersectsWithLine(shootline))
527 mindistance = distance;
528 nodehilightbox = box;
537 for(u16 i=0; i<6; i++)
539 v3f dir_f = v3f(dirs[i].X,
540 dirs[i].Y, dirs[i].Z);
541 v3f centerpoint = npf + dir_f * BS/2;
543 (centerpoint - camera_position).getLength();
545 if(distance < mindistance)
547 core::CMatrix4<f32> m;
548 m.buildRotateFromTo(v3f(0,0,1), dir_f);
550 // This is the back face
552 v3f(BS/2, BS/2, BS/2),
553 v3f(-BS/2, -BS/2, BS/2+d)
556 for(u16 j=0; j<2; j++)
558 m.rotateVect(corners[j]);
562 core::aabbox3d<f32> facebox(corners[0]);
563 facebox.addInternalPoint(corners[1]);
565 if(facebox.intersectsWithLine(shootline))
569 neighbourpos = np + dirs[i];
570 mindistance = distance;
572 //nodehilightbox = facebox;
574 const float d = 0.502;
575 core::aabbox3d<f32> nodebox
576 (-BS*d, -BS*d, -BS*d, BS*d, BS*d, BS*d);
577 v3f nodepos_f = intToFloat(nodepos, BS);
578 nodebox.MinEdge += nodepos_f;
579 nodebox.MaxEdge += nodepos_f;
580 nodehilightbox = nodebox;
582 } // if distance < mindistance
588 void update_skybox(video::IVideoDriver* driver,
589 scene::ISceneManager* smgr, scene::ISceneNode* &skybox,
597 if(brightness >= 0.5)
599 skybox = smgr->addSkyBoxSceneNode(
600 driver->getTexture(porting::getDataPath("skybox2.png").c_str()),
601 driver->getTexture(porting::getDataPath("skybox3.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()),
605 driver->getTexture(porting::getDataPath("skybox1.png").c_str()));
607 else if(brightness >= 0.2)
609 skybox = smgr->addSkyBoxSceneNode(
610 driver->getTexture(porting::getDataPath("skybox2_dawn.png").c_str()),
611 driver->getTexture(porting::getDataPath("skybox3_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()),
615 driver->getTexture(porting::getDataPath("skybox1_dawn.png").c_str()));
619 skybox = smgr->addSkyBoxSceneNode(
620 driver->getTexture(porting::getDataPath("skybox2_night.png").c_str()),
621 driver->getTexture(porting::getDataPath("skybox3_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()),
625 driver->getTexture(porting::getDataPath("skybox1_night.png").c_str()));
633 IrrlichtDevice *device,
636 std::string playername,
639 std::wstring &error_message
642 video::IVideoDriver* driver = device->getVideoDriver();
643 scene::ISceneManager* smgr = device->getSceneManager();
645 v2u32 screensize(0,0);
646 v2u32 last_screensize(0,0);
647 screensize = driver->getScreenSize();
649 const s32 hotbar_itemcount = 8;
650 const s32 hotbar_imagesize = 36;
652 // The color of the sky
654 //video::SColor skycolor = video::SColor(255,140,186,250);
656 video::SColor bgcolor_bright = video::SColor(255,170,200,230);
659 Draw "Loading" screen
661 const wchar_t *loadingtext = L"Loading and connecting...";
662 u32 text_height = font->getDimension(loadingtext).Height;
663 core::vector2d<s32> center(screensize.X/2, screensize.Y/2);
664 core::vector2d<s32> textsize(300, text_height);
665 core::rect<s32> textrect(center - textsize/2, center + textsize/2);
667 gui::IGUIStaticText *gui_loadingtext = guienv->addStaticText(
668 loadingtext, textrect, false, false);
669 gui_loadingtext->setTextAlignment(gui::EGUIA_CENTER, gui::EGUIA_UPPERLEFT);
671 driver->beginScene(true, true, video::SColor(255,0,0,0));
678 SharedPtr will delete it when it goes out of scope.
680 SharedPtr<Server> server;
682 std::cout<<DTIME<<"Creating server"<<std::endl;
683 server = new Server(map_dir);
691 std::cout<<DTIME<<"Creating client"<<std::endl;
692 Client client(device, playername.c_str(), draw_control);
694 Address connect_address(0,0,0,0, port);
697 //connect_address.Resolve("localhost");
698 connect_address.setAddress(127,0,0,1);
700 connect_address.Resolve(address.c_str());
702 catch(ResolveError &e)
704 std::cout<<DTIME<<"Couldn't resolve address"<<std::endl;
706 error_message = L"Couldn't resolve address";
707 gui_loadingtext->remove();
712 Attempt to connect to the server
715 dstream<<DTIME<<"Connecting to server at ";
716 connect_address.print(&dstream);
718 client.connect(connect_address);
720 bool could_connect = false;
723 float time_counter = 0.0;
726 if(client.connectedAndInitialized())
728 could_connect = true;
731 // Wait for 10 seconds
732 if(time_counter >= 10.0)
738 driver->beginScene(true, true, video::SColor(255,0,0,0));
742 // Update client and server
754 catch(con::PeerNotFoundException &e)
757 if(could_connect == false)
759 std::cout<<DTIME<<"Timed out."<<std::endl;
760 error_message = L"Connection timed out.";
761 gui_loadingtext->remove();
768 float old_brightness = 1.0;
769 scene::ISceneNode* skybox = NULL;
770 update_skybox(driver, smgr, skybox, 1.0);
773 Create the camera node
776 scene::ICameraSceneNode* camera = smgr->addCameraSceneNode(
778 v3f(BS*100, BS*2, BS*100), // Look from
779 v3f(BS*100+1, BS*2, BS*100), // Look to
785 error_message = L"Failed to create the camera node";
789 camera->setFOV(FOV_ANGLE);
791 // Just so big a value that everything rendered is visible
792 camera->setFarValue(100000*BS);
794 f32 camera_yaw = 0; // "right/left"
795 f32 camera_pitch = 0; // "up/down"
801 float cloud_height = BS*100;
802 Clouds *clouds = NULL;
803 clouds = new Clouds(smgr->getRootSceneNode(), smgr, -1,
804 cloud_height, time(0));
810 gui_loadingtext->remove();
816 // First line of debug text
817 gui::IGUIStaticText *guitext = guienv->addStaticText(
819 core::rect<s32>(5, 5, 795, 5+text_height),
821 // Second line of debug text
822 gui::IGUIStaticText *guitext2 = guienv->addStaticText(
824 core::rect<s32>(5, 5+(text_height+5)*1, 795, (5+text_height)*2),
827 // At the middle of the screen
828 // Object infos are shown in this
829 gui::IGUIStaticText *guitext_info = guienv->addStaticText(
831 core::rect<s32>(0,0,400,text_height+5) + v2s32(100,200),
835 gui::IGUIStaticText *guitext_chat = guienv->addStaticText(
837 core::rect<s32>(0,0,0,0),
838 false, false); // Disable word wrap as of now
840 //guitext_chat->setBackgroundColor(video::SColor(96,0,0,0));
841 core::list<ChatLine> chat_lines;
843 /*GUIQuickInventory *quick_inventory = new GUIQuickInventory
844 (guienv, NULL, v2s32(10, 70), 5, &local_inventory);*/
845 /*GUIQuickInventory *quick_inventory = new GUIQuickInventory
846 (guienv, NULL, v2s32(0, 0), quickinv_itemcount, &local_inventory);*/
848 // Test the text input system
849 /*(new GUITextInputMenu(guienv, guiroot, -1, &g_menumgr,
851 /*GUIMessageMenu *menu =
852 new GUIMessageMenu(guienv, guiroot, -1,
858 (new GUIPauseMenu(guienv, guiroot, -1, g_gamecallback,
859 &g_menumgr))->drop();
862 /*guitext2->setVisible(true);
863 guitext_info->setVisible(true);
864 guitext_chat->setVisible(true);*/
866 //s32 guitext_chat_pad_bottom = 70;
869 Some statistics are collected in these
872 u32 beginscenetime = 0;
874 u32 endscenetime = 0;
877 //throw con::PeerNotFoundException("lol");
879 core::list<float> frametime_log;
881 float damage_flash_timer = 0;
887 bool first_loop_after_window_activation = true;
889 // Time is in milliseconds
890 // NOTE: getRealTime() causes strange problems in wine (imprecision?)
891 // NOTE: So we have to use getTime() and call run()s between them
892 u32 lasttime = device->getTimer()->getTime();
894 while(device->run() && kill == false)
896 if(g_gamecallback->disconnect_requested)
898 g_gamecallback->disconnect_requested = false;
903 Process TextureSource's queue
905 ((TextureSource*)g_texturesource)->processQueue();
910 last_screensize = screensize;
911 screensize = driver->getScreenSize();
912 v2s32 displaycenter(screensize.X/2,screensize.Y/2);
913 //bool screensize_changed = screensize != last_screensize;
915 // Hilight boxes collected during the loop and displayed
916 core::list< core::aabbox3d<f32> > hilightboxes;
919 std::wstring infotext;
921 // When screen size changes, update positions and sizes of stuff
922 /*if(screensize_changed)
924 v2s32 pos(displaycenter.X-((quickinv_itemcount-1)*quickinv_spacing+quickinv_size)/2, screensize.Y-quickinv_spacing);
925 quick_inventory->updatePosition(pos);
928 //TimeTaker //timer1("//timer1");
930 // Time of frame without fps limit
934 // not using getRealTime is necessary for wine
935 u32 time = device->getTimer()->getTime();
937 busytime_u32 = time - lasttime;
940 busytime = busytime_u32 / 1000.0;
943 //std::cout<<"busytime_u32="<<busytime_u32<<std::endl;
945 // Necessary for device->getTimer()->getTime()
952 updateViewingRange(busytime, &client);
959 float fps_max = g_settings.getFloat("fps_max");
960 u32 frametime_min = 1000./fps_max;
962 if(busytime_u32 < frametime_min)
964 u32 sleeptime = frametime_min - busytime_u32;
965 device->sleep(sleeptime);
969 // Necessary for device->getTimer()->getTime()
973 Time difference calculation
975 f32 dtime; // in seconds
977 u32 time = device->getTimer()->getTime();
979 dtime = (time - lasttime) / 1000.0;
985 Log frametime for visualization
987 frametime_log.push_back(dtime);
988 if(frametime_log.size() > 100)
990 core::list<float>::Iterator i = frametime_log.begin();
991 frametime_log.erase(i);
995 Visualize frametime in terminal
997 /*for(u32 i=0; i<dtime*400; i++)
999 std::cout<<std::endl;*/
1002 Time average and jitter calculation
1005 static f32 dtime_avg1 = 0.0;
1006 dtime_avg1 = dtime_avg1 * 0.98 + dtime * 0.02;
1007 f32 dtime_jitter1 = dtime - dtime_avg1;
1009 static f32 dtime_jitter1_max_sample = 0.0;
1010 static f32 dtime_jitter1_max_fraction = 0.0;
1012 static f32 jitter1_max = 0.0;
1013 static f32 counter = 0.0;
1014 if(dtime_jitter1 > jitter1_max)
1015 jitter1_max = dtime_jitter1;
1020 dtime_jitter1_max_sample = jitter1_max;
1021 dtime_jitter1_max_fraction
1022 = dtime_jitter1_max_sample / (dtime_avg1+0.001);
1028 Busytime average and jitter calculation
1031 static f32 busytime_avg1 = 0.0;
1032 busytime_avg1 = busytime_avg1 * 0.98 + busytime * 0.02;
1033 f32 busytime_jitter1 = busytime - busytime_avg1;
1035 static f32 busytime_jitter1_max_sample = 0.0;
1036 static f32 busytime_jitter1_min_sample = 0.0;
1038 static f32 jitter1_max = 0.0;
1039 static f32 jitter1_min = 0.0;
1040 static f32 counter = 0.0;
1041 if(busytime_jitter1 > jitter1_max)
1042 jitter1_max = busytime_jitter1;
1043 if(busytime_jitter1 < jitter1_min)
1044 jitter1_min = busytime_jitter1;
1048 busytime_jitter1_max_sample = jitter1_max;
1049 busytime_jitter1_min_sample = jitter1_min;
1056 Debug info for client
1059 static float counter = 0.0;
1064 client.printDebugInfo(std::cout);
1069 Direct handling of user input
1072 // Reset input if window not active or some menu is active
1073 if(device->isWindowActive() == false || noMenuActive() == false)
1078 // Input handler step() (used by the random input generator)
1082 Launch menus according to keys
1084 if(input->wasKeyDown(getKeySetting("keymap_inventory")))
1086 dstream<<DTIME<<"the_game: "
1087 <<"Launching inventory"<<std::endl;
1089 GUIInventoryMenu *menu =
1090 new GUIInventoryMenu(guienv, guiroot, -1,
1091 &g_menumgr, v2s16(8,7),
1092 client.getInventoryContext(),
1095 core::array<GUIInventoryMenu::DrawSpec> draw_spec;
1096 draw_spec.push_back(GUIInventoryMenu::DrawSpec(
1097 "list", "current_player", "main",
1098 v2s32(0, 3), v2s32(8, 4)));
1099 draw_spec.push_back(GUIInventoryMenu::DrawSpec(
1100 "list", "current_player", "craft",
1101 v2s32(3, 0), v2s32(3, 3)));
1102 draw_spec.push_back(GUIInventoryMenu::DrawSpec(
1103 "list", "current_player", "craftresult",
1104 v2s32(7, 1), v2s32(1, 1)));
1106 menu->setDrawSpec(draw_spec);
1110 else if(input->wasKeyDown(KEY_ESCAPE))
1112 dstream<<DTIME<<"the_game: "
1113 <<"Launching pause menu"<<std::endl;
1114 // It will delete itself by itself
1115 (new GUIPauseMenu(guienv, guiroot, -1, g_gamecallback,
1116 &g_menumgr))->drop();
1118 else if(input->wasKeyDown(getKeySetting("keymap_chat")))
1120 TextDest *dest = new TextDestChat(&client);
1122 (new GUITextInputMenu(guienv, guiroot, -1,
1127 // Item selection with mouse wheel
1129 s32 wheel = input->getMouseWheel();
1130 u16 max_item = MYMIN(PLAYER_INVENTORY_SIZE-1,
1131 hotbar_itemcount-1);
1135 if(g_selected_item < max_item)
1138 g_selected_item = 0;
1142 if(g_selected_item > 0)
1145 g_selected_item = max_item;
1150 for(u16 i=0; i<10; i++)
1152 s32 keycode = irr::KEY_KEY_1 + i;
1154 keycode = irr::KEY_KEY_0;
1155 if(input->wasKeyDown((irr::EKEY_CODE)keycode))
1157 if(i < PLAYER_INVENTORY_SIZE && i < hotbar_itemcount)
1159 g_selected_item = i;
1161 dstream<<DTIME<<"Selected item: "
1162 <<g_selected_item<<std::endl;
1167 // Viewing range selection
1168 if(input->wasKeyDown(getKeySetting("keymap_rangeselect")))
1170 if(draw_control.range_all)
1172 draw_control.range_all = false;
1173 dstream<<DTIME<<"Disabled full viewing range"<<std::endl;
1177 draw_control.range_all = true;
1178 dstream<<DTIME<<"Enabled full viewing range"<<std::endl;
1182 // Print debug stacks
1183 if(input->wasKeyDown(getKeySetting("keymap_print_debug_stacks")))
1185 dstream<<"-----------------------------------------"
1187 dstream<<DTIME<<"Printing debug stacks:"<<std::endl;
1188 dstream<<"-----------------------------------------"
1190 debug_stacks_print();
1194 Player speed control
1195 TODO: Cache the keycodes from getKeySetting
1208 PlayerControl control(
1209 input->isKeyDown(getKeySetting("keymap_forward")),
1210 input->isKeyDown(getKeySetting("keymap_backward")),
1211 input->isKeyDown(getKeySetting("keymap_left")),
1212 input->isKeyDown(getKeySetting("keymap_right")),
1213 input->isKeyDown(getKeySetting("keymap_jump")),
1214 input->isKeyDown(getKeySetting("keymap_special1")),
1215 input->isKeyDown(getKeySetting("keymap_sneak")),
1219 client.setPlayerControl(control);
1228 //TimeTaker timer("server->step(dtime)");
1229 server->step(dtime);
1237 //TimeTaker timer("client.step(dtime)");
1239 //client.step(dtime_avg1);
1242 // Read client events
1245 ClientEvent event = client.getClientEvent();
1246 if(event.type == CE_NONE)
1250 else if(event.type == CE_PLAYER_DAMAGE)
1252 //u16 damage = event.player_damage.amount;
1253 //dstream<<"Player damage: "<<damage<<std::endl;
1254 damage_flash_timer = 0.05;
1256 else if(event.type == CE_PLAYER_FORCE_MOVE)
1258 camera_yaw = event.player_force_move.yaw;
1259 camera_pitch = event.player_force_move.pitch;
1263 // Get player position
1264 v3f player_position = client.getPlayerPosition();
1266 //TimeTaker //timer2("//timer2");
1269 Mouse and camera control
1272 if((device->isWindowActive() && noMenuActive()) || random_input)
1275 device->getCursorControl()->setVisible(false);
1277 if(first_loop_after_window_activation){
1278 //std::cout<<"window active, first loop"<<std::endl;
1279 first_loop_after_window_activation = false;
1282 s32 dx = input->getMousePos().X - displaycenter.X;
1283 s32 dy = input->getMousePos().Y - displaycenter.Y;
1284 //std::cout<<"window active, pos difference "<<dx<<","<<dy<<std::endl;
1286 /*const float keyspeed = 500;
1287 if(input->isKeyDown(irr::KEY_UP))
1288 dy -= dtime * keyspeed;
1289 if(input->isKeyDown(irr::KEY_DOWN))
1290 dy += dtime * keyspeed;
1291 if(input->isKeyDown(irr::KEY_LEFT))
1292 dx -= dtime * keyspeed;
1293 if(input->isKeyDown(irr::KEY_RIGHT))
1294 dx += dtime * keyspeed;*/
1296 camera_yaw -= dx*0.2;
1297 camera_pitch += dy*0.2;
1298 if(camera_pitch < -89.5) camera_pitch = -89.5;
1299 if(camera_pitch > 89.5) camera_pitch = 89.5;
1301 input->setMousePos(displaycenter.X, displaycenter.Y);
1304 device->getCursorControl()->setVisible(true);
1306 //std::cout<<"window inactive"<<std::endl;
1307 first_loop_after_window_activation = true;
1310 camera_yaw = wrapDegrees(camera_yaw);
1311 camera_pitch = wrapDegrees(camera_pitch);
1313 v3f camera_direction = v3f(0,0,1);
1314 camera_direction.rotateYZBy(camera_pitch);
1315 camera_direction.rotateXZBy(camera_yaw);
1317 // This is at the height of the eyes of the current figure
1318 //v3f camera_position = player_position + v3f(0, BS+BS/2, 0);
1319 // This is more like in minecraft
1320 v3f camera_position = player_position + v3f(0, BS+BS*0.625, 0);
1322 camera->setPosition(camera_position);
1323 // *100.0 helps in large map coordinates
1324 camera->setTarget(camera_position + camera_direction * 100.0);
1326 if(FIELD_OF_VIEW_TEST){
1327 client.updateCamera(v3f(0,0,0), v3f(0,0,1));
1330 //TimeTaker timer("client.updateCamera");
1331 client.updateCamera(camera_position, camera_direction);
1335 //TimeTaker //timer3("//timer3");
1338 Calculate what block is the crosshair pointing to
1341 //u32 t1 = device->getTimer()->getRealTime();
1343 //f32 d = 4; // max. distance
1344 f32 d = 4; // max. distance
1345 core::line3d<f32> shootline(camera_position,
1346 camera_position + camera_direction * BS * (d+1));
1348 MapBlockObject *selected_object = client.getSelectedObject
1349 (d*BS, camera_position, shootline);
1351 ClientActiveObject *selected_active_object
1352 = client.getSelectedActiveObject
1353 (d*BS, camera_position, shootline);
1355 if(selected_object != NULL)
1357 //dstream<<"Client returned selected_object != NULL"<<std::endl;
1359 core::aabbox3d<f32> box_on_map
1360 = selected_object->getSelectionBoxOnMap();
1362 hilightboxes.push_back(box_on_map);
1364 infotext = narrow_to_wide(selected_object->infoText());
1366 if(input->getLeftClicked())
1368 std::cout<<DTIME<<"Left-clicked object"<<std::endl;
1369 client.clickObject(0, selected_object->getBlock()->getPos(),
1370 selected_object->getId(), g_selected_item);
1372 else if(input->getRightClicked())
1374 std::cout<<DTIME<<"Right-clicked object"<<std::endl;
1376 Check if we want to modify the object ourselves
1378 if(selected_object->getTypeId() == MAPBLOCKOBJECT_TYPE_SIGN)
1380 dstream<<"Sign object right-clicked"<<std::endl;
1382 if(random_input == false)
1384 // Get a new text for it
1386 TextDest *dest = new TextDestSign(
1387 selected_object->getBlock()->getPos(),
1388 selected_object->getId(),
1391 SignObject *sign_object = (SignObject*)selected_object;
1393 std::wstring wtext =
1394 narrow_to_wide(sign_object->getText());
1396 (new GUITextInputMenu(guienv, guiroot, -1,
1402 Otherwise pass the event to the server as-is
1406 client.clickObject(1, selected_object->getBlock()->getPos(),
1407 selected_object->getId(), g_selected_item);
1411 else if(selected_active_object != NULL)
1413 //dstream<<"Client returned selected_active_object != NULL"<<std::endl;
1415 core::aabbox3d<f32> *selection_box
1416 = selected_active_object->getSelectionBox();
1417 // Box should exist because object was returned in the
1419 assert(selection_box);
1421 v3f pos = selected_active_object->getPosition();
1423 core::aabbox3d<f32> box_on_map(
1424 selection_box->MinEdge + pos,
1425 selection_box->MaxEdge + pos
1428 hilightboxes.push_back(box_on_map);
1430 //infotext = narrow_to_wide("A ClientActiveObject");
1431 infotext = narrow_to_wide(selected_active_object->infoText());
1433 if(input->getLeftClicked())
1435 std::cout<<DTIME<<"Left-clicked object"<<std::endl;
1436 client.clickActiveObject(0,
1437 selected_active_object->getId(), g_selected_item);
1439 else if(input->getRightClicked())
1441 std::cout<<DTIME<<"Right-clicked object"<<std::endl;
1444 else // selected_object == NULL
1448 Find out which node we are pointing at
1451 bool nodefound = false;
1454 core::aabbox3d<f32> nodehilightbox;
1456 getPointedNode(&client, player_position,
1457 camera_direction, camera_position,
1458 nodefound, shootline,
1459 nodepos, neighbourpos,
1462 static float nodig_delay_counter = 0.0;
1466 static v3s16 nodepos_old(-32768,-32768,-32768);
1468 static float dig_time = 0.0;
1469 static u16 dig_index = 0;
1475 hilightboxes.push_back(nodehilightbox);
1478 Check information text of node
1481 NodeMetadata *meta = client.getNodeMetadata(nodepos);
1484 infotext = narrow_to_wide(meta->infoText());
1487 //MapNode node = client.getNode(nodepos);
1493 if(input->getLeftReleased())
1495 client.clearTempMod(nodepos);
1499 if(nodig_delay_counter > 0.0)
1501 nodig_delay_counter -= dtime;
1505 if(nodepos != nodepos_old)
1507 std::cout<<DTIME<<"Pointing at ("<<nodepos.X<<","
1508 <<nodepos.Y<<","<<nodepos.Z<<")"<<std::endl;
1510 if(nodepos_old != v3s16(-32768,-32768,-32768))
1512 client.clearTempMod(nodepos_old);
1517 if(input->getLeftClicked() ||
1518 (input->getLeftState() && nodepos != nodepos_old))
1520 dstream<<DTIME<<"Started digging"<<std::endl;
1521 client.groundAction(0, nodepos, neighbourpos, g_selected_item);
1523 if(input->getLeftClicked())
1525 client.setTempMod(nodepos, NodeMod(NODEMOD_CRACK, 0));
1527 if(input->getLeftState())
1529 MapNode n = client.getNode(nodepos);
1531 // Get tool name. Default is "" = bare hands
1532 std::string toolname = "";
1533 InventoryList *mlist = local_inventory.getList("main");
1536 InventoryItem *item = mlist->getItem(g_selected_item);
1537 if(item && (std::string)item->getName() == "ToolItem")
1539 ToolItem *titem = (ToolItem*)item;
1540 toolname = titem->getToolName();
1544 // Get digging properties for material and tool
1546 DiggingProperties prop =
1547 getDiggingProperties(material, toolname);
1549 float dig_time_complete = 0.0;
1551 if(prop.diggable == false)
1553 /*dstream<<"Material "<<(int)material
1554 <<" not diggable with \""
1555 <<toolname<<"\""<<std::endl;*/
1556 // I guess nobody will wait for this long
1557 dig_time_complete = 10000000.0;
1561 dig_time_complete = prop.time;
1564 if(dig_time_complete >= 0.001)
1566 dig_index = (u16)((float)CRACK_ANIMATION_LENGTH
1567 * dig_time/dig_time_complete);
1569 // This is for torches
1572 dig_index = CRACK_ANIMATION_LENGTH;
1575 if(dig_index < CRACK_ANIMATION_LENGTH)
1577 //TimeTaker timer("client.setTempMod");
1578 //dstream<<"dig_index="<<dig_index<<std::endl;
1579 client.setTempMod(nodepos, NodeMod(NODEMOD_CRACK, dig_index));
1583 dstream<<DTIME<<"Digging completed"<<std::endl;
1584 client.groundAction(3, nodepos, neighbourpos, g_selected_item);
1585 client.clearTempMod(nodepos);
1586 client.removeNode(nodepos);
1590 nodig_delay_counter = dig_time_complete
1591 / (float)CRACK_ANIMATION_LENGTH;
1593 // We don't want a corresponding delay to
1594 // very time consuming nodes
1595 if(nodig_delay_counter > 0.5)
1597 nodig_delay_counter = 0.5;
1599 // We want a slight delay to very little
1600 // time consuming nodes
1601 float mindelay = 0.15;
1602 if(nodig_delay_counter < mindelay)
1604 nodig_delay_counter = mindelay;
1612 if(input->getRightClicked())
1614 std::cout<<DTIME<<"Ground right-clicked"<<std::endl;
1616 if(meta && meta->typeId() == CONTENT_SIGN_WALL && !random_input)
1618 dstream<<"Sign node right-clicked"<<std::endl;
1620 SignNodeMetadata *signmeta = (SignNodeMetadata*)meta;
1622 // Get a new text for it
1624 TextDest *dest = new TextDestSignNode(nodepos, &client);
1626 std::wstring wtext =
1627 narrow_to_wide(signmeta->getText());
1629 (new GUITextInputMenu(guienv, guiroot, -1,
1633 else if(meta && meta->typeId() == CONTENT_CHEST && !random_input)
1635 dstream<<"Chest node right-clicked"<<std::endl;
1637 //ChestNodeMetadata *chestmeta = (ChestNodeMetadata*)meta;
1639 std::string chest_inv_id;
1640 chest_inv_id += "nodemeta:";
1641 chest_inv_id += itos(nodepos.X);
1642 chest_inv_id += ",";
1643 chest_inv_id += itos(nodepos.Y);
1644 chest_inv_id += ",";
1645 chest_inv_id += itos(nodepos.Z);
1647 GUIInventoryMenu *menu =
1648 new GUIInventoryMenu(guienv, guiroot, -1,
1649 &g_menumgr, v2s16(8,9),
1650 client.getInventoryContext(),
1653 core::array<GUIInventoryMenu::DrawSpec> draw_spec;
1655 draw_spec.push_back(GUIInventoryMenu::DrawSpec(
1656 "list", chest_inv_id, "0",
1657 v2s32(0, 0), v2s32(8, 4)));
1658 draw_spec.push_back(GUIInventoryMenu::DrawSpec(
1659 "list", "current_player", "main",
1660 v2s32(0, 5), v2s32(8, 4)));
1662 menu->setDrawSpec(draw_spec);
1667 else if(meta && meta->typeId() == CONTENT_FURNACE && !random_input)
1669 dstream<<"Furnace node right-clicked"<<std::endl;
1671 GUIFurnaceMenu *menu =
1672 new GUIFurnaceMenu(guienv, guiroot, -1,
1673 &g_menumgr, nodepos, &client);
1680 client.groundAction(1, nodepos, neighbourpos, g_selected_item);
1684 nodepos_old = nodepos;
1689 } // selected_object == NULL
1691 input->resetLeftClicked();
1692 input->resetRightClicked();
1694 if(input->getLeftReleased())
1696 std::cout<<DTIME<<"Left button released (stopped digging)"
1698 client.groundAction(2, v3s16(0,0,0), v3s16(0,0,0), 0);
1700 if(input->getRightReleased())
1702 //std::cout<<DTIME<<"Right released"<<std::endl;
1706 input->resetLeftReleased();
1707 input->resetRightReleased();
1710 Calculate stuff for drawing
1713 camera->setAspectRatio((f32)screensize.X / (f32)screensize.Y);
1715 u32 daynight_ratio = client.getDayNightRatio();
1716 u8 l = decode_light((daynight_ratio * LIGHT_SUN) / 1000);
1717 video::SColor bgcolor = video::SColor(
1719 bgcolor_bright.getRed() * l / 255,
1720 bgcolor_bright.getGreen() * l / 255,
1721 bgcolor_bright.getBlue() * l / 255);
1722 /*skycolor.getRed() * l / 255,
1723 skycolor.getGreen() * l / 255,
1724 skycolor.getBlue() * l / 255);*/
1726 float brightness = (float)l/255.0;
1731 if(fabs(brightness - old_brightness) > 0.01)
1732 update_skybox(driver, smgr, skybox, brightness);
1739 clouds->step(dtime);
1740 clouds->update(v2f(player_position.X, player_position.Z),
1741 0.05+brightness*0.95);
1744 // Store brightness value
1745 old_brightness = brightness;
1751 if(g_settings.getBool("enable_fog") == true)
1753 f32 range = draw_control.wanted_range*BS + MAP_BLOCKSIZE*BS*1.5;
1754 if(draw_control.range_all)
1757 range = range * 0.5 + 25*BS;
1761 video::EFT_FOG_LINEAR,
1773 video::EFT_FOG_LINEAR,
1784 Update gui stuff (0ms)
1787 //TimeTaker guiupdatetimer("Gui updating");
1790 static float drawtime_avg = 0;
1791 drawtime_avg = drawtime_avg * 0.95 + (float)drawtime*0.05;
1792 static float beginscenetime_avg = 0;
1793 beginscenetime_avg = beginscenetime_avg * 0.95 + (float)beginscenetime*0.05;
1794 static float scenetime_avg = 0;
1795 scenetime_avg = scenetime_avg * 0.95 + (float)scenetime*0.05;
1796 static float endscenetime_avg = 0;
1797 endscenetime_avg = endscenetime_avg * 0.95 + (float)endscenetime*0.05;
1800 snprintf(temptext, 300, "Minetest-c55 %s ("
1803 " drawtime=%.0f, beginscenetime=%.0f"
1804 ", scenetime=%.0f, endscenetime=%.0f",
1806 draw_control.range_all,
1813 guitext->setText(narrow_to_wide(temptext).c_str());
1818 snprintf(temptext, 300,
1819 "(% .1f, % .1f, % .1f)"
1820 " (% .3f < btime_jitter < % .3f"
1821 ", dtime_jitter = % .1f %%"
1822 ", v_range = %.1f)",
1823 player_position.X/BS,
1824 player_position.Y/BS,
1825 player_position.Z/BS,
1826 busytime_jitter1_min_sample,
1827 busytime_jitter1_max_sample,
1828 dtime_jitter1_max_fraction * 100.0,
1829 draw_control.wanted_range
1832 guitext2->setText(narrow_to_wide(temptext).c_str());
1836 guitext_info->setText(infotext.c_str());
1840 Get chat messages from client
1844 std::wstring message;
1845 while(client.getChatMessage(message))
1847 chat_lines.push_back(ChatLine(message));
1848 /*if(chat_lines.size() > 6)
1850 core::list<ChatLine>::Iterator
1851 i = chat_lines.begin();
1852 chat_lines.erase(i);
1855 // Append them to form the whole static text and throw
1856 // it to the gui element
1858 // This will correspond to the line number counted from
1859 // top to bottom, from size-1 to 0
1860 s16 line_number = chat_lines.size();
1861 // Count of messages to be removed from the top
1862 u16 to_be_removed_count = 0;
1863 for(core::list<ChatLine>::Iterator
1864 i = chat_lines.begin();
1865 i != chat_lines.end(); i++)
1867 // After this, line number is valid for this loop
1872 This results in a maximum age of 60*6 to the
1873 lowermost line and a maximum of 6 lines
1875 float allowed_age = (6-line_number) * 60.0;
1877 if((*i).age > allowed_age)
1879 to_be_removed_count++;
1882 whole += (*i).text + L'\n';
1884 for(u16 i=0; i<to_be_removed_count; i++)
1886 core::list<ChatLine>::Iterator
1887 it = chat_lines.begin();
1888 chat_lines.erase(it);
1890 guitext_chat->setText(whole.c_str());
1892 // Update gui element size and position
1894 /*core::rect<s32> rect(
1896 screensize.Y - guitext_chat_pad_bottom
1897 - text_height*chat_lines.size(),
1899 screensize.Y - guitext_chat_pad_bottom
1901 core::rect<s32> rect(
1905 50 + text_height*chat_lines.size()
1908 guitext_chat->setRelativePosition(rect);
1910 if(chat_lines.size() == 0)
1911 guitext_chat->setVisible(false);
1913 guitext_chat->setVisible(true);
1920 static u16 old_selected_item = 65535;
1921 if(client.getLocalInventoryUpdated()
1922 || g_selected_item != old_selected_item)
1924 old_selected_item = g_selected_item;
1925 //std::cout<<"Updating local inventory"<<std::endl;
1926 client.getLocalInventory(local_inventory);
1930 Send actions returned by the inventory menu
1932 while(inventory_action_queue.size() != 0)
1934 InventoryAction *a = inventory_action_queue.pop_front();
1936 client.sendInventoryAction(a);
1945 TimeTaker drawtimer("Drawing");
1949 TimeTaker timer("beginScene");
1950 driver->beginScene(true, true, bgcolor);
1951 //driver->beginScene(false, true, bgcolor);
1952 beginscenetime = timer.stop(true);
1957 //std::cout<<DTIME<<"smgr->drawAll()"<<std::endl;
1960 TimeTaker timer("smgr");
1962 scenetime = timer.stop(true);
1966 //TimeTaker timer9("auxiliary drawings");
1970 //TimeTaker //timer10("//timer10");
1976 driver->setMaterial(m);
1978 driver->setTransform(video::ETS_WORLD, core::IdentityMatrix);
1980 for(core::list< core::aabbox3d<f32> >::Iterator i=hilightboxes.begin();
1981 i != hilightboxes.end(); i++)
1983 /*std::cout<<"hilightbox min="
1984 <<"("<<i->MinEdge.X<<","<<i->MinEdge.Y<<","<<i->MinEdge.Z<<")"
1986 <<"("<<i->MaxEdge.X<<","<<i->MaxEdge.Y<<","<<i->MaxEdge.Z<<")"
1988 driver->draw3DBox(*i, video::SColor(255,0,0,0));
1994 if(g_settings.getBool("frametime_graph") == true)
1997 for(core::list<float>::Iterator
1998 i = frametime_log.begin();
1999 i != frametime_log.end();
2002 driver->draw2DLine(v2s32(x,50),
2003 v2s32(x,50+(*i)*1000),
2004 video::SColor(255,255,255,255));
2012 driver->draw2DLine(displaycenter - core::vector2d<s32>(10,0),
2013 displaycenter + core::vector2d<s32>(10,0),
2014 video::SColor(255,255,255,255));
2015 driver->draw2DLine(displaycenter - core::vector2d<s32>(0,10),
2016 displaycenter + core::vector2d<s32>(0,10),
2017 video::SColor(255,255,255,255));
2022 //TimeTaker //timer11("//timer11");
2034 draw_hotbar(driver, font, v2s32(displaycenter.X, screensize.Y),
2035 hotbar_imagesize, hotbar_itemcount, &local_inventory,
2042 if(damage_flash_timer > 0.0)
2044 damage_flash_timer -= dtime;
2046 video::SColor color(128,255,0,0);
2047 driver->draw2DRectangle(color,
2048 core::rect<s32>(0,0,screensize.X,screensize.Y),
2056 TimeTaker timer("endScene");
2058 endscenetime = timer.stop(true);
2061 drawtime = drawtimer.stop(true);
2067 static s16 lastFPS = 0;
2068 //u16 fps = driver->getFPS();
2069 u16 fps = (1.0/dtime_avg1);
2073 core::stringw str = L"Minetest [";
2074 str += driver->getName();
2078 device->setWindowCaption(str.c_str());
2084 Draw a "shutting down" screen, which will be shown while the map
2085 generator and other stuff quits
2088 const wchar_t *shuttingdowntext = L"Shutting down stuff...";
2089 gui::IGUIStaticText *gui_shuttingdowntext = guienv->addStaticText(
2090 shuttingdowntext, textrect, false, false);
2091 gui_shuttingdowntext->setTextAlignment(gui::EGUIA_CENTER,
2092 gui::EGUIA_UPPERLEFT);
2093 driver->beginScene(true, true, video::SColor(255,0,0,0));
2096 gui_shuttingdowntext->remove();