forked from 0ad/0ad
AI-related changes to the AI interface and Command.js, to facilitate debugging of upcoming new version of Aegis.
This was SVN commit r13592.
This commit is contained in:
parent
0d8b9b15e1
commit
1f55280fa2
@ -42,7 +42,7 @@ AIInterface.prototype.GetFullRepresentation = function()
|
|||||||
var cmpGuiInterface = Engine.QueryInterface(SYSTEM_ENTITY, IID_GuiInterface);
|
var cmpGuiInterface = Engine.QueryInterface(SYSTEM_ENTITY, IID_GuiInterface);
|
||||||
|
|
||||||
// Return the same game state as the GUI uses
|
// Return the same game state as the GUI uses
|
||||||
var state = cmpGuiInterface.GetSimulationState(-1);
|
var state = cmpGuiInterface.GetExtendedSimulationState(-1);
|
||||||
|
|
||||||
// Add some extra AI-specific data
|
// Add some extra AI-specific data
|
||||||
state.events = this.events;
|
state.events = this.events;
|
||||||
|
@ -288,4 +288,10 @@ AIProxy.prototype.OnTrainingFinished = function(msg)
|
|||||||
cmpAIInterface.PushEvent("TrainingFinished", msg);
|
cmpAIInterface.PushEvent("TrainingFinished", msg);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
AIProxy.prototype.OnAIMetadata = function(msg)
|
||||||
|
{
|
||||||
|
var cmpAIInterface = Engine.QueryInterface(SYSTEM_ENTITY, IID_AIInterface);
|
||||||
|
cmpAIInterface.PushEvent("AIMetadata", msg);
|
||||||
|
};
|
||||||
|
|
||||||
Engine.RegisterComponentType(IID_AIProxy, "AIProxy", AIProxy);
|
Engine.RegisterComponentType(IID_AIProxy, "AIProxy", AIProxy);
|
||||||
|
@ -650,6 +650,7 @@ function TryConstructBuilding(player, cmpPlayer, controlAllUnits, cmd)
|
|||||||
// "x": ...,
|
// "x": ...,
|
||||||
// "z": ...,
|
// "z": ...,
|
||||||
// "angle": ...,
|
// "angle": ...,
|
||||||
|
// "metadata": "...", // AI metadata of the building
|
||||||
// "actorSeed": ...,
|
// "actorSeed": ...,
|
||||||
// "autorepair": true, // whether to automatically start constructing/repairing the new foundation
|
// "autorepair": true, // whether to automatically start constructing/repairing the new foundation
|
||||||
// "autocontinue": true, // whether to automatically gather/build/etc after finishing this
|
// "autocontinue": true, // whether to automatically gather/build/etc after finishing this
|
||||||
@ -800,6 +801,10 @@ function TryConstructBuilding(player, cmpPlayer, controlAllUnits, cmd)
|
|||||||
var cmpFoundation = Engine.QueryInterface(ent, IID_Foundation);
|
var cmpFoundation = Engine.QueryInterface(ent, IID_Foundation);
|
||||||
cmpFoundation.InitialiseConstruction(player, cmd.template);
|
cmpFoundation.InitialiseConstruction(player, cmd.template);
|
||||||
|
|
||||||
|
// send Metadata info if any
|
||||||
|
if (cmd.metadata)
|
||||||
|
Engine.PostMessage(ent, MT_AIMetadata, { "id": ent, "metadata" : cmd.metadata, "owner" : player } );
|
||||||
|
|
||||||
// Tell the units to start building this new entity
|
// Tell the units to start building this new entity
|
||||||
if (cmd.autorepair)
|
if (cmd.autorepair)
|
||||||
{
|
{
|
||||||
|
@ -131,6 +131,7 @@ private:
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Debug function for AI scripts to dump 2D array data (e.g. terrain tile weights).
|
* Debug function for AI scripts to dump 2D array data (e.g. terrain tile weights).
|
||||||
|
* TODO: check if this needs to be here too.
|
||||||
*/
|
*/
|
||||||
static void DumpImage(void* UNUSED(cbdata), std::wstring name, std::vector<u32> data, u32 w, u32 h, u32 max)
|
static void DumpImage(void* UNUSED(cbdata), std::wstring name, std::vector<u32> data, u32 w, u32 h, u32 max)
|
||||||
{
|
{
|
||||||
@ -328,7 +329,8 @@ public:
|
|||||||
m_ScriptInterface.RegisterFunction<void, CScriptValRooted, CAIWorker::PostCommand>("PostCommand");
|
m_ScriptInterface.RegisterFunction<void, CScriptValRooted, CAIWorker::PostCommand>("PostCommand");
|
||||||
m_ScriptInterface.RegisterFunction<void, CAIWorker::DumpHeap>("DumpHeap");
|
m_ScriptInterface.RegisterFunction<void, CAIWorker::DumpHeap>("DumpHeap");
|
||||||
m_ScriptInterface.RegisterFunction<void, CAIWorker::ForceGC>("ForceGC");
|
m_ScriptInterface.RegisterFunction<void, CAIWorker::ForceGC>("ForceGC");
|
||||||
|
|
||||||
|
m_ScriptInterface.RegisterFunction<void, std::wstring, std::vector<u32>, u32, u32, u32, CAIWorker::DumpImage>("DumpImage");
|
||||||
}
|
}
|
||||||
|
|
||||||
~CAIWorker()
|
~CAIWorker()
|
||||||
@ -374,6 +376,45 @@ public:
|
|||||||
PROFILE3("AI compute GC");
|
PROFILE3("AI compute GC");
|
||||||
JS_GC(self->m_ScriptInterface.GetContext());
|
JS_GC(self->m_ScriptInterface.GetContext());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Debug function for AI scripts to dump 2D array data (e.g. terrain tile weights).
|
||||||
|
*/
|
||||||
|
static void DumpImage(void* UNUSED(cbdata), std::wstring name, std::vector<u32> data, u32 w, u32 h, u32 max)
|
||||||
|
{
|
||||||
|
// TODO: this is totally not threadsafe.
|
||||||
|
VfsPath filename = L"screenshots/aidump/" + name;
|
||||||
|
|
||||||
|
if (data.size() != w*h)
|
||||||
|
{
|
||||||
|
debug_warn(L"DumpImage: data size doesn't match w*h");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (max == 0)
|
||||||
|
{
|
||||||
|
debug_warn(L"DumpImage: max must not be 0");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const size_t bpp = 8;
|
||||||
|
int flags = TEX_BOTTOM_UP|TEX_GREY;
|
||||||
|
|
||||||
|
const size_t img_size = w * h * bpp/8;
|
||||||
|
const size_t hdr_size = tex_hdr_size(filename);
|
||||||
|
shared_ptr<u8> buf;
|
||||||
|
AllocateAligned(buf, hdr_size+img_size, maxSectorSize);
|
||||||
|
Tex t;
|
||||||
|
if (tex_wrap(w, h, bpp, flags, buf, hdr_size, &t) < 0)
|
||||||
|
return;
|
||||||
|
|
||||||
|
u8* img = buf.get() + hdr_size;
|
||||||
|
for (size_t i = 0; i < data.size(); ++i)
|
||||||
|
img[i] = (u8)((data[i] * 255) / max);
|
||||||
|
|
||||||
|
tex_write(&t, filename);
|
||||||
|
tex_free(&t);
|
||||||
|
}
|
||||||
|
|
||||||
bool TryLoadSharedComponent(bool hasTechs)
|
bool TryLoadSharedComponent(bool hasTechs)
|
||||||
{
|
{
|
||||||
@ -489,6 +530,7 @@ public:
|
|||||||
{
|
{
|
||||||
// this will be run last by InitGame.Js, passing the full game representation.
|
// this will be run last by InitGame.Js, passing the full game representation.
|
||||||
// For now it will run for the shared Component.
|
// For now it will run for the shared Component.
|
||||||
|
// This is NOT run during deserialization.
|
||||||
CScriptVal state = m_ScriptInterface.ReadStructuredClone(gameState);
|
CScriptVal state = m_ScriptInterface.ReadStructuredClone(gameState);
|
||||||
JSContext* cx = m_ScriptInterface.GetContext();
|
JSContext* cx = m_ScriptInterface.GetContext();
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user