summaryrefslogtreecommitdiff
path: root/Runtime/Core/Callbacks
diff options
context:
space:
mode:
Diffstat (limited to 'Runtime/Core/Callbacks')
-rw-r--r--Runtime/Core/Callbacks/CallbackArray.cpp40
-rw-r--r--Runtime/Core/Callbacks/CallbackArray.h21
-rw-r--r--Runtime/Core/Callbacks/GlobalCallbacks.cpp9
-rw-r--r--Runtime/Core/Callbacks/GlobalCallbacks.h30
-rw-r--r--Runtime/Core/Callbacks/PlayerLoopCallbacks.cpp9
-rw-r--r--Runtime/Core/Callbacks/PlayerLoopCallbacks.h39
6 files changed, 148 insertions, 0 deletions
diff --git a/Runtime/Core/Callbacks/CallbackArray.cpp b/Runtime/Core/Callbacks/CallbackArray.cpp
new file mode 100644
index 0000000..adea73f
--- /dev/null
+++ b/Runtime/Core/Callbacks/CallbackArray.cpp
@@ -0,0 +1,40 @@
+#include "UnityPrefix.h"
+#include "CallbackArray.h"
+
+CallbackArray::CallbackArray ()
+{
+ for (int i=0;i<kMaxCallback;i++)
+ m_Callbacks[i] = NULL;
+}
+
+void CallbackArray::Register (SimpleCallback* callback)
+{
+ for (int i=0;i<kMaxCallback;i++)
+ {
+ if (m_Callbacks[i] == NULL)
+ {
+ m_Callbacks[i] = callback;
+ return;
+ }
+ }
+
+ AssertString("Callback registration failed. Not enough space.");
+}
+
+void CallbackArray::Unregister (SimpleCallback* callback)
+{
+ for (int i=0;i<kMaxCallback;i++)
+ {
+ if (m_Callbacks[i] == callback)
+ m_Callbacks[i] = NULL;
+ }
+}
+
+void CallbackArray::Invoke ()
+{
+ for (int i=0;i<kMaxCallback;i++)
+ {
+ if (m_Callbacks[i])
+ m_Callbacks[i] ();
+ }
+} \ No newline at end of file
diff --git a/Runtime/Core/Callbacks/CallbackArray.h b/Runtime/Core/Callbacks/CallbackArray.h
new file mode 100644
index 0000000..904769f
--- /dev/null
+++ b/Runtime/Core/Callbacks/CallbackArray.h
@@ -0,0 +1,21 @@
+#pragma once
+
+#include "Runtime/Modules/ExportModules.h"
+
+class EXPORT_COREMODULE CallbackArray
+{
+ public:
+
+ typedef void SimpleCallback ();
+
+ CallbackArray ();
+
+ void Register (SimpleCallback* callback);
+ void Unregister (SimpleCallback* callback);
+ void Invoke ();
+
+ private:
+
+ enum { kMaxCallback = 6 };
+ SimpleCallback* m_Callbacks[kMaxCallback];
+};
diff --git a/Runtime/Core/Callbacks/GlobalCallbacks.cpp b/Runtime/Core/Callbacks/GlobalCallbacks.cpp
new file mode 100644
index 0000000..5e9534b
--- /dev/null
+++ b/Runtime/Core/Callbacks/GlobalCallbacks.cpp
@@ -0,0 +1,9 @@
+#include "UnityPrefix.h"
+#include "GlobalCallbacks.h"
+
+static GlobalCallbacks gGlobalCallback;
+
+GlobalCallbacks& GlobalCallbacks::Get()
+{
+ return gGlobalCallback;
+}
diff --git a/Runtime/Core/Callbacks/GlobalCallbacks.h b/Runtime/Core/Callbacks/GlobalCallbacks.h
new file mode 100644
index 0000000..ddfccca
--- /dev/null
+++ b/Runtime/Core/Callbacks/GlobalCallbacks.h
@@ -0,0 +1,30 @@
+#pragma once
+
+#include "CallbackArray.h"
+#include "Runtime/Modules/ExportModules.h"
+
+struct EXPORT_COREMODULE GlobalCallbacks
+{
+ public:
+
+ // Called after loading the level.
+ // Resets all Random number seeds in the engine after loading a level.
+ CallbackArray resetRandomAfterLevelLoad;
+
+ CallbackArray didReloadMonoDomain;
+ CallbackArray didUnloadScene;
+
+ CallbackArray registerGizmos;
+
+ //only used by hacky audiocode, should be killed.
+ CallbackArray managersWillBeReloadedHack;
+
+ CallbackArray willSaveScene;
+ CallbackArray initializedEngineGraphics;
+
+ CallbackArray initialDomainReloadingComplete;
+
+ static GlobalCallbacks& Get();
+};
+
+#define REGISTER_GLOBAL_CALLBACK(eventName,body) struct eventName { static void Forward () { body; } }; GlobalCallbacks::Get().eventName.Register(eventName::Forward);
diff --git a/Runtime/Core/Callbacks/PlayerLoopCallbacks.cpp b/Runtime/Core/Callbacks/PlayerLoopCallbacks.cpp
new file mode 100644
index 0000000..072a427
--- /dev/null
+++ b/Runtime/Core/Callbacks/PlayerLoopCallbacks.cpp
@@ -0,0 +1,9 @@
+#include "UnityPrefix.h"
+#include "PlayerLoopCallbacks.h"
+
+PlayerLookCallbacks gPlayerLoopCallbacks;
+
+PlayerLookCallbacks::PlayerLookCallbacks ()
+{
+ memset(this, 0, sizeof(PlayerLookCallbacks));
+} \ No newline at end of file
diff --git a/Runtime/Core/Callbacks/PlayerLoopCallbacks.h b/Runtime/Core/Callbacks/PlayerLoopCallbacks.h
new file mode 100644
index 0000000..49dd86e
--- /dev/null
+++ b/Runtime/Core/Callbacks/PlayerLoopCallbacks.h
@@ -0,0 +1,39 @@
+#pragma once
+
+#include "Runtime/Modules/ExportModules.h"
+
+struct PlayerLookCallbacks
+{
+ typedef void UpdateFunc ();
+
+ PlayerLookCallbacks ();
+
+ // Animators
+ UpdateFunc* AnimatorFixedUpdateRetargetIKWrite;
+ UpdateFunc* AnimatorUpdateRetargetIKWrite;
+ UpdateFunc* AnimatorUpdateFKMove;
+ UpdateFunc* AnimatorFixedUpdateFKMove;
+
+ // Physics
+ UpdateFunc* PhysicsFixedUpdate;
+ UpdateFunc* PhysicsUpdate;
+ UpdateFunc* PhysicsRefreshWhenPaused;
+ UpdateFunc* PhysicsSkinnedClothUpdate;
+ UpdateFunc* PhysicsResetInterpolatedTransformPosition;
+
+ // 2D Physics
+ UpdateFunc* Physics2DUpdate;
+ UpdateFunc* Physics2DFixedUpdate;
+ UpdateFunc* Physics2DResetInterpolatedTransformPosition;
+
+ // Navmesh
+ UpdateFunc* NavMeshUpdate;
+
+ // Legacy Animation
+ UpdateFunc* LegacyFixedAnimationUpdate;
+ UpdateFunc* LegacyAnimationUpdate;
+};
+EXPORT_COREMODULE extern PlayerLookCallbacks gPlayerLoopCallbacks;
+
+#define CALL_UPDATE_MODULAR(x) if (gPlayerLoopCallbacks.x) gPlayerLoopCallbacks.x ();
+#define REGISTER_PLAYERLOOP_CALL(name,body) struct name { static void Forward () { body; } }; gPlayerLoopCallbacks.name = name::Forward;