51 lines
1.3 KiB
C++
51 lines
1.3 KiB
C++
#pragma once
|
|
|
|
#include "Components.hpp"
|
|
#include "Entity.hpp"
|
|
#include <memory>
|
|
#include <vector>
|
|
|
|
void UpdateAllSystems(std::vector<std::shared_ptr<Entity>> &entities, float deltaTime) {
|
|
std::shared_ptr<Entity> worldEntity;
|
|
std::shared_ptr<Entity> wellEntity;
|
|
float scrollX = 0.0f;
|
|
|
|
if (!entities.empty()) {
|
|
worldEntity = entities[0];
|
|
}
|
|
if (entities.size() > 1) {
|
|
wellEntity = entities[1];
|
|
}
|
|
|
|
if (worldEntity) {
|
|
worldEntity->Update(deltaTime);
|
|
auto scroll = worldEntity->GetComponent<ScrollComponent>();
|
|
if (scroll) {
|
|
scrollX = scroll->get().scrollX;
|
|
}
|
|
}
|
|
|
|
if (wellEntity) {
|
|
wellEntity->Update(deltaTime);
|
|
}
|
|
|
|
for (auto &entity : entities) {
|
|
if (entity == worldEntity || entity == wellEntity || !entity) {
|
|
continue;
|
|
}
|
|
|
|
auto receiver = entity->GetComponent<GravityReceiverComponent>();
|
|
if (receiver) {
|
|
receiver->get().well = wellEntity.get();
|
|
}
|
|
|
|
auto transform = entity->GetComponent<TransformComponent>();
|
|
auto scrollable = entity->GetComponent<ScrollableComponent>();
|
|
if (transform && scrollable) {
|
|
transform->get().x = scrollable->get().worldX - scrollX;
|
|
}
|
|
|
|
entity->Update(deltaTime);
|
|
}
|
|
}
|