Skip to content

Commit

Permalink
[rtx] add map marker functionality (100 markers) - ff, iwd, conf ..
Browse files Browse the repository at this point in the history
  • Loading branch information
xoxor4d committed Apr 20, 2024
1 parent 2e3ddb7 commit b4d330b
Show file tree
Hide file tree
Showing 9 changed files with 163 additions and 41 deletions.
5 changes: 4 additions & 1 deletion assets-remix/iw3xo/rtx/map_settings.ini
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// (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)
// (5-6-7) : sun dir : x , y , z (angles of directional light)
// (8-9-10) : sun color : r , g , b (0-255)
// (11) : sun intensity : color intensity scalar
// (12) : sky : sky index (0-23) (rtx_gui.hpp)
Expand Down Expand Up @@ -34,3 +34,6 @@ mp_mw3_hardhat, 4600, 150,90,70, 0.406,0.406,-0.819, 254.6,255.0,249.0,
#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)
mp_showdown, [4](6 7)

#MARKER // [NUM](X Y Z), [NUM](X Y Z), ... (0-99)
mp_backlot, [0](-80 -540 170), [1](-160 40 340)
Binary file modified assets-remix/main/xcommon_rtx.iwd
Binary file not shown.
33 changes: 18 additions & 15 deletions assets-remix/rtx.conf

Large diffs are not rendered by default.

Binary file modified assets-remix/zone/english/xcommon_rtx.ff
Binary file not shown.
21 changes: 21 additions & 0 deletions src/components/modules/rtx/rtx_gui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -509,6 +509,27 @@ namespace components

ImGui::Indent(-8.0f); SPACING(0.0f, 12.0f);
}

if constexpr (DEBUG)
{
if (ImGui::CollapsingHeader("DEV", ImGuiTreeNodeFlags_None))
{
static game::FxEffect* marker_test = nullptr;
if (ImGui::Button("Spawn Marker FX"))
{
if (const auto fx = game::DB_FindXAssetHeader(game::XAssetType::ASSET_TYPE_FX, "rtx/markers/rtx_marker_backlot_01").fx; fx)
{
marker_test = game::FX_SpawnOrientedEffect(game::IDENTITY_AXIS[0], fx, 0, game::vec3_origin);
}
}

ImGui::SameLine();
if (ImGui::Button("Delete Marker FX"))
{
game::FX_KillEffect(marker_test);
}
}
}
}

// ---------------------------------------------------------------------
Expand Down
123 changes: 100 additions & 23 deletions src/components/modules/rtx/rtx_map_settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ namespace components
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");
Expand Down Expand Up @@ -39,6 +38,19 @@ namespace components
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);

// spawn map markers
for (auto i = 0u; i < s.map_markers.size(); i++)
{
if (s.map_markers[i].active)
{
if (const auto fx = game::DB_FindXAssetHeader(game::XAssetType::ASSET_TYPE_FX, utils::va("rtx/markers/rtx_marker_%02d", i)).fx; fx)
{
m_loaded_map_settings.map_markers[i].handle = game::FX_SpawnOrientedEffect(game::IDENTITY_AXIS[0], fx, 0, &s.map_markers[i].origin[0]);
}
}
}

found = true;
break;
}
Expand Down Expand Up @@ -66,31 +78,25 @@ namespace components
}
}

void rtx_map_settings::parse_culling()
rtx_map_settings::map_settings_s* rtx_map_settings::get_or_create_settings()
{
// 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;
return &e;
}
}

// create defaults if not
if (!map_settings_exist)
{
m_settings.push_back(map_settings_s(m_args[INI_MAPNAME_ARG]));
s = &m_settings.back();
}
m_settings.push_back(map_settings_s(m_args[INI_MAPNAME_ARG]));
return &m_settings.back();
}

if (s)
void rtx_map_settings::parse_culling()
{
if (map_settings_s* s = get_or_create_settings(); s)
{
s->cell_settings.clear();
s->cell_settings.resize(256);
Expand Down Expand Up @@ -151,6 +157,67 @@ namespace components
}
}

void rtx_map_settings::parse_markers()
{
if (map_settings_s* s = get_or_create_settings(); s)
{
// kill active fx in-case we reload settings
for (auto i = 0u; i < m_loaded_map_settings.map_markers.size(); i++)
{
if (m_loaded_map_settings.map_markers[i].active && m_loaded_map_settings.map_markers[i].handle)
{
game::FX_KillEffect(m_loaded_map_settings.map_markers[i].handle);
}
}

s->map_markers.clear();
s->map_markers.resize(100);

for (auto a = 1u; a < m_args.size(); a++)
{
const auto& str = m_args[a];

if (str.empty())
{
// print msg here
continue;
}

// which marker are we writing settings for?
const auto marker_index = utils::try_stoi(utils::split_string_between_delims(str, '[', ']'), -1);
if (marker_index >= 0)
{
// limit the vector to 100 entries
if (marker_index >= 100)
{
game::Com_PrintMessage(0, "[rtx] map-settings: found marker index override > 100. Skipping...\n", 0);
continue;
}

// get marker
const auto m = &s->map_markers[marker_index];

// ignore duplicate markers
if (m->active)
{
continue;
}

// get and assign origin
const auto origin_str = utils::split_string_between_delims(str, '(', ')');
if (const auto xyz = utils::split(origin_str, ' ');
xyz.size() == 3u)
{
m->origin[0] = utils::try_stof(xyz[0], 0.0f);
m->origin[1] = utils::try_stof(xyz[1], 0.0f);
m->origin[2] = utils::try_stof(xyz[2], 0.0f);
m->active = true;
}
}
}
}
}

