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 "guiFurnaceMenu.h"
29 #include "materials.h"
35 Setting this to 1 enables a special camera mode that forces
36 the renderers to think that the camera statically points from
37 the starting place to a static direction.
39 This allows one to move around with the player and see what
40 is actually drawn behind solid things and behind the player.
42 #define FIELD_OF_VIEW_TEST 0
45 MapDrawControl draw_control;
54 ChatLine(const std::wstring &a_text):
67 // Inventory actions from the menu are buffered here before sending
68 Queue<InventoryAction*> inventory_action_queue;
69 // This is a copy of the inventory that the client's environment has
70 Inventory local_inventory;
72 u16 g_selected_item = 0;
78 struct TextDestSign : public TextDest
80 TextDestSign(v3s16 blockpos, s16 id, Client *client)
82 m_blockpos = blockpos;
86 void gotText(std::wstring text)
88 std::string ntext = wide_to_narrow(text);
89 dstream<<"Changing text of a sign object: "
91 m_client->sendSignText(m_blockpos, m_id, ntext);
99 struct TextDestChat : public TextDest
101 TextDestChat(Client *client)
105 void gotText(std::wstring text)
107 // Discard empty line
111 // Parse command (server command starts with "/#")
112 if(text[0] == L'/' && text[1] != L'#')
114 std::wstring reply = L"Local: ";
116 reply += L"Local commands not yet supported. "
117 L"Server prefix is \"/#\".";
119 m_client->addChatMessage(reply);
124 m_client->sendChatMessage(text);
126 m_client->addChatMessage(text);
132 struct TextDestSignNode : public TextDest
134 TextDestSignNode(v3s16 p, Client *client)
139 void gotText(std::wstring text)
141 std::string ntext = wide_to_narrow(text);
142 dstream<<"Changing text of a sign node: "
144 m_client->sendSignNodeText(m_p, ntext);
152 Render distance feedback loop
154 void updateViewingRange(f32 frametime_in, Client *client)
156 if(draw_control.range_all == true)
159 static f32 added_frametime = 0;
160 static s16 added_frames = 0;
162 added_frametime += frametime_in;
165 // Actually this counter kind of sucks because frametime is busytime
166 static f32 counter = 0;
167 counter -= frametime_in;
173 /*dstream<<__FUNCTION_NAME
174 <<": Collected "<<added_frames<<" frames, total of "
175 <<added_frametime<<"s."<<std::endl;*/
177 /*dstream<<"draw_control.blocks_drawn="
178 <<draw_control.blocks_drawn
179 <<", draw_control.blocks_would_have_drawn="
180 <<draw_control.blocks_would_have_drawn
183 float range_min = g_settings.getS16("viewing_range_nodes_min");
184 float range_max = g_settings.getS16("viewing_range_nodes_max");
186 // Limit minimum to keep the feedback loop stable
190 draw_control.wanted_min_range = range_min;
191 //draw_control.wanted_max_blocks = (1.5*draw_control.blocks_drawn)+1;
192 draw_control.wanted_max_blocks = (1.5*draw_control.blocks_would_have_drawn)+1;
193 if(draw_control.wanted_max_blocks < 10)
194 draw_control.wanted_max_blocks = 10;
196 float block_draw_ratio = 1.0;
197 if(draw_control.blocks_would_have_drawn != 0)
199 block_draw_ratio = (float)draw_control.blocks_drawn
200 / (float)draw_control.blocks_would_have_drawn;
203 // Calculate the average frametime in the case that all wanted
204 // blocks had been drawn
205 f32 frametime = added_frametime / added_frames / block_draw_ratio;
207 added_frametime = 0.0;
210 float wanted_fps = g_settings.getFloat("wanted_fps");
211 float wanted_frametime = 1.0 / wanted_fps;
213 f32 wanted_frametime_change = wanted_frametime - frametime;
214 //dstream<<"wanted_frametime_change="<<wanted_frametime_change<<std::endl;
216 // If needed frametime change is small, just return
217 if(fabs(wanted_frametime_change) < wanted_frametime*0.4)
219 //dstream<<"ignoring small wanted_frametime_change"<<std::endl;
223 float range = draw_control.wanted_range;
224 float new_range = range;
226 static s16 range_old = 0;
227 static f32 frametime_old = 0;
229 float d_range = range - range_old;
230 f32 d_frametime = frametime - frametime_old;
231 // A sane default of 30ms per 50 nodes of range
232 static f32 time_per_range = 30. / 50;
235 time_per_range = d_frametime / d_range;
238 // The minimum allowed calculated frametime-range derivative:
239 // Practically this sets the maximum speed of changing the range.
240 // The lower this value, the higher the maximum changing speed.
241 // A low value here results in wobbly range (0.001)
242 // A high value here results in slow changing range (0.0025)
243 // SUGG: This could be dynamically adjusted so that when
244 // the camera is turning, this is lower
245 //float min_time_per_range = 0.0015;
246 float min_time_per_range = 0.0010;
247 //float min_time_per_range = 0.05 / range;
248 if(time_per_range < min_time_per_range)
250 time_per_range = min_time_per_range;
251 //dstream<<"time_per_range="<<time_per_range<<" (min)"<<std::endl;
255 //dstream<<"time_per_range="<<time_per_range<<std::endl;
258 f32 wanted_range_change = wanted_frametime_change / time_per_range;
259 // Dampen the change a bit to kill oscillations
260 //wanted_range_change *= 0.9;
261 //wanted_range_change *= 0.75;
262 wanted_range_change *= 0.5;
263 //dstream<<"wanted_range_change="<<wanted_range_change<<std::endl;
265 // If needed range change is very small, just return
266 if(fabs(wanted_range_change) < 0.001)
268 //dstream<<"ignoring small wanted_range_change"<<std::endl;
272 new_range += wanted_range_change;
274 //float new_range_unclamped = new_range;
275 if(new_range < range_min)
276 new_range = range_min;
277 if(new_range > range_max)
278 new_range = range_max;
280 /*dstream<<"new_range="<<new_range_unclamped
281 <<", clamped to "<<new_range<<std::endl;*/
283 draw_control.wanted_range = new_range;
285 range_old = new_range;
286 frametime_old = frametime;
292 void draw_hotbar(video::IVideoDriver *driver, gui::IGUIFont *font,
293 v2s32 centerlowerpos, s32 imgsize, s32 itemcount,
294 Inventory *inventory, s32 halfheartcount)
296 InventoryList *mainlist = inventory->getList("main");
299 dstream<<"WARNING: draw_hotbar(): mainlist == NULL"<<std::endl;
303 s32 padding = imgsize/12;
304 //s32 height = imgsize + padding*2;
305 s32 width = itemcount*(imgsize+padding*2);
307 // Position of upper left corner of bar
308 v2s32 pos = centerlowerpos - v2s32(width/2, imgsize+padding*2);
310 // Draw background color
311 /*core::rect<s32> barrect(0,0,width,height);
313 video::SColor bgcolor(255,128,128,128);
314 driver->draw2DRectangle(bgcolor, barrect, NULL);*/
316 core::rect<s32> imgrect(0,0,imgsize,imgsize);
318 for(s32 i=0; i<itemcount; i++)
320 InventoryItem *item = mainlist->getItem(i);
322 core::rect<s32> rect = imgrect + pos
323 + v2s32(padding+i*(imgsize+padding*2), padding);
325 if(g_selected_item == i)
327 driver->draw2DRectangle(video::SColor(255,255,0,0),
328 core::rect<s32>(rect.UpperLeftCorner - v2s32(1,1)*padding,
329 rect.LowerRightCorner + v2s32(1,1)*padding),
334 video::SColor bgcolor2(128,0,0,0);
335 driver->draw2DRectangle(bgcolor2, rect, NULL);
340 drawInventoryItem(driver, font, item, rect, NULL);
348 video::ITexture *heart_texture =
349 driver->getTexture(getTexturePath("heart.png").c_str());
350 v2s32 p = pos + v2s32(0, -20);
351 for(s32 i=0; i<halfheartcount/2; i++)
353 const video::SColor color(255,255,255,255);
354 const video::SColor colors[] = {color,color,color,color};
355 core::rect<s32> rect(0,0,16,16);
357 driver->draw2DImage(heart_texture, rect,
358 core::rect<s32>(core::position2d<s32>(0,0),
359 core::dimension2di(heart_texture->getOriginalSize())),
363 if(halfheartcount % 2 == 1)
365 const video::SColor color(255,255,255,255);
366 const video::SColor colors[] = {color,color,color,color};
367 core::rect<s32> rect(0,0,16/2,16);
369 core::dimension2di srcd(heart_texture->getOriginalSize());
371 driver->draw2DImage(heart_texture, rect,
372 core::rect<s32>(core::position2d<s32>(0,0), srcd),
380 Find what the player is pointing at
382 void getPointedNode(Client *client, v3f player_position,
383 v3f camera_direction, v3f camera_position,
384 bool &nodefound, core::line3d<f32> shootline,
385 v3s16 &nodepos, v3s16 &neighbourpos,
386 core::aabbox3d<f32> &nodehilightbox,
389 f32 mindistance = BS * 1001;
391 v3s16 pos_i = floatToInt(player_position, BS);
393 /*std::cout<<"pos_i=("<<pos_i.X<<","<<pos_i.Y<<","<<pos_i.Z<<")"
397 s16 ystart = pos_i.Y + 0 - (camera_direction.Y<0 ? a : 1);
398 s16 zstart = pos_i.Z - (camera_direction.Z<0 ? a : 1);
399 s16 xstart = pos_i.X - (camera_direction.X<0 ? a : 1);
400 s16 yend = pos_i.Y + 1 + (camera_direction.Y>0 ? a : 1);
401 s16 zend = pos_i.Z + (camera_direction.Z>0 ? a : 1);
402 s16 xend = pos_i.X + (camera_direction.X>0 ? a : 1);
404 for(s16 y = ystart; y <= yend; y++)
405 for(s16 z = zstart; z <= zend; z++)
406 for(s16 x = xstart; x <= xend; x++)
411 n = client->getNode(v3s16(x,y,z));
412 if(content_pointable(n.d) == false)
415 catch(InvalidPositionException &e)
421 v3f npf = intToFloat(np, BS);
426 v3s16(0,0,1), // back
428 v3s16(1,0,0), // right
429 v3s16(0,0,-1), // front
430 v3s16(0,-1,0), // bottom
431 v3s16(-1,0,0), // left
437 if(n.d == CONTENT_TORCH)
439 v3s16 dir = unpackDir(n.dir);
440 v3f dir_f = v3f(dir.X, dir.Y, dir.Z);
441 dir_f *= BS/2 - BS/6 - BS/20;
442 v3f cpf = npf + dir_f;
443 f32 distance = (cpf - camera_position).getLength();
445 core::aabbox3d<f32> box;
448 if(dir == v3s16(0,-1,0))
450 box = core::aabbox3d<f32>(
451 npf - v3f(BS/6, BS/2, BS/6),
452 npf + v3f(BS/6, -BS/2+BS/3*2, BS/6)
456 else if(dir == v3s16(0,1,0))
458 box = core::aabbox3d<f32>(
459 npf - v3f(BS/6, -BS/2+BS/3*2, BS/6),
460 npf + v3f(BS/6, BS/2, BS/6)
466 box = core::aabbox3d<f32>(
467 cpf - v3f(BS/6, BS/3, BS/6),
468 cpf + v3f(BS/6, BS/3, BS/6)
472 if(distance < mindistance)
474 if(box.intersectsWithLine(shootline))
479 mindistance = distance;
480 nodehilightbox = box;
484 else if(n.d == CONTENT_SIGN_WALL)
486 v3s16 dir = unpackDir(n.dir);
487 v3f dir_f = v3f(dir.X, dir.Y, dir.Z);
488 dir_f *= BS/2 - BS/6 - BS/20;
489 v3f cpf = npf + dir_f;
490 f32 distance = (cpf - camera_position).getLength();
494 v3f(BS*0.42,-BS*0.35,-BS*0.4),
495 v3f(BS*0.49, BS*0.35, BS*0.4),
498 for(s32 i=0; i<2; i++)
500 if(dir == v3s16(1,0,0))
501 vertices[i].rotateXZBy(0);
502 if(dir == v3s16(-1,0,0))
503 vertices[i].rotateXZBy(180);
504 if(dir == v3s16(0,0,1))
505 vertices[i].rotateXZBy(90);
506 if(dir == v3s16(0,0,-1))
507 vertices[i].rotateXZBy(-90);
508 if(dir == v3s16(0,-1,0))
509 vertices[i].rotateXYBy(-90);
510 if(dir == v3s16(0,1,0))
511 vertices[i].rotateXYBy(90);
516 core::aabbox3d<f32> box;
518 box = core::aabbox3d<f32>(vertices[0]);
519 box.addInternalPoint(vertices[1]);
521 if(distance < mindistance)
523 if(box.intersectsWithLine(shootline))
528 mindistance = distance;
529 nodehilightbox = box;
533 else if(n.d == CONTENT_RAIL)
535 v3s16 dir = unpackDir(n.dir);
536 v3f dir_f = v3f(dir.X, dir.Y, dir.Z);
537 dir_f *= BS/2 - BS/6 - BS/20;
538 v3f cpf = npf + dir_f;
539 f32 distance = (cpf - camera_position).getLength();
541 float d = (float)BS/16;
544 v3f(BS/2, -BS/2+d, -BS/2),
545 v3f(-BS/2, -BS/2, BS/2),
548 for(s32 i=0; i<2; i++)
553 core::aabbox3d<f32> box;
555 box = core::aabbox3d<f32>(vertices[0]);
556 box.addInternalPoint(vertices[1]);
558 if(distance < mindistance)
560 if(box.intersectsWithLine(shootline))
565 mindistance = distance;
566 nodehilightbox = box;
575 for(u16 i=0; i<6; i++)
577 v3f dir_f = v3f(dirs[i].X,
578 dirs[i].Y, dirs[i].Z);
579 v3f centerpoint = npf + dir_f * BS/2;
581 (centerpoint - camera_position).getLength();
583 if(distance < mindistance)
585 core::CMatrix4<f32> m;
586 m.buildRotateFromTo(v3f(0,0,1), dir_f);
588 // This is the back face
590 v3f(BS/2, BS/2, BS/2),
591 v3f(-BS/2, -BS/2, BS/2+d)
594 for(u16 j=0; j<2; j++)
596 m.rotateVect(corners[j]);
600 core::aabbox3d<f32> facebox(corners[0]);
601 facebox.addInternalPoint(corners[1]);
603 if(facebox.intersectsWithLine(shootline))
607 neighbourpos = np + dirs[i];
608 mindistance = distance;
610 //nodehilightbox = facebox;
612 const float d = 0.502;
613 core::aabbox3d<f32> nodebox
614 (-BS*d, -BS*d, -BS*d, BS*d, BS*d, BS*d);
615 v3f nodepos_f = intToFloat(nodepos, BS);
616 nodebox.MinEdge += nodepos_f;
617 nodebox.MaxEdge += nodepos_f;
618 nodehilightbox = nodebox;
620 } // if distance < mindistance
626 void update_skybox(video::IVideoDriver* driver,
627 scene::ISceneManager* smgr, scene::ISceneNode* &skybox,
635 if(brightness >= 0.5)
637 skybox = smgr->addSkyBoxSceneNode(
638 driver->getTexture(getTexturePath("skybox2.png").c_str()),
639 driver->getTexture(getTexturePath("skybox3.png").c_str()),
640 driver->getTexture(getTexturePath("skybox1.png").c_str()),
641 driver->getTexture(getTexturePath("skybox1.png").c_str()),
642 driver->getTexture(getTexturePath("skybox1.png").c_str()),
643 driver->getTexture(getTexturePath("skybox1.png").c_str()));
645 else if(brightness >= 0.2)
647 skybox = smgr->addSkyBoxSceneNode(
648 driver->getTexture(getTexturePath("skybox2_dawn.png").c_str()),
649 driver->getTexture(getTexturePath("skybox3_dawn.png").c_str()),
650 driver->getTexture(getTexturePath("skybox1_dawn.png").c_str()),
651 driver->getTexture(getTexturePath("skybox1_dawn.png").c_str()),
652 driver->getTexture(getTexturePath("skybox1_dawn.png").c_str()),
653 driver->getTexture(getTexturePath("skybox1_dawn.png").c_str()));
657 skybox = smgr->addSkyBoxSceneNode(
658 driver->getTexture(getTexturePath("skybox2_night.png").c_str()),
659 driver->getTexture(getTexturePath("skybox3_night.png").c_str()),
660 driver->getTexture(getTexturePath("skybox1_night.png").c_str()),
661 driver->getTexture(getTexturePath("skybox1_night.png").c_str()),
662 driver->getTexture(getTexturePath("skybox1_night.png").c_str()),
663 driver->getTexture(getTexturePath("skybox1_night.png").c_str()));
671 IrrlichtDevice *device,
674 std::string playername,
675 std::string password,
678 std::wstring &error_message
681 video::IVideoDriver* driver = device->getVideoDriver();
682 scene::ISceneManager* smgr = device->getSceneManager();
684 v2u32 screensize(0,0);
685 v2u32 last_screensize(0,0);
686 screensize = driver->getScreenSize();
688 const s32 hotbar_itemcount = 8;
689 const s32 hotbar_imagesize = 36;
691 // The color of the sky
693 //video::SColor skycolor = video::SColor(255,140,186,250);
695 video::SColor bgcolor_bright = video::SColor(255,170,200,230);
698 Draw "Loading" screen
700 const wchar_t *loadingtext = L"Loading and connecting...";
701 u32 text_height = font->getDimension(loadingtext).Height;
702 core::vector2d<s32> center(screensize.X/2, screensize.Y/2);
703 core::vector2d<s32> textsize(300, text_height);
704 core::rect<s32> textrect(center - textsize/2, center + textsize/2);
706 gui::IGUIStaticText *gui_loadingtext = guienv->addStaticText(
707 loadingtext, textrect, false, false);
708 gui_loadingtext->setTextAlignment(gui::EGUIA_CENTER, gui::EGUIA_UPPERLEFT);
710 driver->beginScene(true, true, video::SColor(255,0,0,0));
717 SharedPtr will delete it when it goes out of scope.
719 SharedPtr<Server> server;
721 std::cout<<DTIME<<"Creating server"<<std::endl;
722 server = new Server(map_dir);
730 std::cout<<DTIME<<"Creating client"<<std::endl;
731 Client client(device, playername.c_str(), password, draw_control);
733 Address connect_address(0,0,0,0, port);
736 //connect_address.Resolve("localhost");
737 connect_address.setAddress(127,0,0,1);
739 connect_address.Resolve(address.c_str());
741 catch(ResolveError &e)
743 std::cout<<DTIME<<"Couldn't resolve address"<<std::endl;
745 error_message = L"Couldn't resolve address";
746 gui_loadingtext->remove();
751 Attempt to connect to the server
754 dstream<<DTIME<<"Connecting to server at ";
755 connect_address.print(&dstream);
757 client.connect(connect_address);
759 bool could_connect = false;
762 float time_counter = 0.0;
765 if(client.connectedAndInitialized())
767 could_connect = true;
770 if(client.accessDenied())
774 // Wait for 10 seconds
775 if(time_counter >= 10.0)
781 driver->beginScene(true, true, video::SColor(255,0,0,0));
785 // Update client and server
797 catch(con::PeerNotFoundException &e)
800 if(could_connect == false)
802 if(client.accessDenied())
804 error_message = L"Access denied. Check your password and try again.";
805 std::cout<<DTIME<<"Access denied."<<std::endl;
809 error_message = L"Connection timed out.";
810 std::cout<<DTIME<<"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
827 scene::ICameraSceneNode* camera = smgr->addCameraSceneNode(
829 v3f(BS*100, BS*2, BS*100), // Look from
830 v3f(BS*100+1, BS*2, BS*100), // Look to
836 error_message = L"Failed to create the camera node";
840 camera->setFOV(FOV_ANGLE);
842 // Just so big a value that everything rendered is visible
843 camera->setFarValue(100000*BS);
845 f32 camera_yaw = 0; // "right/left"
846 f32 camera_pitch = 0; // "up/down"
852 float cloud_height = BS*100;
853 Clouds *clouds = NULL;
854 clouds = new Clouds(smgr->getRootSceneNode(), smgr, -1,
855 cloud_height, time(0));
861 gui_loadingtext->remove();
867 // First line of debug text
868 gui::IGUIStaticText *guitext = guienv->addStaticText(
870 core::rect<s32>(5, 5, 795, 5+text_height),
872 // Second line of debug text
873 gui::IGUIStaticText *guitext2 = guienv->addStaticText(
875 core::rect<s32>(5, 5+(text_height+5)*1, 795, (5+text_height)*2),
878 // At the middle of the screen
879 // Object infos are shown in this
880 gui::IGUIStaticText *guitext_info = guienv->addStaticText(
882 core::rect<s32>(0,0,400,text_height+5) + v2s32(100,200),
886 gui::IGUIStaticText *guitext_chat = guienv->addStaticText(
888 core::rect<s32>(0,0,0,0),
889 false, false); // Disable word wrap as of now
891 //guitext_chat->setBackgroundColor(video::SColor(96,0,0,0));
892 core::list<ChatLine> chat_lines;
894 /*GUIQuickInventory *quick_inventory = new GUIQuickInventory
895 (guienv, NULL, v2s32(10, 70), 5, &local_inventory);*/
896 /*GUIQuickInventory *quick_inventory = new GUIQuickInventory
897 (guienv, NULL, v2s32(0, 0), quickinv_itemcount, &local_inventory);*/
899 // Test the text input system
900 /*(new GUITextInputMenu(guienv, guiroot, -1, &g_menumgr,
902 /*GUIMessageMenu *menu =
903 new GUIMessageMenu(guienv, guiroot, -1,
909 (new GUIPauseMenu(guienv, guiroot, -1, g_gamecallback,
910 &g_menumgr))->drop();
913 /*guitext2->setVisible(true);
914 guitext_info->setVisible(true);
915 guitext_chat->setVisible(true);*/
917 //s32 guitext_chat_pad_bottom = 70;
920 Some statistics are collected in these
923 u32 beginscenetime = 0;
925 u32 endscenetime = 0;
928 //throw con::PeerNotFoundException("lol");
930 core::list<float> frametime_log;
932 float damage_flash_timer = 0;
938 bool first_loop_after_window_activation = true;
940 // Time is in milliseconds
941 // NOTE: getRealTime() causes strange problems in wine (imprecision?)
942 // NOTE: So we have to use getTime() and call run()s between them
943 u32 lasttime = device->getTimer()->getTime();
945 while(device->run() && kill == false)
947 if(g_gamecallback->disconnect_requested)
949 g_gamecallback->disconnect_requested = false;
953 if(g_gamecallback->changepassword_requested)
955 (new GUIPasswordChange(guienv, guiroot, -1,
956 &g_menumgr, &client))->drop();
957 g_gamecallback->changepassword_requested = false;
961 Process TextureSource's queue
963 ((TextureSource*)g_texturesource)->processQueue();
968 last_screensize = screensize;
969 screensize = driver->getScreenSize();
970 v2s32 displaycenter(screensize.X/2,screensize.Y/2);
971 //bool screensize_changed = screensize != last_screensize;
973 // Hilight boxes collected during the loop and displayed
974 core::list< core::aabbox3d<f32> > hilightboxes;
977 std::wstring infotext;
979 // When screen size changes, update positions and sizes of stuff
980 /*if(screensize_changed)
982 v2s32 pos(displaycenter.X-((quickinv_itemcount-1)*quickinv_spacing+quickinv_size)/2, screensize.Y-quickinv_spacing);
983 quick_inventory->updatePosition(pos);
986 //TimeTaker //timer1("//timer1");
988 // Time of frame without fps limit
992 // not using getRealTime is necessary for wine
993 u32 time = device->getTimer()->getTime();
995 busytime_u32 = time - lasttime;
998 busytime = busytime_u32 / 1000.0;
1001 //std::cout<<"busytime_u32="<<busytime_u32<<std::endl;
1003 // Necessary for device->getTimer()->getTime()
1010 updateViewingRange(busytime, &client);
1017 float fps_max = g_settings.getFloat("fps_max");
1018 u32 frametime_min = 1000./fps_max;
1020 if(busytime_u32 < frametime_min)
1022 u32 sleeptime = frametime_min - busytime_u32;
1023 device->sleep(sleeptime);
1027 // Necessary for device->getTimer()->getTime()
1031 Time difference calculation
1033 f32 dtime; // in seconds
1035 u32 time = device->getTimer()->getTime();
1037 dtime = (time - lasttime) / 1000.0;
1043 Log frametime for visualization
1045 frametime_log.push_back(dtime);
1046 if(frametime_log.size() > 100)
1048 core::list<float>::Iterator i = frametime_log.begin();
1049 frametime_log.erase(i);
1053 Visualize frametime in terminal
1055 /*for(u32 i=0; i<dtime*400; i++)
1057 std::cout<<std::endl;*/
1060 Time average and jitter calculation
1063 static f32 dtime_avg1 = 0.0;
1064 dtime_avg1 = dtime_avg1 * 0.98 + dtime * 0.02;
1065 f32 dtime_jitter1 = dtime - dtime_avg1;
1067 static f32 dtime_jitter1_max_sample = 0.0;
1068 static f32 dtime_jitter1_max_fraction = 0.0;
1070 static f32 jitter1_max = 0.0;
1071 static f32 counter = 0.0;
1072 if(dtime_jitter1 > jitter1_max)
1073 jitter1_max = dtime_jitter1;
1078 dtime_jitter1_max_sample = jitter1_max;
1079 dtime_jitter1_max_fraction
1080 = dtime_jitter1_max_sample / (dtime_avg1+0.001);
1086 Busytime average and jitter calculation
1089 static f32 busytime_avg1 = 0.0;
1090 busytime_avg1 = busytime_avg1 * 0.98 + busytime * 0.02;
1091 f32 busytime_jitter1 = busytime - busytime_avg1;
1093 static f32 busytime_jitter1_max_sample = 0.0;
1094 static f32 busytime_jitter1_min_sample = 0.0;
1096 static f32 jitter1_max = 0.0;
1097 static f32 jitter1_min = 0.0;
1098 static f32 counter = 0.0;
1099 if(busytime_jitter1 > jitter1_max)
1100 jitter1_max = busytime_jitter1;
1101 if(busytime_jitter1 < jitter1_min)
1102 jitter1_min = busytime_jitter1;
1106 busytime_jitter1_max_sample = jitter1_max;
1107 busytime_jitter1_min_sample = jitter1_min;
1114 Debug info for client
1117 static float counter = 0.0;
1122 client.printDebugInfo(std::cout);
1127 Direct handling of user input
1130 // Reset input if window not active or some menu is active
1131 if(device->isWindowActive() == false || noMenuActive() == false)
1136 // Input handler step() (used by the random input generator)
1140 Launch menus according to keys
1142 if(input->wasKeyDown(getKeySetting("keymap_inventory")))
1144 dstream<<DTIME<<"the_game: "
1145 <<"Launching inventory"<<std::endl;
1147 GUIInventoryMenu *menu =
1148 new GUIInventoryMenu(guienv, guiroot, -1,
1149 &g_menumgr, v2s16(8,7),
1150 client.getInventoryContext(),
1153 core::array<GUIInventoryMenu::DrawSpec> draw_spec;
1154 draw_spec.push_back(GUIInventoryMenu::DrawSpec(
1155 "list", "current_player", "main",
1156 v2s32(0, 3), v2s32(8, 4)));
1157 draw_spec.push_back(GUIInventoryMenu::DrawSpec(
1158 "list", "current_player", "craft",
1159 v2s32(3, 0), v2s32(3, 3)));
1160 draw_spec.push_back(GUIInventoryMenu::DrawSpec(
1161 "list", "current_player", "craftresult",
1162 v2s32(7, 1), v2s32(1, 1)));
1164 menu->setDrawSpec(draw_spec);
1168 else if(input->wasKeyDown(KEY_ESCAPE))
1170 dstream<<DTIME<<"the_game: "
1171 <<"Launching pause menu"<<std::endl;
1172 // It will delete itself by itself
1173 (new GUIPauseMenu(guienv, guiroot, -1, g_gamecallback,
1174 &g_menumgr))->drop();
1176 // Move mouse cursor on top of the disconnect button
1177 input->setMousePos(displaycenter.X, displaycenter.Y+25);
1179 else if(input->wasKeyDown(getKeySetting("keymap_chat")))
1181 TextDest *dest = new TextDestChat(&client);
1183 (new GUITextInputMenu(guienv, guiroot, -1,
1187 else if(input->wasKeyDown(getKeySetting("keymap_freemove")))
1189 if(g_settings.getBool("free_move"))
1191 g_settings.set("free_move","false");
1195 g_settings.set("free_move","true");
1198 else if(input->wasKeyDown(getKeySetting("keymap_fastmove")))
1200 if(g_settings.getBool("fast_move"))
1202 g_settings.set("fast_move","false");
1206 g_settings.set("fast_move","true");
1210 // Item selection with mouse wheel
1212 s32 wheel = input->getMouseWheel();
1213 u16 max_item = MYMIN(PLAYER_INVENTORY_SIZE-1,
1214 hotbar_itemcount-1);
1218 if(g_selected_item < max_item)
1221 g_selected_item = 0;
1225 if(g_selected_item > 0)
1228 g_selected_item = max_item;
1233 for(u16 i=0; i<10; i++)
1235 s32 keycode = irr::KEY_KEY_1 + i;
1237 keycode = irr::KEY_KEY_0;
1238 if(input->wasKeyDown((irr::EKEY_CODE)keycode))
1240 if(i < PLAYER_INVENTORY_SIZE && i < hotbar_itemcount)
1242 g_selected_item = i;
1244 dstream<<DTIME<<"Selected item: "
1245 <<g_selected_item<<std::endl;
1250 // Viewing range selection
1251 if(input->wasKeyDown(getKeySetting("keymap_rangeselect")))
1253 if(draw_control.range_all)
1255 draw_control.range_all = false;
1256 dstream<<DTIME<<"Disabled full viewing range"<<std::endl;
1260 draw_control.range_all = true;
1261 dstream<<DTIME<<"Enabled full viewing range"<<std::endl;
1265 // Print debug stacks
1266 if(input->wasKeyDown(getKeySetting("keymap_print_debug_stacks")))
1268 dstream<<"-----------------------------------------"
1270 dstream<<DTIME<<"Printing debug stacks:"<<std::endl;
1271 dstream<<"-----------------------------------------"
1273 debug_stacks_print();
1277 Player speed control
1278 TODO: Cache the keycodes from getKeySetting
1291 PlayerControl control(
1292 input->isKeyDown(getKeySetting("keymap_forward")),
1293 input->isKeyDown(getKeySetting("keymap_backward")),
1294 input->isKeyDown(getKeySetting("keymap_left")),
1295 input->isKeyDown(getKeySetting("keymap_right")),
1296 input->isKeyDown(getKeySetting("keymap_jump")),
1297 input->isKeyDown(getKeySetting("keymap_special1")),
1298 input->isKeyDown(getKeySetting("keymap_sneak")),
1302 client.setPlayerControl(control);
1311 //TimeTaker timer("server->step(dtime)");
1312 server->step(dtime);
1320 //TimeTaker timer("client.step(dtime)");
1322 //client.step(dtime_avg1);
1325 // Read client events
1328 ClientEvent event = client.getClientEvent();
1329 if(event.type == CE_NONE)
1333 else if(event.type == CE_PLAYER_DAMAGE)
1335 //u16 damage = event.player_damage.amount;
1336 //dstream<<"Player damage: "<<damage<<std::endl;
1337 damage_flash_timer = 0.05;
1339 else if(event.type == CE_PLAYER_FORCE_MOVE)
1341 camera_yaw = event.player_force_move.yaw;
1342 camera_pitch = event.player_force_move.pitch;
1346 // Get player position
1347 v3f player_position = client.getPlayerPosition();
1349 //TimeTaker //timer2("//timer2");
1352 Mouse and camera control
1355 if((device->isWindowActive() && noMenuActive()) || random_input)
1358 device->getCursorControl()->setVisible(false);
1360 if(first_loop_after_window_activation){
1361 //std::cout<<"window active, first loop"<<std::endl;
1362 first_loop_after_window_activation = false;
1365 s32 dx = input->getMousePos().X - displaycenter.X;
1366 s32 dy = input->getMousePos().Y - displaycenter.Y;
1367 //std::cout<<"window active, pos difference "<<dx<<","<<dy<<std::endl;
1369 /*const float keyspeed = 500;
1370 if(input->isKeyDown(irr::KEY_UP))
1371 dy -= dtime * keyspeed;
1372 if(input->isKeyDown(irr::KEY_DOWN))
1373 dy += dtime * keyspeed;
1374 if(input->isKeyDown(irr::KEY_LEFT))
1375 dx -= dtime * keyspeed;
1376 if(input->isKeyDown(irr::KEY_RIGHT))
1377 dx += dtime * keyspeed;*/
1379 camera_yaw -= dx*0.2;
1380 camera_pitch += dy*0.2;
1381 if(camera_pitch < -89.5) camera_pitch = -89.5;
1382 if(camera_pitch > 89.5) camera_pitch = 89.5;
1384 input->setMousePos(displaycenter.X, displaycenter.Y);
1387 device->getCursorControl()->setVisible(true);
1389 //std::cout<<"window inactive"<<std::endl;
1390 first_loop_after_window_activation = true;
1393 camera_yaw = wrapDegrees(camera_yaw);
1394 camera_pitch = wrapDegrees(camera_pitch);
1396 v3f camera_direction = v3f(0,0,1);
1397 camera_direction.rotateYZBy(camera_pitch);
1398 camera_direction.rotateXZBy(camera_yaw);
1400 // This is at the height of the eyes of the current figure
1401 //v3f camera_position = player_position + v3f(0, BS+BS/2, 0);
1402 // This is more like in minecraft
1403 v3f camera_position = player_position + v3f(0, BS+BS*0.625, 0);
1405 camera->setPosition(camera_position);
1406 // *100.0 helps in large map coordinates
1407 camera->setTarget(camera_position + camera_direction * 100.0);
1409 if(FIELD_OF_VIEW_TEST){
1410 client.updateCamera(v3f(0,0,0), v3f(0,0,1));
1413 //TimeTaker timer("client.updateCamera");
1414 client.updateCamera(camera_position, camera_direction);
1418 //TimeTaker //timer3("//timer3");
1421 Calculate what block is the crosshair pointing to
1424 //u32 t1 = device->getTimer()->getRealTime();
1426 //f32 d = 4; // max. distance
1427 f32 d = 4; // max. distance
1428 core::line3d<f32> shootline(camera_position,
1429 camera_position + camera_direction * BS * (d+1));
1431 MapBlockObject *selected_object = client.getSelectedObject
1432 (d*BS, camera_position, shootline);
1434 ClientActiveObject *selected_active_object
1435 = client.getSelectedActiveObject
1436 (d*BS, camera_position, shootline);
1438 if(selected_object != NULL)
1440 //dstream<<"Client returned selected_object != NULL"<<std::endl;
1442 core::aabbox3d<f32> box_on_map
1443 = selected_object->getSelectionBoxOnMap();
1445 hilightboxes.push_back(box_on_map);
1447 infotext = narrow_to_wide(selected_object->infoText());
1449 if(input->getLeftClicked())
1451 std::cout<<DTIME<<"Left-clicked object"<<std::endl;
1452 client.clickObject(0, selected_object->getBlock()->getPos(),
1453 selected_object->getId(), g_selected_item);
1455 else if(input->getRightClicked())
1457 std::cout<<DTIME<<"Right-clicked object"<<std::endl;
1459 Check if we want to modify the object ourselves
1461 if(selected_object->getTypeId() == MAPBLOCKOBJECT_TYPE_SIGN)
1463 dstream<<"Sign object right-clicked"<<std::endl;
1465 if(random_input == false)
1467 // Get a new text for it
1469 TextDest *dest = new TextDestSign(
1470 selected_object->getBlock()->getPos(),
1471 selected_object->getId(),
1474 SignObject *sign_object = (SignObject*)selected_object;
1476 std::wstring wtext =
1477 narrow_to_wide(sign_object->getText());
1479 (new GUITextInputMenu(guienv, guiroot, -1,
1485 Otherwise pass the event to the server as-is
1489 client.clickObject(1, selected_object->getBlock()->getPos(),
1490 selected_object->getId(), g_selected_item);
1494 else if(selected_active_object != NULL)
1496 //dstream<<"Client returned selected_active_object != NULL"<<std::endl;
1498 core::aabbox3d<f32> *selection_box
1499 = selected_active_object->getSelectionBox();
1500 // Box should exist because object was returned in the
1502 assert(selection_box);
1504 v3f pos = selected_active_object->getPosition();
1506 core::aabbox3d<f32> box_on_map(
1507 selection_box->MinEdge + pos,
1508 selection_box->MaxEdge + pos
1511 hilightboxes.push_back(box_on_map);
1513 //infotext = narrow_to_wide("A ClientActiveObject");
1514 infotext = narrow_to_wide(selected_active_object->infoText());
1516 if(input->getLeftClicked())
1518 std::cout<<DTIME<<"Left-clicked object"<<std::endl;
1519 client.clickActiveObject(0,
1520 selected_active_object->getId(), g_selected_item);
1522 else if(input->getRightClicked())
1524 std::cout<<DTIME<<"Right-clicked object"<<std::endl;
1527 else // selected_object == NULL
1531 Find out which node we are pointing at
1534 bool nodefound = false;
1537 core::aabbox3d<f32> nodehilightbox;
1539 getPointedNode(&client, player_position,
1540 camera_direction, camera_position,
1541 nodefound, shootline,
1542 nodepos, neighbourpos,
1545 static float nodig_delay_counter = 0.0;
1549 static v3s16 nodepos_old(-32768,-32768,-32768);
1551 static float dig_time = 0.0;
1552 static u16 dig_index = 0;
1558 hilightboxes.push_back(nodehilightbox);
1561 Check information text of node
1564 NodeMetadata *meta = client.getNodeMetadata(nodepos);
1567 infotext = narrow_to_wide(meta->infoText());
1570 //MapNode node = client.getNode(nodepos);
1576 if(input->getLeftReleased())
1578 client.clearTempMod(nodepos);
1582 if(nodig_delay_counter > 0.0)
1584 nodig_delay_counter -= dtime;
1588 if(nodepos != nodepos_old)
1590 std::cout<<DTIME<<"Pointing at ("<<nodepos.X<<","
1591 <<nodepos.Y<<","<<nodepos.Z<<")"<<std::endl;
1593 if(nodepos_old != v3s16(-32768,-32768,-32768))
1595 client.clearTempMod(nodepos_old);
1600 if(input->getLeftClicked() ||
1601 (input->getLeftState() && nodepos != nodepos_old))
1603 dstream<<DTIME<<"Started digging"<<std::endl;
1604 client.groundAction(0, nodepos, neighbourpos, g_selected_item);
1606 if(input->getLeftClicked())
1608 client.setTempMod(nodepos, NodeMod(NODEMOD_CRACK, 0));
1610 if(input->getLeftState())
1612 MapNode n = client.getNode(nodepos);
1614 // Get tool name. Default is "" = bare hands
1615 std::string toolname = "";
1616 InventoryList *mlist = local_inventory.getList("main");
1619 InventoryItem *item = mlist->getItem(g_selected_item);
1620 if(item && (std::string)item->getName() == "ToolItem")
1622 ToolItem *titem = (ToolItem*)item;
1623 toolname = titem->getToolName();
1627 // Get digging properties for material and tool
1629 DiggingProperties prop =
1630 getDiggingProperties(material, toolname);
1632 float dig_time_complete = 0.0;
1634 if(prop.diggable == false)
1636 /*dstream<<"Material "<<(int)material
1637 <<" not diggable with \""
1638 <<toolname<<"\""<<std::endl;*/
1639 // I guess nobody will wait for this long
1640 dig_time_complete = 10000000.0;
1644 dig_time_complete = prop.time;
1647 if(dig_time_complete >= 0.001)
1649 dig_index = (u16)((float)CRACK_ANIMATION_LENGTH
1650 * dig_time/dig_time_complete);
1652 // This is for torches
1655 dig_index = CRACK_ANIMATION_LENGTH;
1658 if(dig_index < CRACK_ANIMATION_LENGTH)
1660 //TimeTaker timer("client.setTempMod");
1661 //dstream<<"dig_index="<<dig_index<<std::endl;
1662 client.setTempMod(nodepos, NodeMod(NODEMOD_CRACK, dig_index));
1666 dstream<<DTIME<<"Digging completed"<<std::endl;
1667 client.groundAction(3, nodepos, neighbourpos, g_selected_item);
1668 client.clearTempMod(nodepos);
1669 client.removeNode(nodepos);
1673 nodig_delay_counter = dig_time_complete
1674 / (float)CRACK_ANIMATION_LENGTH;
1676 // We don't want a corresponding delay to
1677 // very time consuming nodes
1678 if(nodig_delay_counter > 0.5)
1680 nodig_delay_counter = 0.5;
1682 // We want a slight delay to very little
1683 // time consuming nodes
1684 float mindelay = 0.15;
1685 if(nodig_delay_counter < mindelay)
1687 nodig_delay_counter = mindelay;
1695 if(input->getRightClicked())
1697 std::cout<<DTIME<<"Ground right-clicked"<<std::endl;
1699 if(meta && meta->typeId() == CONTENT_SIGN_WALL && !random_input)
1701 dstream<<"Sign node right-clicked"<<std::endl;
1703 SignNodeMetadata *signmeta = (SignNodeMetadata*)meta;
1705 // Get a new text for it
1707 TextDest *dest = new TextDestSignNode(nodepos, &client);
1709 std::wstring wtext =
1710 narrow_to_wide(signmeta->getText());
1712 (new GUITextInputMenu(guienv, guiroot, -1,
1716 else if(meta && meta->typeId() == CONTENT_CHEST && !random_input)
1718 dstream<<"Chest node right-clicked"<<std::endl;
1720 //ChestNodeMetadata *chestmeta = (ChestNodeMetadata*)meta;
1722 std::string chest_inv_id;
1723 chest_inv_id += "nodemeta:";
1724 chest_inv_id += itos(nodepos.X);
1725 chest_inv_id += ",";
1726 chest_inv_id += itos(nodepos.Y);
1727 chest_inv_id += ",";
1728 chest_inv_id += itos(nodepos.Z);
1730 GUIInventoryMenu *menu =
1731 new GUIInventoryMenu(guienv, guiroot, -1,
1732 &g_menumgr, v2s16(8,9),
1733 client.getInventoryContext(),
1736 core::array<GUIInventoryMenu::DrawSpec> draw_spec;
1738 draw_spec.push_back(GUIInventoryMenu::DrawSpec(
1739 "list", chest_inv_id, "0",
1740 v2s32(0, 0), v2s32(8, 4)));
1741 draw_spec.push_back(GUIInventoryMenu::DrawSpec(
1742 "list", "current_player", "main",
1743 v2s32(0, 5), v2s32(8, 4)));
1745 menu->setDrawSpec(draw_spec);
1750 else if(meta && meta->typeId() == CONTENT_FURNACE && !random_input)
1752 dstream<<"Furnace node right-clicked"<<std::endl;
1754 GUIFurnaceMenu *menu =
1755 new GUIFurnaceMenu(guienv, guiroot, -1,
1756 &g_menumgr, nodepos, &client);
1763 client.groundAction(1, nodepos, neighbourpos, g_selected_item);
1767 nodepos_old = nodepos;
1772 } // selected_object == NULL
1774 input->resetLeftClicked();
1775 input->resetRightClicked();
1777 if(input->getLeftReleased())
1779 std::cout<<DTIME<<"Left button released (stopped digging)"
1781 client.groundAction(2, v3s16(0,0,0), v3s16(0,0,0), 0);
1783 if(input->getRightReleased())
1785 //std::cout<<DTIME<<"Right released"<<std::endl;
1789 input->resetLeftReleased();
1790 input->resetRightReleased();
1793 Calculate stuff for drawing
1796 camera->setAspectRatio((f32)screensize.X / (f32)screensize.Y);
1798 u32 daynight_ratio = client.getDayNightRatio();
1799 u8 l = decode_light((daynight_ratio * LIGHT_SUN) / 1000);
1800 video::SColor bgcolor = video::SColor(
1802 bgcolor_bright.getRed() * l / 255,
1803 bgcolor_bright.getGreen() * l / 255,
1804 bgcolor_bright.getBlue() * l / 255);
1805 /*skycolor.getRed() * l / 255,
1806 skycolor.getGreen() * l / 255,
1807 skycolor.getBlue() * l / 255);*/
1809 float brightness = (float)l/255.0;
1814 if(fabs(brightness - old_brightness) > 0.01)
1815 update_skybox(driver, smgr, skybox, brightness);
1822 clouds->step(dtime);
1823 clouds->update(v2f(player_position.X, player_position.Z),
1824 0.05+brightness*0.95);
1827 // Store brightness value
1828 old_brightness = brightness;
1834 if(g_settings.getBool("enable_fog") == true)
1836 f32 range = draw_control.wanted_range*BS + MAP_BLOCKSIZE*BS*1.5;
1837 if(draw_control.range_all)
1840 range = range * 0.5 + 25*BS;
1844 video::EFT_FOG_LINEAR,
1856 video::EFT_FOG_LINEAR,
1867 Update gui stuff (0ms)
1870 //TimeTaker guiupdatetimer("Gui updating");
1873 static float drawtime_avg = 0;
1874 drawtime_avg = drawtime_avg * 0.95 + (float)drawtime*0.05;
1875 static float beginscenetime_avg = 0;
1876 beginscenetime_avg = beginscenetime_avg * 0.95 + (float)beginscenetime*0.05;
1877 static float scenetime_avg = 0;
1878 scenetime_avg = scenetime_avg * 0.95 + (float)scenetime*0.05;
1879 static float endscenetime_avg = 0;
1880 endscenetime_avg = endscenetime_avg * 0.95 + (float)endscenetime*0.05;
1883 snprintf(temptext, 300, "Minetest-c55 %s ("
1886 " drawtime=%.0f, beginscenetime=%.0f"
1887 ", scenetime=%.0f, endscenetime=%.0f",
1889 draw_control.range_all,
1896 guitext->setText(narrow_to_wide(temptext).c_str());
1901 snprintf(temptext, 300,
1902 "(% .1f, % .1f, % .1f)"
1903 " (% .3f < btime_jitter < % .3f"
1904 ", dtime_jitter = % .1f %%"
1905 ", v_range = %.1f)",
1906 player_position.X/BS,
1907 player_position.Y/BS,
1908 player_position.Z/BS,
1909 busytime_jitter1_min_sample,
1910 busytime_jitter1_max_sample,
1911 dtime_jitter1_max_fraction * 100.0,
1912 draw_control.wanted_range
1915 guitext2->setText(narrow_to_wide(temptext).c_str());
1919 guitext_info->setText(infotext.c_str());
1923 Get chat messages from client
1927 std::wstring message;
1928 while(client.getChatMessage(message))
1930 chat_lines.push_back(ChatLine(message));
1931 /*if(chat_lines.size() > 6)
1933 core::list<ChatLine>::Iterator
1934 i = chat_lines.begin();
1935 chat_lines.erase(i);
1938 // Append them to form the whole static text and throw
1939 // it to the gui element
1941 // This will correspond to the line number counted from
1942 // top to bottom, from size-1 to 0
1943 s16 line_number = chat_lines.size();
1944 // Count of messages to be removed from the top
1945 u16 to_be_removed_count = 0;
1946 for(core::list<ChatLine>::Iterator
1947 i = chat_lines.begin();
1948 i != chat_lines.end(); i++)
1950 // After this, line number is valid for this loop
1955 This results in a maximum age of 60*6 to the
1956 lowermost line and a maximum of 6 lines
1958 float allowed_age = (6-line_number) * 60.0;
1960 if((*i).age > allowed_age)
1962 to_be_removed_count++;
1965 whole += (*i).text + L'\n';
1967 for(u16 i=0; i<to_be_removed_count; i++)
1969 core::list<ChatLine>::Iterator
1970 it = chat_lines.begin();
1971 chat_lines.erase(it);
1973 guitext_chat->setText(whole.c_str());
1975 // Update gui element size and position
1977 /*core::rect<s32> rect(
1979 screensize.Y - guitext_chat_pad_bottom
1980 - text_height*chat_lines.size(),
1982 screensize.Y - guitext_chat_pad_bottom
1984 core::rect<s32> rect(
1988 50 + text_height*chat_lines.size()
1991 guitext_chat->setRelativePosition(rect);
1993 if(chat_lines.size() == 0)
1994 guitext_chat->setVisible(false);
1996 guitext_chat->setVisible(true);
2003 static u16 old_selected_item = 65535;
2004 if(client.getLocalInventoryUpdated()
2005 || g_selected_item != old_selected_item)
2007 old_selected_item = g_selected_item;
2008 //std::cout<<"Updating local inventory"<<std::endl;
2009 client.getLocalInventory(local_inventory);
2013 Send actions returned by the inventory menu
2015 while(inventory_action_queue.size() != 0)
2017 InventoryAction *a = inventory_action_queue.pop_front();
2019 client.sendInventoryAction(a);
2028 TimeTaker drawtimer("Drawing");
2032 TimeTaker timer("beginScene");
2033 driver->beginScene(true, true, bgcolor);
2034 //driver->beginScene(false, true, bgcolor);
2035 beginscenetime = timer.stop(true);
2040 //std::cout<<DTIME<<"smgr->drawAll()"<<std::endl;
2043 TimeTaker timer("smgr");
2045 scenetime = timer.stop(true);
2049 //TimeTaker timer9("auxiliary drawings");
2053 //TimeTaker //timer10("//timer10");
2059 driver->setMaterial(m);
2061 driver->setTransform(video::ETS_WORLD, core::IdentityMatrix);
2063 for(core::list< core::aabbox3d<f32> >::Iterator i=hilightboxes.begin();
2064 i != hilightboxes.end(); i++)
2066 /*std::cout<<"hilightbox min="
2067 <<"("<<i->MinEdge.X<<","<<i->MinEdge.Y<<","<<i->MinEdge.Z<<")"
2069 <<"("<<i->MaxEdge.X<<","<<i->MaxEdge.Y<<","<<i->MaxEdge.Z<<")"
2071 driver->draw3DBox(*i, video::SColor(255,0,0,0));
2077 if(g_settings.getBool("frametime_graph") == true)
2080 for(core::list<float>::Iterator
2081 i = frametime_log.begin();
2082 i != frametime_log.end();
2085 driver->draw2DLine(v2s32(x,50),
2086 v2s32(x,50+(*i)*1000),
2087 video::SColor(255,255,255,255));
2095 driver->draw2DLine(displaycenter - core::vector2d<s32>(10,0),
2096 displaycenter + core::vector2d<s32>(10,0),
2097 video::SColor(255,255,255,255));
2098 driver->draw2DLine(displaycenter - core::vector2d<s32>(0,10),
2099 displaycenter + core::vector2d<s32>(0,10),
2100 video::SColor(255,255,255,255));
2105 //TimeTaker //timer11("//timer11");
2117 draw_hotbar(driver, font, v2s32(displaycenter.X, screensize.Y),
2118 hotbar_imagesize, hotbar_itemcount, &local_inventory,
2125 if(damage_flash_timer > 0.0)
2127 damage_flash_timer -= dtime;
2129 video::SColor color(128,255,0,0);
2130 driver->draw2DRectangle(color,
2131 core::rect<s32>(0,0,screensize.X,screensize.Y),
2139 TimeTaker timer("endScene");
2141 endscenetime = timer.stop(true);
2144 drawtime = drawtimer.stop(true);
2150 static s16 lastFPS = 0;
2151 //u16 fps = driver->getFPS();
2152 u16 fps = (1.0/dtime_avg1);
2156 core::stringw str = L"Minetest [";
2157 str += driver->getName();
2161 device->setWindowCaption(str.c_str());
2172 Draw a "shutting down" screen, which will be shown while the map
2173 generator and other stuff quits
2176 const wchar_t *shuttingdowntext = L"Shutting down stuff...";
2177 gui::IGUIStaticText *gui_shuttingdowntext = guienv->addStaticText(
2178 shuttingdowntext, textrect, false, false);
2179 gui_shuttingdowntext->setTextAlignment(gui::EGUIA_CENTER,
2180 gui::EGUIA_UPPERLEFT);
2181 driver->beginScene(true, true, video::SColor(255,0,0,0));
2184 gui_shuttingdowntext->remove();