From b30389bf8a989dbd0ab9f71ea8f2ca73832b8820 Mon Sep 17 00:00:00 2001 From: Robert Machmer Date: Sat, 9 Jan 2016 11:25:50 +0100 Subject: [PATCH] Add two callback functions to the parameter list of the update function These functions will be called on each and every node and edge in the graph and allow the user to extend the graphs behavior between frames. --- fd/Graph.lua | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/fd/Graph.lua b/fd/Graph.lua index 6b84cb2..db157c6 100644 --- a/fd/Graph.lua +++ b/fd/Graph.lua @@ -115,11 +115,14 @@ function Graph.new() --- -- Updates the graph. -- @param dt - The delta time between frames. + -- @param nodeCallback - A callback called on every node. + -- @param edgeCallback - A callback called on every edge. -- - function self:update( dt ) + function self:update( dt, nodeCallback, edgeCallback ) for _, edge in pairs( edges ) do edge.origin:attractTo( edge.target ); edge.target:attractTo( edge.origin ); + edgeCallback( edge ); end resetBoundaries(); @@ -133,6 +136,7 @@ function Graph.new() end nodeA:move( dt ); end + nodeCallback( nodeA ); minX, maxX, minY, maxY = updateBoundaries( minX, maxX, minY, maxY, nodeA:getPosition() ); end