mirror of
https://github.com/godotengine/godot.git
synced 2026-01-03 18:11:19 +03:00
A Whole New World (clang-format edition)
I can show you the code Pretty, with proper whitespace Tell me, coder, now when did You last write readable code? I can open your eyes Make you see your bad indent Force you to respect the style The core devs agreed upon A whole new world A new fantastic code format A de facto standard With some sugar Enforced with clang-format A whole new world A dazzling style we all dreamed of And when we read it through It's crystal clear That now we're in a whole new world of code
This commit is contained in:
@@ -37,21 +37,17 @@
|
||||
|
||||
//AudioDriverJavaScript* AudioDriverJavaScript::s_ad=NULL;
|
||||
|
||||
const char* AudioDriverJavaScript::get_name() const {
|
||||
const char *AudioDriverJavaScript::get_name() const {
|
||||
|
||||
return "JavaScript";
|
||||
}
|
||||
|
||||
Error AudioDriverJavaScript::init(){
|
||||
Error AudioDriverJavaScript::init() {
|
||||
|
||||
return OK;
|
||||
|
||||
}
|
||||
|
||||
void AudioDriverJavaScript::start(){
|
||||
|
||||
|
||||
|
||||
void AudioDriverJavaScript::start() {
|
||||
}
|
||||
|
||||
int AudioDriverJavaScript::get_mix_rate() const {
|
||||
@@ -59,18 +55,17 @@ int AudioDriverJavaScript::get_mix_rate() const {
|
||||
return 44100;
|
||||
}
|
||||
|
||||
AudioDriver::SpeakerMode AudioDriverJavaScript::get_speaker_mode() const{
|
||||
AudioDriver::SpeakerMode AudioDriverJavaScript::get_speaker_mode() const {
|
||||
|
||||
return SPEAKER_MODE_STEREO;
|
||||
}
|
||||
|
||||
void AudioDriverJavaScript::lock(){
|
||||
void AudioDriverJavaScript::lock() {
|
||||
|
||||
/*
|
||||
if (active && mutex)
|
||||
mutex->lock();
|
||||
*/
|
||||
|
||||
}
|
||||
|
||||
void AudioDriverJavaScript::unlock() {
|
||||
@@ -79,16 +74,10 @@ void AudioDriverJavaScript::unlock() {
|
||||
if (active && mutex)
|
||||
mutex->unlock();
|
||||
*/
|
||||
|
||||
}
|
||||
|
||||
void AudioDriverJavaScript::finish(){
|
||||
|
||||
void AudioDriverJavaScript::finish() {
|
||||
}
|
||||
|
||||
AudioDriverJavaScript::AudioDriverJavaScript()
|
||||
{
|
||||
AudioDriverJavaScript::AudioDriverJavaScript() {
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -35,20 +35,17 @@
|
||||
|
||||
class AudioDriverJavaScript : public AudioDriver {
|
||||
public:
|
||||
|
||||
virtual const char* get_name() const;
|
||||
virtual const char *get_name() const;
|
||||
|
||||
virtual Error init();
|
||||
virtual void start();
|
||||
virtual int get_mix_rate() const ;
|
||||
virtual int get_mix_rate() const;
|
||||
virtual SpeakerMode get_speaker_mode() const;
|
||||
virtual void lock();
|
||||
virtual void unlock();
|
||||
virtual void finish();
|
||||
|
||||
|
||||
AudioDriverJavaScript();
|
||||
};
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
@@ -767,7 +767,7 @@ void AudioServerJavascript::driver_process_chunk(int p_frames) {
|
||||
|
||||
int32_t stream_vol_scale=(stream_volume*stream_volume_scale*E->get()->volume_scale)*(1<<STREAM_SCALE_BITS);
|
||||
|
||||
#define STRSCALE(m_val) ((((m_val>>STREAM_SCALE_BITS)*stream_vol_scale)>>8)/8388608.0)
|
||||
#define STRSCALE(m_val) ((((m_val >> STREAM_SCALE_BITS) * stream_vol_scale) >> 8) / 8388608.0)
|
||||
switch(channels) {
|
||||
case 1: {
|
||||
|
||||
|
||||
@@ -236,7 +236,7 @@ int dom2godot_scancode(int dom_keycode) {
|
||||
return KEY_F1 + (dom_keycode - DOM_VK_F1);
|
||||
}
|
||||
|
||||
switch(dom_keycode) {
|
||||
switch (dom_keycode) {
|
||||
//case DOM_VK_CANCEL: return KEY_UNKNOWN;
|
||||
case DOM_VK_HELP: return KEY_HELP;
|
||||
case DOM_VK_BACK_SPACE: return KEY_BACKSPACE;
|
||||
@@ -258,7 +258,8 @@ int dom2godot_scancode(int dom_keycode) {
|
||||
return KEY_ALT;
|
||||
|
||||
case DOM_VK_PAUSE: return KEY_PAUSE;
|
||||
case DOM_VK_CAPS_LOCK: return KEY_CAPSLOCK;
|
||||
case DOM_VK_CAPS_LOCK:
|
||||
return KEY_CAPSLOCK;
|
||||
|
||||
/*
|
||||
case DOM_VK_KANA: return KEY_UNKNOWN;
|
||||
@@ -270,7 +271,8 @@ int dom2godot_scancode(int dom_keycode) {
|
||||
case DOM_VK_KANJI: return KEY_UNKNOWN;
|
||||
*/
|
||||
|
||||
case DOM_VK_ESCAPE: return KEY_ESCAPE;
|
||||
case DOM_VK_ESCAPE:
|
||||
return KEY_ESCAPE;
|
||||
/*
|
||||
case DOM_VK_CONVERT: return KEY_UNKNOWN;
|
||||
case DOM_VK_NONCONVERT: return KEY_UNKNOWN;
|
||||
@@ -286,7 +288,8 @@ int dom2godot_scancode(int dom_keycode) {
|
||||
case DOM_VK_LEFT: return KEY_LEFT;
|
||||
case DOM_VK_UP: return KEY_UP;
|
||||
case DOM_VK_RIGHT: return KEY_RIGHT;
|
||||
case DOM_VK_DOWN: return KEY_DOWN;
|
||||
case DOM_VK_DOWN:
|
||||
return KEY_DOWN;
|
||||
|
||||
//case DOM_VK_SELECT: return KEY_UNKNOWN;
|
||||
|
||||
@@ -303,15 +306,18 @@ int dom2godot_scancode(int dom_keycode) {
|
||||
return KEY_META;
|
||||
|
||||
case DOM_VK_CONTEXT_MENU: return KEY_MENU;
|
||||
case DOM_VK_SLEEP: return KEY_STANDBY;
|
||||
case DOM_VK_SLEEP:
|
||||
return KEY_STANDBY;
|
||||
|
||||
// these are numpad keys according to MDN
|
||||
case DOM_VK_MULTIPLY: return KEY_KP_MULTIPLY;
|
||||
case DOM_VK_ADD: return KEY_KP_ADD;
|
||||
case DOM_VK_SEPARATOR: return KEY_KP_PERIOD; // good enough?
|
||||
case DOM_VK_SEPARATOR:
|
||||
return KEY_KP_PERIOD; // good enough?
|
||||
case DOM_VK_SUBTRACT: return KEY_KP_SUBTRACT;
|
||||
case DOM_VK_DECIMAL: return KEY_KP_PERIOD;
|
||||
case DOM_VK_DIVIDE: return KEY_KP_DIVIDE;
|
||||
case DOM_VK_DIVIDE:
|
||||
return KEY_KP_DIVIDE;
|
||||
|
||||
/*
|
||||
case DOM_VK_F17: return KEY_UNKNOWN;
|
||||
@@ -325,7 +331,8 @@ int dom2godot_scancode(int dom_keycode) {
|
||||
*/
|
||||
|
||||
case DOM_VK_NUM_LOCK: return KEY_NUMLOCK;
|
||||
case DOM_VK_SCROLL_LOCK: return KEY_SCROLLLOCK;
|
||||
case DOM_VK_SCROLL_LOCK:
|
||||
return KEY_SCROLLLOCK;
|
||||
|
||||
/*
|
||||
case DOM_VK_WIN_OEM_FJ_JISHO: return KEY_UNKNOWN;
|
||||
@@ -364,7 +371,8 @@ int dom2godot_scancode(int dom_keycode) {
|
||||
case DOM_VK_OPEN_BRACKET: return KEY_BRACKETLEFT;
|
||||
case DOM_VK_BACK_SLASH: return KEY_BACKSLASH;
|
||||
case DOM_VK_CLOSE_BRACKET: return KEY_BRACKETRIGHT;
|
||||
case DOM_VK_QUOTE: return KEY_APOSTROPHE;
|
||||
case DOM_VK_QUOTE:
|
||||
return KEY_APOSTROPHE;
|
||||
|
||||
// rest is OEM/unusual
|
||||
|
||||
|
||||
@@ -26,19 +26,18 @@
|
||||
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
|
||||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/*************************************************************************/
|
||||
#include "version.h"
|
||||
#include "export.h"
|
||||
#include "editor/editor_settings.h"
|
||||
#include "editor/editor_export.h"
|
||||
#include "editor/editor_node.h"
|
||||
#include "io/zip_io.h"
|
||||
#include "io/marshalls.h"
|
||||
#include "editor/editor_settings.h"
|
||||
#include "global_config.h"
|
||||
#include "io/marshalls.h"
|
||||
#include "io/zip_io.h"
|
||||
#include "os/file_access.h"
|
||||
#include "os/os.h"
|
||||
#include "platform/javascript/logo.h"
|
||||
#include "string.h"
|
||||
|
||||
#include "version.h"
|
||||
|
||||
#if 0
|
||||
class EditorExportPlatformJavaScript : public EditorExportPlatform {
|
||||
@@ -420,11 +419,6 @@ EditorExportPlatformJavaScript::~EditorExportPlatformJavaScript() {
|
||||
#endif
|
||||
void register_javascript_exporter() {
|
||||
|
||||
|
||||
//Ref<EditorExportPlatformJavaScript> exporter = Ref<EditorExportPlatformJavaScript>( memnew(EditorExportPlatformJavaScript) );
|
||||
//EditorImportExport::get_singleton()->add_export_platform(exporter);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -31,16 +31,20 @@
|
||||
#include "javascript_eval.h"
|
||||
#include "emscripten.h"
|
||||
|
||||
JavaScript *JavaScript::singleton=NULL;
|
||||
JavaScript *JavaScript::singleton = NULL;
|
||||
|
||||
JavaScript *JavaScript::get_singleton() {
|
||||
|
||||
return singleton;
|
||||
}
|
||||
|
||||
Variant JavaScript::eval(const String& p_code, bool p_use_global_exec_context) {
|
||||
Variant JavaScript::eval(const String &p_code, bool p_use_global_exec_context) {
|
||||
|
||||
union { int i; double d; char* s; } js_data[4];
|
||||
union {
|
||||
int i;
|
||||
double d;
|
||||
char *s;
|
||||
} js_data[4];
|
||||
/* clang-format off */
|
||||
Variant::Type return_type = static_cast<Variant::Type>(EM_ASM_INT({
|
||||
|
||||
@@ -127,21 +131,20 @@ Variant JavaScript::eval(const String& p_code, bool p_use_global_exec_context) {
|
||||
}, js_data, sizeof *js_data, p_code.utf8().get_data(), p_use_global_exec_context));
|
||||
/* clang-format on */
|
||||
|
||||
switch(return_type) {
|
||||
switch (return_type) {
|
||||
case Variant::BOOL:
|
||||
return !!js_data->i;
|
||||
case Variant::INT:
|
||||
return js_data->i;
|
||||
case Variant::REAL:
|
||||
return js_data->d;
|
||||
case Variant::STRING:
|
||||
{
|
||||
String str = String::utf8(js_data->s);
|
||||
/* clang-format off */
|
||||
case Variant::STRING: {
|
||||
String str = String::utf8(js_data->s);
|
||||
/* clang-format off */
|
||||
EM_ASM_({ _free($0); }, js_data->s);
|
||||
/* clang-format on */
|
||||
return str;
|
||||
}
|
||||
/* clang-format on */
|
||||
return str;
|
||||
}
|
||||
case Variant::VECTOR2:
|
||||
return Vector2(js_data[0].d, js_data[1].d);
|
||||
case Variant::VECTOR3:
|
||||
@@ -149,7 +152,7 @@ Variant JavaScript::eval(const String& p_code, bool p_use_global_exec_context) {
|
||||
case Variant::RECT2:
|
||||
return Rect2(js_data[0].d, js_data[1].d, js_data[2].d, js_data[3].d);
|
||||
case Variant::COLOR:
|
||||
return Color(js_data[0].d/255., js_data[1].d/255., js_data[2].d/255., js_data[3].d);
|
||||
return Color(js_data[0].d / 255., js_data[1].d / 255., js_data[2].d / 255., js_data[3].d);
|
||||
}
|
||||
return Variant();
|
||||
}
|
||||
@@ -166,7 +169,6 @@ JavaScript::JavaScript() {
|
||||
}
|
||||
|
||||
JavaScript::~JavaScript() {
|
||||
|
||||
}
|
||||
|
||||
#endif // JAVASCRIPT_EVAL_ENABLED
|
||||
|
||||
@@ -35,16 +35,15 @@
|
||||
|
||||
class JavaScript : public Object {
|
||||
private:
|
||||
GDCLASS( JavaScript, Object );
|
||||
GDCLASS(JavaScript, Object);
|
||||
|
||||
static JavaScript *singleton;
|
||||
|
||||
|
||||
protected:
|
||||
static void _bind_methods();
|
||||
|
||||
public:
|
||||
Variant eval(const String& p_code, bool p_use_global_exec_context = false);
|
||||
Variant eval(const String &p_code, bool p_use_global_exec_context = false);
|
||||
|
||||
static JavaScript *get_singleton();
|
||||
JavaScript();
|
||||
|
||||
@@ -26,92 +26,88 @@
|
||||
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
|
||||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/*************************************************************************/
|
||||
#include <GL/glut.h>
|
||||
#include "os_javascript.h"
|
||||
#include "main/main.h"
|
||||
#include "io/resource_loader.h"
|
||||
#include "emscripten.h"
|
||||
#include "io/resource_loader.h"
|
||||
#include "main/main.h"
|
||||
#include "os_javascript.h"
|
||||
#include <GL/glut.h>
|
||||
#include <string.h>
|
||||
|
||||
OS_JavaScript *os=NULL;
|
||||
OS_JavaScript *os = NULL;
|
||||
|
||||
static void _gfx_init(void *ud,bool gl2,int w, int h,bool fs) {
|
||||
static void _gfx_init(void *ud, bool gl2, int w, int h, bool fs) {
|
||||
|
||||
glutInitWindowSize(w, h);
|
||||
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
|
||||
glutCreateWindow("godot");
|
||||
|
||||
}
|
||||
|
||||
static uint32_t _mouse_button_mask=0;
|
||||
static uint32_t _mouse_button_mask = 0;
|
||||
|
||||
static void _glut_mouse_button(int button, int state, int x, int y) {
|
||||
|
||||
InputEvent ev;
|
||||
ev.type=InputEvent::MOUSE_BUTTON;
|
||||
switch(button) {
|
||||
case GLUT_LEFT_BUTTON: ev.mouse_button.button_index=BUTTON_LEFT; break;
|
||||
case GLUT_MIDDLE_BUTTON: ev.mouse_button.button_index=BUTTON_MIDDLE; break;
|
||||
case GLUT_RIGHT_BUTTON: ev.mouse_button.button_index=BUTTON_RIGHT; break;
|
||||
case 3: ev.mouse_button.button_index=BUTTON_WHEEL_UP; break;
|
||||
case 4: ev.mouse_button.button_index=BUTTON_WHEEL_DOWN; break;
|
||||
ev.type = InputEvent::MOUSE_BUTTON;
|
||||
switch (button) {
|
||||
case GLUT_LEFT_BUTTON: ev.mouse_button.button_index = BUTTON_LEFT; break;
|
||||
case GLUT_MIDDLE_BUTTON: ev.mouse_button.button_index = BUTTON_MIDDLE; break;
|
||||
case GLUT_RIGHT_BUTTON: ev.mouse_button.button_index = BUTTON_RIGHT; break;
|
||||
case 3: ev.mouse_button.button_index = BUTTON_WHEEL_UP; break;
|
||||
case 4: ev.mouse_button.button_index = BUTTON_WHEEL_DOWN; break;
|
||||
}
|
||||
|
||||
ev.mouse_button.pressed = state == GLUT_DOWN;
|
||||
ev.mouse_button.x = x;
|
||||
ev.mouse_button.y = y;
|
||||
ev.mouse_button.global_x = x;
|
||||
ev.mouse_button.global_y = y;
|
||||
|
||||
ev.mouse_button.pressed=state==GLUT_DOWN;
|
||||
ev.mouse_button.x=x;
|
||||
ev.mouse_button.y=y;
|
||||
ev.mouse_button.global_x=x;
|
||||
ev.mouse_button.global_y=y;
|
||||
|
||||
if (ev.mouse_button.button_index<4) {
|
||||
if (ev.mouse_button.button_index < 4) {
|
||||
if (ev.mouse_button.pressed) {
|
||||
_mouse_button_mask |= 1 << (ev.mouse_button.button_index-1);
|
||||
_mouse_button_mask |= 1 << (ev.mouse_button.button_index - 1);
|
||||
} else {
|
||||
_mouse_button_mask &= ~(1 << (ev.mouse_button.button_index-1));
|
||||
_mouse_button_mask &= ~(1 << (ev.mouse_button.button_index - 1));
|
||||
}
|
||||
}
|
||||
ev.mouse_button.button_mask=_mouse_button_mask;
|
||||
ev.mouse_button.button_mask = _mouse_button_mask;
|
||||
|
||||
uint32_t m = glutGetModifiers();
|
||||
ev.mouse_button.mod.alt=(m&GLUT_ACTIVE_ALT)!=0;
|
||||
ev.mouse_button.mod.shift=(m&GLUT_ACTIVE_SHIFT)!=0;
|
||||
ev.mouse_button.mod.control=(m&GLUT_ACTIVE_CTRL)!=0;
|
||||
ev.mouse_button.mod.alt = (m & GLUT_ACTIVE_ALT) != 0;
|
||||
ev.mouse_button.mod.shift = (m & GLUT_ACTIVE_SHIFT) != 0;
|
||||
ev.mouse_button.mod.control = (m & GLUT_ACTIVE_CTRL) != 0;
|
||||
|
||||
os->push_input(ev);
|
||||
|
||||
if (ev.mouse_button.button_index==BUTTON_WHEEL_UP || ev.mouse_button.button_index==BUTTON_WHEEL_DOWN) {
|
||||
if (ev.mouse_button.button_index == BUTTON_WHEEL_UP || ev.mouse_button.button_index == BUTTON_WHEEL_DOWN) {
|
||||
// GLUT doesn't send release events for mouse wheel, so send manually
|
||||
ev.mouse_button.pressed=false;
|
||||
ev.mouse_button.pressed = false;
|
||||
os->push_input(ev);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static int _glut_prev_x=0;
|
||||
static int _glut_prev_y=0;
|
||||
static int _glut_prev_x = 0;
|
||||
static int _glut_prev_y = 0;
|
||||
|
||||
static void _glut_mouse_motion(int x, int y) {
|
||||
|
||||
InputEvent ev;
|
||||
ev.type=InputEvent::MOUSE_MOTION;
|
||||
ev.mouse_motion.button_mask=_mouse_button_mask;
|
||||
ev.mouse_motion.x=x;
|
||||
ev.mouse_motion.y=y;
|
||||
ev.mouse_motion.global_x=x;
|
||||
ev.mouse_motion.global_y=y;
|
||||
ev.mouse_motion.relative_x=x-_glut_prev_x;
|
||||
ev.mouse_motion.relative_y=y-_glut_prev_y;
|
||||
_glut_prev_x=x;
|
||||
_glut_prev_y=y;
|
||||
ev.type = InputEvent::MOUSE_MOTION;
|
||||
ev.mouse_motion.button_mask = _mouse_button_mask;
|
||||
ev.mouse_motion.x = x;
|
||||
ev.mouse_motion.y = y;
|
||||
ev.mouse_motion.global_x = x;
|
||||
ev.mouse_motion.global_y = y;
|
||||
ev.mouse_motion.relative_x = x - _glut_prev_x;
|
||||
ev.mouse_motion.relative_y = y - _glut_prev_y;
|
||||
_glut_prev_x = x;
|
||||
_glut_prev_y = y;
|
||||
|
||||
uint32_t m = glutGetModifiers();
|
||||
ev.mouse_motion.mod.alt=(m&GLUT_ACTIVE_ALT)!=0;
|
||||
ev.mouse_motion.mod.shift=(m&GLUT_ACTIVE_SHIFT)!=0;
|
||||
ev.mouse_motion.mod.control=(m&GLUT_ACTIVE_CTRL)!=0;
|
||||
ev.mouse_motion.mod.alt = (m & GLUT_ACTIVE_ALT) != 0;
|
||||
ev.mouse_motion.mod.shift = (m & GLUT_ACTIVE_SHIFT) != 0;
|
||||
ev.mouse_motion.mod.control = (m & GLUT_ACTIVE_CTRL) != 0;
|
||||
|
||||
os->push_input(ev);
|
||||
|
||||
}
|
||||
|
||||
static void _gfx_idle() {
|
||||
@@ -119,47 +115,43 @@ static void _gfx_idle() {
|
||||
glutPostRedisplay();
|
||||
}
|
||||
|
||||
int start_step=0;
|
||||
int start_step = 0;
|
||||
|
||||
static void _godot_draw(void) {
|
||||
|
||||
if (start_step==1) {
|
||||
start_step=2;
|
||||
if (start_step == 1) {
|
||||
start_step = 2;
|
||||
Main::start();
|
||||
os->main_loop_begin();
|
||||
os->main_loop_begin();
|
||||
}
|
||||
|
||||
if (start_step==2) {
|
||||
if (start_step == 2) {
|
||||
os->main_loop_iterate();
|
||||
}
|
||||
|
||||
glutSwapBuffers();
|
||||
}
|
||||
|
||||
|
||||
|
||||
extern "C" {
|
||||
|
||||
void main_after_fs_sync() {
|
||||
|
||||
start_step=1;
|
||||
start_step = 1;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
|
||||
|
||||
/* Initialize the window */
|
||||
printf("let it go dude!\n");
|
||||
glutInit(&argc, argv);
|
||||
os = new OS_JavaScript(_gfx_init,NULL,NULL);
|
||||
os = new OS_JavaScript(_gfx_init, NULL, NULL);
|
||||
#if 0
|
||||
char *args[]={"-test","gui","-v",NULL};
|
||||
Error err = Main::setup("apk",3,args);
|
||||
#else
|
||||
char *args[]={"-main_pack","data.pck",NULL}; //pass location of main pack manually, because it wont get an executable name
|
||||
Error err = Main::setup("",2,args);
|
||||
char *args[] = { "-main_pack", "data.pck", NULL }; //pass location of main pack manually, because it wont get an executable name
|
||||
Error err = Main::setup("", 2, args);
|
||||
|
||||
#endif
|
||||
ResourceLoader::set_abort_on_missing_resources(false); //ease up compatibility
|
||||
@@ -168,13 +160,11 @@ int main(int argc, char *argv[]) {
|
||||
glutMotionFunc(_glut_mouse_motion);
|
||||
glutPassiveMotionFunc(_glut_mouse_motion);
|
||||
|
||||
|
||||
|
||||
/* Set up glut callback functions */
|
||||
glutIdleFunc (_gfx_idle);
|
||||
// glutReshapeFunc(gears_reshape);
|
||||
/* Set up glut callback functions */
|
||||
glutIdleFunc(_gfx_idle);
|
||||
// glutReshapeFunc(gears_reshape);
|
||||
glutDisplayFunc(_godot_draw);
|
||||
//glutSpecialFunc(gears_special);
|
||||
//glutSpecialFunc(gears_special);
|
||||
|
||||
//mount persistent file system
|
||||
/* clang-format off */
|
||||
@@ -200,12 +190,9 @@ int main(int argc, char *argv[]) {
|
||||
|
||||
glutMainLoop();
|
||||
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
*
|
||||
*09] <azakai|2__> reduz: yes, define TOTAL_MEMORY on Module. for example var Module = { TOTAL_MEMORY: 12345.. }; before the main
|
||||
|
||||
@@ -28,24 +28,24 @@
|
||||
/*************************************************************************/
|
||||
#include "os_javascript.h"
|
||||
|
||||
#include "drivers/gles3/rasterizer_gles3.h"
|
||||
#include "core/io/file_access_buffered_fa.h"
|
||||
#include "drivers/unix/file_access_unix.h"
|
||||
#include "drivers/unix/dir_access_unix.h"
|
||||
#include "servers/visual/visual_server_raster.h"
|
||||
#include "main/main.h"
|
||||
#include "core/global_config.h"
|
||||
#include "core/io/file_access_buffered_fa.h"
|
||||
#include "dom_keys.h"
|
||||
#include "drivers/gles3/rasterizer_gles3.h"
|
||||
#include "drivers/unix/dir_access_unix.h"
|
||||
#include "drivers/unix/file_access_unix.h"
|
||||
#include "main/main.h"
|
||||
#include "servers/visual/visual_server_raster.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <emscripten.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
int OS_JavaScript::get_video_driver_count() const {
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
const char * OS_JavaScript::get_video_driver_name(int p_driver) const {
|
||||
const char *OS_JavaScript::get_video_driver_name(int p_driver) const {
|
||||
|
||||
return "GLES3";
|
||||
}
|
||||
@@ -60,7 +60,7 @@ int OS_JavaScript::get_audio_driver_count() const {
|
||||
return 1;
|
||||
}
|
||||
|
||||
const char * OS_JavaScript::get_audio_driver_name(int p_driver) const {
|
||||
const char *OS_JavaScript::get_audio_driver_name(int p_driver) const {
|
||||
|
||||
return "JavaScript";
|
||||
}
|
||||
@@ -69,20 +69,19 @@ void OS_JavaScript::initialize_core() {
|
||||
|
||||
OS_Unix::initialize_core();
|
||||
FileAccess::make_default<FileAccessBufferedFA<FileAccessUnix> >(FileAccess::ACCESS_RESOURCES);
|
||||
|
||||
}
|
||||
|
||||
void OS_JavaScript::set_opengl_extensions(const char* p_gl_extensions) {
|
||||
void OS_JavaScript::set_opengl_extensions(const char *p_gl_extensions) {
|
||||
|
||||
ERR_FAIL_COND(!p_gl_extensions);
|
||||
gl_extensions=p_gl_extensions;
|
||||
gl_extensions = p_gl_extensions;
|
||||
}
|
||||
|
||||
static EM_BOOL _browser_resize_callback(int event_type, const EmscriptenUiEvent *ui_event, void *user_data) {
|
||||
|
||||
ERR_FAIL_COND_V(event_type!=EMSCRIPTEN_EVENT_RESIZE, false);
|
||||
ERR_FAIL_COND_V(event_type != EMSCRIPTEN_EVENT_RESIZE, false);
|
||||
|
||||
OS_JavaScript* os = static_cast<OS_JavaScript*>(user_data);
|
||||
OS_JavaScript *os = static_cast<OS_JavaScript *>(user_data);
|
||||
|
||||
// the order in which _browser_resize_callback and
|
||||
// _fullscreen_change_callback are called is browser-dependent,
|
||||
@@ -102,13 +101,13 @@ static Size2 _windowed_size;
|
||||
|
||||
static EM_BOOL _fullscreen_change_callback(int event_type, const EmscriptenFullscreenChangeEvent *event, void *user_data) {
|
||||
|
||||
ERR_FAIL_COND_V(event_type!=EMSCRIPTEN_EVENT_FULLSCREENCHANGE, false);
|
||||
ERR_FAIL_COND_V(event_type != EMSCRIPTEN_EVENT_FULLSCREENCHANGE, false);
|
||||
|
||||
OS_JavaScript* os = static_cast<OS_JavaScript*>(user_data);
|
||||
OS_JavaScript *os = static_cast<OS_JavaScript *>(user_data);
|
||||
String id = String::utf8(event->id);
|
||||
|
||||
// empty id is canvas
|
||||
if (id.empty() || id=="canvas") {
|
||||
if (id.empty() || id == "canvas") {
|
||||
|
||||
OS::VideoMode vm = os->get_video_mode();
|
||||
// this event property is the only reliable information on
|
||||
@@ -120,8 +119,7 @@ static EM_BOOL _fullscreen_change_callback(int event_type, const EmscriptenFulls
|
||||
vm.height = event->screenHeight;
|
||||
os->set_video_mode(vm);
|
||||
emscripten_set_canvas_size(vm.width, vm.height);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
os->set_video_mode(vm);
|
||||
if (!os->is_window_maximized()) {
|
||||
os->set_window_size(_windowed_size);
|
||||
@@ -144,12 +142,12 @@ static InputEvent _setup_key_event(const EmscriptenKeyboardEvent *emscripten_eve
|
||||
|
||||
String unicode = String::utf8(emscripten_event->key);
|
||||
// check if empty or multi-character (e.g. `CapsLock`)
|
||||
if (unicode.length()!=1) {
|
||||
if (unicode.length() != 1) {
|
||||
// might be empty as well, but better than nonsense
|
||||
unicode = String::utf8(emscripten_event->charValue);
|
||||
}
|
||||
if (unicode.length()==1) {
|
||||
ev.key.unicode=unicode[0];
|
||||
if (unicode.length() == 1) {
|
||||
ev.key.unicode = unicode[0];
|
||||
}
|
||||
|
||||
return ev;
|
||||
@@ -159,59 +157,58 @@ static InputEvent deferred_key_event;
|
||||
|
||||
static EM_BOOL _keydown_callback(int event_type, const EmscriptenKeyboardEvent *key_event, void *user_data) {
|
||||
|
||||
ERR_FAIL_COND_V(event_type!=EMSCRIPTEN_EVENT_KEYDOWN, false);
|
||||
ERR_FAIL_COND_V(event_type != EMSCRIPTEN_EVENT_KEYDOWN, false);
|
||||
|
||||
InputEvent ev = _setup_key_event(key_event);
|
||||
ev.key.pressed = true;
|
||||
if (ev.key.unicode==0 && keycode_has_unicode(ev.key.scancode)) {
|
||||
if (ev.key.unicode == 0 && keycode_has_unicode(ev.key.scancode)) {
|
||||
// defer to keypress event for legacy unicode retrieval
|
||||
deferred_key_event = ev;
|
||||
return false; // do not suppress keypress event
|
||||
}
|
||||
static_cast<OS_JavaScript*>(user_data)->push_input(ev);
|
||||
static_cast<OS_JavaScript *>(user_data)->push_input(ev);
|
||||
return true;
|
||||
}
|
||||
|
||||
static EM_BOOL _keypress_callback(int event_type, const EmscriptenKeyboardEvent *key_event, void *user_data) {
|
||||
|
||||
ERR_FAIL_COND_V(event_type!=EMSCRIPTEN_EVENT_KEYPRESS, false);
|
||||
ERR_FAIL_COND_V(event_type != EMSCRIPTEN_EVENT_KEYPRESS, false);
|
||||
|
||||
deferred_key_event.key.unicode = key_event->charCode;
|
||||
static_cast<OS_JavaScript*>(user_data)->push_input(deferred_key_event);
|
||||
static_cast<OS_JavaScript *>(user_data)->push_input(deferred_key_event);
|
||||
return true;
|
||||
}
|
||||
|
||||
static EM_BOOL _keyup_callback(int event_type, const EmscriptenKeyboardEvent *key_event, void *user_data) {
|
||||
|
||||
ERR_FAIL_COND_V(event_type!=EMSCRIPTEN_EVENT_KEYUP, false);
|
||||
ERR_FAIL_COND_V(event_type != EMSCRIPTEN_EVENT_KEYUP, false);
|
||||
|
||||
InputEvent ev = _setup_key_event(key_event);
|
||||
ev.key.pressed = false;
|
||||
static_cast<OS_JavaScript*>(user_data)->push_input(ev);
|
||||
return ev.key.scancode!=KEY_UNKNOWN && ev.key.scancode!=0;
|
||||
|
||||
static_cast<OS_JavaScript *>(user_data)->push_input(ev);
|
||||
return ev.key.scancode != KEY_UNKNOWN && ev.key.scancode != 0;
|
||||
}
|
||||
|
||||
static EM_BOOL joy_callback_func(int p_type, const EmscriptenGamepadEvent *p_event, void *p_user) {
|
||||
OS_JavaScript *os = (OS_JavaScript*) OS::get_singleton();
|
||||
OS_JavaScript *os = (OS_JavaScript *)OS::get_singleton();
|
||||
if (os) {
|
||||
return os->joy_connection_changed(p_type, p_event);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void OS_JavaScript::initialize(const VideoMode& p_desired,int p_video_driver,int p_audio_driver) {
|
||||
void OS_JavaScript::initialize(const VideoMode &p_desired, int p_video_driver, int p_audio_driver) {
|
||||
|
||||
print_line("Init OS");
|
||||
|
||||
if (gfx_init_func)
|
||||
gfx_init_func(gfx_init_ud,use_gl2,p_desired.width,p_desired.height,p_desired.fullscreen);
|
||||
gfx_init_func(gfx_init_ud, use_gl2, p_desired.width, p_desired.height, p_desired.fullscreen);
|
||||
|
||||
// nothing to do here, can't fulfil fullscreen request due to
|
||||
// browser security, window size is already set from HTML
|
||||
video_mode=p_desired;
|
||||
video_mode.fullscreen=false;
|
||||
_windowed_size=get_window_size();
|
||||
video_mode = p_desired;
|
||||
video_mode.fullscreen = false;
|
||||
_windowed_size = get_window_size();
|
||||
|
||||
// find locale, emscripten only sets "C"
|
||||
char locale_ptr[16];
|
||||
@@ -248,24 +245,29 @@ void OS_JavaScript::initialize(const VideoMode& p_desired,int p_video_driver,int
|
||||
|
||||
print_line("Init VS");
|
||||
|
||||
visual_server = memnew( VisualServerRaster() );
|
||||
visual_server = memnew(VisualServerRaster());
|
||||
visual_server->cursor_set_visible(false, 0);
|
||||
|
||||
print_line("Init Physicsserver");
|
||||
|
||||
physics_server = memnew( PhysicsServerSW );
|
||||
physics_server = memnew(PhysicsServerSW);
|
||||
physics_server->init();
|
||||
physics_2d_server = memnew( Physics2DServerSW );
|
||||
physics_2d_server = memnew(Physics2DServerSW);
|
||||
physics_2d_server->init();
|
||||
|
||||
input = memnew( InputDefault );
|
||||
|
||||
power_manager = memnew( PowerJavascript );
|
||||
input = memnew(InputDefault);
|
||||
|
||||
#define EM_CHECK(ev) if (result!=EMSCRIPTEN_RESULT_SUCCESS)\
|
||||
power_manager = memnew(PowerJavascript);
|
||||
|
||||
#define EM_CHECK(ev) \
|
||||
if (result != EMSCRIPTEN_RESULT_SUCCESS) \
|
||||
ERR_PRINTS("Error while setting " #ev " callback: Code " + itos(result))
|
||||
#define SET_EM_CALLBACK(ev, cb) result = emscripten_set_##ev##_callback(NULL, this, true, &cb); EM_CHECK(ev)
|
||||
#define SET_EM_CALLBACK_NODATA(ev, cb) result = emscripten_set_##ev##_callback(NULL, true, &cb); EM_CHECK(ev)
|
||||
#define SET_EM_CALLBACK(ev, cb) \
|
||||
result = emscripten_set_##ev##_callback(NULL, this, true, &cb); \
|
||||
EM_CHECK(ev)
|
||||
#define SET_EM_CALLBACK_NODATA(ev, cb) \
|
||||
result = emscripten_set_##ev##_callback(NULL, true, &cb); \
|
||||
EM_CHECK(ev)
|
||||
|
||||
EMSCRIPTEN_RESULT result;
|
||||
SET_EM_CALLBACK(keydown, _keydown_callback)
|
||||
@@ -288,16 +290,15 @@ void OS_JavaScript::initialize(const VideoMode& p_desired,int p_video_driver,int
|
||||
visual_server->init();
|
||||
}
|
||||
|
||||
void OS_JavaScript::set_main_loop( MainLoop * p_main_loop ) {
|
||||
void OS_JavaScript::set_main_loop(MainLoop *p_main_loop) {
|
||||
|
||||
main_loop=p_main_loop;
|
||||
main_loop = p_main_loop;
|
||||
input->set_main_loop(p_main_loop);
|
||||
|
||||
}
|
||||
|
||||
void OS_JavaScript::delete_main_loop() {
|
||||
|
||||
memdelete( main_loop );
|
||||
memdelete(main_loop);
|
||||
}
|
||||
|
||||
void OS_JavaScript::finalize() {
|
||||
@@ -305,7 +306,7 @@ void OS_JavaScript::finalize() {
|
||||
memdelete(input);
|
||||
}
|
||||
|
||||
void OS_JavaScript::alert(const String& p_alert,const String& p_title) {
|
||||
void OS_JavaScript::alert(const String &p_alert, const String &p_title) {
|
||||
|
||||
/* clang-format off */
|
||||
EM_ASM_({
|
||||
@@ -314,7 +315,6 @@ void OS_JavaScript::alert(const String& p_alert,const String& p_title) {
|
||||
/* clang-format on */
|
||||
}
|
||||
|
||||
|
||||
void OS_JavaScript::set_mouse_show(bool p_show) {
|
||||
|
||||
//javascript has no mouse...
|
||||
@@ -341,7 +341,7 @@ int OS_JavaScript::get_mouse_button_state() const {
|
||||
return last_button_mask;
|
||||
}
|
||||
|
||||
void OS_JavaScript::set_window_title(const String& p_title) {
|
||||
void OS_JavaScript::set_window_title(const String &p_title) {
|
||||
|
||||
/* clang-format off */
|
||||
EM_ASM_({
|
||||
@@ -354,7 +354,7 @@ void OS_JavaScript::set_window_title(const String& p_title) {
|
||||
//void set_clipboard(const String& p_text);
|
||||
//String get_clipboard() const;
|
||||
|
||||
void OS_JavaScript::set_video_mode(const VideoMode& p_video_mode,int p_screen) {
|
||||
void OS_JavaScript::set_video_mode(const VideoMode &p_video_mode, int p_screen) {
|
||||
|
||||
video_mode = p_video_mode;
|
||||
}
|
||||
@@ -366,11 +366,11 @@ OS::VideoMode OS_JavaScript::get_video_mode(int p_screen) const {
|
||||
|
||||
Size2 OS_JavaScript::get_screen_size(int p_screen) const {
|
||||
|
||||
ERR_FAIL_COND_V(p_screen!=0, Size2());
|
||||
ERR_FAIL_COND_V(p_screen != 0, Size2());
|
||||
|
||||
EmscriptenFullscreenChangeEvent ev;
|
||||
EMSCRIPTEN_RESULT result = emscripten_get_fullscreen_status(&ev);
|
||||
ERR_FAIL_COND_V(result!=EMSCRIPTEN_RESULT_SUCCESS, Size2());
|
||||
ERR_FAIL_COND_V(result != EMSCRIPTEN_RESULT_SUCCESS, Size2());
|
||||
return Size2(ev.screenWidth, ev.screenHeight);
|
||||
}
|
||||
|
||||
@@ -389,7 +389,7 @@ void OS_JavaScript::set_window_size(const Size2 p_size) {
|
||||
Size2 OS_JavaScript::get_window_size() const {
|
||||
|
||||
int canvas[3];
|
||||
emscripten_get_canvas_size(canvas, canvas+1, canvas+2);
|
||||
emscripten_get_canvas_size(canvas, canvas + 1, canvas + 2);
|
||||
return Size2(canvas[0], canvas[1]);
|
||||
}
|
||||
|
||||
@@ -401,23 +401,21 @@ void OS_JavaScript::set_window_maximized(bool p_enabled) {
|
||||
if (is_window_fullscreen()) {
|
||||
// _browser_resize callback will set canvas size
|
||||
set_window_fullscreen(false);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
/* clang-format off */
|
||||
video_mode.width = EM_ASM_INT_V(return window.innerWidth);
|
||||
video_mode.height = EM_ASM_INT_V(return window.innerHeight);
|
||||
/* clang-format on */
|
||||
emscripten_set_canvas_size(video_mode.width, video_mode.height);
|
||||
}
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
set_window_size(_windowed_size);
|
||||
}
|
||||
}
|
||||
|
||||
void OS_JavaScript::set_window_fullscreen(bool p_enable) {
|
||||
|
||||
if (p_enable==is_window_fullscreen()) {
|
||||
if (p_enable == is_window_fullscreen()) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -428,10 +426,9 @@ void OS_JavaScript::set_window_fullscreen(bool p_enable) {
|
||||
/* clang-format off */
|
||||
EM_ASM(Module.requestFullscreen(false, false););
|
||||
/* clang-format on */
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
result = emscripten_exit_fullscreen();
|
||||
if (result!=EMSCRIPTEN_RESULT_SUCCESS) {
|
||||
if (result != EMSCRIPTEN_RESULT_SUCCESS) {
|
||||
ERR_PRINTS("Failed to exit fullscreen: Code " + itos(result));
|
||||
}
|
||||
}
|
||||
@@ -442,7 +439,7 @@ bool OS_JavaScript::is_window_fullscreen() const {
|
||||
return video_mode.fullscreen;
|
||||
}
|
||||
|
||||
void OS_JavaScript::get_fullscreen_mode_list(List<VideoMode> *p_list,int p_screen) const {
|
||||
void OS_JavaScript::get_fullscreen_mode_list(List<VideoMode> *p_list, int p_screen) const {
|
||||
|
||||
Size2 screen = get_screen_size();
|
||||
p_list->push_back(OS::VideoMode(screen.width, screen.height, true));
|
||||
@@ -478,14 +475,14 @@ bool OS_JavaScript::main_loop_iterate() {
|
||||
if (!main_loop)
|
||||
return false;
|
||||
|
||||
if (time_to_save_sync>=0) {
|
||||
if (time_to_save_sync >= 0) {
|
||||
int64_t newtime = get_ticks_msec();
|
||||
int64_t elapsed = newtime - last_sync_time;
|
||||
last_sync_time=newtime;
|
||||
last_sync_time = newtime;
|
||||
|
||||
time_to_save_sync-=elapsed;
|
||||
time_to_save_sync -= elapsed;
|
||||
|
||||
if (time_to_save_sync<0) {
|
||||
if (time_to_save_sync < 0) {
|
||||
//time to sync, for real
|
||||
/* clang-format off */
|
||||
EM_ASM(
|
||||
@@ -495,8 +492,6 @@ bool OS_JavaScript::main_loop_iterate() {
|
||||
);
|
||||
/* clang-format on */
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
process_joypads();
|
||||
return Main::iteration();
|
||||
@@ -506,7 +501,6 @@ void OS_JavaScript::main_loop_end() {
|
||||
|
||||
if (main_loop)
|
||||
main_loop->finish();
|
||||
|
||||
}
|
||||
|
||||
void OS_JavaScript::main_loop_focusout() {
|
||||
@@ -514,186 +508,173 @@ void OS_JavaScript::main_loop_focusout() {
|
||||
if (main_loop)
|
||||
main_loop->notification(MainLoop::NOTIFICATION_WM_FOCUS_OUT);
|
||||
//audio_driver_javascript.set_pause(true);
|
||||
|
||||
}
|
||||
|
||||
void OS_JavaScript::main_loop_focusin(){
|
||||
void OS_JavaScript::main_loop_focusin() {
|
||||
|
||||
if (main_loop)
|
||||
main_loop->notification(MainLoop::NOTIFICATION_WM_FOCUS_IN);
|
||||
//audio_driver_javascript.set_pause(false);
|
||||
|
||||
}
|
||||
|
||||
void OS_JavaScript::push_input(const InputEvent& p_ev) {
|
||||
void OS_JavaScript::push_input(const InputEvent &p_ev) {
|
||||
|
||||
InputEvent ev = p_ev;
|
||||
ev.ID=last_id++;
|
||||
if (ev.type==InputEvent::MOUSE_MOTION) {
|
||||
ev.ID = last_id++;
|
||||
if (ev.type == InputEvent::MOUSE_MOTION) {
|
||||
input->set_mouse_pos(Point2(ev.mouse_motion.x, ev.mouse_motion.y));
|
||||
}
|
||||
else if (ev.type==InputEvent::MOUSE_BUTTON) {
|
||||
} else if (ev.type == InputEvent::MOUSE_BUTTON) {
|
||||
last_button_mask = ev.mouse_button.button_mask;
|
||||
}
|
||||
input->parse_input_event(p_ev);
|
||||
}
|
||||
|
||||
void OS_JavaScript::process_touch(int p_what,int p_pointer, const Vector<TouchPos>& p_points) {
|
||||
void OS_JavaScript::process_touch(int p_what, int p_pointer, const Vector<TouchPos> &p_points) {
|
||||
|
||||
//print_line("ev: "+itos(p_what)+" pnt: "+itos(p_pointer)+" pointc: "+itos(p_points.size()));
|
||||
|
||||
switch(p_what) {
|
||||
switch (p_what) {
|
||||
case 0: { //gesture begin
|
||||
|
||||
if (touch.size()) {
|
||||
//end all if exist
|
||||
InputEvent ev;
|
||||
ev.type=InputEvent::MOUSE_BUTTON;
|
||||
ev.ID=last_id++;
|
||||
ev.mouse_button.button_index=BUTTON_LEFT;
|
||||
ev.mouse_button.button_mask=BUTTON_MASK_LEFT;
|
||||
ev.mouse_button.pressed=false;
|
||||
ev.mouse_button.x=touch[0].pos.x;
|
||||
ev.mouse_button.y=touch[0].pos.y;
|
||||
ev.mouse_button.global_x=touch[0].pos.x;
|
||||
ev.mouse_button.global_y=touch[0].pos.y;
|
||||
ev.type = InputEvent::MOUSE_BUTTON;
|
||||
ev.ID = last_id++;
|
||||
ev.mouse_button.button_index = BUTTON_LEFT;
|
||||
ev.mouse_button.button_mask = BUTTON_MASK_LEFT;
|
||||
ev.mouse_button.pressed = false;
|
||||
ev.mouse_button.x = touch[0].pos.x;
|
||||
ev.mouse_button.y = touch[0].pos.y;
|
||||
ev.mouse_button.global_x = touch[0].pos.x;
|
||||
ev.mouse_button.global_y = touch[0].pos.y;
|
||||
input->parse_input_event(ev);
|
||||
|
||||
|
||||
for(int i=0;i<touch.size();i++) {
|
||||
for (int i = 0; i < touch.size(); i++) {
|
||||
|
||||
InputEvent ev;
|
||||
ev.type=InputEvent::SCREEN_TOUCH;
|
||||
ev.ID=last_id++;
|
||||
ev.screen_touch.index=touch[i].id;
|
||||
ev.screen_touch.pressed=false;
|
||||
ev.screen_touch.x=touch[i].pos.x;
|
||||
ev.screen_touch.y=touch[i].pos.y;
|
||||
ev.type = InputEvent::SCREEN_TOUCH;
|
||||
ev.ID = last_id++;
|
||||
ev.screen_touch.index = touch[i].id;
|
||||
ev.screen_touch.pressed = false;
|
||||
ev.screen_touch.x = touch[i].pos.x;
|
||||
ev.screen_touch.y = touch[i].pos.y;
|
||||
input->parse_input_event(ev);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
touch.resize(p_points.size());
|
||||
for(int i=0;i<p_points.size();i++) {
|
||||
touch[i].id=p_points[i].id;
|
||||
touch[i].pos=p_points[i].pos;
|
||||
for (int i = 0; i < p_points.size(); i++) {
|
||||
touch[i].id = p_points[i].id;
|
||||
touch[i].pos = p_points[i].pos;
|
||||
}
|
||||
|
||||
{
|
||||
//send mouse
|
||||
InputEvent ev;
|
||||
ev.type=InputEvent::MOUSE_BUTTON;
|
||||
ev.ID=last_id++;
|
||||
ev.mouse_button.button_index=BUTTON_LEFT;
|
||||
ev.mouse_button.button_mask=BUTTON_MASK_LEFT;
|
||||
ev.mouse_button.pressed=true;
|
||||
ev.mouse_button.x=touch[0].pos.x;
|
||||
ev.mouse_button.y=touch[0].pos.y;
|
||||
ev.mouse_button.global_x=touch[0].pos.x;
|
||||
ev.mouse_button.global_y=touch[0].pos.y;
|
||||
last_mouse=touch[0].pos;
|
||||
ev.type = InputEvent::MOUSE_BUTTON;
|
||||
ev.ID = last_id++;
|
||||
ev.mouse_button.button_index = BUTTON_LEFT;
|
||||
ev.mouse_button.button_mask = BUTTON_MASK_LEFT;
|
||||
ev.mouse_button.pressed = true;
|
||||
ev.mouse_button.x = touch[0].pos.x;
|
||||
ev.mouse_button.y = touch[0].pos.y;
|
||||
ev.mouse_button.global_x = touch[0].pos.x;
|
||||
ev.mouse_button.global_y = touch[0].pos.y;
|
||||
last_mouse = touch[0].pos;
|
||||
input->parse_input_event(ev);
|
||||
}
|
||||
|
||||
|
||||
//send touch
|
||||
for(int i=0;i<touch.size();i++) {
|
||||
for (int i = 0; i < touch.size(); i++) {
|
||||
|
||||
InputEvent ev;
|
||||
ev.type=InputEvent::SCREEN_TOUCH;
|
||||
ev.ID=last_id++;
|
||||
ev.screen_touch.index=touch[i].id;
|
||||
ev.screen_touch.pressed=true;
|
||||
ev.screen_touch.x=touch[i].pos.x;
|
||||
ev.screen_touch.y=touch[i].pos.y;
|
||||
ev.type = InputEvent::SCREEN_TOUCH;
|
||||
ev.ID = last_id++;
|
||||
ev.screen_touch.index = touch[i].id;
|
||||
ev.screen_touch.pressed = true;
|
||||
ev.screen_touch.x = touch[i].pos.x;
|
||||
ev.screen_touch.y = touch[i].pos.y;
|
||||
input->parse_input_event(ev);
|
||||
}
|
||||
|
||||
} break;
|
||||
case 1: { //motion
|
||||
|
||||
|
||||
if (p_points.size()) {
|
||||
//send mouse, should look for point 0?
|
||||
InputEvent ev;
|
||||
ev.type=InputEvent::MOUSE_MOTION;
|
||||
ev.ID=last_id++;
|
||||
ev.mouse_motion.button_mask=BUTTON_MASK_LEFT;
|
||||
ev.mouse_motion.x=p_points[0].pos.x;
|
||||
ev.mouse_motion.y=p_points[0].pos.y;
|
||||
input->set_mouse_pos(Point2(ev.mouse_motion.x,ev.mouse_motion.y));
|
||||
ev.mouse_motion.speed_x=input->get_last_mouse_speed().x;
|
||||
ev.mouse_motion.speed_y=input->get_last_mouse_speed().y;
|
||||
ev.mouse_motion.relative_x=p_points[0].pos.x-last_mouse.x;
|
||||
ev.mouse_motion.relative_y=p_points[0].pos.y-last_mouse.y;
|
||||
last_mouse=p_points[0].pos;
|
||||
ev.type = InputEvent::MOUSE_MOTION;
|
||||
ev.ID = last_id++;
|
||||
ev.mouse_motion.button_mask = BUTTON_MASK_LEFT;
|
||||
ev.mouse_motion.x = p_points[0].pos.x;
|
||||
ev.mouse_motion.y = p_points[0].pos.y;
|
||||
input->set_mouse_pos(Point2(ev.mouse_motion.x, ev.mouse_motion.y));
|
||||
ev.mouse_motion.speed_x = input->get_last_mouse_speed().x;
|
||||
ev.mouse_motion.speed_y = input->get_last_mouse_speed().y;
|
||||
ev.mouse_motion.relative_x = p_points[0].pos.x - last_mouse.x;
|
||||
ev.mouse_motion.relative_y = p_points[0].pos.y - last_mouse.y;
|
||||
last_mouse = p_points[0].pos;
|
||||
input->parse_input_event(ev);
|
||||
}
|
||||
|
||||
ERR_FAIL_COND(touch.size()!=p_points.size());
|
||||
ERR_FAIL_COND(touch.size() != p_points.size());
|
||||
|
||||
for(int i=0;i<touch.size();i++) {
|
||||
for (int i = 0; i < touch.size(); i++) {
|
||||
|
||||
int idx=-1;
|
||||
for(int j=0;j<p_points.size();j++) {
|
||||
int idx = -1;
|
||||
for (int j = 0; j < p_points.size(); j++) {
|
||||
|
||||
if (touch[i].id==p_points[j].id) {
|
||||
idx=j;
|
||||
if (touch[i].id == p_points[j].id) {
|
||||
idx = j;
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
ERR_CONTINUE(idx==-1);
|
||||
ERR_CONTINUE(idx == -1);
|
||||
|
||||
if (touch[i].pos==p_points[idx].pos)
|
||||
if (touch[i].pos == p_points[idx].pos)
|
||||
continue; //no move unncesearily
|
||||
|
||||
InputEvent ev;
|
||||
ev.type=InputEvent::SCREEN_DRAG;
|
||||
ev.ID=last_id++;
|
||||
ev.screen_drag.index=touch[i].id;
|
||||
ev.screen_drag.x=p_points[idx].pos.x;
|
||||
ev.screen_drag.y=p_points[idx].pos.y;
|
||||
ev.screen_drag.relative_x=p_points[idx].pos.x - touch[i].pos.x;
|
||||
ev.screen_drag.relative_y=p_points[idx].pos.y - touch[i].pos.y;
|
||||
ev.type = InputEvent::SCREEN_DRAG;
|
||||
ev.ID = last_id++;
|
||||
ev.screen_drag.index = touch[i].id;
|
||||
ev.screen_drag.x = p_points[idx].pos.x;
|
||||
ev.screen_drag.y = p_points[idx].pos.y;
|
||||
ev.screen_drag.relative_x = p_points[idx].pos.x - touch[i].pos.x;
|
||||
ev.screen_drag.relative_y = p_points[idx].pos.y - touch[i].pos.y;
|
||||
input->parse_input_event(ev);
|
||||
touch[i].pos=p_points[idx].pos;
|
||||
touch[i].pos = p_points[idx].pos;
|
||||
}
|
||||
|
||||
|
||||
} break;
|
||||
case 2: { //release
|
||||
|
||||
|
||||
|
||||
if (touch.size()) {
|
||||
//end all if exist
|
||||
InputEvent ev;
|
||||
ev.type=InputEvent::MOUSE_BUTTON;
|
||||
ev.ID=last_id++;
|
||||
ev.mouse_button.button_index=BUTTON_LEFT;
|
||||
ev.mouse_button.button_mask=BUTTON_MASK_LEFT;
|
||||
ev.mouse_button.pressed=false;
|
||||
ev.mouse_button.x=touch[0].pos.x;
|
||||
ev.mouse_button.y=touch[0].pos.y;
|
||||
ev.mouse_button.global_x=touch[0].pos.x;
|
||||
ev.mouse_button.global_y=touch[0].pos.y;
|
||||
ev.type = InputEvent::MOUSE_BUTTON;
|
||||
ev.ID = last_id++;
|
||||
ev.mouse_button.button_index = BUTTON_LEFT;
|
||||
ev.mouse_button.button_mask = BUTTON_MASK_LEFT;
|
||||
ev.mouse_button.pressed = false;
|
||||
ev.mouse_button.x = touch[0].pos.x;
|
||||
ev.mouse_button.y = touch[0].pos.y;
|
||||
ev.mouse_button.global_x = touch[0].pos.x;
|
||||
ev.mouse_button.global_y = touch[0].pos.y;
|
||||
input->parse_input_event(ev);
|
||||
|
||||
|
||||
for(int i=0;i<touch.size();i++) {
|
||||
for (int i = 0; i < touch.size(); i++) {
|
||||
|
||||
InputEvent ev;
|
||||
ev.type=InputEvent::SCREEN_TOUCH;
|
||||
ev.ID=last_id++;
|
||||
ev.screen_touch.index=touch[i].id;
|
||||
ev.screen_touch.pressed=false;
|
||||
ev.screen_touch.x=touch[i].pos.x;
|
||||
ev.screen_touch.y=touch[i].pos.y;
|
||||
ev.type = InputEvent::SCREEN_TOUCH;
|
||||
ev.ID = last_id++;
|
||||
ev.screen_touch.index = touch[i].id;
|
||||
ev.screen_touch.pressed = false;
|
||||
ev.screen_touch.x = touch[i].pos.x;
|
||||
ev.screen_touch.y = touch[i].pos.y;
|
||||
input->parse_input_event(ev);
|
||||
|
||||
}
|
||||
touch.clear();
|
||||
}
|
||||
@@ -701,38 +682,33 @@ void OS_JavaScript::process_touch(int p_what,int p_pointer, const Vector<TouchPo
|
||||
} break;
|
||||
case 3: { // add tuchi
|
||||
|
||||
ERR_FAIL_INDEX(p_pointer, p_points.size());
|
||||
|
||||
|
||||
|
||||
|
||||
ERR_FAIL_INDEX(p_pointer,p_points.size());
|
||||
|
||||
TouchPos tp=p_points[p_pointer];
|
||||
TouchPos tp = p_points[p_pointer];
|
||||
touch.push_back(tp);
|
||||
|
||||
InputEvent ev;
|
||||
ev.type=InputEvent::SCREEN_TOUCH;
|
||||
ev.ID=last_id++;
|
||||
ev.screen_touch.index=tp.id;
|
||||
ev.screen_touch.pressed=true;
|
||||
ev.screen_touch.x=tp.pos.x;
|
||||
ev.screen_touch.y=tp.pos.y;
|
||||
ev.type = InputEvent::SCREEN_TOUCH;
|
||||
ev.ID = last_id++;
|
||||
ev.screen_touch.index = tp.id;
|
||||
ev.screen_touch.pressed = true;
|
||||
ev.screen_touch.x = tp.pos.x;
|
||||
ev.screen_touch.y = tp.pos.y;
|
||||
input->parse_input_event(ev);
|
||||
|
||||
} break;
|
||||
case 4: {
|
||||
|
||||
|
||||
for(int i=0;i<touch.size();i++) {
|
||||
if (touch[i].id==p_pointer) {
|
||||
for (int i = 0; i < touch.size(); i++) {
|
||||
if (touch[i].id == p_pointer) {
|
||||
|
||||
InputEvent ev;
|
||||
ev.type=InputEvent::SCREEN_TOUCH;
|
||||
ev.ID=last_id++;
|
||||
ev.screen_touch.index=touch[i].id;
|
||||
ev.screen_touch.pressed=false;
|
||||
ev.screen_touch.x=touch[i].pos.x;
|
||||
ev.screen_touch.y=touch[i].pos.y;
|
||||
ev.type = InputEvent::SCREEN_TOUCH;
|
||||
ev.ID = last_id++;
|
||||
ev.screen_touch.index = touch[i].id;
|
||||
ev.screen_touch.pressed = false;
|
||||
ev.screen_touch.x = touch[i].pos.x;
|
||||
ev.screen_touch.y = touch[i].pos.y;
|
||||
input->parse_input_event(ev);
|
||||
touch.remove(i);
|
||||
i--;
|
||||
@@ -740,12 +716,10 @@ void OS_JavaScript::process_touch(int p_what,int p_pointer, const Vector<TouchPo
|
||||
}
|
||||
|
||||
} break;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void OS_JavaScript::process_accelerometer(const Vector3& p_accelerometer) {
|
||||
void OS_JavaScript::process_accelerometer(const Vector3 &p_accelerometer) {
|
||||
|
||||
input->set_accelerometer(p_accelerometer);
|
||||
}
|
||||
@@ -790,12 +764,12 @@ String OS_JavaScript::get_executable_path() const {
|
||||
return String();
|
||||
}
|
||||
|
||||
void OS_JavaScript::_close_notification_funcs(const String& p_file,int p_flags) {
|
||||
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
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
@@ -817,8 +791,7 @@ void OS_JavaScript::process_joypads() {
|
||||
jx.min = 0;
|
||||
jx.value = value;
|
||||
last_id = input->joy_axis(last_id, i, j, jx);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
last_id = input->joy_button(last_id, i, j, value);
|
||||
}
|
||||
}
|
||||
@@ -840,8 +813,7 @@ bool OS_JavaScript::joy_connection_changed(int p_type, const EmscriptenGamepadEv
|
||||
if (String(p_event->mapping) == "standard")
|
||||
guid = "Default HTML5 Gamepad";
|
||||
input->joy_connection_changed(p_event->index, true, String(p_event->id), guid);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
input->joy_connection_changed(p_event->index, false, "");
|
||||
}
|
||||
return true;
|
||||
@@ -867,22 +839,20 @@ int OS_JavaScript::get_power_percent_left() {
|
||||
return power_manager->get_power_percent_left();
|
||||
}
|
||||
|
||||
OS_JavaScript::OS_JavaScript(GFXInitFunc p_gfx_init_func,void*p_gfx_init_ud, GetDataDirFunc p_get_data_dir_func) {
|
||||
gfx_init_func=p_gfx_init_func;
|
||||
gfx_init_ud=p_gfx_init_ud;
|
||||
last_button_mask=0;
|
||||
main_loop=NULL;
|
||||
last_id=1;
|
||||
gl_extensions=NULL;
|
||||
window_maximized=false;
|
||||
OS_JavaScript::OS_JavaScript(GFXInitFunc p_gfx_init_func, void *p_gfx_init_ud, GetDataDirFunc p_get_data_dir_func) {
|
||||
gfx_init_func = p_gfx_init_func;
|
||||
gfx_init_ud = p_gfx_init_ud;
|
||||
last_button_mask = 0;
|
||||
main_loop = NULL;
|
||||
last_id = 1;
|
||||
gl_extensions = NULL;
|
||||
window_maximized = false;
|
||||
|
||||
get_data_dir_func=p_get_data_dir_func;
|
||||
FileAccessUnix::close_notification_func=_close_notification_funcs;
|
||||
get_data_dir_func = p_get_data_dir_func;
|
||||
FileAccessUnix::close_notification_func = _close_notification_funcs;
|
||||
|
||||
time_to_save_sync=-1;
|
||||
time_to_save_sync = -1;
|
||||
}
|
||||
|
||||
OS_JavaScript::~OS_JavaScript() {
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -29,40 +29,38 @@
|
||||
#ifndef OS_JAVASCRIPT_H
|
||||
#define OS_JAVASCRIPT_H
|
||||
|
||||
#include "os/input.h"
|
||||
#include "audio_driver_javascript.h"
|
||||
#include "audio_server_javascript.h"
|
||||
#include "drivers/unix/os_unix.h"
|
||||
#include "javascript_eval.h"
|
||||
#include "main/input_default.h"
|
||||
#include "os/input.h"
|
||||
#include "os/main_loop.h"
|
||||
#include "power_javascript.h"
|
||||
#include "servers/physics/physics_server_sw.h"
|
||||
#include "servers/audio_server.h"
|
||||
#include "servers/physics/physics_server_sw.h"
|
||||
#include "servers/physics_2d/physics_2d_server_sw.h"
|
||||
#include "servers/visual/rasterizer.h"
|
||||
#include "audio_server_javascript.h"
|
||||
#include "audio_driver_javascript.h"
|
||||
#include "main/input_default.h"
|
||||
#include "javascript_eval.h"
|
||||
|
||||
#include <emscripten/html5.h>
|
||||
|
||||
typedef void (*GFXInitFunc)(void *ud,bool gl2,int w, int h, bool fs);
|
||||
typedef void (*GFXInitFunc)(void *ud, bool gl2, int w, int h, bool fs);
|
||||
typedef String (*GetDataDirFunc)();
|
||||
|
||||
class OS_JavaScript : public OS_Unix {
|
||||
public:
|
||||
|
||||
struct TouchPos {
|
||||
int id;
|
||||
Point2 pos;
|
||||
};
|
||||
|
||||
private:
|
||||
|
||||
Vector<TouchPos> touch;
|
||||
Point2 last_mouse;
|
||||
int last_button_mask;
|
||||
unsigned int last_id;
|
||||
GFXInitFunc gfx_init_func;
|
||||
void*gfx_init_ud;
|
||||
void *gfx_init_ud;
|
||||
|
||||
bool use_gl2;
|
||||
|
||||
@@ -73,72 +71,69 @@ private:
|
||||
PhysicsServer *physics_server;
|
||||
Physics2DServer *physics_2d_server;
|
||||
AudioDriverJavaScript audio_driver_javascript;
|
||||
const char* gl_extensions;
|
||||
const char *gl_extensions;
|
||||
|
||||
InputDefault *input;
|
||||
bool window_maximized;
|
||||
VideoMode video_mode;
|
||||
MainLoop * main_loop;
|
||||
MainLoop *main_loop;
|
||||
|
||||
GetDataDirFunc get_data_dir_func;
|
||||
|
||||
PowerJavascript *power_manager;
|
||||
|
||||
#ifdef JAVASCRIPT_EVAL_ENABLED
|
||||
JavaScript* javascript_eval;
|
||||
JavaScript *javascript_eval;
|
||||
#endif
|
||||
|
||||
static void _close_notification_funcs(const String& p_file,int p_flags);
|
||||
static void _close_notification_funcs(const String &p_file, int p_flags);
|
||||
|
||||
void process_joypads();
|
||||
|
||||
public:
|
||||
|
||||
// functions used by main to initialize/deintialize the OS
|
||||
virtual int get_video_driver_count() const;
|
||||
virtual const char * get_video_driver_name(int p_driver) const;
|
||||
virtual const char *get_video_driver_name(int p_driver) const;
|
||||
|
||||
virtual VideoMode get_default_video_mode() const;
|
||||
|
||||
virtual int get_audio_driver_count() const;
|
||||
virtual const char * get_audio_driver_name(int p_driver) const;
|
||||
virtual const char *get_audio_driver_name(int p_driver) const;
|
||||
|
||||
virtual void initialize_core();
|
||||
virtual void initialize(const VideoMode& p_desired,int p_video_driver,int p_audio_driver);
|
||||
virtual void initialize(const VideoMode &p_desired, int p_video_driver, int p_audio_driver);
|
||||
|
||||
virtual void set_main_loop( MainLoop * p_main_loop );
|
||||
virtual void set_main_loop(MainLoop *p_main_loop);
|
||||
virtual void delete_main_loop();
|
||||
|
||||
virtual void finalize();
|
||||
|
||||
|
||||
typedef int64_t ProcessID;
|
||||
|
||||
//static OS* get_singleton();
|
||||
|
||||
virtual void print_error(const char* p_function, const char* p_file, int p_line, const char *p_code, const char* p_rationale, ErrorType p_type) {
|
||||
virtual void print_error(const char *p_function, const char *p_file, int p_line, const char *p_code, const char *p_rationale, ErrorType p_type) {
|
||||
|
||||
OS::print_error(p_function, p_file, p_line, p_code, p_rationale, p_type);
|
||||
}
|
||||
|
||||
virtual void alert(const String& p_alert,const String& p_title="ALERT!");
|
||||
|
||||
virtual void alert(const String &p_alert, const String &p_title = "ALERT!");
|
||||
|
||||
virtual void set_mouse_show(bool p_show);
|
||||
virtual void set_mouse_grab(bool p_grab);
|
||||
virtual bool is_mouse_grab_enabled() const;
|
||||
virtual Point2 get_mouse_pos() const;
|
||||
virtual int get_mouse_button_state() const;
|
||||
virtual void set_window_title(const String& p_title);
|
||||
virtual void set_window_title(const String &p_title);
|
||||
|
||||
//virtual void set_clipboard(const String& p_text);
|
||||
//virtual String get_clipboard() const;
|
||||
|
||||
virtual void set_video_mode(const VideoMode& p_video_mode,int p_screen=0);
|
||||
virtual VideoMode get_video_mode(int p_screen=0) const;
|
||||
virtual void get_fullscreen_mode_list(List<VideoMode> *p_list,int p_screen=0) const;
|
||||
virtual void set_video_mode(const VideoMode &p_video_mode, int p_screen = 0);
|
||||
virtual VideoMode get_video_mode(int p_screen = 0) const;
|
||||
virtual void get_fullscreen_mode_list(List<VideoMode> *p_list, int p_screen = 0) const;
|
||||
|
||||
virtual Size2 get_screen_size(int p_screen=0) const;
|
||||
virtual Size2 get_screen_size(int p_screen = 0) const;
|
||||
|
||||
virtual void set_window_size(const Size2);
|
||||
virtual Size2 get_window_size() const;
|
||||
@@ -163,28 +158,27 @@ public:
|
||||
|
||||
virtual bool has_touchscreen_ui_hint() const;
|
||||
|
||||
void set_opengl_extensions(const char* p_gl_extensions);
|
||||
void set_opengl_extensions(const char *p_gl_extensions);
|
||||
|
||||
virtual Error shell_open(String p_uri);
|
||||
virtual String get_data_dir() const;
|
||||
String get_executable_path() const;
|
||||
virtual String get_resource_dir() const;
|
||||
|
||||
void process_accelerometer(const Vector3& p_accelerometer);
|
||||
void process_touch(int p_what,int p_pointer, const Vector<TouchPos>& p_points);
|
||||
void push_input(const InputEvent& p_ev);
|
||||
void process_accelerometer(const Vector3 &p_accelerometer);
|
||||
void process_touch(int p_what, int p_pointer, const Vector<TouchPos> &p_points);
|
||||
void push_input(const InputEvent &p_ev);
|
||||
|
||||
virtual bool is_joy_known(int p_device);
|
||||
virtual String get_joy_guid(int p_device) const;
|
||||
bool joy_connection_changed(int p_type, const EmscriptenGamepadEvent *p_event);
|
||||
|
||||
|
||||
virtual PowerState get_power_state();
|
||||
virtual int get_power_seconds_left();
|
||||
virtual int get_power_percent_left();
|
||||
|
||||
OS_JavaScript(GFXInitFunc p_gfx_init_func,void*p_gfx_init_ud, GetDataDirFunc p_get_data_dir_func);
|
||||
OS_JavaScript(GFXInitFunc p_gfx_init_func, void *p_gfx_init_ud, GetDataDirFunc p_get_data_dir_func);
|
||||
~OS_JavaScript();
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -27,10 +27,8 @@
|
||||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/*************************************************************************/
|
||||
|
||||
|
||||
#include "core/error_macros.h"
|
||||
#include "power_javascript.h"
|
||||
|
||||
#include "core/error_macros.h"
|
||||
|
||||
bool PowerJavascript::UpdatePowerInfo() {
|
||||
// TODO Javascript implementation
|
||||
@@ -40,8 +38,7 @@ bool PowerJavascript::UpdatePowerInfo() {
|
||||
PowerState PowerJavascript::get_power_state() {
|
||||
if (UpdatePowerInfo()) {
|
||||
return power_state;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
WARN_PRINT("Power management is not implemented on this platform, defaulting to POWERSTATE_UNKNOWN");
|
||||
return POWERSTATE_UNKNOWN;
|
||||
}
|
||||
@@ -50,8 +47,7 @@ PowerState PowerJavascript::get_power_state() {
|
||||
int PowerJavascript::get_power_seconds_left() {
|
||||
if (UpdatePowerInfo()) {
|
||||
return nsecs_left;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
WARN_PRINT("Power management is not implemented on this platform, defaulting to -1");
|
||||
return -1;
|
||||
}
|
||||
@@ -60,16 +56,14 @@ int PowerJavascript::get_power_seconds_left() {
|
||||
int PowerJavascript::get_power_percent_left() {
|
||||
if (UpdatePowerInfo()) {
|
||||
return percent_left;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
WARN_PRINT("Power management is not implemented on this platform, defaulting to -1");
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
PowerJavascript::PowerJavascript() : nsecs_left(-1), percent_left(-1), power_state(POWERSTATE_UNKNOWN) {
|
||||
|
||||
PowerJavascript::PowerJavascript()
|
||||
: nsecs_left(-1), percent_left(-1), power_state(POWERSTATE_UNKNOWN) {
|
||||
}
|
||||
|
||||
PowerJavascript::~PowerJavascript() {
|
||||
|
||||
@@ -27,7 +27,6 @@
|
||||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/*************************************************************************/
|
||||
|
||||
|
||||
#ifndef PLATFORM_JAVASCRIPT_POWER_JAVASCRIPT_H_
|
||||
#define PLATFORM_JAVASCRIPT_POWER_JAVASCRIPT_H_
|
||||
|
||||
|
||||
Reference in New Issue
Block a user