forked from RPTools/maptool
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#49: Add proper pathfinding taking VBL into account
- More progress on A* - Added Terrain Modifiers calculation and option on Token properties - WIP on multi threading... Task-Url: #49 Signed-off-by: Jamz <[email protected]>
- Loading branch information
1 parent
3a8b4a2
commit c3e5a7a
Showing
21 changed files
with
677 additions
and
451 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
119 changes: 119 additions & 0 deletions
119
src/main/java/net/rptools/maptool/client/ui/zone/RenderPathWorker.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
/* | ||
* This software Copyright by the RPTools.net development team, and licensed under the Affero GPL Version 3 or, at your option, any later version. | ||
* | ||
* MapTool Source Code is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License * along with this source Code. If not, please visit <http://www.gnu.org/licenses/> and specifically the Affero license text | ||
* at <http://www.gnu.org/licenses/agpl.html>. | ||
*/ | ||
package net.rptools.maptool.client.ui.zone; | ||
|
||
import java.awt.Graphics2D; | ||
import java.util.List; | ||
|
||
import javax.swing.SwingWorker; | ||
|
||
import org.apache.logging.log4j.LogManager; | ||
import org.apache.logging.log4j.Logger; | ||
|
||
import net.rptools.maptool.client.ui.zone.ZoneRenderer.SelectionSet; | ||
import net.rptools.maptool.client.walker.ZoneWalker; | ||
import net.rptools.maptool.model.CellPoint; | ||
import net.rptools.maptool.model.Path; | ||
import net.rptools.maptool.model.TokenFootprint; | ||
|
||
public class RenderPathWorker extends SwingWorker<Void, Void> { | ||
private static final Logger log = LogManager.getLogger(RenderPathWorker.class); | ||
|
||
ZoneRenderer zoneRenderer; | ||
Graphics2D g; | ||
ZoneWalker walker; | ||
TokenFootprint footprint; | ||
public static boolean isWorking = false; | ||
public static boolean cancel = false; | ||
Path<CellPoint> path; | ||
CellPoint startPoint, endPoint; | ||
boolean setWaypoint = false; | ||
private boolean restrictMovement = false; | ||
int doSomeWork = 0; | ||
|
||
long start = System.currentTimeMillis(); | ||
|
||
RenderPathWorker(ZoneRenderer zoneRenderer, Graphics2D g, ZoneWalker walker, TokenFootprint footprint) { | ||
this.zoneRenderer = zoneRenderer; | ||
this.g = g; | ||
this.walker = walker; | ||
this.footprint = footprint; | ||
} | ||
|
||
RenderPathWorker(ZoneWalker walker, CellPoint startPoint, CellPoint endPoint) { | ||
this.walker = walker; | ||
this.startPoint = startPoint; | ||
this.endPoint = endPoint; | ||
doSomeWork = 1; | ||
} | ||
|
||
public RenderPathWorker(ZoneWalker walker, CellPoint endPoint, boolean restrictMovement) { | ||
this.walker = walker; | ||
this.endPoint = endPoint; | ||
doSomeWork = 2; | ||
this.restrictMovement = restrictMovement; | ||
} | ||
|
||
@Override | ||
protected Void doInBackground() throws Exception { | ||
log.info("start RenderPathWorker: " + (System.currentTimeMillis() - start) + "ms"); | ||
// log.info("Worker working!"); | ||
isWorking = true; | ||
RenderPathWorker something = this; | ||
while (!isCancelled()) { | ||
Thread.sleep(20); | ||
if ((System.currentTimeMillis() - start) > 500) | ||
break; | ||
} | ||
log.info("\n\nwas cancelled: " + isCancelled()); | ||
// log.info("something? " + (something == null)); | ||
|
||
if (doSomeWork == 1) { | ||
walker.setWaypoints(startPoint, endPoint); | ||
} else if (doSomeWork == 2) { | ||
walker.replaceLastWaypoint(endPoint, restrictMovement); | ||
} else { | ||
path = walker.getPath(this); // walker.getPath() is where the real magic happens! | ||
log.info("Time for walker.getPath(): " + (System.currentTimeMillis() - start) + "ms"); | ||
process(null); | ||
} | ||
|
||
// ZoneRenderer.setRenderedPath(walker.getPath(something)); | ||
// this.cancel(false); | ||
// zoneRenderer.renderPath(g, path, footprint); | ||
// log.info("renderPathWorker.isCancelled? " + isCancelled()); | ||
|
||
// while (!this.isCancelled()) { | ||
// //log.info("Swingworker waiting..."); | ||
// } | ||
|
||
return null; | ||
} | ||
|
||
@Override | ||
protected void process(List<Void> v) { | ||
// ZoneRenderer.setRenderedPath(path); | ||
zoneRenderer.renderPath(g, path, footprint); // invokes UI thread? | ||
log.info("process renderPath done: " + (System.currentTimeMillis() - start) + "ms"); | ||
} | ||
|
||
// This is invoked in the UI thread! | ||
@Override | ||
protected void done() { | ||
isWorking = false; | ||
cancel = false; | ||
// log.info("Swingworker done! calling renderPath: " + (System.currentTimeMillis() - start) + "ms"); | ||
// zoneRenderer.renderPath(g, path, footprint); | ||
// ZoneRenderer.setRenderedPath(path); | ||
|
||
// isStarted = false; | ||
log.info("Time for RenderPathWorker: " + (System.currentTimeMillis() - start) + "ms"); | ||
} | ||
|
||
} |
Oops, something went wrong.