Compare commits

..

22 Commits

Author SHA1 Message Date
7bef98a33a update zstd-jnilib to latest
and provide in fetch_dependencies information of latest

Signed-off-by: philippe lhardy <philippe.lhardy@astrolabe.coop>
2025-11-02 20:21:31 +01:00
fcda589742 cleanup remove samples 2025-11-02 18:30:07 +01:00
bce0e160d8 don't build build.xml, maintain it manualy
remove antify.sh and related builx.xml target makefile

Signed-off-by: philippe lhardy <philippe.lhardy@astrolabe.coop>
2025-11-02 18:10:21 +01:00
36e58808d5 don't depend on sharedrawweb
use directly sharedrawweb java code here

Signed-off-by: philippe lhardy <philippe.lhardy@astrolabe.coop>
2025-11-02 18:04:02 +01:00
e78da6ec76 cleanup continued missing files
toolbox related makefiles
remove bootstrapbuild.sh since was for c code not in that project

Signed-off-by: philippe lhardy <philippe.lhardy@astrolabe.coop>
2025-11-02 08:46:16 +01:00
3c4b44e837 add missing script coming from unlinked artlog toolbox project
not mandatory but consistent to have all code

Signed-off-by: philippe lhardy <philippe.lhardy@astrolabe.coop>
2025-11-02 08:41:53 +01:00
1b0be89766 fix dependencies and BUILD.md for public build
Signed-off-by: philippe lhardy <philippe.lhardy@astrolabe.coop>
2025-11-01 23:35:33 +01:00
180718c36f Merge branch 'pi'
# Conflicts:
#	BUILD.md
#	fetch_dependencies.sh
2025-11-01 23:02:15 +01:00
philippe lhardy
2b050cccda better dependencies fetching
- provide git url for sharedrawweb
2025-11-01 22:57:33 +01:00
f3d1af1d45 add buildings too, not only ways
Signed-off-by: philippe lhardy <philippe.lhardy@astrolabe.coop>
2025-11-01 19:33:20 +01:00
9bb481d0b3 x is longitude y is latitude
and y axis is reversed in maze ( (0,0) is upper left square of maze ).

Signed-off-by: philippe lhardy <philippe.lhardy@astrolabe.coop>
2025-11-01 19:32:20 +01:00
8fdea9ed3a copytominetest using metascript
Signed-off-by: philippe lhardy <philippe.lhardy@astrolabe.coop>
2025-11-01 16:15:15 +01:00
1d96ee089b don't bind to artlog toolbox
Signed-off-by: philippe lhardy <philippe.lhardy@astrolabe.coop>
2025-11-01 15:39:35 +01:00
f27120cc50 discard c code was an empty stub
Signed-off-by: philippe lhardy <philippe.lhardy@astrolabe.coop>
2025-11-01 15:37:25 +01:00
06a46343e0 markdown README.md
Signed-off-by: philippe lhardy <philippe.lhardy@astrolabe.coop>
2025-11-01 15:23:10 +01:00
ab6746ed5c metascript and printclonedep
will move to metascript

Signed-off-by: philippe lhardy <philippe.lhardy@astrolabe.coop>
2025-11-01 15:12:45 +01:00
65cc0f4c62 pending files commited
don't really knwon what i am doing here, commit pending code ...

Signed-off-by: philippe lhardy <philippe.lhardy@astrolabe.coop>
2025-11-01 14:09:35 +01:00
philippe lhardy
70744610cc Merge branch 'rebasepi' into pi
# Conflicts:
#	fetch_dependencies.sh
2023-07-30 10:23:02 +02:00
philippe lhardy
9792b79c56 MaimMim Man in the middle minetest interceptor
- prototype
- between client and server, allow to capture all exchanges and potentially change them
- created to capture server maps in laby
- first test get only MapBlock, support version serialization version 28
  - prepartion for 29 with zstd but untested.

# Conflicts:
#	fetch_dependencies.sh
2023-07-30 10:18:45 +02:00
philippe lhardy
6d7c03d468 MaimMim Man in the middle minetest interceptor
- prototype
- between client and server, allow to capture all exchanges and potentially change them
- created to capture server maps in laby
- first test get only MapBlock, support version serialization version 28
  - prepartion for 29 with zstd but untested.
2022-04-23 11:54:25 +02:00
philippe lhardy
1e03ae561c Merge branch 'pi' of framagit.org:artlog/artloglaby into pi 2022-04-17 13:37:58 +02:00
philippe lhardy
744999802c fix first column and firt line not drawable
- within() method should include first point and exclude last.
2022-04-17 13:36:35 +02:00
120 changed files with 5092 additions and 2428334 deletions

3
.gitignore vendored Normal file
View File

@@ -0,0 +1,3 @@
devenv_params
artloglaby
build/

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

@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="AntConfiguration">
<buildFile url="file://$PROJECT_DIR$/build.xml" />
</component>
</project>

1
.idea/laby.iml generated
View File

@@ -25,5 +25,6 @@
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="artgaphics-0.2.0" level="project" />
<orderEntry type="library" name="zstd-jni-1.5.2-2" level="project" />
</component>
</module>

View File

@@ -1,9 +0,0 @@
<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>

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

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

0
.resources.var Normal file
View File

47
4create.makefile Normal file
View File

@@ -0,0 +1,47 @@
PACKAGE?=org.artisanlogiciel.games
MAIN_CLASS?=Main
PACKAGE_DIR=$(subst .,/,$(PACKAGE))
OUT=out
EDITOR=emacs
$(OUT):
mkdir -p $(OUT)
clean:
@find $(PACKAGE_DIR) -name "*.class" -type f -print0|xargs -0 rm 2>/dev/null && echo "cleaned classes in source"
@find $(OUT) -name "*.class" -type f -print0|xargs -0 rm 2>/dev/null || echo "nothing to clean"
test:
javac -d $(OUT) $(PACKAGE_DIR)/$(MAIN_CLASS).java
java -cp $(OUT) $(PACKAGE).$(MAIN_CLASS)
run/%: $(OUT)
javac -d $(OUT) $(PACKAGE_DIR)/$(subst run/,,$@).java
java -cp $(OUT) $(PACKAGE)/$(subst run/,,$@)
compile/%:
javac -d $(OUT) $(PACKAGE_DIR)/$(subst compile/,,$@).java
$(PACKAGE_DIR)/%.java:
./generate_new.sh class $(subst .java,,$(subst $(PACKAGE_DIR)/,,$@))
interface/%:
./generate_new.sh interface package_dir=$(PACKAGE_DIR) $(subst interface/,,$@)
$(EDITOR) $(PACKAGE_DIR)/$(subst interface/,,$@).java
work/%: $(PACKAGE_DIR)/$(subst work/,,%).java
$(EDITOR) $<
work: work/$(MAIN_CLASS)
save:
git citool
.PHONY: clean test work work/% run/% save compile/% interface/%
# tried to avoid intermediate file removal : does not work
# .SECONDARY: $(PACKAGE_DIR)/%.java
# this does work : once precious intermediate file is not removed.
.PRECIOUS: $(PACKAGE_DIR)/%.java

55
4java.makefile Normal file
View File

@@ -0,0 +1,55 @@
PROJECT_VERSION=`./debianize.sh getversion`
DISTPREFIX=`./debianize.sh getproject`
DISTJAR=$(DISTPREFIX)-$(PROJECT_VERSION).jar
JAVAC=javac
JAR=jar
all: dist/lib/$(DISTJAR)
getname:
@echo dist/lib/$(DISTJAR)
getjavalibs:
@if [ -d libs ] ; then find libs/ -type f -o -type l -name "*.jar"; fi
dist:
mkdir -p dist
dist/lib/$(DISTJAR): dist
ant dist
clean:
cd java; make clean
rm -f dist/lib/$(DISTPREFIX)*.jar
rm -rf build
cleanall: clean
rm -rf debian
rm -rf deb
rm -rf download
debian:
mkdir debian
deb/%:
mkdir -p deb
touch $@
./debianize.sh create $@
debian/compat:
echo "10" >$@
debian/%:
./debianize.sh create $@ >$@
deb: debian debian/rules debian/control debian/compat debian/changelog deb/javadoc deb/jlibs
dpkg-buildpackage -uc -us
/usr/bin/emacs:
sudo apt-get install emacs
emacsdevenv:
.PHONY: clean all cleanall getname deb emacsdevenv work/% interface/%

View File

@@ -3,24 +3,23 @@
This project was done in java so it requires a java compiler to be build under an executable form.
It is expected you already obtained content of source since you are readeing this BUILD.md
It is expected you already obtained content of source since you are reading this BUILD.md
within same directory as this BUILD.md :
```
./init.sh
# will create build scripts from artlog_toolbox
# ./doit.sh
# depends on sharedrawweb for stl export
./fetch_dependencies.sh
./fetch_dependencies.sh use_zstd
ant dist
```
Then create de .zip
```
source ./specificdoit.sh; create_zip_package
```
you ccan then provide and copy laby.zip to install it.
you can then provide and copy laby.zip to install it.
See README to find documentation how to install and run it.

View File

@@ -13,13 +13,10 @@ sous windows lancez le laby.bat
il s'agit d'un programme java qui peut aussi être lancé avec l'interpréteur java ainsi :
java -jar artloglaby-1.0.jar
java -jar artloglaby-1.2.jar
mail pl@artisanlogiciel.net
vous pouvez le distribuer ou bien même le vendre
ses sources sont sur https://github.com/artlog/labystl
( et utilise aussi https://github.com/artlog/sharedrawweb )
Les labyrinthes que vous sauvegardez le sont dans le répertoire lab.

68
Makefile.4.java Normal file
View File

@@ -0,0 +1,68 @@
PROJECT_VERSION=`./debianize.sh getversion`
DISTPREFIX=`./debianize.sh getproject`
DISTJAR=$(DISTPREFIX)-$(PROJECT_VERSION).jar
JDEE_VERSION=2.4.1
JAVAC=javac
JAR=jar
RHINO_VER=1_7R5
all: dist/lib/$(DISTJAR)
getname:
@echo dist/lib/$(DISTJAR)
dist:
mkdir -p dist
dist/lib/$(DISTJAR): dist
ant dist
clean:
rm -f dist/lib/$(DISTPREFIX)*.jar
rm -rf build
cd java; make clean
cleanall: clean
rm -rf debian
rm -rf deb
rm -rf download
@( [ -d ~/.emacs.d/jdee-$(JDEE_VERSION) ] && echo "DON'T remove installed ~/.emacs.d/jdee-$(JDEE_VERSION). To remove jdee do 'make removejdee'" ) || true
debian:
mkdir debian
deb/%:
mkdir -p deb
touch $@
./debianize.sh create $@
debian/compat:
echo "10" >$@
debian/%:
./debianize.sh create $@ >$@
deb: debian debian/rules debian/control debian/compat debian/changelog deb/javadoc deb/jlibs deb/format
./buildsourcetree.sh
/usr/bin/emacs:
sudo apt-get install emacs
download/jdee-bin-$(JDEE_VERSION).tar.bz2:
mkdir -p download; cd download; wget http://sourceforge.net/projects/jdee/files/jdee/$(JDEE_VERSION)/jdee-bin-$(JDEE_VERSION).tar.bz2
~/.emacs.d/jdee-$(JDEE_VERSION): /usr/bin/emacs download/jdee-bin-$(JDEE_VERSION).tar.bz2
mkdir -p ~/.emacs.d; tar -xjf download/jdee-bin-$(JDEE_VERSION).tar.bz2 -C ~/.emacs.d
echo "(add-to-list 'load-path \"~/.emacs.d/jdee-$(JDEE_VERSION)/lisp\")\n(load \"jde\")" >>~/.emacs.d/init.el
emacsdevenv: ~/.emacs.d/jdee-$(JDEE_VERSION)
removejdee:
rm -rf ~/.emacs.d/jdee-$(JDEE_VERSION)
sed -i -n -e "/^(add-to-list 'load-path \"~\/\.emacs\.d\/jdee-$(JDEE_VERSION)\/lisp\")$$/d" -e "/^(load \"jde\")$$/d" -e"/^.*$$/p" ~/.emacs.d/init.el
download/rhino$(RHINO_VER).zip:
mkdir -p download
cd download; wget https://github.com/mozilla/rhino/releases/download/Rhino$(RHINO_VER)_RELEASE/rhino$(RHINO_VER).zip
.PHONY: clean all cleanall getname deb emacsdevenv removejdee

View File

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

View File

@@ -1,12 +1,11 @@
# This is a personal project to generate a 2D maze using in depth path generation.
This is a personal project to generate a 2D maze using in depth path generation.
This can generate a stl file, overall goal was to print it with a 3D printer.
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.
After years i finaly printed one maze, find it at https://www.thingiverse.com/thing:2814655
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.
There is a console gui menu based with ./doit.sh
@@ -15,12 +14,31 @@ requirement : you need a java jdk environment installed ( java + javac ) and ant
ex ubuntu : sudo apt-get install default-jdk ant
===== BUILD =====
It can take various input
* raw this tool raw format : see documentation raw
* imc esoteric internal format
* Drawing ?
* osm openstreetmap exported map
* we minetest/luanti world edit format
* Auto-generated
* Created through GUI
and output
* svg SVG / to handle with inkscape
* png
* raw this tool raw format : see documentation raw
* stl for 3d printers
* imc esoteric internal format
* txt labyrinth as text
* we minetest/luanti world edit format
## BUILD
See BUILD.md
===== INSTALL =====
## INSTALL
obtain laby.zip directly build or from you own build ( see BUILD above ).
@@ -30,11 +48,10 @@ unzip laby.zip
it will create a artloglaby directory.
===== RUN =====
## RUN
run it on a Linux distribution with :
```
cd artloglaby ; ./laby.sh
```

View File

@@ -1,12 +0,0 @@
java/
java sources
java/org/artisanlogiciel/games
java sources for package org.artisanlogiciel.games respect of java directory naming convention of files
java/org/artisanlogiciel/games/Main.java
Main Java entry point for this program

View File

@@ -1,23 +0,0 @@
#!/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,8 +10,10 @@
<property name="src" location="java"/>
<property name="build" location="build"/>
<property name="dist" location="dist"/>
<!-- Fill me please / todo -->
<property name="artgraphicslib" value="artgaphics-0.2.0"/>
<!-- Fill me please / todo
see fetch_dependencies
-->
<property name="zstd-jnilib" value="zstd-jni-1.5.7-6"/>
<target name="gather_project_params">
<!-- original source parameter is in project_params project_version -->
<loadfile property="distversion" srcfile="${basedir}/project_params">
@@ -38,7 +40,7 @@
<target name="compile" depends="init"
description="compile the source " >
<!-- 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/${zstd-jnilib}.jar">
<exclude name="org/artisanlogiciel/games/javafx/*"/>
<compilerarg value="-Xlint:deprecation,unchecked" />
</javac>

View File

@@ -1,12 +0,0 @@
# 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)

View File

@@ -1,17 +0,0 @@
#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;
}

