Commit 351f3bec authored by alistert's avatar alistert

Panel is now only loaded when needed.

parent 5c545948
......@@ -102,10 +102,6 @@ EXTERN SDL_Surface* canvas;
EXTERN int viewH, canvasW, canvasH;
#define viewW canvasW
// Panel
EXTERN SDL_Surface* panel;
EXTERN SDL_Surface* panelAmmo[5];
EXTERN Video video;
......
......@@ -82,6 +82,20 @@ Level::Level (char* fileName, unsigned char diff, bool checkpoint) {
}
void Level::deletePanel () {
SDL_FreeSurface(panel);
SDL_FreeSurface(panelAmmo[0]);
SDL_FreeSurface(panelAmmo[1]);
SDL_FreeSurface(panelAmmo[2]);
SDL_FreeSurface(panelAmmo[3]);
SDL_FreeSurface(panelAmmo[4]);
return;
}
Level::~Level () {
int count;
......@@ -102,6 +116,8 @@ Level::~Level () {
delete[] sceneFile;
delete[] musicFile;
deletePanel();
delete font;
return;
......@@ -592,9 +608,8 @@ int Level::play () {
if (timeBonus == -1) {
timeBonus = ((endTime - ticks) / 60000) * 100;
if (timeBonus < 0) timeBonus = 0;
if (ticks < endTime) timeBonus = ((endTime - ticks) / 60000) * 100;
else timeBonus = 0;
if ((levelPlayer->getEnemies() == enemies) &&
(levelPlayer->getItems() == items)) perfect = 100;
......
......@@ -94,6 +94,8 @@ class Scene;
class Level : public BaseLevel {
private:
SDL_Surface* panel;
SDL_Surface* panelAmmo[5];
char* musicFile;
char* sceneFile;
Anim animSet[ANIMS];
......@@ -114,6 +116,8 @@ class Level : public BaseLevel {
fixed waterLevelSpeed;
fixed energyBar;
void deletePanel ();
int loadPanel ();
void loadSprite (File* file, Sprite* sprite);
int loadSprites (char* fileName);
int loadTiles (char* fileName);
......
......@@ -51,6 +51,95 @@
#define SKEY 254 /* Sprite colour key */
int Level::loadPanel () {
File* file;
unsigned char* pixels;
unsigned char* sorted;
int x, y;
try {
file = new File(F_PANEL, false);
} catch (int e) {
return e;
}
pixels = file->loadRLE(46272);
delete file;
// Create the panel background
panel = createSurface(pixels, SW, 32);
// De-scramble the panel's ammo graphics
sorted = new unsigned char[64 * 27];
for (y = 0; y < 27; y++) {
for (x = 0; x < 64; x++)
sorted[(y * 64) + x] = pixels[(y * 64) + (x >> 2) + ((x & 3) << 4) + (55 * 320)];
}
panelAmmo[0] = createSurface(sorted, 64, 27);
for (y = 0; y < 27; y++) {
for (x = 0; x < 64; x++)
sorted[(y * 64) + x] = pixels[(y * 64) + (x >> 2) + ((x & 3) << 4) + (61 * 320)];
}
panelAmmo[1] = createSurface(sorted, 64, 27);
for (y = 0; y < 27; y++) {
for (x = 0; x < 64; x++)
sorted[(y * 64) + x] = pixels[(y * 64) + (x >> 2) + ((x & 3) << 4) + (68 * 320)];
}
panelAmmo[2] = createSurface(sorted, 64, 27);
for (y = 0; y < 27; y++) {
for (x = 0; x < 64; x++)
sorted[(y * 64) + x] = pixels[(y * 64) + (x >> 2) + ((x & 3) << 4) + (74 * 320)];
}
panelAmmo[3] = createSurface(sorted, 64, 27);
for (y = 0; y < 27; y++) {
for (x = 0; x < 64; x++)
sorted[(y * 64) + x] = pixels[(y * 64) + (x >> 2) + ((x & 3) << 4) + (86 * 320)];
}
panelAmmo[4] = createSurface(sorted, 64, 27);
delete[] sorted;
delete[] pixels;
return E_NONE;
}
void Level::loadSprite (File* file, Sprite* sprite) {
unsigned char* pixels;
......@@ -330,18 +419,33 @@ int Level::load (char *fileName, unsigned char diff, bool checkpoint) {
unsigned char startX, startY;
difficulty = diff;
// Load font
try {
font = new Font(false);
} catch (int e) {
throw e;
return e;
}
difficulty = diff;
// Load panel
count = loadPanel();
if (count < 0) {
delete font;
return count;
}
// Show loading screen
......@@ -367,6 +471,7 @@ int Level::load (char *fileName, unsigned char diff, bool checkpoint) {
} catch (int e) {
delete[] string;
deletePanel();
delete font;
return e;
......@@ -434,6 +539,7 @@ int Level::load (char *fileName, unsigned char diff, bool checkpoint) {
} catch (int e) {
deletePanel();
delete font;
return e;
......@@ -495,6 +601,7 @@ int Level::load (char *fileName, unsigned char diff, bool checkpoint) {
if (tiles < 0) {
delete file;
deletePanel();
delete font;
return tiles;
......@@ -513,6 +620,7 @@ int Level::load (char *fileName, unsigned char diff, bool checkpoint) {
if (count < 0) {
delete file;
deletePanel();
delete font;
return count;
......
......@@ -66,8 +66,8 @@ extern float sinf (float);
int loadMain (int argc, char *argv[]) {
File *file;
unsigned char *pixels, *sorted;
File* file;
unsigned char* pixels;
int count, x, y;
int screenW, screenH;
int scaleFactor;
......@@ -312,7 +312,9 @@ int loadMain (int argc, char *argv[]) {
// Load the panel
// Load fonts
// Open the panel, which contains two fonts
try {
......@@ -334,69 +336,6 @@ int loadMain (int argc, char *argv[]) {
delete file;
// Create the panel background
panel = createSurface(pixels, SW, 32);
// De-scramble the panel's ammo graphics
sorted = new unsigned char[64 * 27];
for (y = 0; y < 27; y++) {
for (x = 0; x < 64; x++)
sorted[(y * 64) + x] = pixels[(y * 64) + (x >> 2) + ((x & 3) << 4) + (55 * 320)];
}
panelAmmo[0] = createSurface(sorted, 64, 27);
for (y = 0; y < 27; y++) {
for (x = 0; x < 64; x++)
sorted[(y * 64) + x] = pixels[(y * 64) + (x >> 2) + ((x & 3) << 4) + (61 * 320)];
}
panelAmmo[1] = createSurface(sorted, 64, 27);
for (y = 0; y < 27; y++) {
for (x = 0; x < 64; x++)
sorted[(y * 64) + x] = pixels[(y * 64) + (x >> 2) + ((x & 3) << 4) + (68 * 320)];
}
panelAmmo[2] = createSurface(sorted, 64, 27);
for (y = 0; y < 27; y++) {
for (x = 0; x < 64; x++)
sorted[(y * 64) + x] = pixels[(y * 64) + (x >> 2) + ((x & 3) << 4) + (74 * 320)];
}
panelAmmo[3] = createSurface(sorted, 64, 27);
for (y = 0; y < 27; y++) {
for (x = 0; x < 64; x++)
sorted[(y * 64) + x] = pixels[(y * 64) + (x >> 2) + ((x & 3) << 4) + (86 * 320)];
}
panelAmmo[4] = createSurface(sorted, 64, 27);
delete[] sorted;
// Load fonts
panelBigFont = NULL;
panelSmallFont = NULL;
font2 = NULL;
......@@ -425,13 +364,6 @@ int loadMain (int argc, char *argv[]) {
delete[] pixels;
SDL_FreeSurface(panel);
SDL_FreeSurface(panelAmmo[0]);
SDL_FreeSurface(panelAmmo[1]);
SDL_FreeSurface(panelAmmo[2]);
SDL_FreeSurface(panelAmmo[3]);
SDL_FreeSurface(panelAmmo[4]);
closeAudio();
delete[] characterName;
......@@ -462,6 +394,7 @@ int loadMain (int argc, char *argv[]) {
level = NULL;
jj2Level = NULL;
return E_NONE;
}
......@@ -483,13 +416,6 @@ void freeMain () {
delete fontmn1;
delete fontmn2;
SDL_FreeSurface(panel);
SDL_FreeSurface(panelAmmo[0]);
SDL_FreeSurface(panelAmmo[1]);
SDL_FreeSurface(panelAmmo[2]);
SDL_FreeSurface(panelAmmo[3]);
SDL_FreeSurface(panelAmmo[4]);
#ifdef SCALE
scaleFactor = video.getScaleFactor();
......
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