SimpleAI
 All Classes Namespaces Files Functions Variables Typedefs Macros Groups Pages
Public Member Functions | Static Public Member Functions | Public Attributes | Protected Types | Static Protected Member Functions | Protected Attributes | List of all members
ai::LUAAIRegistry Class Reference

Allows you to register lua TreeNodes, Conditions, Filters and ISteerings. More...

#include <LUAAIRegistry.h>

Inheritance diagram for ai::LUAAIRegistry:
[legend]
Collaboration diagram for ai::LUAAIRegistry:
[legend]

Public Member Functions

lua_State * getLuaState ()
 Access to the lua state. More...
 
int pushAIMetatable ()
 Pushes the AI metatable onto the stack. This allows anyone to modify it to provide own functions and data that is applied to the ai parameters of the lua functions. More...
 
int pushCharacterMetatable ()
 Pushes the character metatable onto the stack. This allows anyone to modify it to provide own functions and data that is applied to the ai:character() value.
 
bool init ()
 
void shutdown ()
 
bool evaluate (const std::string &str)
 
bool evaluate (const char *luaBuffer, size_t size)
 Load your lua scripts into the lua state of the registry. This can be called multiple times to e.g. load multiple files. More...
 
- Public Member Functions inherited from ai::AIRegistry
bool registerNodeFactory (const std::string &type, const ITreeNodeFactory &factory)
 Registers a tree node factory of the given type. More...
 
bool unregisterNodeFactory (const std::string &type)
 Unregisters a tree node factory of the given type. This can also be used to replace a built-in type with a user provided type. More...
 
bool registerSteerNodeFactory (const std::string &type, const ISteerNodeFactory &factory)
 
bool unregisterSteerNodeFactory (const std::string &type)
 Unregisters a tree node factory of the given type. This can also be used to replace a built-in type with a user provided type. More...
 
bool registerSteeringFactory (const std::string &type, const ISteeringFactory &factory)
 
bool unregisterSteeringFactory (const std::string &type)
 
bool registerFilterFactory (const std::string &type, const IFilterFactory &factory)
 
bool unregisterFilterFactory (const std::string &type)
 Unregisters a filter factory of the given type. This can also be used to replace a built-in type with a user provided type. More...
 
bool registerConditionFactory (const std::string &type, const IConditionFactory &factory)
 
bool unregisterConditionFactory (const std::string &type)
 Unregisters a condition factory of the given type. This can also be used to replace a built-in type with a user provided type. More...
 
TreeNodePtr createNode (const std::string &type, const TreeNodeFactoryContext &ctx) const override
 Allocates a new TreeNode for the given type. The type must be registered in the AIRegistry for this to work.
 
TreeNodePtr createSteerNode (const std::string &type, const SteerNodeFactoryContext &ctx) const override
 Allocates a new TreeNode for the given type. The type must be registered in the AIRegistry for this to work.
 
FilterPtr createFilter (const std::string &type, const FilterFactoryContext &ctx) const override
 Allocates a new IFilter for the given type. The type must be registered in the AIRegistry for this to work.
 
ConditionPtr createCondition (const std::string &type, const ConditionFactoryContext &ctx) const override
 Allocates a new ICondition for the given type. The type must be registered in the AIRegistry for this to work.
 
SteeringPtr createSteering (const std::string &type, const SteeringFactoryContext &ctx) const override
 Creates a new ISteering for the given type. The type must be registered in the AIRegistry for this to work.
 

Static Public Member Functions

static int luaAI_aisetfilteredentities (lua_State *s)
 
static int luaAI_aiaddfilteredentity (lua_State *s)
 

Public Attributes

std::vector< luaL_Reg > aiFuncs
 
std::vector< luaL_Reg > vecFuncs
 
std::vector< luaL_Reg > zoneFuncs
 
std::vector< luaL_Reg > characterFuncs
 
std::vector< luaL_Reg > aggroMgrFuncs
 
std::vector< luaL_Reg > groupMgrFuncs
 
std::vector< luaL_Reg > registryFuncs
 

Protected Types

using LuaNodeFactory = LUATreeNode::LUATreeNodeFactory
 
typedef std::shared_ptr
< LuaNodeFactory
LUATreeNodeFactoryPtr
 
typedef std::map< std::string,
LUATreeNodeFactoryPtr > 
TreeNodeFactoryMap
 
using LuaConditionFactory = LUACondition::LUAConditionFactory
 
typedef std::shared_ptr
< LuaConditionFactory
LUAConditionFactoryPtr
 
