redxdev / ecs Goto Github PK
View Code? Open in Web Editor NEWC++ single-header entity component system library
License: MIT License
C++ single-header entity component system library
License: MIT License
Please, split source code to .hpp and .cpp OR make methods inline because there are linker errors when file is included more than once. Thank you.
Awesome library. Works perfectly. I just have a question about general use. Should there be 1 global world or one in every scene? I have written a scene manager and i cant find an answer anywhere regarding this. I am leaning towards one for every scene..... but id love to hear how you use it. Thanks.
Sorry i know this is the wrong place to ask questions but i dont understand github.
This header file compiles and works perfectly:
#pragma once
#include "ECS.h"
struct TestComp {
int x;
int y;
};
class TestClass {
public:
TestClass() {}
virtual ~TestClass() = default;
void update(ECS::World* world, float dt) {
using namespace ECS;
world->each<TestComp>([&](Entity* ent, ComponentHandle<TestComp> testComp) {
testComp->x += 1;
});
}
};
however, as soon as an implementation file is present, for example TestClass.cpp
, even if it just contains
#include "TestClass.h"
Visual Studio shows an internal compiler error (C1001) at the last line of the implementation file. This error remains whatever i do, using inline
, moving the implementation to the .cpp file and so on.
Im running the latest Visual Studio enterprise 2017, v. 15.5.7
I'm using your library to write a simple game. Your library is wonderful and it helps me a lot. But I hope that you could add APIs to support to create singleton components (came from GDC2017 'Overwatch Gameplay Architecture and Netcode', I'm sorry that I didn't find the video), which is like global variables that directly belong to the world instead of entities. I think they are helpful when you need components with camera position, window width and height, time, etc, that need to share between systems but does not logically belong to any entity.
I add some codes to complement a simple version, using a singleton entity to store the singleton components, but it's not gentle at all:
class World
{
public:
Entity* singletons;
template<typename T, typename... Args>
void createSingletonComponent(Args&&... args) {
this->singletons->assign<T>(args...);
}
template<typename T>
ComponentHandle<T> getSingletonComponent() {
return this->singletons->get<T>();
}
};
I hope you could write these APIs in your way.
I tried to compile this on ubuntu with g++-4.8.4
Compiled with:
g++ -std=c++11 sample.cpp
I get the following errors:
errors.txt
I'd like to disable certain systems from running based on certain game events. To support would require being able to get a system from the world and call a method or set a field to disable it. Systems that are disabled would not have their tick methods called until reenabled.
Hi!
First of all , you have done a great job developing this library.
Has any plan to addd Multi thread support to this library?
Regards!
I try to build ECS with my other Project (didn't work), so I fork ESC and add my typical cmake-file and compiler-options (try out C++14 and C++17): https://github.com/abeimler/ECS
OS: Arch Linux x86_64 (4.16.81-1-MANJARO)
Compiler: c++ (GCC) 9.2.0
CMake: 3.15.5
Build:
mkdir build
cmake . -Bbuild -DCMAKE_BUILD_TYPE=Release -DCMAKE_EXPORT_COMPILE_COMMANDS=ON -DECS_SAMPLE_BUILD:BOOL="1"
cmake --build build
Error:
[ 50%] Building CXX object CMakeFiles/sample.dir/sample.cpp.o
/usr/bin/../lib64/gcc/x86_64-pc-linux-gnu/9.2.0/../../../../include/c++/9.2.0/ext/new_allocator.h:146:8: error: allocation of incomplete type 'ECS::Entity' [clang-diagnostic-error]
_Up(std::forward<_Args>(__args)...)))
^
/usr/bin/../lib64/gcc/x86_64-pc-linux-gnu/9.2.0/../../../../include/c++/9.2.0/bits/alloc_traits.h:483:24: note: in instantiation of exception specification for
'construct<ECS::Entity, ECS::World *, unsigned long &>' requested here
noexcept(noexcept(__a.construct(__p, std::forward<_Args>(__args)...)))
^
ECS.h:454:4: note: in instantiation of exception specification for 'construct<ECS::Entity, ECS::World *, unsigned long &>
' requested here
std::allocator_traits<EntityAllocator>::construct(entAlloc, ent, this, lastEntityId);
^
ECS.h:131:8: note: forward declaration of 'ECS::Entity'
class Entity;
^
1 error generated.
Error while processing sample.cpp.
Found compiler errors, but -fix-errors was not specified.
Fixes have NOT been applied.
Found compiler error(s).
make[3]: *** [CMakeFiles/sample.dir/build.make:63: CMakeFiles/sample.dir/sample.cpp.o] Error 1
make[2]: *** [CMakeFiles/Makefile2:105: CMakeFiles/sample.dir/all] Error 2
make[1]: *** [CMakeFiles/Makefile2:117: CMakeFiles/sample.dir/rule] Error 2
make: *** [Makefile:131: sample] Error 2
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.