summaryrefslogtreecommitdiff
path: root/src/T2DLL/T2PaletteAnime.cpp
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/T2DLL/T2PaletteAnime.cpp220
1 files changed, 220 insertions, 0 deletions
diff --git a/src/T2DLL/T2PaletteAnime.cpp b/src/T2DLL/T2PaletteAnime.cpp
new file mode 100644
index 0000000..da9fc8e
--- /dev/null
+++ b/src/T2DLL/T2PaletteAnime.cpp
@@ -0,0 +1,220 @@
+#include "GlobalFunc.h"
+#include "T2DateTime.h"
+#include "T2DayLightFilter.h"
+#include "T2PaletteAnime.h"
+#include "T2PaletteAnimeDef.h"
+#include "T2TowerDoc.h"
+#include "T2TowerMainView.h"
+#include "T2WeatherFilter.h"
+#include "T2WorldDef.h"
+
+T2PaletteAnime::T2PaletteAnime(T2WorldDef* worldDef, T2DateTime* dateTime) {
+ Init();
+
+ mWorldDef = worldDef;
+ mWorldPlugin = (T2WorldPlugin *) mWorldDef->GetPlugin();
+ mPaletteAnimeDef = worldDef->GetPaletteAnimeDef();
+ mInterCTab = MakeInterCTab();
+ mDayLightFilter = new T2DayLightFilter;
+ mWeatherFilter = new T2WeatherFilter;
+
+ AdjustWindowColor(dateTime);
+}
+
+void T2PaletteAnime::Init() {
+ mWorldDef = NULL;
+ mWorldPlugin = NULL;
+ mPaletteAnimeDef = NULL;
+ mInterCTab = NULL;
+ mPaletteUpdated = false;
+ mSkyState = 0;
+ mSkyCount = 0;
+ mSECount = 0;
+ mSEKind = 0;
+ mSETimeNextTick = 0;
+ mDayLightFilter = NULL;
+ mWeatherFilter = NULL;
+}
+
+/*virtual*/ T2PaletteAnime::~T2PaletteAnime() {
+ if (mInterCTab)
+ free(mInterCTab);
+ if (mDayLightFilter)
+ delete mDayLightFilter;
+ if (mWeatherFilter)
+ delete mWeatherFilter;
+}
+
+LOGPALETTE* T2PaletteAnime::MakeInterCTab() {
+ LOGPALETTE *pal = (LOGPALETTE *) malloc(sizeof(LOGPALETTE) + sizeof(PALETTEENTRY) * 256);
+
+ for (int i = 0; i < 256; i++) {
+ pal->palPalEntry[i].peRed = 0;
+ pal->palPalEntry[i].peGreen = 0;
+ pal->palPalEntry[i].peBlue = 0;
+ if (i < mPaletteAnimeDef->GetNumOfAnimColor())
+ pal->palPalEntry[i].peFlags = PC_RESERVED;
+ else
+ pal->palPalEntry[i].peFlags = 0;
+ }
+
+ pal->palVersion = 0x300; // is there a GDI constant for this?
+ pal->palNumEntries = 256;
+
+ return pal;
+}
+
+BOOL T2PaletteAnime::IsSETime() {
+ BOOL result = false;
+ DWORD now = TickCount();
+
+ if (mSETimeNextTick <= now) {
+ mSETimeNextTick = now + 2;
+ mSECount++;
+ if (mSECount >= 60)
+ mSECount = 0;
+ result = true;
+ }
+
+ return result;
+}
+
+void T2PaletteAnime::ChangeSE() {
+ mPaletteUpdated = mWorldDef->ChangeFastSEProc(this) == BOOL3_1;
+
+ if ((mSECount % mPaletteAnimeDef->GetSEInterval()) == 0) {
+ mSEKind++;
+ if (mSEKind >= mPaletteAnimeDef->GetNumOfSEKind())
+ mSEKind = 0;
+
+ int numOfSEColor = mPaletteAnimeDef->GetNumOfSEColor();
+ int interStartIndex = mPaletteAnimeDef->GetNumOfRefrectColor() + mPaletteAnimeDef->GetNumOfSkyColor();
+ int seStartIndex = numOfSEColor * mSEKind;
+ LOGPALETTE *sePal = mPaletteAnimeDef->GetSEPalette();
+
+ for (int i = 0; i < numOfSEColor; i++) {
+ mInterCTab->palPalEntry[interStartIndex + i].peRed = sePal->palPalEntry[seStartIndex + i].peRed;
+ mInterCTab->palPalEntry[interStartIndex + i].peGreen = sePal->palPalEntry[seStartIndex + i].peGreen;
+ mInterCTab->palPalEntry[interStartIndex + i].peBlue = sePal->palPalEntry[seStartIndex + i].peBlue;
+ }
+
+ mWorldDef->ChangeSEProc(this);
+ mPaletteUpdated = true;
+ }
+}
+
+void T2PaletteAnime::RotateDayLightPalette(unsigned int start, unsigned int count) const {
+ RotatePalette(mPaletteAnimeDef->GetDayLightPalette(), start, count);
+ RotatePalette(mInterCTab, start, count);
+}
+
+void T2PaletteAnime::RotatePalette(LOGPALETTE* pal, unsigned int start, unsigned int count) const {
+ PALETTEENTRY save = pal->palPalEntry[start];
+
+ for (unsigned int i = start + 1; i < (start + count); i++) {
+ PALETTEENTRY entry = pal->palPalEntry[i];
+ pal->palPalEntry[i - 1] = entry;
+ }
+
+ pal->palPalEntry[start + count - 1] = save;
+}
+
+void T2PaletteAnime::AdjustSkyState(T2DateTime* dateTime) {
+ if (mWorldDef->AdjustSkyStateProc(this, dateTime) == BOOL3_NEG1) {
+ mDayLightFilter->SetTime(0, (dateTime->GetRawMinutes() * 1000) / 1440);
+ }
+}
+
+BOOL T2PaletteAnime::IsChangeSkyTime() {
+ BOOL result = false;
+
+ if (mSkyCount > 0) {
+ mSkyCount--;
+ if ((mSkyCount % 6) == 0)
+ result = true;
+ }
+
+ return result;
+}
+
+void T2PaletteAnime::ChangeSkyColor() {
+ BOOL3 result = mWorldDef->ChangeSkyColorProc(this);
+ if (result == BOOL3_1) {
+ mPaletteUpdated = true;
+ } else if (result == BOOL3_NEG1) {
+ int i;
+ int numOfSkyColor = mPaletteAnimeDef->GetNumOfSkyColor();
+ int numOfRefrectColor = mPaletteAnimeDef->GetNumOfRefrectColor();
+ LOGPALETTE *dayLightPalette = mPaletteAnimeDef->GetDayLightPalette();
+
+ for (i = 0; i < numOfSkyColor; i++) {
+ RGBQUAD c;
+ c.rgbRed = dayLightPalette->palPalEntry[i].peRed;
+ c.rgbGreen = dayLightPalette->palPalEntry[i].peGreen;
+ c.rgbBlue = dayLightPalette->palPalEntry[i].peBlue;
+ mDayLightFilter->SkyColor(&c);
+ mInterCTab->palPalEntry[i].peRed = c.rgbRed;
+ mInterCTab->palPalEntry[i].peGreen = c.rgbGreen;
+ mInterCTab->palPalEntry[i].peBlue = c.rgbBlue;
+ }
+
+ for (i = 0; i < numOfRefrectColor; i++) {
+ RGBQUAD c;
+ c.rgbRed = dayLightPalette->palPalEntry[i + numOfSkyColor].peRed;
+ c.rgbGreen = dayLightPalette->palPalEntry[i + numOfSkyColor].peGreen;
+ c.rgbBlue = dayLightPalette->palPalEntry[i + numOfSkyColor].peBlue;
+ mDayLightFilter->RefractionColor(&c);
+ mInterCTab->palPalEntry[i + numOfSkyColor].peRed = c.rgbRed;
+ mInterCTab->palPalEntry[i + numOfSkyColor].peGreen = c.rgbGreen;
+ mInterCTab->palPalEntry[i + numOfSkyColor].peBlue = c.rgbBlue;
+ }
+
+ mPaletteUpdated = true;
+ }
+}
+
+void T2PaletteAnime::MinuteChanged(T2DateTime* dateTime) {
+ unsigned int minute = dateTime->GetMinutes();
+ if (mWorldDef->UseOwnSkyPaletteFunction()) {
+ if (minute == 1)
+ AdjustSkyState(dateTime);
+ if (IsChangeSkyTime())
+ ChangeSkyColor();
+ } else {
+ if ((minute % 6) == 0) {
+ AdjustSkyState(dateTime);
+ ChangeSkyColor();
+ }
+ }
+}
+
+void T2PaletteAnime::DoAnimatePalette() {
+ if (mPaletteUpdated) {
+ GetCurrentT2TowerDoc()->towerDoc_vf11C(
+ mPaletteAnimeDef->GetAnimStartIndex(),
+ mPaletteAnimeDef->GetNumOfAnimColor(),
+ mInterCTab->palPalEntry
+ );
+ mPaletteUpdated = false;
+ }
+}
+
+void T2PaletteAnime::ReplaceDayLightPalette(int id) {
+ mPaletteAnimeDef->ReplaceDayLightPalette(mWorldDef->mModuleHandle, id);
+ mPaletteUpdated = false;
+}
+
+void T2PaletteAnime::SetSkyState(int skyState, int skyCount) {
+ if (mSkyState != skyState)
+ GetCurrentT2TowerDoc()->GetTowerMainView()->tmv_vf124(true);
+
+ mSkyState = skyState;
+ mSkyCount = skyCount;
+}
+
+void T2PaletteAnime::AdjustWindowColor(T2DateTime* dateTime) {
+ AdjustSkyState(dateTime);
+ ChangeSkyColor();
+ ChangeSE();
+ DoAnimatePalette();
+}