fix possible mapview crash

This commit is contained in:
Eduardo Bart 2012-03-28 16:09:45 -03:00
parent 4743763d48
commit a4cef0d390
6 changed files with 87 additions and 55 deletions

View File

@ -10,6 +10,7 @@ end
function UIResizeBorder:onHoverChange(hovered) function UIResizeBorder:onHoverChange(hovered)
if hovered then if hovered then
if g_ui.getDraggingWidget() then return end
if self:getWidth() > self:getHeight() then if self:getWidth() > self:getHeight() then
Mouse.setVerticalCursor() Mouse.setVerticalCursor()
self.vertical = true self.vertical = true
@ -17,13 +18,15 @@ function UIResizeBorder:onHoverChange(hovered)
Mouse.setHorizontalCursor() Mouse.setHorizontalCursor()
self.vertical = false self.vertical = false
end end
self.hovering = true
if not self:isPressed() then if not self:isPressed() then
Effects.fadeIn(self) Effects.fadeIn(self)
end end
else else
if not self:isPressed() then if not self:isPressed() and self.hovering then
Mouse.restoreCursor() Mouse.restoreCursor()
Effects.fadeOut(self) Effects.fadeOut(self)
self.hovering = false
end end
end end
end end
@ -63,6 +66,7 @@ function UIResizeBorder:onMouseRelease(mousePos, mouseButton)
if not self:isHovered() then if not self:isHovered() then
Mouse.restoreCursor() Mouse.restoreCursor()
Effects.fadeOut(self) Effects.fadeOut(self)
self.hovering = false
end end
end end

View File

@ -73,3 +73,6 @@ function UIMiniWindow:onMinimize()
end end
end end
function UIMiniWindow:getClassName()
return 'UIMiniWindow'
end

View File

@ -8,9 +8,11 @@ function UIMiniWindowContainer.create()
end end
function UIMiniWindowContainer:onDrop(widget, mousePos) function UIMiniWindowContainer:onDrop(widget, mousePos)
if widget:getClassName() == 'UIMiniWindow' then
widget:setParent(self) widget:setParent(self)
return true return true
end end
end
function UIMiniWindowContainer:getClassName() function UIMiniWindowContainer:getClassName()
return 'UIMiniWindowContainer' return 'UIMiniWindowContainer'

View File

@ -45,19 +45,29 @@ void EventDispatcher::poll()
scheduledEvent->execute(); scheduledEvent->execute();
} }
// execute events list up to 3 times, this is needed because some events can schedule new events that would // execute events list up to 10 times, this is needed because some events can schedule new events that would
// change the UIWidgets layout, in this case we must execute these new events before we continue rendering, // change the UIWidgets layout, in this case we must execute these new events before we continue rendering,
// we can't loop until the event list is empty, because this could lead to infinite loops // we can't loop until the event list is empty, because this could lead to infinite loops
// if someone write a module with bad code // if someone write a module with bad code
for(int i=0;i<3;++i) {
m_pollEventsSize = m_eventList.size(); m_pollEventsSize = m_eventList.size();
if(m_pollEventsSize == 0) int count = 0;
while(m_pollEventsSize > 0) {
if(count > 50) {
static bool reported = false;
if(!reported) {
logError("ATTENTION the event list is not getting empty, this could be caused by some bad code");
reported = true;
}
break; break;
}
for(int i=0;i<m_pollEventsSize;++i) { for(int i=0;i<m_pollEventsSize;++i) {
EventPtr event = m_eventList.front(); EventPtr event = m_eventList.front();
m_eventList.pop_front(); m_eventList.pop_front();
event->execute(); event->execute();
} }
m_pollEventsSize = m_eventList.size();
count++;
} }
} }

View File

