|
|
@ -473,6 +473,7 @@ namespace _gfs = std::filesystem; |
|
|
|
#if defined(__EMSCRIPTEN__) |
|
|
|
#if defined(__EMSCRIPTEN__) |
|
|
|
#define OLC_PLATFORM_EMSCRIPTEN |
|
|
|
#define OLC_PLATFORM_EMSCRIPTEN |
|
|
|
#include <emscripten/fetch.h> |
|
|
|
#include <emscripten/fetch.h> |
|
|
|
|
|
|
|
#include <emscripten/emscripten.h> |
|
|
|
#endif |
|
|
|
#endif |
|
|
|
#endif |
|
|
|
#endif |
|
|
|
#endif |
|
|
|
#endif |
|
|
@ -996,6 +997,7 @@ namespace olc |
|
|
|
virtual void OnTextEntryComplete(const std::string& sText); |
|
|
|
virtual void OnTextEntryComplete(const std::string& sText); |
|
|
|
// Called when a console command is executed
|
|
|
|
// Called when a console command is executed
|
|
|
|
virtual bool OnConsoleCommand(const std::string& sCommand); |
|
|
|
virtual bool OnConsoleCommand(const std::string& sCommand); |
|
|
|
|
|
|
|
virtual void OnRequestCompleted(const std::string_view receivedData)const; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
virtual olc::rcode SendRequest(std::string_view url,std::string_view data); |
|
|
|
virtual olc::rcode SendRequest(std::string_view url,std::string_view data); |
|
|
@ -1242,6 +1244,8 @@ namespace olc |
|
|
|
|
|
|
|
|
|
|
|
public: |
|
|
|
public: |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static std::string responseData; |
|
|
|
|
|
|
|
|
|
|
|
// Experimental Lightweight 3D Routines ================
|
|
|
|
// Experimental Lightweight 3D Routines ================
|
|
|
|
#ifdef OLC_ENABLE_EXPERIMENTAL |
|
|
|
#ifdef OLC_ENABLE_EXPERIMENTAL |
|
|
|
// Set Manual View Matrix
|
|
|
|
// Set Manual View Matrix
|
|
|
@ -2044,6 +2048,8 @@ namespace olc |
|
|
|
return o; |
|
|
|
return o; |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
std::string PixelGameEngine::responseData; |
|
|
|
|
|
|
|
|
|
|
|
// O------------------------------------------------------------------------------O
|
|
|
|
// O------------------------------------------------------------------------------O
|
|
|
|
// | olc::PixelGameEngine IMPLEMENTATION |
|
|
|
|
// | olc::PixelGameEngine IMPLEMENTATION |
|
|
|
|
// O------------------------------------------------------------------------------O
|
|
|
|
// O------------------------------------------------------------------------------O
|
|
|
@ -4393,6 +4399,8 @@ namespace olc |
|
|
|
void PixelGameEngine::OnTextEntryComplete(const std::string& sText) { UNUSED(sText); } |
|
|
|
void PixelGameEngine::OnTextEntryComplete(const std::string& sText) { UNUSED(sText); } |
|
|
|
bool PixelGameEngine::OnConsoleCommand(const std::string& sCommand) { UNUSED(sCommand); return false; } |
|
|
|
bool PixelGameEngine::OnConsoleCommand(const std::string& sCommand) { UNUSED(sCommand); return false; } |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void PixelGameEngine::OnRequestCompleted(const std::string_view receivedData)const{} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
olc::rcode PixelGameEngine::SendRequest(std::string_view url,std::string_view data){platform->SendRequest(url,data);return olc::rcode::OK;}; |
|
|
|
olc::rcode PixelGameEngine::SendRequest(std::string_view url,std::string_view data){platform->SendRequest(url,data);return olc::rcode::OK;}; |
|
|
|
|
|
|
|
|
|
|
@ -7206,23 +7214,10 @@ namespace olc |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
virtual olc::rcode SendRequest(std::string_view url,std::string_view data)override{ |
|
|
|
virtual olc::rcode SendRequest(std::string_view url,std::string_view data)override{ |
|
|
|
emscripten_fetch_attr_t attr; |
|
|
|
EM_ASM({ |
|
|
|
emscripten_fetch_attr_init(&attr); |
|
|
|
requestResp=""; |
|
|
|
strcpy(attr.requestMethod, "GET"); |
|
|
|
fetch(UTF8ToString($0)).then((resp)=>resp.text()).then((data)=>{requestResp=data}); |
|
|
|
attr.attributes=EMSCRIPTEN_FETCH_LOAD_TO_MEMORY|EMSCRIPTEN_FETCH_SYNCHRONOUS|EMSCRIPTEN_FETCH_REPLACE; |
|
|
|
},std::string(url).c_str()); |
|
|
|
emscripten_fetch_t*fetch=emscripten_fetch(&attr,std::string(url).c_str()); // Blocks here until the operation is complete.
|
|
|
|
|
|
|
|
if(fetch->status==200){ |
|
|
|
|
|
|
|
printf("Finished downloading %llu bytes from URL %s.\n", fetch->numBytes, fetch->url); |
|
|
|
|
|
|
|
// The data is now available at fetch->data[0] through fetch->data[fetch->numBytes-1];
|
|
|
|
|
|
|
|
}else{ |
|
|
|
|
|
|
|
printf("Downloading %s failed, HTTP failure status code: %d.\n",fetch->url,fetch->status); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
emscripten_fetch_close(fetch); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for(int i=0;i<fetch->numBytes;i++){ |
|
|
|
|
|
|
|
std::cout<<fetch->data[i]; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
std::cout<<std::endl; |
|
|
|
|
|
|
|
return olc::rcode::OK; |
|
|
|
return olc::rcode::OK; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -7350,6 +7345,22 @@ namespace olc |
|
|
|
static void MainLoop() |
|
|
|
static void MainLoop() |
|
|
|
{ |
|
|
|
{ |
|
|
|
olc::Platform::ptrPGE->olc_CoreUpdate(); |
|
|
|
olc::Platform::ptrPGE->olc_CoreUpdate(); |
|
|
|
|
|
|
|
char*ptr=(char*)EM_ASM_PTR({ |
|
|
|
|
|
|
|
if(requestResp!==""){ |
|
|
|
|
|
|
|
console.log("Request received: "+requestResp); |
|
|
|
|
|
|
|
var newPtr=stringToNewUTF8(requestResp); |
|
|
|
|
|
|
|
requestResp=""; |
|
|
|
|
|
|
|
return newPtr; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return 0; |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(ptr!=NULL){ |
|
|
|
|
|
|
|
PixelGameEngine::responseData=std::string(ptr); |
|
|
|
|
|
|
|
ptrPGE->OnRequestCompleted(PixelGameEngine::responseData); |
|
|
|
|
|
|
|
delete ptr; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (!ptrPGE->olc_IsRunning()) |
|
|
|
if (!ptrPGE->olc_IsRunning()) |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (ptrPGE->OnUserDestroy()) |
|
|
|
if (ptrPGE->OnUserDestroy()) |
|
|
|