332 return ptr.deref(size); |
332 return ptr.deref(size); |
333 } |
333 } |
334 } |
334 } |
335 |
335 |
336 public static ByteArrayPtr createJavaOwned(byte[] buffer) { |
336 public static ByteArrayPtr createJavaOwned(byte[] buffer) { |
337 if(buffer == null) { |
337 if(buffer == null || buffer.length == 0) { |
338 return null; |
338 return null; |
339 } |
339 } |
340 // no need for javaOwnedInstance here because PointerType |
340 // no need for javaOwnedInstance here because PointerType |
341 // remembers the memory as its Pointer |
341 // remembers the memory as its Pointer |
342 Pointer ptr = new Memory(buffer.length); |
342 Pointer ptr = new Memory(buffer.length); |
591 mapgen = map.mapgen; |
591 mapgen = map.mapgen; |
592 name = map.name; |
592 name = map.name; |
593 seed = map.seed; |
593 seed = map.seed; |
594 theme = map.theme; |
594 theme = map.theme; |
595 byte[] buf = map.getDrawData(); |
595 byte[] buf = map.getDrawData(); |
596 drawData = ByteArrayPtr.createJavaOwned(buf); |
596 if(buf==null || buf.length==0) { |
|
597 drawData = null; |
|
598 } else { |
|
599 drawData = ByteArrayPtr.createJavaOwned(buf).getPointer(); |
|
600 } |
597 drawDataSize = NativeSizeT.valueOf(buf==null ? 0 : buf.length); |
601 drawDataSize = NativeSizeT.valueOf(buf==null ? 0 : buf.length); |
598 templateFilter = map.templateFilter; |
602 templateFilter = map.templateFilter; |
599 mazeSize = map.mazeSize; |
603 mazeSize = map.mazeSize; |
600 } |
604 } |
601 |
605 |
602 public MapRecipe toMapRecipe() { |
606 public MapRecipe toMapRecipe() { |
603 byte[] buf = ByteArrayPtr.deref(drawData, drawDataSize.intValue()); |
607 byte[] buf; |
|
608 int size = drawDataSize.intValue(); |
|
609 if(size>0) { |
|
610 buf = drawData.getByteArray(0, size); |
|
611 } else { |
|
612 buf = null; |
|
613 } |
604 return new MapRecipe(mapgen, templateFilter, mazeSize, name, seed, theme, buf); |
614 return new MapRecipe(mapgen, templateFilter, mazeSize, name, seed, theme, buf); |
605 } |
615 } |
606 |
616 |
607 public int mapgen; |
617 public int mapgen; |
608 public String name; |
618 public String name; |
609 public String seed; |
619 public String seed; |
610 public String theme; |
620 public String theme; |
611 public ByteArrayPtr drawData; |
621 public Pointer drawData; // We can't use ByteArrayPtr in a struct because JNA will overwrite the value with NULL - probably a bug. |
612 public NativeSizeT drawDataSize; |
622 public NativeSizeT drawDataSize; |
613 public int templateFilter; |
623 public int templateFilter; |
614 public int mazeSize; |
624 public int mazeSize; |
615 } |
625 } |
616 |
626 |