How to draw debug data from C++ AI onto game view?
Recently I saw java AI that is capable of drawing its internal data (such as eco grid) onto warzone.
Some java AIs contain calls such as
callback.getMap().getDrawer().addPoint(unit.getPos(), "building defender");
And some even contain JFrame derivatives and work with java.awt.Graphics (have no idea whats that).
I did try to use AI interface methods with almost no effect:
callback->GetMap()->GetDrawer()->AddLine(commander->GetPos(), friendCommander->GetPos());
callback->GetMap()->GetDrawer()->AddNotification(commander->GetPos(), AIColor(0.9, 0.1, 0.1), 200);
callback->GetMap()->GetDrawer()->AddPoint(commander->GetPos(), "Pinh!");
Only AddNotification made a 1 second ping on a minimap.
C++ AI: In-game drawing
Moderators: hoijui, Moderators
Re: C++ AI: In-game drawing
(engine version 97.0.1-2xx)
Got direct answer from AI developer.
AddLine and AddPoint should work, but infolog says
[f=0000129] Got message 31 from 0 claiming to be from 1
[f=0000129] Got message 31 from 0 claiming to be from 2
etc.
NETMSG_MAPDRAW = 31.
Will try to fix that.
JFrame and java.awt.Graphics are not related to spring (visualization done in other gui).
Got direct answer from AI developer.
AddLine and AddPoint should work, but infolog says
[f=0000129] Got message 31 from 0 claiming to be from 1
[f=0000129] Got message 31 from 0 claiming to be from 2
etc.
NETMSG_MAPDRAW = 31.
Will try to fix that.
JFrame and java.awt.Graphics are not related to spring (visualization done in other gui).
Re: C++ AI: In-game drawing
try /debugdrawai
Re: C++ AI: In-game drawing
Looks like engine allows to draw only by playerID and not by teamID.
But function CAICallback::HandleCommand (commandId == AIHCAddMapPointId) passes teamID instead of playerID to CBaseNetProtocol::SendMapDrawPoint.
https://github.com/spring/spring/pull/121
But function CAICallback::HandleCommand (commandId == AIHCAddMapPointId) passes teamID instead of playerID to CBaseNetProtocol::SendMapDrawPoint.
https://github.com/spring/spring/pull/121
Re: C++ AI: In-game drawing
/debugdrawai actually has no effect onjK wrote:try /debugdrawai
callback->GetMap()->GetDrawer()->AddPoint(commander->GetPos(), "Pinh!");
You still need https://github.com/spring/spring/pull/121 workaround.
Actually a better fix required that allows to draw not by playerID but by teamID, and thats much more work.
But /debugdrawai intrigued me. Went to investigate it and found another drawer (GraphDrawer).
Looks like local drawer. Will play a bit more with it.
Last edited by lamer on 13 Aug 2014, 23:54, edited 1 time in total.
Re: C++ AI: In-game drawing
Is there any example how to use springai::GraphDrawer and springai::GraphLine?jK wrote:try /debugdrawai
I tried to do on EVENT_INIT
Code: Select all
GraphDrawer* drawer = callback->GetDebug()->GetGraphDrawer();
drawer->SetPosition(0, 0);
drawer->SetSize(map->GetWidth() * SQUARE_SIZE, map->GetHeight() * SQUARE_SIZE);
GraphLine* line = drawer->GetGraphLine();
line->SetColor(0, AIColor(0.9, 0.1, 0.1));
line->SetLabel(0, "label");
Code: Select all
// map->GetDrawer()->AddPoint(commander->GetPos(), "Pinh!");
GraphLine* line = callback->GetDebug()->GetGraphDrawer()->GetGraphLine();
line->AddPoint(0, commander->GetPos().x, commander->GetPos().y);
Re: C++ AI: In-game drawing
/debugdrawai is fine and working, thanks, just had to look at E323AI sources to find out the proper use.
It uses flat screen coordinates (-1..1).
On EVENT_INIT
On EVENT_UPDATE
As spectator select affected AI and see graph.
Reference thread
It uses flat screen coordinates (-1..1).
On EVENT_INIT
Code: Select all
GraphDrawer* drawer = callback->GetDebug()->GetGraphDrawer();
drawer->SetPosition(-0.6f, -0.6f);
drawer->SetSize(0.8f, 0.8f);
GraphLine* line = drawer->GetGraphLine();
line->SetColor(0, AIColor(0.9, 0.1, 0.1));
line->SetLabel(0, "label");
Code: Select all
GraphLine* line = callback->GetDebug()->GetGraphDrawer()->GetGraphLine();
line->AddPoint(0, -0.9, -0.9);
line->AddPoint(0, 0.9, 0.9);
Reference thread