AFLobby

AFLobby

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

Moderator: Moderators

User avatar
AF
AI Developer
Posts: 20687
Joined: 14 Sep 2004, 11:32

AFLobby

Post by AF »

Image

There's a shot taken not long ago showing AFLobby logged into taspring.battlemaster.net. I'm in the process of setting up threads within the code to speed it up.

As you can see I've started on a games settings dialog, however this among other things will need UnitSync java bindings implemented to take advantage of.

Thus I need help writting the JNI code to bind UnitSync to java. My main qualm is minimaps, I only know how to write out TGA images, so I'll need someone to help with that.

Once I got some of the unitsync bindings done I'll ask the source code be commited to svn so that if I go the client doesnt go with me and someone else can pick it up.
Tobi
Spring Developer
Posts: 4598
Joined: 01 Jun 2005, 11:36

Post by Tobi »

Can't you directly use the data the C GetMinimap() function gives? ie. with java, is there no way to construct an image from raw RGB data (like with the python bindings)?

If that doesn't work try finding a format you can easily load from java, then pick the right library (libpng, libjpeg..?) to save it from C++ code (or use DevIL, I think it can save too).

You could look at screenshot code for example in spring, that saves to jpeg, so if you can load jpeg from java...

Edit: look at CBitmap::Save() in Bitmap.cpp
User avatar
AF
AI Developer
Posts: 20687
Joined: 14 Sep 2004, 11:32

Post by AF »

I ran extensive tetss and experiments tryign to Use libjpeg and DevIL in NTai and they all failed miserably despite spring sources.

Also when laoding an image in Java you'd shove it in an EditorPane as an ImageIcon object. However Todo that i have to cosntruct such an object out of a btye[] array which I havent a clue how todo despite googling for ages.

However the very simple solution is to feed in a filepath and tell UnitSync to save the file there. However I dont want users complaining of gigantic folders filled with TGA files.

So I'm not going to deal with that untill the very very very very end, so I'd prefer it if someone else did it for now.

I'll post the JUnitSync.java and it's c++ header counterpart soon.
Tobi
Spring Developer
Posts: 4598
Joined: 01 Jun 2005, 11:36

Post by Tobi »

You don't have to keep this TGAs around... one of the scripts I posted in the ML also just uses them temporarily, it dumps minimap to TGA, converts it to JPG using ImageMagick convert tool and erases the TGA...

Anyway if you post exactly the right info and java apidox and stuff I might take a look, but I don't promise anything as I'm quite busy atm (and have nil experience with any Java libs, let alone Java<->C++ bindings).

Edit: do you make sure your settings tab loads/saves correctly on linux too? ie. to ~/.springrc file filled with variable=value lines like this

Code: Select all

GroundDetail=40
LastListChoice0=Radar AI
LastListChoice1=Commanders
LastListChoice2=Random map
LastListChoice3=Xect vs. Mynn v0.6.3
ShowClock=1
ShowPlayerInfo=1
TreeRadius=1408
address=localhost
name=Tobi
User avatar
AF
AI Developer
Posts: 20687
Joined: 14 Sep 2004, 11:32

Post by AF »

The java binding definition ahs calls to UntiSync that specify 2 strings, one that value to be changed and the other the new value.

This would be a simple copy paste from the RTSSettings.exe code.

As for Java <_> c++ bindings, it aint as complicated as it sounds for basic stuff like strings and integers, e.g. jint is typedef jint int etc, only JString isnt a typedef and thats got 2 or 3 callback functions whcih can be used, whcih you'll see as I've already implemented one of the functions that uses jstring as an example.
hollowsoul
Posts: 665
Joined: 06 Jun 2006, 19:49

Post by hollowsoul »

*drools*
Cant wait till we get first public release nice work :)
Egarwaen
Posts: 1207
Joined: 27 Feb 2006, 21:19

Post by Egarwaen »

AF wrote:Also when laoding an image in Java you'd shove it in an EditorPane as an ImageIcon object. However Todo that i have to cosntruct such an object out of a btye[] array which I havent a clue how todo despite googling for ages.
What's the contents of the byte array? A raw bitmap or some kind of formatted image?

