1 /*
2 Copyright (C) 2007, 2010 - Bit-Blot
3 
4 This file is part of Aquaria.
5 
6 Aquaria is free software; you can redistribute it and/or
7 modify it under the terms of the GNU General Public License
8 as published by the Free Software Foundation; either version 2
9 of the License, or (at your option) any later version.
10 
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14 
15 See the GNU General Public License for more details.
16 
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
20 */
21 #ifndef __after_effect__
22 #define __after_effect__
23 
24 #include "Core.h"
25 
26 
27 class Effect
28 {
29 public:
30 	Effect();
go()31 	virtual void go(){}
update(float dt,Vector ** drawGrid,int xDivs,int yDivs)32 	virtual void update(float dt, Vector ** drawGrid, int xDivs, int yDivs){}
33 	bool done;
34 	Vector position;
35 protected:
36 	float rate;
37 };
38 
39 class ShockEffect : public Effect
40 {
41 public:
Effect()42 	ShockEffect(Vector position, Vector originalCenter, float nAmplitude, float nAmpDecay, float nFrequency,float nWaveLength, float timeMultiplier=1.0) : Effect()
43 	{
44 		this->originalCenter = originalCenter;
45 		this->position = position;
46 		amplitude = nAmplitude;
47 		frequency = nFrequency;
48 		waveLength = nWaveLength;
49 		rate = nAmpDecay;
50 		currentDistance = 0;
51 		this->timeMultiplier = timeMultiplier;
52 	}
53 	float timeMultiplier;
54 	//void go();
55 	void update(float dt, Vector ** drawGrid, int xDivs, int yDivs);
56 
57 	float waveLength;
58 	float amplitude;
59 	float frequency;
60 
61 	Vector centerPoint;
62 	Vector originalCenter;
63 
64 	float currentDistance;
65 };
66 
67 class RippleEffect : public Effect
68 {
69 public:
70 	RippleEffect();
71 	void update(float dt, Vector ** drawGrid, int xDivs, int yDivs);
72 	float time;
73 };
74 
75 class AfterEffectManager
76 {
77 public:
78 	AfterEffectManager(int xDivs, int yDivs);
79 	~AfterEffectManager();
80 	void addEffect(Effect *e);
81 	void destroyEffect(int id);
82 	void update(float dt);
83 
84 	void clear();
85 	void deleteEffects();
86 
87 	void resetGrid();
88 
89 	void render();
90 	void renderGrid();
91 	void renderGridPoints();
92 
93 	void loadShaders();
94 	void unloadShaders(); // unloads shaders but keeps code and data intact, so that they can be reloaded.
95 	void deleteShaders();
96 
97 	void unloadDevice();
98 	void reloadDevice();
99 
100 	std::vector<Effect*> effects;
101 	std::queue<int> openSpots;
102 
103 	bool active;
104 
105 	bool bRenderGridPoints;
106 
107 	int numEffects;
108 	int xDivs, yDivs;
109 	int screenWidth, screenHeight;
110 	int textureWidth, textureHeight;
111 
112 	Vector ** drawGrid;
113 
114 	// returns handle > 0 on success
115 	int loadShaderFile(const char *vert, const char *frag);
116 	int loadShaderSrc(const char *vert, const char *frag);
117 	Shader *getShaderPtr(int handle);
118 	void setShaderPipelineSize(size_t size);
119 	bool setShaderPipelinePos(int handle, size_t pos);
120 	void deleteShader(int handle);
121 
122 protected:
123 	int _insertShader(Shader *sh);
124 
125 	std::vector<Shader*> shaderPipeline; // Shaders are applied in this order. Can contain the same pointer more than once.
126 	std::vector<Shader*> loadedShaders;
127 	FrameBuffer backupBuffer;
128 
129 };
130 
131 
132 #endif
133 
134 
135