Simple game engine with complete export to scripting language
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ScriptSystem_SceneNode.cpp 2.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. #include "ScriptSystem_SceneNode.h"
  2. #include "ScriptSystem_Math.h"
  3. #include "SceneNode.h"
  4. namespace BlueCore
  5. {
  6. static SQInteger _scenenode_releasehook(SQUserPointer p, SQInteger size)
  7. {
  8. SceneNode *node = (SceneNode *)p;
  9. if (node)
  10. node->removeReference();
  11. return 1;
  12. }
  13. static SQInteger _scenenode_constructor(HSQUIRRELVM vm)
  14. {
  15. SQInteger argc = sq_gettop(vm);
  16. SceneNode *node = 0;
  17. if (argc > 1)
  18. {
  19. const SQChar *name = 0;
  20. sq_getstring(vm, 2, &name);
  21. node = new SceneNode (name);
  22. if (node)
  23. node->addReference();
  24. }
  25. sq_setinstanceup(vm, 1, (void *)node );
  26. sq_setreleasehook(vm, 1, _scenenode_releasehook);
  27. return 0;
  28. }
  29. static SQInteger _set_model(HSQUIRRELVM v)
  30. {
  31. SceneNode *node = 0;
  32. sq_getinstanceup(v, 1, ( void ** ) &node, 0);
  33. if (node)
  34. {
  35. Model *model;
  36. sq_getinstanceup(v, 2, ( void ** ) &model, 0);
  37. node->setModel(model);
  38. }
  39. return 0;
  40. }
  41. static SQInteger _set_position(HSQUIRRELVM v)
  42. {
  43. SceneNode *node = 0;
  44. sq_getinstanceup(v, 1, ( void ** ) &node, 0);
  45. if (node)
  46. {
  47. Vector3 position;
  48. int argc = sq_gettop(v);
  49. if (argc == 2)
  50. {
  51. _getvectorvalues(v, 2, position.x, position.y, position.z);
  52. }
  53. else if (argc == 4)
  54. {
  55. sq_getfloat(v, 2, &position.x);
  56. sq_getfloat(v, 3, &position.y);
  57. sq_getfloat(v, 4, &position.z);
  58. }
  59. node->setRelativeTranslation(position);
  60. }
  61. return 0;
  62. }
  63. void setupScriptSystem_SceneNode(ScriptSystem* scriptsystem)
  64. {
  65. if (scriptsystem)
  66. {
  67. HSQUIRRELVM vm = scriptsystem->getVM();
  68. sq_pushroottable(vm);
  69. // push class
  70. sq_pushstring(vm, "SceneNode", -1);
  71. if (SQ_SUCCEEDED(sq_newclass(vm, SQFalse) ) )
  72. {
  73. // register constructor
  74. sq_pushstring(vm, "constructor", -1);
  75. sq_newclosure(vm, _scenenode_constructor, 0);
  76. sq_newslot(vm, -3, false);
  77. sq_pushstring(vm, "setModel", -1);
  78. sq_newclosure(vm, _set_model, 0);
  79. sq_newslot(vm, -3, false);
  80. sq_pushstring(vm, "setPosition", -1);
  81. sq_newclosure(vm, _set_position, 0);
  82. sq_newslot(vm, -3, false);
  83. // create class
  84. sq_newslot(vm, -3, false);
  85. }
  86. sq_poptop(vm);
  87. }
  88. }
  89. }