Move emscripten function to separate file
This commit is contained in:
		
							parent
							
								
									a847164445
								
							
						
					
					
						commit
						2ea2f31c03
					
				
					 4 changed files with 49 additions and 34 deletions
				
			
		| 
						 | 
				
			
			@ -45,7 +45,7 @@
 | 
			
		|||
#include "eventthread.h"
 | 
			
		||||
 | 
			
		||||
#ifdef __EMSCRIPTEN__
 | 
			
		||||
#include <emscripten.h>
 | 
			
		||||
#include "emscripten.hpp"
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
#define GUARD_MEGA \
 | 
			
		||||
| 
						 | 
				
			
			@ -237,39 +237,6 @@ struct BitmapPrivate
 | 
			
		|||
	}
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
#ifdef __EMSCRIPTEN__
 | 
			
		||||
EM_JS(void, load_file_async, (const char* fullPathC), {
 | 
			
		||||
	Asyncify.handleSleep(function(wakeUp) {
 | 
			
		||||
		const fullPath = UTF8ToString(fullPathC);
 | 
			
		||||
 | 
			
		||||
		// Make cache object
 | 
			
		||||
		if (!window.fileAsyncCache) window.fileAsyncCache = {};
 | 
			
		||||
 | 
			
		||||
		// Check if already loaded
 | 
			
		||||
		if (window.fileAsyncCache.hasOwnProperty(fullPath)) return wakeUp();
 | 
			
		||||
 | 
			
		||||
		// Get full destination
 | 
			
		||||
		const file = "game/" + fullPath;
 | 
			
		||||
 | 
			
		||||
		// Get path and filename
 | 
			
		||||
		const path = "/" + file.substring(0, file.lastIndexOf("/"));
 | 
			
		||||
		const filename = file.substring(file.lastIndexOf("/") + 1);
 | 
			
		||||
 | 
			
		||||
		// Get target URL
 | 
			
		||||
		const iurl = "gameasync/" + fullPath;
 | 
			
		||||
 | 
			
		||||
		// Delete original file
 | 
			
		||||
		FS.unlink(path + "/" + filename);
 | 
			
		||||
 | 
			
		||||
		// Get the new file
 | 
			
		||||
		FS.createPreloadedFile(path, filename, iurl, true, true, function() {
 | 
			
		||||
			window.fileAsyncCache[fullPath] = 1;
 | 
			
		||||
			wakeUp();
 | 
			
		||||
		}, console.error);
 | 
			
		||||
	});
 | 
			
		||||
});
 | 
			
		||||
#endif;
 | 
			
		||||
 | 
			
		||||
struct BitmapOpenHandler : FileSystem::OpenHandler
 | 
			
		||||
{
 | 
			
		||||
	SDL_Surface *surf;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
							
								
								
									
										33
									
								
								src/emscripten.cpp
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										33
									
								
								src/emscripten.cpp
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,33 @@
 | 
			
		|||
#include "emscripten.hpp"
 | 
			
		||||
 | 
			
		||||
EM_JS(void, load_file_async, (const char* fullPathC), {
 | 
			
		||||
	Asyncify.handleSleep(function(wakeUp) {
 | 
			
		||||
		const fullPath = UTF8ToString(fullPathC);
 | 
			
		||||
 | 
			
		||||
		// Make cache object
 | 
			
		||||
		if (!window.fileAsyncCache) window.fileAsyncCache = {};
 | 
			
		||||
 | 
			
		||||
		// Check if already loaded
 | 
			
		||||
		if (window.fileAsyncCache.hasOwnProperty(fullPath)) return wakeUp();
 | 
			
		||||
 | 
			
		||||
		// Get full destination
 | 
			
		||||
		const file = "game/" + fullPath;
 | 
			
		||||
 | 
			
		||||
		// Get path and filename
 | 
			
		||||
		const path = "/" + file.substring(0, file.lastIndexOf("/"));
 | 
			
		||||
		const filename = file.substring(file.lastIndexOf("/") + 1);
 | 
			
		||||
 | 
			
		||||
		// Get target URL
 | 
			
		||||
		const iurl = "gameasync/" + fullPath;
 | 
			
		||||
 | 
			
		||||
		// Delete original file
 | 
			
		||||
		FS.unlink(path + "/" + filename);
 | 
			
		||||
 | 
			
		||||
		// Get the new file
 | 
			
		||||
		FS.createPreloadedFile(path, filename, iurl, true, true, function() {
 | 
			
		||||
			window.fileAsyncCache[fullPath] = 1;
 | 
			
		||||
			wakeUp();
 | 
			
		||||
		}, console.error);
 | 
			
		||||
	});
 | 
			
		||||
});
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										14
									
								
								src/emscripten.hpp
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										14
									
								
								src/emscripten.hpp
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,14 @@
 | 
			
		|||
#ifndef EMSCRIPTEN_HPP
 | 
			
		||||
#define EMSCRIPTEN_HPP
 | 
			
		||||
 | 
			
		||||
#ifdef __EMSCRIPTEN__
 | 
			
		||||
#include <emscripten.h>
 | 
			
		||||
 | 
			
		||||
extern "C" {
 | 
			
		||||
	void load_file_async(const char* fullPathC);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue