Reduce chunk tex resolution
parent
f47acae59b
commit
e99b21b11b
|
@ -19,7 +19,7 @@ void DEBUG_draw_ground(uint64_t key, entity_view * data) {
|
||||||
float y = data->y * size + offset;
|
float y = data->y * size + offset;
|
||||||
|
|
||||||
RenderTexture2D tex = GetChunkTexture(key);
|
RenderTexture2D tex = GetChunkTexture(key);
|
||||||
DrawTextureRec(tex.texture, (Rectangle){0, 0, tex.texture.width, -tex.texture.height}, (Vector2){x, y}, ColorAlpha(WHITE, data->tran_time));
|
DrawTextureEx(tex.texture, (Vector2){x, y}, 0.0f, size / (float)tex.texture.width, ColorAlpha(WHITE, data->tran_time));
|
||||||
|
|
||||||
if (zoom_overlay_tran > 0.02f) {
|
if (zoom_overlay_tran > 0.02f) {
|
||||||
DrawRectangleEco(x, y, size-offset, size-offset, ColorAlpha(ColorFromHSV(data->color, 0.13f, 0.89f), data->tran_time*zoom_overlay_tran*0.75f));
|
DrawRectangleEco(x, y, size-offset, size-offset, ColorAlpha(ColorFromHSV(data->color, 0.13f, 0.89f), data->tran_time*zoom_overlay_tran*0.75f));
|
||||||
|
|
|
@ -1,142 +1,143 @@
|
||||||
#define ZPL_NANO
|
#define ZPL_NANO
|
||||||
#include "zpl.h"
|
#include "zpl.h"
|
||||||
#include "world/world.h"
|
#include "world/world.h"
|
||||||
#include "world/blocks.h"
|
#include "world/blocks.h"
|
||||||
#include "raylib.h"
|
#include "raylib.h"
|
||||||
#include "gen/texgen.h"
|
#include "gen/texgen.h"
|
||||||
#include "world_view.h"
|
#include "world_view.h"
|
||||||
#include "perlin.h"
|
#include "perlin.h"
|
||||||
|
|
||||||
#define BLOCKS_COUNT (sizeof(blocks)/sizeof(block))
|
#define BLOCKS_COUNT (sizeof(blocks)/sizeof(block))
|
||||||
|
|
||||||
ZPL_TABLE(static, blocks__chunk_tbl, blocks__chunk_tbl_, RenderTexture2D);
|
ZPL_TABLE(static, blocks__chunk_tbl, blocks__chunk_tbl_, RenderTexture2D);
|
||||||
|
|
||||||
static blocks__chunk_tbl baked_chunks;
|
static blocks__chunk_tbl baked_chunks;
|
||||||
|
|
||||||
static void chunks_unload_textures(uint64_t key, RenderTexture2D *value) {
|
static void chunks_unload_textures(uint64_t key, RenderTexture2D *value) {
|
||||||
(void)key;
|
(void)key;
|
||||||
UnloadRenderTexture(*value);
|
UnloadRenderTexture(*value);
|
||||||
}
|
}
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
char *name;
|
char *name;
|
||||||
uint32_t flags;
|
uint32_t flags;
|
||||||
uint32_t kind;
|
uint32_t kind;
|
||||||
uint32_t biome;
|
uint32_t biome;
|
||||||
char symbol;
|
char symbol;
|
||||||
float drag;
|
float drag;
|
||||||
float friction;
|
float friction;
|
||||||
float bounce;
|
float bounce;
|
||||||
|
|
||||||
// NOTE(zaklaus): viewer data
|
// NOTE(zaklaus): viewer data
|
||||||
Texture2D img;
|
Texture2D img;
|
||||||
} block;
|
} block;
|
||||||
|
|
||||||
#include "blocks_list.c"
|
#include "blocks_list.c"
|
||||||
|
|
||||||
int32_t blocks_setup(void) {
|
int32_t blocks_setup(void) {
|
||||||
for (uint32_t i=0; i<BLOCKS_COUNT; i++) {
|
for (uint32_t i=0; i<BLOCKS_COUNT; i++) {
|
||||||
block *b = &blocks[i];
|
block *b = &blocks[i];
|
||||||
b->img = texgen_build_block(b->biome, b->kind);
|
b->img = texgen_build_block(b->biome, b->kind);
|
||||||
}
|
}
|
||||||
|
|
||||||
blocks__chunk_tbl_init(&baked_chunks, zpl_heap());
|
blocks__chunk_tbl_init(&baked_chunks, zpl_heap());
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void blocks_destroy(void) {
|
void blocks_destroy(void) {
|
||||||
for (uint32_t i=0; i<BLOCKS_COUNT; i++) {
|
for (uint32_t i=0; i<BLOCKS_COUNT; i++) {
|
||||||
UnloadTexture(blocks[i].img);
|
UnloadTexture(blocks[i].img);
|
||||||
}
|
}
|
||||||
|
|
||||||
blocks__chunk_tbl_map_mut(&baked_chunks, chunks_unload_textures);
|
blocks__chunk_tbl_map_mut(&baked_chunks, chunks_unload_textures);
|
||||||
blocks__chunk_tbl_destroy(&baked_chunks);
|
blocks__chunk_tbl_destroy(&baked_chunks);
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t blocks_find(uint32_t biome, uint32_t kind) {
|
uint8_t blocks_find(uint32_t biome, uint32_t kind) {
|
||||||
for (uint32_t i=0; i<BLOCKS_COUNT; i++) {
|
for (uint32_t i=0; i<BLOCKS_COUNT; i++) {
|
||||||
if (blocks[i].biome == biome && blocks[i].kind == kind)
|
if (blocks[i].biome == biome && blocks[i].kind == kind)
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
return BLOCK_INVALID;
|
return BLOCK_INVALID;
|
||||||
}
|
}
|
||||||
|
|
||||||
char *blocks_get_name(uint8_t id) {
|
char *blocks_get_name(uint8_t id) {
|
||||||
return blocks[id].name;
|
return blocks[id].name;
|
||||||
}
|
}
|
||||||
|
|
||||||
char blocks_get_symbol(uint8_t id) {
|
char blocks_get_symbol(uint8_t id) {
|
||||||
return blocks[id].symbol;
|
return blocks[id].symbol;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t blocks_get_flags(uint8_t id) {
|
uint32_t blocks_get_flags(uint8_t id) {
|
||||||
return blocks[id].flags;
|
return blocks[id].flags;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t blocks_get_biome(uint8_t id) {
|
uint32_t blocks_get_biome(uint8_t id) {
|
||||||
return blocks[id].biome;
|
return blocks[id].biome;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t blocks_get_kind(uint8_t id) {
|
uint32_t blocks_get_kind(uint8_t id) {
|
||||||
return blocks[id].kind;
|
return blocks[id].kind;
|
||||||
}
|
}
|
||||||
|
|
||||||
float blocks_get_drag(uint8_t id) {
|
float blocks_get_drag(uint8_t id) {
|
||||||
return blocks[id].drag;
|
return blocks[id].drag;
|
||||||
}
|
}
|
||||||
|
|
||||||
float blocks_get_friction(uint8_t id) {
|
float blocks_get_friction(uint8_t id) {
|
||||||
return blocks[id].friction;
|
return blocks[id].friction;
|
||||||
}
|
}
|
||||||
|
|
||||||
float blocks_get_bounce(uint8_t id) {
|
float blocks_get_bounce(uint8_t id) {
|
||||||
return blocks[id].bounce;
|
return blocks[id].bounce;
|
||||||
}
|
}
|
||||||
|
|
||||||
void *blocks_get_img(uint8_t id) {
|
void *blocks_get_img(uint8_t id) {
|
||||||
return (void*)&blocks[id].img;
|
return (void*)&blocks[id].img;
|
||||||
}
|
}
|
||||||
|
|
||||||
void blocks_build_chunk_tex(uint64_t id, uint8_t *chunk_blocks, uint8_t *outer_chunk_blocks, void *raw_view) {
|
void blocks_build_chunk_tex(uint64_t id, uint8_t *chunk_blocks, uint8_t *outer_chunk_blocks, void *raw_view) {
|
||||||
world_view *view = (world_view*)raw_view;
|
world_view *view = (world_view*)raw_view;
|
||||||
uint16_t dims = WORLD_BLOCK_SIZE * view->chunk_size;
|
uint16_t blk_dims = WORLD_BLOCK_SIZE * 0.5f;
|
||||||
RenderTexture2D canvas = LoadRenderTexture(dims, dims);
|
uint16_t dims = blk_dims * view->chunk_size;
|
||||||
BeginTextureMode(canvas);
|
RenderTexture2D canvas = LoadRenderTexture(dims, dims);
|
||||||
ClearBackground(WHITE);
|
BeginTextureMode(canvas);
|
||||||
for (int y = 0; y < view->chunk_size; y += 1) {
|
ClearBackground(WHITE);
|
||||||
for (int x = 0; x < view->chunk_size; x += 1) {
|
for (int y = 0; y < view->chunk_size; y += 1) {
|
||||||
#if 0
|
for (int x = 0; x < view->chunk_size; x += 1) {
|
||||||
Texture2D blk = blocks[chunk_blocks[(y*view->chunk_size)+x]].img;
|
#if 0
|
||||||
Rectangle src = {0, 0, WORLD_BLOCK_SIZE, WORLD_BLOCK_SIZE};
|
Texture2D blk = blocks[chunk_blocks[(y*view->chunk_size)+x]].img;
|
||||||
Rectangle dst = {x*WORLD_BLOCK_SIZE, y*WORLD_BLOCK_SIZE, WORLD_BLOCK_SIZE, WORLD_BLOCK_SIZE};
|
Rectangle src = {0, 0, WORLD_BLOCK_SIZE, WORLD_BLOCK_SIZE};
|
||||||
DrawTexturePro(blk, src, dst, (Vector2){0.0f,0.0f}, 0.0f, WHITE);
|
Rectangle dst = {x*blk_dims, y*blk_dims, blk_dims, blk_dims};
|
||||||
#else
|
DrawTexturePro(blk, src, dst, (Vector2){0.0f,0.0f}, 0.0f, WHITE);
|
||||||
static float rots[] = { 0.0f, 90.0f, 180.f, 270.0f };
|
#else
|
||||||
float rot = rots[(int32_t)(perlin_fbm(view->seed, x, y, 1.2f, 3) * 4.0f) % 4];
|
static float rots[] = { 0.0f, 90.0f, 180.f, 270.0f };
|
||||||
float half_block = WORLD_BLOCK_SIZE / 2.0f;
|
float rot = rots[(int32_t)(perlin_fbm(view->seed, x, y, 1.2f, 3) * 4.0f) % 4];
|
||||||
Texture2D blk = blocks[chunk_blocks[(y*view->chunk_size)+x]].img;
|
float half_block = blk_dims / 2.0f;
|
||||||
Rectangle src = {0, 0, WORLD_BLOCK_SIZE, WORLD_BLOCK_SIZE};
|
Texture2D blk = blocks[chunk_blocks[(y*view->chunk_size)+x]].img;
|
||||||
Rectangle dst = {x*WORLD_BLOCK_SIZE + half_block, y*WORLD_BLOCK_SIZE + half_block, WORLD_BLOCK_SIZE, WORLD_BLOCK_SIZE};
|
Rectangle src = {0, 0, WORLD_BLOCK_SIZE, WORLD_BLOCK_SIZE};
|
||||||
DrawTexturePro(blk, src, dst, (Vector2){half_block, half_block}, rot, WHITE);
|
Rectangle dst = {x*blk_dims + half_block, y*blk_dims + half_block, blk_dims, blk_dims};
|
||||||
|
DrawTexturePro(blk, src, dst, (Vector2){half_block, half_block}, rot, WHITE);
|
||||||
if (outer_chunk_blocks[(y*view->chunk_size)+x] != 0) {
|
|
||||||
Texture2D blk2 = blocks[outer_chunk_blocks[(y*view->chunk_size)+x]].img;
|
if (outer_chunk_blocks[(y*view->chunk_size)+x] != 0) {
|
||||||
DrawTexturePro(blk2, src, dst, (Vector2){half_block, half_block}, rot, WHITE);
|
Texture2D blk2 = blocks[outer_chunk_blocks[(y*view->chunk_size)+x]].img;
|
||||||
}
|
DrawTexturePro(blk2, src, dst, (Vector2){half_block, half_block}, rot, WHITE);
|
||||||
#endif
|
}
|
||||||
}
|
#endif
|
||||||
}
|
}
|
||||||
EndTextureMode();
|
}
|
||||||
blocks__chunk_tbl_set(&baked_chunks, id, canvas);
|
EndTextureMode();
|
||||||
}
|
blocks__chunk_tbl_set(&baked_chunks, id, canvas);
|
||||||
|
}
|
||||||
void *blocks_get_chunk_tex(uint64_t id) {
|
|
||||||
return blocks__chunk_tbl_get(&baked_chunks, id);
|
void *blocks_get_chunk_tex(uint64_t id) {
|
||||||
}
|
return blocks__chunk_tbl_get(&baked_chunks, id);
|
||||||
|
}
|
||||||
void blocks_remove_chunk_tex(uint64_t id) {
|
|
||||||
RenderTexture2D *tex = blocks__chunk_tbl_get(&baked_chunks, id);
|
void blocks_remove_chunk_tex(uint64_t id) {
|
||||||
if (!tex) return;
|
RenderTexture2D *tex = blocks__chunk_tbl_get(&baked_chunks, id);
|
||||||
UnloadRenderTexture(*tex);
|
if (!tex) return;
|
||||||
blocks__chunk_tbl_remove(&baked_chunks, id);
|
UnloadRenderTexture(*tex);
|
||||||
|
blocks__chunk_tbl_remove(&baked_chunks, id);
|
||||||
}
|
}
|
Loading…
Reference in New Issue