Working on iOS
This commit is contained in:
@@ -14,24 +14,18 @@ namespace lime {
|
||||
|
||||
|
||||
AutoGCRoot* Application::callback = 0;
|
||||
|
||||
|
||||
double Application::GetTicks () {
|
||||
|
||||
return SDL_GetTicks ();
|
||||
|
||||
}
|
||||
SDLApplication* SDLApplication::currentApplication = 0;
|
||||
|
||||
|
||||
SDLApplication::SDLApplication () {
|
||||
|
||||
SDL_Init (SDL_INIT_VIDEO | SDL_INIT_GAMECONTROLLER | SDL_INIT_TIMER);
|
||||
|
||||
#ifdef EMSCRIPTEN
|
||||
currentApplication = this;
|
||||
|
||||
#ifdef EMSCRIPTEN
|
||||
emscripten_cancel_main_loop ();
|
||||
emscripten_set_main_loop (EmscriptenUpdate, 0, 0);
|
||||
emscripten_set_main_loop (UpdateFrame, 0, 0);
|
||||
emscripten_set_main_loop_timing (EM_TIMING_RAF, 1);
|
||||
#endif
|
||||
|
||||
@@ -194,7 +188,7 @@ namespace lime {
|
||||
}
|
||||
|
||||
|
||||
void SDLApplication::Init() {
|
||||
void SDLApplication::Init () {
|
||||
|
||||
framePeriod = 1000.0 / 60.0;
|
||||
active = true;
|
||||
@@ -380,6 +374,15 @@ namespace lime {
|
||||
}
|
||||
|
||||
|
||||
void SDLApplication::RegisterWindow (SDLWindow *window) {
|
||||
|
||||
#ifdef IPHONE
|
||||
SDL_iPhoneSetAnimationCallback (window->sdlWindow, 1, UpdateFrame, NULL);
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
|
||||
static SDL_TimerID timerID = 0;
|
||||
bool timerActive = false;
|
||||
bool firstTime = true;
|
||||
@@ -410,7 +413,7 @@ namespace lime {
|
||||
SDL_Event event;
|
||||
event.type = -1;
|
||||
|
||||
#ifndef EMSCRIPTEN
|
||||
#if (!defined (EMSCRIPTEN) && !defined (IPHONE))
|
||||
|
||||
if (active && (firstTime || SDL_WaitEvent (&event))) {
|
||||
|
||||
@@ -464,6 +467,20 @@ namespace lime {
|
||||
}
|
||||
|
||||
|
||||
void SDLApplication::UpdateFrame (void*) {
|
||||
|
||||
currentApplication->Update ();
|
||||
|
||||
}
|
||||
|
||||
|
||||
double Application::GetTicks () {
|
||||
|
||||
return SDL_GetTicks ();
|
||||
|
||||
}
|
||||
|
||||
|
||||
Application* CreateApplication () {
|
||||
|
||||
return new SDLApplication ();
|
||||
@@ -471,17 +488,6 @@ namespace lime {
|
||||
}
|
||||
|
||||
|
||||
#ifdef EMSCRIPTEN
|
||||
SDLApplication* SDLApplication::currentApplication = 0;
|
||||
|
||||
void SDLApplication::EmscriptenUpdate () {
|
||||
|
||||
currentApplication->Update ();
|
||||
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
#include <ui/MouseEvent.h>
|
||||
#include <ui/TouchEvent.h>
|
||||
#include <ui/WindowEvent.h>
|
||||
#include "SDLWindow.h"
|
||||
|
||||
|
||||
namespace lime {
|
||||
@@ -28,10 +29,7 @@ namespace lime {
|
||||
virtual int Quit ();
|
||||
virtual bool Update ();
|
||||
|
||||
#ifdef EMSCRIPTEN
|
||||
static SDLApplication *currentApplication;
|
||||
static void EmscriptenUpdate ();
|
||||
#endif
|
||||
void RegisterWindow (SDLWindow *window);
|
||||
|
||||
private:
|
||||
|
||||
@@ -42,6 +40,9 @@ namespace lime {
|
||||
void ProcessTouchEvent (SDL_Event* event);
|
||||
void ProcessWindowEvent (SDL_Event* event);
|
||||
|
||||
static void UpdateFrame (void*);
|
||||
static SDLApplication* currentApplication;
|
||||
|
||||
bool active;
|
||||
Uint32 currentUpdate;
|
||||
double framePeriod;
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
#include "SDLWindow.h"
|
||||
#include "SDLApplication.h"
|
||||
|
||||
#ifdef HX_WINDOWS
|
||||
#include <SDL_syswm.h>
|
||||
@@ -35,6 +36,8 @@ namespace lime {
|
||||
|
||||
sdlWindow = SDL_CreateWindow (title, SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, width, height, sdlFlags);
|
||||
|
||||
((SDLApplication*)currentApplication)->RegisterWindow (this);
|
||||
|
||||
#ifdef HX_WINDOWS
|
||||
|
||||
HINSTANCE handle = ::GetModuleHandle (nullptr);
|
||||
|
||||
Reference in New Issue
Block a user