SWIG and float3.h failed

SWIG and float3.h failed

Here is where ideas can be collected for the skirmish AI in development

Moderators: hoijui, Moderators

Post Reply
User avatar
anemol
Posts: 5
Joined: 26 Sep 2014, 09:52

SWIG and float3.h failed

Post by anemol »

I use SWIG to export somes classes for my project.
It work fine but I enconter a problem with AIFloat3 class and float3.h

Here my file .i for SWIG:

Code: Select all

#ifdef SWIG
%include <typemaps.i>
%include <carrays.i>
%include <std_string.i>
%include <std_vector.i>
%module AI
%{
  #include "CppTestAI.h"
 // Need:
  #include "OOAICallback.h"
  #include "Map.h"
  #include "Unit.h"
  #include "UnitDef.h"     
  #include "AIFloat3.h"  
  #  etc ...

%}


  %include "CppTestAI.h"
  %include "OOAICallback.h"
  %include "Map.h"
  %include "Unit.h"
  %include "UnitDef.h"     
  %include "AIFloat3.h"  
  %  etc ...

  

%template(ListofUnits) std::vector<springai::Unit*>;
%template(ListofUnitDefs) std::vector<springai::UnitDef*>;
%template(ListofWeaponDefs) std::vector<springai::WeaponDef*>;
%template(ListofWeaponMounts) std::vector<springai::WeaponMount*>;
%template(ListofCommandDescriptions) std::vector<springai::CommandDescription*>;
%template(ListofCommands) std::vector<springai::Command*>;
%template(ListofFloat) std::vector<float>;
%template(ListofInt) std::vector<int>;
#endif
I get this warning:
Warning 401: Nothing known about base class 'float3'. Ignored.
and AIFloat3 definition is not completed. I need to acces X,Y,Z fields for example.

Ok. AIFloat3 use base float3.

But If i add:
#include "float3.h"
and
%include "float3.h"

I get error:
Error: Syntax error in input(3).

:?
(I download and compile spring from github twice t be sure that source are not corrupted).

Someone have a solution? (I'm not expert in C++.)
abma
Spring Developer
Posts: 3798
Joined: 01 Jun 2009, 00:08

Re: SWIG and float3.h failed

Post by abma »

float3.h is here: https://github.com/spring/spring/blob/d ... m/float3.h

are you sure the "System" path is in the include path?

edit: imo you have to include AIFloat3.h:

https://github.com/spring/spring/blob/a ... AIFloat3.h

and verify that rts/ is in the include dir, then it should work. float3 isn't needed as it is already included from AIFloat3.h

if not, more verbose error message is needed (=full output of the command)
User avatar
anemol
Posts: 5
Joined: 26 Sep 2014, 09:52

Re: SWIG and float3.h failed

Post by anemol »

Paths are correct and AIFloat3.h is present. For others entities (Unit,Game,etc it's ok. I have complete acces to these classes).

The only problem is AIFloat3. I have a partial access (only constructor AIFloat3(x,y,z) )


I have only this error when i put float3.h:
System/float3.h:40: Error: Syntax error in input(3).

and in float3.h, line 40 is:
static const float CMP_EPS;

I wanted to write an interface for float3.h to resolve problem but my knowledge in C++ is too low.

Edit:
Is that the problem can not come to this?

Nested struct not currently supported (SWIG).

i.e float3.h:

union {
struct { float x,y,z; };
struct { float r,g,b; };
struct { float x1,y1,x2; };
struct { float s,t,p; };
struct { float xstart, ystart, xend; };
};

I'll install SWIG v3 to verify. --> same thing with SWIG 3.0.5
abma
Spring Developer
Posts: 3798
Joined: 01 Jun 2009, 00:08

Re: SWIG and float3.h failed

Post by abma »

Is that the problem can not come to this?

Nested struct not currently supported (SWIG).
sounds for me like swig doesn't support float3.h. why/where at all is it needed in the ai interface? imo thats the real problem here.
User avatar
anemol
Posts: 5
Joined: 26 Sep 2014, 09:52

Re: SWIG and float3.h failed

Post by anemol »

Like work around, i write into my C++ library this:

Code: Select all

struct xyz {
        float x;
        float y;
        float z;
    };
    
extern struct xyz * GetPosition(springai::AIFloat3* pos);
C# library can call GetPosition() to retrieve unit position information from his AIFloat3. It's not very elegant, but it works.

So , now, i can write this, for example:

Code: Select all

void UnitCreated( ref int unitId,ref int builderId)
{
			foreach(Unit unit in clb.GetFriendlyUnits()) if (unit.GetUnitId()==unitId)
			{
				AIFloat3 pos=unit.GetPos(); // (x,y,z) unavailable
				xyz position=AI.GetPosition( unit.GetPos()  );
				toLog(string.Format("Nouvelle unite: {0} a ({1},{2},{3})",unit.GetDef().GetName(),position.x,position.y,position.z));
}

Edit:
Finally, i make a new class (base on AIFloat3) to work with AIFloat3 and C# code.

Code: Select all

class TPosition: public springai::AIFloat3
	{
		public:
		float X;
		float Y;
		float Z;
		bool Updated=false;
		
		TPosition():AIFloat3()
		{
			X=0.0f;Z=0.0f;Y=0.0f;
		}
		TPosition(springai::AIFloat3 other):AIFloat3(other)
		{
			X=other.x;Y=other.y;Z=other.z;
		}
		
		TPosition(float x,float y,float z):AIFloat3(x,y,z)
		{
			X=x;Y=y;Z=z;
		}
		
		void Update(springai::AIFloat3 other)
		{
			X=other.x;Y=other.y;Z=other.z;
			Updated=true;
		}
		
		void Update(TPosition other)
		{
			X=other.X;Y=other.Y;Z=other.Z;
			Updated=true;
		}
		
		void Add(springai::AIFloat3 other)
		{
			X+=other.x;Y+=other.y;Z+=other.z;
		}
		void Add(float x,float y,float z)
		{
			X+=x;Y+=y;Z+=z;
		}
		
		springai::AIFloat3 ToAIFloat3()
		{
			return springai::AIFloat3(X,Y,Z);
		}
	};
Post Reply

Return to “AI”