diff --git a/lime/_backend/native/NativeApplication.hx b/lime/_backend/native/NativeApplication.hx index b88b704f4..ad0020563 100644 --- a/lime/_backend/native/NativeApplication.hx +++ b/lime/_backend/native/NativeApplication.hx @@ -741,7 +741,7 @@ class NativeApplication { } -/*private*/ class ApplicationEventInfo { +@:keep /*private*/ class ApplicationEventInfo { public var deltaTime:Int; @@ -774,7 +774,7 @@ class NativeApplication { } -/*private*/ class ClipboardEventInfo { +@:keep /*private*/ class ClipboardEventInfo { public var type:ClipboardEventType; @@ -804,7 +804,7 @@ class NativeApplication { } -/*private*/ class DropEventInfo { +@:keep /*private*/ class DropEventInfo { public var file:String; @@ -836,7 +836,7 @@ class NativeApplication { } -/*private*/ class GamepadEventInfo { +@:keep /*private*/ class GamepadEventInfo { public var axis:Int; @@ -878,7 +878,7 @@ class NativeApplication { } -/*private*/ class JoystickEventInfo { +@:keep /*private*/ class JoystickEventInfo { public var id:Int; @@ -924,7 +924,7 @@ class NativeApplication { } -/*private*/ class KeyEventInfo { +@:keep /*private*/ class KeyEventInfo { public var keyCode:Int; @@ -961,7 +961,7 @@ class NativeApplication { } -/*private*/ class MouseEventInfo { +@:keep /*private*/ class MouseEventInfo { public var button:Int; @@ -1007,7 +1007,7 @@ class NativeApplication { } -/*private*/ class RenderEventInfo { +@:keep /*private*/ class RenderEventInfo { public var context:RenderContext; @@ -1041,7 +1041,7 @@ class NativeApplication { } -/*private*/ class SensorEventInfo { +@:keep /*private*/ class SensorEventInfo { public var id:Int; @@ -1079,7 +1079,7 @@ class NativeApplication { } -/*private*/ class TextEventInfo { +@:keep /*private*/ class TextEventInfo { public var id:Int; @@ -1119,7 +1119,7 @@ class NativeApplication { } -/*private*/ class TouchEventInfo { +@:keep /*private*/ class TouchEventInfo { public var device:Int; @@ -1165,7 +1165,7 @@ class NativeApplication { } -/*private*/ class WindowEventInfo { +@:keep /*private*/ class WindowEventInfo { public var height:Int; diff --git a/lime/math/Vector2.hx b/lime/math/Vector2.hx index b2cb7921d..2cd134d13 100644 --- a/lime/math/Vector2.hx +++ b/lime/math/Vector2.hx @@ -5,6 +5,8 @@ package lime.math; import flash.geom.Point; #end +#if hl @:keep #end + #if !lime_debug @:fileXml('tags="haxe,release"') @:noDebug diff --git a/project/include/system/System.h b/project/include/system/System.h index 127f2e581..767f6a33d 100644 --- a/project/include/system/System.h +++ b/project/include/system/System.h @@ -26,6 +26,8 @@ namespace lime { public: + static void GCEnterBlocking (); + static void GCExitBlocking (); static bool GetAllowScreenTimeout (); static std::wstring* GetDeviceModel (); static std::wstring* GetDeviceVendor (); @@ -50,6 +52,10 @@ namespace lime { static bool SetWindowsConsoleMode (int handleType, int mode); #endif + private: + + static bool _isHL; + }; diff --git a/project/include/utils/ArrayBufferView.h b/project/include/utils/ArrayBufferView.h index 9206e5ab8..900ad86b0 100644 --- a/project/include/utils/ArrayBufferView.h +++ b/project/include/utils/ArrayBufferView.h @@ -33,21 +33,22 @@ namespace lime { ArrayBufferView (HL_ArrayBufferView* arrayBufferView); ~ArrayBufferView (); - unsigned char *Data (); - const unsigned char *Data () const; + unsigned char* Data (); + const unsigned char* Data () const; int Length () const; void Resize (int size); void Set (value bytes); void Set (const QuickVec data); value Value (); - Bytes *buffer; + Bytes* buffer; int byteLength; int length; private: - value mValue; + HL_ArrayBufferView* _bufferView; + value _value; }; diff --git a/project/include/utils/Bytes.h b/project/include/utils/Bytes.h index eb49fccd2..b3d63fe4d 100644 --- a/project/include/utils/Bytes.h +++ b/project/include/utils/Bytes.h @@ -29,17 +29,18 @@ namespace lime { Bytes (const QuickVec data); ~Bytes (); - unsigned char *Data (); - const unsigned char *Data () const; + unsigned char* Data (); + const unsigned char* Data () const; int Length () const; void ReadFile (const char* path); void Resize (int size); void Set (value bytes); void Set (HL_Bytes* bytes); void Set (const QuickVec data); - value Value (); + void* Value (); - unsigned char *_data; + HL_Bytes* _bytes; + unsigned char* _data; int _length; value _value; diff --git a/project/src/ExternalInterface.cpp b/project/src/ExternalInterface.cpp index c09737420..409ec4181 100644 --- a/project/src/ExternalInterface.cpp +++ b/project/src/ExternalInterface.cpp @@ -434,7 +434,7 @@ namespace lime { } - return bytes.Value (); + return (value)bytes.Value (); } @@ -466,7 +466,7 @@ namespace lime { Bytes data (bytes); data.ReadFile (path.c_str ()); - return data.Value (); + return (value)data.Value (); } @@ -582,7 +582,7 @@ namespace lime { Zlib::Compress (DEFLATE, &data, &result); - return result.Value (); + return (value)result.Value (); #else return alloc_null(); #endif @@ -615,7 +615,7 @@ namespace lime { Zlib::Decompress (DEFLATE, &data, &result); - return result.Value (); + return (value)result.Value (); #else return alloc_null (); #endif @@ -1620,7 +1620,7 @@ namespace lime { Zlib::Compress (GZIP, &data, &result); - return result.Value (); + return (value)result.Value (); #else return alloc_null (); #endif @@ -1652,7 +1652,7 @@ namespace lime { Zlib::Decompress (GZIP, &data, &result); - return result.Value (); + return (value)result.Value (); #else return alloc_null (); #endif @@ -1706,7 +1706,7 @@ namespace lime { #ifdef LIME_PNG if (PNG::Encode (&imageBuffer, &data)) { - return data.Value (); + return (value)data.Value (); } #endif @@ -1717,7 +1717,7 @@ namespace lime { #ifdef LIME_JPEG if (JPEG::Encode (&imageBuffer, &data, quality)) { - return data.Value (); + return (value)data.Value (); } #endif @@ -2491,7 +2491,7 @@ namespace lime { LZMA::Compress (&data, &result); - return result.Value (); + return (value)result.Value (); #else return alloc_null (); #endif @@ -2523,7 +2523,7 @@ namespace lime { LZMA::Decompress (&data, &result); - return result.Value (); + return (value)result.Value (); #else return alloc_null (); #endif @@ -3403,7 +3403,7 @@ namespace lime { Font *font = (Font*)val_data (fontHandle); Bytes bytes (data); text->Position (font, size, textString.c_str (), &bytes); - return bytes.Value (); + return (value)bytes.Value (); #endif @@ -3949,7 +3949,7 @@ namespace lime { Zlib::Compress (ZLIB, &data, &result); - return result.Value (); + return (value)result.Value (); #else return alloc_null (); #endif @@ -3981,7 +3981,7 @@ namespace lime { Zlib::Decompress (ZLIB, &data, &result); - return result.Value (); + return (value)result.Value (); #else return alloc_null (); #endif @@ -4072,6 +4072,8 @@ namespace lime { DEFINE_PRIME1v (lime_image_data_util_unmultiply_alpha); DEFINE_PRIME4 (lime_image_encode); DEFINE_PRIME2 (lime_image_load); + DEFINE_PRIME2 (lime_image_load_bytes); + DEFINE_PRIME2 (lime_image_load_file); DEFINE_PRIME0 (lime_jni_getenv); DEFINE_PRIME2v (lime_joystick_event_manager_register); DEFINE_PRIME1 (lime_joystick_get_device_guid); diff --git a/project/src/backend/sdl/SDLApplication.cpp b/project/src/backend/sdl/SDLApplication.cpp index 7e7c92d5e..d4e4866c4 100644 --- a/project/src/backend/sdl/SDLApplication.cpp +++ b/project/src/backend/sdl/SDLApplication.cpp @@ -1,6 +1,7 @@ #include "SDLApplication.h" #include "SDLGamepad.h" #include "SDLJoystick.h" +#include #ifdef HX_MACOS #include @@ -917,9 +918,9 @@ namespace lime { #ifdef HX_MACOS - gc_enter_blocking (); + System::GCEnterBlocking (); int result = SDL_WaitEvent (event); - gc_exit_blocking (); + System::GCExitBlocking (); return result; #else @@ -934,17 +935,17 @@ namespace lime { case -1: - if (isBlocking) gc_exit_blocking (); + if (isBlocking) System::GCExitBlocking (); return 0; case 1: - if (isBlocking) gc_exit_blocking (); + if (isBlocking) System::GCExitBlocking (); return 1; default: - if (!isBlocking) gc_enter_blocking (); + if (!isBlocking) System::GCEnterBlocking (); isBlocking = true; SDL_Delay (1); break; diff --git a/project/src/backend/sdl/SDLSystem.cpp b/project/src/backend/sdl/SDLSystem.cpp index 644a116b9..9a1448420 100644 --- a/project/src/backend/sdl/SDLSystem.cpp +++ b/project/src/backend/sdl/SDLSystem.cpp @@ -92,7 +92,7 @@ namespace lime { std::wstring* System::GetDirectory (SystemDirectory type, const char* company, const char* title) { std::wstring* result = 0; - gc_enter_blocking (); + System::GCEnterBlocking (); switch (type) { @@ -270,7 +270,7 @@ namespace lime { } - gc_exit_blocking (); + System::GCExitBlocking (); return result; } @@ -430,10 +430,10 @@ namespace lime { case SDL_RWOPS_JNIFILE: { #ifdef ANDROID - gc_enter_blocking (); + System::GCEnterBlocking (); FILE* file = ::fdopen (((SDL_RWops*)handle)->hidden.androidio.fd, "rb"); ::fseek (file, ((SDL_RWops*)handle)->hidden.androidio.offset, 0); - gc_exit_blocking (); + System::GCExitBlocking (); return file; #endif } @@ -469,9 +469,9 @@ namespace lime { #ifndef HX_WINDOWS - gc_enter_blocking (); + System::GCEnterBlocking (); int size = SDL_RWsize (((SDL_RWops*)handle)); - gc_exit_blocking (); + System::GCExitBlocking (); return size; #else @@ -504,10 +504,10 @@ namespace lime { if (stream) { - gc_enter_blocking (); + System::GCEnterBlocking (); int code = SDL_RWclose ((SDL_RWops*)stream->handle); delete stream; - gc_exit_blocking (); + System::GCExitBlocking (); return code; } @@ -518,10 +518,10 @@ namespace lime { if (stream) { - gc_enter_blocking (); + System::GCEnterBlocking (); int code = ::fclose ((FILE*)stream->handle); delete stream; - gc_exit_blocking (); + System::GCExitBlocking (); return code; } @@ -537,10 +537,10 @@ namespace lime { #ifndef HX_WINDOWS - gc_enter_blocking (); + System::GCEnterBlocking (); FILE* fp = ::fdopen (fd, mode); SDL_RWops *result = SDL_RWFromFP (fp, SDL_TRUE); - gc_exit_blocking (); + System::GCExitBlocking (); if (result) { @@ -554,9 +554,9 @@ namespace lime { FILE* result; - gc_enter_blocking (); + System::GCEnterBlocking (); result = ::fdopen (fd, mode); - gc_exit_blocking (); + System::GCExitBlocking (); if (result) { @@ -577,7 +577,7 @@ namespace lime { SDL_RWops *result; - gc_enter_blocking (); + System::GCEnterBlocking (); #ifdef HX_MACOS @@ -612,7 +612,7 @@ namespace lime { result = SDL_RWFromFile (filename, mode); #endif - gc_exit_blocking (); + System::GCExitBlocking (); if (result) { @@ -626,9 +626,9 @@ namespace lime { FILE* result; - gc_enter_blocking (); + System::GCEnterBlocking (); result = ::fopen (filename, mode); - gc_exit_blocking (); + System::GCExitBlocking (); if (result) { @@ -646,7 +646,7 @@ namespace lime { size_t fread (void *ptr, size_t size, size_t count, FILE_HANDLE *stream) { size_t nmem; - gc_enter_blocking (); + System::GCEnterBlocking (); #ifndef HX_WINDOWS @@ -658,7 +658,7 @@ namespace lime { #endif - gc_exit_blocking (); + System::GCExitBlocking (); return nmem; } @@ -667,7 +667,7 @@ namespace lime { int fseek (FILE_HANDLE *stream, long int offset, int origin) { int success; - gc_enter_blocking (); + System::GCEnterBlocking (); #ifndef HX_WINDOWS @@ -679,7 +679,7 @@ namespace lime { #endif - gc_exit_blocking (); + System::GCExitBlocking (); return success; } @@ -688,7 +688,7 @@ namespace lime { long int ftell (FILE_HANDLE *stream) { long int pos; - gc_enter_blocking (); + System::GCEnterBlocking (); #ifndef HX_WINDOWS @@ -700,7 +700,7 @@ namespace lime { #endif - gc_exit_blocking (); + System::GCExitBlocking (); return pos; } @@ -709,7 +709,7 @@ namespace lime { size_t fwrite (const void *ptr, size_t size, size_t count, FILE_HANDLE *stream) { size_t nmem; - gc_enter_blocking (); + System::GCEnterBlocking (); #ifndef HX_WINDOWS @@ -721,7 +721,7 @@ namespace lime { #endif - gc_exit_blocking (); + System::GCExitBlocking (); return nmem; } diff --git a/project/src/net/curl/CURLBindings.cpp b/project/src/net/curl/CURLBindings.cpp index 6878f6e83..753c8942d 100644 --- a/project/src/net/curl/CURLBindings.cpp +++ b/project/src/net/curl/CURLBindings.cpp @@ -2,6 +2,7 @@ #include #include #include +#include #include #include #include @@ -195,7 +196,7 @@ namespace lime { callback = headerCallbacks[handle]; _writeBytes = new Bytes (1024); writeBytes[callback] = _writeBytes; - writeBytesRoot[callback] = new AutoGCRoot (_writeBytes->Value ()); + writeBytesRoot[callback] = new AutoGCRoot ((value)_writeBytes->Value ()); headerCallbacks[duphandle] = new AutoGCRoot (headerCallbacks[handle]->get()); } @@ -211,7 +212,7 @@ namespace lime { callback = writeCallbacks[handle]; _writeBytes = new Bytes (1024); writeBytes[callback] = _writeBytes; - writeBytesRoot[callback] = new AutoGCRoot (_writeBytes->Value ()); + writeBytesRoot[callback] = new AutoGCRoot ((value)_writeBytes->Value ()); writeCallbacks[duphandle] = new AutoGCRoot (writeCallbacks[handle]->get()); } @@ -388,11 +389,11 @@ namespace lime { int lime_curl_easy_perform (value easy_handle) { int code; - gc_enter_blocking (); + System::GCEnterBlocking (); code = curl_easy_perform ((CURL*)val_data(easy_handle)); - gc_exit_blocking (); + System::GCExitBlocking (); return code; } @@ -441,7 +442,7 @@ namespace lime { _writeBytes->Resize (size * nmemb); memcpy (_writeBytes->Data (), ptr, size * nmemb); - return val_int (val_call3 (callback->get (), _writeBytes->Value (), alloc_int (size), alloc_int (nmemb))); + return val_int (val_call3 (callback->get (), (value)_writeBytes->Value (), alloc_int (size), alloc_int (nmemb))); } else { @@ -1035,12 +1036,12 @@ namespace lime { int lime_curl_multi_wait (value multi_handle, int timeout_ms) { - gc_enter_blocking (); + System::GCEnterBlocking (); int retcode; CURLMcode result = curl_multi_wait ((CURLM*)val_data (multi_handle), 0, 0, timeout_ms, &retcode); - gc_exit_blocking (); + System::GCExitBlocking (); return result; } diff --git a/project/src/system/CFFI.cpp b/project/src/system/CFFI.cpp index 3f9e60f7e..6d7b17b78 100644 --- a/project/src/system/CFFI.cpp +++ b/project/src/system/CFFI.cpp @@ -15,6 +15,8 @@ HL_API hl_type hlt_dynobj = hl_type (); HL_API hl_type hlt_bool = hl_type (); HL_API hl_type hlt_abstract = hl_type (); +HL_API double hl_nan( void ) { return 0; } + HL_API varray *hl_alloc_array( hl_type *t, int size ) { return 0; } HL_API vdynobj *hl_alloc_dynobj( void ) { return 0; } HL_API char *hl_to_utf8( const uchar *bytes ) { return 0; } diff --git a/project/src/system/System.cpp b/project/src/system/System.cpp index cf46af349..655fe3a14 100644 --- a/project/src/system/System.cpp +++ b/project/src/system/System.cpp @@ -13,6 +13,35 @@ namespace lime { + #ifdef LIME_HASHLINK + bool System::_isHL = (hl_nan () != 0); + #else + bool System::_isHL = false; + #endif + + + void System::GCEnterBlocking () { + + if (!_isHL) { + + gc_enter_blocking (); + + } + + } + + + void System::GCExitBlocking () { + + if (!_isHL) { + + gc_exit_blocking (); + + } + + } + + #ifdef HX_WINDOWS std::wstring* GetWMIValue (BSTR query, BSTR field) { diff --git a/project/src/utils/ArrayBufferView.cpp b/project/src/utils/ArrayBufferView.cpp index 0ee57a771..5da063578 100644 --- a/project/src/utils/ArrayBufferView.cpp +++ b/project/src/utils/ArrayBufferView.cpp @@ -8,6 +8,7 @@ namespace lime { static int id_byteLength; static int id_length; static bool init = false; + static bool isHL = false; ArrayBufferView::ArrayBufferView () { @@ -15,7 +16,8 @@ namespace lime { buffer = new Bytes (); byteLength = 0; length = 0; - mValue = 0; + _value = 0; + _bufferView = 0; } @@ -25,7 +27,8 @@ namespace lime { buffer = new Bytes (size); byteLength = size; length = size; - mValue = 0; + _value = 0; + _bufferView = 0; } @@ -55,47 +58,61 @@ namespace lime { } - mValue = arrayBufferView; + _value = arrayBufferView; + _bufferView = 0; } ArrayBufferView::ArrayBufferView (HL_ArrayBufferView* arrayBufferView) { + if (!init) { + + init = true; + isHL = true; + + } + if (arrayBufferView) { buffer = new Bytes (arrayBufferView->buffer); byteLength = arrayBufferView->byteLength; length = arrayBufferView->length; + _bufferView = arrayBufferView; } else { - buffer = new Bytes (); + buffer = 0; byteLength = 0; length = 0; + _bufferView = 0; } - mValue = 0; + _value = 0; } ArrayBufferView::~ArrayBufferView () { - delete buffer; + if (buffer) { + + delete buffer; + + } } - unsigned char *ArrayBufferView::Data () { + unsigned char* ArrayBufferView::Data () { return buffer->Data (); } - const unsigned char *ArrayBufferView::Data () const { + const unsigned char* ArrayBufferView::Data () const { return buffer->Data (); @@ -112,6 +129,14 @@ namespace lime { void ArrayBufferView::Resize (int size) { buffer->Resize (size); + + if (_bufferView) { + + _bufferView->byteLength = size; + _bufferView->length = size; // ? + + } + byteLength = size; length = size; @@ -147,16 +172,16 @@ namespace lime { } - if (val_is_null (mValue)) { + if (val_is_null (_value)) { - mValue = alloc_empty_object (); + _value = alloc_empty_object (); } - alloc_field (mValue, id_buffer, buffer ? buffer->Value () : alloc_null ()); - alloc_field (mValue, id_byteLength, alloc_int (byteLength)); - alloc_field (mValue, id_length, alloc_int (length)); - return mValue; + alloc_field (_value, id_buffer, buffer ? (value)buffer->Value () : alloc_null ()); + alloc_field (_value, id_byteLength, alloc_int (byteLength)); + alloc_field (_value, id_length, alloc_int (length)); + return _value; } diff --git a/project/src/utils/Bytes.cpp b/project/src/utils/Bytes.cpp index 98ce90308..cd76f20c5 100644 --- a/project/src/utils/Bytes.cpp +++ b/project/src/utils/Bytes.cpp @@ -8,6 +8,7 @@ namespace lime { static int id_b; static int id_length; static bool init = false; + static bool isHL = false; static bool useBuffer = false; @@ -72,6 +73,13 @@ namespace lime { Bytes::Bytes (HL_Bytes* bytes) { + if (!init) { + + init = true; + isHL = true; + + } + // _initializeBytes (); _data = 0; @@ -116,14 +124,14 @@ namespace lime { } - unsigned char *Bytes::Data () { + unsigned char* Bytes::Data () { return (unsigned char*)_data; } - const unsigned char *Bytes::Data () const { + const unsigned char* Bytes::Data () const { return (const unsigned char*)_data; @@ -167,52 +175,85 @@ namespace lime { if (size != _length) { - if (!_value) { + if (isHL) { - _value = alloc_empty_object (); - - } - - if (val_is_null (val_field (_value, id_b))) { - - value dataValue; - - if (useBuffer) { + if (size <= 0) { - buffer b = alloc_buffer_len (size); - dataValue = buffer_val (b); - _data = (unsigned char*)buffer_data (b); + if (_bytes->b) { + + free (_bytes->b); + _bytes->b = 0; + _bytes->length = 0; + _data = 0; + + } } else { - dataValue = alloc_raw_string (size); - _data = (unsigned char*)val_string (dataValue); + unsigned char* data = (unsigned char*)malloc (size); + + if (_bytes->b && _bytes->length) { + + memcpy (_bytes->b, data, _bytes->length); + free (_bytes->b); + _bytes->b = data; + _bytes->length = size; + _data = _bytes->b; + + } } - alloc_field (_value, id_b, dataValue); - } else { - if (useBuffer) { + if (!_value) { - buffer b = val_to_buffer (val_field (_value, id_b)); - buffer_set_size (b, size); - _data = (unsigned char*)buffer_data (b); - - } else { - - value s = alloc_raw_string (size); - memcpy ((char *)val_string (s), val_string (val_field (_value, id_b)), _length); - alloc_field (_value, id_b, s); - _data = (unsigned char*)val_string (s); + _value = alloc_empty_object (); } + if (val_is_null (val_field (_value, id_b))) { + + value dataValue; + + if (useBuffer) { + + buffer b = alloc_buffer_len (size); + dataValue = buffer_val (b); + _data = (unsigned char*)buffer_data (b); + + } else { + + dataValue = alloc_raw_string (size); + _data = (unsigned char*)val_string (dataValue); + + } + + alloc_field (_value, id_b, dataValue); + + } else { + + if (useBuffer) { + + buffer b = val_to_buffer (val_field (_value, id_b)); + buffer_set_size (b, size); + _data = (unsigned char*)buffer_data (b); + + } else { + + value s = alloc_raw_string (size); + memcpy ((char *)val_string (s), val_string (val_field (_value, id_b)), _length); + alloc_field (_value, id_b, s); + _data = (unsigned char*)val_string (s); + + } + + } + + alloc_field (_value, id_length, alloc_int (size)); + } - alloc_field (_value, id_length, alloc_int (size)); - } _length = size; @@ -262,12 +303,14 @@ namespace lime { if (!bytes) { + _bytes = 0; _length = 0; _data = 0; _value = 0; } else { + _bytes = bytes; _value = 0; _length = bytes->length; @@ -305,9 +348,13 @@ namespace lime { } - value Bytes::Value () { + void* Bytes::Value () { - if (_value) { + if (isHL) { + + return _bytes; + + } else if (_value) { return _value;