Annwvyn::AnnScriptManager Class Reference

Script Manager, serve as an interface between ChaiScript and the rest of the engine. More...

#include <AnnScriptManager.hpp>

Inheritance diagram for Annwvyn::AnnScriptManager:
Collaboration diagram for Annwvyn::AnnScriptManager:

Public Types

using AnnScriptID = uID
 

Public Member Functions

 AnnScriptManager ()
 Construct the script manager, initialize ChaiScript and add global functions. Will initialize the AnnScriptFileManager. More...
 
 ~AnnScriptManager ()
 Destruct the Script Manager. will destroy the AnnScriptFileManager. More...
 
bool needUpdate () override
 This subsystem doesn't need to be updated. More...
 
void update () override
 This method does nothing. More...
 
bool evalFile (const std::string &file)
 Evaluate a file. Exceptions internally catches with messages in the log. Return true or false depending on errors. More...
 
std::shared_ptr< AnnBehaviorScriptgetBehaviorScript (const std::string &scriptName, AnnGameObject *owner=nullptr)
 Create a instance to the script. Return a shared pointer. More...
 
void evalString (const std::string &chaiCode)
 Evaluate one line of chaiCode. More...
 
chaiscript::ChaiScript * _getEngine ()
 GetAccess to the chaiscript engine. Only use for special cases. More...
 
- Public Member Functions inherited from Annwvyn::AnnSubSystem
 AnnSubSystem (const std::string &systemName)
 Construct a SubSystem. More...
 
virtual ~AnnSubSystem ()
 Destruct a SubSystem. More...
 

Private Member Functions

void registerApi ()
 Register to the script engine all the things that are possible to do. Called by the constructor. More...
 
void registerResourceManager ()
 Register the scriptFileManager. More...
 
void unregisterResourceManager ()
 Unregister the scriptFileManager. More...
 
void tryAndGetEventHooks ()
 Hook the event listener's "methdod" to the script ones, if possible... More...
 

Private Attributes

chaiscript::ChaiScript chai
 ChaiScript engine. More...
 
AnnScriptFileResourceManagerscriptFileManager
 Pointer to the script manager. More...
 
std::function< void(chaiscript::Boxed_Value &, AnnKeyEvent)> callKeyEventOnScriptInstance
 To create the event hooks for the scripts : More...
 
std::function< void(chaiscript::Boxed_Value &, AnnMouseEvent)> callMouseEventOnScriptInstance
 
std::function< void(chaiscript::Boxed_Value &, AnnControllerEvent)> callStickEventOnScriptInstance
 
std::function< void(chaiscript::Boxed_Value &, AnnTimeEvent)> callTimeEventOnScriptInstance
 
std::function< void(chaiscript::Boxed_Value &, AnnTriggerEvent)> callTriggerEventOnScriptInstance
 
std::function< void(chaiscript::Boxed_Value &, AnnHandControllerEvent)> callHandControllertOnScriptInstance
 
std::function< void(chaiscript::Boxed_Value &, AnnCollisionEvent)> callCollisionEventOnScriptInstance
 
std::function< void(chaiscript::Boxed_Value &, AnnPlayerCollisionEvent)> callPlayerCollisionEventOnScriptInstance
 

Static Private Attributes

static constexpr const char *const scriptExtension { ".chai" }
 The extension of script files. More...
 
static constexpr const char *const fileErrorPrefix { "Script File ERROR - " }
 Prefix for error regarding loading script files. More...
 
static constexpr const char *const logFromScript { "Script - " }
 Prefix for debug print called from a script. More...
 
static constexpr const char *const scriptTemplate
 String constant for script loading and class initialization. This is a bit of ChaiScript code to bootstrap a behavior script. More...
 
static constexpr const char *const scriptNameMarker { "__SCRIPT_NAME__" }
 Marker for the name of the script. More...
 
static constexpr const char *const scriptObjectID { "__OBJECT_SCRIPT_ID__" }
 Marker for the ID of the script. More...
 
static constexpr const char *const scriptOwnerMarker { "__SCRIPT_OWNER__" }
 Marker for the owner of the script. More...
 
static constexpr const char *const scriptInstanceMarker { "ScriptInstance" }
 Prefix of the name of an instance. More...
 
static constexpr const char *const scriptOwnerPrefix { "ScriptOwner" }
 Prefix for the owner of a script. More...
 
static constexpr const size_t nameMarkerLen { 15 }
 Static lengths of constant string of the same name. More...
 
static constexpr const size_t scriptIDMarkerLen { 20 }
 Static lengths of constant string of the same name. More...
 
static constexpr const size_t scriptOwnerMarkerLen { 16 }
 Static lengths of constant string of the same name. More...
 
static AnnScriptID ID { 0 }
 Static counter that will be incremented at each script creation. More...
 