typedef std::map< std::string,
LUAConditionFactoryPtr > 
ConditionFactoryMap
 
using LuaFilterFactory = LUAFilter::LUAFilterFactory
 
typedef std::shared_ptr
< LuaFilterFactory
LUAFilterFactoryPtr
 
typedef std::map< std::string,
LUAFilterFactoryPtr > 
FilterFactoryMap
 
using LuaSteeringFactory = movement::LUASteering::LUASteeringFactory
 
typedef std::shared_ptr
< LuaSteeringFactory
LUASteeringFactoryPtr
 
typedef std::map< std::string,
LUASteeringFactoryPtr > 
SteeringFactoryMap
 

Static Protected Member Functions

static LUAAIRegistryluaAI_toregistry (lua_State *s)
 
static LuaNodeFactoryluaAI_tonodefactory (lua_State *s, int n)
 
static LuaConditionFactoryluaAI_toconditionfactory (lua_State *s, int n)
 
static LuaFilterFactoryluaGetFilterFactoryContext (lua_State *s, int n)
 
static LuaSteeringFactoryluaAI_tosteeringfactory (lua_State *s, int n)
 
static int luaAI_nodeemptyexecute (lua_State *s)
 
static int luaAI_nodetostring (lua_State *s)
 
static int luaAI_createnode (lua_State *s)
 
static int luaAI_conditionemptyevaluate (lua_State *s)
 
static int luaAI_conditiontostring (lua_State *s)
 
static int luaAI_createcondition (lua_State *s)
 
static int luaAI_filteremptyfilter (lua_State *s)
 
static int luaAI_filtertostring (lua_State *s)
 
static int luaAI_createfilter (lua_State *s)
 
static int luaAI_steeringemptyexecute (lua_State *s)
 
static int luaAI_steeringtostring (lua_State *s)
 
static int luaAI_createsteering (lua_State *s)
 

Protected Attributes

lua_State * _s = nullptr
 
ReadWriteLock _lock {"luaregistry"}
 
TreeNodeFactoryMap _treeNodeFactories
 
ConditionFactoryMap _conditionFactories
 
FilterFactoryMap _filterFactories
 
SteeringFactoryMap _steeringFactories
 
- Protected Attributes inherited from ai::AIRegistry
TreeNodeFactory _treeNodeFactory
 
SteerNodeFactory _steerNodeFactory
 
SteeringFactory _steeringFactory
 
FilterFactory _filterFactory
 
ConditionFactory _conditionFactory
 

Detailed Description

Allows you to register lua TreeNodes, Conditions, Filters and ISteerings.

See Also
LUATreeNode
TreeNode
local luanode = REGISTRY.createNode("SomeName")
function luanode:execute(ai, deltaMillis)
print("Node execute called with parameters: ai=["..tostring(ai).."], deltaMillis=["..tostring(deltaMillis).."]")
return FINISHED
end
@encode
The @ai{TreeNodeStatus} states are put into the global space. They are: @c UNKNOWN, @c CANNOTEXECUTE,
@c RUNNING, @c FINISHED, @c FAILED and @c EXCEPTION
Use @c SomeName later on in your behaviour trees to use this @ai{ITreeNode}
@par Conditions
@code
local luacondition = REGISTRY.createCondition("SomeName")
function luacondition:evaluate(ai)
--print("Condition evaluate called with parameter: ai=["..tostring(ai).."]")
return true
end
@encode
Use @c SomeName later on in your behaviour trees to use this @ai{ICondition}
@par IFilter
@code
local luafilter = REGISTRY.createFilter("SomeName")
function luafilter:filter(ai)
end

Use SomeName later on in your behaviour trees to use this ICondition

ISteering
local luasteering = REGISTRY.createSteering("SomeName")
function luasteering:execute(ai, speed)
-- return MoveVector
return 0.0, 1.0, 0.0, 0.6
end

Use SomeName later on in your behaviour trees to use this ICondition

AI metatable
There is a metatable that you can modify by calling LUAAIRegistry::pushAIMetatable(). This metatable is applied to all AI pointers that are forwarded to the lua functions.

Member Function Documentation

bool ai::LUAAIRegistry::evaluate ( const char *  luaBuffer,
size_t  size 
)
inline

Load your lua scripts into the lua state of the registry. This can be called multiple times to e.g. load multiple files.

Returns
true if the lua script was loaded, false otherwise
Note
you have to call init() before
lua_State* ai::LUAAIRegistry::getLuaState ( )
inline

Access to the lua state.

