2024-10-28 15:57:39 +01:00
|
|
|
// Luanti
|
|
|
|
// SPDX-License-Identifier: LGPL-2.1-or-later
|
|
|
|
// Copyright (C) 2010-2013 celeron55, Perttu Ahola <celeron55@gmail.com>
|
2010-11-29 20:13:04 +02:00
|
|
|
|
2017-08-17 22:19:39 +02:00
|
|
|
#pragma once
|
2010-11-27 01:02:21 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
This class is the game's environment.
|
|
|
|
It contains:
|
|
|
|
- The map
|
|
|
|
- Players
|
|
|
|
- Other objects
|
2011-11-14 00:19:48 +02:00
|
|
|
- The current time in the game
|
2011-02-21 00:45:14 +02:00
|
|
|
- etc.
|
2010-11-27 01:02:21 +02:00
|
|
|
*/
|
|
|
|
|
2012-12-20 21:19:49 +04:00
|
|
|
#include <list>
|
2015-04-22 11:47:22 +02:00
|
|
|
#include <queue>
|
2013-08-11 04:09:45 +02:00
|
|
|
#include <map>
|
2017-06-06 14:34:14 +02:00
|
|
|
#include <atomic>
|
2017-06-06 16:29:28 +02:00
|
|
|
#include <mutex>
|
2024-01-22 18:27:08 +01:00
|
|
|
#include <optional>
|
2013-08-11 04:09:45 +02:00
|
|
|
#include "irr_v3d.h"
|
2017-08-16 22:11:45 +02:00
|
|
|
#include "util/basic_macros.h"
|
2023-03-08 22:58:47 +01:00
|
|
|
#include "line3d.h"
|
2011-06-26 15:48:56 +03:00
|
|
|
|
2017-03-17 07:48:29 +01:00
|
|
|
class IGameDef;
|
2017-01-11 09:03:07 +01:00
|
|
|
class Map;
|
2016-07-23 21:11:20 +02:00
|
|
|
struct PointedThing;
|
|
|
|
class RaycastState;
|
2024-01-22 18:27:08 +01:00
|
|
|
struct Pointabilities;
|
2017-01-11 09:03:07 +01:00
|
|
|
|
2010-11-27 01:02:21 +02:00
|
|
|
class Environment
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
// Environment will delete the map passed to the constructor
|
2017-03-17 07:48:29 +01:00
|
|
|
Environment(IGameDef *gamedef);
|
2017-08-20 19:37:29 +02:00
|
|
|
virtual ~Environment() = default;
|
2017-06-10 13:49:15 +02:00
|
|
|
DISABLE_CLASS_COPY(Environment);
|
2011-02-21 00:45:14 +02:00
|
|
|
|
2010-11-27 01:02:21 +02:00
|
|
|
/*
|
2011-02-21 00:45:14 +02:00
|
|
|
Step everything in environment.
|
|
|
|
- Move players
|
|
|
|
- Step mobs
|
|
|
|
- Run timers of map
|
2010-11-27 01:02:21 +02:00
|
|
|
*/
|
2011-02-21 00:45:14 +02:00
|
|
|
virtual void step(f32 dtime) = 0;
|
2010-11-27 01:02:21 +02:00
|
|
|
|
2017-04-23 09:52:40 +02:00
|
|
|
virtual Map &getMap() = 0;
|
2010-12-18 17:46:00 +02:00
|
|
|
|
2011-02-21 00:45:14 +02:00
|
|
|
u32 getDayNightRatio();
|
2013-10-18 11:53:19 +03:00
|
|
|
|
2011-05-22 17:00:09 +03:00
|
|
|
// 0-23999
|
2015-03-04 11:46:31 +01:00
|
|
|
virtual void setTimeOfDay(u32 time);
|
|
|
|
u32 getTimeOfDay();
|
|
|
|
float getTimeOfDayF();
|
2012-03-16 16:34:30 +02:00
|
|
|
|
|
|
|
void stepTimeOfDay(float dtime);
|
|
|
|
|
2014-06-22 23:19:10 +02:00
|
|
|
void setTimeOfDaySpeed(float speed);
|
2011-02-21 00:45:14 +02:00
|
|
|
|
2015-11-04 03:07:32 +01:00
|
|
|
void setDayNightRatioOverride(bool enable, u32 value);
|
2013-10-18 11:53:19 +03:00
|
|
|
|
2016-03-06 12:02:21 -08:00
|
|
|
u32 getDayCount();
|
|
|
|
|
2020-04-10 22:06:24 +02:00
|
|
|
/*!
|
|
|
|
* Returns false if the given line intersects with a
|
|
|
|
* non-air node, true otherwise.
|
|
|
|
* \param pos1 start of the line
|
|
|
|
* \param pos2 end of the line
|
|
|
|
* \param p output, position of the first non-air node
|
|
|
|
* the line intersects
|
|
|
|
*/
|
|
|
|
bool line_of_sight(v3f pos1, v3f pos2, v3s16 *p = nullptr);
|
|
|
|
|
2016-07-23 21:11:20 +02:00
|
|
|
/*!
|
|
|
|
* Gets the objects pointed by the shootline as
|
|
|
|
* pointed things.
|
|
|
|
* If this is a client environment, the local player
|
|
|
|
* won't be returned.
|
|
|
|
* @param[in] shootline_on_map the shootline for
|
|
|
|
* the test in world coordinates
|
|
|
|
*
|
|
|
|
* @param[out] objects found objects
|
|
|
|
*/
|
|
|
|
virtual void getSelectedActiveObjects(const core::line3d<f32> &shootline_on_map,
|
2024-01-22 18:27:08 +01:00
|
|
|
std::vector<PointedThing> &objects,
|
|
|
|
const std::optional<Pointabilities> &pointabilities) = 0;
|
2016-07-23 21:11:20 +02:00
|
|
|
|
|
|
|
/*!
|
|
|
|
* Returns the next node or object the shootline meets.
|
|
|
|
* @param state current state of the raycast
|
|
|
|
* @result output, will contain the next pointed thing
|
|
|
|
*/
|
|
|
|
void continueRaycast(RaycastState *state, PointedThing *result);
|
|
|
|
|
2014-03-06 19:20:06 +00:00
|
|
|
// counter used internally when triggering ABMs
|
|
|
|
u32 m_added_objects;
|
|
|
|
|
2017-04-23 09:52:40 +02:00
|
|
|
IGameDef *getGameDef() { return m_gamedef; }
|
2017-05-26 17:03:46 +02:00
|
|
|
|
2011-02-21 00:45:14 +02:00
|
|
|
protected:
|
2017-06-06 14:34:14 +02:00
|
|
|
std::atomic<float> m_time_of_day_speed;
|
2015-10-27 21:03:59 +01:00
|
|
|
|
|
|
|
/*
|
2015-11-04 03:07:32 +01:00
|
|
|
* Below: values managed by m_time_lock
|
2017-10-09 11:32:06 +02:00
|
|
|
*/
|
2017-09-02 03:18:42 +01:00
|
|
|
// Time of day in milli-hours (0-23999), determines day and night
|
|
|
|
u32 m_time_of_day;
|
|
|
|
// Time of day in 0...1
|
|
|
|
float m_time_of_day_f;
|
2015-11-03 08:56:56 +01:00
|
|
|
// Stores the skew created by the float -> u32 conversion
|
|
|
|
// to be applied at next conversion, so that there is no real skew.
|
2017-06-16 11:25:52 +02:00
|
|
|
float m_time_conversion_skew = 0.0f;
|
2015-11-04 03:07:32 +01:00
|
|
|
// Overriding the day-night ratio is useful for custom sky visuals
|
2017-06-16 11:25:52 +02:00
|
|
|
bool m_enable_day_night_ratio_override = false;
|
|
|
|
u32 m_day_night_ratio_override = 0.0f;
|
2016-03-06 12:02:21 -08:00
|
|
|
// Days from the server start, accounts for time shift
|
|
|
|
// in game (e.g. /time or bed usage)
|
2017-06-06 14:34:14 +02:00
|
|
|
std::atomic<u32> m_day_count;
|
2015-10-27 21:03:59 +01:00
|
|
|
/*
|
2015-11-04 03:07:32 +01:00
|
|
|
* Above: values managed by m_time_lock
|
2017-10-09 11:32:06 +02:00
|
|
|
*/
|
2015-11-03 08:56:56 +01:00
|
|
|
|
2017-03-17 07:48:29 +01:00
|
|
|
IGameDef *m_gamedef;
|
2017-04-23 09:52:40 +02:00
|
|
|
|
2014-06-22 23:19:10 +02:00
|
|
|
private:
|
2017-06-06 16:29:28 +02:00
|
|
|
std::mutex m_time_lock;
|
2011-05-22 17:00:09 +03:00
|
|
|
};
|