OMG! Main Menu!
authorPerttu Ahola <celeron55@gmail.com>
Sun, 23 Jan 2011 15:29:15 +0000 (17:29 +0200)
committerPerttu Ahola <celeron55@gmail.com>
Sun, 23 Jan 2011 15:29:15 +0000 (17:29 +0200)
25 files changed:
minetest.conf.example
minetest.vcproj
src/CMakeLists.txt
src/client.cpp
src/connection.cpp
src/defaultsettings.cpp
src/environment.cpp
src/guiInventoryMenu.cpp
src/guiInventoryMenu.h
src/guiMainMenu.cpp [new file with mode: 0644]
src/guiMainMenu.h [new file with mode: 0644]
src/guiMessageMenu.cpp
src/guiMessageMenu.h
src/guiPauseMenu.cpp
src/guiPauseMenu.h
src/guiTextInputMenu.cpp
src/guiTextInputMenu.h
src/main.cpp
src/map.cpp
src/mapblock.cpp
src/modalMenu.h
src/server.cpp
src/server.h
src/servermain.cpp
src/utility.h

index 41e2dcab6558a021d4adfbe589ca4a41ae7a8137..0cdccf20c3406b6251dccfc33c173a0c387c2263 100644 (file)
@@ -15,7 +15,6 @@
 #viewing_range_nodes_min = 35
 #screenW = 800
 #screenH = 600
-#host_game = 
 #port = 30000
 #address = kray.dy.fi
 #name = 
index c8961ff6e6e67ba454fadd2d08ef1131aa475c40..53481add7dcc035b8c00ff3aec94da40581f996b 100644 (file)
                        />\r
                        <Tool\r
                                Name="VCLinkerTool"\r
-                               AdditionalLibraryDirectories="&quot;C:\Program Files\Microsoft Platform SDK for Windows Server 2003 R2\Lib&quot;;&quot;..\jthread\jthread-1.2.1\Release&quot;;&quot;..\irrlicht\irrlicht-1.7.1\lib\Win32-visualstudio&quot;;..\zlib125dll\dll32"\r
+                               AdditionalLibraryDirectories="&quot;C:\Program Files\Microsoft Platform SDK for Windows Server 2003 R2\Lib&quot;;&quot;..\irrlicht\irrlicht-1.7.1\lib\Win32-visualstudio&quot;;..\zlib125dll\dll32"\r
                                IgnoreDefaultLibraryNames="libcmtd.lib"\r
                                GenerateDebugInformation="false"\r
                                LinkTimeCodeGeneration="1"\r
                                RelativePath=".\src\guiInventoryMenu.cpp"\r
                                >\r
                        </File>\r
+                       <File\r
+                               RelativePath=".\src\guiMainMenu.cpp"\r
+                               >\r
+                       </File>\r
                        <File\r
                                RelativePath=".\src\guiMessageMenu.cpp"\r
                                >\r
                                RelativePath=".\src\irrlichtwrapper.cpp"\r
                                >\r
                        </File>\r
+                       <File\r
+                               RelativePath=".\src\jthread\win32\jmutex.cpp"\r
+                               >\r
+                       </File>\r
+                       <File\r
+                               RelativePath=".\src\jthread\win32\jthread.cpp"\r
+                               >\r
+                       </File>\r
                        <File\r
                                RelativePath=".\src\light.cpp"\r
                                >\r
index a9e3f2788aa7640bab676fd211abbadd0c9e11ef..7913f496426b190c7ec39b114816f96cdcab0588 100644 (file)
@@ -10,7 +10,7 @@ add_definitions ( -DUSE_CMAKE_CONFIG_H )
 
 if(WIN32)
        # Windows
-       # Surpress some warnings
+       # Surpress some useless warnings
        add_definitions ( /D "_CRT_SECURE_NO_DEPRECATE" /W1 )
        # Zlib stuff
        set(ZLIB_INCLUDE_DIR "${PROJECT_SOURCE_DIR}/../../zlib/zlib-1.2.5"
@@ -39,6 +39,7 @@ configure_file(
 )
 
 set(minetest_SRCS
+       guiMainMenu.cpp
        porting.cpp
        guiMessageMenu.cpp
        materials.cpp
@@ -108,8 +109,11 @@ include_directories(
 
 set(EXECUTABLE_OUTPUT_PATH ../bin)
 
+set(JTHREAD_LIBRARIES "jthread")
+set(JTHREAD_SRCS "")
+
 if(BUILD_CLIENT)
-       add_executable(minetest ${minetest_SRCS})
+       add_executable(minetest ${minetest_SRCS} ${JTHREAD_SRCS})
        target_link_libraries(
                minetest
                ${ZLIB_LIBRARIES}
@@ -119,18 +123,18 @@ if(BUILD_CLIENT)
                ${BZIP2_LIBRARIES}
                ${PNG_LIBRARIES}
                ${X11_LIBRARIES}
-               jthread
+               ${JTHREAD_LIBRARIES}
                ${PLATFORM_LIBS}
                ${CLIENT_PLATFORM_LIBS}
        )
 endif(BUILD_CLIENT)
 
 if(BUILD_SERVER)
-       add_executable(minetestserver ${minetestserver_SRCS})
+       add_executable(minetestserver ${minetestserver_SRCS} ${JTHREAD_SRCS})
        target_link_libraries(
                minetestserver
                ${ZLIB_LIBRARIES}
-               jthread
+               ${JTHREAD_LIBRARIES}
                ${PLATFORM_LIBS}
        )
 endif(BUILD_SERVER)
@@ -143,7 +147,11 @@ if(MSVC)
        # Visual Studio
 
        # EHa enables SEH exceptions (used for catching segfaults)
-       set(CMAKE_CXX_FLAGS_RELEASE "/EHa /MD /O2 /Ob2 /Oi /Ot /Oy /GL /FD /MT /GS- /arch:SSE /fp:fast /D NDEBUG")
+       set(CMAKE_CXX_FLAGS_RELEASE "/EHa /MD /O2 /Ob2 /Oi /Ot /Oy /GL /FD /MT /GS- /arch:SSE /fp:fast /D NDEBUG /D _HAS_ITERATOR_DEBUGGING=0 /TP")
+       set(CMAKE_EXE_LINKER_FLAGS_RELEASE "/LTCG /NODEFAULTLIB:\"libcmtd.lib\"")
+
+       # Debug build doesn't catch exceptions by itself
+       # Add some optimizations because otherwise it's VERY slow
        set(CMAKE_CXX_FLAGS_DEBUG "/MDd /Zi /Ob0 /Od /RTC1")
        
        if(BUILD_SERVER)
index 3853c25e5dbebc26b4918f3d4efdcc2d72711598..d6062ef61f9f17d6f8f4c74f9cd161d3b3d0f763 100644 (file)
@@ -1209,8 +1209,8 @@ bool Client::AsyncProcessPacket()
        } //try
        catch(con::PeerNotFoundException &e)
        {
-               dout_client<<DTIME<<"Client::AsyncProcessData(): Cancelling: The server"
-                               " connection doesn't exist (a timeout or not yet connected?)"<<std::endl;
+               /*dout_client<<DTIME<<"Client::AsyncProcessData(): Cancelling: The server"
+                               " connection doesn't exist (a timeout or not yet connected?)"<<std::endl;*/
                return false;
        }
 }
index e890a12a11a582162704d3f1bbce4f71bc2431fc..b07e0de906124fad5c9400f7070e31f44640b000 100644 (file)
@@ -1317,7 +1317,7 @@ Peer* Connection::GetPeer(u16 peer_id)
 
        if(node == NULL){
                // Peer not found
-               throw PeerNotFoundException("Peer not found (possible timeout)");
+               throw PeerNotFoundException("GetPeer: Peer not found (possible timeout)");
        }
 
        // Error checking
index 401fc03f553a8df01515e50fef46f47199b2c050..6cd242f01ae659e1802253be7d0bbd1e29aa7e3c 100644 (file)
@@ -30,7 +30,6 @@ void set_default_settings()
        g_settings.setDefault("viewing_range_nodes_min", "35");
        g_settings.setDefault("screenW", "800");
        g_settings.setDefault("screenH", "600");
-       g_settings.setDefault("host_game", "");
        g_settings.setDefault("port", "");
        g_settings.setDefault("address", "");
        g_settings.setDefault("name", "");
index 6d987e3c2d1d650df046182e7549c72950e00dc1..51ed05422fbdb22424b63207e0da818c88f5d5ad 100644 (file)
@@ -190,9 +190,16 @@ Map & Environment::getMap()
 void Environment::addPlayer(Player *player)
 {
        DSTACK(__FUNCTION_NAME);
-       //Check that only one local player exists and peer_ids are unique
+       /*
+               Check that only one local player exists and peer_ids are unique.
+               Exception: there can be multiple players with peer_id=0
+       */
 #ifndef SERVER
-       assert(player->isLocal() == false || getLocalPlayer() == NULL);
+       /*
+               It is a failure if player is local and there already is a local
+               player
+       */
+       assert(!(player->isLocal() == true && getLocalPlayer() != NULL));
 #endif
        if(player->peer_id != 0)
                assert(getPlayer(player->peer_id) == NULL);
index d7af0a0b955538627b917dfe7da05b8c6760cc44..102a0ae7250a4d2edb812090bab7a56570afcfc8 100644 (file)
@@ -79,8 +79,8 @@ GUIInventoryMenu::GUIInventoryMenu(gui::IGUIEnvironment* env,
                gui::IGUIElement* parent, s32 id,
                Inventory *inventory,
                Queue<InventoryAction*> *actions,
-               int *active_menu_count):
-       GUIModalMenu(env, parent, id, active_menu_count)
+               IMenuManager *menumgr):
+       GUIModalMenu(env, parent, id, menumgr)
 {
        m_inventory = inventory;
        m_selected_item = NULL;
index 82e7ee89d7a5305a8e92de87e047b9a39e18ac15..6211bb24bdf2eed3823b8a755f206b9e7af728cf 100644 (file)
@@ -74,7 +74,7 @@ public:
                        gui::IGUIElement* parent, s32 id,
                        Inventory *inventory,
                        Queue<InventoryAction*> *actions,
-                       int *active_menu_count);
+                       IMenuManager *menumgr);
        ~GUIInventoryMenu();
 
        void removeChildren();
