Native AI: Implementation of Get(Game|Unit|Team)RulesParam.

Native AI: Implementation of Get(Game|Unit|Team)RulesParam.

Discuss the source code and development of Spring Engine in general from a technical point of view. Patches go here too.

Moderator: Moderators

Post Reply
lamer
Posts: 153
Joined: 08 Mar 2014, 23:13

Native AI: Implementation of Get(Game|Unit|Team)RulesParam.

Post by lamer »

Hi. Need some help with native AI and implementation of Get(Game|Unit|Team)RulesParam.
I'm half way with functions like

Code: Select all

  int (CALLING_CONV *Team_getTeamRulesParams)(int skirmishAIId, int teamId); //$ FETCHER:MULTI:NUM:TeamRulesParam
  int (CALLING_CONV *Team_getTeamRulesParamByName)(int skirmishAIId, int teamId, const char* teamRulesParamName); //$ FETCHER:MULTI:NUM:TeamRulesParam
  const char* (CALLING_CONV *Team_TeamRulesParam_getName)(int skirmishAIId, int teamId, int teamRulesParamId);
  float (CALLING_CONV *Team_TeamRulesParam_getValueFloat)(int skirmishAIId, int teamId, int teamRulesParamId);
  const char* (CALLING_CONV *Team_TeamRulesParam_getValueString)(int skirmishAIId, int teamId, int teamRulesParamId);
Trying to find more convinient way because of float/string values and double check if we allowed to see param (when calling ..ByName + ..getValue..), for examle

Code: Select all

  const char* (CALLING_CONV *Team_getTeamRulesParamByName)(int skirmishAIId, int teamId, const char* teamRulesParamName);
  const char* (CALLING_CONV *Team_getTeamRulesParamById)(int skirmishAIId, int teamId, int teamRulesParamId);
- if valueString is empty return std::to_string(valueInt).c_str(); I have doubts about second aproach because of float->string->float conversions and it looks less OO, but maybe it's still faster then calling couple Team_getTeamRulesParamByName+Team_TeamRulesParam_getValueFloat (except that we can save result of ..ByName and then reuse ..getValue..).
Any suggestions?
User avatar
Anarchid
Posts: 1384
Joined: 30 Nov 2008, 04:31

Re: Native AI: Implementation of Get(Game|Unit|Team)RulesPar

Post by Anarchid »

Callback seems rather slow from experience, so probably one call that does a cast will in the end be faster than making two calls and checking one for nil.

OTOH anyone querying GRP, unless being some kind of rules-learning AI, should know the type of the value they're querying.
lamer
Posts: 153
Joined: 08 Mar 2014, 23:13

Re: Native AI: Implementation of Get(Game|Unit|Team)RulesPar

Post by lamer »

Looks like keywords //$ MAP and //$ ARRAY: are not fully functional in awk script (atleast for C++). It will generate legit array of pointers to garbage if i try to cast float to string, because those temporary allocations will be destroyed on return. There is no memory management (copying) per string.
Can't get key-value map from 1 call :(
lamer
Posts: 153
Joined: 08 Mar 2014, 23:13

Re: Native AI: Implementation of Get(Game|Unit|Team)RulesPar

Post by lamer »

Back to my initial approach. It's safe, it's working, and if there is really need for speed - save/cache results.
https://github.com/spring/spring/pull/124
Post Reply

Return to “Engine”