1
0

objcontroller.cpp 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. #include <bfc/wasabi_std.h>
  2. #include <api/script/objcontroller.h>
  3. #include <api/script/objects/c_script/scripthook.h>
  4. #include "api.h"
  5. #define CBCLASS ScriptObjectControllerI
  6. START_DISPATCH;
  7. CB(GETCLASSGUID, getClassGuid);
  8. CB(GETCLASSNAME, getClassName);
  9. CB(GETANCESTORCLASSNAME, getAncestorClassName);
  10. CB(GETNUMFUNCTIONS, getNumFunctions);
  11. CB(GETEXPORTEDFUNCTIONS, getExportedFunctions);
  12. CB(INSTANTIATE, instantiate);
  13. VCB(DESTROY, destroy);
  14. CB(ENCAPSULATE, encapsulate);
  15. VCB(DEENCAPSULATE, deencapsulate);
  16. VCB(SETCLASSID, setClassId);
  17. CB(GETCLASSID, getClassId);
  18. VCB(SETANCESTORCLASSID, setAncestorClassId);
  19. CB(GETANCESTORCLASSID, getAncestorClassId);
  20. CB(GETINSTANTIABLE, getInstantiable);
  21. CB(GETREFERENCEABLE, getReferenceable);
  22. CB(GETANCESTORCONTROLLER, getAncestorController);
  23. VCB(ADDCLASSHOOK, addClassHook);
  24. VCB(ADDOBJHOOK, addObjectHook);
  25. VCB(REMHOOKS, removeHooks);
  26. VCB(ONREGISTERCLASS, onRegisterClass);
  27. CB(CAST, cast);
  28. END_DISPATCH;
  29. ScriptObjectControllerI::ScriptObjectControllerI() {
  30. my_class_id = -1;
  31. my_ancestor_class_id = -1;
  32. rootController = NULL;
  33. incast = 0;
  34. }
  35. ScriptObjectControllerI::~ScriptObjectControllerI() {
  36. }
  37. int ScriptObjectControllerI::processHooks(ScriptObject *o, int dlfid, scriptVar **table, int nparams) {
  38. //CUT: int n=-1;
  39. for (int j=0;j<classhooks.getNumItems();j++) {
  40. classhooks.enumItem(j)->eventCallback(o, dlfid, table, nparams);
  41. }
  42. for (int i=0;i<objhooks.getNumItems();i++) {
  43. object_hook_struct *s = objhooks.enumItem(i);
  44. if (s->object == o) {
  45. s->hook->eventCallback(o, dlfid, table, nparams);
  46. }
  47. }
  48. return 0;
  49. }
  50. ScriptObject *ScriptObjectControllerI::cast(ScriptObject *o, GUID g) {
  51. if (incast) return NULL;
  52. incast = 1;
  53. ASSERT(o != NULL);
  54. ScriptObject *obj = NULL;
  55. void *i = o->vcpu_getInterfaceObject(g, &obj);
  56. incast = 0;
  57. if (i != NULL) {
  58. if (obj != NULL) return obj;
  59. return o;
  60. }
  61. return NULL;
  62. }
  63. void ScriptObjectControllerI::addClassHook(ScriptHook *h) {
  64. classhooks.addItem(h);
  65. }
  66. void ScriptObjectControllerI::addObjectHook(ScriptHook *h, ScriptObject *o) {
  67. object_hook_struct *s = new object_hook_struct;
  68. s->hook = h;
  69. s->object = o;
  70. objhooks.addItem(s);
  71. /* if (getAncestorController())
  72. getAncestorController()->addObjectHook(h, o);
  73. else
  74. if (rootController && this != rootController) rootController->addObjectHook(h, o);*/
  75. }
  76. void ScriptObjectControllerI::removeHooks(ScriptHook *h) {
  77. classhooks.removeItem(h);
  78. for (int i=0;i<objhooks.getNumItems();i++) {
  79. object_hook_struct *o = objhooks.enumItem(i);
  80. if (o->hook == h) {
  81. delete o;
  82. objhooks.removeByPos(i);
  83. i--;
  84. }
  85. }
  86. /* if (getAncestorController())
  87. getAncestorController()->removeHooks(h);
  88. else
  89. if (rootController && this != rootController) rootController->removeHooks(h);*/
  90. }
  91. void ScriptObjectControllerI::onRegisterClass(ScriptObjectController *root) {
  92. rootController = root;
  93. }
  94. scriptVar MAKE_SCRIPT_INT(int i) {
  95. scriptVar r;
  96. r.type = SCRIPT_INT;
  97. r.data.idata = i;
  98. return r;
  99. }
  100. scriptVar MAKE_SCRIPT_VOID() {
  101. scriptVar r; r.type = SCRIPT_VOID;
  102. r.data.idata = 0;
  103. return r;
  104. }
  105. scriptVar MAKE_SCRIPT_FLOAT(float f) {
  106. scriptVar r; r.type = SCRIPT_FLOAT;
  107. r.data.fdata = f;
  108. return r;
  109. }
  110. scriptVar MAKE_SCRIPT_DOUBLE(double d) {
  111. scriptVar r; r.type = SCRIPT_DOUBLE;
  112. r.data.ddata = d;
  113. return r;
  114. }
  115. scriptVar MAKE_SCRIPT_BOOLEAN(int b) {
  116. scriptVar r; r.type = SCRIPT_BOOLEAN;
  117. r.data.idata = b;
  118. return r;
  119. }
  120. scriptVar MAKE_SCRIPT_OBJECT(ScriptObject *o) {
  121. scriptVar r;
  122. r.type = SCRIPT_OBJECT;
  123. r.data.odata = o;
  124. return r;
  125. }
  126. scriptVar MAKE_SCRIPT_STRING(const wchar_t *s)
  127. {
  128. scriptVar r;
  129. r.type = SCRIPT_STRING;
  130. r.data.sdata = s;
  131. return r;
  132. }
  133. void *GET_SCRIPT_OBJECT_AS(scriptVar v, GUID g) {
  134. ScriptObject *o = GET_SCRIPT_OBJECT(v);
  135. if (!o) return NULL;
  136. return o->vcpu_getInterface(g);
  137. }