diff --git a/src/guiMainMenu.cpp b/src/guiMainMenu.cpp
new file mode 100644 (file)
index 0000000..84435b5
--- /dev/null
@@ -0,0 +1,275 @@
+/*
+Minetest-c55
+Copyright (C) 2010 celeron55, Perttu Ahola <celeron55@gmail.com>
+
+This program is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2 of the License, or
+(at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License along
+with this program; if not, write to the Free Software Foundation, Inc.,
+51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+*/
+
+#include "guiMainMenu.h"
+#include "debug.h"
+#include "serialization.h"
+#include <string>
+
+GUIMainMenu::GUIMainMenu(gui::IGUIEnvironment* env,
+               gui::IGUIElement* parent, s32 id,
+               IMenuManager *menumgr,
+               MainMenuData *data,
+               IGameCallback *gamecallback
+):
+       GUIModalMenu(env, parent, id, menumgr),
+       m_data(data),
+       m_accepted(false),
+       m_gamecallback(gamecallback)
+{
+       assert(m_data);
+}
+
+GUIMainMenu::~GUIMainMenu()
+{
+       removeChildren();
+}
+
+void GUIMainMenu::removeChildren()
+{
+       const core::list<gui::IGUIElement*> &children = getChildren();
+       core::list<gui::IGUIElement*> children_copy;
+       for(core::list<gui::IGUIElement*>::ConstIterator
+                       i = children.begin(); i != children.end(); i++)
+       {
+               children_copy.push_back(*i);
+       }
+       for(core::list<gui::IGUIElement*>::Iterator
+                       i = children_copy.begin();
+                       i != children_copy.end(); i++)
+       {
+               (*i)->remove();
+       }
+}
+
+void GUIMainMenu::regenerateGui(v2u32 screensize)
+{
+       std::wstring text_name;
+       std::wstring text_address;
+       std::wstring text_port;
+       bool creative_mode;
+
+       {
+               gui::IGUIElement *e = getElementFromId(258);
+               if(e != NULL)
+                       text_name = e->getText();
+               else
+                       text_name = m_data->name;
+       }
+       {
+               gui::IGUIElement *e = getElementFromId(256);
+               if(e != NULL)
+                       text_address = e->getText();
+               else
+                       text_address = m_data->address;
+       }
+       {
+               gui::IGUIElement *e = getElementFromId(257);
+               if(e != NULL)
+                       text_port = e->getText();
+               else
+                       text_port = m_data->port;
+       }
+       {
+               gui::IGUIElement *e = getElementFromId(259);
+               if(e != NULL && e->getType() == gui::EGUIET_CHECK_BOX)
+                       creative_mode = ((gui::IGUICheckBox*)e)->isChecked();
+               else
+                       creative_mode = m_data->creative_mode;
+       }
+
+       /*
+               Remove stuff
+       */
+       removeChildren();
+       
+       /*
+               Calculate new sizes and positions
+       */
+       core::rect<s32> rect(
+                       screensize.X/2 - 580/2,
+                       screensize.Y/2 - 300/2,
+                       screensize.X/2 + 580/2,
+                       screensize.Y/2 + 300/2
+       );
+       
+       DesiredRect = rect;
+       recalculateAbsolutePosition(false);
+
+       v2s32 size = rect.getSize();
+
+       /*
+               Add stuff
+       */
+
+       // Nickname
+       {
+               core::rect<s32> rect(0, 0, 100, 20);
+               rect = rect + v2s32(size.X/2 - 250, size.Y/2 - 100 + 6);
+               const wchar_t *text = L"Nickname";
+               Environment->addStaticText(text, rect, false, true, this, -1);
+       }
+       {
+               core::rect<s32> rect(0, 0, 250, 30);
+               rect = rect + v2s32(size.X/2 - 130, size.Y/2 - 100);
+               gui::IGUIElement *e = 
+               Environment->addEditBox(text_name.c_str(), rect, true, this, 258);
+               if(text_name == L"")
+                       Environment->setFocus(e);
+       }
+       // Address + port
+       {
+               core::rect<s32> rect(0, 0, 100, 20);
+               rect = rect + v2s32(size.X/2 - 250, size.Y/2 - 50 + 6);
+               const wchar_t *text = L"Address + Port";
+               Environment->addStaticText(text, rect, false, true, this, -1);
+       }
+       {
+               core::rect<s32> rect(0, 0, 250, 30);
+               rect = rect + v2s32(size.X/2 - 130, size.Y/2 - 50);
+               gui::IGUIElement *e = 
+               Environment->addEditBox(text_address.c_str(), rect, true, this, 256);
+               if(text_name != L"")
+                       Environment->setFocus(e);
+       }
+       {
+               core::rect<s32> rect(0, 0, 100, 30);
+               rect = rect + v2s32(size.X/2 - 130 + 250 + 20, size.Y/2 - 50);
+               Environment->addEditBox(text_port.c_str(), rect, true, this, 257);
+       }
+       {
+               core::rect<s32> rect(0, 0, 400, 20);
+               rect = rect + v2s32(size.X/2 - 130, size.Y/2 - 50 + 35);
+               const wchar_t *text = L"Leave address blank to start a local server.";
+               Environment->addStaticText(text, rect, false, true, this, -1);
+       }
+       // Server parameters
+       {
+               core::rect<s32> rect(0, 0, 100, 20);
+               rect = rect + v2s32(size.X/2 - 250, size.Y/2 + 25 + 6);
+               const wchar_t *text = L"Server params";
+               Environment->addStaticText(text, rect, false, true, this, -1);
+       }
+       {
+               core::rect<s32> rect(0, 0, 250, 30);
+               rect = rect + v2s32(size.X/2 - 130, size.Y/2 + 25);
+               Environment->addCheckBox(creative_mode, rect, this, 259, L"Creative Mode");
+       }
+       // Start game button
+       {
+               core::rect<s32> rect(0, 0, 180, 30);
+               rect = rect + v2s32(size.X/2-180/2, size.Y/2-30/2 + 100);
+               Environment->addButton(rect, this, 257, L"Start Game / Connect");
+       }
+}
+
+void GUIMainMenu::drawMenu()
+{
+       gui::IGUISkin* skin = Environment->getSkin();
+       if (!skin)
+               return;
+       video::IVideoDriver* driver = Environment->getVideoDriver();
+       
+       video::SColor bgcolor(140,0,0,0);
+       driver->draw2DRectangle(bgcolor, AbsoluteRect, &AbsoluteClippingRect);
+
+       gui::IGUIElement::draw();
+}
+
+void GUIMainMenu::acceptInput()
+{
+       {
+               gui::IGUIElement *e = getElementFromId(258);
+               if(e != NULL)
+                       m_data->name = e->getText();
+       }
+       {
+               gui::IGUIElement *e = getElementFromId(256);
+               if(e != NULL)
+                       m_data->address = e->getText();
+       }
+       {
+               gui::IGUIElement *e = getElementFromId(257);
+               if(e != NULL)
+                       m_data->port = e->getText();
+       }
+       {
+               gui::IGUIElement *e = getElementFromId(259);
+               if(e != NULL && e->getType() == gui::EGUIET_CHECK_BOX)
+                       m_data->creative_mode = ((gui::IGUICheckBox*)e)->isChecked();
+       }
+       
+       m_accepted = true;
+}
+
+bool GUIMainMenu::OnEvent(const SEvent& event)
+{
+       if(event.EventType==EET_KEY_INPUT_EVENT)
+       {
+               if(event.KeyInput.Key==KEY_ESCAPE && event.KeyInput.PressedDown)
+               {
+                       m_gamecallback->exitToOS();
+                       quitMenu();
+                       return true;
+               }
+               if(event.KeyInput.Key==KEY_RETURN && event.KeyInput.PressedDown)
+               {
+                       acceptInput();
+                       quitMenu();
+                       return true;
+               }
+       }
+       if(event.EventType==EET_GUI_EVENT)
+       {
+               if(event.GUIEvent.EventType==gui::EGET_ELEMENT_FOCUS_LOST
+                               && isVisible())
+               {
+                       if(!canTakeFocus(event.GUIEvent.Element))
+                       {
+                               dstream<<"GUIMainMenu: Not allowing focus change."
+                                               <<std::endl;
+                               // Returning true disables focus change
+                               return true;
+                       }
+               }
+               if(event.GUIEvent.EventType==gui::EGET_BUTTON_CLICKED)
+               {
+                       switch(event.GUIEvent.Caller->getID())
+                       {
+                       case 257:
+                               acceptInput();
+                               quitMenu();
+                               break;
+                       }
+               }
+               if(event.GUIEvent.EventType==gui::EGET_EDITBOX_ENTER)
+               {
+                       switch(event.GUIEvent.Caller->getID())
+                       {
+                       case 256: case 257: case 258:
+                               acceptInput();
+                               quitMenu();
+                               break;
+                       }
+               }
+       }
+
+       return Parent ? Parent->OnEvent(event) : false;
+}
+
diff --git a/src/guiMainMenu.h b/src/guiMainMenu.h
new file mode 100644 (file)
index 0000000..8060f51
--- /dev/null
@@ -0,0 +1,73 @@
+/*
+Minetest-c55
+Copyright (C) 2010 celeron55, Perttu Ahola <celeron55@gmail.com>
+
+This program is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2 of the License, or
+(at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License along
+with this program; if not, write to the Free Software Foundation, Inc.,
+51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+*/
+
+#ifndef GUIMAINMENU_HEADER
+#define GUIMAINMENU_HEADER
+
+#include "common_irrlicht.h"
+#include "modalMenu.h"
+#include "utility.h"
+#include <string>
+// For IGameCallback
+#include "guiPauseMenu.h"
+
+struct MainMenuData
+{
+       // These are in the native format of the gui elements
+       std::wstring address;
+       std::wstring port;
+       std::wstring name;
+       bool creative_mode;
+};
+
+class GUIMainMenu : public GUIModalMenu
+{
+public:
+       GUIMainMenu(gui::IGUIEnvironment* env,
+                       gui::IGUIElement* parent, s32 id,
+                       IMenuManager *menumgr,
+                       MainMenuData *data,
+                       IGameCallback *gamecallback);
+       ~GUIMainMenu();
+       
+       void removeChildren();
+       /*
+               Remove and re-add (or reposition) stuff
+       */
+       void regenerateGui(v2u32 screensize);
+
+       void drawMenu();
+
+       void acceptInput();
+
+       bool getStatus()
+       {
+               return m_accepted;
+       }
+
+       bool OnEvent(const SEvent& event);
+       
+private:
+       MainMenuData *m_data;
+       bool m_accepted;
+       IGameCallback *m_gamecallback;
+};
+
+#endif
+
index 9cba64a892ddd72e5ceec1770335fb777a301288..7102ddd833f489cea573cdbe92e6c3d887e382c9 100644 (file)
@@ -24,10 +24,10 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 
 GUIMessageMenu::GUIMessageMenu(gui::IGUIEnvironment* env,
                gui::IGUIElement* parent, s32 id,
-               int *active_menu_count,
+               IMenuManager *menumgr,
                std::wstring message_text
 ):
