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 "materials.h"
34 // TODO: Move content-aware stuff to separate file
35 #include "content_mapnode.h"
36 #include "content_nodemeta.h"
39 Setting this to 1 enables a special camera mode that forces
40 the renderers to think that the camera statically points from
41 the starting place to a static direction.
43 This allows one to move around with the player and see what
44 is actually drawn behind solid things and behind the player.
46 #define FIELD_OF_VIEW_TEST 0
49 MapDrawControl draw_control;
58 ChatLine(const std::wstring &a_text):
71 // Inventory actions from the menu are buffered here before sending
72 Queue<InventoryAction*> inventory_action_queue;
73 // This is a copy of the inventory that the client's environment has
74 Inventory local_inventory;
76 u16 g_selected_item = 0;
82 struct TextDestSign : public TextDest
84 TextDestSign(v3s16 blockpos, s16 id, Client *client)
86 m_blockpos = blockpos;
90 void gotText(std::wstring text)
92 std::string ntext = wide_to_narrow(text);
93 dstream<<"Changing text of a sign object: "
95 m_client->sendSignText(m_blockpos, m_id, ntext);
103 struct TextDestChat : public TextDest
105 TextDestChat(Client *client)
109 void gotText(std::wstring text)
111 // Discard empty line
115 // Parse command (server command starts with "/#")
116 if(text[0] == L'/' && text[1] != L'#')
118 std::wstring reply = L"Local: ";
120 reply += L"Local commands not yet supported. "
121 L"Server prefix is \"/#\".";
123 m_client->addChatMessage(reply);
128 m_client->sendChatMessage(text);
130 m_client->addChatMessage(text);
136 struct TextDestSignNode : public TextDest
138 TextDestSignNode(v3s16 p, Client *client)
143 void gotText(std::wstring text)
145 std::string ntext = wide_to_narrow(text);
146 dstream<<"Changing text of a sign node: "
148 m_client->sendSignNodeText(m_p, ntext);
156 Render distance feedback loop
158 void updateViewingRange(f32 frametime_in, Client *client)
160 if(draw_control.range_all == true)
163 static f32 added_frametime = 0;
164 static s16 added_frames = 0;
166 added_frametime += frametime_in;
169 // Actually this counter kind of sucks because frametime is busytime
170 static f32 counter = 0;
171 counter -= frametime_in;
177 /*dstream<<__FUNCTION_NAME
178 <<": Collected "<<added_frames<<" frames, total of "
179 <<added_frametime<<"s."<<std::endl;*/
181 /*dstream<<"draw_control.blocks_drawn="
182 <<draw_control.blocks_drawn
183 <<", draw_control.blocks_would_have_drawn="
184 <<draw_control.blocks_would_have_drawn
187 float range_min = g_settings.getS16("viewing_range_nodes_min");
188 float range_max = g_settings.getS16("viewing_range_nodes_max");
190 // Limit minimum to keep the feedback loop stable
194 draw_control.wanted_min_range = range_min;
195 //draw_control.wanted_max_blocks = (1.5*draw_control.blocks_drawn)+1;
196 draw_control.wanted_max_blocks = (1.5*draw_control.blocks_would_have_drawn)+1;
197 if(draw_control.wanted_max_blocks < 10)
198 draw_control.wanted_max_blocks = 10;
200 float block_draw_ratio = 1.0;
201 if(draw_control.blocks_would_have_drawn != 0)
203 block_draw_ratio = (float)draw_control.blocks_drawn
204 / (float)draw_control.blocks_would_have_drawn;
207 // Calculate the average frametime in the case that all wanted
208 // blocks had been drawn
209 f32 frametime = added_frametime / added_frames / block_draw_ratio;
211 added_frametime = 0.0;
214 float wanted_fps = g_settings.getFloat("wanted_fps");
215 float wanted_frametime = 1.0 / wanted_fps;
217 f32 wanted_frametime_change = wanted_frametime - frametime;
218 //dstream<<"wanted_frametime_change="<<wanted_frametime_change<<std::endl;
220 // If needed frametime change is small, just return
221 if(fabs(wanted_frametime_change) < wanted_frametime*0.4)
223 //dstream<<"ignoring small wanted_frametime_change"<<std::endl;
227 float range = draw_control.wanted_range;
228 float new_range = range;
230 static s16 range_old = 0;
231 static f32 frametime_old = 0;
233 float d_range = range - range_old;
234 f32 d_frametime = frametime - frametime_old;
235 // A sane default of 30ms per 50 nodes of range
236 static f32 time_per_range = 30. / 50;
239 time_per_range = d_frametime / d_range;
242 // The minimum allowed calculated frametime-range derivative:
243 // Practically this sets the maximum speed of changing the range.
244 // The lower this value, the higher the maximum changing speed.
245 // A low value here results in wobbly range (0.001)
246 // A high value here results in slow changing range (0.0025)
247 // SUGG: This could be dynamically adjusted so that when
248 // the camera is turning, this is lower
249 //float min_time_per_range = 0.0015;
250 float min_time_per_range = 0.0010;
251 //float min_time_per_range = 0.05 / range;
252 if(time_per_range < min_time_per_range)
254 time_per_range = min_time_per_range;
255 //dstream<<"time_per_range="<<time_per_range<<" (min)"<<std::endl;
259 //dstream<<"time_per_range="<<time_per_range<<std::endl;
262 f32 wanted_range_change = wanted_frametime_change / time_per_range;
263 // Dampen the change a bit to kill oscillations
264 //wanted_range_change *= 0.9;
265 //wanted_range_change *= 0.75;
266 wanted_range_change *= 0.5;
267 //dstream<<"wanted_range_change="<<wanted_range_change<<std::endl;
269 // If needed range change is very small, just return
270 if(fabs(wanted_range_change) < 0.001)
272 //dstream<<"ignoring small wanted_range_change"<<std::endl;
276 new_range += wanted_range_change;
278 //float new_range_unclamped = new_range;
279 if(new_range < range_min)
280 new_range = range_min;
281 if(new_range > range_max)
282 new_range = range_max;
284 /*dstream<<"new_range="<<new_range_unclamped
285 <<", clamped to "<<new_range<<std::endl;*/
287 draw_control.wanted_range = new_range;
289 range_old = new_range;
290 frametime_old = frametime;
296 void draw_hotbar(video::IVideoDriver *driver, gui::IGUIFont *font,
297 v2s32 centerlowerpos, s32 imgsize, s32 itemcount,
298 Inventory *inventory, s32 halfheartcount)
300 InventoryList *mainlist = inventory->getList("main");
303 dstream<<"WARNING: draw_hotbar(): mainlist == NULL"<<std::endl;
307 s32 padding = imgsize/12;
308 //s32 height = imgsize + padding*2;
309 s32 width = itemcount*(imgsize+padding*2);
311 // Position of upper left corner of bar
312 v2s32 pos = centerlowerpos - v2s32(width/2, imgsize+padding*2);
314 // Draw background color
315 /*core::rect<s32> barrect(0,0,width,height);
317 video::SColor bgcolor(255,128,128,128);
318 driver->draw2DRectangle(bgcolor, barrect, NULL);*/
320 core::rect<s32> imgrect(0,0,imgsize,imgsize);
322 for(s32 i=0; i<itemcount; i++)
324 InventoryItem *item = mainlist->getItem(i);
326 core::rect<s32> rect = imgrect + pos
327 + v2s32(padding+i*(imgsize+padding*2), padding);
329 if(g_selected_item == i)
331 driver->draw2DRectangle(video::SColor(255,255,0,0),
332 core::rect<s32>(rect.UpperLeftCorner - v2s32(1,1)*padding,
333 rect.LowerRightCorner + v2s32(1,1)*padding),
338 video::SColor bgcolor2(128,0,0,0);
339 driver->draw2DRectangle(bgcolor2, rect, NULL);
344 drawInventoryItem(driver, font, item, rect, NULL);
352 video::ITexture *heart_texture =
353 driver->getTexture(getTexturePath("heart.png").c_str());
354 v2s32 p = pos + v2s32(0, -20);
355 for(s32 i=0; i<halfheartcount/2; i++)
357 const video::SColor color(255,255,255,255);
358 const video::SColor colors[] = {color,color,color,color};
359 core::rect<s32> rect(0,0,16,16);
361 driver->draw2DImage(heart_texture, rect,
362 core::rect<s32>(core::position2d<s32>(0,0),
363 core::dimension2di(heart_texture->getOriginalSize())),
367 if(halfheartcount % 2 == 1)
369 const video::SColor color(255,255,255,255);
370 const video::SColor colors[] = {color,color,color,color};
371 core::rect<s32> rect(0,0,16/2,16);
373 core::dimension2di srcd(heart_texture->getOriginalSize());
375 driver->draw2DImage(heart_texture, rect,
376 core::rect<s32>(core::position2d<s32>(0,0), srcd),
384 Find what the player is pointing at
386 void getPointedNode(Client *client, v3f player_position,
387 v3f camera_direction, v3f camera_position,
388 bool &nodefound, core::line3d<f32> shootline,
389 v3s16 &nodepos, v3s16 &neighbourpos,
390 core::aabbox3d<f32> &nodehilightbox,
393 f32 mindistance = BS * 1001;
395 v3s16 pos_i = floatToInt(player_position, BS);
397 /*std::cout<<"pos_i=("<<pos_i.X<<","<<pos_i.Y<<","<<pos_i.Z<<")"
401 s16 ystart = pos_i.Y + 0 - (camera_direction.Y<0 ? a : 1);
402 s16 zstart = pos_i.Z - (camera_direction.Z<0 ? a : 1);
403 s16 xstart = pos_i.X - (camera_direction.X<0 ? a : 1);
404 s16 yend = pos_i.Y + 1 + (camera_direction.Y>0 ? a : 1);
405 s16 zend = pos_i.Z + (camera_direction.Z>0 ? a : 1);
406 s16 xend = pos_i.X + (camera_direction.X>0 ? a : 1);
408 for(s16 y = ystart; y <= yend; y++)
409 for(s16 z = zstart; z <= zend; z++)
410 for(s16 x = xstart; x <= xend; x++)
415 n = client->getNode(v3s16(x,y,z));
416 if(content_pointable(n.d) == false)
419 catch(InvalidPositionException &e)
425 v3f npf = intToFloat(np, BS);
430 v3s16(0,0,1), // back
432 v3s16(1,0,0), // right
433 v3s16(0,0,-1), // front
434 v3s16(0,-1,0), // bottom
435 v3s16(-1,0,0), // left
441 if(n.d == CONTENT_TORCH)
443 v3s16 dir = unpackDir(n.dir);
444 v3f dir_f = v3f(dir.X, dir.Y, dir.Z);
445 dir_f *= BS/2 - BS/6 - BS/20;
446 v3f cpf = npf + dir_f;
447 f32 distance = (cpf - camera_position).getLength();
449 core::aabbox3d<f32> box;
452 if(dir == v3s16(0,-1,0))
454 box = core::aabbox3d<f32>(
455 npf - v3f(BS/6, BS/2, BS/6),
456 npf + v3f(BS/6, -BS/2+BS/3*2, BS/6)
460 else if(dir == v3s16(0,1,0))
462 box = core::aabbox3d<f32>(
463 npf - v3f(BS/6, -BS/2+BS/3*2, BS/6),
464 npf + v3f(BS/6, BS/2, BS/6)
470 box = core::aabbox3d<f32>(
471 cpf - v3f(BS/6, BS/3, BS/6),
472 cpf + v3f(BS/6, BS/3, BS/6)
476 if(distance < mindistance)
478 if(box.intersectsWithLine(shootline))
483 mindistance = distance;
484 nodehilightbox = box;
488 else if(n.d == CONTENT_SIGN_WALL)
490 v3s16 dir = unpackDir(n.dir);
491 v3f dir_f = v3f(dir.X, dir.Y, dir.Z);
492 dir_f *= BS/2 - BS/6 - BS/20;
493 v3f cpf = npf + dir_f;
494 f32 distance = (cpf - camera_position).getLength();
498 v3f(BS*0.42,-BS*0.35,-BS*0.4),
499 v3f(BS*0.49, BS*0.35, BS*0.4),
502 for(s32 i=0; i<2; i++)
504 if(dir == v3s16(1,0,0))
505 vertices[i].rotateXZBy(0);
506 if(dir == v3s16(-1,0,0))
507 vertices[i].rotateXZBy(180);
508 if(dir == v3s16(0,0,1))
509 vertices[i].rotateXZBy(90);
510 if(dir == v3s16(0,0,-1))
511 vertices[i].rotateXZBy(-90);
512 if(dir == v3s16(0,-1,0))
513 vertices[i].rotateXYBy(-90);
514 if(dir == v3s16(0,1,0))
515 vertices[i].rotateXYBy(90);
520 core::aabbox3d<f32> box;
522 box = core::aabbox3d<f32>(vertices[0]);
523 box.addInternalPoint(vertices[1]);
525 if(distance < mindistance)
527 if(box.intersectsWithLine(shootline))
532 mindistance = distance;
533 nodehilightbox = box;
542 for(u16 i=0; i<6; i++)
544 v3f dir_f = v3f(dirs[i].X,
545 dirs[i].Y, dirs[i].Z);
546 v3f centerpoint = npf + dir_f * BS/2;
548 (centerpoint - camera_position).getLength();
550 if(distance < mindistance)
552 core::CMatrix4<f32> m;
553 m.buildRotateFromTo(v3f(0,0,1), dir_f);
555 // This is the back face
557 v3f(BS/2, BS/2, BS/2),
558 v3f(-BS/2, -BS/2, BS/2+d)
561 for(u16 j=0; j<2; j++)
563 m.rotateVect(corners[j]);
567 core::aabbox3d<f32> facebox(corners[0]);
568 facebox.addInternalPoint(corners[1]);
570 if(facebox.intersectsWithLine(shootline))
574 neighbourpos = np + dirs[i];
575 mindistance = distance;
577 //nodehilightbox = facebox;
579 const float d = 0.502;
580 core::aabbox3d<f32> nodebox
581 (-BS*d, -BS*d, -BS*d, BS*d, BS*d, BS*d);
582 v3f nodepos_f = intToFloat(nodepos, BS);
583 nodebox.MinEdge += nodepos_f;
584 nodebox.MaxEdge += nodepos_f;
585 nodehilightbox = nodebox;
587 } // if distance < mindistance
593 void update_skybox(video::IVideoDriver* driver,
594 scene::ISceneManager* smgr, scene::ISceneNode* &skybox,
602 /*// Disable skybox if FarMesh is enabled
603 if(g_settings.getBool("enable_farmesh"))
606 if(brightness >= 0.5)
608 skybox = smgr->addSkyBoxSceneNode(
609 driver->getTexture(getTexturePath("skybox2.png").c_str()),
610 driver->getTexture(getTexturePath("skybox3.png").c_str()),
611 driver->getTexture(getTexturePath("skybox1.png").c_str()),
612 driver->getTexture(getTexturePath("skybox1.png").c_str()),
613 driver->getTexture(getTexturePath("skybox1.png").c_str()),
614 driver->getTexture(getTexturePath("skybox1.png").c_str()));
616 else if(brightness >= 0.2)
618 skybox = smgr->addSkyBoxSceneNode(
619 driver->getTexture(getTexturePath("skybox2_dawn.png").c_str()),
620 driver->getTexture(getTexturePath("skybox3_dawn.png").c_str()),
621 driver->getTexture(getTexturePath("skybox1_dawn.png").c_str()),
622 driver->getTexture(getTexturePath("skybox1_dawn.png").c_str()),
623 driver->getTexture(getTexturePath("skybox1_dawn.png").c_str()),
624 driver->getTexture(getTexturePath("skybox1_dawn.png").c_str()));
628 skybox = smgr->addSkyBoxSceneNode(
629 driver->getTexture(getTexturePath("skybox2_night.png").c_str()),
630 driver->getTexture(getTexturePath("skybox3_night.png").c_str()),
631 driver->getTexture(getTexturePath("skybox1_night.png").c_str()),
632 driver->getTexture(getTexturePath("skybox1_night.png").c_str()),
633 driver->getTexture(getTexturePath("skybox1_night.png").c_str()),
634 driver->getTexture(getTexturePath("skybox1_night.png").c_str()));
642 IrrlichtDevice *device,
645 std::string playername,
646 std::string password,
649 std::wstring &error_message
652 video::IVideoDriver* driver = device->getVideoDriver();
653 scene::ISceneManager* smgr = device->getSceneManager();
655 v2u32 screensize(0,0);
656 v2u32 last_screensize(0,0);
657 screensize = driver->getScreenSize();
659 const s32 hotbar_itemcount = 8;
660 const s32 hotbar_imagesize = 36;
662 // The color of the sky
664 //video::SColor skycolor = video::SColor(255,140,186,250);
666 video::SColor bgcolor_bright = video::SColor(255,170,200,230);
669 Draw "Loading" screen
671 const wchar_t *loadingtext = L"Loading and connecting...";
672 u32 text_height = font->getDimension(loadingtext).Height;
673 core::vector2d<s32> center(screensize.X/2, screensize.Y/2);
674 core::vector2d<s32> textsize(300, text_height);
675 core::rect<s32> textrect(center - textsize/2, center + textsize/2);
677 gui::IGUIStaticText *gui_loadingtext = guienv->addStaticText(
678 loadingtext, textrect, false, false);
679 gui_loadingtext->setTextAlignment(gui::EGUIA_CENTER, gui::EGUIA_UPPERLEFT);
681 driver->beginScene(true, true, video::SColor(255,0,0,0));
688 SharedPtr will delete it when it goes out of scope.
690 SharedPtr<Server> server;
692 std::cout<<DTIME<<"Creating server"<<std::endl;
693 server = new Server(map_dir);
701 std::cout<<DTIME<<"Creating client"<<std::endl;
702 Client client(device, playername.c_str(), password, draw_control);
704 Address connect_address(0,0,0,0, port);
707 //connect_address.Resolve("localhost");
708 connect_address.setAddress(127,0,0,1);
710 connect_address.Resolve(address.c_str());
712 catch(ResolveError &e)
714 std::cout<<DTIME<<"Couldn't resolve address"<<std::endl;
716 error_message = L"Couldn't resolve address";
717 gui_loadingtext->remove();
722 Attempt to connect to the server
725 dstream<<DTIME<<"Connecting to server at ";
726 connect_address.print(&dstream);
728 client.connect(connect_address);
730 bool could_connect = false;
733 float time_counter = 0.0;
736 if(client.connectedAndInitialized())
738 could_connect = true;
741 if(client.accessDenied())
745 // Wait for 10 seconds
746 if(time_counter >= 10.0)
752 driver->beginScene(true, true, video::SColor(255,0,0,0));
756 // Update client and server
768 catch(con::PeerNotFoundException &e)
771 if(could_connect == false)
773 if(client.accessDenied())
775 error_message = L"Access denied. Reason: "
776 +client.accessDeniedReason();
777 std::cout<<DTIME<<wide_to_narrow(error_message)<<std::endl;
781 error_message = L"Connection timed out.";
782 std::cout<<DTIME<<"Timed out."<<std::endl;
784 gui_loadingtext->remove();
791 float old_brightness = 1.0;
792 scene::ISceneNode* skybox = NULL;
793 update_skybox(driver, smgr, skybox, 1.0);
796 Create the camera node
799 scene::ICameraSceneNode* camera = smgr->addCameraSceneNode(
801 v3f(BS*100, BS*2, BS*100), // Look from
802 v3f(BS*100+1, BS*2, BS*100), // Look to
808 error_message = L"Failed to create the camera node";
812 camera->setFOV(FOV_ANGLE);
814 // Just so big a value that everything rendered is visible
815 camera->setFarValue(100000*BS);
817 f32 camera_yaw = 0; // "right/left"
818 f32 camera_pitch = 0; // "up/down"
824 float cloud_height = BS*100;
825 Clouds *clouds = NULL;
826 if(g_settings.getBool("enable_clouds"))
828 clouds = new Clouds(smgr->getRootSceneNode(), smgr, -1,
829 cloud_height, time(0));
836 FarMesh *farmesh = NULL;
837 if(g_settings.getBool("enable_farmesh"))
839 farmesh = new FarMesh(smgr->getRootSceneNode(), smgr, -1, client.getMapSeed(), &client);
846 gui_loadingtext->remove();
852 // First line of debug text
853 gui::IGUIStaticText *guitext = guienv->addStaticText(
855 core::rect<s32>(5, 5, 795, 5+text_height),
857 // Second line of debug text
858 gui::IGUIStaticText *guitext2 = guienv->addStaticText(
860 core::rect<s32>(5, 5+(text_height+5)*1, 795, (5+text_height)*2),
863 // At the middle of the screen
864 // Object infos are shown in this
865 gui::IGUIStaticText *guitext_info = guienv->addStaticText(
867 core::rect<s32>(0,0,400,text_height+5) + v2s32(100,200),
871 gui::IGUIStaticText *guitext_chat = guienv->addStaticText(
873 core::rect<s32>(0,0,0,0),
874 //false, false); // Disable word wrap as of now
876 //guitext_chat->setBackgroundColor(video::SColor(96,0,0,0));
877 core::list<ChatLine> chat_lines;
879 /*GUIQuickInventory *quick_inventory = new GUIQuickInventory
880 (guienv, NULL, v2s32(10, 70), 5, &local_inventory);*/
881 /*GUIQuickInventory *quick_inventory = new GUIQuickInventory
882 (guienv, NULL, v2s32(0, 0), quickinv_itemcount, &local_inventory);*/
884 // Test the text input system
885 /*(new GUITextInputMenu(guienv, guiroot, -1, &g_menumgr,
887 /*GUIMessageMenu *menu =
888 new GUIMessageMenu(guienv, guiroot, -1,
894 (new GUIPauseMenu(guienv, guiroot, -1, g_gamecallback,
895 &g_menumgr))->drop();
898 /*guitext2->setVisible(true);
899 guitext_info->setVisible(true);
900 guitext_chat->setVisible(true);*/
902 //s32 guitext_chat_pad_bottom = 70;
905 Some statistics are collected in these
908 u32 beginscenetime = 0;
910 u32 endscenetime = 0;
913 //throw con::PeerNotFoundException("lol");
915 core::list<float> frametime_log;
917 float damage_flash_timer = 0;
918 s16 farmesh_range = 20*MAP_BLOCKSIZE;
920 bool invert_mouse = g_settings.getBool("invert_mouse");
926 bool first_loop_after_window_activation = true;
928 // TODO: Convert the static interval timers to these
929 // Interval limiter for profiler
930 IntervalLimiter m_profiler_interval;
932 // Time is in milliseconds
933 // NOTE: getRealTime() causes strange problems in wine (imprecision?)
934 // NOTE: So we have to use getTime() and call run()s between them
935 u32 lasttime = device->getTimer()->getTime();
937 while(device->run() && kill == false)
939 if(g_gamecallback->disconnect_requested)
941 g_gamecallback->disconnect_requested = false;
945 if(g_gamecallback->changepassword_requested)
947 (new GUIPasswordChange(guienv, guiroot, -1,
948 &g_menumgr, &client))->drop();
949 g_gamecallback->changepassword_requested = false;
953 Process TextureSource's queue
955 ((TextureSource*)g_texturesource)->processQueue();
960 last_screensize = screensize;
961 screensize = driver->getScreenSize();
962 v2s32 displaycenter(screensize.X/2,screensize.Y/2);
963 //bool screensize_changed = screensize != last_screensize;
965 // Hilight boxes collected during the loop and displayed
966 core::list< core::aabbox3d<f32> > hilightboxes;
969 std::wstring infotext;
971 // When screen size changes, update positions and sizes of stuff
972 /*if(screensize_changed)
974 v2s32 pos(displaycenter.X-((quickinv_itemcount-1)*quickinv_spacing+quickinv_size)/2, screensize.Y-quickinv_spacing);
975 quick_inventory->updatePosition(pos);
978 //TimeTaker //timer1("//timer1");
980 // Time of frame without fps limit
984 // not using getRealTime is necessary for wine
985 u32 time = device->getTimer()->getTime();
987 busytime_u32 = time - lasttime;
990 busytime = busytime_u32 / 1000.0;
993 //std::cout<<"busytime_u32="<<busytime_u32<<std::endl;
995 // Necessary for device->getTimer()->getTime()
1002 updateViewingRange(busytime, &client);
1009 float fps_max = g_settings.getFloat("fps_max");
1010 u32 frametime_min = 1000./fps_max;
1012 if(busytime_u32 < frametime_min)
1014 u32 sleeptime = frametime_min - busytime_u32;
1015 device->sleep(sleeptime);
1019 // Necessary for device->getTimer()->getTime()
1023 Time difference calculation
1025 f32 dtime; // in seconds
1027 u32 time = device->getTimer()->getTime();
1029 dtime = (time - lasttime) / 1000.0;
1035 Log frametime for visualization
1037 frametime_log.push_back(dtime);
1038 if(frametime_log.size() > 100)
1040 core::list<float>::Iterator i = frametime_log.begin();
1041 frametime_log.erase(i);
1045 Visualize frametime in terminal
1047 /*for(u32 i=0; i<dtime*400; i++)
1049 std::cout<<std::endl;*/
1052 Time average and jitter calculation
1055 static f32 dtime_avg1 = 0.0;
1056 dtime_avg1 = dtime_avg1 * 0.98 + dtime * 0.02;
1057 f32 dtime_jitter1 = dtime - dtime_avg1;
1059 static f32 dtime_jitter1_max_sample = 0.0;
1060 static f32 dtime_jitter1_max_fraction = 0.0;
1062 static f32 jitter1_max = 0.0;
1063 static f32 counter = 0.0;
1064 if(dtime_jitter1 > jitter1_max)
1065 jitter1_max = dtime_jitter1;
1070 dtime_jitter1_max_sample = jitter1_max;
1071 dtime_jitter1_max_fraction
1072 = dtime_jitter1_max_sample / (dtime_avg1+0.001);
1078 Busytime average and jitter calculation
1081 static f32 busytime_avg1 = 0.0;
1082 busytime_avg1 = busytime_avg1 * 0.98 + busytime * 0.02;
1083 f32 busytime_jitter1 = busytime - busytime_avg1;
1085 static f32 busytime_jitter1_max_sample = 0.0;
1086 static f32 busytime_jitter1_min_sample = 0.0;
1088 static f32 jitter1_max = 0.0;
1089 static f32 jitter1_min = 0.0;
1090 static f32 counter = 0.0;
1091 if(busytime_jitter1 > jitter1_max)
1092 jitter1_max = busytime_jitter1;
1093 if(busytime_jitter1 < jitter1_min)
1094 jitter1_min = busytime_jitter1;
1098 busytime_jitter1_max_sample = jitter1_max;
1099 busytime_jitter1_min_sample = jitter1_min;
1106 Debug info for client
1109 static float counter = 0.0;
1114 client.printDebugInfo(std::cout);
1121 float profiler_print_interval =
1122 g_settings.getFloat("profiler_print_interval");
1123 if(profiler_print_interval != 0)
1125 if(m_profiler_interval.step(0.030, profiler_print_interval))
1127 dstream<<"Profiler:"<<std::endl;
1128 g_profiler.print(dstream);
1134 Direct handling of user input
1137 // Reset input if window not active or some menu is active
1138 if(device->isWindowActive() == false || noMenuActive() == false)
1143 // Input handler step() (used by the random input generator)
1147 Launch menus according to keys
1149 if(input->wasKeyDown(getKeySetting("keymap_inventory")))
1151 dstream<<DTIME<<"the_game: "
1152 <<"Launching inventory"<<std::endl;
1154 GUIInventoryMenu *menu =
1155 new GUIInventoryMenu(guienv, guiroot, -1,
1156 &g_menumgr, v2s16(8,7),
1157 client.getInventoryContext(),
1160 core::array<GUIInventoryMenu::DrawSpec> draw_spec;
1161 draw_spec.push_back(GUIInventoryMenu::DrawSpec(
1162 "list", "current_player", "main",
1163 v2s32(0, 3), v2s32(8, 4)));
1164 draw_spec.push_back(GUIInventoryMenu::DrawSpec(
1165 "list", "current_player", "craft",
1166 v2s32(3, 0), v2s32(3, 3)));
1167 draw_spec.push_back(GUIInventoryMenu::DrawSpec(
1168 "list", "current_player", "craftresult",
1169 v2s32(7, 1), v2s32(1, 1)));
1171 menu->setDrawSpec(draw_spec);
1175 else if(input->wasKeyDown(KEY_ESCAPE))
1177 dstream<<DTIME<<"the_game: "
1178 <<"Launching pause menu"<<std::endl;
1179 // It will delete itself by itself
1180 (new GUIPauseMenu(guienv, guiroot, -1, g_gamecallback,
1181 &g_menumgr))->drop();
1183 // Move mouse cursor on top of the disconnect button
1184 input->setMousePos(displaycenter.X, displaycenter.Y+25);
1186 else if(input->wasKeyDown(getKeySetting("keymap_chat")))
1188 TextDest *dest = new TextDestChat(&client);
1190 (new GUITextInputMenu(guienv, guiroot, -1,
1194 else if(input->wasKeyDown(getKeySetting("keymap_freemove")))
1196 if(g_settings.getBool("free_move"))
1198 g_settings.set("free_move","false");
1199 chat_lines.push_back(ChatLine(L"free_move disabled"));
1203 g_settings.set("free_move","true");
1204 chat_lines.push_back(ChatLine(L"free_move enabled"));
1207 else if(input->wasKeyDown(getKeySetting("keymap_fastmove")))
1209 if(g_settings.getBool("fast_move"))
1211 g_settings.set("fast_move","false");
1212 chat_lines.push_back(ChatLine(L"fast_move disabled"));
1216 g_settings.set("fast_move","true");
1217 chat_lines.push_back(ChatLine(L"fast_move enabled"));
1221 // Item selection with mouse wheel
1223 s32 wheel = input->getMouseWheel();
1224 u16 max_item = MYMIN(PLAYER_INVENTORY_SIZE-1,
1225 hotbar_itemcount-1);
1229 if(g_selected_item < max_item)
1232 g_selected_item = 0;
1236 if(g_selected_item > 0)
1239 g_selected_item = max_item;
1244 for(u16 i=0; i<10; i++)
1246 s32 keycode = irr::KEY_KEY_1 + i;
1248 keycode = irr::KEY_KEY_0;
1249 if(input->wasKeyDown((irr::EKEY_CODE)keycode))
1251 if(i < PLAYER_INVENTORY_SIZE && i < hotbar_itemcount)
1253 g_selected_item = i;
1255 dstream<<DTIME<<"Selected item: "
1256 <<g_selected_item<<std::endl;
1261 // Viewing range selection
1262 if(input->wasKeyDown(getKeySetting("keymap_rangeselect")))
1264 if(draw_control.range_all)
1266 draw_control.range_all = false;
1267 dstream<<DTIME<<"Disabled full viewing range"<<std::endl;
1271 draw_control.range_all = true;
1272 dstream<<DTIME<<"Enabled full viewing range"<<std::endl;
1276 // Print debug stacks
1277 if(input->wasKeyDown(getKeySetting("keymap_print_debug_stacks")))
1279 dstream<<"-----------------------------------------"
1281 dstream<<DTIME<<"Printing debug stacks:"<<std::endl;
1282 dstream<<"-----------------------------------------"
1284 debug_stacks_print();
1288 Player speed control
1289 TODO: Cache the keycodes from getKeySetting
1302 PlayerControl control(
1303 input->isKeyDown(getKeySetting("keymap_forward")),
1304 input->isKeyDown(getKeySetting("keymap_backward")),
1305 input->isKeyDown(getKeySetting("keymap_left")),
1306 input->isKeyDown(getKeySetting("keymap_right")),
1307 input->isKeyDown(getKeySetting("keymap_jump")),
1308 input->isKeyDown(getKeySetting("keymap_special1")),
1309 input->isKeyDown(getKeySetting("keymap_sneak")),
1313 client.setPlayerControl(control);
1322 //TimeTaker timer("server->step(dtime)");
1323 server->step(dtime);
1331 //TimeTaker timer("client.step(dtime)");
1333 //client.step(dtime_avg1);
1336 // Read client events
1339 ClientEvent event = client.getClientEvent();
1340 if(event.type == CE_NONE)
1344 else if(event.type == CE_PLAYER_DAMAGE)
1346 //u16 damage = event.player_damage.amount;
1347 //dstream<<"Player damage: "<<damage<<std::endl;
1348 damage_flash_timer = 0.05;
1350 else if(event.type == CE_PLAYER_FORCE_MOVE)
1352 camera_yaw = event.player_force_move.yaw;
1353 camera_pitch = event.player_force_move.pitch;
1357 // Get player position
1358 v3f player_position = client.getPlayerPosition();
1360 //TimeTaker //timer2("//timer2");
1363 Mouse and camera control
1366 if((device->isWindowActive() && noMenuActive()) || random_input)
1369 device->getCursorControl()->setVisible(false);
1371 if(first_loop_after_window_activation){
1372 //std::cout<<"window active, first loop"<<std::endl;
1373 first_loop_after_window_activation = false;
1376 s32 dx = input->getMousePos().X - displaycenter.X;
1377 s32 dy = input->getMousePos().Y - displaycenter.Y;
1380 //std::cout<<"window active, pos difference "<<dx<<","<<dy<<std::endl;
1382 /*const float keyspeed = 500;
1383 if(input->isKeyDown(irr::KEY_UP))
1384 dy -= dtime * keyspeed;
1385 if(input->isKeyDown(irr::KEY_DOWN))
1386 dy += dtime * keyspeed;
1387 if(input->isKeyDown(irr::KEY_LEFT))
1388 dx -= dtime * keyspeed;
1389 if(input->isKeyDown(irr::KEY_RIGHT))
1390 dx += dtime * keyspeed;*/
1392 camera_yaw -= dx*0.2;
1393 camera_pitch += dy*0.2;
1394 if(camera_pitch < -89.5) camera_pitch = -89.5;
1395 if(camera_pitch > 89.5) camera_pitch = 89.5;
1397 input->setMousePos(displaycenter.X, displaycenter.Y);
1400 device->getCursorControl()->setVisible(true);
1402 //std::cout<<"window inactive"<<std::endl;
1403 first_loop_after_window_activation = true;
1406 camera_yaw = wrapDegrees(camera_yaw);
1407 camera_pitch = wrapDegrees(camera_pitch);
1409 v3f camera_direction = v3f(0,0,1);
1410 camera_direction.rotateYZBy(camera_pitch);
1411 camera_direction.rotateXZBy(camera_yaw);
1413 // This is at the height of the eyes of the current figure
1414 //v3f camera_position = player_position + v3f(0, BS+BS/2, 0);
1415 // This is more like in minecraft
1416 v3f camera_position = player_position + v3f(0, BS+BS*0.625, 0);
1418 camera->setPosition(camera_position);
1419 // *100.0 helps in large map coordinates
1420 camera->setTarget(camera_position + camera_direction * 100.0);
1422 if(FIELD_OF_VIEW_TEST){
1423 client.updateCamera(v3f(0,0,0), v3f(0,0,1));
1426 //TimeTaker timer("client.updateCamera");
1427 client.updateCamera(camera_position, camera_direction);
1431 //TimeTaker //timer3("//timer3");
1434 Calculate what block is the crosshair pointing to
1437 //u32 t1 = device->getTimer()->getRealTime();
1439 //f32 d = 4; // max. distance
1440 f32 d = 4; // max. distance
1441 core::line3d<f32> shootline(camera_position,
1442 camera_position + camera_direction * BS * (d+1));
1444 MapBlockObject *selected_object = client.getSelectedObject
1445 (d*BS, camera_position, shootline);
1447 ClientActiveObject *selected_active_object
1448 = client.getSelectedActiveObject
1449 (d*BS, camera_position, shootline);
1451 if(selected_object != NULL)
1453 //dstream<<"Client returned selected_object != NULL"<<std::endl;
1455 core::aabbox3d<f32> box_on_map
1456 = selected_object->getSelectionBoxOnMap();
1458 hilightboxes.push_back(box_on_map);
1460 infotext = narrow_to_wide(selected_object->infoText());
1462 if(input->getLeftClicked())
1464 std::cout<<DTIME<<"Left-clicked object"<<std::endl;
1465 client.clickObject(0, selected_object->getBlock()->getPos(),
1466 selected_object->getId(), g_selected_item);
1468 else if(input->getRightClicked())
1470 std::cout<<DTIME<<"Right-clicked object"<<std::endl;
1472 Check if we want to modify the object ourselves
1474 if(selected_object->getTypeId() == MAPBLOCKOBJECT_TYPE_SIGN)
1476 dstream<<"Sign object right-clicked"<<std::endl;
1478 if(random_input == false)
1480 // Get a new text for it
1482 TextDest *dest = new TextDestSign(
1483 selected_object->getBlock()->getPos(),
1484 selected_object->getId(),
1487 SignObject *sign_object = (SignObject*)selected_object;
1489 std::wstring wtext =
1490 narrow_to_wide(sign_object->getText());
1492 (new GUITextInputMenu(guienv, guiroot, -1,
1498 Otherwise pass the event to the server as-is
1502 client.clickObject(1, selected_object->getBlock()->getPos(),
1503 selected_object->getId(), g_selected_item);
1507 else if(selected_active_object != NULL)
1509 //dstream<<"Client returned selected_active_object != NULL"<<std::endl;
1511 core::aabbox3d<f32> *selection_box
1512 = selected_active_object->getSelectionBox();
1513 // Box should exist because object was returned in the
1515 assert(selection_box);
1517 v3f pos = selected_active_object->getPosition();
1519 core::aabbox3d<f32> box_on_map(
1520 selection_box->MinEdge + pos,
1521 selection_box->MaxEdge + pos
1524 hilightboxes.push_back(box_on_map);
1526 //infotext = narrow_to_wide("A ClientActiveObject");
1527 infotext = narrow_to_wide(selected_active_object->infoText());
1529 if(input->getLeftClicked())
1531 std::cout<<DTIME<<"Left-clicked object"<<std::endl;
1532 client.clickActiveObject(0,
1533 selected_active_object->getId(), g_selected_item);
1535 else if(input->getRightClicked())
1537 std::cout<<DTIME<<"Right-clicked object"<<std::endl;
1540 else // selected_object == NULL
1544 Find out which node we are pointing at
1547 bool nodefound = false;
1550 core::aabbox3d<f32> nodehilightbox;
1552 getPointedNode(&client, player_position,
1553 camera_direction, camera_position,
1554 nodefound, shootline,
1555 nodepos, neighbourpos,
1558 static float nodig_delay_counter = 0.0;
1562 static v3s16 nodepos_old(-32768,-32768,-32768);
1564 static float dig_time = 0.0;
1565 static u16 dig_index = 0;
1571 hilightboxes.push_back(nodehilightbox);
1574 Check information text of node
1577 NodeMetadata *meta = client.getNodeMetadata(nodepos);
1580 infotext = narrow_to_wide(meta->infoText());
1583 //MapNode node = client.getNode(nodepos);
1589 if(input->getLeftReleased())
1591 client.clearTempMod(nodepos);
1595 if(nodig_delay_counter > 0.0)
1597 nodig_delay_counter -= dtime;
1601 if(nodepos != nodepos_old)
1603 std::cout<<DTIME<<"Pointing at ("<<nodepos.X<<","
1604 <<nodepos.Y<<","<<nodepos.Z<<")"<<std::endl;
1606 if(nodepos_old != v3s16(-32768,-32768,-32768))
1608 client.clearTempMod(nodepos_old);
1613 if(input->getLeftClicked() ||
1614 (input->getLeftState() && nodepos != nodepos_old))
1616 dstream<<DTIME<<"Started digging"<<std::endl;
1617 client.groundAction(0, nodepos, neighbourpos, g_selected_item);
1619 if(input->getLeftClicked())
1621 client.setTempMod(nodepos, NodeMod(NODEMOD_CRACK, 0));
1623 if(input->getLeftState())
1625 MapNode n = client.getNode(nodepos);
1627 // Get tool name. Default is "" = bare hands
1628 std::string toolname = "";
1629 InventoryList *mlist = local_inventory.getList("main");
1632 InventoryItem *item = mlist->getItem(g_selected_item);
1633 if(item && (std::string)item->getName() == "ToolItem")
1635 ToolItem *titem = (ToolItem*)item;
1636 toolname = titem->getToolName();
1640 // Get digging properties for material and tool
1642 DiggingProperties prop =
1643 getDiggingProperties(material, toolname);
1645 float dig_time_complete = 0.0;
1647 if(prop.diggable == false)
1649 /*dstream<<"Material "<<(int)material
1650 <<" not diggable with \""
1651 <<toolname<<"\""<<std::endl;*/
1652 // I guess nobody will wait for this long
1653 dig_time_complete = 10000000.0;
1657 dig_time_complete = prop.time;
1660 if(dig_time_complete >= 0.001)
1662 dig_index = (u16)((float)CRACK_ANIMATION_LENGTH
1663 * dig_time/dig_time_complete);
1665 // This is for torches
1668 dig_index = CRACK_ANIMATION_LENGTH;
1671 if(dig_index < CRACK_ANIMATION_LENGTH)
1673 //TimeTaker timer("client.setTempMod");
1674 //dstream<<"dig_index="<<dig_index<<std::endl;
1675 client.setTempMod(nodepos, NodeMod(NODEMOD_CRACK, dig_index));
1679 dstream<<DTIME<<"Digging completed"<<std::endl;
1680 client.groundAction(3, nodepos, neighbourpos, g_selected_item);
1681 client.clearTempMod(nodepos);
1682 client.removeNode(nodepos);
1686 nodig_delay_counter = dig_time_complete
1687 / (float)CRACK_ANIMATION_LENGTH;
1689 // We don't want a corresponding delay to
1690 // very time consuming nodes
1691 if(nodig_delay_counter > 0.5)
1693 nodig_delay_counter = 0.5;
1695 // We want a slight delay to very little
1696 // time consuming nodes
1697 float mindelay = 0.15;
1698 if(nodig_delay_counter < mindelay)
1700 nodig_delay_counter = mindelay;
1708 if(input->getRightClicked())
1710 std::cout<<DTIME<<"Ground right-clicked"<<std::endl;
1712 // If metadata provides an inventory view, activate it
1713 if(meta && meta->getInventoryDrawSpecString() != "" && !random_input)
1715 dstream<<DTIME<<"Launching custom inventory view"<<std::endl;
1717 Construct the unique identification string of the node
1719 std::string current_name;
1720 current_name += "nodemeta:";
1721 current_name += itos(nodepos.X);
1722 current_name += ",";
1723 current_name += itos(nodepos.Y);
1724 current_name += ",";
1725 current_name += itos(nodepos.Z);
1731 core::array<GUIInventoryMenu::DrawSpec> draw_spec;
1733 GUIInventoryMenu::makeDrawSpecArrayFromString(
1735 meta->getInventoryDrawSpecString(),
1738 GUIInventoryMenu *menu =
1739 new GUIInventoryMenu(guienv, guiroot, -1,
1740 &g_menumgr, invsize,
1741 client.getInventoryContext(),
1743 menu->setDrawSpec(draw_spec);
1746 else if(meta && meta->typeId() == CONTENT_SIGN_WALL && !random_input)
1748 dstream<<"Sign node right-clicked"<<std::endl;
1750 SignNodeMetadata *signmeta = (SignNodeMetadata*)meta;
1752 // Get a new text for it
1754 TextDest *dest = new TextDestSignNode(nodepos, &client);
1756 std::wstring wtext =
1757 narrow_to_wide(signmeta->getText());
1759 (new GUITextInputMenu(guienv, guiroot, -1,
1765 client.groundAction(1, nodepos, neighbourpos, g_selected_item);
1769 nodepos_old = nodepos;
1774 } // selected_object == NULL
1776 input->resetLeftClicked();
1777 input->resetRightClicked();
1779 if(input->getLeftReleased())
1781 std::cout<<DTIME<<"Left button released (stopped digging)"
1783 client.groundAction(2, v3s16(0,0,0), v3s16(0,0,0), 0);
1785 if(input->getRightReleased())
1787 //std::cout<<DTIME<<"Right released"<<std::endl;
1791 input->resetLeftReleased();
1792 input->resetRightReleased();
1795 Calculate stuff for drawing
1798 camera->setAspectRatio((f32)screensize.X / (f32)screensize.Y);
1800 u32 daynight_ratio = client.getDayNightRatio();
1801 u8 l = decode_light((daynight_ratio * LIGHT_SUN) / 1000);
1802 video::SColor bgcolor = video::SColor(
1804 bgcolor_bright.getRed() * l / 255,
1805 bgcolor_bright.getGreen() * l / 255,
1806 bgcolor_bright.getBlue() * l / 255);
1807 /*skycolor.getRed() * l / 255,
1808 skycolor.getGreen() * l / 255,
1809 skycolor.getBlue() * l / 255);*/
1811 float brightness = (float)l/255.0;
1816 if(fabs(brightness - old_brightness) > 0.01)
1817 update_skybox(driver, smgr, skybox, brightness);
1824 clouds->step(dtime);
1825 clouds->update(v2f(player_position.X, player_position.Z),
1826 0.05+brightness*0.95);
1834 farmesh_range = draw_control.wanted_range * 10;
1835 if(draw_control.range_all && farmesh_range < 500)
1836 farmesh_range = 500;
1837 if(farmesh_range > 1000)
1838 farmesh_range = 1000;
1840 farmesh->step(dtime);
1841 farmesh->update(v2f(player_position.X, player_position.Z),
1842 0.05+brightness*0.95, farmesh_range);
1845 // Store brightness value
1846 old_brightness = brightness;
1852 if(g_settings.getBool("enable_fog") == true)
1857 range = BS*farmesh_range;
1861 range = draw_control.wanted_range*BS + MAP_BLOCKSIZE*BS*1.5;
1862 if(draw_control.range_all)
1865 range = range * 0.5 + 25*BS;
1870 video::EFT_FOG_LINEAR,
1882 video::EFT_FOG_LINEAR,
1893 Update gui stuff (0ms)
1896 //TimeTaker guiupdatetimer("Gui updating");
1899 static float drawtime_avg = 0;
1900 drawtime_avg = drawtime_avg * 0.95 + (float)drawtime*0.05;
1901 static float beginscenetime_avg = 0;
1902 beginscenetime_avg = beginscenetime_avg * 0.95 + (float)beginscenetime*0.05;
1903 static float scenetime_avg = 0;
1904 scenetime_avg = scenetime_avg * 0.95 + (float)scenetime*0.05;
1905 static float endscenetime_avg = 0;
1906 endscenetime_avg = endscenetime_avg * 0.95 + (float)endscenetime*0.05;
1909 snprintf(temptext, 300, "Minetest-c55 %s ("
1912 " drawtime=%.0f, beginscenetime=%.0f"
1913 ", scenetime=%.0f, endscenetime=%.0f",
1915 draw_control.range_all,
1922 guitext->setText(narrow_to_wide(temptext).c_str());
1927 snprintf(temptext, 300,
1928 "(% .1f, % .1f, % .1f)"
1929 " (% .3f < btime_jitter < % .3f"
1930 ", dtime_jitter = % .1f %%"
1931 ", v_range = %.1f)",
1932 player_position.X/BS,
1933 player_position.Y/BS,
1934 player_position.Z/BS,
1935 busytime_jitter1_min_sample,
1936 busytime_jitter1_max_sample,
1937 dtime_jitter1_max_fraction * 100.0,
1938 draw_control.wanted_range
1941 guitext2->setText(narrow_to_wide(temptext).c_str());
1945 guitext_info->setText(infotext.c_str());
1949 Get chat messages from client
1953 std::wstring message;
1954 while(client.getChatMessage(message))
1956 chat_lines.push_back(ChatLine(message));
1957 /*if(chat_lines.size() > 6)
1959 core::list<ChatLine>::Iterator
1960 i = chat_lines.begin();
1961 chat_lines.erase(i);
1964 // Append them to form the whole static text and throw
1965 // it to the gui element
1967 // This will correspond to the line number counted from
1968 // top to bottom, from size-1 to 0
1969 s16 line_number = chat_lines.size();
1970 // Count of messages to be removed from the top
1971 u16 to_be_removed_count = 0;
1972 for(core::list<ChatLine>::Iterator
1973 i = chat_lines.begin();
1974 i != chat_lines.end(); i++)
1976 // After this, line number is valid for this loop
1981 This results in a maximum age of 60*6 to the
1982 lowermost line and a maximum of 6 lines
1984 float allowed_age = (6-line_number) * 60.0;
1986 if((*i).age > allowed_age)
1988 to_be_removed_count++;
1991 whole += (*i).text + L'\n';
1993 for(u16 i=0; i<to_be_removed_count; i++)
1995 core::list<ChatLine>::Iterator
1996 it = chat_lines.begin();
1997 chat_lines.erase(it);
1999 guitext_chat->setText(whole.c_str());
2001 // Update gui element size and position
2003 /*core::rect<s32> rect(
2005 screensize.Y - guitext_chat_pad_bottom
2006 - text_height*chat_lines.size(),
2008 screensize.Y - guitext_chat_pad_bottom
2010 core::rect<s32> rect(
2014 50 + guitext_chat->getTextHeight()
2017 guitext_chat->setRelativePosition(rect);
2019 if(chat_lines.size() == 0)
2020 guitext_chat->setVisible(false);
2022 guitext_chat->setVisible(true);
2029 static u16 old_selected_item = 65535;
2030 if(client.getLocalInventoryUpdated()
2031 || g_selected_item != old_selected_item)
2033 old_selected_item = g_selected_item;
2034 //std::cout<<"Updating local inventory"<<std::endl;
2035 client.getLocalInventory(local_inventory);
2039 Send actions returned by the inventory menu
2041 while(inventory_action_queue.size() != 0)
2043 InventoryAction *a = inventory_action_queue.pop_front();
2045 client.sendInventoryAction(a);
2054 TimeTaker drawtimer("Drawing");
2058 TimeTaker timer("beginScene");
2059 driver->beginScene(true, true, bgcolor);
2060 //driver->beginScene(false, true, bgcolor);
2061 beginscenetime = timer.stop(true);
2066 //std::cout<<DTIME<<"smgr->drawAll()"<<std::endl;
2069 TimeTaker timer("smgr");
2071 scenetime = timer.stop(true);
2075 //TimeTaker timer9("auxiliary drawings");
2079 //TimeTaker //timer10("//timer10");
2085 driver->setMaterial(m);
2087 driver->setTransform(video::ETS_WORLD, core::IdentityMatrix);
2089 for(core::list< core::aabbox3d<f32> >::Iterator i=hilightboxes.begin();
2090 i != hilightboxes.end(); i++)
2092 /*std::cout<<"hilightbox min="
2093 <<"("<<i->MinEdge.X<<","<<i->MinEdge.Y<<","<<i->MinEdge.Z<<")"
2095 <<"("<<i->MaxEdge.X<<","<<i->MaxEdge.Y<<","<<i->MaxEdge.Z<<")"
2097 driver->draw3DBox(*i, video::SColor(255,0,0,0));
2103 if(g_settings.getBool("frametime_graph") == true)
2106 for(core::list<float>::Iterator
2107 i = frametime_log.begin();
2108 i != frametime_log.end();
2111 driver->draw2DLine(v2s32(x,50),
2112 v2s32(x,50+(*i)*1000),
2113 video::SColor(255,255,255,255));
2121 driver->draw2DLine(displaycenter - core::vector2d<s32>(10,0),
2122 displaycenter + core::vector2d<s32>(10,0),
2123 video::SColor(255,255,255,255));
2124 driver->draw2DLine(displaycenter - core::vector2d<s32>(0,10),
2125 displaycenter + core::vector2d<s32>(0,10),
2126 video::SColor(255,255,255,255));
2131 //TimeTaker //timer11("//timer11");
2143 draw_hotbar(driver, font, v2s32(displaycenter.X, screensize.Y),
2144 hotbar_imagesize, hotbar_itemcount, &local_inventory,
2151 if(damage_flash_timer > 0.0)
2153 damage_flash_timer -= dtime;
2155 video::SColor color(128,255,0,0);
2156 driver->draw2DRectangle(color,
2157 core::rect<s32>(0,0,screensize.X,screensize.Y),
2165 TimeTaker timer("endScene");
2167 endscenetime = timer.stop(true);
2170 drawtime = drawtimer.stop(true);
2176 static s16 lastFPS = 0;
2177 //u16 fps = driver->getFPS();
2178 u16 fps = (1.0/dtime_avg1);
2182 core::stringw str = L"Minetest [";
2183 str += driver->getName();
2187 device->setWindowCaption(str.c_str());
2199 Draw a "shutting down" screen, which will be shown while the map
2200 generator and other stuff quits
2203 const wchar_t *shuttingdowntext = L"Shutting down stuff...";
2204 gui::IGUIStaticText *gui_shuttingdowntext = guienv->addStaticText(
2205 shuttingdowntext, textrect, false, false);
2206 gui_shuttingdowntext->setTextAlignment(gui::EGUIA_CENTER,
2207 gui::EGUIA_UPPERLEFT);
2208 driver->beginScene(true, true, video::SColor(255,0,0,0));
2211 gui_shuttingdowntext->remove();