LAB: Move the font loading code into the Resource class

This commit is contained in:
Filippos Karapetis 2015-10-08 06:15:36 +03:00 committed by Eugene Sandulenko
parent c67852d940
commit d565b10384
7 changed files with 14 additions and 91 deletions

View file

@ -38,6 +38,7 @@
#include "lab/parsefun.h"
#include "lab/interface.h"
#include "lab/mouse.h"
#include "lab/resource.h"
namespace Lab {
@ -1361,7 +1362,7 @@ void LabEngine::go() {
if (!dointro)
g_music->initMusic();
openFont("P:AvanteG.12", &MsgFont);
MsgFont = g_resource->getFont("P:AvanteG.12");
mouseHide();

View file

@ -31,6 +31,7 @@
#include "lab/lab.h"
#include "lab/stddefines.h"
#include "lab/labfun.h"
#include "lab/resource.h"
#include "lab/timing.h"
#include "lab/diff.h"
#include "lab/text.h"
@ -352,7 +353,7 @@ void introSequence() {
blackAllScreen();
g_music->updateMusic();
getFont("P:Map.fon", msgfont);
msgfont = g_resource->getFont("P:Map.fon");
nopalchange = true;
NReadPict("Intro.1", true);

View file

@ -99,7 +99,6 @@ uint32 flowTextToMem(Image *DestIm, void *font, /* the TextAttr pointer */
void drawMessage(const char *text);
int32 longDrawMessage(const char *text);
bool readFont(char *filename, void *font, void *data);
/* The Wipes */
@ -255,7 +254,6 @@ char *translateFileName(const char *filename);
void fade(bool fadein, uint16 res);
void setAmigaPal(uint16 *pal, uint16 numcolors);
char *getText(const char *filename);
bool getFont(const char *filename, TextFont *textfont);
void readImage(byte **buffer, Image **im);
void doMap(uint16 CurRoom);
void doJournal();

View file

@ -37,6 +37,7 @@
#include "lab/mouse.h"
#include "lab/parsefun.h"
#include "lab/parsetypes.h"
#include "lab/resource.h"
#include "lab/interface.h"
#include "lab/text.h"
@ -74,44 +75,6 @@ void setAmigaPal(uint16 *pal, uint16 numcolors) {
}
/*****************************************************************************/
/* Gets a font from disk and puts it into temporary memory. */
/*****************************************************************************/
bool getFont(const char *filename, TextFont *textfont) {
byte **file = NULL;
char header[5];
uint32 filesize, headersize = 4L + 2L + 256 * 3 + 4L;
file = g_music->newOpen(filename, filesize);
g_music->updateMusic();
if ((file != NULL) && (filesize > headersize)) {
byte *fontbuffer = (byte *)stealBufMem(filesize - (sizeof(TextFont) + 4));
if (!fontbuffer)
return false;
header[4] = 0;
readBlock(&header, 4L, file);
if (strcmp(header, "VGAF") == 0) {
textfont->DataLength = filesize - headersize;
readBlock(&(textfont->Height), 2L, file);
swapUShortPtr(&(textfont->Height), 1);
readBlock(textfont->Widths, 256L, file);
readBlock(textfont->Offsets, 256L * 2L, file);
swapUShortPtr(textfont->Offsets, 256);
(*file) += 4;
textfont->data = fontbuffer;
readBlock(textfont->data, textfont->DataLength, file);
return true;
}
}
return false;
}
/*****************************************************************************/
/* Gets a chunk of text and puts it into the graphics memory. */
@ -234,7 +197,7 @@ static bool loadMapData() {
BigMsgFont = &bmf;
if (!getFont("P:Map.fon", BigMsgFont))
if (!(BigMsgFont = g_resource->getFont("P:Map.fon")))
BigMsgFont = MsgFont;
resetBuffer(); /* Make images load into start of buffer */

View file

@ -44,6 +44,7 @@
#include "lab/timing.h"
#include "lab/stddefines.h"
#include "lab/parsetypes.h"
#include "lab/resource.h"
namespace Lab {
@ -474,7 +475,7 @@ void doNotes() {
/* Load in the data */
BigMsgFont = &bmfont;
if (!getFont("P:Note.fon", BigMsgFont)) {
if (!(BigMsgFont = g_resource->getFont("P:Note.fon"))) {
BigMsgFont = NULL;
return;
}
@ -500,7 +501,7 @@ void doWestPaper() {
BigMsgFont = &bmfont;
if (!getFont("P:News22.fon", BigMsgFont)) {
if (!(BigMsgFont = g_resource->getFont("P:News22.fon"))) {
BigMsgFont = NULL;
return;
}
@ -512,7 +513,7 @@ void doWestPaper() {
BigMsgFont = &bmfont;
if (!getFont("P:News32.fon", BigMsgFont)) {
if (!(BigMsgFont = g_resource->getFont("P:News32.fon"))) {
BigMsgFont = NULL;
return;
}
@ -531,7 +532,7 @@ void doWestPaper() {
BigMsgFont = &bmfont;
if (!getFont("P:Note.fon", BigMsgFont)) {
if (!(BigMsgFont = g_resource->getFont("P:Note.fon"))) {
BigMsgFont = NULL;
return;
}
@ -562,7 +563,7 @@ static bool loadJournalData() {
BigMsgFont = &bmfont;
if (!getFont("P:Journal.fon", BigMsgFont)) {
if (!(BigMsgFont = g_resource->getFont("P:Journal.fon"))) {
BigMsgFont = NULL;
return false;
}
@ -1071,7 +1072,7 @@ void doMonitor(char *background, char *textfile, bool isinteractive, uint16 x1,
BigMsgFont = &bmfont;
if (!getFont("P:Map.fon", BigMsgFont)) {
if (!(BigMsgFont = g_resource->getFont("P:Map.fon"))) {
freeAllStolenMem();
BigMsgFont = NULL;
return;

View file

@ -37,53 +37,13 @@ namespace Lab {
extern uint32 VGAScreenWidth, VGABytesPerPage;
/*****************************************************************************/
/* Opens up a font from disk. */
/*****************************************************************************/
bool openFont(const char *TextFontPath, struct TextFont **tf) {
byte **file = NULL;
char header[5];
uint32 filesize, headersize = 4L + 2L + 256 * 3 + 4L;
if ((*tf = (TextFont *)calloc(sizeof(struct TextFont), 1))) {
file = g_music->newOpen(TextFontPath, filesize);
if ((file != NULL) && (filesize > headersize)) {
header[4] = 0;
readBlock(&header, 4L, file);
if (strcmp(header, "VGAF") == 0) {
(*tf)->DataLength = filesize - headersize;
readBlock(&((*tf)->Height), 2L, file);
swapUShortPtr(&((*tf)->Height), 1);
readBlock((*tf)->Widths, 256L, file);
readBlock((*tf)->Offsets, 256L * 2L, file);
swapUShortPtr((*tf)->Offsets, 256);
(*file) += 4;
if (((*tf)->data = (byte *)calloc((*tf)->DataLength, 1))) {
readBlock((*tf)->data, (*tf)->DataLength, file);
return true;
}
}
}
free(*tf);
}
*tf = NULL;
return false;
}
/*****************************************************************************/
/* Closes a font and frees all memory associated with it. */
/*****************************************************************************/
void closeFont(struct TextFont *tf) {
if (tf) {
if (tf->data && tf->DataLength)
free(tf->data);
delete[] tf->data;
free(tf);
}

View file

@ -52,7 +52,6 @@ struct TextFont {
#pragma pack(pop)
#endif
bool openFont(const char *TextFontPath, TextFont **tf);
void closeFont(TextFont *tf);
uint16 textLength(TextFont *tf, const char *text, uint16 numchars);
uint16 textHeight(TextFont *tf);