If it's a raw bitmap of some kind, I think you want to start with a java.awt.image.BufferedImage and then use a java.awt.image.DataBufferByte to construct a java.awt.image.Raster.
User avatar
smoth
Posts: 22309
Joined: 13 Jan 2005, 00:46

Post by smoth »

looks neat but this makes 3 lobbies?
User avatar
AF
AI Developer
Posts: 20687
Joined: 14 Sep 2004, 11:32

Post by AF »

3 linux comaptible lobbies, 4 lobbies altogether, but onyl 2 udner active dev(AFLobby/TASClient).
What's the contents of the byte array? A raw bitmap or some kind of formatted image?
I chose byte[] int eh interface as it was the closest to what i could see ti as beign in java<->c++.

Are there any examples for that or tutorials I can use?

Code: Select all

#define RM	0x0000F800
#define GM  0x000007E0
#define BM  0x0000001F

#define RED_RGB565(x) ((x&RM)>>11)
#define GREEN_RGB565(x) ((x&GM)>>5)
#define BLUE_RGB565(x) (x&BM)
#define PACKRGB(r, g, b) (((r<<11)&RM) | ((g << 5)&GM) | (b&BM) )

// Used to return the image
char* imgbuf[1024*1024*2];

DLL_EXPORT void* __stdcall GetMinimap(const char* filename, int miplevel)
{
This suggest something like a TGA image format with RGB values and no 4th alpha value, which means that that char* array becomes my byte[] array.
User avatar
AF
AI Developer
Posts: 20687
Joined: 14 Sep 2004, 11:32

Post by AF »

Code: Select all

typedef unsigned char	jboolean;
typedef unsigned short	jchar;
typedef short		jshort;
typedef float		jfloat;
typedef double		jdouble;

typedef jint            jsize;
Keep those in mind, I'll post an example dealing with jstring in a few minutes

Code: Select all

/* DO NOT EDIT THIS FILE - it is machine generated */
#include <jni.h>
/* Header for class jlobby_JUnitSync */

#ifndef _Included_jlobby_JUnitSync
#define _Included_jlobby_JUnitSync
#ifdef __cplusplus
extern "C" {
#endif
/*
 * Class:     jlobby_JUnitSync
 * Method:    Message
 * Signature: (Ljava/lang/String;)V
 */
JNIEXPORT void JNICALL Java_jlobby_JUnitSync_Message
  (JNIEnv *env, jclass jthis, jstring arg1);

/*
 * Class:     jlobby_JUnitSync
 * Method:    Init
 * Signature: (ZI)I
 */
JNIEXPORT jint JNICALL Java_jlobby_JUnitSync_Init
  (JNIEnv *env, jclass jthis, jboolean arg1, jint arg2);

/*
 * Class:     jlobby_JUnitSync
 * Method:    UnInit
 * Signature: ()V
 */
JNIEXPORT void JNICALL Java_jlobby_JUnitSync_UnInit
  (JNIEnv *env, jclass jthis);

/*
 * Class:     jlobby_JUnitSync
 * Method:    ProcessUnits
 * Signature: ()I
 */
JNIEXPORT jint JNICALL Java_jlobby_JUnitSync_ProcessUnits
  (JNIEnv *env, jclass jthis);

/*
 * Class:     jlobby_JUnitSync
 * Method:    ProcessUnitsNoChecksum
 * Signature: ()I
 */
JNIEXPORT jint JNICALL Java_jlobby_JUnitSync_ProcessUnitsNoChecksum
  (JNIEnv *env, jclass jthis);

/*
 * Class:     jlobby_JUnitSync
 * Method:    GetCurrentList
 * Signature: ()Ljava/lang/String;
 */
JNIEXPORT jstring JNICALL Java_jlobby_JUnitSync_GetCurrentList
  (JNIEnv *env, jclass jthis);

/*
 * Class:     jlobby_JUnitSync
 * Method:    AddClient
 * Signature: (ILjava/lang/String;)V
 */
JNIEXPORT void JNICALL Java_jlobby_JUnitSync_AddClient
  (JNIEnv *env, jclass jthis, jint arg1, jstring arg2);

/*
 * Class:     jlobby_JUnitSync
 * Method:    RemoveClient
 * Signature: (I)V
 */
JNIEXPORT void JNICALL Java_jlobby_JUnitSync_RemoveClient
  (JNIEnv *env, jclass jthis, jint arg1);

/*
 * Class:     jlobby_JUnitSync
 * Method:    GetClientDiff
 * Signature: (I)Ljava/lang/String;
 */
JNIEXPORT jstring JNICALL Java_jlobby_JUnitSync_GetClientDiff
  (JNIEnv *env, jclass jthis, jint arg1);

/*
 * Class:     jlobby_JUnitSync
 * Method:    InstallClientDiff
 * Signature: (Ljava/lang/String;)V
 */
JNIEXPORT void JNICALL Java_jlobby_JUnitSync_InstallClientDiff
  (JNIEnv *env, jclass jthis, jstring arg1);

/*
 * Class:     jlobby_JUnitSync
 * Method:    GetUnitCount
 * Signature: ()I
 */
JNIEXPORT jint JNICALL Java_jlobby_JUnitSync_GetUnitCount
  (JNIEnv *env, jclass jthis);

/*
 * Class:     jlobby_JUnitSync
 * Method:    GetUnitName
 * Signature: (I)Ljava/lang/String;
 */
JNIEXPORT jstring JNICALL Java_jlobby_JUnitSync_GetUnitName
  (JNIEnv *env, jclass jthis, jint arg1);

/*
 * Class:     jlobby_JUnitSync
 * Method:    GetFullUnitName
 * Signature: (I)Ljava/lang/String;
 */
JNIEXPORT jstring JNICALL Java_jlobby_JUnitSync_GetFullUnitName
  (JNIEnv *env, jclass jthis, jint arg1);

/*
 * Class:     jlobby_JUnitSync
 * Method:    IsUnitDisabled
 * Signature: (I)I
 */
JNIEXPORT jint JNICALL Java_jlobby_JUnitSync_IsUnitDisabled
  (JNIEnv *env, jclass jthis, jint arg1);

/*
 * Class:     jlobby_JUnitSync
 * Method:    IsUnitDisabledByClient
 * Signature: (II)I
 */
JNIEXPORT jint JNICALL Java_jlobby_JUnitSync_IsUnitDisabledByClient
  (JNIEnv *env, jclass jthis, jint arg1, jint arg2);

/*
 * Class:     jlobby_JUnitSync
 * Method:    InitArchiveScanner
 * Signature: ()I
 */
JNIEXPORT jint JNICALL Java_jlobby_JUnitSync_InitArchiveScanner
  (JNIEnv *env, jclass jthis);

/*
 * Class:     jlobby_JUnitSync
 * Method:    AddArchive
 * Signature: (Ljava/lang/String;)V
 */
JNIEXPORT void JNICALL Java_jlobby_JUnitSync_AddArchive
  (JNIEnv *env, jclass jthis, jstring arg1);

/*
 * Class:     jlobby_JUnitSync
 * Method:    AddAllArchives
 * Signature: (Ljava/lang/String;)V
 */
JNIEXPORT void JNICALL Java_jlobby_JUnitSync_AddAllArchives
  (JNIEnv *env, jclass jthis, jstring arg1);

/*
 * Class:     jlobby_JUnitSync
 * Method:    GetArchiveChecksum
 * Signature: (Ljava/lang/String;)I
 */
JNIEXPORT jint JNICALL Java_jlobby_JUnitSync_GetArchiveChecksum
  (JNIEnv *env, jclass jthis, jstring arg1);

/*
 * Class:     jlobby_JUnitSync
 * Method:    GetMapCount
 * Signature: ()I
 */
JNIEXPORT jint JNICALL Java_jlobby_JUnitSync_GetMapCount
  (JNIEnv *env, jclass jthis);

/*
 * Class:     jlobby_JUnitSync
 * Method:    GetMapName
 * Signature: (I)Ljava/lang/String;
 */
JNIEXPORT jstring JNICALL Java_jlobby_JUnitSync_GetMapName
  (JNIEnv *env, jclass jthis, jint arg1);

/*
 * Class:     jlobby_JUnitSync
 * Method:    GetMapInfo
 * Signature: (Ljava/lang/String;)Ljlobby/JUnitSync/MapInfo;
 */
JNIEXPORT jobject JNICALL Java_jlobby_JUnitSync_GetMapInfo
  (JNIEnv *env, jclass jthis, jstring arg1);

/*
 * Class:     jlobby_JUnitSync
 * Method:    GetSTartingPositions
 * Signature: (Ljava/lang/String;)[Ljlobby/JUnitSync/StartPos;
 */
JNIEXPORT jobjectArray JNICALL Java_jlobby_JUnitSync_GetSTartingPositions
  (JNIEnv *env, jclass jthis, jstring arg1);

/*
 * Class:     jlobby_JUnitSync
 * Method:    GetMinimap
 * Signature: (Ljava/lang/String;I)[B
 */
JNIEXPORT jbyteArray JNICALL Java_jlobby_JUnitSync_GetMinimap
  (JNIEnv *env, jclass jthis, jstring arg1, jint arg2);

/*
 * Class:     jlobby_JUnitSync
 * Method:    WriteMinimap
 * Signature: (Ljava/lang/String;Ljava/lang/String;)Z
 */
JNIEXPORT jboolean JNICALL Java_jlobby_JUnitSync_WriteMinimap
  (JNIEnv *env, jclass jthis, jstring arg1, jstring arg2);

/*
 * Class:     jlobby_JUnitSync
 * Method:    GetIntProperty
 * Signature: (Ljava/lang/String;)I
 */
JNIEXPORT jint JNICALL Java_jlobby_JUnitSync_GetIntProperty
  (JNIEnv *env, jclass jthis, jstring arg1);

/*
 * Class:     jlobby_JUnitSync
 * Method:    GetStringProperty
 * Signature: (Ljava/lang/String;)Ljava/lang/String;
 */
JNIEXPORT jstring JNICALL Java_jlobby_JUnitSync_GetStringProperty
  (JNIEnv *env, jclass jthis, jstring arg1);

/*
 * Class:     jlobby_JUnitSync
 * Method:    GetBooleanProperty
 * Signature: (Ljava/lang/String;)Z
 */
JNIEXPORT jboolean JNICALL Java_jlobby_JUnitSync_GetBooleanProperty
  (JNIEnv *env, jclass jthis, jstring arg1);

/*
 * Class:     jlobby_JUnitSync
 * Method:    SetIntProperty
 * Signature: (I)V
 */
JNIEXPORT void JNICALL Java_jlobby_JUnitSync_SetIntProperty
  (JNIEnv *env, jclass jthis, jint arg1);

/*
 * Class:     jlobby_JUnitSync
 * Method:    SetStringProperty
 * Signature: (Ljava/lang/String;)V
 */
JNIEXPORT void JNICALL Java_jlobby_JUnitSync_SetStringProperty
  (JNIEnv *env, jclass jthis, jstring arg1);

/*
 * Class:     jlobby_JUnitSync
 * Method:    SetBooleanProperty
 * Signature: (Z)V
 */
JNIEXPORT void JNICALL Java_jlobby_JUnitSync_SetBooleanProperty
  (JNIEnv *env, jclass jthis, jboolean arg1);

/*
 * Class:     jlobby_JUnitSync
 * Method:    GetDatapath
 * Signature: ()Ljava/lang/String;
 */
JNIEXPORT jstring JNICALL Java_jlobby_JUnitSync_GetDatapath
  (JNIEnv *env, jclass jthis);

/*
 * Class:     jlobby_JUnitSync
 * Method:    GetMapHash
 * Signature: (Ljava/lang/String;)Ljava/lang/String;
 */
JNIEXPORT jstring JNICALL Java_jlobby_JUnitSync_GetMapHash
  (JNIEnv *env, jclass jthis, jstring arg1);

/*
 * Class:     jlobby_JUnitSync
 * Method:    GetModHash
 * Signature: (Ljava/lang/String;)Ljava/lang/String;
 */
JNIEXPORT jstring JNICALL Java_jlobby_JUnitSync_GetModHash
  (JNIEnv *env, jclass jthis, jstring arg1);

/*
 * Class:     jlobby_JUnitSync
 * Method:    GetPrimaryModCount
 * Signature: ()I
 */
JNIEXPORT jint JNICALL Java_jlobby_JUnitSync_GetPrimaryModCount
  (JNIEnv *env, jclass jthis);

/*
 * Class:     jlobby_JUnitSync
 * Method:    GetPrimaryModName
 * Signature: (I)Ljava/lang/String;
 */
JNIEXPORT jstring JNICALL Java_jlobby_JUnitSync_GetPrimaryModName
  (JNIEnv *env, jclass jthis, jint arg1);

/*
 * Class:     jlobby_JUnitSync
 * Method:    GetPrimaryModArchive
 * Signature: (I)Ljava/lang/String;
 */
JNIEXPORT jstring JNICALL Java_jlobby_JUnitSync_GetPrimaryModArchive
  (JNIEnv *env, jclass jthis, jint arg1);

/*
 * Class:     jlobby_JUnitSync
 * Method:    GetPrimaryModArchiveCount
 * Signature: (I)I
 */
JNIEXPORT jint JNICALL Java_jlobby_JUnitSync_GetPrimaryModArchiveCount
  (JNIEnv *env, jclass jthis, jint arg1);

/*
 * Class:     jlobby_JUnitSync
 * Method:    GetPrimaryModArchiveList
 * Signature: (I)Ljava/lang/String;
 */
JNIEXPORT jstring JNICALL Java_jlobby_JUnitSync_GetPrimaryModArchiveList
  (JNIEnv *env, jclass jthis, jint arg1);

/*
 * Class:     jlobby_JUnitSync
 * Method:    GetPrimaryModIndex
 * Signature: (Ljava/lang/String;)I
 */
JNIEXPORT jint JNICALL Java_jlobby_JUnitSync_GetPrimaryModIndex
  (JNIEnv *env, jclass jthis, jstring arg1);

/*
 * Class:     jlobby_JUnitSync
 * Method:    GetSideCount
 * Signature: ()I
 */
JNIEXPORT jint JNICALL Java_jlobby_JUnitSync_GetSideCount
  (JNIEnv *env, jclass jthis);

/*
 * Class:     jlobby_JUnitSync
 * Method:    GetSideName
 * Signature: (I)Ljava/lang/String;
 */
JNIEXPORT jstring JNICALL Java_jlobby_JUnitSync_GetSideName
  (JNIEnv *env, jclass jthis, jint arg1);

/*
 * Class:     jlobby_JUnitSync
 * Method:    OpenFileVFS
 * Signature: (Ljava/lang/String;)I
 */
JNIEXPORT jint JNICALL Java_jlobby_JUnitSync_OpenFileVFS
  (JNIEnv *env, jclass jthis, jstring arg1);

/*
 * Class:     jlobby_JUnitSync
 * Method:    CloseFileVFS
 * Signature: (I)V
 */
JNIEXPORT void JNICALL Java_jlobby_JUnitSync_CloseFileVFS
  (JNIEnv *env, jclass jthis, jint arg1);

/*
 * Class:     jlobby_JUnitSync
 * Method:    ReadFileVFS
 * Signature: (II)[B
 */
JNIEXPORT jbyteArray JNICALL Java_jlobby_JUnitSync_ReadFileVFS
  (JNIEnv *env, jclass jthis, jint arg1, jint arg2);

/*
 * Class:     jlobby_JUnitSync
 * Method:    FileSizeVFS
 * Signature: (I)I
 */
JNIEXPORT jint JNICALL Java_jlobby_JUnitSync_FileSizeVFS
  (JNIEnv *env, jclass jthis, jint arg1);

/*
 * Class:     jlobby_JUnitSync
 * Method:    OpenArchive
 * Signature: (Ljava/lang/String;)I
 */
JNIEXPORT jint JNICALL Java_jlobby_JUnitSync_OpenArchive
  (JNIEnv *env, jclass jthis, jstring arg1);

/*
 * Class:     jlobby_JUnitSync
 * Method:    CloseArchive
 * Signature: (I)V
 */
JNIEXPORT void JNICALL Java_jlobby_JUnitSync_CloseArchive
  (JNIEnv *env, jclass jthis, jint arg1);

/*
 * Class:     jlobby_JUnitSync
 * Method:    OpenArchiveFile
 * Signature: (ILjava/lang/String;)I
 */
JNIEXPORT jint JNICALL Java_jlobby_JUnitSync_OpenArchiveFile
  (JNIEnv *env, jclass jthis, jint arg1, jstring arg2);

/*
 * Class:     jlobby_JUnitSync
 * Method:    ReadArchiveFile
 * Signature: (III)Ljava/lang/String;
 */
JNIEXPORT jstring JNICALL Java_jlobby_JUnitSync_ReadArchiveFile
  (JNIEnv *env, jclass jthis, jint arg1, jint arg2, jint arg3);

/*
 * Class:     jlobby_JUnitSync
 * Method:    CloseArchiveFile
 * Signature: (II)V
 */
JNIEXPORT void JNICALL Java_jlobby_JUnitSync_CloseArchiveFile
  (JNIEnv *env, jclass jthis, jint arg1, jint arg2);

/*
 * Class:     jlobby_JUnitSync
 * Method:    SizeArchiveFile
 * Signature: (II)I
 */
JNIEXPORT jint JNICALL Java_jlobby_JUnitSync_SizeArchiveFile
  (JNIEnv *env, jclass jthis, jint arg1, jint arg2);

#ifdef __cplusplus
}
#endif
#endif
User avatar
AF
AI Developer
Posts: 20687
Joined: 14 Sep 2004, 11:32

Post by AF »

A quick addition

Code: Select all

/*
* Class:     jlobby_JUnitSync
* Method:    GetPassHash
* Signature: (II)I
*/
JNIEXPORT jstring JNICALL Java_jlobby_JUnitSync_GetPassHash
(JNIEnv *env, jclass jthis, jstring arg1);
The code for that will have to be taken from QSpring. The code in t java Misc class Betalord wrote gives a different hash fromt he one required resulting in bad user/pass messages from the server.

Now for JUnitSync.java

Code: Select all

package jlobby;

import java.util.Vector;

/**
 * JUnitSync.java
 * @author AF
 */
public class JUnitSync {
    
    /** Creates a new instance of JUnitSync */
    public JUnitSync() {
    }
    // load up the UnitSync.dll/UnitSync.so library
    public boolean loaded = false;
    public void LoadUnitSync(){
        //
    }
    // for all intensive purposes any mention of void* has been replaced with
    // byte[], hwoever I have a feeling this is wrong cosnidering why they used
    // void* to begin with.
    
    // this was added ehre so that I could take the QSpring code that generates
    // the MD5 base 64 password hash, rather than use my java implementation
    // which doesnt work the way ti should.
    public static native String GetPassHash(String password);
    public static native void Message(String p_szMessage);
    public static native int Init(boolean isServer, int id);
    public static native void UnInit();
    public static native int ProcessUnits();
    public static native int ProcessUnitsNoChecksum();
    public static native String GetCurrentList();
    public static native void AddClient(int id, String unitList);
    public static native void RemoveClient(int id);
    public static native String GetClientDiff(int id);
    public static native void InstallClientDiff(String diff);
    public static native int GetUnitCount();
    public static native String GetUnitName(int unit);
    public static native String GetFullUnitName(int unit);
    public static native int IsUnitDisabled(int unit);
    public static native int IsUnitDisabledByClient(int unit, int clientId);

    //////////////////////////
    //////////////////////////

    public static native int  InitArchiveScanner();
    public static native void  AddArchive(String name);
    public static native void  AddAllArchives(String root);
    public static native int  GetArchiveChecksum(String arname);
    public static native int  GetMapCount();
    public static native String GetMapName(int index);
    public Vector<String> GetMapList(){
        Vector<String> v = new Vector<String>();
        int j = GetMapCount();
        for(int i = 0; i < j; i++){
            v.add(GetMapName(i));
        }
        return v;
    }

    class StartPos{
        int x;
        int z;
    };
    class MapInfo{
	String description;
	int tidalStrength;
	int gravity;
	float maxMetal;
	int extractorRadius;
	int minWind;
	int maxWind;

	// 0.61b1+
	int width;
	int height;
	int posCount;
    };
    public static native MapInfo GetMapInfo(String name);
    public static native StartPos[] GetSTartingPositions(String name);
/*
    #define RM	0x0000F800
    #define GM  0x000007E0
    #define BM  0x0000001F

    #define RED_RGB565(x) ((x&RM)>>11)
    #define GREEN_RGB565(x) ((x&GM)>>5)
    #define BLUE_RGB565(x) (x&BM)
    #define PACKRGB(r, g, b) (((r<<11)&RM) | ((g << 5)&GM) | (b&BM) )
*/

    public static native byte[]  GetMinimap(String filename, int miplevel);
    public static native boolean WriteMinimap(String mapname, String target);
    /* Write the minimap of the map to a jpeg at the 'target' location*/
    
    public static native int GetIntProperty(String value);
    public static native String GetStringProperty(String value);
    public static native boolean GetBooleanProperty(String value);

    public static native void SetIntProperty(int value);
    public static native void SetStringProperty(String value);
    public static native void SetBooleanProperty(boolean value);
    
    public static native String GetDatapath();
    
    public static native String GetMapHash(String mapname);
    public static native String GetModHash(String modname);

    //////////////////////////
    //////////////////////////

    public static native int  GetPrimaryModCount();
    public static native String   GetPrimaryModName(int index);
    public static native String GetPrimaryModArchive(int index);
    public Vector<String> GetModList(){
        Vector<String> v = new Vector<String>();
        int j = GetPrimaryModCount();
        for(int i = 0; i < j; i++){
            v.add(GetMapName(i));
        }
        return v;
    }

    /*
     * These two funtions are used to get the entire list of archives that a mod
     * requires. Call ..Count with selected mod first to get number of archives,
     * and then use ..List for 0 to count-1 to get the name of each archive.
     */

    public static native int  GetPrimaryModArchiveCount(int index);
    public static native String   GetPrimaryModArchiveList(int arnr);
    public static native int  GetPrimaryModIndex(String name);
    //////////////////////////
    //////////////////////////
    public static native int GetSideCount();
    public static native String GetSideName(int side);
    public Vector<String> GetSideList(){
        Vector<String> v = new Vector<String>();
        int j = GetSideCount();
        for(int i = 0; i < j; i++){
            v.add(GetSideName(i));
        }
        return v;
    }

    public static native int OpenFileVFS(String name);
    public static native void CloseFileVFS(int handle);
    public static native byte[] ReadFileVFS(int handle, int length);
    public static native int FileSizeVFS(int handle);
    
    public static native int OpenArchive(String name);
    public static native void CloseArchive(int archive);
    
    //DLL_EXPORT int __stdcall FindFilesArchive(int archive, int cur, char* nameBuf, int* size)
    public static native int OpenArchiveFile(int archive, String name);
    public static native String ReadArchiveFile(int archive, int handle, int numBytes);
    public static native void CloseArchiveFile(int archive, int handle);
    public static native int SizeArchiveFile(int archive, int handle);
    //
    
}
User avatar
LOrDo
Posts: 1154
Joined: 27 Feb 2006, 00:21

Post by LOrDo »

So is there any point of getting this if we have windows?
User avatar
AF
AI Developer
Posts: 20687
Joined: 14 Sep 2004, 11:32

Post by AF »

yes, this will work anywhere that ahs a Java runtime installed.

Thsi lobby also has unique features such as avatars and multiline messaging aswell as a nicer GUI...

This is of course relying on the fact that I can call the exported UntiSync functions from the java bindings but it's a quick example of creatign jstring objects

Code: Select all

/*
 * Class:     jlobby_JUnitSync
 * Method:    GetMapName
 * Signature: (I)Ljava/lang/String;
 */
JNIEXPORT jstring JNICALL Java_jlobby_JUnitSync_GetMapName
(JNIEnv *env, jclass jthis, jint arg1){
	const char* c = GetMapName(arg1);
	jstring s = env->NewStringUTF(c);
	return s;
}
newStringUTF may take JNIEnv* env as its first parameter but it isnt needed unless you're using pure C as far as I remember.
User avatar
LOrDo
Posts: 1154
Joined: 27 Feb 2006, 00:21

Post by LOrDo »

So is there any point of getting this if we have windows?

Edit: Wtf? Sugababes?

Edit2: How this posted twice is beyond me...
Last edited by LOrDo on 01 Jul 2006, 06:34, edited 1 time in total.
User avatar
AF
AI Developer
Posts: 20687
Joined: 14 Sep 2004, 11:32

Post by AF »

Yes there is a point in getting this if you have windows.

Else altaric would be out of business by now
Tobi
Spring Developer
Posts: 4598
Joined: 01 Jun 2005, 11:36

Post by Tobi »

AF wrote:3 linux comaptible lobbies, 4 lobbies altogether, but onyl 2 udner active dev(AFLobby/TASClient).
What's the contents of the byte array? A raw bitmap or some kind of formatted image?
I chose byte[] int eh interface as it was the closest to what i could see ti as beign in java<->c++.

Are there any examples for that or tutorials I can use?

Code: Select all

#define RM	0x0000F800
#define GM  0x000007E0
#define BM  0x0000001F

#define RED_RGB565(x) ((x&RM)>>11)
#define GREEN_RGB565(x) ((x&GM)>>5)
#define BLUE_RGB565(x) (x&BM)
#define PACKRGB(r, g, b) (((r<<11)&RM) | ((g << 5)&GM) | (b&BM) )

// Used to return the image
char* imgbuf[1024*1024*2];

DLL_EXPORT void* __stdcall GetMinimap(const char* filename, int miplevel)
{
This suggest something like a TGA image format with RGB values and no 4th alpha value, which means that that char* array becomes my byte[] array.
It's 16 bit RGB (5 bits for red, 6 bits for green, 5 bits for blue).

E: miplevel sets the size. Miplevel == 0 -> 1024x1024 pixels (hence the size of the imgbuf, (16 bits/pixel) / (8 bits/byte) * (1024*1024 pixel) == 2*1024*1024 bytes), Miplevel == 1 -> 512x512, Miplevel == 2 -> 256x256, etc. (dividing by two every step).

to access certain pixel you'd use for example (C++ code)

Code: Select all

#define RM	0x0000F800
#define GM  0x000007E0
#define BM  0x0000001F

#define RED_RGB565(x) ((x&RM)>>11)
#define GREEN_RGB565(x) ((x&GM)>>5)
#define BLUE_RGB565(x) (x&BM)

void GetPixel(void* imgbuf, int w, int h, int x, int y, int&r, int&g, int&b) {
  // cast to short, it's easier
  unsigned short* img = (unsigned short*) imgbuf;
  int pix = img[y*w+x];
  r = RED_RGB565(pix) << 3; // shift to get in 0-255 range
  g = GREEN_RGB565(pix) << 2;
  b = BLUE_RGB565(pix) << 3;
}
Maybe that gets you going in converting it to some java readable format. Make sure you fully understand the 5/6/5 packed pixel format as used here then find some java thingie which can load it or convert it on the fly to 8/8/8 24 bit image.
Last edited by Tobi on 30 Jun 2006, 09:22, edited 1 time in total.
User avatar
NOiZE
Balanced Annihilation Developer
Posts: 3984
Joined: 28 Apr 2005, 19:29

Post by NOiZE »

would be kool if it would be able to draw the waterlevel on the minimap
Tobi
Spring Developer
Posts: 4598
Joined: 01 Jun 2005, 11:36

Post by Tobi »

think that's impossible as unitsync can't access the heightmap...
User avatar
NOiZE
Balanced Annihilation Developer
Posts: 3984
Joined: 28 Apr 2005, 19:29

Post by NOiZE »

awwww

EDIT

patch it?
Torrasque
Posts: 1022
Joined: 05 Oct 2004, 23:55

Post by Torrasque »

NOiZE wrote:would be kool if it would be able to draw the waterlevel on the minimap
Yeah, that would be cool ! but wouldn't we have to repath for every water height ?
Post Reply

Return to “Engine”