See Also
pushAIMetatable()
bool ai::LUAAIRegistry::init ( )
inline
See Also
shutdown()
int ai::LUAAIRegistry::pushAIMetatable ( )
inline

Pushes the AI metatable onto the stack. This allows anyone to modify it to provide own functions and data that is applied to the ai parameters of the lua functions.

Note
lua_ctxai() can be used in your lua c callbacks to get access to the AI pointer:
const AI* ai = lua_ctxai(s, 1);
void ai::LUAAIRegistry::shutdown ( )
inline
See Also
init()

Member Data Documentation

std::vector<luaL_Reg> ai::LUAAIRegistry::aggroMgrFuncs
Initial value:
= {
{"setReduceByRatio", luaAI_aggromgrsetreducebyratio},
{"setReduceByValue", luaAI_aggromgrsetreducebyvalue},
{"resetReduceValue", luaAI_aggromgrresetreducevalue},
{"addAggro", luaAI_aggromgraddaggro},
{"highestEntry", luaAI_aggromgrhighestentry},
{"entries", luaAI_aggromgrentries},
{"__tostring", luaAI_aggromgrtostring},
{nullptr, nullptr}
}
std::vector<luaL_Reg> ai::LUAAIRegistry::aiFuncs
Initial value:
= {
{"id", luaAI_aiid},
{"time", luaAI_aitime},
{"hasZone", luaAI_aihaszone},
{"zone", luaAI_aigetzone},
{"filteredEntities", luaAI_aifilteredentities},
{"setFilteredEntities", luaAI_aisetfilteredentities},
{"addFilteredEntity", luaAI_aiaddfilteredentity},
{"character", luaAI_aigetcharacter},
{"aggroMgr", luaAI_aigetaggromgr},
{"__tostring", luaAI_aitostring},
{"__gc", luaAI_aigc},
{"__eq", luaAI_aieq},
{nullptr, nullptr}
}
std::vector<luaL_Reg> ai::LUAAIRegistry::characterFuncs
Initial value:
= {
{"id", luaAI_characterid},
{"position", luaAI_characterposition},
{"setPosition", luaAI_charactersetposition},
{"speed", luaAI_characterspeed},
{"setSpeed", luaAI_charactersetspeed},
{"orientation", luaAI_characterorientation},
{"setOrientation", luaAI_charactersetorientation},
{"setAttribute", luaAI_charactersetattribute},
{"attributes", luaAI_characterattributes},
{"__eq", luaAI_charactereq},
{"__gc", luaAI_charactergc},
{"__tostring", luaAI_charactertostring},
{nullptr, nullptr}
}
std::vector<luaL_Reg> ai::LUAAIRegistry::groupMgrFuncs
Initial value:
= {
{"add", luaAI_groupmgradd},
{"remove", luaAI_groupmgrremove},
{"isLeader", luaAI_groupmgrisleader},
{"isInGroup", luaAI_groupmgrisingroup},
{"isInAnyGroup", luaAI_groupmgrisinanygroup},
{"size", luaAI_groupmgrsize},
{"position", luaAI_groupmgrposition},
{"leader", luaAI_groupmgrleader},
{"__tostring", luaAI_groupmgrtostring},
{nullptr, nullptr}
}
std::vector<luaL_Reg> ai::LUAAIRegistry::registryFuncs
Initial value:
= {
{"createNode", luaAI_createnode},
{"createCondition", luaAI_createcondition},
{"createFilter", luaAI_createfilter},
{"createSteering", luaAI_createsteering},
{nullptr, nullptr}
}
std::vector<luaL_Reg> ai::LUAAIRegistry::vecFuncs
Initial value:
= {
{"__add", luaAI_vecadd},
{"__sub", luaAI_vecsub},
{"__mul", luaAI_vecdot},
{"__div", luaAI_vecdiv},
{"__unm", luaAI_vecnegate},
{"__len", luaAI_veclen},
{"__eq", luaAI_veceq},
{"__tostring", luaAI_vectostring},
{"__index", luaAI_vecindex},
{"__newindex", luaAI_vecnewindex},
{"dot", luaAI_vecdot},
{nullptr, nullptr}
}
std::vector<luaL_Reg> ai::LUAAIRegistry::zoneFuncs
Initial value:
= {
{"size", luaAI_zonesize},
{"name", luaAI_zonename},
{"ai", luaAI_zoneai},
{"execute", luaAI_zoneexecute},
{"groupMgr", luaAI_zonegroupmgr},
{"__tostring", luaAI_zonetostring},
{nullptr, nullptr}
}

The documentation for this class was generated from the following file: