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"
36 TODO: Move content-aware stuff to separate file by adding properties
37 and virtual interfaces
39 #include "content_mapnode.h"
40 #include "content_nodemeta.h"
43 Setting this to 1 enables a special camera mode that forces
44 the renderers to think that the camera statically points from
45 the starting place to a static direction.
47 This allows one to move around with the player and see what
48 is actually drawn behind solid things and behind the player.
50 #define FIELD_OF_VIEW_TEST 0
60 ChatLine(const std::wstring &a_text):
73 // Inventory actions from the menu are buffered here before sending
74 Queue<InventoryAction*> inventory_action_queue;
75 // This is a copy of the inventory that the client's environment has
76 Inventory local_inventory;
78 u16 g_selected_item = 0;
84 struct TextDestSign : public TextDest
86 TextDestSign(v3s16 blockpos, s16 id, Client *client)
88 m_blockpos = blockpos;
92 void gotText(std::wstring text)
94 std::string ntext = wide_to_narrow(text);
95 dstream<<"Changing text of a sign object: "
97 m_client->sendSignText(m_blockpos, m_id, ntext);
105 struct TextDestChat : public TextDest
107 TextDestChat(Client *client)
111 void gotText(std::wstring text)
113 // Discard empty line
118 m_client->sendChatMessage(text);
120 m_client->addChatMessage(text);
126 struct TextDestSignNode : public TextDest
128 TextDestSignNode(v3s16 p, Client *client)
133 void gotText(std::wstring text)
135 std::string ntext = wide_to_narrow(text);
136 dstream<<"Changing text of a sign node: "
138 m_client->sendSignNodeText(m_p, ntext);
148 void draw_hotbar(video::IVideoDriver *driver, gui::IGUIFont *font,
149 v2s32 centerlowerpos, s32 imgsize, s32 itemcount,
150 Inventory *inventory, s32 halfheartcount)
152 InventoryList *mainlist = inventory->getList("main");
155 dstream<<"WARNING: draw_hotbar(): mainlist == NULL"<<std::endl;
159 s32 padding = imgsize/12;
160 //s32 height = imgsize + padding*2;
161 s32 width = itemcount*(imgsize+padding*2);
163 // Position of upper left corner of bar
164 v2s32 pos = centerlowerpos - v2s32(width/2, imgsize+padding*2);
166 // Draw background color
167 /*core::rect<s32> barrect(0,0,width,height);
169 video::SColor bgcolor(255,128,128,128);
170 driver->draw2DRectangle(bgcolor, barrect, NULL);*/
172 core::rect<s32> imgrect(0,0,imgsize,imgsize);
174 for(s32 i=0; i<itemcount; i++)
176 InventoryItem *item = mainlist->getItem(i);
178 core::rect<s32> rect = imgrect + pos
179 + v2s32(padding+i*(imgsize+padding*2), padding);
181 if(g_selected_item == i)
183 video::SColor c_outside(255,255,0,0);
184 //video::SColor c_outside(255,0,0,0);
185 //video::SColor c_inside(255,192,192,192);
186 s32 x1 = rect.UpperLeftCorner.X;
187 s32 y1 = rect.UpperLeftCorner.Y;
188 s32 x2 = rect.LowerRightCorner.X;
189 s32 y2 = rect.LowerRightCorner.Y;
190 // Black base borders
191 driver->draw2DRectangle(c_outside,
193 v2s32(x1 - padding, y1 - padding),
194 v2s32(x2 + padding, y1)
196 driver->draw2DRectangle(c_outside,
198 v2s32(x1 - padding, y2),
199 v2s32(x2 + padding, y2 + padding)
201 driver->draw2DRectangle(c_outside,
203 v2s32(x1 - padding, y1),
206 driver->draw2DRectangle(c_outside,
209 v2s32(x2 + padding, y2)
211 /*// Light inside borders
212 driver->draw2DRectangle(c_inside,
214 v2s32(x1 - padding/2, y1 - padding/2),
215 v2s32(x2 + padding/2, y1)
217 driver->draw2DRectangle(c_inside,
219 v2s32(x1 - padding/2, y2),
220 v2s32(x2 + padding/2, y2 + padding/2)
222 driver->draw2DRectangle(c_inside,
224 v2s32(x1 - padding/2, y1),
227 driver->draw2DRectangle(c_inside,
230 v2s32(x2 + padding/2, y2)
235 video::SColor bgcolor2(128,0,0,0);
236 driver->draw2DRectangle(bgcolor2, rect, NULL);
240 drawInventoryItem(driver, font, item, rect, NULL);
248 video::ITexture *heart_texture =
249 driver->getTexture(getTexturePath("heart.png").c_str());
250 v2s32 p = pos + v2s32(0, -20);
251 for(s32 i=0; i<halfheartcount/2; i++)
253 const video::SColor color(255,255,255,255);
254 const video::SColor colors[] = {color,color,color,color};
255 core::rect<s32> rect(0,0,16,16);
257 driver->draw2DImage(heart_texture, rect,
258 core::rect<s32>(core::position2d<s32>(0,0),
259 core::dimension2di(heart_texture->getOriginalSize())),
263 if(halfheartcount % 2 == 1)
265 const video::SColor color(255,255,255,255);
266 const video::SColor colors[] = {color,color,color,color};
267 core::rect<s32> rect(0,0,16/2,16);
269 core::dimension2di srcd(heart_texture->getOriginalSize());
271 driver->draw2DImage(heart_texture, rect,
272 core::rect<s32>(core::position2d<s32>(0,0), srcd),
280 Find what the player is pointing at
282 void getPointedNode(Client *client, v3f player_position,
283 v3f camera_direction, v3f camera_position,
284 bool &nodefound, core::line3d<f32> shootline,
285 v3s16 &nodepos, v3s16 &neighbourpos,
286 core::aabbox3d<f32> &nodehilightbox,
289 f32 mindistance = BS * 1001;
291 v3s16 pos_i = floatToInt(player_position, BS);
293 /*std::cout<<"pos_i=("<<pos_i.X<<","<<pos_i.Y<<","<<pos_i.Z<<")"
297 s16 ystart = pos_i.Y + 0 - (camera_direction.Y<0 ? a : 1);
298 s16 zstart = pos_i.Z - (camera_direction.Z<0 ? a : 1);
299 s16 xstart = pos_i.X - (camera_direction.X<0 ? a : 1);
300 s16 yend = pos_i.Y + 1 + (camera_direction.Y>0 ? a : 1);
301 s16 zend = pos_i.Z + (camera_direction.Z>0 ? a : 1);
302 s16 xend = pos_i.X + (camera_direction.X>0 ? a : 1);
304 for(s16 y = ystart; y <= yend; y++)
305 for(s16 z = zstart; z <= zend; z++)
306 for(s16 x = xstart; x <= xend; x++)
311 n = client->getNode(v3s16(x,y,z));
312 if(content_pointable(n.getContent()) == false)
315 catch(InvalidPositionException &e)
321 v3f npf = intToFloat(np, BS);
326 v3s16(0,0,1), // back
328 v3s16(1,0,0), // right
329 v3s16(0,0,-1), // front
330 v3s16(0,-1,0), // bottom
331 v3s16(-1,0,0), // left
337 if(n.getContent() == CONTENT_TORCH)
339 v3s16 dir = unpackDir(n.param2);
340 v3f dir_f = v3f(dir.X, dir.Y, dir.Z);
341 dir_f *= BS/2 - BS/6 - BS/20;
342 v3f cpf = npf + dir_f;
343 f32 distance = (cpf - camera_position).getLength();
345 core::aabbox3d<f32> box;
348 if(dir == v3s16(0,-1,0))
350 box = core::aabbox3d<f32>(
351 npf - v3f(BS/6, BS/2, BS/6),
352 npf + v3f(BS/6, -BS/2+BS/3*2, BS/6)
356 else if(dir == v3s16(0,1,0))
358 box = core::aabbox3d<f32>(
359 npf - v3f(BS/6, -BS/2+BS/3*2, BS/6),
360 npf + v3f(BS/6, BS/2, BS/6)
366 box = core::aabbox3d<f32>(
367 cpf - v3f(BS/6, BS/3, BS/6),
368 cpf + v3f(BS/6, BS/3, BS/6)
372 if(distance < mindistance)
374 if(box.intersectsWithLine(shootline))
379 mindistance = distance;
380 nodehilightbox = box;
384 else if(n.getContent() == CONTENT_SIGN_WALL)
386 v3s16 dir = unpackDir(n.param2);
387 v3f dir_f = v3f(dir.X, dir.Y, dir.Z);
388 dir_f *= BS/2 - BS/6 - BS/20;
389 v3f cpf = npf + dir_f;
390 f32 distance = (cpf - camera_position).getLength();
394 v3f(BS*0.42,-BS*0.35,-BS*0.4),
395 v3f(BS*0.49, BS*0.35, BS*0.4),
398 for(s32 i=0; i<2; i++)
400 if(dir == v3s16(1,0,0))
401 vertices[i].rotateXZBy(0);
402 if(dir == v3s16(-1,0,0))
403 vertices[i].rotateXZBy(180);
404 if(dir == v3s16(0,0,1))
405 vertices[i].rotateXZBy(90);
406 if(dir == v3s16(0,0,-1))
407 vertices[i].rotateXZBy(-90);
408 if(dir == v3s16(0,-1,0))
409 vertices[i].rotateXYBy(-90);
410 if(dir == v3s16(0,1,0))
411 vertices[i].rotateXYBy(90);
416 core::aabbox3d<f32> box;
418 box = core::aabbox3d<f32>(vertices[0]);
419 box.addInternalPoint(vertices[1]);
421 if(distance < mindistance)
423 if(box.intersectsWithLine(shootline))
428 mindistance = distance;
429 nodehilightbox = box;
434 else if(n.getContent() == CONTENT_LADDER)
436 v3s16 dir = unpackDir(n.param2);
437 v3f dir_f = v3f(dir.X, dir.Y, dir.Z);
438 dir_f *= BS/2 - BS/6 - BS/20;
439 v3f cpf = npf + dir_f;
440 f32 distance = (cpf - camera_position).getLength();
444 v3f(BS*0.42,-BS/2,-BS/2),
445 v3f(BS*0.49, BS/2, BS/2),
448 for(s32 i=0; i<2; i++)
450 if(dir == v3s16(1,0,0))
451 vertices[i].rotateXZBy(0);
452 if(dir == v3s16(-1,0,0))
453 vertices[i].rotateXZBy(180);
454 if(dir == v3s16(0,0,1))
455 vertices[i].rotateXZBy(90);
456 if(dir == v3s16(0,0,-1))
457 vertices[i].rotateXZBy(-90);
458 if(dir == v3s16(0,-1,0))
459 vertices[i].rotateXYBy(-90);
460 if(dir == v3s16(0,1,0))
461 vertices[i].rotateXYBy(90);
466 core::aabbox3d<f32> box;
468 box = core::aabbox3d<f32>(vertices[0]);
469 box.addInternalPoint(vertices[1]);
471 if(distance < mindistance)
473 if(box.intersectsWithLine(shootline))
478 mindistance = distance;
479 nodehilightbox = box;
483 else if(n.getContent() == CONTENT_RAIL)
485 v3s16 dir = unpackDir(n.param0);
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();
491 float d = (float)BS/16;
494 v3f(BS/2, -BS/2+d, -BS/2),
495 v3f(-BS/2, -BS/2, BS/2),
498 for(s32 i=0; i<2; i++)
503 core::aabbox3d<f32> box;
505 box = core::aabbox3d<f32>(vertices[0]);
506 box.addInternalPoint(vertices[1]);
508 if(distance < mindistance)
510 if(box.intersectsWithLine(shootline))
515 mindistance = distance;
516 nodehilightbox = box;
525 for(u16 i=0; i<6; i++)
527 v3f dir_f = v3f(dirs[i].X,
528 dirs[i].Y, dirs[i].Z);
529 v3f centerpoint = npf + dir_f * BS/2;
531 (centerpoint - camera_position).getLength();
533 if(distance < mindistance)
535 core::CMatrix4<f32> m;
536 m.buildRotateFromTo(v3f(0,0,1), dir_f);
538 // This is the back face
540 v3f(BS/2, BS/2, BS/2),
541 v3f(-BS/2, -BS/2, BS/2+d)
544 for(u16 j=0; j<2; j++)
546 m.rotateVect(corners[j]);
550 core::aabbox3d<f32> facebox(corners[0]);
551 facebox.addInternalPoint(corners[1]);
553 if(facebox.intersectsWithLine(shootline))
557 neighbourpos = np + dirs[i];
558 mindistance = distance;
560 //nodehilightbox = facebox;
562 const float d = 0.502;
563 core::aabbox3d<f32> nodebox
564 (-BS*d, -BS*d, -BS*d, BS*d, BS*d, BS*d);
565 v3f nodepos_f = intToFloat(nodepos, BS);
566 nodebox.MinEdge += nodepos_f;
567 nodebox.MaxEdge += nodepos_f;
568 nodehilightbox = nodebox;
570 } // if distance < mindistance
576 void update_skybox(video::IVideoDriver* driver,
577 scene::ISceneManager* smgr, scene::ISceneNode* &skybox,
585 /*// Disable skybox if FarMesh is enabled
586 if(g_settings.getBool("enable_farmesh"))
589 if(brightness >= 0.5)
591 skybox = smgr->addSkyBoxSceneNode(
592 driver->getTexture(getTexturePath("skybox2.png").c_str()),
593 driver->getTexture(getTexturePath("skybox3.png").c_str()),
594 driver->getTexture(getTexturePath("skybox1.png").c_str()),
595 driver->getTexture(getTexturePath("skybox1.png").c_str()),
596 driver->getTexture(getTexturePath("skybox1.png").c_str()),
597 driver->getTexture(getTexturePath("skybox1.png").c_str()));
599 else if(brightness >= 0.2)
601 skybox = smgr->addSkyBoxSceneNode(
602 driver->getTexture(getTexturePath("skybox2_dawn.png").c_str()),
603 driver->getTexture(getTexturePath("skybox3_dawn.png").c_str()),
604 driver->getTexture(getTexturePath("skybox1_dawn.png").c_str()),
605 driver->getTexture(getTexturePath("skybox1_dawn.png").c_str()),
606 driver->getTexture(getTexturePath("skybox1_dawn.png").c_str()),
607 driver->getTexture(getTexturePath("skybox1_dawn.png").c_str()));
611 skybox = smgr->addSkyBoxSceneNode(
612 driver->getTexture(getTexturePath("skybox2_night.png").c_str()),
613 driver->getTexture(getTexturePath("skybox3_night.png").c_str()),
614 driver->getTexture(getTexturePath("skybox1_night.png").c_str()),
615 driver->getTexture(getTexturePath("skybox1_night.png").c_str()),
616 driver->getTexture(getTexturePath("skybox1_night.png").c_str()),
617 driver->getTexture(getTexturePath("skybox1_night.png").c_str()));
622 Draws a screen with a single text on it.
623 Text will be removed when the screen is drawn the next time.
625 /*gui::IGUIStaticText **/
626 void draw_load_screen(const std::wstring &text,
627 video::IVideoDriver* driver, gui::IGUIFont* font)
629 v2u32 screensize = driver->getScreenSize();
630 const wchar_t *loadingtext = text.c_str();
631 core::vector2d<u32> textsize_u = font->getDimension(loadingtext);
632 core::vector2d<s32> textsize(textsize_u.X,textsize_u.Y);
633 core::vector2d<s32> center(screensize.X/2, screensize.Y/2);
634 core::rect<s32> textrect(center - textsize/2, center + textsize/2);
636 gui::IGUIStaticText *guitext = guienv->addStaticText(
637 loadingtext, textrect, false, false);
638 guitext->setTextAlignment(gui::EGUIA_CENTER, gui::EGUIA_UPPERLEFT);
640 driver->beginScene(true, true, video::SColor(255,0,0,0));
653 IrrlichtDevice *device,
656 std::string playername,
657 std::string password,
660 std::wstring &error_message,
661 std::string configpath
664 video::IVideoDriver* driver = device->getVideoDriver();
665 scene::ISceneManager* smgr = device->getSceneManager();
667 // Calculate text height using the font
668 u32 text_height = font->getDimension(L"Random test string").Height;
670 v2u32 screensize(0,0);
671 v2u32 last_screensize(0,0);
672 screensize = driver->getScreenSize();
674 const s32 hotbar_itemcount = 8;
675 //const s32 hotbar_imagesize = 36;
676 //const s32 hotbar_imagesize = 64;
677 s32 hotbar_imagesize = 48;
679 // The color of the sky
681 //video::SColor skycolor = video::SColor(255,140,186,250);
683 video::SColor bgcolor_bright = video::SColor(255,170,200,230);
686 Draw "Loading" screen
688 /*gui::IGUIStaticText *gui_loadingtext = */
689 //draw_load_screen(L"Loading and connecting...", driver, font);
691 draw_load_screen(L"Loading...", driver, font);
695 SharedPtr will delete it when it goes out of scope.
697 SharedPtr<Server> server;
699 draw_load_screen(L"Creating server...", driver, font);
700 std::cout<<DTIME<<"Creating server"<<std::endl;
701 server = new Server(map_dir, configpath);
709 draw_load_screen(L"Creating client...", driver, font);
710 std::cout<<DTIME<<"Creating client"<<std::endl;
711 MapDrawControl draw_control;
712 Client client(device, playername.c_str(), password, draw_control);
714 draw_load_screen(L"Resolving address...", driver, font);
715 Address connect_address(0,0,0,0, port);
718 //connect_address.Resolve("localhost");
719 connect_address.setAddress(127,0,0,1);
721 connect_address.Resolve(address.c_str());
723 catch(ResolveError &e)
725 std::cout<<DTIME<<"Couldn't resolve address"<<std::endl;
727 error_message = L"Couldn't resolve address";
728 //gui_loadingtext->remove();
733 Attempt to connect to the server
736 dstream<<DTIME<<"Connecting to server at ";
737 connect_address.print(&dstream);
739 client.connect(connect_address);
741 bool could_connect = false;
744 float time_counter = 0.0;
747 if(client.connectedAndInitialized())
749 could_connect = true;
752 if(client.accessDenied())
756 // Wait for 10 seconds
757 if(time_counter >= 10.0)
762 std::wostringstream ss;
763 ss<<L"Connecting to server... (timeout in ";
764 ss<<(int)(10.0 - time_counter + 1.0);
766 draw_load_screen(ss.str(), driver, font);
769 driver->beginScene(true, true, video::SColor(255,0,0,0));
771 driver->endScene();*/
773 // Update client and server
785 catch(con::PeerNotFoundException &e)
788 if(could_connect == false)
790 if(client.accessDenied())
792 error_message = L"Access denied. Reason: "
793 +client.accessDeniedReason();
794 std::cout<<DTIME<<wide_to_narrow(error_message)<<std::endl;
798 error_message = L"Connection timed out.";
799 std::cout<<DTIME<<"Timed out."<<std::endl;
801 //gui_loadingtext->remove();
808 float old_brightness = 1.0;
809 scene::ISceneNode* skybox = NULL;
810 update_skybox(driver, smgr, skybox, 1.0);
813 Create the camera node
815 Camera camera(smgr, draw_control);
816 if (!camera.successfullyCreated(error_message))
819 f32 camera_yaw = 0; // "right/left"
820 f32 camera_pitch = 0; // "up/down"
826 float cloud_height = BS*100;
827 Clouds *clouds = NULL;
828 if(g_settings.getBool("enable_clouds"))
830 clouds = new Clouds(smgr->getRootSceneNode(), smgr, -1,
831 cloud_height, time(0));
838 FarMesh *farmesh = NULL;
839 if(g_settings.getBool("enable_farmesh"))
841 farmesh = new FarMesh(smgr->getRootSceneNode(), smgr, -1, client.getMapSeed(), &client);
848 //gui_loadingtext->remove();
854 // First line of debug text
855 gui::IGUIStaticText *guitext = guienv->addStaticText(
857 core::rect<s32>(5, 5, 795, 5+text_height),
859 // Second line of debug text
860 gui::IGUIStaticText *guitext2 = guienv->addStaticText(
862 core::rect<s32>(5, 5+(text_height+5)*1, 795, (5+text_height)*2),
865 // At the middle of the screen
866 // Object infos are shown in this
867 gui::IGUIStaticText *guitext_info = guienv->addStaticText(
869 core::rect<s32>(0,0,400,text_height+5) + v2s32(100,200),
873 gui::IGUIStaticText *guitext_chat = guienv->addStaticText(
875 core::rect<s32>(0,0,0,0),
876 //false, false); // Disable word wrap as of now
878 //guitext_chat->setBackgroundColor(video::SColor(96,0,0,0));
879 core::list<ChatLine> chat_lines;
881 /*GUIQuickInventory *quick_inventory = new GUIQuickInventory
882 (guienv, NULL, v2s32(10, 70), 5, &local_inventory);*/
883 /*GUIQuickInventory *quick_inventory = new GUIQuickInventory
884 (guienv, NULL, v2s32(0, 0), quickinv_itemcount, &local_inventory);*/
886 // Test the text input system
887 /*(new GUITextInputMenu(guienv, guiroot, -1, &g_menumgr,
889 /*GUIMessageMenu *menu =
890 new GUIMessageMenu(guienv, guiroot, -1,
896 (new GUIPauseMenu(guienv, guiroot, -1, g_gamecallback,
897 &g_menumgr))->drop();
900 /*guitext2->setVisible(true);
901 guitext_info->setVisible(true);
902 guitext_chat->setVisible(true);*/
904 //s32 guitext_chat_pad_bottom = 70;
907 Some statistics are collected in these
910 u32 beginscenetime = 0;
912 u32 endscenetime = 0;
915 //throw con::PeerNotFoundException("lol");
917 core::list<float> frametime_log;
919 float damage_flash_timer = 0;
920 s16 farmesh_range = 20*MAP_BLOCKSIZE;
922 bool invert_mouse = g_settings.getBool("invert_mouse");
928 bool first_loop_after_window_activation = true;
930 // TODO: Convert the static interval timers to these
931 // Interval limiter for profiler
932 IntervalLimiter m_profiler_interval;
934 // Time is in milliseconds
935 // NOTE: getRealTime() causes strange problems in wine (imprecision?)
936 // NOTE: So we have to use getTime() and call run()s between them
937 u32 lasttime = device->getTimer()->getTime();
939 while(device->run() && kill == false)
941 //std::cerr<<"frame"<<std::endl;
943 if(client.accessDenied())
945 error_message = L"Access denied. Reason: "
946 +client.accessDeniedReason();
947 std::cout<<DTIME<<wide_to_narrow(error_message)<<std::endl;
951 if(g_gamecallback->disconnect_requested)
953 g_gamecallback->disconnect_requested = false;
957 if(g_gamecallback->changepassword_requested)
959 (new GUIPasswordChange(guienv, guiroot, -1,
960 &g_menumgr, &client))->drop();
961 g_gamecallback->changepassword_requested = false;
965 Process TextureSource's queue
967 ((TextureSource*)g_texturesource)->processQueue();
972 last_screensize = screensize;
973 screensize = driver->getScreenSize();
974 v2s32 displaycenter(screensize.X/2,screensize.Y/2);
975 //bool screensize_changed = screensize != last_screensize;
978 if(screensize.Y <= 800)
979 hotbar_imagesize = 32;
980 else if(screensize.Y <= 1280)
981 hotbar_imagesize = 48;
983 hotbar_imagesize = 64;
985 // Hilight boxes collected during the loop and displayed
986 core::list< core::aabbox3d<f32> > hilightboxes;
989 std::wstring infotext;
991 // When screen size changes, update positions and sizes of stuff
992 /*if(screensize_changed)
994 v2s32 pos(displaycenter.X-((quickinv_itemcount-1)*quickinv_spacing+quickinv_size)/2, screensize.Y-quickinv_spacing);
995 quick_inventory->updatePosition(pos);
998 //TimeTaker //timer1("//timer1");
1000 // Time of frame without fps limit
1004 // not using getRealTime is necessary for wine
1005 u32 time = device->getTimer()->getTime();
1007 busytime_u32 = time - lasttime;
1010 busytime = busytime_u32 / 1000.0;
1013 //std::cout<<"busytime_u32="<<busytime_u32<<std::endl;
1015 // Necessary for device->getTimer()->getTime()
1023 float fps_max = g_settings.getFloat("fps_max");
1024 u32 frametime_min = 1000./fps_max;
1026 if(busytime_u32 < frametime_min)
1028 u32 sleeptime = frametime_min - busytime_u32;
1029 device->sleep(sleeptime);
1033 // Necessary for device->getTimer()->getTime()
1037 Time difference calculation
1039 f32 dtime; // in seconds
1041 u32 time = device->getTimer()->getTime();
1043 dtime = (time - lasttime) / 1000.0;
1049 Log frametime for visualization
1051 frametime_log.push_back(dtime);
1052 if(frametime_log.size() > 100)
1054 core::list<float>::Iterator i = frametime_log.begin();
1055 frametime_log.erase(i);
1059 Visualize frametime in terminal
1061 /*for(u32 i=0; i<dtime*400; i++)
1063 std::cout<<std::endl;*/
1066 Time average and jitter calculation
1069 static f32 dtime_avg1 = 0.0;
1070 dtime_avg1 = dtime_avg1 * 0.96 + dtime * 0.04;
1071 f32 dtime_jitter1 = dtime - dtime_avg1;
1073 static f32 dtime_jitter1_max_sample = 0.0;
1074 static f32 dtime_jitter1_max_fraction = 0.0;
1076 static f32 jitter1_max = 0.0;
1077 static f32 counter = 0.0;
1078 if(dtime_jitter1 > jitter1_max)
1079 jitter1_max = dtime_jitter1;
1084 dtime_jitter1_max_sample = jitter1_max;
1085 dtime_jitter1_max_fraction
1086 = dtime_jitter1_max_sample / (dtime_avg1+0.001);
1092 Busytime average and jitter calculation
1095 static f32 busytime_avg1 = 0.0;
1096 busytime_avg1 = busytime_avg1 * 0.98 + busytime * 0.02;
1097 f32 busytime_jitter1 = busytime - busytime_avg1;
1099 static f32 busytime_jitter1_max_sample = 0.0;
1100 static f32 busytime_jitter1_min_sample = 0.0;
1102 static f32 jitter1_max = 0.0;
1103 static f32 jitter1_min = 0.0;
1104 static f32 counter = 0.0;
1105 if(busytime_jitter1 > jitter1_max)
1106 jitter1_max = busytime_jitter1;
1107 if(busytime_jitter1 < jitter1_min)
1108 jitter1_min = busytime_jitter1;
1112 busytime_jitter1_max_sample = jitter1_max;
1113 busytime_jitter1_min_sample = jitter1_min;
1120 Debug info for client
1123 static float counter = 0.0;
1128 client.printDebugInfo(std::cout);
1135 float profiler_print_interval =
1136 g_settings.getFloat("profiler_print_interval");
1137 if(profiler_print_interval != 0)
1139 if(m_profiler_interval.step(0.030, profiler_print_interval))
1141 dstream<<"Profiler:"<<std::endl;
1142 g_profiler.print(dstream);
1148 Direct handling of user input
1151 // Reset input if window not active or some menu is active
1152 if(device->isWindowActive() == false || noMenuActive() == false)
1157 // Input handler step() (used by the random input generator)
1161 Launch menus according to keys
1163 if(input->wasKeyDown(getKeySetting("keymap_inventory")))
1165 dstream<<DTIME<<"the_game: "
1166 <<"Launching inventory"<<std::endl;
1168 GUIInventoryMenu *menu =
1169 new GUIInventoryMenu(guienv, guiroot, -1,
1170 &g_menumgr, v2s16(8,7),
1171 client.getInventoryContext(),
1174 core::array<GUIInventoryMenu::DrawSpec> draw_spec;
1175 draw_spec.push_back(GUIInventoryMenu::DrawSpec(
1176 "list", "current_player", "main",
1177 v2s32(0, 3), v2s32(8, 4)));
1178 draw_spec.push_back(GUIInventoryMenu::DrawSpec(
1179 "list", "current_player", "craft",
1180 v2s32(3, 0), v2s32(3, 3)));
1181 draw_spec.push_back(GUIInventoryMenu::DrawSpec(
1182 "list", "current_player", "craftresult",
1183 v2s32(7, 1), v2s32(1, 1)));
1185 menu->setDrawSpec(draw_spec);
1189 else if(input->wasKeyDown(EscapeKey))
1191 dstream<<DTIME<<"the_game: "
1192 <<"Launching pause menu"<<std::endl;
1193 // It will delete itself by itself
1194 (new GUIPauseMenu(guienv, guiroot, -1, g_gamecallback,
1195 &g_menumgr))->drop();
1197 // Move mouse cursor on top of the disconnect button
1198 input->setMousePos(displaycenter.X, displaycenter.Y+25);
1200 else if(input->wasKeyDown(getKeySetting("keymap_chat")))
1202 TextDest *dest = new TextDestChat(&client);
1204 (new GUITextInputMenu(guienv, guiroot, -1,
1208 else if(input->wasKeyDown(getKeySetting("keymap_cmd")))
1210 TextDest *dest = new TextDestChat(&client);
1212 (new GUITextInputMenu(guienv, guiroot, -1,
1216 else if(input->wasKeyDown(getKeySetting("keymap_freemove")))
1218 if(g_settings.getBool("free_move"))
1220 g_settings.set("free_move","false");
1221 chat_lines.push_back(ChatLine(L"free_move disabled"));
1225 g_settings.set("free_move","true");
1226 chat_lines.push_back(ChatLine(L"free_move enabled"));
1229 else if(input->wasKeyDown(getKeySetting("keymap_fastmove")))
1231 if(g_settings.getBool("fast_move"))
1233 g_settings.set("fast_move","false");
1234 chat_lines.push_back(ChatLine(L"fast_move disabled"));
1238 g_settings.set("fast_move","true");
1239 chat_lines.push_back(ChatLine(L"fast_move enabled"));
1242 else if(input->wasKeyDown(getKeySetting("keymap_frametime_graph")))
1244 if(g_settings.getBool("frametime_graph"))
1246 g_settings.set("frametime_graph","false");
1247 chat_lines.push_back(ChatLine(L"frametime_graph disabled"));
1251 g_settings.set("frametime_graph","true");
1252 chat_lines.push_back(ChatLine(L"frametime_graph enabled"));
1255 else if(input->wasKeyDown(getKeySetting("keymap_screenshot")))
1257 irr::video::IImage* const image = driver->createScreenShot();
1259 irr::c8 filename[256];
1260 snprintf(filename, 256, "%s/screenshot_%u.png",
1261 g_settings.get("screenshot_path").c_str(),
1262 device->getTimer()->getRealTime());
1263 if (driver->writeImageToFile(image, filename)) {
1264 std::wstringstream sstr;
1265 sstr<<"Saved screenshot to '"<<filename<<"'";
1266 dstream<<"Saved screenshot to '"<<filename<<"'"<<std::endl;
1267 chat_lines.push_back(ChatLine(sstr.str()));
1269 dstream<<"Failed to save screenshot '"<<filename<<"'"<<std::endl;
1275 // Item selection with mouse wheel
1277 s32 wheel = input->getMouseWheel();
1278 u16 max_item = MYMIN(PLAYER_INVENTORY_SIZE-1,
1279 hotbar_itemcount-1);
1283 if(g_selected_item < max_item)
1286 g_selected_item = 0;
1290 if(g_selected_item > 0)
1293 g_selected_item = max_item;
1298 for(u16 i=0; i<10; i++)
1300 const KeyPress *kp = NumberKey + (i + 1) % 10;
1301 if(input->wasKeyDown(*kp))
1303 if(i < PLAYER_INVENTORY_SIZE && i < hotbar_itemcount)
1305 g_selected_item = i;
1307 dstream<<DTIME<<"Selected item: "
1308 <<g_selected_item<<std::endl;
1313 // Viewing range selection
1314 if(input->wasKeyDown(getKeySetting("keymap_rangeselect")))
1316 if(draw_control.range_all)
1318 draw_control.range_all = false;
1319 dstream<<DTIME<<"Disabled full viewing range"<<std::endl;
1323 draw_control.range_all = true;
1324 dstream<<DTIME<<"Enabled full viewing range"<<std::endl;
1328 // Print debug stacks
1329 if(input->wasKeyDown(getKeySetting("keymap_print_debug_stacks")))
1331 dstream<<"-----------------------------------------"
1333 dstream<<DTIME<<"Printing debug stacks:"<<std::endl;
1334 dstream<<"-----------------------------------------"
1336 debug_stacks_print();
1340 Player speed control
1341 TODO: Cache the keycodes from getKeySetting
1354 PlayerControl control(
1355 input->isKeyDown(getKeySetting("keymap_forward")),
1356 input->isKeyDown(getKeySetting("keymap_backward")),
1357 input->isKeyDown(getKeySetting("keymap_left")),
1358 input->isKeyDown(getKeySetting("keymap_right")),
1359 input->isKeyDown(getKeySetting("keymap_jump")),
1360 input->isKeyDown(getKeySetting("keymap_special1")),
1361 input->isKeyDown(getKeySetting("keymap_sneak")),
1365 client.setPlayerControl(control);
1374 //TimeTaker timer("server->step(dtime)");
1375 server->step(dtime);
1383 //TimeTaker timer("client.step(dtime)");
1385 //client.step(dtime_avg1);
1388 // Read client events
1391 ClientEvent event = client.getClientEvent();
1392 if(event.type == CE_NONE)
1396 else if(event.type == CE_PLAYER_DAMAGE)
1398 //u16 damage = event.player_damage.amount;
1399 //dstream<<"Player damage: "<<damage<<std::endl;
1400 damage_flash_timer = 0.05;
1402 else if(event.type == CE_PLAYER_FORCE_MOVE)
1404 camera_yaw = event.player_force_move.yaw;
1405 camera_pitch = event.player_force_move.pitch;
1409 //TimeTaker //timer2("//timer2");
1412 Mouse and camera control
1415 if((device->isWindowActive() && noMenuActive()) || random_input)
1419 // Mac OSX gets upset if this is set every frame
1420 if(device->getCursorControl()->isVisible())
1421 device->getCursorControl()->setVisible(false);
1424 if(first_loop_after_window_activation){
1425 //std::cout<<"window active, first loop"<<std::endl;
1426 first_loop_after_window_activation = false;
1429 s32 dx = input->getMousePos().X - displaycenter.X;
1430 s32 dy = input->getMousePos().Y - displaycenter.Y;
1433 //std::cout<<"window active, pos difference "<<dx<<","<<dy<<std::endl;
1435 /*const float keyspeed = 500;
1436 if(input->isKeyDown(irr::KEY_UP))
1437 dy -= dtime * keyspeed;
1438 if(input->isKeyDown(irr::KEY_DOWN))
1439 dy += dtime * keyspeed;
1440 if(input->isKeyDown(irr::KEY_LEFT))
1441 dx -= dtime * keyspeed;
1442 if(input->isKeyDown(irr::KEY_RIGHT))
1443 dx += dtime * keyspeed;*/
1445 camera_yaw -= dx*0.2;
1446 camera_pitch += dy*0.2;
1447 if(camera_pitch < -89.5) camera_pitch = -89.5;
1448 if(camera_pitch > 89.5) camera_pitch = 89.5;
1450 input->setMousePos(displaycenter.X, displaycenter.Y);
1453 // Mac OSX gets upset if this is set every frame
1454 if(device->getCursorControl()->isVisible() == false)
1455 device->getCursorControl()->setVisible(true);
1457 //std::cout<<"window inactive"<<std::endl;
1458 first_loop_after_window_activation = true;
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 MapBlockObject *selected_object = client.getSelectedObject
1495 (d*BS, camera_position, shootline);
1497 ClientActiveObject *selected_active_object
1498 = client.getSelectedActiveObject
1499 (d*BS, camera_position, shootline);
1501 if(selected_object != NULL)
1503 //dstream<<"Client returned selected_object != NULL"<<std::endl;
1505 core::aabbox3d<f32> box_on_map
1506 = selected_object->getSelectionBoxOnMap();
1508 hilightboxes.push_back(box_on_map);
1510 infotext = narrow_to_wide(selected_object->infoText());
1512 if(input->getLeftClicked())
1514 std::cout<<DTIME<<"Left-clicked object"<<std::endl;
1515 client.clickObject(0, selected_object->getBlock()->getPos(),
1516 selected_object->getId(), g_selected_item);
1518 else if(input->getRightClicked())
1520 std::cout<<DTIME<<"Right-clicked object"<<std::endl;
1522 Check if we want to modify the object ourselves
1524 if(selected_object->getTypeId() == MAPBLOCKOBJECT_TYPE_SIGN)
1526 dstream<<"Sign object right-clicked"<<std::endl;
1528 if(random_input == false)
1530 // Get a new text for it
1532 TextDest *dest = new TextDestSign(
1533 selected_object->getBlock()->getPos(),
1534 selected_object->getId(),
1537 SignObject *sign_object = (SignObject*)selected_object;
1539 std::wstring wtext =
1540 narrow_to_wide(sign_object->getText());
1542 (new GUITextInputMenu(guienv, guiroot, -1,
1548 Otherwise pass the event to the server as-is
1552 client.clickObject(1, selected_object->getBlock()->getPos(),
1553 selected_object->getId(), g_selected_item);
1557 else if(selected_active_object != NULL)
1559 //dstream<<"Client returned selected_active_object != NULL"<<std::endl;
1561 core::aabbox3d<f32> *selection_box
1562 = selected_active_object->getSelectionBox();
1563 // Box should exist because object was returned in the
1565 assert(selection_box);
1567 v3f pos = selected_active_object->getPosition();
1569 core::aabbox3d<f32> box_on_map(
1570 selection_box->MinEdge + pos,
1571 selection_box->MaxEdge + pos
1574 hilightboxes.push_back(box_on_map);
1576 //infotext = narrow_to_wide("A ClientActiveObject");
1577 infotext = narrow_to_wide(selected_active_object->infoText());
1579 if(input->getLeftClicked())
1581 std::cout<<DTIME<<"Left-clicked object"<<std::endl;
1582 client.clickActiveObject(0,
1583 selected_active_object->getId(), g_selected_item);
1585 else if(input->getRightClicked())
1587 std::cout<<DTIME<<"Right-clicked object"<<std::endl;
1588 client.clickActiveObject(1,
1589 selected_active_object->getId(), g_selected_item);
1592 else // selected_object == NULL
1596 Find out which node we are pointing at
1599 bool nodefound = false;
1602 core::aabbox3d<f32> nodehilightbox;
1604 getPointedNode(&client, player_position,
1605 camera_direction, camera_position,
1606 nodefound, shootline,
1607 nodepos, neighbourpos,
1610 static float nodig_delay_counter = 0.0;
1614 static v3s16 nodepos_old(-32768,-32768,-32768);
1616 static float dig_time = 0.0;
1617 static u16 dig_index = 0;
1623 hilightboxes.push_back(nodehilightbox);
1626 Check information text of node
1629 NodeMetadata *meta = client.getNodeMetadata(nodepos);
1632 infotext = narrow_to_wide(meta->infoText());
1635 //MapNode node = client.getNode(nodepos);
1641 if(input->getLeftReleased())
1643 client.clearTempMod(nodepos);
1647 if(nodig_delay_counter > 0.0)
1649 nodig_delay_counter -= dtime;
1653 if(nodepos != nodepos_old)
1655 std::cout<<DTIME<<"Pointing at ("<<nodepos.X<<","
1656 <<nodepos.Y<<","<<nodepos.Z<<")"<<std::endl;
1658 if(nodepos_old != v3s16(-32768,-32768,-32768))
1660 client.clearTempMod(nodepos_old);
1665 if(input->getLeftClicked() ||
1666 (input->getLeftState() && nodepos != nodepos_old))
1668 dstream<<DTIME<<"Started digging"<<std::endl;
1669 client.groundAction(0, nodepos, neighbourpos, g_selected_item);
1671 if(input->getLeftClicked())
1673 client.setTempMod(nodepos, NodeMod(NODEMOD_CRACK, 0));
1675 if(input->getLeftState())
1677 MapNode n = client.getNode(nodepos);
1679 // Get tool name. Default is "" = bare hands
1680 std::string toolname = "";
1681 InventoryList *mlist = local_inventory.getList("main");
1684 InventoryItem *item = mlist->getItem(g_selected_item);
1685 if(item && (std::string)item->getName() == "ToolItem")
1687 ToolItem *titem = (ToolItem*)item;
1688 toolname = titem->getToolName();
1692 // Get digging properties for material and tool
1693 content_t material = n.getContent();
1694 DiggingProperties prop =
1695 getDiggingProperties(material, toolname);
1697 float dig_time_complete = 0.0;
1699 if(prop.diggable == false)
1701 /*dstream<<"Material "<<(int)material
1702 <<" not diggable with \""
1703 <<toolname<<"\""<<std::endl;*/
1704 // I guess nobody will wait for this long
1705 dig_time_complete = 10000000.0;
1709 dig_time_complete = prop.time;
1712 if(dig_time_complete >= 0.001)
1714 dig_index = (u16)((float)CRACK_ANIMATION_LENGTH
1715 * dig_time/dig_time_complete);
1717 // This is for torches
1720 dig_index = CRACK_ANIMATION_LENGTH;
1723 if(dig_index < CRACK_ANIMATION_LENGTH)
1725 //TimeTaker timer("client.setTempMod");
1726 //dstream<<"dig_index="<<dig_index<<std::endl;
1727 client.setTempMod(nodepos, NodeMod(NODEMOD_CRACK, dig_index));
1731 dstream<<DTIME<<"Digging completed"<<std::endl;
1732 client.groundAction(3, nodepos, neighbourpos, g_selected_item);
1733 client.clearTempMod(nodepos);
1734 client.removeNode(nodepos);
1738 nodig_delay_counter = dig_time_complete
1739 / (float)CRACK_ANIMATION_LENGTH;
1741 // We don't want a corresponding delay to
1742 // very time consuming nodes
1743 if(nodig_delay_counter > 0.5)
1745 nodig_delay_counter = 0.5;
1747 // We want a slight delay to very little
1748 // time consuming nodes
1749 float mindelay = 0.15;
1750 if(nodig_delay_counter < mindelay)
1752 nodig_delay_counter = mindelay;
1758 camera.setDigging(0); // left click animation
1763 if(input->getRightClicked())
1765 std::cout<<DTIME<<"Ground right-clicked"<<std::endl;
1767 // If metadata provides an inventory view, activate it
1768 if(meta && meta->getInventoryDrawSpecString() != "" && !random_input)
1770 dstream<<DTIME<<"Launching custom inventory view"<<std::endl;
1772 Construct the unique identification string of the node
1774 std::string current_name;
1775 current_name += "nodemeta:";
1776 current_name += itos(nodepos.X);
1777 current_name += ",";
1778 current_name += itos(nodepos.Y);
1779 current_name += ",";
1780 current_name += itos(nodepos.Z);
1786 core::array<GUIInventoryMenu::DrawSpec> draw_spec;
1788 GUIInventoryMenu::makeDrawSpecArrayFromString(
1790 meta->getInventoryDrawSpecString(),
1793 GUIInventoryMenu *menu =
1794 new GUIInventoryMenu(guienv, guiroot, -1,
1795 &g_menumgr, invsize,
1796 client.getInventoryContext(),
1798 menu->setDrawSpec(draw_spec);
1801 else if(meta && meta->typeId() == CONTENT_SIGN_WALL && !random_input)
1803 dstream<<"Sign node right-clicked"<<std::endl;
1805 SignNodeMetadata *signmeta = (SignNodeMetadata*)meta;
1807 // Get a new text for it
1809 TextDest *dest = new TextDestSignNode(nodepos, &client);
1811 std::wstring wtext =
1812 narrow_to_wide(signmeta->getText());
1814 (new GUITextInputMenu(guienv, guiroot, -1,
1820 client.groundAction(1, nodepos, neighbourpos, g_selected_item);
1821 camera.setDigging(1); // right click animation
1825 nodepos_old = nodepos;
1828 } // selected_object == NULL
1830 if(input->getLeftClicked())
1832 camera.setDigging(0); // left click animation
1835 input->resetLeftClicked();
1836 input->resetRightClicked();
1838 if(input->getLeftReleased())
1840 std::cout<<DTIME<<"Left button released (stopped digging)"
1842 client.groundAction(2, v3s16(0,0,0), v3s16(0,0,0), 0);
1844 if(input->getRightReleased())
1846 //std::cout<<DTIME<<"Right released"<<std::endl;
1850 input->resetLeftReleased();
1851 input->resetRightReleased();
1854 Calculate stuff for drawing
1857 u32 daynight_ratio = client.getDayNightRatio();
1858 u8 l = decode_light((daynight_ratio * LIGHT_SUN) / 1000);
1859 video::SColor bgcolor = video::SColor(
1861 bgcolor_bright.getRed() * l / 255,
1862 bgcolor_bright.getGreen() * l / 255,
1863 bgcolor_bright.getBlue() * l / 255);
1864 /*skycolor.getRed() * l / 255,
1865 skycolor.getGreen() * l / 255,
1866 skycolor.getBlue() * l / 255);*/
1868 float brightness = (float)l/255.0;
1873 if(fabs(brightness - old_brightness) > 0.01)
1874 update_skybox(driver, smgr, skybox, brightness);
1881 clouds->step(dtime);
1882 clouds->update(v2f(player_position.X, player_position.Z),
1883 0.05+brightness*0.95);
1891 farmesh_range = draw_control.wanted_range * 10;
1892 if(draw_control.range_all && farmesh_range < 500)
1893 farmesh_range = 500;
1894 if(farmesh_range > 1000)
1895 farmesh_range = 1000;
1897 farmesh->step(dtime);
1898 farmesh->update(v2f(player_position.X, player_position.Z),
1899 0.05+brightness*0.95, farmesh_range);
1902 // Store brightness value
1903 old_brightness = brightness;
1909 if(g_settings.getBool("enable_fog") == true)
1914 range = BS*farmesh_range;
1918 range = draw_control.wanted_range*BS + MAP_BLOCKSIZE*BS*1.5;
1919 if(draw_control.range_all)
1922 range = range * 0.5 + 25*BS;
1927 video::EFT_FOG_LINEAR,
1939 video::EFT_FOG_LINEAR,
1949 Update gui stuff (0ms)
1952 //TimeTaker guiupdatetimer("Gui updating");
1955 static float drawtime_avg = 0;
1956 drawtime_avg = drawtime_avg * 0.95 + (float)drawtime*0.05;
1957 static float beginscenetime_avg = 0;
1958 beginscenetime_avg = beginscenetime_avg * 0.95 + (float)beginscenetime*0.05;
1959 static float scenetime_avg = 0;
1960 scenetime_avg = scenetime_avg * 0.95 + (float)scenetime*0.05;
1961 static float endscenetime_avg = 0;
1962 endscenetime_avg = endscenetime_avg * 0.95 + (float)endscenetime*0.05;
1965 snprintf(temptext, 300, "Minetest-c55 %s ("
1968 " drawtime=%.0f, beginscenetime=%.0f"
1969 ", scenetime=%.0f, endscenetime=%.0f",
1971 draw_control.range_all,
1978 guitext->setText(narrow_to_wide(temptext).c_str());
1983 snprintf(temptext, 300,
1984 "(% .1f, % .1f, % .1f)"
1985 " (% .3f < btime_jitter < % .3f"
1986 ", dtime_jitter = % .1f %%"
1987 ", v_range = %.1f)",
1988 player_position.X/BS,
1989 player_position.Y/BS,
1990 player_position.Z/BS,
1991 busytime_jitter1_min_sample,
1992 busytime_jitter1_max_sample,
1993 dtime_jitter1_max_fraction * 100.0,
1994 draw_control.wanted_range
1997 guitext2->setText(narrow_to_wide(temptext).c_str());
2001 guitext_info->setText(infotext.c_str());
2005 Get chat messages from client
2009 std::wstring message;
2010 while(client.getChatMessage(message))
2012 chat_lines.push_back(ChatLine(message));
2013 /*if(chat_lines.size() > 6)
2015 core::list<ChatLine>::Iterator
2016 i = chat_lines.begin();
2017 chat_lines.erase(i);
2020 // Append them to form the whole static text and throw
2021 // it to the gui element
2023 // This will correspond to the line number counted from
2024 // top to bottom, from size-1 to 0
2025 s16 line_number = chat_lines.size();
2026 // Count of messages to be removed from the top
2027 u16 to_be_removed_count = 0;
2028 for(core::list<ChatLine>::Iterator
2029 i = chat_lines.begin();
2030 i != chat_lines.end(); i++)
2032 // After this, line number is valid for this loop
2037 This results in a maximum age of 60*6 to the
2038 lowermost line and a maximum of 6 lines
2040 float allowed_age = (6-line_number) * 60.0;
2042 if((*i).age > allowed_age)
2044 to_be_removed_count++;
2047 whole += (*i).text + L'\n';
2049 for(u16 i=0; i<to_be_removed_count; i++)
2051 core::list<ChatLine>::Iterator
2052 it = chat_lines.begin();
2053 chat_lines.erase(it);
2055 guitext_chat->setText(whole.c_str());
2057 // Update gui element size and position
2059 /*core::rect<s32> rect(
2061 screensize.Y - guitext_chat_pad_bottom
2062 - text_height*chat_lines.size(),
2064 screensize.Y - guitext_chat_pad_bottom
2066 core::rect<s32> rect(
2070 50 + guitext_chat->getTextHeight()
2073 guitext_chat->setRelativePosition(rect);
2075 if(chat_lines.size() == 0)
2076 guitext_chat->setVisible(false);
2078 guitext_chat->setVisible(true);
2085 static u16 old_selected_item = 65535;
2086 if(client.getLocalInventoryUpdated()
2087 || g_selected_item != old_selected_item)
2089 client.selectPlayerItem(g_selected_item);
2090 old_selected_item = g_selected_item;
2091 //std::cout<<"Updating local inventory"<<std::endl;
2092 client.getLocalInventory(local_inventory);
2094 // Update wielded tool
2095 InventoryList *mlist = local_inventory.getList("main");
2096 InventoryItem *item = NULL;
2098 item = mlist->getItem(g_selected_item);
2103 Send actions returned by the inventory menu
2105 while(inventory_action_queue.size() != 0)
2107 InventoryAction *a = inventory_action_queue.pop_front();
2109 client.sendInventoryAction(a);
2118 TimeTaker drawtimer("Drawing");
2122 TimeTaker timer("beginScene");
2123 driver->beginScene(true, true, bgcolor);
2124 //driver->beginScene(false, true, bgcolor);
2125 beginscenetime = timer.stop(true);
2130 //std::cout<<DTIME<<"smgr->drawAll()"<<std::endl;
2133 TimeTaker timer("smgr");
2135 scenetime = timer.stop(true);
2139 //TimeTaker timer9("auxiliary drawings");
2143 //TimeTaker //timer10("//timer10");
2149 driver->setMaterial(m);
2151 driver->setTransform(video::ETS_WORLD, core::IdentityMatrix);
2153 for(core::list< core::aabbox3d<f32> >::Iterator i=hilightboxes.begin();
2154 i != hilightboxes.end(); i++)
2156 /*std::cout<<"hilightbox min="
2157 <<"("<<i->MinEdge.X<<","<<i->MinEdge.Y<<","<<i->MinEdge.Z<<")"
2159 <<"("<<i->MaxEdge.X<<","<<i->MaxEdge.Y<<","<<i->MaxEdge.Z<<")"
2161 driver->draw3DBox(*i, video::SColor(255,0,0,0));
2168 // Warning: This clears the Z buffer.
2169 camera.drawWieldedTool();
2176 client.renderPostFx();
2182 if(g_settings.getBool("frametime_graph") == true)
2185 for(core::list<float>::Iterator
2186 i = frametime_log.begin();
2187 i != frametime_log.end();
2190 driver->draw2DLine(v2s32(x,50),
2191 v2s32(x,50+(*i)*1000),
2192 video::SColor(255,255,255,255));
2200 driver->draw2DLine(displaycenter - core::vector2d<s32>(10,0),
2201 displaycenter + core::vector2d<s32>(10,0),
2202 video::SColor(255,255,255,255));
2203 driver->draw2DLine(displaycenter - core::vector2d<s32>(0,10),
2204 displaycenter + core::vector2d<s32>(0,10),
2205 video::SColor(255,255,255,255));
2210 //TimeTaker //timer11("//timer11");
2222 draw_hotbar(driver, font, v2s32(displaycenter.X, screensize.Y),
2223 hotbar_imagesize, hotbar_itemcount, &local_inventory,
2230 if(damage_flash_timer > 0.0)
2232 damage_flash_timer -= dtime;
2234 video::SColor color(128,255,0,0);
2235 driver->draw2DRectangle(color,
2236 core::rect<s32>(0,0,screensize.X,screensize.Y),
2244 TimeTaker timer("endScene");
2246 endscenetime = timer.stop(true);
2249 drawtime = drawtimer.stop(true);
2255 static s16 lastFPS = 0;
2256 //u16 fps = driver->getFPS();
2257 u16 fps = (1.0/dtime_avg1);
2261 core::stringw str = L"Minetest [";
2262 str += driver->getName();
2266 device->setWindowCaption(str.c_str());
2278 Draw a "shutting down" screen, which will be shown while the map
2279 generator and other stuff quits
2282 /*gui::IGUIStaticText *gui_shuttingdowntext = */
2283 draw_load_screen(L"Shutting down stuff...", driver, font);
2284 /*driver->beginScene(true, true, video::SColor(255,0,0,0));
2287 gui_shuttingdowntext->remove();*/