Aeon Engine c550894
AeonGames Open Source Game Engine
Loading...
Searching...
No Matches
Component.hpp
1/*
2Copyright (C) 2014-2019,2021,2025,2026 Rodrigo Jose Hernandez Cordoba
3
4Licensed under the Apache License, Version 2.0 (the "License");
5you may not use this file except in compliance with the License.
6You may obtain a copy of the License at
7
8http://www.apache.org/licenses/LICENSE-2.0
9
10Unless required by applicable law or agreed to in writing, software
11distributed under the License is distributed on an "AS IS" BASIS,
12WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13See the License for the specific language governing permissions and
14limitations under the License.
15*/
16#ifndef AEONGAMES_COMPONENT_H
17#define AEONGAMES_COMPONENT_H
18#include <memory>
19#include <functional>
20#include <variant>
21#include <string>
22#include <type_traits>
24#include "aeongames/StringId.hpp"
26
27namespace AeonGames
28{
29 class Node;
30 class Window;
31 class Renderer;
39 {
40 public:
42 DLL virtual ~Component() = 0;
47 DLL void SetProperty ( const StringId& aId, const Property& aProperty );
52 DLL void SetProperty ( const std::string& aId, const Property& aProperty );
56 virtual const StringId& GetId() const = 0;
60 virtual size_t GetPropertyCount () const = 0;
64 virtual const StringId* GetPropertyInfoArray () const = 0;
69 virtual Property GetProperty ( const StringId& aId ) const = 0;
74 virtual void SetProperty ( uint32_t aId, const Property& aProperty ) = 0;
79 virtual void Update ( Node& aNode, double aDelta ) = 0;
85 virtual void Render ( const Node& aNode, Renderer& aRenderer, void* aWindowId ) = 0;
91 virtual void ProcessMessage ( Node& aNode, uint32_t aMessageType, const void* aMessageData ) = 0;
92 };
93
99 DLL std::unique_ptr<Component> ConstructComponent ( uint32_t aIdentifier );
104 DLL std::unique_ptr<Component> ConstructComponent ( const std::string& aIdentifier );
109 DLL std::unique_ptr<Component> ConstructComponent ( const StringId& aIdentifier );
111 DLL bool RegisterComponentConstructor ( const StringId& aIdentifier, const std::function<std::unique_ptr<Component>() >& aConstructor );
113 DLL bool UnregisterComponentConstructor ( const StringId& aIdentifier );
115 DLL void EnumerateComponentConstructors ( const std::function<bool ( const StringId& ) >& aEnumerator );
117}
118#endif
Platform-specific macros, includes, and DLL export/import definitions.
Defines the Property variant type used for generic value storage.
Abstract base class for node components.
Definition Component.hpp:39
virtual void SetProperty(uint32_t aId, const Property &aProperty)=0
Set the value aProperty for the property identified by aId.
DLL void SetProperty(const StringId &aId, const Property &aProperty)
Set a property by its StringId identifier.
Definition Component.cpp:23
virtual DLL ~Component()=0
Pure virtual destructor.
virtual size_t GetPropertyCount() const =0
Get the number of properties exposed by this component.
virtual void Render(const Node &aNode, Renderer &aRenderer, void *aWindowId)=0
Render the component.
virtual const StringId & GetId() const =0
Get the unique identifier for this component type.
virtual Property GetProperty(const StringId &aId) const =0
Get the value of a property.
virtual const StringId * GetPropertyInfoArray() const =0
Get the array of property identifiers.
virtual void ProcessMessage(Node &aNode, uint32_t aMessageType, const void *aMessageData)=0
Process an incoming message.
virtual void Update(Node &aNode, double aDelta)=0
Update the component state.
Scene graph node representing an entity in the game world.
Definition Node.hpp:54
Abstract base class for rendering backends.
Definition Renderer.hpp:44
CRC-based compile-time string identifier.
Definition StringId.hpp:31
<- This is here just for the literals
Definition AABB.hpp:31
DLL bool RegisterComponentConstructor(const StringId &aIdentifier, const std::function< std::unique_ptr< Component >() > &aConstructor)
Registers a Component loader for a specific identifier.
std::variant< int, long, long long, unsigned, unsigned long, unsigned long long, float, double, std::string, std::filesystem::path > Property
A variant type that can hold any commonly used property value.
Definition Property.hpp:31
DLL std::unique_ptr< Component > ConstructComponent(uint32_t aIdentifier)
Construct a component from a numeric identifier.
DLL void EnumerateComponentConstructors(const std::function< bool(const StringId &) > &aEnumerator)
Enumerates Component loader identifiers via an enumerator functor.
DLL bool UnregisterComponentConstructor(const StringId &aIdentifier)
Unregisters a Component loader for a specific identifier.