Leviathan  0.8.0.0
Leviathan game engine
Leviathan::ScriptNotifier Class Reference

BaseNotifier for use in scripts. More...

#include <ScriptNotifiers.h>

+ Inheritance diagram for Leviathan::ScriptNotifier:

Public Member Functions

DLLEXPORT ScriptNotifier (asIScriptFunction *functiontocall)
 
virtual DLLEXPORT ~ScriptNotifier ()
 
- Public Member Functions inherited from Leviathan::BaseNotifierAll
 BaseNotifierAll ()
 
 ~BaseNotifierAll ()
 
- Public Member Functions inherited from Leviathan::BaseNotifier< BaseNotifierAll, BaseNotifiableAll >
 BaseNotifier (BaseNotifierAll *ourptr)
 
virtual ~BaseNotifier ()
 
void ReleaseChildHooks ()
 Release function that unhooks all child objects. More...
 
void ReleaseChildHooks (Lock &guard)
 
FORCE_INLINE bool ConnectToNotifiable (BaseNotifiable< BaseNotifierAll, BaseNotifiableAll > *child)
 Connects this to a notifiable object for holding a reference to it. More...
 
bool ConnectToNotifiable (Lock &guard, BaseNotifiable< BaseNotifierAll, BaseNotifiableAll > *child, Lock &childlock)
 The actual implementation of ConnecToNotifiable. More...
 
virtual void NotifyAll (Lock &guard)
 Notifies the children about something. More...
 
bool UnConnectFromNotifiable (Lock &guard, BaseNotifiable< BaseNotifierAll, BaseNotifiableAll > *unhookfrom)
 Disconnects from previously connected notifiable. More...
 
FORCE_INLINE bool UnConnectFromNotifiable (BaseNotifiable< BaseNotifierAll, BaseNotifiableAll > *child)
 
bool UnConnectFromNotifiable (int id)
 Searches the connected notifiable objects and calls the above function with it's pointer. More...
 
bool IsConnectedTo (BaseNotifiable< BaseNotifierAll, BaseNotifiableAll > *check, Lock &guard)
 Actual implementation of this method. More...
 
FORCE_INLINE bool IsConnectedTo (BaseNotifiable< BaseNotifierAll, BaseNotifiableAll > *check)
 Returns true when the specified object is already connected. More...
 
void _OnUnhookNotifiable (Lock &guard, BaseNotifiable< BaseNotifierAll, BaseNotifiableAll > *childtoremove, Lock &childlock)
 
void _OnHookNotifiable (Lock &guard, BaseNotifiable< BaseNotifierAll, BaseNotifiableAll > *child, Lock &childlock)
 
BaseNotifierAllGetActualPointerToNotifierObject ()
 Gets the internal pointer to the actual object. More...
 
- Public Member Functions inherited from Leviathan::ThreadSafeGeneric< MutexType >
DLLEXPORT ThreadSafeGeneric ()
 
DLLEXPORT ~ThreadSafeGeneric ()
 
FORCE_INLINE void VerifyLock (RecursiveLock &guard) const
 
FORCE_INLINE void VerifyLock (Lock &lockit) const
 
- Public Member Functions inherited from Leviathan::ReferenceCounted
 ReferenceCounted (const ReferenceCounted &other)=delete
 
ReferenceCountedoperator= (const ReferenceCounted &other)=delete
 
FORCE_INLINE void AddRef ()
 
FORCE_INLINE void Release ()
 removes a reference and deletes the object if reference count reaches zero More...
 
int32_t GetRefCount () const
 Returns the reference count. More...
 

Protected Member Functions

virtual void OnNotified (Lock &ownlock, BaseNotifiableAll *child, Lock &childlock) override
 Calls into the script engine. More...
 
- Protected Member Functions inherited from Leviathan::BaseNotifier< BaseNotifierAll, BaseNotifiableAll >
virtual void _OnNotifiableConnected (Lock &guard, BaseNotifiableAll *childadded, Lock &childlock)
 
virtual void _OnNotifiableDisconnected (Lock &guard, BaseNotifiableAll *childtoremove, Lock &childlock)
 
- Protected Member Functions inherited from Leviathan::ReferenceCounted
DLLEXPORT ReferenceCounted ()
 
