From 431c7eab94dec487fd9919457897a99977a71046 Mon Sep 17 00:00:00 2001 From: xoxor4d <45299104+xoxor4d@users.noreply.github.com> Date: Sat, 6 Apr 2024 19:43:06 +0200 Subject: [PATCH] [rtx] refactor map settings (sun spawning, manual culling override) - add commandline arg `no_sun` (disable sun spawning via map settings) - add console command `mapsettings_get_defaults` (prints default map sun-settings in to the console) --- assets-remix/iw3xo/rtx/map_settings.ini | 60 +++--- src/components/modules/rtx/rtx.cpp | 45 +++- src/components/modules/rtx/rtx_gui.cpp | 30 +-- .../modules/rtx/rtx_map_settings.cpp | 200 +++++++++++++++--- .../modules/rtx/rtx_map_settings.hpp | 37 ++-- src/std_include.hpp | 2 + src/utils/utils.cpp | 11 + src/utils/utils.hpp | 2 + 8 files changed, 298 insertions(+), 89 deletions(-) diff --git a/assets-remix/iw3xo/rtx/map_settings.ini b/assets-remix/iw3xo/rtx/map_settings.ini index 11e4907..a594cdc 100644 --- a/assets-remix/iw3xo/rtx/map_settings.ini +++ b/assets-remix/iw3xo/rtx/map_settings.ini @@ -1,25 +1,35 @@ -// (0) mapname -// (1) skybox to use (rtx_gui::skysphere_get_name_for_variant) -// (2) distance at which fog reaches max value (can NOT be lower then 700) -// (3-4-5) r , g , b (0-255) -mp_backlot, 5, 4000, 240,200,200 -mp_bloc, 4, 8000, 200,200,200 -mp_bog, 3, 5000, 135, 81, 60 -mp_broadcast, 5, 8000, 200,200,200 -mp_carentan, 3, 4000, 180,160,220 -mp_cargoship, 3, 4000, 80, 120,160 -mp_citystreets, 5, 8000, 200,200,200 -mp_convoy, 0, 1600, 200,190,180 -mp_countdown, 5, 15000, 180,180,200 -mp_crash, 5, 5000, 200,200,160 -mp_crash_snow, 3, 4500, 200,200,240 -mp_creek, 0, 8000, 200,200,200 -mp_crossfire, 5, 5000, 200,200,200 -mp_farm, 4, 1800, 150,200,220 -mp_killhouse, 5, 8000, 210,200,205 -mp_overgrown, 0, 8000, 200,200,200 -mp_pipeline, 5, 8000, 200,200,200 -mp_shipment, 4, 8000, 200,200,200 -mp_showdown, 5, 8000, 200,200,200 -mp_strike, 5, 4000, 200,200,200 -mp_vacant, 0, 8000, 200,200,200 \ No newline at end of file +// (0) : mapname +// (1) : fog dist : distance at which fog reaches max value (can NOT be lower then 700) +// (2-3-4) : fog color : r , g , b (0-255) +// (5-6-7) : sun dir : x , y , z (angles of directional light [x=x] [y=-y+5] [z=z-45] .... x=(z=-45) y=y-5 z=x) +// (8-9-10) : sun color : r , g , b (0-255) +// (11) : sun intensity : color intensity scalar +// (12) : sky : sky index (0-8) +// +// mapname fog dist fog color sun direction sun color sun intensity sky +// ------------------------------------------------------------------------------------------------------------------ +mp_backlot, 4000, 240,200,200, -0.657,-0.308,-0.688, 255.0,234.6,224.4, 1.30, 5 +mp_bloc, 8000, 200,200,200, 0.321,-0.383,-0.866, 229.5,249.9,255.0, 0.90, 4 +mp_bog, 5000, 135, 81, 60, 0.362,0.853,-0.375, 228.2,241.6,255.0, 0.80, 3 +mp_broadcast, 8000, 200,200,200, -0.163,-0.925,-0.342, 255.0,216.8,170.9, 1.40, 5 +mp_carentan, 4000, 180,160,220, -0.855,-0.060,-0.515, 204.0,229.5,255.0, 0.75, 3 +mp_cargoship, 4000, 80, 120,160, -0.641,0.641,-0.423, 127.5,153.0,255.0, 1.30, 7 +mp_citystreets, 8000, 200,200,200, 0.048,-0.388,-0.921, 255.0,234.6,224.4, 0.78, 5 +mp_convoy, 1600, 200,190,180, -0.814,-0.296,-0.500, 255.0,228.0,159.0, 1.60, 5 +mp_countdown, 15000, 180,180,200, -0.866,-0.000,-0.500, 255.0,204.0,153.0, 1.50, 5 +mp_crash, 5000, 200,200,160, 0.321,0.557,-0.766, 255.0,234.6,224.4, 1.30, 5 +mp_crash_snow, 4500, 200,200,240, 0.321,-0.383,-0.866, 165.8,178.5,255.0, 0.25, 3 +mp_creek, 8000, 200,200,200, 0.685,0.367,-0.814, 254.6,255.0,249.0, 1.80, 0 +mp_crossfire, 5000, 200,200,200, 0.462,-0.447,-0.766, 255.0,234.6,224.4, 1.00, 5 +mp_farm, 1800, 150,200,220, 0.542,0.542,-0.643, 229.5,249.9,255.0, 1.00, 4 +mp_killhouse, 8000, 210,200,205, -0.262,0.720,-0.643, 255.0,242.2,204.0, 1.50, 5 +mp_overgrown, 20000, 200,200,200, -0.407,0.734,-0.545, 255.0,245.9,176.1, 1.10, 4 +mp_pipeline, 8000, 200,200,200, 0.551,0.462,-0.695, 229.5,249.9,255.0, 1.15, 5 +mp_shipment, 8000, 200,200,200, -0.455,-0.572,-0.682, 255.0,255.0,242.2, 1.30, 4 +mp_showdown, 8000, 200,200,200, 0.389,-0.739,-0.550, 255.0,228.0,159.0, 1.60, 5 +mp_strike, 4000, 200,200,200, 0.572,0.416,-0.707, 255.0,239.7,204.0, 1.00, 5 +mp_vacant, 8000, 200,200,200, -0.641,-0.299,-0.707, 255.0,245.9,176.1, 1.30, 0 +mp_mw3_hardhat, 2600, 200,200,200, 0.406,0.406,-0.819, 254.6,255.0,249.0, 1.50, 5 + +#CULL // [X: CELL to tweak](indices of cells always rendered when in X) -> display cell indices using dvar 'r_showCellIndex' +mp_backlot, [1](0 2), [2](1), [3](0), [4](0), [7](0 6 9 10), [9](0 10), [10](0), [11](0), [12](0), [14](0 11 16), [34](0 22 32) diff --git a/src/components/modules/rtx/rtx.cpp b/src/components/modules/rtx/rtx.cpp index 23c815d..6df27a4 100644 --- a/src/components/modules/rtx/rtx.cpp +++ b/src/components/modules/rtx/rtx.cpp @@ -48,12 +48,40 @@ namespace components if (!flags::has_flag("no_fog")) { + const auto s = rtx_map_settings::settings(); const float fog_start = 1.0f; + dev->SetRenderState(D3DRS_FOGENABLE, TRUE); - dev->SetRenderState(D3DRS_FOGCOLOR, rtx_map_settings::m_color.packed); + dev->SetRenderState(D3DRS_FOGCOLOR, s->fog_color.packed); dev->SetRenderState(D3DRS_FOGVERTEXMODE, D3DFOG_LINEAR); dev->SetRenderState(D3DRS_FOGSTART, *(DWORD*)(&fog_start)); - dev->SetRenderState(D3DRS_FOGEND, *(DWORD*)(&rtx_map_settings::m_max_distance)); + dev->SetRenderState(D3DRS_FOGEND, *(DWORD*)(&s->fog_distance)); + } + + if (!flags::has_flag("no_sun")) + { + // only set sun if debuglight 0 is not active + if (const auto l0 = &rtx_lights::rtx_debug_lights[0]; !l0->enable) + { + const auto s = rtx_map_settings::settings(); + + D3DLIGHT9 light = {}; + light.Type = D3DLIGHT_DIRECTIONAL; + light.Diffuse.r = s->sun_color[0] * s->sun_intensity; + light.Diffuse.g = s->sun_color[1] * s->sun_intensity; + light.Diffuse.b = s->sun_color[2] * s->sun_intensity; + + D3DXVec3Normalize((D3DXVECTOR3*)&light.Direction, (const D3DXVECTOR3*)&s->sun_direction); + + dev->SetLight(0, &light); + dev->LightEnable(0, TRUE); + + // update gui settings for debug light 0 + l0->color_scale = s->sun_intensity; + l0->color[0] = s->sun_color[0]; l0->color[1] = s->sun_color[1]; l0->color[2] = s->sun_color[2]; + l0->dir[0] = s->sun_direction[0]; l0->dir[1] = s->sun_direction[1]; l0->dir[2] = s->sun_direction[2]; + l0->type = D3DLIGHT_DIRECTIONAL; + } } } @@ -637,7 +665,7 @@ namespace components // # // force cells defined in map_settings.ini - /*const auto& cell_settings = map_settings::settings()->cell_settings; + const auto& cell_settings = rtx_map_settings::settings()->cell_settings; if (!cell_settings.empty()) { for (const auto& c : cell_settings) @@ -646,19 +674,18 @@ namespace components { for (const auto& i : c.forced_cell_indices) { - const auto forced_cell = &game::sp::rgp->world->cells[i]; - const auto c_index = forced_cell - game::sp::rgp->world->cells; - game::sp::R_AddCellSurfacesAndCullGroupsInFrustumDelayed(forced_cell, dpvs->frustumPlanes, dpvs->frustumPlaneCount, dpvs->frustumPlaneCount); - dpvsGlob->cellVisibleBits[(c_index >> 5) + 3] |= (1 << (c_index & 0x1F)) & ~((1 << (c_index & 0x1F)) & dpvsGlob->cellForceInvisibleBits[(c_index >> 5) + 3]); + const auto forced_cell = &game::rgp->world->cells[i]; + const auto c_index = forced_cell - game::rgp->world->cells; + game::R_AddCellSurfacesAndCullGroupsInFrustumDelayed(forced_cell, dpvs->frustumPlanes, dpvs->frustumPlaneCount, dpvs->frustumPlaneCount); + dpvsGlob->cellVisibleBits[(c_index >> 5) + 3] |= (1 << (c_index & 0x1F)); } break; } } - }*/ + } // R_VisitPortals - //utils::hook::call(0x6B3DA0)(cell, &dpvsGlob->nearPlane, dpvs->frustumPlanes, dpvs->frustumPlaneCount); game::R_VisitPortals(dpvs->frustumPlaneCount, cell, &dpvsGlob->viewPlane, dpvs->frustumPlanes); // viewplane here .. or is that the nearplane? } } diff --git a/src/components/modules/rtx/rtx_gui.cpp b/src/components/modules/rtx/rtx_gui.cpp index fb7104f..4e314b5 100644 --- a/src/components/modules/rtx/rtx_gui.cpp +++ b/src/components/modules/rtx/rtx_gui.cpp @@ -133,25 +133,25 @@ namespace components static float skygroup01_width = 0.0f; gui::center_horz_begin(skygroup01_width); { - if (ImGui::Button("Hill", ImVec2(BUTTON_WIDTH, 0))) + if (ImGui::Button("Hill [0]", ImVec2(BUTTON_WIDTH, 0))) { skysphere_spawn(SKY::CLEAR); } ImGui::SameLine(); - if (ImGui::Button("Desert", ImVec2(BUTTON_WIDTH, 0))) + if (ImGui::Button("Desert [1]", ImVec2(BUTTON_WIDTH, 0))) { skysphere_spawn(SKY::DESERT); } ImGui::SameLine(); - if (ImGui::Button("Night", ImVec2(BUTTON_WIDTH, 0))) + if (ImGui::Button("Night [3]", ImVec2(BUTTON_WIDTH, 0))) { skysphere_spawn(SKY::NIGHT); } ImGui::SameLine(); - if (ImGui::Button("Night 2", ImVec2(BUTTON_WIDTH, 0))) + if (ImGui::Button("Night 2 [7]", ImVec2(BUTTON_WIDTH, 0))) { skysphere_spawn(SKY::NIGHT2); } @@ -162,25 +162,25 @@ namespace components static float skygroup02_width = 0.0f; gui::center_horz_begin(skygroup02_width); { - if (ImGui::Button("Overcast", ImVec2(BUTTON_WIDTH, 0))) + if (ImGui::Button("Overcast [4]", ImVec2(BUTTON_WIDTH, 0))) { skysphere_spawn(SKY::OVERCAST); } ImGui::SameLine(); - if (ImGui::Button("Sunset", ImVec2(BUTTON_WIDTH, 0))) + if (ImGui::Button("Sunset [5]", ImVec2(BUTTON_WIDTH, 0))) { skysphere_spawn(SKY::SUNSET); } ImGui::SameLine(); - if (ImGui::Button("Galaxy 1", ImVec2(BUTTON_WIDTH, 0))) + if (ImGui::Button("Galaxy 1 [2]", ImVec2(BUTTON_WIDTH, 0))) { skysphere_spawn(SKY::GALAXY1); } ImGui::SameLine(); - if (ImGui::Button("Galaxy 2", ImVec2(BUTTON_WIDTH, 0))) + if (ImGui::Button("Galaxy 2 [6]", ImVec2(BUTTON_WIDTH, 0))) { skysphere_spawn(SKY::GALAXY2); } @@ -303,7 +303,7 @@ namespace components { ImGui::PushID(i); - if (ImGui::CollapsingHeader(utils::va("Light %d", i), !i ? ImGuiTreeNodeFlags_DefaultOpen : ImGuiTreeNodeFlags_None)) + if (ImGui::CollapsingHeader(!i ? "Light 0 - usually used as sun" : utils::va("Light %d", i), !i ? ImGuiTreeNodeFlags_DefaultOpen : ImGuiTreeNodeFlags_None)) { bool on_edit = false; @@ -414,7 +414,7 @@ namespace components if (rtx_lights::rtx_debug_lights[i].type > D3DLIGHT_POINT) { - on_edit = ImGui::DragFloat3("Direction", rtx_lights::rtx_debug_lights[i].dir, 0.05f) ? true : on_edit; + on_edit = ImGui::DragFloat3("Direction", rtx_lights::rtx_debug_lights[i].dir, 0.001f) ? true : on_edit; if (rtx_lights::rtx_debug_lights[i].attach_to_head) { @@ -426,15 +426,15 @@ namespace components { if (rtx_lights::rtx_debug_lights[i].type == D3DLIGHT_SPOT) { - on_edit = ImGui::DragFloat("Inner Angle", &rtx_lights::rtx_debug_lights[i].inner_angle, 0.25f) ? true : on_edit; - on_edit = ImGui::DragFloat("Outer Angle", &rtx_lights::rtx_debug_lights[i].outer_angle, 0.25f) ? true : on_edit; + on_edit = ImGui::DragFloat("Inner Angle", &rtx_lights::rtx_debug_lights[i].inner_angle, 0.05f) ? true : on_edit; + on_edit = ImGui::DragFloat("Outer Angle", &rtx_lights::rtx_debug_lights[i].outer_angle, 0.05f) ? true : on_edit; } - on_edit = ImGui::DragFloat("Range", &rtx_lights::rtx_debug_lights[i].range, 0.25f) ? true : on_edit; + on_edit = ImGui::DragFloat("Range", &rtx_lights::rtx_debug_lights[i].range, 0.10f) ? true : on_edit; } - on_edit = ImGui::ColorEdit3("Color", rtx_lights::rtx_debug_lights[i].color, ImGuiColorEditFlags_Float) ? true : on_edit; - on_edit = ImGui::DragFloat("Color Scale", &rtx_lights::rtx_debug_lights[i].color_scale, 0.1f) ? true : on_edit; + on_edit = ImGui::ColorEdit3("Color", rtx_lights::rtx_debug_lights[i].color, ImGuiColorEditFlags_RGB) ? true : on_edit; + on_edit = ImGui::DragFloat("Color Scale", &rtx_lights::rtx_debug_lights[i].color_scale, 0.005f) ? true : on_edit; if (rtx_lights::rtx_debug_lights[i].type != D3DLIGHT_DIRECTIONAL) { diff --git a/src/components/modules/rtx/rtx_map_settings.cpp b/src/components/modules/rtx/rtx_map_settings.cpp index 8710175..68feb42 100644 --- a/src/components/modules/rtx/rtx_map_settings.cpp +++ b/src/components/modules/rtx/rtx_map_settings.cpp @@ -2,11 +2,20 @@ namespace components { - rtx_map_settings* rtx_map_settings::p_this = nullptr; - rtx_map_settings* rtx_map_settings::get() { return p_this; } + constexpr auto INI_MAPNAME_ARG = 0; + constexpr auto INI_FOG_DIST = 1; + constexpr auto INI_FOG_COLOR_BEGIN = 2; + constexpr auto INI_SUN_DIR_BEGIN = 5; + constexpr auto INI_SUN_COLOR_BEGIN = 8; + constexpr auto INI_SUN_INTENSITY = 11; + constexpr auto INI_SKY_INDEX = 12; + constexpr auto INI_ARGS_TOTAL = 13; + void rtx_map_settings::set_settings_for_loaded_map(bool reload_settings) { + DEBUG_PRINT("[DEBUG] # Function: map_settings::set_settings_for_loaded_map()\n"); + if ((m_settings.empty() || reload_settings) && !rtx_map_settings::load_settings()) { return; @@ -24,11 +33,12 @@ namespace components { if (s.mapname == map_name) { - m_max_distance = s.max_distance; - m_color = s.m_color; + m_loaded_map_settings = s; - rtx_gui::skysphere_spawn(s.skybox); + // 0-255 to 0-1 range + utils::vector::scale3(m_loaded_map_settings.sun_color, (1.0f / 255.0f), m_loaded_map_settings.sun_color); + rtx_gui::skysphere_spawn(s.sky_index); found = true; break; } @@ -36,24 +46,136 @@ namespace components if (!found) { - m_max_distance = 5000.0f; - m_color.packed = D3DCOLOR_XRGB(200, 200, 220); + // grab map defaults + if (game::gfx_world) + { + game::vec3_t sun_fwd = {}; + utils::vector::angle_vectors(game::gfx_world->sunParse.angles, sun_fwd, nullptr, nullptr); + utils::vector::scale3(sun_fwd, -1.0f, sun_fwd); + utils::vector::copy(sun_fwd, m_loaded_map_settings.sun_direction, 3); + + utils::vector::copy(game::gfx_world->sunParse.sunColor, m_loaded_map_settings.sun_color, 3); + m_loaded_map_settings.sun_intensity = game::gfx_world->sunParse.sunLight; + } if (!flags::has_flag("no_default_sky") && !rtx_gui::skysphere_is_valid()) { - rtx_gui::skysphere_spawn(rtx_gui::SKY::SUNSET); // always spawn sunset + rtx_gui::skysphere_spawn(rtx_gui::SKY::SUNSET); } } } } - constexpr auto INI_MAPNAME_ARG = 0; - constexpr auto INI_SKYBOX_ARG = 1; - constexpr auto INI_FOG_MAX_ARG = 2; - constexpr auto INI_FOG_COLOR_ARG_BEGIN = 3; + void rtx_map_settings::parse_culling() + { + // check if there are map settings + bool map_settings_exist = false; + map_settings_s* s = nullptr; + + // check if map settings exist + for (auto& e : m_settings) + { + if (e.mapname._Equal(m_args[INI_MAPNAME_ARG])) + { + s = &e; + map_settings_exist = true; + break; + } + } + + // create defaults if not + if (!map_settings_exist) + { + m_settings.push_back(map_settings_s(m_args[INI_MAPNAME_ARG])); + s = &m_settings.back(); + } + + if (s) + { + // for each cell with its forced indices with format -> [cell](index index index) + for (auto a = 1u; a < m_args.size(); a++) + { + const auto& str = m_args[a]; + + if (str.empty()) + { + // print msg here + continue; + } + + // which cell are we writing settings for? + const auto cell_index = utils::try_stoi(utils::split_string_between_delims(str, '[', ']'), -1); + if (cell_index != -1) + { + // check for duplicate cells + bool ignore_current_cell = false; + for (const auto& c : s->cell_settings) + { + if (cell_index == c.cell_index) + { + ignore_current_cell = true; + break; + } + } + + // cell has been added already + if (ignore_current_cell) + { + // print msg here + continue; + } + + // get inidices + const auto indices_str = utils::split_string_between_delims(str, '(', ')'); + const auto split_indices = utils::split(indices_str, ' '); + + s->cell_settings.push_back(cell_settings_s(cell_index)); + const auto c = &s->cell_settings.back(); + + // for each forced index + for (const auto& i : split_indices) + { + c->forced_cell_indices.push_back(utils::try_stoi(i, -1)); + } + } + } + } + } + + void rtx_map_settings::parse_settings() + { + if (m_args.size() == INI_ARGS_TOTAL) + { + m_settings.push_back( + { + m_args[INI_MAPNAME_ARG], + utils::try_stof(m_args[INI_FOG_DIST], 5000.0f), + D3DCOLOR_XRGB + ( + utils::try_stoi(m_args[INI_FOG_COLOR_BEGIN + 0], 255), + utils::try_stoi(m_args[INI_FOG_COLOR_BEGIN + 1], 255), + utils::try_stoi(m_args[INI_FOG_COLOR_BEGIN + 2], 255) + ), + { + utils::try_stof(m_args[INI_SUN_DIR_BEGIN + 0], 75.0f), + utils::try_stof(m_args[INI_SUN_DIR_BEGIN + 1], -15.0f), + utils::try_stof(m_args[INI_SUN_DIR_BEGIN + 2], -35.0f) + }, + { + utils::try_stof(m_args[INI_SUN_COLOR_BEGIN + 0], 255), + utils::try_stof(m_args[INI_SUN_COLOR_BEGIN + 1], 255), + utils::try_stof(m_args[INI_SUN_COLOR_BEGIN + 2], 255) + }, + utils::try_stof(m_args[INI_SUN_INTENSITY], 1.0f), + utils::try_stoi(m_args[INI_SKY_INDEX], 2) + }); + } + } bool rtx_map_settings::load_settings() { + DEBUG_PRINT("[DEBUG] # Function: map_settings::load_settings()\n"); + m_settings.clear(); m_settings.reserve(32); @@ -61,7 +183,7 @@ namespace components if (utils::fs::open_file_homepath("iw3xo\\rtx", "map_settings.ini", false, file)) { std::string input; - std::vector args; + bool reading_cull_settings = false; // read line by line while (std::getline(file, input)) @@ -72,23 +194,22 @@ namespace components continue; } + if (!reading_cull_settings && utils::starts_with(input, "#CULL")) + { + reading_cull_settings = true; + continue; + } + // split string on ',' - args = utils::split(input, ','); + m_args = utils::split(input, ','); - if (args.size() == INI_FOG_COLOR_ARG_BEGIN+3) // fog colors rgb are last + if (reading_cull_settings) { - const DWORD color = D3DCOLOR_XRGB( - utils::try_stoi(args[INI_FOG_COLOR_ARG_BEGIN+0], 255), - utils::try_stoi(args[INI_FOG_COLOR_ARG_BEGIN+1], 255), - utils::try_stoi(args[INI_FOG_COLOR_ARG_BEGIN+2], 255)); - - m_settings.push_back( - { - args[INI_MAPNAME_ARG], - utils::try_stoi(args[INI_SKYBOX_ARG], 0), - utils::try_stof(args[INI_FOG_MAX_ARG], 5000.0f), - color - }); + parse_culling(); + } + else + { + parse_settings(); } } @@ -101,9 +222,32 @@ namespace components rtx_map_settings::rtx_map_settings() { - command::add("mapsettings_update", [this](command::params) + command::add("mapsettings_update", "", "reloads the map_settings.ini file in root/iw3xo/rtx", [this](const command::params&) { rtx_map_settings::set_settings_for_loaded_map(true); }); + + command::add("mapsettings_get_defaults", "", "get sun direction, color and intensity in map_settings format based on the stock map settings", [this](const command::params&) + { + if (game::gfx_world) + { + game::vec3_t sun_fwd = {}; + utils::vector::angle_vectors(game::gfx_world->sunParse.angles, sun_fwd, nullptr, nullptr); + utils::vector::scale3(sun_fwd, -1.0f, sun_fwd); + + game::vec3_t sun_color = {}; + utils::vector::scale3(game::gfx_world->sunParse.sunColor, 255.0f, sun_color); + + const auto str = utils::va("SunDir - SunColor - SunIntensity [%.3f,%.3f,%.3f, %.1f,%.1f,%.1f, %.2f]\n", + sun_fwd[0], sun_fwd[1], sun_fwd[2], sun_color[0], sun_color[1], sun_color[2], game::gfx_world->sunParse.sunLight); + + game::Com_PrintMessage(0, str, 0); + DEBUG_PRINT(str); + } + else + { + game::Com_PrintMessage(0, "No map loaded ..", 0); + } + }); } } \ No newline at end of file diff --git a/src/components/modules/rtx/rtx_map_settings.hpp b/src/components/modules/rtx/rtx_map_settings.hpp index 9259646..1ccc0af 100644 --- a/src/components/modules/rtx/rtx_map_settings.hpp +++ b/src/components/modules/rtx/rtx_map_settings.hpp @@ -9,24 +9,37 @@ namespace components ~rtx_map_settings() = default; const char* get_name() override { return "rtx_map_settings"; } - static rtx_map_settings* p_this; - static rtx_map_settings* get(); + static inline rtx_map_settings* p_this = nullptr; + static rtx_map_settings* get() { return p_this; } - static inline float m_max_distance = 5000.0f; - static inline game::GfxColor m_color = { 0x00FFFFFF }; + struct cell_settings_s + { + int cell_index = -1; + std::vector forced_cell_indices; + }; + struct map_settings_s + { + std::string mapname; + float fog_distance = 5000.0f; + game::GfxColor fog_color = { 0x00FFFFFF }; + game::vec3_t sun_direction = { 75.0f, -15.0f, -35.0f }; + game::vec3_t sun_color = { 255.0f, 255.0f, 255.0f }; + float sun_intensity = 1.0f; + int sky_index = rtx_gui::SKY::SUNSET; + std::vector cell_settings; + }; + + static inline const map_settings_s* settings() { return &m_loaded_map_settings; } void set_settings_for_loaded_map(bool reload_settings = false); private: - struct settings_s - { - std::string mapname; - int skybox; - float max_distance = 5000.0f; - game::GfxColor m_color = { 0x00FFFFFF }; - }; + static inline map_settings_s m_loaded_map_settings = {}; + static inline std::vector m_settings; + static inline std::vector m_args; - static inline std::vector m_settings; + void parse_culling(); + void parse_settings(); bool load_settings(); }; } diff --git a/src/std_include.hpp b/src/std_include.hpp index f3e07eb..ae842f4 100644 --- a/src/std_include.hpp +++ b/src/std_include.hpp @@ -69,6 +69,8 @@ #define STATIC_ASSERT_SIZE(struct, size) static_assert(sizeof(struct) == size, "Size check") #define STATIC_ASSERT_OFFSET(struct, member, offset) static_assert(offsetof(struct, member) == offset, "Offset check") +#define DEBUG_PRINT(_MSG) if constexpr (DEBUG) { OutputDebugStringA(_MSG); } //{ game::Com_PrintMessage(0, _MSG, 0); } + #include #include #include diff --git a/src/utils/utils.cpp b/src/utils/utils.cpp index dec5670..81dc94a 100644 --- a/src/utils/utils.cpp +++ b/src/utils/utils.cpp @@ -110,6 +110,17 @@ namespace utils return ret; } + std::string split_string_between_delims(const std::string& str, const char delim_start, const char delim_end) + { + const auto first = str.find_last_of(delim_start); + if (first == std::string::npos) return ""; + + const auto last = str.find_first_of(delim_end, first); + if (last == std::string::npos) return ""; + + return str.substr(first + 1, last - first - 1); + }; + int q_strncasecmp(char *s1, char *s2, int n) { int c1, c2; diff --git a/src/utils/utils.hpp b/src/utils/utils.hpp index e86c6a1..85c0550 100644 --- a/src/utils/utils.hpp +++ b/src/utils/utils.hpp @@ -16,6 +16,8 @@ namespace utils int try_stoi(const std::string& str, const int& default_return_val = 0); float try_stof(const std::string& str, const float& default_return_val = 0.0f); + std::string split_string_between_delims(const std::string& str, const char delim_start, const char delim_end); + static std::vector split(const std::string& raw_input, const std::vector& delims) { std::vector strings;