Skip to content
This repository has been archived by the owner on Oct 10, 2024. It is now read-only.

Commit

Permalink
first pass
Browse files Browse the repository at this point in the history
* still need to clear collections at round end / disconnect
* still need to add polyline optimizations
* still want to add rendertexture
  • Loading branch information
kotae4 committed Feb 12, 2022
1 parent a6be2d3 commit 43408bd
Show file tree
Hide file tree
Showing 11 changed files with 92 additions and 19 deletions.
10 changes: 5 additions & 5 deletions gui/console.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,13 @@ namespace ConsoleGui
ImGui::Separator();
ImGui::BeginChild("console#scroll", ImVec2(511, 270), true, ImGuiWindowFlags_AlwaysVerticalScrollbar);
for (int i = State.events.size() - 1; i >= 0; i--) {
if (State.events[i]->getType() == EVENT_WALK)
if (State.events[i].get()->getType() == EVENT_WALK)
continue;

bool typeFound = false, anyTypeFilterSelected = false;
for (int n = 0; n < ConsoleGui::event_filter.size(); n++) {
if (ConsoleGui::event_filter[n].second
&& (EVENT_TYPES)n == State.events[i]->getType()) {
&& (EVENT_TYPES)n == State.events[i].get()->getType()) {
typeFound = true;
anyTypeFilterSelected = true;
break;
Expand All @@ -79,7 +79,7 @@ namespace ConsoleGui
for (auto player : ConsoleGui::player_filter) {
if (player.second
&& player.first.has_value()
&& player.first.get_PlayerId() == State.events[i]->getSource().playerId)
&& player.first.get_PlayerId() == State.events[i].get()->getSource().playerId)
{
playerFound = true;
anyPlayerFilterSelected = true;
Expand All @@ -92,9 +92,9 @@ namespace ConsoleGui
if (!playerFound && anyPlayerFilterSelected)
continue;

State.events[i]->ColoredEventOutput();
State.events[i].get()->ColoredEventOutput();
ImGui::SameLine();
State.events[i]->Output();
State.events[i].get()->Output();
}
ImGui::EndChild();
ImGui::End();
Expand Down
32 changes: 23 additions & 9 deletions gui/replay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ namespace Replay
std::vector<std::pair<PlayerSelection, bool>> player_filter;

std::vector<__int64> lastWalkEventIndexPerPlayer;
std::vector<Replay::WalkEvent_LineData> lastWalkEventLineDataPerPlayer;
std::vector<ImVec2> lastWalkEventPosPerPlayer;

ImU32 GetReplayPlayerColor(uint8_t colorId) {
return ImGui::ColorConvertFloat4ToU32(AmongUsColorToImVec4(GetPlayerColor(colorId)));
Expand All @@ -52,7 +52,7 @@ namespace Replay
for (int i = 0; i < MAX_PLAYERS; i++) {
Replay::player_filter.push_back({ PlayerSelection(), false });
Replay::lastWalkEventIndexPerPlayer.push_back(-1);
Replay::lastWalkEventLineDataPerPlayer.push_back(Replay::WalkEvent_LineData());
Replay::lastWalkEventPosPerPlayer.push_back(ImVec2(0.f, 0.f));
}
init = true;
}
Expand All @@ -61,11 +61,11 @@ namespace Replay
void Reset()
{
Replay::lastWalkEventIndexPerPlayer.clear();
Replay::lastWalkEventLineDataPerPlayer.clear();
Replay::lastWalkEventPosPerPlayer.clear();
for (int i = 0; i < MAX_PLAYERS; i++)
{
Replay::lastWalkEventIndexPerPlayer.push_back(-1);
Replay::lastWalkEventLineDataPerPlayer.push_back(Replay::WalkEvent_LineData());
Replay::lastWalkEventPosPerPlayer.push_back(ImVec2(0.f, 0.f));
}
}

Expand Down Expand Up @@ -252,11 +252,11 @@ namespace Replay
// on the first walk event per player, these values will be 0.f
// BUT the if statement will also be true so the 'continue' statement will be hit
// which will avoid drawing a line to 0,0
float prevMapX = lastWalkEventLineDataPerPlayer[evtPlayerSource.playerId].mapX;
float prevMapY = lastWalkEventLineDataPerPlayer[evtPlayerSource.playerId].mapY;
float prevMapX = lastWalkEventPosPerPlayer[evtPlayerSource.playerId].x;
float prevMapY = lastWalkEventPosPerPlayer[evtPlayerSource.playerId].y;

lastWalkEventLineDataPerPlayer[evtPlayerSource.playerId].mapX = mapX;
lastWalkEventLineDataPerPlayer[evtPlayerSource.playerId].mapY = mapY;
lastWalkEventPosPerPlayer[evtPlayerSource.playerId].x = mapX;
lastWalkEventPosPerPlayer[evtPlayerSource.playerId].y = mapY;

if (lastWalkEventIndexPerPlayer[evtPlayerSource.playerId] <= evtIdx)
{
Expand All @@ -282,14 +282,28 @@ namespace Replay
ImVec2(0.0f, 1.0f),
ImVec2(1.0f, 0.0f));

Profiler::EndSample("ReplayWalkEvent");
continue;
}

drawList->AddLine(ImVec2(prevMapX, prevMapY), ImVec2(mapX, mapY), GetReplayPlayerColor(evtPlayerSource.colorId));
//drawList->AddLine(ImVec2(prevMapX, prevMapY), ImVec2(mapX, mapY), GetReplayPlayerColor(evtPlayerSource.colorId));
Profiler::EndSample("ReplayWalkEvent");
}
}
Profiler::EndSample("ReplayLoop");

