Leviathan  0.8.0.0
Leviathan game engine
Leviathan::ScriptNotifiable Class Reference

BaseNotifiable for use in scripts. More...

#include <ScriptNotifiers.h>

+ Inheritance diagram for Leviathan::ScriptNotifiable:

Public Member Functions

DLLEXPORT ScriptNotifiable (asIScriptFunction *functiontocall)
 
virtual DLLEXPORT ~ScriptNotifiable ()
 
- Public Member Functions inherited from Leviathan::BaseNotifiableAll
 BaseNotifiableAll ()
 
 ~BaseNotifiableAll ()
 
- Public Member Functions inherited from Leviathan::BaseNotifiable< BaseNotifierAll, BaseNotifiableAll >
 BaseNotifiable (BaseNotifiableAll *ourptr)
 
virtual ~BaseNotifiable ()
 
void ReleaseParentHooks (Lock &guard)
 Release function which releases all hooks. More...
 
bool UnConnectFromNotifier (Lock &guard, BaseNotifier< BaseNotifierAll, BaseNotifiableAll > *specificnotifier, Lock &notifierlock)
 The actual implementation of UnConnectFromNotifier. More...
 
bool UnConnectFromNotifier (Lock &guard, BaseNotifier< BaseNotifierAll, BaseNotifiableAll > *specificnotifier)
 
FORCE_INLINE bool UnConnectFromNotifier (BaseNotifier< BaseNotifierAll, BaseNotifiableAll > *specificnotifier)
 Disconnects this from a previously connected notifier. More...
 
bool UnConnectFromNotifier (int id)
 This searches the connected notifiers and calls the above function with it's pointer. More...
 
virtual void NotifyAll (Lock &guard)
 Notifies all the parents of this object about something. More...
 
bool IsConnectedTo (BaseNotifier< BaseNotifierAll, BaseNotifiableAll > *check, Lock &guard)
 Actual implementation of this method. More...
 
FORCE_INLINE bool IsConnectedTo (BaseNotifier< BaseNotifierAll, BaseNotifiableAll > *check)
 Returns true when the specified object is already connected. More...
 
bool ConnectToNotifier (BaseNotifier< BaseNotifierAll, BaseNotifiableAll > *owner)
 Connects this to a notifier object calling all the needed functions. More...
 
bool ConnectToNotifier (Lock &unlockable, BaseNotifier< BaseNotifierAll, BaseNotifiableAll > *owner)
 Variant for already locked objects. More...
 
void _OnUnhookNotifier (Lock &locked, BaseNotifier< BaseNotifierAll, BaseNotifiableAll > *parent, Lock &parentlock)
 Callback called by the parent, used to not to call the unhook again on the parent. More...
 
void _OnHookNotifier (Lock &locked, BaseNotifier< BaseNotifierAll, BaseNotifiableAll > *parent, Lock &parentlock)
 Called by parent to hook, and doesn't call the parent's functions. More...
 
BaseNotifiableAllGetActualPointerToNotifiableObject ()
 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, BaseNotifierAll *parent, Lock &parentlock) override
 Calls into the script engine. More...
 
- Protected Member Functions inherited from Leviathan::BaseNotifiable< BaseNotifierAll, BaseNotifiableAll >
virtual void _OnNotifierConnected (Lock &guard, BaseNotifierAll *parentadded, Lock &parentlock)
 
virtual void _OnNotifierDisconnected (Lock &guard, BaseNotifierAll *parentremoved, Lock &parentlock)
 
- 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::BaseNotifiable< BaseNotifierAll, BaseNotifiableAll >
BaseNotifiableAllPointerToOurNotifiable
 Stores a pointer to the object that is inherited from this. More...
 
std::vector< BaseNotifier< BaseNotifierAll, BaseNotifiableAll > *> ConnectedToParents
 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::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

BaseNotifiable for use in scripts.

Definition at line 36 of file ScriptNotifiers.h.

Constructor & Destructor Documentation

◆ ScriptNotifiable()

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

Definition at line 42 of file ScriptNotifiers.cpp.

42  :
43  CallbackFunction(functiontocall)
44 {
45  // TODO: increase ref count? or does the caller do that
46 }
asIScriptFunction * CallbackFunction
The function that is called when this is notified.

◆ ~ScriptNotifiable()

DLLEXPORT Leviathan::ScriptNotifiable::~ScriptNotifiable ( )
virtual

Definition at line 48 of file ScriptNotifiers.cpp.

48  {
49 
50  GUARD_LOCK();
51 
52  ReleaseParentHooks(guard);
53 
55  CallbackFunction->Release();
56 
57  CallbackFunction = NULL;
58 }
asIScriptFunction * CallbackFunction
The function that is called when this is notified.
void ReleaseParentHooks(Lock &guard)
Release function which releases all hooks.
#define GUARD_LOCK()
Definition: ThreadSafe.h:97

Member Function Documentation

◆ OnNotified()

void Leviathan::ScriptNotifiable::OnNotified ( Lock ownlock,
BaseNotifierAll parent,
Lock parentlock 
)
overrideprotectedvirtual

Calls into the script engine.

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

Definition at line 60 of file ScriptNotifiers.cpp.

62 {
63  ScriptRunningSetup params;
64  params.ErrorOnNonExistingFunction = true;
65 
66  auto result = ScriptExecutor::Get()->RunScript<void>(CallbackFunction, nullptr, params);
67 
68  if(result.Result != SCRIPT_RUN_RESULT::Success)
69  LOG_ERROR("ScriptNotifiable: OnNotified: failed to call script callback");
70 }
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:83
asIScriptFunction * CallbackFunction
The function that is called when this is notified.
static DLLEXPORT ScriptExecutor * Get()

Member Data Documentation

◆ CallbackFunction

asIScriptFunction* Leviathan::ScriptNotifiable::CallbackFunction
protected

The function that is called when this is notified.

Definition at line 51 of file ScriptNotifiers.h.


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