Skip to content

Commit

Permalink
Moved StoC handling for PingsLinesRenderer into UI Message handler in…
Browse files Browse the repository at this point in the history
…stead

When drawing on compass, draw on minimap, vice versa
  • Loading branch information
3vcloud committed Apr 3, 2024
1 parent 43c08d6 commit 016693d
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 39 deletions.
2 changes: 1 addition & 1 deletion Dependencies/GWCA
Submodule GWCA updated from 95665a to 347d5e
11 changes: 4 additions & 7 deletions GWToolboxdll/Widgets/Minimap/Minimap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -311,11 +311,6 @@ void Minimap::Initialize()
pingslines_renderer.P046Callback(pak);
}
});
GW::StoC::RegisterPacketCallback<GW::Packet::StoC::CompassEvent>(&CompassEvent_Entry, [this](GW::HookStatus*, const GW::Packet::StoC::CompassEvent* pak) -> void {
if (visible) {
pingslines_renderer.P138Callback(pak);
}
});
GW::StoC::RegisterPacketCallback<GW::Packet::StoC::PlayEffect>(&CompassEvent_Entry, [this](const GW::HookStatus*, GW::Packet::StoC::PlayEffect* pak) -> void {
if (visible) {
if (GW::Map::GetInstanceType() == GW::Constants::InstanceType::Explorable) {
Expand All @@ -342,7 +337,8 @@ void Minimap::Initialize()
GW::UI::UIMessage::kMapChange,
GW::UI::UIMessage::kMapLoaded,
GW::UI::UIMessage::kChangeTarget,
GW::UI::UIMessage::kSkillActivated
GW::UI::UIMessage::kSkillActivated,
GW::UI::UIMessage::kCompassDraw
};
for (const auto message_id : hook_messages) {
RegisterUIMessageCallback(&UIMsg_Entry, message_id, OnUIMessage);
Expand All @@ -359,9 +355,10 @@ void Minimap::Initialize()
GW::Chat::CreateCommand(L"flag", &OnFlagHeroCmd);
}

void Minimap::OnUIMessage(GW::HookStatus*, const GW::UI::UIMessage msgid, void* wParam, void*)
void Minimap::OnUIMessage(GW::HookStatus* status, const GW::UI::UIMessage msgid, void* wParam, void* lParam)
{
auto& instance = Instance();
instance.pingslines_renderer.OnUIMessage(status, msgid, wParam, lParam);
switch (msgid) {
case GW::UI::UIMessage::kMapLoaded: {
instance.pmap_renderer.Invalidate();
Expand Down
1 change: 1 addition & 0 deletions GWToolboxdll/Widgets/Minimap/Minimap.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ class Minimap final : public ToolboxWidget {
static void Render(IDirect3DDevice9* device);

private:

[[nodiscard]] bool IsInside(int x, int y) const;
// returns true if the map is visible, valid, not loading, etc
[[nodiscard]] bool IsActive() const;
Expand Down
70 changes: 42 additions & 28 deletions GWToolboxdll/Widgets/Minimap/PingsLinesRenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,55 +101,61 @@ void PingsLinesRenderer::P046Callback(const GW::Packet::StoC::AgentPinged* pak)
}
}

void PingsLinesRenderer::P138Callback(const GW::Packet::StoC::CompassEvent* pak)
{
void PingsLinesRenderer::OnUIMessage(GW::HookStatus*, GW::UI::UIMessage message_id, void* wparam, void*) {
if (message_id != GW::UI::UIMessage::kCompassDraw)
return;

const auto packet = (GW::UI::UIPacket::kCompassDraw*)wparam;

bool new_session;
if (drawings[pak->Player].player == pak->Player) {
new_session = drawings[pak->Player].session != pak->SessionID;
drawings[pak->Player].session = pak->SessionID;

if (drawings[packet->player_number].player == packet->player_number) {
new_session = drawings[packet->player_number].session != packet->session_id;
drawings[packet->player_number].session = packet->session_id;
}
else {
drawings[pak->Player].player = pak->Player;
drawings[pak->Player].session = pak->SessionID;
drawings[packet->player_number].player = packet->player_number;
drawings[packet->player_number].session = packet->session_id;
new_session = true;
}

if (new_session && pak->NumberPts == 1) {
if (new_session && packet->number_of_points == 1) {
pings.push_front(new TerrainPing(
pak->points[0].x * drawing_scale,
pak->points[0].y * drawing_scale));
packet->points[0].x * drawing_scale,
packet->points[0].y * drawing_scale));
return;
}

if (new_session) {
for (auto i = 0u; i < pak->NumberPts - 1; i++) {
for (auto i = 0u; i < packet->number_of_points - 1; i++) {
DrawingLine l;
l.x1 = pak->points[i + 0].x * drawing_scale;
l.y1 = pak->points[i + 0].y * drawing_scale;
l.x2 = pak->points[i + 1].x * drawing_scale;
l.y2 = pak->points[i + 1].y * drawing_scale;
drawings[pak->Player].lines.push_back(l);
l.x1 = packet->points[i + 0].x * drawing_scale;
l.y1 = packet->points[i + 0].y * drawing_scale;
l.x2 = packet->points[i + 1].x * drawing_scale;
l.y2 = packet->points[i + 1].y * drawing_scale;
drawings[packet->player_number].lines.push_back(l);
}
}
else {
if (drawings[pak->Player].lines.empty()) {
if (drawings[packet->player_number].lines.empty()) {
return;
}
for (auto i = 0u; i < pak->NumberPts; i++) {
for (auto i = 0u; i < packet->number_of_points; i++) {
DrawingLine l;
if (i == 0) {
l.x1 = drawings[pak->Player].lines.back().x2;
l.y1 = drawings[pak->Player].lines.back().y2;
l.x1 = drawings[packet->player_number].lines.back().x2;
l.y1 = drawings[packet->player_number].lines.back().y2;
}
else {
l.x1 = pak->points[i - 1].x * drawing_scale;
l.y1 = pak->points[i - 1].y * drawing_scale;
l.x1 = packet->points[i - 1].x * drawing_scale;
l.y1 = packet->points[i - 1].y * drawing_scale;
}
l.x2 = pak->points[i].x * drawing_scale;
l.y2 = pak->points[i].y * drawing_scale;
drawings[pak->Player].lines.push_back(l);
l.x2 = packet->points[i].x * drawing_scale;
l.y2 = packet->points[i].y * drawing_scale;
drawings[packet->player_number].lines.push_back(l);
}
}

}

void PingsLinesRenderer::P153Callback(const GW::Packet::StoC::GenericValueTarget* pak)
Expand All @@ -166,6 +172,7 @@ void PingsLinesRenderer::Initialize(IDirect3DDevice9* device)
if (initialized) {
return;
}

initialized = true;
type = D3DPT_LINELIST;

Expand Down Expand Up @@ -503,13 +510,13 @@ bool PingsLinesRenderer::OnMouseMove(const float x, const float y)
l.y1 = mouse_y;
l.x2 = mouse_x = x;
l.y2 = mouse_y = y;
drawings[me->player_number].lines.push_back(l);
//drawings[me->player_number].lines.push_back(l);

if (TIMER_DIFF(lastqueued) > queue_interval
|| TIMER_DIFF(lastsent) > send_interval) {
lastqueued = TIMER_INIT();

queue.push_back(GW::UI::CompassPoint(ToShortPos(x), ToShortPos(y)));
queue.push_back(GW::UI::CompassPoint(ToIntPos(x), ToIntPos(y)));

if (queue.size() == 7 || TIMER_DIFF(lastsent) > send_interval) {
lastsent = TIMER_INIT();
Expand All @@ -533,7 +540,7 @@ bool PingsLinesRenderer::OnMouseUp()
}
else {
BumpSessionID();
queue.push_back(GW::UI::CompassPoint(ToShortPos(mouse_x), ToShortPos(mouse_y)));
queue.push_back(GW::UI::CompassPoint(ToIntPos(mouse_x), ToIntPos(mouse_y)));
pings.push_front(new TerrainPing(mouse_x, mouse_y));
}

Expand All @@ -550,6 +557,13 @@ void PingsLinesRenderer::SendQueue()
pts[i] = queue[i];
}
DrawOnCompass(static_cast<size_t>(session_id), queue.size(), pts);
GW::UI::UIPacket::kCompassDraw packet = {
.player_number = GW::Agents::GetPlayerId(),
.session_id = static_cast<size_t>(session_id),
.number_of_points = queue.size(),
.points = pts
};
GW::UI::SendUIMessage(GW::UI::UIMessage::kCompassDraw, &packet);
}

queue.clear();
Expand Down
6 changes: 3 additions & 3 deletions GWToolboxdll/Widgets/Minimap/PingsLinesRenderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ class PingsLinesRenderer : public VBuffer {
void AddMouseClickPing(GW::Vec2f pos);

void P046Callback(const GW::Packet::StoC::AgentPinged* pak);
void P138Callback(const GW::Packet::StoC::CompassEvent* pak);
void OnUIMessage(GW::HookStatus*, GW::UI::UIMessage, void*, void*);
void P153Callback(const GW::Packet::StoC::GenericValueTarget* pak);

void DrawSettings();
Expand All @@ -131,9 +131,9 @@ class PingsLinesRenderer : public VBuffer {
void DrawDrawings(IDirect3DDevice9* device);
void EnqueueVertex(float x, float y, Color color);

short ToShortPos(const float n) const
int ToIntPos(const float n) const
{
return static_cast<short>(std::lroundf(n / drawing_scale));
return static_cast<int>(std::lroundf(n / drawing_scale));
}

void BumpSessionID()
Expand Down

0 comments on commit 016693d

Please sign in to comment.