store States to heap so that State memory adresses stay same
This commit is contained in:
18
Animal.cpp
18
Animal.cpp
@@ -22,6 +22,7 @@ Animal::Animal(string skin) {
|
||||
cur = 0;
|
||||
viime_event = 0;
|
||||
state_changed = false;
|
||||
animation_i = 0;
|
||||
|
||||
// set rand seed
|
||||
SDL_srand(0);
|
||||
@@ -31,6 +32,11 @@ Animal::Animal(string skin) {
|
||||
}
|
||||
|
||||
Animal::~Animal() {
|
||||
for (unsigned i = 0; i < states.size(); i++) {
|
||||
if (states[i]) {
|
||||
delete states[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
SDL_Surface *Animal::readImg(string skin, string state_name, int num) {
|
||||
@@ -79,6 +85,12 @@ void Animal::readSkin(string skin) {
|
||||
State feat;
|
||||
char prev_chr;
|
||||
|
||||
for (unsigned i = 0; i < states.size(); i++) {
|
||||
if (states[i]) {
|
||||
delete states[i];
|
||||
}
|
||||
}
|
||||
|
||||
states.clear();
|
||||
special_states.clear();
|
||||
random_states.clear();
|
||||
@@ -150,11 +162,11 @@ void Animal::readSkinStep(string skin, char chr, string &buf, string &key, State
|
||||
prev_chr = chr;
|
||||
}
|
||||
|
||||
void Animal::readSkinFill(string skin, State feat) {
|
||||
states.push_back(feat);
|
||||
void Animal::readSkinFill(string skin, State &feat) {
|
||||
cur_state = new State(feat);
|
||||
states.push_back(cur_state);
|
||||
|
||||
// Load images to memory
|
||||
cur_state = &states.back();
|
||||
for (int x = 0; x < cur_state->count; x++) {
|
||||
cur_state->imgs.push_back(NULL);
|
||||
cur_state->imgs[x] = readImg(skin, cur_state->img_name, x);
|
||||
|
||||
Reference in New Issue
Block a user