Skip to content

Commit

Permalink
support editor/application deployment and fullscreen mode
Browse files Browse the repository at this point in the history
  • Loading branch information
Code-Guy committed Oct 16, 2023
1 parent 54754e7 commit 63ceb2a
Show file tree
Hide file tree
Showing 14 changed files with 147 additions and 110 deletions.
2 changes: 1 addition & 1 deletion source/editor/editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ namespace Bamboo

void Editor::constructUI()
{
if (g_editor.isFullscreen())
if (g_editor.isSimulationPanelFullscreen())
{
m_simulation_ui->construct();
}
Expand Down
19 changes: 19 additions & 0 deletions source/editor/global/editor_context.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#include "editor_context.h"
#include "engine/function/global/engine_context.h"
#include "engine/function/render/window_system.h"

namespace Bamboo
{
Expand All @@ -14,4 +16,21 @@ namespace Bamboo

}

void EditorContext::toggleFullscreen()
{
if (g_engine.isEditor())
{
m_simulation_panel_fullscreen = !m_simulation_panel_fullscreen;
}
else
{
g_engine.windowSystem()->toggleFullscreen();
}
}

bool EditorContext::isSimulationPanelFullscreen()
{
return m_simulation_panel_fullscreen || g_engine.isApplication();
}

}
10 changes: 3 additions & 7 deletions source/editor/global/editor_context.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,11 @@ namespace Bamboo
void init();
void destroy();

void toggleFullscreen() { m_fullscreen = !m_fullscreen; }
bool isFullscreen() { return m_fullscreen; }

void toggleSimulate() { m_simulate = !m_simulate; }
bool isSimulate() { return m_simulate; }
void toggleFullscreen();
bool isSimulationPanelFullscreen();

private:
bool m_fullscreen = false;
bool m_simulate = false;
bool m_simulation_panel_fullscreen = false;
};

extern EditorContext g_editor;
Expand Down
87 changes: 53 additions & 34 deletions source/editor/simulation/simulation_ui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,15 @@ namespace Bamboo
{
const std::string& world_name = g_engine.worldManager()->getCurrentWorldName();
sprintf(m_title_buf, "%s %s###%s", ICON_FA_GAMEPAD, world_name.c_str(), m_title.c_str());

bool is_simulating_fullscreen = g_engine.isSimulating() && g_editor.isSimulationPanelFullscreen();
ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(0.0f, 0.0f));
ImGui::PushStyleVar(ImGuiStyleVar_WindowBorderSize, is_simulating_fullscreen ? 0.0f : 1.0f);

