Skip to content

Commit

Permalink
WINTERMUTE: Cap the renderqueue to 800.
Browse files Browse the repository at this point in the history
  • Loading branch information
somaen committed Apr 23, 2013
1 parent 86b93a8 commit 182c1a1
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 6 deletions.
47 changes: 41 additions & 6 deletions engines/wintermute/base/gfx/osystem/base_render_osystem.cpp
Expand Up @@ -39,6 +39,8 @@
#include "common/queue.h"
#include "common/config-manager.h"

#define DIRTY_RECT_LIMIT 800

namespace Wintermute {

BaseRenderer *makeOSystemRenderer(BaseGame *inGame) {
Expand All @@ -62,6 +64,7 @@ BaseRenderOSystem::BaseRenderOSystem(BaseGame *inGame) : BaseRenderer(inGame) {
setColorMod(255, 255, 255);
_dirtyRect = nullptr;
_disableDirtyRects = false;
_tempDisableDirtyRects = 0;
if (ConfMan.hasKey("dirty_rects")) {
_disableDirtyRects = !ConfMan.getBool("dirty_rects");
}
Expand Down Expand Up @@ -166,6 +169,9 @@ bool BaseRenderOSystem::indicatorFlip() {
}

bool BaseRenderOSystem::flip() {
if (_renderQueue.size() > DIRTY_RECT_LIMIT) {
_tempDisableDirtyRects++;
}
if (_skipThisFrame) {
_skipThisFrame = false;
delete _dirtyRect;
Expand All @@ -176,7 +182,7 @@ bool BaseRenderOSystem::flip() {
addDirtyRect(_renderRect);
return true;
}
if (!_disableDirtyRects) {
if (!_tempDisableDirtyRects && !_disableDirtyRects) {
drawTickets();
} else {
// Clear the scale-buffered tickets that wasn't reused.
Expand All @@ -192,8 +198,8 @@ bool BaseRenderOSystem::flip() {
}
}
}
if (_needsFlip || _disableDirtyRects) {
if (_disableDirtyRects) {
if (_needsFlip || _disableDirtyRects || _tempDisableDirtyRects) {
if (_disableDirtyRects || _tempDisableDirtyRects) {
g_system->copyRectToScreen((byte *)_renderSurface->pixels, _renderSurface->pitch, 0, 0, _renderSurface->w, _renderSurface->h);
}
// g_system->copyRectToScreen((byte *)_renderSurface->pixels, _renderSurface->pitch, _dirtyRect->left, _dirtyRect->top, _dirtyRect->width(), _dirtyRect->height());
Expand All @@ -204,13 +210,29 @@ bool BaseRenderOSystem::flip() {
}
_drawNum = 1;

if (_tempDisableDirtyRects && !_disableDirtyRects) {
_tempDisableDirtyRects--;
if (!_tempDisableDirtyRects) {
Common::Rect screen(_screenRect.top, _screenRect.left, _screenRect.bottom, _screenRect.right);
addDirtyRect(screen);

// The queue has been ignored but updated, and is guaranteed to be in draw-order when run without dirty-rects.
RenderQueueIterator it = _renderQueue.begin();
int drawNum = 1;
while (it != _renderQueue.end()) {
(*it)->_drawNum = drawNum++;
++it;
}
}
}

return STATUS_OK;
}

//////////////////////////////////////////////////////////////////////////
bool BaseRenderOSystem::fill(byte r, byte g, byte b, Common::Rect *rect) {
_clearColor = _renderSurface->format.ARGBToColor(0xFF, r, g, b);
if (!_disableDirtyRects) {
if (!_disableDirtyRects && !_tempDisableDirtyRects) {
return STATUS_OK;
}
if (!rect) {
Expand Down Expand Up @@ -277,6 +299,15 @@ Graphics::PixelFormat BaseRenderOSystem::getPixelFormat() const {
}

void BaseRenderOSystem::drawSurface(BaseSurfaceOSystem *owner, const Graphics::Surface *surf, Common::Rect *srcRect, Common::Rect *dstRect, bool mirrorX, bool mirrorY, bool disableAlpha) {
if (_tempDisableDirtyRects || _disableDirtyRects) {
RenderTicket *ticket = new RenderTicket(owner, surf, srcRect, dstRect, mirrorX, mirrorY, disableAlpha);
ticket->_colorMod = _colorMod;
ticket->_wantsDraw = true;
_renderQueue.push_back(ticket);
_previousTicket = ticket;
drawFromSurface(ticket);
return;
}
// Start searching from the beginning for the first and second items (since it's empty the first time around
// then keep incrementing the start-position, to avoid comparing against already used tickets.
if (_drawNum == 0 || _drawNum == 1) {
Expand Down Expand Up @@ -310,6 +341,10 @@ void BaseRenderOSystem::drawSurface(BaseSurfaceOSystem *owner, const Graphics::S
drawFromTicket(compareTicket);
_previousTicket = compareTicket;
}
if (_renderQueue.size() > DIRTY_RECT_LIMIT) {
drawTickets();
_tempDisableDirtyRects = 3;
}
return;
}
}
Expand All @@ -332,7 +367,7 @@ void BaseRenderOSystem::repeatLastDraw(int offsetX, int offsetY, int numTimesX,
RenderTicket *origTicket = _previousTicket;

// Make sure drawSurface WILL start from the correct _lastAddedTicket
if (*_lastAddedTicket != origTicket) {
if (!_tempDisableDirtyRects && !_disableDirtyRects && *_lastAddedTicket != origTicket) {
RenderQueueIterator it;
RenderQueueIterator endIterator = _renderQueue.end();
for (it = _renderQueue.begin(); it != endIterator; ++it) {
Expand Down Expand Up @@ -543,7 +578,7 @@ void BaseRenderOSystem::drawFromSurface(RenderTicket *ticket, Common::Rect *dstR
bool BaseRenderOSystem::drawLine(int x1, int y1, int x2, int y2, uint32 color) {
// This function isn't used outside of indicator-displaying, and thus quite unused in
// BaseRenderOSystem when dirty-rects are enabled.
if (!_disableDirtyRects && !_indicatorDisplay) {
if (!_tempDisableDirtyRects && !_disableDirtyRects && !_indicatorDisplay) {
error("BaseRenderOSystem::DrawLine - doesn't work for dirty rects yet");
}

Expand Down
1 change: 1 addition & 0 deletions engines/wintermute/base/gfx/osystem/base_render_osystem.h
Expand Up @@ -108,6 +108,7 @@ class BaseRenderOSystem : public BaseRenderer {
int _borderBottom;

bool _disableDirtyRects;
uint32 _tempDisableDirtyRects;
bool _spriteBatch;
uint32 _batchNum;
float _ratioX;
Expand Down

0 comments on commit 182c1a1

Please sign in to comment.