removing object if added to inventory
This commit is contained in:
parent
2d21324743
commit
45334c77f7
@ -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);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@ -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);
|
||||
}
|
||||
|
||||
@ -6,6 +6,7 @@
|
||||
#include <vector>
|
||||
#include "ActiveObject.h"
|
||||
#include "Room.h"
|
||||
#include "RenderSystem.h"
|
||||
#include "Inventory.h"
|
||||
#ifdef __linux__
|
||||
#include <SDL2/SDL.h>
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user