void rtx_map_settings::parse_settings()
{
if (m_args.size() == INI_ARGS_TOTAL)
Expand Down Expand Up @@ -192,7 +259,7 @@ namespace components
if (utils::fs::open_file_homepath("iw3xo\\rtx", "map_settings.ini", false, file))
{
std::string input;
bool reading_cull_settings = false;
auto parse_mode = PARSE_MODE::SETTINGS;

// read line by line
while (std::getline(file, input))
Expand All @@ -203,22 +270,32 @@ namespace components
continue;
}

if (!reading_cull_settings && utils::starts_with(input, "#CULL"))
if (parse_mode == SETTINGS && utils::starts_with(input, "#CULL"))
{
parse_mode = CULL;
continue;
}

if (parse_mode == CULL && utils::starts_with(input, "#MARKER"))
{
reading_cull_settings = true;
parse_mode = MARKER;
continue;
}

// split string on ','
m_args = utils::split(input, ',');

if (reading_cull_settings)
{
parse_culling();
}
else
switch (parse_mode)
{
case SETTINGS:
parse_settings();
break;
case CULL:
parse_culling();
break;
case MARKER:
parse_markers();
break;
}
}

Expand Down
17 changes: 17 additions & 0 deletions src/components/modules/rtx/rtx_map_settings.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,27 @@ namespace components
static inline rtx_map_settings* p_this = nullptr;
static rtx_map_settings* get() { return p_this; }

enum PARSE_MODE : std::uint32_t
{
SETTINGS,
CULL,
MARKER
};

struct cell_settings_s
{
//int cell_index = -1;
std::vector<int> forced_cell_indices;
bool active = false;
};

struct marker_settings_s
{
float origin[3];
game::FxEffect* handle;
bool active = false;
};

struct map_settings_s
{
std::string mapname;
Expand All @@ -30,6 +44,7 @@ namespace components
int sky_index = rtx_gui::SKY::SUNSET;
std::vector<cell_settings_s> cell_settings;
bool cell_overrides_exist = false;
std::vector<marker_settings_s> map_markers;
};

static inline const map_settings_s* settings() { return &m_loaded_map_settings; }
Expand All @@ -40,7 +55,9 @@ namespace components
static inline std::vector<map_settings_s> m_settings;
static inline std::vector<std::string> m_args;

map_settings_s* get_or_create_settings();
void parse_culling();
void parse_markers();
void parse_settings();
bool load_settings();
};
Expand Down
2 changes: 1 addition & 1 deletion src/game/functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1701,7 +1701,7 @@ namespace game
}
}

game::FxEffect* FX_SpawnOrientedEffect(const float* axis /*edx*/, game::FxEffectDef* def, int msec_begin, float* origin)
game::FxEffect* FX_SpawnOrientedEffect(const float* axis /*edx*/, game::FxEffectDef* def, int msec_begin, const float* origin)
{
const static uint32_t func_addr = 0x4A14B0;
__asm
Expand Down
3 changes: 2 additions & 1 deletion src/game/functions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ namespace game
static inline float COLOR_GREEN[4] = { 0.0f, 1.0f, 0.0f, 1.0f };
static inline float COLOR_BLUE[4] = { 0.0f, 0.0f, 1.0f, 1.0f };
static inline float vec3_origin[3] = { 0.0f, 0.0f, 0.0f };
static inline float IDENTITY_AXIS[3][3] = { 1.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 1.0f };

extern game::TestLod g_testLods[4];

Expand Down Expand Up @@ -604,7 +605,7 @@ namespace game

void AxisToAngles(float* angles /*eax*/, const float(*axis)[3] /*ecx*/);

game::FxEffect* FX_SpawnOrientedEffect(const float* axis /*edx*/, game::FxEffectDef* def, int msec_begin, float* origin);
game::FxEffect* FX_SpawnOrientedEffect(const float* axis /*edx*/, game::FxEffectDef* def, int msec_begin, const float* origin);
void FX_KillEffect(game::FxEffect* def);

// *
Expand Down

0 comments on commit b4d330b

Please sign in to comment.