STARK: Collect the render entries from the location and render them

This commit is contained in:
Bastien Bouclet 2015-01-02 17:32:44 +01:00
parent 328cbdc32b
commit 495e8e2611
13 changed files with 172 additions and 17 deletions

View file

@ -28,7 +28,18 @@
namespace Stark {
RenderEntry::RenderEntry(Resource *owner, const Common::String &name) :
_visual(nullptr),
_name(name),
_owner(owner) {
}
void RenderEntry::update(uint32 delta) {
if (!_visual) {
// warning("No visual for render entry '%s'", _name.c_str());
return;
}
VisualActor *actor = _visual->get<VisualActor>();
if (actor) {
actor->update(delta);
@ -36,6 +47,11 @@ void RenderEntry::update(uint32 delta) {
}
void RenderEntry::render(GfxDriver *gfx) {
if (!_visual) {
// warning("No visual for render entry '%s'", _name.c_str());
return;
}
VisualImageXMG *imageXMG = _visual->get<VisualImageXMG>();
if (imageXMG) {
imageXMG->render(gfx, _position);

View file

@ -23,15 +23,19 @@
#ifndef STARK_GFX_RENDER_ENTRY_H
#define STARK_GFX_RENDER_ENTRY_H
#include "common/array.h"
#include "common/rect.h"
#include "common/str.h"
namespace Stark {
class Visual;
class GfxDriver;
class Resource;
class Visual;
class RenderEntry {
public:
RenderEntry(Resource *owner, const Common::String &name);
virtual ~RenderEntry() {};
void update(uint32 delta); // TODO: Remove
@ -41,10 +45,15 @@ public:
void setPosition(const Common::Point &position);
protected:
Common::String _name;
Resource *_owner;
Visual *_visual;
Common::Point _position;
};
typedef Common::Array<RenderEntry *> RenderEntryArray;
} // End of namespace Stark
#endif // STARK_GFX_RENDER_ENTRY_H

View file

@ -110,6 +110,10 @@ void AnimHierarchy::selectItemAnim(ItemVisual *item) {
}
}
Anim *AnimHierarchy::getCurrentAnim() {
return _currentAnim;
}
void AnimHierarchy::printData() {
for (uint i = 0; i < _animationReferences.size(); i++) {
debug("anim %d: %s", i, _animationReferences[i].describe().c_str());

View file

@ -49,6 +49,8 @@ public:
void unselectItemAnim(ItemVisual *item);
void selectItemAnim(ItemVisual *item);
Anim *getCurrentAnim();
protected:
void printData() override;

View file

@ -20,9 +20,12 @@
*
*/
#include "engines/stark/resources/item.h"
#include "common/debug.h"
#include "engines/stark/resources/item.h"
#include "engines/stark/gfx/renderentry.h"
#include "engines/stark/resources/anim.h"
#include "engines/stark/resources/animhierarchy.h"
#include "engines/stark/xrcreader.h"
@ -31,11 +34,11 @@ namespace Stark {
Resource *Item::construct(Resource *parent, byte subType, uint16 index, const Common::String &name) {
switch (subType) {
case kItemSub1:
return new UnimplementedResource(parent, TYPE, subType, index, name);
return new Item(parent, subType, index, name); // TODO
case kItemSub2:
return new UnimplementedResource(parent, TYPE, subType, index, name);
return new Item(parent, subType, index, name); // TODO
case kItemSub3:
return new UnimplementedResource(parent, TYPE, subType, index, name);
return new Item(parent, subType, index, name); // TODO
case kItemSub5:
case kItemSub6:
return new ItemSub56(parent, subType, index, name);
@ -43,7 +46,7 @@ Resource *Item::construct(Resource *parent, byte subType, uint16 index, const Co
case kItemSub8:
return new ItemSub78(parent, subType, index, name);
case kItemSub10:
return new UnimplementedResource(parent, TYPE, subType, index, name);
return new Item(parent, subType, index, name); // TODO
default:
error("Unknown item subtype %d", subType);
}
@ -64,19 +67,26 @@ void Item::readData(XRCReadStream *stream) {
_field_38 = stream->readSint32LE();
}
RenderEntry *Item::getRenderEntry() {
return nullptr;
}
void Item::printData() {
debug("field_34: %d", _field_34);
debug("field_38: %d", _field_38);
}
ItemVisual::~ItemVisual() {
delete _renderEntry;
}
ItemVisual::ItemVisual(Resource *parent, byte subType, uint16 index, const Common::String &name) :
Item(parent, subType, index, name),
_renderEntry(nullptr),
_animHierarchy(nullptr),
_currentAnimIndex(-1),
_field_44(1) {
_renderEntry = new RenderEntry(this, getName());
}
void ItemVisual::readData(XRCReadStream *stream) {
@ -110,6 +120,20 @@ void ItemVisual::printData() {
debug("field_44: %d", _field_44);
}
Anim *ItemVisual::getAnim() {
return _animHierarchy->getCurrentAnim();
}
Visual *ItemVisual::getVisual() {
Anim *anim = getAnim();
if (!anim) {
return nullptr;
}
return anim->getVisual();
}
ItemSub5610::~ItemSub5610() {
}
@ -132,6 +156,15 @@ void ItemSub56::readData(XRCReadStream *stream) {
_position = stream->readPoint();
}
RenderEntry *ItemSub56::getRenderEntry() {
Visual *visual = getVisual();
_renderEntry->setVisual(visual);
_renderEntry->setPosition(_position);
return _renderEntry;
}
void ItemSub56::printData() {
ItemSub5610::printData();

View file

@ -31,8 +31,11 @@
namespace Stark {
class XRCReadStream;
class Anim;
class AnimHierarchy;
class RenderEntry;
class Visual;
class XRCReadStream;
class Item : public Resource {
public:
@ -55,8 +58,11 @@ public:
Item(Resource *parent, byte subType, uint16 index, const Common::String &name);
virtual ~Item();
// Resource API
virtual void readData(XRCReadStream *stream) override;
virtual RenderEntry *getRenderEntry();
protected:
void printData() override;
@ -69,14 +75,21 @@ public:
ItemVisual(Resource *parent, byte subType, uint16 index, const Common::String &name);
virtual ~ItemVisual();
// Resource API
virtual void readData(XRCReadStream *stream) override;
virtual void onAllLoaded() override;
void setAnim(int32 index);
protected:
// Resource API
void printData() override;
Anim *getAnim();
Visual *getVisual();
RenderEntry *_renderEntry;
AnimHierarchy *_animHierarchy;
int32 _currentAnimIndex;
uint32 _field_44;
@ -93,8 +106,12 @@ public:
ItemSub56(Resource *parent, byte subType, uint16 index, const Common::String &name);
virtual ~ItemSub56();
// Resource API
virtual void readData(XRCReadStream *stream) override;
// Item API
virtual RenderEntry *getRenderEntry() override;
protected:
void printData() override;

View file

@ -21,6 +21,8 @@
*/
#include "engines/stark/resources/layer.h"
#include "engines/stark/resources/item.h"
#include "engines/stark/xrcreader.h"
#include "common/debug.h"
@ -78,6 +80,11 @@ void Layer2D::readData(XRCReadStream *stream) {
_field_50 = stream->readUint32LE();
}
RenderEntryArray Layer2D::listRenderEntries() {
// TODO
return RenderEntryArray();
}
void Layer2D::printData() {
Layer::printData();
}
@ -104,6 +111,33 @@ void Layer3D::readData(XRCReadStream *stream) {
}
}
void Layer3D::onAllLoaded() {
Layer::onAllLoaded();
_items = listChildren<Item>();
}
RenderEntryArray Layer3D::listRenderEntries() {
RenderEntryArray renderEntries;
for (uint i = 0; i < _items.size(); i++) {
Item *item = _items[i];
if (item->getSubType() != Item::kItemSub8) {
RenderEntry *renderEntry = item->getRenderEntry();
if (!renderEntry) {
// warning("No render entry for item '%s'", item->getName().c_str());
continue;
}
renderEntries.push_back(renderEntry);
}
}
return renderEntries;
}
void Layer3D::printData() {
Layer::printData();

View file

@ -26,10 +26,12 @@
#include "common/array.h"
#include "common/str.h"
#include "engines/stark/gfx/renderentry.h"
#include "engines/stark/resources/resource.h"
namespace Stark {
class Item;
class XRCReadStream;
class Layer : public Resource {
@ -47,8 +49,11 @@ public:
Layer(Resource *parent, byte subType, uint16 index, const Common::String &name);
virtual ~Layer();
// Resource API
virtual void readData(XRCReadStream *stream) override;
virtual RenderEntryArray listRenderEntries() = 0;
protected:
void printData() override;
@ -61,7 +66,11 @@ public:
Layer2D(Resource *parent, byte subType, uint16 index, const Common::String &name);
virtual ~Layer2D();
virtual void readData(XRCReadStream *stream) override;
// Resource API
void readData(XRCReadStream *stream) override;
// Layer API
RenderEntryArray listRenderEntries() override;
protected:
void printData() override;
@ -74,7 +83,12 @@ public:
Layer3D(Resource *parent, byte subType, uint16 index, const Common::String &name);
virtual ~Layer3D();
virtual void readData(XRCReadStream *stream) override;
// Resource API
void readData(XRCReadStream *stream) override;
void onAllLoaded() override;
// Layer API
RenderEntryArray listRenderEntries() override;
protected:
void printData() override;
@ -83,6 +97,8 @@ protected:
uint32 _field_58;
float _nearClipPlane;
float _farClipPlane;
Common::Array<Item *> _items;
};
} // End of namespace Stark

View file

@ -41,6 +41,17 @@ void Location::onAllLoaded() {
_layers = listChildren<Layer>();
}
RenderEntryArray Location::listRenderEntries() {
RenderEntryArray renderEntries;
for (uint i = 0; i < _layers.size(); i++) {
Layer *layer = _layers[i];
renderEntries.push_back(layer->listRenderEntries());
}
return renderEntries;
}
void Location::printData() {
}

View file

@ -25,12 +25,13 @@
#include "common/str.h"
#include "engines/stark/gfx/renderentry.h"
#include "engines/stark/resources/resource.h"
namespace Stark {
class XRCReadStream;
class Layer;
class XRCReadStream;
class Location : public Resource {
public:
@ -39,8 +40,11 @@ public:
Location(Resource *parent, byte subType, uint16 index, const Common::String &name);
virtual ~Location();
// Resource API
void onAllLoaded() override;
RenderEntryArray listRenderEntries();
protected:
void printData() override;

View file

@ -49,7 +49,7 @@ Scene::Scene(GfxDriver *gfx) : _gfx(gfx) {
actor->setAnim(&xarc, "oldapril_idle.ani");
actor->setTexture(&xarc, "oldapril.tm");
RenderEntry *oldApril = new RenderEntry();
RenderEntry *oldApril = new RenderEntry(nullptr, "Old April");
oldApril->setVisual(actor);
_elements.push_back(oldApril);
@ -58,7 +58,11 @@ Scene::Scene(GfxDriver *gfx) : _gfx(gfx) {
Scene::~Scene() {
}
void Scene::render(uint32 delta) {
void Scene::render(RenderEntryArray renderEntries, uint32 delta) {
RenderEntryArray allElements;
allElements.push_back(renderEntries);
allElements.push_back(_elements);
// setup cam
// Draw bg
@ -66,8 +70,8 @@ void Scene::render(uint32 delta) {
// Draw other things
// Render all the scene elements
Common::Array<RenderEntry *>::iterator element = _elements.begin();
while (element != _elements.end()) {
RenderEntryArray::iterator element = allElements.begin();
while (element != allElements.end()) {
// Draw the current element
(*element)->update(delta);
(*element)->render(_gfx);

View file

@ -25,6 +25,8 @@
#include "common/array.h"
#include "engines/stark/gfx/renderentry.h"
namespace Stark {
class GfxDriver;
@ -43,11 +45,11 @@ public:
*
* @param delta Time offset (in ms) since last frame render
*/
void render(uint32 delta);
void render(RenderEntryArray renderEntries, uint32 delta);
private:
GfxDriver *_gfx;
Common::Array<RenderEntry *> _elements;
RenderEntryArray _elements;
};
} // End of namespace Stark

View file

@ -21,6 +21,7 @@
*/
#include "engines/stark/stark.h"
#include "engines/stark/archiveloader.h"
#include "engines/stark/console.h"
#include "engines/stark/debug.h"
@ -30,6 +31,7 @@
#include "engines/stark/scene.h"
#include "engines/stark/stateprovider.h"
#include "engines/stark/gfx/driver.h"
#include "engines/stark/gfx/renderentry.h"
#include "common/config-manager.h"
#include "common/events.h"
@ -171,7 +173,8 @@ void StarkEngine::updateDisplayScene() {
_global->getCurrent()->getLocation()->onGameLoop(delta);
// Render the current scene
_scene->render(delta);
RenderEntryArray renderEntries = _global->getCurrent()->getLocation()->listRenderEntries();
_scene->render(renderEntries, delta);
// Swap buffers
_gfx->flipBuffer();