SLUDGE: format code and remove oneliners

This commit is contained in:
yinsimei 2017-06-05 11:49:19 +02:00 committed by Eugene Sandulenko
parent 414b3c4714
commit 10ff6994ae
31 changed files with 1448 additions and 1396 deletions

View File

@ -251,11 +251,11 @@ void killParallax() {
bool reserveBackdrop() { bool reserveBackdrop() {
cameraX = 0; cameraX = 0;
cameraY = 0; cameraY = 0;
input.mouseX = (int) ((float) input.mouseX * cameraZoom); input.mouseX = (int)((float)input.mouseX * cameraZoom);
input.mouseY = (int) ((float) input.mouseY * cameraZoom); input.mouseY = (int)((float)input.mouseY * cameraZoom);
cameraZoom = 1.0; cameraZoom = 1.0;
input.mouseX = (int) ((float) input.mouseX / cameraZoom); input.mouseX = (int)((float)input.mouseX / cameraZoom);
input.mouseY = (int) ((float) input.mouseY / cameraZoom); input.mouseY = (int)((float)input.mouseY / cameraZoom);
setPixelCoords(false); setPixelCoords(false);
int picWidth = sceneWidth; int picWidth = sceneWidth;
int picHeight = sceneHeight; int picHeight = sceneHeight;
@ -317,9 +317,7 @@ void loadBackDrop(int fileNum, int x, int y) {
if (!loadHSI(bigDataFile, x, y, false)) { if (!loadHSI(bigDataFile, x, y, false)) {
char mess[200]; char mess[200];
sprintf(mess, sprintf(mess, "Can't paste overlay image outside scene dimensions\n\nX = %i\nY = %i\nWidth = %i\nHeight = %i", x, y, sceneWidth, sceneHeight);
"Can't paste overlay image outside scene dimensions\n\nX = %i\nY = %i\nWidth = %i\nHeight = %i",
x, y, sceneWidth, sceneHeight);
fatal(mess); fatal(mess);
} }
@ -348,10 +346,10 @@ void blankScreen(int x1, int y1, int x2, int y2) {
y1 = 0; y1 = 0;
if (x1 < 0) if (x1 < 0)
x1 = 0; x1 = 0;
if (x2 > (int) sceneWidth) if (x2 > (int)sceneWidth)
x2 = (int) sceneWidth; x2 = (int)sceneWidth;
if (y2 > (int) sceneHeight) if (y2 > (int)sceneHeight)
y2 = (int) sceneHeight; y2 = (int)sceneHeight;
int picWidth = x2 - x1; int picWidth = x2 - x1;
int picHeight = y2 - y1; int picHeight = y2 - y1;
@ -467,13 +465,11 @@ void darkScreen() {
int xoffset = 0; int xoffset = 0;
while (xoffset < sceneWidth) { while (xoffset < sceneWidth) {
int w = (sceneWidth - xoffset < viewportWidth) ? int w = (sceneWidth - xoffset < viewportWidth) ? sceneWidth - xoffset : viewportWidth;
sceneWidth - xoffset : viewportWidth;
int yoffset = 0; int yoffset = 0;
while (yoffset < sceneHeight) { while (yoffset < sceneHeight) {
int h = (sceneHeight - yoffset < viewportHeight) ? int h = (sceneHeight - yoffset < viewportHeight) ? sceneHeight - yoffset : viewportHeight;
sceneHeight - yoffset : viewportHeight;
// Render the scene - first the old backdrop // Render the scene - first the old backdrop
#if 0 #if 0
@ -533,8 +529,7 @@ void darkScreen() {
} }
inline int sortOutPCamera(int cX, int fX, int sceneMax, int boxMax) { inline int sortOutPCamera(int cX, int fX, int sceneMax, int boxMax) {
return (fX == 65535) ? return (fX == 65535) ? (sceneMax ? ((cX * boxMax) / sceneMax) : 0) : ((cX * fX) / 100);
(sceneMax ? ((cX * boxMax) / sceneMax) : 0) : ((cX * fX) / 100);
} }
void drawBackDrop() { void drawBackDrop() {
@ -624,7 +619,8 @@ void drawBackDrop() {
bool loadLightMap(int v) { bool loadLightMap(int v) {
setResourceForFatal(v); setResourceForFatal(v);
if (!openFileFromNum(v)) return fatal("Can't open light map."); if (!openFileFromNum(v))
return fatal("Can't open light map.");
killLightMap(); killLightMap();
lightMapNumber = v; lightMapNumber = v;
@ -714,10 +710,12 @@ void reloadParallaxTextures() {
bool loadParallax(unsigned short v, unsigned short fracX, unsigned short fracY) { bool loadParallax(unsigned short v, unsigned short fracX, unsigned short fracY) {
setResourceForFatal(v); setResourceForFatal(v);
if (!openFileFromNum(v)) return fatal("Can't open parallax image"); if (!openFileFromNum(v))
return fatal("Can't open parallax image");
parallaxLayer *nP = new parallaxLayer; parallaxLayer *nP = new parallaxLayer;
if (!checkNew(nP)) return false; if (!checkNew(nP))
return false;
nP->next = parallaxStuff; nP->next = parallaxStuff;
parallaxStuff = nP; parallaxStuff = nP;
@ -924,15 +922,15 @@ bool loadHSI(Common::SeekableReadStream *stream, int x, int y, bool reserve) {
int realPicHeight = backdropSurface.h; int realPicHeight = backdropSurface.h;
if (reserve) { // resize backdrop if (reserve) { // resize backdrop
if (!resizeBackdrop(realPicWidth, realPicHeight)) return false; if (!resizeBackdrop(realPicWidth, realPicHeight))
return false;
} }
if (x == IN_THE_CENTRE) if (x == IN_THE_CENTRE)
x = (sceneWidth - realPicWidth) >> 1; x = (sceneWidth - realPicWidth) >> 1;
if (y == IN_THE_CENTRE) if (y == IN_THE_CENTRE)
y = (sceneHeight - realPicHeight) >> 1; y = (sceneHeight - realPicHeight) >> 1;
if (x < 0 || x + realPicWidth > sceneWidth || y < 0 if (x < 0 || x + realPicWidth > sceneWidth || y < 0 || y + realPicHeight > sceneHeight) {
|| y + realPicHeight > sceneHeight) {
debug(kSludgeDebugGraphics, "Illegal back drop size"); debug(kSludgeDebugGraphics, "Illegal back drop size");
return false; return false;
} }
@ -957,9 +955,12 @@ bool mixHSI(Common::SeekableReadStream *stream, int x, int y) {
int realPicWidth = backdropSurface.w; int realPicWidth = backdropSurface.w;
int realPicHeight = backdropSurface.h; int realPicHeight = backdropSurface.h;
if (x == IN_THE_CENTRE) x = (sceneWidth - realPicWidth) >> 1; if (x == IN_THE_CENTRE)
if (y == IN_THE_CENTRE) y = (sceneHeight - realPicHeight) >> 1; x = (sceneWidth - realPicWidth) >> 1;
if (x < 0 || x + realPicWidth > sceneWidth || y < 0 || y + realPicHeight > sceneHeight) return false; if (y == IN_THE_CENTRE)
y = (sceneHeight - realPicHeight) >> 1;
if (x < 0 || x + realPicWidth > sceneWidth || y < 0 || y + realPicHeight > sceneHeight)
return false;
#if 0 #if 0
float btx1, tx1; float btx1, tx1;
float btx2, tx2; float btx2, tx2;
@ -1160,27 +1161,22 @@ void saveCorePNG(Common::WriteStream *stream, GLuint texture, int w, int h) {
#endif #endif
} }
#endif #endif
#if 0 #if 0
void saveCoreHSI(Common::WriteStream *stream, GLuint texture, int w, int h) { void saveCoreHSI(Common::WriteStream *stream, GLuint texture, int w, int h) {
GLint tw, th; GLint tw, th;
glBindTexture(GL_TEXTURE_2D, texture); glBindTexture(GL_TEXTURE_2D, texture);
getTextureDimensions(texture, &tw, &th); getTextureDimensions(texture, &tw, &th);
GLushort *image = new GLushort [tw * th]; GLushort *image = new GLushort[tw * th];
if (!checkNew(image)) return; if (!checkNew(image))
return;
glPixelStorei(GL_PACK_ALIGNMENT, 1); glPixelStorei(GL_PACK_ALIGNMENT, 1);
// glGetTexImage(GL_TEXTURE_2D, 0, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, image); // glGetTexImage(GL_TEXTURE_2D, 0, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, image);
setPixelCoords(true); setPixelCoords(true);
//glTexEnvf (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); //glTexEnvf (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
const GLfloat texCoords[] = { const GLfloat texCoords[] = { 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f, 1.0f, 1.0f };
0.0f, 0.0f,
1.0f, 0.0f,
0.0f, 1.0f,
1.0f, 1.0f
};
int xoffset = 0; int xoffset = 0;
while (xoffset < tw) { while (xoffset < tw) {
@ -1189,13 +1185,9 @@ void saveCoreHSI(Common::WriteStream *stream, GLuint texture, int w, int h) {
int yoffset = 0; int yoffset = 0;
while (yoffset < th) { while (yoffset < th) {
int h = (th - yoffset < viewportHeight) ? th - yoffset : viewportHeight; int h = (th - yoffset < viewportHeight) ? th - yoffset : viewportHeight;
glClear(GL_COLOR_BUFFER_BIT); // Clear The Screen glClear (GL_COLOR_BUFFER_BIT); // Clear The Screen
const GLfloat vertices[] = { const GLfloat vertices[] = { (GLfloat)-xoffset, (GLfloat)-yoffset, 0., (GLfloat)w - xoffset, (GLfloat)-yoffset, 0., (GLfloat)-xoffset, (GLfloat)-yoffset + h, 0., (GLfloat)w - xoffset,
(GLfloat) - xoffset, (GLfloat) - yoffset, 0., (GLfloat)-yoffset + h, 0. };
(GLfloat)w - xoffset, (GLfloat) - yoffset, 0.,
(GLfloat) - xoffset, (GLfloat) - yoffset + h, 0.,
(GLfloat)w - xoffset, (GLfloat) - yoffset + h, 0.
};
glUseProgram(shader.texture); glUseProgram(shader.texture);
setPMVMatrix(shader.texture); setPMVMatrix(shader.texture);
@ -1203,7 +1195,7 @@ void saveCoreHSI(Common::WriteStream *stream, GLuint texture, int w, int h) {
glUseProgram(0); glUseProgram(0);
for (int i = 0; i < h; i++) { for (int i = 0; i < h; i++) {
glReadPixels(viewportOffsetX, viewportOffsetY + i, w, 1, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, image + xoffset + (yoffset + i)*tw); glReadPixels(viewportOffsetX, viewportOffsetY + i, w, 1, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, image + xoffset + (yoffset + i) * tw);
} }
yoffset += viewportHeight; yoffset += viewportHeight;
} }
@ -1214,32 +1206,34 @@ void saveCoreHSI(Common::WriteStream *stream, GLuint texture, int w, int h) {
setPixelCoords(false); setPixelCoords(false);
int x, y, lookAhead; int x, y, lookAhead;
unsigned short int *fromHere, * lookPointer; unsigned short int *fromHere, *lookPointer;
stream->writeUint16BE(w); stream->writeUint16BE(w);
stream->writeUint16BE(h); stream->writeUint16BE(h);
for (y = 0; y < h; y ++) { for (y = 0; y < h; y++) {
fromHere = image + (y * tw); fromHere = image + (y * tw);
x = 0; x = 0;
while (x < w) { while (x < w) {
lookPointer = fromHere + 1; lookPointer = fromHere + 1;
for (lookAhead = x + 1; lookAhead < w; lookAhead ++) { for (lookAhead = x + 1; lookAhead < w; lookAhead++) {
if (lookAhead - x == 256) break; if (lookAhead - x == 256)
if (* fromHere != * lookPointer) break; break;
lookPointer ++; if (*fromHere != *lookPointer)
break;
lookPointer++;
} }
if (lookAhead == x + 1) { if (lookAhead == x + 1) {
put2bytes((* fromHere) & 65503, stream); put2bytes((*fromHere) & 65503, stream);
} else { } else {
stream->writeUint16BE(* fromHere | 32); stream->writeUint16BE(*fromHere | 32);
stream->writeByte(lookAhead - x - 1); stream->writeByte(lookAhead - x - 1);
} }
fromHere = lookPointer; fromHere = lookPointer;
x = lookAhead; x = lookAhead;
} }
} }
delete [] image; delete[] image;
image = NULL; image = NULL;
} }
#endif #endif

View File

@ -64,14 +64,14 @@ static int s_matrixEffectBase = 15;
static int s_matrixEffectDivide = 4; static int s_matrixEffectDivide = 4;
static int s_matrixEffectWidth = 3; static int s_matrixEffectWidth = 3;
static int s_matrixEffectHeight = 3; static int s_matrixEffectHeight = 3;
static int s_matrixEffectData[9] = { -2, -1, 0, -1, 1, 1, 0, 1, 2}; static int s_matrixEffectData[9] = {-2, -1, 0, -1, 1, 1, 0, 1, 2};
static int s_matrixEffectBase = 16; static int s_matrixEffectBase = 16;
#elif 0 #elif 0
// Standard emboss // Standard emboss
static int s_matrixEffectDivide = 2; static int s_matrixEffectDivide = 2;
static int s_matrixEffectWidth = 3; static int s_matrixEffectWidth = 3;
static int s_matrixEffectHeight = 3; static int s_matrixEffectHeight = 3;
static int s_matrixEffectData[9] = { -1, 0, 0, 0, 0, 0, 0, 0, 1}; static int s_matrixEffectData[9] = {-1, 0, 0, 0, 0, 0, 0, 0, 1};
static int s_matrixEffectBase = 128; static int s_matrixEffectBase = 128;
#elif 0 #elif 0
// Horizontal blur // Horizontal blur
@ -92,7 +92,7 @@ static int s_matrixEffectBase = 0;
static int s_matrixEffectDivide = 1; static int s_matrixEffectDivide = 1;
static int s_matrixEffectWidth = 1; static int s_matrixEffectWidth = 1;
static int s_matrixEffectHeight = 1; static int s_matrixEffectHeight = 1;
static int s_matrixEffectData[9] = { -1}; static int s_matrixEffectData[9] = {-1};
static int s_matrixEffectBase = 255; static int s_matrixEffectBase = 255;
#elif 0 #elif 0
// Fog // Fog
@ -136,7 +136,7 @@ static int *blur_allocateMemoryForEffect() {
s_matrixEffectData = NULL; s_matrixEffectData = NULL;
if (s_matrixEffectWidth && s_matrixEffectHeight) { if (s_matrixEffectWidth && s_matrixEffectHeight) {
s_matrixEffectData = (int *) malloc(sizeof(int) * s_matrixEffectHeight * s_matrixEffectWidth); s_matrixEffectData = (int *)malloc(sizeof(int) * s_matrixEffectHeight * s_matrixEffectWidth);
checkNew(s_matrixEffectData); checkNew(s_matrixEffectData);
} }
return s_matrixEffectData; return s_matrixEffectData;
@ -169,7 +169,7 @@ bool blur_createSettings(int numParams, variableStack *&stack) {
int width = 0; int width = 0;
variableStack *justToCheckSizes = stack; variableStack *justToCheckSizes = stack;
for (int a = 0; a < height; a ++) { for (int a = 0; a < height; a++) {
if (justToCheckSizes->thisVar.varType != SVT_STACK) { if (justToCheckSizes->thisVar.varType != SVT_STACK) {
error = "Third and subsequent parameters in setBackgroundEffect should be arrays"; error = "Third and subsequent parameters in setBackgroundEffect should be arrays";
break; break;
@ -189,19 +189,19 @@ bool blur_createSettings(int numParams, variableStack *&stack) {
} }
} }
if (width == 0 && ! error) { if (width == 0 && !error) {
error = "Empty arrays found in setBackgroundEffect parameters"; error = "Empty arrays found in setBackgroundEffect parameters";
} }
if (! error) { if (!error) {
s_matrixEffectWidth = width; s_matrixEffectWidth = width;
s_matrixEffectHeight = height; s_matrixEffectHeight = height;
if (blur_allocateMemoryForEffect()) { if (blur_allocateMemoryForEffect()) {
for (int y = height - 1; y >= 0; y --) { for (int y = height - 1; y >= 0; y--) {
variableStack *eachNumber = stack->thisVar.varData.theStack->first; variableStack *eachNumber = stack->thisVar.varData.theStack->first;
if (! error) { if (!error) {
for (int x = 0; x < width; x ++) { for (int x = 0; x < width; x++) {
int arraySlot = x + (y * width); int arraySlot = x + (y * width);
// s_matrixEffectData[arraySlot] = (rand() % 4); // s_matrixEffectData[arraySlot] = (rand() % 4);
if (!getValueType(s_matrixEffectData[arraySlot], SVT_INT, eachNumber->thisVar)) { if (!getValueType(s_matrixEffectData[arraySlot], SVT_INT, eachNumber->thisVar)) {
@ -213,13 +213,13 @@ bool blur_createSettings(int numParams, variableStack *&stack) {
trimStack(stack); trimStack(stack);
} }
} }
if (! error && !getValueType(s_matrixEffectDivide, SVT_INT, stack -> thisVar)) if (!error && !getValueType(s_matrixEffectDivide, SVT_INT, stack->thisVar))
error = ""; error = "";
trimStack(stack); trimStack(stack);
if (! error && !getValueType(s_matrixEffectBase, SVT_INT, stack -> thisVar)) if (!error && !getValueType(s_matrixEffectBase, SVT_INT, stack->thisVar))
error = ""; error = "";
trimStack(stack); trimStack(stack);
if (! error) { if (!error) {
if (s_matrixEffectDivide) { if (s_matrixEffectDivide) {
createNullThing = false; createNullThing = false;
} else { } else {
@ -249,7 +249,7 @@ bool blur_createSettings(int numParams, variableStack *&stack) {
fatal(error); fatal(error);
} }
return ! createNullThing; return !createNullThing;
} }
static inline int clampi(int i, int min, int max) { static inline int clampi(int i, int min, int max) {
@ -260,13 +260,13 @@ static inline void blur_createSourceLine(unsigned char *createLine, unsigned cha
int miniX; int miniX;
memcpy(createLine + overlapOnLeft * 4, fromLine, width * 4); memcpy(createLine + overlapOnLeft * 4, fromLine, width * 4);
for (miniX = 0; miniX < overlapOnLeft; miniX ++) { for (miniX = 0; miniX < overlapOnLeft; miniX++) {
createLine[miniX * 4] = fromLine[0]; createLine[miniX * 4] = fromLine[0];
createLine[miniX * 4 + 1] = fromLine[1]; createLine[miniX * 4 + 1] = fromLine[1];
createLine[miniX * 4 + 2] = fromLine[2]; createLine[miniX * 4 + 2] = fromLine[2];
} }
for (miniX = width + overlapOnLeft; miniX < width + s_matrixEffectWidth - 1; miniX ++) { for (miniX = width + overlapOnLeft; miniX < width + s_matrixEffectWidth - 1; miniX++) {
createLine[miniX * 4] = fromLine[width * 4 - 4]; createLine[miniX * 4] = fromLine[width * 4 - 4];
createLine[miniX * 4 + 1] = fromLine[width * 4 - 3]; createLine[miniX * 4 + 1] = fromLine[width * 4 - 3];
createLine[miniX * 4 + 2] = fromLine[width * 4 - 2]; createLine[miniX * 4 + 2] = fromLine[width * 4 - 2];
@ -280,15 +280,16 @@ bool blurScreen() {
int y, x; int y, x;
bool ok = true; bool ok = true;
int overlapOnLeft = s_matrixEffectWidth / 2; int overlapOnLeft = s_matrixEffectWidth / 2;
int overlapAbove = s_matrixEffectHeight / 2; int overlapAbove = s_matrixEffectHeight / 2;
unsigned char **sourceLine = new unsigned char *[s_matrixEffectHeight]; unsigned char **sourceLine = new unsigned char *[s_matrixEffectHeight];
if (! checkNew(sourceLine)) return false; if (!checkNew(sourceLine))
return false;
int picWidth = sceneWidth; int picWidth = sceneWidth;
int picHeight = sceneHeight; int picHeight = sceneHeight;
if (! NPOT_textures) { if (!NPOT_textures) {
picWidth = getNextPOT(sceneWidth); picWidth = getNextPOT(sceneWidth);
picHeight = getNextPOT(sceneHeight); picHeight = getNextPOT(sceneHeight);
} }
@ -296,26 +297,26 @@ bool blurScreen() {
// Retrieve the texture // Retrieve the texture
saveTexture(backdropTextureName, backdropTexture); saveTexture(backdropTextureName, backdropTexture);
for (y = 0; y < s_matrixEffectHeight; y ++) { for (y = 0; y < s_matrixEffectHeight; y++) {
sourceLine[y] = new unsigned char[(s_matrixEffectWidth - 1 + picWidth) * 4]; sourceLine[y] = new unsigned char[(s_matrixEffectWidth - 1 + picWidth) * 4];
ok &= (sourceLine[y] != NULL); ok &= (sourceLine[y] != NULL);
} }
if (ok) { if (ok) {
for (y = 0; y < s_matrixEffectHeight; y ++) { for (y = 0; y < s_matrixEffectHeight; y++) {
int miniY = clampi(y - overlapAbove - 1, 0, sceneHeight - 1); int miniY = clampi(y - overlapAbove - 1, 0, sceneHeight - 1);
blur_createSourceLine(sourceLine[y], backdropTexture + miniY * picWidth * 4, overlapOnLeft, picWidth); blur_createSourceLine(sourceLine[y], backdropTexture + miniY * picWidth * 4, overlapOnLeft, picWidth);
} }
for (y = 0; y < sceneHeight; y ++) { for (y = 0; y < sceneHeight; y++) {
thisLine = backdropTexture + y * picWidth * 4; thisLine = backdropTexture + y * picWidth * 4;
//------------------------- //-------------------------
// Scroll source lines // Scroll source lines
//------------------------- //-------------------------
unsigned char *tempLine = sourceLine[0]; unsigned char *tempLine = sourceLine[0];
for (int miniY = 0; miniY < s_matrixEffectHeight - 1; miniY ++) { for (int miniY = 0; miniY < s_matrixEffectHeight - 1; miniY++) {
sourceLine[miniY] = sourceLine[miniY + 1]; sourceLine[miniY] = sourceLine[miniY + 1];
} }
sourceLine[s_matrixEffectHeight - 1] = tempLine; sourceLine[s_matrixEffectHeight - 1] = tempLine;
@ -325,19 +326,19 @@ bool blurScreen() {
blur_createSourceLine(sourceLine[h], backdropTexture + miniY * picWidth * 4, overlapOnLeft, picWidth); blur_createSourceLine(sourceLine[h], backdropTexture + miniY * picWidth * 4, overlapOnLeft, picWidth);
} }
for (x = 0; x < sceneWidth; x ++) { for (x = 0; x < sceneWidth; x++) {
int totalRed = 0; int totalRed = 0;
int totalGreen = 0; int totalGreen = 0;
int totalBlue = 0; int totalBlue = 0;
int *matrixElement = s_matrixEffectData; int *matrixElement = s_matrixEffectData;
for (int miniY = 0; miniY < s_matrixEffectHeight; ++ miniY) { for (int miniY = 0; miniY < s_matrixEffectHeight; ++miniY) {
unsigned char *pixel = & sourceLine[miniY][x * 4]; unsigned char *pixel = &sourceLine[miniY][x * 4];
for (int miniX = 0; miniX < s_matrixEffectWidth; ++ miniX) { for (int miniX = 0; miniX < s_matrixEffectWidth; ++miniX) {
totalRed += pixel[0] * * matrixElement; totalRed += pixel[0] * *matrixElement;
totalGreen += pixel[1] * * matrixElement; totalGreen += pixel[1] * *matrixElement;
totalBlue += pixel[2] * * matrixElement; totalBlue += pixel[2] * *matrixElement;
++ matrixElement; ++matrixElement;
pixel += 4; pixel += 4;
} }
} }
@ -350,19 +351,19 @@ bool blurScreen() {
totalBlue = (totalBlue + s_matrixEffectDivide / 2) / s_matrixEffectDivide + s_matrixEffectBase; totalBlue = (totalBlue + s_matrixEffectDivide / 2) / s_matrixEffectDivide + s_matrixEffectBase;
totalBlue = (totalBlue < 0) ? 0 : ((totalBlue > 255) ? 255 : totalBlue); totalBlue = (totalBlue < 0) ? 0 : ((totalBlue > 255) ? 255 : totalBlue);
* thisLine = totalRed; *thisLine = totalRed;
++ thisLine; ++thisLine;
* thisLine = totalGreen; *thisLine = totalGreen;
++ thisLine; ++thisLine;
* thisLine = totalBlue; *thisLine = totalBlue;
++ thisLine; ++thisLine;
// * thisLine = totalAlpha; // *thisLine = totalAlpha;
++ thisLine; ++thisLine;
} }
} }
} }
for (y = 0; y < s_matrixEffectHeight; y ++) { for (y = 0; y < s_matrixEffectHeight; y++) {
delete sourceLine[y]; delete sourceLine[y];
} }
delete sourceLine; delete sourceLine;

File diff suppressed because it is too large Load Diff

View File

@ -56,9 +56,9 @@ namespace Sludge {
#define ERROR_MUSIC_MEMORY_LOW "Your computer doesn't have enough memory available to load a music resource that needs playing." _NO_MEMORY_GENERAL_ #define ERROR_MUSIC_MEMORY_LOW "Your computer doesn't have enough memory available to load a music resource that needs playing." _NO_MEMORY_GENERAL_
#define ERROR_SOUND_MEMORY_LOW "Your computer doesn't have enough memory available to load a sound resource that needs playing." _NO_MEMORY_GENERAL_ #define ERROR_SOUND_MEMORY_LOW "Your computer doesn't have enough memory available to load a sound resource that needs playing." _NO_MEMORY_GENERAL_
#define ERROR_MUSIC_UNKNOWN "I can't understand a piece of music which I've been told to play!\n\n" \ #define ERROR_MUSIC_UNKNOWN "I can't understand a piece of music which I've been told to play!\n\n" \
"Maybe it's stored in a format that SLUDGE doesn't know about... " \ "Maybe it's stored in a format that SLUDGE doesn't know about... " \
"make sure you've got a recent version of the SLUDGE engine from http://opensludge.github.io/. " \ "make sure you've got a recent version of the SLUDGE engine from http://opensludge.github.io/. " \
"Failing that, maybe the resource in question isn't a valid music format at all... in which case, contact the game's author and tell them what's happened." "Failing that, maybe the resource in question isn't a valid music format at all... in which case, contact the game's author and tell them what's happened."
#define ERROR_SOUND_UNKNOWN "I can't understand a sample which I've been told to play!\nMake sure you've got the latest SLUDGE engine from http://opensludge.github.io/. Failing that, maybe the resource in question isn't a valid sound at all... in which case, contact the game's author and tell them what's happened." #define ERROR_SOUND_UNKNOWN "I can't understand a sample which I've been told to play!\nMake sure you've got the latest SLUDGE engine from http://opensludge.github.io/. Failing that, maybe the resource in question isn't a valid sound at all... in which case, contact the game's author and tell them what's happened."
#define ERROR_MUSIC_ODDNESS "I can't load a music resource I've been told to play. Sorry." #define ERROR_MUSIC_ODDNESS "I can't load a music resource I've been told to play. Sorry."
#define ERROR_SOUND_ODDNESS "I can't load a sound resource I've been told to play. Sorry." #define ERROR_SOUND_ODDNESS "I can't load a sound resource I've been told to play. Sorry."

View File

@ -44,8 +44,7 @@ bool sliceBusy = true;
Common::File *bigDataFile = NULL; Common::File *bigDataFile = NULL;
uint32_t startOfDataIndex, startOfTextIndex, startOfSubIndex, uint32_t startOfDataIndex, startOfTextIndex, startOfSubIndex, startOfObjectIndex;
startOfObjectIndex;
bool openSubSlice(int num) { bool openSubSlice(int num) {
// FILE * dbug = fopen ("debuggy.txt", "at"); // FILE * dbug = fopen ("debuggy.txt", "at");
@ -199,8 +198,7 @@ void finishAccess() {
int32_t startIndex; int32_t startIndex;
void setFileIndices(Common::File *fp, int numLanguages, void setFileIndices(Common::File *fp, int numLanguages, unsigned int skipBefore) {
unsigned int skipBefore) {
if (fp) { if (fp) {
// Keep hold of the file handle, and let things get at it // Keep hold of the file handle, and let things get at it
bigDataFile = fp; bigDataFile = fp;

View File

@ -42,17 +42,14 @@ bool pointInFloorPolygon(floorPolygon &floorPoly, int x, int y) {
xp_j = currentFloor->vertex[floorPoly.vertexID[j]].x; xp_j = currentFloor->vertex[floorPoly.vertexID[j]].x;
yp_j = currentFloor->vertex[floorPoly.vertexID[j]].y; yp_j = currentFloor->vertex[floorPoly.vertexID[j]].y;
if ((((yp_i <= y) && (y < yp_j)) || ((yp_j <= y) && (y < yp_i))) if ((((yp_i <= y) && (y < yp_j)) || ((yp_j <= y) && (y < yp_i))) && (x < (xp_j - xp_i) * (y - yp_i) / (yp_j - yp_i) + xp_i)) {
&& (x < (xp_j - xp_i) * (y - yp_i) / (yp_j - yp_i) + xp_i)) {
c = !c; c = !c;
} }
} }
return c; return c;
} }
bool getMatchingCorners(floorPolygon &a, floorPolygon &b, int &cornerA, bool getMatchingCorners(floorPolygon &a, floorPolygon &b, int &cornerA, int &cornerB) {
int &cornerB) {
int sharedVertices = 0; int sharedVertices = 0;
int i, j; int i, j;
@ -147,8 +144,7 @@ bool setFloor(int fileNum) {
// Find out how many vertex IDs there are and reserve memory // Find out how many vertex IDs there are and reserve memory
currentFloor->polygon[i].numVertices = bigDataFile->readByte(); currentFloor->polygon[i].numVertices = bigDataFile->readByte();
currentFloor->polygon[i].vertexID = currentFloor->polygon[i].vertexID = new int[currentFloor->polygon[i].numVertices];
new int[currentFloor->polygon[i].numVertices];
if (!checkNew(currentFloor->polygon[i].vertexID)) if (!checkNew(currentFloor->polygon[i].vertexID))
return false; return false;
@ -196,8 +192,7 @@ bool setFloor(int fileNum) {
for (i = 0; i < currentFloor->numPolygons; i++) { for (i = 0; i < currentFloor->numPolygons; i++) {
for (j = 0; j < currentFloor->numPolygons; j++) { for (j = 0; j < currentFloor->numPolygons; j++) {
if (i != j) { if (i != j) {
if (polysShareSide(currentFloor->polygon[i], if (polysShareSide(currentFloor->polygon[i], currentFloor->polygon[j])) {
currentFloor->polygon[j])) {
currentFloor->matrix[i][j] = j; currentFloor->matrix[i][j] = j;
distanceMatrix[i][j] = 1; distanceMatrix[i][j] = 1;
} }
@ -222,11 +217,7 @@ bool setFloor(int fileNum) {
// OK, so we don't know how to get from i to j... // OK, so we don't know how to get from i to j...
for (int d = 0; d < currentFloor->numPolygons; d++) { for (int d = 0; d < currentFloor->numPolygons; d++) {
if (d != i && d != j) { if (d != i && d != j) {
if (currentFloor->matrix[i][d] == d if (currentFloor->matrix[i][d] == d && currentFloor->matrix[d][j] >= 0 && distanceMatrix[d][j] <= lookForDistance) {
&& currentFloor->matrix[d][j] >= 0
&& distanceMatrix[d][j]
<= lookForDistance) {
currentFloor->matrix[i][j] = d; currentFloor->matrix[i][j] = d;
distanceMatrix[i][j] = lookForDistance + 1; distanceMatrix[i][j] = lookForDistance + 1;
madeChange = true; madeChange = true;
@ -257,21 +248,11 @@ void drawFloor() {
nV = currentFloor->polygon[i].numVertices; nV = currentFloor->polygon[i].numVertices;
if (nV > 1) { if (nV > 1) {
for (j = 1; j < nV; j++) { for (j = 1; j < nV; j++) {
drawLine( drawLine(currentFloor->vertex[currentFloor->polygon[i].vertexID[j - 1]].x, currentFloor->vertex[currentFloor->polygon[i].vertexID[j - 1]].y,
currentFloor->vertex[currentFloor->polygon[i].vertexID[j currentFloor->vertex[currentFloor->polygon[i].vertexID[j]].x, currentFloor->vertex[currentFloor->polygon[i].vertexID[j]].y);
- 1]].x,
currentFloor->vertex[currentFloor->polygon[i].vertexID[j
- 1]].y,
currentFloor->vertex[currentFloor->polygon[i].vertexID[j]].x,
currentFloor->vertex[currentFloor->polygon[i].vertexID[j]].y);
} }
drawLine( drawLine(currentFloor->vertex[currentFloor->polygon[i].vertexID[0]].x, currentFloor->vertex[currentFloor->polygon[i].vertexID[0]].y,
currentFloor->vertex[currentFloor->polygon[i].vertexID[0]].x, currentFloor->vertex[currentFloor->polygon[i].vertexID[nV - 1]].x, currentFloor->vertex[currentFloor->polygon[i].vertexID[nV - 1]].y);
currentFloor->vertex[currentFloor->polygon[i].vertexID[0]].y,
currentFloor->vertex[currentFloor->polygon[i].vertexID[nV
- 1]].x,
currentFloor->vertex[currentFloor->polygon[i].vertexID[nV
- 1]].y);
} }
} }
} }
@ -286,8 +267,7 @@ int inFloor(int x, int y) {
return r; return r;
} }
bool closestPointOnLine(int &closestX, int &closestY, int x1, int y1, int x2, bool closestPointOnLine(int &closestX, int &closestY, int x1, int y1, int x2, int y2, int xP, int yP) {
int y2, int xP, int yP) {
int xDiff = x2 - x1; int xDiff = x2 - x1;
int yDiff = y2 - y1; int yDiff = y2 - y1;

View File

@ -54,8 +54,7 @@ bool setFloor(int fileNum);
void drawFloor(); void drawFloor();
int inFloor(int x, int y); int inFloor(int x, int y);
bool getMatchingCorners(floorPolygon &, floorPolygon &, int &, int &); bool getMatchingCorners(floorPolygon &, floorPolygon &, int &, int &);
bool closestPointOnLine(int &closestX, int &closestY, int x1, int y1, int x2, bool closestPointOnLine(int &closestX, int &closestY, int x1, int y1, int x2, int y2, int xP, int yP);
int y2, int xP, int yP);
} // End of namespace Sludge } // End of namespace Sludge

View File

@ -94,17 +94,16 @@ void pasteString(char *theText, int xOff, int y, spritePalette &thePal) {
if (!fontTableSize) if (!fontTableSize)
return; return;
xOff += (int) ((float) (fontSpace >> 1) / cameraZoom); xOff += (int)((float)(fontSpace >> 1) / cameraZoom);
while (theText[a]) { while (theText[a]) {
c = u8_nextchar(theText, &a); c = u8_nextchar(theText, &a);
mySprite = &theFont.sprites[fontInTable(c)]; mySprite = &theFont.sprites[fontInTable(c)];
fontSprite(xOff, y, *mySprite, thePal); fontSprite(xOff, y, *mySprite, thePal);
xOff += (int) ((double) (mySprite->surface.w + fontSpace) / cameraZoom); xOff += (int)((double)(mySprite->surface.w + fontSpace) / cameraZoom);
} }
} }
void pasteStringToBackdrop(char *theText, int xOff, int y, void pasteStringToBackdrop(char *theText, int xOff, int y, spritePalette &thePal) {
spritePalette &thePal) {
sprite *mySprite; sprite *mySprite;
int a = 0; int a = 0;
uint32_t c; uint32_t c;
@ -121,8 +120,7 @@ void pasteStringToBackdrop(char *theText, int xOff, int y,
} }
} }
void burnStringToBackdrop(char *theText, int xOff, int y, void burnStringToBackdrop(char *theText, int xOff, int y, spritePalette &thePal) {
spritePalette &thePal) {
sprite *mySprite; sprite *mySprite;
int a = 0; int a = 0;
uint32_t c; uint32_t c;

View File

@ -156,7 +156,7 @@ bool freeze() {
// Grab a copy of the current scene // Grab a copy of the current scene
freezeGraphics(); freezeGraphics();
#if 0 #if 0
newFreezer -> backdropTextureName = backdropTextureName; newFreezer->backdropTextureName = backdropTextureName;
#endif #endif
int picWidth = sceneWidth; int picWidth = sceneWidth;
int picHeight = sceneHeight; int picHeight = sceneHeight;
@ -165,8 +165,9 @@ bool freeze() {
picHeight = getNextPOT(picHeight); picHeight = getNextPOT(picHeight);
} }
#if 0 #if 0
newFreezer -> backdropTexture = new GLubyte [picHeight * picWidth * 4]; newFreezer->backdropTexture = new GLubyte[picHeight * picWidth * 4];
if (! checkNew(newFreezer -> backdropTexture)) return false; if (!checkNew(newFreezer->backdropTexture))
return false;
saveTexture(backdropTextureName, newFreezer->backdropTexture); saveTexture(backdropTextureName, newFreezer->backdropTexture);
@ -178,16 +179,16 @@ bool freeze() {
newFreezer->cameraY = cameraY; newFreezer->cameraY = cameraY;
newFreezer->cameraZoom = cameraZoom; newFreezer->cameraZoom = cameraZoom;
#if 0 #if 0
newFreezer -> lightMapTexture = lightMap.data; newFreezer->lightMapTexture = lightMap.data;
newFreezer -> lightMapTextureName = lightMap.name; newFreezer->lightMapTextureName = lightMap.name;
newFreezer -> lightMapNumber = lightMapNumber; newFreezer->lightMapNumber = lightMapNumber;
lightMap.data = NULL; lightMap.data = NULL;
lightMap.name = 0; lightMap.name = 0;
newFreezer -> parallaxStuff = parallaxStuff; newFreezer->parallaxStuff = parallaxStuff;
parallaxStuff = NULL; parallaxStuff = NULL;
newFreezer -> zBufferImage = zBuffer.tex; newFreezer->zBufferImage = zBuffer.tex;
newFreezer -> zBufferNumber = zBuffer.originalNum; newFreezer->zBufferNumber = zBuffer.originalNum;
newFreezer -> zPanels = zBuffer.numPanels; newFreezer->zPanels = zBuffer.numPanels;
zBuffer.tex = NULL; zBuffer.tex = NULL;
#endif #endif
// resizeBackdrop kills parallax stuff, light map, z-buffer... // resizeBackdrop kills parallax stuff, light map, z-buffer...
@ -198,8 +199,8 @@ bool freeze() {
picWidth = getNextPOT(sceneWidth); picWidth = getNextPOT(sceneWidth);
picHeight = getNextPOT(sceneHeight); picHeight = getNextPOT(sceneHeight);
#if 0 #if 0
backdropTexW = (double) sceneWidth / picWidth; backdropTexW = (double)sceneWidth / picWidth;
backdropTexH = (double) sceneHeight / picHeight; backdropTexH = (double)sceneHeight / picHeight;
#endif #endif
} }
@ -210,19 +211,19 @@ bool freeze() {
backdropExists = true; backdropExists = true;
// Free texture memory used by old stuff // Free texture memory used by old stuff
parallaxStuff = newFreezer -> parallaxStuff; parallaxStuff = newFreezer->parallaxStuff;
while (parallaxStuff) { while (parallaxStuff) {
deleteTextures(1, &parallaxStuff -> textureName); deleteTextures(1, &parallaxStuff->textureName);
parallaxStuff = parallaxStuff -> next; parallaxStuff = parallaxStuff->next;
} }
if (newFreezer -> zBufferImage) { if (newFreezer->zBufferImage) {
deleteTextures(1, &zBuffer.texName); deleteTextures(1, &zBuffer.texName);
} }
if (newFreezer -> lightMapTextureName) { if (newFreezer->lightMapTextureName) {
deleteTextures(1, &newFreezer -> lightMapTextureName); deleteTextures(1, &newFreezer->lightMapTextureName);
} }
if (newFreezer -> backdropTextureName) { if (newFreezer->backdropTextureName) {
deleteTextures(1, &newFreezer -> backdropTextureName); deleteTextures(1, &newFreezer->backdropTextureName);
} }
#endif #endif
newFreezer->allPeople = allPeople; newFreezer->allPeople = allPeople;
@ -282,11 +283,11 @@ void unfreeze(bool killImage) {
cameraX = frozenStuff->cameraX; cameraX = frozenStuff->cameraX;
cameraY = frozenStuff->cameraY; cameraY = frozenStuff->cameraY;
input.mouseX = (int) (input.mouseX * cameraZoom); input.mouseX = (int)(input.mouseX * cameraZoom);
input.mouseY = (int) (input.mouseY * cameraZoom); input.mouseY = (int)(input.mouseY * cameraZoom);
cameraZoom = frozenStuff->cameraZoom; cameraZoom = frozenStuff->cameraZoom;
input.mouseX = (int) (input.mouseX / cameraZoom); input.mouseX = (int)(input.mouseX / cameraZoom);
input.mouseY = (int) (input.mouseY / cameraZoom); input.mouseY = (int)(input.mouseY / cameraZoom);
setPixelCoords(false); setPixelCoords(false);
killAllPeople(); killAllPeople();
@ -297,31 +298,33 @@ void unfreeze(bool killImage) {
killLightMap(); killLightMap();
#if 0 #if 0
lightMap.data = frozenStuff -> lightMapTexture; lightMap.data = frozenStuff->lightMapTexture;
lightMap.name = frozenStuff -> lightMapTextureName; lightMap.name = frozenStuff->lightMapTextureName;
lightMapNumber = frozenStuff -> lightMapNumber; lightMapNumber = frozenStuff->lightMapNumber;
if (lightMapNumber) { if (lightMapNumber) {
lightMap.name = 0; lightMap.name = 0;
loadLightMap(lightMapNumber); loadLightMap(lightMapNumber);
} }
killZBuffer(); killZBuffer();
zBuffer.tex = frozenStuff -> zBufferImage; zBuffer.tex = frozenStuff->zBufferImage;
zBuffer.originalNum = frozenStuff -> zBufferNumber; zBuffer.originalNum = frozenStuff->zBufferNumber;
zBuffer.numPanels = frozenStuff -> zPanels; zBuffer.numPanels = frozenStuff->zPanels;
if (zBuffer.numPanels) { if (zBuffer.numPanels) {
zBuffer.texName = 0; zBuffer.texName = 0;
setZBuffer(zBuffer.originalNum); setZBuffer(zBuffer.originalNum);
} }
killParallax(); killParallax();
parallaxStuff = frozenStuff -> parallaxStuff; parallaxStuff = frozenStuff->parallaxStuff;
reloadParallaxTextures(); reloadParallaxTextures();
if (killImage) killBackDrop(); if (killImage)
backdropTextureName = frozenStuff -> backdropTextureName; killBackDrop();
if (backdropTexture) delete[] backdropTexture; backdropTextureName = frozenStuff->backdropTextureName;
backdropTexture = frozenStuff -> backdropTexture; if (backdropTexture)
delete[] backdropTexture;
backdropTexture = frozenStuff->backdropTexture;
backdropExists = true; backdropExists = true;
if (backdropTextureName) { if (backdropTextureName) {
backdropTextureName = 0; backdropTextureName = 0;
@ -340,12 +343,12 @@ void unfreeze(bool killImage) {
int picWidth = sceneWidth; int picWidth = sceneWidth;
int picHeight = sceneHeight; int picHeight = sceneHeight;
if (! NPOT_textures) { if (!NPOT_textures) {
picWidth = getNextPOT(picWidth); picWidth = getNextPOT(picWidth);
picHeight = getNextPOT(picHeight); picHeight = getNextPOT(picHeight);
} }
// Restore the backdrop // Restore the backdrop
texImage2D(GL_TEXTURE_2D, 0, GL_RGBA, picWidth, picHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, frozenStuff -> backdropTexture, backdropTextureName); texImage2D(GL_TEXTURE_2D, 0, GL_RGBA, picWidth, picHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, frozenStuff->backdropTexture, backdropTextureName);
} }
#endif #endif
deleteAnim(mouseCursorAnim); deleteAnim(mouseCursorAnim);

View File

@ -91,8 +91,7 @@ void readIniFile(char *filename) {
Common::File fd; Common::File fd;
if (!fd.open(langName)) { if (!fd.open(langName)) {
debug(kSludgeDebugDataLoad, "Fail to open language file : %s", debug(kSludgeDebugDataLoad, "Fail to open language file : %s", langName);
langName);
return; return;
} }
@ -121,45 +120,45 @@ void readIniFile(char *filename) {
keepGoing = false; keepGoing = false;
} }
switch (readChar) { switch (readChar) {
case '\n': case '\n':
case '\r': case '\r':
if (doingSecond) { if (doingSecond) {
if (strcmp(lineSoFar, "LANGUAGE") == 0) { if (strcmp(lineSoFar, "LANGUAGE") == 0) {
gameSettings.languageID = stringToInt(secondSoFar); gameSettings.languageID = stringToInt(secondSoFar);
} else if (strcmp(lineSoFar, "WINDOW") == 0) { } else if (strcmp(lineSoFar, "WINDOW") == 0) {
gameSettings.userFullScreen = !stringToInt(secondSoFar); gameSettings.userFullScreen = !stringToInt(secondSoFar);
} else if (strcmp(lineSoFar, "REFRESH") == 0) { } else if (strcmp(lineSoFar, "REFRESH") == 0) {
gameSettings.refreshRate = stringToInt(secondSoFar); gameSettings.refreshRate = stringToInt(secondSoFar);
} else if (strcmp(lineSoFar, "ANTIALIAS") == 0) { } else if (strcmp(lineSoFar, "ANTIALIAS") == 0) {
gameSettings.antiAlias = stringToInt(secondSoFar); gameSettings.antiAlias = stringToInt(secondSoFar);
} else if (strcmp(lineSoFar, "FIXEDPIXELS") == 0) { } else if (strcmp(lineSoFar, "FIXEDPIXELS") == 0) {
gameSettings.fixedPixels = stringToInt(secondSoFar); gameSettings.fixedPixels = stringToInt(secondSoFar);
} else if (strcmp(lineSoFar, "NOSTARTWINDOW") == 0) { } else if (strcmp(lineSoFar, "NOSTARTWINDOW") == 0) {
gameSettings.noStartWindow = stringToInt(secondSoFar); gameSettings.noStartWindow = stringToInt(secondSoFar);
} else if (strcmp(lineSoFar, "DEBUGMODE") == 0) { } else if (strcmp(lineSoFar, "DEBUGMODE") == 0) {
gameSettings.debugMode = stringToInt(secondSoFar); gameSettings.debugMode = stringToInt(secondSoFar);
}
} }
} here = 0;
here = 0; doingSecond = false;
doingSecond = false; lineSoFar[0] = 0;
lineSoFar[0] = 0; secondSoFar[0] = 0;
secondSoFar[0] = 0; break;
break;
case '=': case '=':
doingSecond = true; doingSecond = true;
here = 0; here = 0;
break; break;
default: default:
if (doingSecond) { if (doingSecond) {
secondSoFar[here++] = readChar; secondSoFar[here++] = readChar;
secondSoFar[here] = 0; secondSoFar[here] = 0;
} else { } else {
lineSoFar[here++] = readChar; lineSoFar[here++] = readChar;
lineSoFar[here] = 0; lineSoFar[here] = 0;
} }
break; break;
} }
} while (keepGoing); } while (keepGoing);
@ -194,14 +193,12 @@ void makeLanguageTable(Common::File *table) {
for (unsigned int i = 0; i <= gameSettings.numLanguages; i++) { for (unsigned int i = 0; i <= gameSettings.numLanguages; i++) {
languageTable[i] = i ? table->readUint16BE() : 0; languageTable[i] = i ? table->readUint16BE() : 0;
debug(kSludgeDebugDataLoad, "languageTable %i: %i", i, debug(kSludgeDebugDataLoad, "languageTable %i: %i", i, languageTable[i]);
languageTable[i]);
languageName[i] = 0; languageName[i] = 0;
if (gameVersion >= VERSION(2, 0)) { if (gameVersion >= VERSION(2, 0)) {
if (gameSettings.numLanguages) { if (gameSettings.numLanguages) {
languageName[i] = readString(table); languageName[i] = readString(table);
debug(kSludgeDebugDataLoad, "languageName %i: %s\n", i, debug(kSludgeDebugDataLoad, "languageName %i: %s\n", i, languageName[i]);
languageName[i]);
} }
} }
} }

View File

@ -37,35 +37,47 @@ void drawLine(int x1, int y1, int x2, int y2) {
int x, y; int x, y;
bool backwards = false; bool backwards = false;
#if 0 #if 0
if (x1 < 0) x1 = 0; if (x1 < 0)
if (y1 < 0) y1 = 0; x1 = 0;
if (x2 < 0) x2 = 0; if (y1 < 0)
if (y2 < 0) y2 = 0; y1 = 0;
if (x1 > sceneWidth) x1 = sceneWidth - 1; if (x2 < 0)
if (x2 > sceneWidth) x2 = sceneWidth - 1; x2 = 0;
if (y1 > sceneHeight) y1 = sceneHeight - 1; if (y2 < 0)
if (y2 > sceneHeight) y2 = sceneHeight - 1; y2 = 0;
if (x1 > sceneWidth)
x1 = sceneWidth - 1;
if (x2 > sceneWidth)
x2 = sceneWidth - 1;
if (y1 > sceneHeight)
y1 = sceneHeight - 1;
if (y2 > sceneHeight)
y2 = sceneHeight - 1;
if (x1 > x2) { if (x1 > x2) {
x = x2; x = x2;
backwards = !backwards; backwards = !backwards;
} else x = x1; } else
x = x1;
if (y1 > y2) { if (y1 > y2) {
y = y2; y = y2;
backwards = !backwards; backwards = !backwards;
} else y = y1; } else
y = y1;
int diffX = abs(x2 - x1); int diffX = abs(x2 - x1);
int diffY = abs(y2 - y1); int diffY = abs(y2 - y1);
if (! diffX) { if (!diffX) {
diffX = 1; diffX = 1;
if (x == sceneWidth - 1) x = sceneWidth - 2; if (x == sceneWidth - 1)
x = sceneWidth - 2;
} }
if (! diffY) { if (!diffY) {
diffY = 1; diffY = 1;
if (y == sceneHeight - 1) y = sceneHeight - 2; if (y == sceneHeight - 1)
y = sceneHeight - 2;
} }
setPixelCoords(true); setPixelCoords(true);
@ -82,19 +94,10 @@ void drawLine(int x1, int y1, int x2, int y2) {
// Render the scene - first the old backdrop // Render the scene - first the old backdrop
glBindTexture(GL_TEXTURE_2D, backdropTextureName); glBindTexture(GL_TEXTURE_2D, backdropTextureName);
//glTexEnvf (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); //glTexEnvf (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
const GLfloat vertices[] = { const GLfloat vertices[] = { (GLfloat)-x - xoffset, (GLfloat)1 - y - yoffset, 0., (GLfloat)sceneWidth - x - xoffset, (GLfloat)1 - y - yoffset, 0., (GLfloat)-x - xoffset,
(GLfloat) - x - xoffset, (GLfloat)1 - y - yoffset, 0., (GLfloat)sceneHeight - y - yoffset, 0., (GLfloat)sceneWidth - x - xoffset, (GLfloat)sceneHeight - y - yoffset, 0. };
(GLfloat)sceneWidth - x - xoffset, (GLfloat)1 - y - yoffset, 0.,
(GLfloat) - x - xoffset, (GLfloat)sceneHeight - y - yoffset, 0.,
(GLfloat)sceneWidth - x - xoffset, (GLfloat)sceneHeight - y - yoffset, 0.
};
const GLfloat texCoords[] = { const GLfloat texCoords[] = { 0.0f, 0.0f, backdropTexW, 0.0f, 0.0f, backdropTexH, backdropTexW, backdropTexH };
0.0f, 0.0f,
backdropTexW, 0.0f,
0.0f, backdropTexH,
backdropTexW, backdropTexH
};
glUseProgram(shader.texture); glUseProgram(shader.texture);
@ -105,15 +108,12 @@ void drawLine(int x1, int y1, int x2, int y2) {
//FIXME:Removing the lines doesn't work, but also didn't work properly before. //FIXME:Removing the lines doesn't work, but also didn't work properly before.
GLint xo1 = -xoffset, xo2 = -xoffset; GLint xo1 = -xoffset, xo2 = -xoffset;
if (! backwards) { if (!backwards) {
xo2 += diffX; xo2 += diffX;
} else { } else {
xo1 += diffX; xo1 += diffX;
} }
const GLint lineVertices[] = { const GLint lineVertices[] = { xo1, -yoffset, 0, xo2, -yoffset + diffY, 0, };
xo1, -yoffset, 0,
xo2, -yoffset + diffY, 0,
};
glUseProgram(shader.color); glUseProgram(shader.color);

View File

@ -113,14 +113,13 @@ void saveStack(variableStack *vs, Common::WriteStream *stream) {
} }
} }
variableStack *loadStack(Common::SeekableReadStream *stream, variableStack *loadStack(Common::SeekableReadStream *stream, variableStack **last) {
variableStack **last) {
int elements = stream->readUint16BE(); int elements = stream->readUint16BE();
int a; int a;
variableStack *first = NULL; variableStack *first = NULL;
variableStack * * changeMe = &first; variableStack * * changeMe = &first;
for (a = 0; a < elements; ++a) { for (a = 0; a < elements; a++) {
variableStack *nS = new variableStack; variableStack *nS = new variableStack;
if (!checkNew(nS)) if (!checkNew(nS))
return NULL; return NULL;
@ -147,7 +146,7 @@ bool saveStackRef(stackHandler *vs, Common::WriteStream *stream) {
return true; return true;
} }
s = s->next; s = s->next;
++a; a++;
} }
stream->writeByte(0); stream->writeByte(0);
saveStack(vs->first, stream); saveStack(vs->first, stream);
@ -233,36 +232,34 @@ bool saveVariable(variable *from, Common::WriteStream *stream) {
stream->writeByte(from->varType); stream->writeByte(from->varType);
switch (from->varType) { switch (from->varType) {
case SVT_INT: case SVT_INT:
case SVT_FUNC: case SVT_FUNC:
case SVT_BUILT: case SVT_BUILT:
case SVT_FILE: case SVT_FILE:
case SVT_OBJTYPE: case SVT_OBJTYPE:
stream->writeUint32LE(from->varData.intValue); stream->writeUint32LE(from->varData.intValue);
return true; return true;
case SVT_STRING: case SVT_STRING:
writeString(from->varData.theString, stream); writeString(from->varData.theString, stream);
return true; return true;
case SVT_STACK: case SVT_STACK:
return saveStackRef(from->varData.theStack, stream); return saveStackRef(from->varData.theStack, stream);
case SVT_COSTUME: case SVT_COSTUME:
saveCostume(from->varData.costumeHandler, stream); saveCostume(from->varData.costumeHandler, stream);
return false; return false;
case SVT_ANIM: case SVT_ANIM:
saveAnim(from->varData.animHandler, stream); saveAnim(from->varData.animHandler, stream);
return false; return false;
case SVT_NULL: case SVT_NULL:
return false; return false;
default: default:
fatal("Can't save variables of this type:", fatal("Can't save variables of this type:", (from->varType < SVT_NUM_TYPES) ? typeName[from->varType] : "bad ID");
(from->varType < SVT_NUM_TYPES) ?
typeName[from->varType] : "bad ID");
} }
return true; return true;
} }
@ -270,45 +267,45 @@ bool saveVariable(variable *from, Common::WriteStream *stream) {
bool loadVariable(variable *to, Common::SeekableReadStream *stream) { bool loadVariable(variable *to, Common::SeekableReadStream *stream) {
to->varType = (variableType)stream->readByte(); to->varType = (variableType)stream->readByte();
switch (to->varType) { switch (to->varType) {
case SVT_INT: case SVT_INT:
case SVT_FUNC: case SVT_FUNC:
case SVT_BUILT: case SVT_BUILT:
case SVT_FILE: case SVT_FILE:
case SVT_OBJTYPE: case SVT_OBJTYPE:
to->varData.intValue = stream->readUint32LE(); to->varData.intValue = stream->readUint32LE();
return true; return true;
case SVT_STRING: case SVT_STRING:
to->varData.theString = readString(stream); to->varData.theString = readString(stream);
return true; return true;
case SVT_STACK: case SVT_STACK:
to->varData.theStack = loadStackRef(stream); to->varData.theStack = loadStackRef(stream);
#if DEBUG_STACKINESS #if DEBUG_STACKINESS
{ {
char *str = getTextFromAnyVar(*to); char *str = getTextFromAnyVar(*to);
stackDebug((stackfp, "just loaded %s\n", str)); stackDebug((stackfp, "just loaded %s\n", str));
delete str; delete str;
} }
#endif #endif
return true; return true;
case SVT_COSTUME: case SVT_COSTUME:
to->varData.costumeHandler = new persona; to->varData.costumeHandler = new persona;
if (!checkNew(to->varData.costumeHandler)) if (!checkNew(to->varData.costumeHandler))
return false; return false;
loadCostume(to->varData.costumeHandler, stream); loadCostume(to->varData.costumeHandler, stream);
return true; return true;
case SVT_ANIM: case SVT_ANIM:
to->varData.animHandler = new personaAnimation; to->varData.animHandler = new personaAnimation;
if (!checkNew(to->varData.animHandler)) if (!checkNew(to->varData.animHandler))
return false; return false;
loadAnim(to->varData.animHandler, stream); loadAnim(to->varData.animHandler, stream);
return true; return true;
default: default:
break; break;
} }
return true; return true;
} }

View File

@ -136,50 +136,50 @@ char *encodeFilename(char *nameIn) {
int i = 0; int i = 0;
while (*nameIn) { while (*nameIn) {
switch (*nameIn) { switch (*nameIn) {
case '<': case '<':
newName[i++] = '_'; newName[i++] = '_';
newName[i++] = 'L'; newName[i++] = 'L';
break; break;
case '>': case '>':
newName[i++] = '_'; newName[i++] = '_';
newName[i++] = 'G'; newName[i++] = 'G';
break; break;
case '|': case '|':
newName[i++] = '_'; newName[i++] = '_';
newName[i++] = 'P'; newName[i++] = 'P';
break; break;
case '_': case '_':
newName[i++] = '_'; newName[i++] = '_';
newName[i++] = 'U'; newName[i++] = 'U';
break; break;
case '\"': case '\"':
newName[i++] = '_'; newName[i++] = '_';
newName[i++] = 'S'; newName[i++] = 'S';
break; break;
case '\\': case '\\':
newName[i++] = '_'; newName[i++] = '_';
newName[i++] = 'B'; newName[i++] = 'B';
break; break;
case '/': case '/':
newName[i++] = '_'; newName[i++] = '_';
newName[i++] = 'F'; newName[i++] = 'F';
break; break;
case ':': case ':':
newName[i++] = '_'; newName[i++] = '_';
newName[i++] = 'C'; newName[i++] = 'C';
break; break;
case '*': case '*':
newName[i++] = '_'; newName[i++] = '_';
newName[i++] = 'A'; newName[i++] = 'A';
break; break;
case '?': case '?':
newName[i++] = '_'; newName[i++] = '_';
newName[i++] = 'Q'; newName[i++] = 'Q';
break; break;
default: default:
newName[i++] = *nameIn; newName[i++] = *nameIn;
break; break;
} }
newName[i] = 0; newName[i] = 0;
nameIn++; nameIn++;
@ -211,48 +211,48 @@ char *decodeFilename(char *nameIn) {
if (*nameIn == '_') { if (*nameIn == '_') {
nameIn++; nameIn++;
switch (*nameIn) { switch (*nameIn) {
case 'L': case 'L':
newName[i] = '<'; newName[i] = '<';
nameIn++; nameIn++;
break; break;
case 'G': case 'G':
newName[i] = '>'; newName[i] = '>';
nameIn++; nameIn++;
break; break;
case 'P': case 'P':
newName[i] = '|'; newName[i] = '|';
nameIn++; nameIn++;
break; break;
case 'U': case 'U':
newName[i] = '_'; newName[i] = '_';
nameIn++; nameIn++;
break; break;
case 'S': case 'S':
newName[i] = '\"'; newName[i] = '\"';
nameIn++; nameIn++;
break; break;
case 'B': case 'B':
newName[i] = '\\'; newName[i] = '\\';
nameIn++; nameIn++;
break; break;
case 'F': case 'F':
newName[i] = '/'; newName[i] = '/';
nameIn++; nameIn++;
break; break;
case 'C': case 'C':
newName[i] = ':'; newName[i] = ':';
nameIn++; nameIn++;
break; break;
case 'A': case 'A':
newName[i] = '*'; newName[i] = '*';
nameIn++; nameIn++;
break; break;
case 'Q': case 'Q':
newName[i] = '?'; newName[i] = '?';
nameIn++; nameIn++;
break; break;
default: default:
newName[i] = '_'; newName[i] = '_';
} }
} else { } else {
newName[i] = *nameIn; newName[i] = *nameIn;

View File

@ -42,9 +42,7 @@ namespace Sludge {
const char emergencyMemoryMessage[] = "Out of memory displaying error message!"; const char emergencyMemoryMessage[] = "Out of memory displaying error message!";
static char *fatalMessage = NULL; static char *fatalMessage = NULL;
static char *fatalInfo = static char *fatalInfo = joinStrings("Initialisation error! Something went wrong before we even got started!", "");
joinStrings("Initialisation error! Something went wrong before we even got started!",
"");
extern int numResourceNames /* = 0*/; extern int numResourceNames /* = 0*/;
extern char * *allResourceNames /*= NULL*/; extern char * *allResourceNames /*= NULL*/;
@ -85,9 +83,7 @@ void warning(const char *l) {
void registerWindowForFatal() { void registerWindowForFatal() {
delete fatalInfo; delete fatalInfo;
fatalInfo = fatalInfo =
joinStrings( joinStrings("There's an error with this SLUDGE game! If you're designing this game, please turn on verbose error messages in the project manager and recompile. If not, please contact the author saying where and how this problem occured.", "");
"There's an error with this SLUDGE game! If you're designing this game, please turn on verbose error messages in the project manager and recompile. If not, please contact the author saying where and how this problem occured.",
"");
} }
#if 0 #if 0
@ -132,8 +128,7 @@ void setFatalInfo(const char *userFunc, const char *BIF) {
delete fatalInfo; delete fatalInfo;
fatalInfo = new char[strlen(userFunc) + strlen(BIF) + 38]; fatalInfo = new char[strlen(userFunc) + strlen(BIF) + 38];
if (fatalInfo) if (fatalInfo)
sprintf(fatalInfo, "Currently in this sub: %s\nCalling: %s", userFunc, sprintf(fatalInfo, "Currently in this sub: %s\nCalling: %s", userFunc, BIF);
BIF);
debug(kSludgeDebugFatal, "%s", fatalInfo); debug(kSludgeDebugFatal, "%s", fatalInfo);
} }
@ -144,8 +139,7 @@ void setResourceForFatal(int n) {
int fatal(const char *str1) { int fatal(const char *str1) {
if (numResourceNames && resourceForFatal != -1) { if (numResourceNames && resourceForFatal != -1) {
const char *r = resourceNameFromNum(resourceForFatal); const char *r = resourceNameFromNum(resourceForFatal);
char *newStr = new char[strlen(str1) + strlen(r) + strlen(fatalInfo) char *newStr = new char[strlen(str1) + strlen(r) + strlen(fatalInfo) + 14];
+ 14];
if (checkNew(newStr)) { if (checkNew(newStr)) {
sprintf(newStr, "%s\nResource: %s\n\n%s", fatalInfo, r, str1); sprintf(newStr, "%s\nResource: %s\n\n%s", fatalInfo, r, str1);
inFatal(newStr); inFatal(newStr);

View File

@ -79,8 +79,7 @@ objectType *loadObjectType(int i) {
} }
newType->numCom = bigDataFile->readUint16BE(); newType->numCom = bigDataFile->readUint16BE();
newType->allCombis = newType->allCombis = (newType->numCom) ? new combination[newType->numCom] : NULL;
(newType->numCom) ? new combination[newType->numCom] : NULL;
#if DEBUG_COMBINATIONS #if DEBUG_COMBINATIONS
FILE *callEventLog = fopen("callEventLog.txt", "at"); FILE *callEventLog = fopen("callEventLog.txt", "at");

View File

@ -71,8 +71,7 @@ inline int TF_abs(int a) {
} }
void setFrames(onScreenPerson &m, int a) { void setFrames(onScreenPerson &m, int a) {
m.myAnim = m.myPersona->animation[(a * m.myPersona->numDirections) m.myAnim = m.myPersona->animation[(a * m.myPersona->numDirections) + m.direction];
+ m.direction];
} }
personaAnimation *createPersonaAnim(int num, variableStack *&stacky) { personaAnimation *createPersonaAnim(int num, variableStack *&stacky) {
@ -93,10 +92,8 @@ personaAnimation *createPersonaAnim(int num, variableStack *&stacky) {
} else if (stacky->thisVar.varType == SVT_FUNC) { } else if (stacky->thisVar.varType == SVT_FUNC) {
newP->frames[a].noise = -stacky->thisVar.varData.intValue; newP->frames[a].noise = -stacky->thisVar.varData.intValue;
} else if (stacky->thisVar.varType == SVT_STACK) { } else if (stacky->thisVar.varType == SVT_STACK) {
getValueType(frameNum, SVT_INT, getValueType(frameNum, SVT_INT, stacky->thisVar.varData.theStack->first->thisVar);
stacky->thisVar.varData.theStack->first->thisVar); getValueType(howMany, SVT_INT, stacky->thisVar.varData.theStack->first->next->thisVar);
getValueType(howMany, SVT_INT,
stacky->thisVar.varData.theStack->first->next->thisVar);
} else { } else {
getValueType(frameNum, SVT_INT, stacky->thisVar); getValueType(frameNum, SVT_INT, stacky->thisVar);
howMany = 1; howMany = 1;
@ -182,10 +179,7 @@ bool initPeople() {
void spinStep(onScreenPerson *thisPerson) { void spinStep(onScreenPerson *thisPerson) {
int diff = (thisPerson->angle + 360) - thisPerson->wantAngle; int diff = (thisPerson->angle + 360) - thisPerson->wantAngle;
int eachSlice = int eachSlice = thisPerson->spinSpeed ? thisPerson->spinSpeed : (360 / thisPerson->myPersona->numDirections);
thisPerson->spinSpeed ?
thisPerson->spinSpeed :
(360 / thisPerson->myPersona->numDirections);
while (diff > 180) { while (diff > 180) {
diff -= 360; diff -= 360;
} }
@ -217,8 +211,7 @@ bool turnPersonToFace(int thisNum, int direc) {
thisPerson->walking = false; thisPerson->walking = false;
thisPerson->spinning = false; thisPerson->spinning = false;
turnMeAngle(thisPerson, direc); turnMeAngle(thisPerson, direc);
setFrames(*thisPerson, setFrames(*thisPerson, (thisPerson == speech->currentTalker) ? ANI_TALK : ANI_STAND);
(thisPerson == speech->currentTalker) ? ANI_TALK : ANI_STAND);
return true; return true;
} }
return false; return false;
@ -295,106 +288,106 @@ enum drawModes {
void setMyDrawMode(onScreenPerson *moveMe, int h) { void setMyDrawMode(onScreenPerson *moveMe, int h) {
switch (h) { switch (h) {
case drawModeTransparent3: case drawModeTransparent3:
moveMe->r = moveMe->g = moveMe->b = 0; moveMe->r = moveMe->g = moveMe->b = 0;
moveMe->colourmix = 0; moveMe->colourmix = 0;
moveMe->transparency = 64; moveMe->transparency = 64;
break; break;
case drawModeTransparent2: case drawModeTransparent2:
moveMe->r = moveMe->g = moveMe->b = 0; moveMe->r = moveMe->g = moveMe->b = 0;
moveMe->colourmix = 0; moveMe->colourmix = 0;
moveMe->transparency = 128; moveMe->transparency = 128;
break; break;
case drawModeTransparent1: case drawModeTransparent1:
moveMe->r = moveMe->g = moveMe->b = 0; moveMe->r = moveMe->g = moveMe->b = 0;
moveMe->colourmix = 0; moveMe->colourmix = 0;
moveMe->transparency = 192; moveMe->transparency = 192;
break; break;
case drawModeInvisible: case drawModeInvisible:
moveMe->r = moveMe->g = moveMe->b = 0; moveMe->r = moveMe->g = moveMe->b = 0;
moveMe->colourmix = 0; moveMe->colourmix = 0;
moveMe->transparency = 254; moveMe->transparency = 254;
break; break;
case drawModeDark1: case drawModeDark1:
moveMe->r = moveMe->g = moveMe->b = 0; moveMe->r = moveMe->g = moveMe->b = 0;
moveMe->colourmix = 192; moveMe->colourmix = 192;
moveMe->transparency = 0; moveMe->transparency = 0;
break; break;
case drawModeDark2: case drawModeDark2:
moveMe->r = moveMe->g = moveMe->b = 0; moveMe->r = moveMe->g = moveMe->b = 0;
moveMe->colourmix = 128; moveMe->colourmix = 128;
moveMe->transparency = 0; moveMe->transparency = 0;
break; break;
case drawModeDark3: case drawModeDark3:
moveMe->r = moveMe->g = moveMe->b = 0; moveMe->r = moveMe->g = moveMe->b = 0;
moveMe->colourmix = 64; moveMe->colourmix = 64;
moveMe->transparency = 0; moveMe->transparency = 0;
break; break;
case drawModeBlack: case drawModeBlack:
moveMe->r = moveMe->g = moveMe->b = 0; moveMe->r = moveMe->g = moveMe->b = 0;
moveMe->colourmix = 255; moveMe->colourmix = 255;
moveMe->transparency = 0; moveMe->transparency = 0;
break; break;
case drawModeShadow1: case drawModeShadow1:
moveMe->r = moveMe->g = moveMe->b = 0; moveMe->r = moveMe->g = moveMe->b = 0;
moveMe->colourmix = 255; moveMe->colourmix = 255;
moveMe->transparency = 64; moveMe->transparency = 64;
break; break;
case drawModeShadow2: case drawModeShadow2:
moveMe->r = moveMe->g = moveMe->b = 0; moveMe->r = moveMe->g = moveMe->b = 0;
moveMe->colourmix = 255; moveMe->colourmix = 255;
moveMe->transparency = 128; moveMe->transparency = 128;
break; break;
case drawModeShadow3: case drawModeShadow3:
moveMe->r = moveMe->g = moveMe->b = 0; moveMe->r = moveMe->g = moveMe->b = 0;
moveMe->colourmix = 255; moveMe->colourmix = 255;
moveMe->transparency = 192; moveMe->transparency = 192;
break; break;
case drawModeFoggy3: case drawModeFoggy3:
moveMe->r = moveMe->g = moveMe->b = 128; moveMe->r = moveMe->g = moveMe->b = 128;
moveMe->colourmix = 192; moveMe->colourmix = 192;
moveMe->transparency = 0; moveMe->transparency = 0;
break; break;
case drawModeFoggy2: case drawModeFoggy2:
moveMe->r = moveMe->g = moveMe->b = 128; moveMe->r = moveMe->g = moveMe->b = 128;
moveMe->colourmix = 128; moveMe->colourmix = 128;
moveMe->transparency = 0; moveMe->transparency = 0;
break; break;
case drawModeFoggy1: case drawModeFoggy1:
moveMe->r = moveMe->g = moveMe->b = 128; moveMe->r = moveMe->g = moveMe->b = 128;
moveMe->colourmix = 64; moveMe->colourmix = 64;
moveMe->transparency = 0; moveMe->transparency = 0;
break; break;
case drawModeFoggy4: case drawModeFoggy4:
moveMe->r = moveMe->g = moveMe->b = 128; moveMe->r = moveMe->g = moveMe->b = 128;
moveMe->colourmix = 255; moveMe->colourmix = 255;
moveMe->transparency = 0; moveMe->transparency = 0;
break; break;
case drawModeGlow3: case drawModeGlow3:
moveMe->r = moveMe->g = moveMe->b = 255; moveMe->r = moveMe->g = moveMe->b = 255;
moveMe->colourmix = 192; moveMe->colourmix = 192;
moveMe->transparency = 0; moveMe->transparency = 0;
break; break;
case drawModeGlow2: case drawModeGlow2:
moveMe->r = moveMe->g = moveMe->b = 255; moveMe->r = moveMe->g = moveMe->b = 255;
moveMe->colourmix = 128; moveMe->colourmix = 128;
moveMe->transparency = 0; moveMe->transparency = 0;
break; break;
case drawModeGlow1: case drawModeGlow1:
moveMe->r = moveMe->g = moveMe->b = 255; moveMe->r = moveMe->g = moveMe->b = 255;
moveMe->colourmix = 64; moveMe->colourmix = 64;
moveMe->transparency = 0; moveMe->transparency = 0;
break; break;
case drawModeGlow4: case drawModeGlow4:
moveMe->r = moveMe->g = moveMe->b = 255; moveMe->r = moveMe->g = moveMe->b = 255;
moveMe->colourmix = 255; moveMe->colourmix = 255;
moveMe->transparency = 0; moveMe->transparency = 0;
break; break;
default: default:
moveMe->r = moveMe->g = moveMe->b = 0; moveMe->r = moveMe->g = moveMe->b = 0;
moveMe->colourmix = 0; moveMe->colourmix = 0;
moveMe->transparency = 0; moveMe->transparency = 0;
break; break;
} }
} }
@ -417,8 +410,7 @@ void setPersonTransparency(int ob, unsigned char x) {
moveMe->transparency = x; moveMe->transparency = x;
} }
void setPersonColourise(int ob, unsigned char r, unsigned char g, void setPersonColourise(int ob, unsigned char r, unsigned char g, unsigned char b, unsigned char colourmix) {
unsigned char b, unsigned char colourmix) {
onScreenPerson *moveMe = findPerson(ob); onScreenPerson *moveMe = findPerson(ob);
if (!moveMe) if (!moveMe)
return; return;
@ -474,20 +466,16 @@ void drawPeople() {
thisPerson->frameNum = 0; thisPerson->frameNum = 0;
thisPerson->frameTick = myAnim->frames[0].howMany; thisPerson->frameTick = myAnim->frames[0].howMany;
if (myAnim->frames[thisPerson->frameNum].noise > 0) { if (myAnim->frames[thisPerson->frameNum].noise > 0) {
startSound(myAnim->frames[thisPerson->frameNum].noise, startSound(myAnim->frames[thisPerson->frameNum].noise, false);
false);
thisPerson->frameNum++; thisPerson->frameNum++;
thisPerson->frameNum %= thisPerson->myAnim->numFrames; thisPerson->frameNum %= thisPerson->myAnim->numFrames;
thisPerson->frameTick = thisPerson->frameTick = thisPerson->myAnim->frames[thisPerson->frameNum].howMany;
thisPerson->myAnim->frames[thisPerson->frameNum].howMany;
} else if (myAnim->frames[thisPerson->frameNum].noise) { } else if (myAnim->frames[thisPerson->frameNum].noise) {
startNewFunctionNum( startNewFunctionNum(-myAnim->frames[thisPerson->frameNum].noise, 0,
-myAnim->frames[thisPerson->frameNum].noise, 0, NULL, noStack);
NULL, noStack);
thisPerson->frameNum++; thisPerson->frameNum++;
thisPerson->frameNum %= thisPerson->myAnim->numFrames; thisPerson->frameNum %= thisPerson->myAnim->numFrames;
thisPerson->frameTick = thisPerson->frameTick = thisPerson->myAnim->frames[thisPerson->frameNum].howMany;
thisPerson->myAnim->frames[thisPerson->frameNum].howMany;
} }
} }
int fNumSign = myAnim->frames[thisPerson->frameNum].frameNum; int fNumSign = myAnim->frames[thisPerson->frameNum].frameNum;
@ -499,8 +487,7 @@ void drawPeople() {
} }
if (m != 2) { if (m != 2) {
bool r = false; bool r = false;
r = scaleSprite(myAnim->theSprites->bank.sprites[fNum], r = scaleSprite(myAnim->theSprites->bank.sprites[fNum], myAnim->theSprites->bank.myPalette, thisPerson, m);
myAnim->theSprites->bank.myPalette, thisPerson, m);
if (r) { if (r) {
if (thisPerson->thisType->screenName[0]) { if (thisPerson->thisType->screenName[0]) {
if (personRegion.thisType != thisPerson->thisType) if (personRegion.thisType != thisPerson->thisType)
@ -514,24 +501,19 @@ void drawPeople() {
if (!--thisPerson->frameTick) { if (!--thisPerson->frameTick) {
thisPerson->frameNum++; thisPerson->frameNum++;
thisPerson->frameNum %= thisPerson->myAnim->numFrames; thisPerson->frameNum %= thisPerson->myAnim->numFrames;
thisPerson->frameTick = thisPerson->frameTick = thisPerson->myAnim->frames[thisPerson->frameNum].howMany;
thisPerson->myAnim->frames[thisPerson->frameNum].howMany;
if (thisPerson->show && myAnim && myAnim->frames) { if (thisPerson->show && myAnim && myAnim->frames) {
if (myAnim->frames[thisPerson->frameNum].noise > 0) { if (myAnim->frames[thisPerson->frameNum].noise > 0) {
startSound(myAnim->frames[thisPerson->frameNum].noise, startSound(myAnim->frames[thisPerson->frameNum].noise, false);
false);
thisPerson->frameNum++; thisPerson->frameNum++;
thisPerson->frameNum %= thisPerson->myAnim->numFrames; thisPerson->frameNum %= thisPerson->myAnim->numFrames;
thisPerson->frameTick = thisPerson->frameTick = thisPerson->myAnim->frames[thisPerson->frameNum].howMany;
thisPerson->myAnim->frames[thisPerson->frameNum].howMany;
} else if (myAnim->frames[thisPerson->frameNum].noise) { } else if (myAnim->frames[thisPerson->frameNum].noise) {
startNewFunctionNum( startNewFunctionNum(-myAnim->frames[thisPerson->frameNum].noise, 0,
-myAnim->frames[thisPerson->frameNum].noise, 0, NULL, noStack);
NULL, noStack);
thisPerson->frameNum++; thisPerson->frameNum++;
thisPerson->frameNum %= thisPerson->myAnim->numFrames; thisPerson->frameNum %= thisPerson->myAnim->numFrames;
thisPerson->frameTick = thisPerson->frameTick = thisPerson->myAnim->frames[thisPerson->frameNum].howMany;
thisPerson->myAnim->frames[thisPerson->frameNum].howMany;
} }
} }
} }
@ -548,9 +530,7 @@ void makeSilent(onScreenPerson &me) {
} }
bool handleClosestPoint(int &setX, int &setY, int &setPoly) { bool handleClosestPoint(int &setX, int &setY, int &setPoly) {
int gotX = 320, gotY = 200, gotPoly = -1, i, j, xTest1, yTest1, xTest2, int gotX = 320, gotY = 200, gotPoly = -1, i, j, xTest1, yTest1, xTest2, yTest2, closestX, closestY, oldJ, currentDistance = 0xFFFFF, thisDistance;
yTest2, closestX, closestY, oldJ, currentDistance = 0xFFFFF,
thisDistance;
// FILE * dbug = fopen ("debug_closest.txt", "at"); // FILE * dbug = fopen ("debug_closest.txt", "at");
// fprintf (dbug, "\nGetting closest point to %i, %i\n", setX, setY); // fprintf (dbug, "\nGetting closest point to %i, %i\n", setX, setY);
@ -559,16 +539,11 @@ bool handleClosestPoint(int &setX, int &setY, int &setPoly) {
oldJ = currentFloor->polygon[i].numVertices - 1; oldJ = currentFloor->polygon[i].numVertices - 1;
for (j = 0; j < currentFloor->polygon[i].numVertices; j++) { for (j = 0; j < currentFloor->polygon[i].numVertices; j++) {
// fprintf (dbug, "Polygon %i, line %i... ", i, j); // fprintf (dbug, "Polygon %i, line %i... ", i, j);
xTest1 = xTest1 = currentFloor->vertex[currentFloor->polygon[i].vertexID[j]].x;
currentFloor->vertex[currentFloor->polygon[i].vertexID[j]].x; yTest1 = currentFloor->vertex[currentFloor->polygon[i].vertexID[j]].y;
yTest1 = xTest2 = currentFloor->vertex[currentFloor->polygon[i].vertexID[oldJ]].x;
currentFloor->vertex[currentFloor->polygon[i].vertexID[j]].y; yTest2 = currentFloor->vertex[currentFloor->polygon[i].vertexID[oldJ]].y;
xTest2 = closestPointOnLine(closestX, closestY, xTest1, yTest1, xTest2, yTest2, setX, setY);
currentFloor->vertex[currentFloor->polygon[i].vertexID[oldJ]].x;
yTest2 =
currentFloor->vertex[currentFloor->polygon[i].vertexID[oldJ]].y;
closestPointOnLine(closestX, closestY, xTest1, yTest1, xTest2,
yTest2, setX, setY);
// fprintf (dbug, "closest point is %i, %i... ", closestX, closestY); // fprintf (dbug, "closest point is %i, %i... ", closestX, closestY);
xTest1 = setX - closestX; xTest1 = setX - closestX;
yTest1 = setY - closestY; yTest1 = setY - closestY;
@ -610,8 +585,7 @@ bool doBorderStuff(onScreenPerson *moveMe) {
// Grab the index of the second matching corner... // Grab the index of the second matching corner...
int ID, ID2; int ID, ID2;
if (!getMatchingCorners(currentFloor->polygon[moveMe->inPoly], if (!getMatchingCorners(currentFloor->polygon[moveMe->inPoly], currentFloor->polygon[newPoly], ID, ID2))
currentFloor->polygon[newPoly], ID, ID2))
return fatal("Not a valid floor plan!"); return fatal("Not a valid floor plan!");
// Remember that we're walking to the new polygon... // Remember that we're walking to the new polygon...
@ -647,8 +621,7 @@ bool doBorderStuff(onScreenPerson *moveMe) {
dy23 *= dy23; dy23 *= dy23;
dy24 *= dy24; dy24 *= dy24;
if (sqrt((double) dx13 + dy13) + sqrt((double) dx23 + dy23) if (sqrt((double)dx13 + dy13) + sqrt((double)dx23 + dy23) < sqrt((double)dx14 + dy14) + sqrt((double)dx24 + dy24)) {
< sqrt((double) dx14 + dy14) + sqrt((double) dx24 + dy24)) {
moveMe->thisStepX = x3; moveMe->thisStepX = x3;
moveMe->thisStepY = y3; moveMe->thisStepY = y3;
} else { } else {
@ -679,9 +652,7 @@ bool walkMe(onScreenPerson *thisPerson, bool move = true) {
if (s < 0.2) if (s < 0.2)
s = 0.2; s = 0.2;
maxDiff = maxDiff = (TF_abs(xDiff) >= TF_abs(yDiff)) ? TF_abs(xDiff) : TF_abs(yDiff);
(TF_abs(xDiff) >= TF_abs(yDiff)) ?
TF_abs(xDiff) : TF_abs(yDiff);
if (TF_abs(maxDiff) > s) { if (TF_abs(maxDiff) > s) {
if (thisPerson->spinning) { if (thisPerson->spinning) {
@ -690,8 +661,7 @@ bool walkMe(onScreenPerson *thisPerson, bool move = true) {
} }
s = maxDiff / s; s = maxDiff / s;
if (move) if (move)
moveAndScale(*thisPerson, thisPerson->x + xDiff / s, moveAndScale(*thisPerson, thisPerson->x + xDiff / s, thisPerson->y + yDiff / (s * 2));
thisPerson->y + yDiff / (s * 2));
return true; return true;
} }
@ -732,8 +702,7 @@ bool makeWalkingPerson(int x, int y, int objNum, loadedFunction *func, int di) {
moveMe->walkToY = y; moveMe->walkToY = y;
moveMe->walkToPoly = inFloor(x, y); moveMe->walkToPoly = inFloor(x, y);
if (moveMe->walkToPoly == -1) { if (moveMe->walkToPoly == -1) {
if (!handleClosestPoint(moveMe->walkToX, moveMe->walkToY, if (!handleClosestPoint(moveMe->walkToX, moveMe->walkToY, moveMe->walkToPoly))
moveMe->walkToPoly))
return false; return false;
} }
@ -767,8 +736,7 @@ bool stopPerson(int o) {
return false; return false;
} }
bool forceWalkingPerson(int x, int y, int objNum, loadedFunction *func, bool forceWalkingPerson(int x, int y, int objNum, loadedFunction *func, int di) {
int di) {
if (x == 0 && y == 0) if (x == 0 && y == 0)
return false; return false;
onScreenPerson *moveMe = findPerson(objNum); onScreenPerson *moveMe = findPerson(objNum);
@ -840,8 +808,7 @@ void walkAllPeople() {
spinStep(thisPerson); spinStep(thisPerson);
setFrames(*thisPerson, ANI_STAND); setFrames(*thisPerson, ANI_STAND);
} }
if ((!thisPerson->walking) && (!thisPerson->spinning) if ((!thisPerson->walking) && (!thisPerson->spinning) && thisPerson->continueAfterWalking) {
&& thisPerson->continueAfterWalking) {
restartFunction(thisPerson->continueAfterWalking); restartFunction(thisPerson->continueAfterWalking);
thisPerson->continueAfterWalking = NULL; thisPerson->continueAfterWalking = NULL;
} }
@ -890,12 +857,10 @@ bool addPerson(int x, int y, int objNum, persona *p) {
if (fNumSigned < 0) { if (fNumSigned < 0) {
newPerson->height = 5; newPerson->height = 5;
} else { } else {
newPerson->height = newPerson->height = p->animation[0]->theSprites->bank.sprites[0].yhot + 5;
p->animation[0]->theSprites->bank.sprites[0].yhot + 5;
} }
} else { } else {
newPerson->height = p->animation[0]->theSprites->bank.sprites[fNum].yhot newPerson->height = p->animation[0]->theSprites->bank.sprites[fNum].yhot + 5;
+ 5;
} }
// NOW ADD IT IN THE RIGHT PLACE // NOW ADD IT IN THE RIGHT PLACE
@ -907,7 +872,7 @@ bool addPerson(int x, int y, int objNum, persona *p) {
newPerson->next = (*changethat); newPerson->next = (*changethat);
(*changethat) = newPerson; (*changethat) = newPerson;
return (bool) (newPerson->thisType != NULL); return (bool)(newPerson->thisType != NULL);
} }
int timeForAnim(personaAnimation *fram) { int timeForAnim(personaAnimation *fram) {
@ -987,8 +952,7 @@ void removeOneCharacter(int i) {
onScreenPerson *p = findPerson(i); onScreenPerson *p = findPerson(i);
if (p) { if (p) {
if (overRegion == &personRegion if (overRegion == &personRegion && overRegion->thisType == p->thisType) {
&& overRegion->thisType == p->thisType) {
overRegion = NULL; overRegion = NULL;
} }
@ -997,8 +961,7 @@ void removeOneCharacter(int i) {
p->continueAfterWalking = NULL; p->continueAfterWalking = NULL;
onScreenPerson * * killPeople; onScreenPerson * * killPeople;
for (killPeople = &allPeople; *killPeople != p; killPeople = for (killPeople = &allPeople; *killPeople != p; killPeople = &((*killPeople)->next)) {
&((*killPeople)->next)) {
; ;
} }

View File

@ -69,43 +69,34 @@ struct onScreenPerson {
}; };
// Initialisation and creation // Initialisation and creation
bool initPeople(); bool initPeople();
bool addPerson(int x, int y, int objNum, persona *p); bool addPerson(int x, int y, int objNum, persona *p);
// Draw to screen and to backdrop // Draw to screen and to backdrop
void drawPeople(); void drawPeople();
void freezePeople(int, int); void freezePeople(int, int);
// Removalisationisms // Removalisationisms
void killAllPeople(); void killAllPeople();
void killMostPeople(); void killMostPeople();
void removeOneCharacter(int i); void removeOneCharacter(int i);
// Things which affect or use all characters // Things which affect or use all characters
onScreenPerson *findPerson(int v); onScreenPerson *findPerson(int v);
void setScale(short int h, short int d); void setScale(short int h, short int d);
// Things which affect one character // Things which affect one character
void makeTalker(onScreenPerson &me); void makeTalker(onScreenPerson &me);
void makeSilent(onScreenPerson &me); void makeSilent(onScreenPerson &me);
void setShown(bool h, int ob); void setShown(bool h, int ob);
void setDrawMode(int h, int ob); void setDrawMode(int h, int ob);
void setPersonTransparency(int ob, unsigned char x); void setPersonTransparency(int ob, unsigned char x);
void setPersonColourise(int ob, unsigned char r, unsigned char g, void setPersonColourise(int ob, unsigned char r, unsigned char g, unsigned char b, unsigned char colourmix);
unsigned char b, unsigned char colourmix);
// Moving 'em // Moving 'em
void movePerson(int x, int y, int objNum); void movePerson(int x, int y, int objNum);
bool makeWalkingPerson(int x, int y, int objNum, struct loadedFunction *func, bool makeWalkingPerson(int x, int y, int objNum, struct loadedFunction *func, int di);
int di); bool forceWalkingPerson(int x, int y, int objNum, struct loadedFunction *func, int di);
bool forceWalkingPerson(int x, int y, int objNum, struct loadedFunction *func,
int di);
void jumpPerson(int x, int y, int objNum); void jumpPerson(int x, int y, int objNum);
void walkAllPeople(); void walkAllPeople();
bool turnPersonToFace(int thisNum, int direc); bool turnPersonToFace(int thisNum, int direc);
@ -114,7 +105,6 @@ bool floatCharacter(int f, int objNum);
bool setCharacterWalkSpeed(int f, int objNum); bool setCharacterWalkSpeed(int f, int objNum);
// Animating 'em // Animating 'em
void animatePerson(int obj, personaAnimation *); void animatePerson(int obj, personaAnimation *);
void animatePerson(int obj, persona *per); void animatePerson(int obj, persona *per);
personaAnimation *createPersonaAnim(int num, struct variableStack *&stacky); personaAnimation *createPersonaAnim(int num, struct variableStack *&stacky);

View File

@ -47,7 +47,7 @@ void showBoxes() {
} }
void removeScreenRegion(int objectNum) { void removeScreenRegion(int objectNum) {
screenRegion * * huntRegion = &allScreenRegions; screenRegion ** huntRegion = &allScreenRegions;
screenRegion *killMe; screenRegion *killMe;
while (*huntRegion) { while (*huntRegion) {

View File

@ -77,7 +77,7 @@ char *readStringEncoded(Common::File *fp) {
if (!checkNew(s)) if (!checkNew(s))
return NULL; return NULL;
for (a = 0; a < len; a++) { for (a = 0; a < len; a++) {
s[a] = (char) (fp->readByte() ^ encode1); s[a] = (char)(fp->readByte() ^ encode1);
encode1 += encode2; encode1 += encode2;
} }
s[len] = 0; s[len] = 0;
@ -95,7 +95,7 @@ char *readTextPlain(Common::File *fp) {
startPos = fp->pos(); startPos = fp->pos();
while (keepGoing) { while (keepGoing) {
gotChar = (char) fp->readByte(); gotChar = (char)fp->readByte();
if ((gotChar == '\n') || (fp->eos())) { if ((gotChar == '\n') || (fp->eos())) {
keepGoing = false; keepGoing = false;
} else { } else {
@ -125,9 +125,7 @@ bool fileToStack(char *filename, stackHandler *sH) {
variable stringVar; variable stringVar;
stringVar.varType = SVT_NULL; stringVar.varType = SVT_NULL;
const char *checker = const char *checker = saveEncoding ? "[Custom data (encoded)]\r\n" : "[Custom data (ASCII)]\n";
saveEncoding ?
"[Custom data (encoded)]\r\n" : "[Custom data (ASCII)]\n";
Common::File fd; Common::File fd;
@ -153,14 +151,13 @@ bool fileToStack(char *filename, stackHandler *sH) {
return fatal("No such file", filename); //TODO: false value return fatal("No such file", filename); //TODO: false value
} }
encode1 = (unsigned char) saveEncoding & 255; encode1 = (unsigned char)saveEncoding & 255;
encode2 = (unsigned char) (saveEncoding >> 8); encode2 = (unsigned char)(saveEncoding >> 8);
while (*checker) { while (*checker) {
if (fd.readByte() != *checker) { if (fd.readByte() != *checker) {
fd.close(); fd.close();
return fatal(LOAD_ERROR "This isn't a SLUDGE custom data file:", return fatal(LOAD_ERROR "This isn't a SLUDGE custom data file:", filename);
filename);
} }
checker++; checker++;
} }
@ -170,8 +167,7 @@ bool fileToStack(char *filename, stackHandler *sH) {
if (strcmp(checker, "UN<EFBFBD>LO<EFBFBD>CKED")) { if (strcmp(checker, "UN<EFBFBD>LO<EFBFBD>CKED")) {
fd.close(); fd.close();
return fatal( return fatal(
LOAD_ERROR "The current file encoding setting does not match the encoding setting used when this file was created:", LOAD_ERROR "The current file encoding setting does not match the encoding setting used when this file was created:", filename);
filename);
} }
delete checker; delete checker;
checker = NULL; checker = NULL;
@ -184,25 +180,25 @@ bool fileToStack(char *filename, stackHandler *sH) {
if (fd.eos()) if (fd.eos())
break; break;
switch (i) { switch (i) {
case 0: { case 0: {
char *g = readStringEncoded(&fd); char *g = readStringEncoded(&fd);
makeTextVar(stringVar, g); makeTextVar(stringVar, g);
delete g; delete g;
} }
break; break;
case 1: case 1:
setVariable(stringVar, SVT_INT, fd.readUint32LE()); setVariable(stringVar, SVT_INT, fd.readUint32LE());
break; break;
case 2: case 2:
setVariable(stringVar, SVT_INT, fd.readByte()); setVariable(stringVar, SVT_INT, fd.readByte());
break; break;
default: default:
fatal(LOAD_ERROR "Corrupt custom data file:", filename); fatal(LOAD_ERROR "Corrupt custom data file:", filename);
fd.close(); fd.close();
return false; return false;
} }
} else { } else {
char *line = readTextPlain(&fd); char *line = readTextPlain(&fd);

View File

@ -20,7 +20,7 @@
* *
*/ */
#include "common/scummsys.h" #include "common/scummsys.h"
#include "common/config-manager.h" #include "common/config-manager.h"
#include "common/debug.h" #include "common/debug.h"
#include "common/debug-channels.h" #include "common/debug-channels.h"
@ -32,10 +32,10 @@
#include "main_loop.h" #include "main_loop.h"
namespace Sludge { namespace Sludge {
SludgeEngine::SludgeEngine(OSystem *syst, const SludgeGameDescription *gameDesc) SludgeEngine::SludgeEngine(OSystem *syst, const SludgeGameDescription *gameDesc) :
: Engine(syst), _gameDescription(gameDesc), _console(nullptr) { Engine(syst), _gameDescription(gameDesc), _console(nullptr) {
// register your random source // register your random source
_rnd = new Common::RandomSource("sludge"); _rnd = new Common::RandomSource("sludge");
@ -49,19 +49,19 @@ SludgeEngine::SludgeEngine(OSystem *syst, const SludgeGameDescription *gameDesc)
// check init // check init
debug("SludgeEngine::SludgeEngine"); debug("SludgeEngine::SludgeEngine");
} }
SludgeEngine::~SludgeEngine() { SludgeEngine::~SludgeEngine() {
// Dispose resources // Dispose resources
delete _rnd; delete _rnd;
// Remove debug levels // Remove debug levels
DebugMan.clearAllDebugChannels(); DebugMan.clearAllDebugChannels();
// Dispose console // Dispose console
delete _console; delete _console;
} }
Common::Error SludgeEngine::run() { Common::Error SludgeEngine::run() {
// init graphics // init graphics
Graphics::PixelFormat format = Graphics::PixelFormat(4, 8, 8, 8, 8, 24, 16, 8, 0); Graphics::PixelFormat format = Graphics::PixelFormat(4, 8, 8, 8, 8, 24, 16, 8, 0);
@ -69,12 +69,12 @@ Common::Error SludgeEngine::run() {
// create console // create console
_console = new SludgeConsole(this); _console = new SludgeConsole(this);
// debug log // debug log
main_loop("Welcome.slg"); main_loop("Welcome.slg");
return Common::kNoError; return Common::kNoError;
} }
} // End of namespace Sludge } // End of namespace Sludge

View File

@ -1672,8 +1672,7 @@ bool handleInput() {
delete tempString; delete tempString;
tempString = NULL; tempString = NULL;
tempStack->next = NULL; tempStack->next = NULL;
if (!startNewFunctionNum(currentEvents->spaceFunction, 1, NULL, if (!startNewFunctionNum(currentEvents->spaceFunction, 1, NULL, tempStack))
tempStack))
return false; return false;
} }
} }

View File

@ -82,8 +82,7 @@ extern int iconW, iconH;
bool initSludge(char *); bool initSludge(char *);
void sludgeDisplay(); void sludgeDisplay();
int startNewFunctionNum(unsigned int, unsigned int, loadedFunction *, int startNewFunctionNum(unsigned int, unsigned int, loadedFunction *, variableStack*&, bool = true);
variableStack*&, bool = true);
bool handleInput(); bool handleInput();
void restartFunction(loadedFunction *fun); void restartFunction(loadedFunction *fun);
bool loadFunctionCode(loadedFunction *newFunc); bool loadFunctionCode(loadedFunction *newFunc);
@ -92,8 +91,7 @@ void saveHandlers(Common::WriteStream *stream);
void finishFunction(loadedFunction *fun); void finishFunction(loadedFunction *fun);
void abortFunction(loadedFunction *fun); void abortFunction(loadedFunction *fun);
Common::File *openAndVerify(char *filename, char extra1, char extra2, Common::File *openAndVerify(char *filename, char extra1, char extra2, const char *er, int &fileVersion);
const char *er, int &fileVersion);
void freezeSubs(); void freezeSubs();
void unfreezeSubs(); void unfreezeSubs();

View File

@ -49,8 +49,7 @@ soundThing soundCache[MAX_SAMPLES];
int defVol = 128; int defVol = 128;
int defSoundVol = 255; int defSoundVol = 255;
char *loadEntireFileToMemory(Common::SeekableReadStream *inputFile, char *loadEntireFileToMemory(Common::SeekableReadStream *inputFile, uint32_t size) {
uint32_t size) {
char *allData = new char[size]; char *allData = new char[size];
if (!allData) if (!allData)
return NULL; return NULL;
@ -147,11 +146,7 @@ bool playMOD(int f, int a, int fromTrack) {
if (!memImage) if (!memImage)
return fatal(ERROR_MUSIC_MEMORY_LOW); return fatal(ERROR_MUSIC_MEMORY_LOW);
mod[a] = mod[a] = BASS_MusicLoad(true, memImage, 0, length, BASS_MUSIC_LOOP | BASS_MUSIC_RAMP/*|BASS_MUSIC_PRESCAN needed too if we're going to set the position in bytes*/, 0);
BASS_MusicLoad(true, memImage, 0, length,
BASS_MUSIC_LOOP
| BASS_MUSIC_RAMP/*|BASS_MUSIC_PRESCAN needed too if we're going to set the position in bytes*/,
0);
delete memImage; delete memImage;
if (!mod[a]) { if (!mod[a]) {
@ -162,10 +157,8 @@ bool playMOD(int f, int a, int fromTrack) {
if (!BASS_ChannelPlay(mod[a], true)) if (!BASS_ChannelPlay(mod[a], true))
debugOut("playMOD: Error %d!\n", BASS_ErrorGetCode()); debugOut("playMOD: Error %d!\n", BASS_ErrorGetCode());
BASS_ChannelSetPosition(mod[a], MAKELONG(fromTrack, 0), BASS_ChannelSetPosition(mod[a], MAKELONG(fromTrack, 0), BASS_POS_MUSIC_ORDER);
BASS_POS_MUSIC_ORDER); BASS_ChannelFlags(mod[a], BASS_SAMPLE_LOOP | BASS_MUSIC_RAMP, BASS_SAMPLE_LOOP | BASS_MUSIC_RAMP);
BASS_ChannelFlags(mod[a], BASS_SAMPLE_LOOP | BASS_MUSIC_RAMP,
BASS_SAMPLE_LOOP | BASS_MUSIC_RAMP);
} }
setResourceForFatal(-1); setResourceForFatal(-1);
} }
@ -175,8 +168,7 @@ bool playMOD(int f, int a, int fromTrack) {
void setMusicVolume(int a, int v) { void setMusicVolume(int a, int v) {
int ret; int ret;
if (soundOK && mod[a]) { if (soundOK && mod[a]) {
ret = BASS_ChannelSetAttribute(mod[a], BASS_ATTRIB_VOL, ret = BASS_ChannelSetAttribute(mod[a], BASS_ATTRIB_VOL, (float)v / 256);
(float) v / 256);
if (!ret) { if (!ret) {
debugOut("setMusicVolume: Error %d\n", BASS_ErrorGetCode()); debugOut("setMusicVolume: Error %d\n", BASS_ErrorGetCode());
} }
@ -192,8 +184,7 @@ void setSoundVolume(int a, int v) {
int ch = findInSoundCache(a); int ch = findInSoundCache(a);
if (ch != -1) { if (ch != -1) {
if (BASS_ChannelIsActive(soundCache[ch].mostRecentChannel)) { if (BASS_ChannelIsActive(soundCache[ch].mostRecentChannel)) {
BASS_ChannelSetAttribute(soundCache[ch].mostRecentChannel, BASS_ChannelSetAttribute(soundCache[ch].mostRecentChannel, BASS_ATTRIB_VOL, (float)v / 256);
BASS_ATTRIB_VOL, (float) v / 256);
} }
} }
} }
@ -203,8 +194,7 @@ bool stillPlayingSound(int ch) {
if (soundOK) if (soundOK)
if (ch != -1) if (ch != -1)
if (soundCache[ch].fileLoaded != -1) if (soundCache[ch].fileLoaded != -1)
if (BASS_ChannelIsActive(soundCache[ch].mostRecentChannel) if (BASS_ChannelIsActive(soundCache[ch].mostRecentChannel) != BASS_ACTIVE_STOPPED)
!= BASS_ACTIVE_STOPPED)
return true; return true;
return false; return false;
} }
@ -318,8 +308,7 @@ int cacheSound(int f) {
for (;;) { for (;;) {
// soundWarning (" Trying to load sound into slot", a); // soundWarning (" Trying to load sound into slot", a);
soundCache[a].sample = BASS_SampleLoad(true, memImage, 0, length, 65535, soundCache[a].sample = BASS_SampleLoad(true, memImage, 0, length, 65535, 0);
0);
if (soundCache[a].sample) { if (soundCache[a].sample) {
soundCache[a].fileLoaded = f; soundCache[a].fileLoaded = f;
@ -345,15 +334,12 @@ bool startSound(int f, bool loopy) {
soundCache[a].looping = loopy; soundCache[a].looping = loopy;
soundCache[a].vol = defSoundVol; soundCache[a].vol = defSoundVol;
soundCache[a].mostRecentChannel = BASS_SampleGetChannel( soundCache[a].mostRecentChannel = BASS_SampleGetChannel(soundCache[a].sample, false);
soundCache[a].sample, false);
if (soundCache[a].mostRecentChannel) { if (soundCache[a].mostRecentChannel) {
BASS_ChannelPlay(soundCache[a].mostRecentChannel, true); BASS_ChannelPlay(soundCache[a].mostRecentChannel, true);
BASS_ChannelSetAttribute(soundCache[a].mostRecentChannel, BASS_ChannelSetAttribute(soundCache[a].mostRecentChannel, BASS_ATTRIB_VOL, defSoundVol);
BASS_ATTRIB_VOL, defSoundVol);
if (loopy) { if (loopy) {
BASS_ChannelFlags(soundCache[a].mostRecentChannel, BASS_ChannelFlags(soundCache[a].mostRecentChannel, BASS_SAMPLE_LOOP, BASS_SAMPLE_LOOP); // set LOOP flag
BASS_SAMPLE_LOOP, BASS_SAMPLE_LOOP); // set LOOP flag
} }
} }

View File

@ -52,8 +52,7 @@ loadedSpriteBank *loadBankForAnim(int ID) {
debugOut("loadBankForAnim: New sprite bank created OK\n"); debugOut("loadBankForAnim: New sprite bank created OK\n");
return returnMe; return returnMe;
} else { } else {
debugOut( debugOut("loadBankForAnim: I guess I couldn't load the sprites...\n");
"loadBankForAnim: I guess I couldn't load the sprites...\n");
return NULL; return NULL;
} }
} else } else

View File

@ -67,19 +67,13 @@ bool loadSpriteBank(char *filename, spriteBank &loadhere);
bool loadSpriteBank(int fileNum, spriteBank &loadhere, bool isFont); bool loadSpriteBank(int fileNum, spriteBank &loadhere, bool isFont);
void fontSprite(int x1, int y1, sprite &single, const spritePalette &fontPal); void fontSprite(int x1, int y1, sprite &single, const spritePalette &fontPal);
void flipFontSprite(int x1, int y1, sprite &single, void flipFontSprite(int x1, int y1, sprite &single, const spritePalette &fontPal);
const spritePalette &fontPal);
bool scaleSprite(sprite &single, const spritePalette &fontPal, bool scaleSprite(sprite &single, const spritePalette &fontPal, onScreenPerson *thisPerson, bool mirror);
onScreenPerson *thisPerson, bool mirror); void pasteSpriteToBackDrop(int x1, int y1, sprite &single, const spritePalette &fontPal);
void pasteSpriteToBackDrop(int x1, int y1, sprite &single,
const spritePalette &fontPal);
bool reserveSpritePal(spritePalette &sP, int n); bool reserveSpritePal(spritePalette &sP, int n);
void fixScaleSprite(int x1, int y1, sprite &single, void fixScaleSprite(int x1, int y1, sprite &single, const spritePalette &fontPal, onScreenPerson *thisPerson, const int camX, const int camY, bool);
const spritePalette &fontPal, onScreenPerson *thisPerson, void burnSpriteToBackDrop(int x1, int y1, sprite &single, const spritePalette &fontPal);
const int camX, const int camY, bool);
void burnSpriteToBackDrop(int x1, int y1, sprite &single,
const spritePalette &fontPal);
} // End of namespace Sludge } // End of namespace Sludge

View File

@ -223,8 +223,8 @@ bool loadStatusBars(Common::SeekableReadStream *stream) {
if (! checkNew(newOne)) return false; if (! checkNew(newOne)) return false;
newOne->text = readString(stream); newOne->text = readString(stream);
newOne->next = NULL; newOne->next = NULL;
(* viewLine) = newOne; (*viewLine) = newOne;
viewLine = & (newOne->next); viewLine = &(newOne->next);
} }
return true; return true;
} }

View File

@ -104,8 +104,8 @@ bool saveThumbnail(Common::WriteStream *stream) {
GLuint *tmp = new GLuint [thumbWidth * thumbHeight]; GLuint *tmp = new GLuint [thumbWidth * thumbHeight];
if (! checkNew(image)) return false; if (! checkNew(image)) return false;
glReadPixels(viewportOffsetX, viewportOffsetY, thumbWidth, thumbHeight, GL_RGBA, GL_UNSIGNED_BYTE, tmp); glReadPixels(viewportOffsetX, viewportOffsetY, thumbWidth, thumbHeight, GL_RGBA, GL_UNSIGNED_BYTE, tmp);
for (int y = 0; y < thumbHeight; y ++) { for (int y = 0; y < thumbHeight; y++) {
for (int x = 0; x < thumbWidth; x ++) { for (int x = 0; x < thumbWidth; x++) {
const GLuint a = tmp[y * thumbWidth + x]; const GLuint a = tmp[y * thumbWidth + x];
image[y * thumbWidth + x] = ((a & 0x00f80000) >> (16 + 3)) | ((a & 0x0000fc00) >> (8 + 2 - 5)) | ((a & 0x000000f8) << (11 - 3)); image[y * thumbWidth + x] = ((a & 0x00f80000) >> (16 + 3)) | ((a & 0x0000fc00) >> (8 + 2 - 5)) | ((a & 0x000000f8) << (11 - 3));
} }
@ -122,8 +122,8 @@ bool saveThumbnail(Common::WriteStream *stream) {
#endif #endif
setPixelCoords(false); setPixelCoords(false);
for (int y = 0; y < thumbHeight; y ++) { for (int y = 0; y < thumbHeight; y++) {
for (int x = 0; x < thumbWidth; x ++) { for (int x = 0; x < thumbWidth; x++) {
put2bytes((*(image + y * thumbWidth + x)), fp); put2bytes((*(image + y * thumbWidth + x)), fp);
} }
} }
@ -167,7 +167,7 @@ void showThumbnail(char *filename, int atX, int atY) {
int t1, t2; int t1, t2;
unsigned short c; unsigned short c;
GLubyte *target; GLubyte *target;
for (t2 = 0; t2 < fileHeight; t2 ++) { for (t2 = 0; t2 < fileHeight; t2++) {
t1 = 0; t1 = 0;
while (t1 < fileWidth) { while (t1 < fileWidth) {
c = (unsigned short) fp->readUint16BE(); c = (unsigned short) fp->readUint16BE();

View File

@ -380,27 +380,27 @@ void transitionBlinds() {
void fixBrightness() { void fixBrightness() {
switch (fadeMode) { switch (fadeMode) {
case 0: case 0:
transitionFader(); transitionFader();
break; break;
case 1: case 1:
resetRandW(); resetRandW();
// Fall through! // Fall through!
case 2: case 2:
transitionDisolve(); transitionDisolve();
break; break;
case 3: case 3:
transitionTV(); transitionTV();
break; break;
case 4: case 4:
transitionBlinds(); transitionBlinds();
break; break;
case 5: case 5:
transitionCrossFader(); transitionCrossFader();
break; break;
case 6: case 6:
transitionSnapshotBox(); transitionSnapshotBox();
break; break;
} }
} }

View File

@ -49,36 +49,36 @@ extern char *outputDir;
void unlinkVar(variable &thisVar) { void unlinkVar(variable &thisVar) {
switch (thisVar.varType) { switch (thisVar.varType) {
case SVT_STRING: case SVT_STRING:
delete[] thisVar.varData.theString; delete[] thisVar.varData.theString;
thisVar.varData.theString = NULL; thisVar.varData.theString = NULL;
break; break;
case SVT_STACK: case SVT_STACK:
thisVar.varData.theStack->timesUsed--; thisVar.varData.theStack->timesUsed--;
if (thisVar.varData.theStack->timesUsed <= 0) { if (thisVar.varData.theStack->timesUsed <= 0) {
while (thisVar.varData.theStack->first) while (thisVar.varData.theStack->first)
trimStack(thisVar.varData.theStack->first); trimStack(thisVar.varData.theStack->first);
delete thisVar.varData.theStack; delete thisVar.varData.theStack;
thisVar.varData.theStack = NULL; thisVar.varData.theStack = NULL;
} }
break; break;
case SVT_FASTARRAY: case SVT_FASTARRAY:
thisVar.varData.fastArray->timesUsed--; thisVar.varData.fastArray->timesUsed--;
if (thisVar.varData.theStack->timesUsed <= 0) { if (thisVar.varData.theStack->timesUsed <= 0) {
delete thisVar.varData.fastArray->fastVariables; delete thisVar.varData.fastArray->fastVariables;
delete[] thisVar.varData.fastArray; delete[] thisVar.varData.fastArray;
thisVar.varData.fastArray = NULL; thisVar.varData.fastArray = NULL;
} }
break; break;
case SVT_ANIM: case SVT_ANIM:
deleteAnim(thisVar.varData.animHandler); deleteAnim(thisVar.varData.animHandler);
break; break;
default: default:
break; break;
} }
} }
@ -101,8 +101,7 @@ personaAnimation *getAnimationFromVar(variable &thisVar) {
if (thisVar.varType == SVT_INT && thisVar.varData.intValue == 0) if (thisVar.varType == SVT_INT && thisVar.varData.intValue == 0)
return makeNullAnim(); return makeNullAnim();
fatal("Expecting an animation variable; found variable of type", fatal("Expecting an animation variable; found variable of type", typeName[thisVar.varType]);
typeName[thisVar.varType]);
return NULL; return NULL;
} }
@ -116,27 +115,26 @@ persona *getCostumeFromVar(variable &thisVar) {
persona *p = NULL; persona *p = NULL;
switch (thisVar.varType) { switch (thisVar.varType) {
case SVT_ANIM: case SVT_ANIM:
p = new persona; p = new persona;
if (!checkNew(p)) if (!checkNew(p))
return NULL; return NULL;
p->numDirections = 1; p->numDirections = 1;
p->animation = new personaAnimation *[3]; p->animation = new personaAnimation *[3];
if (!checkNew(p->animation)) if (!checkNew(p->animation))
return NULL; return NULL;
for (int iii = 0; iii < 3; iii++) for (int iii = 0; iii < 3; iii++)
p->animation[iii] = copyAnim(thisVar.varData.animHandler); p->animation[iii] = copyAnim(thisVar.varData.animHandler);
break; break;
case SVT_COSTUME: case SVT_COSTUME:
return thisVar.varData.costumeHandler; return thisVar.varData.costumeHandler;
break; break;
default: default:
fatal("Expecting an animation variable; found variable of type", fatal("Expecting an animation variable; found variable of type", typeName[thisVar.varType]);
typeName[thisVar.varType]);
} }
return p; return p;
@ -297,29 +295,29 @@ int compareVars(const variable &var1, const variable &var2) {
int re = 0; int re = 0;
if (var1.varType == var2.varType) { if (var1.varType == var2.varType) {
switch (var1.varType) { switch (var1.varType) {
case SVT_NULL: case SVT_NULL:
re = 1; re = 1;
break; break;
case SVT_COSTUME: case SVT_COSTUME:
re = (var1.varData.costumeHandler == var2.varData.costumeHandler); re = (var1.varData.costumeHandler == var2.varData.costumeHandler);
break; break;
case SVT_ANIM: case SVT_ANIM:
re = (var1.varData.animHandler == var2.varData.animHandler); re = (var1.varData.animHandler == var2.varData.animHandler);
break; break;
case SVT_STRING: case SVT_STRING:
re = (strcmp(var1.varData.theString, var2.varData.theString) == 0); re = (strcmp(var1.varData.theString, var2.varData.theString) == 0);
break; break;
case SVT_STACK: case SVT_STACK:
re = (var1.varData.theStack == var2.varData.theStack); re = (var1.varData.theStack == var2.varData.theStack);
break; break;
default: default:
re = (var1.varData.intValue == var2.varData.intValue); re = (var1.varData.intValue == var2.varData.intValue);
} }
} }
return re; return re;
@ -338,93 +336,92 @@ void makeTextVar(variable &thisVar, const char *txt) {
bool loadStringToVar(variable &thisVar, int value) { bool loadStringToVar(variable &thisVar, int value) {
makeTextVar(thisVar, getNumberedString(value)); makeTextVar(thisVar, getNumberedString(value));
return (bool) (thisVar.varData.theString != NULL); return (bool)(thisVar.varData.theString != NULL);
} }
char *getTextFromAnyVar(const variable &from) { char *getTextFromAnyVar(const variable &from) {
switch (from.varType) { switch (from.varType) {
case SVT_STRING: case SVT_STRING:
return copyString(from.varData.theString); return copyString(from.varData.theString);
case SVT_FASTARRAY: { case SVT_FASTARRAY: {
char *builder = copyString("FAST:"); char *builder = copyString("FAST:");
char *builder2; char *builder2;
char *grabText; char *grabText;
for (int i = 0; i < from.varData.fastArray->size; i++) { for (int i = 0; i < from.varData.fastArray->size; i++) {
builder2 = joinStrings(builder, " "); builder2 = joinStrings(builder, " ");
if (!builder2) if (!builder2)
return NULL; return NULL;
delete builder; delete builder;
grabText = getTextFromAnyVar( grabText = getTextFromAnyVar(from.varData.fastArray->fastVariables[i]);
from.varData.fastArray->fastVariables[i]); builder = joinStrings(builder2, grabText);
builder = joinStrings(builder2, grabText); if (!builder)
if (!builder) return NULL;
return NULL; delete grabText;
delete grabText; grabText = NULL;
grabText = NULL; delete builder2;
delete builder2; builder2 = NULL;
builder2 = NULL; }
return builder;
} }
return builder;
}
case SVT_STACK: { case SVT_STACK: {
char *builder = copyString("ARRAY:"); char *builder = copyString("ARRAY:");
char *builder2; char *builder2;
char *grabText; char *grabText;
variableStack *stacky = from.varData.theStack->first; variableStack *stacky = from.varData.theStack->first;
while (stacky) { while (stacky) {
builder2 = joinStrings(builder, " "); builder2 = joinStrings(builder, " ");
if (!builder2) if (!builder2)
return NULL; return NULL;
delete builder; delete builder;
grabText = getTextFromAnyVar(stacky->thisVar); grabText = getTextFromAnyVar(stacky->thisVar);
builder = joinStrings(builder2, grabText); builder = joinStrings(builder2, grabText);
if (!builder) if (!builder)
return NULL; return NULL;
delete grabText; delete grabText;
grabText = NULL; grabText = NULL;
delete builder2; delete builder2;
builder2 = NULL; builder2 = NULL;
stacky = stacky->next; stacky = stacky->next;
}
return builder;
} }
return builder;
}
case SVT_INT: { case SVT_INT: {
char *buff = new char[10]; char *buff = new char[10];
if (!checkNew(buff)) if (!checkNew(buff))
return NULL; return NULL;
sprintf(buff, "%i", from.varData.intValue); sprintf(buff, "%i", from.varData.intValue);
return buff; return buff;
} }
case SVT_FILE: { case SVT_FILE: {
// char * buff = new char[15]; // char * buff = new char[15];
// if (! checkNew (buff)) return NULL; // if (! checkNew (buff)) return NULL;
// sprintf (buff, "FILE %i", from.varData.intValue); // sprintf (buff, "FILE %i", from.varData.intValue);
return joinStrings("", resourceNameFromNum(from.varData.intValue)); return joinStrings("", resourceNameFromNum(from.varData.intValue));
} }
/* case SVT_ANIM: /* case SVT_ANIM:
{ {
char * buff = new char[20]; char * buff = new char[20];
if (! checkNew (buff)) return NULL; if (! checkNew (buff)) return NULL;
sprintf (buff, "%p", from.varData.animHandler); sprintf (buff, "%p", from.varData.animHandler);
return buff; return buff;
}*/ }*/
case SVT_OBJTYPE: { case SVT_OBJTYPE: {
objectType *thisType = findObjectType(from.varData.intValue); objectType *thisType = findObjectType(from.varData.intValue);
if (thisType) if (thisType)
return copyString(thisType->screenName); return copyString(thisType->screenName);
} }
default: default:
break; break;
} }
return copyString(typeName[from.varType]); return copyString(typeName[from.varType]);
@ -432,23 +429,23 @@ char *getTextFromAnyVar(const variable &from) {
bool getBoolean(const variable &from) { bool getBoolean(const variable &from) {
switch (from.varType) { switch (from.varType) {
case SVT_NULL: case SVT_NULL:
return false; return false;
case SVT_INT: case SVT_INT:
return (bool) (from.varData.intValue != 0); return (bool)(from.varData.intValue != 0);
case SVT_STACK: case SVT_STACK:
return (bool) (from.varData.theStack->first != NULL); return (bool)(from.varData.theStack->first != NULL);
case SVT_STRING: case SVT_STRING:
return (bool) (from.varData.theString[0] != 0); return (bool)(from.varData.theString[0] != 0);
case SVT_FASTARRAY: case SVT_FASTARRAY:
return (bool) (from.varData.fastArray->size != 0); return (bool)(from.varData.fastArray->size != 0);
default: default:
break; break;
} }
return true; return true;
} }
@ -456,41 +453,41 @@ bool getBoolean(const variable &from) {
bool copyMain(const variable &from, variable &to) { bool copyMain(const variable &from, variable &to) {
to.varType = from.varType; to.varType = from.varType;
switch (to.varType) { switch (to.varType) {
case SVT_INT: case SVT_INT:
case SVT_FUNC: case SVT_FUNC:
case SVT_BUILT: case SVT_BUILT:
case SVT_FILE: case SVT_FILE:
case SVT_OBJTYPE: case SVT_OBJTYPE:
to.varData.intValue = from.varData.intValue; to.varData.intValue = from.varData.intValue;
return true; return true;
case SVT_FASTARRAY: case SVT_FASTARRAY:
to.varData.fastArray = from.varData.fastArray; to.varData.fastArray = from.varData.fastArray;
to.varData.fastArray->timesUsed++; to.varData.fastArray->timesUsed++;
return true; return true;
case SVT_STRING: case SVT_STRING:
to.varData.theString = copyString(from.varData.theString); to.varData.theString = copyString(from.varData.theString);
return to.varData.theString ? true : false; return to.varData.theString ? true : false;
case SVT_STACK: case SVT_STACK:
to.varData.theStack = from.varData.theStack; to.varData.theStack = from.varData.theStack;
to.varData.theStack->timesUsed++; to.varData.theStack->timesUsed++;
return true; return true;
case SVT_COSTUME: case SVT_COSTUME:
to.varData.costumeHandler = from.varData.costumeHandler; to.varData.costumeHandler = from.varData.costumeHandler;
return true; return true;
case SVT_ANIM: case SVT_ANIM:
to.varData.animHandler = copyAnim(from.varData.animHandler); to.varData.animHandler = copyAnim(from.varData.animHandler);
return true; return true;
case SVT_NULL: case SVT_NULL:
return true; return true;
default: default:
break; break;
} }
fatal("Unknown value type"); fatal("Unknown value type");
return false; return false;
@ -509,8 +506,7 @@ variable *fastArrayGetByIndex(fastArrayHandler *vS, unsigned int theIndex) {
bool makeFastArraySize(variable &to, int size) { bool makeFastArraySize(variable &to, int size) {
if (size < 0) if (size < 0)
return fatal( return fatal("Can't create a fast array with a negative number of elements!");
"Can't create a fast array with a negative number of elements!");
unlinkVar(to); unlinkVar(to);
to.varType = SVT_FASTARRAY; to.varType = SVT_FASTARRAY;
to.varData.fastArray = new fastArrayHandler; to.varData.fastArray = new fastArrayHandler;
@ -561,8 +557,7 @@ bool addVarToStack(const variable &va, variableStack *&thisStack) {
return false; return false;
newStack->next = thisStack; newStack->next = thisStack;
thisStack = newStack; thisStack = newStack;
debug(kSludgeDebugStackMachine, "Variable %s was added to stack", debug(kSludgeDebugStackMachine, "Variable %s was added to stack", getTextFromAnyVar(va));
getTextFromAnyVar(va));
return true; return true;
} }
@ -578,13 +573,11 @@ bool addVarToStackQuick(variable &va, variableStack *&thisStack) {
newStack->next = thisStack; newStack->next = thisStack;
thisStack = newStack; thisStack = newStack;
debug(kSludgeDebugStackMachine, "Variable %s was added to stack quick", debug(kSludgeDebugStackMachine, "Variable %s was added to stack quick", getTextFromAnyVar(va));
getTextFromAnyVar(va));
return true; return true;
} }
bool stackSetByIndex(variableStack *vS, unsigned int theIndex, bool stackSetByIndex(variableStack *vS, unsigned int theIndex, const variable &va) {
const variable &va) {
while (theIndex--) { while (theIndex--) {
vS = vS->next; vS = vS->next;
if (!vS) if (!vS)
@ -603,8 +596,7 @@ variable *stackGetByIndex(variableStack *vS, unsigned int theIndex) {
return &(vS->thisVar); return &(vS->thisVar);
} }
int deleteVarFromStack(const variable &va, variableStack *&thisStack, int deleteVarFromStack(const variable &va, variableStack *&thisStack, bool allOfEm) {
bool allOfEm) {
variableStack * * huntVar = &thisStack; variableStack * * huntVar = &thisStack;
variableStack *killMe; variableStack *killMe;
int reply = 0; int reply = 0;
@ -640,12 +632,8 @@ variableStack *stackFindLast(variableStack *hunt) {
bool getValueType(int &toHere, variableType vT, const variable &v) { bool getValueType(int &toHere, variableType vT, const variable &v) {
//if (! v) return false; //if (! v) return false;
if (v.varType != vT) { if (v.varType != vT) {
char *e1 = char *e1 = joinStrings("Can only perform specified operation on a value which is of type ", typeName[vT]);
joinStrings( char *e2 = joinStrings("... value supplied was of type ", typeName[v.varType]);
"Can only perform specified operation on a value which is of type ",
typeName[vT]);
char *e2 = joinStrings("... value supplied was of type ",
typeName[v.varType]);
fatal(e1, e2); fatal(e1, e2);
return false; return false;
@ -658,8 +646,7 @@ void trimStack(variableStack *&stack) {
variableStack *killMe = stack; variableStack *killMe = stack;
stack = stack->next; stack = stack->next;
debug(kSludgeDebugStackMachine, "Variable %s was removed from stack", debug(kSludgeDebugStackMachine, "Variable %s was removed from stack", getTextFromAnyVar(killMe->thisVar));
getTextFromAnyVar(killMe->thisVar));
// When calling this, we've ALWAYS checked that stack != NULL // When calling this, we've ALWAYS checked that stack != NULL
unlinkVar(killMe->thisVar); unlinkVar(killMe->thisVar);

View File

@ -74,8 +74,7 @@ bool getStream(DWORD type, timStream &intoHere) {
if (AVIFileGetStream(pAviFile, &intoHere.got, type, 0)) { if (AVIFileGetStream(pAviFile, &intoHere.got, type, 0)) {
intoHere.got = NULL; intoHere.got = NULL;
return true; return true;
} else if (AVIStreamInfo(intoHere.got, &intoHere.info, } else if (AVIStreamInfo(intoHere.got, &intoHere.info, sizeof(AVISTREAMINFO))) {
sizeof(AVISTREAMINFO))) {
return fatal("Can't get stream info"); return fatal("Can't get stream info");
} else if (AVIStreamReadFormat(intoHere.got, AVIStreamStart(intoHere.got), } else if (AVIStreamReadFormat(intoHere.got, AVIStreamStart(intoHere.got),
NULL, &intoHere.chunkSize)) { NULL, &intoHere.chunkSize)) {
@ -87,9 +86,7 @@ bool getStream(DWORD type, timStream &intoHere) {
if (!intoHere.chunk) { if (!intoHere.chunk) {
return fatal("Out of memory"); return fatal("Out of memory");
} else if (AVIStreamReadFormat(intoHere.got, } else if (AVIStreamReadFormat(intoHere.got, AVIStreamStart(intoHere.got), intoHere.chunk, &intoHere.chunkSize)) {
AVIStreamStart(intoHere.got), intoHere.chunk,
&intoHere.chunkSize)) {
return fatal("Couldn't read stream format"); return fatal("Couldn't read stream format");
} }
} }
@ -231,14 +228,13 @@ return true;
} }
bool nextVideoFrame() { bool nextVideoFrame() {
LPBITMAPINFOHEADER lpbi = (LPBITMAPINFOHEADER) AVIStreamGetFrame(pgf, LPBITMAPINFOHEADER lpbi = (LPBITMAPINFOHEADER)AVIStreamGetFrame(pgf, videoFrameNum);
videoFrameNum);
if (!lpbi) { if (!lpbi) {
finishVideo(); finishVideo();
return false; return false;
} }
BYTE *pData = (((BYTE *) lpbi) + lpbi->biSize); BYTE *pData = (((BYTE *)lpbi) + lpbi->biSize);
int xOff = (winWidth - vidWidth) >> 1; int xOff = (winWidth - vidWidth) >> 1;
int yOff = (winHeight + vidHeight) >> 1; int yOff = (winHeight + vidHeight) >> 1;
@ -249,22 +245,20 @@ for (int y = 0; y < vidHeight; y++) {
unsigned short int *toHere = startingPoint; unsigned short int *toHere = startingPoint;
for (int x = 0; x < vidWidth; x++) { for (int x = 0; x < vidWidth; x++) {
switch (vidBytesPerPixel) { switch (vidBytesPerPixel) {
case 1: case 1:
(*toHere) = makeGrey(*pData); (*toHere) = makeGrey(*pData);
break; break;
case 3: case 3:
case 4: case 4:
(*toHere) = makeColour(*(pData + 2), *(pData + 1), *pData); (*toHere) = makeColour(*(pData + 2), *(pData + 1), *pData);
break; break;
default: { default: {
WORD Pixel16 = *((WORD *) pData); WORD Pixel16 = *((WORD *)pData);
(*toHere) = makeColour((((UINT)(Pixel16) >> 10) & 0x1F) << 3, (*toHere) = makeColour((((UINT)(Pixel16) >> 10) & 0x1F) << 3, (((UINT)(Pixel16) >> 5) & 0x1F) << 3, (((UINT)(Pixel16) >> 0) & 0x1F) << 3);
(((UINT)(Pixel16) >> 5) & 0x1F) << 3, }
(((UINT)(Pixel16) >> 0) & 0x1F) << 3); break;
}
break;
} }
pData += vidBytesPerPixel; pData += vidBytesPerPixel;
toHere++; toHere++;

View File

@ -75,133 +75,140 @@ bool setZBuffer(int y) {
setResourceForFatal(y); setResourceForFatal(y);
zBuffer.originalNum = y; zBuffer.originalNum = y;
if (! openFileFromNum(y)) return false; if (!openFileFromNum(y))
if (fgetc(bigDataFile) != 'S') return fatal("Not a Z-buffer file"); return false;
if (fgetc(bigDataFile) != 'z') return fatal("Not a Z-buffer file"); if (bigDataFile->readByte() != 'S')
if (fgetc(bigDataFile) != 'b') return fatal("Not a Z-buffer file"); return fatal("Not a Z-buffer file");
if (bigDataFile->readByte() != 'z')
return fatal("Not a Z-buffer file");
if (bigDataFile->readByte() != 'b')
return fatal("Not a Z-buffer file");
switch (fgetc(bigDataFile)) { switch (bigDataFile->readByte()) {
case 0: case 0:
zBuffer.width = 640; zBuffer.width = 640;
zBuffer.height = 480; zBuffer.height = 480;
break; break;
case 1: case 1:
zBuffer.width = bigDataFile->readUint16BE(); zBuffer.width = bigDataFile->readUint16BE();
zBuffer.height = bigDataFile->readUint16BE(); zBuffer.height = bigDataFile->readUint16BE();
break; break;
default: default:
return fatal("Extended Z-buffer format not supported in this version of the SLUDGE engine"); return fatal("Extended Z-buffer format not supported in this version of the SLUDGE engine");
} }
if (zBuffer.width != sceneWidth || zBuffer.height != sceneHeight) { if (zBuffer.width != sceneWidth || zBuffer.height != sceneHeight) {
char tmp[256]; char tmp[256];
sprintf(tmp, "Z-w: %d Z-h:%d w: %d, h:%d", zBuffer.width, zBuffer.height, sceneWidth, sceneHeight); sprintf(tmp, "Z-w: %d Z-h:%d w: %d, h:%d", zBuffer.width, zBuffer.height, sceneWidth, sceneHeight);
return fatal("Z-buffer width and height don't match scene width and height", tmp); return fatal("Z-buffer width and height don't match scene width and height", tmp);
} }
zBuffer.numPanels = fgetc(bigDataFile); zBuffer.numPanels = bigDataFile->readByte();
for (y = 0; y < zBuffer.numPanels; y ++) { for (y = 0; y < zBuffer.numPanels; y++) {
yPalette[y] = bigDataFile->readUint16BE(); yPalette[y] = bigDataFile->readUint16BE();
} }
sortZPal(yPalette, sorted, zBuffer.numPanels); sortZPal(yPalette, sorted, zBuffer.numPanels);
for (y = 0; y < zBuffer.numPanels; y ++) { for (y = 0; y < zBuffer.numPanels; y++) {
zBuffer.panel[y] = yPalette[sorted[y]]; zBuffer.panel[y] = yPalette[sorted[y]];
sortback[sorted[y]] = y; sortback[sorted[y]] = y;
} }
int picWidth = sceneWidth; int picWidth = sceneWidth;
int picHeight = sceneHeight; int picHeight = sceneHeight;
if (! NPOT_textures) { if (!NPOT_textures) {
picWidth = getNextPOT(picWidth); picWidth = getNextPOT(picWidth);
picHeight = getNextPOT(picHeight); picHeight = getNextPOT(picHeight);
} }
zBuffer.tex = new GLubyte [picHeight * picWidth]; zBuffer.tex = new GLubyte[picHeight * picWidth];
if (! checkNew(zBuffer.tex)) return false; if (!checkNew(zBuffer.tex))
return false;
for (y = 0; y < sceneHeight; y ++) { for (y = 0; y < sceneHeight; y++) {
for (x = 0; x < sceneWidth; x ++) { for (x = 0; x < sceneWidth; x++) {
if (stillToGo == 0) { if (stillToGo == 0) {
n = fgetc(bigDataFile); n = bigDataFile->readByte();
stillToGo = n >> 4; stillToGo = n >> 4;
if (stillToGo == 15) stillToGo = bigDataFile->readUint16BE() + 16l; if (stillToGo == 15)
else stillToGo ++; stillToGo = bigDataFile->readUint16BE() + 16l;
n &= 15; else
stillToGo++;
n &= 15;
}
zBuffer.tex[y * picWidth + x] = sortback[n] * 16;
stillToGo--;
} }
zBuffer.tex[y * picWidth + x] = sortback[n] * 16;
stillToGo --;
} }
} finishAccess();
finishAccess();
#endif #endif
setResourceForFatal(-1); setResourceForFatal(-1);
#if 0 #if 0
if (! zBuffer.texName) glGenTextures(1, &zBuffer.texName); if (! zBuffer.texName) glGenTextures(1, &zBuffer.texName);
glBindTexture(GL_TEXTURE_2D, zBuffer.texName); glBindTexture(GL_TEXTURE_2D, zBuffer.texName);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
texImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, picWidth, picHeight, 0, GL_ALPHA, GL_UNSIGNED_BYTE, zBuffer.tex, zBuffer.texName); texImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, picWidth, picHeight, 0, GL_ALPHA, GL_UNSIGNED_BYTE, zBuffer.tex, zBuffer.texName);
#endif #endif
return true; return true;
}
void drawZBuffer(int x, int y, bool upsidedown) {
int i;
#if 0
if (! zBuffer.tex) return;
glEnable(GL_DEPTH_TEST);
glEnable(GL_BLEND);
glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE);
glDepthMask(GL_TRUE);
glUseProgram(shader.texture);
setPMVMatrix(shader.texture);
//glTexEnvf (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
glBindTexture(GL_TEXTURE_2D, zBuffer.texName);
setPrimaryColor(1.0, 1.0, 1.0, 1.0);
for (i = 1; i < zBuffer.numPanels; i++) {
GLfloat z = 1.0 - (double) i * (1.0 / 128.0);
GLfloat vy1 = -y, vy2 = zBuffer.height - y;
if (upsidedown) {
vy1 += zBuffer.height;
vy2 -= zBuffer.height;
}
const GLfloat vertices[] = {
(GLfloat) - x, vy1, z,
(GLfloat)zBuffer.width - x, vy1, z,
(GLfloat) - x, vy2, z,
(GLfloat)zBuffer.width - x, vy2, z
};
const GLfloat texCoords[] = {
0.0f, 0.0f,
backdropTexW, 0.0f,
0.0f, backdropTexH,
backdropTexW, backdropTexH
};
glUniform1i(glGetUniformLocation(shader.texture, "zBuffer"), 1);
glUniform1f(glGetUniformLocation(shader.texture, "zBufferLayer"), i);
drawQuad(shader.texture, vertices, 1, texCoords);
glUniform1i(glGetUniformLocation(shader.texture, "zBuffer"), 0);
} }
glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); void drawZBuffer(int x, int y, bool upsidedown) {
glDepthMask(GL_FALSE); int i;
glDisable(GL_BLEND); #if 0
glUseProgram(0); if (! zBuffer.tex) return;
#endif
}
} // End of namespace Sludge glEnable(GL_DEPTH_TEST);
glEnable(GL_BLEND);
glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE);
glDepthMask(GL_TRUE);
glUseProgram(shader.texture);
setPMVMatrix(shader.texture);
//glTexEnvf (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
glBindTexture(GL_TEXTURE_2D, zBuffer.texName);
setPrimaryColor(1.0, 1.0, 1.0, 1.0);
for (i = 1; i < zBuffer.numPanels; i++) {
GLfloat z = 1.0 - (double) i * (1.0 / 128.0);
GLfloat vy1 = -y, vy2 = zBuffer.height - y;
if (upsidedown) {
vy1 += zBuffer.height;
vy2 -= zBuffer.height;
}
const GLfloat vertices[] = {
(GLfloat) - x, vy1, z,
(GLfloat)zBuffer.width - x, vy1, z,
(GLfloat) - x, vy2, z,
(GLfloat)zBuffer.width - x, vy2, z
};
const GLfloat texCoords[] = {
0.0f, 0.0f,
backdropTexW, 0.0f,
0.0f, backdropTexH,
backdropTexW, backdropTexH
};
glUniform1i(glGetUniformLocation(shader.texture, "zBuffer"), 1);
glUniform1f(glGetUniformLocation(shader.texture, "zBufferLayer"), i);
drawQuad(shader.texture, vertices, 1, texCoords);
glUniform1i(glGetUniformLocation(shader.texture, "zBuffer"), 0);
}
glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
glDepthMask(GL_FALSE);
glDisable(GL_BLEND);
glUseProgram(0);
#endif
}
} // End of namespace Sludge