Ticket #8849: hashmap_v2.patch
File hashmap_v2.patch, 17.7 KB (added by , 17 years ago) |
---|
-
common/hashmap.h
150 150 int lookupAndCreateIfMissing(const Key &key); 151 151 void expand_array(uint newsize); 152 152 153 class Iterator; 154 class ConstIterator; 155 friend class Iterator; 156 friend class ConstIterator; 153 template<class T> friend class IteratorImpl; 157 154 158 155 /** 159 156 * Simple HashMap iterator implementation. 160 157 */ 161 class Iterator { 158 template<class NodeType> 159 class IteratorImpl { 160 friend class HashMap; 161 template<class T> friend class IteratorImpl; 162 162 protected: 163 163 typedef const HashMap hashmap_t; 164 friend class HashMap;165 164 166 // Allow ConstIterator to read member vars, so that Iterators can be converted to ConstIterator167 friend class HashMap::ConstIterator;168 169 165 uint _idx; 170 166 hashmap_t *_hashmap; 171 167 172 168 protected: 173 Iterator (uint idx, hashmap_t *hashmap) : _idx(idx), _hashmap(hashmap) {}169 IteratorImpl(uint idx, hashmap_t *hashmap) : _idx(idx), _hashmap(hashmap) {} 174 170 175 Node *deref() const {171 NodeType *deref() const { 176 172 assert(_hashmap != 0); 177 173 assert(_idx < _hashmap->_arrsize); 178 174 Node *node = _hashmap->_arr[_idx]; … … 181 177 } 182 178 183 179 public: 184 Iterator() : _idx(0), _hashmap(0) {} 180 IteratorImpl() : _idx(0), _hashmap(0) {} 181 template<class T> 182 IteratorImpl(const IteratorImpl<T> &c) : _idx(c._idx), _hashmap(c._hashmap) {} 185 183 186 Node &operator *() const { return *deref(); }187 Node *operator->() const { return deref(); }184 NodeType &operator *() const { return *deref(); } 185 NodeType *operator->() const { return deref(); } 188 186 189 bool operator ==(const Iterator &iter) const { return _idx == iter._idx && _hashmap == iter._hashmap; }190 bool operator !=(const Iterator &iter) const { return !(*this == iter); }187 bool operator ==(const IteratorImpl &iter) const { return _idx == iter._idx && _hashmap == iter._hashmap; } 188 bool operator !=(const IteratorImpl &iter) const { return !(*this == iter); } 191 189 192 Iterator &operator ++() {190 IteratorImpl &operator ++() { 193 191 assert(_hashmap); 194 192 do { 195 193 _idx++; … … 200 198 return *this; 201 199 } 202 200 203 Iterator operator ++(int) {204 Iterator old = *this;201 IteratorImpl operator ++(int) { 202 IteratorImpl old = *this; 205 203 operator ++(); 206 204 return old; 207 205 } 208 206 }; 209 207 210 /**211 * Simple HashMap const iterator implementation.212 * This is almost completely identical to the normal iterator class, only213 * with some const keywords added here and there, plus a conversion214 * operator which makes it possible to transparently convert iterators to215 * const iterators.216 * It is sadly not really possible to reduce this code duplication using217 * template, unless one is willing to accept various warnings on certain218 * compilers. Note that many (most? all?) implementations of the standard219 * C++ library use a similar approach for their implementations.220 */221 class ConstIterator {222 protected:223 typedef const HashMap hashmap_t;224 friend class HashMap;225 226 uint _idx;227 hashmap_t *_hashmap;228 229 protected:230 ConstIterator(uint idx, hashmap_t *hashmap) : _idx(idx), _hashmap(hashmap) {}231 232 const Node *deref() const {233 assert(_hashmap != 0);234 assert(_idx < _hashmap->_arrsize);235 const Node *node = _hashmap->_arr[_idx];236 assert(node != 0);237 return node;238 }239 240 public:241 ConstIterator() : _idx(0), _hashmap(0) {}242 243 // Converting a non-const iterator to a const one is allowed244 ConstIterator(const Iterator &iter) : _idx(iter._idx), _hashmap(iter._hashmap) {}245 246 const Node &operator *() const { return *deref(); }247 const Node *operator->() const { return deref(); }248 249 bool operator ==(const ConstIterator &iter) const { return _idx == iter._idx && _hashmap == iter._hashmap; }250 bool operator !=(const ConstIterator &iter) const { return !(*this == iter); }251 252 ConstIterator &operator ++() {253 assert(_hashmap);254 do {255 _idx++;256 } while (_idx < _hashmap->_arrsize && _hashmap->_arr[_idx] == 0);257 if (_idx >= _hashmap->_arrsize)258 _idx = (uint)-1;259 260 return *this;261 }262 263 ConstIterator operator ++(int) {264 ConstIterator old = *this;265 operator ++();266 return old;267 }268 };269 270 208 public: 271 typedef Iterator iterator;272 typedef ConstIteratorconst_iterator;209 typedef IteratorImpl<Node> iterator; 210 typedef IteratorImpl<const Node> const_iterator; 273 211 274 212 HashMap(); 275 213 HashMap(const HM_t& map); -
engines/sword1/sword1.cpp
339 339 _logic->initialize(); 340 340 _objectMan->initialize(); 341 341 _mouse->initialize(); 342 _control = new Control( _saveFileMan, _resMan, _objectMan, _system, _mouse, _sound, _music);342 _control = new Control(this, _saveFileMan, _resMan, _objectMan, _system, _mouse, _sound, _music); 343 343 344 344 return 0; 345 345 } -
engines/sword1/control.h
42 42 class Mouse; 43 43 class Music; 44 44 class Sound; 45 class SwordEngine; 45 46 46 47 #define MAX_BUTTONS 16 47 48 … … 82 83 83 84 class Control { 84 85 public: 85 Control( Common::SaveFileManager *saveFileMan, ResMan *pResMan, ObjectMan *pObjMan, OSystem *system, Mouse *pMouse, Sound *pSound, Music *pMusic);86 Control(SwordEngine *engine, Common::SaveFileManager *saveFileMan, ResMan *pResMan, ObjectMan *pObjMan, OSystem *system, Mouse *pMouse, Sound *pSound, Music *pMusic); 86 87 uint8 runPanel(void); 87 88 void doRestore(void); 88 89 void askForCd(void); … … 134 135 static const uint8 _languageStrings[8 * 20][43]; 135 136 const uint8 (*_lStrings)[43]; 136 137 Common::SaveFileManager *_saveFileMan; 138 SwordEngine *_engine; 137 139 ObjectMan *_objMan; 138 140 ResMan *_resMan; 139 141 OSystem *_system; -
engines/sword1/control.cpp
160 160 draw(); 161 161 } 162 162 163 Control::Control(Common::SaveFileManager *saveFileMan, ResMan *pResMan, ObjectMan *pObjMan, OSystem *system, Mouse *pMouse, Sound *pSound, Music *pMusic) { 163 Control::Control(SwordEngine *engine, Common::SaveFileManager *saveFileMan, ResMan *pResMan, ObjectMan *pObjMan, OSystem *system, Mouse *pMouse, Sound *pSound, Music *pMusic) { 164 _engine = engine; 164 165 _saveFileMan = saveFileMan; 165 166 _resMan = pResMan; 166 167 _objMan = pObjMan; … … 717 718 718 719 void Control::readSavegameDescriptions(void) { 719 720 Common::InSaveFile *inf; 720 inf = _saveFileMan->openForLoading( "SAVEGAME.INF");721 inf = _saveFileMan->openForLoading((_engine->getTargetName() + ".inf").c_str()); 721 722 _saveScrollPos = _saveFiles = 0; 722 723 _selectedSavegame = 255; 723 724 for (uint8 cnt = 0; cnt < 64; cnt++) { … … 761 762 762 763 void Control::writeSavegameDescriptions(void) { 763 764 Common::OutSaveFile *outf; 764 outf = _saveFileMan->openForSaving( "SAVEGAME.INF");765 outf = _saveFileMan->openForSaving((_engine->getTargetName() + ".inf").c_str()); 765 766 766 767 if (!outf) { 767 768 // Display an error message, and do nothing 768 displayMessage(0, "Can't create SAVEGAME.INF. (%s)", _saveFileMan->popErrorDesc().c_str());769 displayMessage(0, "Can't create %s.inf. (%s)", _engine->getTargetName().c_str(), _saveFileMan->popErrorDesc().c_str()); 769 770 return; 770 771 } 771 772 … … 784 785 } 785 786 outf->finalize(); 786 787 if (outf->ioFailed()) 787 displayMessage(0, "Can't write to SAVEGAME.INF. Device full? (%s)", _saveFileMan->popErrorDesc().c_str());788 displayMessage(0, "Can't write to %s.inf. Device full? (%s)", _engine->getTargetName().c_str(), _saveFileMan->popErrorDesc().c_str()); 788 789 delete outf; 789 790 } 790 791 … … 947 948 } 948 949 949 950 void Control::saveGameToFile(uint8 slot) { 950 char fName[15]; 951 Common::String filename = _engine->getTargetName(); 952 char fName[5]; 953 snprintf(fName, 5, ".%03d", slot); 954 filename += fName; 955 951 956 uint16 cnt; 952 sprintf(fName, "SAVEGAME.%03d", slot);953 957 uint16 liveBuf[TOTAL_SECTIONS]; 954 958 Common::OutSaveFile *outf; 955 outf = _saveFileMan->openForSaving(f Name);959 outf = _saveFileMan->openForSaving(filename.c_str()); 956 960 if (!outf) { 957 961 // Display an error message and do nothing 958 displayMessage(0, "Unable to create file '%s'. (%s)", f Name, _saveFileMan->popErrorDesc().c_str());962 displayMessage(0, "Unable to create file '%s'. (%s)", filename.c_str(), _saveFileMan->popErrorDesc().c_str()); 959 963 return; 960 964 } 961 965 … … 979 983 outf->writeUint32LE(playerRaw[cnt2]); 980 984 outf->finalize(); 981 985 if (outf->ioFailed()) 982 displayMessage(0, "Couldn't write to file '%s'. Device full? (%s)", f Name, _saveFileMan->popErrorDesc().c_str());986 displayMessage(0, "Couldn't write to file '%s'. Device full? (%s)", filename.c_str(), _saveFileMan->popErrorDesc().c_str()); 983 987 delete outf; 984 988 } 985 989 986 990 bool Control::restoreGameFromFile(uint8 slot) { 987 char fName[15]; 991 Common::String filename = _engine->getTargetName(); 992 char fName[5]; 993 snprintf(fName, 5, ".%03d", slot); 994 filename += fName; 995 988 996 uint16 cnt; 989 sprintf(fName, "SAVEGAME.%03d", slot);990 997 Common::InSaveFile *inf; 991 inf = _saveFileMan->openForLoading(f Name);998 inf = _saveFileMan->openForLoading(filename.c_str()); 992 999 if (!inf) { 993 1000 // Display an error message, and do nothing 994 displayMessage(0, "Can't open file '%s'. (%s)", f Name, _saveFileMan->popErrorDesc().c_str());1001 displayMessage(0, "Can't open file '%s'. (%s)", filename.c_str(), _saveFileMan->popErrorDesc().c_str()); 995 1002 return false; 996 1003 } 997 1004 … … 1015 1022 playerBuf[cnt2] = inf->readUint32LE(); 1016 1023 1017 1024 if (inf->ioFailed()) { 1018 displayMessage(0, "Can't read from file '%s'. (%s)", f Name, _saveFileMan->popErrorDesc().c_str());1025 displayMessage(0, "Can't read from file '%s'. (%s)", filename.c_str(), _saveFileMan->popErrorDesc().c_str()); 1019 1026 delete inf; 1020 1027 free(_restoreBuf); 1021 1028 _restoreBuf = NULL; -
engines/sword1/sword1.h
80 80 void reinitialize(void); 81 81 82 82 uint32 _features; 83 84 Common::String getTargetName() const { return _targetName; } 83 85 protected: 84 86 int go(); 85 87 int init(); -
engines/kyra/sequences_v2.cpp
2408 2408 int m = cnt * 11; 2409 2409 uint16 cH = cnt ? READ_LE_UINT16(&tmp[m + 2]) + tmp[m + 9] + (tmp[m + 9] >> 3) : d->h; 2410 2410 2411 c onst char *str = (constchar*)ptr;2411 char *str = (char*)ptr; 2412 2412 2413 ptr = (uint8*)strpbrk( (const char*)str, mark);2413 ptr = (uint8*)strpbrk(str, mark); 2414 2414 if (!ptr) 2415 ptr = (uint8*)strchr( (const char*)str, 0);2415 ptr = (uint8*)strchr(str, 0); 2416 2416 2417 2417 tmp[m + 19] = *ptr; 2418 2418 *ptr = 0; -
engines/kyra/staticres.cpp
1496 1496 } 1497 1497 1498 1498 Button::Callback clickLoadSlotFunctor = BUTTON_FUNCTOR(GUI_v2, this, &GUI_v2::clickLoadSlot); 1499 Button::Callback clickLoadMenuFunctor = BUTTON_FUNCTOR(GUI_v2, this, &GUI_v2::loadMenu); 1499 1500 1500 1501 GUI_V2_MENU(_loadMenu, -1, -1, 0x120, 0xA0, 0xF8, 0xF9, 0xFA, 8, 0xFB, -1, 8, 0, 6, 0x84, 0x16, 0x84, 0x7C); 1501 1502 GUI_V2_MENU_ITEM(_loadMenu.item[0], 1, 0x29, -1, 0x27, 0x100, 0xF, 0xFC, 0xFD, 5, 0xF8, 0xF9, 0xFA, -1, 0, 0, 0, 0); … … 1508 1509 1509 1510 GUI_V2_MENU_ITEM(_loadMenu.item[5], 1, 0x0B, 0xB8, 0x86, 0x58, 0xF, 0xFC, 0xFD, -1, 0xF8, 0xF9, 0xFA, -1, 0, 0, 0, 0); 1510 1511 _loadMenu.item[6].enabled = false; 1512 1513 GUI_V2_MENU(_deathMenu, -1, -1, 0xD0, 0x4C, 0xF8, 0xF9, 0xFA, 0xE, 0xFB, -1, 8, 0, 2, -1, -1, -1, -1); 1514 GUI_V2_MENU_ITEM(_deathMenu.item[0], 1, 2, -1, 0x1E, 0xB4, 0x0F, 0xFC, 0xFD, 8, 0xF8, 0xF9, 0xFA, -1, 0, 0, 0, 0); 1515 _deathMenu.item[0].callback = clickLoadMenuFunctor; 1516 GUI_V2_MENU_ITEM(_deathMenu.item[1], 1, 5, -1, 0x2F, 0xB4, 0x0F, 0xFC, 0xFD, 8, 0xF8, 0xF9, 0xFA, -1, 0, 0, 0, 0); 1517 for (int i = 2; i <= 6; ++i) 1518 _deathMenu.item[i].enabled = false; 1511 1519 } 1512 1520 1513 1521 const uint16 KyraEngine_v2::_itemMagicTable[] = { -
engines/kyra/kyra_v2.h
310 310 311 311 void dinoRide(); 312 312 313 int checkInput(Button *buttonList, bool mainLoop = false );313 int checkInput(Button *buttonList, bool mainLoop = false, bool guiCode = false); 314 314 void removeInputTop(); 315 315 void handleInput(int x, int y); 316 316 bool handleInputUnkSub(int x, int y); -
engines/kyra/gui_v2.h
111 111 Button _menuButtons[7]; 112 112 Button _scrollUpButton; 113 113 Button _scrollDownButton; 114 Menu _loadMenu ;114 Menu _loadMenu, _deathMenu; 115 115 void initStaticData(); 116 116 117 117 const char *getMenuTitle(const Menu &menu); … … 151 151 Menu *_currentMenu; 152 152 bool _isDeathMenu; 153 153 bool _isSaveMenu; 154 bool _madeTempSave; 154 155 bool _loadedSave; 155 156 bool _restartGame; 156 157 bool _reloadTemporarySave; -
engines/kyra/kyra_v2.cpp
411 411 _quitFlag = false; 412 412 _runFlag = true; 413 413 while (!_quitFlag && _runFlag) { 414 //if (_deathHandler >= 0) { 415 // removeHandItem(); 416 // waitTicks(5); 417 // sub_270A0(); 418 //} 414 if (_deathHandler >= 0) { 415 removeHandItem(); 416 delay(5); 417 _drawNoShapeFlag = 0; 418 _gui->optionsButton(0); 419 _deathHandler = -1; 420 } 419 421 420 422 if (_system->getMillis() > _nextIdleAnim) 421 423 showIdleAnim(); … … 770 772 _eventList.push_back(Event(event, true)); 771 773 break; 772 774 775 case Common::EVENT_LBUTTONDOWN: 776 case Common::EVENT_MOUSEMOVE: 777 _eventList.push_back(event); 778 break; 779 773 780 default: 774 781 break; 775 782 } 776 783 } 777 784 } 778 785 779 int KyraEngine_v2::checkInput(Button *buttonList, bool mainLoop ) {786 int KyraEngine_v2::checkInput(Button *buttonList, bool mainLoop, bool guiCode) { 780 787 updateInput(); 781 788 782 789 int keys = 0; … … 806 813 } 807 814 break; 808 815 816 case Common::EVENT_MOUSEMOVE: { 817 Common::Point pos = getMousePos(); 818 _mouseX = pos.x; 819 _mouseY = pos.y; 820 _screen->updateScreen(); 821 } break; 822 823 case Common::EVENT_LBUTTONDOWN: 824 if (guiCode) { 825 Common::Point pos = getMousePos(); 826 _mouseX = pos.x; 827 _mouseY = pos.y; 828 keys = 198; 829 breakLoop = true; 830 } 831 break; 832 809 833 case Common::EVENT_LBUTTONUP: { 810 834 Common::Point pos = getMousePos(); 811 835 _mouseX = pos.x; 812 836 _mouseY = pos.y; 813 keys = 19 8;837 keys = 199; 814 838 breakLoop = true; 815 839 } break; 816 840 -
engines/kyra/gui_v2.cpp
265 265 void GUI_v2::processButton(Button *button) { 266 266 if (!button) 267 267 return; 268 268 269 269 if (button->flags & 8) { 270 270 if (button->flags & 0x10) { 271 271 // XXX … … 379 379 // but did some other magic, which looks like it depends on how the handle 380 380 // key input... so we just enable 0x1000 and 0x4000 here to allow 381 381 // all GUI buttons to work (for now at least...) 382 if (inFlags == 199 || inFlags == 198) 382 if (inFlags == 198) 383 temp = 0x100/* | 0x400*/; 384 else if (inFlags == 199) 383 385 temp = 0x1000 | 0x4000; 384 386 385 387 //if (inputFlag & 0x800) … … 1156 1158 #pragma mark - 1157 1159 1158 1160 void GUI_v2::getInput() { 1159 _vm->checkInput(_menuButtonList); 1161 if (!_displayMenu) 1162 return; 1163 1164 _vm->checkInput(_menuButtonList, false, true); 1165 _vm->removeInputTop(); 1160 1166 if (_vm->quit()) { 1161 1167 _displayMenu = false; 1162 1168 _displaySubMenu = false; … … 1171 1177 updateButton(&_vm->_inventoryButtons[0]); 1172 1178 _screen->showMouse(); 1173 1179 1174 if (!_screen->isMouseVisible() )1180 if (!_screen->isMouseVisible() && button) 1175 1181 return 0; 1176 1182 1177 1183 _vm->showMessage(0, 0xCF); … … 1184 1190 return 0; 1185 1191 } 1186 1192 1187 //int oldHandItem = _vm->_itemInHand;1193 int oldHandItem = _vm->_itemInHand; 1188 1194 _screen->setMouseCursor(0, 0, _vm->getShapePtr(0)); 1189 1195 _vm->displayInvWsaLastFrame(); 1190 1196 //XXX … … 1203 1209 //XXX 1204 1210 _loadMenu.numberOfItems = 6; 1205 1211 initMenuLayout(_loadMenu); 1212 //XXX 1213 initMenuLayout(_deathMenu); 1206 1214 1207 1215 if (_vm->_menuDirectlyToLoad) { 1208 1216 backUpPage1(_vm->_screenBuffer); … … 1225 1233 return 0; 1226 1234 } 1227 1235 1236 if (!button) { 1237 _currentMenu = &_deathMenu; 1238 _isDeathMenu = true; 1239 } else { 1240 //XXX just fail for now 1241 return 0; 1242 } 1243 1244 backUpPage1(_vm->_screenBuffer); 1245 setupPalette(); 1246 initMenu(*_currentMenu); 1247 _madeTempSave = false; 1248 _loadedSave = false; 1249 _vm->_itemInHand = -1; 1250 updateAllMenuButtons(); 1251 1252 if (_isDeathMenu) { 1253 while (!_screen->isMouseVisible()) 1254 _screen->showMouse(); 1255 } 1256 1257 while (_displayMenu) { 1258 processHighlights(*_currentMenu, _vm->_mouseX, _vm->_mouseY); 1259 getInput(); 1260 } 1261 1262 if (_vm->_runFlag && !_loadedSave && !_madeTempSave) { 1263 restorePalette(); 1264 restorePage1(_vm->_screenBuffer); 1265 } 1266 1267 if (_vm->_runFlag) 1268 updateMenuButton(&_vm->_inventoryButtons[0]); 1269 1270 resetState(oldHandItem); 1271 1272 if (!_loadedSave && _reloadTemporarySave) { 1273 _vm->_unkSceneScreenFlag1 = true; 1274 //XXX 1275 _vm->_unkSceneScreenFlag1 = false; 1276 } 1277 1228 1278 return 0; 1229 1279 } 1230 1280 … … 1354 1404 1355 1405 _screen->updateScreen(); 1356 1406 while (_displaySubMenu) { 1357 Common::Point mouse = _vm->getMousePos(); 1358 processHighlights(_loadMenu, mouse.x, mouse.y); 1407 processHighlights(_loadMenu, _vm->_mouseX, _vm->_mouseY); 1359 1408 getInput(); 1360 1409 } 1361 1410 … … 1366 1415 initMenu(*_currentMenu); 1367 1416 updateAllMenuButtons(); 1368 1417 } 1369 } else {1418 } else if (_vm->_gameToLoad >= 0) { 1370 1419 restorePage1(_vm->_screenBuffer); 1371 1420 restorePalette(); 1372 1421 _vm->loadGame(_vm->getSavegameFilename(_vm->_gameToLoad)); 1422 backUpPage1(_vm->_screenBuffer); 1373 1423 if (_vm->_gameToLoad == 0) { 1374 1424 _restartGame = true; 1375 1425 for (int i = 0; i < 23; ++i)