-       GUIModalMenu(env, parent, id, active_menu_count),
+       GUIModalMenu(env, parent, id, menumgr),
        m_message_text(message_text),
        m_status(false)
 {
index 03dbb54e9006048190887b8cd3e8cd79a40cbcf6..82c40ce096a0247b15ad77f901c303fff184a79b 100644 (file)
@@ -30,7 +30,7 @@ class GUIMessageMenu : public GUIModalMenu
 public:
        GUIMessageMenu(gui::IGUIEnvironment* env,
                        gui::IGUIElement* parent, s32 id,
-                       int *active_menu_count,
+                       IMenuManager *menumgr,
                        std::wstring message_text);
        ~GUIMessageMenu();
        
index 574cc774f011b018ca5f48e80d15d7e847b082e1..d905d32227bdc5288a715b8f74aacf23ca3ccf93 100644 (file)
@@ -25,11 +25,11 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 \r
 GUIPauseMenu::GUIPauseMenu(gui::IGUIEnvironment* env,\r
                gui::IGUIElement* parent, s32 id,\r
-               IrrlichtDevice *dev,\r
-               int *active_menu_count):\r
-       GUIModalMenu(env, parent, id, active_menu_count)\r
+               IGameCallback *gamecallback,\r
+               IMenuManager *menumgr):\r
+       GUIModalMenu(env, parent, id, menumgr)\r
 {\r
-       m_dev = dev;\r
+       m_gamecallback = gamecallback;\r
 }\r
 \r
 GUIPauseMenu::~GUIPauseMenu()\r
@@ -59,6 +59,11 @@ void GUIPauseMenu::removeChildren()
                if(e != NULL)\r
                        e->remove();\r
        }\r
+       {\r
+               gui::IGUIElement *e = getElementFromId(260);\r
+               if(e != NULL)\r
+                       e->remove();\r
+       }\r
 }\r
 \r
 void GUIPauseMenu::regenerateGui(v2u32 screensize)\r
@@ -88,13 +93,18 @@ void GUIPauseMenu::regenerateGui(v2u32 screensize)
        */\r
        {\r
                core::rect<s32> rect(0, 0, 140, 30);\r
-               rect = rect + v2s32(size.X/2-140/2, size.Y/2-30/2-25);\r
+               rect = rect + v2s32(size.X/2-140/2, size.Y/2-30/2-50);\r
                Environment->addButton(rect, this, 256, L"Continue");\r
        }\r
        {\r
                core::rect<s32> rect(0, 0, 140, 30);\r
-               rect = rect + v2s32(size.X/2-140/2, size.Y/2-30/2+25);\r
-               Environment->addButton(rect, this, 257, L"Exit");\r
+               rect = rect + v2s32(size.X/2-140/2, size.Y/2-30/2+0);\r
+               Environment->addButton(rect, this, 260, L"Disconnect");\r
+       }\r
+       {\r
+               core::rect<s32> rect(0, 0, 140, 30);\r
+               rect = rect + v2s32(size.X/2-140/2, size.Y/2-30/2+50);\r
+               Environment->addButton(rect, this, 257, L"Exit to OS");\r
        }\r
        {\r
                core::rect<s32> rect(0, 0, 180, 240);\r
@@ -183,8 +193,13 @@ bool GUIPauseMenu::OnEvent(const SEvent& event)
                        case 256: // continue\r
                                quitMenu();\r
                                break;\r
+                       case 260: // disconnect\r
+                               m_gamecallback->disconnect();\r
+                               quitMenu();\r
+                               break;\r
                        case 257: // exit\r
-                               m_dev->closeDevice();\r
+                               m_gamecallback->exitToOS();\r
+                               quitMenu();\r
                                break;\r
                        }\r
                }\r
