Divide Framework 0.1
A free and open-source 3D Framework under heavy development
Loading...
Searching...
No Matches
ECSSystem.inl
Go to the documentation of this file.
1/*
2Copyright (c) 2018 DIVIDE-Studio
3Copyright (c) 2009 Ionut Cava
4
5This file is part of DIVIDE Framework.
6
7Permission is hereby granted, free of charge, to any person obtaining a copy of
8this software
9and associated documentation files (the "Software"), to deal in the Software
10without restriction,
11including without limitation the rights to use, copy, modify, merge, publish,
12distribute, sublicense,
13and/or sell copies of the Software, and to permit persons to whom the Software
14is furnished to do so,
15subject to the following conditions:
16
17The above copyright notice and this permission notice shall be included in all
18copies or substantial portions of the Software.
19
20THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21IMPLIED,
22INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
23PARTICULAR PURPOSE AND NONINFRINGEMENT.
24IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
25DAMAGES OR OTHER LIABILITY,
26WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
27CONNECTION WITH THE SOFTWARE
28OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29
30*/
31
32#pragma once
33#ifndef DVD_ECS_SYSTEM_INL_
34#define DVD_ECS_SYSTEM_INL_
35
37
38namespace Divide {
40
41 template<class T, class U>
43 : _engine(engine)
44 {
45 _serializer._parent = this;
47 }
48
49 template<class T, class U>
50 bool ECSSystem<T, U>::saveCache([[maybe_unused]] const SceneGraphNode* sgn, ByteBuffer& outputBuffer)
51 {
52 outputBuffer << BYTE_BUFFER_VERSION_ECS_MANAGER;
53 return true;
54 }
55
56 template<class T, class U>
57 bool ECSSystem<T, U>::loadCache([[maybe_unused]] SceneGraphNode* sgn, ByteBuffer& inputBuffer)
58 {
59 auto tempVer = decltype(BYTE_BUFFER_VERSION_ECS_MANAGER){0};
60 inputBuffer >> tempVer;
61 return tempVer == BYTE_BUFFER_VERSION_ECS_MANAGER;
62 }
63
64 template<class T, class U>
65 void ECSSystem<T, U>::PreUpdate([[maybe_unused]] const F32 dt)
66 {
67 }
68
69 template<class T, class U>
70 void ECSSystem<T, U>::Update([[maybe_unused]] const F32 dt)
71 {
73 }
74
75 template<class T, class U>
76 void ECSSystem<T, U>::PostUpdate( [[maybe_unused]] const F32 dt)
77 {
79 }
81 template<class T, class U>
83 {
85
86 bool expected = true;
87 if (ECS::ComponentMonitor<U>::s_ComponentsChanged.compare_exchange_strong(expected, false))
88 {
89 const auto container = _engine.GetComponentManager()->GetComponentContainer<U>();
90 const size_t compCount = container->size();
91 _componentCache.resize(compCount);
92
93 auto iterBegin = container->begin();
94 for (size_t idx = 0u; idx < compCount; ++idx)
95 {
96 _componentCache[idx] = &*iterBegin;
97 ++iterBegin;
98 }
99 }
100 }
101
102 template<class T, class U>
104
105 }
106}
107
108#endif //DVD_ECS_SYSTEM_INL_
#define PROFILE_SCOPE_AUTO(CATEGORY)
Definition: Profiler.h:87
virtual bool saveCache(const SceneGraphNode *sgn, ByteBuffer &outputBuffer)
Definition: ECSSystem.inl:50
void PreUpdate(F32 dt) override
Definition: ECSSystem.inl:65
virtual bool loadCache(SceneGraphNode *sgn, ByteBuffer &inputBuffer)
Definition: ECSSystem.inl:57
ECSSystem(ECS::ECSEngine &engine)
Definition: ECSSystem.inl:42
void OnFrameStart() override
Definition: ECSSystem.inl:82
void PostUpdate(F32 dt) override
Definition: ECSSystem.inl:76
void OnFrameEnd() override
Definition: ECSSystem.inl:103
ECSSerializer< T, U > _serializer
Definition: ECSSystem.h:91
void Update(F32 dt) override
Definition: ECSSystem.inl:70
vector< U * > _componentCache
Definition: ECSSystem.h:92
constexpr U16 MAX_VISIBLE_NODES
Estimated maximum number of visible objects per render pass (this includes debug primitives)
Definition: config.h:120
constexpr Optick::Category::Type GameLogic
Definition: Profiler.h:63
Handle console commands that start with a forward slash.
Definition: AIProcessor.cpp:7
constexpr U16 BYTE_BUFFER_VERSION_ECS_MANAGER
Definition: ECSSystem.inl:39
uint16_t U16