Creepy-simulation
 
Loading...
Searching...
No Matches
CreepersManager.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <glog/logging.h>
4
5#include <list>
6
7#include "Creeper.hpp"
8#include "Steve.hpp"
9
10class Simulation;
16 std::shared_ptr<CreepersParams> params_;
17 std::vector<std::shared_ptr<Creeper>> creepers_;
18 std::vector<std::shared_ptr<Creeper>> actives_;
19
20 protected:
25 [[nodiscard]] decltype(creepers_)& getCreepersRef() { return creepers_; }
26
27 public:
32 CreepersManager(std::shared_ptr<CreepersParams> params);
37 void beginAndFindSteves(const std::vector<std::shared_ptr<Steve>>& steves);
42 [[nodiscard]] const decltype(creepers_)& getCreepers() const { return creepers_; }
46 void walk();
50 void refreshActives();
56 template <typename Units>
57 void interactWith(Units units) {
58#pragma omp parallel for
59 for (auto i = 0; i < actives_.size(); ++i) {
60 for (const auto& unit : units) {
61 if (static_cast<Unit*>(actives_[i].get()) != static_cast<Unit*>(unit.get())) {
62 actives_[i]->updateState(unit);
63 }
64 }
65 }
66 }
67
68 friend Simulation;
69};
Manages a collection of creeper entities and their interactions.
Definition CreepersManager.hpp:15
void refreshActives()
Refreshes the list of active creepers.
Definition CreepersManager.cpp:29
decltype(creepers_) & getCreepersRef()
Provides access to the collection of all creepers.
Definition CreepersManager.hpp:25
void walk()
Executes the walking behavior for all creepers.
Definition CreepersManager.cpp:22
void beginAndFindSteves(const std::vector< std::shared_ptr< Steve > > &steves)
Initializes creepers and associates them with nearby Steves.
Definition CreepersManager.cpp:12
const decltype(creepers_) & getCreepers() const
Provides constant access to the collection of all creepers.
Definition CreepersManager.hpp:42
friend Simulation
Definition CreepersManager.hpp:68
void interactWith(Units units)
Allows creepers to interact with a collection of other units.
Definition CreepersManager.hpp:57
Main controller for managing the simulation of creepers and Steves.
Definition Simulation.hpp:16
Represents a generic unit in the simulation.
Definition Unit.hpp:63