AtomicSharpAPI.cpp 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. //
  2. // The above copyright notice and this permission notice shall be included in
  3. // all copies or substantial portions of the Software.
  4. //
  5. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  6. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  7. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  8. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  9. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  10. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  11. // THE SOFTWARE.
  12. //
  13. #include <AtomicNET/NETCore/NETCore.h>
  14. #include <AtomicNET/NETCore/NETManaged.h>
  15. #include <AtomicNET/NETCore/NETCoreThunk.h>
  16. #include <AtomicNET/NETCore/CSScriptObject.h>
  17. #include "AtomicSharpAPI.h"
  18. #ifdef ATOMIC_PLATFORM_WINDOWS
  19. #pragma warning(disable: 4244) // possible loss of data
  20. #define ATOMIC_EXPORT_API __declspec(dllexport)
  21. #else
  22. #define ATOMIC_EXPORT_API
  23. #endif
  24. using namespace Atomic;
  25. static AtomicNETCoreThunk_t AtomicNETCoreThunk;
  26. static bool AtomicNETCoreThunkEnabled = false;
  27. extern "C"
  28. {
  29. ATOMIC_EXPORT_API void csb_package_set_Atomic_NETCore_thunk(AtomicNETCoreThunk_t* thunkIn)
  30. {
  31. AtomicNETCoreThunk = *thunkIn;
  32. AtomicNETCoreThunkEnabled = true;
  33. }
  34. ATOMIC_EXPORT_API void csb_AtomicEngine_AtomicInterop_Set_CSComponentCreate(CSComponentCreateFunctionPtr method)
  35. {
  36. if (AtomicNETCoreThunkEnabled)
  37. {
  38. AtomicNETCoreThunk.__Atomic_NETManaged_SetCSComponentCreate(method);
  39. }
  40. else
  41. {
  42. Atomic_NETManaged_SetCSComponentCreate(method);
  43. }
  44. }
  45. ATOMIC_EXPORT_API void csb_AtomicEngine_AtomicInterop_Set_CSComponentCallMethod(CSComponentCallMethodFunctionPtr method)
  46. {
  47. if (AtomicNETCoreThunkEnabled)
  48. {
  49. AtomicNETCoreThunk.__Atomic_NETManaged_SetCSComponentCallMethod(method);
  50. }
  51. else
  52. {
  53. Atomic_NETManaged_SetCSComponentCallMethod(method);
  54. }
  55. }
  56. // Event Handling
  57. ATOMIC_EXPORT_API void csb_AtomicEngine_AtomicInterop_Set_CSBeginSendEvent(CSBeginSendEventFunctionPtr method)
  58. {
  59. if (AtomicNETCoreThunkEnabled)
  60. {
  61. AtomicNETCoreThunk.__Atomic_NETManaged_SetCSBeginSendEvent(method);
  62. }
  63. else
  64. {
  65. Atomic_NETManaged_SetCSBeginSendEvent(method);
  66. }
  67. }
  68. // Instance methods
  69. ATOMIC_EXPORT_API void csb_Atomic_AObject_SendEvent(Object* object, const char* eventType)
  70. {
  71. if (AtomicNETCoreThunkEnabled)
  72. {
  73. AtomicNETCoreThunk.__Atomic_AObject_SendEvent(object, eventType);
  74. }
  75. else
  76. {
  77. Atomic_AObject_SendEvent(object, eventType);
  78. }
  79. }
  80. ATOMIC_EXPORT_API ClassID csb_Atomic_RefCounted_GetClassID(RefCounted* refCounted)
  81. {
  82. if (AtomicNETCoreThunkEnabled)
  83. {
  84. return AtomicNETCoreThunk.__Atomic_RefCounted_GetClassID(refCounted);
  85. }
  86. else
  87. {
  88. return Atomic_RefCounted_GetClassID(refCounted);
  89. }
  90. }
  91. ATOMIC_EXPORT_API RefCounted* csb_AtomicEngine_GetSubsystem(const char* name)
  92. {
  93. if (AtomicNETCoreThunkEnabled)
  94. {
  95. return AtomicNETCoreThunk.__AtomicEngine_GetSubsystem(name);
  96. }
  97. else
  98. {
  99. return AtomicEngine_GetSubsystem(name);
  100. }
  101. }
  102. ATOMIC_EXPORT_API void csb_Atomic_RefCounted_SafeAddRef(unsigned id)
  103. {
  104. if (AtomicNETCoreThunkEnabled)
  105. {
  106. AtomicNETCoreThunk.__Atomic_RefCounted_SafeAddRef(id);
  107. }
  108. else
  109. {
  110. Atomic_RefCounted_SafeAddRef(id);
  111. }
  112. }
  113. ATOMIC_EXPORT_API void csb_Atomic_RefCounted_SafeReleaseRef(unsigned id)
  114. {
  115. if (AtomicNETCoreThunkEnabled)
  116. {
  117. AtomicNETCoreThunk.__Atomic_RefCounted_SafeReleaseRef(id);
  118. }
  119. else
  120. {
  121. Atomic_RefCounted_SafeReleaseRef(id);
  122. }
  123. }
  124. ATOMIC_EXPORT_API unsigned csb_Atomic_StringToStringHash(const char* stringValue)
  125. {
  126. if (AtomicNETCoreThunkEnabled)
  127. {
  128. return AtomicNETCoreThunk.__Atomic_StringToStringHash(stringValue);
  129. }
  130. else
  131. {
  132. return Atomic_StringToStringHash(stringValue);
  133. }
  134. }
  135. // Variant Map
  136. ATOMIC_EXPORT_API RefCounted* csb_Atomic_VariantMap_GetInstance(VariantMap& vmap, const char* key)
  137. {
  138. if (AtomicNETCoreThunkEnabled)
  139. {
  140. return AtomicNETCoreThunk.__Atomic_VariantMap_GetInstance(vmap, key);
  141. }
  142. else
  143. {
  144. return Atomic_VariantMap_GetInstance(vmap, key);
  145. }
  146. }
  147. }