store States to heap so that State memory adresses stay same

This commit is contained in:
jettis
2024-12-06 12:33:58 +02:00
parent 688def7e01
commit 38931cf65e
2 changed files with 24 additions and 5 deletions

View File

@@ -30,6 +30,13 @@ class State {
vector<SDL_Surface *> imgs;
SoundData sound_data;
~State() {
for (unsigned i = 0; i < imgs.size(); i++) {
if (imgs[i]) {
SDL_DestroySurface(imgs[i]);
}
}
}
};
class Animal {
@@ -40,7 +47,7 @@ class Animal {
SDL_Surface *readImg(string skin, string state_name, int num);
void readSkin(string file);
void readSkinStep(string skin, char chr, string &buf, string &key, State &state, char &prev_chr);
void readSkinFill(string skin, State state);
void readSkinFill(string skin, State &state);
void createShape(int num, int w, int h);
void move();
void animate(bool reset);
@@ -57,7 +64,7 @@ class Animal {
SDL_Rect disp_pos; // has display width and height and window posiion on it
vector<State> states;
vector<State *> states;
vector<State *> special_states;
State *cur_state;
vector<State *> random_states;