index 187d20edb29e1ad6e9dd4bb93f4b70595f145433..22cb65b2ceb13aa78804a112ec29e8d0216900ce 100644 (file)
@@ -23,13 +23,20 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 #include "common_irrlicht.h"\r
 #include "modalMenu.h"\r
 \r
+class IGameCallback\r
+{\r
+public:\r
+       virtual void exitToOS() = 0;\r
+       virtual void disconnect() = 0;\r
+};\r
+\r
 class GUIPauseMenu : public GUIModalMenu\r
 {\r
 public:\r
        GUIPauseMenu(gui::IGUIEnvironment* env,\r
                        gui::IGUIElement* parent, s32 id,\r
-                       IrrlichtDevice *dev,\r
-                       int *active_menu_count);\r
+                       IGameCallback *gamecallback,\r
+                       IMenuManager *menumgr);\r
        ~GUIPauseMenu();\r
        \r
        void removeChildren();\r
@@ -43,7 +50,7 @@ public:
        bool OnEvent(const SEvent& event);\r
        \r
 private:\r
-       IrrlichtDevice *m_dev;\r
+       IGameCallback *m_gamecallback;\r
 };\r
 \r
 #endif\r
index 787680bc51f00c00b5d4dd38f60a642f63aad614..38985cfa04e916a697df37dd0336e60d3c871085 100644 (file)
@@ -24,11 +24,11 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 
 GUITextInputMenu::GUITextInputMenu(gui::IGUIEnvironment* env,
                gui::IGUIElement* parent, s32 id,
-               int *active_menu_count,
+               IMenuManager *menumgr,
                TextDest *dest,
                std::wstring initial_text
 ):
-       GUIModalMenu(env, parent, id, active_menu_count),
+       GUIModalMenu(env, parent, id, menumgr),
        m_dest(dest),
        m_initial_text(initial_text)
 {
index 5db10a529bc723a8800aecf7661105eba1d045c6..c679aa9ca35bc2430317d5ab07a000d90dad0103 100644 (file)
@@ -35,7 +35,7 @@ class GUITextInputMenu : public GUIModalMenu
 public:
        GUITextInputMenu(gui::IGUIEnvironment* env,
                        gui::IGUIElement* parent, s32 id,
-                       int *active_menu_count,
+                       IMenuManager *menumgr,
                        TextDest *dest,
                        std::wstring initial_text);
        ~GUITextInputMenu();
index 3006e3fd5d60f46cbea670d36fa585f92ffaf9a5..4472246452d69d04ad93d6f4ecea201b7645a079 100644 (file)
@@ -104,6 +104,16 @@ SUGG: Meshes of blocks could be split into 6 meshes facing into
       different directions and then only those drawn that need to be\r
          - Also an 1-dimensional tile map would be nice probably\r
 \r
+Gaming ideas:\r
+-------------\r
+\r
+- How would some GTA-style ideas work?\r
+  - Cars? Stealing? Unlawful stuff and cops? Lots of guns?\r
+\r
+- RPG style?\r
+\r
+- Space racer style?\r
+\r
 Documentation:\r
 --------------\r
 \r
@@ -289,7 +299,7 @@ Doing now:
 \r
 #ifdef _MSC_VER\r
 #pragma comment(lib, "Irrlicht.lib")\r
-#pragma comment(lib, "jthread.lib")\r
+//#pragma comment(lib, "jthread.lib")\r
 #pragma comment(lib, "zlibwapi.lib")\r
 // This would get rid of the console window\r
 //#pragma comment(linker, "/subsystem:windows /ENTRY:mainCRTStartup")\r
@@ -322,6 +332,7 @@ Doing now:
 #include "guiMessageMenu.h"\r
 #include "filesys.h"\r
 #include "config.h"\r
+#include "guiMainMenu.h"\r
 \r
 IrrlichtWrapper *g_irrlicht;\r
 \r
@@ -346,15 +357,87 @@ Client *g_client = NULL;
 /*\r
        GUI Stuff\r
 */\r
+\r
 gui::IGUIEnvironment* guienv = NULL;\r
 gui::IGUIStaticText *guiroot = NULL;\r
-int g_active_menu_count = 0;\r
+\r
+class MainMenuManager : public IMenuManager\r
+{\r
+public:\r
+       virtual void createdMenu(GUIModalMenu *menu)\r
+       {\r
+               for(core::list<GUIModalMenu*>::Iterator\r
+                               i = m_stack.begin();\r
+                               i != m_stack.end(); i++)\r
+               {\r
+                       assert(*i != menu);\r
+               }\r
+\r
+               if(m_stack.size() != 0)\r
+                       (*m_stack.getLast())->setVisible(false);\r
+               m_stack.push_back(menu);\r
+       }\r
+\r
+       virtual void deletingMenu(GUIModalMenu *menu)\r
+       {\r
+               // Remove all entries if there are duplicates\r
+               bool removed_entry;\r
+               do{\r
+                       removed_entry = false;\r
+                       for(core::list<GUIModalMenu*>::Iterator\r
+                                       i = m_stack.begin();\r
+                                       i != m_stack.end(); i++)\r
+                       {\r
+                               if(*i == menu)\r
+                               {\r
+                                       m_stack.erase(i);\r
+                                       removed_entry = true;\r
+                                       break;\r
+                               }\r
+                       }\r
+               }while(removed_entry);\r
+\r
+               /*core::list<GUIModalMenu*>::Iterator i = m_stack.getLast();\r
+               assert(*i == menu);\r
+               m_stack.erase(i);*/\r
+               \r
+               if(m_stack.size() != 0)\r
+                       (*m_stack.getLast())->setVisible(true);\r
+       }\r
+\r
+       u32 menuCount()\r
+       {\r
+               return m_stack.size();\r
+       }\r
+\r
+       core::list<GUIModalMenu*> m_stack;\r
+};\r
+\r
+MainMenuManager g_menumgr;\r
 \r
 bool noMenuActive()\r
 {\r
-       return (g_active_menu_count == 0);\r
+       return (g_menumgr.menuCount() == 0);\r
 }\r
 \r
+bool g_disconnect_requested = false;\r
+\r
+class MainGameCallback : public IGameCallback\r
+{\r
+public:\r
+       virtual void exitToOS()\r
+       {\r
+               g_device->closeDevice();\r
+       }\r
+\r
+       virtual void disconnect()\r
+       {\r
+               g_disconnect_requested = true;\r
+       }\r
+};\r
+\r
+MainGameCallback g_gamecallback;\r
+\r
 // Inventory actions from the menu are buffered here before sending\r
 Queue<InventoryAction*> inventory_action_queue;\r
 // This is a copy of the inventory that the client's environment has\r
@@ -472,8 +555,8 @@ public:
                                                dstream<<DTIME<<"MyEventReceiver: "\r
                                                                <<"Launching pause menu"<<std::endl;\r
                                                // It will delete itself by itself\r
-                                               (new GUIPauseMenu(guienv, guiroot, -1, g_device,\r
-                                                               &g_active_menu_count))->drop();\r
+                                               (new GUIPauseMenu(guienv, guiroot, -1, &g_gamecallback,\r
+                                                               &g_menumgr))->drop();\r
                                                return true;\r
                                        }\r
                                        if(event.KeyInput.Key == irr::KEY_KEY_I)\r
@@ -482,7 +565,7 @@ public:
                                                                <<"Launching inventory"<<std::endl;\r
                                                (new GUIInventoryMenu(guienv, guiroot, -1,\r
                                                                &local_inventory, &inventory_action_queue,\r
-                                                               &g_active_menu_count))->drop();\r
+                                                               &g_menumgr))->drop();\r
                                                return true;\r
                                        }\r
                                        if(event.KeyInput.Key == irr::KEY_KEY_T)\r
@@ -490,7 +573,7 @@ public:
                                                TextDest *dest = new TextDestChat(g_client);\r
 \r
                                                (new GUITextInputMenu(guienv, guiroot, -1,\r
-                                                               &g_active_menu_count, dest,\r
+                                                               &g_menumgr, dest,\r
                                                                L""))->drop();\r
                                        }\r
                                }\r
@@ -1067,6 +1150,18 @@ public:
                }\r
        }\r
 \r
