<commit_before>#ifndef __EACSMB_MAP_H__
#define __EACSMB_MAP_H__


// terrain textures must always be a power of two
#define TERR_TEX_SZ 256
// terrain blocks must always be a power of two minus one
#define TERR_BLOCK_SZ (TERR_TEX_SZ)

#define MAP_TEX_SZ (TERR_TEX_SZ)



#define TCOORD(x,y) ((y * TERR_TEX_SZ) + x)
#define MCOORD(x,y) ((y * MAP_TEX_SZ) + x)

#include "road.h"
#include "view.h"
#include "uniformBuffer.h"

typedef struct TerrainPatchVertex {
	float x, y, z;
	float hmU, hmV; // these are in texels
	float divX, divY;
} TerrainPatchVertex;


typedef struct TerrainBlock {
	float zs[TERR_TEX_SZ * TERR_TEX_SZ];
	int cx, cy;
	AABB2 box;
	int scale;
	
	int dirty;
	AABB2 dirtyBox;
	
	GLuint tex;
	
} TerrainBlock;



typedef struct MapBlock {
	int32_t bix, biy; // location in blocks. max world size is 2^32 blocks square ~5.6e8 km2 ~1.1x earth surface area  
	
	struct MapBlock* n_xp, *n_xm, *n_yp, *n_ym;
	
	unsigned char surface[TERR_TEX_SZ * TERR_TEX_SZ];
	unsigned char zones[TERR_TEX_SZ * TERR_TEX_SZ];
	
	int dirtyZone, dirtySurface;
	

	TerrainBlock tb;
	
	RoadBlock roads;
	
} MapBlock;

typedef struct MapBlockTreeLeaf {
	MapBlock* c[8][8];
	int32_t minx, miny;
} MapBlockTreeLeaf;






//TODO: mark some regular terrain tiles as transparent... to see excavations
typedef struct VirtualTerrainBlock { // used for planning, renders as wireframe, usually
	float* zs;
	AABB2i worldBounds; // in world tile space, not TB tile space
	
	GLuint vbo;
	int vertices;
	
	TerrainBlock** blocks;
	
} VirtualTerrainBlock;


/*

in general:

render opaque buildings
render terrain
render infrastructure
render ui



conservative frustum culling/selection
sort by distance
render front to back


*/


typedef struct MapBlockRenderInfo {
	int texIndex; // index into the origin offset texture map
	Vector2 originOffset; // offset from the view's origin at this time
	MapBlock* mb; // the map block this belongs to
	float minViewDistance; // distance of the min and max corners from the camera, 
	float maxViewDistance; //   in 3d
	float min2DDistance; // distance of min and max corners from the camera,
	float max2DDistance; //   projected onto the ground
	
	Matrix* mWorldView;
	Matrix* mViewProj;
} MapBlockRenderInfo;

struct sGL_RG8 {
	unsigned char x, y;
};


typedef struct MapRenderComponent {
	void (*alloc)(MapInfo*, MapBlock*, void*); // called to allocate memory for the block
	void (*create)(MapInfo*, MapBlock*, void*); // called once ever when the block is first created
		
	void (*load)(MapInfo*, MapBlock*, void*); 
	void (*save)(MapInfo*, MapBlock*, void*);
	<commit_msg>eh. don't bite off more than i can chew atm.<commit_after>#ifndef __EACSMB_MAP_H__
#define __EACSMB_MAP_H__


#define MAP_SIZE (255 * 8)

// terrain textures must always be a power of two
#define TERR_TEX_SZ 256
// terrain blocks must always be a power of two minus one
#define TERR_BLOCK_SZ (TERR_TEX_SZ)

#define MAP_TEX_SZ (TERR_TEX_SZ)




#define TCOORD(x,y) ((y * TERR_TEX_SZ) + x)
#define MCOORD(x,y) ((y * MAP_TEX_SZ) + x)

#include "road.h"
#include "view.h"
#include "uniformBuffer.h"

typedef struct TerrainPatchVertex {
	float x, y, z;
	float hmU, hmV; // these are in texels
	float divX, divY;
} TerrainPatchVertex;


typedef struct TerrainBlock {
	float zs[TERR_TEX_SZ * TERR_TEX_SZ];
	int cx, cy;
	AABB2 box;
	int scale;
	
	int dirty;
	AABB2 dirtyBox;
	
	GLuint tex;
	
} TerrainBlock;



typedef struct MapBlock {
	int32_t bix, biy; // location in blocks. max world size is 2^32 blocks square ~5.6e8 km2 ~1.1x earth surface area  
	
	struct MapBlock* n_xp, *n_xm, *n_yp, *n_ym;
	
	unsigned char surface[TERR_TEX_SZ * TERR_TEX_SZ];
	unsigned char zones[TERR_TEX_SZ * TERR_TEX_SZ];
	
	int dirtyZone, dirtySurface;
	

	TerrainBlock tb;
	
	RoadBlock roads;
	
} MapBlock;

typedef struct MapBlockTreeLeaf {
	MapBlock* c[8][8];
	int32_t minx, miny;
} MapBlockTreeLeaf;






//TODO: mark some regular terrain tiles as transparent... to see excavations
typedef struct VirtualTerrainBlock { // used for planning, renders as wireframe, usually
	float* zs;
	AABB2i worldBounds; // in world tile space, not TB tile space
	
	GLuint vbo;
	int vertices;
	
	TerrainBlock** blocks;
	
} VirtualTerrainBlock;


/*

in general:

render opaque buildings
render terrain
render infrastructure
render ui



conservative frustum culling/selection
sort by distance
render front to back


*/


typedef struct MapBlockRenderInfo {
	int texIndex; // index into the origin offset texture map
	Vector2 originOffset; // offset from the view's origin at this time
	MapBlock* mb; // the map block this belongs to
	float minViewDistance; // distance of the min and max corners from the camera, 
	float maxViewDistance; //   in 3d
	float min2DDistance; // distance of min and max corners from the camera,
	float max2DDistance; //   projected onto the ground
	
	Matrix* mWorldView;
	Matrix* mViewProj;
} MapBlockRenderInfo;

struct sGL_RG8 {
	unsigned char x, y;
};

typedef struct MapLayer_Roads {
	
} MapLayer_Roads;

typedef struct MapLayer_Trees {
	TerrainBlock* blocks;
} MapLayer_Trees;

typedef struct MapLayer_Zones {
	uint8_t* zone_data;
	// zone list
	// zone colors
} MapLayer_Zones;

typedef struct MapLayer_Terrain {
	TerrainBlock* blocks;
} MapLayer_Terrain;

// just hardcode to some moderately large size for now
typedef struct MapLayer {
	uint16_t id;
	uint16_t type;
	uint32_t flags;
	char* name;
	
	union {
		MapLayer_Terrain terrain;
		MapLayer_Roads roads;
		MapLayer_Zones zones;
	}
} MapLayer;


typedef struct MapRenderComponent {
	void (*alloc)(MapInfo*, MapBlock*, void*); // called to allocate memory for the block
	void (*create)(MapInfo*, MapBlock*, void*); // called once ever when the block is first created
		
	void (*load)(MapInfo*, MapBlock*, void*); 
	void (*save)(MapInfo*, MapBlock*, void*);
	
{'fraction_non_alphanumeric': 0.08816945066299293, 'fraction_numerical': 0.010848975374547959, 'mean_word_length': 4.148936170212766, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6828889', 'n_tokens_mistral': 2221, 'n_tokens_neox': 1994, 'n_words': 687}