changeset 5:6f455ef24063

fixed world wrap
author zzzzrrr <mason.green@gmail.com>
date Sat, 21 Mar 2009 15:51:41 -0400
parents 8d7c50415269
children eb6059f7035a
files build-dmd-win.bat main.d melee.d orz.d render.d ship.d urQuan.d
diffstat 7 files changed, 66 insertions(+), 65 deletions(-) [+]
line wrap: on
line diff
--- a/build-dmd-win.bat	Fri Mar 20 17:00:30 2009 -0400
+++ b/build-dmd-win.bat	Sat Mar 21 15:51:41 2009 -0400
@@ -1,3 +1,3 @@
-jake -I.. -I../blaze -I../xf/ext zlib.lib -inline -release -O main.d
-::rebuild -I.. -I../blaze -I../xf/ext zlib.lib -inline -release -O main.d
+::jake -I.. -I../blaze -I../xf/ext zlib.lib -inline -release -O main.d
+rebuild -I.. -I../blaze -I../xf/ext zlib.lib -inline -release -O main.d
 
--- a/main.d	Fri Mar 20 17:00:30 2009 -0400
+++ b/main.d	Sat Mar 21 15:51:41 2009 -0400
@@ -79,12 +79,7 @@
     bool running = true;
 
     jobHub.addPreFrameJob( {
-        // Clean out the kill list
-        uint[] key = whut.wrapList.keys;
-        foreach(k; key) {
-            //bzVec2 p = whut.wrapList[key].position;            
-            whut.wrapList.remove(k);
-        }
+        
     });
 
     jobHub.addPostFrameJob( {
--- a/melee.d	Fri Mar 20 17:00:30 2009 -0400
+++ b/melee.d	Sat Mar 21 15:51:41 2009 -0400
@@ -29,6 +29,8 @@
  */
 module openmelee.melee;
 
+import tango.io.Stdout: Stdout;
+
 import Integer = tango.text.convert.Integer;
 import tango.math.Math;
 import tango.math.random.Kiss;
@@ -95,7 +97,7 @@
     bool drawJoints = true;
     bool drawControllers;
     bool drawCoreShapes;
-    bool drawAABBs = true;
+    bool drawAABBs;
     bool drawOBBs;
     bool drawPairs;
     bool drawContactPoints;
@@ -158,12 +160,12 @@
 	this(Settings *settings)
 	{
 		this.settings = settings;
-		init();
 		spawnRect = vec2(INIT_SPAWN_SIZE, INIT_SPAWN_SIZE);
 		// bzWorld boundary callback
 		m_boundaryListener = new BoundaryListener(this);
 		// bzContact callback
 		m_contactListener = new ContactListener(this);
+        init();
 	}
 
 	void init() {
@@ -190,34 +192,37 @@
 
 	EventHandling onKey(KeyboardEvent e)
 	{
-		if (e.unicode == '+') {         // HACK: the windows input writer doesn't do plus correctly yet   - h3
-			e.keySym = KeySym.plus;
-		}
+        // Key pressed
 		if (e.down) {
 			switch (e.keySym) {
+            case KeySym.space:
+                settings.drawAABBs = !settings.drawAABBs;
+                break;
 			case KeySym.Escape:
                 quit = true;
                 break;
+            case KeySym.Up:            
+                thrust = true;
+                break;
+            case KeySym.Left:            
+                ship1.turnLeft();
+                break;
+            case KeySym.Right:             
+                ship1.turnRight();
+                break;
+            case KeySym.Down:             
+                break;
 			default:
-			    char key = cast(char) e.keySym;
-			    if(key == 'w') {
-			        thrust = true;
-			        break;
-			    } else {
-			        ship1.turn(key);
-			    }
 				break;
 			}
         // Key released
 		} else {
-		    char key = cast(char) e.keySym;
-		    if(key == 'w') {
+		    if(e.keySym == KeySym.Up) {
 		         thrust = false;
-		    } else if (key == 'd' || key == 'a') {
+		    } else if (e.keySym == KeySym.Left || e.keySym == KeySym.Right) {
                 ship1.rBody.angularVelocity = 0.0f;
             }
 		}
-
 		return EventHandling.Stop;
 	}
 
@@ -266,8 +271,21 @@
 
 	void boundaryViolated(bzBody rBody)
 	{
-        uint key = rBody.toHash();
-        wrapList[key] = rBody;
+        float x,y;
+        
+        if(rBody.position.x > worldAABB.upperBound.x) {
+            x = worldAABB.lowerBound.x + 5;
+            rBody.position = bzVec2(x, rBody.position.y);
+        } else if (rBody.position.x < worldAABB.lowerBound.x) {
+            x = worldAABB.upperBound.x - 5;
+            rBody.position = bzVec2(x, rBody.position.y);
+        } else if (rBody.position.y > worldAABB.upperBound.y) {
+            y = worldAABB.lowerBound.y + 5;
+            rBody.position = bzVec2(rBody.position.x, y);
+        } else if(rBody.position.y < worldAABB.lowerBound.y) {
+            y = worldAABB.upperBound.y - 5;
+            rBody.position = bzVec2(rBody.position.x, y);
+        }
 	}
 
 	bool quit;
@@ -276,7 +294,6 @@
 	float zoom = 40;
 	int pointCount;
 	vec2 viewCenter;
-    bzBody[uint] wrapList;
 
 	bzWorld world;
 	Settings *settings;
--- a/orz.d	Fri Mar 20 17:00:30 2009 -0400
+++ b/orz.d	Sat Mar 21 15:51:41 2009 -0400
@@ -55,9 +55,10 @@
         auto bodyDef = new bzBodyDef;
         bodyDef.position = bzVec2(10,10);
         bodyDef.angle = PI/2;
+        bodyDef.allowFreeze = false;
 
-        super.rBody = world.createBody(bodyDef);
-
+        auto rBody = world.createBody(bodyDef);
+        super(rBody);
         float density = 2.0f;
 
         // Body
@@ -67,7 +68,7 @@
         b.vertices[1] = bzVec2(-28,21) * scale;
         b.vertices[2] = bzVec2(-28,-28) * scale;
         b.vertices[3] = bzVec2(42,-21) * scale;
-        super.shapes.add(rBody.createShape(b));
+        shapes.add(rBody.createShape(b));
 
         // Top Wing
         auto tWing = new bzPolyDef(density);
@@ -77,7 +78,7 @@
         tWing.vertices[2] = bzVec2(-49,63) * scale;
         tWing.vertices[1] = bzVec2(70,14) * scale;
         tWing.vertices[0] = bzVec2(42,14) * scale;
-        super.shapes.add(rBody.createShape(tWing));
+        shapes.add(rBody.createShape(tWing));
 
         // Bottom Wing
         auto bWing = new bzPolyDef(density);
@@ -87,9 +88,9 @@
         bWing.vertices[2] = bzVec2(-49,-63) * scale;
         bWing.vertices[3] = bzVec2(70,-21) * scale;
         bWing.vertices[4] = bzVec2(42,-21) * scale;
-        super.shapes.add(rBody.createShape(bWing));
+        shapes.add(rBody.createShape(bWing));
 
-        super.rBody.setMassFromShapes();
+        rBody.setMassFromShapes();
 
     }
 }
--- a/render.d	Fri Mar 20 17:00:30 2009 -0400
+++ b/render.d	Sat Mar 21 15:51:41 2009 -0400
@@ -535,7 +535,7 @@
         bzVec2 invQ;
         invQ.set(1.0f / bp.m_quantizationFactor.x, 1.0f / bp.m_quantizationFactor.y);
         color = Color(1.0f, 1.0f, 1.0f);
-        /*
+        
         for (int i = 0; i < k_maxProxies; ++i) {
             bzProxy p = bp.m_proxyPool[i];
             if (!p.isValid) {
@@ -556,7 +556,7 @@
 
             drawPolygon(gl, vs, color);
         }
-        */
+        
         vec2 vs[4];
         vs[0] = vec2(worldLower.x, worldLower.y);
         vs[1] = vec2(worldUpper.x, worldLower.y);
@@ -653,16 +653,6 @@
             drawXForm(gl, xf);
         }
     }
