From 1c1889c726a93542e840c61dd4ac8da11bbcfbec Mon Sep 17 00:00:00 2001 From: Henrik Rydgard Date: Fri, 28 Sep 2012 10:01:01 +0200 Subject: [PATCH] WIP --- android/app-android.cpp | 3 +- android/native-audio-so.cpp | 3 +- .../com/turboviking/libnative/NativeApp.java | 7 ++-- base/PCMain.cpp | 4 ++ ext/stb_vorbis/stb_vorbis.c | 1 - image/png_load.cpp | 1 + ui/screen.cpp | 42 +++++++++++++++++-- ui/screen.h | 15 +++++-- 8 files changed, 63 insertions(+), 13 deletions(-) diff --git a/android/app-android.cpp b/android/app-android.cpp index 83d7461399..3e3482843e 100644 --- a/android/app-android.cpp +++ b/android/app-android.cpp @@ -88,7 +88,8 @@ std::string GetJavaString(JNIEnv *env, jstring jstr) return cpp_string; } -extern "C" jboolean Java_com_turboviking_libnative_NativeApp_isLandscape(JNIEnv *env, jclass) { +extern "C" jboolean Java_com_turboviking_libnative_NativeApp_isLandscape(JNIEnv *env, jclass) +{ std::string app_name, app_nice_name; bool landscape; NativeGetAppInfo(&app_name, &app_nice_name, &landscape); diff --git a/android/native-audio-so.cpp b/android/native-audio-so.cpp index d6bdb0772c..93748e3695 100644 --- a/android/native-audio-so.cpp +++ b/android/native-audio-so.cpp @@ -49,8 +49,7 @@ static void bqPlayerCallback(SLAndroidSimpleBufferQueueItf bq, void *context) { short *nextBuffer = buffer[curBuffer]; int nextSize = sizeof(buffer[0]); - SLresult result; - result = (*bqPlayerBufferQueue)->Enqueue(bqPlayerBufferQueue, nextBuffer, nextSize); + SLresult result = (*bqPlayerBufferQueue)->Enqueue(bqPlayerBufferQueue, nextBuffer, nextSize); // Comment from sample code: // the most likely other result is SL_RESULT_BUFFER_INSUFFICIENT, diff --git a/android/src/com/turboviking/libnative/NativeApp.java b/android/src/com/turboviking/libnative/NativeApp.java index 420739f406..ee403238b2 100644 --- a/android/src/com/turboviking/libnative/NativeApp.java +++ b/android/src/com/turboviking/libnative/NativeApp.java @@ -1,11 +1,12 @@ package com.turboviking.libnative; public class NativeApp { - public static native boolean isLandscape(); - public static native boolean isAtTopLevel(); public static native void init( int xxres, int yyres, int dpi, String apkPath, String dataDir, String externalDir, String libraryDir, String installID, boolean useOpenSL); + + public static native boolean isLandscape(); + public static native boolean isAtTopLevel(); // These have Android semantics: Resume is always called on bootup, after init public static native void pause(); @@ -24,4 +25,4 @@ public class NativeApp { public static native void accelerometer(float x, float y, float z); public static native void sendMessage(String msg, String arg); -} \ No newline at end of file +} \ No newline at end of file diff --git a/base/PCMain.cpp b/base/PCMain.cpp index 6c0610c4b8..99add6aecd 100644 --- a/base/PCMain.cpp +++ b/base/PCMain.cpp @@ -217,7 +217,11 @@ int main(int argc, char *argv[]) { } #endif +#ifdef _WIN32 + NativeInit(argc, (const char **)argv, path, "D:\\", "BADCOFFEE"); +#else NativeInit(argc, (const char **)argv, path, "/tmp", "BADCOFFEE"); +#endif float density = 1.0f; dp_xres = (float)pixel_xres * density / zoom; diff --git a/ext/stb_vorbis/stb_vorbis.c b/ext/stb_vorbis/stb_vorbis.c index 7b3c69ca6f..019438ccbd 100644 --- a/ext/stb_vorbis/stb_vorbis.c +++ b/ext/stb_vorbis/stb_vorbis.c @@ -2016,7 +2016,6 @@ void dct_iv_slow(float *buffer, int n) //acc += x[j] * cos(M_PI / n * (i + 0.5) * (j + 0.5)); buffer[i] = acc; } - free(x); } void inverse_mdct_slow(float *buffer, int n, vorb *f, int blocktype) diff --git a/image/png_load.cpp b/image/png_load.cpp index 6959ef03ff..7c14dd489e 100644 --- a/image/png_load.cpp +++ b/image/png_load.cpp @@ -1,3 +1,4 @@ +#define PNG_AVAILABLE #ifdef PNG_AVAILABLE #include #include diff --git a/ui/screen.cpp b/ui/screen.cpp index 548ae4fb58..dbfd63a4e9 100644 --- a/ui/screen.cpp +++ b/ui/screen.cpp @@ -8,8 +8,8 @@ Screen::Screen() { } Screen::~Screen() { } ScreenManager::ScreenManager() { - currentScreen_=0; - nextScreen_=0; + currentScreen_ = 0; + nextScreen_ = 0; } ScreenManager::~ScreenManager() { @@ -17,6 +17,13 @@ ScreenManager::~ScreenManager() { } void ScreenManager::switchScreen(Screen *screen) { + if (dialog_.size()) + { + WLOG("Switching screens - dropping the whole dialog stack"); + while (dialog_.size()) + pop(); + } + // TODO: is this still true? // Note that if a dialog is found, this will be a silent background switch that // will only become apparent if the dialog is closed. The previous screen will stick around // until that switch. @@ -35,12 +42,14 @@ void ScreenManager::update(const InputState &input) { } if (nextScreen_) { + ILOG("Screen switch!"); Screen *temp = currentScreen_; currentScreen_ = nextScreen_; delete temp; temp = 0; nextScreen_ = 0; } + if (currentScreen_) { currentScreen_->update(input); } @@ -59,6 +68,13 @@ void ScreenManager::render() { } } +Screen *ScreenManager::topScreen() { + if (dialog_.size()) + return dialog_.back(); + else + return currentScreen_; +} + void ScreenManager::shutdown() { if (nextScreen_) { delete nextScreen_; @@ -81,4 +97,24 @@ void ScreenManager::pop() { } else { ELOG("Can't push when no dialog is shown"); } -} \ No newline at end of file +} + +void ScreenManager::finishDialog(const Screen *dialog, DialogResult result) +{ + if (!dialog_.size()) { + ELOG("Must be in a dialog to finishDialog"); + return; + } + Screen *dlg = dialog_.back(); + if (dialog != dialog_.back()) + { + ELOG("Wrong dialog being finished!"); + return; + } + if (dialog_.size()) { + dialog_.pop_back(); + } + Screen *caller = topScreen(); + caller->dialogFinished(dialog, result); + delete dialog; +} diff --git a/ui/screen.h b/ui/screen.h index 57a92ca443..46189d9069 100644 --- a/ui/screen.h +++ b/ui/screen.h @@ -20,6 +20,13 @@ struct InputState; +enum DialogResult { + DR_OK, + DR_CANCEL, + DR_YES, + DR_NO, +}; + class Screen { public: Screen(); @@ -27,7 +34,7 @@ public: virtual void update(const InputState &input) = 0; virtual void render() {} - virtual void dialogFinished(const Screen &dialog) {} + virtual void dialogFinished(const Screen *dialog, DialogResult result) {} private: DISALLOW_COPY_AND_ASSIGN(Screen); }; @@ -51,9 +58,11 @@ public: void push(Screen *screen); // Pops the dialog away. - void pop(); - + void finishDialog(const Screen *dialog, DialogResult result = DR_OK); + private: + void pop(); + Screen *topScreen(); // Base screen. These don't "stack" and you can move in any order between them. Screen *currentScreen_; Screen *nextScreen_;