View File

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

View File

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

View File

@@ -1 +1 @@
sharedrawweb artlog_toolbox
sharedrawweb

View File

@@ -1,37 +0,0 @@
# 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

57
copytominetest.sh Executable file
View File

@@ -0,0 +1,57 @@
#!/bin/bash
# SPDX-FileCopyrightText: 2025 artlog@l0g.eu
# SPDX-License-Identifier: AGPL-3.0-or-later
# header generated by lib/metascript.sh header
# metascript_version=v1.0.0
toolsdir=lib
pushd $toolsdir >/dev/null
toolsdir=$(pwd)
source metascript.sh
popd >/dev/null
usage() {
cat <<EOF
copy a .we generated lab into minetest local game directory
name=name of generated .we without extension
game=name of game
EOF
}
metarun=metarun
# change default to sudo if needed
# metasudo=sudo
name="$1.we"
srcdir="lab/"
game="nm"
while [[ $# > 0 ]]
do
case "$1" in
name=*)
name=${1/name=}.we
;;
game=*)
game=${1/game=}
;;
*)
parsemetaarg "$1"
;;
esac
shift
done
dest=~/.minetest/worlds/$game/schems
src=${srcdir}$name
enforce file $src exists
enforce dir $dest exists
if [[ -f $src ]]
then
$defer cp $src $dest/
else
log_error "missing $src"
fi

76
debianize.sh Executable file
View File

@@ -0,0 +1,76 @@
#!/bin/bash
action=$1
file=$2
maintainer="Artlog <pl@artisanlogiciel.net>"
if [[ $action == getversion ]]
then
source ./project_params
echo $project_version
elif [[ $action == getproject ]]
then
source ./project_params
echo $project_name
elif [[ $action =~ get([_a-z]*)$ ]]
then
getvar=${BASH_REMATCH[1]}
source ./project_params
eval "echo \$$getvar"
elif [[ $action == create ]]
then
source ./project_params
if [[ $file == debian/control ]]
then
cat <<EOF
Source: ${project_name}-java
Priority: extra
Maintainer: $maintainer
Build-Depends: debhelper (>= 7.0.50~), javahelper (>=0.25)
Build-Depends-Indep: default-jdk, default-jdk-doc, libtrove-java, libtrove-java-doc, ant
Standards-Version: ${project_version}
Section: java
Package: ${project_name}-java
Architecture: all
Depends: \${java:Depends}, \${misc:Depends}
Recommends: \${java:Recommends}
Description: Labyrinth generator
Labyrinth generator
Package: ${project_name}-java-doc
Architecture: all
Depends: \${java:Depends}, \${misc:Depends}
Recommends: \${java:Recommends}
Description: Labyrinth generator (documentation)
Labyrinth generator
EOF
elif [[ $file = debian/changelog ]]
then
cat <<EOF
${project_name}-java (${project_version}) unstable; urgency=low
* Initial debian package
-- ${maintainer} $(LANG=C date -R)
EOF
elif [[ $file = debian/rules ]]
then
cat <<EOF
#!/usr/bin/make -f
JAVA_HOME=/usr/lib/jvm/default-java
%:
dh \$@ --with javahelper
EOF
elif [[ $file = deb/javadoc ]]
then
echo "api /usr/share/doc/${project_name}-java/api" >debian/${project_name}-java-doc.javadoc
elif [[ $file = deb/jlibs ]]
then
echo "dist/lib/${project_name}-${project_version}.jar" >debian/${project_name}-java.jlibs
fi
fi

View File

@@ -1,3 +1,3 @@
DEV_ENV=~/artisanlogiciel/devel_tools
JDK_PATH=~/artisanlogiciel/devel_tools/jdk1.8.0_74
ECLIPSE_PATH=~/artisanlogiciel/devel_tools/eclipse
DEV_ENV=~/home/plhardy/clients/artlog/code/laby/devel_tools
JDK_PATH=/usr/lib/jvm/java-11-openjdk-amd64
ECLIPSE_PATH=/snap/bin

393
doit.sh Executable file
View File

