Hi all,
I am a new member to the project, and I wanted to say hello to everyone.
Additionally I had a question about when to branch, and when not to branch.
I would like to make some changes to the code for speed optimizations. The changes would require changing the interface to the PhysicsEngine class. Basically instead of passing in a node at a time, the code would just pass in the list of livingNodes to the onRelax and onUpdate methods. Having the complete list allows the physics engine to optimize how it iterates over the list, and can pass back of list of nodes that are still living/active after the update. I have included a diff of the changes to PhysicsEngine.java below for clarity.
An example of the potential speed up is removing the n^2 algorithm for onRelaxNode in the legacy physics engine. Which would instead look something like:
public LinkedList<code_swarm.FileNode> onRelaxNodes(LinkedList<code_swarm.FileNode> fNodes ) {
Vector2f forceBetweenFiles = new Vector2f();
LinkedList<code_swarm.FileNode> tNodes = new LinkedList<code_swarm.FileNode>();
while (!fNodes.isEmpty())
{
code_swarm.FileNode aNode = fNodes.removeFirst();
for (code_swarm.FileNode bNode : fNodes)
{
forceBetweenFiles = calculateForceBetweenNodes(aNode, bNode);
aNode.addForce(forceBetweenFiles);
forceBetweenFiles.negate();
bNode.addForce(forceBetweenFiles);
}
aNode.applyForce(FORCE_TO_SPEED_MULTIPLIER);
tNodes.addLast(aNode);
}
return tNodes;
}
}
The keen observer will note that this is not exactly the same result as what the PhysicsEngineLegacy would give, but is is much faster, and could be contained in a new PhysicsEngineLegacyFast class. Giving people the options of old slower style vs. new faster, but similar, style.
Additionally instead of filtering all the nodes to find the ones which are still alive, the code_swarm.java code would only add new and freshen'ed nodes to the living node list(s), and allow the PhysicEngine to remove the dead/inactive ones.
There would be some other minor changes to support this, but those are the major ones.
I just wanted to know if people thought this would require a branch.
Sincerely,
Dudley
Index: src/PhysicsEngine.java
===================================================================
--- src/PhysicsEngine.java (revision 273)
+++ src/PhysicsEngine.java (working copy)
@@ -18,6 +18,7 @@
*/
import java.util.Properties;
+import java.util.LinkedList;
import javax.vecmath.Vector2f;
/**
@@ -51,56 +52,74 @@
/**
* Method that allows Physics Engine to modify Speed / Position during the relax phase.
*
- * @param edge the node to which the force apply
+ * @param edges the nodes to which the force apply
*
+ * @return LinkedList<code_swarm.Edge> which is the list of edges which are still active/living
+ * after the relaxing.
+ *
* @Note Standard physics is "Position Variation = Speed x Duration" with a convention of "Duration=1" between to frames
*/
- public void onRelaxEdge(code_swarm.Edge edge);
+ public LinkedList<code_swarm.Edge> onRelaxEdges(LinkedList<code_swarm.Edge> edges);
/**
* Method that allows Physics Engine to modify Speed / Position during the relax phase.
*
- * @param fNode the node to which the force apply
+ * @param fNodes the nodes to which the force apply
*
+ * @return LinkedList<code_swarm.FileNode> which is the list of FileNodes which are still active/living
+ * after the relaxing.
+ *
* @Note Standard physics is "Position Variation = Speed x Duration" with a convention of "Duration=1" between to frames
*/
- public void onRelaxNode(code_swarm.FileNode fNode);
+ public LinkedList<code_swarm.Edge> onRelaxNodes(LinkedList<code_swarm.FileNode> fNodes);
/**
* Method that allows Physics Engine to modify Speed / Position during the relax phase.
*
- * @param pNode the node to which the force apply
+ * @param pNodes the nodes to which the force apply
+ *
+ * @return LinkedList<code_swarm.PersonNode> which is the list of PersonNodes which are still active/living
+ * after the relaxing.
*
* @Note Standard physics is "Position Variation = Speed x Duration" with a convention of "Duration=1" between to frames
*/
- public void onRelaxPerson(code_swarm.PersonNode pNode);
+ public LinkedList<code_swarm.PersonNode> onRelaxPeople(LinkedList<code_swarm.PersonNode> pNodes);
/**
* Method that allows Physics Engine to modify Speed / Position during the update phase.
*
- * @param edge the node to which the force apply
+ * @param edges the nodes to which the force apply
*
+ * @return LinkedList<code_swarm.Edge> which is the list of edges which are still active/living
+ * after the update.
+ *
* @Note Standard physics is "Position Variation = Speed x Duration" with a convention of "Duration=1" between to frames
*/
- public void onUpdateEdge(code_swarm.Edge edge);
+ public LinkedList<code_swarm.Edge> onUpdateEdges(LinkedList<code_swarm.Edge> edges);
/**
* Method that allows Physics Engine to modify Speed / Position during the update phase.
*
* @param fNode the node to which the force apply
*
+ * @return LinkedList<code_swarm.FileNode> which is the list of FileNodes which are still active/living
+ * after the update.
+ *
* @Note Standard physics is "Position Variation = Speed x Duration" with a convention of "Duration=1" between to frames
*/
- public void onUpdateNode(code_swarm.FileNode fNode);
+ public LinkedList<code_swarm.FileNode> onUpdateNodes(LinkedList<code_swarm.FileNode> fNodes);
/**
* Method that allows Physics Engine to modify Speed / Position during the update phase.
*
* @param pNode the node to which the force apply
*
+ * @return LinkedList<code_swarm.PersonNode> which is the list of PersonNodes which are still active/living
+ * after the update.
+ *
* @Note Standard physics is "Position Variation = Speed x Duration" with a convention of "Duration=1" between to frames
*/
- public void onUpdatePerson(code_swarm.PersonNode pNode);
+ public LinkedList<code_swarm.PersonNode> onUpdatePeople(LinkedList<code_swarm.PersonNode> pNodes);
/**
*