mirror of
https://github.com/moparisthebest/minetest
synced 2024-11-13 12:55:04 -05:00
Handle ActiveBlockModifier intervals properly, down to 1s
This commit is contained in:
parent
0f2b932e92
commit
fadf248892
@ -301,9 +301,9 @@ ServerEnvironment::~ServerEnvironment()
|
|||||||
m_map->drop();
|
m_map->drop();
|
||||||
|
|
||||||
// Delete ActiveBlockModifiers
|
// Delete ActiveBlockModifiers
|
||||||
for(core::list<ActiveBlockModifier*>::Iterator
|
for(core::list<ABMWithState>::Iterator
|
||||||
i = m_abms.begin(); i != m_abms.end(); i++){
|
i = m_abms.begin(); i != m_abms.end(); i++){
|
||||||
delete (*i);
|
delete i->abm;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -566,20 +566,29 @@ private:
|
|||||||
ServerEnvironment *m_env;
|
ServerEnvironment *m_env;
|
||||||
std::map<content_t, std::list<ActiveABM> > m_aabms;
|
std::map<content_t, std::list<ActiveABM> > m_aabms;
|
||||||
public:
|
public:
|
||||||
ABMHandler(core::list<ActiveBlockModifier*> &abms,
|
ABMHandler(core::list<ABMWithState> &abms,
|
||||||
float dtime_s, ServerEnvironment *env):
|
float dtime_s, ServerEnvironment *env,
|
||||||
|
bool use_timers):
|
||||||
m_env(env)
|
m_env(env)
|
||||||
{
|
{
|
||||||
infostream<<"ABMHandler: dtime_s="<<dtime_s<<std::endl;
|
|
||||||
if(dtime_s < 0.001)
|
if(dtime_s < 0.001)
|
||||||
return;
|
return;
|
||||||
INodeDefManager *ndef = env->getGameDef()->ndef();
|
INodeDefManager *ndef = env->getGameDef()->ndef();
|
||||||
for(core::list<ActiveBlockModifier*>::Iterator
|
for(core::list<ABMWithState>::Iterator
|
||||||
i = abms.begin(); i != abms.end(); i++){
|
i = abms.begin(); i != abms.end(); i++){
|
||||||
ActiveBlockModifier *abm = *i;
|
ActiveBlockModifier *abm = i->abm;
|
||||||
|
float trigger_interval = abm->getTriggerInterval();
|
||||||
|
if(trigger_interval < 0.001)
|
||||||
|
trigger_interval = 0.001;
|
||||||
|
if(use_timers){
|
||||||
|
i->timer += dtime_s;
|
||||||
|
if(i->timer < trigger_interval)
|
||||||
|
continue;
|
||||||
|
i->timer -= trigger_interval;
|
||||||
|
}
|
||||||
ActiveABM aabm;
|
ActiveABM aabm;
|
||||||
aabm.abm = abm;
|
aabm.abm = abm;
|
||||||
float intervals = dtime_s / abm->getTriggerInterval();
|
float intervals = dtime_s / trigger_interval;
|
||||||
float chance = abm->getTriggerChance();
|
float chance = abm->getTriggerChance();
|
||||||
if(chance == 0)
|
if(chance == 0)
|
||||||
chance = 1;
|
chance = 1;
|
||||||
@ -605,6 +614,9 @@ public:
|
|||||||
}
|
}
|
||||||
void apply(MapBlock *block)
|
void apply(MapBlock *block)
|
||||||
{
|
{
|
||||||
|
if(m_aabms.empty())
|
||||||
|
return;
|
||||||
|
|
||||||
ServerMap *map = &m_env->getServerMap();
|
ServerMap *map = &m_env->getServerMap();
|
||||||
// Find out how many objects the block contains
|
// Find out how many objects the block contains
|
||||||
u32 active_object_count = block->m_static_objects.m_active.size();
|
u32 active_object_count = block->m_static_objects.m_active.size();
|
||||||
@ -685,13 +697,13 @@ void ServerEnvironment::activateBlock(MapBlock *block, u32 additional_dtime)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Handle ActiveBlockModifiers */
|
/* Handle ActiveBlockModifiers */
|
||||||
ABMHandler abmhandler(m_abms, dtime_s, this);
|
ABMHandler abmhandler(m_abms, dtime_s, this, false);
|
||||||
abmhandler.apply(block);
|
abmhandler.apply(block);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ServerEnvironment::addActiveBlockModifier(ActiveBlockModifier *abm)
|
void ServerEnvironment::addActiveBlockModifier(ActiveBlockModifier *abm)
|
||||||
{
|
{
|
||||||
m_abms.push_back(abm);
|
m_abms.push_back(ABMWithState(abm));
|
||||||
}
|
}
|
||||||
|
|
||||||
void ServerEnvironment::clearAllObjects()
|
void ServerEnvironment::clearAllObjects()
|
||||||
@ -973,14 +985,14 @@ void ServerEnvironment::step(float dtime)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const float abm_interval = 10.0;
|
const float abm_interval = 1.0;
|
||||||
if(m_active_block_modifier_interval.step(dtime, abm_interval))
|
if(m_active_block_modifier_interval.step(dtime, abm_interval))
|
||||||
{
|
{
|
||||||
ScopeProfiler sp(g_profiler, "SEnv: modify in blocks avg /10s", SPT_AVG);
|
ScopeProfiler sp(g_profiler, "SEnv: modify in blocks avg /1s", SPT_AVG);
|
||||||
TimeTaker timer("modify in active blocks");
|
TimeTaker timer("modify in active blocks");
|
||||||
|
|
||||||
// Initialize handling of ActiveBlockModifiers
|
// Initialize handling of ActiveBlockModifiers
|
||||||
ABMHandler abmhandler(m_abms, abm_interval, this);
|
ABMHandler abmhandler(m_abms, abm_interval, this, true);
|
||||||
|
|
||||||
for(core::map<v3s16, bool>::Iterator
|
for(core::map<v3s16, bool>::Iterator
|
||||||
i = m_active_blocks.m_list.getIterator();
|
i = m_active_blocks.m_list.getIterator();
|
||||||
|
@ -118,6 +118,16 @@ public:
|
|||||||
u32 active_object_count, u32 active_object_count_wider){};
|
u32 active_object_count, u32 active_object_count_wider){};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct ABMWithState
|
||||||
|
{
|
||||||
|
ActiveBlockModifier *abm;
|
||||||
|
float timer;
|
||||||
|
|
||||||
|
ABMWithState(ActiveBlockModifier *abm_):
|
||||||
|
abm(abm_)
|
||||||
|
{}
|
||||||
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
List of active blocks, used by ServerEnvironment
|
List of active blocks, used by ServerEnvironment
|
||||||
*/
|
*/
|
||||||
@ -329,7 +339,7 @@ private:
|
|||||||
u32 m_game_time;
|
u32 m_game_time;
|
||||||
// A helper variable for incrementing the latter
|
// A helper variable for incrementing the latter
|
||||||
float m_game_time_fraction_counter;
|
float m_game_time_fraction_counter;
|
||||||
core::list<ActiveBlockModifier*> m_abms;
|
core::list<ABMWithState> m_abms;
|
||||||
};
|
};
|
||||||
|
|
||||||
#ifndef SERVER
|
#ifndef SERVER
|
||||||
|
Loading…
Reference in New Issue
Block a user