Skip to content

Commit

Permalink
fix world / bsp toggle
Browse files Browse the repository at this point in the history
  • Loading branch information
xoxor4d committed Dec 30, 2023
1 parent 222ac50 commit af157a1
Show file tree
Hide file tree
Showing 9 changed files with 69 additions and 20 deletions.
22 changes: 19 additions & 3 deletions src/components/modules/d3dbsp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ namespace components
int d3dbsp::radiant_dobj_count = 0;
d3dbsp::radiant_dobj_s d3dbsp::radiant_dobj[512] = {};


void d3dbsp::dobj_clear_list()
{
memset(d3dbsp::radiant_dobj, 0, sizeof(d3dbsp::radiant_dobj));
Expand Down Expand Up @@ -744,6 +743,22 @@ namespace components
}
}

void d3dbsp::toggle_radiant_bsp_view(bool show_bsp)
{
if (d3dbsp::Com_IsBspLoaded())
{
const bool gameview_was_enabled = dvars::radiant_gameview->current.enabled;

dvars::set_bool(dvars::r_draw_bsp, show_bsp);
gameview::get()->toggle_all_filters(show_bsp);

if (gameview_was_enabled)
{
components::gameview::p_this->set_state(gameview_was_enabled);
}
}
}

void d3dbsp::compile_fastfile(const std::string& bsp_name)
{
game::printf_to_console("[BSP] Compiling fastfile for map: %s ... \n", bsp_name.c_str());
Expand Down Expand Up @@ -864,8 +879,7 @@ namespace components
{
if (dvars::bsp_show_bsp_after_compile->current.enabled)
{
command::execute("toggle_bsp_radiant");
dvars::set_bool(dvars::r_draw_bsp, dvars::bsp_show_bsp_after_compile->current.enabled);
toggle_radiant_bsp_view(true);
}

// slightly delay process generation
Expand Down Expand Up @@ -1020,6 +1034,8 @@ namespace components
/* desc */ "enable to overwrite bsp sunspecular with fakesun settings");
}



d3dbsp::d3dbsp()
{
// #
Expand Down
2 changes: 2 additions & 0 deletions src/components/modules/d3dbsp.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,8 @@ namespace components
static bool radiant_load_bsp(const char* bsppath, bool reload = false);
static void reload_bsp();

static void toggle_radiant_bsp_view(bool show_bsp);

static void compile_fastfile(const std::string& bsp_name);
static void compile_bsp(const std::string& bsp_name, bool generate_createfx = false);
static void compile_current_map();
Expand Down
28 changes: 28 additions & 0 deletions src/components/modules/gameview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ namespace components
{
gameview* gameview::p_this = nullptr;

gameview* gameview::get()
{
return p_this;
}

void gameview::toggle_all_geo(bool state)
{
if (!gameview::p_this)
Expand Down Expand Up @@ -269,6 +274,29 @@ namespace components
gameview::all_off = !gameview::all_off;
}

void gameview::toggle_all_filters(bool state)
{
// restore states if was toggled manually
if (gameview::get_all_geo_state()) gameview::toggle_all_geo(false);
if (gameview::get_all_ents_state()) gameview::toggle_all_entities(false);
if (gameview::get_all_triggers_state()) gameview::toggle_all_triggers(false);
if (gameview::get_all_others_state()) gameview::toggle_all_others(false);

// toggle global
gameview::toggle_all_geo(state);
gameview::toggle_all_entities(state);
gameview::toggle_all_triggers(state);
gameview::toggle_all_others(state);

gameview::all_off = state;
}

bool gameview::toggle_all_get_state()
{
return all_off;
}


void gameview::set_state(bool state)
{
const auto filter = GET_GUI(ggui::filter_dialog);
Expand Down
5 changes: 4 additions & 1 deletion src/components/modules/gameview.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ namespace components
const char* get_name() override { return "gameview"; };

static gameview* p_this;
static gameview* get();

[[nodiscard]] bool get_all_geo_state() const
{
Expand All @@ -36,7 +37,9 @@ namespace components
void toggle_all_triggers(bool state);
void toggle_all_others(bool state);
void toggle_all_filters();

void toggle_all_filters(bool state);
bool toggle_all_get_state();

void set_state(bool state);
static void register_dvars();

Expand Down
10 changes: 5 additions & 5 deletions src/components/modules/renderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2141,17 +2141,17 @@ namespace components
{
if (!dvars::r_draw_bsp->current.enabled)
{
game::printf_to_console("[Reflections] Turning on bsp view ...");
command::execute("toggle_bsp_radiant");
game::printf_to_console("[Reflections] Turning on bsp view ...\n");
d3dbsp::toggle_radiant_bsp_view(true);
}

reflectionprobes::generate_reflections_for_bsp();
dvars::set_bool(dvars::r_reflectionprobe_generate, false);

if (dvars::bsp_show_bsp_after_compile->current.enabled)
// turn off bsp view if user doesnt want it on
if (!dvars::bsp_show_bsp_after_compile->current.enabled)
{
command::execute("toggle_bsp_radiant");
dvars::set_bool(dvars::r_draw_bsp, dvars::bsp_show_bsp_after_compile->current.enabled);
d3dbsp::toggle_radiant_bsp_view(false);
}

if (dvars::bsp_gen_fastfile_on_compile->current.enabled)
Expand Down
6 changes: 3 additions & 3 deletions src/ggui/camera.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ namespace ggui
, &toolbar_button_background_active
, &toolbar_button_size))
{
components::command::execute("toggle_bsp_radiant");
components::d3dbsp::toggle_radiant_bsp_view(!show_bsp_icon);

} ggui::rtt_handle_windowfocus_overlaywidget(this->rtt_get_hovered_state());
}
Expand All @@ -285,7 +285,7 @@ namespace ggui

static bool hov_toggle_world;

const auto gameview = components::gameview::p_this;
const auto gameview = components::gameview::get();
const bool tstate = gameview->get_all_geo_state() || gameview->get_all_ents_state() || gameview->get_all_triggers_state() || gameview->get_all_others_state();

if (tb->image_togglebutton("toggle_radiant_world"
Expand All @@ -297,7 +297,7 @@ namespace ggui
, &toolbar_button_background_active
, &toolbar_button_size))
{
components::command::execute("toggle_filter_all");
gameview->toggle_all_filters(!tstate);

} ggui::rtt_handle_windowfocus_overlaywidget(this->rtt_get_hovered_state());
}
Expand Down
6 changes: 3 additions & 3 deletions src/ggui/menubar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1006,14 +1006,14 @@ namespace ggui
dvars::set_bool(dvars::r_draw_bsp, !dvars::r_draw_bsp->current.enabled);
}