Additional Inherited Members

- Protected Attributes inherited from Annwvyn::AnnSubSystem
std::string name
 Name of the subsystem. More...
 

Detailed Description

Script Manager, serve as an interface between ChaiScript and the rest of the engine.

Definition at line 120 of file AnnScriptManager.hpp.

Member Typedef Documentation

◆ AnnScriptID

Constructor & Destructor Documentation

◆ AnnScriptManager()

AnnScriptManager::AnnScriptManager ( )

Construct the script manager, initialize ChaiScript and add global functions. Will initialize the AnnScriptFileManager.

Definition at line 17 of file AnnScriptManager.cpp.

Here is the call graph for this function:

◆ ~AnnScriptManager()

AnnScriptManager::~AnnScriptManager ( )

Destruct the Script Manager. will destroy the AnnScriptFileManager.

Definition at line 797 of file AnnScriptManager.cpp.

Here is the call graph for this function:

Member Function Documentation

◆ _getEngine()

chaiscript::ChaiScript * AnnScriptManager::_getEngine ( )

GetAccess to the chaiscript engine. Only use for special cases.

Definition at line 802 of file AnnScriptManager.cpp.

◆ evalFile()

bool AnnScriptManager::evalFile ( const std::string file)

Evaluate a file. Exceptions internally catches with messages in the log. Return true or false depending on errors.

Definition at line 458 of file AnnScriptManager.cpp.

◆ evalString()

void AnnScriptManager::evalString ( const std::string chaiCode)

Evaluate one line of chaiCode.

Definition at line 781 of file AnnScriptManager.cpp.

◆ getBehaviorScript()

std::shared_ptr< AnnBehaviorScript > AnnScriptManager::getBehaviorScript ( const std::string scriptName,
AnnGameObject owner = nullptr 
)

Create a instance to the script. Return a shared pointer.

Definition at line 479 of file AnnScriptManager.cpp.

Here is the call graph for this function:

◆ needUpdate()

bool Annwvyn::AnnScriptManager::needUpdate ( )
inlineoverridevirtual

This subsystem doesn't need to be updated.

Reimplemented from Annwvyn::AnnSubSystem.

Definition at line 132 of file AnnScriptManager.hpp.

◆ registerApi()

void AnnScriptManager::registerApi ( )
private

Register to the script engine all the things that are possible to do. Called by the constructor.

Clear the console

Definition at line 26 of file AnnScriptManager.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ registerResourceManager()

void AnnScriptManager::registerResourceManager ( )
private

Register the scriptFileManager.

Definition at line 786 of file AnnScriptManager.cpp.

Here is the caller graph for this function:

◆ tryAndGetEventHooks()

void AnnScriptManager::tryAndGetEventHooks ( )
private

Hook the event listener's "methdod" to the script ones, if possible...

Definition at line 379 of file AnnScriptManager.cpp.

Here is the caller graph for this function:

◆ unregisterResourceManager()

void AnnScriptManager::unregisterResourceManager ( )
private

Unregister the scriptFileManager.

Definition at line 791 of file AnnScriptManager.cpp.

Here is the caller graph for this function:

◆ update()

void Annwvyn::AnnScriptManager::update ( )
inlineoverridevirtual

This method does nothing.

Reimplemented from Annwvyn::AnnSubSystem.

Definition at line 135 of file AnnScriptManager.hpp.

Member Data Documentation

◆ callCollisionEventOnScriptInstance

std::function<void(chaiscript::Boxed_Value&, AnnCollisionEvent)> Annwvyn::AnnScriptManager::callCollisionEventOnScriptInstance
private

Definition at line 211 of file AnnScriptManager.hpp.

◆ callHandControllertOnScriptInstance

std::function<void(chaiscript::Boxed_Value&, AnnHandControllerEvent)> Annwvyn::AnnScriptManager::callHandControllertOnScriptInstance
private

Definition at line 210 of file AnnScriptManager.hpp.

◆ callKeyEventOnScriptInstance

std::function<void(chaiscript::Boxed_Value&, AnnKeyEvent)> Annwvyn::AnnScriptManager::callKeyEventOnScriptInstance
private

To create the event hooks for the scripts :

Definition at line 205 of file AnnScriptManager.hpp.

◆ callMouseEventOnScriptInstance

std::function<void(chaiscript::Boxed_Value&, AnnMouseEvent)> Annwvyn::AnnScriptManager::callMouseEventOnScriptInstance
private

Definition at line 206 of file AnnScriptManager.hpp.

◆ callPlayerCollisionEventOnScriptInstance

std::function<void(chaiscript::Boxed_Value&, AnnPlayerCollisionEvent)> Annwvyn::AnnScriptManager::callPlayerCollisionEventOnScriptInstance
private

Definition at line 212 of file AnnScriptManager.hpp.

