3 Copyright (C) 2010-2011 celeron55, Perttu Ahola <celeron55@gmail.com>
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License along
16 with this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21 #include "common_irrlicht.h"
22 #include <IGUICheckBox.h>
23 #include <IGUIEditBox.h>
24 #include <IGUIButton.h>
25 #include <IGUIStaticText.h>
29 #include "guiPauseMenu.h"
30 #include "guiPasswordChange.h"
31 #include "guiInventoryMenu.h"
32 #include "guiTextInputMenu.h"
33 #include "guiDeathScreen.h"
35 #include "guiChatConsole.h"
43 #include "mainmenumanager.h"
47 // Needed for determining pointing to nodes
49 #include "nodemetadata.h"
50 #include "main.h" // For g_settings
52 #include "tile.h" // For TextureSource
53 #include "logoutputbuffer.h"
55 #include "quicktune_shortcutter.h"
56 #include "clientmap.h"
60 #include "sound_openal.h"
62 #include "event_manager.h"
66 Setting this to 1 enables a special camera mode that forces
67 the renderers to think that the camera statically points from
68 the starting place to a static direction.
70 This allows one to move around with the player and see what
71 is actually drawn behind solid things and behind the player.
73 #define FIELD_OF_VIEW_TEST 0
80 struct TextDestChat : public TextDest
82 TextDestChat(Client *client)
86 void gotText(std::wstring text)
88 m_client->typeChatMessage(text);
94 struct TextDestNodeMetadata : public TextDest
96 TextDestNodeMetadata(v3s16 p, Client *client)
101 void gotText(std::wstring text)
103 std::string ntext = wide_to_narrow(text);
104 infostream<<"Changing text of a sign node: "
106 m_client->sendSignNodeText(m_p, ntext);
113 /* Respawn menu callback */
115 class MainRespawnInitiator: public IRespawnInitiator
118 MainRespawnInitiator(bool *active, Client *client):
119 m_active(active), m_client(client)
126 m_client->sendRespawn();
136 void draw_hotbar(video::IVideoDriver *driver, gui::IGUIFont *font,
138 v2s32 centerlowerpos, s32 imgsize, s32 itemcount,
139 Inventory *inventory, s32 halfheartcount, u16 playeritem)
141 InventoryList *mainlist = inventory->getList("main");
144 errorstream<<"draw_hotbar(): mainlist == NULL"<<std::endl;
148 s32 padding = imgsize/12;
149 //s32 height = imgsize + padding*2;
150 s32 width = itemcount*(imgsize+padding*2);
152 // Position of upper left corner of bar
153 v2s32 pos = centerlowerpos - v2s32(width/2, imgsize+padding*2);
155 // Draw background color
156 /*core::rect<s32> barrect(0,0,width,height);
158 video::SColor bgcolor(255,128,128,128);
159 driver->draw2DRectangle(bgcolor, barrect, NULL);*/
161 core::rect<s32> imgrect(0,0,imgsize,imgsize);
163 for(s32 i=0; i<itemcount; i++)
165 const ItemStack &item = mainlist->getItem(i);
167 core::rect<s32> rect = imgrect + pos
168 + v2s32(padding+i*(imgsize+padding*2), padding);
172 video::SColor c_outside(255,255,0,0);
173 //video::SColor c_outside(255,0,0,0);
174 //video::SColor c_inside(255,192,192,192);
175 s32 x1 = rect.UpperLeftCorner.X;
176 s32 y1 = rect.UpperLeftCorner.Y;
177 s32 x2 = rect.LowerRightCorner.X;
178 s32 y2 = rect.LowerRightCorner.Y;
179 // Black base borders
180 driver->draw2DRectangle(c_outside,
182 v2s32(x1 - padding, y1 - padding),
183 v2s32(x2 + padding, y1)
185 driver->draw2DRectangle(c_outside,
187 v2s32(x1 - padding, y2),
188 v2s32(x2 + padding, y2 + padding)
190 driver->draw2DRectangle(c_outside,
192 v2s32(x1 - padding, y1),
195 driver->draw2DRectangle(c_outside,
198 v2s32(x2 + padding, y2)
200 /*// Light inside borders
201 driver->draw2DRectangle(c_inside,
203 v2s32(x1 - padding/2, y1 - padding/2),
204 v2s32(x2 + padding/2, y1)
206 driver->draw2DRectangle(c_inside,
208 v2s32(x1 - padding/2, y2),
209 v2s32(x2 + padding/2, y2 + padding/2)
211 driver->draw2DRectangle(c_inside,
213 v2s32(x1 - padding/2, y1),
216 driver->draw2DRectangle(c_inside,
219 v2s32(x2 + padding/2, y2)
224 video::SColor bgcolor2(128,0,0,0);
225 driver->draw2DRectangle(bgcolor2, rect, NULL);
226 drawItemStack(driver, font, item, rect, NULL, gamedef);
232 video::ITexture *heart_texture =
233 gamedef->getTextureSource()->getTextureRaw("heart.png");
236 v2s32 p = pos + v2s32(0, -20);
237 for(s32 i=0; i<halfheartcount/2; i++)
239 const video::SColor color(255,255,255,255);
240 const video::SColor colors[] = {color,color,color,color};
241 core::rect<s32> rect(0,0,16,16);
243 driver->draw2DImage(heart_texture, rect,
244 core::rect<s32>(core::position2d<s32>(0,0),
245 core::dimension2di(heart_texture->getOriginalSize())),
249 if(halfheartcount % 2 == 1)
251 const video::SColor color(255,255,255,255);
252 const video::SColor colors[] = {color,color,color,color};
253 core::rect<s32> rect(0,0,16/2,16);
255 core::dimension2di srcd(heart_texture->getOriginalSize());
257 driver->draw2DImage(heart_texture, rect,
258 core::rect<s32>(core::position2d<s32>(0,0), srcd),
266 Check if a node is pointable
268 inline bool isPointableNode(const MapNode& n,
269 Client *client, bool liquids_pointable)
271 const ContentFeatures &features = client->getNodeDefManager()->get(n);
272 return features.pointable ||
273 (liquids_pointable && features.isLiquid());
277 Find what the player is pointing at
279 PointedThing getPointedThing(Client *client, v3f player_position,
280 v3f camera_direction, v3f camera_position,
281 core::line3d<f32> shootline, f32 d,
282 bool liquids_pointable,
283 bool look_for_object,
284 core::aabbox3d<f32> &hilightbox,
285 bool &should_show_hilightbox,
286 ClientActiveObject *&selected_object)
290 hilightbox = core::aabbox3d<f32>(0,0,0,0,0,0);
291 should_show_hilightbox = false;
292 selected_object = NULL;
294 INodeDefManager *nodedef = client->getNodeDefManager();
295 ClientMap &map = client->getEnv().getClientMap();
297 // First try to find a pointed at active object
300 selected_object = client->getSelectedActiveObject(d*BS,
301 camera_position, shootline);
303 if(selected_object != NULL)
305 core::aabbox3d<f32> *selection_box
306 = selected_object->getSelectionBox();
307 // Box should exist because object was returned in the
309 assert(selection_box);
311 v3f pos = selected_object->getPosition();
313 hilightbox = core::aabbox3d<f32>(
314 selection_box->MinEdge + pos,
315 selection_box->MaxEdge + pos
318 should_show_hilightbox = selected_object->doShowSelectionBox();
320 result.type = POINTEDTHING_OBJECT;
321 result.object_id = selected_object->getId();
325 // That didn't work, try to find a pointed at node
327 f32 mindistance = BS * 1001;
329 v3s16 pos_i = floatToInt(player_position, BS);
331 /*infostream<<"pos_i=("<<pos_i.X<<","<<pos_i.Y<<","<<pos_i.Z<<")"
335 s16 ystart = pos_i.Y + 0 - (camera_direction.Y<0 ? a : 1);
336 s16 zstart = pos_i.Z - (camera_direction.Z<0 ? a : 1);
337 s16 xstart = pos_i.X - (camera_direction.X<0 ? a : 1);
338 s16 yend = pos_i.Y + 1 + (camera_direction.Y>0 ? a : 1);
339 s16 zend = pos_i.Z + (camera_direction.Z>0 ? a : 1);
340 s16 xend = pos_i.X + (camera_direction.X>0 ? a : 1);
342 for(s16 y = ystart; y <= yend; y++)
343 for(s16 z = zstart; z <= zend; z++)
344 for(s16 x = xstart; x <= xend; x++)
349 n = map.getNode(v3s16(x,y,z));
351 catch(InvalidPositionException &e)
355 if(!isPointableNode(n, client, liquids_pointable))
359 v3f npf = intToFloat(np, BS);
364 v3s16(0,0,1), // back
366 v3s16(1,0,0), // right
367 v3s16(0,0,-1), // front
368 v3s16(0,-1,0), // bottom
369 v3s16(-1,0,0), // left
372 const ContentFeatures &f = nodedef->get(n);
374 if(f.selection_box.type == NODEBOX_FIXED)
376 core::aabbox3d<f32> box = f.selection_box.fixed;
380 v3s16 facedirs[6] = {
389 core::aabbox3d<f32> faceboxes[6] = {
392 box.MinEdge.X, box.MinEdge.Y, box.MinEdge.Z,
393 box.MinEdge.X+d, box.MaxEdge.Y, box.MaxEdge.Z
397 box.MaxEdge.X-d, box.MinEdge.Y, box.MinEdge.Z,
398 box.MaxEdge.X, box.MaxEdge.Y, box.MaxEdge.Z
402 box.MinEdge.X, box.MinEdge.Y, box.MinEdge.Z,
403 box.MaxEdge.X, box.MinEdge.Y+d, box.MaxEdge.Z
407 box.MinEdge.X, box.MaxEdge.Y-d, box.MinEdge.Z,
408 box.MaxEdge.X, box.MaxEdge.Y, box.MaxEdge.Z
412 box.MinEdge.X, box.MinEdge.Y, box.MinEdge.Z,
413 box.MaxEdge.X, box.MaxEdge.Y, box.MinEdge.Z+d
417 box.MinEdge.X, box.MinEdge.Y, box.MaxEdge.Z-d,
418 box.MaxEdge.X, box.MaxEdge.Y, box.MaxEdge.Z
422 for(u16 i=0; i<6; i++)
424 v3f facedir_f(facedirs[i].X, facedirs[i].Y, facedirs[i].Z);
425 v3f centerpoint = npf + facedir_f * BS/2;
426 f32 distance = (centerpoint - camera_position).getLength();
427 if(distance >= mindistance)
429 if(!faceboxes[i].intersectsWithLine(shootline))
431 result.type = POINTEDTHING_NODE;
432 result.node_undersurface = np;
433 result.node_abovesurface = np+facedirs[i];
434 mindistance = distance;
436 should_show_hilightbox = true;
439 else if(f.selection_box.type == NODEBOX_WALLMOUNTED)
441 v3s16 dir = n.getWallMountedDir(nodedef);
442 v3f dir_f = v3f(dir.X, dir.Y, dir.Z);
443 dir_f *= BS/2 - BS/6 - BS/20;
444 v3f cpf = npf + dir_f;
445 f32 distance = (cpf - camera_position).getLength();
447 core::aabbox3d<f32> box;
450 if(dir == v3s16(0,1,0)){
451 box = f.selection_box.wall_top;
454 else if(dir == v3s16(0,-1,0)){
455 box = f.selection_box.wall_bottom;
461 f.selection_box.wall_side.MinEdge,
462 f.selection_box.wall_side.MaxEdge
465 for(s32 i=0; i<2; i++)
467 if(dir == v3s16(-1,0,0))
468 vertices[i].rotateXZBy(0);
469 if(dir == v3s16(1,0,0))
470 vertices[i].rotateXZBy(180);
471 if(dir == v3s16(0,0,-1))
472 vertices[i].rotateXZBy(90);
473 if(dir == v3s16(0,0,1))
474 vertices[i].rotateXZBy(-90);
477 box = core::aabbox3d<f32>(vertices[0]);
478 box.addInternalPoint(vertices[1]);
484 if(distance < mindistance)
486 if(box.intersectsWithLine(shootline))
488 result.type = POINTEDTHING_NODE;
489 result.node_undersurface = np;
490 result.node_abovesurface = np;
491 mindistance = distance;
493 should_show_hilightbox = true;
497 else // NODEBOX_REGULAR
499 for(u16 i=0; i<6; i++)
501 v3f dir_f = v3f(dirs[i].X,
502 dirs[i].Y, dirs[i].Z);
503 v3f centerpoint = npf + dir_f * BS/2;
505 (centerpoint - camera_position).getLength();
507 if(distance < mindistance)
509 core::CMatrix4<f32> m;
510 m.buildRotateFromTo(v3f(0,0,1), dir_f);
512 // This is the back face
514 v3f(BS/2, BS/2, BS/2),
515 v3f(-BS/2, -BS/2, BS/2+d)
518 for(u16 j=0; j<2; j++)
520 m.rotateVect(corners[j]);
524 core::aabbox3d<f32> facebox(corners[0]);
525 facebox.addInternalPoint(corners[1]);
527 if(facebox.intersectsWithLine(shootline))
529 result.type = POINTEDTHING_NODE;
530 result.node_undersurface = np;
531 result.node_abovesurface = np + dirs[i];
532 mindistance = distance;
534 //hilightbox = facebox;
536 const float d = 0.502;
537 core::aabbox3d<f32> nodebox
538 (-BS*d, -BS*d, -BS*d, BS*d, BS*d, BS*d);
539 v3f nodepos_f = intToFloat(np, BS);
540 nodebox.MinEdge += nodepos_f;
541 nodebox.MaxEdge += nodepos_f;
542 hilightbox = nodebox;
543 should_show_hilightbox = true;
545 } // if distance < mindistance
554 Draws a screen with a single text on it.
555 Text will be removed when the screen is drawn the next time.
557 /*gui::IGUIStaticText **/
558 void draw_load_screen(const std::wstring &text,
559 video::IVideoDriver* driver, gui::IGUIFont* font)
561 v2u32 screensize = driver->getScreenSize();
562 const wchar_t *loadingtext = text.c_str();
563 core::vector2d<u32> textsize_u = font->getDimension(loadingtext);
564 core::vector2d<s32> textsize(textsize_u.X,textsize_u.Y);
565 core::vector2d<s32> center(screensize.X/2, screensize.Y/2);
566 core::rect<s32> textrect(center - textsize/2, center + textsize/2);
568 gui::IGUIStaticText *guitext = guienv->addStaticText(
569 loadingtext, textrect, false, false);
570 guitext->setTextAlignment(gui::EGUIA_CENTER, gui::EGUIA_UPPERLEFT);
572 driver->beginScene(true, true, video::SColor(255,0,0,0));
581 /* Profiler display */
583 void update_profiler_gui(gui::IGUIStaticText *guitext_profiler,
584 gui::IGUIFont *font, u32 text_height,
585 u32 show_profiler, u32 show_profiler_max)
587 if(show_profiler == 0)
589 guitext_profiler->setVisible(false);
594 std::ostringstream os(std::ios_base::binary);
595 g_profiler->printPage(os, show_profiler, show_profiler_max);
596 std::wstring text = narrow_to_wide(os.str());
597 guitext_profiler->setText(text.c_str());
598 guitext_profiler->setVisible(true);
600 s32 w = font->getDimension(text.c_str()).Width;
603 core::rect<s32> rect(6, 4+(text_height+5)*2, 12+w,
604 8+(text_height+5)*2 +
605 font->getDimension(text.c_str()).Height);
606 guitext_profiler->setRelativePosition(rect);
607 guitext_profiler->setVisible(true);
615 Profiler::GraphValues values;
621 Meta(float initial=0, video::SColor color=
622 video::SColor(255,255,255,255)):
628 std::list<Piece> m_log;
636 void put(const Profiler::GraphValues &values)
639 piece.values = values;
640 m_log.push_back(piece);
641 while(m_log.size() > m_log_max_size)
642 m_log.erase(m_log.begin());
645 void draw(s32 x_left, s32 y_bottom, video::IVideoDriver *driver,
646 gui::IGUIFont* font) const
648 std::map<std::string, Meta> m_meta;
649 for(std::list<Piece>::const_iterator k = m_log.begin();
650 k != m_log.end(); k++)
652 const Piece &piece = *k;
653 for(Profiler::GraphValues::const_iterator i = piece.values.begin();
654 i != piece.values.end(); i++){
655 const std::string &id = i->first;
656 const float &value = i->second;
657 std::map<std::string, Meta>::iterator j =
659 if(j == m_meta.end()){
660 m_meta[id] = Meta(value);
663 if(value < j->second.min)
664 j->second.min = value;
665 if(value > j->second.max)
666 j->second.max = value;
671 static const video::SColor usable_colors[] = {
672 video::SColor(255,255,100,100),
673 video::SColor(255,90,225,90),
674 video::SColor(255,100,100,255),
675 video::SColor(255,255,150,50),
676 video::SColor(255,220,220,100)
678 static const u32 usable_colors_count =
679 sizeof(usable_colors) / sizeof(*usable_colors);
680 u32 next_color_i = 0;
681 for(std::map<std::string, Meta>::iterator i = m_meta.begin();
682 i != m_meta.end(); i++){
683 Meta &meta = i->second;
684 video::SColor color(255,200,200,200);
685 if(next_color_i < usable_colors_count)
686 color = usable_colors[next_color_i++];
691 s32 textx = x_left + m_log_max_size + 15;
692 s32 textx2 = textx + 200 - 15;
696 u32 num_graphs = m_meta.size();
697 core::rect<s32> rect(x_left, y_bottom - num_graphs*graphh,
699 video::SColor bgcolor(120,0,0,0);
700 driver->draw2DRectangle(bgcolor, rect, NULL);
704 for(std::map<std::string, Meta>::const_iterator i = m_meta.begin();
705 i != m_meta.end(); i++){
706 const std::string &id = i->first;
707 const Meta &meta = i->second;
709 s32 y = y_bottom - meta_i * 50;
710 float show_min = meta.min;
711 float show_max = meta.max;
712 if(show_min >= -0.0001 && show_max >= -0.0001){
713 if(show_min <= show_max * 0.5)
718 snprintf(buf, 10, "%.3g", show_max);
719 font->draw(narrow_to_wide(buf).c_str(),
720 core::rect<s32>(textx, y - graphh,
721 textx2, y - graphh + texth),
723 snprintf(buf, 10, "%.3g", show_min);
724 font->draw(narrow_to_wide(buf).c_str(),
725 core::rect<s32>(textx, y - texth,
728 font->draw(narrow_to_wide(id).c_str(),
729 core::rect<s32>(textx, y - graphh/2 - texth/2,
730 textx2, y - graphh/2 + texth/2),
733 s32 graph1h = graphh;
734 bool relativegraph = (show_min != 0 && show_min != show_max);
735 float lastscaledvalue = 0.0;
736 bool lastscaledvalue_exists = false;
737 for(std::list<Piece>::const_iterator j = m_log.begin();
738 j != m_log.end(); j++)
740 const Piece &piece = *j;
742 bool value_exists = false;
743 Profiler::GraphValues::const_iterator k =
744 piece.values.find(id);
745 if(k != piece.values.end()){
751 lastscaledvalue_exists = false;
754 float scaledvalue = 1.0;
755 if(show_max != show_min)
756 scaledvalue = (value - show_min) / (show_max - show_min);
757 if(scaledvalue == 1.0 && value == 0){
759 lastscaledvalue_exists = false;
763 if(lastscaledvalue_exists){
764 s32 ivalue1 = lastscaledvalue * graph1h;
765 s32 ivalue2 = scaledvalue * graph1h;
766 driver->draw2DLine(v2s32(x-1, graph1y - ivalue1),
767 v2s32(x, graph1y - ivalue2), meta.color);
769 lastscaledvalue = scaledvalue;
770 lastscaledvalue_exists = true;
772 s32 ivalue = scaledvalue * graph1h;
773 driver->draw2DLine(v2s32(x, graph1y),
774 v2s32(x, graph1y - ivalue), meta.color);
783 class NodeDugEvent: public MtEvent
789 NodeDugEvent(v3s16 p, MapNode n):
793 const char* getType() const
799 ISoundManager *m_sound;
800 INodeDefManager *m_ndef;
802 float m_player_step_timer;
804 SimpleSoundSpec m_player_step_sound;
805 SimpleSoundSpec m_player_leftpunch_sound;
806 SimpleSoundSpec m_player_rightpunch_sound;
808 SoundMaker(ISoundManager *sound, INodeDefManager *ndef):
811 m_player_step_timer(0)
815 void playPlayerStep()
817 if(m_player_step_timer <= 0 && m_player_step_sound.exists()){
818 m_player_step_timer = 0.03;
819 m_sound->playSound(m_player_step_sound, false);
823 static void viewBobbingStep(MtEvent *e, void *data)
825 SoundMaker *sm = (SoundMaker*)data;
826 sm->playPlayerStep();
829 static void playerRegainGround(MtEvent *e, void *data)
831 SoundMaker *sm = (SoundMaker*)data;
832 sm->playPlayerStep();
835 static void playerJump(MtEvent *e, void *data)
837 //SoundMaker *sm = (SoundMaker*)data;
840 static void cameraPunchLeft(MtEvent *e, void *data)
842 SoundMaker *sm = (SoundMaker*)data;
843 sm->m_sound->playSound(sm->m_player_leftpunch_sound, false);
846 static void cameraPunchRight(MtEvent *e, void *data)
848 SoundMaker *sm = (SoundMaker*)data;
849 sm->m_sound->playSound(sm->m_player_rightpunch_sound, false);
852 static void nodeDug(MtEvent *e, void *data)
854 SoundMaker *sm = (SoundMaker*)data;
855 NodeDugEvent *nde = (NodeDugEvent*)e;
856 sm->m_sound->playSound(sm->m_ndef->get(nde->n).sound_dug, false);
859 void registerReceiver(MtEventManager *mgr)
861 mgr->reg("ViewBobbingStep", SoundMaker::viewBobbingStep, this);
862 mgr->reg("PlayerRegainGround", SoundMaker::playerRegainGround, this);
863 mgr->reg("PlayerJump", SoundMaker::playerJump, this);
864 mgr->reg("CameraPunchLeft", SoundMaker::cameraPunchLeft, this);
865 mgr->reg("CameraPunchRight", SoundMaker::cameraPunchRight, this);
866 mgr->reg("NodeDug", SoundMaker::nodeDug, this);
869 void step(float dtime)
871 m_player_step_timer -= dtime;
875 // Locally stored sounds don't need to be preloaded because of this
876 class GameOnDemandSoundFetcher: public OnDemandSoundFetcher
878 std::set<std::string> m_fetched;
881 void fetchSounds(const std::string &name,
882 std::set<std::string> &dst_paths,
883 std::set<std::vector<char> > &dst_datas)
885 if(m_fetched.count(name))
887 m_fetched.insert(name);
888 std::string base = porting::path_share + DIR_DELIM + "testsounds";
889 dst_paths.insert(base + DIR_DELIM + name + ".ogg");
890 dst_paths.insert(base + DIR_DELIM + name + "1.ogg");
891 dst_paths.insert(base + DIR_DELIM + name + "2.ogg");
892 dst_paths.insert(base + DIR_DELIM + name + "3.ogg");
893 dst_paths.insert(base + DIR_DELIM + name + "4.ogg");
894 dst_paths.insert(base + DIR_DELIM + name + "5.ogg");
895 dst_paths.insert(base + DIR_DELIM + name + "6.ogg");
896 dst_paths.insert(base + DIR_DELIM + name + "7.ogg");
897 dst_paths.insert(base + DIR_DELIM + name + "8.ogg");
898 dst_paths.insert(base + DIR_DELIM + name + "9.ogg");
906 IrrlichtDevice *device,
909 std::string playername,
910 std::string password,
911 std::string address, // If "", local server is used
913 std::wstring &error_message,
914 std::string configpath,
915 ChatBackend &chat_backend,
916 const SubgameSpec &gamespec, // Used for local game,
917 bool simple_singleplayer_mode
920 video::IVideoDriver* driver = device->getVideoDriver();
921 scene::ISceneManager* smgr = device->getSceneManager();
923 // Calculate text height using the font
924 u32 text_height = font->getDimension(L"Random test string").Height;
926 v2u32 screensize(0,0);
927 v2u32 last_screensize(0,0);
928 screensize = driver->getScreenSize();
930 const s32 hotbar_itemcount = 8;
931 //const s32 hotbar_imagesize = 36;
932 //const s32 hotbar_imagesize = 64;
933 s32 hotbar_imagesize = 48;
936 Draw "Loading" screen
939 draw_load_screen(L"Loading...", driver, font);
941 // Create texture source
942 IWritableTextureSource *tsrc = createTextureSource(device);
944 // These will be filled by data received from the server
945 // Create item definition manager
946 IWritableItemDefManager *itemdef = createItemDefManager();
947 // Create node definition manager
948 IWritableNodeDefManager *nodedef = createNodeDefManager();
950 // Sound fetcher (useful when testing)
951 GameOnDemandSoundFetcher soundfetcher;
954 ISoundManager *sound = NULL;
955 bool sound_is_dummy = false;
957 infostream<<"Attempting to use OpenAL audio"<<std::endl;
958 sound = createOpenALSoundManager(&soundfetcher);
960 infostream<<"Failed to initialize OpenAL audio"<<std::endl;
963 infostream<<"Using dummy audio."<<std::endl;
964 sound = &dummySoundManager;
965 sound_is_dummy = true;
969 EventManager eventmgr;
972 SoundMaker soundmaker(sound, nodedef);
973 soundmaker.registerReceiver(&eventmgr);
977 sound->loadSound("default_grass_footstep", porting::path_share + DIR_DELIM
978 + "sounds" + DIR_DELIM + "default_grass_walk1.ogg");
979 sound->loadSound("default_grass_footstep", porting::path_share + DIR_DELIM
980 + "sounds" + DIR_DELIM + "default_grass_walk2.ogg");
981 sound->loadSound("default_grass_footstep", porting::path_share + DIR_DELIM
982 + "sounds" + DIR_DELIM + "default_grass_walk3.ogg");
984 sound->loadSound("default_dig_crumbly", porting::path_share + DIR_DELIM
985 + "sounds" + DIR_DELIM + "default_dig_crumbly1.ogg");
986 sound->loadSound("default_dig_crumbly", porting::path_share + DIR_DELIM
987 + "sounds" + DIR_DELIM + "default_dig_crumbly2.ogg");
989 sound->loadSound("default_dig_cracky", porting::path_share + DIR_DELIM
990 + "sounds" + DIR_DELIM + "default_dig_cracky1.ogg");
992 sound->loadSound("default_place_node", porting::path_share + DIR_DELIM
993 + "sounds" + DIR_DELIM + "default_place_node1.ogg");
994 sound->loadSound("default_place_node", porting::path_share + DIR_DELIM
995 + "sounds" + DIR_DELIM + "default_place_node2.ogg");
996 sound->loadSound("default_place_node", porting::path_share + DIR_DELIM
997 + "sounds" + DIR_DELIM + "default_place_node3.ogg");
1000 // Add chat log output for errors to be shown in chat
1001 LogOutputBuffer chat_log_error_buf(LMT_ERROR);
1003 // Create UI for modifying quicktune values
1004 QuicktuneShortcutter quicktune;
1008 SharedPtr will delete it when it goes out of scope.
1010 SharedPtr<Server> server;
1012 draw_load_screen(L"Creating server...", driver, font);
1013 infostream<<"Creating server"<<std::endl;
1014 server = new Server(map_dir, configpath, gamespec,
1015 simple_singleplayer_mode);
1016 server->start(port);
1019 do{ // Client scope (breakable do-while(0))
1025 draw_load_screen(L"Creating client...", driver, font);
1026 infostream<<"Creating client"<<std::endl;
1028 MapDrawControl draw_control;
1030 Client client(device, playername.c_str(), password, draw_control,
1031 tsrc, itemdef, nodedef, sound, &eventmgr);
1033 // Client acts as our GameDef
1034 IGameDef *gamedef = &client;
1036 draw_load_screen(L"Resolving address...", driver, font);
1037 Address connect_address(0,0,0,0, port);
1040 //connect_address.Resolve("localhost");
1041 connect_address.setAddress(127,0,0,1);
1043 connect_address.Resolve(address.c_str());
1045 catch(ResolveError &e)
1047 error_message = L"Couldn't resolve address";
1048 errorstream<<wide_to_narrow(error_message)<<std::endl;
1049 // Break out of client scope
1054 Attempt to connect to the server
1057 infostream<<"Connecting to server at ";
1058 connect_address.print(&infostream);
1059 infostream<<std::endl;
1060 client.connect(connect_address);
1063 Wait for server to accept connection
1065 bool could_connect = false;
1066 bool connect_aborted = false;
1068 float frametime = 0.033;
1069 float time_counter = 0.0;
1071 while(device->run())
1073 // Update client and server
1074 client.step(frametime);
1076 server->step(frametime);
1079 if(client.connectedAndInitialized()){
1080 could_connect = true;
1084 if(client.accessDenied()){
1085 error_message = L"Access denied. Reason: "
1086 +client.accessDeniedReason();
1087 errorstream<<wide_to_narrow(error_message)<<std::endl;
1090 if(input->wasKeyDown(EscapeKey)){
1091 connect_aborted = true;
1092 infostream<<"Connect aborted [Escape]"<<std::endl;
1097 std::wostringstream ss;
1098 ss<<L"Connecting to server... (press Escape to cancel)\n";
1099 std::wstring animation = L"/-\\|";
1100 ss<<animation[(int)(time_counter/0.2)%4];
1101 draw_load_screen(ss.str(), driver, font);
1104 sleep_ms(1000*frametime);
1105 time_counter += frametime;
1108 catch(con::PeerNotFoundException &e)
1112 Handle failure to connect
1115 if(error_message == L"" && !connect_aborted){
1116 error_message = L"Connection failed";
1117 errorstream<<wide_to_narrow(error_message)<<std::endl;
1119 // Break out of client scope
1124 Wait until content has been received
1126 bool got_content = false;
1127 bool content_aborted = false;
1129 float frametime = 0.033;
1130 float time_counter = 0.0;
1132 while(device->run())
1134 // Update client and server
1135 client.step(frametime);
1137 server->step(frametime);
1140 if(client.texturesReceived() &&
1141 client.itemdefReceived() &&
1142 client.nodedefReceived()){
1147 if(!client.connectedAndInitialized()){
1148 error_message = L"Client disconnected";
1149 errorstream<<wide_to_narrow(error_message)<<std::endl;
1152 if(input->wasKeyDown(EscapeKey)){
1153 content_aborted = true;
1154 infostream<<"Connect aborted [Escape]"<<std::endl;
1159 std::wostringstream ss;
1160 ss<<L"Waiting content... (press Escape to cancel)\n";
1162 ss<<(client.itemdefReceived()?L"[X]":L"[ ]");
1163 ss<<L" Item definitions\n";
1164 ss<<(client.nodedefReceived()?L"[X]":L"[ ]");
1165 ss<<L" Node definitions\n";
1166 ss<<L"["<<(int)(client.mediaReceiveProgress()*100+0.5)<<L"%] ";
1169 draw_load_screen(ss.str(), driver, font);
1172 sleep_ms(1000*frametime);
1173 time_counter += frametime;
1178 if(error_message == L"" && !content_aborted){
1179 error_message = L"Something failed";
1180 errorstream<<wide_to_narrow(error_message)<<std::endl;
1182 // Break out of client scope
1187 After all content has been received:
1188 Update cached textures, meshes and materials
1190 client.afterContentReceived();
1193 Create the camera node
1195 Camera camera(smgr, draw_control, gamedef);
1196 if (!camera.successfullyCreated(error_message))
1199 f32 camera_yaw = 0; // "right/left"
1200 f32 camera_pitch = 0; // "up/down"
1206 Clouds *clouds = NULL;
1207 if(g_settings->getBool("enable_clouds"))
1209 clouds = new Clouds(smgr->getRootSceneNode(), smgr, -1, time(0));
1217 sky = new Sky(smgr->getRootSceneNode(), smgr, -1);
1223 FarMesh *farmesh = NULL;
1224 if(g_settings->getBool("enable_farmesh"))
1226 farmesh = new FarMesh(smgr->getRootSceneNode(), smgr, -1, client.getMapSeed(), &client);
1230 A copy of the local inventory
1232 Inventory local_inventory(itemdef);
1238 // First line of debug text
1239 gui::IGUIStaticText *guitext = guienv->addStaticText(
1241 core::rect<s32>(5, 5, 795, 5+text_height),
1243 // Second line of debug text
1244 gui::IGUIStaticText *guitext2 = guienv->addStaticText(
1246 core::rect<s32>(5, 5+(text_height+5)*1, 795, (5+text_height)*2),
1248 // At the middle of the screen
1249 // Object infos are shown in this
1250 gui::IGUIStaticText *guitext_info = guienv->addStaticText(
1252 core::rect<s32>(0,0,400,text_height*5+5) + v2s32(100,200),
1255 // Status text (displays info when showing and hiding GUI stuff, etc.)
1256 gui::IGUIStaticText *guitext_status = guienv->addStaticText(
1258 core::rect<s32>(0,0,0,0),
1260 guitext_status->setVisible(false);
1262 std::wstring statustext;
1263 float statustext_time = 0;
1266 gui::IGUIStaticText *guitext_chat = guienv->addStaticText(
1268 core::rect<s32>(0,0,0,0),
1269 //false, false); // Disable word wrap as of now
1271 // Remove stale "recent" chat messages from previous connections
1272 chat_backend.clearRecentChat();
1273 // Chat backend and console
1274 GUIChatConsole *gui_chat_console = new GUIChatConsole(guienv, guienv->getRootGUIElement(), -1, &chat_backend, &client);
1276 // Profiler text (size is updated when text is updated)
1277 gui::IGUIStaticText *guitext_profiler = guienv->addStaticText(
1279 core::rect<s32>(0,0,0,0),
1281 guitext_profiler->setBackgroundColor(video::SColor(120,0,0,0));
1282 guitext_profiler->setVisible(false);
1285 Some statistics are collected in these
1288 u32 beginscenetime = 0;
1290 u32 endscenetime = 0;
1292 float recent_turn_speed = 0.0;
1294 ProfilerGraph graph;
1295 // Initially clear the profiler
1296 Profiler::GraphValues dummyvalues;
1297 g_profiler->graphGet(dummyvalues);
1299 float nodig_delay_timer = 0.0;
1300 float dig_time = 0.0;
1302 PointedThing pointed_old;
1303 bool digging = false;
1304 bool ldown_for_dig = false;
1306 float damage_flash_timer = 0;
1307 s16 farmesh_range = 20*MAP_BLOCKSIZE;
1309 const float object_hit_delay = 0.2;
1310 float object_hit_delay_timer = 0.0;
1311 float time_from_last_punch = 10;
1313 bool invert_mouse = g_settings->getBool("invert_mouse");
1315 bool respawn_menu_active = false;
1316 bool update_wielded_item_trigger = false;
1318 bool show_hud = true;
1319 bool show_chat = true;
1320 bool force_fog_off = false;
1321 bool disable_camera_update = false;
1322 bool show_debug = g_settings->getBool("show_debug");
1323 bool show_profiler_graph = false;
1324 u32 show_profiler = 0;
1325 u32 show_profiler_max = 3; // Number of pages
1327 float time_of_day = 0;
1328 float time_of_day_smooth = 0;
1334 bool first_loop_after_window_activation = true;
1336 // TODO: Convert the static interval timers to these
1337 // Interval limiter for profiler
1338 IntervalLimiter m_profiler_interval;
1340 // Time is in milliseconds
1341 // NOTE: getRealTime() causes strange problems in wine (imprecision?)
1342 // NOTE: So we have to use getTime() and call run()s between them
1343 u32 lasttime = device->getTimer()->getTime();
1347 if(device->run() == false || kill == true)
1350 // Time of frame without fps limit
1354 // not using getRealTime is necessary for wine
1355 u32 time = device->getTimer()->getTime();
1357 busytime_u32 = time - lasttime;
1360 busytime = busytime_u32 / 1000.0;
1363 g_profiler->graphAdd("mainloop_other", busytime - (float)drawtime/1000.0f);
1365 // Necessary for device->getTimer()->getTime()
1373 float fps_max = g_settings->getFloat("fps_max");
1374 u32 frametime_min = 1000./fps_max;
1376 if(busytime_u32 < frametime_min)
1378 u32 sleeptime = frametime_min - busytime_u32;
1379 device->sleep(sleeptime);
1380 g_profiler->graphAdd("mainloop_sleep", (float)sleeptime/1000.0f);
1384 // Necessary for device->getTimer()->getTime()
1388 Time difference calculation
1390 f32 dtime; // in seconds
1392 u32 time = device->getTimer()->getTime();
1394 dtime = (time - lasttime) / 1000.0;
1399 g_profiler->graphAdd("mainloop_dtime", dtime);
1403 if(nodig_delay_timer >= 0)
1404 nodig_delay_timer -= dtime;
1405 if(object_hit_delay_timer >= 0)
1406 object_hit_delay_timer -= dtime;
1407 time_from_last_punch += dtime;
1409 g_profiler->add("Elapsed time", dtime);
1410 g_profiler->avg("FPS", 1./dtime);
1413 Time average and jitter calculation
1416 static f32 dtime_avg1 = 0.0;
1417 dtime_avg1 = dtime_avg1 * 0.96 + dtime * 0.04;
1418 f32 dtime_jitter1 = dtime - dtime_avg1;
1420 static f32 dtime_jitter1_max_sample = 0.0;
1421 static f32 dtime_jitter1_max_fraction = 0.0;
1423 static f32 jitter1_max = 0.0;
1424 static f32 counter = 0.0;
1425 if(dtime_jitter1 > jitter1_max)
1426 jitter1_max = dtime_jitter1;
1431 dtime_jitter1_max_sample = jitter1_max;
1432 dtime_jitter1_max_fraction
1433 = dtime_jitter1_max_sample / (dtime_avg1+0.001);
1439 Busytime average and jitter calculation
1442 static f32 busytime_avg1 = 0.0;
1443 busytime_avg1 = busytime_avg1 * 0.98 + busytime * 0.02;
1444 f32 busytime_jitter1 = busytime - busytime_avg1;
1446 static f32 busytime_jitter1_max_sample = 0.0;
1447 static f32 busytime_jitter1_min_sample = 0.0;
1449 static f32 jitter1_max = 0.0;
1450 static f32 jitter1_min = 0.0;
1451 static f32 counter = 0.0;
1452 if(busytime_jitter1 > jitter1_max)
1453 jitter1_max = busytime_jitter1;
1454 if(busytime_jitter1 < jitter1_min)
1455 jitter1_min = busytime_jitter1;
1459 busytime_jitter1_max_sample = jitter1_max;
1460 busytime_jitter1_min_sample = jitter1_min;
1467 Handle miscellaneous stuff
1470 if(client.accessDenied())
1472 error_message = L"Access denied. Reason: "
1473 +client.accessDeniedReason();
1474 errorstream<<wide_to_narrow(error_message)<<std::endl;
1478 if(g_gamecallback->disconnect_requested)
1480 g_gamecallback->disconnect_requested = false;
1484 if(g_gamecallback->changepassword_requested)
1486 (new GUIPasswordChange(guienv, guiroot, -1,
1487 &g_menumgr, &client))->drop();
1488 g_gamecallback->changepassword_requested = false;
1492 Process TextureSource's queue
1494 tsrc->processQueue();
1499 last_screensize = screensize;
1500 screensize = driver->getScreenSize();
1501 v2s32 displaycenter(screensize.X/2,screensize.Y/2);
1502 //bool screensize_changed = screensize != last_screensize;
1505 if(screensize.Y <= 800)
1506 hotbar_imagesize = 32;
1507 else if(screensize.Y <= 1280)
1508 hotbar_imagesize = 48;
1510 hotbar_imagesize = 64;
1512 // Hilight boxes collected during the loop and displayed
1513 core::list< core::aabbox3d<f32> > hilightboxes;
1516 std::wstring infotext;
1519 Debug info for client
1522 static float counter = 0.0;
1527 client.printDebugInfo(infostream);
1534 float profiler_print_interval =
1535 g_settings->getFloat("profiler_print_interval");
1536 bool print_to_log = true;
1537 if(profiler_print_interval == 0){
1538 print_to_log = false;
1539 profiler_print_interval = 5;
1541 if(m_profiler_interval.step(dtime, profiler_print_interval))
1544 infostream<<"Profiler:"<<std::endl;
1545 g_profiler->print(infostream);
1548 update_profiler_gui(guitext_profiler, font, text_height,
1549 show_profiler, show_profiler_max);
1551 g_profiler->clear();
1555 Direct handling of user input
1558 // Reset input if window not active or some menu is active
1559 if(device->isWindowActive() == false
1560 || noMenuActive() == false
1561 || guienv->hasFocus(gui_chat_console))
1566 // Input handler step() (used by the random input generator)
1570 Launch menus and trigger stuff according to keys
1572 if(input->wasKeyDown(getKeySetting("keymap_drop")))
1574 // drop selected item
1575 IDropAction *a = new IDropAction();
1577 a->from_inv.setCurrentPlayer();
1578 a->from_list = "main";
1579 a->from_i = client.getPlayerItem();
1580 client.inventoryAction(a);
1582 else if(input->wasKeyDown(getKeySetting("keymap_inventory")))
1584 infostream<<"the_game: "
1585 <<"Launching inventory"<<std::endl;
1587 GUIInventoryMenu *menu =
1588 new GUIInventoryMenu(guienv, guiroot, -1,
1589 &g_menumgr, v2s16(8,7),
1592 InventoryLocation inventoryloc;
1593 inventoryloc.setCurrentPlayer();
1595 core::array<GUIInventoryMenu::DrawSpec> draw_spec;
1596 draw_spec.push_back(GUIInventoryMenu::DrawSpec(
1597 "list", inventoryloc, "main",
1598 v2s32(0, 3), v2s32(8, 4)));
1599 draw_spec.push_back(GUIInventoryMenu::DrawSpec(
1600 "list", inventoryloc, "craft",
1601 v2s32(3, 0), v2s32(3, 3)));
1602 draw_spec.push_back(GUIInventoryMenu::DrawSpec(
1603 "list", inventoryloc, "craftpreview",
1604 v2s32(7, 1), v2s32(1, 1)));
1606 menu->setDrawSpec(draw_spec);
1610 else if(input->wasKeyDown(EscapeKey))
1612 infostream<<"the_game: "
1613 <<"Launching pause menu"<<std::endl;
1614 // It will delete itself by itself
1615 (new GUIPauseMenu(guienv, guiroot, -1, g_gamecallback,
1616 &g_menumgr, simple_singleplayer_mode))->drop();
1618 // Move mouse cursor on top of the disconnect button
1619 if(simple_singleplayer_mode)
1620 input->setMousePos(displaycenter.X, displaycenter.Y+0);
1622 input->setMousePos(displaycenter.X, displaycenter.Y+25);
1624 else if(input->wasKeyDown(getKeySetting("keymap_chat")))
1626 TextDest *dest = new TextDestChat(&client);
1628 (new GUITextInputMenu(guienv, guiroot, -1,
1632 else if(input->wasKeyDown(getKeySetting("keymap_cmd")))
1634 TextDest *dest = new TextDestChat(&client);
1636 (new GUITextInputMenu(guienv, guiroot, -1,
1640 else if(input->wasKeyDown(getKeySetting("keymap_console")))
1642 if (!gui_chat_console->isOpenInhibited())
1644 // Open up to over half of the screen
1645 gui_chat_console->openConsole(0.6);
1646 guienv->setFocus(gui_chat_console);
1649 else if(input->wasKeyDown(getKeySetting("keymap_freemove")))
1651 if(g_settings->getBool("free_move"))
1653 g_settings->set("free_move","false");
1654 statustext = L"free_move disabled";
1655 statustext_time = 0;
1659 g_settings->set("free_move","true");
1660 statustext = L"free_move enabled";
1661 statustext_time = 0;
1664 else if(input->wasKeyDown(getKeySetting("keymap_fastmove")))
1666 if(g_settings->getBool("fast_move"))
1668 g_settings->set("fast_move","false");
1669 statustext = L"fast_move disabled";
1670 statustext_time = 0;
1674 g_settings->set("fast_move","true");
1675 statustext = L"fast_move enabled";
1676 statustext_time = 0;
1679 else if(input->wasKeyDown(getKeySetting("keymap_screenshot")))
1681 irr::video::IImage* const image = driver->createScreenShot();
1683 irr::c8 filename[256];
1684 snprintf(filename, 256, "%s" DIR_DELIM "screenshot_%u.png",
1685 g_settings->get("screenshot_path").c_str(),
1686 device->getTimer()->getRealTime());
1687 if (driver->writeImageToFile(image, filename)) {
1688 std::wstringstream sstr;
1689 sstr<<"Saved screenshot to '"<<filename<<"'";
1690 infostream<<"Saved screenshot to '"<<filename<<"'"<<std::endl;
1691 statustext = sstr.str();
1692 statustext_time = 0;
1694 infostream<<"Failed to save screenshot '"<<filename<<"'"<<std::endl;
1699 else if(input->wasKeyDown(getKeySetting("keymap_toggle_hud")))
1701 show_hud = !show_hud;
1703 statustext = L"HUD shown";
1705 statustext = L"HUD hidden";
1706 statustext_time = 0;
1708 else if(input->wasKeyDown(getKeySetting("keymap_toggle_chat")))
1710 show_chat = !show_chat;
1712 statustext = L"Chat shown";
1714 statustext = L"Chat hidden";
1715 statustext_time = 0;
1717 else if(input->wasKeyDown(getKeySetting("keymap_toggle_force_fog_off")))
1719 force_fog_off = !force_fog_off;
1721 statustext = L"Fog disabled";
1723 statustext = L"Fog enabled";
1724 statustext_time = 0;
1726 else if(input->wasKeyDown(getKeySetting("keymap_toggle_update_camera")))
1728 disable_camera_update = !disable_camera_update;
1729 if(disable_camera_update)
1730 statustext = L"Camera update disabled";
1732 statustext = L"Camera update enabled";
1733 statustext_time = 0;
1735 else if(input->wasKeyDown(getKeySetting("keymap_toggle_debug")))
1737 // Initial / 3x toggle: Chat only
1738 // 1x toggle: Debug text with chat
1739 // 2x toggle: Debug text with profiler graph
1743 show_profiler_graph = false;
1744 statustext = L"Debug info shown";
1745 statustext_time = 0;
1747 else if(show_profiler_graph)
1750 show_profiler_graph = false;
1751 statustext = L"Debug info and profiler graph hidden";
1752 statustext_time = 0;
1756 show_profiler_graph = true;
1757 statustext = L"Profiler graph shown";
1758 statustext_time = 0;
1761 else if(input->wasKeyDown(getKeySetting("keymap_toggle_profiler")))
1763 show_profiler = (show_profiler + 1) % (show_profiler_max + 1);
1765 // FIXME: This updates the profiler with incomplete values
1766 update_profiler_gui(guitext_profiler, font, text_height,
1767 show_profiler, show_profiler_max);
1769 if(show_profiler != 0)
1771 std::wstringstream sstr;
1772 sstr<<"Profiler shown (page "<<show_profiler
1773 <<" of "<<show_profiler_max<<")";
1774 statustext = sstr.str();
1775 statustext_time = 0;
1779 statustext = L"Profiler hidden";
1780 statustext_time = 0;
1783 else if(input->wasKeyDown(getKeySetting("keymap_increase_viewing_range_min")))
1785 s16 range = g_settings->getS16("viewing_range_nodes_min");
1786 s16 range_new = range + 10;
1787 g_settings->set("viewing_range_nodes_min", itos(range_new));
1788 statustext = narrow_to_wide(
1789 "Minimum viewing range changed to "
1791 statustext_time = 0;
1793 else if(input->wasKeyDown(getKeySetting("keymap_decrease_viewing_range_min")))
1795 s16 range = g_settings->getS16("viewing_range_nodes_min");
1796 s16 range_new = range - 10;
1799 g_settings->set("viewing_range_nodes_min",
1801 statustext = narrow_to_wide(
1802 "Minimum viewing range changed to "
1804 statustext_time = 0;
1807 // Handle QuicktuneShortcutter
1808 if(input->wasKeyDown(getKeySetting("keymap_quicktune_next")))
1810 if(input->wasKeyDown(getKeySetting("keymap_quicktune_prev")))
1812 if(input->wasKeyDown(getKeySetting("keymap_quicktune_inc")))
1814 if(input->wasKeyDown(getKeySetting("keymap_quicktune_dec")))
1817 std::string msg = quicktune.getMessage();
1819 statustext = narrow_to_wide(msg);
1820 statustext_time = 0;
1824 // Item selection with mouse wheel
1825 u16 new_playeritem = client.getPlayerItem();
1827 s32 wheel = input->getMouseWheel();
1828 u16 max_item = MYMIN(PLAYER_INVENTORY_SIZE-1,
1829 hotbar_itemcount-1);
1833 if(new_playeritem < max_item)
1840 if(new_playeritem > 0)
1843 new_playeritem = max_item;
1848 for(u16 i=0; i<10; i++)
1850 const KeyPress *kp = NumberKey + (i + 1) % 10;
1851 if(input->wasKeyDown(*kp))
1853 if(i < PLAYER_INVENTORY_SIZE && i < hotbar_itemcount)
1857 infostream<<"Selected item: "
1858 <<new_playeritem<<std::endl;
1863 // Viewing range selection
1864 if(input->wasKeyDown(getKeySetting("keymap_rangeselect")))
1866 draw_control.range_all = !draw_control.range_all;
1867 if(draw_control.range_all)
1869 infostream<<"Enabled full viewing range"<<std::endl;
1870 statustext = L"Enabled full viewing range";
1871 statustext_time = 0;
1875 infostream<<"Disabled full viewing range"<<std::endl;
1876 statustext = L"Disabled full viewing range";
1877 statustext_time = 0;
1881 // Print debug stacks
1882 if(input->wasKeyDown(getKeySetting("keymap_print_debug_stacks")))
1884 dstream<<"-----------------------------------------"
1886 dstream<<DTIME<<"Printing debug stacks:"<<std::endl;
1887 dstream<<"-----------------------------------------"
1889 debug_stacks_print();
1893 Mouse and camera control
1894 NOTE: Do this before client.setPlayerControl() to not cause a camera lag of one frame
1897 float turn_amount = 0;
1898 if((device->isWindowActive() && noMenuActive()) || random_input)
1902 // Mac OSX gets upset if this is set every frame
1903 if(device->getCursorControl()->isVisible())
1904 device->getCursorControl()->setVisible(false);
1907 if(first_loop_after_window_activation){
1908 //infostream<<"window active, first loop"<<std::endl;
1909 first_loop_after_window_activation = false;
1912 s32 dx = input->getMousePos().X - displaycenter.X;
1913 s32 dy = input->getMousePos().Y - displaycenter.Y;
1916 //infostream<<"window active, pos difference "<<dx<<","<<dy<<std::endl;
1918 /*const float keyspeed = 500;
1919 if(input->isKeyDown(irr::KEY_UP))
1920 dy -= dtime * keyspeed;
1921 if(input->isKeyDown(irr::KEY_DOWN))
1922 dy += dtime * keyspeed;
1923 if(input->isKeyDown(irr::KEY_LEFT))
1924 dx -= dtime * keyspeed;
1925 if(input->isKeyDown(irr::KEY_RIGHT))
1926 dx += dtime * keyspeed;*/
1930 camera_pitch += dy*d;
1931 if(camera_pitch < -89.5) camera_pitch = -89.5;
1932 if(camera_pitch > 89.5) camera_pitch = 89.5;
1934 turn_amount = v2f(dx, dy).getLength() * d;
1936 input->setMousePos(displaycenter.X, displaycenter.Y);
1939 // Mac OSX gets upset if this is set every frame
1940 if(device->getCursorControl()->isVisible() == false)
1941 device->getCursorControl()->setVisible(true);
1943 //infostream<<"window inactive"<<std::endl;
1944 first_loop_after_window_activation = true;
1946 recent_turn_speed = recent_turn_speed * 0.9 + turn_amount * 0.1;
1947 //std::cerr<<"recent_turn_speed = "<<recent_turn_speed<<std::endl;
1950 Player speed control
1962 PlayerControl control(
1963 input->isKeyDown(getKeySetting("keymap_forward")),
1964 input->isKeyDown(getKeySetting("keymap_backward")),
1965 input->isKeyDown(getKeySetting("keymap_left")),
1966 input->isKeyDown(getKeySetting("keymap_right")),
1967 input->isKeyDown(getKeySetting("keymap_jump")),
1968 input->isKeyDown(getKeySetting("keymap_special1")),
1969 input->isKeyDown(getKeySetting("keymap_sneak")),
1973 client.setPlayerControl(control);
1982 //TimeTaker timer("server->step(dtime)");
1983 server->step(dtime);
1991 //TimeTaker timer("client.step(dtime)");
1993 //client.step(dtime_avg1);
1997 // Read client events
2000 ClientEvent event = client.getClientEvent();
2001 if(event.type == CE_NONE)
2005 else if(event.type == CE_PLAYER_DAMAGE)
2007 //u16 damage = event.player_damage.amount;
2008 //infostream<<"Player damage: "<<damage<<std::endl;
2009 damage_flash_timer = 0.05;
2010 if(event.player_damage.amount >= 2){
2011 damage_flash_timer += 0.05 * event.player_damage.amount;
2014 else if(event.type == CE_PLAYER_FORCE_MOVE)
2016 camera_yaw = event.player_force_move.yaw;
2017 camera_pitch = event.player_force_move.pitch;
2019 else if(event.type == CE_DEATHSCREEN)
2021 if(respawn_menu_active)
2024 /*bool set_camera_point_target =
2025 event.deathscreen.set_camera_point_target;
2026 v3f camera_point_target;
2027 camera_point_target.X = event.deathscreen.camera_point_target_x;
2028 camera_point_target.Y = event.deathscreen.camera_point_target_y;
2029 camera_point_target.Z = event.deathscreen.camera_point_target_z;*/
2030 MainRespawnInitiator *respawner =
2031 new MainRespawnInitiator(
2032 &respawn_menu_active, &client);
2033 GUIDeathScreen *menu =
2034 new GUIDeathScreen(guienv, guiroot, -1,
2035 &g_menumgr, respawner);
2038 chat_backend.addMessage(L"", L"You died.");
2040 /* Handle visualization */
2042 damage_flash_timer = 0;
2044 /*LocalPlayer* player = client.getLocalPlayer();
2045 player->setPosition(player->getPosition() + v3f(0,-BS,0));
2046 camera.update(player, busytime, screensize);*/
2048 else if(event.type == CE_TEXTURES_UPDATED)
2050 update_wielded_item_trigger = true;
2055 //TimeTaker //timer2("//timer2");
2058 For interaction purposes, get info about the held item
2060 - Is it a usable item?
2061 - Can it point to liquids?
2063 ItemStack playeritem;
2064 bool playeritem_usable = false;
2065 bool playeritem_liquids_pointable = false;
2067 InventoryList *mlist = local_inventory.getList("main");
2070 playeritem = mlist->getItem(client.getPlayerItem());
2071 playeritem_usable = playeritem.getDefinition(itemdef).usable;
2072 playeritem_liquids_pointable = playeritem.getDefinition(itemdef).liquids_pointable;
2075 ToolCapabilities playeritem_toolcap =
2076 playeritem.getToolCapabilities(itemdef);
2082 LocalPlayer* player = client.getEnv().getLocalPlayer();
2083 float full_punch_interval = playeritem_toolcap.full_punch_interval;
2084 float tool_reload_ratio = time_from_last_punch / full_punch_interval;
2085 tool_reload_ratio = MYMIN(tool_reload_ratio, 1.0);
2086 camera.update(player, busytime, screensize, tool_reload_ratio);
2089 v3f player_position = player->getPosition();
2090 v3f camera_position = camera.getPosition();
2091 v3f camera_direction = camera.getDirection();
2092 f32 camera_fov = camera.getFovMax();
2094 if(!disable_camera_update){
2095 client.getEnv().getClientMap().updateCamera(camera_position,
2096 camera_direction, camera_fov);
2099 // Update sound listener
2100 sound->updateListener(camera.getCameraNode()->getPosition(),
2101 v3f(0,0,0), // velocity
2102 camera.getCameraNode()->getTarget(),
2103 camera.getCameraNode()->getUpVector());
2109 soundmaker.step(dtime);
2111 ClientMap &map = client.getEnv().getClientMap();
2112 MapNode n = map.getNodeNoEx(player->getStandingNodePos());
2113 soundmaker.m_player_step_sound = nodedef->get(n).sound_footstep;
2117 Calculate what block is the crosshair pointing to
2120 //u32 t1 = device->getTimer()->getRealTime();
2122 f32 d = 4; // max. distance
2123 core::line3d<f32> shootline(camera_position,
2124 camera_position + camera_direction * BS * (d+1));
2126 core::aabbox3d<f32> hilightbox;
2127 bool should_show_hilightbox = false;
2128 ClientActiveObject *selected_object = NULL;
2130 PointedThing pointed = getPointedThing(
2132 &client, player_position, camera_direction,
2133 camera_position, shootline, d,
2134 playeritem_liquids_pointable, !ldown_for_dig,
2136 hilightbox, should_show_hilightbox,
2139 if(pointed != pointed_old)
2141 infostream<<"Pointing at "<<pointed.dump()<<std::endl;
2142 //dstream<<"Pointing at "<<pointed.dump()<<std::endl;
2148 if(should_show_hilightbox)
2149 hilightboxes.push_back(hilightbox);
2153 - releasing left mouse button
2154 - pointing away from node
2158 if(input->getLeftReleased())
2160 infostream<<"Left button released"
2161 <<" (stopped digging)"<<std::endl;
2164 else if(pointed != pointed_old)
2166 if (pointed.type == POINTEDTHING_NODE
2167 && pointed_old.type == POINTEDTHING_NODE
2168 && pointed.node_undersurface == pointed_old.node_undersurface)
2170 // Still pointing to the same node,
2171 // but a different face. Don't reset.
2175 infostream<<"Pointing away from node"
2176 <<" (stopped digging)"<<std::endl;
2182 client.interact(1, pointed_old);
2183 client.setCrack(-1, v3s16(0,0,0));
2187 if(!digging && ldown_for_dig && !input->getLeftState())
2189 ldown_for_dig = false;
2192 bool left_punch = false;
2193 soundmaker.m_player_leftpunch_sound.name = "";
2195 if(playeritem_usable && input->getLeftState())
2197 if(input->getLeftClicked())
2198 client.interact(4, pointed);
2200 else if(pointed.type == POINTEDTHING_NODE)
2202 v3s16 nodepos = pointed.node_undersurface;
2203 v3s16 neighbourpos = pointed.node_abovesurface;
2206 Check information text of node
2209 ClientMap &map = client.getEnv().getClientMap();
2210 NodeMetadata *meta = map.getNodeMetadata(nodepos);
2212 infotext = narrow_to_wide(meta->infoText());
2214 MapNode n = map.getNode(nodepos);
2215 if(nodedef->get(n).tname_tiles[0] == "unknown_block.png"){
2216 infotext = L"Unknown node: ";
2217 infotext += narrow_to_wide(nodedef->get(n).name);
2221 // We can't actually know, but assume the sound of right-clicking
2222 // to be the sound of placing a node
2223 soundmaker.m_player_rightpunch_sound.gain = 0.5;
2224 soundmaker.m_player_rightpunch_sound.name = "default_place_node";
2230 if(nodig_delay_timer <= 0.0 && input->getLeftState())
2234 infostream<<"Started digging"<<std::endl;
2235 client.interact(0, pointed);
2237 ldown_for_dig = true;
2239 MapNode n = client.getEnv().getClientMap().getNode(nodepos);
2241 // Get digging parameters
2242 DigParams params = getDigParams(nodedef->get(n).groups,
2243 &playeritem_toolcap);
2244 // If can't dig, try hand
2245 if(!params.diggable){
2246 const ItemDefinition &hand = itemdef->get("");
2247 const ToolCapabilities *tp = hand.tool_capabilities;
2249 params = getDigParams(nodedef->get(n).groups, tp);
2252 SimpleSoundSpec sound_dig = nodedef->get(n).sound_dig;
2253 if(sound_dig.exists()){
2254 if(sound_dig.name == "__group"){
2255 if(params.main_group != ""){
2256 soundmaker.m_player_leftpunch_sound.gain = 0.5;
2257 soundmaker.m_player_leftpunch_sound.name =
2258 std::string("default_dig_") +
2262 soundmaker.m_player_leftpunch_sound = sound_dig;
2266 float dig_time_complete = 0.0;
2268 if(params.diggable == false)
2270 // I guess nobody will wait for this long
2271 dig_time_complete = 10000000.0;
2275 dig_time_complete = params.time;
2278 if(dig_time_complete >= 0.001)
2280 dig_index = (u16)((float)CRACK_ANIMATION_LENGTH
2281 * dig_time/dig_time_complete);
2283 // This is for torches
2286 dig_index = CRACK_ANIMATION_LENGTH;
2289 // Don't show cracks if not diggable
2290 if(dig_time_complete >= 100000.0)
2293 else if(dig_index < CRACK_ANIMATION_LENGTH)
2295 //TimeTaker timer("client.setTempMod");
2296 //infostream<<"dig_index="<<dig_index<<std::endl;
2297 client.setCrack(dig_index, nodepos);
2301 infostream<<"Digging completed"<<std::endl;
2302 client.interact(2, pointed);
2303 client.setCrack(-1, v3s16(0,0,0));
2304 MapNode wasnode = map.getNode(nodepos);
2305 client.removeNode(nodepos);
2310 nodig_delay_timer = dig_time_complete
2311 / (float)CRACK_ANIMATION_LENGTH;
2313 // We don't want a corresponding delay to
2314 // very time consuming nodes
2315 if(nodig_delay_timer > 0.3)
2316 nodig_delay_timer = 0.3;
2317 // We want a slight delay to very little
2318 // time consuming nodes
2319 float mindelay = 0.15;
2320 if(nodig_delay_timer < mindelay)
2321 nodig_delay_timer = mindelay;
2323 // Send event to trigger sound
2324 MtEvent *e = new NodeDugEvent(nodepos, wasnode);
2325 gamedef->event()->put(e);
2330 camera.setDigging(0); // left click animation
2333 if(input->getRightClicked())
2335 infostream<<"Ground right-clicked"<<std::endl;
2337 // If metadata provides an inventory view, activate it
2338 if(meta && meta->getInventoryDrawSpecString() != "" && !random_input)
2340 infostream<<"Launching custom inventory view"<<std::endl;
2342 InventoryLocation inventoryloc;
2343 inventoryloc.setNodeMeta(nodepos);
2350 core::array<GUIInventoryMenu::DrawSpec> draw_spec;
2352 GUIInventoryMenu::makeDrawSpecArrayFromString(
2354 meta->getInventoryDrawSpecString(),
2357 GUIInventoryMenu *menu =
2358 new GUIInventoryMenu(guienv, guiroot, -1,
2359 &g_menumgr, invsize,
2361 menu->setDrawSpec(draw_spec);
2364 // If metadata provides text input, activate text input
2365 else if(meta && meta->allowsTextInput() && !random_input)
2367 infostream<<"Launching metadata text input"<<std::endl;
2369 // Get a new text for it
2371 TextDest *dest = new TextDestNodeMetadata(nodepos, &client);
2373 std::wstring wtext = narrow_to_wide(meta->getText());
2375 (new GUITextInputMenu(guienv, guiroot, -1,
2379 // Otherwise report right click to server
2382 client.interact(3, pointed);
2383 camera.setDigging(1); // right click animation
2387 else if(pointed.type == POINTEDTHING_OBJECT)
2389 infotext = narrow_to_wide(selected_object->infoText());
2391 if(infotext == L"" && show_debug){
2392 infotext = narrow_to_wide(selected_object->debugInfoText());
2395 //if(input->getLeftClicked())
2396 if(input->getLeftState())
2398 bool do_punch = false;
2399 bool do_punch_damage = false;
2400 if(object_hit_delay_timer <= 0.0){
2402 do_punch_damage = true;
2403 object_hit_delay_timer = object_hit_delay;
2405 if(input->getLeftClicked()){
2409 infostream<<"Left-clicked object"<<std::endl;
2412 if(do_punch_damage){
2413 // Report direct punch
2414 v3f objpos = selected_object->getPosition();
2415 v3f dir = (objpos - player_position).normalize();
2417 bool disable_send = selected_object->directReportPunch(
2418 dir, &playeritem, time_from_last_punch);
2419 time_from_last_punch = 0;
2421 client.interact(0, pointed);
2424 else if(input->getRightClicked())
2426 infostream<<"Right-clicked object"<<std::endl;
2427 client.interact(3, pointed); // place
2430 else if(input->getLeftState())
2432 // When button is held down in air, show continuous animation
2436 pointed_old = pointed;
2438 if(left_punch || input->getLeftClicked())
2440 camera.setDigging(0); // left click animation
2443 input->resetLeftClicked();
2444 input->resetRightClicked();
2446 input->resetLeftReleased();
2447 input->resetRightReleased();
2450 Calculate stuff for drawing
2460 fog_range = BS*farmesh_range;
2464 fog_range = draw_control.wanted_range*BS + 0.0*MAP_BLOCKSIZE*BS;
2466 if(draw_control.range_all)
2467 fog_range = 100000*BS;
2471 Calculate general brightness
2473 u32 daynight_ratio = client.getEnv().getDayNightRatio();
2474 float time_brightness = (float)decode_light(
2475 (daynight_ratio * LIGHT_SUN) / 1000) / 255.0;
2476 float direct_brightness = 0;
2477 bool sunlight_seen = false;
2478 if(g_settings->getBool("free_move")){
2479 direct_brightness = time_brightness;
2480 sunlight_seen = true;
2482 ScopeProfiler sp(g_profiler, "Detecting background light", SPT_AVG);
2483 float old_brightness = sky->getBrightness();
2484 direct_brightness = (float)client.getEnv().getClientMap()
2485 .getBackgroundBrightness(MYMIN(fog_range*1.2, 60*BS),
2486 daynight_ratio, (int)(old_brightness*255.5), &sunlight_seen)
2490 time_of_day = client.getEnv().getTimeOfDayF();
2492 if(fabs(time_of_day - time_of_day_smooth) > maxsm &&
2493 fabs(time_of_day - time_of_day_smooth + 1.0) > maxsm &&
2494 fabs(time_of_day - time_of_day_smooth - 1.0) > maxsm)
2495 time_of_day_smooth = time_of_day;
2497 if(time_of_day_smooth > 0.8 && time_of_day < 0.2)
2498 time_of_day_smooth = time_of_day_smooth * (1.0-todsm)
2499 + (time_of_day+1.0) * todsm;
2501 time_of_day_smooth = time_of_day_smooth * (1.0-todsm)
2502 + time_of_day * todsm;
2504 sky->update(time_of_day_smooth, time_brightness, direct_brightness,
2507 float brightness = sky->getBrightness();
2508 video::SColor bgcolor = sky->getBgColor();
2509 video::SColor skycolor = sky->getSkyColor();
2515 if(sky->getCloudsVisible()){
2516 clouds->setVisible(true);
2517 clouds->step(dtime);
2518 clouds->update(v2f(player_position.X, player_position.Z),
2519 sky->getCloudColor());
2521 clouds->setVisible(false);
2530 farmesh_range = draw_control.wanted_range * 10;
2531 if(draw_control.range_all && farmesh_range < 500)
2532 farmesh_range = 500;
2533 if(farmesh_range > 1000)
2534 farmesh_range = 1000;
2536 farmesh->step(dtime);
2537 farmesh->update(v2f(player_position.X, player_position.Z),
2538 brightness, farmesh_range);
2545 if(g_settings->getBool("enable_fog") == true && !force_fog_off)
2549 video::EFT_FOG_LINEAR,
2561 video::EFT_FOG_LINEAR,
2571 Update gui stuff (0ms)
2574 //TimeTaker guiupdatetimer("Gui updating");
2576 const char program_name_and_version[] =
2577 "Minetest-c55 " VERSION_STRING;
2581 static float drawtime_avg = 0;
2582 drawtime_avg = drawtime_avg * 0.95 + (float)drawtime*0.05;
2583 /*static float beginscenetime_avg = 0;
2584 beginscenetime_avg = beginscenetime_avg * 0.95 + (float)beginscenetime*0.05;
2585 static float scenetime_avg = 0;
2586 scenetime_avg = scenetime_avg * 0.95 + (float)scenetime*0.05;
2587 static float endscenetime_avg = 0;
2588 endscenetime_avg = endscenetime_avg * 0.95 + (float)endscenetime*0.05;*/
2591 snprintf(temptext, 300, "%s ("
2594 " drawtime=%.0f, dtime_jitter = % .1f %%"
2595 ", v_range = %.1f, RTT = %.3f",
2596 program_name_and_version,
2597 draw_control.range_all,
2599 dtime_jitter1_max_fraction * 100.0,
2600 draw_control.wanted_range,
2604 guitext->setText(narrow_to_wide(temptext).c_str());
2605 guitext->setVisible(true);
2607 else if(show_hud || show_chat)
2609 guitext->setText(narrow_to_wide(program_name_and_version).c_str());
2610 guitext->setVisible(true);
2614 guitext->setVisible(false);
2620 snprintf(temptext, 300,
2621 "(% .1f, % .1f, % .1f)"
2623 player_position.X/BS,
2624 player_position.Y/BS,
2625 player_position.Z/BS,
2626 wrapDegrees_0_360(camera_yaw));
2628 guitext2->setText(narrow_to_wide(temptext).c_str());
2629 guitext2->setVisible(true);
2633 guitext2->setVisible(false);
2637 guitext_info->setText(infotext.c_str());
2638 guitext_info->setVisible(show_hud && g_menumgr.menuCount() == 0);
2642 float statustext_time_max = 1.5;
2643 if(!statustext.empty())
2645 statustext_time += dtime;
2646 if(statustext_time >= statustext_time_max)
2649 statustext_time = 0;
2652 guitext_status->setText(statustext.c_str());
2653 guitext_status->setVisible(!statustext.empty());
2655 if(!statustext.empty())
2657 s32 status_y = screensize.Y - 130;
2658 core::rect<s32> rect(
2660 status_y - guitext_status->getTextHeight(),
2664 guitext_status->setRelativePosition(rect);
2667 video::SColor initial_color(255,0,0,0);
2668 if(guienv->getSkin())
2669 initial_color = guienv->getSkin()->getColor(gui::EGDC_BUTTON_TEXT);
2670 video::SColor final_color = initial_color;
2671 final_color.setAlpha(0);
2672 video::SColor fade_color =
2673 initial_color.getInterpolated_quadratic(
2676 pow(statustext_time / (float)statustext_time_max, 2.0f));
2677 guitext_status->setOverrideColor(fade_color);
2678 guitext_status->enableOverrideColor(true);
2683 Get chat messages from client
2686 // Get new messages from error log buffer
2687 while(!chat_log_error_buf.empty())
2689 chat_backend.addMessage(L"", narrow_to_wide(
2690 chat_log_error_buf.get()));
2692 // Get new messages from client
2693 std::wstring message;
2694 while(client.getChatMessage(message))
2696 chat_backend.addUnparsedMessage(message);
2698 // Remove old messages
2699 chat_backend.step(dtime);
2701 // Display all messages in a static text element
2702 u32 recent_chat_count = chat_backend.getRecentBuffer().getLineCount();
2703 std::wstring recent_chat = chat_backend.getRecentChat();
2704 guitext_chat->setText(recent_chat.c_str());
2706 // Update gui element size and position
2707 s32 chat_y = 5+(text_height+5);
2709 chat_y += (text_height+5);
2710 core::rect<s32> rect(
2714 chat_y + guitext_chat->getTextHeight()
2716 guitext_chat->setRelativePosition(rect);
2718 // Don't show chat if disabled or empty or profiler is enabled
2719 guitext_chat->setVisible(show_chat && recent_chat_count != 0
2727 if(client.getPlayerItem() != new_playeritem)
2729 client.selectPlayerItem(new_playeritem);
2731 if(client.getLocalInventoryUpdated())
2733 //infostream<<"Updating local inventory"<<std::endl;
2734 client.getLocalInventory(local_inventory);
2736 update_wielded_item_trigger = true;
2738 if(update_wielded_item_trigger)
2740 update_wielded_item_trigger = false;
2741 // Update wielded tool
2742 InventoryList *mlist = local_inventory.getList("main");
2745 item = mlist->getItem(client.getPlayerItem());
2753 TimeTaker tt_draw("mainloop: draw");
2757 TimeTaker timer("beginScene");
2758 //driver->beginScene(false, true, bgcolor);
2759 //driver->beginScene(true, true, bgcolor);
2760 driver->beginScene(true, true, skycolor);
2761 beginscenetime = timer.stop(true);
2766 //infostream<<"smgr->drawAll()"<<std::endl;
2768 TimeTaker timer("smgr");
2770 scenetime = timer.stop(true);
2774 //TimeTaker timer9("auxiliary drawings");
2778 //TimeTaker //timer10("//timer10");
2784 driver->setMaterial(m);
2786 driver->setTransform(video::ETS_WORLD, core::IdentityMatrix);
2790 for(core::list<aabb3f>::Iterator i=hilightboxes.begin();
2791 i != hilightboxes.end(); i++)
2793 /*infostream<<"hilightbox min="
2794 <<"("<<i->MinEdge.X<<","<<i->MinEdge.Y<<","<<i->MinEdge.Z<<")"
2796 <<"("<<i->MaxEdge.X<<","<<i->MaxEdge.Y<<","<<i->MaxEdge.Z<<")"
2798 driver->draw3DBox(*i, video::SColor(255,0,0,0));
2807 // Warning: This clears the Z buffer.
2808 camera.drawWieldedTool();
2815 client.getEnv().getClientMap().renderPostFx();
2821 if(show_profiler_graph)
2823 graph.draw(10, screensize.Y - 10, driver, font);
2831 driver->draw2DLine(displaycenter - core::vector2d<s32>(10,0),
2832 displaycenter + core::vector2d<s32>(10,0),
2833 video::SColor(255,255,255,255));
2834 driver->draw2DLine(displaycenter - core::vector2d<s32>(0,10),
2835 displaycenter + core::vector2d<s32>(0,10),
2836 video::SColor(255,255,255,255));
2842 //TimeTaker //timer11("//timer11");
2855 draw_hotbar(driver, font, gamedef,
2856 v2s32(displaycenter.X, screensize.Y),
2857 hotbar_imagesize, hotbar_itemcount, &local_inventory,
2858 client.getHP(), client.getPlayerItem());
2864 if(damage_flash_timer > 0.0)
2866 damage_flash_timer -= dtime;
2868 video::SColor color(128,255,0,0);
2869 driver->draw2DRectangle(color,
2870 core::rect<s32>(0,0,screensize.X,screensize.Y),
2878 TimeTaker timer("endScene");
2880 endscenetime = timer.stop(true);
2883 drawtime = tt_draw.stop(true);
2884 g_profiler->graphAdd("mainloop_draw", (float)drawtime/1000.0f);
2890 static s16 lastFPS = 0;
2891 //u16 fps = driver->getFPS();
2892 u16 fps = (1.0/dtime_avg1);
2896 core::stringw str = L"Minetest [";
2897 str += driver->getName();
2901 device->setWindowCaption(str.c_str());
2906 Log times and stuff for visualization
2908 Profiler::GraphValues values;
2909 g_profiler->graphGet(values);
2918 if(gui_chat_console)
2919 gui_chat_console->drop();
2922 Draw a "shutting down" screen, which will be shown while the map
2923 generator and other stuff quits
2926 /*gui::IGUIStaticText *gui_shuttingdowntext = */
2927 draw_load_screen(L"Shutting down stuff...", driver, font);
2928 /*driver->beginScene(true, true, video::SColor(255,0,0,0));
2931 gui_shuttingdowntext->remove();*/
2934 chat_backend.addMessage(L"", L"# Disconnected.");
2935 chat_backend.addMessage(L"", L"");
2937 // Client scope (client is destructed before destructing *def and tsrc)