Skip to content

Conversation

@Stepazavr
Copy link

Added a Camera manager, which contains a list of camera, ptr to a current active camera and also can

  1. create camera and return ptr to a created camera (if you want to work and change this camera, not current active)
  2. return ptr to a current active camera
  3. switch to the next or previous camera in a list (especially to demonstrate a list of camera in a game)

On a game scene (launch Game) you can create another camera with button "C" and switch to the next or previous one with the buttons "Q" and "E".

world.system<Position, CameraPtr, const Speed>()
.each([&](flecs::entity e, Position& position, CameraPtr& camera, const Speed& speed)
world.system<CameraManagerPtr>()
.each([&](flecs::entity e, CameraManagerPtr& cameraManager)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Как-то глупо, что у вас сущности есть с камера менеджером в качестве компоненты, не находите?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ну и что будет, если я создам 2 сущности с такой компонентой? А если 3?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

В игре должна быть сущность - менеджер камер. А значит, у сущности есть указатель на менеджер камер в качестве компоненты. В игре предполагается создание одного менеджера камер. Если в игре будет несколько таких сущностей, то действия (переключиться на след. камеру, создать камеру и т.д.) будут дублироваться, но при этом работать с одним и тем же менеджером камер.

Core::g_MainCamera = new Core::Camera();
Core::g_MainCamera->SetPosition(Math::Vector3f(0.0f, 12.0f, -10.0f));
Core::g_MainCamera->SetViewDir(Math::Vector3f(0.0f, -6.0f, 12.0f));
Core::g_CameraManager = new Core::CameraManager();
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Может, лучше через unique_ptr сделать? У нас всё же только один менеджер может быть, а так сейчас ещё и память течёт

for (World::LevelObject::Component& component : levelObject.GetComponents())
{
ImGui::InputText(component.first.c_str(), &component.second);
if (VECTOR3_COMPONENTS.contains(component.first)) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Я немного пофорщу код стайл движка, так что готовьтесь =)
В случае условий, как вы могли заметить, у нас фигурные скобки живут на отдельных строчках

if ()
{
...
}

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

да, стараюсь соблюдать, машинально пишу своим стилем

}

void LevelEditor::AddDefaultObject() {
if (!m_Level.has_value()) return;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Даже такие простые условия должны выделяться фигурными скобками в нашем движке


std::string baseName = "NewObject1";
std::string objectName = baseName;
int counter = 1;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Предпочитайте более явный тип данных. Есть всякие uint16_t и прочие. Из вашего кода я ожидаю, что возможные значения тут могут быть и отрицательные.

// Can be set to 0 since it doesn't matter now, will be updated by the system
entity.set(EntitySystem::EditorECS::Position{ 0.0f, 0.0f, 0.0f });
entity.set(GeometryPtr{
reinterpret_cast<RenderCore::Geometry*>(
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Не static_cast?

namespace GameEngine::Core
{
Camera* g_MainCamera = nullptr;
//Camera* g_MainCamera = nullptr;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Не оставляйте такие комментарии. Просто удалите, раз оно не надо


Camera::Ptr CameraManager::CreateCamera()
{
auto newCamera = std::make_shared<Camera>();
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

auto...

--m_CurrCameraIt;
}
}
} No newline at end of file
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

А если я хочу не "следующую камеру", а вполне конкретную камеру активировать?

GameEngine::Core::Controller* ptr;
};

struct ButtonManager
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Из текущей логики я могу переключиться только раз. Я хочу переключаться бесконечное количество раз, но не создавать новые камеры из кода, только заранее заданные камеры привязанные к объектам

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

нет, переключаться можно сколько угодно раз. Компонент ButtonManager нужен для того, чтобы предотвращать залипание кнопки. При нажатии на клавишу (переменная wasPressed меняется на true) переключение произойдет только один раз и не будет возможным до тех пор, пока не будет отжата кнопка (wasPressed = false).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants