diff --git a/binding-mri/audio-binding.cpp b/binding-mri/audio-binding.cpp index 0c42f1f..1de027b 100644 --- a/binding-mri/audio-binding.cpp +++ b/binding-mri/audio-binding.cpp @@ -32,10 +32,7 @@ int volume = 100; \ int pitch = 100; \ double pos = 0.0; \ - if (rgssVer >= 3) \ - rb_get_args(argc, argv, "z|iif", &filename, &volume, &pitch, &pos RB_ARG_END); \ - else \ - rb_get_args(argc, argv, "z|ii", &filename, &volume, &pitch RB_ARG_END); \ + rb_get_args(argc, argv, "z|ii", &filename, &volume, &pitch RB_ARG_END); \ GUARD_EXC( shState->audio().entity##Play(filename, volume, pitch, pos); ) \ return Qnil; \ } \ diff --git a/binding-mri/binding-mri.cpp b/binding-mri/binding-mri.cpp index ca671fb..32a8c78 100644 --- a/binding-mri/binding-mri.cpp +++ b/binding-mri/binding-mri.cpp @@ -322,8 +322,7 @@ static void runCustomScript(const std::string &filename){ char msg[1024]; if (!readFileSDL(filename.c_str(), scriptData)){ - snprintf(msg, sizeof msg, "Unable to open %s", filename); - crash(msg, Exception::MEOW, false); + crash(Exception::MEOW, false, "Unable to open %s", filename); return; } @@ -337,16 +336,14 @@ struct BacktraceData{ BoostHash scriptNames; }; -#define SCRIPT_SECTION_FMT (rgssVer >= 3 ? "{%04ld}" : "Section%03ld") +#define SCRIPT_SECTION_FMT ("Section%03ld") static void runRMXPScripts(BacktraceData &btData){ const Config &conf = shState->rtData().config; const std::string &scriptPack = conf.game.scripts; - char msg[1024]; if (!shState->fileSystem().exists(scriptPack.c_str())){ - snprintf(msg, sizeof msg, "Unable to open '%s'", scriptPack.c_str()); - crash(msg, Exception::MEOW, false); + crash(Exception::MEOW, false, "Unable to open '%s'", scriptPack.c_str()); return; } @@ -357,13 +354,12 @@ static void runRMXPScripts(BacktraceData &btData){ try{ scriptArray = kernelLoadDataInt(scriptPack.c_str(), false); }catch (const Exception &e){ - snprintf(msg, sizeof msg, "Failed to read script data: %s", e.msg); - crash(msg, Exception::MEOW, false); + crash(Exception::MEOW, false, "Failed to read script data: %s", e.msg); return; } if (!RB_TYPE_P(scriptArray, RUBY_T_ARRAY)){ - crash("Failed to read script data", Exception::MEOW, false); + crash(Exception::MEOW, false, "Failed to read script data"); return; } @@ -406,8 +402,7 @@ static void runRMXPScripts(BacktraceData &btData){ if (result != Z_OK){ static char buffer[256]; - snprintf(buffer, sizeof(buffer), "Error decoding script %ld: '%s'\n", i, RSTRING_PTR(scriptName)); - crash(buffer, Exception::MEOW, false); + crash(Exception::MEOW, false, "Error decoding script %ld: '%s'\n", i, RSTRING_PTR(scriptName)); break; } @@ -504,9 +499,7 @@ static void showExc(VALUE exc, const BacktraceData &btData){ file.resize(strlen(file.c_str())); file = btData.scriptNames.value(file, file); - char ms[640]; - snprintf(&ms[0], 640, "Script '%s' line %s: %s occured.\n\n%s", file.c_str(), line, RSTRING_PTR(name), RSTRING_PTR(msg)); - crash(ms, Exception::MEOW, false); + crash(Exception::MEOW, false, "Script '%s' line %s: %s occured.\n\n%s", file.c_str(), line, RSTRING_PTR(name), RSTRING_PTR(msg)); exit(0); } @@ -517,7 +510,7 @@ static void mriBindingExecute(){ //JIT for performance int argc = 0; char **argv = 0; - char options_argv1[] = "oneshot", options_argv2[] = "-evd", options_argv3[] = "--jit"; + char options_argv1[] = "oneshot", options_argv2[] = "-ev", options_argv3[] = "--jit"; char* options_argv[] = {options_argv1, options_argv2, options_argv3, NULL}; ruby_sysinit(&argc, &argv); RUBY_INIT_STACK; diff --git a/binding-mri/binding-util.cpp b/binding-mri/binding-util.cpp index 91426a3..38a7d9e 100644 --- a/binding-mri/binding-util.cpp +++ b/binding-mri/binding-util.cpp @@ -48,7 +48,7 @@ RbData::RbData(){ exc[customExc[i].id] = rb_define_class(customExc[i].name, rb_eException); exc[RGSS] = rb_define_class("RGSSError", rb_eStandardError); - exc[Reset] = rb_define_class(rgssVer >= 3 ? "RGSSReset" : "Reset", rb_eException); + exc[Reset] = rb_define_class("Reset", rb_eException); exc[ErrnoENOENT] = rb_const_get(rb_const_get(rb_cObject, rb_intern("Errno")), rb_intern("ENOENT")); exc[IOError] = rb_eIOError; diff --git a/binding-mri/bitmap-binding.cpp b/binding-mri/bitmap-binding.cpp index fd4b0c9..40a245a 100644 --- a/binding-mri/bitmap-binding.cpp +++ b/binding-mri/bitmap-binding.cpp @@ -238,14 +238,7 @@ RB_METHOD(bitmapDrawText){ VALUE rectObj; Rect *rect; - if (rgssVer >= 2){ - VALUE strObj; - rb_get_args(argc, argv, "oo|i", &rectObj, &strObj, &align RB_ARG_END); - - str = objAsStringPtr(strObj); - }else{ - rb_get_args(argc, argv, "oz|i", &rectObj, &str, &align RB_ARG_END); - } + rb_get_args(argc, argv, "oz|i", &rectObj, &str, &align RB_ARG_END); rect = getPrivateDataCheck(rectObj, RectType); @@ -253,14 +246,7 @@ RB_METHOD(bitmapDrawText){ }else{ int x, y, width, height; - if (rgssVer >= 2){ - VALUE strObj; - rb_get_args(argc, argv, "iiiio|i", &x, &y, &width, &height, &strObj, &align RB_ARG_END); - - str = objAsStringPtr(strObj); - }else{ - rb_get_args(argc, argv, "iiiiz|i", &x, &y, &width, &height, &str, &align RB_ARG_END); - } + rb_get_args(argc, argv, "iiiiz|i", &x, &y, &width, &height, &str, &align RB_ARG_END); GUARD_EXC( b->drawText(x, y, width, height, str, align); ); } @@ -273,14 +259,7 @@ RB_METHOD(bitmapTextSize){ const char *str; - if (rgssVer >= 2){ - VALUE strObj; - rb_get_args(argc, argv, "o", &strObj RB_ARG_END); - - str = objAsStringPtr(strObj); - }else{ - rb_get_args(argc, argv, "z", &str RB_ARG_END); - } + rb_get_args(argc, argv, "z", &str RB_ARG_END); IntRect value; GUARD_EXC( value = b->textSize(str); ); @@ -303,8 +282,7 @@ RB_METHOD(bitmapGradientFillRect){ VALUE rectObj; Rect *rect; - rb_get_args(argc, argv, "ooo|b", &rectObj, - &color1Obj, &color2Obj, &vertical RB_ARG_END); + rb_get_args(argc, argv, "ooo|b", &rectObj, &color1Obj, &color2Obj, &vertical RB_ARG_END); rect = getPrivateDataCheck(rectObj, RectType); color1 = getPrivateDataCheck(color1Obj, ColorType); @@ -314,8 +292,7 @@ RB_METHOD(bitmapGradientFillRect){ }else{ int x, y, width, height; - rb_get_args(argc, argv, "iiiioo|b", &x, &y, &width, &height, - &color1Obj, &color2Obj, &vertical RB_ARG_END); + rb_get_args(argc, argv, "iiiioo|b", &x, &y, &width, &height, &color1Obj, &color2Obj, &vertical RB_ARG_END); color1 = getPrivateDataCheck(color1Obj, ColorType); color2 = getPrivateDataCheck(color2Obj, ColorType); diff --git a/binding-mri/font-binding.cpp b/binding-mri/font-binding.cpp index b6b8e00..eba13fa 100644 --- a/binding-mri/font-binding.cpp +++ b/binding-mri/font-binding.cpp @@ -93,9 +93,7 @@ RB_METHOD(fontInitialize){ f->initDynAttribs(); wrapProperty(self, &f->getColor(), "color", ColorType); - - if (rgssVer >= 3) - wrapProperty(self, &f->getOutColor(), "out_color", ColorType); + wrapProperty(self, &f->getOutColor(), "out_color", ColorType); return self; } @@ -115,9 +113,7 @@ RB_METHOD(fontInitializeCopy){ f->initDynAttribs(); wrapProperty(self, &f->getColor(), "color", ColorType); - - if (rgssVer >= 3) - wrapProperty(self, &f->getOutColor(), "out_color", ColorType); + wrapProperty(self, &f->getOutColor(), "out_color", ColorType); return self; } diff --git a/binding-mri/viewport-binding.cpp b/binding-mri/viewport-binding.cpp index b9e0d01..b720eff 100644 --- a/binding-mri/viewport-binding.cpp +++ b/binding-mri/viewport-binding.cpp @@ -32,7 +32,7 @@ DEF_TYPE(Viewport); RB_METHOD(viewportInitialize){ Viewport *v; - if (argc == 0 && rgssVer >= 3){ + if (argc == 0){ v = new Viewport(); } else if (argc == 1){ diff --git a/binding-mri/wallpaper-binding.cpp b/binding-mri/wallpaper-binding.cpp index bfc1848..9a49684 100644 --- a/binding-mri/wallpaper-binding.cpp +++ b/binding-mri/wallpaper-binding.cpp @@ -188,7 +188,8 @@ desktop = "kde_error"; } } else { - fallbackPath = std::string(getenv("HOME")) + "/Desktop/ONESHOT_hint.png"; + //not all linux enviroment show dekstop icons + need translation support + fallbackPath = std::string(getenv("HOME")) + "/ONESHOT_hint.png"; } } #endif diff --git a/binding-mri/window-binding.cpp b/binding-mri/window-binding.cpp index 0ea04ad..a8cf07e 100644 --- a/binding-mri/window-binding.cpp +++ b/binding-mri/window-binding.cpp @@ -27,9 +27,6 @@ DEF_TYPE(Window); RB_METHOD(windowInitialize){ - #ifdef DEBUG - printf("[windowInitialize] Creating window\n"); - #endif Window *w = viewportElementInitialize(argc, argv, self); setPrivateData(self, w); diff --git a/src/al-util.h b/src/al-util.h index 41a59db..385e6cb 100644 --- a/src/al-util.h +++ b/src/al-util.h @@ -177,8 +177,7 @@ inline uint8_t formatSampleSize(int sdlFormat){ case SDL_AUDIO_S16BE : return 2; default : - crash("Unhandled sample format", Exception::MEOW, false); - assert(!"Unhandled sample format"); + crash(Exception::MEOW, true, "Unhandled sample format"); } return 0; @@ -197,8 +196,7 @@ inline ALenum chooseALFormat(int sampleSize, int channelCount){ case 2 : return AL_FORMAT_STEREO16; } default : - crash("Unhandled sample size / channel count", Exception::MEOW, false); - assert(!"Unhandled sample size / channel count"); + crash(Exception::SDLError, true, "Unhandled sample size / channel count"); } return 0; diff --git a/src/alstream.cpp b/src/alstream.cpp index eea6f4d..6348b34 100644 --- a/src/alstream.cpp +++ b/src/alstream.cpp @@ -231,9 +231,7 @@ void ALStream::openSource(const std::string &filename){ needsRewind.clear(); if (!source){ - char buf[512]; - snprintf(buf, sizeof(buf), "Unable to decode audio stream: %s: %s", filename.c_str(), handler.errorMsg.c_str()); - crash(buf, Exception::MEOW, false); + crash(Exception::MEOW, false, "Unable to decode audio stream: %s: %s", filename.c_str(), handler.errorMsg.c_str()); } } diff --git a/src/audio.cpp b/src/audio.cpp index 2898a72..344f5d4 100644 --- a/src/audio.cpp +++ b/src/audio.cpp @@ -231,7 +231,6 @@ Audio::Audio(RGSSThreadData &rtData) : p(new AudioPrivate(rtData)) {} - void Audio::bgmPlay(const char *filename, int volume, int pitch, float pos){ p->current_bgm_volume = volume; p->bgm.play(filename, (volume*p->bgm_volume)/100, pitch, pos); @@ -245,7 +244,6 @@ void Audio::bgmFade(int time){ p->bgm.fadeOut(time); } - void Audio::bgsPlay(const char *filename, int volume, int pitch, float pos){ p->current_bgs_volume = volume; p->bgs.play(filename, (volume*p->sfx_volume)/100, pitch, pos); @@ -259,7 +257,6 @@ void Audio::bgsFade(int time){ p->bgs.fadeOut(time); } - void Audio::mePlay(const char *filename, int volume, int pitch){ p->current_me_volume = volume; p->me.play(filename, (volume*p->bgm_volume)/100, pitch); @@ -273,7 +270,6 @@ void Audio::meFade(int time){ p->me.fadeOut(time); } - void Audio::sePlay(const char *filename, int volume, int pitch){ p->se.play(filename, (volume*p->sfx_volume)/100, pitch); } diff --git a/src/bitmap.cpp b/src/bitmap.cpp index 32b7299..9fff340 100644 --- a/src/bitmap.cpp +++ b/src/bitmap.cpp @@ -48,7 +48,7 @@ #define GUARD_MEGA \ { \ if (p->megaSurface) \ - crash("Operation not supported for mega surfaces", Exception::MKXPError, true); \ + crash(Exception::MKXPError, true, "Operation not supported for mega surfaces"); \ } #define OUTLINE_SIZE 1 @@ -222,13 +222,11 @@ struct BitmapOpenHandler : FileSystem::OpenHandler{ Bitmap::Bitmap(const char *filename){ BitmapOpenHandler handler; - char msg[1024]; shState->fileSystem().openRead(handler, filename); SDL_Surface *imgSurf = handler.surf; if (!imgSurf){ - snprintf(msg, sizeof msg, "Error loading image '%s': %s", filename, SDL_GetError()); - throw Exception(Exception::SDLError, msg); + crash(Exception::SDLError, true, "Error loading image '%s': %s", filename, SDL_GetError()); } p->ensureFormat(imgSurf, SDL_PIXELFORMAT_ABGR8888); @@ -264,8 +262,7 @@ Bitmap::Bitmap(const char *filename){ Bitmap::Bitmap(int width, int height){ if (width <= 0 || height <= 0){ - //rash("failed to create bitmap"); - throw Exception(Exception::RGSSError, "failed to create bitmap"); + crash(Exception::RGSSError, true, "failed to create bitmap"); } TEXFBO tex = shState->texPool().request(width, height); @@ -1050,8 +1047,7 @@ void Bitmap::drawText(const IntRect &rect, const char *str, int align){ GLMeta::blitBegin(p->gl); GLMeta::blitSource(gpTF); - GLMeta::blitRectangle(IntRect(0, 0, txtSurf->w, txtSurf->h), - posRect, true); + GLMeta::blitRectangle(IntRect(0, 0, txtSurf->w, txtSurf->h), posRect, true); GLMeta::blitEnd(); } } diff --git a/src/config.cpp b/src/config.cpp index 42df465..91f701d 100644 --- a/src/config.cpp +++ b/src/config.cpp @@ -35,6 +35,8 @@ #include "util.h" #include "sdl-util.h" +#define CONF_FILE "oneshot.conf" + namespace std{ std::ostream& operator<<(std::ostream &os, const std::vector &vec){ for (auto item : vec){ @@ -61,8 +63,6 @@ std::set setFromVec(const std::vector &vec){ typedef std::vector StringVec; namespace po = boost::program_options; -#define CONF_FILE "oneshot.conf" - Config::Config() {} diff --git a/src/disposable.h b/src/disposable.h index ad63f03..5fa338f 100644 --- a/src/disposable.h +++ b/src/disposable.h @@ -26,13 +26,14 @@ #include "exception.h" #include "sharedstate.h" #include "graphics.h" +#include "meow.h" #include #include -// #include #include -// #include + + class Disposable{ public: @@ -65,7 +66,7 @@ public: protected: void guardDisposed() const{ if (isDisposed()) - throw Exception(Exception::RGSSError, "disposed %s", klassName()); + crash(Exception::RGSSError, true, "disposed %s", klassName()); } private: diff --git a/src/etc.cpp b/src/etc.cpp index ba62cfe..93ae6a7 100644 --- a/src/etc.cpp +++ b/src/etc.cpp @@ -24,9 +24,6 @@ #include "serial-util.h" #include "exception.h" #include "meow.h" - -// this file doesn't exist, idk what to do if it, so i'll comment it. -// #include #include Color::Color(double red, double green, double blue, double alpha) @@ -104,7 +101,7 @@ void Color::serialize(char *buffer) const{ Color *Color::deserialize(const char *data, int len){ if (len != 32) - crash("Color: Serialized data invalid", Exception::ArgumentError, true); + crash(Exception::ArgumentError, true, "Color: Serialized data invalid"); Color *c = new Color(); @@ -223,7 +220,7 @@ void Tone::serialize(char *buffer) const{ Tone *Tone::deserialize(const char *data, int len){ if (len != 32) - crash("Tone: Serialized data invalid", Exception::ArgumentError, true); + crash(Exception::ArgumentError, true, "Tone: Serialized data invalid"); Tone *t = new Tone(); @@ -354,7 +351,7 @@ void Rect::serialize(char *buffer) const{ Rect *Rect::deserialize(const char *data, int len){ if (len != 16) - crash("Rect: Serialized data invalid", Exception::ArgumentError, true); + crash(Exception::ArgumentError, true, "Rect: Serialized data invalid"); Rect *r = new Rect(); diff --git a/src/font.cpp b/src/font.cpp index 894bc5e..9e99651 100644 --- a/src/font.cpp +++ b/src/font.cpp @@ -128,7 +128,7 @@ TTF_Font *SharedFontState::getFont(std::string family, int size){ SDL_IOStream *ops; if (family.empty()){ - crash("font does not exist", Exception::RGSSError, true); + crash(Exception::RGSSError, true, "font does not exist"); }else{ /* Use 'other' path as alternative in case * we have no 'regular' styled font asset */ @@ -142,10 +142,8 @@ TTF_Font *SharedFontState::getFont(std::string family, int size){ font = TTF_OpenFontIO(ops, 1, size); - if (!font){ - snprintf(msg, sizeof msg, "%s", SDL_GetError()); - crash(msg, Exception::SDLError, true); - } + if (!font) + crash(Exception::SDLError, true, "%s", SDL_GetError()); p->pool.insert(key, font); return font; @@ -161,10 +159,7 @@ bool SharedFontState::fontPresent(std::string family) const{ return !(set.regular.empty() && set.other.empty()); } -void pickExistingFontName(const std::vector &names, - std::string &out, - const SharedFontState &sfs) -{ +void pickExistingFontName(const std::vector &names, std::string &out, const SharedFontState &sfs) { /* Note: In RMXP, a names array with no existing entry * results in no text being drawn at all (same for "" and []); * we can't replicate this in mkxp due to the default substitute. */ diff --git a/src/input.cpp b/src/input.cpp index 6a8bd3d..8c240f6 100644 --- a/src/input.cpp +++ b/src/input.cpp @@ -646,10 +646,8 @@ void Input::update(){ p->repeatCount++; bool repeated; - if (rgssVer >= 2) - repeated = p->repeatCount >= 23 && ((p->repeatCount+1) % 6) == 0; - else - repeated = p->repeatCount >= 15 && ((p->repeatCount+1) % 4) == 0; + + repeated = p->repeatCount >= 15 && ((p->repeatCount+1) % 4) == 0; p->getState(p->repeating).repeated |= repeated; diff --git a/src/main.cpp b/src/main.cpp index e999e1c..860330e 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -88,8 +88,7 @@ int rgssThreadFun(void *userdata){ glCtx = SDL_GL_CreateContext(win); if (!glCtx){ - SDL_snprintf(msg, sizeof msg, "Error creating context: %s", SDL_GetError()); - crash(msg, Exception::MEOW, false); + crash(Exception::MEOW, false, "Error creating context: %s", SDL_GetError()); rgssThreadError(threadData, std::string(msg)); return 0; } @@ -98,7 +97,7 @@ int rgssThreadFun(void *userdata){ initGLFunctions(); } catch (const Exception &exc){ - crash(exc.msg.c_str(), Exception::MEOW, false); + crash(Exception::MEOW, false, exc.msg.c_str()); rgssThreadError(threadData, exc.msg); SDL_GL_DestroyContext(glCtx); return 0; @@ -127,7 +126,7 @@ int rgssThreadFun(void *userdata){ ALCcontext *alcCtx = alcCreateContext(threadData->alcDev, 0); if (!alcCtx){ - crash("Error creating OpenAL context", Exception::MEOW, false); + crash(Exception::MEOW, false, "Error creating OpenAL context"); rgssThreadError(threadData, "Error creating OpenAL context"); SDL_GL_DestroyContext(glCtx); return 0; @@ -138,7 +137,7 @@ int rgssThreadFun(void *userdata){ try{ SharedState::initInstance(threadData); }catch (const Exception &exc){ - crash(exc.msg.c_str(), Exception::MEOW, false); + crash(Exception::MEOW, false, exc.msg.c_str()); rgssThreadError(threadData, exc.msg); alcDestroyContext(alcCtx); SDL_GL_DestroyContext(glCtx); @@ -190,7 +189,7 @@ static void setGamePathInRegistry() { long keyCreateError = RegCreateKeyEx(HKEY_CURRENT_USER, TEXT("Software\\OneShot\\"), 0L, NULL, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &key, NULL); if (keyCreateError != ERROR_SUCCESS){ - crash("Unable to create key in registry", Exception::MEOW, false); + crash(Exception::MEOW, false, "Unable to create key in registry"); } else { keyOpenError = ERROR_SUCCESS; @@ -198,12 +197,12 @@ static void setGamePathInRegistry() { } if (keyOpenError != ERROR_SUCCESS){ - crash("Unable to open registry.", Exception::MEOW, false); + crash(Exception::MEOW, false, "Unable to open registry."); } else { DWORD dataSize = (strlen(dataDir) + 1) * sizeof(char); if (RegSetValueEx(key, TEXT("GameDirectory"), 0, REG_SZ, (LPBYTE)dataDir, dataSize) != ERROR_SUCCESS){ - crash("Unable to set GameDirectory registry value", Exception::MEOW, false); + crash(Exception::MEOW, false, "Unable to set GameDirectory registry value"); } RegCloseKey(key); } @@ -230,20 +229,19 @@ int main(int argc, char *argv[]){ /* initialize SDL first */ if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_JOYSTICK | SDL_INIT_GAMEPAD) == false){ - SDL_snprintf(msg, sizeof msg, "Error initializing SDL: %s", SDL_GetError()); - crash(msg, Exception::MEOW, false); + crash(Exception::MEOW, false, "Error initializing SDL: %s", SDL_GetError()); return 0; } #ifdef STEAM if (!STEAMSHIM_init()){ - crash("Could not initialize Steamworks API", Exception::MEOW, false); + crash(Exception::MEOW, false, "Could not initialize Steamworks API"); return 0; } #endif if (!EventThread::allocUserEvents()){ - crash("Error allocating SDL user events", Exception::MEOW, false); + crash(Exception::MEOW, false, "Error allocating SDL user events"); return 0; } @@ -276,8 +274,7 @@ int main(int argc, char *argv[]){ if (!conf.gameFolder.empty()){ if (chdir(conf.gameFolder.c_str()) != 0){ - SDL_snprintf(msg, sizeof msg, "Unable to switch into gameFolder %s", conf.gameFolder); - crash(msg, Exception::MEOW, false); + crash(Exception::MEOW, false, "Unable to switch into gameFolder %s", conf.gameFolder); return 0; } } @@ -290,14 +287,12 @@ int main(int argc, char *argv[]){ conf.windowTitle = conf.game.title; if (TTF_Init() == false){ - SDL_snprintf(msg, sizeof msg, "Error initializing SDL_ttf: %s", SDL_GetError()); - crash(msg, Exception::MEOW, false); + crash(Exception::MEOW, false, "Error initializing SDL_ttf: %s", SDL_GetError()); SDL_Quit(); } if (Sound_Init() == false){ - SDL_snprintf(msg, sizeof msg, "Error initializing SDL_sound: %s", Sound_GetError()); - crash(msg, Exception::MEOW, false); + crash(Exception::MEOW, false, "Error initializing SDL_sound: %s", Sound_GetError()); TTF_Quit(); SDL_Quit(); @@ -316,8 +311,7 @@ int main(int argc, char *argv[]){ SDL_SetWindowFullscreen(win, true); if (!win){ - SDL_snprintf(msg, sizeof msg, "Error creating window: %s", SDL_GetError()); - crash(msg, Exception::MEOW, false); + crash(Exception::MEOW, false, "Error creating window: %s", SDL_GetError()); return 0; } @@ -333,7 +327,7 @@ int main(int argc, char *argv[]){ if (!alcDev){ SDL_DestroyWindow(win); - crash("Error opening OpenAL device", Exception::MEOW, false); + crash(Exception::MEOW, false, "Error opening OpenAL device"); TTF_Quit(); SDL_Quit(); @@ -390,7 +384,7 @@ int main(int argc, char *argv[]){ SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, conf.windowTitle.c_str(), "The RGSS script seems to be stuck and Sunshine will now force quit", win); if (!rtData.rgssErrorMsg.empty()) - crash(rtData.rgssErrorMsg.c_str(), Exception::MEOW, false); + crash(Exception::MEOW, false, rtData.rgssErrorMsg.c_str()); /* Clean up any remainin events */ eventThread.cleanup(); diff --git a/src/meow.cpp b/src/meow.cpp index cea695b..9b14158 100644 --- a/src/meow.cpp +++ b/src/meow.cpp @@ -17,12 +17,15 @@ #include #include #include -#include #include +#include #include #include #include #include +#include +#include +#include #ifdef __LINUX__ #include @@ -38,9 +41,23 @@ static inline const char* glGetStringInt(GLenum name){ return (const char*) gl.GetString(name); } -void crash(const char* reason, Exception::Type t, bool do_exp){ - char msg[1024]; - SDL_snprintf(msg, sizeof msg, "Error occured! Error message: %s\n\n Want to create a crash log? You can share the crash log with the developers and help resolve the issue.", reason); +void crash(Exception::Type t, bool do_exp, const char *fmt, ...){ + va_list ap; + va_start(ap, fmt); + va_list ap2; + va_copy(ap2, ap); + unsigned short len = vsnprintf(NULL, 0, fmt, ap2); + va_end(ap2); + + char *buf = (char*)malloc(len + 1); + if (!buf) + va_end(ap); + + vsnprintf(buf, len + 1, fmt, ap); + va_end(ap); + + char msg[256 + len]; + SDL_snprintf(msg, sizeof msg, "Error occured! Error message: %s\n\nWant to create a crash log? You can share the crash log with the developers and help resolve the issue.", buf); SDL_MessageBoxData messageboxdata = { .flags = SDL_MESSAGEBOX_ERROR, .window = NULL, @@ -54,7 +71,7 @@ void crash(const char* reason, Exception::Type t, bool do_exp){ int buttonid = 0; if (SDL_ShowMessageBox(&messageboxdata, &buttonid) == false) { - printf("[CRASHDUMP] %s\n", reason); + printf("[CRASHDUMP] %s\n", buf); } if(buttonid == 1){ @@ -110,3 +127,7 @@ void crash(const char* reason, Exception::Type t, bool do_exp){ throw Exception(t, msg); } } + +void ShowError(const char* m){ + SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "Sunshine Error", m, NULL); +} diff --git a/src/meow.h b/src/meow.h index 897e512..2178efd 100644 --- a/src/meow.h +++ b/src/meow.h @@ -1,2 +1,3 @@ #include "exception.h" -void crash(const char* reason, Exception::Type t, bool do_exp); +void crash(Exception::Type t, bool do_exp, const char *fmt, ...); +void ShowError(const char* m); diff --git a/src/scene.cpp b/src/scene.cpp index 90cd03e..a1b61aa 100644 --- a/src/scene.cpp +++ b/src/scene.cpp @@ -148,14 +148,6 @@ bool SceneElement::operator<(const SceneElement &o) const{ if (z <= o.z){ if (z == o.z){ - if (rgssVer >= 2){ - /* RGSS2: If two sprites' Z values collide, - * their Y coordinates decide draw order. Only - * on equal Y does the creation time take effect */ - if (spriteY != o.spriteY) - return (spriteY < o.spriteY); - } - return (creationStamp < o.creationStamp); } diff --git a/src/screen.cpp b/src/screen.cpp index 6c8d959..4e1e125 100644 --- a/src/screen.cpp +++ b/src/screen.cpp @@ -34,8 +34,7 @@ int screenMain(Config &conf){ win = SDL_CreateWindow("The Journal", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, SDL_WINDOW_RESIZABLE | SDL_WINDOW_TRANSPARENT); if (!win){ - snprintf(msg, sizeof msg, "Error creating window: %s", SDL_GetError()); - crash(msg, Exception::MEOW, false); + crash(Exception::MEOW, false, "Error creating window: %s", SDL_GetError()); return 0; } diff --git a/src/sdlsoundsource.cpp b/src/sdlsoundsource.cpp index 28c6eba..cc228d9 100644 --- a/src/sdlsoundsource.cpp +++ b/src/sdlsoundsource.cpp @@ -45,9 +45,8 @@ struct SDLSoundSource : ALDataSource{ sample = Sound_NewSample(&srcOps, extension, 0, maxBufSize); if (!sample){ - SDL_CloseIO(&ops); - snprintf(msg, sizeof msg, "SDL_sound: %s", Sound_GetError()); - crash(msg, Exception::SDLError, true); + SDL_CloseIO(&ops); + crash(Exception::SDLError, true, "SDL_sound: %s", Sound_GetError()); } sampleSize = formatSampleSize(sample->actual.format); diff --git a/src/shader.cpp b/src/shader.cpp index 177ef64..6a4f2ea 100644 --- a/src/shader.cpp +++ b/src/shader.cpp @@ -152,8 +152,7 @@ void Shader::init(const unsigned char *vert, int vertSize, const unsigned char * if (!success){ printShaderLog(vertShader); - snprintf(msg, sizeof msg, "GLSL: An error occured while compiling vertex shader '%s' in program '%s'", vertName, programName); - crash(msg, Exception::MKXPError ,true); + crash(Exception::MKXPError , true, "GLSL: An error occured while compiling vertex shader '%s' in program '%s'", vertName, programName); } /* Compile fragment shader */ @@ -164,8 +163,7 @@ void Shader::init(const unsigned char *vert, int vertSize, const unsigned char * if (!success){ printShaderLog(fragShader); - snprintf(msg, sizeof msg, "GLSL: An error occured while compiling fragment shader '%s' in program '%s'", fragName, programName); - crash(msg, Exception::MKXPError, true); + crash(Exception::MKXPError, true, "GLSL: An error occured while compiling fragment shader '%s' in program '%s'", fragName, programName); } /* Link shader program */ @@ -182,8 +180,7 @@ void Shader::init(const unsigned char *vert, int vertSize, const unsigned char * if (!success){ printProgramLog(program); - snprintf(msg, sizeof msg, "GLSL: An error occured while linking program '%s' (vertex '%s', fragment '%s')", programName, vertName, fragName); - crash(msg, Exception::MKXPError, true); + crash(Exception::MKXPError, true, "GLSL: An error occured while linking program '%s' (vertex '%s', fragment '%s')", programName, vertName, fragName); } } @@ -378,7 +375,6 @@ void SimpleTransShader::setProg(float value){ gl.Uniform1f(u_prog, value); } - void SpriteShaderBase::SpriteShaderInit(){ ShaderBase::init(); @@ -465,7 +461,6 @@ void PlaneShader::setOpacity(float value){ gl.Uniform1f(u_opacity, value); } - GrayShader::GrayShader(){ INIT_SHADER(simple, gray, GrayShader); @@ -478,7 +473,6 @@ void GrayShader::setGray(float value){ gl.Uniform1f(u_gray, value); } - TilemapShader::TilemapShader(){ INIT_SHADER(tilemap, simple, TilemapShader); @@ -491,7 +485,6 @@ void TilemapShader::setAniIndex(int value){ gl.Uniform1f(u_aniIndex, value); } - TilemapWaterShader::TilemapWaterShader(){ INIT_SHADER(tilemap, tilemapWater, TilemapWaterShader); @@ -509,8 +502,6 @@ void TilemapWaterShader::setOffset(const Vec2i &value){ gl.Uniform2f(u_offset, value.x, value.y); } - - FlashMapShader::FlashMapShader(){ INIT_SHADER(simpleColor, flashMap, FlashMapShader); diff --git a/src/soundemitter.cpp b/src/soundemitter.cpp index f46a802..29df061 100644 --- a/src/soundemitter.cpp +++ b/src/soundemitter.cpp @@ -206,7 +206,6 @@ struct SoundOpenHandler : FileSystem::OpenHandler{ }; SoundBuffer *SoundEmitter::allocateBuffer(const std::string &filename){ - char msg[512]; SoundBuffer *buffer = bufferHash.value(filename, 0); if (buffer){ @@ -224,8 +223,7 @@ SoundBuffer *SoundEmitter::allocateBuffer(const std::string &filename){ if (!buffer){ char buf[512]; - snprintf(buf, sizeof(buf), "Unable to decode sound: %s: %s", filename.c_str(), Sound_GetError()); - crash(msg, Exception::MEOW, false); + crash(Exception::MEOW, false, "Unable to decode sound: %s: %s", filename.c_str(), Sound_GetError()); return 0; } diff --git a/src/sprite.cpp b/src/sprite.cpp index d3cd7f2..7e345a4 100644 --- a/src/sprite.cpp +++ b/src/sprite.cpp @@ -360,11 +360,6 @@ void Sprite::setY(int value){ return; p->trans.setPosition(Vec2(getX(), value)); - - if (rgssVer >= 2){ - p->wave.dirty = true; - setSpriteY(value); - } } void Sprite::setOX(int value){ @@ -402,9 +397,6 @@ void Sprite::setZoomY(float value){ p->trans.setScale(Vec2(getZoomX(), value)); p->recomputeBushDepth(); - - if (rgssVer >= 2) - p->wave.dirty = true; } void Sprite::setAngle(float value){ @@ -628,4 +620,4 @@ void Sprite::defaultSpriteShaderInit(SpriteShaderBase &shader){ shader.setColor(*blend); shader.setModulate(p->modulate->norm); -} \ No newline at end of file +} diff --git a/src/table.cpp b/src/table.cpp index 9f1e6c9..908f249 100644 --- a/src/table.cpp +++ b/src/table.cpp @@ -114,7 +114,7 @@ void Table::serialize(char *buffer) const{ Table *Table::deserialize(const char *data, int len){ if (len < 20) - crash("Marshal: Table: bad file format", Exception::RGSSError, true); + crash(Exception::RGSSError, true, "Marshal: Table: bad file format"); readInt32(&data); int x = readInt32(&data); @@ -123,10 +123,10 @@ Table *Table::deserialize(const char *data, int len){ int size = readInt32(&data); if (size != x*y*z) - crash("Marshal: Table: bad file format", Exception::RGSSError, true); + crash(Exception::RGSSError, true, "Marshal: Table: bad file format"); if (len != 20 + x*y*z*2) - crash("Marshal: Table: bad file format", Exception::RGSSError, true); + crash(Exception::RGSSError, true, "Marshal: Table: bad file format"); Table *t = new Table(x, y, z); memcpy(dataPtr(t->data), data, sizeof(int16_t)*size); diff --git a/src/texpool.cpp b/src/texpool.cpp index e4f9ea9..137a3f8 100644 --- a/src/texpool.cpp +++ b/src/texpool.cpp @@ -97,7 +97,6 @@ TexPool::~TexPool(){ TEXFBO TexPool::request(int width, int height){ CacheNode cnode; Size size(width, height); - char msg[512]; /* See if we can statisfy request from cache */ CNodeList &bucket = p->poolHash[size]; @@ -118,8 +117,7 @@ TEXFBO TexPool::request(int width, int height){ int maxSize = glState.caps.maxTexSize; if (width > maxSize || height > maxSize){ - snprintf(msg, sizeof msg, "Texture dimensions [%d, %d] exceed hardware capabilities", width, height); - crash(msg, Exception::MKXPError, true); + crash(Exception::MKXPError, true, "Texture dimensions [%d, %d] exceed hardware capabilities", width, height); } /* Nope, create it instead */ diff --git a/src/tilemap.cpp b/src/tilemap.cpp index 6d56430..47c949e 100644 --- a/src/tilemap.cpp +++ b/src/tilemap.cpp @@ -357,8 +357,7 @@ struct TilemapPrivate { for (size_t i = 0; i < zlayersMax; ++i) elem.zlayers[i] = new ZLayer(this, viewport); - prepareCon = shState->prepareDraw.connect - (sigc::mem_fun(this, &TilemapPrivate::prepare)); + prepareCon = shState->prepareDraw.connect(sigc::mem_fun(this, &TilemapPrivate::prepare)); updateFlashMapViewport(); } @@ -403,7 +402,7 @@ struct TilemapPrivate { atlas.size = TileAtlas::minSize(atlas.efTilesetH, glState.caps.maxTexSize); if (atlas.size.x < 0) - throw Exception(Exception::MKXPError, "Cannot allocate big enough texture for tileset atlas"); + crash(Exception::MKXPError, true, "Cannot allocate big enough texture for tileset atlas"); } void updateAutotileInfo(){ @@ -499,13 +498,11 @@ struct TilemapPrivate { if (blitW <= autotileW && tiles.animated){ /* Static autotile */ for (int j = 0; j < 4; ++j) - GLMeta::blitRectangle(IntRect(0, 0, blitW, blitH), - Vec2i(autotileW*j, atInd*autotileH)); + GLMeta::blitRectangle(IntRect(0, 0, blitW, blitH), Vec2i(autotileW*j, atInd*autotileH)); } else{ /* Animated autotile */ - GLMeta::blitRectangle(IntRect(0, 0, blitW, blitH), - Vec2i(0, atInd*autotileH)); + GLMeta::blitRectangle(IntRect(0, 0, blitW, blitH), Vec2i(0, atInd*autotileH)); } } @@ -535,8 +532,7 @@ struct TilemapPrivate { Vec2i texSize; shState->ensureTexSize(tsLaneW, blitOp.h, texSize); shState->bindTex(); - GLMeta::subRectImageUpload(tsSurf->w, blitOp.src.x, blitOp.src.y, - 0, 0, tsLaneW, blitOp.h, tsSurf, GL_RGBA); + GLMeta::subRectImageUpload(tsSurf->w, blitOp.src.x, blitOp.src.y, 0, 0, tsLaneW, blitOp.h, tsSurf, GL_RGBA); shader.setTexSize(texSize); quad.setTexRect(FloatRect(0, 0, tsLaneW, blitOp.h)); @@ -556,8 +552,7 @@ struct TilemapPrivate { for (size_t i = 0; i < blits.size(); ++i){ const TileAtlas::Blit &blitOp = blits[i]; - GLMeta::subRectImageUpload(tsSurf->w, blitOp.src.x, blitOp.src.y, - blitOp.dst.x, blitOp.dst.y, tsLaneW, blitOp.h, tsSurf, GL_RGBA); + GLMeta::subRectImageUpload(tsSurf->w, blitOp.src.x, blitOp.src.y, blitOp.dst.x, blitOp.dst.y, tsLaneW, blitOp.h, tsSurf, GL_RGBA); } GLMeta::subRectImageEnd(); @@ -572,8 +567,7 @@ struct TilemapPrivate { for (size_t i = 0; i < blits.size(); ++i){ const TileAtlas::Blit &blitOp = blits[i]; - GLMeta::blitRectangle(IntRect(blitOp.src.x, blitOp.src.y, tsLaneW, blitOp.h), - blitOp.dst); + GLMeta::blitRectangle(IntRect(blitOp.src.x, blitOp.src.y, tsLaneW, blitOp.h), blitOp.dst); } GLMeta::blitEnd(); @@ -1118,8 +1112,7 @@ void Tilemap::setMapData(Table *value){ p->invalidateBuffers(); p->mapDataCon.disconnect(); - p->mapDataCon = value->modified.connect - (sigc::mem_fun(p, &TilemapPrivate::invalidateBuffers)); + p->mapDataCon = value->modified.connect(sigc::mem_fun(p, &TilemapPrivate::invalidateBuffers)); } void Tilemap::setFlashData(Table *value){ @@ -1141,8 +1134,7 @@ void Tilemap::setPriorities(Table *value){ p->invalidateBuffers(); p->prioritiesCon.disconnect(); - p->prioritiesCon = value->modified.connect - (sigc::mem_fun(p, &TilemapPrivate::invalidateBuffers)); + p->prioritiesCon = value->modified.connect(sigc::mem_fun(p, &TilemapPrivate::invalidateBuffers)); } void Tilemap::setVisible(bool value){ diff --git a/src/tilequad.h b/src/tilequad.h index da40ae4..b35b7d2 100644 --- a/src/tilequad.h +++ b/src/tilequad.h @@ -35,23 +35,15 @@ namespace TileQuads{ /* Calculate needed quad counts */ - int oneDimCount(int tileDimension, - int destDimension); - int twoDimCount(int tileW, int tileH, - int destW, int destH); + int oneDimCount(int tileDimension, int destDimension); + int twoDimCount(int tileW, int tileH, int destW, int destH); /* Build tiling quads */ - int buildH(const IntRect &sourceRect, - int width, int x, int y, - Vertex *verts); + int buildH(const IntRect &sourceRect, int width, int x, int y, Vertex *verts); - int buildV(const IntRect &sourceRect, - int height, int ox, int oy, - Vertex *verts); + int buildV(const IntRect &sourceRect, int height, int ox, int oy, Vertex *verts); - int build(const IntRect &sourceRect, - const IntRect &destRect, - Vertex *verts); + int build(const IntRect &sourceRect, const IntRect &destRect, Vertex *verts); /* Build a quad "frame" (see Window cursor_rect) */ int buildFrame(const IntRect &rect, Vertex vert[36]); diff --git a/src/vorbissource.cpp b/src/vorbissource.cpp index 59af03b..a603e65 100644 --- a/src/vorbissource.cpp +++ b/src/vorbissource.cpp @@ -80,7 +80,7 @@ struct VorbisSource : ALDataSource{ if (error){ SDL_CloseIO(&src); - crash("Vorbisfile: Cannot read ogg file", Exception::MKXPError, true); + crash(Exception::MKXPError, true, "Vorbisfile: Cannot read ogg file"); } /* Extract bitstream info */ @@ -90,7 +90,7 @@ struct VorbisSource : ALDataSource{ if (info.channels > 2){ ov_clear(&vf); SDL_CloseIO(&src); - crash("Cannot handle audio with more than 2 channels", Exception::MKXPError, true); + crash(Exception::MKXPError, true, "Cannot handle audio with more than 2 channels"); } info.alFormat = chooseALFormat(sizeof(int16_t), info.channels);