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