Skip to content

Commit

Permalink
Show enemy silhouettes in Spectator and demos.
Browse files Browse the repository at this point in the history
  • Loading branch information
geneotech committed Feb 16, 2024
1 parent 7a1e1c3 commit 2638ba8
Show file tree
Hide file tree
Showing 14 changed files with 91 additions and 5 deletions.
1 change: 1 addition & 0 deletions src/application/gui/client/demo_player_gui.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ struct demo_player_gui : standard_window_mixin<demo_player_gui> {
using base::base;
using introspect_base = base;

bool draw_enemy_silhouettes = true;
bool show_spectator_overlay = true;
bool pending_interpolation_snap = false;
bool pending_dump = false;
Expand Down
1 change: 1 addition & 0 deletions src/application/gui/client/demo_player_gui.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ inline void demo_player_gui::perform(
}

checkbox("Show spectator overlay", show_spectator_overlay);
checkbox("Draw enemy silhouettes", draw_enemy_silhouettes);
text("POV:"); ImGui::SameLine();

if (enum_radio(shown_arena_type, true)) {
Expand Down
2 changes: 2 additions & 0 deletions src/application/gui/settings_gui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1136,6 +1136,8 @@ void settings_gui_state::perform(
if (auto node = scoped_tree_node("HUD")) {
revertable_checkbox("Cinematic mode", config.drawing.cinematic_mode);

revertable_checkbox("Draw enemy silhouettes in Spectator", config.drawing.draw_enemy_silhouettes_in_spectator);

revertable_checkbox(SCOPE_CFG_NVP(draw_inventory));
revertable_checkbox(SCOPE_CFG_NVP(draw_hotbar));

Expand Down
14 changes: 14 additions & 0 deletions src/application/setups/client/client_setup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -746,6 +746,8 @@ void client_setup::customize_for_viewing(config_lua_table& config) const {

if (is_replaying()) {
config.arena_mode_gui.show_spectator_overlay = demo_player.gui.show_spectator_overlay;
config.drawing.draw_enemy_silhouettes_in_spectator = demo_player.gui.draw_enemy_silhouettes;

config.client.spectated_arena_type = demo_player.gui.shown_arena_type;

if (is_paused()) {
Expand Down Expand Up @@ -1784,3 +1786,15 @@ bool client_setup::would_abandon_match() const {
}
);
}

faction_type client_setup::get_assigned_faction() const {
return get_arena_handle(client_arena_type::PREDICTED).on_mode(
[&](const auto& mode) {
if (const auto p = mode.find(get_local_player_id())) {
return p->get_faction();
}

return faction_type::COUNT;
}
);
}
2 changes: 2 additions & 0 deletions src/application/setups/client/client_setup.h
Original file line number Diff line number Diff line change
Expand Up @@ -865,4 +865,6 @@ class client_setup :

bool is_ranked_live_or_starting() const;
bool would_abandon_match() const;

faction_type get_assigned_faction() const;
};
12 changes: 12 additions & 0 deletions src/application/setups/server/server_setup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3745,6 +3745,18 @@ bool server_setup::has_assigned_teams() const {
return !assigned_teams.id_to_faction.empty();
}

faction_type server_setup::get_assigned_faction() const {
return get_arena_handle().on_mode(
[&](const auto& mode) {
if (const auto p = mode.find(get_local_player_id())) {
return p->get_faction();
}

return faction_type::COUNT;
}
);
}

#include "augs/readwrite/to_bytes.h"

// TODO: rewrite unit tests to use streams since we're no longer using preserialized_message
Expand Down
2 changes: 2 additions & 0 deletions src/application/setups/server/server_setup.h
Original file line number Diff line number Diff line change
Expand Up @@ -642,6 +642,8 @@ class server_setup :
return get_integrated_player_id();
}

faction_type get_assigned_faction() const;

bool is_gameplay_on() const;

#if !HEADLESS
Expand Down
2 changes: 2 additions & 0 deletions src/augs/graphics/dedicated_buffers.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ namespace augs {
BORDERS_FRIENDLY_SENTIENCES,
BORDERS_ENEMY_SENTIENCES,

OCCLUDED_ENEMY_HIGHLIGHTS,

NEONS_FRIENDLY_SENTIENCES,
NEONS_ENEMY_SENTIENCES,

Expand Down
2 changes: 2 additions & 0 deletions src/view/game_drawing_settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ struct game_drawing_settings {
int snap_zoom_to_multiple_if_different_by_pixels = 10;
float custom_zoom = 1.0f;

bool draw_enemy_silhouettes_in_spectator = true;

bool draw_crosshairs = true;
bool draw_weapon_laser = true;
bool draw_aabb_highlighter = true;
Expand Down
30 changes: 26 additions & 4 deletions src/view/rendering_scripts/enqueue_illuminated_rendering_jobs.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ void enqueue_illuminated_rendering_jobs(
using D = augs::dedicated_buffer;
using DV = augs::dedicated_buffer_vector;

const bool draw_enemy_silhouettes = in.can_draw_enemy_silhouettes && in.drawing.draw_enemy_silhouettes_in_spectator;
const bool streamer_mode = in.streamer_mode;
const auto& necessarys = in.necessary_images;

Expand Down Expand Up @@ -81,7 +82,7 @@ void enqueue_illuminated_rendering_jobs(
return augs::line_drawer_with_default { dedicated[d].lines, necessarys.at(assets::necessary_image_id::BLANK) };
};

auto sentience_hud_job = [&cosm, considered_fov, streamer_mode, cone, global_time_seconds, settings, &necessarys, &dedicated, queried_cone, &visible, viewed_character, &interp, &gui_font, indicator_meta, fog_of_war_effective, pre_step_crosshair_displacement, &damage_indication, damage_indication_settings]() {
auto sentience_hud_job = [draw_enemy_silhouettes, &cosm, considered_fov, streamer_mode, cone, global_time_seconds, settings, &necessarys, &dedicated, queried_cone, &visible, viewed_character, &interp, &gui_font, indicator_meta, fog_of_war_effective, pre_step_crosshair_displacement, &damage_indication, damage_indication_settings]() {
(void)fog_of_war_effective;
augs::constant_size_vector<requested_sentience_meter, 3> requested_meters;

Expand Down Expand Up @@ -148,7 +149,8 @@ void enqueue_illuminated_rendering_jobs(
pre_step_crosshair_displacement,
interp,
considered_fov,
settings.teammates_are_enemies
settings.teammates_are_enemies,
draw_enemy_silhouettes
);
};

Expand Down Expand Up @@ -520,7 +522,7 @@ void enqueue_illuminated_rendering_jobs(
}
};

auto sentiences_job = [ffa = settings.teammates_are_enemies, cast_highlight_tex, &cosm, fog_of_war_character_id, make_drawing_input, &visible, &interp, global_time_seconds]() {
auto sentiences_job = [draw_enemy_silhouettes, ffa = settings.teammates_are_enemies, cast_highlight_tex, &cosm, fog_of_war_character_id, make_drawing_input, &visible, &interp, global_time_seconds]() {
auto draw_lights_for = [&](const auto& drawing_in, const auto& handle) {
::specific_draw_neon_map(handle, drawing_in);
::draw_character_glow(
Expand All @@ -540,12 +542,28 @@ void enqueue_illuminated_rendering_jobs(
return typed_handle.template get<components::sentience>().find_low_health_border(timestamp_ms);
};

auto occluded_highlight_provider = [](const auto& typed_handle) -> std::optional<rgba> {
switch (typed_handle.get_official_faction()) {
case faction_type::RESISTANCE:
return orange;
case faction_type::METROPOLIS:
return cyan;
case faction_type::ATLANTIS:
return green;

default:
return std::nullopt;
}
};

const auto friendly_drawing_in = make_drawing_input(D::FRIENDLY_SENTIENCES);
const auto enemy_drawing_in = make_drawing_input(D::ENEMY_SENTIENCES);

const auto borders_friendly_drawing_in = make_drawing_input(D::BORDERS_FRIENDLY_SENTIENCES);
const auto borders_enemy_drawing_in = make_drawing_input(D::BORDERS_ENEMY_SENTIENCES);

const auto occluded_enemy_highlights_in = make_drawing_input(D::OCCLUDED_ENEMY_HIGHLIGHTS);

const auto neons_friendly_drawing_in = make_drawing_input(D::NEONS_FRIENDLY_SENTIENCES);
const auto neons_enemy_drawing_in = make_drawing_input(D::NEONS_ENEMY_SENTIENCES);

Expand All @@ -564,7 +582,7 @@ void enqueue_illuminated_rendering_jobs(
return modified_input;
};

if (is_local || (!ffa && typed_handle.get_official_faction() == fow_faction)) {
if (const bool visible_in_fow = is_local || (!ffa && typed_handle.get_official_faction() == fow_faction)) {
draw_lights_for(neons_friendly_drawing_in, typed_handle);

::specific_draw_color_highlight(typed_handle, SHADOW_COLOR, friendly_drawing_in, shadow_input_customizer);
Expand All @@ -577,6 +595,10 @@ void enqueue_illuminated_rendering_jobs(
::specific_draw_color_highlight(typed_handle, SHADOW_COLOR, enemy_drawing_in, shadow_input_customizer);
::specific_draw_entity(typed_handle, enemy_drawing_in);
::specific_draw_border(typed_handle, borders_enemy_drawing_in, standard_border_provider);

if (draw_enemy_silhouettes) {
::specific_draw_border(typed_handle, occluded_enemy_highlights_in, occluded_highlight_provider);
}
}
});
});
Expand Down
1 change: 1 addition & 0 deletions src/view/rendering_scripts/illuminated_rendering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,7 @@ void illuminated_rendering(const illuminated_rendering_input in) {
renderer.call_triangles(D::BORDERS_ENEMY_SENTIENCES);
renderer.set_stencil(false);

renderer.call_triangles(D::OCCLUDED_ENEMY_HIGHLIGHTS);
renderer.call_triangles(D::BORDERS_FRIENDLY_SENTIENCES);
}
else {
Expand Down
1 change: 1 addition & 0 deletions src/view/rendering_scripts/illuminated_rendering.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ struct illuminated_rendering_input {
const vec2 pre_step_crosshair_displacement;
const audiovisual_state& audiovisuals;
const game_drawing_settings drawing;
const bool can_draw_enemy_silhouettes;
const necessary_images_in_atlas_map& necessary_images;
const all_loaded_gui_fonts& fonts;
const images_in_atlas_map& game_images;
Expand Down
7 changes: 6 additions & 1 deletion src/view/rendering_scripts/is_reasonably_in_view.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ bool is_reasonably_in_view(
const vec2 pre_step_crosshair_displacement,
const interpolation_system& interp,
const fog_of_war_settings considered_fow,
const bool teammates_are_enemies
const bool teammates_are_enemies,
const bool skip_occlusion_check = false
) {
const auto fow_angle = considered_fow.angle;
const auto viewed_character_transform = viewed_character ? viewed_character.find_viewing_transform(interp) : std::optional<transformr>();
Expand All @@ -33,6 +34,10 @@ bool is_reasonably_in_view(
return false;
}

if (skip_occlusion_check) {
return true;
}

auto look_dir = calc_crosshair_displacement(viewed_character) + pre_step_crosshair_displacement;

if (look_dir.is_zero()) {
Expand Down
19 changes: 19 additions & 0 deletions src/work.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2308,6 +2308,24 @@ work_result work(
return result;
};

auto can_show_enemy_silhouettes = [&]() {
if (is_replaying_demo()) {
return true;
}

bool result = false;

on_specific_setup([&](client_setup& setup) {
result = setup.get_assigned_faction() == faction_type::SPECTATOR;
});

on_specific_setup([&](server_setup& setup) {
result = setup.get_assigned_faction() == faction_type::SPECTATOR;
});

return result;
};

augs::timer ad_hoc_animation_timer;

auto perform_setup_custom_imgui = [&]() {
Expand Down Expand Up @@ -4168,6 +4186,7 @@ work_result work(
calc_pre_step_crosshair_displacement(viewing_config),
get_audiovisuals(),
viewing_config.drawing,
can_show_enemy_silhouettes(),
streaming.necessary_images_in_atlas,
streaming.get_loaded_gui_fonts(),
streaming.images_in_atlas,
Expand Down

0 comments on commit 2638ba8

Please sign in to comment.