Memory usage optimization

This commit is contained in:
DepressedTWM 2026-05-19 13:18:04 +04:00
parent ec6247b5c7
commit e59ac9f339
10 changed files with 27 additions and 40 deletions

View File

@ -426,3 +426,4 @@ void ALStream::streamData(){
SDL_Delay(AUDIO_SLEEP); SDL_Delay(AUDIO_SLEEP);
} }
} }

View File

@ -33,16 +33,16 @@
#include <SDL3/SDL_timer.h> #include <SDL3/SDL_timer.h>
struct AudioPrivate{ struct AudioPrivate{
int bgm_volume; unsigned char bgm_volume;
int sfx_volume; unsigned char sfx_volume;
AudioStream bgm; AudioStream bgm;
AudioStream bgs; AudioStream bgs;
AudioStream me; AudioStream me;
int current_bgm_volume; unsigned char current_bgm_volume;
int current_bgs_volume; unsigned char current_bgs_volume;
int current_me_volume; unsigned char current_me_volume;
SoundEmitter se; 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->current_bgm_volume = volume;
p->bgm.play(filename, (volume*p->bgm_volume)/100, pitch, pos); 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->current_bgs_volume = volume;
p->bgs.play(filename, (volume*p->sfx_volume)/100, pitch, pos); 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->current_me_volume = volume;
p->me.play(filename, (volume*p->bgm_volume)/100, pitch); 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); p->se.play(filename, (volume*p->sfx_volume)/100, pitch);
} }
@ -301,7 +301,7 @@ int Audio::getBGM_Volume() const{
return p->bgm_volume; return p->bgm_volume;
} }
void Audio::setBGM_Volume(int value){ void Audio::setBGM_Volume(short value){
if(value > 100){ if(value > 100){
value = 100; value = 100;
}else if(value < 0){ }else if(value < 0){
@ -320,7 +320,7 @@ int Audio::getSFX_Volume() const{
return p->sfx_volume; return p->sfx_volume;
} }
void Audio::setSFX_Volume(int value){ void Audio::setSFX_Volume(short value){
if(value > 100){ if(value > 100){
value = 100; value = 100;
}else if(value < 0){ }else if(value < 0){

View File

@ -39,29 +39,19 @@ struct RGSSThreadData;
class Audio{ class Audio{
public: public:
void bgmPlay(const char *filename, void bgmPlay(const char *filename, short volume = 100, short pitch = 100, float pos = 0);
int volume = 100,
int pitch = 100,
float pos = 0);
void bgmStop(); void bgmStop();
void bgmFade(int time); void bgmFade(int time);
void bgsPlay(const char *filename, void bgsPlay(const char *filename, short volume = 100, short pitch = 100, float pos = 0);
int volume = 100,
int pitch = 100,
float pos = 0);
void bgsStop(); void bgsStop();
void bgsFade(int time); void bgsFade(int time);
void mePlay(const char *filename, void mePlay(const char *filename, short volume = 100, short pitch = 100);
int volume = 100,
int pitch = 100);
void meStop(); void meStop();
void meFade(int time); void meFade(int time);
void sePlay(const char *filename, void sePlay(const char *filename, short volume = 100, short pitch = 100);
int volume = 100,
int pitch = 100);
void seStop(); void seStop();
float bgmPos(); float bgmPos();

View File

@ -134,7 +134,7 @@ void AudioStream::play(const std::string &filename, int volume, int pitch, float
stream.setPitch(_pitch); stream.setPitch(_pitch);
if (offset > 0){ if (offset > 0){
setVolume(FadeIn, 0); 0 setVolume(FadeIn, 0);
startFadeIn(); startFadeIn();
} }
@ -279,8 +279,7 @@ void AudioStream::fadeOutThread(){
if (state != ALStream::Playing if (state != ALStream::Playing
|| resVol < 0 || resVol < 0
|| fade.reqFini) || fade.reqFini){
{
if (state != ALStream::Paused) if (state != ALStream::Paused)
stream.stop(); stream.stop();

View File

@ -1069,9 +1069,7 @@ void Bitmap::drawText(const IntRect &rect, const char *str, int align){
GLMeta::blitRectangle(posRect, Vec2i()); GLMeta::blitRectangle(posRect, Vec2i());
GLMeta::blitEnd(); GLMeta::blitEnd();
FloatRect bltRect(0, 0, FloatRect bltRect(0, 0, (float) (gpTexSize.x * squeeze) / gpTex2.width, (float) gpTexSize.y / gpTex2.height);
(float) (gpTexSize.x * squeeze) / gpTex2.width,
(float) gpTexSize.y / gpTex2.height);
BltShader &shader = shState->shaders().blt; BltShader &shader = shState->shaders().blt;
shader.bind(); shader.bind();

View File

@ -66,7 +66,7 @@ namespace po = boost::program_options;
Config::Config() Config::Config()
{} {}
void Config::read(int argc, char *argv[]){ void Config::read(short argc, char *argv[]){
#define PO_DESC_ALL \ #define PO_DESC_ALL \
PO_DESC(debugMode, bool, false) \ PO_DESC(debugMode, bool, false) \
PO_DESC(screenMode, bool, false) \ PO_DESC(screenMode, bool, false) \

View File

@ -27,7 +27,7 @@
#include <set> #include <set>
struct Config{ struct Config{
int rgssVersion; unsigned char rgssVersion;
bool debugMode; bool debugMode;
bool screenMode; bool screenMode;
@ -89,7 +89,7 @@ struct Config{
Config(); Config();
void read(int argc, char *argv[]); void read(short argc, char *argv[]);
}; };
#endif // CONFIG_H #endif // CONFIG_H

View File

@ -65,8 +65,7 @@ public:
protected: protected:
void guardDisposed() const{ void guardDisposed() const{
if (isDisposed()) if (isDisposed())
throw Exception(Exception::RGSSError, throw Exception(Exception::RGSSError, "disposed %s", klassName());
"disposed %s", klassName());
} }
private: private:

View File

@ -101,7 +101,7 @@ void Color::serialize(char *buffer) const{
writeDouble(&buffer, alpha); writeDouble(&buffer, alpha);
} }
Color *Color::deserialize(const char *data, int len){ Color *Color::deserialize(const char *data, short len){
if (len != 32) if (len != 32)
throw Exception(Exception::ArgumentError, "Color: Serialized data invalid"); throw Exception(Exception::ArgumentError, "Color: Serialized data invalid");

View File

@ -66,7 +66,7 @@ struct Color : public Serializable{
/* Serializable */ /* Serializable */
int serialSize() const; int serialSize() const;
void serialize(char *buffer) const; void serialize(char *buffer) const;
static Color *deserialize(const char *data, int len); static Color *deserialize(const char *data, short len);
/* Internal */ /* Internal */
void updateInternal(); void updateInternal();