Slopemap: Request for spring AI callback feature GetSlopeMap

Slopemap: Request for spring AI callback feature GetSlopeMap

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
Firenu
Posts: 39
Joined: 29 Apr 2006, 00:49

Slopemap: Request for spring AI callback feature GetSlopeMap

Post by Firenu »

Slopemap: Request for spring AI callback feature GetSlopeMap()

During some of the work relating to the pathfinder we are using in KAI, we found ourselves trying to estimate the slopemap being used internally in spring. So instead of trying to emulate the calculation in an already existing spring feature for calculating slopes :roll: , how about this:
Would you save us the development time and give access to spring's Slopemap in the same way as you give access to the Heightmap?

class IAICallback in iaicallback.h has the following function declared:
virtual const float* GetHeightMap()=0;

//Could be like this:
virtual const float* GetSlopeMap()=0;
//with a def like
const float* CAICallback::GetSlopeMap()
{
return readmap->slopemap;
}

I'm sure other AI devs might agree with me that this is useful.
With this at our fingertips you might see a new KAI with support for sea units, spiders, amphibies, subs, you name it :twisted:
User avatar
AF
AI Developer
Posts: 20687
Joined: 14 Sep 2004, 11:32

Post by AF »

That would nto fit in witht eh changes caina dn zaphod amde that allowed the itnerfce to expand without adding functions.

Also look at NTai source, specifically the Map class, as it has a slope calculation method that uses a similar if not the same method as spring to calculate slopes.

Further additiosn tot eh AI itnerface need to take the form of

CGlobalAI::HandleEvent()
IAICallback::GetProperty()
IAICallback::GetValue()

But NTai code provides a full map complete with slope values
Firenu
Posts: 39
Joined: 29 Apr 2006, 00:49

Post by Firenu »

AF wrote:NTai has a slope calculation method that uses a similar if not the same method as spring to calculate slopes.
So does kai, but every little difference between between our slopemap and the spring slopemap results in less than optimal performance. Theres also some issues about matching resolution (or factors thereof).
AF wrote: Further additiosn tot eh AI itnerface need to take the form of

CGlobalAI::HandleEvent()
IAICallback::GetProperty()
IAICallback::GetValue()
Are you saying I can currently retrieve the slopemap spring uses via these methods or that it isn't but has to be added using this kind of an interface?
edit:typo
User avatar
AF
AI Developer
Posts: 20687
Joined: 14 Sep 2004, 11:32

Post by AF »

New additions to the interface have to go through those functions.

Look at the additions I've made and the marker placement additions and GetMapLines etc
Firenu
Posts: 39
Joined: 29 Apr 2006, 00:49

Post by Firenu »

The map lines thing works nicely. Do you have a similar example of getting information out rather than in?
I dont see how getmaplines follows this interface
Firenu
Posts: 39
Joined: 29 Apr 2006, 00:49

Post by Firenu »

Well whatever. I just want a const pointer to the already existing float array, and if it has to follow a specific interface, show me how. Its a one-line function in either case, afaik.
Firenu
Posts: 39
Joined: 29 Apr 2006, 00:49

Post by Firenu »

Tournesol wrote how he thinks it would work if added to GetValue:

Code: Select all

The new GetValue function. Its in AICallback.cpp:

bool CAICallback::GetValue(int id, void *data)
{
	verify();
	switch (id) {
		case AIVAL_NUMDAMAGETYPES:
			*((int*)data) = DamageArray::numTypes;
			return true;
		case AI_EXCEPTION_HANDLING:{
			*(bool*)data = CGlobalAIHandler::CatchException();
			return true;
		}
		case AIVAL_SLOPE_MAP:
			// Returns the slope map spring use. Its size is 1/4 of the height map.
			*(const float*)data = readmap->slopemap;
			return true;
		default:
			return false;
	}
}




Add this to "IAICallback.h":
// Returns springs internal slope map. Its size is 1/4 of the height map. For use in GetValue().
#define AIVAL_SLOPE_MAP 3
Firenu
Posts: 39
Joined: 29 Apr 2006, 00:49

Post by Firenu »

okay that was three lines, not one :P
User avatar
AF
AI Developer
Posts: 20687
Joined: 14 Sep 2004, 11:32

Post by AF »

bool CAICallback::GetValue(int id, void *data)
{
verify();
switch (id) {
case AIVAL_NUMDAMAGETYPES:
*((int*)data) = DamageArray::numTypes;
return true;
case AI_EXCEPTION_HANDLING:{
*(bool*)data = CGlobalAIHandler::CatchException();
return true;
}
case AIVAL_SLOPE_MAP:{
// Returns the slope map spring use. Its size is 1/4 of the height map.
*(const float*)data = readmap->slopemap;
return true;
}
default:
return false;
}
}

I'll add this to my source, make a few additions of my own (such as getting the n# of enemy units without having to have an array of possibly 10,000 values getting created copied over and filled then deleted and never being used just to get a single integer.), then create a large patch with that and the nanospray (I made a mistake doing something for fang that needs removing from the nanospray patch...)
Firenu
Posts: 39
Joined: 29 Apr 2006, 00:49

Post by Firenu »

thanks, AF =)

