aboutsummaryrefslogtreecommitdiff
path: root/engines
diff options
context:
space:
mode:
authorTony Puccinelli2010-08-09 06:55:25 +0000
committerTony Puccinelli2010-08-09 06:55:25 +0000
commit83f1531cb8fa5ba43c246143ecdde2cb1d140a8e (patch)
treec31cb2d9980580eccb992a73a176356d32fff7c5 /engines
parent924c4e0c06eb90677847d04b185468ad3d2efb22 (diff)
downloadscummvm-rg350-83f1531cb8fa5ba43c246143ecdde2cb1d140a8e.tar.gz
scummvm-rg350-83f1531cb8fa5ba43c246143ecdde2cb1d140a8e.tar.bz2
scummvm-rg350-83f1531cb8fa5ba43c246143ecdde2cb1d140a8e.zip
Moved a large number of global variables in the Cruise Engine into a Singleton class and modified all references to these variables to access them via an instance of this Singleton class
svn-id: r51935
Diffstat (limited to 'engines')
-rw-r--r--engines/cruise/actor.cpp22
-rw-r--r--engines/cruise/background.cpp12
-rw-r--r--engines/cruise/cruise.cpp6
-rw-r--r--engines/cruise/cruise_main.cpp38
-rw-r--r--engines/cruise/cruise_main.h2
-rw-r--r--engines/cruise/ctp.cpp10
-rw-r--r--engines/cruise/ctp.h4
-rw-r--r--engines/cruise/font.cpp27
-rw-r--r--engines/cruise/function.cpp12
-rw-r--r--engines/cruise/gfxModule.cpp95
-rw-r--r--engines/cruise/gfxModule.h6
-rw-r--r--engines/cruise/mainDraw.cpp26
-rw-r--r--engines/cruise/perso.cpp6
-rw-r--r--engines/cruise/saveload.cpp18
-rw-r--r--engines/cruise/vars.cpp31
-rw-r--r--engines/cruise/vars.h56
-rw-r--r--engines/cruise/volume.cpp8
17 files changed, 214 insertions, 165 deletions
diff --git a/engines/cruise/actor.cpp b/engines/cruise/actor.cpp
index 81e39600f5..87b7f0a27f 100644
--- a/engines/cruise/actor.cpp
+++ b/engines/cruise/actor.cpp
@@ -293,7 +293,7 @@ int point_proche(int16 table[][2]) {
int x1, y1, i, x, y, p;
int d1 = 1000;
- polyStructs = &polyStructNorm;
+ polyStructs = &CVars.polyStructNorm;
if (nclick_noeud == 1) {
x = x_mouse;
@@ -301,19 +301,19 @@ int point_proche(int16 table[][2]) {
x1 = table_ptselect[0][0];
y1 = table_ptselect[0][1];
- polyStructs = &polyStructExp;
+ polyStructs = &CVars.polyStructExp;
getPixel(x, y);
if (!flag_obstacle) {
- polyStructs = &polyStructNorm;
+ polyStructs = &CVars.polyStructNorm;
getPixel(x, y);
if (flag_obstacle) {
polydroite(x1, y1, x, y);
}
- polyStructs = &polyStructExp;
+ polyStructs = &CVars.polyStructExp;
}
if (!flag_obstacle) { /* dans flag_obstacle --> couleur du point */
x1 = table_ptselect[0][0];
@@ -325,7 +325,7 @@ int point_proche(int16 table[][2]) {
y_mouse = Y;
}
}
- polyStructs = &polyStructNorm;
+ polyStructs = &CVars.polyStructNorm;
p = -1;
for (i = 0; i < ctp_routeCoordCount; i++) {
@@ -453,7 +453,7 @@ void valide_noeud(int16 table[], int16 p, int *nclick, int16 solution0[20 + 3][2
table_ptselect[*nclick][0] = x_mouse;
table_ptselect[*nclick][1] = y_mouse;
(*nclick)++;
- polyStructs = &polyStructNorm;
+ polyStructs = &CVars.polyStructNorm;
if (*nclick == 2) { // second point
x1 = table_ptselect[0][0];
@@ -464,7 +464,7 @@ void valide_noeud(int16 table[], int16 p, int *nclick, int16 solution0[20 + 3][2
return;
}
flag_aff_chemin = 1;
- polyStructs = &polyStructExp;
+ polyStructs = &CVars.polyStructExp;
// can we go there directly ?
polydroite(x1, y1, x2, y2);
@@ -472,7 +472,7 @@ void valide_noeud(int16 table[], int16 p, int *nclick, int16 solution0[20 + 3][2
if (!flag_obstacle) {
solution0[0][0] = x1;
solution0[0][1] = y1;
- polyStructs = &polyStructExp;
+ polyStructs = &CVars.polyStructExp;
poly2(x2, y2, ctp_routeCoords[select_noeud[1]][0],
ctp_routeCoords[select_noeud[1]][1]);
@@ -516,7 +516,7 @@ void valide_noeud(int16 table[], int16 p, int *nclick, int16 solution0[20 + 3][2
solution0[++i][1] =
ctp_routeCoords[p1][1];
}
- polyStructs = &polyStructExp;
+ polyStructs = &CVars.polyStructExp;
poly2(x2, y2,
ctp_routeCoords[select_noeud[1]][0],
ctp_routeCoords[select_noeud[1]][1]);
@@ -541,7 +541,7 @@ void valide_noeud(int16 table[], int16 p, int *nclick, int16 solution0[20 + 3][2
while (flag_obstacle && i != d) {
x2 = solution0[i][0];
y2 = solution0[i][1];
- polyStructs = &polyStructExp;
+ polyStructs = &CVars.polyStructExp;
polydroite(x1, y1, x2, y2);
i--;
}
@@ -621,7 +621,7 @@ int16 computePathfinding(MovementEntry &moveInfo, int16 x, int16 y, int16 destX,
}
nclick_noeud = 0;
- polyStructs = &polyStructNorm;
+ polyStructs = &CVars.polyStructNorm;
flag_aff_chemin = 0;
if (x == destX && y == destY) {
diff --git a/engines/cruise/background.cpp b/engines/cruise/background.cpp
index 3ac57cc376..da6a35aff0 100644
--- a/engines/cruise/background.cpp
+++ b/engines/cruise/background.cpp
@@ -47,10 +47,10 @@ int loadMEN(uint8 **ptr) {
if (!strcmp(localPtr, "MEN")) {
localPtr += 4;
- titleColor = *(localPtr++);
- selectColor = *(localPtr++);
- itemColor = *(localPtr++);
- subColor = *(localPtr++);
+ CVars.titleColor = *(localPtr++);
+ CVars.selectColor = *(localPtr++);
+ CVars.itemColor = *(localPtr++);
+ CVars.subColor = *(localPtr++);
*ptr = (uint8 *) localPtr;
@@ -104,9 +104,9 @@ int loadBackground(const char *name, int idx) {
backgroundChanged[idx] = true;
- ptrToFree = gfxModuleData.pPage10;
+ ptrToFree = CVars.pPage10;
if (loadFileSub1(&ptrToFree, name, NULL) < 0) {
- if (ptrToFree != gfxModuleData.pPage10)
+ if (ptrToFree != CVars.pPage10)
MemFree(ptrToFree);
return (-18);
diff --git a/engines/cruise/cruise.cpp b/engines/cruise/cruise.cpp
index e6d0359059..964f22af3d 100644
--- a/engines/cruise/cruise.cpp
+++ b/engines/cruise/cruise.cpp
@@ -137,8 +137,8 @@ void CruiseEngine::initialize() {
}
void CruiseEngine::deinitialise() {
- polyStructNorm.clear();
- polyStructExp.clear();
+ CVars.polyStructNorm.clear();
+ CVars.polyStructExp.clear();
// Clear any backgrounds
for (int i = 0; i < 8; ++i) {
@@ -205,7 +205,7 @@ void CruiseEngine::pauseEngine(bool pause) {
if (pause) {
// Draw the 'Paused' message
drawSolidBox(64, 100, 256, 117, 0);
- drawString(10, 100, langString(ID_PAUSED), gfxModuleData.pPage00, itemColor, 300);
+ drawString(10, 100, langString(ID_PAUSED), CVars.pPage00, CVars.itemColor, 300);
gfxModuleData_flipScreen();
_savedCursor = currentCursor;
diff --git a/engines/cruise/cruise_main.cpp b/engines/cruise/cruise_main.cpp
index 14de916a84..ceab9bf706 100644
--- a/engines/cruise/cruise_main.cpp
+++ b/engines/cruise/cruise_main.cpp
@@ -38,17 +38,15 @@ namespace Cruise {
enum RelationType {RT_REL = 30, RT_MSG = 50};
static int playerDontAskQuit;
-unsigned int timer = 0;
-
-gfxEntryStruct* linkedMsgList = NULL;
-
-Common::List<byte *> memList;
+#if !defined(__DS__)
+//unsigned int timer = 0;
+#endif
void MemoryList() {
- if (!memList.empty()) {
+ if (!CVars.memList.empty()) {
printf("Current list of un-freed memory blocks:\n");
Common::List<byte *>::iterator i;
- for (i = memList.begin(); i != memList.end(); ++i) {
+ for (i = CVars.memList.begin(); i != CVars.memList.end(); ++i) {
byte *v = *i;
printf("%s - %d\n", (const char *)(v - 68), *((int32 *)(v - 72)));
}
@@ -73,7 +71,7 @@ void *MemoryAlloc(uint32 size, bool clearFlag, int32 lineNum, const char *fname)
// Add the block to the memory list
result = v + 64 + 8;
- memList.push_back(result);
+ CVars.memList.push_back(result);
} else
result = (byte *)malloc(size);
@@ -91,7 +89,7 @@ void MemoryFree(void *v) {
byte *p = (byte *)v;
assert(*((uint32 *) (p - 4)) == 0x41424344);
- memList.remove(p);
+ CVars.memList.remove(p);
free(p - 8 - 64);
} else
free(v);
@@ -953,7 +951,7 @@ bool createDialog(int objOvl, int objIdx, int x, int y) {
int color;
if (objectState2 == -2)
- color = subColor;
+ color = CVars.subColor;
else
color = -1;
@@ -1390,12 +1388,12 @@ void closeAllMenu() {
freeMenu(menuTable[1]);
menuTable[1] = NULL;
}
- if (linkedMsgList) {
+ if (CVars.linkedMsgList) {
ASSERT(0);
-// freeMsgList(linkedMsgList);
+// freeMsgList(CVars.linkedMsgList);
}
- linkedMsgList = NULL;
+ CVars.linkedMsgList = NULL;
linkedRelation = NULL;
}
@@ -1545,12 +1543,12 @@ int CruiseEngine::processInput() {
freeMenu(menuTable[0]);
menuTable[0] = NULL;
- if (linkedMsgList) {
+ if (CVars.linkedMsgList) {
ASSERT(0);
- // freeMsgList(linkedMsgList);
+ // freeMsgList(CVars.linkedMsgList);
}
- linkedMsgList = NULL;
+ CVars.linkedMsgList = NULL;
linkedRelation = NULL;
changeCursor(CURSOR_NORMAL);
@@ -1582,10 +1580,10 @@ int CruiseEngine::processInput() {
menuTable[0] = NULL;
}
- if (linkedMsgList) {
-// freeMsgList(linkedMsgList);
+ if (CVars.linkedMsgList) {
+// freeMsgList(CVars.linkedMsgList);
}
- linkedMsgList = NULL;
+ CVars.linkedMsgList = NULL;
linkedRelation = NULL;
changeCursor(CURSOR_NORMAL);
} else { // call sub relation when clicking in inventory
@@ -1655,7 +1653,7 @@ int CruiseEngine::processInput() {
strcpy(text, menuTable[0]->stringPtr);
strcat(text, ":");
strcat(text, currentMenuElement->string);
- linkedMsgList = renderText(320, (const char *)text);
+ CVars.linkedMsgList = renderText(320, (const char *)text);
changeCursor(CURSOR_CROSS);
}
}
diff --git a/engines/cruise/cruise_main.h b/engines/cruise/cruise_main.h
index 8657b4bc21..406ebfaa2b 100644
--- a/engines/cruise/cruise_main.h
+++ b/engines/cruise/cruise_main.h
@@ -81,7 +81,7 @@ enum ResType {
OBJ_TYPE_EXIT = 9
};
-extern gfxEntryStruct* linkedMsgList;
+//extern gfxEntryStruct* linkedMsgList;
extern int buttonDown;
extern int selectDown;
diff --git a/engines/cruise/ctp.cpp b/engines/cruise/ctp.cpp
index 59f3cae942..1ee29917d1 100644
--- a/engines/cruise/ctp.cpp
+++ b/engines/cruise/ctp.cpp
@@ -29,10 +29,6 @@
namespace Cruise {
-uint8 *ctpVar17;
-
-Common::Array<CtStruct> polyStructNorm;
-Common::Array<CtStruct> polyStructExp;
Common::Array<CtStruct> *polyStructs = NULL;
Common::Array<CtStruct> *polyStruct = NULL;
@@ -324,16 +320,16 @@ int initCt(const char *ctpName) {
// Load the polyStructNorm list
for (int i = numberOfWalkboxes - 1; i >= 0; i--) {
- makeCtStruct(polyStructNorm, ctp_walkboxTable, i, 0);
+ makeCtStruct(CVars.polyStructNorm, ctp_walkboxTable, i, 0);
}
// Load the polyStructExp list
for (int i = numberOfWalkboxes - 1; i >= 0; i--) {
- makeCtStruct(polyStructExp, ctp_walkboxTable, i, walkboxZoom[i] * 20);
+ makeCtStruct(CVars.polyStructExp, ctp_walkboxTable, i, walkboxZoom[i] * 20);
}
- polyStruct = polyStructs = &polyStructNorm;
+ polyStruct = polyStructs = &CVars.polyStructNorm;
return (1);
}
diff --git a/engines/cruise/ctp.h b/engines/cruise/ctp.h
index 6cc5ea48ef..f6968e184a 100644
--- a/engines/cruise/ctp.h
+++ b/engines/cruise/ctp.h
@@ -62,10 +62,6 @@ public:
Common::Array<CtEntry> slices;
};
-extern uint8 *ctpVar17;
-
-extern Common::Array<CtStruct> polyStructNorm;
-extern Common::Array<CtStruct> polyStructExp;
extern Common::Array<CtStruct> *polyStructs;
extern Common::Array<CtStruct> *polyStruct;
diff --git a/engines/cruise/font.cpp b/engines/cruise/font.cpp
index 3a609cb8d4..aecadab193 100644
--- a/engines/cruise/font.cpp
+++ b/engines/cruise/font.cpp
@@ -30,6 +30,7 @@
#include "cruise/cruise_main.h"
#include "cruise/mouse.h"
#include "cruise/staticres.h"
+#include "cruise/vars.h"
namespace Cruise {
@@ -98,7 +99,7 @@ int32 getTextLineCount(int32 rightBorder_X, int16 wordSpacingWidth,
void loadFNT(const char *fileName) {
uint8 header[4];
- _systemFNT = NULL;
+ CVars._systemFNT = NULL;
Common::File fontFileHandle;
@@ -112,20 +113,20 @@ void loadFNT(const char *fileName) {
if (strcmp((char*)header, "FNT") == 0) {
uint32 fontSize = fontFileHandle.readUint32BE();
- _systemFNT = (uint8 *)mallocAndZero(fontSize);
+ CVars._systemFNT = (uint8 *)mallocAndZero(fontSize);
- if (_systemFNT != NULL) {
+ if (CVars._systemFNT != NULL) {
fontFileHandle.seek(4);
- fontFileHandle.read(_systemFNT, fontSize);
+ fontFileHandle.read(CVars._systemFNT, fontSize);
// Flip structure values from BE to LE for font files - this is for consistency
// with font resources, which are in LE formatt
- FontInfo *f = (FontInfo *)_systemFNT;
+ FontInfo *f = (FontInfo *)CVars._systemFNT;
bigEndianLongToNative(&f->offset);
bigEndianLongToNative(&f->size);
flipGen(&f->numChars, 6); // numChars, hSpacing, and vSpacing
- FontEntry *fe = (FontEntry *)(_systemFNT + sizeof(FontInfo));
+ FontEntry *fe = (FontEntry *)(CVars._systemFNT + sizeof(FontInfo));
for (int i = 0; i < f->numChars; ++i, ++fe) {
bigEndianLongToNative(&fe->offset); // Flip 32-bit offset field
@@ -140,10 +141,10 @@ void loadFNT(const char *fileName) {
void initSystem() {
int32 i;
- itemColor = 15;
- titleColor = 9;
- selectColor = 13;
- subColor = 10;
+ CVars.itemColor = 15;
+ CVars.titleColor = 9;
+ CVars.selectColor = 13;
+ CVars.subColor = 10;
for (i = 0; i < 64; i++) {
strcpy(preloadData[i].name, "");
@@ -169,7 +170,7 @@ void initSystem() {
}
void freeSystem() {
- MemFree(_systemFNT);
+ MemFree(CVars._systemFNT);
}
void bigEndianShortToNative(void *var) {
@@ -309,10 +310,10 @@ gfxEntryStruct *renderText(int inRightBorder_X, const char *string) {
fontPtr = (const FontInfo *)filesDatabase[fontFileIndex].subData.ptr;
if (!fontPtr) {
- fontPtr = (const FontInfo *)_systemFNT;
+ fontPtr = (const FontInfo *)CVars._systemFNT;
}
} else {
- fontPtr = (const FontInfo *)_systemFNT;
+ fontPtr = (const FontInfo *)CVars._systemFNT;
}
if (!fontPtr) {
diff --git a/engines/cruise/function.cpp b/engines/cruise/function.cpp
index 3d07abf441..a25a54c562 100644
--- a/engines/cruise/function.cpp
+++ b/engines/cruise/function.cpp
@@ -446,8 +446,8 @@ int16 Op_KillMenu() {
}
// Free the message list
-// if (linkedMsgList) freeMsgList(linkedMsgList);
- linkedMsgList = NULL;
+// if (CVars.linkedMsgList) freeMsgList(CVars.linkedMsgList);
+ CVars.linkedMsgList = NULL;
linkedRelation = NULL;
return 0;
@@ -1268,10 +1268,10 @@ int16 Op_regenerateBackgroundIncrust() {
int16 Op_SetStringColors() {
// TODO: here ignore if low color mode
- subColor = (uint8) popVar();
- itemColor = (uint8) popVar();
- selectColor = (uint8) popVar();
- titleColor = (uint8) popVar();
+ CVars.subColor = (uint8) popVar();
+ CVars.itemColor = (uint8) popVar();
+ CVars.selectColor = (uint8) popVar();
+ CVars.titleColor = (uint8) popVar();
return 0;
}
diff --git a/engines/cruise/gfxModule.cpp b/engines/cruise/gfxModule.cpp
index dbc8160ac6..1e77037e84 100644
--- a/engines/cruise/gfxModule.cpp
+++ b/engines/cruise/gfxModule.cpp
@@ -34,29 +34,16 @@
namespace Cruise {
-uint8 page00[320 * 200];
-uint8 page10[320 * 200];
-
-char screen[320 * 200];
-palEntry lpalette[256];
-
-int palDirtyMin = 256;
-int palDirtyMax = -1;
-
typedef Common::List<Common::Rect> RectList;
-RectList _dirtyRects;
-RectList _priorFrameRects;
-
-bool _dirtyRectScreen = false;
-gfxModuleDataStruct gfxModuleData = {
+/*gfxModuleDataStruct gfxModuleData = {
0, // use Tandy
0, // use EGA
1, // use VGA
- page00, // pPage00
- page10, // pPage10
-};
+ CVars.page00, // pPage00
+ CVars.page10, // pPage10
+};*/
void gfxModuleData_gfxClearFrameBuffer(uint8 *ptr) {
memset(ptr, 0, 64000);
@@ -112,16 +99,16 @@ void convertGfxFromMode5(const uint8 *sourcePtr, int width, int height, uint8 *d
}
void gfxModuleData_setDirtyColors(int min, int max) {
- if (min < palDirtyMin)
- palDirtyMin = min;
- if (max > palDirtyMax)
- palDirtyMax = max;
+ if (min < CVars.palDirtyMin)
+ CVars.palDirtyMin = min;
+ if (max > CVars.palDirtyMax)
+ CVars.palDirtyMax = max;
}
void gfxModuleData_setPalColor(int idx, int r, int g, int b) {
- lpalette[idx].R = r;
- lpalette[idx].G = g;
- lpalette[idx].B = b;
+ CVars.lpalette[idx].R = r;
+ CVars.lpalette[idx].G = g;
+ CVars.lpalette[idx].B = b;
gfxModuleData_setDirtyColors(idx, idx);
}
@@ -133,10 +120,10 @@ void gfxModuleData_setPalEntries(const byte *ptr, int start, int num) {
G = *(ptr++);
B = *(ptr++);
- lpalette[i].R = R;
- lpalette[i].G = G;
- lpalette[i].B = B;
- lpalette[i].A = 255;
+ CVars.lpalette[i].R = R;
+ CVars.lpalette[i].G = G;
+ CVars.lpalette[i].B = B;
+ CVars.lpalette[i].A = 255;
}
gfxModuleData_setDirtyColors(start, start + num - 1);
@@ -169,10 +156,10 @@ void gfxModuleData_setPal256(const byte *ptr) {
if (B > 0xFF)
B = 0xFF;
- lpalette[i].R = R;
- lpalette[i].G = G;
- lpalette[i].B = B;
- lpalette[i].A = 255;
+ CVars.lpalette[i].R = R;
+ CVars.lpalette[i].G = G;
+ CVars.lpalette[i].B = B;
+ CVars.lpalette[i].A = 255;
}
gfxModuleData_setDirtyColors(0, 16);
@@ -227,18 +214,18 @@ void gfxCopyRect(const uint8 *sourceBuffer, int width, int height, byte *dest, i
void gfxModuleData_Init() {
memset(globalScreen, 0, 320 * 200);
- memset(page00, 0, 320 * 200);
- memset(page10, 0, 320 * 200);
+ memset(CVars.page00, 0, 320 * 200);
+ memset(CVars.page10, 0, 320 * 200);
}
void gfxModuleData_flipScreen() {
- memcpy(globalScreen, gfxModuleData.pPage00, 320 * 200);
+ memcpy(globalScreen, CVars.pPage00, 320 * 200);
flip();
}
void gfxModuleData_addDirtyRect(const Common::Rect &r) {
- _dirtyRects.push_back(Common::Rect( MAX(r.left, (int16)0), MAX(r.top, (int16)0),
+ CVars._dirtyRects.push_back(Common::Rect( MAX(r.left, (int16)0), MAX(r.top, (int16)0),
MIN(r.right, (int16)320), MIN(r.bottom, (int16)200)));
}
@@ -257,9 +244,9 @@ static bool unionRectangle(Common::Rect &pDest, const Common::Rect &pSrc1, const
static void mergeClipRects() {
RectList::iterator rOuter, rInner;
- for (rOuter = _dirtyRects.begin(); rOuter != _dirtyRects.end(); ++rOuter) {
+ for (rOuter = CVars._dirtyRects.begin(); rOuter != CVars._dirtyRects.end(); ++rOuter) {
rInner = rOuter;
- while (++rInner != _dirtyRects.end()) {
+ while (++rInner != CVars._dirtyRects.end()) {
if ((*rOuter).intersects(*rInner)) {
// these two rectangles overlap, so translate it to a bigger rectangle
@@ -267,7 +254,7 @@ static void mergeClipRects() {
unionRectangle(*rOuter, *rOuter, *rInner);
// remove the inner rect from the list
- _dirtyRects.erase(rInner);
+ CVars._dirtyRects.erase(rInner);
// move back to beginning of list
rInner = rOuter;
@@ -279,16 +266,16 @@ static void mergeClipRects() {
void gfxModuleData_updatePalette() {
byte paletteRGBA[256 * 4];
- if (palDirtyMax != -1) {
- for (int i = palDirtyMin; i <= palDirtyMax; i++) {
- paletteRGBA[i * 4 + 0] = lpalette[i].R;
- paletteRGBA[i * 4 + 1] = lpalette[i].G;
- paletteRGBA[i * 4 + 2] = lpalette[i].B;
+ if (CVars.palDirtyMax != -1) {
+ for (int i = CVars.palDirtyMin; i <= CVars.palDirtyMax; i++) {
+ paletteRGBA[i * 4 + 0] = CVars.lpalette[i].R;
+ paletteRGBA[i * 4 + 1] = CVars.lpalette[i].G;
+ paletteRGBA[i * 4 + 2] = CVars.lpalette[i].B;
paletteRGBA[i * 4 + 3] = 0xFF;
}
- g_system->setPalette(paletteRGBA + palDirtyMin*4, palDirtyMin, palDirtyMax - palDirtyMin + 1);
- palDirtyMin = 256;
- palDirtyMax = -1;
+ g_system->setPalette(paletteRGBA + CVars.palDirtyMin*4, CVars.palDirtyMin, CVars.palDirtyMax - CVars.palDirtyMin + 1);
+ CVars.palDirtyMin = 256;
+ CVars.palDirtyMax = -1;
}
}
@@ -304,26 +291,26 @@ void flip() {
gfxModuleData_updatePalette();
// Make a copy of the prior frame's dirty rects, and then backup the current frame's rects
- RectList tempList = _priorFrameRects;
- _priorFrameRects = _dirtyRects;
+ RectList tempList = CVars._priorFrameRects;
+ CVars._priorFrameRects = CVars._dirtyRects;
// Merge the prior frame's dirty rects into the current frame's list
for (dr = tempList.begin(); dr != tempList.end(); ++dr) {
Common::Rect &r = *dr;
- _dirtyRects.push_back(Common::Rect(r.left, r.top, r.right, r.bottom));
+ CVars._dirtyRects.push_back(Common::Rect(r.left, r.top, r.right, r.bottom));
}
// Merge any overlapping rects to simplify the drawing process
mergeClipRects();
// Copy any modified areas
- for (dr = _dirtyRects.begin(); dr != _dirtyRects.end(); ++dr) {
+ for (dr = CVars._dirtyRects.begin(); dr != CVars._dirtyRects.end(); ++dr) {
Common::Rect &r = *dr;
g_system->copyRectToScreen(globalScreen + 320 * r.top + r.left, 320,
r.left, r.top, r.width(), r.height());
}
- _dirtyRects.clear();
+ CVars._dirtyRects.clear();
// Allow the screen to update
g_system->updateScreen();
@@ -331,7 +318,7 @@ void flip() {
void drawSolidBox(int32 x1, int32 y1, int32 x2, int32 y2, uint8 colour) {
for (int y = y1; y < y2; ++y) {
- byte *p = &gfxModuleData.pPage00[y * 320 + x1];
+ byte *p = &CVars.pPage00[y * 320 + x1];
Common::set_to(p, p + (x2 - x1), colour);
}
}
@@ -345,7 +332,7 @@ void resetBitmap(uint8 *dataPtr, int32 dataSize) {
* to figure out rectangles of changed areas for dirty rectangles
*/
void switchBackground(const byte *newBg) {
- const byte *bg = gfxModuleData.pPage00;
+ const byte *bg = CVars.pPage00;
int sliceXStart, sliceXEnd;
// If both the upper corners are different, presume it's a full screen change
diff --git a/engines/cruise/gfxModule.h b/engines/cruise/gfxModule.h
index 1dbc5afc9b..289cc24d98 100644
--- a/engines/cruise/gfxModule.h
+++ b/engines/cruise/gfxModule.h
@@ -28,14 +28,14 @@
namespace Cruise {
-struct gfxModuleDataStruct {
+/*struct gfxModuleDataStruct {
int useTandy;
int useEGA;
int useVGA;
uint8 *pPage00;
uint8 *pPage10;
-};
+};*/
struct palEntry {
uint8 R;
@@ -44,7 +44,7 @@ struct palEntry {
uint8 A;
};
-extern gfxModuleDataStruct gfxModuleData;
+//extern gfxModuleDataStruct gfxModuleData;
void gfxModuleData_gfxClearFrameBuffer(uint8 *ptr);
void gfxModuleData_setDirtyColors(int min, int max);
diff --git a/engines/cruise/mainDraw.cpp b/engines/cruise/mainDraw.cpp
index aaa6f987b6..67c6d96455 100644
--- a/engines/cruise/mainDraw.cpp
+++ b/engines/cruise/mainDraw.cpp
@@ -135,7 +135,7 @@ void flipScreen() {
gfxModuleData_setPal256(workpal);
}
- SWAP(gfxModuleData.pPage00, gfxModuleData.pPage10);
+ SWAP(CVars.pPage00, CVars.pPage10);
gfxModuleData_flipScreen();
@@ -1330,7 +1330,7 @@ void drawMenu(menuStruct *pMenu) {
int wx = x + (nbcol - 1) * (160 / 2);
if (wx <= 320 - 160) {
- drawMessage(pMenu->gfx, wx, y - hline, 160, titleColor, gfxModuleData.pPage10);
+ drawMessage(pMenu->gfx, wx, y - hline, 160, CVars.titleColor, CVars.pPage10);
}
wx = x;
@@ -1348,17 +1348,17 @@ void drawMenu(menuStruct *pMenu) {
int color;
if (p1->selected) {
- color = selectColor;
+ color = CVars.selectColor;
} else {
if (p1->color != 255) {
color = p1->color;
} else {
- color = itemColor;
+ color = CVars.itemColor;
}
}
if (wx <= (320 - 160)) {
- drawMessage(p2, wx, wy, 160, color, gfxModuleData.pPage10);
+ drawMessage(p2, wx, wy, 160, color, CVars.pPage10);
}
wy += hline;
@@ -1418,7 +1418,7 @@ void mainDraw(int16 param) {
bgPtr = backgroundScreens[masterScreen];
if (bgPtr) {
- gfxModuleData_gfxCopyScreen(bgPtr, gfxModuleData.pPage10);
+ gfxModuleData_gfxCopyScreen(bgPtr, CVars.pPage10);
if (backgroundChanged[masterScreen]) {
backgroundChanged[masterScreen] = false;
switchBackground(bgPtr);
@@ -1469,7 +1469,7 @@ void mainDraw(int16 param) {
if ((params.state >= 0) && (objZ2 >= 0) && filesDatabase[objZ2].subData.ptr) {
if (filesDatabase[objZ2].subData.resourceType == 8) { // Poly
- mainDrawPolygons(objZ2, currentObjPtr, objX2, params.scale, objY2, (char *)gfxModuleData.pPage10, (char *)filesDatabase[objZ2].subData.ptr); // poly
+ mainDrawPolygons(objZ2, currentObjPtr, objX2, params.scale, objY2, (char *)CVars.pPage10, (char *)filesDatabase[objZ2].subData.ptr); // poly
} else if (filesDatabase[objZ2].subData.resourceType == OBJ_TYPE_SOUND) {
} else if (filesDatabase[objZ2].resType == OBJ_TYPE_MASK) {
} else if (filesDatabase[objZ2].subData.resourceType == OBJ_TYPE_SPRITE) {
@@ -1477,7 +1477,7 @@ void mainDraw(int16 param) {
spriteHeight = filesDatabase[objZ2].height; // height
if (filesDatabase[objZ2].subData.ptr) {
- drawSprite(objX1, spriteHeight, currentObjPtr, filesDatabase[objZ2].subData.ptr, objY2, objX2, gfxModuleData.pPage10, filesDatabase[objZ2].subData.ptrMask);
+ drawSprite(objX1, spriteHeight, currentObjPtr, filesDatabase[objZ2].subData.ptr, objY2, objX2, CVars.pPage10, filesDatabase[objZ2].subData.ptrMask);
}
}
}
@@ -1573,7 +1573,7 @@ void mainDraw(int16 param) {
while (currentObjPtr) {
if (currentObjPtr->type == OBJ_TYPE_MESSAGE && currentObjPtr->freeze == 0) {
- drawMessage(currentObjPtr->gfxPtr, currentObjPtr->x, currentObjPtr->field_C, currentObjPtr->spriteIdx, currentObjPtr->color, gfxModuleData.pPage10);
+ drawMessage(currentObjPtr->gfxPtr, currentObjPtr->x, currentObjPtr->field_C, currentObjPtr->spriteIdx, currentObjPtr->color, CVars.pPage10);
isMessage = 1;
}
currentObjPtr = currentObjPtr->next;
@@ -1586,16 +1586,16 @@ void mainDraw(int16 param) {
drawMenu(menuTable[currentActiveMenu]);
return;
}
- } else if ((linkedRelation) && (linkedMsgList)) {
+ } else if ((linkedRelation) && (CVars.linkedMsgList)) {
int16 mouseX;
int16 mouseY;
int16 button;
getMouseStatus(&main10, &mouseX, &button, &mouseY);
- if (mouseY > (linkedMsgList->height)*2)
- drawMessage(linkedMsgList, 0, 0, 320, findHighColor(), gfxModuleData.pPage10);
+ if (mouseY > (CVars.linkedMsgList->height)*2)
+ drawMessage(CVars.linkedMsgList, 0, 0, 320, findHighColor(), CVars.pPage10);
else
- drawMessage(linkedMsgList, 0, 200, 320, findHighColor(), gfxModuleData.pPage10);
+ drawMessage(CVars.linkedMsgList, 0, 200, 320, findHighColor(), CVars.pPage10);
}
}
diff --git a/engines/cruise/perso.cpp b/engines/cruise/perso.cpp
index 27d3c8cb7d..1e92b8bc3e 100644
--- a/engines/cruise/perso.cpp
+++ b/engines/cruise/perso.cpp
@@ -46,12 +46,12 @@ void freeCTP() {
}
if (polyStruct) {
- polyStructNorm.clear();
- polyStructExp.clear();
+ CVars.polyStructNorm.clear();
+ CVars.polyStructExp.clear();
polyStruct = NULL;
}
- ctpVar17 = NULL;
+ CVars.ctpVar17 = NULL;
polyStruct = NULL;
strcpy((char *)currentCtpName, "");
diff --git a/engines/cruise/saveload.cpp b/engines/cruise/saveload.cpp
index 6e50ef8cdb..bfbf808168 100644
--- a/engines/cruise/saveload.cpp
+++ b/engines/cruise/saveload.cpp
@@ -113,10 +113,10 @@ static void syncBasicInfo(Common::Serializer &s) {
s.syncAsSint16LE(isMessage);
s.syncAsSint16LE(fadeFlag);
s.syncAsSint16LE(automaticMode);
- s.syncAsSint16LE(titleColor);
- s.syncAsSint16LE(itemColor);
- s.syncAsSint16LE(selectColor);
- s.syncAsSint16LE(subColor);
+ s.syncAsSint16LE(CVars.titleColor);
+ s.syncAsSint16LE(CVars.itemColor);
+ s.syncAsSint16LE(CVars.selectColor);
+ s.syncAsSint16LE(CVars.subColor);
s.syncAsSint16LE(narratorOvl);
s.syncAsSint16LE(narratorIdx);
s.syncAsSint16LE(aniX);
@@ -582,7 +582,7 @@ static void syncCT(Common::Serializer &s) {
int v = (polyStruct) ? 1 : 0;
s.syncAsSint32LE(v);
if (s.isLoading())
- polyStruct = (v != 0) ? &polyStructNorm : NULL;
+ polyStruct = (v != 0) ? &CVars.polyStructNorm : NULL;
if (v == 0)
// There is no further data to load or save
@@ -762,10 +762,10 @@ void initVars() {
// video param (vga and mcga mode)
- titleColor = 2;
- itemColor = 1;
- selectColor = 3;
- subColor = 5;
+ CVars.titleColor = 2;
+ CVars.itemColor = 1;
+ CVars.selectColor = 3;
+ CVars.subColor = 5;
//
diff --git a/engines/cruise/vars.cpp b/engines/cruise/vars.cpp
index 94fd00cbfd..87f0626355 100644
--- a/engines/cruise/vars.cpp
+++ b/engines/cruise/vars.cpp
@@ -24,15 +24,36 @@
*/
#include "cruise/cruise_main.h"
+#include "cruise/vars.h"
+
+DECLARE_SINGLETON(Cruise::CruiseVars)
namespace Cruise {
-uint8 *_systemFNT = NULL;
+CruiseVars::CruiseVars() {
+ _systemFNT = NULL;
+
+ itemColor = 1;
+ selectColor = 3;
+ titleColor = 2;
+ subColor = 5;
+
+ linkedMsgList = NULL;
+
+ palDirtyMin = 256;
+ palDirtyMax = -1;
+
+ _dirtyRectScreen = false;
+
+ useTandy = 0;
+ useEGA = 0;
+ useVGA = 1;
+
+ pPage00 = page00;
+ pPage10 = page10;
+}
-uint8 itemColor = 1;
-uint8 selectColor = 3;
-uint8 titleColor = 2;
-uint8 subColor = 5;
+CruiseVars::~CruiseVars() {}
int16 lowMemory;
int16 scroll;
diff --git a/engines/cruise/vars.h b/engines/cruise/vars.h
index 1e19794f3a..06b479128b 100644
--- a/engines/cruise/vars.h
+++ b/engines/cruise/vars.h
@@ -27,9 +27,16 @@
#define CRUISE_VARS_H
#include "common/file.h"
+#include "common/list.h"
+#include "common/singleton.h"
+#include "common/endian.h"
+#include "common/util.h"
+#include "gfxModule.h"
namespace Cruise {
+typedef Common::List<Common::Rect> RectList;
+
#define NBCOLORS 256
#define NBSCREENS 8
@@ -54,13 +61,50 @@ struct menuElementStruct {
typedef int32(*opcodeTypeFunction)();
typedef int16(*opcodeFunction)();
-extern uint8 *_systemFNT;
extern int16 fontFileIndex;
-extern uint8 itemColor;
-extern uint8 selectColor;
-extern uint8 titleColor;
-extern uint8 subColor;
+class CruiseVars : public Common::Singleton<CruiseVars> {
+public:
+ uint8 *_systemFNT;
+
+ uint8 itemColor;
+ uint8 selectColor;
+ uint8 titleColor;
+ uint8 subColor;
+
+ gfxEntryStruct* linkedMsgList;
+
+ Common::List<byte *> memList;
+
+ uint8 *ctpVar17;
+
+ Common::Array<CtStruct> polyStructNorm;
+ Common::Array<CtStruct> polyStructExp;
+
+ uint8 page00[320 * 200];
+ uint8 page10[320 * 200];
+ char screen[320 * 200];
+
+ palEntry lpalette[256];
+
+ int palDirtyMin;
+ int palDirtyMax;
+
+ RectList _dirtyRects;
+ RectList _priorFrameRects;
+ bool _dirtyRectScreen;
+
+ int useTandy;
+ int useEGA;
+ int useVGA;
+
+ uint8 *pPage00;
+ uint8 *pPage10;
+
+ ~CruiseVars();
+ CruiseVars();
+
+};
extern int16 lowMemory;
extern int16 scroll;
@@ -301,4 +345,6 @@ extern uint8 globalScreen[320 * 200];
} // End of namespace Cruise
+#define CVars (::Cruise::CruiseVars::instance())
+
#endif
diff --git a/engines/cruise/volume.cpp b/engines/cruise/volume.cpp
index 3b856b4440..86b37bb394 100644
--- a/engines/cruise/volume.cpp
+++ b/engines/cruise/volume.cpp
@@ -27,7 +27,9 @@
namespace Cruise {
+#if !defined(__DS__)
Common::File PAL_file;
+#endif
uint8 *PAL_ptr = NULL;
int16 numLoadedPal;
@@ -57,6 +59,7 @@ void loadPal(volumeDataStruct *entry) {
}
void closePal() {
+#if !defined(__DS__)
if (PAL_file.isOpen()) {
PAL_file.close();
@@ -66,6 +69,7 @@ void closePal() {
numLoadedPal = 0;
fileData2 = 0;
}
+#endif
}
int closeBase() {
@@ -76,11 +80,11 @@ int closeBase() {
strcpy(currentBaseName, "");
}
-
+#if !defined(__DS__)
if (PAL_file.isOpen()) {
closePal();
}
-
+#endif
return 0;
}