NETCore.cpp 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. #include <Atomic/Math/MathDefs.h>
  2. #include <Atomic/Core/ProcessUtils.h>
  3. #include <Atomic/Script/ScriptVariantMap.h>
  4. #include "NETCore.h"
  5. #include "NETEventDispatcher.h"
  6. namespace Atomic
  7. {
  8. SharedPtr<Context> NETCore::csContext_;
  9. NETCoreEventDispatchFunction NETCore::eventDispatch_ = nullptr;
  10. NETCore::NETCore(Context* context, NETCoreDelegates* delegates) :
  11. Object(context)
  12. {
  13. assert (!csContext_);
  14. csContext_ = context;
  15. eventDispatch_ = delegates->eventDispatch;
  16. NETEventDispatcher* dispatcher = new NETEventDispatcher(context_);
  17. context_->RegisterSubsystem(dispatcher);
  18. context_->AddGlobalEventListener(dispatcher);
  19. }
  20. NETCore::~NETCore()
  21. {
  22. assert (!csContext_);
  23. }
  24. void NETCore::RegisterNETEventType(unsigned eventType)
  25. {
  26. NETEventDispatcher* dispatcher = csContext_->GetSubsystem<NETEventDispatcher>();
  27. dispatcher->RegisterNETEvent(StringHash(eventType));
  28. }
  29. void NETCore::Shutdown()
  30. {
  31. assert (csContext_);
  32. csContext_->RemoveGlobalEventListener(csContext_->GetSubsystem<NETEventDispatcher>());
  33. csContext_->RemoveSubsystem(NETEventDispatcher::GetTypeStatic());
  34. eventDispatch_ = nullptr;
  35. csContext_ = nullptr;
  36. }
  37. }