diff options
author | Rémi Verschelde <rverschelde@gmail.com> | 2017-03-05 16:44:50 +0100 |
---|---|---|
committer | Rémi Verschelde <rverschelde@gmail.com> | 2017-03-05 16:44:50 +0100 |
commit | 5dbf1809c6e3e905b94b8764e99491e608122261 (patch) | |
tree | 5e5a5360db15d86d59ec8c6e4f7eb511388c5a9a /main | |
parent | 45438e9918d421b244bfd7776a30e67dc7f2d3e3 (diff) |
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
Diffstat (limited to 'main')
33 files changed, 2225 insertions, 2607 deletions
diff --git a/main/input_default.cpp b/main/input_default.cpp index a9f643c785..bc409960d6 100644 --- a/main/input_default.cpp +++ b/main/input_default.cpp @@ -27,48 +27,46 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ #include "input_default.h" -#include "servers/visual_server.h" -#include "os/os.h" #include "input_map.h" +#include "os/os.h" #include "scene/resources/texture.h" +#include "servers/visual_server.h" -void InputDefault::SpeedTrack::update(const Vector2& p_delta_p) { +void InputDefault::SpeedTrack::update(const Vector2 &p_delta_p) { uint64_t tick = OS::get_singleton()->get_ticks_usec(); - uint32_t tdiff = tick-last_tick; + uint32_t tdiff = tick - last_tick; float delta_t = tdiff / 1000000.0; - last_tick=tick; - + last_tick = tick; - accum+=p_delta_p; - accum_t+=delta_t; + accum += p_delta_p; + accum_t += delta_t; - if (accum_t>max_ref_frame*10) - accum_t=max_ref_frame*10; + if (accum_t > max_ref_frame * 10) + accum_t = max_ref_frame * 10; - while( accum_t>=min_ref_frame ) { + while (accum_t >= min_ref_frame) { float slice_t = min_ref_frame / accum_t; - Vector2 slice = accum*slice_t; - accum=accum-slice; - accum_t-=min_ref_frame; + Vector2 slice = accum * slice_t; + accum = accum - slice; + accum_t -= min_ref_frame; - speed=(slice/min_ref_frame).linear_interpolate(speed,min_ref_frame/max_ref_frame); + speed = (slice / min_ref_frame).linear_interpolate(speed, min_ref_frame / max_ref_frame); } - } void InputDefault::SpeedTrack::reset() { last_tick = OS::get_singleton()->get_ticks_usec(); - speed=Vector2(); - accum_t=0; + speed = Vector2(); + accum_t = 0; } InputDefault::SpeedTrack::SpeedTrack() { - min_ref_frame=0.1; - max_ref_frame=0.3; - reset(); + min_ref_frame = 0.1; + max_ref_frame = 0.3; + reset(); } bool InputDefault::is_key_pressed(int p_scancode) const { @@ -80,22 +78,21 @@ bool InputDefault::is_key_pressed(int p_scancode) const { bool InputDefault::is_mouse_button_pressed(int p_button) const { _THREAD_SAFE_METHOD_ - return (mouse_button_mask&(1<<p_button))!=0; + return (mouse_button_mask & (1 << p_button)) != 0; } +static int _combine_device(int p_value, int p_device) { -static int _combine_device(int p_value,int p_device) { - - return p_value|(p_device<<20); + return p_value | (p_device << 20); } -bool InputDefault::is_joy_button_pressed(int p_device, int p_button) const{ +bool InputDefault::is_joy_button_pressed(int p_device, int p_button) const { _THREAD_SAFE_METHOD_ - return joy_buttons_pressed.has(_combine_device(p_button,p_device)); + return joy_buttons_pressed.has(_combine_device(p_button, p_device)); } -bool InputDefault::is_action_pressed(const StringName& p_action) const{ +bool InputDefault::is_action_pressed(const StringName &p_action) const { return action_state.has(p_action) && action_state[p_action].pressed; #if 0 @@ -152,37 +149,36 @@ bool InputDefault::is_action_pressed(const StringName& p_action) const{ #endif } -bool InputDefault::is_action_just_pressed(const StringName& p_action) const { +bool InputDefault::is_action_just_pressed(const StringName &p_action) const { - const Map<StringName,Action>::Element *E=action_state.find(p_action); + const Map<StringName, Action>::Element *E = action_state.find(p_action); if (!E) return false; if (Engine::get_singleton()->is_in_fixed_frame()) { - return E->get().pressed && E->get().fixed_frame==Engine::get_singleton()->get_fixed_frames(); + return E->get().pressed && E->get().fixed_frame == Engine::get_singleton()->get_fixed_frames(); } else { - return E->get().pressed && E->get().idle_frame==Engine::get_singleton()->get_idle_frames(); + return E->get().pressed && E->get().idle_frame == Engine::get_singleton()->get_idle_frames(); } } -bool InputDefault::is_action_just_released(const StringName& p_action) const{ +bool InputDefault::is_action_just_released(const StringName &p_action) const { - const Map<StringName,Action>::Element *E=action_state.find(p_action); + const Map<StringName, Action>::Element *E = action_state.find(p_action); if (!E) return false; if (Engine::get_singleton()->is_in_fixed_frame()) { - return !E->get().pressed && E->get().fixed_frame==Engine::get_singleton()->get_fixed_frames(); + return !E->get().pressed && E->get().fixed_frame == Engine::get_singleton()->get_fixed_frames(); } else { - return !E->get().pressed && E->get().idle_frame==Engine::get_singleton()->get_idle_frames(); + return !E->get().pressed && E->get().idle_frame == Engine::get_singleton()->get_idle_frames(); } } - -float InputDefault::get_joy_axis(int p_device,int p_axis) const{ +float InputDefault::get_joy_axis(int p_device, int p_axis) const { _THREAD_SAFE_METHOD_ - int c = _combine_device(p_axis,p_device); + int c = _combine_device(p_axis, p_device); if (_joy_axis.has(c)) { return _joy_axis[c]; } else { @@ -222,11 +218,11 @@ float InputDefault::get_joy_vibration_duration(int p_device) { static String _hex_str(uint8_t p_byte) { - static const char* dict = "0123456789abcdef"; + static const char *dict = "0123456789abcdef"; char ret[3]; ret[2] = 0; - ret[0] = dict[p_byte>>4]; + ret[0] = dict[p_byte >> 4]; ret[1] = dict[p_byte & 0xf]; return ret; @@ -246,22 +242,21 @@ void InputDefault::joy_connection_changed(int p_idx, bool p_connected, String p_ String uidname = p_guid; if (p_guid == "") { int uidlen = MIN(p_name.length(), 16); - for (int i=0; i<uidlen; i++) { + for (int i = 0; i < uidlen; i++) { uidname = uidname + _hex_str(p_name[i]); }; }; js.uid = uidname; js.connected = true; int mapping = fallback_mapping; - for (int i=0; i < map_db.size(); i++) { + for (int i = 0; i < map_db.size(); i++) { if (js.uid == map_db[i].uid) { mapping = i; js.name = map_db[i].name; }; }; js.mapping = mapping; - } - else { + } else { js.connected = false; for (int i = 0; i < JOY_BUTTON_MAX; i++) { @@ -277,19 +272,19 @@ void InputDefault::joy_connection_changed(int p_idx, bool p_connected, String p_ emit_signal("joy_connection_changed", p_idx, p_connected); }; -Vector3 InputDefault::get_gravity() const{ +Vector3 InputDefault::get_gravity() const { _THREAD_SAFE_METHOD_ return gravity; } -Vector3 InputDefault::get_accelerometer() const{ +Vector3 InputDefault::get_accelerometer() const { _THREAD_SAFE_METHOD_ return accelerometer; } -Vector3 InputDefault::get_magnetometer() const{ +Vector3 InputDefault::get_magnetometer() const { _THREAD_SAFE_METHOD_ return magnetometer; @@ -301,16 +296,16 @@ Vector3 InputDefault::get_gyroscope() const { return gyroscope; } -void InputDefault::parse_input_event(const InputEvent& p_event) { +void InputDefault::parse_input_event(const InputEvent &p_event) { _THREAD_SAFE_METHOD_ - switch(p_event.type) { + switch (p_event.type) { case InputEvent::KEY: { if (p_event.key.echo) break; - if (p_event.key.scancode==0) + if (p_event.key.scancode == 0) break; //print_line(p_event); @@ -326,37 +321,37 @@ void InputDefault::parse_input_event(const InputEvent& p_event) { break; if (p_event.mouse_button.pressed) - mouse_button_mask|=(1<<p_event.mouse_button.button_index); + mouse_button_mask |= (1 << p_event.mouse_button.button_index); else - mouse_button_mask&=~(1<<p_event.mouse_button.button_index); + mouse_button_mask &= ~(1 << p_event.mouse_button.button_index); - if (main_loop && emulate_touch && p_event.mouse_button.button_index==1) { + if (main_loop && emulate_touch && p_event.mouse_button.button_index == 1) { InputEventScreenTouch touch_event; - touch_event.index=0; - touch_event.pressed=p_event.mouse_button.pressed; - touch_event.x=p_event.mouse_button.x; - touch_event.y=p_event.mouse_button.y; + touch_event.index = 0; + touch_event.pressed = p_event.mouse_button.pressed; + touch_event.x = p_event.mouse_button.x; + touch_event.y = p_event.mouse_button.y; InputEvent ev; - ev.type=InputEvent::SCREEN_TOUCH; - ev.screen_touch=touch_event; + ev.type = InputEvent::SCREEN_TOUCH; + ev.screen_touch = touch_event; main_loop->input_event(ev); } } break; case InputEvent::MOUSE_MOTION: { - if (main_loop && emulate_touch && p_event.mouse_motion.button_mask&1) { + if (main_loop && emulate_touch && p_event.mouse_motion.button_mask & 1) { InputEventScreenDrag drag_event; - drag_event.index=0; - drag_event.x=p_event.mouse_motion.x; - drag_event.y=p_event.mouse_motion.y; - drag_event.relative_x=p_event.mouse_motion.relative_x; - drag_event.relative_y=p_event.mouse_motion.relative_y; - drag_event.speed_x=p_event.mouse_motion.speed_x; - drag_event.speed_y=p_event.mouse_motion.speed_y; + drag_event.index = 0; + drag_event.x = p_event.mouse_motion.x; + drag_event.y = p_event.mouse_motion.y; + drag_event.relative_x = p_event.mouse_motion.relative_x; + drag_event.relative_y = p_event.mouse_motion.relative_y; + drag_event.speed_x = p_event.mouse_motion.speed_x; + drag_event.speed_y = p_event.mouse_motion.speed_y; InputEvent ev; - ev.type=InputEvent::SCREEN_DRAG; - ev.screen_drag=drag_event; + ev.type = InputEvent::SCREEN_DRAG; + ev.screen_drag = drag_event; main_loop->input_event(ev); } @@ -364,7 +359,7 @@ void InputDefault::parse_input_event(const InputEvent& p_event) { } break; case InputEvent::JOYPAD_BUTTON: { - int c = _combine_device(p_event.joy_button.button_index,p_event.device); + int c = _combine_device(p_event.joy_button.button_index, p_event.device); if (p_event.joy_button.pressed) joy_buttons_pressed.insert(c); @@ -374,33 +369,30 @@ void InputDefault::parse_input_event(const InputEvent& p_event) { case InputEvent::JOYPAD_MOTION: { set_joy_axis(p_event.device, p_event.joy_motion.axis, p_event.joy_motion.axis_value); } break; - } - if (!p_event.is_echo()) { - for (const Map<StringName,InputMap::Action>::Element *E=InputMap::get_singleton()->get_action_map().front();E;E=E->next()) { + for (const Map<StringName, InputMap::Action>::Element *E = InputMap::get_singleton()->get_action_map().front(); E; E = E->next()) { - if (InputMap::get_singleton()->event_is_action(p_event,E->key()) && is_action_pressed(E->key()) != p_event.is_pressed()) { + if (InputMap::get_singleton()->event_is_action(p_event, E->key()) && is_action_pressed(E->key()) != p_event.is_pressed()) { Action action; - action.fixed_frame=Engine::get_singleton()->get_fixed_frames(); - action.idle_frame=Engine::get_singleton()->get_idle_frames(); - action.pressed=p_event.is_pressed(); - action_state[E->key()]=action; + action.fixed_frame = Engine::get_singleton()->get_fixed_frames(); + action.idle_frame = Engine::get_singleton()->get_idle_frames(); + action.pressed = p_event.is_pressed(); + action_state[E->key()] = action; } } } if (main_loop) main_loop->input_event(p_event); - } -void InputDefault::set_joy_axis(int p_device,int p_axis,float p_value) { +void InputDefault::set_joy_axis(int p_device, int p_axis, float p_value) { _THREAD_SAFE_METHOD_ - int c = _combine_device(p_axis,p_device); - _joy_axis[c]=p_value; + int c = _combine_device(p_axis, p_device); + _joy_axis[c] = p_value; } void InputDefault::start_joy_vibration(int p_device, float p_weak_magnitude, float p_strong_magnitude, float p_duration) { @@ -426,47 +418,42 @@ void InputDefault::stop_joy_vibration(int p_device) { joy_vibration[p_device] = vibration; } -void InputDefault::set_gravity(const Vector3& p_gravity) { +void InputDefault::set_gravity(const Vector3 &p_gravity) { _THREAD_SAFE_METHOD_ - gravity=p_gravity; - + gravity = p_gravity; } -void InputDefault::set_accelerometer(const Vector3& p_accel) { +void InputDefault::set_accelerometer(const Vector3 &p_accel) { _THREAD_SAFE_METHOD_ - accelerometer=p_accel; - + accelerometer = p_accel; } -void InputDefault::set_magnetometer(const Vector3& p_magnetometer) { +void InputDefault::set_magnetometer(const Vector3 &p_magnetometer) { _THREAD_SAFE_METHOD_ - magnetometer=p_magnetometer; - + magnetometer = p_magnetometer; } -void InputDefault::set_gyroscope(const Vector3& p_gyroscope) { +void InputDefault::set_gyroscope(const Vector3 &p_gyroscope) { _THREAD_SAFE_METHOD_ - gyroscope=p_gyroscope; - + gyroscope = p_gyroscope; } void InputDefault::set_main_loop(MainLoop *p_main_loop) { - main_loop=p_main_loop; - + main_loop = p_main_loop; } -void InputDefault::set_mouse_pos(const Point2& p_posf) { +void InputDefault::set_mouse_pos(const Point2 &p_posf) { - mouse_speed_track.update(p_posf-mouse_pos); - mouse_pos=p_posf; + mouse_speed_track.update(p_posf - mouse_pos); + mouse_pos = p_posf; if (custom_cursor.is_valid()) { VisualServer::get_singleton()->cursor_set_pos(get_mouse_pos()); } @@ -483,46 +470,42 @@ Point2 InputDefault::get_last_mouse_speed() const { int InputDefault::get_mouse_button_mask() const { - return mouse_button_mask;// do not trust OS implementaiton, should remove it - OS::get_singleton()->get_mouse_button_state(); + return mouse_button_mask; // do not trust OS implementaiton, should remove it - OS::get_singleton()->get_mouse_button_state(); } -void InputDefault::warp_mouse_pos(const Vector2& p_to) { +void InputDefault::warp_mouse_pos(const Vector2 &p_to) { OS::get_singleton()->warp_mouse_pos(p_to); } - void InputDefault::iteration(float p_step) { - - } -void InputDefault::action_press(const StringName& p_action) { +void InputDefault::action_press(const StringName &p_action) { Action action; - action.fixed_frame=Engine::get_singleton()->get_fixed_frames(); - action.idle_frame=Engine::get_singleton()->get_idle_frames(); - action.pressed=true; - - action_state[p_action]=action; + action.fixed_frame = Engine::get_singleton()->get_fixed_frames(); + action.idle_frame = Engine::get_singleton()->get_idle_frames(); + action.pressed = true; + action_state[p_action] = action; } -void InputDefault::action_release(const StringName& p_action){ +void InputDefault::action_release(const StringName &p_action) { Action action; - action.fixed_frame=Engine::get_singleton()->get_fixed_frames(); - action.idle_frame=Engine::get_singleton()->get_idle_frames(); - action.pressed=false; + action.fixed_frame = Engine::get_singleton()->get_fixed_frames(); + action.idle_frame = Engine::get_singleton()->get_idle_frames(); + action.pressed = false; - action_state[p_action]=action; + action_state[p_action] = action; } void InputDefault::set_emulate_touch(bool p_emulate) { - emulate_touch=p_emulate; + emulate_touch = p_emulate; } bool InputDefault::is_emulating_touchscreen() const { @@ -530,11 +513,11 @@ bool InputDefault::is_emulating_touchscreen() const { return emulate_touch; } -void InputDefault::set_custom_mouse_cursor(const RES& p_cursor,const Vector2& p_hotspot) { - if (custom_cursor==p_cursor) +void InputDefault::set_custom_mouse_cursor(const RES &p_cursor, const Vector2 &p_hotspot) { + if (custom_cursor == p_cursor) return; - custom_cursor=p_cursor; + custom_cursor = p_cursor; if (p_cursor.is_null()) { set_mouse_mode(MOUSE_MODE_VISIBLE); @@ -544,7 +527,7 @@ void InputDefault::set_custom_mouse_cursor(const RES& p_cursor,const Vector2& p_ Rect2 region = atex.is_valid() ? atex->get_region() : Rect2(); set_mouse_mode(MOUSE_MODE_HIDDEN); VisualServer::get_singleton()->cursor_set_visible(true); - VisualServer::get_singleton()->cursor_set_texture(custom_cursor->get_rid(),p_hotspot, 0, region); + VisualServer::get_singleton()->cursor_set_texture(custom_cursor->get_rid(), p_hotspot, 0, region); VisualServer::get_singleton()->cursor_set_pos(get_mouse_pos()); } } @@ -560,13 +543,12 @@ void InputDefault::set_mouse_in_window(bool p_in_window) { set_mouse_mode(MOUSE_MODE_VISIBLE); VisualServer::get_singleton()->cursor_set_visible(false); } - } } // from github.com/gabomdq/SDL_GameControllerDB -static const char *s_ControllerMappings [] = { - #ifdef WINDOWS_ENABLED +static const char *s_ControllerMappings[] = { +#ifdef WINDOWS_ENABLED "00f00300000000000000504944564944,RetroUSB.com RetroPad,a:b1,b:b5,x:b0,y:b4,back:b2,start:b3,leftshoulder:b6,rightshoulder:b7,leftx:a0,lefty:a1,", "00f0f100000000000000504944564944,RetroUSB.com Super RetroPort,a:b1,b:b5,x:b0,y:b4,back:b2,start:b3,leftshoulder:b6,rightshoulder:b7,leftx:a0,lefty:a1,", "02200090000000000000504944564944,8Bitdo NES30 PRO USB,a:b0,b:b1,x:b3,y:b4,leftshoulder:b6,rightshoulder:b7,lefttrigger:b8,righttrigger:b9,back:b10,start:b11,leftstick:b13,rightstick:b14,leftx:a0,lefty:a1,rightx:a3,righty:a4,dpup:h0.1,dpright:h0.2,dpdown:h0.4,dpleft:h0.8,", @@ -613,9 +595,9 @@ static const char *s_ControllerMappings [] = { "ff113133000000000000504944564944,SVEN X-PAD,a:b2,b:b3,y:b1,x:b0,start:b5,back:b4,leftshoulder:b6,rightshoulder:b7,dpup:h0.1,dpleft:h0.8,dpdown:h0.4,dpright:h0.2,leftx:a0,lefty:a1,rightx:a2,righty:a4,lefttrigger:b8,righttrigger:b9,", "ffff0000000000000000504944564944,GameStop Gamepad,a:b0,b:b1,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:,leftshoulder:b4,leftstick:b10,lefttrigger:b6,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:b7,rightx:a2,righty:a3,start:b9,x:b2,y:b3,", "__XINPUT_DEVICE__,XInput Gamepad,a:b12,b:b13,x:b14,y:b15,start:b4,back:b5,leftstick:b6,rightstick:b7,leftshoulder:b8,rightshoulder:b9,dpup:b0,dpdown:b1,dpleft:b2,dpright:b3,leftx:a0,lefty:a1,rightx:a2,righty:a3,lefttrigger:a4,righttrigger:a5,", - #endif +#endif - #ifdef OSX_ENABLED +#ifdef OSX_ENABLED "0500000047532047616d657061640000,GameStop Gamepad,a:b0,b:b1,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:,leftshoulder:b4,leftstick:b10,lefttrigger:b6,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:b7,rightx:a2,righty:a3,start:b9,x:b2,y:b3,", "050000005769696d6f74652028303000,Wii Remote,a:b4,b:b5,y:b9,x:b10,start:b6,guide:b8,back:b7,dpup:b2,dpleft:b0,dpdown:b3,dpright:b1,leftx:a0,lefty:a1,lefttrigger:b12,righttrigger:,leftshoulder:b11,", "050000005769696d6f74652028313800,Wii U Pro Controller,a:b16,b:b15,x:b18,y:b17,back:b7,guide:b8,start:b6,leftstick:b23,rightstick:b24,leftshoulder:b19,rightshoulder:b20,dpup:b11,dpdown:b12,dpleft:b13,dpright:b14,leftx:a0,lefty:a1,rightx:a2,righty:a3,lefttrigger:b21,righttrigger:b22,", @@ -642,9 +624,9 @@ static const char *s_ControllerMappings [] = { "ad1b00000000000001f9000000000000,Gamestop BB-070 X360 Controller,a:b0,b:b1,back:b9,dpdown:b12,dpleft:b13,dpright:b14,dpup:b11,guide:b10,leftshoulder:b4,leftstick:b6,lefttrigger:a2,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b7,righttrigger:a5,rightx:a3,righty:a4,start:b8,x:b2,y:b3,", "b4040000000000000a01000000000000,Sega Saturn USB Gamepad,a:b0,b:b1,x:b3,y:b4,back:b5,guide:b2,start:b8,leftshoulder:b6,rightshoulder:b7,leftx:a0,lefty:a1,", "d814000000000000cecf000000000000,MC Cthulhu,leftx:,lefty:,rightx:,righty:,lefttrigger:b6,a:b1,b:b2,y:b3,x:b0,start:b9,back:b8,leftshoulder:b4,rightshoulder:b5,dpup:h0.1,dpleft:h0.8,dpdown:h0.4,dpright:h0.2,righttrigger:b7,", - #endif +#endif - #if X11_ENABLED +#if X11_ENABLED "0000000058626f782047616d65706100,Xbox Gamepad (userspace driver),a:b0,b:b1,x:b2,y:b3,start:b7,back:b6,guide:b8,dpup:h0.1,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,leftshoulder:b4,rightshoulder:b5,lefttrigger:a5,righttrigger:a4,leftstick:b9,rightstick:b10,leftx:a0,lefty:a1,rightx:a2,righty:a3,", "0300000000f000000300000000010000,RetroUSB.com RetroPad,a:b1,b:b5,x:b0,y:b4,back:b2,start:b3,leftshoulder:b6,rightshoulder:b7,leftx:a0,lefty:a1,", "0300000000f00000f100000000010000,RetroUSB.com Super RetroPort,a:b1,b:b5,x:b0,y:b4,back:b2,start:b3,leftshoulder:b6,rightshoulder:b7,leftx:a0,lefty:a1,", @@ -727,9 +709,9 @@ static const char *s_ControllerMappings [] = { "050000007e0500003003000001000000,Nintendo Wii U Pro Controller,a:b0,b:b1,x:b3,y:b2,back:b8,start:b9,guide:b10,leftshoulder:b4,rightshoulder:b5,leftstick:b11,rightstick:b12,leftx:a0,lefty:a1,rightx:a2,righty:a3,lefttrigger:b6,righttrigger:b7,dpup:b13,dpleft:b15,dpdown:b14,dpright:b16,", "05000000d6200000ad0d000001000000,Moga Pro,a:b0,b:b1,y:b3,x:b2,start:b6,leftstick:b7,rightstick:b8,leftshoulder:b4,rightshoulder:b5,dpup:h0.1,dpleft:h0.8,dpdown:h0.4,dpright:h0.2,leftx:a0,lefty:a1,rightx:a2,righty:a3,lefttrigger:a5,righttrigger:a4,", "060000004c0500006802000000010000,PS3 Controller (Bluetooth),a:b14,b:b13,y:b12,x:b15,start:b3,guide:b16,back:b0,leftstick:b1,rightstick:b2,leftshoulder:b10,rightshoulder:b11,dpup:b4,dpleft:b7,dpdown:b6,dpright:b5,leftx:a0,lefty:a1,rightx:a2,righty:a3,lefttrigger:b8,righttrigger:b9,", - #endif +#endif - #if defined(__ANDROID__) +#if defined(__ANDROID__) "Default Android Gamepad,Default Controller,leftx:a0,lefty:a1,dpdown:h0.4,rightstick:b8,rightshoulder:b10,rightx:a2,start:b6,righty:a3,dpleft:h0.8,lefttrigger:a4,x:b2,dpup:h0.1,back:b4,leftstick:b7,leftshoulder:b9,y:b3,a:b0,dpright:h0.2,righttrigger:a5,b:b1,", "47656e6572696320582d426f78207061,Logitech F-310,leftx:a0,lefty:a1,dpdown:h0.4,rightstick:b8,rightshoulder:b10,rightx:a2,start:b6,righty:a3,dpleft:h0.8,lefttrigger:a5,x:b2,dpup:h0.1,leftstick:b7,leftshoulder:b9,y:b3,a:b0,dpright:h0.2,righttrigger:a4,b:b1,", "484f524920434f2e2c4c544420205041,Hori Gem Pad 3,leftx:a0,lefty:a1,dpdown:h0.4,rightstick:b6,rightshoulder:b18,rightx:a2,start:b16,righty:a3,dpleft:h0.8,lefttrigger:b9,x:b0,dpup:h0.1,back:b15,leftstick:b4,leftshoulder:b3,y:b2,a:b1,dpright:h0.2,righttrigger:b10,b:b17,", @@ -737,9 +719,9 @@ static const char *s_ControllerMappings [] = { "4e564944494120436f72706f72617469,NVIDIA Controller,a:b0,b:b1,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,leftshoulder:b9,leftstick:b7,lefttrigger:a4,leftx:a0,lefty:a1,rightshoulder:b10,rightstick:b8,righttrigger:a5,rightx:a2,righty:a3,start:b6,x:b2,y:b3,", "532e542e442e20496e74657261637420,3dfx InterAct HammerHead FX,leftx:a0,lefty:a1,dpdown:h0.4,rightstick:b25,rightshoulder:b27,rightx:a2,start:b31,righty:a3,dpleft:h0.8,lefttrigger:b28,x:b20,dpup:h0.1,back:b30,leftstick:b22,leftshoulder:b26,y:b21,a:b23,dpright:h0.2,righttrigger:b29,b:b24,", "506572666f726d616e63652044657369,PDP Rock Candy Wireless Controller for PS3,leftx:a0,lefty:a1,dpdown:h0.4,rightstick:b6,rightshoulder:b18,rightx:a2,start:b16,righty:a3,dpleft:h0.8,lefttrigger:b9,x:b0,dpup:h0.1,back:h0.2,leftstick:b4,leftshoulder:b3,y:b2,a:b1,dpright:h0.2,righttrigger:b10,b:b17,", - #endif +#endif - #ifdef JAVASCRIPT_ENABLED +#ifdef JAVASCRIPT_ENABLED "Default HTML5 Gamepad, Default Mapping,leftx:a0,lefty:a1,dpdown:b13,rightstick:b11,rightshoulder:b5,rightx:a2,start:b9,righty:a3,dpleft:b14,lefttrigger:a6,x:b2,dpup:b12,back:b8,leftstick:b10,leftshoulder:b4,y:b3,a:b0,dpright:b15,righttrigger:a7,b:b1,", "303435652d303238652d4d6963726f73,Wired X360 Controller,leftx:a0,lefty:a1,dpdown:a7,rightstick:b10,rightshoulder:b5,rightx:a3,start:b7,righty:a4,dpleft:a6,lefttrigger:a2,x:b2,dpup:a7,back:b6,leftstick:b9,leftshoulder:b4,y:b3,a:b0,dpright:a6,righttrigger:a5,b:b1,", "303435652d303731392d58626f782033,Wireless X360 Controller,leftx:a0,lefty:a1,dpdown:b14,rightstick:b10,rightshoulder:b5,rightx:a3,start:b7,righty:a4,dpleft:b11,lefttrigger:a2,x:b2,dpup:b13,back:b6,leftstick:b9,leftshoulder:b4,y:b3,a:b0,dpright:b12,righttrigger:a5,b:b1,", @@ -747,19 +729,19 @@ static const char *s_ControllerMappings [] = { "303534632d303563342d536f6e792043,PS4 Controller USB/Linux,leftx:a0,lefty:a1,dpdown:a7,rightstick:b11,rightshoulder:b5,rightx:a2,start:b9,righty:a5,dpleft:a6,lefttrigger:a3,x:b0,dpup:a7,back:b8,leftstick:b10,leftshoulder:b4,y:b3,a:b1,dpright:a6,righttrigger:a4,b:b2,", "303534632d303563342d576972656c65,PS4 Controller USB/Win,leftx:a0,lefty:a1,dpdown:b15,rightstick:b11,rightshoulder:b5,rightx:a2,start:b9,righty:a5,lefttrigger:a3,x:b0,dpup:b14,dpleft:b16,dpright:b17,back:b8,leftstick:b10,leftshoulder:b4,y:b3,a:b1,righttrigger:b7,b:b2,", "c2a94d6963726f736f66742058626f78,Wireless X360 Controller,leftx:a0,lefty:a1,dpdown:b14,rightstick:b10,rightshoulder:b5,rightx:a3,start:b7,righty:a4,dpleft:b11,lefttrigger:a2,x:b2,dpup:b13,back:b6,leftstick:b9,leftshoulder:b4,y:b3,a:b0,dpright:b12,righttrigger:a5,b:b1,", - #endif +#endif - #ifdef UWP_ENABLED +#ifdef UWP_ENABLED "__UWP_GAMEPAD__,Xbox Controller,a:b2,b:b3,x:b4,y:b5,start:b0,back:b1,leftstick:b12,rightstick:b13,leftshoulder:b10,rightshoulder:b11,dpup:b6,dpdown:b7,dpleft:b8,dpright:b9,leftx:a0,lefty:a1,rightx:a2,righty:a3,lefttrigger:a4,righttrigger:a5,", - #endif +#endif NULL }; InputDefault::InputDefault() { - mouse_button_mask=0; - emulate_touch=false; - main_loop=NULL; + mouse_button_mask = 0; + emulate_touch = false; + main_loop = NULL; hat_map_default[HAT_UP].type = TYPE_BUTTON; hat_map_default[HAT_UP].index = JOY_DPAD_UP; @@ -783,7 +765,7 @@ InputDefault::InputDefault() { if (env_mapping != "") { Vector<String> entries = env_mapping.split("\n"); - for (int i=0; i < entries.size(); i++) { + for (int i = 0; i < entries.size(); i++) { if (entries[i] == "") continue; parse_mapping(entries[i]); @@ -797,11 +779,10 @@ InputDefault::InputDefault() { }; } - uint32_t InputDefault::joy_button(uint32_t p_last_id, int p_device, int p_button, bool p_pressed) { _THREAD_SAFE_METHOD_; - Joypad& joy = joy_names[p_device]; + Joypad &joy = joy_names[p_device]; //printf("got button %i, mapping is %i\n", p_button, joy.mapping); if (joy.last_buttons[p_button] == p_pressed) { return p_last_id; @@ -812,7 +793,7 @@ uint32_t InputDefault::joy_button(uint32_t p_last_id, int p_device, int p_button return _button_event(p_last_id, p_device, p_button, p_pressed); }; - Map<int,JoyEvent>::Element* el = map_db[joy.mapping].buttons.find(p_button); + Map<int, JoyEvent>::Element *el = map_db[joy.mapping].buttons.find(p_button); if (!el) { //don't process un-mapped events for now, it could mess things up badly for devices with additional buttons/axis //return _button_event(p_last_id, p_device, p_button, p_pressed); @@ -837,11 +818,11 @@ uint32_t InputDefault::joy_button(uint32_t p_last_id, int p_device, int p_button return p_last_id; // no event? }; -uint32_t InputDefault::joy_axis(uint32_t p_last_id, int p_device, int p_axis, const JoyAxis& p_value) { +uint32_t InputDefault::joy_axis(uint32_t p_last_id, int p_device, int p_axis, const JoyAxis &p_value) { _THREAD_SAFE_METHOD_; - Joypad& joy = joy_names[p_device]; + Joypad &joy = joy_names[p_device]; if (joy.last_axis[p_axis] == p_value.value) { return p_last_id; @@ -849,12 +830,11 @@ uint32_t InputDefault::joy_axis(uint32_t p_last_id, int p_device, int p_axis, co if (p_value.value > joy.last_axis[p_axis]) { - if (p_value.value < joy.last_axis[p_axis] + joy.filter ) { + if (p_value.value < joy.last_axis[p_axis] + joy.filter) { return p_last_id; } - } - else if (p_value.value > joy.last_axis[p_axis] - joy.filter) { + } else if (p_value.value > joy.last_axis[p_axis] - joy.filter) { return p_last_id; } @@ -874,13 +854,12 @@ uint32_t InputDefault::joy_axis(uint32_t p_last_id, int p_device, int p_axis, co return _axis_event(p_last_id, p_device, p_axis, val); }; - Map<int,JoyEvent>::Element* el = map_db[joy.mapping].axis.find(p_axis); + Map<int, JoyEvent>::Element *el = map_db[joy.mapping].axis.find(p_axis); if (!el) { //return _axis_event(p_last_id, p_device, p_axis, p_value); return p_last_id; }; - JoyEvent map = el->get(); if (map.type == TYPE_BUTTON) { @@ -903,7 +882,7 @@ uint32_t InputDefault::joy_axis(uint32_t p_last_id, int p_device, int p_axis, co p_last_id = _button_event(p_last_id, p_device, JOY_DPAD_DOWN, false); } } - if ( pressed == joy_buttons_pressed.has(_combine_device(button, p_device))) { + if (pressed == joy_buttons_pressed.has(_combine_device(button, p_device))) { return p_last_id; } return _button_event(p_last_id, p_device, button, true); @@ -920,14 +899,14 @@ uint32_t InputDefault::joy_axis(uint32_t p_last_id, int p_device, int p_axis, co p_last_id = _button_event(p_last_id, p_device, JOY_DPAD_RIGHT, false); } } - if ( pressed == joy_buttons_pressed.has(_combine_device(button, p_device))) { + if (pressed == joy_buttons_pressed.has(_combine_device(button, p_device))) { return p_last_id; } return _button_event(p_last_id, p_device, button, true); } float deadzone = p_value.min == 0 ? 0.5f : 0.0f; bool pressed = p_value.value > deadzone ? true : false; - if (pressed == joy_buttons_pressed.has(_combine_device(map.index,p_device))) { + if (pressed == joy_buttons_pressed.has(_combine_device(map.index, p_device))) { // button already pressed or released, this is an axis bounce value return p_last_id; }; @@ -936,7 +915,7 @@ uint32_t InputDefault::joy_axis(uint32_t p_last_id, int p_device, int p_axis, co if (map.type == TYPE_AXIS) { - return _axis_event(p_last_id, p_device, map.index, val ); + return _axis_event(p_last_id, p_device, map.index, val); }; //printf("invalid mapping\n"); return p_last_id; @@ -945,9 +924,9 @@ uint32_t InputDefault::joy_axis(uint32_t p_last_id, int p_device, int p_axis, co uint32_t InputDefault::joy_hat(uint32_t p_last_id, int p_device, int p_val) { _THREAD_SAFE_METHOD_; - const Joypad& joy = joy_names[p_device]; + const Joypad &joy = joy_names[p_device]; - JoyEvent* map; + JoyEvent *map; if (joy.mapping == -1) { map = hat_map_default; @@ -957,17 +936,17 @@ uint32_t InputDefault::joy_hat(uint32_t p_last_id, int p_device, int p_val) { int cur_val = joy_names[p_device].hat_current; - if ( (p_val & HAT_MASK_UP) != (cur_val & HAT_MASK_UP) ) { + if ((p_val & HAT_MASK_UP) != (cur_val & HAT_MASK_UP)) { p_last_id = _button_event(p_last_id, p_device, map[HAT_UP].index, p_val & HAT_MASK_UP); }; - if ( (p_val & HAT_MASK_RIGHT) != (cur_val & HAT_MASK_RIGHT) ) { + if ((p_val & HAT_MASK_RIGHT) != (cur_val & HAT_MASK_RIGHT)) { p_last_id = _button_event(p_last_id, p_device, map[HAT_RIGHT].index, p_val & HAT_MASK_RIGHT); }; - if ( (p_val & HAT_MASK_DOWN) != (cur_val & HAT_MASK_DOWN) ) { + if ((p_val & HAT_MASK_DOWN) != (cur_val & HAT_MASK_DOWN)) { p_last_id = _button_event(p_last_id, p_device, map[HAT_DOWN].index, p_val & HAT_MASK_DOWN); }; - if ( (p_val & HAT_MASK_LEFT) != (cur_val & HAT_MASK_LEFT) ) { + if ((p_val & HAT_MASK_LEFT) != (cur_val & HAT_MASK_LEFT)) { p_last_id = _button_event(p_last_id, p_device, map[HAT_LEFT].index, p_val & HAT_MASK_LEFT); }; @@ -999,7 +978,7 @@ uint32_t InputDefault::_axis_event(uint32_t p_last_id, int p_device, int p_axis, ievent.joy_motion.axis = p_axis; ievent.joy_motion.axis_value = p_value; - parse_input_event( ievent ); + parse_input_event(ievent); return p_last_id; }; @@ -1007,14 +986,14 @@ uint32_t InputDefault::_axis_event(uint32_t p_last_id, int p_device, int p_axis, InputDefault::JoyEvent InputDefault::_find_to_event(String p_to) { // string names of the SDL buttons in the same order as input_event.h godot buttons - static const char* buttons[] = {"a", "b", "x", "y", "leftshoulder", "rightshoulder", "lefttrigger", "righttrigger", "leftstick", "rightstick", "back", "start", "dpup", "dpdown", "dpleft", "dpright", "guide", NULL }; + static const char *buttons[] = { "a", "b", "x", "y", "leftshoulder", "rightshoulder", "lefttrigger", "righttrigger", "leftstick", "rightstick", "back", "start", "dpup", "dpdown", "dpleft", "dpright", "guide", NULL }; - static const char* axis[] = {"leftx", "lefty", "rightx", "righty", NULL }; + static const char *axis[] = { "leftx", "lefty", "rightx", "righty", NULL }; JoyEvent ret; ret.type = -1; - int i=0; + int i = 0; while (buttons[i]) { if (p_to == buttons[i]) { @@ -1070,30 +1049,30 @@ void InputDefault::parse_mapping(String p_mapping) { String etype = from.substr(0, 1); if (etype == "a") { - int aid = from.substr(1, from.length()-1).to_int(); + int aid = from.substr(1, from.length() - 1).to_int(); mapping.axis[aid] = to_event; } else if (etype == "b") { - int bid = from.substr(1, from.length()-1).to_int(); + int bid = from.substr(1, from.length() - 1).to_int(); mapping.buttons[bid] = to_event; } else if (etype == "h") { int hat_value = from.get_slice(".", 1).to_int(); switch (hat_value) { - case 1: - mapping.hat[HAT_UP] = to_event; - break; - case 2: - mapping.hat[HAT_RIGHT] = to_event; - break; - case 4: - mapping.hat[HAT_DOWN] = to_event; - break; - case 8: - mapping.hat[HAT_LEFT] = to_event; - break; + case 1: + mapping.hat[HAT_UP] = to_event; + break; + case 2: + mapping.hat[HAT_RIGHT] = to_event; + break; + case 4: + mapping.hat[HAT_DOWN] = to_event; + break; + case 8: + mapping.hat[HAT_LEFT] = to_event; + break; }; }; }; @@ -1106,21 +1085,21 @@ void InputDefault::add_joy_mapping(String p_mapping, bool p_update_existing) { if (p_update_existing) { Vector<String> entry = p_mapping.split(","); String uid = entry[0]; - for (int i=0; i<joy_names.size(); i++) { + for (int i = 0; i < joy_names.size(); i++) { if (uid == joy_names[i].uid) { - joy_names[i].mapping = map_db.size() -1; + joy_names[i].mapping = map_db.size() - 1; } } } } void InputDefault::remove_joy_mapping(String p_guid) { - for (int i=map_db.size()-1; i >= 0;i--) { + for (int i = map_db.size() - 1; i >= 0; i--) { if (p_guid == map_db[i].uid) { map_db.remove(i); } } - for (int i=0; i<joy_names.size(); i++) { + for (int i = 0; i < joy_names.size(); i++) { if (joy_names[i].uid == p_guid) { joy_names[i].mapping = -1; } @@ -1170,7 +1149,7 @@ Array InputDefault::get_connected_joypads() { return ret; } -static const char* _buttons[] = { +static const char *_buttons[] = { "Face Button Bottom", "Face Button Right", "Face Button Left", @@ -1189,7 +1168,7 @@ static const char* _buttons[] = { "DPAD Right" }; -static const char* _axes[] = { +static const char *_axes[] = { "Left Stick X", "Left Stick Y", "Right Stick X", @@ -1215,7 +1194,7 @@ int InputDefault::get_joy_button_index_from_string(String p_button) { } int InputDefault::get_unused_joy_id() { - for (int i=0;i<JOYPADS_MAX;i++) { + for (int i = 0; i < JOYPADS_MAX; i++) { if (!joy_names.has(i) || !joy_names[i].connected) { return i; } diff --git a/main/input_default.h b/main/input_default.h index 78bc0f4355..a1a055366c 100644 --- a/main/input_default.h +++ b/main/input_default.h @@ -31,18 +31,16 @@ #include "os/input.h" - class InputDefault : public Input { - GDCLASS( InputDefault, Input ); + GDCLASS(InputDefault, Input); _THREAD_SAFE_CLASS_ int mouse_button_mask; - Set<int> keys_pressed; Set<int> joy_buttons_pressed; - Map<int,float> _joy_axis; + Map<int, float> _joy_axis; //Map<StringName,int> custom_action_press; Vector3 gravity; Vector3 accelerometer; @@ -57,8 +55,7 @@ class InputDefault : public Input { bool pressed; }; - Map<StringName,Action> action_state; - + Map<StringName, Action> action_state; bool emulate_touch; @@ -80,7 +77,7 @@ class InputDefault : public Input { float min_ref_frame; float max_ref_frame; - void update(const Vector2& p_delta_p); + void update(const Vector2 &p_delta_p); void reset(); SpeedTrack(); }; @@ -101,7 +98,6 @@ class InputDefault : public Input { for (int i = 0; i < JOY_AXIS_MAX; i++) { last_axis[i] = 0.0f; - } for (int i = 0; i < JOY_BUTTON_MAX + 19; i++) { @@ -118,6 +114,7 @@ class InputDefault : public Input { Map<int, Joypad> joy_names; int fallback_mapping; RES custom_cursor; + public: enum HatMask { HAT_MASK_CENTER = 0, @@ -145,7 +142,6 @@ public: }; private: - enum JoyType { TYPE_BUTTON, TYPE_AXIS, @@ -163,8 +159,8 @@ private: String uid; String name; - Map<int,JoyEvent> buttons; - Map<int,JoyEvent> axis; + Map<int, JoyEvent> buttons; + Map<int, JoyEvent> axis; JoyEvent hat[HAT_MAX]; }; @@ -178,17 +174,14 @@ private: float _handle_deadzone(int p_device, int p_axis, float p_value); public: - - - virtual bool is_key_pressed(int p_scancode) const; virtual bool is_mouse_button_pressed(int p_button) const; virtual bool is_joy_button_pressed(int p_device, int p_button) const; - virtual bool is_action_pressed(const StringName& p_action) const; - virtual bool is_action_just_pressed(const StringName& p_action) const; - virtual bool is_action_just_released(const StringName& p_action) const; + virtual bool is_action_pressed(const StringName &p_action) const; + virtual bool is_action_just_pressed(const StringName &p_action) const; + virtual bool is_action_just_released(const StringName &p_action) const; - virtual float get_joy_axis(int p_device,int p_axis) const; + virtual float get_joy_axis(int p_device, int p_axis) const; String get_joy_name(int p_idx); virtual Array get_connected_joypads(); virtual Vector2 get_joy_vibration_strength(int p_device); @@ -206,47 +199,46 @@ public: virtual Point2 get_last_mouse_speed() const; virtual int get_mouse_button_mask() const; - virtual void warp_mouse_pos(const Vector2& p_to); - + virtual void warp_mouse_pos(const Vector2 &p_to); - void parse_input_event(const InputEvent& p_event); - void set_gravity(const Vector3& p_gravity); - void set_accelerometer(const Vector3& p_accel); - void set_magnetometer(const Vector3& p_magnetometer); - void set_gyroscope(const Vector3& p_gyroscope); - void set_joy_axis(int p_device,int p_axis,float p_value); + void parse_input_event(const InputEvent &p_event); + void set_gravity(const Vector3 &p_gravity); + void set_accelerometer(const Vector3 &p_accel); + void set_magnetometer(const Vector3 &p_magnetometer); + void set_gyroscope(const Vector3 &p_gyroscope); + void set_joy_axis(int p_device, int p_axis, float p_value); - virtual void start_joy_vibration(int p_device, float p_weak_magnitude, float p_strong_magnitude, float p_duration=0); + virtual void start_joy_vibration(int p_device, float p_weak_magnitude, float p_strong_magnitude, float p_duration = 0); virtual void stop_joy_vibration(int p_device); void set_main_loop(MainLoop *main_loop); - void set_mouse_pos(const Point2& p_posf); + void set_mouse_pos(const Point2 &p_posf); - void action_press(const StringName& p_action); - void action_release(const StringName& p_action); + void action_press(const StringName &p_action); + void action_release(const StringName &p_action); void iteration(float p_step); void set_emulate_touch(bool p_emulate); virtual bool is_emulating_touchscreen() const; - virtual void set_custom_mouse_cursor(const RES& p_cursor,const Vector2& p_hotspot=Vector2()); + virtual void set_custom_mouse_cursor(const RES &p_cursor, const Vector2 &p_hotspot = Vector2()); virtual void set_mouse_in_window(bool p_in_window); void parse_mapping(String p_mapping); uint32_t joy_button(uint32_t p_last_id, int p_device, int p_button, bool p_pressed); - uint32_t joy_axis(uint32_t p_last_id, int p_device, int p_axis, const JoyAxis& p_value); + uint32_t joy_axis(uint32_t p_last_id, int p_device, int p_axis, const JoyAxis &p_value); uint32_t joy_hat(uint32_t p_last_id, int p_device, int p_val); - virtual void add_joy_mapping(String p_mapping, bool p_update_existing=false); + virtual void add_joy_mapping(String p_mapping, bool p_update_existing = false); virtual void remove_joy_mapping(String p_guid); virtual bool is_joy_known(int p_device); virtual String get_joy_guid(int p_device) const; virtual String get_joy_button_string(int p_button); virtual String get_joy_axis_string(int p_axis); - virtual int get_joy_axis_index_from_string(String p_axis); - virtual int get_joy_button_index_from_string(String p_button); + virtual int get_joy_axis_index_from_string(String p_axis); + virtual int get_joy_button_index_from_string(String p_button); int get_unused_joy_id(); diff --git a/main/main.cpp b/main/main.cpp index 32aea6a4a5..f905e22070 100644 --- a/main/main.cpp +++ b/main/main.cpp @@ -27,31 +27,31 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ #include "main.h" -#include "os/os.h" -#include "global_config.h" -#include "splash.h" #include "core/register_core_types.h" -#include "scene/register_scene_types.h" #include "drivers/register_driver_types.h" -#include "servers/register_server_types.h" +#include "global_config.h" +#include "message_queue.h" #include "modules/register_module_types.h" +#include "os/os.h" +#include "scene/register_scene_types.h" #include "script_debugger_local.h" #include "script_debugger_remote.h" -#include "message_queue.h" +#include "servers/register_server_types.h" +#include "splash.h" #include "input_map.h" #include "io/resource_loader.h" #include "scene/main/scene_main_loop.h" #include "servers/audio_server.h" -#include "script_language.h" #include "io/resource_loader.h" +#include "script_language.h" +#include "core/io/ip.h" #include "main/tests/test_main.h" #include "os/dir_access.h" -#include "core/io/ip.h" -#include "scene/resources/packed_scene.h" #include "scene/main/viewport.h" +#include "scene/resources/packed_scene.h" #ifdef TOOLS_ENABLED #include "editor/doc/doc_data.h" @@ -62,57 +62,56 @@ #include "io/file_access_network.h" #include "servers/physics_2d_server.h" -#include "core/io/stream_peer_tcp.h" -#include "core/os/thread.h" #include "core/io/file_access_pack.h" #include "core/io/file_access_zip.h" #include "core/io/stream_peer_ssl.h" -#include "translation.h" -#include "version.h" +#include "core/io/stream_peer_tcp.h" +#include "core/os/thread.h" #include "main/input_default.h" #include "performance.h" +#include "translation.h" +#include "version.h" -static GlobalConfig *globals=NULL; -static Engine *engine=NULL; -static InputMap *input_map=NULL; -static bool _start_success=false; -static ScriptDebugger *script_debugger=NULL; -AudioServer *audio_server=NULL; +static GlobalConfig *globals = NULL; +static Engine *engine = NULL; +static InputMap *input_map = NULL; +static bool _start_success = false; +static ScriptDebugger *script_debugger = NULL; +AudioServer *audio_server = NULL; -static MessageQueue *message_queue=NULL; +static MessageQueue *message_queue = NULL; static Performance *performance = NULL; -static PackedData *packed_data=NULL; +static PackedData *packed_data = NULL; #ifdef MINIZIP_ENABLED -static ZipArchive *zip_packed_data=NULL; +static ZipArchive *zip_packed_data = NULL; #endif -static FileAccessNetworkClient *file_access_network_client=NULL; +static FileAccessNetworkClient *file_access_network_client = NULL; static TranslationServer *translation_server = NULL; static OS::VideoMode video_mode; -static bool init_maximized=false; -static bool init_windowed=false; -static bool init_fullscreen=false; -static bool init_use_custom_pos=false; -static bool debug_collisions=false; -static bool debug_navigation=false; -static int frame_delay=0; +static bool init_maximized = false; +static bool init_windowed = false; +static bool init_fullscreen = false; +static bool init_use_custom_pos = false; +static bool debug_collisions = false; +static bool debug_navigation = false; +static int frame_delay = 0; static Vector2 init_custom_pos; -static int video_driver_idx=-1; -static int audio_driver_idx=-1; +static int video_driver_idx = -1; +static int audio_driver_idx = -1; static String locale; -static bool use_debug_profiler=false; -static bool force_lowdpi=false; -static int init_screen=-1; -static bool use_vsync=true; -static bool editor=false; +static bool use_debug_profiler = false; +static bool force_lowdpi = false; +static int init_screen = -1; +static bool use_vsync = true; +static bool editor = false; -static String unescape_cmdline(const String& p_str) { +static String unescape_cmdline(const String &p_str) { - return p_str.replace("%20"," "); + return p_str.replace("%20", " "); } - //#define DEBUG_INIT #ifdef DEBUG_INIT @@ -121,10 +120,10 @@ static String unescape_cmdline(const String& p_str) { #define MAIN_PRINT(m_txt) #endif -void Main::print_help(const char* p_binary) { +void Main::print_help(const char *p_binary) { - OS::get_singleton()->print(VERSION_FULL_NAME" (c) 2008-2017 Juan Linietsky, Ariel Manzur.\n"); - OS::get_singleton()->print("Usage: %s [options] [scene]\n",p_binary); + OS::get_singleton()->print(VERSION_FULL_NAME " (c) 2008-2017 Juan Linietsky, Ariel Manzur.\n"); + OS::get_singleton()->print("Usage: %s [options] [scene]\n", p_binary); OS::get_singleton()->print("Options:\n"); OS::get_singleton()->print("\t-path [dir] : Path to a game, containing godot.cfg\n"); #ifdef TOOLS_ENABLED @@ -132,9 +131,9 @@ void Main::print_help(const char* p_binary) { #endif OS::get_singleton()->print("\t-test [test] : Run a test.\n"); OS::get_singleton()->print("\t\t("); - const char **test_names=tests_get_names(); - const char* coma = ""; - while(*test_names) { + const char **test_names = tests_get_names(); + const char *coma = ""; + while (*test_names) { OS::get_singleton()->print("%s%s", coma, *test_names); test_names++; @@ -148,23 +147,23 @@ void Main::print_help(const char* p_binary) { OS::get_singleton()->print("\t-mx\t\t Request Maximized\n"); OS::get_singleton()->print("\t-w\t\t Request Windowed\n"); OS::get_singleton()->print("\t-vd DRIVER\t : Video Driver ("); - for (int i=0;i<OS::get_singleton()->get_video_driver_count();i++) { + for (int i = 0; i < OS::get_singleton()->get_video_driver_count(); i++) { - if (i!=0) + if (i != 0) OS::get_singleton()->print(", "); - OS::get_singleton()->print("%s",OS::get_singleton()->get_video_driver_name(i)); + OS::get_singleton()->print("%s", OS::get_singleton()->get_video_driver_name(i)); } OS::get_singleton()->print(")\n"); OS::get_singleton()->print("\t-ldpi\t : Force low-dpi mode (OSX Only)\n"); OS::get_singleton()->print("\t-ad DRIVER\t : Audio Driver ("); - for (int i=0;i<OS::get_singleton()->get_audio_driver_count();i++) { + for (int i = 0; i < OS::get_singleton()->get_audio_driver_count(); i++) { - if (i!=0) + if (i != 0) OS::get_singleton()->print(", "); - OS::get_singleton()->print("%s",OS::get_singleton()->get_audio_driver_name(i)); + OS::get_singleton()->print("%s", OS::get_singleton()->get_audio_driver_name(i)); } - OS::get_singleton()->print(")\n"); + OS::get_singleton()->print(")\n"); OS::get_singleton()->print("\t-rthread <mode>\t : Render Thread Mode ('unsafe', 'safe', 'separate').\n"); OS::get_singleton()->print("\t-s,-script [script] : Run a script.\n"); OS::get_singleton()->print("\t-d,-debug : Debug (local stdout debugger).\n"); @@ -183,14 +182,13 @@ void Main::print_help(const char* p_binary) { #endif } - -Error Main::setup(const char *execpath,int argc, char *argv[],bool p_second_phase) { +Error Main::setup(const char *execpath, int argc, char *argv[], bool p_second_phase) { RID_OwnerBase::init_rid(); OS::get_singleton()->initialize_core(); - engine = memnew( Engine ); + engine = memnew(Engine); ClassDB::init(); @@ -201,17 +199,16 @@ Error Main::setup(const char *execpath,int argc, char *argv[],bool p_second_phas MAIN_PRINT("Main: Initialize Globals"); - Thread::_main_thread_id = Thread::get_caller_ID(); - globals = memnew( GlobalConfig ); - input_map = memnew( InputMap ); + globals = memnew(GlobalConfig); + input_map = memnew(InputMap); register_core_settings(); //here globals is present - translation_server = memnew( TranslationServer ); - performance = memnew( Performance ); - globals->add_singleton(GlobalConfig::Singleton("Performance",performance)); + translation_server = memnew(TranslationServer); + performance = memnew(Performance); + globals->add_singleton(GlobalConfig::Singleton("Performance", performance)); MAIN_PRINT("Main: Parse CMDLine"); @@ -219,34 +216,34 @@ Error Main::setup(const char *execpath,int argc, char *argv[],bool p_second_phas List<String> args; List<String> main_args; - for(int i=0;i<argc;i++) { + for (int i = 0; i < argc; i++) { args.push_back(String::utf8(argv[i])); } - List<String>::Element *I=args.front(); + List<String>::Element *I = args.front(); - I=args.front(); + I = args.front(); while (I) { - I->get()=unescape_cmdline(I->get().strip_escapes()); + I->get() = unescape_cmdline(I->get().strip_escapes()); //print_line("CMD: "+I->get()); - I=I->next(); + I = I->next(); } - I=args.front(); + I = args.front(); video_mode = OS::get_singleton()->get_default_video_mode(); - String video_driver=""; - String audio_driver=""; - String game_path="."; + String video_driver = ""; + String audio_driver = ""; + String game_path = "."; String debug_mode; String debug_host; String main_pack; - bool quiet_stdout=false; - int rtm=-1; + bool quiet_stdout = false; + int rtm = -1; String remotefs; String remotefs_pass; @@ -255,10 +252,10 @@ Error Main::setup(const char *execpath,int argc, char *argv[],bool p_second_phas List<String> pack_list; Vector<String> breakpoints; - bool use_custom_res=true; - bool force_res=false; + bool use_custom_res = true; + bool force_res = false; - I=args.front(); + I = args.front(); packed_data = PackedData::get_singleton(); if (!packed_data) @@ -276,233 +273,207 @@ Error Main::setup(const char *execpath,int argc, char *argv[],bool p_second_phas packed_data->add_pack_source(zip_packed_data); #endif + while (I) { - - while(I) { - - List<String>::Element *N=I->next(); + List<String>::Element *N = I->next(); if (I->get() == "-noop") { // no op - } else if (I->get()=="-h" || I->get()=="--help" || I->get()=="/?") { // resolution + } else if (I->get() == "-h" || I->get() == "--help" || I->get() == "/?") { // resolution goto error; - - } else if (I->get()=="-r") { // resolution + } else if (I->get() == "-r") { // resolution if (I->next()) { - String vm=I->next()->get(); + String vm = I->next()->get(); - if (vm.find("x")==-1) { // invalid parameter format + if (vm.find("x") == -1) { // invalid parameter format - OS::get_singleton()->print("Invalid -r argument: %s\n",vm.utf8().get_data()); + OS::get_singleton()->print("Invalid -r argument: %s\n", vm.utf8().get_data()); goto error; - - } - int w=vm.get_slice("x",0).to_int(); - int h=vm.get_slice("x",1).to_int(); + int w = vm.get_slice("x", 0).to_int(); + int h = vm.get_slice("x", 1).to_int(); - if (w==0 || h==0) { + if (w == 0 || h == 0) { OS::get_singleton()->print("Invalid -r resolution, x and y must be >0\n"); goto error; - } - video_mode.width=w; - video_mode.height=h; - force_res=true; + video_mode.width = w; + video_mode.height = h; + force_res = true; - N=I->next()->next(); + N = I->next()->next(); } else { OS::get_singleton()->print("Invalid -p argument, needs resolution\n"); goto error; - - } - } else if (I->get()=="-p") { // position + } else if (I->get() == "-p") { // position if (I->next()) { - String vm=I->next()->get(); + String vm = I->next()->get(); - if (vm.find("x")==-1) { // invalid parameter format + if (vm.find("x") == -1) { // invalid parameter format - OS::get_singleton()->print("Invalid -p argument: %s\n",vm.utf8().get_data()); + OS::get_singleton()->print("Invalid -p argument: %s\n", vm.utf8().get_data()); goto error; - - } - int x=vm.get_slice("x",0).to_int(); - int y=vm.get_slice("x",1).to_int(); + int x = vm.get_slice("x", 0).to_int(); + int y = vm.get_slice("x", 1).to_int(); - init_custom_pos=Point2(x,y); - init_use_custom_pos=true; + init_custom_pos = Point2(x, y); + init_use_custom_pos = true; - N=I->next()->next(); + N = I->next()->next(); } else { OS::get_singleton()->print("Invalid -r argument, needs position\n"); goto error; - - } + } else if (I->get() == "-mx") { // video driver - } else if (I->get()=="-mx") { // video driver + init_maximized = true; + } else if (I->get() == "-w") { // video driver - init_maximized=true; - } else if (I->get()=="-w") { // video driver + init_windowed = true; + } else if (I->get() == "-profile") { // video driver - init_windowed=true; - } else if (I->get()=="-profile") { // video driver - - use_debug_profiler=true; - } else if (I->get()=="-vd") { // video driver + use_debug_profiler = true; + } else if (I->get() == "-vd") { // video driver if (I->next()) { - video_driver=I->next()->get(); - N=I->next()->next(); + video_driver = I->next()->get(); + N = I->next()->next(); } else { OS::get_singleton()->print("Invalid -cd argument, needs driver name\n"); goto error; - } - } else if (I->get()=="-lang") { // language + } else if (I->get() == "-lang") { // language if (I->next()) { - locale=I->next()->get(); - N=I->next()->next(); + locale = I->next()->get(); + N = I->next()->next(); } else { OS::get_singleton()->print("Invalid -lang argument, needs language code\n"); goto error; - } - } else if (I->get()=="-ldpi") { // language + } else if (I->get() == "-ldpi") { // language - force_lowdpi=true; - } else if (I->get()=="-rfs") { // language + force_lowdpi = true; + } else if (I->get() == "-rfs") { // language if (I->next()) { - remotefs=I->next()->get(); - N=I->next()->next(); + remotefs = I->next()->get(); + N = I->next()->next(); } else { goto error; - } - } else if (I->get()=="-rfs_pass") { // language + } else if (I->get() == "-rfs_pass") { // language if (I->next()) { - remotefs_pass=I->next()->get(); - N=I->next()->next(); + remotefs_pass = I->next()->get(); + N = I->next()->next(); } else { goto error; - } - } else if (I->get()=="-rthread") { // language + } else if (I->get() == "-rthread") { // language if (I->next()) { - if (I->next()->get()=="safe") - rtm=OS::RENDER_THREAD_SAFE; - else if (I->next()->get()=="unsafe") - rtm=OS::RENDER_THREAD_UNSAFE; - else if (I->next()->get()=="separate") - rtm=OS::RENDER_SEPARATE_THREAD; - + if (I->next()->get() == "safe") + rtm = OS::RENDER_THREAD_SAFE; + else if (I->next()->get() == "unsafe") + rtm = OS::RENDER_THREAD_UNSAFE; + else if (I->next()->get() == "separate") + rtm = OS::RENDER_SEPARATE_THREAD; - N=I->next()->next(); + N = I->next()->next(); } else { goto error; - } - } else if (I->get()=="-ad") { // video driver + } else if (I->get() == "-ad") { // video driver if (I->next()) { - audio_driver=I->next()->get(); - N=I->next()->next(); + audio_driver = I->next()->get(); + N = I->next()->next(); } else { goto error; - } - } else if (I->get()=="-f") { // fullscreen + } else if (I->get() == "-f") { // fullscreen //video_mode.fullscreen=false; - init_fullscreen=true; - } else if (I->get()=="-e" || I->get()=="-editor") { // fonud editor + init_fullscreen = true; + } else if (I->get() == "-e" || I->get() == "-editor") { // fonud editor - editor=true; - } else if (I->get()=="-nowindow") { // fullscreen + editor = true; + } else if (I->get() == "-nowindow") { // fullscreen OS::get_singleton()->set_no_window_mode(true); - } else if (I->get()=="-quiet") { // fullscreen + } else if (I->get() == "-quiet") { // fullscreen - quiet_stdout=true; - } else if (I->get()=="-v") { // fullscreen - OS::get_singleton()->_verbose_stdout=true; - } else if (I->get()=="-path") { // resolution + quiet_stdout = true; + } else if (I->get() == "-v") { // fullscreen + OS::get_singleton()->_verbose_stdout = true; + } else if (I->get() == "-path") { // resolution if (I->next()) { String p = I->next()->get(); - if (OS::get_singleton()->set_cwd(p)==OK) { + if (OS::get_singleton()->set_cwd(p) == OK) { //nothing } else { - game_path=I->next()->get(); //use game_path instead + game_path = I->next()->get(); //use game_path instead } - N=I->next()->next(); + N = I->next()->next(); } else { goto error; - } - } else if (I->get()=="-bp") { // /breakpoints + } else if (I->get() == "-bp") { // /breakpoints if (I->next()) { String bplist = I->next()->get(); - breakpoints= bplist.split(","); - N=I->next()->next(); + breakpoints = bplist.split(","); + N = I->next()->next(); } else { goto error; - } - - } else if (I->get()=="-fdelay") { // resolution + } else if (I->get() == "-fdelay") { // resolution if (I->next()) { - frame_delay=I->next()->get().to_int(); - N=I->next()->next(); + frame_delay = I->next()->get().to_int(); + N = I->next()->next(); } else { goto error; - } - } else if (I->get()=="-timescale") { // resolution + } else if (I->get() == "-timescale") { // resolution if (I->next()) { Engine::get_singleton()->set_time_scale(I->next()->get().to_double()); - N=I->next()->next(); + N = I->next()->next(); } else { goto error; - } - } else if (I->get() == "-pack") { if (I->next()) { @@ -518,66 +489,62 @@ Error Main::setup(const char *execpath,int argc, char *argv[],bool p_second_phas if (I->next()) { - main_pack=I->next()->get(); + main_pack = I->next()->get(); N = I->next()->next(); } else { goto error; }; - } else if (I->get()=="-debug" || I->get()=="-d") { - debug_mode="local"; - } else if (I->get()=="-debugcol" || I->get()=="-dc") { - debug_collisions=true; - } else if (I->get()=="-debugnav" || I->get()=="-dn") { - debug_navigation=true; - } else if (I->get()=="-editor_scene") { + } else if (I->get() == "-debug" || I->get() == "-d") { + debug_mode = "local"; + } else if (I->get() == "-debugcol" || I->get() == "-dc") { + debug_collisions = true; + } else if (I->get() == "-debugnav" || I->get() == "-dn") { + debug_navigation = true; + } else if (I->get() == "-editor_scene") { if (I->next()) { - GlobalConfig::get_singleton()->set("editor_scene",game_path=I->next()->get()); + GlobalConfig::get_singleton()->set("editor_scene", game_path = I->next()->get()); } else { goto error; - } - } else if (I->get()=="-rdebug") { + } else if (I->get() == "-rdebug") { if (I->next()) { - debug_mode="remote"; - debug_host=I->next()->get(); - if (debug_host.find(":")==-1) { //wrong host + debug_mode = "remote"; + debug_host = I->next()->get(); + if (debug_host.find(":") == -1) { //wrong host OS::get_singleton()->print("Invalid debug host string\n"); goto error; } - N=I->next()->next(); + N = I->next()->next(); } else { goto error; - } - } else if (I->get()=="-epid") { + } else if (I->get() == "-epid") { if (I->next()) { - int editor_pid=I->next()->get().to_int(); - GlobalConfig::get_singleton()->set("editor_pid",editor_pid); - N=I->next()->next(); + int editor_pid = I->next()->get().to_int(); + GlobalConfig::get_singleton()->set("editor_pid", editor_pid); + N = I->next()->next(); } else { goto error; - } } else { //test for game path - bool gpfound=false; + bool gpfound = false; - if (!I->get().begins_with("-") && game_path=="") { - DirAccess* da = DirAccess::open(I->get()); - if (da!=NULL) { - game_path=I->get(); - gpfound=true; + if (!I->get().begins_with("-") && game_path == "") { + DirAccess *da = DirAccess::open(I->get()); + if (da != NULL) { + game_path = I->get(); + gpfound = true; memdelete(da); } - } if (!gpfound) { @@ -585,51 +552,50 @@ Error Main::setup(const char *execpath,int argc, char *argv[],bool p_second_phas } } - I=N; + I = N; } - GLOBAL_DEF("memory/multithread/thread_rid_pool_prealloc",60); + GLOBAL_DEF("memory/multithread/thread_rid_pool_prealloc", 60); - GLOBAL_DEF("network/debug/max_remote_stdout_chars_per_second",2048); - GLOBAL_DEF("network/debug/remote_port",6007); + GLOBAL_DEF("network/debug/max_remote_stdout_chars_per_second", 2048); + GLOBAL_DEF("network/debug/remote_port", 6007); if (debug_mode == "remote") { - ScriptDebuggerRemote *sdr = memnew( ScriptDebuggerRemote ); + ScriptDebuggerRemote *sdr = memnew(ScriptDebuggerRemote); uint16_t debug_port = GLOBAL_GET("network/debug/remote_port"); - if (debug_host.find(":")!=-1) { - debug_port=debug_host.get_slicec(':',1).to_int(); - debug_host=debug_host.get_slicec(':',0); + if (debug_host.find(":") != -1) { + debug_port = debug_host.get_slicec(':', 1).to_int(); + debug_host = debug_host.get_slicec(':', 0); } - Error derr = sdr->connect_to_host(debug_host,debug_port); + Error derr = sdr->connect_to_host(debug_host, debug_port); - if (derr!=OK) { + if (derr != OK) { memdelete(sdr); } else { - script_debugger=sdr; + script_debugger = sdr; } - } else if (debug_mode=="local") { - - script_debugger = memnew( ScriptDebuggerLocal ); + } else if (debug_mode == "local") { + script_debugger = memnew(ScriptDebuggerLocal); } FileAccessNetwork::configure(); - if (remotefs!="") { + if (remotefs != "") { - file_access_network_client=memnew(FileAccessNetworkClient); + file_access_network_client = memnew(FileAccessNetworkClient); int port; - if (remotefs.find(":")!=-1) { - port=remotefs.get_slicec(':',1).to_int(); - remotefs=remotefs.get_slicec(':',0); + if (remotefs.find(":") != -1) { + port = remotefs.get_slicec(':', 1).to_int(); + remotefs = remotefs.get_slicec(':', 0); } else { - port=6010; + port = 6010; } - Error err = file_access_network_client->connect(remotefs,port,remotefs_pass); + Error err = file_access_network_client->connect(remotefs, port, remotefs_pass); if (err) { - OS::get_singleton()->printerr("Could not connect to remotefs: %s:%i\n",remotefs.utf8().get_data(),port); + OS::get_singleton()->printerr("Could not connect to remotefs: %s:%i\n", remotefs.utf8().get_data(), port); goto error; } @@ -638,36 +604,34 @@ Error Main::setup(const char *execpath,int argc, char *argv[],bool p_second_phas if (script_debugger) { //there is a debugger, parse breakpoints - for(int i=0;i<breakpoints.size();i++) { + for (int i = 0; i < breakpoints.size(); i++) { String bp = breakpoints[i]; - int sp=bp.find_last(":"); - if (sp==-1) { - ERR_EXPLAIN("Invalid breakpoint: '"+bp+"', expected file:line format."); - ERR_CONTINUE(sp==-1); + int sp = bp.find_last(":"); + if (sp == -1) { + ERR_EXPLAIN("Invalid breakpoint: '" + bp + "', expected file:line format."); + ERR_CONTINUE(sp == -1); } - script_debugger->insert_breakpoint(bp.substr(sp+1,bp.length()).to_int(),bp.substr(0,sp)); + script_debugger->insert_breakpoint(bp.substr(sp + 1, bp.length()).to_int(), bp.substr(0, sp)); } } - #ifdef TOOLS_ENABLED if (editor) { packed_data->set_disabled(true); globals->set_disable_platform_override(true); - StreamPeerSSL::initialize_certs=false; //will be initialized by editor + StreamPeerSSL::initialize_certs = false; //will be initialized by editor } #endif - - if (globals->setup(game_path,main_pack)!=OK) { + if (globals->setup(game_path, main_pack) != OK) { #ifdef TOOLS_ENABLED - editor=false; + editor = false; #else - OS::get_singleton()->print("error: Couldn't load game path '%s'\n",game_path.ascii().get_data()); + OS::get_singleton()->print("error: Couldn't load game path '%s'\n", game_path.ascii().get_data()); goto error; #endif @@ -675,26 +639,26 @@ Error Main::setup(const char *execpath,int argc, char *argv[],bool p_second_phas if (editor) { main_args.push_back("-editor"); - init_maximized=true; - use_custom_res=false; + init_maximized = true; + use_custom_res = false; } if (bool(GlobalConfig::get_singleton()->get("application/disable_stdout"))) { - quiet_stdout=true; + quiet_stdout = true; } if (bool(GlobalConfig::get_singleton()->get("application/disable_stderr"))) { _print_error_enabled = false; }; if (quiet_stdout) - _print_line_enabled=false; + _print_line_enabled = false; OS::get_singleton()->set_cmdline(execpath, main_args); #ifdef TOOLS_ENABLED - if (main_args.size()==0 && (!GlobalConfig::get_singleton()->has("application/main_loop_type")) && (!GlobalConfig::get_singleton()->has("application/main_scene") || String(GlobalConfig::get_singleton()->get("application/main_scene"))=="")) - use_custom_res=false; //project manager (run without arguments) + if (main_args.size() == 0 && (!GlobalConfig::get_singleton()->has("application/main_loop_type")) && (!GlobalConfig::get_singleton()->has("application/main_scene") || String(GlobalConfig::get_singleton()->get("application/main_scene")) == "")) + use_custom_res = false; //project manager (run without arguments) #endif @@ -703,148 +667,141 @@ Error Main::setup(const char *execpath,int argc, char *argv[],bool p_second_phas else input_map->load_from_globals(); //keys for game - if (video_driver=="") // specified in godot.cfg - video_driver=GLOBAL_DEF("display/driver/name",Variant((const char*)OS::get_singleton()->get_video_driver_name(0))); + if (video_driver == "") // specified in godot.cfg + video_driver = GLOBAL_DEF("display/driver/name", Variant((const char *)OS::get_singleton()->get_video_driver_name(0))); if (!force_res && use_custom_res && globals->has("display/window/width")) - video_mode.width=globals->get("display/window/width"); - if (!force_res &&use_custom_res && globals->has("display/window/height")) - video_mode.height=globals->get("display/window/height"); + video_mode.width = globals->get("display/window/width"); + if (!force_res && use_custom_res && globals->has("display/window/height")) + video_mode.height = globals->get("display/window/height"); if (!editor && (!bool(globals->get("display/window/allow_hidpi")) || force_lowdpi)) { - OS::get_singleton()->_allow_hidpi=false; + OS::get_singleton()->_allow_hidpi = false; } if (use_custom_res && globals->has("display/window/fullscreen")) - video_mode.fullscreen=globals->get("display/window/fullscreen"); + video_mode.fullscreen = globals->get("display/window/fullscreen"); if (use_custom_res && globals->has("display/window/resizable")) - video_mode.resizable=globals->get("display/window/resizable"); + video_mode.resizable = globals->get("display/window/resizable"); if (use_custom_res && globals->has("display/window/borderless")) video_mode.borderless_window = globals->get("display/window/borderless"); if (!force_res && use_custom_res && globals->has("display/window/test_width") && globals->has("display/window/test_height")) { int tw = globals->get("display/window/test_width"); int th = globals->get("display/window/test_height"); - if (tw>0 && th>0) { - video_mode.width=tw; - video_mode.height=th; + if (tw > 0 && th > 0) { + video_mode.width = tw; + video_mode.height = th; } } - - GLOBAL_DEF("display/window/width",video_mode.width); - GLOBAL_DEF("display/window/height",video_mode.height); - GLOBAL_DEF("display/window/allow_hidpi",false); - GLOBAL_DEF("display/window/fullscreen",video_mode.fullscreen); - GLOBAL_DEF("display/window/resizable",video_mode.resizable); + GLOBAL_DEF("display/window/width", video_mode.width); + GLOBAL_DEF("display/window/height", video_mode.height); + GLOBAL_DEF("display/window/allow_hidpi", false); + GLOBAL_DEF("display/window/fullscreen", video_mode.fullscreen); + GLOBAL_DEF("display/window/resizable", video_mode.resizable); GLOBAL_DEF("display/window/borderless", video_mode.borderless_window); use_vsync = GLOBAL_DEF("display/window/use_vsync", use_vsync); - GLOBAL_DEF("display/window/test_width",0); - GLOBAL_DEF("display/window/test_height",0); - Engine::get_singleton()->_pixel_snap=GLOBAL_DEF("rendering/2d/use_pixel_snap",false); - OS::get_singleton()->_keep_screen_on=GLOBAL_DEF("display/energy_saving/keep_screen_on",true); - if (rtm==-1) { - rtm=GLOBAL_DEF("rendering/threads/thread_model",OS::RENDER_THREAD_SAFE); - if (rtm>=1) //hack for now - rtm=1; - + GLOBAL_DEF("display/window/test_width", 0); + GLOBAL_DEF("display/window/test_height", 0); + Engine::get_singleton()->_pixel_snap = GLOBAL_DEF("rendering/2d/use_pixel_snap", false); + OS::get_singleton()->_keep_screen_on = GLOBAL_DEF("display/energy_saving/keep_screen_on", true); + if (rtm == -1) { + rtm = GLOBAL_DEF("rendering/threads/thread_model", OS::RENDER_THREAD_SAFE); + if (rtm >= 1) //hack for now + rtm = 1; } - if (rtm>=0 && rtm<3) { + if (rtm >= 0 && rtm < 3) { if (editor) { - rtm=OS::RENDER_THREAD_SAFE; + rtm = OS::RENDER_THREAD_SAFE; } - OS::get_singleton()->_render_thread_mode=OS::RenderThreadMode(rtm); + OS::get_singleton()->_render_thread_mode = OS::RenderThreadMode(rtm); } - - /* Determine Video Driver */ - if (audio_driver=="") { // specified in godot.cfg - audio_driver=GLOBAL_DEF("audio/driver",OS::get_singleton()->get_audio_driver_name(0)); + if (audio_driver == "") { // specified in godot.cfg + audio_driver = GLOBAL_DEF("audio/driver", OS::get_singleton()->get_audio_driver_name(0)); } + for (int i = 0; i < OS::get_singleton()->get_video_driver_count(); i++) { - for (int i=0;i<OS::get_singleton()->get_video_driver_count();i++) { - - if (video_driver==OS::get_singleton()->get_video_driver_name(i)) { + if (video_driver == OS::get_singleton()->get_video_driver_name(i)) { - video_driver_idx=i; + video_driver_idx = i; break; } } - if (video_driver_idx<0) { + if (video_driver_idx < 0) { - OS::get_singleton()->alert( "Invalid Video Driver: "+video_driver ); + OS::get_singleton()->alert("Invalid Video Driver: " + video_driver); video_driver_idx = 0; //goto error; } - for (int i=0;i<OS::get_singleton()->get_audio_driver_count();i++) { + for (int i = 0; i < OS::get_singleton()->get_audio_driver_count(); i++) { - if (audio_driver==OS::get_singleton()->get_audio_driver_name(i)) { + if (audio_driver == OS::get_singleton()->get_audio_driver_name(i)) { - audio_driver_idx=i; + audio_driver_idx = i; break; } } - if (audio_driver_idx<0) { + if (audio_driver_idx < 0) { - OS::get_singleton()->alert( "Invalid Audio Driver: "+audio_driver ); + OS::get_singleton()->alert("Invalid Audio Driver: " + audio_driver); audio_driver_idx = 0; //goto error; } { - String orientation = GLOBAL_DEF("display/handheld/orientation","landscape"); + String orientation = GLOBAL_DEF("display/handheld/orientation", "landscape"); - if (orientation=="portrait") + if (orientation == "portrait") OS::get_singleton()->set_screen_orientation(OS::SCREEN_PORTRAIT); - else if (orientation=="reverse_landscape") + else if (orientation == "reverse_landscape") OS::get_singleton()->set_screen_orientation(OS::SCREEN_REVERSE_LANDSCAPE); - else if (orientation=="reverse_portrait") + else if (orientation == "reverse_portrait") OS::get_singleton()->set_screen_orientation(OS::SCREEN_REVERSE_PORTRAIT); - else if (orientation=="sensor_landscape") + else if (orientation == "sensor_landscape") OS::get_singleton()->set_screen_orientation(OS::SCREEN_SENSOR_LANDSCAPE); - else if (orientation=="sensor_portrait") + else if (orientation == "sensor_portrait") OS::get_singleton()->set_screen_orientation(OS::SCREEN_SENSOR_PORTRAIT); - else if (orientation=="sensor") + else if (orientation == "sensor") OS::get_singleton()->set_screen_orientation(OS::SCREEN_SENSOR); else OS::get_singleton()->set_screen_orientation(OS::SCREEN_LANDSCAPE); } - - Engine::get_singleton()->set_iterations_per_second(GLOBAL_DEF("physics/common/fixed_fps",60)); - Engine::get_singleton()->set_target_fps(GLOBAL_DEF("debug/fps/force_fps",0)); + Engine::get_singleton()->set_iterations_per_second(GLOBAL_DEF("physics/common/fixed_fps", 60)); + Engine::get_singleton()->set_target_fps(GLOBAL_DEF("debug/fps/force_fps", 0)); GLOBAL_DEF("debug/stdout/print_fps", OS::get_singleton()->is_stdout_verbose()); if (!OS::get_singleton()->_verbose_stdout) //overrided - OS::get_singleton()->_verbose_stdout=GLOBAL_DEF("debug/stdout/verbose_stdout",false); + OS::get_singleton()->_verbose_stdout = GLOBAL_DEF("debug/stdout/verbose_stdout", false); - if (frame_delay==0) { - frame_delay=GLOBAL_DEF("application/frame_delay_msec",0); + if (frame_delay == 0) { + frame_delay = GLOBAL_DEF("application/frame_delay_msec", 0); } Engine::get_singleton()->set_frame_delay(frame_delay); - message_queue = memnew( MessageQueue ); + message_queue = memnew(MessageQueue); GlobalConfig::get_singleton()->register_global_defaults(); if (p_second_phase) return setup2(); - return OK; - error: +error: - video_driver=""; - audio_driver=""; - game_path=""; + video_driver = ""; + audio_driver = ""; + game_path = ""; args.clear(); main_args.clear(); @@ -856,7 +813,7 @@ Error Main::setup(const char *execpath,int argc, char *argv[],bool p_second_phas if (input_map) memdelete(input_map); if (translation_server) - memdelete( translation_server ); + memdelete(translation_server); if (globals) memdelete(globals); if (engine) @@ -868,9 +825,9 @@ Error Main::setup(const char *execpath,int argc, char *argv[],bool p_second_phas if (file_access_network_client) memdelete(file_access_network_client); -// Note 1: *zip_packed_data live into *packed_data -// Note 2: PackedData::~PackedData destroy this. -/* + // Note 1: *zip_packed_data live into *packed_data + // Note 2: PackedData::~PackedData destroy this. + /* #ifdef MINIZIP_ENABLED if (zip_packed_data) memdelete( zip_packed_data ); @@ -883,24 +840,23 @@ Error Main::setup(const char *execpath,int argc, char *argv[],bool p_second_phas OS::get_singleton()->_cmdline.clear(); if (message_queue) - memdelete( message_queue); + memdelete(message_queue); OS::get_singleton()->finalize_core(); - locale=String(); + locale = String(); return ERR_INVALID_PARAMETER; } Error Main::setup2() { - - OS::get_singleton()->initialize(video_mode,video_driver_idx,audio_driver_idx); + OS::get_singleton()->initialize(video_mode, video_driver_idx, audio_driver_idx); if (init_use_custom_pos) { OS::get_singleton()->set_window_position(init_custom_pos); } //right moment to create and initialize the audio server - audio_server = memnew( AudioServer ); + audio_server = memnew(AudioServer); audio_server->init(); OS::get_singleton()->set_use_vsync(use_vsync); @@ -909,12 +865,12 @@ Error Main::setup2() { MAIN_PRINT("Main: Setup Logo"); - bool show_logo=true; + bool show_logo = true; #ifdef JAVASCRIPT_ENABLED - show_logo=false; + show_logo = false; #endif - if (init_screen!=-1) { + if (init_screen != -1) { OS::get_singleton()->set_current_screen(init_screen); } if (init_windowed) { @@ -926,32 +882,32 @@ Error Main::setup2() { } MAIN_PRINT("Main: Load Remaps"); - Color clear = GLOBAL_DEF("rendering/viewport/default_clear_color",Color(0.3,0.3,0.3)); + Color clear = GLOBAL_DEF("rendering/viewport/default_clear_color", Color(0.3, 0.3, 0.3)); VisualServer::get_singleton()->set_default_clear_color(clear); if (show_logo) { //boot logo! - String boot_logo_path=GLOBAL_DEF("application/boot_splash",String()); - bool boot_logo_scale=GLOBAL_DEF("application/boot_splash_fullsize",true); - GlobalConfig::get_singleton()->set_custom_property_info("application/boot_splash",PropertyInfo(Variant::STRING,"application/boot_splash",PROPERTY_HINT_FILE,"*.png")); + String boot_logo_path = GLOBAL_DEF("application/boot_splash", String()); + bool boot_logo_scale = GLOBAL_DEF("application/boot_splash_fullsize", true); + GlobalConfig::get_singleton()->set_custom_property_info("application/boot_splash", PropertyInfo(Variant::STRING, "application/boot_splash", PROPERTY_HINT_FILE, "*.png")); Image boot_logo; boot_logo_path = boot_logo_path.strip_edges(); - if (boot_logo_path!=String() /*&& FileAccess::exists(boot_logo_path)*/) { - print_line("Boot splash path: "+boot_logo_path); + if (boot_logo_path != String() /*&& FileAccess::exists(boot_logo_path)*/) { + print_line("Boot splash path: " + boot_logo_path); Error err = boot_logo.load(boot_logo_path); if (err) ERR_PRINTS("Non-existing or invalid boot splash at: " + boot_logo_path + ". Loading default splash."); } if (!boot_logo.empty()) { - OS::get_singleton()->_msec_splash=OS::get_singleton()->get_ticks_msec(); + OS::get_singleton()->_msec_splash = OS::get_singleton()->get_ticks_msec(); Color boot_bg = GLOBAL_DEF("application/boot_bg_color", clear); - VisualServer::get_singleton()->set_boot_image(boot_logo, boot_bg,boot_logo_scale); + VisualServer::get_singleton()->set_boot_image(boot_logo, boot_bg, boot_logo_scale); #ifndef TOOLS_ENABLED - //no tools, so free the boot logo (no longer needed) - //GlobalConfig::get_singleton()->set("application/boot_logo",Image()); +//no tools, so free the boot logo (no longer needed) +//GlobalConfig::get_singleton()->set("application/boot_logo",Image()); #endif } else { @@ -963,7 +919,7 @@ Error Main::setup2() { MAIN_PRINT("Main: ClearColor"); VisualServer::get_singleton()->set_default_clear_color(boot_splash_bg_color); MAIN_PRINT("Main: Image"); - VisualServer::get_singleton()->set_boot_image(splash, boot_splash_bg_color,false); + VisualServer::get_singleton()->set_boot_image(splash, boot_splash_bg_color, false); #endif } @@ -972,13 +928,13 @@ Error Main::setup2() { } MAIN_PRINT("Main: DCC"); - VisualServer::get_singleton()->set_default_clear_color(GLOBAL_DEF("rendering/viewport/default_clear_color",Color(0.3,0.3,0.3))); + VisualServer::get_singleton()->set_default_clear_color(GLOBAL_DEF("rendering/viewport/default_clear_color", Color(0.3, 0.3, 0.3))); MAIN_PRINT("Main: END"); - GLOBAL_DEF("application/icon",String()); - GlobalConfig::get_singleton()->set_custom_property_info("application/icon",PropertyInfo(Variant::STRING,"application/icon",PROPERTY_HINT_FILE,"*.png,*.webp")); + GLOBAL_DEF("application/icon", String()); + GlobalConfig::get_singleton()->set_custom_property_info("application/icon", PropertyInfo(Variant::STRING, "application/icon", PROPERTY_HINT_FILE, "*.png,*.webp")); - if (bool(GLOBAL_DEF("display/handheld/emulate_touchscreen",false))) { + if (bool(GLOBAL_DEF("display/handheld/emulate_touchscreen", false))) { if (!OS::get_singleton()->has_touchscreen_ui_hint() && Input::get_singleton() && !editor) { //only if no touchscreen ui hint, set emulation InputDefault *id = Input::get_singleton()->cast_to<InputDefault>(); @@ -987,8 +943,6 @@ Error Main::setup2() { } } - - MAIN_PRINT("Main: Load Remaps"); MAIN_PRINT("Main: Load Scene Types"); @@ -996,18 +950,18 @@ Error Main::setup2() { register_scene_types(); register_server_types(); - GLOBAL_DEF("display/mouse_cursor/custom_image",String()); - GLOBAL_DEF("display/mouse_cursor/custom_image_hotspot",Vector2()); - GlobalConfig::get_singleton()->set_custom_property_info("display/mouse_cursor/custom_image",PropertyInfo(Variant::STRING,"display/mouse_cursor/custom_image",PROPERTY_HINT_FILE,"*.png,*.webp")); + GLOBAL_DEF("display/mouse_cursor/custom_image", String()); + GLOBAL_DEF("display/mouse_cursor/custom_image_hotspot", Vector2()); + GlobalConfig::get_singleton()->set_custom_property_info("display/mouse_cursor/custom_image", PropertyInfo(Variant::STRING, "display/mouse_cursor/custom_image", PROPERTY_HINT_FILE, "*.png,*.webp")); - if (String(GlobalConfig::get_singleton()->get("display/mouse_cursor/custom_image"))!=String()) { + if (String(GlobalConfig::get_singleton()->get("display/mouse_cursor/custom_image")) != String()) { //print_line("use custom cursor"); - Ref<Texture> cursor=ResourceLoader::load(GlobalConfig::get_singleton()->get("display/mouse_cursor/custom_image")); + Ref<Texture> cursor = ResourceLoader::load(GlobalConfig::get_singleton()->get("display/mouse_cursor/custom_image")); if (cursor.is_valid()) { //print_line("loaded ok"); Vector2 hotspot = GlobalConfig::get_singleton()->get("display/mouse_cursor/custom_image_hotspot"); - Input::get_singleton()->set_custom_mouse_cursor(cursor,hotspot); + Input::get_singleton()->set_custom_mouse_cursor(cursor, hotspot); } } #ifdef TOOLS_ENABLED @@ -1028,43 +982,39 @@ Error Main::setup2() { MAIN_PRINT("Main: Load Translations"); translation_server->setup(); //register translations, load them, etc. - if (locale!="") { + if (locale != "") { translation_server->set_locale(locale); } translation_server->load_translations(); - audio_server->load_default_bus_layout(); if (use_debug_profiler && script_debugger) { script_debugger->profiling_start(); } - _start_success=true; - locale=String(); + _start_success = true; + locale = String(); ClassDB::set_current_api(ClassDB::API_NONE); //no more api is registered at this point if (OS::get_singleton()->is_stdout_verbose()) { - print_line("CORE API HASH: "+itos(ClassDB::get_api_hash(ClassDB::API_CORE))); - print_line("EDITOR API HASH: "+itos(ClassDB::get_api_hash(ClassDB::API_EDITOR))); + print_line("CORE API HASH: " + itos(ClassDB::get_api_hash(ClassDB::API_CORE))); + print_line("EDITOR API HASH: " + itos(ClassDB::get_api_hash(ClassDB::API_EDITOR))); } MAIN_PRINT("Main: Done"); return OK; - } - - bool Main::start() { - ERR_FAIL_COND_V(!_start_success,false); + ERR_FAIL_COND_V(!_start_success, false); - bool editor=false; + bool editor = false; String doc_tool; List<String> removal_docs; - bool doc_base=true; + bool doc_base = true; String game_path; String script; String test; @@ -1072,52 +1022,52 @@ bool Main::start() { String _export_platform; String _import; String _import_script; - bool noquit=false; - bool export_debug=false; + bool noquit = false; + bool export_debug = false; bool project_manager_request = false; List<String> args = OS::get_singleton()->get_cmdline_args(); - for (int i=0;i<args.size();i++) { + for (int i = 0; i < args.size(); i++) { //parameters that do not have an argument to the right - if (args[i]=="-nodocbase") { - doc_base=false; - } else if (args[i]=="-noquit") { - noquit=true; - } else if (args[i]=="-editor" || args[i]=="-e") { - editor=true; + if (args[i] == "-nodocbase") { + doc_base = false; + } else if (args[i] == "-noquit") { + noquit = true; + } else if (args[i] == "-editor" || args[i] == "-e") { + editor = true; } else if (args[i] == "-pm" || args[i] == "-project_manager") { project_manager_request = true; } else if (args[i].length() && args[i][0] != '-' && game_path == "") { - game_path=args[i]; + game_path = args[i]; } //parameters that have an argument to the right - else if (i < (args.size()-1)) { - bool parsed_pair=true; - if (args[i]=="-doctool") { - doc_tool=args[i+1]; - for(int j=i+2; j<args.size();j++) + else if (i < (args.size() - 1)) { + bool parsed_pair = true; + if (args[i] == "-doctool") { + doc_tool = args[i + 1]; + for (int j = i + 2; j < args.size(); j++) removal_docs.push_back(args[j]); - } else if (args[i]=="-script" || args[i]=="-s") { - script=args[i+1]; - } else if (args[i]=="-level" || args[i]=="-l") { - Engine::get_singleton()->_custom_level=args[i+1]; - } else if (args[i]=="-test") { - test=args[i+1]; - } else if (args[i]=="-export") { - editor=true; //needs editor - _export_platform=args[i+1]; - } else if (args[i]=="-export_debug") { - editor=true; //needs editor - _export_platform=args[i+1]; - export_debug=true; - } else if (args[i]=="-import") { - editor=true; //needs editor - _import=args[i+1]; - } else if (args[i]=="-import_script") { - editor=true; //needs editor - _import_script=args[i+1]; + } else if (args[i] == "-script" || args[i] == "-s") { + script = args[i + 1]; + } else if (args[i] == "-level" || args[i] == "-l") { + Engine::get_singleton()->_custom_level = args[i + 1]; + } else if (args[i] == "-test") { + test = args[i + 1]; + } else if (args[i] == "-export") { + editor = true; //needs editor + _export_platform = args[i + 1]; + } else if (args[i] == "-export_debug") { + editor = true; //needs editor + _export_platform = args[i + 1]; + export_debug = true; + } else if (args[i] == "-import") { + editor = true; //needs editor + _import = args[i + 1]; + } else if (args[i] == "-import_script") { + editor = true; //needs editor + _import_script = args[i + 1]; } else { // The parameter does not match anything known, don't skip the next argument - parsed_pair=false; + parsed_pair = false; } if (parsed_pair) { i++; @@ -1125,26 +1075,24 @@ bool Main::start() { } } - GLOBAL_DEF("editor/active",editor); - + GLOBAL_DEF("editor/active", editor); String main_loop_type; #ifdef TOOLS_ENABLED - if(doc_tool!="") { + if (doc_tool != "") { DocData doc; doc.generate(doc_base); DocData docsrc; - if (docsrc.load(doc_tool)==OK) { + if (docsrc.load(doc_tool) == OK) { print_line("Doc exists. Merging.."); doc.merge_from(docsrc); } else { print_line("No Doc exists. Generating empty."); - } - for(List<String>::Element* E= removal_docs.front(); E; E=E->next()) { + for (List<String>::Element *E = removal_docs.front(); E; E = E->next()) { DocData rmdoc; if (rmdoc.load(E->get()) == OK) { print_line(String("Removing classes in ") + E->get()); @@ -1157,76 +1105,72 @@ bool Main::start() { return false; } - #endif - if (_export_platform!="") { - if (game_path=="") { - String err="Command line param "; - err+=export_debug?"-export_debug":"-export"; - err+=" passed but no destination path given.\n"; - err+="Please specify the binary's file path to export to. Aborting export."; + if (_export_platform != "") { + if (game_path == "") { + String err = "Command line param "; + err += export_debug ? "-export_debug" : "-export"; + err += " passed but no destination path given.\n"; + err += "Please specify the binary's file path to export to. Aborting export."; ERR_PRINT(err.utf8().get_data()); return false; } } - if(script=="" && game_path=="" && String(GLOBAL_DEF("application/main_scene",""))!="") { - game_path=GLOBAL_DEF("application/main_scene",""); + if (script == "" && game_path == "" && String(GLOBAL_DEF("application/main_scene", "")) != "") { + game_path = GLOBAL_DEF("application/main_scene", ""); } - - MainLoop *main_loop=NULL; + MainLoop *main_loop = NULL; if (editor) { main_loop = memnew(SceneTree); }; - if (test!="") { + if (test != "") { #ifdef DEBUG_ENABLED - main_loop = test_main(test,args); + main_loop = test_main(test, args); if (!main_loop) return false; #endif - } else if (script!="") { + } else if (script != "") { Ref<Script> script_res = ResourceLoader::load(script); - ERR_EXPLAIN("Can't load script: "+script); - ERR_FAIL_COND_V(script_res.is_null(),false); - - if( script_res->can_instance() /*&& script_res->inherits_from("SceneTreeScripted")*/) { + ERR_EXPLAIN("Can't load script: " + script); + ERR_FAIL_COND_V(script_res.is_null(), false); + if (script_res->can_instance() /*&& script_res->inherits_from("SceneTreeScripted")*/) { - StringName instance_type=script_res->get_instance_base_type(); + StringName instance_type = script_res->get_instance_base_type(); Object *obj = ClassDB::instance(instance_type); - MainLoop *script_loop = obj?obj->cast_to<MainLoop>():NULL; + MainLoop *script_loop = obj ? obj->cast_to<MainLoop>() : NULL; if (!script_loop) { if (obj) memdelete(obj); - ERR_EXPLAIN("Can't load script '"+script+"', it does not inherit from a MainLoop type"); - ERR_FAIL_COND_V(!script_loop,false); + ERR_EXPLAIN("Can't load script '" + script + "', it does not inherit from a MainLoop type"); + ERR_FAIL_COND_V(!script_loop, false); } - script_loop->set_init_script(script_res); - main_loop=script_loop; + main_loop = script_loop; } else { return false; } } else { - main_loop_type=GLOBAL_DEF("application/main_loop_type",""); + main_loop_type = GLOBAL_DEF("application/main_loop_type", ""); } - if (!main_loop && main_loop_type=="") - main_loop_type="SceneTree"; + if (!main_loop && main_loop_type == "") + main_loop_type = "SceneTree"; if (!main_loop) { if (!ClassDB::class_exists(main_loop_type)) { - OS::get_singleton()->alert("godot: error: MainLoop type doesn't exist: "+main_loop_type); + OS::get_singleton()->alert("godot: error: MainLoop type doesn't exist: " + main_loop_type); return false; } else { @@ -1236,13 +1180,12 @@ bool Main::start() { ERR_FAIL_V(false); } - main_loop=ml->cast_to<MainLoop>(); + main_loop = ml->cast_to<MainLoop>(); if (!main_loop) { memdelete(ml); ERR_EXPLAIN("Invalid MainLoop type"); ERR_FAIL_V(false); - } } } @@ -1259,20 +1202,19 @@ bool Main::start() { } #ifdef TOOLS_ENABLED - - EditorNode *editor_node=NULL; + EditorNode *editor_node = NULL; if (editor) { - editor_node = memnew( EditorNode ); + editor_node = memnew(EditorNode); sml->get_root()->add_child(editor_node); //root_node->set_editor(editor); //startup editor - if (_export_platform!="") { + if (_export_platform != "") { - editor_node->export_platform(_export_platform,game_path,export_debug,"",true); - game_path=""; //no load anything + editor_node->export_platform(_export_platform, game_path, export_debug, "", true); + game_path = ""; //no load anything } } #endif @@ -1280,117 +1222,112 @@ bool Main::start() { if (!editor) { //standard helpers that can be changed from main config - String stretch_mode = GLOBAL_DEF("display/stretch/mode","disabled"); - String stretch_aspect = GLOBAL_DEF("display/stretch/aspect","ignore"); - Size2i stretch_size = Size2(GLOBAL_DEF("display/screen/width",0),GLOBAL_DEF("display/screen/height",0)); + String stretch_mode = GLOBAL_DEF("display/stretch/mode", "disabled"); + String stretch_aspect = GLOBAL_DEF("display/stretch/aspect", "ignore"); + Size2i stretch_size = Size2(GLOBAL_DEF("display/screen/width", 0), GLOBAL_DEF("display/screen/height", 0)); - SceneTree::StretchMode sml_sm=SceneTree::STRETCH_MODE_DISABLED; - if (stretch_mode=="2d") - sml_sm=SceneTree::STRETCH_MODE_2D; - else if (stretch_mode=="viewport") - sml_sm=SceneTree::STRETCH_MODE_VIEWPORT; + SceneTree::StretchMode sml_sm = SceneTree::STRETCH_MODE_DISABLED; + if (stretch_mode == "2d") + sml_sm = SceneTree::STRETCH_MODE_2D; + else if (stretch_mode == "viewport") + sml_sm = SceneTree::STRETCH_MODE_VIEWPORT; - SceneTree::StretchAspect sml_aspect=SceneTree::STRETCH_ASPECT_IGNORE; - if (stretch_aspect=="keep") - sml_aspect=SceneTree::STRETCH_ASPECT_KEEP; - else if (stretch_aspect=="keep_width") - sml_aspect=SceneTree::STRETCH_ASPECT_KEEP_WIDTH; - else if (stretch_aspect=="keep_height") - sml_aspect=SceneTree::STRETCH_ASPECT_KEEP_HEIGHT; + SceneTree::StretchAspect sml_aspect = SceneTree::STRETCH_ASPECT_IGNORE; + if (stretch_aspect == "keep") + sml_aspect = SceneTree::STRETCH_ASPECT_KEEP; + else if (stretch_aspect == "keep_width") + sml_aspect = SceneTree::STRETCH_ASPECT_KEEP_WIDTH; + else if (stretch_aspect == "keep_height") + sml_aspect = SceneTree::STRETCH_ASPECT_KEEP_HEIGHT; - sml->set_screen_stretch(sml_sm,sml_aspect,stretch_size); + sml->set_screen_stretch(sml_sm, sml_aspect, stretch_size); - sml->set_auto_accept_quit(GLOBAL_DEF("application/auto_accept_quit",true)); - sml->set_quit_on_go_back(GLOBAL_DEF("application/quit_on_go_back",true)); + sml->set_auto_accept_quit(GLOBAL_DEF("application/auto_accept_quit", true)); + sml->set_quit_on_go_back(GLOBAL_DEF("application/quit_on_go_back", true)); String appname = GlobalConfig::get_singleton()->get("application/name"); appname = TranslationServer::get_singleton()->translate(appname); OS::get_singleton()->set_window_title(appname); - int shadow_atlas_size = GLOBAL_DEF("rendering/shadow_atlas/size",2048); - int shadow_atlas_q0_subdiv = GLOBAL_DEF("rendering/shadow_atlas/quadrant_0_subdiv",2); - int shadow_atlas_q1_subdiv = GLOBAL_DEF("rendering/shadow_atlas/quadrant_1_subdiv",2); - int shadow_atlas_q2_subdiv = GLOBAL_DEF("rendering/shadow_atlas/quadrant_2_subdiv",3); - int shadow_atlas_q3_subdiv = GLOBAL_DEF("rendering/shadow_atlas/quadrant_3_subdiv",4); + int shadow_atlas_size = GLOBAL_DEF("rendering/shadow_atlas/size", 2048); + int shadow_atlas_q0_subdiv = GLOBAL_DEF("rendering/shadow_atlas/quadrant_0_subdiv", 2); + int shadow_atlas_q1_subdiv = GLOBAL_DEF("rendering/shadow_atlas/quadrant_1_subdiv", 2); + int shadow_atlas_q2_subdiv = GLOBAL_DEF("rendering/shadow_atlas/quadrant_2_subdiv", 3); + int shadow_atlas_q3_subdiv = GLOBAL_DEF("rendering/shadow_atlas/quadrant_3_subdiv", 4); sml->get_root()->set_shadow_atlas_size(shadow_atlas_size); - sml->get_root()->set_shadow_atlas_quadrant_subdiv(0,Viewport::ShadowAtlasQuadrantSubdiv(shadow_atlas_q0_subdiv)); - sml->get_root()->set_shadow_atlas_quadrant_subdiv(1,Viewport::ShadowAtlasQuadrantSubdiv(shadow_atlas_q1_subdiv)); - sml->get_root()->set_shadow_atlas_quadrant_subdiv(2,Viewport::ShadowAtlasQuadrantSubdiv(shadow_atlas_q2_subdiv)); - sml->get_root()->set_shadow_atlas_quadrant_subdiv(3,Viewport::ShadowAtlasQuadrantSubdiv(shadow_atlas_q3_subdiv)); + sml->get_root()->set_shadow_atlas_quadrant_subdiv(0, Viewport::ShadowAtlasQuadrantSubdiv(shadow_atlas_q0_subdiv)); + sml->get_root()->set_shadow_atlas_quadrant_subdiv(1, Viewport::ShadowAtlasQuadrantSubdiv(shadow_atlas_q1_subdiv)); + sml->get_root()->set_shadow_atlas_quadrant_subdiv(2, Viewport::ShadowAtlasQuadrantSubdiv(shadow_atlas_q2_subdiv)); + sml->get_root()->set_shadow_atlas_quadrant_subdiv(3, Viewport::ShadowAtlasQuadrantSubdiv(shadow_atlas_q3_subdiv)); } else { - GLOBAL_DEF("display/stretch/mode","disabled"); - GlobalConfig::get_singleton()->set_custom_property_info("display/stretch/mode",PropertyInfo(Variant::STRING,"display/stretch/mode",PROPERTY_HINT_ENUM,"disabled,2d,viewport")); - GLOBAL_DEF("display/stretch/aspect","ignore"); - GlobalConfig::get_singleton()->set_custom_property_info("display/stretch/aspect",PropertyInfo(Variant::STRING,"display/stretch/aspect",PROPERTY_HINT_ENUM,"ignore,keep,keep_width,keep_height")); - sml->set_auto_accept_quit(GLOBAL_DEF("application/auto_accept_quit",true)); - sml->set_quit_on_go_back(GLOBAL_DEF("application/quit_on_go_back",true)); - - GLOBAL_DEF("rendering/shadow_atlas/size",2048); - GlobalConfig::get_singleton()->set_custom_property_info("rendering/shadow_atlas/size",PropertyInfo(Variant::INT,"rendering/shadow_atlas/size",PROPERTY_HINT_RANGE,"256,16384")); - - GLOBAL_DEF("rendering/shadow_atlas/quadrant_0_subdiv",2); - GLOBAL_DEF("rendering/shadow_atlas/quadrant_1_subdiv",2); - GLOBAL_DEF("rendering/shadow_atlas/quadrant_2_subdiv",3); - GLOBAL_DEF("rendering/shadow_atlas/quadrant_3_subdiv",4); - GlobalConfig::get_singleton()->set_custom_property_info("rendering/shadow_atlas/quadrant_0_subdiv",PropertyInfo(Variant::INT,"rendering/shadow_atlas/quadrant_0_subdiv",PROPERTY_HINT_ENUM,"Disabled,1 Shadow,4 Shadows,16 Shadows,64 Shadows,256 Shadows,1024 Shadows")); - GlobalConfig::get_singleton()->set_custom_property_info("rendering/shadow_atlas/quadrant_1_subdiv",PropertyInfo(Variant::INT,"rendering/shadow_atlas/quadrant_1_subdiv",PROPERTY_HINT_ENUM,"Disabled,1 Shadow,4 Shadows,16 Shadows,64 Shadows,256 Shadows,1024 Shadows")); - GlobalConfig::get_singleton()->set_custom_property_info("rendering/shadow_atlas/quadrant_2_subdiv",PropertyInfo(Variant::INT,"rendering/shadow_atlas/quadrant_2_subdiv",PROPERTY_HINT_ENUM,"Disabled,1 Shadow,4 Shadows,16 Shadows,64 Shadows,256 Shadows,1024 Shadows")); - GlobalConfig::get_singleton()->set_custom_property_info("rendering/shadow_atlas/quadrant_3_subdiv",PropertyInfo(Variant::INT,"rendering/shadow_atlas/quadrant_3_subdiv",PROPERTY_HINT_ENUM,"Disabled,1 Shadow,4 Shadows,16 Shadows,64 Shadows,256 Shadows,1024 Shadows")); + GLOBAL_DEF("display/stretch/mode", "disabled"); + GlobalConfig::get_singleton()->set_custom_property_info("display/stretch/mode", PropertyInfo(Variant::STRING, "display/stretch/mode", PROPERTY_HINT_ENUM, "disabled,2d,viewport")); + GLOBAL_DEF("display/stretch/aspect", "ignore"); + GlobalConfig::get_singleton()->set_custom_property_info("display/stretch/aspect", PropertyInfo(Variant::STRING, "display/stretch/aspect", PROPERTY_HINT_ENUM, "ignore,keep,keep_width,keep_height")); + sml->set_auto_accept_quit(GLOBAL_DEF("application/auto_accept_quit", true)); + sml->set_quit_on_go_back(GLOBAL_DEF("application/quit_on_go_back", true)); + + GLOBAL_DEF("rendering/shadow_atlas/size", 2048); + GlobalConfig::get_singleton()->set_custom_property_info("rendering/shadow_atlas/size", PropertyInfo(Variant::INT, "rendering/shadow_atlas/size", PROPERTY_HINT_RANGE, "256,16384")); + + GLOBAL_DEF("rendering/shadow_atlas/quadrant_0_subdiv", 2); + GLOBAL_DEF("rendering/shadow_atlas/quadrant_1_subdiv", 2); + GLOBAL_DEF("rendering/shadow_atlas/quadrant_2_subdiv", 3); + GLOBAL_DEF("rendering/shadow_atlas/quadrant_3_subdiv", 4); + GlobalConfig::get_singleton()->set_custom_property_info("rendering/shadow_atlas/quadrant_0_subdiv", PropertyInfo(Variant::INT, "rendering/shadow_atlas/quadrant_0_subdiv", PROPERTY_HINT_ENUM, "Disabled,1 Shadow,4 Shadows,16 Shadows,64 Shadows,256 Shadows,1024 Shadows")); + GlobalConfig::get_singleton()->set_custom_property_info("rendering/shadow_atlas/quadrant_1_subdiv", PropertyInfo(Variant::INT, "rendering/shadow_atlas/quadrant_1_subdiv", PROPERTY_HINT_ENUM, "Disabled,1 Shadow,4 Shadows,16 Shadows,64 Shadows,256 Shadows,1024 Shadows")); + GlobalConfig::get_singleton()->set_custom_property_info("rendering/shadow_atlas/quadrant_2_subdiv", PropertyInfo(Variant::INT, "rendering/shadow_atlas/quadrant_2_subdiv", PROPERTY_HINT_ENUM, "Disabled,1 Shadow,4 Shadows,16 Shadows,64 Shadows,256 Shadows,1024 Shadows")); + GlobalConfig::get_singleton()->set_custom_property_info("rendering/shadow_atlas/quadrant_3_subdiv", PropertyInfo(Variant::INT, "rendering/shadow_atlas/quadrant_3_subdiv", PROPERTY_HINT_ENUM, "Disabled,1 Shadow,4 Shadows,16 Shadows,64 Shadows,256 Shadows,1024 Shadows")); } - String local_game_path; - if (game_path!="" && !project_manager_request) { + if (game_path != "" && !project_manager_request) { - local_game_path=game_path.replace("\\","/"); + local_game_path = game_path.replace("\\", "/"); if (!local_game_path.begins_with("res://")) { - bool absolute=(local_game_path.size()>1) && (local_game_path[0]=='/' || local_game_path[1]==':'); + bool absolute = (local_game_path.size() > 1) && (local_game_path[0] == '/' || local_game_path[1] == ':'); if (!absolute) { if (GlobalConfig::get_singleton()->is_using_datapack()) { - local_game_path="res://"+local_game_path; + local_game_path = "res://" + local_game_path; } else { - int sep=local_game_path.find_last("/"); + int sep = local_game_path.find_last("/"); - if (sep==-1) { + if (sep == -1) { DirAccess *da = DirAccess::create(DirAccess::ACCESS_FILESYSTEM); - local_game_path=da->get_current_dir()+"/"+local_game_path; - memdelete(da) ; + local_game_path = da->get_current_dir() + "/" + local_game_path; + memdelete(da); } else { - DirAccess *da = DirAccess::open(local_game_path.substr(0,sep)); + DirAccess *da = DirAccess::open(local_game_path.substr(0, sep)); if (da) { - local_game_path=da->get_current_dir()+"/"+local_game_path.substr(sep+1,local_game_path.length()); + local_game_path = da->get_current_dir() + "/" + local_game_path.substr(sep + 1, local_game_path.length()); memdelete(da); } } } - } } - local_game_path=GlobalConfig::get_singleton()->localize_path(local_game_path); + local_game_path = GlobalConfig::get_singleton()->localize_path(local_game_path); #ifdef TOOLS_ENABLED if (editor) { - - if (_import!="") { + if (_import != "") { //editor_node->import_scene(_import,local_game_path,_import_script); if (!noquit) sml->quit(); - game_path=""; //no load anything + game_path = ""; //no load anything } else { Error serr = editor_node->load_scene(local_game_path); - - } OS::get_singleton()->set_context(OS::CONTEXT_EDITOR); @@ -1400,71 +1337,70 @@ bool Main::start() { } if (!project_manager_request && !editor) { - if (game_path!="" || script!="") { + if (game_path != "" || script != "") { //autoload List<PropertyInfo> props; GlobalConfig::get_singleton()->get_property_list(&props); //first pass, add the constants so they exist before any script is loaded - for(List<PropertyInfo>::Element *E=props.front();E;E=E->next()) { + for (List<PropertyInfo>::Element *E = props.front(); E; E = E->next()) { String s = E->get().name; if (!s.begins_with("autoload/")) continue; - String name = s.get_slicec('/',1); + String name = s.get_slicec('/', 1); String path = GlobalConfig::get_singleton()->get(s); - bool global_var=false; + bool global_var = false; if (path.begins_with("*")) { - global_var=true; + global_var = true; } if (global_var) { - for(int i=0;i<ScriptServer::get_language_count();i++) { - ScriptServer::get_language(i)->add_global_constant(name,Variant()); + for (int i = 0; i < ScriptServer::get_language_count(); i++) { + ScriptServer::get_language(i)->add_global_constant(name, Variant()); } } - } //second pass, load into global constants - List<Node*> to_add; - for(List<PropertyInfo>::Element *E=props.front();E;E=E->next()) { + List<Node *> to_add; + for (List<PropertyInfo>::Element *E = props.front(); E; E = E->next()) { String s = E->get().name; if (!s.begins_with("autoload/")) continue; - String name = s.get_slicec('/',1); + String name = s.get_slicec('/', 1); String path = GlobalConfig::get_singleton()->get(s); - bool global_var=false; + bool global_var = false; if (path.begins_with("*")) { - global_var=true; - path=path.substr(1,path.length()-1); + global_var = true; + path = path.substr(1, path.length() - 1); } RES res = ResourceLoader::load(path); - ERR_EXPLAIN("Can't autoload: "+path); + ERR_EXPLAIN("Can't autoload: " + path); ERR_CONTINUE(res.is_null()); - Node *n=NULL; + Node *n = NULL; if (res->is_class("PackedScene")) { Ref<PackedScene> ps = res; - n=ps->instance(); + n = ps->instance(); } else if (res->is_class("Script")) { Ref<Script> s = res; StringName ibt = s->get_instance_base_type(); - bool valid_type = ClassDB::is_parent_class(ibt,"Node"); - ERR_EXPLAIN("Script does not inherit a Node: "+path); - ERR_CONTINUE( !valid_type ); + bool valid_type = ClassDB::is_parent_class(ibt, "Node"); + ERR_EXPLAIN("Script does not inherit a Node: " + path); + ERR_CONTINUE(!valid_type); Object *obj = ClassDB::instance(ibt); - ERR_EXPLAIN("Cannot instance script for autoload, expected 'Node' inheritance, got: "+String(ibt)); - ERR_CONTINUE( obj==NULL ); + ERR_EXPLAIN("Cannot instance script for autoload, expected 'Node' inheritance, got: " + String(ibt)); + ERR_CONTINUE(obj == NULL); n = obj->cast_to<Node>(); n->set_script(s.get_ref_ptr()); } - ERR_EXPLAIN("Path in autoload not a node or script: "+path); + ERR_EXPLAIN("Path in autoload not a node or script: " + path); ERR_CONTINUE(!n); n->set_name(name); @@ -1473,35 +1409,34 @@ bool Main::start() { to_add.push_back(n); if (global_var) { - for(int i=0;i<ScriptServer::get_language_count();i++) { - ScriptServer::get_language(i)->add_global_constant(name,n); + for (int i = 0; i < ScriptServer::get_language_count(); i++) { + ScriptServer::get_language(i)->add_global_constant(name, n); } } - } - for(List<Node*>::Element *E=to_add.front();E;E=E->next()) { + for (List<Node *>::Element *E = to_add.front(); E; E = E->next()) { sml->get_root()->add_child(E->get()); } //singletons } - if (game_path!="") { - Node *scene=NULL; + if (game_path != "") { + Node *scene = NULL; Ref<PackedScene> scenedata = ResourceLoader::load(local_game_path); if (scenedata.is_valid()) - scene=scenedata->instance(); + scene = scenedata->instance(); - ERR_EXPLAIN("Failed loading scene: "+local_game_path); - ERR_FAIL_COND_V(!scene,false) + ERR_EXPLAIN("Failed loading scene: " + local_game_path); + ERR_FAIL_COND_V(!scene, false) //sml->get_root()->add_child(scene); sml->add_current_scene(scene); - String iconpath = GLOBAL_DEF("application/icon","Variant()"); - if (iconpath!="") { + String iconpath = GLOBAL_DEF("application/icon", "Variant()"); + if (iconpath != "") { Image icon; - if (icon.load(iconpath)==OK) + if (icon.load(iconpath) == OK) OS::get_singleton()->set_icon(icon); } } @@ -1529,10 +1464,10 @@ bool Main::start() { }; } */ - if (project_manager_request || (script=="" && test=="" && game_path=="" && !editor)) { + if (project_manager_request || (script == "" && test == "" && game_path == "" && !editor)) { - ProjectManager *pmanager = memnew( ProjectManager ); - ProgressDialog *progress_dialog = memnew( ProgressDialog ); + ProjectManager *pmanager = memnew(ProjectManager); + ProgressDialog *progress_dialog = memnew(ProgressDialog); pmanager->add_child(progress_dialog); sml->get_root()->add_child(pmanager); OS::get_singleton()->set_context(OS::CONTEXT_PROJECTMAN); @@ -1541,57 +1476,56 @@ bool Main::start() { #endif } - OS::get_singleton()->set_main_loop( main_loop ); + OS::get_singleton()->set_main_loop(main_loop); return true; } -uint64_t Main::last_ticks=0; -uint64_t Main::target_ticks=0; -float Main::time_accum=0; -uint32_t Main::frames=0; -uint32_t Main::frame=0; +uint64_t Main::last_ticks = 0; +uint64_t Main::target_ticks = 0; +float Main::time_accum = 0; +uint32_t Main::frames = 0; +uint32_t Main::frame = 0; bool Main::force_redraw_requested = false; //for performance metrics -static uint64_t fixed_process_max=0; -static uint64_t idle_process_max=0; - +static uint64_t fixed_process_max = 0; +static uint64_t idle_process_max = 0; bool Main::iteration() { - uint64_t ticks=OS::get_singleton()->get_ticks_usec(); - uint64_t ticks_elapsed=ticks-last_ticks; + uint64_t ticks = OS::get_singleton()->get_ticks_usec(); + uint64_t ticks_elapsed = ticks - last_ticks; - double step=(double)ticks_elapsed / 1000000.0; - float frame_slice=1.0/Engine::get_singleton()->get_iterations_per_second(); + double step = (double)ticks_elapsed / 1000000.0; + float frame_slice = 1.0 / Engine::get_singleton()->get_iterations_per_second(); /* if (time_accum+step < frame_slice) return false; */ - uint64_t fixed_process_ticks=0; - uint64_t idle_process_ticks=0; + uint64_t fixed_process_ticks = 0; + uint64_t idle_process_ticks = 0; - frame+=ticks_elapsed; + frame += ticks_elapsed; - last_ticks=ticks; + last_ticks = ticks; - if (step>frame_slice*8) - step=frame_slice*8; + if (step > frame_slice * 8) + step = frame_slice * 8; - time_accum+=step; + time_accum += step; float time_scale = Engine::get_singleton()->get_time_scale(); - bool exit=false; + bool exit = false; int iters = 0; - Engine::get_singleton()->_in_fixed=true; + Engine::get_singleton()->_in_fixed = true; - while(time_accum>frame_slice) { + while (time_accum > frame_slice) { uint64_t fixed_begin = OS::get_singleton()->get_ticks_usec(); @@ -1601,39 +1535,38 @@ bool Main::iteration() { Physics2DServer::get_singleton()->sync(); Physics2DServer::get_singleton()->flush_queries(); - if (OS::get_singleton()->get_main_loop()->iteration( frame_slice*time_scale )) { - exit=true; + if (OS::get_singleton()->get_main_loop()->iteration(frame_slice * time_scale)) { + exit = true; break; } message_queue->flush(); - PhysicsServer::get_singleton()->step(frame_slice*time_scale); + PhysicsServer::get_singleton()->step(frame_slice * time_scale); Physics2DServer::get_singleton()->end_sync(); - Physics2DServer::get_singleton()->step(frame_slice*time_scale); + Physics2DServer::get_singleton()->step(frame_slice * time_scale); - time_accum-=frame_slice; + time_accum -= frame_slice; message_queue->flush(); /* if (AudioServer::get_singleton()) AudioServer::get_singleton()->update(); */ - fixed_process_ticks=MAX(fixed_process_ticks,OS::get_singleton()->get_ticks_usec()-fixed_begin); // keep the largest one for reference - fixed_process_max=MAX(OS::get_singleton()->get_ticks_usec()-fixed_begin,fixed_process_max); + fixed_process_ticks = MAX(fixed_process_ticks, OS::get_singleton()->get_ticks_usec() - fixed_begin); // keep the largest one for reference + fixed_process_max = MAX(OS::get_singleton()->get_ticks_usec() - fixed_begin, fixed_process_max); iters++; Engine::get_singleton()->_fixed_frames++; } - Engine::get_singleton()->_in_fixed=false; + Engine::get_singleton()->_in_fixed = false; uint64_t idle_begin = OS::get_singleton()->get_ticks_usec(); - OS::get_singleton()->get_main_loop()->idle( step*time_scale ); + OS::get_singleton()->get_main_loop()->idle(step * time_scale); message_queue->flush(); - VisualServer::get_singleton()->sync(); //sync if still drawing from previous frames. if (OS::get_singleton()->can_draw()) { @@ -1653,41 +1586,39 @@ bool Main::iteration() { if (AudioServer::get_singleton()) AudioServer::get_singleton()->update(); - idle_process_ticks=OS::get_singleton()->get_ticks_usec()-idle_begin; - idle_process_max=MAX(idle_process_ticks,idle_process_max); + idle_process_ticks = OS::get_singleton()->get_ticks_usec() - idle_begin; + idle_process_max = MAX(idle_process_ticks, idle_process_max); uint64_t frame_time = OS::get_singleton()->get_ticks_usec() - ticks; - for(int i=0;i<ScriptServer::get_language_count();i++) { + for (int i = 0; i < ScriptServer::get_language_count(); i++) { ScriptServer::get_language(i)->frame(); } if (script_debugger) { if (script_debugger->is_profiling()) { - script_debugger->profiling_set_frame_times(USEC_TO_SEC(frame_time),USEC_TO_SEC(idle_process_ticks),USEC_TO_SEC(fixed_process_ticks),frame_slice); + script_debugger->profiling_set_frame_times(USEC_TO_SEC(frame_time), USEC_TO_SEC(idle_process_ticks), USEC_TO_SEC(fixed_process_ticks), frame_slice); } script_debugger->idle_poll(); } - //x11_delay_usec(10000); frames++; Engine::get_singleton()->_idle_frames++; - if (frame>1000000) { + if (frame > 1000000) { if (GLOBAL_DEF("debug/stdout/print_fps", OS::get_singleton()->is_stdout_verbose())) { - print_line("FPS: "+itos(frames)); + print_line("FPS: " + itos(frames)); }; - Engine::get_singleton()->_fps=frames; + Engine::get_singleton()->_fps = frames; performance->set_process_time(USEC_TO_SEC(idle_process_max)); performance->set_fixed_process_time(USEC_TO_SEC(fixed_process_max)); - idle_process_max=0; - fixed_process_max=0; + idle_process_max = 0; + fixed_process_max = 0; - - frame%=1000000; - frames=0; + frame %= 1000000; + frames = 0; } if (OS::get_singleton()->is_in_low_processor_usage_mode() || !OS::get_singleton()->can_draw()) @@ -1695,17 +1626,17 @@ bool Main::iteration() { else { uint32_t frame_delay = Engine::get_singleton()->get_frame_delay(); if (frame_delay) - OS::get_singleton()->delay_usec( Engine::get_singleton()->get_frame_delay()*1000 ); + OS::get_singleton()->delay_usec(Engine::get_singleton()->get_frame_delay() * 1000); } int target_fps = Engine::get_singleton()->get_target_fps(); - if (target_fps>0) { - uint64_t time_step = 1000000L/target_fps; + if (target_fps > 0) { + uint64_t time_step = 1000000L / target_fps; target_ticks += time_step; uint64_t current_ticks = OS::get_singleton()->get_ticks_usec(); - if (current_ticks<target_ticks) OS::get_singleton()->delay_usec(target_ticks-current_ticks); + if (current_ticks < target_ticks) OS::get_singleton()->delay_usec(target_ticks - current_ticks); current_ticks = OS::get_singleton()->get_ticks_usec(); - target_ticks = MIN(MAX(target_ticks,current_ticks-time_step),current_ticks+time_step); + target_ticks = MIN(MAX(target_ticks, current_ticks - time_step), current_ticks + time_step); } return exit; @@ -1716,7 +1647,6 @@ void Main::force_redraw() { force_redraw_requested = true; }; - void Main::cleanup() { ERR_FAIL_COND(!_start_success); @@ -1732,14 +1662,13 @@ void Main::cleanup() { OS::get_singleton()->delete_main_loop(); OS::get_singleton()->_cmdline.clear(); - OS::get_singleton()->_execpath=""; - OS::get_singleton()->_local_clipboard=""; + OS::get_singleton()->_execpath = ""; + OS::get_singleton()->_local_clipboard = ""; if (audio_server) { memdelete(audio_server); } - #ifdef TOOLS_ENABLED EditorNode::unregister_editor_types(); #endif @@ -1751,7 +1680,6 @@ void Main::cleanup() { OS::get_singleton()->finalize(); - if (packed_data) memdelete(packed_data); if (file_access_network_client) @@ -1761,16 +1689,13 @@ void Main::cleanup() { if (input_map) memdelete(input_map); if (translation_server) - memdelete( translation_server ); + memdelete(translation_server); if (globals) memdelete(globals); if (engine) memdelete(engine); - - - - memdelete( message_queue ); + memdelete(message_queue); unregister_core_driver_types(); unregister_core_types(); @@ -1778,6 +1703,4 @@ void Main::cleanup() { //PerformanceMetrics::finish(); OS::get_singleton()->clear_last_error(); OS::get_singleton()->finalize_core(); - - } diff --git a/main/main.h b/main/main.h index 42c8a984bf..dadf45dfde 100644 --- a/main/main.h +++ b/main/main.h @@ -36,19 +36,18 @@ #include "error_list.h" #include "typedefs.h" - class Main { - static void print_help(const char* p_binary); + static void print_help(const char *p_binary); static uint64_t last_ticks; static uint64_t target_ticks; static float time_accum; static uint32_t frames; static uint32_t frame; static bool force_redraw_requested; -public: - static Error setup(const char *execpath,int argc, char *argv[],bool p_second_phase=true); +public: + static Error setup(const char *execpath, int argc, char *argv[], bool p_second_phase = true); static Error setup2(); static bool start(); static bool iteration(); diff --git a/main/performance.cpp b/main/performance.cpp index bc5d8c33c4..d566bc325f 100644 --- a/main/performance.cpp +++ b/main/performance.cpp @@ -27,57 +27,53 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ #include "performance.h" +#include "message_queue.h" #include "os/os.h" -#include "servers/visual_server.h" +#include "scene/main/scene_main_loop.h" #include "servers/physics_2d_server.h" #include "servers/physics_server.h" -#include "message_queue.h" -#include "scene/main/scene_main_loop.h" -Performance *Performance::singleton=NULL; - - - +#include "servers/visual_server.h" +Performance *Performance::singleton = NULL; void Performance::_bind_methods() { - ClassDB::bind_method(D_METHOD("get_monitor","monitor"),&Performance::get_monitor); - - BIND_CONSTANT( TIME_FPS ); - BIND_CONSTANT( TIME_PROCESS ); - BIND_CONSTANT( TIME_FIXED_PROCESS ); - BIND_CONSTANT( MEMORY_STATIC ); - BIND_CONSTANT( MEMORY_DYNAMIC ); - BIND_CONSTANT( MEMORY_STATIC_MAX ); - BIND_CONSTANT( MEMORY_DYNAMIC_MAX ); - BIND_CONSTANT( MEMORY_MESSAGE_BUFFER_MAX ); - BIND_CONSTANT( OBJECT_COUNT ); - BIND_CONSTANT( OBJECT_RESOURCE_COUNT ); - BIND_CONSTANT( OBJECT_NODE_COUNT ); - BIND_CONSTANT( RENDER_OBJECTS_IN_FRAME ); - BIND_CONSTANT( RENDER_VERTICES_IN_FRAME ); - BIND_CONSTANT( RENDER_MATERIAL_CHANGES_IN_FRAME ); - BIND_CONSTANT( RENDER_SHADER_CHANGES_IN_FRAME ); - BIND_CONSTANT( RENDER_SURFACE_CHANGES_IN_FRAME ); - BIND_CONSTANT( RENDER_DRAW_CALLS_IN_FRAME ); - BIND_CONSTANT( RENDER_USAGE_VIDEO_MEM_TOTAL ); - BIND_CONSTANT( RENDER_VIDEO_MEM_USED ); - BIND_CONSTANT( RENDER_TEXTURE_MEM_USED ); - BIND_CONSTANT( RENDER_VERTEX_MEM_USED ); - BIND_CONSTANT( PHYSICS_2D_ACTIVE_OBJECTS ); - BIND_CONSTANT( PHYSICS_2D_COLLISION_PAIRS ); - BIND_CONSTANT( PHYSICS_2D_ISLAND_COUNT ); - BIND_CONSTANT( PHYSICS_3D_ACTIVE_OBJECTS ); - BIND_CONSTANT( PHYSICS_3D_COLLISION_PAIRS ); - BIND_CONSTANT( PHYSICS_3D_ISLAND_COUNT ); - - BIND_CONSTANT( MONITOR_MAX ); - + ClassDB::bind_method(D_METHOD("get_monitor", "monitor"), &Performance::get_monitor); + + BIND_CONSTANT(TIME_FPS); + BIND_CONSTANT(TIME_PROCESS); + BIND_CONSTANT(TIME_FIXED_PROCESS); + BIND_CONSTANT(MEMORY_STATIC); + BIND_CONSTANT(MEMORY_DYNAMIC); + BIND_CONSTANT(MEMORY_STATIC_MAX); + BIND_CONSTANT(MEMORY_DYNAMIC_MAX); + BIND_CONSTANT(MEMORY_MESSAGE_BUFFER_MAX); + BIND_CONSTANT(OBJECT_COUNT); + BIND_CONSTANT(OBJECT_RESOURCE_COUNT); + BIND_CONSTANT(OBJECT_NODE_COUNT); + BIND_CONSTANT(RENDER_OBJECTS_IN_FRAME); + BIND_CONSTANT(RENDER_VERTICES_IN_FRAME); + BIND_CONSTANT(RENDER_MATERIAL_CHANGES_IN_FRAME); + BIND_CONSTANT(RENDER_SHADER_CHANGES_IN_FRAME); + BIND_CONSTANT(RENDER_SURFACE_CHANGES_IN_FRAME); + BIND_CONSTANT(RENDER_DRAW_CALLS_IN_FRAME); + BIND_CONSTANT(RENDER_USAGE_VIDEO_MEM_TOTAL); + BIND_CONSTANT(RENDER_VIDEO_MEM_USED); + BIND_CONSTANT(RENDER_TEXTURE_MEM_USED); + BIND_CONSTANT(RENDER_VERTEX_MEM_USED); + BIND_CONSTANT(PHYSICS_2D_ACTIVE_OBJECTS); + BIND_CONSTANT(PHYSICS_2D_COLLISION_PAIRS); + BIND_CONSTANT(PHYSICS_2D_ISLAND_COUNT); + BIND_CONSTANT(PHYSICS_3D_ACTIVE_OBJECTS); + BIND_CONSTANT(PHYSICS_3D_COLLISION_PAIRS); + BIND_CONSTANT(PHYSICS_3D_ISLAND_COUNT); + + BIND_CONSTANT(MONITOR_MAX); } String Performance::get_monitor_name(Monitor p_monitor) const { - ERR_FAIL_INDEX_V(p_monitor,MONITOR_MAX,String()); - static const char* names[MONITOR_MAX]={ + ERR_FAIL_INDEX_V(p_monitor, MONITOR_MAX, String()); + static const char *names[MONITOR_MAX] = { "time/fps", "time/process", @@ -110,14 +106,11 @@ String Performance::get_monitor_name(Monitor p_monitor) const { }; return names[p_monitor]; - - } - float Performance::get_monitor(Monitor p_monitor) const { - switch(p_monitor) { + switch (p_monitor) { case TIME_FPS: return Engine::get_singleton()->get_frames_per_second(); case TIME_PROCESS: return _process_time; case TIME_FIXED_PROCESS: return _fixed_process_time; @@ -137,7 +130,6 @@ float Performance::get_monitor(Monitor p_monitor) const { if (!sml) return 0; return sml->get_node_count(); - }; case RENDER_OBJECTS_IN_FRAME: return VS::get_singleton()->get_render_info(VS::INFO_OBJECTS_IN_FRAME); case RENDER_VERTICES_IN_FRAME: return VS::get_singleton()->get_render_info(VS::INFO_VERTICES_IN_FRAME); @@ -164,18 +156,17 @@ float Performance::get_monitor(Monitor p_monitor) const { void Performance::set_process_time(float p_pt) { - _process_time=p_pt; + _process_time = p_pt; } void Performance::set_fixed_process_time(float p_pt) { - _fixed_process_time=p_pt; + _fixed_process_time = p_pt; } - Performance::Performance() { - _process_time=0; - _fixed_process_time=0; - singleton=this; + _process_time = 0; + _fixed_process_time = 0; + singleton = this; } diff --git a/main/performance.h b/main/performance.h index 8b5626b681..03bec11296 100644 --- a/main/performance.h +++ b/main/performance.h @@ -34,18 +34,17 @@ #define PERF_WARN_OFFLINE_FUNCTION #define PERF_WARN_PROCESS_SYNC - class Performance : public Object { - GDCLASS(Performance,Object); + GDCLASS(Performance, Object); static Performance *singleton; static void _bind_methods(); float _process_time; float _fixed_process_time; -public: +public: enum Monitor { TIME_FPS, @@ -79,7 +78,6 @@ public: MONITOR_MAX }; - float get_monitor(Monitor p_monitor) const; String get_monitor_name(Monitor p_monitor) const; @@ -89,10 +87,8 @@ public: static Performance *get_singleton() { return singleton; } Performance(); - }; -VARIANT_ENUM_CAST( Performance::Monitor ); - +VARIANT_ENUM_CAST(Performance::Monitor); #endif // PERFORMANCE_H diff --git a/main/splash.h b/main/splash.h index 3423f1b932..401cf5a022 100644 --- a/main/splash.h +++ b/main/splash.h @@ -1419,5 +1419,5 @@ static const unsigned char app_icon_png[] = { 0x42, 0x60, 0x82 }; -static const Color boot_splash_bg_color = Color(224/255.0,224/255.0,224/255.0); +static const Color boot_splash_bg_color = Color(224 / 255.0, 224 / 255.0, 224 / 255.0); #endif // SPLASH_H diff --git a/main/tests/test_containers.cpp b/main/tests/test_containers.cpp index 8926066fe6..d860d9940e 100644 --- a/main/tests/test_containers.cpp +++ b/main/tests/test_containers.cpp @@ -29,19 +29,18 @@ #include "test_containers.h" #include "dvector.h" -#include "set.h" -#include "print_string.h" #include "math_funcs.h" +#include "print_string.h" #include "servers/visual/default_mouse_cursor.xpm" +#include "set.h" -#include "variant.h" -#include "list.h" #include "image.h" +#include "list.h" +#include "variant.h" namespace TestContainers { -MainLoop * test() { - +MainLoop *test() { /* HashMap<int,int> int_map; @@ -53,14 +52,13 @@ MainLoop * test() { } */ - { Image img; img.create(default_mouse_cursor_xpm); { - for (int i=0; i<8; i++) { + for (int i = 0; i < 8; i++) { Image mipmap; //img.make_mipmap(mipmap); @@ -68,7 +66,6 @@ MainLoop * test() { if (img.get_width() <= 4) break; }; }; - }; #if 0 @@ -103,5 +100,4 @@ MainLoop * test() { return NULL; } - } diff --git a/main/tests/test_containers.h b/main/tests/test_containers.h index bbc132f1c2..990bf4f819 100644 --- a/main/tests/test_containers.h +++ b/main/tests/test_containers.h @@ -36,8 +36,7 @@ namespace TestContainers { -MainLoop * test(); - +MainLoop *test(); } #endif diff --git a/main/tests/test_gdscript.cpp b/main/tests/test_gdscript.cpp index e9ac238f2a..fcbecc768b 100644 --- a/main/tests/test_gdscript.cpp +++ b/main/tests/test_gdscript.cpp @@ -28,47 +28,44 @@ /*************************************************************************/ #include "test_gdscript.h" - +#include "os/file_access.h" #include "os/main_loop.h" #include "os/os.h" -#include "os/file_access.h" #ifdef GDSCRIPT_ENABLED -#include "modules/gdscript/gd_tokenizer.h" -#include "modules/gdscript/gd_parser.h" #include "modules/gdscript/gd_compiler.h" +#include "modules/gdscript/gd_parser.h" #include "modules/gdscript/gd_script.h" - +#include "modules/gdscript/gd_tokenizer.h" namespace TestGDScript { - -static void _print_indent(int p_ident,const String& p_text) { +static void _print_indent(int p_ident, const String &p_text) { String txt; - for(int i=0;i<p_ident;i++) { - txt+='\t'; + for (int i = 0; i < p_ident; i++) { + txt += '\t'; } - print_line(txt+p_text); + print_line(txt + p_text); } static String _parser_extends(const GDParser::ClassNode *p_class) { - String txt="extends "; - if (String(p_class->extends_file)!="") { - txt+="\""+p_class->extends_file+"\""; + String txt = "extends "; + if (String(p_class->extends_file) != "") { + txt += "\"" + p_class->extends_file + "\""; if (p_class->extends_class.size()) - txt+="."; + txt += "."; } - for(int i=0;i<p_class->extends_class.size();i++) { + for (int i = 0; i < p_class->extends_class.size(); i++) { - if (i!=0) - txt+="."; + if (i != 0) + txt += "."; - txt+=p_class->extends_class[i]; + txt += p_class->extends_class[i]; } return txt; @@ -77,153 +74,222 @@ static String _parser_extends(const GDParser::ClassNode *p_class) { static String _parser_expr(const GDParser::Node *p_expr) { String txt; - switch(p_expr->type) { + switch (p_expr->type) { case GDParser::Node::TYPE_IDENTIFIER: { const GDParser::IdentifierNode *id_node = static_cast<const GDParser::IdentifierNode *>(p_expr); - txt=id_node->name; + txt = id_node->name; } break; case GDParser::Node::TYPE_CONSTANT: { const GDParser::ConstantNode *c_node = static_cast<const GDParser::ConstantNode *>(p_expr); - if (c_node->value.get_type()==Variant::STRING) - txt="\""+String(c_node->value)+"\""; + if (c_node->value.get_type() == Variant::STRING) + txt = "\"" + String(c_node->value) + "\""; else - txt=c_node->value; + txt = c_node->value; } break; case GDParser::Node::TYPE_SELF: { - txt="self"; + txt = "self"; } break; case GDParser::Node::TYPE_ARRAY: { const GDParser::ArrayNode *arr_node = static_cast<const GDParser::ArrayNode *>(p_expr); - txt+="["; - for(int i=0;i<arr_node->elements.size();i++) { + txt += "["; + for (int i = 0; i < arr_node->elements.size(); i++) { - if (i>0) - txt+=", "; - txt+=_parser_expr(arr_node->elements[i]); + if (i > 0) + txt += ", "; + txt += _parser_expr(arr_node->elements[i]); } - txt+="]"; + txt += "]"; } break; case GDParser::Node::TYPE_DICTIONARY: { const GDParser::DictionaryNode *dict_node = static_cast<const GDParser::DictionaryNode *>(p_expr); - txt+="{"; - for(int i=0;i<dict_node->elements.size();i++) { + txt += "{"; + for (int i = 0; i < dict_node->elements.size(); i++) { - if (i>0) - txt+=", "; + if (i > 0) + txt += ", "; const GDParser::DictionaryNode::Pair &p = dict_node->elements[i]; - txt+=_parser_expr(p.key); - txt+=":"; - txt+=_parser_expr(p.value); + txt += _parser_expr(p.key); + txt += ":"; + txt += _parser_expr(p.value); } - txt+="}"; + txt += "}"; } break; case GDParser::Node::TYPE_OPERATOR: { const GDParser::OperatorNode *c_node = static_cast<const GDParser::OperatorNode *>(p_expr); - switch(c_node->op) { + switch (c_node->op) { case GDParser::OperatorNode::OP_PARENT_CALL: - txt+="."; + txt += "."; case GDParser::OperatorNode::OP_CALL: { - ERR_FAIL_COND_V(c_node->arguments.size()<1,""); + ERR_FAIL_COND_V(c_node->arguments.size() < 1, ""); String func_name; const GDParser::Node *nfunc = c_node->arguments[0]; - int arg_ofs=0; - if (nfunc->type==GDParser::Node::TYPE_BUILT_IN_FUNCTION) { + int arg_ofs = 0; + if (nfunc->type == GDParser::Node::TYPE_BUILT_IN_FUNCTION) { const GDParser::BuiltInFunctionNode *bif_node = static_cast<const GDParser::BuiltInFunctionNode *>(nfunc); - func_name=GDFunctions::get_func_name(bif_node->function); - arg_ofs=1; - } else if (nfunc->type==GDParser::Node::TYPE_TYPE) { + func_name = GDFunctions::get_func_name(bif_node->function); + arg_ofs = 1; + } else if (nfunc->type == GDParser::Node::TYPE_TYPE) { const GDParser::TypeNode *t_node = static_cast<const GDParser::TypeNode *>(nfunc); - func_name=Variant::get_type_name(t_node->vtype); - arg_ofs=1; + func_name = Variant::get_type_name(t_node->vtype); + arg_ofs = 1; } else { - ERR_FAIL_COND_V(c_node->arguments.size()<2,""); + ERR_FAIL_COND_V(c_node->arguments.size() < 2, ""); nfunc = c_node->arguments[1]; - ERR_FAIL_COND_V(nfunc->type!=GDParser::Node::TYPE_IDENTIFIER,""); + ERR_FAIL_COND_V(nfunc->type != GDParser::Node::TYPE_IDENTIFIER, ""); - if (c_node->arguments[0]->type!=GDParser::Node::TYPE_SELF) - func_name=_parser_expr(c_node->arguments[0])+"."; + if (c_node->arguments[0]->type != GDParser::Node::TYPE_SELF) + func_name = _parser_expr(c_node->arguments[0]) + "."; - func_name+=_parser_expr(nfunc); - arg_ofs=2; + func_name += _parser_expr(nfunc); + arg_ofs = 2; } - txt+=func_name+"("; + txt += func_name + "("; - for(int i=arg_ofs;i<c_node->arguments.size();i++) { + for (int i = arg_ofs; i < c_node->arguments.size(); i++) { - const GDParser::Node *arg=c_node->arguments[i]; - if (i>arg_ofs) - txt+=", "; - txt+=_parser_expr(arg); + const GDParser::Node *arg = c_node->arguments[i]; + if (i > arg_ofs) + txt += ", "; + txt += _parser_expr(arg); } - txt+=")"; + txt += ")"; } break; case GDParser::OperatorNode::OP_INDEX: { - ERR_FAIL_COND_V(c_node->arguments.size()!=2,""); + ERR_FAIL_COND_V(c_node->arguments.size() != 2, ""); //index with [] - txt=_parser_expr(c_node->arguments[0])+"["+_parser_expr(c_node->arguments[1])+"]"; + txt = _parser_expr(c_node->arguments[0]) + "[" + _parser_expr(c_node->arguments[1]) + "]"; } break; case GDParser::OperatorNode::OP_INDEX_NAMED: { - ERR_FAIL_COND_V(c_node->arguments.size()!=2,""); - - txt=_parser_expr(c_node->arguments[0])+"."+_parser_expr(c_node->arguments[1]); - - } break; - case GDParser::OperatorNode::OP_NEG: { txt="-"+_parser_expr(c_node->arguments[0]); } break; - case GDParser::OperatorNode::OP_NOT: { txt="not "+_parser_expr(c_node->arguments[0]); } break; - case GDParser::OperatorNode::OP_BIT_INVERT: { txt="~"+_parser_expr(c_node->arguments[0]); } break; - case GDParser::OperatorNode::OP_PREINC: {} break; - case GDParser::OperatorNode::OP_PREDEC: {} break; - case GDParser::OperatorNode::OP_INC: {} break; - case GDParser::OperatorNode::OP_DEC: {} break; - case GDParser::OperatorNode::OP_IN: { txt=_parser_expr(c_node->arguments[0])+" in "+_parser_expr(c_node->arguments[1]); } break; - case GDParser::OperatorNode::OP_EQUAL: { txt=_parser_expr(c_node->arguments[0])+"=="+_parser_expr(c_node->arguments[1]); } break; - case GDParser::OperatorNode::OP_NOT_EQUAL: { txt=_parser_expr(c_node->arguments[0])+"!="+_parser_expr(c_node->arguments[1]); } break; - case GDParser::OperatorNode::OP_LESS: { txt=_parser_expr(c_node->arguments[0])+"<"+_parser_expr(c_node->arguments[1]); } break; - case GDParser::OperatorNode::OP_LESS_EQUAL: { txt=_parser_expr(c_node->arguments[0])+"<="+_parser_expr(c_node->arguments[1]); } break; - case GDParser::OperatorNode::OP_GREATER: { txt=_parser_expr(c_node->arguments[0])+">"+_parser_expr(c_node->arguments[1]); } break; - case GDParser::OperatorNode::OP_GREATER_EQUAL: { txt=_parser_expr(c_node->arguments[0])+">="+_parser_expr(c_node->arguments[1]); } break; - case GDParser::OperatorNode::OP_AND: { txt=_parser_expr(c_node->arguments[0])+" and "+_parser_expr(c_node->arguments[1]); } break; - case GDParser::OperatorNode::OP_OR: { txt=_parser_expr(c_node->arguments[0])+" or "+_parser_expr(c_node->arguments[1]); } break; - case GDParser::OperatorNode::OP_ADD: { txt=_parser_expr(c_node->arguments[0])+"+"+_parser_expr(c_node->arguments[1]); } break; - case GDParser::OperatorNode::OP_SUB: { txt=_parser_expr(c_node->arguments[0])+"-"+_parser_expr(c_node->arguments[1]); } break; - case GDParser::OperatorNode::OP_MUL: { txt=_parser_expr(c_node->arguments[0])+"*"+_parser_expr(c_node->arguments[1]); } break; - case GDParser::OperatorNode::OP_DIV: { txt=_parser_expr(c_node->arguments[0])+"/"+_parser_expr(c_node->arguments[1]); } break; - case GDParser::OperatorNode::OP_MOD: { txt=_parser_expr(c_node->arguments[0])+"%"+_parser_expr(c_node->arguments[1]); } break; - case GDParser::OperatorNode::OP_SHIFT_LEFT: { txt=_parser_expr(c_node->arguments[0])+"<<"+_parser_expr(c_node->arguments[1]); } break; - case GDParser::OperatorNode::OP_SHIFT_RIGHT: { txt=_parser_expr(c_node->arguments[0])+">>"+_parser_expr(c_node->arguments[1]); } break; - case GDParser::OperatorNode::OP_ASSIGN: { txt=_parser_expr(c_node->arguments[0])+"="+_parser_expr(c_node->arguments[1]); } break; - case GDParser::OperatorNode::OP_ASSIGN_ADD: { txt=_parser_expr(c_node->arguments[0])+"+="+_parser_expr(c_node->arguments[1]); } break; - case GDParser::OperatorNode::OP_ASSIGN_SUB: { txt=_parser_expr(c_node->arguments[0])+"-="+_parser_expr(c_node->arguments[1]); } break; - case GDParser::OperatorNode::OP_ASSIGN_MUL: { txt=_parser_expr(c_node->arguments[0])+"*="+_parser_expr(c_node->arguments[1]); } break; - case GDParser::OperatorNode::OP_ASSIGN_DIV: { txt=_parser_expr(c_node->arguments[0])+"/="+_parser_expr(c_node->arguments[1]); } break; - case GDParser::OperatorNode::OP_ASSIGN_MOD: { txt=_parser_expr(c_node->arguments[0])+"%="+_parser_expr(c_node->arguments[1]); } break; - case GDParser::OperatorNode::OP_ASSIGN_SHIFT_LEFT:{ txt=_parser_expr(c_node->arguments[0])+"<<="+_parser_expr(c_node->arguments[1]); } break; - case GDParser::OperatorNode::OP_ASSIGN_SHIFT_RIGHT: { txt=_parser_expr(c_node->arguments[0])+">>="+_parser_expr(c_node->arguments[1]); } break; - case GDParser::OperatorNode::OP_ASSIGN_BIT_AND: { txt=_parser_expr(c_node->arguments[0])+"&="+_parser_expr(c_node->arguments[1]); } break; - case GDParser::OperatorNode::OP_ASSIGN_BIT_OR: { txt=_parser_expr(c_node->arguments[0])+"|="+_parser_expr(c_node->arguments[1]); } break; - case GDParser::OperatorNode::OP_ASSIGN_BIT_XOR: { txt=_parser_expr(c_node->arguments[0])+"^="+_parser_expr(c_node->arguments[1]); } break; - case GDParser::OperatorNode::OP_BIT_AND: { txt=_parser_expr(c_node->arguments[0])+"&"+_parser_expr(c_node->arguments[1]); } break; - case GDParser::OperatorNode::OP_BIT_OR: { txt=_parser_expr(c_node->arguments[0])+"|"+_parser_expr(c_node->arguments[1]); } break; - case GDParser::OperatorNode::OP_BIT_XOR: { txt=_parser_expr(c_node->arguments[0])+"^"+_parser_expr(c_node->arguments[1]); } break; - default: {} + ERR_FAIL_COND_V(c_node->arguments.size() != 2, ""); + txt = _parser_expr(c_node->arguments[0]) + "." + _parser_expr(c_node->arguments[1]); + + } break; + case GDParser::OperatorNode::OP_NEG: { + txt = "-" + _parser_expr(c_node->arguments[0]); + } break; + case GDParser::OperatorNode::OP_NOT: { + txt = "not " + _parser_expr(c_node->arguments[0]); + } break; + case GDParser::OperatorNode::OP_BIT_INVERT: { + txt = "~" + _parser_expr(c_node->arguments[0]); + } break; + case GDParser::OperatorNode::OP_PREINC: { + } break; + case GDParser::OperatorNode::OP_PREDEC: { + } break; + case GDParser::OperatorNode::OP_INC: { + } break; + case GDParser::OperatorNode::OP_DEC: { + } break; + case GDParser::OperatorNode::OP_IN: { + txt = _parser_expr(c_node->arguments[0]) + " in " + _parser_expr(c_node->arguments[1]); + } break; + case GDParser::OperatorNode::OP_EQUAL: { + txt = _parser_expr(c_node->arguments[0]) + "==" + _parser_expr(c_node->arguments[1]); + } break; + case GDParser::OperatorNode::OP_NOT_EQUAL: { + txt = _parser_expr(c_node->arguments[0]) + "!=" + _parser_expr(c_node->arguments[1]); + } break; + case GDParser::OperatorNode::OP_LESS: { + txt = _parser_expr(c_node->arguments[0]) + "<" + _parser_expr(c_node->arguments[1]); + } break; + case GDParser::OperatorNode::OP_LESS_EQUAL: { + txt = _parser_expr(c_node->arguments[0]) + "<=" + _parser_expr(c_node->arguments[1]); + } break; + case GDParser::OperatorNode::OP_GREATER: { + txt = _parser_expr(c_node->arguments[0]) + ">" + _parser_expr(c_node->arguments[1]); + } break; + case GDParser::OperatorNode::OP_GREATER_EQUAL: { + txt = _parser_expr(c_node->arguments[0]) + ">=" + _parser_expr(c_node->arguments[1]); + } break; + case GDParser::OperatorNode::OP_AND: { + txt = _parser_expr(c_node->arguments[0]) + " and " + _parser_expr(c_node->arguments[1]); + } break; + case GDParser::OperatorNode::OP_OR: { + txt = _parser_expr(c_node->arguments[0]) + " or " + _parser_expr(c_node->arguments[1]); + } break; + case GDParser::OperatorNode::OP_ADD: { + txt = _parser_expr(c_node->arguments[0]) + "+" + _parser_expr(c_node->arguments[1]); + } break; + case GDParser::OperatorNode::OP_SUB: { + txt = _parser_expr(c_node->arguments[0]) + "-" + _parser_expr(c_node->arguments[1]); + } break; + case GDParser::OperatorNode::OP_MUL: { + txt = _parser_expr(c_node->arguments[0]) + "*" + _parser_expr(c_node->arguments[1]); + } break; + case GDParser::OperatorNode::OP_DIV: { + txt = _parser_expr(c_node->arguments[0]) + "/" + _parser_expr(c_node->arguments[1]); + } break; + case GDParser::OperatorNode::OP_MOD: { + txt = _parser_expr(c_node->arguments[0]) + "%" + _parser_expr(c_node->arguments[1]); + } break; + case GDParser::OperatorNode::OP_SHIFT_LEFT: { + txt = _parser_expr(c_node->arguments[0]) + "<<" + _parser_expr(c_node->arguments[1]); + } break; + case GDParser::OperatorNode::OP_SHIFT_RIGHT: { + txt = _parser_expr(c_node->arguments[0]) + ">>" + _parser_expr(c_node->arguments[1]); + } break; + case GDParser::OperatorNode::OP_ASSIGN: { + txt = _parser_expr(c_node->arguments[0]) + "=" + _parser_expr(c_node->arguments[1]); + } break; + case GDParser::OperatorNode::OP_ASSIGN_ADD: { + txt = _parser_expr(c_node->arguments[0]) + "+=" + _parser_expr(c_node->arguments[1]); + } break; + case GDParser::OperatorNode::OP_ASSIGN_SUB: { + txt = _parser_expr(c_node->arguments[0]) + "-=" + _parser_expr(c_node->arguments[1]); + } break; + case GDParser::OperatorNode::OP_ASSIGN_MUL: { + txt = _parser_expr(c_node->arguments[0]) + "*=" + _parser_expr(c_node->arguments[1]); + } break; + case GDParser::OperatorNode::OP_ASSIGN_DIV: { + txt = _parser_expr(c_node->arguments[0]) + "/=" + _parser_expr(c_node->arguments[1]); + } break; + case GDParser::OperatorNode::OP_ASSIGN_MOD: { + txt = _parser_expr(c_node->arguments[0]) + "%=" + _parser_expr(c_node->arguments[1]); + } break; + case GDParser::OperatorNode::OP_ASSIGN_SHIFT_LEFT: { + txt = _parser_expr(c_node->arguments[0]) + "<<=" + _parser_expr(c_node->arguments[1]); + } break; + case GDParser::OperatorNode::OP_ASSIGN_SHIFT_RIGHT: { + txt = _parser_expr(c_node->arguments[0]) + ">>=" + _parser_expr(c_node->arguments[1]); + } break; + case GDParser::OperatorNode::OP_ASSIGN_BIT_AND: { + txt = _parser_expr(c_node->arguments[0]) + "&=" + _parser_expr(c_node->arguments[1]); + } break; + case GDParser::OperatorNode::OP_ASSIGN_BIT_OR: { + txt = _parser_expr(c_node->arguments[0]) + "|=" + _parser_expr(c_node->arguments[1]); + } break; + case GDParser::OperatorNode::OP_ASSIGN_BIT_XOR: { + txt = _parser_expr(c_node->arguments[0]) + "^=" + _parser_expr(c_node->arguments[1]); + } break; + case GDParser::OperatorNode::OP_BIT_AND: { + txt = _parser_expr(c_node->arguments[0]) + "&" + _parser_expr(c_node->arguments[1]); + } break; + case GDParser::OperatorNode::OP_BIT_OR: { + txt = _parser_expr(c_node->arguments[0]) + "|" + _parser_expr(c_node->arguments[1]); + } break; + case GDParser::OperatorNode::OP_BIT_XOR: { + txt = _parser_expr(c_node->arguments[0]) + "^" + _parser_expr(c_node->arguments[1]); + } break; + default: {} } } break; @@ -233,71 +299,68 @@ static String _parser_expr(const GDParser::Node *p_expr) { } break; default: { - String error="Parser bug at "+itos(p_expr->line)+", invalid expression type: "+itos(p_expr->type); + String error = "Parser bug at " + itos(p_expr->line) + ", invalid expression type: " + itos(p_expr->type); ERR_EXPLAIN(error); ERR_FAIL_V(""); - } - } return txt; //return "("+txt+")"; } +static void _parser_show_block(const GDParser::BlockNode *p_block, int p_indent) { -static void _parser_show_block(const GDParser::BlockNode *p_block,int p_indent) { + for (int i = 0; i < p_block->statements.size(); i++) { - for(int i=0;i<p_block->statements.size();i++) { + const GDParser::Node *statement = p_block->statements[i]; - const GDParser::Node *statement=p_block->statements[i]; - - switch(statement->type) { + switch (statement->type) { case GDParser::Node::TYPE_CONTROL_FLOW: { const GDParser::ControlFlowNode *cf_node = static_cast<const GDParser::ControlFlowNode *>(statement); - switch(cf_node->cf_type) { + switch (cf_node->cf_type) { case GDParser::ControlFlowNode::CF_IF: { - ERR_FAIL_COND(cf_node->arguments.size()!=1); + ERR_FAIL_COND(cf_node->arguments.size() != 1); String txt; - txt+="if "; - txt+=_parser_expr(cf_node->arguments[0]); - txt+=":"; - _print_indent(p_indent,txt); + txt += "if "; + txt += _parser_expr(cf_node->arguments[0]); + txt += ":"; + _print_indent(p_indent, txt); ERR_FAIL_COND(!cf_node->body); - _parser_show_block(cf_node->body,p_indent+1); + _parser_show_block(cf_node->body, p_indent + 1); if (cf_node->body_else) { - _print_indent(p_indent,"else:"); - _parser_show_block(cf_node->body_else,p_indent+1); + _print_indent(p_indent, "else:"); + _parser_show_block(cf_node->body_else, p_indent + 1); } } break; case GDParser::ControlFlowNode::CF_FOR: { - ERR_FAIL_COND(cf_node->arguments.size()!=2); + ERR_FAIL_COND(cf_node->arguments.size() != 2); String txt; - txt+="for "; - txt+=_parser_expr(cf_node->arguments[0]); - txt+=" in "; - txt+=_parser_expr(cf_node->arguments[1]); - txt+=":"; - _print_indent(p_indent,txt); + txt += "for "; + txt += _parser_expr(cf_node->arguments[0]); + txt += " in "; + txt += _parser_expr(cf_node->arguments[1]); + txt += ":"; + _print_indent(p_indent, txt); ERR_FAIL_COND(!cf_node->body); - _parser_show_block(cf_node->body,p_indent+1); + _parser_show_block(cf_node->body, p_indent + 1); } break; case GDParser::ControlFlowNode::CF_WHILE: { - ERR_FAIL_COND(cf_node->arguments.size()!=1); + ERR_FAIL_COND(cf_node->arguments.size() != 1); String txt; - txt+="while "; - txt+=_parser_expr(cf_node->arguments[0]); - txt+=":"; - _print_indent(p_indent,txt); + txt += "while "; + txt += _parser_expr(cf_node->arguments[0]); + txt += ":"; + _print_indent(p_indent, txt); ERR_FAIL_COND(!cf_node->body); - _parser_show_block(cf_node->body,p_indent+1); + _parser_show_block(cf_node->body, p_indent + 1); } break; case GDParser::ControlFlowNode::CF_SWITCH: { @@ -305,18 +368,18 @@ static void _parser_show_block(const GDParser::BlockNode *p_block,int p_indent) } break; case GDParser::ControlFlowNode::CF_CONTINUE: { - _print_indent(p_indent,"continue"); + _print_indent(p_indent, "continue"); } break; case GDParser::ControlFlowNode::CF_BREAK: { - _print_indent(p_indent,"break"); + _print_indent(p_indent, "break"); } break; case GDParser::ControlFlowNode::CF_RETURN: { if (cf_node->arguments.size()) - _print_indent(p_indent,"return "+_parser_expr(cf_node->arguments[0])); + _print_indent(p_indent, "return " + _parser_expr(cf_node->arguments[0])); else - _print_indent(p_indent,"return "); + _print_indent(p_indent, "return "); } break; } @@ -324,121 +387,110 @@ static void _parser_show_block(const GDParser::BlockNode *p_block,int p_indent) case GDParser::Node::TYPE_LOCAL_VAR: { const GDParser::LocalVarNode *lv_node = static_cast<const GDParser::LocalVarNode *>(statement); - _print_indent(p_indent,"var "+String(lv_node->name)); + _print_indent(p_indent, "var " + String(lv_node->name)); } break; default: { //expression i guess - _print_indent(p_indent,_parser_expr(statement)); - + _print_indent(p_indent, _parser_expr(statement)); } } } } -static void _parser_show_function(const GDParser::FunctionNode *p_func,int p_indent,GDParser::BlockNode *p_initializer=NULL) { +static void _parser_show_function(const GDParser::FunctionNode *p_func, int p_indent, GDParser::BlockNode *p_initializer = NULL) { String txt; if (p_func->_static) - txt="static "; - txt+="func "; - if (p_func->name=="") // initializer - txt+="[built-in-initializer]"; + txt = "static "; + txt += "func "; + if (p_func->name == "") // initializer + txt += "[built-in-initializer]"; else - txt+=String(p_func->name); - txt+="("; + txt += String(p_func->name); + txt += "("; - for(int i=0;i<p_func->arguments.size();i++) { + for (int i = 0; i < p_func->arguments.size(); i++) { - if (i!=0) - txt+=", "; - txt+="var "+String(p_func->arguments[i]); - if (i>=(p_func->arguments.size()-p_func->default_values.size())) { + if (i != 0) + txt += ", "; + txt += "var " + String(p_func->arguments[i]); + if (i >= (p_func->arguments.size() - p_func->default_values.size())) { int defarg = i - (p_func->arguments.size() - p_func->default_values.size()); - txt+="="; - txt+=_parser_expr(p_func->default_values[defarg]); + txt += "="; + txt += _parser_expr(p_func->default_values[defarg]); } } - txt+=")"; + txt += ")"; //todo constructor check! - txt+=":"; + txt += ":"; - _print_indent(p_indent,txt); + _print_indent(p_indent, txt); if (p_initializer) - _parser_show_block(p_initializer,p_indent+1); - _parser_show_block(p_func->body,p_indent+1); + _parser_show_block(p_initializer, p_indent + 1); + _parser_show_block(p_func->body, p_indent + 1); } -static void _parser_show_class(const GDParser::ClassNode *p_class,int p_indent,const Vector<String>& p_code) { +static void _parser_show_class(const GDParser::ClassNode *p_class, int p_indent, const Vector<String> &p_code) { - if (p_indent==0 && (String(p_class->extends_file)!="" || p_class->extends_class.size())) { + if (p_indent == 0 && (String(p_class->extends_file) != "" || p_class->extends_class.size())) { - _print_indent(p_indent,_parser_extends(p_class)); + _print_indent(p_indent, _parser_extends(p_class)); print_line("\n"); - } - for(int i=0;i<p_class->subclasses.size();i++) { - + for (int i = 0; i < p_class->subclasses.size(); i++) { - const GDParser::ClassNode *subclass=p_class->subclasses[i]; - String line="class "+subclass->name; - if (String(subclass->extends_file)!="" || subclass->extends_class.size()) - line+=" "+_parser_extends(subclass); - line+=":"; - _print_indent(p_indent,line); - _parser_show_class(subclass,p_indent+1,p_code); + const GDParser::ClassNode *subclass = p_class->subclasses[i]; + String line = "class " + subclass->name; + if (String(subclass->extends_file) != "" || subclass->extends_class.size()) + line += " " + _parser_extends(subclass); + line += ":"; + _print_indent(p_indent, line); + _parser_show_class(subclass, p_indent + 1, p_code); print_line("\n"); } + for (int i = 0; i < p_class->constant_expressions.size(); i++) { - for(int i=0;i<p_class->constant_expressions.size();i++) { - - const GDParser::ClassNode::Constant &constant=p_class->constant_expressions[i]; - _print_indent(p_indent,"const "+String(constant.identifier)+"="+_parser_expr(constant.expression)); + const GDParser::ClassNode::Constant &constant = p_class->constant_expressions[i]; + _print_indent(p_indent, "const " + String(constant.identifier) + "=" + _parser_expr(constant.expression)); } + for (int i = 0; i < p_class->variables.size(); i++) { - for(int i=0;i<p_class->variables.size();i++) { - - const GDParser::ClassNode::Member &m=p_class->variables[i]; - - _print_indent(p_indent,"var "+String(m.identifier)); + const GDParser::ClassNode::Member &m = p_class->variables[i]; + _print_indent(p_indent, "var " + String(m.identifier)); } print_line("\n"); - for(int i=0;i<p_class->static_functions.size();i++) { + for (int i = 0; i < p_class->static_functions.size(); i++) { - _parser_show_function(p_class->static_functions[i],p_indent); + _parser_show_function(p_class->static_functions[i], p_indent); print_line("\n"); - } - for(int i=0;i<p_class->functions.size();i++) { + for (int i = 0; i < p_class->functions.size(); i++) { - if (String(p_class->functions[i]->name)=="_init") { - _parser_show_function(p_class->functions[i],p_indent,p_class->initializer); + if (String(p_class->functions[i]->name) == "_init") { + _parser_show_function(p_class->functions[i], p_indent, p_class->initializer); } else - _parser_show_function(p_class->functions[i],p_indent); + _parser_show_function(p_class->functions[i], p_indent); print_line("\n"); - } //_parser_show_function(p_class->initializer,p_indent); print_line("\n"); - - } +static String _disassemble_addr(const Ref<GDScript> &p_script, const GDFunction &func, int p_addr) { -static String _disassemble_addr(const Ref<GDScript>& p_script,const GDFunction& func, int p_addr) { + int addr = p_addr & GDFunction::ADDR_MASK; - int addr=p_addr&GDFunction::ADDR_MASK; - - switch(p_addr>>GDFunction::ADDR_BITS) { + switch (p_addr >> GDFunction::ADDR_BITS) { case GDFunction::ADDR_TYPE_SELF: { return "self"; @@ -448,434 +500,417 @@ static String _disassemble_addr(const Ref<GDScript>& p_script,const GDFunction& } break; case GDFunction::ADDR_TYPE_MEMBER: { - return "member("+p_script->debug_get_member_by_index(addr)+")"; + return "member(" + p_script->debug_get_member_by_index(addr) + ")"; } break; case GDFunction::ADDR_TYPE_CLASS_CONSTANT: { - return "class_const("+func.get_global_name(addr)+")"; + return "class_const(" + func.get_global_name(addr) + ")"; } break; case GDFunction::ADDR_TYPE_LOCAL_CONSTANT: { - Variant v=func.get_constant(addr); + Variant v = func.get_constant(addr); String txt; - if (v.get_type()==Variant::STRING || v.get_type()==Variant::NODE_PATH) - txt="\""+String(v)+"\""; + if (v.get_type() == Variant::STRING || v.get_type() == Variant::NODE_PATH) + txt = "\"" + String(v) + "\""; else - txt=v; - return "const("+txt+")"; + txt = v; + return "const(" + txt + ")"; } break; case GDFunction::ADDR_TYPE_STACK: { - return "stack("+itos(addr)+")"; + return "stack(" + itos(addr) + ")"; } break; case GDFunction::ADDR_TYPE_STACK_VARIABLE: { - return "var_stack("+itos(addr)+")"; + return "var_stack(" + itos(addr) + ")"; } break; case GDFunction::ADDR_TYPE_GLOBAL: { - return "global("+func.get_global_name(addr)+")"; + return "global(" + func.get_global_name(addr) + ")"; } break; case GDFunction::ADDR_TYPE_NIL: { return "nil"; } break; - } return "<err>"; } -static void _disassemble_class(const Ref<GDScript>& p_class,const Vector<String>& p_code) { - +static void _disassemble_class(const Ref<GDScript> &p_class, const Vector<String> &p_code) { - const Map<StringName,GDFunction*>& mf = p_class->debug_get_member_functions(); + const Map<StringName, GDFunction *> &mf = p_class->debug_get_member_functions(); - for(const Map<StringName,GDFunction*>::Element *E=mf.front();E;E=E->next()) { + for (const Map<StringName, GDFunction *>::Element *E = mf.front(); E; E = E->next()) { - - const GDFunction &func=*E->get(); + const GDFunction &func = *E->get(); const int *code = func.get_code(); - int codelen=func.get_code_size(); + int codelen = func.get_code_size(); String defargs; if (func.get_default_argument_count()) { - defargs="defarg at: "; - for(int i=0;i<func.get_default_argument_count();i++) { + defargs = "defarg at: "; + for (int i = 0; i < func.get_default_argument_count(); i++) { - if (i>0) - defargs+=","; - defargs+=itos(func.get_default_argument_addr(i)); + if (i > 0) + defargs += ","; + defargs += itos(func.get_default_argument_addr(i)); } - defargs+=" "; + defargs += " "; } - print_line("== function "+String(func.get_name())+"() :: stack size: "+itos(func.get_max_stack_size())+" "+defargs+"=="); - -#define DADDR(m_ip) (_disassemble_addr(p_class,func,code[ip+m_ip])) + print_line("== function " + String(func.get_name()) + "() :: stack size: " + itos(func.get_max_stack_size()) + " " + defargs + "=="); - for(int ip=0;ip<codelen;) { +#define DADDR(m_ip) (_disassemble_addr(p_class, func, code[ip + m_ip])) + for (int ip = 0; ip < codelen;) { - int incr=0; - String txt=itos(ip)+" "; + int incr = 0; + String txt = itos(ip) + " "; - switch(code[ip]) { + switch (code[ip]) { case GDFunction::OPCODE_OPERATOR: { - int op = code[ip+1]; - txt+="op "; + int op = code[ip + 1]; + txt += "op "; String opname = Variant::get_operator_name(Variant::Operator(op)); - txt+=DADDR(4); - txt+=" = "; - txt+=DADDR(2); - txt+=" "+opname+" "; - txt+=DADDR(3); - incr+=5; + txt += DADDR(4); + txt += " = "; + txt += DADDR(2); + txt += " " + opname + " "; + txt += DADDR(3); + incr += 5; } break; case GDFunction::OPCODE_SET: { - txt+="set "; - txt+=DADDR(1); - txt+="["; - txt+=DADDR(2); - txt+="]="; - txt+=DADDR(3); - incr+=4; + txt += "set "; + txt += DADDR(1); + txt += "["; + txt += DADDR(2); + txt += "]="; + txt += DADDR(3); + incr += 4; } break; case GDFunction::OPCODE_GET: { - txt+=" get "; - txt+=DADDR(3); - txt+="="; - txt+=DADDR(1); - txt+="["; - txt+=DADDR(2); - txt+="]"; - incr+=4; + txt += " get "; + txt += DADDR(3); + txt += "="; + txt += DADDR(1); + txt += "["; + txt += DADDR(2); + txt += "]"; + incr += 4; } break; case GDFunction::OPCODE_SET_NAMED: { - txt+=" set_named "; - txt+=DADDR(1); - txt+="[\""; - txt+=func.get_global_name(code[ip+2]); - txt+="\"]="; - txt+=DADDR(3); - incr+=4; - + txt += " set_named "; + txt += DADDR(1); + txt += "[\""; + txt += func.get_global_name(code[ip + 2]); + txt += "\"]="; + txt += DADDR(3); + incr += 4; } break; case GDFunction::OPCODE_GET_NAMED: { - txt+=" get_named "; - txt+=DADDR(3); - txt+="="; - txt+=DADDR(1); - txt+="[\""; - txt+=func.get_global_name(code[ip+2]); - txt+="\"]"; - incr+=4; + txt += " get_named "; + txt += DADDR(3); + txt += "="; + txt += DADDR(1); + txt += "[\""; + txt += func.get_global_name(code[ip + 2]); + txt += "\"]"; + incr += 4; } break; case GDFunction::OPCODE_SET_MEMBER: { - txt+=" set_member "; - txt+="[\""; - txt+=func.get_global_name(code[ip+1]); - txt+="\"]="; - txt+=DADDR(2); - incr+=3; - + txt += " set_member "; + txt += "[\""; + txt += func.get_global_name(code[ip + 1]); + txt += "\"]="; + txt += DADDR(2); + incr += 3; } break; case GDFunction::OPCODE_GET_MEMBER: { - txt+=" get_member "; - txt+=DADDR(2); - txt+="="; - txt+="[\""; - txt+=func.get_global_name(code[ip+1]); - txt+="\"]"; - incr+=3; + txt += " get_member "; + txt += DADDR(2); + txt += "="; + txt += "[\""; + txt += func.get_global_name(code[ip + 1]); + txt += "\"]"; + incr += 3; } break; case GDFunction::OPCODE_ASSIGN: { - txt+=" assign "; - txt+=DADDR(1); - txt+="="; - txt+=DADDR(2); - incr+=3; - + txt += " assign "; + txt += DADDR(1); + txt += "="; + txt += DADDR(2); + incr += 3; } break; case GDFunction::OPCODE_ASSIGN_TRUE: { - txt+=" assign "; - txt+=DADDR(1); - txt+="= true"; - incr+=2; + txt += " assign "; + txt += DADDR(1); + txt += "= true"; + incr += 2; } break; case GDFunction::OPCODE_ASSIGN_FALSE: { - txt+=" assign "; - txt+=DADDR(1); - txt+="= false"; - incr+=2; + txt += " assign "; + txt += DADDR(1); + txt += "= false"; + incr += 2; } break; case GDFunction::OPCODE_CONSTRUCT: { - Variant::Type t=Variant::Type(code[ip+1]); - int argc=code[ip+2]; + Variant::Type t = Variant::Type(code[ip + 1]); + int argc = code[ip + 2]; - txt+=" construct "; - txt+=DADDR(3+argc); - txt+=" = "; + txt += " construct "; + txt += DADDR(3 + argc); + txt += " = "; - txt+=Variant::get_type_name(t)+"("; - for(int i=0;i<argc;i++) { + txt += Variant::get_type_name(t) + "("; + for (int i = 0; i < argc; i++) { - if (i>0) - txt+=", "; - txt+=DADDR(i+3); + if (i > 0) + txt += ", "; + txt += DADDR(i + 3); } - txt+=")"; + txt += ")"; - incr=4+argc; + incr = 4 + argc; } break; case GDFunction::OPCODE_CONSTRUCT_ARRAY: { - int argc=code[ip+1]; - txt+=" make_array "; - txt+=DADDR(2+argc); - txt+=" = [ "; + int argc = code[ip + 1]; + txt += " make_array "; + txt += DADDR(2 + argc); + txt += " = [ "; - for(int i=0;i<argc;i++) { - if (i>0) - txt+=", "; - txt+=DADDR(2+i); + for (int i = 0; i < argc; i++) { + if (i > 0) + txt += ", "; + txt += DADDR(2 + i); } - txt+="]"; + txt += "]"; - incr+=3+argc; + incr += 3 + argc; } break; case GDFunction::OPCODE_CONSTRUCT_DICTIONARY: { - int argc=code[ip+1]; - txt+=" make_dict "; - txt+=DADDR(2+argc*2); - txt+=" = { "; - - for(int i=0;i<argc;i++) { - if (i>0) - txt+=", "; - txt+=DADDR(2+i*2+0); - txt+=":"; - txt+=DADDR(2+i*2+1); + int argc = code[ip + 1]; + txt += " make_dict "; + txt += DADDR(2 + argc * 2); + txt += " = { "; + + for (int i = 0; i < argc; i++) { + if (i > 0) + txt += ", "; + txt += DADDR(2 + i * 2 + 0); + txt += ":"; + txt += DADDR(2 + i * 2 + 1); } - txt+="}"; + txt += "}"; - incr+=3+argc*2; + incr += 3 + argc * 2; } break; case GDFunction::OPCODE_CALL: case GDFunction::OPCODE_CALL_RETURN: { - bool ret=code[ip]==GDFunction::OPCODE_CALL_RETURN; + bool ret = code[ip] == GDFunction::OPCODE_CALL_RETURN; if (ret) - txt+=" call-ret "; + txt += " call-ret "; else - txt+=" call "; - + txt += " call "; - int argc=code[ip+1]; + int argc = code[ip + 1]; if (ret) { - txt+=DADDR(4+argc)+"="; + txt += DADDR(4 + argc) + "="; } - txt+=DADDR(2)+"."; - txt+=String(func.get_global_name(code[ip+3])); - txt+="("; + txt += DADDR(2) + "."; + txt += String(func.get_global_name(code[ip + 3])); + txt += "("; - for(int i=0;i<argc;i++) { - if (i>0) - txt+=", "; - txt+=DADDR(4+i); + for (int i = 0; i < argc; i++) { + if (i > 0) + txt += ", "; + txt += DADDR(4 + i); } - txt+=")"; + txt += ")"; - - incr=5+argc; + incr = 5 + argc; } break; case GDFunction::OPCODE_CALL_BUILT_IN: { - txt+=" call-built-in "; + txt += " call-built-in "; - int argc=code[ip+2]; - txt+=DADDR(3+argc)+"="; + int argc = code[ip + 2]; + txt += DADDR(3 + argc) + "="; - txt+=GDFunctions::get_func_name(GDFunctions::Function(code[ip+1])); - txt+="("; + txt += GDFunctions::get_func_name(GDFunctions::Function(code[ip + 1])); + txt += "("; - for(int i=0;i<argc;i++) { - if (i>0) - txt+=", "; - txt+=DADDR(3+i); + for (int i = 0; i < argc; i++) { + if (i > 0) + txt += ", "; + txt += DADDR(3 + i); } - txt+=")"; - + txt += ")"; - incr=4+argc; + incr = 4 + argc; } break; case GDFunction::OPCODE_CALL_SELF_BASE: { - txt+=" call-self-base "; + txt += " call-self-base "; - int argc=code[ip+2]; - txt+=DADDR(3+argc)+"="; + int argc = code[ip + 2]; + txt += DADDR(3 + argc) + "="; - txt+=func.get_global_name(code[ip+1]); - txt+="("; + txt += func.get_global_name(code[ip + 1]); + txt += "("; - for(int i=0;i<argc;i++) { - if (i>0) - txt+=", "; - txt+=DADDR(3+i); + for (int i = 0; i < argc; i++) { + if (i > 0) + txt += ", "; + txt += DADDR(3 + i); } - txt+=")"; - + txt += ")"; - incr=4+argc; + incr = 4 + argc; } break; case GDFunction::OPCODE_YIELD: { - txt+=" yield "; - incr=1; + txt += " yield "; + incr = 1; } break; case GDFunction::OPCODE_YIELD_SIGNAL: { - txt+=" yield_signal "; - txt+=DADDR(1); - txt+=","; - txt+=DADDR(2); - incr=3; + txt += " yield_signal "; + txt += DADDR(1); + txt += ","; + txt += DADDR(2); + incr = 3; } break; case GDFunction::OPCODE_YIELD_RESUME: { - txt+=" yield resume: "; - txt+=DADDR(1); - incr=2; + txt += " yield resume: "; + txt += DADDR(1); + incr = 2; } break; case GDFunction::OPCODE_JUMP: { - txt+=" jump "; - txt+=itos(code[ip+1]); + txt += " jump "; + txt += itos(code[ip + 1]); - incr=2; + incr = 2; } break; case GDFunction::OPCODE_JUMP_IF: { + txt += " jump-if "; + txt += DADDR(1); + txt += " to "; + txt += itos(code[ip + 2]); - txt+=" jump-if "; - txt+=DADDR(1); - txt+=" to "; - txt+=itos(code[ip+2]); - - incr=3; + incr = 3; } break; case GDFunction::OPCODE_JUMP_IF_NOT: { + txt += " jump-if-not "; + txt += DADDR(1); + txt += " to "; + txt += itos(code[ip + 2]); - txt+=" jump-if-not "; - txt+=DADDR(1); - txt+=" to "; - txt+=itos(code[ip+2]); - - incr=3; + incr = 3; } break; case GDFunction::OPCODE_JUMP_TO_DEF_ARGUMENT: { - - txt+=" jump-to-default-argument "; - incr=1; + txt += " jump-to-default-argument "; + incr = 1; } break; case GDFunction::OPCODE_RETURN: { - txt+=" return "; - txt+=DADDR(1); + txt += " return "; + txt += DADDR(1); - incr=2; + incr = 2; } break; case GDFunction::OPCODE_ITERATE_BEGIN: { - txt+=" for-init "+DADDR(4)+" in "+DADDR(2)+" counter "+DADDR(1)+" end "+itos(code[ip+3]); - incr+=5; + txt += " for-init " + DADDR(4) + " in " + DADDR(2) + " counter " + DADDR(1) + " end " + itos(code[ip + 3]); + incr += 5; } break; case GDFunction::OPCODE_ITERATE: { - txt+=" for-loop "+DADDR(4)+" in "+DADDR(2)+" counter "+DADDR(1)+" end "+itos(code[ip+3]); - incr+=5; + txt += " for-loop " + DADDR(4) + " in " + DADDR(2) + " counter " + DADDR(1) + " end " + itos(code[ip + 3]); + incr += 5; } break; case GDFunction::OPCODE_LINE: { - - - int line = code[ip+1]-1; - if (line>=0 && line <p_code.size()) - txt="\n"+itos(line+1)+": "+p_code[line]+"\n"; + int line = code[ip + 1] - 1; + if (line >= 0 && line < p_code.size()) + txt = "\n" + itos(line + 1) + ": " + p_code[line] + "\n"; else - txt=""; - incr+=2; + txt = ""; + incr += 2; } break; case GDFunction::OPCODE_END: { - txt+=" end"; - incr+=1; + txt += " end"; + incr += 1; } break; case GDFunction::OPCODE_ASSERT: { - txt+=" assert "; - txt+=DADDR(1); - incr+=2; + txt += " assert "; + txt += DADDR(1); + incr += 2; } break; - } - if (incr==0) { + if (incr == 0) { - ERR_EXPLAIN("unhandled opcode: "+itos(code[ip])); - ERR_BREAK(incr==0); + ERR_EXPLAIN("unhandled opcode: " + itos(code[ip])); + ERR_BREAK(incr == 0); } - ip+=incr; - if (txt!="") + ip += incr; + if (txt != "") print_line(txt); } } } -MainLoop* test(TestType p_test) { +MainLoop *test(TestType p_test) { List<String> cmdlargs = OS::get_singleton()->get_cmdline_args(); @@ -886,153 +921,137 @@ MainLoop* test(TestType p_test) { String test = cmdlargs.back()->get(); - FileAccess *fa = FileAccess::open(test,FileAccess::READ); + FileAccess *fa = FileAccess::open(test, FileAccess::READ); if (!fa) { - ERR_EXPLAIN("Could not open file: "+test); + ERR_EXPLAIN("Could not open file: " + test); ERR_FAIL_V(NULL); } - Vector<uint8_t> buf; int flen = fa->get_len(); - buf.resize(fa->get_len()+1); - fa->get_buffer(&buf[0],flen); - buf[flen]=0; + buf.resize(fa->get_len() + 1); + fa->get_buffer(&buf[0], flen); + buf[flen] = 0; String code; - code.parse_utf8((const char*)&buf[0]); + code.parse_utf8((const char *)&buf[0]); Vector<String> lines; - int last=0; + int last = 0; - for(int i=0;i<=code.length();i++) { + for (int i = 0; i <= code.length(); i++) { - if (code[i]=='\n' || code[i]==0) { + if (code[i] == '\n' || code[i] == 0) { - lines.push_back(code.substr(last,i-last)); - last=i+1; + lines.push_back(code.substr(last, i - last)); + last = i + 1; } } - - if (p_test==TEST_TOKENIZER) { + if (p_test == TEST_TOKENIZER) { GDTokenizerText tk; tk.set_code(code); - int line=-1; - while(tk.get_token()!=GDTokenizer::TK_EOF) { - + int line = -1; + while (tk.get_token() != GDTokenizer::TK_EOF) { String text; - if (tk.get_token()==GDTokenizer::TK_IDENTIFIER) - text="'"+tk.get_token_identifier()+"' (identifier)"; - else if (tk.get_token()==GDTokenizer::TK_CONSTANT) { - Variant c= tk.get_token_constant(); - if (c.get_type()==Variant::STRING) - text="\""+String(c)+"\""; + if (tk.get_token() == GDTokenizer::TK_IDENTIFIER) + text = "'" + tk.get_token_identifier() + "' (identifier)"; + else if (tk.get_token() == GDTokenizer::TK_CONSTANT) { + Variant c = tk.get_token_constant(); + if (c.get_type() == Variant::STRING) + text = "\"" + String(c) + "\""; else - text=c; - - text=text+" ("+Variant::get_type_name(c.get_type())+" constant)"; - } else if (tk.get_token()==GDTokenizer::TK_ERROR) - text="ERROR: "+tk.get_token_error(); - else if (tk.get_token()==GDTokenizer::TK_NEWLINE) - text="newline ("+itos(tk.get_token_line())+") + indent: "+itos(tk.get_token_line_indent()); - else if (tk.get_token()==GDTokenizer::TK_BUILT_IN_FUNC) - text="'"+String(GDFunctions::get_func_name(tk.get_token_built_in_func()))+"' (built-in function)"; + text = c; + + text = text + " (" + Variant::get_type_name(c.get_type()) + " constant)"; + } else if (tk.get_token() == GDTokenizer::TK_ERROR) + text = "ERROR: " + tk.get_token_error(); + else if (tk.get_token() == GDTokenizer::TK_NEWLINE) + text = "newline (" + itos(tk.get_token_line()) + ") + indent: " + itos(tk.get_token_line_indent()); + else if (tk.get_token() == GDTokenizer::TK_BUILT_IN_FUNC) + text = "'" + String(GDFunctions::get_func_name(tk.get_token_built_in_func())) + "' (built-in function)"; else - text=tk.get_token_name(tk.get_token()); - + text = tk.get_token_name(tk.get_token()); - if (tk.get_token_line()!=line) { - int from=line+1; + if (tk.get_token_line() != line) { + int from = line + 1; line = tk.get_token_line(); - for(int i=from;i<=line;i++) { - int l=i-1; - if (l>=0 && l<lines.size()) { - print_line("\n"+itos(i)+": "+lines[l]+"\n"); + for (int i = from; i <= line; i++) { + int l = i - 1; + if (l >= 0 && l < lines.size()) { + print_line("\n" + itos(i) + ": " + lines[l] + "\n"); } } } - print_line("\t("+itos(tk.get_token_column())+"): "+text); + print_line("\t(" + itos(tk.get_token_column()) + "): " + text); tk.advance(); - } } - if (p_test==TEST_PARSER) { - + if (p_test == TEST_PARSER) { GDParser parser; Error err = parser.parse(code); if (err) { - print_line("Parse Error:\n"+itos(parser.get_error_line())+":"+itos(parser.get_error_column())+":"+parser.get_error()); + print_line("Parse Error:\n" + itos(parser.get_error_line()) + ":" + itos(parser.get_error_column()) + ":" + parser.get_error()); memdelete(fa); return NULL; - } - const GDParser::Node* root = parser.get_parse_tree(); - ERR_FAIL_COND_V(root->type!=GDParser::Node::TYPE_CLASS,NULL); - const GDParser::ClassNode *cnode=static_cast<const GDParser::ClassNode*>(root); - - _parser_show_class(cnode,0,lines); + const GDParser::Node *root = parser.get_parse_tree(); + ERR_FAIL_COND_V(root->type != GDParser::Node::TYPE_CLASS, NULL); + const GDParser::ClassNode *cnode = static_cast<const GDParser::ClassNode *>(root); + _parser_show_class(cnode, 0, lines); } - if (p_test==TEST_COMPILER) { - + if (p_test == TEST_COMPILER) { GDParser parser; Error err = parser.parse(code); if (err) { - print_line("Parse Error:\n"+itos(parser.get_error_line())+":"+itos(parser.get_error_column())+":"+parser.get_error()); + print_line("Parse Error:\n" + itos(parser.get_error_line()) + ":" + itos(parser.get_error_column()) + ":" + parser.get_error()); memdelete(fa); return NULL; - } - GDScript *script = memnew( GDScript ); + GDScript *script = memnew(GDScript); GDCompiler gdc; - err = gdc.compile(&parser,script); + err = gdc.compile(&parser, script); if (err) { - print_line("Compile Error:\n"+itos(gdc.get_error_line())+":"+itos(gdc.get_error_column())+":"+gdc.get_error()); + print_line("Compile Error:\n" + itos(gdc.get_error_line()) + ":" + itos(gdc.get_error_column()) + ":" + gdc.get_error()); memdelete(script); return NULL; - } + Ref<GDScript> gds = Ref<GDScript>(script); - Ref<GDScript> gds =Ref<GDScript>( script ); - - Ref<GDScript> current=gds; + Ref<GDScript> current = gds; - while(current.is_valid()) { + while (current.is_valid()) { print_line("** CLASS **"); - _disassemble_class(current,lines); + _disassemble_class(current, lines); - current=current->get_base(); + current = current->get_base(); } - - - - } else if (p_test==TEST_BYTECODE) { + } else if (p_test == TEST_BYTECODE) { Vector<uint8_t> buf = GDTokenizerBuffer::parse_code_string(code); - String dst = test.get_basename()+".gdc"; - FileAccess *fw = FileAccess::open(dst,FileAccess::WRITE); - fw->store_buffer(buf.ptr(),buf.size()); + String dst = test.get_basename() + ".gdc"; + FileAccess *fw = FileAccess::open(dst, FileAccess::WRITE); + fw->store_buffer(buf.ptr(), buf.size()); memdelete(fw); } - #if 0 Parser parser; Error err = parser.parse(code); @@ -1043,20 +1062,17 @@ MainLoop* test(TestType p_test) { } #endif - - memdelete(fa); return NULL; } - } #else namespace TestGDScript { -MainLoop* test(TestType p_test) { +MainLoop *test(TestType p_test) { return NULL; } diff --git a/main/tests/test_gdscript.h b/main/tests/test_gdscript.h index 7541e7b20f..3b2a4aa4ec 100644 --- a/main/tests/test_gdscript.h +++ b/main/tests/test_gdscript.h @@ -40,8 +40,7 @@ enum TestType { TEST_BYTECODE, }; -MainLoop* test(TestType p_type); - +MainLoop *test(TestType p_type); } #endif // TEST_GDSCRIPT_H diff --git a/main/tests/test_gui.cpp b/main/tests/test_gui.cpp index 6833558f07..c291afaf32 100644 --- a/main/tests/test_gui.cpp +++ b/main/tests/test_gui.cpp @@ -30,51 +30,46 @@ #include "test_gui.h" -#include "scene/main/scene_main_loop.h" +#include "io/image_loader.h" #include "os/os.h" -#include "scene/gui/control.h" +#include "print_string.h" +#include "scene/2d/sprite.h" #include "scene/gui/button.h" +#include "scene/gui/control.h" #include "scene/gui/label.h" #include "scene/gui/line_edit.h" -#include "scene/gui/scroll_bar.h" -#include "scene/gui/popup_menu.h" -#include "scene/gui/option_button.h" -#include "scene/gui/spin_box.h" #include "scene/gui/menu_button.h" -#include "scene/gui/progress_bar.h" +#include "scene/gui/option_button.h" #include "scene/gui/panel.h" -#include "scene/gui/tab_container.h" -#include "scene/gui/tree.h" +#include "scene/gui/popup_menu.h" +#include "scene/gui/progress_bar.h" #include "scene/gui/rich_text_label.h" +#include "scene/gui/scroll_bar.h" +#include "scene/gui/spin_box.h" +#include "scene/gui/tab_container.h" #include "scene/gui/texture_rect.h" -#include "io/image_loader.h" -#include "print_string.h" -#include "scene/2d/sprite.h" +#include "scene/gui/tree.h" +#include "scene/main/scene_main_loop.h" -#include "scene/main/viewport.h" #include "scene/3d/camera.h" #include "scene/3d/test_cube.h" +#include "scene/main/viewport.h" namespace TestGUI { - class TestMainLoop : public SceneTree { - Control *control; public: - virtual void request_quit() { quit(); - } virtual void init() { SceneTree::init(); - #if 0 @@ -105,35 +100,33 @@ public: return; #endif - Panel * frame = memnew( Panel ); - frame->set_anchor( MARGIN_RIGHT, Control::ANCHOR_END ); - frame->set_anchor( MARGIN_BOTTOM, Control::ANCHOR_END ); - frame->set_end( Point2(0,0) ); + Panel *frame = memnew(Panel); + frame->set_anchor(MARGIN_RIGHT, Control::ANCHOR_END); + frame->set_anchor(MARGIN_BOTTOM, Control::ANCHOR_END); + frame->set_end(Point2(0, 0)); - Ref<Theme> t = memnew( Theme ); + Ref<Theme> t = memnew(Theme); frame->set_theme(t); - get_root()->add_child( frame ); + get_root()->add_child(frame); - Label *label = memnew( Label ); + Label *label = memnew(Label); - label->set_pos( Point2( 80,90 ) ); - label->set_size( Point2( 170,80 ) ); - label->set_align( Label::ALIGN_FILL ); + label->set_pos(Point2(80, 90)); + label->set_size(Point2(170, 80)); + label->set_align(Label::ALIGN_FILL); //label->set_text("There"); label->set_text("There was once upon a time a beautiful unicorn that loved to play with little girls..."); frame->add_child(label); - Button *button = memnew( Button ); + Button *button = memnew(Button); - button->set_pos( Point2( 20,20 ) ); - button->set_size( Point2( 1,1 ) ); + button->set_pos(Point2(20, 20)); + button->set_size(Point2(1, 1)); button->set_text("This is a biggie button"); - - frame->add_child( button ); - + frame->add_child(button); #if 0 Sprite *tf = memnew( Sprite ); @@ -154,90 +147,85 @@ public: return; #endif - Tree * tree = memnew( Tree ); + Tree *tree = memnew(Tree); tree->set_columns(2); - tree->set_pos( Point2( 230,210 ) ); - tree->set_size( Point2( 150,250 ) ); - + tree->set_pos(Point2(230, 210)); + tree->set_size(Point2(150, 250)); TreeItem *item = tree->create_item(); - item->set_editable(0,true); - item->set_text(0,"root"); - item = tree->create_item( tree->get_root() ); + item->set_editable(0, true); + item->set_text(0, "root"); + item = tree->create_item(tree->get_root()); item->set_cell_mode(0, TreeItem::CELL_MODE_CHECK); - item->set_editable(0,true); - item->set_text(0,"check"); + item->set_editable(0, true); + item->set_text(0, "check"); item->set_cell_mode(1, TreeItem::CELL_MODE_CHECK); - item->set_editable(1,true); - item->set_text(1,"check2"); - item = tree->create_item( tree->get_root() ); + item->set_editable(1, true); + item->set_text(1, "check2"); + item = tree->create_item(tree->get_root()); item->set_cell_mode(0, TreeItem::CELL_MODE_RANGE); - item->set_editable(0,true); - item->set_range_config(0,0,20,0.1); - item->set_range(0,2); - item->add_button(0,Theme::get_default()->get_icon("folder","FileDialog")); + item->set_editable(0, true); + item->set_range_config(0, 0, 20, 0.1); + item->set_range(0, 2); + item->add_button(0, Theme::get_default()->get_icon("folder", "FileDialog")); item->set_cell_mode(1, TreeItem::CELL_MODE_RANGE); - item->set_editable(1,true); - item->set_range_config(1,0,20,0.1); - item->set_range(1,3); + item->set_editable(1, true); + item->set_range_config(1, 0, 20, 0.1); + item->set_range(1, 3); - item = tree->create_item( tree->get_root() ); + item = tree->create_item(tree->get_root()); item->set_cell_mode(0, TreeItem::CELL_MODE_RANGE); - item->set_editable(0,true); - item->set_text(0,"Have,Many,Several,Options!"); - item->set_range(0,2); + item->set_editable(0, true); + item->set_text(0, "Have,Many,Several,Options!"); + item->set_range(0, 2); - item = tree->create_item( item ); - item->set_editable(0,true); - item->set_text(0,"Gershwin!"); + item = tree->create_item(item); + item->set_editable(0, true); + item->set_text(0, "Gershwin!"); frame->add_child(tree); //control = memnew( Control ); //root->add_child( control ); + LineEdit *line_edit = memnew(LineEdit); - - LineEdit *line_edit = memnew( LineEdit ); - - line_edit->set_pos( Point2( 30,190 ) ); - line_edit->set_size( Point2( 180,1 ) ); + line_edit->set_pos(Point2(30, 190)); + line_edit->set_size(Point2(180, 1)); frame->add_child(line_edit); - HScrollBar *hscroll = memnew( HScrollBar ); + HScrollBar *hscroll = memnew(HScrollBar); - hscroll->set_pos( Point2( 30,290 ) ); - hscroll->set_size( Point2( 180,1 ) ); + hscroll->set_pos(Point2(30, 290)); + hscroll->set_size(Point2(180, 1)); hscroll->set_max(10); hscroll->set_page(4); frame->add_child(hscroll); + SpinBox *spin = memnew(SpinBox); - - SpinBox *spin = memnew( SpinBox ); - - spin->set_pos( Point2( 30,260 ) ); - spin->set_size( Point2( 120,1 ) ); + spin->set_pos(Point2(30, 260)); + spin->set_size(Point2(120, 1)); frame->add_child(spin); hscroll->share(spin); - ProgressBar *progress = memnew( ProgressBar ); + ProgressBar *progress = memnew(ProgressBar); - progress->set_pos( Point2( 30,330 ) ); - progress->set_size( Point2( 120,1 ) ); + progress->set_pos(Point2(30, 330)); + progress->set_size(Point2(120, 1)); frame->add_child(progress); hscroll->share(progress); - MenuButton *menu_button = memnew( MenuButton ); + MenuButton *menu_button = memnew(MenuButton); menu_button->set_text("I'm a menu!"); - menu_button->set_pos( Point2( 30,380 ) ); - menu_button->set_size( Point2( 1,1 ) ); + menu_button->set_pos(Point2(30, 380)); + menu_button->set_size(Point2(1, 1)); frame->add_child(menu_button); @@ -248,15 +236,15 @@ public: popup->add_separator(); popup->add_item("Popup"); popup->add_check_item("Check Popup"); - popup->set_item_checked(4,true); + popup->set_item_checked(4, true); - OptionButton *options = memnew( OptionButton ); + OptionButton *options = memnew(OptionButton); options->add_item("Hello, testing"); options->add_item("My Dearest"); - options->set_pos( Point2( 230,180 ) ); - options->set_size( Point2( 1,1 ) ); + options->set_pos(Point2(230, 180)); + options->set_size(Point2(1, 1)); frame->add_child(options); @@ -290,32 +278,30 @@ public: frame->add_child(tree); */ + RichTextLabel *richtext = memnew(RichTextLabel); - RichTextLabel *richtext = memnew( RichTextLabel ); - - richtext->set_pos( Point2( 600,210 ) ); - richtext->set_size( Point2( 180,250 ) ); - richtext->set_anchor_and_margin(MARGIN_RIGHT,Control::ANCHOR_END,20); + richtext->set_pos(Point2(600, 210)); + richtext->set_size(Point2(180, 250)); + richtext->set_anchor_and_margin(MARGIN_RIGHT, Control::ANCHOR_END, 20); frame->add_child(richtext); - richtext->add_text("Hello, My Friends!\n\nWelcome to the amazing world of "); richtext->add_newline(); richtext->add_newline(); - richtext->push_color(Color(1,0.5,0.5)); + richtext->push_color(Color(1, 0.5, 0.5)); richtext->add_text("leprechauns"); richtext->pop(); richtext->add_text(" and "); - richtext->push_color(Color(0,1.0,0.5)); + richtext->push_color(Color(0, 1.0, 0.5)); richtext->add_text("faeries.\n"); richtext->pop(); richtext->add_text("In this new episode, we will attemp to "); - richtext->push_font(richtext->get_font("mono_font","Fonts")); - richtext->push_color(Color(0.7,0.5,1.0)); + richtext->push_font(richtext->get_font("mono_font", "Fonts")); + richtext->push_color(Color(0.7, 0.5, 1.0)); richtext->add_text("deliver something nice"); richtext->pop(); richtext->pop(); @@ -333,42 +319,39 @@ public: richtext->add_text("of the rich text label for huge text (not like this text will really be huge but, you know).\nAs long as it is so long that it will work nicely for a test/demo, then it's welcomed in my book...\nChanging subject, the day is cloudy today and I'm wondering if I'll get che chance to travel somewhere nice. Sometimes, watching the clouds from satellite images may give a nice insight about how pressure zones in our planet work, althogh it also makes it pretty obvious to see why most weather forecasts get it wrong so often.\nClouds are so difficult to predict!\nBut it's pretty cool how our civilization has adapted to having water falling from the sky each time it rains..."); //richtext->add_text("Hello!\nGorgeous.."); - //richtext->push_meta("http://www.scrollingcapabilities.xz"); ///richtext->add_text("Hello!\n"); //richtext->pop(); - richtext->set_anchor(MARGIN_RIGHT,Control::ANCHOR_END); + richtext->set_anchor(MARGIN_RIGHT, Control::ANCHOR_END); + TabContainer *tabc = memnew(TabContainer); - TabContainer * tabc = memnew( TabContainer ); - - Control *ctl= memnew( Control ); + Control *ctl = memnew(Control); ctl->set_name("tab 1"); tabc->add_child(ctl); - ctl= memnew( Control ); + ctl = memnew(Control); ctl->set_name("tab 2"); tabc->add_child(ctl); - label = memnew( Label ); + label = memnew(Label); label->set_text("Some Label"); - label->set_pos( Point2(20,20) ); + label->set_pos(Point2(20, 20)); ctl->add_child(label); - ctl= memnew( Control ); + ctl = memnew(Control); ctl->set_name("tab 3"); - button = memnew( Button ); + button = memnew(Button); button->set_text("Some Button"); - button->set_pos( Point2(30,50) ); + button->set_pos(Point2(30, 50)); ctl->add_child(button); tabc->add_child(ctl); frame->add_child(tabc); - tabc->set_pos( Point2( 400,210 ) ); - tabc->set_size( Point2( 180,250 ) ); - + tabc->set_pos(Point2(400, 210)); + tabc->set_size(Point2(180, 250)); /*Ref<ImageTexture> text = memnew( ImageTexture ); text->load("test_data/concave.png"); @@ -385,18 +368,12 @@ public: sprite2->set_pos(Point2(50, 50)); sprite2->show();*/ } - - - }; +MainLoop *test() { -MainLoop* test() { - - - return memnew( TestMainLoop ); + return memnew(TestMainLoop); } - } #endif diff --git a/main/tests/test_gui.h b/main/tests/test_gui.h index d053770bdd..5ffa077dc9 100644 --- a/main/tests/test_gui.h +++ b/main/tests/test_gui.h @@ -36,9 +36,7 @@ */ namespace TestGUI { -MainLoop* test(); - +MainLoop *test(); } - #endif diff --git a/main/tests/test_image.cpp b/main/tests/test_image.cpp index dbe0111367..c57968ad10 100644 --- a/main/tests/test_image.cpp +++ b/main/tests/test_image.cpp @@ -28,26 +28,24 @@ /*************************************************************************/ #include "test_image.h" -#include "os/main_loop.h" +#include "io/image_loader.h" #include "math_funcs.h" +#include "os/main_loop.h" #include "print_string.h" -#include "io/image_loader.h" namespace TestImage { - class TestMainLoop : public MainLoop { bool quit; -public: - virtual void input_event(const InputEvent& p_event) { - +public: + virtual void input_event(const InputEvent &p_event) { } virtual void init() { - quit=false; + quit = false; } virtual bool iteration(float p_time) { @@ -59,21 +57,16 @@ public: } virtual void finish() { - } - }; - -MainLoop* test() { +MainLoop *test() { Image img; - ImageLoader::load_image("as1.png",&img); - - img.resize(512,512); + ImageLoader::load_image("as1.png", &img); - return memnew( TestMainLoop ); + img.resize(512, 512); + return memnew(TestMainLoop); } - } diff --git a/main/tests/test_image.h b/main/tests/test_image.h index 51ce6d5cc7..f520462429 100644 --- a/main/tests/test_image.h +++ b/main/tests/test_image.h @@ -37,8 +37,7 @@ namespace TestImage { -MainLoop* test(); - +MainLoop *test(); } #endif diff --git a/main/tests/test_io.cpp b/main/tests/test_io.cpp index af4742afa7..dfc1f05383 100644 --- a/main/tests/test_io.cpp +++ b/main/tests/test_io.cpp @@ -30,31 +30,25 @@ #ifdef MINIZIP_ENABLED - - -#include "os/main_loop.h" -#include "os/os.h" -#include "scene/resources/texture.h" -#include "print_string.h" +#include "core/global_config.h" #include "io/resource_loader.h" #include "io/resource_saver.h" #include "os/dir_access.h" -#include "core/global_config.h" +#include "os/main_loop.h" +#include "os/os.h" +#include "print_string.h" +#include "scene/resources/texture.h" #include "io/file_access_memory.h" namespace TestIO { - class TestMainLoop : public MainLoop { - bool quit; public: - virtual void input_event(const InputEvent& p_event) { - - + virtual void input_event(const InputEvent &p_event) { } virtual bool idle(float p_time) { return false; @@ -62,53 +56,48 @@ public: virtual void request_quit() { - quit=true; - + quit = true; } virtual void init() { - quit=true; + quit = true; } virtual bool iteration(float p_time) { return quit; } virtual void finish() { - } - - }; - -MainLoop* test() { +MainLoop *test() { print_line("this is test io"); - DirAccess* da = DirAccess::create(DirAccess::ACCESS_FILESYSTEM); + DirAccess *da = DirAccess::create(DirAccess::ACCESS_FILESYSTEM); da->change_dir("."); - print_line("Opening current dir "+ da->get_current_dir()); + print_line("Opening current dir " + da->get_current_dir()); String entry; da->list_dir_begin(); - while ( (entry = da->get_next()) != "") { + while ((entry = da->get_next()) != "") { - print_line("entry "+entry+" is dir: " + Variant(da->current_is_dir())); + print_line("entry " + entry + " is dir: " + Variant(da->current_is_dir())); }; da->list_dir_end(); RES texture = ResourceLoader::load("test_data/rock.png"); ERR_FAIL_COND_V(texture.is_null(), NULL); - ResourceSaver::save("test_data/rock.xml",texture); + ResourceSaver::save("test_data/rock.xml", texture); print_line("localize paths"); print_line(GlobalConfig::get_singleton()->localize_path("algo.xml")); print_line(GlobalConfig::get_singleton()->localize_path("c:\\windows\\algo.xml")); - print_line(GlobalConfig::get_singleton()->localize_path(GlobalConfig::get_singleton()->get_resource_path()+"/something/something.xml")); + print_line(GlobalConfig::get_singleton()->localize_path(GlobalConfig::get_singleton()->get_resource_path() + "/something/something.xml")); print_line(GlobalConfig::get_singleton()->localize_path("somedir/algo.xml")); { - FileAccess* z = FileAccess::open("test_data/archive.zip", FileAccess::READ); + FileAccess *z = FileAccess::open("test_data/archive.zip", FileAccess::READ); int len = z->get_len(); Vector<uint8_t> zip; zip.resize(len); @@ -186,23 +175,17 @@ MainLoop* test() { print_line("test done"); - - return memnew( TestMainLoop ); - + return memnew(TestMainLoop); } - } #else namespace TestIO { - -MainLoop* test() { +MainLoop *test() { return NULL; } - } #endif - diff --git a/main/tests/test_io.h b/main/tests/test_io.h index bb6a4a4474..21c1356c35 100644 --- a/main/tests/test_io.h +++ b/main/tests/test_io.h @@ -37,8 +37,7 @@ namespace TestIO { -MainLoop* test(); - +MainLoop *test(); } #endif diff --git a/main/tests/test_main.cpp b/main/tests/test_main.cpp index 27f7c2d025..ca039402c1 100644 --- a/main/tests/test_main.cpp +++ b/main/tests/test_main.cpp @@ -31,24 +31,23 @@ #ifdef DEBUG_ENABLED -#include "test_string.h" #include "test_containers.h" -#include "test_math.h" #include "test_gui.h" -#include "test_render.h" -#include "test_sound.h" +#include "test_math.h" #include "test_physics.h" #include "test_physics_2d.h" +#include "test_render.h" +#include "test_sound.h" +#include "test_string.h" -#include "test_io.h" -#include "test_shader_lang.h" #include "test_gdscript.h" #include "test_image.h" +#include "test_io.h" +#include "test_shader_lang.h" +const char **tests_get_names() { -const char ** tests_get_names() { - - static const char* test_names[]={ + static const char *test_names[] = { "string", "containers", "math", @@ -64,82 +63,81 @@ const char ** tests_get_names() { return test_names; } -MainLoop* test_main(String p_test,const List<String>& p_args) { - +MainLoop *test_main(String p_test, const List<String> &p_args) { - if (p_test=="string") { + if (p_test == "string") { return TestString::test(); } - if (p_test=="containers") { + if (p_test == "containers") { return TestContainers::test(); } - if (p_test=="math") { + if (p_test == "math") { return TestMath::test(); } - if (p_test=="physics") { + if (p_test == "physics") { return TestPhysics::test(); } - if (p_test=="physics_2d") { + if (p_test == "physics_2d") { return TestPhysics2D::test(); } - if (p_test=="render") { + if (p_test == "render") { return TestRender::test(); } - #ifndef _3D_DISABLED - if (p_test=="gui") { +#ifndef _3D_DISABLED + if (p_test == "gui") { return TestGUI::test(); } - #endif +#endif //if (p_test=="sound") { // return TestSound::test(); //} - if (p_test=="io") { + if (p_test == "io") { return TestIO::test(); } - if (p_test=="shaderlang") { + if (p_test == "shaderlang") { return TestShaderLang::test(); } - if (p_test=="gd_tokenizer") { + if (p_test == "gd_tokenizer") { return TestGDScript::test(TestGDScript::TEST_TOKENIZER); } - if (p_test=="gd_parser") { + if (p_test == "gd_parser") { return TestGDScript::test(TestGDScript::TEST_PARSER); } - if (p_test=="gd_compiler") { + if (p_test == "gd_compiler") { return TestGDScript::test(TestGDScript::TEST_COMPILER); } - if (p_test=="gd_bytecode") { + if (p_test == "gd_bytecode") { return TestGDScript::test(TestGDScript::TEST_BYTECODE); } - if (p_test=="image") { + if (p_test == "image") { return TestImage::test(); } @@ -149,16 +147,16 @@ MainLoop* test_main(String p_test,const List<String>& p_args) { #else -const char ** tests_get_names() { +const char **tests_get_names() { - static const char* test_names[]={ + static const char *test_names[] = { NULL }; return test_names; } -MainLoop* test_main(String p_test,const List<String>& p_args) { +MainLoop *test_main(String p_test, const List<String> &p_args) { return NULL; } diff --git a/main/tests/test_main.h b/main/tests/test_main.h index 4d9419a4f6..729f2ca1f8 100644 --- a/main/tests/test_main.h +++ b/main/tests/test_main.h @@ -29,13 +29,10 @@ #ifndef TEST_MAIN_H #define TEST_MAIN_H -#include "ustring.h" #include "list.h" +#include "ustring.h" -const char ** tests_get_names(); -MainLoop* test_main(String p_test,const List<String>& p_args); - +const char **tests_get_names(); +MainLoop *test_main(String p_test, const List<String> &p_args); #endif - - diff --git a/main/tests/test_math.cpp b/main/tests/test_math.cpp index 43164bb2e6..c82ae1abf5 100644 --- a/main/tests/test_math.cpp +++ b/main/tests/test_math.cpp @@ -28,26 +28,25 @@ /*************************************************************************/ #include "test_math.h" -#include "ustring.h" -#include "print_string.h" -#include "transform.h" -#include "matrix3.h" -#include "math_funcs.h" #include "camera_matrix.h" -#include "scene/main/node.h" -#include "variant.h" -#include "servers/visual/shader_language.h" +#include "math_funcs.h" +#include "matrix3.h" +#include "os/file_access.h" #include "os/keyboard.h" +#include "os/os.h" +#include "print_string.h" +#include "scene/main/node.h" #include "scene/resources/texture.h" +#include "servers/visual/shader_language.h" +#include "transform.h" +#include "ustring.h" +#include "variant.h" #include "vmap.h" -#include "os/os.h" -#include "os/file_access.h" #include "method_ptrcall.h" namespace TestMath { - class GetClassAndNamespace { String code; @@ -75,11 +74,10 @@ class GetClassAndNamespace { TK_ERROR }; - Token get_token() { while (true) { - switch(code[idx]) { + switch (code[idx]) { case '\n': { @@ -128,28 +126,27 @@ class GetClassAndNamespace { }; case '#': { //compiler directive - while(code[idx]!='\n' && code[idx]!=0) { + while (code[idx] != '\n' && code[idx] != 0) { idx++; } continue; } break; case '/': { - - switch(code[idx+1]) { + switch (code[idx + 1]) { case '*': { // block comment - idx+=2; - while(true) { - if (code[idx]==0) { - error_str="Unterminated comment"; - error=true; + idx += 2; + while (true) { + if (code[idx] == 0) { + error_str = "Unterminated comment"; + error = true; return TK_ERROR; - } else if (code[idx]=='*' &&code[idx+1]=='/') { + } else if (code[idx] == '*' && code[idx + 1] == '/') { - idx+=2; + idx += 2; break; - } else if (code[idx]=='\n') { + } else if (code[idx] == '\n') { line++; } @@ -159,17 +156,16 @@ class GetClassAndNamespace { } break; case '/': { // line comment skip - while(code[idx]!='\n' && code[idx]!=0) { + while (code[idx] != '\n' && code[idx] != 0) { idx++; } } break; default: { - value="/"; + value = "/"; idx++; return TK_SYMBOL; } - } continue; // a comment @@ -179,34 +175,36 @@ class GetClassAndNamespace { CharType begin_str = code[idx]; idx++; - String tk_string=String(); - while(true) { - if (code[idx]==0) { - error_str="Unterminated String"; - error=true; + String tk_string = String(); + while (true) { + if (code[idx] == 0) { + error_str = "Unterminated String"; + error = true; return TK_ERROR; - } else if (code[idx]==begin_str) { + } else if (code[idx] == begin_str) { idx++; break; - } else if (code[idx]=='\\') { + } else if (code[idx] == '\\') { //escaped characters... idx++; CharType next = code[idx]; - if (next==0) { - error_str="Unterminated String"; - error=true; + if (next == 0) { + error_str = "Unterminated String"; + error = true; return TK_ERROR; } - CharType res=0; + CharType res = 0; - switch(next) { + switch (next) { - case 'b': res=8; break; - case 't': res=9; break; - case 'n': res=10; break; - case 'f': res=12; break; - case 'r': res=13; break; - /* too much, not needed for now + case 'b': res = 8; break; + case 't': res = 9; break; + case 'n': res = 10; break; + case 'f': res = 12; break; + case 'r': + res = 13; + break; + /* too much, not needed for now case 'u': { //hexnumbarh - oct is deprecated @@ -245,8 +243,10 @@ class GetClassAndNamespace { } break;*/ - case '\"': res='\"'; break; - case '\\': res='\\'; break; + case '\"': res = '\"'; break; + case '\\': + res = '\\'; + break; //case '/': res='/'; break; default: { res = next; @@ -255,133 +255,130 @@ class GetClassAndNamespace { } break; } - tk_string+=res; + tk_string += res; } else { - if (code[idx]=='\n') + if (code[idx] == '\n') line++; - tk_string+=code[idx]; + tk_string += code[idx]; } idx++; } - value=tk_string; + value = tk_string; return TK_STRING; } break; default: { - if (code[idx]<=32) { + if (code[idx] <= 32) { idx++; break; } - if ( (code[idx]>=33 && code[idx]<=47) || (code[idx]>=58 && code[idx]<=64) || (code[idx]>=91 && code[idx]<=96) || (code[idx]>=123 && code[idx]<=127)){ - value=String::chr(code[idx]); + if ((code[idx] >= 33 && code[idx] <= 47) || (code[idx] >= 58 && code[idx] <= 64) || (code[idx] >= 91 && code[idx] <= 96) || (code[idx] >= 123 && code[idx] <= 127)) { + value = String::chr(code[idx]); idx++; return TK_SYMBOL; } - if (code[idx]=='-' || (code[idx]>='0' && code[idx]<='9')) { + if (code[idx] == '-' || (code[idx] >= '0' && code[idx] <= '9')) { //a number const CharType *rptr; - double number = String::to_double(&code[idx],&rptr); - idx+=(rptr - &code[idx]); - value=number; + double number = String::to_double(&code[idx], &rptr); + idx += (rptr - &code[idx]); + value = number; return TK_NUMBER; - } else if ((code[idx]>='A' && code[idx]<='Z') || (code[idx]>='a' && code[idx]<='z') || code[idx]>127) { + } else if ((code[idx] >= 'A' && code[idx] <= 'Z') || (code[idx] >= 'a' && code[idx] <= 'z') || code[idx] > 127) { String id; - while((code[idx]>='A' && code[idx]<='Z') || (code[idx]>='a' && code[idx]<='z') || code[idx]>127) { + while ((code[idx] >= 'A' && code[idx] <= 'Z') || (code[idx] >= 'a' && code[idx] <= 'z') || code[idx] > 127) { - id+=code[idx]; + id += code[idx]; idx++; } - value=id; + value = id; return TK_IDENTIFIER; } else { - error_str="Unexpected character."; - error=true; + error_str = "Unexpected character."; + error = true; return TK_ERROR; } } - } } } public: - Error parse(const String& p_code,const String& p_known_class_name=String()) { + Error parse(const String &p_code, const String &p_known_class_name = String()) { - code=p_code; - idx=0; - line=0; - error_str=String(); - error=false; - value=Variant(); - class_name=String(); + code = p_code; + idx = 0; + line = 0; + error_str = String(); + error = false; + value = Variant(); + class_name = String(); - bool use_next_class=false; + bool use_next_class = false; Token tk = get_token(); - Map<int,String> namespace_stack; - int curly_stack=0; + Map<int, String> namespace_stack; + int curly_stack = 0; + while (!error || tk != TK_EOF) { - while(!error || tk!=TK_EOF) { - - if (tk==TK_BRACKET_OPEN) { + if (tk == TK_BRACKET_OPEN) { tk = get_token(); - if (tk==TK_IDENTIFIER && String(value)=="ScriptClass") { - if (get_token()==TK_BRACKET_CLOSE) { - use_next_class=true; + if (tk == TK_IDENTIFIER && String(value) == "ScriptClass") { + if (get_token() == TK_BRACKET_CLOSE) { + use_next_class = true; } } - } else if (tk==TK_IDENTIFIER && String(value)=="class") { + } else if (tk == TK_IDENTIFIER && String(value) == "class") { tk = get_token(); - if (tk==TK_IDENTIFIER) { + if (tk == TK_IDENTIFIER) { String name = value; - if (use_next_class || p_known_class_name==name) { - for (Map<int,String>::Element *E=namespace_stack.front();E;E=E->next()) { - class_name+=E->get()+"."; + if (use_next_class || p_known_class_name == name) { + for (Map<int, String>::Element *E = namespace_stack.front(); E; E = E->next()) { + class_name += E->get() + "."; } - class_name+=String(value); + class_name += String(value); break; } } - } else if (tk==TK_IDENTIFIER && String(value)=="namespace") { + } else if (tk == TK_IDENTIFIER && String(value) == "namespace") { String name; int at_level = curly_stack; - while(true) { + while (true) { tk = get_token(); - if (tk==TK_IDENTIFIER) { - name+=String(value); + if (tk == TK_IDENTIFIER) { + name += String(value); } tk = get_token(); - if (tk==TK_PERIOD) { - name+="."; - } else if (tk==TK_CURLY_BRACKET_OPEN) { + if (tk == TK_PERIOD) { + name += "."; + } else if (tk == TK_CURLY_BRACKET_OPEN) { curly_stack++; break; } else { break; //whathever else } - } - if (name!=String()) { - namespace_stack[at_level]=name; + if (name != String()) { + namespace_stack[at_level] = name; } - } else if (tk==TK_CURLY_BRACKET_OPEN) { + } else if (tk == TK_CURLY_BRACKET_OPEN) { curly_stack++; - } else if (tk==TK_CURLY_BRACKET_CLOSE) { + } else if (tk == TK_CURLY_BRACKET_CLOSE) { curly_stack--; if (namespace_stack.has(curly_stack)) { namespace_stack.erase(curly_stack); @@ -394,10 +391,7 @@ public: if (error) return ERR_PARSE_ERROR; - - return OK; - } String get_error() { @@ -407,23 +401,19 @@ public: String get_class() { return class_name; } - }; - void test_vec(Plane p_vec) { - CameraMatrix cm; - cm.set_perspective(45,1,0,100); - Plane v0=cm.xform4(p_vec); - - print_line("out: "+v0); - v0.normal.z = (v0.d/100.0 *2.0-1.0) * v0.d; - print_line("out_F: "+v0); + cm.set_perspective(45, 1, 0, 100); + Plane v0 = cm.xform4(p_vec); + print_line("out: " + v0); + v0.normal.z = (v0.d / 100.0 * 2.0 - 1.0) * v0.d; + print_line("out_F: " + v0); -/*v0: 0, 0, -0.1, 0.1 + /*v0: 0, 0, -0.1, 0.1 v1: 0, 0, 0, 0.1 fix: 0, 0, 0, 0.1 v0: 0, 0, 1.302803, 1.5 @@ -439,49 +429,41 @@ v0: 0, 0, 100, 100 v1: 0, 0, 100, 100 fix: 0, 0, 100, 100 */ - - } -uint32_t ihash( uint32_t a) -{ - a = (a+0x7ed55d16) + (a<<12); - a = (a^0xc761c23c) ^ (a>>19); - a = (a+0x165667b1) + (a<<5); - a = (a+0xd3a2646c) ^ (a<<9); - a = (a+0xfd7046c5) + (a<<3); - a = (a^0xb55a4f09) ^ (a>>16); - return a; +uint32_t ihash(uint32_t a) { + a = (a + 0x7ed55d16) + (a << 12); + a = (a ^ 0xc761c23c) ^ (a >> 19); + a = (a + 0x165667b1) + (a << 5); + a = (a + 0xd3a2646c) ^ (a << 9); + a = (a + 0xfd7046c5) + (a << 3); + a = (a ^ 0xb55a4f09) ^ (a >> 16); + return a; } -uint32_t ihash2( uint32_t a) { - a = (a ^ 61) ^ (a >> 16); - a = a + (a << 3); - a = a ^ (a >> 4); - a = a * 0x27d4eb2d; - a = a ^ (a >> 15); - return a; +uint32_t ihash2(uint32_t a) { + a = (a ^ 61) ^ (a >> 16); + a = a + (a << 3); + a = a ^ (a >> 4); + a = a * 0x27d4eb2d; + a = a ^ (a >> 15); + return a; } -uint32_t ihash3( uint32_t a) -{ - a = (a+0x479ab41d) + (a<<8); - a = (a^0xe4aa10ce) ^ (a>>5); - a = (a+0x9942f0a6) - (a<<14); - a = (a^0x5aedd67d) ^ (a>>3); - a = (a+0x17bea992) + (a<<7); - return a; +uint32_t ihash3(uint32_t a) { + a = (a + 0x479ab41d) + (a << 8); + a = (a ^ 0xe4aa10ce) ^ (a >> 5); + a = (a + 0x9942f0a6) - (a << 14); + a = (a ^ 0x5aedd67d) ^ (a >> 3); + a = (a + 0x17bea992) + (a << 7); + return a; } +MainLoop *test() { - - -MainLoop* test() { - - - print_line("Dvectors: "+itos(MemoryPool::allocs_used)); - print_line("Mem used: "+itos(MemoryPool::total_memory)); - print_line("MAx mem used: "+itos(MemoryPool::max_memory)); + print_line("Dvectors: " + itos(MemoryPool::allocs_used)); + print_line("Mem used: " + itos(MemoryPool::total_memory)); + print_line("MAx mem used: " + itos(MemoryPool::max_memory)); PoolVector<int> ints; ints.resize(20); @@ -489,8 +471,8 @@ MainLoop* test() { { PoolVector<int>::Write w; w = ints.write(); - for(int i=0;i<ints.size();i++) { - w[i]=i; + for (int i = 0; i < ints.size(); i++) { + w[i] = i; } } @@ -498,15 +480,14 @@ MainLoop* test() { { PoolVector<int>::Read r = posho.read(); - for(int i=0;i<posho.size();i++) { - print_line(itos(i)+" : " +itos(r[i])); + for (int i = 0; i < posho.size(); i++) { + print_line(itos(i) + " : " + itos(r[i])); } } - print_line("later Dvectors: "+itos(MemoryPool::allocs_used)); - print_line("later Mem used: "+itos(MemoryPool::total_memory)); - print_line("Mlater Ax mem used: "+itos(MemoryPool::max_memory)); - + print_line("later Dvectors: " + itos(MemoryPool::allocs_used)); + print_line("later Mem used: " + itos(MemoryPool::total_memory)); + print_line("Mlater Ax mem used: " + itos(MemoryPool::max_memory)); return NULL; @@ -519,29 +500,27 @@ MainLoop* test() { String test = cmdlargs.back()->get(); - FileAccess *fa = FileAccess::open(test,FileAccess::READ); + FileAccess *fa = FileAccess::open(test, FileAccess::READ); if (!fa) { - ERR_EXPLAIN("Could not open file: "+test); + ERR_EXPLAIN("Could not open file: " + test); ERR_FAIL_V(NULL); } - Vector<uint8_t> buf; int flen = fa->get_len(); - buf.resize(fa->get_len()+1); - fa->get_buffer(&buf[0],flen); - buf[flen]=0; - + buf.resize(fa->get_len() + 1); + fa->get_buffer(&buf[0], flen); + buf[flen] = 0; String code; - code.parse_utf8((const char*)&buf[0]); + code.parse_utf8((const char *)&buf[0]); GetClassAndNamespace getclass; if (getclass.parse(code)) { - print_line("Parse error: "+getclass.get_error()); + print_line("Parse error: " + getclass.get_error()); } else { - print_line("Found class: "+getclass.get_class()); + print_line("Found class: " + getclass.get_class()); } return NULL; @@ -552,35 +531,33 @@ MainLoop* test() { List<StringName> tl; ClassDB::get_class_list(&tl); - - for (List<StringName>::Element *E=tl.front();E;E=E->next()) { + for (List<StringName>::Element *E = tl.front(); E; E = E->next()) { Vector<uint8_t> m5b = E->get().operator String().md5_buffer(); hashes.push_back(hashes.size()); - } //hashes.resize(50); - for(int i=nearest_shift(hashes.size());i<20;i++) { + for (int i = nearest_shift(hashes.size()); i < 20; i++) { - bool success=true; - for(int s=0;s<10000;s++) { + bool success = true; + for (int s = 0; s < 10000; s++) { Set<uint32_t> existing; - success=true; + success = true; - for(int j=0;j<hashes.size();j++) { + for (int j = 0; j < hashes.size(); j++) { - uint32_t eh = ihash2(ihash3(hashes[j]+ihash(s)+s))&((1<<i)-1); + uint32_t eh = ihash2(ihash3(hashes[j] + ihash(s) + s)) & ((1 << i) - 1); if (existing.has(eh)) { - success=false; + success = false; break; } existing.insert(eh); } if (success) { - print_line("success at "+itos(i)+"/"+itos(nearest_shift(hashes.size()))+" shift "+itos(s)); + print_line("success at " + itos(i) + "/" + itos(nearest_shift(hashes.size())) + " shift " + itos(s)); break; } } @@ -590,47 +567,42 @@ MainLoop* test() { print_line("DONE"); - - return NULL; } { - //print_line("NUM: "+itos(237641278346127)); - print_line("NUM: "+itos(-128)); + print_line("NUM: " + itos(-128)); return NULL; - } - { - Vector3 v(1,2,3); + Vector3 v(1, 2, 3); v.normalize(); - float a=0.3; + float a = 0.3; //Quat q(v,a); - Basis m(v,a); + Basis m(v, a); - Vector3 v2(7,3,1); + Vector3 v2(7, 3, 1); v2.normalize(); - float a2=0.8; + float a2 = 0.8; //Quat q(v,a); - Basis m2(v2,a2); + Basis m2(v2, a2); - Quat q=m; - Quat q2=m2; + Quat q = m; + Quat q2 = m2; Basis m3 = m.inverse() * m2; - Quat q3 = (q.inverse() * q2);//.normalized(); + Quat q3 = (q.inverse() * q2); //.normalized(); print_line(Quat(m3)); print_line(q3); - print_line("before v: "+v+" a: "+rtos(a)); - q.get_axis_and_angle(v,a); - print_line("after v: "+v+" a: "+rtos(a)); + print_line("before v: " + v + " a: " + rtos(a)); + q.get_axis_and_angle(v, a); + print_line("after v: " + v + " a: " + rtos(a)); } return NULL; @@ -638,98 +610,91 @@ MainLoop* test() { List<String> args; args.push_back("-l"); - Error err = OS::get_singleton()->execute("/bin/ls",args,true,NULL,&ret); - print_line("error: "+itos(err)); + Error err = OS::get_singleton()->execute("/bin/ls", args, true, NULL, &ret); + print_line("error: " + itos(err)); print_line(ret); return NULL; Basis m3; - m3.rotate(Vector3(1,0,0),0.2); - m3.rotate(Vector3(0,1,0),1.77); - m3.rotate(Vector3(0,0,1),212); + m3.rotate(Vector3(1, 0, 0), 0.2); + m3.rotate(Vector3(0, 1, 0), 1.77); + m3.rotate(Vector3(0, 0, 1), 212); Basis m32; m32.set_euler(m3.get_euler()); - print_line("ELEULEEEEEEEEEEEEEEEEEER: "+m3.get_euler()+" vs "+m32.get_euler()); - + print_line("ELEULEEEEEEEEEEEEEEEEEER: " + m3.get_euler() + " vs " + m32.get_euler()); return NULL; { Dictionary d; - d["momo"]=1; - Dictionary b=d; - b["44"]=4; + d["momo"] = 1; + Dictionary b = d; + b["44"] = 4; } - - return NULL; - print_line("inters: "+rtos(Geometry::segment_intersects_circle(Vector2(-5,0),Vector2(-2,0),Vector2(),1.0))); - - - - print_line("cross: "+Vector3(1,2,3).cross(Vector3(4,5,7))); - print_line("dot: "+rtos(Vector3(1,2,3).dot(Vector3(4,5,7)))); - print_line("abs: "+Vector3(-1,2,-3).abs()); - print_line("distance_to: "+rtos(Vector3(1,2,3).distance_to(Vector3(4,5,7)))); - print_line("distance_squared_to: "+rtos(Vector3(1,2,3).distance_squared_to(Vector3(4,5,7)))); - print_line("plus: "+(Vector3(1,2,3)+Vector3(Vector3(4,5,7)))); - print_line("minus: "+(Vector3(1,2,3)-Vector3(Vector3(4,5,7)))); - print_line("mul: "+(Vector3(1,2,3)*Vector3(Vector3(4,5,7)))); - print_line("div: "+(Vector3(1,2,3)/Vector3(Vector3(4,5,7)))); - print_line("mul scalar: "+(Vector3(1,2,3)*2)); - print_line("premul scalar: "+(2*Vector3(1,2,3))); - print_line("div scalar: "+(Vector3(1,2,3)/3.0)); - print_line("length: "+rtos(Vector3(1,2,3).length())); - print_line("length squared: "+rtos(Vector3(1,2,3).length_squared())); - print_line("normalized: "+Vector3(1,2,3).normalized()); - print_line("inverse: "+Vector3(1,2,3).inverse()); + print_line("inters: " + rtos(Geometry::segment_intersects_circle(Vector2(-5, 0), Vector2(-2, 0), Vector2(), 1.0))); + + print_line("cross: " + Vector3(1, 2, 3).cross(Vector3(4, 5, 7))); + print_line("dot: " + rtos(Vector3(1, 2, 3).dot(Vector3(4, 5, 7)))); + print_line("abs: " + Vector3(-1, 2, -3).abs()); + print_line("distance_to: " + rtos(Vector3(1, 2, 3).distance_to(Vector3(4, 5, 7)))); + print_line("distance_squared_to: " + rtos(Vector3(1, 2, 3).distance_squared_to(Vector3(4, 5, 7)))); + print_line("plus: " + (Vector3(1, 2, 3) + Vector3(Vector3(4, 5, 7)))); + print_line("minus: " + (Vector3(1, 2, 3) - Vector3(Vector3(4, 5, 7)))); + print_line("mul: " + (Vector3(1, 2, 3) * Vector3(Vector3(4, 5, 7)))); + print_line("div: " + (Vector3(1, 2, 3) / Vector3(Vector3(4, 5, 7)))); + print_line("mul scalar: " + (Vector3(1, 2, 3) * 2)); + print_line("premul scalar: " + (2 * Vector3(1, 2, 3))); + print_line("div scalar: " + (Vector3(1, 2, 3) / 3.0)); + print_line("length: " + rtos(Vector3(1, 2, 3).length())); + print_line("length squared: " + rtos(Vector3(1, 2, 3).length_squared())); + print_line("normalized: " + Vector3(1, 2, 3).normalized()); + print_line("inverse: " + Vector3(1, 2, 3).inverse()); { - Vector3 v(4,5,7); + Vector3 v(4, 5, 7); v.normalize(); - print_line("normalize: "+v); + print_line("normalize: " + v); } { - Vector3 v(4,5,7); - v+=Vector3(1,2,3); - print_line("+=: "+v); + Vector3 v(4, 5, 7); + v += Vector3(1, 2, 3); + print_line("+=: " + v); } { - Vector3 v(4,5,7); - v-=Vector3(1,2,3); - print_line("-=: "+v); + Vector3 v(4, 5, 7); + v -= Vector3(1, 2, 3); + print_line("-=: " + v); } { - Vector3 v(4,5,7); - v*=Vector3(1,2,3); - print_line("*=: "+v); + Vector3 v(4, 5, 7); + v *= Vector3(1, 2, 3); + print_line("*=: " + v); } { - Vector3 v(4,5,7); - v/=Vector3(1,2,3); - print_line("/=: "+v); + Vector3 v(4, 5, 7); + v /= Vector3(1, 2, 3); + print_line("/=: " + v); } { - Vector3 v(4,5,7); - v*=2.0; - print_line("scalar *=: "+v); + Vector3 v(4, 5, 7); + v *= 2.0; + print_line("scalar *=: " + v); } { - Vector3 v(4,5,7); - v/=2.0; - print_line("scalar /=: "+v); + Vector3 v(4, 5, 7); + v /= 2.0; + print_line("scalar /=: " + v); } - - #if 0 print_line(String("C:\\momo\\.\\popo\\..\\gongo").simplify_path()); print_line(String("res://../popo/..//gongo").simplify_path()); @@ -811,7 +776,5 @@ MainLoop* test() { #endif return NULL; - } - } diff --git a/main/tests/test_math.h b/main/tests/test_math.h index 1ca8a8c12a..239f16f6b0 100644 --- a/main/tests/test_math.h +++ b/main/tests/test_math.h @@ -33,8 +33,7 @@ namespace TestMath { -MainLoop* test(); - +MainLoop *test(); } #endif diff --git a/main/tests/test_physics.cpp b/main/tests/test_physics.cpp index fe0fad9bc8..6637139c86 100644 --- a/main/tests/test_physics.cpp +++ b/main/tests/test_physics.cpp @@ -28,19 +28,18 @@ /*************************************************************************/ #include "test_physics.h" - -#include "servers/visual_server.h" -#include "servers/physics_server.h" -#include "os/main_loop.h" -#include "math_funcs.h" -#include "print_string.h" #include "map.h" +#include "math_funcs.h" +#include "os/main_loop.h" #include "os/os.h" +#include "print_string.h" #include "quick_hull.h" +#include "servers/physics_server.h" +#include "servers/visual_server.h" class TestPhysicsMainLoop : public MainLoop { - GDCLASS( TestPhysicsMainLoop, MainLoop ); + GDCLASS(TestPhysicsMainLoop, MainLoop); enum { LINK_COUNT = 20, @@ -58,150 +57,145 @@ class TestPhysicsMainLoop : public MainLoop { RID character; - float ofs_x,ofs_y; + float ofs_x, ofs_y; Point2 joy_direction; List<RID> bodies; - Map<PhysicsServer::ShapeType,RID> type_shape_map; - Map<PhysicsServer::ShapeType,RID> type_mesh_map; + Map<PhysicsServer::ShapeType, RID> type_shape_map; + Map<PhysicsServer::ShapeType, RID> type_mesh_map; void body_changed_transform(Object *p_state, RID p_visual_instance) { - PhysicsDirectBodyState *state = (PhysicsDirectBodyState*)p_state; - VisualServer *vs=VisualServer::get_singleton(); - Transform t=state->get_transform(); + PhysicsDirectBodyState *state = (PhysicsDirectBodyState *)p_state; + VisualServer *vs = VisualServer::get_singleton(); + Transform t = state->get_transform(); //t.basis.scale( Vector3(1.0,0.5,0.2) ); - vs->instance_set_transform(p_visual_instance,t); + vs->instance_set_transform(p_visual_instance, t); } bool quit; protected: - static void _bind_methods() { - ClassDB::bind_method("body_changed_transform",&TestPhysicsMainLoop::body_changed_transform); + ClassDB::bind_method("body_changed_transform", &TestPhysicsMainLoop::body_changed_transform); } - RID create_body(PhysicsServer::ShapeType p_shape, PhysicsServer::BodyMode p_body,const Transform p_location,bool p_active_default=true,const Transform&p_shape_xform=Transform()) { + RID create_body(PhysicsServer::ShapeType p_shape, PhysicsServer::BodyMode p_body, const Transform p_location, bool p_active_default = true, const Transform &p_shape_xform = Transform()) { - VisualServer *vs=VisualServer::get_singleton(); - PhysicsServer * ps = PhysicsServer::get_singleton(); + VisualServer *vs = VisualServer::get_singleton(); + PhysicsServer *ps = PhysicsServer::get_singleton(); - RID mesh_instance = vs->instance_create2(type_mesh_map[p_shape],scenario); - RID body = ps->body_create(p_body,!p_active_default); - ps->body_set_space(body,space); - ps->body_set_param(body,PhysicsServer::BODY_PARAM_BOUNCE,0.0); + RID mesh_instance = vs->instance_create2(type_mesh_map[p_shape], scenario); + RID body = ps->body_create(p_body, !p_active_default); + ps->body_set_space(body, space); + ps->body_set_param(body, PhysicsServer::BODY_PARAM_BOUNCE, 0.0); //todo set space - ps->body_add_shape(body,type_shape_map[p_shape]); - ps->body_set_force_integration_callback(body,this,"body_changed_transform",mesh_instance); + ps->body_add_shape(body, type_shape_map[p_shape]); + ps->body_set_force_integration_callback(body, this, "body_changed_transform", mesh_instance); - ps->body_set_state( body, PhysicsServer::BODY_STATE_TRANSFORM,p_location); + ps->body_set_state(body, PhysicsServer::BODY_STATE_TRANSFORM, p_location); bodies.push_back(body); - if (p_body==PhysicsServer::BODY_MODE_STATIC) { + if (p_body == PhysicsServer::BODY_MODE_STATIC) { - vs->instance_set_transform(mesh_instance,p_location); + vs->instance_set_transform(mesh_instance, p_location); } return body; } - RID create_static_plane(const Plane& p_plane) { + RID create_static_plane(const Plane &p_plane) { - PhysicsServer * ps = PhysicsServer::get_singleton(); + PhysicsServer *ps = PhysicsServer::get_singleton(); RID plane_shape = ps->shape_create(PhysicsServer::SHAPE_PLANE); - ps->shape_set_data( plane_shape, p_plane ); + ps->shape_set_data(plane_shape, p_plane); - RID b = ps->body_create( PhysicsServer::BODY_MODE_STATIC ); - ps->body_set_space(b,space); + RID b = ps->body_create(PhysicsServer::BODY_MODE_STATIC); + ps->body_set_space(b, space); //todo set space ps->body_add_shape(b, plane_shape); return b; - } - void configure_body(RID p_body,float p_mass, float p_friction, float p_bounce) { - - PhysicsServer * ps = PhysicsServer::get_singleton(); - ps->body_set_param( p_body, PhysicsServer::BODY_PARAM_MASS, p_mass ); - ps->body_set_param( p_body, PhysicsServer::BODY_PARAM_FRICTION, p_friction ); - ps->body_set_param( p_body, PhysicsServer::BODY_PARAM_BOUNCE, p_bounce ); + void configure_body(RID p_body, float p_mass, float p_friction, float p_bounce) { + PhysicsServer *ps = PhysicsServer::get_singleton(); + ps->body_set_param(p_body, PhysicsServer::BODY_PARAM_MASS, p_mass); + ps->body_set_param(p_body, PhysicsServer::BODY_PARAM_FRICTION, p_friction); + ps->body_set_param(p_body, PhysicsServer::BODY_PARAM_BOUNCE, p_bounce); } void init_shapes() { - VisualServer *vs=VisualServer::get_singleton(); - PhysicsServer * ps = PhysicsServer::get_singleton(); + VisualServer *vs = VisualServer::get_singleton(); + PhysicsServer *ps = PhysicsServer::get_singleton(); /* SPHERE SHAPE */ - RID sphere_mesh = vs->make_sphere_mesh(10,20,0.5); - type_mesh_map[PhysicsServer::SHAPE_SPHERE]=sphere_mesh; + RID sphere_mesh = vs->make_sphere_mesh(10, 20, 0.5); + type_mesh_map[PhysicsServer::SHAPE_SPHERE] = sphere_mesh; - RID sphere_shape=ps->shape_create(PhysicsServer::SHAPE_SPHERE); - ps->shape_set_data( sphere_shape, 0.5 ); - type_shape_map[PhysicsServer::SHAPE_SPHERE]=sphere_shape; + RID sphere_shape = ps->shape_create(PhysicsServer::SHAPE_SPHERE); + ps->shape_set_data(sphere_shape, 0.5); + type_shape_map[PhysicsServer::SHAPE_SPHERE] = sphere_shape; /* BOX SHAPE */ - PoolVector<Plane> box_planes = Geometry::build_box_planes(Vector3(0.5,0.5,0.5)); + PoolVector<Plane> box_planes = Geometry::build_box_planes(Vector3(0.5, 0.5, 0.5)); RID box_mesh = vs->mesh_create(); Geometry::MeshData box_data = Geometry::build_convex_mesh(box_planes); - vs->mesh_add_surface_from_mesh_data(box_mesh,box_data); - type_mesh_map[PhysicsServer::SHAPE_BOX]=box_mesh; - - RID box_shape=ps->shape_create(PhysicsServer::SHAPE_BOX); - ps->shape_set_data( box_shape, Vector3(0.5,0.5,0.5) ); - type_shape_map[PhysicsServer::SHAPE_BOX]=box_shape; + vs->mesh_add_surface_from_mesh_data(box_mesh, box_data); + type_mesh_map[PhysicsServer::SHAPE_BOX] = box_mesh; + RID box_shape = ps->shape_create(PhysicsServer::SHAPE_BOX); + ps->shape_set_data(box_shape, Vector3(0.5, 0.5, 0.5)); + type_shape_map[PhysicsServer::SHAPE_BOX] = box_shape; /* CAPSULE SHAPE */ - PoolVector<Plane> capsule_planes = Geometry::build_capsule_planes(0.5,0.7,12,Vector3::AXIS_Z); + PoolVector<Plane> capsule_planes = Geometry::build_capsule_planes(0.5, 0.7, 12, Vector3::AXIS_Z); RID capsule_mesh = vs->mesh_create(); Geometry::MeshData capsule_data = Geometry::build_convex_mesh(capsule_planes); - vs->mesh_add_surface_from_mesh_data(capsule_mesh,capsule_data); + vs->mesh_add_surface_from_mesh_data(capsule_mesh, capsule_data); - type_mesh_map[PhysicsServer::SHAPE_CAPSULE]=capsule_mesh; + type_mesh_map[PhysicsServer::SHAPE_CAPSULE] = capsule_mesh; - RID capsule_shape=ps->shape_create(PhysicsServer::SHAPE_CAPSULE); + RID capsule_shape = ps->shape_create(PhysicsServer::SHAPE_CAPSULE); Dictionary capsule_params; - capsule_params["radius"]=0.5; - capsule_params["height"]=1.4; - ps->shape_set_data( capsule_shape, capsule_params ); - type_shape_map[PhysicsServer::SHAPE_CAPSULE]=capsule_shape; + capsule_params["radius"] = 0.5; + capsule_params["height"] = 1.4; + ps->shape_set_data(capsule_shape, capsule_params); + type_shape_map[PhysicsServer::SHAPE_CAPSULE] = capsule_shape; /* CONVEX SHAPE */ - PoolVector<Plane> convex_planes = Geometry::build_cylinder_planes(0.5,0.7,5,Vector3::AXIS_Z); + PoolVector<Plane> convex_planes = Geometry::build_cylinder_planes(0.5, 0.7, 5, Vector3::AXIS_Z); RID convex_mesh = vs->mesh_create(); Geometry::MeshData convex_data = Geometry::build_convex_mesh(convex_planes); - QuickHull::build(convex_data.vertices,convex_data); - vs->mesh_add_surface_from_mesh_data(convex_mesh,convex_data); + QuickHull::build(convex_data.vertices, convex_data); + vs->mesh_add_surface_from_mesh_data(convex_mesh, convex_data); - type_mesh_map[PhysicsServer::SHAPE_CONVEX_POLYGON]=convex_mesh; - - RID convex_shape=ps->shape_create(PhysicsServer::SHAPE_CONVEX_POLYGON); - ps->shape_set_data( convex_shape, convex_data.vertices ); - type_shape_map[PhysicsServer::SHAPE_CONVEX_POLYGON]=convex_shape; + type_mesh_map[PhysicsServer::SHAPE_CONVEX_POLYGON] = convex_mesh; + RID convex_shape = ps->shape_create(PhysicsServer::SHAPE_CONVEX_POLYGON); + ps->shape_set_data(convex_shape, convex_data.vertices); + type_shape_map[PhysicsServer::SHAPE_CONVEX_POLYGON] = convex_shape; } - void make_trimesh(Vector<Vector3> p_faces,const Transform& p_xform=Transform()) { + void make_trimesh(Vector<Vector3> p_faces, const Transform &p_xform = Transform()) { - VisualServer *vs=VisualServer::get_singleton(); - PhysicsServer * ps = PhysicsServer::get_singleton(); + VisualServer *vs = VisualServer::get_singleton(); + PhysicsServer *ps = PhysicsServer::get_singleton(); RID trimesh_shape = ps->shape_create(PhysicsServer::SHAPE_CONCAVE_POLYGON); ps->shape_set_data(trimesh_shape, p_faces); - p_faces=ps->shape_get_data(trimesh_shape); // optimized one + p_faces = ps->shape_get_data(trimesh_shape); // optimized one Vector<Vector3> normals; // for drawing - for (int i=0;i<p_faces.size()/3;i++) { + for (int i = 0; i < p_faces.size() / 3; i++) { - Plane p( p_faces[i*3+0],p_faces[i*3+1], p_faces[i*3+2] ); + Plane p(p_faces[i * 3 + 0], p_faces[i * 3 + 1], p_faces[i * 3 + 2]); normals.push_back(p.normal); normals.push_back(p.normal); normals.push_back(p.normal); @@ -210,95 +204,85 @@ protected: RID trimesh_mesh = vs->mesh_create(); Array d; d.resize(VS::ARRAY_MAX); - d[VS::ARRAY_VERTEX]=p_faces; - d[VS::ARRAY_NORMAL]=normals; - vs->mesh_add_surface_from_arrays(trimesh_mesh, VS::PRIMITIVE_TRIANGLES, d ); + d[VS::ARRAY_VERTEX] = p_faces; + d[VS::ARRAY_NORMAL] = normals; + vs->mesh_add_surface_from_arrays(trimesh_mesh, VS::PRIMITIVE_TRIANGLES, d); //vs->material_set_flag( trimesh_mat, VisualServer::MATERIAL_FLAG_UNSHADED,true); + RID triins = vs->instance_create2(trimesh_mesh, scenario); - RID triins = vs->instance_create2(trimesh_mesh,scenario); - - - RID tribody = ps->body_create( PhysicsServer::BODY_MODE_STATIC); - ps->body_set_space(tribody,space); + RID tribody = ps->body_create(PhysicsServer::BODY_MODE_STATIC); + ps->body_set_space(tribody, space); //todo set space ps->body_add_shape(tribody, trimesh_shape); Transform tritrans = p_xform; - ps->body_set_state( tribody, PhysicsServer::BODY_STATE_TRANSFORM, tritrans ); - vs->instance_set_transform( triins, tritrans ); + ps->body_set_state(tribody, PhysicsServer::BODY_STATE_TRANSFORM, tritrans); + vs->instance_set_transform(triins, tritrans); //RID trimesh_material = vs->fixed_material_create(); //vs->material_generate( trimesh_material, Color(0.2,0.4,0.6) ); //vs->mesh_surface_set_material( trimesh_mesh, 0, trimesh_material ); - } - void make_grid(int p_width,int p_height,float p_cellsize,float p_cellheight,const Transform& p_xform=Transform()) { + void make_grid(int p_width, int p_height, float p_cellsize, float p_cellheight, const Transform &p_xform = Transform()) { - Vector< Vector< float > > grid; + Vector<Vector<float> > grid; grid.resize(p_width); - for (int i=0;i<p_width;i++) { + for (int i = 0; i < p_width; i++) { grid[i].resize(p_height); - for (int j=0;j<p_height;j++) { + for (int j = 0; j < p_height; j++) { - grid[i][j]=1.0+Math::random(-p_cellheight, p_cellheight ); + grid[i][j] = 1.0 + Math::random(-p_cellheight, p_cellheight); } } Vector<Vector3> faces; - for (int i=1;i<p_width;i++) { - - for (int j=1;j<p_height;j++) { - + for (int i = 1; i < p_width; i++) { -#define MAKE_VERTEX(m_x,m_z)\ - faces.push_back( Vector3( (m_x-p_width/2)*p_cellsize, grid[m_x][m_z], (m_z-p_height/2)*p_cellsize ) ) + for (int j = 1; j < p_height; j++) { - MAKE_VERTEX(i,j-1); - MAKE_VERTEX(i,j); - MAKE_VERTEX(i-1,j); +#define MAKE_VERTEX(m_x, m_z) \ + faces.push_back(Vector3((m_x - p_width / 2) * p_cellsize, grid[m_x][m_z], (m_z - p_height / 2) * p_cellsize)) - MAKE_VERTEX(i-1,j-1); - MAKE_VERTEX(i,j-1); - MAKE_VERTEX(i-1,j); + MAKE_VERTEX(i, j - 1); + MAKE_VERTEX(i, j); + MAKE_VERTEX(i - 1, j); + MAKE_VERTEX(i - 1, j - 1); + MAKE_VERTEX(i, j - 1); + MAKE_VERTEX(i - 1, j); } } - make_trimesh(faces,p_xform); - + make_trimesh(faces, p_xform); } - public: - virtual void input_event(const InputEvent& p_event) { - - if (p_event.type==InputEvent::MOUSE_MOTION && p_event.mouse_motion.button_mask&4) { + virtual void input_event(const InputEvent &p_event) { - ofs_y-=p_event.mouse_motion.relative_y/200.0; - ofs_x+=p_event.mouse_motion.relative_x/200.0; + if (p_event.type == InputEvent::MOUSE_MOTION && p_event.mouse_motion.button_mask & 4) { + ofs_y -= p_event.mouse_motion.relative_y / 200.0; + ofs_x += p_event.mouse_motion.relative_x / 200.0; } - if (p_event.type==InputEvent::MOUSE_MOTION && p_event.mouse_motion.button_mask&1) { + if (p_event.type == InputEvent::MOUSE_MOTION && p_event.mouse_motion.button_mask & 1) { - float y=-p_event.mouse_motion.relative_y/20.0; - float x=p_event.mouse_motion.relative_x/20.0; + float y = -p_event.mouse_motion.relative_y / 20.0; + float x = p_event.mouse_motion.relative_x / 20.0; if (mover.is_valid()) { + PhysicsServer *ps = PhysicsServer::get_singleton(); + Transform t = ps->body_get_state(mover, PhysicsServer::BODY_STATE_TRANSFORM); + t.origin += Vector3(x, y, 0); - PhysicsServer * ps = PhysicsServer::get_singleton(); - Transform t = ps->body_get_state(mover,PhysicsServer::BODY_STATE_TRANSFORM); - t.origin+=Vector3(x,y,0); - - ps->body_set_state(mover,PhysicsServer::BODY_STATE_TRANSFORM,t); + ps->body_set_state(mover, PhysicsServer::BODY_STATE_TRANSFORM, t); } - } if (p_event.type == InputEvent::JOYPAD_MOTION) { @@ -317,30 +301,28 @@ public: virtual void request_quit() { - quit=true; + quit = true; } virtual void init() { - ofs_x=ofs_y=0; + ofs_x = ofs_y = 0; init_shapes(); PhysicsServer *ps = PhysicsServer::get_singleton(); - space=ps->space_create(); - ps->space_set_active(space,true); + space = ps->space_create(); + ps->space_set_active(space, true); - VisualServer *vs=VisualServer::get_singleton(); + VisualServer *vs = VisualServer::get_singleton(); /* LIGHT */ - RID lightaux = vs->light_create( VisualServer::LIGHT_DIRECTIONAL ); + RID lightaux = vs->light_create(VisualServer::LIGHT_DIRECTIONAL); //vs->light_set_color( lightaux, VisualServer::LIGHT_COLOR_AMBIENT, Color(0.0,0.0,0.0) ); scenario = vs->scenario_create(); - vs->light_set_shadow(lightaux,true); - light = vs->instance_create2( lightaux,scenario ); + vs->light_set_shadow(lightaux, true); + light = vs->instance_create2(lightaux, scenario); Transform t; - t.rotate(Vector3(1.0,0,0),0.6); - vs->instance_set_transform(light,t); - - + t.rotate(Vector3(1.0, 0, 0), 0.6); + vs->instance_set_transform(light, t); /* CAMERA */ @@ -348,29 +330,27 @@ public: RID viewport = vs->viewport_create(); Size2i screen_size = OS::get_singleton()->get_window_size(); - vs->viewport_set_size(viewport,screen_size.x,screen_size.y); - vs->viewport_attach_to_screen(viewport,Rect2(Vector2(),screen_size)); - vs->viewport_set_active(viewport,true); - vs->viewport_attach_camera( viewport, camera ); - vs->viewport_set_scenario( viewport, scenario ); - - - vs->camera_set_perspective(camera,60,0.1,40.0); - vs->camera_set_transform(camera,Transform( Basis(), Vector3(0,9,12))); + vs->viewport_set_size(viewport, screen_size.x, screen_size.y); + vs->viewport_attach_to_screen(viewport, Rect2(Vector2(), screen_size)); + vs->viewport_set_active(viewport, true); + vs->viewport_attach_camera(viewport, camera); + vs->viewport_set_scenario(viewport, scenario); + + vs->camera_set_perspective(camera, 60, 0.1, 40.0); + vs->camera_set_transform(camera, Transform(Basis(), Vector3(0, 9, 12))); //vs->scenario_set_debug(scenario,VS::SCENARIO_DEBUG_WIREFRAME); Transform gxf; - gxf.basis.scale(Vector3(1.4,0.4,1.4)); - gxf.origin=Vector3(-2,1,-2); - make_grid(5,5,2.5,1,gxf); + gxf.basis.scale(Vector3(1.4, 0.4, 1.4)); + gxf.origin = Vector3(-2, 1, -2); + make_grid(5, 5, 2.5, 1, gxf); //create_body(PhysicsServer::SHAPE_BOX,PhysicsServer::BODY_MODE_STATIC,gxf); //create_static_plane( Plane( Vector3(0,1,0), -2) ); //test_joint(); test_fall(); //test_joint(); - -/* + /* Vector<Vector3> faces; faces.push_back( Vector3(10,0,-5) ); faces.push_back( Vector3(0,0,10) ); @@ -378,7 +358,7 @@ public: make_trimesh(faces); */ /* Make Trimesh */ - quit=false; + quit = false; return; #if 0 @@ -400,9 +380,8 @@ public: for (int j=1;j<GRID_SIZE;j++) { - -#define MAKE_VERTEX(m_x,m_z)\ - faces.push_back( Vector3( m_x-GRID_SIZE/2.0, grid[m_x][m_z], m_z-GRID_SIZE/2.0 )*3.0 ) +#define MAKE_VERTEX(m_x, m_z) \ + faces.push_back(Vector3(m_x - GRID_SIZE / 2.0, grid[m_x][m_z], m_z - GRID_SIZE / 2.0) * 3.0) MAKE_VERTEX(i,j-1); MAKE_VERTEX(i,j); @@ -458,24 +437,22 @@ public: if (mover.is_valid()) { static float joy_speed = 10; - PhysicsServer * ps = PhysicsServer::get_singleton(); - Transform t = ps->body_get_state(mover,PhysicsServer::BODY_STATE_TRANSFORM); - t.origin+=Vector3(joy_speed * joy_direction.x * p_time, -joy_speed * joy_direction.y * p_time,0); - ps->body_set_state(mover,PhysicsServer::BODY_STATE_TRANSFORM,t); + PhysicsServer *ps = PhysicsServer::get_singleton(); + Transform t = ps->body_get_state(mover, PhysicsServer::BODY_STATE_TRANSFORM); + t.origin += Vector3(joy_speed * joy_direction.x * p_time, -joy_speed * joy_direction.y * p_time, 0); + ps->body_set_state(mover, PhysicsServer::BODY_STATE_TRANSFORM, t); }; - Transform cameratr; - cameratr.rotate(Vector3(0,1,0),ofs_x); - cameratr.rotate(Vector3(1,0,0),-ofs_y); - cameratr.translate(Vector3(0,2,8)); - VisualServer *vs=VisualServer::get_singleton(); - vs->camera_set_transform(camera,cameratr); + cameratr.rotate(Vector3(0, 1, 0), ofs_x); + cameratr.rotate(Vector3(1, 0, 0), -ofs_y); + cameratr.translate(Vector3(0, 2, 8)); + VisualServer *vs = VisualServer::get_singleton(); + vs->camera_set_transform(camera, cameratr); return quit; } virtual void finish() { - } void test_joint() { @@ -535,115 +512,93 @@ public: void test_character() { - VisualServer *vs=VisualServer::get_singleton(); - PhysicsServer * ps = PhysicsServer::get_singleton(); - + VisualServer *vs = VisualServer::get_singleton(); + PhysicsServer *ps = PhysicsServer::get_singleton(); - PoolVector<Plane> capsule_planes = Geometry::build_capsule_planes(0.5,1,12,5,Vector3::AXIS_Y); + PoolVector<Plane> capsule_planes = Geometry::build_capsule_planes(0.5, 1, 12, 5, Vector3::AXIS_Y); RID capsule_mesh = vs->mesh_create(); Geometry::MeshData capsule_data = Geometry::build_convex_mesh(capsule_planes); - vs->mesh_add_surface_from_mesh_data(capsule_mesh,capsule_data); - type_mesh_map[PhysicsServer::SHAPE_CAPSULE]=capsule_mesh; + vs->mesh_add_surface_from_mesh_data(capsule_mesh, capsule_data); + type_mesh_map[PhysicsServer::SHAPE_CAPSULE] = capsule_mesh; - RID capsule_shape=ps->shape_create(PhysicsServer::SHAPE_CAPSULE); + RID capsule_shape = ps->shape_create(PhysicsServer::SHAPE_CAPSULE); Dictionary capsule_params; - capsule_params["radius"]=0.5; - capsule_params["height"]=1; + capsule_params["radius"] = 0.5; + capsule_params["height"] = 1; Transform shape_xform; - shape_xform.rotate(Vector3(1,0,0),Math_PI/2.0); + shape_xform.rotate(Vector3(1, 0, 0), Math_PI / 2.0); //shape_xform.origin=Vector3(1,1,1); - ps->shape_set_data( capsule_shape, capsule_params); - + ps->shape_set_data(capsule_shape, capsule_params); - RID mesh_instance = vs->instance_create2(capsule_mesh,scenario); + RID mesh_instance = vs->instance_create2(capsule_mesh, scenario); character = ps->body_create(PhysicsServer::BODY_MODE_CHARACTER); - ps->body_set_space(character,space); + ps->body_set_space(character, space); //todo add space - ps->body_add_shape(character,capsule_shape); + ps->body_add_shape(character, capsule_shape); - ps->body_set_force_integration_callback(character,this,"body_changed_transform",mesh_instance); + ps->body_set_force_integration_callback(character, this, "body_changed_transform", mesh_instance); - - ps->body_set_state( character, PhysicsServer::BODY_STATE_TRANSFORM,Transform(Basis(),Vector3(-2,5,-2))); + ps->body_set_state(character, PhysicsServer::BODY_STATE_TRANSFORM, Transform(Basis(), Vector3(-2, 5, -2))); bodies.push_back(character); - - } void test_fall() { + for (int i = 0; i < 35; i++) { - for (int i=0;i<35;i++) { - - static const PhysicsServer::ShapeType shape_idx[]={ + static const PhysicsServer::ShapeType shape_idx[] = { PhysicsServer::SHAPE_CAPSULE, PhysicsServer::SHAPE_BOX, PhysicsServer::SHAPE_SPHERE, PhysicsServer::SHAPE_CONVEX_POLYGON }; - PhysicsServer::ShapeType type=shape_idx[i%4]; + PhysicsServer::ShapeType type = shape_idx[i % 4]; //type=PhysicsServer::SHAPE_CONVEX_POLYGON; Transform t; - t.origin=Vector3(0.0*i,3.5+1.1*i,0.7+0.0*i); + t.origin = Vector3(0.0 * i, 3.5 + 1.1 * i, 0.7 + 0.0 * i); //t.origin=Vector3(-0.7+0.0*i,0.5+4.1*i,0); - t.basis.rotate(Vector3(0.2,-1,0),Math_PI/2*0.6); + t.basis.rotate(Vector3(0.2, -1, 0), Math_PI / 2 * 0.6); //t.basis.rotate(Vector3(0,-1,0),Math_PI/4*i); //t.basis.rotate(Vector3(0,-1,0),Math_PI/4*i); //t.basis.rotate(Vector3(-1,0,0),Math_PI/4*i); - - create_body(type,PhysicsServer::BODY_MODE_RIGID,t); + create_body(type, PhysicsServer::BODY_MODE_RIGID, t); //RID b = create_body(type,i==0?PhysicsServer::BODY_MODE_STATIC:PhysicsServer::BODY_MODE_RIGID,t); - } - create_static_plane( Plane( Vector3(0,1,0), -1) ); - + create_static_plane(Plane(Vector3(0, 1, 0), -1)); -/* + /* create_static_plane( Plane( Vector3(1,0,0), -2) ); create_static_plane( Plane( Vector3(-1,0,0), -2) ); create_static_plane( Plane( Vector3(0,0,1), -2) ); create_static_plane( Plane( Vector3(0,0,-1), -2) ); */ - - } void test_activate() { - create_body(PhysicsServer::SHAPE_BOX,PhysicsServer::BODY_MODE_RIGID,Transform(Basis(),Vector3(0,2,0)),true); + create_body(PhysicsServer::SHAPE_BOX, PhysicsServer::BODY_MODE_RIGID, Transform(Basis(), Vector3(0, 2, 0)), true); //create_body(PhysicsServer::SHAPE_SPHERE,PhysicsServer::BODY_MODE_RIGID,Transform(Basis(),Vector3(0,6,0)),true); - create_static_plane( Plane( Vector3(0,1,0), -1) ); - + create_static_plane(Plane(Vector3(0, 1, 0), -1)); } - virtual bool idle(float p_time) { return false; } - - - - - - TestPhysicsMainLoop() { - } }; namespace TestPhysics { -MainLoop* test() { - - return memnew( TestPhysicsMainLoop ); +MainLoop *test() { + return memnew(TestPhysicsMainLoop); } - } diff --git a/main/tests/test_physics.h b/main/tests/test_physics.h index 68693fd931..a0dc15e421 100644 --- a/main/tests/test_physics.h +++ b/main/tests/test_physics.h @@ -37,8 +37,7 @@ namespace TestPhysics { -MainLoop* test(); - +MainLoop *test(); } #endif diff --git a/main/tests/test_physics_2d.cpp b/main/tests/test_physics_2d.cpp index 4321a356f5..8818c4b595 100644 --- a/main/tests/test_physics_2d.cpp +++ b/main/tests/test_physics_2d.cpp @@ -28,23 +28,21 @@ /*************************************************************************/ #include "test_physics_2d.h" -#include "servers/visual_server.h" -#include "servers/physics_2d_server.h" +#include "map.h" #include "os/main_loop.h" +#include "os/os.h" #include "print_string.h" -#include "map.h" #include "scene/resources/texture.h" -#include "os/os.h" +#include "servers/physics_2d_server.h" +#include "servers/visual_server.h" -static const unsigned char convex_png[]={ -0x89,0x50,0x4e,0x47,0xd,0xa,0x1a,0xa,0x0,0x0,0x0,0xd,0x49,0x48,0x44,0x52,0x0,0x0,0x0,0x40,0x0,0x0,0x0,0x40,0x8,0x6,0x0,0x0,0x0,0xaa,0x69,0x71,0xde,0x0,0x0,0x0,0x1,0x73,0x52,0x47,0x42,0x0,0xae,0xce,0x1c,0xe9,0x0,0x0,0x0,0x6,0x62,0x4b,0x47,0x44,0x0,0x0,0x0,0x0,0x0,0x0,0xf9,0x43,0xbb,0x7f,0x0,0x0,0x0,0x9,0x70,0x48,0x59,0x73,0x0,0x0,0xb,0x13,0x0,0x0,0xb,0x13,0x1,0x0,0x9a,0x9c,0x18,0x0,0x0,0x0,0x7,0x74,0x49,0x4d,0x45,0x7,0xdb,0x6,0xa,0x3,0x13,0x31,0x66,0xa7,0xac,0x79,0x0,0x0,0x4,0xef,0x49,0x44,0x41,0x54,0x78,0xda,0xed,0x9b,0xdd,0x4e,0x2a,0x57,0x14,0xc7,0xf7,0x1e,0xc0,0x19,0x38,0x32,0x80,0xa,0x6a,0xda,0x18,0xa3,0xc6,0x47,0x50,0x7b,0xa1,0xd9,0x36,0x27,0x7e,0x44,0xed,0x45,0x4d,0x93,0x3e,0x40,0x1f,0x64,0x90,0xf4,0x1,0xbc,0xf0,0xc2,0x9c,0x57,0x30,0x4d,0xbc,0xa8,0x6d,0xc,0x69,0x26,0xb5,0x68,0x8b,0x35,0x7e,0x20,0xb4,0xf5,0x14,0xbf,0x51,0x3c,0x52,0xe,0xc,0xe,0xc8,0xf0,0xb1,0x7a,0x51,0x3d,0xb1,0x9e,0x19,0x1c,0x54,0x70,0x1c,0xdc,0x9,0x17,0x64,0x8,0xc9,0xff,0xb7,0xd6,0x7f,0xcd,0x3f,0x2b,0xd9,0x8,0xbd,0x9c,0xda,0x3e,0xf8,0x31,0xff,0xc,0x0,0x8,0x42,0x88,0x9c,0x9f,0x9f,0xbf,0xa,0x87,0xc3,0xad,0x7d,0x7d,0x7d,0x7f,0x23,0x84,0x78,0x8c,0x31,0xaf,0x55,0x0,0xc6,0xc7,0x14,0x1e,0x8f,0xc7,0xbf,0x38,0x3c,0x3c,0x6c,0x9b,0x9f,0x9f,0x6f,0xb8,0x82,0x9b,0xee,0xe8,0xe8,0xf8,0x12,0x0,0xbe,0xd3,0x2a,0x8,0xfc,0x50,0xd1,0xf9,0x7c,0x9e,0x8a,0x46,0xa3,0x5f,0x9d,0x9e,0x9e,0x7e,0xb2,0xb0,0xb0,0x60,0xe5,0x79,0x1e,0xf1,0xfc,0x7f,0x3a,0x9,0x21,0x88,0x10,0x82,0x26,0x26,0x26,0xde,0x77,0x75,0x75,0x85,0x59,0x96,0xfd,0x5e,0x6b,0x20,0xf0,0x7d,0x85,0x4b,0x92,0xf4,0xfa,0xe0,0xe0,0xe0,0xd3,0xb9,0xb9,0xb9,0x46,0x49,0x92,0xea,0x6f,0xa,0xbf,0x7d,0x8,0x21,0x68,0x70,0x70,0xb0,0x38,0x39,0x39,0x79,0xd6,0xd9,0xd9,0xb9,0xcf,0x30,0xcc,0xa2,0xd6,0xad,0x21,0x2b,0x1c,0x0,0x38,0x41,0x10,0xfc,0xdb,0xdb,0xdb,0x27,0x1e,0x8f,0x27,0x4b,0x8,0x1,0x84,0x90,0xea,0xf,0x21,0x4,0x3c,0x1e,0x4f,0x76,0x67,0x67,0x67,0x3f,0x9f,0xcf,0xff,0x7c,0x5,0xf3,0xd9,0x0,0xe0,0x2,0x81,0xc0,0xa9,0xdb,0xed,0x2e,0x94,0x2b,0x5c,0xe,0xc4,0xca,0xca,0x8a,0x18,0x8d,0x46,0x3,0x0,0xc0,0x69,0x1e,0x4,0x0,0x90,0x48,0x24,0x12,0xe4,0x38,0xee,0x41,0xc2,0x6f,0x43,0xe0,0x38,0xe,0xfc,0x7e,0xbf,0x10,0x8b,0xc5,0xd6,0x35,0xd,0x22,0x9b,0xcd,0x7a,0x96,0x97,0x97,0x33,0xf,0xad,0x7c,0x29,0x10,0x9b,0x9b,0x9b,0xef,0x2e,0x2e,0x2e,0x7e,0xd5,0x1c,0x8,0x0,0x20,0xe1,0x70,0x38,0xfc,0x98,0xd5,0x57,0x2,0xe1,0x76,0xbb,0xf3,0xa1,0x50,0xe8,0x38,0x9b,0xcd,0xfe,0xa2,0x9,0x8,0x0,0x40,0x2e,0x2f,0x2f,0x7d,0x4b,0x4b,0x4b,0xb9,0x4a,0x54,0x5f,0x9,0xc4,0xd2,0xd2,0x92,0xb4,0xb7,0xb7,0xf7,0x36,0x97,0xcb,0x4d,0x3d,0x29,0x8,0x0,0xe0,0x42,0xa1,0xd0,0x71,0xb5,0xc4,0xdf,0xb6,0xc5,0x93,0xe,0x4a,0x0,0x20,0xa9,0x54,0xea,0x37,0xb7,0xdb,0x5d,0xa8,0xa6,0x78,0x39,0x10,0x6b,0x6b,0x6b,0xf1,0x64,0x32,0xb9,0x5a,0x55,0x10,0x0,0xc0,0x6d,0x6c,0x6c,0x9c,0x57,0xbb,0xfa,0x25,0x40,0x14,0x3,0x81,0x40,0x34,0x93,0xc9,0x2c,0x57,0x1c,0x4,0x0,0x90,0x58,0x2c,0xb6,0x5e,0xe9,0xc1,0x77,0x1f,0x10,0x53,0x53,0x53,0x52,0xc5,0x83,0x14,0x0,0x70,0x7e,0xbf,0x5f,0xd0,0x42,0xf5,0x95,0x40,0xf8,0x7c,0xbe,0xcb,0xa3,0xa3,0xa3,0x3f,0x1e,0xbd,0x1b,0x0,0x80,0x1c,0x1f,0x1f,0x87,0xb4,0x56,0xfd,0xaa,0x5,0x29,0x51,0x14,0xbf,0xf5,0xf9,0x7c,0x97,0x5a,0xad,0xbe,0x12,0x88,0xf5,0xf5,0xf5,0xd8,0x83,0x83,0x54,0xb5,0x42,0x8f,0x66,0x83,0x94,0xd6,0xbd,0x5f,0xce,0x7c,0x38,0x3c,0x3c,0xfc,0xb3,0x50,0x28,0xb8,0xcb,0x2,0x1,0x0,0xdc,0xf4,0xf4,0xf4,0xfe,0x73,0x15,0x2f,0x17,0xa4,0x22,0x91,0x48,0x50,0xb5,0x2d,0x0,0x80,0x9b,0x99,0x99,0x79,0xfb,0xdc,0x1,0xc8,0x5,0xa9,0x44,0x22,0xf1,0xfb,0x9d,0x10,0x0,0x80,0x9b,0x9d,0x9d,0xd,0xea,0x5,0xc0,0xad,0xfd,0x43,0x1a,0x0,0xb8,0xdb,0x9a,0xa9,0x8f,0xb6,0xa4,0x46,0xa3,0xa4,0xb7,0xd5,0x37,0xcf,0xf3,0x68,0x75,0x75,0xf5,0x4c,0xee,0x99,0x1c,0x80,0x9c,0x1e,0xf7,0xff,0x16,0x8b,0x45,0x50,0x5,0xa0,0xb7,0xb7,0xb7,0x85,0x10,0xa2,0x2b,0xf1,0x84,0x10,0xd4,0xdf,0xdf,0x6f,0x57,0x3,0x80,0x37,0x18,0xc,0x5,0x3d,0x2,0xa0,0x69,0x3a,0x8b,0x10,0xe2,0x4b,0x2,0xc0,0x18,0xf3,0xc1,0x60,0x70,0x47,0x8f,0x16,0x38,0x3a,0x3a,0x5a,0x93,0x5b,0xc3,0x7f,0x64,0x81,0xba,0xba,0x3a,0x49,0x8f,0x0,0x1a,0x1a,0x1a,0xd4,0xcd,0x0,0x93,0xc9,0xa4,0xcb,0x21,0xe8,0x74,0x3a,0xd5,0x1,0xa0,0x69,0x5a,0x77,0x1d,0x80,0x31,0x2e,0x38,0x9d,0x4e,0xb1,0x66,0x1,0x30,0xc,0x23,0x28,0x3d,0x93,0x9b,0x1,0xb9,0x9a,0x6,0x60,0x36,0x9b,0x75,0xd7,0x1,0x4a,0x21,0xa8,0x26,0x0,0x94,0xa,0x41,0xb2,0x0,0x18,0x86,0xc9,0xe9,0xd,0x80,0x52,0x8,0x92,0x5,0x60,0xb1,0x58,0x74,0x67,0x1,0xa5,0x10,0xa4,0x4,0x40,0x77,0x43,0xd0,0xe1,0x70,0xa8,0x9f,0x1,0x14,0x45,0x1,0x45,0x51,0x79,0x3d,0x1,0x68,0x6e,0x6e,0x4e,0xaa,0x6,0x80,0x10,0x42,0x6,0x83,0x41,0x37,0x36,0x28,0x15,0x82,0x6a,0x2,0x0,0x4d,0xd3,0xa9,0x52,0xcf,0x95,0x0,0xe8,0x66,0xe,0x98,0xcd,0x66,0xa1,0x6c,0x0,0x7a,0x5a,0x8b,0x59,0x2c,0x96,0x64,0xcd,0x2,0xb8,0x2b,0x4,0xe9,0xde,0x2,0x77,0x85,0xa0,0x9a,0xb0,0x40,0xa9,0x10,0xa4,0x8,0xc0,0x64,0x32,0xe9,0x6,0x40,0xa9,0x10,0x54,0xaa,0x3,0x74,0xf3,0x16,0x70,0xb9,0x5c,0xe5,0x3,0xe8,0xe9,0xe9,0x69,0xd5,0xc3,0x66,0x18,0x63,0x5c,0x68,0x6a,0x6a,0x12,0xcb,0x5,0xa0,0x9b,0xd5,0x38,0x4d,0xd3,0x29,0x8a,0xa2,0xa0,0x2c,0x0,0x18,0x63,0x3e,0x14,0xa,0xfd,0x55,0xb,0x21,0x48,0xd1,0x2,0x7a,0x59,0x8d,0xdf,0x1b,0x80,0x1e,0x56,0xe3,0x84,0x10,0x34,0x30,0x30,0x60,0xbb,0xeb,0x77,0x46,0x5,0xef,0x48,0xcf,0x4d,0xec,0x8d,0x99,0x5,0xf5,0xf5,0xf5,0xef,0x46,0x47,0x47,0xb,0x2e,0x97,0xeb,0xbc,0x54,0x8,0x52,0x4,0xc0,0x30,0x8c,0xf4,0x5c,0x4,0x9b,0x4c,0xa6,0xf4,0xf8,0xf8,0xb8,0xc8,0xb2,0x6c,0x32,0x9d,0x4e,0xff,0xd4,0xdd,0xdd,0x7d,0x66,0x34,0x1a,0x8b,0xd7,0x3,0xfd,0xae,0x5b,0x29,0xb2,0x57,0x66,0xb6,0xb6,0xb6,0xde,0xc4,0xe3,0xf1,0x6f,0xae,0xaf,0xc1,0x28,0x5d,0x85,0x79,0x2,0xc1,0x60,0xb5,0x5a,0xa3,0xa3,0xa3,0xa3,0x45,0xab,0xd5,0x9a,0x2a,0x16,0x8b,0x8b,0x6d,0x6d,0x6d,0xef,0xd5,0x8a,0x55,0xd,0x20,0x91,0x48,0xbc,0x3e,0x38,0x38,0xf8,0xda,0x6e,0xb7,0xf7,0x5f,0x5c,0x5c,0xd4,0x7b,0xbd,0xde,0xbc,0x20,0x8,0xcd,0x85,0x42,0x81,0xfe,0xf0,0xae,0xac,0x10,0x98,0x9b,0xd5,0xc5,0x18,0x17,0x59,0x96,0x3d,0x1d,0x19,0x19,0x1,0x96,0x65,0x5,0x8a,0xa2,0x7e,0x6c,0x69,0x69,0x49,0x3d,0x44,0xb0,0x2a,0x0,0x1f,0xcc,0x74,0x75,0x41,0xea,0xfa,0x7b,0x32,0x99,0x64,0x76,0x77,0x77,0x5d,0xe,0x87,0xa3,0x5f,0x14,0xc5,0x57,0x57,0x60,0x5a,0x8b,0xc5,0xa2,0xf1,0xbe,0x50,0x6e,0xa,0x66,0x18,0x26,0x31,0x36,0x36,0x96,0x65,0x59,0x36,0x29,0x49,0x92,0xb7,0xbd,0xbd,0xfd,0x9f,0x72,0xda,0xf9,0xd1,0x1,0xa8,0x1,0x93,0xcf,0xe7,0xa9,0x93,0x93,0x13,0x1b,0x4d,0xd3,0x9f,0xb,0x82,0x60,0xf5,0x7a,0xbd,0xd9,0x54,0x2a,0xe5,0xcc,0x64,0x32,0xe,0xb9,0x6e,0xb9,0x16,0x8c,0x31,0x2e,0xda,0x6c,0xb6,0xc8,0xd0,0xd0,0x10,0x65,0xb3,0xd9,0x92,0x95,0xa8,0x6e,0xc5,0x0,0xa8,0xe9,0x96,0x68,0x34,0x6a,0xdd,0xdf,0xdf,0x6f,0x76,0xb9,0x5c,0x9f,0x89,0xa2,0x58,0xbf,0xb8,0xb8,0x8,0x26,0x93,0x29,0x3b,0x3c,0x3c,0x8c,0xed,0x76,0x7b,0xd2,0x68,0x34,0xfe,0xd0,0xd8,0xd8,0x98,0xae,0xb6,0xe0,0x8a,0x1,0x50,0xb,0xe6,0xa9,0x5,0xbf,0x9c,0x97,0xf3,0xff,0xf3,0x2f,0x6a,0x82,0x7f,0xf6,0x4e,0xca,0x1b,0xf5,0x0,0x0,0x0,0x0,0x49,0x45,0x4e,0x44,0xae,0x42,0x60,0x82 +static const unsigned char convex_png[] = { + 0x89, 0x50, 0x4e, 0x47, 0xd, 0xa, 0x1a, 0xa, 0x0, 0x0, 0x0, 0xd, 0x49, 0x48, 0x44, 0x52, 0x0, 0x0, 0x0, 0x40, 0x0, 0x0, 0x0, 0x40, 0x8, 0x6, 0x0, 0x0, 0x0, 0xaa, 0x69, 0x71, 0xde, 0x0, 0x0, 0x0, 0x1, 0x73, 0x52, 0x47, 0x42, 0x0, 0xae, 0xce, 0x1c, 0xe9, 0x0, 0x0, 0x0, 0x6, 0x62, 0x4b, 0x47, 0x44, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0xf9, 0x43, 0xbb, 0x7f, 0x0, 0x0, 0x0, 0x9, 0x70, 0x48, 0x59, 0x73, 0x0, 0x0, 0xb, 0x13, 0x0, 0x0, 0xb, 0x13, 0x1, 0x0, 0x9a, 0x9c, 0x18, 0x0, 0x0, 0x0, 0x7, 0x74, 0x49, 0x4d, 0x45, 0x7, 0xdb, 0x6, 0xa, 0x3, 0x13, 0x31, 0x66, 0xa7, 0xac, 0x79, 0x0, 0x0, 0x4, 0xef, 0x49, 0x44, 0x41, 0x54, 0x78, 0xda, 0xed, 0x9b, 0xdd, 0x4e, 0x2a, 0x57, 0x14, 0xc7, 0xf7, 0x1e, 0xc0, 0x19, 0x38, 0x32, 0x80, 0xa, 0x6a, 0xda, 0x18, 0xa3, 0xc6, 0x47, 0x50, 0x7b, 0xa1, 0xd9, 0x36, 0x27, 0x7e, 0x44, 0xed, 0x45, 0x4d, 0x93, 0x3e, 0x40, 0x1f, 0x64, 0x90, 0xf4, 0x1, 0xbc, 0xf0, 0xc2, 0x9c, 0x57, 0x30, 0x4d, 0xbc, 0xa8, 0x6d, 0xc, 0x69, 0x26, 0xb5, 0x68, 0x8b, 0x35, 0x7e, 0x20, 0xb4, 0xf5, 0x14, 0xbf, 0x51, 0x3c, 0x52, 0xe, 0xc, 0xe, 0xc8, 0xf0, 0xb1, 0x7a, 0x51, 0x3d, 0xb1, 0x9e, 0x19, 0x1c, 0x54, 0x70, 0x1c, 0xdc, 0x9, 0x17, 0x64, 0x8, 0xc9, 0xff, 0xb7, 0xd6, 0x7f, 0xcd, 0x3f, 0x2b, 0xd9, 0x8, 0xbd, 0x9c, 0xda, 0x3e, 0xf8, 0x31, 0xff, 0xc, 0x0, 0x8, 0x42, 0x88, 0x9c, 0x9f, 0x9f, 0xbf, 0xa, 0x87, 0xc3, 0xad, 0x7d, 0x7d, 0x7d, 0x7f, 0x23, 0x84, 0x78, 0x8c, 0x31, 0xaf, 0x55, 0x0, 0xc6, 0xc7, 0x14, 0x1e, 0x8f, 0xc7, 0xbf, 0x38, 0x3c, 0x3c, 0x6c, 0x9b, 0x9f, 0x9f, 0x6f, 0xb8, 0x82, 0x9b, 0xee, 0xe8, 0xe8, 0xf8, 0x12, 0x0, 0xbe, 0xd3, 0x2a, 0x8, 0xfc, 0x50, 0xd1, 0xf9, 0x7c, 0x9e, 0x8a, 0x46, 0xa3, 0x5f, 0x9d, 0x9e, 0x9e, 0x7e, 0xb2, 0xb0, 0xb0, 0x60, 0xe5, 0x79, 0x1e, 0xf1, 0xfc, 0x7f, 0x3a, 0x9, 0x21, 0x88, 0x10, 0x82, 0x26, 0x26, 0x26, 0xde, 0x77, 0x75, 0x75, 0x85, 0x59, 0x96, 0xfd, 0x5e, 0x6b, 0x20, 0xf0, 0x7d, 0x85, 0x4b, 0x92, 0xf4, 0xfa, 0xe0, 0xe0, 0xe0, 0xd3, 0xb9, 0xb9, 0xb9, 0x46, 0x49, 0x92, 0xea, 0x6f, 0xa, 0xbf, 0x7d, 0x8, 0x21, 0x68, 0x70, 0x70, 0xb0, 0x38, 0x39, 0x39, 0x79, 0xd6, 0xd9, 0xd9, 0xb9, 0xcf, 0x30, 0xcc, 0xa2, 0xd6, 0xad, 0x21, 0x2b, 0x1c, 0x0, 0x38, 0x41, 0x10, 0xfc, 0xdb, 0xdb, 0xdb, 0x27, 0x1e, 0x8f, 0x27, 0x4b, 0x8, 0x1, 0x84, 0x90, 0xea, 0xf, 0x21, 0x4, 0x3c, 0x1e, 0x4f, 0x76, 0x67, 0x67, 0x67, 0x3f, 0x9f, 0xcf, 0xff, 0x7c, 0x5, 0xf3, 0xd9, 0x0, 0xe0, 0x2, 0x81, 0xc0, 0xa9, 0xdb, 0xed, 0x2e, 0x94, 0x2b, 0x5c, 0xe, 0xc4, 0xca, 0xca, 0x8a, 0x18, 0x8d, 0x46, 0x3, 0x0, 0xc0, 0x69, 0x1e, 0x4, 0x0, 0x90, 0x48, 0x24, 0x12, 0xe4, 0x38, 0xee, 0x41, 0xc2, 0x6f, 0x43, 0xe0, 0x38, 0xe, 0xfc, 0x7e, 0xbf, 0x10, 0x8b, 0xc5, 0xd6, 0x35, 0xd, 0x22, 0x9b, 0xcd, 0x7a, 0x96, 0x97, 0x97, 0x33, 0xf, 0xad, 0x7c, 0x29, 0x10, 0x9b, 0x9b, 0x9b, 0xef, 0x2e, 0x2e, 0x2e, 0x7e, 0xd5, 0x1c, 0x8, 0x0, 0x20, 0xe1, 0x70, 0x38, 0xfc, 0x98, 0xd5, 0x57, 0x2, 0xe1, 0x76, 0xbb, 0xf3, 0xa1, 0x50, 0xe8, 0x38, 0x9b, 0xcd, 0xfe, 0xa2, 0x9, 0x8, 0x0, 0x40, 0x2e, 0x2f, 0x2f, 0x7d, 0x4b, 0x4b, 0x4b, 0xb9, 0x4a, 0x54, 0x5f, 0x9, 0xc4, 0xd2, 0xd2, 0x92, 0xb4, 0xb7, 0xb7, 0xf7, 0x36, 0x97, 0xcb, 0x4d, 0x3d, 0x29, 0x8, 0x0, 0xe0, 0x42, 0xa1, 0xd0, 0x71, 0xb5, 0xc4, 0xdf, 0xb6, 0xc5, 0x93, 0xe, 0x4a, 0x0, 0x20, 0xa9, 0x54, 0xea, 0x37, 0xb7, 0xdb, 0x5d, 0xa8, 0xa6, 0x78, 0x39, 0x10, 0x6b, 0x6b, 0x6b, 0xf1, 0x64, 0x32, 0xb9, 0x5a, 0x55, 0x10, 0x0, 0xc0, 0x6d, 0x6c, 0x6c, 0x9c, 0x57, 0xbb, 0xfa, 0x25, 0x40, 0x14, 0x3, 0x81, 0x40, 0x34, 0x93, 0xc9, 0x2c, 0x57, 0x1c, 0x4, 0x0, 0x90, 0x58, 0x2c, 0xb6, 0x5e, 0xe9, 0xc1, 0x77, 0x1f, 0x10, 0x53, 0x53, 0x53, 0x52, 0xc5, 0x83, 0x14, 0x0, 0x70, 0x7e, 0xbf, 0x5f, 0xd0, 0x42, 0xf5, 0x95, 0x40, 0xf8, 0x7c, 0xbe, 0xcb, 0xa3, 0xa3, 0xa3, 0x3f, 0x1e, 0xbd, 0x1b, 0x0, 0x80, 0x1c, 0x1f, 0x1f, 0x87, 0xb4, 0x56, 0xfd, 0xaa, 0x5, 0x29, 0x51, 0x14, 0xbf, 0xf5, 0xf9, 0x7c, 0x97, 0x5a, 0xad, 0xbe, 0x12, 0x88, 0xf5, 0xf5, 0xf5, 0xd8, 0x83, 0x83, 0x54, 0xb5, 0x42, 0x8f, 0x66, 0x83, 0x94, 0xd6, 0xbd, 0x5f, 0xce, 0x7c, 0x38, 0x3c, 0x3c, 0xfc, 0xb3, 0x50, 0x28, 0xb8, 0xcb, 0x2, 0x1, 0x0, 0xdc, 0xf4, 0xf4, 0xf4, 0xfe, 0x73, 0x15, 0x2f, 0x17, 0xa4, 0x22, 0x91, 0x48, 0x50, 0xb5, 0x2d, 0x0, 0x80, 0x9b, 0x99, 0x99, 0x79, 0xfb, 0xdc, 0x1, 0xc8, 0x5, 0xa9, 0x44, 0x22, 0xf1, 0xfb, 0x9d, 0x10, 0x0, 0x80, 0x9b, 0x9d, 0x9d, 0xd, 0xea, 0x5, 0xc0, 0xad, 0xfd, 0x43, 0x1a, 0x0, 0xb8, 0xdb, 0x9a, 0xa9, 0x8f, 0xb6, 0xa4, 0x46, 0xa3, 0xa4, 0xb7, 0xd5, 0x37, 0xcf, 0xf3, 0x68, 0x75, 0x75, 0xf5, 0x4c, 0xee, 0x99, 0x1c, 0x80, 0x9c, 0x1e, 0xf7, 0xff, 0x16, 0x8b, 0x45, 0x50, 0x5, 0xa0, 0xb7, 0xb7, 0xb7, 0x85, 0x10, 0xa2, 0x2b, 0xf1, 0x84, 0x10, 0xd4, 0xdf, 0xdf, 0x6f, 0x57, 0x3, 0x80, 0x37, 0x18, 0xc, 0x5, 0x3d, 0x2, 0xa0, 0x69, 0x3a, 0x8b, 0x10, 0xe2, 0x4b, 0x2, 0xc0, 0x18, 0xf3, 0xc1, 0x60, 0x70, 0x47, 0x8f, 0x16, 0x38, 0x3a, 0x3a, 0x5a, 0x93, 0x5b, 0xc3, 0x7f, 0x64, 0x81, 0xba, 0xba, 0x3a, 0x49, 0x8f, 0x0, 0x1a, 0x1a, 0x1a, 0xd4, 0xcd, 0x0, 0x93, 0xc9, 0xa4, 0xcb, 0x21, 0xe8, 0x74, 0x3a, 0xd5, 0x1, 0xa0, 0x69, 0x5a, 0x77, 0x1d, 0x80, 0x31, 0x2e, 0x38, 0x9d, 0x4e, 0xb1, 0x66, 0x1, 0x30, 0xc, 0x23, 0x28, 0x3d, 0x93, 0x9b, 0x1, 0xb9, 0x9a, 0x6, 0x60, 0x36, 0x9b, 0x75, 0xd7, 0x1, 0x4a, 0x21, 0xa8, 0x26, 0x0, 0x94, 0xa, 0x41, 0xb2, 0x0, 0x18, 0x86, 0xc9, 0xe9, 0xd, 0x80, 0x52, 0x8, 0x92, 0x5, 0x60, 0xb1, 0x58, 0x74, 0x67, 0x1, 0xa5, 0x10, 0xa4, 0x4, 0x40, 0x77, 0x43, 0xd0, 0xe1, 0x70, 0xa8, 0x9f, 0x1, 0x14, 0x45, 0x1, 0x45, 0x51, 0x79, 0x3d, 0x1, 0x68, 0x6e, 0x6e, 0x4e, 0xaa, 0x6, 0x80, 0x10, 0x42, 0x6, 0x83, 0x41, 0x37, 0x36, 0x28, 0x15, 0x82, 0x6a, 0x2, 0x0, 0x4d, 0xd3, 0xa9, 0x52, 0xcf, 0x95, 0x0, 0xe8, 0x66, 0xe, 0x98, 0xcd, 0x66, 0xa1, 0x6c, 0x0, 0x7a, 0x5a, 0x8b, 0x59, 0x2c, 0x96, 0x64, 0xcd, 0x2, 0xb8, 0x2b, 0x4, 0xe9, 0xde, 0x2, 0x77, 0x85, 0xa0, 0x9a, 0xb0, 0x40, 0xa9, 0x10, 0xa4, 0x8, 0xc0, 0x64, 0x32, 0xe9, 0x6, 0x40, 0xa9, 0x10, 0x54, 0xaa, 0x3, 0x74, 0xf3, 0x16, 0x70, 0xb9, 0x5c, 0xe5, 0x3, 0xe8, 0xe9, 0xe9, 0x69, 0xd5, 0xc3, 0x66, 0x18, 0x63, 0x5c, 0x68, 0x6a, 0x6a, 0x12, 0xcb, 0x5, 0xa0, 0x9b, 0xd5, 0x38, 0x4d, 0xd3, 0x29, 0x8a, 0xa2, 0xa0, 0x2c, 0x0, 0x18, 0x63, 0x3e, 0x14, 0xa, 0xfd, 0x55, 0xb, 0x21, 0x48, 0xd1, 0x2, 0x7a, 0x59, 0x8d, 0xdf, 0x1b, 0x80, 0x1e, 0x56, 0xe3, 0x84, 0x10, 0x34, 0x30, 0x30, 0x60, 0xbb, 0xeb, 0x77, 0x46, 0x5, 0xef, 0x48, 0xcf, 0x4d, 0xec, 0x8d, 0x99, 0x5, 0xf5, 0xf5, 0xf5, 0xef, 0x46, 0x47, 0x47, 0xb, 0x2e, 0x97, 0xeb, 0xbc, 0x54, 0x8, 0x52, 0x4, 0xc0, 0x30, 0x8c, 0xf4, 0x5c, 0x4, 0x9b, 0x4c, 0xa6, 0xf4, 0xf8, 0xf8, 0xb8, 0xc8, 0xb2, 0x6c, 0x32, 0x9d, 0x4e, 0xff, 0xd4, 0xdd, 0xdd, 0x7d, 0x66, 0x34, 0x1a, 0x8b, 0xd7, 0x3, 0xfd, 0xae, 0x5b, 0x29, 0xb2, 0x57, 0x66, 0xb6, 0xb6, 0xb6, 0xde, 0xc4, 0xe3, 0xf1, 0x6f, 0xae, 0xaf, 0xc1, 0x28, 0x5d, 0x85, 0x79, 0x2, 0xc1, 0x60, 0xb5, 0x5a, 0xa3, 0xa3, 0xa3, 0xa3, 0x45, 0xab, 0xd5, 0x9a, 0x2a, 0x16, 0x8b, 0x8b, 0x6d, 0x6d, 0x6d, 0xef, 0xd5, 0x8a, 0x55, 0xd, 0x20, 0x91, 0x48, 0xbc, 0x3e, 0x38, 0x38, 0xf8, 0xda, 0x6e, 0xb7, 0xf7, 0x5f, 0x5c, 0x5c, 0xd4, 0x7b, 0xbd, 0xde, 0xbc, 0x20, 0x8, 0xcd, 0x85, 0x42, 0x81, 0xfe, 0xf0, 0xae, 0xac, 0x10, 0x98, 0x9b, 0xd5, 0xc5, 0x18, 0x17, 0x59, 0x96, 0x3d, 0x1d, 0x19, 0x19, 0x1, 0x96, 0x65, 0x5, 0x8a, 0xa2, 0x7e, 0x6c, 0x69, 0x69, 0x49, 0x3d, 0x44, 0xb0, 0x2a, 0x0, 0x1f, 0xcc, 0x74, 0x75, 0x41, 0xea, 0xfa, 0x7b, 0x32, 0x99, 0x64, 0x76, 0x77, 0x77, 0x5d, 0xe, 0x87, 0xa3, 0x5f, 0x14, 0xc5, 0x57, 0x57, 0x60, 0x5a, 0x8b, 0xc5, 0xa2, 0xf1, 0xbe, 0x50, 0x6e, 0xa, 0x66, 0x18, 0x26, 0x31, 0x36, 0x36, 0x96, 0x65, 0x59, 0x36, 0x29, 0x49, 0x92, 0xb7, 0xbd, 0xbd, 0xfd, 0x9f, 0x72, 0xda, 0xf9, 0xd1, 0x1, 0xa8, 0x1, 0x93, 0xcf, 0xe7, 0xa9, 0x93, 0x93, 0x13, 0x1b, 0x4d, 0xd3, 0x9f, 0xb, 0x82, 0x60, 0xf5, 0x7a, 0xbd, 0xd9, 0x54, 0x2a, 0xe5, 0xcc, 0x64, 0x32, 0xe, 0xb9, 0x6e, 0xb9, 0x16, 0x8c, 0x31, 0x2e, 0xda, 0x6c, 0xb6, 0xc8, 0xd0, 0xd0, 0x10, 0x65, 0xb3, 0xd9, 0x92, 0x95, 0xa8, 0x6e, 0xc5, 0x0, 0xa8, 0xe9, 0x96, 0x68, 0x34, 0x6a, 0xdd, 0xdf, 0xdf, 0x6f, 0x76, 0xb9, 0x5c, 0x9f, 0x89, 0xa2, 0x58, 0xbf, 0xb8, 0xb8, 0x8, 0x26, 0x93, 0x29, 0x3b, 0x3c, 0x3c, 0x8c, 0xed, 0x76, 0x7b, 0xd2, 0x68, 0x34, 0xfe, 0xd0, 0xd8, 0xd8, 0x98, 0xae, 0xb6, 0xe0, 0x8a, 0x1, 0x50, 0xb, 0xe6, 0xa9, 0x5, 0xbf, 0x9c, 0x97, 0xf3, 0xff, 0xf3, 0x2f, 0x6a, 0x82, 0x7f, 0xf6, 0x4e, 0xca, 0x1b, 0xf5, 0x0, 0x0, 0x0, 0x0, 0x49, 0x45, 0x4e, 0x44, 0xae, 0x42, 0x60, 0x82 }; - class TestPhysics2DMainLoop : public MainLoop { - GDCLASS( TestPhysics2DMainLoop, MainLoop ); - + GDCLASS(TestPhysics2DMainLoop, MainLoop); RID circle_img; RID circle_shape; @@ -54,8 +52,7 @@ class TestPhysics2DMainLoop : public MainLoop { RID ray_query; Transform2D view_xform; - Vector2 ray_from,ray_to; - + Vector2 ray_from, ray_to; struct BodyShapeData { @@ -63,10 +60,8 @@ class TestPhysics2DMainLoop : public MainLoop { RID shape; }; - BodyShapeData body_shape_data[8]; - void _create_body_shape_data() { VisualServer *vs = VisualServer::get_singleton(); Physics2DServer *ps = Physics2DServer::get_singleton(); @@ -76,53 +71,51 @@ class TestPhysics2DMainLoop : public MainLoop { { PoolVector<uint8_t> pixels; - pixels.resize(32*2*2); - for(int i=0;i<2;i++) { + pixels.resize(32 * 2 * 2); + for (int i = 0; i < 2; i++) { - for(int j=0;j<32;j++) { + for (int j = 0; j < 32; j++) { - pixels.set(i*32*2+j*2+0,(j==0)?255:0); - pixels.set(i*32*2+j*2+1,255); + pixels.set(i * 32 * 2 + j * 2 + 0, (j == 0) ? 255 : 0); + pixels.set(i * 32 * 2 + j * 2 + 1, 255); } } - Image image(32,2,0,Image::FORMAT_LA8,pixels); + Image image(32, 2, 0, Image::FORMAT_LA8, pixels); - body_shape_data[Physics2DServer::SHAPE_SEGMENT].image=vs->texture_create_from_image(image); + body_shape_data[Physics2DServer::SHAPE_SEGMENT].image = vs->texture_create_from_image(image); RID segment_shape = ps->shape_create(Physics2DServer::SHAPE_SEGMENT); - Rect2 sg(Point2(-16,0),Point2(16,0)); - ps->shape_set_data(segment_shape,sg); + Rect2 sg(Point2(-16, 0), Point2(16, 0)); + ps->shape_set_data(segment_shape, sg); body_shape_data[Physics2DServer::SHAPE_SEGMENT].shape = segment_shape; - } // CIRCLE { PoolVector<uint8_t> pixels; - pixels.resize(32*32*2); - for(int i=0;i<32;i++) { + pixels.resize(32 * 32 * 2); + for (int i = 0; i < 32; i++) { - for(int j=0;j<32;j++) { + for (int j = 0; j < 32; j++) { - bool black=Vector2(i-16,j-16).length_squared() < 16*16; + bool black = Vector2(i - 16, j - 16).length_squared() < 16 * 16; - pixels.set(i*32*2+j*2+0,(i==16 || j==16)?255:0); - pixels.set(i*32*2+j*2+1,black?255:0); + pixels.set(i * 32 * 2 + j * 2 + 0, (i == 16 || j == 16) ? 255 : 0); + pixels.set(i * 32 * 2 + j * 2 + 1, black ? 255 : 0); } } - Image image(32,32,0,Image::FORMAT_LA8,pixels); + Image image(32, 32, 0, Image::FORMAT_LA8, pixels); - body_shape_data[Physics2DServer::SHAPE_CIRCLE].image=vs->texture_create_from_image(image); + body_shape_data[Physics2DServer::SHAPE_CIRCLE].image = vs->texture_create_from_image(image); RID circle_shape = ps->shape_create(Physics2DServer::SHAPE_CIRCLE); - ps->shape_set_data(circle_shape,16); + ps->shape_set_data(circle_shape, 16); body_shape_data[Physics2DServer::SHAPE_CIRCLE].shape = circle_shape; - } // BOX @@ -130,167 +123,151 @@ class TestPhysics2DMainLoop : public MainLoop { { PoolVector<uint8_t> pixels; - pixels.resize(32*32*2); - for(int i=0;i<32;i++) { + pixels.resize(32 * 32 * 2); + for (int i = 0; i < 32; i++) { - for(int j=0;j<32;j++) { + for (int j = 0; j < 32; j++) { - bool black=i>0 && i<31 && j>0 && j<31; + bool black = i > 0 && i < 31 && j > 0 && j < 31; - pixels.set(i*32*2+j*2+0,black?0:255); - pixels.set(i*32*2+j*2+1,255); + pixels.set(i * 32 * 2 + j * 2 + 0, black ? 0 : 255); + pixels.set(i * 32 * 2 + j * 2 + 1, 255); } } - Image image(32,32,0,Image::FORMAT_LA8,pixels); + Image image(32, 32, 0, Image::FORMAT_LA8, pixels); - body_shape_data[Physics2DServer::SHAPE_RECTANGLE].image=vs->texture_create_from_image(image); + body_shape_data[Physics2DServer::SHAPE_RECTANGLE].image = vs->texture_create_from_image(image); RID rectangle_shape = ps->shape_create(Physics2DServer::SHAPE_RECTANGLE); - ps->shape_set_data(rectangle_shape,Vector2(16,16)); + ps->shape_set_data(rectangle_shape, Vector2(16, 16)); body_shape_data[Physics2DServer::SHAPE_RECTANGLE].shape = rectangle_shape; - } - // CAPSULE { PoolVector<uint8_t> pixels; - pixels.resize(32*64*2); - for(int i=0;i<64;i++) { - - for(int j=0;j<32;j++) { + pixels.resize(32 * 64 * 2); + for (int i = 0; i < 64; i++) { + for (int j = 0; j < 32; j++) { - int si = i>48 ? i - 32 : (i<16 ? i : 16); - bool black=Vector2(si-16,j-16).length_squared() < 16*16; - - pixels.set(i*32*2+j*2+0,(i==16 || j==16 || i==48)?255:0); - pixels.set(i*32*2+j*2+1,black?255:0); + int si = i > 48 ? i - 32 : (i < 16 ? i : 16); + bool black = Vector2(si - 16, j - 16).length_squared() < 16 * 16; + pixels.set(i * 32 * 2 + j * 2 + 0, (i == 16 || j == 16 || i == 48) ? 255 : 0); + pixels.set(i * 32 * 2 + j * 2 + 1, black ? 255 : 0); } } - Image image(32,64,0,Image::FORMAT_LA8,pixels); + Image image(32, 64, 0, Image::FORMAT_LA8, pixels); - body_shape_data[Physics2DServer::SHAPE_CAPSULE].image=vs->texture_create_from_image(image); + body_shape_data[Physics2DServer::SHAPE_CAPSULE].image = vs->texture_create_from_image(image); RID capsule_shape = ps->shape_create(Physics2DServer::SHAPE_CAPSULE); - ps->shape_set_data(capsule_shape,Vector2(16,32)); + ps->shape_set_data(capsule_shape, Vector2(16, 32)); body_shape_data[Physics2DServer::SHAPE_CAPSULE].shape = capsule_shape; - } // CONVEX { - Image image(convex_png); - body_shape_data[Physics2DServer::SHAPE_CONVEX_POLYGON].image=vs->texture_create_from_image(image); + body_shape_data[Physics2DServer::SHAPE_CONVEX_POLYGON].image = vs->texture_create_from_image(image); RID convex_polygon_shape = ps->shape_create(Physics2DServer::SHAPE_CONVEX_POLYGON); PoolVector<Vector2> arr; - Point2 sb(32,32); - arr.push_back(Point2(20,3)-sb); - arr.push_back(Point2(58,23)-sb); - arr.push_back(Point2(55,54)-sb); - arr.push_back(Point2(27,60)-sb); - arr.push_back(Point2(5,56)-sb); - arr.push_back(Point2(4,20)-sb); - arr.push_back(Point2(11,7)-sb); - ps->shape_set_data(convex_polygon_shape,arr); + Point2 sb(32, 32); + arr.push_back(Point2(20, 3) - sb); + arr.push_back(Point2(58, 23) - sb); + arr.push_back(Point2(55, 54) - sb); + arr.push_back(Point2(27, 60) - sb); + arr.push_back(Point2(5, 56) - sb); + arr.push_back(Point2(4, 20) - sb); + arr.push_back(Point2(11, 7) - sb); + ps->shape_set_data(convex_polygon_shape, arr); body_shape_data[Physics2DServer::SHAPE_CONVEX_POLYGON].shape = convex_polygon_shape; - } - - } - - - void _do_ray_query() { /* Physics2DServer *ps = Physics2DServer::get_singleton(); ps->query_intersection_segment(ray_query,ray_from,ray_to); */ - } protected: + void input_event(const InputEvent &p_event) { + if (p_event.type == InputEvent::MOUSE_BUTTON) { - void input_event(const InputEvent& p_event) { - - if (p_event.type==InputEvent::MOUSE_BUTTON) { - - const InputEventMouseButton &mb=p_event.mouse_button; + const InputEventMouseButton &mb = p_event.mouse_button; if (mb.pressed) { - Point2 p( mb.x, mb.y ); + Point2 p(mb.x, mb.y); - if (mb.button_index==1) { - ray_to=p; + if (mb.button_index == 1) { + ray_to = p; _do_ray_query(); - } else if (mb.button_index==2) { - ray_from=p; + } else if (mb.button_index == 2) { + ray_from = p; _do_ray_query(); } - } } - if (p_event.type==InputEvent::MOUSE_MOTION) { + if (p_event.type == InputEvent::MOUSE_MOTION) { - const InputEventMouseMotion &mm=p_event.mouse_motion; + const InputEventMouseMotion &mm = p_event.mouse_motion; - Point2 p( mm.x, mm.y ); + Point2 p(mm.x, mm.y); - if (mm.button_mask&BUTTON_MASK_LEFT) { - ray_to=p; + if (mm.button_mask & BUTTON_MASK_LEFT) { + ray_to = p; _do_ray_query(); - } else if (mm.button_mask&BUTTON_MASK_RIGHT) { - ray_from=p; + } else if (mm.button_mask & BUTTON_MASK_RIGHT) { + ray_from = p; _do_ray_query(); } } } - RID _add_body(Physics2DServer::ShapeType p_shape, const Transform2D& p_xform) { + RID _add_body(Physics2DServer::ShapeType p_shape, const Transform2D &p_xform) { VisualServer *vs = VisualServer::get_singleton(); Physics2DServer *ps = Physics2DServer::get_singleton(); RID body = ps->body_create(); - ps->body_add_shape(body,body_shape_data[p_shape].shape); - ps->body_set_space(body,space); - ps->body_set_continuous_collision_detection_mode(body,Physics2DServer::CCD_MODE_CAST_SHAPE); - ps->body_set_state(body,Physics2DServer::BODY_STATE_TRANSFORM,p_xform); + ps->body_add_shape(body, body_shape_data[p_shape].shape); + ps->body_set_space(body, space); + ps->body_set_continuous_collision_detection_mode(body, Physics2DServer::CCD_MODE_CAST_SHAPE); + ps->body_set_state(body, Physics2DServer::BODY_STATE_TRANSFORM, p_xform); //print_line("add body with xform: "+p_xform); RID sprite = vs->canvas_item_create(); - vs->canvas_item_set_parent(sprite,canvas); - vs->canvas_item_set_transform(sprite,p_xform); - Size2 imgsize( vs->texture_get_width(body_shape_data[p_shape].image),vs->texture_get_height(body_shape_data[p_shape].image) ); - vs->canvas_item_add_texture_rect(sprite,Rect2(-imgsize/2.0,imgsize),body_shape_data[p_shape].image); + vs->canvas_item_set_parent(sprite, canvas); + vs->canvas_item_set_transform(sprite, p_xform); + Size2 imgsize(vs->texture_get_width(body_shape_data[p_shape].image), vs->texture_get_height(body_shape_data[p_shape].image)); + vs->canvas_item_add_texture_rect(sprite, Rect2(-imgsize / 2.0, imgsize), body_shape_data[p_shape].image); - ps->body_set_force_integration_callback(body,this,"_body_moved",sprite); + ps->body_set_force_integration_callback(body, this, "_body_moved", sprite); //RID q = ps->query_create(this,"_body_moved",sprite); //ps->query_body_state(q,body); return body; } - void _add_plane(const Vector2& p_normal, real_t p_d) { + void _add_plane(const Vector2 &p_normal, real_t p_d) { Physics2DServer *ps = Physics2DServer::get_singleton(); @@ -299,85 +276,73 @@ protected: arr.push_back(p_d); RID plane = ps->shape_create(Physics2DServer::SHAPE_LINE); - ps->shape_set_data(plane,arr); + ps->shape_set_data(plane, arr); RID plane_body = ps->body_create(Physics2DServer::BODY_MODE_STATIC); - ps->body_set_space(plane_body,space); - ps->body_add_shape(plane_body,plane); - + ps->body_set_space(plane_body, space); + ps->body_add_shape(plane_body, plane); } - void _add_concave(const Vector<Vector2>& p_points,const Transform2D& p_xform=Transform2D()) { + void _add_concave(const Vector<Vector2> &p_points, const Transform2D &p_xform = Transform2D()) { Physics2DServer *ps = Physics2DServer::get_singleton(); VisualServer *vs = VisualServer::get_singleton(); RID concave = ps->shape_create(Physics2DServer::SHAPE_CONCAVE_POLYGON); - ps->shape_set_data(concave,p_points); + ps->shape_set_data(concave, p_points); RID body = ps->body_create(Physics2DServer::BODY_MODE_STATIC); - ps->body_set_space(body,space); - ps->body_add_shape(body,concave); - ps->body_set_state(body,Physics2DServer::BODY_STATE_TRANSFORM,p_xform); - + ps->body_set_space(body, space); + ps->body_add_shape(body, concave); + ps->body_set_state(body, Physics2DServer::BODY_STATE_TRANSFORM, p_xform); RID sprite = vs->canvas_item_create(); - vs->canvas_item_set_parent(sprite,canvas); - vs->canvas_item_set_transform(sprite,p_xform); - for(int i=0;i<p_points.size();i+=2) { - vs->canvas_item_add_line(sprite,p_points[i],p_points[i+1],Color(0,0,0),2); + vs->canvas_item_set_parent(sprite, canvas); + vs->canvas_item_set_transform(sprite, p_xform); + for (int i = 0; i < p_points.size(); i += 2) { + vs->canvas_item_add_line(sprite, p_points[i], p_points[i + 1], Color(0, 0, 0), 2); } - } - void _body_moved(Object *p_state,RID p_sprite) { - Physics2DDirectBodyState *state=(Physics2DDirectBodyState *)p_state; - VisualServer::get_singleton()->canvas_item_set_transform(p_sprite,state->get_transform()); + void _body_moved(Object *p_state, RID p_sprite) { + Physics2DDirectBodyState *state = (Physics2DDirectBodyState *)p_state; + VisualServer::get_singleton()->canvas_item_set_transform(p_sprite, state->get_transform()); } - void _ray_query_callback(const RID& p_rid, ObjectID p_id, int p_shape, const Vector2& p_point, const Vector2& p_normal) { - + void _ray_query_callback(const RID &p_rid, ObjectID p_id, int p_shape, const Vector2 &p_point, const Vector2 &p_normal) { Vector2 ray_end; if (p_rid.is_valid()) { - ray_end=p_point; + ray_end = p_point; } else { - ray_end=ray_to; + ray_end = ray_to; } VisualServer *vs = VisualServer::get_singleton(); vs->canvas_item_clear(ray); - vs->canvas_item_add_line(ray,ray_from,ray_end,p_rid.is_valid()?Color(0,1,0.4):Color(1,0.4,0),2); + vs->canvas_item_add_line(ray, ray_from, ray_end, p_rid.is_valid() ? Color(0, 1, 0.4) : Color(1, 0.4, 0), 2); if (p_rid.is_valid()) - vs->canvas_item_add_line(ray,ray_end,ray_end+p_normal*20,p_rid.is_valid()?Color(0,1,0.4):Color(1,0.4,0),2); - + vs->canvas_item_add_line(ray, ray_end, ray_end + p_normal * 20, p_rid.is_valid() ? Color(0, 1, 0.4) : Color(1, 0.4, 0), 2); } static void _bind_methods() { - - ClassDB::bind_method(D_METHOD("_body_moved"),&TestPhysics2DMainLoop::_body_moved); - ClassDB::bind_method(D_METHOD("_ray_query_callback"),&TestPhysics2DMainLoop::_ray_query_callback); + ClassDB::bind_method(D_METHOD("_body_moved"), &TestPhysics2DMainLoop::_body_moved); + ClassDB::bind_method(D_METHOD("_ray_query_callback"), &TestPhysics2DMainLoop::_ray_query_callback); } - public: - - - virtual void init() { VisualServer *vs = VisualServer::get_singleton(); Physics2DServer *ps = Physics2DServer::get_singleton(); - - - space=ps->space_create(); - ps->space_set_active(space,true); + space = ps->space_create(); + ps->space_set_active(space, true); ps->set_active(true); - ps->area_set_param(space,Physics2DServer::AREA_PARAM_GRAVITY_VECTOR,Vector2(0,1)); - ps->area_set_param(space,Physics2DServer::AREA_PARAM_GRAVITY,98); + ps->area_set_param(space, Physics2DServer::AREA_PARAM_GRAVITY_VECTOR, Vector2(0, 1)); + ps->area_set_param(space, Physics2DServer::AREA_PARAM_GRAVITY, 98); { @@ -385,30 +350,29 @@ public: canvas = vs->canvas_create(); Size2i screen_size = OS::get_singleton()->get_window_size(); - vs->viewport_attach_canvas(vp,canvas); - vs->viewport_set_size(vp,screen_size.x,screen_size.y); - vs->viewport_attach_to_screen(vp,Rect2(Vector2(),screen_size)); - vs->viewport_set_active(vp,true); + vs->viewport_attach_canvas(vp, canvas); + vs->viewport_set_size(vp, screen_size.x, screen_size.y); + vs->viewport_attach_to_screen(vp, Rect2(Vector2(), screen_size)); + vs->viewport_set_active(vp, true); Transform2D smaller; //smaller.scale(Vector2(0.6,0.6)); //smaller.elements[2]=Vector2(100,0); //view_xform = smaller; - vs->viewport_set_canvas_transform(vp,canvas,view_xform); - + vs->viewport_set_canvas_transform(vp, canvas, view_xform); } ray = vs->canvas_item_create(); - vs->canvas_item_set_parent(ray,canvas); + vs->canvas_item_set_parent(ray, canvas); //ray_query = ps->query_create(this,"_ray_query_callback",Variant()); //ps->query_intersection(ray_query,space); _create_body_shape_data(); - for(int i=0;i<32;i++) { + for (int i = 0; i < 32; i++) { - Physics2DServer::ShapeType types[4]={ + Physics2DServer::ShapeType types[4] = { Physics2DServer::SHAPE_CIRCLE, Physics2DServer::SHAPE_CAPSULE, Physics2DServer::SHAPE_RECTANGLE, @@ -416,9 +380,9 @@ public: }; - Physics2DServer::ShapeType type = types[i%4]; + Physics2DServer::ShapeType type = types[i % 4]; //type=Physics2DServer::SHAPE_SEGMENT; - _add_body(type,Transform2D(i*0.8,Point2(152+i*40,100-40*i))); + _add_body(type, Transform2D(i * 0.8, Point2(152 + i * 40, 100 - 40 * i))); /* if (i==0) ps->body_set_mode(b,Physics2DServer::BODY_MODE_STATIC); @@ -431,47 +395,36 @@ public: Point2 prev; Vector<Point2> parr; - for(int i=0;i<30;i++) { + for (int i = 0; i < 30; i++) { - Point2 p(i*60,Math::randf() * 70+340); - if (i>0) { + Point2 p(i * 60, Math::randf() * 70 + 340); + if (i > 0) { parr.push_back(prev); parr.push_back(p); } - prev=p; + prev = p; } _add_concave(parr); //_add_plane(Vector2(0.0,-1).normalized(),-300); //_add_plane(Vector2(1,0).normalized(),50); //_add_plane(Vector2(-1,0).normalized(),-600); - } virtual bool idle(float p_time) { - return false; } virtual void finish() { - - } - TestPhysics2DMainLoop() {} - }; - namespace TestPhysics2D { +MainLoop *test() { -MainLoop* test() { - - - return memnew( TestPhysics2DMainLoop ); + return memnew(TestPhysics2DMainLoop); } - - } diff --git a/main/tests/test_physics_2d.h b/main/tests/test_physics_2d.h index dee18edfe0..883bf15201 100644 --- a/main/tests/test_physics_2d.h +++ b/main/tests/test_physics_2d.h @@ -29,13 +29,11 @@ #ifndef TEST_PHYSICS_2D_H #define TEST_PHYSICS_2D_H - #include "os/main_loop.h" namespace TestPhysics2D { -MainLoop* test(); - +MainLoop *test(); } #endif // TEST_PHYSICS_2D_H diff --git a/main/tests/test_render.cpp b/main/tests/test_render.cpp index 512c48b116..188d736ff6 100644 --- a/main/tests/test_render.cpp +++ b/main/tests/test_render.cpp @@ -28,22 +28,20 @@ /*************************************************************************/ #include "test_render.h" -#include "servers/visual_server.h" -#include "os/main_loop.h" #include "math_funcs.h" -#include "print_string.h" +#include "os/keyboard.h" +#include "os/main_loop.h" #include "os/os.h" +#include "print_string.h" #include "quick_hull.h" -#include "os/keyboard.h" +#include "servers/visual_server.h" #define OBJECT_COUNT 50 namespace TestRender { - class TestMainLoop : public MainLoop { - RID test_cube; RID instance; RID camera; @@ -62,37 +60,30 @@ class TestMainLoop : public MainLoop { float ofs; bool quit; -protected: - +protected: public: - virtual void input_event(const InputEvent& p_event) { + virtual void input_event(const InputEvent &p_event) { - if (p_event.type==InputEvent::KEY && p_event.key.pressed) - quit=true; + if (p_event.type == InputEvent::KEY && p_event.key.pressed) + quit = true; } virtual void init() { - print_line("INITIALIZING TEST RENDER"); - VisualServer *vs=VisualServer::get_singleton(); + VisualServer *vs = VisualServer::get_singleton(); test_cube = vs->get_test_cube(); scenario = vs->scenario_create(); - - - - - Vector<Vector3> vts; -/* + /* PoolVector<Plane> sp = Geometry::build_sphere_planes(2,5,5); Geometry::MeshData md2 = Geometry::build_convex_mesh(sp); vts=md2.vertices; */ -/* + /* static const int s = 20; for(int i=0;i<s;i++) { @@ -118,20 +109,20 @@ public: vts.push_back(Vector3(1,0,0)); vts.push_back(Vector3(-1,0,0));*/ - vts.push_back(Vector3(1,1,1)); - vts.push_back(Vector3(1,-1,1)); - vts.push_back(Vector3(-1,1,1)); - vts.push_back(Vector3(-1,-1,1)); - vts.push_back(Vector3(1,1,-1)); - vts.push_back(Vector3(1,-1,-1)); - vts.push_back(Vector3(-1,1,-1)); - vts.push_back(Vector3(-1,-1,-1)); + vts.push_back(Vector3(1, 1, 1)); + vts.push_back(Vector3(1, -1, 1)); + vts.push_back(Vector3(-1, 1, 1)); + vts.push_back(Vector3(-1, -1, 1)); + vts.push_back(Vector3(1, 1, -1)); + vts.push_back(Vector3(1, -1, -1)); + vts.push_back(Vector3(-1, 1, -1)); + vts.push_back(Vector3(-1, -1, -1)); Geometry::MeshData md; - Error err = QuickHull::build(vts,md); - print_line("ERR: "+itos(err)); + Error err = QuickHull::build(vts, md); + print_line("ERR: " + itos(err)); test_cube = vs->mesh_create(); - vs->mesh_add_surface_from_mesh_data(test_cube,md); + vs->mesh_add_surface_from_mesh_data(test_cube, md); //vs->scenario_set_debug(scenario,VS::SCENARIO_DEBUG_WIREFRAME); /* @@ -143,46 +134,41 @@ public: vs->material_set_shader(tcmat,sm); */ - List<String> cmdline = OS::get_singleton()->get_cmdline_args(); int object_count = OBJECT_COUNT; - if (cmdline.size() > 0 && cmdline[cmdline.size()-1].to_int()) { - object_count = cmdline[cmdline.size()-1].to_int(); + if (cmdline.size() > 0 && cmdline[cmdline.size() - 1].to_int()) { + object_count = cmdline[cmdline.size() - 1].to_int(); }; - for (int i=0;i<object_count;i++) { + for (int i = 0; i < object_count; i++) { InstanceInfo ii; + ii.instance = vs->instance_create2(test_cube, scenario); - ii.instance = vs->instance_create2( test_cube, scenario ); - - - ii.base.translate( Math::random(-20,20), Math::random(-20,20),Math::random(-20,18) ); - ii.base.rotate( Vector3(0,1,0), Math::randf() * Math_PI ); - ii.base.rotate( Vector3(1,0,0), Math::randf() * Math_PI ); - vs->instance_set_transform( ii.instance, ii.base ); + ii.base.translate(Math::random(-20, 20), Math::random(-20, 20), Math::random(-20, 18)); + ii.base.rotate(Vector3(0, 1, 0), Math::randf() * Math_PI); + ii.base.rotate(Vector3(1, 0, 0), Math::randf() * Math_PI); + vs->instance_set_transform(ii.instance, ii.base); - ii.rot_axis = Vector3( Math::random(-1,1), Math::random(-1,1), Math::random(-1,1) ).normalized(); + ii.rot_axis = Vector3(Math::random(-1, 1), Math::random(-1, 1), Math::random(-1, 1)).normalized(); instances.push_back(ii); - } camera = vs->camera_create(); -// vs->camera_set_perspective( camera, 60.0,0.1, 100.0 ); + // vs->camera_set_perspective( camera, 60.0,0.1, 100.0 ); viewport = vs->viewport_create(); Size2i screen_size = OS::get_singleton()->get_window_size(); - vs->viewport_set_size(viewport,screen_size.x,screen_size.y); - vs->viewport_attach_to_screen(viewport,Rect2(Vector2(),screen_size)); - vs->viewport_set_active(viewport,true); - vs->viewport_attach_camera( viewport, camera ); - vs->viewport_set_scenario( viewport, scenario ); - vs->camera_set_transform(camera, Transform( Basis(), Vector3(0,3,30 ) ) ); - vs->camera_set_perspective( camera, 60, 0.1, 1000); - + vs->viewport_set_size(viewport, screen_size.x, screen_size.y); + vs->viewport_attach_to_screen(viewport, Rect2(Vector2(), screen_size)); + vs->viewport_set_active(viewport, true); + vs->viewport_attach_camera(viewport, camera); + vs->viewport_set_scenario(viewport, scenario); + vs->camera_set_transform(camera, Transform(Basis(), Vector3(0, 3, 30))); + vs->camera_set_perspective(camera, 60, 0.1, 1000); /* RID lightaux = vs->light_create( VisualServer::LIGHT_OMNI ); @@ -193,44 +179,44 @@ public: */ RID lightaux; - lightaux = vs->light_create( VisualServer::LIGHT_DIRECTIONAL ); + lightaux = vs->light_create(VisualServer::LIGHT_DIRECTIONAL); //vs->light_set_color( lightaux, VisualServer::LIGHT_COLOR_AMBIENT, Color(0.0,0.0,0.0) ); - vs->light_set_color( lightaux, Color(1.0,1.0,1.0) ); + vs->light_set_color(lightaux, Color(1.0, 1.0, 1.0)); //vs->light_set_shadow( lightaux, true ); - light = vs->instance_create2( lightaux, scenario ); + light = vs->instance_create2(lightaux, scenario); Transform lla; //lla.set_look_at(Vector3(),Vector3(1,-1,1),Vector3(0,1,0)); - lla.set_look_at(Vector3(),Vector3(-0.000000,-0.836026,-0.548690),Vector3(0,1,0)); + lla.set_look_at(Vector3(), Vector3(-0.000000, -0.836026, -0.548690), Vector3(0, 1, 0)); - vs->instance_set_transform( light, lla ); + vs->instance_set_transform(light, lla); - lightaux = vs->light_create( VisualServer::LIGHT_OMNI ); + lightaux = vs->light_create(VisualServer::LIGHT_OMNI); //vs->light_set_color( lightaux, VisualServer::LIGHT_COLOR_AMBIENT, Color(0.0,0.0,1.0) ); - vs->light_set_color( lightaux, Color(1.0,1.0,0.0) ); - vs->light_set_param( lightaux, VisualServer::LIGHT_PARAM_RANGE, 4 ); - vs->light_set_param( lightaux, VisualServer::LIGHT_PARAM_ENERGY, 8 ); + vs->light_set_color(lightaux, Color(1.0, 1.0, 0.0)); + vs->light_set_param(lightaux, VisualServer::LIGHT_PARAM_RANGE, 4); + vs->light_set_param(lightaux, VisualServer::LIGHT_PARAM_ENERGY, 8); //vs->light_set_shadow( lightaux, true ); //light = vs->instance_create( lightaux ); - ofs=0; - quit=false; + ofs = 0; + quit = false; } virtual bool iteration(float p_time) { - VisualServer *vs=VisualServer::get_singleton(); + VisualServer *vs = VisualServer::get_singleton(); //Transform t; //t.rotate(Vector3(0, 1, 0), ofs); //t.translate(Vector3(0,0,20 )); //vs->camera_set_transform(camera, t); - ofs+=p_time*0.05; + ofs += p_time * 0.05; //return quit; - for(List<InstanceInfo>::Element *E=instances.front();E;E=E->next()) { + for (List<InstanceInfo>::Element *E = instances.front(); E; E = E->next()) { - Transform pre( Basis(E->get().rot_axis, ofs), Vector3() ); - vs->instance_set_transform( E->get().instance, pre * E->get().base ); + Transform pre(Basis(E->get().rot_axis, ofs), Vector3()); + vs->instance_set_transform(E->get().instance, pre * E->get().base); /* if( !E->next() ) { @@ -246,18 +232,12 @@ public: return quit; } - virtual void finish() { - } - }; +MainLoop *test() { -MainLoop* test() { - - return memnew( TestMainLoop ); - + return memnew(TestMainLoop); } - } diff --git a/main/tests/test_render.h b/main/tests/test_render.h index b6f6d81881..1dbf3c7f29 100644 --- a/main/tests/test_render.h +++ b/main/tests/test_render.h @@ -37,8 +37,7 @@ namespace TestRender { -MainLoop* test(); - +MainLoop *test(); } #endif diff --git a/main/tests/test_shader_lang.cpp b/main/tests/test_shader_lang.cpp index 64c3853065..4ca09fe656 100644 --- a/main/tests/test_shader_lang.cpp +++ b/main/tests/test_shader_lang.cpp @@ -28,28 +28,25 @@ /*************************************************************************/ #include "test_shader_lang.h" - +#include "os/file_access.h" #include "os/main_loop.h" #include "os/os.h" -#include "os/file_access.h" +#include "print_string.h" #include "scene/gui/control.h" #include "scene/gui/text_edit.h" -#include "print_string.h" #include "servers/visual/shader_language.h" //#include "drivers/gles2/shader_compiler_gles2.h" - typedef ShaderLanguage SL; namespace TestShaderLang { - static String _mktab(int p_level) { String tb; - for(int i=0;i<p_level;i++) { - tb+="\t"; + for (int i = 0; i < p_level; i++) { + tb += "\t"; } return tb; @@ -62,11 +59,9 @@ static String _typestr(SL::DataType p_type) { return ""; } - static String _prestr(SL::DataPrecision p_pres) { - - switch(p_pres) { + switch (p_pres) { case SL::PRECISION_LOWP: return "lowp "; case SL::PRECISION_MEDIUMP: return "mediump "; case SL::PRECISION_HIGHP: return "highp "; @@ -75,60 +70,56 @@ static String _prestr(SL::DataPrecision p_pres) { return ""; } - static String _opstr(SL::Operator p_op) { return ShaderLanguage::get_operator_text(p_op); - - } - -static String get_constant_text(SL::DataType p_type, const Vector<SL::ConstantNode::Value>& p_values) { - - switch(p_type) { - case SL::TYPE_BOOL: return p_values[0].boolean?"true":"false"; - case SL::TYPE_BVEC2: return String()+"bvec2("+(p_values[0].boolean?"true":"false")+(p_values[1].boolean?"true":"false")+")"; - case SL::TYPE_BVEC3: return String()+"bvec3("+(p_values[0].boolean?"true":"false")+","+(p_values[1].boolean?"true":"false")+","+(p_values[2].boolean?"true":"false")+")"; - case SL::TYPE_BVEC4: return String()+"bvec4("+(p_values[0].boolean?"true":"false")+","+(p_values[1].boolean?"true":"false")+","+(p_values[2].boolean?"true":"false")+","+(p_values[3].boolean?"true":"false")+")"; - case SL::TYPE_INT: return rtos(p_values[0].sint); - case SL::TYPE_IVEC2: return String()+"ivec2("+rtos(p_values[0].sint)+","+rtos(p_values[1].sint)+")"; - case SL::TYPE_IVEC3: return String()+"ivec3("+rtos(p_values[0].sint)+","+rtos(p_values[1].sint)+","+rtos(p_values[2].sint)+")"; - case SL::TYPE_IVEC4: return String()+"ivec4("+rtos(p_values[0].sint)+","+rtos(p_values[1].sint)+","+rtos(p_values[2].sint)+","+rtos(p_values[3].sint)+")"; - case SL::TYPE_UINT: return rtos(p_values[0].real); - case SL::TYPE_UVEC2: return String()+"uvec2("+rtos(p_values[0].real)+","+rtos(p_values[1].real)+")"; - case SL::TYPE_UVEC3: return String()+"uvec3("+rtos(p_values[0].real)+","+rtos(p_values[1].real)+","+rtos(p_values[2].real)+")"; - case SL::TYPE_UVEC4: return String()+"uvec4("+rtos(p_values[0].real)+","+rtos(p_values[1].real)+","+rtos(p_values[2].real)+","+rtos(p_values[3].real)+")"; - case SL::TYPE_FLOAT: return rtos(p_values[0].real); - case SL::TYPE_VEC2: return String()+"vec2("+rtos(p_values[0].real)+","+rtos(p_values[1].real)+")"; - case SL::TYPE_VEC3: return String()+"vec3("+rtos(p_values[0].real)+","+rtos(p_values[1].real)+","+rtos(p_values[2].real)+")"; - case SL::TYPE_VEC4: return String()+"vec4("+rtos(p_values[0].real)+","+rtos(p_values[1].real)+","+rtos(p_values[2].real)+","+rtos(p_values[3].real)+")"; +static String get_constant_text(SL::DataType p_type, const Vector<SL::ConstantNode::Value> &p_values) { + + switch (p_type) { + case SL::TYPE_BOOL: return p_values[0].boolean ? "true" : "false"; + case SL::TYPE_BVEC2: return String() + "bvec2(" + (p_values[0].boolean ? "true" : "false") + (p_values[1].boolean ? "true" : "false") + ")"; + case SL::TYPE_BVEC3: return String() + "bvec3(" + (p_values[0].boolean ? "true" : "false") + "," + (p_values[1].boolean ? "true" : "false") + "," + (p_values[2].boolean ? "true" : "false") + ")"; + case SL::TYPE_BVEC4: return String() + "bvec4(" + (p_values[0].boolean ? "true" : "false") + "," + (p_values[1].boolean ? "true" : "false") + "," + (p_values[2].boolean ? "true" : "false") + "," + (p_values[3].boolean ? "true" : "false") + ")"; + case SL::TYPE_INT: return rtos(p_values[0].sint); + case SL::TYPE_IVEC2: return String() + "ivec2(" + rtos(p_values[0].sint) + "," + rtos(p_values[1].sint) + ")"; + case SL::TYPE_IVEC3: return String() + "ivec3(" + rtos(p_values[0].sint) + "," + rtos(p_values[1].sint) + "," + rtos(p_values[2].sint) + ")"; + case SL::TYPE_IVEC4: return String() + "ivec4(" + rtos(p_values[0].sint) + "," + rtos(p_values[1].sint) + "," + rtos(p_values[2].sint) + "," + rtos(p_values[3].sint) + ")"; + case SL::TYPE_UINT: return rtos(p_values[0].real); + case SL::TYPE_UVEC2: return String() + "uvec2(" + rtos(p_values[0].real) + "," + rtos(p_values[1].real) + ")"; + case SL::TYPE_UVEC3: return String() + "uvec3(" + rtos(p_values[0].real) + "," + rtos(p_values[1].real) + "," + rtos(p_values[2].real) + ")"; + case SL::TYPE_UVEC4: return String() + "uvec4(" + rtos(p_values[0].real) + "," + rtos(p_values[1].real) + "," + rtos(p_values[2].real) + "," + rtos(p_values[3].real) + ")"; + case SL::TYPE_FLOAT: return rtos(p_values[0].real); + case SL::TYPE_VEC2: return String() + "vec2(" + rtos(p_values[0].real) + "," + rtos(p_values[1].real) + ")"; + case SL::TYPE_VEC3: return String() + "vec3(" + rtos(p_values[0].real) + "," + rtos(p_values[1].real) + "," + rtos(p_values[2].real) + ")"; + case SL::TYPE_VEC4: return String() + "vec4(" + rtos(p_values[0].real) + "," + rtos(p_values[1].real) + "," + rtos(p_values[2].real) + "," + rtos(p_values[3].real) + ")"; default: ERR_FAIL_V(String()); } } -static String dump_node_code(SL::Node *p_node,int p_level) { +static String dump_node_code(SL::Node *p_node, int p_level) { String code; - switch(p_node->type) { + switch (p_node->type) { case SL::Node::TYPE_SHADER: { - SL::ShaderNode *pnode=(SL::ShaderNode*)p_node; + SL::ShaderNode *pnode = (SL::ShaderNode *)p_node; - for(Map<StringName,SL::ShaderNode::Uniform>::Element *E=pnode->uniforms.front();E;E=E->next()) { + for (Map<StringName, SL::ShaderNode::Uniform>::Element *E = pnode->uniforms.front(); E; E = E->next()) { - String ucode="uniform "; - ucode+=_prestr(E->get().precission); - ucode+=_typestr(E->get().type); - ucode+=" "+String(E->key()); + String ucode = "uniform "; + ucode += _prestr(E->get().precission); + ucode += _typestr(E->get().type); + ucode += " " + String(E->key()); if (E->get().default_value.size()) { - ucode+=" = "+get_constant_text(E->get().type,E->get().default_value); + ucode += " = " + get_constant_text(E->get().type, E->get().default_value); } - static const char*hint_name[SL::ShaderNode::Uniform::HINT_MAX]={ + static const char *hint_name[SL::ShaderNode::Uniform::HINT_MAX] = { "", "color", "range", @@ -139,38 +130,36 @@ static String dump_node_code(SL::Node *p_node,int p_level) { }; if (E->get().hint) - ucode+=" : "+String(hint_name[E->get().hint]); - - code+=ucode+"\n"; + ucode += " : " + String(hint_name[E->get().hint]); + code += ucode + "\n"; } - for(Map<StringName,SL::ShaderNode::Varying>::Element *E=pnode->varyings.front();E;E=E->next()) { - - String vcode="varying "; - vcode+=_prestr(E->get().precission); - vcode+=_typestr(E->get().type); - vcode+=" "+String(E->key()); + for (Map<StringName, SL::ShaderNode::Varying>::Element *E = pnode->varyings.front(); E; E = E->next()) { - code+=vcode+"\n"; + String vcode = "varying "; + vcode += _prestr(E->get().precission); + vcode += _typestr(E->get().type); + vcode += " " + String(E->key()); + code += vcode + "\n"; } - for(int i=0;i<pnode->functions.size();i++) { + for (int i = 0; i < pnode->functions.size(); i++) { - SL::FunctionNode *fnode=pnode->functions[i].function; + SL::FunctionNode *fnode = pnode->functions[i].function; String header; - header=_typestr(fnode->return_type)+" "+fnode->name+"("; - for(int i=0;i<fnode->arguments.size();i++) { + header = _typestr(fnode->return_type) + " " + fnode->name + "("; + for (int i = 0; i < fnode->arguments.size(); i++) { - if (i>0) - header+=", "; - header+=_prestr(fnode->arguments[i].precision)+_typestr(fnode->arguments[i].type)+" "+fnode->arguments[i].name; + if (i > 0) + header += ", "; + header += _prestr(fnode->arguments[i].precision) + _typestr(fnode->arguments[i].type) + " " + fnode->arguments[i].name; } - header+=")\n"; - code+=header; - code+=dump_node_code(fnode->body,p_level+1); + header += ")\n"; + code += header; + code += dump_node_code(fnode->body, p_level + 1); } //code+=dump_node_code(pnode->body,p_level); @@ -179,44 +168,42 @@ static String dump_node_code(SL::Node *p_node,int p_level) { } break; case SL::Node::TYPE_BLOCK: { - SL::BlockNode *bnode=(SL::BlockNode*)p_node; + SL::BlockNode *bnode = (SL::BlockNode *)p_node; //variables - code+=_mktab(p_level-1)+"{\n"; - for(Map<StringName,SL::BlockNode::Variable>::Element *E=bnode->variables.front();E;E=E->next()) { + code += _mktab(p_level - 1) + "{\n"; + for (Map<StringName, SL::BlockNode::Variable>::Element *E = bnode->variables.front(); E; E = E->next()) { - code+=_mktab(p_level)+_prestr(E->get().precision)+_typestr(E->get().type)+" "+E->key()+";\n"; + code += _mktab(p_level) + _prestr(E->get().precision) + _typestr(E->get().type) + " " + E->key() + ";\n"; } - for(int i=0;i<bnode->statements.size();i++) { + for (int i = 0; i < bnode->statements.size(); i++) { - String scode = dump_node_code(bnode->statements[i],p_level); + String scode = dump_node_code(bnode->statements[i], p_level); - if (bnode->statements[i]->type==SL::Node::TYPE_CONTROL_FLOW || bnode->statements[i]->type==SL::Node::TYPE_CONTROL_FLOW) { - code+=scode; //use directly + if (bnode->statements[i]->type == SL::Node::TYPE_CONTROL_FLOW || bnode->statements[i]->type == SL::Node::TYPE_CONTROL_FLOW) { + code += scode; //use directly } else { - code+=_mktab(p_level)+scode+";\n"; + code += _mktab(p_level) + scode + ";\n"; } } - code+=_mktab(p_level-1)+"}\n"; - + code += _mktab(p_level - 1) + "}\n"; } break; case SL::Node::TYPE_VARIABLE: { - SL::VariableNode *vnode=(SL::VariableNode*)p_node; - code=vnode->name; + SL::VariableNode *vnode = (SL::VariableNode *)p_node; + code = vnode->name; } break; case SL::Node::TYPE_CONSTANT: { - SL::ConstantNode *cnode=(SL::ConstantNode*)p_node; - return get_constant_text(cnode->datatype,cnode->values); + SL::ConstantNode *cnode = (SL::ConstantNode *)p_node; + return get_constant_text(cnode->datatype, cnode->values); } break; case SL::Node::TYPE_OPERATOR: { - SL::OperatorNode *onode=(SL::OperatorNode*)p_node; - + SL::OperatorNode *onode = (SL::OperatorNode *)p_node; - switch(onode->op) { + switch (onode->op) { case SL::OP_ASSIGN: case SL::OP_ASSIGN_ADD: @@ -229,84 +216,79 @@ static String dump_node_code(SL::Node *p_node,int p_level) { case SL::OP_ASSIGN_BIT_AND: case SL::OP_ASSIGN_BIT_OR: case SL::OP_ASSIGN_BIT_XOR: - code=dump_node_code(onode->arguments[0],p_level)+_opstr(onode->op)+dump_node_code(onode->arguments[1],p_level); + code = dump_node_code(onode->arguments[0], p_level) + _opstr(onode->op) + dump_node_code(onode->arguments[1], p_level); break; case SL::OP_BIT_INVERT: case SL::OP_NEGATE: case SL::OP_NOT: case SL::OP_DECREMENT: case SL::OP_INCREMENT: - code=_opstr(onode->op)+dump_node_code(onode->arguments[0],p_level); + code = _opstr(onode->op) + dump_node_code(onode->arguments[0], p_level); break; case SL::OP_POST_DECREMENT: case SL::OP_POST_INCREMENT: - code=dump_node_code(onode->arguments[0],p_level)+_opstr(onode->op); + code = dump_node_code(onode->arguments[0], p_level) + _opstr(onode->op); break; case SL::OP_CALL: case SL::OP_CONSTRUCT: - code=dump_node_code(onode->arguments[0],p_level)+"("; - for(int i=1;i<onode->arguments.size();i++) { - if (i>1) - code+=", "; - code+=dump_node_code(onode->arguments[i],p_level); + code = dump_node_code(onode->arguments[0], p_level) + "("; + for (int i = 1; i < onode->arguments.size(); i++) { + if (i > 1) + code += ", "; + code += dump_node_code(onode->arguments[i], p_level); } - code+=")"; + code += ")"; break; default: { - code="("+dump_node_code(onode->arguments[0],p_level)+_opstr(onode->op)+dump_node_code(onode->arguments[1],p_level)+")"; + code = "(" + dump_node_code(onode->arguments[0], p_level) + _opstr(onode->op) + dump_node_code(onode->arguments[1], p_level) + ")"; break; - } } } break; case SL::Node::TYPE_CONTROL_FLOW: { - SL::ControlFlowNode *cfnode=(SL::ControlFlowNode*)p_node; - if (cfnode->flow_op==SL::FLOW_OP_IF) { + SL::ControlFlowNode *cfnode = (SL::ControlFlowNode *)p_node; + if (cfnode->flow_op == SL::FLOW_OP_IF) { - code+=_mktab(p_level)+"if ("+dump_node_code(cfnode->expressions[0],p_level)+")\n"; - code+=dump_node_code(cfnode->blocks[0],p_level+1); - if (cfnode->blocks.size()==2) { + code += _mktab(p_level) + "if (" + dump_node_code(cfnode->expressions[0], p_level) + ")\n"; + code += dump_node_code(cfnode->blocks[0], p_level + 1); + if (cfnode->blocks.size() == 2) { - code+=_mktab(p_level)+"else\n"; - code+=dump_node_code(cfnode->blocks[1],p_level+1); + code += _mktab(p_level) + "else\n"; + code += dump_node_code(cfnode->blocks[1], p_level + 1); } - - } else if (cfnode->flow_op==SL::FLOW_OP_RETURN) { + } else if (cfnode->flow_op == SL::FLOW_OP_RETURN) { if (cfnode->blocks.size()) { - code="return "+dump_node_code(cfnode->blocks[0],p_level); + code = "return " + dump_node_code(cfnode->blocks[0], p_level); } else { - code="return"; + code = "return"; } } } break; case SL::Node::TYPE_MEMBER: { - SL::MemberNode *mnode=(SL::MemberNode*)p_node; - code=dump_node_code(mnode->owner,p_level)+"."+mnode->name; + SL::MemberNode *mnode = (SL::MemberNode *)p_node; + code = dump_node_code(mnode->owner, p_level) + "." + mnode->name; } break; } return code; - } -static Error recreate_code(void *p_str,SL::ShaderNode *p_program) { - +static Error recreate_code(void *p_str, SL::ShaderNode *p_program) { - String *str=(String*)p_str; + String *str = (String *)p_str; - *str=dump_node_code(p_program,0); + *str = dump_node_code(p_program, 0); return OK; } - -MainLoop* test() { +MainLoop *test() { List<String> cmdlargs = OS::get_singleton()->get_cmdline_args(); @@ -318,7 +300,7 @@ MainLoop* test() { String test = cmdlargs.back()->get(); - FileAccess *fa = FileAccess::open(test,FileAccess::READ); + FileAccess *fa = FileAccess::open(test, FileAccess::READ); if (!fa) { ERR_FAIL_V(NULL); @@ -326,36 +308,34 @@ MainLoop* test() { String code; - while(true) { + while (true) { CharType c = fa->get_8(); if (fa->eof_reached()) break; - code+=c; + code += c; } SL sl; - print_line("tokens:\n\n"+sl.token_debug(code)); + print_line("tokens:\n\n" + sl.token_debug(code)); - Map<StringName,Map<StringName,SL::DataType> > dt; - dt["fragment"]["ALBEDO"]=SL::TYPE_VEC3; + Map<StringName, Map<StringName, SL::DataType> > dt; + dt["fragment"]["ALBEDO"] = SL::TYPE_VEC3; Set<String> rm; rm.insert("popo"); - Error err = sl.compile(code,dt,rm); + Error err = sl.compile(code, dt, rm); if (err) { - print_line("Error at line: "+rtos(sl.get_error_line())+": "+sl.get_error_text()); + print_line("Error at line: " + rtos(sl.get_error_line()) + ": " + sl.get_error_text()); return NULL; } else { String code; - recreate_code(&code,sl.get_shader()); - print_line("code:\n\n"+code); + recreate_code(&code, sl.get_shader()); + print_line("code:\n\n" + code); } return NULL; } - - } diff --git a/main/tests/test_shader_lang.h b/main/tests/test_shader_lang.h index aae047ce10..3a3797ecdc 100644 --- a/main/tests/test_shader_lang.h +++ b/main/tests/test_shader_lang.h @@ -33,8 +33,7 @@ namespace TestShaderLang { -MainLoop* test(); - +MainLoop *test(); } #endif // TEST_SHADER_LANG_H diff --git a/main/tests/test_sound.cpp b/main/tests/test_sound.cpp index 095ce001ba..9683faf1e5 100644 --- a/main/tests/test_sound.cpp +++ b/main/tests/test_sound.cpp @@ -27,14 +27,14 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ #include "test_sound.h" -#include "servers/visual_server.h" -#include "os/main_loop.h" #include "math_funcs.h" +#include "os/main_loop.h" +#include "servers/visual_server.h" #include "io/resource_loader.h" +#include "os/os.h" #include "print_string.h" #include "servers/audio_server.h" -#include "os/os.h" #if 0 namespace TestSound { diff --git a/main/tests/test_sound.h b/main/tests/test_sound.h index 167751bd1d..1246e3b9c5 100644 --- a/main/tests/test_sound.h +++ b/main/tests/test_sound.h @@ -33,8 +33,7 @@ namespace TestSound { -MainLoop* test(); - +MainLoop *test(); } #endif // TEST_SOUND_H diff --git a/main/tests/test_string.cpp b/main/tests/test_string.cpp index ca7fdedcb8..41ec113845 100644 --- a/main/tests/test_string.cpp +++ b/main/tests/test_string.cpp @@ -29,9 +29,9 @@ #include "ustring.h" #include <wchar.h> //#include "math_funcs.h" -#include <stdio.h> -#include "os/os.h" #include "core/io/ip_address.h" +#include "os/os.h" +#include <stdio.h> #include "test_string.h" @@ -44,10 +44,9 @@ bool test_1() { String s = "Hello"; OS::get_singleton()->print("\tExpected: Hello\n"); - OS::get_singleton()->print("\tResulted: %ls\n",s.c_str()); - - return (wcscmp(s.c_str(),L"Hello")==0); + OS::get_singleton()->print("\tResulted: %ls\n", s.c_str()); + return (wcscmp(s.c_str(), L"Hello") == 0); } bool test_2() { @@ -58,10 +57,9 @@ bool test_2() { String t = s; OS::get_singleton()->print("\tExpected: Dolly\n"); - OS::get_singleton()->print("\tResulted: %ls\n",t.c_str()); - - return (wcscmp(t.c_str(),L"Dolly")==0); + OS::get_singleton()->print("\tResulted: %ls\n", t.c_str()); + return (wcscmp(t.c_str(), L"Dolly") == 0); } bool test_3() { @@ -72,10 +70,9 @@ bool test_3() { String t(s); OS::get_singleton()->print("\tExpected: Sheep\n"); - OS::get_singleton()->print("\tResulted: %ls\n",t.c_str()); - - return (wcscmp(t.c_str(),L"Sheep")==0); + OS::get_singleton()->print("\tResulted: %ls\n", t.c_str()); + return (wcscmp(t.c_str(), L"Sheep") == 0); } bool test_4() { @@ -85,10 +82,9 @@ bool test_4() { String s(L"Give me"); OS::get_singleton()->print("\tExpected: Give me\n"); - OS::get_singleton()->print("\tResulted: %ls\n",s.c_str()); - - return (wcscmp(s.c_str(),L"Give me")==0); + OS::get_singleton()->print("\tResulted: %ls\n", s.c_str()); + return (wcscmp(s.c_str(), L"Give me") == 0); } bool test_5() { @@ -98,89 +94,81 @@ bool test_5() { String s(L"Wool"); OS::get_singleton()->print("\tExpected: Wool\n"); - OS::get_singleton()->print("\tResulted: %ls\n",s.c_str()); - - return (wcscmp(s.c_str(),L"Wool")==0); + OS::get_singleton()->print("\tResulted: %ls\n", s.c_str()); + return (wcscmp(s.c_str(), L"Wool") == 0); } bool test_6() { OS::get_singleton()->print("\n\nTest 6: comparisons (equal)\n"); - - String s="Test Compare"; + String s = "Test Compare"; OS::get_singleton()->print("\tComparing to \"Test Compare\"\n"); - if (! ( s=="Test Compare" ) ) + if (!(s == "Test Compare")) return false; - if (! ( s==L"Test Compare" ) ) + if (!(s == L"Test Compare")) return false; - if (! ( s==String("Test Compare") ) ) + if (!(s == String("Test Compare"))) return false; return true; - } bool test_7() { OS::get_singleton()->print("\n\nTest 7: comparisons (unequal)\n"); - - String s="Test Compare"; + String s = "Test Compare"; OS::get_singleton()->print("\tComparing to \"Test Compare\"\n"); - if (! ( s!="Peanut" ) ) + if (!(s != "Peanut")) return false; - if (! ( s!=L"Coconut" ) ) + if (!(s != L"Coconut")) return false; - if (! ( s!=String("Butter") ) ) + if (!(s != String("Butter"))) return false; return true; - } bool test_8() { OS::get_singleton()->print("\n\nTest 8: comparisons (operator<)\n"); - - String s="Bees"; + String s = "Bees"; OS::get_singleton()->print("\tComparing to \"Bees\"\n"); - if ( ! (s < "Elephant") ) + if (!(s < "Elephant")) return false; - if ( s < L"Amber" ) + if (s < L"Amber") return false; - if ( s < String("Beatrix") ) + if (s < String("Beatrix")) return false; return true; - } bool test_9() { OS::get_singleton()->print("\n\nTest 9: Concatenation\n"); - String s; - s+="Have"; - s+=' '; - s+='a'; - s+=String(" "); + s += "Have"; + s += ' '; + s += 'a'; + s += String(" "); s = s + L"Nice"; s = s + " "; s = s + String("Day"); @@ -188,14 +176,13 @@ bool test_9() { OS::get_singleton()->print("\tComparing to \"Have a Nice Day\"\n"); return (s == "Have a Nice Day"); - } bool test_10() { OS::get_singleton()->print("\n\nTest 10: Misc funcs (size/length/empty/etc)\n"); - if (! String("").empty()) + if (!String("").empty()) return false; if (String("Mellon").size() != 7) @@ -205,44 +192,39 @@ bool test_10() { return false; return true; - } - bool test_11() { OS::get_singleton()->print("\n\nTest 11: Operator[]\n"); - String a="Kugar Sane"; + String a = "Kugar Sane"; - a[0]='S'; - a[6]='C'; + a[0] = 'S'; + a[6] = 'C'; if (a != "Sugar Cane") return false; - if (a[1]!='u') + if (a[1] != 'u') return false; return true; - } bool test_12() { OS::get_singleton()->print("\n\nTest 12: case functions\n"); - - String a="MoMoNgA"; + String a = "MoMoNgA"; if (a.to_upper() != "MOMONGA") return false; - if (a.nocasecmp_to("momonga")!=0) + if (a.nocasecmp_to("momonga") != 0) return false; return true; - } bool test_13() { @@ -251,16 +233,15 @@ bool test_13() { /* how can i embed UTF in here? */ - static const CharType ustr[] = { 0x304A , 0x360F, 0x3088, 0x3046, 0 }; + static const CharType ustr[] = { 0x304A, 0x360F, 0x3088, 0x3046, 0 }; //static const wchar_t ustr[] = { 'P', 0xCE, 'p',0xD3, 0 }; - String s=ustr; - - OS::get_singleton()->print("\tUnicode: %ls\n",ustr); - s.parse_utf8( s.utf8().get_data() ); - OS::get_singleton()->print("\tConvert/Parse UTF8: %ls\n",s.c_str()); + String s = ustr; - return (s==ustr); + OS::get_singleton()->print("\tUnicode: %ls\n", ustr); + s.parse_utf8(s.utf8().get_data()); + OS::get_singleton()->print("\tConvert/Parse UTF8: %ls\n", s.c_str()); + return (s == ustr); } bool test_14() { @@ -268,195 +249,180 @@ bool test_14() { OS::get_singleton()->print("\n\nTest 14: ASCII\n"); String s = L"Primero Leche"; - OS::get_singleton()->print("\tAscii: %s\n",s.ascii().get_data()); - - String t=s.ascii().get_data(); - return (s==t); + OS::get_singleton()->print("\tAscii: %s\n", s.ascii().get_data()); + String t = s.ascii().get_data(); + return (s == t); } bool test_15() { OS::get_singleton()->print("\n\nTest 15: substr\n"); - String s="Killer Baby"; - OS::get_singleton()->print("\tsubstr(3,4) of \"%ls\" is \"%ls\"\n",s.c_str(),s.substr(3,4).c_str()); - - return (s.substr(3,4)=="ler "); + String s = "Killer Baby"; + OS::get_singleton()->print("\tsubstr(3,4) of \"%ls\" is \"%ls\"\n", s.c_str(), s.substr(3, 4).c_str()); + return (s.substr(3, 4) == "ler "); } bool test_16() { OS::get_singleton()->print("\n\nTest 16: find\n"); - String s="Pretty Woman"; - OS::get_singleton()->print("\tString: %ls\n",s.c_str()); - OS::get_singleton()->print("\t\"tty\" is at %i pos.\n",s.find("tty")); - OS::get_singleton()->print("\t\"Revenge of the Monster Truck\" is at %i pos.\n",s.find("Revenge of the Monster Truck")); + String s = "Pretty Woman"; + OS::get_singleton()->print("\tString: %ls\n", s.c_str()); + OS::get_singleton()->print("\t\"tty\" is at %i pos.\n", s.find("tty")); + OS::get_singleton()->print("\t\"Revenge of the Monster Truck\" is at %i pos.\n", s.find("Revenge of the Monster Truck")); - if (s.find("tty")!=3) + if (s.find("tty") != 3) return false; - if (s.find("Revenge of the Monster Truck")!=-1) + if (s.find("Revenge of the Monster Truck") != -1) return false; return true; - } bool test_17() { OS::get_singleton()->print("\n\nTest 17: find no case\n"); - String s="Pretty Whale"; - OS::get_singleton()->print("\tString: %ls\n",s.c_str()); - OS::get_singleton()->print("\t\"WHA\" is at %i pos.\n",s.findn("WHA")); - OS::get_singleton()->print("\t\"Revenge of the Monster SawFish\" is at %i pos.\n",s.findn("Revenge of the Monster Truck")); + String s = "Pretty Whale"; + OS::get_singleton()->print("\tString: %ls\n", s.c_str()); + OS::get_singleton()->print("\t\"WHA\" is at %i pos.\n", s.findn("WHA")); + OS::get_singleton()->print("\t\"Revenge of the Monster SawFish\" is at %i pos.\n", s.findn("Revenge of the Monster Truck")); - if (s.findn("WHA")!=7) + if (s.findn("WHA") != 7) return false; - if (s.findn("Revenge of the Monster SawFish")!=-1) + if (s.findn("Revenge of the Monster SawFish") != -1) return false; return true; - } bool test_18() { OS::get_singleton()->print("\n\nTest 18: find no case\n"); - String s="Pretty Whale"; - OS::get_singleton()->print("\tString: %ls\n",s.c_str()); - OS::get_singleton()->print("\t\"WHA\" is at %i pos.\n",s.findn("WHA")); - OS::get_singleton()->print("\t\"Revenge of the Monster SawFish\" is at %i pos.\n",s.findn("Revenge of the Monster Truck")); + String s = "Pretty Whale"; + OS::get_singleton()->print("\tString: %ls\n", s.c_str()); + OS::get_singleton()->print("\t\"WHA\" is at %i pos.\n", s.findn("WHA")); + OS::get_singleton()->print("\t\"Revenge of the Monster SawFish\" is at %i pos.\n", s.findn("Revenge of the Monster Truck")); - if (s.findn("WHA")!=7) + if (s.findn("WHA") != 7) return false; - if (s.findn("Revenge of the Monster SawFish")!=-1) + if (s.findn("Revenge of the Monster SawFish") != -1) return false; return true; - } bool test_19() { OS::get_singleton()->print("\n\nTest 19: Search & replace\n"); - String s="Happy Birthday, Anna!"; - OS::get_singleton()->print("\tString: %ls\n",s.c_str()); + String s = "Happy Birthday, Anna!"; + OS::get_singleton()->print("\tString: %ls\n", s.c_str()); - s=s.replace("Birthday","Halloween"); - OS::get_singleton()->print("\tReplaced Birthday/Halloween: %ls.\n",s.c_str()); - - return (s=="Happy Halloween, Anna!"); + s = s.replace("Birthday", "Halloween"); + OS::get_singleton()->print("\tReplaced Birthday/Halloween: %ls.\n", s.c_str()); + return (s == "Happy Halloween, Anna!"); } bool test_20() { OS::get_singleton()->print("\n\nTest 20: Insertion\n"); - String s="Who is Frederic?"; - - OS::get_singleton()->print("\tString: %ls\n",s.c_str()); - s=s.insert( s.find("?")," Chopin" ); - OS::get_singleton()->print("\tInserted Chopin: %ls.\n",s.c_str()); + String s = "Who is Frederic?"; - return (s=="Who is Frederic Chopin?"); + OS::get_singleton()->print("\tString: %ls\n", s.c_str()); + s = s.insert(s.find("?"), " Chopin"); + OS::get_singleton()->print("\tInserted Chopin: %ls.\n", s.c_str()); + return (s == "Who is Frederic Chopin?"); } bool test_21() { OS::get_singleton()->print("\n\nTest 21: Number -> String\n"); - OS::get_singleton()->print("\tPi is %f\n",33.141593); - OS::get_singleton()->print("\tPi String is %ls\n",String::num(3.141593).c_str()); - - return String::num(3.141593)=="3.141593"; + OS::get_singleton()->print("\tPi is %f\n", 33.141593); + OS::get_singleton()->print("\tPi String is %ls\n", String::num(3.141593).c_str()); + return String::num(3.141593) == "3.141593"; } bool test_22() { OS::get_singleton()->print("\n\nTest 22: String -> Int\n"); - static const char* nums[4]={ "1237461283", "- 22", "0", " - 1123412" }; - static const int num[4]={ 1237461283, -22, 0, -1123412 }; + static const char *nums[4] = { "1237461283", "- 22", "0", " - 1123412" }; + static const int num[4] = { 1237461283, -22, 0, -1123412 }; - for (int i=0;i<4;i++) { - OS::get_singleton()->print("\tString: \"%s\" as Int is %i\n",nums[i],String(nums[i]).to_int()); + for (int i = 0; i < 4; i++) { + OS::get_singleton()->print("\tString: \"%s\" as Int is %i\n", nums[i], String(nums[i]).to_int()); - if (String(nums[i]).to_int()!=num[i]) + if (String(nums[i]).to_int() != num[i]) return false; } return true; - } bool test_23() { OS::get_singleton()->print("\n\nTest 23: String -> Float\n"); - static const char* nums[4]={ "-12348298412.2", "0.05", "2.0002", " -0.0001" }; - static const double num[4]={ -12348298412.2, 0.05, 2.0002, -0.0001 }; + static const char *nums[4] = { "-12348298412.2", "0.05", "2.0002", " -0.0001" }; + static const double num[4] = { -12348298412.2, 0.05, 2.0002, -0.0001 }; - for (int i=0;i<4;i++) { - OS::get_singleton()->print("\tString: \"%s\" as Float is %f\n",nums[i],String(nums[i]).to_double()); + for (int i = 0; i < 4; i++) { + OS::get_singleton()->print("\tString: \"%s\" as Float is %f\n", nums[i], String(nums[i]).to_double()); - if ( ABS(String(nums[i]).to_double()-num[i])>0.00001) + if (ABS(String(nums[i]).to_double() - num[i]) > 0.00001) return false; } return true; - } - bool test_24() { OS::get_singleton()->print("\n\nTest 24: Slicing\n"); - String s="Mars,Jupiter,Saturn,Uranus"; - - const char*slices[4]={"Mars","Jupiter","Saturn","Uranus"}; + String s = "Mars,Jupiter,Saturn,Uranus"; - OS::get_singleton()->print("\tSlicing \"%ls\" by \"%s\"..\n",s.c_str(),","); + const char *slices[4] = { "Mars", "Jupiter", "Saturn", "Uranus" }; - for (int i=0;i<s.get_slice_count(",");i++) { + OS::get_singleton()->print("\tSlicing \"%ls\" by \"%s\"..\n", s.c_str(), ","); - OS::get_singleton()->print("\t\t%i- %ls\n",i+1,s.get_slice(",",i).c_str()); + for (int i = 0; i < s.get_slice_count(","); i++) { + OS::get_singleton()->print("\t\t%i- %ls\n", i + 1, s.get_slice(",", i).c_str()); - if (s.get_slice(",",i)!=slices[i]) + if (s.get_slice(",", i) != slices[i]) return false; } return true; - } bool test_25() { OS::get_singleton()->print("\n\nTest 25: Erasing\n"); - String s="Josephine is such a cute girl!"; + String s = "Josephine is such a cute girl!"; - OS::get_singleton()->print("\tString: %ls\n",s.c_str()); + OS::get_singleton()->print("\tString: %ls\n", s.c_str()); OS::get_singleton()->print("\tRemoving \"cute\"\n"); - s.erase(s.find("cute "),String("cute ").length()); - OS::get_singleton()->print("\tResult: %ls\n",s.c_str()); - - - return (s=="Josephine is such a girl!"); + s.erase(s.find("cute "), String("cute ").length()); + OS::get_singleton()->print("\tResult: %ls\n", s.c_str()); + return (s == "Josephine is such a girl!"); } bool test_26() { @@ -466,8 +432,8 @@ bool test_26() { }; struct test_27_data { - char const * data; - char const * begin; + char const *data; + char const *begin; bool expected; }; @@ -475,13 +441,13 @@ bool test_27() { OS::get_singleton()->print("\n\nTest 27: begins_with\n"); test_27_data tc[] = { - {"res://foobar", "res://", true}, - {"res", "res://", false}, - {"abc", "abc", true} + { "res://foobar", "res://", true }, + { "res", "res://", false }, + { "abc", "abc", true } }; size_t count = sizeof(tc) / sizeof(tc[0]); bool state = true; - for (size_t i = 0;state && i < count; ++i) { + for (size_t i = 0; state && i < count; ++i) { String s = tc[i].data; state = s.begins_with(tc[i].begin) == tc[i].expected; if (state) { @@ -496,7 +462,6 @@ bool test_27() { return state; }; - bool test_28() { OS::get_singleton()->print("\n\nTest 28: sprintf\n"); @@ -925,22 +890,22 @@ TestFunc test_funcs[] = { }; -MainLoop* test() { +MainLoop *test() { /** A character length != wchar_t may be forced, so the tests wont work */ - ERR_FAIL_COND_V( sizeof(CharType) != sizeof(wchar_t), NULL ); + ERR_FAIL_COND_V(sizeof(CharType) != sizeof(wchar_t), NULL); - int count=0; - int passed=0; + int count = 0; + int passed = 0; - while(true) { + while (true) { if (!test_funcs[count]) break; - bool pass=test_funcs[count](); + bool pass = test_funcs[count](); if (pass) passed++; - OS::get_singleton()->print("\t%s\n",pass?"PASS":"FAILED"); + OS::get_singleton()->print("\t%s\n", pass ? "PASS" : "FAILED"); count++; } @@ -954,5 +919,4 @@ MainLoop* test() { return NULL; } - } diff --git a/main/tests/test_string.h b/main/tests/test_string.h index 12df7f126f..c8116a0c53 100644 --- a/main/tests/test_string.h +++ b/main/tests/test_string.h @@ -29,16 +29,12 @@ #ifndef TEST_STRING_H #define TEST_STRING_H -#include "ustring.h" #include "os/main_loop.h" +#include "ustring.h" namespace TestString { -MainLoop* test(); - +MainLoop *test(); } - #endif - - |