Luanti 5.18.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 <atomic>
18#include <mutex>
19#include <optional>
20#include <vector>
21#include "irr_v3d.h"
22#include "util/basic_macros.h"
23#include "line3d.h"
24
25class IGameDef;
26class Map;
27struct PointedThing;
28class RaycastState;
29struct Pointabilities;
30
32{
33public:
34 // Environment will delete the map passed to the constructor
35 Environment(IGameDef *gamedef);
36 virtual ~Environment() = default;
38
39 /*
40 Step everything in environment.
41 - Move players
42 - Step mobs
43 - Run timers of map
44 */
45 virtual void step(f32 dtime) = 0;
46
47 virtual Map &getMap() = 0;
48
49 u32 getDayNightRatio();
50
51 // 0-23999
52 virtual void setTimeOfDay(u32 time);
53 u32 getTimeOfDay();
54 float getTimeOfDayF();
55
56 void stepTimeOfDay(float dtime);
57
58 void setTimeOfDaySpeed(float speed);
59
60 void setDayNightRatioOverride(bool enable, u32 value);
61
62 u32 getDayCount();
63
72 bool line_of_sight(v3f pos1, v3f pos2, v3s16 *p = nullptr);
73
84 virtual void getSelectedActiveObjects(const core::line3d<f32> &shootline_on_map,
85 std::vector<PointedThing> &objects,
86 const std::optional<Pointabilities> &pointabilities) = 0;
87
93 void continueRaycast(RaycastState *state, PointedThing *result);
94
95 // counter used internally when triggering ABMs
97
99
100protected:
101 std::atomic<float> m_time_of_day_speed;
102
103 /*
104 * Below: values managed by m_time_lock
105 */
106 // Time of day in milli-hours (0-23999), determines day and night
108 // Time of day in 0...1
110 // Stores the skew created by the float -> u32 conversion
111 // to be applied at next conversion, so that there is no real skew.
113 // Overriding the day-night ratio is useful for custom sky visuals
116 // Days from the server start, accounts for time shift
117 // in game (e.g. /time or bed usage)
118 std::atomic<u32> m_day_count;
119 /*
120 * Above: values managed by m_time_lock
121 */
122
124
125private:
126 std::mutex m_time_lock;
127};
u32 m_added_objects
Definition environment.h:96
virtual ~Environment()=default
void setDayNightRatioOverride(bool enable, u32 value)
Definition environment.cpp:35
IGameDef * m_gamedef
Definition environment.h:123
std::atomic< float > m_time_of_day_speed
Definition environment.h:101
virtual void step(f32 dtime)=0
u32 m_time_of_day
Definition environment.h:107
bool m_enable_day_night_ratio_override
Definition environment.h:114
u32 getDayNightRatio()
Definition environment.cpp:22
std::atomic< u32 > m_day_count
Definition environment.h:118
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:51
float m_time_conversion_skew
Definition environment.h:112
DISABLE_CLASS_COPY(Environment)
float m_time_of_day_f
Definition environment.h:109
virtual Map & getMap()=0
u32 m_day_night_ratio_override
Definition environment.h:115
std::mutex m_time_lock
Definition environment.h:126
void setTimeOfDaySpeed(float speed)
Definition environment.cpp:30
IGameDef * getGameDef()
Definition environment.h:98
Environment(IGameDef *gamedef)
Definition environment.cpp:13
bool line_of_sight(v3f pos1, v3f pos2, v3s16 *p=nullptr)
Definition environment.cpp:63
u32 getDayCount()
Definition environment.cpp:315
void stepTimeOfDay(float dtime)
Definition environment.cpp:281
virtual void setTimeOfDay(u32 time)
Definition environment.cpp:42
float getTimeOfDayF()
Definition environment.cpp:57
void continueRaycast(RaycastState *state, PointedThing *result)
Definition environment.cpp:101
Definition gamedef.h:26
Definition map.h:105
Describes the state of a raycast.
Definition raycast.h:20
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:73