for (int plrIdx = 0; plrIdx < State.replayWalkPolylineByPlayer.size(); plrIdx++)
{
Replay::WalkEvent_LineData plrLineData = State.replayWalkPolylineByPlayer.at(plrIdx);
for (auto& point : plrLineData.points)
{
point.x += winpos.x;
point.y += winpos.y;
}
drawList->AddPolyline(plrLineData.points.data(), plrLineData.points.size(), GetReplayPlayerColor(plrLineData.colorId), false, 1.f);
}


ImGui::EndChild();

ImGui::BeginChild("replay#control");
Expand Down
5 changes: 3 additions & 2 deletions gui/replay.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#pragma once
#include <mutex>
#include "imgui/imgui.h"

namespace Replay
{
Expand All @@ -10,7 +11,7 @@ namespace Replay

struct WalkEvent_LineData
{
float mapX = 0.f;
float mapY = 0.f;
uint8_t colorId;
std::vector<ImVec2> points;
};
}
2 changes: 1 addition & 1 deletion gui/tabs/debug_tab.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ namespace DebugTab {
ImGui::BeginChild("debug#profiler", ImVec2(0, 0), true);

std::stringstream statStream;
Profiler::AppendStatStringStream("ClearEvents", statStream);
//Profiler::AppendStatStringStream("ClearEvents", statStream);
Profiler::AppendStatStringStream("ReplayRender", statStream);
Profiler::AppendStatStringStream("ReplayLoop", statStream);
//Profiler::AppendStatStringStream("ReplayFilter", statStream);
Expand Down
5 changes: 5 additions & 0 deletions hooks/InnerNetClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,11 @@ void dInnerNetClient_StartEndGame(InnerNetClient* __this, MethodInfo* method) {
e.reset();
State.events.clear();

for (int plyIdx = 0; plyIdx < MAX_PLAYERS; plyIdx++)
{
State.lastWalkEventPosPerPlayer[plyIdx] = ImVec2(0.f, 0.f);
}

InnerNetClient_StartEndGame(__this, method);
}

Expand Down
20 changes: 19 additions & 1 deletion hooks/PlayerControl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,11 +147,29 @@ void dPlayerControl_FixedUpdate(PlayerControl* __this, MethodInfo* method) {
ImVec2 localScreenPosition = WorldToScreen(localPos);

Vector2 playerPos = PlayerControl_GetTruePosition(__this, nullptr);
Vector2 prevPlayerPos = {State.lastWalkEventPosPerPlayer[__this->fields.PlayerId].x, State.lastWalkEventPosPerPlayer[__this->fields.PlayerId].y};

State.lastWalkEventPosPerPlayer[__this->fields.PlayerId].x = playerPos.x;
State.lastWalkEventPosPerPlayer[__this->fields.PlayerId].y = playerPos.y;

std::lock_guard<std::mutex> replayLock(Replay::replayEventMutex);
if (!State.InMeeting)
{
State.events.emplace_back(std::make_unique<WalkEvent>(GetEventPlayerControl(__this).value(), playerPos));
float dist = GetDistanceBetweenPoints_Unity(playerPos, prevPlayerPos);
if (dist > 0.f)
{
State.events.emplace_back(std::make_unique<WalkEvent>(GetEventPlayerControl(__this).value(), playerPos));
ImVec2 lineData = {maps[State.mapType].x_offset + (playerPos.x * maps[State.mapType].scale), maps[State.mapType].y_offset - (playerPos.y * maps[State.mapType].scale)};
if (State.replayWalkPolylineByPlayer.find(__this->fields.PlayerId) == State.replayWalkPolylineByPlayer.end())
{
// initialize its value
State.replayWalkPolylineByPlayer[__this->fields.PlayerId] = {};
State.replayWalkPolylineByPlayer[__this->fields.PlayerId].points = {};
// bad. but not worried about micro-optimizations right now.
State.replayWalkPolylineByPlayer[__this->fields.PlayerId].colorId = GetEventPlayerControl(__this).value().colorId;
}
State.replayWalkPolylineByPlayer[__this->fields.PlayerId].points.push_back(lineData);
}
}

PlayerData espPlayerData;
Expand Down
5 changes: 5 additions & 0 deletions hooks/PolusShipStatus.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ void dPolusShipStatus_OnEnable(PolusShipStatus* __this, MethodInfo* method)
e.reset();
State.events.clear();

for (int plyIdx = 0; plyIdx < MAX_PLAYERS; plyIdx++)
{
State.lastWalkEventPosPerPlayer[plyIdx] = ImVec2(0.f, 0.f);
}

State.selectedDoor = SystemTypes__Enum::Hallway;
State.mapDoors.clear();
State.pinnedDoors.clear();
Expand Down
5 changes: 5 additions & 0 deletions hooks/ShipStatus.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ void dShipStatus_OnEnable(ShipStatus* __this, MethodInfo* method) {
e.reset();
State.events.clear();

for (int plyIdx = 0; plyIdx < MAX_PLAYERS; plyIdx++)
{
State.lastWalkEventPosPerPlayer[plyIdx] = ImVec2(0.f, 0.f);
}

State.selectedDoor = SystemTypes__Enum::Hallway;
State.mapDoors.clear();
State.pinnedDoors.clear();
Expand Down
11 changes: 11 additions & 0 deletions user/state.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "_rpc.h"
#include "keybinds.h"
#include "game.h"
#include "replay.hpp"

class Settings {
public:
Expand Down Expand Up @@ -87,6 +88,8 @@ class Settings {

bool ShowConsole = false;
std::vector<std::unique_ptr<EventInterface>> events;
std::vector<ImVec2> lastWalkEventPosPerPlayer;
std::map<int, Replay::WalkEvent_LineData> replayWalkPolylineByPlayer;

std::bitset<0xFF> voteMonitor;

Expand Down Expand Up @@ -151,6 +154,14 @@ class Settings {

bool AutoOpenDoors = false;

Settings()
{
for (int plyIdx = 0; plyIdx < MAX_PLAYERS; plyIdx++)
{
this->lastWalkEventPosPerPlayer.push_back(ImVec2(0.f, 0.f));
}
}

void Load();
void Save();
};
Expand Down
12 changes: 12 additions & 0 deletions user/utility.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -688,4 +688,16 @@ RoleTypes__Enum GetRoleTypesEnum(RoleType role)
return RoleTypes__Enum::Scientist;
}
return RoleTypes__Enum::Crewmate;
}

float GetDistanceBetweenPoints_Unity(Vector2 p1, Vector2 p2)
{
float dx = p1.x - p2.x, dy = p1.y - p2.y;
return sqrtf(dx * dx + dy * dy);
}

float GetDistanceBetweenPoints_ImGui(ImVec2 p1, ImVec2 p2)
{
float dx = p1.x - p2.x, dy = p1.y - p2.y;
return sqrtf(dx * dx + dy * dy);
}
4 changes: 3 additions & 1 deletion user/utility.h
Original file line number Diff line number Diff line change
Expand Up @@ -136,4 +136,6 @@ bool PlayerIsImpostor(GameData_PlayerInfo* player);
GameData_PlayerOutfit* GetPlayerOutfit(GameData_PlayerInfo* player, bool includeShapeshifted = false);
Color GetRoleColor(RoleBehaviour* roleBehaviour);
std::string GetRoleName(RoleBehaviour* roleBehaviour, bool abbreviated = false);
RoleTypes__Enum GetRoleTypesEnum(RoleType role);
RoleTypes__Enum GetRoleTypesEnum(RoleType role);
float GetDistanceBetweenPoints_Unity(Vector2 p1, Vector2 p2);
float GetDistanceBetweenPoints_ImGui(ImVec2 p1, ImVec2 p2);

0 comments on commit 43408bd

Please sign in to comment.