Skip to content

Commit 96e2b9a

Browse files
author
dgengin
committed
- refactor CompositeTexture as a TexturePack
1 parent eaf5573 commit 96e2b9a

36 files changed

+508
-633
lines changed

CMakeLists.txt

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,6 @@ set(SOURCE_FILES
5252
src/Circle.h
5353
src/CmdLineUtils.cpp
5454
src/CmdLineUtils.h
55-
src/CompositeTexture.cpp
56-
src/CompositeTexture.h
5755
src/DrawableText.h
5856
src/Event.cpp
5957
src/Event.h
@@ -191,8 +189,6 @@ set(SOURCE_FILES
191189
src/Parser/ParseButton.h
192190
src/Parser/ParseCircle.cpp
193191
src/Parser/ParseCircle.h
194-
src/Parser/ParseCompositeTexture.cpp
195-
src/Parser/ParseCompositeTexture.h
196192
src/Parser/ParseCondition.cpp
197193
src/Parser/ParseCondition.h
198194
src/Parser/ParseCursor.cpp
@@ -302,6 +298,8 @@ set(SOURCE_FILES
302298
src/TexturePacks/BitmapFontTexturePack.h
303299
src/TexturePacks/CachedTexturePack.cpp
304300
src/TexturePacks/CachedTexturePack.h
301+
src/TexturePacks/CompositeTexturePack.cpp
302+
src/TexturePacks/CompositeTexturePack.h
305303
src/TexturePacks/IndexedTexturePack.cpp
306304
src/TexturePacks/IndexedTexturePack.h
307305
src/TexturePacks/RectTexturePack.cpp
@@ -327,6 +325,7 @@ set(SOURCE_FILES
327325
src/Utils/UnorderedStringMap.h
328326
src/Utils/Utils.cpp
329327
src/Utils/Utils.h
328+
src/Utils/Vector2D.h
330329
)
331330

332331
if(FFmpeg_FOUND)

Project.vcxproj

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,6 @@
7777
<ClCompile Include="src\CachedImagePack.cpp" />
7878
<ClCompile Include="src\Circle.cpp" />
7979
<ClCompile Include="src\CmdLineUtils.cpp" />
80-
<ClCompile Include="src\CompositeTexture.cpp" />
8180
<ClCompile Include="src\Event.cpp" />
8281
<ClCompile Include="src\FadeInOut.cpp" />
8382
<ClCompile Include="src\FileUtils.cpp" />
@@ -114,7 +113,6 @@
114113
<ClCompile Include="src\Parser\ParseAudioCommon.cpp" />
115114
<ClCompile Include="src\Parser\ParseButton.cpp" />
116115
<ClCompile Include="src\Parser\ParseCircle.cpp" />
117-
<ClCompile Include="src\Parser\ParseCompositeTexture.cpp" />
118116
<ClCompile Include="src\Parser\ParseCondition.cpp" />
119117
<ClCompile Include="src\Parser\ParseCursor.cpp" />
120118
<ClCompile Include="src\Parser\ParseEvent.cpp" />
@@ -208,6 +206,7 @@
208206
<ClCompile Include="src\Text.cpp" />
209207
<ClCompile Include="src\TexturePacks\BitmapFontTexturePack.cpp" />
210208
<ClCompile Include="src\TexturePacks\CachedTexturePack.cpp" />
209+
<ClCompile Include="src\TexturePacks\CompositeTexturePack.cpp" />
211210
<ClCompile Include="src\TexturePacks\IndexedTexturePack.cpp" />
212211
<ClCompile Include="src\TexturePacks\RectTexturePack.cpp" />
213212
<ClCompile Include="src\TexturePacks\SimpleTexturePack.cpp" />
@@ -263,7 +262,6 @@
263262
<ClInclude Include="src\CachedImagePack.h" />
264263
<ClInclude Include="src\Circle.h" />
265264
<ClInclude Include="src\CmdLineUtils.h" />
266-
<ClInclude Include="src\CompositeTexture.h" />
267265
<ClInclude Include="src\FadeInOut.h" />
268266
<ClInclude Include="src\FileBytes.h" />
269267
<ClInclude Include="src\FileUtils.h" />
@@ -304,7 +302,6 @@
304302
<ClInclude Include="src\Parser\ParseAudioCommon.h" />
305303
<ClInclude Include="src\Parser\ParseButton.h" />
306304
<ClInclude Include="src\Parser\ParseCircle.h" />
307-
<ClInclude Include="src\Parser\ParseCompositeTexture.h" />
308305
<ClInclude Include="src\Parser\ParseCondition.h" />
309306
<ClInclude Include="src\Parser\ParseCursor.h" />
310307
<ClInclude Include="src\Parser\ParseEvent.h" />
@@ -428,6 +425,7 @@
428425
<ClInclude Include="src\TextureInfo.h" />
429426
<ClInclude Include="src\TexturePacks\BitmapFontTexturePack.h" />
430427
<ClInclude Include="src\TexturePacks\CachedTexturePack.h" />
428+
<ClInclude Include="src\TexturePacks\CompositeTexturePack.h" />
431429
<ClInclude Include="src\TexturePacks\IndexedTexturePack.h" />
432430
<ClInclude Include="src\TexturePacks\RectTexturePack.h" />
433431
<ClInclude Include="src\TexturePacks\SimpleTexturePack.h" />
@@ -449,6 +447,7 @@
449447
<ClInclude Include="src\Utils\ReverseIterable.h" />
450448
<ClInclude Include="src\Utils\UnorderedStringMap.h" />
451449
<ClInclude Include="src\Utils\Utils.h" />
450+
<ClInclude Include="src\Utils\Vector2D.h" />
452451
<ClInclude Include="src\Variable.h" />
453452
<ClInclude Include="src\VarOrPredicate.h" />
454453
</ItemGroup>

src/Actions/ActAnimation.h

Lines changed: 6 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -41,46 +41,24 @@ class ActAnimationSetAnimation : public Action
4141
sf::Time refresh;
4242
bool resetAnimation;
4343
bool updateAnimationType;
44-
bool setCompositeTexture;
4544

4645
public:
4746
ActAnimationSetAnimation(const std::string_view id_,
4847
const std::string_view idTexturePack_, int32_t groupIdx_, int32_t directionIdx_,
49-
sf::Time refresh_, bool resetAnimation_, bool updateAnimationType_,
50-
bool setCompositeTexture_) : id(id_), idTexturePack(idTexturePack_),
51-
groupIdx(groupIdx_), directionIdx(directionIdx_), refresh(refresh_),
52-
resetAnimation(resetAnimation_), updateAnimationType(updateAnimationType_),
53-
setCompositeTexture(setCompositeTexture_) {}
48+
sf::Time refresh_, bool resetAnimation_, bool updateAnimationType_) : id(id_),
49+
idTexturePack(idTexturePack_), groupIdx(groupIdx_), directionIdx(directionIdx_),
50+
refresh(refresh_), resetAnimation(resetAnimation_), updateAnimationType(updateAnimationType_) {}
5451

5552
bool execute(Game& game) override
5653
{
5754
auto animation = game.Resources().getDrawable<Animation>(id);
5855
if (animation != nullptr)
5956
{
60-
TexturePackVariant texVar;
61-
if (idTexturePack.empty() == false)
62-
{
63-
if (setCompositeTexture == false)
64-
{
65-
auto tex = game.Resources().getTexturePack(idTexturePack);
66-
if (tex != nullptr)
67-
{
68-
texVar = std::move(tex);
69-
}
70-
}
71-
else
72-
{
73-
auto tex = game.Resources().getCompositeTexture(idTexturePack);
74-
if (tex != nullptr)
75-
{
76-
texVar = std::move(tex);
77-
}
78-
}
79-
}
80-
if (texVar.holdsNullTexturePack() == false)
57+
auto texPack = game.Resources().getTexturePack(idTexturePack);
58+
if (texPack != nullptr)
8159
{
8260
animation->setAnimation(
83-
std::move(texVar), groupIdx, directionIdx,
61+
texPack, groupIdx, directionIdx,
8462
resetAnimation, updateAnimationType
8563
);
8664
}

src/Animation.cpp

Lines changed: 12 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@
22
#include "Game.h"
33
#include "Utils/Utils.h"
44

5-
Animation::Animation(TexturePackVariant texturePackVar, bool pause)
6-
: animation(texturePackVar, pause)
5+
Animation::Animation(const std::shared_ptr<TexturePack>& texturePack, bool pause)
6+
: animation(texturePack, pause)
77
{
88
animation.updateTexture(sprite);
99
}
1010

11-
Animation::Animation(TexturePackVariant texturePackVar,
12-
const AnimationInfo& animInfo, bool pause) : animation(texturePackVar, animInfo, pause)
11+
Animation::Animation(const std::shared_ptr<TexturePack>& texturePack,
12+
const AnimationInfo& animInfo, bool pause) : animation(texturePack, animInfo, pause)
1313
{
1414
animation.updateTexture(sprite);
1515
}
@@ -25,10 +25,10 @@ void Animation::setAnimation(const AnimationInfo& animInfo)
2525
animation.updateTexture(sprite);
2626
}
2727

28-
void Animation::setAnimation(TexturePackVariant texturePackVar,
28+
void Animation::setAnimation(const std::shared_ptr<TexturePack>& texturePack,
2929
const AnimationInfo& animInfo)
3030
{
31-
animation.setTexturePack(std::move(texturePackVar));
31+
animation.setTexturePack(texturePack);
3232
animation.setAnimation(animInfo);
3333
animation.updateTexture(sprite);
3434
}
@@ -39,10 +39,10 @@ void Animation::setAnimation(int32_t groupIdx, int32_t directionIdx)
3939
animation.updateTexture(sprite);
4040
}
4141

42-
void Animation::setAnimation(TexturePackVariant texturePackVar,
42+
void Animation::setAnimation(const std::shared_ptr<TexturePack>& texturePack,
4343
int32_t groupIdx, int32_t directionIdx)
4444
{
45-
animation.setTexturePack(std::move(texturePackVar));
45+
animation.setTexturePack(texturePack);
4646
animation.setAnimation(groupIdx, directionIdx);
4747
animation.updateTexture(sprite);
4848
}
@@ -56,11 +56,11 @@ void Animation::setAnimation(int32_t groupIdx, int32_t directionIdx,
5656
animation.updateTexture(sprite);
5757
}
5858

59-
void Animation::setAnimation(TexturePackVariant texturePackVar,
59+
void Animation::setAnimation(const std::shared_ptr<TexturePack>& texturePack,
6060
int32_t groupIdx, int32_t directionIdx,
6161
bool resetAnimation, bool updateAnimationType)
6262
{
63-
animation.setTexturePack(std::move(texturePackVar));
63+
animation.setTexturePack(texturePack);
6464
animation.setAnimation(
6565
groupIdx, directionIdx, resetAnimation, updateAnimationType
6666
);
@@ -74,10 +74,10 @@ void Animation::setAnimation(int32_t groupIdx, int32_t directionIdx,
7474
animation.updateTexture(sprite);
7575
}
7676

77-
void Animation::setAnimation(TexturePackVariant texturePackVar_,
77+
void Animation::setAnimation(const std::shared_ptr<TexturePack>& texturePack,
7878
int32_t groupIdx, int32_t directionIdx, AnimationType animationType)
7979
{
80-
animation.setTexturePack(std::move(texturePackVar_));
80+
animation.setTexturePack(texturePack);
8181
animation.setAnimation(groupIdx, directionIdx, animationType);
8282
animation.updateTexture(sprite);
8383
}
@@ -87,26 +87,6 @@ bool Animation::holdsNullTexturePack() const noexcept
8787
return animation.holdsNullTexturePack();
8888
}
8989

90-
bool Animation::holdsTexturePack() const noexcept
91-
{
92-
return animation.holdsTexturePack();
93-
}
94-
95-
bool Animation::holdsTexturePack(const std::shared_ptr<TexturePack>& obj) const noexcept
96-
{
97-
return animation.holdsTexturePack();
98-
}
99-
100-
bool Animation::holdsCompositeTexture() const noexcept
101-
{
102-
return animation.holdsCompositeTexture();
103-
}
104-
105-
bool Animation::holdsCompositeTexture(const std::shared_ptr<CompositeTexture>& obj) const noexcept
106-
{
107-
return animation.holdsCompositeTexture();
108-
}
109-
11090
const std::shared_ptr<TexturePack>& Animation::getTexturePack() const
11191
{
11292
return animation.getTexturePack();
@@ -117,16 +97,6 @@ std::shared_ptr<TexturePack>& Animation::getTexturePack()
11797
return animation.getTexturePack();
11898
}
11999

120-
const std::shared_ptr<CompositeTexture>& Animation::getCompositeTexture() const
121-
{
122-
return animation.getCompositeTexture();
123-
}
124-
125-
std::shared_ptr<CompositeTexture>& Animation::getCompositeTexture()
126-
{
127-
return animation.getCompositeTexture();
128-
}
129-
130100
void Animation::update(Game& game)
131101
{
132102
if (Visible() == true &&

src/Animation.h

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ class Animation : public Image
1111
public:
1212
Animation() {}
1313
Animation(const sf::Texture& texture) : Image(texture) {}
14-
Animation(TexturePackVariant texturePackVar, bool pause = false);
14+
Animation(const std::shared_ptr<TexturePack>& texturePack, bool pause = false);
1515

16-
Animation(TexturePackVariant texturePackVar,
16+
Animation(const std::shared_ptr<TexturePack>& texturePack,
1717
const AnimationInfo& animInfo, bool pause = false);
1818

1919
void updateTexture();
@@ -22,23 +22,23 @@ class Animation : public Image
2222
void Pause(bool pause) noexcept { animation.pause = pause; }
2323

2424
void setAnimation(const AnimationInfo& animInfo);
25-
void setAnimation(TexturePackVariant texturePackVar, const AnimationInfo& animInfo);
25+
void setAnimation(const std::shared_ptr<TexturePack>& texturePack, const AnimationInfo& animInfo);
2626
void setAnimation(int32_t groupIdx, int32_t directionIdx);
2727

28-
void setAnimation(TexturePackVariant texturePackVar,
28+
void setAnimation(const std::shared_ptr<TexturePack>& texturePack,
2929
int32_t groupIdx, int32_t directionIdx);
3030

3131
void setAnimation(int32_t groupIdx, int32_t directionIdx,
3232
bool resetAnimation, bool updateAnimationType);
3333

34-
void setAnimation(TexturePackVariant texturePackVar,
34+
void setAnimation(const std::shared_ptr<TexturePack>& texturePack,
3535
int32_t groupIdx, int32_t directionIdx,
3636
bool resetAnimation, bool updateAnimationType);
3737

3838
void setAnimation(int32_t groupIdx, int32_t directionIdx,
3939
AnimationType animationType);
4040

41-
void setAnimation(TexturePackVariant texturePackVar,
41+
void setAnimation(const std::shared_ptr<TexturePack>& texturePack,
4242
int32_t groupIdx, int32_t directionIdx,
4343
AnimationType animationType);
4444

@@ -51,14 +51,8 @@ class Animation : public Image
5151
bool hasPlayOnceAnimationFinished() const noexcept { return animation.hasPlayOnceAnimationFinished(); }
5252

5353
bool holdsNullTexturePack() const noexcept;
54-
bool holdsTexturePack() const noexcept;
55-
bool holdsTexturePack(const std::shared_ptr<TexturePack>& obj) const noexcept;
56-
bool holdsCompositeTexture() const noexcept;
57-
bool holdsCompositeTexture(const std::shared_ptr<CompositeTexture>& obj) const noexcept;
5854
const std::shared_ptr<TexturePack>& getTexturePack() const;
5955
std::shared_ptr<TexturePack>& getTexturePack();
60-
const std::shared_ptr<CompositeTexture>& getCompositeTexture() const;
61-
std::shared_ptr<CompositeTexture>& getCompositeTexture();
6256

6357
void update(Game& game) override;
6458

0 commit comments

Comments
 (0)