Merge branch 'pi' of 192.168.1.28:artisanlogiciel/code/laby

# Conflicts:
#	build.xml
#	mybuild.xml
This commit is contained in:
philippe lhardy
2020-10-15 17:33:19 +02:00
41 changed files with 2524 additions and 2300 deletions

3
.idea/.gitignore generated vendored Normal file
View File

@@ -0,0 +1,3 @@
# Default ignored files
/shelf/
/workspace.xml

29
.idea/laby.iml generated Normal file
View File

@@ -0,0 +1,29 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/java" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/lang" type="java-resource" />
<excludeFolder url="file://$MODULE_DIR$/artloglaby" />
<excludeFolder url="file://$MODULE_DIR$/autom4te.cache" />
<excludeFolder url="file://$MODULE_DIR$/build" />
<excludeFolder url="file://$MODULE_DIR$/c" />
<excludeFolder url="file://$MODULE_DIR$/classes" />
<excludeFolder url="file://$MODULE_DIR$/deb" />
<excludeFolder url="file://$MODULE_DIR$/debian" />
<excludeFolder url="file://$MODULE_DIR$/dist" />
<excludeFolder url="file://$MODULE_DIR$/documentation" />
<excludeFolder url="file://$MODULE_DIR$/download" />
<excludeFolder url="file://$MODULE_DIR$/java/lab" />
<excludeFolder url="file://$MODULE_DIR$/java/org/artisanlogiciel/games/javafx" />
<excludeFolder url="file://$MODULE_DIR$/lab" />
<excludeFolder url="file://$MODULE_DIR$/scripts" />
<excludeFolder url="file://$MODULE_DIR$/src" />
<excludeFolder url="file://$MODULE_DIR$/workspace" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="artgaphics-0.1.0" level="project" />
</component>
</module>

9
.idea/libraries/artgaphics_0_1_0.xml generated Normal file
View File

@@ -0,0 +1,9 @@
<component name="libraryTable">
<library name="artgaphics-0.1.0">
<CLASSES>
<root url="jar://$PROJECT_DIR$/libs/artgaphics-0.1.0.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</component>

6
.idea/misc.xml generated Normal file
View File

@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="false" project-jdk-name="1.8" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/java/out" />
</component>
</project>

8
.idea/modules.xml generated Normal file
View File

@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/laby.iml" filepath="$PROJECT_DIR$/.idea/laby.iml" />
</modules>
</component>
</project>

6
.idea/vcs.xml generated Normal file
View File

@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="" vcs="Git" />
</component>
</project>

View File

@@ -5,6 +5,14 @@ Il s'agit d'un générateur de labyrinthes écrit en langage java.
Pour le lancer vous devez avoir installé un environnement java 8 ( avec javafx (*) ) Pour le lancer vous devez avoir installé un environnement java 8 ( avec javafx (*) )
racourçi :
sous linux ./laby.sh
sous windows lancez le laby.bat
il s'gait d'un porgramme java qui peut aussi être lancé avec l'interpréteur java ainsi :
java -jar artloglaby-1.0.jar java -jar artloglaby-1.0.jar
mail pl@artisanlogiciel.net mail pl@artisanlogiciel.net
@@ -14,5 +22,6 @@ vous pouvez le distribuer ou bien même le vendre
ses sources sont sur https://github.com/artlog/labystl ses sources sont sur https://github.com/artlog/labystl
( et utilise aussi https://github.com/artlog/sharedrawweb ) ( et utilise aussi https://github.com/artlog/sharedrawweb )
Les labyrinthes que vous sauvegardez le sont dans le répertoire lab.

2
Makefile.am Normal file
View File

@@ -0,0 +1,2 @@
SUBDIRS = c
dist_doc_DATA = README

5
README
View File

@@ -3,7 +3,8 @@ This is a personal project to generate a 2D maze using in depth path generation.
Download the 'latest' laby.zip containing java jar from my blog http://blog.artisanlogiciel.net/public/tech/laby.zip Download the 'latest' laby.zip containing java jar from my blog http://blog.artisanlogiciel.net/public/tech/laby.zip
this can generate a stl file, overall goal was to print it with a 3D printer, i didn't test it yet ( even if i actualy have a 3D printer ). this can generate a stl file, overall goal was to print it with a 3D printer.
After years i finaly printed one maze, find it at https://www.thingiverse.com/thing:2814655
This is the very first usable part. This is the very first usable part.
It was developped under debian 7/8 but since it is java based it might be very easily recompiled or even just copied on other platform. It was developped under debian 7/8 but since it is java based it might be very easily recompiled or even just copied on other platform.
@@ -25,6 +26,8 @@ cd labystl
./init.sh ./init.sh
# will create build scripts from artlog_toolbox # will create build scripts from artlog_toolbox
# ./doit.sh # ./doit.sh
# depends on sharedrawweb for stl export
./fetch_dependencies.sh
ant dist ant dist
source ./specificdoit.sh; create_zip_package source ./specificdoit.sh; create_zip_package
unzip laby.zip; cd artloglaby ; ./laby.sh unzip laby.zip; cd artloglaby ; ./laby.sh

23
bootstrapbuild.sh Executable file
View File

@@ -0,0 +1,23 @@
#!/bin/bash
if [[ ! -f configure.ac ]]
then
echo "[ERROR] Missing configure.ac . Please create one " >&2
exit 1
fi
if which autoreconf
then
echo "bootstrap using automake tools"
echo "from configure.ac will generate configure"
autoreconf --install
echo "lauch ./configure && make"
else
echo "[ERROR] Missing autoreconf script from autotools. Please install autotools ( package autotools-dev and autoreconf" >&2
fi

View File

@@ -10,9 +10,9 @@
<property name="src" location="java"/> <property name="src" location="java"/>
<property name="build" location="build"/> <property name="build" location="build"/>
<property name="dist" location="dist"/> <property name="dist" location="dist"/>
<!-- Fill me please / todo -->
<property name="artgraphicslib" value="artgaphics-0.2.0"/> <property name="artgraphicslib" value="artgaphics-0.2.0"/>
<property name="distversion" value="1.0"/> <property name="distversion" value="1.1"/>
<target name="init"> <target name="init">
<!-- Create the time stamp --> <!-- Create the time stamp -->
@@ -26,6 +26,7 @@
<!-- Compile the java code from ${src} into ${build} --> <!-- Compile the java code from ${src} into ${build} -->
<javac srcdir="${src}" destdir="${build}" includeantruntime="false" classpath="libs/${artgraphicslib}.jar"> <javac srcdir="${src}" destdir="${build}" includeantruntime="false" classpath="libs/${artgraphicslib}.jar">
<exclude name="org/artisanlogiciel/games/javafx/*"/> <exclude name="org/artisanlogiciel/games/javafx/*"/>
<compilerarg value="-Xlint:deprecation,unchecked" />
</javac> </javac>
</target> </target>
@@ -37,8 +38,8 @@
<!-- Put everything in ${build} into the artloglaby-${distversion}.jar file ( ${DSTAMP} not used yet )--> <!-- Put everything in ${build} into the artloglaby-${distversion}.jar file ( ${DSTAMP} not used yet )-->
<jar jarfile="${dist}/lib/artloglaby-${distversion}.jar" basedir="${build}"> <jar jarfile="${dist}/lib/artloglaby-${distversion}.jar" basedir="${build}">
<manifest> <manifest>
<attribute name="Main-Class" value="org.artisanlogiciel.games.Display"/> <attribute name="Main-Class" value="org.artisanlogiciel.games.maze.gui.Display"/>
<attribute name="Class-Path" value="${artgraphicslib}.jar"/> <attribute name="Class-Path" value="libs/${artgraphicslib}.jar"/>
</manifest> </manifest>
<fileset dir="lang" includes="**" /> <fileset dir="lang" includes="**" />
</jar> </jar>
@@ -50,5 +51,4 @@
<delete dir="${build}"/> <delete dir="${build}"/>
<delete dir="${dist}"/> <delete dir="${dist}"/>
</target> </target>
</project> </project>

12
c/Makefile.am Normal file
View File

@@ -0,0 +1,12 @@
# Makefile.am is REALLY where changes should be done
# Makefile.in and Makefile are generated from this.
bin_PROGRAMS = laby
laby_SOURCES = allaby_reader.c allaby_main.c
laby_CPPFLAGS = $(ARTLOG_CPPFLAGS) $(ALEXPANDER_CPPFLAGS)
# in LDADD and not in LDFLAGS to be linked AFTER
laby_LDADD = $(ARTLOG_LDFLAGS) $(ALEXPANDER_LDFLAGS)

17
c/allaby_main.c Normal file
View File

@@ -0,0 +1,17 @@
#include "al_options.h"
// NOT YET IMPLEMENTED
int main(int argc, char ** argv)
{
int exitcode = 1;
struct al_options * options = al_options_create(argc,argv);
al_options_set_debug(options,0);
struct alhash_datablock * debugdata = al_option_get(options,"debug");
if ( debugdata != NULL )
{
exitcode = 0;
}
al_options_release(options);
return exitcode;
}

2
c/allaby_reader.c Normal file
View File

@@ -0,0 +1,2 @@
#include "allaby_reader.h"

9
c/allaby_reader.h Normal file
View File

@@ -0,0 +1,9 @@
#ifndef __ALLABY_READER_H__
#define __ALLABY_READER_H__
/** goal : read a labyrinth/maze created
by java laby project
**/
#endif // __ALLABY_READER_H__

37
configure.ac Normal file
View File

@@ -0,0 +1,37 @@
# written manually, this is root entry files for automake together with Makefile.am
# inspired from
# http://www.gnu.org/software/automake/manual/html_node/Creating-amhello.html#Creating-amhello
AC_INIT([allaby], [0.1], [pl@artisanlogiciel.net])
# set ARTLOG_TOOLBOX where artlog_toolbox is to use it.
[ARTLOG_TOOLBOX=`pwd`/`./locate_artlog_toolbox.sh`]
# non need to propagate it in .h ...
# AC_DEFINE_UNQUOTED([ARTLOG_TOOLBOX],["$ARTLOG_TOOLBOX"],[where artog toolbox is])
ARTLOG_CPPFLAGS="-I${ARTLOG_TOOLBOX}/build/include"
ARTLOG_LDFLAGS="-Wl,-Bstatic -L${ARTLOG_TOOLBOX}/build/lib -lalsave -laltest -laljson -lalstack -lalhash -laldev -Wl,-Bdynamic"
AC_SUBST(ARTLOG_CPPFLAGS)
AC_SUBST(ARTLOG_LDFLAGS)
[if [ "$ALEXPANDER_DIR" = "" ]]
[then]
[ALEXPANDER_DIR=`pwd`/../sharedrawweb]
[fi]
ALEXPANDER_CPPFLAGS="-I${ALEXPANDER_DIR}/build/include -D CHARSPERRECORD=80"
ALEXPANDER_LDFLAGS="-Wl,-Bstatic -L${ALEXPANDER_DIR}/build/lib -lalima -lalcommon -Wl,-Bdynamic"
AC_SUBST(ALEXPANDER_CPPFLAGS)
AC_SUBST(ALEXPANDER_LDFLAGS)
AM_INIT_AUTOMAKE([-Wall -Werror foreign])
AC_PROG_CC
AC_CONFIG_HEADERS([config.h])
AC_DEFINE([MAX_FLAT_VIEWS],[20],[maximum number of view])
AC_CONFIG_FILES([
Makefile
c/Makefile
])
AC_OUTPUT

16
fetch_dependencies.sh Executable file
View File

@@ -0,0 +1,16 @@
#!/bin/bash
if [[ ! -d ../sharedrawweb ]]
then
echo "[ERROR] expected a sharedrawweb project parent ( for exports )" >&2
fi
if [[ ! -d libs ]]
then
mkdir libs
fi
if [[ ! -e libs/artgaphics-0.1.0.jar ]]
then
ln -s ../../sharedrawweb/dist/lib/artgaphics-0.1.0.jar libs/
fi

View File

@@ -11,8 +11,8 @@ $(OUT):
# mkdir -p $(OUT) # mkdir -p $(OUT)
clean: clean:
@find $(PACKAGE_DIR) -name "*.class" -type f -print0|xargs -0 rm 2>/dev/null && echo "cleaned classes in source" @find $(PACKAGE_DIR) -name "*.class" -type f -print0|xargs -0 --no-run-if-empty rm 2>/dev/null
@find $(OUT) -name "*.class" -type f -print0|xargs -0 rm 2>/dev/null || echo "nothing to clean" @find $(OUT) -name "*.class" -type f -print0|xargs -0 --no-run-if-empty rm 2>/dev/null
test: test:
echo "$(pwd)/$(PACKAGE_DIR)" echo "$(pwd)/$(PACKAGE_DIR)"

View File

@@ -1,73 +1,56 @@
package org.artisanlogiciel.games; package org.artisanlogiciel.games;
/** /**
DirectionPosition * DirectionPosition
* <p>
record direction and position ( direction as defined in LabyModel ). * record direction and position ( direction as defined in LabyModel ).
**/ **/
public class DirectionPosition public class DirectionPosition {
{
private short direction; private short direction;
private Position position; private Position position;
// (direction,position) // (direction,position)
DirectionPosition(short d, Position p) public DirectionPosition(short d, Position p) {
{
direction = d; direction = d;
position = p; position = p;
} }
short getDirection() public short getDirection() {
{
return direction; return direction;
} }
void setDirection(short d) public void setDirection(short d) {
{
direction = d; direction = d;
} }
Position getPosition() public Position getPosition() {
{
return position; return position;
} }
public String toString() public String toString() {
{ if (position != null) {
if (position != null)
{
return position.toString(); return position.toString();
} }
return "?"; return "?";
} }
// create a new DirectionPosition from this using one possible direction. // create a new DirectionPosition from this using one possible direction.
DirectionPosition moveToAdjacentDirection() public DirectionPosition moveToAdjacentDirection() {
{
short pointingdirection = 0; short pointingdirection = 0;
Position p = null; Position p = null;
if (LabyModel.isFlagSet(direction,LabyModel.RIGHT)) if (LabyModel.isFlagSet(direction, LabyModel.RIGHT)) {
{
p = new Position(position.getX() + 1, position.getY()); p = new Position(position.getX() + 1, position.getY());
pointingdirection |= LabyModel.LEFT; pointingdirection |= LabyModel.LEFT;
} } else if (LabyModel.isFlagSet(direction, LabyModel.LEFT)) {
else if (LabyModel.isFlagSet(direction,LabyModel.LEFT))
{
p = new Position(position.getX() - 1, position.getY()); p = new Position(position.getX() - 1, position.getY());
pointingdirection |= LabyModel.RIGHT; pointingdirection |= LabyModel.RIGHT;
} } else if (LabyModel.isFlagSet(direction, LabyModel.UP)) {
else if (LabyModel.isFlagSet(direction,LabyModel.UP))
{
p = new Position(position.getX(), position.getY() - 1); p = new Position(position.getX(), position.getY() - 1);
pointingdirection |= LabyModel.DOWN; pointingdirection |= LabyModel.DOWN;
} } else if (LabyModel.isFlagSet(direction, LabyModel.DOWN)) {
else if (LabyModel.isFlagSet(direction,LabyModel.DOWN))
{
p = new Position(position.getX(), position.getY() + 1); p = new Position(position.getX(), position.getY() + 1);
pointingdirection |= LabyModel.UP; pointingdirection |= LabyModel.UP;
} } else {
else
{
p = position; p = position;
} }

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -14,25 +14,14 @@ public class Main
return editor; return editor;
} }
public WallsProvider generate(int width, int height, int maxdepth, MazeResolutionListener listener) public LabyMap generate2(MazeParamEditor params)
{ {
LabyModel model = new LabyModel(width, height, maxdepth, new java.util.Random()); params.setSeed(1024L);
LabyModel model = new LabyModel(params);
model.generateWithEntry(0, 0); model.generateWithEntry(0, 0);
LinkedList<Position> exits = new LinkedList<Position>();
model.addEntryOrExit(-1, 0);
model.addEntryOrExit(width, height - 1);
if (!model.check())
{
System.out.println("Check failed");
}
model.resolve(width - 1, height - 1, listener);
return model;
}
public LabyMap generate2(int width, int height, int maxdepth) final int width = params.getWidth();
{ final int height = params.getHeight();
LabyModel model = new LabyModel(width, height, maxdepth, new java.util.Random(1024L));
model.generateWithEntry(0, 0);
LinkedList<Position> exits = new LinkedList<Position>(); LinkedList<Position> exits = new LinkedList<Position>();
model.addEntryOrExit(-1, 0); model.addEntryOrExit(-1, 0);
model.addEntryOrExit(width, height - 1); model.addEntryOrExit(width, height - 1);
@@ -51,7 +40,7 @@ public class Main
{ {
Main m = new Main(); Main m = new Main();
MazeParamEditor editor = m.editor(); MazeParamEditor editor = m.editor();
LabyMap map = m.generate2(editor.width, editor.height, editor.maxdepth); LabyMap map = m.generate2(editor);
System.out.println(map.toShortString()); System.out.println(map.toShortString());
System.out.println(map.toString()); System.out.println(map.toString());
System.out.println(Brick.getDirLine()); System.out.println(Brick.getDirLine());

View File

@@ -3,7 +3,7 @@ package org.artisanlogiciel.games;
/** /**
* MazeCreationListener * MazeCreationListener
**/ **/
interface MazeCreationListener public interface MazeCreationListener
{ {
void changed(Position cornerleft, Position cornerright, WallsProvider provider); void changed(Position cornerleft, Position cornerright, WallsProvider provider);
} }

View File

@@ -8,6 +8,7 @@ import java.util.Scanner;
**/ **/
class MazeParamEditor implements MazeParams class MazeParamEditor implements MazeParams
{ {
long seed;
int width; int width;
int height; int height;
int maxdepth; int maxdepth;
@@ -27,6 +28,11 @@ class MazeParamEditor implements MazeParams
maxdepth = console.nextInt(); maxdepth = console.nextInt();
} }
public long getSeed()
{
return seed;
}
public int getWidth() public int getWidth()
{ {
return width; return width;
@@ -51,6 +57,11 @@ class MazeParamEditor implements MazeParams
return name; return name;
} }
public void setSeed(long seed)
{
this.seed = seed;
}
public File getSaveDir() public File getSaveDir()
{ {
return labdir; return labdir;

View File

@@ -7,6 +7,9 @@ import java.io.File;
**/ **/
public interface MazeParams public interface MazeParams
{ {
/** currently seed of java.util.random **/
public long getSeed();
public int getWidth(); public int getWidth();
public int getHeight(); public int getHeight();

View File

@@ -0,0 +1,76 @@
package org.artisanlogiciel.games;
import java.io.File;
public class MazeParamsFixed implements MazeParams
{
long seed;
int width;
int height;
int maxdepth;
File labdir;
String name;
public MazeParamsFixed()
{
}
public MazeParamsFixed(MazeParams params)
{
setParams(params.getSaveDir(),params.getWidth(),params.getHeight(),params.getMaxDepth());
}
public void setParams(File saveDir, int W, int H, int MD)
{
labdir = saveDir;
width=W;
height=H;
maxdepth=MD;
}
public MazeParamsFixed(File saveDir, int W, int H, int MD, long seed)
{
name = null;
setParams(saveDir,W,H,MD);
this.seed=seed;
}
public long getSeed()
{
return seed;
}
public int getWidth()
{
return width;
}
public int getHeight()
{
return height;
}
public int getMaxDepth()
{
return maxdepth;
}
public void setName(String n)
{
name = n;
}
public String getName()
{
if (name == null)
{
name = "lab" + width + "x" + height;
}
return name;
}
public File getSaveDir()
{
return labdir;
}
}

View File

@@ -13,7 +13,12 @@ public interface WallsProvider
/** /**
* See Brick * See Brick
* *
* Will set bits : 3 2 1 0 (8)(4)(2)(1) ^ > v < U R D L p i o e g w f h n t * Will set bits :
* 3 2 1 0
* (8)(4)(2)(1)
* ^ > v <
* U R D L
* p i o e g w f h n t
* t * t
**/ **/
public short getWalls(int x, int y); public short getWalls(int x, int y);

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,72 @@
package org.artisanlogiciel.games.maze.gui;
import org.artisanlogiciel.games.MazeParams;
import org.artisanlogiciel.games.stl.Maze3dParams;
import org.artisanlogiciel.games.stl.Wall3d;
import javax.swing.*;
public class Maze3dSettings
extends JPanel
{
// grid size
JTextField xl;
JTextField yl;
JTextField zl;
JTextField w;
JTextField lg;
JTextField hg;
JCheckBox reverse;
Maze3dParams params;
public Maze3dSettings(Maze3dParams params) {
super();
this.params = params;
createSettingsGui();
}
void createSettingsGui() {
if (params != null) {
JLabel widthLabel = new JLabel(Display.labels.getString("width"));
xl = new JTextField("0" + params.getXl());
add(widthLabel);
add(xl);
JLabel heightLabel = new JLabel(Display.labels.getString("height"));
zl = new JTextField("0" + params.getZl());
add(heightLabel);
add(zl);
JLabel depthLabel = new JLabel(Display.labels.getString("depth"));
yl = new JTextField("0" + params.getYl());
add(depthLabel);
add(yl);
reverse = new JCheckBox("reverse",params.isReverse());
add(reverse);
w = new JTextField("0" + params.getW());
add(w);
// lowground hightground
lg = new JTextField("0" + params.getLg());
add(lg);
hg = new JTextField("0" + params.getHg());
add(hg);
}
}
Maze3dParams createParams()
{
return new Maze3dParams(
Integer.parseInt(xl.getText()),
Integer.parseInt(yl.getText()),
Integer.parseInt(zl.getText()),
Integer.parseInt(w.getText()),
Integer.parseInt(lg.getText()),
Integer.parseInt(hg.getText()),
reverse.isSelected());
}
}

View File

@@ -0,0 +1,56 @@
package org.artisanlogiciel.games.maze.gui;
import org.artisanlogiciel.games.MazeParams;
import org.artisanlogiciel.games.MazeParamsFixed;
import javax.swing.*;
import java.util.Random;
public class MazeSettings extends JPanel {
MazeParams params;
JTextField textWidth = null;
JTextField textHeight = null;
JTextField textDepth = null;
JTextField textSeed = null;
// TODO set width and height and depth of maze with gui
public MazeSettings(MazeParams params) {
super();
this.params = params;
createSettingsGui();
}
void createSettingsGui() {
if (params != null) {
JLabel widthLabel = new JLabel(Display.labels.getString("width"));
textWidth = new JTextField("0" + params.getWidth());
add(widthLabel);
add(textWidth);
JLabel heightLabel = new JLabel(Display.labels.getString("height"));
textHeight = new JTextField("0" + params.getHeight());
add(heightLabel);
add(textHeight);
JLabel depthLabel = new JLabel(Display.labels.getString("depth"));
textDepth = new JTextField("0" + params.getMaxDepth());
add(depthLabel);
add(textDepth);
JLabel seedLabel = new JLabel(Display.labels.getString("seed"));
textSeed = new JTextField( "" + params.getSeed(),16);
add(seedLabel);
add(textSeed);
}
}
public MazeParams resetParams() {
params = new MazeParamsFixed(params.getSaveDir(),
Integer.parseInt(textWidth.getText()),
Integer.parseInt(textHeight.getText()),
Integer.parseInt(textDepth.getText()),
new Random().nextLong()
);
textSeed.setText("" + params.getSeed());
return params;
}
}

View File

@@ -0,0 +1,104 @@
package org.artisanlogiciel.games.stl;
public class Maze3dParams {
// grid size
int xl;
int yl;
int zl;
int w;
int lg;
int hg;
Wall3d south;
Wall3d west;
Wall3d north;
Wall3d east;
Wall3d highGround;
Wall3d lowGround;
// reverse : means that resolved path will be HighGround actual making maze more difficult to play with
boolean reverse;
// default
public Maze3dParams()
{
this(10,10,10, 1 , 1, 3, false);
}
// w width is wall thickness
public Maze3dParams(int xl, int yl, int zl, int w, int lg, int hg, boolean reverse)
{
this.xl = xl;
this.yl = yl;
this.zl = zl;
this.reverse = reverse;
int h = zl;
this.w = w;
this.lg = lg;
this.hg = hg;
south = new Wall3d(xl, w, h, 0, 0, 0);
west = new Wall3d(w, yl, h, 0, 0, 0);
north = new Wall3d(xl, w, h, 0, yl, 0);
east = new Wall3d(w, yl, h, xl, 0, 0);
highGround = new Wall3d(xl, yl, hg, 0, 0, 0);
lowGround = new Wall3d(xl, yl, lg, 0, 0, 0);
}
public boolean isReverse() {
return reverse;
}
public int getXl() {
return xl;
}
public int getYl() {
return yl;
}
public int getZl() {
return zl;
}
public Wall3d getSouth() {
return south;
}
public Wall3d getWest() {
return west;
}
public Wall3d getNorth() {
return north;
}
public Wall3d getEast() {
return east;
}
public Wall3d getHighGround() {
return highGround;
}
public Wall3d getLowGround() {
return lowGround;
}
public int getLg() {
return lg;
}
public int getHg() {
return hg;
}
public int getW() {
return w;
}
}

View File

@@ -11,114 +11,134 @@ import java.io.IOException;
/** /**
* Wall3d to create walls in 3d for stl conversion South, West North East... * Wall3d to create walls in 3d for stl conversion South, West North East...
*
* wall3D will create a rectangular cuboid with 2 triangle vertex for each face
**/ **/
public class Wall3d public class Wall3d {
{
// 4 triangles in 2 dim space reused 3 times // 4 triangles in 2 dim space reused 3 times
final static int BASE[][][] = { { { 0, 0 }, { 1, 0 }, { 0, 1 } }, { { 1, 0 }, { 1, 1 }, { 0, 1 } }, // in facts order matters...
{ { 0, 0 }, { 1, 0 }, { 1, 1 } }, { { 0, 0 }, { 1, 1 }, { 0, 1 } } }; final static int BASE[][][] = {
// lower left
{{0, 0}, {1, 0}, {0, 1}},
// higher right
{{1, 0}, {1, 1}, {0, 1}},
// lower right
{{0, 0}, {1, 0}, {1, 1}},
// higher left
{{0, 0}, {1, 1}, {0, 1}}};
final static short X = 1; final static short X = 1;
final static short Y = 2; final static short Y = 2;
final static short Z = 4; final static short Z = 4;
// final static short AXIS[][]= {{X,Y},{-Z,Y},{X,Y},{Z,Y},{X,-Z},{X,-Z}}; // final static short AXIS[][]= {{X,Y},{-Z,Y},{X,Y},{Z,Y},{X,-Z},{X,-Z}};
final static short AXIS[][] = { { X, Y, 0 }, { Z, Y, 0 }, { X, Y, 1 }, { Z, Y, 1 }, { X, Z, 0 }, { X, Z, 1 } };
public final static Wall3d South = new Wall3d(10, 1, 10, 0, 0, 0); // [face][axis]
public final static Wall3d West = new Wall3d(1, 10, 10, 0, 0, 0); final static short AXIS[][] = {
public final static Wall3d North = new Wall3d(10, 1, 10, 0, 10, 0); // face 0 (x,y) back
public final static Wall3d East = new Wall3d(1, 10, 10, 10, 0, 0); {X, Y, 0},
public final static Wall3d HighGround = new Wall3d(10, 10, 3, 0, 0, 0); // face 1 (z,y) left
public final static Wall3d LowGround = new Wall3d(10, 10, 2, 0, 0, 0); {Z, Y, 0},
// face 2 (x,y,1)
{X, Y, 1},
// face 3
{Z, Y, 1},
// face 4
{X, Z, 0},
// face 5
{X, Z, 1}};
final static String normalx = "1.0 0.0 0.0";
final static String normaly = "0.0 1.0 0.0";
final static String normalz = "0.0 0.0 1.0";
final static String normalmx = "-1.0 0.0 0.0";
final static String normalmy = "0.0 -1.0 0.0";
final static String normalmz = "0.0 0.0 -1.0";
// final static short NORMAL[] = {Z,X,Z,X,Y,Y};
final static String normalstr[] =
{ normalmz, normalx,
normalz, normalmx,
normaly, normalmy
};
boolean reverse_vertex[] = {
true,false,false,true,false,true
};
int triangle[][][] = null; int triangle[][][] = null;
public Wall3d(int t[][][]) public Wall3d(int t[][][]) {
{
triangle = t; triangle = t;
} }
public Wall3d(Wall3d origin, int dx, int dy, int dz) public Wall3d(Wall3d origin, int dx, int dy, int dz) {
{
triangle = origin.translate(dx, dy, dz); triangle = origin.translate(dx, dy, dz);
} }
Wall3d(int xl, int yl, int zl, int dx, int dy, int dz) Wall3d(int xl, int yl, int zl, int dx, int dy, int dz) {
{
int f = 0; int f = 0;
triangle = new int[12][3][3]; triangle = new int[12][3][3];
int[] factor = {xl, yl, zl}; int[] factor = {xl, yl, zl};
int[] translate = {dx, dy, dz}; int[] translate = {dx, dy, dz};
for (int i = 0; i < 12; i++) for (int facet = 0; facet < 12; facet++) {
{ // point in a triangle / facet
// point in a triangle for (int p = 0; p < 3; p++) {
for (int p = 0; p < 3; p++)
{
short uaxis = 0; short uaxis = 0;
for (int axis = 0; axis < 2; axis++) // a square face is two facets.
{ int face = facet / 2;
short caxis = AXIS[i / 2][axis]; // first two axis ( projected on x,y,z depending on AXIS[face][] )
if (caxis > 0) for (int axis = 0; axis < 2; axis++) {
{ short caxis = AXIS[face][axis];
if (caxis > 0) {
f = 1; f = 1;
} } else if (caxis < 0) {
else if (caxis < 0) // wait wait in AXIS there is no negative value ...
{ // so we never enter here, what was the purpose ? might be history.
f = -1; f = -1;
caxis = (short) -caxis; caxis = (short) -caxis;
} }
// what if caxis == 0 ? f is kept as its previous value ?
// which is 1 in facts due to AXIS[..][0] > 0
// uaxis keep track of used axes for this face to find last missing axis
uaxis |= caxis; uaxis |= caxis;
if (caxis == X) if (caxis == X) {
{
caxis = 0; caxis = 0;
} } else if (caxis == Y) {
else if (caxis == Y)
{
caxis = 1; caxis = 1;
} } else {
else
{
caxis = 2; caxis = 2;
} }
// if ( f == 0 ) triangle[facet][p][caxis] = translate[caxis] + BASE[facet % 4][p][axis] * f * factor[caxis];
// {
// System.out.println("ERROR");
// }
// System.out.println("i " + i + " p " + p + " a " + caxis +
// " , " + BASE[i%4][p][axis] );
triangle[i][p][caxis] = translate[caxis] + BASE[i % 4][p][axis] * f * factor[caxis];
} }
if ((uaxis & X) == 0) // last remaining axis
{ if ((uaxis & X) == 0) {
// no X was used => X
uaxis = 0; uaxis = 0;
} } else if ((uaxis & Y) == 0) {
else if ((uaxis & Y) == 0) // X was used byt not Y => Y
{
uaxis = 1; uaxis = 1;
} } else {
else // default X, and Y were used => Z
{
uaxis = 2; uaxis = 2;
} }
triangle[i][p][uaxis] = translate[uaxis] + AXIS[i / 2][2] * factor[uaxis]; triangle[facet][p][uaxis] = translate[uaxis] + AXIS[facet / 2][2] * factor[uaxis];
} }
} }
} }
public int[][][] translate(int dx, int dy, int dz) public int[][][] translate(int dx, int dy, int dz) {
{
int[] translate = {dx, dy, dz}; int[] translate = {dx, dy, dz};
int t[][][] = new int[12][3][3]; int t[][][] = new int[12][3][3];
for (int i = 0; i < 12; i++) for (int facet = 0; facet < 12; facet ++) {
{
// point in a triangle // point in a triangle
for (int p = 0; p < 3; p++) for (int p = 0; p < 3; p++) {
{ for (int axis = 0; axis < 3; axis++) {
for (int axis = 0; axis < 3; axis++) t[facet][p][axis] = translate[axis] + triangle[facet][p][axis];
{
t[i][p][axis] = translate[axis] + triangle[i][p][axis];
} }
} }
} }
@@ -127,22 +147,27 @@ public class Wall3d
} }
/** /**
write triangles as stl text * write triangles as stl text
**/ **/
public String toString() public String toString() {
{
String s = ""; String s = "";
for (int t = 0; t < 12; t++) for (int facet = 0; facet < 12; facet++) {
{ int face = facet / 2;
s += "facet normal 0 0 0\nouter loop\n"; // most software don't care normal but just rely on vertex order ( right hand ).
for (int p = 0; p < 3; p++) String normal = normalstr[face];
{ s += "facet normal " + normal + "\nouter loop\n";
boolean reverse = reverse_vertex[face];
for (int p = 0; p < 3; p++) {
s += "vertex"; s += "vertex";
for (int a = 0; a < 3; a++) // p that accept right hand
int rhp = p;
if ( reverse )
{ {
// s+=" t "+ t + " p " + p + " a " + a + "=" + // reverse 2 and 1 ; 0 => 0, 1 => 2 , 2 => 1
// triangle[t][p][a]; rhp = ( p * 5 ) % 3;
s += " " + triangle[t][p][a]; }
for (int a = 0; a < 3; a++) {
s += " " + triangle[facet][rhp][a];
} }
s += "\n"; s += "\n";
} }
@@ -151,94 +176,4 @@ public class Wall3d
return s; return s;
} }
public static void prepare()
{
System.out.println(South.toString());
System.out.println(East.toString());
System.out.println(North.toString());
System.out.println(West.toString());
}
public static void streamWallsOut(String name, LabyModel provider, OutputStream stream) throws IOException
{
int width = provider.getWidth();
int height = provider.getHeight();
int xl = 10;
int yl = 10;
int zl = 10;
// WARNING DOWN - UP reversed ( in 2D Y is oriented to lower, in 3D it
// is to upper ).
stream.write(("solid " + name + "\n").getBytes());
for (int x = 0; x < width; x++)
{
short walls = provider.getWalls(x, 0);
if ((walls & Brick.UP) != 0)
{
stream.write(new Wall3d(South, x * xl, 0, 0).toString().getBytes());
}
if ((walls & Brick.LEFT) != 0)
{
stream.write(new Wall3d(West, x * xl, 0, 0).toString().getBytes());
}
}
for (int y = 0; y < height; y++)
{
short walls = provider.getWalls(0, y);
if ((walls & Brick.LEFT) != 0)
{
stream.write(new Wall3d(West, 0, y * yl, 0).toString().getBytes());
}
for (int x = 0; x < width; x++)
{
// south and east
walls = provider.getWalls(x, y);
if ((walls & Brick.DOWN) != 0)
{
stream.write(new Wall3d(North, x * xl, y * yl, 0).toString().getBytes());
}
if ((walls & Brick.RIGHT) != 0)
{
stream.write(new Wall3d(East, x * xl, y * yl, 0).toString().getBytes());
}
short path = provider.getPath(x,y);
if ( ( path & LabyModel.SOLVED ) == LabyModel.SOLVED )
// if ( (walls & ( Brick.GOAL | Brick.ENTRY ) ) == 0 )
{
// if ( ( (x+y) % 2) == 0 )
stream.write(new Wall3d(LowGround, x * xl, y * yl, 0).toString().getBytes());
}
else
{
stream.write(new Wall3d(HighGround, x * xl, y * yl, 0).toString().getBytes());
}
}
}
stream.write("endsolid wall\n\n".getBytes());
}
public static void main(String args[])
{
Scanner console = new Scanner(System.in);
int xl = console.nextInt();
int yl = console.nextInt();
int zl = console.nextInt();
int dx = console.nextInt();
int dy = console.nextInt();
int dz = console.nextInt();
String s = "solid wall\n";
Wall3d instance = new Wall3d(xl, yl, zl, dx, dy, dz);
prepare();
s += "endsolid wall\n\n";
System.out.println(s);
}
} }

View File

@@ -0,0 +1,93 @@
package org.artisanlogiciel.games.stl;
import org.artisanlogiciel.games.Brick;
import org.artisanlogiciel.games.LabyModel;
import java.io.IOException;
import java.io.OutputStream;
public class Wall3dStream
{
String name;
LabyModel provider;
OutputStream stream;
Maze3dParams params;
/**
*
* @param name
* @param provider
* @param stream
* @param params
*/
public Wall3dStream(String name, LabyModel provider, OutputStream stream, Maze3dParams params)
{
this.name = name;
this.provider = provider;
this.stream = stream;
this.params = params;
}
private void writeWall3D(Wall3d wall3d)
throws IOException
{
stream.write(wall3d.toString().getBytes());
}
public void stream() throws IOException {
int width = provider.getWidth();
int height = provider.getHeight();
int xl = params.getXl();
int yl = params.getYl();
int zl = params.getZl();
boolean reverse = params.isReverse();
// WARNING DOWN - UP reversed ( in 2D Y is oriented to lower, in 3D it
// is to upper ).
stream.write(("solid " + name + "\n").getBytes());
for (int x = 0; x < width; x++) {
short walls = provider.getWalls(x, 0);
if ((walls & Brick.UP) != 0) {
writeWall3D(new Wall3d(params.getSouth(), x * xl, 0, 0));
}
if ((walls & Brick.LEFT) != 0) {
writeWall3D(new Wall3d(params.getWest(), x * xl, 0, 0));
}
}
for (int y = 0; y < height; y++) {
short walls = provider.getWalls(0, y);
if ((walls & Brick.LEFT) != 0) {
writeWall3D(new Wall3d(params.getWest(), 0, y * yl, 0));
}
for (int x = 0; x < width; x++) {
// south and east
walls = provider.getWalls(x, y);
if ((walls & Brick.DOWN) != 0) {
writeWall3D(new Wall3d(params.getNorth(), x * xl, y * yl, 0));
}
if ((walls & Brick.RIGHT) != 0) {
writeWall3D(new Wall3d(params.getEast(), x * xl, y * yl, 0));
}
short path = provider.getPath(x, y);
// where resolved path is leaked to stl model.
Wall3d ground = reverse ? params.getLowGround() : params.getHighGround();
if ((path & LabyModel.SOLVED) == LabyModel.SOLVED)
// if ( (walls & ( Brick.GOAL | Brick.ENTRY ) ) == 0 )
{
// if ( ( (x+y) % 2) == 0 )
ground = reverse ? params.getHighGround() : params.getLowGround();
}
writeWall3D(new Wall3d(ground, x * xl, y * yl, 0));
}
}
stream.write("endsolid wall\n\n".getBytes());
stream.flush();
}
}

View File

@@ -10,3 +10,5 @@ create = Create
save = Save save = Save
quit = Quit quit = Quit
title = A Maz ing title = A Maz ing
seed = seed
load = Load

View File

@@ -10,3 +10,5 @@ create = Créer
save = Sauver save = Sauver
quit = Quitter quit = Quitter
title = La Bireinte title = La Bireinte
seed = graine
load = Charger

View File

@@ -10,9 +10,9 @@
<property name="src" location="java"/> <property name="src" location="java"/>
<property name="build" location="build"/> <property name="build" location="build"/>
<property name="dist" location="dist"/> <property name="dist" location="dist"/>
<!-- Fill me please / todo -->
<property name="artgraphicslib" value="artgaphics-0.2.0"/> <property name="artgraphicslib" value="artgaphics-0.2.0"/>
<property name="distversion" value="1.0"/> <property name="distversion" value="1.1"/>
<target name="init"> <target name="init">
<!-- Create the time stamp --> <!-- Create the time stamp -->
@@ -26,6 +26,7 @@
<!-- Compile the java code from ${src} into ${build} --> <!-- Compile the java code from ${src} into ${build} -->
<javac srcdir="${src}" destdir="${build}" includeantruntime="false" classpath="libs/${artgraphicslib}.jar"> <javac srcdir="${src}" destdir="${build}" includeantruntime="false" classpath="libs/${artgraphicslib}.jar">
<exclude name="org/artisanlogiciel/games/javafx/*"/> <exclude name="org/artisanlogiciel/games/javafx/*"/>
<compilerarg value="-Xlint:deprecation,unchecked" />
</javac> </javac>
</target> </target>
@@ -37,8 +38,8 @@
<!-- Put everything in ${build} into the artloglaby-${distversion}.jar file ( ${DSTAMP} not used yet )--> <!-- Put everything in ${build} into the artloglaby-${distversion}.jar file ( ${DSTAMP} not used yet )-->
<jar jarfile="${dist}/lib/artloglaby-${distversion}.jar" basedir="${build}"> <jar jarfile="${dist}/lib/artloglaby-${distversion}.jar" basedir="${build}">
<manifest> <manifest>
<attribute name="Main-Class" value="org.artisanlogiciel.games.Display"/> <attribute name="Main-Class" value="org.artisanlogiciel.games.maze.gui.Display"/>
<attribute name="Class-Path" value="${artgraphicslib}.jar"/> <attribute name="Class-Path" value="libs/${artgraphicslib}.jar"/>
</manifest> </manifest>
<fileset dir="lang" includes="**" /> <fileset dir="lang" includes="**" />
</jar> </jar>
@@ -50,5 +51,4 @@
<delete dir="${build}"/> <delete dir="${build}"/>
<delete dir="${dist}"/> <delete dir="${dist}"/>
</target> </target>
</project> </project>

View File

@@ -2,6 +2,6 @@ project_name=artloglaby
project_default=dist project_default=dist
project_basedir=$(pwd) project_basedir=$(pwd)
project_mainpackage=org.artisanlogiciel.games project_mainpackage=org.artisanlogiciel.games
project_mainclass=$project_mainpackage.Display project_mainclass=$project_mainpackage.maze.gui.Display
project_version=1.0 project_version=1.1
default_args='lab/lab30x30.raw' default_args='lab/lab30x30.raw'

42
renamelabindir.sh Executable file
View File

@@ -0,0 +1,42 @@
#!/bin/bash
labdir=$1
newprefix=$2
if [[ -z $labdir ]]
then
echo "[ERROR] expect a lab directory"
echo "will rename all labxxx.* within this directory to directory name labdirxxx.*"
exit 1
fi
if [[ -z $newprefix ]]
then
newprefix=$labdir
fi
{
echo "[INFO] changing lab prefix to $newprefix"
declare -i index=1
pushd $labdir
for f in $(find . -regextype egrep -regex "./lab[0-9]+x[0-9]+\..*")
do
if [[ $f =~ ./lab([0-9]+)x([0-9]+)\.(.+) ]]
then
width=${BASH_REMATCH[1]}
height=${BASH_REMATCH[2]}
extension=${BASH_REMATCH[3]}
newname="${newprefix}_${index}_${width}x${height}.$extension"
if [[ ! -e ./$newname ]]
then
mv $f ./$newname
else
echo "[ERROR] skip $f -> ./$newname since new name already used" >&2
fi
fi
index=index+1
done
popd
}

37
scripts/laby.sh Executable file
View File

@@ -0,0 +1,37 @@
#!/bin/bash
findmainjar()
{
for MJ in $(find . -name "*.jar")
do
echo "$MJ"
if [[ $MJ =~ artloglaby-(.*)\.jar ]]
then
VERSION=${BASH_REMATCH[1]}
echo "found $MJ version $VERSION"
MAINJAR=$MJ
fi
done
}
echo "Ce script a été conçu pour une distribution linux"
echo "This script was created for linux"
findmainjar
if [[ -z $MAINJAR ]]
then
echo "[ERREUR] aucun jar artloglaby-xxx.jar dans ce répertoire"
exit 1
fi
if which java
then
java -jar $MAINJAR
else
echo "Aucun java/jre de trouvé"
echo
echo "Pour ubuntu :"
echo "sudo apt install openjdk-8-jre"
fi

View File

@@ -1,5 +1,19 @@
#!/bin/bash #!/bin/bash
function findmainjar()
{
for MJ in $(find . -name "*.jar")
do
echo "$MJ"
if [[ $MJ =~ (artloglaby-.*\.jar) ]]
then
MAINJAR=${BASH_REMATCH[1]}
echo "found $MJ jar $MAINJAR"
fi
done
}
specific_run() specific_run()
{ {
local action=$1 local action=$1
@@ -33,9 +47,25 @@ create_zip_package()
mkdir $dest mkdir $dest
# will be used at run time to save mazes # will be used at run time to save mazes
mkdir $dest/lab mkdir $dest/lab
mkdir $dest/libs
cp scripts/laby.sh $dest cp scripts/laby.sh $dest
MAINJAR=""
pushd dist/lib
findmainjar
popd
if [[ -n $MAINJAR ]]
then
printf '%b\n' "java -jar $MAINJAR"
printf '%b\r\n' "java -jar $MAINJAR" >$dest/laby.bat
else
echo "[ERROR] can't find main jar"
fi
cp LISEZMOI $dest cp LISEZMOI $dest
cp libs/* $dest cp libs/* $dest/libs/
cp dist/lib/* $dest cp dist/lib/* $dest
zip -r $zip_package $dest zip -r $zip_package $dest

1
toolbox.param Normal file
View File

@@ -0,0 +1 @@
ARTLOG_TOOLBOX=../artlog_toolbox