CCPUTranslateManager.cpp 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. /****************************************************************************
  2. Copyright (C) 2013 Henry van Merode. All rights reserved.
  3. Copyright (c) 2015-2016 Chukong Technologies Inc.
  4. Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
  5. http://www.cocos2d-x.org
  6. Permission is hereby granted, free of charge, to any person obtaining a copy
  7. of this software and associated documentation files (the "Software"), to deal
  8. in the Software without restriction, including without limitation the rights
  9. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  10. copies of the Software, and to permit persons to whom the Software is
  11. furnished to do so, subject to the following conditions:
  12. The above copyright notice and this permission notice shall be included in
  13. all copies or substantial portions of the Software.
  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 FROM,
  19. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  20. THE SOFTWARE.
  21. ****************************************************************************/
  22. #include "CCPUTranslateManager.h"
  23. #include "extensions/Particle3D/PU/CCPUScriptCompiler.h"
  24. NS_CC_BEGIN
  25. PUTranslateManager::PUTranslateManager()
  26. {
  27. }
  28. PUTranslateManager::~PUTranslateManager()
  29. {
  30. }
  31. PUScriptTranslator* PUTranslateManager::getTranslator(PUAbstractNode *node)
  32. {
  33. PUScriptTranslator* translator = 0;
  34. //add//
  35. if(node->type == ANT_OBJECT)
  36. {
  37. PUObjectAbstractNode* obj = reinterpret_cast<PUObjectAbstractNode*>(node);
  38. PUObjectAbstractNode* parent = obj->parent ? reinterpret_cast<PUObjectAbstractNode*>(obj->parent) : 0;
  39. if(obj->cls == token[TOKEN_SYSTEM])
  40. {
  41. // Parse Particle System
  42. translator = &_systemTranslator;
  43. }
  44. else if(obj->cls == token[TOKEN_MATERIAL])
  45. {
  46. // Parse Particle System
  47. translator = &_materialTranslator;
  48. }
  49. //else if(obj->cls == token[TOKEN_ALIAS])
  50. //{
  51. // // Parse the Alias
  52. // translator = &mAliasTranslator;
  53. //}
  54. else if(obj->cls == token[TOKEN_TECHNIQUE] && parent && (parent->cls == token[TOKEN_SYSTEM] || parent->cls == token[TOKEN_ALIAS]))
  55. {
  56. // Parse Particle Technique
  57. translator = &_techniqueTranslator;
  58. }
  59. else if(obj->cls == token[TOKEN_RENDERER] && parent && (parent->cls == token[TOKEN_TECHNIQUE] || parent->cls == token[TOKEN_ALIAS]))
  60. {
  61. // Parse Particle Renderer
  62. translator = &_rendererTranslator;
  63. }
  64. else if(obj->cls == token[TOKEN_EMITTER] && parent && (parent->cls == token[TOKEN_TECHNIQUE] || parent->cls == token[TOKEN_ALIAS]))
  65. {
  66. // Parse Particle Emitter
  67. translator = &_emitterTranslator;
  68. }
  69. else if(obj->cls == token[TOKEN_AFFECTOR] && parent && (parent->cls == token[TOKEN_TECHNIQUE] || parent->cls == token[TOKEN_ALIAS]))
  70. {
  71. // Parse Particle Affector
  72. translator = &_affectorTranslator;
  73. }
  74. else if(obj->cls == token[TOKEN_BEHAVIOUR] && parent && (parent->cls == token[TOKEN_TECHNIQUE] || parent->cls == token[TOKEN_ALIAS]))
  75. {
  76. // Parse Particle Behaviour
  77. translator = &_behaviourTranslator;
  78. }
  79. else if(obj->cls == token[TOKEN_OBSERVER] && parent && (parent->cls == token[TOKEN_TECHNIQUE] || parent->cls == token[TOKEN_ALIAS]))
  80. {
  81. // Parse Particle Observer
  82. translator = &_observerTranslator;
  83. }
  84. else if(obj->cls == token[TOKEN_HANDLER] && parent && (parent->cls == token[TOKEN_OBSERVER] || parent->cls == token[TOKEN_ALIAS]))
  85. {
  86. // Parse Particle Event Handler
  87. translator = &_eventHandlerTranslator;
  88. }
  89. //else if(obj->cls == token[TOKEN_EXTERN] && parent && (parent->cls == token[TOKEN_TECHNIQUE] || parent->cls == token[TOKEN_ALIAS]))
  90. //{
  91. // // Parse Extern
  92. // translator = &mExternTranslator;
  93. //}
  94. }
  95. return translator;
  96. }
  97. PUTranslateManager* PUTranslateManager::Instance()
  98. {
  99. static PUTranslateManager ptm;
  100. return &ptm;
  101. }
  102. void PUTranslateManager::translateParticleSystem( PUParticleSystem3D *pu, const PUAbstractNodeList *alist )
  103. {
  104. for(PUAbstractNodeList::const_iterator i = alist->begin(); i != alist->end(); ++i)
  105. {
  106. _systemTranslator.setParticleSystem3D(pu);
  107. _systemTranslator.translate(PUScriptCompiler::Instance(), *i);
  108. }
  109. }
  110. void PUTranslateManager::translateMaterialSystem( PUMaterialCache *ms, const PUAbstractNodeList *alist )
  111. {
  112. for(PUAbstractNodeList::const_iterator i = alist->begin(); i != alist->end(); ++i)
  113. {
  114. _materialTranslator.setMaterialSystem(ms);
  115. _materialTranslator.translate(PUScriptCompiler::Instance(), *i);
  116. }
  117. }
  118. NS_CC_END