2010-11-29 19:13:04 +01:00
|
|
|
/*
|
2013-02-24 18:40:43 +01:00
|
|
|
Minetest
|
2013-02-24 19:38:45 +01:00
|
|
|
Copyright (C) 2010-2013 celeron55, Perttu Ahola <celeron55@gmail.com>
|
2010-11-29 19:13:04 +01:00
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
2012-06-05 16:56:56 +02:00
|
|
|
it under the terms of the GNU Lesser General Public License as published by
|
|
|
|
the Free Software Foundation; either version 2.1 of the License, or
|
2010-11-29 19:13:04 +01:00
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
2012-06-05 16:56:56 +02:00
|
|
|
GNU Lesser General Public License for more details.
|
2010-11-29 19:13:04 +01:00
|
|
|
|
2012-06-05 16:56:56 +02:00
|
|
|
You should have received a copy of the GNU Lesser General Public License along
|
2010-11-29 19:13:04 +01:00
|
|
|
with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
*/
|
|
|
|
|
2017-08-17 22:19:39 +02:00
|
|
|
#pragma once
|
2010-11-27 00:02:21 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
This class is the game's environment.
|
|
|
|
It contains:
|
|
|
|
- The map
|
|
|
|
- Players
|
|
|
|
- Other objects
|
2011-11-13 23:19:48 +01:00
|
|
|
- The current time in the game
|
2011-02-20 23:45:14 +01:00
|
|
|
- etc.
|
2010-11-27 00:02:21 +01:00
|
|
|
*/
|
|
|
|
|
2012-12-20 18:19:49 +01: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>
|
2013-08-11 04:09:45 +02:00
|
|
|
#include "irr_v3d.h"
|
2015-07-17 16:40:41 +02:00
|
|
|
#include "network/networkprotocol.h" // for AccessDeniedCode
|
2017-08-16 22:11:45 +02:00
|
|
|
#include "util/basic_macros.h"
|
2011-06-26 14:48:56 +02: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;
|
2017-01-11 09:03:07 +01:00
|
|
|
|
2010-11-27 00:02:21 +01: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-20 23:45:14 +01:00
|
|
|
|
2010-11-27 00:02:21 +01:00
|
|
|
/*
|
2011-02-20 23:45:14 +01:00
|
|
|
Step everything in environment.
|
|
|
|
- Move players
|
|
|
|
- Step mobs
|
|
|
|
- Run timers of map
|
2010-11-27 00:02:21 +01:00
|
|
|
*/
|
2011-02-20 23:45:14 +01:00
|
|
|
virtual void step(f32 dtime) = 0;
|
2010-11-27 00:02:21 +01:00
|
|
|
|
2017-04-23 09:52:40 +02:00
|
|
|
virtual Map &getMap() = 0;
|
2010-12-18 16:46:00 +01:00
|
|
|
|
2011-02-20 23:45:14 +01:00
|
|
|
u32 getDayNightRatio();
|
2013-10-18 10:53:19 +02:00
|
|
|
|
2011-05-22 16:00:09 +02:00
|
|
|
// 0-23999
|
2015-03-04 11:46:31 +01:00
|
|
|
virtual void setTimeOfDay(u32 time);
|
|
|
|
u32 getTimeOfDay();
|
|
|
|
float getTimeOfDayF();
|
2012-03-16 15:34:30 +01:00
|
|
|
|
|
|
|
void stepTimeOfDay(float dtime);
|
|
|
|
|
2014-06-22 23:19:10 +02:00
|
|
|
void setTimeOfDaySpeed(float speed);
|
2011-02-20 23:45:14 +01:00
|
|
|
|
2015-11-04 03:07:32 +01:00
|
|
|
void setDayNightRatioOverride(bool enable, u32 value);
|
2013-10-18 10:53:19 +02:00
|
|
|
|
2016-03-06 21:02:21 +01:00
|
|
|
u32 getDayCount();
|
|
|
|
|
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,
|
|
|
|
std::vector<PointedThing> &objects) = 0;
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* 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 20:20:06 +01: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-20 23:45:14 +01: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
|
2015-11-03 08:56:56 +01:00
|
|
|
*/
|
2017-09-02 04:18:42 +02: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 21:02:21 +01: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
|
2015-11-03 08:56:56 +01:00
|
|
|
*/
|
|
|
|
|
2014-12-06 15:37:37 +01:00
|
|
|
/* TODO: Add a callback function so these can be updated when a setting
|
|
|
|
* changes. At this point in time it doesn't matter (e.g. /set
|
|
|
|
* is documented to change server settings only)
|
|
|
|
*
|
|
|
|
* TODO: Local caching of settings is not optimal and should at some stage
|
|
|
|
* be updated to use a global settings object for getting thse values
|
|
|
|
* (as opposed to the this local caching). This can be addressed in
|
|
|
|
* a later release.
|
|
|
|
*/
|
|
|
|
bool m_cache_enable_shaders;
|
Allow NodeTimer, ABM and block mgmt interval changes.
ABM's are hardcoded to run every 1.0s, NodeTimers are hard coded to
run at every 1.0s. Block mgmt is running every 2.0sec.
However, these timers can be better tuned for both higher and lower
values by server owners. Some server owners want to, and have the
resources to send more packets per second to clients, and so they
may wish to send smaller updates sooner. Right now all ABM's are
coalesced into 1.0 second intervals, resulting in large send queues
to all clients. By reducing the amount of possible timers, one can
get a far better response rate and lower the perception of lag.
On the other side of the camp, some servers may want to increase
these values, which again isn't easily doable.
The global settings abm_interval and nodetimer_interval are set to
current values by default. I've tested with 0.2/0.5 type values
and noticed a greatly improved response and better scattering of
nodetimers, as well as enjoying not faceplanting into doors with
pressure plates anymore.
2016-03-02 08:14:26 +01:00
|
|
|
float m_cache_active_block_mgmt_interval;
|
|
|
|
float m_cache_abm_interval;
|
|
|
|
float m_cache_nodetimer_interval;
|
2015-01-19 05:29:19 +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 16:00:09 +02:00
|
|
|
};
|