Page 2 of 21

Posted: 11 Oct 2007, 12:32
by hoijui
hey :-)
well...
how to say..
im doing the whole thing very.. messy, just trying to get something to work when i see a problem.
right now i got the compilation errors quite done (for now).
and i have the following problem:

the beginning of the file CommandQueue.h looks like this:

Code: Select all

class CCommandQueue {

	friend class CCommandAI;
	friend class CFactoryCAI;

	enum QueueType {
		CommandQueueType,
		NewUnitQueueType,
		BuildQueueType
	};

	CR_DECLARE(CCommandQueue);
	public:
		inline QueueType GetType() const { return queueType; }
...
so the public function GetType() returns a private type (QueueType).
because of this, i get an error.
i would like to move the QueueType struct into the public section aswell.

so i have this and the other thing with the CommandDescription struct mentioned earlier.
2 small changes to the source.
for uploading them to svn, i would need a password and username.
as it are small changes, you could do it as well, or.. well i would need an account.

Posted: 11 Oct 2007, 12:50
by DJ
I don't have commit access, we'll have to wait until a dev approves it. Also will the other changes effect the other AI's using the interface?

Posted: 11 Oct 2007, 13:09
by hoijui
these 2 changes..
its a syntax error corrected and one struct made public intead of private.
so it should not change anything for other AIs.
so far i have no other changes.

Posted: 11 Oct 2007, 13:57
by DJ
best thing to do then is to make a patch and submit it into mantis with an explaination of what you've done and what it fixes.

Posted: 11 Oct 2007, 15:37
by hoijui
@DJ
..how do i do a patch and what is mantis? :/

@AF
when linking, i get:
undefined reference to CGlobalAICallback::CGlobalAICallback(CGlobalAI*)
for example.
am just missing all the implementations under rts.
do i have to compile and include them myself, or is there a dll somewhere somewhen that contains them which i can use with -l ?

(i am now working with the SVN version of spring)

Posted: 11 Oct 2007, 16:34
by AF
No, your binding the implementation of the itnerface. You should be binding the itnerface tiself.

AIs dont handle CAICallback etc they handle IAICallback

Posted: 11 Oct 2007, 16:46
by hoijui
yes...
but i cant create a Java proxy class with swig from IAICallback, it only works with CAICallback.
at least i don know how.
though. it should be possible somehow...
hm
will look through the swig documentation again :-( (-> guess jcnossen feels with me :D ;-) )

Edit:
i forgot:
even if i get this to work with the I* classes, i still would need some of the others, like UnitDef, WeaponDef, Command and such. so where would i get these from?
Edit: i mean, with what would i have to link to get them?

Posted: 11 Oct 2007, 17:48
by DJ
most svn clients can create patches automatically from the changes to your code.

Mantis is the bug tracking software we use, if you register an issue and attach a patch to the issue the devs can take a look and then apply your patch. After you've done a few patches they then may give you SVN commit access...

Posted: 11 Oct 2007, 22:43
by jcnossen
Have you looked into swig director classes? IIRC they are what you need to allow script side implementation of C++ interfaces.

That is what you should be needing for IGlobalAI I think, for the other abstract C++ classes (Including IAICallback), SWIG should be able to generate java classes (I know it works for C#, which is based on the SWIG java code).

Also, to limit the need to modify springs code itself, you might want to have some keyword to make SWIG ignore parts of spring code. This would have to be added to the C++ header StdAfx.h for global inclusion.

Something like

Code: Select all

%ignore NO_JAVA;
in your swig .i script. And in your StdAfx.h

Code: Select all

#define NO_JAVA
This way you can quickly insert NO_JAVA in every definition that you don't want SWIG to use.

It wont make spring code prettier, but its probably still the cleanest way to prevent you having to work around all kinds of header problems

Finally, maybe you already made swig ignore CR_* macro's, if not that will be required too, otherwise SWIG will generate functions to call stuff like 'CR_DECLARE_STRUCT'
Anyway good luck ;)

Posted: 12 Oct 2007, 09:26
by hoijui
thanks jcnossen
will look at that with the CR_DECLARE_STRUCT stuff.
i knew i have to use director for IGlobalAI, and not for the rest, i am doing this already...
but the thing is, that SWIG does not generate a wrapper class for IGlobalAICallback (and the other I* classes)!
well.. id does do some wrapper class, but this class serves only as pointer, and the methods (like GetCheatsCallback()) are not available there.
when i include CGlobalAICallback, it works.

and aside of that:
There is no IUnitDef at all, so i have to include UnitDef, and have to link against it somewhere, where is that??
i tried making a link spring.dll to spring.exe, and link against that.... didn't work well ;-)

the thing with StdAfx.h.
i think i got it.

i could then.. for example, wrap some part of the code in.. for example CommandQueue.h in a

Code: Select all

#ifndef NO_JAVA
...
some C++ code usually necessary but incompatible with SWIG or unimportant for the AI interface
...
#endif
right? :/
(to say it again, i have no real life knowledge about C/C++, i only ever used it in school and school projects, or in small amounts in other projects)

as you mentioned C#...
how was the C# interface done?
..ahhh .Net supports C and C++, i guess it works that way, right?

if you can and want.. maybe i can learn from your SWIG sources too (you said you did something for the LUA support). could i have a look at it?

well.. right now, the problem i have is linking, and doesn't have to do with SWIG, but as soon as thats solved, i will have problems with swig again for sure ;-)

Posted: 12 Oct 2007, 11:39
by hoijui
the I* classes now work with swig.
the problem was the DECLARE_PURE_VIRTUAL(arg) of the destructor.
i couldn't get it to work with %ignore, so i did a

Code: Select all

#define DECLARE_PURE_VIRTUAL(arg)
and now it works.

I still have the other problem, where i don know where to link to, to get UnitDef, WeaponDef and so on.
should it be in spring.exe when it compiles successfully?

Posted: 12 Oct 2007, 16:38
by hoijui
i got something to run..
well.. something to not crash spring instantly ;-)
i get sync warnings now:

