SAGA2: Replace elementsof with ARRAYSIZE

This commit is contained in:
Eugene Sandulenko 2021-06-23 14:29:21 +02:00
parent 44c4ad38e9
commit 37bd0e9c38
No known key found for this signature in database
GPG Key ID: 014D387312D34F08
26 changed files with 114 additions and 119 deletions

View File

@ -1330,7 +1330,7 @@ void *Actor::archive(void *buf) {
a->currentRecoveryPoints = currentRecoveryPoints;
a->leaderID = leader != NULL ? leader->thisID() : Nothing;
a->followersID = followers != NULL ? getBandID(followers) : NoBand;
for (i = 0; i < elementsof(a->armorObjects); i++)
for (i = 0; i < ARRAYSIZE(a->armorObjects); i++)
a->armorObjects[i] = armorObjects[i];
a->currentTargetID = currentTarget != NULL ? currentTarget->thisID() : Nothing;
for (i = 0; i < actorScriptVars; i++)
@ -3076,7 +3076,7 @@ bool Actor::pathFindState(void) {
// Add knowledge package to actor
bool Actor::addKnowledge(uint16 kID) {
for (int i = 0; i < elementsof(knowledge); i++) {
for (int i = 0; i < ARRAYSIZE(knowledge); i++) {
if (knowledge[i] == 0) {
knowledge[i] = kID;
return true;
@ -3089,7 +3089,7 @@ bool Actor::addKnowledge(uint16 kID) {
// Remove knowledge package from actor
bool Actor::removeKnowledge(uint16 kID) {
for (int i = 0; i < elementsof(knowledge); i++) {
for (int i = 0; i < ARRAYSIZE(knowledge); i++) {
if (knowledge[i] == kID) {
knowledge[i] = 0;
return true;
@ -3102,7 +3102,7 @@ bool Actor::removeKnowledge(uint16 kID) {
// Remove all knowledge package from actor
void Actor::clearKnowledge(void) {
for (int i = 0; i < elementsof(knowledge); i++) {
for (int i = 0; i < ARRAYSIZE(knowledge); i++) {
knowledge[i] = 0;
}
}
@ -3117,7 +3117,7 @@ void Actor::useKnowledge(scriptCallFrame &scf) {
// First, search for the class with the best response
for (int i = 0; i < elementsof(knowledge); i++) {
for (int i = 0; i < ARRAYSIZE(knowledge); i++) {
if (knowledge[i]) {
scriptResult res;

View File

@ -551,7 +551,7 @@ int16 openAutoMap() {
scrollBtn = new gCompButton(*pAutoMap, scrollBtnRect, scrollBtnImage, numBtnImages, 0, cmdAutoMapScroll);
pAutoMap->setDecorations(autoMapDecorations,
elementsof(autoMapDecorations),
ARRAYSIZE(autoMapDecorations),
decRes, 'M', 'A', 'P');
// attach the structure to the book

View File

@ -105,7 +105,7 @@ public:
BandList::BandList(void) {
int i;
for (i = 0; i < elementsof(array); i++)
for (i = 0; i < ARRAYSIZE(array); i++)
free.addTail(array[i]);
}
@ -222,7 +222,7 @@ void *BandList::newBand(void) {
// Place a specific Band into the active list and return its address
void *BandList::newBand(BandID id) {
assert(id >= 0 && id < elementsof(array));
assert(id >= 0 && id < ARRAYSIZE(array));
BandPlaceHolder *bp;
@ -395,7 +395,7 @@ Band::Band(void **buf) {
bufferPtr = (ObjectID *)bufferPtr + 1;
// Restore the member count
assert(*((int16 *)bufferPtr) < elementsof(members));
assert(*((int16 *)bufferPtr) < ARRAYSIZE(members));
memberCount = *((int16 *)bufferPtr);
bufferPtr = (int16 *)bufferPtr + 1;

View File

@ -98,7 +98,7 @@ public:
}
bool add(Actor *newMember) {
if (memberCount < elementsof(members)) {
if (memberCount < ARRAYSIZE(members)) {
members[memberCount++] = newMember;
return true;
} else

View File

@ -1241,7 +1241,7 @@ TangibleContainerWindow::TangibleContainerWindow(
if (deathFlag) {
// set the decorations for this window
setDecorations(deathDecorations,
elementsof(deathDecorations),
ARRAYSIZE(deathDecorations),
containerRes, 'F', 'R', 'M');
massWeightIndicator = NULL;
} else {
@ -1258,7 +1258,7 @@ TangibleContainerWindow::TangibleContainerWindow(
// set the decorations for this window
setDecorations(winDecs[bgndType],
elementsof(brassDecorations), // brass was arb, all should have same
ARRAYSIZE(brassDecorations), // brass was arb, all should have same
containerRes, 'F', 'R', 'M');
// set the userdata such that we can extract the container object later
@ -1343,7 +1343,7 @@ IntangibleContainerWindow::IntangibleContainerWindow(
// set the decorations for this window
setDecorations(mentalDecorations,
elementsof(mentalDecorations),
ARRAYSIZE(mentalDecorations),
containerRes, 'F', 'R', 'M');
setMindContainer(nd.mindType, *this);
@ -1928,7 +1928,7 @@ void setMindContainer(int index, IntangibleContainerWindow &cw) {
ObjectID id;
assert(index >= 0);
assert(index < elementsof(classTable));
assert(index < ARRAYSIZE(classTable));
int containerClass = classTable[index];

View File

@ -501,7 +501,7 @@ void DisplayNode::drawObject(void) {
buildColorTable(
mainColors,
bubbleColorTable,
elementsof(bubbleColorTable));
ARRAYSIZE(bubbleColorTable));
if (a->kludgeCount < 0 || ++a->kludgeCount >= bubbleSpriteCount)
a->kludgeCount = 0;

View File

@ -74,7 +74,7 @@ CDocumentAppearance scrollAppearance(
Rect16(0, 0, 0, 0), // (No page 2)
Rect16(184, 206, 44, 42), // Close button rect
scrollDecorations,
elementsof(scrollDecorations),
ARRAYSIZE(scrollDecorations),
MKTAG('S', 'C', 'R', 'L'),
MKTAG('S', 'R', 'L', 0)
);
@ -101,7 +101,7 @@ CDocumentAppearance bookAppearance(
Rect16(218, 26, 135, 205), // Page 2
Rect16(231, 217, 34, 27), // Close button rect
bookDecorations,
elementsof(bookDecorations),
ARRAYSIZE(bookDecorations),
MKTAG('B', 'O', 'O', 'K'),
MKTAG('B', 'K', 'D', 0)
);
@ -123,7 +123,7 @@ CDocumentAppearance parchAppearance(
Rect16(0, 0, 0, 0), // (No page 2)
Rect16(164, 229, 20, 20), // Close button rect
parchDecorations,
elementsof(parchDecorations),
ARRAYSIZE(parchDecorations),
MKTAG('P', 'A', 'R', 'C'),
MKTAG('P', 'C', 'H', 0)
);

View File

@ -594,31 +594,31 @@ void CPortrait::getStateString(char buf[], int8 size, uint16 brotherID) {
length += appendToStr(
&buf[length],
asleepStr,
elementsof(asleepStr) - 1,
ARRAYSIZE(asleepStr) - 1,
size - length - 1);
} else if (a->enchantmentFlags & (1 << actorParalyzed)) {
length += appendToStr(
&buf[length],
paralysedStr,
elementsof(paralysedStr) - 1,
ARRAYSIZE(paralysedStr) - 1,
size - length - 1);
} else if (a->enchantmentFlags & (1 << actorBlind)) {
length += appendToStr(
&buf[length],
blindStr,
elementsof(blindStr) - 1,
ARRAYSIZE(blindStr) - 1,
size - length - 1);
} else if (a->enchantmentFlags & (1 << actorFear)) {
length += appendToStr(
&buf[length],
afraidStr,
elementsof(afraidStr) - 1,
ARRAYSIZE(afraidStr) - 1,
size - length - 1);
} else if (pa->isAggressive()) {
length += appendToStr(
&buf[length],
angryStr,
elementsof(angryStr) - 1,
ARRAYSIZE(angryStr) - 1,
size - length - 1);
}
@ -627,24 +627,24 @@ void CPortrait::getStateString(char buf[], int8 size, uint16 brotherID) {
length += appendToStr(
&buf[length],
commaStr,
elementsof(commaStr) - 1,
ARRAYSIZE(commaStr) - 1,
size - length - 1);
length += appendToStr(
&buf[length],
badlyWoundedStr,
elementsof(badlyWoundedStr) - 1,
ARRAYSIZE(badlyWoundedStr) - 1,
size - length - 1);
} else if (stats.vitality * 2 > a->effectiveStats.vitality * 3) {
if (length != 0)
length += appendToStr(
&buf[length],
commaStr,
elementsof(commaStr) - 1,
ARRAYSIZE(commaStr) - 1,
size - length - 1);
length += appendToStr(
&buf[length],
hurtStr,
elementsof(hurtStr) - 1,
ARRAYSIZE(hurtStr) - 1,
size - length - 1);
}
@ -653,24 +653,24 @@ void CPortrait::getStateString(char buf[], int8 size, uint16 brotherID) {
length += appendToStr(
&buf[length],
commaStr,
elementsof(commaStr) - 1,
ARRAYSIZE(commaStr) - 1,
size - length - 1);
length += appendToStr(
&buf[length],
poisonedStr,
elementsof(poisonedStr) - 1,
ARRAYSIZE(poisonedStr) - 1,
size - length - 1);
} else if (a->enchantmentFlags & (1 << actorDiseased)) {
if (length != 0)
length += appendToStr(
&buf[length],
commaStr,
elementsof(commaStr) - 1,
ARRAYSIZE(commaStr) - 1,
size - length - 1);
length += appendToStr(
&buf[length],
diseasedStr,
elementsof(diseasedStr) - 1,
ARRAYSIZE(diseasedStr) - 1,
size - length - 1);
}
@ -678,7 +678,7 @@ void CPortrait::getStateString(char buf[], int8 size, uint16 brotherID) {
length += appendToStr(
&buf[length],
normalStr,
elementsof(normalStr) - 1,
ARRAYSIZE(normalStr) - 1,
size - length - 1);
}
}
@ -705,7 +705,7 @@ CStatusLine::CStatusLine(gPanelList &list,
lineDisplayed = false;
queueHead = queueTail = 0;
for (i = 0; i < elementsof(lineQueue); i++)
for (i = 0; i < ARRAYSIZE(lineQueue); i++)
lineQueue[i].text = nullptr;
}

View File

@ -42,7 +42,7 @@ ActiveMission *ActiveMission::newMission(ObjectID genID, uint16 script) {
int i;
ActiveMission *ms = NULL;
for (i = 0; i < elementsof(activeMissions); i++) {
for (i = 0; i < ARRAYSIZE(activeMissions); i++) {
if (!(activeMissions[i]._data.missionFlags & inUse)) {
ms = &activeMissions[i];
break;
@ -58,7 +58,7 @@ ActiveMission *ActiveMission::newMission(ObjectID genID, uint16 script) {
ms->_data.numKnowledgeIDs = ms->_data.numObjectIDs = 0;
memset(ms->_data.missionVars, 0, elementsof(ms->_data.missionVars));
memset(ms->_data.missionVars, 0, ARRAYSIZE(ms->_data.missionVars));
return ms;
}
@ -69,7 +69,7 @@ ActiveMission *ActiveMission::newMission(ObjectID genID, uint16 script) {
int ActiveMission::findMission(ObjectID genID) {
int i;
for (i = 0; i < elementsof(activeMissions); i++) {
for (i = 0; i < ARRAYSIZE(activeMissions); i++) {
if (activeMissions[i]._data.missionFlags & inUse
&& activeMissions[i]._data.generatorID == genID) {
return i;
@ -81,7 +81,7 @@ int ActiveMission::findMission(ObjectID genID) {
ActiveMission *ActiveMission::missionAddress(int index) {
assert(index >= 0);
assert(index < elementsof(activeMissions));
assert(index < ARRAYSIZE(activeMissions));
return &activeMissions[index];
}
@ -90,7 +90,7 @@ ActiveMission *ActiveMission::missionAddress(int index) {
// Add record of object creation to mission
bool ActiveMission::addObjectID(ObjectID objID) {
if (_data.numObjectIDs < elementsof(_data.missionObjectList)) {
if (_data.numObjectIDs < ARRAYSIZE(_data.missionObjectList)) {
_data.missionObjectList[_data.numObjectIDs++] = objID;
return true;
}
@ -124,7 +124,7 @@ bool ActiveMission::removeObjectID(ObjectID objID) {
bool ActiveMission::addKnowledgeID(ObjectID actor, uint16 knowledgeID) {
if (!isActor(actor)) return false;
if (_data.numKnowledgeIDs < elementsof(_data.missionKnowledgeList)) {
if (_data.numKnowledgeIDs < ARRAYSIZE(_data.missionKnowledgeList)) {
Actor *a = (Actor *)GameObject::objectAddress(actor);
if (!a->addKnowledge(knowledgeID)) return false;
@ -191,7 +191,7 @@ void ActiveMission::cleanup(void) {
void initMissions(void) {
int i;
for (i = 0; i < elementsof(activeMissions); i++)
for (i = 0; i < ARRAYSIZE(activeMissions); i++)
activeMissions[i]._data.missionFlags &= ~inUse;
}

View File

@ -86,7 +86,7 @@ public:
void cleanup(void);
bool spaceForObject(void) {
return _data.numObjectIDs < elementsof(_data.missionObjectList);
return _data.numObjectIDs < ARRAYSIZE(_data.missionObjectList);
}
// Add record of object creation to mission

View File

@ -361,7 +361,7 @@ static MotionTaskList &mTaskList = *((MotionTaskList *)mTaskListBuffer);
// Initialize the MotionTaskList
MotionTaskList::MotionTaskList(void) {
for (int i = 0; i < elementsof(array); i++) {
for (int i = 0; i < ARRAYSIZE(array); i++) {
free.addTail(array[i]);
}
}
@ -375,7 +375,7 @@ MotionTaskList::MotionTaskList(void **buf) {
int16 i,
motionTaskCount;
for (i = 0; i < elementsof(array); i++) {
for (i = 0; i < ARRAYSIZE(array); i++) {
free.addTail(array[i]);
}
@ -3283,7 +3283,7 @@ const uint8 twoHandedSwingArray[] = {
const CombatMotionSet twoHandedSwingSet =
CombatMotionSet(
twoHandedSwingArray,
elementsof(twoHandedSwingArray));
ARRAYSIZE(twoHandedSwingArray));
// Construct a subset of all high two handed swing types
const uint8 twoHandedHighSwingArray[] = {
@ -3295,7 +3295,7 @@ const uint8 twoHandedHighSwingArray[] = {
const CombatMotionSet twoHandedHighSwingSet =
CombatMotionSet(
twoHandedHighSwingArray,
elementsof(twoHandedHighSwingArray));
ARRAYSIZE(twoHandedHighSwingArray));
// Construct a subset of all low two handed swing types
const uint8 twoHandedLowSwingArray[] = {
@ -3307,7 +3307,7 @@ const uint8 twoHandedLowSwingArray[] = {
const CombatMotionSet twoHandedLowSwingSet =
CombatMotionSet(
twoHandedLowSwingArray,
elementsof(twoHandedLowSwingArray));
ARRAYSIZE(twoHandedLowSwingArray));
//-----------------------------------------------------------------------
// Handle all two handed swing motions
@ -3402,7 +3402,7 @@ const uint8 oneHandedSwingArray[] = {
const CombatMotionSet oneHandedSwingSet =
CombatMotionSet(
oneHandedSwingArray,
elementsof(oneHandedSwingArray));
ARRAYSIZE(oneHandedSwingArray));
// Construct a subset of all high one handed swing types
const uint8 oneHandedHighSwingArray[] = {
@ -3412,7 +3412,7 @@ const uint8 oneHandedHighSwingArray[] = {
const CombatMotionSet oneHandedHighSwingSet =
CombatMotionSet(
oneHandedHighSwingArray,
elementsof(oneHandedHighSwingArray));
ARRAYSIZE(oneHandedHighSwingArray));
// Construct a subset of all low one handed swing types
const uint8 oneHandedLowSwingArray[] = {
@ -3422,7 +3422,7 @@ const uint8 oneHandedLowSwingArray[] = {
const CombatMotionSet oneHandedLowSwingSet =
CombatMotionSet(
oneHandedLowSwingArray,
elementsof(oneHandedLowSwingArray));
ARRAYSIZE(oneHandedLowSwingArray));
//-----------------------------------------------------------------------
// Handle all one handed swing motions

View File

@ -1250,7 +1250,7 @@ void GameObject::deleteObject(void) {
if (a->leftHandObject == id) a->leftHandObject = Nothing;
if (a->rightHandObject == id) a->rightHandObject = Nothing;
for (i = 0; i < elementsof(a->armorObjects); i++)
for (i = 0; i < ARRAYSIZE(a->armorObjects); i++)
if (a->armorObjects[i] == id)
a->wear(Nothing, i);
}
@ -3246,7 +3246,7 @@ static ActiveRegion activeRegionList[playerActors];
void updateActiveRegions(void) {
int16 i;
for (i = 0; i < elementsof(activeRegionList); i++)
for (i = 0; i < ARRAYSIZE(activeRegionList); i++)
activeRegionList[i].update();
}
@ -3761,7 +3761,7 @@ bool ActiveRegionObjectIterator::nextActiveRegion(void) {
TilePoint currentRegionSize;
do {
if (++activeRegionIndex >= elementsof(activeRegionList))
if (++activeRegionIndex >= ARRAYSIZE(activeRegionList))
return false;
int16 prevRegionIndex;
@ -3941,7 +3941,7 @@ ObjectID ActiveRegionObjectIterator::first(GameObject **obj) {
ObjectID ActiveRegionObjectIterator::next(GameObject **obj) {
assert(activeRegionIndex >= 0);
assert(activeRegionIndex < elementsof(activeRegionList));
assert(activeRegionIndex < ARRAYSIZE(activeRegionList));
ObjectID currentObjectID;

View File

@ -786,7 +786,7 @@ bool ProtoObj::acceptInsertionAtAction(
// Creates a color translation table for this object
void ProtoObj::getColorTranslation(ColorTable map) {
buildColorTable(map, colorMap, elementsof(colorMap));
buildColorTable(map, colorMap, ARRAYSIZE(colorMap));
}
uint16 ProtoObj::containmentSet(void) {
@ -1106,7 +1106,7 @@ bool InventoryProto::dropAction(
static const int8 dirOffsetTable[] = { 0, 1, -1, 2, -2, 3, -3 };
for (i = 0; i < elementsof(dirOffsetTable); i++) {
for (i = 0; i < ARRAYSIZE(dirOffsetTable); i++) {
TilePoint testPt;
Direction testDir;
@ -2852,7 +2852,7 @@ ContainerWindow *EnchantmentProto::makeWindow( GameObject *Obj )
// set the decorations for this window
window->setDecorations( enchantDecorations,
elementsof( enchantDecorations ),
ARRAYSIZE( enchantDecorations ),
decRes, 'E', 'F', 'R' );

View File

@ -867,13 +867,13 @@ DirMaskGroup *MaskComputer::computeMask(uint8 crossSection) {
}
}
if (arraySize < elementsof(array)) {
if (arraySize < ARRAYSIZE(array)) {
// Allocate a new place for this mask group
maskGroup = ptrArray[arraySize] = &array[arraySize];
arraySize++;
} else
// Discard last referenced mask group in array
maskGroup = ptrArray[elementsof(array) - 1];
maskGroup = ptrArray[ARRAYSIZE(array) - 1];
// Compute the new group of masks
maskGroup->computeMask(crossSection);
@ -1525,12 +1525,12 @@ void PathRequest::initialize(void) {
*tablePtrPtr = node;
if (nextAvailableLookupNode
>= elementsof(volumeLookupNodePool))
>= ARRAYSIZE(volumeLookupNodePool))
goto big_break;
}
}
if (++objectVolumes >= elementsof(objectVolumeArray)) break;
if (++objectVolumes >= ARRAYSIZE(objectVolumeArray)) break;
}
big_break:
@ -1607,7 +1607,7 @@ void PathRequest::finish(void) {
assert(cell != nullptr);
if (cell->direction != dirInvalid) {
res = &tempResult[elementsof(tempResult)];
res = &tempResult[ARRAYSIZE(tempResult)];
prevDir = dirInvalid;
@ -1648,8 +1648,8 @@ void PathRequest::finish(void) {
}
if (resultSteps) {
while (stepCount < elementsof(path)
&& res < &tempResult[elementsof(tempResult)]) {
while (stepCount < ARRAYSIZE(path)
&& res < &tempResult[ARRAYSIZE(tempResult)]) {
*resultSteps++ = *res++;
stepCount++;
}

View File

@ -510,7 +510,7 @@ void PlayerActor::handleAttacked(void) {
// Return a pointer to a PlayerActor given it's ID
PlayerActor *getPlayerActorAddress(PlayerActorID id) {
assert(id >= 0 && id < elementsof(playerList));
assert(id >= 0 && id < ARRAYSIZE(playerList));
return &playerList[id];
}

View File

@ -2342,7 +2342,7 @@ C_Call *actorCFuncList[] = {
scriptActorImNotQuiteDead,
};
CallTable actorCFuncs = { actorCFuncList, elementsof(actorCFuncList), 0 };
CallTable actorCFuncs = { actorCFuncList, ARRAYSIZE(actorCFuncList), 0 };
//-----------------------------------------------------------------------
// Return the id of this TAI
@ -2615,7 +2615,7 @@ C_Call *tagCFuncList[] = {
scriptTagReleaseLock,
};
CallTable tagCFuncs = { tagCFuncList, elementsof(tagCFuncList), 0 };
CallTable tagCFuncs = { tagCFuncList, ARRAYSIZE(tagCFuncList), 0 };
//-----------------------------------------------------------------------
// Find a mission by generator id
@ -2696,7 +2696,7 @@ C_Call *missionCFuncList[] = {
scriptMissionMakeActor,
};
CallTable missionCFuncs = { missionCFuncList, elementsof(missionCFuncList), 0 };
CallTable missionCFuncs = { missionCFuncList, ARRAYSIZE(missionCFuncList), 0 };
//-----------------------------------------------------------------------
// Global functions
@ -4014,6 +4014,6 @@ C_Call *globalCFuncList[] = {
scriptBigMul,
};
CallTable globalCFuncs = { globalCFuncList, elementsof(globalCFuncList), 0 };
CallTable globalCFuncs = { globalCFuncList, ARRAYSIZE(globalCFuncList), 0 };
} // end of namespace Saga2

View File

@ -482,7 +482,7 @@ bool ProtaganistSensor::check(SenseInfo &info, uint32 senseFlags) {
int16 i;
bool objIsActor = isActor(getObject());
for (i = 0; i < (long)elementsof(playerActorIDs); i++) {
for (i = 0; i < (long)ARRAYSIZE(playerActorIDs); i++) {
Actor *protag =
getPlayerActorAddress(playerActorIDs[i])->getActor();

View File

@ -680,18 +680,18 @@ void abortAllSpeeches(void) {
void sentenceGenerator(char *sentence) {
int16 index;
index = rand() % elementsof(names);
index = rand() % ARRAYSIZE(names);
strcat(sentence, names[index]);
index = rand() % elementsof(verbs);
index = rand() % ARRAYSIZE(verbs);
strcat(sentence, verbs[index]);
index = rand() % elementsof(adjectives);
index = rand() % ARRAYSIZE(adjectives);
strcat(sentence, adjectives[index]);
index = rand() % elementsof(nouns);
index = rand() % ARRAYSIZE(nouns);
strcat(sentence, nouns[index]);
// for(int i=0; i<elementsof(sentenceParts); i++)
// for(int i=0; i<ARRAYSIZE(sentenceParts); i++)
// {
// strcat(sentence,sentenceParts[i].index = rand() % elementsof(sentenceParts[i]);
// strcat(sentence,sentenceParts[i].index = rand() % ARRAYSIZE(sentenceParts[i]);
// }
}
@ -1015,7 +1015,7 @@ bool isVisible(GameObject *obj) {
SpeechTaskList::SpeechTaskList(void) {
lockFlag = false;
for (int i = 0; i < (long)elementsof(array); i++) {
for (int i = 0; i < (long)ARRAYSIZE(array); i++) {
free.addTail(array[i]);
}
}
@ -1032,7 +1032,7 @@ SpeechTaskList::SpeechTaskList(void **buf) {
lockFlag = false;
// Initialize the free list
for (i = 0; i < (long)elementsof(array); i++) {
for (i = 0; i < (long)ARRAYSIZE(array); i++) {
free.addTail(array[i]);
}

View File

@ -572,7 +572,7 @@ void ActorAppearance::loadSpriteBanks(int16 banksNeeded) {
appearanceLRU.push_back(this);
// Load in additional sprite banks if requested...
for (bank = 0; bank < (long)elementsof(spriteBanks); bank++) {
for (bank = 0; bank < (long)ARRAYSIZE(spriteBanks); bank++) {
// Load the sprite handle...
if (spriteBanks[bank] == nullptr && (banksNeeded & (1 << bank))) {
Common::SeekableReadStream *stream = loadResourceToStream(spriteRes, id + MKTAG(0, 0, 0, bank), "sprite bank");
@ -666,7 +666,7 @@ ActorAppearance *LoadActorAppearance(uint32 id, int16 banksNeeded) {
}
// Dump the sprites being stored
for (bank = 0; bank < (long)elementsof(aa->spriteBanks); bank++) {
for (bank = 0; bank < (long)ARRAYSIZE(aa->spriteBanks); bank++) {
if (aa->spriteBanks[bank])
delete aa->spriteBanks[bank];
aa->spriteBanks[bank] = nullptr;
@ -845,7 +845,7 @@ void initSprites(void) {
initQuickMem(0x10000);
// Initialize actor appearance table
for (i = 0; i < elementsof(appearanceTable); i++) {
for (i = 0; i < ARRAYSIZE(appearanceTable); i++) {
ActorAppearance *aa = &appearanceTable[i];
aa->useCount = 0;

View File

@ -38,13 +38,8 @@ typedef uint32 ChunkID;
#define FTA
// #define LEAVE goto exitit // bail out of function
#define unless(x) if((x)==NULL) // an inverted if statement
#ifndef elementsof
#define elementsof(x) (sizeof(x)/sizeof(x[0]))
#endif
#ifndef offsetof
#define offsetof(type,field) (uint32)&(((type *)0)->field)
#endif

View File

@ -2170,11 +2170,11 @@ TilePoint GoAwayFromActorTask::getRepulsionVector(void) {
repulsionVector;
int16 i;
TilePoint locArray[6];
int16 strengthArray[elementsof(locArray)] =
int16 strengthArray[ARRAYSIZE(locArray)] =
{ 1, 1, 1, 1, 1, 1 };
int16 distArray[elementsof(locArray)];
int16 distArray[ARRAYSIZE(locArray)];
TargetLocationArray tla(
elementsof(locArray),
ARRAYSIZE(locArray),
locArray,
distArray);
@ -2728,9 +2728,9 @@ void HuntToBeNearObjectTask::evaluateTarget(void) {
Actor *a = stack->getActor();
int16 i;
GameObject *objArray[16];
int16 distArray[elementsof(objArray)];
int16 distArray[ARRAYSIZE(objArray)];
TargetObjectArray toa(
elementsof(objArray),
ARRAYSIZE(objArray),
objArray,
distArray);
SenseInfo info;
@ -2867,9 +2867,9 @@ void HuntToPossessTask::evaluateTarget(void) {
Actor *a = stack->getActor();
int16 i;
GameObject *objArray[16];
int16 distArray[elementsof(objArray)];
int16 distArray[ARRAYSIZE(objArray)];
TargetObjectArray toa(
elementsof(objArray),
ARRAYSIZE(objArray),
objArray,
distArray);
SenseInfo info;
@ -3166,9 +3166,9 @@ void HuntToBeNearActorTask::evaluateTarget(void) {
Actor *a = stack->getActor();
int16 i;
Actor *actorArray[16];
int16 distArray[elementsof(actorArray)];
int16 distArray[ARRAYSIZE(actorArray)];
TargetActorArray taa(
elementsof(actorArray),
ARRAYSIZE(actorArray),
actorArray,
distArray);
SenseInfo info;
@ -3411,9 +3411,9 @@ void HuntToKillTask::evaluateTarget(void) {
ActorProto *proto = (ActorProto *)a->proto();
int16 i;
Actor *actorArray[16];
int16 distArray[elementsof(actorArray)];
int16 distArray[ARRAYSIZE(actorArray)];
TargetActorArray taa(
elementsof(actorArray),
ARRAYSIZE(actorArray),
actorArray,
distArray);
SenseInfo info;
@ -3921,8 +3921,8 @@ void BandTask::evaluateTarget(void) {
TilePoint repulsorVector;
int16 repulsorStrength;
TilePoint repulsorVectorArray[6];
int16 repulsorStrengthArray[elementsof(repulsorVectorArray)];
int16 repulsorDistArray[elementsof(repulsorVectorArray)];
int16 repulsorStrengthArray[ARRAYSIZE(repulsorVectorArray)];
int16 repulsorDistArray[ARRAYSIZE(repulsorVectorArray)];
int16 repulsorCount;
bool repulsorFlag;
@ -3950,7 +3950,7 @@ void BandTask::evaluateTarget(void) {
int16 j = repulsorCount;
if (repulsorDist < repulsorDistArray[j - 1]) {
if (repulsorCount < (long)elementsof(repulsorVectorArray)) {
if (repulsorCount < (long)ARRAYSIZE(repulsorVectorArray)) {
repulsorDistArray[j] = repulsorDistArray[j - 1];
repulsorVectorArray[j] = repulsorVectorArray[j - 1];
repulsorStrengthArray[j] = repulsorStrengthArray[j - 1];
@ -3965,8 +3965,8 @@ void BandTask::evaluateTarget(void) {
j--;
}
if (j < (long)elementsof(repulsorVectorArray)) {
if (repulsorCount < (long)elementsof(repulsorVectorArray))
if (j < (long)ARRAYSIZE(repulsorVectorArray)) {
if (repulsorCount < (long)ARRAYSIZE(repulsorVectorArray))
repulsorCount++;
repulsorDistArray[j] = repulsorDist;
repulsorVectorArray[j] = repulsorVector;
@ -4099,8 +4099,8 @@ bool BandTask::BandAndAvoidEnemiesRepulsorIterator::firstEnemyRepulsor(
int16 &repulsorStrength) {
assert(iteratingThruEnemies);
int16 actorDistArray[elementsof(actorArray)];
TargetActorArray taa(elementsof(actorArray), actorArray, actorDistArray);
int16 actorDistArray[ARRAYSIZE(actorArray)];
TargetActorArray taa(ARRAYSIZE(actorArray), actorArray, actorDistArray);
ActorPropertyTarget target(actorPropIDEnemy);
numActors = target.actor(a->world(), a->getLocation(), taa);

View File

@ -984,7 +984,7 @@ static TileActivityTaskList &aTaskList =
// Constructor
TileActivityTaskList::TileActivityTaskList(void) {
for (uint i = 0; i < elementsof(array); i++) {
for (uint i = 0; i < ARRAYSIZE(array); i++) {
free.addTail(array[i]);
}
}
@ -997,7 +997,7 @@ TileActivityTaskList::TileActivityTaskList(void **buf) {
int16 taskCount;
for (uint i = 0; i < elementsof(array); i++) {
for (uint i = 0; i < ARRAYSIZE(array); i++) {
free.addTail(array[i]);
}
@ -2481,7 +2481,7 @@ void WorldMapData::buildInstanceHash(void) {
if (ai->_data.itemType == activeTypeInstance) {
hashVal = (((ai->_data.instance.u + ai->_data.instance.h) << 4)
+ ai->_data.instance.v + (ai->_data.instance.groupID << 2))
% elementsof(instHash);
% ARRAYSIZE(instHash);
itemHash.setVal(hashVal, ai);
}
@ -2496,7 +2496,7 @@ ActiveItem *WorldMapData::findHashedInstance(
TilePoint &tp,
int16 group) {
int16 hashVal = (((tp.u + tp.z) << 4) + tp.v + (group << 2))
% elementsof(instHash);
% ARRAYSIZE(instHash);
if (itemHash.contains(hashVal))
return itemHash.getVal(hashVal);
@ -2865,7 +2865,7 @@ void buildRipTables(void) {
int16 tableIndex;
// bit array of available rip tables
uint8 tableAvail[(elementsof(ripTableList) + 7) >> 3];
uint8 tableAvail[(ARRAYSIZE(ripTableList) + 7) >> 3];
memset(tableAvail, 0xFF, sizeof(tableAvail));
@ -2899,7 +2899,7 @@ void buildRipTables(void) {
uint j;
// Find available table
for (j = 0; j < elementsof(ripTableList); j++) {
for (j = 0; j < ARRAYSIZE(ripTableList); j++) {
if (tableAvail[j >> 3] & (1 << (j & 0x7)))
break;
}

View File

@ -668,7 +668,7 @@ void loadTileModeState(SaveFileReader &saveGame) {
void TileModeSetup(void) {
// Load in decorative panels for the main window (for this mode)
mainWindow->setDecorations(mainWindowDecorations, elementsof(mainWindowDecorations), imageRes);
mainWindow->setDecorations(mainWindowDecorations, ARRAYSIZE(mainWindowDecorations), imageRes);
// Test to draw borders.
// REM: We should actually have a routine to refresh the window...

View File

@ -737,7 +737,7 @@ int16 FileDialog(int16 fileProcess) {
win->setDecorations(saveWindowDecorations,
elementsof(saveWindowDecorations),
ARRAYSIZE(saveWindowDecorations),
decRes, 'S', 'L', 'D');
win->userData = &rInfo;
@ -922,7 +922,7 @@ int16 OptionsDialog(bool disableSaveResume) {
}
win->setDecorations(optionsDecorations,
elementsof(optionsDecorations),
ARRAYSIZE(optionsDecorations),
decRes, 'O', 'P', 'T');
@ -1035,7 +1035,7 @@ bool initUserDialog(void) {
udWin = new ModalWindow(messageWindowRect, 0 nullptr);
udWin->setDecorations(messageDecorations,
elementsof(messageDecorations),
ARRAYSIZE(messageDecorations),
udDecRes, 'M', 'E', 'S');
udWin->userData = &udrInfo;
@ -1237,7 +1237,7 @@ int16 userDialog(const char *title, const char *msg, const char *bMsg1,
new CPlacardPanel(*win, messageTextRects[1], msg, &Onyx10Font, 0, pal, 0, nullptr);
win->setDecorations(messageDecorations,
elementsof(messageDecorations),
ARRAYSIZE(messageDecorations),
decRes, 'M', 'E', 'S');
@ -1539,7 +1539,7 @@ void placardWindow(int8 type, char *text) {
// setup the background imagery
win->setDecorations(plaqDecWood,
elementsof(plaqDecWood),
ARRAYSIZE(plaqDecWood),
resContext, 'P', 'L', 'Q');
break;
@ -1554,7 +1554,7 @@ void placardWindow(int8 type, char *text) {
// setup the background imagery
win->setDecorations(plaqDecStone,
elementsof(plaqDecStone),
ARRAYSIZE(plaqDecStone),
resContext, 'P', 'L', 'Q');
break;
@ -1569,7 +1569,7 @@ void placardWindow(int8 type, char *text) {
// setup the background imagery
win->setDecorations(plaqDecBrass,
elementsof(plaqDecBrass),
ARRAYSIZE(plaqDecBrass),
resContext, 'P', 'L', 'Q');
break;

View File

@ -137,7 +137,7 @@ void CVideoBox::init(void) {
// get the decorations for this window
setDecorations(vidDec,
elementsof(vidDec),
ARRAYSIZE(vidDec),
decRes,
'V', 'B', 'D');

View File

@ -247,7 +247,7 @@ void createPalette(
int i;
uint32 fadeProgress = (elapsedTime << 8) / totalTime_;
for (i = 0; i < (long)elementsof(newP->entry); i++) {
for (i = 0; i < (long)ARRAYSIZE(newP->entry); i++) {
gPaletteEntry *srcPal = &srcP->entry[i];
gPaletteEntry *dstPal = &dstP->entry[i];
gPaletteEntry *curPal = &newP->entry[i];