Original date:2021-03-23 17:16:52 Edited by: Icy_Viking Subject: Re: TileEngine Wrapper Issue

ghaberek said...
Icy_Viking said...

I was currently writing a wrapper of TileEngine for Euphoria. Everything was going smoothly until I noticed I'd need to make a shim for it due to the way its functions are handled. Some work without shims, but its the structs.

Mmm nope. Not in this case at least. According to the Tilengine.h include file, TLN_Tilemap is an opaque reference:

typedef struct Tilemap*		 TLN_Tilemap;			/*!< Opaque tilemap reference */ 

An "opaque" pointer or reference is just that: you can't see "through" it to the object on the other side (like an opaque wall versus a transparent window). The function expects to return a pointer to you and that's it. So in this case what you've already done is quite sufficient. No muss no fuss.

One tip I can offer when wrapping a libray is to start with the user-facing include files for a library (what you might call its "interface") before digging into back-end source code. If something isn't meant to be exposed to the programmer using the library then it's unlikely to be found in the include files and probably doesn't need to be wrapped.

Icy_Viking said...

Maybe I should just switch to Phix since has simple struct support. -slight sarcarsm

Har har. I've been working on the struct branch as best I can. I've had to re-familiarize myself with the Euphoria internals and then start work on finishing up the bits to make it complete. I'm making progress.


Ah I see. Well that makes more sense. Also, I wasn't trying to jab at you, I was just saying. I'm surprised Robert Craig didn't think of adding in some sorta struct type when he adding the ability to wrap DLLs in Euphoria. I know there is a simple way to wrap structs or use them through peek and poke, etc, but its still pretty primitive compared to other programming languages. Anyways I've almost got an example going except nothing shows up on the window.

public constant xTLN_Init = define_c_func(tile,"+TLN_Init",{C_INT,C_INT,C_INT,C_INT,C_INT},C_POINTER) 
public function TLN_Init(integer hres,integer vres,integer numlayers,integer numsprites,integer numanimations) 
 return c_func(xTLN_Init,{hres,vres,numlayers,numsprites,numanimations}) 
end function 
public constant xTLN_CreateWindow = define_c_func(tile,"+TLN_CreateWindow",{C_POINTER,C_INT},C_BOOL) 
public function TLN_CreateWindow(sequence overlay,integer flags) 
 atom str = allocate_string(overlay,1) 
 return c_func(xTLN_CreateWindow,{str,flags}) 
end function 
public constant xTLN_LoadWorld = define_c_func(tile,"+TLN_LoadWorld",{C_POINTER,C_INT},C_BOOL), 
xTLN_SetWorldPosition = define_c_proc(tile,"+TLN_SetWorldPosition",{C_INT,C_INT}) 
public function TLN_LoadWorld(sequence tmxfile,integer first_layer) 
 atom str = allocate_string(tmxfile,1) 
 return c_func(xTLN_LoadWorld,{str,first_layer}) 
end function 
public procedure TLN_SetWorldPosition(integer x,integer y) 
end procedure 
--EuTile Engine Basic Example 
without warning 
include std/dll.e 
include EuTileEngine.ew 
TLN_Init(400,240,8,80,0) --width,height,layers,sprites,animations 
TLN_CreateWindow("",0) --NOTE: Adding NULL caused it to crash 
TLN_SetWindowTitle("EuTile Engine Example") 
atom m 
m = TLN_LoadWorld("map.tmx",0) --this shows nothing 
if m = -1 then 
	puts(1,"Cannot load map!\n") 
end if 
atom x = 0 
while (TLN_ProcessWindow()) do 
	x += 2 
end while 

The above example almost works, except the map doesn't show, its just a blank window.

Not Categorized, Please Help


Quick Links

User menu

Not signed in.

Misc Menu