mirror of
				https://github.com/zenorogue/hyperrogue.git
				synced 2025-10-31 05:52:59 +00:00 
			
		
		
		
	render entities only if visible
This commit is contained in:
		| @@ -116,6 +116,8 @@ struct entity { | |||||||
|   double gwhere_x, gwhere_y; |   double gwhere_x, gwhere_y; | ||||||
|   double gvel_x, gvel_y; |   double gvel_x, gvel_y; | ||||||
|  |  | ||||||
|  |   bool visible(room *r); | ||||||
|  |  | ||||||
|   void clearg() { |   void clearg() { | ||||||
|     gwhere_x = where_x; |     gwhere_x = where_x; | ||||||
|     gwhere_y = where_y; |     gwhere_y = where_y; | ||||||
|   | |||||||
| @@ -16,6 +16,12 @@ bbox entity::get_pixel_bbox_at(double x, double y) { | |||||||
|   return b; |   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() { | void entity::apply_grav() { | ||||||
|  |  | ||||||
|   if(non_hyperbolic) return apply_portal_grav(); |   if(non_hyperbolic) return apply_portal_grav(); | ||||||
|   | |||||||
| @@ -94,8 +94,21 @@ bbox join(bbox a, bbox b) { | |||||||
|   return r; |   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) { | 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) { | void print(hstream& hs, const bbox& b) { | ||||||
|   | |||||||
| @@ -245,7 +245,9 @@ void man::draw() { | |||||||
| void render_room_objects(room *r) { | void render_room_objects(room *r) { | ||||||
|   initquickqueue(); |   initquickqueue(); | ||||||
|   if(r == current_room) m.draw(); |   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(); |   quickqueue(); | ||||||
|   } |   } | ||||||
|  |  | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 Zeno Rogue
					Zeno Rogue