1 /* ScummVM - Graphic Adventure Engine
2  *
3  * ScummVM is the legal property of its developers, whose names
4  * are too numerous to list here. Please refer to the COPYRIGHT
5  * file distributed with this source distribution.
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or(at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20  *
21  */
22 
23 #ifndef AGS_PLUGINS_AGS_WAVES_AGS_WAVES_H
24 #define AGS_PLUGINS_AGS_WAVES_AGS_WAVES_H
25 
26 #include "audio/mixer.h"
27 #include "common/fs.h"
28 #include "ags/plugins/ags_plugin.h"
29 #include "ags/plugins/ags_waves/vars.h"
30 
31 namespace AGS3 {
32 namespace Plugins {
33 namespace AGSWaves {
34 
35 class AGSWaves : public PluginBase, public Vars {
36 	SCRIPT_HASH(AGSWaves)
37 private:
38 	Audio::Mixer *_mixer;
39 private:
40 	void DrawScreenEffect(ScriptMethodParams &params);
41 	void SFX_Play(ScriptMethodParams &params);
42 	void SFX_SetVolume(ScriptMethodParams &params);
43 	void SFX_GetVolume(ScriptMethodParams &params);
44 	void Music_Play(ScriptMethodParams &params);
45 	void Music_GetVolume(ScriptMethodParams &params);
46 	void Music_SetVolume(ScriptMethodParams &params);
47 	void SFX_Stop(ScriptMethodParams &params);
48 	void SFX_SetPosition(ScriptMethodParams &params);
49 	void SFX_SetGlobalVolume(ScriptMethodParams &params);
50 	void Load_SFX(ScriptMethodParams &params);
51 	void Audio_Apply_Filter(ScriptMethodParams &params);
52 	void Audio_Remove_Filter(ScriptMethodParams &params);
53 	void SFX_AllowOverlap(ScriptMethodParams &params);
54 	void SFX_Filter(ScriptMethodParams &params);
55 	void DrawBlur(ScriptMethodParams &params);
56 	void DrawTunnel(ScriptMethodParams &params);
57 	void DrawCylinder(ScriptMethodParams &params);
58 	void DrawForceField(ScriptMethodParams &params);
59 	void Grayscale(ScriptMethodParams &params);
60 	void ReadWalkBehindIntoSprite(ScriptMethodParams &params);
61 	void AdjustSpriteFont(ScriptMethodParams &params);
62 	void SpriteGradient(ScriptMethodParams &params);
63 	void Outline(ScriptMethodParams &params);
64 	void OutlineOnly(ScriptMethodParams &params);
65 	void SaveVariable(ScriptMethodParams &params);
66 	void ReadVariable(ScriptMethodParams &params);
67 	void GameDoOnceOnly(ScriptMethodParams &params);
68 	void SetGDState(ScriptMethodParams &params);
69 	void GetGDState(ScriptMethodParams &params);
70 	void ResetAllGD(ScriptMethodParams &params);
71 	void SpriteSkew(ScriptMethodParams &params);
72 	void FireUpdate(ScriptMethodParams &params);
73 	void WindUpdate(ScriptMethodParams &params);
74 	void SetWindValues(ScriptMethodParams &params);
75 	void ReturnWidth(ScriptMethodParams &params);
76 	void ReturnHeight(ScriptMethodParams &params);
77 	void ReturnNewHeight(ScriptMethodParams &params);
78 	void ReturnNewWidth(ScriptMethodParams &params);
79 	void Warper(ScriptMethodParams &params);
80 	void SetWarper(ScriptMethodParams &params);
81 	void RainUpdate(ScriptMethodParams &params);
82 	void BlendTwoSprites(ScriptMethodParams &params);
83 	void Blend(ScriptMethodParams &params);
84 	void Dissolve(ScriptMethodParams &params);
85 	void ReverseTransparency(ScriptMethodParams &params);
86 	void NoiseCreator(ScriptMethodParams &params);
87 	void TintProper(ScriptMethodParams &params);
88 	void GetWalkbehindBaserine(ScriptMethodParams &params);
89 	void SetWalkbehindBaserine(ScriptMethodParams &params);
90 
91 private:
92 	void StartingValues();
93 	void Update();
94 
95 	void CastWave(int delayMax, int PixelsWide, int n);
96 	void DrawEffect(int sprite_a, int sprite_b, int id, int n);
97 	int Random(int threshold);
98 
getRcolor(int color)99 	inline static int getRcolor(int color) {
100 		return ((color >> 16) & 0xFF);
101 	}
getGcolor(int color)102 	inline static int getGcolor(int color) {
103 		return ((color >> 8) & 0xFF);
104 	}
getBcolor(int color)105 	inline static int getBcolor(int color) {
106 		return ((color >> 0) & 0xFF);
107 	}
getAcolor(int color)108 	inline static int getAcolor(int color) {
109 		return ((color >> 24) & 0xFF);
110 	}
BlendColor(int Ln,int Bn,int perc)111 	static int BlendColor(int Ln, int Bn, int perc) {
112 		return ((Ln < 128) ? (2 * Bn * Ln / perc) : (perc - 2 * (perc - Bn) * (perc - Ln) / perc));
113 	}
BlendColorScreen(int Ln,int Bn,int perc)114 	static int BlendColorScreen(int Ln, int Bn, int perc) {
115 		return (Bn == perc) ? Bn :
116 			MIN(perc, (Ln * Ln / (perc - Bn)));
117 	}
118 	static int SetColorRGBA(int r, int g, int b, int a);
119 	static int ConvertColorToGrayScale(int color);
120 	static bool IsPixelTransparent(int color);
121 	float noiseField(float tx, float ty, float tz);
122 
123 	int IntersectLines(float x1, float y1, float x2, float y2, float x3, float y3, float x4, float y4);
124 
fracts(float value)125 	static inline float fracts(float value) {
126 		return value - floor(value);
127 	}
lerp(float x,float y,float fn)128 	static inline float lerp(float x, float y, float fn) {
129 		return x * (1.0 - fn) + y * fn;
130 	}
hasher(float n)131 	static inline float hasher(float n) {
132 		return fracts(sin(n) * 153.5453123);
133 	}
min4(float m1,float m2,float m3,float m4)134 	static float min4(float m1, float m2, float m3, float m4) {
135 		return MIN(MIN(m1, m2), MIN(m3, m4));
136 	}
max4(float m1,float m2,float m3,float m4)137 	static float max4(float m1, float m2, float m3, float m4) {
138 		return MAX(MAX(m1, m2), MAX(m3, m4));
139 	}
140 
141 	// Weather
142 	void DrawLineCustom(int x1, int y1, int x2, int y2, int graphic, int setR, int setG, int setB, int setA, int TranDif);
143 	void CreateParticle(int xx, int yy, int ForceX, int ForceY);
144 	void CreateParticle2(int xx, int yy, int ForceX, int ForceY);
145 	void CreateParticleF(int xx, int yy, int ForceX, int ForceY);
146 	void CreateDustParticle(int xx, int yy);
147 	void CreateRainParticleMid(int x, int y, int fx, int fy, int maxpart);
148 	void CreateRainParticleFore(int x, int y, int fx, int fy, int maxpart);
149 	void CreateRainParticleBack(int x, int y, int fx, int fy, int maxpart);
150 
151 	// Sound
152 	/**
153 	 * Plays a sound from the sounds.sfx in the Sounds/ folder
154 	 * @param soundToPlay	The sound to play
155 	 * @param repeat		Times to repeat, -1 for indefine
156 	 */
157 	void PlaySFX(int SoundToPlay, int repeat);
158 
159 	/**
160 	 * Stops a playing sound effect
161 	 */
162 	void StopSFX(int sfxNum);
163 
164 	/**
165 	 * Loads a ScummVM OGG stream for playback
166 	 */
167 	Audio::AudioStream *loadOGG(const Common::FSNode &fsNode);
168 
169 	void playStream(Audio::Mixer::SoundType type, Audio::SoundHandle *handle, Audio::AudioStream *stream, int repeat);
170 
171 	void stopAllSounds();
172 	void GlitchFix();
173 	void ApplyFilter(int SetFrequency);
174 	void SetFilterFrequency(int setFrequency);
175 	void MusicPlay(int MusicToPlay, int repeat, int fadeinMS, int fadeoutMS, int pos, bool forceplay, bool fixclick);
176 
177 public:
178 	AGSWaves();
179 	virtual ~AGSWaves();
180 
181 	const char *AGS_GetPluginName() override;
182 	void AGS_EngineStartup(IAGSEngine *engine) override;
183 	int64 AGS_EngineOnEvent(int event, NumberPtr data) override;
184 };
185 
186 } // namespace AGSWaves
187 } // namespace Plugins
188 } // namespace AGS3
189 
190 #endif
191