forked from AtomicGameEngine/AtomicGameEngine
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNETCore.cpp
More file actions
93 lines (70 loc) · 2.27 KB
/
NETCore.cpp
File metadata and controls
93 lines (70 loc) · 2.27 KB
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#include <Atomic/Math/MathDefs.h>
#include <Atomic/Core/ProcessUtils.h>
#include <Atomic/Core/Thread.h>
#include <Atomic/IO/Log.h>
#include <Atomic/Script/ScriptVariantMap.h>
#include "NETCore.h"
#include "NETEventDispatcher.h"
namespace Atomic
{
SharedPtr<Context> NETCore::csContext_;
NETCoreEventDispatchFunction NETCore::eventDispatch_ = nullptr;
NETCoreUpdateDispatchFunction NETCore::updateDispatch_ = nullptr;
NETCoreRefCountedDeletedFunction NETCore::refCountedDeleted_ = nullptr;
NETCoreThrowManagedExceptionFunction NETCore::throwManagedException_ = nullptr;
NETCore::NETCore(Context* context, NETCoreDelegates* delegates) :
Object(context)
{
assert (!csContext_);
csContext_ = context;
eventDispatch_ = delegates->eventDispatch;
updateDispatch_ = delegates->updateDispatch;
refCountedDeleted_ = delegates->refCountedDeleted;
throwManagedException_ = delegates->throwManagedException;
NETEventDispatcher* dispatcher = new NETEventDispatcher(context_);
context_->RegisterSubsystem(dispatcher);
context_->AddGlobalEventListener(dispatcher);
RefCounted::AddRefCountedDeletedFunction(OnRefCountedDeleted);
}
NETCore::~NETCore()
{
RefCounted::RemoveRefCountedDeletedFunction(OnRefCountedDeleted);
assert (!csContext_);
}
bool NETCore::EnsureMainThread(const String& throwMsg)
{
if (!Thread::IsMainThread())
{
if (throwMsg.Length())
{
NETCore::ThrowManagedException(throwMsg.CString());
}
return false;
}
return true;
}
void NETCore::OnRefCountedDeleted(RefCounted* ref)
{
if (csContext_.Null())
return;
if (refCountedDeleted_)
refCountedDeleted_(ref);
}
void NETCore::RegisterNETEventType(unsigned eventType)
{
NETEventDispatcher* dispatcher = csContext_->GetSubsystem<NETEventDispatcher>();
dispatcher->RegisterNETEvent(StringHash(eventType));
}
void NETCore::Shutdown()
{
assert (csContext_);
csContext_->RemoveGlobalEventListener(csContext_->GetSubsystem<NETEventDispatcher>());
csContext_->RemoveSubsystem(NETEventDispatcher::GetTypeStatic());
eventDispatch_ = nullptr;
csContext_ = nullptr;
eventDispatch_ = nullptr;
updateDispatch_ = nullptr;
refCountedDeleted_ = nullptr;
throwManagedException_ = nullptr;
}
}