From e59ac9f3390cb3d7389d7a8878dc575ca539a1f3 Mon Sep 17 00:00:00 2001 From: DepressedTWM Date: Tue, 19 May 2026 13:18:04 +0400 Subject: [PATCH] Memory usage optimization --- src/alstream.cpp | 1 + src/audio.cpp | 22 +++++++++++----------- src/audio.h | 18 ++++-------------- src/audiostream.cpp | 7 +++---- src/bitmap.cpp | 4 +--- src/config.cpp | 4 ++-- src/config.h | 4 ++-- src/disposable.h | 3 +-- src/etc.cpp | 2 +- src/etc.h | 2 +- 10 files changed, 27 insertions(+), 40 deletions(-) diff --git a/src/alstream.cpp b/src/alstream.cpp index 47b4399..c1054a7 100644 --- a/src/alstream.cpp +++ b/src/alstream.cpp @@ -426,3 +426,4 @@ void ALStream::streamData(){ SDL_Delay(AUDIO_SLEEP); } } + diff --git a/src/audio.cpp b/src/audio.cpp index 65ba959..2215a6d 100644 --- a/src/audio.cpp +++ b/src/audio.cpp @@ -33,16 +33,16 @@ #include struct AudioPrivate{ - int bgm_volume; - int sfx_volume; + unsigned char bgm_volume; + unsigned char sfx_volume; AudioStream bgm; AudioStream bgs; AudioStream me; - int current_bgm_volume; - int current_bgs_volume; - int current_me_volume; + unsigned char current_bgm_volume; + unsigned char current_bgs_volume; + unsigned char current_me_volume; SoundEmitter se; @@ -232,7 +232,7 @@ Audio::Audio(RGSSThreadData &rtData) {} -void Audio::bgmPlay(const char *filename, int volume, int pitch, float pos){ +void Audio::bgmPlay(const char *filename, short volume, short pitch, float pos){ p->current_bgm_volume = volume; p->bgm.play(filename, (volume*p->bgm_volume)/100, pitch, pos); } @@ -246,7 +246,7 @@ void Audio::bgmFade(int time){ } -void Audio::bgsPlay(const char *filename, int volume, int pitch, float pos){ +void Audio::bgsPlay(const char *filename, short volume, short pitch, float pos){ p->current_bgs_volume = volume; p->bgs.play(filename, (volume*p->sfx_volume)/100, pitch, pos); } @@ -260,7 +260,7 @@ void Audio::bgsFade(int time){ } -void Audio::mePlay(const char *filename, int volume, int pitch){ +void Audio::mePlay(const char *filename, short volume, short pitch){ p->current_me_volume = volume; p->me.play(filename, (volume*p->bgm_volume)/100, pitch); } @@ -274,7 +274,7 @@ void Audio::meFade(int time){ } -void Audio::sePlay(const char *filename, int volume, int pitch){ +void Audio::sePlay(const char *filename, short volume, short pitch){ p->se.play(filename, (volume*p->sfx_volume)/100, pitch); } @@ -301,7 +301,7 @@ int Audio::getBGM_Volume() const{ return p->bgm_volume; } -void Audio::setBGM_Volume(int value){ +void Audio::setBGM_Volume(short value){ if(value > 100){ value = 100; }else if(value < 0){ @@ -320,7 +320,7 @@ int Audio::getSFX_Volume() const{ return p->sfx_volume; } -void Audio::setSFX_Volume(int value){ +void Audio::setSFX_Volume(short value){ if(value > 100){ value = 100; }else if(value < 0){ diff --git a/src/audio.h b/src/audio.h index 5412d21..96c2bde 100644 --- a/src/audio.h +++ b/src/audio.h @@ -39,29 +39,19 @@ struct RGSSThreadData; class Audio{ public: - void bgmPlay(const char *filename, - int volume = 100, - int pitch = 100, - float pos = 0); + void bgmPlay(const char *filename, short volume = 100, short pitch = 100, float pos = 0); void bgmStop(); void bgmFade(int time); - void bgsPlay(const char *filename, - int volume = 100, - int pitch = 100, - float pos = 0); + void bgsPlay(const char *filename, short volume = 100, short pitch = 100, float pos = 0); void bgsStop(); void bgsFade(int time); - void mePlay(const char *filename, - int volume = 100, - int pitch = 100); + void mePlay(const char *filename, short volume = 100, short pitch = 100); void meStop(); void meFade(int time); - void sePlay(const char *filename, - int volume = 100, - int pitch = 100); + void sePlay(const char *filename, short volume = 100, short pitch = 100); void seStop(); float bgmPos(); diff --git a/src/audiostream.cpp b/src/audiostream.cpp index 3d0d617..e1f8f97 100644 --- a/src/audiostream.cpp +++ b/src/audiostream.cpp @@ -70,7 +70,7 @@ AudioStream::~AudioStream(){ SDL_DestroyMutex(streamMut); } -void AudioStream::play(const std::string &filename, int volume, int pitch, float offset){ +void AudioStream::play(const std::string &filename, int volume, int pitch, float offset) { finiFadeOutInt(); lockStream(); @@ -134,7 +134,7 @@ void AudioStream::play(const std::string &filename, int volume, int pitch, float stream.setPitch(_pitch); if (offset > 0){ - setVolume(FadeIn, 0); +0 setVolume(FadeIn, 0); startFadeIn(); } @@ -279,8 +279,7 @@ void AudioStream::fadeOutThread(){ if (state != ALStream::Playing || resVol < 0 - || fade.reqFini) - { + || fade.reqFini){ if (state != ALStream::Paused) stream.stop(); diff --git a/src/bitmap.cpp b/src/bitmap.cpp index 87c3ef8..a43317a 100644 --- a/src/bitmap.cpp +++ b/src/bitmap.cpp @@ -1069,9 +1069,7 @@ void Bitmap::drawText(const IntRect &rect, const char *str, int align){ GLMeta::blitRectangle(posRect, Vec2i()); GLMeta::blitEnd(); - FloatRect bltRect(0, 0, - (float) (gpTexSize.x * squeeze) / gpTex2.width, - (float) gpTexSize.y / gpTex2.height); + FloatRect bltRect(0, 0, (float) (gpTexSize.x * squeeze) / gpTex2.width, (float) gpTexSize.y / gpTex2.height); BltShader &shader = shState->shaders().blt; shader.bind(); diff --git a/src/config.cpp b/src/config.cpp index aa90d62..d85963a 100644 --- a/src/config.cpp +++ b/src/config.cpp @@ -66,7 +66,7 @@ namespace po = boost::program_options; Config::Config() {} -void Config::read(int argc, char *argv[]){ +void Config::read(short argc, char *argv[]){ #define PO_DESC_ALL \ PO_DESC(debugMode, bool, false) \ PO_DESC(screenMode, bool, false) \ @@ -179,7 +179,7 @@ void Config::read(int argc, char *argv[]){ defScreenW = 640; defScreenH = 480; } - + #ifdef STEAM /* Override fullscreen config if Big Picture */ if (const char *env = std::getenv("SteamTenfoot")){ diff --git a/src/config.h b/src/config.h index b27891a..230ad8c 100644 --- a/src/config.h +++ b/src/config.h @@ -27,7 +27,7 @@ #include struct Config{ - int rgssVersion; + unsigned char rgssVersion; bool debugMode; bool screenMode; @@ -89,7 +89,7 @@ struct Config{ Config(); - void read(int argc, char *argv[]); + void read(short argc, char *argv[]); }; #endif // CONFIG_H diff --git a/src/disposable.h b/src/disposable.h index 50d43ac..ad63f03 100644 --- a/src/disposable.h +++ b/src/disposable.h @@ -65,8 +65,7 @@ public: protected: void guardDisposed() const{ if (isDisposed()) - throw Exception(Exception::RGSSError, - "disposed %s", klassName()); + throw Exception(Exception::RGSSError, "disposed %s", klassName()); } private: diff --git a/src/etc.cpp b/src/etc.cpp index b0e4f93..647f2b1 100644 --- a/src/etc.cpp +++ b/src/etc.cpp @@ -101,7 +101,7 @@ void Color::serialize(char *buffer) const{ writeDouble(&buffer, alpha); } -Color *Color::deserialize(const char *data, int len){ +Color *Color::deserialize(const char *data, short len){ if (len != 32) throw Exception(Exception::ArgumentError, "Color: Serialized data invalid"); diff --git a/src/etc.h b/src/etc.h index fc769cd..b17c57c 100644 --- a/src/etc.h +++ b/src/etc.h @@ -66,7 +66,7 @@ struct Color : public Serializable{ /* Serializable */ int serialSize() const; void serialize(char *buffer) const; - static Color *deserialize(const char *data, int len); + static Color *deserialize(const char *data, short len); /* Internal */ void updateInternal();