+       ~GUIQuickInventory()\r
+       {\r
+               for(u32 i=0; i<m_texts.size(); i++)\r
+               {\r
+                       m_texts[i]->remove();\r
+               }\r
+               for(u32 i=0; i<m_images.size(); i++)\r
+               {\r
+                       m_images[i]->remove();\r
+               }\r
+       }\r
+\r
        virtual bool OnEvent(const SEvent& event)\r
        {\r
                return false;\r
@@ -1179,9 +1274,6 @@ int main(int argc, char *argv[])
                        <<", "<<BUILD_INFO\r
                        <<std::endl;\r
        \r
-       try\r
-       {\r
-       \r
        /*\r
                Parse command line\r
        */\r
@@ -1315,137 +1407,63 @@ int main(int argc, char *argv[])
        map_params.ravines_amount = g_settings.getFloat("ravines_amount");\r
 \r
        /*\r
-               Ask some stuff\r
+               Some parameters\r
        */\r
 \r
-       std::cout<<std::endl<<std::endl;\r
-       \r
-       std::cout\r
-       <<"        .__               __                   __   "<<std::endl\r
-       <<"  _____ |__| ____   _____/  |_  ____   _______/  |_ "<<std::endl\r
-       <<" /     \\|  |/    \\_/ __ \\   __\\/ __ \\ /  ___/\\   __\\"<<std::endl\r
-       <<"|  Y Y  \\  |   |  \\  ___/|  | \\  ___/ \\___ \\  |  |  "<<std::endl\r
-       <<"|__|_|  /__|___|  /\\___  >__|  \\___  >____  > |__|  "<<std::endl\r
-       <<"      \\/        \\/     \\/          \\/     \\/        "<<std::endl\r
-       <<std::endl;\r
-\r
-       std::cout<<std::endl;\r
-       //char templine[100];\r
-       \r
-       // Port?\r
+       // Port\r
        u16 port = 30000;\r
        if(cmd_args.exists("port"))\r
-       {\r
                port = cmd_args.getU16("port");\r
-       }\r
-       else\r
-       {\r
-               port = g_settings.getU16Ask("port", "Port", 30000);\r
-               std::cout<<"-> "<<port<<std::endl;\r
-       }\r
+       else if(cmd_args.exists("port"))\r
+               port = g_settings.getU16("port");\r
        \r
-       //Map directory\r
+       // Map directory\r
        std::string map_dir = porting::path_userdata+"/map";\r
        if(cmd_args.exists("map-dir"))\r
                map_dir = cmd_args.get("map-dir");\r
        else if(g_settings.exists("map-dir"))\r
                map_dir = g_settings.get("map-dir");\r
        \r
+       // Run dedicated server if asked to\r
        if(cmd_args.getFlag("server"))\r
        {\r
                DSTACK("Dedicated server branch");\r
-               \r
-               std::cout<<std::endl;\r
-               std::cout<<"========================"<<std::endl;\r
-               std::cout<<"Running dedicated server"<<std::endl;\r
-               std::cout<<"========================"<<std::endl;\r
-               std::cout<<std::endl;\r
 \r
-               Server server(map_dir, hm_params, map_params);\r
+               // Create server\r
+               Server server(map_dir.c_str(), hm_params, map_params);\r
                server.start(port);\r
-       \r
-               for(;;)\r
-               {\r
-                       // This is kind of a hack but can be done like this\r
-                       // because server.step() is very light\r
-                       sleep_ms(30);\r
-                       server.step(0.030);\r
-\r
-                       static int counter = 0;\r
-                       counter--;\r
-                       if(counter <= 0)\r
-                       {\r
-                               counter = 10;\r
-\r
-                               core::list<PlayerInfo> list = server.getPlayerInfo();\r
-                               core::list<PlayerInfo>::Iterator i;\r
-                               static u32 sum_old = 0;\r
-                               u32 sum = PIChecksum(list);\r
-                               if(sum != sum_old)\r
-                               {\r
-                                       std::cout<<DTIME<<"Player info:"<<std::endl;\r
-                                       for(i=list.begin(); i!=list.end(); i++)\r
-                                       {\r
-                                               i->PrintLine(&std::cout);\r
-                                       }\r
-                               }\r
-                               sum_old = sum;\r
-                       }\r
-               }\r
+               \r
+               // Run server\r
+               dedicated_server_loop(server);\r
 \r
                return 0;\r
        }\r
 \r
-       bool hosting = false;\r
-       char connect_name[100] = "";\r
-\r
-       if(cmd_args.exists("address"))\r
-       {\r
-               snprintf(connect_name, 100, "%s", cmd_args.get("address").c_str());\r
-       }\r
-       else if(is_yes(g_settings.get("host_game")) == false)\r
-       {\r
-               if(g_settings.get("address") != "")\r
-               {\r
-                       std::cout<<g_settings.get("address")<<std::endl;\r
-                       snprintf(connect_name, 100, "%s", g_settings.get("address").c_str());\r
-               }\r
-               else\r
-               {\r
-                       std::cout<<"Address to connect to [empty = host a game]: ";\r
-                       std::cin.getline(connect_name, 100);\r
-               }\r
-       }\r
-       \r
-       if(connect_name[0] == 0){\r
-               snprintf(connect_name, 100, "127.0.0.1");\r
-               hosting = true;\r
-       }\r
+       /*\r
+               More parameters\r
+       */\r
        \r
-       if(hosting)\r
-               std::cout<<"> Hosting game"<<std::endl;\r
-       else\r
-               std::cout<<"> Connecting to "<<connect_name<<std::endl;\r
+       // Address to connect to\r
+       std::string address = "";\r
        \r
-       char playername[PLAYERNAME_SIZE] = "";\r
-       if(g_settings.get("name") != "")\r
+       if(cmd_args.exists("address"))\r
        {\r
-               snprintf(playername, PLAYERNAME_SIZE, "%s", g_settings.get("name").c_str());\r
+               address = cmd_args.get("address");\r
        }\r
        else\r
        {\r
-               std::cout<<"Name of player: ";\r
-               std::cin.getline(playername, PLAYERNAME_SIZE);\r
+               address = g_settings.get("address");\r
        }\r
-       std::cout<<"-> \""<<playername<<"\""<<std::endl;\r
+       \r
+       std::string playername = g_settings.get("name");\r
 \r
        /*\r
                Resolution selection\r
        */\r
        \r
        bool fullscreen = false;\r
-       u16 screenW = atoi(g_settings.get("screenW").c_str());\r
-       u16 screenH = atoi(g_settings.get("screenH").c_str());\r
+       u16 screenW = g_settings.getU16("screenW");\r
+       u16 screenH = g_settings.getU16("screenH");\r
 \r
        //\r
 \r
@@ -1520,6 +1538,172 @@ int main(int argc, char *argv[])
        skin->setColor(gui::EGDC_3D_HIGH_LIGHT, video::SColor(255,0,0,0));\r
        skin->setColor(gui::EGDC_3D_SHADOW, video::SColor(255,0,0,0));\r
        \r
+       /*\r
+               Preload some textures\r
+       */\r
+\r
+       init_content_inventory_texture_paths();\r
+       init_tile_texture_paths();\r
+       tile_materials_preload(g_irrlicht);\r
+\r
+       /*\r
+               GUI stuff\r
+       */\r
+\r
+       /*\r
+               We need some kind of a root node to be able to add\r
+               custom gui elements directly on the screen.\r
+               Otherwise they won't be automatically drawn.\r
+       */\r
+       guiroot = guienv->addStaticText(L"",\r
+                       core::rect<s32>(0, 0, 10000, 10000));\r
+       \r
+       // First line of debug text\r
+       gui::IGUIStaticText *guitext = guienv->addStaticText(\r
+                       L"",\r
+                       core::rect<s32>(5, 5, 795, 5+text_height),\r
+                       false, false);\r
+       // Second line of debug text\r
+       gui::IGUIStaticText *guitext2 = guienv->addStaticText(\r
+                       L"",\r
+                       core::rect<s32>(5, 5+(text_height+5)*1, 795, (5+text_height)*2),\r
+                       false, false);\r
+       \r
+       // At the middle of the screen\r
+       // Object infos are shown in this\r
+       gui::IGUIStaticText *guitext_info = guienv->addStaticText(\r
+                       L"",\r
+                       core::rect<s32>(100, 70, 100+400, 70+(text_height+5)),\r
+                       false, false);\r
+       \r
+       // Chat text\r
+       gui::IGUIStaticText *guitext_chat = guienv->addStaticText(\r
+                       L"",\r
+                       core::rect<s32>(0,0,0,0),\r
+                       false, true);\r
+       guitext_chat->setBackgroundColor(video::SColor(96,0,0,0));\r
+       core::list<ChatLine> chat_lines;\r
+       \r
+       /*\r
+               If an error occurs, this is set to something and the\r
+               menu-game loop is restarted. It is then displayed before\r
+               the menu.\r
+       */\r
+       std::wstring error_message = L"";\r
+       \r
+       /*\r
+               Menu-game loop\r
+       */\r
+       while(g_device->run())\r
+       {\r
+       \r
+       // This is used for catching disconnects\r
+       try\r
+       {\r
+       \r
+       /*\r
+               Out-of-game menu loop\r
+       */\r
+       \r
+       // Wait for proper parameters\r
+       for(;;)\r
+       {\r
+               // Cursor can be non-visible when coming from the game\r
+               device->getCursorControl()->setVisible(true);\r
+               // Some stuff are left to scene manager when coming from the game\r
+               // (map at least?)\r
+               smgr->clear();\r
+               // Reset or hide the debug gui texts\r
+               guitext->setText(L"Minetest-c55");\r
+               guitext2->setVisible(false);\r
+               guitext_info->setVisible(false);\r
+               guitext_chat->setVisible(false);\r
+               \r
+               // Initialize menu data\r
+               MainMenuData menudata;\r
+               menudata.address = narrow_to_wide(address);\r
+               menudata.name = narrow_to_wide(playername);\r
+               menudata.port = narrow_to_wide(itos(port));\r
+               menudata.creative_mode = g_settings.getBool("creative_mode");\r
+\r
+               GUIMainMenu *menu =\r
+                               new GUIMainMenu(guienv, guiroot, -1, \r
+                                       &g_menumgr, &menudata, &g_gamecallback);\r
+               menu->allowFocusRemoval(true);\r
+\r
+               if(error_message != L"")\r
+               {\r
+                       GUIMessageMenu *menu2 =\r
+                                       new GUIMessageMenu(guienv, guiroot, -1, \r
+                                               &g_menumgr, error_message.c_str());\r
+                       menu2->drop();\r
+                       error_message = L"";\r
+               }\r
+\r
+               video::IVideoDriver* driver = g_device->getVideoDriver();\r
+               \r
+               dstream<<"Created main menu"<<std::endl;\r
+\r
+               while(g_device->run())\r
+               {\r
+                       // Run global IrrlichtWrapper's main thread processing stuff\r
+                       g_irrlicht->Run();\r
+                       \r
+                       if(menu->getStatus() == true)\r
+                               break;\r
+\r
+                       //driver->beginScene(true, true, video::SColor(255,0,0,0));\r
+                       driver->beginScene(true, true, video::SColor(255,128,128,128));\r
+                       guienv->drawAll();\r
+                       driver->endScene();\r
+               }\r
+               \r
+               // Break out of menu-game loop to shut down cleanly\r
+               if(g_device->run() == false)\r
+                       break;\r
+               \r
+               dstream<<"Dropping main menu"<<std::endl;\r
+\r
+               menu->drop();\r
+\r
+               playername = wide_to_narrow(menudata.name);\r
+               address = wide_to_narrow(menudata.address);\r
+               port = stoi(wide_to_narrow(menudata.port));\r
+               g_settings.set("creative_mode", itos(menudata.creative_mode));\r
+               \r
+               // Check for valid parameters, restart menu if invalid.\r
+               if(playername == "")\r
+               {\r
+                       error_message = L"Name required.";\r
+                       continue;\r
+               }\r
+               \r
+               // Save settings\r
+               g_settings.set("name", playername);\r
+               g_settings.set("address", address);\r
+               g_settings.set("port", itos(port));\r
+               // Update configuration file\r
+               if(configpath != "")\r
+                       g_settings.updateConfigFile(configpath.c_str());\r
+       \r
+               // Continue to game\r
+               break;\r
+       }\r
+       \r
+       // Break out of menu-game loop to shut down cleanly\r
+       if(g_device->run() == false)\r
+               break;\r
+\r
+       /*\r
+               Make a scope here so that the client and the server and other\r
+               stuff gets removed when disconnected or the irrlicht device\r
+               is removed.\r
+       */\r
+       {\r
+\r
+       /*\r
+               Draw "Loading" screen\r
+       */\r
        const wchar_t *text = L"Loading and connecting...";\r
        core::vector2d<s32> center(screenW/2, screenH/2);\r
        core::vector2d<s32> textsize(300, text_height);\r
@@ -1533,27 +1717,14 @@ int main(int argc, char *argv[])
        guienv->drawAll();\r
        driver->endScene();\r
 \r
-       /*\r
-               Preload some textures\r
-       */\r
-\r
-       init_content_inventory_texture_paths();\r
-       init_tile_texture_paths();\r
-       tile_materials_preload(g_irrlicht);\r
-\r
-       /*\r
-               Make a scope here for the client so that it gets removed\r
-               before the irrlicht device\r
-       */\r
-       {\r
-\r
        std::cout<<DTIME<<"Creating server and client"<<std::endl;\r
        \r
        /*\r
-               Create server\r
+               Create server.\r
+               SharedPtr will delete it when it goes out of scope.\r
        */\r
        SharedPtr<Server> server;\r
-       if(hosting){\r
+       if(address == ""){\r
                server = new Server(map_dir, hm_params, map_params);\r
                server->start(port);\r
        }\r
@@ -1562,18 +1733,24 @@ int main(int argc, char *argv[])
                Create client\r
        */\r
 \r
-       Client client(device, playername, draw_control);\r
+       Client client(device, playername.c_str(), draw_control);\r
                        \r
        g_client = &client;\r
        \r
        Address connect_address(0,0,0,0, port);\r
        try{\r
-               connect_address.Resolve(connect_name);\r
+               if(address == "")\r
+                       connect_address.Resolve("localhost");\r
+               else\r
+                       connect_address.Resolve(address.c_str());\r
        }\r
        catch(ResolveError &e)\r
        {\r
                std::cout<<DTIME<<"Couldn't resolve address"<<std::endl;\r
-               return 0;\r
+               //return 0;\r
+               error_message = L"Couldn't resolve address";\r
+               gui_loadingtext->remove();\r
+               continue;\r
        }\r
        \r
        std::cout<<DTIME<<"Connecting to server..."<<std::endl;\r
@@ -1582,17 +1759,29 @@ int main(int argc, char *argv[])
        try{\r
                while(client.connectedAndInitialized() == false)\r
                {\r
+                       // Update screen\r
+                       driver->beginScene(true, true, video::SColor(255,0,0,0));\r
+                       guienv->drawAll();\r
+                       driver->endScene();\r
+\r
+                       // Update client and server\r
+\r
                        client.step(0.1);\r
-                       if(server != NULL){\r
+\r
+                       if(server != NULL)\r
                                server->step(0.1);\r
-                       }\r
+                       \r
+                       // Delay a bit\r
                        sleep_ms(100);\r
                }\r
        }\r
        catch(con::PeerNotFoundException &e)\r
        {\r
                std::cout<<DTIME<<"Timed out."<<std::endl;\r
-               return 0;\r
+               //return 0;\r
+               error_message = L"Connection timed out.";\r
+               gui_loadingtext->remove();\r
+               continue;\r
        }\r
 \r
        /*\r
@@ -1644,52 +1833,23 @@ int main(int argc, char *argv[])
        GUIQuickInventory *quick_inventory = new GUIQuickInventory\r
                        (guienv, NULL, v2s32(10, 70), 5, &local_inventory);\r
        \r
-       /*\r
-               We need some kind of a root node to be able to add\r
-               custom elements directly on the screen.\r
-               Otherwise they won't be automatically drawn.\r
-       */\r
-       guiroot = guienv->addStaticText(L"",\r
-                       core::rect<s32>(0, 0, 10000, 10000));\r
-       \r
        // Test the text input system\r
-       /*(new GUITextInputMenu(guienv, guiroot, -1, &g_active_menu_count,\r
+       /*(new GUITextInputMenu(guienv, guiroot, -1, &g_menumgr,\r
                        NULL))->drop();*/\r
        /*GUIMessageMenu *menu =\r
                        new GUIMessageMenu(guienv, guiroot, -1, \r
-                               &g_active_menu_count,\r
+                               &g_menumgr,\r
                                L"Asd");\r
        menu->drop();*/\r
        \r
        // Launch pause menu\r
-       (new GUIPauseMenu(guienv, guiroot, -1, g_device,\r
-                       &g_active_menu_count))->drop();\r
-\r
-       // First line of debug text\r
-       gui::IGUIStaticText *guitext = guienv->addStaticText(\r
-                       L"Minetest-c55",\r
-                       core::rect<s32>(5, 5, 795, 5+textsize.Y),\r
-                       false, false);\r
-       // Second line of debug text\r
-       gui::IGUIStaticText *guitext2 = guienv->addStaticText(\r
-                       L"",\r
-                       core::rect<s32>(5, 5+(textsize.Y+5)*1, 795, (5+textsize.Y)*2),\r
-                       false, false);\r
+       (new GUIPauseMenu(guienv, guiroot, -1, &g_gamecallback,\r
+                       &g_menumgr))->drop();\r
        \r
-       // At the middle of the screen\r
-       // Object infos are shown in this\r
-       gui::IGUIStaticText *guitext_info = guienv->addStaticText(\r
-                       L"test",\r
-                       core::rect<s32>(100, 70, 100+400, 70+(textsize.Y+5)),\r
-                       false, false);\r
-       \r
-       // Chat text\r
-       gui::IGUIStaticText *chat_guitext = guienv->addStaticText(\r
-                       L"Chat here\nOther line\nOther line\nOther line\nOther line",\r
-                       core::rect<s32>(70, 60, 795, 150),\r
-                       false, true);\r
-       chat_guitext->setBackgroundColor(video::SColor(96,0,0,0));\r
-       core::list<ChatLine> chat_lines;\r
+       // Enable texts\r
+       guitext2->setVisible(true);\r
+       guitext_info->setVisible(true);\r
+       guitext_chat->setVisible(true);\r
        \r
        /*\r
                Some statistics are collected in these\r
@@ -1715,6 +1875,12 @@ int main(int argc, char *argv[])
 \r
        while(device->run())\r
        {\r
+               if(g_disconnect_requested)\r
+               {\r
+                       g_disconnect_requested = false;\r
+                       break;\r
+               }\r
+\r
                /*\r
                        Run global IrrlichtWrapper's main thread processing stuff\r
                */\r
@@ -2042,7 +2208,7 @@ int main(int argc, char *argv[])
                                                                narrow_to_wide(sign_object->getText());\r
 \r
                                                (new GUITextInputMenu(guienv, guiroot, -1,\r
-                                                               &g_active_menu_count, dest,\r
+                                                               &g_menumgr, dest,\r
                                                                wtext))->drop();\r
                                        }\r
                                }\r
@@ -2519,7 +2685,7 @@ int main(int argc, char *argv[])
                                                it = chat_lines.begin();\r
                                chat_lines.erase(it);\r
                        }\r
-                       chat_guitext->setText(whole.c_str());\r
+                       guitext_chat->setText(whole.c_str());\r
                        // Update gui element size and position\r
                        core::rect<s32> rect(\r
                                        10,\r
@@ -2527,12 +2693,12 @@ int main(int argc, char *argv[])
                                        screensize.X - 10,\r
                                        screensize.Y - 10\r
                        );\r
-                       chat_guitext->setRelativePosition(rect);\r
+                       guitext_chat->setRelativePosition(rect);\r
 \r
                        if(chat_lines.size() == 0)\r
-                               chat_guitext->setVisible(false);\r
+                               guitext_chat->setVisible(false);\r
                        else\r
-                               chat_guitext->setVisible(true);\r
+                               guitext_chat->setVisible(true);\r
                }\r
 \r
                /*\r
@@ -2667,22 +2833,7 @@ int main(int argc, char *argv[])
 \r
        delete quick_inventory;\r
 \r
-       } // client is deleted at this point\r
-       \r
-       delete g_input;\r
-\r
-       /*\r
-               In the end, delete the Irrlicht device.\r
-       */\r
-       device->drop();\r
-       \r
-       /*\r
-               Update configuration file\r
-       */\r
-       /*if(configpath != "")\r
-       {\r
-               g_settings.updateConfigFile(configpath.c_str());\r
-       }*/\r
+       } // client and server are deleted at this point\r
 \r
        } //try\r
        catch(con::PeerNotFoundException &e)\r
@@ -2693,7 +2844,7 @@ int main(int argc, char *argv[])
                {\r
                        GUIMessageMenu *menu =\r
                                        new GUIMessageMenu(guienv, guiroot, -1, \r
-                                               &g_active_menu_count,\r
+                                               &g_menumgr,\r
                                                L"Connection timed out");\r
 \r
                        video::IVideoDriver* driver = g_device->getVideoDriver();\r
@@ -2713,6 +2864,23 @@ int main(int argc, char *argv[])
                }*/\r
        }\r
 \r