@@ -0,0 +1,393 @@
#!/bin/bash
# entry point for project building / editing / running
# this specific_run is intended to be overriden by specific_doit.sh script if any.
function specific_run()
{
echo "[ERROR] '$1' command is not supported in a generic manner" >&2
}
# within a list of files $1 $2 ... find the first that exists and set variable found_best to it.
find_best()
{
while [[ $# > 0 ]]
do
if [[ -f $1 ]]
then
found_best=$1
return
fi
shift
done
}
# $1 variable $2 value
save_parameter()
{
echo "$1=\"$2\"" >> .params
}
info()
{
if [[ -z $NOJAVA ]]
then
echo "DEV_ENV=$DEV_ENV"
echo "JDK_PATH=$JDK_PATH"
echo "ECLIPSE_PATH=$ECLIPSE_PATH"
echo "PATH=$PATH"
java -version
else
echo "NOJAVA is set to $NOJAVA"
fi
}
setup()
{
if [[ -z $NOJAVA ]]
then
if [[ ! -d java ]]
then
echo "[INFO] Missing java directory." >&2
fi
fi
}
do_code()
{
if [[ -z $NOJAVA ]]
then
background=$1
local jd=()
local id=()
local menu=()
index=0
# find all java source file within current directory and populate jd array with. even if java is a link ( -H option ).
for java_dir in $(find -H java -name '*.java' -exec dirname {} \; | sort -u)
do
index=$((index+1))
id+=($index)
jd+=("$java_dir")
menu+=($index "$java_dir")
done
echo "found ${#jd[@]} java source directories"
if [[ ${#jd[@]} -gt 1 ]]
then
echo "${jd[@]}"
# menu <text> <height> <width> <listheight> <tag[1]> <name[1]> ... <tag[n]> <name[n]>
index_dir=$($DIALOG --menu "Select dir" 20 100 10 ${menu[@]} 3>&1 1>&2 2>&3)
if [[ ! $? ]]
then
echo "[ERROR] $DIALOG --menu did fail when requesting choice over java directories" >&2
exit 1
fi
fi
java_dir=${jd[$((index_dir-1))]}
if [[ ! -d $java_dir ]]
then
echo "$java_dir is not a directory" >&2
return
fi
echo "chose dir $java_dir"
find $java_dir -maxdepth 1 -name '*.java' |
{
local s=()
while read codeline
do
javafile=$(basename "$codeline")
javaclass=${javafile/.java/}
echo "$javafile $javaclass"
s+=("$javaclass" "$codeline")
done
javaclass=$($DIALOG --menu "Edit it" 20 100 10 ${s[@]} 3>&1 1>&2 2>&3)
if [[ -n $javaclass ]]
then
if [[ $background == codebg ]]
then
${EDITOR} $java_dir/$javaclass.java &
else
${EDITOR} $java_dir/$javaclass.java
fi
fi
}
else
echo "NOJAVA set"
fi
}
edit_properties()
{
local property_file=$1
if [[ -f $property_file ]]
then
modified=0
s=()
properties=()
values=()
{
while read codeline
do
if [[ $codeline =~ (^[a-zA-Z_]*)=(.*) ]]
then
property=${BASH_REMATCH[1]}
value=${BASH_REMATCH[2]}
s+=("$property" "$value")
properties+=("$property")
values+=("$value")
fi
done
s+=(exit "Exit")
} < $property_file
while true
do
property=$($DIALOG --menu "Edit '$property_file'" 20 100 10 ${s[@]} 3>&1 1>&2 2>&3)
if [[ $? = 0 ]]
then
if [[ -n $property ]]
then
if [[ $property == exit ]]
then
return 1
elif [[ $property == save ]]
then
for (( i=0; i<${prop_len}; i++ ));
do
echo "${properties[$i]}=${values[$i]}"
done >$property_file
return 0
fi
prop_len="${#properties[@]}"
for (( i=0; i<${prop_len}; i++ ));
do
if [[ ${properties[$i]} == $property ]]
then
init_value=${values[$i]}
fi
done
value=$($DIALOG --inputbox "Enter $property value" 10 80 "$init_value" 3>&1 1>&2 2>&3)
if [[ $? = 0 ]]
then
prop_len="${#properties[@]}"
s=()
if [[ "$value" != "$init_value" ]]
then
modified=$(( modified + 1 ))
fi
for (( i=0; i<${prop_len}; i++ ));
do
if [[ ${properties[$i]} == $property ]]
then
values[$i]=$value
fi
s+=("${properties[$i]}" "${values[$i]}")
echo "${properties[$i]}=${values[$i]}"
done
s+=(exit "Exit")
if [[ $modified != 0 ]]
then
s+=(save "Save")
fi
fi
fi
else
return 2
fi
done
else
echo "[ERROR] property_file '$propertyfile' not found" >&2
fi
}
specific_menus=()
if [[ -f ./specificdoit.sh ]]
then
source ./specificdoit.sh
fi
if [[ -f .params ]]
then
source .params
if [[ -n $DIALOG ]]
then
if [[ ! -x $DIALOG ]]
then
echo "[ERROR] DIALOG=$DIALOG dialog tool not executable" >&2
exit 1
fi
fi
fi
LOG_OUTFILE=.log
if [[ -z $DIALOG ]]
then
echo "[INFO] detecting dialog program"
possible_console_gui="whiptail dialog"
for DIALOG in $possible_console_gui
do
DIALOG=$(which $DIALOG)
if [[ -x $DIALOG ]]
then
$DIALOG --menu "Ultra Light IDE" 20 80 2 "select me to validate $DIALOG " justfortest
rc=$?
if [[ $rc != 0 ]]
then
echo "[ERROR] $DIALOG return code $rc : can't use it" >&2
else
break
fi
fi
done
if [[ -z $DIALOG ]]
then
echo "[ERROR] no console gui support (no dialog tool found within $possible_console_gui) => no menus " >&2
echo "[INFO] this can happen under emacs within shell or eshell, please use term then"
exit 1
fi
save_parameter DIALOG "$DIALOG"
fi
possible_editor="emacs vi nano"
for EDITOR in $possible_editor
do
EDITOR=$(which $EDITOR)
if [[ -x $EDITOR ]]
then
break
fi
done
if [[ -z $EDITOR ]]
then
echo "[ERROR] no editor found (within $possible_editor) => no editing " >&2
fi
setup
action=initial
# count successives failures.
failed_commands_count=0
while [[ $action != quit ]]
do
# should detect that dialog failed
if [[ -z $NOJAVA ]]
then
# should be cleaned up from specific laby project targets.
action=$($DIALOG --menu "Ultra Light IDE" 20 80 12 readme "Read me" clean "Clean All" ant "Ant build" run "Run it" ${specific_menus[@]} test "Test it" code "Code" codebg "Code in background" deb "Debian package" properties "Edit Properties" create "Create a new class" info "Info" logs "Logs" quit "Quit" 3>&1 1>&2 2>&3)
else
action=$($DIALOG --menu "Ultra Light IDE" 20 80 12 readme "Read me" clean "Clean All" run "Run it" test "Test it" ${specific_menus[@]} code "Code" codebg "Code in background" deb "Debian package" properties "Edit Properties" info "Info" logs "Logs" quit "Quit" 3>&1 1>&2 2>&3)
fi
rc=$?
if [[ $rc == 0 ]]
then
failed_commands_count=0
else
failed_commands_count=$(( failed_commands_count + 1 ))
fi
if (( $failed_commands_count > 10 ))
then
echo "[ERROR] more than 10 successive failures ( $failed_commands_count > 10 )" >&2
echo "[INFO] Check if your environment supports $DIALOG"
action=quit
fi
if [[ $action == run ]]
then
if [[ -z $NOJAVA ]]
then
echo "run it"
{
source ./project_params
javalibs=$(make -f ${JAVA_MAKEFILE} getjavalibs|awk '{ printf "%s:",$1 }')
mainlib=$(make -f ${JAVA_MAKEFILE} getname)
javarun="java -cp $mainlib:$javalibs $project_mainclass"
echo $javarun
$javarun
}
else
make
fi
elif [[ $action == ant ]]
then
make -f ${JAVA_MAKEFILE} clean
make -f ${JAVA_MAKEFILE}
ant compile >>.log 2>&1
elif [[ $action == clean ]]
then
if [[ -z $NOJAVA ]]
then
make -f ${JAVA_MAKEFILE} clean
pushd java
make clean
popd
else
make clean
fi
elif [[ $action == test ]]
then
if [[ -z $NOJAVA ]]
then
echo "test it"
pushd java
make display
popd
else
make test
fi
elif [[ $action == deb ]]
then
make -f ${JAVA_MAKEFILE} deb
elif [[ $action =~ code ]]
then
do_code $action
elif [[ $action == readme ]]
then
found_best=
find_best README README.md
if [[ -n $found_best ]]
then
$DIALOG --textbox $found_best 40 80 --scrolltext
else
echo "no README or README.md found" >&2
fi
elif [[ $action == properties ]]
then
edit_properties project_params
elif [[ $action == create ]]
then
newclass=$($DIALOG --inputbox "Enter new class name" 10 80 "NewClass" 3>&1 1>&2 2>&3)
if [[ $? = 0 ]]
then
if [[ -n $newclass ]]
then
MAIN_CLASS=Main PACKAGE=$(./debianize.sh getproject_mainpackage) make -f 4create.makefile work/$newclass
fi
fi
elif [[ $action == info ]]
then
infos=$(mktemp)
info >$infos
$DIALOG --textbox $infos 40 80 --scrolltext
rm $infos
elif [[ $action == logs ]]
then
if [[ -f .log ]]
then
$DIALOG --textbox .log 40 80 --scrolltext
fi
elif [[ $action == quit ]]
then
echo "[INFO] quit requested"
else
specific_run $action
fi
done

137
eclipse_env.sh Executable file
View File

@@ -0,0 +1,137 @@
#!/bin/bash
# for the story this comes from a JavaFX training i attended
usage()
{
cat <<EOF
Usage $0:
setup_dev_env: create file devenv_params with reference over jdk and eclipse path
any other argument is an error
no argument => launch eclipse
EOF
}
create_dev_params()
{
if [[ -e devenv_params ]]
then
echo " devenv_params already exists"
exit 1
# could update this way
# source devenv_params
else
if [[ -z $DEV_ENV ]]
then
echo "[ERROR] DEV_ENV $DEV_ENV not set, call setup_eclipse_dir from this '$0' script"
exit 1
fi
cat >devenv_params <<EOF
DEV_ENV=$DEV_ENV
JDK_PATH=$JDK_PATH
ECLIPSE_PATH=$ECLIPSE_PATH
EOF
fi
}
setup_eclipse_dir()
{
if [[ -e devenv_params ]]
then
source devenv_params
else
echo "[WARNING] Use some defaults for devenv_params"
echo "[INFO] please adapt them. Current setup should be compatible with 'sudo snap install eclipse --classic' setup"
DEV_ENV=~$(pwd)/devel_tools
JDK_PATH=/usr/lib/jvm/java-11-openjdk-amd64
ECLIPSE_PATH=$(dirname $(which eclipse))
fi
}
# Not tested written after install ...
setup_eclipse()
{
# current list of TGZ got from oracle (tm)
TGZ_LIST="eclipse-jee-mars-2-linux-gtk-x86_64.tar.gz javafx_scenebuilder-2_0-linux-x64.tar.gz jdk-8u74-linux-x64.tar.gz"
}
check_eclipse()
{
if [[ -z $JDK_PATH ]]
then
echo "[ERROR] Missing JDK_PATH, either devenv_params is wrong or missing" >&2
exit 1
fi
if [[ -z $ECLIPSE_PATH ]]
then
echo "[ERROR] Missing ECLIPSE_PATH, either devenv_params is wrong or missing" >&2
exit 1
fi
if [[ ! -d $JDK_PATH ]]
then
echo "[ERROR] Missing JDK_PATH '$JDK_PATH'" >&2
fi
if [[ ! -d $ECLIPSE_PATH ]]
then
ls -la ${DEV_ENV}
echo "[ERROR] Missing ECLIPSE_PATH '$ECLIPSE_PATH'" >&2
exit 1
fi
}
# not yet used ...
create_sandbox()
{
mkdir sandbox
}
check_java_version() {
local expected_version='1.8.0'
if java -version 2>&1 | grep "$expected_version"
then
if javac -version 2>&1 | grep "$expected_version"
then
$*
else
echo "[ERROR] Wrong javac version expected $expected_version" >&2
fi
else
echo "[ERROR] Wrong java version expected $expected_version" >&2
fi
}
# overrides PATH with JDK_PATH ECLIPSE_PATH
# and check java is the right one to launch eclipse
run_in_sandbox()
{
PATH=$JDK_PATH/bin/:$JDK_PATH/jre/bin/:$ECLIPSE_PATH:$PATH
export PATH
[[ -n $check_version ]] && check_java_version
}
while [[ $# > 0 ]]
do
case $1 in
setup_dev_env)
setup_eclipse_dir
create_dev_params
exit 0
;;
*)
echo "[ERROR] Unrecognized argument '$1'" >&2
usage
exit 1
;;
esac
shift 1
done
setup_eclipse_dir
check_eclipse
run_in_sandbox eclipse -data $(pwd)/workspace

View File

@@ -1,63 +1,118 @@
#!/bin/bash
# SPDX-FileCopyrightText: 2025 artlog@l0g.eu
# SPDX-License-Identifier: AGPL-3.0-or-later
# header generated by lib/metascript.sh header
# metascript_version=v1.0.0
log_any()
{
echo "$@" >&2
toolsdir=lib
pushd $toolsdir >/dev/null
toolsdir=$(pwd)
source metascript.sh
popd >/dev/null
usage() {
cat <<EOF
$0 use_jackson|use_zstd|use_artgraphic
EOF
}
log_error()
{
log_any "[ERROR] $@"
}
log_info()
{
log_any "[INFO] $@"
}
fetch_jackson_databind()
{
lib_jackson_databind=jackson-databind-${libversion_jackson_databind}.jar
if [[ ! -e libs/$lib_jackson_databind ]]
then
jacksonmaven=https://repo1.maven.org/maven2/com/fasterxml/jackson/core/jackson-databind/${libversion_jackson_databind}/$lib_jackson_databind
pushd libs
wget $jacksonmaven
popd
$defer pushd libs
$metarun wget $jacksonmaven
$defer popd
fi
}
fetch_zstd-jni()
{
# echo "compiled from https://github.com/luben/zstd-jni commit 54d3d50c16d96bd8a30e2d4c0a9648001a52d6f9"
# had to hack through jar generation ...
# cp ~/artisanlogiciel/ext_projects/java/zstd-jni/target/zstd-jni-1.5.2-2.jar .
maven_repo=https://repo1.maven.org/maven2/
package_path=com/github/luben/zstd-jni/
# https://repo1.maven.org/maven2/maven-metadata.xml
latest=$(curl -s ${maven_repo}${package_path}maven-metadata.xml | xmllint --xpath 'string(metadata/versioning/latest)' -)
log_info "latest version : $latest"
zstdjni=$(xmllint --xpath 'string(/project/property[@name="zstd-jnilib"]/@value)' build.xml)
if [[ -n $zstdjni ]]
then
$defer pushd libs
libversion_zstdjni=${zstdjni/zstd-jni-}
$metarun curl ${maven_repo}${package_path}${libversion_zstdjni}/${zstdjni}.jar -o ${zstdjni}.jar
$defer popd
else
log_error 'no /project/property[@name="zstd-jnilib"]/@value) found in build.xml'
fi
}
# HARDCODED START
libversion_jackson_databind=2.12.0
sharedrawweb_git_url="ssh://philippe@www4.artisanlogiciel.net:2023/home/philippe/artisanlogiciel/code/sharedrawweb"
sharedrawweb_git_url="https://framagit.org/artlog/sharedrawweb.git"
libversion_artgaphic=0.2.0
# HARDCODED END
lib_artgaphic=artgaphics-${libversion_artgaphic}.jar
if [[ ! -d ../sharedrawweb ]]
then
log_error "expected a sharedrawweb project parent ( for exports ). Please clone related project."
log_info "cd ..; git clone $sharedrawweb_git_url"
fi
metarun=metarun
# change default to sudo if needed
# metasudo=sudo
while [[ $# > 0 ]]
do
case "$1" in
use_jackson)
use_jackson=$1
;;
use_zstd)
use_zstd=$1
;;
use_artgraphic)
use_artgraphic=$1
;;
*)
parsemetaarg "$1"
;;
esac
shift
done
if [[ ! -d libs ]]
then
mkdir libs
$metarun mkdir libs
fi
if [[ ! -e libs/$lib_artgaphic ]]
if [[ -n $user_artgraphic ]]
then
lib_artgaphic_source_file=../sharedrawweb/dist/lib/$lib_artgaphic
if [[ -f $lib_artgaphic_source_file ]]
if [[ ! -d sharedrawweb ]]
then
# ../ since libs is one level below current project
ln -s ../$lib_artgaphic_source_file libs/
else
log_error "Missing $lib_artgaphic_source_file. It is require to build it sharedrawweb project first"
log_error "expected a sharedrawweb project parent ( for exports ). Please clone related project."
log_info "git clone $sharedrawweb_git_url sharedrawweb"
fi
if [[ ! -e libs/$lib_artgaphic ]]
then
lib_artgaphic_source_file=sharedrawweb/dist/lib/$lib_artgaphic
if [[ -f $lib_artgaphic_source_file ]]
then
# ../ since libs is one level below current project
$metarun ln -s ../$lib_artgaphic_source_file libs/
else
log_error "Missing $lib_artgaphic_source_file"
log_info "It is required to build sharedrawweb project first"
fi
fi
fi
if [[ -n $use_jackson ]]
then
then
fetch_jackson_databind
fi
if [[ -n $use_zstd ]]
then
fetch_zstd-jni
fi

209
generate_new.sh Executable file
View File

@@ -0,0 +1,209 @@
#!/bin/bash
# generate empty templates or add functions given a defined language
usage()
{
head -n 2
}
generate_java_class()
{
cat <<EOF >$JAVA_FILE
package $PACKAGE;
/**
$CLASS was autogenerated by $TOOLP
**/
public $ctype $CLASS
{
Object param;
$CLASS(Object param)
{
this.param=param;
}
void method()
{
System.out.println("Method of $PACKAGE.$CLASS");
}
public static void main(String args[]) {
if ( args.length > 1 )
{
$CLASS instance=new $CLASS(args[1]);
instance.method();
}
else
{
System.err.println("Missing argument for $CLASS");
}
}
}
EOF
}
generate_java_interface()
{
cat <<EOF >$JAVA_FILE
package $PACKAGE;
/**
$CLASS was autogenerated by $TOOLP
**/
public $ctype $CLASS
{
/**
@return X
*/
int getX();
/**
@return Y
*/
int getY();
}
EOF
}
add_new_c_main()
{
cat <<EOF >>$C_FILE
# autogenerated by $TOOLP
int main(int argc, char **argv)
{
todo(\"Code this\");
return 0;
}
EOF
}
add_new_c_function()
{
echo "[INFO] add new c function $FUNCTION in h_file=$H_FILE and c_file=$C_FILE"
if [[ $FUNCTION == main ]]
then
add_new_c_main
else
cat <<EOF >>$H_FILE
# autogenerated by $TOOLP
int $FUNCTION();
EOF
cat <<EOF >>$C_FILE
# autogenerated by $TOOLP
int $FUNCTION(){
todo(\"Code this $FUNCTION\");
return -2;
}
EOF
fi
}
#TODO : support "like=" to copy/renaming an existing class
TOOLP="$0 $*"
ctype=class
genlang=java
while [[ $# > 0 ]]
do
case $1 in
class|interface)
ctype=$1
;;
package=*)
PACKAGE=${1/package=/}
;;
package_dir=*)
PACKAGE_DIR=${1/package=/}
PACKAGE=${PACKAGE//\//\.}
;;
genlang=*)
genlang=${1/genlang=/}
;;
class=*)
CLASS=${1/class=/}
;;
function=*)
FUNCTION=${1/function=/}
;;
c_file=*)
C_FILE=${1/c_file=}
;;
h_file=*)
H_FILE=${1/h_file=}
;;
*)
if [[ -z $CLASS ]]
then
CLASS=${1}
echo "[INFO] setting class=$CLASS" >&2
else
echo "[ERROR] unrecognized parameter $1" >&2
fi
;;
esac
shift 1
done
if [[ $genlang == java ]]
then
if [[ -z $PACKAGE ]]
then
echo "[INFO] obtain package name from project settings"
PACKAGE=$(./debianize.sh getproject_mainpackage)
if [[ -z $PACKAGE ]]
then
echo "[ERROR] can't find project_mainpackage" >&2
exit 1
fi
fi
if [[ -z $CLASS ]]
then
echo "[ERROR] Missing class" >&2
exit 1
fi
PACKAGE_DIR=${PACKAGE//\./\/}
if [[ ! -d $PACKAGE_DIR ]]
then
echo "Missing $PACKAGE_DIR" >&2
exit 1
fi
JAVA_FILE=$PACKAGE_DIR/$CLASS.java
if [[ -e $JAVA_FILE ]]
then
echo "[ERROR] $JAVA_FILE already exists" >&2
exit 1
else
if [[ $ctype == class ]]
then
generate_java_class
else
generate_java_interface
fi
fi
echo "$JAVA_FILE generated"
elif [[ $genlang == c ]]
then
if [[ -z $H_FILE ]]
then
H_FILE=c/genauto.h
fi
if [[ -z $C_FILE ]]
then
C_FILE=c/genauto.c
fi
add_new_c_function
else
echo "[ERROR] language genlang=$genlang NOT supported" >&2
usage
fi

18
init.sh
View File

@@ -1,18 +1,5 @@
#!/bin/bash
setup()
{
artlog_toolbox_path=../artlog_toolbox
if [[ ! -d $artlog_toolbox_path ]]
then
git clone $artlog_toolbox_remote_origin_url $artlog_toolbox_path
pushd $artlog_toolbox_path
git checkout
popd
fi
$artlog_toolbox_path/deploy.sh
}
# parses project.gitref
project=
gitref=project.gitref
@@ -33,9 +20,6 @@ do
artloglaby)
artloglaby_remote_origin_url=$remote_origin_url
;;
artlog_toolbox)
artlog_toolbox_remote_origin_url=$remote_origin_url
;;
*)
echo "ERROR unrecognized project='$project' line='$line'"
;;
@@ -43,4 +27,4 @@ do
fi
done <$gitref
setup

View File

@@ -1,7 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path=""/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER">
<attributes>
<attribute name="module" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.fx.ide.jdt.core.JAVAFX_CONTAINER"/>
<classpathentry kind="lib" path="/home/plhardy/clients/artlog/code/laby/libs/artgaphics-0.2.0.jar"/>
<classpathentry kind="lib" path="/home/plhardy/artisanlogiciel/code/laby/libs/sharedrawweb-0.2.0.jar"/>
<classpathentry kind="lib" path="/home/plhardy/artisanlogiciel/code/laby/libs/artgaphics-0.2.0.jar"/>
<classpathentry kind="output" path=""/>
</classpath>