Code: Select all

Sync warning: FPUCW 0x027F instead of 0x003A or 0x003F
Sync warning: FPUCW 0x027F instead of 0x003A or 0x003F
Sync warning: FPUCW 0x027F instead of 0x003A or 0x003F
...
is it a threading issue?

Posted: 12 Oct 2007, 16:47
by Tobi
No, means the CPU's floating point control word is incorrect (which determines for example the precision of floating point calculations).

Which in turn means all calculations will probably be slightly off compared to other clients, meaning it would desync (hence "sync error").

Through IIRC creating a new thread (for game server) did trigger the same problem, resetting the control word just after the thread creation solved it.
(call streflop_init<float>() for that)

To be more specific I'd need some more information though:

Is there already a JVM running here _inside_ the Spring process?
If so, is it running in a separate thread or in the main thread?

Posted: 12 Oct 2007, 17:50
by jcnossen
The problem with a C# SWIG binding was that it needs the C# .NET dll to load the native dll, which is very unpractical when you want to make an interface for a native exe.
Maybe swig java allows to start the runtime in other ways...

Posted: 12 Oct 2007, 17:59
by hoijui
where from should i get streflop_init?
(is it accessible through the spring sources already, or from the system?)
i am not really a C or C++ dev.

there is a JNI function JNI_GetCreatedJavaVMs, which lets one see if there are any jvms running already, it returned 0 for me (right before the piece of code where i create my own jvm).
i don't know if this really would return all jvms created in the process.
there is also a JNI function AttachCurrentThread, but as i got it, this is not necessary to call when the JVM is used in the thread where it is created.
i also tried calling this method after i created the JVM.

well...
i don't know how to give more info :/

Posted: 12 Oct 2007, 21:00
by hoijui
jcnossen wrote:The problem with a C# SWIG binding was that it needs the C# .NET dll to load the native dll, which is very unpractical when you want to make an interface for a native exe.
Maybe swig java allows to start the runtime in other ways...
I am pretty sure that it is possible in with java.
one can start the JVM from native code, and then instantiate swig C++ director classes with that jvm.
i have simple test code ready, but am currently getting the sync error mentioned above.

Posted: 12 Oct 2007, 22:21
by hoijui
i found this:
http://blogs.sun.com/krylov/entry/excep ... de_by_zero
this is exactly what happens for me too.

i guess its the swig generated code that changes the FPU word.
as i didn't get that error before, when i was using the jni calls i wrote by hand.

i tried the -XX:+AlwaysRestoreFPU flag mentioned in that link, but that only let spring crash.
so i guess i have to change the code using streflop or controlfp.

@Tobi
thanks for your explanation!
and... if you get something in mind that could easy the pain for me on that... ;-) pls tell me!

Posted: 12 Oct 2007, 22:31
by AF
I wouldn't be surprised if Sun amde soem attempt to mess with fpu registers to sync Java calculations closer together across different platforms.

Posted: 13 Oct 2007, 11:15
by Tobi
hoijui maybe you can post the source you have until now so I can take a look wrt this float bug?

(provided I have enough time ofc)

Posted: 14 Oct 2007, 11:48
by hoijui
thanks tobi :-)
i didn't have time yesterday.
well .. what i have so far.. its REALLY ugly, but i cleaned it as far as i was able.
how should i give it to you?
email?