FastEngine 0.9.3
A multiplayer oriented 2D engine made with Vulkan.
Loading...
Searching...
No Matches
C_childObjectsAccessor.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_CHILDOBJECTSACCESSOR_HPP_INCLUDED
18#define _FGE_C_CHILDOBJECTSACCESSOR_HPP_INCLUDED
19
20#include "FastEngine/fge_extern.hpp"
21#include "FastEngine/graphic/C_renderStates.hpp"
22#include "FastEngine/graphic/C_renderWindow.hpp"
23#include <chrono>
24#include <limits>
25#include <memory>
26#include <vector>
27
28namespace fge
29{
30
31class Event;
32class Scene;
33class Object;
34class ObjectData;
35using ObjectPtr = std::unique_ptr<fge::Object>;
36using ObjectDataWeak = std::weak_ptr<fge::ObjectData>;
37using ObjectDataShared = std::shared_ptr<fge::ObjectData>;
38
40{
41public:
42 explicit ChildObjectsAccessor(fge::Object* owner);
43 ChildObjectsAccessor([[maybe_unused]] ChildObjectsAccessor const& r) {}
44 ChildObjectsAccessor([[maybe_unused]] ChildObjectsAccessor&& r) noexcept {}
45
46 ChildObjectsAccessor& operator=([[maybe_unused]] ChildObjectsAccessor const& r) { return *this; }
47 ChildObjectsAccessor& operator=([[maybe_unused]] ChildObjectsAccessor&& r) noexcept { return *this; }
48
49 void clear();
50
51 fge::ObjectDataShared addExistingObject(fge::Object* object,
52 std::size_t insertionIndex = std::numeric_limits<std::size_t>::max());
53 fge::ObjectDataShared addNewObject(fge::ObjectPtr&& newObject,
54 std::size_t insertionIndex = std::numeric_limits<std::size_t>::max());
55
56 [[nodiscard]] std::size_t getSize() const;
57 [[nodiscard]] fge::Object const* get(std::size_t index) const;
58 [[nodiscard]] fge::Object* get(std::size_t index);
59 [[nodiscard]] fge::ObjectDataShared getSharedPtr(std::size_t index) const;
60
61 void remove(std::size_t index);
62 void remove(std::size_t first, std::size_t last);
63
64#ifdef FGE_DEF_SERVER
65 void update(fge::Event& event, std::chrono::microseconds const& deltaTime, fge::Scene& scene);
66#else
67 void update(fge::RenderWindow& screen,
68 fge::Event& event,
69 std::chrono::microseconds const& deltaTime,
70 fge::Scene& scene) const;
71 void draw(fge::RenderTarget& target, fge::RenderStates const& states) const;
72#endif //FGE_DEF_SERVER
73
74 void putInFront(std::size_t index);
75 void putInBack(std::size_t index);
76
77 [[nodiscard]] std::size_t getActualIteratedIndex() const;
78
79 [[nodiscard]] std::size_t getIndex(fge::Object* object) const;
80
81private:
82 struct DataContext
83 {
85 {
86 void operator()(fge::ObjectData* data) const;
87 };
88
89 fge::Object* _objPtr;
90 fge::ObjectDataShared _objData;
91 };
92
93 std::vector<DataContext> g_data;
94 mutable std::size_t g_actualIteratedIndex{std::numeric_limits<std::size_t>::max()};
95 fge::Object* g_owner{nullptr};
96};
97
98} // namespace fge
99
100#endif // _FGE_C_CHILDOBJECTSACCESSOR_HPP_INCLUDED
Definition C_childObjectsAccessor.hpp:40
This class is a wrapper for SDL events.
Definition C_event.hpp:59
Data wrapper representing an Object in a Scene.
Definition C_scene.hpp:159
The Object class is the base class for all objects in the engine.
Definition C_object.hpp:102
The RenderStates class contains all the information needed to render something.
Definition C_renderStates.hpp:412
Definition C_renderTarget.hpp:56
Definition C_renderWindow.hpp:51
A scene contain a collection of object and handle them.
Definition C_scene.hpp:450