Changeset 7297892 in opengl-game
- Timestamp:
- Apr 19, 2020, 4:06:03 AM (5 years ago)
- Branches:
- feature/imgui-sdl, master, points-test
- Children:
- 73a10ca
- Parents:
- 3950236
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
vulkan-game.cpp
r3950236 r7297892 707 707 laserObjects[leftLaserIdx].modified = true; 708 708 leftLaserIdx = -1; 709 710 if (leftLaserEffect != nullptr) { 711 leftLaserEffect->deleted = true; 712 leftLaserEffect = nullptr; 713 } 709 714 } else if (e.key.keycode == SDL_SCANCODE_X && rightLaserIdx != -1) { 710 715 laserObjects[rightLaserIdx].ssbo.deleted = true; 711 716 laserObjects[rightLaserIdx].modified = true; 712 717 rightLaserIdx = -1; 718 719 if (rightLaserEffect != nullptr) { 720 rightLaserEffect->deleted = true; 721 rightLaserEffect = nullptr; 722 } 713 723 } 714 724 break; … … 786 796 } 787 797 798 for (vector<BaseEffectOverTime*>::iterator it = effects.begin(); it != effects.end(); ) { 799 if ((*it)->deleted) { 800 delete *it; 801 it = effects.erase(it); 802 } else { 803 BaseEffectOverTime* eot = *it; 804 805 eot->applyEffect(); 806 807 it++; 808 } 809 } 810 788 811 for (SceneObject<AsteroidVertex, SSBO_Asteroid>& asteroid : this->asteroidObjects) { 789 812 if (!asteroid.ssbo.deleted) { 790 813 vec3 objCenter = vec3(viewMat * vec4(asteroid.center, 1.0f)); 791 814 792 if ((objCenter.z - asteroid.radius) > -NEAR_CLIP ) {815 if ((objCenter.z - asteroid.radius) > -NEAR_CLIP || asteroid.ssbo.hp <= 0.0f) { 793 816 asteroid.ssbo.deleted = true; 794 817 … … 1663 1686 1664 1687 if (laser.targetAsteroid != closestAsteroid) { 1688 if (laser.targetAsteroid != nullptr) { 1689 if (index == leftLaserIdx && leftLaserEffect != nullptr) { 1690 leftLaserEffect->deleted = true; 1691 } else if (index == rightLaserIdx && rightLaserEffect != nullptr) { 1692 rightLaserEffect->deleted = true; 1693 } 1694 } 1695 1696 EffectOverTime<AsteroidVertex, SSBO_Asteroid>* eot = nullptr; 1697 1698 if (closestAsteroid != nullptr) { 1699 // TODO: Use some sort of smart pointer instead 1700 eot = new EffectOverTime(asteroidPipeline, asteroidObjects, closestAsteroidIndex, 1701 offset_of(&SSBO_Asteroid::hp), -20.0f); 1702 effects.push_back(eot); 1703 } 1704 1705 if (index == leftLaserIdx) { 1706 leftLaserEffect = eot; 1707 } else if (index == rightLaserIdx) { 1708 rightLaserEffect = eot; 1709 } 1710 1665 1711 laser.targetAsteroid = closestAsteroid; 1666 1712 } -
vulkan-game.hpp
r3950236 r7297892 107 107 static float curTime; 108 108 109 110 // TODO: Look into using dynamic_cast to check types of SceneObject and EffectOverTime 111 112 struct BaseEffectOverTime { 113 bool deleted; 114 115 virtual void applyEffect() = 0; 116 117 BaseEffectOverTime() : 118 deleted(false) { 119 } 120 121 virtual ~BaseEffectOverTime() { 122 } 123 }; 124 125 template<class VertexType, class SSBOType> 126 struct EffectOverTime : public BaseEffectOverTime { 127 GraphicsPipeline_Vulkan<VertexType, SSBOType>& pipeline; 128 vector<SceneObject<VertexType, SSBOType>>& objects; 129 unsigned int objectIndex; 130 size_t effectedFieldOffset; 131 float startValue; 132 float startTime; 133 float changePerSecond; 134 135 EffectOverTime(GraphicsPipeline_Vulkan<VertexType, SSBOType>& pipeline, 136 vector<SceneObject<VertexType, SSBOType>>& objects, unsigned int objectIndex, 137 size_t effectedFieldOffset, float changePerSecond) : 138 pipeline(pipeline), 139 objects(objects), 140 objectIndex(objectIndex), 141 effectedFieldOffset(effectedFieldOffset), 142 startTime(curTime), 143 changePerSecond(changePerSecond) { 144 size_t ssboOffset = offset_of(&SceneObject<VertexType, SSBOType>::ssbo); 145 146 unsigned char* effectedFieldPtr = reinterpret_cast<unsigned char*>(&objects[objectIndex]) + 147 ssboOffset + effectedFieldOffset; 148 149 startValue = *reinterpret_cast<float*>(effectedFieldPtr); 150 } 151 152 void applyEffect() { 153 if (objects[objectIndex].ssbo.deleted) { 154 this->deleted = true; 155 return; 156 } 157 158 size_t ssboOffset = offset_of(&SceneObject<VertexType, SSBOType>::ssbo); 159 160 unsigned char* effectedFieldPtr = reinterpret_cast<unsigned char*>(&objects[objectIndex]) + 161 ssboOffset + effectedFieldOffset; 162 163 *reinterpret_cast<float*>(effectedFieldPtr) = startValue + (curTime - startTime) * changePerSecond; 164 165 objects[objectIndex].modified = true; 166 } 167 }; 168 109 169 class VulkanGame { 110 170 public: … … 226 286 UBO_VP_mats laser_VP_mats; 227 287 288 vector<BaseEffectOverTime*> effects; 289 228 290 time_point<steady_clock> startTime; 229 291 float prevTime, elapsedTime; … … 236 298 237 299 unsigned int leftLaserIdx = -1; 300 EffectOverTime<AsteroidVertex, SSBO_Asteroid>* leftLaserEffect = nullptr; 238 301 239 302 unsigned int rightLaserIdx = -1; 303 EffectOverTime<AsteroidVertex, SSBO_Asteroid>* rightLaserEffect = nullptr; 240 304 241 305 bool initWindow(int width, int height, unsigned char guiFlags);
Note:
See TracChangeset
for help on using the changeset viewer.