if (!ImGui::Begin(m_title_buf))
{
ImGui::End();
ImGui::PopStyleVar();
ImGui::PopStyleVar(2);
return;
}
updateWindowRegion();
Expand All @@ -58,7 +62,7 @@ namespace Bamboo
{
ImGuiWindow* window = ImGui::FindWindowByName(m_title_buf);
ImGuiDockNode* node = window->DockNode;
bool show_tab = !(g_editor.isSimulate() && g_editor.isFullscreen());
bool show_tab = !is_simulating_fullscreen;
if ((!show_tab && !node->IsHiddenTabBar()) || (show_tab && node->IsHiddenTabBar()))
{
node->WantHiddenTabBarToggle = true;
Expand All @@ -72,12 +76,12 @@ namespace Bamboo
ImVec2 content_size = ImGui::GetContentRegionAvail();
ImGui::Image(m_color_texture_desc_set, content_size);

if (g_editor.isSimulate() || !g_engine.isEditing())
if (g_engine.isSimulating())
{
updateCamera();

ImGui::End();
ImGui::PopStyleVar();
ImGui::PopStyleVar(2);
return;
}

Expand Down Expand Up @@ -171,7 +175,7 @@ namespace Bamboo
constructImGuizmo();

ImGui::End();
ImGui::PopStyleVar();
ImGui::PopStyleVar(2);
}

void SimulationUI::destroy()
Expand Down Expand Up @@ -386,46 +390,61 @@ namespace Bamboo
{
g_editor.toggleFullscreen();
}
else if (key_event->key == GLFW_KEY_G)
{
g_editor.toggleSimulate();
}

if (m_selected_entity.lock())
if (g_engine.isEditor())
{
uint32_t selected_entity_id = m_selected_entity.lock()->getID();
if (key_event->key == GLFW_KEY_ESCAPE || key_event->key == GLFW_KEY_DELETE)
EWorldMode current_world_mode = g_engine.worldManager()->getWorldMode();
if (key_event->mods == GLFW_MOD_ALT && key_event->key == GLFW_KEY_P)
{
g_engine.eventSystem()->syncDispatch(std::make_shared<SelectEntityEvent>(UINT_MAX));
if (current_world_mode == EWorldMode::Edit)
{
g_engine.worldManager()->setWorldMode(EWorldMode::Play);
}
}
if (key_event->key == GLFW_KEY_DELETE)
else if (key_event->key == GLFW_KEY_ESCAPE)
{
g_engine.worldManager()->getCurrentWorld()->removeEntity(selected_entity_id);
if (current_world_mode == EWorldMode::Play)
{
g_engine.worldManager()->setWorldMode(EWorldMode::Edit);
}
}
}

if (!isFocused())
{
return;
}

if (m_selected_entity.lock() || !m_mouse_right_button_pressed)
{
if (key_event->key == GLFW_KEY_Q)
{
m_operation_mode = EOperationMode::Pick;
}
else if (key_event->key == GLFW_KEY_W)
if (m_selected_entity.lock())
{
m_operation_mode = EOperationMode::Translate;
uint32_t selected_entity_id = m_selected_entity.lock()->getID();
if (key_event->key == GLFW_KEY_ESCAPE || key_event->key == GLFW_KEY_DELETE)
{
g_engine.eventSystem()->syncDispatch(std::make_shared<SelectEntityEvent>(UINT_MAX));
}
if (key_event->key == GLFW_KEY_DELETE)
{
g_engine.worldManager()->getCurrentWorld()->removeEntity(selected_entity_id);
}
}
else if (key_event->key == GLFW_KEY_E)

if (!isFocused())
{
m_operation_mode = EOperationMode::Rotate;
return;
}
else if (key_event->key == GLFW_KEY_R)

if (m_selected_entity.lock() || !m_mouse_right_button_pressed)
{
m_operation_mode = EOperationMode::Scale;
if (key_event->key == GLFW_KEY_Q)
{
m_operation_mode = EOperationMode::Pick;
}
else if (key_event->key == GLFW_KEY_W)
{
m_operation_mode = EOperationMode::Translate;
}
else if (key_event->key == GLFW_KEY_E)
{
m_operation_mode = EOperationMode::Rotate;
}
else if (key_event->key == GLFW_KEY_R)
{
m_operation_mode = EOperationMode::Scale;
}
}
}
}
Expand All @@ -451,7 +470,7 @@ namespace Bamboo

// set camera component
m_camera_component.lock()->m_aspect_ratio = (float)m_content_region.z / m_content_region.w;
if (g_editor.isSimulate())
if (g_engine.isSimulating())
{
m_mouse_right_button_pressed = ImGui::IsMouseDown(ImGuiMouseButton_Right);
}
Expand Down
9 changes: 7 additions & 2 deletions source/engine/core/config/config_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ namespace Bamboo
return m_config_node["window"]["height"].as<int>();
}

bool ConfigManager::isFullscreen()
{
return m_config_node["window"]["fullscreen"].as<bool>();
}

std::string ConfigManager::getDefaultWorldUrl()
{
return m_config_node["default_world_url"].as<std::string>();
Expand All @@ -33,9 +38,9 @@ namespace Bamboo
return m_config_node["save_layout"].as<bool>();
}

bool ConfigManager::isInEditor()
bool ConfigManager::isEditor()
{
return m_config_node["in_editor"].as<bool>();
return m_config_node["is_editor"].as<bool>();
}

}
3 changes: 2 additions & 1 deletion source/engine/core/config/config_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,13 @@ namespace Bamboo

int getWindowWidth();
int getWindowHeight();
bool isFullscreen();

std::string getDefaultWorldUrl();
std::string getEditorLayout();
bool getSaveLayout();

bool isInEditor();
bool isEditor();

private:
YAML::Node m_config_node;
Expand Down
6 changes: 3 additions & 3 deletions source/engine/function/framework/world/world.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ namespace Bamboo
const auto& entity = iter.second;
entity->m_world = weak_from_this();
entity->inflate();
if (!g_engine.isEditing())
if (g_engine.isSimulating())
{
entity->beginPlay();
}
Expand Down Expand Up @@ -101,7 +101,7 @@ namespace Bamboo
entity->m_name = name;
entity->m_world = weak_from_this();

if (!g_engine.isEditing())
if (g_engine.isSimulating())
{
entity->beginPlay();
}
Expand All @@ -112,7 +112,7 @@ namespace Bamboo

