@@ -10,7 +10,6 @@ import (
1010 input "github.com/quasilyte/ebitengine-input"
1111 "github.com/setanarut/kamera/v2"
1212 "github.com/solarlune/dngn"
13- "github.com/solarlune/resolv"
1413 "github.com/yohamta/ganim8/v2"
1514)
1615
@@ -67,19 +66,13 @@ func (g *Game) Draw(screen *ebiten.Image) {
6766 // get the camera bounds in world coords for culling purposes
6867 x1 , y1 := cam .ScreenToWorld (0 , 0 )
6968 x2 , y2 := cam .ScreenToWorld (g .screen_w , g .screen_h )
70- cam_rect := resolv .NewRectangleFromCorners (x1 , y1 , x2 , y2 )
7169
7270 // draw the map
7371 map_select := game_map .Select ()
7472 op := & ebiten.DrawImageOptions {}
7573 for cell := range map_select .Cells {
76- // TODO: create all these rects ONCE on map generation instead of on every frame
77- cell_rect := resolv .NewRectangle (float64 (cell .X * 16 ), float64 (cell .Y * 16 ), 16 , 16 )
78-
7974 // cull (only draw what's actually on-screen to avoid 100% CPU usage)
80- // apparently Intersection() only returns whether the *borders* or the rects intersect w/ each-other
81- // if one is entirely contained by the other, you have to also check IsContainedBy()
82- if cell_rect .IsContainedBy (cam_rect ) || ! cam_rect .Intersection (cell_rect ).IsEmpty () {
75+ if isRectangleOverlap (x1 , y1 , x2 , y2 , float64 (cell .X * 16 ), float64 (cell .Y * 16 ), float64 (cell .X * 16 + 16 ), float64 (cell .Y * 16 + 16 )) {
8376 op .GeoM .Reset ()
8477 op .GeoM .Translate (float64 (cell .X * 16 ), float64 (cell .Y * 16 ))
8578 // smooth anti-aliasing (and so ebitengine batches calls due to identical Filter param)
@@ -159,3 +152,11 @@ func Check(err error) {
159152 panic (err )
160153 }
161154}
155+
156+ func isRectangleOverlap (x1 float64 , y1 float64 , x2 float64 , y2 float64 , x3 float64 , y3 float64 , x4 float64 , y4 float64 ) bool {
157+ // If any of these are true, the rectangles do NOT overlap
158+ if y3 >= y2 || y4 <= y1 || x3 >= x2 || x4 <= x1 {
159+ return false
160+ }
161+ return true
162+ }
0 commit comments