Commit 947aa7ae authored by alistert's avatar alistert

Simplified Scene animation loading.

parent 9a3017d7
......@@ -381,7 +381,8 @@ int Scene::play () {
} else if (pages[sceneIndex].animIndex != -1) {
if(currentFrame == NULL) {
if (currentFrame == NULL) {
animation = animations;
while (animation && (animation->id != pages[sceneIndex].animIndex))
......@@ -391,32 +392,38 @@ int Scene::play () {
dst.x = (canvasW - SW) >> 1;
dst.y = (canvasH - SH) >> 1;
frameDelay = 1000/(pages[sceneIndex].animSpeed>>8);
frameDelay = 1000 / (pages[sceneIndex].animSpeed >> 8);
SDL_BlitSurface(animation->background, NULL, canvas, &dst);
currentFrame = animation->sceneFrames;
SDL_Delay(frameDelay);
}
}
else {
} else {
// Upload pixel data to the surface
if (SDL_MUSTLOCK(animation->background)) SDL_LockSurface(animation->background);
switch(currentFrame->frameType)
{
switch (currentFrame->frameType) {
case ESquareAniHeader:
{
loadCompactedMem(currentFrame->frameSize, currentFrame->frameData,(unsigned char*) animation->background->pixels, SW, SH);
}
loadCompactedMem(currentFrame->frameSize, currentFrame->frameData, (unsigned char*)animation->background->pixels, SW, SH);
break;
case EFFAniHeader:
{
unsigned char* data = currentFrame->frameData;
int size = currentFrame->frameSize;
loadFFMem(size, currentFrame->frameData, (unsigned char*) animation->background->pixels);
}break;
loadFFMem(currentFrame->frameSize, currentFrame->frameData, (unsigned char*)animation->background->pixels);
break;
default:
LOG("Scene::Play unknown type", currentFrame->frameType);
break;
}
if (SDL_MUSTLOCK(animation->background)) SDL_UnlockSurface(animation->background);
......@@ -425,39 +432,45 @@ int Scene::play () {
dst.y = (canvasH - SH) >> 1;
SDL_BlitSurface(animation->background, NULL, canvas, &dst);
if(currentFrame->soundId != -1 && animation->noSounds > 0) {
if (currentFrame->soundId != -1 && animation->noSounds > 0) {
LOG("PLAY SOUND NAME",animation->soundNames[currentFrame->soundId-1]);
// Search for matching sound
for (int y = 0; y < nSounds ; y++) {
if (!strcmp(animation->soundNames[currentFrame->soundId-1], sounds[y].name)) {
playSound(y);
break;
}
}
}
lastFrame = currentFrame;
if(prevFrame) {
currentFrame = currentFrame->prev;
}
else {
currentFrame = currentFrame->next;
}
if (prevFrame) currentFrame = currentFrame->prev;
else currentFrame = currentFrame->next;
SDL_Delay(frameDelay);
if(currentFrame == NULL && animation->reverseAnimation) {
/*prevFrame = 1-prevFrame;
/*if(prevFrame) {
currentFrame = lastFrame->prev;
}
else {
currentFrame = lastFrame->next;
}*/
if (currentFrame == NULL && animation->reverseAnimation) {
//prevFrame = 1 - prevFrame;
/*if(prevFrame) currentFrame = lastFrame->prev;
else currentFrame = lastFrame->next;*/
currentFrame = NULL;//animation->sceneFrames;
}
else if(currentFrame == NULL && !pageTime && !pages[sceneIndex].askForYesNo && pages[sceneIndex].nextPageAfterAnim) {
} else if (currentFrame == NULL && !pageTime && !pages[sceneIndex].askForYesNo && pages[sceneIndex].nextPageAfterAnim) {
continueToNextPage = 1;
}
}
} else clearScreen(0);
......
......@@ -234,9 +234,10 @@ class Scene {
void loadScripts (File* f);
void loadData (File* f);
void loadAni (File* f, int dataIndex);
void loadCompacted(int size, File* f, unsigned char* pixdata, int width, int height);
void loadCompactedMem(int size, unsigned char* frameData, unsigned char* pixdata, int width, int height);
void loadFFMem(int size, unsigned char* frameData, unsigned char* pixdata);
void loadCompactedMem (int size, unsigned char* frameData, unsigned char* pixdata, int width, int height);
void loadFFMem (int size, unsigned char* frameData, unsigned char* pixdata);
unsigned short int loadShortMem (unsigned char **data);
public:
Scene (const char* fileName);
~Scene ();
......
......@@ -33,11 +33,27 @@
#include <string.h>
void Scene::loadFFMem(int size, unsigned char* frameData, unsigned char* pixdata) {
unsigned short int Scene::loadShortMem (unsigned char** data) {
unsigned short int val;
val = **data;
(*data)++;
val += ((unsigned short)(**data)) << 8;
(*data)++;
return val;
}
void Scene::loadFFMem (int size, unsigned char* frameData, unsigned char* pixdata) {
int pixels = 0;
int fillWidth = 0;
unsigned char fillColor = 0;
int trans = 1;
bool trans = true;
int opCodeNo = 0;
unsigned char* repeatPos = NULL;
unsigned char* startPix = pixdata;
......@@ -48,149 +64,112 @@ void Scene::loadFFMem(int size, unsigned char* frameData, unsigned char* pixdata
fclose(out);*/
while (size > 0 && pixels < 64000) {
LOG("PL FF frame offset",(frameData-framestart));
LOG("PL FF frame offset", frameData - framestart);
opCodeNo++;
fflush(stderr);
unsigned char header = *frameData;frameData++;
unsigned char header = *frameData;
frameData++;
if(header == 0xFF) {
unsigned short skip = *frameData;frameData++;
skip+=((unsigned short)(*frameData))<<8;frameData++;
if(trans) {
skip+=255;
}
LOG("PL FF 0xff skip", skip);
pixels+=skip;
pixdata+=skip;
size -= 2;
trans = 0;
}
else if (header == 0x7f) {
fillWidth = *frameData;frameData++;
fillWidth+=((unsigned short)(*frameData))<<8;frameData++;
if ((header & 0x7F) == 0x7F) {
if(trans) {
fillWidth+=255;
}
//fillColor = *frameData;frameData++;
fillWidth = loadShortMem(&frameData);
if (trans) fillWidth += 255;
if (header & 0x80) {
LOG("PL FF 0xff skip", fillWidth);
} else {
fillColor = *frameData;
frameData++;
//memset(pixdata, fillColor, fillWidth);
LOG("PL FF 0x7f fillWidth", fillWidth);
pixels+=fillWidth;
pixdata+=fillWidth;
size-=2;
trans = 1;
}
else if ((header & 0xe0) == 0xe0) {
LOG("PL FF 0xe0 skip", header);
pixels+=header;
pixdata+=header;
trans = 0;
}
else if ((header & 0xA0) == 0xA0) {
fillWidth = (header-0xA0);
LOG("PL FF 0xa0 fill next op",fillWidth);
// fill ?
unsigned char* readfill = pixdata-320;
for(int col = 0;col < fillWidth;col++) {
*pixdata = *readfill;
pixels++;
pixdata++;
readfill++;
}
trans = 0;
}
else if ((header & 0xC0) == 0xc0) {
fillWidth = (header - 0xC0);
LOG("PL FF 0xc0 fillWidth", fillWidth);
fillColor = *frameData;frameData++;
memset(pixdata, fillColor, fillWidth);
pixdata+=fillWidth;
pixels+=fillWidth;
size--;
trans = 0;
}
else if (header & 0x80) {
fillWidth = (header-0x80);
if(trans) {
LOG("PL FF 0x8? SKIP bytes",fillWidth);
pixels+=(fillWidth);
pixdata+=(fillWidth);
}
else {
LOG("PL FF 0x8? Copy bytes", fillWidth);
for(int col = 0;col < fillWidth;col++) {
fillColor= *frameData;frameData++;
*pixdata = fillColor;
pixels++;
pixdata++;
size--;
}
size -= 2;
} else if (header) {
fillWidth = header & 0x1F;
switch (header & 0x60) {
case 0x00:
if (trans) {
LOG("PL FF 0x00 SKIP bytes", header);
} else {
LOG("PL FF 0x00 Copy bytes", header);
memcpy(pixdata, frameData, fillWidth);
frameData += fillWidth;
size -= fillWidth;
}
trans = 1-trans;
}
else if (header & 0x40) {
fillWidth = (header-0x40);
fillColor = *frameData;frameData++;
memset(pixdata, fillColor, fillWidth);
break;
case 0x20:
LOG("PL FF 0x20 fill next op", fillWidth);
if (pixdata - 320 >= startPix) memcpy(pixdata, pixdata - 320, fillWidth);
break;
case 0x40:
LOG("PL FF 0x40 fillWidth", fillWidth);
pixels+=fillWidth;
pixdata+=fillWidth;
fillColor = *frameData;
frameData++;
memset(pixdata, fillColor, fillWidth);
size--;
trans = 1;
}
else if (header & 0x20)
{
// fill ?
unsigned char* readfill = pixdata-320;
fillWidth = header-0x20;
for(int col = 0;col < fillWidth;col++) {
*pixdata = *readfill;
pixels++;
pixdata++;
readfill++;
}
break;
LOG("PL FF Fill 0x20 ", (header-0x20));
case 0x60:
trans = 1;
}
else if(header) {
if(trans) {
LOG("PL FF 0x0? SKIP bytes", header);
pixels+=(header);
pixdata+=(header);
}
else {
LOG("PL FF 0x0? Copy bytes", header);
for(int col = 0;col < (header);col++) {
fillColor= *frameData;frameData++;
*pixdata = fillColor;
LOG("PL FF 0x60 skip", header);
pixels++;
pixdata++;
size--;
}
break;
}
trans = 1-trans;
}
else
{
} else {
fillWidth = 0;
size = 1; // end
LOG("PL FF END OF STREAM", size);
}
pixdata += fillWidth;
pixels += fillWidth;
if (header & 0x80) trans = false;
else trans = !trans;
size--;
SDL_Rect dst;
dst.x = (canvasW - SW) >> 1;
dst.y = (canvasH - SH) >> 1;
}
LOG("PL FF pixels", pixels);
}
}
/*
* $0x $... Next x + 1 bytes are 'literals'; each byte colors 1 column (Max val $3F)
......@@ -199,167 +178,114 @@ void Scene::loadFFMem(int size, unsigned char* frameData, unsigned char* pixdata
* $8x Next x + 1 pixels are skipped, they're already the right color (Max val $FE)
* $FF $xxxx Skip next xxxx pixels of picture, they're already the right color
*/
void Scene::loadCompacted(int size, File* f, unsigned char* pixdata, int width, int height) {
void Scene::loadCompactedMem (int size, unsigned char* frameData, unsigned char* pixdata, int width, int height) {
int pixels = 0;
unsigned char* endpixdata = pixdata + (width*height);
int fillWidth = 0;
unsigned char* endpixdata = pixdata + (width * height);
unsigned char* fillstart = NULL;
while (size > 0) {
unsigned char header = f->loadChar();
unsigned char header = *frameData;
frameData++;
switch (header) {
case 0x7F: {
unsigned short fillWidth = f->loadShort();
unsigned char fillColor = f->loadChar();
case 0x7F:
{
fillWidth = loadShortMem(&frameData);
unsigned char fillColor = *frameData;
frameData++;
fillstart = pixdata;
while(fillstart+fillWidth < endpixdata) {
while (fillstart + fillWidth < endpixdata) {
memset(fillstart, fillColor, fillWidth);
fillstart+=width;
}
pixdata+=fillWidth;
pixels+=fillWidth;
size -= 3;
}
break;
case 0xff: {
unsigned short skip = f->loadShort();
pixels+=skip;
pixdata+=skip;
case 0xFF:
fillWidth = loadShortMem(&frameData);
size -= 2;
}
break;
default:
if(header&0x80) {
unsigned short skip =(header-0x80)+1;
pixels+=skip;
pixdata+=skip;
}
else if(header&0x40) {
unsigned char fillColor = f->loadChar();
unsigned char fillWidth = ((header-0x40)+1);
fillstart = pixdata;
while(fillstart+fillWidth < endpixdata) {
memset(fillstart, fillColor, fillWidth);
fillstart+=width;
}
pixdata+=fillWidth;
pixels+=fillWidth;
size--;
}
else {
int copyWidth = (header & 0x3f)+1;
unsigned char color;
if (header & 0x80) {
for(int col = 0;col < copyWidth;col++) {
color= f->loadChar();
if(color != 0xff){
fillstart = pixdata;
fillWidth = (header - 0x80) + 1;
while(fillstart < endpixdata) {
*fillstart = color;
fillstart+=width;
}
}
pixdata++;
pixels++;
size--;
}
}
break;
}
} else if (header & 0x40) {
size--;
}
unsigned char fillColor = *frameData;
frameData++;
fillWidth = (header - 0x40) + 1;
LOG("PL Compacts pixels", pixels);
}
void Scene::loadCompactedMem(int size, unsigned char* frameData, unsigned char* pixdata, int width, int height) {
int pixels = 0;
unsigned char* endpixdata = pixdata + (width*height);
unsigned char* fillstart = NULL;
while (size > 0) {
unsigned char header = *frameData;frameData++;
fillstart = pixdata;
switch (header) {
case 0x7F: {
unsigned short fillWidth = *frameData;frameData++;
fillWidth+=((unsigned short)(*frameData))<<8;frameData++;
unsigned char fillColor = *frameData;frameData++;
while (fillstart + fillWidth < endpixdata) {
fillstart = pixdata;
while(fillstart+fillWidth < endpixdata) {
memset(fillstart, fillColor, fillWidth);
fillstart+=width;
}
fillstart += width;
pixdata+=fillWidth;
pixels+=fillWidth;
size -= 3;
}
break;
case 0xff: {
unsigned short skip = *frameData;frameData++;
skip+=((unsigned short)(*frameData))<<8;frameData++;
pixels+=skip;
pixdata+=skip;
size -= 2;
}
size--;
break;
} else {
default:
if(header&0x80) {
unsigned short skip =(header-0x80)+1;
pixels+=skip;
pixdata+=skip;
}
else if(header&0x40) {
unsigned char fillColor = *frameData;frameData++;
unsigned char fillWidth = ((header-0x40)+1);
fillWidth = (header & 0x3F) + 1;
unsigned char color;
fillstart = pixdata;
for (int col = 0; col < fillWidth; col++) {
while(fillstart+fillWidth < endpixdata) {
memset(fillstart, fillColor, fillWidth);
fillstart+=width;
}
color = *frameData;
frameData++;
pixdata+=fillWidth;
pixels+=fillWidth;
size--;
}
else {
int copyWidth = (header & 0x3f)+1;
unsigned char color;
if (color != 0xFF) {
for(int col = 0;col < copyWidth;col++) {
color= *frameData;frameData++;
if(color != 0xff){
fillstart = pixdata;
while(fillstart < endpixdata) {
while (fillstart < endpixdata) {
*fillstart = color;
fillstart+=width;
fillstart += width;
}
}
pixdata++;
pixels++;
size--;
}
pixdata -= fillWidth;
}
break;
}
pixdata += fillWidth;
pixels += fillWidth;
size--;
}
LOG("PL Compacts pixels", pixels);
......@@ -448,7 +374,10 @@ void Scene::loadAni (File *f, int dataIndex) {
unsigned char* pixels;
pixels = new unsigned char[SW* SH];
memset(pixels, 0, SW*SH);
loadCompacted(size, f, pixels, SW, SH);
unsigned char* frameData;
frameData = f->loadBlock(size);
loadCompactedMem(size, frameData, pixels, SW, SH);
delete[] frameData;
animations->background = createSurface(pixels, SW, SH);
delete[] pixels;
// Use the most recently loaded palette
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment