#viewing_range_nodes_min = 35
#screenW = 800
#screenH = 600
-#host_game =
#port = 30000
#address = kray.dy.fi
#name =
/>\r
<Tool\r
Name="VCLinkerTool"\r
- AdditionalLibraryDirectories=""C:\Program Files\Microsoft Platform SDK for Windows Server 2003 R2\Lib";"..\jthread\jthread-1.2.1\Release";"..\irrlicht\irrlicht-1.7.1\lib\Win32-visualstudio";..\zlib125dll\dll32"\r
+ AdditionalLibraryDirectories=""C:\Program Files\Microsoft Platform SDK for Windows Server 2003 R2\Lib";"..\irrlicht\irrlicht-1.7.1\lib\Win32-visualstudio";..\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
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"
)
set(minetest_SRCS
+ guiMainMenu.cpp
porting.cpp
guiMessageMenu.cpp
materials.cpp
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}
${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)
# 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)
} //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;
}
}
if(node == NULL){
// Peer not found
- throw PeerNotFoundException("Peer not found (possible timeout)");
+ throw PeerNotFoundException("GetPeer: Peer not found (possible timeout)");
}
// Error checking
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", "");
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);
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;
gui::IGUIElement* parent, s32 id,
Inventory *inventory,
Queue<InventoryAction*> *actions,
- int *active_menu_count);
+ IMenuManager *menumgr);
~GUIInventoryMenu();
void removeChildren();
--- /dev/null
+/*
+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;
+}
+
--- /dev/null
+/*
+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
+
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)
{
public:
GUIMessageMenu(gui::IGUIEnvironment* env,
gui::IGUIElement* parent, s32 id,
- int *active_menu_count,
+ IMenuManager *menumgr,
std::wstring message_text);
~GUIMessageMenu();
\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
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
*/\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
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
#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
bool OnEvent(const SEvent& event);\r
\r
private:\r
- IrrlichtDevice *m_dev;\r
+ IGameCallback *m_gamecallback;\r
};\r
\r
#endif\r
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)
{
public:
GUITextInputMenu(gui::IGUIEnvironment* env,
gui::IGUIElement* parent, s32 id,
- int *active_menu_count,
+ IMenuManager *menumgr,
TextDest *dest,
std::wstring initial_text);
~GUITextInputMenu();
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
\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
#include "guiMessageMenu.h"\r
#include "filesys.h"\r
#include "config.h"\r
+#include "guiMainMenu.h"\r
\r
IrrlichtWrapper *g_irrlicht;\r
\r
/*\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
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
<<"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
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
}\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
<<", "<<BUILD_INFO\r
<<std::endl;\r
\r
- try\r
- {\r
- \r
/*\r
Parse command line\r
*/\r
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
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
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
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
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
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
\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
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
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
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
\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
{\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
}*/\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
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);
v3s16 p2 = p0 + dirs_to[i];
MapNode n2 = getNode(p2);
+ //dstream<<"[1] n2.param="<<(int)n2.param<<std::endl;
if(content_liquid(n2.d))
{
n2_changed = true;
flowed = true;
}
+
+ //dstream<<"[2] n2.param="<<(int)n2.param<<std::endl;
if(n2_changed)
{
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)
MapNode &n = getNodeRef(x,y,z);
+ /*
+ Add torches to mesh
+ */
if(n.d == CONTENT_TORCH)
{
video::SColor c(255,255,255,255);
// 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;
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
#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.
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)
*/
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;
catch(con::NoIncomingDataException &e)
{
}
+ catch(con::PeerNotFoundException &e)
+ {
+ dout_server<<"Server: PeerNotFoundException"<<std::endl;
+ }
}
END_DEBUG_EXCEPTION_HANDLER
}
}
+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;
+ }
+ }
+}
+
// 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);
// 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);
friend class RemoteClient;
};
+/*
+ Runs a simple dedicated server loop
+*/
+void dedicated_server_loop(Server &server);
+
#endif
<<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"))
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)
{
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;
}