NETCore.cpp 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. #include <Atomic/Math/MathDefs.h>
  2. #include <Atomic/Core/ProcessUtils.h>
  3. #include <Atomic/IO/Log.h>
  4. #include <Atomic/Script/ScriptVariantMap.h>
  5. #include "NETCore.h"
  6. #include "NETEventDispatcher.h"
  7. namespace Atomic
  8. {
  9. SharedPtr<Context> NETCore::csContext_;
  10. NETCoreEventDispatchFunction NETCore::eventDispatch_ = nullptr;
  11. NETCoreUpdateDispatchFunction NETCore::updateDispatch_ = nullptr;
  12. NETCoreRefCountedDeletedFunction NETCore::refCountedDeleted_ = nullptr;
  13. NETCore::NETCore(Context* context, NETCoreDelegates* delegates) :
  14. Object(context)
  15. {
  16. assert (!csContext_);
  17. csContext_ = context;
  18. eventDispatch_ = delegates->eventDispatch;
  19. updateDispatch_ = delegates->updateDispatch;
  20. refCountedDeleted_ = delegates->refCountedDeleted;
  21. NETEventDispatcher* dispatcher = new NETEventDispatcher(context_);
  22. context_->RegisterSubsystem(dispatcher);
  23. context_->AddGlobalEventListener(dispatcher);
  24. RefCounted::AddRefCountedDeletedFunction(OnRefCountedDeleted);
  25. }
  26. NETCore::~NETCore()
  27. {
  28. RefCounted::RemoveRefCountedDeletedFunction(OnRefCountedDeleted);
  29. assert (!csContext_);
  30. }
  31. void NETCore::OnRefCountedDeleted(RefCounted* ref)
  32. {
  33. if (csContext_.Null())
  34. return;
  35. if (refCountedDeleted_)
  36. refCountedDeleted_(ref);
  37. }
  38. void NETCore::RegisterNETEventType(unsigned eventType)
  39. {
  40. NETEventDispatcher* dispatcher = csContext_->GetSubsystem<NETEventDispatcher>();
  41. dispatcher->RegisterNETEvent(StringHash(eventType));
  42. }
  43. void NETCore::Shutdown()
  44. {
  45. assert (csContext_);
  46. csContext_->RemoveGlobalEventListener(csContext_->GetSubsystem<NETEventDispatcher>());
  47. csContext_->RemoveSubsystem(NETEventDispatcher::GetTypeStatic());
  48. eventDispatch_ = nullptr;
  49. csContext_ = nullptr;
  50. }
  51. }