Another rework for scripthooks, for better performance.
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This new version caches pointers to the pointers to scripts, so that we can build the data once and then simply iterate over it whenever we want to run a hook.
This commit is contained in:
33
src/Battling/ScriptHandling/ScriptWrapper.hpp
Normal file
33
src/Battling/ScriptHandling/ScriptWrapper.hpp
Normal file
@@ -0,0 +1,33 @@
|
||||
|
||||
|
||||
#ifndef CREATURELIB_SCRIPTWRAPPER_HPP
|
||||
#define CREATURELIB_SCRIPTWRAPPER_HPP
|
||||
|
||||
#include <variant>
|
||||
#include "Script.hpp"
|
||||
#include "ScriptSet.hpp"
|
||||
|
||||
namespace CreatureLib::Battling{
|
||||
class ScriptWrapper {
|
||||
std::variant<Script**, ScriptSet*> _value;
|
||||
bool _isSet;
|
||||
public:
|
||||
ScriptWrapper(Script** s) : _value(s), _isSet(false){}
|
||||
ScriptWrapper(ScriptSet* s) : _value(s), _isSet(true){}
|
||||
|
||||
bool IsSet() const{
|
||||
return _isSet;
|
||||
}
|
||||
|
||||
Script** GetScript() const{
|
||||
return std::get<Script**>(_value);
|
||||
}
|
||||
|
||||
ScriptSet* GetScriptSet() const{
|
||||
return std::get<ScriptSet*>(_value);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
#endif //CREATURELIB_SCRIPTWRAPPER_HPP
|
||||
Reference in New Issue
Block a user