FastEngine 0.9.3
A multiplayer oriented 2D engine made with Vulkan.
Loading...
Searching...
No Matches
C_objSpriteCluster.hpp
1/*
2 * Copyright 2024 Guillaume Guillet
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#ifndef _FGE_C_OBJSPRITECLUSTER_HPP_INCLUDED
18#define _FGE_C_OBJSPRITECLUSTER_HPP_INCLUDED
19
20#include "FastEngine/fge_extern.hpp"
21#include "C_object.hpp"
22#include "FastEngine/accessor/C_texture.hpp"
23#include "FastEngine/extra/extra_function.hpp"
24
25#define FGE_OBJSPRITECLUSTER_CLASSNAME "FGE:OBJ:SPRITECLUSTER"
26
27namespace fge
28{
29
30class FGE_API ObjSpriteCluster : public fge::Object
31{
32public:
35 explicit ObjSpriteCluster(fge::Texture texture);
36
37 FGE_OBJ_DEFAULT_COPYMETHOD(fge::ObjSpriteCluster)
38
39 void setTexture(fge::Texture texture);
40
41 void clear();
42 void addSprite(fge::RectInt const& rectangle, fge::Vector2f const& offset = {0.0f, 0.0f});
43 void resize(std::size_t size);
44 void setTextureRect(std::size_t index, fge::RectInt const& rectangle);
45 void setColor(std::size_t index, fge::Color const& color);
46 void setOffset(std::size_t index, fge::Vector2f const& offset);
47
48 fge::Texture const& getTexture() const;
49
50 [[nodiscard]] std::optional<fge::RectInt> getTextureRect(std::size_t index) const;
51 [[nodiscard]] std::optional<fge::Color> getColor(std::size_t index) const;
52 [[nodiscard]] std::optional<fge::Vector2f> getOffset(std::size_t index) const;
53
54 FGE_OBJ_DRAW_DECLARE
55
56 void save(nlohmann::json& jsonObject, fge::Scene* scene) override;
57 void load(nlohmann::json& jsonObject, fge::Scene* scene) override;
58 void pack(fge::net::Packet& pck) override;
59 void unpack(fge::net::Packet const& pck) override;
60
61 char const* getClassName() const override;
62 char const* getReadableClassName() const override;
63
64 [[nodiscard]] fge::RectFloat getGlobalBounds() const override;
65 [[nodiscard]] std::optional<fge::RectFloat> getGlobalBounds(std::size_t index) const;
66 [[nodiscard]] fge::RectFloat getLocalBounds() const override;
67 [[nodiscard]] std::optional<fge::RectFloat> getLocalBounds(std::size_t index) const;
68
69private:
70 void updatePositions(std::size_t index);
71 void updateTexCoords(std::size_t index);
72
73 struct InstanceData
74 {
75 InstanceData() = default;
76 explicit InstanceData(fge::RectInt const& textureRect, fge::Vector2f const& offset) :
77 _offset(offset),
78 _textureRect(textureRect)
79 {}
80
81 fge::Vector2f _offset;
82 fge::RectInt _textureRect;
83 };
84
85 fge::Texture g_texture;
86
87 std::vector<InstanceData> g_instancesData;
88 fge::vulkan::VertexBuffer g_instancesVertices;
89};
90
91} // namespace fge
92
93#endif // _FGE_C_OBJSPRITECLUSTER_HPP_INCLUDED
Definition C_color.hpp:35
Definition C_objSpriteCluster.hpp:31
fge::RectFloat getLocalBounds() const override
Get the local bounds of the object (without any transformations)
void load(nlohmann::json &jsonObject, fge::Scene *scene) override
Load the object from a json object.
void pack(fge::net::Packet &pck) override
Pack the object into a packet.
fge::RectFloat getGlobalBounds() const override
Get the global bounds of the object.
char const * getClassName() const override
Get the unique class name of the object.
void save(nlohmann::json &jsonObject, fge::Scene *scene) override
Save the object to a json object.
char const * getReadableClassName() const override
Get a readable version of the class name.
void unpack(fge::net::Packet const &pck) override
Unpack the object from a packet.
The Object class is the base class for all objects in the engine.
Definition C_object.hpp:102
A scene contain a collection of object and handle them.
Definition C_scene.hpp:450
This class is a wrapper for the texture manager to allow easy manipulation.
Definition C_texture.hpp:36
Definition C_packet.hpp:70
Definition C_vertexBuffer.hpp:45