Commit 59d7d776 authored by alistert's avatar alistert

Applied some of Fabian Greffrath's patches. Changed file opening code. Minor tidying.

parent 762a7bee
...@@ -63,41 +63,44 @@ ...@@ -63,41 +63,44 @@
#define F100 102400 #define F100 102400
#define F160 163840 #define F160 163840
// File names // Files
#ifdef __SYMBIAN32__
#ifdef UIQ3
#define CONFIG_FILE "c:\\shared\\openjazz\\openjazz.cfg"
#define LOGO_FILE "c:\\shared\\openjazz\\openjazz.000"
#else
#define CONFIG_FILE "c:\\data\\openjazz\\openjazz.cfg"
#define LOGO_FILE "c:\\data\\openjazz\\openjazz.000"
#endif
#else
#define CONFIG_FILE "openjazz.cfg" #define CONFIG_FILE "openjazz.cfg"
#define LOGO_FILE "openjazz.000" #define LOGO_FILE "openjazz.000"
#endif
#define LEVEL_FILE "openjazz.tmp" #define LEVEL_FILE "openjazz.tmp"
#ifdef UPPERCASE_FILENAMES #ifdef UPPERCASE_FILENAMES
#define F_MAINCHAR "MAINCHAR.000" #define F_MAINCHAR "MAINCHAR.000"
#define F_MENU "MENU.000" #define F_MENU "MENU.000"
#define F_PANEL "PANEL.000" #define F_PANEL "PANEL.000"
#define F_SOUNDS "SOUNDS.000"
// File name formats
#define F_BLOCKS "BLOCKS" #define F_STARTUP_0SC "STARTUP.0SC"
#define F_LEVEL "LEVEL" #define F_END_0SC "END.0SC"
#define F_PLANET "PLANET"
#define F_SPRITES "SPRITES" #define F_MACRO "MACRO.2"
// File path prefixes
#define F_BLOCKS "BLOCKS"
#define F_LEVEL "LEVEL"
#define F_PLANET "PLANET"
#define F_SPRITES "SPRITES"
#else #else
#define F_MAINCHAR "mainchar.000" #define F_MAINCHAR "mainchar.000"
#define F_MENU "menu.000" #define F_MENU "menu.000"
#define F_PANEL "panel.000" #define F_PANEL "panel.000"
#define F_SOUNDS "sounds.000"
// File name formats
#define F_BLOCKS "blocks" #define F_STARTUP_0SC "startup.0sc"
#define F_LEVEL "level" #define F_END_0SC "end.0sc"
#define F_PLANET "planet"
#define F_SPRITES "sprites" #define F_MACRO "macro.2"
// File path prefixes
#define F_BLOCKS "blocks"
#define F_LEVEL "level"
#define F_PLANET "planet"
#define F_SPRITES "sprites"
#endif #endif
// Standard string length // Standard string length
...@@ -161,17 +164,17 @@ EXTERN int loop (int type); ...@@ -161,17 +164,17 @@ EXTERN int loop (int type);
// Functions in util.cpp // Functions in util.cpp
EXTERN bool fileExists (char *fileName); EXTERN bool fileExists (const char *fileName);
EXTERN char * createString (char *string); EXTERN char * createString (const char *string);
EXTERN char * createString (char *first, char *second); EXTERN char * createString (const char *first, const char *second);
EXTERN char * createFileName (char *type, int extension); EXTERN char * createFileName (const char *type, int extension);
EXTERN char * createFileName (char *type, char *extension); EXTERN char * createFileName (const char *type, const char *extension);
EXTERN char * createFileName (char *type, int level, int extension); EXTERN char * createFileName (const char *type, int level, int extension);
EXTERN char * createEditableString (char *string); EXTERN char * createEditableString (const char *string);
EXTERN void log (char *message); EXTERN void log (const char *message);
EXTERN void log (char *message, char *detail); EXTERN void log (const char *message, const char *detail);
EXTERN void log (char *message, int number); EXTERN void log (const char *message, int number);
EXTERN void logError (char *message, char *detail); EXTERN void logError (const char *message, const char *detail);
#endif #endif
...@@ -25,57 +25,60 @@ ...@@ -25,57 +25,60 @@
#include "io/gfx/video.h" #include "io/gfx/video.h"
File::File (char * fileName, bool write) { File::File (const char * name, bool write) {
// Open the file from the current directory // Open the file from the user's directory
f = fopen(fileName, write ? "wb": "rb"); if (open(userPath, name, write)) return;
// If that succeeded, done // Open the file from the OpenJazz directory
if (f) { if (open(ojPath, name, write)) return;
//log("Opened file", fileName); // Open the file from the game directory
if (open(gamePath, name, write)) return;
filePath = createString(fileName); log("Could not open file", name);
return; throw E_FILE;
} }
// Create the file path
filePath = createString(path, fileName);
// Open the file from the path File::~File () {
f = fopen(filePath, write ? "wb": "rb");
if (f == NULL) { fclose(f);
log("Could not open file", fileName); //log("Closed file", filePath);
delete[] filePath; delete[] filePath;
throw E_FILE; return;
} }
//log("Opened file", filePath);
return; bool File::open (const char * path, const char * name, bool write) {
} // Create the file path for the given directory
filePath = createString(path, name);
// Open the file from the path
f = fopen(filePath, write ? "wb": "rb");
File::~File () { if (f) {
fclose(f); //log("Opened file", filePath);
//log("Closed file", filePath); return true;
}
delete[] filePath; delete[] filePath;
return; return false;
} }
int File::getSize () { int File::getSize () {
int pos, size; int pos, size;
......
...@@ -30,7 +30,7 @@ ...@@ -30,7 +30,7 @@
#include <stdio.h> #include <stdio.h>
// Class // Classes
class File { class File {
...@@ -38,8 +38,10 @@ class File { ...@@ -38,8 +38,10 @@ class File {
FILE *f; FILE *f;
char *filePath; char *filePath;
bool open (const char * path, const char * name, bool write);
public: public:
File (char * fileName, bool write); File (const char * name, bool write);
~File (); ~File ();
int getSize (); int getSize ();
...@@ -61,10 +63,12 @@ class File { ...@@ -61,10 +63,12 @@ class File {
}; };
//Variable // Variables
// Path to game data // Paths to files
EXTERN char *path; EXTERN char *userPath;
EXTERN char *ojPath;
EXTERN char *gamePath;
#endif #endif
...@@ -33,7 +33,7 @@ ...@@ -33,7 +33,7 @@
#include <string.h> #include <string.h>
Font::Font (char * fileName) { Font::Font (const char * fileName) {
File *file; File *file;
unsigned char *pixels, *character; unsigned char *pixels, *character;
...@@ -314,7 +314,7 @@ Font::~Font () { ...@@ -314,7 +314,7 @@ Font::~Font () {
int Font::showString (char * s, int x, int y) { int Font::showString (const char * s, int x, int y) {
SDL_Rect src, dst; SDL_Rect src, dst;
unsigned int count; unsigned int count;
...@@ -466,27 +466,41 @@ void Font::restorePalette () { ...@@ -466,27 +466,41 @@ void Font::restorePalette () {
} }
int Font::calcStringWidth(char *s) int Font::getHeight () {
{
return h;
}
int Font::getStringWidth (const char *string) {
int count; int count;
int stringwidth = 0; int stringWidth = 0;
// Go through each character of the string // Go through each character of the string
for (count = 0; s[count]; count++) { for (count = 0; string[count]; count++) {
if (s[count] == '\n') { if (string[count] == '\n') {
} else { } else {
int width = w[(int)(map[(int)(s[count])])];
int width = w[(int)(map[(int)(string[count])])];
if (string[count] == ' ') {
width = width >> 1;
}
stringWidth += width - 1;
if(s[count] == 32) {
width = width/2;
} }
stringwidth += (width-1);
} }
} return stringWidth;
}
return stringwidth;
}
...@@ -42,17 +42,17 @@ class Font { ...@@ -42,17 +42,17 @@ class Font {
char map[128]; // Maps ASCII values to letter positions char map[128]; // Maps ASCII values to letter positions
public: public:
Font (char *fileName); Font (const char *fileName);
Font (File *file, bool big); Font (File *file, bool big);
~Font (); ~Font ();
int showString (char *s, int x, int y); int showString (const char *s, int x, int y);
void showNumber (int n, int x, int y); void showNumber (int n, int x, int y);
void mapPalette (int start, int length, int newStart, void mapPalette (int start, int length, int newStart,
int newLength); int newLength);
void restorePalette (); void restorePalette ();
int fontHeight() { return h; } int getHeight ();
int calcStringWidth(char *s); int getStringWidth (const char *string);
}; };
// Variables // Variables
......
...@@ -113,7 +113,7 @@ void openAudio () { ...@@ -113,7 +113,7 @@ void openAudio () {
// Load sounds // Load sounds
if (loadSounds("sounds.000") != E_NONE) sounds = NULL; if (loadSounds(F_SOUNDS) != E_NONE) sounds = NULL;
return; return;
...@@ -133,7 +133,7 @@ void closeAudio () { ...@@ -133,7 +133,7 @@ void closeAudio () {
} }
void playMusic (char * fileName) { void playMusic (const char * fileName) {
#ifdef USE_MODPLUG #ifdef USE_MODPLUG
...@@ -234,7 +234,7 @@ void stopMusic () { ...@@ -234,7 +234,7 @@ void stopMusic () {
} }
int loadSounds (char *fileName) { int loadSounds (const char *fileName) {
File *file; File *file;
unsigned char *clip; unsigned char *clip;
......
...@@ -74,9 +74,9 @@ EXTERN int nSounds; ...@@ -74,9 +74,9 @@ EXTERN int nSounds;
EXTERN void openAudio (); EXTERN void openAudio ();
EXTERN void closeAudio (); EXTERN void closeAudio ();
EXTERN void playMusic (char *fileName); EXTERN void playMusic (const char *fileName);
EXTERN void stopMusic (); EXTERN void stopMusic ();
EXTERN int loadSounds (char *fileName); EXTERN int loadSounds (const char *fileName);
EXTERN void freeSounds (); EXTERN void freeSounds ();
EXTERN void playSound (int sound); EXTERN void playSound (int sound);
......
...@@ -37,7 +37,7 @@ ...@@ -37,7 +37,7 @@
#include "player/player.h" #include "player/player.h"
DemoLevel::DemoLevel (char *fileName) { DemoLevel::DemoLevel (const char *fileName) {
File *file; File *file;
char *levelFile; char *levelFile;
......
...@@ -551,7 +551,7 @@ void Level::timeCalcs (bool paused) { ...@@ -551,7 +551,7 @@ void Level::timeCalcs (bool paused) {
int Level::play () { int Level::play () {
char *options[5] = {"continue game", "save game", "load game", const char *options[5] = {"continue game", "save game", "load game",
"setup options", "quit game"}; "setup options", "quit game"};
PaletteEffect *levelPE; PaletteEffect *levelPE;
char *string; char *string;
......
...@@ -181,7 +181,7 @@ class DemoLevel : public Level { ...@@ -181,7 +181,7 @@ class DemoLevel : public Level {
unsigned char *macro; unsigned char *macro;
public: public:
DemoLevel (char *fileName); DemoLevel (const char *fileName);
~DemoLevel (); ~DemoLevel ();
int play (); int play ();
......
...@@ -43,6 +43,7 @@ ...@@ -43,6 +43,7 @@
#include "level/level.h" #include "level/level.h"
#include "menu/menu.h" #include "menu/menu.h"
#include "player/player.h" #include "player/player.h"
#include "scene.h"
#include <string.h> #include <string.h>
...@@ -555,57 +556,80 @@ int main(int argc, char *argv[]) { ...@@ -555,57 +556,80 @@ int main(int argc, char *argv[]) {
/* /*
Scene *scene; Scene *scene;
*/ */
int count;
// Find path // Determine user path
#ifdef HOMEDIR
#ifdef WIN32
userPath = createString(getenv("HOME"), "\\");
#else
userPath = createString(getenv("HOME"), "/.");
#endif
#else
userPath = createString("");
#endif
if (argc < 2) {
// No path was given, use the path of the program // Determine OpenJazz path
int count; // Use the path of the program, if available
count = strlen(argv[0]) - 1; count = strlen(argv[0]) - 1;
// Search for directory separator // Search for directory separator
#ifdef WIN32 #ifdef WIN32
while ((argv[0][count] != '\\') && (count >= 0)) count--; while ((argv[0][count] != '\\') && (count >= 0)) count--;
#else #else
while ((argv[0][count] != '/') && (count >= 0)) count--; while ((argv[0][count] != '/') && (count >= 0)) count--;
#endif #endif
path = new char[count + 2]; // If a directory was found, copy it to the path
if (count >= 0) {
// If a directory was found, copy it to the path ojPath = new char[count + 2];
if (count >= 0) { memcpy(ojPath, argv[0], count + 1);
ojPath[count + 1] = 0;
memcpy(path, argv[0], count + 1); } else ojPath = createString("");
path[count + 1] = 0;
} else path[0] = 0;
} else { // Determine game path
#ifdef DATAPATH
gamePath = createString(DATAPATH);
#elseifdef __SYMBIAN32__
#ifdef UIQ3
gamePath = createString("c:\\shared\\openjazz\\");
#else
gamePath = createString("c:\\data\\openjazz\\");
#endif
#else
if (argc >= 2) {
// Copy the provided path, appending a directory separator as necessary // Copy the provided path, appending a directory separator as necessary
#ifdef WIN32 #ifdef WIN32
if (argv[1][strlen(argv[1]) - 1] != '\\') { if (argv[1][strlen(argv[1]) - 1] != '\\') {
#else
gamePath = createString(argv[1], "\\");
#else
if (argv[1][strlen(argv[1]) - 1] != '/') { if (argv[1][strlen(argv[1]) - 1] != '/') {
#endif
#ifdef WIN32 gamePath = createString(argv[1], "/");
path = createString(argv[1], "\\"); #endif
#else
path = createString(argv[1], "/");
#endif
} else { } else {
path = createString(argv[1]); gamePath = createString(argv[1]);
} }
} } else gamePath = createString("");
#endif
// Initialise SDL // Initialise SDL
...@@ -625,7 +649,9 @@ int main(int argc, char *argv[]) { ...@@ -625,7 +649,9 @@ int main(int argc, char *argv[]) {
if (loadMain() != E_NONE) { if (loadMain() != E_NONE) {
SDL_Quit(); SDL_Quit();
delete[] path; delete[] ojPath;
delete[] gamePath;
delete[] userPath;
return -1; return -1;
...@@ -633,18 +659,20 @@ int main(int argc, char *argv[]) { ...@@ -633,18 +659,20 @@ int main(int argc, char *argv[]) {
// Show the startup cutscene // Show the startup cutscene
/*
try {
scene = new Scene("startup.0sc"); /* try {
scene = new Scene(F_STARTUP_0SC);
} catch (int e) { } catch (int e) {
freeMain(); freeMain();
SDL_Quit(); SDL_Quit();
delete[] path; delete[] ojPath;
delete[] gamePath;
delete[] userPath;
return e; return e;
} }
...@@ -662,7 +690,9 @@ int main(int argc, char *argv[]) { ...@@ -662,7 +690,9 @@ int main(int argc, char *argv[]) {
freeMain(); freeMain();
SDL_Quit(); SDL_Quit();
delete[] path; delete[] ojPath;
delete[] gamePath;
delete[] userPath;
return e; return e;
...@@ -672,17 +702,19 @@ int main(int argc, char *argv[]) { ...@@ -672,17 +702,19 @@ int main(int argc, char *argv[]) {
if (menu->main() == E_NONE) { if (menu->main() == E_NONE) {
// Show the ending cutscene // Show the ending cutscene
/*
try {
scene = new Scene("end.0sc"); /* try {
scene = new Scene(F_END_0SC);
} catch (int e) { } catch (int e) {
delete menu; delete menu;
freeMain(); freeMain();
SDL_Quit(); SDL_Quit();
delete[] path; delete[] ojPath;
delete[] gamePath;
delete[] userPath;
return e; return e;
...@@ -703,7 +735,9 @@ int main(int argc, char *argv[]) { ...@@ -703,7 +735,9 @@ int main(int argc, char *argv[]) {
freeMain(); freeMain();
SDL_Quit(); SDL_Quit();
delete[] path; delete[] ojPath;
delete[] gamePath;
delete[] userPath;
return 0; return 0;
......
...@@ -38,7 +38,7 @@ ...@@ -38,7 +38,7 @@
int Menu::newGameDifficulty (int mode, int levelNum, int worldNum) { int Menu::newGameDifficulty (int mode, int levelNum, int worldNum) {
char *options[4] = {"easy", "medium", "hard", "turbo"}; const char *options[4] = {"easy", "medium", "hard", "turbo"};
char *firstLevel; char *firstLevel;
SDL_Rect src, dst; SDL_Rect src, dst;
int count; int count;
...@@ -220,9 +220,9 @@ int Menu::newGameLevel (int mode) { ...@@ -220,9 +220,9 @@ int Menu::newGameLevel (int mode) {
int Menu::newGameEpisode (int mode) { int Menu::newGameEpisode (int mode) {
char *options[12] = {"episode 1", "episode 2", "episode 3", "episode 4", const char *options[12] = {"episode 1", "episode 2", "episode 3",
"episode 5", "episode 6", "episode a", "episode b", "episode c", "episode 4", "episode 5", "episode 6", "episode a", "episode b",
"episode x", "bonus stage", "specific level"}; "episode c", "episode x", "bonus stage", "specific level"};
bool exists[12]; bool exists[12];
char *check; char *check;
SDL_Rect dst; SDL_Rect dst;
......
...@@ -40,7 +40,7 @@ ...@@ -40,7 +40,7 @@
int Menu::main () { int Menu::main () {
char *newGameOptions[6] = {"new single player game", "new co-op game", const char *newGameOptions[6] = {"new single player game", "new co-op game",
"new battle", "new team battle", "new race", "join game"}; "new battle", "new team battle", "new race", "join game"};
Scene *scene; Scene *scene;
SDL_Rect src, dst; SDL_Rect src, dst;
...@@ -189,7 +189,7 @@ int Menu::main () { ...@@ -189,7 +189,7 @@ int Menu::main () {
try { try {
level = new DemoLevel("macro.2"); level = new DemoLevel(F_MACRO);
} catch (int e) { } catch (int e) {
......
...@@ -43,9 +43,9 @@ class Menu { ...@@ -43,9 +43,9 @@ class Menu {
int episodes; int episodes;
unsigned char difficulty; unsigned char difficulty;
int message (char *text); int message (const char *text);
int generic (char **optionNames, int options, int *chosen); int generic (const char **optionNames, int options, int *chosen);
int textInput (char *request, char **text); int textInput (const char *request, char **text);
int newGameDifficulty (int mode, int levelNum, int worldNum); int newGameDifficulty (int mode, int levelNum, int worldNum);
int newGameLevel (int mode); int newGameLevel (int mode);
int newGameEpisode (int mode); int newGameEpisode (int mode);
......
...@@ -35,7 +35,7 @@ ...@@ -35,7 +35,7 @@
#include <string.h> #include <string.h>
int Menu::message (char *text) { int Menu::message (const char *text) {
// Display a message to the user // Display a message to the user
...@@ -62,7 +62,7 @@ int Menu::message (char *text) { ...@@ -62,7 +62,7 @@ int Menu::message (char *text) {
} }
int Menu::generic (char **optionNames, int options, int *chosen) { int Menu::generic (const char **optionNames, int options, int *chosen) {
// Let the user select from a menu of the given options // Let the user select from a menu of the given options
...@@ -112,7 +112,7 @@ int Menu::generic (char **optionNames, int options, int *chosen) { ...@@ -112,7 +112,7 @@ int Menu::generic (char **optionNames, int options, int *chosen) {
} }
int Menu::textInput (char *request, char **text) { int Menu::textInput (const char *request, char **text) {
// Let the user to edit a text string // Let the user to edit a text string
......
...@@ -37,7 +37,7 @@ ...@@ -37,7 +37,7 @@
int Menu::setupKeyboard () { int Menu::setupKeyboard () {
char *options[7] = {"up", "down", "left", "right", "jump", "fire", const char *options[7] = {"up", "down", "left", "right", "jump", "fire",
"weapon"}; "weapon"};
int progress, count, character; int progress, count, character;
bool used; bool used;
...@@ -122,7 +122,7 @@ int Menu::setupKeyboard () { ...@@ -122,7 +122,7 @@ int Menu::setupKeyboard () {
int Menu::setupJoystick () { int Menu::setupJoystick () {
char *options[7] = {"up", "down", "left", "right", "jump", "fire", const char *options[7] = {"up", "down", "left", "right", "jump", "fire",
"weapon"}; "weapon"};
int progress, count, control; int progress, count, control;
bool used; bool used;
...@@ -428,12 +428,13 @@ int Menu::setupResolution () { ...@@ -428,12 +428,13 @@ int Menu::setupResolution () {
int Menu::setup () { int Menu::setup () {
char *setupOptions[4] = {"character", "keyboard", "joystick", "resolution"}; const char *setupOptions[4] = {"character", "keyboard", "joystick",
char *setupCharacterOptions[5] = {"name", "fur", "bandana", "gun", "resolution"};
const char *setupCharacterOptions[5] = {"name", "fur", "bandana", "gun",
"wristband"}; "wristband"};
char *setupCharacterColOptions[8] = {"white", "red", "orange", "yellow", const char *setupCharacterColOptions[8] = {"white", "red", "orange",
"green", "blue", "animation 1", "animation 2"}; "yellow", "green", "blue", "animation 1", "animation 2"};
unsigned char setupCharacterCols[8] = {PC_WHITE, PC_RED, PC_ORANGE, const unsigned char setupCharacterCols[8] = {PC_WHITE, PC_RED, PC_ORANGE,
PC_YELLOW, PC_LGREEN, PC_BLUE, PC_SANIM, PC_LANIM}; PC_YELLOW, PC_LGREEN, PC_BLUE, PC_SANIM, PC_LANIM};
int ret; int ret;
int option, suboption, subsuboption; int option, suboption, subsuboption;
......
...@@ -36,6 +36,8 @@ ...@@ -36,6 +36,8 @@
#include "io/sound.h" #include "io/sound.h"
#include "io/gfx/paletteeffects.h" #include "io/gfx/paletteeffects.h"
#include <string.h>
/** /**
* This is the 0sc format * This is the 0sc format
* Offset, Size (hex), type * Offset, Size (hex), type
...@@ -46,7 +48,7 @@ ...@@ -46,7 +48,7 @@
* *
* ----, 0x02 Number of data items * ----, 0x02 Number of data items
* * 0x19, 0x4* Number of script items, Offset to datablocks * * 0x19, 0x4* Number of script items, Offset to datablocks
* *
*/ */
// These are the known script types // These are the known script types
enum enum
...@@ -83,7 +85,7 @@ ImageInfo::~ImageInfo() { ...@@ -83,7 +85,7 @@ ImageInfo::~ImageInfo() {
if(image != NULL) { if(image != NULL) {
SDL_FreeSurface(image); SDL_FreeSurface(image);
image = NULL; image = NULL;
} }
} }
ScriptText::ScriptText() { ScriptText::ScriptText() {
...@@ -96,9 +98,11 @@ ScriptText::ScriptText() { ...@@ -96,9 +98,11 @@ ScriptText::ScriptText() {
} }
ScriptText::~ScriptText() { ScriptText::~ScriptText() {
free(text);
text = NULL; if (text) delete[] text;
}
}
ScriptPage::ScriptPage() { ScriptPage::ScriptPage() {
pageTime = 0; pageTime = 0;
noScriptTexts = 0; noScriptTexts = 0;
...@@ -108,8 +112,9 @@ ScriptPage::ScriptPage() { ...@@ -108,8 +112,9 @@ ScriptPage::ScriptPage() {
} }
ScriptPage::~ScriptPage() { ScriptPage::~ScriptPage() {
free(musicfile);
musicfile = NULL; if (musicfile) delete[] musicfile;
} }
void Scene::ParseAni(File* f, int dataIndex) { void Scene::ParseAni(File* f, int dataIndex) {
...@@ -129,7 +134,7 @@ void Scene::ParseAni(File* f, int dataIndex) { ...@@ -129,7 +134,7 @@ void Scene::ParseAni(File* f, int dataIndex) {
for(loop = 0;loop<noSounds;loop++) { for(loop = 0;loop<noSounds;loop++) {
char* soundName = f->loadString(); char* soundName = f->loadString();
log("Soundname ", soundName); log("Soundname ", soundName);
free(soundName); delete[] soundName;
} }
} }
else if(type == 0x4C50) {// PL else if(type == 0x4C50) {// PL
...@@ -226,21 +231,26 @@ void Scene::ParseAni(File* f, int dataIndex) { ...@@ -226,21 +231,26 @@ void Scene::ParseAni(File* f, int dataIndex) {
case 0x5252: case 0x5252:
break; break;
case 0x5b5d: case 0x5b5d:
{
unsigned char header = f->loadChar(); unsigned char header = f->loadChar();
log("PL 5b5d block header", header); log("PL 5b5d block header", header);
unsigned short int value = f->loadShort(); unsigned short int value = f->loadShort();
log("PL 5b5d block value", value); log("PL 5b5d block value", value);
}
break; break;
case 0x5453: case 0x5453:
{
unsigned char soundIndex = f->loadChar(); unsigned char soundIndex = f->loadChar();
unsigned char soundNote = f->loadChar(); unsigned char soundNote = f->loadChar();
unsigned char soundOffset = f->loadChar(); unsigned char soundOffset = f->loadChar();
log("PL Audio tag with index", soundIndex); log("PL Audio tag with index", soundIndex);
log("PL Audio tag play at ", soundNote); log("PL Audio tag play at ", soundNote);
log("PL Audio tag play offset ", soundOffset); log("PL Audio tag play offset ", soundOffset);
}
break; break;
case 0: case 0:
{
int longvalue = f->loadInt(); int longvalue = f->loadInt();
while(longvalue == 0) { while(longvalue == 0) {
longvalue = f->loadInt(); longvalue = f->loadInt();
...@@ -248,6 +258,7 @@ void Scene::ParseAni(File* f, int dataIndex) { ...@@ -248,6 +258,7 @@ void Scene::ParseAni(File* f, int dataIndex) {
} }
f->seek(-4, false); f->seek(-4, false);
value = longvalue; value = longvalue;
}
break; break;
default: default:
log("PL Read Unknown type", value); log("PL Read Unknown type", value);
...@@ -336,7 +347,8 @@ void Scene::ParseScripts(File *f) { ...@@ -336,7 +347,8 @@ void Scene::ParseScripts(File *f) {
int textPosY = -1; int textPosY = -1;
int extraheight = -1; int extraheight = -1;
SDL_Rect textRect = {-1,-1,-1,-1}; SDL_Rect textRect;
bool textRectValid = false;
f->seek(scriptStarts[loop], true); // Seek to data start f->seek(scriptStarts[loop], true); // Seek to data start
if(f->loadChar() == 0x50) { // Script tag if(f->loadChar() == 0x50) { // Script tag
unsigned short int scriptid = f->loadShort(); unsigned short int scriptid = f->loadShort();
...@@ -386,7 +398,7 @@ void Scene::ParseScripts(File *f) { ...@@ -386,7 +398,7 @@ void Scene::ParseScripts(File *f) {
// Music file name // Music file name
string = f->loadString(); string = f->loadString();
log("ESceneMusic: ", string); log("ESceneMusic: ", string);
scriptPages[loop].musicfile = strdup(string); scriptPages[loop].musicfile = createString(string);
delete[] string; delete[] string;
}break; }break;
case ESceneSomethingElse: case ESceneSomethingElse:
...@@ -400,6 +412,7 @@ void Scene::ParseScripts(File *f) { ...@@ -400,6 +412,7 @@ void Scene::ParseScripts(File *f) {
unsigned short y = textRect.y = f->loadShort(); unsigned short y = textRect.y = f->loadShort();
unsigned short w = textRect.w = (f->loadShort()-x); unsigned short w = textRect.w = (f->loadShort()-x);
unsigned short h = textRect.h = (f->loadShort()-y); unsigned short h = textRect.h = (f->loadShort()-y);
textRectValid = true;
log("Text rectangle xpos:", x); log("Text rectangle xpos:", x);
log("Text rectangle ypos:", y); log("Text rectangle ypos:", y);
log("Text rectangle w:", w); log("Text rectangle w:", w);
...@@ -434,7 +447,7 @@ void Scene::ParseScripts(File *f) { ...@@ -434,7 +447,7 @@ void Scene::ParseScripts(File *f) {
scriptFonts[noScriptFonts].fontId = fontid; scriptFonts[noScriptFonts].fontId = fontid;
noScriptFonts++; noScriptFonts++;
free(fontname); delete[] fontname;
}break; }break;
case ESceneTextPosition: case ESceneTextPosition:
{ {
...@@ -447,8 +460,10 @@ void Scene::ParseScripts(File *f) { ...@@ -447,8 +460,10 @@ void Scene::ParseScripts(File *f) {
} }
break; break;
case ESceneTextColour: case ESceneTextColour:
{
unsigned short value = f->loadShort(); unsigned short value = f->loadShort();
log("ESceneTextColour", value); log("ESceneTextColour", value);
}
break; break;
case ESceneFontFun: case ESceneFontFun:
{ {
...@@ -578,14 +593,14 @@ void Scene::ParseScripts(File *f) { ...@@ -578,14 +593,14 @@ void Scene::ParseScripts(File *f) {
} }
if(orgdatalen > 0) { if(orgdatalen > 0) {
scriptPages[loop].scriptTexts[scriptPages[loop].noScriptTexts].text =(char*) malloc(orgdatalen+1); scriptPages[loop].scriptTexts[scriptPages[loop].noScriptTexts].text = new char[orgdatalen + 1];
memcpy(scriptPages[loop].scriptTexts[scriptPages[loop].noScriptTexts].text, block, orgdatalen); memcpy(scriptPages[loop].scriptTexts[scriptPages[loop].noScriptTexts].text, block, orgdatalen);
scriptPages[loop].scriptTexts[scriptPages[loop].noScriptTexts].text[orgdatalen] = 0; scriptPages[loop].scriptTexts[scriptPages[loop].noScriptTexts].text[orgdatalen] = 0;
log("Text data",(char*) scriptPages[loop].scriptTexts[scriptPages[loop].noScriptTexts].text); log("Text data",(char*) scriptPages[loop].scriptTexts[scriptPages[loop].noScriptTexts].text);
} }
else { else {
scriptPages[loop].scriptTexts[scriptPages[loop].noScriptTexts].text =(char*) malloc(1); scriptPages[loop].scriptTexts[scriptPages[loop].noScriptTexts].text = new char[1];
scriptPages[loop].scriptTexts[scriptPages[loop].noScriptTexts].text[0] = 0; scriptPages[loop].scriptTexts[scriptPages[loop].noScriptTexts].text[0] = 0;
log("Text data", "Empty line"); log("Text data", "Empty line");
} }
...@@ -597,11 +612,10 @@ void Scene::ParseScripts(File *f) { ...@@ -597,11 +612,10 @@ void Scene::ParseScripts(File *f) {
textPosX = -1; textPosX = -1;
textPosY = -1; textPosY = -1;
} }
if(textRect.x != -1) if(textRectValid)
{ {
scriptPages[loop].scriptTexts[scriptPages[loop].noScriptTexts].textRect = textRect; scriptPages[loop].scriptTexts[scriptPages[loop].noScriptTexts].textRect = textRect;
textRect.x = -1; textRectValid = false;
textRect.y = -1;
} }
if(extraheight != -1) if(extraheight != -1)
{ {
...@@ -611,10 +625,12 @@ void Scene::ParseScripts(File *f) { ...@@ -611,10 +625,12 @@ void Scene::ParseScripts(File *f) {
scriptPages[loop].noScriptTexts++; scriptPages[loop].noScriptTexts++;
}break; }break;
case ESceneTime: case ESceneTime:
{
unsigned short int sceneTime = f->loadShort(); unsigned short int sceneTime = f->loadShort();
log("Scene time",sceneTime&255); log("Scene time",sceneTime&255);
scriptPages[loop].pageTime = sceneTime&255; scriptPages[loop].pageTime = sceneTime&255;
break; }
break;
case ESceneBreaker: case ESceneBreaker:
case 0x3e: case 0x3e:
pos = f->tell(); pos = f->tell();
...@@ -639,7 +655,7 @@ void Scene::ParseScripts(File *f) { ...@@ -639,7 +655,7 @@ void Scene::ParseScripts(File *f) {
} }
Scene::Scene (char * fileName) { Scene::Scene (const char * fileName) {
File *file; File *file;
int loop; int loop;
...@@ -841,17 +857,19 @@ int Scene::play () { ...@@ -841,17 +857,19 @@ int Scene::play () {
font->showString(scriptPages[sceneIndex].scriptTexts[text].text, textRect.x+x,textRect.y+y); font->showString(scriptPages[sceneIndex].scriptTexts[text].text, textRect.x+x,textRect.y+y);
break; break;
case 1: // right case 1: // right
int width = font->calcStringWidth(scriptPages[sceneIndex].scriptTexts[text].text); {
int width = font->getStringWidth(scriptPages[sceneIndex].scriptTexts[text].text);
font->showString(scriptPages[sceneIndex].scriptTexts[text].text, textRect.x+textRect.w-width, textRect.y+y); font->showString(scriptPages[sceneIndex].scriptTexts[text].text, textRect.x+textRect.w-width, textRect.y+y);
}
break; break;
case 2: // center case 2: // center
{ {
int width = font->calcStringWidth(scriptPages[sceneIndex].scriptTexts[text].text)/2; int width = font->getStringWidth(scriptPages[sceneIndex].scriptTexts[text].text)/2;
font->showString(scriptPages[sceneIndex].scriptTexts[text].text, textRect.x+(textRect.w/2)-width,textRect.y+ y); font->showString(scriptPages[sceneIndex].scriptTexts[text].text, textRect.x+(textRect.w/2)-width,textRect.y+ y);
} }
break; break;
} }
y+=(extralineheight+font->fontHeight()/2); y+=(extralineheight+font->getHeight()/2);
} }
} }
......
...@@ -23,8 +23,11 @@ ...@@ -23,8 +23,11 @@
#ifndef _SCENE_H #ifndef _SCENE_H
#define _SCENE_H #define _SCENE_H
#include <io/file.h> #include <io/file.h>
#include <sdl.h>
#include <SDL/SDL.h>
enum EScriptFontTypes enum EScriptFontTypes
{ {
...@@ -117,7 +120,7 @@ class Scene { ...@@ -117,7 +120,7 @@ class Scene {
void ParseData(File *f); void ParseData(File *f);
void ParseAni(File* f, int dataIndex); void ParseAni(File* f, int dataIndex);
public: public:
Scene (char * fileName); Scene (const char * fileName);
~Scene (); ~Scene ();
int play (); int play ();
......
...@@ -34,7 +34,7 @@ ...@@ -34,7 +34,7 @@
#include <string.h> #include <string.h>
bool fileExists (char * fileName) { bool fileExists (const char * fileName) {
File *file; File *file;
...@@ -57,7 +57,7 @@ bool fileExists (char * fileName) { ...@@ -57,7 +57,7 @@ bool fileExists (char * fileName) {
} }
char * createString (char *string) { char * createString (const char *string) {
char *cloned; char *cloned;
...@@ -69,7 +69,7 @@ char * createString (char *string) { ...@@ -69,7 +69,7 @@ char * createString (char *string) {
} }
char * createString (char *first, char *second) { char * createString (const char *first, const char *second) {
char *concatenated; char *concatenated;
...@@ -82,7 +82,7 @@ char * createString (char *first, char *second) { ...@@ -82,7 +82,7 @@ char * createString (char *first, char *second) {
} }
char * createFileName (char *type, int extension) { char * createFileName (const char *type, int extension) {
char *fileName; char *fileName;
int pos; int pos;
...@@ -101,7 +101,7 @@ char * createFileName (char *type, int extension) { ...@@ -101,7 +101,7 @@ char * createFileName (char *type, int extension) {
} }
char * createFileName (char *type, char *extension) { char * createFileName (const char *type, const char *extension) {
char *fileName; char *fileName;
int pos; int pos;
...@@ -117,7 +117,7 @@ char * createFileName (char *type, char *extension) { ...@@ -117,7 +117,7 @@ char * createFileName (char *type, char *extension) {
} }
char * createFileName (char *type, int level, int extension) { char * createFileName (const char *type, int level, int extension) {
char *fileName; char *fileName;
int pos; int pos;
...@@ -137,7 +137,7 @@ char * createFileName (char *type, int level, int extension) { ...@@ -137,7 +137,7 @@ char * createFileName (char *type, int level, int extension) {
} }
char * createEditableString (char *string) { char * createEditableString (const char *string) {
char *cloned; char *cloned;
...@@ -149,7 +149,7 @@ char * createEditableString (char *string) { ...@@ -149,7 +149,7 @@ char * createEditableString (char *string) {
} }
void log (char *message) { void log (const char *message) {
printf("%s\n", message); printf("%s\n", message);
...@@ -158,7 +158,7 @@ void log (char *message) { ...@@ -158,7 +158,7 @@ void log (char *message) {
} }
void log (char *message, char *detail) { void log (const char *message, const char *detail) {
printf("%s: %s\n", message, detail); printf("%s: %s\n", message, detail);
...@@ -167,7 +167,7 @@ void log (char *message, char *detail) { ...@@ -167,7 +167,7 @@ void log (char *message, char *detail) {
} }
void log (char *message, int number) { void log (const char *message, int number) {
printf("%s: %d\n", message, number); printf("%s: %d\n", message, number);
...@@ -176,7 +176,7 @@ void log (char *message, int number) { ...@@ -176,7 +176,7 @@ void log (char *message, int number) {
} }
void logError (char *message, char *detail) { void logError (const char *message, const char *detail) {
fprintf(stderr, "%s: %s\n", message, detail); fprintf(stderr, "%s: %s\n", message, detail);
......
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