aboutsummaryrefslogtreecommitdiff
path: root/platform/iphone/os_iphone.cpp
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--platform/iphone/os_iphone.cpp115
1 files changed, 53 insertions, 62 deletions
diff --git a/platform/iphone/os_iphone.cpp b/platform/iphone/os_iphone.cpp
index c7eef6d33..73acb3a18 100644
--- a/platform/iphone/os_iphone.cpp
+++ b/platform/iphone/os_iphone.cpp
@@ -32,17 +32,16 @@
#include "drivers/gles2/rasterizer_gles2.h"
-
#include "servers/visual/visual_server_raster.h"
#include "servers/visual/visual_server_wrap_mt.h"
-#include "main/main.h"
#include "audio_driver_iphone.h"
+#include "main/main.h"
+#include "core/globals.h"
+#include "core/io/file_access_pack.h"
#include "core/os/dir_access.h"
#include "core/os/file_access.h"
-#include "core/io/file_access_pack.h"
-#include "core/globals.h"
#include "sem_iphone.h"
@@ -53,17 +52,16 @@ int OSIPhone::get_video_driver_count() const {
return 1;
};
-const char * OSIPhone::get_video_driver_name(int p_driver) const {
+const char *OSIPhone::get_video_driver_name(int p_driver) const {
return "GLES2";
};
-OSIPhone* OSIPhone::get_singleton() {
+OSIPhone *OSIPhone::get_singleton() {
- return (OSIPhone*)OS::get_singleton();
+ return (OSIPhone *)OS::get_singleton();
};
-
OS::VideoMode OSIPhone::get_default_video_mode() const {
return video_mode;
@@ -78,7 +76,7 @@ extern int gl_view_base_fb; // from gl_view.mm
void OSIPhone::set_data_dir(String p_dir) {
- DirAccess* da = DirAccess::open(p_dir);
+ DirAccess *da = DirAccess::open(p_dir);
data_dir = da->get_current_dir();
printf("setting data dir to %ls from %ls\n", data_dir.c_str(), p_dir.c_str());
@@ -101,19 +99,19 @@ void OSIPhone::initialize_core() {
SemaphoreIphone::make_default();
};
-void OSIPhone::initialize(const VideoMode& p_desired,int p_video_driver,int p_audio_driver) {
+void OSIPhone::initialize(const VideoMode &p_desired, int p_video_driver, int p_audio_driver) {
supported_orientations = 0;
- supported_orientations |= ((GLOBAL_DEF("video_mode/allow_horizontal", true)?1:0) << LandscapeLeft);
- supported_orientations |= ((GLOBAL_DEF("video_mode/allow_horizontal_flipped", false)?1:0) << LandscapeRight);
- supported_orientations |= ((GLOBAL_DEF("video_mode/allow_vertical", false)?1:0) << PortraitDown);
- supported_orientations |= ((GLOBAL_DEF("video_mode/allow_vertical_flipped", false)?1:0) << PortraitUp);
+ supported_orientations |= ((GLOBAL_DEF("video_mode/allow_horizontal", true) ? 1 : 0) << LandscapeLeft);
+ supported_orientations |= ((GLOBAL_DEF("video_mode/allow_horizontal_flipped", false) ? 1 : 0) << LandscapeRight);
+ supported_orientations |= ((GLOBAL_DEF("video_mode/allow_vertical", false) ? 1 : 0) << PortraitDown);
+ supported_orientations |= ((GLOBAL_DEF("video_mode/allow_vertical_flipped", false) ? 1 : 0) << PortraitUp);
- rasterizer_gles22 = memnew( RasterizerGLES2(false, false, false) );
+ rasterizer_gles22 = memnew(RasterizerGLES2(false, false, false));
rasterizer = rasterizer_gles22;
rasterizer_gles22->set_base_framebuffer(gl_view_base_fb);
- visual_server = memnew( VisualServerRaster(rasterizer) );
+ visual_server = memnew(VisualServerRaster(rasterizer));
if (get_render_thread_mode() != RENDER_THREAD_UNSAFE) {
visual_server = memnew(VisualServerWrapMT(visual_server, false));
@@ -127,25 +125,25 @@ void OSIPhone::initialize(const VideoMode& p_desired,int p_video_driver,int p_au
audio_driver->set_singleton();
audio_driver->init();
- sample_manager = memnew( SampleManagerMallocSW );
- audio_server = memnew( AudioServerSW(sample_manager) );
+ sample_manager = memnew(SampleManagerMallocSW);
+ audio_server = memnew(AudioServerSW(sample_manager));
audio_server->init();
- spatial_sound_server = memnew( SpatialSoundServerSW );
+ spatial_sound_server = memnew(SpatialSoundServerSW);
spatial_sound_server->init();
- spatial_sound_2d_server = memnew( SpatialSound2DServerSW );
+ spatial_sound_2d_server = memnew(SpatialSound2DServerSW);
spatial_sound_2d_server->init();
//
- physics_server = memnew( PhysicsServerSW );
+ physics_server = memnew(PhysicsServerSW);
physics_server->init();
//physics_2d_server = memnew( Physics2DServerSW );
physics_2d_server = Physics2DServerWrapMT::init_server<Physics2DServerSW>();
physics_2d_server->init();
- input = memnew( InputDefault );
+ input = memnew(InputDefault);
- /*
+/*
#ifdef IOS_SCORELOOP_ENABLED
scoreloop = memnew(ScoreloopIOS);
Globals::get_singleton()->add_singleton(Globals::Singleton("Scoreloop", scoreloop));
@@ -167,7 +165,7 @@ void OSIPhone::initialize(const VideoMode& p_desired,int p_video_driver,int p_au
#ifdef ICLOUD_ENABLED
icloud = memnew(ICloud);
Globals::get_singleton()->add_singleton(Globals::Singleton("ICloud", icloud));
- //icloud->connect();
+//icloud->connect();
#endif
Globals::get_singleton()->add_singleton(Globals::Singleton("iOS", memnew(iOS)));
};
@@ -177,8 +175,7 @@ MainLoop *OSIPhone::get_main_loop() const {
return main_loop;
};
-
-void OSIPhone::set_main_loop( MainLoop * p_main_loop ) {
+void OSIPhone::set_main_loop(MainLoop *p_main_loop) {
main_loop = p_main_loop;
@@ -188,14 +185,13 @@ void OSIPhone::set_main_loop( MainLoop * p_main_loop ) {
}
};
-
bool OSIPhone::iterate() {
if (!main_loop)
return true;
if (main_loop) {
- for (int i=0; i<event_count; i++) {
+ for (int i = 0; i < event_count; i++) {
input->parse_input_event(event_queue[i]);
};
@@ -223,10 +219,10 @@ void OSIPhone::mouse_button(int p_idx, int p_x, int p_y, bool p_pressed, bool p_
InputEvent ev;
ev.type = InputEvent::SCREEN_TOUCH;
ev.ID = ++last_event_id;
- ev.screen_touch.index=p_idx;
- ev.screen_touch.pressed=p_pressed;
- ev.screen_touch.x=p_x;
- ev.screen_touch.y=p_y;
+ ev.screen_touch.index = p_idx;
+ ev.screen_touch.pressed = p_pressed;
+ ev.screen_touch.x = p_x;
+ ev.screen_touch.y = p_y;
queue_event(ev);
};
@@ -248,7 +244,7 @@ void OSIPhone::mouse_button(int p_idx, int p_x, int p_y, bool p_pressed, bool p_
//mouse_list.pressed[p_idx] = p_pressed;
- input->set_mouse_pos(Point2(ev.mouse_motion.x,ev.mouse_motion.y));
+ input->set_mouse_pos(Point2(ev.mouse_motion.x, ev.mouse_motion.y));
ev.mouse_button.button_index = BUTTON_LEFT;
ev.mouse_button.doubleclick = p_doubleclick;
ev.mouse_button.pressed = p_pressed;
@@ -262,11 +258,11 @@ void OSIPhone::mouse_move(int p_idx, int p_prev_x, int p_prev_y, int p_x, int p_
if (!GLOBAL_DEF("debug/disable_touch", false)) {
InputEvent ev;
- ev.type=InputEvent::SCREEN_DRAG;
+ ev.type = InputEvent::SCREEN_DRAG;
ev.ID = ++last_event_id;
- ev.screen_drag.index=p_idx;
- ev.screen_drag.x=p_x;
- ev.screen_drag.y=p_y;
+ ev.screen_drag.index = p_idx;
+ ev.screen_drag.x = p_x;
+ ev.screen_drag.y = p_y;
ev.screen_drag.relative_x = p_x - p_prev_x;
ev.screen_drag.relative_y = p_y - p_prev_y;
queue_event(ev);
@@ -293,25 +289,25 @@ void OSIPhone::mouse_move(int p_idx, int p_prev_x, int p_prev_y, int p_x, int p_
ev.mouse_motion.relative_y = ev.mouse_motion.y - p_prev_x;
};
- input->set_mouse_pos(Point2(ev.mouse_motion.x,ev.mouse_motion.y));
- ev.mouse_motion.speed_x=input->get_mouse_speed().x;
- ev.mouse_motion.speed_y=input->get_mouse_speed().y;
+ input->set_mouse_pos(Point2(ev.mouse_motion.x, ev.mouse_motion.y));
+ ev.mouse_motion.speed_x = input->get_mouse_speed().x;
+ ev.mouse_motion.speed_y = input->get_mouse_speed().y;
ev.mouse_motion.button_mask = 1; // pressed
queue_event(ev);
};
};
-void OSIPhone::queue_event(const InputEvent& p_event) {
+void OSIPhone::queue_event(const InputEvent &p_event) {
- ERR_FAIL_INDEX( event_count, MAX_EVENTS );
+ ERR_FAIL_INDEX(event_count, MAX_EVENTS);
event_queue[event_count++] = p_event;
};
void OSIPhone::touches_cancelled() {
- for (int i=0; i<MAX_MOUSE_COUNT; i++) {
+ for (int i = 0; i < MAX_MOUSE_COUNT; i++) {
if (mouse_list.pressed[i]) {
@@ -331,13 +327,12 @@ void OSIPhone::update_accelerometer(float p_x, float p_y, float p_z) {
// Found out the Z should not be negated! Pass as is!
input->set_accelerometer(Vector3(p_x / (float)ACCEL_RANGE, p_y / (float)ACCEL_RANGE, p_z / (float)ACCEL_RANGE));
-
};
void OSIPhone::update_magnetometer(float p_x, float p_y, float p_z) {
input->set_magnetometer(Vector3(p_x, p_y, p_z));
};
-
+
void OSIPhone::update_gyroscope(float p_x, float p_y, float p_z) {
input->set_gyroscope(Vector3(p_x, p_y, p_z));
};
@@ -354,7 +349,7 @@ void OSIPhone::delete_main_loop() {
void OSIPhone::finalize() {
- if(main_loop) // should not happen?
+ if (main_loop) // should not happen?
memdelete(main_loop);
visual_server->finish();
@@ -374,11 +369,10 @@ void OSIPhone::finalize() {
spatial_sound_2d_server->finish();
memdelete(spatial_sound_2d_server);
-
};
-void OSIPhone::set_mouse_show(bool p_show) { };
-void OSIPhone::set_mouse_grab(bool p_grab) { };
+void OSIPhone::set_mouse_show(bool p_show){};
+void OSIPhone::set_mouse_grab(bool p_grab){};
bool OSIPhone::is_mouse_grab_enabled() const {
@@ -395,9 +389,9 @@ int OSIPhone::get_mouse_button_state() const {
return mouse_list.pressed[0];
};
-void OSIPhone::set_window_title(const String& p_title) { };
+void OSIPhone::set_window_title(const String &p_title){};
-void OSIPhone::set_video_mode(const VideoMode& p_video_mode, int p_screen) {
+void OSIPhone::set_video_mode(const VideoMode &p_video_mode, int p_screen) {
video_mode = p_video_mode;
};
@@ -436,7 +430,7 @@ extern void _hide_keyboard();
extern Error _shell_open(String p_uri);
extern void _set_keep_screen_on(bool p_enabled);
-void OSIPhone::show_virtual_keyboard(const String& p_existing_text,const Rect2& p_screen_rect) {
+void OSIPhone::show_virtual_keyboard(const String &p_existing_text, const Rect2 &p_screen_rect) {
_show_keyboard(p_existing_text);
};
@@ -453,8 +447,7 @@ void OSIPhone::set_keep_screen_on(bool p_enabled) {
_set_keep_screen_on(p_enabled);
};
-void OSIPhone::set_cursor_shape(CursorShape p_shape) {
-
+void OSIPhone::set_cursor_shape(CursorShape p_shape){
};
@@ -478,8 +471,7 @@ bool OSIPhone::has_touchscreen_ui_hint() const {
return true;
}
-void OSIPhone::set_locale(String p_locale)
-{
+void OSIPhone::set_locale(String p_locale) {
locale_code = p_locale;
}
@@ -495,7 +487,7 @@ extern void _stop_video();
extern void _focus_out_video();
Error OSIPhone::native_video_play(String p_path, float p_volume, String p_audio_track, String p_subtitle_track) {
- FileAccess* f = FileAccess::open(p_path, FileAccess::READ);
+ FileAccess *f = FileAccess::open(p_path, FileAccess::READ);
bool exists = f && f->is_open();
String tempFile = get_data_dir();
@@ -515,18 +507,18 @@ Error OSIPhone::native_video_play(String p_path, float p_volume, String p_audio_
memdelete(f);
print("Playing video: %S\n", p_path.c_str());
- if (_play_video(p_path, p_volume, p_audio_track, p_subtitle_track) )
+ if (_play_video(p_path, p_volume, p_audio_track, p_subtitle_track))
return OK;
return FAILED;
}
bool OSIPhone::native_video_is_playing() const {
- return _is_video_playing();
+ return _is_video_playing();
}
void OSIPhone::native_video_pause() {
if (native_video_is_playing())
- _pause_video();
+ _pause_video();
}
void OSIPhone::native_video_unpause() {
@@ -539,7 +531,7 @@ void OSIPhone::native_video_focus_out() {
void OSIPhone::native_video_stop() {
if (native_video_is_playing())
- _stop_video();
+ _stop_video();
}
OSIPhone::OSIPhone(int width, int height) {
@@ -560,7 +552,6 @@ OSIPhone::OSIPhone(int width, int height) {
};
OSIPhone::~OSIPhone() {
-
}
#endif