Skip to content

Commit

Permalink
Revert "Shape Collision data ordering"
Browse files Browse the repository at this point in the history
  • Loading branch information
AustinEast authored Jan 10, 2024
1 parent 4fa1f14 commit 88284b1
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 26 deletions.
6 changes: 3 additions & 3 deletions echo/Shape.hx
Original file line number Diff line number Diff line change
Expand Up @@ -206,11 +206,11 @@ class Shape #if cog implements cog.IComponent #end {

public function collides(s:Shape):Null<CollisionData> return null;

function collide_rect(r:Rect, flip:Bool = false):Null<CollisionData> return null;
function collide_rect(r:Rect):Null<CollisionData> return null;

function collide_circle(c:Circle, flip:Bool = false):Null<CollisionData> return null;
function collide_circle(c:Circle):Null<CollisionData> return null;

function collide_polygon(p:Polygon, flip:Bool = false):Null<CollisionData> return null;
function collide_polygon(p:Polygon):Null<CollisionData> return null;

function toString() {
var s = switch (type) {
Expand Down
11 changes: 4 additions & 7 deletions echo/shape/Circle.hx
Original file line number Diff line number Diff line change
Expand Up @@ -87,16 +87,13 @@ class Circle extends Shape implements Poolable {
return false;
}

// collision calculated as s against this. So flip result
override inline function collides(s:Shape):Null<CollisionData> return s.collide_circle(this, true);
override inline function collides(s:Shape):Null<CollisionData> return s.collide_circle(this);

// collision calculated as r against this. So invert flip value
override inline function collide_rect(r:Rect, flip:Bool = false):Null<CollisionData> return r.rect_and_circle(this, !flip);
override inline function collide_rect(r:Rect):Null<CollisionData> return r.rect_and_circle(this, true);

// collision calculated as c against this. So invert flip value
override inline function collide_circle(c:Circle, flip:Bool = false):Null<CollisionData> return c.circle_and_circle(this, !flip);
override inline function collide_circle(c:Circle):Null<CollisionData> return c.circle_and_circle(this);

override inline function collide_polygon(p:Polygon, flip:Bool = false):Null<CollisionData> return this.circle_and_polygon(p, flip);
override inline function collide_polygon(p:Polygon):Null<CollisionData> return this.circle_and_polygon(p, true);

// getters
inline function get_radius():Float return local_radius * scale_x;
Expand Down
13 changes: 5 additions & 8 deletions echo/shape/Polygon.hx
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import echo.shape.*;
import echo.util.AABB;
import echo.util.Poolable;

using echo.math.Vector2;
using echo.util.SAT;
using echo.math.Vector2;

class Polygon extends Shape implements Poolable {
/**
Expand Down Expand Up @@ -197,16 +197,13 @@ class Polygon extends Shape implements Poolable {
return false;
}

// collision calculated as s against this. So flip result
override inline function collides(s:Shape):Null<CollisionData> return s.collide_polygon(this, true);
override inline function collides(s:Shape):Null<CollisionData> return s.collide_polygon(this);

// collision calculated as r against this. So invert flip value
override inline function collide_rect(r:Rect, flip:Bool = false):Null<CollisionData> return r.rect_and_polygon(this, !flip);
override inline function collide_rect(r:Rect):Null<CollisionData> return r.rect_and_polygon(this, true);

// collision calculated as c against this. So invert flip value
override inline function collide_circle(c:Circle, flip:Bool = false):Null<CollisionData> return c.circle_and_polygon(this, !flip);
override inline function collide_circle(c:Circle):Null<CollisionData> return c.circle_and_polygon(this);

override inline function collide_polygon(p:Polygon, flip:Bool = false):Null<CollisionData> return this.polygon_and_polygon(p, flip);
override inline function collide_polygon(p:Polygon):Null<CollisionData> return p.polygon_and_polygon(this, true);

override inline function get_top():Float {
if (count == 0 || vertices[0] == null) return y;
Expand Down
15 changes: 7 additions & 8 deletions echo/shape/Rect.hx
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package echo.shape;

import echo.data.Data;
import echo.math.Vector2;
import echo.shape.*;
import echo.util.AABB;
import echo.shape.*;
import echo.util.Poolable;
import echo.data.Data;
import echo.math.Vector2;

using echo.util.SAT;

Expand Down Expand Up @@ -174,14 +174,13 @@ class Rect extends Shape implements Poolable {
return false;
}

// collision calculated as s against this. So flip result
override inline function collides(s:Shape):Null<CollisionData> return s.collide_rect(this, true);
override inline function collides(s:Shape):Null<CollisionData> return s.collide_rect(this);

override inline function collide_rect(r:Rect, flip:Bool = false):Null<CollisionData> return this.rect_and_rect(r, flip);
override inline function collide_rect(r:Rect):Null<CollisionData> return r.rect_and_rect(this);

override inline function collide_circle(c:Circle, flip:Bool = false):Null<CollisionData> return this.rect_and_circle(c, flip);
override inline function collide_circle(c:Circle):Null<CollisionData> return this.rect_and_circle(c);

override inline function collide_polygon(p:Polygon, flip:Bool = false):Null<CollisionData> return this.rect_and_polygon(p, flip);
override inline function collide_polygon(p:Polygon):Null<CollisionData> return this.rect_and_polygon(p);

override function set_parent(?body:Body) {
super.set_parent(body);
Expand Down

0 comments on commit 88284b1

Please sign in to comment.