1
0

rl_beathold.cpp 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. /*
  2. LICENSE
  3. -------
  4. Copyright 2005 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. #ifdef LASER
  25. #include <windows.h>
  26. #include <commctrl.h>
  27. #include "../r_defs.h"
  28. #include "../resource.h"
  29. #include <math.h>
  30. #define C_THISCLASS CLASER_BeatHoldClass
  31. #define MOD_NAME "Misc / Beat Hold"
  32. class C_THISCLASS : public C_RBASE {
  33. protected:
  34. public:
  35. C_THISCLASS();
  36. virtual ~C_THISCLASS();
  37. virtual int render(char visdata[2][2][576], int isBeat, int *framebuffer, int *fbout, int w, int h); // returns 1 if fbout has dest
  38. virtual char *get_desc() { return MOD_NAME; }
  39. virtual HWND conf(HINSTANCE hInstance, HWND hwndParent);
  40. virtual void load_config(unsigned char *data, int len);
  41. virtual int save_config(unsigned char *data);
  42. int decayMS, beatSkip;
  43. DWORD isBeatDecay;
  44. int beatCount;
  45. LineType m_linelist[1024];
  46. int linelist_used;
  47. };
  48. #define PUT_INT(y) data[pos]=(y)&255; data[pos+1]=(y>>8)&255; data[pos+2]=(y>>16)&255; data[pos+3]=(y>>24)&255; pos+=4
  49. #define GET_INT(a) if (len-pos>=4) { (a)=(data[pos]|(data[pos+1]<<8)|(data[pos+2]<<16)|(data[pos+3]<<24)); pos += 4; }
  50. void C_THISCLASS::load_config(unsigned char *data, int len)
  51. {
  52. int pos=0;
  53. int x=0;
  54. GET_INT(decayMS);
  55. GET_INT(beatSkip);
  56. }
  57. int C_THISCLASS::save_config(unsigned char *data)
  58. {
  59. int pos=0;
  60. PUT_INT(decayMS);
  61. PUT_INT(beatSkip);
  62. return pos;
  63. }
  64. C_THISCLASS::C_THISCLASS()
  65. {
  66. isBeatDecay=0;
  67. decayMS=500;
  68. beatCount=0;
  69. beatSkip=4;
  70. linelist_used=0;
  71. }
  72. C_THISCLASS::~C_THISCLASS()
  73. {
  74. }
  75. int C_THISCLASS::render(char visdata[2][2][576], int isBeat, int *framebuffer, int *fbout, int w, int h) // returns 1 if fbout has dest
  76. {
  77. if (isBeat&0x80000000) return 0;
  78. if (isBeatDecay)
  79. {
  80. if (GetTickCount() > isBeatDecay)
  81. {
  82. isBeatDecay=0;
  83. }
  84. else
  85. {
  86. g_laser_linelist->SetLines(m_linelist,0,linelist_used);
  87. g_laser_linelist->SetUsedLines(linelist_used);
  88. }
  89. }
  90. else if (isBeat && ++beatCount > beatSkip)
  91. {
  92. beatCount=0;
  93. isBeatDecay=GetTickCount()+decayMS;
  94. linelist_used=g_laser_linelist->GetUsedLines();
  95. memcpy(m_linelist,g_laser_linelist->GetLineList(),linelist_used*sizeof(LineType));
  96. }
  97. return 0;
  98. }
  99. C_RBASE *RLASER_BeatHold(char *desc)
  100. {
  101. if (desc) { strcpy(desc,MOD_NAME); return NULL; }
  102. return (C_RBASE *) new C_THISCLASS();
  103. }
  104. static C_THISCLASS *g_this;
  105. static BOOL CALLBACK g_DlgProc(HWND hwndDlg, UINT uMsg, WPARAM wParam,LPARAM lParam)
  106. {
  107. int *a=NULL;
  108. switch (uMsg)
  109. {
  110. case WM_INITDIALOG:
  111. SendDlgItemMessage(hwndDlg,IDC_SLIDER1,TBM_SETRANGEMIN,0,1);
  112. SendDlgItemMessage(hwndDlg,IDC_SLIDER1,TBM_SETRANGEMAX,0,20);
  113. SendDlgItemMessage(hwndDlg,IDC_SLIDER1,TBM_SETPOS,1,g_this->decayMS/100);
  114. SendDlgItemMessage(hwndDlg,IDC_SLIDER2,TBM_SETRANGEMIN,0,0);
  115. SendDlgItemMessage(hwndDlg,IDC_SLIDER2,TBM_SETRANGEMAX,0,16);
  116. SendDlgItemMessage(hwndDlg,IDC_SLIDER2,TBM_SETPOS,1,g_this->beatSkip);
  117. return 1;
  118. case WM_HSCROLL:
  119. {
  120. HWND swnd = (HWND) lParam;
  121. int t = (int) SendMessage(swnd,TBM_GETPOS,0,0);
  122. if (swnd == GetDlgItem(hwndDlg,IDC_SLIDER1))
  123. {
  124. g_this->decayMS=t*100;
  125. }
  126. if (swnd == GetDlgItem(hwndDlg,IDC_SLIDER2))
  127. {
  128. g_this->beatSkip=t;
  129. }
  130. }
  131. return 0;
  132. }
  133. return 0;
  134. }
  135. HWND C_THISCLASS::conf(HINSTANCE hInstance, HWND hwndParent)
  136. {
  137. g_this = this;
  138. return WASABI_API_CREATEDIALOG(IDD_CFG_LASER_BEATHOLD,hwndParent,g_DlgProc);
  139. }
  140. #endif