AtomicSharpAPI.cpp 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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 "AtomicSharp.h"
  14. #include "AtomicSharpAPI.h"
  15. #ifdef ATOMIC_PLATFORM_WINDOWS
  16. #pragma warning(disable: 4244) // possible loss of data
  17. #define ATOMIC_EXPORT_API __declspec(dllexport)
  18. #else
  19. #define ATOMIC_EXPORT_API
  20. #endif
  21. using namespace Atomic;
  22. extern "C"
  23. {
  24. typedef void (*CSComponentCreatePtr)(const char* csComponentTypeName, CSComponent* instance);
  25. CSComponentCreatePtr _CSComponentCreate = 0;
  26. ATOMIC_EXPORT_API void csb_AtomicEngine_AtomicInterop_Set_CSComponentCreate(CSComponentCreatePtr method)
  27. {
  28. _CSComponentCreate = method;
  29. }
  30. void CSComponentCreate(String name, CSComponent* instance)
  31. {
  32. assert(_CSComponentCreate);
  33. _CSComponentCreate(name.CString(), instance);
  34. }
  35. typedef void (*CSComponentCallMethodPtr)(unsigned id, CSComponentMethod method, float value);
  36. CSComponentCallMethodPtr _CSComponentCallMethod = 0;
  37. ATOMIC_EXPORT_API void csb_AtomicEngine_AtomicInterop_Set_CSComponentCallMethod(CSComponentCallMethodPtr method)
  38. {
  39. _CSComponentCallMethod = method;
  40. }
  41. void CSComponentCallMethod(unsigned id, CSComponentMethod methodID, float value)
  42. {
  43. assert(_CSComponentCreate);
  44. _CSComponentCallMethod(id, methodID, value);
  45. }
  46. // Instance methods
  47. ATOMIC_EXPORT_API RefCounted* csb_Atomic_CSComponent_Constructor()
  48. {
  49. return new CSComponent(AtomicSharp::GetContext());
  50. }
  51. ATOMIC_EXPORT_API void csb_Atomic_CSComponent_SetManagedID(CSComponent* self, unsigned id)
  52. {
  53. if (!self)
  54. return;
  55. self->SetManagedID(id);
  56. }
  57. ATOMIC_EXPORT_API ClassID csb_RefCounted_GetClassID(RefCounted* refCounted)
  58. {
  59. if (!refCounted)
  60. return 0;
  61. return refCounted->GetClassID();
  62. }
  63. ATOMIC_EXPORT_API RefCounted* csb_AtomicEngine_GetSubsystem(const char* name)
  64. {
  65. return AtomicSharp::GetContext()->GetSubsystem(name);
  66. }
  67. }