Emscripten playground #417

Merged
merged 13 commits into from Feb 21, 2015
View
@@ -23,8 +23,12 @@
AudioInterface& Audio() {
static EmptyAudio default_;
+#ifdef SUPPORT_AUDIO
if (Player::no_audio_flag || !DisplayUi) {
return default_;
}
return DisplayUi->GetAudio();
+#else
+ return default_;
+#endif
}
View
@@ -134,6 +134,11 @@ void Graphics::Update() {
}
void Graphics::InternUpdate1(bool reset) {
+#ifdef EMSCRIPTEN
+ // FIXME: Graphics code doesn't play well with Emscripten (only 1 FPS)
+ DrawFrame();
+ framecount++;
+#else
// FIXME: This method needs more comments.
static const double framerate_interval = 1000.0 / framerate;
static uint32_t current_time = 0;
@@ -182,6 +187,7 @@ void Graphics::InternUpdate1(bool reset) {
DisplayUi->Sleep((uint32_t)(framerate_interval - (current_time - last_time)));
}
}
+#endif
}
void Graphics::InternUpdate2(bool reset) {
@@ -351,10 +357,13 @@ void Graphics::Transition(TransitionType type, int duration, bool erase) {
screen1 = screen2;
}
+#ifndef EMSCRIPTEN
+ // Fixme: Refactor how transitions work, they should return to the main loop
for (int i = 1; i <= transition_duration; i++) {
Player::Update();
InternUpdate1();
}
+#endif
}
if (!erase) frozen_screen = BitmapRef();
View
@@ -188,6 +188,7 @@ void Output::ErrorStr(std::string const& err) {
if (!recursive_call && DisplayUi) {
recursive_call = true;
HandleErrorOutput(err);
+ DisplayUi.reset();
} else {
// Fallback to Console if the display is not ready yet
std::cout << err << std::endl;
View
@@ -107,6 +107,12 @@ void Player::Init(int argc, char *argv[]) {
InitMiniDumpWriter();
#endif
+#ifdef EMSCRIPTEN
+ Output::IgnorePause(true);
+
+ emscripten_set_canvas_size(SCREEN_TARGET_WIDTH * 2, SCREEN_TARGET_HEIGHT * 2);
+#endif
+
srand(time(NULL));
ParseCommandLine(argc, argv);
@@ -149,8 +155,6 @@ void Player::Run() {
while (Scene::instance->type != Scene::Null)
Player::MainLoop();
#endif
-
- Player::Exit();
}
void Player::MainLoop() {
@@ -159,6 +163,10 @@ void Player::MainLoop() {
Graphics::Pop();
}
Scene::old_instances.clear();
+
+ if (Scene::instance->type == Scene::Null) {
+ Player::Exit();
+ }
}
void Player::Pause() {
View
@@ -63,44 +63,54 @@ Scene::Scene() {
}
void Scene::MainFunction() {
- switch(push_pop_operation) {
- case ScenePushed:
- Start();
- break;
- case ScenePopped:
- Continue();
- break;
- default:;
- }
+ static bool init = false;
+
+ if (!init) {
+ // Initialization after scene switch
+ switch (push_pop_operation) {
+ case ScenePushed:
+ Start();
+ break;
+ case ScenePopped:
+ Continue();
+ break;
+ default:;
+ }
- push_pop_operation = 0;
+ push_pop_operation = 0;
- TransitionIn();
- Resume();
+ TransitionIn();
+ Resume();
- // Scene loop
- while (Scene::instance.get() == this) {
- Player::Update();
- Graphics::Update();
- Audio().Update();
- Input::Update();
- Update();
+ init = true;
}
- assert(Scene::instance == instances.back() &&
- "Don't set Scene::instance directly, use Push instead!");
-
+ // Update scene
+ Player::Update();
Graphics::Update();
+ Audio().Update();
+ Input::Update();
+ Update();
+
+ if (Scene::instance.get() != this) {
+ // Shutdown after scene switch
+ assert(Scene::instance == instances.back() &&
+ "Don't set Scene::instance directly, use Push instead!");
- Suspend();
- TransitionOut();
+ Graphics::Update();
+
+ Suspend();
+ TransitionOut();
+
+ switch (push_pop_operation) {
+ case ScenePushed:
+ Graphics::Push();
+ break;
+ // Graphics::Pop done in Player Loop
+ default:;
+ }
- switch (push_pop_operation) {
- case ScenePushed:
- Graphics::Push();
- break;
- // Graphics::Pop done in Player Loop
- default:;
+ init = false;
}
}
View
@@ -84,7 +84,12 @@ SdlUi::SdlUi(long width, long height, const std::string& title, bool fs_flag) :
SYS_SetResetCallback(GekkoResetCallback);
#endif
- uint32_t flags = SDL_INIT_VIDEO | SDL_INIT_TIMER;
+ uint32_t flags = SDL_INIT_VIDEO;
+
+#ifndef EMSCRIPTEN
+ flags |= SDL_INIT_TIMER;
+#endif
+
#if (!defined(NDEBUG) || defined(_WIN32))
flags |= SDL_INIT_NOPARACHUTE;
#endif
@@ -294,7 +299,14 @@ bool SdlUi::RequestVideoMode(int width, int height, bool fullscreen) {
current_display_mode.flags |= SDL_WINDOW_FULLSCREEN_DESKTOP;
}
toggle_fs_available = true;
+
+#ifdef SUPPORT_ZOOM
current_display_mode.zoom = true;
+ zoom_available = true;
+#else
+ current_display_mode.zoom = false;
+ zoom_available = false;
+#endif
return true;
#endif
View
@@ -65,13 +65,17 @@
#ifdef USE_SDL
# define USE_SDL_MIXER
-
# ifdef PSP
-# undef SUPPORT_AUDIO
# undef USE_SDL_MIXER
+# define NO_SDL_MIXER
+# endif
+
+# ifdef EMSCRIPTEN
+# undef USE_SDL_MIXER
+# define NO_SDL_MIXER
# endif
-# if defined(GEKKO) || defined(OPENDINGUX)
+# if defined(GEKKO) || defined(OPENDINGUX) || defined(EMSCRIPTEN)
# undef SUPPORT_ZOOM
# endif