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 "guiDeathScreen.h"
34 #include "materials.h"
42 #include "mainmenumanager.h"
48 TODO: Move content-aware stuff to separate file by adding properties
49 and virtual interfaces
51 #include "content_mapnode.h"
52 #include "content_nodemeta.h"
55 Setting this to 1 enables a special camera mode that forces
56 the renderers to think that the camera statically points from
57 the starting place to a static direction.
59 This allows one to move around with the player and see what
60 is actually drawn behind solid things and behind the player.
62 #define FIELD_OF_VIEW_TEST 0
72 ChatLine(const std::wstring &a_text):
85 // Inventory actions from the menu are buffered here before sending
86 Queue<InventoryAction*> inventory_action_queue;
87 // This is a copy of the inventory that the client's environment has
88 Inventory local_inventory;
90 u16 g_selected_item = 0;
96 struct TextDestChat : public TextDest
98 TextDestChat(Client *client)
102 void gotText(std::wstring text)
104 // Discard empty line
109 m_client->sendChatMessage(text);
111 m_client->addChatMessage(text);
117 struct TextDestSignNode : public TextDest
119 TextDestSignNode(v3s16 p, Client *client)
124 void gotText(std::wstring text)
126 std::string ntext = wide_to_narrow(text);
127 infostream<<"Changing text of a sign node: "
129 m_client->sendSignNodeText(m_p, ntext);
136 /* Respawn menu callback */
138 class MainRespawnInitiator: public IRespawnInitiator
141 MainRespawnInitiator(bool *active, Client *client):
142 m_active(active), m_client(client)
149 m_client->sendRespawn();
159 void draw_hotbar(video::IVideoDriver *driver, gui::IGUIFont *font,
160 v2s32 centerlowerpos, s32 imgsize, s32 itemcount,
161 Inventory *inventory, s32 halfheartcount)
163 InventoryList *mainlist = inventory->getList("main");
166 errorstream<<"draw_hotbar(): mainlist == NULL"<<std::endl;
170 s32 padding = imgsize/12;
171 //s32 height = imgsize + padding*2;
172 s32 width = itemcount*(imgsize+padding*2);
174 // Position of upper left corner of bar
175 v2s32 pos = centerlowerpos - v2s32(width/2, imgsize+padding*2);
177 // Draw background color
178 /*core::rect<s32> barrect(0,0,width,height);
180 video::SColor bgcolor(255,128,128,128);
181 driver->draw2DRectangle(bgcolor, barrect, NULL);*/
183 core::rect<s32> imgrect(0,0,imgsize,imgsize);
185 for(s32 i=0; i<itemcount; i++)
187 InventoryItem *item = mainlist->getItem(i);
189 core::rect<s32> rect = imgrect + pos
190 + v2s32(padding+i*(imgsize+padding*2), padding);
192 if(g_selected_item == i)
194 video::SColor c_outside(255,255,0,0);
195 //video::SColor c_outside(255,0,0,0);
196 //video::SColor c_inside(255,192,192,192);
197 s32 x1 = rect.UpperLeftCorner.X;
198 s32 y1 = rect.UpperLeftCorner.Y;
199 s32 x2 = rect.LowerRightCorner.X;
200 s32 y2 = rect.LowerRightCorner.Y;
201 // Black base borders
202 driver->draw2DRectangle(c_outside,
204 v2s32(x1 - padding, y1 - padding),
205 v2s32(x2 + padding, y1)
207 driver->draw2DRectangle(c_outside,
209 v2s32(x1 - padding, y2),
210 v2s32(x2 + padding, y2 + padding)
212 driver->draw2DRectangle(c_outside,
214 v2s32(x1 - padding, y1),
217 driver->draw2DRectangle(c_outside,
220 v2s32(x2 + padding, y2)
222 /*// Light inside borders
223 driver->draw2DRectangle(c_inside,
225 v2s32(x1 - padding/2, y1 - padding/2),
226 v2s32(x2 + padding/2, y1)
228 driver->draw2DRectangle(c_inside,
230 v2s32(x1 - padding/2, y2),
231 v2s32(x2 + padding/2, y2 + padding/2)
233 driver->draw2DRectangle(c_inside,
235 v2s32(x1 - padding/2, y1),
238 driver->draw2DRectangle(c_inside,
241 v2s32(x2 + padding/2, y2)
246 video::SColor bgcolor2(128,0,0,0);
247 driver->draw2DRectangle(bgcolor2, rect, NULL);
251 drawInventoryItem(driver, font, item, rect, NULL);
259 video::ITexture *heart_texture =
260 driver->getTexture(getTexturePath("heart.png").c_str());
261 v2s32 p = pos + v2s32(0, -20);
262 for(s32 i=0; i<halfheartcount/2; i++)
264 const video::SColor color(255,255,255,255);
265 const video::SColor colors[] = {color,color,color,color};
266 core::rect<s32> rect(0,0,16,16);
268 driver->draw2DImage(heart_texture, rect,
269 core::rect<s32>(core::position2d<s32>(0,0),
270 core::dimension2di(heart_texture->getOriginalSize())),
274 if(halfheartcount % 2 == 1)
276 const video::SColor color(255,255,255,255);
277 const video::SColor colors[] = {color,color,color,color};
278 core::rect<s32> rect(0,0,16/2,16);
280 core::dimension2di srcd(heart_texture->getOriginalSize());
282 driver->draw2DImage(heart_texture, rect,
283 core::rect<s32>(core::position2d<s32>(0,0), srcd),
291 Find what the player is pointing at
293 void getPointedNode(Client *client, v3f player_position,
294 v3f camera_direction, v3f camera_position,
295 bool &nodefound, core::line3d<f32> shootline,
296 v3s16 &nodepos, v3s16 &neighbourpos,
297 core::aabbox3d<f32> &nodehilightbox,
300 f32 mindistance = BS * 1001;
302 v3s16 pos_i = floatToInt(player_position, BS);
304 /*infostream<<"pos_i=("<<pos_i.X<<","<<pos_i.Y<<","<<pos_i.Z<<")"
308 s16 ystart = pos_i.Y + 0 - (camera_direction.Y<0 ? a : 1);
309 s16 zstart = pos_i.Z - (camera_direction.Z<0 ? a : 1);
310 s16 xstart = pos_i.X - (camera_direction.X<0 ? a : 1);
311 s16 yend = pos_i.Y + 1 + (camera_direction.Y>0 ? a : 1);
312 s16 zend = pos_i.Z + (camera_direction.Z>0 ? a : 1);
313 s16 xend = pos_i.X + (camera_direction.X>0 ? a : 1);
315 for(s16 y = ystart; y <= yend; y++)
316 for(s16 z = zstart; z <= zend; z++)
317 for(s16 x = xstart; x <= xend; x++)
322 n = client->getNode(v3s16(x,y,z));
323 if(content_pointable(n.getContent()) == false)
326 catch(InvalidPositionException &e)
332 v3f npf = intToFloat(np, BS);
337 v3s16(0,0,1), // back
339 v3s16(1,0,0), // right
340 v3s16(0,0,-1), // front
341 v3s16(0,-1,0), // bottom
342 v3s16(-1,0,0), // left
348 if(n.getContent() == CONTENT_TORCH)
350 v3s16 dir = unpackDir(n.param2);
351 v3f dir_f = v3f(dir.X, dir.Y, dir.Z);
352 dir_f *= BS/2 - BS/6 - BS/20;
353 v3f cpf = npf + dir_f;
354 f32 distance = (cpf - camera_position).getLength();
356 core::aabbox3d<f32> box;
359 if(dir == v3s16(0,-1,0))
361 box = core::aabbox3d<f32>(
362 npf - v3f(BS/6, BS/2, BS/6),
363 npf + v3f(BS/6, -BS/2+BS/3*2, BS/6)
367 else if(dir == v3s16(0,1,0))
369 box = core::aabbox3d<f32>(
370 npf - v3f(BS/6, -BS/2+BS/3*2, BS/6),
371 npf + v3f(BS/6, BS/2, BS/6)
377 box = core::aabbox3d<f32>(
378 cpf - v3f(BS/6, BS/3, BS/6),
379 cpf + v3f(BS/6, BS/3, BS/6)
383 if(distance < mindistance)
385 if(box.intersectsWithLine(shootline))
390 mindistance = distance;
391 nodehilightbox = box;
395 else if(n.getContent() == CONTENT_SIGN_WALL)
397 v3s16 dir = unpackDir(n.param2);
398 v3f dir_f = v3f(dir.X, dir.Y, dir.Z);
399 dir_f *= BS/2 - BS/6 - BS/20;
400 v3f cpf = npf + dir_f;
401 f32 distance = (cpf - camera_position).getLength();
405 v3f(BS*0.42,-BS*0.35,-BS*0.4),
406 v3f(BS*0.49, BS*0.35, BS*0.4),
409 for(s32 i=0; i<2; i++)
411 if(dir == v3s16(1,0,0))
412 vertices[i].rotateXZBy(0);
413 if(dir == v3s16(-1,0,0))
414 vertices[i].rotateXZBy(180);
415 if(dir == v3s16(0,0,1))
416 vertices[i].rotateXZBy(90);
417 if(dir == v3s16(0,0,-1))
418 vertices[i].rotateXZBy(-90);
419 if(dir == v3s16(0,-1,0))
420 vertices[i].rotateXYBy(-90);
421 if(dir == v3s16(0,1,0))
422 vertices[i].rotateXYBy(90);
427 core::aabbox3d<f32> box;
429 box = core::aabbox3d<f32>(vertices[0]);
430 box.addInternalPoint(vertices[1]);
432 if(distance < mindistance)
434 if(box.intersectsWithLine(shootline))
439 mindistance = distance;
440 nodehilightbox = box;
445 else if(n.getContent() == CONTENT_LADDER)
447 v3s16 dir = unpackDir(n.param2);
448 v3f dir_f = v3f(dir.X, dir.Y, dir.Z);
449 dir_f *= BS/2 - BS/6 - BS/20;
450 v3f cpf = npf + dir_f;
451 f32 distance = (cpf - camera_position).getLength();
455 v3f(BS*0.42,-BS/2,-BS/2),
456 v3f(BS*0.49, BS/2, BS/2),
459 for(s32 i=0; i<2; i++)
461 if(dir == v3s16(1,0,0))
462 vertices[i].rotateXZBy(0);
463 if(dir == v3s16(-1,0,0))
464 vertices[i].rotateXZBy(180);
465 if(dir == v3s16(0,0,1))
466 vertices[i].rotateXZBy(90);
467 if(dir == v3s16(0,0,-1))
468 vertices[i].rotateXZBy(-90);
469 if(dir == v3s16(0,-1,0))
470 vertices[i].rotateXYBy(-90);
471 if(dir == v3s16(0,1,0))
472 vertices[i].rotateXYBy(90);
477 core::aabbox3d<f32> box;
479 box = core::aabbox3d<f32>(vertices[0]);
480 box.addInternalPoint(vertices[1]);
482 if(distance < mindistance)
484 if(box.intersectsWithLine(shootline))
489 mindistance = distance;
490 nodehilightbox = box;
494 else if(n.getContent() == CONTENT_RAIL)
496 v3s16 dir = unpackDir(n.param0);
497 v3f dir_f = v3f(dir.X, dir.Y, dir.Z);
498 dir_f *= BS/2 - BS/6 - BS/20;
499 v3f cpf = npf + dir_f;
500 f32 distance = (cpf - camera_position).getLength();
502 float d = (float)BS/16;
505 v3f(BS/2, -BS/2+d, -BS/2),
506 v3f(-BS/2, -BS/2, BS/2),
509 for(s32 i=0; i<2; i++)
514 core::aabbox3d<f32> box;
516 box = core::aabbox3d<f32>(vertices[0]);
517 box.addInternalPoint(vertices[1]);
519 if(distance < mindistance)
521 if(box.intersectsWithLine(shootline))
526 mindistance = distance;
527 nodehilightbox = box;
536 for(u16 i=0; i<6; i++)
538 v3f dir_f = v3f(dirs[i].X,
539 dirs[i].Y, dirs[i].Z);
540 v3f centerpoint = npf + dir_f * BS/2;
542 (centerpoint - camera_position).getLength();
544 if(distance < mindistance)
546 core::CMatrix4<f32> m;
547 m.buildRotateFromTo(v3f(0,0,1), dir_f);
549 // This is the back face
551 v3f(BS/2, BS/2, BS/2),
552 v3f(-BS/2, -BS/2, BS/2+d)
555 for(u16 j=0; j<2; j++)
557 m.rotateVect(corners[j]);
561 core::aabbox3d<f32> facebox(corners[0]);
562 facebox.addInternalPoint(corners[1]);
564 if(facebox.intersectsWithLine(shootline))
568 neighbourpos = np + dirs[i];
569 mindistance = distance;
571 //nodehilightbox = facebox;
573 const float d = 0.502;
574 core::aabbox3d<f32> nodebox
575 (-BS*d, -BS*d, -BS*d, BS*d, BS*d, BS*d);
576 v3f nodepos_f = intToFloat(nodepos, BS);
577 nodebox.MinEdge += nodepos_f;
578 nodebox.MaxEdge += nodepos_f;
579 nodehilightbox = nodebox;
581 } // if distance < mindistance
587 void update_skybox(video::IVideoDriver* driver,
588 scene::ISceneManager* smgr, scene::ISceneNode* &skybox,
596 /*// Disable skybox if FarMesh is enabled
597 if(g_settings->getBool("enable_farmesh"))
600 if(brightness >= 0.5)
602 skybox = smgr->addSkyBoxSceneNode(
603 driver->getTexture(getTexturePath("skybox2.png").c_str()),
604 driver->getTexture(getTexturePath("skybox3.png").c_str()),
605 driver->getTexture(getTexturePath("skybox1.png").c_str()),
606 driver->getTexture(getTexturePath("skybox1.png").c_str()),
607 driver->getTexture(getTexturePath("skybox1.png").c_str()),
608 driver->getTexture(getTexturePath("skybox1.png").c_str()));
610 else if(brightness >= 0.2)
612 skybox = smgr->addSkyBoxSceneNode(
613 driver->getTexture(getTexturePath("skybox2_dawn.png").c_str()),
614 driver->getTexture(getTexturePath("skybox3_dawn.png").c_str()),
615 driver->getTexture(getTexturePath("skybox1_dawn.png").c_str()),
616 driver->getTexture(getTexturePath("skybox1_dawn.png").c_str()),
617 driver->getTexture(getTexturePath("skybox1_dawn.png").c_str()),
618 driver->getTexture(getTexturePath("skybox1_dawn.png").c_str()));
622 skybox = smgr->addSkyBoxSceneNode(
623 driver->getTexture(getTexturePath("skybox2_night.png").c_str()),
624 driver->getTexture(getTexturePath("skybox3_night.png").c_str()),
625 driver->getTexture(getTexturePath("skybox1_night.png").c_str()),
626 driver->getTexture(getTexturePath("skybox1_night.png").c_str()),
627 driver->getTexture(getTexturePath("skybox1_night.png").c_str()),
628 driver->getTexture(getTexturePath("skybox1_night.png").c_str()));
633 Draws a screen with a single text on it.
634 Text will be removed when the screen is drawn the next time.
636 /*gui::IGUIStaticText **/
637 void draw_load_screen(const std::wstring &text,
638 video::IVideoDriver* driver, gui::IGUIFont* font)
640 v2u32 screensize = driver->getScreenSize();
641 const wchar_t *loadingtext = text.c_str();
642 core::vector2d<u32> textsize_u = font->getDimension(loadingtext);
643 core::vector2d<s32> textsize(textsize_u.X,textsize_u.Y);
644 core::vector2d<s32> center(screensize.X/2, screensize.Y/2);
645 core::rect<s32> textrect(center - textsize/2, center + textsize/2);
647 gui::IGUIStaticText *guitext = guienv->addStaticText(
648 loadingtext, textrect, false, false);
649 guitext->setTextAlignment(gui::EGUIA_CENTER, gui::EGUIA_UPPERLEFT);
651 driver->beginScene(true, true, video::SColor(255,0,0,0));
664 IrrlichtDevice *device,
667 std::string playername,
668 std::string password,
671 std::wstring &error_message,
672 std::string configpath
675 video::IVideoDriver* driver = device->getVideoDriver();
676 scene::ISceneManager* smgr = device->getSceneManager();
678 // Calculate text height using the font
679 u32 text_height = font->getDimension(L"Random test string").Height;
681 v2u32 screensize(0,0);
682 v2u32 last_screensize(0,0);
683 screensize = driver->getScreenSize();
685 const s32 hotbar_itemcount = 8;
686 //const s32 hotbar_imagesize = 36;
687 //const s32 hotbar_imagesize = 64;
688 s32 hotbar_imagesize = 48;
690 // The color of the sky
692 //video::SColor skycolor = video::SColor(255,140,186,250);
694 video::SColor bgcolor_bright = video::SColor(255,170,200,230);
697 Draw "Loading" screen
699 /*gui::IGUIStaticText *gui_loadingtext = */
700 //draw_load_screen(L"Loading and connecting...", driver, font);
702 draw_load_screen(L"Loading...", driver, font);
706 SharedPtr will delete it when it goes out of scope.
708 SharedPtr<Server> server;
710 draw_load_screen(L"Creating server...", driver, font);
711 infostream<<"Creating server"<<std::endl;
712 server = new Server(map_dir, configpath);
720 draw_load_screen(L"Creating client...", driver, font);
721 infostream<<"Creating client"<<std::endl;
722 MapDrawControl draw_control;
723 Client client(device, playername.c_str(), password, draw_control);
725 draw_load_screen(L"Resolving address...", driver, font);
726 Address connect_address(0,0,0,0, port);
729 //connect_address.Resolve("localhost");
730 connect_address.setAddress(127,0,0,1);
732 connect_address.Resolve(address.c_str());
734 catch(ResolveError &e)
736 errorstream<<"Couldn't resolve address"<<std::endl;
738 error_message = L"Couldn't resolve address";
739 //gui_loadingtext->remove();
744 Attempt to connect to the server
747 infostream<<"Connecting to server at ";
748 connect_address.print(&infostream);
749 infostream<<std::endl;
750 client.connect(connect_address);
752 bool could_connect = false;
755 float time_counter = 0.0;
758 if(client.connectedAndInitialized())
760 could_connect = true;
763 if(client.accessDenied())
767 // Wait for 10 seconds
768 if(time_counter >= 10.0)
773 std::wostringstream ss;
774 ss<<L"Connecting to server... (timeout in ";
775 ss<<(int)(10.0 - time_counter + 1.0);
777 draw_load_screen(ss.str(), driver, font);
780 driver->beginScene(true, true, video::SColor(255,0,0,0));
782 driver->endScene();*/
784 // Update client and server
796 catch(con::PeerNotFoundException &e)
799 if(could_connect == false)
801 if(client.accessDenied())
803 error_message = L"Access denied. Reason: "
804 +client.accessDeniedReason();
805 errorstream<<wide_to_narrow(error_message)<<std::endl;
809 error_message = L"Connection timed out.";
810 errorstream<<"Timed out."<<std::endl;
812 //gui_loadingtext->remove();
819 float old_brightness = 1.0;
820 scene::ISceneNode* skybox = NULL;
821 update_skybox(driver, smgr, skybox, 1.0);
824 Create the camera node
826 Camera camera(smgr, draw_control);
827 if (!camera.successfullyCreated(error_message))
830 f32 camera_yaw = 0; // "right/left"
831 f32 camera_pitch = 0; // "up/down"
837 float cloud_height = BS*100;
838 Clouds *clouds = NULL;
839 if(g_settings->getBool("enable_clouds"))
841 clouds = new Clouds(smgr->getRootSceneNode(), smgr, -1,
842 cloud_height, time(0));
849 FarMesh *farmesh = NULL;
850 if(g_settings->getBool("enable_farmesh"))
852 farmesh = new FarMesh(smgr->getRootSceneNode(), smgr, -1, client.getMapSeed(), &client);
859 //gui_loadingtext->remove();
865 // First line of debug text
866 gui::IGUIStaticText *guitext = guienv->addStaticText(
868 core::rect<s32>(5, 5, 795, 5+text_height),
870 // Second line of debug text
871 gui::IGUIStaticText *guitext2 = guienv->addStaticText(
873 core::rect<s32>(5, 5+(text_height+5)*1, 795, (5+text_height)*2),
875 // At the middle of the screen
876 // Object infos are shown in this
877 gui::IGUIStaticText *guitext_info = guienv->addStaticText(
879 core::rect<s32>(0,0,400,text_height+5) + v2s32(100,200),
883 gui::IGUIStaticText *guitext_chat = guienv->addStaticText(
885 core::rect<s32>(0,0,0,0),
886 //false, false); // Disable word wrap as of now
888 //guitext_chat->setBackgroundColor(video::SColor(96,0,0,0));
889 core::list<ChatLine> chat_lines;
892 gui::IGUIStaticText *guitext_profiler = guienv->addStaticText(
894 core::rect<s32>(6, 4+(text_height+5)*3, 400,
895 (text_height+5)*3 + text_height*35),
897 guitext_profiler->setBackgroundColor(video::SColor(80,0,0,0));
898 guitext_profiler->setVisible(false);
900 /*GUIQuickInventory *quick_inventory = new GUIQuickInventory
901 (guienv, NULL, v2s32(10, 70), 5, &local_inventory);*/
902 /*GUIQuickInventory *quick_inventory = new GUIQuickInventory
903 (guienv, NULL, v2s32(0, 0), quickinv_itemcount, &local_inventory);*/
905 // Test the text input system
906 /*(new GUITextInputMenu(guienv, guiroot, -1, &g_menumgr,
908 /*GUIMessageMenu *menu =
909 new GUIMessageMenu(guienv, guiroot, -1,
915 (new GUIPauseMenu(guienv, guiroot, -1, g_gamecallback,
916 &g_menumgr))->drop();
919 /*guitext2->setVisible(true);
920 guitext_info->setVisible(true);
921 guitext_chat->setVisible(true);*/
923 //s32 guitext_chat_pad_bottom = 70;
926 Some statistics are collected in these
929 u32 beginscenetime = 0;
931 u32 endscenetime = 0;
934 //throw con::PeerNotFoundException("lol");
936 core::list<float> frametime_log;
938 float nodig_delay_counter = 0.0;
939 float dig_time = 0.0;
941 v3s16 nodepos_old(-32768,-32768,-32768);
943 float damage_flash_timer = 0;
944 s16 farmesh_range = 20*MAP_BLOCKSIZE;
946 const float object_hit_delay = 0.5;
947 float object_hit_delay_timer = 0.0;
949 bool invert_mouse = g_settings->getBool("invert_mouse");
951 bool respawn_menu_active = false;
953 bool show_profiler = false;
959 bool first_loop_after_window_activation = true;
961 // TODO: Convert the static interval timers to these
962 // Interval limiter for profiler
963 IntervalLimiter m_profiler_interval;
965 // Time is in milliseconds
966 // NOTE: getRealTime() causes strange problems in wine (imprecision?)
967 // NOTE: So we have to use getTime() and call run()s between them
968 u32 lasttime = device->getTimer()->getTime();
970 while(device->run() && kill == false)
972 //std::cerr<<"frame"<<std::endl;
974 if(client.accessDenied())
976 error_message = L"Access denied. Reason: "
977 +client.accessDeniedReason();
978 errorstream<<wide_to_narrow(error_message)<<std::endl;
982 if(g_gamecallback->disconnect_requested)
984 g_gamecallback->disconnect_requested = false;
988 if(g_gamecallback->changepassword_requested)
990 (new GUIPasswordChange(guienv, guiroot, -1,
991 &g_menumgr, &client))->drop();
992 g_gamecallback->changepassword_requested = false;
996 Process TextureSource's queue
998 ((TextureSource*)g_texturesource)->processQueue();
1003 last_screensize = screensize;
1004 screensize = driver->getScreenSize();
1005 v2s32 displaycenter(screensize.X/2,screensize.Y/2);
1006 //bool screensize_changed = screensize != last_screensize;
1009 if(screensize.Y <= 800)
1010 hotbar_imagesize = 32;
1011 else if(screensize.Y <= 1280)
1012 hotbar_imagesize = 48;
1014 hotbar_imagesize = 64;
1016 // Hilight boxes collected during the loop and displayed
1017 core::list< core::aabbox3d<f32> > hilightboxes;
1020 std::wstring infotext;
1022 // When screen size changes, update positions and sizes of stuff
1023 /*if(screensize_changed)
1025 v2s32 pos(displaycenter.X-((quickinv_itemcount-1)*quickinv_spacing+quickinv_size)/2, screensize.Y-quickinv_spacing);
1026 quick_inventory->updatePosition(pos);
1029 //TimeTaker //timer1("//timer1");
1031 // Time of frame without fps limit
1035 // not using getRealTime is necessary for wine
1036 u32 time = device->getTimer()->getTime();
1038 busytime_u32 = time - lasttime;
1041 busytime = busytime_u32 / 1000.0;
1044 //infostream<<"busytime_u32="<<busytime_u32<<std::endl;
1046 // Necessary for device->getTimer()->getTime()
1054 float fps_max = g_settings->getFloat("fps_max");
1055 u32 frametime_min = 1000./fps_max;
1057 if(busytime_u32 < frametime_min)
1059 u32 sleeptime = frametime_min - busytime_u32;
1060 device->sleep(sleeptime);
1064 // Necessary for device->getTimer()->getTime()
1068 Time difference calculation
1070 f32 dtime; // in seconds
1072 u32 time = device->getTimer()->getTime();
1074 dtime = (time - lasttime) / 1000.0;
1081 object_hit_delay_timer -= dtime;
1083 g_profiler->add("Elapsed time", dtime);
1084 g_profiler->avg("FPS", 1./dtime);
1087 Log frametime for visualization
1089 frametime_log.push_back(dtime);
1090 if(frametime_log.size() > 100)
1092 core::list<float>::Iterator i = frametime_log.begin();
1093 frametime_log.erase(i);
1097 Visualize frametime in terminal
1099 /*for(u32 i=0; i<dtime*400; i++)
1101 infostream<<std::endl;*/
1104 Time average and jitter calculation
1107 static f32 dtime_avg1 = 0.0;
1108 dtime_avg1 = dtime_avg1 * 0.96 + dtime * 0.04;
1109 f32 dtime_jitter1 = dtime - dtime_avg1;
1111 static f32 dtime_jitter1_max_sample = 0.0;
1112 static f32 dtime_jitter1_max_fraction = 0.0;
1114 static f32 jitter1_max = 0.0;
1115 static f32 counter = 0.0;
1116 if(dtime_jitter1 > jitter1_max)
1117 jitter1_max = dtime_jitter1;
1122 dtime_jitter1_max_sample = jitter1_max;
1123 dtime_jitter1_max_fraction
1124 = dtime_jitter1_max_sample / (dtime_avg1+0.001);
1130 Busytime average and jitter calculation
1133 static f32 busytime_avg1 = 0.0;
1134 busytime_avg1 = busytime_avg1 * 0.98 + busytime * 0.02;
1135 f32 busytime_jitter1 = busytime - busytime_avg1;
1137 static f32 busytime_jitter1_max_sample = 0.0;
1138 static f32 busytime_jitter1_min_sample = 0.0;
1140 static f32 jitter1_max = 0.0;
1141 static f32 jitter1_min = 0.0;
1142 static f32 counter = 0.0;
1143 if(busytime_jitter1 > jitter1_max)
1144 jitter1_max = busytime_jitter1;
1145 if(busytime_jitter1 < jitter1_min)
1146 jitter1_min = busytime_jitter1;
1150 busytime_jitter1_max_sample = jitter1_max;
1151 busytime_jitter1_min_sample = jitter1_min;
1158 Debug info for client
1161 static float counter = 0.0;
1166 client.printDebugInfo(infostream);
1173 float profiler_print_interval =
1174 g_settings->getFloat("profiler_print_interval");
1175 bool print_to_log = true;
1176 if(profiler_print_interval == 0){
1177 print_to_log = false;
1178 profiler_print_interval = 5;
1180 if(m_profiler_interval.step(dtime, profiler_print_interval))
1183 infostream<<"Profiler:"<<std::endl;
1184 g_profiler->print(infostream);
1187 std::ostringstream os(std::ios_base::binary);
1188 g_profiler->print(os);
1189 guitext_profiler->setText(narrow_to_wide(os.str()).c_str());
1191 g_profiler->clear();
1195 Direct handling of user input
1198 // Reset input if window not active or some menu is active
1199 if(device->isWindowActive() == false || noMenuActive() == false)
1204 // Input handler step() (used by the random input generator)
1208 Launch menus according to keys
1210 if(input->wasKeyDown(getKeySetting("keymap_inventory")))
1212 infostream<<"the_game: "
1213 <<"Launching inventory"<<std::endl;
1215 GUIInventoryMenu *menu =
1216 new GUIInventoryMenu(guienv, guiroot, -1,
1217 &g_menumgr, v2s16(8,7),
1218 client.getInventoryContext(),
1221 core::array<GUIInventoryMenu::DrawSpec> draw_spec;
1222 draw_spec.push_back(GUIInventoryMenu::DrawSpec(
1223 "list", "current_player", "main",
1224 v2s32(0, 3), v2s32(8, 4)));
1225 draw_spec.push_back(GUIInventoryMenu::DrawSpec(
1226 "list", "current_player", "craft",
1227 v2s32(3, 0), v2s32(3, 3)));
1228 draw_spec.push_back(GUIInventoryMenu::DrawSpec(
1229 "list", "current_player", "craftresult",
1230 v2s32(7, 1), v2s32(1, 1)));
1232 menu->setDrawSpec(draw_spec);
1236 else if(input->wasKeyDown(EscapeKey))
1238 infostream<<"the_game: "
1239 <<"Launching pause menu"<<std::endl;
1240 // It will delete itself by itself
1241 (new GUIPauseMenu(guienv, guiroot, -1, g_gamecallback,
1242 &g_menumgr))->drop();
1244 // Move mouse cursor on top of the disconnect button
1245 input->setMousePos(displaycenter.X, displaycenter.Y+25);
1247 else if(input->wasKeyDown(getKeySetting("keymap_chat")))
1249 TextDest *dest = new TextDestChat(&client);
1251 (new GUITextInputMenu(guienv, guiroot, -1,
1255 else if(input->wasKeyDown(getKeySetting("keymap_cmd")))
1257 TextDest *dest = new TextDestChat(&client);
1259 (new GUITextInputMenu(guienv, guiroot, -1,
1263 else if(input->wasKeyDown(getKeySetting("keymap_freemove")))
1265 if(g_settings->getBool("free_move"))
1267 g_settings->set("free_move","false");
1268 chat_lines.push_back(ChatLine(L"free_move disabled"));
1272 g_settings->set("free_move","true");
1273 chat_lines.push_back(ChatLine(L"free_move enabled"));
1276 else if(input->wasKeyDown(getKeySetting("keymap_fastmove")))
1278 if(g_settings->getBool("fast_move"))
1280 g_settings->set("fast_move","false");
1281 chat_lines.push_back(ChatLine(L"fast_move disabled"));
1285 g_settings->set("fast_move","true");
1286 chat_lines.push_back(ChatLine(L"fast_move enabled"));
1289 else if(input->wasKeyDown(getKeySetting("keymap_frametime_graph")))
1291 if(g_settings->getBool("frametime_graph"))
1293 g_settings->set("frametime_graph","false");
1294 chat_lines.push_back(ChatLine(L"frametime_graph disabled"));
1298 g_settings->set("frametime_graph","true");
1299 chat_lines.push_back(ChatLine(L"frametime_graph enabled"));
1302 else if(input->wasKeyDown(getKeySetting("keymap_screenshot")))
1304 irr::video::IImage* const image = driver->createScreenShot();
1306 irr::c8 filename[256];
1307 snprintf(filename, 256, "%s" DIR_DELIM "screenshot_%u.png",
1308 g_settings->get("screenshot_path").c_str(),
1309 device->getTimer()->getRealTime());
1310 if (driver->writeImageToFile(image, filename)) {
1311 std::wstringstream sstr;
1312 sstr<<"Saved screenshot to '"<<filename<<"'";
1313 infostream<<"Saved screenshot to '"<<filename<<"'"<<std::endl;
1314 chat_lines.push_back(ChatLine(sstr.str()));
1316 infostream<<"Failed to save screenshot '"<<filename<<"'"<<std::endl;
1321 else if(input->wasKeyDown(getKeySetting("keymap_toggle_profiler")))
1323 show_profiler = !show_profiler;
1324 guitext_profiler->setVisible(show_profiler);
1327 // Item selection with mouse wheel
1329 s32 wheel = input->getMouseWheel();
1330 u16 max_item = MYMIN(PLAYER_INVENTORY_SIZE-1,
1331 hotbar_itemcount-1);
1335 if(g_selected_item < max_item)
1338 g_selected_item = 0;
1342 if(g_selected_item > 0)
1345 g_selected_item = max_item;
1350 for(u16 i=0; i<10; i++)
1352 const KeyPress *kp = NumberKey + (i + 1) % 10;
1353 if(input->wasKeyDown(*kp))
1355 if(i < PLAYER_INVENTORY_SIZE && i < hotbar_itemcount)
1357 g_selected_item = i;
1359 infostream<<"Selected item: "
1360 <<g_selected_item<<std::endl;
1365 // Viewing range selection
1366 if(input->wasKeyDown(getKeySetting("keymap_rangeselect")))
1368 if(draw_control.range_all)
1370 draw_control.range_all = false;
1371 infostream<<"Disabled full viewing range"<<std::endl;
1375 draw_control.range_all = true;
1376 infostream<<"Enabled full viewing range"<<std::endl;
1380 // Print debug stacks
1381 if(input->wasKeyDown(getKeySetting("keymap_print_debug_stacks")))
1383 dstream<<"-----------------------------------------"
1385 dstream<<DTIME<<"Printing debug stacks:"<<std::endl;
1386 dstream<<"-----------------------------------------"
1388 debug_stacks_print();
1392 Mouse and camera control
1393 NOTE: Do this before client.setPlayerControl() to not cause a camera lag of one frame
1396 if((device->isWindowActive() && noMenuActive()) || random_input)
1400 // Mac OSX gets upset if this is set every frame
1401 if(device->getCursorControl()->isVisible())
1402 device->getCursorControl()->setVisible(false);
1405 if(first_loop_after_window_activation){
1406 //infostream<<"window active, first loop"<<std::endl;
1407 first_loop_after_window_activation = false;
1410 s32 dx = input->getMousePos().X - displaycenter.X;
1411 s32 dy = input->getMousePos().Y - displaycenter.Y;
1414 //infostream<<"window active, pos difference "<<dx<<","<<dy<<std::endl;
1416 /*const float keyspeed = 500;
1417 if(input->isKeyDown(irr::KEY_UP))
1418 dy -= dtime * keyspeed;
1419 if(input->isKeyDown(irr::KEY_DOWN))
1420 dy += dtime * keyspeed;
1421 if(input->isKeyDown(irr::KEY_LEFT))
1422 dx -= dtime * keyspeed;
1423 if(input->isKeyDown(irr::KEY_RIGHT))
1424 dx += dtime * keyspeed;*/
1426 camera_yaw -= dx*0.2;
1427 camera_pitch += dy*0.2;
1428 if(camera_pitch < -89.5) camera_pitch = -89.5;
1429 if(camera_pitch > 89.5) camera_pitch = 89.5;
1431 input->setMousePos(displaycenter.X, displaycenter.Y);
1434 // Mac OSX gets upset if this is set every frame
1435 if(device->getCursorControl()->isVisible() == false)
1436 device->getCursorControl()->setVisible(true);
1438 //infostream<<"window inactive"<<std::endl;
1439 first_loop_after_window_activation = true;
1443 Player speed control
1446 if(!noMenuActive() || !device->isWindowActive())
1448 PlayerControl control(
1459 client.setPlayerControl(control);
1472 PlayerControl control(
1473 input->isKeyDown(getKeySetting("keymap_forward")),
1474 input->isKeyDown(getKeySetting("keymap_backward")),
1475 input->isKeyDown(getKeySetting("keymap_left")),
1476 input->isKeyDown(getKeySetting("keymap_right")),
1477 input->isKeyDown(getKeySetting("keymap_jump")),
1478 input->isKeyDown(getKeySetting("keymap_special1")),
1479 input->isKeyDown(getKeySetting("keymap_sneak")),
1483 client.setPlayerControl(control);
1492 //TimeTaker timer("server->step(dtime)");
1493 server->step(dtime);
1501 //TimeTaker timer("client.step(dtime)");
1503 //client.step(dtime_avg1);
1507 // Read client events
1510 ClientEvent event = client.getClientEvent();
1511 if(event.type == CE_NONE)
1515 else if(event.type == CE_PLAYER_DAMAGE)
1517 //u16 damage = event.player_damage.amount;
1518 //infostream<<"Player damage: "<<damage<<std::endl;
1519 damage_flash_timer = 0.05;
1520 if(event.player_damage.amount >= 2){
1521 damage_flash_timer += 0.05 * event.player_damage.amount;
1524 else if(event.type == CE_PLAYER_FORCE_MOVE)
1526 camera_yaw = event.player_force_move.yaw;
1527 camera_pitch = event.player_force_move.pitch;
1529 else if(event.type == CE_DEATHSCREEN)
1531 if(respawn_menu_active)
1534 /*bool set_camera_point_target =
1535 event.deathscreen.set_camera_point_target;
1536 v3f camera_point_target;
1537 camera_point_target.X = event.deathscreen.camera_point_target_x;
1538 camera_point_target.Y = event.deathscreen.camera_point_target_y;
1539 camera_point_target.Z = event.deathscreen.camera_point_target_z;*/
1540 MainRespawnInitiator *respawner =
1541 new MainRespawnInitiator(
1542 &respawn_menu_active, &client);
1543 GUIDeathScreen *menu =
1544 new GUIDeathScreen(guienv, guiroot, -1,
1545 &g_menumgr, respawner);
1548 /* Handle visualization */
1550 damage_flash_timer = 0;
1552 /*LocalPlayer* player = client.getLocalPlayer();
1553 player->setPosition(player->getPosition() + v3f(0,-BS,0));
1554 camera.update(player, busytime, screensize);*/
1559 //TimeTaker //timer2("//timer2");
1561 LocalPlayer* player = client.getLocalPlayer();
1562 camera.update(player, busytime, screensize);
1565 v3f player_position = player->getPosition();
1566 v3f camera_position = camera.getPosition();
1567 v3f camera_direction = camera.getDirection();
1568 f32 camera_fov = camera.getFovMax();
1570 if(FIELD_OF_VIEW_TEST)
1571 client.updateCamera(v3f(0,0,0), v3f(0,0,1), camera_fov);
1573 client.updateCamera(camera_position,
1574 camera_direction, camera_fov);
1577 //TimeTaker //timer3("//timer3");
1580 Calculate what block is the crosshair pointing to
1583 //u32 t1 = device->getTimer()->getRealTime();
1585 //f32 d = 4; // max. distance
1586 f32 d = 4; // max. distance
1587 core::line3d<f32> shootline(camera_position,
1588 camera_position + camera_direction * BS * (d+1));
1590 ClientActiveObject *selected_active_object
1591 = client.getSelectedActiveObject
1592 (d*BS, camera_position, shootline);
1594 bool left_punch = false;
1595 bool left_punch_muted = false;
1597 if(selected_active_object != NULL)
1599 /* Clear possible cracking animation */
1600 if(nodepos_old != v3s16(-32768,-32768,-32768))
1602 client.clearTempMod(nodepos_old);
1604 nodepos_old = v3s16(-32768,-32768,-32768);
1607 //infostream<<"Client returned selected_active_object != NULL"<<std::endl;
1609 core::aabbox3d<f32> *selection_box
1610 = selected_active_object->getSelectionBox();
1611 // Box should exist because object was returned in the
1613 assert(selection_box);
1615 v3f pos = selected_active_object->getPosition();
1617 core::aabbox3d<f32> box_on_map(
1618 selection_box->MinEdge + pos,
1619 selection_box->MaxEdge + pos
1622 if(selected_active_object->doShowSelectionBox())
1623 hilightboxes.push_back(box_on_map);
1625 //infotext = narrow_to_wide("A ClientActiveObject");
1626 infotext = narrow_to_wide(selected_active_object->infoText());
1628 //if(input->getLeftClicked())
1629 if(input->getLeftState())
1631 bool do_punch = false;
1632 bool do_punch_damage = false;
1633 if(object_hit_delay_timer <= 0.0){
1635 do_punch_damage = true;
1636 object_hit_delay_timer = object_hit_delay;
1638 if(input->getLeftClicked()){
1642 infostream<<"Left-clicked object"<<std::endl;
1645 if(do_punch_damage){
1646 client.clickActiveObject(0,
1647 selected_active_object->getId(), g_selected_item);
1650 else if(input->getRightClicked())
1652 infostream<<"Right-clicked object"<<std::endl;
1653 client.clickActiveObject(1,
1654 selected_active_object->getId(), g_selected_item);
1657 else // selected_object == NULL
1661 Find out which node we are pointing at
1664 bool nodefound = false;
1667 core::aabbox3d<f32> nodehilightbox;
1669 getPointedNode(&client, player_position,
1670 camera_direction, camera_position,
1671 nodefound, shootline,
1672 nodepos, neighbourpos,
1676 if(nodepos_old != v3s16(-32768,-32768,-32768))
1678 client.clearTempMod(nodepos_old);
1680 nodepos_old = v3s16(-32768,-32768,-32768);
1687 hilightboxes.push_back(nodehilightbox);
1690 Check information text of node
1693 NodeMetadata *meta = client.getNodeMetadata(nodepos);
1696 infotext = narrow_to_wide(meta->infoText());
1699 //MapNode node = client.getNode(nodepos);
1705 if(input->getLeftReleased())
1707 client.clearTempMod(nodepos);
1711 if(nodig_delay_counter > 0.0)
1713 nodig_delay_counter -= dtime;
1717 if(nodepos != nodepos_old)
1719 infostream<<"Pointing at ("<<nodepos.X<<","
1720 <<nodepos.Y<<","<<nodepos.Z<<")"<<std::endl;
1722 if(nodepos_old != v3s16(-32768,-32768,-32768))
1724 client.clearTempMod(nodepos_old);
1726 nodepos_old = v3s16(-32768,-32768,-32768);
1730 if(input->getLeftClicked() ||
1731 (input->getLeftState() && nodepos != nodepos_old))
1733 infostream<<"Started digging"<<std::endl;
1734 client.groundAction(0, nodepos, neighbourpos, g_selected_item);
1736 if(input->getLeftClicked())
1738 client.setTempMod(nodepos, NodeMod(NODEMOD_CRACK, 0));
1740 if(input->getLeftState())
1742 MapNode n = client.getNode(nodepos);
1744 // Get tool name. Default is "" = bare hands
1745 std::string toolname = "";
1746 InventoryList *mlist = local_inventory.getList("main");
1749 InventoryItem *item = mlist->getItem(g_selected_item);
1750 if(item && (std::string)item->getName() == "ToolItem")
1752 ToolItem *titem = (ToolItem*)item;
1753 toolname = titem->getToolName();
1757 // Get digging properties for material and tool
1758 content_t material = n.getContent();
1759 DiggingProperties prop =
1760 getDiggingProperties(material, toolname);
1762 float dig_time_complete = 0.0;
1764 if(prop.diggable == false)
1766 /*infostream<<"Material "<<(int)material
1767 <<" not diggable with \""
1768 <<toolname<<"\""<<std::endl;*/
1769 // I guess nobody will wait for this long
1770 dig_time_complete = 10000000.0;
1774 dig_time_complete = prop.time;
1777 if(dig_time_complete >= 0.001)
1779 dig_index = (u16)((float)CRACK_ANIMATION_LENGTH
1780 * dig_time/dig_time_complete);
1782 // This is for torches
1785 dig_index = CRACK_ANIMATION_LENGTH;
1788 if(dig_index < CRACK_ANIMATION_LENGTH)
1790 //TimeTaker timer("client.setTempMod");
1791 //infostream<<"dig_index="<<dig_index<<std::endl;
1792 client.setTempMod(nodepos, NodeMod(NODEMOD_CRACK, dig_index));
1796 infostream<<"Digging completed"<<std::endl;
1797 client.groundAction(3, nodepos, neighbourpos, g_selected_item);
1798 client.clearTempMod(nodepos);
1799 client.removeNode(nodepos);
1803 nodig_delay_counter = dig_time_complete
1804 / (float)CRACK_ANIMATION_LENGTH;
1806 // We don't want a corresponding delay to
1807 // very time consuming nodes
1808 if(nodig_delay_counter > 0.5)
1810 nodig_delay_counter = 0.5;
1812 // We want a slight delay to very little
1813 // time consuming nodes
1814 float mindelay = 0.15;
1815 if(nodig_delay_counter < mindelay)
1817 nodig_delay_counter = mindelay;
1823 camera.setDigging(0); // left click animation
1828 if(input->getRightClicked())
1830 infostream<<"Ground right-clicked"<<std::endl;
1832 // If metadata provides an inventory view, activate it
1833 if(meta && meta->getInventoryDrawSpecString() != "" && !random_input)
1835 infostream<<"Launching custom inventory view"<<std::endl;
1837 Construct the unique identification string of the node
1839 std::string current_name;
1840 current_name += "nodemeta:";
1841 current_name += itos(nodepos.X);
1842 current_name += ",";
1843 current_name += itos(nodepos.Y);
1844 current_name += ",";
1845 current_name += itos(nodepos.Z);
1851 core::array<GUIInventoryMenu::DrawSpec> draw_spec;
1853 GUIInventoryMenu::makeDrawSpecArrayFromString(
1855 meta->getInventoryDrawSpecString(),
1858 GUIInventoryMenu *menu =
1859 new GUIInventoryMenu(guienv, guiroot, -1,
1860 &g_menumgr, invsize,
1861 client.getInventoryContext(),
1863 menu->setDrawSpec(draw_spec);
1866 else if(meta && meta->typeId() == CONTENT_SIGN_WALL && !random_input)
1868 infostream<<"Sign node right-clicked"<<std::endl;
1870 SignNodeMetadata *signmeta = (SignNodeMetadata*)meta;
1872 // Get a new text for it
1874 TextDest *dest = new TextDestSignNode(nodepos, &client);
1876 std::wstring wtext =
1877 narrow_to_wide(signmeta->getText());
1879 (new GUITextInputMenu(guienv, guiroot, -1,
1885 client.groundAction(1, nodepos, neighbourpos, g_selected_item);
1886 camera.setDigging(1); // right click animation
1890 nodepos_old = nodepos;
1893 } // selected_object == NULL
1895 if(left_punch || (input->getLeftClicked() && !left_punch_muted))
1897 camera.setDigging(0); // left click animation
1900 input->resetLeftClicked();
1901 input->resetRightClicked();
1903 if(input->getLeftReleased())
1905 infostream<<"Left button released (stopped digging)"
1907 client.groundAction(2, v3s16(0,0,0), v3s16(0,0,0), 0);
1909 if(input->getRightReleased())
1911 //inostream<<DTIME<<"Right released"<<std::endl;
1915 input->resetLeftReleased();
1916 input->resetRightReleased();
1919 Calculate stuff for drawing
1922 u32 daynight_ratio = client.getDayNightRatio();
1923 u8 l = decode_light((daynight_ratio * LIGHT_SUN) / 1000);
1924 video::SColor bgcolor = video::SColor(
1926 bgcolor_bright.getRed() * l / 255,
1927 bgcolor_bright.getGreen() * l / 255,
1928 bgcolor_bright.getBlue() * l / 255);
1929 /*skycolor.getRed() * l / 255,
1930 skycolor.getGreen() * l / 255,
1931 skycolor.getBlue() * l / 255);*/
1933 float brightness = (float)l/255.0;
1938 if(fabs(brightness - old_brightness) > 0.01)
1939 update_skybox(driver, smgr, skybox, brightness);
1946 clouds->step(dtime);
1947 clouds->update(v2f(player_position.X, player_position.Z),
1948 0.05+brightness*0.95);
1956 farmesh_range = draw_control.wanted_range * 10;
1957 if(draw_control.range_all && farmesh_range < 500)
1958 farmesh_range = 500;
1959 if(farmesh_range > 1000)
1960 farmesh_range = 1000;
1962 farmesh->step(dtime);
1963 farmesh->update(v2f(player_position.X, player_position.Z),
1964 0.05+brightness*0.95, farmesh_range);
1967 // Store brightness value
1968 old_brightness = brightness;
1974 if(g_settings->getBool("enable_fog") == true)
1979 range = BS*farmesh_range;
1983 range = draw_control.wanted_range*BS + MAP_BLOCKSIZE*BS*1.5;
1984 if(draw_control.range_all)
1987 range = range * 0.5 + 25*BS;*/
1988 // Move the invisible limit a bit further
1994 video::EFT_FOG_LINEAR,
2006 video::EFT_FOG_LINEAR,
2016 Update gui stuff (0ms)
2019 //TimeTaker guiupdatetimer("Gui updating");
2022 static float drawtime_avg = 0;
2023 drawtime_avg = drawtime_avg * 0.95 + (float)drawtime*0.05;
2024 static float beginscenetime_avg = 0;
2025 beginscenetime_avg = beginscenetime_avg * 0.95 + (float)beginscenetime*0.05;
2026 static float scenetime_avg = 0;
2027 scenetime_avg = scenetime_avg * 0.95 + (float)scenetime*0.05;
2028 static float endscenetime_avg = 0;
2029 endscenetime_avg = endscenetime_avg * 0.95 + (float)endscenetime*0.05;
2032 snprintf(temptext, 300, "Minetest-c55 %s ("
2035 " drawtime=%.0f, beginscenetime=%.0f"
2036 ", scenetime=%.0f, endscenetime=%.0f",
2038 draw_control.range_all,
2045 guitext->setText(narrow_to_wide(temptext).c_str());
2050 snprintf(temptext, 300,
2051 "(% .1f, % .1f, % .1f)"
2052 " (% .3f < btime_jitter < % .3f"
2053 ", dtime_jitter = % .1f %%"
2054 ", v_range = %.1f, RTT = %.3f)",
2055 player_position.X/BS,
2056 player_position.Y/BS,
2057 player_position.Z/BS,
2058 busytime_jitter1_min_sample,
2059 busytime_jitter1_max_sample,
2060 dtime_jitter1_max_fraction * 100.0,
2061 draw_control.wanted_range,
2065 guitext2->setText(narrow_to_wide(temptext).c_str());
2069 guitext_info->setText(infotext.c_str());
2073 Get chat messages from client
2077 std::wstring message;
2078 while(client.getChatMessage(message))
2080 chat_lines.push_back(ChatLine(message));
2081 /*if(chat_lines.size() > 6)
2083 core::list<ChatLine>::Iterator
2084 i = chat_lines.begin();
2085 chat_lines.erase(i);
2088 // Append them to form the whole static text and throw
2089 // it to the gui element
2091 // This will correspond to the line number counted from
2092 // top to bottom, from size-1 to 0
2093 s16 line_number = chat_lines.size();
2094 // Count of messages to be removed from the top
2095 u16 to_be_removed_count = 0;
2096 for(core::list<ChatLine>::Iterator
2097 i = chat_lines.begin();
2098 i != chat_lines.end(); i++)
2100 // After this, line number is valid for this loop
2105 This results in a maximum age of 60*6 to the
2106 lowermost line and a maximum of 6 lines
2108 float allowed_age = (6-line_number) * 60.0;
2110 if((*i).age > allowed_age)
2112 to_be_removed_count++;
2115 whole += (*i).text + L'\n';
2117 for(u16 i=0; i<to_be_removed_count; i++)
2119 core::list<ChatLine>::Iterator
2120 it = chat_lines.begin();
2121 chat_lines.erase(it);
2123 guitext_chat->setText(whole.c_str());
2125 // Update gui element size and position
2127 /*core::rect<s32> rect(
2129 screensize.Y - guitext_chat_pad_bottom
2130 - text_height*chat_lines.size(),
2132 screensize.Y - guitext_chat_pad_bottom
2134 core::rect<s32> rect(
2138 50 + guitext_chat->getTextHeight()
2141 guitext_chat->setRelativePosition(rect);
2143 // Don't show chat if empty or profiler is enabled
2144 if(chat_lines.size() == 0 || show_profiler)
2145 guitext_chat->setVisible(false);
2147 guitext_chat->setVisible(true);
2154 static u16 old_selected_item = 65535;
2155 if(client.getLocalInventoryUpdated()
2156 || g_selected_item != old_selected_item)
2158 client.selectPlayerItem(g_selected_item);
2159 old_selected_item = g_selected_item;
2160 //infostream<<"Updating local inventory"<<std::endl;
2161 client.getLocalInventory(local_inventory);
2163 // Update wielded tool
2164 InventoryList *mlist = local_inventory.getList("main");
2165 InventoryItem *item = NULL;
2167 item = mlist->getItem(g_selected_item);
2172 Send actions returned by the inventory menu
2174 while(inventory_action_queue.size() != 0)
2176 InventoryAction *a = inventory_action_queue.pop_front();
2178 client.sendInventoryAction(a);
2187 TimeTaker drawtimer("Drawing");
2191 TimeTaker timer("beginScene");
2192 driver->beginScene(true, true, bgcolor);
2193 //driver->beginScene(false, true, bgcolor);
2194 beginscenetime = timer.stop(true);
2199 //infostream<<"smgr->drawAll()"<<std::endl;
2202 TimeTaker timer("smgr");
2204 scenetime = timer.stop(true);
2208 //TimeTaker timer9("auxiliary drawings");
2212 //TimeTaker //timer10("//timer10");
2218 driver->setMaterial(m);
2220 driver->setTransform(video::ETS_WORLD, core::IdentityMatrix);
2222 for(core::list< core::aabbox3d<f32> >::Iterator i=hilightboxes.begin();
2223 i != hilightboxes.end(); i++)
2225 /*infostream<<"hilightbox min="
2226 <<"("<<i->MinEdge.X<<","<<i->MinEdge.Y<<","<<i->MinEdge.Z<<")"
2228 <<"("<<i->MaxEdge.X<<","<<i->MaxEdge.Y<<","<<i->MaxEdge.Z<<")"
2230 driver->draw3DBox(*i, video::SColor(255,0,0,0));
2237 // Warning: This clears the Z buffer.
2238 camera.drawWieldedTool();
2245 client.renderPostFx();
2251 if(g_settings->getBool("frametime_graph") == true)
2254 for(core::list<float>::Iterator
2255 i = frametime_log.begin();
2256 i != frametime_log.end();
2259 driver->draw2DLine(v2s32(x,50),
2260 v2s32(x,50+(*i)*1000),
2261 video::SColor(255,255,255,255));
2269 driver->draw2DLine(displaycenter - core::vector2d<s32>(10,0),
2270 displaycenter + core::vector2d<s32>(10,0),
2271 video::SColor(255,255,255,255));
2272 driver->draw2DLine(displaycenter - core::vector2d<s32>(0,10),
2273 displaycenter + core::vector2d<s32>(0,10),
2274 video::SColor(255,255,255,255));
2279 //TimeTaker //timer11("//timer11");
2291 draw_hotbar(driver, font, v2s32(displaycenter.X, screensize.Y),
2292 hotbar_imagesize, hotbar_itemcount, &local_inventory,
2299 if(damage_flash_timer > 0.0)
2301 damage_flash_timer -= dtime;
2303 video::SColor color(128,255,0,0);
2304 driver->draw2DRectangle(color,
2305 core::rect<s32>(0,0,screensize.X,screensize.Y),
2313 TimeTaker timer("endScene");
2315 endscenetime = timer.stop(true);
2318 drawtime = drawtimer.stop(true);
2324 static s16 lastFPS = 0;
2325 //u16 fps = driver->getFPS();
2326 u16 fps = (1.0/dtime_avg1);
2330 core::stringw str = L"Minetest [";
2331 str += driver->getName();
2335 device->setWindowCaption(str.c_str());
2347 Draw a "shutting down" screen, which will be shown while the map
2348 generator and other stuff quits
2351 /*gui::IGUIStaticText *gui_shuttingdowntext = */
2352 draw_load_screen(L"Shutting down stuff...", driver, font);
2353 /*driver->beginScene(true, true, video::SColor(255,0,0,0));
2356 gui_shuttingdowntext->remove();*/