Unitsync units

Unitsync units

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
User avatar
AF
AI Developer
Posts: 20687
Joined: 14 Sep 2004, 11:32

Unitsync units

Post by AF »

Unitsync has a setup for getting unitnames from a mod. However how this si to be used is unclear.

So far I do the following setup:

1)Initialize unitsync
2)Set the primary ModArchive and Load all its archives
3)Call ProcessUnits taking the return value as the number of units
4)Enter a loop retrieving each unitsname

The problem is as soon as I try to retrieve a unitsname in the loop unitsync crashes and java outputs a cryptic error log and exits citing unitsync as the issue.

The only example of howto do this is buried in tasclient somewhere, and tasclient code is nasty enough to read without the syntax style changing and beign messy.
User avatar
Michilus_nimbus
Posts: 634
Joined: 19 Nov 2004, 20:38

Post by Michilus_nimbus »

As far as I can remember, you have to call GetUnitCount first, and call ProcessUnits for every unit before you can safely use the other unit-related functions.
User avatar
AF
AI Developer
Posts: 20687
Joined: 14 Sep 2004, 11:32

Post by AF »

so

Code: Select all

int n = GteUnitCount();
for(int i = 0; i < n){
    int x = ProcessUnits();
    AddUnit(GetUnitName(x));
}
Like that?
User avatar
AF
AI Developer
Posts: 20687
Joined: 14 Sep 2004, 11:32

Post by AF »

hmm that makes even elss sense now:

unitcount = CUnitSyncJNIBindings.ProcessUnits ();

unitcount now contains the fulll n# of units in that mod from the first call. If I was correct in my previous post it would be 1 and it would increment.

Sometimes I wonder why unitsync was written in such an archaic way without even a single comment to explain each function unless the functions usage is painfully obvious.

Code: Select all

int i = CUnitSyncJNIBindings.GetUnitCount();
System.out.println(i);
console wrote:1
User avatar
Michilus_nimbus
Posts: 634
Joined: 19 Nov 2004, 20:38

Post by Michilus_nimbus »

Ah, I remember now.
ProcessUnits returns the number of units that haven't been processed yet, and GetUnitCount returns the opposite.

so:

Code: Select all

while unitsync.ProcessUnits():
	pass
l = []
for i in range(0,unitsync.GetUnitCount()):
	l.append(unitsync.GetUnitName(i))
Would put every unit name in a list in Python
Last edited by Michilus_nimbus on 11 Jul 2007, 19:34, edited 1 time in total.
Kloot
Spring Developer
Posts: 1867
Joined: 08 Oct 2006, 16:58

Post by Kloot »

Basically correct yes. Here's some pseudocode to retrieve a mod's internal/external unit-names:

Code: Select all

AddAllArchives("XTAPE.sd7");
while (ProcessUnits() > 0);
int n = GetUnitCount();

for (int i = 0; i < n; i++) {
	cout << "unit: " << i << endl;
	cout << "int. name: " << GetUnitName(i) << endl; // eg. "armbbq"
	cout << "ext. name: " << GetFullUnitName(i) << endl; // eg. "Arm Barbebeque Rack"
}
Edit: beaten to the punch I see ;)
User avatar
AF
AI Developer
Posts: 20687
Joined: 14 Sep 2004, 11:32

Post by AF »

blah, while you wrote those replies I figured it out anyway:

Code: Select all

        units.clear ();
        while(CUnitSyncJNIBindings.ProcessUnits ()>0){}
        unitcount = CUnitSyncJNIBindings.GetUnitCount ();
        for(int i = 0; i < unitcount; i++){
            String s = CUnitSyncJNIBindings.GetUnitName (i);
            System.out.println(s);
            units.add (s);
        }
Now we just need a wiki page with all of this.
Tobi
Spring Developer
Posts: 4598
Joined: 01 Jun 2005, 11:36

Post by Tobi »

Why not convert it into a patch with some doxygen comments?

Then theres a much higher chance it will stay reasonably up to date and it stimulates others to add comments too.
User avatar
AF
AI Developer
Posts: 20687
Joined: 14 Sep 2004, 11:32

Post by AF »

How? Is there any documentation on howto document using doxygen?
Tobi
Spring Developer
Posts: 4598
Joined: 01 Jun 2005, 11:36

Post by Tobi »

http://www.stack.nl/~dimitri/doxygen/do ... #latestman

Or look at other functions that are already commented (thats by far the easiest :-)):
https://spring.clan-sy.com/svn/spring/t ... System.cpp

No need to bother with the initial *'s btw.
User avatar
AF
AI Developer
Posts: 20687
Joined: 14 Sep 2004, 11:32

Post by AF »

I've written a few doxygen comments for the functions involved here and one or two others. There're still lots of other functions undocumented but its a start.

Submitted to mantis.
User avatar
Agon
Posts: 527
Joined: 16 May 2007, 18:33

Post by Agon »

Yeah, a documentation for unitsync would be good.
A little question: Can I call the unitsync library from .net?
Tobi
Spring Developer
Posts: 4598
Joined: 01 Jun 2005, 11:36

Post by Tobi »

With P/Invoke it should be possible yeah.
User avatar
Agon
Posts: 527
Joined: 16 May 2007, 18:33

Post by Agon »

I hope mono supports p/invoke...!?
I will make a search on this.

Edit: Yeah should work: http://www.mono-project.com/Interop_wit ... _Libraries
Post Reply

Return to “Engine”