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,
1572 &g_menumgr, v2s16(8,7),
1575 InventoryLocation inventoryloc;
1576 inventoryloc.setCurrentPlayer();
1578 core::array<GUIInventoryMenu::DrawSpec> draw_spec;
1579 draw_spec.push_back(GUIInventoryMenu::DrawSpec(
1580 "list", inventoryloc, "main",
1581 v2s32(0, 3), v2s32(8, 4)));
1582 draw_spec.push_back(GUIInventoryMenu::DrawSpec(
1583 "list", inventoryloc, "craft",
1584 v2s32(3, 0), v2s32(3, 3)));
1585 draw_spec.push_back(GUIInventoryMenu::DrawSpec(
1586 "list", inventoryloc, "craftpreview",
1587 v2s32(7, 1), v2s32(1, 1)));
1589 menu->setDrawSpec(draw_spec);
1593 else if(input->wasKeyDown(EscapeKey))
1595 infostream<<"the_game: "
1596 <<"Launching pause menu"<<std::endl;
1597 // It will delete itself by itself
1598 (new GUIPauseMenu(guienv, guiroot, -1, g_gamecallback,
1599 &g_menumgr, simple_singleplayer_mode))->drop();
1601 // Move mouse cursor on top of the disconnect button
1602 if(simple_singleplayer_mode)
1603 input->setMousePos(displaycenter.X, displaycenter.Y+0);
1605 input->setMousePos(displaycenter.X, displaycenter.Y+25);
1607 else if(input->wasKeyDown(getKeySetting("keymap_chat")))
1609 TextDest *dest = new TextDestChat(&client);
1611 (new GUITextInputMenu(guienv, guiroot, -1,
1615 else if(input->wasKeyDown(getKeySetting("keymap_cmd")))
1617 TextDest *dest = new TextDestChat(&client);
1619 (new GUITextInputMenu(guienv, guiroot, -1,
1623 else if(input->wasKeyDown(getKeySetting("keymap_console")))
1625 if (!gui_chat_console->isOpenInhibited())
1627 // Open up to over half of the screen
1628 gui_chat_console->openConsole(0.6);
1629 guienv->setFocus(gui_chat_console);
1632 else if(input->wasKeyDown(getKeySetting("keymap_freemove")))
1634 if(g_settings->getBool("free_move"))
1636 g_settings->set("free_move","false");
1637 statustext = L"free_move disabled";
1638 statustext_time = 0;
1642 g_settings->set("free_move","true");
1643 statustext = L"free_move enabled";
1644 statustext_time = 0;
1645 if(!client.checkPrivilege("fly"))
1646 statustext += L" (note: no 'fly' privilege)";
1649 else if(input->wasKeyDown(getKeySetting("keymap_fastmove")))
1651 if(g_settings->getBool("fast_move"))
1653 g_settings->set("fast_move","false");
1654 statustext = L"fast_move disabled";
1655 statustext_time = 0;
1659 g_settings->set("fast_move","true");
1660 statustext = L"fast_move enabled";
1661 statustext_time = 0;
1662 if(!client.checkPrivilege("fast"))
1663 statustext += L" (note: no 'fast' privilege)";
1666 else if(input->wasKeyDown(getKeySetting("keymap_screenshot")))
1668 irr::video::IImage* const image = driver->createScreenShot();
1670 irr::c8 filename[256];
1671 snprintf(filename, 256, "%s" DIR_DELIM "screenshot_%u.png",
1672 g_settings->get("screenshot_path").c_str(),
1673 device->getTimer()->getRealTime());
1674 if (driver->writeImageToFile(image, filename)) {
1675 std::wstringstream sstr;
1676 sstr<<"Saved screenshot to '"<<filename<<"'";
1677 infostream<<"Saved screenshot to '"<<filename<<"'"<<std::endl;
1678 statustext = sstr.str();
1679 statustext_time = 0;
1681 infostream<<"Failed to save screenshot '"<<filename<<"'"<<std::endl;
1686 else if(input->wasKeyDown(getKeySetting("keymap_toggle_hud")))
1688 show_hud = !show_hud;
1690 statustext = L"HUD shown";
1692 statustext = L"HUD hidden";
1693 statustext_time = 0;
1695 else if(input->wasKeyDown(getKeySetting("keymap_toggle_chat")))
1697 show_chat = !show_chat;
1699 statustext = L"Chat shown";
1701 statustext = L"Chat hidden";
1702 statustext_time = 0;
1704 else if(input->wasKeyDown(getKeySetting("keymap_toggle_force_fog_off")))
1706 force_fog_off = !force_fog_off;
1708 statustext = L"Fog disabled";
1710 statustext = L"Fog enabled";
1711 statustext_time = 0;
1713 else if(input->wasKeyDown(getKeySetting("keymap_toggle_update_camera")))
1715 disable_camera_update = !disable_camera_update;
1716 if(disable_camera_update)
1717 statustext = L"Camera update disabled";
1719 statustext = L"Camera update enabled";
1720 statustext_time = 0;
1722 else if(input->wasKeyDown(getKeySetting("keymap_toggle_debug")))
1724 // Initial / 3x toggle: Chat only
1725 // 1x toggle: Debug text with chat
1726 // 2x toggle: Debug text with profiler graph
1730 show_profiler_graph = false;
1731 statustext = L"Debug info shown";
1732 statustext_time = 0;
1734 else if(show_profiler_graph)
1737 show_profiler_graph = false;
1738 statustext = L"Debug info and profiler graph hidden";
1739 statustext_time = 0;
1743 show_profiler_graph = true;
1744 statustext = L"Profiler graph shown";
1745 statustext_time = 0;
1748 else if(input->wasKeyDown(getKeySetting("keymap_toggle_profiler")))
1750 show_profiler = (show_profiler + 1) % (show_profiler_max + 1);
1752 // FIXME: This updates the profiler with incomplete values
1753 update_profiler_gui(guitext_profiler, font, text_height,
1754 show_profiler, show_profiler_max);
1756 if(show_profiler != 0)
1758 std::wstringstream sstr;
1759 sstr<<"Profiler shown (page "<<show_profiler
1760 <<" of "<<show_profiler_max<<")";
1761 statustext = sstr.str();
1762 statustext_time = 0;
1766 statustext = L"Profiler hidden";
1767 statustext_time = 0;
1770 else if(input->wasKeyDown(getKeySetting("keymap_increase_viewing_range_min")))
1772 s16 range = g_settings->getS16("viewing_range_nodes_min");
1773 s16 range_new = range + 10;
1774 g_settings->set("viewing_range_nodes_min", itos(range_new));
1775 statustext = narrow_to_wide(
1776 "Minimum viewing range changed to "
1778 statustext_time = 0;
1780 else if(input->wasKeyDown(getKeySetting("keymap_decrease_viewing_range_min")))
1782 s16 range = g_settings->getS16("viewing_range_nodes_min");
1783 s16 range_new = range - 10;
1786 g_settings->set("viewing_range_nodes_min",
1788 statustext = narrow_to_wide(
1789 "Minimum viewing range changed to "
1791 statustext_time = 0;
1794 // Handle QuicktuneShortcutter
1795 if(input->wasKeyDown(getKeySetting("keymap_quicktune_next")))
1797 if(input->wasKeyDown(getKeySetting("keymap_quicktune_prev")))
1799 if(input->wasKeyDown(getKeySetting("keymap_quicktune_inc")))
1801 if(input->wasKeyDown(getKeySetting("keymap_quicktune_dec")))
1804 std::string msg = quicktune.getMessage();
1806 statustext = narrow_to_wide(msg);
1807 statustext_time = 0;
1811 // Item selection with mouse wheel
1812 u16 new_playeritem = client.getPlayerItem();
1814 s32 wheel = input->getMouseWheel();
1815 u16 max_item = MYMIN(PLAYER_INVENTORY_SIZE-1,
1816 hotbar_itemcount-1);
1820 if(new_playeritem < max_item)
1827 if(new_playeritem > 0)
1830 new_playeritem = max_item;
1835 for(u16 i=0; i<10; i++)
1837 const KeyPress *kp = NumberKey + (i + 1) % 10;
1838 if(input->wasKeyDown(*kp))
1840 if(i < PLAYER_INVENTORY_SIZE && i < hotbar_itemcount)
1844 infostream<<"Selected item: "
1845 <<new_playeritem<<std::endl;
1850 // Viewing range selection
1851 if(input->wasKeyDown(getKeySetting("keymap_rangeselect")))
1853 draw_control.range_all = !draw_control.range_all;
1854 if(draw_control.range_all)
1856 infostream<<"Enabled full viewing range"<<std::endl;
1857 statustext = L"Enabled full viewing range";
1858 statustext_time = 0;
1862 infostream<<"Disabled full viewing range"<<std::endl;
1863 statustext = L"Disabled full viewing range";
1864 statustext_time = 0;
1868 // Print debug stacks
1869 if(input->wasKeyDown(getKeySetting("keymap_print_debug_stacks")))
1871 dstream<<"-----------------------------------------"
1873 dstream<<DTIME<<"Printing debug stacks:"<<std::endl;
1874 dstream<<"-----------------------------------------"
1876 debug_stacks_print();
1880 Mouse and camera control
1881 NOTE: Do this before client.setPlayerControl() to not cause a camera lag of one frame
1884 float turn_amount = 0;
1885 if((device->isWindowActive() && noMenuActive()) || random_input)
1889 // Mac OSX gets upset if this is set every frame
1890 if(device->getCursorControl()->isVisible())
1891 device->getCursorControl()->setVisible(false);
1894 if(first_loop_after_window_activation){
1895 //infostream<<"window active, first loop"<<std::endl;
1896 first_loop_after_window_activation = false;
1899 s32 dx = input->getMousePos().X - displaycenter.X;
1900 s32 dy = input->getMousePos().Y - displaycenter.Y;
1903 //infostream<<"window active, pos difference "<<dx<<","<<dy<<std::endl;
1905 /*const float keyspeed = 500;
1906 if(input->isKeyDown(irr::KEY_UP))
1907 dy -= dtime * keyspeed;
1908 if(input->isKeyDown(irr::KEY_DOWN))
1909 dy += dtime * keyspeed;
1910 if(input->isKeyDown(irr::KEY_LEFT))
1911 dx -= dtime * keyspeed;
1912 if(input->isKeyDown(irr::KEY_RIGHT))
1913 dx += dtime * keyspeed;*/
1917 camera_pitch += dy*d;
1918 if(camera_pitch < -89.5) camera_pitch = -89.5;
1919 if(camera_pitch > 89.5) camera_pitch = 89.5;
1921 turn_amount = v2f(dx, dy).getLength() * d;
1923 input->setMousePos(displaycenter.X, displaycenter.Y);
1926 // Mac OSX gets upset if this is set every frame
1927 if(device->getCursorControl()->isVisible() == false)
1928 device->getCursorControl()->setVisible(true);
1930 //infostream<<"window inactive"<<std::endl;
1931 first_loop_after_window_activation = true;
1933 recent_turn_speed = recent_turn_speed * 0.9 + turn_amount * 0.1;
1934 //std::cerr<<"recent_turn_speed = "<<recent_turn_speed<<std::endl;
1937 Player speed control
1949 PlayerControl control(
1950 input->isKeyDown(getKeySetting("keymap_forward")),
1951 input->isKeyDown(getKeySetting("keymap_backward")),
1952 input->isKeyDown(getKeySetting("keymap_left")),
1953 input->isKeyDown(getKeySetting("keymap_right")),
1954 input->isKeyDown(getKeySetting("keymap_jump")),
1955 input->isKeyDown(getKeySetting("keymap_special1")),
1956 input->isKeyDown(getKeySetting("keymap_sneak")),
1960 client.setPlayerControl(control);
1969 //TimeTaker timer("server->step(dtime)");
1970 server->step(dtime);
1978 //TimeTaker timer("client.step(dtime)");
1980 //client.step(dtime_avg1);
1984 // Read client events
1987 ClientEvent event = client.getClientEvent();
1988 if(event.type == CE_NONE)
1992 else if(event.type == CE_PLAYER_DAMAGE)
1994 //u16 damage = event.player_damage.amount;
1995 //infostream<<"Player damage: "<<damage<<std::endl;
1996 damage_flash_timer = 0.05;
1997 if(event.player_damage.amount >= 2){
1998 damage_flash_timer += 0.05 * event.player_damage.amount;
2001 else if(event.type == CE_PLAYER_FORCE_MOVE)
2003 camera_yaw = event.player_force_move.yaw;
2004 camera_pitch = event.player_force_move.pitch;
2006 else if(event.type == CE_DEATHSCREEN)
2008 if(respawn_menu_active)
2011 /*bool set_camera_point_target =
2012 event.deathscreen.set_camera_point_target;
2013 v3f camera_point_target;
2014 camera_point_target.X = event.deathscreen.camera_point_target_x;
2015 camera_point_target.Y = event.deathscreen.camera_point_target_y;
2016 camera_point_target.Z = event.deathscreen.camera_point_target_z;*/
2017 MainRespawnInitiator *respawner =
2018 new MainRespawnInitiator(
2019 &respawn_menu_active, &client);
2020 GUIDeathScreen *menu =
2021 new GUIDeathScreen(guienv, guiroot, -1,
2022 &g_menumgr, respawner);
2025 chat_backend.addMessage(L"", L"You died.");
2027 /* Handle visualization */
2029 damage_flash_timer = 0;
2031 /*LocalPlayer* player = client.getLocalPlayer();
2032 player->setPosition(player->getPosition() + v3f(0,-BS,0));
2033 camera.update(player, busytime, screensize);*/
2035 else if(event.type == CE_TEXTURES_UPDATED)
2037 update_wielded_item_trigger = true;
2042 //TimeTaker //timer2("//timer2");
2045 For interaction purposes, get info about the held item
2047 - Is it a usable item?
2048 - Can it point to liquids?
2050 ItemStack playeritem;
2051 bool playeritem_usable = false;
2052 bool playeritem_liquids_pointable = false;
2054 InventoryList *mlist = local_inventory.getList("main");
2057 playeritem = mlist->getItem(client.getPlayerItem());
2058 playeritem_usable = playeritem.getDefinition(itemdef).usable;
2059 playeritem_liquids_pointable = playeritem.getDefinition(itemdef).liquids_pointable;
2062 ToolCapabilities playeritem_toolcap =
2063 playeritem.getToolCapabilities(itemdef);
2069 LocalPlayer* player = client.getEnv().getLocalPlayer();
2070 float full_punch_interval = playeritem_toolcap.full_punch_interval;
2071 float tool_reload_ratio = time_from_last_punch / full_punch_interval;
2072 tool_reload_ratio = MYMIN(tool_reload_ratio, 1.0);
2073 camera.update(player, busytime, screensize, tool_reload_ratio);
2076 v3f player_position = player->getPosition();
2077 v3f camera_position = camera.getPosition();
2078 v3f camera_direction = camera.getDirection();
2079 f32 camera_fov = camera.getFovMax();
2081 if(!disable_camera_update){
2082 client.getEnv().getClientMap().updateCamera(camera_position,
2083 camera_direction, camera_fov);
2086 // Update sound listener
2087 sound->updateListener(camera.getCameraNode()->getPosition(),
2088 v3f(0,0,0), // velocity
2089 camera.getDirection(),
2090 camera.getCameraNode()->getUpVector());
2091 sound->setListenerGain(g_settings->getFloat("sound_volume"));
2097 soundmaker.step(dtime);
2099 ClientMap &map = client.getEnv().getClientMap();
2100 MapNode n = map.getNodeNoEx(player->getStandingNodePos());
2101 soundmaker.m_player_step_sound = nodedef->get(n).sound_footstep;
2105 Calculate what block is the crosshair pointing to
2108 //u32 t1 = device->getTimer()->getRealTime();
2110 f32 d = 4; // max. distance
2111 core::line3d<f32> shootline(camera_position,
2112 camera_position + camera_direction * BS * (d+1));
2114 core::aabbox3d<f32> hilightbox;
2115 bool should_show_hilightbox = false;
2116 ClientActiveObject *selected_object = NULL;
2118 PointedThing pointed = getPointedThing(
2120 &client, player_position, camera_direction,
2121 camera_position, shootline, d,
2122 playeritem_liquids_pointable, !ldown_for_dig,
2124 hilightbox, should_show_hilightbox,
2127 if(pointed != pointed_old)
2129 infostream<<"Pointing at "<<pointed.dump()<<std::endl;
2130 //dstream<<"Pointing at "<<pointed.dump()<<std::endl;
2136 if(should_show_hilightbox)
2137 hilightboxes.push_back(hilightbox);
2141 - releasing left mouse button
2142 - pointing away from node
2146 if(input->getLeftReleased())
2148 infostream<<"Left button released"
2149 <<" (stopped digging)"<<std::endl;
2152 else if(pointed != pointed_old)
2154 if (pointed.type == POINTEDTHING_NODE
2155 && pointed_old.type == POINTEDTHING_NODE
2156 && pointed.node_undersurface == pointed_old.node_undersurface)
2158 // Still pointing to the same node,
2159 // but a different face. Don't reset.
2163 infostream<<"Pointing away from node"
2164 <<" (stopped digging)"<<std::endl;
2170 client.interact(1, pointed_old);
2171 client.setCrack(-1, v3s16(0,0,0));
2175 if(!digging && ldown_for_dig && !input->getLeftState())
2177 ldown_for_dig = false;
2180 bool left_punch = false;
2181 soundmaker.m_player_leftpunch_sound.name = "";
2183 if(playeritem_usable && input->getLeftState())
2185 if(input->getLeftClicked())
2186 client.interact(4, pointed);
2188 else if(pointed.type == POINTEDTHING_NODE)
2190 v3s16 nodepos = pointed.node_undersurface;
2191 v3s16 neighbourpos = pointed.node_abovesurface;
2194 Check information text of node
2197 ClientMap &map = client.getEnv().getClientMap();
2198 NodeMetadata *meta = map.getNodeMetadata(nodepos);
2200 infotext = narrow_to_wide(meta->getString("infotext"));
2202 MapNode n = map.getNode(nodepos);
2203 if(nodedef->get(n).tname_tiles[0] == "unknown_block.png"){
2204 infotext = L"Unknown node: ";
2205 infotext += narrow_to_wide(nodedef->get(n).name);
2209 // We can't actually know, but assume the sound of right-clicking
2210 // to be the sound of placing a node
2211 soundmaker.m_player_rightpunch_sound.gain = 0.5;
2212 soundmaker.m_player_rightpunch_sound.name = "default_place_node";
2218 if(nodig_delay_timer <= 0.0 && input->getLeftState())
2222 infostream<<"Started digging"<<std::endl;
2223 client.interact(0, pointed);
2225 ldown_for_dig = true;
2227 MapNode n = client.getEnv().getClientMap().getNode(nodepos);
2229 // Get digging parameters
2230 DigParams params = getDigParams(nodedef->get(n).groups,
2231 &playeritem_toolcap);
2232 // If can't dig, try hand
2233 if(!params.diggable){
2234 const ItemDefinition &hand = itemdef->get("");
2235 const ToolCapabilities *tp = hand.tool_capabilities;
2237 params = getDigParams(nodedef->get(n).groups, tp);
2240 SimpleSoundSpec sound_dig = nodedef->get(n).sound_dig;
2241 if(sound_dig.exists()){
2242 if(sound_dig.name == "__group"){
2243 if(params.main_group != ""){
2244 soundmaker.m_player_leftpunch_sound.gain = 0.5;
2245 soundmaker.m_player_leftpunch_sound.name =
2246 std::string("default_dig_") +
2250 soundmaker.m_player_leftpunch_sound = sound_dig;
2254 float dig_time_complete = 0.0;
2256 if(params.diggable == false)
2258 // I guess nobody will wait for this long
2259 dig_time_complete = 10000000.0;
2263 dig_time_complete = params.time;
2266 if(dig_time_complete >= 0.001)
2268 dig_index = (u16)((float)CRACK_ANIMATION_LENGTH
2269 * dig_time/dig_time_complete);
2271 // This is for torches
2274 dig_index = CRACK_ANIMATION_LENGTH;
2277 // Don't show cracks if not diggable
2278 if(dig_time_complete >= 100000.0)
2281 else if(dig_index < CRACK_ANIMATION_LENGTH)
2283 //TimeTaker timer("client.setTempMod");
2284 //infostream<<"dig_index="<<dig_index<<std::endl;
2285 client.setCrack(dig_index, nodepos);
2289 infostream<<"Digging completed"<<std::endl;
2290 client.interact(2, pointed);
2291 client.setCrack(-1, v3s16(0,0,0));
2292 MapNode wasnode = map.getNode(nodepos);
2293 client.removeNode(nodepos);
2298 nodig_delay_timer = dig_time_complete
2299 / (float)CRACK_ANIMATION_LENGTH;
2301 // We don't want a corresponding delay to
2302 // very time consuming nodes
2303 if(nodig_delay_timer > 0.3)
2304 nodig_delay_timer = 0.3;
2305 // We want a slight delay to very little
2306 // time consuming nodes
2307 float mindelay = 0.15;
2308 if(nodig_delay_timer < mindelay)
2309 nodig_delay_timer = mindelay;
2311 // Send event to trigger sound
2312 MtEvent *e = new NodeDugEvent(nodepos, wasnode);
2313 gamedef->event()->put(e);
2318 camera.setDigging(0); // left click animation
2321 if(input->getRightClicked())
2323 infostream<<"Ground right-clicked"<<std::endl;
2325 // sign special case, at least until formspec is properly implemented
2326 if(meta && meta->getString("formspec") == "hack:sign_text_input" && !random_input)
2328 infostream<<"Launching metadata text input"<<std::endl;
2330 // Get a new text for it
2332 TextDest *dest = new TextDestNodeMetadata(nodepos, &client);
2334 std::wstring wtext = narrow_to_wide(meta->getString("text"));
2336 (new GUITextInputMenu(guienv, guiroot, -1,
2340 // If metadata provides an inventory view, activate it
2341 else if(meta && meta->getString("formspec") != "" && !random_input)
2343 infostream<<"Launching custom inventory view"<<std::endl;
2345 InventoryLocation inventoryloc;
2346 inventoryloc.setNodeMeta(nodepos);
2353 core::array<GUIInventoryMenu::DrawSpec> draw_spec;
2355 GUIInventoryMenu::makeDrawSpecArrayFromString(
2357 meta->getString("formspec"),
2360 GUIInventoryMenu *menu =
2361 new GUIInventoryMenu(guienv, guiroot, -1,
2362 &g_menumgr, invsize,
2364 menu->setDrawSpec(draw_spec);
2367 // Otherwise report right click to server
2370 client.interact(3, pointed);
2371 camera.setDigging(1); // right click animation
2375 else if(pointed.type == POINTEDTHING_OBJECT)
2377 infotext = narrow_to_wide(selected_object->infoText());
2379 if(infotext == L"" && show_debug){
2380 infotext = narrow_to_wide(selected_object->debugInfoText());
2383 //if(input->getLeftClicked())
2384 if(input->getLeftState())
2386 bool do_punch = false;
2387 bool do_punch_damage = false;
2388 if(object_hit_delay_timer <= 0.0){
2390 do_punch_damage = true;
2391 object_hit_delay_timer = object_hit_delay;
2393 if(input->getLeftClicked()){
2397 infostream<<"Left-clicked object"<<std::endl;
2400 if(do_punch_damage){
2401 // Report direct punch
2402 v3f objpos = selected_object->getPosition();
2403 v3f dir = (objpos - player_position).normalize();
2405 bool disable_send = selected_object->directReportPunch(
2406 dir, &playeritem, time_from_last_punch);
2407 time_from_last_punch = 0;
2409 client.interact(0, pointed);
2412 else if(input->getRightClicked())
2414 infostream<<"Right-clicked object"<<std::endl;
2415 client.interact(3, pointed); // place
2418 else if(input->getLeftState())
2420 // When button is held down in air, show continuous animation
2424 pointed_old = pointed;
2426 if(left_punch || input->getLeftClicked())
2428 camera.setDigging(0); // left click animation
2431 input->resetLeftClicked();
2432 input->resetRightClicked();
2434 input->resetLeftReleased();
2435 input->resetRightReleased();
2438 Calculate stuff for drawing
2448 fog_range = BS*farmesh_range;
2452 fog_range = draw_control.wanted_range*BS + 0.0*MAP_BLOCKSIZE*BS;
2454 if(draw_control.range_all)
2455 fog_range = 100000*BS;
2459 Calculate general brightness
2461 u32 daynight_ratio = client.getEnv().getDayNightRatio();
2462 float time_brightness = (float)decode_light(
2463 (daynight_ratio * LIGHT_SUN) / 1000) / 255.0;
2464 float direct_brightness = 0;
2465 bool sunlight_seen = false;
2466 if(g_settings->getBool("free_move")){
2467 direct_brightness = time_brightness;
2468 sunlight_seen = true;
2470 ScopeProfiler sp(g_profiler, "Detecting background light", SPT_AVG);
2471 float old_brightness = sky->getBrightness();
2472 direct_brightness = (float)client.getEnv().getClientMap()
2473 .getBackgroundBrightness(MYMIN(fog_range*1.2, 60*BS),
2474 daynight_ratio, (int)(old_brightness*255.5), &sunlight_seen)
2478 time_of_day = client.getEnv().getTimeOfDayF();
2480 if(fabs(time_of_day - time_of_day_smooth) > maxsm &&
2481 fabs(time_of_day - time_of_day_smooth + 1.0) > maxsm &&
2482 fabs(time_of_day - time_of_day_smooth - 1.0) > maxsm)
2483 time_of_day_smooth = time_of_day;
2485 if(time_of_day_smooth > 0.8 && time_of_day < 0.2)
2486 time_of_day_smooth = time_of_day_smooth * (1.0-todsm)
2487 + (time_of_day+1.0) * todsm;
2489 time_of_day_smooth = time_of_day_smooth * (1.0-todsm)
2490 + time_of_day * todsm;
2492 sky->update(time_of_day_smooth, time_brightness, direct_brightness,
2495 float brightness = sky->getBrightness();
2496 video::SColor bgcolor = sky->getBgColor();
2497 video::SColor skycolor = sky->getSkyColor();
2503 if(sky->getCloudsVisible()){
2504 clouds->setVisible(true);
2505 clouds->step(dtime);
2506 clouds->update(v2f(player_position.X, player_position.Z),
2507 sky->getCloudColor());
2509 clouds->setVisible(false);
2518 farmesh_range = draw_control.wanted_range * 10;
2519 if(draw_control.range_all && farmesh_range < 500)
2520 farmesh_range = 500;
2521 if(farmesh_range > 1000)
2522 farmesh_range = 1000;
2524 farmesh->step(dtime);
2525 farmesh->update(v2f(player_position.X, player_position.Z),
2526 brightness, farmesh_range);
2533 if(g_settings->getBool("enable_fog") == true && !force_fog_off)
2537 video::EFT_FOG_LINEAR,
2549 video::EFT_FOG_LINEAR,
2559 Update gui stuff (0ms)
2562 //TimeTaker guiupdatetimer("Gui updating");
2564 const char program_name_and_version[] =
2565 "Minetest-c55 " VERSION_STRING;
2569 static float drawtime_avg = 0;
2570 drawtime_avg = drawtime_avg * 0.95 + (float)drawtime*0.05;
2571 /*static float beginscenetime_avg = 0;
2572 beginscenetime_avg = beginscenetime_avg * 0.95 + (float)beginscenetime*0.05;
2573 static float scenetime_avg = 0;
2574 scenetime_avg = scenetime_avg * 0.95 + (float)scenetime*0.05;
2575 static float endscenetime_avg = 0;
2576 endscenetime_avg = endscenetime_avg * 0.95 + (float)endscenetime*0.05;*/
2579 snprintf(temptext, 300, "%s ("
2582 " drawtime=%.0f, dtime_jitter = % .1f %%"
2583 ", v_range = %.1f, RTT = %.3f",
2584 program_name_and_version,
2585 draw_control.range_all,
2587 dtime_jitter1_max_fraction * 100.0,
2588 draw_control.wanted_range,
2592 guitext->setText(narrow_to_wide(temptext).c_str());
2593 guitext->setVisible(true);
2595 else if(show_hud || show_chat)
2597 guitext->setText(narrow_to_wide(program_name_and_version).c_str());
2598 guitext->setVisible(true);
2602 guitext->setVisible(false);
2608 snprintf(temptext, 300,
2609 "(% .1f, % .1f, % .1f)"
2610 " (yaw = %.1f) (seed = %lli)",
2611 player_position.X/BS,
2612 player_position.Y/BS,
2613 player_position.Z/BS,
2614 wrapDegrees_0_360(camera_yaw),
2615 client.getMapSeed());
2617 guitext2->setText(narrow_to_wide(temptext).c_str());
2618 guitext2->setVisible(true);
2622 guitext2->setVisible(false);
2626 guitext_info->setText(infotext.c_str());
2627 guitext_info->setVisible(show_hud && g_menumgr.menuCount() == 0);
2631 float statustext_time_max = 1.5;
2632 if(!statustext.empty())
2634 statustext_time += dtime;
2635 if(statustext_time >= statustext_time_max)
2638 statustext_time = 0;
2641 guitext_status->setText(statustext.c_str());
2642 guitext_status->setVisible(!statustext.empty());
2644 if(!statustext.empty())
2646 s32 status_y = screensize.Y - 130;
2647 core::rect<s32> rect(
2649 status_y - guitext_status->getTextHeight(),
2653 guitext_status->setRelativePosition(rect);
2656 video::SColor initial_color(255,0,0,0);
2657 if(guienv->getSkin())
2658 initial_color = guienv->getSkin()->getColor(gui::EGDC_BUTTON_TEXT);
2659 video::SColor final_color = initial_color;
2660 final_color.setAlpha(0);
2661 video::SColor fade_color =
2662 initial_color.getInterpolated_quadratic(
2665 pow(statustext_time / (float)statustext_time_max, 2.0f));
2666 guitext_status->setOverrideColor(fade_color);
2667 guitext_status->enableOverrideColor(true);
2672 Get chat messages from client
2675 // Get new messages from error log buffer
2676 while(!chat_log_error_buf.empty())
2678 chat_backend.addMessage(L"", narrow_to_wide(
2679 chat_log_error_buf.get()));
2681 // Get new messages from client
2682 std::wstring message;
2683 while(client.getChatMessage(message))
2685 chat_backend.addUnparsedMessage(message);
2687 // Remove old messages
2688 chat_backend.step(dtime);
2690 // Display all messages in a static text element
2691 u32 recent_chat_count = chat_backend.getRecentBuffer().getLineCount();
2692 std::wstring recent_chat = chat_backend.getRecentChat();
2693 guitext_chat->setText(recent_chat.c_str());
2695 // Update gui element size and position
2696 s32 chat_y = 5+(text_height+5);
2698 chat_y += (text_height+5);
2699 core::rect<s32> rect(
2703 chat_y + guitext_chat->getTextHeight()
2705 guitext_chat->setRelativePosition(rect);
2707 // Don't show chat if disabled or empty or profiler is enabled
2708 guitext_chat->setVisible(show_chat && recent_chat_count != 0
2716 if(client.getPlayerItem() != new_playeritem)
2718 client.selectPlayerItem(new_playeritem);
2720 if(client.getLocalInventoryUpdated())
2722 //infostream<<"Updating local inventory"<<std::endl;
2723 client.getLocalInventory(local_inventory);
2725 update_wielded_item_trigger = true;
2727 if(update_wielded_item_trigger)
2729 update_wielded_item_trigger = false;
2730 // Update wielded tool
2731 InventoryList *mlist = local_inventory.getList("main");
2734 item = mlist->getItem(client.getPlayerItem());
2742 TimeTaker tt_draw("mainloop: draw");
2746 TimeTaker timer("beginScene");
2747 //driver->beginScene(false, true, bgcolor);
2748 //driver->beginScene(true, true, bgcolor);
2749 driver->beginScene(true, true, skycolor);
2750 beginscenetime = timer.stop(true);
2755 //infostream<<"smgr->drawAll()"<<std::endl;
2757 TimeTaker timer("smgr");
2759 scenetime = timer.stop(true);
2763 //TimeTaker timer9("auxiliary drawings");
2767 //TimeTaker //timer10("//timer10");
2773 driver->setMaterial(m);
2775 driver->setTransform(video::ETS_WORLD, core::IdentityMatrix);
2779 for(core::list<aabb3f>::Iterator i=hilightboxes.begin();
2780 i != hilightboxes.end(); i++)
2782 /*infostream<<"hilightbox min="
2783 <<"("<<i->MinEdge.X<<","<<i->MinEdge.Y<<","<<i->MinEdge.Z<<")"
2785 <<"("<<i->MaxEdge.X<<","<<i->MaxEdge.Y<<","<<i->MaxEdge.Z<<")"
2787 driver->draw3DBox(*i, video::SColor(255,0,0,0));
2796 // Warning: This clears the Z buffer.
2797 camera.drawWieldedTool();
2804 client.getEnv().getClientMap().renderPostFx();
2810 if(show_profiler_graph)
2812 graph.draw(10, screensize.Y - 10, driver, font);
2820 driver->draw2DLine(displaycenter - core::vector2d<s32>(10,0),
2821 displaycenter + core::vector2d<s32>(10,0),
2822 video::SColor(255,255,255,255));
2823 driver->draw2DLine(displaycenter - core::vector2d<s32>(0,10),
2824 displaycenter + core::vector2d<s32>(0,10),
2825 video::SColor(255,255,255,255));
2831 //TimeTaker //timer11("//timer11");
2844 draw_hotbar(driver, font, gamedef,
2845 v2s32(displaycenter.X, screensize.Y),
2846 hotbar_imagesize, hotbar_itemcount, &local_inventory,
2847 client.getHP(), client.getPlayerItem());
2853 if(damage_flash_timer > 0.0)
2855 damage_flash_timer -= dtime;
2857 video::SColor color(128,255,0,0);
2858 driver->draw2DRectangle(color,
2859 core::rect<s32>(0,0,screensize.X,screensize.Y),
2867 TimeTaker timer("endScene");
2869 endscenetime = timer.stop(true);
2872 drawtime = tt_draw.stop(true);
2873 g_profiler->graphAdd("mainloop_draw", (float)drawtime/1000.0f);
2879 static s16 lastFPS = 0;
2880 //u16 fps = driver->getFPS();
2881 u16 fps = (1.0/dtime_avg1);
2885 core::stringw str = L"Minetest [";
2886 str += driver->getName();
2890 device->setWindowCaption(str.c_str());
2895 Log times and stuff for visualization
2897 Profiler::GraphValues values;
2898 g_profiler->graphGet(values);
2907 if(gui_chat_console)
2908 gui_chat_console->drop();
2911 Draw a "shutting down" screen, which will be shown while the map
2912 generator and other stuff quits
2915 /*gui::IGUIStaticText *gui_shuttingdowntext = */
2916 draw_load_screen(L"Shutting down stuff...", driver, font);
2917 /*driver->beginScene(true, true, video::SColor(255,0,0,0));
2920 gui_shuttingdowntext->remove();*/
2923 chat_backend.addMessage(L"", L"# Disconnected.");
2924 chat_backend.addMessage(L"", L"");
2926 // Client scope (client is destructed before destructing *def and tsrc)
2929 catch(SerializationError &e)
2931 error_message = L"A serialization error occurred:\n"
2932 + narrow_to_wide(e.what()) + L"\n\nThe server is probably "
2933 L" running a different version of Minetest.";
2934 errorstream<<wide_to_narrow(error_message)<<std::endl;