1
java/.gitignore vendored Normal file
View File

@@ -0,0 +1 @@
/module-info.class

View File

@@ -0,0 +1 @@
/JWToken.class

View File

@@ -0,0 +1,4 @@
package org.artisanlogiciel.aaa.authorize;
public class JWToken {
}

View File

@@ -0,0 +1,92 @@
package org.artisanlogiciel.compression;
import java.io.DataInputStream;
import java.io.OutputStream;
import java.io.DataOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import org.artisanlogiciel.graphics.SvgWriter;
import org.artisanlogiciel.graphics.Drawing;
/**
* Very simple utility to convert from .imc to svg.
*
* TODO : could be more clever and not load full image into memory to save it afterwards ( for very small embedded systems ).
*/
public class Main
{
Drawing mLocalImage;
public static void main(String[] args) {
Main m = new Main();
if ( args.length > 1 )
{
m.loadExpanded(args[0]);
try {
File out = new File(args[1]);
if (out.exists())
{
System.err.println("File already exists" + out + " Not overriding it");
}
else
{
//m.saveSvg(new DataOutputStream(new FileOutputStream(out)));
FileOutputStream fout = new FileOutputStream(out);
m.saveSvg(fout);
fout.flush();
fout.close();
}
} catch (IOException e) {
e.printStackTrace();
}
}
else
{
System.out.println("Very simple utility to convert from .imc to svg.");
System.out.println("first argument is compressed file, second is svg output file (should not already exist)");
}
}
public void saveSvg(OutputStream s)
throws IOException
{
SvgWriter writer = new SvgWriter(mLocalImage.getLines());
writer.writeTo(s);
}
public void saveKompressed( String ref) {
try {
FileOutputStream fi = new FileOutputStream( ref);
mLocalImage.saveLinesKompressed( new DataOutputStream( fi));
}
catch( java.io.FileNotFoundException fnfe)
{
fnfe.printStackTrace(System.err);
}
catch ( java.io.IOException ioe) {
ioe.printStackTrace(System.err);
}
}
public void loadExpanded( String ref) {
try {
FileInputStream fi = new FileInputStream( ref);
mLocalImage = new Drawing();
mLocalImage.loadLinesExpanded( new DataInputStream( fi));
}
catch( java.io.FileNotFoundException fnfe) {
fnfe.printStackTrace(System.err);
}
catch ( java.io.IOException ioe) {
ioe.printStackTrace(System.err);
}
}
}

View File

@@ -0,0 +1,146 @@
/*
This file is part of ShareDrawWeb.
ShareDrawWeb is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
ShareDrawWeb 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. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with ShareDrawWeb; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package org.artisanlogiciel.compression.graphics;
/*
simple class to read bitfields
@see BitFieldWriter
@author Philippe Lhardy
*/
import java.io.*;
class BitFieldReader {
// size of nextWord
final int dataSize = 32;
/* offset of next bit to be read in current word
should ensure bitOffset < dataSize
*/
private int bitOffset = 0;
/* word used waiting to be fully read
dataSize is bit size of currentWord
currentWord is part of word read that begins at bitOffset.
*/
private int currentWord = 0;
private DataInputStream inputStream;
/* value returned is an int between 0 and 2^bits-1 */
public int read( int bits) throws java.io.IOException {
int field = 0;
int head = 0;
// a new word is needed
if ( bitOffset == 0 ) {
nextWord();
}
// if more bits needed that word currently used.
if ( bits + bitOffset > dataSize) {
// warning recursive call ( not terminal )
int bitsize = dataSize - bitOffset;
head = read( dataSize - bitOffset);
// current word had entirely been read, need a new one
// don't do that... nextWord() will be done by next read...
field = read( bits - bitsize);
// reconstruct all
// more significant bits in first word, least in last
field = field | ( head << (bits - bitsize));
}
else {
// terminal part do the job
if ( bits == dataSize) {
// special case to keep sign
field = currentWord;
currentWord = 0;
bitOffset = 0;
}
else {
field = ( currentWord >> ( dataSize - bits) )
& ( 0x7fffffff >> ( dataSize - 1 - bits) );
// bits are read then remove them from currentWord
currentWord <<= bits;
bitOffset = ( bitOffset + bits ) % dataSize;
/*
System.out.println( "size " + Integer.toString(bits)
+ " value " + Integer.toString(field)
+ " offset " + Integer.toString(bitOffset)
+ " currentWord " + Integer.toString( currentWord)
);
*/
}
}
return field;
}
private int getInt( byte[] pBytes)
{
long field = 0;
field = pBytes[0]<<24 | pBytes[1]<<16 | pBytes[2]<<8 | pBytes[3];
return (int) field;
}
/**
* doesn't work correctly as readInt
*/
private int readInt()
throws IOException
{
byte bytes[]=new byte[4];
int nr=0;
int index = 0;
/* read at least 4 bytes */
while ( ( nr != -1) && ( index < 4 ) )
{
nr = inputStream.read( bytes, index, 4 - index);
index +=nr;
}
return getInt( bytes);
}
private void nextWord() throws java.io.IOException {
// read next word
// currentWord = readInt();
currentWord= inputStream.readInt();
bitOffset = 0;
}
/*
go to next entire word.
*/
public void padToWord() throws java.io.IOException {
if ( bitOffset != 0) {
nextWord();
}
}
/* set InputStream */
public void setInputStream( InputStream input) {
inputStream = new DataInputStream(input);
}
}

View File

@@ -0,0 +1,125 @@
/*
This file is part of ShareDrawWeb.
ShareDrawWeb is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
ShareDrawWeb 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. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with ShareDrawWeb; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package org.artisanlogiciel.compression.graphics;
/*
simple class to write bitfields
@see BitFieldReader
@author Philippe Lhardy
*/
import java.io.*;
class BitFieldWriter {
// size of nextWord
final int dataSize = 32;
/* bitOffset is number of bits already used in word
should ensure bitOffset < dataSize
*/
private int bitOffset;
/* word used waiting to be filled to be written
dataSize is bit size of nextWord
*/
private int nextWord;
private DataOutputStream outputStream;
public void write( int field, int bits) throws java.io.IOException {
// if more bits needed that word currently used.
if ( bits + bitOffset > dataSize) {
// warning recursive call ( not terminal )
// fill and write current word
int bitsize = dataSize - bitOffset;
int head;
// most significant bits first
// suppress at left least significant bits
head = field >> (bits - bitsize);
write( head, dataSize - bitOffset);
// no need of newWord() previous write already done it
// least significant bits last
field = field & ( 0x7FFFFFFF >> ( bitsize - 1));
write( field, bits - bitsize);
}
else {
if ( bits == dataSize ) {
// special case to keep sign
nextWord = field;
bitOffset = 0;
}
else {
// keep only meaning part of field
field = field & ( 0x7FFFFFFF >> ( dataSize - 1 - bits));
nextWord = nextWord | ( field << ( dataSize - bits - bitOffset));
bitOffset = ( bitOffset + bits ) % dataSize;
}
// a new word is needed
if ( bitOffset == 0 ) {
newWord();
}
}
/*
System.out.println( "nextWord " + Integer.toString( nextWord) + " size "
+ Integer.toString( bits) + " field " + Integer.toString( field));
*/
}
/**
* seems to works correctly as DataOutputStream.writeInt()
*/
private void writeInt( int i)
throws IOException
{
long j = i;
byte bytes[]=new byte[4];
bytes[0] = (byte) ((j & 0xFF000000) >> 24);
bytes[1] = (byte) ((j & 0x00FF0000) >> 16);
bytes[2] = (byte) ((j & 0x0000FF00) >> 8);
bytes[3] = (byte) (j & 0x000000FF);
outputStream.write( bytes, 0, 4);
}
private void newWord() throws java.io.IOException {
// do really write current word;
//writeInt( nextWord);
outputStream.writeInt(nextWord);
// reset nextWord
bitOffset = 0;
nextWord = 0;
}
/*
write all current datas if any
to have a clean word ready.
*/
public void padToWord() throws java.io.IOException {
if ( bitOffset != 0) {
newWord();
}
}
/* set OutputStream */
public void setOutputStream( OutputStream output) {
outputStream = new DataOutputStream(output);
}
}

View File

@@ -0,0 +1,149 @@
/*
This file is part of ShareDrawWeb.
ShareDrawWeb is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
ShareDrawWeb 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. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with ShareDrawWeb; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/*
DrawingLineExpander
decompress a draw line from a stream
main algorithm is to code only delta displacement in littlest possible size.
*/
package org.artisanlogiciel.compression.graphics;
import java.awt.Point;
import java.io.InputStream;
import java.util.ArrayList;
public class DrawLineExpander {
ArrayList<Point> expandedLines;
int currentSize;
int scode[] = {3,6,14,30,64};
final static int SCODE_MAX = 4;
private BitFieldReader fieldReader = null;
public DrawLineExpander() {
expandedLines = new ArrayList<>();
fieldReader = new BitFieldReader();
}
/* create a List of points */
public ArrayList<Point> expand( InputStream input ) throws java.io.IOException {
fieldReader.setInputStream( input);
int point_count = fieldReader.read( 32);
// System.out.println( point_count);
expandedLines.add( readAbs( 64));
for ( int i = 1; i < point_count; i ++ ) {
Point point = readRel();
if ( currentSize == 64 ) {
// absolute
expandedLines.add( point);
}
else {
// relative
Point previous = (Point) expandedLines.get(expandedLines.size()-1);
point.x = point.x + previous.x;
point.y = point.y + previous.y;
expandedLines.add( point);
}
}
return expandedLines;
}
/*
read point with size encoding depending on first bits
*/
private Point readRel() throws java.io.IOException {
int index;
/* 11 : next, 10 : previous ; 0* : same
6 -> 14->30
^ |
| v
3 <- 64
*/
// find index of current size
for ( index = 0; index < SCODE_MAX; index ++) {
if ( scode[index] == currentSize ) break;
}
// read size modifier until it is good one
while ( fieldReader.read(1) != 0 ) {
index = index + ( ( fieldReader.read(1) == 0 ) ? -1 : 1);
// handle circularity
if ( index > SCODE_MAX ) {
index = 0;
}
if ( index < 0 ) {
index = SCODE_MAX;
}
}
return readAbs( scode[index]);
}
/* write given Point with size */
Point readAbs( int size) throws java.io.IOException {
int codeval;
int center, max;
currentSize = size;
Point point = new Point();
if ( size > 32 ) {
point.x = fieldReader.read(32);
point.y = fieldReader.read(32);
}
else {
boolean nocenter=false;
codeval = fieldReader.read( size);
// System.out.println( codeval);
/*
for coding/decoding scheme see
org.artisanlogiciel.graphics.DrawLineKompressor.java
*/
if ( size == 3 ) {
max = 3;
center = 1;
nocenter=true;
}
else {
max = ( 1 << ( size / 2 ) );
center = (max / 2) - 1;
}
// central hole impossible but we don't really care
if ( nocenter )
{
if ( codeval > ( center * max ) ) {
codeval ++;
}
if ( codeval >= ( max * max )) {
System.out.println(
"!!! reserved value for decompression should not occur !!!");
}
}
point.x = ( codeval % max) - center;
point.y = ( codeval / max) - center;
// System.out.println( point.toString());
}
return point;
}
}

View File

