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 std::map<std::string, std::string> fields;
107 fields["text"] = ntext;
108 m_client->sendNodemetaFields(m_p, "", fields);
115 /* Respawn menu callback */
117 class MainRespawnInitiator: public IRespawnInitiator
120 MainRespawnInitiator(bool *active, Client *client):
121 m_active(active), m_client(client)
128 m_client->sendRespawn();
138 void draw_hotbar(video::IVideoDriver *driver, gui::IGUIFont *font,
140 v2s32 centerlowerpos, s32 imgsize, s32 itemcount,
141 Inventory *inventory, s32 halfheartcount, u16 playeritem)
143 InventoryList *mainlist = inventory->getList("main");
146 errorstream<<"draw_hotbar(): mainlist == NULL"<<std::endl;
150 s32 padding = imgsize/12;
151 //s32 height = imgsize + padding*2;
152 s32 width = itemcount*(imgsize+padding*2);
154 // Position of upper left corner of bar
155 v2s32 pos = centerlowerpos - v2s32(width/2, imgsize+padding*2);
157 // Draw background color
158 /*core::rect<s32> barrect(0,0,width,height);
160 video::SColor bgcolor(255,128,128,128);
161 driver->draw2DRectangle(bgcolor, barrect, NULL);*/
163 core::rect<s32> imgrect(0,0,imgsize,imgsize);
165 for(s32 i=0; i<itemcount; i++)
167 const ItemStack &item = mainlist->getItem(i);
169 core::rect<s32> rect = imgrect + pos
170 + v2s32(padding+i*(imgsize+padding*2), padding);
174 video::SColor c_outside(255,255,0,0);
175 //video::SColor c_outside(255,0,0,0);
176 //video::SColor c_inside(255,192,192,192);
177 s32 x1 = rect.UpperLeftCorner.X;
178 s32 y1 = rect.UpperLeftCorner.Y;
179 s32 x2 = rect.LowerRightCorner.X;
180 s32 y2 = rect.LowerRightCorner.Y;
181 // Black base borders
182 driver->draw2DRectangle(c_outside,
184 v2s32(x1 - padding, y1 - padding),
185 v2s32(x2 + padding, y1)
187 driver->draw2DRectangle(c_outside,
189 v2s32(x1 - padding, y2),
190 v2s32(x2 + padding, y2 + padding)
192 driver->draw2DRectangle(c_outside,
194 v2s32(x1 - padding, y1),
197 driver->draw2DRectangle(c_outside,
200 v2s32(x2 + padding, y2)
202 /*// Light inside borders
203 driver->draw2DRectangle(c_inside,
205 v2s32(x1 - padding/2, y1 - padding/2),
206 v2s32(x2 + padding/2, y1)
208 driver->draw2DRectangle(c_inside,
210 v2s32(x1 - padding/2, y2),
211 v2s32(x2 + padding/2, y2 + padding/2)
213 driver->draw2DRectangle(c_inside,
215 v2s32(x1 - padding/2, y1),
218 driver->draw2DRectangle(c_inside,
221 v2s32(x2 + padding/2, y2)
226 video::SColor bgcolor2(128,0,0,0);
227 driver->draw2DRectangle(bgcolor2, rect, NULL);
228 drawItemStack(driver, font, item, rect, NULL, gamedef);
234 video::ITexture *heart_texture =
235 gamedef->getTextureSource()->getTextureRaw("heart.png");
238 v2s32 p = pos + v2s32(0, -20);
239 for(s32 i=0; i<halfheartcount/2; i++)
241 const video::SColor color(255,255,255,255);
242 const video::SColor colors[] = {color,color,color,color};
243 core::rect<s32> rect(0,0,16,16);
245 driver->draw2DImage(heart_texture, rect,
246 core::rect<s32>(core::position2d<s32>(0,0),
247 core::dimension2di(heart_texture->getOriginalSize())),
251 if(halfheartcount % 2 == 1)
253 const video::SColor color(255,255,255,255);
254 const video::SColor colors[] = {color,color,color,color};
255 core::rect<s32> rect(0,0,16/2,16);
257 core::dimension2di srcd(heart_texture->getOriginalSize());
259 driver->draw2DImage(heart_texture, rect,
260 core::rect<s32>(core::position2d<s32>(0,0), srcd),
268 Check if a node is pointable
270 inline bool isPointableNode(const MapNode& n,
271 Client *client, bool liquids_pointable)
273 const ContentFeatures &features = client->getNodeDefManager()->get(n);
274 return features.pointable ||
275 (liquids_pointable && features.isLiquid());
279 Find what the player is pointing at
281 PointedThing getPointedThing(Client *client, v3f player_position,
282 v3f camera_direction, v3f camera_position,
283 core::line3d<f32> shootline, f32 d,
284 bool liquids_pointable,
285 bool look_for_object,
286 core::aabbox3d<f32> &hilightbox,
287 bool &should_show_hilightbox,
288 ClientActiveObject *&selected_object)
292 hilightbox = core::aabbox3d<f32>(0,0,0,0,0,0);
293 should_show_hilightbox = false;
294 selected_object = NULL;
296 INodeDefManager *nodedef = client->getNodeDefManager();
297 ClientMap &map = client->getEnv().getClientMap();
299 // First try to find a pointed at active object
302 selected_object = client->getSelectedActiveObject(d*BS,
303 camera_position, shootline);
305 if(selected_object != NULL)
307 core::aabbox3d<f32> *selection_box
308 = selected_object->getSelectionBox();
309 // Box should exist because object was returned in the
311 assert(selection_box);
313 v3f pos = selected_object->getPosition();
315 hilightbox = core::aabbox3d<f32>(
316 selection_box->MinEdge + pos,
317 selection_box->MaxEdge + pos
320 should_show_hilightbox = selected_object->doShowSelectionBox();
322 result.type = POINTEDTHING_OBJECT;
323 result.object_id = selected_object->getId();
327 // That didn't work, try to find a pointed at node
329 f32 mindistance = BS * 1001;
331 v3s16 pos_i = floatToInt(player_position, BS);
333 /*infostream<<"pos_i=("<<pos_i.X<<","<<pos_i.Y<<","<<pos_i.Z<<")"
337 s16 ystart = pos_i.Y + 0 - (camera_direction.Y<0 ? a : 1);
338 s16 zstart = pos_i.Z - (camera_direction.Z<0 ? a : 1);
339 s16 xstart = pos_i.X - (camera_direction.X<0 ? a : 1);
340 s16 yend = pos_i.Y + 1 + (camera_direction.Y>0 ? a : 1);
341 s16 zend = pos_i.Z + (camera_direction.Z>0 ? a : 1);
342 s16 xend = pos_i.X + (camera_direction.X>0 ? a : 1);
344 for(s16 y = ystart; y <= yend; y++)
345 for(s16 z = zstart; z <= zend; z++)
346 for(s16 x = xstart; x <= xend; x++)
351 n = map.getNode(v3s16(x,y,z));
353 catch(InvalidPositionException &e)
357 if(!isPointableNode(n, client, liquids_pointable))
361 v3f npf = intToFloat(np, BS);
366 v3s16(0,0,1), // back
368 v3s16(1,0,0), // right
369 v3s16(0,0,-1), // front
370 v3s16(0,-1,0), // bottom
371 v3s16(-1,0,0), // left
374 const ContentFeatures &f = nodedef->get(n);
376 if(f.selection_box.type == NODEBOX_FIXED)
378 core::aabbox3d<f32> box = f.selection_box.fixed;
382 v3s16 facedirs[6] = {
391 core::aabbox3d<f32> faceboxes[6] = {
394 box.MinEdge.X, box.MinEdge.Y, box.MinEdge.Z,
395 box.MinEdge.X+d, box.MaxEdge.Y, box.MaxEdge.Z
399 box.MaxEdge.X-d, box.MinEdge.Y, box.MinEdge.Z,
400 box.MaxEdge.X, box.MaxEdge.Y, box.MaxEdge.Z
404 box.MinEdge.X, box.MinEdge.Y, box.MinEdge.Z,
405 box.MaxEdge.X, box.MinEdge.Y+d, box.MaxEdge.Z
409 box.MinEdge.X, box.MaxEdge.Y-d, box.MinEdge.Z,
410 box.MaxEdge.X, box.MaxEdge.Y, box.MaxEdge.Z
414 box.MinEdge.X, box.MinEdge.Y, box.MinEdge.Z,
415 box.MaxEdge.X, box.MaxEdge.Y, box.MinEdge.Z+d
419 box.MinEdge.X, box.MinEdge.Y, box.MaxEdge.Z-d,
420 box.MaxEdge.X, box.MaxEdge.Y, box.MaxEdge.Z
424 for(u16 i=0; i<6; i++)
426 v3f facedir_f(facedirs[i].X, facedirs[i].Y, facedirs[i].Z);
427 v3f centerpoint = npf + facedir_f * BS/2;
428 f32 distance = (centerpoint - camera_position).getLength();
429 if(distance >= mindistance)
431 if(!faceboxes[i].intersectsWithLine(shootline))
433 result.type = POINTEDTHING_NODE;
434 result.node_undersurface = np;
435 result.node_abovesurface = np+facedirs[i];
436 mindistance = distance;
438 should_show_hilightbox = true;
441 else if(f.selection_box.type == NODEBOX_WALLMOUNTED)
443 v3s16 dir = n.getWallMountedDir(nodedef);
444 v3f dir_f = v3f(dir.X, dir.Y, dir.Z);
445 dir_f *= BS/2 - BS/6 - BS/20;
446 v3f cpf = npf + dir_f;
447 f32 distance = (cpf - camera_position).getLength();
449 core::aabbox3d<f32> box;
452 if(dir == v3s16(0,1,0)){
453 box = f.selection_box.wall_top;
456 else if(dir == v3s16(0,-1,0)){
457 box = f.selection_box.wall_bottom;
463 f.selection_box.wall_side.MinEdge,
464 f.selection_box.wall_side.MaxEdge
467 for(s32 i=0; i<2; i++)
469 if(dir == v3s16(-1,0,0))
470 vertices[i].rotateXZBy(0);
471 if(dir == v3s16(1,0,0))
472 vertices[i].rotateXZBy(180);
473 if(dir == v3s16(0,0,-1))
474 vertices[i].rotateXZBy(90);
475 if(dir == v3s16(0,0,1))
476 vertices[i].rotateXZBy(-90);
479 box = core::aabbox3d<f32>(vertices[0]);
480 box.addInternalPoint(vertices[1]);
486 if(distance < mindistance)
488 if(box.intersectsWithLine(shootline))
490 result.type = POINTEDTHING_NODE;
491 result.node_undersurface = np;
492 result.node_abovesurface = np;
493 mindistance = distance;
495 should_show_hilightbox = true;
499 else // NODEBOX_REGULAR
501 for(u16 i=0; i<6; i++)
503 v3f dir_f = v3f(dirs[i].X,
504 dirs[i].Y, dirs[i].Z);
505 v3f centerpoint = npf + dir_f * BS/2;
507 (centerpoint - camera_position).getLength();
509 if(distance < mindistance)
511 core::CMatrix4<f32> m;
512 m.buildRotateFromTo(v3f(0,0,1), dir_f);
514 // This is the back face
516 v3f(BS/2, BS/2, BS/2),
517 v3f(-BS/2, -BS/2, BS/2+d)
520 for(u16 j=0; j<2; j++)
522 m.rotateVect(corners[j]);
526 core::aabbox3d<f32> facebox(corners[0]);
527 facebox.addInternalPoint(corners[1]);
529 if(facebox.intersectsWithLine(shootline))
531 result.type = POINTEDTHING_NODE;
532 result.node_undersurface = np;
533 result.node_abovesurface = np + dirs[i];
534 mindistance = distance;
536 //hilightbox = facebox;
538 const float d = 0.502;
539 core::aabbox3d<f32> nodebox
540 (-BS*d, -BS*d, -BS*d, BS*d, BS*d, BS*d);
541 v3f nodepos_f = intToFloat(np, BS);
542 nodebox.MinEdge += nodepos_f;
543 nodebox.MaxEdge += nodepos_f;
544 hilightbox = nodebox;
545 should_show_hilightbox = true;
547 } // if distance < mindistance
556 Draws a screen with a single text on it.
557 Text will be removed when the screen is drawn the next time.
559 /*gui::IGUIStaticText **/
560 void draw_load_screen(const std::wstring &text,
561 video::IVideoDriver* driver, gui::IGUIFont* font)
563 v2u32 screensize = driver->getScreenSize();
564 const wchar_t *loadingtext = text.c_str();
565 core::vector2d<u32> textsize_u = font->getDimension(loadingtext);
566 core::vector2d<s32> textsize(textsize_u.X,textsize_u.Y);
567 core::vector2d<s32> center(screensize.X/2, screensize.Y/2);
568 core::rect<s32> textrect(center - textsize/2, center + textsize/2);
570 gui::IGUIStaticText *guitext = guienv->addStaticText(
571 loadingtext, textrect, false, false);
572 guitext->setTextAlignment(gui::EGUIA_CENTER, gui::EGUIA_UPPERLEFT);
574 driver->beginScene(true, true, video::SColor(255,0,0,0));
583 /* Profiler display */
585 void update_profiler_gui(gui::IGUIStaticText *guitext_profiler,
586 gui::IGUIFont *font, u32 text_height,
587 u32 show_profiler, u32 show_profiler_max)
589 if(show_profiler == 0)
591 guitext_profiler->setVisible(false);
596 std::ostringstream os(std::ios_base::binary);
597 g_profiler->printPage(os, show_profiler, show_profiler_max);
598 std::wstring text = narrow_to_wide(os.str());
599 guitext_profiler->setText(text.c_str());
600 guitext_profiler->setVisible(true);
602 s32 w = font->getDimension(text.c_str()).Width;
605 core::rect<s32> rect(6, 4+(text_height+5)*2, 12+w,
606 8+(text_height+5)*2 +
607 font->getDimension(text.c_str()).Height);
608 guitext_profiler->setRelativePosition(rect);
609 guitext_profiler->setVisible(true);
617 Profiler::GraphValues values;
623 Meta(float initial=0, video::SColor color=
624 video::SColor(255,255,255,255)):
630 std::list<Piece> m_log;
638 void put(const Profiler::GraphValues &values)
641 piece.values = values;
642 m_log.push_back(piece);
643 while(m_log.size() > m_log_max_size)
644 m_log.erase(m_log.begin());
647 void draw(s32 x_left, s32 y_bottom, video::IVideoDriver *driver,
648 gui::IGUIFont* font) const
650 std::map<std::string, Meta> m_meta;
651 for(std::list<Piece>::const_iterator k = m_log.begin();
652 k != m_log.end(); k++)
654 const Piece &piece = *k;
655 for(Profiler::GraphValues::const_iterator i = piece.values.begin();
656 i != piece.values.end(); i++){
657 const std::string &id = i->first;
658 const float &value = i->second;
659 std::map<std::string, Meta>::iterator j =
661 if(j == m_meta.end()){
662 m_meta[id] = Meta(value);
665 if(value < j->second.min)
666 j->second.min = value;
667 if(value > j->second.max)
668 j->second.max = value;
673 static const video::SColor usable_colors[] = {
674 video::SColor(255,255,100,100),
675 video::SColor(255,90,225,90),
676 video::SColor(255,100,100,255),
677 video::SColor(255,255,150,50),
678 video::SColor(255,220,220,100)
680 static const u32 usable_colors_count =
681 sizeof(usable_colors) / sizeof(*usable_colors);
682 u32 next_color_i = 0;
683 for(std::map<std::string, Meta>::iterator i = m_meta.begin();
684 i != m_meta.end(); i++){
685 Meta &meta = i->second;
686 video::SColor color(255,200,200,200);
687 if(next_color_i < usable_colors_count)
688 color = usable_colors[next_color_i++];
693 s32 textx = x_left + m_log_max_size + 15;
694 s32 textx2 = textx + 200 - 15;
698 u32 num_graphs = m_meta.size();
699 core::rect<s32> rect(x_left, y_bottom - num_graphs*graphh,
701 video::SColor bgcolor(120,0,0,0);
702 driver->draw2DRectangle(bgcolor, rect, NULL);
706 for(std::map<std::string, Meta>::const_iterator i = m_meta.begin();
707 i != m_meta.end(); i++){
708 const std::string &id = i->first;
709 const Meta &meta = i->second;
711 s32 y = y_bottom - meta_i * 50;
712 float show_min = meta.min;
713 float show_max = meta.max;
714 if(show_min >= -0.0001 && show_max >= -0.0001){
715 if(show_min <= show_max * 0.5)
720 snprintf(buf, 10, "%.3g", show_max);
721 font->draw(narrow_to_wide(buf).c_str(),
722 core::rect<s32>(textx, y - graphh,
723 textx2, y - graphh + texth),
725 snprintf(buf, 10, "%.3g", show_min);
726 font->draw(narrow_to_wide(buf).c_str(),
727 core::rect<s32>(textx, y - texth,
730 font->draw(narrow_to_wide(id).c_str(),
731 core::rect<s32>(textx, y - graphh/2 - texth/2,
732 textx2, y - graphh/2 + texth/2),
735 s32 graph1h = graphh;
736 bool relativegraph = (show_min != 0 && show_min != show_max);
737 float lastscaledvalue = 0.0;
738 bool lastscaledvalue_exists = false;
739 for(std::list<Piece>::const_iterator j = m_log.begin();
740 j != m_log.end(); j++)
742 const Piece &piece = *j;
744 bool value_exists = false;
745 Profiler::GraphValues::const_iterator k =
746 piece.values.find(id);
747 if(k != piece.values.end()){
753 lastscaledvalue_exists = false;
756 float scaledvalue = 1.0;
757 if(show_max != show_min)
758 scaledvalue = (value - show_min) / (show_max - show_min);
759 if(scaledvalue == 1.0 && value == 0){
761 lastscaledvalue_exists = false;
765 if(lastscaledvalue_exists){
766 s32 ivalue1 = lastscaledvalue * graph1h;
767 s32 ivalue2 = scaledvalue * graph1h;
768 driver->draw2DLine(v2s32(x-1, graph1y - ivalue1),
769 v2s32(x, graph1y - ivalue2), meta.color);
771 lastscaledvalue = scaledvalue;
772 lastscaledvalue_exists = true;
774 s32 ivalue = scaledvalue * graph1h;
775 driver->draw2DLine(v2s32(x, graph1y),
776 v2s32(x, graph1y - ivalue), meta.color);
785 class NodeDugEvent: public MtEvent
791 NodeDugEvent(v3s16 p, MapNode n):
795 const char* getType() const
801 ISoundManager *m_sound;
802 INodeDefManager *m_ndef;
804 float m_player_step_timer;
806 SimpleSoundSpec m_player_step_sound;
807 SimpleSoundSpec m_player_leftpunch_sound;
808 SimpleSoundSpec m_player_rightpunch_sound;
810 SoundMaker(ISoundManager *sound, INodeDefManager *ndef):
813 m_player_step_timer(0)
817 void playPlayerStep()
819 if(m_player_step_timer <= 0 && m_player_step_sound.exists()){
820 m_player_step_timer = 0.03;
821 m_sound->playSound(m_player_step_sound, false);
825 static void viewBobbingStep(MtEvent *e, void *data)
827 SoundMaker *sm = (SoundMaker*)data;
828 sm->playPlayerStep();
831 static void playerRegainGround(MtEvent *e, void *data)
833 SoundMaker *sm = (SoundMaker*)data;
834 sm->playPlayerStep();
837 static void playerJump(MtEvent *e, void *data)
839 //SoundMaker *sm = (SoundMaker*)data;
842 static void cameraPunchLeft(MtEvent *e, void *data)
844 SoundMaker *sm = (SoundMaker*)data;
845 sm->m_sound->playSound(sm->m_player_leftpunch_sound, false);
848 static void cameraPunchRight(MtEvent *e, void *data)
850 SoundMaker *sm = (SoundMaker*)data;
851 sm->m_sound->playSound(sm->m_player_rightpunch_sound, false);
854 static void nodeDug(MtEvent *e, void *data)
856 SoundMaker *sm = (SoundMaker*)data;
857 NodeDugEvent *nde = (NodeDugEvent*)e;
858 sm->m_sound->playSound(sm->m_ndef->get(nde->n).sound_dug, false);
861 void registerReceiver(MtEventManager *mgr)
863 mgr->reg("ViewBobbingStep", SoundMaker::viewBobbingStep, this);
864 mgr->reg("PlayerRegainGround", SoundMaker::playerRegainGround, this);
865 mgr->reg("PlayerJump", SoundMaker::playerJump, this);
866 mgr->reg("CameraPunchLeft", SoundMaker::cameraPunchLeft, this);
867 mgr->reg("CameraPunchRight", SoundMaker::cameraPunchRight, this);
868 mgr->reg("NodeDug", SoundMaker::nodeDug, this);
871 void step(float dtime)
873 m_player_step_timer -= dtime;
877 // Locally stored sounds don't need to be preloaded because of this
878 class GameOnDemandSoundFetcher: public OnDemandSoundFetcher
880 std::set<std::string> m_fetched;
883 void fetchSounds(const std::string &name,
884 std::set<std::string> &dst_paths,
885 std::set<std::string> &dst_datas)
887 if(m_fetched.count(name))
889 m_fetched.insert(name);
890 std::string base = porting::path_share + DIR_DELIM + "testsounds";
891 dst_paths.insert(base + DIR_DELIM + name + ".ogg");
892 dst_paths.insert(base + DIR_DELIM + name + ".0.ogg");
893 dst_paths.insert(base + DIR_DELIM + name + ".1.ogg");
894 dst_paths.insert(base + DIR_DELIM + name + ".2.ogg");
895 dst_paths.insert(base + DIR_DELIM + name + ".3.ogg");
896 dst_paths.insert(base + DIR_DELIM + name + ".4.ogg");
897 dst_paths.insert(base + DIR_DELIM + name + ".5.ogg");
898 dst_paths.insert(base + DIR_DELIM + name + ".6.ogg");
899 dst_paths.insert(base + DIR_DELIM + name + ".7.ogg");
900 dst_paths.insert(base + DIR_DELIM + name + ".8.ogg");
901 dst_paths.insert(base + DIR_DELIM + name + ".9.ogg");
909 IrrlichtDevice *device,
912 std::string playername,
913 std::string password,
914 std::string address, // If "", local server is used
916 std::wstring &error_message,
917 std::string configpath,
918 ChatBackend &chat_backend,
919 const SubgameSpec &gamespec, // Used for local game,
920 bool simple_singleplayer_mode
923 video::IVideoDriver* driver = device->getVideoDriver();
924 scene::ISceneManager* smgr = device->getSceneManager();
926 // Calculate text height using the font
927 u32 text_height = font->getDimension(L"Random test string").Height;
929 v2u32 screensize(0,0);
930 v2u32 last_screensize(0,0);
931 screensize = driver->getScreenSize();
933 const s32 hotbar_itemcount = 8;
934 //const s32 hotbar_imagesize = 36;
935 //const s32 hotbar_imagesize = 64;
936 s32 hotbar_imagesize = 48;
939 Draw "Loading" screen
942 draw_load_screen(L"Loading...", driver, font);
944 // Create texture source
945 IWritableTextureSource *tsrc = createTextureSource(device);
947 // These will be filled by data received from the server
948 // Create item definition manager
949 IWritableItemDefManager *itemdef = createItemDefManager();
950 // Create node definition manager
951 IWritableNodeDefManager *nodedef = createNodeDefManager();
953 // Sound fetcher (useful when testing)
954 GameOnDemandSoundFetcher soundfetcher;
957 ISoundManager *sound = NULL;
958 bool sound_is_dummy = false;
960 if(g_settings->getBool("enable_sound")){
961 infostream<<"Attempting to use OpenAL audio"<<std::endl;
962 sound = createOpenALSoundManager(&soundfetcher);
964 infostream<<"Failed to initialize OpenAL audio"<<std::endl;
966 infostream<<"Sound disabled."<<std::endl;
970 infostream<<"Using dummy audio."<<std::endl;
971 sound = &dummySoundManager;
972 sound_is_dummy = true;
976 EventManager eventmgr;
979 SoundMaker soundmaker(sound, nodedef);
980 soundmaker.registerReceiver(&eventmgr);
982 // Add chat log output for errors to be shown in chat
983 LogOutputBuffer chat_log_error_buf(LMT_ERROR);
985 // Create UI for modifying quicktune values
986 QuicktuneShortcutter quicktune;
990 SharedPtr will delete it when it goes out of scope.
992 SharedPtr<Server> server;
994 draw_load_screen(L"Creating server...", driver, font);
995 infostream<<"Creating server"<<std::endl;
996 server = new Server(map_dir, configpath, gamespec,
997 simple_singleplayer_mode);
1002 do{ // Client scope (breakable do-while(0))
1008 draw_load_screen(L"Creating client...", driver, font);
1009 infostream<<"Creating client"<<std::endl;
1011 MapDrawControl draw_control;
1013 Client client(device, playername.c_str(), password, draw_control,
1014 tsrc, itemdef, nodedef, sound, &eventmgr);
1016 // Client acts as our GameDef
1017 IGameDef *gamedef = &client;
1019 draw_load_screen(L"Resolving address...", driver, font);
1020 Address connect_address(0,0,0,0, port);
1023 //connect_address.Resolve("localhost");
1024 connect_address.setAddress(127,0,0,1);
1026 connect_address.Resolve(address.c_str());
1028 catch(ResolveError &e)
1030 error_message = L"Couldn't resolve address";
1031 errorstream<<wide_to_narrow(error_message)<<std::endl;
1032 // Break out of client scope
1037 Attempt to connect to the server
1040 infostream<<"Connecting to server at ";
1041 connect_address.print(&infostream);
1042 infostream<<std::endl;
1043 client.connect(connect_address);
1046 Wait for server to accept connection
1048 bool could_connect = false;
1049 bool connect_aborted = false;
1051 float frametime = 0.033;
1052 float time_counter = 0.0;
1054 while(device->run())
1056 // Update client and server
1057 client.step(frametime);
1059 server->step(frametime);
1062 if(client.connectedAndInitialized()){
1063 could_connect = true;
1067 if(client.accessDenied()){
1068 error_message = L"Access denied. Reason: "
1069 +client.accessDeniedReason();
1070 errorstream<<wide_to_narrow(error_message)<<std::endl;
1073 if(input->wasKeyDown(EscapeKey)){
1074 connect_aborted = true;
1075 infostream<<"Connect aborted [Escape]"<<std::endl;
1080 std::wostringstream ss;
1081 ss<<L"Connecting to server... (press Escape to cancel)\n";
1082 std::wstring animation = L"/-\\|";
1083 ss<<animation[(int)(time_counter/0.2)%4];
1084 draw_load_screen(ss.str(), driver, font);
1087 sleep_ms(1000*frametime);
1088 time_counter += frametime;
1091 catch(con::PeerNotFoundException &e)
1095 Handle failure to connect
1098 if(error_message == L"" && !connect_aborted){
1099 error_message = L"Connection failed";
1100 errorstream<<wide_to_narrow(error_message)<<std::endl;
1102 // Break out of client scope
1107 Wait until content has been received
1109 bool got_content = false;
1110 bool content_aborted = false;
1112 float frametime = 0.033;
1113 float time_counter = 0.0;
1115 while(device->run())
1117 // Update client and server
1118 client.step(frametime);
1120 server->step(frametime);
1123 if(client.texturesReceived() &&
1124 client.itemdefReceived() &&
1125 client.nodedefReceived()){
1130 if(!client.connectedAndInitialized()){
1131 error_message = L"Client disconnected";
1132 errorstream<<wide_to_narrow(error_message)<<std::endl;
1135 if(input->wasKeyDown(EscapeKey)){
1136 content_aborted = true;
1137 infostream<<"Connect aborted [Escape]"<<std::endl;
1142 std::wostringstream ss;
1143 ss<<L"Waiting content... (press Escape to cancel)\n";
1145 ss<<(client.itemdefReceived()?L"[X]":L"[ ]");
1146 ss<<L" Item definitions\n";
1147 ss<<(client.nodedefReceived()?L"[X]":L"[ ]");
1148 ss<<L" Node definitions\n";
1149 ss<<L"["<<(int)(client.mediaReceiveProgress()*100+0.5)<<L"%] ";
1152 draw_load_screen(ss.str(), driver, font);
1155 sleep_ms(1000*frametime);
1156 time_counter += frametime;
1161 if(error_message == L"" && !content_aborted){
1162 error_message = L"Something failed";
1163 errorstream<<wide_to_narrow(error_message)<<std::endl;
1165 // Break out of client scope
1170 After all content has been received:
1171 Update cached textures, meshes and materials
1173 client.afterContentReceived();
1176 Create the camera node
1178 Camera camera(smgr, draw_control, gamedef);
1179 if (!camera.successfullyCreated(error_message))
1182 f32 camera_yaw = 0; // "right/left"
1183 f32 camera_pitch = 0; // "up/down"
1189 Clouds *clouds = NULL;
1190 if(g_settings->getBool("enable_clouds"))
1192 clouds = new Clouds(smgr->getRootSceneNode(), smgr, -1, time(0));
1200 sky = new Sky(smgr->getRootSceneNode(), smgr, -1);
1206 FarMesh *farmesh = NULL;
1207 if(g_settings->getBool("enable_farmesh"))
1209 farmesh = new FarMesh(smgr->getRootSceneNode(), smgr, -1, client.getMapSeed(), &client);
1213 A copy of the local inventory
1215 Inventory local_inventory(itemdef);
1221 // First line of debug text
1222 gui::IGUIStaticText *guitext = guienv->addStaticText(
1224 core::rect<s32>(5, 5, 795, 5+text_height),
1226 // Second line of debug text
1227 gui::IGUIStaticText *guitext2 = guienv->addStaticText(
1229 core::rect<s32>(5, 5+(text_height+5)*1, 795, (5+text_height)*2),
1231 // At the middle of the screen
1232 // Object infos are shown in this
1233 gui::IGUIStaticText *guitext_info = guienv->addStaticText(
1235 core::rect<s32>(0,0,400,text_height*5+5) + v2s32(100,200),
1238 // Status text (displays info when showing and hiding GUI stuff, etc.)
1239 gui::IGUIStaticText *guitext_status = guienv->addStaticText(
1241 core::rect<s32>(0,0,0,0),
1243 guitext_status->setVisible(false);
1245 std::wstring statustext;
1246 float statustext_time = 0;
1249 gui::IGUIStaticText *guitext_chat = guienv->addStaticText(
1251 core::rect<s32>(0,0,0,0),
1252 //false, false); // Disable word wrap as of now
1254 // Remove stale "recent" chat messages from previous connections
1255 chat_backend.clearRecentChat();
1256 // Chat backend and console
1257 GUIChatConsole *gui_chat_console = new GUIChatConsole(guienv, guienv->getRootGUIElement(), -1, &chat_backend, &client);
1259 // Profiler text (size is updated when text is updated)
1260 gui::IGUIStaticText *guitext_profiler = guienv->addStaticText(
1262 core::rect<s32>(0,0,0,0),
1264 guitext_profiler->setBackgroundColor(video::SColor(120,0,0,0));
1265 guitext_profiler->setVisible(false);
1268 Some statistics are collected in these
1271 u32 beginscenetime = 0;
1273 u32 endscenetime = 0;
1275 float recent_turn_speed = 0.0;
1277 ProfilerGraph graph;
1278 // Initially clear the profiler
1279 Profiler::GraphValues dummyvalues;
1280 g_profiler->graphGet(dummyvalues);
1282 float nodig_delay_timer = 0.0;
1283 float dig_time = 0.0;
1285 PointedThing pointed_old;
1286 bool digging = false;
1287 bool ldown_for_dig = false;
1289 float damage_flash_timer = 0;
1290 s16 farmesh_range = 20*MAP_BLOCKSIZE;
1292 const float object_hit_delay = 0.2;
1293 float object_hit_delay_timer = 0.0;
1294 float time_from_last_punch = 10;
1296 bool invert_mouse = g_settings->getBool("invert_mouse");
1298 bool respawn_menu_active = false;
1299 bool update_wielded_item_trigger = false;
1301 bool show_hud = true;
1302 bool show_chat = true;
1303 bool force_fog_off = false;
1304 bool disable_camera_update = false;
1305 bool show_debug = g_settings->getBool("show_debug");
1306 bool show_profiler_graph = false;
1307 u32 show_profiler = 0;
1308 u32 show_profiler_max = 3; // Number of pages
1310 float time_of_day = 0;
1311 float time_of_day_smooth = 0;
1317 bool first_loop_after_window_activation = true;
1319 // TODO: Convert the static interval timers to these
1320 // Interval limiter for profiler
1321 IntervalLimiter m_profiler_interval;
1323 // Time is in milliseconds
1324 // NOTE: getRealTime() causes strange problems in wine (imprecision?)
1325 // NOTE: So we have to use getTime() and call run()s between them
1326 u32 lasttime = device->getTimer()->getTime();
1330 if(device->run() == false || kill == true)
1333 // Time of frame without fps limit
1337 // not using getRealTime is necessary for wine
1338 u32 time = device->getTimer()->getTime();
1340 busytime_u32 = time - lasttime;
1343 busytime = busytime_u32 / 1000.0;
1346 g_profiler->graphAdd("mainloop_other", busytime - (float)drawtime/1000.0f);
1348 // Necessary for device->getTimer()->getTime()
1356 float fps_max = g_settings->getFloat("fps_max");
1357 u32 frametime_min = 1000./fps_max;
1359 if(busytime_u32 < frametime_min)
1361 u32 sleeptime = frametime_min - busytime_u32;
1362 device->sleep(sleeptime);
1363 g_profiler->graphAdd("mainloop_sleep", (float)sleeptime/1000.0f);
1367 // Necessary for device->getTimer()->getTime()
1371 Time difference calculation
1373 f32 dtime; // in seconds
1375 u32 time = device->getTimer()->getTime();
1377 dtime = (time - lasttime) / 1000.0;
1382 g_profiler->graphAdd("mainloop_dtime", dtime);
1386 if(nodig_delay_timer >= 0)
1387 nodig_delay_timer -= dtime;
1388 if(object_hit_delay_timer >= 0)
1389 object_hit_delay_timer -= dtime;
1390 time_from_last_punch += dtime;
1392 g_profiler->add("Elapsed time", dtime);
1393 g_profiler->avg("FPS", 1./dtime);
1396 Time average and jitter calculation
1399 static f32 dtime_avg1 = 0.0;
1400 dtime_avg1 = dtime_avg1 * 0.96 + dtime * 0.04;
1401 f32 dtime_jitter1 = dtime - dtime_avg1;
1403 static f32 dtime_jitter1_max_sample = 0.0;
1404 static f32 dtime_jitter1_max_fraction = 0.0;
1406 static f32 jitter1_max = 0.0;
1407 static f32 counter = 0.0;
1408 if(dtime_jitter1 > jitter1_max)
1409 jitter1_max = dtime_jitter1;
1414 dtime_jitter1_max_sample = jitter1_max;
1415 dtime_jitter1_max_fraction
1416 = dtime_jitter1_max_sample / (dtime_avg1+0.001);
1422 Busytime average and jitter calculation
1425 static f32 busytime_avg1 = 0.0;
1426 busytime_avg1 = busytime_avg1 * 0.98 + busytime * 0.02;
1427 f32 busytime_jitter1 = busytime - busytime_avg1;
1429 static f32 busytime_jitter1_max_sample = 0.0;
1430 static f32 busytime_jitter1_min_sample = 0.0;
1432 static f32 jitter1_max = 0.0;
1433 static f32 jitter1_min = 0.0;
1434 static f32 counter = 0.0;
1435 if(busytime_jitter1 > jitter1_max)
1436 jitter1_max = busytime_jitter1;
1437 if(busytime_jitter1 < jitter1_min)
1438 jitter1_min = busytime_jitter1;
1442 busytime_jitter1_max_sample = jitter1_max;
1443 busytime_jitter1_min_sample = jitter1_min;
1450 Handle miscellaneous stuff
1453 if(client.accessDenied())
1455 error_message = L"Access denied. Reason: "
1456 +client.accessDeniedReason();
1457 errorstream<<wide_to_narrow(error_message)<<std::endl;
1461 if(g_gamecallback->disconnect_requested)
1463 g_gamecallback->disconnect_requested = false;
1467 if(g_gamecallback->changepassword_requested)
1469 (new GUIPasswordChange(guienv, guiroot, -1,
1470 &g_menumgr, &client))->drop();
1471 g_gamecallback->changepassword_requested = false;
1475 Process TextureSource's queue
1477 tsrc->processQueue();
1482 last_screensize = screensize;
1483 screensize = driver->getScreenSize();
1484 v2s32 displaycenter(screensize.X/2,screensize.Y/2);
1485 //bool screensize_changed = screensize != last_screensize;
1488 if(screensize.Y <= 800)
1489 hotbar_imagesize = 32;
1490 else if(screensize.Y <= 1280)
1491 hotbar_imagesize = 48;
1493 hotbar_imagesize = 64;
1495 // Hilight boxes collected during the loop and displayed
1496 core::list< core::aabbox3d<f32> > hilightboxes;
1499 std::wstring infotext;
1502 Debug info for client
1505 static float counter = 0.0;
1510 client.printDebugInfo(infostream);
1517 float profiler_print_interval =
1518 g_settings->getFloat("profiler_print_interval");
1519 bool print_to_log = true;
1520 if(profiler_print_interval == 0){
1521 print_to_log = false;
1522 profiler_print_interval = 5;
1524 if(m_profiler_interval.step(dtime, profiler_print_interval))
1527 infostream<<"Profiler:"<<std::endl;
1528 g_profiler->print(infostream);
1531 update_profiler_gui(guitext_profiler, font, text_height,
1532 show_profiler, show_profiler_max);
1534 g_profiler->clear();
1538 Direct handling of user input
1541 // Reset input if window not active or some menu is active
1542 if(device->isWindowActive() == false
1543 || noMenuActive() == false
1544 || guienv->hasFocus(gui_chat_console))
1549 // Input handler step() (used by the random input generator)
1553 Launch menus and trigger stuff according to keys
1555 if(input->wasKeyDown(getKeySetting("keymap_drop")))
1557 // drop selected item
1558 IDropAction *a = new IDropAction();
1560 a->from_inv.setCurrentPlayer();
1561 a->from_list = "main";
1562 a->from_i = client.getPlayerItem();
1563 client.inventoryAction(a);
1565 else if(input->wasKeyDown(getKeySetting("keymap_inventory")))
1567 infostream<<"the_game: "
1568 <<"Launching inventory"<<std::endl;
1570 GUIInventoryMenu *menu =
1571 new GUIInventoryMenu(guienv, guiroot, -1,
1575 InventoryLocation inventoryloc;
1576 inventoryloc.setCurrentPlayer();
1580 "list[current_player;main;0,3;8,4;]"
1581 "list[current_player;craft;3,0;3,3;]"
1582 "list[current_player;craftpreview;7,1;1,1;]"
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;
1639 if(!client.checkPrivilege("fly"))
1640 statustext += L" (note: no 'fly' privilege)";
1643 else if(input->wasKeyDown(getKeySetting("keymap_fastmove")))
1645 if(g_settings->getBool("fast_move"))
1647 g_settings->set("fast_move","false");
1648 statustext = L"fast_move disabled";
1649 statustext_time = 0;
1653 g_settings->set("fast_move","true");
1654 statustext = L"fast_move enabled";
1655 statustext_time = 0;
1656 if(!client.checkPrivilege("fast"))
1657 statustext += L" (note: no 'fast' privilege)";
1660 else if(input->wasKeyDown(getKeySetting("keymap_screenshot")))
1662 irr::video::IImage* const image = driver->createScreenShot();
1664 irr::c8 filename[256];
1665 snprintf(filename, 256, "%s" DIR_DELIM "screenshot_%u.png",
1666 g_settings->get("screenshot_path").c_str(),
1667 device->getTimer()->getRealTime());
1668 if (driver->writeImageToFile(image, filename)) {
1669 std::wstringstream sstr;
1670 sstr<<"Saved screenshot to '"<<filename<<"'";
1671 infostream<<"Saved screenshot to '"<<filename<<"'"<<std::endl;
1672 statustext = sstr.str();
1673 statustext_time = 0;
1675 infostream<<"Failed to save screenshot '"<<filename<<"'"<<std::endl;
1680 else if(input->wasKeyDown(getKeySetting("keymap_toggle_hud")))
1682 show_hud = !show_hud;
1684 statustext = L"HUD shown";
1686 statustext = L"HUD hidden";
1687 statustext_time = 0;
1689 else if(input->wasKeyDown(getKeySetting("keymap_toggle_chat")))
1691 show_chat = !show_chat;
1693 statustext = L"Chat shown";
1695 statustext = L"Chat hidden";
1696 statustext_time = 0;
1698 else if(input->wasKeyDown(getKeySetting("keymap_toggle_force_fog_off")))
1700 force_fog_off = !force_fog_off;
1702 statustext = L"Fog disabled";
1704 statustext = L"Fog enabled";
1705 statustext_time = 0;
1707 else if(input->wasKeyDown(getKeySetting("keymap_toggle_update_camera")))
1709 disable_camera_update = !disable_camera_update;
1710 if(disable_camera_update)
1711 statustext = L"Camera update disabled";
1713 statustext = L"Camera update enabled";
1714 statustext_time = 0;
1716 else if(input->wasKeyDown(getKeySetting("keymap_toggle_debug")))
1718 // Initial / 3x toggle: Chat only
1719 // 1x toggle: Debug text with chat
1720 // 2x toggle: Debug text with profiler graph
1724 show_profiler_graph = false;
1725 statustext = L"Debug info shown";
1726 statustext_time = 0;
1728 else if(show_profiler_graph)
1731 show_profiler_graph = false;
1732 statustext = L"Debug info and profiler graph hidden";
1733 statustext_time = 0;
1737 show_profiler_graph = true;
1738 statustext = L"Profiler graph shown";
1739 statustext_time = 0;
1742 else if(input->wasKeyDown(getKeySetting("keymap_toggle_profiler")))
1744 show_profiler = (show_profiler + 1) % (show_profiler_max + 1);
1746 // FIXME: This updates the profiler with incomplete values
1747 update_profiler_gui(guitext_profiler, font, text_height,
1748 show_profiler, show_profiler_max);
1750 if(show_profiler != 0)
1752 std::wstringstream sstr;
1753 sstr<<"Profiler shown (page "<<show_profiler
1754 <<" of "<<show_profiler_max<<")";
1755 statustext = sstr.str();
1756 statustext_time = 0;
1760 statustext = L"Profiler hidden";
1761 statustext_time = 0;
1764 else if(input->wasKeyDown(getKeySetting("keymap_increase_viewing_range_min")))
1766 s16 range = g_settings->getS16("viewing_range_nodes_min");
1767 s16 range_new = range + 10;
1768 g_settings->set("viewing_range_nodes_min", itos(range_new));
1769 statustext = narrow_to_wide(
1770 "Minimum viewing range changed to "
1772 statustext_time = 0;
1774 else if(input->wasKeyDown(getKeySetting("keymap_decrease_viewing_range_min")))
1776 s16 range = g_settings->getS16("viewing_range_nodes_min");
1777 s16 range_new = range - 10;
1780 g_settings->set("viewing_range_nodes_min",
1782 statustext = narrow_to_wide(
1783 "Minimum viewing range changed to "
1785 statustext_time = 0;
1788 // Handle QuicktuneShortcutter
1789 if(input->wasKeyDown(getKeySetting("keymap_quicktune_next")))
1791 if(input->wasKeyDown(getKeySetting("keymap_quicktune_prev")))
1793 if(input->wasKeyDown(getKeySetting("keymap_quicktune_inc")))
1795 if(input->wasKeyDown(getKeySetting("keymap_quicktune_dec")))
1798 std::string msg = quicktune.getMessage();
1800 statustext = narrow_to_wide(msg);
1801 statustext_time = 0;
1805 // Item selection with mouse wheel
1806 u16 new_playeritem = client.getPlayerItem();
1808 s32 wheel = input->getMouseWheel();
1809 u16 max_item = MYMIN(PLAYER_INVENTORY_SIZE-1,
1810 hotbar_itemcount-1);
1814 if(new_playeritem < max_item)
1821 if(new_playeritem > 0)
1824 new_playeritem = max_item;
1829 for(u16 i=0; i<10; i++)
1831 const KeyPress *kp = NumberKey + (i + 1) % 10;
1832 if(input->wasKeyDown(*kp))
1834 if(i < PLAYER_INVENTORY_SIZE && i < hotbar_itemcount)
1838 infostream<<"Selected item: "
1839 <<new_playeritem<<std::endl;
1844 // Viewing range selection
1845 if(input->wasKeyDown(getKeySetting("keymap_rangeselect")))
1847 draw_control.range_all = !draw_control.range_all;
1848 if(draw_control.range_all)
1850 infostream<<"Enabled full viewing range"<<std::endl;
1851 statustext = L"Enabled full viewing range";
1852 statustext_time = 0;
1856 infostream<<"Disabled full viewing range"<<std::endl;
1857 statustext = L"Disabled full viewing range";
1858 statustext_time = 0;
1862 // Print debug stacks
1863 if(input->wasKeyDown(getKeySetting("keymap_print_debug_stacks")))
1865 dstream<<"-----------------------------------------"
1867 dstream<<DTIME<<"Printing debug stacks:"<<std::endl;
1868 dstream<<"-----------------------------------------"
1870 debug_stacks_print();
1874 Mouse and camera control
1875 NOTE: Do this before client.setPlayerControl() to not cause a camera lag of one frame
1878 float turn_amount = 0;
1879 if((device->isWindowActive() && noMenuActive()) || random_input)
1883 // Mac OSX gets upset if this is set every frame
1884 if(device->getCursorControl()->isVisible())
1885 device->getCursorControl()->setVisible(false);
1888 if(first_loop_after_window_activation){
1889 //infostream<<"window active, first loop"<<std::endl;
1890 first_loop_after_window_activation = false;
1893 s32 dx = input->getMousePos().X - displaycenter.X;
1894 s32 dy = input->getMousePos().Y - displaycenter.Y;
1897 //infostream<<"window active, pos difference "<<dx<<","<<dy<<std::endl;
1899 /*const float keyspeed = 500;
1900 if(input->isKeyDown(irr::KEY_UP))
1901 dy -= dtime * keyspeed;
1902 if(input->isKeyDown(irr::KEY_DOWN))
1903 dy += dtime * keyspeed;
1904 if(input->isKeyDown(irr::KEY_LEFT))
1905 dx -= dtime * keyspeed;
1906 if(input->isKeyDown(irr::KEY_RIGHT))
1907 dx += dtime * keyspeed;*/
1911 camera_pitch += dy*d;
1912 if(camera_pitch < -89.5) camera_pitch = -89.5;
1913 if(camera_pitch > 89.5) camera_pitch = 89.5;
1915 turn_amount = v2f(dx, dy).getLength() * d;
1917 input->setMousePos(displaycenter.X, displaycenter.Y);
1920 // Mac OSX gets upset if this is set every frame
1921 if(device->getCursorControl()->isVisible() == false)
1922 device->getCursorControl()->setVisible(true);
1924 //infostream<<"window inactive"<<std::endl;
1925 first_loop_after_window_activation = true;
1927 recent_turn_speed = recent_turn_speed * 0.9 + turn_amount * 0.1;
1928 //std::cerr<<"recent_turn_speed = "<<recent_turn_speed<<std::endl;
1931 Player speed control
1943 PlayerControl control(
1944 input->isKeyDown(getKeySetting("keymap_forward")),
1945 input->isKeyDown(getKeySetting("keymap_backward")),
1946 input->isKeyDown(getKeySetting("keymap_left")),
1947 input->isKeyDown(getKeySetting("keymap_right")),
1948 input->isKeyDown(getKeySetting("keymap_jump")),
1949 input->isKeyDown(getKeySetting("keymap_special1")),
1950 input->isKeyDown(getKeySetting("keymap_sneak")),
1954 client.setPlayerControl(control);
1963 //TimeTaker timer("server->step(dtime)");
1964 server->step(dtime);
1972 //TimeTaker timer("client.step(dtime)");
1974 //client.step(dtime_avg1);
1978 // Read client events
1981 ClientEvent event = client.getClientEvent();
1982 if(event.type == CE_NONE)
1986 else if(event.type == CE_PLAYER_DAMAGE)
1988 //u16 damage = event.player_damage.amount;
1989 //infostream<<"Player damage: "<<damage<<std::endl;
1990 damage_flash_timer = 0.05;
1991 if(event.player_damage.amount >= 2){
1992 damage_flash_timer += 0.05 * event.player_damage.amount;
1995 else if(event.type == CE_PLAYER_FORCE_MOVE)
1997 camera_yaw = event.player_force_move.yaw;
1998 camera_pitch = event.player_force_move.pitch;
2000 else if(event.type == CE_DEATHSCREEN)
2002 if(respawn_menu_active)
2005 /*bool set_camera_point_target =
2006 event.deathscreen.set_camera_point_target;
2007 v3f camera_point_target;
2008 camera_point_target.X = event.deathscreen.camera_point_target_x;
2009 camera_point_target.Y = event.deathscreen.camera_point_target_y;
2010 camera_point_target.Z = event.deathscreen.camera_point_target_z;*/
2011 MainRespawnInitiator *respawner =
2012 new MainRespawnInitiator(
2013 &respawn_menu_active, &client);
2014 GUIDeathScreen *menu =
2015 new GUIDeathScreen(guienv, guiroot, -1,
2016 &g_menumgr, respawner);
2019 chat_backend.addMessage(L"", L"You died.");
2021 /* Handle visualization */
2023 damage_flash_timer = 0;
2025 /*LocalPlayer* player = client.getLocalPlayer();
2026 player->setPosition(player->getPosition() + v3f(0,-BS,0));
2027 camera.update(player, busytime, screensize);*/
2029 else if(event.type == CE_TEXTURES_UPDATED)
2031 update_wielded_item_trigger = true;
2036 //TimeTaker //timer2("//timer2");
2039 For interaction purposes, get info about the held item
2041 - Is it a usable item?
2042 - Can it point to liquids?
2044 ItemStack playeritem;
2045 bool playeritem_usable = false;
2046 bool playeritem_liquids_pointable = false;
2048 InventoryList *mlist = local_inventory.getList("main");
2051 playeritem = mlist->getItem(client.getPlayerItem());
2052 playeritem_usable = playeritem.getDefinition(itemdef).usable;
2053 playeritem_liquids_pointable = playeritem.getDefinition(itemdef).liquids_pointable;
2056 ToolCapabilities playeritem_toolcap =
2057 playeritem.getToolCapabilities(itemdef);
2063 LocalPlayer* player = client.getEnv().getLocalPlayer();
2064 float full_punch_interval = playeritem_toolcap.full_punch_interval;
2065 float tool_reload_ratio = time_from_last_punch / full_punch_interval;
2066 tool_reload_ratio = MYMIN(tool_reload_ratio, 1.0);
2067 camera.update(player, busytime, screensize, tool_reload_ratio);
2070 v3f player_position = player->getPosition();
2071 v3f camera_position = camera.getPosition();
2072 v3f camera_direction = camera.getDirection();
2073 f32 camera_fov = camera.getFovMax();
2075 if(!disable_camera_update){
2076 client.getEnv().getClientMap().updateCamera(camera_position,
2077 camera_direction, camera_fov);
2080 // Update sound listener
2081 sound->updateListener(camera.getCameraNode()->getPosition(),
2082 v3f(0,0,0), // velocity
2083 camera.getDirection(),
2084 camera.getCameraNode()->getUpVector());
2085 sound->setListenerGain(g_settings->getFloat("sound_volume"));
2091 soundmaker.step(dtime);
2093 ClientMap &map = client.getEnv().getClientMap();
2094 MapNode n = map.getNodeNoEx(player->getStandingNodePos());
2095 soundmaker.m_player_step_sound = nodedef->get(n).sound_footstep;
2099 Calculate what block is the crosshair pointing to
2102 //u32 t1 = device->getTimer()->getRealTime();
2104 f32 d = 4; // max. distance
2105 core::line3d<f32> shootline(camera_position,
2106 camera_position + camera_direction * BS * (d+1));
2108 core::aabbox3d<f32> hilightbox;
2109 bool should_show_hilightbox = false;
2110 ClientActiveObject *selected_object = NULL;
2112 PointedThing pointed = getPointedThing(
2114 &client, player_position, camera_direction,
2115 camera_position, shootline, d,
2116 playeritem_liquids_pointable, !ldown_for_dig,
2118 hilightbox, should_show_hilightbox,
2121 if(pointed != pointed_old)
2123 infostream<<"Pointing at "<<pointed.dump()<<std::endl;
2124 //dstream<<"Pointing at "<<pointed.dump()<<std::endl;
2130 if(should_show_hilightbox)
2131 hilightboxes.push_back(hilightbox);
2135 - releasing left mouse button
2136 - pointing away from node
2140 if(input->getLeftReleased())
2142 infostream<<"Left button released"
2143 <<" (stopped digging)"<<std::endl;
2146 else if(pointed != pointed_old)
2148 if (pointed.type == POINTEDTHING_NODE
2149 && pointed_old.type == POINTEDTHING_NODE
2150 && pointed.node_undersurface == pointed_old.node_undersurface)
2152 // Still pointing to the same node,
2153 // but a different face. Don't reset.
2157 infostream<<"Pointing away from node"
2158 <<" (stopped digging)"<<std::endl;
2164 client.interact(1, pointed_old);
2165 client.setCrack(-1, v3s16(0,0,0));
2169 if(!digging && ldown_for_dig && !input->getLeftState())
2171 ldown_for_dig = false;
2174 bool left_punch = false;
2175 soundmaker.m_player_leftpunch_sound.name = "";
2177 if(playeritem_usable && input->getLeftState())
2179 if(input->getLeftClicked())
2180 client.interact(4, pointed);
2182 else if(pointed.type == POINTEDTHING_NODE)
2184 v3s16 nodepos = pointed.node_undersurface;
2185 v3s16 neighbourpos = pointed.node_abovesurface;
2188 Check information text of node
2191 ClientMap &map = client.getEnv().getClientMap();
2192 NodeMetadata *meta = map.getNodeMetadata(nodepos);
2194 infotext = narrow_to_wide(meta->getString("infotext"));
2196 MapNode n = map.getNode(nodepos);
2197 if(nodedef->get(n).tname_tiles[0] == "unknown_block.png"){
2198 infotext = L"Unknown node: ";
2199 infotext += narrow_to_wide(nodedef->get(n).name);
2203 // We can't actually know, but assume the sound of right-clicking
2204 // to be the sound of placing a node
2205 soundmaker.m_player_rightpunch_sound.gain = 0.5;
2206 soundmaker.m_player_rightpunch_sound.name = "default_place_node";
2212 if(nodig_delay_timer <= 0.0 && input->getLeftState())
2216 infostream<<"Started digging"<<std::endl;
2217 client.interact(0, pointed);
2219 ldown_for_dig = true;
2221 MapNode n = client.getEnv().getClientMap().getNode(nodepos);
2223 // Get digging parameters
2224 DigParams params = getDigParams(nodedef->get(n).groups,
2225 &playeritem_toolcap);
2226 // If can't dig, try hand
2227 if(!params.diggable){
2228 const ItemDefinition &hand = itemdef->get("");
2229 const ToolCapabilities *tp = hand.tool_capabilities;
2231 params = getDigParams(nodedef->get(n).groups, tp);
2234 SimpleSoundSpec sound_dig = nodedef->get(n).sound_dig;
2235 if(sound_dig.exists()){
2236 if(sound_dig.name == "__group"){
2237 if(params.main_group != ""){
2238 soundmaker.m_player_leftpunch_sound.gain = 0.5;
2239 soundmaker.m_player_leftpunch_sound.name =
2240 std::string("default_dig_") +
2244 soundmaker.m_player_leftpunch_sound = sound_dig;
2248 float dig_time_complete = 0.0;
2250 if(params.diggable == false)
2252 // I guess nobody will wait for this long
2253 dig_time_complete = 10000000.0;
2257 dig_time_complete = params.time;
2260 if(dig_time_complete >= 0.001)
2262 dig_index = (u16)((float)CRACK_ANIMATION_LENGTH
2263 * dig_time/dig_time_complete);
2265 // This is for torches
2268 dig_index = CRACK_ANIMATION_LENGTH;
2271 // Don't show cracks if not diggable
2272 if(dig_time_complete >= 100000.0)
2275 else if(dig_index < CRACK_ANIMATION_LENGTH)
2277 //TimeTaker timer("client.setTempMod");
2278 //infostream<<"dig_index="<<dig_index<<std::endl;
2279 client.setCrack(dig_index, nodepos);
2283 infostream<<"Digging completed"<<std::endl;
2284 client.interact(2, pointed);
2285 client.setCrack(-1, v3s16(0,0,0));
2286 MapNode wasnode = map.getNode(nodepos);
2287 client.removeNode(nodepos);
2292 nodig_delay_timer = dig_time_complete
2293 / (float)CRACK_ANIMATION_LENGTH;
2295 // We don't want a corresponding delay to
2296 // very time consuming nodes
2297 if(nodig_delay_timer > 0.3)
2298 nodig_delay_timer = 0.3;
2299 // We want a slight delay to very little
2300 // time consuming nodes
2301 float mindelay = 0.15;
2302 if(nodig_delay_timer < mindelay)
2303 nodig_delay_timer = mindelay;
2305 // Send event to trigger sound
2306 MtEvent *e = new NodeDugEvent(nodepos, wasnode);
2307 gamedef->event()->put(e);
2312 camera.setDigging(0); // left click animation
2315 if(input->getRightClicked())
2317 infostream<<"Ground right-clicked"<<std::endl;
2319 // sign special case, at least until formspec is properly implemented
2320 if(meta && meta->getString("formspec") == "hack:sign_text_input" && !random_input)
2322 infostream<<"Launching metadata text input"<<std::endl;
2324 // Get a new text for it
2326 TextDest *dest = new TextDestNodeMetadata(nodepos, &client);
2328 std::wstring wtext = narrow_to_wide(meta->getString("text"));
2330 (new GUITextInputMenu(guienv, guiroot, -1,
2334 // If metadata provides an inventory view, activate it
2335 else if(meta && meta->getString("formspec") != "" && !random_input)
2337 infostream<<"Launching custom inventory view"<<std::endl;
2339 InventoryLocation inventoryloc;
2340 inventoryloc.setNodeMeta(nodepos);
2344 GUIInventoryMenu *menu =
2345 new GUIInventoryMenu(guienv, guiroot, -1,
2348 menu->setFormSpec(meta->getString("formspec"),
2352 // Otherwise report right click to server
2355 client.interact(3, pointed);
2356 camera.setDigging(1); // right click animation
2360 else if(pointed.type == POINTEDTHING_OBJECT)
2362 infotext = narrow_to_wide(selected_object->infoText());
2364 if(infotext == L"" && show_debug){
2365 infotext = narrow_to_wide(selected_object->debugInfoText());
2368 //if(input->getLeftClicked())
2369 if(input->getLeftState())
2371 bool do_punch = false;
2372 bool do_punch_damage = false;
2373 if(object_hit_delay_timer <= 0.0){
2375 do_punch_damage = true;
2376 object_hit_delay_timer = object_hit_delay;
2378 if(input->getLeftClicked()){
2382 infostream<<"Left-clicked object"<<std::endl;
2385 if(do_punch_damage){
2386 // Report direct punch
2387 v3f objpos = selected_object->getPosition();
2388 v3f dir = (objpos - player_position).normalize();
2390 bool disable_send = selected_object->directReportPunch(
2391 dir, &playeritem, time_from_last_punch);
2392 time_from_last_punch = 0;
2394 client.interact(0, pointed);
2397 else if(input->getRightClicked())
2399 infostream<<"Right-clicked object"<<std::endl;
2400 client.interact(3, pointed); // place
2403 else if(input->getLeftState())
2405 // When button is held down in air, show continuous animation
2409 pointed_old = pointed;
2411 if(left_punch || input->getLeftClicked())
2413 camera.setDigging(0); // left click animation
2416 input->resetLeftClicked();
2417 input->resetRightClicked();
2419 input->resetLeftReleased();
2420 input->resetRightReleased();
2423 Calculate stuff for drawing
2433 fog_range = BS*farmesh_range;
2437 fog_range = draw_control.wanted_range*BS + 0.0*MAP_BLOCKSIZE*BS;
2439 if(draw_control.range_all)
2440 fog_range = 100000*BS;
2444 Calculate general brightness
2446 u32 daynight_ratio = client.getEnv().getDayNightRatio();
2447 float time_brightness = (float)decode_light(
2448 (daynight_ratio * LIGHT_SUN) / 1000) / 255.0;
2449 float direct_brightness = 0;
2450 bool sunlight_seen = false;
2451 if(g_settings->getBool("free_move")){
2452 direct_brightness = time_brightness;
2453 sunlight_seen = true;
2455 ScopeProfiler sp(g_profiler, "Detecting background light", SPT_AVG);
2456 float old_brightness = sky->getBrightness();
2457 direct_brightness = (float)client.getEnv().getClientMap()
2458 .getBackgroundBrightness(MYMIN(fog_range*1.2, 60*BS),
2459 daynight_ratio, (int)(old_brightness*255.5), &sunlight_seen)
2463 time_of_day = client.getEnv().getTimeOfDayF();
2465 if(fabs(time_of_day - time_of_day_smooth) > maxsm &&
2466 fabs(time_of_day - time_of_day_smooth + 1.0) > maxsm &&
2467 fabs(time_of_day - time_of_day_smooth - 1.0) > maxsm)
2468 time_of_day_smooth = time_of_day;
2470 if(time_of_day_smooth > 0.8 && time_of_day < 0.2)
2471 time_of_day_smooth = time_of_day_smooth * (1.0-todsm)
2472 + (time_of_day+1.0) * todsm;
2474 time_of_day_smooth = time_of_day_smooth * (1.0-todsm)
2475 + time_of_day * todsm;
2477 sky->update(time_of_day_smooth, time_brightness, direct_brightness,
2480 float brightness = sky->getBrightness();
2481 video::SColor bgcolor = sky->getBgColor();
2482 video::SColor skycolor = sky->getSkyColor();
2488 if(sky->getCloudsVisible()){
2489 clouds->setVisible(true);
2490 clouds->step(dtime);
2491 clouds->update(v2f(player_position.X, player_position.Z),
2492 sky->getCloudColor());
2494 clouds->setVisible(false);
2503 farmesh_range = draw_control.wanted_range * 10;
2504 if(draw_control.range_all && farmesh_range < 500)
2505 farmesh_range = 500;
2506 if(farmesh_range > 1000)
2507 farmesh_range = 1000;
2509 farmesh->step(dtime);
2510 farmesh->update(v2f(player_position.X, player_position.Z),
2511 brightness, farmesh_range);
2518 if(g_settings->getBool("enable_fog") == true && !force_fog_off)
2522 video::EFT_FOG_LINEAR,
2534 video::EFT_FOG_LINEAR,
2544 Update gui stuff (0ms)
2547 //TimeTaker guiupdatetimer("Gui updating");
2549 const char program_name_and_version[] =
2550 "Minetest-c55 " VERSION_STRING;
2554 static float drawtime_avg = 0;
2555 drawtime_avg = drawtime_avg * 0.95 + (float)drawtime*0.05;
2556 /*static float beginscenetime_avg = 0;
2557 beginscenetime_avg = beginscenetime_avg * 0.95 + (float)beginscenetime*0.05;
2558 static float scenetime_avg = 0;
2559 scenetime_avg = scenetime_avg * 0.95 + (float)scenetime*0.05;
2560 static float endscenetime_avg = 0;
2561 endscenetime_avg = endscenetime_avg * 0.95 + (float)endscenetime*0.05;*/
2564 snprintf(temptext, 300, "%s ("
2567 " drawtime=%.0f, dtime_jitter = % .1f %%"
2568 ", v_range = %.1f, RTT = %.3f",
2569 program_name_and_version,
2570 draw_control.range_all,
2572 dtime_jitter1_max_fraction * 100.0,
2573 draw_control.wanted_range,
2577 guitext->setText(narrow_to_wide(temptext).c_str());
2578 guitext->setVisible(true);
2580 else if(show_hud || show_chat)
2582 guitext->setText(narrow_to_wide(program_name_and_version).c_str());
2583 guitext->setVisible(true);
2587 guitext->setVisible(false);
2593 snprintf(temptext, 300,
2594 "(% .1f, % .1f, % .1f)"
2595 " (yaw = %.1f) (seed = %lli)",
2596 player_position.X/BS,
2597 player_position.Y/BS,
2598 player_position.Z/BS,
2599 wrapDegrees_0_360(camera_yaw),
2600 client.getMapSeed());
2602 guitext2->setText(narrow_to_wide(temptext).c_str());
2603 guitext2->setVisible(true);
2607 guitext2->setVisible(false);
2611 guitext_info->setText(infotext.c_str());
2612 guitext_info->setVisible(show_hud && g_menumgr.menuCount() == 0);
2616 float statustext_time_max = 1.5;
2617 if(!statustext.empty())
2619 statustext_time += dtime;
2620 if(statustext_time >= statustext_time_max)
2623 statustext_time = 0;
2626 guitext_status->setText(statustext.c_str());
2627 guitext_status->setVisible(!statustext.empty());
2629 if(!statustext.empty())
2631 s32 status_y = screensize.Y - 130;
2632 core::rect<s32> rect(
2634 status_y - guitext_status->getTextHeight(),
2638 guitext_status->setRelativePosition(rect);
2641 video::SColor initial_color(255,0,0,0);
2642 if(guienv->getSkin())
2643 initial_color = guienv->getSkin()->getColor(gui::EGDC_BUTTON_TEXT);
2644 video::SColor final_color = initial_color;
2645 final_color.setAlpha(0);
2646 video::SColor fade_color =
2647 initial_color.getInterpolated_quadratic(
2650 pow(statustext_time / (float)statustext_time_max, 2.0f));
2651 guitext_status->setOverrideColor(fade_color);
2652 guitext_status->enableOverrideColor(true);
2657 Get chat messages from client
2660 // Get new messages from error log buffer
2661 while(!chat_log_error_buf.empty())
2663 chat_backend.addMessage(L"", narrow_to_wide(
2664 chat_log_error_buf.get()));
2666 // Get new messages from client
2667 std::wstring message;
2668 while(client.getChatMessage(message))
2670 chat_backend.addUnparsedMessage(message);
2672 // Remove old messages
2673 chat_backend.step(dtime);
2675 // Display all messages in a static text element
2676 u32 recent_chat_count = chat_backend.getRecentBuffer().getLineCount();
2677 std::wstring recent_chat = chat_backend.getRecentChat();
2678 guitext_chat->setText(recent_chat.c_str());
2680 // Update gui element size and position
2681 s32 chat_y = 5+(text_height+5);
2683 chat_y += (text_height+5);
2684 core::rect<s32> rect(
2688 chat_y + guitext_chat->getTextHeight()
2690 guitext_chat->setRelativePosition(rect);
2692 // Don't show chat if disabled or empty or profiler is enabled
2693 guitext_chat->setVisible(show_chat && recent_chat_count != 0
2701 if(client.getPlayerItem() != new_playeritem)
2703 client.selectPlayerItem(new_playeritem);
2705 if(client.getLocalInventoryUpdated())
2707 //infostream<<"Updating local inventory"<<std::endl;
2708 client.getLocalInventory(local_inventory);
2710 update_wielded_item_trigger = true;
2712 if(update_wielded_item_trigger)
2714 update_wielded_item_trigger = false;
2715 // Update wielded tool
2716 InventoryList *mlist = local_inventory.getList("main");
2719 item = mlist->getItem(client.getPlayerItem());
2727 TimeTaker tt_draw("mainloop: draw");
2731 TimeTaker timer("beginScene");
2732 //driver->beginScene(false, true, bgcolor);
2733 //driver->beginScene(true, true, bgcolor);
2734 driver->beginScene(true, true, skycolor);
2735 beginscenetime = timer.stop(true);
2740 //infostream<<"smgr->drawAll()"<<std::endl;
2742 TimeTaker timer("smgr");
2744 scenetime = timer.stop(true);
2748 //TimeTaker timer9("auxiliary drawings");
2752 //TimeTaker //timer10("//timer10");
2758 driver->setMaterial(m);
2760 driver->setTransform(video::ETS_WORLD, core::IdentityMatrix);
2764 for(core::list<aabb3f>::Iterator i=hilightboxes.begin();
2765 i != hilightboxes.end(); i++)
2767 /*infostream<<"hilightbox min="
2768 <<"("<<i->MinEdge.X<<","<<i->MinEdge.Y<<","<<i->MinEdge.Z<<")"
2770 <<"("<<i->MaxEdge.X<<","<<i->MaxEdge.Y<<","<<i->MaxEdge.Z<<")"
2772 driver->draw3DBox(*i, video::SColor(255,0,0,0));
2781 // Warning: This clears the Z buffer.
2782 camera.drawWieldedTool();
2789 client.getEnv().getClientMap().renderPostFx();
2795 if(show_profiler_graph)
2797 graph.draw(10, screensize.Y - 10, driver, font);
2805 driver->draw2DLine(displaycenter - core::vector2d<s32>(10,0),
2806 displaycenter + core::vector2d<s32>(10,0),
2807 video::SColor(255,255,255,255));
2808 driver->draw2DLine(displaycenter - core::vector2d<s32>(0,10),
2809 displaycenter + core::vector2d<s32>(0,10),
2810 video::SColor(255,255,255,255));
2816 //TimeTaker //timer11("//timer11");
2829 draw_hotbar(driver, font, gamedef,
2830 v2s32(displaycenter.X, screensize.Y),
2831 hotbar_imagesize, hotbar_itemcount, &local_inventory,
2832 client.getHP(), client.getPlayerItem());
2838 if(damage_flash_timer > 0.0)
2840 damage_flash_timer -= dtime;
2842 video::SColor color(128,255,0,0);
2843 driver->draw2DRectangle(color,
2844 core::rect<s32>(0,0,screensize.X,screensize.Y),
2852 TimeTaker timer("endScene");
2854 endscenetime = timer.stop(true);
2857 drawtime = tt_draw.stop(true);
2858 g_profiler->graphAdd("mainloop_draw", (float)drawtime/1000.0f);
2864 static s16 lastFPS = 0;
2865 //u16 fps = driver->getFPS();
2866 u16 fps = (1.0/dtime_avg1);
2870 core::stringw str = L"Minetest [";
2871 str += driver->getName();
2875 device->setWindowCaption(str.c_str());
2880 Log times and stuff for visualization
2882 Profiler::GraphValues values;
2883 g_profiler->graphGet(values);
2892 if(gui_chat_console)
2893 gui_chat_console->drop();
2896 Draw a "shutting down" screen, which will be shown while the map
2897 generator and other stuff quits
2900 /*gui::IGUIStaticText *gui_shuttingdowntext = */
2901 draw_load_screen(L"Shutting down stuff...", driver, font);
2902 /*driver->beginScene(true, true, video::SColor(255,0,0,0));
2905 gui_shuttingdowntext->remove();*/
2908 chat_backend.addMessage(L"", L"# Disconnected.");
2909 chat_backend.addMessage(L"", L"");
2911 // Client scope (client is destructed before destructing *def and tsrc)
2914 catch(SerializationError &e)
2916 error_message = L"A serialization error occurred:\n"
2917 + narrow_to_wide(e.what()) + L"\n\nThe server is probably "
2918 L" running a different version of Minetest.";
2919 errorstream<<wide_to_narrow(error_message)<<std::endl;