2010-07-31 09:53:02 +00:00
|
|
|
|
/* ScummVM - Graphic Adventure Engine
|
|
|
|
|
*
|
|
|
|
|
* ScummVM is the legal property of its developers, whose names
|
|
|
|
|
* are too numerous to list here. Please refer to the COPYRIGHT
|
|
|
|
|
* file distributed with this source distribution.
|
|
|
|
|
*
|
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
|
2010-08-06 13:13:25 +00:00
|
|
|
|
/*
|
2010-07-31 09:53:02 +00:00
|
|
|
|
* This code is based on Broken Sword 2.5 engine
|
|
|
|
|
*
|
|
|
|
|
* Copyright (c) Malte Thiesen, Daniel Queteschiner and Michael Elsdoerfer
|
|
|
|
|
*
|
|
|
|
|
* Licensed under GNU GPL v2
|
|
|
|
|
*
|
|
|
|
|
*/
|
2010-07-29 19:53:02 +00:00
|
|
|
|
|
2010-07-30 09:02:39 +00:00
|
|
|
|
#include "sword25/gfx/renderobjectmanager.h"
|
2010-07-29 19:53:02 +00:00
|
|
|
|
|
2010-07-30 09:02:39 +00:00
|
|
|
|
#include "sword25/kernel/kernel.h"
|
|
|
|
|
#include "sword25/kernel/inputpersistenceblock.h"
|
|
|
|
|
#include "sword25/kernel/outputpersistenceblock.h"
|
|
|
|
|
#include "sword25/gfx/graphicengine.h"
|
|
|
|
|
#include "sword25/gfx/animationtemplateregistry.h"
|
2010-08-21 08:20:32 +00:00
|
|
|
|
#include "common/rect.h"
|
2010-07-30 09:02:39 +00:00
|
|
|
|
#include "sword25/gfx/renderobject.h"
|
|
|
|
|
#include "sword25/gfx/timedrenderobject.h"
|
|
|
|
|
#include "sword25/gfx/rootrenderobject.h"
|
2010-07-29 19:53:02 +00:00
|
|
|
|
|
2010-08-05 12:48:19 +00:00
|
|
|
|
namespace Sword25 {
|
|
|
|
|
|
2010-09-02 17:11:45 +00:00
|
|
|
|
RenderObjectManager::RenderObjectManager(int width, int height, int framebufferCount) :
|
|
|
|
|
_frameStarted(false) {
|
2010-07-29 19:53:02 +00:00
|
|
|
|
// Wurzel des BS_RenderObject-Baumes erzeugen.
|
2010-09-02 17:11:45 +00:00
|
|
|
|
_rootPtr = (new RootRenderObject(this, width, height))->getHandle();
|
2010-07-29 19:53:02 +00:00
|
|
|
|
}
|
|
|
|
|
|
2010-08-18 10:52:24 +00:00
|
|
|
|
RenderObjectManager::~RenderObjectManager() {
|
2010-07-29 19:53:02 +00:00
|
|
|
|
// Die Wurzel des Baumes l<>schen, damit werden alle BS_RenderObjects mitgel<65>scht.
|
2010-09-02 17:11:45 +00:00
|
|
|
|
_rootPtr.erase();
|
2010-07-29 19:53:02 +00:00
|
|
|
|
}
|
|
|
|
|
|
2010-09-02 17:11:45 +00:00
|
|
|
|
void RenderObjectManager::startFrame() {
|
|
|
|
|
_frameStarted = true;
|
2010-07-29 19:53:02 +00:00
|
|
|
|
|
|
|
|
|
// Verstrichene Zeit bestimmen
|
2010-10-19 21:03:33 +00:00
|
|
|
|
int timeElapsed = Kernel::getInstance()->getGfx()->getLastFrameDurationMicro();
|
2010-07-29 19:53:02 +00:00
|
|
|
|
|
|
|
|
|
// Alle BS_TimedRenderObject Objekte <20>ber den Framestart und die verstrichene Zeit in Kenntnis setzen
|
2010-09-02 17:11:45 +00:00
|
|
|
|
RenderObjectList::iterator iter = _timedRenderObjects.begin();
|
|
|
|
|
for (; iter != _timedRenderObjects.end(); ++iter)
|
|
|
|
|
(*iter)->frameNotification(timeElapsed);
|
2010-07-29 19:53:02 +00:00
|
|
|
|
}
|
|
|
|
|
|
2010-09-02 17:11:45 +00:00
|
|
|
|
bool RenderObjectManager::render() {
|
2010-07-29 19:53:02 +00:00
|
|
|
|
// Den Objekt-Status des Wurzelobjektes aktualisieren. Dadurch werden rekursiv alle Baumelemente aktualisiert.
|
|
|
|
|
// Beim aktualisieren des Objekt-Status werden auch die Update-Rects gefunden, so dass feststeht, was neu gezeichnet
|
|
|
|
|
// werden muss.
|
2010-09-02 17:11:45 +00:00
|
|
|
|
if (!_rootPtr.isValid() || !_rootPtr->updateObjectState())
|
|
|
|
|
return false;
|
2010-07-29 19:53:02 +00:00
|
|
|
|
|
2010-09-02 17:11:45 +00:00
|
|
|
|
_frameStarted = false;
|
2010-07-29 19:53:02 +00:00
|
|
|
|
|
|
|
|
|
// Die Render-Methode der Wurzel aufrufen. Dadurch wird das rekursive Rendern der Baumelemente angesto<74>en.
|
2010-09-02 17:11:45 +00:00
|
|
|
|
return _rootPtr->render();
|
2010-07-29 19:53:02 +00:00
|
|
|
|
}
|
|
|
|
|
|
2010-09-02 17:11:45 +00:00
|
|
|
|
void RenderObjectManager::attatchTimedRenderObject(RenderObjectPtr<TimedRenderObject> renderObjectPtr) {
|
|
|
|
|
_timedRenderObjects.push_back(renderObjectPtr);
|
2010-07-29 19:53:02 +00:00
|
|
|
|
}
|
|
|
|
|
|
2010-09-02 17:11:45 +00:00
|
|
|
|
void RenderObjectManager::detatchTimedRenderObject(RenderObjectPtr<TimedRenderObject> renderObjectPtr) {
|
|
|
|
|
for (uint i = 0; i < _timedRenderObjects.size(); i++)
|
|
|
|
|
if (_timedRenderObjects[i] == renderObjectPtr) {
|
|
|
|
|
_timedRenderObjects.remove_at(i);
|
2010-08-06 14:38:08 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
2010-07-29 19:53:02 +00:00
|
|
|
|
}
|
|
|
|
|
|
2010-09-02 17:11:45 +00:00
|
|
|
|
bool RenderObjectManager::persist(OutputPersistenceBlock &writer) {
|
|
|
|
|
bool result = true;
|
2010-07-29 19:53:02 +00:00
|
|
|
|
|
|
|
|
|
// Alle Kinder des Wurzelknotens speichern. Dadurch werden alle BS_RenderObjects gespeichert rekursiv gespeichert.
|
2010-09-02 17:11:45 +00:00
|
|
|
|
result &= _rootPtr->persistChildren(writer);
|
2010-07-29 19:53:02 +00:00
|
|
|
|
|
2010-09-02 17:11:45 +00:00
|
|
|
|
writer.write(_frameStarted);
|
2010-07-29 19:53:02 +00:00
|
|
|
|
|
|
|
|
|
// Referenzen auf die TimedRenderObjects persistieren.
|
2010-09-02 17:11:45 +00:00
|
|
|
|
writer.write(_timedRenderObjects.size());
|
|
|
|
|
RenderObjectList::const_iterator iter = _timedRenderObjects.begin();
|
|
|
|
|
while (iter != _timedRenderObjects.end()) {
|
|
|
|
|
writer.write((*iter)->getHandle());
|
|
|
|
|
++iter;
|
2010-07-29 19:53:02 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Alle BS_AnimationTemplates persistieren.
|
2010-10-13 15:41:00 +00:00
|
|
|
|
result &= AnimationTemplateRegistry::instance().persist(writer);
|
2010-07-29 19:53:02 +00:00
|
|
|
|
|
2010-09-02 17:11:45 +00:00
|
|
|
|
return result;
|
2010-07-29 19:53:02 +00:00
|
|
|
|
}
|
|
|
|
|
|
2010-09-02 17:11:45 +00:00
|
|
|
|
bool RenderObjectManager::unpersist(InputPersistenceBlock &reader) {
|
|
|
|
|
bool result = true;
|
2010-07-29 19:53:02 +00:00
|
|
|
|
|
|
|
|
|
// Alle Kinder des Wurzelknotens l<>schen. Damit werden alle BS_RenderObjects gel<65>scht.
|
2010-09-02 17:11:45 +00:00
|
|
|
|
_rootPtr->deleteAllChildren();
|
2010-07-29 19:53:02 +00:00
|
|
|
|
|
|
|
|
|
// Alle BS_RenderObjects wieder hestellen.
|
2010-09-02 17:11:45 +00:00
|
|
|
|
if (!_rootPtr->unpersistChildren(reader))
|
|
|
|
|
return false;
|
2010-07-29 19:53:02 +00:00
|
|
|
|
|
2010-09-02 17:11:45 +00:00
|
|
|
|
reader.read(_frameStarted);
|
2010-07-29 19:53:02 +00:00
|
|
|
|
|
|
|
|
|
// Momentan gespeicherte Referenzen auf TimedRenderObjects l<>schen.
|
2010-09-02 17:11:45 +00:00
|
|
|
|
_timedRenderObjects.resize(0);
|
2010-07-29 19:53:02 +00:00
|
|
|
|
|
|
|
|
|
// Referenzen auf die TimedRenderObjects wieder herstellen.
|
2010-09-02 17:11:45 +00:00
|
|
|
|
uint timedObjectCount;
|
|
|
|
|
reader.read(timedObjectCount);
|
|
|
|
|
for (uint i = 0; i < timedObjectCount; ++i) {
|
|
|
|
|
uint handle;
|
|
|
|
|
reader.read(handle);
|
|
|
|
|
_timedRenderObjects.push_back(handle);
|
2010-07-29 19:53:02 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Alle BS_AnimationTemplates wieder herstellen.
|
2010-10-13 15:41:00 +00:00
|
|
|
|
result &= AnimationTemplateRegistry::instance().unpersist(reader);
|
2010-07-29 19:53:02 +00:00
|
|
|
|
|
2010-09-02 17:11:45 +00:00
|
|
|
|
return result;
|
2010-07-29 19:53:02 +00:00
|
|
|
|
}
|
2010-08-05 12:48:19 +00:00
|
|
|
|
|
|
|
|
|
} // End of namespace Sword25
|