1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108
|
#ifndef BLOCK_GRID_INCLUDED
#define BLOCK_GRID_INCLUDED
#include "minorGems/util/SimpleVector.h"
#include "Block.h"
#include "World.h"
class BlockGrid {
public:
// sets world to NULL
// setWorld must be called before using the resulting class
BlockGrid();
// the world that this grid is in
BlockGrid( World *inWorld );
~BlockGrid();
void setWorld( World *inWorld );
void setDepthLayer( int inDepthLayer );
// blocks destroyed when corresponding world destroyed
// return true if add succeeded
char add( Block *inBlock, int inX, int inY );
// gets all blocks managed by this grid
SimpleVector<Block *> *getAllBlocks();
// can return NULL
Block *getBlock( int inX, int inY );
Block *removeBlock( int inX, int inY );
// is the column at world position inX full?
char isColumnFull( int inX );
// for synching with server
// gets all dirty columns as strings in format that matches
// server's protocol.txt specification
// vector and strings destroyed by caller
SimpleVector<char*> *getDirtyColumns();
void clearDirtyFlags();
// sets columns using server formatted column strings
void setColumns( SimpleVector<char*> *inColumns );
protected:
World *mWorld;
// depth layer to set for all blocks added to this grid
int mDepthLayer;
static const int mBlockColumns = 40;
static const int mBlockRows = 9;
Block *mBlocks[mBlockRows][mBlockColumns];
char mDirtyFlags[mBlockColumns];
void initBlocks();
// coordinate conversion functions
int worldToGridC( int inX ) {
return inX + mBlockColumns / 2;
}
int worldToGridR( int inY ) {
return inY - 1;
}
int gridToWorldX( int inC ) {
return inC - mBlockColumns / 2;
}
int gridToWorldY( int inR ) {
return inR + 1;
}
};
#endif
|