-
Notifications
You must be signed in to change notification settings - Fork 154
Apple libcurl replacement #169
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
88dc44f
88b6563
7e4c480
2ae0ab2
93c0987
c0d461a
b0ebcd2
550ebb6
ea713a9
055afe4
3db5907
3184172
0ede11a
afe482a
edd1d91
0e9fce6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1,2 @@ | ||
| /Build | ||
| /Build | ||
| .DS_Store |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,13 +1,25 @@ | ||
| set(SOURCES | ||
| "Include/Babylon/NetworkUtils.h" | ||
| "Include/Babylon/TicketedCollection.h" | ||
| "Source/NetworkUtils.cpp") | ||
| if(APPLE) | ||
| set(SOURCES | ||
| "Include/Babylon/NetworkUtils.h" | ||
| "Include/Babylon/TicketedCollection.h" | ||
| "Source/NetworkUtils.mm") | ||
| else() | ||
| set(SOURCES | ||
| "Include/Babylon/NetworkUtils.h" | ||
| "Include/Babylon/TicketedCollection.h" | ||
| "Source/NetworkUtils.cpp") | ||
| endif() | ||
|
|
||
| add_library(BabylonNativeUtils ${SOURCES}) | ||
|
|
||
| target_include_directories(BabylonNativeUtils PRIVATE "Include/Babylon") | ||
| target_include_directories(BabylonNativeUtils INTERFACE "Include") | ||
|
|
||
| target_link_libraries(BabylonNativeUtils | ||
| PUBLIC arcana | ||
| PRIVATE libcurl) | ||
| if(APPLE) | ||
| target_link_libraries(BabylonNativeUtils | ||
| PUBLIC arcana) | ||
| else() | ||
| target_link_libraries(BabylonNativeUtils | ||
| PUBLIC arcana | ||
| PRIVATE libcurl) | ||
| endif() | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| #include "NetworkUtils.h" | ||
| #import <Foundation/Foundation.h> | ||
|
|
||
| namespace Babylon | ||
| { | ||
| std::string GetAbsoluteUrl(const std::string& url, const std::string& rootUrl) | ||
| { | ||
| NSString *urlStr = [NSString stringWithCString:url.c_str() encoding:[NSString defaultCStringEncoding]]; | ||
|
bghgary marked this conversation as resolved.
|
||
| NSString *rootUrlStr = [NSString stringWithCString:rootUrl.c_str() encoding:[NSString defaultCStringEncoding]]; | ||
| NSString *completeURL = [NSString stringWithFormat:@"%@/%@",rootUrlStr,urlStr]; | ||
| NSURL *baseUrl = [NSURL URLWithString:completeURL]; | ||
| NSError *error; | ||
| BOOL reachable = [baseUrl checkResourceIsReachableAndReturnError:&error]; | ||
| if (reachable) | ||
| { | ||
| return std::string([completeURL UTF8String]); | ||
| } | ||
| return url; | ||
| } | ||
|
|
||
| template<typename DataT> | ||
| arcana::task<DataT, std::exception_ptr> LoadUrlAsync(std::string url) | ||
| { | ||
| __block arcana::task_completion_source<DataT, std::exception_ptr> taskCompletionSource{}; | ||
| NSString *urlStr = [NSString stringWithCString:url.c_str() encoding:[NSString defaultCStringEncoding]]; | ||
| NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:urlStr]]; | ||
| NSURLSession *session = [NSURLSession sharedSession]; | ||
| NSURLSessionDataTask *task = [session dataTaskWithRequest:request completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) { | ||
| if (!error) { | ||
| DataT dataT{}; | ||
| dataT.resize(data.length); | ||
| [data getBytes:dataT.data() | ||
| length:data.length]; | ||
|
bghgary marked this conversation as resolved.
|
||
| taskCompletionSource.complete(std::move(dataT)); | ||
| } | ||
| else | ||
| { | ||
| NSLog(@"Error: %@", [error localizedDescription]); | ||
| } | ||
| }]; | ||
| [task resume]; | ||
| return taskCompletionSource.as_task(); | ||
| } | ||
|
|
||
| arcana::task<std::string, std::exception_ptr> LoadTextAsync(std::string url) | ||
| { | ||
| return LoadUrlAsync<std::string>(std::move(url)); | ||
| } | ||
|
|
||
| arcana::task<std::vector<uint8_t>, std::exception_ptr> LoadBinaryAsync(std::string url) | ||
| { | ||
| return LoadUrlAsync<std::vector<uint8_t>>(std::move(url)); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -616,7 +616,7 @@ namespace Babylon | |
| const spirv_cross::ShaderResources resources = compiler.get_shader_resources(); | ||
| assert(resources.uniform_buffers.size() == 1); | ||
| const spirv_cross::Resource& uniformBuffer = resources.uniform_buffers[0]; | ||
| #if (BGFX_CONFIG_RENDERER_METAL) | ||
| #if __APPLE__ | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why this change? The comment below indicates that the guarded behavior is specific to Metal, not Apple; is that incorrect?
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. BGFX_CONFIG_RENDERER_METAL not defined. APPLE is the only define that I've found to make the guard.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: We should probably associate this with the rendering engine somewhere down the line, since this could cause problems if somebody doesn't use the default runtime for the platform (i.e., GL or MoltenVK or whatever). |
||
| // with metal, we bind images and not samplers | ||
| const spirv_cross::SmallVector<spirv_cross::Resource>& samplers = resources.separate_images; | ||
| #else | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| // XMLHttpRequest from https://github.com/Lukas-Stuehrk/XMLHTTPRequest | ||
| // with modifications (addEventListener, arraybuffer) | ||
| // MIT License | ||
|
bghgary marked this conversation as resolved.
|
||
| #import <Foundation/Foundation.h> | ||
| #import <JavaScriptCore/JavaScriptCore.h> | ||
| #include <napi/napi.h> | ||
| #include <Babylon/JsRuntime.h> | ||
|
|
||
| typedef void (^ CompletionHandlerFunction)(); | ||
| typedef void (^ CompletionHandler)(CompletionHandlerFunction); | ||
|
|
||
| void InitializeXMLHttpRequest(Babylon::JsRuntime& runtime); | ||
|
|
||
| typedef NS_ENUM(NSUInteger , ReadyState) { | ||
| XMLHttpRequestUNSENT =0, // open()has not been called yet. | ||
| XMLHttpRequestOPENED, // send()has not been called yet. | ||
| XMLHttpRequestHEADERS, // RECEIVED send() has been called, and headers and status are available. | ||
| XMLHttpRequestLOADING, // Downloading; responseText holds partial data. | ||
| XMLHttpRequestDONE // The operation is complete. | ||
| }; | ||
|
|
||
| @protocol XMLHttpRequest <JSExport> | ||
| @property (nonatomic, retain) JSValue *response; | ||
| @property (nonatomic) NSString *responseText; | ||
| @property (nonatomic, copy) NSString *responseType; | ||
|
|
||
| @property (nonatomic) NSNumber *readyState; | ||
| @property (nonatomic) JSValue *onload; | ||
| @property (nonatomic) JSValue *onerror; | ||
| @property (nonatomic) NSNumber *status; | ||
| @property (nonatomic) NSString *statusText; | ||
|
|
||
| -(void)open:(NSString *)httpMethod :(NSString *)url :(bool)async; | ||
| -(void)send:(id)data; | ||
| -(void)setRequestHeader:(NSString *)name :(NSString *)value; | ||
| -(void)addEventListener:(NSString *)event :(JSValue *)callback; | ||
| -(void)removeEventListener:(NSString *)event :(JSValue *)callback; | ||
| -(NSString *)getAllResponseHeaders; | ||
| -(NSString *)getResponseHeader:(NSString *)name; | ||
| @end | ||
|
|
||
| @interface XMLHttpRequest : NSObject <XMLHttpRequest> | ||
| - (instancetype)initWithURLSession: (NSURLSession *)urlSession; | ||
| - (void)extend:(JSGlobalContextRef)globalContextRef:(Babylon::JsRuntime *)runtime; | ||
| @property (nonatomic) NSMutableDictionary *_eventHandlers; | ||
| @property (atomic, copy) NSURLSession *_urlSession; | ||
| @property (atomic, copy) NSString *_httpMethod; | ||
| @property (atomic, copy) NSURL *_url; | ||
| @property (atomic) bool _async; | ||
| @property (nonatomic) NSMutableDictionary *_requestHeaders; | ||
| @property (atomic, copy) NSDictionary *_responseHeaders; | ||
| //@property (atomic, copy) NSString *_urlString; | ||
| @property (nonatomic, retain) JSValue *_onreadystatechange; | ||
| @end | ||
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: I'm a little iffy about the platform-specific guards we have in here. I know they're inevitable in certain cases, but we really ended up with a ton of them before the plugin refactor (many of which we still have), and for me it felt pretty messy. Can we look for alternatives for how to minimize these, at least within scenarios where we have duplicated code, as below?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
best alternative is to have specific plugin/project per platform IMHO. instead of guards we would have more cmakelists.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd be fine with that. Is this just a temporary workaround, then? If so, can we associate an issue with it?