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.
21 #include "common_irrlicht.h"
22 #include <IGUICheckBox.h>
23 #include <IGUIEditBox.h>
24 #include <IGUIButton.h>
25 #include <IGUIStaticText.h>
29 #include "guiPauseMenu.h"
30 #include "guiPasswordChange.h"
31 #include "guiInventoryMenu.h"
32 #include "guiTextInputMenu.h"
33 #include "materials.h"
41 #include "mainmenumanager.h"
44 TODO: Move content-aware stuff to separate file by adding properties
45 and virtual interfaces
47 #include "content_mapnode.h"
48 #include "content_nodemeta.h"
51 Setting this to 1 enables a special camera mode that forces
52 the renderers to think that the camera statically points from
53 the starting place to a static direction.
55 This allows one to move around with the player and see what
56 is actually drawn behind solid things and behind the player.
58 #define FIELD_OF_VIEW_TEST 0
68 ChatLine(const std::wstring &a_text):
81 // Inventory actions from the menu are buffered here before sending
82 Queue<InventoryAction*> inventory_action_queue;
83 // This is a copy of the inventory that the client's environment has
84 Inventory local_inventory;
86 u16 g_selected_item = 0;
92 struct TextDestChat : public TextDest
94 TextDestChat(Client *client)
98 void gotText(std::wstring text)
100 // Discard empty line
105 m_client->sendChatMessage(text);
107 m_client->addChatMessage(text);
113 struct TextDestSignNode : public TextDest
115 TextDestSignNode(v3s16 p, Client *client)
120 void gotText(std::wstring text)
122 std::string ntext = wide_to_narrow(text);
123 dstream<<"Changing text of a sign node: "
125 m_client->sendSignNodeText(m_p, ntext);
135 void draw_hotbar(video::IVideoDriver *driver, gui::IGUIFont *font,
136 v2s32 centerlowerpos, s32 imgsize, s32 itemcount,
137 Inventory *inventory, s32 halfheartcount)
139 InventoryList *mainlist = inventory->getList("main");
142 dstream<<"WARNING: draw_hotbar(): mainlist == NULL"<<std::endl;
146 s32 padding = imgsize/12;
147 //s32 height = imgsize + padding*2;
148 s32 width = itemcount*(imgsize+padding*2);
150 // Position of upper left corner of bar
151 v2s32 pos = centerlowerpos - v2s32(width/2, imgsize+padding*2);
153 // Draw background color
154 /*core::rect<s32> barrect(0,0,width,height);
156 video::SColor bgcolor(255,128,128,128);
157 driver->draw2DRectangle(bgcolor, barrect, NULL);*/
159 core::rect<s32> imgrect(0,0,imgsize,imgsize);
161 for(s32 i=0; i<itemcount; i++)
163 InventoryItem *item = mainlist->getItem(i);
165 core::rect<s32> rect = imgrect + pos
166 + v2s32(padding+i*(imgsize+padding*2), padding);
168 if(g_selected_item == i)
170 video::SColor c_outside(255,255,0,0);
171 //video::SColor c_outside(255,0,0,0);
172 //video::SColor c_inside(255,192,192,192);
173 s32 x1 = rect.UpperLeftCorner.X;
174 s32 y1 = rect.UpperLeftCorner.Y;
175 s32 x2 = rect.LowerRightCorner.X;
176 s32 y2 = rect.LowerRightCorner.Y;
177 // Black base borders
178 driver->draw2DRectangle(c_outside,
180 v2s32(x1 - padding, y1 - padding),
181 v2s32(x2 + padding, y1)
183 driver->draw2DRectangle(c_outside,
185 v2s32(x1 - padding, y2),
186 v2s32(x2 + padding, y2 + padding)
188 driver->draw2DRectangle(c_outside,
190 v2s32(x1 - padding, y1),
193 driver->draw2DRectangle(c_outside,
196 v2s32(x2 + padding, y2)
198 /*// Light inside borders
199 driver->draw2DRectangle(c_inside,
201 v2s32(x1 - padding/2, y1 - padding/2),
202 v2s32(x2 + padding/2, y1)
204 driver->draw2DRectangle(c_inside,
206 v2s32(x1 - padding/2, y2),
207 v2s32(x2 + padding/2, y2 + padding/2)
209 driver->draw2DRectangle(c_inside,
211 v2s32(x1 - padding/2, y1),
214 driver->draw2DRectangle(c_inside,
217 v2s32(x2 + padding/2, y2)
222 video::SColor bgcolor2(128,0,0,0);
223 driver->draw2DRectangle(bgcolor2, rect, NULL);
227 drawInventoryItem(driver, font, item, rect, NULL);
235 video::ITexture *heart_texture =
236 driver->getTexture(getTexturePath("heart.png").c_str());
237 v2s32 p = pos + v2s32(0, -20);
238 for(s32 i=0; i<halfheartcount/2; i++)
240 const video::SColor color(255,255,255,255);
241 const video::SColor colors[] = {color,color,color,color};
242 core::rect<s32> rect(0,0,16,16);
244 driver->draw2DImage(heart_texture, rect,
245 core::rect<s32>(core::position2d<s32>(0,0),
246 core::dimension2di(heart_texture->getOriginalSize())),
250 if(halfheartcount % 2 == 1)
252 const video::SColor color(255,255,255,255);
253 const video::SColor colors[] = {color,color,color,color};
254 core::rect<s32> rect(0,0,16/2,16);
256 core::dimension2di srcd(heart_texture->getOriginalSize());
258 driver->draw2DImage(heart_texture, rect,
259 core::rect<s32>(core::position2d<s32>(0,0), srcd),
267 Find what the player is pointing at
269 void getPointedNode(Client *client, v3f player_position,
270 v3f camera_direction, v3f camera_position,
271 bool &nodefound, core::line3d<f32> shootline,
272 v3s16 &nodepos, v3s16 &neighbourpos,
273 core::aabbox3d<f32> &nodehilightbox,
276 f32 mindistance = BS * 1001;
278 v3s16 pos_i = floatToInt(player_position, BS);
280 /*dstream<<"pos_i=("<<pos_i.X<<","<<pos_i.Y<<","<<pos_i.Z<<")"
284 s16 ystart = pos_i.Y + 0 - (camera_direction.Y<0 ? a : 1);
285 s16 zstart = pos_i.Z - (camera_direction.Z<0 ? a : 1);
286 s16 xstart = pos_i.X - (camera_direction.X<0 ? a : 1);
287 s16 yend = pos_i.Y + 1 + (camera_direction.Y>0 ? a : 1);
288 s16 zend = pos_i.Z + (camera_direction.Z>0 ? a : 1);
289 s16 xend = pos_i.X + (camera_direction.X>0 ? a : 1);
291 for(s16 y = ystart; y <= yend; y++)
292 for(s16 z = zstart; z <= zend; z++)
293 for(s16 x = xstart; x <= xend; x++)
298 n = client->getNode(v3s16(x,y,z));
299 if(content_pointable(n.getContent()) == false)
302 catch(InvalidPositionException &e)
308 v3f npf = intToFloat(np, BS);
313 v3s16(0,0,1), // back
315 v3s16(1,0,0), // right
316 v3s16(0,0,-1), // front
317 v3s16(0,-1,0), // bottom
318 v3s16(-1,0,0), // left
324 if(n.getContent() == CONTENT_TORCH)
326 v3s16 dir = unpackDir(n.param2);
327 v3f dir_f = v3f(dir.X, dir.Y, dir.Z);
328 dir_f *= BS/2 - BS/6 - BS/20;
329 v3f cpf = npf + dir_f;
330 f32 distance = (cpf - camera_position).getLength();
332 core::aabbox3d<f32> box;
335 if(dir == v3s16(0,-1,0))
337 box = core::aabbox3d<f32>(
338 npf - v3f(BS/6, BS/2, BS/6),
339 npf + v3f(BS/6, -BS/2+BS/3*2, BS/6)
343 else if(dir == v3s16(0,1,0))
345 box = core::aabbox3d<f32>(
346 npf - v3f(BS/6, -BS/2+BS/3*2, BS/6),
347 npf + v3f(BS/6, BS/2, BS/6)
353 box = core::aabbox3d<f32>(
354 cpf - v3f(BS/6, BS/3, BS/6),
355 cpf + v3f(BS/6, BS/3, BS/6)
359 if(distance < mindistance)
361 if(box.intersectsWithLine(shootline))
366 mindistance = distance;
367 nodehilightbox = box;
371 else if(n.getContent() == CONTENT_SIGN_WALL)
373 v3s16 dir = unpackDir(n.param2);
374 v3f dir_f = v3f(dir.X, dir.Y, dir.Z);
375 dir_f *= BS/2 - BS/6 - BS/20;
376 v3f cpf = npf + dir_f;
377 f32 distance = (cpf - camera_position).getLength();
381 v3f(BS*0.42,-BS*0.35,-BS*0.4),
382 v3f(BS*0.49, BS*0.35, BS*0.4),
385 for(s32 i=0; i<2; i++)
387 if(dir == v3s16(1,0,0))
388 vertices[i].rotateXZBy(0);
389 if(dir == v3s16(-1,0,0))
390 vertices[i].rotateXZBy(180);
391 if(dir == v3s16(0,0,1))
392 vertices[i].rotateXZBy(90);
393 if(dir == v3s16(0,0,-1))
394 vertices[i].rotateXZBy(-90);
395 if(dir == v3s16(0,-1,0))
396 vertices[i].rotateXYBy(-90);
397 if(dir == v3s16(0,1,0))
398 vertices[i].rotateXYBy(90);
403 core::aabbox3d<f32> box;
405 box = core::aabbox3d<f32>(vertices[0]);
406 box.addInternalPoint(vertices[1]);
408 if(distance < mindistance)
410 if(box.intersectsWithLine(shootline))
415 mindistance = distance;
416 nodehilightbox = box;
421 else if(n.getContent() == CONTENT_LADDER)
423 v3s16 dir = unpackDir(n.param2);
424 v3f dir_f = v3f(dir.X, dir.Y, dir.Z);
425 dir_f *= BS/2 - BS/6 - BS/20;
426 v3f cpf = npf + dir_f;
427 f32 distance = (cpf - camera_position).getLength();
431 v3f(BS*0.42,-BS/2,-BS/2),
432 v3f(BS*0.49, BS/2, BS/2),
435 for(s32 i=0; i<2; i++)
437 if(dir == v3s16(1,0,0))
438 vertices[i].rotateXZBy(0);
439 if(dir == v3s16(-1,0,0))
440 vertices[i].rotateXZBy(180);
441 if(dir == v3s16(0,0,1))
442 vertices[i].rotateXZBy(90);
443 if(dir == v3s16(0,0,-1))
444 vertices[i].rotateXZBy(-90);
445 if(dir == v3s16(0,-1,0))
446 vertices[i].rotateXYBy(-90);
447 if(dir == v3s16(0,1,0))
448 vertices[i].rotateXYBy(90);
453 core::aabbox3d<f32> box;
455 box = core::aabbox3d<f32>(vertices[0]);
456 box.addInternalPoint(vertices[1]);
458 if(distance < mindistance)
460 if(box.intersectsWithLine(shootline))
465 mindistance = distance;
466 nodehilightbox = box;
470 else if(n.getContent() == CONTENT_RAIL)
472 v3s16 dir = unpackDir(n.param0);
473 v3f dir_f = v3f(dir.X, dir.Y, dir.Z);
474 dir_f *= BS/2 - BS/6 - BS/20;
475 v3f cpf = npf + dir_f;
476 f32 distance = (cpf - camera_position).getLength();
478 float d = (float)BS/16;
481 v3f(BS/2, -BS/2+d, -BS/2),
482 v3f(-BS/2, -BS/2, BS/2),
485 for(s32 i=0; i<2; i++)
490 core::aabbox3d<f32> box;
492 box = core::aabbox3d<f32>(vertices[0]);
493 box.addInternalPoint(vertices[1]);
495 if(distance < mindistance)
497 if(box.intersectsWithLine(shootline))
502 mindistance = distance;
503 nodehilightbox = box;
512 for(u16 i=0; i<6; i++)
514 v3f dir_f = v3f(dirs[i].X,
515 dirs[i].Y, dirs[i].Z);
516 v3f centerpoint = npf + dir_f * BS/2;
518 (centerpoint - camera_position).getLength();
520 if(distance < mindistance)
522 core::CMatrix4<f32> m;
523 m.buildRotateFromTo(v3f(0,0,1), dir_f);
525 // This is the back face
527 v3f(BS/2, BS/2, BS/2),
528 v3f(-BS/2, -BS/2, BS/2+d)
531 for(u16 j=0; j<2; j++)
533 m.rotateVect(corners[j]);
537 core::aabbox3d<f32> facebox(corners[0]);
538 facebox.addInternalPoint(corners[1]);
540 if(facebox.intersectsWithLine(shootline))
544 neighbourpos = np + dirs[i];
545 mindistance = distance;
547 //nodehilightbox = facebox;
549 const float d = 0.502;
550 core::aabbox3d<f32> nodebox
551 (-BS*d, -BS*d, -BS*d, BS*d, BS*d, BS*d);
552 v3f nodepos_f = intToFloat(nodepos, BS);
553 nodebox.MinEdge += nodepos_f;
554 nodebox.MaxEdge += nodepos_f;
555 nodehilightbox = nodebox;
557 } // if distance < mindistance
563 void update_skybox(video::IVideoDriver* driver,
564 scene::ISceneManager* smgr, scene::ISceneNode* &skybox,
572 /*// Disable skybox if FarMesh is enabled
573 if(g_settings->getBool("enable_farmesh"))
576 if(brightness >= 0.5)
578 skybox = smgr->addSkyBoxSceneNode(
579 driver->getTexture(getTexturePath("skybox2.png").c_str()),
580 driver->getTexture(getTexturePath("skybox3.png").c_str()),
581 driver->getTexture(getTexturePath("skybox1.png").c_str()),
582 driver->getTexture(getTexturePath("skybox1.png").c_str()),
583 driver->getTexture(getTexturePath("skybox1.png").c_str()),
584 driver->getTexture(getTexturePath("skybox1.png").c_str()));
586 else if(brightness >= 0.2)
588 skybox = smgr->addSkyBoxSceneNode(
589 driver->getTexture(getTexturePath("skybox2_dawn.png").c_str()),
590 driver->getTexture(getTexturePath("skybox3_dawn.png").c_str()),
591 driver->getTexture(getTexturePath("skybox1_dawn.png").c_str()),
592 driver->getTexture(getTexturePath("skybox1_dawn.png").c_str()),
593 driver->getTexture(getTexturePath("skybox1_dawn.png").c_str()),
594 driver->getTexture(getTexturePath("skybox1_dawn.png").c_str()));
598 skybox = smgr->addSkyBoxSceneNode(
599 driver->getTexture(getTexturePath("skybox2_night.png").c_str()),
600 driver->getTexture(getTexturePath("skybox3_night.png").c_str()),
601 driver->getTexture(getTexturePath("skybox1_night.png").c_str()),
602 driver->getTexture(getTexturePath("skybox1_night.png").c_str()),
603 driver->getTexture(getTexturePath("skybox1_night.png").c_str()),
604 driver->getTexture(getTexturePath("skybox1_night.png").c_str()));
609 Draws a screen with a single text on it.
610 Text will be removed when the screen is drawn the next time.
612 /*gui::IGUIStaticText **/
613 void draw_load_screen(const std::wstring &text,
614 video::IVideoDriver* driver, gui::IGUIFont* font)
616 v2u32 screensize = driver->getScreenSize();
617 const wchar_t *loadingtext = text.c_str();
618 core::vector2d<u32> textsize_u = font->getDimension(loadingtext);
619 core::vector2d<s32> textsize(textsize_u.X,textsize_u.Y);
620 core::vector2d<s32> center(screensize.X/2, screensize.Y/2);
621 core::rect<s32> textrect(center - textsize/2, center + textsize/2);
623 gui::IGUIStaticText *guitext = guienv->addStaticText(
624 loadingtext, textrect, false, false);
625 guitext->setTextAlignment(gui::EGUIA_CENTER, gui::EGUIA_UPPERLEFT);
627 driver->beginScene(true, true, video::SColor(255,0,0,0));
640 IrrlichtDevice *device,
643 std::string playername,
644 std::string password,
647 std::wstring &error_message,
648 std::string configpath
651 video::IVideoDriver* driver = device->getVideoDriver();
652 scene::ISceneManager* smgr = device->getSceneManager();
654 // Calculate text height using the font
655 u32 text_height = font->getDimension(L"Random test string").Height;
657 v2u32 screensize(0,0);
658 v2u32 last_screensize(0,0);
659 screensize = driver->getScreenSize();
661 const s32 hotbar_itemcount = 8;
662 //const s32 hotbar_imagesize = 36;
663 //const s32 hotbar_imagesize = 64;
664 s32 hotbar_imagesize = 48;
666 // The color of the sky
668 //video::SColor skycolor = video::SColor(255,140,186,250);
670 video::SColor bgcolor_bright = video::SColor(255,170,200,230);
673 Draw "Loading" screen
675 /*gui::IGUIStaticText *gui_loadingtext = */
676 //draw_load_screen(L"Loading and connecting...", driver, font);
678 draw_load_screen(L"Loading...", driver, font);
682 SharedPtr will delete it when it goes out of scope.
684 SharedPtr<Server> server;
686 draw_load_screen(L"Creating server...", driver, font);
687 dstream<<DTIME<<"Creating server"<<std::endl;
688 server = new Server(map_dir, configpath);
696 draw_load_screen(L"Creating client...", driver, font);
697 dstream<<DTIME<<"Creating client"<<std::endl;
698 MapDrawControl draw_control;
699 Client client(device, playername.c_str(), password, draw_control);
701 draw_load_screen(L"Resolving address...", driver, font);
702 Address connect_address(0,0,0,0, port);
705 //connect_address.Resolve("localhost");
706 connect_address.setAddress(127,0,0,1);
708 connect_address.Resolve(address.c_str());
710 catch(ResolveError &e)
712 dstream<<DTIME<<"Couldn't resolve address"<<std::endl;
714 error_message = L"Couldn't resolve address";
715 //gui_loadingtext->remove();
720 Attempt to connect to the server
723 dstream<<DTIME<<"Connecting to server at ";
724 connect_address.print(&dstream);
726 client.connect(connect_address);
728 bool could_connect = false;
731 float time_counter = 0.0;
734 if(client.connectedAndInitialized())
736 could_connect = true;
739 if(client.accessDenied())
743 // Wait for 10 seconds
744 if(time_counter >= 10.0)
749 std::wostringstream ss;
750 ss<<L"Connecting to server... (timeout in ";
751 ss<<(int)(10.0 - time_counter + 1.0);
753 draw_load_screen(ss.str(), driver, font);
756 driver->beginScene(true, true, video::SColor(255,0,0,0));
758 driver->endScene();*/
760 // Update client and server
772 catch(con::PeerNotFoundException &e)
775 if(could_connect == false)
777 if(client.accessDenied())
779 error_message = L"Access denied. Reason: "
780 +client.accessDeniedReason();
781 dstream<<DTIME<<wide_to_narrow(error_message)<<std::endl;
785 error_message = L"Connection timed out.";
786 dstream<<DTIME<<"Timed out."<<std::endl;
788 //gui_loadingtext->remove();
795 float old_brightness = 1.0;
796 scene::ISceneNode* skybox = NULL;
797 update_skybox(driver, smgr, skybox, 1.0);
800 Create the camera node
802 Camera camera(smgr, draw_control);
803 if (!camera.successfullyCreated(error_message))
806 f32 camera_yaw = 0; // "right/left"
807 f32 camera_pitch = 0; // "up/down"
813 float cloud_height = BS*100;
814 Clouds *clouds = NULL;
815 if(g_settings->getBool("enable_clouds"))
817 clouds = new Clouds(smgr->getRootSceneNode(), smgr, -1,
818 cloud_height, time(0));
825 FarMesh *farmesh = NULL;
826 if(g_settings->getBool("enable_farmesh"))
828 farmesh = new FarMesh(smgr->getRootSceneNode(), smgr, -1, client.getMapSeed(), &client);
835 //gui_loadingtext->remove();
841 // First line of debug text
842 gui::IGUIStaticText *guitext = guienv->addStaticText(
844 core::rect<s32>(5, 5, 795, 5+text_height),
846 // Second line of debug text
847 gui::IGUIStaticText *guitext2 = guienv->addStaticText(
849 core::rect<s32>(5, 5+(text_height+5)*1, 795, (5+text_height)*2),
852 // At the middle of the screen
853 // Object infos are shown in this
854 gui::IGUIStaticText *guitext_info = guienv->addStaticText(
856 core::rect<s32>(0,0,400,text_height+5) + v2s32(100,200),
860 gui::IGUIStaticText *guitext_chat = guienv->addStaticText(
862 core::rect<s32>(0,0,0,0),
863 //false, false); // Disable word wrap as of now
865 //guitext_chat->setBackgroundColor(video::SColor(96,0,0,0));
866 core::list<ChatLine> chat_lines;
868 /*GUIQuickInventory *quick_inventory = new GUIQuickInventory
869 (guienv, NULL, v2s32(10, 70), 5, &local_inventory);*/
870 /*GUIQuickInventory *quick_inventory = new GUIQuickInventory
871 (guienv, NULL, v2s32(0, 0), quickinv_itemcount, &local_inventory);*/
873 // Test the text input system
874 /*(new GUITextInputMenu(guienv, guiroot, -1, &g_menumgr,
876 /*GUIMessageMenu *menu =
877 new GUIMessageMenu(guienv, guiroot, -1,
883 (new GUIPauseMenu(guienv, guiroot, -1, g_gamecallback,
884 &g_menumgr))->drop();
887 /*guitext2->setVisible(true);
888 guitext_info->setVisible(true);
889 guitext_chat->setVisible(true);*/
891 //s32 guitext_chat_pad_bottom = 70;
894 Some statistics are collected in these
897 u32 beginscenetime = 0;
899 u32 endscenetime = 0;
902 //throw con::PeerNotFoundException("lol");
904 core::list<float> frametime_log;
906 float nodig_delay_counter = 0.0;
907 float dig_time = 0.0;
909 v3s16 nodepos_old(-32768,-32768,-32768);
911 float damage_flash_timer = 0;
912 s16 farmesh_range = 20*MAP_BLOCKSIZE;
914 const float object_hit_delay = 0.5;
915 float object_hit_delay_timer = 0.0;
917 bool invert_mouse = g_settings->getBool("invert_mouse");
923 bool first_loop_after_window_activation = true;
925 // TODO: Convert the static interval timers to these
926 // Interval limiter for profiler
927 IntervalLimiter m_profiler_interval;
929 // Time is in milliseconds
930 // NOTE: getRealTime() causes strange problems in wine (imprecision?)
931 // NOTE: So we have to use getTime() and call run()s between them
932 u32 lasttime = device->getTimer()->getTime();
934 while(device->run() && kill == false)
936 //std::cerr<<"frame"<<std::endl;
938 if(client.accessDenied())
940 error_message = L"Access denied. Reason: "
941 +client.accessDeniedReason();
942 dstream<<DTIME<<wide_to_narrow(error_message)<<std::endl;
946 if(g_gamecallback->disconnect_requested)
948 g_gamecallback->disconnect_requested = false;
952 if(g_gamecallback->changepassword_requested)
954 (new GUIPasswordChange(guienv, guiroot, -1,
955 &g_menumgr, &client))->drop();
956 g_gamecallback->changepassword_requested = false;
960 Process TextureSource's queue
962 ((TextureSource*)g_texturesource)->processQueue();
967 last_screensize = screensize;
968 screensize = driver->getScreenSize();
969 v2s32 displaycenter(screensize.X/2,screensize.Y/2);
970 //bool screensize_changed = screensize != last_screensize;
973 if(screensize.Y <= 800)
974 hotbar_imagesize = 32;
975 else if(screensize.Y <= 1280)
976 hotbar_imagesize = 48;
978 hotbar_imagesize = 64;
980 // Hilight boxes collected during the loop and displayed
981 core::list< core::aabbox3d<f32> > hilightboxes;
984 std::wstring infotext;
986 // When screen size changes, update positions and sizes of stuff
987 /*if(screensize_changed)
989 v2s32 pos(displaycenter.X-((quickinv_itemcount-1)*quickinv_spacing+quickinv_size)/2, screensize.Y-quickinv_spacing);
990 quick_inventory->updatePosition(pos);
993 //TimeTaker //timer1("//timer1");
995 // Time of frame without fps limit
999 // not using getRealTime is necessary for wine
1000 u32 time = device->getTimer()->getTime();
1002 busytime_u32 = time - lasttime;
1005 busytime = busytime_u32 / 1000.0;
1008 //dstream<<"busytime_u32="<<busytime_u32<<std::endl;
1010 // Necessary for device->getTimer()->getTime()
1018 float fps_max = g_settings->getFloat("fps_max");
1019 u32 frametime_min = 1000./fps_max;
1021 if(busytime_u32 < frametime_min)
1023 u32 sleeptime = frametime_min - busytime_u32;
1024 device->sleep(sleeptime);
1028 // Necessary for device->getTimer()->getTime()
1032 Time difference calculation
1034 f32 dtime; // in seconds
1036 u32 time = device->getTimer()->getTime();
1038 dtime = (time - lasttime) / 1000.0;
1045 object_hit_delay_timer -= dtime;
1048 Log frametime for visualization
1050 frametime_log.push_back(dtime);
1051 if(frametime_log.size() > 100)
1053 core::list<float>::Iterator i = frametime_log.begin();
1054 frametime_log.erase(i);
1058 Visualize frametime in terminal
1060 /*for(u32 i=0; i<dtime*400; i++)
1062 dstream<<std::endl;*/
1065 Time average and jitter calculation
1068 static f32 dtime_avg1 = 0.0;
1069 dtime_avg1 = dtime_avg1 * 0.96 + dtime * 0.04;
1070 f32 dtime_jitter1 = dtime - dtime_avg1;
1072 static f32 dtime_jitter1_max_sample = 0.0;
1073 static f32 dtime_jitter1_max_fraction = 0.0;
1075 static f32 jitter1_max = 0.0;
1076 static f32 counter = 0.0;
1077 if(dtime_jitter1 > jitter1_max)
1078 jitter1_max = dtime_jitter1;
1083 dtime_jitter1_max_sample = jitter1_max;
1084 dtime_jitter1_max_fraction
1085 = dtime_jitter1_max_sample / (dtime_avg1+0.001);
1091 Busytime average and jitter calculation
1094 static f32 busytime_avg1 = 0.0;
1095 busytime_avg1 = busytime_avg1 * 0.98 + busytime * 0.02;
1096 f32 busytime_jitter1 = busytime - busytime_avg1;
1098 static f32 busytime_jitter1_max_sample = 0.0;
1099 static f32 busytime_jitter1_min_sample = 0.0;
1101 static f32 jitter1_max = 0.0;
1102 static f32 jitter1_min = 0.0;
1103 static f32 counter = 0.0;
1104 if(busytime_jitter1 > jitter1_max)
1105 jitter1_max = busytime_jitter1;
1106 if(busytime_jitter1 < jitter1_min)
1107 jitter1_min = busytime_jitter1;
1111 busytime_jitter1_max_sample = jitter1_max;
1112 busytime_jitter1_min_sample = jitter1_min;
1119 Debug info for client
1122 static float counter = 0.0;
1127 client.printDebugInfo(dstream);
1134 float profiler_print_interval =
1135 g_settings->getFloat("profiler_print_interval");
1136 if(profiler_print_interval != 0)
1138 if(m_profiler_interval.step(0.030, profiler_print_interval))
1140 dstream<<"Profiler:"<<std::endl;
1141 g_profiler->print(dstream);
1142 g_profiler->clear();
1147 Direct handling of user input
1150 // Reset input if window not active or some menu is active
1151 if(device->isWindowActive() == false || noMenuActive() == false)
1156 // Input handler step() (used by the random input generator)
1160 Launch menus according to keys
1162 if(input->wasKeyDown(getKeySetting("keymap_inventory")))
1164 dstream<<DTIME<<"the_game: "
1165 <<"Launching inventory"<<std::endl;
1167 GUIInventoryMenu *menu =
1168 new GUIInventoryMenu(guienv, guiroot, -1,
1169 &g_menumgr, v2s16(8,7),
1170 client.getInventoryContext(),
1173 core::array<GUIInventoryMenu::DrawSpec> draw_spec;
1174 draw_spec.push_back(GUIInventoryMenu::DrawSpec(
1175 "list", "current_player", "main",
1176 v2s32(0, 3), v2s32(8, 4)));
1177 draw_spec.push_back(GUIInventoryMenu::DrawSpec(
1178 "list", "current_player", "craft",
1179 v2s32(3, 0), v2s32(3, 3)));
1180 draw_spec.push_back(GUIInventoryMenu::DrawSpec(
1181 "list", "current_player", "craftresult",
1182 v2s32(7, 1), v2s32(1, 1)));
1184 menu->setDrawSpec(draw_spec);
1188 else if(input->wasKeyDown(EscapeKey))
1190 dstream<<DTIME<<"the_game: "
1191 <<"Launching pause menu"<<std::endl;
1192 // It will delete itself by itself
1193 (new GUIPauseMenu(guienv, guiroot, -1, g_gamecallback,
1194 &g_menumgr))->drop();
1196 // Move mouse cursor on top of the disconnect button
1197 input->setMousePos(displaycenter.X, displaycenter.Y+25);
1199 else if(input->wasKeyDown(getKeySetting("keymap_chat")))
1201 TextDest *dest = new TextDestChat(&client);
1203 (new GUITextInputMenu(guienv, guiroot, -1,
1207 else if(input->wasKeyDown(getKeySetting("keymap_cmd")))
1209 TextDest *dest = new TextDestChat(&client);
1211 (new GUITextInputMenu(guienv, guiroot, -1,
1215 else if(input->wasKeyDown(getKeySetting("keymap_freemove")))
1217 if(g_settings->getBool("free_move"))
1219 g_settings->set("free_move","false");
1220 chat_lines.push_back(ChatLine(L"free_move disabled"));
1224 g_settings->set("free_move","true");
1225 chat_lines.push_back(ChatLine(L"free_move enabled"));
1228 else if(input->wasKeyDown(getKeySetting("keymap_fastmove")))
1230 if(g_settings->getBool("fast_move"))
1232 g_settings->set("fast_move","false");
1233 chat_lines.push_back(ChatLine(L"fast_move disabled"));
1237 g_settings->set("fast_move","true");
1238 chat_lines.push_back(ChatLine(L"fast_move enabled"));
1241 else if(input->wasKeyDown(getKeySetting("keymap_frametime_graph")))
1243 if(g_settings->getBool("frametime_graph"))
1245 g_settings->set("frametime_graph","false");
1246 chat_lines.push_back(ChatLine(L"frametime_graph disabled"));
1250 g_settings->set("frametime_graph","true");
1251 chat_lines.push_back(ChatLine(L"frametime_graph enabled"));
1254 else if(input->wasKeyDown(getKeySetting("keymap_screenshot")))
1256 irr::video::IImage* const image = driver->createScreenShot();
1258 irr::c8 filename[256];
1259 snprintf(filename, 256, "%s/screenshot_%u.png",
1260 g_settings->get("screenshot_path").c_str(),
1261 device->getTimer()->getRealTime());
1262 if (driver->writeImageToFile(image, filename)) {
1263 std::wstringstream sstr;
1264 sstr<<"Saved screenshot to '"<<filename<<"'";
1265 dstream<<"Saved screenshot to '"<<filename<<"'"<<std::endl;
1266 chat_lines.push_back(ChatLine(sstr.str()));
1268 dstream<<"Failed to save screenshot '"<<filename<<"'"<<std::endl;
1274 // Item selection with mouse wheel
1276 s32 wheel = input->getMouseWheel();
1277 u16 max_item = MYMIN(PLAYER_INVENTORY_SIZE-1,
1278 hotbar_itemcount-1);
1282 if(g_selected_item < max_item)
1285 g_selected_item = 0;
1289 if(g_selected_item > 0)
1292 g_selected_item = max_item;
1297 for(u16 i=0; i<10; i++)
1299 const KeyPress *kp = NumberKey + (i + 1) % 10;
1300 if(input->wasKeyDown(*kp))
1302 if(i < PLAYER_INVENTORY_SIZE && i < hotbar_itemcount)
1304 g_selected_item = i;
1306 dstream<<DTIME<<"Selected item: "
1307 <<g_selected_item<<std::endl;
1312 // Viewing range selection
1313 if(input->wasKeyDown(getKeySetting("keymap_rangeselect")))
1315 if(draw_control.range_all)
1317 draw_control.range_all = false;
1318 dstream<<DTIME<<"Disabled full viewing range"<<std::endl;
1322 draw_control.range_all = true;
1323 dstream<<DTIME<<"Enabled full viewing range"<<std::endl;
1327 // Print debug stacks
1328 if(input->wasKeyDown(getKeySetting("keymap_print_debug_stacks")))
1330 dstream<<"-----------------------------------------"
1332 dstream<<DTIME<<"Printing debug stacks:"<<std::endl;
1333 dstream<<"-----------------------------------------"
1335 debug_stacks_print();
1339 Mouse and camera control
1340 NOTE: Do this before client.setPlayerControl() to not cause a camera lag of one frame
1343 if((device->isWindowActive() && noMenuActive()) || random_input)
1347 // Mac OSX gets upset if this is set every frame
1348 if(device->getCursorControl()->isVisible())
1349 device->getCursorControl()->setVisible(false);
1352 if(first_loop_after_window_activation){
1353 //dstream<<"window active, first loop"<<std::endl;
1354 first_loop_after_window_activation = false;
1357 s32 dx = input->getMousePos().X - displaycenter.X;
1358 s32 dy = input->getMousePos().Y - displaycenter.Y;
1361 //dstream<<"window active, pos difference "<<dx<<","<<dy<<std::endl;
1363 /*const float keyspeed = 500;
1364 if(input->isKeyDown(irr::KEY_UP))
1365 dy -= dtime * keyspeed;
1366 if(input->isKeyDown(irr::KEY_DOWN))
1367 dy += dtime * keyspeed;
1368 if(input->isKeyDown(irr::KEY_LEFT))
1369 dx -= dtime * keyspeed;
1370 if(input->isKeyDown(irr::KEY_RIGHT))
1371 dx += dtime * keyspeed;*/
1373 camera_yaw -= dx*0.2;
1374 camera_pitch += dy*0.2;
1375 if(camera_pitch < -89.5) camera_pitch = -89.5;
1376 if(camera_pitch > 89.5) camera_pitch = 89.5;
1378 input->setMousePos(displaycenter.X, displaycenter.Y);
1381 // Mac OSX gets upset if this is set every frame
1382 if(device->getCursorControl()->isVisible() == false)
1383 device->getCursorControl()->setVisible(true);
1385 //dstream<<"window inactive"<<std::endl;
1386 first_loop_after_window_activation = true;
1390 Player speed control
1391 TODO: Cache the keycodes from getKeySetting
1404 PlayerControl control(
1405 input->isKeyDown(getKeySetting("keymap_forward")),
1406 input->isKeyDown(getKeySetting("keymap_backward")),
1407 input->isKeyDown(getKeySetting("keymap_left")),
1408 input->isKeyDown(getKeySetting("keymap_right")),
1409 input->isKeyDown(getKeySetting("keymap_jump")),
1410 input->isKeyDown(getKeySetting("keymap_special1")),
1411 input->isKeyDown(getKeySetting("keymap_sneak")),
1415 client.setPlayerControl(control);
1424 //TimeTaker timer("server->step(dtime)");
1425 server->step(dtime);
1433 //TimeTaker timer("client.step(dtime)");
1435 //client.step(dtime_avg1);
1438 // Read client events
1441 ClientEvent event = client.getClientEvent();
1442 if(event.type == CE_NONE)
1446 else if(event.type == CE_PLAYER_DAMAGE)
1448 //u16 damage = event.player_damage.amount;
1449 //dstream<<"Player damage: "<<damage<<std::endl;
1450 damage_flash_timer = 0.05;
1452 else if(event.type == CE_PLAYER_FORCE_MOVE)
1454 camera_yaw = event.player_force_move.yaw;
1455 camera_pitch = event.player_force_move.pitch;
1459 //TimeTaker //timer2("//timer2");
1461 LocalPlayer* player = client.getLocalPlayer();
1462 camera.update(player, busytime, screensize);
1465 v3f player_position = player->getPosition();
1466 v3f camera_position = camera.getPosition();
1467 v3f camera_direction = camera.getDirection();
1468 f32 camera_fov = camera.getFovMax();
1470 if(FIELD_OF_VIEW_TEST)
1472 client.updateCamera(v3f(0,0,0), v3f(0,0,1), camera_fov);
1476 client.updateCamera(camera_position,
1477 camera_direction, camera_fov);
1481 //TimeTaker //timer3("//timer3");
1484 Calculate what block is the crosshair pointing to
1487 //u32 t1 = device->getTimer()->getRealTime();
1489 //f32 d = 4; // max. distance
1490 f32 d = 4; // max. distance
1491 core::line3d<f32> shootline(camera_position,
1492 camera_position + camera_direction * BS * (d+1));
1494 ClientActiveObject *selected_active_object
1495 = client.getSelectedActiveObject
1496 (d*BS, camera_position, shootline);
1498 bool left_punch = false;
1499 bool left_punch_muted = false;
1501 if(selected_active_object != NULL)
1503 /* Clear possible cracking animation */
1504 if(nodepos_old != v3s16(-32768,-32768,-32768))
1506 client.clearTempMod(nodepos_old);
1508 nodepos_old = v3s16(-32768,-32768,-32768);
1511 //dstream<<"Client returned selected_active_object != NULL"<<std::endl;
1513 core::aabbox3d<f32> *selection_box
1514 = selected_active_object->getSelectionBox();
1515 // Box should exist because object was returned in the
1517 assert(selection_box);
1519 v3f pos = selected_active_object->getPosition();
1521 core::aabbox3d<f32> box_on_map(
1522 selection_box->MinEdge + pos,
1523 selection_box->MaxEdge + pos
1526 if(selected_active_object->doShowSelectionBox())
1527 hilightboxes.push_back(box_on_map);
1529 //infotext = narrow_to_wide("A ClientActiveObject");
1530 infotext = narrow_to_wide(selected_active_object->infoText());
1532 //if(input->getLeftClicked())
1533 if(input->getLeftState())
1535 bool do_punch = false;
1536 bool do_punch_damage = false;
1537 if(object_hit_delay_timer <= 0.0){
1539 do_punch_damage = true;
1540 object_hit_delay_timer = object_hit_delay;
1542 if(input->getLeftClicked()){
1546 dstream<<DTIME<<"Left-clicked object"<<std::endl;
1549 if(do_punch_damage){
1550 client.clickActiveObject(0,
1551 selected_active_object->getId(), g_selected_item);
1554 else if(input->getRightClicked())
1556 dstream<<DTIME<<"Right-clicked object"<<std::endl;
1557 client.clickActiveObject(1,
1558 selected_active_object->getId(), g_selected_item);
1561 else // selected_object == NULL
1565 Find out which node we are pointing at
1568 bool nodefound = false;
1571 core::aabbox3d<f32> nodehilightbox;
1573 getPointedNode(&client, player_position,
1574 camera_direction, camera_position,
1575 nodefound, shootline,
1576 nodepos, neighbourpos,
1580 if(nodepos_old != v3s16(-32768,-32768,-32768))
1582 client.clearTempMod(nodepos_old);
1584 nodepos_old = v3s16(-32768,-32768,-32768);
1591 hilightboxes.push_back(nodehilightbox);
1594 Check information text of node
1597 NodeMetadata *meta = client.getNodeMetadata(nodepos);
1600 infotext = narrow_to_wide(meta->infoText());
1603 //MapNode node = client.getNode(nodepos);
1609 if(input->getLeftReleased())
1611 client.clearTempMod(nodepos);
1615 if(nodig_delay_counter > 0.0)
1617 nodig_delay_counter -= dtime;
1621 if(nodepos != nodepos_old)
1623 dstream<<DTIME<<"Pointing at ("<<nodepos.X<<","
1624 <<nodepos.Y<<","<<nodepos.Z<<")"<<std::endl;
1626 if(nodepos_old != v3s16(-32768,-32768,-32768))
1628 client.clearTempMod(nodepos_old);
1630 nodepos_old = v3s16(-32768,-32768,-32768);
1634 if(input->getLeftClicked() ||
1635 (input->getLeftState() && nodepos != nodepos_old))
1637 dstream<<DTIME<<"Started digging"<<std::endl;
1638 client.groundAction(0, nodepos, neighbourpos, g_selected_item);
1640 if(input->getLeftClicked())
1642 client.setTempMod(nodepos, NodeMod(NODEMOD_CRACK, 0));
1644 if(input->getLeftState())
1646 MapNode n = client.getNode(nodepos);
1648 // Get tool name. Default is "" = bare hands
1649 std::string toolname = "";
1650 InventoryList *mlist = local_inventory.getList("main");
1653 InventoryItem *item = mlist->getItem(g_selected_item);
1654 if(item && (std::string)item->getName() == "ToolItem")
1656 ToolItem *titem = (ToolItem*)item;
1657 toolname = titem->getToolName();
1661 // Get digging properties for material and tool
1662 content_t material = n.getContent();
1663 DiggingProperties prop =
1664 getDiggingProperties(material, toolname);
1666 float dig_time_complete = 0.0;
1668 if(prop.diggable == false)
1670 /*dstream<<"Material "<<(int)material
1671 <<" not diggable with \""
1672 <<toolname<<"\""<<std::endl;*/
1673 // I guess nobody will wait for this long
1674 dig_time_complete = 10000000.0;
1678 dig_time_complete = prop.time;
1681 if(dig_time_complete >= 0.001)
1683 dig_index = (u16)((float)CRACK_ANIMATION_LENGTH
1684 * dig_time/dig_time_complete);
1686 // This is for torches
1689 dig_index = CRACK_ANIMATION_LENGTH;
1692 if(dig_index < CRACK_ANIMATION_LENGTH)
1694 //TimeTaker timer("client.setTempMod");
1695 //dstream<<"dig_index="<<dig_index<<std::endl;
1696 client.setTempMod(nodepos, NodeMod(NODEMOD_CRACK, dig_index));
1700 dstream<<DTIME<<"Digging completed"<<std::endl;
1701 client.groundAction(3, nodepos, neighbourpos, g_selected_item);
1702 client.clearTempMod(nodepos);
1703 client.removeNode(nodepos);
1707 nodig_delay_counter = dig_time_complete
1708 / (float)CRACK_ANIMATION_LENGTH;
1710 // We don't want a corresponding delay to
1711 // very time consuming nodes
1712 if(nodig_delay_counter > 0.5)
1714 nodig_delay_counter = 0.5;
1716 // We want a slight delay to very little
1717 // time consuming nodes
1718 float mindelay = 0.15;
1719 if(nodig_delay_counter < mindelay)
1721 nodig_delay_counter = mindelay;
1727 camera.setDigging(0); // left click animation
1732 if(input->getRightClicked())
1734 dstream<<DTIME<<"Ground right-clicked"<<std::endl;
1736 // If metadata provides an inventory view, activate it
1737 if(meta && meta->getInventoryDrawSpecString() != "" && !random_input)
1739 dstream<<DTIME<<"Launching custom inventory view"<<std::endl;
1741 Construct the unique identification string of the node
1743 std::string current_name;
1744 current_name += "nodemeta:";
1745 current_name += itos(nodepos.X);
1746 current_name += ",";
1747 current_name += itos(nodepos.Y);
1748 current_name += ",";
1749 current_name += itos(nodepos.Z);
1755 core::array<GUIInventoryMenu::DrawSpec> draw_spec;
1757 GUIInventoryMenu::makeDrawSpecArrayFromString(
1759 meta->getInventoryDrawSpecString(),
1762 GUIInventoryMenu *menu =
1763 new GUIInventoryMenu(guienv, guiroot, -1,
1764 &g_menumgr, invsize,
1765 client.getInventoryContext(),
1767 menu->setDrawSpec(draw_spec);
1770 else if(meta && meta->typeId() == CONTENT_SIGN_WALL && !random_input)
1772 dstream<<"Sign node right-clicked"<<std::endl;
1774 SignNodeMetadata *signmeta = (SignNodeMetadata*)meta;
1776 // Get a new text for it
1778 TextDest *dest = new TextDestSignNode(nodepos, &client);
1780 std::wstring wtext =
1781 narrow_to_wide(signmeta->getText());
1783 (new GUITextInputMenu(guienv, guiroot, -1,
1789 client.groundAction(1, nodepos, neighbourpos, g_selected_item);
1790 camera.setDigging(1); // right click animation
1794 nodepos_old = nodepos;
1797 } // selected_object == NULL
1799 if(left_punch || (input->getLeftClicked() && !left_punch_muted))
1801 camera.setDigging(0); // left click animation
1804 input->resetLeftClicked();
1805 input->resetRightClicked();
1807 if(input->getLeftReleased())
1809 dstream<<DTIME<<"Left button released (stopped digging)"
1811 client.groundAction(2, v3s16(0,0,0), v3s16(0,0,0), 0);
1813 if(input->getRightReleased())
1815 //dstream<<DTIME<<"Right released"<<std::endl;
1819 input->resetLeftReleased();
1820 input->resetRightReleased();
1823 Calculate stuff for drawing
1826 u32 daynight_ratio = client.getDayNightRatio();
1827 u8 l = decode_light((daynight_ratio * LIGHT_SUN) / 1000);
1828 video::SColor bgcolor = video::SColor(
1830 bgcolor_bright.getRed() * l / 255,
1831 bgcolor_bright.getGreen() * l / 255,
1832 bgcolor_bright.getBlue() * l / 255);
1833 /*skycolor.getRed() * l / 255,
1834 skycolor.getGreen() * l / 255,
1835 skycolor.getBlue() * l / 255);*/
1837 float brightness = (float)l/255.0;
1842 if(fabs(brightness - old_brightness) > 0.01)
1843 update_skybox(driver, smgr, skybox, brightness);
1850 clouds->step(dtime);
1851 clouds->update(v2f(player_position.X, player_position.Z),
1852 0.05+brightness*0.95);
1860 farmesh_range = draw_control.wanted_range * 10;
1861 if(draw_control.range_all && farmesh_range < 500)
1862 farmesh_range = 500;
1863 if(farmesh_range > 1000)
1864 farmesh_range = 1000;
1866 farmesh->step(dtime);
1867 farmesh->update(v2f(player_position.X, player_position.Z),
1868 0.05+brightness*0.95, farmesh_range);
1871 // Store brightness value
1872 old_brightness = brightness;
1878 if(g_settings->getBool("enable_fog") == true)
1883 range = BS*farmesh_range;
1887 range = draw_control.wanted_range*BS + MAP_BLOCKSIZE*BS*1.5;
1888 if(draw_control.range_all)
1891 range = range * 0.5 + 25*BS;
1896 video::EFT_FOG_LINEAR,
1908 video::EFT_FOG_LINEAR,
1918 Update gui stuff (0ms)
1921 //TimeTaker guiupdatetimer("Gui updating");
1924 static float drawtime_avg = 0;
1925 drawtime_avg = drawtime_avg * 0.95 + (float)drawtime*0.05;
1926 static float beginscenetime_avg = 0;
1927 beginscenetime_avg = beginscenetime_avg * 0.95 + (float)beginscenetime*0.05;
1928 static float scenetime_avg = 0;
1929 scenetime_avg = scenetime_avg * 0.95 + (float)scenetime*0.05;
1930 static float endscenetime_avg = 0;
1931 endscenetime_avg = endscenetime_avg * 0.95 + (float)endscenetime*0.05;
1934 snprintf(temptext, 300, "Minetest-c55 %s ("
1937 " drawtime=%.0f, beginscenetime=%.0f"
1938 ", scenetime=%.0f, endscenetime=%.0f",
1940 draw_control.range_all,
1947 guitext->setText(narrow_to_wide(temptext).c_str());
1952 snprintf(temptext, 300,
1953 "(% .1f, % .1f, % .1f)"
1954 " (% .3f < btime_jitter < % .3f"
1955 ", dtime_jitter = % .1f %%"
1956 ", v_range = %.1f)",
1957 player_position.X/BS,
1958 player_position.Y/BS,
1959 player_position.Z/BS,
1960 busytime_jitter1_min_sample,
1961 busytime_jitter1_max_sample,
1962 dtime_jitter1_max_fraction * 100.0,
1963 draw_control.wanted_range
1966 guitext2->setText(narrow_to_wide(temptext).c_str());
1970 guitext_info->setText(infotext.c_str());
1974 Get chat messages from client
1978 std::wstring message;
1979 while(client.getChatMessage(message))
1981 chat_lines.push_back(ChatLine(message));
1982 /*if(chat_lines.size() > 6)
1984 core::list<ChatLine>::Iterator
1985 i = chat_lines.begin();
1986 chat_lines.erase(i);
1989 // Append them to form the whole static text and throw
1990 // it to the gui element
1992 // This will correspond to the line number counted from
1993 // top to bottom, from size-1 to 0
1994 s16 line_number = chat_lines.size();
1995 // Count of messages to be removed from the top
1996 u16 to_be_removed_count = 0;
1997 for(core::list<ChatLine>::Iterator
1998 i = chat_lines.begin();
1999 i != chat_lines.end(); i++)
2001 // After this, line number is valid for this loop
2006 This results in a maximum age of 60*6 to the
2007 lowermost line and a maximum of 6 lines
2009 float allowed_age = (6-line_number) * 60.0;
2011 if((*i).age > allowed_age)
2013 to_be_removed_count++;
2016 whole += (*i).text + L'\n';
2018 for(u16 i=0; i<to_be_removed_count; i++)
2020 core::list<ChatLine>::Iterator
2021 it = chat_lines.begin();
2022 chat_lines.erase(it);
2024 guitext_chat->setText(whole.c_str());
2026 // Update gui element size and position
2028 /*core::rect<s32> rect(
2030 screensize.Y - guitext_chat_pad_bottom
2031 - text_height*chat_lines.size(),
2033 screensize.Y - guitext_chat_pad_bottom
2035 core::rect<s32> rect(
2039 50 + guitext_chat->getTextHeight()
2042 guitext_chat->setRelativePosition(rect);
2044 if(chat_lines.size() == 0)
2045 guitext_chat->setVisible(false);
2047 guitext_chat->setVisible(true);
2054 static u16 old_selected_item = 65535;
2055 if(client.getLocalInventoryUpdated()
2056 || g_selected_item != old_selected_item)
2058 client.selectPlayerItem(g_selected_item);
2059 old_selected_item = g_selected_item;
2060 //dstream<<"Updating local inventory"<<std::endl;
2061 client.getLocalInventory(local_inventory);
2063 // Update wielded tool
2064 InventoryList *mlist = local_inventory.getList("main");
2065 InventoryItem *item = NULL;
2067 item = mlist->getItem(g_selected_item);
2072 Send actions returned by the inventory menu
2074 while(inventory_action_queue.size() != 0)
2076 InventoryAction *a = inventory_action_queue.pop_front();
2078 client.sendInventoryAction(a);
2087 TimeTaker drawtimer("Drawing");
2091 TimeTaker timer("beginScene");
2092 driver->beginScene(true, true, bgcolor);
2093 //driver->beginScene(false, true, bgcolor);
2094 beginscenetime = timer.stop(true);
2099 //dstream<<DTIME<<"smgr->drawAll()"<<std::endl;
2102 TimeTaker timer("smgr");
2104 scenetime = timer.stop(true);
2108 //TimeTaker timer9("auxiliary drawings");
2112 //TimeTaker //timer10("//timer10");
2118 driver->setMaterial(m);
2120 driver->setTransform(video::ETS_WORLD, core::IdentityMatrix);
2122 for(core::list< core::aabbox3d<f32> >::Iterator i=hilightboxes.begin();
2123 i != hilightboxes.end(); i++)
2125 /*dstream<<"hilightbox min="
2126 <<"("<<i->MinEdge.X<<","<<i->MinEdge.Y<<","<<i->MinEdge.Z<<")"
2128 <<"("<<i->MaxEdge.X<<","<<i->MaxEdge.Y<<","<<i->MaxEdge.Z<<")"
2130 driver->draw3DBox(*i, video::SColor(255,0,0,0));
2137 // Warning: This clears the Z buffer.
2138 camera.drawWieldedTool();
2145 client.renderPostFx();
2151 if(g_settings->getBool("frametime_graph") == true)
2154 for(core::list<float>::Iterator
2155 i = frametime_log.begin();
2156 i != frametime_log.end();
2159 driver->draw2DLine(v2s32(x,50),
2160 v2s32(x,50+(*i)*1000),
2161 video::SColor(255,255,255,255));
2169 driver->draw2DLine(displaycenter - core::vector2d<s32>(10,0),
2170 displaycenter + core::vector2d<s32>(10,0),
2171 video::SColor(255,255,255,255));
2172 driver->draw2DLine(displaycenter - core::vector2d<s32>(0,10),
2173 displaycenter + core::vector2d<s32>(0,10),
2174 video::SColor(255,255,255,255));
2179 //TimeTaker //timer11("//timer11");
2191 draw_hotbar(driver, font, v2s32(displaycenter.X, screensize.Y),
2192 hotbar_imagesize, hotbar_itemcount, &local_inventory,
2199 if(damage_flash_timer > 0.0)
2201 damage_flash_timer -= dtime;
2203 video::SColor color(128,255,0,0);
2204 driver->draw2DRectangle(color,
2205 core::rect<s32>(0,0,screensize.X,screensize.Y),
2213 TimeTaker timer("endScene");
2215 endscenetime = timer.stop(true);
2218 drawtime = drawtimer.stop(true);
2224 static s16 lastFPS = 0;
2225 //u16 fps = driver->getFPS();
2226 u16 fps = (1.0/dtime_avg1);
2230 core::stringw str = L"Minetest [";
2231 str += driver->getName();
2235 device->setWindowCaption(str.c_str());
2247 Draw a "shutting down" screen, which will be shown while the map
2248 generator and other stuff quits
2251 /*gui::IGUIStaticText *gui_shuttingdowntext = */
2252 draw_load_screen(L"Shutting down stuff...", driver, font);
2253 /*driver->beginScene(true, true, video::SColor(255,0,0,0));
2256 gui_shuttingdowntext->remove();*/