mirror of
https://github.com/godotengine/godot.git
synced 2025-10-25 18:54:43 +00:00
HTML5 exporter seems to be fully functional
-user:// filesystem implemented -default template page could look prettier, help appreciated
This commit is contained in:
parent
56c907ad04
commit
a88f67821c
6 changed files with 113 additions and 13 deletions
|
|
@ -63,7 +63,7 @@ Error FileAccessUnix::_open(const String& p_path, int p_mode_flags) {
|
||||||
fclose(f);
|
fclose(f);
|
||||||
f=NULL;
|
f=NULL;
|
||||||
|
|
||||||
String path=fix_path(p_path);
|
path=fix_path(p_path);
|
||||||
//printf("opening %ls, %i\n", path.c_str(), Memory::get_static_mem_usage());
|
//printf("opening %ls, %i\n", path.c_str(), Memory::get_static_mem_usage());
|
||||||
|
|
||||||
ERR_FAIL_COND_V(f,ERR_ALREADY_IN_USE);
|
ERR_FAIL_COND_V(f,ERR_ALREADY_IN_USE);
|
||||||
|
|
@ -114,6 +114,9 @@ void FileAccessUnix::close() {
|
||||||
return;
|
return;
|
||||||
fclose(f);
|
fclose(f);
|
||||||
f = NULL;
|
f = NULL;
|
||||||
|
if (close_notification_func) {
|
||||||
|
close_notification_func(path,flags);
|
||||||
|
}
|
||||||
if (save_path!="") {
|
if (save_path!="") {
|
||||||
|
|
||||||
//unlink(save_path.utf8().get_data());
|
//unlink(save_path.utf8().get_data());
|
||||||
|
|
@ -240,6 +243,7 @@ FileAccess * FileAccessUnix::create_libc() {
|
||||||
return memnew( FileAccessUnix );
|
return memnew( FileAccessUnix );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
CloseNotificationFunc FileAccessUnix::close_notification_func=NULL;
|
||||||
|
|
||||||
FileAccessUnix::FileAccessUnix() {
|
FileAccessUnix::FileAccessUnix() {
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -38,6 +38,10 @@
|
||||||
/**
|
/**
|
||||||
@author Juan Linietsky <reduzio@gmail.com>
|
@author Juan Linietsky <reduzio@gmail.com>
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
typedef void (*CloseNotificationFunc)(const String& p_file,int p_flags);
|
||||||
|
|
||||||
class FileAccessUnix : public FileAccess {
|
class FileAccessUnix : public FileAccess {
|
||||||
|
|
||||||
FILE *f;
|
FILE *f;
|
||||||
|
|
@ -45,10 +49,13 @@ class FileAccessUnix : public FileAccess {
|
||||||
void check_errors() const;
|
void check_errors() const;
|
||||||
mutable Error last_error;
|
mutable Error last_error;
|
||||||
String save_path;
|
String save_path;
|
||||||
|
String path;
|
||||||
|
|
||||||
static FileAccess* create_libc();
|
static FileAccess* create_libc();
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
static CloseNotificationFunc close_notification_func;
|
||||||
|
|
||||||
virtual Error _open(const String& p_path, int p_mode_flags); ///< open a file
|
virtual Error _open(const String& p_path, int p_mode_flags); ///< open a file
|
||||||
virtual void close(); ///< close a file
|
virtual void close(); ///< close a file
|
||||||
virtual bool is_open() const; ///< true when file is open
|
virtual bool is_open() const; ///< true when file is open
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,7 @@ javascript_objects=[]
|
||||||
for x in javascript_files:
|
for x in javascript_files:
|
||||||
javascript_objects.append( env_javascript.Object( x ) )
|
javascript_objects.append( env_javascript.Object( x ) )
|
||||||
|
|
||||||
env.Append(LINKFLAGS=["-s","EXPORTED_FUNCTIONS=\"['_main','_audio_server_mix_function']\""])
|
env.Append(LINKFLAGS=["-s","EXPORTED_FUNCTIONS=\"['_main','_audio_server_mix_function','_main_after_fs_sync']\""])
|
||||||
|
|
||||||
prog = None
|
prog = None
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -31,7 +31,8 @@
|
||||||
#include "main/main.h"
|
#include "main/main.h"
|
||||||
#include "io/resource_loader.h"
|
#include "io/resource_loader.h"
|
||||||
#include "os/keyboard.h"
|
#include "os/keyboard.h"
|
||||||
|
#include "emscripten.h"
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
OS_JavaScript *os=NULL;
|
OS_JavaScript *os=NULL;
|
||||||
|
|
||||||
|
|
@ -198,15 +199,39 @@ static void _gfx_idle() {
|
||||||
glutPostRedisplay();
|
glutPostRedisplay();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int start_step=0;
|
||||||
|
|
||||||
static void _godot_draw(void) {
|
static void _godot_draw(void) {
|
||||||
|
|
||||||
os->main_loop_iterate();
|
if (start_step==1) {
|
||||||
|
start_step=2;
|
||||||
|
Main::start();
|
||||||
|
os->main_loop_begin();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (start_step==2) {
|
||||||
|
os->main_loop_iterate();
|
||||||
|
}
|
||||||
|
|
||||||
glutSwapBuffers();
|
glutSwapBuffers();
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char *argv[]) {
|
|
||||||
/* Initialize the window */
|
|
||||||
|
|
||||||
|
|
||||||
|
extern "C" {
|
||||||
|
|
||||||
|
void main_after_fs_sync(int value) {
|
||||||
|
|
||||||
|
start_step=1;
|
||||||
|
printf("FS SYNCHED!\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(int argc, char *argv[]) {
|
||||||
|
|
||||||
|
|
||||||
|
/* Initialize the window */
|
||||||
printf("let it go!\n");
|
printf("let it go!\n");
|
||||||
glutInit(&argc, argv);
|
glutInit(&argc, argv);
|
||||||
os = new OS_JavaScript(_gfx_init,NULL,NULL,NULL,NULL);
|
os = new OS_JavaScript(_gfx_init,NULL,NULL,NULL,NULL);
|
||||||
|
|
@ -220,7 +245,7 @@ int main(int argc, char *argv[]) {
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
ResourceLoader::set_abort_on_missing_resources(false); //ease up compatibility
|
ResourceLoader::set_abort_on_missing_resources(false); //ease up compatibility
|
||||||
Main::start();
|
|
||||||
|
|
||||||
glutSpecialUpFunc(_glut_skey_up);
|
glutSpecialUpFunc(_glut_skey_up);
|
||||||
glutSpecialFunc(_glut_skey_down);
|
glutSpecialFunc(_glut_skey_down);
|
||||||
|
|
@ -238,10 +263,32 @@ int main(int argc, char *argv[]) {
|
||||||
// glutReshapeFunc(gears_reshape);
|
// glutReshapeFunc(gears_reshape);
|
||||||
glutDisplayFunc(_godot_draw);
|
glutDisplayFunc(_godot_draw);
|
||||||
//glutSpecialFunc(gears_special);
|
//glutSpecialFunc(gears_special);
|
||||||
os->main_loop_begin();
|
|
||||||
|
|
||||||
|
|
||||||
|
//mount persistent filesystem
|
||||||
|
EM_ASM(
|
||||||
|
FS.mkdir('/userfs');
|
||||||
|
FS.mount(IDBFS, {}, '/userfs');
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// sync from persisted state into memory and then
|
||||||
|
// run the 'test' function
|
||||||
|
FS.syncfs(true, function (err) {
|
||||||
|
assert(!err);
|
||||||
|
console.log("done syncinc!");
|
||||||
|
_after_sync_cb = Module.cwrap('main_after_fs_sync', 'void',['number']);
|
||||||
|
_after_sync_cb(0);
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
);
|
||||||
|
|
||||||
glutMainLoop();
|
glutMainLoop();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -37,6 +37,7 @@
|
||||||
#include "main/main.h"
|
#include "main/main.h"
|
||||||
|
|
||||||
#include "core/globals.h"
|
#include "core/globals.h"
|
||||||
|
#include "emscripten.h"
|
||||||
|
|
||||||
int OS_JavaScript::get_video_driver_count() const {
|
int OS_JavaScript::get_video_driver_count() const {
|
||||||
|
|
||||||
|
|
@ -270,6 +271,32 @@ bool OS_JavaScript::main_loop_iterate() {
|
||||||
|
|
||||||
if (!main_loop)
|
if (!main_loop)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
if (time_to_save_sync>=0) {
|
||||||
|
int64_t newtime = get_ticks_msec();
|
||||||
|
int64_t elapsed = newtime - last_sync_time;
|
||||||
|
last_sync_time=newtime;
|
||||||
|
|
||||||
|
time_to_save_sync-=elapsed;
|
||||||
|
|
||||||
|
print_line("elapsed "+itos(elapsed)+" tts "+itos(time_to_save_sync));
|
||||||
|
|
||||||
|
if (time_to_save_sync<0) {
|
||||||
|
//time to sync, for real
|
||||||
|
// run 'success'
|
||||||
|
print_line("DOING SYNCH!");
|
||||||
|
EM_ASM(
|
||||||
|
FS.syncfs(function (err) {
|
||||||
|
assert(!err);
|
||||||
|
console.log("Synched!");
|
||||||
|
//ccall('success', 'v');
|
||||||
|
});
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
return Main::iteration();
|
return Main::iteration();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -562,14 +589,21 @@ String OS_JavaScript::get_locale() const {
|
||||||
|
|
||||||
String OS_JavaScript::get_data_dir() const {
|
String OS_JavaScript::get_data_dir() const {
|
||||||
|
|
||||||
if (get_data_dir_func)
|
//if (get_data_dir_func)
|
||||||
return get_data_dir_func();
|
// return get_data_dir_func();
|
||||||
return "/";
|
return "/userfs";
|
||||||
//return Globals::get_singleton()->get_singleton_object("GodotOS")->call("get_data_dir");
|
//return Globals::get_singleton()->get_singleton_object("GodotOS")->call("get_data_dir");
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
void OS_JavaScript::_close_notification_funcs(const String& p_file,int p_flags) {
|
||||||
|
|
||||||
|
print_line("close "+p_file+" flags "+itos(p_flags));
|
||||||
|
if (p_file.begins_with("/userfs") && p_flags&FileAccess::WRITE) {
|
||||||
|
static_cast<OS_JavaScript*>(get_singleton())->last_sync_time=OS::get_singleton()->get_ticks_msec();
|
||||||
|
static_cast<OS_JavaScript*>(get_singleton())->time_to_save_sync=5000; //five seconds since last save
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
OS_JavaScript::OS_JavaScript(GFXInitFunc p_gfx_init_func,void*p_gfx_init_ud, OpenURIFunc p_open_uri_func, GetDataDirFunc p_get_data_dir_func,GetLocaleFunc p_get_locale_func) {
|
OS_JavaScript::OS_JavaScript(GFXInitFunc p_gfx_init_func,void*p_gfx_init_ud, OpenURIFunc p_open_uri_func, GetDataDirFunc p_get_data_dir_func,GetLocaleFunc p_get_locale_func) {
|
||||||
|
|
||||||
|
|
@ -589,6 +623,9 @@ OS_JavaScript::OS_JavaScript(GFXInitFunc p_gfx_init_func,void*p_gfx_init_ud, Ope
|
||||||
open_uri_func=p_open_uri_func;
|
open_uri_func=p_open_uri_func;
|
||||||
get_data_dir_func=p_get_data_dir_func;
|
get_data_dir_func=p_get_data_dir_func;
|
||||||
get_locale_func=p_get_locale_func;
|
get_locale_func=p_get_locale_func;
|
||||||
|
FileAccessUnix::close_notification_func=_close_notification_funcs;
|
||||||
|
|
||||||
|
time_to_save_sync=-1;
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -65,6 +65,9 @@ private:
|
||||||
|
|
||||||
bool use_gl2;
|
bool use_gl2;
|
||||||
|
|
||||||
|
int64_t time_to_save_sync;
|
||||||
|
int64_t last_sync_time;
|
||||||
|
|
||||||
Rasterizer *rasterizer;
|
Rasterizer *rasterizer;
|
||||||
VisualServer *visual_server;
|
VisualServer *visual_server;
|
||||||
AudioServerJavascript *audio_server;
|
AudioServerJavascript *audio_server;
|
||||||
|
|
@ -84,6 +87,8 @@ private:
|
||||||
GetDataDirFunc get_data_dir_func;
|
GetDataDirFunc get_data_dir_func;
|
||||||
GetLocaleFunc get_locale_func;
|
GetLocaleFunc get_locale_func;
|
||||||
|
|
||||||
|
static void _close_notification_funcs(const String& p_file,int p_flags);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
// functions used by main to initialize/deintialize the OS
|
// functions used by main to initialize/deintialize the OS
|
||||||
|
|
@ -106,7 +111,7 @@ public:
|
||||||
|
|
||||||
typedef int64_t ProcessID;
|
typedef int64_t ProcessID;
|
||||||
|
|
||||||
static OS* get_singleton();
|
//static OS* get_singleton();
|
||||||
|
|
||||||
virtual void vprint(const char* p_format, va_list p_list, bool p_stderr=false);
|
virtual void vprint(const char* p_format, va_list p_list, bool p_stderr=false);
|
||||||
virtual void print(const char *p_format, ... );
|
virtual void print(const char *p_format, ... );
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue