changeset 15:8e6a9e390cba

Added binary win32 demo
author zzzzrrr <mason.green@gmail.com>
date Tue, 24 Mar 2009 11:06:16 -0400
parents af1e8620f027
children cc494b8f8710
files ai.d main.d melee.d openmelee.geany openmelee.zip ship.d steer.d
diffstat 7 files changed, 68 insertions(+), 48 deletions(-) [+]
line wrap: on
line diff
--- a/ai.d	Mon Mar 23 14:06:47 2009 -0400
+++ b/ai.d	Tue Mar 24 11:06:16 2009 -0400
@@ -51,7 +51,7 @@
 	
 	void move(Ship enemy) {
 	    
-        // Ver stupid, elementary AI so far...
+        // Elementary steering AI 
         
 	    steer.update();
 	    bzVec2 st;
@@ -79,7 +79,7 @@
 		}
 		
 		float range = (ship.state.position - enemy.state.position).length; 
-		if(range > 10 && abs(angle) < PI/4) {
+		if(range > 2 && abs(angle) < PI/4) {
 			ship.thrust();
 		}
     }
--- a/main.d	Mon Mar 23 14:06:47 2009 -0400
+++ b/main.d	Tue Mar 24 11:06:16 2009 -0400
@@ -77,23 +77,29 @@
     StopWatch timer;
 
     jobHub.addRepeatableJob( {
+        
+        // Update AI
+        ai.move(whut.ship1);
+        
         // Update physics
         whut.world.step(timeStep, settings.velocityIterations,
                         settings.positionIterations);
-        // Update AI
-        ai.move(whut.ship1);
+        
+        // Limit velocity
+        whut.ship1.limitVelocity();
+        whut.ship2.limitVelocity();
+        whut.ship1.updateState();
+        whut.ship2.updateState();
+        
     }, ITERS_PER_SECOND);
 
     bool running = true;
 
     jobHub.addPreFrameJob( {
-        whut.ship1.limitVelocity();
-        whut.ship2.limitVelocity();
-        whut.ship1.updateState();
-        whut.ship2.updateState();
     });
 
     jobHub.addPostFrameJob( {
+        
         gui.begin(cfg);
         gui.push(`main`);
         if (gui().getProperty!(bool)("frame.closeClicked")) {
--- a/melee.d	Mon Mar 23 14:06:47 2009 -0400
+++ b/melee.d	Tue Mar 24 11:06:16 2009 -0400
@@ -276,7 +276,7 @@
         } else if(rBody.position.y < worldAABB.lowerBound.y) {
             y = worldAABB.upperBound.y - 5;
             rBody.position = bzVec2(rBody.position.x, y);
-        }
+        }        
 	}
 
 	bool quit;
--- a/openmelee.geany	Mon Mar 23 14:06:47 2009 -0400
+++ b/openmelee.geany	Tue Mar 24 11:06:16 2009 -0400
@@ -14,14 +14,21 @@
 run_cmd=
 
 [files]
-current_page=5
-FILE_NAME_0=3145;D;0;16;0;1;1;C:\\workspace\\openmelee\\main.d;0
-FILE_NAME_1=1648;D;0;16;0;1;1;C:\\workspace\\openmelee\\melee.d;0
-FILE_NAME_2=1648;D;0;16;0;1;1;C:\\workspace\\openmelee\\orz.d;0
-FILE_NAME_3=10638;D;0;16;0;1;1;C:\\workspace\\openmelee\\render.d;0
-FILE_NAME_4=1648;D;0;16;0;1;1;C:\\workspace\\openmelee\\ship.d;0
-FILE_NAME_5=2349;D;0;16;0;1;1;C:\\workspace\\openmelee\\steer.d;0
-FILE_NAME_6=1648;D;0;16;0;1;1;C:\\workspace\\openmelee\\urQuan.d;0
+current_page=14
+FILE_NAME_0=3621;D;0;16;0;1;1;C:\\workspace\\openmelee\\main.d;0
+FILE_NAME_1=7216;D;0;16;0;1;1;C:\\workspace\\openmelee\\melee.d;0
+FILE_NAME_2=2248;D;0;16;0;1;1;C:\\workspace\\openmelee\\orz.d;0
+FILE_NAME_3=9747;D;0;16;0;1;1;C:\\workspace\\openmelee\\render.d;0
+FILE_NAME_4=2600;D;0;16;0;1;1;C:\\workspace\\openmelee\\ship.d;0
+FILE_NAME_5=5704;D;0;16;0;1;1;C:\\workspace\\openmelee\\steer.d;0
+FILE_NAME_6=2250;D;0;16;0;1;1;C:\\workspace\\openmelee\\urQuan.d;0
 FILE_NAME_7=147;None;0;16;0;1;1;C:\\workspace\\openmelee\\build-dmd-win.bat;0
 FILE_NAME_8=304;Conf;0;16;0;1;0;C:\\workspace\\openmelee\\gui.cfg;0
 FILE_NAME_9=1648;D;0;16;0;1;0;C:\\workspace\\openmelee\\planet.d;0
