Estella 0.113.0
A fast 2D and 3D game engine powered by WebAssembly and ECS
Loading...
Searching...
No Matches
DragonBonesAdapter.hpp
Go to the documentation of this file.
1// SPDX-License-Identifier: Apache-2.0
2// SPDX-FileCopyrightText: Copyright (c) 2024-present ESEngine Team
30#pragma once
31
32#include <cstdint>
33#include <vector>
34
35#include "dragonBones/DragonBonesHeaders.h"
36
38
40
42class EsTextureData : public TextureData {
43 BIND_CLASS_TYPE_B(EsTextureData);
44
45public:
46 std::uint32_t textureId = 0;
47
48 EsTextureData() = default;
49
50 void _onClear() override {
51 textureId = 0;
52 TextureData::_onClear();
53 }
54};
55
56class EsTextureAtlasData : public TextureAtlasData {
57 BIND_CLASS_TYPE_B(EsTextureAtlasData);
58
59public:
61 std::uint32_t textureId = 0;
62
63 EsTextureAtlasData() = default;
64
65 void _onClear() override {
66 textureId = 0;
67 TextureAtlasData::_onClear();
68 }
69
70 TextureData* createTexture() const override { return BaseObject::borrowObject<EsTextureData>(); }
71
73 void setTexture(std::uint32_t id) {
74 textureId = id;
75 for (const auto& pair : textures) {
76 static_cast<EsTextureData*>(pair.second)->textureId = id;
77 }
78 }
79};
80
87class EsSlot : public Slot {
88 BIND_CLASS_TYPE_A(EsSlot);
89
90public:
91 std::vector<float> positions;
92 std::vector<float> uvs;
93 std::vector<std::uint16_t> indices;
94 std::uint32_t textureId = 0;
95 bool armatureSpace = false;
96
99 char rawDisplay = 0;
100 char meshDisplay = 0;
101
102 void _onClear() override {
103 positions.clear();
104 uvs.clear();
105 indices.clear();
106 textureId = 0;
107 armatureSpace = false;
108 Slot::_onClear();
109 }
110
115 void emit(es::skeletal::TriangleSink& sink, const float tint[4]) const;
116
117protected:
118 // — Scene-graph duties this module does not have —
119 void _initDisplay(void*, bool) override {}
120 void _disposeDisplay(void*, bool) override {}
121 void _onUpdateDisplay() override {}
122 void _addDisplay() override {}
123 void _replaceDisplay(void*, bool) override {}
124 void _removeDisplay() override {}
125 void _updateZOrder() override {}
126 void _updateVisible() override {}
127 void _updateBlendMode() override {}
128 void _updateColor() override {}
129
130 // — The ones that carry geometry —
131 void _updateFrame() override;
132 void _updateMesh() override;
133 void _updateTransform() override { armatureSpace = false; }
134 void _identityTransform() override { armatureSpace = true; }
135};
136
138class EsArmatureProxy : public IArmatureProxy {
139public:
140 ~EsArmatureProxy() override = default;
141
142 void dbInit(Armature* armatureValue) override { _armature = armatureValue; }
143 void dbClear() override { _armature = nullptr; }
144 void dbUpdate() override {}
145 void dispose(bool disposeProxy) override;
146 Armature* getArmature() const override { return _armature; }
147 Animation* getAnimation() const override { return _armature ? _armature->getAnimation() : nullptr; }
148
149 bool hasDBEventListener(const std::string&) const override { return false; }
150 void addDBEventListener(const std::string&, const std::function<void(EventObject*)>&) override {}
151 void removeDBEventListener(const std::string&, const std::function<void(EventObject*)>&) override {}
152 void dispatchDBEvent(const std::string&, EventObject*) override {}
153
154private:
155 Armature* _armature = nullptr;
156};
157
159class EsEventDispatcher : public IEventDispatcher {
160public:
161 ~EsEventDispatcher() override = default;
162 bool hasDBEventListener(const std::string&) const override { return false; }
163 void addDBEventListener(const std::string&, const std::function<void(EventObject*)>&) override {}
164 void removeDBEventListener(const std::string&, const std::function<void(EventObject*)>&) override {}
165 void dispatchDBEvent(const std::string&, EventObject*) override {}
166};
167
168class EsFactory : public BaseFactory {
169public:
170 EsFactory();
171 ~EsFactory() override;
172
173 static EsFactory& instance();
174
183 void advanceTime(float passedTime);
184
186 Armature* buildArmature(const std::string& armatureName, const std::string& dragonBonesName);
187
188protected:
193
194 TextureAtlasData* _buildTextureAtlasData(TextureAtlasData* textureAtlasData, void* textureAtlas) const override;
195 Armature* _buildArmature(const BuildArmaturePackage& dataPackage) const override;
196 Slot* _buildSlot(const BuildArmaturePackage& dataPackage, const SlotData* slotData, Armature* armature) const override;
197};
198
199DRAGONBONES_NAMESPACE_END
What every 2D skeletal-animation side module needs, none of which is about any particular one.
The armature's "display": nothing, because there is nothing to display into.
void removeDBEventListener(const std::string &, const std::function< void(EventObject *)> &) override
void dbClear() override
void dispose(bool disposeProxy) override
void addDBEventListener(const std::string &, const std::function< void(EventObject *)> &) override
void dbInit(Armature *armatureValue) override
Armature * getArmature() const override
void dbUpdate() override
void dispatchDBEvent(const std::string &, EventObject *) override
~EsArmatureProxy() override=default
bool hasDBEventListener(const std::string &) const override
Animation * getAnimation() const override
Nothing listens: events leave through the module's own ABI, not this one.
void addDBEventListener(const std::string &, const std::function< void(EventObject *)> &) override
void dispatchDBEvent(const std::string &, EventObject *) override
~EsEventDispatcher() override=default
bool hasDBEventListener(const std::string &) const override
void removeDBEventListener(const std::string &, const std::function< void(EventObject *)> &) override
Slot * _buildSlot(const BuildArmaturePackage &dataPackage, const SlotData *slotData, Armature *armature) const override
~EsFactory() override
static EsFactory & instance()
EsEventDispatcher _eventDispatcher
Armature * buildArmature(const std::string &armatureName, const std::string &dragonBonesName)
Build an armature by name; null when this data holds no such armature.
void advanceTime(float passedTime)
TextureAtlasData * _buildTextureAtlasData(TextureAtlasData *textureAtlasData, void *textureAtlas) const override
Armature * _buildArmature(const BuildArmaturePackage &dataPackage) const override
void _updateColor() override
void _identityTransform() override
void _updateTransform() override
void _updateBlendMode() override
void _initDisplay(void *, bool) override
std::uint32_t textureId
void _removeDisplay() override
void _updateFrame() override
void _updateZOrder() override
void _disposeDisplay(void *, bool) override
void _onClear() override
void _replaceDisplay(void *, bool) override
void _onUpdateDisplay() override
bool armatureSpace
positions already have the bones applied
void _addDisplay() override
std::vector< float > uvs
u,v per vertex
std::vector< float > positions
x,y per vertex
void emit(es::skeletal::TriangleSink &sink, const float tint[4]) const
void _updateVisible() override
std::vector< std::uint16_t > indices
void _updateMesh() override
std::uint32_t textureId
Bound after parsing, once the host has uploaded the page (see setTexture).
TextureData * createTexture() const override
void setTexture(std::uint32_t id)
Point every page of this atlas at an uploaded texture.
EsTextureAtlasData()=default
One atlas page: the texture the host bound to it, and its pixel size.
void _onClear() override
EsTextureData()=default
std::uint32_t textureId
Where a runtime pours the triangles it posed.