ParticleSystem.cpp 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. /*
  2. * Copyright (C) 2022 The V-Gears Team
  3. *
  4. * This file is part of V-Gears
  5. *
  6. * V-Gears is free software: you can redistribute it and/or modify it under
  7. * terms of the GNU General Public License as published by the Free Software
  8. * Foundation, version 3.0 (GPLv3) of the License.
  9. *
  10. * V-Gears is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. */
  15. #include <OgreLogManager.h>
  16. #include <OgreSceneNode.h>
  17. #include "engine/particles/ParticleSystem.h"
  18. #include "engine/particles/ParticleSystemManager.h"
  19. ParticleSystem::ParticleSystem(const Ogre::String& name): MovableObject(name){}
  20. ParticleSystem::~ParticleSystem(){
  21. // Destroy nodes that are used for renderers.
  22. if (getParentSceneNode())
  23. getParentSceneNode()->removeAndDestroyAllChildren();
  24. DestroyAllTechniques();
  25. }
  26. void ParticleSystem::CopyAttributesTo(ParticleSystem* ps){
  27. // Destroy all existing techniques.
  28. ps->DestroyAllTechniques();
  29. // Copy techniques
  30. ParticleTechnique* cloned_technique = nullptr;
  31. for (unsigned int i = 0; i < techniques_.size(); ++ i){
  32. cloned_technique =
  33. ParticleSystemManager::getSingletonPtr()->CloneTechnique(
  34. techniques_[i]
  35. );
  36. ps->AddTechnique(cloned_technique);
  37. }
  38. }
  39. const Ogre::String& ParticleSystem::getMovableType() const{
  40. Ogre::String type = "ParticleSystem";
  41. return type;
  42. }
  43. const Ogre::AxisAlignedBox& ParticleSystem::getBoundingBox() const{
  44. return Ogre::AxisAlignedBox::BOX_INFINITE;
  45. }
  46. Ogre::Real ParticleSystem::getBoundingRadius() const{
  47. // TODO: Calculate.
  48. return 999;
  49. }
  50. void ParticleSystem::_updateRenderQueue(Ogre::RenderQueue* queue){
  51. Ogre::LogManager::getSingletonPtr()->logMessage(
  52. "ParticleSystem::UpdateRenderQueue"
  53. );
  54. for(unsigned int i = 0; i < techniques_.size(); ++ i){
  55. techniques_[i]->UpdateRenderQueue(queue);
  56. }
  57. }
  58. void ParticleSystem::Update(Ogre::Real time_elapsed){
  59. Ogre::LogManager::getSingletonPtr()->logMessage(
  60. "ParticleSystem::Update STARTED. Technique number: "
  61. + Ogre::StringConverter::toString(techniques_.size())
  62. );
  63. for (unsigned int i = 0; i < techniques_.size(); ++ i){
  64. techniques_[i]->Update(time_elapsed);
  65. }
  66. }
  67. ParticleTechnique*ParticleSystem::CreateTechnique(){
  68. ParticleTechnique* technique =
  69. ParticleSystemManager::getSingletonPtr()->CreateTechnique();
  70. AddTechnique(technique);
  71. return technique;
  72. }
  73. void ParticleSystem::AddTechnique(ParticleTechnique* technique){
  74. techniques_.push_back(technique);
  75. technique->SetParentSystem(this);
  76. }
  77. void ParticleSystem::DestroyAllTechniques(){
  78. for (unsigned int i = 0; i < techniques_.size(); ++ i){
  79. ParticleSystemManager::getSingletonPtr()->DestroyTechnique(
  80. techniques_[i]
  81. );
  82. }
  83. techniques_.clear();
  84. }