+       } // Menu-game loop\r
+       \r
+       delete g_input;\r
+\r
+       /*\r
+               In the end, delete the Irrlicht device.\r
+       */\r
+       device->drop();\r
+       \r
+       /*\r
+               Update configuration file\r
+       */\r
+       /*if(configpath != "")\r
+       {\r
+               g_settings.updateConfigFile(configpath.c_str());\r
+       }*/\r
+\r
        END_DEBUG_EXCEPTION_HANDLER\r
        \r
        debugstreams_deinit();\r
index 1889cccf69cd2511efcafcc73dd0a362eada80f2..973e126787f893057284606c6e3b14d135fcdff7 100644 (file)
@@ -1372,8 +1372,12 @@ void Map::transformLiquids(core::map<v3s16, MapBlock*> & modified_blocks)
 
        u32 loopcount = 0;
        u32 initial_size = m_transforming_liquid.size();
+
        while(m_transforming_liquid.size() != 0)
        {
+               /*
+                       Get a queued transforming liquid node
+               */
                v3s16 p0 = m_transforming_liquid.pop_front();
 
                MapNode n0 = getNode(p0);
@@ -1557,6 +1561,7 @@ void Map::transformLiquids(core::map<v3s16, MapBlock*> & modified_blocks)
                        v3s16 p2 = p0 + dirs_to[i];
 
                        MapNode n2 = getNode(p2);
+                       //dstream<<"[1] n2.param="<<(int)n2.param<<std::endl;
 
                        if(content_liquid(n2.d))
                        {
@@ -1605,6 +1610,8 @@ void Map::transformLiquids(core::map<v3s16, MapBlock*> & modified_blocks)
                                n2_changed = true;
                                flowed = true;
                        }
+                       
+                       //dstream<<"[2] n2.param="<<(int)n2.param<<std::endl;
 
                        if(n2_changed)
                        {
index 8de81b7741c418cf4b761de8ae13e3b4a717d061..5cfb60aa288898c502bf9db5a2102b397346654b 100644 (file)
@@ -141,6 +141,8 @@ MapNode MapBlock::getNodeParentNoEx(v3s16 p)
                n: getNodeParent(p)
                n2: getNodeParent(p + face_dir)
                face_dir: axis oriented unit vector from p to p2
+       
+       returns encoded light value.
 */
 u8 MapBlock::getFaceLight(u32 daynight_ratio, MapNode n, MapNode n2,
                v3s16 face_dir)
@@ -721,6 +723,9 @@ void MapBlock::updateMesh(u32 daynight_ratio)
 
                MapNode &n = getNodeRef(x,y,z);
                
+               /*
+                       Add torches to mesh
+               */
                if(n.d == CONTENT_TORCH)
                {
                        video::SColor c(255,255,255,255);
@@ -779,6 +784,9 @@ void MapBlock::updateMesh(u32 daynight_ratio)
                        // Add to mesh collector
                        collector.append(material, vertices, 4, indices, 6);
                }
+               /*
+                       Add flowing water to mesh
+               */
                else if(n.d == CONTENT_WATER)
                {
                        bool top_is_water = false;
@@ -787,8 +795,9 @@ void MapBlock::updateMesh(u32 daynight_ratio)
                                if(n.d == CONTENT_WATER || n.d == CONTENT_WATERSOURCE)
                                        top_is_water = true;
                        }catch(InvalidPositionException &e){}
-
-                       video::SColor c(128,255,255,255);
+                       
+                       u8 l = decode_light(n.getLightBlend(daynight_ratio));
+                       video::SColor c(128,l,l,l);
                        
                        // Neighbor water levels (key = relative position)
                        // Includes current node
index e2e8b29f640045c3e4b5418c7385cb756c7fbce5..2323a7e427cab7cf298f7d0e983bf5d7468abc6d 100644 (file)
@@ -22,6 +22,16 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 
 #include "common_irrlicht.h"
 
+class GUIModalMenu;
+
+class IMenuManager
+{
+public:
+       // A GUIModalMenu calls these when this class is passed as a parameter
+       virtual void createdMenu(GUIModalMenu *menu) = 0;
+       virtual void deletingMenu(GUIModalMenu *menu) = 0;
+};
+
 /*
        Remember to drop() the menu after creating, so that it can
        remove itself when it wants to.
@@ -32,21 +42,26 @@ class GUIModalMenu : public gui::IGUIElement
 public:
        GUIModalMenu(gui::IGUIEnvironment* env,
                        gui::IGUIElement* parent, s32 id,
-                       int *active_menu_count):
+                       IMenuManager *menumgr):
                IGUIElement(gui::EGUIET_ELEMENT, env, parent, id,
                                core::rect<s32>(0,0,100,100))
        {
-               m_active_menu_count = active_menu_count;
+               m_menumgr = menumgr;
                m_allow_focus_removal = false;
                m_screensize_old = v2u32(0,0);
 
                setVisible(true);
                Environment->setFocus(this);
-               (*m_active_menu_count)++;
+               m_menumgr->createdMenu(this);
        }
        virtual ~GUIModalMenu()
        {
-               (*m_active_menu_count)--;
+               m_menumgr->deletingMenu(this);
+       }
+
+       void allowFocusRemoval(bool allow)
+       {
+               m_allow_focus_removal = allow;
        }
 
        bool canTakeFocus(gui::IGUIElement *e)
@@ -75,18 +90,35 @@ public:
        */
        void quitMenu()
        {
-               m_allow_focus_removal = true;
+               allowFocusRemoval(true);
                // This removes Environment's grab on us
                Environment->removeFocus(this);
                this->remove();
        }
 
+       void removeChildren()
+       {
+               const core::list<gui::IGUIElement*> &children = getChildren();
+               core::list<gui::IGUIElement*> children_copy;
+               for(core::list<gui::IGUIElement*>::ConstIterator
+                               i = children.begin(); i != children.end(); i++)
+               {
+                       children_copy.push_back(*i);
+               }
+               for(core::list<gui::IGUIElement*>::Iterator
+                               i = children_copy.begin();
+                               i != children_copy.end(); i++)
+               {
+                       (*i)->remove();
+               }
+       }
+
        virtual void regenerateGui(v2u32 screensize) = 0;
        virtual void drawMenu() = 0;
        virtual bool OnEvent(const SEvent& event) { return false; };
        
 private:
-       int *m_active_menu_count;
+       IMenuManager *m_menumgr;
        // This might be necessary to expose to the implementation if it
        // wants to launch other menus
        bool m_allow_focus_removal;
index e06e69d8767879debebe28d6e1ac0342b6cda4a6..a979086ea769794e80338214c46eae2d8176d366 100644 (file)
@@ -53,6 +53,10 @@ void * ServerThread::Thread()
                catch(con::NoIncomingDataException &e)
                {
                }
+               catch(con::PeerNotFoundException &e)
+               {
+                       dout_server<<"Server: PeerNotFoundException"<<std::endl;
+               }
        }
        
        END_DEBUG_EXCEPTION_HANDLER
@@ -3436,4 +3440,44 @@ void Server::handlePeerChanges()
        }
 }
 
