Divide Framework 0.1
A free and open-source 3D Framework under heavy development
Loading...
Searching...
No Matches
ECSSystem.h
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_H_
34#define DVD_ECS_SYSTEM_H_
35
37#include <ECS/System.h>
38#include <ECS/Engine.h>
39
40namespace Divide {
41 class ByteBuffer;
42 class SceneGraphNode;
43 template<class T, class U>
44 class ECSSystem;
45
47 virtual ~ECSSerializerProxy() = default;
48
49 virtual bool saveCache(const SceneGraphNode* sgn, ByteBuffer& outputBuffer) = 0;
50 virtual bool loadCache(SceneGraphNode* sgn, ByteBuffer& inputBuffer) = 0;
51 };
52
53 template<class T, class U>
55 [[nodiscard]] bool saveCache(const SceneGraphNode* sgn, ByteBuffer& outputBuffer) override {
56 assert(_parent != nullptr);
57
58 return _parent->saveCache(sgn, outputBuffer);
59 }
60 [[nodiscard]] bool loadCache(SceneGraphNode* sgn, ByteBuffer& inputBuffer) override {
61 assert(_parent != nullptr);
62
63 return _parent->loadCache(sgn, inputBuffer);
64 }
65
67 };
68
69 template<class T, class U>
70 class ECSSystem : public ECS::System<T> {
71 public:
72
73 explicit ECSSystem(ECS::ECSEngine& engine);
74 virtual ~ECSSystem() override = default;
75
76 virtual bool saveCache(const SceneGraphNode* sgn, ByteBuffer& outputBuffer);
77 virtual bool loadCache(SceneGraphNode* sgn, ByteBuffer& inputBuffer);
78
79 void PreUpdate(F32 dt) override;
80 void Update(F32 dt) override;
81 void PostUpdate(F32 dt) override;
82 void OnFrameStart() override;
83 void OnFrameEnd() override;
84
85 [[nodiscard]] ECS::ISystemSerializer& GetSerializer() noexcept override { return _serializer; }
86 [[nodiscard]] const ECS::ISystemSerializer& GetSerializer() const noexcept override { return _serializer; }
87
88 protected:
90
93
94 };
95
96}
97
98#endif //DVD_ECS_SYSTEM_H_
99
100#include "ECSSystem.inl"
virtual bool saveCache(const SceneGraphNode *sgn, ByteBuffer &outputBuffer)
Definition: ECSSystem.inl:50
virtual ~ECSSystem() override=default
void PreUpdate(F32 dt) override
Definition: ECSSystem.inl:65
virtual bool loadCache(SceneGraphNode *sgn, ByteBuffer &inputBuffer)
Definition: ECSSystem.inl:57
ECS::ECSEngine & _engine
Definition: ECSSystem.h:89
ECS::ISystemSerializer & GetSerializer() noexcept override
Definition: ECSSystem.h:85
const ECS::ISystemSerializer & GetSerializer() const noexcept override
Definition: ECSSystem.h:86
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
Handle console commands that start with a forward slash.
Definition: AIProcessor.cpp:7
eastl::vector< Type > vector
Definition: Vector.h:42
bool loadCache(SceneGraphNode *sgn, ByteBuffer &inputBuffer) override
Definition: ECSSystem.h:60
bool saveCache(const SceneGraphNode *sgn, ByteBuffer &outputBuffer) override
Definition: ECSSystem.h:55
ECSSystem< T, U > * _parent
Definition: ECSSystem.h:66
virtual ~ECSSerializerProxy()=default
virtual bool loadCache(SceneGraphNode *sgn, ByteBuffer &inputBuffer)=0
virtual bool saveCache(const SceneGraphNode *sgn, ByteBuffer &outputBuffer)=0