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.
 
 
 

76 lines
1.5 KiB

  1. #include "ScriptSystem_Model.h"
  2. namespace BlueCore
  3. {
  4. //------------------------------------------------------------------------------
  5. static weak_ptr<ModelManager> gModelManager;
  6. //------------------------------------------------------------------------------
  7. static SQInteger _model_releasehook(SQUserPointer p, SQInteger size)
  8. {
  9. Model *model = (Model *)p;
  10. if (model)
  11. model->removeReference();
  12. return 1;
  13. }
  14. //------------------------------------------------------------------------------
  15. static SQInteger _model_constructor(HSQUIRRELVM vm)
  16. {
  17. SQInteger argc = sq_gettop(vm);
  18. Model *model = 0;
  19. if (argc > 1)
  20. {
  21. const SQChar *name = 0;
  22. sq_getstring(vm, 2, &name);
  23. if (gModelManager.valid())
  24. {
  25. model = gModelManager->loadModel(name);
  26. if (model)
  27. model->addReference();
  28. }
  29. }
  30. sq_setinstanceup(vm, 1, (void *)model );
  31. sq_setreleasehook(vm, 1, _model_releasehook);
  32. return 0;
  33. }
  34. //------------------------------------------------------------------------------
  35. void setupScriptSystem_Model(ScriptSystem* scriptsystem, ModelManager* modelmanager)
  36. {
  37. if (scriptsystem && modelmanager)
  38. {
  39. HSQUIRRELVM vm = scriptsystem->getVM();
  40. gModelManager = modelmanager;
  41. sq_pushroottable(vm);
  42. // push class
  43. sq_pushstring(vm, "Model", -1);
  44. if (SQ_SUCCEEDED(sq_newclass(vm, SQFalse) ) )
  45. {
  46. // register constructor
  47. sq_pushstring(vm, "constructor", -1);
  48. sq_newclosure(vm, _model_constructor, 0);
  49. sq_newslot(vm, -3, false);
  50. // create class
  51. sq_newslot(vm, -3, false);
  52. }
  53. sq_poptop(vm);
  54. }
  55. }
  56. }