2010-11-29 10:13:04 -08:00
|
|
|
/*
|
2013-02-24 09:40:43 -08:00
|
|
|
Minetest
|
2013-02-24 10:38:45 -08:00
|
|
|
Copyright (C) 2010-2013 celeron55, Perttu Ahola <celeron55@gmail.com>
|
2010-11-29 10:13:04 -08:00
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
2012-06-05 07:56:56 -07: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 10:13:04 -08: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 07:56:56 -07:00
|
|
|
GNU Lesser General Public License for more details.
|
2010-11-29 10:13:04 -08:00
|
|
|
|
2012-06-05 07:56:56 -07:00
|
|
|
You should have received a copy of the GNU Lesser General Public License along
|
2010-11-29 10:13:04 -08:00
|
|
|
with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
*/
|
|
|
|
|
2010-11-26 15:02:21 -08:00
|
|
|
#ifndef ENVIRONMENT_HEADER
|
|
|
|
#define ENVIRONMENT_HEADER
|
|
|
|
|
|
|
|
/*
|
|
|
|
This class is the game's environment.
|
|
|
|
It contains:
|
|
|
|
- The map
|
|
|
|
- Players
|
|
|
|
- Other objects
|
2011-11-13 14:19:48 -08:00
|
|
|
- The current time in the game
|
2011-02-20 14:45:14 -08:00
|
|
|
- etc.
|
2010-11-26 15:02:21 -08:00
|
|
|
*/
|
|
|
|
|
2012-12-20 09:19:49 -08:00
|
|
|
#include <list>
|
2015-04-22 02:47:22 -07:00
|
|
|
#include <queue>
|
2013-08-10 19:09:45 -07:00
|
|
|
#include <map>
|
2017-06-06 05:34:14 -07:00
|
|
|
#include <atomic>
|
2017-06-06 07:29:28 -07:00
|
|
|
#include <mutex>
|
2013-08-10 19:09:45 -07:00
|
|
|
#include "irr_v3d.h"
|
2011-06-26 05:48:56 -07:00
|
|
|
#include "activeobject.h"
|
2012-06-16 16:40:36 -07:00
|
|
|
#include "util/numeric.h"
|
2015-07-17 07:40:41 -07:00
|
|
|
#include "network/networkprotocol.h" // for AccessDeniedCode
|
2011-06-26 05:48:56 -07:00
|
|
|
|
2017-03-16 23:48:29 -07:00
|
|
|
class IGameDef;
|
2017-01-11 00:03:07 -08:00
|
|
|
class Map;
|
|
|
|
|
2010-11-26 15:02:21 -08:00
|
|
|
class Environment
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
// Environment will delete the map passed to the constructor
|
2017-03-16 23:48:29 -07:00
|
|
|
Environment(IGameDef *gamedef);
|
2011-02-20 14:45:14 -08:00
|
|
|
virtual ~Environment();
|
2017-06-10 04:49:15 -07:00
|
|
|
DISABLE_CLASS_COPY(Environment);
|
2011-02-20 14:45:14 -08:00
|
|
|
|
2010-11-26 15:02:21 -08:00
|
|
|
/*
|
2011-02-20 14:45:14 -08:00
|
|
|
Step everything in environment.
|
|
|
|
- Move players
|
|
|
|
- Step mobs
|
|
|
|
- Run timers of map
|
2010-11-26 15:02:21 -08:00
|
|
|
*/
|
2011-02-20 14:45:14 -08:00
|
|
|
virtual void step(f32 dtime) = 0;
|
2010-11-26 15:02:21 -08:00
|
|
|
|
2017-04-23 00:52:40 -07:00
|
|
|
virtual Map &getMap() = 0;
|
2010-12-18 07:46:00 -08:00
|
|
|
|
2011-02-20 14:45:14 -08:00
|
|
|
u32 getDayNightRatio();
|
2013-10-18 01:53:19 -07:00
|
|
|
|
2011-05-22 07:00:09 -07:00
|
|
|
// 0-23999
|
2015-03-04 02:46:31 -08:00
|
|
|
virtual void setTimeOfDay(u32 time);
|
|
|
|
u32 getTimeOfDay();
|
|
|
|
float getTimeOfDayF();
|
2012-03-16 07:34:30 -07:00
|
|
|
|
|
|
|
void stepTimeOfDay(float dtime);
|
|
|
|
|
2014-06-22 14:19:10 -07:00
|
|
|
void setTimeOfDaySpeed(float speed);
|
2011-02-20 14:45:14 -08:00
|
|
|
|
2015-11-03 18:07:32 -08:00
|
|
|
void setDayNightRatioOverride(bool enable, u32 value);
|
2013-10-18 01:53:19 -07:00
|
|
|
|
2016-03-06 12:02:21 -08:00
|
|
|
u32 getDayCount();
|
|
|
|
|
2014-03-06 11:20:06 -08:00
|
|
|
// counter used internally when triggering ABMs
|
|
|
|
u32 m_added_objects;
|
|
|
|
|
2017-04-23 00:52:40 -07:00
|
|
|
IGameDef *getGameDef() { return m_gamedef; }
|
2017-05-26 08:03:46 -07:00
|
|
|
|
2011-02-20 14:45:14 -08:00
|
|
|
protected:
|
2017-06-06 05:34:14 -07:00
|
|
|
std::atomic<float> m_time_of_day_speed;
|
2015-10-27 13:03:59 -07:00
|
|
|
|
|
|
|
/*
|
2015-11-03 18:07:32 -08:00
|
|
|
* Below: values managed by m_time_lock
|
2015-11-02 23:56:56 -08:00
|
|
|
*/
|
2015-11-03 18:07:32 -08:00
|
|
|
// Time of day in milli-hours (0-23999); determines day and night
|
2017-06-16 02:25:52 -07:00
|
|
|
u32 m_time_of_day = 9000;
|
2012-03-16 07:34:30 -07:00
|
|
|
// Time of day in 0...1
|
2017-06-16 02:25:52 -07:00
|
|
|
float m_time_of_day_f = 9000.0f / 24000.0f;
|
2015-11-02 23:56:56 -08: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 02:25:52 -07:00
|
|
|
float m_time_conversion_skew = 0.0f;
|
2015-11-03 18:07:32 -08:00
|
|
|
// Overriding the day-night ratio is useful for custom sky visuals
|
2017-06-16 02:25:52 -07: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 05:34:14 -07:00
|
|
|
std::atomic<u32> m_day_count;
|
2015-10-27 13:03:59 -07:00
|
|
|
/*
|
2015-11-03 18:07:32 -08:00
|
|
|
* Above: values managed by m_time_lock
|
2015-11-02 23:56:56 -08:00
|
|
|
*/
|
|
|
|
|
2014-12-06 06:37:37 -08: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-01 23:14:26 -08:00
|
|
|
float m_cache_active_block_mgmt_interval;
|
|
|
|
float m_cache_abm_interval;
|
|
|
|
float m_cache_nodetimer_interval;
|
2015-01-18 20:29:19 -08:00
|
|
|
|
2017-03-16 23:48:29 -07:00
|
|
|
IGameDef *m_gamedef;
|
2017-04-23 00:52:40 -07:00
|
|
|
|
2014-06-22 14:19:10 -07:00
|
|
|
private:
|
2017-06-06 07:29:28 -07:00
|
|
|
std::mutex m_time_lock;
|
2011-05-22 07:00:09 -07:00
|
|
|
};
|
|
|
|
|
2011-02-20 14:45:14 -08:00
|
|
|
#endif
|