Commit 947aa7ae authored by alistert's avatar alistert

Simplified Scene animation loading.

parent 9a3017d7
...@@ -381,84 +381,97 @@ int Scene::play () { ...@@ -381,84 +381,97 @@ int Scene::play () {
} else if (pages[sceneIndex].animIndex != -1) { } else if (pages[sceneIndex].animIndex != -1) {
if(currentFrame == NULL) { if (currentFrame == NULL) {
animation = animations;
animation = animations;
while (animation && (animation->id != pages[sceneIndex].animIndex))
animation = animation->next; while (animation && (animation->id != pages[sceneIndex].animIndex))
animation = animation->next;
if (animation && animation->background) {
if (animation && animation->background) {
dst.x = (canvasW - SW) >> 1; dst.x = (canvasW - SW) >> 1;
dst.y = (canvasH - SH) >> 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); SDL_BlitSurface(animation->background, NULL, canvas, &dst);
currentFrame = animation->sceneFrames; currentFrame = animation->sceneFrames;
SDL_Delay(frameDelay); SDL_Delay(frameDelay);
}
} }
else {
// Upload pixel data to the surface } else {
if (SDL_MUSTLOCK(animation->background)) SDL_LockSurface(animation->background);
// Upload pixel data to the surface
switch(currentFrame->frameType) if (SDL_MUSTLOCK(animation->background)) SDL_LockSurface(animation->background);
{
case ESquareAniHeader: switch (currentFrame->frameType) {
{
loadCompactedMem(currentFrame->frameSize, currentFrame->frameData,(unsigned char*) animation->background->pixels, SW, SH); case ESquareAniHeader:
}
break; loadCompactedMem(currentFrame->frameSize, currentFrame->frameData, (unsigned char*)animation->background->pixels, SW, SH);
case EFFAniHeader:
{ break;
unsigned char* data = currentFrame->frameData;
int size = currentFrame->frameSize; case EFFAniHeader:
loadFFMem(size, currentFrame->frameData, (unsigned char*) animation->background->pixels);
}break; loadFFMem(currentFrame->frameSize, currentFrame->frameData, (unsigned char*)animation->background->pixels);
default:
LOG("Scene::Play unknown type", currentFrame->frameType); break;
default:
LOG("Scene::Play unknown type", currentFrame->frameType);
break;
}
if (SDL_MUSTLOCK(animation->background)) SDL_UnlockSurface(animation->background);
dst.x = (canvasW - SW) >> 1;
dst.y = (canvasH - SH) >> 1;
SDL_BlitSurface(animation->background, NULL, canvas, &dst);
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; break;
} }
if (SDL_MUSTLOCK(animation->background)) SDL_UnlockSurface(animation->background);
dst.x = (canvasW - SW) >> 1;
dst.y = (canvasH - SH) >> 1;
SDL_BlitSurface(animation->background, NULL, canvas, &dst);
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;
} }
SDL_Delay(frameDelay);
if(currentFrame == NULL && animation->reverseAnimation) { }
/*prevFrame = 1-prevFrame;
lastFrame = currentFrame;
/*if(prevFrame) { if (prevFrame) currentFrame = currentFrame->prev;
currentFrame = lastFrame->prev; else currentFrame = currentFrame->next;
}
else { SDL_Delay(frameDelay);
currentFrame = lastFrame->next;
}*/ if (currentFrame == NULL && animation->reverseAnimation) {
currentFrame = NULL;//animation->sceneFrames;
} //prevFrame = 1 - prevFrame;
else if(currentFrame == NULL && !pageTime && !pages[sceneIndex].askForYesNo && pages[sceneIndex].nextPageAfterAnim) {
continueToNextPage = 1; /*if(prevFrame) currentFrame = lastFrame->prev;
} else currentFrame = lastFrame->next;*/
} currentFrame = NULL;//animation->sceneFrames;
} else if (currentFrame == NULL && !pageTime && !pages[sceneIndex].askForYesNo && pages[sceneIndex].nextPageAfterAnim) {
continueToNextPage = 1;
}
}
} else clearScreen(0); } else clearScreen(0);
......
...@@ -231,12 +231,13 @@ class Scene { ...@@ -231,12 +231,13 @@ class Scene {
// Scripts all information needed to render script pages, text etc // Scripts all information needed to render script pages, text etc
ScenePage* pages; ScenePage* pages;
void loadScripts (File* f); void loadScripts (File* f);
void loadData (File* f); void loadData (File* f);
void loadAni (File* f, int dataIndex); 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 loadCompactedMem(int size, unsigned char* frameData, unsigned char* pixdata, int width, int height); void loadFFMem (int size, unsigned char* frameData, unsigned char* pixdata);
void loadFFMem(int size, unsigned char* frameData, unsigned char* pixdata); unsigned short int loadShortMem (unsigned char **data);
public: public:
Scene (const char* fileName); Scene (const char* fileName);
~Scene (); ~Scene ();
......
This diff is collapsed.
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