Roguelike
 All Classes Namespaces Functions Variables Typedefs Friends Pages
Public Member Functions | Private Types | Private Attributes | List of all members
ChunkMatrix Class Reference

Public Member Functions

 ChunkMatrix (int _diameter, IntPoint center_chunk, MapTileMatrix &world_map)
 
void populate_initial (IntPoint center_chunk, MapTileMatrix &world_map)
 
void pretty_print ()
 
bool out_of_bounds (IntPoint local_chunk_point)
 
IntPoint get_offset ()
 
void set_offset (IntPoint point)
 
Chunkget_chunk_abs (IntPoint abs_chunk_loc)
 
Chunkget_chunk_abs (int row, int col)
 
Chunkget_center_chunk ()
 
void shift_matrix (IntPoint directions, MapTileMatrix &world_map)
 
void serialize_all ()
 

Private Types

typedef std::vector
< std::vector< MapTile > > 
MapTileMatrix
 

Private Attributes

int diameter
 
vector< vector< Chunk > > model
 
IntPoint offset
 

Member Function Documentation

Chunk * ChunkMatrix::get_center_chunk ( )

TODO update more code to use this instead of get_chunk_abs(main_char.get_y(), main_char.get_x())

Returns
the central chunk in the model.
Chunk * ChunkMatrix::get_chunk_abs ( IntPoint  abs_chunk_loc)
Parameters
abs_chunk_locthe absolute chunk coordinates on the world map.
Returns
a reference to the chunk from the local buffer.
Chunk * ChunkMatrix::get_chunk_abs ( int  row,
int  col 
)

The same as the other get_chunk_abs, but with two ints instead of an IntPoint.

IntPoint ChunkMatrix::get_offset ( )
Returns
an IntPoint representing the amount by which the top left corner of the ChunkMatrix is offset from the top left corner of the world.
bool ChunkMatrix::out_of_bounds ( IntPoint  local_chunk_point)

Determines whether or not the given local coordinates on this small chunk map are out of bounds.

Parameters
[in]chunk_pointan IntPoint representing a chunk's location on the private "model" matrix.
Returns
True if the given point cannot lie on the chunk map.
void ChunkMatrix::populate_initial ( IntPoint  center_chunk,
MapTileMatrix &  world_map 
)

Populates the chunk matrix initially, affecting the internal model.

Parameters
[in]center_chunkAn IntPoint representing the central chunk in the matrix
[in]world_mapThe world map, passed by reference here to avoid copying.
void ChunkMatrix::pretty_print ( )

Prints a graphic of the chunk matrix and its coordinates.

void ChunkMatrix::serialize_all ( )

Serializes all the chunks in the chunk_map.

void ChunkMatrix::set_offset ( IntPoint  point)

Set the offset (amount by which the top left corner of the ChunkMatrix differs from the world's top left corner).

Parameters
[in]pointa point representing a location on the world map.
void ChunkMatrix::shift_matrix ( IntPoint  directions,
MapTileMatrix &  world_map 
)

Shifts the contents of the chunk matrix.

Will shift the chunk buffer around on the world map, agnostic of the chunk buffer diameter. The concept of the chunk buffer is shown below. Periods are unloaded chunks on the world map, and x's are chunks within the chunk buffer (so, they are loaded). The buffer will move around, loading and unloading chunks as needed. Serialization and deserialization should all be handled in this function and the functions that it causes.

. . . . . . . . . . . . . . x x x . . . x x x . . . x x x . . . . . . .

Parameters
directionsan IntPoint representing the direction to shift the matrix: (1, 0) means one chunk to the right; (-1, -1) means one chunk to the left and one chunk up; (0, -1) means 1 chunk up, etc.
world_mapa reference to the world map.

Member Data Documentation

int ChunkMatrix::diameter
private

The diameter of this matrix.

vector<vector<Chunk> > ChunkMatrix::model
private

The base model where chunks are stored in a (diameter)*(diameter) two-dimensional vector.

IntPoint ChunkMatrix::offset
private

The amount by which the top left corner of the matrix is offset from the world.


The documentation for this class was generated from the following files: