Objc_util wants incorrect number of parameters
For your argtypes, first should be c_void_p, not GKNoise (that is what the error is saying. there are two hidden argtypes that get added, so your first is really the third... i think, i forget if you have to add the secret ones)
next, the signature calls for vectors, not pointers to the vectors. so remove POINTER. then your third arg is wrong... restype also should be c_void_p.
argtypes=[c_void_p, vector_double2, vector_double2, vector_int2, c_bool], restype=c_void_p
you might need to add two c_void_p's at the start --i forget if objc_util does that for you (for the hidden _self and selector arguments to objc_msgSend)
import objc_util from objc_util import * import ctypes objc_util.load_framework("GameplayKit") GKNoise = objc_util.ObjCClass("GKNoise") GKNoiseMap = objc_util.ObjCClass("GKNoiseMap") GKPerlinNoiseSource = objc_util.ObjCClass('GKPerlinNoiseSource') class vector_double2 (ctypes.Structure): _fields_ = [('x', ctypes.c_float), ('y', ctypes.c_float)] class vector_int2 (ctypes.Structure): _fields_ = [('x', ctypes.c_int), ('y', ctypes.c_int)] noiseSource = GKPerlinNoiseSource.alloc().init() noiseSource.frequency = 1 noiseSource.octaveCount = 6 noiseSource.lacunarity = 2 noiseSource.persistence = 0.5 noise = GKNoise.alloc().initWithNoiseSource(noiseSource)#make the noise algorithem size = vector_double2(10.0,10.0) origin = vector_double2(0.0,0.0) sampleCount = vector_int2(10,10) newMap = GKNoiseMap.alloc().initWithNoise_size_origin_sampleCount_seamless_(noise, size, origin, sampleCount, True, argtypes=[c_void_p, vector_double2, vector_double2, vector_int2, c_bool], restype=c_void_p) row =  for x in range(10): col =  for y in range(10): col.append(newMap.interpolatedValueAtPosition_(position=(x/10,y/10))) row.append(col) print(row) print()
the encodings you get from introspection also have bytesize numbers after each character, which you can ignore.
simon_hibbs last edited by
@cvp I tried the code you posted above, but it doesn't work for me. I just get an array in which all the values are -1.0 and can't seem to get anything else out of the noise map.
I am finding using objc_util frustrating. Under what circumstances do I need to use the .alloc() method on an object? To be fair the Apple documentation on these classes is terrible. Putting all the documentation on a class and it's methods and properties on a single page in a consistent format can't be all that hard.
There is a difference between primitive ctypes structures and objc objects. If you are creating an objc object directly from a ObjCClass, with an init method, you need an alloc:
Some classes provide ways of directly giving you an object, or giving you a pointer to a shared object. So
Also, .new() is short for .alloc().init().
So, if you are calling an init method you must use alloc. If not, not.
cvp last edited by cvp
To check if a class needs alloc() or not, I first do
and I see if alloc is in the list or not, then
simon_hibbs last edited by
@cvp Ok, thanks. very helpful.
mikael last edited by
Thank you all, this thread has been so very useful.