@@ -0,0 +1,256 @@
/*
This file is part of ShareDrawWeb.
ShareDrawWeb is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
ShareDrawWeb 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. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with ShareDrawWeb; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/*
DrawingLineKompressor
compress a draw line over a stream
main algorithm is to code only delta displacement in littlest possible size.
*/
package org.artisanlogiciel.compression.graphics;
import java.awt.Point;
import java.io.OutputStream;
import java.util.ArrayList;
public class DrawLineKompressor {
ArrayList<Point> fromLines;
int previousSize;
int scode[] = {3,6,14,30,64};
final static int SCODE_MAX = 4;
private BitFieldWriter fieldWriter = null;
public DrawLineKompressor( ArrayList<Point> lines) {
fromLines = lines;
fieldWriter = new BitFieldWriter();
}
public void kompress( OutputStream output ) throws java.io.IOException {
fieldWriter.setOutputStream( output);
int skipsame=0;
if ( ( fromLines != null) && ( fromLines.size() > 0)) {
Point topoint = null;
for ( int i = 1; i < fromLines.size(); i++) {
Point frompoint = (Point) fromLines.get( i);
if ( ( topoint != null ) && ( topoint.x == frompoint.x ) && ( topoint.y == frompoint.y ) )
{
skipsame ++;
}
topoint=frompoint;
}
if ( skipsame > 0 )
{
System.out.println("[WARNING] lines contains " + skipsame + " duplicates points");
}
}
if ( ( fromLines != null) && ( fromLines.size() > 0)) {
Point frompoint = (Point) fromLines.get(0);
Point point, topoint;
topoint = new Point();
int center, size;
fieldWriter.write( fromLines.size() - skipsame, 32);
writeAbs( frompoint, 64);
for ( int i = 1; i < fromLines.size(); i++) {
point = (Point) fromLines.get( i);
topoint.x = point.x - frompoint.x;
topoint.y = point.y - frompoint.y;
// find wich size to use...
if (( topoint.x == 0 ) && ( topoint.y == 0 ))
{
// ARGH THIS IS INVALID !
System.out.println("[ERROR] (0,0) point is invalid for compression !!!");
continue;
}
if ( (Math.abs( topoint.x) < 2) && (Math.abs(topoint.y) < 2)) {
writeRel( topoint, 3);
}
else {
size = 64;
for ( int index = 1; index < ( SCODE_MAX - 1 ); index ++) {
/* center = ( ( 1 << ( scode[index] / 2 ) ) - 1 ) / 2;
if ( (Math.abs(topoint.x) <= center)
&& (Math.abs(topoint.y) <= center))
{
size = scode[index];
}
*/
// center is biased there are more + than - , ex for 6bits :(x,y) within ( -3,4 ) x (-3,4)
center = 1 << ( ( scode[index] / 2 ) - 1 );
if ( ( topoint.x <= center ) && ( topoint.x > -center )
&& ( topoint.y <= center ) && ( topoint.y > -center ) )
{
size = scode[index];
// always take the smaller size.
break;
}
}
if ( size < 32 ) {
writeRel( topoint, size);
}
else {
// warning absolute
writeRel( point, 64);
}
}
// new frompoint is previous point
frompoint = point;
}
fieldWriter.padToWord();
}
}
/*
compute bits of size
*/
void writeRel( Point point, int size) throws java.io.IOException {
/*
System.out.println( "point " + point.toString());
System.out.println( "size " + Integer.toString( size));
*/
/* 11 : next, 10 : previous ; 0* : same
6 -> 14
^ |
| v
3 <- 64
*/
if ( size != previousSize) {
int cindex, pindex;
// find index of size
for ( cindex = 0; cindex < SCODE_MAX; cindex ++) {
if ( scode[cindex] == size ) break;
}
// find index of previous size
for ( pindex = 0; pindex < SCODE_MAX; pindex ++) {
if ( scode[pindex] == previousSize ) break;
}
if ( pindex < cindex ) {
/*
if way with = is better than - then use = next
else use - previous
0--<--pindex===>==cindex---<---SCODE_MAX
*/
if ( ((SCODE_MAX - cindex) + pindex ) > ( pindex - cindex ) ) {
// ( pindex - cindex ) times next
for ( ; pindex < cindex; pindex ++) {
fieldWriter.write( 3,2);
}
}
else {
// ((SCODE_MAX -cindex) + pindex ) fois previous
for ( pindex = SCODE_MAX - cindex + pindex; pindex > 0; pindex --) {
fieldWriter.write( 2,2);
}
}
}
else {
/*
if way with = is better than - then use = previous
else use - next
0-->--cindex===<==pindex--->---SCODE_MAX
*/
if ( ((SCODE_MAX - pindex) + cindex ) > cindex - pindex ) {
// ( cindex - pindex ) fois previous
for ( ; cindex < pindex; pindex --) {
fieldWriter.write( 2,2);
}
}
else {
// ((SCODE_MAX - pindex) + cindex ) fois next
for ( pindex = SCODE_MAX - pindex + cindex; pindex > 0; pindex --)
{
fieldWriter.write( 3,2);
}
}
}
}
// this is good size.
fieldWriter.write( 0,1);
writeAbs( point, size);
}
/* write given Point with size */
void writeAbs( Point point, int size) throws java.io.IOException {
int codeval;
int center, max;
previousSize = size;
if ( size > 32 ) {
fieldWriter.write( point.x, 32);
fieldWriter.write( point.y, 32);
}
else {
boolean nocenter = false;
/* size == 3 example :
X - >
Y 0 1 2
| 3 . 4-
v 5 6 7
specific application of general case bellow.
*/
/* X ->
Y 0
| 0 center max
v max
0 1 2 ...center.... (max - 1)
max 2 * max - 1
. (0,0) center * ( max + 1)
(max-1)*max -1 (max ^ 2) - 1
2 */
if ( size == 3 ) {
max = 3;
center = 1;
nocenter = true;
}
else {
max = ( 1 << ( size / 2 ) );
// biased center ( -center +1, center )
center = (max / 2) - 1;
}
/*
System.out.println( "size" + Integer.toString( size));
System.out.println( "max, center " + Integer.toString( max) + " " + Integer.toString( center));
System.out.println( "x, y " + Integer.toString( point.x) + " " + Integer.toString( point.y));
*/
codeval = point.x + center + (( point.y + center ) * max );
// central hole impossible BUT we should not really care ( in fact whole center square is impossible since covered by encoding with lower number of bits ) , avoid it only for size 3.
if (nocenter) {
if ( codeval == ( center * max ) + 1 ) {
System.out.println("!!! warning (0,0) point is invalid for compression !!!");
}
if ( codeval > (center * max) ){
codeval --;
}
}
// System.out.println( "code " + Integer.toString( codeval));
fieldWriter.write( codeval, size);
}
}
}

View File

@@ -0,0 +1,20 @@
/Brick.class
/BrickTextMapping.class
/DrawingGenerator.class
/LabyLayers.class
/LabyMap.class
/LabyModel.class
/Main.class
/Maze$1.class
/Maze$2.class
/Maze$3.class
/Maze.class
/MazeCreationListener.class
/MazeParamEditor.class
/MazeParams.class
/MazeParamsFixed.class
/MovesProvider.class
/Position.class
/PositionWithDepth.class
/WallsProvider.class
/XYGridIterator.class

View File

@@ -0,0 +1,26 @@
package org.artisanlogiciel.games.maze;
import org.artisanlogiciel.games.minetest.net.MiM;
import java.net.InetSocketAddress;
public class MainMim {
void minetestMime(String serverName, int port) {
MiM mim = new MiM(30002, new InetSocketAddress(serverName, port));
mim.launch();
}
public static void main(String pArgs[])
{
if ( pArgs.length > 1)
{
new MainMim().minetestMime(pArgs[0], Integer.parseInt(pArgs[1]));
}
else
{
System.err.println("[ERROR] please set minetest server hostname and port as arguments");
}
}
}

View File

@@ -307,9 +307,11 @@ public class Maze {
OsmReader reader = new OsmReader(infile.getCanonicalPath());
reader.read();
OsmToDrawing converter = new OsmToDrawing(reader, mulx,muly);
Drawing drawing = converter.getDrawing(reader.getWays());
Drawing ways = converter.getDrawing(reader.getWays());
Drawing buildings = converter.getDrawing(reader.getBuildings());
setStatusEnable(false);
addDrawing(drawing,add);
addDrawing(ways,add);
addDrawing(buildings,add);
setStatusEnable(true);
} catch (IOException io) {
io.printStackTrace(System.err);

View File

@@ -0,0 +1,44 @@
/CellGridComponent.class
/Display$1.class
/Display$2.class
/Display$3.class
/Display$MazeFrame.class
/Display.class
/HexagonCellRenderer$UV.class
/HexagonCellRenderer.class
/Maze3dSettings.class
/MazeCellRenderer.class
/MazeColorMap.class
/MazeComponent.class
/MazeControler$1.class
/MazeControler$10.class
/MazeControler$11.class
/MazeControler$12.class
/MazeControler$13.class
/MazeControler$14.class
/MazeControler$15.class
/MazeControler$16.class
/MazeControler$17.class
/MazeControler$18.class
/MazeControler$19.class
/MazeControler$2.class
/MazeControler$20.class
/MazeControler$21.class
/MazeControler$22.class
/MazeControler$23.class
/MazeControler$24.class
/MazeControler$25.class
/MazeControler$26.class
/MazeControler$27.class
/MazeControler$3.class
/MazeControler$4.class
/MazeControler$5.class
/MazeControler$6.class
/MazeControler$7.class
/MazeControler$8.class
/MazeControler$9.class
/MazeControler.class
/MazeDefault.class
/MazeSettings$1.class
/MazeSettings.class
/StatusListener.class

View File

@@ -4,6 +4,7 @@ import org.artisanlogiciel.games.maze.*;
import org.artisanlogiciel.games.maze.model.WidthHeightProvider;
import org.artisanlogiciel.games.maze.persist.MazePersistRaw;
import org.artisanlogiciel.games.maze.solve.SolvingModel;
import org.artisanlogiciel.games.minetest.net.MiM;
import org.artisanlogiciel.graphics.Drawing;
import org.artisanlogiciel.xpm.Xpm;
@@ -14,6 +15,7 @@ import java.awt.image.BufferedImage;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.net.InetSocketAddress;
import java.util.Locale;
/**
@@ -270,6 +272,7 @@ implements StatusListener
}
};
System.out.println("Default Locale " + Locale.getDefault());
if ((pArgs.length > 0) && (pArgs[0].length() > 0)) {

View File

@@ -31,13 +31,13 @@ public class Maze3dSettings
void createSettingsGui() {
if (params != null) {
IntegerField xl = new IntegerField("width",params.getXl());
xl = new IntegerField("width",params.getXl());
addField(xl);
IntegerField zl = new IntegerField("height",params.getZl());
zl = new IntegerField("height",params.getZl());
addField(zl);
IntegerField yl = new IntegerField("depth",params.getYl());
yl = new IntegerField("depth",params.getYl());
addField(yl);
reverse = new JCheckBox("reverse",params.isReverse());
@@ -52,6 +52,9 @@ public class Maze3dSettings
hg = new IntegerField(params.getHg());
addField(hg);
}
else {
System.err.println("params null");
}
}
Maze3dParams createParams()

View File

@@ -0,0 +1,2 @@
/IntegerField.class
/Panel.class

View File

@@ -0,0 +1,9 @@
/BooleanLongSet.class
/HalfSquareModelCreator$SetXY.class
/HalfSquareModelCreator.class
/HalfSquareProvider.class
/HalfSquareRasterModel.class
/HexagonModelProvider.class
/LabyModelProvider.class
/LineColumnModel.class
/WidthHeightProvider.class

View File

@@ -6,7 +6,7 @@ import org.artisanlogiciel.games.maze.WallsProvider;
/**
* minimal model without repetition
* keep only left and down wall and rely on neightbor squeres to obtain right and up
* keep only left and down wall and rely on neightbor squares to obtain right and up
* left down compatible with Bricks
*
* LEFT 01

View File

@@ -0,0 +1,3 @@
/HalfSquareRasterModelPersistRaw.class
/MazePersistRaw.class
/MazePersistWorldEdit.class

View File

@@ -0,0 +1,3 @@
/DirectionPosition.class
/MazeResolutionListener.class
/SolvingModel.class

View File

@@ -0,0 +1,8 @@
/Material.class
/Node.class
/Range.class
/Raw.class
/Slice.class
/WorlEditGenerator.class
/World.class
/WorldEditReader.class

View File

@@ -0,0 +1,97 @@
package org.artisanlogiciel.games.minetest;
import com.github.luben.zstd.Zstd;
import org.artisanlogiciel.games.minetest.core.Constant;
import org.artisanlogiciel.games.minetest.core.PacketException;
import org.artisanlogiciel.games.minetest.core.Serialize;
import java.nio.ByteBuffer;
import java.util.ArrayList;
/**
* A block of nodes of MAP_BLOCKSIZE in any x,y,z direction
*/
public class MapBlock {
final static int nodecount = Constant.MAP_BLOCKSIZE * Constant.MAP_BLOCKSIZE * Constant.MAP_BLOCKSIZE;
int m_lighting_complete;
ArrayList<MapNode> nodes;
ArrayList<MapNode> getNodes()
{
if ( nodes == null )
{
nodes = new ArrayList<>(nodecount);
}
return nodes;
}
// in memory case
public void deSerialize(ByteBuffer buffer, int version)
throws PacketException
{
int flags = 0;
int content_width = 0;
int params_width = 0;
if ( version >= 29) {
// ByteBuffer byteBuffer = ByteBuffer.wrap(networkPacket.getBuffer(),offset,networkPacket.getLength() - offset);
/*
// force to have a direct buffer.
ByteBuffer byteBuffer = ByteBuffer.allocateDirect(networkPacket.getLength());
byteBuffer.put(networkPacket.getBuffer());
byteBuffer.position(networkPacket.getOffset());
//System.arraycopy(networkPacket.getBuffer(), 0, byteBuffer.array(), 0, length);
// zstd compression
// FIXME, can we know original size ? somehow related to BLOCKSIZE³
long originalSizeMax = Zstd.decompressedSize(byteBuffer);
System.out.println(String.format("originalSizeMax=%d", originalSizeMax));
ByteBuffer decompressed = Zstd.decompress(byteBuffer,(int) originalSizeMax);
*/
byte out[] = new byte[16386];
long outLength = Zstd.decompressByteArray(out, 0, out.length, buffer.array(), buffer.arrayOffset(), buffer.limit());
// Should be a MapBlock
MapBlock block = new MapBlock();
ByteBuffer decompressed = ByteBuffer.wrap(out, 0, (int) outLength);
buffer = decompressed;
}
flags = Serialize.readU8(buffer);
if ( version >= 27 ) {
m_lighting_complete = Serialize.readU16(buffer);
}
content_width = Serialize.readU8(buffer);
params_width = Serialize.readU8(buffer);
System.out.println(String.format(" flags %x lightning_complete %d content_witd %d params_width %d ",flags, m_lighting_complete, content_width, params_width));
if (( version < 29 ) && ( version >= 11 ))
{
// ZLib decompression
try {
byte decompressed[] = Serialize.decompress(buffer);
buffer = ByteBuffer.wrap(decompressed);
}
catch ( Exception e)
{
// TODO
System.err.println(e);
e.printStackTrace(System.err);
return;
}
}
nodes = getNodes();
MapNode.deSerializeBulk(buffer,version, nodes,nodecount,content_width,params_width);
//m_node_metadata.deSerialize(is, m_gamedef->idef());
}
}

View File

@@ -0,0 +1,99 @@
package org.artisanlogiciel.games.minetest;
import org.artisanlogiciel.games.minetest.core.PacketException;
import org.artisanlogiciel.games.minetest.core.Serialize;
import java.nio.ByteBuffer;
import java.util.List;
public class MapNode {
/*
Main content
*/
short param0;
/*
Misc parameter. Initialized to 0.
- For light_propagates() blocks, this is light intensity,
stored logarithmically from 0 to LIGHT_MAX.
Sunlight is LIGHT_SUN, which is LIGHT_MAX+1.
- Contains 2 values, day- and night lighting. Each takes 4 bits.
- Uhh... well, most blocks have light or nothing in here.
*/
byte param1;
/*
The second parameter. Initialized to 0.
E.g. direction for torches and flowing water.
*/
byte param2;
public void deSerialize(ByteBuffer buffer)
throws PacketException
{
// version >= 24
param0 = (short) Serialize.readU16(buffer);
buffer.position(buffer.position() + 2);
param1 = (byte) Serialize.readU8(buffer);
buffer.position(buffer.position() + 1);
param2 = (byte) Serialize.readU8(buffer);
// network specific ...
// readU8(is);
}
// Deserialize bulk node data
public static void deSerializeBulk(ByteBuffer buffer, int version,
List<MapNode> nodes, int nodecount,
int content_width, int params_width)
throws PacketException
{
byte[] intern = buffer.array();
int initialOffset = buffer.position();
// Deserialize content
if(content_width == 1)
{
for(int i=0; i<nodecount; i++) {
nodes.add(i, new MapNode());
nodes.get(i).param0 = (short) Serialize.readU8( intern, initialOffset + i, intern.length);
}
}
else if(content_width == 2)
{
for(int i=0; i<nodecount; i++) {
nodes.add(i, new MapNode());
nodes.get(i).param0 = (short) Serialize.readU8( intern, initialOffset + (i*2), intern.length);
}
}
// Deserialize param1
int start1 = initialOffset + (content_width * nodecount);
for(int i=0; i<nodecount; i++) {
nodes.get(i).param1 = (byte) Serialize.readU8( intern, start1 + i, intern.length);
}
// Deserialize param2
int start2 = initialOffset + ((content_width + 1) * nodecount);
if(content_width == 1)
{
for(int i=0; i<nodecount; i++) {
MapNode node = nodes.get(i);
node.param2 = (byte) Serialize.readU8( intern, start2 + i, intern.length);
if(node.param0 > 0x7F){
node.param0 <<= 4;
node.param0 |= (node.param2&0xF0)>>4;
node.param2 &= 0x0F;
}
}
}
else if(content_width == 2)
{
for(int i=0; i<nodecount; i++) {
nodes.get(i).param2 = (byte) Serialize.readU8(intern, start2 + i, intern.length);
}
}
}
}

View File

@@ -3,6 +3,7 @@ package org.artisanlogiciel.games.minetest;
import java.util.HashMap;
public class Node {
// could be a core.v3s16
int x;
int y;
int z;

View File

@@ -0,0 +1,6 @@
package org.artisanlogiciel.games.minetest.core;
public class Constant {
public final static int MAP_BLOCKSIZE = 16;
}

View File

@@ -0,0 +1,10 @@
package org.artisanlogiciel.games.minetest.core;
public class PacketException
extends Exception
{
public PacketException(String message)
{
super(message);
}
}

View File

@@ -0,0 +1,116 @@
package org.artisanlogiciel.games.minetest.core;
import java.io.ByteArrayOutputStream;
import java.nio.ByteBuffer;
import java.util.zip.Inflater;
public class Serialize {
public final static int BUFFER_SIZE = 16386;
public static int readS16(byte buffer[], int offset, int length)
throws PacketException
{
if ( offset + 2 < length) {
return 256 * buffer[offset] + buffer[offset + 1];
}
else
{
throw new PacketException("out of bound offset U16");
}
}
// MSB network order
public static int readU32(byte[] buffer, int offset, int length)
throws PacketException
{
if ( offset + 4 < length) {
return 16777216 * Byte.toUnsignedInt(buffer[offset]) +
65536 * Byte.toUnsignedInt(buffer[offset + 1]) +
256 * Byte.toUnsignedInt(buffer[offset + 2]) +
Byte.toUnsignedInt(buffer[offset + 3]);
}
else
{
throw new PacketException("out of bound offset U32");
}
}
// MSB network order
public static int readU16(byte[] buffer, int offset, int length)
throws PacketException
{
if ( offset + 2 < length) {
return 256 * Byte.toUnsignedInt(buffer[offset]) +
Byte.toUnsignedInt(buffer[offset + 1]);
}
else
{
throw new PacketException("out of bound offset U16");
}
}
// will update position
public static int readU16(ByteBuffer byteBuffer)
throws PacketException
{
int u16 = readU16(byteBuffer.array(), byteBuffer.position(), byteBuffer.array().length);
byteBuffer.position(byteBuffer.position()+2);
return u16;
}
public static int readU8(byte[] buffer, int offset, int length)
throws PacketException
{
if ( offset + 1 < length) {
return Byte.toUnsignedInt(buffer[offset]);
}
else
{
throw new PacketException("out of bound offset U8");
}
}
// will update position
public static int readU8(ByteBuffer byteBuffer)
throws PacketException
{
int u8 = readU8(byteBuffer.array(), byteBuffer.position(), byteBuffer.array().length);
byteBuffer.position(byteBuffer.position()+1);
return u8;
}
public static v3s16 readV3S16(byte buffer[], int offset, int length)
throws PacketException
{
if ( offset + 6 <= length) {
int x = readS16(buffer, offset, length);
int y = readS16(buffer, offset + 2, length);
int z = readS16(buffer, offset + 4, length);
return new v3s16(x, y, z);
}
else
{
throw new PacketException("out of bound offset v3s16");
}
}
// Zlib decompression
public static byte[] decompress(ByteBuffer byteBuffer) throws Exception
{
final Inflater inflater = new Inflater(false);
inflater.setInput(byteBuffer.array(), byteBuffer.position(), byteBuffer.limit() - byteBuffer.position());
try (final ByteArrayOutputStream outputStream = new ByteArrayOutputStream(byteBuffer.limit()))
{
byte[] buffer = new byte[BUFFER_SIZE];
while (!inflater.finished())
{
final int count = inflater.inflate(buffer);
outputStream.write(buffer, 0, count);
}
return outputStream.toByteArray();
}
}
}

View File

@@ -0,0 +1,13 @@
package org.artisanlogiciel.games.minetest.core;
public class v2s16 {
public int X;
public int Y;
public v2s16(int x, int y) {
X = x;
Y = y;
}
}

View File

@@ -0,0 +1,14 @@
package org.artisanlogiciel.games.minetest.core;
public class v3s16 {
public int X;
public int Y;
public int Z;
public v3s16(int x, int y, int z) {
X = x;
Y = y;
Z = z;
}
}

View File

@@ -0,0 +1,4 @@
package org.artisanlogiciel.games.minetest.net;
public class Address {
}

View File

@@ -0,0 +1,28 @@
package org.artisanlogiciel.games.minetest.net;
import org.artisanlogiciel.games.minetest.core.PacketException;
import org.artisanlogiciel.games.minetest.core.Serialize;
public class BufferedPacket {
public static int BASE_HEADER_SIZE = 7;
// Data of the packet, including headers
byte[] m_data;
BufferedPacket(byte[] data)
{
m_data = data;
}
int getSeqNum()
throws PacketException
{
return Serialize.readU16(m_data, BASE_HEADER_SIZE + 1, size());
}
int size()
{
return m_data.length;
}
}

View File

@@ -0,0 +1,9 @@
package org.artisanlogiciel.games.minetest.net;
public class Channel {
int readNextIncomingSeqNum()
{
return 0;
}
}

View File

@@ -0,0 +1,45 @@
package org.artisanlogiciel.games.minetest.net;
public class ConnectionEvent {
ConnectionEventType m_event_type;
int m_peer_id;
byte[] m_data;
boolean m_timeout;
ConnectionEvent(ConnectionEventType eventType)
{
m_event_type = eventType;
}
String describe()
{
return m_event_type.toString();
}
ConnectionEventPtr create(ConnectionEventType type)
{
return null;
}
ConnectionEventPtr dataReceived(int peer_id, byte[] data)
{
return null;
}
ConnectionEventPtr peerAdded(int peer_id, Address address)
{
return null;
}
ConnectionEventPtr peerRemoved(int peer_id, boolean is_timeout, Address address)
{
return null;
}
ConnectionEventPtr bindFailed()
{
return null;
}
}

View File

@@ -0,0 +1,4 @@
package org.artisanlogiciel.games.minetest.net;
public class ConnectionEventPtr {
}

View File

@@ -0,0 +1,9 @@
package org.artisanlogiciel.games.minetest.net;
public enum ConnectionEventType {
CONNEVENT_NONE,
CONNEVENT_DATA_RECEIVED,
CONNEVENT_PEER_ADDED,
CONNEVENT_PEER_REMOVED,
CONNEVENT_BIND_FAILED
}

View File

@@ -0,0 +1,90 @@
package org.artisanlogiciel.games.minetest.net;
import org.artisanlogiciel.games.minetest.core.PacketException;
import org.artisanlogiciel.games.minetest.core.Serialize;
import java.util.ArrayList;
public class IncomingSplitBuffer {
int m_seqnum;
int m_chunk_count;
int m_chunk_num;
// number of chunks
int m_got = 0;
NetworkPacket m_list[] = null;
BufferedPacket m_reassembled = null;
BufferedPacket insert(NetworkPacket networkPacket)
throws PacketException
{
byte[] buffer = networkPacket.getBuffer();
int length = networkPacket.getLength();
int offset = networkPacket.getOffset();
int type = Serialize.readU8(buffer , offset, length);
int seqnum = Serialize.readU16(buffer, offset + 1, length);
// total number of chunk
int chunk_count = Serialize.readU16(buffer, offset + 3, length);
// this chunk number
int chunk_num = Serialize.readU16(buffer, offset+ 5, length);
System.out.println("Split length " + length + " type " + type + " seqnum " + seqnum + " chunk_num/chunk_count " + chunk_num + "/" + chunk_count );
// move to next header
networkPacket.addOffset(7);
if (m_reassembled != null)
{
return m_reassembled;
}
if (m_list == null )
{
m_list = new NetworkPacket[chunk_count];
}
if ( chunk_num < chunk_count && (m_list[chunk_num] == null) )
{
m_list[chunk_num] = networkPacket;
m_got ++;
}
//todo seqnum
m_seqnum = seqnum;
// fully obtained
if ( m_got == chunk_count )
{
reassemble();
}
return m_reassembled;
}
private void reassemble()
{
// keep first header since result is a valid BufferedPacket
int fullLength = BufferedPacket.BASE_HEADER_SIZE;
for (NetworkPacket networkPacket : m_list )
{
fullLength += networkPacket.getLength() - networkPacket.getOffset();
}
byte[] reassembled = new byte[fullLength];
NetworkPacket first = m_list[0];
System.arraycopy(first.getBuffer(),0,reassembled,0,BufferedPacket.BASE_HEADER_SIZE);
int offset = BufferedPacket.BASE_HEADER_SIZE;
for (NetworkPacket networkPacket : m_list )
{
int dataLength = networkPacket.getLength() - networkPacket.getOffset();
System.arraycopy(networkPacket.getBuffer(), networkPacket.getOffset(),reassembled,offset,dataLength);
offset+=dataLength;
}
m_reassembled = new BufferedPacket(reassembled);
}
}

View File

@@ -0,0 +1,127 @@
package org.artisanlogiciel.games.minetest.net;
import org.artisanlogiciel.games.minetest.core.PacketException;
import java.io.IOException;
import java.net.*;
/**
* Man in the middle UDP
* very simple for one client only
*/
public class MiM {
DatagramSocket serverSocket;
boolean running = false;
InetSocketAddress serverAddress;
// will be captured, incoming address & port
SocketAddress fromClient = null;
int localPort;
PacketHandler handler = null;
public MiM(int myPort, InetSocketAddress remoteAddress)
{
localPort = myPort;
serverAddress = remoteAddress;
}
public void launch()
{
// ServerSocket socket = new ServerSocket()
try {
handler = new PacketHandler();
serverSocket = new DatagramSocket(localPort);
DatagramSocket in = serverSocket;
SocketAddress fromServer = serverAddress;
Thread toServer = new Thread( () -> {runFromToServer(in,fromServer);});
running = true;
toServer.start();
}
catch(Exception e)
{
System.out.println("problem");
e.printStackTrace(System.err);
running = false;
}
}
public void stop()
{
running = false;
}
public void runFromToServer(DatagramSocket in, SocketAddress fromServer) {
try {
while (running) {
// quick way, a new buffer at each reception
// to handle split packets that are buffered
byte[] buf = new byte[4096];
SocketAddress toRemote = null;
DatagramPacket packet = new DatagramPacket(buf, buf.length);
in.receive(packet);
SocketAddress from = packet.getSocketAddress();
if ( from.equals(fromServer)) {
// no client yet
if ( fromClient == null )
{
continue;
}
fromServer(buf,packet.getLength());
toRemote = fromClient;
}
else
{
// record client
// later on to be smart : could try to record peer id ?
// will add a constraint : only one auth at a time
if ( fromClient == null ) {
fromClient = from;
}
fromClient(buf,packet.getLength());
toRemote = fromServer;
}
packet = new DatagramPacket(buf, packet.getLength(), toRemote);
in.send(packet);
}
}
catch( IOException ioException)
{
//
System.out.println("oops");
}
// socket.close();
}
void fromServer(byte[] buffer, int length)
{
try {
// reply from server
if (handler != null) {
handler.fromServer(buffer, length);
}
}
catch (PacketException packetException)
{
//
}
}
void fromClient(byte[] buffer, int length)
{
try {
// reply from client
if (handler != null) {
handler.fromClient(buffer, length);
}
}
catch (PacketException packetException)
{
//
}
}
}

View File

@@ -0,0 +1,70 @@
package org.artisanlogiciel.games.minetest.net;
import org.artisanlogiciel.games.minetest.core.PacketException;
import org.artisanlogiciel.games.minetest.core.Serialize;
import org.artisanlogiciel.games.minetest.core.v3s16;
import java.nio.ByteBuffer;
public class NetworkPacket {
int m_protocol_id;
int m_peer_id;
int m_channel;
public PacketType packetType;
// somehow a BufferedPacket ...
byte[] m_buffer; // m_data
// used part in buffer
int m_length; // m_datasize ?
// current header index in packet
int m_offset; // m_read_offset
short m_command = 0;
public NetworkPacket(int protocol_id, int peer_id, int channel, PacketType type, byte[] buffer, int length) {
this.m_protocol_id = protocol_id;
this.m_peer_id = peer_id;
this.m_channel = channel;
this.packetType = type;
m_buffer = buffer;
m_length = length;
m_offset = 0;
}
public int getChannel()
{
return m_channel;
}
public byte[] getBuffer()
{
return m_buffer;
}
public int getOffset() {
return m_offset;
}
public int getLength() {
return m_length;
}
void addOffset(int offset)
{
m_offset += offset;
}
// Serialization
public v3s16 v3s16()
throws PacketException
{
return Serialize.readV3S16(m_buffer, m_offset, m_length);
}
public ByteBuffer getByteBuffer()
{
ByteBuffer buffer = ByteBuffer.wrap(m_buffer,m_offset,m_length-m_offset);
return buffer;
}
}

View File

@@ -0,0 +1,287 @@
package org.artisanlogiciel.games.minetest.net;
import com.github.luben.zstd.Zstd;
import org.artisanlogiciel.games.minetest.MapBlock;
import org.artisanlogiciel.games.minetest.MapNode;
import org.artisanlogiciel.games.minetest.core.PacketException;
import org.artisanlogiciel.games.minetest.core.Serialize;
import org.artisanlogiciel.games.minetest.core.v2s16;
import org.artisanlogiciel.games.minetest.core.v3s16;
import java.nio.ByteBuffer;
/**
* see src/network/networkprotocol.h of minetest sources
*
*
* === NOTES ===
*
* A packet is sent through a channel to a peer with a basic header:
* Header (7 bytes):
* [0] u32 protocol_id
* [4] session_t sender_peer_id
* [6] u8 channel
* sender_peer_id:
* Unique to each peer.
* value 0 (PEER_ID_INEXISTENT) is reserved for making new connections
* value 1 (PEER_ID_SERVER) is reserved for server
* these constants are defined in constants.h
* channel:
* Channel numbers have no intrinsic meaning. Currently only 0, 1, 2 exist.
*
*
* */
public class PacketHandler {
ReliablePacketBuffer reliableBuffer = null;
IncomingSplitBuffer[] incomingChanneleSplitBuffer = new IncomingSplitBuffer[4];
// server serialization in hello version
int ser_version;
// minetest protocol should be 0x4f457403
static int readProtocolId(byte[] buffer, int length)
throws PacketException
{
return Serialize.readU32(buffer, 0, length);
}
static int readPeerId(byte[] buffer, int length)
throws PacketException
{
return Serialize.readU16(buffer,4,length);
}
static int readChannel(byte[] buffer, int length)
throws PacketException
{
return Serialize.readU8(buffer, 6, length);
}
NetworkPacket handleAny(byte[] buffer, int length)
throws PacketException
{
int protocol_id = readProtocolId(buffer, length);
int peer_id = readPeerId(buffer, length);
int channel = readChannel(buffer, length);
int type = Serialize.readU8(buffer,7,length);
PacketType packetType = PacketType.getPacketType(type);
NetworkPacket networkPacket = new NetworkPacket(protocol_id,peer_id,channel,packetType, buffer, length);
// offset of packet within buffer.
networkPacket.addOffset(BufferedPacket.BASE_HEADER_SIZE);
System.out.println("length " + length + " protocol_id " + String.format("%x", protocol_id) + " peer_id " + peer_id + " channel " + channel + " type " + packetType);
return networkPacket;
}
void handlePacketType_Control(NetworkPacket networkPacket)
throws PacketException {
}
void handlePacketType_Reliable(NetworkPacket networkPacket)
throws PacketException
{
// TODO handle misordered...
/*
if ( reliableBuffer == null )
{
reliableBuffer = new ReliablePacketBuffer();
}
BufferedPacket packet = new BufferedPacket(buffer);
int nextExpected = 0;
reliableBuffer.insert(packet, nextExpected);
*/
// handle nested packet
networkPacket.addOffset(3);
int offset = networkPacket.getOffset();
byte buffer[] = networkPacket.getBuffer();
int length = networkPacket.getLength();
PacketType packetType = PacketType.getPacketType(Serialize.readU8(buffer,offset,length));
System.out.println( "reliable " + packetType.toString());
switch (packetType)
{
case PACKET_TYPE_CONTROL:
//
handlePacketType_Control(networkPacket);
break;
case PACKET_TYPE_ORIGINAL:
handlePacketType_Original(networkPacket);
break;
case PACKET_TYPE_SPLIT:
handlePacketType_Split(networkPacket);
break;
case PACKET_TYPE_RELIABLE:
// this is an error, no nested reliable accepted.
throw new PacketException("nested reliable");
default: // error
throw new PacketException("unknown type");
}
}
void handleCommand_Hello(NetworkPacket networkPacket)
throws PacketException {
// u8 deployed serialisation version
ByteBuffer buffer = networkPacket.getByteBuffer();
int ser_ver = Serialize.readU8(buffer);
ser_version = ser_ver;
// u16 deployed network compression mode
int net_compress = Serialize.readU16(buffer);
// u16 deployed protocol version
int deployed = Serialize.readU16(buffer);
System.out.println(String.format("HELLO ser_ver=%d net_compress %d deployed %d", ser_ver,net_compress,deployed));
// u32 supported auth methods
// std::string username that should be used for legacy hash (for proper casing)
}
// clientpackethandler.cpp Client::handleCommand_BlockData(NetworkPacket* pkt)
// TOCLIENT_BLOCKDATA
void handleCommand_BlockData(NetworkPacket networkPacket)
throws PacketException
{
v3s16 p = networkPacket.v3s16();
// will be used to get vector...
// v2s16 p2d = new v2s16(p.X,p.Z);
System.out.println(String.format(" (X,Y,Z) %d %d %d", p.X, p.Y,p.Z));
//
networkPacket.addOffset(6);
// FIXME get it from handshake
int version = 28;
// Should be a MapBlock
MapBlock block = new MapBlock();
block.deSerialize(networkPacket.getByteBuffer(),version);
// now we have a block ! what to do with it ?
}
void handlePacketCommand(NetworkPacket networkPacket)
throws PacketException {
// consume type and ??? well ... 2
int command = Serialize.readU16(networkPacket.getBuffer(),networkPacket.getOffset(),networkPacket.getLength());
System.out.println(String.format("command %x length %d", command, networkPacket.getLength()));
networkPacket.addOffset(2);
// Original ... toClient - toServer
switch (command)
{
case 0x02:
{
System.out.println("TOCLIENT_HELLO");
handleCommand_Hello(networkPacket);
}
break;
case 0x20:
{
System.out.println("TOCLIENT_BLOCKDATA");
handleCommand_BlockData(networkPacket);
}
break;
case 0x4f:
{
//TOCLIENT_SET_SKY = 0x4f,
System.out.println("TOCLIENT_SET_SKY");
}
break;
}
}
void handlePacketType_Original(NetworkPacket networkPacket)
throws PacketException {
// eat original type 1.
networkPacket.addOffset(1);
handlePacketCommand(networkPacket);
}
void handlePacketType_Split(NetworkPacket networkPacket)
throws PacketException {
int channel = networkPacket.getChannel();
if ( channel < incomingChanneleSplitBuffer.length) {
IncomingSplitBuffer splitBuffer = incomingChanneleSplitBuffer[channel];
if ( splitBuffer == null )
{
splitBuffer = new IncomingSplitBuffer();
incomingChanneleSplitBuffer[channel] = splitBuffer;
}
if ( splitBuffer != null ) {
BufferedPacket bufferedPacket = splitBuffer.insert(networkPacket);
if ( bufferedPacket != null ) {
// well should handle it.
System.out.println("Reassembled packet size " + bufferedPacket.m_data.length);
// reset it.
incomingChanneleSplitBuffer[channel] = new IncomingSplitBuffer();
handleBufferedPacket(bufferedPacket);
}
}
}
else {
throw new PacketException("invalid channel " + channel);
}
}
void handleBufferedPacket(BufferedPacket bufferedPacket)
throws PacketException
{
// FIXME, why a BufferedPacket anyway since we finaly need a NetworkPacket ?
NetworkPacket networkPacket = new NetworkPacket(0,0,0, PacketType.PACKET_TYPE_ORIGINAL,bufferedPacket.m_data, bufferedPacket.size());
networkPacket.addOffset(BufferedPacket.BASE_HEADER_SIZE);
handlePacketCommand(networkPacket);
}
void fromServer(byte[] buffer, int length)
throws PacketException
{
System.out.print(" <- ");
NetworkPacket networkPacket = handleAny(buffer,length);
switch (networkPacket.packetType)
{
case PACKET_TYPE_CONTROL:
//
handlePacketType_Control(networkPacket);
break;
case PACKET_TYPE_RELIABLE:
//
handlePacketType_Reliable(networkPacket);
break;
case PACKET_TYPE_ORIGINAL:
handlePacketType_Original(networkPacket);
break;
case PACKET_TYPE_SPLIT:
handlePacketType_Split(networkPacket);
break;
default: // error
throw new PacketException("unknown type");
}
}
void fromClient(byte[] buffer, int length)
throws PacketException
{
System.out.print(" -> ");
handleAny(buffer,length);
}
}

View File

@@ -0,0 +1,27 @@
package org.artisanlogiciel.games.minetest.net;
public enum PacketType {
PACKET_TYPE_CONTROL,
PACKET_TYPE_ORIGINAL,
PACKET_TYPE_SPLIT,
PACKET_TYPE_RELIABLE,
PACKET_TYPE_ERROR;
static PacketType getPacketType(int value)
{
switch (value)
{
case 0:
return PACKET_TYPE_CONTROL;
case 1:
return PACKET_TYPE_ORIGINAL;
case 2:
return PACKET_TYPE_SPLIT;
case 3:
return PACKET_TYPE_RELIABLE;
default:
return PACKET_TYPE_ERROR;
}
}
}

View File

@@ -0,0 +1,20 @@
package org.artisanlogiciel.games.minetest.net;
import org.artisanlogiciel.games.minetest.core.PacketException;
import java.util.LinkedList;
import java.util.List;
public class ReliablePacketBuffer {
List<BufferedPacket> m_list = new LinkedList<>();
void insert(BufferedPacket packet, int nextExpected)
throws PacketException
{
//
int seqNum = packet.getSeqNum();
m_list.add(packet);
}
}

View File

@@ -0,0 +1,3 @@
/Maze3dParams.class
/Wall3d.class
/Wall3dStream.class

View File

@@ -0,0 +1,28 @@
/*
This file is part of ShareDrawWeb.
ShareDrawWeb is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
ShareDrawWeb 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. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with ShareDrawWeb; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package org.artisanlogiciel.graphics;
import java.io.Serializable;
public class DrawException extends Exception implements Serializable {
public DrawException() {
super();
}
}

View File

@@ -0,0 +1,106 @@
/**
Drawing
contains a set of DrawingLine to create a Drawing
- feature of load / save
*/
package org.artisanlogiciel.graphics;
import java.awt.Graphics;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.util.ArrayList;
import org.artisanlogiciel.graphics.Importer;
import org.artisanlogiciel.graphics.ResetException;
import org.artisanlogiciel.graphics.NoMoreLineException;
public class Drawing
{
private ArrayList<DrawingLine> lines;
public Drawing()
{
reset();
}
public void reset() {
lines = new ArrayList<DrawingLine>(10);
}
public void addLine( DrawingLine line) {
lines.add( line);
}
public void saveLines( DataOutputStream destination) throws
java.io.IOException {
destination.writeInt( lines.size());
for ( DrawingLine line : lines )
{
line.save( destination);
}
}
public void loadLines( DataInputStream source) throws
java.io.IOException {
int nb_lines = source.readInt();
DrawingLine line;
for ( int i = 0; i < nb_lines; i++ ) {
line = new DrawingLine();
line.load( source);
lines.add( line);
}
}
public void importImage( Importer importer) throws
java.io.IOException
{
importer.importInto(this);
}
public void saveLinesKompressed( DataOutputStream destination) throws
java.io.IOException {
destination.writeInt( lines.size());
for ( DrawingLine line : lines )
{
line.saveKompressed( destination);
}
}
public void loadLinesExpanded( DataInputStream source) throws
java.io.IOException {
// DrawLineExpander expander = new DrawLineExpander();
int nb_lines = source.readInt();
DrawingLine line;
for ( int i = 0; i < nb_lines; i++ ) {
line = new DrawingLine();
line.loadExpanded( source);
lines.add( line);
}
}
public int length() {
return lines.size();
}
public DrawingLine getLine( int line) throws ResetException, NoMoreLineException {
if ( line == lines.size() ) {
throw new NoMoreLineException();
}
if ( line > lines.size() ) {
throw new ResetException();
}
return lines.get( line);
}
public ArrayList<DrawingLine> getLines() {
return new ArrayList<DrawingLine>(lines);
}
/** Not a copy, use with care */
public ArrayList<DrawingLine> getInternLines() {
return lines;
}
}

View File

@@ -0,0 +1,96 @@
/**
DrawingLine
keep track of list of Points constituting a line
*/
package org.artisanlogiciel.graphics;
import java.awt.Point;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.Serializable;
import java.util.ArrayList;
import org.artisanlogiciel.compression.graphics.DrawLineExpander;
import org.artisanlogiciel.compression.graphics.DrawLineKompressor;
public class DrawingLine implements Cloneable, Serializable
{
ArrayList<Point> lines;
public DrawingLine() {
lines = new ArrayList<>();
}
public void addPoint( Point point) {
lines.add( point);
}
public void setPoints( ArrayList<Point> points) {
lines = points;
}
public Object clone() throws java.lang.CloneNotSupportedException {
return super.clone();
}
private void writePoint( Point p, DataOutputStream destination) throws
java.io.IOException {
destination.writeInt( p.x);
destination.writeInt( p.y);
}
private void readPoint( DataInputStream source) throws java.io.IOException {
Point point = new Point( source.readInt(), source.readInt());
lines.add( point);
}
public void save( DataOutputStream destination) throws
java.io.IOException {
destination.writeInt( lines.size());
for (int i=0; i < lines.size(); i++) {
writePoint( (Point) lines.get(i), destination);
}
}
public void load( DataInputStream source) throws
java.io.IOException {
int point_number = source.readInt();
for (int i=0; i < point_number; i++) {
readPoint( source);
}
}
/**
* send over the stream a compressed version of this line
*/
public void saveKompressed( OutputStream destination) throws
java.io.IOException {
DrawLineKompressor kompressor = new DrawLineKompressor( lines);
kompressor.kompress( destination);
}
/**
* load form the stream a compressed version of this line
*/
public void loadExpanded( InputStream source) throws
java.io.IOException {
DrawLineExpander expander = new DrawLineExpander();
lines = expander.expand( source);
}
public ArrayList<Point> getPoints() {
return new ArrayList<Point>(lines);
}
public ArrayList<Point> internalGetPoints() {
return lines;
}
}

View File

@@ -0,0 +1,94 @@
package org.artisanlogiciel.graphics;
import java.awt.Point;
import java.io.DataInputStream;
/**
.IMA format is an old proprietary format for laser show program
it contain a list of point the laser beam should goe through,
x=255 has a special meaning to hide (255,254) ( send beam into the box) or show it (255,255): let is flow outside.
*/
public class IMAImporter implements Importer
{
final DataInputStream mStream;
boolean mBeanOn = false;
int mIndex =0;
boolean mDebug = false;
public IMAImporter(DataInputStream inputStream)
{
mStream=inputStream;
}
public void setDebug(boolean pDebug)
{
mDebug=pDebug;
}
@Override
public void importInto(Drawing drawing)
{
int x,y;
DrawingLine line = null;
mBeanOn = false;
try {
// little endian unsigned short
int pointCount = mStream.readUnsignedByte();
pointCount = ( 256 * mStream.readUnsignedByte() ) + pointCount;
if ( mDebug )
{
System.out.println("point count :" + pointCount);
}
for (int j = 0 ; j < pointCount; j+=2)
{
mIndex=j;
x = mStream.readUnsignedByte();
y = mStream.readUnsignedByte();
// special beam on/off
if ( ( x == 0xff ) && ( y >= 0xfe ) )
{
mBeanOn = ( y == 0xff);
if ( mDebug )
{
System.out.println("beam change at " + mIndex + " " + mBeanOn);
}
}
else
{
y = 255-y;
if ( mDebug )
{
System.out.println("point at " + mIndex + " " + mBeanOn + " x " + x + " y " + y);
}
if ( mBeanOn )
{
if (line == null )
{
line = new DrawingLine();
}
line.addPoint(new Point(x,y));
}
else
{
if ( line != null )
{
drawing.addLine(line);
line = null;
}
}
}
}
if ( line != null )
{
drawing.addLine(line);
line = null;
}
}
catch( Exception any)
{
System.err.println(" error at index " + mIndex);
any.printStackTrace(System.err);
}
}
}

View File

@@ -0,0 +1,143 @@
package org.artisanlogiciel.graphics;
import java.awt.Point;
import java.io.DataOutputStream;
import java.io.IOException;
import java.util.ArrayList;
/**
* Write a DrawLine (using its internal Vector representation) into IMA format
* this is with loss ( ima is a 255x255 point resolution )
*
* @author philippe
*
*/
public class IMAWriter {
private final ArrayList<DrawingLine> mLines;
private int mByteCount = 0;
// need to compute bounding box and normalize to 255x255
private Point mOrig = new Point(100000,100000);
private Point mMax = new Point(-100000,-100000);
double ratioX = .1;
double ratioY = .1;
public IMAWriter(ArrayList<DrawingLine> pLines)
{
mLines = pLines;
setup();
}
private void updateOrigMax(Point p)
{
double ox = mOrig.getX(), oy = mOrig.getY(), mx = mMax.getX(), my = mMax.getY();
if (p.getX() < ox )
{
ox = p.getX();
}
if (p.getX() > mx)
{
mx = p.getX();
}
if (p.getY() < oy )
{
oy = p.getY();
}
if (p.getY() > my)
{
my = p.getY();
}
mOrig.setLocation(ox,oy);
mMax.setLocation(mx,my);
}
private void setup()
{
int count = 0;
for (DrawingLine line : mLines)
{
for (Point p : line.getPoints())
{
updateOrigMax(p);
count+=2;
}
// beam on + off
count+=4;
}
mByteCount=count;
if ( mMax.getX() != mOrig.getX())
{
ratioX = 255 / (mMax.getX() - mOrig.getX());
}
else
{
ratioX = 1.;
}
if ( mMax.getY() != mOrig.getY())
{
ratioY = 255 / (mMax.getY() - mOrig.getY());
}
else
{
ratioY = 1.;
}
}
public void writeTo(DataOutputStream pData)
throws IOException
{
int wrote = 0;
// writeheader : number of points ...
// little endian unsigned short.
pData.writeByte(mByteCount%256);
pData.writeByte(mByteCount/256);
for (DrawingLine line : mLines)
{
// write ima line
wrote += writeLine(pData, line.getPoints());
}
}
void writeBeamOnOff(DataOutputStream pData,boolean pOn)
throws IOException
{
pData.writeByte(0xff);
pData.writeByte(pOn ? 0xff : 0xfe);
}
void writePoint(DataOutputStream pData,Point pPoint)
throws IOException
{
int x = (int) ((pPoint.getX()-mOrig.getX()) * ratioX);
int y = 255 - ((int) ((pPoint.getY()-mOrig.getY()) * ratioY));
if ( x == 0xff )
{
x=0xfe;
}
pData.writeByte(x);
pData.writeByte(y);
}
int writeLine(DataOutputStream pData,ArrayList<Point> pPoints)
throws IOException
{
int count = 0;
for (Point p : pPoints)
{
writePoint(pData,p);
if ( count == 0 )
{
writeBeamOnOff(pData,true);
}
count++;
}
writeBeamOnOff(pData,false);
return 2*(count +2);
}
}

View File

@@ -0,0 +1,8 @@
package org.artisanlogiciel.graphics;
public interface Importer {
void importInto(Drawing drawing);
void setDebug(boolean pDebug);
}

View File

@@ -0,0 +1,31 @@
/*
This file is part of ShareDrawWeb.
ShareDrawWeb is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
ShareDrawWeb 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. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with ShareDrawWeb; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package org.artisanlogiciel.graphics;
import java.io.Serializable;
public class NoMoreLineException
extends DrawException
implements Serializable
{
public NoMoreLineException() {
super();
}
}

View File

@@ -0,0 +1,28 @@
/*
This file is part of ShareDrawWeb.
ShareDrawWeb is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
ShareDrawWeb 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. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with ShareDrawWeb; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package org.artisanlogiciel.graphics;
public class ResetException
extends DrawException
{
public ResetException() {
super();
}
}

View File

@@ -0,0 +1,65 @@
package org.artisanlogiciel.graphics;
import java.awt.Point;
//import java.io.DataOutputStream;
import java.io.OutputStream;
import java.io.IOException;
import java.util.ArrayList;
/**
* Write a DrawLine (using its internal Vector representation) into svg
*
* @author philippe
*
*/
public class SvgWriter {
private final ArrayList<DrawingLine> mLines;
public SvgWriter(ArrayList<DrawingLine> pLines)
{
mLines = pLines;
}
public void writeTo(OutputStream pData)
throws IOException
{
pData.write("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>".getBytes("UTF8"));
pData.write("<svg>".getBytes("UTF8"));
for (DrawingLine line : mLines)
{
pData.write("<g><path ".getBytes("UTF8"));
pData.write("style=\"fill:none;fill-rule:evenodd;stroke:#000000;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1\" d=\"".getBytes("UTF8"));
pData.write( getSvgPathString(line.getPoints()).getBytes("UTF8"));
pData.write(" \" /></g>".getBytes("UTF8"));
}
pData.write("</svg>".getBytes("UTF8"));
}
String getSvgPathString(ArrayList<Point> pPoints)
{
StringBuilder sb = new StringBuilder(pPoints.size() * 10);
Point second = null;
Point previous = null;
for ( Point p : pPoints)
{
if ( previous != null )
{
if ( second == null )
{
second = p;
// 'l' a line ( 'c' woudl be a curve )
sb.append(" l ");
}
sb.append( "" + (p.getX() - previous.getX()) + "," + (p.getY() - previous.getY()) );
previous = p;
}
else
{
sb.append("m " + p.getX() + "," + p.getY());
previous = p;
}
}
return sb.toString();
}
}

View File

@@ -0,0 +1,7 @@
/CharProvider.class
/LuaNumber.class
/LuaObject.class
/LuaSequence.class
/LuaString.class
/LuaTuple.class
/Parser.class

View File

@@ -62,7 +62,7 @@ public class Parser {
pushBackChar(c);
if ( errors == null)
{
errors = new ArrayList();
errors = new ArrayList<String>();
}
System.err.println(info);
errors.add(info);

View File

@@ -0,0 +1,4 @@
/Node.class
/NodeRef.class
/OsmReader.class
/Way.class

View File

@@ -0,0 +1 @@
/OsmToDrawing.class

View File

@@ -37,9 +37,10 @@ public class OsmToDrawing {
public OsmToDrawing(OsmReader reader, int mulx, int muly)
{
this.refx = reader.getMinlat();
this.refx = reader.getMinlon();
this.refy = reader.getMaxlat();
this.minlat = reader.getMinlat();
this.refy = reader.getMinlon();
this.minlon = reader.getMinlon();
this.maxlat = reader.getMaxlat();
this.maxlon = reader.getMaxlon();
@@ -92,7 +93,7 @@ public class OsmToDrawing {
boundserror ++;
System.err.println("lon > minlon " + lon);
}
drawingLine.addPoint(new Point((int) ( (lon - refy ) * muly), (int) ( (lat - refx)* mulx ) ));
drawingLine.addPoint(new Point((int) ( ( lon - refx ) * mulx), (int) ( ( refy - lat ) * muly ) ));
}
return drawingLine;
}

View File

@@ -0,0 +1 @@
/UTF8Control.class

View File

@@ -0,0 +1 @@
/Xpm.class

View File

@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path=""/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="con" path="org.eclipse.fx.ide.jdt.core.JAVAFX_CONTAINER"/>
<classpathentry kind="output" path=""/>
</classpath>

View File

@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>Karmazoff</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.xtext.ui.shared.xtextBuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.xtext.ui.shared.xtextNature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>

View File

@@ -0,0 +1,15 @@
width = Width
height = Height
depth = Depth
north = North
south = South
east = East
west = West
resolve = Resolve
create = Create
save = Save
quit = Quit
title = A Maz ing
seed = seed
load = Load
reverse = Reverse

View File

@@ -0,0 +1,15 @@
width = Largeur
height = Hauteur
depth = Profondeur
north = Nord
south = Sud
east = Est
west = Ouest
resolve = Résoudre
create = Créer
save = Sauver
quit = Quitter
title = La Bireinte
seed = graine
load = Charger
reverse = Inverse

View File

@@ -0,0 +1,59 @@
PACKAGE=org.artisanlogiciel.games
PACKAGE_DIR=$(subst .,/,$(PACKAGE))
# maps with ant build.xml
OUT=../build
# external libraries
LIBS=../libs/artgaphics-0.1.0.jar
EDITOR=emacs
$(OUT):
echo "[ERROR] Missing $(OUT)"
# mkdir -p $(OUT)
clean:
@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 --no-run-if-empty rm 2>/dev/null
test:
echo "$(pwd)/$(PACKAGE_DIR)"
javac -sourcepath . -cp $(LIBS) -d $(OUT) $(PACKAGE_DIR)/LabyModel.java
javac -sourcepath . -cp $(LIBS) -d $(OUT) $(PACKAGE_DIR)/Main.java
java -cp $(OUT):$(LIBS):../lang $(PACKAGE).Main
run/%: $(OUT)
javac -cp $(LIBS):$(OUT) -d $(OUT) $(PACKAGE_DIR)/$(subst run/,,$@).java
java -cp $(OUT):$(LIBS) $(PACKAGE)/$(subst run/,,$@)
display: run/Display
display/%: $(OUT)
javac -cp $(LIBS) -d $(OUT) $(PACKAGE_DIR)/Display.java
java -cp $(OUT):$(LIBS) $(PACKAGE).Display $(subst display/,,$@)
compile/%:
javac -d $(OUT) $(PACKAGE_DIR)/$(subst compile/,,$@).java
$(PACKAGE_DIR)/%.java:
./generate_new.sh class $(subst .java,,$(subst $(PACKAGE_DIR)/,,$@))
interface/%:
./generate_new.sh interface package_dir=$(PACKAGE_DIR) $(subst interface/,,$@)
$(EDITOR) $(PACKAGE_DIR)/$(subst interface/,,$@).java
work/%: $(PACKAGE_DIR)/$(subst work/,,%).java
$(EDITOR) $<
work: work/LabyModel
save:
git citool
.PHONY: clean test work display work/% run/% save compile/% interface/%
# tried to avoid intermediate file removal : does not work
# .SECONDARY: $(PACKAGE_DIR)/%.java
# this does work : once precious intermediate file is not removed.
.PRECIOUS: $(PACKAGE_DIR)/%.java

View File

@@ -0,0 +1,24 @@
A Maze generator that keep all reverse paths to solutions.
See Makefile
#clean
make clean
#console
make test
#gui
make display
#code emacs : work/ClassName
make work/Display
#run a class
make run/Display
#save work with git (ie git citool )
make save
# create an interface
make interface/InterfaceName

View File

@@ -0,0 +1,16 @@
By pref
- rendering
GUI
* WALK it...
* regenerate it
CONSOLE :
* provide interactive ( view a part of maze )
- model
* saving in stream ( better than in toString() that basically fails... )
- format :
3D format ( for 3Dprinting )

Binary file not shown.

File diff suppressed because it is too large Load Diff

Binary file not shown.

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

Some files were not shown because too many files have changed in this diff Show More