-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
27 changed files
with
80 additions
and
98 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
#include <iostream> | ||
#include "ecs.h" | ||
|
||
// We need to define the static variables here | ||
std::multiset<std::unique_ptr<Entity>> ECS::entities; | ||
std::set<std::unique_ptr<System>> ECS::systems; | ||
|
||
/** | ||
* @brief Gets the entities | ||
*/ | ||
std::multiset<std::unique_ptr<Entity>>& ECS::GetEntities() { | ||
return entities; | ||
} | ||
|
||
/** | ||
* @brief Runs the every frame | ||
* @details It loops over all the systems and calls their UpdateEntity function | ||
*/ | ||
void ECS::Update() { | ||
for (auto& system : systems) { | ||
system->Update(); | ||
} | ||
|
||
// Loop over all the entities | ||
for(auto entity = entities.begin(); entity != entities.end(); entity++) { | ||
// Check if the entity got destroyed | ||
// If it did, remove it from the set | ||
// and move the iterator back one step | ||
if ((*entity)->gotDestroyed()) | ||
entity = std::prev(entities.erase(entity)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,37 @@ | ||
#include "engine/ecs.h" | ||
#include "ecs.h" | ||
#include "systems/input.h" | ||
|
||
#include <chrono> | ||
#include <thread> | ||
|
||
// ECS | ||
// ECS::entities | ||
// Components | ||
// What systems need to be run | ||
// ECS::systems | ||
// A function on how to manipulate the entities components | ||
// Gets looped over all entities, that use the system | ||
|
||
/** | ||
* @brief The main game loop | ||
*/ | ||
void GameLoop() { | ||
const auto timeStep = std::chrono::milliseconds(1000 / 60); | ||
do { | ||
// Start the timer | ||
auto start = std::chrono::high_resolution_clock::now(); | ||
|
||
// Update the entities | ||
ECS::Update(); | ||
|
||
// Sleep for the remaining time | ||
std::this_thread::sleep_until(start + timeStep); | ||
} while(!Input::GetKeyPressed(Key::QUIT)); | ||
} | ||
|
||
int main() { | ||
ECS::GameLoop(); | ||
// Game Loop | ||
GameLoop(); | ||
|
||
return 0; | ||
} |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.