NETScript.cpp 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. #include "../NETCore/NETCore.h"
  2. #include "CSComponent.h"
  3. #include "CSComponentAssembly.h"
  4. #include "CSManaged.h"
  5. #include "NETScript.h"
  6. namespace Atomic
  7. {
  8. void RegisterNETScriptLibrary(Context* context);
  9. NETScript::NETScript(Context* context) :
  10. Object(context)
  11. {
  12. // NETScript subsystem should not be instantiated in editor context
  13. assert(!context->GetEditorContext());
  14. netCore_ = GetSubsystem<NETCore>();
  15. assert(netCore_.NotNull());
  16. }
  17. NETScript::~NETScript()
  18. {
  19. //context_->RemoveGlobalEventListener(context_->GetSubsystem<CSEventDispatcher>());
  20. //context_->RemoveSubsystem(CSEventDispatcher::GetTypeStatic());
  21. context_->RemoveSubsystem(CSManaged::GetTypeStatic());
  22. }
  23. bool NETScript::ExecMainAssembly()
  24. {
  25. typedef void (*StartFunction)();
  26. StartFunction start;
  27. bool result = netCore_->CreateDelegate(
  28. "AtomicNETEngine",
  29. "AtomicEngine.Atomic",
  30. "Start",
  31. (void**) &start);
  32. if (!result)
  33. return false;
  34. if (result)
  35. {
  36. start();
  37. // Load Project Assemblies
  38. typedef void (*ExecMainAssemblyFunction)();
  39. ExecMainAssemblyFunction execMainAssembly;
  40. result = netCore_->CreateDelegate(
  41. "AtomicNETEngine",
  42. "AtomicEngine.Atomic",
  43. "ExecMainAssembly",
  44. (void**) &execMainAssembly);
  45. if (!result)
  46. return false;
  47. execMainAssembly();
  48. }
  49. return true;
  50. }
  51. bool NETScript::Initialize()
  52. {
  53. // MOVE THIS!
  54. typedef void (*InitializeFunction)();
  55. InitializeFunction init;
  56. bool result = netCore_->CreateDelegate(
  57. "AtomicNETEngine",
  58. "AtomicEngine.Atomic",
  59. "Initialize",
  60. (void**) &init);
  61. if (!result)
  62. return false;
  63. init();
  64. csManaged_ = new CSManaged(context_);
  65. context_->RegisterSubsystem(csManaged_);
  66. //SharedPtr<CSEventDispatcher> dispatcher(new CSEventDispatcher(context_));
  67. //context_->RegisterSubsystem(dispatcher);
  68. //context_->AddGlobalEventListener(dispatcher);
  69. //if (!context_->GetEditorContext())
  70. //{
  71. //SubscribeToEvent(E_UPDATE, HANDLER(NETCore, HandleUpdate));
  72. //}
  73. return csManaged_->Initialize();
  74. }
  75. void RegisterNETScriptLibrary(Context* context)
  76. {
  77. CSComponentAssembly::RegisterObject(context);
  78. CSComponent::RegisterObject(context);
  79. }
  80. }