/
clientserverworld.h
143 lines (119 loc) · 3.9 KB
/
clientserverworld.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
/** @file worldsystem.h World subsystem.
*
* @authors Copyright © 2003-2017 Jaakko Keränen <jaakko.keranen@iki.fi>
* @authors Copyright © 2006-2015 Daniel Swanson <danij@dengine.net>
*
* @par License
* GPL: http://www.gnu.org/licenses/gpl.html
*
* <small>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 St, Fifth Floor, Boston, MA
* 02110-1301 USA</small>
*/
#ifndef WORLDSYSTEM_H
#define WORLDSYSTEM_H
#include <de/liblegacy.h>
#include <de/Error>
#include <de/Observers>
#include <de/Scheduler>
#include <de/Vector>
#include <doomsday/world/world.h>
#include <doomsday/uri.h>
namespace de { class Context; }
namespace world { class Map; }
/**
* Ideas for improvement:
*
* "background loading" - it would be very cool if map loading happened in
* another thread. This way we could be keeping busy while players watch the
* intermission animations.
*
* "seamless world" - multiple concurrent maps with no perceivable delay when
* players move between them.
*
* @ingroup world
*/
class ClientServerWorld : public world::World
{
public:
/// No map is currently loaded. @ingroup errors
DE_ERROR(MapError);
#ifdef __CLIENT__
/// Notified when a new frame begins.
DE_AUDIENCE(FrameBegin, void worldSystemFrameBegins(bool resetNextViewer))
/// Notified when the "current" frame ends.
DE_AUDIENCE(FrameEnd, void worldSystemFrameEnds())
#endif
public:
/**
* Construct a new world system (no map is loaded by default).
*/
ClientServerWorld();
/**
* To be called to reset the world back to the initial state. Any currently
* loaded map will be unloaded and player states are re-initialized.
*
* @todo World should observe GameChange.
*/
void reset();
/**
* To be called following an engine reset to update the world state.
*/
void update();
de::Scheduler &scheduler();
/**
* Provides access to the currently loaded map.
*/
world::Map &map() const;
/**
* Returns a pointer to the currently loaded map, if any.
*/
inline world::Map *mapPtr() const { return hasMap() ? &map() : nullptr; }
/**
* @param uri Universal resource identifier (URI) for the map to change to.
* If an empty URI is specified the current map will be unloaded.
*
* @return @c true= the map change completed successfully.
*/
bool changeMap(const res::Uri &uri);
/**
* Unload the currently loaded map (if any).
*
* @see changeMap()
*/
inline void unloadMap() { changeMap(res::Uri()); }
/**
* Advance time in the world.
*
* @param delta Time delta to apply.
*/
void advanceTime(timespan_t delta);
/**
* Returns the current world time.
*/
timespan_t time() const;
#ifdef __CLIENT__
bool allowAdvanceTime() const override;
void tick(timespan_t) override;
/**
* To be called at the beginning of a render frame, so that we can prepare for
* drawing view(s) of the current map.
*/
void beginFrame(bool resetNextViewer = false);
/**
* To be called at the end of a render frame, so that we can finish up any tasks
* that must be completed after view(s) have been drawn.
*/
void endFrame();
#endif // __CLIENT__
private:
DE_PRIVATE(d)
};
#endif // WORLDSYSTEM_H