1
0

state.cpp 80 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961
  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. #include "api__vis_milk2.h"
  25. #include "state.h"
  26. #include "support.h"
  27. #include "ns-eel2/ns-eel.h"
  28. #include "plugin.h"
  29. #include "utility.h"
  30. #include <windows.h>
  31. #include <locale.h>
  32. #include "resource.h"
  33. #include <vector>
  34. #include <assert.h>
  35. extern CPlugin g_plugin; // declared in main.cpp
  36. #define FRAND ((rand() % 7381)/7380.0f)
  37. // These are intended to replace GetPrivateProfileInt/FloatString, which are very slow
  38. // for large files (they always start from the top). (really slow - some preset loads
  39. // were taking 90 ms because of these!)
  40. // The trick here is that we assume the file will be ordered correctly. If not - if
  41. // the next line doesn't have the expected token - we rescan from the top. If the line
  42. // is never found, we use the default value, and leave MyGetPos untouched.
  43. #include "gstring.h"
  44. typedef std::vector<GStringA> VarNameList;
  45. typedef std::vector<int > IntList;
  46. FILE* fLastFilePtr = NULL;
  47. void GetFast_CLEAR() { fLastFilePtr = NULL; }
  48. bool _GetLineByName(FILE* f, const char* szVarName, char* szRet, int nMaxRetChars)
  49. {
  50. // lines in the file look like this: szVarName=szRet
  51. // OR: szVarName szRet
  52. // the part of the line after the '=' sign (or space) goes into szRet.
  53. // szVarName can't have any spaces in it.
  54. static int MyLineNum = 0;
  55. static VarNameList line_varName;
  56. static IntList line_value_bytepos;
  57. if (f != fLastFilePtr)
  58. {
  59. fLastFilePtr = f;
  60. MyLineNum = 0;
  61. line_varName.clear();
  62. line_value_bytepos.clear();
  63. // start from beginning of file
  64. fseek(f, 0, SEEK_SET);
  65. // scan each line in the file for "szVarName=value" pairs, and store info about them.
  66. #define MAX_VARNAME_LEN 128
  67. char szThisLineVarName[MAX_VARNAME_LEN];
  68. while (1)
  69. {
  70. char ch;
  71. int pos = 0;
  72. do
  73. {
  74. ch = fgetc(f);
  75. if (pos < MAX_VARNAME_LEN-3)
  76. szThisLineVarName[pos++] = ch;
  77. }
  78. while ( ch != '\r' &&
  79. ch != '\n' &&
  80. ch != ' ' &&
  81. ch != '=' &&
  82. ch != EOF );
  83. if (ch == EOF)
  84. break;
  85. if (ch == '=' || ch == ' ')
  86. {
  87. szThisLineVarName[pos-1] = 0; // replace '=' with a null char.
  88. int bytepos = ftell(f);
  89. //add an entry
  90. line_varName.push_back(szThisLineVarName);
  91. line_value_bytepos.push_back( bytepos );
  92. // eat chars up to linefeed or EOF
  93. /*
  94. do
  95. {
  96. ch = fgetc(f);
  97. }
  98. while (ch != '\r' && ch != '\n' && ch != EOF);
  99. */
  100. fgets(szRet, nMaxRetChars-3, f); // reads chars up til the next linefeed.
  101. }
  102. if (ch == EOF)
  103. break;
  104. // eat any extra linefeed chars.
  105. do
  106. {
  107. ch = fgetc(f);
  108. }
  109. while ((ch == '\r' || ch == '\n') && ch != EOF);
  110. if (ch == EOF)
  111. break;
  112. // back up one char
  113. fseek(f, -1, SEEK_CUR);
  114. // on to next line...
  115. }
  116. }
  117. // if current line isn't the one, check all the others...
  118. if (MyLineNum < 0 || (size_t)MyLineNum >= line_varName.size() || strcmp(line_varName[MyLineNum].c_str(), szVarName) != 0)
  119. {
  120. int N = line_varName.size();
  121. int i = 0;
  122. for (i=0; i<N; i++)
  123. if (strcmp(line_varName[i].c_str(), szVarName) == 0)
  124. {
  125. MyLineNum = i;
  126. break;
  127. }
  128. // otherwise, szVarName not found in the file!
  129. if (i==N)
  130. return false;
  131. }
  132. fseek(f, line_value_bytepos[MyLineNum], SEEK_SET);
  133. // now we know that we found and ate the '=' sign; return rest of the line.
  134. int nChars = 0;
  135. int pos = 0;
  136. while (pos < nMaxRetChars-3)
  137. {
  138. char ch = fgetc(f);
  139. if (ch == '\r' || ch == '\n' || ch==EOF)
  140. break;
  141. szRet[pos++] = ch;
  142. };
  143. szRet[pos] = 0;
  144. //fgets(szRet, nMaxRetChars-3, f); // reads chars up til the next linefeed. NAH - it also copies in the linefeed char...
  145. // move to next line
  146. MyLineNum++;
  147. //fseek(f, line_value_bytepos[MyLineNum], SEEK_SET);
  148. return true;
  149. }
  150. int GetFastInt (const char* szVarName, int def, FILE* f)
  151. {
  152. char buf[256];
  153. if (!_GetLineByName(f, szVarName, buf, 255))
  154. return def;
  155. int ret;
  156. if (sscanf(buf, "%d", &ret)==1)
  157. return ret;
  158. return def;
  159. }
  160. float GetFastFloat (const char* szVarName, float def, FILE* f)
  161. {
  162. char buf[256];
  163. if (!_GetLineByName(f, szVarName, buf, 255))
  164. return def;
  165. float ret;
  166. if (_sscanf_l(buf, "%f", g_use_C_locale, &ret)==1)
  167. {
  168. return ret;
  169. }
  170. return def;
  171. }
  172. void GetFastString(const char* szVarName, const char* szDef, char* szRetLine, int nMaxChars, FILE* f)
  173. {
  174. if (_GetLineByName(f, szVarName, szRetLine, nMaxChars-1))
  175. return;
  176. // otherwise, copy the default string, being careful not to overflow dest buf.
  177. // (avoid strncpy because it pads with zeroes all the way out to the max size.)
  178. int x = 0;
  179. while (szDef[x] && x < nMaxChars)
  180. {
  181. szRetLine[x] = szDef[x];
  182. x++;
  183. }
  184. szRetLine[x] = 0;
  185. }
  186. CState::CState()
  187. {
  188. //Default();
  189. // this is the list of variables that can be used for a PER-FRAME calculation;
  190. // it is a SUBSET of the per-vertex calculation variable list.
  191. m_pf_codehandle = NULL;
  192. m_pp_codehandle = NULL;
  193. m_pf_eel = NSEEL_VM_alloc();
  194. m_pv_eel = NSEEL_VM_alloc();
  195. int i = 0;
  196. for (i=0; i<MAX_CUSTOM_WAVES; i++)
  197. {
  198. m_wave[i].m_pf_codehandle = NULL;
  199. m_wave[i].m_pp_codehandle = NULL;
  200. m_wave[i].m_pf_eel=NSEEL_VM_alloc();
  201. m_wave[i].m_pp_eel=NSEEL_VM_alloc();
  202. }
  203. for (i=0; i<MAX_CUSTOM_SHAPES; i++)
  204. {
  205. m_shape[i].m_pf_codehandle = NULL;
  206. m_shape[i].m_pf_eel=NSEEL_VM_alloc();
  207. //m_shape[i].m_pp_codehandle = NULL;
  208. }
  209. //RegisterBuiltInVariables();
  210. }
  211. CState::~CState()
  212. {
  213. FreeVarsAndCode();
  214. NSEEL_VM_free(m_pf_eel);
  215. NSEEL_VM_free(m_pv_eel);
  216. int i = 0;
  217. for (i=0; i<MAX_CUSTOM_WAVES; i++)
  218. {
  219. NSEEL_VM_free(m_wave[i].m_pf_eel);
  220. NSEEL_VM_free(m_wave[i].m_pp_eel);
  221. }
  222. for (i=0; i<MAX_CUSTOM_SHAPES; i++)
  223. {
  224. NSEEL_VM_free(m_shape[i].m_pf_eel);
  225. }
  226. }
  227. //--------------------------------------------------------------------------------
  228. void CState::RegisterBuiltInVariables(int flags)
  229. {
  230. if (flags & RECOMPILE_PRESET_CODE)
  231. {
  232. NSEEL_VM_resetvars(m_pf_eel);
  233. var_pf_zoom = NSEEL_VM_regvar(m_pf_eel, "zoom"); // i/o
  234. var_pf_zoomexp = NSEEL_VM_regvar(m_pf_eel, "zoomexp"); // i/o
  235. var_pf_rot = NSEEL_VM_regvar(m_pf_eel, "rot"); // i/o
  236. var_pf_warp = NSEEL_VM_regvar(m_pf_eel, "warp"); // i/o
  237. var_pf_cx = NSEEL_VM_regvar(m_pf_eel, "cx"); // i/o
  238. var_pf_cy = NSEEL_VM_regvar(m_pf_eel, "cy"); // i/o
  239. var_pf_dx = NSEEL_VM_regvar(m_pf_eel, "dx"); // i/o
  240. var_pf_dy = NSEEL_VM_regvar(m_pf_eel, "dy"); // i/o
  241. var_pf_sx = NSEEL_VM_regvar(m_pf_eel, "sx"); // i/o
  242. var_pf_sy = NSEEL_VM_regvar(m_pf_eel, "sy"); // i/o
  243. var_pf_time = NSEEL_VM_regvar(m_pf_eel, "time"); // i
  244. var_pf_fps = NSEEL_VM_regvar(m_pf_eel, "fps"); // i
  245. var_pf_bass = NSEEL_VM_regvar(m_pf_eel, "bass"); // i
  246. var_pf_mid = NSEEL_VM_regvar(m_pf_eel, "mid"); // i
  247. var_pf_treb = NSEEL_VM_regvar(m_pf_eel, "treb"); // i
  248. var_pf_bass_att = NSEEL_VM_regvar(m_pf_eel, "bass_att"); // i
  249. var_pf_mid_att = NSEEL_VM_regvar(m_pf_eel, "mid_att"); // i
  250. var_pf_treb_att = NSEEL_VM_regvar(m_pf_eel, "treb_att"); // i
  251. var_pf_frame = NSEEL_VM_regvar(m_pf_eel, "frame");
  252. var_pf_decay = NSEEL_VM_regvar(m_pf_eel, "decay");
  253. var_pf_wave_a = NSEEL_VM_regvar(m_pf_eel, "wave_a");
  254. var_pf_wave_r = NSEEL_VM_regvar(m_pf_eel, "wave_r");
  255. var_pf_wave_g = NSEEL_VM_regvar(m_pf_eel, "wave_g");
  256. var_pf_wave_b = NSEEL_VM_regvar(m_pf_eel, "wave_b");
  257. var_pf_wave_x = NSEEL_VM_regvar(m_pf_eel, "wave_x");
  258. var_pf_wave_y = NSEEL_VM_regvar(m_pf_eel, "wave_y");
  259. var_pf_wave_mystery = NSEEL_VM_regvar(m_pf_eel, "wave_mystery");
  260. var_pf_wave_mode = NSEEL_VM_regvar(m_pf_eel, "wave_mode");
  261. int vi = 0;
  262. for (vi=0; vi<NUM_Q_VAR; vi++)
  263. {
  264. char buf[16];
  265. sprintf(buf, "q%d", vi+1);
  266. var_pf_q[vi] = NSEEL_VM_regvar(m_pf_eel, buf);
  267. }
  268. var_pf_progress = NSEEL_VM_regvar(m_pf_eel, "progress");
  269. var_pf_ob_size = NSEEL_VM_regvar(m_pf_eel, "ob_size");
  270. var_pf_ob_r = NSEEL_VM_regvar(m_pf_eel, "ob_r");
  271. var_pf_ob_g = NSEEL_VM_regvar(m_pf_eel, "ob_g");
  272. var_pf_ob_b = NSEEL_VM_regvar(m_pf_eel, "ob_b");
  273. var_pf_ob_a = NSEEL_VM_regvar(m_pf_eel, "ob_a");
  274. var_pf_ib_size = NSEEL_VM_regvar(m_pf_eel, "ib_size");
  275. var_pf_ib_r = NSEEL_VM_regvar(m_pf_eel, "ib_r");
  276. var_pf_ib_g = NSEEL_VM_regvar(m_pf_eel, "ib_g");
  277. var_pf_ib_b = NSEEL_VM_regvar(m_pf_eel, "ib_b");
  278. var_pf_ib_a = NSEEL_VM_regvar(m_pf_eel, "ib_a");
  279. var_pf_mv_x = NSEEL_VM_regvar(m_pf_eel, "mv_x");
  280. var_pf_mv_y = NSEEL_VM_regvar(m_pf_eel, "mv_y");
  281. var_pf_mv_dx = NSEEL_VM_regvar(m_pf_eel, "mv_dx");
  282. var_pf_mv_dy = NSEEL_VM_regvar(m_pf_eel, "mv_dy");
  283. var_pf_mv_l = NSEEL_VM_regvar(m_pf_eel, "mv_l");
  284. var_pf_mv_r = NSEEL_VM_regvar(m_pf_eel, "mv_r");
  285. var_pf_mv_g = NSEEL_VM_regvar(m_pf_eel, "mv_g");
  286. var_pf_mv_b = NSEEL_VM_regvar(m_pf_eel, "mv_b");
  287. var_pf_mv_a = NSEEL_VM_regvar(m_pf_eel, "mv_a");
  288. var_pf_monitor = NSEEL_VM_regvar(m_pf_eel, "monitor");
  289. var_pf_echo_zoom = NSEEL_VM_regvar(m_pf_eel, "echo_zoom");
  290. var_pf_echo_alpha = NSEEL_VM_regvar(m_pf_eel, "echo_alpha");
  291. var_pf_echo_orient = NSEEL_VM_regvar(m_pf_eel, "echo_orient");
  292. var_pf_wave_usedots = NSEEL_VM_regvar(m_pf_eel, "wave_usedots");
  293. var_pf_wave_thick = NSEEL_VM_regvar(m_pf_eel, "wave_thick");
  294. var_pf_wave_additive = NSEEL_VM_regvar(m_pf_eel, "wave_additive");
  295. var_pf_wave_brighten = NSEEL_VM_regvar(m_pf_eel, "wave_brighten");
  296. var_pf_darken_center = NSEEL_VM_regvar(m_pf_eel, "darken_center");
  297. var_pf_gamma = NSEEL_VM_regvar(m_pf_eel, "gamma");
  298. var_pf_wrap = NSEEL_VM_regvar(m_pf_eel, "wrap");
  299. var_pf_invert = NSEEL_VM_regvar(m_pf_eel, "invert");
  300. var_pf_brighten = NSEEL_VM_regvar(m_pf_eel, "brighten");
  301. var_pf_darken = NSEEL_VM_regvar(m_pf_eel, "darken");
  302. var_pf_solarize = NSEEL_VM_regvar(m_pf_eel, "solarize");
  303. var_pf_meshx = NSEEL_VM_regvar(m_pf_eel, "meshx");
  304. var_pf_meshy = NSEEL_VM_regvar(m_pf_eel, "meshy");
  305. var_pf_pixelsx = NSEEL_VM_regvar(m_pf_eel, "pixelsx");
  306. var_pf_pixelsy = NSEEL_VM_regvar(m_pf_eel, "pixelsy");
  307. var_pf_aspectx = NSEEL_VM_regvar(m_pf_eel, "aspectx");
  308. var_pf_aspecty = NSEEL_VM_regvar(m_pf_eel, "aspecty");
  309. var_pf_blur1min = NSEEL_VM_regvar(m_pf_eel, "blur1_min");
  310. var_pf_blur2min = NSEEL_VM_regvar(m_pf_eel, "blur2_min");
  311. var_pf_blur3min = NSEEL_VM_regvar(m_pf_eel, "blur3_min");
  312. var_pf_blur1max = NSEEL_VM_regvar(m_pf_eel, "blur1_max");
  313. var_pf_blur2max = NSEEL_VM_regvar(m_pf_eel, "blur2_max");
  314. var_pf_blur3max = NSEEL_VM_regvar(m_pf_eel, "blur3_max");
  315. var_pf_blur1_edge_darken = NSEEL_VM_regvar(m_pf_eel, "blur1_edge_darken");
  316. // this is the list of variables that can be used for a PER-VERTEX calculation:
  317. // ('vertex' meaning a vertex on the mesh) (as opposed to a once-per-frame calculation)
  318. NSEEL_VM_resetvars(m_pv_eel);
  319. var_pv_zoom = NSEEL_VM_regvar(m_pv_eel, "zoom"); // i/o
  320. var_pv_zoomexp = NSEEL_VM_regvar(m_pv_eel, "zoomexp"); // i/o
  321. var_pv_rot = NSEEL_VM_regvar(m_pv_eel, "rot"); // i/o
  322. var_pv_warp = NSEEL_VM_regvar(m_pv_eel, "warp"); // i/o
  323. var_pv_cx = NSEEL_VM_regvar(m_pv_eel, "cx"); // i/o
  324. var_pv_cy = NSEEL_VM_regvar(m_pv_eel, "cy"); // i/o
  325. var_pv_dx = NSEEL_VM_regvar(m_pv_eel, "dx"); // i/o
  326. var_pv_dy = NSEEL_VM_regvar(m_pv_eel, "dy"); // i/o
  327. var_pv_sx = NSEEL_VM_regvar(m_pv_eel, "sx"); // i/o
  328. var_pv_sy = NSEEL_VM_regvar(m_pv_eel, "sy"); // i/o
  329. var_pv_time = NSEEL_VM_regvar(m_pv_eel, "time"); // i
  330. var_pv_fps = NSEEL_VM_regvar(m_pv_eel, "fps"); // i
  331. var_pv_bass = NSEEL_VM_regvar(m_pv_eel, "bass"); // i
  332. var_pv_mid = NSEEL_VM_regvar(m_pv_eel, "mid"); // i
  333. var_pv_treb = NSEEL_VM_regvar(m_pv_eel, "treb"); // i
  334. var_pv_bass_att = NSEEL_VM_regvar(m_pv_eel, "bass_att"); // i
  335. var_pv_mid_att = NSEEL_VM_regvar(m_pv_eel, "mid_att"); // i
  336. var_pv_treb_att = NSEEL_VM_regvar(m_pv_eel, "treb_att"); // i
  337. var_pv_frame = NSEEL_VM_regvar(m_pv_eel, "frame");
  338. var_pv_x = NSEEL_VM_regvar(m_pv_eel, "x"); // i
  339. var_pv_y = NSEEL_VM_regvar(m_pv_eel, "y"); // i
  340. var_pv_rad = NSEEL_VM_regvar(m_pv_eel, "rad"); // i
  341. var_pv_ang = NSEEL_VM_regvar(m_pv_eel, "ang"); // i
  342. for (vi=0; vi<NUM_Q_VAR; vi++)
  343. {
  344. char buf[16];
  345. sprintf(buf, "q%d", vi+1);
  346. var_pv_q[vi] = NSEEL_VM_regvar(m_pv_eel, buf);
  347. }
  348. var_pv_progress = NSEEL_VM_regvar(m_pv_eel, "progress");
  349. var_pv_meshx = NSEEL_VM_regvar(m_pv_eel, "meshx");
  350. var_pv_meshy = NSEEL_VM_regvar(m_pv_eel, "meshy");
  351. var_pv_pixelsx = NSEEL_VM_regvar(m_pv_eel, "pixelsx");
  352. var_pv_pixelsy = NSEEL_VM_regvar(m_pv_eel, "pixelsy");
  353. var_pv_aspectx = NSEEL_VM_regvar(m_pv_eel, "aspectx");
  354. var_pv_aspecty = NSEEL_VM_regvar(m_pv_eel, "aspecty");
  355. }
  356. if (flags & RECOMPILE_WAVE_CODE)
  357. {
  358. for (int i=0; i<MAX_CUSTOM_WAVES; i++)
  359. {
  360. NSEEL_VM_resetvars(m_wave[i].m_pf_eel);
  361. m_wave[i].var_pf_time = NSEEL_VM_regvar(m_wave[i].m_pf_eel, "time"); // i
  362. m_wave[i].var_pf_fps = NSEEL_VM_regvar(m_wave[i].m_pf_eel, "fps"); // i
  363. m_wave[i].var_pf_frame = NSEEL_VM_regvar(m_wave[i].m_pf_eel, "frame"); // i
  364. m_wave[i].var_pf_progress = NSEEL_VM_regvar(m_wave[i].m_pf_eel, "progress"); // i
  365. int vi = 0;
  366. for (vi=0; vi<NUM_Q_VAR; vi++)
  367. {
  368. char buf[16];
  369. sprintf(buf, "q%d", vi+1);
  370. m_wave[i].var_pf_q[vi] = NSEEL_VM_regvar(m_wave[i].m_pf_eel, buf);
  371. }
  372. for (vi=0; vi<NUM_T_VAR; vi++)
  373. {
  374. char buf[16];
  375. sprintf(buf, "t%d", vi+1);
  376. m_wave[i].var_pf_t[vi] = NSEEL_VM_regvar(m_wave[i].m_pf_eel, buf);
  377. }
  378. m_wave[i].var_pf_bass = NSEEL_VM_regvar(m_wave[i].m_pf_eel, "bass"); // i
  379. m_wave[i].var_pf_mid = NSEEL_VM_regvar(m_wave[i].m_pf_eel, "mid"); // i
  380. m_wave[i].var_pf_treb = NSEEL_VM_regvar(m_wave[i].m_pf_eel, "treb"); // i
  381. m_wave[i].var_pf_bass_att = NSEEL_VM_regvar(m_wave[i].m_pf_eel, "bass_att"); // i
  382. m_wave[i].var_pf_mid_att = NSEEL_VM_regvar(m_wave[i].m_pf_eel, "mid_att"); // i
  383. m_wave[i].var_pf_treb_att = NSEEL_VM_regvar(m_wave[i].m_pf_eel, "treb_att"); // i
  384. m_wave[i].var_pf_r = NSEEL_VM_regvar(m_wave[i].m_pf_eel, "r"); // i/o
  385. m_wave[i].var_pf_g = NSEEL_VM_regvar(m_wave[i].m_pf_eel, "g"); // i/o
  386. m_wave[i].var_pf_b = NSEEL_VM_regvar(m_wave[i].m_pf_eel, "b"); // i/o
  387. m_wave[i].var_pf_a = NSEEL_VM_regvar(m_wave[i].m_pf_eel, "a"); // i/o
  388. m_wave[i].var_pf_samples = NSEEL_VM_regvar(m_wave[i].m_pf_eel, "samples"); // i/o
  389. NSEEL_VM_resetvars(m_wave[i].m_pp_eel);
  390. m_wave[i].var_pp_time = NSEEL_VM_regvar(m_wave[i].m_pp_eel, "time"); // i
  391. m_wave[i].var_pp_fps = NSEEL_VM_regvar(m_wave[i].m_pp_eel, "fps"); // i
  392. m_wave[i].var_pp_frame = NSEEL_VM_regvar(m_wave[i].m_pp_eel, "frame"); // i
  393. m_wave[i].var_pp_progress = NSEEL_VM_regvar(m_wave[i].m_pp_eel, "progress"); // i
  394. for (vi=0; vi<NUM_Q_VAR; vi++)
  395. {
  396. char buf[16];
  397. sprintf(buf, "q%d", vi+1);
  398. m_wave[i].var_pp_q[vi] = NSEEL_VM_regvar(m_wave[i].m_pp_eel, buf);
  399. }
  400. for (vi=0; vi<NUM_T_VAR; vi++)
  401. {
  402. char buf[16];
  403. sprintf(buf, "t%d", vi+1);
  404. m_wave[i].var_pp_t[vi] = NSEEL_VM_regvar(m_wave[i].m_pp_eel, buf);
  405. }
  406. m_wave[i].var_pp_bass = NSEEL_VM_regvar(m_wave[i].m_pp_eel, "bass"); // i
  407. m_wave[i].var_pp_mid = NSEEL_VM_regvar(m_wave[i].m_pp_eel, "mid"); // i
  408. m_wave[i].var_pp_treb = NSEEL_VM_regvar(m_wave[i].m_pp_eel, "treb"); // i
  409. m_wave[i].var_pp_bass_att = NSEEL_VM_regvar(m_wave[i].m_pp_eel, "bass_att"); // i
  410. m_wave[i].var_pp_mid_att = NSEEL_VM_regvar(m_wave[i].m_pp_eel, "mid_att"); // i
  411. m_wave[i].var_pp_treb_att = NSEEL_VM_regvar(m_wave[i].m_pp_eel, "treb_att"); // i
  412. m_wave[i].var_pp_sample = NSEEL_VM_regvar(m_wave[i].m_pp_eel, "sample"); // i
  413. m_wave[i].var_pp_value1 = NSEEL_VM_regvar(m_wave[i].m_pp_eel, "value1"); // i
  414. m_wave[i].var_pp_value2 = NSEEL_VM_regvar(m_wave[i].m_pp_eel, "value2"); // i
  415. m_wave[i].var_pp_x = NSEEL_VM_regvar(m_wave[i].m_pp_eel, "x"); // i/o
  416. m_wave[i].var_pp_y = NSEEL_VM_regvar(m_wave[i].m_pp_eel, "y"); // i/o
  417. m_wave[i].var_pp_r = NSEEL_VM_regvar(m_wave[i].m_pp_eel, "r"); // i/o
  418. m_wave[i].var_pp_g = NSEEL_VM_regvar(m_wave[i].m_pp_eel, "g"); // i/o
  419. m_wave[i].var_pp_b = NSEEL_VM_regvar(m_wave[i].m_pp_eel, "b"); // i/o
  420. m_wave[i].var_pp_a = NSEEL_VM_regvar(m_wave[i].m_pp_eel, "a"); // i/o
  421. }
  422. }
  423. if (flags & RECOMPILE_SHAPE_CODE)
  424. {
  425. for (int i=0; i<MAX_CUSTOM_SHAPES; i++)
  426. {
  427. NSEEL_VM_resetvars(m_shape[i].m_pf_eel);
  428. m_shape[i].var_pf_time = NSEEL_VM_regvar(m_shape[i].m_pf_eel, "time"); // i
  429. m_shape[i].var_pf_fps = NSEEL_VM_regvar(m_shape[i].m_pf_eel, "fps"); // i
  430. m_shape[i].var_pf_frame = NSEEL_VM_regvar(m_shape[i].m_pf_eel, "frame"); // i
  431. m_shape[i].var_pf_progress = NSEEL_VM_regvar(m_shape[i].m_pf_eel, "progress"); // i
  432. int vi = 0;
  433. for (vi=0; vi<NUM_Q_VAR; vi++)
  434. {
  435. char buf[16];
  436. sprintf(buf, "q%d", vi+1);
  437. m_shape[i].var_pf_q[vi] = NSEEL_VM_regvar(m_shape[i].m_pf_eel, buf);
  438. }
  439. for (vi=0; vi<NUM_T_VAR; vi++)
  440. {
  441. char buf[16];
  442. sprintf(buf, "t%d", vi+1);
  443. m_shape[i].var_pf_t[vi] = NSEEL_VM_regvar(m_shape[i].m_pf_eel, buf);
  444. }
  445. m_shape[i].var_pf_bass = NSEEL_VM_regvar(m_shape[i].m_pf_eel, "bass"); // i
  446. m_shape[i].var_pf_mid = NSEEL_VM_regvar(m_shape[i].m_pf_eel, "mid"); // i
  447. m_shape[i].var_pf_treb = NSEEL_VM_regvar(m_shape[i].m_pf_eel, "treb"); // i
  448. m_shape[i].var_pf_bass_att = NSEEL_VM_regvar(m_shape[i].m_pf_eel, "bass_att"); // i
  449. m_shape[i].var_pf_mid_att = NSEEL_VM_regvar(m_shape[i].m_pf_eel, "mid_att"); // i
  450. m_shape[i].var_pf_treb_att = NSEEL_VM_regvar(m_shape[i].m_pf_eel, "treb_att"); // i
  451. m_shape[i].var_pf_x = NSEEL_VM_regvar(m_shape[i].m_pf_eel, "x"); // i/o
  452. m_shape[i].var_pf_y = NSEEL_VM_regvar(m_shape[i].m_pf_eel, "y"); // i/o
  453. m_shape[i].var_pf_rad = NSEEL_VM_regvar(m_shape[i].m_pf_eel, "rad"); // i/o
  454. m_shape[i].var_pf_ang = NSEEL_VM_regvar(m_shape[i].m_pf_eel, "ang"); // i/o
  455. m_shape[i].var_pf_tex_ang = NSEEL_VM_regvar(m_shape[i].m_pf_eel, "tex_ang"); // i/o
  456. m_shape[i].var_pf_tex_zoom = NSEEL_VM_regvar(m_shape[i].m_pf_eel, "tex_zoom"); // i/o
  457. m_shape[i].var_pf_sides = NSEEL_VM_regvar(m_shape[i].m_pf_eel, "sides"); // i/o
  458. m_shape[i].var_pf_textured = NSEEL_VM_regvar(m_shape[i].m_pf_eel, "textured"); // i/o
  459. m_shape[i].var_pf_instance = NSEEL_VM_regvar(m_shape[i].m_pf_eel, "instance"); // i/o
  460. m_shape[i].var_pf_instances = NSEEL_VM_regvar(m_shape[i].m_pf_eel, "num_inst"); // i/o
  461. m_shape[i].var_pf_additive = NSEEL_VM_regvar(m_shape[i].m_pf_eel, "additive"); // i/o
  462. m_shape[i].var_pf_thick = NSEEL_VM_regvar(m_shape[i].m_pf_eel, "thick"); // i/o
  463. m_shape[i].var_pf_r = NSEEL_VM_regvar(m_shape[i].m_pf_eel, "r"); // i/o
  464. m_shape[i].var_pf_g = NSEEL_VM_regvar(m_shape[i].m_pf_eel, "g"); // i/o
  465. m_shape[i].var_pf_b = NSEEL_VM_regvar(m_shape[i].m_pf_eel, "b"); // i/o
  466. m_shape[i].var_pf_a = NSEEL_VM_regvar(m_shape[i].m_pf_eel, "a"); // i/o
  467. m_shape[i].var_pf_r2 = NSEEL_VM_regvar(m_shape[i].m_pf_eel, "r2"); // i/o
  468. m_shape[i].var_pf_g2 = NSEEL_VM_regvar(m_shape[i].m_pf_eel, "g2"); // i/o
  469. m_shape[i].var_pf_b2 = NSEEL_VM_regvar(m_shape[i].m_pf_eel, "b2"); // i/o
  470. m_shape[i].var_pf_a2 = NSEEL_VM_regvar(m_shape[i].m_pf_eel, "a2"); // i/o
  471. m_shape[i].var_pf_border_r = NSEEL_VM_regvar(m_shape[i].m_pf_eel, "border_r"); // i/o
  472. m_shape[i].var_pf_border_g = NSEEL_VM_regvar(m_shape[i].m_pf_eel, "border_g"); // i/o
  473. m_shape[i].var_pf_border_b = NSEEL_VM_regvar(m_shape[i].m_pf_eel, "border_b"); // i/o
  474. m_shape[i].var_pf_border_a = NSEEL_VM_regvar(m_shape[i].m_pf_eel, "border_a"); // i/o
  475. }
  476. }
  477. }
  478. void CState::Default(DWORD ApplyFlags)
  479. {
  480. // DON'T FORGET TO ADD NEW VARIABLES TO BLEND FUNCTION, IMPORT, and EXPORT AS WELL!!!!!!!!
  481. if ( (ApplyFlags & STATE_GENERAL) && // check for these 3 @ same time,
  482. (ApplyFlags & STATE_MOTION) && // so a preset switch w/ warp/comp lock
  483. (ApplyFlags & STATE_WAVE) // updates the name, but mash-ups don't.
  484. )
  485. {
  486. lstrcpyW(m_szDesc, INVALID_PRESET_DESC);
  487. //lstrcpy(m_szSection, "n/a");
  488. m_fPresetStartTime = -1;
  489. }
  490. m_nMinPSVersion = 0;
  491. m_nMaxPSVersion = 0;
  492. m_bBlending = false;
  493. // general:
  494. if (ApplyFlags & STATE_GENERAL)
  495. {
  496. m_fRating = 3.0f;
  497. m_fDecay = 0.98f; // 1.0 = none, 0.95 = heavy decay
  498. m_fGammaAdj = 2.0f; // 1.0 = reg; +2.0 = double, +3.0 = triple...
  499. m_fVideoEchoZoom = 2.0f;
  500. m_fVideoEchoAlpha = 0.0f;
  501. m_nVideoEchoOrientation = 0; // 0-3
  502. m_bRedBlueStereo = false;
  503. m_bBrighten = false;
  504. m_bDarken = false;
  505. m_bTexWrap = true;
  506. m_bDarkenCenter = false;
  507. m_bSolarize = false;
  508. m_bInvert = false;
  509. m_fShader = 0.0f;
  510. m_fBlur1Min = 0.0f;
  511. m_fBlur2Min = 0.0f;
  512. m_fBlur3Min = 0.0f;
  513. m_fBlur1Max = 1.0f;
  514. m_fBlur2Max = 1.0f;
  515. m_fBlur3Max = 1.0f;
  516. m_fBlur1EdgeDarken = 0.25f;
  517. }
  518. // wave:
  519. if (ApplyFlags & STATE_WAVE)
  520. {
  521. m_nWaveMode = 0;
  522. m_nOldWaveMode = -1;
  523. m_bAdditiveWaves = false;
  524. m_bWaveDots = false;
  525. m_bWaveThick = false;
  526. m_fWaveAlpha = 0.8f;
  527. m_fWaveScale = 1.0f;
  528. m_fWaveSmoothing = 0.75f; // 0 = no smoothing, 0.9 = HEAVY smoothing
  529. m_fWaveParam = 0.0f;
  530. m_bModWaveAlphaByVolume = false;
  531. m_fModWaveAlphaStart = 0.75f; // when relative volume hits this level, alpha -> 0
  532. m_fModWaveAlphaEnd = 0.95f; // when relative volume hits this level, alpha -> 1
  533. m_fWaveR = 1.0f;
  534. m_fWaveG = 1.0f;
  535. m_fWaveB = 1.0f;
  536. m_fWaveX = 0.5f;
  537. m_fWaveY = 0.5f;
  538. m_bMaximizeWaveColor = true;
  539. m_fMvX = 12.0f;
  540. m_fMvY = 9.0f;
  541. m_fMvDX = 0.0f;
  542. m_fMvDY = 0.0f;
  543. m_fMvL = 0.9f;
  544. m_fMvR = 1.0f;
  545. m_fMvG = 1.0f;
  546. m_fMvB = 1.0f;
  547. m_fMvA = 1.0f;
  548. int i = 0;
  549. for (i=0; i<MAX_CUSTOM_WAVES; i++)
  550. {
  551. m_wave[i].enabled = 0;
  552. m_wave[i].samples = 512;
  553. m_wave[i].sep = 0;
  554. m_wave[i].scaling = 1.0f;
  555. m_wave[i].smoothing = 0.5f;
  556. m_wave[i].r = 1.0f;
  557. m_wave[i].g = 1.0f;
  558. m_wave[i].b = 1.0f;
  559. m_wave[i].a = 1.0f;
  560. m_wave[i].bSpectrum = 0;
  561. m_wave[i].bUseDots = 0;
  562. m_wave[i].bDrawThick = 0;
  563. m_wave[i].bAdditive = 0;
  564. }
  565. for (i=0; i<MAX_CUSTOM_SHAPES; i++)
  566. {
  567. m_shape[i].enabled = 0;
  568. m_shape[i].sides = 4;
  569. m_shape[i].additive = 0;
  570. m_shape[i].thickOutline = 0;
  571. m_shape[i].textured = 0;
  572. m_shape[i].instances = 1;
  573. m_shape[i].tex_zoom = 1.0f;
  574. m_shape[i].tex_ang = 0.0f;
  575. m_shape[i].x = 0.5f;
  576. m_shape[i].y = 0.5f;
  577. m_shape[i].rad = 0.1f;
  578. m_shape[i].ang = 0.0f;
  579. m_shape[i].r = 1.0f;
  580. m_shape[i].g = 0.0f;
  581. m_shape[i].b = 0.0f;
  582. m_shape[i].a = 1.0f;
  583. m_shape[i].r2 = 0.0f;
  584. m_shape[i].g2 = 1.0f;
  585. m_shape[i].b2 = 0.0f;
  586. m_shape[i].a2 = 0.0f;
  587. m_shape[i].border_r = 1.0f;
  588. m_shape[i].border_g = 1.0f;
  589. m_shape[i].border_b = 1.0f;
  590. m_shape[i].border_a = 0.1f;
  591. }
  592. for (i=0; i<MAX_CUSTOM_WAVES; i++)
  593. {
  594. m_wave[i].m_szInit[0] = 0;
  595. m_wave[i].m_szPerFrame[0] = 0;
  596. m_wave[i].m_szPerPoint[0] = 0;
  597. }
  598. for (i=0; i<MAX_CUSTOM_SHAPES; i++)
  599. {
  600. m_shape[i].m_szInit[0] = 0;
  601. m_shape[i].m_szPerFrame[0] = 0;
  602. //m_shape[i].m_szPerPoint[0] = 0;
  603. }
  604. }
  605. // motion:
  606. if (ApplyFlags & STATE_MOTION)
  607. {
  608. m_fWarpAnimSpeed = 1.0f; // additional timescaling for warp animation
  609. m_fWarpScale = 1.0f;
  610. m_fZoomExponent = 1.0f;
  611. m_fZoom = 1.0f;
  612. m_fRot = 0.0f;
  613. m_fRotCX = 0.5f;
  614. m_fRotCY = 0.5f;
  615. m_fXPush = 0.0f;
  616. m_fYPush = 0.0f;
  617. m_fWarpAmount = 1.0f;
  618. m_fStretchX = 1.0f;
  619. m_fStretchY = 1.0f;
  620. m_fOuterBorderSize = 0.01f;
  621. m_fOuterBorderR = 0.0f;
  622. m_fOuterBorderG = 0.0f;
  623. m_fOuterBorderB = 0.0f;
  624. m_fOuterBorderA = 0.0f;
  625. m_fInnerBorderSize = 0.01f;
  626. m_fInnerBorderR = 0.25f;
  627. m_fInnerBorderG = 0.25f;
  628. m_fInnerBorderB = 0.25f;
  629. m_fInnerBorderA = 0.0f;
  630. // clear all code strings:
  631. m_szPerFrameInit[0] = 0;
  632. m_szPerFrameExpr[0] = 0;
  633. m_szPerPixelExpr[0] = 0;
  634. }
  635. // DON'T FORGET TO ADD NEW VARIABLES TO BLEND FUNCTION, IMPORT, and EXPORT AS WELL!!!!!!!!
  636. // ALSO BE SURE TO REGISTER THEM ON THE MAIN MENU (SEE MILKDROP.CPP)
  637. // warp shader
  638. if (ApplyFlags & STATE_WARP)
  639. {
  640. m_szWarpShadersText[0] = 0;
  641. m_nWarpPSVersion = 0;
  642. }
  643. // comp shader
  644. if (ApplyFlags & STATE_COMP)
  645. {
  646. m_szCompShadersText[0] = 0;
  647. m_nCompPSVersion = 0;
  648. }
  649. RandomizePresetVars();
  650. FreeVarsAndCode();
  651. }
  652. void CState::StartBlendFrom(CState *s_from, float fAnimTime, float fTimespan)
  653. {
  654. CState *s_to = this;
  655. // bools, ints, and strings instantly change
  656. s_to->m_fVideoEchoAlphaOld = s_from->m_fVideoEchoAlpha.eval(-1);
  657. s_to->m_nVideoEchoOrientationOld = s_from->m_nVideoEchoOrientation;
  658. s_to->m_nOldWaveMode = s_from->m_nWaveMode;
  659. /*
  660. s_to->m_fVideoEchoAlphaOld = s_from->m_fVideoEchoAlpha.eval(-1);
  661. s_to->m_nVideoEchoOrientationOld = s_from->m_nVideoEchoOrientation;
  662. s_to->m_nOldWaveMode = s_from->m_nWaveMode;
  663. s_to->m_nWaveMode = s_from->m_nWaveMode;
  664. s_to->m_bAdditiveWaves = s_from->m_bAdditiveWaves;
  665. s_to->m_nVideoEchoOrientation = s_from->m_nVideoEchoOrientation;
  666. s_to->m_fWarpAnimSpeed = s_from->m_fWarpAnimSpeed; // would req. 10 phase-matches to blend this one!!!
  667. s_to->m_bWaveDots = s_from->m_bWaveDots;
  668. s_to->m_bWaveThick = s_from->m_bWaveThick;
  669. s_to->m_bModWaveAlphaByVolume = s_from->m_bModWaveAlphaByVolume;
  670. s_to->m_bMaximizeWaveColor = s_from->m_bMaximizeWaveColor;
  671. s_to->m_bTexWrap = s_from->m_bTexWrap;
  672. s_to->m_bDarkenCenter = s_from->m_bDarkenCenter;
  673. s_to->m_bRedBlueStereo = s_from->m_bRedBlueStereo;
  674. s_to->m_bBrighten = s_from->m_bBrighten;
  675. s_to->m_bDarken = s_from->m_bDarken;
  676. s_to->m_bSolarize = s_from->m_bSolarize;
  677. s_to->m_bInvert = s_from->m_bInvert;
  678. s_to->m_fRating = s_from->m_fRating;
  679. */
  680. // expr. eval. also copies over immediately (replaces prev.)
  681. m_bBlending = true;
  682. m_fBlendStartTime = fAnimTime;
  683. m_fBlendDuration = fTimespan;
  684. /*
  685. //for (int e=0; e<MAX_EVALS; e++)
  686. {
  687. char szTemp[MAX_BIGSTRING_LEN];
  688. lstrcpy(szTemp, m_szPerFrameExpr);
  689. lstrcpy(m_szPerFrameExpr, s_to->m_szPerFrameExpr);
  690. lstrcpy(s_to->m_szPerFrameExpr, szTemp);
  691. lstrcpy(szTemp, m_szPerPixelExpr);
  692. lstrcpy(m_szPerPixelExpr, s_to->m_szPerPixelExpr);
  693. lstrcpy(s_to->m_szPerPixelExpr, szTemp);
  694. lstrcpy(szTemp, m_szPerFrameInit);
  695. lstrcpy(m_szPerFrameInit, s_to->m_szPerFrameInit);
  696. lstrcpy(s_to->m_szPerFrameInit, szTemp);
  697. }
  698. RecompileExpressions();
  699. s_to->RecompileExpressions();
  700. lstrcpy(m_szDesc, s_to->m_szDesc);
  701. //lstrcpy(m_szSection, s_to->m_szSection);
  702. */
  703. // CBlendableFloats & SuperValues blend over time
  704. m_fGammaAdj .StartBlendFrom(&s_from->m_fGammaAdj , fAnimTime, fTimespan);
  705. m_fVideoEchoZoom .StartBlendFrom(&s_from->m_fVideoEchoZoom , fAnimTime, fTimespan);
  706. m_fVideoEchoAlpha.StartBlendFrom(&s_from->m_fVideoEchoAlpha, fAnimTime, fTimespan);
  707. m_fDecay .StartBlendFrom(&s_from->m_fDecay , fAnimTime, fTimespan);
  708. m_fWaveAlpha .StartBlendFrom(&s_from->m_fWaveAlpha , fAnimTime, fTimespan);
  709. m_fWaveScale .StartBlendFrom(&s_from->m_fWaveScale , fAnimTime, fTimespan);
  710. m_fWaveSmoothing .StartBlendFrom(&s_from->m_fWaveSmoothing , fAnimTime, fTimespan);
  711. m_fWaveParam .StartBlendFrom(&s_from->m_fWaveParam , fAnimTime, fTimespan);
  712. m_fWarpScale .StartBlendFrom(&s_from->m_fWarpScale , fAnimTime, fTimespan);
  713. m_fZoomExponent .StartBlendFrom(&s_from->m_fZoomExponent , fAnimTime, fTimespan);
  714. m_fShader .StartBlendFrom(&s_from->m_fShader , fAnimTime, fTimespan);
  715. m_fModWaveAlphaStart.StartBlendFrom(&s_from->m_fModWaveAlphaStart, fAnimTime, fTimespan);
  716. m_fModWaveAlphaEnd .StartBlendFrom(&s_from->m_fModWaveAlphaEnd, fAnimTime, fTimespan);
  717. m_fZoom .StartBlendFrom(&s_from->m_fZoom , fAnimTime, fTimespan);
  718. m_fRot .StartBlendFrom(&s_from->m_fRot , fAnimTime, fTimespan);
  719. m_fRotCX .StartBlendFrom(&s_from->m_fRotCX , fAnimTime, fTimespan);
  720. m_fRotCY .StartBlendFrom(&s_from->m_fRotCY , fAnimTime, fTimespan);
  721. m_fXPush .StartBlendFrom(&s_from->m_fXPush , fAnimTime, fTimespan);
  722. m_fYPush .StartBlendFrom(&s_from->m_fYPush , fAnimTime, fTimespan);
  723. m_fWarpAmount.StartBlendFrom(&s_from->m_fWarpAmount,fAnimTime, fTimespan);
  724. m_fStretchX .StartBlendFrom(&s_from->m_fStretchX , fAnimTime, fTimespan);
  725. m_fStretchY .StartBlendFrom(&s_from->m_fStretchY , fAnimTime, fTimespan);
  726. m_fWaveR .StartBlendFrom(&s_from->m_fWaveR , fAnimTime, fTimespan);
  727. m_fWaveG .StartBlendFrom(&s_from->m_fWaveG , fAnimTime, fTimespan);
  728. m_fWaveB .StartBlendFrom(&s_from->m_fWaveB , fAnimTime, fTimespan);
  729. m_fWaveX .StartBlendFrom(&s_from->m_fWaveX , fAnimTime, fTimespan);
  730. m_fWaveY .StartBlendFrom(&s_from->m_fWaveY , fAnimTime, fTimespan);
  731. m_fOuterBorderSize .StartBlendFrom(&s_from->m_fOuterBorderSize , fAnimTime, fTimespan);
  732. m_fOuterBorderR .StartBlendFrom(&s_from->m_fOuterBorderR , fAnimTime, fTimespan);
  733. m_fOuterBorderG .StartBlendFrom(&s_from->m_fOuterBorderG , fAnimTime, fTimespan);
  734. m_fOuterBorderB .StartBlendFrom(&s_from->m_fOuterBorderB , fAnimTime, fTimespan);
  735. m_fOuterBorderA .StartBlendFrom(&s_from->m_fOuterBorderA , fAnimTime, fTimespan);
  736. m_fInnerBorderSize .StartBlendFrom(&s_from->m_fInnerBorderSize , fAnimTime, fTimespan);
  737. m_fInnerBorderR .StartBlendFrom(&s_from->m_fInnerBorderR , fAnimTime, fTimespan);
  738. m_fInnerBorderG .StartBlendFrom(&s_from->m_fInnerBorderG , fAnimTime, fTimespan);
  739. m_fInnerBorderB .StartBlendFrom(&s_from->m_fInnerBorderB , fAnimTime, fTimespan);
  740. m_fInnerBorderA .StartBlendFrom(&s_from->m_fInnerBorderA , fAnimTime, fTimespan);
  741. m_fMvX .StartBlendFrom(&s_from->m_fMvX , fAnimTime, fTimespan);
  742. m_fMvY .StartBlendFrom(&s_from->m_fMvY , fAnimTime, fTimespan);
  743. m_fMvDX .StartBlendFrom(&s_from->m_fMvDX , fAnimTime, fTimespan);
  744. m_fMvDY .StartBlendFrom(&s_from->m_fMvDY , fAnimTime, fTimespan);
  745. m_fMvL .StartBlendFrom(&s_from->m_fMvL , fAnimTime, fTimespan);
  746. m_fMvR .StartBlendFrom(&s_from->m_fMvR , fAnimTime, fTimespan);
  747. m_fMvG .StartBlendFrom(&s_from->m_fMvG , fAnimTime, fTimespan);
  748. m_fMvB .StartBlendFrom(&s_from->m_fMvB , fAnimTime, fTimespan);
  749. m_fMvA .StartBlendFrom(&s_from->m_fMvA , fAnimTime, fTimespan);
  750. m_fBlur1Min .StartBlendFrom(&s_from->m_fBlur1Min , fAnimTime, fTimespan);
  751. m_fBlur2Min .StartBlendFrom(&s_from->m_fBlur2Min , fAnimTime, fTimespan);
  752. m_fBlur3Min .StartBlendFrom(&s_from->m_fBlur3Min , fAnimTime, fTimespan);
  753. m_fBlur1Max .StartBlendFrom(&s_from->m_fBlur1Max , fAnimTime, fTimespan);
  754. m_fBlur2Max .StartBlendFrom(&s_from->m_fBlur2Max , fAnimTime, fTimespan);
  755. m_fBlur3Max .StartBlendFrom(&s_from->m_fBlur3Max , fAnimTime, fTimespan);
  756. m_fBlur1EdgeDarken .StartBlendFrom(&s_from->m_fBlur1EdgeDarken , fAnimTime, fTimespan);
  757. // if motion vectors were transparent before, don't morph the # in X and Y - just
  758. // start in the right place, and fade them in.
  759. bool bOldStateTransparent = (s_from->m_fMvA.eval(-1) < 0.001f);
  760. bool bNewStateTransparent = (s_to->m_fMvA.eval(-1) < 0.001f);
  761. if (!bOldStateTransparent && bNewStateTransparent)
  762. {
  763. s_from->m_fMvX = s_to->m_fMvX.eval(fAnimTime);
  764. s_from->m_fMvY = s_to->m_fMvY.eval(fAnimTime);
  765. s_from->m_fMvDX = s_to->m_fMvDX.eval(fAnimTime);
  766. s_from->m_fMvDY = s_to->m_fMvDY.eval(fAnimTime);
  767. s_from->m_fMvL = s_to->m_fMvL.eval(fAnimTime);
  768. s_from->m_fMvR = s_to->m_fMvR.eval(fAnimTime);
  769. s_from->m_fMvG = s_to->m_fMvG.eval(fAnimTime);
  770. s_from->m_fMvB = s_to->m_fMvB.eval(fAnimTime);
  771. }
  772. if (bNewStateTransparent && !bOldStateTransparent)
  773. {
  774. s_to->m_fMvX = s_from->m_fMvX.eval(fAnimTime);
  775. s_to->m_fMvY = s_from->m_fMvY.eval(fAnimTime);
  776. s_to->m_fMvDX = s_from->m_fMvDX.eval(fAnimTime);
  777. s_to->m_fMvDY = s_from->m_fMvDY.eval(fAnimTime);
  778. s_to->m_fMvL = s_from->m_fMvL.eval(fAnimTime);
  779. s_to->m_fMvR = s_from->m_fMvR.eval(fAnimTime);
  780. s_to->m_fMvG = s_from->m_fMvG.eval(fAnimTime);
  781. s_to->m_fMvB = s_from->m_fMvB.eval(fAnimTime);
  782. }
  783. }
  784. void WriteCode(FILE* fOut, int i, char* pStr, char* prefix, bool bPrependApostrophe = false)
  785. {
  786. char szLineName[32];
  787. int line = 1;
  788. int start_pos = 0;
  789. int char_pos = 0;
  790. while (pStr[start_pos] != 0)
  791. {
  792. while ( pStr[char_pos] != 0 &&
  793. pStr[char_pos] != LINEFEED_CONTROL_CHAR)
  794. char_pos++;
  795. sprintf(szLineName, "%s%d", prefix, line);
  796. char ch = pStr[char_pos];
  797. pStr[char_pos] = 0;
  798. //if (!WritePrivateProfileString(szSectionName,szLineName,&pStr[start_pos],szIniFile)) return false;
  799. fprintf(fOut, "%s=%s%s\n", szLineName, bPrependApostrophe ? "`" : "", &pStr[start_pos]);
  800. pStr[char_pos] = ch;
  801. if (pStr[char_pos] != 0) char_pos++;
  802. start_pos = char_pos;
  803. line++;
  804. }
  805. }
  806. bool CState::Export(const wchar_t *szIniFile)
  807. {
  808. FILE *fOut = _wfopen(szIniFile, L"w");
  809. if (!fOut) return false;
  810. // IMPORTANT: THESE MUST BE THE FIRST TWO LINES. Otherwise it is assumed to be a MilkDrop 1-era preset.
  811. if (m_nMaxPSVersion > 0)
  812. {
  813. fprintf(fOut, "MILKDROP_PRESET_VERSION=%d\n", CUR_MILKDROP_PRESET_VERSION);
  814. fprintf(fOut, "PSVERSION=%d\n" ,m_nMaxPSVersion); // the max
  815. fprintf(fOut, "PSVERSION_WARP=%d\n",m_nWarpPSVersion);
  816. fprintf(fOut, "PSVERSION_COMP=%d\n",m_nCompPSVersion);
  817. }
  818. // just for backwards compatibility; MilkDrop 1 can read MilkDrop 2 presets, minus the new features.
  819. // (...this section name allows the GetPrivateProfile*() functions to still work on milkdrop 1)
  820. fprintf(fOut, "[preset00]\n");
  821. fprintf(fOut, "%s=%.3f\n", "fRating", m_fRating);
  822. fprintf(fOut, "%s=%.3f\n", "fGammaAdj", m_fGammaAdj.eval(-1));
  823. fprintf(fOut, "%s=%.3f\n", "fDecay", m_fDecay.eval(-1));
  824. fprintf(fOut, "%s=%.3f\n", "fVideoEchoZoom", m_fVideoEchoZoom.eval(-1));
  825. fprintf(fOut, "%s=%.3f\n", "fVideoEchoAlpha", m_fVideoEchoAlpha.eval(-1));
  826. fprintf(fOut, "%s=%d\n", "nVideoEchoOrientation", m_nVideoEchoOrientation);
  827. fprintf(fOut, "%s=%d\n", "nWaveMode", m_nWaveMode);
  828. fprintf(fOut, "%s=%d\n", "bAdditiveWaves", m_bAdditiveWaves);
  829. fprintf(fOut, "%s=%d\n", "bWaveDots", m_bWaveDots);
  830. fprintf(fOut, "%s=%d\n", "bWaveThick", m_bWaveThick);
  831. fprintf(fOut, "%s=%d\n", "bModWaveAlphaByVolume", m_bModWaveAlphaByVolume);
  832. fprintf(fOut, "%s=%d\n", "bMaximizeWaveColor", m_bMaximizeWaveColor);
  833. fprintf(fOut, "%s=%d\n", "bTexWrap", m_bTexWrap );
  834. fprintf(fOut, "%s=%d\n", "bDarkenCenter", m_bDarkenCenter );
  835. fprintf(fOut, "%s=%d\n", "bRedBlueStereo", m_bRedBlueStereo );
  836. fprintf(fOut, "%s=%d\n", "bBrighten", m_bBrighten );
  837. fprintf(fOut, "%s=%d\n", "bDarken", m_bDarken );
  838. fprintf(fOut, "%s=%d\n", "bSolarize", m_bSolarize );
  839. fprintf(fOut, "%s=%d\n", "bInvert", m_bInvert );
  840. fprintf(fOut, "%s=%.3f\n", "fWaveAlpha", m_fWaveAlpha.eval(-1));
  841. fprintf(fOut, "%s=%.3f\n", "fWaveScale", m_fWaveScale.eval(-1));
  842. fprintf(fOut, "%s=%.3f\n", "fWaveSmoothing", m_fWaveSmoothing.eval(-1));
  843. fprintf(fOut, "%s=%.3f\n", "fWaveParam", m_fWaveParam.eval(-1));
  844. fprintf(fOut, "%s=%.3f\n", "fModWaveAlphaStart", m_fModWaveAlphaStart.eval(-1));
  845. fprintf(fOut, "%s=%.3f\n", "fModWaveAlphaEnd", m_fModWaveAlphaEnd.eval(-1));
  846. fprintf(fOut, "%s=%.3f\n", "fWarpAnimSpeed", m_fWarpAnimSpeed);
  847. fprintf(fOut, "%s=%.3f\n", "fWarpScale", m_fWarpScale.eval(-1));
  848. fprintf(fOut, "%s=%.5f\n", "fZoomExponent", m_fZoomExponent.eval(-1));
  849. fprintf(fOut, "%s=%.3f\n", "fShader", m_fShader.eval(-1));
  850. fprintf(fOut, "%s=%.5f\n", "zoom", m_fZoom .eval(-1));
  851. fprintf(fOut, "%s=%.5f\n", "rot", m_fRot .eval(-1));
  852. fprintf(fOut, "%s=%.3f\n", "cx", m_fRotCX .eval(-1));
  853. fprintf(fOut, "%s=%.3f\n", "cy", m_fRotCY .eval(-1));
  854. fprintf(fOut, "%s=%.5f\n", "dx", m_fXPush .eval(-1));
  855. fprintf(fOut, "%s=%.5f\n", "dy", m_fYPush .eval(-1));
  856. fprintf(fOut, "%s=%.5f\n", "warp", m_fWarpAmount.eval(-1));
  857. fprintf(fOut, "%s=%.5f\n", "sx", m_fStretchX .eval(-1));
  858. fprintf(fOut, "%s=%.5f\n", "sy", m_fStretchY .eval(-1));
  859. fprintf(fOut, "%s=%.3f\n", "wave_r", m_fWaveR .eval(-1));
  860. fprintf(fOut, "%s=%.3f\n", "wave_g", m_fWaveG .eval(-1));
  861. fprintf(fOut, "%s=%.3f\n", "wave_b", m_fWaveB .eval(-1));
  862. fprintf(fOut, "%s=%.3f\n", "wave_x", m_fWaveX .eval(-1));
  863. fprintf(fOut, "%s=%.3f\n", "wave_y", m_fWaveY .eval(-1));
  864. fprintf(fOut, "%s=%.3f\n", "ob_size", m_fOuterBorderSize.eval(-1));
  865. fprintf(fOut, "%s=%.3f\n", "ob_r", m_fOuterBorderR.eval(-1));
  866. fprintf(fOut, "%s=%.3f\n", "ob_g", m_fOuterBorderG.eval(-1));
  867. fprintf(fOut, "%s=%.3f\n", "ob_b", m_fOuterBorderB.eval(-1));
  868. fprintf(fOut, "%s=%.3f\n", "ob_a", m_fOuterBorderA.eval(-1));
  869. fprintf(fOut, "%s=%.3f\n", "ib_size", m_fInnerBorderSize.eval(-1));
  870. fprintf(fOut, "%s=%.3f\n", "ib_r", m_fInnerBorderR.eval(-1));
  871. fprintf(fOut, "%s=%.3f\n", "ib_g", m_fInnerBorderG.eval(-1));
  872. fprintf(fOut, "%s=%.3f\n", "ib_b", m_fInnerBorderB.eval(-1));
  873. fprintf(fOut, "%s=%.3f\n", "ib_a", m_fInnerBorderA.eval(-1));
  874. fprintf(fOut, "%s=%.3f\n", "nMotionVectorsX", m_fMvX.eval(-1));
  875. fprintf(fOut, "%s=%.3f\n", "nMotionVectorsY", m_fMvY.eval(-1));
  876. fprintf(fOut, "%s=%.3f\n", "mv_dx", m_fMvDX.eval(-1));
  877. fprintf(fOut, "%s=%.3f\n", "mv_dy", m_fMvDY.eval(-1));
  878. fprintf(fOut, "%s=%.3f\n", "mv_l", m_fMvL.eval(-1));
  879. fprintf(fOut, "%s=%.3f\n", "mv_r", m_fMvR.eval(-1));
  880. fprintf(fOut, "%s=%.3f\n", "mv_g", m_fMvG.eval(-1));
  881. fprintf(fOut, "%s=%.3f\n", "mv_b", m_fMvB.eval(-1));
  882. fprintf(fOut, "%s=%.3f\n", "mv_a", m_fMvA.eval(-1));
  883. fprintf(fOut, "%s=%.3f\n", "b1n", m_fBlur1Min.eval(-1));
  884. fprintf(fOut, "%s=%.3f\n", "b2n", m_fBlur2Min.eval(-1));
  885. fprintf(fOut, "%s=%.3f\n", "b3n", m_fBlur3Min.eval(-1));
  886. fprintf(fOut, "%s=%.3f\n", "b1x", m_fBlur1Max.eval(-1));
  887. fprintf(fOut, "%s=%.3f\n", "b2x", m_fBlur2Max.eval(-1));
  888. fprintf(fOut, "%s=%.3f\n", "b3x", m_fBlur3Max.eval(-1));
  889. fprintf(fOut, "%s=%.3f\n", "b1ed", m_fBlur1EdgeDarken.eval(-1));
  890. int i = 0;
  891. for (i=0; i<MAX_CUSTOM_WAVES; i++)
  892. m_wave[i].Export(fOut, L"dummy_filename", i);
  893. for (i=0; i<MAX_CUSTOM_SHAPES; i++)
  894. m_shape[i].Export(fOut, L"dummy_filename", i);
  895. // write out arbitrary expressions, one line at a time
  896. WriteCode(fOut, i, m_szPerFrameInit, "per_frame_init_");
  897. WriteCode(fOut, i, m_szPerFrameExpr, "per_frame_");
  898. WriteCode(fOut, i, m_szPerPixelExpr, "per_pixel_");
  899. if (m_nWarpPSVersion >= MD2_PS_2_0)
  900. WriteCode(fOut, i, m_szWarpShadersText, "warp_", true);
  901. if (m_nCompPSVersion >= MD2_PS_2_0)
  902. WriteCode(fOut, i, m_szCompShadersText, "comp_", true);
  903. fclose(fOut);
  904. return true;
  905. }
  906. int CWave::Export(FILE* fOut, const wchar_t *szFile, int i)
  907. {
  908. FILE* f2 = fOut;
  909. if (!fOut)
  910. {
  911. f2 = _wfopen(szFile, L"w");
  912. if (!f2) return 0;
  913. }
  914. fprintf(f2, "wavecode_%d_%s=%d\n", i, "enabled", enabled);
  915. fprintf(f2, "wavecode_%d_%s=%d\n", i, "samples", samples);
  916. fprintf(f2, "wavecode_%d_%s=%d\n", i, "sep", sep );
  917. fprintf(f2, "wavecode_%d_%s=%d\n", i, "bSpectrum", bSpectrum);
  918. fprintf(f2, "wavecode_%d_%s=%d\n", i, "bUseDots", bUseDots);
  919. fprintf(f2, "wavecode_%d_%s=%d\n", i, "bDrawThick", bDrawThick);
  920. fprintf(f2, "wavecode_%d_%s=%d\n", i, "bAdditive", bAdditive);
  921. fprintf(f2, "wavecode_%d_%s=%.5f\n", i, "scaling", scaling);
  922. fprintf(f2, "wavecode_%d_%s=%.5f\n", i, "smoothing", smoothing);
  923. fprintf(f2, "wavecode_%d_%s=%.3f\n", i, "r", r);
  924. fprintf(f2, "wavecode_%d_%s=%.3f\n", i, "g", g);
  925. fprintf(f2, "wavecode_%d_%s=%.3f\n", i, "b", b);
  926. fprintf(f2, "wavecode_%d_%s=%.3f\n", i, "a", a);
  927. // READ THE CODE IN
  928. char prefix[64];
  929. sprintf(prefix, "wave_%d_init", i); WriteCode(f2, i, m_szInit, prefix);
  930. sprintf(prefix, "wave_%d_per_frame", i); WriteCode(f2, i, m_szPerFrame, prefix);
  931. sprintf(prefix, "wave_%d_per_point", i); WriteCode(f2, i, m_szPerPoint, prefix);
  932. if (!fOut)
  933. fclose(f2); // [sic]
  934. return 1;
  935. }
  936. int CShape::Export(FILE* fOut, const wchar_t *szFile, int i)
  937. {
  938. FILE* f2 = fOut;
  939. if (!fOut)
  940. {
  941. f2 = _wfopen(szFile, L"w");
  942. if (!f2) return 0;
  943. //fprintf(f2, "[%s]\n", szSection);
  944. }
  945. fprintf(f2, "shapecode_%d_%s=%d\n", i, "enabled", enabled);
  946. fprintf(f2, "shapecode_%d_%s=%d\n", i, "sides", sides);
  947. fprintf(f2, "shapecode_%d_%s=%d\n", i, "additive", additive);
  948. fprintf(f2, "shapecode_%d_%s=%d\n", i, "thickOutline",thickOutline);
  949. fprintf(f2, "shapecode_%d_%s=%d\n", i, "textured", textured);
  950. fprintf(f2, "shapecode_%d_%s=%d\n", i, "num_inst", instances);
  951. fprintf(f2, "shapecode_%d_%s=%.3f\n", i, "x", x);
  952. fprintf(f2, "shapecode_%d_%s=%.3f\n", i, "y", y);
  953. fprintf(f2, "shapecode_%d_%s=%.5f\n", i, "rad", rad);
  954. fprintf(f2, "shapecode_%d_%s=%.5f\n", i, "ang", ang);
  955. fprintf(f2, "shapecode_%d_%s=%.5f\n", i, "tex_ang", tex_ang);
  956. fprintf(f2, "shapecode_%d_%s=%.5f\n", i, "tex_zoom", tex_zoom);
  957. fprintf(f2, "shapecode_%d_%s=%.3f\n", i, "r", r);
  958. fprintf(f2, "shapecode_%d_%s=%.3f\n", i, "g", g);
  959. fprintf(f2, "shapecode_%d_%s=%.3f\n", i, "b", b);
  960. fprintf(f2, "shapecode_%d_%s=%.3f\n", i, "a", a);
  961. fprintf(f2, "shapecode_%d_%s=%.3f\n", i, "r2", r2);
  962. fprintf(f2, "shapecode_%d_%s=%.3f\n", i, "g2", g2);
  963. fprintf(f2, "shapecode_%d_%s=%.3f\n", i, "b2", b2);
  964. fprintf(f2, "shapecode_%d_%s=%.3f\n", i, "a2", a2);
  965. fprintf(f2, "shapecode_%d_%s=%.3f\n", i, "border_r", border_r);
  966. fprintf(f2, "shapecode_%d_%s=%.3f\n", i, "border_g", border_g);
  967. fprintf(f2, "shapecode_%d_%s=%.3f\n", i, "border_b", border_b);
  968. fprintf(f2, "shapecode_%d_%s=%.3f\n", i, "border_a", border_a);
  969. char prefix[64];
  970. sprintf(prefix, "shape_%d_init", i); WriteCode(f2, i, m_szInit, prefix);
  971. sprintf(prefix, "shape_%d_per_frame", i); WriteCode(f2, i, m_szPerFrame, prefix);
  972. //sprintf(prefix, "shape_%d_per_point", i); WriteCode(f2, i, m_szPerPoint, prefix);
  973. if (!fOut)
  974. fclose(f2); // [sic]
  975. return 1;
  976. }
  977. void ReadCode(FILE* f, char* pStr, char* prefix)
  978. {
  979. if (!pStr)
  980. return;
  981. pStr[0] = 0;
  982. // read in & compile arbitrary expressions
  983. char szLineName[32];
  984. char szLine[MAX_BIGSTRING_LEN];
  985. int len;
  986. int line = 1;
  987. int char_pos = 0;
  988. bool bDone = false;
  989. while (!bDone)
  990. {
  991. sprintf(szLineName, "%s%d", prefix, line);
  992. GetFastString(szLineName, "~!@#$", szLine, MAX_BIGSTRING_LEN, f); // fixme
  993. len = strlen(szLine);
  994. if ((strcmp(szLine, "~!@#$")==0) || // if the key was missing,
  995. (len >= MAX_BIGSTRING_LEN-1-char_pos-1)) // or if we're out of space
  996. {
  997. bDone = true;
  998. }
  999. else
  1000. {
  1001. sprintf(&pStr[char_pos], "%s%c", (szLine[0]=='`') ? &szLine[1] : szLine, LINEFEED_CONTROL_CHAR);
  1002. if (szLine[0] == '`')
  1003. len--;
  1004. }
  1005. char_pos += len + 1;
  1006. line++;
  1007. }
  1008. pStr[char_pos++] = 0; // null-terminate
  1009. // read in & compile arbitrary expressions
  1010. /*
  1011. int n2 = 3 + MAX_CUSTOM_WAVES*3 + MAX_CUSTOM_SHAPES*2;
  1012. for (int n=0; n<n2; n++)
  1013. {
  1014. char *pStr;
  1015. char prefix[64];
  1016. char szLineName[32];
  1017. char szLine[MAX_BIGSTRING_LEN];
  1018. int len;
  1019. int line = 1;
  1020. int char_pos = 0;
  1021. bool bDone = false;
  1022. switch(n)
  1023. {
  1024. case 0: pStr = m_szPerFrameExpr; strcpy(prefix, "per_frame_"); break;
  1025. case 1: pStr = m_szPerPixelExpr; strcpy(prefix, "per_pixel_"); break;
  1026. case 2: pStr = m_szPerFrameInit; strcpy(prefix, "per_frame_init_"); break;
  1027. default:
  1028. if (n < 3 + 3*MAX_CUSTOM_WAVES)
  1029. {
  1030. int i = (n-3) / 3;
  1031. int j = (n-3) % 3;
  1032. switch(j)
  1033. {
  1034. case 0: pStr = m_wave[i].m_szInit; sprintf(prefix, "wave_%d_init", i); break;
  1035. case 1: pStr = m_wave[i].m_szPerFrame; sprintf(prefix, "wave_%d_per_frame", i); break;
  1036. case 2: pStr = m_wave[i].m_szPerPoint; sprintf(prefix, "wave_%d_per_point", i); break;
  1037. }
  1038. }
  1039. else
  1040. {
  1041. int i = (n-3-3*MAX_CUSTOM_WAVES) / 2;
  1042. int j = (n-3-3*MAX_CUSTOM_WAVES) % 2;
  1043. switch(j)
  1044. {
  1045. case 0: pStr = m_shape[i].m_szInit; sprintf(prefix, "shape_%d_init", i); break;
  1046. case 1: pStr = m_shape[i].m_szPerFrame; sprintf(prefix, "shape_%d_per_frame", i); break;
  1047. }
  1048. }
  1049. }
  1050. while (!bDone)
  1051. {
  1052. sprintf(szLineName, "%s%d", prefix, line);
  1053. GetPrivateProfileString(szSectionName, szLineName, "~!@#$", szLine, MAX_BIGSTRING_LEN, szIniFile); // fixme
  1054. len = strlen(szLine);
  1055. if ((strcmp(szLine, "~!@#$")==0) || // if the key was missing,
  1056. (len >= MAX_BIGSTRING_LEN-1-char_pos-1)) // or if we're out of space
  1057. {
  1058. bDone = true;
  1059. }
  1060. else
  1061. {
  1062. sprintf(&pStr[char_pos], "%s%c", szLine, LINEFEED_CONTROL_CHAR);
  1063. }
  1064. char_pos += len + 1;
  1065. line++;
  1066. }
  1067. pStr[char_pos++] = 0; // null-terminate
  1068. }
  1069. */
  1070. }
  1071. int CWave::Import(FILE* f, const wchar_t* szFile, int i)
  1072. {
  1073. FILE* f2 = f;
  1074. if (!f)
  1075. {
  1076. f2 = _wfopen(szFile, L"rb");
  1077. if (!f2) return 0;
  1078. GetFast_CLEAR();
  1079. }
  1080. char buf[64];
  1081. sprintf(buf, "wavecode_%d_%s", i, "enabled" ); enabled = GetFastInt (buf, enabled , f2);
  1082. sprintf(buf, "wavecode_%d_%s", i, "samples" ); samples = GetFastInt (buf, samples , f2);
  1083. sprintf(buf, "wavecode_%d_%s", i, "sep" ); sep = GetFastInt (buf, sep , f2);
  1084. sprintf(buf, "wavecode_%d_%s", i, "bSpectrum" ); bSpectrum = GetFastInt (buf, bSpectrum , f2);
  1085. sprintf(buf, "wavecode_%d_%s", i, "bUseDots" ); bUseDots = GetFastInt (buf, bUseDots , f2);
  1086. sprintf(buf, "wavecode_%d_%s", i, "bDrawThick"); bDrawThick = GetFastInt (buf, bDrawThick, f2);
  1087. sprintf(buf, "wavecode_%d_%s", i, "bAdditive" ); bAdditive = GetFastInt (buf, bAdditive , f2);
  1088. sprintf(buf, "wavecode_%d_%s", i, "scaling" ); scaling = GetFastFloat(buf, scaling , f2);
  1089. sprintf(buf, "wavecode_%d_%s", i, "smoothing" ); smoothing = GetFastFloat(buf, smoothing , f2);
  1090. sprintf(buf, "wavecode_%d_%s", i, "r" ); r = GetFastFloat(buf, r , f2);
  1091. sprintf(buf, "wavecode_%d_%s", i, "g" ); g = GetFastFloat(buf, g , f2);
  1092. sprintf(buf, "wavecode_%d_%s", i, "b" ); b = GetFastFloat(buf, b , f2);
  1093. sprintf(buf, "wavecode_%d_%s", i, "a" ); a = GetFastFloat(buf, a , f2);
  1094. // READ THE CODE IN
  1095. char prefix[64];
  1096. sprintf(prefix, "wave_%d_init", i); ReadCode(f2, m_szInit, prefix);
  1097. sprintf(prefix, "wave_%d_per_frame", i); ReadCode(f2, m_szPerFrame, prefix);
  1098. sprintf(prefix, "wave_%d_per_point", i); ReadCode(f2, m_szPerPoint, prefix);
  1099. if (!f)
  1100. fclose(f2); // [sic]
  1101. return 1;
  1102. }
  1103. int CShape::Import(FILE* f, const wchar_t* szFile, int i)
  1104. {
  1105. FILE* f2 = f;
  1106. if (!f)
  1107. {
  1108. f2 = _wfopen(szFile, L"rb");
  1109. if (!f2) return 0;
  1110. GetFast_CLEAR();
  1111. }
  1112. char buf[64];
  1113. sprintf(buf, "shapecode_%d_%s", i, "enabled" ); enabled = GetFastInt (buf, enabled , f2);
  1114. sprintf(buf, "shapecode_%d_%s", i, "sides" ); sides = GetFastInt (buf, sides , f2);
  1115. sprintf(buf, "shapecode_%d_%s", i, "additive" ); additive = GetFastInt (buf, additive , f2);
  1116. sprintf(buf, "shapecode_%d_%s", i, "thickOutline"); thickOutline = GetFastInt (buf, thickOutline, f2);
  1117. sprintf(buf, "shapecode_%d_%s", i, "textured" ); textured = GetFastInt (buf, textured , f2);
  1118. sprintf(buf, "shapecode_%d_%s", i, "num_inst" ); instances = GetFastInt (buf, instances , f2);
  1119. sprintf(buf, "shapecode_%d_%s", i, "x" ); x = GetFastFloat(buf, x , f2);
  1120. sprintf(buf, "shapecode_%d_%s", i, "y" ); y = GetFastFloat(buf, y , f2);
  1121. sprintf(buf, "shapecode_%d_%s", i, "rad" ); rad = GetFastFloat(buf, rad , f2);
  1122. sprintf(buf, "shapecode_%d_%s", i, "ang" ); ang = GetFastFloat(buf, ang , f2);
  1123. sprintf(buf, "shapecode_%d_%s", i, "tex_ang" ); tex_ang = GetFastFloat(buf, tex_ang , f2);
  1124. sprintf(buf, "shapecode_%d_%s", i, "tex_zoom" ); tex_zoom = GetFastFloat(buf, tex_zoom , f2);
  1125. sprintf(buf, "shapecode_%d_%s", i, "r" ); r = GetFastFloat(buf, r , f2);
  1126. sprintf(buf, "shapecode_%d_%s", i, "g" ); g = GetFastFloat(buf, g , f2);
  1127. sprintf(buf, "shapecode_%d_%s", i, "b" ); b = GetFastFloat(buf, b , f2);
  1128. sprintf(buf, "shapecode_%d_%s", i, "a" ); a = GetFastFloat(buf, a , f2);
  1129. sprintf(buf, "shapecode_%d_%s", i, "r2" ); r2 = GetFastFloat(buf, r2 , f2);
  1130. sprintf(buf, "shapecode_%d_%s", i, "g2" ); g2 = GetFastFloat(buf, g2 , f2);
  1131. sprintf(buf, "shapecode_%d_%s", i, "b2" ); b2 = GetFastFloat(buf, b2 , f2);
  1132. sprintf(buf, "shapecode_%d_%s", i, "a2" ); a2 = GetFastFloat(buf, a2 , f2);
  1133. sprintf(buf, "shapecode_%d_%s", i, "border_r" ); border_r = GetFastFloat(buf, border_r , f2);
  1134. sprintf(buf, "shapecode_%d_%s", i, "border_g" ); border_g = GetFastFloat(buf, border_g , f2);
  1135. sprintf(buf, "shapecode_%d_%s", i, "border_b" ); border_b = GetFastFloat(buf, border_b , f2);
  1136. sprintf(buf, "shapecode_%d_%s", i, "border_a" ); border_a = GetFastFloat(buf, border_a , f2);
  1137. // READ THE CODE IN
  1138. char prefix[64];
  1139. sprintf(prefix, "shape_%d_init", i); ReadCode(f2, m_szInit, prefix);
  1140. sprintf(prefix, "shape_%d_per_frame", i); ReadCode(f2, m_szPerFrame, prefix);
  1141. if (!f)
  1142. fclose(f2); // [sic]
  1143. return 1;
  1144. }
  1145. bool CState::Import(const wchar_t *szIniFile, float fTime, CState* pOldState, DWORD ApplyFlags)
  1146. {
  1147. // if any ApplyFlags are missing, the settings will be copied from pOldState. =)
  1148. if (!pOldState)
  1149. ApplyFlags = STATE_ALL;
  1150. if (ApplyFlags!=STATE_ALL && this != pOldState)
  1151. {
  1152. assert(pOldState);
  1153. // in order to copy the old state, we have to byte copy it.
  1154. memcpy(this, pOldState, sizeof(CState));
  1155. // clear all the copied code pointers, WITHOUT actually freeing it (since ptrs were copied)
  1156. // so that the Default() call below won't release pOldState's copied pointers.
  1157. // [all expressions will be recompiled @ end of this fn, whether we updated them or not]
  1158. FreeVarsAndCode(false);
  1159. }
  1160. // apply defaults for the stuff we will overwrite.
  1161. Default(ApplyFlags);//RandomizePresetVars();
  1162. GetFast_CLEAR();
  1163. if ( (ApplyFlags & STATE_GENERAL) && // check for these 3 @ same time,
  1164. (ApplyFlags & STATE_MOTION) && // so a preset switch w/ warp/comp lock
  1165. (ApplyFlags & STATE_WAVE) // updates the name, but mash-ups don't.
  1166. )
  1167. {
  1168. m_fPresetStartTime = fTime;
  1169. // extract a description of the preset from the filename
  1170. {
  1171. // copy get the filename (without the path)
  1172. const wchar_t *p = wcsrchr(szIniFile, '\\');
  1173. if (p==NULL) p = szIniFile;
  1174. lstrcpyW(m_szDesc, p+1);
  1175. // next remove the extension
  1176. RemoveExtension(m_szDesc);
  1177. }
  1178. }
  1179. FILE* f = _wfopen(szIniFile, L"rb");
  1180. if (!f)
  1181. return false;
  1182. int nMilkdropPresetVersion = GetFastInt("MILKDROP_PRESET_VERSION",100,f);
  1183. //if (ApplyFlags != STATE_ALL)
  1184. // nMilkdropPresetVersion = CUR_MILKDROP_PRESET_VERSION; //if we're mashing up, force it up to now
  1185. int nWarpPSVersionInFile;
  1186. int nCompPSVersionInFile;
  1187. if (nMilkdropPresetVersion < 200) {
  1188. nWarpPSVersionInFile = 0;
  1189. nCompPSVersionInFile = 0;
  1190. }
  1191. else if (nMilkdropPresetVersion == 200) {
  1192. nWarpPSVersionInFile = GetFastInt("PSVERSION", 2, f);
  1193. nCompPSVersionInFile = nWarpPSVersionInFile;
  1194. }
  1195. else {
  1196. nWarpPSVersionInFile = GetFastInt("PSVERSION_WARP", 2, f);
  1197. nCompPSVersionInFile = GetFastInt("PSVERSION_COMP", 2, f);
  1198. }
  1199. // general:
  1200. if (ApplyFlags & STATE_GENERAL)
  1201. {
  1202. m_fRating = GetFastFloat("fRating",m_fRating,f);
  1203. m_fDecay = GetFastFloat("fDecay",m_fDecay.eval(-1),f);
  1204. m_fGammaAdj = GetFastFloat("fGammaAdj" ,m_fGammaAdj.eval(-1),f);
  1205. m_fVideoEchoZoom = GetFastFloat("fVideoEchoZoom",m_fVideoEchoZoom.eval(-1),f);
  1206. m_fVideoEchoAlpha = GetFastFloat("fVideoEchoAlpha",m_fVideoEchoAlpha.eval(-1),f);
  1207. m_nVideoEchoOrientation = GetFastInt ("nVideoEchoOrientation",m_nVideoEchoOrientation,f);
  1208. m_bRedBlueStereo = (GetFastInt ("bRedBlueStereo", m_bRedBlueStereo,f) != 0);
  1209. m_bBrighten = (GetFastInt ("bBrighten",m_bBrighten ,f) != 0);
  1210. m_bDarken = (GetFastInt ("bDarken" ,m_bDarken ,f) != 0);
  1211. m_bSolarize = (GetFastInt ("bSolarize",m_bSolarize ,f) != 0);
  1212. m_bInvert = (GetFastInt ("bInvert" ,m_bInvert ,f) != 0);
  1213. m_fShader = GetFastFloat("fShader",m_fShader.eval(-1),f);
  1214. m_fBlur1Min = GetFastFloat("b1n", m_fBlur1Min.eval(-1),f);
  1215. m_fBlur2Min = GetFastFloat("b2n", m_fBlur2Min.eval(-1),f);
  1216. m_fBlur3Min = GetFastFloat("b3n", m_fBlur3Min.eval(-1),f);
  1217. m_fBlur1Max = GetFastFloat("b1x", m_fBlur1Max.eval(-1),f);
  1218. m_fBlur2Max = GetFastFloat("b2x", m_fBlur2Max.eval(-1),f);
  1219. m_fBlur3Max = GetFastFloat("b3x", m_fBlur3Max.eval(-1),f);
  1220. m_fBlur1EdgeDarken = GetFastFloat("b1ed", m_fBlur1EdgeDarken.eval(-1),f);
  1221. }
  1222. // wave:
  1223. if (ApplyFlags & STATE_WAVE)
  1224. {
  1225. m_nWaveMode = GetFastInt ("nWaveMode",m_nWaveMode,f);
  1226. m_bAdditiveWaves = (GetFastInt ("bAdditiveWaves",m_bAdditiveWaves,f) != 0);
  1227. m_bWaveDots = (GetFastInt ("bWaveDots",m_bWaveDots,f) != 0);
  1228. m_bWaveThick = (GetFastInt ("bWaveThick",m_bWaveThick,f) != 0);
  1229. m_bModWaveAlphaByVolume = (GetFastInt ("bModWaveAlphaByVolume",m_bModWaveAlphaByVolume,f) != 0);
  1230. m_bMaximizeWaveColor = (GetFastInt ("bMaximizeWaveColor" ,m_bMaximizeWaveColor,f) != 0);
  1231. m_fWaveAlpha = GetFastFloat("fWaveAlpha",m_fWaveAlpha.eval(-1),f);
  1232. m_fWaveScale = GetFastFloat("fWaveScale",m_fWaveScale.eval(-1),f);
  1233. m_fWaveSmoothing = GetFastFloat("fWaveSmoothing",m_fWaveSmoothing.eval(-1),f);
  1234. m_fWaveParam = GetFastFloat("fWaveParam",m_fWaveParam.eval(-1),f);
  1235. m_fModWaveAlphaStart = GetFastFloat("fModWaveAlphaStart",m_fModWaveAlphaStart.eval(-1),f);
  1236. m_fModWaveAlphaEnd = GetFastFloat("fModWaveAlphaEnd",m_fModWaveAlphaEnd.eval(-1),f);
  1237. m_fWaveR = GetFastFloat("wave_r",m_fRot.eval(-1),f);
  1238. m_fWaveG = GetFastFloat("wave_g",m_fRot.eval(-1),f);
  1239. m_fWaveB = GetFastFloat("wave_b",m_fRot.eval(-1),f);
  1240. m_fWaveX = GetFastFloat("wave_x",m_fRot.eval(-1),f);
  1241. m_fWaveY = GetFastFloat("wave_y",m_fRot.eval(-1),f);
  1242. m_fMvX = GetFastFloat("nMotionVectorsX", m_fMvX.eval(-1),f);
  1243. m_fMvY = GetFastFloat("nMotionVectorsY", m_fMvY.eval(-1),f);
  1244. m_fMvDX = GetFastFloat("mv_dx", m_fMvDX.eval(-1),f);
  1245. m_fMvDY = GetFastFloat("mv_dy", m_fMvDY.eval(-1),f);
  1246. m_fMvL = GetFastFloat("mv_l", m_fMvL.eval(-1),f);
  1247. m_fMvR = GetFastFloat("mv_r", m_fMvR.eval(-1),f);
  1248. m_fMvG = GetFastFloat("mv_g", m_fMvG.eval(-1),f);
  1249. m_fMvB = GetFastFloat("mv_b", m_fMvB.eval(-1),f);
  1250. m_fMvA = (GetFastInt ("bMotionVectorsOn",false,f) == 0) ? 0.0f : 1.0f; // for backwards compatibility
  1251. m_fMvA = GetFastFloat("mv_a", m_fMvA.eval(-1),f);
  1252. int i = 0;
  1253. for (i=0; i<MAX_CUSTOM_WAVES; i++)
  1254. {
  1255. m_wave[i].Import(f, L"dummy_filename", i);
  1256. }
  1257. for (i=0; i<MAX_CUSTOM_SHAPES; i++)
  1258. {
  1259. m_shape[i].Import(f, L"dummy_filename", i);
  1260. }
  1261. }
  1262. // motion:
  1263. if (ApplyFlags & STATE_MOTION)
  1264. {
  1265. m_fZoom = GetFastFloat("zoom",m_fZoom.eval(-1),f);
  1266. m_fRot = GetFastFloat("rot",m_fRot.eval(-1),f);
  1267. m_fRotCX = GetFastFloat("cx",m_fRotCX.eval(-1),f);
  1268. m_fRotCY = GetFastFloat("cy",m_fRotCY.eval(-1),f);
  1269. m_fXPush = GetFastFloat("dx",m_fXPush.eval(-1),f);
  1270. m_fYPush = GetFastFloat("dy",m_fYPush.eval(-1),f);
  1271. m_fWarpAmount = GetFastFloat("warp",m_fWarpAmount.eval(-1),f);
  1272. m_fStretchX = GetFastFloat("sx",m_fStretchX.eval(-1),f);
  1273. m_fStretchY = GetFastFloat("sy",m_fStretchY.eval(-1),f);
  1274. m_bTexWrap = (GetFastInt ("bTexWrap", m_bTexWrap,f) != 0);
  1275. m_bDarkenCenter = (GetFastInt ("bDarkenCenter", m_bDarkenCenter,f) != 0);
  1276. m_fWarpAnimSpeed = GetFastFloat("fWarpAnimSpeed",m_fWarpAnimSpeed,f);
  1277. m_fWarpScale = GetFastFloat("fWarpScale",m_fWarpScale.eval(-1),f);
  1278. m_fZoomExponent = GetFastFloat("fZoomExponent",m_fZoomExponent.eval(-1),f);
  1279. m_fOuterBorderSize = GetFastFloat("ob_size",m_fOuterBorderSize.eval(-1),f);
  1280. m_fOuterBorderR = GetFastFloat("ob_r", m_fOuterBorderR.eval(-1),f);
  1281. m_fOuterBorderG = GetFastFloat("ob_g", m_fOuterBorderG.eval(-1),f);
  1282. m_fOuterBorderB = GetFastFloat("ob_b", m_fOuterBorderB.eval(-1),f);
  1283. m_fOuterBorderA = GetFastFloat("ob_a", m_fOuterBorderA.eval(-1),f);
  1284. m_fInnerBorderSize = GetFastFloat("ib_size",m_fInnerBorderSize.eval(-1),f);
  1285. m_fInnerBorderR = GetFastFloat("ib_r", m_fInnerBorderR.eval(-1),f);
  1286. m_fInnerBorderG = GetFastFloat("ib_g", m_fInnerBorderG.eval(-1),f);
  1287. m_fInnerBorderB = GetFastFloat("ib_b", m_fInnerBorderB.eval(-1),f);
  1288. m_fInnerBorderA = GetFastFloat("ib_a", m_fInnerBorderA.eval(-1),f);
  1289. //m_szPerFrameInit[0] = 0;
  1290. //m_szPerFrameExpr[0] = 0;
  1291. //m_szPerPixelExpr[0] = 0;
  1292. ReadCode(f, m_szPerFrameInit, "per_frame_init_");
  1293. ReadCode(f, m_szPerFrameExpr, "per_frame_");
  1294. ReadCode(f, m_szPerPixelExpr, "per_pixel_");
  1295. }
  1296. // warp shader
  1297. if (ApplyFlags & STATE_WARP)
  1298. {
  1299. //m_szWarpShadersText[0] = 0;
  1300. ReadCode(f, m_szWarpShadersText, "warp_");
  1301. if (!m_szWarpShadersText[0])
  1302. g_plugin.GenWarpPShaderText(m_szWarpShadersText, m_fDecay.eval(-1), m_bTexWrap);
  1303. m_nWarpPSVersion = nWarpPSVersionInFile;
  1304. }
  1305. // comp shader
  1306. if (ApplyFlags & STATE_COMP)
  1307. {
  1308. //m_szCompShadersText[0] = 0;
  1309. ReadCode(f, m_szCompShadersText, "comp_");
  1310. if (!m_szCompShadersText[0])
  1311. g_plugin.GenCompPShaderText(m_szCompShadersText, m_fGammaAdj.eval(-1), m_fVideoEchoAlpha.eval(-1), m_fVideoEchoZoom.eval(-1), m_nVideoEchoOrientation, m_fShader.eval(-1), m_bBrighten, m_bDarken, m_bSolarize, m_bInvert);
  1312. m_nCompPSVersion = nCompPSVersionInFile;
  1313. }
  1314. m_nMaxPSVersion = max(m_nWarpPSVersion, m_nCompPSVersion);
  1315. m_nMinPSVersion = min(m_nWarpPSVersion, m_nCompPSVersion);
  1316. RecompileExpressions();
  1317. fclose(f);
  1318. return true;
  1319. }
  1320. void CState::GenDefaultWarpShader()
  1321. {
  1322. if (m_nWarpPSVersion>0)
  1323. g_plugin.GenWarpPShaderText(m_szWarpShadersText, m_fDecay.eval(-1), m_bTexWrap);
  1324. }
  1325. void CState::GenDefaultCompShader()
  1326. {
  1327. if (m_nCompPSVersion>0)
  1328. g_plugin.GenCompPShaderText(m_szCompShadersText, m_fGammaAdj.eval(-1), m_fVideoEchoAlpha.eval(-1), m_fVideoEchoZoom.eval(-1), m_nVideoEchoOrientation, m_fShader.eval(-1), m_bBrighten, m_bDarken, m_bSolarize, m_bInvert);
  1329. }
  1330. void CState::FreeVarsAndCode(bool bFree)
  1331. {
  1332. // free the compiled expressions
  1333. if (m_pf_codehandle)
  1334. {
  1335. if (bFree)
  1336. NSEEL_code_free(m_pf_codehandle);
  1337. m_pf_codehandle = NULL;
  1338. }
  1339. if (m_pp_codehandle)
  1340. {
  1341. if (bFree)
  1342. NSEEL_code_free(m_pp_codehandle);
  1343. m_pp_codehandle = NULL;
  1344. }
  1345. int i = 0;
  1346. for (i=0; i<MAX_CUSTOM_WAVES; i++)
  1347. {
  1348. if (m_wave[i].m_pf_codehandle)
  1349. {
  1350. if (bFree)
  1351. NSEEL_code_free(m_wave[i].m_pf_codehandle);
  1352. m_wave[i].m_pf_codehandle = NULL;
  1353. }
  1354. if (m_wave[i].m_pp_codehandle)
  1355. {
  1356. if (bFree)
  1357. NSEEL_code_free(m_wave[i].m_pp_codehandle);
  1358. m_wave[i].m_pp_codehandle = NULL;
  1359. }
  1360. }
  1361. for (i=0; i<MAX_CUSTOM_SHAPES; i++)
  1362. {
  1363. if (m_shape[i].m_pf_codehandle)
  1364. {
  1365. if (bFree)
  1366. NSEEL_code_free(m_shape[i].m_pf_codehandle);
  1367. m_shape[i].m_pf_codehandle = NULL;
  1368. }
  1369. /*if (m_shape[i].m_pp_codehandle)
  1370. {
  1371. freeCode(m_shape[i].m_pp_codehandle);
  1372. m_shape[i].m_pp_codehandle = NULL;
  1373. }*/
  1374. }
  1375. // free our text version of the expressions? - no!
  1376. //m_szPerFrameExpr[0] = 0;
  1377. //m_szPerPixelExpr[0] = 0;
  1378. // free the old variable names & reregister the built-in variables (since they got nuked too)
  1379. RegisterBuiltInVariables(0xFFFFFFFF);
  1380. }
  1381. void CState::StripLinefeedCharsAndComments(char *src, char *dest)
  1382. {
  1383. // replaces all LINEFEED_CONTROL_CHAR characters in src with a space in dest;
  1384. // also strips out all comments (beginning with '//' and going til end of line).
  1385. // Restriction: sizeof(dest) must be >= sizeof(src).
  1386. int i2 = 0;
  1387. int len = strlen(src);
  1388. int bComment = false;
  1389. for (int i=0; i<len; i++)
  1390. {
  1391. if (bComment)
  1392. {
  1393. if (src[i] == LINEFEED_CONTROL_CHAR)
  1394. bComment = false;
  1395. }
  1396. else
  1397. {
  1398. if ((src[i] =='\\' && src[i+1] =='\\') || (src[i] =='/' && src[i+1] =='/'))
  1399. bComment = true;
  1400. else if (src[i] != LINEFEED_CONTROL_CHAR)
  1401. dest[i2++] = src[i];
  1402. }
  1403. }
  1404. dest[i2] = 0;
  1405. }
  1406. void CState::RecompileExpressions(int flags, int bReInit)
  1407. {
  1408. // before we get started, if we redo the init code for the preset, we have to redo
  1409. // other things too, because q1-q8 could change.
  1410. if ((flags & RECOMPILE_PRESET_CODE) && bReInit)
  1411. {
  1412. flags |= RECOMPILE_WAVE_CODE;
  1413. flags |= RECOMPILE_SHAPE_CODE;
  1414. }
  1415. // free old code handles
  1416. if (flags & RECOMPILE_PRESET_CODE)
  1417. {
  1418. if (m_pf_codehandle)
  1419. {
  1420. NSEEL_code_free(m_pf_codehandle);
  1421. m_pf_codehandle = NULL;
  1422. }
  1423. if (m_pp_codehandle)
  1424. {
  1425. NSEEL_code_free(m_pp_codehandle);
  1426. m_pp_codehandle = NULL;
  1427. }
  1428. }
  1429. if (flags & RECOMPILE_WAVE_CODE)
  1430. {
  1431. for (int i=0; i<MAX_CUSTOM_WAVES; i++)
  1432. {
  1433. if (m_wave[i].m_pf_codehandle)
  1434. {
  1435. NSEEL_code_free(m_wave[i].m_pf_codehandle);
  1436. m_wave[i].m_pf_codehandle = NULL;
  1437. }
  1438. if (m_wave[i].m_pp_codehandle)
  1439. {
  1440. NSEEL_code_free(m_wave[i].m_pp_codehandle);
  1441. m_wave[i].m_pp_codehandle = NULL;
  1442. }
  1443. }
  1444. }
  1445. if (flags & RECOMPILE_SHAPE_CODE)
  1446. {
  1447. for (int i=0; i<MAX_CUSTOM_SHAPES; i++)
  1448. {
  1449. if (m_shape[i].m_pf_codehandle)
  1450. {
  1451. NSEEL_code_free(m_shape[i].m_pf_codehandle);
  1452. m_shape[i].m_pf_codehandle = NULL;
  1453. }
  1454. /*if (m_shape[i].m_pp_codehandle)
  1455. {
  1456. freeCode(m_shape[i].m_pp_codehandle);
  1457. m_shape[i].m_pp_codehandle = NULL;
  1458. }*/
  1459. }
  1460. }
  1461. // if we're recompiling init code, clear vars to zero, and re-register built-in variables.
  1462. if (bReInit)
  1463. {
  1464. RegisterBuiltInVariables(flags);
  1465. }
  1466. // QUICK FIX: if the code strings ONLY have spaces and linefeeds, erase them,
  1467. // because for some strange reason this causes errors in compileCode().
  1468. int n2 = 3 + MAX_CUSTOM_WAVES*3 + MAX_CUSTOM_SHAPES*2;
  1469. for (int n=0; n<n2; n++)
  1470. {
  1471. char *pOrig;
  1472. switch(n)
  1473. {
  1474. case 0: pOrig = m_szPerFrameExpr; break;
  1475. case 1: pOrig = m_szPerPixelExpr; break;
  1476. case 2: pOrig = m_szPerFrameInit; break;
  1477. default:
  1478. if (n < 3 + 3*MAX_CUSTOM_WAVES)
  1479. {
  1480. int i = (n-3) / 3;
  1481. int j = (n-3) % 3;
  1482. switch(j)
  1483. {
  1484. case 0: pOrig = m_wave[i].m_szInit; break;
  1485. case 1: pOrig = m_wave[i].m_szPerFrame; break;
  1486. case 2: pOrig = m_wave[i].m_szPerPoint; break;
  1487. }
  1488. }
  1489. else
  1490. {
  1491. int i = (n-3-3*MAX_CUSTOM_WAVES) / 2;
  1492. int j = (n-3-3*MAX_CUSTOM_WAVES) % 2;
  1493. switch(j)
  1494. {
  1495. case 0: pOrig = m_shape[i].m_szInit; break;
  1496. case 1: pOrig = m_shape[i].m_szPerFrame; break;
  1497. }
  1498. }
  1499. }
  1500. char *p = pOrig;
  1501. while (*p==' ' || *p==LINEFEED_CONTROL_CHAR) p++;
  1502. if (*p == 0) pOrig[0] = 0;
  1503. }
  1504. // COMPILE NEW CODE.
  1505. #ifndef _NO_EXPR_
  1506. {
  1507. // clear any old error msg.:
  1508. //g_plugin.m_fShowUserMessageUntilThisTime = g_plugin.GetTime();
  1509. char buf[MAX_BIGSTRING_LEN*3];
  1510. if (flags & RECOMPILE_PRESET_CODE)
  1511. {
  1512. // 1. compile AND EXECUTE preset init code
  1513. StripLinefeedCharsAndComments(m_szPerFrameInit, buf);
  1514. if (buf[0] && bReInit)
  1515. {
  1516. NSEEL_CODEHANDLE pf_codehandle_init;
  1517. if ( ! (pf_codehandle_init = NSEEL_code_compile(m_pf_eel, buf)))
  1518. {
  1519. wchar_t buf[1024];
  1520. swprintf(buf, WASABI_API_LNGSTRINGW(IDS_WARNING_PRESET_X_ERROR_IN_PRESET_INIT_CODE), m_szDesc);
  1521. g_plugin.AddError(buf, 6.0f, ERR_PRESET, true);
  1522. for (int vi=0; vi<NUM_Q_VAR; vi++)
  1523. q_values_after_init_code[vi] = 0;
  1524. monitor_after_init_code = 0;
  1525. }
  1526. else
  1527. {
  1528. // now execute the code, save the values of q1..q32, and clean up the code!
  1529. g_plugin.LoadPerFrameEvallibVars(g_plugin.m_pState);
  1530. NSEEL_code_execute(pf_codehandle_init);
  1531. for (int vi=0; vi<NUM_Q_VAR; vi++)
  1532. q_values_after_init_code[vi] = *var_pf_q[vi];
  1533. monitor_after_init_code = *var_pf_monitor;
  1534. NSEEL_code_free(pf_codehandle_init);
  1535. pf_codehandle_init = NULL;
  1536. }
  1537. }
  1538. // 2. compile preset per-frame code
  1539. StripLinefeedCharsAndComments(m_szPerFrameExpr, buf);
  1540. if (buf[0])
  1541. {
  1542. if ( ! (m_pf_codehandle = NSEEL_code_compile(m_pf_eel, buf)))
  1543. {
  1544. wchar_t buf[1024];
  1545. swprintf(buf, WASABI_API_LNGSTRINGW(IDS_WARNING_PRESET_X_ERROR_IN_PER_FRAME_CODE), m_szDesc);
  1546. g_plugin.AddError(buf, 6.0f, ERR_PRESET, true);
  1547. }
  1548. }
  1549. // 3. compile preset per-pixel code
  1550. StripLinefeedCharsAndComments(m_szPerPixelExpr, buf);
  1551. if (buf[0])
  1552. {
  1553. if ( ! (m_pp_codehandle = NSEEL_code_compile(m_pv_eel, buf)))
  1554. {
  1555. wchar_t buf[1024];
  1556. swprintf(buf, WASABI_API_LNGSTRINGW(IDS_WARNING_PRESET_X_ERROR_IN_PER_VERTEX_CODE), m_szDesc);
  1557. g_plugin.AddError(buf, 6.0f, ERR_PRESET, true);
  1558. }
  1559. }
  1560. //resetVars(NULL);
  1561. }
  1562. if (flags & RECOMPILE_WAVE_CODE)
  1563. {
  1564. for (int i=0; i<MAX_CUSTOM_WAVES; i++)
  1565. {
  1566. // 1. compile AND EXECUTE custom waveform init code
  1567. StripLinefeedCharsAndComments(m_wave[i].m_szInit, buf);
  1568. if (buf[0] && bReInit)
  1569. {
  1570. #ifndef _NO_EXPR_
  1571. {
  1572. NSEEL_CODEHANDLE codehandle_temp;
  1573. if ( ! (codehandle_temp = NSEEL_code_compile(m_wave[i].m_pf_eel, buf)))
  1574. {
  1575. wchar_t buf[1024];
  1576. swprintf(buf, WASABI_API_LNGSTRINGW(IDS_WARNING_PRESET_X_ERROR_IN_WAVE_X_INIT_CODE), m_szDesc, i);
  1577. g_plugin.AddError(buf, 6.0f, ERR_PRESET, true);
  1578. int vi = 0;
  1579. for (vi=0; vi<NUM_Q_VAR; vi++)
  1580. *m_wave[i].var_pf_q[vi] = q_values_after_init_code[vi];
  1581. for (vi=0; vi<NUM_T_VAR; vi++)
  1582. m_wave[i].t_values_after_init_code[vi] = 0;
  1583. }
  1584. else
  1585. {
  1586. // now execute the code, save the values of t1..t8, and clean up the code!
  1587. g_plugin.LoadCustomWavePerFrameEvallibVars(g_plugin.m_pState, i);
  1588. // note: q values at this point will actually be same as
  1589. // q_values_after_init_code[], since no per-frame code
  1590. // has actually been executed yet!
  1591. NSEEL_code_execute(codehandle_temp);
  1592. for (int vi=0; vi<NUM_T_VAR; vi++)
  1593. m_wave[i].t_values_after_init_code[vi] = *m_wave[i].var_pf_t[vi];
  1594. NSEEL_code_free(codehandle_temp);
  1595. codehandle_temp = NULL;
  1596. }
  1597. }
  1598. #endif
  1599. }
  1600. // 2. compile custom waveform per-frame code
  1601. StripLinefeedCharsAndComments(m_wave[i].m_szPerFrame, buf);
  1602. if (buf[0])
  1603. {
  1604. #ifndef _NO_EXPR_
  1605. if ( ! (m_wave[i].m_pf_codehandle = NSEEL_code_compile(m_wave[i].m_pf_eel, buf)))
  1606. {
  1607. wchar_t buf[1024];
  1608. swprintf(buf, WASABI_API_LNGSTRINGW(IDS_WARNING_PRESET_X_ERROR_IN_WAVE_X_PER_FRAME_CODE), m_szDesc, i);
  1609. g_plugin.AddError(buf, 6.0f, ERR_PRESET, true);
  1610. }
  1611. #endif
  1612. }
  1613. // 3. compile custom waveform per-point code
  1614. StripLinefeedCharsAndComments(m_wave[i].m_szPerPoint, buf);
  1615. if (buf[0])
  1616. {
  1617. if ( ! (m_wave[i].m_pp_codehandle = NSEEL_code_compile(m_wave[i].m_pp_eel, buf)))
  1618. {
  1619. wchar_t buf[1024];
  1620. swprintf(buf, WASABI_API_LNGSTRINGW(IDS_WARNING_PRESET_X_ERROR_IN_WAVE_X_PER_POINT_CODE), m_szDesc, i);
  1621. g_plugin.AddError(buf, 6.0f, ERR_PRESET, true);
  1622. }
  1623. }
  1624. }
  1625. }
  1626. if (flags & RECOMPILE_SHAPE_CODE)
  1627. {
  1628. for (int i=0; i<MAX_CUSTOM_SHAPES; i++)
  1629. {
  1630. // 1. compile AND EXECUTE custom shape init code
  1631. StripLinefeedCharsAndComments(m_shape[i].m_szInit, buf);
  1632. if (buf[0] && bReInit)
  1633. {
  1634. #ifndef _NO_EXPR_
  1635. {
  1636. NSEEL_CODEHANDLE codehandle_temp;
  1637. if ( ! (codehandle_temp = NSEEL_code_compile(m_shape[i].m_pf_eel, buf)))
  1638. {
  1639. wchar_t buf[1024];
  1640. swprintf(buf, WASABI_API_LNGSTRINGW(IDS_WARNING_PRESET_X_ERROR_IN_SHAPE_X_INIT_CODE), m_szDesc, i);
  1641. g_plugin.AddError(buf, 6.0f, ERR_PRESET, true);
  1642. int vi = 0;
  1643. for (vi=0; vi<NUM_Q_VAR; vi++)
  1644. *m_shape[i].var_pf_q[vi] = q_values_after_init_code[vi];
  1645. for (vi=0; vi<NUM_T_VAR; vi++)
  1646. m_shape[i].t_values_after_init_code[vi] = 0;
  1647. }
  1648. else
  1649. {
  1650. // now execute the code, save the values of q1..q8, and clean up the code!
  1651. g_plugin.LoadCustomShapePerFrameEvallibVars(g_plugin.m_pState, i, 0);
  1652. // note: q values at this point will actually be same as
  1653. // q_values_after_init_code[], since no per-frame code
  1654. // has actually been executed yet!
  1655. NSEEL_code_execute(codehandle_temp);
  1656. for (int vi=0; vi<NUM_T_VAR; vi++)
  1657. m_shape[i].t_values_after_init_code[vi] = *m_shape[i].var_pf_t[vi];
  1658. NSEEL_code_free(codehandle_temp);
  1659. codehandle_temp = NULL;
  1660. }
  1661. }
  1662. #endif
  1663. }
  1664. // 2. compile custom shape per-frame code
  1665. StripLinefeedCharsAndComments(m_shape[i].m_szPerFrame, buf);
  1666. if (buf[0])
  1667. {
  1668. #ifndef _NO_EXPR_
  1669. if ( ! (m_shape[i].m_pf_codehandle = NSEEL_code_compile(m_shape[i].m_pf_eel, buf)))
  1670. {
  1671. wchar_t buf[1024];
  1672. swprintf(buf, WASABI_API_LNGSTRINGW(IDS_WARNING_PRESET_X_ERROR_IN_SHAPE_X_PER_FRAME_CODE), m_szDesc, i);
  1673. g_plugin.AddError(buf, 6.0f, ERR_PRESET, true);
  1674. }
  1675. #endif
  1676. }
  1677. /*
  1678. // 3. compile custom shape per-point code
  1679. StripLinefeedCharsAndComments(m_shape[i].m_szPerPoint, buf);
  1680. if (buf[0])
  1681. {
  1682. resetVars(m_shape[i].m_pp_vars);
  1683. #ifndef _NO_EXPR_
  1684. if ( ! (m_shape[i].m_pp_codehandle = compileCode(buf)))
  1685. {
  1686. sprintf(g_plugin.m_szUserMessage, "warning: preset \"%s\": error in shape %d per-point code", m_szDesc, i);
  1687. g_plugin.m_fShowUserMessageUntilThisTime = g_plugin.GetTime() + 6.0f;
  1688. g_plugin.m_bUserMessageIsError = true;
  1689. }
  1690. #endif
  1691. resetVars(NULL);
  1692. }
  1693. */
  1694. }
  1695. }
  1696. }
  1697. #endif
  1698. }
  1699. void CState::RandomizePresetVars()
  1700. {
  1701. m_rand_preset = D3DXVECTOR4(FRAND, FRAND, FRAND, FRAND);
  1702. int k = 0;
  1703. do
  1704. {
  1705. for (int i=0; i<4; i++)
  1706. {
  1707. float xlate_mult = 1;//(j==0) ? 1 : 0;
  1708. float rot_mult = 0.9f*powf(k/8.0f, 3.2f);
  1709. m_xlate[k].x = (FRAND*2-1)*xlate_mult;
  1710. m_xlate[k].y = (FRAND*2-1)*xlate_mult;
  1711. m_xlate[k].z = (FRAND*2-1)*xlate_mult;
  1712. m_rot_base[k].x = FRAND*6.28f;
  1713. m_rot_base[k].y = FRAND*6.28f;
  1714. m_rot_base[k].z = FRAND*6.28f;
  1715. m_rot_speed[k].x = (FRAND*2-1)*rot_mult;
  1716. m_rot_speed[k].y = (FRAND*2-1)*rot_mult;
  1717. m_rot_speed[k].z = (FRAND*2-1)*rot_mult;
  1718. k++;
  1719. }
  1720. }
  1721. while (k < sizeof(m_xlate)/sizeof(m_xlate[0]));
  1722. }
  1723. CBlendableFloat::CBlendableFloat()
  1724. {
  1725. m_bBlending = false;
  1726. }
  1727. CBlendableFloat::~CBlendableFloat()
  1728. {
  1729. }
  1730. //--------------------------------------------------------------------------------
  1731. float CBlendableFloat::eval(float fTime)
  1732. {
  1733. if (fTime < 0)
  1734. {
  1735. return val;
  1736. }
  1737. if (m_bBlending && (fTime > m_fBlendStartTime + m_fBlendDuration) || (fTime < m_fBlendStartTime))
  1738. {
  1739. m_bBlending = false;
  1740. }
  1741. if (!m_bBlending)
  1742. {
  1743. return val;
  1744. }
  1745. else
  1746. {
  1747. float mix = (fTime - m_fBlendStartTime) / m_fBlendDuration;
  1748. return (m_fBlendFrom*(1.0f - mix) + val*mix);
  1749. }
  1750. }
  1751. //--------------------------------------------------------------------------------
  1752. void CBlendableFloat::StartBlendFrom(CBlendableFloat *f_from, float fAnimTime, float fDuration)
  1753. {
  1754. if (fDuration < 0.001f)
  1755. return;
  1756. m_fBlendFrom = f_from->eval(fAnimTime);
  1757. m_bBlending = true;
  1758. m_fBlendStartTime = fAnimTime;
  1759. m_fBlendDuration = fDuration;
  1760. }