91 * the GameConfig. When converting GameConfig to a native flib_gamesetup, both |
91 * the GameConfig. When converting GameConfig to a native flib_gamesetup, both |
92 * are automatically copied to all hogs in the game, and for the reverse |
92 * are automatically copied to all hogs in the game, and for the reverse |
93 * conversion the weaponset of the first hog of the first team is used as the |
93 * conversion the weaponset of the first hog of the first team is used as the |
94 * GameConfig weaponset. This means that GameConfig.weaponset will be null if |
94 * GameConfig weaponset. This means that GameConfig.weaponset will be null if |
95 * there are no teams in the game. |
95 * there are no teams in the game. |
96 * |
96 * |
97 * When starting a network game, you only need to query the GameSetupPtr from |
97 * When starting a network game, you only need to query the GameSetupPtr from |
98 * the netconn and use it to create the gameconn - this is preferable to using |
98 * the netconn and use it to create the gameconn - this is preferable to using |
99 * your own recreation of the game setup, because that way the same piece of |
99 * your own recreation of the game setup, because that way the same piece of |
100 * code is used to determine the game setup on all platforms. |
100 * code is used to determine the game setup on all platforms. |
101 * |
101 * |
102 * The "context" parameter of the callbacks is never needed here because JNA |
102 * The "context" parameter of the callbacks is never needed here because JNA |
103 * generates function code for each callback object. Don't worry about it, just |
103 * generates function code for each callback object. Don't worry about it, just |
104 * pass null for context and ignore the context parameter in the callbacks. |
104 * pass null for context and ignore the context parameter in the callbacks. |
105 * |
105 * |
106 * Finally, the library functions are documented in the actual library, not |
106 * Finally, the library functions are documented in the actual library, not |
107 * here, so check the docs there to find out what exactly each function does! |
107 * here, so check the docs there to find out what exactly each function does! |
108 * |
108 * |
109 * Notes about the structure of this class (for the next one who has to touch |
109 * Notes about the structure of this class (for the next one who has to touch |
110 * this...): |
110 * this...): |
111 * |
111 * |
112 * Java/C interop is quite fiddly and error-prone, so as long as things work, |
112 * Java/C interop is quite fiddly and error-prone, so as long as things work, |
113 * try to stick to the established patterns. |
113 * try to stick to the established patterns. |
114 * |
114 * |
115 * Structure types should always be hidden from the outside world, because they |
115 * Structure types should always be hidden from the outside world, because they |
116 * can be misused too easily. For example, if you get a Structure from the |
116 * can be misused too easily. For example, if you get a Structure from the |
117 * library, change a String value in there and pass it back, JNA will re-write |
117 * library, change a String value in there and pass it back, JNA will re-write |
118 * that string using Java-owned memory without freeing the old native-owned |
118 * that string using Java-owned memory without freeing the old native-owned |
119 * string, which causes a memory leak and possibly a double-free or other Bad |
119 * string, which causes a memory leak and possibly a double-free or other Bad |
120 * Things (tm). To avoid problems like this, Structure types are only used |
120 * Things (tm). To avoid problems like this, Structure types are only used |
121 * internally, to map existing structures to Java types (without modifying them) |
121 * internally, to map existing structures to Java types (without modifying them) |
122 * or to create brand-new, Java-owned structures. Both operations are exposed to |
122 * or to create brand-new, Java-owned structures. Both operations are exposed to |
123 * the outside through the PointerType classes corresponding to the structures |
123 * the outside through the PointerType classes corresponding to the structures |
124 * in question. |
124 * in question. |
125 * |
125 * |
126 * Since all of the struct mapping happens in Java, it is never checked against |
126 * Since all of the struct mapping happens in Java, it is never checked against |
127 * the actual struct declarations in the library. That means strange things can |
127 * the actual struct declarations in the library. That means strange things can |
128 * start happening at runtime if the frontlib structs are modified without |
128 * start happening at runtime if the frontlib structs are modified without |
129 * changing the mappings here to match. This also applies to the function |
129 * changing the mappings here to match. This also applies to the function |
130 * signatures: JNA checks whether the functions actually exist when loading the |
130 * signatures: JNA checks whether the functions actually exist when loading the |
131 * library, but it has no way of knowing whether the signatures are correct. If |
131 * library, but it has no way of knowing whether the signatures are correct. If |
132 * the signatures here deviate from those in the frontlib, you might get stack |
132 * the signatures here deviate from those in the frontlib, you might get stack |
133 * corruption. |
133 * corruption. |
134 * |
134 * |
135 * In order to check at least the function signatures, take a look at the file |
135 * In order to check at least the function signatures, take a look at the file |
136 * extra/jnacontrol.c in the frontlib sources. You can validate whether the |
136 * extra/jnacontrol.c in the frontlib sources. You can validate whether the |
137 * function signatures are still correct by copy-pasting them into jnaControl.c |
137 * function signatures are still correct by copy-pasting them into jnaControl.c |
138 * and compiling it against the frontlib headers. The typedefs and #defines in |
138 * and compiling it against the frontlib headers. The typedefs and #defines in |
139 * that file will make the compiler see the Java method signatures as C function |
139 * that file will make the compiler see the Java method signatures as C function |
140 * declarations. Since the same functions are already declared in the frontlib |
140 * declarations. Since the same functions are already declared in the frontlib |
141 * headers, the compiler will give you errors if the signatures don't match. |
141 * headers, the compiler will give you errors if the signatures don't match. |
142 */ |
142 */ |
143 public interface Frontlib extends Library { |
143 public interface Frontlib extends Library { |
144 public static class NetconnPtr extends PointerType { } |
144 public static class NetconnPtr extends PointerType { } |
145 public static class MapconnPtr extends PointerType { } |
145 public static class MapconnPtr extends PointerType { } |
146 public static class GameconnPtr extends PointerType { } |
146 public static class GameconnPtr extends PointerType { } |
147 |
147 |
148 public static class MetaschemePtr extends PointerType { |
148 public static class MetaschemePtr extends PointerType { |
149 public MetaScheme deref() { |
149 public MetaScheme deref() { |
150 return deref(getPointer()); |
150 return deref(getPointer()); |
151 } |
151 } |
152 |
152 |
153 public static MetaScheme deref(Pointer p) { |
153 public static MetaScheme deref(Pointer p) { |
154 MetaschemeStruct struct = new MetaschemeStruct(p); |
154 MetaschemeStruct struct = new MetaschemeStruct(p); |
155 struct.read(); |
155 struct.read(); |
156 return struct.toMetaScheme(); |
156 return struct.toMetaScheme(); |
157 } |
157 } |
158 } |
158 } |
159 |
159 |
160 public static class RoomArrayPtr extends PointerType { |
160 public static class RoomArrayPtr extends PointerType { |
161 public Room[] getRooms(int count) { |
161 public Room[] getRooms(int count) { |
162 Pointer ptr = getPointer(); |
162 Pointer ptr = getPointer(); |
163 if(ptr == null) { |
163 if(ptr == null) { |
164 return new Room[0]; |
164 return new Room[0]; |
165 } |
165 } |
166 Pointer[] untypedPtrs = ptr.getPointerArray(0, count); |
166 Pointer[] untypedPtrs = ptr.getPointerArray(0, count); |
167 Room[] result = new Room[count]; |
167 Room[] result = new Room[count]; |
168 for(int i=0; i<count; i++) { |
168 for(int i=0; i<count; i++) { |
169 result[i] = RoomPtr.deref(untypedPtrs[i]); |
169 result[i] = RoomPtr.deref(untypedPtrs[i]); |
170 } |
170 } |
171 return result; |
171 return result; |
172 } |
172 } |
173 } |
173 } |
174 |
174 |
175 public static class RoomPtr extends PointerType { |
175 public static class RoomPtr extends PointerType { |
176 public Room deref() { |
176 public Room deref() { |
177 return deref(getPointer()); |
177 return deref(getPointer()); |
178 } |
178 } |
179 |
179 |
180 public static Room deref(Pointer p) { |
180 public static Room deref(Pointer p) { |
181 RoomStruct struct = new RoomStruct(p); |
181 RoomStruct struct = new RoomStruct(p); |
182 struct.read(); |
182 struct.read(); |
183 return struct.toRoomlistRoom(); |
183 return struct.toRoomlistRoom(); |
184 } |
184 } |
185 } |
185 } |
186 |
186 |
187 public static class TeamPtr extends PointerType { |
187 public static class TeamPtr extends PointerType { |
188 private TeamStruct javaOwnedInstance; |
188 private TeamStruct javaOwnedInstance; |
189 |
189 |
190 public TeamInGame deref() { |
190 public TeamInGame deref() { |
191 TeamStruct struct = new TeamStruct(getPointer()); |
191 TeamStruct struct = new TeamStruct(getPointer()); |
192 struct.read(); |
192 struct.read(); |
193 return struct.toTeamInGame(); |
193 return struct.toTeamInGame(); |
194 } |
194 } |
195 |
195 |
196 public static TeamPtr createJavaOwned(Team t) { |
196 public static TeamPtr createJavaOwned(Team t) { |
197 return createJavaOwned(new TeamInGame(t, null)); |
197 return createJavaOwned(new TeamInGame(t, null)); |
198 } |
198 } |
199 |
199 |
200 public static TeamPtr createJavaOwned(TeamInGame ingameTeam) { |
200 public static TeamPtr createJavaOwned(TeamInGame ingameTeam) { |
201 TeamPtr result = new TeamPtr(); |
201 TeamPtr result = new TeamPtr(); |
202 result.javaOwnedInstance = new TeamStruct(); |
202 result.javaOwnedInstance = new TeamStruct(); |
203 result.javaOwnedInstance.fillFrom(ingameTeam.team, ingameTeam.ingameAttribs); |
203 result.javaOwnedInstance.fillFrom(ingameTeam.team, ingameTeam.ingameAttribs); |
204 result.javaOwnedInstance.autoWrite(); |
204 result.javaOwnedInstance.autoWrite(); |
205 result.setPointer(result.javaOwnedInstance.getPointer()); |
205 result.setPointer(result.javaOwnedInstance.getPointer()); |
206 return result; |
206 return result; |
207 } |
207 } |
208 } |
208 } |
209 |
209 |
210 public static class WeaponsetPtr extends PointerType { |
210 public static class WeaponsetPtr extends PointerType { |
211 private WeaponsetStruct javaOwnedInstance; |
211 private WeaponsetStruct javaOwnedInstance; |
212 |
212 |
213 public Weaponset deref() { |
213 public Weaponset deref() { |
214 WeaponsetStruct struct = new WeaponsetStruct(getPointer()); |
214 WeaponsetStruct struct = new WeaponsetStruct(getPointer()); |
215 struct.read(); |
215 struct.read(); |
216 return struct.toWeaponset(); |
216 return struct.toWeaponset(); |
217 } |
217 } |
218 |
218 |
219 public static WeaponsetPtr createJavaOwned(Weaponset weaponset) { |
219 public static WeaponsetPtr createJavaOwned(Weaponset weaponset) { |
220 WeaponsetPtr result = new WeaponsetPtr(); |
220 WeaponsetPtr result = new WeaponsetPtr(); |
221 result.javaOwnedInstance = new WeaponsetStruct(); |
221 result.javaOwnedInstance = new WeaponsetStruct(); |
222 result.javaOwnedInstance.fillFrom(weaponset); |
222 result.javaOwnedInstance.fillFrom(weaponset); |
223 result.javaOwnedInstance.autoWrite(); |
223 result.javaOwnedInstance.autoWrite(); |
224 result.setPointer(result.javaOwnedInstance.getPointer()); |
224 result.setPointer(result.javaOwnedInstance.getPointer()); |
225 return result; |
225 return result; |
226 } |
226 } |
227 } |
227 } |
228 |
228 |
229 public static class WeaponsetListPtr extends PointerType { |
229 public static class WeaponsetListPtr extends PointerType { |
230 private WeaponsetListStruct javaOwnedInstance; |
230 private WeaponsetListStruct javaOwnedInstance; |
231 |
231 |
232 public List<Weaponset> deref() { |
232 public List<Weaponset> deref() { |
233 WeaponsetListStruct struct = new WeaponsetListStruct(getPointer()); |
233 WeaponsetListStruct struct = new WeaponsetListStruct(getPointer()); |
234 struct.read(); |
234 struct.read(); |
235 return struct.toWeaponsetList(); |
235 return struct.toWeaponsetList(); |
236 } |
236 } |
237 |
237 |
238 public static WeaponsetListPtr createJavaOwned(List<Weaponset> list) { |
238 public static WeaponsetListPtr createJavaOwned(List<Weaponset> list) { |
239 WeaponsetListPtr result = new WeaponsetListPtr(); |
239 WeaponsetListPtr result = new WeaponsetListPtr(); |
240 result.javaOwnedInstance = new WeaponsetListStruct(); |
240 result.javaOwnedInstance = new WeaponsetListStruct(); |
241 result.javaOwnedInstance.fillFrom(list); |
241 result.javaOwnedInstance.fillFrom(list); |
242 result.javaOwnedInstance.autoWrite(); |
242 result.javaOwnedInstance.autoWrite(); |
243 result.setPointer(result.javaOwnedInstance.getPointer()); |
243 result.setPointer(result.javaOwnedInstance.getPointer()); |
244 return result; |
244 return result; |
245 } |
245 } |
246 } |
246 } |
247 |
247 |
248 public static class MapRecipePtr extends PointerType { |
248 public static class MapRecipePtr extends PointerType { |
249 private MapRecipeStruct javaOwnedInstance; |
249 private MapRecipeStruct javaOwnedInstance; |
250 |
250 |
251 public MapRecipe deref() { |
251 public MapRecipe deref() { |
252 MapRecipeStruct struct = new MapRecipeStruct(getPointer()); |
252 MapRecipeStruct struct = new MapRecipeStruct(getPointer()); |
253 struct.read(); |
253 struct.read(); |
254 return struct.toMapRecipe(); |
254 return struct.toMapRecipe(); |
255 } |
255 } |
256 |
256 |
257 public static MapRecipePtr createJavaOwned(MapRecipe recipe) { |
257 public static MapRecipePtr createJavaOwned(MapRecipe recipe) { |
258 MapRecipePtr result = new MapRecipePtr(); |
258 MapRecipePtr result = new MapRecipePtr(); |
259 result.javaOwnedInstance = new MapRecipeStruct(); |
259 result.javaOwnedInstance = new MapRecipeStruct(); |
260 result.javaOwnedInstance.fillFrom(recipe); |
260 result.javaOwnedInstance.fillFrom(recipe); |
261 result.javaOwnedInstance.autoWrite(); |
261 result.javaOwnedInstance.autoWrite(); |
262 result.setPointer(result.javaOwnedInstance.getPointer()); |
262 result.setPointer(result.javaOwnedInstance.getPointer()); |
263 return result; |
263 return result; |
264 } |
264 } |
265 } |
265 } |
266 |
266 |
267 public static class SchemePtr extends PointerType { |
267 public static class SchemePtr extends PointerType { |
268 private SchemeStruct javaOwnedInstance; |
268 private SchemeStruct javaOwnedInstance; |
269 |
269 |
270 public Scheme deref() { |
270 public Scheme deref() { |
271 SchemeStruct struct = new SchemeStruct(getPointer()); |
271 SchemeStruct struct = new SchemeStruct(getPointer()); |
272 struct.read(); |
272 struct.read(); |
273 return struct.toScheme(); |
273 return struct.toScheme(); |
274 } |
274 } |
275 |
275 |
276 public static SchemePtr createJavaOwned(Scheme scheme) { |
276 public static SchemePtr createJavaOwned(Scheme scheme) { |
277 SchemePtr result = new SchemePtr(); |
277 SchemePtr result = new SchemePtr(); |
278 result.javaOwnedInstance = new SchemeStruct(); |
278 result.javaOwnedInstance = new SchemeStruct(); |
279 result.javaOwnedInstance.fillFrom(scheme); |
279 result.javaOwnedInstance.fillFrom(scheme); |
280 result.javaOwnedInstance.autoWrite(); |
280 result.javaOwnedInstance.autoWrite(); |
281 result.setPointer(result.javaOwnedInstance.getPointer()); |
281 result.setPointer(result.javaOwnedInstance.getPointer()); |
282 return result; |
282 return result; |
283 } |
283 } |
284 } |
284 } |
285 |
285 |
286 public static class SchemelistPtr extends PointerType { |
286 public static class SchemelistPtr extends PointerType { |
287 private SchemelistStruct javaOwnedInstance; |
287 private SchemelistStruct javaOwnedInstance; |
288 |
288 |
289 public List<Scheme> deref() { |
289 public List<Scheme> deref() { |
290 SchemelistStruct struct = new SchemelistStruct(getPointer()); |
290 SchemelistStruct struct = new SchemelistStruct(getPointer()); |
291 struct.read(); |
291 struct.read(); |
292 return struct.toSchemeList(); |
292 return struct.toSchemeList(); |
293 } |
293 } |
294 |
294 |
295 public static SchemelistPtr createJavaOwned(List<Scheme> schemes) { |
295 public static SchemelistPtr createJavaOwned(List<Scheme> schemes) { |
296 SchemelistPtr result = new SchemelistPtr(); |
296 SchemelistPtr result = new SchemelistPtr(); |
297 result.javaOwnedInstance = new SchemelistStruct(); |
297 result.javaOwnedInstance = new SchemelistStruct(); |
298 result.javaOwnedInstance.fillFrom(schemes); |
298 result.javaOwnedInstance.fillFrom(schemes); |
299 result.javaOwnedInstance.autoWrite(); |
299 result.javaOwnedInstance.autoWrite(); |
300 result.setPointer(result.javaOwnedInstance.getPointer()); |
300 result.setPointer(result.javaOwnedInstance.getPointer()); |
301 return result; |
301 return result; |
302 } |
302 } |
303 } |
303 } |
304 |
304 |
305 public static class GameSetupPtr extends PointerType { |
305 public static class GameSetupPtr extends PointerType { |
306 private GameSetupStruct javaOwnedInstance; |
306 private GameSetupStruct javaOwnedInstance; |
307 |
307 |
308 public GameConfig deref() { |
308 public GameConfig deref() { |
309 GameSetupStruct struct = new GameSetupStruct(getPointer()); |
309 GameSetupStruct struct = new GameSetupStruct(getPointer()); |
310 struct.read(); |
310 struct.read(); |
311 return struct.toGameConfig(); |
311 return struct.toGameConfig(); |
312 } |
312 } |
313 |
313 |
314 public static GameSetupPtr createJavaOwned(GameConfig conf) { |
314 public static GameSetupPtr createJavaOwned(GameConfig conf) { |
315 GameSetupPtr result = new GameSetupPtr(); |
315 GameSetupPtr result = new GameSetupPtr(); |
316 result.javaOwnedInstance = new GameSetupStruct(); |
316 result.javaOwnedInstance = new GameSetupStruct(); |
317 result.javaOwnedInstance.fillFrom(conf); |
317 result.javaOwnedInstance.fillFrom(conf); |
318 result.javaOwnedInstance.autoWrite(); |
318 result.javaOwnedInstance.autoWrite(); |
319 result.setPointer(result.javaOwnedInstance.getPointer()); |
319 result.setPointer(result.javaOwnedInstance.getPointer()); |
320 return result; |
320 return result; |
321 } |
321 } |
322 } |
322 } |
323 |
323 |
324 public static class ByteArrayPtr extends PointerType { |
324 public static class ByteArrayPtr extends PointerType { |
325 public byte[] deref(int size) { |
325 public byte[] deref(int size) { |
326 return getPointer().getByteArray(0, size); |
326 return getPointer().getByteArray(0, size); |
327 } |
327 } |
328 |
328 |
329 public static byte[] deref(ByteArrayPtr ptr, int size) { |
329 public static byte[] deref(ByteArrayPtr ptr, int size) { |
330 if(ptr==null && size==0) { |
330 if(ptr==null && size==0) { |
331 return null; |
331 return null; |
332 } else { |
332 } else { |
333 return ptr.deref(size); |
333 return ptr.deref(size); |
334 } |
334 } |
335 } |
335 } |
336 |
336 |
337 public static ByteArrayPtr createJavaOwned(byte[] buffer) { |
337 public static ByteArrayPtr createJavaOwned(byte[] buffer) { |
338 if(buffer == null || buffer.length == 0) { |
338 if(buffer == null || buffer.length == 0) { |
339 return null; |
339 return null; |
340 } |
340 } |
341 // no need for javaOwnedInstance here because PointerType |
341 // no need for javaOwnedInstance here because PointerType |
342 // remembers the memory as its Pointer |
342 // remembers the memory as its Pointer |
343 Pointer ptr = new Memory(buffer.length); |
343 Pointer ptr = new Memory(buffer.length); |
344 ptr.write(0, buffer, 0, buffer.length); |
344 ptr.write(0, buffer, 0, buffer.length); |
345 ByteArrayPtr result = new ByteArrayPtr(); |
345 ByteArrayPtr result = new ByteArrayPtr(); |
346 result.setPointer(ptr); |
346 result.setPointer(ptr); |
347 return result; |
347 return result; |
348 } |
348 } |
349 } |
349 } |
350 |
350 |
351 static class HogStruct extends Structure { |
351 static class HogStruct extends Structure { |
352 public static class ByVal extends HogStruct implements Structure.ByValue {} |
352 public static class ByVal extends HogStruct implements Structure.ByValue {} |
353 public static class ByRef extends HogStruct implements Structure.ByReference {} |
353 public static class ByRef extends HogStruct implements Structure.ByReference {} |
354 |
354 |
355 public HogStruct() { super(); } |
355 public HogStruct() { super(); } |
356 public HogStruct(Pointer ptr) { super(ptr); } |
356 public HogStruct(Pointer ptr) { super(ptr); } |
357 |
357 |
358 @Override |
358 @Override |
359 protected List<String> getFieldOrder() { |
359 protected List<String> getFieldOrder() { |
360 return Arrays.asList("name", "hat", "rounds", "kills", "deaths", "suicides", "difficulty", "initialHealth", "weaponset"); |
360 return Arrays.asList("name", "hat", "rounds", "kills", "deaths", "suicides", "difficulty", "initialHealth", "weaponset"); |
361 } |
361 } |
362 |
362 |
363 public void fillFrom(Hog hog) { |
363 public void fillFrom(Hog hog) { |
364 difficulty = hog.level; |
364 difficulty = hog.level; |
365 hat = hog.hat; |
365 hat = hog.hat; |
366 name = hog.name; |
366 name = hog.name; |
367 } |
367 } |
368 |
368 |
369 public Hog toHog() { |
369 public Hog toHog() { |
370 return new Hog(name, hat, difficulty); |
370 return new Hog(name, hat, difficulty); |
371 } |
371 } |
372 |
372 |
373 public String name; |
373 public String name; |
374 public String hat; |
374 public String hat; |
375 |
375 |
376 public int rounds; |
376 public int rounds; |
377 public int kills; |
377 public int kills; |
378 public int deaths; |
378 public int deaths; |
379 public int suicides; |
379 public int suicides; |
380 |
380 |
381 public int difficulty; |
381 public int difficulty; |
382 |
382 |
383 public int initialHealth; |
383 public int initialHealth; |
384 public WeaponsetStruct.ByRef weaponset; |
384 public WeaponsetStruct.ByRef weaponset; |
385 } |
385 } |
386 |
386 |
387 static class TeamStruct extends Structure { |
387 static class TeamStruct extends Structure { |
388 public static class ByVal extends TeamStruct implements Structure.ByValue {} |
388 public static class ByVal extends TeamStruct implements Structure.ByValue {} |
389 public static class ByRef extends TeamStruct implements Structure.ByReference {} |
389 public static class ByRef extends TeamStruct implements Structure.ByReference {} |
390 |
390 |
391 public TeamStruct() { super(); } |
391 public TeamStruct() { super(); } |
392 public TeamStruct(Pointer ptr) { super(ptr); } |
392 public TeamStruct(Pointer ptr) { super(ptr); } |
393 |
393 |
394 @Override |
394 @Override |
395 protected List<String> getFieldOrder() { |
395 protected List<String> getFieldOrder() { |
396 return Arrays.asList("hogs", "name", "grave", "fort", "voicepack", "flag", "bindings", "bindingCount", "rounds", "wins", "campaignProgress", "colorIndex", "hogsInGame", "remoteDriven", "ownerName"); |
396 return Arrays.asList("hogs", "name", "grave", "fort", "voicepack", "flag", "bindings", "bindingCount", "rounds", "wins", "campaignProgress", "colorIndex", "hogsInGame", "remoteDriven", "ownerName"); |
397 } |
397 } |
398 |
398 |
399 public void fillFrom(Team team, TeamIngameAttributes attrs) { |
399 public void fillFrom(Team team, TeamIngameAttributes attrs) { |
400 if(team != null) { |
400 if(team != null) { |
401 name = team.name; |
401 name = team.name; |
402 grave = team.grave; |
402 grave = team.grave; |
403 flag = team.flag; |
403 flag = team.flag; |
404 voicepack = team.voice; |
404 voicepack = team.voice; |
405 fort = team.fort; |
405 fort = team.fort; |
406 if(team.hogs.size() != Team.HEDGEHOGS_PER_TEAM) { |
406 if(team.hogs.size() != Team.HEDGEHOGS_PER_TEAM) { |
407 throw new IllegalArgumentException(); |
407 throw new IllegalArgumentException(); |
408 } |
408 } |
409 for(int i=0; i<hogs.length; i++) { |
409 for(int i=0; i<hogs.length; i++) { |
410 hogs[i] = new HogStruct(); |
410 hogs[i] = new HogStruct(); |
411 hogs[i].fillFrom(team.hogs.get(i)); |
411 hogs[i].fillFrom(team.hogs.get(i)); |
412 } |
412 } |
413 } |
413 } |
414 |
414 |
415 if(attrs != null) { |
415 if(attrs != null) { |
416 hogsInGame = attrs.hogCount; |
416 hogsInGame = attrs.hogCount; |
417 ownerName = attrs.ownerName; |
417 ownerName = attrs.ownerName; |
418 colorIndex = attrs.colorIndex; |
418 colorIndex = attrs.colorIndex; |
419 remoteDriven = attrs.remoteDriven; |
419 remoteDriven = attrs.remoteDriven; |
420 } |
420 } |
421 } |
421 } |
422 |
422 |
423 public void fillFrom(TeamInGame team, WeaponsetStruct.ByRef weaponset, int initialHealth) { |
423 public void fillFrom(TeamInGame team, WeaponsetStruct.ByRef weaponset, int initialHealth) { |
424 fillFrom(team.team, team.ingameAttribs); |
424 fillFrom(team.team, team.ingameAttribs); |
425 for(int i=0; i<hogs.length; i++) { |
425 for(int i=0; i<hogs.length; i++) { |
426 hogs[i].initialHealth = initialHealth; |
426 hogs[i].initialHealth = initialHealth; |
427 hogs[i].weaponset = weaponset; |
427 hogs[i].weaponset = weaponset; |
428 } |
428 } |
429 } |
429 } |
430 |
430 |
431 public Team toTeam() { |
431 public Team toTeam() { |
432 List<Hog> hogList = new ArrayList<Hog>(); |
432 List<Hog> hogList = new ArrayList<Hog>(); |
433 for(int i=0; i<hogs.length; i++) { |
433 for(int i=0; i<hogs.length; i++) { |
434 hogList.add(hogs[i].toHog()); |
434 hogList.add(hogs[i].toHog()); |
435 } |
435 } |
436 return new Team(name, grave, flag, voicepack, fort, hogList); |
436 return new Team(name, grave, flag, voicepack, fort, hogList); |
437 } |
437 } |
438 |
438 |
439 public TeamIngameAttributes toTeamIngameAttributes() { |
439 public TeamIngameAttributes toTeamIngameAttributes() { |
440 return new TeamIngameAttributes(ownerName, colorIndex, hogsInGame, remoteDriven); |
440 return new TeamIngameAttributes(ownerName, colorIndex, hogsInGame, remoteDriven); |
441 } |
441 } |
442 |
442 |
443 public TeamInGame toTeamInGame() { |
443 public TeamInGame toTeamInGame() { |
444 return new TeamInGame(toTeam(), toTeamIngameAttributes()); |
444 return new TeamInGame(toTeam(), toTeamIngameAttributes()); |
445 } |
445 } |
446 |
446 |
447 public HogStruct[] hogs = new HogStruct[Team.HEDGEHOGS_PER_TEAM]; |
447 public HogStruct[] hogs = new HogStruct[Team.HEDGEHOGS_PER_TEAM]; |
448 public String name; |
448 public String name; |
449 public String grave; |
449 public String grave; |
450 public String fort; |
450 public String fort; |
451 public String voicepack; |
451 public String voicepack; |
452 public String flag; |
452 public String flag; |
453 |
453 |
454 public Pointer bindings; |
454 public Pointer bindings; |
455 public int bindingCount; |
455 public int bindingCount; |
456 |
456 |
457 public int rounds; |
457 public int rounds; |
458 public int wins; |
458 public int wins; |
459 public int campaignProgress; |
459 public int campaignProgress; |
460 |
460 |
461 public int colorIndex; |
461 public int colorIndex; |
462 public int hogsInGame; |
462 public int hogsInGame; |
463 public boolean remoteDriven; |
463 public boolean remoteDriven; |
464 public String ownerName; |
464 public String ownerName; |
465 } |
465 } |
466 |
466 |
467 static class WeaponsetStruct extends Structure { |
467 static class WeaponsetStruct extends Structure { |
468 public static class ByVal extends WeaponsetStruct implements Structure.ByValue {} |
468 public static class ByVal extends WeaponsetStruct implements Structure.ByValue {} |
469 public static class ByRef extends WeaponsetStruct implements Structure.ByReference {} |
469 public static class ByRef extends WeaponsetStruct implements Structure.ByReference {} |
470 |
470 |
471 public WeaponsetStruct() { super(); } |
471 public WeaponsetStruct() { super(); } |
472 public WeaponsetStruct(Pointer ptr) { super(ptr); } |
472 public WeaponsetStruct(Pointer ptr) { super(ptr); } |
473 |
473 |
474 @Override |
474 @Override |
475 protected List<String> getFieldOrder() { |
475 protected List<String> getFieldOrder() { |
476 return Arrays.asList("loadout", "crateprob", "crateammo", "delay", "name"); |
476 return Arrays.asList("loadout", "crateprob", "crateammo", "delay", "name"); |
477 } |
477 } |
478 |
478 |
479 public void fillFrom(Weaponset weaponset) { |
479 public void fillFrom(Weaponset weaponset) { |
480 fillWeaponInfo(loadout, weaponset.loadout); |
480 fillWeaponInfo(loadout, weaponset.loadout); |
481 fillWeaponInfo(crateprob, weaponset.crateProb); |
481 fillWeaponInfo(crateprob, weaponset.crateProb); |
482 fillWeaponInfo(crateammo, weaponset.crateAmmo); |
482 fillWeaponInfo(crateammo, weaponset.crateAmmo); |
483 fillWeaponInfo(delay, weaponset.delay); |
483 fillWeaponInfo(delay, weaponset.delay); |
484 name = weaponset.name; |
484 name = weaponset.name; |
485 } |
485 } |
486 |
486 |
487 private static void fillWeaponInfo(byte[] array, String str) { |
487 private static void fillWeaponInfo(byte[] array, String str) { |
488 for(int i=0; i<array.length-1; i++) { |
488 for(int i=0; i<array.length-1; i++) { |
489 array[i] = (byte) (i<str.length() ? str.charAt(i) : '0'); |
489 array[i] = (byte) (i<str.length() ? str.charAt(i) : '0'); |
490 } |
490 } |
491 array[array.length-1] = (byte)0; |
491 array[array.length-1] = (byte)0; |
492 } |
492 } |
493 |
493 |
494 public Weaponset toWeaponset() { |
494 public Weaponset toWeaponset() { |
495 return new Weaponset(name, weaponInfoToString(loadout), weaponInfoToString(crateprob), weaponInfoToString(crateammo), weaponInfoToString(delay)); |
495 return new Weaponset(name, weaponInfoToString(loadout), weaponInfoToString(crateprob), weaponInfoToString(crateammo), weaponInfoToString(delay)); |
496 } |
496 } |
497 |
497 |
498 private static String weaponInfoToString(byte[] array) { |
498 private static String weaponInfoToString(byte[] array) { |
499 try { |
499 try { |
500 return new String(array, 0, array.length-1, "ASCII"); |
500 return new String(array, 0, array.length-1, "ASCII"); |
501 } catch (UnsupportedEncodingException e) { |
501 } catch (UnsupportedEncodingException e) { |
502 throw new AssertionError(); |
502 throw new AssertionError(); |
503 } |
503 } |
504 } |
504 } |
505 |
505 |
506 public byte[] loadout = new byte[Weaponset.WEAPONS_COUNT+1]; |
506 public byte[] loadout = new byte[Weaponset.WEAPONS_COUNT+1]; |
507 public byte[] crateprob = new byte[Weaponset.WEAPONS_COUNT+1]; |
507 public byte[] crateprob = new byte[Weaponset.WEAPONS_COUNT+1]; |
508 public byte[] crateammo = new byte[Weaponset.WEAPONS_COUNT+1]; |
508 public byte[] crateammo = new byte[Weaponset.WEAPONS_COUNT+1]; |
509 public byte[] delay = new byte[Weaponset.WEAPONS_COUNT+1]; |
509 public byte[] delay = new byte[Weaponset.WEAPONS_COUNT+1]; |
510 public String name; |
510 public String name; |
511 } |
511 } |
512 |
512 |
513 /** |
513 /** |
514 * Represents a flib_weaponset*, for use as part of a flib_weaponset** |
514 * Represents a flib_weaponset*, for use as part of a flib_weaponset** |
515 */ |
515 */ |
516 static class WeaponsetPointerByReference extends Structure implements Structure.ByReference { |
516 static class WeaponsetPointerByReference extends Structure implements Structure.ByReference { |
517 public WeaponsetPointerByReference() { super(); } |
517 public WeaponsetPointerByReference() { super(); } |
518 public WeaponsetPointerByReference(Pointer ptr) { super(ptr); } |
518 public WeaponsetPointerByReference(Pointer ptr) { super(ptr); } |
519 |
519 |
520 @Override |
520 @Override |
521 protected List<String> getFieldOrder() { |
521 protected List<String> getFieldOrder() { |
522 return Arrays.asList("weaponset"); |
522 return Arrays.asList("weaponset"); |
523 } |
523 } |
524 |
524 |
525 public WeaponsetStruct.ByRef weaponset; |
525 public WeaponsetStruct.ByRef weaponset; |
526 } |
526 } |
527 |
527 |
528 static class WeaponsetListStruct extends Structure { |
528 static class WeaponsetListStruct extends Structure { |
529 public static class ByVal extends WeaponsetListStruct implements Structure.ByValue {} |
529 public static class ByVal extends WeaponsetListStruct implements Structure.ByValue {} |
530 public static class ByRef extends WeaponsetListStruct implements Structure.ByReference {} |
530 public static class ByRef extends WeaponsetListStruct implements Structure.ByReference {} |
531 |
531 |
532 public WeaponsetListStruct() { super(); } |
532 public WeaponsetListStruct() { super(); } |
533 public WeaponsetListStruct(Pointer ptr) { super(ptr); } |
533 public WeaponsetListStruct(Pointer ptr) { super(ptr); } |
534 |
534 |
535 @Override |
535 @Override |
536 protected List<String> getFieldOrder() { |
536 protected List<String> getFieldOrder() { |
537 return Arrays.asList("weaponsetCount", "weaponsets"); |
537 return Arrays.asList("weaponsetCount", "weaponsets"); |
538 } |
538 } |
539 |
539 |
540 public void fillFrom(List<Weaponset> list) { |
540 public void fillFrom(List<Weaponset> list) { |
541 weaponsetCount = list.size(); |
541 weaponsetCount = list.size(); |
542 if(weaponsetCount<=0) { |
542 if(weaponsetCount<=0) { |
543 weaponsets = null; |
543 weaponsets = null; |
544 } else { |
544 } else { |
545 weaponsets = new WeaponsetPointerByReference(); |
545 weaponsets = new WeaponsetPointerByReference(); |
546 Structure[] structs = weaponsets.toArray(weaponsetCount); |
546 Structure[] structs = weaponsets.toArray(weaponsetCount); |
547 |
547 |
548 for(int i=0; i<weaponsetCount; i++) { |
548 for(int i=0; i<weaponsetCount; i++) { |
549 WeaponsetPointerByReference pstruct = (WeaponsetPointerByReference)structs[i]; |
549 WeaponsetPointerByReference pstruct = (WeaponsetPointerByReference)structs[i]; |
550 pstruct.weaponset = new WeaponsetStruct.ByRef(); |
550 pstruct.weaponset = new WeaponsetStruct.ByRef(); |
551 pstruct.weaponset.fillFrom(list.get(i)); |
551 pstruct.weaponset.fillFrom(list.get(i)); |
552 } |
552 } |
553 } |
553 } |
554 } |
554 } |
555 |
555 |
556 /** |
556 /** |
557 * Only use on native-owned structs! |
557 * Only use on native-owned structs! |
558 * Calling this method on a Java-owned struct could cause garbage collection of referenced |
558 * Calling this method on a Java-owned struct could cause garbage collection of referenced |
559 * structures. |
559 * structures. |
560 */ |
560 */ |
561 public List<Weaponset> toWeaponsetList() { |
561 public List<Weaponset> toWeaponsetList() { |
562 if(weaponsetCount<=0) { |
562 if(weaponsetCount<=0) { |
563 return new ArrayList<Weaponset>(); |
563 return new ArrayList<Weaponset>(); |
564 } else { |
564 } else { |
565 List<Weaponset> list = new ArrayList<Weaponset>(weaponsetCount); |
565 List<Weaponset> list = new ArrayList<Weaponset>(weaponsetCount); |
566 Structure[] structs = weaponsets.toArray(weaponsetCount); |
566 Structure[] structs = weaponsets.toArray(weaponsetCount); |
567 |
567 |
568 for(int i=0; i<weaponsetCount; i++) { |
568 for(int i=0; i<weaponsetCount; i++) { |
569 WeaponsetPointerByReference pstruct = (WeaponsetPointerByReference)structs[i]; |
569 WeaponsetPointerByReference pstruct = (WeaponsetPointerByReference)structs[i]; |
570 list.add(pstruct.weaponset.toWeaponset()); |
570 list.add(pstruct.weaponset.toWeaponset()); |
571 } |
571 } |
572 return list; |
572 return list; |
573 } |
573 } |
574 } |
574 } |
575 |
575 |
576 public int weaponsetCount; |
576 public int weaponsetCount; |
577 public WeaponsetPointerByReference weaponsets; |
577 public WeaponsetPointerByReference weaponsets; |
578 } |
578 } |
579 |
579 |
580 static class RoomStruct extends Structure { |
580 static class RoomStruct extends Structure { |
581 public static class ByVal extends RoomStruct implements Structure.ByValue {} |
581 public static class ByVal extends RoomStruct implements Structure.ByValue {} |
582 public static class ByRef extends RoomStruct implements Structure.ByReference {} |
582 public static class ByRef extends RoomStruct implements Structure.ByReference {} |
583 |
583 |
584 public RoomStruct() { super(); } |
584 public RoomStruct() { super(); } |
585 public RoomStruct(Pointer ptr) { super(ptr); } |
585 public RoomStruct(Pointer ptr) { super(ptr); } |
586 |
586 |
587 @Override |
587 @Override |
588 protected List<String> getFieldOrder() { |
588 protected List<String> getFieldOrder() { |
589 return Arrays.asList("inProgress", "name", "playerCount", "teamCount", "owner", "map", "scheme", "weapons"); |
589 return Arrays.asList("inProgress", "name", "playerCount", "teamCount", "owner", "map", "scheme", "weapons"); |
590 } |
590 } |
591 |
591 |
592 public Room toRoomlistRoom() { |
592 public Room toRoomlistRoom() { |
593 return new Room(name, map, scheme, weapons, owner, playerCount, teamCount, inProgress); |
593 return new Room(name, map, scheme, weapons, owner, playerCount, teamCount, inProgress); |
594 } |
594 } |
595 |
595 |
596 public boolean inProgress; |
596 public boolean inProgress; |
597 public String name; |
597 public String name; |
598 public int playerCount; |
598 public int playerCount; |
599 public int teamCount; |
599 public int teamCount; |
600 public String owner; |
600 public String owner; |
601 public String map; |
601 public String map; |
602 public String scheme; |
602 public String scheme; |
603 public String weapons; |
603 public String weapons; |
604 } |
604 } |
605 |
605 |
606 static class MapRecipeStruct extends Structure { |
606 static class MapRecipeStruct extends Structure { |
607 public static class ByVal extends MapRecipeStruct implements Structure.ByValue {} |
607 public static class ByVal extends MapRecipeStruct implements Structure.ByValue {} |
608 public static class ByRef extends MapRecipeStruct implements Structure.ByReference {} |
608 public static class ByRef extends MapRecipeStruct implements Structure.ByReference {} |
609 |
609 |
610 public MapRecipeStruct() { super(); } |
610 public MapRecipeStruct() { super(); } |
611 public MapRecipeStruct(Pointer ptr) { super(ptr); } |
611 public MapRecipeStruct(Pointer ptr) { super(ptr); } |
612 |
612 |
613 @Override |
613 @Override |
614 protected List<String> getFieldOrder() { |
614 protected List<String> getFieldOrder() { |
615 return Arrays.asList("mapgen", "name", "seed", "theme", "drawData", "drawDataSize", "templateFilter", "mazeSize"); |
615 return Arrays.asList("mapgen", "name", "seed", "theme", "drawData", "drawDataSize", "templateFilter", "mazeSize"); |
616 } |
616 } |
617 |
617 |
618 public void fillFrom(MapRecipe map) { |
618 public void fillFrom(MapRecipe map) { |
619 mapgen = map.mapgen; |
619 mapgen = map.mapgen; |
620 name = map.name; |
620 name = map.name; |
621 seed = map.seed; |
621 seed = map.seed; |
622 theme = map.theme; |
622 theme = map.theme; |
623 byte[] buf = map.getDrawData(); |
623 byte[] buf = map.getDrawData(); |
624 drawData = ByteArrayPtr.createJavaOwned(buf); |
624 drawData = ByteArrayPtr.createJavaOwned(buf); |
625 drawDataSize = NativeSizeT.valueOf(buf==null ? 0 : buf.length); |
625 drawDataSize = NativeSizeT.valueOf(buf==null ? 0 : buf.length); |
626 templateFilter = map.templateFilter; |
626 templateFilter = map.templateFilter; |
627 mazeSize = map.mazeSize; |
627 mazeSize = map.mazeSize; |
628 } |
628 } |
629 |
629 |
630 public MapRecipe toMapRecipe() { |
630 public MapRecipe toMapRecipe() { |
631 byte[] buf = ByteArrayPtr.deref(drawData, drawDataSize.intValue()); |
631 byte[] buf = ByteArrayPtr.deref(drawData, drawDataSize.intValue()); |
632 return new MapRecipe(mapgen, templateFilter, mazeSize, name, seed, theme, buf); |
632 return new MapRecipe(mapgen, templateFilter, mazeSize, name, seed, theme, buf); |
633 } |
633 } |
634 |
634 |
635 public int mapgen; |
635 public int mapgen; |
636 public String name; |
636 public String name; |
637 public String seed; |
637 public String seed; |
638 public String theme; |
638 public String theme; |
639 public ByteArrayPtr drawData; |
639 public ByteArrayPtr drawData; |
640 public NativeSizeT drawDataSize; |
640 public NativeSizeT drawDataSize; |
641 public int templateFilter; |
641 public int templateFilter; |
642 public int mazeSize; |
642 public int mazeSize; |
643 } |
643 } |
644 |
644 |
645 static class MetaschemeSettingStruct extends Structure { |
645 static class MetaschemeSettingStruct extends Structure { |
646 public static class ByVal extends MetaschemeSettingStruct implements Structure.ByValue {} |
646 public static class ByVal extends MetaschemeSettingStruct implements Structure.ByValue {} |
647 public static class ByRef extends MetaschemeSettingStruct implements Structure.ByReference {} |
647 public static class ByRef extends MetaschemeSettingStruct implements Structure.ByReference {} |
648 |
648 |
649 public MetaschemeSettingStruct() { super(); } |
649 public MetaschemeSettingStruct() { super(); } |
650 public MetaschemeSettingStruct(Pointer ptr) { super(ptr); } |
650 public MetaschemeSettingStruct(Pointer ptr) { super(ptr); } |
651 |
651 |
652 @Override |
652 @Override |
653 protected List<String> getFieldOrder() { |
653 protected List<String> getFieldOrder() { |
654 return Arrays.asList("name", "engineCommand", "maxMeansInfinity", "times1000", "min", "max", "def"); |
654 return Arrays.asList("name", "engineCommand", "maxMeansInfinity", "times1000", "min", "max", "def"); |
655 } |
655 } |
656 |
656 |
657 public void fillFrom(Setting setting) { |
657 public void fillFrom(Setting setting) { |
658 name = setting.name; |
658 name = setting.name; |
659 engineCommand = setting.engineCommand; |
659 engineCommand = setting.engineCommand; |
660 maxMeansInfinity = setting.maxMeansInfinity; |
660 maxMeansInfinity = setting.maxMeansInfinity; |
661 times1000 = setting.times1000; |
661 times1000 = setting.times1000; |
662 min = setting.min; |
662 min = setting.min; |
663 max = setting.max; |
663 max = setting.max; |
664 def = setting.def; |
664 def = setting.def; |
665 } |
665 } |
666 |
666 |
667 public MetaScheme.Setting toMetaSchemeSetting() { |
667 public MetaScheme.Setting toMetaSchemeSetting() { |
668 return new MetaScheme.Setting(name, engineCommand, maxMeansInfinity, times1000, min, max, def); |
668 return new MetaScheme.Setting(name, engineCommand, maxMeansInfinity, times1000, min, max, def); |
669 } |
669 } |
670 |
670 |
671 public String name; |
671 public String name; |
672 public String engineCommand; |
672 public String engineCommand; |
673 public boolean maxMeansInfinity; |
673 public boolean maxMeansInfinity; |
674 public boolean times1000; |
674 public boolean times1000; |
675 public int min; |
675 public int min; |
676 public int max; |
676 public int max; |
677 public int def; |
677 public int def; |
678 } |
678 } |
679 |
679 |
680 static class MetaschemeModStruct extends Structure { |
680 static class MetaschemeModStruct extends Structure { |
681 public static class ByVal extends MetaschemeModStruct implements Structure.ByValue {} |
681 public static class ByVal extends MetaschemeModStruct implements Structure.ByValue {} |
682 public static class ByRef extends MetaschemeModStruct implements Structure.ByReference {} |
682 public static class ByRef extends MetaschemeModStruct implements Structure.ByReference {} |
683 |
683 |
684 public MetaschemeModStruct() { super(); } |
684 public MetaschemeModStruct() { super(); } |
685 public MetaschemeModStruct(Pointer ptr) { super(ptr); } |
685 public MetaschemeModStruct(Pointer ptr) { super(ptr); } |
686 |
686 |
687 @Override |
687 @Override |
688 protected List<String> getFieldOrder() { |
688 protected List<String> getFieldOrder() { |
689 return Arrays.asList("name", "bitmaskIndex"); |
689 return Arrays.asList("name", "bitmaskIndex"); |
690 } |
690 } |
691 |
691 |
692 public void fillFrom(Mod mod) { |
692 public void fillFrom(Mod mod) { |
693 name = mod.name; |
693 name = mod.name; |
694 bitmaskIndex = mod.bitmaskIndex; |
694 bitmaskIndex = mod.bitmaskIndex; |
695 } |
695 } |
696 |
696 |
697 public MetaScheme.Mod toMetaSchemeMod() { |
697 public MetaScheme.Mod toMetaSchemeMod() { |
698 return new MetaScheme.Mod(name, bitmaskIndex); |
698 return new MetaScheme.Mod(name, bitmaskIndex); |
699 } |
699 } |
700 |
700 |
701 public String name; |
701 public String name; |
702 public int bitmaskIndex; |
702 public int bitmaskIndex; |
703 |
703 |
704 } |
704 } |
705 |
705 |
706 static class MetaschemeStruct extends Structure { |
706 static class MetaschemeStruct extends Structure { |
707 public static class ByVal extends MetaschemeStruct implements Structure.ByValue {} |
707 public static class ByVal extends MetaschemeStruct implements Structure.ByValue {} |
708 public static class ByRef extends MetaschemeStruct implements Structure.ByReference {} |
708 public static class ByRef extends MetaschemeStruct implements Structure.ByReference {} |
709 |
709 |
710 public MetaschemeStruct() { super(); } |
710 public MetaschemeStruct() { super(); } |
711 public MetaschemeStruct(Pointer ptr) { super(ptr); } |
711 public MetaschemeStruct(Pointer ptr) { super(ptr); } |
712 |
712 |
713 @Override |
713 @Override |
714 protected List<String> getFieldOrder() { |
714 protected List<String> getFieldOrder() { |
715 return Arrays.asList("settingCount", "modCount", "settings", "mods"); |
715 return Arrays.asList("settingCount", "modCount", "settings", "mods"); |
716 } |
716 } |
717 |
717 |
718 /** |
718 /** |
719 * Only use on native-owned structs! |
719 * Only use on native-owned structs! |
720 * Calling this method on a Java-owned struct could cause garbage collection of referenced |
720 * Calling this method on a Java-owned struct could cause garbage collection of referenced |
721 * structures. |
721 * structures. |
722 */ |
722 */ |
723 public MetaScheme toMetaScheme() { |
723 public MetaScheme toMetaScheme() { |
724 List<MetaScheme.Setting> settingList = new ArrayList<MetaScheme.Setting>(settingCount); |
724 List<MetaScheme.Setting> settingList = new ArrayList<MetaScheme.Setting>(settingCount); |
725 List<MetaScheme.Mod> modList = new ArrayList<MetaScheme.Mod>(modCount); |
725 List<MetaScheme.Mod> modList = new ArrayList<MetaScheme.Mod>(modCount); |
726 |
726 |
727 Structure[] settingStructs = settings.toArray(settingCount); |
727 Structure[] settingStructs = settings.toArray(settingCount); |
728 Structure[] modStructs = mods.toArray(modCount); |
728 Structure[] modStructs = mods.toArray(modCount); |
729 |
729 |
730 for(int i=0; i<settingCount; i++) { |
730 for(int i=0; i<settingCount; i++) { |
731 MetaschemeSettingStruct mss = (MetaschemeSettingStruct)settingStructs[i]; |
731 MetaschemeSettingStruct mss = (MetaschemeSettingStruct)settingStructs[i]; |
732 settingList.add(mss.toMetaSchemeSetting()); |
732 settingList.add(mss.toMetaSchemeSetting()); |
733 } |
733 } |
734 |
734 |
735 for(int i=0; i<modCount; i++) { |
735 for(int i=0; i<modCount; i++) { |
736 MetaschemeModStruct mms = (MetaschemeModStruct)modStructs[i]; |
736 MetaschemeModStruct mms = (MetaschemeModStruct)modStructs[i]; |
737 modList.add(mms.toMetaSchemeMod()); |
737 modList.add(mms.toMetaSchemeMod()); |
738 } |
738 } |
739 |
739 |
740 return new MetaScheme(modList, settingList); |
740 return new MetaScheme(modList, settingList); |
741 } |
741 } |
742 |
742 |
743 public int settingCount; |
743 public int settingCount; |
744 public int modCount; |
744 public int modCount; |
745 public MetaschemeSettingStruct.ByRef settings; |
745 public MetaschemeSettingStruct.ByRef settings; |
746 public MetaschemeModStruct.ByRef mods; |
746 public MetaschemeModStruct.ByRef mods; |
747 } |
747 } |
748 |
748 |
749 static class SchemeStruct extends Structure { |
749 static class SchemeStruct extends Structure { |
750 public static class ByVal extends SchemeStruct implements Structure.ByValue {} |
750 public static class ByVal extends SchemeStruct implements Structure.ByValue {} |
751 public static class ByRef extends SchemeStruct implements Structure.ByReference {} |
751 public static class ByRef extends SchemeStruct implements Structure.ByReference {} |
752 |
752 |
753 public SchemeStruct() { super(); } |
753 public SchemeStruct() { super(); } |
754 public SchemeStruct(Pointer ptr) { super(ptr); } |
754 public SchemeStruct(Pointer ptr) { super(ptr); } |
755 |
755 |
756 @Override |
756 @Override |
757 protected List<String> getFieldOrder() { |
757 protected List<String> getFieldOrder() { |
758 return Arrays.asList("name", "settings", "mods"); |
758 return Arrays.asList("name", "settings", "mods"); |
759 } |
759 } |
760 |
760 |
761 public void fillFrom(Scheme scheme) { |
761 public void fillFrom(Scheme scheme) { |
762 MetaScheme meta = MetaScheme.INSTANCE; |
762 MetaScheme meta = MetaScheme.INSTANCE; |
763 name = scheme.name; |
763 name = scheme.name; |
764 settings = new Memory(AndroidTypeMapper.NATIVE_INT_SIZE * meta.settings.size()); |
764 settings = new Memory(AndroidTypeMapper.NATIVE_INT_SIZE * meta.settings.size()); |
765 for(int i=0; i<meta.settings.size(); i++) { |
765 for(int i=0; i<meta.settings.size(); i++) { |
766 Integer value = scheme.settings.get(meta.settings.get(i).name); |
766 Integer value = scheme.settings.get(meta.settings.get(i).name); |
767 settings.setInt(AndroidTypeMapper.NATIVE_INT_SIZE*i, value); |
767 settings.setInt(AndroidTypeMapper.NATIVE_INT_SIZE*i, value); |
768 } |
768 } |
769 mods = new Memory(AndroidTypeMapper.NATIVE_BOOL_SIZE * meta.mods.size()); |
769 mods = new Memory(AndroidTypeMapper.NATIVE_BOOL_SIZE * meta.mods.size()); |
770 for(int i=0; i<meta.mods.size(); i++) { |
770 for(int i=0; i<meta.mods.size(); i++) { |
771 Boolean value = scheme.mods.get(meta.mods.get(i).name); |
771 Boolean value = scheme.mods.get(meta.mods.get(i).name); |
772 mods.setByte(AndroidTypeMapper.NATIVE_BOOL_SIZE*i, (byte)(value ? 1 : 0)); |
772 mods.setByte(AndroidTypeMapper.NATIVE_BOOL_SIZE*i, (byte)(value ? 1 : 0)); |
773 } |
773 } |
774 } |
774 } |
775 |
775 |
776 public Scheme toScheme() { |
776 public Scheme toScheme() { |
777 Map<String, Integer> settingsMap = new HashMap<String, Integer>(); |
777 Map<String, Integer> settingsMap = new HashMap<String, Integer>(); |
778 MetaScheme meta = MetaScheme.INSTANCE; |
778 MetaScheme meta = MetaScheme.INSTANCE; |
779 for(int i=0; i<meta.settings.size(); i++) { |
779 for(int i=0; i<meta.settings.size(); i++) { |
780 settingsMap.put(meta.settings.get(i).name, settings.getInt(AndroidTypeMapper.NATIVE_INT_SIZE*i)); |
780 settingsMap.put(meta.settings.get(i).name, settings.getInt(AndroidTypeMapper.NATIVE_INT_SIZE*i)); |
781 } |
781 } |
782 Map<String, Boolean> modsMap = new HashMap<String, Boolean>(); |
782 Map<String, Boolean> modsMap = new HashMap<String, Boolean>(); |
783 for(int i=0; i<meta.mods.size(); i++) { |
783 for(int i=0; i<meta.mods.size(); i++) { |
784 modsMap.put(meta.mods.get(i).name, mods.getByte(i) != 0 ? Boolean.TRUE : Boolean.FALSE); |
784 modsMap.put(meta.mods.get(i).name, mods.getByte(i) != 0 ? Boolean.TRUE : Boolean.FALSE); |
785 } |
785 } |
786 return new Scheme(name, settingsMap, modsMap); |
786 return new Scheme(name, settingsMap, modsMap); |
787 } |
787 } |
788 |
788 |
789 public String name; |
789 public String name; |
790 public Pointer settings; |
790 public Pointer settings; |
791 public Pointer mods; |
791 public Pointer mods; |
792 } |
792 } |
793 |
793 |
794 /** |
794 /** |
795 * Represents a flib_scheme*, for use as part of a flib_scheme** |
795 * Represents a flib_scheme*, for use as part of a flib_scheme** |
796 */ |
796 */ |
797 static class SchemePointerByReference extends Structure implements Structure.ByReference { |
797 static class SchemePointerByReference extends Structure implements Structure.ByReference { |
798 public SchemePointerByReference() { super(); } |
798 public SchemePointerByReference() { super(); } |
799 public SchemePointerByReference(Pointer ptr) { super(ptr); } |
799 public SchemePointerByReference(Pointer ptr) { super(ptr); } |
800 |
800 |
801 @Override |
801 @Override |
802 protected List<String> getFieldOrder() { |
802 protected List<String> getFieldOrder() { |
803 return Arrays.asList("scheme"); |
803 return Arrays.asList("scheme"); |
804 } |
804 } |
805 |
805 |
806 public SchemeStruct.ByRef scheme; |
806 public SchemeStruct.ByRef scheme; |
807 } |
807 } |
808 |
808 |
809 static class SchemelistStruct extends Structure { |
809 static class SchemelistStruct extends Structure { |
810 public static class ByVal extends SchemelistStruct implements Structure.ByValue {} |
810 public static class ByVal extends SchemelistStruct implements Structure.ByValue {} |
811 public static class ByRef extends SchemelistStruct implements Structure.ByReference {} |
811 public static class ByRef extends SchemelistStruct implements Structure.ByReference {} |
812 |
812 |
813 public SchemelistStruct() { super(); } |
813 public SchemelistStruct() { super(); } |
814 public SchemelistStruct(Pointer ptr) { super(ptr); } |
814 public SchemelistStruct(Pointer ptr) { super(ptr); } |
815 |
815 |
816 @Override |
816 @Override |
817 protected List<String> getFieldOrder() { |
817 protected List<String> getFieldOrder() { |
818 return Arrays.asList("schemeCount", "schemes"); |
818 return Arrays.asList("schemeCount", "schemes"); |
819 } |
819 } |
820 |
820 |
821 public void fillFrom(List<Scheme> schemeList) { |
821 public void fillFrom(List<Scheme> schemeList) { |
822 schemeCount = schemeList.size(); |
822 schemeCount = schemeList.size(); |
823 if(schemeCount<=0) { |
823 if(schemeCount<=0) { |
824 schemes = null; |
824 schemes = null; |
825 } else { |
825 } else { |
826 schemes = new SchemePointerByReference(); |
826 schemes = new SchemePointerByReference(); |
827 Structure[] schemePtrStructs = schemes.toArray(schemeCount); |
827 Structure[] schemePtrStructs = schemes.toArray(schemeCount); |
828 |
828 |
829 for(int i=0; i<this.schemeCount; i++) { |
829 for(int i=0; i<this.schemeCount; i++) { |
830 SchemePointerByReference spbr = (SchemePointerByReference)schemePtrStructs[i]; |
830 SchemePointerByReference spbr = (SchemePointerByReference)schemePtrStructs[i]; |
831 spbr.scheme = new SchemeStruct.ByRef(); |
831 spbr.scheme = new SchemeStruct.ByRef(); |
832 spbr.scheme.fillFrom(schemeList.get(i)); |
832 spbr.scheme.fillFrom(schemeList.get(i)); |
833 } |
833 } |
834 } |
834 } |
835 } |
835 } |
836 |
836 |
837 /** |
837 /** |
838 * Only use on native-owned structs! |
838 * Only use on native-owned structs! |
839 * Calling this method on a Java-owned struct could cause garbage collection of referenced |
839 * Calling this method on a Java-owned struct could cause garbage collection of referenced |
840 * structures. |
840 * structures. |
841 */ |
841 */ |
842 public List<Scheme> toSchemeList() { |
842 public List<Scheme> toSchemeList() { |
843 if(schemeCount<=0) { |
843 if(schemeCount<=0) { |
844 return new ArrayList<Scheme>(); |
844 return new ArrayList<Scheme>(); |
845 } else { |
845 } else { |
846 List<Scheme> schemeList = new ArrayList<Scheme>(schemeCount); |
846 List<Scheme> schemeList = new ArrayList<Scheme>(schemeCount); |
847 |
847 |
848 Structure[] schemePtrStructs = schemes.toArray(schemeCount); |
848 Structure[] schemePtrStructs = schemes.toArray(schemeCount); |
849 |
849 |
850 for(int i=0; i<schemeCount; i++) { |
850 for(int i=0; i<schemeCount; i++) { |
851 SchemePointerByReference spbr2 = (SchemePointerByReference)schemePtrStructs[i]; |
851 SchemePointerByReference spbr2 = (SchemePointerByReference)schemePtrStructs[i]; |
852 schemeList.add(spbr2.scheme.toScheme()); |
852 schemeList.add(spbr2.scheme.toScheme()); |
853 } |
853 } |
854 return schemeList; |
854 return schemeList; |
855 } |
855 } |
856 } |
856 } |
857 |
857 |
858 public int schemeCount; |
858 public int schemeCount; |
859 public SchemePointerByReference schemes; |
859 public SchemePointerByReference schemes; |
860 } |
860 } |
861 |
861 |
862 /** |
862 /** |
863 * Represents a flib_team*, for use as part of a flib_team** |
863 * Represents a flib_team*, for use as part of a flib_team** |
864 */ |
864 */ |
865 static class TeamPointerByReference extends Structure implements Structure.ByReference { |
865 static class TeamPointerByReference extends Structure implements Structure.ByReference { |
866 public TeamPointerByReference() { super(); } |
866 public TeamPointerByReference() { super(); } |
867 public TeamPointerByReference(Pointer ptr) { super(ptr); } |
867 public TeamPointerByReference(Pointer ptr) { super(ptr); } |
868 |
868 |
869 @Override |
869 @Override |
870 protected List<String> getFieldOrder() { |
870 protected List<String> getFieldOrder() { |
871 return Arrays.asList("team"); |
871 return Arrays.asList("team"); |
872 } |
872 } |
873 |
873 |
874 public TeamStruct.ByRef team; |
874 public TeamStruct.ByRef team; |
875 } |
875 } |
876 |
876 |
877 static class TeamlistStruct extends Structure { |
877 static class TeamlistStruct extends Structure { |
878 public static class ByVal extends TeamlistStruct implements Structure.ByValue {} |
878 public static class ByVal extends TeamlistStruct implements Structure.ByValue {} |
879 public static class ByRef extends TeamlistStruct implements Structure.ByReference {} |
879 public static class ByRef extends TeamlistStruct implements Structure.ByReference {} |
880 |
880 |
881 public TeamlistStruct() { super(); } |
881 public TeamlistStruct() { super(); } |
882 public TeamlistStruct(Pointer ptr) { super(ptr); } |
882 public TeamlistStruct(Pointer ptr) { super(ptr); } |
883 |
883 |
884 @Override |
884 @Override |
885 protected List<String> getFieldOrder() { |
885 protected List<String> getFieldOrder() { |
886 return Arrays.asList("teamCount", "teams"); |
886 return Arrays.asList("teamCount", "teams"); |
887 } |
887 } |
888 |
888 |
889 public void fillFrom(List<TeamInGame> teamList, WeaponsetStruct.ByRef weaponset, int initialHealth) { |
889 public void fillFrom(List<TeamInGame> teamList, WeaponsetStruct.ByRef weaponset, int initialHealth) { |
890 teamCount = teamList.size(); |
890 teamCount = teamList.size(); |
891 if(teamCount <= 0) { |
891 if(teamCount <= 0) { |
892 teams = null; |
892 teams = null; |
893 } else { |
893 } else { |
894 teams = new TeamPointerByReference(); |
894 teams = new TeamPointerByReference(); |
895 Structure[] teamPtrStructs = teams.toArray(teamCount); |
895 Structure[] teamPtrStructs = teams.toArray(teamCount); |
896 |
896 |
897 for(int i=0; i<this.teamCount; i++) { |
897 for(int i=0; i<this.teamCount; i++) { |
898 TeamPointerByReference tpbr = (TeamPointerByReference)teamPtrStructs[i]; |
898 TeamPointerByReference tpbr = (TeamPointerByReference)teamPtrStructs[i]; |
899 tpbr.team = new TeamStruct.ByRef(); |
899 tpbr.team = new TeamStruct.ByRef(); |
900 tpbr.team.fillFrom(teamList.get(i), weaponset, initialHealth); |
900 tpbr.team.fillFrom(teamList.get(i), weaponset, initialHealth); |
901 } |
901 } |
902 } |
902 } |
903 } |
903 } |
904 |
904 |
905 public List<TeamInGame> toTeamInGameList() { |
905 public List<TeamInGame> toTeamInGameList() { |
906 if(teamCount<=0) { |
906 if(teamCount<=0) { |
907 return new ArrayList<TeamInGame>(); |
907 return new ArrayList<TeamInGame>(); |
908 } else { |
908 } else { |
909 List<TeamInGame> result = new ArrayList<TeamInGame>(teamCount); |
909 List<TeamInGame> result = new ArrayList<TeamInGame>(teamCount); |
910 Structure[] structs = teams.toArray(teamCount); |
910 Structure[] structs = teams.toArray(teamCount); |
911 |
911 |
912 for(int i=0; i<teamCount; i++) { |
912 for(int i=0; i<teamCount; i++) { |
913 TeamPointerByReference struct = (TeamPointerByReference)structs[i]; |
913 TeamPointerByReference struct = (TeamPointerByReference)structs[i]; |
914 result.add(struct.team.toTeamInGame()); |
914 result.add(struct.team.toTeamInGame()); |
915 } |
915 } |
916 return result; |
916 return result; |
917 } |
917 } |
918 } |
918 } |
919 |
919 |
920 public int teamCount; |
920 public int teamCount; |
921 public TeamPointerByReference teams; |
921 public TeamPointerByReference teams; |
922 } |
922 } |
923 |
923 |
924 static class GameSetupStruct extends Structure { |
924 static class GameSetupStruct extends Structure { |
925 public static class ByVal extends GameSetupStruct implements Structure.ByValue {} |
925 public static class ByVal extends GameSetupStruct implements Structure.ByValue {} |
926 public static class ByRef extends GameSetupStruct implements Structure.ByReference {} |
926 public static class ByRef extends GameSetupStruct implements Structure.ByReference {} |
927 |
927 |
928 public GameSetupStruct() { super(); } |
928 public GameSetupStruct() { super(); } |
929 public GameSetupStruct(Pointer ptr) { super(ptr); } |
929 public GameSetupStruct(Pointer ptr) { super(ptr); } |
930 |
930 |
931 @Override |
931 @Override |
932 protected List<String> getFieldOrder() { |
932 protected List<String> getFieldOrder() { |
933 return Arrays.asList("script", "gamescheme", "map", "teamlist"); |
933 return Arrays.asList("script", "gamescheme", "map", "teamlist"); |
934 } |
934 } |
935 |
935 |
936 public void fillFrom(GameConfig conf) { |
936 public void fillFrom(GameConfig conf) { |
937 script = conf.style; |
937 script = conf.style; |
938 gamescheme = new SchemeStruct.ByRef(); |
938 gamescheme = new SchemeStruct.ByRef(); |
939 gamescheme.fillFrom(conf.scheme); |
939 gamescheme.fillFrom(conf.scheme); |
940 map = new MapRecipeStruct.ByRef(); |
940 map = new MapRecipeStruct.ByRef(); |
941 map.fillFrom(conf.map); |
941 map.fillFrom(conf.map); |
942 |
942 |
943 /* |
943 /* |
944 * At this point we deviate from the usual copying pattern because the frontlib |
944 * At this point we deviate from the usual copying pattern because the frontlib |
945 * expects per-hog weapons and initial health, but the UI models them as per- |
945 * expects per-hog weapons and initial health, but the UI models them as per- |
946 * game, so we extract them from the config here and pass them on to be included |
946 * game, so we extract them from the config here and pass them on to be included |
947 * in each hog. |
947 * in each hog. |
948 */ |
948 */ |
949 WeaponsetStruct.ByRef wss = new WeaponsetStruct.ByRef(); |
949 WeaponsetStruct.ByRef wss = new WeaponsetStruct.ByRef(); |
950 wss.fillFrom(conf.weaponset); |
950 wss.fillFrom(conf.weaponset); |
951 int initialHealth = conf.scheme.getHealth(); |
951 int initialHealth = conf.scheme.getHealth(); |
952 |
952 |
953 teamlist = new TeamlistStruct.ByRef(); |
953 teamlist = new TeamlistStruct.ByRef(); |
954 teamlist.fillFrom(conf.teams, wss, initialHealth); |
954 teamlist.fillFrom(conf.teams, wss, initialHealth); |
955 } |
955 } |
956 |
956 |
957 public GameConfig toGameConfig() { |
957 public GameConfig toGameConfig() { |
958 Scheme scheme = gamescheme != null ? gamescheme.toScheme() : null; |
958 Scheme scheme = gamescheme != null ? gamescheme.toScheme() : null; |
959 MapRecipe mapRecipe = map != null ? map.toMapRecipe() : null; |
959 MapRecipe mapRecipe = map != null ? map.toMapRecipe() : null; |
960 List<TeamInGame> teams = teamlist != null ? teamlist.toTeamInGameList() : null; |
960 List<TeamInGame> teams = teamlist != null ? teamlist.toTeamInGameList() : null; |
961 |
961 |
962 WeaponsetStruct weaponsetStruct = teamlist != null && teamlist.teamCount>0 ? teamlist.teams.team.hogs[0].weaponset : null; |
962 WeaponsetStruct weaponsetStruct = teamlist != null && teamlist.teamCount>0 ? teamlist.teams.team.hogs[0].weaponset : null; |
963 Weaponset weaponset = weaponsetStruct != null ? weaponsetStruct.toWeaponset() : null; |
963 Weaponset weaponset = weaponsetStruct != null ? weaponsetStruct.toWeaponset() : null; |
964 return new GameConfig(script, scheme, mapRecipe, teams, weaponset); |
964 return new GameConfig(script, scheme, mapRecipe, teams, weaponset); |
965 } |
965 } |
966 |
966 |
967 public String script; |
967 public String script; |
968 public SchemeStruct.ByRef gamescheme; |
968 public SchemeStruct.ByRef gamescheme; |
969 public MapRecipeStruct.ByRef map; |
969 public MapRecipeStruct.ByRef map; |
970 public TeamlistStruct.ByRef teamlist; |
970 public TeamlistStruct.ByRef teamlist; |
971 } |
971 } |
972 |
972 |
973 /* |
973 /* |
974 * Callback interfaces. The context parameter is never needed here and |
974 * Callback interfaces. The context parameter is never needed here and |
975 * should always be ignored. Be sure to keep a reference to each callback |
975 * should always be ignored. Be sure to keep a reference to each callback |
976 * for as long as they might be called by native code, to avoid premature |
976 * for as long as they might be called by native code, to avoid premature |
977 * garbage collection. |
977 * garbage collection. |
978 */ |
978 */ |
979 public static interface VoidCallback extends Callback { |
979 public static interface VoidCallback extends Callback { |
980 void callback(Pointer context); |
980 void callback(Pointer context); |
981 } |
981 } |
982 |
982 |
983 public static interface StrCallback extends Callback { |
983 public static interface StrCallback extends Callback { |
984 void callback(Pointer context, String arg1); |
984 void callback(Pointer context, String arg1); |
985 } |
985 } |
986 |
986 |
987 public static interface IntCallback extends Callback { |
987 public static interface IntCallback extends Callback { |
988 void callback(Pointer context, int arg1); |
988 void callback(Pointer context, int arg1); |
989 } |
989 } |
990 |
990 |
991 public static interface IntStrCallback extends Callback { |
991 public static interface IntStrCallback extends Callback { |
992 void callback(Pointer context, int arg1, String arg2); |
992 void callback(Pointer context, int arg1, String arg2); |
993 } |
993 } |
994 |
994 |
995 public static interface StrIntCallback extends Callback { |
995 public static interface StrIntCallback extends Callback { |
996 void callback(Pointer context, String arg1, int arg2); |
996 void callback(Pointer context, String arg1, int arg2); |
997 } |
997 } |
998 |
998 |
999 public static interface StrStrCallback extends Callback { |
999 public static interface StrStrCallback extends Callback { |
1000 void callback(Pointer context, String arg1, String arg2); |
1000 void callback(Pointer context, String arg1, String arg2); |
1001 } |
1001 } |
1002 |
1002 |
1003 public static interface StrStrBoolCallback extends Callback { |
1003 public static interface StrStrBoolCallback extends Callback { |
1004 void callback(Pointer context, String arg1, String arg2, boolean arg3); |
1004 void callback(Pointer context, String arg1, String arg2, boolean arg3); |
1005 } |
1005 } |
1006 |
1006 |
1007 public static interface RoomCallback extends Callback { |
1007 public static interface RoomCallback extends Callback { |
1008 void callback(Pointer context, RoomPtr arg1); |
1008 void callback(Pointer context, RoomPtr arg1); |
1009 } |
1009 } |
1010 |
1010 |
1011 public static interface RoomListCallback extends Callback { |
1011 public static interface RoomListCallback extends Callback { |
1012 void callback(Pointer context, RoomArrayPtr arg1, int count); |
1012 void callback(Pointer context, RoomArrayPtr arg1, int count); |
1013 } |
1013 } |
1014 |
1014 |
1015 public static interface StrRoomCallback extends Callback { |
1015 public static interface StrRoomCallback extends Callback { |
1016 void callback(Pointer context, String arg1, RoomPtr arg2); |
1016 void callback(Pointer context, String arg1, RoomPtr arg2); |
1017 } |
1017 } |
1018 |
1018 |
1019 public static interface BoolCallback extends Callback { |
1019 public static interface BoolCallback extends Callback { |
1020 void callback(Pointer context, boolean arg1); |
1020 void callback(Pointer context, boolean arg1); |
1021 } |
1021 } |
1022 |
1022 |
1023 public static interface StrBoolCallback extends Callback { |
1023 public static interface StrBoolCallback extends Callback { |
1024 void callback(Pointer context, String arg1, boolean arg2); |
1024 void callback(Pointer context, String arg1, boolean arg2); |
1025 } |
1025 } |
1026 |
1026 |
1027 public static interface TeamCallback extends Callback { |
1027 public static interface TeamCallback extends Callback { |
1028 void callback(Pointer context, TeamPtr arg1); |
1028 void callback(Pointer context, TeamPtr arg1); |
1029 } |
1029 } |
1030 |
1030 |
1031 public static interface BytesCallback extends Callback { |
1031 public static interface BytesCallback extends Callback { |
1032 void callback(Pointer context, ByteArrayPtr buffer, NativeSizeT size); |
1032 void callback(Pointer context, ByteArrayPtr buffer, NativeSizeT size); |
1033 } |
1033 } |
1034 |
1034 |
1035 public static interface BytesBoolCallback extends Callback { |
1035 public static interface BytesBoolCallback extends Callback { |
1036 void callback(Pointer context, ByteArrayPtr buffer, NativeSizeT size, boolean arg3); |
1036 void callback(Pointer context, ByteArrayPtr buffer, NativeSizeT size, boolean arg3); |
1037 } |
1037 } |
1038 |
1038 |
1039 public static interface SchemeCallback extends Callback { |
1039 public static interface SchemeCallback extends Callback { |
1040 void callback(Pointer context, SchemePtr arg1); |
1040 void callback(Pointer context, SchemePtr arg1); |
1041 } |
1041 } |
1042 |
1042 |
1043 public static interface MapIntCallback extends Callback { |
1043 public static interface MapIntCallback extends Callback { |
1044 void callback(Pointer context, MapRecipePtr arg1, int arg2); |
1044 void callback(Pointer context, MapRecipePtr arg1, int arg2); |
1045 } |
1045 } |
1046 |
1046 |
1047 public static interface WeaponsetCallback extends Callback { |
1047 public static interface WeaponsetCallback extends Callback { |
1048 void callback(Pointer context, WeaponsetPtr arg1); |
1048 void callback(Pointer context, WeaponsetPtr arg1); |
1049 } |
1049 } |
1050 |
1050 |
1051 public static interface MapimageCallback extends Callback { |
1051 public static interface MapimageCallback extends Callback { |
1052 void callback(Pointer context, ByteArrayPtr buffer, int hedgehogCount); |
1052 void callback(Pointer context, ByteArrayPtr buffer, int hedgehogCount); |
1053 } |
1053 } |
1054 |
1054 |
1055 public static interface LogCallback extends Callback { |
1055 public static interface LogCallback extends Callback { |
1056 void callback(int level, String logMessage); |
1056 void callback(int level, String logMessage); |
1057 } |
1057 } |
1058 |
1058 |
1059 // frontlib.h |
1059 // frontlib.h |
1060 int flib_init(); |
1060 int flib_init(); |
1061 void flib_quit(); |
1061 void flib_quit(); |
1062 |
1062 |
1063 // hwconsts.h |
1063 // hwconsts.h |
1064 int flib_get_teamcolor(int colorIndex); |
1064 int flib_get_teamcolor(int colorIndex); |
1065 int flib_get_teamcolor_count(); |
1065 int flib_get_teamcolor_count(); |
1066 int flib_get_hedgehogs_per_team(); |
1066 int flib_get_hedgehogs_per_team(); |
1067 int flib_get_weapons_count(); |
1067 int flib_get_weapons_count(); |
1068 MetaschemePtr flib_get_metascheme(); |
1068 MetaschemePtr flib_get_metascheme(); |
1069 |
1069 |
1070 // net/netconn.h |
1070 // net/netconn.h |
1071 static final int NETCONN_STATE_CONNECTING = 0; |
1071 static final int NETCONN_STATE_CONNECTING = 0; |
1072 static final int NETCONN_STATE_LOBBY = 1; |
1072 static final int NETCONN_STATE_LOBBY = 1; |
1073 static final int NETCONN_STATE_ROOM = 2; |
1073 static final int NETCONN_STATE_ROOM = 2; |
1074 static final int NETCONN_STATE_DISCONNECTED = 10; |
1074 static final int NETCONN_STATE_DISCONNECTED = 10; |
1075 |
1075 |
1076 static final int NETCONN_DISCONNECT_NORMAL = 0; |
1076 static final int NETCONN_DISCONNECT_NORMAL = 0; |
1077 static final int NETCONN_DISCONNECT_SERVER_TOO_OLD = 1; |
1077 static final int NETCONN_DISCONNECT_SERVER_TOO_OLD = 1; |
1078 static final int NETCONN_DISCONNECT_AUTH_FAILED = 2; |
1078 static final int NETCONN_DISCONNECT_AUTH_FAILED = 2; |
1079 static final int NETCONN_DISCONNECT_CONNLOST = 3; |
1079 static final int NETCONN_DISCONNECT_CONNLOST = 3; |
1080 static final int NETCONN_DISCONNECT_INTERNAL_ERROR = 100; |
1080 static final int NETCONN_DISCONNECT_INTERNAL_ERROR = 100; |
1081 |
1081 |
1082 static final int NETCONN_ROOMLEAVE_ABANDONED = 0; |
1082 static final int NETCONN_ROOMLEAVE_ABANDONED = 0; |
1083 static final int NETCONN_ROOMLEAVE_KICKED = 1; |
1083 static final int NETCONN_ROOMLEAVE_KICKED = 1; |
1084 |
1084 |
1085 static final int NETCONN_MSG_TYPE_PLAYERINFO = 0; |
1085 static final int NETCONN_MSG_TYPE_PLAYERINFO = 0; |
1086 static final int NETCONN_MSG_TYPE_SERVERMESSAGE = 1; |
1086 static final int NETCONN_MSG_TYPE_SERVERMESSAGE = 1; |
1087 static final int NETCONN_MSG_TYPE_WARNING = 2; |
1087 static final int NETCONN_MSG_TYPE_WARNING = 2; |
1088 static final int NETCONN_MSG_TYPE_ERROR = 3; |
1088 static final int NETCONN_MSG_TYPE_ERROR = 3; |
1089 |
1089 |
1090 static final int NETCONN_MAPCHANGE_FULL = 0; |
1090 static final int NETCONN_MAPCHANGE_FULL = 0; |
1091 static final int NETCONN_MAPCHANGE_MAP = 1; |
1091 static final int NETCONN_MAPCHANGE_MAP = 1; |
1092 static final int NETCONN_MAPCHANGE_MAPGEN = 2; |
1092 static final int NETCONN_MAPCHANGE_MAPGEN = 2; |
1093 static final int NETCONN_MAPCHANGE_DRAWNMAP = 3; |
1093 static final int NETCONN_MAPCHANGE_DRAWNMAP = 3; |
1094 static final int NETCONN_MAPCHANGE_MAZE_SIZE = 4; |
1094 static final int NETCONN_MAPCHANGE_MAZE_SIZE = 4; |
1095 static final int NETCONN_MAPCHANGE_TEMPLATE = 5; |
1095 static final int NETCONN_MAPCHANGE_TEMPLATE = 5; |
1096 static final int NETCONN_MAPCHANGE_THEME = 6; |
1096 static final int NETCONN_MAPCHANGE_THEME = 6; |
1097 static final int NETCONN_MAPCHANGE_SEED = 7; |
1097 static final int NETCONN_MAPCHANGE_SEED = 7; |
1098 |
1098 |
1099 NetconnPtr flib_netconn_create(String playerName, String dataDirPath, String host, int port); |
1099 NetconnPtr flib_netconn_create(String playerName, String dataDirPath, String host, int port); |
1100 void flib_netconn_destroy(NetconnPtr conn); |
1100 void flib_netconn_destroy(NetconnPtr conn); |
1101 |
1101 |
1102 void flib_netconn_tick(NetconnPtr conn); |
1102 void flib_netconn_tick(NetconnPtr conn); |
1103 boolean flib_netconn_is_chief(NetconnPtr conn); |
1103 boolean flib_netconn_is_chief(NetconnPtr conn); |
1104 String flib_netconn_get_playername(NetconnPtr conn); |
1104 String flib_netconn_get_playername(NetconnPtr conn); |
1105 GameSetupPtr flib_netconn_create_gamesetup(NetconnPtr conn); |
1105 GameSetupPtr flib_netconn_create_gamesetup(NetconnPtr conn); |
1106 int flib_netconn_send_quit(NetconnPtr conn, String quitmsg); |
1106 int flib_netconn_send_quit(NetconnPtr conn, String quitmsg); |
1107 int flib_netconn_send_chat(NetconnPtr conn, String chat); |
1107 int flib_netconn_send_chat(NetconnPtr conn, String chat); |
1108 int flib_netconn_send_teamchat(NetconnPtr conn, String msg); |
1108 int flib_netconn_send_teamchat(NetconnPtr conn, String msg); |
1109 int flib_netconn_send_password(NetconnPtr conn, String passwd); |
1109 int flib_netconn_send_password(NetconnPtr conn, String passwd); |
1110 int flib_netconn_send_nick(NetconnPtr conn, String nick); |
1110 int flib_netconn_send_nick(NetconnPtr conn, String nick); |
1111 int flib_netconn_send_request_roomlist(NetconnPtr conn); |
1111 int flib_netconn_send_request_roomlist(NetconnPtr conn); |
1112 int flib_netconn_send_joinRoom(NetconnPtr conn, String room); |
1112 int flib_netconn_send_joinRoom(NetconnPtr conn, String room); |
1113 int flib_netconn_send_createRoom(NetconnPtr conn, String room); |
1113 int flib_netconn_send_createRoom(NetconnPtr conn, String room); |
1114 int flib_netconn_send_renameRoom(NetconnPtr conn, String roomName); |
1114 int flib_netconn_send_renameRoom(NetconnPtr conn, String roomName); |
1115 int flib_netconn_send_leaveRoom(NetconnPtr conn, String msg); |
1115 int flib_netconn_send_leaveRoom(NetconnPtr conn, String msg); |
1116 int flib_netconn_send_toggleReady(NetconnPtr conn); |
1116 int flib_netconn_send_toggleReady(NetconnPtr conn); |
1117 int flib_netconn_send_addTeam(NetconnPtr conn, TeamPtr team); |
1117 int flib_netconn_send_addTeam(NetconnPtr conn, TeamPtr team); |
1118 int flib_netconn_send_removeTeam(NetconnPtr conn, String teamname); |
1118 int flib_netconn_send_removeTeam(NetconnPtr conn, String teamname); |
1119 int flib_netconn_send_engineMessage(NetconnPtr conn, ByteArrayPtr message, NativeSizeT size); |
1119 int flib_netconn_send_engineMessage(NetconnPtr conn, ByteArrayPtr message, NativeSizeT size); |
1120 int flib_netconn_send_teamHogCount(NetconnPtr conn, String teamname, int hogcount); |
1120 int flib_netconn_send_teamHogCount(NetconnPtr conn, String teamname, int hogcount); |
1121 int flib_netconn_send_teamColor(NetconnPtr conn, String teamname, int colorIndex); |
1121 int flib_netconn_send_teamColor(NetconnPtr conn, String teamname, int colorIndex); |
1122 int flib_netconn_send_weaponset(NetconnPtr conn, WeaponsetPtr weaponset); |
1122 int flib_netconn_send_weaponset(NetconnPtr conn, WeaponsetPtr weaponset); |
1123 int flib_netconn_send_map(NetconnPtr conn, MapRecipePtr map); |
1123 int flib_netconn_send_map(NetconnPtr conn, MapRecipePtr map); |
1124 int flib_netconn_send_mapName(NetconnPtr conn, String mapName); |
1124 int flib_netconn_send_mapName(NetconnPtr conn, String mapName); |
1125 int flib_netconn_send_mapGen(NetconnPtr conn, int mapGen); |
1125 int flib_netconn_send_mapGen(NetconnPtr conn, int mapGen); |
1126 int flib_netconn_send_mapTemplate(NetconnPtr conn, int templateFilter); |
1126 int flib_netconn_send_mapTemplate(NetconnPtr conn, int templateFilter); |
1127 int flib_netconn_send_mapMazeSize(NetconnPtr conn, int mazeSize); |
1127 int flib_netconn_send_mapMazeSize(NetconnPtr conn, int mazeSize); |
1128 int flib_netconn_send_mapSeed(NetconnPtr conn, String seed); |
1128 int flib_netconn_send_mapSeed(NetconnPtr conn, String seed); |
1129 int flib_netconn_send_mapTheme(NetconnPtr conn, String theme); |
1129 int flib_netconn_send_mapTheme(NetconnPtr conn, String theme); |
1130 int flib_netconn_send_mapDrawdata(NetconnPtr conn, ByteArrayPtr drawData, NativeSizeT size); |
1130 int flib_netconn_send_mapDrawdata(NetconnPtr conn, ByteArrayPtr drawData, NativeSizeT size); |
1131 int flib_netconn_send_script(NetconnPtr conn, String scriptName); |
1131 int flib_netconn_send_script(NetconnPtr conn, String scriptName); |
1132 int flib_netconn_send_scheme(NetconnPtr conn, SchemePtr scheme); |
1132 int flib_netconn_send_scheme(NetconnPtr conn, SchemePtr scheme); |
1133 int flib_netconn_send_roundfinished(NetconnPtr conn, boolean withoutError); |
1133 int flib_netconn_send_roundfinished(NetconnPtr conn, boolean withoutError); |
1134 int flib_netconn_send_ban(NetconnPtr conn, String playerName); |
1134 int flib_netconn_send_ban(NetconnPtr conn, String playerName); |
1135 int flib_netconn_send_kick(NetconnPtr conn, String playerName); |
1135 int flib_netconn_send_kick(NetconnPtr conn, String playerName); |
1136 int flib_netconn_send_playerInfo(NetconnPtr conn, String playerName); |
1136 int flib_netconn_send_playerInfo(NetconnPtr conn, String playerName); |
1137 int flib_netconn_send_playerFollow(NetconnPtr conn, String playerName); |
1137 int flib_netconn_send_playerFollow(NetconnPtr conn, String playerName); |
1138 int flib_netconn_send_startGame(NetconnPtr conn); |
1138 int flib_netconn_send_startGame(NetconnPtr conn); |
1139 int flib_netconn_send_toggleRestrictJoins(NetconnPtr conn); |
1139 int flib_netconn_send_toggleRestrictJoins(NetconnPtr conn); |
1140 int flib_netconn_send_toggleRestrictTeams(NetconnPtr conn); |
1140 int flib_netconn_send_toggleRestrictTeams(NetconnPtr conn); |
1141 int flib_netconn_send_clearAccountsCache(NetconnPtr conn); |
1141 int flib_netconn_send_clearAccountsCache(NetconnPtr conn); |
1142 int flib_netconn_send_setServerVar(NetconnPtr conn, String name, String value); |
1142 int flib_netconn_send_setServerVar(NetconnPtr conn, String name, String value); |
1143 int flib_netconn_send_getServerVars(NetconnPtr conn); |
1143 int flib_netconn_send_getServerVars(NetconnPtr conn); |
1144 |
1144 |
1145 void flib_netconn_onMessage(NetconnPtr conn, IntStrCallback callback, Pointer context); |
1145 void flib_netconn_onMessage(NetconnPtr conn, IntStrCallback callback, Pointer context); |
1146 void flib_netconn_onClientFlags(NetconnPtr conn, StrStrBoolCallback callback, Pointer context); |
1146 void flib_netconn_onClientFlags(NetconnPtr conn, StrStrBoolCallback callback, Pointer context); |
1147 void flib_netconn_onChat(NetconnPtr conn, StrStrCallback callback, Pointer context); |
1147 void flib_netconn_onChat(NetconnPtr conn, StrStrCallback callback, Pointer context); |
1148 void flib_netconn_onConnected(NetconnPtr conn, VoidCallback callback, Pointer context); |
1148 void flib_netconn_onConnected(NetconnPtr conn, VoidCallback callback, Pointer context); |
1149 void flib_netconn_onDisconnected(NetconnPtr conn, IntStrCallback callback, Pointer context); |
1149 void flib_netconn_onDisconnected(NetconnPtr conn, IntStrCallback callback, Pointer context); |
1150 void flib_netconn_onRoomlist(NetconnPtr conn, RoomListCallback callback, Pointer context); |
1150 void flib_netconn_onRoomlist(NetconnPtr conn, RoomListCallback callback, Pointer context); |
1151 void flib_netconn_onRoomAdd(NetconnPtr conn, RoomCallback callback, Pointer context); |
1151 void flib_netconn_onRoomAdd(NetconnPtr conn, RoomCallback callback, Pointer context); |
1152 void flib_netconn_onRoomDelete(NetconnPtr conn, StrCallback callback, Pointer context); |
1152 void flib_netconn_onRoomDelete(NetconnPtr conn, StrCallback callback, Pointer context); |
1153 void flib_netconn_onRoomUpdate(NetconnPtr conn, StrRoomCallback callback, Pointer context); |
1153 void flib_netconn_onRoomUpdate(NetconnPtr conn, StrRoomCallback callback, Pointer context); |
1154 void flib_netconn_onLobbyJoin(NetconnPtr conn, StrCallback callback, Pointer context); |
1154 void flib_netconn_onLobbyJoin(NetconnPtr conn, StrCallback callback, Pointer context); |
1155 void flib_netconn_onLobbyLeave(NetconnPtr conn, StrStrCallback callback, Pointer context); |
1155 void flib_netconn_onLobbyLeave(NetconnPtr conn, StrStrCallback callback, Pointer context); |
1156 void flib_netconn_onNickTaken(NetconnPtr conn, StrCallback callback, Pointer context); |
1156 void flib_netconn_onNickTaken(NetconnPtr conn, StrCallback callback, Pointer context); |
1157 void flib_netconn_onPasswordRequest(NetconnPtr conn, StrCallback callback, Pointer context); |
1157 void flib_netconn_onPasswordRequest(NetconnPtr conn, StrCallback callback, Pointer context); |
1158 void flib_netconn_onEnterRoom(NetconnPtr conn, BoolCallback callback, Pointer context); |
1158 void flib_netconn_onEnterRoom(NetconnPtr conn, BoolCallback callback, Pointer context); |
1159 void flib_netconn_onLeaveRoom(NetconnPtr conn, IntStrCallback callback, Pointer context); |
1159 void flib_netconn_onLeaveRoom(NetconnPtr conn, IntStrCallback callback, Pointer context); |
1160 void flib_netconn_onTeamAdd(NetconnPtr conn, TeamCallback callback, Pointer context); |
1160 void flib_netconn_onTeamAdd(NetconnPtr conn, TeamCallback callback, Pointer context); |
1161 void flib_netconn_onTeamDelete(NetconnPtr conn, StrCallback callback, Pointer context); |
1161 void flib_netconn_onTeamDelete(NetconnPtr conn, StrCallback callback, Pointer context); |
1162 void flib_netconn_onRoomJoin(NetconnPtr conn, StrCallback callback, Pointer context); |
1162 void flib_netconn_onRoomJoin(NetconnPtr conn, StrCallback callback, Pointer context); |
1163 void flib_netconn_onRoomLeave(NetconnPtr conn, StrStrCallback callback, Pointer context); |
1163 void flib_netconn_onRoomLeave(NetconnPtr conn, StrStrCallback callback, Pointer context); |
1164 void flib_netconn_onRunGame(NetconnPtr conn, VoidCallback callback, Pointer context); |
1164 void flib_netconn_onRunGame(NetconnPtr conn, VoidCallback callback, Pointer context); |
1165 void flib_netconn_onTeamAccepted(NetconnPtr conn, StrCallback callback, Pointer context); |
1165 void flib_netconn_onTeamAccepted(NetconnPtr conn, StrCallback callback, Pointer context); |
1166 void flib_netconn_onHogCountChanged(NetconnPtr conn, StrIntCallback callback, Pointer context); |
1166 void flib_netconn_onHogCountChanged(NetconnPtr conn, StrIntCallback callback, Pointer context); |
1167 void flib_netconn_onTeamColorChanged(NetconnPtr conn, StrIntCallback callback, Pointer context); |
1167 void flib_netconn_onTeamColorChanged(NetconnPtr conn, StrIntCallback callback, Pointer context); |
1168 void flib_netconn_onEngineMessage(NetconnPtr conn, BytesCallback callback, Pointer context); |
1168 void flib_netconn_onEngineMessage(NetconnPtr conn, BytesCallback callback, Pointer context); |
1169 void flib_netconn_onSchemeChanged(NetconnPtr conn, SchemeCallback callback, Pointer context); |
1169 void flib_netconn_onSchemeChanged(NetconnPtr conn, SchemeCallback callback, Pointer context); |
1170 void flib_netconn_onMapChanged(NetconnPtr conn, MapIntCallback callback, Pointer context); |
1170 void flib_netconn_onMapChanged(NetconnPtr conn, MapIntCallback callback, Pointer context); |
1171 void flib_netconn_onScriptChanged(NetconnPtr conn, StrCallback callback, Pointer context); |
1171 void flib_netconn_onScriptChanged(NetconnPtr conn, StrCallback callback, Pointer context); |
1172 void flib_netconn_onWeaponsetChanged(NetconnPtr conn, WeaponsetCallback callback, Pointer context); |
1172 void flib_netconn_onWeaponsetChanged(NetconnPtr conn, WeaponsetCallback callback, Pointer context); |
1173 void flib_netconn_onServerVar(NetconnPtr conn, StrStrCallback callback, Pointer context); |
1173 void flib_netconn_onServerVar(NetconnPtr conn, StrStrCallback callback, Pointer context); |
1174 |
1174 |
1175 // ipc/gameconn.h |
1175 // ipc/gameconn.h |
1176 static final int GAME_END_FINISHED = 0; |
1176 static final int GAME_END_FINISHED = 0; |
1177 static final int GAME_END_INTERRUPTED = 1; |
1177 static final int GAME_END_INTERRUPTED = 1; |
1178 static final int GAME_END_HALTED = 2; |
1178 static final int GAME_END_HALTED = 2; |
1179 static final int GAME_END_ERROR = 3; |
1179 static final int GAME_END_ERROR = 3; |
1180 |
1180 |
1181 GameconnPtr flib_gameconn_create(String playerName, GameSetupPtr setup, boolean netgame); |
1181 GameconnPtr flib_gameconn_create(String playerName, GameSetupPtr setup, boolean netgame); |
1182 GameconnPtr flib_gameconn_create_playdemo(ByteArrayPtr demo, NativeSizeT size); |
1182 GameconnPtr flib_gameconn_create_playdemo(ByteArrayPtr demo, NativeSizeT size); |
1183 GameconnPtr flib_gameconn_create_loadgame(String playerName, ByteArrayPtr save, NativeSizeT size); |
1183 GameconnPtr flib_gameconn_create_loadgame(String playerName, ByteArrayPtr save, NativeSizeT size); |
1184 GameconnPtr flib_gameconn_create_campaign(String playerName, String seed, String script); |
1184 GameconnPtr flib_gameconn_create_campaign(String playerName, String seed, String script); |
1185 |
1185 |
1186 void flib_gameconn_destroy(GameconnPtr conn); |
1186 void flib_gameconn_destroy(GameconnPtr conn); |
1187 int flib_gameconn_getport(GameconnPtr conn); |
1187 int flib_gameconn_getport(GameconnPtr conn); |
1188 void flib_gameconn_tick(GameconnPtr conn); |
1188 void flib_gameconn_tick(GameconnPtr conn); |
1189 |
1189 |
1190 int flib_gameconn_send_enginemsg(GameconnPtr conn, ByteArrayPtr data, NativeSizeT len); |
1190 int flib_gameconn_send_enginemsg(GameconnPtr conn, ByteArrayPtr data, NativeSizeT len); |
1191 int flib_gameconn_send_textmsg(GameconnPtr conn, int msgtype, String msg); |
1191 int flib_gameconn_send_textmsg(GameconnPtr conn, int msgtype, String msg); |
1192 int flib_gameconn_send_chatmsg(GameconnPtr conn, String playername, String msg); |
1192 int flib_gameconn_send_chatmsg(GameconnPtr conn, String playername, String msg); |
1193 int flib_gameconn_send_quit(GameconnPtr conn); |
1193 int flib_gameconn_send_quit(GameconnPtr conn); |
1194 int flib_gameconn_send_cmd(GameconnPtr conn, String cmdString); |
1194 int flib_gameconn_send_cmd(GameconnPtr conn, String cmdString); |
1195 |
1195 |
1196 void flib_gameconn_onConnect(GameconnPtr conn, VoidCallback callback, Pointer context); |
1196 void flib_gameconn_onConnect(GameconnPtr conn, VoidCallback callback, Pointer context); |
1197 void flib_gameconn_onDisconnect(GameconnPtr conn, IntCallback callback, Pointer context); |
1197 void flib_gameconn_onDisconnect(GameconnPtr conn, IntCallback callback, Pointer context); |
1198 void flib_gameconn_onErrorMessage(GameconnPtr conn, StrCallback callback, Pointer context); |
1198 void flib_gameconn_onErrorMessage(GameconnPtr conn, StrCallback callback, Pointer context); |
1199 void flib_gameconn_onChat(GameconnPtr conn, StrBoolCallback callback, Pointer context); |
1199 void flib_gameconn_onChat(GameconnPtr conn, StrBoolCallback callback, Pointer context); |
1200 void flib_gameconn_onGameRecorded(GameconnPtr conn, BytesBoolCallback callback, Pointer context); |
1200 void flib_gameconn_onGameRecorded(GameconnPtr conn, BytesBoolCallback callback, Pointer context); |
1201 void flib_gameconn_onEngineMessage(GameconnPtr conn, BytesCallback callback, Pointer context); |
1201 void flib_gameconn_onEngineMessage(GameconnPtr conn, BytesCallback callback, Pointer context); |
1202 |
1202 |
1203 // ipc/mapconn.h |
1203 // ipc/mapconn.h |
1204 public static final int MAPIMAGE_WIDTH = 256; |
1204 public static final int MAPIMAGE_WIDTH = 256; |
1205 public static final int MAPIMAGE_HEIGHT = 128; |
1205 public static final int MAPIMAGE_HEIGHT = 128; |
1206 public static final int MAPIMAGE_BYTES = (MAPIMAGE_WIDTH/8*MAPIMAGE_HEIGHT); |
1206 public static final int MAPIMAGE_BYTES = (MAPIMAGE_WIDTH/8*MAPIMAGE_HEIGHT); |
1207 |
1207 |
1208 MapconnPtr flib_mapconn_create(MapRecipePtr mapdesc); |
1208 MapconnPtr flib_mapconn_create(MapRecipePtr mapdesc); |
1209 void flib_mapconn_destroy(MapconnPtr conn); |
1209 void flib_mapconn_destroy(MapconnPtr conn); |
1210 int flib_mapconn_getport(MapconnPtr conn); |
1210 int flib_mapconn_getport(MapconnPtr conn); |
1211 void flib_mapconn_onSuccess(MapconnPtr conn, MapimageCallback callback, Pointer context); |
1211 void flib_mapconn_onSuccess(MapconnPtr conn, MapimageCallback callback, Pointer context); |
1212 void flib_mapconn_onFailure(MapconnPtr conn, StrCallback callback, Pointer context); |
1212 void flib_mapconn_onFailure(MapconnPtr conn, StrCallback callback, Pointer context); |
1213 void flib_mapconn_tick(MapconnPtr conn); |
1213 void flib_mapconn_tick(MapconnPtr conn); |
1214 |
1214 |
1215 // model/map.h |
1215 // model/map.h |
1216 public static final int MAPGEN_REGULAR = 0; |
1216 public static final int MAPGEN_REGULAR = 0; |
1217 public static final int MAPGEN_MAZE = 1; |
1217 public static final int MAPGEN_MAZE = 1; |
1218 public static final int MAPGEN_DRAWN = 2; |
1218 public static final int MAPGEN_DRAWN = 2; |
1219 public static final int MAPGEN_NAMED = 3; |
1219 public static final int MAPGEN_NAMED = 3; |
1220 |
1220 |
1221 public static final int TEMPLATEFILTER_ALL = 0; |
1221 public static final int TEMPLATEFILTER_ALL = 0; |
1222 public static final int TEMPLATEFILTER_SMALL = 1; |
1222 public static final int TEMPLATEFILTER_SMALL = 1; |
1223 public static final int TEMPLATEFILTER_MEDIUM = 2; |
1223 public static final int TEMPLATEFILTER_MEDIUM = 2; |
1224 public static final int TEMPLATEFILTER_LARGE = 3; |
1224 public static final int TEMPLATEFILTER_LARGE = 3; |
1225 public static final int TEMPLATEFILTER_CAVERN = 4; |
1225 public static final int TEMPLATEFILTER_CAVERN = 4; |
1226 public static final int TEMPLATEFILTER_WACKY = 5; |
1226 public static final int TEMPLATEFILTER_WACKY = 5; |
1227 |
1227 |
1228 public static final int MAZE_SIZE_SMALL_TUNNELS = 0; |
1228 public static final int MAZE_SIZE_SMALL_TUNNELS = 0; |
1229 public static final int MAZE_SIZE_MEDIUM_TUNNELS = 1; |
1229 public static final int MAZE_SIZE_MEDIUM_TUNNELS = 1; |
1230 public static final int MAZE_SIZE_LARGE_TUNNELS = 2; |
1230 public static final int MAZE_SIZE_LARGE_TUNNELS = 2; |
1231 public static final int MAZE_SIZE_SMALL_ISLANDS = 3; |
1231 public static final int MAZE_SIZE_SMALL_ISLANDS = 3; |
1232 public static final int MAZE_SIZE_MEDIUM_ISLANDS = 4; |
1232 public static final int MAZE_SIZE_MEDIUM_ISLANDS = 4; |
1233 public static final int MAZE_SIZE_LARGE_ISLANDS = 5; |
1233 public static final int MAZE_SIZE_LARGE_ISLANDS = 5; |
1234 |
1234 |
1235 // model/schemelist.h |
1235 // model/schemelist.h |
1236 SchemelistPtr flib_schemelist_from_ini(String filename); |
1236 SchemelistPtr flib_schemelist_from_ini(String filename); |
1237 int flib_schemelist_to_ini(String filename, SchemelistPtr list); |
1237 int flib_schemelist_to_ini(String filename, SchemelistPtr list); |
1238 void flib_schemelist_destroy(SchemelistPtr list); |
1238 void flib_schemelist_destroy(SchemelistPtr list); |
1239 |
1239 |
1240 // model/team.h |
1240 // model/team.h |
1241 TeamPtr flib_team_from_ini(String filename); |
1241 TeamPtr flib_team_from_ini(String filename); |
1242 int flib_team_to_ini(String filename, TeamPtr team); |
1242 int flib_team_to_ini(String filename, TeamPtr team); |
1243 void flib_team_destroy(TeamPtr team); |
1243 void flib_team_destroy(TeamPtr team); |
1244 |
1244 |
1245 // model/weapon.h |
1245 // model/weapon.h |
1246 WeaponsetListPtr flib_weaponsetlist_from_ini(String filename); |
1246 WeaponsetListPtr flib_weaponsetlist_from_ini(String filename); |
1247 int flib_weaponsetlist_to_ini(String filename, WeaponsetListPtr weaponsets); |
1247 int flib_weaponsetlist_to_ini(String filename, WeaponsetListPtr weaponsets); |
1248 void flib_weaponsetlist_destroy(WeaponsetListPtr list); |
1248 void flib_weaponsetlist_destroy(WeaponsetListPtr list); |
1249 |
1249 |
1250 // model/gamesetup.h |
1250 // model/gamesetup.h |
1251 void flib_gamesetup_destroy(GameSetupPtr gamesetup); |
1251 void flib_gamesetup_destroy(GameSetupPtr gamesetup); |
1252 |
1252 |
1253 // util/logging.h |
1253 // util/logging.h |
1254 public static final int FLIB_LOGLEVEL_ALL = -100; |
1254 public static final int FLIB_LOGLEVEL_ALL = -100; |
1255 public static final int FLIB_LOGLEVEL_DEBUG = -1; |
1255 public static final int FLIB_LOGLEVEL_DEBUG = -1; |
1256 public static final int FLIB_LOGLEVEL_INFO = 0; |
1256 public static final int FLIB_LOGLEVEL_INFO = 0; |
1257 public static final int FLIB_LOGLEVEL_WARNING = 1; |
1257 public static final int FLIB_LOGLEVEL_WARNING = 1; |
1258 public static final int FLIB_LOGLEVEL_ERROR = 2; |
1258 public static final int FLIB_LOGLEVEL_ERROR = 2; |
1259 public static final int FLIB_LOGLEVEL_NONE = 100; |
1259 public static final int FLIB_LOGLEVEL_NONE = 100; |
1260 |
1260 |
1261 void flib_log_setLevel(int level); |
1261 void flib_log_setLevel(int level); |
1262 void flib_log_setCallback(LogCallback callback); |
1262 void flib_log_setCallback(LogCallback callback); |
1263 } |
1263 } |