Tarendai/Shard — pull request #46 by Garfonso (2014-02-19 07:07:55+00:00)
Title: change in unit-management

I do a PR so you can review the changes. I did change the architecture a bit and moved the aliveUnit-map from CppTestAI to CSpringGame. For me having to handle unit adds/deletes and so on in two different places was very confusing. Now all the unit handling happens in one place. CppTestAI calls GetUnitById, CreateUnit and DestroyUnit from the event handler which then manage alterations to the aliveUnit-map and possibly the unit vectors. I hope these changes do not conflict with the broader architecture you have in mind (i.e. engine agnostic, but as I see it, currently CppTestAI is spring specific, as is CSpringGame).

The unit vectors are still additionally filled by callback->Get***Units(), because we don't get the ENEMY_UNIT_CREATED/FINISHED events, it seems. I added handlers for them, but they don't get called. But still all these units go into the same alvieUnits map, again, so the unit-vector is only a "view" of this map, so to say. :)

What I learned from my experiments is, that it is not a good idea to delete dead units. Dead units can (and currently also will) be referenced by the lua-Part. Also the API still gives us dead units back from the callback->Get***Units() calls, so it seems the game keeps them, too. Also they don't use up too much space.... now the memory leak is gone, memory consumption is in line with other AIs and so much of an issue.