diff options
author | johndoe123 | 2013-04-17 12:41:49 +0200 |
---|---|---|
committer | johndoe123 | 2013-04-17 12:41:49 +0200 |
commit | 0a0b2f397b95e6e219f2ac8c5b79bbe6300ef432 (patch) | |
tree | 4351e3a630eb9dc4e684d5147e1c1499fbf0e98e /engines/sword25/gfx/renderobject.cpp | |
parent | 6548104b96be211b1c93412a05802cc821b1d2e0 (diff) | |
download | scummvm-rg350-0a0b2f397b95e6e219f2ac8c5b79bbe6300ef432.tar.gz scummvm-rg350-0a0b2f397b95e6e219f2ac8c5b79bbe6300ef432.tar.bz2 scummvm-rg350-0a0b2f397b95e6e219f2ac8c5b79bbe6300ef432.zip |
SWORD25: Optimize graphics drawing code
Diffstat (limited to 'engines/sword25/gfx/renderobject.cpp')
-rw-r--r-- | engines/sword25/gfx/renderobject.cpp | 43 |
1 files changed, 39 insertions, 4 deletions
diff --git a/engines/sword25/gfx/renderobject.cpp b/engines/sword25/gfx/renderobject.cpp index a977eb80ba..f2d25771a9 100644 --- a/engines/sword25/gfx/renderobject.cpp +++ b/engines/sword25/gfx/renderobject.cpp @@ -48,6 +48,8 @@ namespace Sword25 { +int RenderObject::_nextGlobalVersion = 0; + RenderObject::RenderObject(RenderObjectPtr<RenderObject> parentPtr, TYPES type, uint handle) : _managerPtr(0), _parentPtr(parentPtr), @@ -65,7 +67,9 @@ RenderObject::RenderObject(RenderObjectPtr<RenderObject> parentPtr, TYPES type, _type(type), _initSuccess(false), _refreshForced(true), - _handle(0) { + _handle(0), + _version(++_nextGlobalVersion), + _isSolid(false) { // Renderobject registrieren, abhängig vom Handle-Parameter entweder mit beliebigem oder vorgegebenen Handle. if (handle == 0) @@ -106,7 +110,7 @@ RenderObject::~RenderObject() { RenderObjectRegistry::instance().deregisterObject(this); } -bool RenderObject::render() { +bool RenderObject::render(RectangleList *updateRects, const Common::Array<int> &updateRectsMinZ) { // Objektänderungen validieren validateObject(); @@ -121,17 +125,39 @@ bool RenderObject::render() { } // Objekt zeichnen. - doRender(); + bool needRender = false; + int index = 0; + + // Only draw if the bounding box intersects any update rectangle and + // the object is in front of the minimum Z value. + for (RectangleList::iterator rectIt = updateRects->begin(); !needRender && rectIt != updateRects->end(); ++rectIt, ++index) + needRender = (_bbox.contains(*rectIt) || _bbox.intersects(*rectIt)) && getAbsoluteZ() >= updateRectsMinZ[index]; + + if (needRender) + doRender(updateRects); // Dann müssen die Kinder gezeichnet werden RENDEROBJECT_ITER it = _children.begin(); for (; it != _children.end(); ++it) - if (!(*it)->render()) + if (!(*it)->render(updateRects, updateRectsMinZ)) return false; return true; } +void RenderObject::collectRenderQueue(RenderObjectQueue *renderQueue) { + + if (!_visible) + return; + + renderQueue->add(this); + + RENDEROBJECT_ITER it = _children.begin(); + for (; it != _children.end(); ++it) + (*it)->collectRenderQueue(renderQueue); + +} + void RenderObject::validateObject() { // Die Veränderungen in den Objektvariablen aufheben _oldBbox = _bbox; @@ -157,6 +183,8 @@ bool RenderObject::updateObjectState() { // Die Bounding-Box neu berechnen und Update-Regions registrieren. updateBoxes(); + + ++_version; // Änderungen Validieren validateObject(); @@ -289,6 +317,13 @@ void RenderObject::setZ(int z) { _z = z; } +int RenderObject::getAbsoluteZ() const { + if (_parentPtr.isValid()) + return _parentPtr->getAbsoluteZ() + _z; + else + return _z; +} + void RenderObject::setVisible(bool visible) { _visible = visible; } |