1
0
mirror of https://github.com/rwengine/openrw.git synced 2024-11-07 19:32:49 +01:00
openrw/rwengine/include/script/ScriptModule.hpp
Daniel Evans 185687b1b5 Add and improve functionality for first mission.
+ Improve GoTo activity behaviour, jumping to target.
+ Fixed crash on non-existing audio file
+ Added correct conditional flag to conditional opcodes
+ Fixed seat state on exit from non 0th seat
+ Implement many opcodes
2015-01-21 20:40:31 +00:00

48 lines
1.5 KiB
C++

#ifndef _SCRIPTMODULE_HPP_
#define _SCRIPTMODULE_HPP_
#include <script/ScriptTypes.hpp>
#include "ScriptMachine.hpp"
#include <string>
/**
* Interface for a collection of functions that can be exported to a game script interface.
*
* For example a collection of functions that control the time of day, or create objects would
* be the collected within one ScriptModule with a sensible name like "Environment" or "Objects"
*/
class ScriptModule
{
public:
ScriptModule(const std::string& name) : name(name) { }
const std::string& getName() const { return name; }
void bind(ScriptFunctionID id,
ScriptFunction func,
bool conditional,
int args,
const std::string& name,
const std::string& desc
);
bool findOpcode(ScriptFunctionID id, ScriptFunctionMeta** out);
private:
const std::string name;
std::map<ScriptFunctionID, ScriptFunctionMeta> functions;
};
template<class Tret> ScriptFunction conditional_facade(Tret(*f)(const ScriptArguments&)) { return f; }
template<> ScriptFunction conditional_facade<bool>(bool(*f)(const ScriptArguments&));
template<class Tret> bool is_conditional(Tret(*f)(const ScriptArguments&)) { return false; }
template<> bool is_conditional<bool>(bool(*f)(const ScriptArguments&));
// Macro to automatically use function name.
#define bindFunction(id, func, argc, desc) \
bind(id, conditional_facade(func), is_conditional(func), argc, #func, desc)
#define bindUnimplemented(id, func, argc, desc) \
bind(id, 0, false, argc, #func, desc)
#endif