/xbmc/visualizations/Milkdrop/vis_milkdrop/milkdropfs.cpp
http://github.com/xbmc/xbmc · C++ · 3791 lines · 2280 code · 486 blank · 1025 comment · 366 complexity · 787dd83e37422f1a7c78d74f419bf83e MD5 · raw file
Large files are truncated click here to view the full file
- /*
- LICENSE
- -------
- Copyright 2005 Nullsoft, Inc.
- All rights reserved.
- Redistribution and use in source and binary forms, with or without modification,
- are permitted provided that the following conditions are met:
- * Redistributions of source code must retain the above copyright notice,
- this list of conditions and the following disclaimer.
- * Redistributions in binary form must reproduce the above copyright notice,
- this list of conditions and the following disclaimer in the documentation
- and/or other materials provided with the distribution.
- * Neither the name of Nullsoft nor the names of its contributors may be used to
- endorse or promote products derived from this software without specific prior written permission.
-
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
- IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
- FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
- CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
- IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
- OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
- #include "plugin.h"
- //#include "resource.h"
- #include "support.h"
- #include "evallib\eval.h" // for math. expr. eval - thanks Francis! (in SourceOffSite, it's the 'vis_avs\evallib' project.)
- #include "evallib\compiler.h"
- #include "utility.h"
- #include <stdlib.h>
- #include <stdio.h>
- //#include <ddraw.h>
- //#include <d3dcaps.h>
- #include <assert.h>
- #include <math.h>
- //#include <shellapi.h>
- #define D3DCOLOR_RGBA_01(r,g,b,a) D3DCOLOR_RGBA(((int)(r*255)),((int)(g*255)),((int)(b*255)),((int)(a*255)))
- #define FRAND ((rand() % 7381)/7380.0f)
- //#define D3D_OVERLOADS
- #define VERT_CLIP 0.75f // warning: top/bottom can get clipped if you go < 0.65!
- //extern CPlugin* g_plugin; // declared in main.cpp
- //extern bool g_bDebugOutput; // declared in support.cpp
- int g_title_font_sizes[] =
- {
- // NOTE: DO NOT EXCEED 64 FONTS HERE.
- 6, 8, 10, 12, 14, 16,
- 20, 26, 32, 38, 44, 50, 56,
- 64, 72, 80, 88, 96, 104, 112, 120, 128, 136, 144,
- 160, 192, 224, 256, 288, 320, 352, 384, 416, 448,
- 480, 512 /**/
- };
- //#define COMPILE_MULTIMON_STUBS 1
- //#include <multimon.h>
- // This function evaluates whether the floating-point
- // control Word is set to single precision/round to nearest/
- // exceptions disabled. If not, the
- // function changes the control Word to set them and returns
- // TRUE, putting the old control Word value in the passback
- // location pointed to by pwOldCW.
- BOOL MungeFPCW( WORD *pwOldCW )
- {
- BOOL ret = FALSE;
- WORD wTemp, wSave;
-
- __asm fstcw wSave
- if (wSave & 0x300 || // Not single mode
- 0x3f != (wSave & 0x3f) || // Exceptions enabled
- wSave & 0xC00) // Not round to nearest mode
- {
- __asm
- {
- mov ax, wSave
- and ax, not 300h ;; single mode
- or ax, 3fh ;; disable all exceptions
- and ax, not 0xC00 ;; round to nearest mode
- mov wTemp, ax
- fldcw wTemp
- }
- ret = TRUE;
- }
- if (pwOldCW) *pwOldCW = wSave;
- return ret;
- }
-
- void RestoreFPCW(WORD wSave)
- {
- __asm fldcw wSave
- }
- int GetNumToSpawn(float fTime, float fDeltaT, float fRate, float fRegularity, int iNumSpawnedSoFar)
- {
- // PARAMETERS
- // ------------
- // fTime: sum of all fDeltaT's so far (excluding this one)
- // fDeltaT: time window for this frame
- // fRate: avg. rate (spawns per second) of generation
- // fRegularity: regularity of generation
- // 0.0: totally chaotic
- // 0.2: getting chaotic / very jittered
- // 0.4: nicely jittered
- // 0.6: slightly jittered
- // 0.8: almost perfectly regular
- // 1.0: perfectly regular
- // iNumSpawnedSoFar: the total number of spawnings so far
- //
- // RETURN VALUE
- // ------------
- // The number to spawn for this frame (add this to your net count!).
- //
- // COMMENTS
- // ------------
- // The spawn values returned will, over time, match
- // (within 1%) the theoretical totals expected based on the
- // amount of time passed and the average generation rate.
- //
- // UNRESOLVED ISSUES
- // -----------------
- // actual results of mixed gen. (0 < reg < 1) are about 1% too low
- // in the long run (vs. analytical expectations). Decided not
- // to bother fixing it since it's only 1% (and VERY consistent).
-
-
- float fNumToSpawnReg;
- float fNumToSpawnIrreg;
- float fNumToSpawn;
-
- // compute # spawned based on regular generation
- fNumToSpawnReg = ((fTime + fDeltaT) * fRate) - iNumSpawnedSoFar;
-
- // compute # spawned based on irregular (random) generation
- if (fDeltaT <= 1.0f / fRate)
- {
- // case 1: avg. less than 1 spawn per frame
- if ((rand() % 16384)/16384.0f < fDeltaT * fRate)
- fNumToSpawnIrreg = 1.0f;
- else
- fNumToSpawnIrreg = 0.0f;
- }
- else
- {
- // case 2: avg. more than 1 spawn per frame
- fNumToSpawnIrreg = fDeltaT * fRate;
- fNumToSpawnIrreg *= 2.0f*(rand() % 16384)/16384.0f;
- }
-
- // get linear combo. of regular & irregular
- fNumToSpawn = fNumToSpawnReg*fRegularity + fNumToSpawnIrreg*(1.0f - fRegularity);
- // round to nearest integer for result
- return (int)(fNumToSpawn + 0.49f);
- }
- /*
- char szHelp[] =
- {
- // note: this is a string-of-null-terminated-strings; the whole thing ends with a double null termination.
- // each substring will be drawn on its own line, and the strings are drawn in BOTTOM-UP order..
- // (this is just an effort to keep the file size low)
- "ESC: exit\0"
- " \0"
- "F9: toggle stereo 3D mode\0"
- "F8: change directory/drive\0"
- "F7: refresh milk_msg.ini\0"
- "F6: show preset rating\0"
- "F5: show fps\0"
- "F4: show preset name\0"
- "F2,F3: show song title,length\0"
- "F1: show help\0"
- " \0"
- "N: show per-frame variable moNitor\0"
- "S: save preset\0"
- "M: (preset editing) menu\0"
- " \0"
- "scroll lock: locks current preset\0"
- "+/-: rate current preset\0"
- "L: load specific preset\0"
- "R: toggle random(/sequential) preset order\0"
- "H: instant Hard cut (to next preset)\0"
- "spacebar: transition to next preset\0"
- " \0"
- "left/right arrows: seek 5 sec. [+SHIFT=seek 30]\0"
- "up/down arrows: adjust volume\0"
- "P: playlist\0"
- "U: toggle shuffle\0"
- "z/x/c/v/b: prev/play/pause/stop/next\0"
- " \0"
- "Y/K: enter custom message/sprite mode [see docs!]\0"
- "##: show custom message/sprite (##=00-99)\0"
- "T: launch song title animation\0"
- "\0\0"
- };
- */
- bool CPlugin::OnResizeTextWindow()
- {
- /*
- if (!m_hTextWnd)
- return false;
- RECT rect;
- GetClientRect(m_hTextWnd, &rect);
- if (rect.right - rect.left != m_nTextWndWidth ||
- rect.bottom - rect.top != m_nTextWndHeight)
- {
- m_nTextWndWidth = rect.right - rect.left;
- m_nTextWndHeight = rect.bottom - rect.top;
- // first, resize fonts if necessary
- //if (!InitFont())
- //return false;
- // then resize the memory bitmap used for double buffering
- if (m_memDC)
- {
- SelectObject(m_memDC, m_oldBM); // delete our doublebuffer
- DeleteObject(m_memDC);
- DeleteObject(m_memBM);
- m_memDC = NULL;
- m_memBM = NULL;
- m_oldBM = NULL;
- }
-
- HDC hdc = GetDC(m_hTextWnd);
- if (!hdc) return false;
- m_memDC = CreateCompatibleDC(hdc);
- m_memBM = CreateCompatibleBitmap(hdc, rect.right - rect.left, rect.bottom - rect.top);
- m_oldBM = (HBITMAP)SelectObject(m_memDC,m_memBM);
-
- ReleaseDC(m_hTextWnd, hdc);
- // save new window pos
- WriteRealtimeConfig();
- }*/
- return true;
- }
- void CPlugin::ClearGraphicsWindow()
- {
- // clear the window contents, to avoid a 1-pixel-thick border of noise that sometimes sticks around
- /*
- RECT rect;
- GetClientRect(GetPluginWindow(), &rect);
- HDC hdc = GetDC(GetPluginWindow());
- FillRect(hdc, &rect, m_hBlackBrush);
- ReleaseDC(GetPluginWindow(), hdc);
- */
- }
- /*
- bool CPlugin::OnResizeGraphicsWindow()
- {
- // NO LONGER NEEDED, SINCE PLUGIN SHELL CREATES A NEW DIRECTX
- // OBJECT WHENEVER WINDOW IS RESIZED.
- }
- */
- bool CPlugin::RenderStringToTitleTexture() // m_szSongMessage
- {
- #if 0
- if (!m_lpDDSTitle) // this *can* be NULL, if not much video mem!
- return false;
- if (m_supertext.szText[0]==0)
- return false;
- LPDIRECT3DDEVICE8 lpDevice = GetDevice();
- if (!lpDevice)
- return false;
- char szTextToDraw[512];
- sprintf(szTextToDraw, " %s ", m_supertext.szText); //add a space @ end for italicized fonts; and at start, too, because it's centered!
-
- // Remember the original backbuffer and zbuffer
- LPDIRECT3DSURFACE8 pBackBuffer, pZBuffer;
- lpDevice->GetRenderTarget( &pBackBuffer );
- // lpDevice->GetDepthStencilSurface( &pZBuffer );
- // set render target to m_lpDDSTitle
- {
- lpDevice->SetTexture(0, NULL);
- IDirect3DSurface8* pNewTarget = NULL;
- if (m_lpDDSTitle->GetSurfaceLevel(0, &pNewTarget) != D3D_OK)
- {
- SafeRelease(pBackBuffer);
- // SafeRelease(pZBuffer);
- return false;
- }
- lpDevice->SetRenderTarget(pNewTarget, NULL);
- pNewTarget->Release();
- lpDevice->SetTexture(0, NULL);
- }
- // clear the texture to black
- {
- lpDevice->SetVertexShader( WFVERTEX_FORMAT );
- lpDevice->SetTexture(0, NULL);
- lpDevice->SetRenderState( D3DRS_ALPHABLENDENABLE, FALSE );
- // set up a quad
- WFVERTEX verts[4];
- for (int i=0; i<4; i++)
- {
- verts[i].x = (i%2==0) ? -1 : 1;
- verts[i].y = (i/2==0) ? -1 : 1;
- verts[i].z = 0;
- verts[i].Diffuse = 0xFF000000;
- }
- lpDevice->DrawPrimitiveUP(D3DPT_TRIANGLESTRIP, 2, verts, sizeof(WFVERTEX));
- }
- /*// 1. clip title if too many chars
- if (m_supertext.bIsSongTitle)
- {
- // truncate song title if too long; don't clip custom messages, though!
- int clip_chars = 32;
- int user_title_size = GetFontHeight(SONGTITLE_FONT);
- #define MIN_CHARS 8 // max clip_chars *for BIG FONTS*
- #define MAX_CHARS 64 // max clip chars *for tiny fonts*
- float t = (user_title_size-10)/(float)(128-10);
- t = min(1,max(0,t));
- clip_chars = (int)(MAX_CHARS - (MAX_CHARS-MIN_CHARS)*t);
- if ((int)strlen(szTextToDraw) > clip_chars+3)
- lstrcpy(&szTextToDraw[clip_chars], "...");
- }*/
- bool ret = true;
- // use 2 lines; must leave room for bottom of 'g' characters and such!
- RECT rect;
- rect.left = 0;
- rect.right = m_nTitleTexSizeX;
- rect.top = m_nTitleTexSizeY* 1/21; // otherwise, top of '%' could be cut off (1/21 seems safe)
- rect.bottom = m_nTitleTexSizeY*17/21; // otherwise, bottom of 'g' could be cut off (18/21 seems safe, but we want some leeway)
- if (!m_supertext.bIsSongTitle)
- {
- // custom msg -> pick font to use that will best fill the texture
- HFONT gdi_font = NULL;
- LPD3DXFONT d3dx_font = NULL;
- int lo = 0;
- int hi = sizeof(g_title_font_sizes)/sizeof(int) - 1;
-
- // limit the size of the font used:
- //int user_title_size = GetFontHeight(SONGTITLE_FONT);
- //while (g_title_font_sizes[hi] > user_title_size*2 && hi>4)
- // hi--;
- RECT temp;
- while (1)//(lo < hi-1)
- {
- int mid = (lo+hi)/2;
- // create new gdi font at 'mid' size:
- gdi_font = CreateFont(g_title_font_sizes[mid], 0, 0, 0, m_supertext.bBold ? 900 : 400, m_supertext.bItal, FALSE, FALSE, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, m_fontinfo[SONGTITLE_FONT].bAntiAliased ? ANTIALIASED_QUALITY : DEFAULT_QUALITY, DEFAULT_PITCH, m_supertext.nFontFace);
- if (gdi_font)
- {
- // create new d3dx font at 'mid' size:
- if (D3DXCreateFont(lpDevice, gdi_font, &d3dx_font) == D3D_OK)
- {
- if (lo == hi-1)
- break; // DONE; but the 'lo'-size font is ready for use!
- // compute size of text if drawn w/font of THIS size:
- temp = rect;
- int h = d3dx_font->DrawText(szTextToDraw, -1, &temp, DT_SINGLELINE | DT_CALCRECT | DT_NOPREFIX, 0xFFFFFFFF);
- // adjust & prepare to reiterate:
- if (temp.right >= rect.right || h > rect.bottom-rect.top)
- hi = mid;
- else
- lo = mid;
- SafeRelease(d3dx_font);
- }
-
- DeleteObject(gdi_font); gdi_font=NULL;
- }
- }
- if (gdi_font && d3dx_font)
- {
- // do actual drawing + set m_supertext.nFontSizeUsed; use 'lo' size
- int h = d3dx_font->DrawText(szTextToDraw, -1, &temp, DT_SINGLELINE | DT_CALCRECT | DT_NOPREFIX | DT_CENTER, 0xFFFFFFFF);
- temp.left = 0;
- temp.right = m_nTitleTexSizeX; // now allow text to go all the way over, since we're actually drawing!
- temp.top = m_nTitleTexSizeY/2 - h/2;
- temp.bottom = m_nTitleTexSizeY/2 + h/2;
- m_supertext.nFontSizeUsed = d3dx_font->DrawText(szTextToDraw, -1, &temp, DT_SINGLELINE | DT_NOPREFIX | DT_CENTER, 0xFFFFFFFF);
-
- ret = true;
- }
- else
- {
- ret = false;
- }
- // clean up font:
- SafeRelease(d3dx_font);
- if (gdi_font) DeleteObject(gdi_font); gdi_font=NULL;
- }
- else // song title
- {
- RECT temp = rect;
- // do actual drawing + set m_supertext.nFontSizeUsed; use 'lo' size
- int h = m_d3dx_title_font_doublesize->DrawText(szTextToDraw, -1, &temp, DT_SINGLELINE | DT_CALCRECT | DT_NOPREFIX | DT_CENTER | DT_END_ELLIPSIS, 0xFFFFFFFF);
- temp.left = 0;
- temp.right = m_nTitleTexSizeX; // now allow text to go all the way over, since we're actually drawing!
- temp.top = m_nTitleTexSizeY/2 - h/2;
- temp.bottom = m_nTitleTexSizeY/2 + h/2;
- m_supertext.nFontSizeUsed = m_d3dx_title_font_doublesize->DrawText(szTextToDraw, -1, &temp, DT_SINGLELINE | DT_NOPREFIX | DT_CENTER | DT_END_ELLIPSIS, 0xFFFFFFFF);
- }
- // Change the rendertarget back to the original setup
- lpDevice->SetTexture(0, NULL);
- lpDevice->SetRenderTarget( pBackBuffer, NULL );
- SafeRelease(pBackBuffer);
- SafeRelease(pZBuffer);
- return ret;
- #endif
- return false;
- }
- void CPlugin::LoadPerFrameEvallibVars(CState* pState)
- {
- // load the 'var_pf_*' variables in this CState object with the correct values.
- // for vars that affect pixel motion, that means evaluating them at time==-1,
- // (i.e. no blending w/blendto value); the blending of the file dx/dy
- // will be done *after* execution of the per-vertex code.
- // for vars that do NOT affect pixel motion, evaluate them at the current time,
- // so that if they're blending, both states see the blended value.
- // 1. vars that affect pixel motion: (eval at time==-1)
- *pState->var_pf_zoom = (double)pState->m_fZoom.eval(-1);//GetTime());
- *pState->var_pf_zoomexp = (double)pState->m_fZoomExponent.eval(-1);//GetTime());
- *pState->var_pf_rot = (double)pState->m_fRot.eval(-1);//GetTime());
- *pState->var_pf_warp = (double)pState->m_fWarpAmount.eval(-1);//GetTime());
- *pState->var_pf_cx = (double)pState->m_fRotCX.eval(-1);//GetTime());
- *pState->var_pf_cy = (double)pState->m_fRotCY.eval(-1);//GetTime());
- *pState->var_pf_dx = (double)pState->m_fXPush.eval(-1);//GetTime());
- *pState->var_pf_dy = (double)pState->m_fYPush.eval(-1);//GetTime());
- *pState->var_pf_sx = (double)pState->m_fStretchX.eval(-1);//GetTime());
- *pState->var_pf_sy = (double)pState->m_fStretchY.eval(-1);//GetTime());
- // read-only:
- *pState->var_pf_time = (double)(GetTime() - m_fStartTime);
- *pState->var_pf_fps = (double)GetFps();
- *pState->var_pf_bass = (double)mysound.imm_rel[0];
- *pState->var_pf_mid = (double)mysound.imm_rel[1];
- *pState->var_pf_treb = (double)mysound.imm_rel[2];
- *pState->var_pf_bass_att = (double)mysound.avg_rel[0];
- *pState->var_pf_mid_att = (double)mysound.avg_rel[1];
- *pState->var_pf_treb_att = (double)mysound.avg_rel[2];
- *pState->var_pf_frame = (double)GetFrame();
- //*pState->var_pf_monitor = 0; -leave this as it was set in the per-frame INIT code!
- *pState->var_pf_q1 = pState->q_values_after_init_code[0];//0.0f;
- *pState->var_pf_q2 = pState->q_values_after_init_code[1];//0.0f;
- *pState->var_pf_q3 = pState->q_values_after_init_code[2];//0.0f;
- *pState->var_pf_q4 = pState->q_values_after_init_code[3];//0.0f;
- *pState->var_pf_q5 = pState->q_values_after_init_code[4];//0.0f;
- *pState->var_pf_q6 = pState->q_values_after_init_code[5];//0.0f;
- *pState->var_pf_q7 = pState->q_values_after_init_code[6];//0.0f;
- *pState->var_pf_q8 = pState->q_values_after_init_code[7];//0.0f;
- *pState->var_pf_monitor = pState->monitor_after_init_code;
- *pState->var_pf_progress = (GetTime() - m_fPresetStartTime) / (m_fNextPresetTime - m_fPresetStartTime);
- // 2. vars that do NOT affect pixel motion: (eval at time==now)
- *pState->var_pf_decay = (double)pState->m_fDecay.eval(GetTime());
- *pState->var_pf_wave_a = (double)pState->m_fWaveAlpha.eval(GetTime());
- *pState->var_pf_wave_r = (double)pState->m_fWaveR.eval(GetTime());
- *pState->var_pf_wave_g = (double)pState->m_fWaveG.eval(GetTime());
- *pState->var_pf_wave_b = (double)pState->m_fWaveB.eval(GetTime());
- *pState->var_pf_wave_x = (double)pState->m_fWaveX.eval(GetTime());
- *pState->var_pf_wave_y = (double)pState->m_fWaveY.eval(GetTime());
- *pState->var_pf_wave_mystery= (double)pState->m_fWaveParam.eval(GetTime());
- *pState->var_pf_wave_mode = (double)pState->m_nWaveMode; //?!?! -why won't it work if set to pState->m_nWaveMode???
- *pState->var_pf_ob_size = (double)pState->m_fOuterBorderSize.eval(GetTime());
- *pState->var_pf_ob_r = (double)pState->m_fOuterBorderR.eval(GetTime());
- *pState->var_pf_ob_g = (double)pState->m_fOuterBorderG.eval(GetTime());
- *pState->var_pf_ob_b = (double)pState->m_fOuterBorderB.eval(GetTime());
- *pState->var_pf_ob_a = (double)pState->m_fOuterBorderA.eval(GetTime());
- *pState->var_pf_ib_size = (double)pState->m_fInnerBorderSize.eval(GetTime());
- *pState->var_pf_ib_r = (double)pState->m_fInnerBorderR.eval(GetTime());
- *pState->var_pf_ib_g = (double)pState->m_fInnerBorderG.eval(GetTime());
- *pState->var_pf_ib_b = (double)pState->m_fInnerBorderB.eval(GetTime());
- *pState->var_pf_ib_a = (double)pState->m_fInnerBorderA.eval(GetTime());
- *pState->var_pf_mv_x = (double)pState->m_fMvX.eval(GetTime());
- *pState->var_pf_mv_y = (double)pState->m_fMvY.eval(GetTime());
- *pState->var_pf_mv_dx = (double)pState->m_fMvDX.eval(GetTime());
- *pState->var_pf_mv_dy = (double)pState->m_fMvDY.eval(GetTime());
- *pState->var_pf_mv_l = (double)pState->m_fMvL.eval(GetTime());
- *pState->var_pf_mv_r = (double)pState->m_fMvR.eval(GetTime());
- *pState->var_pf_mv_g = (double)pState->m_fMvG.eval(GetTime());
- *pState->var_pf_mv_b = (double)pState->m_fMvB.eval(GetTime());
- *pState->var_pf_mv_a = (double)pState->m_fMvA.eval(GetTime());
- *pState->var_pf_echo_zoom = (double)pState->m_fVideoEchoZoom.eval(GetTime());
- *pState->var_pf_echo_alpha = (double)pState->m_fVideoEchoAlpha.eval(GetTime());
- *pState->var_pf_echo_orient = (double)pState->m_nVideoEchoOrientation;
- // new in v1.04:
- *pState->var_pf_wave_usedots = (double)pState->m_bWaveDots;
- *pState->var_pf_wave_thick = (double)pState->m_bWaveThick;
- *pState->var_pf_wave_additive = (double)pState->m_bAdditiveWaves;
- *pState->var_pf_wave_brighten = (double)pState->m_bMaximizeWaveColor;
- *pState->var_pf_darken_center = (double)pState->m_bDarkenCenter;
- *pState->var_pf_gamma = (double)pState->m_fGammaAdj.eval(GetTime());
- *pState->var_pf_wrap = (double)pState->m_bTexWrap;
- *pState->var_pf_invert = (double)pState->m_bInvert;
- *pState->var_pf_brighten = (double)pState->m_bBrighten;
- *pState->var_pf_darken = (double)pState->m_bDarken;
- *pState->var_pf_solarize = (double)pState->m_bSolarize;
- *pState->var_pf_meshx = (double)m_nGridX;
- *pState->var_pf_meshy = (double)m_nGridY;
- }
- void CPlugin::RunPerFrameEquations()
- {
- // run per-frame calculations
- int num_reps = (m_pState->m_bBlending) ? 2 : 1;
- for (int rep=0; rep<num_reps; rep++)
- {
- CState *pState;
- if (rep==0)
- pState = m_pState;
- else
- pState = m_pOldState;
- // values that will affect the pixel motion (and will be automatically blended
- // LATER, when the results of 2 sets of these params creates 2 different U/V
- // meshes that get blended together.)
- LoadPerFrameEvallibVars(pState);
- // also do just a once-per-frame init for the *per-**VERTEX*** *READ-ONLY* variables
- // (the non-read-only ones will be reset/restored at the start of each vertex)
- *pState->var_pv_time = *pState->var_pf_time;
- *pState->var_pv_fps = *pState->var_pf_fps;
- *pState->var_pv_frame = *pState->var_pf_frame;
- *pState->var_pv_progress = *pState->var_pf_progress;
- *pState->var_pv_bass = *pState->var_pf_bass;
- *pState->var_pv_mid = *pState->var_pf_mid;
- *pState->var_pv_treb = *pState->var_pf_treb;
- *pState->var_pv_bass_att = *pState->var_pf_bass_att;
- *pState->var_pv_mid_att = *pState->var_pf_mid_att;
- *pState->var_pv_treb_att = *pState->var_pf_treb_att;
- *pState->var_pv_meshx = (double)m_nGridX;
- *pState->var_pv_meshy = (double)m_nGridY;
- //*pState->var_pv_monitor = *pState->var_pf_monitor;
- // execute once-per-frame expressions:
- #ifndef _NO_EXPR_
- if (pState->m_pf_codehandle)
- {
- resetVars(pState->m_pf_vars);
- if (pState->m_pf_codehandle)
- {
- executeCode(pState->m_pf_codehandle);
- }
- resetVars(NULL);
- }
- #endif
- // save some things for next frame:
- pState->monitor_after_init_code = *pState->var_pf_monitor;
- // save some things for per-vertex code:
- *pState->var_pv_q1 = *pState->var_pf_q1;
- *pState->var_pv_q2 = *pState->var_pf_q2;
- *pState->var_pv_q3 = *pState->var_pf_q3;
- *pState->var_pv_q4 = *pState->var_pf_q4;
- *pState->var_pv_q5 = *pState->var_pf_q5;
- *pState->var_pv_q6 = *pState->var_pf_q6;
- *pState->var_pv_q7 = *pState->var_pf_q7;
- *pState->var_pv_q8 = *pState->var_pf_q8;
- // (a few range checks:)
- *pState->var_pf_gamma = max(0 , min( 8, *pState->var_pf_gamma ));
- *pState->var_pf_echo_zoom = max(0.001, min( 1000, *pState->var_pf_echo_zoom));
- if (m_pState->m_bRedBlueStereo || m_bAlways3D)
- {
- // override wave colors
- *pState->var_pf_wave_r = 0.35f*(*pState->var_pf_wave_r) + 0.65f;
- *pState->var_pf_wave_g = 0.35f*(*pState->var_pf_wave_g) + 0.65f;
- *pState->var_pf_wave_b = 0.35f*(*pState->var_pf_wave_b) + 0.65f;
- }
- }
- if (m_pState->m_bBlending)
- {
- // For all variables that do NOT affect pixel motion, blend them NOW,
- // so later the user can just access m_pState->m_pf_whatever.
- double mix = (double)CosineInterp(m_pState->m_fBlendProgress);
- double mix2 = 1.0 - mix;
- *m_pState->var_pf_decay = mix*(*m_pState->var_pf_decay ) + mix2*(*m_pOldState->var_pf_decay );
- *m_pState->var_pf_wave_a = mix*(*m_pState->var_pf_wave_a ) + mix2*(*m_pOldState->var_pf_wave_a );
- *m_pState->var_pf_wave_r = mix*(*m_pState->var_pf_wave_r ) + mix2*(*m_pOldState->var_pf_wave_r );
- *m_pState->var_pf_wave_g = mix*(*m_pState->var_pf_wave_g ) + mix2*(*m_pOldState->var_pf_wave_g );
- *m_pState->var_pf_wave_b = mix*(*m_pState->var_pf_wave_b ) + mix2*(*m_pOldState->var_pf_wave_b );
- *m_pState->var_pf_wave_x = mix*(*m_pState->var_pf_wave_x ) + mix2*(*m_pOldState->var_pf_wave_x );
- *m_pState->var_pf_wave_y = mix*(*m_pState->var_pf_wave_y ) + mix2*(*m_pOldState->var_pf_wave_y );
- *m_pState->var_pf_wave_mystery = mix*(*m_pState->var_pf_wave_mystery) + mix2*(*m_pOldState->var_pf_wave_mystery);
- // wave_mode: exempt (integer)
- *m_pState->var_pf_ob_size = mix*(*m_pState->var_pf_ob_size ) + mix2*(*m_pOldState->var_pf_ob_size );
- *m_pState->var_pf_ob_r = mix*(*m_pState->var_pf_ob_r ) + mix2*(*m_pOldState->var_pf_ob_r );
- *m_pState->var_pf_ob_g = mix*(*m_pState->var_pf_ob_g ) + mix2*(*m_pOldState->var_pf_ob_g );
- *m_pState->var_pf_ob_b = mix*(*m_pState->var_pf_ob_b ) + mix2*(*m_pOldState->var_pf_ob_b );
- *m_pState->var_pf_ob_a = mix*(*m_pState->var_pf_ob_a ) + mix2*(*m_pOldState->var_pf_ob_a );
- *m_pState->var_pf_ib_size = mix*(*m_pState->var_pf_ib_size ) + mix2*(*m_pOldState->var_pf_ib_size );
- *m_pState->var_pf_ib_r = mix*(*m_pState->var_pf_ib_r ) + mix2*(*m_pOldState->var_pf_ib_r );
- *m_pState->var_pf_ib_g = mix*(*m_pState->var_pf_ib_g ) + mix2*(*m_pOldState->var_pf_ib_g );
- *m_pState->var_pf_ib_b = mix*(*m_pState->var_pf_ib_b ) + mix2*(*m_pOldState->var_pf_ib_b );
- *m_pState->var_pf_ib_a = mix*(*m_pState->var_pf_ib_a ) + mix2*(*m_pOldState->var_pf_ib_a );
- *m_pState->var_pf_mv_x = mix*(*m_pState->var_pf_mv_x ) + mix2*(*m_pOldState->var_pf_mv_x );
- *m_pState->var_pf_mv_y = mix*(*m_pState->var_pf_mv_y ) + mix2*(*m_pOldState->var_pf_mv_y );
- *m_pState->var_pf_mv_dx = mix*(*m_pState->var_pf_mv_dx ) + mix2*(*m_pOldState->var_pf_mv_dx );
- *m_pState->var_pf_mv_dy = mix*(*m_pState->var_pf_mv_dy ) + mix2*(*m_pOldState->var_pf_mv_dy );
- *m_pState->var_pf_mv_l = mix*(*m_pState->var_pf_mv_l ) + mix2*(*m_pOldState->var_pf_mv_l );
- *m_pState->var_pf_mv_r = mix*(*m_pState->var_pf_mv_r ) + mix2*(*m_pOldState->var_pf_mv_r );
- *m_pState->var_pf_mv_g = mix*(*m_pState->var_pf_mv_g ) + mix2*(*m_pOldState->var_pf_mv_g );
- *m_pState->var_pf_mv_b = mix*(*m_pState->var_pf_mv_b ) + mix2*(*m_pOldState->var_pf_mv_b );
- *m_pState->var_pf_mv_a = mix*(*m_pState->var_pf_mv_a ) + mix2*(*m_pOldState->var_pf_mv_a );
- *m_pState->var_pf_echo_zoom = mix*(*m_pState->var_pf_echo_zoom ) + mix2*(*m_pOldState->var_pf_echo_zoom );
- *m_pState->var_pf_echo_alpha = mix*(*m_pState->var_pf_echo_alpha ) + mix2*(*m_pOldState->var_pf_echo_alpha );
- *m_pState->var_pf_echo_orient = (mix < 0.5f) ? *m_pOldState->var_pf_echo_orient : *m_pState->var_pf_echo_orient;
- // added in v1.04:
- *m_pState->var_pf_wave_usedots = (mix < 0.5f) ? *m_pOldState->var_pf_wave_usedots : *m_pState->var_pf_wave_usedots ;
- *m_pState->var_pf_wave_thick = (mix < 0.5f) ? *m_pOldState->var_pf_wave_thick : *m_pState->var_pf_wave_thick ;
- *m_pState->var_pf_wave_additive= (mix < 0.5f) ? *m_pOldState->var_pf_wave_additive : *m_pState->var_pf_wave_additive;
- *m_pState->var_pf_wave_brighten= (mix < 0.5f) ? *m_pOldState->var_pf_wave_brighten : *m_pState->var_pf_wave_brighten;
- *m_pState->var_pf_darken_center= (mix < 0.5f) ? *m_pOldState->var_pf_darken_center : *m_pState->var_pf_darken_center;
- *m_pState->var_pf_gamma = mix*(*m_pState->var_pf_gamma ) + mix2*(*m_pOldState->var_pf_gamma );
- *m_pState->var_pf_wrap = (mix < 0.5f) ? *m_pOldState->var_pf_wrap : *m_pState->var_pf_wrap ;
- *m_pState->var_pf_invert = (mix < 0.5f) ? *m_pOldState->var_pf_invert : *m_pState->var_pf_invert ;
- *m_pState->var_pf_brighten = (mix < 0.5f) ? *m_pOldState->var_pf_brighten : *m_pState->var_pf_brighten ;
- *m_pState->var_pf_darken = (mix < 0.5f) ? *m_pOldState->var_pf_darken : *m_pState->var_pf_darken ;
- *m_pState->var_pf_solarize = (mix < 0.5f) ? *m_pOldState->var_pf_solarize : *m_pState->var_pf_solarize ;
- }
- }
- void CPlugin::RenderFrame(int bRedraw)
- {
- int i;
- float fDeltaT = 1.0f/GetFps();
- // update time
- /*
- float fDeltaT = (GetFrame()==0) ? 1.0f/30.0f : GetTime() - m_prev_time;
- DWORD dwTime = GetTickCount();
- float fDeltaT = (dwTime - m_dwPrevTickCount)*0.001f;
- if (GetFrame() > 64)
- {
- fDeltaT = (fDeltaT)*0.2f + 0.8f*(1.0f/m_fps);
- if (fDeltaT > 2.0f/m_fps)
- {
- char buf[64];
- sprintf(buf, "fixing time gap of %5.3f seconds", fDeltaT);
- dumpmsg(buf);
- fDeltaT = 1.0f/m_fps;
- }
- }
- m_dwPrevTickCount = dwTime;
- GetTime() += fDeltaT;
- */
- if (GetFrame()==0)
- {
- m_fStartTime = GetTime();
- m_fPresetStartTime = GetTime();
- }
- if (m_fNextPresetTime < 0)
- {
- float dt = m_fTimeBetweenPresetsRand * (rand()%1000)*0.001f;
- m_fNextPresetTime = GetTime() + m_fBlendTimeAuto + m_fTimeBetweenPresets + dt;
- }
- /*
- if (m_bPresetLockedByUser || m_bPresetLockedByCode)
- {
- // if the user has the preset LOCKED, or if they're in the middle of
- // saving it, then keep extending the time at which the auto-switch will occur
- // (by the length of this frame).
- m_fPresetStartTime += fDeltaT;
- m_fNextPresetTime += fDeltaT;
- }*/
- // update fps
- /*
- if (GetFrame() < 4)
- {
- m_fps = 0.0f;
- }
- else if (GetFrame() <= 64)
- {
- m_fps = GetFrame() / (float)(GetTime() - m_fTimeHistory[0]);
- }
- else
- {
- m_fps = 64.0f / (float)(GetTime() - m_fTimeHistory[m_nTimeHistoryPos]);
- }
- m_fTimeHistory[m_nTimeHistoryPos] = GetTime();
- m_nTimeHistoryPos = (m_nTimeHistoryPos + 1) % 64;
- */
- // limit fps, if necessary
- /*
- if (m_nFpsLimit > 0 && (GetFrame() % 64) == 0 && GetFrame() > 64)
- {
- float spf_now = 1.0f / m_fps;
- float spf_desired = 1.0f / (float)m_nFpsLimit;
- float new_sleep = m_fFPSLimitSleep + (spf_desired - spf_now)*1000.0f;
-
- if (GetFrame() <= 128)
- m_fFPSLimitSleep = new_sleep;
- else
- m_fFPSLimitSleep = m_fFPSLimitSleep*0.8f + 0.2f*new_sleep;
-
- if (m_fFPSLimitSleep < 0) m_fFPSLimitSleep = 0;
- if (m_fFPSLimitSleep > 100) m_fFPSLimitSleep = 100;
- //sprintf(m_szUserMessage, "sleep=%f", m_fFPSLimitSleep);
- //m_fShowUserMessageUntilThisTime = GetTime() + 3.0f;
- }
- static float deficit;
- if (GetFrame()==0) deficit = 0;
- float ideal_sleep = (m_fFPSLimitSleep + deficit);
- int actual_sleep = (int)ideal_sleep;
- if (actual_sleep > 0)
- Sleep(actual_sleep);
- deficit = ideal_sleep - actual_sleep;
- if (deficit < 0) deficit = 0; // just in case
- if (deficit > 1) deficit = 1; // just in case
- */
- // randomly change the preset, if it's time
- if (m_fNextPresetTime < GetTime())
- {
- LoadRandomPreset(m_fBlendTimeAuto);
- }
- /*
- // randomly spawn Song Title, if time
- if (m_fTimeBetweenRandomSongTitles > 0 &&
- !m_supertext.bRedrawSuperText &&
- GetTime() >= m_supertext.fStartTime + m_supertext.fDuration + 1.0f/GetFps())
- {
- int n = GetNumToSpawn(GetTime(), fDeltaT, 1.0f/m_fTimeBetweenRandomSongTitles, 0.5f, m_nSongTitlesSpawned);
- if (n > 0)
- {
- LaunchSongTitleAnim();
- m_nSongTitlesSpawned += n;
- }
- }
- // randomly spawn Custom Message, if time
- if (m_fTimeBetweenRandomCustomMsgs > 0 &&
- !m_supertext.bRedrawSuperText &&
- GetTime() >= m_supertext.fStartTime + m_supertext.fDuration + 1.0f/GetFps())
- {
- int n = GetNumToSpawn(GetTime(), fDeltaT, 1.0f/m_fTimeBetweenRandomCustomMsgs, 0.5f, m_nCustMsgsSpawned);
- if (n > 0)
- {
- LaunchCustomMessage(-1);
- m_nCustMsgsSpawned += n;
- }
- }
- */
- // update m_fBlendProgress;
- if (m_pState->m_bBlending)
- {
- m_pState->m_fBlendProgress = (GetTime() - m_pState->m_fBlendStartTime) / m_pState->m_fBlendDuration;
- if (m_pState->m_fBlendProgress > 1.0f)
- {
- m_pState->m_bBlending = false;
- }
- }
- // handle hard cuts here (just after new sound analysis)
- static float m_fHardCutThresh;
- if (GetFrame() == 0)
- m_fHardCutThresh = m_fHardCutLoudnessThresh*2.0f;
- if (GetFps() > 1.0f && !m_bHardCutsDisabled && !m_bPresetLockedByUser && !m_bPresetLockedByCode)
- {
- if (mysound.imm_rel[0] + mysound.imm_rel[1] + mysound.imm_rel[2] > m_fHardCutThresh*3.0f)
- {
- LoadRandomPreset(0.0f);
- m_fHardCutThresh *= 2.0f;
- }
- else
- {
- float halflife_modified = m_fHardCutHalflife*0.5f;
- //thresh = (thresh - 1.5f)*0.99f + 1.5f;
- float k = -0.69315f / halflife_modified;
- float single_frame_multiplier = powf(2.7183f, k / GetFps());
- m_fHardCutThresh = (m_fHardCutThresh - m_fHardCutLoudnessThresh)*single_frame_multiplier + m_fHardCutLoudnessThresh;
- }
- }
- // smooth & scale the audio data, according to m_state, for display purposes
- float scale = m_pState->m_fWaveScale.eval(GetTime()) / 128.0f;
- mysound.fWave[0][0] *= scale;
- mysound.fWave[1][0] *= scale;
- float mix2 = m_pState->m_fWaveSmoothing.eval(GetTime());
- float mix1 = scale*(1.0f - mix2);
- for (i=1; i<576; i++)
- {
- mysound.fWave[0][i] = mysound.fWave[0][i]*mix1 + mysound.fWave[0][i-1]*mix2;
- mysound.fWave[1][i] = mysound.fWave[1][i]*mix1 + mysound.fWave[1][i-1]*mix2;
- }
- RunPerFrameEquations();
- // restore any lost surfaces
- //m_lpDD->RestoreAllSurfaces();
- LPDIRECT3DDEVICE9 lpDevice = GetDevice();
- if (!lpDevice)
- return;
- // Remember the original backbuffer and zbuffer
- LPDIRECT3DSURFACE9 pBackBuffer, pZBuffer;
- lpDevice->GetRenderTarget(0, &pBackBuffer );
- lpDevice->GetDepthStencilSurface( &pZBuffer );
- D3DSURFACE_DESC desc;
- pBackBuffer->GetDesc(&desc);
- m_backBufferWidth = desc.Width;
- m_backBufferHeight = desc.Height;
- // set up render state
- {
- DWORD texaddr = (*m_pState->var_pf_wrap) ? D3DTADDRESS_WRAP : D3DTADDRESS_CLAMP;
- lpDevice->SetRenderState(D3DRS_WRAP0, 0);
- lpDevice->SetSamplerState(0, D3DSAMP_ADDRESSU, texaddr);
- lpDevice->SetSamplerState(0, D3DSAMP_ADDRESSV, texaddr);
- lpDevice->SetSamplerState(0, D3DSAMP_ADDRESSW, texaddr);
-
- lpDevice->SetRenderState( D3DRS_SHADEMODE, D3DSHADE_GOURAUD );
- lpDevice->SetRenderState( D3DRS_SPECULARENABLE, FALSE );
- lpDevice->SetRenderState( D3DRS_CULLMODE, D3DCULL_NONE );
- lpDevice->SetRenderState( D3DRS_ZENABLE, FALSE );
- lpDevice->SetRenderState( D3DRS_ZWRITEENABLE, FALSE );
- lpDevice->SetRenderState( D3DRS_LIGHTING, FALSE );
- lpDevice->SetRenderState( D3DRS_COLORVERTEX, TRUE );
- lpDevice->SetRenderState( D3DRS_FILLMODE, D3DFILL_SOLID );
- lpDevice->SetRenderState( D3DRS_ALPHABLENDENABLE, FALSE );
- lpDevice->SetRenderState( D3DRS_AMBIENT, 0xFFFFFFFF ); //?
- // lpDevice->SetRenderState( D3DRS_CLIPPING, TRUE );
- // set min/mag/mip filtering modes; use anisotropy if available.
- if (m_bAnisotropicFiltering && (GetCaps()->TextureFilterCaps & D3DPTFILTERCAPS_MAGFANISOTROPIC))
- lpDevice->SetSamplerState(0, D3DSAMP_MAGFILTER, D3DTEXF_ANISOTROPIC);
- // else if (GetCaps()->TextureFilterCaps & D3DPTFILTERCAPS_MAGFLINEAR)
- else
- lpDevice->SetSamplerState(0, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR);
- // else
- // SetTextureStageState(0, D3DTSS_MAGFILTER, D3DTEXF_POINT);
- if (m_bAnisotropicFiltering && (GetCaps()->TextureFilterCaps & D3DPTFILTERCAPS_MINFANISOTROPIC))
- lpDevice->SetSamplerState(0, D3DSAMP_MINFILTER, D3DTEXF_ANISOTROPIC);
- else
- // else if (GetCaps()->TextureFilterCaps & D3DPTFILTERCAPS_MINFLINEAR)
- lpDevice->SetSamplerState(0, D3DSAMP_MINFILTER, D3DTEXF_LINEAR);
- // else
- // SetTextureStageState(0, D3DTSS_MINFILTER, D3DTEXF_LINEAR);
- lpDevice->SetSamplerState(0, D3DSAMP_MIPFILTER, D3DTEXF_LINEAR );
- // note: this texture stage state setup works for 0 or 1 texture.
- // if you set a texture, it will be modulated with the current diffuse color.
- // if you don't set a texture, it will just use the current diffuse color.
- lpDevice->SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_MODULATE);
- lpDevice->SetTextureStageState(0, D3DTSS_COLORARG1, D3DTA_DIFFUSE);
- lpDevice->SetTextureStageState(0, D3DTSS_COLORARG2, D3DTA_TEXTURE);
- lpDevice->SetTextureStageState(1, D3DTSS_COLOROP, D3DTOP_DISABLE);
- lpDevice->SetTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1 );
- lpDevice->SetTextureStageState(0, D3DTSS_ALPHAARG1, D3DTA_DIFFUSE );
- lpDevice->SetTextureStageState(1, D3DTSS_ALPHAOP, D3DTOP_DISABLE);
- if (GetCaps()->RasterCaps & D3DPRASTERCAPS_DITHER)
- lpDevice->SetRenderState(D3DRS_DITHERENABLE, FALSE);
- /* WISO: if (GetCaps()->RasterCaps & D3DPRASTERCAPS_ANTIALIASEDGES)
- lpDevice->SetRenderState(D3DRS_MULTISAMPLEANTIALIAS, TRUE);*/
- // NOTE: don't forget to call SetTexture and SetVertexShader before drawing!
- // Examples:
- // SPRITEVERTEX verts[4]; // has texcoords
- // lpDevice->SetTexture(0, m_sprite_tex);
- // lpDevice->SetVertexShader( SPRITEVERTEX_FORMAT );
- //
- // WFVERTEX verts[4]; // no texcoords
- // lpDevice->SetTexture(0, NULL);
- // lpDevice->SetVertexShader( WFVERTEX_FORMAT );
- }
- // render string to m_lpDDSTitle, if necessary
- if (m_supertext.bRedrawSuperText)
- {
- if (!RenderStringToTitleTexture())
- m_supertext.fStartTime = -1.0f;
- m_supertext.bRedrawSuperText = false;
- }
- // set up to render [from NULL] to VS0 (for motion vectors).
- {
- lpDevice->SetTexture(0, NULL);
- IDirect3DSurface9* pNewTarget = NULL;
- if (m_lpVS[0]->GetSurfaceLevel(0, &pNewTarget) != D3D_OK)
- return;
- lpDevice->SetRenderTarget(0, pNewTarget);
- pNewTarget->Release();
- lpDevice->SetDepthStencilSurface( NULL );
- lpDevice->SetTexture(0, NULL);
- }
- // draw motion vectors to VS0
- DrawMotionVectors();
- // set up to render [from VS0] to VS1.
- {
- lpDevice->SetTexture(0, NULL);
- IDirect3DSurface9* pNewTarget = NULL;
- if (m_lpVS[1]->GetSurfaceLevel(0, &pNewTarget) != D3D_OK)
- return;
- lpDevice->SetRenderTarget(0, pNewTarget);
- lpDevice->SetDepthStencilSurface( NULL );
- pNewTarget->Release();
- }
- // do the warping for this frame
- if (GetCaps()->RasterCaps & D3DPRASTERCAPS_DITHER)
- lpDevice->SetRenderState(D3DRS_DITHERENABLE, TRUE);
- /* WISO: if (GetCaps()->RasterCaps & D3DPRASTERCAPS_ANTIALIASEDGES)
- lpDevice->SetRenderState(D3DRS_EDGEANTIALIAS, FALSE);*/
- WarpedBlitFromVS0ToVS1();
- if (GetCaps()->RasterCaps & D3DPRASTERCAPS_DITHER)
- lpDevice->SetRenderState(D3DRS_DITHERENABLE, FALSE);
- /*if (GetCaps()->RasterCaps & D3DPRASTERCAPS_ANTIALIASEDGES)
- lpDevice->SetRenderState(D3DRS_EDGEANTIALIAS, TRUE);*/
- // draw audio data
- DrawCustomShapes(); // draw these first; better for feedback if the waves draw *over* them.
- DrawCustomWaves();
- DrawWave(mysound.fWave[0], mysound.fWave[1]);
- DrawSprites();
- // if song title animation just ended, render it into the VS:
- if (m_supertext.fStartTime >= 0 &&
- GetTime() >= m_supertext.fStartTime + m_supertext.fDuration &&
- !m_supertext.bRedrawSuperText)
- {
- m_supertext.fStartTime = -1.0f; // 'off' state
- ShowSongTitleAnim(m_nTexSize, m_nTexSize, 1.0f);
- }
- // Change the rendertarget back to the original setup
- lpDevice->SetTexture(0, NULL);
- // WISO: lpDevice->SetRenderTarget( pBackBuffer, pZBuffer );
- lpDevice->SetRenderTarget(0, pBackBuffer);
- lpDevice->SetDepthStencilSurface( pZBuffer );
- SafeRelease(pBackBuffer);
- SafeRelease(pZBuffer);
- /* WISO: if (GetCaps()->RasterCaps & D3DPRASTERCAPS_ANTIALIASEDGES)
- lpDevice->SetRenderState(D3DRS_EDGEANTIALIAS, FALSE);*/
- // show it to user
- ShowToUser(bRedraw);
- // finally, render song title animation to back buffer
- if (m_supertext.fStartTime >= 0 &&
- GetTime() < m_supertext.fStartTime + m_supertext.fDuration &&
- !m_supertext.bRedrawSuperText)
- {
- float fProgress = (GetTime() - m_supertext.fStartTime) / m_supertext.fDuration;
- ShowSongTitleAnim(GetWidth(), GetHeight(), fProgress);
- }
- DrawUserSprites();
- // flip buffers
- IDirect3DTexture9* pTemp = m_lpVS[0];
- m_lpVS[0] = m_lpVS[1];
- m_lpVS[1] = pTemp;
- /* WISO: if (GetCaps()->RasterCaps & D3DPRASTERCAPS_ANTIALIASEDGES)
- lpDevice->SetRenderState(D3DRS_EDGEANTIALIAS, FALSE);*/
- if (GetCaps()->RasterCaps & D3DPRASTERCAPS_DITHER)
- lpDevice->SetRenderState(D3DRS_DITHERENABLE, FALSE);
- }
- void CPlugin::DrawMotionVectors()
- {
- // FLEXIBLE MOTION VECTOR FIELD
- if ((float)*m_pState->var_pf_mv_a >= 0.001f)
- {
- //-------------------------------------------------------
- LPDIRECT3DDEVICE9 lpDevice = GetDevice();
- if (!lpDevice)
- return;
- lpDevice->SetTexture(0, NULL);
- lpDevice->SetFVF(WFVERTEX_FORMAT);
- //-------------------------------------------------------
- int x,y;
- int nX = (int)(*m_pState->var_pf_mv_x);// + 0.999f);
- int nY = (int)(*m_pState->var_pf_mv_y);// + 0.999f);
- float dx = (float)*m_pState->var_pf_mv_x - nX;
- float dy = (float)*m_pState->var_pf_mv_y - nY;
- if (nX > 64) { nX = 64; dx = 0; }
- if (nY > 48) { nY = 48; dy = 0; }
-
- if (nX > 0 && nY > 0)
- {
- /*
- float dx2 = m_fMotionVectorsTempDx;//(*m_pState->var_pf_mv_dx) * 0.05f*GetTime(); // 0..1 range
- float dy2 = m_fMotionVectorsTempDy;//(*m_pState->var_pf_mv_dy) * 0.05f*GetTime(); // 0..1 range
- if (GetFps() > 2.0f && GetFps() < 300.0f)
- {
- dx2 += (float)(*m_pState->var_pf_mv_dx) * 0.05f / GetFps();
- dy2 += (float)(*m_pState->var_pf_mv_dy) * 0.05f / GetFps();
- }
- if (dx2 > 1.0f) dx2 -= (int)dx2;
- if (dy2 > 1.0f) dy2 -= (int)dy2;
- if (dx2 < 0.0f) dx2 = 1.0f - (-dx2 - (int)(-dx2));
- if (dy2 < 0.0f) dy2 = 1.0f - (-dy2 - (int)(-dy2));
- // hack: when there is only 1 motion vector on the screem, to keep it in
- // the center, we gradually migrate it toward 0.5.
- dx2 = dx2*0.995f + 0.5f*0.005f;
- dy2 = dy2*0.995f + 0.5f*0.005f;
- // safety catch
- if (dx2 < 0 || dx2 > 1 || dy2 < 0 || dy2 > 1)
- {
- dx2 = 0.5f;
- dy2 = 0.5f;
- }
- m_fMotionVectorsTempDx = dx2;
- m_fMotionVectorsTempDy = dy2;*/
- float dx2 = (float)(*m_pState->var_pf_mv_dx);
- float dy2 = (float)(*m_pState->var_pf_mv_dy);
- float len_mult = (float)*m_pState->var_pf_mv_l;
- if (dx < 0) dx = 0;
- if (dy < 0) dy = 0;
- if (dx > 1) dx = 1;
- if (dy > 1) dy = 1;
- //dx = dx * 1.0f/(float)nX;
- //dy = dy * 1.0f/(float)nY;
- float inv_texsize = 1.0f/(float)m_nTexSize;
- float min_len = 1.0f*inv_texsize;
- WFVERTEX v[(64+1)*2];
- ZeroMemory(v, sizeof(WFVERTEX)*(64+1)*2);
- v[0].Diffuse = D3DCOLOR_RGBA_01((float)*m_pState->var_pf_mv_r,(float)*m_pState->var_pf_mv_g,(float)*m_pState->var_pf_mv_b,(float)*m_pState->var_pf_mv_a);
- for (x=1; x<(nX+1)*2; x++)
- v[x].Diffuse = v[0].Diffuse;
- lpDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, TRUE);
- lpDevice->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA);
- lpDevice->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA);
- for (y=0; y<nY; y++)
- {
- float fy = (y + 0.25f)/(float)(nY + dy + 0.25f - 1.0f);
- // now move by offset
- fy -= dy2;
- if (fy > 0.0001f && fy < 0.9999f)
- {
- int n = 0;
- for (x=0; x<nX; x++)
- {
- //float fx = (x + 0.25f)/(float)(nX + dx + 0.25f - 1.0f);
- float fx = (x + 0.25f)/(float)(nX + dx + 0.25f - 1.0f);
- // now move by offset
- fx += dx2;
- if (fx > 0.0001f && fx < 0.9999f)
- {
- float fx2, fy2;
- ReversePropagatePoint(fx, fy, &fx2, &fy2); // NOTE: THIS IS REALLY A REVERSE-PROPAGATION
- //fx2 = fx*2 - fx2;
- //fy2 = fy*2 - fy2;
- //fx2 = fx + 1.0f/(float)m_nTexSize;
- //fy2 = 1-(fy + 1.0f/(float)m_nTexSize);
- // enforce minimum trail lengths:
- {
- float dx = (fx2 - fx);
- float dy = (fy2 - fy);
- dx *= len_mult;
- dy *= len_mult;
- float len = sqrtf(dx*dx + dy*dy);
- if (len > min_len)
- {
- }
- else if (len > 0.00000001f)
- {
- len = min_len/len;
- dx *= len;
- dy *= len;
- }
- else
- {
- dx = min_len;
- dy = min_len;
- }
-
- fx2 = fx + dx;
- fy2 = fy + dy;
- }
- /**/
- v[n].x = fx * 2.0f - 1.0f;
- v[n].y = fy * 2.0f - 1.0f;
- v[n+1].x = fx2 * 2.0f - 1.0f;
- v[n+1].y = fy2 * 2.0f - 1.0f;
- // actually, project it in the reverse direction
- //v[n+1].x = v[n].x*2.0f - v[n+1].x;// + dx*2;
- //v[n+1].y = v[n].y*2.0f - v[n+1].y;// + dy*2;
- //v[n].x += dx*2;
- //v[n].y += dy*2;
- n += 2;
- }
- }
- // draw it
- if (n != 0)
- lpDevice->DrawPrimitiveUP(D3DPT_LINELIST, n/2, v, sizeof(WFVERTEX));
- }
- }
- lpDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, FALSE);
- }
- }
- }
- /*
- void CPlugin::UpdateSongInfo()
- {
- if (m_bShowSongTitle || m_bSongTitleAnims)
- {
- char szOldSongMessage[512];
- strcpy(szOldSongMessage, m_szSongMessage);
- if (::GetWindowText(m_hWndParent, m_szSongMessage, sizeof(m_szSongMessage)))
- {
- // remove ' - Winamp' at end
- if (strlen(m_szSongMessage) > 9)
- {
- int check_pos = strlen(m_szSongMessage) - 9;
- if (strcmp(" - Winamp", (char *)(m_szSongMessage + check_pos)) == 0)
- m_szSongMessage[check_pos] = 0;
- }
- // remove ' - Winamp [Paused]' at end
- if (strlen(m_szSongMessage) > 18)
- {
- int check_pos = strlen(m_szSongMessage) - 18;
- if (strcmp(" - Winamp [Paused]", (char *)(m_szSongMessage + check_pos)) == 0)
- m_szSongMessage[check_pos] = 0;
- }
- // remove song # and period from beginning
- char *p = m_szSongMessage;
- while (*p >= '0' && *p <= '9') p++;
- if (*p == '.' && *(p+1) == ' ')
- {
- p += 2;
- int pos = 0;
- while (*p != 0)
- {
- m_szSongMessage[pos++] = *p;
- p++;
- }
- m_szSongMessage[pos++] = 0;
- }
- // fix &'s for display
- /*
- {
- int pos = 0;
- int len = strlen(m_szSongMessage);
- while (m_szSongMessage[pos])
- {
- if (m_szSongMessage[pos] == '&')
- {
- for (int x=len; x>=pos; x--)
- m_szSongMessage[x+1] = m_szSongMessage[x];
- len++;
- pos++;
- }
- pos++;
- }
- }*/
- /*
- if (m_bSongTitleAnims &&
- ((strcmp(szOldSongMessage, m_szSongMessage) != 0) || (GetFrame()==0)))
- {
- // launch song title animation
- LaunchSongTitleAnim();
- /*
- m_supertext.bRedrawSuperText = true;
- m_supertext.bIsSongTitle = true;
- strcpy(m_supertext.szText, m_szSongMessage);
- strcpy(m_supertext.nFontFace, m_szTitleFontFace);
- m_supertext.fFontSize = (float)m_nTitleFontSize;
- m_supertext.bBold = m_bTitleFontBold;
- m_supertext.bItal = m_bTitleFontItalic;
- m_supertext.fX = 0.5f;
- m_supertext.fY = 0.5f;
- m_supertext.fGrowth = 1.0f;
- m_supertext.fDuration = m_fSongTitleAnimDuration;
- m_supertext.nColorR = 255;
- m_supertext.nColorG = 255;
- m_supertext.nColorB = 255;
- m_supertext.fStartTime = GetTime();
- */
- /* }
- }
- else
- {
- sprintf(m_szSongMessage, "<couldn't get song title>");
- }
- }
- m_nTrackPlaying = SendMessage(m_hWndParent,WM_USER, 0, 125);
- // append song time
- if (m_bShowSongTime && m_nSongPosMS >= 0)
- {
- float time_s = m_nSongPosMS*0.001f;
-
- int minutes = (int)(time_s/60);
- time_s -= minutes*60;
- int seconds = (int)time_s;
- time_s -= seconds;
- int dsec = (int)(time_s*100);
- sprintf(m_szSongTime, "%d:%02d.%02d", minutes, seconds, dsec);
- }
- // append song length
- if (m_bShowSongLen && m_nSongLenMS > 0)
- {
- int len_s = m_nSongLenMS/1000;
- int minutes = len_s/60;
- int seconds = len_s - minutes*60;
- char buf[512];
- sprintf(buf, " / %d:%02d", minutes, seconds);
- strcat(m_szSongTime, buf);
- }
- }
- */
- bool CPlugin::ReversePropagatePoint(float fx, float fy, float *fx2, float *fy2)
- {
- //float fy = y/(float)nMotionVectorsY;
- int y0 = (int)(fy*m_nGridY);
- float dy = fy*m_nGridY - y0;
- //float fx = x/(float)nMotionVectorsX;
- int x0 = (int)(fx*m_nGridX);
- float dx = fx*m_nGridX - x0;
- int x1 = x0 + 1;
- int y1 = y0 + 1;
- if (x0 < 0) return false;
- if (y0 < 0) return false;
- //if (x1 < 0) return false;
- //if (y1 < 0) return false;
- //if (x0 > m_nGridX) return false;
- //if (y0 > m_nGridY) return false;
- if (x1 > m_nGridX) return false;
- if (y1 > m_nGridY) return false;
- float tu, tv;
- tu = m_verts[y0*(m_nGridX+1)+x0].tu * (1-dx)*(1-dy);
- tv = m_verts[y0*(m_nGridX+1)+x0].tv * (1-dx)*(1-dy);
- tu += m_verts[y0*(m_nGridX+1)+x1].tu * (dx)*(1-dy);
- tv += m_verts[y0*(m_nGridX+1)+x1].tv * (dx)*(1-dy);
- tu += m_verts[y1*(m_nGridX+1)+x0].tu * (1-dx)*(dy);
- tv += m_verts[y1*(m_nGridX+1)+x0].tv * (1-dx)*(dy);
- tu += m_verts[y1*(m_nGridX+1)+x1].tu * (dx)*(dy);
- tv += m_verts[y1*(m_nGridX+1)+x1].tv * (dx)*(dy);
- *fx2 = tu;
- *fy2 = 1.0f - tv;
- return true;
- }
- void CPlugin::WarpedBlitFromVS0ToVS1()
- {
- MungeFPCW(NULL); // puts us in single-precision mode & disables exceptions
- LPDIRECT3DDEVICE9 lpDevice = GetDevice();
- if (!lpDevice)
- return;
- lpDevice->SetTexture(0, m_lpVS[0]);
- lpDevice->SetFVF( SPRITEVERTEX_FORMAT );
- // warp stuff
- float fWarpTime = GetTime() * m_pState->m_fWarpAnimSpeed;
- float fWarpScale = m_pState->m_fWarpScale.eval(GetTime());
- float fWarpScaleInv = 1.0f;
- if(fWarpScale != 0.0f)
- fWarpScaleInv = 1.0f / fWarpScale;
- float f[4];
- f[0] = 11.68f + 4.0f*cosf(fWarpTime*1.413f + 10);
- f[1] = 8.77f + 3.0f*cosf(fWarpTime*1.113f + 7);
- f[2] = 10.54f + 3.0f*cosf(fWarpTime*1.233…