active objects to unordered map
This commit is contained in:
parent
4fd09212dd
commit
6c25d1f06b
@ -18,4 +18,38 @@ struct ActiveObject {
|
|||||||
bool highlighted = false;
|
bool highlighted = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class ActiveObjectManager {
|
||||||
|
public:
|
||||||
|
// Добавить или обновить объект в контейнере
|
||||||
|
void addActiveObject(const ActiveObject& object) {
|
||||||
|
activeObjects[object.name] = object;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Найти объект по имени (возвращает указатель, nullptr — если не найден)
|
||||||
|
ActiveObject* findByName(const std::string& name) {
|
||||||
|
auto it = activeObjects.find(name);
|
||||||
|
if (it != activeObjects.end()) {
|
||||||
|
return &it->second;
|
||||||
|
}
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Найти все объекты с нужным значением highlighted
|
||||||
|
// (возвращает список указателей на найденные объекты)
|
||||||
|
std::vector<ActiveObject*> findByHighlighted(bool highlighted) {
|
||||||
|
std::vector<ActiveObject*> result;
|
||||||
|
result.reserve(activeObjects.size());
|
||||||
|
for (auto& [key, object] : activeObjects) {
|
||||||
|
if (object.highlighted == highlighted) {
|
||||||
|
result.push_back(&object);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
// Хранение объектов по ключу name
|
||||||
|
std::unordered_map<std::string, ActiveObject> activeObjects;
|
||||||
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -56,7 +56,7 @@ void GameObjectManager::initialize() {
|
|||||||
Room room_1;
|
Room room_1;
|
||||||
room_1.roomTexture = std::make_shared<Texture>(CreateTextureDataFromBmp24("./Kitchen_ceramics.bmp"));
|
room_1.roomTexture = std::make_shared<Texture>(CreateTextureDataFromBmp24("./Kitchen_ceramics.bmp"));
|
||||||
room_1.objects.push_back(ao1);
|
room_1.objects.push_back(ao1);
|
||||||
room_1.sound_name = "file_example_OOG_5MG.ogg";
|
room_1.sound_name = "Symphony No.6 (1st movement).ogg";
|
||||||
room_1.roomLogic = createRoom1Logic();
|
room_1.roomLogic = createRoom1Logic();
|
||||||
rooms.push_back(room_1);
|
rooms.push_back(room_1);
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user