mirror of
https://github.com/libretro/scummvm.git
synced 2024-12-12 20:17:49 +00:00
ULTIMA8: Add a helper function to clean up list code
This commit is contained in:
parent
adebe08365
commit
6b66d7007a
@ -77,6 +77,14 @@ public:
|
||||
_size++;
|
||||
}
|
||||
|
||||
void appenduint16(uint16 val) {
|
||||
assert(_elementSize == 2);
|
||||
uint8 buf[2];
|
||||
buf[0] = static_cast<uint8>(val);
|
||||
buf[1] = static_cast<uint8>(val >> 8);
|
||||
append(buf);
|
||||
}
|
||||
|
||||
void remove(const uint8 *e) {
|
||||
// do we need to erase all occurences of e or just the first one?
|
||||
// (deleting all, currently)
|
||||
@ -105,20 +113,23 @@ public:
|
||||
}
|
||||
|
||||
void appendList(const UCList &l) {
|
||||
// need to check if elementsizes match...
|
||||
// elementsizes should match...
|
||||
assert(_elementSize == l.getElementSize());
|
||||
_elements.reserve(_elementSize * (_size + l._size));
|
||||
unsigned int lsize = l._size;
|
||||
for (unsigned int i = 0; i < lsize; i++)
|
||||
for (unsigned int i = 0; i < l._size; i++)
|
||||
append(l[i]);
|
||||
}
|
||||
void unionList(const UCList &l) { // like append, but remove duplicates
|
||||
// need to check if elementsizes match...
|
||||
// elementsizes should match...
|
||||
assert(_elementSize == l.getElementSize());
|
||||
_elements.reserve(_elementSize * (_size + l._size));
|
||||
for (unsigned int i = 0; i < l._size; i++)
|
||||
if (!inList(l[i]))
|
||||
append(l[i]);
|
||||
}
|
||||
void subtractList(const UCList &l) {
|
||||
// elementsizes should match...
|
||||
assert(_elementSize == l.getElementSize());
|
||||
for (unsigned int i = 0; i < l._size; i++)
|
||||
remove(l[i]);
|
||||
}
|
||||
|
@ -275,10 +275,7 @@ void Container::containerSearch(UCList *itemlist, const uint8 *loopscript,
|
||||
if ((*iter)->checkLoopScript(loopscript, scriptsize)) {
|
||||
assert(itemlist->getElementSize() == 2);
|
||||
uint16 oId = (*iter)->getObjId();
|
||||
uint8 buf[2];
|
||||
buf[0] = static_cast<uint8>(oId);
|
||||
buf[1] = static_cast<uint8>(oId >> 8);
|
||||
itemlist->append(buf);
|
||||
itemlist->appenduint16(oId);
|
||||
}
|
||||
|
||||
if (recurse) {
|
||||
|
@ -607,11 +607,7 @@ void CurrentMap::areaSearch(UCList *itemlist, const uint8 *loopscript,
|
||||
// check item against loopscript
|
||||
if (item->checkLoopScript(loopscript, scriptsize)) {
|
||||
assert(itemlist->getElementSize() == 2);
|
||||
const uint16 objid = item->getObjId();
|
||||
uint8 buf[2];
|
||||
buf[0] = static_cast<uint8>(objid);
|
||||
buf[1] = static_cast<uint8>(objid >> 8);
|
||||
itemlist->append(buf);
|
||||
itemlist->appenduint16(item->getObjId());
|
||||
}
|
||||
|
||||
if (recurse) {
|
||||
@ -696,11 +692,7 @@ void CurrentMap::surfaceSearch(UCList *itemlist, const uint8 *loopscript,
|
||||
// check item against loopscript
|
||||
if (item->checkLoopScript(loopscript, scriptsize)) {
|
||||
assert(itemlist->getElementSize() == 2);
|
||||
uint16 objid = item->getObjId();
|
||||
uint8 buf[2];
|
||||
buf[0] = static_cast<uint8>(objid);
|
||||
buf[1] = static_cast<uint8>(objid >> 8);
|
||||
itemlist->append(buf);
|
||||
itemlist->appenduint16(item->getObjId());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user