Add basic project with gravity system test
This commit is contained in:
parent
83e1cec88b
commit
8032f2efec
2
.idea/ecsgame.iml
generated
Normal file
2
.idea/ecsgame.iml
generated
Normal file
@ -0,0 +1,2 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module classpath="CMake" type="CPP_MODULE" version="4" />
|
7
.idea/misc.xml
generated
Normal file
7
.idea/misc.xml
generated
Normal file
@ -0,0 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="CMakeWorkspace" PROJECT_DIR="$PROJECT_DIR$" />
|
||||
<component name="JavaScriptSettings">
|
||||
<option name="languageLevel" value="ES6" />
|
||||
</component>
|
||||
</project>
|
8
.idea/modules.xml
generated
Normal file
8
.idea/modules.xml
generated
Normal file
@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectModuleManager">
|
||||
<modules>
|
||||
<module fileurl="file://$PROJECT_DIR$/.idea/ecsgame.iml" filepath="$PROJECT_DIR$/.idea/ecsgame.iml" />
|
||||
</modules>
|
||||
</component>
|
||||
</project>
|
6
.idea/vcs.xml
generated
Normal file
6
.idea/vcs.xml
generated
Normal file
@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="VcsDirectoryMappings">
|
||||
<mapping directory="$PROJECT_DIR$" vcs="Git" />
|
||||
</component>
|
||||
</project>
|
6
CMakeLists.txt
Normal file
6
CMakeLists.txt
Normal file
@ -0,0 +1,6 @@
|
||||
cmake_minimum_required(VERSION 3.15)
|
||||
project(ecsgame)
|
||||
|
||||
set(CMAKE_CXX_STANDARD 17)
|
||||
|
||||
add_executable(ecsgame main.cpp)
|
50
main.cpp
Normal file
50
main.cpp
Normal file
@ -0,0 +1,50 @@
|
||||
#include <iostream>
|
||||
#include "ECS.h"
|
||||
|
||||
using namespace ECS;
|
||||
|
||||
struct Position
|
||||
{
|
||||
Position(float x, float y, float z) : x(x), y(y), z(z) {}
|
||||
Position() : x(0.f), y(0.f), z(0.f) {}
|
||||
|
||||
float x;
|
||||
float y;
|
||||
float z;
|
||||
};
|
||||
|
||||
class GravitySystem : public EntitySystem
|
||||
{
|
||||
public:
|
||||
GravitySystem(float amount)
|
||||
{
|
||||
gravityAmount = amount;
|
||||
}
|
||||
|
||||
virtual ~GravitySystem() {}
|
||||
|
||||
virtual void tick(World* world, float deltaTime) override
|
||||
{
|
||||
world->each<Position>([&](Entity* ent, ComponentHandle<Position> position) {
|
||||
position->y += gravityAmount * deltaTime;
|
||||
});
|
||||
}
|
||||
|
||||
private:
|
||||
float gravityAmount;
|
||||
};
|
||||
|
||||
int main() {
|
||||
World* world = World::createWorld();
|
||||
world->registerSystem(new GravitySystem(-9.8f));
|
||||
|
||||
Entity* ent = world->create();
|
||||
ent->assign<Position>(0.f, 0.f, 0.f); // assign() takes arguments and passes them to the constructor
|
||||
|
||||
world->tick(1.0f);
|
||||
|
||||
ComponentHandle<Position> pos = ent->get<Position>();
|
||||
|
||||
std::cout << "y position after tick: " << pos->y << std::endl;
|
||||
return 0;
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user