if (ImGui::MenuItem("Toggle d3dbsp/radiant", ggui::hotkey_dialog::get_hotkey_for_command("toggle_bsp_radiant").c_str()))
if (ImGui::MenuItem("Toggle d3dbsp/radiant", ggui::hotkey_dialog::get_hotkey_for_command("toggle_bsp_radiant").c_str(), dvars::r_draw_bsp->current.enabled))
{
components::command::execute("toggle_bsp_radiant");
components::d3dbsp::toggle_radiant_bsp_view(!dvars::r_draw_bsp->current.enabled);
}

if (ImGui::MenuItem("Draw Radiant World", ggui::hotkey_dialog::get_hotkey_for_command("toggle_filter_all").c_str(), !tstate))
{
components::command::execute("toggle_filter_all");
gameview->toggle_all_filters();
}

ImGui::EndDisabled();
Expand Down
5 changes: 3 additions & 2 deletions src/ggui/preferences.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -262,8 +262,6 @@ namespace ggui
ImGui::title_with_seperator("Toolbar");
ImGui::Checkbox("Draw FPS within the camera window", &dvars::gui_draw_fps->current.enabled);
ImGui::Checkbox("Default Open - Toolbar", &dvars::gui_camera_toolbar_defaultopen->current.enabled);
ImGui::Checkbox("Merge BSP/Radiant buttons", &dvars::gui_camera_toolbar_merge_bsp_buttons->current.enabled); TT(dvars::gui_camera_toolbar_merge_bsp_buttons->description);

});
}

Expand Down Expand Up @@ -399,6 +397,9 @@ namespace ggui
ImGui::DvarInt_External("Display aabb Trees", "r_showaabbtrees");
ImGui::DvarInt_External("Display portals", "r_showportals");

// -----------------
ImGui::title_with_seperator("Gui");
ImGui::Checkbox("Merge BSP/Radiant buttons (camera toolbar)", &dvars::gui_camera_toolbar_merge_bsp_buttons->current.enabled); TT(dvars::gui_camera_toolbar_merge_bsp_buttons->description);

// -----------------
ImGui::title_with_seperator("BSP Only");
Expand Down
5 changes: 2 additions & 3 deletions src/ggui/toolbox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1634,8 +1634,7 @@ namespace ggui
, &cam_toolbar_active_bg
, &toolbar_button_size))
{
components::command::execute("toggle_bsp_radiant");

components::d3dbsp::toggle_radiant_bsp_view(!dvars::r_draw_bsp->current.enabled);
}

maxs = ImVec2(mins.x + actual_button_size.x, mins.y + actual_button_size.y);
Expand Down Expand Up @@ -1678,7 +1677,7 @@ namespace ggui
, &cam_toolbar_active_bg
, &toolbar_button_size))
{
components::command::execute("toggle_filter_all");
gameview->toggle_all_filters(!tstate);
}

maxs = ImVec2(mins.x + actual_button_size.x, mins.y + actual_button_size.y);
Expand Down

0 comments on commit af157a1

Please sign in to comment.