Re: Interface Redesign
Posted: 23 Feb 2009, 18:26
everything compiled fine on windows with only a little poking (one fix committed, and javac wasn't on PATH). good job.
Open Source Realtime Strategy Game Engine
https://springrts.com/phpbb/
Code: Select all
struct SCreateSharedMemAreaCommand {
char* name;
int size;
void* ret_sharedMemArea;
}; // COMMAND_SHARED_MEM_AREA_CREATE
thanks for both!imbaczek wrote:everything compiled fine on windows with only a little poking (one fix committed, and javac wasn't on PATH). good job.
Code: Select all
AI/Skirmish/AAI/0.X/log.txt
AI/Skirmish/AAI/0.Y/log.txt
AI/Skirmish/AAI/learning/mod.txt
AI/Skirmish/AAI/learning/map.txt
AI/Skirmish/AAI/cache/map.txt
Code: Select all
AI/Skirmish/AAI/0.X/log.txt
AI/Skirmish/AAI/0.Y/log.txt
AI/Skirmish/AAI/common/learning/mod.txt
AI/Skirmish/AAI/common/learning/map.txt
AI/Skirmish/AAI/common/cache/map.txt
Code: Select all
C-Interface Wrapper
command -> command
function -> function
Code: Select all
C-Interface Wrapper
command -> function
Code: Select all
callback.getFriendlyUnits()[0].move(pos)
The inconvienience is not really an issue, as nobody will ever use the pure C interface for an AI, and so we can wrapp away all inconvienence, and for variable return data, i use two functions per logical call already: one to fetch the data size, then allocate enough memory, then fetch the data for real. same could be done wiht events, using a single event, once just fetching the size of the data, with allocated target memory of size 0, and then clal the same event type again with the needed ammount of memory allocated.Tobi wrote: A generic callback function seems like a useless complication to me for the callback interface, not in the least because of the trouble of returning a pointer to an object:Of course one could make it like this:
- it can't just be created on the stack in the engine because then pointer would be dangling on return of the callback function.
- It can't be allocated on the heap without a bunch of code to automatically garbage collect it a later frame.
- It can't be allocated on the heap and freed in the AI because they may use a different C runtime (ie. different heaps).
- It can only be made a global variable engine side (or member of the object representing the AI, but that's still pretty much global), with accompanying issues of people still trying to free the pointer, callbacks being non-reentrant, etc.
Where the AI allocates space for the data and the engine actually fills it, but:Code: Select all
void callback(int id, void* data);
- I do not think this is very intuitive (because of the "out" parameter).
- It wouldn't have as good compatibility because the callback data structure couldn't be made bigger in the engine: it would write out of bounds of the area allocated by older AIs.