+void dedicated_server_loop(Server &server)
+{
+       DSTACK(__FUNCTION_NAME);
+       
+       std::cout<<std::endl;
+       std::cout<<"========================"<<std::endl;
+       std::cout<<"Running dedicated server"<<std::endl;
+       std::cout<<"========================"<<std::endl;
+       std::cout<<std::endl;
+
+       for(;;)
+       {
+               // This is kind of a hack but can be done like this
+               // because server.step() is very light
+               sleep_ms(30);
+               server.step(0.030);
+
+               static int counter = 0;
+               counter--;
+               if(counter <= 0)
+               {
+                       counter = 10;
+
+                       core::list<PlayerInfo> list = server.getPlayerInfo();
+                       core::list<PlayerInfo>::Iterator i;
+                       static u32 sum_old = 0;
+                       u32 sum = PIChecksum(list);
+                       if(sum != sum_old)
+                       {
+                               std::cout<<DTIME<<"Player info:"<<std::endl;
+                               for(i=list.begin(); i!=list.end(); i++)
+                               {
+                                       i->PrintLine(&std::cout);
+                               }
+                       }
+                       sum_old = sum;
+               }
+       }
+}
+
 
index 9c655b9abf6c9690bab1d7170662216d5ba61a38..a3e1897d9360d23dd270fcfc0b4b463c70adf840 100644 (file)
@@ -397,7 +397,6 @@ public:
 
        // Environment and Connection must be locked when called
        void SendBlockNoLock(u16 peer_id, MapBlock *block, u8 ver);