@ -193,8 +193,10 @@ void MapView::updateVisibleTilesCache(int start)
m_updateTilesCacheEvent = nullptr; m_updateTilesCacheEvent = nullptr;
} }
m_cachedFirstVisibleFloor = getFirstVisibleFloor(); m_cachedFirstVisibleFloor = calcFirstVisibleFloor();
m_cachedLastVisibleFloor = getLastVisibleFloor(); m_cachedLastVisibleFloor = calcLastVisibleFloor();
assert(m_cachedFirstVisibleFloor >= 0 && m_cachedLastVisibleFloor >= 0 &&
m_cachedFirstVisibleFloor <= Otc::MAX_Z && m_cachedLastVisibleFloor <= Otc::MAX_Z);
if(m_cachedLastVisibleFloor < m_cachedFirstVisibleFloor) if(m_cachedLastVisibleFloor < m_cachedFirstVisibleFloor)
m_cachedLastVisibleFloor = m_cachedFirstVisibleFloor; m_cachedLastVisibleFloor = m_cachedFirstVisibleFloor;
@ -461,18 +463,19 @@ void MapView::setVisibleDimension(const Size& visibleDimension)
requestVisibleTilesCacheUpdate(); requestVisibleTilesCacheUpdate();
} }
int MapView::getFirstVisibleFloor() int MapView::calcFirstVisibleFloor()
{ {
int z = 7;
// return forced first visible floor // return forced first visible floor
if(m_lockedFirstVisibleFloor != -1) if(m_lockedFirstVisibleFloor != -1) {
return m_lockedFirstVisibleFloor; z = m_lockedFirstVisibleFloor;
} else {
Position cameraPosition = getCameraPosition(); Position cameraPosition = getCameraPosition();
// avoid rendering multifloors in far views // avoid rendering multifloors in far views
if(m_viewRange >= FAR_VIEW) if(m_viewRange >= FAR_VIEW) {
return cameraPosition.z; z = cameraPosition.z;
} else {
// if nothing is limiting the view, the first visible floor is 0 // if nothing is limiting the view, the first visible floor is 0
int firstFloor = 0; int firstFloor = 0;
@ -509,22 +512,32 @@ int MapView::getFirstVisibleFloor()
} }
} }
return firstFloor; z = firstFloor;
}
} }
int MapView::getLastVisibleFloor() z = std::min(std::max(z, 0), (int)Otc::MAX_Z);
return z;
}
int MapView::calcLastVisibleFloor()
{ {
int z = 7;
Position cameraPosition = getCameraPosition(); Position cameraPosition = getCameraPosition();
// avoid rendering multifloors in far views // avoid rendering multifloors in far views
if(m_viewRange >= FAR_VIEW) if(m_viewRange >= FAR_VIEW) {
return cameraPosition.z; z = cameraPosition.z;
} else {
// view only underground floors when below sea level // view only underground floors when below sea level
if(cameraPosition.z > Otc::SEA_FLOOR) if(cameraPosition.z > Otc::SEA_FLOOR)
return std::min(cameraPosition.z + Otc::AWARE_UNDEGROUND_FLOOR_RANGE, (int)Otc::MAX_Z); z = cameraPosition.z + Otc::AWARE_UNDEGROUND_FLOOR_RANGE;
else else
return Otc::SEA_FLOOR; z = Otc::SEA_FLOOR;
}
z = std::min(std::max(z, 0), (int)Otc::MAX_Z);
return z;
} }
Position MapView::getCameraPosition() Position MapView::getCameraPosition()

View File

@ -77,8 +77,8 @@ public:
bool isFollowingCreature() { return !!m_followingCreature; } bool isFollowingCreature() { return !!m_followingCreature; }
int getFirstVisibleFloor(); int calcFirstVisibleFloor();
int getLastVisibleFloor(); int calcLastVisibleFloor();
Position getCameraPosition(); Position getCameraPosition();
TilePtr getTile(const Point& mousePos, const Rect& mapRect); TilePtr getTile(const Point& mousePos, const Rect& mapRect);
Size getVisibleDimension() { return m_visibleDimension; } Size getVisibleDimension() { return m_visibleDimension; }