Commit b2bc449b authored by Alex44098's avatar Alex44098
Browse files

Uploading a project

parent 7569b0b3
Showing with 1296 additions and 0 deletions
+1296 -0
## Ignore Visual Studio temporary files, build results, and
## files generated by popular Visual Studio add-ons.
##
## Get latest from https://github.com/github/gitignore/blob/main/VisualStudio.gitignore
# User folder
scenes/
shaders/
scr/
default_skybox/
blue_skybox/
# User-specific files
*.rsuser
*.suo
*.user
*.userosscache
*.sln.docstates
default.json
# User-specific files (MonoDevelop/Xamarin Studio)
*.userprefs
# Mono auto generated files
mono_crash.*
# Build results
[Dd]ebug/
[Dd]ebugPublic/
[Rr]elease/
[Rr]eleases/
x64/
x86/
[Ww][Ii][Nn]32/
[Aa][Rr][Mm]/
[Aa][Rr][Mm]64/
bld/
[Bb]in/
[Oo]bj/
[Ll]og/
[Ll]ogs/
# Visual Studio 2015/2017 cache/options directory
.vs/
# Uncomment if you have tasks that create the project's static files in wwwroot
#wwwroot/
# Visual Studio 2017 auto generated files
Generated\ Files/
# MSTest test Results
[Tt]est[Rr]esult*/
[Bb]uild[Ll]og.*
# NUnit
*.VisualState.xml
TestResult.xml
nunit-*.xml
# Build Results of an ATL Project
[Dd]ebugPS/
[Rr]eleasePS/
dlldata.c
# Benchmark Results
BenchmarkDotNet.Artifacts/
# .NET Core
project.lock.json
project.fragment.lock.json
artifacts/
# ASP.NET Scaffolding
ScaffoldingReadMe.txt
# StyleCop
StyleCopReport.xml
# Files built by Visual Studio
*_i.c
*_p.c
*_h.h
*.ilk
*.meta
*.obj
*.iobj
*.pch
*.pdb
*.ipdb
*.pgc
*.pgd
*.rsp
# but not Directory.Build.rsp, as it configures directory-level build defaults
!Directory.Build.rsp
*.sbr
*.tlb
*.tli
*.tlh
*.tmp
*.tmp_proj
*_wpftmp.csproj
*.log
*.tlog
*.vspscc
*.vssscc
.builds
*.pidb
*.svclog
*.scc
# Chutzpah Test files
_Chutzpah*
# Visual C++ cache files
ipch/
*.aps
*.ncb
*.opendb
*.opensdf
*.sdf
*.cachefile
*.VC.db
*.VC.VC.opendb
# Visual Studio profiler
*.psess
*.vsp
*.vspx
*.sap
# Visual Studio Trace Files
*.e2e
# TFS 2012 Local Workspace
$tf/
# Guidance Automation Toolkit
*.gpState
# ReSharper is a .NET coding add-in
_ReSharper*/
*.[Rr]e[Ss]harper
*.DotSettings.user
# TeamCity is a build add-in
_TeamCity*
# DotCover is a Code Coverage Tool
*.dotCover
# AxoCover is a Code Coverage Tool
.axoCover/*
!.axoCover/settings.json
# Coverlet is a free, cross platform Code Coverage Tool
coverage*.json
coverage*.xml
coverage*.info
# Visual Studio code coverage results
*.coverage
*.coveragexml
# NCrunch
_NCrunch_*
.*crunch*.local.xml
nCrunchTemp_*
# MightyMoose
*.mm.*
AutoTest.Net/
# Web workbench (sass)
.sass-cache/
# Installshield output folder
[Ee]xpress/
# DocProject is a documentation generator add-in
DocProject/buildhelp/
DocProject/Help/*.HxT
DocProject/Help/*.HxC
DocProject/Help/*.hhc
DocProject/Help/*.hhk
DocProject/Help/*.hhp
DocProject/Help/Html2
DocProject/Help/html
# Click-Once directory
publish/
# Publish Web Output
*.[Pp]ublish.xml
*.azurePubxml
# Note: Comment the next line if you want to checkin your web deploy settings,
# but database connection strings (with potential passwords) will be unencrypted
*.pubxml
*.publishproj
# Microsoft Azure Web App publish settings. Comment the next line if you want to
# checkin your Azure Web App publish settings, but sensitive information contained
# in these scripts will be unencrypted
PublishScripts/
# NuGet Packages
*.nupkg
# NuGet Symbol Packages
*.snupkg
# The packages folder can be ignored because of Package Restore
**/[Pp]ackages/*
# except build/, which is used as an MSBuild target.
!**/[Pp]ackages/build/
# Uncomment if necessary however generally it will be regenerated when needed
#!**/[Pp]ackages/repositories.config
# NuGet v3's project.json files produces more ignorable files
*.nuget.props
*.nuget.targets
# Microsoft Azure Build Output
csx/
*.build.csdef
# Microsoft Azure Emulator
ecf/
rcf/
# Windows Store app package directories and files
AppPackages/
BundleArtifacts/
Package.StoreAssociation.xml
_pkginfo.txt
*.appx
*.appxbundle
*.appxupload
# Visual Studio cache files
# files ending in .cache can be ignored
*.[Cc]ache
# but keep track of directories ending in .cache
!?*.[Cc]ache/
# Others
ClientBin/
~$*
*~
*.dbmdl
*.dbproj.schemaview
*.jfm
*.pfx
*.publishsettings
orleans.codegen.cs
# Including strong name files can present a security risk
# (https://github.com/github/gitignore/pull/2483#issue-259490424)
#*.snk
# Since there are multiple workflows, uncomment next line to ignore bower_components
# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622)
#bower_components/
# RIA/Silverlight projects
Generated_Code/
# Backup & report files from converting an old project file
# to a newer Visual Studio version. Backup files are not needed,
# because we have git ;-)
_UpgradeReport_Files/
Backup*/
UpgradeLog*.XML
UpgradeLog*.htm
ServiceFabricBackup/
*.rptproj.bak
# SQL Server files
*.mdf
*.ldf
*.ndf
# Business Intelligence projects
*.rdl.data
*.bim.layout
*.bim_*.settings
*.rptproj.rsuser
*- [Bb]ackup.rdl
*- [Bb]ackup ([0-9]).rdl
*- [Bb]ackup ([0-9][0-9]).rdl
# Microsoft Fakes
FakesAssemblies/
# GhostDoc plugin setting file
*.GhostDoc.xml
# Node.js Tools for Visual Studio
.ntvs_analysis.dat
node_modules/
# Visual Studio 6 build log
*.plg
# Visual Studio 6 workspace options file
*.opt
# Visual Studio 6 auto-generated workspace file (contains which files were open etc.)
*.vbw
# Visual Studio 6 auto-generated project file (contains which files were open etc.)
*.vbp
# Visual Studio 6 workspace and project file (working project files containing files to include in project)
*.dsw
*.dsp
# Visual Studio 6 technical files
*.ncb
*.aps
# Visual Studio LightSwitch build output
**/*.HTMLClient/GeneratedArtifacts
**/*.DesktopClient/GeneratedArtifacts
**/*.DesktopClient/ModelManifest.xml
**/*.Server/GeneratedArtifacts
**/*.Server/ModelManifest.xml
_Pvt_Extensions
# Paket dependency manager
.paket/paket.exe
paket-files/
# FAKE - F# Make
.fake/
# CodeRush personal settings
.cr/personal
# Python Tools for Visual Studio (PTVS)
__pycache__/
*.pyc
# Cake - Uncomment if you are using it
# tools/**
# !tools/packages.config
# Tabs Studio
*.tss
# Telerik's JustMock configuration file
*.jmconfig
# BizTalk build output
*.btp.cs
*.btm.cs
*.odx.cs
*.xsd.cs
# OpenCover UI analysis results
OpenCover/
# Azure Stream Analytics local run output
ASALocalRun/
# MSBuild Binary and Structured Log
*.binlog
# NVidia Nsight GPU debugger configuration file
*.nvuser
# MFractors (Xamarin productivity tool) working folder
.mfractor/
# Local History for Visual Studio
.localhistory/
# Visual Studio History (VSHistory) files
.vshistory/
# BeatPulse healthcheck temp database
healthchecksdb
# Backup folder for Package Reference Convert tool in Visual Studio 2017
MigrationBackup/
# Ionide (cross platform F# VS Code tools) working folder
.ionide/
# Fody - auto-generated XML schema
FodyWeavers.xsd
# VS Code files for those working on multiple tools
.vscode/*
!.vscode/settings.json
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json
*.code-workspace
# Local History for Visual Studio Code
.history/
# Windows Installer files from build outputs
*.cab
*.msi
*.msix
*.msm
*.msp
# JetBrains Rider
*.sln.iml
#pragma once
#include "IComponent.h"
namespace GECS {
template<class T>
class Component : public IComponent {
public:
static const type_id COMPONENT_TYPE_ID;
// Component manager responsible for deleting
void operator delete(void*) = delete;
void operator delete[](void*) = delete;
Component() {}
virtual ~Component() {}
inline type_id GetComponentTypeId() const
{
return COMPONENT_TYPE_ID;
}
};
template<class T>
const type_id Component<T>::COMPONENT_TYPE_ID = Identifier::TypeIDCounter<IComponent>::GetTypeId<T>();
}
\ No newline at end of file
#pragma once
#pragma warning(disable: 4251)
#include "Facade.h"
#include "Handle/Handle.h"
#include "Utilities/TypeIDCounter.h"
#include "Containers/ComponentContainer.h"
namespace GECS{
class GECS_API ComponentManager {
private:
std::unordered_map<type_id, IComponentContainer*> m_componentTypeContainers;
std::vector<IComponent*> m_componentTableById;
// Contains components' id.
// Access by the index of the entity descriptor (Handle)
// and the component type ID.
std::vector<std::vector<object_id>> m_entityComponentsIdByTypes;
object_id GetNewId(IComponent* component);
void ReleaseId(object_id id);
void AttachComponentToEntity(Handle entityHandle, object_id componentId, type_id componentTypeId);
void DetachComponentToEntity(Handle entityHandle, object_id componentId, type_id componentTypeId);
public:
ComponentManager();
~ComponentManager();
template<class T, class... Arguments>
T* AddComponent(const Handle entityHandle, Arguments&&... args) {
uptr address = GetComponentContainer<T>(m_componentTypeContainers)->CreateObject();
const object_id componentId = this->GetNewId((T*)address);
// creating an object at a dedicated address
IComponent* component = new (reinterpret_cast<void*>(address)) T (std::forward<Arguments>(args)...);
component->m_componentID = componentId;
component->m_entityOwner = entityHandle;
AttachComponentToEntity(entityHandle, componentId, T::COMPONENT_TYPE_ID);
L_(ldebug) << "Added a new component " << typeid(T).name() << " for the entity " << entityHandle.index;
return static_cast<T*>(component);
}
template<class T>
void ReleaseComponent(const Handle entityHandle) {
const object_id componentId = this->m_entityComponentsIdByTypes[entityHandle.index][T::COMPONENT_TYPE_ID];
IComponent* component = this->m_componentTableById[componentId];
GetComponentContainer<T>(m_componentTypeContainers)->ReleaseComponent(component);
DetachComponentToEntity(entityHandle, componentId, T::COMPONENT_TYPE_ID);
L_(ldebug) << "Released a component " << typeid(T).name() << " for the entity " << entityHandle.index;
}
template<class T>
T* GetComponent(const Handle entityHandle) {
const object_id componentId = this->m_entityComponentsIdByTypes[entityHandle.index][T::COMPONENT_TYPE_ID];
if (componentId == INVALID_OBJECT_ID) {
return nullptr;
}
return static_cast<T*>(this->m_componentTableById[componentId]);
}
template<class T>
inline typename ComponentContainer<T>::iterator begin() {
return GetComponentContainer<T>(m_componentTypeContainers)->begin();
}
template<class T>
inline typename ComponentContainer<T>::iterator end() {
return GetComponentContainer<T>(m_componentTypeContainers)->end();
}
void ReleaseAllComponents(const Handle entityHandle);
};
}
\ No newline at end of file
#pragma once
#include "Facade.h"
#include "Memory/ChunkAllocator.h"
#include "IComponent.h"
namespace GECS {
class ChunkAllocator;
class IComponentContainer {
public:
virtual ~IComponentContainer()
{}
virtual void ReleaseComponent(IComponent* component) = 0;
};
template<class T>
class ComponentContainer : public Memory::ChunkAllocator<T, COMPONENT_CONTAINER_CHUNK_MAX_OBJECTS>, public IComponentContainer {
public:
ComponentContainer() : Memory::ChunkAllocator<T, COMPONENT_CONTAINER_CHUNK_MAX_OBJECTS>()
{}
virtual ~ComponentContainer()
{}
virtual void ReleaseComponent(IComponent* component) override {
component->~IComponent();
this->ReleaseObject(reinterpret_cast<uptr>(component));
}
};
template<class T>
inline ComponentContainer<T>* GetComponentContainer(std::unordered_map<type_id, IComponentContainer*>& componentTypeContainers) {
type_id componentTypeID = T::COMPONENT_TYPE_ID;
auto container = componentTypeContainers.find(componentTypeID);
ComponentContainer<T>* newContainer = nullptr;
if (container == componentTypeContainers.end()) {
newContainer = new ComponentContainer<T>();
componentTypeContainers[componentTypeID] = newContainer;
L_(ldebug) << "Created a new component container with type " << typeid(T).name();
}
else
newContainer = static_cast<ComponentContainer<T>*>(container->second);
assert(newContainer != nullptr && "Component container: failed to create new type container!");
return newContainer;
}
}
\ No newline at end of file
#pragma once
#include "IEntity.h"
#include "Memory/ChunkAllocator.h"
#include "Facade.h"
namespace GECS {
class ChunkAllocator;
class IEntityContainer {
public:
virtual ~IEntityContainer()
{}
virtual void ReleaseEntity(IEntity* entity) = 0;
};
template<class T>
class EntityContainer : public Memory::ChunkAllocator<T, ENTITY_CONTAINER_CHUNK_MAX_OBJECTS>, public IEntityContainer {
public:
EntityContainer() : Memory::ChunkAllocator<T, ENTITY_CONTAINER_CHUNK_MAX_OBJECTS>()
{}
virtual ~EntityContainer()
{}
virtual void ReleaseEntity(IEntity* entity) override {
entity->~IEntity();
this->ReleaseObject(reinterpret_cast<uptr>(entity));
}
};
template<class T>
inline EntityContainer<T>* GetEntityContainer(std::unordered_map<type_id, IEntityContainer*>& entityTypeContainers) {
type_id entityTypeID = T::ENTITY_TYPE_ID;
auto container = entityTypeContainers.find(entityTypeID);
EntityContainer<T>* newContainer = nullptr;
if (container == entityTypeContainers.end()) {
newContainer = new EntityContainer<T>();
entityTypeContainers[entityTypeID] = newContainer;
L_(ldebug) << "Created a new entity container with type " << typeid(T).name();
}
else
newContainer = static_cast<EntityContainer<T>*>(container->second);
assert(newContainer != nullptr && "Entity container: failed to create new type container!");
return newContainer;
}
}
\ No newline at end of file
#pragma once
#include "Event/IEvent.h"
#include "Delegate/IClassMethod.h"
namespace GECS {
template<class Class, class Method>
class ClassMethod : public IClassMethod {};
// specialization - without arguments
template<class Class>
class ClassMethod<Class, void(Class::*)(void)> : public IClassMethod {
typedef void(Class::* Method)(void);
Class* m_class;
Method m_method;
public:
ClassMethod(Class* c, Method method) :
m_class(c),
m_method(method)
{}
virtual inline object_id GetClassHash() const override
{
static const object_id classHash{ typeid(Class).hash_code() };
return classHash;
}
virtual inline object_id GetMethodHash() const override
{
static const object_id methodHash{ typeid(Method).hash_code() };
return methodHash;
}
virtual inline void Call() override {
(m_class->*m_method)();
}
};
// specialization - with IEvent argument
template<class Class>
class ClassMethod<Class, void(Class::*)(const Event::IEvent* const)> : public IClassMethod {
typedef void(Class::* Method)(const Event::IEvent* const);
Class* m_class;
Method m_method;
public:
ClassMethod(Class* c, Method method) :
m_class(c),
m_method(method)
{}
virtual inline void Call() override { } // yes, today without solId
virtual inline void Call(const Event::IEvent* const e) override {
(m_class->*m_method)(e);
}
virtual bool operator==(const IClassMethod* other) const override {
ClassMethod* cm = (ClassMethod*)other;
return (this->m_class == cm->m_class) && (this->m_method == cm->m_method);
}
};
}
\ No newline at end of file
#pragma once
#include "Event/IEvent.h"
namespace GECS {
class GECS_API IClassMethod {
public:
IClassMethod();
virtual ~IClassMethod();
virtual inline void Call() = 0;
virtual inline void Call(const Event::IEvent* const e) = 0;
virtual bool operator==(const IClassMethod* other) const = 0;
};
}
\ No newline at end of file
#pragma once
#include "IEntity.h"
#include "Utilities/TypeIDCounter.h"
namespace GECS {
template <class T>
class Entity : public IEntity {
public:
static const type_id ENTITY_TYPE_ID;
// Entity manager responsible for deleting
void operator delete(void*) = delete;
void operator delete[](void*) = delete;
Entity() {}
virtual ~Entity() {}
virtual inline const type_id GetEntityTypeId() const override {
return ENTITY_TYPE_ID;
}
};
template <class T>
const type_id Entity<T>::ENTITY_TYPE_ID = Identifier::TypeIDCounter<IEntity>::GetTypeId<T>();
}
\ No newline at end of file
#pragma once
#pragma warning(disable: 4251)
#include "Facade.h"
#include "Containers/EntityContainer.h"
#include "Handle/HandleManager.h"
namespace GECS {
class GECS_API EntityManager {
private:
std::unordered_map<type_id, IEntityContainer*> m_entityTypeContainers;
Identifier::HandleManager<IEntity, Handle> m_entityHandleTable;
std::vector<Handle> m_releasedEntities;
size_t m_numReleasedEntities;
// ComponentManager singleton for entities
ComponentManager* m_componentManagerSingleton;
Handle GetNewHandle(IEntity* entity);
void ReleaseHandle(Handle handle);
public:
EntityManager(ComponentManager* componentManagerSingleton);
~EntityManager();
// using a variadic template to pass arguments to an entity
template<class T, class... Arguments>
Handle CreateEntity(Arguments&&... args) {
uptr address = GetEntityContainer<T>(m_entityTypeContainers)->CreateObject();
const Handle entityHandle = this->GetNewHandle((T*)address);
// IMPORTANT TO FILL FIELDS BEFORE CREATING AN OBJECT
// because components is created in entity constructor and
// it needs an entity handle
((T*)address)->m_handle = entityHandle;
((T*)address)->m_componentManagerSingleton = m_componentManagerSingleton;
// creating an object at a dedicated address
IEntity* entity = new (reinterpret_cast<void*>(address)) T (std::forward<Arguments>(args)...);
L_(ldebug) << "Created a new entity with index " << entityHandle.index;
return entityHandle;
}
inline IEntity* GetEntity(Handle handle) {
return this->m_entityHandleTable[handle];
}
inline Handle GetEntityHandle(Handle::value_type index) const {
return this->m_entityHandleTable[index];
}
template<class T>
inline typename EntityContainer<T>::iterator begin() {
return GetEntityContainer<T>(m_entityTypeContainers)->begin();
}
template<class T>
inline typename EntityContainer<T>::iterator end() {
return GetEntityContainer<T>(m_entityTypeContainers)->end();
}
void ReleaseEntity(Handle handle);
void DestroyReleasedEntities();
};
}
\ No newline at end of file
#pragma once
#include "IEvent.h"
#include "Utilities/TypeIDCounter.h"
namespace GECS {
namespace Event {
template<class T>
class Event : public IEvent {
public:
static const type_id EVENT_TYPE_ID;
Event() {}
virtual ~Event() {}
virtual inline const type_id GetEventTypeId() const override {
return EVENT_TYPE_ID;
}
};
template <class T>
const type_id Event<T>::EVENT_TYPE_ID = Identifier::TypeIDCounter<IEvent>::GetTypeId<T>();
}
}
\ No newline at end of file
#pragma once
#include "Facade.h"
#include "IEventCollection.h"
namespace GECS {
namespace Event {
template<class T>
class EventCollection : public IEventCollection {
std::list<IClassMethod*> m_eventMethodsList;
public:
EventCollection()
{}
virtual ~EventCollection()
{
this->m_eventMethodsList.clear();
}
void Call(const IEvent* event) override {
for (IClassMethod* method : this->m_eventMethodsList) {
method->Call(event);
}
}
virtual void AddMethod(IClassMethod* method) {
for (IClassMethod* eventMethod : this->m_eventMethodsList)
if (eventMethod == method)
return;
this->m_eventMethodsList.push_back(method);
}
virtual void RemoveMethod(IClassMethod* method) {
for (IClassMethod* eventMethod : this->m_eventMethodsList) {
if (method->operator==(eventMethod)) {
this->m_eventMethodsList.remove(eventMethod);
delete eventMethod;
eventMethod = nullptr;
return;
}
}
}
};
}
}
\ No newline at end of file
#pragma once
#pragma warning(disable: 4251)
#include "Facade.h"
#include "Delegate/ClassMethod.h"
#include "Event/EventCollection.h"
#include "Memory/LinearAllocator.h"
namespace GECS {
namespace Event {
class GECS_API EventQueue {
Memory::LinearAllocator* m_eventAllocator;
std::unordered_map<type_id, IEventCollection*> m_eventsById;
std::vector<IEvent*> m_eventsQueue;
inline void ClearEventBuffer() {
this->m_eventAllocator->Clear();
this->m_eventsQueue.clear();
}
public:
EventQueue();
~EventQueue();
template<class Event, class Class>
inline void AddEventHandler(Class* c, void(Class::* Method)(const IEvent* const)) {
IClassMethod* classMethod = new ClassMethod<Class, void(Class::*)(const IEvent* const)>(c, Method);
type_id eventTypeId = Event::EVENT_TYPE_ID;
auto eventCollection = this->m_eventsById.find(eventTypeId);
if (eventCollection == this->m_eventsById.end()) {
EventCollection<Event>* newEventCollection = new EventCollection<Event>();
newEventCollection->AddMethod(classMethod);
std::pair<type_id, IEventCollection*> eventTypeCollectionPair;
eventTypeCollectionPair.first = eventTypeId;
eventTypeCollectionPair.second = newEventCollection;
this->m_eventsById.insert(eventTypeCollectionPair);
L_(ldebug) << "Created a new event collection with " << typeid(Event).name();
}
else {
this->m_eventsById[eventTypeId]->AddMethod(classMethod);
}
}
template<class Event, class Class>
inline void RemoveEventHandler(Class* c, void(Class::* Method)(const IEvent* const)) {
ClassMethod<Class, void(Class::*)(const IEvent* const)> classMethod(c, Method);
type_id eventTypeId = Event::EVENT_TYPE_ID;
auto eventCollection = this->m_eventsById.find(eventTypeId);
if (eventCollection != this->m_eventsById.end())
this->m_eventsById[eventTypeId]->RemoveMethod(&classMethod);
}
template<class Event, class... Arguments>
void Send(Arguments&&... args) {
uptr address = m_eventAllocator->Allocate(sizeof(Event), alignof(Event));
assert(address != 0 && "EventHandler: address not allocated");
L_(ldebug) << typeid(Event).name() << " has been sent";
this->m_eventsQueue.push_back(new (reinterpret_cast<void*>(address))Event(std::forward<Arguments>(args)...));
}
void ProcessEvents();
};
}
}
\ No newline at end of file
#pragma once
#include "Facade.h"
namespace GECS {
namespace Event {
class GECS_API IEvent {
public:
IEvent();
virtual ~IEvent();
virtual inline const type_id GetEventTypeId() const = 0;
};
}
}
\ No newline at end of file
#pragma once
#include "Delegate/IClassMethod.h"
namespace GECS {
namespace Event {
class GECS_API IEventCollection {
public:
IEventCollection();
virtual ~IEventCollection();
virtual void Call(const IEvent* event) = 0;
virtual void AddMethod(IClassMethod* method) = 0;
virtual void RemoveMethod(IClassMethod* method) = 0;
};
}
}
\ No newline at end of file
#pragma once
#include "Logger/LiteLogger.h"
#include "Platform.h"
// Setting global memory size
#define GECS_GLOBAL_MEMORY_CAPACITY 134217728 // 128 MB
// Setting system manager memory size
#define GECS_SYSTEM_MANAGER_MEMORY_CAPACITY 8388608 // 8 MB
// Setting event buffer memory size
#define GECS_EVENT_BUFFER_MEMORY_SIZE 4194304 // 4 MB
// Chunks settings
#define ENTITY_CONTAINER_CHUNK_MAX_OBJECTS 512
#define COMPONENT_CONTAINER_CHUNK_MAX_OBJECTS 512
// Managers tables settings
#define ENTITY_COMPONENT_TABLE_GROW_SIZE 1024
#define COMPONENT_TABLE_GROW_SIZE 1024
// Handle settings
#define HANDLE_MANAGER_GROW_SIZE 1024
namespace GECS {
class EntityManager;
class ComponentManager;
class SystemManager;
namespace Event {
class EventQueue;
}
namespace Util {
class EngineTimer;
}
namespace Memory {
class GlobalMemoryManager;
GECS_API extern GlobalMemoryManager* g_globalMemManager; // global manager
}
class GECSMain;
GECS_API extern GECSMain* GECSInstance;
GECS_API void Init();
GECS_API void Destroy();
}
\ No newline at end of file
#pragma once
#include "Facade.h"
#include "GECSMain.h"
#include "Entity.h"
#include "Component.h"
#include "System.h"
#include "EntityManager.h"
#include "ComponentManager.h"
#include "SystemManager.h"
#include "Event/EventQueue.h"
#include "Event/Event.h"
\ No newline at end of file
#pragma once
#include "Facade.h"
namespace GECS {
class GECS_API GECSMain {
EntityManager* EM;
ComponentManager* CM;
SystemManager* SM;
Event::EventQueue* EQ;
Util::EngineTimer* ET;
public:
GECSMain();
~GECSMain();
inline EntityManager* GetEntityManager() { return EM; }
inline ComponentManager* GetComponentManager() { return CM; }
inline SystemManager* GetSystemManager() { return SM; }
inline Event::EventQueue* GetEventQueue() { return EQ; }
void Update(f32 delta);
};
}
\ No newline at end of file
#pragma once
#include "Facade.h"
namespace GECS {
namespace Identifier {
/// <summary>
/// Struct: Handle
///
/// <para> Created for safe objects identification. </para>
/// <para> Contains params:</para>
/// <para>- Index: used to store the index of an object in collections. </para>
/// <para>- Version: It is used to prevent the appearance of dangling pointers. </para>
/// </summary>
/// <typeparam name="handle_type">Type of internal parameters</typeparam>
/// <typeparam name="version_bits">Amount of bits used for indexes</typeparam>
/// <typeparam name="index_bits">Amount of bits used for versions</typeparam>
template<typename handle_value_type, size_t index_bits, size_t version_bits>
struct UniversalHandle {
static_assert(sizeof(handle_value_type) * CHAR_BIT >= (version_bits + index_bits), "Handle: value type is too small!");
using value_type = handle_value_type;
static constexpr value_type MIN_VERSION{ 0 };
static constexpr value_type MAX_VERSION{ (1ULL << version_bits) - 2U };
static constexpr value_type MAX_INDICES{ (1ULL << index_bits) - 2U };
static constexpr value_type INVALID_HANDLE{ 0 };
public:
value_type index : index_bits;
value_type version : version_bits;
UniversalHandle()
{}
UniversalHandle(value_type indexVersionChecksum) :
index(indexVersionChecksum),
version(indexVersionChecksum)
{}
UniversalHandle(value_type index, value_type version) :
index(index),
version(version)
{}
inline operator value_type() const { return index; }
};
}
//---------------------------------------------------------------
// Installing a descriptors for systems with different bit rates.
//
// 64 bit:
// - Value type: unsigned 64 bit int, max value: 18,446,744,073,709,551,616
// - Max posible indices: 1,099,511,627,776 (40 bits)
// - Max posible versions: 16,777,216 (24 bits)
// - 1,099,511,627,776 * 16,777,216 = 18,446,744,073,709,551,616
//
// 32 bit:
// - Value type: unsigned 32 bit int, max value: 4,294,967,296
// - Max posible indices: 1,048,576 (20 bits)
// - Max posible versions: 4,096 (12 bits)
// - 1,048,576 * 4,096 = 4,294,967,296
//---------------------------------------------------------------
#ifdef GECS_64
using Handle = Identifier::UniversalHandle<u64, 40, 24>;
#else
using Handle = Identifier::UniversalHandle<u32, 20, 12>;
#endif
}
\ No newline at end of file
#pragma once
#include "Facade.h"
#include "Handle.h"
namespace GECS {
namespace Identifier {
template<class T, class handle_type>
class HandleManager {
private:
/// <summary>
/// <para> LookUp table </para>
/// <para> Contains pairs of handles and object pointers </para>
/// </summary>
std::vector<std::pair<typename handle_type::value_type, T*>> m_table;
size_t m_growSize;
void GrowTable() {
size_t oldSize = this->m_table.size();
assert(oldSize < handle_type::MAX_INDICES &&
"Handle manager: Max table capacity reached!");
size_t newSize = std::min(oldSize + m_growSize, handle_type::MAX_INDICES);
this->m_table.resize(newSize);
typename handle_type::value_type i = oldSize;
for (; i < newSize; ++i)
this->m_table[i] = std::pair<typename handle_type::value_type, T*>();
}
public:
HandleManager() : m_growSize(HANDLE_MANAGER_GROW_SIZE) {
this->GrowTable();
}
handle_type GetHandle(T* p_object) {
typename handle_type::value_type i = 0;
for (; i < this->m_table.size(); ++i)
{
if (this->m_table[i].second == nullptr)
{
this->m_table[i].second = p_object;
this->m_table[i].first =
this->m_table[i].first + 1 > handle_type::MAX_VERSION
? handle_type::MIN_VERSION
: this->m_table[i].first + 1;
return handle_type(i, this->m_table[i].first);
}
}
GrowTable();
this->m_table[i].first = 1;
this->m_table[i].second = p_object;
return handle_type(i, this->m_table[i].first);
}
void ReleaseHandle(handle_type handle) {
assert((handle.index < this->m_table.size() &&
handle.version == this->m_table[handle.index].first) &&
"Handle manager: Releasing error. Invalid handle!");
this->m_table[handle.index].second = nullptr;
}
inline handle_type operator[](typename handle_type::value_type index) const {
assert(index < this->m_table.size() &&
"Handle manager: Index out of range!");
return handle_type(index, this->m_table[index].first);
}
inline T* operator[](handle_type handle) {
assert((handle.index < this->m_table.size() &&
handle.version == this->m_table[handle.index].first) &&
"Handle manager: Invalid handle!");
return this->m_table[handle.index].second;
}
};
}
}
\ No newline at end of file
#pragma once
#pragma warning(disable: 4251)
#include "Facade.h"
#include "Handle/Handle.h"
namespace GECS {
static const object_id INVALID_COMPONENT_ID = INVALID_OBJECT_ID;
class GECS_API IComponent {
friend class ComponentManager;
protected:
object_id m_componentID;
Handle m_entityOwner;
public:
IComponent();
virtual ~IComponent();
inline const object_id GetComponentID() const {
return this->m_componentID;
}
inline const Handle GetEntityOwner() const {
return this->m_entityOwner;
}
};
}
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment