Skip to content

Commit

Permalink
Add detailed signal visualization
Browse files Browse the repository at this point in the history
-   Add toggle to crew6/science to show circular and numerical
    visualizations of radar signal values.
  • Loading branch information
oznogon committed Feb 2, 2020
1 parent 599667a commit 78d0f75
Show file tree
Hide file tree
Showing 4 changed files with 131 additions and 2 deletions.
117 changes: 115 additions & 2 deletions src/screenComponents/radarView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@
#include "targetsContainer.h"

GuiRadarView::GuiRadarView(GuiContainer* owner, string id, float distance, TargetsContainer* targets)
: GuiElement(owner, id), next_ghost_dot_update(0.0), targets(targets), missile_tube_controls(nullptr), distance(distance), long_range(false), show_ghost_dots(false)
, show_waypoints(false), show_target_projection(false), show_missile_tubes(false), show_callsigns(false), show_heading_indicators(false), show_game_master_data(false)
: GuiElement(owner, id), next_ghost_dot_update(0.0), targets(targets), missile_tube_controls(nullptr), distance(distance), long_range(false), show_ghost_dots(false), show_signal_details(false), show_waypoints(false), show_target_projection(false), show_missile_tubes(false), show_callsigns(false), show_heading_indicators(false), show_game_master_data(false)
, range_indicator_step_size(0.0f), style(Circular), fog_style(NoFogOfWar), mouse_down_func(nullptr), mouse_drag_func(nullptr), mouse_up_func(nullptr)
{
auto_center_on_my_ship = true;
Expand Down Expand Up @@ -74,6 +73,8 @@ void GuiRadarView::onDraw(sf::RenderTarget& window)
drawGhostDots(forground_texture);
}
drawObjects(forground_texture, background_texture);
if (show_signal_details)
drawSignalDetails(forground_texture, background_texture);
if (show_game_master_data)
drawObjectsGM(forground_texture);

Expand Down Expand Up @@ -597,6 +598,118 @@ void GuiRadarView::drawObjects(sf::RenderTarget& window_normal, sf::RenderTarget
}
}

void GuiRadarView::drawSignalDetails(sf::RenderTarget& window_normal, sf::RenderTarget& window_alpha)
{
sf::Vector2f radar_screen_center(rect.left + rect.width / 2.0f, rect.top + rect.height / 2.0f);
float scale = std::min(rect.width, rect.height) / 2.0f / distance;

foreach(SpaceObject, obj, space_object_list)
{
sf::Vector2f object_position_on_screen = radar_screen_center + (obj->getPosition() - view_position) * scale;

float r = obj->getRadius() * scale;

sf::FloatRect object_rect(object_position_on_screen.x - r, object_position_on_screen.y - r, r * 2, r * 2);
if (rect.intersects(object_rect))
{
RawRadarSignatureInfo info = obj->getRadarSignatureInfo();

// If the object is a SpaceShip, adjust the signature dynamically based
// on its current state and activity.
P<SpaceShip> this_ship = obj;

if (this_ship)
{
RawRadarSignatureInfo signature_delta;

// For each ship system ...
for(int n = 0; n < SYS_COUNT; n++)
{
ESystem this_system = static_cast<ESystem>(n);
// Increase the biological band based on system heat, offset by
// coolant.
signature_delta.biological += std::max(0.0f, std::min(1.0f, this_ship->getSystemHeat(this_system) - (this_ship->getSystemCoolant(this_system) / 10.0f)));
// Adjust the electrical band if system power allocation is not
// 100%.
if (this_system == SYS_JumpDrive && this_ship->jump_drive_charge < this_ship->jump_drive_max_distance)
{
// Elevate electrical after a jump, since recharging jump
// consumes energy.
signature_delta.electrical += std::max(0.0f, std::min(1.0f, this_ship->getSystemPower(this_system) * (this_ship->jump_drive_charge + 0.01f / this_ship->jump_drive_max_distance)));
}else if(this_ship->getSystemPower(this_system) != 1.0f){
signature_delta.electrical += std::max(-1.0f, std::min(1.0f, this_ship->getSystemPower(this_system) - 1.0f));
}
}

// Increase the gravitational band if the ship is about to jump, or
// is actively warping.
if (this_ship->jump_delay > 0.0f)
{
signature_delta.gravity += std::max(0.0f, std::min((1.0f / this_ship->jump_delay + 0.01f) + 0.25f, 10.0f));
}else if (this_ship->current_warp > 0.0f) {
signature_delta.gravity += this_ship->current_warp;
}

// Update the signature by adding the delta to its baseline.
info += signature_delta;
}
sf::RenderTarget* window = &window_normal;
if (!obj->canHideInNebula())
window = &window_alpha;

float gr = 2.0f + (r * info.gravity);
float er = 2.0f + (r * info.electrical);
float br = 2.0f + (r * info.biological);
// Gravitational
sf::CircleShape circle(gr, rand() % 5 + 10);
circle.setOutlineThickness(0.0);
circle.setOrigin(gr, gr);
circle.setPosition(object_position_on_screen);
circle.setFillColor(sf::Color(0,0,255,128));
window->draw(circle);
// Electrical
circle.setRadius(er);
circle.setOrigin(er, er);
circle.setPosition(object_position_on_screen);
circle.setFillColor(sf::Color(0,255,0,128));
window->draw(circle);
// Biological
circle.setRadius(br);
circle.setOrigin(br, br);
circle.setPosition(object_position_on_screen);
circle.setFillColor(sf::Color(255,0,0,128));
window->draw(circle);
// obj->drawOnGMRadar(window, object_position_on_screen, scale, long_range);
if (this_ship) {
drawText(*window,
sf::FloatRect(
object_position_on_screen.x + 15,
object_position_on_screen.y, 0, 0),
std::to_string(static_cast<int>(
info.gravity * this_ship->getRadius() * 10 + random(0, 5))),
ATopLeft, 15, bold_font, sf::Color(0, 0, 255, 255)
);
drawText(*window,
sf::FloatRect(
object_position_on_screen.x + 15,
object_position_on_screen.y + 15, 0, 0),
std::to_string(static_cast<int>(
info.electrical * this_ship->getRadius() * 10 + random(0, 5))),
ATopLeft, 15, bold_font, sf::Color(0, 255, 0, 255)
);
drawText(*window,
sf::FloatRect(
object_position_on_screen.x + 15,
object_position_on_screen.y + 30, 0, 0),
std::to_string(static_cast<int>(
info.biological * this_ship->getRadius() * 10 + random(0, 5))),
ATopLeft, 15, bold_font, sf::Color(255, 0, 0, 255)
);
}
}
}
}

void GuiRadarView::drawObjectsGM(sf::RenderTarget& window)
{
sf::Vector2f radar_screen_center(rect.left + rect.width / 2.0f, rect.top + rect.height / 2.0f);
Expand Down
5 changes: 5 additions & 0 deletions src/screenComponents/radarView.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ class GuiRadarView : public GuiElement
sf::Vector2f view_position;
bool long_range;
bool show_ghost_dots;
bool show_signal_details;
bool show_waypoints;
bool show_target_projection;
bool show_missile_tubes;
Expand Down Expand Up @@ -78,6 +79,9 @@ class GuiRadarView : public GuiElement
GuiRadarView* shortRange() { long_range = false; return this; }
GuiRadarView* enableGhostDots() { show_ghost_dots = true; return this; }
GuiRadarView* disableGhostDots() { show_ghost_dots = false; return this; }
bool areSignalDetailsEnabled() { return show_signal_details; }
GuiRadarView* enableSignalDetails() { show_signal_details = true; return this; }
GuiRadarView* disableSignalDetails() { show_signal_details = false; return this; }
GuiRadarView* enableWaypoints() { show_waypoints = true; return this; }
GuiRadarView* disableWaypoints() { show_waypoints = false; return this; }
GuiRadarView* enableTargetProjections(GuiMissileTubeControls* missile_tube_controls) { show_target_projection = true; this->missile_tube_controls = missile_tube_controls; return this; }
Expand Down Expand Up @@ -126,6 +130,7 @@ class GuiRadarView : public GuiElement
void drawTargets(sf::RenderTarget& window);
void drawHeadingIndicators(sf::RenderTarget& window);
void drawRadarCutoff(sf::RenderTarget& window);
void drawSignalDetails(sf::RenderTarget& window_normal, sf::RenderTarget& window_alpha);
};

#endif//RADAR_VIEW_H
10 changes: 10 additions & 0 deletions src/screens/crew6/scienceScreen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,16 @@ ScienceScreen::ScienceScreen(GuiContainer* owner, ECrewPosition crew_position)
zoom_label = new GuiLabel(zoom_slider, "", "Zoom: 1.0x", 30);
zoom_label->setSize(GuiElement::GuiSizeMax, GuiElement::GuiSizeMax);

// Radar signal details toggle.
signal_details_toggle = new GuiToggleButton(this, "SIGNAL_DETAILS_TOGGLE", "Signal Details", [this](bool value)
{
if (science_radar->areSignalDetailsEnabled())
science_radar->disableSignalDetails();
else
science_radar->enableSignalDetails();
});
signal_details_toggle->setPosition(-270, -20, ABottomRight)->setSize(250, 50);

// Radar/database view toggle.
view_mode_selection = new GuiListbox(this, "VIEW_SELECTION", [this](int index, string value) {
radar_view->setVisible(index == 0);
Expand Down
1 change: 1 addition & 0 deletions src/screens/crew6/scienceScreen.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ class ScienceScreen : public GuiOverlay
GuiFrequencyCurve* info_beam_frequency;
GuiKeyValueDisplay* info_system[SYS_COUNT];

GuiToggleButton* signal_details_toggle;
GuiToggleButton* probe_view_button;
P<ScanProbe> observation_point;
GuiListbox* view_mode_selection;
Expand Down

0 comments on commit 78d0f75

Please sign in to comment.