removing object if added to inventory

This commit is contained in:
maka70vv 2025-03-03 02:53:43 +06:00
parent 2d21324743
commit 45334c77f7
5 changed files with 16 additions and 39 deletions

View File

@ -21,34 +21,4 @@ struct ActiveObject {
ZL::Vector3f objectPos;
bool highlighted = false;
};
class ActiveObjectManager {
public:
std::unordered_map<std::string, ActiveObject> activeObjectsEntities;
// Добавить или обновить объект в контейнере
void addActiveObject(const ActiveObject& object) {
activeObjectsEntities[object.name] = object;
}
// Найти объект по имени (возвращает указатель, nullptr — если не найден)
ActiveObject* findByName(const std::string& name) {
auto it = activeObjectsEntities.find(name);
if (it != activeObjectsEntities.end()) {
return &it->second;
}
return nullptr;
}
// Найти все объекты с нужным значением highlighted
// (возвращает список указателей на найденные объекты)
// ActiveObject.h
void removeByName(const std::string& name) {
activeObjectsEntities.erase(name);
}
};
}

View File

@ -272,6 +272,8 @@ void GameObjectManager::handleEvent(const SDL_Event& event) {
objects_in_inventory++;
rooms[current_room_index].removeByPtr(ao);
activeObjects = rooms[current_room_index].objects;
//aoMgr.removeByName(ao->name);
}

View File

@ -6,6 +6,7 @@
#include <vector>
#include "ActiveObject.h"
#include "Room.h"
#include "RenderSystem.h"
#include "Inventory.h"
#ifdef __linux__
#include <SDL2/SDL.h>

View File

@ -165,13 +165,7 @@ void RenderSystem::drawWorld(GameObjectManager& gameObjects) {
renderer.TranslateMatrix({ 0, Environment::cameraDefaultVerticalShift, 0 });
// Draw active objects
for (const auto& ao : gameObjects.activeObjects) {
renderer.PushMatrix();
renderer.TranslateMatrix(ao.objectPos);
glBindTexture(GL_TEXTURE_2D, ao.activeObjectTexturePtr->getTexID());
renderer.DrawVertexRenderStruct(ao.activeObjectMeshMutable);
renderer.PopMatrix();
}
drawObjects(gameObjects);
// Draw room
glBindTexture(GL_TEXTURE_2D, gameObjects.rooms[gameObjects.current_room_index].roomTexture->getTexID());
@ -292,8 +286,6 @@ void RenderSystem::drawUI(const GameObjectManager& gameObjects) {
}
}
renderer.PopMatrix();
renderer.PopProjectionMatrix();
@ -399,4 +391,14 @@ void RenderSystem::worldToScreenCoordinates(Vector3f objectPos,
screenY = (int)((1.0f + ndcY) * 0.5f * screenHeight);
}
void RenderSystem::drawObjects(GameObjectManager& gameObjects){
for (const auto& ao : gameObjects.activeObjects) {
renderer.PushMatrix();
renderer.TranslateMatrix(ao.objectPos);
glBindTexture(GL_TEXTURE_2D, ao.activeObjectTexturePtr->getTexID());
renderer.DrawVertexRenderStruct(ao.activeObjectMeshMutable);
renderer.PopMatrix();
}
}
} // namespace ZL

View File

@ -19,6 +19,8 @@ public:
int screenWidth, int screenHeight,
int& screenX, int& screenY);
void drawObjects(GameObjectManager& gameObjects);
private:
void drawWorld(GameObjectManager& gameObjects);
void drawUI(const GameObjectManager& gameObjects);