Skip to content
Permalink
Browse files

Working on reducing memory of wall storage

We need to reduce the amount of memory that the wall storage takes.
Inorder to achomplish this we are going to use an uint8_t to store
the values of the walls. Each bit will store a different wall
reducing the memory cost by 4.
  • Loading branch information
StefanBossbaly committed Mar 6, 2014
1 parent 8c541ef commit 90e3d13fbed50e9d34b5e72b7b5caf2a5cbe8ade
Showing with 29 additions and 8 deletions.
  1. +22 −4 nav.cpp
  2. +7 −4 nav.h
26 nav.cpp
@@ -33,10 +33,7 @@ void nav_init(struct nav_array *array, struct nav_cell *cells, int rows, int col
for (i = 0; i < size; i++)
{
struct nav_cell *cell = &array->cells[i];
cell->north = 0;
cell->south = 0;
cell->east = 0;
cell->west = 0;
cell->wall = 0;
cell->has_visited = 0;
cell->flood_num = -1;
cell->row = (i / array->columns);
@@ -420,4 +417,25 @@ void nav_update_wall(struct nav_array *array, pos_t *position, facing_t dir)
nav_update_wall_cell(west_cell, east);
}
}

inline uint8_t nav_north_wall(struct nav_cell *cell)
{
return cell->wall & 0x01;
}

inline uint8_t nav_east_wall(struct nav_cell *cell)
{
return cell->wall & 0x02;
}

inline uint8_t nav_south_wall(struct nav_cell *cell)
{
return cell->wall & 0x04;
}

inline uint8_t nav_west_wall(struct nav_cell *cell)
{
return cell->wall & 0x08;
}

}
11 nav.h
@@ -2,6 +2,7 @@
#define NAV_H

#include "position.h"
#include "inttypes.h"

#ifdef __cplusplus
extern "C"
@@ -12,10 +13,7 @@ struct nav_cell
{
int flood_num;
int has_visited;
int north;
int south;
int east;
int west;
uint8_t wall;
int row;
int column;
};
@@ -56,6 +54,11 @@ struct nav_cell *nav_get_next_neighbor(struct nav_array *array, int row, int col
void nav_update_wall_cell(struct nav_cell *cell, dir_t dir);
void nav_update_wall(struct nav_array *array, pos_t *position, facing_t dir);

inline uint8_t nav_north_wall(struct nav_cell *cell);
inline uint8_t nav_east_wall(struct nav_cell *cell);
inline uint8_t nav_south_wall(struct nav_cell *cell);
inline uint8_t nav_west_wall(struct nav_cell *cell);


#ifdef __cplusplus
}

0 comments on commit 90e3d13

Please sign in to comment.
You can’t perform that action at this time.