Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Chunk class, 32x32x32 section of blocks
- */
- #ifndef __chunk_h__
- #define __chunk_h__
- #include "Block.h"
- #include <vector>
- #include <iostream>
- #define CHUNK_SIZE 16
- #define C_SURFACE_AREA 256
- #define stp(val) GLfloat(val) - CHUNK_SIZE/2.0f - B_HALF_SIZE
- /// A pair of indices, makes up a row of non-null blocks
- typedef struct _indicePair {
- int start, end;
- } IndicePair;
- /// A quad of indices, makes up a quad of non-null blocks
- /// which will then be used to construct the merged face
- typedef struct _indiceQuad {
- int startX, startY;
- int endX, endY;
- } IndiceQuad;
- /// Test whether one pair ascends from the next.
- /// eg. If chunk size is 16, then the pair (18, 24)
- /// is an ascension of (2, 8).
- #define IPAIR_Ascension(p1, p2) ( p1.start == p2.start + CHUNK_SIZE && \
- p1.end == p2.end + CHUNK_SIZE )
- /// Helper class for face merging
- class CPoint {
- public:
- CPoint() { }
- CPoint(GLfloat x, GLfloat y, GLfloat z) {
- pts[0] = x;
- pts[1] = y;
- pts[2] = z;
- }
- GLfloat* arr(void) { return pts; }
- private:
- GLfloat pts[3];
- };
- /// Merges adjacent blocks
- /// on the same level into one large face for
- /// performance improvements.
- typedef struct _mgFace {
- CPoint pointList[4];
- int xr, yr; // num times to repeat texture
- } MergedFace;
- class Chunk {
- public:
- Chunk();
- /// Build the chunk
- void buildChunk(void);
- /// Draw all blocks in the chunk
- void drawAll(void);
- /// Cleans up all blocks within the chunk
- void destroyChunk(void);
- /// Build merged faces
- void buildMergedFaces(void);
- private:
- /// Draws a single block in the chunk
- void draw(Block* block, int i, int j, int k);
- /// Determines whether a block is on the edge of a chunk
- bool isEdgeBlock(int x, int y, int z);
- /// Construct merged face
- void constructMergedFace(int startA, int sizeA, int startB, int sizeB, int orientation, int depth);
- /// Split off a row into a list of paired indices (start and end)
- std::vector<IndicePair> getSplitRow(std::vector<int> values);
- Block* blocks[CHUNK_SIZE][CHUNK_SIZE][CHUNK_SIZE];
- std::vector<MergedFace> mergeList;
- };
- #endif
Add Comment
Please, Sign In to add comment