NETCore.cpp 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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. NETCoreUpdateDispatchFunction NETCore::updateDispatch_ = nullptr;
  11. NETCore::NETCore(Context* context, NETCoreDelegates* delegates) :
  12. Object(context)
  13. {
  14. assert (!csContext_);
  15. csContext_ = context;
  16. eventDispatch_ = delegates->eventDispatch;
  17. updateDispatch_ = delegates->updateDispatch;
  18. NETEventDispatcher* dispatcher = new NETEventDispatcher(context_);
  19. context_->RegisterSubsystem(dispatcher);
  20. context_->AddGlobalEventListener(dispatcher);
  21. }
  22. NETCore::~NETCore()
  23. {
  24. assert (!csContext_);
  25. }
  26. void NETCore::RegisterNETEventType(unsigned eventType)
  27. {
  28. NETEventDispatcher* dispatcher = csContext_->GetSubsystem<NETEventDispatcher>();
  29. dispatcher->RegisterNETEvent(StringHash(eventType));
  30. }
  31. void NETCore::Shutdown()
  32. {
  33. assert (csContext_);
  34. csContext_->RemoveGlobalEventListener(csContext_->GetSubsystem<NETEventDispatcher>());
  35. csContext_->RemoveSubsystem(NETEventDispatcher::GetTypeStatic());
  36. eventDispatch_ = nullptr;
  37. csContext_ = nullptr;
  38. }
  39. }