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"
35 #include "guiChatConsole.h"
43 #include "mainmenumanager.h"
47 // Needed for determining pointing to nodes
49 #include "nodemetadata.h"
50 #include "main.h" // For g_settings
52 #include "tile.h" // For TextureSource
53 #include "logoutputbuffer.h"
55 #include "quicktune_shortcutter.h"
56 #include "clientmap.h"
60 #include "sound_openal.h"
62 #include "event_manager.h"
66 Setting this to 1 enables a special camera mode that forces
67 the renderers to think that the camera statically points from
68 the starting place to a static direction.
70 This allows one to move around with the player and see what
71 is actually drawn behind solid things and behind the player.
73 #define FIELD_OF_VIEW_TEST 0
80 struct TextDestChat : public TextDest
82 TextDestChat(Client *client)
86 void gotText(std::wstring text)
88 m_client->typeChatMessage(text);
94 struct TextDestNodeMetadata : public TextDest
96 TextDestNodeMetadata(v3s16 p, Client *client)
101 void gotText(std::wstring text)
103 std::string ntext = wide_to_narrow(text);
104 infostream<<"Changing text of a sign node: "
106 m_client->sendSignNodeText(m_p, ntext);
113 /* Respawn menu callback */
115 class MainRespawnInitiator: public IRespawnInitiator
118 MainRespawnInitiator(bool *active, Client *client):
119 m_active(active), m_client(client)
126 m_client->sendRespawn();
136 void draw_hotbar(video::IVideoDriver *driver, gui::IGUIFont *font,
138 v2s32 centerlowerpos, s32 imgsize, s32 itemcount,
139 Inventory *inventory, s32 halfheartcount, u16 playeritem)
141 InventoryList *mainlist = inventory->getList("main");
144 errorstream<<"draw_hotbar(): mainlist == NULL"<<std::endl;
148 s32 padding = imgsize/12;
149 //s32 height = imgsize + padding*2;
150 s32 width = itemcount*(imgsize+padding*2);
152 // Position of upper left corner of bar
153 v2s32 pos = centerlowerpos - v2s32(width/2, imgsize+padding*2);
155 // Draw background color
156 /*core::rect<s32> barrect(0,0,width,height);
158 video::SColor bgcolor(255,128,128,128);
159 driver->draw2DRectangle(bgcolor, barrect, NULL);*/
161 core::rect<s32> imgrect(0,0,imgsize,imgsize);
163 for(s32 i=0; i<itemcount; i++)
165 const ItemStack &item = mainlist->getItem(i);
167 core::rect<s32> rect = imgrect + pos
168 + v2s32(padding+i*(imgsize+padding*2), padding);
172 video::SColor c_outside(255,255,0,0);
173 //video::SColor c_outside(255,0,0,0);
174 //video::SColor c_inside(255,192,192,192);
175 s32 x1 = rect.UpperLeftCorner.X;
176 s32 y1 = rect.UpperLeftCorner.Y;
177 s32 x2 = rect.LowerRightCorner.X;
178 s32 y2 = rect.LowerRightCorner.Y;
179 // Black base borders
180 driver->draw2DRectangle(c_outside,
182 v2s32(x1 - padding, y1 - padding),
183 v2s32(x2 + padding, y1)
185 driver->draw2DRectangle(c_outside,
187 v2s32(x1 - padding, y2),
188 v2s32(x2 + padding, y2 + padding)
190 driver->draw2DRectangle(c_outside,
192 v2s32(x1 - padding, y1),
195 driver->draw2DRectangle(c_outside,
198 v2s32(x2 + padding, y2)
200 /*// Light inside borders
201 driver->draw2DRectangle(c_inside,
203 v2s32(x1 - padding/2, y1 - padding/2),
204 v2s32(x2 + padding/2, y1)
206 driver->draw2DRectangle(c_inside,
208 v2s32(x1 - padding/2, y2),
209 v2s32(x2 + padding/2, y2 + padding/2)
211 driver->draw2DRectangle(c_inside,
213 v2s32(x1 - padding/2, y1),
216 driver->draw2DRectangle(c_inside,
219 v2s32(x2 + padding/2, y2)
224 video::SColor bgcolor2(128,0,0,0);
225 driver->draw2DRectangle(bgcolor2, rect, NULL);
226 drawItemStack(driver, font, item, rect, NULL, gamedef);
232 video::ITexture *heart_texture =
233 gamedef->getTextureSource()->getTextureRaw("heart.png");
236 v2s32 p = pos + v2s32(0, -20);
237 for(s32 i=0; i<halfheartcount/2; i++)
239 const video::SColor color(255,255,255,255);
240 const video::SColor colors[] = {color,color,color,color};
241 core::rect<s32> rect(0,0,16,16);
243 driver->draw2DImage(heart_texture, rect,
244 core::rect<s32>(core::position2d<s32>(0,0),
245 core::dimension2di(heart_texture->getOriginalSize())),
249 if(halfheartcount % 2 == 1)
251 const video::SColor color(255,255,255,255);
252 const video::SColor colors[] = {color,color,color,color};
253 core::rect<s32> rect(0,0,16/2,16);
255 core::dimension2di srcd(heart_texture->getOriginalSize());
257 driver->draw2DImage(heart_texture, rect,
258 core::rect<s32>(core::position2d<s32>(0,0), srcd),
266 Check if a node is pointable
268 inline bool isPointableNode(const MapNode& n,
269 Client *client, bool liquids_pointable)
271 const ContentFeatures &features = client->getNodeDefManager()->get(n);
272 return features.pointable ||
273 (liquids_pointable && features.isLiquid());
277 Find what the player is pointing at
279 PointedThing getPointedThing(Client *client, v3f player_position,
280 v3f camera_direction, v3f camera_position,
281 core::line3d<f32> shootline, f32 d,
282 bool liquids_pointable,
283 bool look_for_object,
284 core::aabbox3d<f32> &hilightbox,
285 bool &should_show_hilightbox,
286 ClientActiveObject *&selected_object)
290 hilightbox = core::aabbox3d<f32>(0,0,0,0,0,0);
291 should_show_hilightbox = false;
292 selected_object = NULL;
294 INodeDefManager *nodedef = client->getNodeDefManager();
295 ClientMap &map = client->getEnv().getClientMap();
297 // First try to find a pointed at active object
300 selected_object = client->getSelectedActiveObject(d*BS,
301 camera_position, shootline);
303 if(selected_object != NULL)
305 core::aabbox3d<f32> *selection_box
306 = selected_object->getSelectionBox();
307 // Box should exist because object was returned in the
309 assert(selection_box);
311 v3f pos = selected_object->getPosition();
313 hilightbox = core::aabbox3d<f32>(
314 selection_box->MinEdge + pos,
315 selection_box->MaxEdge + pos
318 should_show_hilightbox = selected_object->doShowSelectionBox();
320 result.type = POINTEDTHING_OBJECT;
321 result.object_id = selected_object->getId();
325 // That didn't work, try to find a pointed at node
327 f32 mindistance = BS * 1001;
329 v3s16 pos_i = floatToInt(player_position, BS);
331 /*infostream<<"pos_i=("<<pos_i.X<<","<<pos_i.Y<<","<<pos_i.Z<<")"
335 s16 ystart = pos_i.Y + 0 - (camera_direction.Y<0 ? a : 1);
336 s16 zstart = pos_i.Z - (camera_direction.Z<0 ? a : 1);
337 s16 xstart = pos_i.X - (camera_direction.X<0 ? a : 1);
338 s16 yend = pos_i.Y + 1 + (camera_direction.Y>0 ? a : 1);
339 s16 zend = pos_i.Z + (camera_direction.Z>0 ? a : 1);
340 s16 xend = pos_i.X + (camera_direction.X>0 ? a : 1);
342 for(s16 y = ystart; y <= yend; y++)
343 for(s16 z = zstart; z <= zend; z++)
344 for(s16 x = xstart; x <= xend; x++)
349 n = map.getNode(v3s16(x,y,z));
351 catch(InvalidPositionException &e)
355 if(!isPointableNode(n, client, liquids_pointable))
359 v3f npf = intToFloat(np, BS);
364 v3s16(0,0,1), // back
366 v3s16(1,0,0), // right
367 v3s16(0,0,-1), // front
368 v3s16(0,-1,0), // bottom
369 v3s16(-1,0,0), // left
372 const ContentFeatures &f = nodedef->get(n);
374 if(f.selection_box.type == NODEBOX_FIXED)
376 core::aabbox3d<f32> box = f.selection_box.fixed;
380 v3s16 facedirs[6] = {
389 core::aabbox3d<f32> faceboxes[6] = {
392 box.MinEdge.X, box.MinEdge.Y, box.MinEdge.Z,
393 box.MinEdge.X+d, box.MaxEdge.Y, box.MaxEdge.Z
397 box.MaxEdge.X-d, box.MinEdge.Y, box.MinEdge.Z,
398 box.MaxEdge.X, box.MaxEdge.Y, box.MaxEdge.Z
402 box.MinEdge.X, box.MinEdge.Y, box.MinEdge.Z,
403 box.MaxEdge.X, box.MinEdge.Y+d, box.MaxEdge.Z
407 box.MinEdge.X, box.MaxEdge.Y-d, box.MinEdge.Z,
408 box.MaxEdge.X, box.MaxEdge.Y, box.MaxEdge.Z
412 box.MinEdge.X, box.MinEdge.Y, box.MinEdge.Z,
413 box.MaxEdge.X, box.MaxEdge.Y, box.MinEdge.Z+d
417 box.MinEdge.X, box.MinEdge.Y, box.MaxEdge.Z-d,
418 box.MaxEdge.X, box.MaxEdge.Y, box.MaxEdge.Z
422 for(u16 i=0; i<6; i++)
424 v3f facedir_f(facedirs[i].X, facedirs[i].Y, facedirs[i].Z);
425 v3f centerpoint = npf + facedir_f * BS/2;
426 f32 distance = (centerpoint - camera_position).getLength();
427 if(distance >= mindistance)
429 if(!faceboxes[i].intersectsWithLine(shootline))
431 result.type = POINTEDTHING_NODE;
432 result.node_undersurface = np;
433 result.node_abovesurface = np+facedirs[i];
434 mindistance = distance;
436 should_show_hilightbox = true;
439 else if(f.selection_box.type == NODEBOX_WALLMOUNTED)
441 v3s16 dir = n.getWallMountedDir(nodedef);
442 v3f dir_f = v3f(dir.X, dir.Y, dir.Z);
443 dir_f *= BS/2 - BS/6 - BS/20;
444 v3f cpf = npf + dir_f;
445 f32 distance = (cpf - camera_position).getLength();
447 core::aabbox3d<f32> box;
450 if(dir == v3s16(0,1,0)){
451 box = f.selection_box.wall_top;
454 else if(dir == v3s16(0,-1,0)){
455 box = f.selection_box.wall_bottom;
461 f.selection_box.wall_side.MinEdge,
462 f.selection_box.wall_side.MaxEdge
465 for(s32 i=0; i<2; i++)
467 if(dir == v3s16(-1,0,0))
468 vertices[i].rotateXZBy(0);
469 if(dir == v3s16(1,0,0))
470 vertices[i].rotateXZBy(180);
471 if(dir == v3s16(0,0,-1))
472 vertices[i].rotateXZBy(90);
473 if(dir == v3s16(0,0,1))
474 vertices[i].rotateXZBy(-90);
477 box = core::aabbox3d<f32>(vertices[0]);
478 box.addInternalPoint(vertices[1]);
484 if(distance < mindistance)
486 if(box.intersectsWithLine(shootline))
488 result.type = POINTEDTHING_NODE;
489 result.node_undersurface = np;
490 result.node_abovesurface = np;
491 mindistance = distance;
493 should_show_hilightbox = true;
497 else // NODEBOX_REGULAR
499 for(u16 i=0; i<6; i++)
501 v3f dir_f = v3f(dirs[i].X,
502 dirs[i].Y, dirs[i].Z);
503 v3f centerpoint = npf + dir_f * BS/2;
505 (centerpoint - camera_position).getLength();
507 if(distance < mindistance)
509 core::CMatrix4<f32> m;
510 m.buildRotateFromTo(v3f(0,0,1), dir_f);
512 // This is the back face
514 v3f(BS/2, BS/2, BS/2),
515 v3f(-BS/2, -BS/2, BS/2+d)
518 for(u16 j=0; j<2; j++)
520 m.rotateVect(corners[j]);
524 core::aabbox3d<f32> facebox(corners[0]);
525 facebox.addInternalPoint(corners[1]);
527 if(facebox.intersectsWithLine(shootline))
529 result.type = POINTEDTHING_NODE;
530 result.node_undersurface = np;
531 result.node_abovesurface = np + dirs[i];
532 mindistance = distance;
534 //hilightbox = facebox;
536 const float d = 0.502;
537 core::aabbox3d<f32> nodebox
538 (-BS*d, -BS*d, -BS*d, BS*d, BS*d, BS*d);
539 v3f nodepos_f = intToFloat(np, BS);
540 nodebox.MinEdge += nodepos_f;
541 nodebox.MaxEdge += nodepos_f;
542 hilightbox = nodebox;
543 should_show_hilightbox = true;
545 } // if distance < mindistance
554 Draws a screen with a single text on it.
555 Text will be removed when the screen is drawn the next time.
557 /*gui::IGUIStaticText **/
558 void draw_load_screen(const std::wstring &text,
559 video::IVideoDriver* driver, gui::IGUIFont* font)
561 v2u32 screensize = driver->getScreenSize();
562 const wchar_t *loadingtext = text.c_str();
563 core::vector2d<u32> textsize_u = font->getDimension(loadingtext);
564 core::vector2d<s32> textsize(textsize_u.X,textsize_u.Y);
565 core::vector2d<s32> center(screensize.X/2, screensize.Y/2);
566 core::rect<s32> textrect(center - textsize/2, center + textsize/2);
568 gui::IGUIStaticText *guitext = guienv->addStaticText(
569 loadingtext, textrect, false, false);
570 guitext->setTextAlignment(gui::EGUIA_CENTER, gui::EGUIA_UPPERLEFT);
572 driver->beginScene(true, true, video::SColor(255,0,0,0));
581 /* Profiler display */
583 void update_profiler_gui(gui::IGUIStaticText *guitext_profiler,
584 gui::IGUIFont *font, u32 text_height,
585 u32 show_profiler, u32 show_profiler_max)
587 if(show_profiler == 0)
589 guitext_profiler->setVisible(false);
594 std::ostringstream os(std::ios_base::binary);
595 g_profiler->printPage(os, show_profiler, show_profiler_max);
596 std::wstring text = narrow_to_wide(os.str());
597 guitext_profiler->setText(text.c_str());
598 guitext_profiler->setVisible(true);
600 s32 w = font->getDimension(text.c_str()).Width;
603 core::rect<s32> rect(6, 4+(text_height+5)*2, 12+w,
604 8+(text_height+5)*2 +
605 font->getDimension(text.c_str()).Height);
606 guitext_profiler->setRelativePosition(rect);
607 guitext_profiler->setVisible(true);
615 Profiler::GraphValues values;
621 Meta(float initial=0, video::SColor color=
622 video::SColor(255,255,255,255)):
628 std::list<Piece> m_log;
636 void put(const Profiler::GraphValues &values)
639 piece.values = values;
640 m_log.push_back(piece);
641 while(m_log.size() > m_log_max_size)
642 m_log.erase(m_log.begin());
645 void draw(s32 x_left, s32 y_bottom, video::IVideoDriver *driver,
646 gui::IGUIFont* font) const
648 std::map<std::string, Meta> m_meta;
649 for(std::list<Piece>::const_iterator k = m_log.begin();
650 k != m_log.end(); k++)
652 const Piece &piece = *k;
653 for(Profiler::GraphValues::const_iterator i = piece.values.begin();
654 i != piece.values.end(); i++){
655 const std::string &id = i->first;
656 const float &value = i->second;
657 std::map<std::string, Meta>::iterator j =
659 if(j == m_meta.end()){
660 m_meta[id] = Meta(value);
663 if(value < j->second.min)
664 j->second.min = value;
665 if(value > j->second.max)
666 j->second.max = value;
671 static const video::SColor usable_colors[] = {
672 video::SColor(255,255,100,100),
673 video::SColor(255,90,225,90),
674 video::SColor(255,100,100,255),
675 video::SColor(255,255,150,50),
676 video::SColor(255,220,220,100)
678 static const u32 usable_colors_count =
679 sizeof(usable_colors) / sizeof(*usable_colors);
680 u32 next_color_i = 0;
681 for(std::map<std::string, Meta>::iterator i = m_meta.begin();
682 i != m_meta.end(); i++){
683 Meta &meta = i->second;
684 video::SColor color(255,200,200,200);
685 if(next_color_i < usable_colors_count)
686 color = usable_colors[next_color_i++];
691 s32 textx = x_left + m_log_max_size + 15;
692 s32 textx2 = textx + 200 - 15;
696 u32 num_graphs = m_meta.size();
697 core::rect<s32> rect(x_left, y_bottom - num_graphs*graphh,
699 video::SColor bgcolor(120,0,0,0);
700 driver->draw2DRectangle(bgcolor, rect, NULL);
704 for(std::map<std::string, Meta>::const_iterator i = m_meta.begin();
705 i != m_meta.end(); i++){
706 const std::string &id = i->first;
707 const Meta &meta = i->second;
709 s32 y = y_bottom - meta_i * 50;
710 float show_min = meta.min;
711 float show_max = meta.max;
712 if(show_min >= -0.0001 && show_max >= -0.0001){
713 if(show_min <= show_max * 0.5)
718 snprintf(buf, 10, "%.3g", show_max);
719 font->draw(narrow_to_wide(buf).c_str(),
720 core::rect<s32>(textx, y - graphh,
721 textx2, y - graphh + texth),
723 snprintf(buf, 10, "%.3g", show_min);
724 font->draw(narrow_to_wide(buf).c_str(),
725 core::rect<s32>(textx, y - texth,
728 font->draw(narrow_to_wide(id).c_str(),
729 core::rect<s32>(textx, y - graphh/2 - texth/2,
730 textx2, y - graphh/2 + texth/2),
733 s32 graph1h = graphh;
734 bool relativegraph = (show_min != 0 && show_min != show_max);
735 float lastscaledvalue = 0.0;
736 bool lastscaledvalue_exists = false;
737 for(std::list<Piece>::const_iterator j = m_log.begin();
738 j != m_log.end(); j++)
740 const Piece &piece = *j;
742 bool value_exists = false;
743 Profiler::GraphValues::const_iterator k =
744 piece.values.find(id);
745 if(k != piece.values.end()){
751 lastscaledvalue_exists = false;
754 float scaledvalue = 1.0;
755 if(show_max != show_min)
756 scaledvalue = (value - show_min) / (show_max - show_min);
757 if(scaledvalue == 1.0 && value == 0){
759 lastscaledvalue_exists = false;
763 if(lastscaledvalue_exists){
764 s32 ivalue1 = lastscaledvalue * graph1h;
765 s32 ivalue2 = scaledvalue * graph1h;
766 driver->draw2DLine(v2s32(x-1, graph1y - ivalue1),
767 v2s32(x, graph1y - ivalue2), meta.color);
769 lastscaledvalue = scaledvalue;
770 lastscaledvalue_exists = true;
772 s32 ivalue = scaledvalue * graph1h;
773 driver->draw2DLine(v2s32(x, graph1y),
774 v2s32(x, graph1y - ivalue), meta.color);
783 class NodeDugEvent: public MtEvent
789 NodeDugEvent(v3s16 p, MapNode n):
793 const char* getType() const
799 ISoundManager *m_sound;
800 INodeDefManager *m_ndef;
802 float m_player_step_timer;
804 SimpleSoundSpec m_player_step_sound;
805 SimpleSoundSpec m_player_leftpunch_sound;
806 SimpleSoundSpec m_player_rightpunch_sound;
808 SoundMaker(ISoundManager *sound, INodeDefManager *ndef):
811 m_player_step_timer(0)
815 void playPlayerStep()
817 if(m_player_step_timer <= 0 && m_player_step_sound.exists()){
818 m_player_step_timer = 0.03;
819 m_sound->playSound(m_player_step_sound, false);
823 static void viewBobbingStep(MtEvent *e, void *data)
825 SoundMaker *sm = (SoundMaker*)data;
826 sm->playPlayerStep();
829 static void playerRegainGround(MtEvent *e, void *data)
831 SoundMaker *sm = (SoundMaker*)data;
832 sm->playPlayerStep();
835 static void playerJump(MtEvent *e, void *data)
837 //SoundMaker *sm = (SoundMaker*)data;
840 static void cameraPunchLeft(MtEvent *e, void *data)
842 SoundMaker *sm = (SoundMaker*)data;
843 sm->m_sound->playSound(sm->m_player_leftpunch_sound, false);
846 static void cameraPunchRight(MtEvent *e, void *data)
848 SoundMaker *sm = (SoundMaker*)data;
849 sm->m_sound->playSound(sm->m_player_rightpunch_sound, false);
852 static void nodeDug(MtEvent *e, void *data)
854 SoundMaker *sm = (SoundMaker*)data;
855 NodeDugEvent *nde = (NodeDugEvent*)e;
856 sm->m_sound->playSound(sm->m_ndef->get(nde->n).sound_dug, false);
859 void registerReceiver(MtEventManager *mgr)
861 mgr->reg("ViewBobbingStep", SoundMaker::viewBobbingStep, this);
862 mgr->reg("PlayerRegainGround", SoundMaker::playerRegainGround, this);
863 mgr->reg("PlayerJump", SoundMaker::playerJump, this);
864 mgr->reg("CameraPunchLeft", SoundMaker::cameraPunchLeft, this);
865 mgr->reg("CameraPunchRight", SoundMaker::cameraPunchRight, this);
866 mgr->reg("NodeDug", SoundMaker::nodeDug, this);
869 void step(float dtime)
871 m_player_step_timer -= dtime;
875 // Locally stored sounds don't need to be preloaded because of this
876 class GameOnDemandSoundFetcher: public OnDemandSoundFetcher
878 std::set<std::string> m_fetched;
881 void fetchSounds(const std::string &name,
882 std::set<std::string> &dst_paths,
883 std::set<std::string> &dst_datas)
885 if(m_fetched.count(name))
887 m_fetched.insert(name);
888 std::string base = porting::path_share + DIR_DELIM + "testsounds";
889 dst_paths.insert(base + DIR_DELIM + name + ".ogg");
890 dst_paths.insert(base + DIR_DELIM + name + ".0.ogg");
891 dst_paths.insert(base + DIR_DELIM + name + ".1.ogg");
892 dst_paths.insert(base + DIR_DELIM + name + ".2.ogg");
893 dst_paths.insert(base + DIR_DELIM + name + ".3.ogg");
894 dst_paths.insert(base + DIR_DELIM + name + ".4.ogg");
895 dst_paths.insert(base + DIR_DELIM + name + ".5.ogg");
896 dst_paths.insert(base + DIR_DELIM + name + ".6.ogg");
897 dst_paths.insert(base + DIR_DELIM + name + ".7.ogg");
898 dst_paths.insert(base + DIR_DELIM + name + ".8.ogg");
899 dst_paths.insert(base + DIR_DELIM + name + ".9.ogg");
907 IrrlichtDevice *device,
910 std::string playername,
911 std::string password,
912 std::string address, // If "", local server is used
914 std::wstring &error_message,
915 std::string configpath,
916 ChatBackend &chat_backend,
917 const SubgameSpec &gamespec, // Used for local game,
918 bool simple_singleplayer_mode
921 video::IVideoDriver* driver = device->getVideoDriver();
922 scene::ISceneManager* smgr = device->getSceneManager();
924 // Calculate text height using the font
925 u32 text_height = font->getDimension(L"Random test string").Height;
927 v2u32 screensize(0,0);
928 v2u32 last_screensize(0,0);
929 screensize = driver->getScreenSize();
931 const s32 hotbar_itemcount = 8;
932 //const s32 hotbar_imagesize = 36;
933 //const s32 hotbar_imagesize = 64;
934 s32 hotbar_imagesize = 48;
937 Draw "Loading" screen
940 draw_load_screen(L"Loading...", driver, font);
942 // Create texture source
943 IWritableTextureSource *tsrc = createTextureSource(device);
945 // These will be filled by data received from the server
946 // Create item definition manager
947 IWritableItemDefManager *itemdef = createItemDefManager();
948 // Create node definition manager
949 IWritableNodeDefManager *nodedef = createNodeDefManager();
951 // Sound fetcher (useful when testing)
952 GameOnDemandSoundFetcher soundfetcher;
955 ISoundManager *sound = NULL;
956 bool sound_is_dummy = false;
958 infostream<<"Attempting to use OpenAL audio"<<std::endl;
959 sound = createOpenALSoundManager(&soundfetcher);
961 infostream<<"Failed to initialize OpenAL audio"<<std::endl;
964 infostream<<"Using dummy audio."<<std::endl;
965 sound = &dummySoundManager;
966 sound_is_dummy = true;
970 EventManager eventmgr;
973 SoundMaker soundmaker(sound, nodedef);
974 soundmaker.registerReceiver(&eventmgr);
976 // Add chat log output for errors to be shown in chat
977 LogOutputBuffer chat_log_error_buf(LMT_ERROR);
979 // Create UI for modifying quicktune values
980 QuicktuneShortcutter quicktune;
984 SharedPtr will delete it when it goes out of scope.
986 SharedPtr<Server> server;
988 draw_load_screen(L"Creating server...", driver, font);
989 infostream<<"Creating server"<<std::endl;
990 server = new Server(map_dir, configpath, gamespec,
991 simple_singleplayer_mode);
996 do{ // Client scope (breakable do-while(0))
1002 draw_load_screen(L"Creating client...", driver, font);
1003 infostream<<"Creating client"<<std::endl;
1005 MapDrawControl draw_control;
1007 Client client(device, playername.c_str(), password, draw_control,
1008 tsrc, itemdef, nodedef, sound, &eventmgr);
1010 // Client acts as our GameDef
1011 IGameDef *gamedef = &client;
1013 draw_load_screen(L"Resolving address...", driver, font);
1014 Address connect_address(0,0,0,0, port);
1017 //connect_address.Resolve("localhost");
1018 connect_address.setAddress(127,0,0,1);
1020 connect_address.Resolve(address.c_str());
1022 catch(ResolveError &e)
1024 error_message = L"Couldn't resolve address";
1025 errorstream<<wide_to_narrow(error_message)<<std::endl;
1026 // Break out of client scope
1031 Attempt to connect to the server
1034 infostream<<"Connecting to server at ";
1035 connect_address.print(&infostream);
1036 infostream<<std::endl;
1037 client.connect(connect_address);
1040 Wait for server to accept connection
1042 bool could_connect = false;
1043 bool connect_aborted = false;
1045 float frametime = 0.033;
1046 float time_counter = 0.0;
1048 while(device->run())
1050 // Update client and server
1051 client.step(frametime);
1053 server->step(frametime);
1056 if(client.connectedAndInitialized()){
1057 could_connect = true;
1061 if(client.accessDenied()){
1062 error_message = L"Access denied. Reason: "
1063 +client.accessDeniedReason();
1064 errorstream<<wide_to_narrow(error_message)<<std::endl;
1067 if(input->wasKeyDown(EscapeKey)){
1068 connect_aborted = true;
1069 infostream<<"Connect aborted [Escape]"<<std::endl;
1074 std::wostringstream ss;
1075 ss<<L"Connecting to server... (press Escape to cancel)\n";
1076 std::wstring animation = L"/-\\|";
1077 ss<<animation[(int)(time_counter/0.2)%4];
1078 draw_load_screen(ss.str(), driver, font);
1081 sleep_ms(1000*frametime);
1082 time_counter += frametime;
1085 catch(con::PeerNotFoundException &e)
1089 Handle failure to connect
1092 if(error_message == L"" && !connect_aborted){
1093 error_message = L"Connection failed";
1094 errorstream<<wide_to_narrow(error_message)<<std::endl;
1096 // Break out of client scope
1101 Wait until content has been received
1103 bool got_content = false;
1104 bool content_aborted = false;
1106 float frametime = 0.033;
1107 float time_counter = 0.0;
1109 while(device->run())
1111 // Update client and server
1112 client.step(frametime);
1114 server->step(frametime);
1117 if(client.texturesReceived() &&
1118 client.itemdefReceived() &&
1119 client.nodedefReceived()){
1124 if(!client.connectedAndInitialized()){
1125 error_message = L"Client disconnected";
1126 errorstream<<wide_to_narrow(error_message)<<std::endl;
1129 if(input->wasKeyDown(EscapeKey)){
1130 content_aborted = true;
1131 infostream<<"Connect aborted [Escape]"<<std::endl;
1136 std::wostringstream ss;
1137 ss<<L"Waiting content... (press Escape to cancel)\n";
1139 ss<<(client.itemdefReceived()?L"[X]":L"[ ]");
1140 ss<<L" Item definitions\n";
1141 ss<<(client.nodedefReceived()?L"[X]":L"[ ]");
1142 ss<<L" Node definitions\n";
1143 ss<<L"["<<(int)(client.mediaReceiveProgress()*100+0.5)<<L"%] ";
1146 draw_load_screen(ss.str(), driver, font);
1149 sleep_ms(1000*frametime);
1150 time_counter += frametime;
1155 if(error_message == L"" && !content_aborted){
1156 error_message = L"Something failed";
1157 errorstream<<wide_to_narrow(error_message)<<std::endl;
1159 // Break out of client scope
1164 After all content has been received:
1165 Update cached textures, meshes and materials
1167 client.afterContentReceived();
1170 Create the camera node
1172 Camera camera(smgr, draw_control, gamedef);
1173 if (!camera.successfullyCreated(error_message))
1176 f32 camera_yaw = 0; // "right/left"
1177 f32 camera_pitch = 0; // "up/down"
1183 Clouds *clouds = NULL;
1184 if(g_settings->getBool("enable_clouds"))
1186 clouds = new Clouds(smgr->getRootSceneNode(), smgr, -1, time(0));
1194 sky = new Sky(smgr->getRootSceneNode(), smgr, -1);
1200 FarMesh *farmesh = NULL;
1201 if(g_settings->getBool("enable_farmesh"))
1203 farmesh = new FarMesh(smgr->getRootSceneNode(), smgr, -1, client.getMapSeed(), &client);
1207 A copy of the local inventory
1209 Inventory local_inventory(itemdef);
1215 // First line of debug text
1216 gui::IGUIStaticText *guitext = guienv->addStaticText(
1218 core::rect<s32>(5, 5, 795, 5+text_height),
1220 // Second line of debug text
1221 gui::IGUIStaticText *guitext2 = guienv->addStaticText(
1223 core::rect<s32>(5, 5+(text_height+5)*1, 795, (5+text_height)*2),
1225 // At the middle of the screen
1226 // Object infos are shown in this
1227 gui::IGUIStaticText *guitext_info = guienv->addStaticText(
1229 core::rect<s32>(0,0,400,text_height*5+5) + v2s32(100,200),
1232 // Status text (displays info when showing and hiding GUI stuff, etc.)
1233 gui::IGUIStaticText *guitext_status = guienv->addStaticText(
1235 core::rect<s32>(0,0,0,0),
1237 guitext_status->setVisible(false);
1239 std::wstring statustext;
1240 float statustext_time = 0;
1243 gui::IGUIStaticText *guitext_chat = guienv->addStaticText(
1245 core::rect<s32>(0,0,0,0),
1246 //false, false); // Disable word wrap as of now
1248 // Remove stale "recent" chat messages from previous connections
1249 chat_backend.clearRecentChat();
1250 // Chat backend and console
1251 GUIChatConsole *gui_chat_console = new GUIChatConsole(guienv, guienv->getRootGUIElement(), -1, &chat_backend, &client);
1253 // Profiler text (size is updated when text is updated)
1254 gui::IGUIStaticText *guitext_profiler = guienv->addStaticText(
1256 core::rect<s32>(0,0,0,0),
1258 guitext_profiler->setBackgroundColor(video::SColor(120,0,0,0));
1259 guitext_profiler->setVisible(false);
1262 Some statistics are collected in these
1265 u32 beginscenetime = 0;
1267 u32 endscenetime = 0;
1269 float recent_turn_speed = 0.0;
1271 ProfilerGraph graph;
1272 // Initially clear the profiler
1273 Profiler::GraphValues dummyvalues;
1274 g_profiler->graphGet(dummyvalues);
1276 float nodig_delay_timer = 0.0;
1277 float dig_time = 0.0;
1279 PointedThing pointed_old;
1280 bool digging = false;
1281 bool ldown_for_dig = false;
1283 float damage_flash_timer = 0;
1284 s16 farmesh_range = 20*MAP_BLOCKSIZE;
1286 const float object_hit_delay = 0.2;
1287 float object_hit_delay_timer = 0.0;
1288 float time_from_last_punch = 10;
1290 bool invert_mouse = g_settings->getBool("invert_mouse");
1292 bool respawn_menu_active = false;
1293 bool update_wielded_item_trigger = false;
1295 bool show_hud = true;
1296 bool show_chat = true;
1297 bool force_fog_off = false;
1298 bool disable_camera_update = false;
1299 bool show_debug = g_settings->getBool("show_debug");
1300 bool show_profiler_graph = false;
1301 u32 show_profiler = 0;
1302 u32 show_profiler_max = 3; // Number of pages
1304 float time_of_day = 0;
1305 float time_of_day_smooth = 0;
1311 bool first_loop_after_window_activation = true;
1313 // TODO: Convert the static interval timers to these
1314 // Interval limiter for profiler
1315 IntervalLimiter m_profiler_interval;
1317 // Time is in milliseconds
1318 // NOTE: getRealTime() causes strange problems in wine (imprecision?)
1319 // NOTE: So we have to use getTime() and call run()s between them
1320 u32 lasttime = device->getTimer()->getTime();
1324 if(device->run() == false || kill == true)
1327 // Time of frame without fps limit
1331 // not using getRealTime is necessary for wine
1332 u32 time = device->getTimer()->getTime();
1334 busytime_u32 = time - lasttime;
1337 busytime = busytime_u32 / 1000.0;
1340 g_profiler->graphAdd("mainloop_other", busytime - (float)drawtime/1000.0f);
1342 // Necessary for device->getTimer()->getTime()
1350 float fps_max = g_settings->getFloat("fps_max");
1351 u32 frametime_min = 1000./fps_max;
1353 if(busytime_u32 < frametime_min)
1355 u32 sleeptime = frametime_min - busytime_u32;
1356 device->sleep(sleeptime);
1357 g_profiler->graphAdd("mainloop_sleep", (float)sleeptime/1000.0f);
1361 // Necessary for device->getTimer()->getTime()
1365 Time difference calculation
1367 f32 dtime; // in seconds
1369 u32 time = device->getTimer()->getTime();
1371 dtime = (time - lasttime) / 1000.0;
1376 g_profiler->graphAdd("mainloop_dtime", dtime);
1380 if(nodig_delay_timer >= 0)
1381 nodig_delay_timer -= dtime;
1382 if(object_hit_delay_timer >= 0)
1383 object_hit_delay_timer -= dtime;
1384 time_from_last_punch += dtime;
1386 g_profiler->add("Elapsed time", dtime);
1387 g_profiler->avg("FPS", 1./dtime);
1390 Time average and jitter calculation
1393 static f32 dtime_avg1 = 0.0;
1394 dtime_avg1 = dtime_avg1 * 0.96 + dtime * 0.04;
1395 f32 dtime_jitter1 = dtime - dtime_avg1;
1397 static f32 dtime_jitter1_max_sample = 0.0;
1398 static f32 dtime_jitter1_max_fraction = 0.0;
1400 static f32 jitter1_max = 0.0;
1401 static f32 counter = 0.0;
1402 if(dtime_jitter1 > jitter1_max)
1403 jitter1_max = dtime_jitter1;
1408 dtime_jitter1_max_sample = jitter1_max;
1409 dtime_jitter1_max_fraction
1410 = dtime_jitter1_max_sample / (dtime_avg1+0.001);
1416 Busytime average and jitter calculation
1419 static f32 busytime_avg1 = 0.0;
1420 busytime_avg1 = busytime_avg1 * 0.98 + busytime * 0.02;
1421 f32 busytime_jitter1 = busytime - busytime_avg1;
1423 static f32 busytime_jitter1_max_sample = 0.0;
1424 static f32 busytime_jitter1_min_sample = 0.0;
1426 static f32 jitter1_max = 0.0;
1427 static f32 jitter1_min = 0.0;
1428 static f32 counter = 0.0;
1429 if(busytime_jitter1 > jitter1_max)
1430 jitter1_max = busytime_jitter1;
1431 if(busytime_jitter1 < jitter1_min)
1432 jitter1_min = busytime_jitter1;
1436 busytime_jitter1_max_sample = jitter1_max;
1437 busytime_jitter1_min_sample = jitter1_min;
1444 Handle miscellaneous stuff
1447 if(client.accessDenied())
1449 error_message = L"Access denied. Reason: "
1450 +client.accessDeniedReason();
1451 errorstream<<wide_to_narrow(error_message)<<std::endl;
1455 if(g_gamecallback->disconnect_requested)
1457 g_gamecallback->disconnect_requested = false;
1461 if(g_gamecallback->changepassword_requested)
1463 (new GUIPasswordChange(guienv, guiroot, -1,
1464 &g_menumgr, &client))->drop();
1465 g_gamecallback->changepassword_requested = false;
1469 Process TextureSource's queue
1471 tsrc->processQueue();
1476 last_screensize = screensize;
1477 screensize = driver->getScreenSize();
1478 v2s32 displaycenter(screensize.X/2,screensize.Y/2);
1479 //bool screensize_changed = screensize != last_screensize;
1482 if(screensize.Y <= 800)
1483 hotbar_imagesize = 32;
1484 else if(screensize.Y <= 1280)
1485 hotbar_imagesize = 48;
1487 hotbar_imagesize = 64;
1489 // Hilight boxes collected during the loop and displayed
1490 core::list< core::aabbox3d<f32> > hilightboxes;
1493 std::wstring infotext;
1496 Debug info for client
1499 static float counter = 0.0;
1504 client.printDebugInfo(infostream);
1511 float profiler_print_interval =
1512 g_settings->getFloat("profiler_print_interval");
1513 bool print_to_log = true;
1514 if(profiler_print_interval == 0){
1515 print_to_log = false;
1516 profiler_print_interval = 5;
1518 if(m_profiler_interval.step(dtime, profiler_print_interval))
1521 infostream<<"Profiler:"<<std::endl;
1522 g_profiler->print(infostream);
1525 update_profiler_gui(guitext_profiler, font, text_height,
1526 show_profiler, show_profiler_max);
1528 g_profiler->clear();
1532 Direct handling of user input
1535 // Reset input if window not active or some menu is active
1536 if(device->isWindowActive() == false
1537 || noMenuActive() == false
1538 || guienv->hasFocus(gui_chat_console))
1543 // Input handler step() (used by the random input generator)
1547 Launch menus and trigger stuff according to keys
1549 if(input->wasKeyDown(getKeySetting("keymap_drop")))
1551 // drop selected item
1552 IDropAction *a = new IDropAction();
1554 a->from_inv.setCurrentPlayer();
1555 a->from_list = "main";
1556 a->from_i = client.getPlayerItem();
1557 client.inventoryAction(a);
1559 else if(input->wasKeyDown(getKeySetting("keymap_inventory")))
1561 infostream<<"the_game: "
1562 <<"Launching inventory"<<std::endl;
1564 GUIInventoryMenu *menu =
1565 new GUIInventoryMenu(guienv, guiroot, -1,
1566 &g_menumgr, v2s16(8,7),
1569 InventoryLocation inventoryloc;
1570 inventoryloc.setCurrentPlayer();
1572 core::array<GUIInventoryMenu::DrawSpec> draw_spec;
1573 draw_spec.push_back(GUIInventoryMenu::DrawSpec(
1574 "list", inventoryloc, "main",
1575 v2s32(0, 3), v2s32(8, 4)));
1576 draw_spec.push_back(GUIInventoryMenu::DrawSpec(
1577 "list", inventoryloc, "craft",
1578 v2s32(3, 0), v2s32(3, 3)));
1579 draw_spec.push_back(GUIInventoryMenu::DrawSpec(
1580 "list", inventoryloc, "craftpreview",
1581 v2s32(7, 1), v2s32(1, 1)));
1583 menu->setDrawSpec(draw_spec);
1587 else if(input->wasKeyDown(EscapeKey))
1589 infostream<<"the_game: "
1590 <<"Launching pause menu"<<std::endl;
1591 // It will delete itself by itself
1592 (new GUIPauseMenu(guienv, guiroot, -1, g_gamecallback,
1593 &g_menumgr, simple_singleplayer_mode))->drop();
1595 // Move mouse cursor on top of the disconnect button
1596 if(simple_singleplayer_mode)
1597 input->setMousePos(displaycenter.X, displaycenter.Y+0);
1599 input->setMousePos(displaycenter.X, displaycenter.Y+25);
1601 else if(input->wasKeyDown(getKeySetting("keymap_chat")))
1603 TextDest *dest = new TextDestChat(&client);
1605 (new GUITextInputMenu(guienv, guiroot, -1,
1609 else if(input->wasKeyDown(getKeySetting("keymap_cmd")))
1611 TextDest *dest = new TextDestChat(&client);
1613 (new GUITextInputMenu(guienv, guiroot, -1,
1617 else if(input->wasKeyDown(getKeySetting("keymap_console")))
1619 if (!gui_chat_console->isOpenInhibited())
1621 // Open up to over half of the screen
1622 gui_chat_console->openConsole(0.6);
1623 guienv->setFocus(gui_chat_console);
1626 else if(input->wasKeyDown(getKeySetting("keymap_freemove")))
1628 if(g_settings->getBool("free_move"))
1630 g_settings->set("free_move","false");
1631 statustext = L"free_move disabled";
1632 statustext_time = 0;
1636 g_settings->set("free_move","true");
1637 statustext = L"free_move enabled";
1638 statustext_time = 0;
1641 else if(input->wasKeyDown(getKeySetting("keymap_fastmove")))
1643 if(g_settings->getBool("fast_move"))
1645 g_settings->set("fast_move","false");
1646 statustext = L"fast_move disabled";
1647 statustext_time = 0;
1651 g_settings->set("fast_move","true");
1652 statustext = L"fast_move enabled";
1653 statustext_time = 0;
1656 else if(input->wasKeyDown(getKeySetting("keymap_screenshot")))
1658 irr::video::IImage* const image = driver->createScreenShot();
1660 irr::c8 filename[256];
1661 snprintf(filename, 256, "%s" DIR_DELIM "screenshot_%u.png",
1662 g_settings->get("screenshot_path").c_str(),
1663 device->getTimer()->getRealTime());
1664 if (driver->writeImageToFile(image, filename)) {
1665 std::wstringstream sstr;
1666 sstr<<"Saved screenshot to '"<<filename<<"'";
1667 infostream<<"Saved screenshot to '"<<filename<<"'"<<std::endl;
1668 statustext = sstr.str();
1669 statustext_time = 0;
1671 infostream<<"Failed to save screenshot '"<<filename<<"'"<<std::endl;
1676 else if(input->wasKeyDown(getKeySetting("keymap_toggle_hud")))
1678 show_hud = !show_hud;
1680 statustext = L"HUD shown";
1682 statustext = L"HUD hidden";
1683 statustext_time = 0;
1685 else if(input->wasKeyDown(getKeySetting("keymap_toggle_chat")))
1687 show_chat = !show_chat;
1689 statustext = L"Chat shown";
1691 statustext = L"Chat hidden";
1692 statustext_time = 0;
1694 else if(input->wasKeyDown(getKeySetting("keymap_toggle_force_fog_off")))
1696 force_fog_off = !force_fog_off;
1698 statustext = L"Fog disabled";
1700 statustext = L"Fog enabled";
1701 statustext_time = 0;
1703 else if(input->wasKeyDown(getKeySetting("keymap_toggle_update_camera")))
1705 disable_camera_update = !disable_camera_update;
1706 if(disable_camera_update)
1707 statustext = L"Camera update disabled";
1709 statustext = L"Camera update enabled";
1710 statustext_time = 0;
1712 else if(input->wasKeyDown(getKeySetting("keymap_toggle_debug")))
1714 // Initial / 3x toggle: Chat only
1715 // 1x toggle: Debug text with chat
1716 // 2x toggle: Debug text with profiler graph
1720 show_profiler_graph = false;
1721 statustext = L"Debug info shown";
1722 statustext_time = 0;
1724 else if(show_profiler_graph)
1727 show_profiler_graph = false;
1728 statustext = L"Debug info and profiler graph hidden";
1729 statustext_time = 0;
1733 show_profiler_graph = true;
1734 statustext = L"Profiler graph shown";
1735 statustext_time = 0;
1738 else if(input->wasKeyDown(getKeySetting("keymap_toggle_profiler")))
1740 show_profiler = (show_profiler + 1) % (show_profiler_max + 1);
1742 // FIXME: This updates the profiler with incomplete values
1743 update_profiler_gui(guitext_profiler, font, text_height,
1744 show_profiler, show_profiler_max);
1746 if(show_profiler != 0)
1748 std::wstringstream sstr;
1749 sstr<<"Profiler shown (page "<<show_profiler
1750 <<" of "<<show_profiler_max<<")";
1751 statustext = sstr.str();
1752 statustext_time = 0;
1756 statustext = L"Profiler hidden";
1757 statustext_time = 0;
1760 else if(input->wasKeyDown(getKeySetting("keymap_increase_viewing_range_min")))
1762 s16 range = g_settings->getS16("viewing_range_nodes_min");
1763 s16 range_new = range + 10;
1764 g_settings->set("viewing_range_nodes_min", itos(range_new));
1765 statustext = narrow_to_wide(
1766 "Minimum viewing range changed to "
1768 statustext_time = 0;
1770 else if(input->wasKeyDown(getKeySetting("keymap_decrease_viewing_range_min")))
1772 s16 range = g_settings->getS16("viewing_range_nodes_min");
1773 s16 range_new = range - 10;
1776 g_settings->set("viewing_range_nodes_min",
1778 statustext = narrow_to_wide(
1779 "Minimum viewing range changed to "
1781 statustext_time = 0;
1784 // Handle QuicktuneShortcutter
1785 if(input->wasKeyDown(getKeySetting("keymap_quicktune_next")))
1787 if(input->wasKeyDown(getKeySetting("keymap_quicktune_prev")))
1789 if(input->wasKeyDown(getKeySetting("keymap_quicktune_inc")))
1791 if(input->wasKeyDown(getKeySetting("keymap_quicktune_dec")))
1794 std::string msg = quicktune.getMessage();
1796 statustext = narrow_to_wide(msg);
1797 statustext_time = 0;
1801 // Item selection with mouse wheel
1802 u16 new_playeritem = client.getPlayerItem();
1804 s32 wheel = input->getMouseWheel();
1805 u16 max_item = MYMIN(PLAYER_INVENTORY_SIZE-1,
1806 hotbar_itemcount-1);
1810 if(new_playeritem < max_item)
1817 if(new_playeritem > 0)
1820 new_playeritem = max_item;
1825 for(u16 i=0; i<10; i++)
1827 const KeyPress *kp = NumberKey + (i + 1) % 10;
1828 if(input->wasKeyDown(*kp))
1830 if(i < PLAYER_INVENTORY_SIZE && i < hotbar_itemcount)
1834 infostream<<"Selected item: "
1835 <<new_playeritem<<std::endl;
1840 // Viewing range selection
1841 if(input->wasKeyDown(getKeySetting("keymap_rangeselect")))
1843 draw_control.range_all = !draw_control.range_all;
1844 if(draw_control.range_all)
1846 infostream<<"Enabled full viewing range"<<std::endl;
1847 statustext = L"Enabled full viewing range";
1848 statustext_time = 0;
1852 infostream<<"Disabled full viewing range"<<std::endl;
1853 statustext = L"Disabled full viewing range";
1854 statustext_time = 0;
1858 // Print debug stacks
1859 if(input->wasKeyDown(getKeySetting("keymap_print_debug_stacks")))
1861 dstream<<"-----------------------------------------"
1863 dstream<<DTIME<<"Printing debug stacks:"<<std::endl;
1864 dstream<<"-----------------------------------------"
1866 debug_stacks_print();
1870 Mouse and camera control
1871 NOTE: Do this before client.setPlayerControl() to not cause a camera lag of one frame
1874 float turn_amount = 0;
1875 if((device->isWindowActive() && noMenuActive()) || random_input)
1879 // Mac OSX gets upset if this is set every frame
1880 if(device->getCursorControl()->isVisible())
1881 device->getCursorControl()->setVisible(false);
1884 if(first_loop_after_window_activation){
1885 //infostream<<"window active, first loop"<<std::endl;
1886 first_loop_after_window_activation = false;
1889 s32 dx = input->getMousePos().X - displaycenter.X;
1890 s32 dy = input->getMousePos().Y - displaycenter.Y;
1893 //infostream<<"window active, pos difference "<<dx<<","<<dy<<std::endl;
1895 /*const float keyspeed = 500;
1896 if(input->isKeyDown(irr::KEY_UP))
1897 dy -= dtime * keyspeed;
1898 if(input->isKeyDown(irr::KEY_DOWN))
1899 dy += dtime * keyspeed;
1900 if(input->isKeyDown(irr::KEY_LEFT))
1901 dx -= dtime * keyspeed;
1902 if(input->isKeyDown(irr::KEY_RIGHT))
1903 dx += dtime * keyspeed;*/
1907 camera_pitch += dy*d;
1908 if(camera_pitch < -89.5) camera_pitch = -89.5;
1909 if(camera_pitch > 89.5) camera_pitch = 89.5;
1911 turn_amount = v2f(dx, dy).getLength() * d;
1913 input->setMousePos(displaycenter.X, displaycenter.Y);
1916 // Mac OSX gets upset if this is set every frame
1917 if(device->getCursorControl()->isVisible() == false)
1918 device->getCursorControl()->setVisible(true);
1920 //infostream<<"window inactive"<<std::endl;
1921 first_loop_after_window_activation = true;
1923 recent_turn_speed = recent_turn_speed * 0.9 + turn_amount * 0.1;
1924 //std::cerr<<"recent_turn_speed = "<<recent_turn_speed<<std::endl;
1927 Player speed control
1939 PlayerControl control(
1940 input->isKeyDown(getKeySetting("keymap_forward")),
1941 input->isKeyDown(getKeySetting("keymap_backward")),
1942 input->isKeyDown(getKeySetting("keymap_left")),
1943 input->isKeyDown(getKeySetting("keymap_right")),
1944 input->isKeyDown(getKeySetting("keymap_jump")),
1945 input->isKeyDown(getKeySetting("keymap_special1")),
1946 input->isKeyDown(getKeySetting("keymap_sneak")),
1950 client.setPlayerControl(control);
1959 //TimeTaker timer("server->step(dtime)");
1960 server->step(dtime);
1968 //TimeTaker timer("client.step(dtime)");
1970 //client.step(dtime_avg1);
1974 // Read client events
1977 ClientEvent event = client.getClientEvent();
1978 if(event.type == CE_NONE)
1982 else if(event.type == CE_PLAYER_DAMAGE)
1984 //u16 damage = event.player_damage.amount;
1985 //infostream<<"Player damage: "<<damage<<std::endl;
1986 damage_flash_timer = 0.05;
1987 if(event.player_damage.amount >= 2){
1988 damage_flash_timer += 0.05 * event.player_damage.amount;
1991 else if(event.type == CE_PLAYER_FORCE_MOVE)
1993 camera_yaw = event.player_force_move.yaw;
1994 camera_pitch = event.player_force_move.pitch;
1996 else if(event.type == CE_DEATHSCREEN)
1998 if(respawn_menu_active)
2001 /*bool set_camera_point_target =
2002 event.deathscreen.set_camera_point_target;
2003 v3f camera_point_target;
2004 camera_point_target.X = event.deathscreen.camera_point_target_x;
2005 camera_point_target.Y = event.deathscreen.camera_point_target_y;
2006 camera_point_target.Z = event.deathscreen.camera_point_target_z;*/
2007 MainRespawnInitiator *respawner =
2008 new MainRespawnInitiator(
2009 &respawn_menu_active, &client);
2010 GUIDeathScreen *menu =
2011 new GUIDeathScreen(guienv, guiroot, -1,
2012 &g_menumgr, respawner);
2015 chat_backend.addMessage(L"", L"You died.");
2017 /* Handle visualization */
2019 damage_flash_timer = 0;
2021 /*LocalPlayer* player = client.getLocalPlayer();
2022 player->setPosition(player->getPosition() + v3f(0,-BS,0));
2023 camera.update(player, busytime, screensize);*/
2025 else if(event.type == CE_TEXTURES_UPDATED)
2027 update_wielded_item_trigger = true;
2032 //TimeTaker //timer2("//timer2");
2035 For interaction purposes, get info about the held item
2037 - Is it a usable item?
2038 - Can it point to liquids?
2040 ItemStack playeritem;
2041 bool playeritem_usable = false;
2042 bool playeritem_liquids_pointable = false;
2044 InventoryList *mlist = local_inventory.getList("main");
2047 playeritem = mlist->getItem(client.getPlayerItem());
2048 playeritem_usable = playeritem.getDefinition(itemdef).usable;
2049 playeritem_liquids_pointable = playeritem.getDefinition(itemdef).liquids_pointable;
2052 ToolCapabilities playeritem_toolcap =
2053 playeritem.getToolCapabilities(itemdef);
2059 LocalPlayer* player = client.getEnv().getLocalPlayer();
2060 float full_punch_interval = playeritem_toolcap.full_punch_interval;
2061 float tool_reload_ratio = time_from_last_punch / full_punch_interval;
2062 tool_reload_ratio = MYMIN(tool_reload_ratio, 1.0);
2063 camera.update(player, busytime, screensize, tool_reload_ratio);
2066 v3f player_position = player->getPosition();
2067 v3f camera_position = camera.getPosition();
2068 v3f camera_direction = camera.getDirection();
2069 f32 camera_fov = camera.getFovMax();
2071 if(!disable_camera_update){
2072 client.getEnv().getClientMap().updateCamera(camera_position,
2073 camera_direction, camera_fov);
2076 // Update sound listener
2077 sound->updateListener(camera.getCameraNode()->getPosition(),
2078 v3f(0,0,0), // velocity
2079 camera.getCameraNode()->getTarget(),
2080 camera.getCameraNode()->getUpVector());
2086 soundmaker.step(dtime);
2088 ClientMap &map = client.getEnv().getClientMap();
2089 MapNode n = map.getNodeNoEx(player->getStandingNodePos());
2090 soundmaker.m_player_step_sound = nodedef->get(n).sound_footstep;
2094 Calculate what block is the crosshair pointing to
2097 //u32 t1 = device->getTimer()->getRealTime();
2099 f32 d = 4; // max. distance
2100 core::line3d<f32> shootline(camera_position,
2101 camera_position + camera_direction * BS * (d+1));
2103 core::aabbox3d<f32> hilightbox;
2104 bool should_show_hilightbox = false;
2105 ClientActiveObject *selected_object = NULL;
2107 PointedThing pointed = getPointedThing(
2109 &client, player_position, camera_direction,
2110 camera_position, shootline, d,
2111 playeritem_liquids_pointable, !ldown_for_dig,
2113 hilightbox, should_show_hilightbox,
2116 if(pointed != pointed_old)
2118 infostream<<"Pointing at "<<pointed.dump()<<std::endl;
2119 //dstream<<"Pointing at "<<pointed.dump()<<std::endl;
2125 if(should_show_hilightbox)
2126 hilightboxes.push_back(hilightbox);
2130 - releasing left mouse button
2131 - pointing away from node
2135 if(input->getLeftReleased())
2137 infostream<<"Left button released"
2138 <<" (stopped digging)"<<std::endl;
2141 else if(pointed != pointed_old)
2143 if (pointed.type == POINTEDTHING_NODE
2144 && pointed_old.type == POINTEDTHING_NODE
2145 && pointed.node_undersurface == pointed_old.node_undersurface)
2147 // Still pointing to the same node,
2148 // but a different face. Don't reset.
2152 infostream<<"Pointing away from node"
2153 <<" (stopped digging)"<<std::endl;
2159 client.interact(1, pointed_old);
2160 client.setCrack(-1, v3s16(0,0,0));
2164 if(!digging && ldown_for_dig && !input->getLeftState())
2166 ldown_for_dig = false;
2169 bool left_punch = false;
2170 soundmaker.m_player_leftpunch_sound.name = "";
2172 if(playeritem_usable && input->getLeftState())
2174 if(input->getLeftClicked())
2175 client.interact(4, pointed);
2177 else if(pointed.type == POINTEDTHING_NODE)
2179 v3s16 nodepos = pointed.node_undersurface;
2180 v3s16 neighbourpos = pointed.node_abovesurface;
2183 Check information text of node
2186 ClientMap &map = client.getEnv().getClientMap();
2187 NodeMetadata *meta = map.getNodeMetadata(nodepos);
2189 infotext = narrow_to_wide(meta->infoText());
2191 MapNode n = map.getNode(nodepos);
2192 if(nodedef->get(n).tname_tiles[0] == "unknown_block.png"){
2193 infotext = L"Unknown node: ";
2194 infotext += narrow_to_wide(nodedef->get(n).name);
2198 // We can't actually know, but assume the sound of right-clicking
2199 // to be the sound of placing a node
2200 soundmaker.m_player_rightpunch_sound.gain = 0.5;
2201 soundmaker.m_player_rightpunch_sound.name = "default_place_node";
2207 if(nodig_delay_timer <= 0.0 && input->getLeftState())
2211 infostream<<"Started digging"<<std::endl;
2212 client.interact(0, pointed);
2214 ldown_for_dig = true;
2216 MapNode n = client.getEnv().getClientMap().getNode(nodepos);
2218 // Get digging parameters
2219 DigParams params = getDigParams(nodedef->get(n).groups,
2220 &playeritem_toolcap);
2221 // If can't dig, try hand
2222 if(!params.diggable){
2223 const ItemDefinition &hand = itemdef->get("");
2224 const ToolCapabilities *tp = hand.tool_capabilities;
2226 params = getDigParams(nodedef->get(n).groups, tp);
2229 SimpleSoundSpec sound_dig = nodedef->get(n).sound_dig;
2230 if(sound_dig.exists()){
2231 if(sound_dig.name == "__group"){
2232 if(params.main_group != ""){
2233 soundmaker.m_player_leftpunch_sound.gain = 0.5;
2234 soundmaker.m_player_leftpunch_sound.name =
2235 std::string("default_dig_") +
2239 soundmaker.m_player_leftpunch_sound = sound_dig;
2243 float dig_time_complete = 0.0;
2245 if(params.diggable == false)
2247 // I guess nobody will wait for this long
2248 dig_time_complete = 10000000.0;
2252 dig_time_complete = params.time;
2255 if(dig_time_complete >= 0.001)
2257 dig_index = (u16)((float)CRACK_ANIMATION_LENGTH
2258 * dig_time/dig_time_complete);
2260 // This is for torches
2263 dig_index = CRACK_ANIMATION_LENGTH;
2266 // Don't show cracks if not diggable
2267 if(dig_time_complete >= 100000.0)
2270 else if(dig_index < CRACK_ANIMATION_LENGTH)
2272 //TimeTaker timer("client.setTempMod");
2273 //infostream<<"dig_index="<<dig_index<<std::endl;
2274 client.setCrack(dig_index, nodepos);
2278 infostream<<"Digging completed"<<std::endl;
2279 client.interact(2, pointed);
2280 client.setCrack(-1, v3s16(0,0,0));
2281 MapNode wasnode = map.getNode(nodepos);
2282 client.removeNode(nodepos);
2287 nodig_delay_timer = dig_time_complete
2288 / (float)CRACK_ANIMATION_LENGTH;
2290 // We don't want a corresponding delay to
2291 // very time consuming nodes
2292 if(nodig_delay_timer > 0.3)
2293 nodig_delay_timer = 0.3;
2294 // We want a slight delay to very little
2295 // time consuming nodes
2296 float mindelay = 0.15;
2297 if(nodig_delay_timer < mindelay)
2298 nodig_delay_timer = mindelay;
2300 // Send event to trigger sound
2301 MtEvent *e = new NodeDugEvent(nodepos, wasnode);
2302 gamedef->event()->put(e);
2307 camera.setDigging(0); // left click animation
2310 if(input->getRightClicked())
2312 infostream<<"Ground right-clicked"<<std::endl;
2314 // If metadata provides an inventory view, activate it
2315 if(meta && meta->getInventoryDrawSpecString() != "" && !random_input)
2317 infostream<<"Launching custom inventory view"<<std::endl;
2319 InventoryLocation inventoryloc;
2320 inventoryloc.setNodeMeta(nodepos);
2327 core::array<GUIInventoryMenu::DrawSpec> draw_spec;
2329 GUIInventoryMenu::makeDrawSpecArrayFromString(
2331 meta->getInventoryDrawSpecString(),
2334 GUIInventoryMenu *menu =
2335 new GUIInventoryMenu(guienv, guiroot, -1,
2336 &g_menumgr, invsize,
2338 menu->setDrawSpec(draw_spec);
2341 // If metadata provides text input, activate text input
2342 else if(meta && meta->allowsTextInput() && !random_input)
2344 infostream<<"Launching metadata text input"<<std::endl;
2346 // Get a new text for it
2348 TextDest *dest = new TextDestNodeMetadata(nodepos, &client);
2350 std::wstring wtext = narrow_to_wide(meta->getText());
2352 (new GUITextInputMenu(guienv, guiroot, -1,
2356 // Otherwise report right click to server
2359 client.interact(3, pointed);
2360 camera.setDigging(1); // right click animation
2364 else if(pointed.type == POINTEDTHING_OBJECT)
2366 infotext = narrow_to_wide(selected_object->infoText());
2368 if(infotext == L"" && show_debug){
2369 infotext = narrow_to_wide(selected_object->debugInfoText());
2372 //if(input->getLeftClicked())
2373 if(input->getLeftState())
2375 bool do_punch = false;
2376 bool do_punch_damage = false;
2377 if(object_hit_delay_timer <= 0.0){
2379 do_punch_damage = true;
2380 object_hit_delay_timer = object_hit_delay;
2382 if(input->getLeftClicked()){
2386 infostream<<"Left-clicked object"<<std::endl;
2389 if(do_punch_damage){
2390 // Report direct punch
2391 v3f objpos = selected_object->getPosition();
2392 v3f dir = (objpos - player_position).normalize();
2394 bool disable_send = selected_object->directReportPunch(
2395 dir, &playeritem, time_from_last_punch);
2396 time_from_last_punch = 0;
2398 client.interact(0, pointed);
2401 else if(input->getRightClicked())
2403 infostream<<"Right-clicked object"<<std::endl;
2404 client.interact(3, pointed); // place
2407 else if(input->getLeftState())
2409 // When button is held down in air, show continuous animation
2413 pointed_old = pointed;
2415 if(left_punch || input->getLeftClicked())
2417 camera.setDigging(0); // left click animation
2420 input->resetLeftClicked();
2421 input->resetRightClicked();
2423 input->resetLeftReleased();
2424 input->resetRightReleased();
2427 Calculate stuff for drawing
2437 fog_range = BS*farmesh_range;
2441 fog_range = draw_control.wanted_range*BS + 0.0*MAP_BLOCKSIZE*BS;
2443 if(draw_control.range_all)
2444 fog_range = 100000*BS;
2448 Calculate general brightness
2450 u32 daynight_ratio = client.getEnv().getDayNightRatio();
2451 float time_brightness = (float)decode_light(
2452 (daynight_ratio * LIGHT_SUN) / 1000) / 255.0;
2453 float direct_brightness = 0;
2454 bool sunlight_seen = false;
2455 if(g_settings->getBool("free_move")){
2456 direct_brightness = time_brightness;
2457 sunlight_seen = true;
2459 ScopeProfiler sp(g_profiler, "Detecting background light", SPT_AVG);
2460 float old_brightness = sky->getBrightness();
2461 direct_brightness = (float)client.getEnv().getClientMap()
2462 .getBackgroundBrightness(MYMIN(fog_range*1.2, 60*BS),
2463 daynight_ratio, (int)(old_brightness*255.5), &sunlight_seen)
2467 time_of_day = client.getEnv().getTimeOfDayF();
2469 if(fabs(time_of_day - time_of_day_smooth) > maxsm &&
2470 fabs(time_of_day - time_of_day_smooth + 1.0) > maxsm &&
2471 fabs(time_of_day - time_of_day_smooth - 1.0) > maxsm)
2472 time_of_day_smooth = time_of_day;
2474 if(time_of_day_smooth > 0.8 && time_of_day < 0.2)
2475 time_of_day_smooth = time_of_day_smooth * (1.0-todsm)
2476 + (time_of_day+1.0) * todsm;
2478 time_of_day_smooth = time_of_day_smooth * (1.0-todsm)
2479 + time_of_day * todsm;
2481 sky->update(time_of_day_smooth, time_brightness, direct_brightness,
2484 float brightness = sky->getBrightness();
2485 video::SColor bgcolor = sky->getBgColor();
2486 video::SColor skycolor = sky->getSkyColor();
2492 if(sky->getCloudsVisible()){
2493 clouds->setVisible(true);
2494 clouds->step(dtime);
2495 clouds->update(v2f(player_position.X, player_position.Z),
2496 sky->getCloudColor());
2498 clouds->setVisible(false);
2507 farmesh_range = draw_control.wanted_range * 10;
2508 if(draw_control.range_all && farmesh_range < 500)
2509 farmesh_range = 500;
2510 if(farmesh_range > 1000)
2511 farmesh_range = 1000;
2513 farmesh->step(dtime);
2514 farmesh->update(v2f(player_position.X, player_position.Z),
2515 brightness, farmesh_range);
2522 if(g_settings->getBool("enable_fog") == true && !force_fog_off)
2526 video::EFT_FOG_LINEAR,
2538 video::EFT_FOG_LINEAR,
2548 Update gui stuff (0ms)
2551 //TimeTaker guiupdatetimer("Gui updating");
2553 const char program_name_and_version[] =
2554 "Minetest-c55 " VERSION_STRING;
2558 static float drawtime_avg = 0;
2559 drawtime_avg = drawtime_avg * 0.95 + (float)drawtime*0.05;
2560 /*static float beginscenetime_avg = 0;
2561 beginscenetime_avg = beginscenetime_avg * 0.95 + (float)beginscenetime*0.05;
2562 static float scenetime_avg = 0;
2563 scenetime_avg = scenetime_avg * 0.95 + (float)scenetime*0.05;
2564 static float endscenetime_avg = 0;
2565 endscenetime_avg = endscenetime_avg * 0.95 + (float)endscenetime*0.05;*/
2568 snprintf(temptext, 300, "%s ("
2571 " drawtime=%.0f, dtime_jitter = % .1f %%"
2572 ", v_range = %.1f, RTT = %.3f",
2573 program_name_and_version,
2574 draw_control.range_all,
2576 dtime_jitter1_max_fraction * 100.0,
2577 draw_control.wanted_range,
2581 guitext->setText(narrow_to_wide(temptext).c_str());
2582 guitext->setVisible(true);
2584 else if(show_hud || show_chat)
2586 guitext->setText(narrow_to_wide(program_name_and_version).c_str());
2587 guitext->setVisible(true);
2591 guitext->setVisible(false);
2597 snprintf(temptext, 300,
2598 "(% .1f, % .1f, % .1f)"
2600 player_position.X/BS,
2601 player_position.Y/BS,
2602 player_position.Z/BS,
2603 wrapDegrees_0_360(camera_yaw));
2605 guitext2->setText(narrow_to_wide(temptext).c_str());
2606 guitext2->setVisible(true);
2610 guitext2->setVisible(false);
2614 guitext_info->setText(infotext.c_str());
2615 guitext_info->setVisible(show_hud && g_menumgr.menuCount() == 0);
2619 float statustext_time_max = 1.5;
2620 if(!statustext.empty())
2622 statustext_time += dtime;
2623 if(statustext_time >= statustext_time_max)
2626 statustext_time = 0;
2629 guitext_status->setText(statustext.c_str());
2630 guitext_status->setVisible(!statustext.empty());
2632 if(!statustext.empty())
2634 s32 status_y = screensize.Y - 130;
2635 core::rect<s32> rect(
2637 status_y - guitext_status->getTextHeight(),
2641 guitext_status->setRelativePosition(rect);
2644 video::SColor initial_color(255,0,0,0);
2645 if(guienv->getSkin())
2646 initial_color = guienv->getSkin()->getColor(gui::EGDC_BUTTON_TEXT);
2647 video::SColor final_color = initial_color;
2648 final_color.setAlpha(0);
2649 video::SColor fade_color =
2650 initial_color.getInterpolated_quadratic(
2653 pow(statustext_time / (float)statustext_time_max, 2.0f));
2654 guitext_status->setOverrideColor(fade_color);
2655 guitext_status->enableOverrideColor(true);
2660 Get chat messages from client
2663 // Get new messages from error log buffer
2664 while(!chat_log_error_buf.empty())
2666 chat_backend.addMessage(L"", narrow_to_wide(
2667 chat_log_error_buf.get()));
2669 // Get new messages from client
2670 std::wstring message;
2671 while(client.getChatMessage(message))
2673 chat_backend.addUnparsedMessage(message);
2675 // Remove old messages
2676 chat_backend.step(dtime);
2678 // Display all messages in a static text element
2679 u32 recent_chat_count = chat_backend.getRecentBuffer().getLineCount();
2680 std::wstring recent_chat = chat_backend.getRecentChat();
2681 guitext_chat->setText(recent_chat.c_str());
2683 // Update gui element size and position
2684 s32 chat_y = 5+(text_height+5);
2686 chat_y += (text_height+5);
2687 core::rect<s32> rect(
2691 chat_y + guitext_chat->getTextHeight()
2693 guitext_chat->setRelativePosition(rect);
2695 // Don't show chat if disabled or empty or profiler is enabled
2696 guitext_chat->setVisible(show_chat && recent_chat_count != 0
2704 if(client.getPlayerItem() != new_playeritem)
2706 client.selectPlayerItem(new_playeritem);
2708 if(client.getLocalInventoryUpdated())
2710 //infostream<<"Updating local inventory"<<std::endl;
2711 client.getLocalInventory(local_inventory);
2713 update_wielded_item_trigger = true;
2715 if(update_wielded_item_trigger)
2717 update_wielded_item_trigger = false;
2718 // Update wielded tool
2719 InventoryList *mlist = local_inventory.getList("main");
2722 item = mlist->getItem(client.getPlayerItem());
2730 TimeTaker tt_draw("mainloop: draw");
2734 TimeTaker timer("beginScene");
2735 //driver->beginScene(false, true, bgcolor);
2736 //driver->beginScene(true, true, bgcolor);
2737 driver->beginScene(true, true, skycolor);
2738 beginscenetime = timer.stop(true);
2743 //infostream<<"smgr->drawAll()"<<std::endl;
2745 TimeTaker timer("smgr");
2747 scenetime = timer.stop(true);
2751 //TimeTaker timer9("auxiliary drawings");
2755 //TimeTaker //timer10("//timer10");
2761 driver->setMaterial(m);
2763 driver->setTransform(video::ETS_WORLD, core::IdentityMatrix);
2767 for(core::list<aabb3f>::Iterator i=hilightboxes.begin();
2768 i != hilightboxes.end(); i++)
2770 /*infostream<<"hilightbox min="
2771 <<"("<<i->MinEdge.X<<","<<i->MinEdge.Y<<","<<i->MinEdge.Z<<")"
2773 <<"("<<i->MaxEdge.X<<","<<i->MaxEdge.Y<<","<<i->MaxEdge.Z<<")"
2775 driver->draw3DBox(*i, video::SColor(255,0,0,0));
2784 // Warning: This clears the Z buffer.
2785 camera.drawWieldedTool();
2792 client.getEnv().getClientMap().renderPostFx();
2798 if(show_profiler_graph)
2800 graph.draw(10, screensize.Y - 10, driver, font);
2808 driver->draw2DLine(displaycenter - core::vector2d<s32>(10,0),
2809 displaycenter + core::vector2d<s32>(10,0),
2810 video::SColor(255,255,255,255));
2811 driver->draw2DLine(displaycenter - core::vector2d<s32>(0,10),
2812 displaycenter + core::vector2d<s32>(0,10),
2813 video::SColor(255,255,255,255));
2819 //TimeTaker //timer11("//timer11");
2832 draw_hotbar(driver, font, gamedef,
2833 v2s32(displaycenter.X, screensize.Y),
2834 hotbar_imagesize, hotbar_itemcount, &local_inventory,
2835 client.getHP(), client.getPlayerItem());
2841 if(damage_flash_timer > 0.0)
2843 damage_flash_timer -= dtime;
2845 video::SColor color(128,255,0,0);
2846 driver->draw2DRectangle(color,
2847 core::rect<s32>(0,0,screensize.X,screensize.Y),
2855 TimeTaker timer("endScene");
2857 endscenetime = timer.stop(true);
2860 drawtime = tt_draw.stop(true);
2861 g_profiler->graphAdd("mainloop_draw", (float)drawtime/1000.0f);
2867 static s16 lastFPS = 0;
2868 //u16 fps = driver->getFPS();
2869 u16 fps = (1.0/dtime_avg1);
2873 core::stringw str = L"Minetest [";
2874 str += driver->getName();
2878 device->setWindowCaption(str.c_str());
2883 Log times and stuff for visualization
2885 Profiler::GraphValues values;
2886 g_profiler->graphGet(values);
2895 if(gui_chat_console)
2896 gui_chat_console->drop();
2899 Draw a "shutting down" screen, which will be shown while the map
2900 generator and other stuff quits
2903 /*gui::IGUIStaticText *gui_shuttingdowntext = */
2904 draw_load_screen(L"Shutting down stuff...", driver, font);
2905 /*driver->beginScene(true, true, video::SColor(255,0,0,0));
2908 gui_shuttingdowntext->remove();*/
2911 chat_backend.addMessage(L"", L"# Disconnected.");
2912 chat_backend.addMessage(L"", L"");
2914 // Client scope (client is destructed before destructing *def and tsrc)
2917 catch(SerializationError &e)
2919 error_message = L"A serialization error occurred:\n"
2920 + narrow_to_wide(e.what()) + L"\n\nThe server is probably "
2921 L" running a different version of Minetest.";
2922 errorstream<<wide_to_narrow(error_message)<<std::endl;