updated to use new callback signatures

develop
doomchild 2010-05-27 12:35:40 -05:00
parent 3caac25145
commit 66159d4221
4 changed files with 82 additions and 36 deletions

@ -170,7 +170,9 @@ class Context(object):
return self._tran_obj
def reveal():
df = API("Memory.xml")
df_cm = ContextManager("Memory.xml")
df = df_cm.get_single_context()
df.attach()
m = df.maps
@ -193,3 +195,11 @@ def reveal():
m.finish()
df.detach()
def resume():
df_cm = ContextManager("Memory.xml")
df = df_cm.get_single_context()
df.attach()
df.force_resume()
df.detach()

@ -1,6 +1,6 @@
from ctypes import *
from pydftypes import libdfhack
from util import _uintify
from pydftypes import *
from util import _uintify, uint_ptr
libdfhack.Maps_getSize.argtypes = [ c_void_p, uint_ptr, uint_ptr, uint_ptr ]
libdfhack.Maps_ReadTileTypes.argtypes = [ c_void_p, c_uint, c_uint, c_uint, POINTER(TileTypes40d) ]

@ -87,12 +87,15 @@ class Matgloss(Structure):
("bright", c_byte),
("name", c_char * 128)]
def _alloc_matgloss_buffer_callback(count):
def _alloc_matgloss_buffer_callback(ptr, count):
allocated = _allocate_array(Matgloss, count)
return allocated[1]
ptr = addressof(allocated[0])
libdfhack.alloc_matgloss_buffer_callback = CFUNCTYPE(POINTER(Matgloss), c_int)(_alloc_matgloss_buffer_callback)
return 1
_matgloss_functype = CFUNCTYPE(c_int, POINTER(Matgloss), c_uint)
libdfhack.alloc_matgloss_buffer_callback = _matgloss_functype(_alloc_matgloss_buffer_callback)
class MatglossPair(Structure):
_fields_ = [("type", c_short),
@ -105,12 +108,15 @@ class DescriptorColor(Structure):
("b", c_float),
("name", c_char * 128)]
def _alloc_descriptor_buffer_callback(count):
def _alloc_descriptor_buffer_callback(ptr, count):
allocated = _allocate_array(DescriptorColor, count)
return allocated[1]
ptr = addressof(allocated[0])
return 1
libdfhack.alloc_descriptor_buffer_callback = CFUNCTYPE(POINTER(DescriptorColor), c_int)(_alloc_descriptor_buffer_callback)
_descriptor_functype = CFUNCTYPE(c_int, POINTER(DescriptorColor), c_uint)
libdfhack.alloc_descriptor_buffer_callback = _descriptor_functype(_alloc_descriptor_buffer_callback)
class MatglossOther(Structure):
_fields_ = [("rawname", c_char * 128)]
@ -118,9 +124,12 @@ class MatglossOther(Structure):
def _alloc_matgloss_other_buffer_callback(count):
allocated = _allocate_array(MatglossOther, count)
return allocated[1]
ptr = addressof(allocated[0])
libdfhack.alloc_matgloss_other_buffer_callback = CFUNCTYPE(POINTER(MatglossOther), c_int)(_alloc_matgloss_other_buffer_callback)
return 1
_matgloss_other_functype = CFUNCTYPE(c_int, POINTER(MatglossOther), c_uint)
libdfhack.alloc_matgloss_other_buffer_callback = _matgloss_other_functype(_alloc_matgloss_other_buffer_callback)
class Building(Structure):
_fields_ = [("origin", c_uint),
@ -297,7 +306,10 @@ class ColorModifier(Structure):
ColorModifierPtr = POINTER(ColorModifier)
def _alloc_empty_colormodifier_callback():
return ColorModifierPtr(ColorModifier())
def _alloc_empty_colormodifier_callback(ptr):
ptr = ColorModifierPtr(ColorModifier())
return 1
libdfhack.alloc_empty_colormodifier_callback = CFUNCTYPE(ColorModifierPtr)(_alloc_empty_colormodifier_callback)
_empty_colormodifier_functype = CFUNCTYPE(c_int, ColorModifierPtr)
libdfhack.alloc_empty_colormodifier_callback = _empty_colormodifier_functype(_alloc_empty_colormodifier_callback)

@ -1,5 +1,8 @@
from ctypes import *
uint_ptr = POINTER(c_uint)
int_ptr = POINTER(c_int)
def _uintify(x, y, z):
return (c_uint(x), c_uint(y), c_uint(z))
@ -13,54 +16,75 @@ def _allocate_array(t_type, count):
return (arr, ptr)
def _alloc_int_buffer(count):
def _alloc_int_buffer(ptr, count):
a = _allocate_array(c_int, count)
return a[1]
ptr = addressof(a[0])
return 1
alloc_int_buffer = CFUNCTYPE(POINTER(c_int), c_uint)(_alloc_int_buffer)
_int_functype = CFUNCTYPE(c_int, POINTER(c_int), c_uint)
alloc_int_buffer = _int_functype(_alloc_int_buffer)
def _alloc_uint_buffer(count):
def _alloc_uint_buffer(ptr, count):
a = _allocate_array(c_uint, count)
return a[1]
ptr = addressof(a[0])
return 1
alloc_uint_buffer = CFUNCTYPE(POINTER(c_uint), c_uint)(_alloc_uint_buffer)
_uint_functype = CFUNCTYPE(c_int, POINTER(c_uint), c_uint)
alloc_uint_buffer = _uint_functype(_alloc_uint_buffer)
def _alloc_short_buffer(count):
def _alloc_short_buffer(ptr, count):
a = _allocate_array(c_short, count)
return a[1]
ptr = addressof(a[0])
alloc_short_buffer = CFUNCTYPE(POINTER(c_short), c_uint)(_alloc_short_buffer)
return 1
def _alloc_ushort_buffer(count):
_short_functype = CFUNCTYPE(c_int, POINTER(c_short), c_uint)
alloc_short_buffer = _short_functype(_alloc_short_buffer)
def _alloc_ushort_buffer(ptr, count):
a = _allocate_array(c_ushort, count)
return a[1]
ptr = addressof(a[0])
return 1
alloc_ushort_buffer = CFUNCTYPE(POINTER(c_ushort), c_uint)(_alloc_ushort_buffer)
_ushort_functype = CFUNCTYPE(c_int, POINTER(c_ushort), c_uint)
alloc_ushort_buffer = _ushort_functype(_alloc_ushort_buffer)
def _alloc_byte_buffer(count):
def _alloc_byte_buffer(ptr, count):
a = _allocate_array(c_byte, count)
return a[1]
ptr = addressof(a[0])
alloc_byte_buffer = CFUNCTYPE(POINTER(c_byte), c_uint)(_alloc_byte_buffer)
return 1
def _alloc_ubyte_buffer(count):
_byte_functype = CFUNCTYPE(c_int, POINTER(c_byte), c_uint)
alloc_byte_buffer = _byte_functype(_alloc_byte_buffer)
def _alloc_ubyte_buffer(ptr, count):
a = _allocate_array(c_ubyte, count)
return a[1]
ptr = addressof(a[0])
return 1
alloc_ubyte_buffer = CFUNCTYPE(POINTER(c_ubyte), c_uint)(_alloc_ubyte_buffer)
_ubyte_functype = CFUNCTYPE(c_int, POINTER(c_ubyte), c_uint)
alloc_ubyte_buffer = _ubyte_functype(_alloc_ubyte_buffer)
def _alloc_char_buffer(count):
def _alloc_char_buffer(ptr, count):
c = create_string_buffer(count)
ptr = c_void_p()
if ptr is None:
ptr = c_void_p
ptr = addressof(c)
return ptr
return 1
alloc_char_buffer = CFUNCTYPE(POINTER(c_char), c_uint)(_alloc_char_buffer)
_char_functype = CFUNCTYPE(c_int, POINTER(c_char), c_uint)
alloc_char_buffer = _char_functype(_alloc_char_buffer)