virtual DLLEXPORT ~ReferenceCounted ()
 

Protected Attributes

asIScriptFunction * CallbackFunction
 The function that is called when this is notified. More...
 
- Protected Attributes inherited from Leviathan::BaseNotifier< BaseNotifierAll, BaseNotifiableAll >
BaseNotifierAllPointerToOurNotifier
 Stores a pointer to the object that is inherited from this. More...
 
std::vector< BaseNotifiable< BaseNotifierAll, BaseNotifiableAll > *> ConnectedChildren
 Vector of other objects that this is connected to. More...
 
- Protected Attributes inherited from Leviathan::ThreadSafeGeneric< MutexType >
MutexType ObjectsLock
 

Additional Inherited Members

- Public Types inherited from Leviathan::ThreadSafeGeneric< MutexType >
using LockT = typename LockTypeResolver< MutexType >::LType
 
- Public Types inherited from Leviathan::ReferenceCounted
using basepointer = boost::intrusive_ptr< ReferenceCounted >
 
using refcountedpointer = boost::intrusive_ptr< ReferenceCounted >
 
- Static Public Member Functions inherited from Leviathan::ReferenceCounted
template<class ActualType >
static boost::intrusive_ptr< ActualType > WrapPtr (ActualType *ptr)
 Creates an intrusive_ptr from raw pointer. More...
 
template<class ActualType , class... Args>
static boost::intrusive_ptr< ActualType > MakeShared (Args &&... args)
 Constructs a new instance and wraps it. More...
 

Detailed Description

BaseNotifier for use in scripts.

Definition at line 16 of file ScriptNotifiers.h.

Constructor & Destructor Documentation

◆ ScriptNotifier()

DLLEXPORT Leviathan::ScriptNotifier::ScriptNotifier ( asIScriptFunction *  functiontocall)

Definition at line 12 of file ScriptNotifiers.cpp.

12  :
13  CallbackFunction(functiontocall)
14 {
15  // TODO: increase ref count? or does the caller do that
16 }
asIScriptFunction * CallbackFunction
The function that is called when this is notified.

◆ ~ScriptNotifier()

DLLEXPORT Leviathan::ScriptNotifier::~ScriptNotifier ( )
virtual

Definition at line 18 of file ScriptNotifiers.cpp.

18  {
19 
20  GUARD_LOCK();
21 
22  ReleaseChildHooks(guard);
23 
25  CallbackFunction->Release();
26 
27  CallbackFunction = NULL;
28 }
asIScriptFunction * CallbackFunction
The function that is called when this is notified.
void ReleaseChildHooks()
Release function that unhooks all child objects.
Definition: BaseNotifier.h:17
#define GUARD_LOCK()
Definition: ThreadSafe.h:111

Member Function Documentation

◆ OnNotified()

void Leviathan::ScriptNotifier::OnNotified ( Lock ownlock,
BaseNotifiableAll child,
Lock childlock 
)
overrideprotectedvirtual

Calls into the script engine.

Reimplemented from Leviathan::BaseNotifier< BaseNotifierAll, BaseNotifiableAll >.

Definition at line 30 of file ScriptNotifiers.cpp.

32 {
33  ScriptRunningSetup params;
34  params.ErrorOnNonExistingFunction = true;
35 
36  auto result = ScriptExecutor::Get()->RunScript<void>(CallbackFunction, nullptr, params);
37 
38  if(result.Result != SCRIPT_RUN_RESULT::Success)
39  LOG_ERROR("ScriptNotifier: OnNotified: failed to call script callback");
40 }
ScriptRunResult< ReturnT > RunScript(const std::shared_ptr< ScriptModule > &module, ScriptRunningSetup &parameters, Args &&... args)
Runs a function in a script.
#define LOG_ERROR(x)
Definition: Define.h:84
static DLLEXPORT ScriptExecutor * Get()
asIScriptFunction * CallbackFunction
The function that is called when this is notified.

Member Data Documentation

◆ CallbackFunction

asIScriptFunction* Leviathan::ScriptNotifier::CallbackFunction
protected

The function that is called when this is notified.

Definition at line 31 of file ScriptNotifiers.h.


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