Code refactoring; split half of main.cpp to game.cpp.

This commit is contained in:
Perttu Ahola 2011-04-23 18:31:31 +03:00
parent 9f17664336
commit 1995b59320
9 changed files with 2385 additions and 2262 deletions

@ -90,6 +90,7 @@ set(minetest_SRCS
guiPauseMenu.cpp guiPauseMenu.cpp
client.cpp client.cpp
tile.cpp tile.cpp
game.cpp
main.cpp main.cpp
) )

@ -621,7 +621,7 @@ void Client::ProcessData(u8 *data, u32 datasize, u16 sender_peer_id)
p.Y = readS16(&data[4]); p.Y = readS16(&data[4]);
p.Z = readS16(&data[6]); p.Z = readS16(&data[6]);
//TimeTaker t1("TOCLIENT_REMOVENODE", g_device); //TimeTaker t1("TOCLIENT_REMOVENODE");
// This will clear the cracking animation after digging // This will clear the cracking animation after digging
((ClientMap&)m_env.getMap()).clearTempMod(p); ((ClientMap&)m_env.getMap()).clearTempMod(p);
@ -638,7 +638,7 @@ void Client::ProcessData(u8 *data, u32 datasize, u16 sender_peer_id)
p.Y = readS16(&data[4]); p.Y = readS16(&data[4]);
p.Z = readS16(&data[6]); p.Z = readS16(&data[6]);
//TimeTaker t1("TOCLIENT_ADDNODE", g_device); //TimeTaker t1("TOCLIENT_ADDNODE");
MapNode n; MapNode n;
n.deSerialize(&data[8], ser_version); n.deSerialize(&data[8], ser_version);

@ -438,7 +438,7 @@ void ServerEnvironment::step(float dtime)
bool footprints = g_settings.getBool("footprints"); bool footprints = g_settings.getBool("footprints");
{ {
//TimeTaker timer("Server m_map->timerUpdate()", g_device); //TimeTaker timer("Server m_map->timerUpdate()");
m_map->timerUpdate(dtime); m_map->timerUpdate(dtime);
} }
@ -1027,7 +1027,7 @@ void ClientEnvironment::step(float dtime)
bool footprints = g_settings.getBool("footprints"); bool footprints = g_settings.getBool("footprints");
{ {
//TimeTaker timer("Client m_map->timerUpdate()", g_device); //TimeTaker timer("Client m_map->timerUpdate()");
m_map->timerUpdate(dtime); m_map->timerUpdate(dtime);
} }

1975
src/game.cpp Normal file

File diff suppressed because it is too large Load Diff

76
src/game.h Normal file

@ -0,0 +1,76 @@
/*
Minetest-c55
Copyright (C) 2011 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 GAME_HEADER
#define GAME_HEADER
#include "common_irrlicht.h"
#include <string>
class InputHandler
{
public:
InputHandler()
{
}
virtual ~InputHandler()
{
}
virtual bool isKeyDown(EKEY_CODE keyCode) = 0;
virtual bool wasKeyDown(EKEY_CODE keyCode) = 0;
virtual v2s32 getMousePos() = 0;
virtual void setMousePos(s32 x, s32 y) = 0;
virtual bool getLeftState() = 0;
virtual bool getRightState() = 0;
virtual bool getLeftClicked() = 0;
virtual bool getRightClicked() = 0;
virtual void resetLeftClicked() = 0;
virtual void resetRightClicked() = 0;
virtual bool getLeftReleased() = 0;
virtual bool getRightReleased() = 0;
virtual void resetLeftReleased() = 0;
virtual void resetRightReleased() = 0;
virtual s32 getMouseWheel() = 0;
virtual void step(float dtime) {};
virtual void clear() {};
};
void the_game(
bool &kill,
bool random_input,
InputHandler *input,
IrrlichtDevice *device,
gui::IGUIFont* font,
std::string map_dir,
std::string playername,
std::string address,
u16 port,
std::wstring &error_message
);
#endif

File diff suppressed because it is too large Load Diff

@ -46,5 +46,98 @@ extern std::ostream *derr_server_ptr;
#define dout_server (*dout_server_ptr) #define dout_server (*dout_server_ptr)
#define derr_server (*derr_server_ptr) #define derr_server (*derr_server_ptr)
/*
All kinds of stuff that needs to be exposed from main.cpp
*/
#include "modalMenu.h"
#include "guiPauseMenu.h" //For IGameCallback
extern gui::IGUIEnvironment* guienv;
extern gui::IGUIStaticText *guiroot;
// Handler for the modal menus
class MainMenuManager : public IMenuManager
{
public:
virtual void createdMenu(GUIModalMenu *menu)
{
for(core::list<GUIModalMenu*>::Iterator
i = m_stack.begin();
i != m_stack.end(); i++)
{
assert(*i != menu);
}
if(m_stack.size() != 0)
(*m_stack.getLast())->setVisible(false);
m_stack.push_back(menu);
}
virtual void deletingMenu(GUIModalMenu *menu)
{
// Remove all entries if there are duplicates
bool removed_entry;
do{
removed_entry = false;
for(core::list<GUIModalMenu*>::Iterator
i = m_stack.begin();
i != m_stack.end(); i++)
{
if(*i == menu)
{
m_stack.erase(i);
removed_entry = true;
break;
}
}
}while(removed_entry);
/*core::list<GUIModalMenu*>::Iterator i = m_stack.getLast();
assert(*i == menu);
m_stack.erase(i);*/
if(m_stack.size() != 0)
(*m_stack.getLast())->setVisible(true);
}
u32 menuCount()
{
return m_stack.size();
}
core::list<GUIModalMenu*> m_stack;
};
extern MainMenuManager g_menumgr;
extern bool noMenuActive();
class MainGameCallback : public IGameCallback
{
public:
MainGameCallback(IrrlichtDevice *a_device):
disconnect_requested(false),
device(a_device)
{
}
virtual void exitToOS()
{
device->closeDevice();
}
virtual void disconnect()
{
disconnect_requested = true;
}
bool disconnect_requested;
IrrlichtDevice *device;
};
extern MainGameCallback *g_gamecallback;
#endif #endif

@ -1,6 +1,6 @@
/* /*
Minetest-c55 Minetest-c55
Copyright (C) 2010 celeron55, Perttu Ahola <celeron55@gmail.com> Copyright (C) 2010-2011 celeron55, Perttu Ahola <celeron55@gmail.com>
This program is free software; you can redistribute it and/or modify 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 it under the terms of the GNU General Public License as published by
@ -17,10 +17,6 @@ with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/ */
/*
(c) 2010 Perttu Ahola <celeron55@gmail.com>
*/
#include "player.h" #include "player.h"
#include "map.h" #include "map.h"
#include "connection.h" #include "connection.h"

@ -1,6 +1,6 @@
/* /*
Minetest-c55 Minetest-c55
Copyright (C) 2010 celeron55, Perttu Ahola <celeron55@gmail.com> Copyright (C) 2010-2011 celeron55, Perttu Ahola <celeron55@gmail.com>
This program is free software; you can redistribute it and/or modify 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 it under the terms of the GNU General Public License as published by
@ -17,10 +17,6 @@ with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/ */
/*
(c) 2010 Perttu Ahola <celeron55@gmail.com>
*/
#ifndef PLAYER_HEADER #ifndef PLAYER_HEADER
#define PLAYER_HEADER #define PLAYER_HEADER