summaryrefslogtreecommitdiff
path: root/Runtime/Mono/MonoScriptCache.h
blob: 04271aed33bd4a8336b285a766710bd2e4f7e661 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#pragma once

#include "Runtime/Scripting/Backend/ScriptingTypes.h"
#include "Runtime/Threads/AtomicRefCounter.h"
#include "Runtime/Utilities/CStringHash.h"
#include "Runtime/Utilities/dynamic_array.h"
#include "MonoScriptType.h"

struct CommonScriptingClasses;


// A refcounted constant method cache for the MonoBehaviour.
// When creating the MonoScript it precomputes all available methods etc.
// The data is shared in this class.
// It is refcounted, in case the MonoSript is deleted before the MonoBehaviour is destroyed.

struct MonoScriptCache
{
	typedef std::map<const char*, ScriptingMethodPtr, compare_cstring> MethodCache;
	
	enum { kUpdate = 0, kLateUpdate, kFixedUpdate, kAwake, kStart, kMain, kRenderObject, kAddToManager, kRemoveFromManager, kRemoveFromManagerInternal, kCoroutineStart, kCoroutineMain, kRenderImageFilter, kDrawGizmos, kGUI, kValidateProperties, kSerializeNetView, kNetworkInstantiate, kOnDestroy, kAudioFilterRead, kMethodCount };
	
	AtomicRefCounter                  refCount;
	ScriptingClassPtr                 klass;
	dynamic_array<ScriptingMethodPtr> methods;	
	MethodCache                       methodCache;
	MonoScriptType                        scriptType;
	const char*                       className;

	#if UNITY_EDITOR
	bool                              scriptTypeWasJustCreatedFromComponentMenu;
	bool                              runInEditMode;
	#endif

	
	MonoScriptCache ();
	~MonoScriptCache ();	
	
	void Release () const;
	void Retain () const;
};

ScriptingMethodPtr FindMethod (const MonoScriptCache& cache, const char* name);

typedef void RegisterMonoRPCCallback (const char* name);
void RegisterMonoRPC (RegisterMonoRPCCallback* callback);
MonoScriptCache* CreateMonoScriptCache (ScriptingTypePtr klass, bool isEditorScript, Object* errorContext);

bool IsValidScriptType(MonoScriptType type);
std::string FormatScriptTypeError(MonoScriptType type, const std::string& fileName);