-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
51545c2
commit 9f59922
Showing
7 changed files
with
84 additions
and
1,814 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
#include "actrwasm.h" | ||
#include "actrfetch.h" | ||
#include "actrmap.h" | ||
#include "actrcanvas.h" | ||
#include "actrasync.h" | ||
#include "actrjson.h" | ||
|
||
// fetch json example | ||
|
||
int asyncHandle = 0; | ||
char * text = "loading will begin shortly..."; | ||
|
||
[[clang::export_name("actr_async_result")]] | ||
void actr_async_result(int handle, int success) | ||
{ | ||
if (handle == asyncHandle) { | ||
if (success == 1) { | ||
text = actr_json_get_string(1, "MyObject.one"); | ||
} else { | ||
// this will happen if the fetch request fails | ||
asyncHandle = 0; | ||
text = "fetch error, retrying..."; | ||
} | ||
} | ||
} | ||
|
||
[[clang::export_name("actr_step")]] | ||
void actr_step(double delta) | ||
{ | ||
if (asyncHandle == 0) | ||
{ | ||
text = "loading..."; | ||
asyncHandle = actr_fetch_json("https://mrnathanstiles.github.io/test.json", 1); | ||
if (asyncHandle < 1) { | ||
// this would happen if the url is invalid or rejected | ||
// this will happen if actr_async_result is not exported | ||
text = "url error, retrying..."; | ||
asyncHandle = 0; | ||
} | ||
} | ||
|
||
|
||
actr_canvas2d_fillStyle(0, 0, 0, 100); | ||
actr_canvas2d_fillRect(-10, -10, 9999, 9999); | ||
|
||
actr_canvas2d_fillStyle(255, 255, 255, 100); | ||
actr_canvas2d_fillText(10, 20, text, strlen(text)); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,21 @@ | ||
#include "actrwasm.h" | ||
|
||
#ifndef ACTRJSON_H | ||
#define ACTRJSON_H | ||
|
||
int actr_json_get_int_length(int jsonId, char * path, int pathLength); | ||
float actr_json_get_float_length(int jsonId, char * path, int pathLength); | ||
char * actr_json_get_string_length(int jsonId, char * path, int pathLength); | ||
|
||
int actr_json_get_int(int jsonId, char * path) { | ||
return actr_json_get_int_length(jsonId, path, strlen(path)); | ||
} | ||
float actr_json_get_float(int jsonId, char * path) { | ||
return actr_json_get_float_length(jsonId, path, strlen(path)); | ||
} | ||
char * actr_json_get_string(int jsonId, char * path) { | ||
return actr_json_get_string_length(jsonId, path, strlen(path)); | ||
} | ||
|
||
#endif | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.