00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #include "pent_include.h"
00020 #include "PaletteFaderProcess.h"
00021 #include "Kernel.h"
00022 #include "Palette.h"
00023
00024 #include "IDataSource.h"
00025 #include "ODataSource.h"
00026
00027 #define PALETTEFADER_COUNTER 30
00028
00029 PaletteFaderProcess *PaletteFaderProcess::fader = 0;
00030
00031
00032 DEFINE_RUNTIME_CLASSTYPE_CODE(PaletteFaderProcess,Process)
00033
00034 PaletteFaderProcess::PaletteFaderProcess()
00035 : Process()
00036 {
00037
00038 }
00039
00040 PaletteFaderProcess::PaletteFaderProcess(Pentagram::PalTransforms trans,
00041 int priority_, int frames) : priority(priority_),
00042 counter(frames), max_counter(frames)
00043 {
00044 PaletteManager *pm = PaletteManager::get_instance();
00045 Pentagram::Palette *pal = pm->getPalette(PaletteManager::Pal_Game);
00046 for (int i = 0; i < 12; i++) old_matrix[i] = pal->matrix[i];
00047 pm->getTransformMatrix(new_matrix,trans);
00048 pal->transform = trans;
00049 }
00050
00051 PaletteFaderProcess::PaletteFaderProcess(uint32 col32, bool from,
00052 int priority_, int frames, bool current) : priority(priority_),
00053 counter(frames), max_counter(frames)
00054 {
00055 PaletteManager *pm = PaletteManager::get_instance();
00056 Pentagram::Palette *pal = pm->getPalette(PaletteManager::Pal_Game);
00057 if (!from)
00058 {
00059 if (current)
00060 for (int i = 0; i < 12; i++) old_matrix[i] = pal->matrix[i];
00061 else
00062 pm->getTransformMatrix(old_matrix,pal->transform);
00063 pm->getTransformMatrix(new_matrix,col32);
00064 }
00065 else
00066 {
00067 pm->getTransformMatrix(old_matrix,col32);
00068 if (current)
00069 for (int i = 0; i < 12; i++) new_matrix[i] = pal->matrix[i];
00070 else
00071 pm->getTransformMatrix(new_matrix,pal->transform);
00072 }
00073 }
00074
00075 PaletteFaderProcess::PaletteFaderProcess(sint16 from[12], sint16 to[12],
00076 int priority_, int frames) : priority(priority_),
00077 counter(frames), max_counter(frames)
00078 {
00079 int i;
00080 for (i = 0; i < 12; i++) old_matrix[i] = from[i];
00081 for (i = 0; i < 12; i++) new_matrix[i] = to[i];
00082 }
00083
00084 PaletteFaderProcess::~PaletteFaderProcess(void)
00085 {
00086 if (fader == this)
00087 fader = 0;
00088 }
00089
00090 bool PaletteFaderProcess::run(const uint32)
00091 {
00092 sint16 matrix[12];
00093
00094 for (int i = 0; i < 12; i++)
00095 {
00096 sint32 o = old_matrix[i] * counter;
00097 sint32 n = new_matrix[i] * (max_counter-counter);
00098 matrix[i] = static_cast<sint16>((o + n)/max_counter);
00099 }
00100
00101 PaletteManager::get_instance()->transformPalette(
00102 PaletteManager::Pal_Game,
00103 matrix);
00104
00105 if (!counter--) terminate();
00106 return true;
00107 }
00108
00109 void PaletteFaderProcess::saveData(ODataSource* ods)
00110 {
00111 Process::saveData(ods);
00112
00113 ods->write4(static_cast<uint32>(priority));
00114 ods->write4(static_cast<uint32>(counter));
00115 ods->write4(static_cast<uint32>(max_counter));
00116 unsigned int i;
00117 for (i = 0; i < 12; ++i)
00118 ods->write2(old_matrix[i]);
00119 for (i = 0; i < 12; ++i)
00120 ods->write2(new_matrix[i]);
00121 }
00122
00123 bool PaletteFaderProcess::loadData(IDataSource* ids, uint32 version)
00124 {
00125 if (!Process::loadData(ids, version)) return false;
00126
00127 priority = static_cast<int>(ids->read4());
00128 counter = static_cast<int>(ids->read4());
00129 max_counter = static_cast<int>(ids->read4());
00130
00131 unsigned int i;
00132 for (i = 0; i < 12; ++i)
00133 old_matrix[i] = ids->read2();
00134 for (i = 0; i < 12; ++i)
00135 new_matrix[i] = ids->read2();
00136
00137 fader = this;
00138 return true;
00139 }
00140
00141 uint32 PaletteFaderProcess::I_fadeToPaletteTransform(const uint8* args,
00142 unsigned int )
00143 {
00144 ARG_UINT16(transform);
00145 ARG_UINT16(priority);
00146
00147
00148 if (fader && fader->priority > priority) return 0;
00149 else if (fader) fader->terminate();
00150
00151 fader = new PaletteFaderProcess(static_cast<Pentagram::PalTransforms>(transform),
00152 priority, 45);
00153
00154 return Kernel::get_instance()->addProcess(fader);
00155 }
00156
00157 uint32 PaletteFaderProcess::I_fadeToBlack(const uint8* ,
00158 unsigned int )
00159 {
00160 if (fader && fader->priority > 0x7FFF) return 0;
00161 else if (fader) fader->terminate();
00162
00163 fader = new PaletteFaderProcess(0x00000000, false, 0x7FFF, 30, true);
00164 return Kernel::get_instance()->addProcess(fader);
00165 }
00166
00167 uint32 PaletteFaderProcess::I_fadeFromBlack(const uint8* ,
00168 unsigned int )
00169 {
00170 if (fader && fader->priority > 0x7FFF) return 0;
00171 else if (fader) fader->terminate();
00172
00173 fader = new PaletteFaderProcess(0x00000000, true, 0x7FFF, 30, false);
00174 return Kernel::get_instance()->addProcess(fader);
00175 }
00176
00177 uint32 PaletteFaderProcess::I_fadeToWhite(const uint8* ,
00178 unsigned int )
00179 {
00180 if (fader && fader->priority > 0x7FFF) return 0;
00181 else if (fader) fader->terminate();
00182
00183 fader = new PaletteFaderProcess(0x00FFFFFF, false, 0x7FFF, 30, true);
00184 return Kernel::get_instance()->addProcess(fader);
00185 }
00186
00187 uint32 PaletteFaderProcess::I_fadeFromWhite(const uint8* ,
00188 unsigned int )
00189 {
00190 if (fader && fader->priority > 0x7FFF) return 0;
00191 else if (fader) fader->terminate();
00192
00193 fader = new PaletteFaderProcess(0x00FFFFFF, true, 0x7FFF, 30, false);
00194 return Kernel::get_instance()->addProcess(fader);
00195 }
00196
00197 uint32 PaletteFaderProcess::I_lightningBolt(const uint8* ,
00198 unsigned int )
00199 {
00200 if (fader && fader->priority > -1) return 0;
00201 else if (fader) fader->terminate();
00202
00203 fader = new PaletteFaderProcess(0x3FCFCFCF, true, -1, 10, false);
00204 return Kernel::get_instance()->addProcess(fader);
00205 }
00206