Luanti 5.10.0-dev
 
Loading...
Searching...
No Matches
environment.h
Go to the documentation of this file.
1// Luanti
2// SPDX-License-Identifier: LGPL-2.1-or-later
3// Copyright (C) 2010-2013 celeron55, Perttu Ahola <celeron55@gmail.com>
4
5#pragma once
6
7/*
8 This class is the game's environment.
9 It contains:
10 - The map
11 - Players
12 - Other objects
13 - The current time in the game
14 - etc.
15*/
16
17#include <list>
18#include <queue>
19#include <map>
20#include <atomic>
21#include <mutex>
22#include <optional>
23#include "irr_v3d.h"
24#include "util/basic_macros.h"
25#include "line3d.h"
26
27class IGameDef;
28class Map;
29struct PointedThing;
30class RaycastState;
31struct Pointabilities;
32
34{
35public:
36 // Environment will delete the map passed to the constructor
37 Environment(IGameDef *gamedef);
38 virtual ~Environment() = default;
40
41 /*
42 Step everything in environment.
43 - Move players
44 - Step mobs
45 - Run timers of map
46 */
47 virtual void step(f32 dtime) = 0;
48
49 virtual Map &getMap() = 0;
50
51 u32 getDayNightRatio();
52
53 // 0-23999
54 virtual void setTimeOfDay(u32 time);
55 u32 getTimeOfDay();
56 float getTimeOfDayF();
57
58 void stepTimeOfDay(float dtime);
59
60 void setTimeOfDaySpeed(float speed);
61
62 void setDayNightRatioOverride(bool enable, u32 value);
63
64 u32 getDayCount();
65
74 bool line_of_sight(v3f pos1, v3f pos2, v3s16 *p = nullptr);
75
86 virtual void getSelectedActiveObjects(const core::line3d<f32> &shootline_on_map,
87 std::vector<PointedThing> &objects,
88 const std::optional<Pointabilities> &pointabilities) = 0;
89
95 void continueRaycast(RaycastState *state, PointedThing *result);
96
97 // counter used internally when triggering ABMs
99
101
102protected:
103 std::atomic<float> m_time_of_day_speed;
104
105 /*
106 * Below: values managed by m_time_lock
107 */
108 // Time of day in milli-hours (0-23999), determines day and night
110 // Time of day in 0...1
112 // Stores the skew created by the float -> u32 conversion
113 // to be applied at next conversion, so that there is no real skew.
115 // Overriding the day-night ratio is useful for custom sky visuals
118 // Days from the server start, accounts for time shift
119 // in game (e.g. /time or bed usage)
120 std::atomic<u32> m_day_count;
121 /*
122 * Above: values managed by m_time_lock
123 */
124
125 /* TODO: Add a callback function so these can be updated when a setting
126 * changes. At this point in time it doesn't matter (e.g. /set
127 * is documented to change server settings only)
128 *
129 * TODO: Local caching of settings is not optimal and should at some stage
130 * be updated to use a global settings object for getting thse values
131 * (as opposed to the this local caching). This can be addressed in
132 * a later release.
133 */
139
141
142private:
143 std::mutex m_time_lock;
144};
Definition environment.h:34
float m_cache_active_block_mgmt_interval
Definition environment.h:135
u32 m_added_objects
Definition environment.h:98
virtual ~Environment()=default
void setDayNightRatioOverride(bool enable, u32 value)
Definition environment.cpp:43
IGameDef * m_gamedef
Definition environment.h:140
std::atomic< float > m_time_of_day_speed
Definition environment.h:103
virtual void step(f32 dtime)=0
u32 m_time_of_day
Definition environment.h:109
bool m_enable_day_night_ratio_override
Definition environment.h:116
u32 getDayNightRatio()
Definition environment.cpp:30
std::atomic< u32 > m_day_count
Definition environment.h:120
virtual void getSelectedActiveObjects(const core::line3d< f32 > &shootline_on_map, std::vector< PointedThing > &objects, const std::optional< Pointabilities > &pointabilities)=0
u32 getTimeOfDay()
Definition environment.cpp:59
float m_time_conversion_skew
Definition environment.h:114
DISABLE_CLASS_COPY(Environment)
float m_time_of_day_f
Definition environment.h:111
virtual Map & getMap()=0
float m_cache_abm_time_budget
Definition environment.h:138
u32 m_day_night_ratio_override
Definition environment.h:117
std::mutex m_time_lock
Definition environment.h:143
void setTimeOfDaySpeed(float speed)
Definition environment.cpp:38
IGameDef * getGameDef()
Definition environment.h:100
bool m_cache_enable_shaders
Definition environment.h:134
Environment(IGameDef *gamedef)
Definition environment.cpp:15
bool line_of_sight(v3f pos1, v3f pos2, v3s16 *p=nullptr)
Definition environment.cpp:71
u32 getDayCount()
Definition environment.cpp:323
float m_cache_nodetimer_interval
Definition environment.h:137
float m_cache_abm_interval
Definition environment.h:136
void stepTimeOfDay(float dtime)
Definition environment.cpp:289
virtual void setTimeOfDay(u32 time)
Definition environment.cpp:50
float getTimeOfDayF()
Definition environment.cpp:65
void continueRaycast(RaycastState *state, PointedThing *result)
Definition environment.cpp:109
Definition gamedef.h:36
Definition map.h:101
Describes the state of a raycast.
Definition raycast.h:18
core::vector3d< s16 > v3s16
Definition irr_v3d.h:13
core::vector3df v3f
Definition irr_v3d.h:11
Definition pointabilities.h:30
An active object or node which is selected by a ray on the map.
Definition pointedthing.h:22
static std::string p(std::string path)
Definition test_filesys.cpp:53