bool World::removeEntity(uint32_t id)
{
if (!g_engine.isEditing())
if (g_engine.isSimulating())
{
m_entities[id]->endPlay();
}
Expand Down
1 change: 1 addition & 0 deletions source/engine/function/framework/world/world_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ namespace Bamboo
void WorldManager::init()
{
URL default_world_url = g_engine.configManager()->getDefaultWorldUrl();
m_world_mode = g_engine.isEditor() ? EWorldMode::Edit : EWorldMode::Play;

loadWorld(default_world_url);
//scriptWorld();
Expand Down
4 changes: 2 additions & 2 deletions source/engine/function/global/engine_context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,9 @@ namespace Bamboo
m_timer_manager->destroy();
}

bool EngineContext::isInEditor()
bool EngineContext::isEditor()
{
return m_config_manager->isInEditor();
return m_config_manager->isEditor();
}

bool EngineContext::isEditing()
Expand Down
5 changes: 4 additions & 1 deletion source/engine/function/global/engine_context.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,13 @@ namespace Bamboo
float getDeltaTime() { return m_delta_time; }

// runtime modes
bool isInEditor();
bool isEditor();
bool isApplication() { return !isEditor(); }

bool isEditing();
bool isPlaying();
bool isPausing();
bool isSimulating() { return isPlaying() || isPausing(); }

private:
std::shared_ptr<class TimerManager> m_timer_manager;
Expand Down
48 changes: 3 additions & 45 deletions source/engine/function/render/render_system.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@ namespace Bamboo
void RenderSystem::tick(float delta_time)
{
// collect render data from entities of current world
//scriptEntities(delta_time);
collectRenderDatas();

// vulkan rendering
Expand Down Expand Up @@ -528,22 +527,13 @@ namespace Bamboo
m_pick_pass->setEntityIDs(mesh_entity_ids);

// outline pass
m_outline_pass->setRenderDatas(selected_mesh_render_datas);
m_outline_pass->setBillboardRenderDatas(selected_billboard_render_datas);
m_outline_pass->setRenderDatas(!g_engine.isSimulating() ? selected_mesh_render_datas : std::vector<std::shared_ptr<RenderData>>{});
m_outline_pass->setBillboardRenderDatas(!g_engine.isSimulating() ? selected_billboard_render_datas : std::vector<std::shared_ptr<BillboardRenderData>>{});

// main pass
m_main_pass->setLightingRenderData(lighting_render_data);
m_main_pass->setSkyboxRenderData(skybox_render_data);
// if (!mesh_render_datas.empty())
// {
// m_main_pass->setTransparencyRenderDatas({ mesh_render_datas.back() });
// mesh_render_datas.pop_back();
// }
// else
// {
// m_main_pass->setTransparencyRenderDatas({});
// }
m_main_pass->setBillboardRenderDatas(billboard_render_datas);
m_main_pass->setBillboardRenderDatas(!g_engine.isSimulating() ? billboard_render_datas : std::vector<std::shared_ptr<BillboardRenderData>>{});
m_main_pass->setRenderDatas(mesh_render_datas);

// postprocess pass
Expand Down Expand Up @@ -586,36 +576,4 @@ namespace Bamboo
billboard_entity_ids.push_back(entity_id);
}

void RenderSystem::scriptEntities(float delta_time)
{
const auto& current_world = g_engine.worldManager()->getCurrentWorld();
const auto& entities = current_world->getEntities();

std::random_device rd;
std::mt19937 mt(rd());
std::uniform_real_distribution<float> dist(0.1f, 1.0f);

static float time = 0.0f;
static glm::vec3 start_axis = glm::normalize(glm::vec3(dist(mt), dist(mt), dist(mt)));
static glm::vec3 target_axis = glm::normalize(glm::vec3(dist(mt), dist(mt), dist(mt)));

time += delta_time;
if (time > 1.0f)
{
target_axis = glm::normalize(glm::vec3(dist(mt), dist(mt), dist(mt)));
time = 0.0f;
}

glm::vec3 current_axis = glm::mix(start_axis, target_axis, time);
for (const auto& iter : entities)
{
const auto& entity = iter.second;
if (entity->getName() == "sm_octopus_dance")
{
auto transform_component = entity->getComponent(TransformComponent);
transform_component->m_rotation += target_axis * delta_time * 30.0f;
}
}
}

}
1 change: 0 additions & 1 deletion source/engine/function/render/render_system.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ namespace Bamboo
std::vector<std::shared_ptr<BillboardRenderData>>& selected_billboard_render_datas,
std::vector<uint32_t>& billboard_entity_ids,
ELightType light_type);
void scriptEntities(float delta_time);

// render passes
std::shared_ptr<class DirectionalLightShadowPass> m_directional_light_shadow_pass;
Expand Down
Loading

0 comments on commit 63ceb2a

Please sign in to comment.