Skip to content

Commit

Permalink
Fix: Viewport compilation
Browse files Browse the repository at this point in the history
  • Loading branch information
brenocq committed Jun 12, 2024
1 parent 85a820e commit d881747
Show file tree
Hide file tree
Showing 9 changed files with 312 additions and 306 deletions.
13 changes: 7 additions & 6 deletions src/atta/file/project/projectSerializerDeserialize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,13 @@ void ProjectSerializer::deserializeComponentModule(Section& section) {
void ProjectSerializer::deserializeGraphicsModule(Section& section) {
if (section.contains("viewports")) {
std::vector<graphics::Viewport> viewports = std::vector<graphics::Viewport>(section["viewports"]);
graphics::clearViewports();
for (auto& viewport : viewports) {
std::shared_ptr<graphics::Viewport> v = std::make_shared<graphics::Viewport>();
*v = viewport;
graphics::addViewport(v);
}
LOG_WARN("file::ProjectSerializer", "Deserializing viewports was not implemented yet");
// graphics::clearViewports();
// for (auto& viewport : viewports) {
// std::shared_ptr<graphics::Viewport> v = std::make_shared<graphics::Viewport>();
// *v = viewport;
// graphics::addViewport(v);
// }
}
if (section.contains("graphicsFPS"))
graphics::setGraphicsFPS(float(section["graphicsFPS"]));
Expand Down
11 changes: 6 additions & 5 deletions src/atta/file/project/projectSerializerSerialize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,12 @@ void ProjectSerializer::serializeComponentModule(Section& section) {
}

void ProjectSerializer::serializeGraphicsModule(Section& section) {
std::vector<std::shared_ptr<graphics::Viewport>> pviewports = graphics::getViewports();
std::vector<graphics::Viewport> viewports;
for (auto pv : pviewports)
viewports.push_back(*pv);
section["viewports"] = viewports;
// std::vector<std::shared_ptr<graphics::Viewport>> pviewports = graphics::getViewports();
// std::vector<graphics::Viewport> viewports;
// for (auto pv : pviewports)
// viewports.push_back(*pv);
// section["viewports"] = viewports;
LOG_WARN("file::ProjectSerializer", "Serializing viewports was not implemented yet");
section["graphicsFPS"] = graphics::getGraphicsFPS();
section["viewportFPS"] = graphics::getViewportFPS();
section["viewportRendering"] = graphics::getViewportRendering();
Expand Down
16 changes: 8 additions & 8 deletions src/atta/graphics/interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,14 @@ void setUiShutDownFunc(std::function<void()> uiShutDownFunc) { Manager::getInsta
void setUiStartUpFunc(std::function<void()> uiStartUpFunc) { Manager::getInstance()._uiStartUpFunc = uiStartUpFunc; }

//----- Viewport -----//
std::vector<std::shared_ptr<Viewport>> getViewports() { return Manager::getInstance().getViewportsImpl(); }
void clearViewports() { Manager::getInstance().clearViewportsImpl(); }
void addViewport(std::shared_ptr<Viewport> viewport) { Manager::getInstance().addViewportImpl(viewport); }
void removeViewport(std::shared_ptr<Viewport> viewport) { Manager::getInstance().removeViewportImpl(viewport); }
void createDefaultViewports() { return Manager::getInstance().createDefaultViewportsImpl(); }
component::EntityId viewportEntityClick(std::shared_ptr<Viewport> viewport, vec2i pos) {
return Manager::getInstance().viewportEntityClickImpl(viewport, pos);
}
// std::vector<std::shared_ptr<Viewport>> getViewports() { return Manager::getInstance().getViewportsImpl(); }
// void clearViewports() { Manager::getInstance().clearViewportsImpl(); }
// void addViewport(std::shared_ptr<Viewport> viewport) { Manager::getInstance().addViewportImpl(viewport); }
// void removeViewport(std::shared_ptr<Viewport> viewport) { Manager::getInstance().removeViewportImpl(viewport); }
// void createDefaultViewports() { return Manager::getInstance().createDefaultViewportsImpl(); }
// component::EntityId viewportEntityClick(std::shared_ptr<Viewport> viewport, vec2i pos) {
// return Manager::getInstance().viewportEntityClickImpl(viewport, pos);
//}

void* getImGuiImage(StringId sid) { return Manager::getInstance().getImGuiImageImpl(sid); }

Expand Down
82 changes: 41 additions & 41 deletions src/atta/graphics/manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ void Manager::startUpImpl() {
_computeEntityClick = std::make_unique<EntityClick>();

//----- Create viewports -----//
createDefaultViewportsImpl();
// createDefaultViewportsImpl();
}

void Manager::shutDownImpl() {
Expand Down Expand Up @@ -164,46 +164,46 @@ void Manager::recreateGraphicsAPI() {
_uiStartUpFunc();
}

std::vector<std::shared_ptr<Viewport>>& Manager::getViewportsImpl() { return _viewports; }

void Manager::clearViewportsImpl() {
_viewportsNext.clear();
_swapViewports = true;
}

void Manager::addViewportImpl(std::shared_ptr<Viewport> viewport) {
_viewportsNext.push_back(viewport);
_swapViewports = true;
}

void Manager::removeViewportImpl(std::shared_ptr<Viewport> viewport) {
// TODO make it work with zero viewports
if (_viewportsNext.size() > 1) {
for (unsigned i = 0; i < _viewportsNext.size(); i++)
if (_viewportsNext[i] == viewport) {
_viewportsNext.erase(_viewportsNext.begin() + i);
break;
}
_swapViewports = true;
} else {
LOG_WARN("graphics::Manager", "It is not possible to have 0 viewports yet");
}
}

void Manager::createDefaultViewportsImpl() {
_viewportsNext.clear();

Viewport::CreateInfo viewportInfo;
viewportInfo.renderer = std::make_shared<PbrRenderer>();
viewportInfo.camera = std::make_shared<PerspectiveCamera>(PerspectiveCamera::CreateInfo{});
viewportInfo.sid = StringId("Main Viewport");
_viewportsNext.push_back(std::make_shared<Viewport>(viewportInfo));
_swapViewports = true;
}

component::EntityId Manager::viewportEntityClickImpl(std::shared_ptr<Viewport> viewport, vec2i pos) {
return _computeEntityClick->click(viewport, pos);
}
// std::vector<std::shared_ptr<Viewport>>& Manager::getViewportsImpl() { return _viewports; }

// void Manager::clearViewportsImpl() {
// _viewportsNext.clear();
// _swapViewports = true;
// }
//
// void Manager::addViewportImpl(std::shared_ptr<Viewport> viewport) {
// _viewportsNext.push_back(viewport);
// _swapViewports = true;
// }
//
// void Manager::removeViewportImpl(std::shared_ptr<Viewport> viewport) {
// // TODO make it work with zero viewports
// if (_viewportsNext.size() > 1) {
// for (unsigned i = 0; i < _viewportsNext.size(); i++)
// if (_viewportsNext[i] == viewport) {
// _viewportsNext.erase(_viewportsNext.begin() + i);
// break;
// }
// _swapViewports = true;
// } else {
// LOG_WARN("graphics::Manager", "It is not possible to have 0 viewports yet");
// }
// }
//
// void Manager::createDefaultViewportsImpl() {
// _viewportsNext.clear();
//
// Viewport::CreateInfo viewportInfo;
// viewportInfo.renderer = std::make_shared<PbrRenderer>();
// viewportInfo.camera = std::make_shared<PerspectiveCamera>(PerspectiveCamera::CreateInfo{});
// viewportInfo.sid = StringId("Main Viewport");
// _viewportsNext.push_back(std::make_shared<Viewport>(viewportInfo));
// _swapViewports = true;
// }
//
// component::EntityId Manager::viewportEntityClickImpl(std::shared_ptr<Viewport> viewport, vec2i pos) {
// return _computeEntityClick->click(viewport, pos);
// }

void* Manager::getImGuiImageImpl(StringId sid) { return _images[sid]->getImGuiImage(); }

Expand Down
1 change: 1 addition & 0 deletions src/atta/pch.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#define ATTA_PRE_COMPILED_HEADER_H

#define _USE_MATH_DEFINES // Windows M_PI fix
#include <algorithm>
#include <any>
#include <array>
#include <bitset>
Expand Down
143 changes: 72 additions & 71 deletions src/atta/ui/editor/topBar/topBar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,45 +93,45 @@ void TopBar::render() {
ImGui::EndMenu();
}

if (ImGui::BeginMenu("Viewports")) {
std::vector<std::shared_ptr<graphics::Viewport>> viewports = graphics::getViewports();
_viewportModals.resize(viewports.size());
int i = 0;
for (auto viewport : viewports) {
if (ImGui::MenuItem(viewport->getName().c_str()))
_viewportModals[i] = true;
i++;
}

ImGui::Separator();

if (ImGui::MenuItem("Create viewport")) {
// Choose viewport name
unsigned newViewportNumber = 0;
bool found = false;
while (!found) {
found = true;
for (auto viewport : viewports)
if (viewport->getSID() == StringId("Viewport " + std::to_string(newViewportNumber))) {
found = false;
break;
}
if (!found)
newViewportNumber++;
}
// if (ImGui::BeginMenu("Viewports")) {
// std::vector<std::shared_ptr<graphics::Viewport>> viewports = graphics::getViewports();
// _viewportModals.resize(viewports.size());
// int i = 0;
// for (auto viewport : viewports) {
// if (ImGui::MenuItem(viewport->getName().c_str()))
// _viewportModals[i] = true;
// i++;
// }

// ImGui::Separator();

// if (ImGui::MenuItem("Create viewport")) {
// // Choose viewport name
// unsigned newViewportNumber = 0;
// bool found = false;
// while (!found) {
// found = true;
// for (auto viewport : viewports)
// if (viewport->getSID() == StringId("Viewport " + std::to_string(newViewportNumber))) {
// found = false;
// break;
// }
// if (!found)
// newViewportNumber++;
// }

// // Create viewport
// graphics::Viewport::CreateInfo viewportInfo;
// viewportInfo.renderer = std::make_shared<graphics::PhongRenderer>();
// viewportInfo.camera = std::static_pointer_cast<graphics::Camera>(
// std::make_shared<graphics::PerspectiveCamera>(graphics::PerspectiveCamera::CreateInfo{}));
// viewportInfo.sid = StringId("Viewport " + std::to_string(newViewportNumber));
// std::shared_ptr<graphics::Viewport> viewport = std::make_shared<graphics::Viewport>(viewportInfo);
// graphics::addViewport(viewport);
// }

// Create viewport
graphics::Viewport::CreateInfo viewportInfo;
viewportInfo.renderer = std::make_shared<graphics::PhongRenderer>();
viewportInfo.camera = std::static_pointer_cast<graphics::Camera>(
std::make_shared<graphics::PerspectiveCamera>(graphics::PerspectiveCamera::CreateInfo{}));
viewportInfo.sid = StringId("Viewport " + std::to_string(newViewportNumber));
std::shared_ptr<graphics::Viewport> viewport = std::make_shared<graphics::Viewport>(viewportInfo);
graphics::addViewport(viewport);
}

ImGui::EndMenu();
}
// ImGui::EndMenu();
//}

if (ImGui::BeginMenu("Modules")) {
if (ImGui::MenuItem("Graphics"))
Expand Down Expand Up @@ -459,7 +459,7 @@ void TopBar::saveProjectModal() {
component::clear();
component::createDefault();
// Replace viewports with default
graphics::createDefaultViewports();
// XXX graphics::createDefaultViewports();

if (_quitAfterSaveModal) {
event::WindowClose e;
Expand All @@ -474,38 +474,39 @@ void TopBar::saveProjectModal() {
}

void TopBar::viewportModals() {
std::vector<std::shared_ptr<graphics::Viewport>> viewports = graphics::getViewports();
static std::vector<bool> newViewportModals; // If first time creating the modal
_viewportModals.resize(viewports.size());

// Check if first time creating viewport
newViewportModals.resize(_viewportModals.size());
for (unsigned i = 0; i < newViewportModals.size(); i++)
newViewportModals[i] = !newViewportModals[i] && _viewportModals[i];

for (uint32_t i = 0; i < _viewportModals.size(); i++) {
char nameBuf[196];
sprintf(nameBuf, "%s###ViewportProps%s", viewports[i]->getName().c_str(), viewports[i]->getSID().getString().c_str());

bool open = _viewportModals[i];
if (open) {
if (newViewportModals[i])
ImGui::SetNextWindowSize(ImVec2(200.0f, 300.0f));
if (ImGui::Begin(nameBuf, &open)) {
viewports[i]->renderUI();

ImGui::Separator();
if (ImGui::Button("Delete Viewport")) {
graphics::removeViewport(viewports[i]);
ImGui::End();
break;
}
}
ImGui::End();
_viewportModals[i] = open;
}
}
newViewportModals = _viewportModals;
// XXX
// std::vector<std::shared_ptr<graphics::Viewport>> viewports = graphics::getViewports();
// static std::vector<bool> newViewportModals; // If first time creating the modal
//_viewportModals.resize(viewports.size());

//// Check if first time creating viewport
// newViewportModals.resize(_viewportModals.size());
// for (unsigned i = 0; i < newViewportModals.size(); i++)
// newViewportModals[i] = !newViewportModals[i] && _viewportModals[i];

// for (uint32_t i = 0; i < _viewportModals.size(); i++) {
// char nameBuf[196];
// sprintf(nameBuf, "%s###ViewportProps%s", viewports[i]->getName().c_str(), viewports[i]->getSID().getString().c_str());

// bool open = _viewportModals[i];
// if (open) {
// if (newViewportModals[i])
// ImGui::SetNextWindowSize(ImVec2(200.0f, 300.0f));
// if (ImGui::Begin(nameBuf, &open)) {
// viewports[i]->renderUI();

// ImGui::Separator();
// if (ImGui::Button("Delete Viewport")) {
// graphics::removeViewport(viewports[i]);
// ImGui::End();
// break;
// }
// }
// ImGui::End();
// _viewportModals[i] = open;
// }
//}
// newViewportModals = _viewportModals;
}

} // namespace atta::ui
2 changes: 2 additions & 0 deletions src/atta/ui/editor/topBar/topBar.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include <atta/ui/editor/topBar/localWindows/repoWindow.h>

namespace atta::ui {

class TopBar {
public:
TopBar();
Expand Down Expand Up @@ -39,6 +40,7 @@ class TopBar {
std::vector<bool> _viewportModals; ///< Which viewports should be rendered
std::vector<RepoWindow> _repoWindows; ///< Which repository windows are open
};

} // namespace atta::ui

#endif // ATTA_UI_EDITOR_TOP_BAR_TOP_BAR_H
Loading

0 comments on commit d881747

Please sign in to comment.