]> git.lizzy.rs Git - dragonfireclient.git/blob - src/main.h
Code refactoring; split half of main.cpp to game.cpp.
[dragonfireclient.git] / src / main.h
1 /*
2 Minetest-c55
3 Copyright (C) 2010 celeron55, Perttu Ahola <celeron55@gmail.com>
4
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License along
16 with this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 */
19
20 #ifndef MAIN_HEADER
21 #define MAIN_HEADER
22
23 // Settings
24 #include "utility.h"
25 extern Settings g_settings;
26
27 // This makes and maps textures
28 #include "tile.h"
29 extern ITextureSource *g_texturesource;
30
31 // Debug streams
32
33 #include <fstream>
34
35 extern std::ostream *dout_con_ptr;
36 extern std::ostream *derr_con_ptr;
37 extern std::ostream *dout_client_ptr;
38 extern std::ostream *derr_client_ptr;
39 extern std::ostream *dout_server_ptr;
40 extern std::ostream *derr_server_ptr;
41
42 #define dout_con (*dout_con_ptr)
43 #define derr_con (*derr_con_ptr)
44 #define dout_client (*dout_client_ptr)
45 #define derr_client (*derr_client_ptr)
46 #define dout_server (*dout_server_ptr)
47 #define derr_server (*derr_server_ptr)
48
49 /*
50         All kinds of stuff that needs to be exposed from main.cpp
51 */
52
53 #include "modalMenu.h"
54 #include "guiPauseMenu.h" //For IGameCallback
55
56 extern gui::IGUIEnvironment* guienv;
57 extern gui::IGUIStaticText *guiroot;
58
59 // Handler for the modal menus
60
61 class MainMenuManager : public IMenuManager
62 {
63 public:
64         virtual void createdMenu(GUIModalMenu *menu)
65         {
66                 for(core::list<GUIModalMenu*>::Iterator
67                                 i = m_stack.begin();
68                                 i != m_stack.end(); i++)
69                 {
70                         assert(*i != menu);
71                 }
72
73                 if(m_stack.size() != 0)
74                         (*m_stack.getLast())->setVisible(false);
75                 m_stack.push_back(menu);
76         }
77
78         virtual void deletingMenu(GUIModalMenu *menu)
79         {
80                 // Remove all entries if there are duplicates
81                 bool removed_entry;
82                 do{
83                         removed_entry = false;
84                         for(core::list<GUIModalMenu*>::Iterator
85                                         i = m_stack.begin();
86                                         i != m_stack.end(); i++)
87                         {
88                                 if(*i == menu)
89                                 {
90                                         m_stack.erase(i);
91                                         removed_entry = true;
92                                         break;
93                                 }
94                         }
95                 }while(removed_entry);
96
97                 /*core::list<GUIModalMenu*>::Iterator i = m_stack.getLast();
98                 assert(*i == menu);
99                 m_stack.erase(i);*/
100                 
101                 if(m_stack.size() != 0)
102                         (*m_stack.getLast())->setVisible(true);
103         }
104
105         u32 menuCount()
106         {
107                 return m_stack.size();
108         }
109
110         core::list<GUIModalMenu*> m_stack;
111 };
112
113 extern MainMenuManager g_menumgr;
114
115 extern bool noMenuActive();
116
117 class MainGameCallback : public IGameCallback
118 {
119 public:
120         MainGameCallback(IrrlichtDevice *a_device):
121                 disconnect_requested(false),
122                 device(a_device)
123         {
124         }
125
126         virtual void exitToOS()
127         {
128                 device->closeDevice();
129         }
130
131         virtual void disconnect()
132         {
133                 disconnect_requested = true;
134         }
135
136         bool disconnect_requested;
137         IrrlichtDevice *device;
138 };
139
140 extern MainGameCallback *g_gamecallback;
141
142 #endif
143