◆ callStickEventOnScriptInstance

std::function<void(chaiscript::Boxed_Value&, AnnControllerEvent)> Annwvyn::AnnScriptManager::callStickEventOnScriptInstance
private

Definition at line 207 of file AnnScriptManager.hpp.

◆ callTimeEventOnScriptInstance

std::function<void(chaiscript::Boxed_Value&, AnnTimeEvent)> Annwvyn::AnnScriptManager::callTimeEventOnScriptInstance
private

Definition at line 208 of file AnnScriptManager.hpp.

◆ callTriggerEventOnScriptInstance

std::function<void(chaiscript::Boxed_Value&, AnnTriggerEvent)> Annwvyn::AnnScriptManager::callTriggerEventOnScriptInstance
private

Definition at line 209 of file AnnScriptManager.hpp.

◆ chai

chaiscript::ChaiScript Annwvyn::AnnScriptManager::chai
private

ChaiScript engine.

Definition at line 151 of file AnnScriptManager.hpp.

◆ fileErrorPrefix

constexpr const char *const AnnScriptManager::fileErrorPrefix { "Script File ERROR - " }
staticprivate

Prefix for error regarding loading script files.

Definition at line 169 of file AnnScriptManager.hpp.

◆ ID

AnnScriptManager::AnnScriptID AnnScriptManager::ID { 0 }
staticprivate

Static counter that will be incremented at each script creation.

Definition at line 202 of file AnnScriptManager.hpp.

◆ logFromScript

constexpr const char *const AnnScriptManager::logFromScript { "Script - " }
staticprivate

Prefix for debug print called from a script.

Definition at line 172 of file AnnScriptManager.hpp.

◆ nameMarkerLen

constexpr const size_t Annwvyn::AnnScriptManager::nameMarkerLen { 15 }
staticprivate

Static lengths of constant string of the same name.

Definition at line 195 of file AnnScriptManager.hpp.

◆ scriptExtension

constexpr const char* const Annwvyn::AnnScriptManager::scriptExtension { ".chai" }
staticprivate

The extension of script files.

Definition at line 166 of file AnnScriptManager.hpp.

◆ scriptFileManager

AnnScriptFileResourceManager* Annwvyn::AnnScriptManager::scriptFileManager
private

Pointer to the script manager.

Definition at line 154 of file AnnScriptManager.hpp.

◆ scriptIDMarkerLen

constexpr const size_t Annwvyn::AnnScriptManager::scriptIDMarkerLen { 20 }
staticprivate

Static lengths of constant string of the same name.

Definition at line 197 of file AnnScriptManager.hpp.

◆ scriptInstanceMarker

constexpr const char* const Annwvyn::AnnScriptManager::scriptInstanceMarker { "ScriptInstance" }
staticprivate

Prefix of the name of an instance.

Definition at line 190 of file AnnScriptManager.hpp.

◆ scriptNameMarker

constexpr const char* const Annwvyn::AnnScriptManager::scriptNameMarker { "__SCRIPT_NAME__" }
staticprivate

Marker for the name of the script.

Definition at line 184 of file AnnScriptManager.hpp.

◆ scriptObjectID

constexpr const char* const Annwvyn::AnnScriptManager::scriptObjectID { "__OBJECT_SCRIPT_ID__" }
staticprivate

Marker for the ID of the script.

Definition at line 186 of file AnnScriptManager.hpp.

◆ scriptOwnerMarker

constexpr const char* const Annwvyn::AnnScriptManager::scriptOwnerMarker { "__SCRIPT_OWNER__" }
staticprivate

Marker for the owner of the script.

Definition at line 188 of file AnnScriptManager.hpp.

◆ scriptOwnerMarkerLen

constexpr const size_t Annwvyn::AnnScriptManager::scriptOwnerMarkerLen { 16 }
staticprivate

Static lengths of constant string of the same name.

Definition at line 199 of file AnnScriptManager.hpp.

◆ scriptOwnerPrefix

constexpr const char* const Annwvyn::AnnScriptManager::scriptOwnerPrefix { "ScriptOwner" }
staticprivate

Prefix for the owner of a script.

Definition at line 192 of file AnnScriptManager.hpp.

◆ scriptTemplate

constexpr const char* const Annwvyn::AnnScriptManager::scriptTemplate
staticprivate
Initial value:
{
R"chaiscript(def create__SCRIPT_NAME____OBJECT_SCRIPT_ID__(owner)
{
var ScriptInstance__OBJECT_SCRIPT_ID__ = __SCRIPT_NAME__(owner);
return ScriptInstance__OBJECT_SCRIPT_ID__;
})chaiscript"
}

String constant for script loading and class initialization. This is a bit of ChaiScript code to bootstrap a behavior script.

Definition at line 175 of file AnnScriptManager.hpp.


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