+FILE_NAME_10=2031;D;0;16;0;1;1;C:\\workspace\\openmelee\\ai.d;0
+FILE_NAME_11=13893;D;0;16;0;1;1;C:\\Documents and Settings\\greenma3\\workspace\\blaze\\blaze\\dynamics\\bzIsland.d;0
+FILE_NAME_12=17007;D;0;16;0;1;1;C:\\Documents and Settings\\greenma3\\workspace\\blaze\\blaze\\dynamics\\bzBody.d;0
+FILE_NAME_13=29005;D;0;16;0;1;1;C:\\workspace\\blaze\\blaze\\bzWorld.d;0
+FILE_NAME_14=22084;D;0;16;0;1;1;C:\\workspace\\blaze\\blaze\\dynamics\\bzBody.d;0
+FILE_NAME_15=8520;D;0;16;0;1;1;C:\\workspace\\blaze\\blaze\\collision\\shapes\\bzShape.d;0
+FILE_NAME_16=12632;D;0;16;0;1;1;C:\\workspace\\blaze\\blaze\\collision\\shapes\\bzPolygon.d;0
Binary file openmelee.zip has changed
--- a/ship.d	Mon Mar 23 14:06:47 2009 -0400
+++ b/ship.d	Tue Mar 24 11:06:16 2009 -0400
@@ -71,7 +71,10 @@
     bzVec2 rightTurnPoint;
 	State state;
 	
-    float maxLinVel = 100;
+    float battery;
+    float crew;
+    
+    float maxLinVel = 50;
     float maxAngVel = 2;
     
     this(bzWorld world) {
@@ -99,7 +102,7 @@
     void setPlanetGravity() {
         float minRadius = 0.1;
         float maxRadius = 10;
-        float strength = 3.5;
+        float strength = 4.0;
         bzVec2 center = bzVec2(0,0);
         auto attractor = new bzAttractor(rBody, center, strength, minRadius, maxRadius);
         world.addForce(attractor);
--- a/steer.d	Mon Mar 23 14:06:47 2009 -0400
+++ b/steer.d	Tue Mar 24 11:06:16 2009 -0400
@@ -33,6 +33,8 @@
 module openmelee.steer;
 
 import blaze.common.bzMath: bzDot, bzClamp, bzVec2;
+import blaze.dynamics.bzBody: bzBody;
+
 import openmelee.ship : Ship, State;
 import openmelee.utilities;
 
@@ -42,6 +44,15 @@
     this (Ship ship)
     {
         m_ship = ship;
+    }
+    
+	struct PathIntersection
+    {
+        bool intersect;
+        float distance;
+        bzVec2 surfacePoint;
+        bzVec2 surfaceNormal;
+        bzBody obstacle;
     }
 
     // reset state
@@ -116,53 +127,46 @@
         return avoidance;
     }
 
-    // avoids all obstacles in an ObstacleGroup
-
-    bzVec2 steerToAvoidObstacles (float minTimeToCollision, 
-                                  ObstacleGroup obstacles) {
+    // avoids all obstacles in an ObstacleGroup
+    */
+    
+    bzVec2 steerToAvoidObstacles (float minTimeToCollision, bzBody obstacles) {
 
         bzVec2 avoidance;
         PathIntersection nearest, next;
-        float minDistanceToCollision = minTimeToCollision * speed;
+        float minDistanceToCollision = minTimeToCollision * m_speed;
 
         next.intersect = false;
         nearest.intersect = false;
 
         // test all obstacles for intersection with my forward axis,
         // select the one whose point of intersection is nearest
-        for (ObstacleIterator o = obstacles.begin(); o != obstacles.end(); o++)
-        {
-            // xxx this should be a generic call on Obstacle, rather than
-            // xxx this code which presumes the obstacle is spherical
-            findNextIntersectionWithSphere ((SphericalObstacle)**o, next);
+        for (bzBody o; o; o = o.next) {
+            // This code which presumes the obstacle is spherical
+            //findNextIntersectionWithSphere (o, next);
 
-            if ((nearest.intersect == false) ||
-                ((next.intersect != false)
-                 (next.distance < nearest.distance)))
-                nearest = next;
+            if (!nearest.intersect || (next.intersect && next.distance < nearest.distance)) {
+					nearest = next;
+            }
         }
 
         // when a nearest intersection was found
-        if ((nearest.intersect != false)
-            (nearest.distance < minDistanceToCollision))
-        {
-            // show the corridor that was checked for collisions
-            annotateAvoidObstacle (minDistanceToCollision);
-
+        if (nearest.intersect && (nearest.distance < minDistanceToCollision)) {
             // compute avoidance steering force: take offset from obstacle to me,
             // take the component of that which is lateral (perpendicular to my
             // forward direction), set length to maxForce, add a bit of forward
             // component (in capture the flag, we never want to slow down)
-            bzVec2 offset = m_position - nearest.obstacle.center;
-            avoidance = offset.perpendicularComponent (m_forward());
-            avoidance = avoidance.normalize;
-            avoidance *= maxForce;
-            avoidance += m_forward * maxForce * 0.75;
+            bzVec2 offset = m_position - nearest.obstacle.position;
+            //avoidance = Vector3Helpers.PerpendicularComponent(offset, this.Forward);
+            avoidance.normalize;
+            avoidance *= m_maxForce;
+            avoidance += m_forward * m_maxForce * 0.75f;
         }
 
         return avoidance;
     }
-
+
+    /*
     // ------------------------------------------------------------------------
     // Unaligned collision avoidance behavior: avoid colliding with other
     // nearby vehicles moving in unconstrained directions.  Determine which
@@ -178,7 +182,7 @@
 
         // otherwise, go on to consider potential future collisions
         float steer = 0;
-        Ship* threat = NULL;
+        Ship threat;
 
         // Time (in seconds) until the most immediate collision threat found
         // so far.  Initial value is a threshold: don't look more than this
@@ -193,8 +197,8 @@
         // pose the most immediate threat of collision.
         for (AVIterator i = others.begin(); i != others.end(); i++)
         {
-            Ship other = **i;
-            if (other != this)
+            Ship other = i;
+            if (other !is this)
             {
                 // avoid when future positions are this close (or less)
                 float collisionDangerThreshold = radius * 2;