-
-    // Nonphysical stuffs
-    // Universal '.' cursor
-    gl.Color3f(1, 1, 1);
-    gl.immediate(GL_POINTS,
-    {
-        gl.Vertex2fv(mousePos.ptr);
-    });
-
-    pointCount = 0;
 }
 
 }
--- a/ship.d	Fri Mar 20 17:00:30 2009 -0400
+++ b/ship.d	Sat Mar 21 15:51:41 2009 -0400
@@ -48,7 +48,8 @@
     bzVec2 leftTurnPoint;
     bzVec2 rightTurnPoint;
 
-    this() {
+    this(bzBody rBody) {
+        this.rBody = rBody;
         shapes = new ShapeList;
     }
 
@@ -56,18 +57,13 @@
         rBody.force += engineForce.rotate(rBody.angle);
     }
 
-    void turn(char key) {
-        switch(key) {
-            case 'd':
-                rBody.torque += bzCross(rightTurnPoint.rotate(rBody.angle), 
+    void turnLeft() {
+        rBody.torque += bzCross(leftTurnPoint.rotate(rBody.angle), 
                                 turnForce.rotate(rBody.angle));
-                break;
-            case 'a':
-                rBody.torque += bzCross(leftTurnPoint.rotate(rBody.angle), 
+    }
+    
+    void turnRight() {
+        rBody.torque += bzCross(rightTurnPoint.rotate(rBody.angle), 
                                 turnForce.rotate(rBody.angle));
-                break;
-            default:
-                break;
-        }
     }
 }
--- a/urQuan.d	Fri Mar 20 17:00:30 2009 -0400
+++ b/urQuan.d	Sat Mar 21 15:51:41 2009 -0400
@@ -47,7 +47,9 @@
 
         auto bodyDef = new bzBodyDef;
         bodyDef.position = bzVec2(10,5);
-        super.rBody = world.createBody(bodyDef);
+        bodyDef.allowFreeze = false;
+        auto rBody = world.createBody(bodyDef);
+        super(rBody);
         float density = 2.0f;
 
         // Head
@@ -61,7 +63,7 @@
         head.vertices[3] = bzVec2(70,-49) * scale;
         head.vertices[2] = bzVec2(63,-56) * scale;
         head.vertices[1] = bzVec2(42,-56) * scale;
-        super.shapes.add(rBody.createShape(head));
+        shapes.add(rBody.createShape(head));
 
         // Body
         auto b = new bzPolyDef(density);
@@ -70,7 +72,7 @@
         b.vertices[3] = bzVec2(-70,24.5) * scale;
         b.vertices[2] = bzVec2(42,24.5) * scale;
         b.vertices[1] = bzVec2(42,-31.5) * scale;
-        super.shapes.add(rBody.createShape(b));
+        shapes.add(rBody.createShape(b));
 
         // Top Strut
         auto tStrut = new bzPolyDef(density);
@@ -79,7 +81,7 @@
         tStrut.vertices[3] = bzVec2(-28,24.5) * scale;
         tStrut.vertices[2] = bzVec2(-28,42) * scale;
         tStrut.vertices[1] = bzVec2(0,42) * scale;
-        super.shapes.add(rBody.createShape(tStrut));
+        shapes.add(rBody.createShape(tStrut));
 
         // Top Wing
         auto tWing = new bzPolyDef(density);
@@ -88,7 +90,7 @@
         tWing.vertices[3] = bzVec2(-49,63) * scale;
         tWing.vertices[2] = bzVec2(28,63) * scale;
         tWing.vertices[1] = bzVec2(28,42) * scale;
-        super.shapes.add(rBody.createShape(tWing));
+        shapes.add(rBody.createShape(tWing));
 
         // Bottom Strut
         auto bStrut = new bzPolyDef(density);
@@ -97,7 +99,7 @@
         bStrut.vertices[3] = bzVec2(0,-49) * scale;
         bStrut.vertices[2] = bzVec2(-28,-49) * scale;
         bStrut.vertices[1] = bzVec2(-28,-31.5) * scale;
-        super.shapes.add(rBody.createShape(bStrut));
+        shapes.add(rBody.createShape(bStrut));
 
         // Bottom Wing
         auto bWing = new bzPolyDef(density);
@@ -106,8 +108,8 @@
         bWing.vertices[3] = bzVec2(28,-49) * scale;
         bWing.vertices[2] = bzVec2(28,-70) * scale;
         bWing.vertices[1] = bzVec2(-42,-70) * scale;
-        super.shapes.add(rBody.createShape(bWing));
+        shapes.add(rBody.createShape(bWing));
 
-        super.rBody.setMassFromShapes();
+        rBody.setMassFromShapes();
     }
 }