20 import org.hedgewars.hedgeroid.Datastructures.Weaponset; |
20 import org.hedgewars.hedgeroid.Datastructures.Weaponset; |
21 |
21 |
22 import com.sun.jna.Callback; |
22 import com.sun.jna.Callback; |
23 import com.sun.jna.Library; |
23 import com.sun.jna.Library; |
24 import com.sun.jna.Memory; |
24 import com.sun.jna.Memory; |
25 import com.sun.jna.NativeLong; |
|
26 import com.sun.jna.Pointer; |
25 import com.sun.jna.Pointer; |
27 import com.sun.jna.PointerType; |
26 import com.sun.jna.PointerType; |
28 import com.sun.jna.Structure; |
27 import com.sun.jna.Structure; |
29 |
28 |
30 /** |
29 /** |
120 * that file will make the compiler see the Java method signatures as C function |
119 * that file will make the compiler see the Java method signatures as C function |
121 * declarations. Since the same functions are already declared in the frontlib |
120 * declarations. Since the same functions are already declared in the frontlib |
122 * headers, the compiler will give you errors if the signatures don't match. |
121 * headers, the compiler will give you errors if the signatures don't match. |
123 */ |
122 */ |
124 public interface Frontlib extends Library { |
123 public interface Frontlib extends Library { |
125 static final int NATIVE_INT_SIZE = 4; |
|
126 static final int NATIVE_BOOL_SIZE = 1; |
|
127 |
|
128 public static class NetconnPtr extends PointerType { } |
124 public static class NetconnPtr extends PointerType { } |
129 public static class MapconnPtr extends PointerType { } |
125 public static class MapconnPtr extends PointerType { } |
130 public static class GameconnPtr extends PointerType { } |
126 public static class GameconnPtr extends PointerType { } |
131 |
127 |
132 // TODO avoid code duplication in the pointer types |
|
133 public static class MetaschemePtr extends PointerType { |
128 public static class MetaschemePtr extends PointerType { |
134 public MetaScheme deref() { |
129 public MetaScheme deref() { |
135 return deref(getPointer()); |
130 return deref(getPointer()); |
136 } |
131 } |
137 |
132 |
553 theme = map.theme; |
548 theme = map.theme; |
554 byte[] buf = map.getDrawData(); |
549 byte[] buf = map.getDrawData(); |
555 if(buf != null) { |
550 if(buf != null) { |
556 drawData = new Memory(buf.length); |
551 drawData = new Memory(buf.length); |
557 drawData.write(0, buf, 0, buf.length); |
552 drawData.write(0, buf, 0, buf.length); |
558 drawDataSize = new NativeLong(buf.length); |
553 drawDataSize = NativeSizeT.valueOf(buf.length); |
559 } else { |
554 } else { |
560 drawData = null; |
555 drawData = null; |
561 drawDataSize = new NativeLong(0); |
556 drawDataSize = NativeSizeT.valueOf(0); |
562 } |
557 } |
563 templateFilter = map.templateFilter; |
558 templateFilter = map.templateFilter; |
564 mazeSize = map.mazeSize; |
559 mazeSize = map.mazeSize; |
565 } |
560 } |
566 |
561 |
685 public SchemeStruct(Pointer ptr) { super(ptr); setFieldOrder(FIELD_ORDER); } |
680 public SchemeStruct(Pointer ptr) { super(ptr); setFieldOrder(FIELD_ORDER); } |
686 |
681 |
687 public void fillFrom(Scheme scheme) { |
682 public void fillFrom(Scheme scheme) { |
688 MetaScheme meta = MetaScheme.INSTANCE; |
683 MetaScheme meta = MetaScheme.INSTANCE; |
689 name = scheme.name; |
684 name = scheme.name; |
690 settings = new Memory(NATIVE_INT_SIZE * meta.settings.size()); |
685 settings = new Memory(AndroidTypeMapper.NATIVE_INT_SIZE * meta.settings.size()); |
691 for(int i=0; i<meta.settings.size(); i++) { |
686 for(int i=0; i<meta.settings.size(); i++) { |
692 Integer value = scheme.settings.get(meta.settings.get(i).name); |
687 Integer value = scheme.settings.get(meta.settings.get(i).name); |
693 settings.setInt(NATIVE_INT_SIZE*i, value); |
688 settings.setInt(AndroidTypeMapper.NATIVE_INT_SIZE*i, value); |
694 } |
689 } |
695 mods = new Memory(NATIVE_BOOL_SIZE * meta.mods.size()); |
690 mods = new Memory(AndroidTypeMapper.NATIVE_BOOL_SIZE * meta.mods.size()); |
696 for(int i=0; i<meta.mods.size(); i++) { |
691 for(int i=0; i<meta.mods.size(); i++) { |
697 Boolean value = scheme.mods.get(meta.mods.get(i).name); |
692 Boolean value = scheme.mods.get(meta.mods.get(i).name); |
698 mods.setByte(NATIVE_BOOL_SIZE*i, (byte)(value ? 1 : 0)); |
693 mods.setByte(AndroidTypeMapper.NATIVE_BOOL_SIZE*i, (byte)(value ? 1 : 0)); |
699 } |
694 } |
700 } |
695 } |
701 |
696 |
702 public Scheme toScheme() { |
697 public Scheme toScheme() { |
703 Map<String, Integer> settingsMap = new HashMap<String, Integer>(); |
698 Map<String, Integer> settingsMap = new HashMap<String, Integer>(); |
704 MetaScheme meta = MetaScheme.INSTANCE; |
699 MetaScheme meta = MetaScheme.INSTANCE; |
705 for(int i=0; i<meta.settings.size(); i++) { |
700 for(int i=0; i<meta.settings.size(); i++) { |
706 settingsMap.put(meta.settings.get(i).name, settings.getInt(NATIVE_INT_SIZE*i)); |
701 settingsMap.put(meta.settings.get(i).name, settings.getInt(AndroidTypeMapper.NATIVE_INT_SIZE*i)); |
707 } |
702 } |
708 Map<String, Boolean> modsMap = new HashMap<String, Boolean>(); |
703 Map<String, Boolean> modsMap = new HashMap<String, Boolean>(); |
709 for(int i=0; i<meta.mods.size(); i++) { |
704 for(int i=0; i<meta.mods.size(); i++) { |
710 modsMap.put(meta.mods.get(i).name, mods.getByte(i) != 0 ? Boolean.TRUE : Boolean.FALSE); |
705 modsMap.put(meta.mods.get(i).name, mods.getByte(i) != 0 ? Boolean.TRUE : Boolean.FALSE); |
711 } |
706 } |
932 public static interface TeamCallback extends Callback { |
927 public static interface TeamCallback extends Callback { |
933 void callback(Pointer context, TeamPtr arg1); |
928 void callback(Pointer context, TeamPtr arg1); |
934 } |
929 } |
935 |
930 |
936 public static interface BytesCallback extends Callback { |
931 public static interface BytesCallback extends Callback { |
937 void callback(Pointer context, Pointer buffer, NativeLong size); |
932 void callback(Pointer context, Pointer buffer, NativeSizeT size); |
938 } |
933 } |
939 |
934 |
940 public static interface BytesBoolCallback extends Callback { |
935 public static interface BytesBoolCallback extends Callback { |
941 void callback(Pointer context, Pointer buffer, NativeLong size, boolean arg3); |
936 void callback(Pointer context, Pointer buffer, NativeSizeT size, boolean arg3); |
942 } |
937 } |
943 |
938 |
944 public static interface SchemeCallback extends Callback { |
939 public static interface SchemeCallback extends Callback { |
945 void callback(Pointer context, SchemePtr arg1); |
940 void callback(Pointer context, SchemePtr arg1); |
946 } |
941 } |
1019 int flib_netconn_send_renameRoom(NetconnPtr conn, String roomName); |
1014 int flib_netconn_send_renameRoom(NetconnPtr conn, String roomName); |
1020 int flib_netconn_send_leaveRoom(NetconnPtr conn, String msg); |
1015 int flib_netconn_send_leaveRoom(NetconnPtr conn, String msg); |
1021 int flib_netconn_send_toggleReady(NetconnPtr conn); |
1016 int flib_netconn_send_toggleReady(NetconnPtr conn); |
1022 int flib_netconn_send_addTeam(NetconnPtr conn, TeamPtr team); |
1017 int flib_netconn_send_addTeam(NetconnPtr conn, TeamPtr team); |
1023 int flib_netconn_send_removeTeam(NetconnPtr conn, String teamname); |
1018 int flib_netconn_send_removeTeam(NetconnPtr conn, String teamname); |
1024 int flib_netconn_send_engineMessage(NetconnPtr conn, Pointer message, NativeLong size); |
1019 int flib_netconn_send_engineMessage(NetconnPtr conn, Pointer message, NativeSizeT size); |
1025 int flib_netconn_send_teamHogCount(NetconnPtr conn, String teamname, int hogcount); |
1020 int flib_netconn_send_teamHogCount(NetconnPtr conn, String teamname, int hogcount); |
1026 int flib_netconn_send_teamColor(NetconnPtr conn, String teamname, int colorIndex); |
1021 int flib_netconn_send_teamColor(NetconnPtr conn, String teamname, int colorIndex); |
1027 int flib_netconn_send_weaponset(NetconnPtr conn, WeaponsetPtr weaponset); |
1022 int flib_netconn_send_weaponset(NetconnPtr conn, WeaponsetPtr weaponset); |
1028 int flib_netconn_send_map(NetconnPtr conn, MapRecipePtr map); |
1023 int flib_netconn_send_map(NetconnPtr conn, MapRecipePtr map); |
1029 int flib_netconn_send_mapName(NetconnPtr conn, String mapName); |
1024 int flib_netconn_send_mapName(NetconnPtr conn, String mapName); |
1030 int flib_netconn_send_mapGen(NetconnPtr conn, int mapGen); |
1025 int flib_netconn_send_mapGen(NetconnPtr conn, int mapGen); |
1031 int flib_netconn_send_mapTemplate(NetconnPtr conn, int templateFilter); |
1026 int flib_netconn_send_mapTemplate(NetconnPtr conn, int templateFilter); |
1032 int flib_netconn_send_mapMazeSize(NetconnPtr conn, int mazeSize); |
1027 int flib_netconn_send_mapMazeSize(NetconnPtr conn, int mazeSize); |
1033 int flib_netconn_send_mapSeed(NetconnPtr conn, String seed); |
1028 int flib_netconn_send_mapSeed(NetconnPtr conn, String seed); |
1034 int flib_netconn_send_mapTheme(NetconnPtr conn, String theme); |
1029 int flib_netconn_send_mapTheme(NetconnPtr conn, String theme); |
1035 int flib_netconn_send_mapDrawdata(NetconnPtr conn, Pointer drawData, NativeLong size); |
1030 int flib_netconn_send_mapDrawdata(NetconnPtr conn, Pointer drawData, NativeSizeT size); |
1036 int flib_netconn_send_script(NetconnPtr conn, String scriptName); |
1031 int flib_netconn_send_script(NetconnPtr conn, String scriptName); |
1037 int flib_netconn_send_scheme(NetconnPtr conn, SchemePtr scheme); |
1032 int flib_netconn_send_scheme(NetconnPtr conn, SchemePtr scheme); |
1038 int flib_netconn_send_roundfinished(NetconnPtr conn, boolean withoutError); |
1033 int flib_netconn_send_roundfinished(NetconnPtr conn, boolean withoutError); |
1039 int flib_netconn_send_ban(NetconnPtr conn, String playerName); |
1034 int flib_netconn_send_ban(NetconnPtr conn, String playerName); |
1040 int flib_netconn_send_kick(NetconnPtr conn, String playerName); |
1035 int flib_netconn_send_kick(NetconnPtr conn, String playerName); |
1084 static final int GAME_END_INTERRUPTED = 1; |
1079 static final int GAME_END_INTERRUPTED = 1; |
1085 static final int GAME_END_HALTED = 2; |
1080 static final int GAME_END_HALTED = 2; |
1086 static final int GAME_END_ERROR = 3; |
1081 static final int GAME_END_ERROR = 3; |
1087 |
1082 |
1088 GameconnPtr flib_gameconn_create(String playerName, GameSetupPtr setup, boolean netgame); |
1083 GameconnPtr flib_gameconn_create(String playerName, GameSetupPtr setup, boolean netgame); |
1089 GameconnPtr flib_gameconn_create_playdemo(Buffer demo, NativeLong size); |
1084 GameconnPtr flib_gameconn_create_playdemo(Buffer demo, NativeSizeT size); |
1090 GameconnPtr flib_gameconn_create_loadgame(String playerName, Buffer save, NativeLong size); |
1085 GameconnPtr flib_gameconn_create_loadgame(String playerName, Buffer save, NativeSizeT size); |
1091 GameconnPtr flib_gameconn_create_campaign(String playerName, String seed, String script); |
1086 GameconnPtr flib_gameconn_create_campaign(String playerName, String seed, String script); |
1092 |
1087 |
1093 void flib_gameconn_destroy(GameconnPtr conn); |
1088 void flib_gameconn_destroy(GameconnPtr conn); |
1094 int flib_gameconn_getport(GameconnPtr conn); |
1089 int flib_gameconn_getport(GameconnPtr conn); |
1095 void flib_gameconn_tick(GameconnPtr conn); |
1090 void flib_gameconn_tick(GameconnPtr conn); |
1096 |
1091 |
1097 int flib_gameconn_send_enginemsg(GameconnPtr conn, Pointer data, NativeLong len); |
1092 int flib_gameconn_send_enginemsg(GameconnPtr conn, Pointer data, NativeSizeT len); |
1098 int flib_gameconn_send_textmsg(GameconnPtr conn, int msgtype, String msg); |
1093 int flib_gameconn_send_textmsg(GameconnPtr conn, int msgtype, String msg); |
1099 int flib_gameconn_send_chatmsg(GameconnPtr conn, String playername, String msg); |
1094 int flib_gameconn_send_chatmsg(GameconnPtr conn, String playername, String msg); |
1100 int flib_gameconn_send_quit(GameconnPtr conn); |
1095 int flib_gameconn_send_quit(GameconnPtr conn); |
1101 |
1096 |
1102 void flib_gameconn_onConnect(GameconnPtr conn, VoidCallback callback, Pointer context); |
1097 void flib_gameconn_onConnect(GameconnPtr conn, VoidCallback callback, Pointer context); |