diff options
author | Eugene Sandulenko | 2014-12-25 12:36:47 +0100 |
---|---|---|
committer | Eugene Sandulenko | 2015-12-15 00:05:02 +0100 |
commit | 471dbaa758f0ebea9f3d76caa7fd769c6809d395 (patch) | |
tree | 9f786ded0254e4efddc387e48dfc420645b414d0 /engines/lab/labsets.cpp | |
parent | 6ab5edf7629ae2166b0fdc9773005d240ade5d3e (diff) | |
download | scummvm-rg350-471dbaa758f0ebea9f3d76caa7fd769c6809d395.tar.gz scummvm-rg350-471dbaa758f0ebea9f3d76caa7fd769c6809d395.tar.bz2 scummvm-rg350-471dbaa758f0ebea9f3d76caa7fd769c6809d395.zip |
LAB: Started objectifying LargeSets
Diffstat (limited to 'engines/lab/labsets.cpp')
-rw-r--r-- | engines/lab/labsets.cpp | 86 |
1 files changed, 39 insertions, 47 deletions
diff --git a/engines/lab/labsets.cpp b/engines/lab/labsets.cpp index 86fd6fd60b..cee9cda56b 100644 --- a/engines/lab/labsets.cpp +++ b/engines/lab/labsets.cpp @@ -33,65 +33,57 @@ namespace Lab { -const uint32 LargeSetSIZE = sizeof(LargeSetRecord) - 2; - - - -/*****************************************************************************/ -/* Creates a large set. */ -/*****************************************************************************/ -bool createSet(LargeSet *set, uint16 last) { +LabSet::LabSet(uint16 last) { last = (((last + 15) >> 4) << 4); - if ((*set = (LargeSet)calloc((last >> 3) + LargeSetSIZE, 1))) { - (*set)->lastElement = last; - return true; - } else /* Not Enough Memory! */ - return false; - + _array = (uint16 *)calloc(last >> 3); } - - - -/*****************************************************************************/ -/* Deletes a large set. */ -/*****************************************************************************/ -void deleteSet(LargeSet set) { - if (set) - free(set); +LargeSet::~LargeSet() { + free(_array); } - -#define INCL(BITSET,BIT) ((BITSET) |= (BIT)) - -#define EXCL(BITSET,BIT) ((BITSET) &= (~(BIT))) - - - -/*****************************************************************************/ -/* Tests if an element is in the set. */ -/*****************************************************************************/ -bool In(LargeSet set, uint16 element) { - return ((1 << ((element - 1) % 16)) & (set->array[(element - 1) >> 4])) > 0; +bool LargeSet::in(uint16 element) { + return ((1 << ((element - 1) % 16)) & (_array[(element - 1) >> 4])) > 0; } - - -/*****************************************************************************/ -/* Sets an element in the Large set. */ -/*****************************************************************************/ -void inclElement(LargeSet set, uint16 element) { - INCL((set->array[(element - 1) >> 4]), (1 << ((element - 1) % 16))); +void LargeSet::inclElement(uint16 element) { + _array[(element - 1) >> 4]) |= 1 << ((element - 1) % 16); } +void LargeSet::exclElement(uint16 element) { + _array[(element - 1) >> 4] &= ~(1 << ((element - 1) % 16)); +} +bool LargeSet::readInitialConditions(const char *fileName) { + byte **file; + uint16 many, set; + char temp[5]; + + if ((file = g_music->newOpen(fileName)) != NULL) { + readBlock(temp, 4L, file); + temp[4] = '\0'; + + if (strcmp(temp, "CON0") != 0) + return false; + + readBlock(&many, 2L, file); +#if !defined(DOSCODE) + swapUShortPtr(&many, 1); +#endif + + for (int counter = 0; counter < many; counter++) { + readBlock(&set, 2L, file); +#if !defined(DOSCODE) + swapUShortPtr(&set, 1); +#endif + inclElement(set); + } + } else + return false; -/*****************************************************************************/ -/* Removes an element in the Large set. */ -/*****************************************************************************/ -void exclElement(LargeSet set, uint16 element) { - EXCL((set->array[(element - 1) >> 4]), (1 << ((element - 1) % 16))); + return true; } + } // End of namespace Lab |