Skip to content

Commit

Permalink
zero initialize member variables (#27)
Browse files Browse the repository at this point in the history
  • Loading branch information
christopherhesse authored Feb 3, 2020
1 parent 74e9125 commit d9c1207
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 38 deletions.
4 changes: 4 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## 0.9.5

* zero initialize member variables from base classes

## 0.9.4

* add random agent script
Expand Down
45 changes: 28 additions & 17 deletions procgen/src/basic-abstract-game.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Base game class used by all currently existing games

class BasicAbstractGame : public Game {
public:
int grid_size;
int grid_size = 0;

BasicAbstractGame();
~BasicAbstractGame();
Expand Down Expand Up @@ -112,31 +112,42 @@ class BasicAbstractGame : public Game {
std::vector<float> asset_aspect_ratios;
std::vector<int> asset_num_themes;

bool use_procgen_background;
int background_index;
float bg_tile_ratio;
float bg_pct_x;
bool use_procgen_background = false;
int background_index = 0;
float bg_tile_ratio = 0.0f;
float bg_pct_x = 0.0f;

float char_dim;
int last_move_action, move_action, special_action;
float mixrate, maxspeed, max_jump;
float char_dim = 0.0f;
int last_move_action = 0;
int move_action = 0;
int special_action = 0;
float mixrate = 0.0f;
float maxspeed = 0.0f;
float max_jump = 0.0f;

float action_vx;
float action_vy;
float action_vrot;
float action_vx = 0.0f;
float action_vy = 0.0f;
float action_vrot = 0.0f;

float center_x, center_y;
float center_x = 0.0f;
float center_y = 0.0f;

bool random_agent_start = true;
bool has_useful_vel_info;
int step_rand_int;
bool has_useful_vel_info = false;
int step_rand_int = 0;

RandGen asset_rand_gen;

int main_width, main_height;
int out_of_bounds_object;
int main_width = 0;
int main_height = 0;
int out_of_bounds_object = 0;

float unit, view_dim, x_off, y_off, visibility, min_visibility;
float unit = 0.0f;
float view_dim = 0.0f;
float x_off = 0.0f;
float y_off = 0.0f;
float visibility = 0.0f;
float min_visibility = 0.0f;

private:
Grid<int> grid;
Expand Down
40 changes: 20 additions & 20 deletions procgen/src/game.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ enum DistributionMode {
};

struct StepData {
float reward;
bool done;
bool level_complete;
float reward = 0.0f;
bool done = false;
bool level_complete = false;
};

struct GameOptions {
Expand All @@ -61,40 +61,40 @@ class Game {
bool grid_step = false;
int level_seed_low = 0;
int level_seed_high = 1;
int game_type;
int game_n;
int game_type = 0;
int game_n = 0;

RandGen level_seed_rand_gen;
RandGen rand_gen;

StepData step_data;
int action;
int action = 0;

int timeout;
int timeout = 0;

int current_level_seed;
int episodes_remaining;
bool episode_done;
int current_level_seed = 0;
int episodes_remaining = 0;
bool episode_done = false;

float last_ep_reward;
int last_reward_timer;
float last_reward;
int default_action;
float last_ep_reward = 0.0f;
int last_reward_timer = 0;
float last_reward = 0.0f;
int default_action = 0;

int fixed_asset_seed;
int fixed_asset_seed = 0;

uint32_t render_buf[RES_W * RES_H];

int cur_time;
int cur_time = 0;

bool is_waiting_for_step = false;

// pointers to buffers where we should put step data
// these are set by step_async
std::vector<void *> obs_bufs;
std::vector<void *> info_bufs;
float *reward_ptr;
uint8_t *done_ptr;
float *reward_ptr = nullptr;
uint8_t *done_ptr = nullptr;

Game();
void step();
Expand All @@ -109,6 +109,6 @@ class Game {
virtual void game_draw(QPainter &p, const QRect &rect) = 0;

private:
int reset_count;
float total_reward;
int reset_count = 0;
float total_reward = 0.0f;
};
2 changes: 1 addition & 1 deletion procgen/version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.9.4
0.9.5

0 comments on commit d9c1207

Please sign in to comment.