Add lime.system.CFFIPointer
This commit is contained in:
@@ -1,6 +1,8 @@
|
|||||||
package lime.audio.openal;
|
package lime.audio.openal;
|
||||||
|
|
||||||
|
|
||||||
|
import lime.system.CFFIPointer;
|
||||||
|
|
||||||
#if !macro
|
#if !macro
|
||||||
@:build(lime.system.CFFI.build())
|
@:build(lime.system.CFFI.build())
|
||||||
#end
|
#end
|
||||||
@@ -199,18 +201,18 @@ class ALC {
|
|||||||
|
|
||||||
|
|
||||||
#if ((cpp || neko || nodejs) && lime_openal && !macro)
|
#if ((cpp || neko || nodejs) && lime_openal && !macro)
|
||||||
@:cffi private static function lime_alc_close_device (device:Dynamic):Bool;
|
@:cffi private static function lime_alc_close_device (device:CFFIPointer):Bool;
|
||||||
@:cffi private static function lime_alc_create_context (device:Dynamic, attrlist:Dynamic):Dynamic;
|
@:cffi private static function lime_alc_create_context (device:CFFIPointer, attrlist:Dynamic):CFFIPointer;
|
||||||
@:cffi private static function lime_alc_destroy_context (context:Dynamic):Void;
|
@:cffi private static function lime_alc_destroy_context (context:CFFIPointer):Void;
|
||||||
@:cffi private static function lime_alc_get_contexts_device (context:Dynamic):Dynamic;
|
@:cffi private static function lime_alc_get_contexts_device (context:CFFIPointer):CFFIPointer;
|
||||||
@:cffi private static function lime_alc_get_current_context ():Dynamic;
|
@:cffi private static function lime_alc_get_current_context ():CFFIPointer;
|
||||||
@:cffi private static function lime_alc_get_error (device:Dynamic):Int;
|
@:cffi private static function lime_alc_get_error (device:CFFIPointer):Int;
|
||||||
@:cffi private static function lime_alc_get_integerv (device:Dynamic, param:Int, size:Int):Dynamic;
|
@:cffi private static function lime_alc_get_integerv (device:CFFIPointer, param:Int, size:Int):Dynamic;
|
||||||
@:cffi private static function lime_alc_get_string (device:Dynamic, param:Int):Dynamic;
|
@:cffi private static function lime_alc_get_string (device:CFFIPointer, param:Int):Dynamic;
|
||||||
@:cffi private static function lime_alc_make_context_current (context:Dynamic):Bool;
|
@:cffi private static function lime_alc_make_context_current (context:CFFIPointer):Bool;
|
||||||
@:cffi private static function lime_alc_open_device (devicename:String):Dynamic;
|
@:cffi private static function lime_alc_open_device (devicename:String):CFFIPointer;
|
||||||
@:cffi private static function lime_alc_process_context (context:Dynamic):Void;
|
@:cffi private static function lime_alc_process_context (context:CFFIPointer):Void;
|
||||||
@:cffi private static function lime_alc_suspend_context (context:Dynamic):Void;
|
@:cffi private static function lime_alc_suspend_context (context:CFFIPointer):Void;
|
||||||
#end
|
#end
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,14 +1,16 @@
|
|||||||
package lime.audio.openal;
|
package lime.audio.openal;
|
||||||
|
|
||||||
|
|
||||||
|
import lime.system.CFFIPointer;
|
||||||
|
|
||||||
@:allow(lime.audio.openal.AL)
|
@:allow(lime.audio.openal.AL)
|
||||||
@:allow(lime.audio.openal.ALC)
|
@:allow(lime.audio.openal.ALC)
|
||||||
|
|
||||||
|
|
||||||
abstract ALContext(Dynamic) {
|
abstract ALContext(CFFIPointer) from CFFIPointer to CFFIPointer {
|
||||||
|
|
||||||
|
|
||||||
private function new (handle:Dynamic) {
|
private function new (handle:CFFIPointer) {
|
||||||
|
|
||||||
this = handle;
|
this = handle;
|
||||||
|
|
||||||
|
|||||||
@@ -1,14 +1,16 @@
|
|||||||
package lime.audio.openal;
|
package lime.audio.openal;
|
||||||
|
|
||||||
|
|
||||||
|
import lime.system.CFFIPointer;
|
||||||
|
|
||||||
@:allow(lime.audio.openal.AL)
|
@:allow(lime.audio.openal.AL)
|
||||||
@:allow(lime.audio.openal.ALC)
|
@:allow(lime.audio.openal.ALC)
|
||||||
|
|
||||||
|
|
||||||
abstract ALDevice(Dynamic) {
|
abstract ALDevice(CFFIPointer) from CFFIPointer to CFFIPointer {
|
||||||
|
|
||||||
|
|
||||||
private function new (handle:Dynamic) {
|
private function new (handle:CFFIPointer) {
|
||||||
|
|
||||||
this = handle;
|
this = handle;
|
||||||
|
|
||||||
|
|||||||
55
lime/system/CFFIPointer.hx
Normal file
55
lime/system/CFFIPointer.hx
Normal file
@@ -0,0 +1,55 @@
|
|||||||
|
package lime.system;
|
||||||
|
|
||||||
|
|
||||||
|
abstract CFFIPointer(Dynamic) {
|
||||||
|
|
||||||
|
|
||||||
|
public function new (handle:Dynamic) {
|
||||||
|
|
||||||
|
this = handle;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function get ():Float {
|
||||||
|
|
||||||
|
if (this != null) {
|
||||||
|
|
||||||
|
#if ((cpp || neko || nodejs) && !macro)
|
||||||
|
return lime_cffi_get_native_pointer (this);
|
||||||
|
#end
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@:noCompletion @:op(A == B) private static inline function equals (a:CFFIPointer, b:Int):Bool { return a.get () == b; }
|
||||||
|
@:noCompletion @:op(A == B) private static inline function equalsPointer (a:CFFIPointer, b:CFFIPointer):Bool { return a.get () == b.get (); }
|
||||||
|
@:noCompletion @:op(A > B) private static inline function greaterThan (a:CFFIPointer, b:Int):Bool { return a.get () > b; }
|
||||||
|
@:noCompletion @:op(A > B) private static inline function greaterThanPointer (a:CFFIPointer, b:CFFIPointer):Bool { return a.get () > b.get (); }
|
||||||
|
@:noCompletion @:op(A >= B) private static inline function greaterThanOrEqual (a:CFFIPointer, b:Int):Bool { return a.get () >= b; }
|
||||||
|
@:noCompletion @:op(A >= B) private static inline function greaterThanOrEqualPointer (a:CFFIPointer, b:CFFIPointer):Bool { return a.get () >= b.get (); }
|
||||||
|
@:noCompletion @:op(A < B) private static inline function lessThan (a:CFFIPointer, b:Int):Bool { return a.get () < b; }
|
||||||
|
@:noCompletion @:op(A < B) private static inline function lessThanPointer (a:CFFIPointer, b:CFFIPointer):Bool { return a.get () < b.get (); }
|
||||||
|
@:noCompletion @:op(A <= B) private static inline function lessThanOrEqual (a:CFFIPointer, b:Int):Bool { return a.get () <= b; }
|
||||||
|
@:noCompletion @:op(A <= B) private static inline function lessThanOrEqualPointer (a:CFFIPointer, b:CFFIPointer):Bool { return a.get () <= b.get (); }
|
||||||
|
@:noCompletion @:op(A != B) private static inline function notEquals (a:CFFIPointer, b:Int):Bool { return a.get () != b; }
|
||||||
|
@:noCompletion @:op(A != B) private static inline function notEqualsPointer (a:CFFIPointer, b:CFFIPointer):Bool { return a.get () != b.get (); }
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// Native Methods
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#if ((cpp || neko || nodejs) && !macro)
|
||||||
|
private static var lime_cffi_get_native_pointer = CFFI.load ("lime", "lime_cffi_get_native_pointer", 1);
|
||||||
|
#end
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@@ -215,6 +215,7 @@
|
|||||||
<file name="src/math/Matrix3.cpp" />
|
<file name="src/math/Matrix3.cpp" />
|
||||||
<file name="src/math/Rectangle.cpp" />
|
<file name="src/math/Rectangle.cpp" />
|
||||||
<file name="src/math/Vector2.cpp" />
|
<file name="src/math/Vector2.cpp" />
|
||||||
|
<file name="src/system/CFFIPointer.cpp" />
|
||||||
<file name="src/system/JNI.cpp" if="android" />
|
<file name="src/system/JNI.cpp" if="android" />
|
||||||
<file name="src/system/SensorEvent.cpp" />
|
<file name="src/system/SensorEvent.cpp" />
|
||||||
<file name="src/ui/GamepadEvent.cpp" />
|
<file name="src/ui/GamepadEvent.cpp" />
|
||||||
|
|||||||
25
project/include/system/CFFIPointer.h
Normal file
25
project/include/system/CFFIPointer.h
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
#ifndef LIME_SYSTEM_CFFI_POINTER_H
|
||||||
|
#define LIME_SYSTEM_CFFI_POINTER_H
|
||||||
|
|
||||||
|
|
||||||
|
#include <hx/CFFIPrime.h>
|
||||||
|
|
||||||
|
|
||||||
|
namespace hx {
|
||||||
|
|
||||||
|
class Object;
|
||||||
|
typedef void (*finalizer)(value v);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
namespace lime {
|
||||||
|
|
||||||
|
|
||||||
|
value CFFIPointer (void* ptr, hx::finalizer finalizer = 0);
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -20,6 +20,7 @@
|
|||||||
#include <graphics/ImageBuffer.h>
|
#include <graphics/ImageBuffer.h>
|
||||||
#include <graphics/Renderer.h>
|
#include <graphics/Renderer.h>
|
||||||
#include <graphics/RenderEvent.h>
|
#include <graphics/RenderEvent.h>
|
||||||
|
#include <system/CFFIPointer.h>
|
||||||
#include <system/Clipboard.h>
|
#include <system/Clipboard.h>
|
||||||
#include <system/JNI.h>
|
#include <system/JNI.h>
|
||||||
#include <system/SensorEvent.h>
|
#include <system/SensorEvent.h>
|
||||||
@@ -94,9 +95,7 @@ namespace lime {
|
|||||||
|
|
||||||
Application* application = CreateApplication ();
|
Application* application = CreateApplication ();
|
||||||
Application::callback = new AutoGCRoot (callback);
|
Application::callback = new AutoGCRoot (callback);
|
||||||
value handle = cffi::alloc_pointer (application);
|
return CFFIPointer (application, gc_application);
|
||||||
val_gc (handle, gc_application);
|
|
||||||
return handle;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -216,6 +215,13 @@ namespace lime {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
double lime_cffi_get_native_pointer (value handle) {
|
||||||
|
|
||||||
|
return (intptr_t)val_data (handle);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void lime_cffi_finalizer (value abstract) {
|
void lime_cffi_finalizer (value abstract) {
|
||||||
|
|
||||||
val_call0 ((value)val_data (abstract));
|
val_call0 ((value)val_data (abstract));
|
||||||
@@ -457,9 +463,7 @@ namespace lime {
|
|||||||
|
|
||||||
if (font->face) {
|
if (font->face) {
|
||||||
|
|
||||||
value handle = cffi::alloc_pointer (font);
|
return CFFIPointer (font, gc_font);
|
||||||
val_gc (handle, gc_font);
|
|
||||||
return handle;
|
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
@@ -966,9 +970,7 @@ namespace lime {
|
|||||||
value lime_renderer_create (value window) {
|
value lime_renderer_create (value window) {
|
||||||
|
|
||||||
Renderer* renderer = CreateRenderer ((Window*)val_data (window));
|
Renderer* renderer = CreateRenderer ((Window*)val_data (window));
|
||||||
value handle = cffi::alloc_pointer (renderer);
|
return CFFIPointer (renderer, gc_renderer);
|
||||||
val_gc (handle, gc_renderer);
|
|
||||||
return handle;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1068,9 +1070,7 @@ namespace lime {
|
|||||||
#if defined(LIME_FREETYPE) && defined(LIME_HARFBUZZ)
|
#if defined(LIME_FREETYPE) && defined(LIME_HARFBUZZ)
|
||||||
|
|
||||||
TextLayout *text = new TextLayout (direction, script.__s, language.__s);
|
TextLayout *text = new TextLayout (direction, script.__s, language.__s);
|
||||||
value handle = cffi::alloc_pointer (text);
|
return CFFIPointer (text, gc_text_layout);
|
||||||
val_gc (handle, gc_text_layout);
|
|
||||||
return handle;
|
|
||||||
|
|
||||||
#else
|
#else
|
||||||
|
|
||||||
@@ -1155,9 +1155,7 @@ namespace lime {
|
|||||||
value lime_window_create (value application, int width, int height, int flags, HxString title) {
|
value lime_window_create (value application, int width, int height, int flags, HxString title) {
|
||||||
|
|
||||||
Window* window = CreateWindow ((Application*)val_data (application), width, height, flags, title.__s);
|
Window* window = CreateWindow ((Application*)val_data (application), width, height, flags, title.__s);
|
||||||
value handle = cffi::alloc_pointer (window);
|
return CFFIPointer (window, gc_window);
|
||||||
val_gc (handle, gc_window);
|
|
||||||
return handle;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1295,6 +1293,7 @@ namespace lime {
|
|||||||
DEFINE_PRIME2 (lime_bytes_from_data_pointer);
|
DEFINE_PRIME2 (lime_bytes_from_data_pointer);
|
||||||
DEFINE_PRIME1 (lime_bytes_get_data_pointer);
|
DEFINE_PRIME1 (lime_bytes_get_data_pointer);
|
||||||
DEFINE_PRIME1 (lime_bytes_read_file);
|
DEFINE_PRIME1 (lime_bytes_read_file);
|
||||||
|
DEFINE_PRIME1 (lime_cffi_get_native_pointer);
|
||||||
DEFINE_PRIME1 (lime_cffi_set_finalizer);
|
DEFINE_PRIME1 (lime_cffi_set_finalizer);
|
||||||
DEFINE_PRIME0 (lime_clipboard_get_text);
|
DEFINE_PRIME0 (lime_clipboard_get_text);
|
||||||
DEFINE_PRIME1v (lime_clipboard_set_text);
|
DEFINE_PRIME1v (lime_clipboard_set_text);
|
||||||
|
|||||||
@@ -7,6 +7,7 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <hx/CFFIPrime.h>
|
#include <hx/CFFIPrime.h>
|
||||||
|
#include <system/CFFIPointer.h>
|
||||||
#include <utils/Bytes.h>
|
#include <utils/Bytes.h>
|
||||||
|
|
||||||
|
|
||||||
@@ -890,16 +891,7 @@ namespace lime {
|
|||||||
int* list = val_array_int (attrlist);
|
int* list = val_array_int (attrlist);
|
||||||
|
|
||||||
ALCcontext* alcContext = alcCreateContext (alcDevice, list);
|
ALCcontext* alcContext = alcCreateContext (alcDevice, list);
|
||||||
|
return CFFIPointer (alcContext);
|
||||||
if (alcContext) {
|
|
||||||
|
|
||||||
return cffi::alloc_pointer (alcContext);
|
|
||||||
|
|
||||||
} else {
|
|
||||||
|
|
||||||
return alloc_null ();
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -916,16 +908,7 @@ namespace lime {
|
|||||||
|
|
||||||
ALCcontext* alcContext = (ALCcontext*)val_data (context);
|
ALCcontext* alcContext = (ALCcontext*)val_data (context);
|
||||||
ALCdevice* alcDevice = alcGetContextsDevice (alcContext);
|
ALCdevice* alcDevice = alcGetContextsDevice (alcContext);
|
||||||
|
return CFFIPointer (alcDevice);
|
||||||
if (alcDevice) {
|
|
||||||
|
|
||||||
return cffi::alloc_pointer (alcDevice);
|
|
||||||
|
|
||||||
} else {
|
|
||||||
|
|
||||||
return alloc_null ();
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -933,16 +916,7 @@ namespace lime {
|
|||||||
value lime_alc_get_current_context () {
|
value lime_alc_get_current_context () {
|
||||||
|
|
||||||
ALCcontext* alcContext = alcGetCurrentContext ();
|
ALCcontext* alcContext = alcGetCurrentContext ();
|
||||||
|
return CFFIPointer (alcContext);
|
||||||
if (alcContext) {
|
|
||||||
|
|
||||||
return cffi::alloc_pointer (alcContext);
|
|
||||||
|
|
||||||
} else {
|
|
||||||
|
|
||||||
return alloc_null ();
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -997,16 +971,7 @@ namespace lime {
|
|||||||
|
|
||||||
ALCdevice* alcDevice = alcOpenDevice (devicename.__s);
|
ALCdevice* alcDevice = alcOpenDevice (devicename.__s);
|
||||||
atexit (lime_al_cleanup);
|
atexit (lime_al_cleanup);
|
||||||
|
return CFFIPointer (alcDevice);
|
||||||
if (alcDevice) {
|
|
||||||
|
|
||||||
return cffi::alloc_pointer (alcDevice);
|
|
||||||
|
|
||||||
} else {
|
|
||||||
|
|
||||||
return alloc_null ();
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
30
project/src/system/CFFIPointer.cpp
Normal file
30
project/src/system/CFFIPointer.cpp
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
#include <system/CFFIPointer.h>
|
||||||
|
|
||||||
|
|
||||||
|
namespace lime {
|
||||||
|
|
||||||
|
|
||||||
|
value CFFIPointer (void* ptr, hx::finalizer finalizer) {
|
||||||
|
|
||||||
|
if (ptr) {
|
||||||
|
|
||||||
|
value handle = cffi::alloc_pointer (ptr);
|
||||||
|
|
||||||
|
if (finalizer) {
|
||||||
|
|
||||||
|
val_gc (handle, finalizer);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return handle;
|
||||||
|
|
||||||
|
} else {
|
||||||
|
|
||||||
|
return alloc_null ();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user