diff --git a/engines/stark/gfx/renderentry.cpp b/engines/stark/gfx/renderentry.cpp index 8f2baf79b0a..9f9193792ba 100644 --- a/engines/stark/gfx/renderentry.cpp +++ b/engines/stark/gfx/renderentry.cpp @@ -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(); 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(); if (imageXMG) { imageXMG->render(gfx, _position); diff --git a/engines/stark/gfx/renderentry.h b/engines/stark/gfx/renderentry.h index ec57d837afc..89ebab7e395 100644 --- a/engines/stark/gfx/renderentry.h +++ b/engines/stark/gfx/renderentry.h @@ -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 RenderEntryArray; + } // End of namespace Stark #endif // STARK_GFX_RENDER_ENTRY_H diff --git a/engines/stark/resources/animhierarchy.cpp b/engines/stark/resources/animhierarchy.cpp index 782ea215346..07f0f47e079 100644 --- a/engines/stark/resources/animhierarchy.cpp +++ b/engines/stark/resources/animhierarchy.cpp @@ -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()); diff --git a/engines/stark/resources/animhierarchy.h b/engines/stark/resources/animhierarchy.h index c6311ba7554..d8dfad9fe6a 100644 --- a/engines/stark/resources/animhierarchy.h +++ b/engines/stark/resources/animhierarchy.h @@ -49,6 +49,8 @@ public: void unselectItemAnim(ItemVisual *item); void selectItemAnim(ItemVisual *item); + Anim *getCurrentAnim(); + protected: void printData() override; diff --git a/engines/stark/resources/item.cpp b/engines/stark/resources/item.cpp index 0c8c11766a6..2999bda2fee 100644 --- a/engines/stark/resources/item.cpp +++ b/engines/stark/resources/item.cpp @@ -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(); diff --git a/engines/stark/resources/item.h b/engines/stark/resources/item.h index ea269b6c5eb..c326588c03a 100644 --- a/engines/stark/resources/item.h +++ b/engines/stark/resources/item.h @@ -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; diff --git a/engines/stark/resources/layer.cpp b/engines/stark/resources/layer.cpp index 626e75c5c5c..e0963a228be 100644 --- a/engines/stark/resources/layer.cpp +++ b/engines/stark/resources/layer.cpp @@ -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(); +} + +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(); diff --git a/engines/stark/resources/layer.h b/engines/stark/resources/layer.h index 69dc83269e4..c65b8c7564c 100644 --- a/engines/stark/resources/layer.h +++ b/engines/stark/resources/layer.h @@ -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 _items; }; } // End of namespace Stark diff --git a/engines/stark/resources/location.cpp b/engines/stark/resources/location.cpp index 21b43259f75..9a6b3f2b32a 100644 --- a/engines/stark/resources/location.cpp +++ b/engines/stark/resources/location.cpp @@ -41,6 +41,17 @@ void Location::onAllLoaded() { _layers = listChildren(); } +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() { } diff --git a/engines/stark/resources/location.h b/engines/stark/resources/location.h index 0c95382c195..eeb9907b029 100644 --- a/engines/stark/resources/location.h +++ b/engines/stark/resources/location.h @@ -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; diff --git a/engines/stark/scene.cpp b/engines/stark/scene.cpp index 11ca6cf8ac0..eb6ab6eb089 100644 --- a/engines/stark/scene.cpp +++ b/engines/stark/scene.cpp @@ -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::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); diff --git a/engines/stark/scene.h b/engines/stark/scene.h index ad49ac5ea9d..362ad0af584 100644 --- a/engines/stark/scene.h +++ b/engines/stark/scene.h @@ -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 _elements; + RenderEntryArray _elements; }; } // End of namespace Stark diff --git a/engines/stark/stark.cpp b/engines/stark/stark.cpp index 46cc48db006..3bb6d7ff493 100644 --- a/engines/stark/stark.cpp +++ b/engines/stark/stark.cpp @@ -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();