Don't change mouse cursors so ridiculously often.

svn-id: r45451
This commit is contained in:
Robert Špalek 2009-10-27 23:51:32 +00:00
parent 7d6e96fa80
commit ed87e5cd31
3 changed files with 38 additions and 19 deletions

View File

@ -463,16 +463,11 @@ void Game::updateCursor() {
if (_loopStatus == kStatusDialogue)
return;
bool mouseChanged = false;
// If we are in inventory mode, we do a different kind of updating that handles
// inventory items and return early
if (_loopStatus == kStatusInventory && _loopSubstatus == kSubstatusOrdinary) {
if (_currentItem == kNoItem) {
_vm->_mouse->setCursorType(kNormalCursor);
} else {
_vm->_mouse->loadItemCursor(_currentItem);
}
if (_itemUnderCursor != kNoItem) {
const GameItem *item = &_items[_itemUnderCursor];
@ -482,6 +477,14 @@ void Game::updateCursor() {
} else {
_vm->_mouse->loadItemCursor(_currentItem, true);
}
mouseChanged = true;
}
}
if (!mouseChanged) {
if (_currentItem == kNoItem) {
_vm->_mouse->setCursorType(kNormalCursor);
} else {
_vm->_mouse->loadItemCursor(_currentItem);
}
}
@ -498,14 +501,6 @@ void Game::updateCursor() {
_oldObjUnderCursor = _objUnderCursor;
}
// Load the appropriate cursor (item image if an item is held or ordinary cursor
// if not)
if (_currentItem == kNoItem) {
_vm->_mouse->setCursorType(kNormalCursor);
} else {
_vm->_mouse->loadItemCursor(_currentItem);
}
// TODO: Handle main menu
// If there is no game object under the cursor, try using the room itself
@ -516,6 +511,7 @@ void Game::updateCursor() {
} else {
_vm->_mouse->loadItemCursor(_currentItem, true);
}
mouseChanged = true;
}
// If there *is* a game object under the cursor, update the cursor image
} else {
@ -531,11 +527,22 @@ void Game::updateCursor() {
} else {
_vm->_mouse->loadItemCursor(_currentItem, true);
}
mouseChanged = true;
}
// If the walking direction *is* set, the game object is a gate, so update
// the cursor image to the appropriate arrow.
} else {
_vm->_mouse->setCursorType((CursorType)obj->_walkDir);
mouseChanged = true;
}
}
// Load the appropriate cursor (item image if an item is held or ordinary cursor
// if not)
if (!mouseChanged) {
if (_currentItem == kNoItem) {
_vm->_mouse->setCursorType(kNormalCursor);
} else {
_vm->_mouse->loadItemCursor(_currentItem);
}
}
}

View File

@ -34,7 +34,7 @@ Mouse::Mouse(DraciEngine *vm) {
_y = 0;
_lButton = false;
_rButton = false;
_cursorType = kNormalCursor;
_cursorType = kUninitializedCursor;
_vm = vm;
}
@ -90,10 +90,13 @@ void Mouse::setPosition(uint16 x, uint16 y) {
}
void Mouse::setCursorType(CursorType cur) {
if (cur == getCursorType()) {
return;
}
_cursorType = cur;
const BAFile *f;
f = _vm->_iconsArchive->getFile(_cursorType);
f = _vm->_iconsArchive->getFile(cur);
Sprite sp(f->_data, f->_length, 0, 0, true);
CursorMan.replaceCursorPalette(_vm->_screen->getPalette(), 0, kNumColours);
@ -102,8 +105,15 @@ void Mouse::setCursorType(CursorType cur) {
}
void Mouse::loadItemCursor(int itemID, bool highlighted) {
int archiveIndex = 2 * itemID + highlighted;
CursorType newCursor = static_cast<CursorType> (kItemCursor + archiveIndex);
if (newCursor == getCursorType()) {
return;
}
_cursorType = newCursor;
const BAFile *f;
f = _vm->_itemImagesArchive->getFile(2 * itemID + highlighted);
f = _vm->_itemImagesArchive->getFile(archiveIndex);
Sprite sp(f->_data, f->_length, 0, 0, true);
CursorMan.replaceCursorPalette(_vm->_screen->getPalette(), 0, kNumColours);

View File

@ -39,7 +39,9 @@ enum CursorType {
kArrowCursor4,
kDialogueCursor,
kHighlightedCursor,
kMainMenuCursor
kMainMenuCursor,
kUninitializedCursor = 100,
kItemCursor // + the index in the BArchive
};
class DraciEngine;