]> git.lizzy.rs Git - minetest.git/blob - src/environment.h
4c00ef9e85890c9b83c8d743db02c5ddec3512cf
[minetest.git] / src / environment.h
1 /*
2 Minetest
3 Copyright (C) 2010-2013 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 Lesser General Public License as published by
7 the Free Software Foundation; either version 2.1 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 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser 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 ENVIRONMENT_HEADER
21 #define ENVIRONMENT_HEADER
22
23 /*
24         This class is the game's environment.
25         It contains:
26         - The map
27         - Players
28         - Other objects
29         - The current time in the game
30         - etc.
31 */
32
33 #include <list>
34 #include <queue>
35 #include <map>
36 #include <atomic>
37 #include <mutex>
38 #include "irr_v3d.h"
39 #include "activeobject.h"
40 #include "util/numeric.h"
41 #include "network/networkprotocol.h" // for AccessDeniedCode
42
43 class IGameDef;
44 class Map;
45
46 class Environment
47 {
48 public:
49         // Environment will delete the map passed to the constructor
50         Environment(IGameDef *gamedef);
51         virtual ~Environment();
52
53         /*
54                 Step everything in environment.
55                 - Move players
56                 - Step mobs
57                 - Run timers of map
58         */
59         virtual void step(f32 dtime) = 0;
60
61         virtual Map &getMap() = 0;
62
63         u32 getDayNightRatio();
64
65         // 0-23999
66         virtual void setTimeOfDay(u32 time);
67         u32 getTimeOfDay();
68         float getTimeOfDayF();
69
70         void stepTimeOfDay(float dtime);
71
72         void setTimeOfDaySpeed(float speed);
73
74         void setDayNightRatioOverride(bool enable, u32 value);
75
76         u32 getDayCount();
77
78         // counter used internally when triggering ABMs
79         u32 m_added_objects;
80
81         IGameDef *getGameDef() { return m_gamedef; }
82
83 protected:
84         std::atomic<float> m_time_of_day_speed;
85
86         /*
87          * Below: values managed by m_time_lock
88         */
89         // Time of day in milli-hours (0-23999); determines day and night
90         u32 m_time_of_day;
91         // Time of day in 0...1
92         float m_time_of_day_f;
93         // Stores the skew created by the float -> u32 conversion
94         // to be applied at next conversion, so that there is no real skew.
95         float m_time_conversion_skew;
96         // Overriding the day-night ratio is useful for custom sky visuals
97         bool m_enable_day_night_ratio_override;
98         u32 m_day_night_ratio_override;
99         // Days from the server start, accounts for time shift
100         // in game (e.g. /time or bed usage)
101         std::atomic<u32> m_day_count;
102         /*
103          * Above: values managed by m_time_lock
104         */
105
106         /* TODO: Add a callback function so these can be updated when a setting
107          *       changes.  At this point in time it doesn't matter (e.g. /set
108          *       is documented to change server settings only)
109          *
110          * TODO: Local caching of settings is not optimal and should at some stage
111          *       be updated to use a global settings object for getting thse values
112          *       (as opposed to the this local caching). This can be addressed in
113          *       a later release.
114          */
115         bool m_cache_enable_shaders;
116         float m_cache_active_block_mgmt_interval;
117         float m_cache_abm_interval;
118         float m_cache_nodetimer_interval;
119
120         IGameDef *m_gamedef;
121
122 private:
123         std::mutex m_time_lock;
124
125         DISABLE_CLASS_COPY(Environment);
126 };
127
128 #endif