c_consoleInterface.cpp 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. //-----------------------------------------------------------------------------
  2. // Copyright (c) 2012 GarageGames, LLC
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to
  6. // deal in the Software without restriction, including without limitation the
  7. // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  8. // sell copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  19. // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  20. // IN THE SOFTWARE.
  21. //-----------------------------------------------------------------------------
  22. #include "platform/platform.h"
  23. #include "console/compiler.h"
  24. #include "console/consoleInternal.h"
  25. #include "console/simSet.h"
  26. extern "C" {
  27. // SimObject C interface
  28. const char *SimObject_GetName(SimObject *so)
  29. {
  30. return so->getName();
  31. }
  32. U32 SimObject_GetId(SimObject *so)
  33. {
  34. return so->getId();
  35. }
  36. const char *SimObject_GetClassName(SimObject *so)
  37. {
  38. return so->getClassName();
  39. }
  40. void *SimObject_GetFieldList(SimObject *so, S32 &outNumFields)
  41. {
  42. const AbstractClassRep::FieldList &fl = so->getFieldList();
  43. outNumFields = fl.size();
  44. return fl.address();
  45. }
  46. bool SimObject_IsLocked(SimObject *so)
  47. {
  48. return so->isLocked();
  49. }
  50. void SimObject_SetDataField(SimObject *so, const char *fieldName, const char *arr, const char *val)
  51. {
  52. so->setDataField(StringTable->insert(fieldName), arr, val);
  53. }
  54. const char *SimObject_GetDataField(SimObject *so, const char *fieldName, const char *arr)
  55. {
  56. return so->getDataField(StringTable->insert(fieldName), arr);
  57. }
  58. void SimObject_InspectPreApply(SimObject *so)
  59. {
  60. so->inspectPreApply();
  61. }
  62. void SimObject_InspectPostApply(SimObject *so)
  63. {
  64. so->inspectPostApply();
  65. }
  66. // Con C interface
  67. void Con_AddConsumer(ConsumerCallback cb)
  68. {
  69. Con::addConsumer(cb);
  70. }
  71. void Con_RemoveConsumer(ConsumerCallback cb)
  72. {
  73. Con::removeConsumer(cb);
  74. }
  75. void Con_AddCommand_String(StringCallback cb, const char *nameSpace, const char *funcName, const char* usage, S32 minArgs, S32 maxArgs)
  76. {
  77. if (!nameSpace || !dStrlen(nameSpace))
  78. Con::addCommand(funcName, cb, usage, minArgs + 1, maxArgs + 1);
  79. else
  80. Con::addCommand(nameSpace, funcName, cb, usage, minArgs + 1, maxArgs + 1);
  81. }
  82. // ConsoleBaseType C interface
  83. ConsoleBaseType *ConsoleBaseType_GetTypeById(const S32 typeId)
  84. {
  85. return ConsoleBaseType::getType(typeId);
  86. }
  87. S32 ConsoleBaseType_GetTypeId(ConsoleBaseType *cbt)
  88. {
  89. return cbt->getTypeID();
  90. }
  91. S32 ConsoleBaseType_GetTypeSize(ConsoleBaseType *cbt)
  92. {
  93. return cbt->getTypeSize();
  94. }
  95. const char *ConsoleBaseType_GetTypeName(ConsoleBaseType *cbt)
  96. {
  97. return cbt->getTypeName();
  98. }
  99. const char *ConsoleBaseType_GetInspectorFieldType(ConsoleBaseType *cbt)
  100. {
  101. return cbt->getInspectorFieldType();
  102. }
  103. void ConsoleBaseType_SetData(ConsoleBaseType *cbt, void *dptr, S32 argc, const char **argv, const EnumTable *tbl, BitSet32 flag)
  104. {
  105. return cbt->setData(dptr, argc, argv, tbl, flag);
  106. }
  107. const char *ConsoleBaseType_GetData(ConsoleBaseType *cbt, void *dptr, const EnumTable *tbl, BitSet32 flag)
  108. {
  109. return cbt->getData(dptr, tbl, flag);
  110. }
  111. // Abstract Class Rep
  112. AbstractClassRep *AbstractClassRep_GetCommonParent(AbstractClassRep *acr, AbstractClassRep *otheracr)
  113. {
  114. return acr->getCommonParent(otheracr);
  115. }
  116. AbstractClassRep *AbstractClassRep_FindClassRep(const char* in_pClassName)
  117. {
  118. return AbstractClassRep::findClassRep(in_pClassName);
  119. }
  120. U32 AbstractClassRep_GetFieldStructSize()
  121. {
  122. return sizeof(AbstractClassRep::Field);
  123. }
  124. // Sim C interface
  125. SimObject *Sim_FindObjectByString(const char *param)
  126. {
  127. return Sim::findObject(param);
  128. }
  129. SimObject *Sim_FindObjectById(S32 param)
  130. {
  131. return Sim::findObject(param);
  132. }
  133. // Sim Set
  134. SimObject **SimSet_Begin(SimObject *simObject)
  135. {
  136. return dynamic_cast<SimSet *>(simObject)->begin();
  137. }
  138. SimObject **SimSet_End(SimObject *simObject)
  139. {
  140. return dynamic_cast<SimSet *>(simObject)->end();
  141. }
  142. };