-       //TODO: Sending of many blocks in a single packet
        
        // Environment and Connection must be locked when called
        //void SendSectorMeta(u16 peer_id, core::list<v2s16> ps, u8 ver);
@@ -420,7 +419,6 @@ private:
 
        // Virtual methods from con::PeerHandler.
        // As of now, these create and remove clients and players.
-       // TODO: Make it possible to leave players on server.
        void peerAdded(con::Peer *peer);
        void deletingPeer(con::Peer *peer, bool timeout);
        
@@ -514,5 +512,10 @@ private:
        friend class RemoteClient;
 };
 
+/*
+       Runs a simple dedicated server loop
+*/
+void dedicated_server_loop(Server &server);
+
 #endif
 
index 3d015b73231039d583198902552f786bcdc329c5..d5be5b8acebe0ad355c75d0bc1408334e533ccd3 100644 (file)
@@ -301,14 +301,6 @@ int main(int argc, char *argv[])
                                <<std::endl;
        }
        
-       DSTACK("Dedicated server branch");
-       
-       std::cout<<std::endl;
-       std::cout<<"========================"<<std::endl;
-       std::cout<<"Running dedicated server"<<std::endl;
-       std::cout<<"========================"<<std::endl;
-       std::cout<<std::endl;
-       
        // Figure out path to map
        std::string map_dir = porting::path_userdata+"/map";
        if(cmd_args.exists("map-dir"))
@@ -316,38 +308,13 @@ int main(int argc, char *argv[])
        else if(g_settings.exists("map-dir"))
                map_dir = g_settings.get("map-dir");
        
+       // Create server
        Server server(map_dir.c_str(), hm_params, map_params);
        server.start(port);
-
-       for(;;)
-       {
-               // This is kind of a hack but can be done like this
-               // because server.step() is very light
-               sleep_ms(30);
-               server.step(0.030);
-
-               static int counter = 0;
-               counter--;
-               if(counter <= 0)
-               {
-                       counter = 10;
-
-                       core::list<PlayerInfo> list = server.getPlayerInfo();
-                       core::list<PlayerInfo>::Iterator i;
-                       static u32 sum_old = 0;
-                       u32 sum = PIChecksum(list);
-                       if(sum != sum_old)
-                       {
-                               std::cout<<DTIME<<"Player info:"<<std::endl;
-                               for(i=list.begin(); i!=list.end(); i++)
-                               {
-                                       i->PrintLine(&std::cout);
-                               }
-                       }
-                       sum_old = sum;
-               }
-       }
-
+       
+       // Run server
+       dedicated_server_loop(server);
+       
        } //try
        catch(con::PeerNotFoundException &e)
        {
index 897390dba8d7f2ff7736ee09c2beff803d6e7f47..8ab2345e1aad863fcbcd90b7e847849bf37c8805 100644 (file)
@@ -646,7 +646,7 @@ inline std::string lowercase(const std::string &s)
 inline bool is_yes(const std::string &s)
 {
        std::string s2 = lowercase(trim(s));
-       if(s2 == "y" || s2 == "yes" || s2 == "true")
+       if(s2 == "y" || s2 == "yes" || s2 == "true" || s2 == "1")
                return true;
        return false;
 }