atm generally i cache a unit list as a member variable, like in the header make
int unitArray[MAXUNITS];
so memory usage and cpu time isnt wasted each time a version of getenemies or getfriendlyunits is called, just for allocating the array
at least in classes that do these things a lot
but theres a certain ugliness in making global variables like this so an alternative would be appreciated (how could it be efficient if you remake a list every time though? i guess if its small. maybe a getClosestUnit(float3 pos)? not really something you need a lot so i dont know)
submarine
AI Developer
Posts: 834
Joined: 31 Jan 2005, 20:04

Post by submarine »

why not add them to the interface?

all ais will be broken after the next spring release anyway. all ai devs will have to recompile ther ais - so i dont see why it should be a problem to add some functions to the interface.
Firenu
Posts: 39
Joined: 29 Apr 2006, 00:49

Post by Firenu »

Firenu wrote:Tournesol wrote how he thinks it would work if added to GetValue:

Code: Select all

*snip*
Apperantly tournesol sent this tvo before going on vacation
Tobi
Spring Developer
Posts: 4598
Joined: 01 Jun 2005, 11:36

Post by Tobi »

maybe not... unless someone messed up unitdefs/weapondefs...

The vtable stuff is binary exactly equal as before (on windows), only the source changed a bit but that compiles away to nothing on windows.

So I wouldn't know why AIs would need a recompile.

Good chance unitdef will break if it hasn't already be broken tho...

(C++ ABI compatibility is just a bit too hard without strict policy and someone enforcing it)

You've a good point that maybe we should have a policy of copying all extensions to normal functions if we break ABI anyway. (AKA I'll try to remember it :wink: )
Tobi
Spring Developer
Posts: 4598
Joined: 01 Jun 2005, 11:36

Post by Tobi »

Firenu, yeah, but now AF is going to put it in his patch so I'll apply it all at once..
User avatar
AF
AI Developer
Posts: 20687
Joined: 14 Sep 2004, 11:32

Post by AF »

I added tournesols slopemap addition alogn with a list of others, nanospray colours, and nanospray on/off and a patch fro fang that fixes not being able to build a unit with 0 energycost if your e stalling (vice versa for metal).

The additions are summarized in these definitions:

#define AIVAL_EXCEPTION_HANDLING 2
// is exception handlign turned on

#define AIVAL_DEBUG_MODE 3
// is the suer in debug mode (pressed 'b')

#define AIVAL_SLOPE_MAP 4
// The slope map tournesola dn firenua sked for

#define AIVAL_MAX_HEIGHT 5
// The biggest height value on the heightmap

#define AIVAL_MIN_HEIGHT 6
// teh samllest height value on the heightmap

#define AIVAL_MAX_METAL 7
// The biggest metal value on the emtal map

#define AIVAL_MAP_CHECKSUM 8
// unsigned int, the checksum of the map being played on

#define AIVAL_BLOCK_MAP 9
// The itnernal blocking map used by Spring CSolidObject**

#define AIVAL_GAME_MODE 10
// commander death game end? commander death continue?

#define AIVAL_GAME_PAUSED 11
// Is the game paused?

#define AIVAL_GAME_SPEED_FACTOR 12
// The gamespeed

#define AIVAL_GUI_VIEW_RANGE 13
// What's the view radius

#define AIVAL_USYNC_RAND_FLOAT 14
// teh random float generator used by unsynced code in spring

#define AIVAL_USYNC_RAND_INT 15
// the random integer generator used by unsynced code in spring

#define AIVAL_GUI_SCREENX 16
// screen resolution

#define AIVAL_GUI_SCREENY 17
// Screen resolution

#define AIVAL_GUI_CAMERA_DIR 18
// where si the camera pointing too

#define AIVAL_GUI_CAMERA_POS 19
// where is the camera


The only issue arises ebcause Rafal had a patch commited today that added another item to get the name of script.txt/w.e its called and the definition uses 3 which clashes with AIVAL_DEBUG_MODE in my patch.
User avatar
Rafal99
Posts: 162
Joined: 14 Jan 2006, 04:09

Post by Rafal99 »

Yes, my patch was committed today with quite big log entry. 8)
Here is more info about it:
http://svn.berlios.de/wsvn/taspring-lin ... =1587&sc=1
Hope the additions will be useful.
AF wrote:#define AIVAL_GAME_MODE 10
// commander death game end? commander death continue?
Btw it can be read from script.txt. But more variables can't hurt anyway.
User avatar
Rafal99
Posts: 162
Joined: 14 Jan 2006, 04:09

Post by Rafal99 »

I see your patch has been applied too. Nice job.
One question - why do you use:

Code: Select all

}case SOMETHING:{
  dosomething;
  return true;
}case SOMETHING:{
Instead of:

Code: Select all

case SOMETHING:
  dosomething;
  return true;
case SOMETHING:
:?:
I don't think {} brackets are needed in this situation.
User avatar
AF
AI Developer
Posts: 20687
Joined: 14 Sep 2004, 11:32

Post by AF »

because aside from being clearer, it also solves a few issues in VS such as collapsing brackets and line returns and tab spacing..

nd it's much clearer imo

If its a problem you can always change it
User avatar
Rafal99
Posts: 162
Joined: 14 Jan 2006, 04:09

Post by Rafal99 »

Ok, no problem with it. I just didn't understand what they are for.
Post Reply

Return to “Engine”