Only render objects on screen
This commit is contained in:
19
game/main.c
19
game/main.c
@@ -12,6 +12,7 @@
|
||||
#include "map_layers.h"
|
||||
#include "buildings.h"
|
||||
#include "ui_widgets.h"
|
||||
#include "utils.h"
|
||||
|
||||
#include "pathfinding.h"
|
||||
#include "sounds.h"
|
||||
@@ -376,8 +377,9 @@ static void renderGame(Game *game, float dt) {
|
||||
i32 numDraws = ecs_query_entity_count(game->drawQuery);
|
||||
DrawData *drawData = bzStackAlloc(&game->stackAlloc, numDraws * sizeof(*drawData));
|
||||
ecs_iter_t it = ecs_query_iter(ECS, game->drawQuery);
|
||||
ecs_entity_t worker = 0;
|
||||
i32 drawIdx = 0;
|
||||
Camera2D camera = game->camera;
|
||||
Rectangle camBounds = getCameraBounds(camera);
|
||||
while (ecs_iter_next(&it)) {
|
||||
Position *p = ecs_field(&it, Position, 1);
|
||||
Size *s = ecs_field(&it, Size, 2);
|
||||
@@ -385,12 +387,17 @@ static void renderGame(Game *game, float dt) {
|
||||
TextureRegion *t = ecs_field(&it, TextureRegion, 4);
|
||||
for (i32 i = 0; i < it.count; i++) {
|
||||
Rectangle dst = {p[i].x, p[i].y, s[i].x, s[i].y};
|
||||
if (dst.width == 10 && dst.height == 10) {
|
||||
worker = it.entities[i];
|
||||
}
|
||||
Vector2 origin = {dst.width * 0.5f, dst.height};
|
||||
dst.x += origin.x - dst.width * 0.5f;
|
||||
dst.y += origin.y - dst.height * 0.5f;
|
||||
Rectangle collider = {
|
||||
p[i].x - s[i].x * 0.5f,
|
||||
p[i].y - s[i].y * 0.5f,
|
||||
.width = s[i].x,
|
||||
.height = s[i].y
|
||||
};
|
||||
if (!CheckCollisionRecs(camBounds, collider))
|
||||
continue;
|
||||
Rectangle src = t[i].rec;
|
||||
// Fixes texture bleeding issue
|
||||
src.x += 0.01f;
|
||||
@@ -417,7 +424,7 @@ static void renderGame(Game *game, float dt) {
|
||||
drawData[drawIdx++] = draw;
|
||||
}
|
||||
}
|
||||
BZ_ASSERT(drawIdx == numDraws);
|
||||
numDraws = drawIdx;
|
||||
qsort(drawData, numDraws, sizeof(*drawData), cmpDrawData);
|
||||
|
||||
Texture2D tex = game->tileset.tiles;
|
||||
@@ -450,6 +457,7 @@ static void renderGame(Game *game, float dt) {
|
||||
elapsed += dt * 2;
|
||||
elapsed = Clamp(elapsed, 0, 1.0f);
|
||||
attack = false;
|
||||
#if 0
|
||||
if (worker && false) {
|
||||
Position *pos = ecs_get_mut(ECS, worker, Position);
|
||||
DrawCircle(pos->x, pos->y, 2.0f, BLUE);
|
||||
@@ -463,6 +471,7 @@ static void renderGame(Game *game, float dt) {
|
||||
*rot = targetRot * bzEase(BZ_EASE_IN_BACK, elapsed);
|
||||
bzLogInfo("%.2f", Vector2Angle(*pos, lockedTarget) * RAD2DEG);
|
||||
}
|
||||
#endif
|
||||
|
||||
ecs_progress(ECS, dt);
|
||||
ecs_enable(ECS, renderDebugPathSystem, game->debug.drawPath);
|
||||
|
||||
Reference in New Issue
Block a user