[Scummvm-git-logs] scummvm master -> 1659ab6ad3b245a6ec53dd44d244aa47ce4c5fa5
Strangerke
noreply at scummvm.org
Thu May 29 23:14:39 UTC 2025
This automated email contains information about 2 new commits which have been
pushed to the 'scummvm' repo located at https://api.github.com/repos/scummvm/scummvm .
Summary:
ed9c78d778 M4: Some cleanup in ws_load ad ws_crunch
1659ab6ad3 M4: Some cleanup in ws_machine
Commit: ed9c78d778f36ea9062f46ab75f8089da856e73c
https://github.com/scummvm/scummvm/commit/ed9c78d778f36ea9062f46ab75f8089da856e73c
Author: Strangerke (arnaud.boutonne at gmail.com)
Date: 2025-05-29T23:52:20+01:00
Commit Message:
M4: Some cleanup in ws_load ad ws_crunch
Changed paths:
engines/m4/wscript/ws_cruncher.cpp
engines/m4/wscript/ws_load.cpp
diff --git a/engines/m4/wscript/ws_cruncher.cpp b/engines/m4/wscript/ws_cruncher.cpp
index 342303d21ea..33e856a6930 100644
--- a/engines/m4/wscript/ws_cruncher.cpp
+++ b/engines/m4/wscript/ws_cruncher.cpp
@@ -156,10 +156,8 @@ bool ws_InitCruncher(void) {
}
void ws_KillCruncher() {
- Anim8 *myAnim8;
-
if (_GWS(cruncherInitialized)) {
- myAnim8 = _GWS(myCruncher)->firstAnim8ToCrunch;
+ Anim8 *myAnim8 = _GWS(myCruncher)->firstAnim8ToCrunch;
while (myAnim8) {
_GWS(myCruncher)->firstAnim8ToCrunch = myAnim8->next;
if (myAnim8->myCCB) {
@@ -179,9 +177,8 @@ void ws_KillCruncher() {
Anim8 *ws_AddAnim8ToCruncher(machine *m, int32 sequHash) {
Anim8 *myAnim8;
- frac16 *myRegs;
+ frac16 *my_regs;
int32 numLocalVars;
- int32 i;
// Make sure the cruncher has been initialized
VERIFY_INTIALIZED("ws_AddAnim8ToCruncher()");
@@ -198,7 +195,7 @@ Anim8 *ws_AddAnim8ToCruncher(machine *m, int32 sequHash) {
}
// Allocate an array of registers
- if ((myRegs = (frac16 *)mem_alloc(sizeof(frac16) * (IDX_COUNT + numLocalVars), "Anim8 regs")) == nullptr) {
+ if ((my_regs = (frac16 *)mem_alloc(sizeof(frac16) * (IDX_COUNT + numLocalVars), "Anim8 regs")) == nullptr) {
ws_LogErrorMsg(FL, "Out of memory - mem requested: %d.", sizeof(frac16) * (IDX_COUNT + numLocalVars));
return nullptr;
}
@@ -217,7 +214,7 @@ Anim8 *ws_AddAnim8ToCruncher(machine *m, int32 sequHash) {
myAnim8->switchTime = 0;
myAnim8->flags = 0;
myAnim8->numLocalVars = numLocalVars;
- myAnim8->myRegs = myRegs;
+ myAnim8->myRegs = my_regs;
myAnim8->returnStackIndex = 0;
// Link it into the execution list
@@ -242,7 +239,7 @@ Anim8 *ws_AddAnim8ToCruncher(machine *m, int32 sequHash) {
_GWS(myCruncher)->frontLayerAnim8 = myAnim8;
// Now clear the registers, but set the scale = 100%
- for (i = 0; i < IDX_COUNT + numLocalVars; i++) {
+ for (int32 i = 0; i < IDX_COUNT + numLocalVars; i++) {
myAnim8->myRegs[i] = 0;
}
myAnim8->myRegs[IDX_S] = 0x10000;
@@ -252,7 +249,6 @@ Anim8 *ws_AddAnim8ToCruncher(machine *m, int32 sequHash) {
}
bool ws_ChangeAnim8Program(machine *m, int32 newSequHash) {
- Anim8 *myAnim8;
int32 numLocalVars;
// Make sure the cruncher has been initialized
@@ -263,7 +259,7 @@ bool ws_ChangeAnim8Program(machine *m, int32 newSequHash) {
error_show(FL, 'WSMI');
}
- myAnim8 = m->myAnim8;
+ Anim8 *myAnim8 = m->myAnim8;
// Find the sequence
if ((myAnim8->sequHandle = ws_GetSEQU((uint32)newSequHash, &numLocalVars, &myAnim8->pcOffset)) == nullptr) {
@@ -287,8 +283,6 @@ bool ws_ChangeAnim8Program(machine *m, int32 newSequHash) {
}
void ws_RemoveAnim8FromCruncher(Anim8 *myAnim8) {
- EOSreq *tempEOSreq;
-
// Make sure the cruncher has been initialized
VERIFY_INTIALIZED("ws_RemoveAnim8FromCruncher()");
@@ -296,7 +290,7 @@ void ws_RemoveAnim8FromCruncher(Anim8 *myAnim8) {
error_show(FL, 'WSAI');
// In case we are crunching the current list of EOS requests, remove any for this machine
- tempEOSreq = _GWS(EOSreqList);
+ EOSreq *tempEOSreq = _GWS(EOSreqList);
while (tempEOSreq && (tempEOSreq->myAnim8 != myAnim8)) {
tempEOSreq = tempEOSreq->next;
}
@@ -493,28 +487,27 @@ static bool ExtractArg(Anim8 *myAnim8, int32 myFormat, int32 myData, frac16 **ar
}
int32 ws_PreProcessPcode(uint32 **PC, Anim8 *myAnim8) {
- int32 myInstruction, myFormat, myData; // myIndex;
- uint32 *myPC, opCode, word2;
+ uint32 word2;
if (!PC) {
ws_LogErrorMsg(FL, "INTERNAL ERROR - ws_PreProcessPcode() failed - An invalid PC was passed.");
return -1;
}
- myPC = *PC;
+ uint32 *myPC = *PC;
// Get the opCode
- opCode = FROM_LE_32(*myPC++);
+ uint32 opCode = FROM_LE_32(*myPC++);
// Get the instruction number
- myInstruction = (opCode & OP_INSTR) >> 25;
+ int32 myInstruction = (opCode & OP_INSTR) >> 25;
dbg_AddOpcodeToMachineInstr(myInstruction);
// Get the format for the first arg
- myFormat = (opCode & OP_FORMAT1) >> 22;
+ int32 myFormat = (opCode & OP_FORMAT1) >> 22;
// Get the data for the first arg
- myData = opCode & OP_LOW_DATA;
+ int32 myData = opCode & OP_LOW_DATA;
// Verify we have an argument
if (myFormat) {
@@ -569,10 +562,8 @@ static void op_END(Anim8 *myAnim8) {
}
static void op_CLEAR(Anim8 *myAnim8) {
- int32 i;
-
// Now clear the registers, but set the scale = 100%
- for (i = 0; i <= IDX_COUNT + myAnim8->numLocalVars; i++) {
+ for (int32 i = 0; i <= IDX_COUNT + myAnim8->numLocalVars; i++) {
myAnim8->myRegs[i] = 0;
}
myAnim8->myRegs[IDX_S] = 0x10000;
@@ -849,12 +840,11 @@ static void op_POINT(Anim8 *myAnim8) {
}
static void op_DIST2D(Anim8 *myAnim8) {
- int32 temp1, temp2;
if (!_GWS(myArg3)) {
ws_Error(myAnim8->myMachine, ERR_SEQU, 0x0252, "functionality: arg1 = distance from (x, y) to (arg2, arg3)");
}
- temp1 = (int32)(imath_abs(*_GWS(myArg2) - myAnim8->myRegs[IDX_X]));
- temp2 = (int32)(imath_abs(*_GWS(myArg3) - myAnim8->myRegs[IDX_Y]));
+ int32 temp1 = (int32)(imath_abs(*_GWS(myArg2) - myAnim8->myRegs[IDX_X]));
+ int32 temp2 = (int32)(imath_abs(*_GWS(myArg3) - myAnim8->myRegs[IDX_Y]));
if ((temp1 >= 0x800000) || (temp2 >= 0x800000)) {
temp1 >>= 16;
temp2 >>= 16;
@@ -886,12 +876,10 @@ static void op_CRUNCH(Anim8 *myAnim8) {
}
static void op_BRANCH(Anim8 *myAnim8) {
- int32 myOffset;
-
if (!_GWS(myArg2)) {
ws_Error(myAnim8->myMachine, ERR_SEQU, 0x0251, "check the CCR, arg1 is the branch type, arg2 is the PC offset");
}
- myOffset = *_GWS(myArg2) >> 14;
+ int32 myOffset = *_GWS(myArg2) >> 14;
switch (*_GWS(myArg1) >> 16) {
case BRANCH_BR:
myAnim8->pcOffset += myOffset;
@@ -919,8 +907,6 @@ static void op_BRANCH(Anim8 *myAnim8) {
static void op_SETCEL(Anim8 *myAnim8) {
int32 myIndex;
- CCB *myCCB;
- frac16 *myRegs;
if (!_GWS(myArg2)) {
ws_Error(myAnim8->myMachine, ERR_SEQU, 0x0251, "setcel(arg1, arg2) or setcel(arg1, rand(arg2, arg3))");
@@ -944,7 +930,7 @@ static void op_SETCEL(Anim8 *myAnim8) {
}
}
- myCCB = myAnim8->myCCB;
+ CCB *myCCB = myAnim8->myCCB;
if (myCCB->flags & CCB_DISC_STREAM) {
ws_CloseSSstream(myCCB);
}
@@ -953,7 +939,7 @@ static void op_SETCEL(Anim8 *myAnim8) {
if ((myAnim8->myCCB = GetWSAssetCEL((uint32)(*_GWS(myArg1)) >> 24, (uint32)myIndex, myCCB)) == nullptr) {
ws_Error(myAnim8->myMachine, ERR_SEQU, 0x025b, "setcel() failed.");
}
- myRegs = myAnim8->myRegs;
+ frac16 *myRegs = myAnim8->myRegs;
if (myRegs[IDX_W] < 0) {
myRegs[IDX_W] = -myCCB->source->w << 16;
} else {
@@ -1238,8 +1224,6 @@ static void op_SET_DATA(Anim8 *myAnim8) {
}
static void op_OPEN_STREAM_SS(Anim8 *myAnim8) {
- CCB *myCCB;
-
if (!_GWS(myArg1)) {
ws_Error(myAnim8->myMachine, ERR_SEQU, 0x0250, "functionality: stream_series(arg1)");
}
@@ -1255,7 +1239,7 @@ static void op_OPEN_STREAM_SS(Anim8 *myAnim8) {
}
}
- myCCB = myAnim8->myCCB;
+ CCB *myCCB = myAnim8->myCCB;
ShowCCB(myCCB);
myCCB->flags |= CCB_SKIP;
@@ -1273,11 +1257,10 @@ static void op_OPEN_STREAM_SS(Anim8 *myAnim8) {
}
static void op_NEXT_STREAM_SS(Anim8 *myAnim8) {
- CCB *myCCB;
if (!myAnim8->myCCB) {
ws_Error(myAnim8->myMachine, ERR_SEQU, 0x0253, "next_ss_stream() failed.");
}
- myCCB = myAnim8->myCCB;
+ CCB *myCCB = myAnim8->myCCB;
myCCB->flags |= CCB_SKIP;
if (!ws_GetNextSSstreamCel(myAnim8)) {
ws_Error(myAnim8->myMachine, ERR_SEQU, 0x0259, "next_ss_stream() failed.");
@@ -1292,11 +1275,10 @@ static void op_NEXT_STREAM_SS(Anim8 *myAnim8) {
}
static void op_CLOSE_STREAM_SS(Anim8 *myAnim8) {
- CCB *myCCB;
if (!myAnim8->myCCB) {
ws_Error(myAnim8->myMachine, ERR_SEQU, 0x02f3, "close_ss_stream() failed.");
}
- myCCB = myAnim8->myCCB;
+ CCB *myCCB = myAnim8->myCCB;
ws_CloseSSstream(myCCB);
HideCCB(myCCB);
}
@@ -1349,16 +1331,12 @@ void (*pCodeJmpTable[])(Anim8 *myAnim8) = {
// The guts of the engine. This proc executes an anim8s program.
bool CrunchAnim8(Anim8 *myAnim8) {
bool moveTheCel = false;
- frac16 timeElapsed, percentDist;
- int32 tempAngle;
- frac16 oldX, oldY, oldS;
- int32 oldW, oldH, oldR;
+ frac16 percentDist;
int32 myInstruction;
- frac16 *myRegs;
- uint32 *myPC, *oldPC;
+ uint32 *myPC;
// Get the register set for myAnim8
- myRegs = myAnim8->myRegs;
+ frac16 *myRegs = myAnim8->myRegs;
// Initialize the globals (flags, mostly) used in processing op codes
_GWS(keepProcessing) = false;
@@ -1367,12 +1345,12 @@ bool CrunchAnim8(Anim8 *myAnim8) {
_GWS(compareCCR) = 0;
//store the old values, so we can tell if we need to remap the Sprite
- oldX = myRegs[IDX_X];
- oldY = myRegs[IDX_Y];
- oldS = myRegs[IDX_S];
- oldW = myRegs[IDX_W] >> 16;
- oldH = myRegs[IDX_H] >> 16;
- oldR = myRegs[IDX_R] >> 16;
+ frac16 oldX = myRegs[IDX_X];
+ frac16 oldY = myRegs[IDX_Y];
+ frac16 oldS = myRegs[IDX_S];
+ int32 oldW = myRegs[IDX_W] >> 16;
+ int32 oldH = myRegs[IDX_H] >> 16;
+ int32 oldR = myRegs[IDX_R] >> 16;
// Check to see if we are still in an execution loop, or if it is time to
// Interpret further instructions
@@ -1388,7 +1366,7 @@ bool CrunchAnim8(Anim8 *myAnim8) {
dbg_SetCurrSequInstr(myAnim8, _GWS(compareCCR));
myPC = (uint32 *)((intptr)*(myAnim8->sequHandle) + myAnim8->pcOffset);
- oldPC = myPC;
+ uint32 *oldPC = myPC;
_GWS(pcOffsetOld) = myAnim8->pcOffset;
dbg_SetCurrMachInstr(myAnim8->myMachine, myAnim8->pcOffset, true);
@@ -1421,7 +1399,7 @@ bool CrunchAnim8(Anim8 *myAnim8) {
}
if (myAnim8->flags) {
- timeElapsed = (_GWS(ws_globals)[GLB_TIME] - myAnim8->startTime) << 16;
+ frac16 timeElapsed = (_GWS(ws_globals)[GLB_TIME] - myAnim8->startTime) << 16;
// This must be checked before TAG_TARGS because a bez path can use a target scale and rotate
// And we don't want to accidentally set up a target x or y.
@@ -1466,7 +1444,7 @@ bool CrunchAnim8(Anim8 *myAnim8) {
myAnim8->start_s = myRegs[IDX_S];
myAnim8->start_r = myRegs[IDX_R];
}
- tempAngle = (myRegs[IDX_THETA] >> 16) & 0xff;
+ int32 tempAngle = (myRegs[IDX_THETA] >> 16) & 0xff;
myRegs[IDX_DELTA_X] = MulSF16(myRegs[IDX_VELOCITY], sinTable[tempAngle]);
myRegs[IDX_DELTA_Y] = MulSF16(myRegs[IDX_VELOCITY], -(int)cosTable[tempAngle]);
myAnim8->flags |= (TAG_DELTAS << 16);
@@ -1525,7 +1503,6 @@ bool CrunchAnim8(Anim8 *myAnim8) {
}
void ws_CrunchAnim8s(int16 *depth_table) {
- Anim8 *currAnim8;
EOSreq *tempEOSreq;
// Make sure the cruncher has been initialized
@@ -1535,7 +1512,7 @@ void ws_CrunchAnim8s(int16 *depth_table) {
_GWS(myDepthTable) = depth_table;
_GWS(crunchNext) = nullptr;
- currAnim8 = _GWS(myCruncher)->firstAnim8ToCrunch;
+ Anim8 *currAnim8 = _GWS(myCruncher)->firstAnim8ToCrunch;
while (currAnim8) {
_GWS(crunchNext) = currAnim8->next;
if (currAnim8->active) {
@@ -1563,23 +1540,19 @@ void ws_CrunchAnim8s(int16 *depth_table) {
}
void ws_CrunchEOSreqs(void) {
- int32 pcOffset, pcCount;
- machine *myXM;
- EOSreq *tempEOSreq;
-
// Make sure the cruncher has been initialized
VERIFY_INTIALIZED("ws_CrunchEOSreqs()");
// Loop through, and handle all the eos requests
- tempEOSreq = _GWS(EOSreqList);
+ EOSreq *tempEOSreq = _GWS(EOSreqList);
while (tempEOSreq) {
_GWS(EOSreqList) = _GWS(EOSreqList)->next;
if (_GWS(EOSreqList)) {
_GWS(EOSreqList)->prev = nullptr;
}
- pcOffset = tempEOSreq->myAnim8->eosReqOffset;
- pcCount = tempEOSreq->myAnim8->eosReqCount;
- myXM = tempEOSreq->myAnim8->myMachine;
+ int32 pcOffset = tempEOSreq->myAnim8->eosReqOffset;
+ int32 pcCount = tempEOSreq->myAnim8->eosReqCount;
+ machine *myXM = tempEOSreq->myAnim8->myMachine;
tempEOSreq->myAnim8->eosReqOffset = -1;
mem_free_to_stash((void *)tempEOSreq, _GWS(memtypeEOS));
ws_StepWhile(myXM, pcOffset, pcCount);
diff --git a/engines/m4/wscript/ws_load.cpp b/engines/m4/wscript/ws_load.cpp
index 0556077d6f3..ef7781450a6 100644
--- a/engines/m4/wscript/ws_load.cpp
+++ b/engines/m4/wscript/ws_load.cpp
@@ -278,10 +278,9 @@ bool LoadWSAssets(const char *wsAssetName) {
bool LoadWSAssets(const char *wsAssetName, RGB8 *myPalette) {
MemHandle workHandle;
- char *mainAssetPtr, *parseAssetPtr, *endOfAssetBlock;
+ char *parseAssetPtr;
uint32 *tempPtr;
IntPointer chunkType, chunkSize, chunkHash;
- bool finished, chunkSwap;
int32 *celsPtr, *palPtr;
int32 i;
int32 assetSize;
@@ -298,14 +297,14 @@ bool LoadWSAssets(const char *wsAssetName, RGB8 *myPalette) {
// Lock the handle so we can step through the chunk
HLock(workHandle);
- mainAssetPtr = (char *)(*workHandle);
+ char *mainAssetPtr = (char *)(*workHandle);
- endOfAssetBlock = (char *)((intptr)mainAssetPtr + assetSize);
+ char *endOfAssetBlock = (char *)((intptr)mainAssetPtr + assetSize);
parseAssetPtr = mainAssetPtr;
// Set the finished flag
- finished = false;
+ bool finished = false;
// Get the first chunkType
if (!GetNextint32(&parseAssetPtr, endOfAssetBlock, chunkType)) {
@@ -323,7 +322,7 @@ bool LoadWSAssets(const char *wsAssetName, RGB8 *myPalette) {
}
// Process the chunk according to type
- chunkSwap = false;
+ bool chunkSwap = false;
switch (*chunkType) {
// Chunk is a machine chunk
case CHUNK_HCAM:
@@ -500,9 +499,6 @@ bool LoadWSAssets(const char *wsAssetName, RGB8 *myPalette) {
}
M4sprite *CreateSprite(MemHandle resourceHandle, int32 handleOffset, int32 index, M4sprite *mySprite, bool *streamSeries) {
- uint32 *myCelSource, *data, *offsets, numCels;
- uint32 *celsPtr;
-
// Parameter verification
if ((!resourceHandle) || (!*resourceHandle)) {
ws_LogErrorMsg(FL, "No sprite source in memory.");
@@ -519,21 +515,21 @@ M4sprite *CreateSprite(MemHandle resourceHandle, int32 handleOffset, int32 index
// Find the cels source from the asset block
HLock(resourceHandle);
- celsPtr = (uint32 *)((intptr)*resourceHandle + handleOffset);
+ uint32 *celsPtr = (uint32 *)((intptr)*resourceHandle + handleOffset);
// Check that the index into the series requested is within a valid range
- numCels = FROM_LE_32(celsPtr[CELS_COUNT]);
- if (index >= (int)numCels) {
+ uint32 numCels = FROM_LE_32(celsPtr[CELS_COUNT]);
+ if (index >= (int32)numCels) {
ws_LogErrorMsg(FL, "CreateSprite: Sprite index out of range - max index: %d, requested index: %d", numCels - 1, index);
return nullptr;
}
// Find the offset table, and the beginning of the data for all sprites
- offsets = &celsPtr[CELS_OFFSETS];
- data = &celsPtr[CELS_OFFSETS + numCels];
+ uint32 *offsets = &celsPtr[CELS_OFFSETS];
+ uint32 *data = &celsPtr[CELS_OFFSETS + numCels];
// Find the sprite data for the specific sprite in the series
- myCelSource = (uint32 *)((intptr)data + FROM_LE_32(offsets[index]));
+ uint32 *myCelSource = (uint32 *)((intptr)data + FROM_LE_32(offsets[index]));
// Set the stream boolean
if (streamSeries) {
@@ -571,7 +567,7 @@ M4sprite *CreateSprite(MemHandle resourceHandle, int32 handleOffset, int32 index
int32 LoadSpriteSeries(const char *assetName, MemHandle *seriesHandle, int32 *celsOffset, int32 *palOffset, RGB8 *myPalette) {
MemHandle workHandle;
int32 celsSize, *celsPtr, *palPtr;
- char *mainAssetPtr, *endOfAssetBlock, *parseAssetPtr;
+ char *parseAssetPtr;
int32 assetSize;
// This loads a sprite series into the provided vars, rather than the WS tables.
@@ -583,8 +579,8 @@ int32 LoadSpriteSeries(const char *assetName, MemHandle *seriesHandle, int32 *ce
HLock(workHandle);
- mainAssetPtr = (char *)*workHandle;
- endOfAssetBlock = (char *)((intptr)mainAssetPtr + assetSize);
+ char *mainAssetPtr = (char *)*workHandle;
+ char *endOfAssetBlock = (char *)((intptr)mainAssetPtr + assetSize);
parseAssetPtr = mainAssetPtr;
// Process the SS from the stream file
@@ -603,11 +599,9 @@ int32 LoadSpriteSeries(const char *assetName, MemHandle *seriesHandle, int32 *ce
}
int32 LoadSpriteSeriesDirect(const char *assetName, MemHandle *seriesHandle, int32 *celsOffset, int32 *palOffset, RGB8 *myPalette) {
- MemHandle workHandle;
Common::File f;
int32 celsSize, *celsPtr, *palPtr;
- char *mainAssetPtr, *endOfAssetBlock, *parseAssetPtr;
- uint32 assetSize;
+ char *parseAssetPtr;
// This loads a sprite series into the provided vars, rather than the WS tables.
// The WS loader is not involved with this procedure.
@@ -617,14 +611,14 @@ int32 LoadSpriteSeriesDirect(const char *assetName, MemHandle *seriesHandle, int
return -1;
// Get the file size
- assetSize = f.size();
+ uint32 assetSize = f.size();
// Create a handle big enough to hold the contents of the file
- workHandle = NewHandle(assetSize, "ss file");
+ MemHandle workHandle = NewHandle(assetSize, "ss file");
// Lock the handle and read the contents of the file intoit
HLock(workHandle);
- mainAssetPtr = (char *)*workHandle;
+ char *mainAssetPtr = (char *)*workHandle;
if (f.read(mainAssetPtr, assetSize) < assetSize) {
mem_free(workHandle);
return -1;
@@ -634,7 +628,7 @@ int32 LoadSpriteSeriesDirect(const char *assetName, MemHandle *seriesHandle, int
f.close();
// Set up some pointers
- endOfAssetBlock = (char *)((intptr)mainAssetPtr + assetSize);
+ char *endOfAssetBlock = (char *)((intptr)mainAssetPtr + assetSize);
parseAssetPtr = mainAssetPtr;
// Process the SS from the stream file
@@ -652,8 +646,6 @@ int32 LoadSpriteSeriesDirect(const char *assetName, MemHandle *seriesHandle, int
}
bool ws_GetSSMaxWH(MemHandle ssHandle, int32 ssOffset, int32 *maxW, int32 *maxH) {
- int32 *celsPtr;
-
// Parameter verification
if ((!ssHandle) || (!*ssHandle)) {
ws_LogErrorMsg(FL, "nullptr Handle given.");
@@ -662,7 +654,7 @@ bool ws_GetSSMaxWH(MemHandle ssHandle, int32 ssOffset, int32 *maxW, int32 *maxH)
// Lock the handle, and get the cels source
HLock(ssHandle);
- celsPtr = (int32 *)((intptr)*ssHandle + ssOffset);
+ int32 *celsPtr = (int32 *)((intptr)*ssHandle + ssOffset);
// Return the values
if (maxW) {
@@ -681,15 +673,15 @@ bool ws_GetSSMaxWH(MemHandle ssHandle, int32 ssOffset, int32 *maxW, int32 *maxH)
int32 AddWSAssetCELS(const char *wsAssetName, int32 hash, RGB8 *myPalette) {
MemHandle workHandle;
- char *parseAssetPtr, *mainAssetPtr, *endOfAssetBlock;
- int32 emptySlot, i, assetSize, *celsPtr, *palPtr;
+ char *parseAssetPtr;
+ int32 i, assetSize, *celsPtr, *palPtr;
// Check that the loader has been initialized
if (!_GWS(wsloaderInitialized)) {
error_show(FL, 'WSLI', "Asset Name: %s", wsAssetName);
}
- emptySlot = -1;
+ int32 emptySlot = -1;
// If hash is < 0, find the first available slot
if (hash < 0) {
@@ -743,10 +735,10 @@ int32 AddWSAssetCELS(const char *wsAssetName, int32 hash, RGB8 *myPalette) {
// Lock the handle so we can step through the chunk
HLock(workHandle);
- mainAssetPtr = (char *)(*workHandle);
+ char *mainAssetPtr = (char *)(*workHandle);
parseAssetPtr = mainAssetPtr;
- endOfAssetBlock = (char *)((intptr)mainAssetPtr + assetSize);
+ char *endOfAssetBlock = (char *)((intptr)mainAssetPtr + assetSize);
ClearWSAssets(_WS_ASSET_CELS, emptySlot, emptySlot);
@@ -776,7 +768,9 @@ int32 AddWSAssetCELS(const char *wsAssetName, int32 hash, RGB8 *myPalette) {
HUnLock(workHandle);
return emptySlot;
- } else if (i < MAX_ASSET_HASH) {
+ }
+
+ if (i < MAX_ASSET_HASH) {
// Else if we found the SS already loaded
if (_GWS(globalCELSPaloffsets)[i] >= 0) {
// Get the pointer to the pal data
@@ -802,9 +796,8 @@ int32 AddWSAssetCELS(const char *wsAssetName, int32 hash, RGB8 *myPalette) {
static int32 ProcessCELS(const char * /*assetName*/, char **parseAssetPtr, char * /*mainAssetPtr*/, char *endOfAssetBlock,
int32 **dataOffset, int32 **palDataOffset, RGB8 *myPalette) {
IntPointer celsType, numColors, celsSize;
- int32 *tempPtr, *data, *dataPtr, *offsetPtr, *palData, i, j;
+ int32 *tempPtr, i, j;
IntPointer header, format;
- bool byteSwap;
if (!_GWS(wsloaderInitialized))
return -1;
@@ -843,7 +836,7 @@ static int32 ProcessCELS(const char * /*assetName*/, char **parseAssetPtr, char
return -1;
}
- byteSwap = false;
+ bool byteSwap = false;
// If the chunk is PAL info - celsType == CELS_LAP_ indicates the chunk needs to be byte-swapped.
if ((*celsType == CELS__PAL) || (*celsType == CELS_LAP_)) {
// Read the chunk size, and the number of palette colors, and byte-swap if necessary
@@ -871,7 +864,7 @@ static int32 ProcessCELS(const char * /*assetName*/, char **parseAssetPtr, char
// The asset block offset for palData should begin with the number of colors
*palDataOffset = numColors.ptr();
- palData = numColors.ptr();
+ int32 *palData = numColors.ptr();
if (((intptr)endOfAssetBlock - (intptr)(*parseAssetPtr)) < ((int32)(*celsSize) - 8)) {
ws_LogErrorMsg(FL, "Pal info is larger than asset block.");
@@ -934,7 +927,7 @@ static int32 ProcessCELS(const char * /*assetName*/, char **parseAssetPtr, char
// The asset block offset for the cel should begin with the celsType
*dataOffset = (int32 *)celsType.ptr();
- data = (int32 *)celsType.ptr();
+ int32 *data = (int32 *)celsType.ptr();
// Verify that we actually got legitimate values
if ((int32)(*celsSize) <= 0) {
@@ -964,7 +957,7 @@ static int32 ProcessCELS(const char * /*assetName*/, char **parseAssetPtr, char
// The chunk header has been byteswapped, now we must byte-swap the table of
// offsets into the chunk, which indicate where each individual sprite can be found.
- offsetPtr = &(data[CELS_OFFSETS]);
+ int32 *offsetPtr = &(data[CELS_OFFSETS]);
tempPtr = offsetPtr;
for (i = 0; i < (int32)FROM_LE_32(data[CELS_COUNT]); i++) {
*tempPtr = SWAP_INT32(*tempPtr);
@@ -973,7 +966,7 @@ static int32 ProcessCELS(const char * /*assetName*/, char **parseAssetPtr, char
// dataPtr points to the beginning of the block which is a concatenation of
// all the sprites. Loop through and byteswap each individual sprite header.
- dataPtr = tempPtr;
+ int32 *dataPtr = tempPtr;
for (i = 0; i < (int32)FROM_LE_32(data[CELS_COUNT]); i++) {
// The beginning of sprite i is the dataPtr + the number of bytes in the offset table
tempPtr = (int32 *)((intptr)dataPtr + offsetPtr[i]);
@@ -991,18 +984,16 @@ static int32 ProcessCELS(const char * /*assetName*/, char **parseAssetPtr, char
}
static void RestoreSSPaletteInfo(RGB8 *myPalette, int32 *palPtr) {
- uint32 *tempPtr, i, j;
-
// Parameter verification
if ((!myPalette) || (!palPtr))
return;
// Set up a pointer that can step through the pal info for the SS, and restore each color
if (myPalette) {
- tempPtr = (uint32 *)(&palPtr[1]);
- for (i = 0; i < FROM_LE_32(palPtr[0]); i++) {
+ uint32 *tempPtr = (uint32 *)(&palPtr[1]);
+ for (uint32 i = 0; i < FROM_LE_32(palPtr[0]); i++) {
uint32 rgb = READ_LE_UINT32(tempPtr);
- j = (rgb & 0xff000000) >> 24;
+ uint32 j = (rgb & 0xff000000) >> 24;
myPalette[j].r = (rgb & 0x00ff0000) >> 14;
myPalette[j].g = (rgb & 0x0000ff00) >> 6;
myPalette[j].b = (rgb & 0x000000ff) << 2;
@@ -1012,7 +1003,6 @@ static void RestoreSSPaletteInfo(RGB8 *myPalette, int32 *palPtr) {
}
M4sprite *GetWSAssetSprite(char *spriteName, uint32 hash, uint32 index, M4sprite *mySprite, bool *streamSeries) {
- MemHandle workHandle;
int32 i;
// Ensure wsloader has been initialized
@@ -1042,7 +1032,7 @@ M4sprite *GetWSAssetSprite(char *spriteName, uint32 hash, uint32 index, M4sprite
}
// Get the resource handle
- workHandle = _GWS(globalCELSHandles)[hash];
+ MemHandle workHandle = _GWS(globalCELSHandles)[hash];
// Create the sprite
mySprite = CreateSprite(workHandle, _GWS(globalCELSoffsets)[hash], index, mySprite, streamSeries);
@@ -1059,7 +1049,7 @@ M4sprite *GetWSAssetSprite(char *spriteName, uint32 hash, uint32 index, M4sprite
int32 LoadSpriteSeries(const char *assetName, Handle *seriesHandle, int32 *celsOffset, int32 *palOffset, RGB8 *myPalette) {
MemHandle workHandle;
int32 celsSize, *celsPtr, *palPtr;
- char *mainAssetPtr, *endOfAssetBlock, *parseAssetPtr;
+ char *parseAssetPtr;
int32 assetSize;
//This loads a sprite series into the provided vars, rather than the WS tables.
@@ -1071,8 +1061,8 @@ int32 LoadSpriteSeries(const char *assetName, Handle *seriesHandle, int32 *celsO
HLock(workHandle);
- mainAssetPtr = (char *)*workHandle;
- endOfAssetBlock = (char *)((intptr)mainAssetPtr + assetSize);
+ char *mainAssetPtr = (char *)*workHandle;
+ char *endOfAssetBlock = (char *)((intptr)mainAssetPtr + assetSize);
parseAssetPtr = mainAssetPtr;
// Process the SS from the stream file
@@ -1220,8 +1210,6 @@ int32 GetWSAssetCELCount(uint32 hash) {
int32 GetWSAssetCELFrameRate(uint32 hash) {
- uint32 *celsPtr;
-
// Ensure the WS loader has been initialized.
if (!_GWS(wsloaderInitialized)) {
ws_LogErrorMsg(FL, "WS loader has not been initialized.");
@@ -1241,14 +1229,11 @@ int32 GetWSAssetCELFrameRate(uint32 hash) {
}
// Find and return the frame rate for the SS
- celsPtr = (uint32 *)((intptr)*(_GWS(globalCELSHandles)[hash]) + (uint32)(_GWS(globalCELSoffsets)[hash]));
+ uint32 *celsPtr = (uint32 *)((intptr)*(_GWS(globalCELSHandles)[hash]) + (uint32)(_GWS(globalCELSoffsets)[hash]));
return FROM_LE_32(celsPtr[CELS_FRAME_RATE]);
}
-
int32 GetWSAssetCELPixSpeed(uint32 hash) {
- uint32 *celsPtr;
-
// Ensure the WS loader has been initialized.
if (!_GWS(wsloaderInitialized)) {
ws_LogErrorMsg(FL, "WS loader has not been initialized.");
@@ -1268,14 +1253,11 @@ int32 GetWSAssetCELPixSpeed(uint32 hash) {
}
// Find and return the pix speed for the SS
- celsPtr = (uint32 *)((intptr)*(_GWS(globalCELSHandles)[hash]) + (uint32)(_GWS(globalCELSoffsets)[hash]));
+ uint32 *celsPtr = (uint32 *)((intptr)*(_GWS(globalCELSHandles)[hash]) + (uint32)(_GWS(globalCELSoffsets)[hash]));
return FROM_LE_32(celsPtr[CELS_PIX_SPEED]);
}
int32 ws_get_sprite_width(uint32 hash, int32 index) {
- uint32 *celsPtr, *offsets, *data, *myCelSource;
- int32 numCels;
-
// Ensure the WS loader has been initialized.
if (!_GWS(wsloaderInitialized)) {
ws_LogErrorMsg(FL, "WS loader has not been initialized.");
@@ -1295,10 +1277,10 @@ int32 ws_get_sprite_width(uint32 hash, int32 index) {
}
// Find the source for the SS
- celsPtr = (uint32 *)((intptr)*(_GWS(globalCELSHandles)[hash]) + (uint32)(_GWS(globalCELSoffsets)[hash]));
+ uint32 *celsPtr = (uint32 *)((intptr)*(_GWS(globalCELSHandles)[hash]) + (uint32)(_GWS(globalCELSoffsets)[hash]));
// Check that the index into the series requested is within a valid range
- numCels = FROM_LE_32(celsPtr[CELS_COUNT]);
+ int32 numCels = FROM_LE_32(celsPtr[CELS_COUNT]);
if (index >= numCels) {
ws_LogErrorMsg(FL, "ws_get_sprite_width: Sprite index out of range - max index: %d, requested index: %d, hash: %d",
numCels - 1, index, hash);
@@ -1306,21 +1288,18 @@ int32 ws_get_sprite_width(uint32 hash, int32 index) {
}
// Find the offset table in the SS header
- offsets = &celsPtr[CELS_OFFSETS];
+ uint32 *offsets = &celsPtr[CELS_OFFSETS];
// Find the beginning of the data for all sprites in the SS
- data = &celsPtr[CELS_OFFSETS + numCels];
+ uint32 *data = &celsPtr[CELS_OFFSETS + numCels];
// Find the sprite data for the specific sprite in the series
- myCelSource = (uint32 *)((intptr)data + FROM_LE_32(offsets[index]));
+ uint32 *myCelSource = (uint32 *)((intptr)data + FROM_LE_32(offsets[index]));
return FROM_LE_32(myCelSource[CELS_W]);
}
int32 ws_get_sprite_height(uint32 hash, int32 index) {
- uint32 *celsPtr, *offsets, *data, *myCelSource;
- int32 numCels;
-
// Ensure the WS loader has been initialized.
if (!_GWS(wsloaderInitialized)) {
ws_LogErrorMsg(FL, "WS loader has not been initialized.");
@@ -1340,10 +1319,10 @@ int32 ws_get_sprite_height(uint32 hash, int32 index) {
}
// Find the source for the SS
- celsPtr = (uint32 *)((intptr)*(_GWS(globalCELSHandles)[hash]) + (uint32)(_GWS(globalCELSoffsets)[hash]));
+ uint32 *celsPtr = (uint32 *)((intptr)*(_GWS(globalCELSHandles)[hash]) + (uint32)(_GWS(globalCELSoffsets)[hash]));
// Check that the index into the series requested is within a valid range
- numCels = FROM_LE_32(celsPtr[CELS_COUNT]);
+ int32 numCels = FROM_LE_32(celsPtr[CELS_COUNT]);
if (index >= numCels) {
ws_LogErrorMsg(FL, "ws_get_sprite_height: Sprite index out of range - max index: %d, requested index: %d, hash: %d",
numCels - 1, index, hash);
@@ -1351,20 +1330,18 @@ int32 ws_get_sprite_height(uint32 hash, int32 index) {
}
// Find the offset table in the SS header
- offsets = &celsPtr[CELS_OFFSETS];
+ uint32 *offsets = &celsPtr[CELS_OFFSETS];
// Find the beginning of the data for all sprites in the SS
- data = &celsPtr[CELS_OFFSETS + numCels];
+ uint32 *data = &celsPtr[CELS_OFFSETS + numCels];
// Find the sprite data for the specific sprite in the series
- myCelSource = (uint32 *)((intptr)data + FROM_LE_32(offsets[index]));
+ uint32 *myCelSource = (uint32 *)((intptr)data + FROM_LE_32(offsets[index]));
return FROM_LE_32(myCelSource[CELS_H]);
}
MemHandle ws_GetSEQU(uint32 hash, int32 *numLocalVars, int32 *offset) {
- uint32 *sequPtr;
-
// Ensure the WS loader has been initialized.
if (!_GWS(wsloaderInitialized)) {
ws_LogErrorMsg(FL, "WS loader has not been initialized.");
@@ -1384,7 +1361,7 @@ MemHandle ws_GetSEQU(uint32 hash, int32 *numLocalVars, int32 *offset) {
}
// Find the sequence chunk
- sequPtr = (uint32 *)((intptr)*(_GWS(globalSEQUHandles)[hash]) + (uint32)(_GWS(globalSEQUoffsets)[hash]));
+ uint32 *sequPtr = (uint32 *)((intptr)*(_GWS(globalSEQUHandles)[hash]) + (uint32)(_GWS(globalSEQUoffsets)[hash]));
// Return the offset into the resource chunk, and the number of local vars used by the sequence
*offset = (intptr)(&sequPtr[SEQU_SEQU_START]) - (intptr)*(_GWS(globalSEQUHandles)[hash]);
@@ -1395,8 +1372,6 @@ MemHandle ws_GetSEQU(uint32 hash, int32 *numLocalVars, int32 *offset) {
}
MemHandle ws_GetMACH(uint32 hash, int32 *numStates, int32 *stateTableOffset, int32 *machInstrOffset) {
- uint32 *machPtr;
-
// Ensure the WS loader has been initialized.
if (!_GWS(wsloaderInitialized)) {
ws_LogErrorMsg(FL, "WS loader has not been initialized.");
@@ -1419,7 +1394,7 @@ MemHandle ws_GetMACH(uint32 hash, int32 *numStates, int32 *stateTableOffset, int
HLock(_GWS(globalMACHHandles)[hash]);
// Find the machine chunk
- machPtr = (uint32 *)((intptr)*(_GWS(globalMACHHandles)[hash]) + (uint32)(_GWS(globalMACHoffsets)[hash]));
+ uint32 *machPtr = (uint32 *)((intptr)*(_GWS(globalMACHHandles)[hash]) + (uint32)(_GWS(globalMACHoffsets)[hash]));
// Set the number of states, the state offset table, the start of the mach instructions
*numStates = FROM_LE_32(machPtr[MACH_NUM_STATES]);
@@ -1432,8 +1407,6 @@ MemHandle ws_GetMACH(uint32 hash, int32 *numStates, int32 *stateTableOffset, int
}
MemHandle ws_GetDATA(uint32 hash, uint32 index, int32 *rowOffset) {
- uint32 *dataPtr;
-
// Ensure the WS loader has been initialized.
if (!_GWS(wsloaderInitialized)) {
ws_LogErrorMsg(FL, "WS loader has not been initialized.");
@@ -1453,7 +1426,7 @@ MemHandle ws_GetDATA(uint32 hash, uint32 index, int32 *rowOffset) {
}
// Find the data block chunk
- dataPtr = (uint32 *)((intptr)*(_GWS(globalDATAHandles)[hash]) + (uint32)(_GWS(globalDATAoffsets)[hash]));
+ uint32 *dataPtr = (uint32 *)((intptr)*(_GWS(globalDATAHandles)[hash]) + (uint32)(_GWS(globalDATAoffsets)[hash]));
// Verify the row index of the data block is valid
if (index > FROM_LE_32(dataPtr[DATA_REC_COUNT])) {
@@ -1472,8 +1445,6 @@ MemHandle ws_GetDATA(uint32 hash, uint32 index, int32 *rowOffset) {
}
int32 ws_GetDATACount(uint32 hash) {
- uint32 *dataPtr;
-
// Ensure the WS loader has been initialized.
if (!_GWS(wsloaderInitialized)) {
ws_LogErrorMsg(FL, "WS loader has not been initialized.");
@@ -1493,16 +1464,15 @@ int32 ws_GetDATACount(uint32 hash) {
}
// Find the data block chunk
- dataPtr = (uint32 *)((intptr)*(_GWS(globalDATAHandles)[hash]) + (uint32)(_GWS(globalDATAoffsets)[hash]));
+ uint32 *dataPtr = (uint32 *)((intptr)*(_GWS(globalDATAHandles)[hash]) + (uint32)(_GWS(globalDATAoffsets)[hash]));
// Return the number of rows in the data block
return FROM_LE_32(dataPtr[DATA_REC_COUNT]);
}
static int32 GetSSHeaderInfo(SysFile *sysFile, uint32 **data, RGB8 *myPalette) {
- uint32 celsType, celsSize, numColors, *myColors;
- uint32 *tempPtr, i, j, header, format;
- int32 numCels, dataOffset;
+ uint32 celsSize, *myColors;
+ uint32 *tempPtr, i;
bool byteSwap;
if (!sysFile) {
@@ -1511,8 +1481,8 @@ static int32 GetSSHeaderInfo(SysFile *sysFile, uint32 **data, RGB8 *myPalette) {
}
// Read in the series header and the format number
- header = sysFile->readUint32LE();
- format = sysFile->readUint32LE();
+ uint32 header = sysFile->readUint32LE();
+ uint32 format = sysFile->readUint32LE();
// Make sure the header is "M4SS", and that the format is not antique
if (header == HEAD_SS4M) {
@@ -1527,14 +1497,14 @@ static int32 GetSSHeaderInfo(SysFile *sysFile, uint32 **data, RGB8 *myPalette) {
}
// Read in the SS chunk type - either PAL or SS info
- celsType = sysFile->readUint32LE();
+ uint32 celsType = sysFile->readUint32LE();
if ((celsType == CELS__PAL) || (celsType == CELS_LAP_)) {
// PAL info, read in the size of the PAL chunk
celsSize = sysFile->readUint32LE();
// Now read in the number of colors to be inserted into the PAL
- numColors = sysFile->readUint32LE();
+ uint32 numColors = sysFile->readUint32LE();
// Make sure the info is in the correct format (swap between Motorola and Intel formats)
if (celsType == CELS_LAP_) {
@@ -1573,7 +1543,7 @@ static int32 GetSSHeaderInfo(SysFile *sysFile, uint32 **data, RGB8 *myPalette) {
if (myPalette) {
tempPtr = (uint32 *)(&myColors[0]);
for (i = 0; i < numColors; i++) {
- j = (*tempPtr & 0xff000000) >> 24;
+ uint32 j = (*tempPtr & 0xff000000) >> 24;
myPalette[j].r = (*tempPtr & 0x00ff0000) >> 14;
myPalette[j].g = (*tempPtr & 0x0000ff00) >> 6;
myPalette[j].b = (*tempPtr & 0x000000ff) << 2;
@@ -1611,7 +1581,7 @@ static int32 GetSSHeaderInfo(SysFile *sysFile, uint32 **data, RGB8 *myPalette) {
}
// Read how many sprites are in the series
- numCels = sysFile->readUint32LE();
+ int32 numCels = sysFile->readUint32LE();
// Again, byte-swap if the chunk is in the wrong format
if (celsType == CELS_SS__) {
@@ -1649,17 +1619,12 @@ static int32 GetSSHeaderInfo(SysFile *sysFile, uint32 **data, RGB8 *myPalette) {
}
// Find out how far into the stream we are, and return that value
- dataOffset = (*sysFile).get_pos();
+ int32 dataOffset = (*sysFile).get_pos();
return dataOffset;
}
bool ws_OpenSSstream(SysFile *sysFile, Anim8 *anim8) {
- CCB *myCCB;
- frac16 *myRegs;
- uint32 *celsPtr, *offsets;
- int32 ssDataOffset, i, numSprites;
int32 obesest_frame = 0;
- uint32 maxFrameSize;
// Verify the parameters
if (!sysFile || !anim8 || !anim8->myCCB) {
@@ -1667,9 +1632,9 @@ bool ws_OpenSSstream(SysFile *sysFile, Anim8 *anim8) {
return false;
}
- myCCB = anim8->myCCB;
- myRegs = anim8->myRegs;
- ssDataOffset = 0;
+ CCB *myCCB = anim8->myCCB;
+ frac16 *myRegs = anim8->myRegs;
+ int32 ssDataOffset = 0;
// Read in the SS stream header
if ((ssDataOffset = GetSSHeaderInfo(sysFile, &(myCCB->streamSSHeader), &_G(master_palette)[0])) <= 0) {
@@ -1677,8 +1642,8 @@ bool ws_OpenSSstream(SysFile *sysFile, Anim8 *anim8) {
}
// Automatically set some of the sequence registers
- celsPtr = myCCB->streamSSHeader;
- numSprites = celsPtr[CELS_COUNT];
+ uint32 *celsPtr = myCCB->streamSSHeader;
+ int32 numSprites = celsPtr[CELS_COUNT];
myRegs[IDX_CELS_INDEX] = -(1 << 16); // First frame inc will make it 0
myRegs[IDX_CELS_COUNT] = numSprites << 16;
myRegs[IDX_CELS_FRAME_RATE] = celsPtr[CELS_FRAME_RATE] << 16;
@@ -1686,11 +1651,11 @@ bool ws_OpenSSstream(SysFile *sysFile, Anim8 *anim8) {
// Here we convert the offset table to become the actual size of the data for each sprite
// This is so the stream can be optimized to always read in on sprite boundaries
// Get the beginning of the offset table
- offsets = &celsPtr[CELS_OFFSETS];
+ uint32 *offsets = &celsPtr[CELS_OFFSETS];
- maxFrameSize = 0;
+ uint32 maxFrameSize = 0;
// For all but the last frame, the frame size is the difference in offset values
- for (i = 0; i < numSprites - 1; i++) {
+ for (int32 i = 0; i < numSprites - 1; i++) {
offsets[i] = offsets[i + 1] - offsets[i];
if (offsets[i] > maxFrameSize) {
@@ -1742,18 +1707,13 @@ bool ws_OpenSSstream(SysFile *sysFile, Anim8 *anim8) {
}
bool ws_GetNextSSstreamCel(Anim8 *anim8) {
- CCB *myCCB;
- M4sprite *mySprite;
- uint32 *celsPtr, *offsets, *myCelSource;
- uint32 frameNum;
-
// Verify the parameters
if (!anim8) {
ws_LogErrorMsg(FL, "nullptr Anim8* given");
return false;
}
- myCCB = anim8->myCCB;
+ CCB *myCCB = anim8->myCCB;
if ((!anim8->myCCB) || (!myCCB->streamSSHeader) || (!myCCB->myStream)) {
ws_LogErrorMsg(FL, "Invalid Anim8* given.");
return false;
@@ -1764,14 +1724,14 @@ bool ws_GetNextSSstreamCel(Anim8 *anim8) {
}
// Find the SS source and the offset table into the source
- celsPtr = myCCB->streamSSHeader;
- offsets = &celsPtr[CELS_OFFSETS];
+ uint32 *celsPtr = myCCB->streamSSHeader;
+ uint32 *offsets = &celsPtr[CELS_OFFSETS];
// Automatically increment the sequence register
anim8->myRegs[IDX_CELS_INDEX] += 0x10000;
// Check whether the end of the SS has been streamed
- frameNum = anim8->myRegs[IDX_CELS_INDEX] >> 16;
+ uint32 frameNum = anim8->myRegs[IDX_CELS_INDEX] >> 16;
if (frameNum >= celsPtr[CELS_COUNT]) {
ws_LogErrorMsg(FL, "No more frames available to stream");
return false;
@@ -1790,8 +1750,8 @@ bool ws_GetNextSSstreamCel(Anim8 *anim8) {
}
// Initialize the sprite structure
- myCelSource = myCCB->streamSpriteSource;
- mySprite = myCCB->source;
+ uint32 *myCelSource = myCCB->streamSpriteSource;
+ M4sprite *mySprite = myCCB->source;
mySprite->xOffset = FROM_LE_32(myCelSource[CELS_X]);
mySprite->yOffset = FROM_LE_32(myCelSource[CELS_Y]);
Commit: 1659ab6ad3b245a6ec53dd44d244aa47ce4c5fa5
https://github.com/scummvm/scummvm/commit/1659ab6ad3b245a6ec53dd44d244aa47ce4c5fa5
Author: Strangerke (arnaud.boutonne at gmail.com)
Date: 2025-05-30T00:14:29+01:00
Commit Message:
M4: Some cleanup in ws_machine
Changed paths:
engines/m4/wscript/ws_machine.cpp
diff --git a/engines/m4/wscript/ws_machine.cpp b/engines/m4/wscript/ws_machine.cpp
index deb76ba3a87..8121e75af65 100644
--- a/engines/m4/wscript/ws_machine.cpp
+++ b/engines/m4/wscript/ws_machine.cpp
@@ -43,8 +43,6 @@ static void clear_msg_list(machine *m);
static void clear_persistent_msg_list(machine *m);
bool ws_Initialize(frac16 *theGlobals) {
- int32 i;
-
_GWS(machineIDCount) = 0;
_GWS(dataFormats) = ws_GetDataFormats();
@@ -55,7 +53,7 @@ bool ws_Initialize(frac16 *theGlobals) {
_GWS(ws_globals) = theGlobals;
- for (i = 0; i < GLB_SHARED_VARS; i++) {
+ for (int32 i = 0; i < GLB_SHARED_VARS; i++) {
_GWS(ws_globals)[i] = 0;
}
@@ -94,11 +92,9 @@ static void dispose_msgRequest(msgRequest *msg) {
}
static void clear_msg_list(machine *m) {
- msgRequest *freeMsg, *nextMsg;
-
- nextMsg = m->myMsgs;
+ msgRequest *nextMsg = m->myMsgs;
while (nextMsg) {
- freeMsg = nextMsg;
+ msgRequest *freeMsg = nextMsg;
nextMsg = nextMsg->nextMsg;
dispose_msgRequest(freeMsg);
}
@@ -107,10 +103,10 @@ static void clear_msg_list(machine *m) {
}
static void clear_persistent_msg_list(machine *m) {
- msgRequest *freeMsg, *nextMsg;
+ msgRequest *freeMsg;
// Clear the active persistent msgs
- nextMsg = m->myPersistentMsgs;
+ msgRequest *nextMsg = m->myPersistentMsgs;
while (nextMsg) {
freeMsg = nextMsg;
nextMsg = nextMsg->nextMsg;
@@ -130,23 +126,21 @@ static void clear_persistent_msg_list(machine *m) {
}
static msgRequest *new_msgRequest() {
- msgRequest *newMsg;
- if ((newMsg = (msgRequest *)mem_alloc(sizeof(msgRequest), "msgRequest")) == nullptr) {
+ msgRequest *newMsg = (msgRequest *)mem_alloc(sizeof(msgRequest), "msgRequest");
+ if (newMsg == nullptr) {
ws_LogErrorMsg(FL, "Failed to mem_alloc() %d bytes.", sizeof(msgRequest));
}
return newMsg;
}
static void restore_persistent_msgs(machine *m) {
- msgRequest *lastMsg;
-
// Check params...
if ((!m) || (!m->usedPersistentMsgs)) {
return;
}
// Loop to find the last used persistent msg
- lastMsg = m->usedPersistentMsgs;
+ msgRequest *lastMsg = m->usedPersistentMsgs;
while (lastMsg->nextMsg) {
lastMsg = lastMsg->nextMsg;
}
@@ -223,8 +217,6 @@ static void op_ON_MSG(machine *m, int32 *pcOffset) {
* Same as op_ON_MSG() except these messages do not get cleared between states
*/
static void op_ON_P_MSG(machine *m, int32 *pcOffset) {
- msgRequest *myMsg, *prevMsg;
- uint32 msgHash;
frac16 msgValue;
if (!_GWS(myArg2)) {
@@ -232,7 +224,7 @@ static void op_ON_P_MSG(machine *m, int32 *pcOffset) {
}
// Get the values for msgHash and msgValue from the args...
- msgHash = *_GWS(myArg2);
+ uint32 msgHash = *_GWS(myArg2);
if (_GWS(myArg3)) {
msgValue = *_GWS(myArg3);
} else {
@@ -240,8 +232,8 @@ static void op_ON_P_MSG(machine *m, int32 *pcOffset) {
}
// Since the message is persistent, it may have been satisfied earlier, check the used list
- prevMsg = nullptr;
- myMsg = m->usedPersistentMsgs;
+ msgRequest *prevMsg = nullptr;
+ msgRequest *myMsg = m->usedPersistentMsgs;
// Loop through all the used msgs, see if there is already a struct in place
while (myMsg && ((myMsg->msgHash != msgHash) || (myMsg->msgValue != msgValue))) {
@@ -468,7 +460,7 @@ static bool op_SYSTEM_MSG(machine *m, int32 *pcOffset) {
}
static bool op_TRIG(machine *m, int32 *pcOffset) {
- int32 myCount, i;
+ int32 myCount;
char tempStr[80];
if (!_GWS(myArg1)) {
@@ -486,7 +478,7 @@ static bool op_TRIG(machine *m, int32 *pcOffset) {
}
Common::sprintf_s(tempStr, "*** TRIGGERED BY MACHINE: %d", m->myHash);
- for (i = 0; i < myCount; i++) {
+ for (int32 i = 0; i < myCount; i++) {
if (!TriggerMachineByHash(*_GWS(myArg1) >> 16, m->myAnim8, -1, -1, m->CintrMsg, false, tempStr)) {
ws_Error(m, ERR_MACH, 0x0267, "trig() failed");
}
@@ -496,18 +488,17 @@ static bool op_TRIG(machine *m, int32 *pcOffset) {
}
static bool op_TRIG_W(machine *m, int32 *pcOffset) {
- int32 myHash, myCount = 0, minCount = 0, maxCount = 0, i, myInstruction;
- int32 myIndex, minIndex, maxIndex, myDataCount;
- int32 myDataHash;
+ int32 myCount = 0, minCount = 0, maxCount = 0, i, myInstruction;
+ int32 myIndex, minIndex, maxIndex;
bool randFlag = false;
char tempStr[80];
- uint32 *myPC, *oldPC, *machInstr;
+ uint32 *myPC;
if (!_GWS(myArg1)) {
ws_Error(m, ERR_MACH, 0x0263, "functionality: trigger mach arg1, arg2 instances");
}
- myHash = (*_GWS(myArg1)) >> 16;
+ int32 myHash = (*_GWS(myArg1)) >> 16;
if (_GWS(myArg2)) {
if (_GWS(myArg3)) {
randFlag = true;
@@ -521,9 +512,9 @@ static bool op_TRIG_W(machine *m, int32 *pcOffset) {
}
// This is a double length instruction - up to 128 bits, we must read in the next pCode
- machInstr = (uint32 *)((intptr)(*(m->machHandle)) + (uint32)m->machInstrOffset);
+ uint32 *machInstr = (uint32 *)((intptr)(*(m->machHandle)) + (uint32)m->machInstrOffset);
myPC = (uint32 *)((intptr)machInstr + *pcOffset);
- oldPC = myPC;
+ uint32 *oldPC = myPC;
dbg_SetCurrMachInstr(m, *pcOffset, false);
@@ -540,8 +531,8 @@ static bool op_TRIG_W(machine *m, int32 *pcOffset) {
ws_Error(m, ERR_MACH, 0x0263, "trig_w instruction requires a data hash specified by a second pCode.");
}
- myDataHash = (int32)(*_GWS(myArg1)) >> 16;
- myDataCount = ws_GetDATACount(myDataHash);
+ int32 myDataHash = (int32)(*_GWS(myArg1)) >> 16;
+ int32 myDataCount = ws_GetDATACount(myDataHash);
if (_GWS(myArg2)) {
if (_GWS(myArg3)) {
minIndex = (*_GWS(myArg2)) >> 16;
@@ -583,15 +574,12 @@ static bool op_TRIG_W(machine *m, int32 *pcOffset) {
}
static bool op_CLEAR_REGS(machine *m, int32 *pcOffset) {
- Anim8 *myAnim8;
- int32 i;
-
if (!m->myAnim8) {
ws_Error(m, ERR_INTERNAL, 0x02f3, "clear_regs() failed.");
}
- myAnim8 = m->myAnim8;
- for (i = 0; i < IDX_COUNT + myAnim8->numLocalVars; i++) {
+ Anim8 *myAnim8 = m->myAnim8;
+ for (int32 i = 0; i < IDX_COUNT + myAnim8->numLocalVars; i++) {
myAnim8->myRegs[i] = 0;
}
@@ -656,10 +644,8 @@ void addPauseTime(int32 myTime) {
void cycleEngines(Buffer *cleanBackground, int16 *depth_table, Buffer *screenCodes,
uint8 *myPalette, uint8 *ICT, bool updateVideo) {
- int32 clockTime;
-
dbg_DebugNextCycle();
- clockTime = timer_read_60();
+ int32 clockTime = timer_read_60();
if (_GWS(enginesPaused)) {
_GWS(pauseTime) += clockTime - _GWS(oldTime);
@@ -686,8 +672,6 @@ void ws_RefreshWoodscriptBuffer(Buffer *cleanBackground, int16 *depth_table,
}
static void cancelAllEngineReqs(machine *m) {
- globalMsgReq *myGMsg, *tempGMsg;
-
if (m->machID == DEAD_MACHINE_ID) {
return;
}
@@ -705,10 +689,10 @@ static void cancelAllEngineReqs(machine *m) {
//---- Free all pending global messages requests in this machine
if (_GWS(myGlobalMessages)) {
- myGMsg = _GWS(myGlobalMessages);
+ globalMsgReq *myGMsg = _GWS(myGlobalMessages);
while (myGMsg->next) {
if (myGMsg->next->sendM == m) {
- tempGMsg = myGMsg->next;
+ globalMsgReq *tempGMsg = myGMsg->next;
myGMsg->next = myGMsg->next->next;
mem_free((void *)tempGMsg);
} else myGMsg = myGMsg->next;
@@ -765,11 +749,10 @@ static machine *getValidNext(machine *currMachine) {
}
void terminateMachinesByHash(uint32 machHash) {
- machine *curr, *next;
- curr = _GWS(firstMachine); // Start at beginning of machine chain
+ machine *curr = _GWS(firstMachine); // Start at beginning of machine chain
while (curr) {
- next = curr->next; // Preserve next pointer against curr's dealloc
+ machine *next = curr->next; // Preserve next pointer against curr's dealloc
if (curr->myHash == machHash) { // is this one to delete?
if (curr == _GWS(firstMachine)) { // maintain the beginning of machine chain
_GWS(firstMachine) = next;
@@ -797,15 +780,13 @@ void terminateMachineAndNull(machine *&m) {
}
bool verifyMachineExists(machine *m) {
- machine *tempM;
-
// Parameter verification
if (!m) {
return false;
}
// Loop through the active machine list, looking for m
- tempM = _GWS(firstMachine);
+ machine *tempM = _GWS(firstMachine);
while (tempM && (tempM != m)) {
tempM = getValidNext(tempM);
}
@@ -820,12 +801,10 @@ bool verifyMachineExists(machine *m) {
}
int32 ws_KillMachines() {
- machine *myMachine;
- globalMsgReq *tempGlobalMsg;
int32 myBytes = 0;
// Deallocate all machines
- myMachine = _GWS(firstMachine);
+ machine *myMachine = _GWS(firstMachine);
while (myMachine) {
// get any next Machine here, not validNext
_GWS(firstMachine) = _GWS(firstMachine)->next;
@@ -841,7 +820,7 @@ int32 ws_KillMachines() {
}
// Deallocate global messages
- tempGlobalMsg = _GWS(myGlobalMessages);
+ globalMsgReq *tempGlobalMsg = _GWS(myGlobalMessages);
while (tempGlobalMsg) {
_GWS(myGlobalMessages) = _GWS(myGlobalMessages)->next;
mem_free((void *)tempGlobalMsg);
@@ -872,18 +851,16 @@ void ws_KillDeadMachines() {
// This is the proc designed to evaluate the instructions of the state machine
static int32 StepAt(int32 *pcOffset, machine *m) {
- bool keepProcessing;
int32 myInstruction;
- Anim8 *myAnim8;
- uint32 machID, *myPC, *oldPC, *machInstr;
+ uint32 *myPC;
- machID = m->machID;
- myAnim8 = m->myAnim8;
+ uint32 machID = m->machID;
+ Anim8 *myAnim8 = m->myAnim8;
// Find the current PC and process it to get the current instruction
- machInstr = (uint32 *)((intptr)(*(m->machHandle)) + m->machInstrOffset);
+ uint32 *machInstr = (uint32 *)((intptr)(*(m->machHandle)) + m->machInstrOffset);
myPC = (uint32 *)((intptr)(machInstr) + *pcOffset);
- oldPC = myPC;
+ uint32 *oldPC = myPC;
_GWS(pcOffsetOld) = *pcOffset;
dbg_SetCurrMachInstr(m, *pcOffset, false);
@@ -900,7 +877,7 @@ static int32 StepAt(int32 *pcOffset, machine *m) {
if (myInstruction >= 64) {
condOpTable[myInstruction - 64](m, pcOffset);
} else if (myInstruction > 0) {
- keepProcessing = immOpTable[myInstruction](m, pcOffset);
+ bool keepProcessing = immOpTable[myInstruction](m, pcOffset);
if (!keepProcessing) {
// Does the machine still exist
@@ -920,20 +897,17 @@ static int32 StepAt(int32 *pcOffset, machine *m) {
void ws_StepWhile(machine *m, int32 pcOffset, int32 pcCount) {
- int32 myInstruction, oldPC;
- uint32 machID, recurseLevel;
-
// We are executing machine instructions after a conditional has been satisfied.
// Mark where we started
- oldPC = pcOffset;
+ int32 oldPC = pcOffset;
// Increment and remember the recurseLevel and the machine ID
m->recurseLevel++;
- recurseLevel = m->recurseLevel;
- machID = m->machID;
+ uint32 recurseLevel = m->recurseLevel;
+ uint32 machID = m->machID;
// Execute instructions until the conditional count has been reached.
- myInstruction = -1;
+ int32 myInstruction = -1;
while (myInstruction && (myInstruction != OP_KILL) &&
(pcOffset >= oldPC) && (pcOffset - oldPC < pcCount) &&
(m->machID == machID) && (m->recurseLevel == recurseLevel)) {
@@ -959,25 +933,21 @@ void ws_StepWhile(machine *m, int32 pcOffset, int32 pcCount) {
// evaluated immediately.
void IntoTheState(machine *m) {
- int32 myInstruction;
- uint32 *stateTable, machID, recurseLevel;
- int32 pcOffset;
-
if ((m->curState >= m->numOfStates) || (m->curState < 0)) {
ws_Error(m, ERR_INTERNAL, 0x2f2, "IntoTheState() failed.");
}
- stateTable = (uint32 *)((intptr)(*(m->machHandle)) + (intptr)m->stateTableOffset);
- pcOffset = FROM_LE_32(stateTable[m->curState]);
+ uint32 *stateTable = (uint32 *)((intptr)(*(m->machHandle)) + (intptr)m->stateTableOffset);
+ int32 pcOffset = FROM_LE_32(stateTable[m->curState]);
// Increment and remember the recurseLevel and the machine ID
m->recurseLevel++;
- recurseLevel = m->recurseLevel;
- machID = m->machID;
+ uint32 recurseLevel = m->recurseLevel;
+ uint32 machID = m->machID;
// Execute all instruction until an instruction (ie. OP_END) signals execution to stop
// by returning 0, or something has reset the recurseLevel (ie. op_GOTO)
- myInstruction = -1;
+ int32 myInstruction = -1;
while (myInstruction && (myInstruction != OP_KILL) &&
((m->machID == machID) && (m->recurseLevel == recurseLevel))) {
myInstruction = StepAt(&pcOffset, m);
@@ -995,9 +965,9 @@ void IntoTheState(machine *m) {
// This proc creates an instance of a machine based on the machine chunk
machine *TriggerMachineByHash(int32 myHash, Anim8 *parentAnim8, int32 dataHash, int32 dataRow, MessageCB CintrMsg, bool debug, const char *machName) {
- machine *m;
+ machine *m = (machine *)mem_alloc(sizeof(machine), "machine");
- if ((m = (machine *)mem_alloc(sizeof(machine), "machine")) == nullptr) {
+ if (m == nullptr) {
ws_LogErrorMsg(FL, "Out of memory - mem requested: %d.", sizeof(machine));
ws_LogErrorMsg(FL, "Trying to trigger hash: %d, name: %s", myHash, machName);
ws_Error(m, ERR_INTERNAL, 0x2fe, "TriggerMachineByHash() failed.");
@@ -1088,13 +1058,11 @@ enum {
static bool SearchMsgList(uint32 msgHash, uint32 msgValue, machine *recvM, int32 whichList, machine *sendM) {
- bool found;
- msgRequest *myMsg = nullptr, *prevMsg;
- int32 pcOffset, pcCount;
+ msgRequest *myMsg = nullptr;
// Initialize search vars
- found = false;
- prevMsg = nullptr;
+ bool found = false;
+ msgRequest *prevMsg = nullptr;
// Find the first msg, based on which list is to be searched
switch (whichList) {
@@ -1120,8 +1088,8 @@ static bool SearchMsgList(uint32 msgHash, uint32 msgValue, machine *recvM, int32
found = true;
// Find out where to begin executing from
- pcOffset = myMsg->pcOffset;
- pcCount = myMsg->pcCount;
+ int32 pcOffset = myMsg->pcOffset;
+ int32 pcCount = myMsg->pcCount;
// Remove the msg from the list, based on which list
switch (whichList) {
@@ -1178,15 +1146,11 @@ static bool SearchMsgList(uint32 msgHash, uint32 msgValue, machine *recvM, int32
void sendWSMessage(uint32 msgHash, frac16 msgValue, machine *recvM,
uint32 machHash, machine *sendM, int32 msgCount) {
- bool found, more_to_send;
- machine *currMachine;
- int32 myCount;
bool sendToAll;
- globalMsgReq *myGlobalMsgs, *tempGlobalMsg;
debugC(1, kDebugMessages, "Message %xh, %lxh, %s, %xh, %s, %d",
- msgHash, msgValue, recvM ? recvM->machName : "NONE",
- machHash, sendM ? sendM->machName : "NONE", msgCount);
+ msgHash, msgValue, recvM ? recvM->machName : "NONE",
+ machHash, sendM ? sendM->machName : "NONE", msgCount);
// In this case we are sending to a specific machine: recvM
if (recvM) {
@@ -1204,7 +1168,8 @@ void sendWSMessage(uint32 msgHash, frac16 msgValue, machine *recvM,
// Not sending to a specific machine, so send to <msgCount> machines with the given hash
// Prepare a global message structure
- if ((tempGlobalMsg = (globalMsgReq *)mem_alloc(sizeof(globalMsgReq), "globalMsgReq")) == nullptr) {
+ globalMsgReq *tempGlobalMsg = (globalMsgReq *)mem_alloc(sizeof(globalMsgReq), "globalMsgReq");
+ if (tempGlobalMsg == nullptr) {
ws_LogErrorMsg(FL, "Out of memory - mem requested: %d.", sizeof(machine));
ws_Error(nullptr, ERR_INTERNAL, 0x2fe, "SendWSMessage() failed.");
}
@@ -1232,7 +1197,7 @@ void sendWSMessage(uint32 msgHash, frac16 msgValue, machine *recvM,
// Check to see if we are already in the middle of processing global messages
if (_GWS(myGlobalMessages)) {
// Find the end of the global list
- myGlobalMsgs = _GWS(myGlobalMessages);
+ globalMsgReq *myGlobalMsgs = _GWS(myGlobalMessages);
while (myGlobalMsgs->next) {
myGlobalMsgs = myGlobalMsgs->next;
}
@@ -1251,7 +1216,7 @@ void sendWSMessage(uint32 msgHash, frac16 msgValue, machine *recvM,
// Loop through and service all global requests.
while (_GWS(myGlobalMessages)) {
// Sending to all machines, or just a bunch of them?
- myCount = _GWS(myGlobalMessages)->msgCount;
+ int32 myCount = _GWS(myGlobalMessages)->msgCount;
if (myCount <= 0) {
sendToAll = true;
} else {
@@ -1259,8 +1224,8 @@ void sendWSMessage(uint32 msgHash, frac16 msgValue, machine *recvM,
}
// Search machine list
- more_to_send = true;
- currMachine = _GWS(firstMachine);
+ bool more_to_send = true;
+ machine *currMachine = _GWS(firstMachine);
while (currMachine && more_to_send) {
// Set nextXM up in case this machine is deleted during the ws_StepWhile
// nextXM will be maintained by ShutDownMachine()
@@ -1269,7 +1234,7 @@ void sendWSMessage(uint32 msgHash, frac16 msgValue, machine *recvM,
// Have we got a machine of the specified hash
if (currMachine->myHash == _GWS(myGlobalMessages)->machHash) {
// Search the machines regular list.
- found = SearchMsgList(msgHash, msgValue, currMachine, REGULAR_MSG, sendM);
+ bool found = SearchMsgList(msgHash, msgValue, currMachine, REGULAR_MSG, sendM);
// If the message wasn't found in the regular list, search the persistent list
if (!found) {
More information about the Scummvm-git-logs
mailing list