Draw only things within the game rectangle
Testing it out on sandbox for nowscene_man
parent
963ba34164
commit
e6683dfec1
|
@ -81,15 +81,37 @@ static void level_scene_render_func(Scene_t* scene)
|
||||||
TileGrid_t tilemap = data->tilemap;
|
TileGrid_t tilemap = data->tilemap;
|
||||||
|
|
||||||
Entity_t* p_ent;
|
Entity_t* p_ent;
|
||||||
|
Vector2 min = GetScreenToWorld2D((Vector2){data->game_rec.x, data->game_rec.y}, data->cam);
|
||||||
|
Vector2 max = GetScreenToWorld2D(
|
||||||
|
(Vector2){
|
||||||
|
data->game_rec.x + data->game_rec.width,
|
||||||
|
data->game_rec.y + data->game_rec.height
|
||||||
|
},
|
||||||
|
data->cam
|
||||||
|
);
|
||||||
|
min = Vector2Scale(min, 1.0f/tilemap.tile_size);
|
||||||
|
max = Vector2Scale(max, 1.0f/tilemap.tile_size);
|
||||||
|
min.x = (int)fmax(0, min.x - 1);
|
||||||
|
min.y = (int)fmax(0, min.y - 1);
|
||||||
|
max.x = (int)fmin(tilemap.width-1, max.x + 1);
|
||||||
|
max.y = (int)fmin(tilemap.height-1, max.y + 1);
|
||||||
|
|
||||||
|
printf("(%d,%d %d,%d\n", (int)min.x, (int)min.y, (int)max.x, (int)max.y);
|
||||||
BeginTextureMode(data->game_viewport);
|
BeginTextureMode(data->game_viewport);
|
||||||
ClearBackground(WHITE);
|
ClearBackground(WHITE);
|
||||||
BeginMode2D(data->cam);
|
BeginMode2D(data->cam);
|
||||||
for (size_t i = 0; i < tilemap.n_tiles; ++i)
|
//for (size_t i = 0; i < tilemap.n_tiles; ++i)
|
||||||
|
//{
|
||||||
|
for (int tile_y = min.y; tile_y <= max.y; tile_y++)
|
||||||
{
|
{
|
||||||
|
//for (unsigned int tile_x = tile_x1; tile_x <= tile_x2; tile_x++)
|
||||||
|
for (int tile_x = min.x; tile_x <= max.x; tile_x++)
|
||||||
|
{
|
||||||
|
//int i = get_tile_idx(x, y, &tilemap);
|
||||||
|
int i = tile_x + tile_y * tilemap.width;
|
||||||
char buffer[6] = {0};
|
char buffer[6] = {0};
|
||||||
int x = (i % tilemap.width) * TILE_SIZE;
|
int x = tile_x * TILE_SIZE;
|
||||||
int y = (i / tilemap.width) * TILE_SIZE;
|
int y = tile_y * TILE_SIZE;
|
||||||
sprintf(buffer, "%u", sc_map_size_64v(&tilemap.tiles[i].entities_set));
|
sprintf(buffer, "%u", sc_map_size_64v(&tilemap.tiles[i].entities_set));
|
||||||
|
|
||||||
if (!tilemap.tiles[i].moveable)
|
if (!tilemap.tiles[i].moveable)
|
||||||
|
@ -169,12 +191,21 @@ static void level_scene_render_func(Scene_t* scene)
|
||||||
DrawRectangleLinesEx((Rectangle){x, y, TILE_SIZE, TILE_SIZE}, 2.0, ColorAlpha(BLUE, 0.5));
|
DrawRectangleLinesEx((Rectangle){x, y, TILE_SIZE, TILE_SIZE}, 2.0, ColorAlpha(BLUE, 0.5));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
char buffer[64] = {0};
|
char buffer[64] = {0};
|
||||||
sc_map_foreach_value(&scene->ent_manager.entities, p_ent)
|
sc_map_foreach_value(&scene->ent_manager.entities, p_ent)
|
||||||
{
|
{
|
||||||
CTransform_t* p_ct = get_component(p_ent, CTRANSFORM_COMP_T);
|
CTransform_t* p_ct = get_component(p_ent, CTRANSFORM_COMP_T);
|
||||||
CBBox_t* p_bbox = get_component(p_ent, CBBOX_COMP_T);
|
CBBox_t* p_bbox = get_component(p_ent, CBBOX_COMP_T);
|
||||||
|
|
||||||
|
if (
|
||||||
|
p_ct->position.x < min.x * tilemap.tile_size
|
||||||
|
|| p_ct->position.x + p_bbox->size.x > max.x * tilemap.tile_size
|
||||||
|
|| p_ct->position.y < min.y * tilemap.tile_size
|
||||||
|
|| p_ct->position.y + p_bbox->size.y > max.y * tilemap.tile_size
|
||||||
|
) continue;
|
||||||
|
|
||||||
Color colour;
|
Color colour;
|
||||||
switch(p_ent->m_tag)
|
switch(p_ent->m_tag)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue