mirror of
https://github.com/zenorogue/hyperrogue.git
synced 2025-05-10 03:04:06 +00:00
render entities only if visible
This commit is contained in:
parent
3846ff83c3
commit
0797e540d6
@ -116,6 +116,8 @@ struct entity {
|
||||
double gwhere_x, gwhere_y;
|
||||
double gvel_x, gvel_y;
|
||||
|
||||
bool visible(room *r);
|
||||
|
||||
void clearg() {
|
||||
gwhere_x = where_x;
|
||||
gwhere_y = where_y;
|
||||
|
@ -16,6 +16,12 @@ bbox entity::get_pixel_bbox_at(double x, double y) {
|
||||
return b;
|
||||
}
|
||||
|
||||
bool entity::visible(room *r) {
|
||||
auto bb = get_intersect(pixel_to_block(get_pixel_bbox()), room_bb);
|
||||
for(int y = bb.miny; y < bb.maxy; y++) for(int x = bb.minx; x < bb.maxx; x++) if(r->fov[y][x]) return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
void entity::apply_grav() {
|
||||
|
||||
if(non_hyperbolic) return apply_portal_grav();
|
||||
|
@ -94,8 +94,21 @@ bbox join(bbox a, bbox b) {
|
||||
return r;
|
||||
}
|
||||
|
||||
bbox room_bb{0, 0, room_x, room_y};
|
||||
bbox screen_bb{0, 0, screen_x, screen_y};
|
||||
|
||||
bbox get_intersect(bbox a, bbox b) {
|
||||
bbox r;
|
||||
r.minx = max(a.minx, b.minx);
|
||||
r.miny = max(a.miny, b.miny);
|
||||
r.maxx = min(a.maxx, b.maxx);
|
||||
r.maxy = min(a.maxy, b.maxy);
|
||||
return r;
|
||||
}
|
||||
|
||||
bool intersect(bbox a, bbox b) {
|
||||
return max(a.minx, b.minx) < min(a.maxx, b.maxx) && max(a.miny, b.miny) < min(a.maxy, b.maxy);
|
||||
auto g = get_intersect(a, b);
|
||||
return g.minx < g.maxx && g.miny < g.maxy;
|
||||
}
|
||||
|
||||
void print(hstream& hs, const bbox& b) {
|
||||
|
@ -245,7 +245,9 @@ void man::draw() {
|
||||
void render_room_objects(room *r) {
|
||||
initquickqueue();
|
||||
if(r == current_room) m.draw();
|
||||
for(auto& e: r->entities) e->draw();
|
||||
for(auto& e: r->entities)
|
||||
if(e->visible(r))
|
||||
e->draw();
|
||||
quickqueue();
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user