1. Wrapper Help Again

Hello,

I am having some trouble wrapping the key codes for my Irrlicht wrapper.

C Code in Header File

CIRR_DEFINE(irr_EKEY_CODE,irr::EKEY_CODE*); 
 
#ifndef CIRR_KEY_CODE 
  #define CIRR_KEY_CODE(x) CIRR_API irr_EKEY_CODE irr_EKEY_CODE_KEY_ ## x (); 
#endif 
 
 
 
CIRR_KEY_CODE(LBUTTON) 
CIRR_KEY_CODE(RBUTTON) 
CIRR_KEY_CODE(CANCEL) 
CIRR_KEY_CODE(MBUTTON) 
CIRR_KEY_CODE(XBUTTON1) 
 
CIRR_API IRR_BOOL irrEKeyCodeEqual(irr_EKEY_CODE, irr_EKEY_CODE); 
 
#undef CIRR_CIRR_KEY_CODE 

C Code example

while(irrIrrlichtDevicePopEvent(evt)) 
  { 
    if(irrSEventIsKeyboardInputEvent(evt)) 
    { 
      irrSKeyInput keyInput = irrSEventGetKeyInput(evt); 
      irr_EKEY_CODE keyCode = irrSKeyInputGetKey(keyInput); 
       
      if(irrEKeyCodeEqual(keyCode,irr_EKEY_CODE_KEY_KEY_V()) && irrSKeyInputIsPressed(keyInput)==false) 
      { 
        irrISceneNodeSetVisible(sphere,!irrISceneNodeIsVisible(sphere)); 
        printf("irrISCeneNodeSetVisible\n"); 
      } 

Eu Wrapper Code

public constant xirrSEventGetKeyInput = define_c_func(irr,"irrSEventGetKeyInput",{C_POINTER},C_POINTER) 
 
public function irrSEventGetKeyInput(atom evt) 
 
 return c_func(xirrSEventGetKeyInput,{evt}) 
	 
end function 
 
public constant xirrSKeyInputGetKey = define_c_func(irr,"irrSKeyInputGetKey",{C_POINTER},C_POINTER) 
 
public function irrSKeyInputGetKey(atom evt) 
 
 return c_func(xirrSKeyInputGetKey,{evt}) 
	 
end function 
 
public constant xirrSKeyInputIsPressed = define_c_func(irr,"irrSKeyInputIsPressed",{C_POINTER},C_BOOL) 
 
public function irrSKeyInputIsPressed(atom evt) 
 
 return c_func(xirrSKeyInputIsPressed,{evt}) 
	 
end function 
 
public constant xirrSGUIEventGetCaller = define_c_func(irr,"irrSGUIEventGetCaller",{C_POINTER},C_POINTER) 
 
public function irrSGUIEventGetCaller(atom evt) 
 
 return c_func(xirrSGUIEventGetCaller,{evt}) 
	 
end function 
 
public constant xirrSGUIEventGetElement = define_c_func(irr,"irrSGUIEventGetElement",{C_POINTER},C_POINTER) 
 
public function irrSGUIEventGetElement(atom evt) 
 
 return c_func(xirrSGUIEventGetElement,{evt}) 
	 
end function 
 
public constant xirrSGUIEventGetEventType = define_c_func(irr,"irrSGUIEventGetEventType",{C_POINTER},C_POINTER) 
 
public function irrSGUIEventGetEventType(atom evt) 
 
 return c_func(xirrSGUIEventGetEventType,{evt}) 
	 
end function 
 
public constant xirrSGUIEventIsEventType = define_c_func(irr,"irrSGUIEventIsEventType",{C_POINTER,C_POINTER},C_BOOL) 
 
public function irrSGUIEventIsEventType(atom evt,atom xtype) 
 
 return c_func(xirrSGUIEventIsEventType,{evt,xtype}) 
	 
end function 
 
--Irr Key Code 
 
public constant xirrEKeyCodeEqual = define_c_func(irr,"irrEKeyCodeEqual",{C_POINTER,C_POINTER},C_BOOL) 
 
public function irrEKeyCodeEqual(atom code,atom code2) 
 
 return c_func(xirrEKeyCodeEqual,{code,code2}) 
	 
end function 

Eu Example

	evt = irrSEventNew() 
	 
	while irrIrrlichtDevicePopEvent(evt) do 
		if irrSEventIsKeyboardInputEvent(evt) then 
			atom keyIn = irrSEventGetKeyInput(evt) 
			atom keyCode = irrSKeyInputGetKey(keyIn) 
		end if	 
	end while 

I'm not sure how I'd wrap the EKEY Codes in Irrlicht. The codes are exported in the DLL as irr_EKEY_CODE_KEY_ESCAPE and so on. I'd assume you'd have to wrap them as any other function, but I'm not entirely sure as how to go about it. Most other libraries have their keycodes as ENUMS, but not Irrlicht. Any help is appericated.

new topic     » topic index » view message » categorize

2. Re: Wrapper Help Again

Icy_Viking said...

Hello,

I am having some trouble wrapping the key codes for my Irrlicht wrapper.

C Code in Header File

I copied and pasted this part into a temp file, and used gcc -E on it (to only run the C preprocessor.

#ifndef CIRR_KEY_CODE 
  #define CIRR_KEY_CODE(x) CIRR_API irr_EKEY_CODE irr_EKEY_CODE_KEY_ ## x (); 
#endif 
 
 
 
CIRR_KEY_CODE(LBUTTON) 
CIRR_KEY_CODE(RBUTTON) 
CIRR_KEY_CODE(CANCEL) 
CIRR_KEY_CODE(MBUTTON) 
CIRR_KEY_CODE(XBUTTON1) 

It produced the following output:

CIRR_API irr_EKEY_CODE irr_EKEY_CODE_KEY_LBUTTON (); 
CIRR_API irr_EKEY_CODE irr_EKEY_CODE_KEY_RBUTTON (); 
CIRR_API irr_EKEY_CODE irr_EKEY_CODE_KEY_CANCEL (); 
CIRR_API irr_EKEY_CODE irr_EKEY_CODE_KEY_MBUTTON (); 
CIRR_API irr_EKEY_CODE irr_EKEY_CODE_KEY_XBUTTON1 (); 

So you'd have to wrap those. Each one looks like a separate function, so it looks like it is one function per C code to wrap. (ugh.)

Based on what you have here (and assuming it is 100% correct):

--Irr Key Code 
 
public constant xirrEKeyCodeEqual = define_c_func(irr,"irrEKeyCodeEqual",{C_POINTER,C_POINTER},C_BOOL) 
 
public function irrEKeyCodeEqual(atom code,atom code2) 
 
 return c_func(xirrEKeyCodeEqual,{code,code2}) 
	 
end function 

I reckon that one way to do the wrap would be like this:

public constant xirrEKeyCodeKeyCancel = define_c_func(irr,"irr_EKEY_CODE_KEY_CANCEL",{},C_POINTER) 
 
public function irrEKeyCodeKeyCancel() 
 
 return c_func(xirrEKeyCodeKeyCancel,{}) 
	 
end function 

There are ways you can significantly improve on this, mind you, but it's a start.

new topic     » goto parent     » topic index » view message » categorize

3. Re: Wrapper Help Again

I'd figure I'd have to wrap them like that. I had to wrap some event commands like that. It's a pain, but at least its fairly easy to wrap.

EDIT: Ok so I wrapped it like this.

Wrapper

 
public constant xirrEKeyCodeKeyEscape = define_c_func(irr,"irr_EKEY_CODE_KEY_ESCAPE",{},C_POINTER) 
 
public function irrEKeyCodeKeyEscape() 
 
 return c_func(xirrEKeyCodeKeyEscape,{}) 
	 
end function 

Example

atom evt 
	 
	evt = irrSEventNew() 
	 
	while irrSEventIsKeyboardInputEvent(evt) do 
		if irrSEventIsKeyboardInputEvent(evt) then 
			atom keyInput = irrSEventGetKeyInput(evt) 
			atom keyCode = irrSKeyInputGetKey(keyInput) 
			 
			if irrEKeyCodeKeyEscape() then 
				irrIrrlichtDeviceClose() 
			end if 
		end if 
	end while 

When I try to run the example, the window closes right away. Maybe I have certain vars messed up?

This freezes the program when I try to run it.

atom evt 
 
evt = irrSEventNew() 
	 
	while irrSEventIsKeyboardInputEvent(evt) do 
		if irrSEventIsKeyboardInputEvent(evt) then 
			atom keyInput = irrSEventGetKeyInput(evt) 
			atom keyCode = irrSKeyInputGetKey(keyInput) 
			 
			if irrSKeyInputIsPressed(keyInput) = irrEKeyCodeKeyEscape() then 
				irrIrrlichtDeviceClose() 
			end if 
		end if 
	end while 

New Test, this is closer to how the C example is, but the Euphoria program still freezes.

include std/machine.e 
include std/get.e 
 
include EuIrr.ew 
 
constant TRUE = 1, FALSE = 0 
 
integer EscapePressed 
 
procedure handleInput() 
 
	atom evt 
 
	evt = irrSEventNew() 
	 
	while irrSEventIsKeyboardInputEvent(evt) do 
		if irrSEventIsKeyboardInputEvent(evt) then 
			atom keyInput = irrSEventGetKeyInput(evt) 
			atom keyCode = irrSKeyInputGetKey(keyInput) 
			 
			if irrEKeyCodeEqual(keyCode,irrEKeyCodeKeyEscape()) then 
				EscapePressed = irrSKeyInputIsPressed(keyInput) 
			end if 
		end if 
	end while 
	 
	if (EscapePressed) then 
		irrIrrlichtDeviceClose() 
	end if 
	 
	irrSEventDelete(evt) 
	 
end procedure 
 
atom dim = irrDimension2duNew(600,600) 
atom backColor = irrSColorNew(255,100,100,100) 
atom driver,smgr,env 
atom fs 
atom cur 
atom timer,last 
 
irrCreateDevice(dim,FALSE,TRUE,TRUE) 
 
smgr = irrIrrlichtDeviceGetSceneManager() 
driver = irrIrrlichtDeviceGetVideoDriver() 
env = irrIrrlichtDeviceGetGUIEnviroment() 
 
timer = irrIrrlichtDeviceGetTimer() 
last = irrITimerGetTime(timer) 
 
while irrIrrlichtDeviceRun() do 
 
	atom now = irrITimerGetTime(timer) 
	deltaTime = now - last / 1000.0 
	last = now 
	 
	irrIVideoDriverBeginScene(driver,TRUE,TRUE,backColor) 
	irrISceneManagerDrawAll(smgr) 
	irrIGUIEnviromentDrawAll(env) 
	 
	irrIVideoDriverEndScene(driver) 
	 
	handleInput() 
	 
end while 
 
irrDimension2duDelete(dim) 
irrSColorDelete(backColor) 
irrIrrlichtDeviceDrop() 
new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu