<commit_before>
#include "PCH-rpgcraft.h"
#include "TileMapLayer.h"

#include "x-png-decode.h"
#include "x-png-encode.h"
#include "fmod-ifc.h"
#include "imgtools.h"

#include "imgui.h"

TerrainMapItem*		g_WorldMap		= nullptr;

static FmodMusic	s_music_world;
static float		s_bgm_volume =	1.0f;

enum class TerrainTileConstructId
{
	FIRST = 0,
	Solid = 0,

	ObtuseCorners,
	Obtuse_HiL		= ObtuseCorners,
	Obtuse_HiR,
	Obtuse_LoL,
	Obtuse_LoR,

	AcuteCorners,
	Acute_HiL		= AcuteCorners,
	Acute_HiR,
	Acute_LoL,
	Acute_LoR,

	Spans,
	Span_HorizHi	= Spans,
	Span_HorizLo,
	Span_VertL,
	Span_VertR,

	LAST
};

TerrainTileConstructId _TerrainTileSet_incr(const TerrainTileConstructId& src) {
	TerrainTileConstructId result = src;
	(int&)result += 1;
	bug_on(int(result) >= int(TerrainTileConstructId::LAST));
	return result;
}

TerrainTileConstructId _TerrainTileSet_decr(const TerrainTileConstructId& src) {
	TerrainTileConstructId result = src;
	(int&)result += 1;
	bug_on(int(result) >= int(TerrainTileConstructId::LAST));
	return result;
}

TerrainTileConstructId& operator++(TerrainTileConstructId& left)      { return left = _TerrainTileSet_incr(left); }
TerrainTileConstructId  operator++(TerrainTileConstructId& left, int) { return        _TerrainTileSet_incr(left); }
TerrainTileConstructId& operator--(TerrainTileConstructId& left)      { return left = _TerrainTileSet_decr(left); }
TerrainTileConstructId  operator--(TerrainTileConstructId& left, int) { return        _TerrainTileSet_decr(left); }

static const int TerrainTileConstruct_Count = (int)TerrainTileConstructId::LAST;

static const int2 RipSrcTilePos[TerrainTileConstruct_Count];

namespace StdTileOffset
{
	static const int Empty			= 0;
	static const int Water			= 1 + (0 * TerrainTileConstruct_Count);
	static const int Sandy			= 1 + (1 * TerrainTileConstruct_Count);
	static const int Grassy			= 1 + (2 * TerrainTileConstruct_Count);
}

void PlaceTileWithRules()
{

}

void WorldMap_Procgen()
{
	g_WorldMap		= (TerrainMapItem*)	xRealloc(g_WorldMap,	WorldSizeX    * WorldSizeY    * sizeof(TerrainMapItem));

	// Fill map with boring grass.  or sand.

	for (int y=0; y<WorldSizeY; ++y) {
		for (int x=0; x<WorldSizeX; ++x) {
			g_WorldMap		[(y * WorldSizeX) + x].tile_below = StdTileOffset::Water;
			g_WorldMap		[(y * WorldSizeX) + x].tile_above  = StdTileOffset::Sandy;
		}
	}

	// carve a watering hole...
	for (int y=4; y<4+8; ++y) {
		for (int x=4; x<4+8; ++x) {
			g_WorldMap		[(y * WorldSizeX) + x].tile_above  = StdTileOffset::Empty;
		}
	}

}

static const int2 T2_GrabCoords[TerrainTileConstruct_Count] = {
	{ 1, 3 },	// Solid,
	{ 1, 0 },	// Obtuse_HiL
	{ 2, 0 },	// Obtuse_HiR
	{ 1, 1 },	// Obtuse_LoL
	{ 2, 1 },	// Obtuse_LoR
	{ 0, 2 },	// Acute_HiL,
	{ 2, 2 },	// Acute_HiR
	{ 0, 4 },	// Acute_LoL
	{ 2, 4 },	// Acute_LoR<commit_msg>WIP - PlaceTileWithRules(), just a stub for the moment.  Needs lots of love.<commit_after>
#include "PCH-rpgcraft.h"
#include "TileMapLayer.h"

#include "x-png-decode.h"
#include "x-png-encode.h"
#include "fmod-ifc.h"
#include "imgtools.h"

#include "imgui.h"

TerrainMapItem*		g_WorldMap		= nullptr;

static FmodMusic	s_music_world;
static float		s_bgm_volume =	1.0f;

enum class TerrainTileConstructId
{
	FIRST = 0,
	Solid = 0,

	ObtuseCorners,
	Obtuse_HiL		= ObtuseCorners,
	Obtuse_HiR,
	Obtuse_LoL,
	Obtuse_LoR,

	AcuteCorners,
	Acute_HiL		= AcuteCorners,
	Acute_HiR,
	Acute_LoL,
	Acute_LoR,

	Spans,
	Span_HorizHi	= Spans,
	Span_HorizLo,
	Span_VertL,
	Span_VertR,

	LAST
};

TerrainTileConstructId _TerrainTileSet_incr(const TerrainTileConstructId& src) {
	TerrainTileConstructId result = src;
	(int&)result += 1;
	bug_on(int(result) >= int(TerrainTileConstructId::LAST));
	return result;
}

TerrainTileConstructId _TerrainTileSet_decr(const TerrainTileConstructId& src) {
	TerrainTileConstructId result = src;
	(int&)result += 1;
	bug_on(int(result) >= int(TerrainTileConstructId::LAST));
	return result;
}

TerrainTileConstructId& operator++(TerrainTileConstructId& left)      { return left = _TerrainTileSet_incr(left); }
TerrainTileConstructId  operator++(TerrainTileConstructId& left, int) { return        _TerrainTileSet_incr(left); }
TerrainTileConstructId& operator--(TerrainTileConstructId& left)      { return left = _TerrainTileSet_decr(left); }
TerrainTileConstructId  operator--(TerrainTileConstructId& left, int) { return        _TerrainTileSet_decr(left); }

static const int TerrainTileConstruct_Count = (int)TerrainTileConstructId::LAST;

static const int2 RipSrcTilePos[TerrainTileConstruct_Count];

enum class TileClass
{
	Water,
	Sandy,
	Grassy,
};

namespace StdTileOffset
{
	static const int Empty			= 0;
	static const int Water			= 1 + (0 * TerrainTileConstruct_Count);
	static const int Sandy			= 1 + (1 * TerrainTileConstruct_Count);
	static const int Grassy			= 1 + (2 * TerrainTileConstruct_Count);
}

// tileDecorType - for defining variety in apperance, can be unsed for now until such time we want to "pretty things up" ...
void PlaceTileWithRules(int tileClass, int tileDecorType, int2 pos)
{
	auto  thisIdx		= (pos.y * WorldSizeX) + pos.x;
	int4  edgesIdx		= {
		((pos.y + -1) * WorldSizeX) + pos.x +  0,
		((pos.y +  0) * WorldSizeX) + pos.x +  1,
		((pos.y +  1) * WorldSizeX) + pos.x +  0,
		((pos.y +  0) * WorldSizeX) + pos.x + -1,
	};

	int4  cornersIdx	= {
		edgesIdx.x - 1,
		edgesIdx.x + 1,
		edgesIdx.z - 1,
		edgesIdx.z + 1,
	};

	auto& thisTile		= g_WorldMap[thisIdx];

	pragma_todo("select the correct TerrainTileConstructId according to surrounding tile classes and constructId's");
	//  TODO details:
	//   * This probably requires modifying neighboring tiles as well.
	//   * bounds checking on edgesIdx and cornersIdx is needed!  (for now can assume out-of-bounds edges are "water")

}

void DigThroughTile(int2 pos)
{
	auto  digSpotIndex  = (pos.y * WorldSizeX) + pos.x;
	auto& digSpot		= g_WorldMap[digSpotIndex];

	//
}

void WorldMap_Procgen()
{
	g_WorldMap		= (TerrainMapItem*)	xRealloc(g_WorldMap,	WorldSizeX    * WorldSizeY    * sizeof(TerrainMapItem));

	// Fill map with boring grass.  or sand.

	for (int y=0; y<WorldSizeY; ++y) {
		for (int x=0; x<WorldSizeX; ++x) {
			g_WorldMap		[(y * WorldSizeX) + x].tile_below	= StdTileOffset::Water;
			g_WorldMap		[(y * WorldSizeX) + x].tile_above	= StdTileOffset::Sandy;
		}
	}

	// carve a watering hole...
	for (int y=4; y<4+8; ++y) {
		for (int x=4; x<4+8; ++x) {
			g_WorldMap		[(y * WorldSizeX) + x].tile_above  = StdTileOffset::Empty;
		}
	}

}

static const int2 T2_GrabCoords[TerrainTileConstruct_Count] = {
	{ 1, 3 },	// Solid,
	{ 1, 0 },	// Obtuse_HiL
	{ 2, 0 },	// Obtuse_HiR
	{ 1, 1 },	// Obtuse_LoL
	{ 2, 1 },	// Obtuse_LoR
	{ 0, 2 },	// Acute_HiL,
	{ 2, 2 },	// Acute_HiR
	{ 0, 4 },	// Acute_LoL
	{ 2, 4 },	// Acute_LoR
{'fraction_non_alphanumeric': 0.12792419307077288, 'fraction_numerical': 0.014806040864672786, 'mean_word_length': 4.228328173374613, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 7, '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': '4250455', 'n_tokens_mistral': 2904, 'n_tokens_neox': 2701, 'n_words': 579}