state.h 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448
  1. /*
  2. LICENSE
  3. -------
  4. Copyright 2005-2013 Nullsoft, Inc.
  5. All rights reserved.
  6. Redistribution and use in source and binary forms, with or without modification,
  7. are permitted provided that the following conditions are met:
  8. * Redistributions of source code must retain the above copyright notice,
  9. this list of conditions and the following disclaimer.
  10. * Redistributions in binary form must reproduce the above copyright notice,
  11. this list of conditions and the following disclaimer in the documentation
  12. and/or other materials provided with the distribution.
  13. * Neither the name of Nullsoft nor the names of its contributors may be used to
  14. endorse or promote products derived from this software without specific prior written permission.
  15. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
  16. IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
  17. FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  18. CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  19. DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  20. DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
  21. IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
  22. OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  23. */
  24. #ifndef _MILKDROP_STATE_
  25. #define _MILKDROP_STATE_ 1
  26. #include <memory.h>
  27. #include <stdlib.h>
  28. #include <stdio.h>
  29. #include "gstring.h"
  30. #include "texmgr.h"
  31. #include <d3dx9math.h> // for D3DXVECTOR3
  32. //#include "evallib/eval.h"
  33. #include "ns-eel2/ns-eel.h"
  34. #include "md_defines.h"
  35. // flags for CState::RecompileExpressions():
  36. #define RECOMPILE_PRESET_CODE 1
  37. #define RECOMPILE_WAVE_CODE 2
  38. #define RECOMPILE_SHAPE_CODE 4
  39. #define NUM_Q_VAR 32
  40. #define NUM_T_VAR 8
  41. #define MAX_BIGSTRING_LEN 32768
  42. class CBlendableFloat
  43. {
  44. public:
  45. CBlendableFloat();
  46. ~CBlendableFloat();
  47. float operator = (float f) {
  48. val = f;
  49. m_bBlending = false;
  50. return val;
  51. };
  52. float operator *= (float f) {
  53. val *= f;
  54. m_bBlending = false;
  55. return val;
  56. };
  57. float operator /= (float f) {
  58. val /= f;
  59. m_bBlending = false;
  60. return val;
  61. };
  62. float operator -= (float f) {
  63. val -= f;
  64. m_bBlending = false;
  65. return val;
  66. };
  67. float operator += (float f) {
  68. val += f;
  69. m_bBlending = false;
  70. return val;
  71. };
  72. float eval(float fTime); // call this from animation code. if fTime < 0, it will return unblended 'val'.
  73. void StartBlendFrom(CBlendableFloat *f_from, float fAnimTime, float fDuration);
  74. protected:
  75. float val;
  76. bool m_bBlending;
  77. float m_fBlendStartTime;
  78. float m_fBlendDuration;
  79. float m_fBlendFrom;
  80. };
  81. class CShape
  82. {
  83. public:
  84. int Import(FILE* f, const wchar_t* szFile, int i);
  85. int Export(FILE* f, const wchar_t* szFile, int i);
  86. int enabled;
  87. int sides;
  88. int additive;
  89. int thickOutline;
  90. int textured;
  91. int instances;
  92. float x,y,rad,ang;
  93. float r,g,b,a;
  94. float r2,g2,b2,a2;
  95. float border_r,border_g,border_b,border_a;
  96. float tex_ang, tex_zoom;
  97. char m_szInit[MAX_BIGSTRING_LEN]; // note: only executed once -> don't need to save codehandle
  98. char m_szPerFrame[MAX_BIGSTRING_LEN];
  99. //char m_szPerPoint[MAX_BIGSTRING_LEN];
  100. NSEEL_CODEHANDLE m_pf_codehandle;
  101. //int m_pp_codehandle;
  102. // for per-frame expression evaluation:
  103. NSEEL_VMCTX m_pf_eel;
  104. double *var_pf_time, *var_pf_fps;
  105. double *var_pf_frame;
  106. double *var_pf_progress;
  107. //double *var_pf_q1, *var_pf_q2, *var_pf_q3, *var_pf_q4, *var_pf_q5, *var_pf_q6, *var_pf_q7, *var_pf_q8;
  108. //double *var_pf_t1, *var_pf_t2, *var_pf_t3, *var_pf_t4, *var_pf_t5, *var_pf_t6, *var_pf_t7, *var_pf_t8;
  109. double* var_pf_q[NUM_Q_VAR];
  110. double* var_pf_t[NUM_T_VAR];
  111. double *var_pf_bass, *var_pf_mid, *var_pf_treb, *var_pf_bass_att, *var_pf_mid_att, *var_pf_treb_att;
  112. double *var_pf_r, *var_pf_g, *var_pf_b, *var_pf_a;
  113. double *var_pf_r2, *var_pf_g2, *var_pf_b2, *var_pf_a2;
  114. double *var_pf_border_r, *var_pf_border_g, *var_pf_border_b, *var_pf_border_a;
  115. double *var_pf_x, *var_pf_y, *var_pf_rad, *var_pf_ang;
  116. double *var_pf_sides, *var_pf_textured, *var_pf_additive, *var_pf_thick, *var_pf_instances, *var_pf_instance;
  117. double *var_pf_tex_zoom, *var_pf_tex_ang;
  118. // for per-point expression evaluation:
  119. /*
  120. NSEEL_VMCTX m_pp_eel;
  121. double *var_pp_time, *var_pp_fps;
  122. double *var_pp_frame;
  123. double *var_pp_progress;
  124. double *var_pp_q1, *var_pp_q2, *var_pp_q3, *var_pp_q4, *var_pp_q5, *var_pp_q6, *var_pp_q7, *var_pp_q8;
  125. double *var_pp_t1, *var_pp_t2, *var_pp_t3, *var_pp_t4, *var_pp_t5, *var_pp_t6, *var_pp_t7, *var_pp_t8;
  126. double *var_pp_bass, *var_pp_mid, *var_pp_treb, *var_pp_bass_att, *var_pp_mid_att, *var_pp_treb_att;
  127. double *var_pp_r, *var_pp_g, *var_pp_b, *var_pp_a;
  128. double *var_pp_r2, *var_pp_g2, *var_pp_b2, *var_pp_a2;
  129. double *var_pp_border_r, *var_pp_border_g, *var_pp_border_b, *var_pp_border_a;
  130. double *var_pp_x, *var_pp_y, *var_pp_rad, *var_pp_ang, *var_pp_sides;
  131. */
  132. double t_values_after_init_code[NUM_T_VAR];
  133. };
  134. class CWave
  135. {
  136. public:
  137. int Import(FILE* f, const wchar_t *szFile, int i);
  138. int Export(FILE* f, const wchar_t* szFile, int i);
  139. int enabled;
  140. int samples;
  141. int sep;
  142. float scaling;
  143. float smoothing;
  144. float x,y,r,g,b,a;
  145. int bSpectrum;
  146. int bUseDots;
  147. int bDrawThick;
  148. int bAdditive;
  149. char m_szInit[MAX_BIGSTRING_LEN]; // note: only executed once -> don't need to save codehandle
  150. char m_szPerFrame[MAX_BIGSTRING_LEN];
  151. char m_szPerPoint[MAX_BIGSTRING_LEN];
  152. NSEEL_CODEHANDLE m_pf_codehandle;
  153. NSEEL_CODEHANDLE m_pp_codehandle;
  154. // for per-frame expression evaluation:
  155. NSEEL_VMCTX m_pf_eel;
  156. double *var_pf_time, *var_pf_fps;
  157. double *var_pf_frame;
  158. double *var_pf_progress;
  159. //double *var_pf_q1, *var_pf_q2, *var_pf_q3, *var_pf_q4, *var_pf_q5, *var_pf_q6, *var_pf_q7, *var_pf_q8;
  160. //double *var_pf_t1, *var_pf_t2, *var_pf_t3, *var_pf_t4, *var_pf_t5, *var_pf_t6, *var_pf_t7, *var_pf_t8;
  161. double* var_pf_q[NUM_Q_VAR];
  162. double* var_pf_t[NUM_T_VAR];
  163. double *var_pf_bass, *var_pf_mid, *var_pf_treb, *var_pf_bass_att, *var_pf_mid_att, *var_pf_treb_att;
  164. double *var_pf_r, *var_pf_g, *var_pf_b, *var_pf_a;
  165. double *var_pf_samples;
  166. // for per-point expression evaluation:
  167. NSEEL_VMCTX m_pp_eel;
  168. double *var_pp_time, *var_pp_fps;
  169. double *var_pp_frame;
  170. double *var_pp_progress;
  171. //double *var_pp_q1, *var_pp_q2, *var_pp_q3, *var_pp_q4, *var_pp_q5, *var_pp_q6, *var_pp_q7, *var_pp_q8;
  172. //double *var_pp_t1, *var_pp_t2, *var_pp_t3, *var_pp_t4, *var_pp_t5, *var_pp_t6, *var_pp_t7, *var_pp_t8;
  173. double* var_pp_q[NUM_Q_VAR];
  174. double* var_pp_t[NUM_T_VAR];
  175. double *var_pp_bass, *var_pp_mid, *var_pp_treb, *var_pp_bass_att, *var_pp_mid_att, *var_pp_treb_att;
  176. double *var_pp_sample, *var_pp_value1, *var_pp_value2;
  177. double *var_pp_x, *var_pp_y, *var_pp_r, *var_pp_g, *var_pp_b, *var_pp_a;
  178. double t_values_after_init_code[NUM_T_VAR];
  179. };
  180. typedef struct
  181. {
  182. int type;
  183. int in_var;
  184. int out_var;
  185. float constant;
  186. float min;
  187. float max;
  188. float in_scale;
  189. float amp; // for sine functions
  190. float freq; // for sine functions
  191. float freq2; // for sine functions
  192. float phase; // for sine functions
  193. float phase2; // for sine functions
  194. } td_modifier;
  195. //#define MAX_EVALS 8
  196. #define INVALID_PRESET_DESC L"<no description>" // this should contain invalid filename chars, so there is never a conflict...
  197. #define STATE_GENERAL 1 // and postproc (old presets) or blur, etc. (new presets)
  198. #define STATE_MOTION 2 // and equations
  199. #define STATE_WAVE 4 // waves, shapes, motion vectors
  200. #define STATE_WARP 8
  201. #define STATE_COMP 16
  202. #define STATE_ALL (32-1)
  203. #define CUR_MILKDROP_PRESET_VERSION 201
  204. // 200: milkdrop 2
  205. // 201: instead of just 1 variable for shader version, it tracks 2 (comp and warp) separately.
  206. class CState
  207. {
  208. public:
  209. CState();
  210. ~CState();
  211. void Default(DWORD ApplyFlags=STATE_ALL);
  212. void Randomize(int nMode);
  213. void StartBlendFrom(CState *s_from, float fAnimTime, float fTimespan);
  214. bool Import(const wchar_t *szIniFile, float fTime, CState* pOldState, DWORD ApplyFlags=STATE_ALL);
  215. bool Export(const wchar_t *szIniFile);
  216. void RecompileExpressions(int flags=0xFFFFFFFF, int bReInit=1);
  217. void GenDefaultWarpShader();
  218. void GenDefaultCompShader();
  219. wchar_t m_szDesc[512]; // this is just the filename, without a path or extension.
  220. //char m_szSection[256];
  221. int m_nMinPSVersion; // the min of the warp & comp values...
  222. int m_nMaxPSVersion; // the max of the warp & comp values...
  223. int m_nWarpPSVersion; // 0 = milkdrop 1 era (no PS), 2 = ps_2_0, 3 = ps_3_0
  224. int m_nCompPSVersion; // 0 = milkdrop 1 era (no PS), 2 = ps_2_0, 3 = ps_3_0
  225. float m_fRating; // 0..5
  226. // post-processing:
  227. CBlendableFloat m_fGammaAdj; // +0 -> +1.0 (double), +2.0 (triple)...
  228. CBlendableFloat m_fVideoEchoZoom;
  229. CBlendableFloat m_fVideoEchoAlpha;
  230. float m_fVideoEchoAlphaOld;
  231. int m_nVideoEchoOrientation;
  232. int m_nVideoEchoOrientationOld;
  233. // fps-dependant:
  234. CBlendableFloat m_fDecay; // 1.0 = none, 0.95 = heavy decay
  235. // other:
  236. int m_nWaveMode;
  237. int m_nOldWaveMode;
  238. bool m_bAdditiveWaves;
  239. CBlendableFloat m_fWaveAlpha;
  240. CBlendableFloat m_fWaveScale;
  241. CBlendableFloat m_fWaveSmoothing;
  242. bool m_bWaveDots;
  243. bool m_bWaveThick;
  244. CBlendableFloat m_fWaveParam; // -1..1; 0 is normal
  245. bool m_bModWaveAlphaByVolume;
  246. CBlendableFloat m_fModWaveAlphaStart; // when relative volume hits this level, alpha -> 0
  247. CBlendableFloat m_fModWaveAlphaEnd; // when relative volume hits this level, alpha -> 1
  248. float m_fWarpAnimSpeed; // 1.0 = normal, 2.0 = double, 0.5 = half, etc.
  249. CBlendableFloat m_fWarpScale;
  250. CBlendableFloat m_fZoomExponent;
  251. CBlendableFloat m_fShader; // 0 = no color shader, 1 = full color shader
  252. bool m_bMaximizeWaveColor;
  253. bool m_bTexWrap;
  254. bool m_bDarkenCenter;
  255. bool m_bRedBlueStereo;
  256. bool m_bBrighten;
  257. bool m_bDarken;
  258. bool m_bSolarize;
  259. bool m_bInvert;
  260. /*
  261. bool m_bPlates;
  262. int m_nPlates;
  263. CBlendableFloat m_fPlateAlpha; // 0 = off, 0.1 = barely visible, 1.0 = solid
  264. CBlendableFloat m_fPlateR;
  265. CBlendableFloat m_fPlateG;
  266. CBlendableFloat m_fPlateB;
  267. CBlendableFloat m_fPlateWidth; // 1.0=normal, 2.0=double, etc.
  268. CBlendableFloat m_fPlateLength; // 1.0=normal, 2.0=double, etc.
  269. float m_fPlateSpeed; // 1.0=normal, 2.0=double, etc.
  270. bool m_bPlatesAdditive;
  271. */
  272. // map controls:
  273. CBlendableFloat m_fZoom;
  274. CBlendableFloat m_fRot;
  275. CBlendableFloat m_fRotCX;
  276. CBlendableFloat m_fRotCY;
  277. CBlendableFloat m_fXPush;
  278. CBlendableFloat m_fYPush;
  279. CBlendableFloat m_fWarpAmount;
  280. CBlendableFloat m_fStretchX;
  281. CBlendableFloat m_fStretchY;
  282. CBlendableFloat m_fWaveR;
  283. CBlendableFloat m_fWaveG;
  284. CBlendableFloat m_fWaveB;
  285. CBlendableFloat m_fWaveX;
  286. CBlendableFloat m_fWaveY;
  287. CBlendableFloat m_fOuterBorderSize;
  288. CBlendableFloat m_fOuterBorderR;
  289. CBlendableFloat m_fOuterBorderG;
  290. CBlendableFloat m_fOuterBorderB;
  291. CBlendableFloat m_fOuterBorderA;
  292. CBlendableFloat m_fInnerBorderSize;
  293. CBlendableFloat m_fInnerBorderR;
  294. CBlendableFloat m_fInnerBorderG;
  295. CBlendableFloat m_fInnerBorderB;
  296. CBlendableFloat m_fInnerBorderA;
  297. CBlendableFloat m_fMvX;
  298. CBlendableFloat m_fMvY;
  299. CBlendableFloat m_fMvDX;
  300. CBlendableFloat m_fMvDY;
  301. CBlendableFloat m_fMvL;
  302. CBlendableFloat m_fMvR;
  303. CBlendableFloat m_fMvG;
  304. CBlendableFloat m_fMvB;
  305. CBlendableFloat m_fMvA;
  306. CBlendableFloat m_fBlur1Min;
  307. CBlendableFloat m_fBlur2Min;
  308. CBlendableFloat m_fBlur3Min;
  309. CBlendableFloat m_fBlur1Max;
  310. CBlendableFloat m_fBlur2Max;
  311. CBlendableFloat m_fBlur3Max;
  312. CBlendableFloat m_fBlur1EdgeDarken;
  313. CShape m_shape[MAX_CUSTOM_SHAPES];
  314. CWave m_wave[MAX_CUSTOM_WAVES];
  315. // some random stuff for driving shaders:
  316. void RandomizePresetVars();
  317. D3DXVECTOR4 m_rand_preset; // 4 random floats (0..1); randomized @ preset load; fed to pixel shaders. --FIXME (blending)
  318. D3DXVECTOR3 m_xlate[20];
  319. D3DXVECTOR3 m_rot_base[20];
  320. D3DXVECTOR3 m_rot_speed[20];
  321. //COscillator m_waveR;
  322. //COscillator m_waveG;
  323. //COscillator m_waveB;
  324. //COscillator m_wavePosX; // 0 = centered
  325. //COscillator m_wavePosY; // 0 = centered
  326. // for arbitrary function evaluation:
  327. NSEEL_CODEHANDLE m_pf_codehandle;
  328. NSEEL_CODEHANDLE m_pp_codehandle;
  329. char m_szPerFrameInit[MAX_BIGSTRING_LEN];
  330. char m_szPerFrameExpr[MAX_BIGSTRING_LEN];
  331. char m_szPerPixelExpr[MAX_BIGSTRING_LEN];
  332. char m_szWarpShadersText[MAX_BIGSTRING_LEN]; // pixel shader code
  333. char m_szCompShadersText[MAX_BIGSTRING_LEN]; // pixel shader code
  334. void FreeVarsAndCode(bool bFree = true);
  335. void RegisterBuiltInVariables(int flags);
  336. void StripLinefeedCharsAndComments(char *src, char *dest);
  337. bool m_bBlending;
  338. float m_fBlendStartTime;
  339. float m_fBlendDuration;
  340. float m_fBlendProgress; // 0..1; updated every frame based on StartTime and Duration.
  341. // for once-per-frame expression evaluation: [although, these vars are also shared w/preset init expr eval]
  342. NSEEL_VMCTX m_pf_eel;
  343. double *var_pf_zoom, *var_pf_zoomexp, *var_pf_rot, *var_pf_warp, *var_pf_cx, *var_pf_cy, *var_pf_dx, *var_pf_dy, *var_pf_sx, *var_pf_sy;
  344. double *var_pf_time, *var_pf_fps;
  345. double *var_pf_bass, *var_pf_mid, *var_pf_treb, *var_pf_bass_att, *var_pf_mid_att, *var_pf_treb_att;
  346. double *var_pf_wave_a, *var_pf_wave_r, *var_pf_wave_g, *var_pf_wave_b, *var_pf_wave_x, *var_pf_wave_y, *var_pf_wave_mystery, *var_pf_wave_mode;
  347. double *var_pf_decay;
  348. double *var_pf_frame;
  349. //double *var_pf_q1, *var_pf_q2, *var_pf_q3, *var_pf_q4, *var_pf_q5, *var_pf_q6, *var_pf_q7, *var_pf_q8;
  350. double* var_pf_q[NUM_Q_VAR];
  351. double *var_pf_progress;
  352. double *var_pf_ob_size, *var_pf_ob_r, *var_pf_ob_g, *var_pf_ob_b, *var_pf_ob_a;
  353. double *var_pf_ib_size, *var_pf_ib_r, *var_pf_ib_g, *var_pf_ib_b, *var_pf_ib_a;
  354. double *var_pf_mv_x;
  355. double *var_pf_mv_y;
  356. double *var_pf_mv_dx;
  357. double *var_pf_mv_dy;
  358. double *var_pf_mv_l;
  359. double *var_pf_mv_r;
  360. double *var_pf_mv_g;
  361. double *var_pf_mv_b;
  362. double *var_pf_mv_a;
  363. double *var_pf_monitor;
  364. double *var_pf_echo_zoom, *var_pf_echo_alpha, *var_pf_echo_orient;
  365. // new in v1.04:
  366. double *var_pf_wave_usedots, *var_pf_wave_thick, *var_pf_wave_additive, *var_pf_wave_brighten;
  367. double *var_pf_darken_center, *var_pf_gamma, *var_pf_wrap;
  368. double *var_pf_invert, *var_pf_brighten, *var_pf_darken, *var_pf_solarize;
  369. double *var_pf_meshx, *var_pf_meshy;
  370. double *var_pf_pixelsx, *var_pf_pixelsy;
  371. double *var_pf_aspectx, *var_pf_aspecty;
  372. double *var_pf_blur1min;
  373. double *var_pf_blur2min;
  374. double *var_pf_blur3min;
  375. double *var_pf_blur1max;
  376. double *var_pf_blur2max;
  377. double *var_pf_blur3max;
  378. double *var_pf_blur1_edge_darken;
  379. // for per-vertex expression evaluation:
  380. NSEEL_VMCTX m_pv_eel;
  381. double *var_pv_zoom, *var_pv_zoomexp, *var_pv_rot, *var_pv_warp, *var_pv_cx, *var_pv_cy, *var_pv_dx, *var_pv_dy, *var_pv_sx, *var_pv_sy;
  382. double *var_pv_time, *var_pv_fps;
  383. double *var_pv_bass, *var_pv_mid, *var_pv_treb, *var_pv_bass_att, *var_pv_mid_att, *var_pv_treb_att;
  384. double *var_pv_x, *var_pv_y, *var_pv_rad, *var_pv_ang;
  385. double *var_pv_frame;
  386. //double *var_pv_q1, *var_pv_q2, *var_pv_q3, *var_pv_q4, *var_pv_q5, *var_pv_q6, *var_pv_q7, *var_pv_q8;
  387. double* var_pv_q[NUM_Q_VAR];
  388. double *var_pv_progress;
  389. double *var_pv_meshx, *var_pv_meshy;
  390. double *var_pv_pixelsx, *var_pv_pixelsy;
  391. double *var_pv_aspectx, *var_pv_aspecty;
  392. double q_values_after_init_code[NUM_Q_VAR];
  393. double monitor_after_init_code;
  394. float GetPresetStartTime() { return m_fPresetStartTime; }
  395. float m_fPresetStartTime;
  396. };
  397. #endif