Commit 411eaa5a authored by alistert's avatar alistert

Cutscene refactoring. Fixed in-game gfx stats.

parent 1174dd9f
...@@ -13,7 +13,8 @@ objects = src/bonus/bonus.o \ ...@@ -13,7 +13,8 @@ objects = src/bonus/bonus.o \
src/menu/gamemenu.o src/menu/mainmenu.o src/menu/menu.o \ src/menu/gamemenu.o src/menu/mainmenu.o src/menu/menu.o \
src/menu/menuutil.o src/menu/setupmenu.o \ src/menu/menuutil.o src/menu/setupmenu.o \
src/player/bird.o src/player/player.o src/player/playerframe.o \ src/player/bird.o src/player/player.o src/player/playerframe.o \
src/main.o src/movable.o src/planet.o src/scene.o src/util.o \ src/scene/scene.o src/scene/sceneload.o \
src/main.o src/movable.o src/planet.o src/util.o \
src/io/gfx/scale2x/getopt.o src/io/gfx/scale2x/pixel.o \ src/io/gfx/scale2x/getopt.o src/io/gfx/scale2x/pixel.o \
src/io/gfx/scale2x/scale2x.o src/io/gfx/scale2x/scale3x.o \ src/io/gfx/scale2x/scale2x.o src/io/gfx/scale2x/scale3x.o \
src/io/gfx/scale2x/scalebit.o src/io/gfx/scale2x/simple2x.o src/io/gfx/scale2x/scalebit.o src/io/gfx/scale2x/simple2x.o
......
...@@ -37,7 +37,8 @@ OBJS = src/bonus/bonus.o \ ...@@ -37,7 +37,8 @@ OBJS = src/bonus/bonus.o \
src/menu/gamemenu.o src/menu/mainmenu.o src/menu/menu.o \ src/menu/gamemenu.o src/menu/mainmenu.o src/menu/menu.o \
src/menu/menuutil.o src/menu/setupmenu.o \ src/menu/menuutil.o src/menu/setupmenu.o \
src/player/bird.o src/player/player.o src/player/playerframe.o \ src/player/bird.o src/player/player.o src/player/playerframe.o \
src/main.o src/movable.o src/planet.o src/scene.o src/util.o \ src/scene/scene.o src/scene/sceneload.o \
src/main.o src/movable.o src/planet.o src/util.o \
src/io/gfx/scale2x/getopt.o src/io/gfx/scale2x/pixel.o \ src/io/gfx/scale2x/getopt.o src/io/gfx/scale2x/pixel.o \
src/io/gfx/scale2x/scale2x.o src/io/gfx/scale2x/scale3x.o \ src/io/gfx/scale2x/scale2x.o src/io/gfx/scale2x/scale3x.o \
src/io/gfx/scale2x/scalebit.o src/io/gfx/scale2x/simple2x.o src/io/gfx/scale2x/scalebit.o src/io/gfx/scale2x/simple2x.o
......
...@@ -13,7 +13,8 @@ objects = src/bonus/bonus.o \ ...@@ -13,7 +13,8 @@ objects = src/bonus/bonus.o \
src/menu/gamemenu.o src/menu/mainmenu.o src/menu/menu.o \ src/menu/gamemenu.o src/menu/mainmenu.o src/menu/menu.o \
src/menu/menuutil.o src/menu/setupmenu.o \ src/menu/menuutil.o src/menu/setupmenu.o \
src/player/bird.o src/player/player.o src/player/playerframe.o \ src/player/bird.o src/player/player.o src/player/playerframe.o \
src/main.o src/movable.o src/planet.o src/scene.o src/util.o \ src/scene/scene.o src/scene/sceneload.o \
src/main.o src/movable.o src/planet.o src/util.o \
src/io/gfx/scale2x/getopt.o src/io/gfx/scale2x/pixel.o \ src/io/gfx/scale2x/getopt.o src/io/gfx/scale2x/pixel.o \
src/io/gfx/scale2x/scale2x.o src/io/gfx/scale2x/scale3x.o \ src/io/gfx/scale2x/scale2x.o src/io/gfx/scale2x/scale3x.o \
src/io/gfx/scale2x/scalebit.o src/io/gfx/scale2x/simple2x.o src/io/gfx/scale2x/scalebit.o src/io/gfx/scale2x/simple2x.o
......
...@@ -67,7 +67,7 @@ Game::~Game () { ...@@ -67,7 +67,7 @@ Game::~Game () {
if (levelFile) delete[] levelFile; if (levelFile) delete[] levelFile;
if (players != NULL) delete[] players; if (players) delete[] players;
localPlayer = NULL; localPlayer = NULL;
return; return;
......
...@@ -194,7 +194,7 @@ unsigned char * File::loadBlock (int length) { ...@@ -194,7 +194,7 @@ unsigned char * File::loadBlock (int length) {
} }
unsigned char * File::loadRLE (int length, bool dontseek) { unsigned char * File::loadRLE (int length) {
unsigned char *buffer; unsigned char *buffer;
int rle, pos, byte, count, next; int rle, pos, byte, count, next;
...@@ -236,9 +236,7 @@ unsigned char * File::loadRLE (int length, bool dontseek) { ...@@ -236,9 +236,7 @@ unsigned char * File::loadRLE (int length, bool dontseek) {
} }
if(!dontseek) {
fseek(f, next, SEEK_SET); fseek(f, next, SEEK_SET);
}
return buffer; return buffer;
...@@ -265,18 +263,18 @@ char * File::loadString () { ...@@ -265,18 +263,18 @@ char * File::loadString () {
int length, count; int length, count;
length = fgetc(f); length = fgetc(f);
count = 0;
if (length) { if (length) {
string = new char[length + 1]; string = new char[length + 1];
for (; count < length; count++) string[count] = fgetc(f); fread(string, 1, length, f);
} else { } else {
// If the length is not given, assume it is an 8.3 file name // If the length is not given, assume it is an 8.3 file name
string = new char[13]; string = new char[13];
for (; count < 9; count++) {
for (count = 0; count < 9; count++) {
string[count] = fgetc(f); string[count] = fgetc(f);
...@@ -292,19 +290,20 @@ char * File::loadString () { ...@@ -292,19 +290,20 @@ char * File::loadString () {
} }
} }
length = count;
} }
string[count] = 0; string[length] = 0;
return string; return string;
} }
SDL_Surface * File::loadSurface (int width, int height, bool dontseek) { SDL_Surface * File::loadSurface (int width, int height) {
return createSurface(loadRLE(width * height, dontseek), width, height); return createSurface(loadRLE(width * height), width, height);
} }
......
...@@ -54,10 +54,10 @@ class File { ...@@ -54,10 +54,10 @@ class File {
signed long int loadInt (); signed long int loadInt ();
void storeInt (signed long int val); void storeInt (signed long int val);
unsigned char * loadBlock (int length); unsigned char * loadBlock (int length);
unsigned char * loadRLE (int length, bool dontseek = false); unsigned char * loadRLE (int length);
void skipRLE (); void skipRLE ();
char * loadString (); char * loadString ();
SDL_Surface * loadSurface (int width, int height, bool dontseek = false); SDL_Surface * loadSurface (int width, int height);
void loadPalette (SDL_Color *palette); void loadPalette (SDL_Color *palette);
}; };
......
...@@ -42,7 +42,7 @@ SDL_Surface * createSurface (unsigned char * pixels, int width, int height) { ...@@ -42,7 +42,7 @@ SDL_Surface * createSurface (unsigned char * pixels, int width, int height) {
// Set the surface's palette // Set the surface's palette
SDL_SetPalette(ret, SDL_LOGPAL, logicalPalette, 0, 256); SDL_SetPalette(ret, SDL_LOGPAL, logicalPalette, 0, 256);
if (pixels != NULL) { if (pixels) {
// Upload pixel data to the surface // Upload pixel data to the surface
if (SDL_MUSTLOCK(ret)) SDL_LockSurface(ret); if (SDL_MUSTLOCK(ret)) SDL_LockSurface(ret);
......
...@@ -330,7 +330,7 @@ void freeSounds () { ...@@ -330,7 +330,7 @@ void freeSounds () {
int count; int count;
if (sounds != NULL) { if (sounds) {
for (count = 0; count < nSounds; count++) { for (count = 0; count < nSounds; count++) {
...@@ -352,7 +352,7 @@ void playSound (int newSound) { ...@@ -352,7 +352,7 @@ void playSound (int newSound) {
// Set the sound to be played // Set the sound to be played
if ((sounds != NULL) && (newSound >= 0)) sounds[newSound].position = 0; if (sounds && (newSound >= 0)) sounds[newSound].position = 0;
return; return;
......
...@@ -97,9 +97,6 @@ int DemoLevel::play () { ...@@ -97,9 +97,6 @@ int DemoLevel::play () {
int ret; int ret;
// Arbitrary initial value
smoothfps = 50.0f;
tickOffset = globalTicks; tickOffset = globalTicks;
ticks = 16; ticks = 16;
prevStepTicks = 0; prevStepTicks = 0;
...@@ -170,26 +167,12 @@ int DemoLevel::play () { ...@@ -170,26 +167,12 @@ int DemoLevel::play () {
// Draw the graphics // Draw the graphics
draw(); draw(stats);
fontmn1->showString("DEMO", (canvasW >> 1) - 36, 32); fontmn1->showString("DEMO", (canvasW >> 1) - 36, 32);
// Draw graphics statistics
if (stats & S_SCREEN) {
drawRect(236, 9, 80, 32, BLACK);
panelBigFont->showNumber(canvasW, 268, 15);
panelBigFont->showString("x", 272, 15);
panelBigFont->showNumber(canvasH, 308, 15);
panelBigFont->showString("fps", 244, 27);
panelBigFont->showNumber((int)smoothfps, 308, 27);
}
} }
return E_NONE; return E_NONE;
......
...@@ -56,8 +56,9 @@ ...@@ -56,8 +56,9 @@
Level::Level () { Level::Level () {
// Do nothing // Arbitrary initial value
smoothfps = 50.0f;
return; return;
} }
...@@ -73,6 +74,9 @@ Level::Level (char *fileName, unsigned char diff, bool checkpoint) { ...@@ -73,6 +74,9 @@ Level::Level (char *fileName, unsigned char diff, bool checkpoint) {
if (ret < 0) throw ret; if (ret < 0) throw ret;
// Arbitrary initial value
smoothfps = 50.0f;
return; return;
} }
...@@ -574,9 +578,6 @@ int Level::play () { ...@@ -574,9 +578,6 @@ int Level::play () {
int width; int width;
// Arbitrary initial value
smoothfps = 50.0f;
tickOffset = globalTicks; tickOffset = globalTicks;
ticks = 16; ticks = 16;
prevStepTicks = 0; prevStepTicks = 0;
...@@ -728,7 +729,7 @@ int Level::play () { ...@@ -728,7 +729,7 @@ int Level::play () {
// Draw the graphics // Draw the graphics
draw(); draw(stats);
// If paused, draw "PAUSE" // If paused, draw "PAUSE"
...@@ -766,21 +767,6 @@ int Level::play () { ...@@ -766,21 +767,6 @@ int Level::play () {
} }
// Draw graphics statistics
if (stats & S_SCREEN) {
drawRect(viewW - 84, 11, 80, 25, BLACK);
panelBigFont->showNumber(canvasW, viewW - 52, 14);
panelBigFont->showString("x", viewW - 48, 14);
panelBigFont->showNumber(canvasH, viewW - 12, 14);
panelBigFont->showString("fps", viewW - 76, 26);
panelBigFont->showNumber((int)smoothfps, viewW - 12, 26);
}
if (stage == LS_END) { if (stage == LS_END) {
// The level is over, so draw play statistics & bonuses // The level is over, so draw play statistics & bonuses
......
...@@ -131,17 +131,17 @@ class Level { ...@@ -131,17 +131,17 @@ class Level {
fixed waterLevelSpeed; fixed waterLevelSpeed;
fixed energyBar; fixed energyBar;
int stage; int stage;
float smoothfps;
int loadSprites (char *fileName); int loadSprites (char *fileName);
int loadTiles (char *fileName); int loadTiles (char *fileName);
protected: protected:
float smoothfps;
unsigned int tickOffset, prevStepTicks, prevTicks, ticks; unsigned int tickOffset, prevStepTicks, prevTicks, ticks;
int load (char *fileName, unsigned char diff, bool checkpoint); int load (char *fileName, unsigned char diff, bool checkpoint);
int step (); int step ();
void draw (); void draw (int stats);
void timeCalcs (bool paused); void timeCalcs (bool paused);
public: public:
......
...@@ -173,7 +173,7 @@ int Level::step () { ...@@ -173,7 +173,7 @@ int Level::step () {
void Level::draw () { void Level::draw (int stats) {
GridElement *ge; GridElement *ge;
Event *event; Event *event;
...@@ -440,6 +440,36 @@ void Level::draw () { ...@@ -440,6 +440,36 @@ void Level::draw () {
drawRect(dst.x, canvasH - 13, dst.w, 7, BLACK); drawRect(dst.x, canvasH - 13, dst.w, 7, BLACK);
// Draw graphics statistics
if (stats & S_SCREEN) {
#ifdef SCALE
if (scaleFactor > 1)
drawRect(viewW - 84, 11, 80, 37, BLACK);
else
#endif
drawRect(viewW - 84, 11, 80, 25, BLACK);
panelBigFont->showNumber(screenW, viewW - 52, 14);
panelBigFont->showString("x", viewW - 48, 14);
panelBigFont->showNumber(screenH, viewW - 12, 14);
panelBigFont->showString("fps", viewW - 76, 26);
panelBigFont->showNumber((int)smoothfps, viewW - 12, 26);
#ifdef SCALE
if (scaleFactor > 1) {
panelBigFont->showNumber(canvasW, viewW - 52, 38);
panelBigFont->showString("x", viewW - 48, 39);
panelBigFont->showNumber(canvasH, viewW - 12, 38);
}
#endif
}
return; return;
} }
......
...@@ -49,19 +49,38 @@ ...@@ -49,19 +49,38 @@
* *
*/ */
ImageInfo::ImageInfo () { SceneImage::SceneImage (SceneImage *newNext) {
next = newNext;
image = NULL; image = NULL;
} }
ImageInfo::~ImageInfo () {
if (image != NULL) SDL_FreeSurface(image); SceneImage::~SceneImage () {
if (next) delete next;
if (image) SDL_FreeSurface(image);
} }
ScriptText::ScriptText() {
ScenePalette::ScenePalette (ScenePalette *newNext) {
next = newNext;
}
ScenePalette::~ScenePalette () {
if (next) delete next;
}
SceneText::SceneText() {
x = -1; x = -1;
y = -1; y = -1;
...@@ -72,25 +91,25 @@ ScriptText::ScriptText() { ...@@ -72,25 +91,25 @@ ScriptText::ScriptText() {
} }
ScriptText::~ScriptText() { SceneText::~SceneText() {
if (text) delete[] text; if (text) delete[] text;
} }
ScriptPage::ScriptPage() { ScenePage::ScenePage() {
pageTime = 0; pageTime = 0;
noScriptTexts = 0; nTexts = 0;
backgrounds = 0; backgrounds = 0;
musicfile = NULL; musicFile = NULL;
paletteIndex = 0; paletteIndex = 0;
} }
ScriptPage::~ScriptPage() { ScenePage::~ScenePage() {
if (musicfile) delete[] musicfile; if (musicFile) delete[] musicFile;
} }
...@@ -100,7 +119,7 @@ Scene::Scene (const char * fileName) { ...@@ -100,7 +119,7 @@ Scene::Scene (const char * fileName) {
File *file; File *file;
int loop; int loop;
noScriptFonts = 0; nFonts = 0;
LOG("\nScene", fileName); LOG("\nScene", fileName);
try { try {
...@@ -113,22 +132,22 @@ Scene::Scene (const char * fileName) { ...@@ -113,22 +132,22 @@ Scene::Scene (const char * fileName) {
} }
imageIndex = 0; images = NULL;
paletteIndex = 0; palettes = NULL;
file->seek(0x13, true); // Skip Digital Dimensions header file->seek(0x13, true); // Skip Digital Dimensions header
signed long int dataOffset = file->loadInt(); //get offset pointer to first data block signed long int dataOffset = file->loadInt(); //get offset pointer to first data block
scriptItems = file->loadShort(); // Get number of script items scriptItems = file->loadShort(); // Get number of script items
scriptStarts = new signed long int[scriptItems]; scriptStarts = new signed long int[scriptItems];
scriptPages = new ScriptPage[scriptItems]; pages = new ScenePage[scriptItems];
LOG("Scene: Script items", scriptItems); LOG("Scene: Script items", scriptItems);
for (loop = 0; loop < scriptItems; loop++) { for (loop = 0; loop < scriptItems; loop++) {
scriptStarts[loop] = file->loadInt();// Load offset to script scriptStarts[loop] = file->loadInt();// Load offset to script
LOG("scriptStart:", scriptStarts[loop]); LOG("scriptStart", scriptStarts[loop]);
} }
...@@ -141,7 +160,7 @@ Scene::Scene (const char * fileName) { ...@@ -141,7 +160,7 @@ Scene::Scene (const char * fileName) {
for (loop = 0; loop < dataItems; loop++) { for (loop = 0; loop < dataItems; loop++) {
dataOffsets[loop] = file->loadInt();// Load offset to script dataOffsets[loop] = file->loadInt();// Load offset to script
LOG("dataOffsets:", dataOffsets[loop]); LOG("dataOffsets", dataOffsets[loop]);
} }
...@@ -159,30 +178,20 @@ Scene::Scene (const char * fileName) { ...@@ -159,30 +178,20 @@ Scene::Scene (const char * fileName) {
Scene::~Scene () { Scene::~Scene () {
delete[] scriptPages; delete[] pages;
}
ImageInfo * Scene::FindImage (int dataIndex) {
int loop;
for (loop = 0; loop < imageIndex; loop++) {
if (imageInfos[loop].dataIndex == dataIndex) return imageInfos + loop;
}
return NULL; if (images) delete images;
if (palettes) delete palettes;
} }
int Scene::play () { int Scene::play () {
SDL_Rect dst; SDL_Rect dst;
unsigned int sceneIndex = 0; unsigned int sceneIndex = 0;
ImageInfo* imageInfo; SceneImage *image;
unsigned int pageTime = scriptPages[sceneIndex].pageTime; unsigned int pageTime = pages[sceneIndex].pageTime;
unsigned int lastTicks = globalTicks; unsigned int lastTicks = globalTicks;
int newpage = true; int newpage = true;
int fadein = false; int fadein = false;
...@@ -211,7 +220,7 @@ int Scene::play () { ...@@ -211,7 +220,7 @@ int Scene::play () {
// Get bg for this page // Get bg for this page
newpage = true; newpage = true;
pageTime = scriptPages[sceneIndex].pageTime; pageTime = pages[sceneIndex].pageTime;
} }
...@@ -223,24 +232,14 @@ int Scene::play () { ...@@ -223,24 +232,14 @@ int Scene::play () {
textRect.y = 0; textRect.y = 0;
textRect.w = 320; textRect.w = 320;
textRect.h = 200; textRect.h = 200;
PaletteInfo* paletteInfo = NULL; ScenePalette *palette = palettes;
for (int palette = 0; palette < paletteIndex; palette++) {
if (paletteInfos[palette].dataIndex == scriptPages[sceneIndex].paletteIndex) {
paletteInfo = &paletteInfos[palette]; while (palette && (palette->id != pages[sceneIndex].paletteIndex)) palette = palette->next;
break;
}
} if (palette) {
if (paletteInfo != NULL) {
// usePalette(paletteInfo->palette); // usePalette(palette);
currentPalette = paletteInfo->palette; currentPalette = palette->palette;
fadein = true; fadein = true;
} else restorePalette(screen); } else restorePalette(screen);
...@@ -250,17 +249,20 @@ int Scene::play () { ...@@ -250,17 +249,20 @@ int Scene::play () {
} }
// First draw the backgrounds associated with this page // First draw the backgrounds associated with this page
if (scriptPages[sceneIndex].backgrounds > 0) { if (pages[sceneIndex].backgrounds > 0) {
for (int bg = 0; bg < pages[sceneIndex].backgrounds; bg++) {
for (int bg = 0; bg < scriptPages[sceneIndex].backgrounds; bg++) { image = images;
imageInfo = FindImage(scriptPages[sceneIndex].bgIndex[bg]); while (image && (image->id != pages[sceneIndex].bgIndex[bg]))
image = image->next;
if (imageInfo != NULL) { if (image) {
dst.x = (scriptPages[sceneIndex].bgPos[bg] & 65535)*2 + (canvasW - 320) >> 1; dst.x = (pages[sceneIndex].bgPos[bg] & 65535)*2 + (canvasW - 320) >> 1;
dst.y = ((scriptPages[sceneIndex].bgPos[bg] & (~65535))>>16)*2 + (canvasH - 200) >> 1; dst.y = ((pages[sceneIndex].bgPos[bg] & (~65535))>>16)*2 + (canvasH - 200) >> 1;
SDL_BlitSurface(imageInfo->image, NULL, canvas, &dst); SDL_BlitSurface(image->image, NULL, canvas, &dst);
} }
...@@ -274,16 +276,17 @@ int Scene::play () { ...@@ -274,16 +276,17 @@ int Scene::play () {
int y = 0; int y = 0;
int extraLineHeight = 0; int extraLineHeight = 0;
for (int text = 0; text < scriptPages[sceneIndex].noScriptTexts; text++) { for (int count = 0; count < pages[sceneIndex].nTexts; count++) {
Font *font = NULL; SceneText *text = pages[sceneIndex].texts + count;
Font *font = NULL;
int xOffset, yOffset; int xOffset, yOffset;
for (int index = 0; index < noScriptFonts; index++) { for (int index = 0; index < nFonts; index++) {
if (scriptPages[sceneIndex].scriptTexts[text].fontId == scriptFonts[index].fontId) { if (text->fontId == fonts[index].id) {
font = scriptFonts[index].font; font = fonts[index].font;
continue; continue;
...@@ -291,31 +294,31 @@ int Scene::play () { ...@@ -291,31 +294,31 @@ int Scene::play () {
} }
if (scriptPages[sceneIndex].scriptTexts[text].x != -1) { if (text->x != -1) {
x = scriptPages[sceneIndex].scriptTexts[text].x; x = text->x;
y = scriptPages[sceneIndex].scriptTexts[text].y; y = text->y;
} }
if (scriptPages[sceneIndex].scriptTexts[text].textRect.x != -1) { if (text->textRect.x != -1) {
textRect = scriptPages[sceneIndex].scriptTexts[text].textRect; textRect = text->textRect;
x = 0; x = 0;
y = 0; y = 0;
} }
if (scriptPages[sceneIndex].scriptTexts[text].extraLineHeight != -1) { if (text->extraLineHeight != -1) {
extraLineHeight = scriptPages[sceneIndex].scriptTexts[text].extraLineHeight; extraLineHeight = text->extraLineHeight;
} }
xOffset = ((canvasW - 320) >> 1) + textRect.x + x; xOffset = ((canvasW - 320) >> 1) + textRect.x + x;
yOffset = ((canvasH - 200) >> 1) + textRect.y + y; yOffset = ((canvasH - 200) >> 1) + textRect.y + y;
switch (scriptPages[sceneIndex].scriptTexts[text].alignment) { switch (text->alignment) {
case 0: // left case 0: // left
...@@ -323,13 +326,13 @@ int Scene::play () { ...@@ -323,13 +326,13 @@ int Scene::play () {
case 1: // right case 1: // right
xOffset += textRect.w - font->getSceneStringWidth(scriptPages[sceneIndex].scriptTexts[text].text); xOffset += textRect.w - font->getSceneStringWidth(text->text);
break; break;
case 2: // center case 2: // center
xOffset += (textRect.w - font->getSceneStringWidth(scriptPages[sceneIndex].scriptTexts[text].text)) >> 1; xOffset += (textRect.w - font->getSceneStringWidth(text->text)) >> 1;
break; break;
...@@ -337,11 +340,11 @@ int Scene::play () { ...@@ -337,11 +340,11 @@ int Scene::play () {
// Drop shadow // Drop shadow
font->mapPalette(0, 256, 0, 1); font->mapPalette(0, 256, 0, 1);
font->showSceneString(scriptPages[sceneIndex].scriptTexts[text].text, xOffset + 1, yOffset + 1); font->showSceneString(text->text, xOffset + 1, yOffset + 1);
font->restorePalette(); font->restorePalette();
// Text itself // Text itself
font->showSceneString(scriptPages[sceneIndex].scriptTexts[text].text, xOffset, yOffset); font->showSceneString(text->text, xOffset, yOffset);
y += extraLineHeight + font->getHeight() / 2; y += extraLineHeight + font->getHeight() / 2;
......
...@@ -64,18 +64,7 @@ enum { ...@@ -64,18 +64,7 @@ enum {
class Font; class Font;
class ScriptFont { class SceneText {
public:
// This points to any of the available types (already loaded)
Font *font;
// Font id given this font
int fontId;
};
class ScriptText {
public: public:
char *text; char *text;
...@@ -86,12 +75,12 @@ class ScriptText { ...@@ -86,12 +75,12 @@ class ScriptText {
SDL_Rect textRect; SDL_Rect textRect;
int extraLineHeight; int extraLineHeight;
ScriptText (); SceneText ();
~ScriptText (); ~SceneText ();
}; };
class ScriptPage { class ScenePage {
public: public:
int backgrounds; int backgrounds;
...@@ -100,65 +89,68 @@ class ScriptPage { ...@@ -100,65 +89,68 @@ class ScriptPage {
// Length of the scene in seconds, or if zero = anim complete, or 256 = user interaction // Length of the scene in seconds, or if zero = anim complete, or 256 = user interaction
int pageTime; int pageTime;
ScriptText scriptTexts[100]; SceneText texts[100];
int noScriptTexts; int nTexts;
char *musicfile; char *musicFile;
int paletteIndex; int paletteIndex;
ScriptPage(); ScenePage();
~ScriptPage(); ~ScenePage();
}; };
class ImageInfo { class SceneImage {
public: public:
// SDL_Surface with the image SceneImage *next;
SDL_Surface *image; SDL_Surface *image;
int id;
// data index of the image (not the palette) to compare with scripts SceneImage (SceneImage *newNext);
int dataIndex; ~SceneImage ();
ImageInfo ();
~ImageInfo ();
}; };
class PaletteInfo { class ScenePalette {
public: public:
// Palette associated with the image ScenePalette *next;
SDL_Color palette[256]; SDL_Color palette[256];
int id;
// data index of the image (not the palette) to compare with scripts
int dataIndex; ScenePalette (ScenePalette *newNext);
~ScenePalette ();
}; };
class SceneFont {
public:
Font *font;
int id;
};
class Scene { class Scene {
private: private:
ImageInfo imageInfos[100]; SceneImage *images;
PaletteInfo paletteInfos[100]; ScenePalette *palettes;
SceneFont fonts[5];
int nFonts;
unsigned short int scriptItems; unsigned short int scriptItems;
unsigned short int dataItems; unsigned short int dataItems;
signed long int *scriptStarts; signed long int *scriptStarts;
signed long int *dataOffsets; signed long int *dataOffsets;
int imageIndex;
int paletteIndex;
// Scripts all information needed to render script pages, text etc // Scripts all information needed to render script pages, text etc
ScriptPage *scriptPages; 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);
ImageInfo * FindImage (int dataIndex);
public:
ScriptFont scriptFonts[5];
int noScriptFonts;
public:
Scene (const char * fileName); Scene (const char * fileName);
~Scene (); ~Scene ();
......
...@@ -68,23 +68,21 @@ void Scene::loadAni (File *f, int dataIndex) { ...@@ -68,23 +68,21 @@ void Scene::loadAni (File *f, int dataIndex) {
unsigned short int len = f->loadShort(); unsigned short int len = f->loadShort();
unsigned char* buffer = f->loadBlock(len); unsigned char* buffer = f->loadBlock(len);
palettes = new ScenePalette(palettes);
for (int count = 0; count < 256; count++) { for (int count = 0; count < 256; count++) {
// Palette entries are 6-bit // Palette entries are 6-bit
// Shift them upwards to 8-bit, and fill in the lower 2 bits // Shift them upwards to 8-bit, and fill in the lower 2 bits
paletteInfos[paletteIndex].palette[count].r = palettes->palette[count].r = (buffer[count * 3] << 2) + (buffer[count * 3] >> 4);
(buffer[count * 3] << 2) + (buffer[count * 3] >> 4); palettes->palette[count].g = (buffer[(count * 3) + 1] << 2) + (buffer[(count * 3) + 1] >> 4);
paletteInfos[paletteIndex].palette[count].g = palettes->palette[count].b = (buffer[(count * 3) + 2] << 2) + (buffer[(count * 3) + 2] >> 4);
(buffer[(count * 3) + 1] << 2) + (buffer[(count * 3) + 1] >> 4);
paletteInfos[paletteIndex].palette[count].b =
(buffer[(count * 3) + 2] << 2) + (buffer[(count * 3) + 2] >> 4);
} }
delete[] buffer; delete[] buffer;
paletteInfos[paletteIndex].dataIndex = dataIndex; palettes->id = dataIndex;
paletteIndex++;
unsigned short int value = 0x4646; unsigned short int value = 0x4646;
int items = 0; int items = 0;
...@@ -97,11 +95,11 @@ void Scene::loadAni (File *f, int dataIndex) { ...@@ -97,11 +95,11 @@ void Scene::loadAni (File *f, int dataIndex) {
value = f->loadShort(); value = f->loadShort();
LOG("PL Read block start tag", value); LOG("PL Read block start tag", value);
unsigned short int size= f->loadShort(); unsigned short int size = f->loadShort();
LOG("PL Anim block size", size); LOG("PL Anim block size", size);
nextPos = f->tell(); nextPos = f->tell();
// next pos is intial position + size and four bytes header // next pos is intial position + size and four bytes header
nextPos+=(size); nextPos += size;
switch (value) { switch (value) {
...@@ -118,11 +116,13 @@ void Scene::loadAni (File *f, int dataIndex) { ...@@ -118,11 +116,13 @@ void Scene::loadAni (File *f, int dataIndex) {
// Skip back size header, this is read by the surface reader // Skip back size header, this is read by the surface reader
f->seek(-2, false); f->seek(-2, false);
SDL_Surface *image = f->loadSurface(320, 200, true); SDL_Surface *image = f->loadSurface(320, 200);
SDL_BlitSurface(image, NULL, canvas, NULL); SDL_BlitSurface(image, NULL, canvas, NULL);
SDL_FreeSurface(image); SDL_FreeSurface(image);
SDL_SetPalette(screen, SDL_PHYSPAL, paletteInfos[paletteIndex-1].palette, 0, 256);
currentPalette = paletteInfos[paletteIndex-1].palette; // Use the most recently loaded palette
SDL_SetPalette(screen, SDL_PHYSPAL, palettes->palette, 0, 256);
currentPalette = palettes->palette;
} }
...@@ -134,8 +134,6 @@ void Scene::loadAni (File *f, int dataIndex) { ...@@ -134,8 +134,6 @@ void Scene::loadAni (File *f, int dataIndex) {
int longvalue = f->loadInt(); int longvalue = f->loadInt();
LOG("PL Anim block value", longvalue); LOG("PL Anim block value", longvalue);
// Skip back size header, this is read by the surface reader
//f->seek(-2, false);
while (size) { while (size) {
...@@ -176,6 +174,7 @@ void Scene::loadAni (File *f, int dataIndex) { ...@@ -176,6 +174,7 @@ void Scene::loadAni (File *f, int dataIndex) {
default: default:
LOG("PL Unknown type", header); LOG("PL Unknown type", header);
break; break;
} }
...@@ -327,7 +326,7 @@ void Scene::loadData (File *f) { ...@@ -327,7 +326,7 @@ void Scene::loadData (File *f) {
int loop; int loop;
for(loop = 0; loop < dataItems; loop++) { for (loop = 0; loop < dataItems; loop++) {
f->seek(dataOffsets[loop], true); // Seek to data start f->seek(dataOffsets[loop], true); // Seek to data start
unsigned short int dataLen = f->loadShort(); // Get get the length of the datablock unsigned short int dataLen = f->loadShort(); // Get get the length of the datablock
...@@ -361,14 +360,10 @@ void Scene::loadData (File *f) { ...@@ -361,14 +360,10 @@ void Scene::loadData (File *f) {
if (type == 3) height = f->loadChar(); // Get height if (type == 3) height = f->loadChar(); // Get height
else height = f->loadShort(); // Get height else height = f->loadShort(); // Get height
if (imageIndex<100) { f->seek(-2, false);
images = new SceneImage(images);
f->seek(-2, false); images->image = f->loadSurface(width, height);
imageInfos[imageIndex].image = f->loadSurface(width, height); images->id = loop;
imageInfos[imageIndex].dataIndex = loop;
imageIndex++;
}
} }
...@@ -376,16 +371,13 @@ void Scene::loadData (File *f) { ...@@ -376,16 +371,13 @@ void Scene::loadData (File *f) {
default: default:
{ LOG("Data Type", "Palette");
LOG("Data Type Palette index", loop);
LOG("Data Type", "Palette"); f->seek(-3, false);
LOG("Data Type Palette index", loop);
f->seek(-3, false);
f->loadPalette(paletteInfos[paletteIndex].palette);
paletteInfos[paletteIndex].dataIndex = loop;
paletteIndex++;
} palettes = new ScenePalette(palettes);
f->loadPalette(palettes->palette);
palettes->id = loop;
break; break;
...@@ -401,7 +393,6 @@ void Scene::loadData (File *f) { ...@@ -401,7 +393,6 @@ void Scene::loadData (File *f) {
void Scene::loadScripts (File *f) { void Scene::loadScripts (File *f) {
int loop; int loop;
char *string;
/*int bgIndex = 0;*/ /*int bgIndex = 0;*/
int textAlignment = 0; int textAlignment = 0;
int textFont = 0; int textFont = 0;
...@@ -420,10 +411,10 @@ void Scene::loadScripts (File *f) { ...@@ -420,10 +411,10 @@ void Scene::loadScripts (File *f) {
if (f->loadChar() == 0x50) { // Script tag if (f->loadChar() == 0x50) { // Script tag
unsigned short int scriptid = f->loadShort(); unsigned short int scriptid = f->loadShort();
LOG("Script id:", scriptid); LOG("Script id", scriptid);
int palette = f->loadShort(); int palette = f->loadShort();
LOG("Script default palette", palette); LOG("Script default palette", palette);
scriptPages[loop].paletteIndex = palette; pages[loop].paletteIndex = palette;
unsigned char type = 0; unsigned char type = 0;
bool breakloop = false; bool breakloop = false;
...@@ -452,7 +443,7 @@ void Scene::loadScripts (File *f) { ...@@ -452,7 +443,7 @@ void Scene::loadScripts (File *f) {
{ {
unsigned char aniIndex = f->loadChar(); unsigned char aniIndex = f->loadChar();
LOG("ESceneAnimationIndex:", aniIndex); LOG("ESceneAnimationIndex", aniIndex);
} }
...@@ -462,7 +453,7 @@ void Scene::loadScripts (File *f) { ...@@ -462,7 +453,7 @@ void Scene::loadScripts (File *f) {
{ {
unsigned char fadein = f->loadChar(); unsigned char fadein = f->loadChar();
LOG("ESceneFadeType:", fadein); LOG("ESceneFadeType", fadein);
} }
...@@ -478,9 +469,9 @@ void Scene::loadScripts (File *f) { ...@@ -478,9 +469,9 @@ void Scene::loadScripts (File *f) {
LOG("ESceneBackground: index", bgImageIndex); LOG("ESceneBackground: index", bgImageIndex);
LOG("ESceneBackground: xpos", xpos); LOG("ESceneBackground: xpos", xpos);
LOG("ESceneBackground: ypos", ypos); LOG("ESceneBackground: ypos", ypos);
scriptPages[loop].bgIndex[scriptPages[loop].backgrounds] = bgImageIndex; pages[loop].bgIndex[pages[loop].backgrounds] = bgImageIndex;
scriptPages[loop].bgPos[scriptPages[loop].backgrounds] = xpos|(ypos<<16); pages[loop].bgPos[pages[loop].backgrounds] = xpos | (ypos << 16);
scriptPages[loop].backgrounds++; pages[loop].backgrounds++;
} }
...@@ -488,15 +479,9 @@ void Scene::loadScripts (File *f) { ...@@ -488,15 +479,9 @@ void Scene::loadScripts (File *f) {
case ESceneMusic: case ESceneMusic:
{ // Music file name
pages[loop].musicFile = f->loadString();
// Music file name LOG("ESceneMusic", pages[loop].musicFile);
string = f->loadString();
LOG("ESceneMusic: ", string);
scriptPages[loop].musicfile = createString(string);
delete[] string;
}
break; break;
...@@ -513,45 +498,42 @@ void Scene::loadScripts (File *f) { ...@@ -513,45 +498,42 @@ void Scene::loadScripts (File *f) {
case ESceneTextRect: // String case ESceneTextRect: // String
{ textRect.x = f->loadShort();
textRect.y = f->loadShort();
unsigned short x = textRect.x = f->loadShort(); textRect.w = f->loadShort() - textRect.x;
unsigned short y = textRect.y = f->loadShort(); textRect.h = f->loadShort() - textRect.y;
unsigned short w = textRect.w = f->loadShort() - x; textRectValid = true;
unsigned short h = textRect.h = f->loadShort() - y; LOG("Text rectangle xpos", textRect.x);
textRectValid = true; LOG("Text rectangle ypos", textRect.y);
LOG("Text rectangle xpos:", x); LOG("Text rectangle w", textRect.w);
LOG("Text rectangle ypos:", y); LOG("Text rectangle h", textRect.h);
LOG("Text rectangle w:", w);
LOG("Text rectangle h:", h);
}
break; break;
case ESceneFontDefine: // Font defnition case ESceneFontDefine: // Font defnition
{ if (nFonts < 5) {
fonts[nFonts].id = f->loadShort();
char *fontname = f->loadString();
unsigned short fontid = f->loadShort();
char* fontname = f->loadString();
LOG("ESceneFontDefine", fontname); LOG("ESceneFontDefine", fontname);
LOG("ESceneFontDefine with id=", fontid); LOG("ESceneFontDefine with id", fonts[nFonts].id);
if (strcmp(fontname, "FONT2") == 0) if (strcmp(fontname, "FONT2") == 0)
scriptFonts[noScriptFonts].font = font2; fonts[nFonts].font = font2;
else if (strcmp(fontname, "FONTBIG") == 0) else if (strcmp(fontname, "FONTBIG") == 0)
scriptFonts[noScriptFonts].font = fontbig; fonts[nFonts].font = fontbig;
else if (strcmp(fontname, "FONTTINY") == 0) else if (strcmp(fontname, "FONTTINY") == 0)
scriptFonts[noScriptFonts].font = fontiny; fonts[nFonts].font = fontiny;
else if (strcmp(fontname, "FONTMN1") == 0) else if (strcmp(fontname, "FONTMN1") == 0)
scriptFonts[noScriptFonts].font = fontmn1; fonts[nFonts].font = fontmn1;
else if (strcmp(fontname, "FONTMN2") == 0) else if (strcmp(fontname, "FONTMN2") == 0)
scriptFonts[noScriptFonts].font = fontmn2; fonts[nFonts].font = fontmn2;
else scriptFonts[noScriptFonts].font = font2; else fonts[nFonts].font = font2;
nFonts++;
scriptFonts[noScriptFonts].fontId = fontid;
noScriptFonts++;
delete[] fontname; delete[] fontname;
} }
...@@ -560,16 +542,10 @@ void Scene::loadScripts (File *f) { ...@@ -560,16 +542,10 @@ void Scene::loadScripts (File *f) {
case ESceneTextPosition: case ESceneTextPosition:
{ textPosX = f->loadShort();
textPosY = f->loadShort();
unsigned short newx = f->loadShort(); LOG("TextPosition x", textPosX);
unsigned short newy = f->loadShort(); LOG("TextPosition y", textPosY);
LOG("TextPosition x", newx);
LOG("TextPosition y", newy);
textPosX = newx;
textPosY = newy;
}
break; break;
...@@ -604,25 +580,15 @@ void Scene::loadScripts (File *f) { ...@@ -604,25 +580,15 @@ void Scene::loadScripts (File *f) {
case ESceneFontIndex: case ESceneFontIndex:
{ textFont = f->loadShort();
LOG("ESceneFontIndex", textFont);
unsigned short value = f->loadShort();
LOG("ESceneFontIndex", value);
textFont = value;
}
break; break;
case ESceneTextVAdjust: case ESceneTextVAdjust:
{ extraheight = f->loadShort();
LOG("ESceneTextVAdjust", extraheight);
unsigned short value = f->loadShort();
LOG("ESceneTextVAdjust", value);
extraheight = value;
}
break; break;
...@@ -650,13 +616,8 @@ void Scene::loadScripts (File *f) { ...@@ -650,13 +616,8 @@ void Scene::loadScripts (File *f) {
case ESceneTextAlign: case ESceneTextAlign:
{ textAlignment = f->loadChar();
LOG("ESceneTextAlign", textAlignment);
unsigned char alignment = f->loadChar();
LOG("ESceneTextAlign", alignment);
textAlignment = alignment;
}
break; break;
...@@ -692,54 +653,50 @@ void Scene::loadScripts (File *f) { ...@@ -692,54 +653,50 @@ void Scene::loadScripts (File *f) {
{ {
unsigned char datalen = f->loadChar(); unsigned char datalen = f->loadChar();
LOG("Text len=", datalen); LOG("Text len", datalen);
SceneText *text = pages[loop].texts + pages[loop].nTexts;
if (datalen > 0) { if (datalen > 0) {
f->seek(-1, false); f->seek(-1, false);
char *block = f->loadString(); text->text = f->loadString();
// Convert number placeholders // Convert number placeholders
for (int pos = 1; pos < datalen; pos++) { for (int pos = 1; pos < datalen; pos++) {
if (block[pos] == -117) { if (text->text[pos] == -117) {
if (loop >= 9) if (loop >= 9)
block[pos - 1] = ((loop + 1) / 10) + 53; text->text[pos - 1] = ((loop + 1) / 10) + 53;
block[pos] = ((loop + 1) % 10) + 53; text->text[pos] = ((loop + 1) % 10) + 53;
} else if (block[pos] == -118) { } else if (text->text[pos] == -118) {
if (scriptItems >= 10) if (scriptItems >= 10)
block[pos - 1] = (scriptItems / 10) + 53; text->text[pos - 1] = (scriptItems / 10) + 53;
block[pos] = (scriptItems % 10) + 53; text->text[pos] = (scriptItems % 10) + 53;
} }
} }
scriptPages[loop].scriptTexts[scriptPages[loop].noScriptTexts].text = block;
LOG("Text data",(char*) scriptPages[loop].scriptTexts[scriptPages[loop].noScriptTexts].text);
} else { } else {
scriptPages[loop].scriptTexts[scriptPages[loop].noScriptTexts].text = new char[1]; text->text = new char[1];
scriptPages[loop].scriptTexts[scriptPages[loop].noScriptTexts].text[0] = 0; text->text[0] = 0;
LOG("Text data", "Empty line");
} }
scriptPages[loop].scriptTexts[scriptPages[loop].noScriptTexts].alignment = textAlignment; text->alignment = textAlignment;
scriptPages[loop].scriptTexts[scriptPages[loop].noScriptTexts].fontId = textFont; text->fontId = textFont;
if(textPosX != -1) { if(textPosX != -1) {
scriptPages[loop].scriptTexts[scriptPages[loop].noScriptTexts].x = textPosX; text->x = textPosX;
scriptPages[loop].scriptTexts[scriptPages[loop].noScriptTexts].y = textPosY; text->y = textPosY;
textPosX = -1; textPosX = -1;
textPosY = -1; textPosY = -1;
...@@ -747,19 +704,19 @@ void Scene::loadScripts (File *f) { ...@@ -747,19 +704,19 @@ void Scene::loadScripts (File *f) {
if(textRectValid) { if(textRectValid) {
scriptPages[loop].scriptTexts[scriptPages[loop].noScriptTexts].textRect = textRect; text->textRect = textRect;
textRectValid = false; textRectValid = false;
} }
if(extraheight != -1) { if(extraheight != -1) {
scriptPages[loop].scriptTexts[scriptPages[loop].noScriptTexts].extraLineHeight = extraheight; text->extraLineHeight = extraheight;
extraheight = -1; extraheight = -1;
} }
scriptPages[loop].noScriptTexts++; pages[loop].nTexts++;
} }
...@@ -767,12 +724,8 @@ void Scene::loadScripts (File *f) { ...@@ -767,12 +724,8 @@ void Scene::loadScripts (File *f) {
case ESceneTime: case ESceneTime:
{ pages[loop].pageTime = f->loadShort() & 255;
unsigned short int sceneTime = f->loadShort(); LOG("Scene time", pages[loop].pageTime);
LOG("Scene time",sceneTime&255);
scriptPages[loop].pageTime = sceneTime&255;
}
break; break;
......
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