added verse library (release r6) to extern directory
authorJiri Hnidek <jiri.hnidek@tul.cz>
Sun, 20 Aug 2006 16:09:03 +0000 (16:09 +0000)
committerJiri Hnidek <jiri.hnidek@tul.cz>
Sun, 20 Aug 2006 16:09:03 +0000 (16:09 +0000)
69 files changed:
extern/verse/Makefile [new file with mode: 0644]
extern/verse/dist/BUGS [new file with mode: 0644]
extern/verse/dist/MAINTAINERS [new file with mode: 0644]
extern/verse/dist/Makefile [new file with mode: 0644]
extern/verse/dist/Makefile.win32 [new file with mode: 0644]
extern/verse/dist/README [new file with mode: 0644]
extern/verse/dist/SConstruct [new file with mode: 0644]
extern/verse/dist/v_bignum.c [new file with mode: 0644]
extern/verse/dist/v_bignum.h [new file with mode: 0644]
extern/verse/dist/v_cmd_buf.c [new file with mode: 0644]
extern/verse/dist/v_cmd_buf.h [new file with mode: 0644]
extern/verse/dist/v_cmd_def_a.c [new file with mode: 0644]
extern/verse/dist/v_cmd_def_b.c [new file with mode: 0644]
extern/verse/dist/v_cmd_def_c.c [new file with mode: 0644]
extern/verse/dist/v_cmd_def_g.c [new file with mode: 0644]
extern/verse/dist/v_cmd_def_m.c [new file with mode: 0644]
extern/verse/dist/v_cmd_def_o.c [new file with mode: 0644]
extern/verse/dist/v_cmd_def_s.c [new file with mode: 0644]
extern/verse/dist/v_cmd_def_t.c [new file with mode: 0644]
extern/verse/dist/v_cmd_gen.c [new file with mode: 0644]
extern/verse/dist/v_cmd_gen.h [new file with mode: 0644]
extern/verse/dist/v_connect.c [new file with mode: 0644]
extern/verse/dist/v_connection.c [new file with mode: 0644]
extern/verse/dist/v_connection.h [new file with mode: 0644]
extern/verse/dist/v_encryption.c [new file with mode: 0644]
extern/verse/dist/v_encryption.h [new file with mode: 0644]
extern/verse/dist/v_func_storage.c [new file with mode: 0644]
extern/verse/dist/v_gen_pack_a_node.c [new file with mode: 0644]
extern/verse/dist/v_gen_pack_b_node.c [new file with mode: 0644]
extern/verse/dist/v_gen_pack_c_node.c [new file with mode: 0644]
extern/verse/dist/v_gen_pack_g_node.c [new file with mode: 0644]
extern/verse/dist/v_gen_pack_init.c [new file with mode: 0644]
extern/verse/dist/v_gen_pack_m_node.c [new file with mode: 0644]
extern/verse/dist/v_gen_pack_o_node.c [new file with mode: 0644]
extern/verse/dist/v_gen_pack_s_node.c [new file with mode: 0644]
extern/verse/dist/v_gen_pack_t_node.c [new file with mode: 0644]
extern/verse/dist/v_gen_unpack_func.h [new file with mode: 0644]
extern/verse/dist/v_gen_unpack_funcs.h [new file with mode: 0644]
extern/verse/dist/v_internal_verse.h [new file with mode: 0644]
extern/verse/dist/v_man_pack_node.c [new file with mode: 0644]
extern/verse/dist/v_network.c [new file with mode: 0644]
extern/verse/dist/v_network.h [new file with mode: 0644]
extern/verse/dist/v_network_in_que.c [new file with mode: 0644]
extern/verse/dist/v_network_in_que.h [new file with mode: 0644]
extern/verse/dist/v_network_out_que.c [new file with mode: 0644]
extern/verse/dist/v_network_out_que.h [new file with mode: 0644]
extern/verse/dist/v_pack.c [new file with mode: 0644]
extern/verse/dist/v_pack.h [new file with mode: 0644]
extern/verse/dist/v_pack_method.c [new file with mode: 0644]
extern/verse/dist/v_prime.c [new file with mode: 0644]
extern/verse/dist/v_randgen.c [new file with mode: 0644]
extern/verse/dist/v_randgen.h [new file with mode: 0644]
extern/verse/dist/v_util.c [new file with mode: 0644]
extern/verse/dist/v_util.h [new file with mode: 0644]
extern/verse/dist/verse.h [new file with mode: 0644]
extern/verse/dist/verse_header.h [new file with mode: 0644]
extern/verse/dist/vs_connection.c [new file with mode: 0644]
extern/verse/dist/vs_main.c [new file with mode: 0644]
extern/verse/dist/vs_node_audio.c [new file with mode: 0644]
extern/verse/dist/vs_node_bitmap.c [new file with mode: 0644]
extern/verse/dist/vs_node_curve.c [new file with mode: 0644]
extern/verse/dist/vs_node_geometry.c [new file with mode: 0644]
extern/verse/dist/vs_node_head.c [new file with mode: 0644]
extern/verse/dist/vs_node_material.c [new file with mode: 0644]
extern/verse/dist/vs_node_object.c [new file with mode: 0644]
extern/verse/dist/vs_node_particle.c [new file with mode: 0644]
extern/verse/dist/vs_node_storage.c [new file with mode: 0644]
extern/verse/dist/vs_node_text.c [new file with mode: 0644]
extern/verse/dist/vs_server.h [new file with mode: 0644]

diff --git a/extern/verse/Makefile b/extern/verse/Makefile
new file mode 100644 (file)
index 0000000..769bbe4
--- /dev/null
@@ -0,0 +1,60 @@
+#
+# $Id$
+#
+# ***** BEGIN GPL/BL DUAL LICENSE BLOCK *****
+#
+# This program 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. The Blender
+# Foundation also sells licenses for use in proprietary software under
+# the Blender License.  See http://www.blender.org/BL/ for information
+# about this.
+#
+# This program 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 this program; if not, write to the Free Software Foundation,
+# Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+#
+# The Original Code is Copyright (C) 2002 by Hans Lambermont
+# All rights reserved.
+#
+# The Original Code is: all of this file.
+#
+# Contributor(s): Jiri Hnidek
+#
+# ***** END GPL/BL DUAL LICENSE BLOCK *****
+
+include nan_definitions.mk
+
+DISTDIR = dist
+CP = ../../intern/tools/cpifdiff.sh
+
+ifeq ($(OS),windows)
+    EXT = .exe
+endif
+
+all:
+       $(MAKE) -C $(DISTDIR)
+
+# fake debug target
+debug:
+
+install: all
+       @[ -d $(NAN_VERSE) ] || mkdir -p $(NAN_VERSE)
+       @[ -d $(NAN_VERSE)/include ] || mkdir -p $(NAN_VERSE)/include
+       @[ -d $(NAN_VERSE)/lib ] || mkdir -p $(NAN_VERSE)/lib
+       @[ -d $(OCGDIR)/bin ] || mkdir -p $(OCGDIR)/bin
+       @$(CP) $(DISTDIR)/*.h $(NAN_VERSE)/include
+       @$(CP) $(DISTDIR)/libverse.a $(NAN_VERSE)/lib
+       @$(CP) $(DISTDIR)/verse$(EXT) $(OCGDIR)/bin
+ifeq ($(OS),darwin)
+       ranlib $(NAN_VERSE)/lib/libverse.a
+endif
+
+clean:
+       $(MAKE) -C $(DISTDIR) clean
diff --git a/extern/verse/dist/BUGS b/extern/verse/dist/BUGS
new file mode 100644 (file)
index 0000000..8c3603a
--- /dev/null
@@ -0,0 +1,8 @@
+
+Known problems with Verse
+
+2004-03-03
+* The source code needs plenty of cleaning up in order to compile more
+  cleanly.
+* License information needs to be added all over the place.
+* Decent documentation is missing.
diff --git a/extern/verse/dist/MAINTAINERS b/extern/verse/dist/MAINTAINERS
new file mode 100644 (file)
index 0000000..c467d53
--- /dev/null
@@ -0,0 +1,15 @@
+
+                       Verse Maintainers
+
+This file tries to list credits for the various parts of the
+Verse core distribution, and also identify who maintains what.
+
+We are deeply appreciative of any contributions and thank you
+all for your time and interest in helping make Verse a better
+thing.
+
+* All code was originally written by Eskil Steenberg, and is
+  being maintained by him and Emil Brink. Contact us through
+  the project page at http://www.blender.org/modules/verse/.
+
+* SCons build file by N. Letwory, http://www.jester-depot.net/.
diff --git a/extern/verse/dist/Makefile b/extern/verse/dist/Makefile
new file mode 100644 (file)
index 0000000..32ab7ae
--- /dev/null
@@ -0,0 +1,91 @@
+#
+# Makefile for Verse core; API and reference server.
+# This pretty much requires GNU Make, I think.
+#
+# This build is slightly complicated that part of the C code that
+# needs to go into the API implementation is generated by building
+# and running other C files (this is the protocol definition).
+#
+
+CC     ?= gcc
+CFLAGS ?= "-I$(shell pwd)" -Wall -Wpointer-arith -ansi -g # -pg -O2 -finline-functions
+LDFLAGS        ?= -pg
+
+AR     ?= ar
+ARFLAGS        = rus
+RANLIB ?= ranlib
+
+TARGETS = libverse.a verse
+
+.PHONY:        all clean cleanprot
+
+# Automatically generated protocol things.
+PROT_DEF  = $(wildcard v_cmd_def_*.c)
+PROT_TOOL = v_cmd_gen.c $(PROT_DEF)
+PROT_OUT  = v_gen_pack_init.c v_gen_unpack_func.h verse.h \
+               $(patsubst v_cmd_def_%.c,v_gen_pack_%_node.c, $(PROT_DEF))
+
+# The API implementation is the protocol code plus a few bits.
+LIBVERSE_SRC =  $(PROT_OUT) v_bignum.c v_cmd_buf.c v_connect.c \
+               v_connection.c v_connection.h v_encryption.c \
+               v_func_storage.c v_internal_verse.h v_man_pack_node.c \
+               v_network.c v_network.h v_network_in_que.c v_network_out_que.c \
+               v_pack.c v_pack.h v_pack_method.c v_prime.c v_randgen.c v_util.c
+
+LIBVERSE_OBJ = $(patsubst %h,, $(LIBVERSE_SRC:%.c=%.o))
+
+# The server is a simple 1:1 mapping, so just use wildcards.
+VERSE_SRC = $(wildcard vs_*.c)
+VERSE_OBJ = $(VERSE_SRC:%.c=%.o)
+
+# -----------------------------------------------------
+
+all:           $(TARGETS)
+
+verse:         $(VERSE_OBJ) libverse.a
+               $(CC) $(LDFLAGS) -o $@ $^
+
+libverse.a:    libverse.a($(LIBVERSE_OBJ))
+
+# -----------------------------------------------------
+
+# Here are the automatically generated pieces of the puzzle.
+# Basically, we generate v_gen_pack_X_node.c files by compiling
+# the v_cmd_def_X.c files together with some driver glue and
+# running the result.
+#
+
+# The autogen outputs all depend on the tool.
+$(PROT_OUT):   mkprot
+               ./mkprot
+
+# Build the protocol maker, from the definitions themselves.
+mkprot:                $(PROT_TOOL) verse_header.h
+               $(CC) -DV_GENERATE_FUNC_MODE -o $@ $(PROT_TOOL)
+
+# Clean away all the generated parts of the protocol implementation.
+cleanprot:     clean
+               rm -f mkprot $(PROT_OUT)
+
+# -----------------------------------------------------
+
+clean:
+       rm -f *.o $(TARGETS) mkprot
+
+# -----------------------------------------------------
+
+# Utter ugliness to create release archives. Needs to improve, but should work for a while.
+dist:
+       RELEASE=$$( \
+       R=`grep V_RELEASE_NUMBER verse.h | tr -s ' \t' | tr -d '"\r' | cut -d'  ' -f3` ; \
+       P=`grep V_RELEASE_PATCH verse.h | tr -s ' \t' | tr -d '"\r' | cut -d'   ' -f3` ; \
+       L=`grep V_RELEASE_LABEL verse.h | tr -s ' \t' | tr -d '"\r' | cut -d'   ' -f3` ; echo r$${R}p$$P$$L ) ; \
+       if [ $$RELEASE ]; then ( \
+        rm -rf  /tmp/verse; \
+        mkdir -p /tmp/verse; \
+        cp -a * /tmp/verse; \
+        cd /tmp && zip verse-$$RELEASE.zip -r verse -x 'verse/*CVS*' -x 'verse/.*' ; \
+        ); mv /tmp/verse-$$RELEASE.zip . \
+       ;else \
+         echo "Couldn't auto-set RELEASE from verse.h, something is fishy" \
+       ;fi
diff --git a/extern/verse/dist/Makefile.win32 b/extern/verse/dist/Makefile.win32
new file mode 100644 (file)
index 0000000..be2a76a
--- /dev/null
@@ -0,0 +1,102 @@
+#
+# Makefile for Verse core; API and reference server.
+# Written by modifying the main GNU Makefile, for nmake.
+#
+# It is more hard-coded, relying on less intelligence in
+# the make tool.
+#
+# This build is slightly complicated that part of the C code that
+# needs to go into the API implementation is generated by building
+# and running other C files (this is the protocol definition).
+#
+
+CC     = cl
+CFLAGS = 
+LDFLAGS        = -pg
+
+AR     = ar
+ARFLAGS        = rus
+RANLIB = ranlib
+
+TARGETS = verse.lib verse.exe
+
+# Automatically generated protocol things.
+PROT_DEF  = v_cmd_def_a.c v_cmd_def_b.c v_cmd_def_c.c v_cmd_def_g.c v_cmd_def_m.c v_cmd_def_o.c v_cmd_def_s.c v_cmd_def_t.c
+PROT_TOOL = v_cmd_gen.c $(PROT_DEF)
+PROT_OUT  = v_gen_pack_init.c v_gen_unpack_func.h verse.h \
+           v_gen_pack_a_node.c v_gen_pack_b_node.c v_gen_pack_c_node.c v_gen_pack_g_node.c v_gen_pack_m_node.c v_gen_pack_o_node.c v_gen_pack_s_node.c v_gen_pack_t_node.c
+
+# The API implementation is the protocol code plus a few bits.
+LIBVERSE_SRC =  v_gen_pack_init.c v_gen_unpack_func.h verse.h v_gen_pack_a_node.c v_gen_pack_b_node.c v_gen_pack_c_node.c v_gen_pack_g_node.c \
+               v_gen_pack_m_node.c v_gen_pack_o_node.c v_gen_pack_s_node.c v_gen_pack_t_node.c \
+               v_bignum.c v_cmd_buf.c v_connect.c \
+               v_connection.c v_connection.h v_encryption.c \
+               v_func_storage.c v_internal_verse.h v_man_pack_node.c \
+               v_network.c v_network.h v_network_in_que.c v_network_out_que.c \
+               v_pack.c v_pack.h v_pack_method.c v_prime.c v_randgen.c v_util.c
+
+LIBVERSE_OBJ = v_gen_pack_init.obj v_gen_pack_a_node.obj v_gen_pack_b_node.obj v_gen_pack_c_node.obj v_gen_pack_g_node.obj \
+               v_gen_pack_m_node.obj v_gen_pack_o_node.obj v_gen_pack_s_node.obj v_gen_pack_t_node.obj \
+               v_bignum.obj v_cmd_buf.obj v_connect.obj \
+               v_connection.obj v_encryption.obj \
+               v_func_storage.obj v_man_pack_node.obj \
+               v_network.obj v_network_in_que.obj v_network_out_que.obj \
+               v_pack.obj v_pack_method.obj v_prime.obj v_randgen.obj v_util.obj
+
+# The server is a simple 1:1 mapping, but in Windows nmake ... That doesn't help much. :/
+VERSE_SRC = vs_connection.c vs_main.c vs_node_audio.c vs_node_bitmap.c vs_node_curve.c vs_node_geometry.c vs_node_head.c vs_node_material.c vs_node_object.c vs_node_particle.c vs_node_storage.c vs_node_text.c
+VERSE_OBJ = vs_connection.obj vs_main.obj vs_node_audio.obj vs_node_bitmap.obj vs_node_curve.obj vs_node_geometry.obj \
+       vs_node_head.obj vs_node_material.obj vs_node_object.obj vs_node_particle.obj vs_node_storage.obj vs_node_text.obj
+
+# -----------------------------------------------------
+
+ALL:           verse.lib verse.exe
+
+verse.exe:     $(VERSE_OBJ) verse.lib
+               cl /Fe$@ $**  $** wsock32.lib
+
+verse.lib:     $(LIBVERSE_OBJ)
+               lib /nologo /out:$@ $**
+
+# -----------------------------------------------------
+
+# Here are the automatically generated pieces of the puzzle.   
+# Basically, we generate v_gen_pack_X_node.c files by compiling
+# the v_cmd_def_X.c files together with some driver glue and
+# running the result.
+#
+
+# The autogen outputs all depend on the tool.
+$(PROT_OUT):   mkprot.exe
+               mkprot.exe
+
+# Build the protocol maker, from the definitions themselves.
+mkprot.exe:    $(PROT_TOOL) verse_header.h
+               $(CC) /DV_GENERATE_FUNC_MODE /Fe$@ $(PROT_TOOL)
+
+# Clean away all the generated parts of the protocol implementation.
+cleanprot:     clean
+               del mkprot $(PROT_OUT) mkprot.exe
+
+# -----------------------------------------------------
+
+clean:
+       del *.obj $(TARGETS)
+
+# -----------------------------------------------------
+
+# Utter ugliness to create release archives. Needs to improve, but should work for a while.
+dist:
+       RELEASE=$$( \
+       R=`grep V_RELEASE_NUMBER verse.h | tr -s ' \t' | tr -d '"\r' | cut -d'  ' -f3` ; \
+       P=`grep V_RELEASE_PATCH verse.h | tr -s ' \t' | tr -d '"\r' | cut -d'   ' -f3` ; \
+       L=`grep V_RELEASE_LABEL verse.h | tr -s ' \t' | tr -d '"\r' | cut -d'   ' -f3` ; echo r$${R}p$$P$$L ) ; \
+       if [ $$RELEASE ]; then ( \
+        rm -rf  /tmp/verse; \
+        mkdir -p /tmp/verse; \
+        cp -a * /tmp/verse; \
+        cd /tmp && zip verse-$$RELEASE.zip -r verse -x 'verse/*CVS*' -x 'verse/.*' ; \
+        ); mv /tmp/verse-$$RELEASE.zip . \
+       ;else \
+         echo "Couldn't auto-set RELEASE from verse.h, something is fishy" \
+       ;fi
diff --git a/extern/verse/dist/README b/extern/verse/dist/README
new file mode 100644 (file)
index 0000000..2554012
--- /dev/null
@@ -0,0 +1,23 @@
+
+                               Verse
+
+This is the Verse protocol and sample server implementations.
+
+For more information, see <http://verse.blender.org/>.
+
+Running "make" here will build the API library, "libverse.a" (and its
+header file, "verse.h"). These two will then be used to build the
+reference Verse server binary, called "verse".
+
+
+RELEASE LABELING
+Verse uses a simple two-level numbering scheme to identify releases.
+There is a "release number", and a "patch level" on each release. The
+intent is that within a release, the API does not change and neither
+should the network protocol. Between releases, we might improve the
+API which will require application programmers to update their code
+to stay in sync. We can do non-API-altering changes within a release
+by increasing the patch level, for bug fixing and other things.
+       The symbols V_RELEASE_NUMBER and V_RELEASE_PATCH are integer
+literals that hold the values for the API you have, and can be used
+(and displayed) in application source code as you see fit.
diff --git a/extern/verse/dist/SConstruct b/extern/verse/dist/SConstruct
new file mode 100644 (file)
index 0000000..ac6f603
--- /dev/null
@@ -0,0 +1,191 @@
+#
+# SConstruct for Verse
+#
+# This file is still quite crude, but it does it's job, and
+# is geared towards future extensions.
+#
+# I did this only on Windows so people should look into the
+# if...elif...
+# construction about the platform specific stuff.
+#
+# I think it is quite straight-forward to add new platforms,
+# just look at the old makefile and at the existing platforms.
+#
+# This SConstruct creates a configuration file which can be
+# used for tweaking a build.
+#
+# For more about SConstruct, see <http://www.scons.org/>.
+#
+
+import os
+import sys
+import time
+import string
+from distutils import sysconfig
+
+root_build_dir = '..' + os.sep + 'build' + os.sep
+
+config_file = 'config.opts'
+version = '1.0'
+
+env = Environment ()
+
+defines = []
+cflags = []
+debug_flags = []
+extra_flags = []
+release_flags = []
+warn_flags = []
+platform_libs = []
+platform_libpath = []
+platform_linkflags = []
+
+if sys.platform == 'win32':
+    print "Building on win32"
+    defines += ['_WIN32']
+    warn_flags = ['/Wall']
+    platform_libs = ['ws2_32']
+elif sys.platform == 'linux2':
+    print "Building on linux2"
+elif sys.platform == 'openbsd3':
+    print "Building on openbsd3"
+
+if os.path.exists (config_file):
+    print "Using config file: " + config_file
+else:
+    print "Creating new config file: " + config_file
+    env_dict = env.Dictionary()
+    config = open (config_file, 'w')
+    config.write ("#Configuration file for verse SCons user definable options.\n")
+    config.write ("BUILD_BINARY = 'release'\n")
+    config.write ("REGEN_PROTO = 'yes'\n")
+    config.write ("\n# Compiler information.\n")
+    config.write ("HOST_CC = %r\n"%(env_dict['CC']))
+    config.write ("HOST_CXX = %r\n"%(env_dict['CXX']))
+    config.write ("TARGET_CC = %r\n"%(env_dict['CC']))
+    config.write ("TARGET_CXX = %r\n"%(env_dict['CXX']))
+    config.write ("TARGET_AR = %r\n"%(env_dict['AR']))
+    config.write ("PATH = %r\n"%(os.environ['PATH']))
+
+user_options_env = Environment()
+user_options = Options (config_file)
+user_options.AddOptions(
+    (EnumOption ('BUILD_BINARY', 'release',
+        'Build a release or debug binary.',
+        allowed_values = ('release', 'debug'))),
+    ('BUILD_DIR', 'Target directory for intermediate files.',
+        root_build_dir),
+    (EnumOption ('REGEN_PROTO', 'yes',
+        'Whether to regenerate the protocol files',
+        allowed_values = ('yes', 'no'))),
+    ('HOST_CC', 'C compiler for the host platfor. This is the same as target platform when not cross compiling.'),
+    ('HOST_CXX', 'C++ compiler for the host platform. This is the same as target platform when not cross compiling.'),
+    ('TARGET_CC', 'C compiler for the target platform.'),
+    ('TARGET_CXX', 'C++ compiler for the target platform.'),
+    ('TARGET_AR', 'Linker command for linking libraries.'),
+    ('PATH', 'Standard search path')
+)
+user_options.Update (user_options_env)
+user_options_dict = user_options_env.Dictionary()
+
+root_build_dir = user_options_dict['BUILD_DIR']
+
+if user_options_dict['BUILD_BINARY'] == 'release':
+    cflags = extra_flags + release_flags + warn_flags
+    if sys.platform == 'win32':
+        defines += ['NDEBUG']
+else:
+    cflags = extra_flags + debug_flags + warn_flags
+    if sys.platform == 'win32':
+        #defines += ['_DEBUG'] specifying this makes msvc want to link to python22_d.lib??
+        platform_linkflags += ['/DEBUG','/PDB:verse.pdb']
+
+library_env = Environment()
+library_env.Replace (CC = user_options_dict['TARGET_CC'])
+library_env.Replace (CXX = user_options_dict['TARGET_CXX'])
+library_env.Replace (PATH = user_options_dict['PATH'])
+library_env.Replace (AR = user_options_dict['TARGET_AR'])
+
+cmd_gen_files = (['v_cmd_gen.c',
+                                 'v_cmd_def_a.c',
+                                 'v_cmd_def_b.c',
+                                 'v_cmd_def_c.c',
+                                 'v_cmd_def_g.c',
+                                 'v_cmd_def_m.c',
+                                 'v_cmd_def_o.c',
+                                 'v_cmd_def_s.c',
+                                 'v_cmd_def_t.c'
+                                 ])
+
+cmd_gen_deps = (['v_gen_pack_init.c',
+                                'v_gen_pack_a_node.c',
+                                'v_gen_pack_b_node.c',
+                                'v_gen_pack_c_node.c',
+                                'v_gen_pack_g_node.c',
+                                'v_gen_pack_m_node.c',
+                                'v_gen_pack_o_node.c',
+                                'v_gen_pack_s_node.c',
+                                'v_gen_pack_t_node.c',
+                               ])
+
+if user_options_dict['REGEN_PROTO']=='yes':
+    cmd_gen_env = library_env.Copy()
+    cmd_gen_env.Append(CPPDEFINES=['V_GENERATE_FUNC_MODE'])
+    mkprot = cmd_gen_env.Program(target='mkprot', source=cmd_gen_files)
+    cmd_gen_env.Command('regen', '' , './mkprot')
+
+lib_source_files = (['v_cmd_buf.c',
+                                        'v_connect.c',
+                                        'v_connection.c',
+                                        'v_encryption.c',
+                                        'v_func_storage.c',
+                                        'v_man_pack_node.c',
+                                        'v_network.c',
+                                        'v_network_in_que.c',
+                                        'v_network_out_que.c',
+                                        'v_pack.c',
+                                        'v_pack_method.c',
+                                        'v_prime.c',
+                                        'v_randgen.c',
+                                        'v_util.c',
+                                        'v_bignum.c'
+                                        ])
+lib_source_files += cmd_gen_deps
+
+server_source_files = (['vs_connection.c',
+                        'vs_main.c',
+                                               'vs_node_audio.c',
+                        'vs_node_bitmap.c',
+                        'vs_node_curve.c',
+                        'vs_node_geometry.c',
+                        'vs_node_head.c',
+                        'vs_node_material.c',
+                        'vs_node_object.c',
+                        'vs_node_particle.c',
+                        'vs_node_storage.c',
+                        'vs_node_text.c'
+                        ])
+
+verse_example_sources = (['examples/list-nodes.c'])
+
+verselib_env = library_env.Copy()
+verselib_env.Append(CPPDEFINES = defines)
+
+verseserver_env = library_env.Copy()
+verseserver_env.Append(CPPDEFINES = defines)
+verseserver_env.Append (LIBS=['libverse'])
+verseserver_env.Append (LIBPATH = ['.'])
+verseserver_env.Append (LIBS= platform_libs)
+
+verseexample_env = library_env.Copy()
+verseexample_env.Append(CPPDEFINES = defines)
+verseexample_env.Append (LIBS=['libverse'])
+verseexample_env.Append (LIBPATH = ['.'])
+verseexample_env.Append (LIBS= platform_libs)
+verseexample_env.Append (CPPPATH = ['.'])
+
+verselib = verselib_env.Library(target='libverse', source=lib_source_files)
+if user_options_dict['REGEN_PROTO']=='yes':
+    verselib_env.Depends(verselib, mkprot)
+verseserver_env.Program(target='verse', source=server_source_files)
+verseexample_env.Program(target='list-nodes', source=verse_example_sources)
diff --git a/extern/verse/dist/v_bignum.c b/extern/verse/dist/v_bignum.c
new file mode 100644 (file)
index 0000000..7ca075f
--- /dev/null
@@ -0,0 +1,859 @@
+/*
+ * Routines for big (thousands of bits) unsigned integers, and
+ * doing simple maths operations on them. Written by Emil Brink.
+ * 
+ * Part of the Verse core, see license details elsewhere.
+ * 
+ * Bignums are represented as vectors of VBigDig (unsigned short),
+ * where the first element holds the length of the number in such
+ * digits. So a 32-bit number would be { 2, low, high }; digits are
+ * in little-endian format.
+ * 
+ * Verse's uint16 and uint32 types are *not* used, since there is no
+ * need to limit the bits. If your machine has 32-bit shorts and 64-
+ * bit ints, this code should cope.
+ * 
+ * By using unsigned shorts, which are assumed to be half the size of
+ * an unsigned int, we can easily do intermediary steps in int-sized
+ * variables, and thus get space for manual carry-management.
+ * 
+ * This is the second incarnation of this code, the first one used
+ * a fixed 2,048-bit VBigNum structure passed by value. It had to be
+ * replaced since it was too weak for the desired functionality. Now,
+ * there's roughly 1,5 weeks of time gone into this code, which still
+ * means it's optimized for simplicity rather than speed.
+ * 
+ * There has been neither time nor interest to meditate over FFTs and
+ * Karatsubas. Reasonable improvements are of course welcome, although
+ * this code *should* not be a bottleneck. Famous last words...
+ * 
+ * In general, these routines do not do a lot of error checking, they
+ * assume you know what you're doing. Numbers must have >0 digits.
+*/
+
+#include <ctype.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "v_randgen.h"
+
+#include "v_bignum.h"
+
+#define        MAX_DIG ((1UL << V_BIGBITS) - 1)
+
+/* ----------------------------------------------------------------------------------------- */
+
+/* Some routines need temporary storage to hold a term or two (the multi-
+ * plier, for instance). Since we don't want to use malloc()/free(), let's
+ * just have a bunch of digits that it's possible to allocate from in a
+ * stack-like manner.
+*/
+static VBigDig         heap[2048 + 32];
+static unsigned int    heap_pos;
+
+/* Allocate a number of <n> digits, returning it un-initialized. */
+static VBigDig * bignum_alloc(unsigned int n)
+{
+       VBigDig *y;
+
+       if(heap_pos + n > sizeof heap / sizeof *heap)
+       {
+               printf("Out of memory in bignum heap -- unbalanced calls?\n");
+               return NULL;
+       }
+       y = heap + heap_pos;
+       heap_pos += n + 1;
+       *y = n;
+       return y;
+}
+
+/* Free a number previously allocated by bignum_allow() above. MUST match in sequences. */
+static void bignum_free(const VBigDig *x)
+{
+       heap_pos -= *x + 1;
+}
+
+/* ----------------------------------------------------------------------------------------- */
+
+/* Set x from bits. External representation is big-endian byte array. */
+void v_bignum_raw_import(VBigDig *x, const void *bits)
+{
+       const unsigned char     *bytes = bits;
+       int                     i;
+
+       for(i = *x++ - 1; i >= 0; i--)
+       {
+               x[i] =  ((VBigDig) *bytes++) << 8;
+               x[i] |= *bytes++;
+       }
+}
+
+/* Set bits to value of x. External representation is big-endian byte array. */
+void v_bignum_raw_export(const VBigDig *x, void *bits)
+{
+       unsigned char   *bytes = bits;
+       int             i;
+
+       for(i = *x++ - 1; i >= 0; i--)
+       {
+               *bytes++ = x[i] >> 8;
+               *bytes++ = x[i];
+       }
+}
+
+/* ----------------------------------------------------------------------------------------- */
+
+/* Assigns x = 0. */
+void v_bignum_set_zero(VBigDig *x)
+{
+       memset(x + 1, 0, *x * sizeof *x);
+}
+
+/* Assigns x = 1. */
+void v_bignum_set_one(VBigDig *x)
+{
+       int     i;
+
+       for(i = *x++ - 1, *x++ = 1; i > 0; i--)
+               *x++ = 0;
+}
+
+/* Assigns x = y. */
+void v_bignum_set_digit(VBigDig *x, VBigDig y)
+{
+       v_bignum_set_zero(x);
+       x[1] = y;
+}
+
+/* Assigns x = <string>, with string in decimal ASCII. Kind of slow. */
+void v_bignum_set_string(VBigDig *x, const char *string)
+{
+       unsigned int    d;
+
+       v_bignum_set_zero(x);
+       for(; *string && isdigit(*string); string++)
+       {
+               v_bignum_mul_digit(x, 10);
+               d = *string - '0';
+               v_bignum_add_digit(x, d);
+       }
+}
+
+/* Assigns x = <string>, with string in hexadecimal ASCII. */
+void v_bignum_set_string_hex(VBigDig *x, const char *string)
+{
+       unsigned int    d;
+
+       if(string[0] == '0' && (string[1] == 'x' || string[1] == 'X'))
+               string += 2;
+       v_bignum_set_zero(x);
+       for(; *string && isxdigit(*string); string++)
+       {
+               v_bignum_bit_shift_left(x, 4);
+               d = tolower(*string) - '0';
+               if(d > 9)
+                       d -= ('a' - '0') - 10;
+               x[1] |= (d & 0xF);
+       }
+}
+
+/* Performs x = y, taking care to handle different precisions correctly by truncating. */
+void v_bignum_set_bignum(VBigDig *x, const VBigDig *y)
+{
+       int     xs, ys, i, s;
+
+       xs = x[0];
+       ys = y[0];
+       if(xs == ys)    /* For same sizes, just memcpy() and be done. */
+       {
+               memcpy(x + 1, y + 1, xs * sizeof *x);
+               return;
+       }
+       else if(ys > xs)
+               s = xs;
+       else
+               s = ys;
+       /* Copy as many digits as will fit, and clear any remaining high digits. */
+       for(i = 1; i <= s; i++)
+               x[i] = y[i];
+       for(; i <= xs; i++)
+               x[i] = 0;
+}
+
+/* Performs x = y[msb:msb-bits], right-adjusting the result. */
+void v_bignum_set_bignum_part(VBigDig *x, const VBigDig *y, unsigned int msb, unsigned int bits)
+{
+       int     i, bit;
+
+       v_bignum_set_zero(x);
+       if(y == NULL || msb > (y[0] * (CHAR_BIT * sizeof *x)))
+               return;
+       for(i = 0; i < bits; i++)
+       {
+               bit = msb - (bits - 1) + i;
+               if(v_bignum_bit_test(y, bit))
+                       v_bignum_bit_set(x, i);
+       }
+}
+
+/* Set x to a random bunch of bits. Should use a real random source. */
+void v_bignum_set_random(VBigDig *x, VRandGen *gen)
+{
+       unsigned int    s = *x++;
+
+       if(gen != NULL)
+               v_randgen_get(gen, x, s * sizeof *x);
+       else
+       {
+               fprintf(stderr, "** Warning: Calling v_bignum_set_random() without VRandGen is potentially expensive\n");
+               if((gen = v_randgen_new()) != NULL)
+               {
+                       v_randgen_get(gen, x, s * sizeof *x);
+                       v_randgen_destroy(gen);
+               }
+               else
+                       fprintf(stderr, __FILE__ ":  Couldn't create random number generator\n");
+       }
+}
+
+/* Print x in hexadecimal, with 0x prefix but no linefeed. */
+void v_bignum_print_hex(const VBigDig *x)
+{
+       int     i, s = *x;
+
+       printf("0x");
+       for(i = 0; i < s; i++)
+               printf("%04X", x[s - i]);
+}
+
+/* Print x in hexadecimal, with linefeed. */
+void v_bignum_print_hex_lf(const VBigDig *x)
+{
+       v_bignum_print_hex(x);
+       printf("\n");
+}
+
+/* ----------------------------------------------------------------------------------------- */
+
+/* x = ~x. */
+void v_bignum_not(VBigDig *x)
+{
+       unsigned int    i, s = *x++;
+
+       for(i = 0; i < s; i++)
+               x[i] = ~x[i];
+}
+
+int v_bignum_bit_test(const VBigDig *x, unsigned int bit)
+{
+       unsigned int    slot = bit / (CHAR_BIT * sizeof *x), m = 1 << (bit % (CHAR_BIT * sizeof *x));
+
+       if(slot < x[0])
+               return (x[slot + 1] & m) != 0;
+       return 0;
+}
+
+/* Compute x |= (1 << bit). */
+void v_bignum_bit_set(VBigDig *x, unsigned int bit)
+{
+       unsigned int    slot, m;
+
+       if(bit >= (*x * (CHAR_BIT * sizeof *x)))
+               return;
+       slot = bit / (CHAR_BIT * sizeof *x);
+       m    = 1 << (bit % (CHAR_BIT * sizeof *x));
+       x[1 + slot] |= m;
+}
+
+/* Returns index of most signifant '1' bit of x, or -1 if x == 0. */
+int v_bignum_bit_msb(const VBigDig *x)
+{
+       int             i;
+       unsigned int    s = *x++;
+
+       for(i = s - 1; i >= 0; i--)
+       {
+               if(x[i] != 0)
+               {
+                       int     bit = (i + 1) * (CHAR_BIT * sizeof *x) - 1;
+                       VBigDig d = x[i], mask;
+
+                       for(mask = 1 << (CHAR_BIT * sizeof *x - 1); mask != 0; mask >>= 1, bit--)
+                       {
+                               if(d & mask)
+                                       return bit;
+                       }
+               }
+       }
+       return -1;
+}
+
+int v_bignum_bit_size(const VBigDig *x)
+{
+       return *x * V_BIGBITS;
+}
+
+/* Perform x <<= count. */
+void v_bignum_bit_shift_left(VBigDig *x, unsigned int count)
+{
+       unsigned int    t, carry, s = *x++;
+       register int    i;
+
+       if(count >= CHAR_BIT * sizeof *x)       /* Shift whole digits. */
+       {
+               unsigned int    places = count / (CHAR_BIT * sizeof *x);
+
+               for(i = s - 1; i >= places; i--)
+                       x[i] = x[i - places];
+               for(; i >= 0; i--)              /* Clear out the LSBs. */
+                       x[i] = 0;
+               count -= places * (CHAR_BIT * sizeof *x);
+               if(count == 0)
+                       return;
+       }
+       /* Shift bits. */
+       for(i = carry = 0; i < s; i++)
+       {
+               t = (x[i] << count) | carry;
+               x[i] = t;
+               carry = t >> (CHAR_BIT * sizeof *x);
+       }
+}
+
+/* Perform x <<= 1. This is a frequent operation so it can have its own function. */
+void v_bignum_bit_shift_left_1(VBigDig *x)
+{
+       register unsigned int   t, carry, s = *x++, i;
+
+       /* Shift bits. */
+       for(i = carry = 0; i < s; i++)
+       {
+               t = (x[i] << 1) | carry;
+               x[i] = t;
+               carry = t >> (CHAR_BIT * sizeof *x);
+       }
+}
+
+/* Perform x >>= count. */
+void v_bignum_bit_shift_right(VBigDig *x, unsigned int count)
+{
+       unsigned int    t, carry, s = *x++;
+       int             i;
+
+       /* Shift entire digits first. */
+       if(count >= CHAR_BIT * sizeof *x)
+       {
+               unsigned int    places = count / (CHAR_BIT * sizeof *x);
+
+               if(places > s)
+               {
+                       memset(x, 0, s * sizeof *x);
+                       return;
+               }
+               for(i = 0; i < s - places; i++)
+                       x[i] = x[i + places];
+               for(; i < s; i++)
+                       x[i] = 0;
+               count -= places * CHAR_BIT * sizeof *x;
+               if(count == 0)
+                       return;
+       }
+       /* Shift any remaining bits. */
+       for(i = s - 1, carry = 0; i >= 0; i--)
+       {
+               t = x[i] << (CHAR_BIT * sizeof *x);
+               t >>= count;
+               t |= carry;
+               carry = (t & MAX_DIG) << (CHAR_BIT * sizeof *x);
+               x[i] = t >> (CHAR_BIT * sizeof *x);
+       }
+}
+
+/* ----------------------------------------------------------------------------------------- */
+
+/* Return x == 0. */
+int v_bignum_eq_zero(const VBigDig *x)
+{
+       unsigned int    i, s = *x++;
+
+       for(i = 0; i < s; i++)
+               if(x[i])
+                       return 0;
+       return 1;
+}
+
+/* Return x == 1. */
+int v_bignum_eq_one(const VBigDig *x)
+{
+       unsigned int    i, s = *x++;
+
+       if(x[0] != 1)
+               return 0;
+       for(i = 1; i < s; i++)
+               if(x[i])
+                       return 0;
+       return 1;
+}
+
+/* Returns x == y, handling different lengths properly. */
+int v_bignum_eq(const VBigDig *x, const VBigDig *y)
+{
+       unsigned int    i, xs, ys, cs;
+
+       if(x == y)              /* Quick test thanks to pointer representation. */
+               return 1;
+       xs = *x++;
+       ys = *y++;
+
+       if(xs == ys)            /* Same size? Then let's be quick about this. */
+               return memcmp(x, y, xs * sizeof *x) == 0;
+       else
+       {
+               cs = xs < ys ? xs : ys;         /* Common size. */
+               if(memcmp(x, y, cs * sizeof *x) == 0)
+               {
+                       const VBigDig   *l;
+
+                       if(cs == xs)            /* y is longer. */
+                               l = y, i = ys - 1;
+                       else
+                               l = x, i = xs - 1;
+                       for(; i > cs; i--)
+                               if(l[i])
+                                       return 0;
+                       return 1;
+               }
+       }
+       return 0;
+}
+
+/* Returns x >= y. */
+int v_bignum_gte(const VBigDig *x, const VBigDig *y)
+{
+       unsigned int    xs, ys;
+       int             i, j, k;
+
+       if(x == y)
+               return 1;
+       /* Find indexes of highest-most used digit in each of the numbers. */
+       xs = *x++;
+       ys = *y++;
+       for(i = xs - 1; i >= 0; i--)
+               if(x[i] != 0)
+                       break;
+       for(j = ys - 1; j >= 0; j--)
+               if(y[j] != 0)
+                       break;
+       /* Both zero? */
+       if(i < 0 && j < 0)
+               return 1;
+       /* Quick answers exists for different-sized numbers. Find them. */
+       if(i < j)
+               return 0;
+       if(i > j)
+               return 1;
+       /* Compare digit by digit. */
+       for(k = i; k >= 0; k--)
+       {
+               if(x[k] < y[k])
+                       return 0;
+               if(x[k] > y[k])
+                       return 1;
+       }
+       return x[k] >= y[k];
+}
+
+/* ----------------------------------------------------------------------------------------- */
+
+/* Computes x += y. */
+void v_bignum_add_digit(VBigDig *x, VBigDig y)
+{
+       unsigned int    i, s = *x++, t;
+
+       t = x[0] + y;
+       x[0] = t;
+       if(t > MAX_DIG)
+       {
+               for(i = 1; i < s; i++)
+               {
+                       if(++x[i])
+                               break;
+               }
+       }
+}
+
+/* Computes x -= y. */
+void v_bignum_sub_digit(VBigDig *x, VBigDig y)
+{
+       unsigned int    i, s = *x++, t;
+
+       t = x[0] - y;
+       x[0] = t;
+       if(t > MAX_DIG)
+       {
+               for(i = 1; i < s; i++)
+               {
+                       x[i]--;
+                       if(x[i] < MAX_DIG)
+                               break;
+               }
+       }
+}
+
+/* Computes x *= y. */
+void v_bignum_mul_digit(VBigDig *x, VBigDig y)
+{
+       unsigned int    i, s = *x++, carry, t;
+
+       for(i = carry = 0; i < s; i++)
+       {
+               t = x[i] * y + carry;
+               x[i] = t;
+               carry = t >> (CHAR_BIT * sizeof *x);
+       }
+}
+
+/* ----------------------------------------------------------------------------------------- */
+
+/* Computes x += y. */
+void v_bignum_add(VBigDig *x, const VBigDig *y)
+{
+       unsigned int    i, xs = *x++, ys = *y++, s, carry, t;
+
+       s = xs < ys ? xs : ys;
+       for(i = carry = 0; i < s; i++)
+       {
+               t = x[i] + y[i] + carry;
+               x[i] = t;
+               carry = t > MAX_DIG;
+       }
+       for(; carry && i < xs; i++)
+       {
+               t = x[i] + carry;
+               x[i] = t;
+               carry = t > MAX_DIG;
+       }
+}
+
+/* Computes x -= y. */
+void v_bignum_sub(VBigDig *x, const VBigDig *y)
+{
+       unsigned int    i, xs = *x++, ys = *y++, s, carry, t;
+
+       if(x == y)
+       {
+               v_bignum_set_zero(x - 1);
+               return;
+       }
+       s = xs < ys ? xs : ys;
+       for(i = carry = 0; i < s; i++)
+       {
+               t = x[i] - y[i] - carry;
+               x[i] = t;
+               carry = t > MAX_DIG;
+       }
+       for(; carry && i < xs; i++)
+       {
+               t = x[i] - carry;
+               x[i] = t;
+               carry = t > MAX_DIG;
+       }
+}
+
+/* Compute x *= y, using as many digits as is necessary, then truncating the
+ * result down. This is Algorithm 14.12 from "Handbook of Applied Cryptography".
+*/
+void v_bignum_mul(VBigDig *x, const VBigDig *y)
+{
+       int             n = *x, t = *y, i, j;
+       VBigDigs        uv = 0, c, w[2048];
+
+       memset(w, 0, (n + t + 1) * sizeof *w);
+       for(i = 0; i < t; i++)
+       {
+               c = 0;
+               for(j = 0; j < n; j++)
+               {
+                       uv = w[i + j] + x[1 + j] * y[1 + i] + c;
+                       w[i + j] = uv & ((1 << V_BIGBITS) - 1);
+                       c = uv >> V_BIGBITS;
+               }
+               w[i + n + 1] = uv >> V_BIGBITS;
+       }
+       /* Write low words of w back into x. */
+       for(i = 0; i < *x; i++)
+               x[1 + i] = w[i];
+}
+
+/* Computes x /= y and remainder = x % y. */
+void v_bignum_div(VBigDig *x, const VBigDig *y, VBigDig *remainder)
+{
+       VBigDig *q, *work;
+       int     msbx = v_bignum_bit_msb(x), msby = v_bignum_bit_msb(y), next;
+
+       /* Compare magnitudes of inputs, allows quick exits. */
+       if(msby > msbx)
+       {
+               if(remainder != NULL)
+                       v_bignum_set_bignum(remainder, x);
+               v_bignum_set_zero(x);
+               return;
+       }
+       if(msby < 0)
+       {
+               v_bignum_set_zero(x);
+               return;
+       }
+       q = bignum_alloc(*x);
+       v_bignum_set_zero(q);
+       work = bignum_alloc(*x);
+       v_bignum_set_bignum_part(work, x, msbx, msby + 1);
+
+       for(next = msbx - (msby + 1); next >= -1; next--)
+       {
+               v_bignum_bit_shift_left_1(q);
+               if(v_bignum_gte(work, y))
+               {
+                       q[1] |= 1;
+                       v_bignum_sub(work, y);
+               }
+               v_bignum_bit_shift_left_1(work);
+               if(v_bignum_bit_test(x, next))
+                       work[1] |= 1;
+       }
+       v_bignum_bit_shift_right(work, 1);      /* Undo the last shift (when next==-1). */
+       
+       if(remainder != NULL)
+       {
+/*             printf("div() got remainder ");
+               v_bignum_print_hex_lf(work);
+*/
+               v_bignum_set_bignum(remainder, work);
+       }
+       bignum_free(work);
+       v_bignum_set_bignum(x, q);
+       bignum_free(q);
+}
+
+/* Computes x %= y. */
+void v_bignum_mod(VBigDig *x, const VBigDig *y)
+{
+       int     digs;
+       VBigDig *tmp;
+
+/*     printf("computing ");
+       v_bignum_print_hex(x);
+       printf("L %% ");
+       v_bignum_print_hex(y);
+*/
+       digs = *x > *y ? *x : *y;
+       tmp = bignum_alloc(digs);
+       v_bignum_div(x, y, tmp);
+       v_bignum_set_bignum(x, tmp);
+       bignum_free(tmp);
+/*     printf("L = ");
+       v_bignum_print_hex_lf(x);
+*/
+}
+
+/* Initialize Barrett reduction by computing the "mu" helper value. Defined in
+ * Handbook of Applied Cryptography algorithm 14.42 as floor(b^2k / m).
+*/
+const VBigDig * v_bignum_reduce_begin(const VBigDig *m)
+{
+       VBigDig *mu;
+       int     k;
+
+       for(k = *m; m[k] == 0; k--)
+               ;
+/*     printf("k=%d -> digits are 0..%u\n", k, k - 1);
+       printf("computing mu=floor(65536^%d/", 2 * k);
+       v_bignum_print_hex(m);
+       printf(")\n");
+*/     mu = bignum_alloc(2 * k + 1);
+       /* b ^ 2k is just 65536 << 2k, i.e. set bit 16 * 2k. */
+       v_bignum_set_zero(mu);
+       v_bignum_bit_set(mu, V_BIGBITS * 2 * k);
+/*     v_bignum_print_hex_lf(mu);*/
+       v_bignum_div(mu, m, NULL);
+
+       return mu;
+}
+
+void v_bignum_reduce_end(const VBigDig *mu)
+{
+       bignum_free(mu);
+}
+
+/* Compute x % m, using mu as the helper quantity mu, precomputed by the
+ * routine above.
+*/
+void v_bignum_reduce(VBigDig *x, const VBigDig *m, const VBigDig *mu)
+{
+       VBigDig *q, *r1, *r2, *r;
+       int     i, k;
+
+       for(k = *m; m[k] == 0; k--)
+               ;
+       /* Step 1, compute the q helper. */
+       q = bignum_alloc(*x + *mu - (k - 1));   /* Tighter bound number length (was 2 * *x). */
+       v_bignum_set_bignum(q, x);
+       v_bignum_bit_shift_right(q, V_BIGBITS * (k - 1));
+       v_bignum_mul(q, mu);
+       v_bignum_bit_shift_right(q, V_BIGBITS * (k + 1));
+
+       /* Step 2, initialize. */
+       r1 = bignum_alloc(*x);
+       r2 = bignum_alloc(*x);
+       v_bignum_set_bignum(r1, x);
+       for(i = k + 1; i < *r1; i++)
+               r1[i + 1] = 0;
+       v_bignum_set_bignum(r2, q);
+       v_bignum_mul(r2, m);
+       for(i = k + 1; i < *r2; i++)
+               r2[i + 1] = 0;
+       r = x;
+       v_bignum_set_bignum(r, r1);
+       v_bignum_sub(r, r2);
+       /* Step 3, make sure r is positive. */
+       if(v_bignum_bit_test(r, V_BIGBITS * *r - 1))
+       {
+               VBigDig *term;
+               
+               term = bignum_alloc(k + 1 * V_BIGBITS);
+               v_bignum_set_zero(term);
+               v_bignum_bit_set(term, V_BIGBITS * (k + 1));
+               v_bignum_add(r, term);
+               bignum_free(term);
+       }
+       /* Step 4, loop. */
+       while(v_bignum_gte(r, m))
+               v_bignum_sub(r, m);
+
+       bignum_free(r2);
+       bignum_free(r1);
+       bignum_free(q);
+}
+
+/* Compute x * x using the algorithm 14.16 from "Handbook of Applied Cryptography".
+ * Note that since 'w' needs to be double-precision (i.e., 32-bit), we cannot allocate
+ * it using bignum_alloc() cleanly. Thus the static limit, which should be enough here.
+ * NOTE: This very much assumes V_BIGBITS == 16.
+*/
+void v_bignum_square_half(VBigDig *x)
+{
+       VBigDigs        w[256], uv, c, ouv;
+       int             t = *x / 2, i, j, high;
+
+       if(t == 0)
+               return;
+       for(; x[t] == 0; t--)
+               ;
+       memset(w, 0, 2 * t * sizeof *w);        /* Clear digits of w. */
+/*     printf("print %lu, ", ++count);
+       v_bignum_print_hex(x);
+       printf("*");
+       v_bignum_print_hex(x);
+*/     for(i = 0; i < t; i++)
+       {
+/*             printf("computing w[%d]: %lX + %lX * %lX\n", 2 * i, w[2 * i], x[1 + i], x[1 + i]);*/
+               uv = w[2 * i] + x[1 + i] * x[1 + i];
+/*             printf("setting w[%d]=%X [before]\n", 2 * i, uv & 0xffff);*/
+               w[2 * i] = uv & 0xffff;
+               c = uv >> V_BIGBITS;
+/*             printf("uv before=%X, c=%X\n", uv, c);*/
+               high = 0;
+               for(j = i + 1; j < t; j++)
+               {
+/*                     printf("computing uv=%X+2*%X*%X+%X\n", w[i + j], x[1 + j], x[1 + i], c);*/
+                       uv = x[1 + j] * x[1 + i];
+                       high = (uv & 0x80000000) != 0;
+                       uv *= 2;
+                       ouv = uv;       /* Addition below might wrap and generate high bit. */
+                       uv += w[i + j] + c;
+/*                     printf("ouv=0x%lX uv=0x%lX\n", ouv, uv);*/
+                       high |= uv < ouv;
+/*                     printf("setting w[%d]=%lX [inner] uv=%lX high=%d c=%X\n", i + j, uv & 0xffff, uv, high, c);*/
+                       w[i + j] = uv & 0xffff;
+                       c = (uv >> V_BIGBITS) | (high << V_BIGBITS);
+               }
+/*             printf("setting w[%d] to %X [after]\n", i + t, (uv >> 16) | (high << 16));*/
+               w[i + t] = (uv >> V_BIGBITS) | (high << V_BIGBITS);
+       }
+/*     printf("w=0x");
+       for(i = *x - 1; i >= 0; i--)
+               printf("%04X.", w[i]);
+       printf("\n");
+*/     /* Write low words of w back into x, trashing it with the square. */
+       for(i = 0; i < 2 * t; i++)
+               x[1 + i] = w[i];
+       for(; i < *x; i++)
+               x[1 + i] = 0;
+/*     printf("==");
+       v_bignum_print_hex_lf(x);
+*/
+}
+
+/* Computes x = (x^y) % n, where ^ denotes exponentiation. */
+void v_bignum_pow_mod(VBigDig *x, const VBigDig *y, const VBigDig *n)
+{
+       VBigDig         *tmp;
+       const VBigDig   *mu;
+       int             i, k;
+
+/*     printf("computing pow(");
+       v_bignum_print_hex(x);
+       printf("L,");
+       v_bignum_print_hex(y);
+       printf("L,");
+       v_bignum_print_hex(n);
+       printf("L)\n");
+*/
+       tmp = bignum_alloc(2 * *x);     /* Squaring needs twice the bits, or lossage occurs. */
+       v_bignum_set_bignum(tmp, x);
+       k = v_bignum_bit_msb(y);
+       mu = v_bignum_reduce_begin(n);
+       for(i = k - 1; i >= 0; i--)
+       {
+               v_bignum_square_half(tmp);
+               v_bignum_reduce(tmp, n, mu);
+               if(v_bignum_bit_test(y, i))
+               {
+                       v_bignum_mul(tmp, x);
+                       v_bignum_reduce(tmp, n, mu);
+               }
+       }
+       v_bignum_set_bignum(x, tmp);
+       v_bignum_reduce_end(mu);
+       bignum_free(tmp);
+}
+
+/* ----------------------------------------------------------------------------------------- */
+
+#if defined STANDALONE
+
+int main(void)
+{
+       VBigDig VBIGNUM(x, 3648), VBIGNUM(y, 128), VBIGNUM(z, 128);
+
+       printf("MAX_DIG=%u\n", MAX_DIG);
+       
+       v_bignum_set_string_hex(x, "0x433864FE0F8FAC180FF1BC3A5BFD0C5566F6B11679E27294EDCC43056EB73EE118415E0CD6E6519509476EB21341ED0328BA7B14E0ED80D5E100A4549C5202B57B4CF17A74987631B6BA896C0DBA2095A7EDE5B9C4B4EEFCD1B9EF8474BCB7FBD0F64B549625D444847ED1FCB7F8050EB4F22794F694A0FAC6DFFB781C264B227966840185F9216484F6A7954741CB11FC14DEC2937EAD2CE640FD9A4339706BDB5BC355079C2F2F7994669DFA5B20C50D957A676E67C86835037078323A0BDAD3686B8E638749F327A7AD433C0D18BCD2FC970D125914C7FBEE061290A0F0F3572E207");
+       v_bignum_set_bignum(y, x);
+       v_bignum_set_digit(z, 77);
+
+       printf("x:");
+       v_bignum_print_hex_lf(x);
+       printf("y:");
+       v_bignum_print_hex_lf(y);
+       printf("r:");
+       v_bignum_print_hex_lf(z);
+       v_bignum_pow_mod(x, y, z);
+       printf(" =");
+       v_bignum_print_hex_lf(x);
+
+       return 0;
+}
+
+#endif         /* STANDALONE */
diff --git a/extern/verse/dist/v_bignum.h b/extern/verse/dist/v_bignum.h
new file mode 100644 (file)
index 0000000..06e5884
--- /dev/null
@@ -0,0 +1,89 @@
+/*
+ * Verse routines for big integer operations.
+ * Handy in heavy encryption done during connect.
+*/
+
+#include <limits.h>
+
+#include "v_randgen.h"
+
+/* ----------------------------------------------------------------------------------------- */
+
+typedef unsigned short VBigDig;        /* Type used to hold one digit of a bignum. */
+typedef unsigned int   VBigDigs;       /* Should hold precisely two digits. */
+
+#define        V_BIGBITS       (CHAR_BIT * sizeof (VBigDig))
+
+/* Use this macro to initialize big number variables, like so:
+ * VBigDig BIGNUM(foo, 128), BIGNUM(bar, 256);
+ * Creates automatic variables 'foo' of 128 bits, and 'bar' of 256.
+ * 
+ * Note that 'bits' must be a multiple of V_BIGBITS, completely
+ * arbitrary number sizes are not supported by this module.
+*/
+#define        VBIGNUM(n, bits)        n[1 + (bits / V_BIGBITS)] = { bits / V_BIGBITS }
+
+/* ----------------------------------------------------------------------------------------- */
+
+/* Import/export numbers from raw bits. The number x must have been allocated
+ * with the desired number of bits to read/write.
+*/
+extern void    v_bignum_raw_import(VBigDig *x, const void *bits);
+extern void    v_bignum_raw_export(const VBigDig *x, void *bits);
+
+/* Initializers. */
+extern void    v_bignum_set_zero(VBigDig *x);
+extern void    v_bignum_set_one(VBigDig *x);
+extern void    v_bignum_set_digit(VBigDig *x, VBigDig y);
+extern void    v_bignum_set_string(VBigDig *x, const char *string);    /* Decimal. */
+extern void    v_bignum_set_string_hex(VBigDig *x, const char *string);
+extern void    v_bignum_set_bignum(VBigDig *x, const VBigDig *y);
+/* x = <bits> most significant <bits> bits of <y>, starting at <msb>. Right-
+ * adjusted in x, so that e.g. y=0xcafebabec001 msb=47 bits=16 gives x=0xcafe.
+*/ 
+extern void    v_bignum_set_bignum_part(VBigDig *x, const VBigDig *y,
+                                        unsigned int msb, unsigned int bits);
+extern void    v_bignum_set_random(VBigDig *x, VRandGen *gen);
+
+/* Handy during debugging. */
+extern void    v_bignum_print_hex(const VBigDig *x);
+extern void    v_bignum_print_hex_lf(const VBigDig *x);
+
+/* Bit operators. */
+extern void    v_bignum_not(VBigDig *x);
+extern int     v_bignum_bit_test(const VBigDig *x, unsigned int bit);
+extern void    v_bignum_bit_set(VBigDig *x, unsigned int bit);
+extern int     v_bignum_bit_msb(const VBigDig *x);
+extern int     v_bignum_bit_size(const VBigDig *x);
+extern void    v_bignum_bit_shift_left(VBigDig *x, unsigned int count);
+extern void    v_bignum_bit_shift_left_1(VBigDig *x);
+extern void    v_bignum_bit_shift_right(VBigDig *x, unsigned int count);
+
+/* Comparators. */
+extern int     v_bignum_eq_zero(const VBigDig *x);                     /* x == 0. */
+extern int     v_bignum_eq_one(const VBigDig *x);                      /* x == 1. */
+extern int     v_bignum_eq(const VBigDig *x, const VBigDig *y);        /* x == y. */
+extern int     v_bignum_gte(const VBigDig *x, const VBigDig *y);       /* x >= y. */
+
+/* Number vs single-digit arithmetic. */
+extern void    v_bignum_add_digit(VBigDig *x, VBigDig y);      /* x += y. */
+extern void    v_bignum_sub_digit(VBigDig *x, VBigDig y);      /* x -= y. */
+extern void    v_bignum_mul_digit(VBigDig *x, VBigDig y);      /* x *= y. */
+
+/* Arithmetic. */
+extern void    v_bignum_add(VBigDig *x, const VBigDig *y);     /* x += y. */
+extern void    v_bignum_sub(VBigDig *x, const VBigDig *y);     /* x -= y. */
+extern void    v_bignum_mul(VBigDig *x, const VBigDig *y);     /* x *= y. */
+extern void    v_bignum_div(VBigDig *x, const VBigDig *y, VBigDig *remainder);
+extern void    v_bignum_mod(VBigDig *x, const VBigDig *y);     /* x %= y. */
+
+/* Barrett reducer for fast x % m computation. Requires precalcing step. */
+extern const VBigDig * v_bignum_reduce_begin(const VBigDig *m);
+extern void            v_bignum_reduce(VBigDig *x, const VBigDig *m, const VBigDig *mu);
+extern void            v_bignum_reduce_end(const VBigDig *mu);
+
+/* Compute x *= x, assuming x only uses half of its actual size. */
+extern void    v_bignum_square_half(VBigDig *x);
+
+/* Compute pow(x, y, n) == (x raised to the y:th power) modulo n. */
+extern void    v_bignum_pow_mod(VBigDig *x, const VBigDig *y, const VBigDig *n);
diff --git a/extern/verse/dist/v_cmd_buf.c b/extern/verse/dist/v_cmd_buf.c
new file mode 100644 (file)
index 0000000..bee000a
--- /dev/null
@@ -0,0 +1,125 @@
+/*
+**
+*/
+
+#include <stdio.h>
+#include <stdlib.h>
+
+#include "verse_header.h"
+#include "v_pack.h"
+#include "v_cmd_buf.h"
+
+static const size_t    vcmdbuf_chunk_size[] = { 10000, 10000, 10000, 10000, 8000, 5000, 500 }; /* If you think memory is cheap, set this to a high value. */
+
+/* Sizes of individual command buffers, indexable by VCMDBufSize values. Switch-killer. */
+static const size_t    vcmdbuf_size[] = {
+       sizeof (VCMDBuffer10), sizeof (VCMDBuffer20), sizeof (VCMDBuffer30), sizeof (VCMDBuffer80),
+       sizeof (VCMDBuffer160), sizeof (VCMDBuffer320), sizeof (VCMDBuffer1500)
+};
+
+#define VCMDBUF_INIT_CHUNK_FACTOR 0.5
+
+static struct {
+       VCMDBufHead     *buffers[VCMDBS_COUNT];
+       unsigned int available[VCMDBS_COUNT];
+} VCMDBufData;
+
+static boolean v_cmd_buf_initialized = FALSE;
+
+void cmd_buf_init(void)
+{
+       unsigned int i, j;
+       VCMDBufHead *buf, *b;
+
+       for(i = 0; i < VCMDBS_COUNT; i++)
+       {
+               VCMDBufData.buffers[i] = NULL;
+               VCMDBufData.available[i] = vcmdbuf_chunk_size[i] * VCMDBUF_INIT_CHUNK_FACTOR;
+               for(j = 0, buf = NULL; j < VCMDBufData.available[i]; j++, buf = b)
+               {
+                       b = v_cmd_buf_allocate(i);
+                       b->next = buf;
+               }
+               VCMDBufData.buffers[i] = buf;
+       }
+       v_cmd_buf_initialized = TRUE;
+}
+
+VCMDBufHead * v_cmd_buf_allocate(VCMDBufSize buf_size)
+{
+       VCMDBufHead     *output = NULL;
+
+       if(VCMDBufData.buffers[buf_size] != NULL)
+       {
+               output = VCMDBufData.buffers[buf_size];
+               VCMDBufData.buffers[buf_size] = output->next;
+               VCMDBufData.available[buf_size]--;
+       }
+       else
+       {
+               if(buf_size < sizeof vcmdbuf_size / sizeof *vcmdbuf_size)
+                       output = malloc(vcmdbuf_size[buf_size]);
+               else
+               {
+                       fprintf(stderr, "v_cmd_buf.c: Can't handle buffer size %d\n", buf_size);
+                       return NULL;
+               }
+               output->buf_size = buf_size;
+       }
+       output->next = NULL;    
+       output->packet = 0;
+       output->size = 0;
+       output->address_size = -1;
+       return output;
+}
+
+void v_cmd_buf_free(VCMDBufHead *head)
+{
+       if(VCMDBufData.available[head->buf_size] < vcmdbuf_chunk_size[head->buf_size])
+       {
+               head->next = VCMDBufData.buffers[head->buf_size];
+               VCMDBufData.buffers[head->buf_size] = head;
+               VCMDBufData.available[head->buf_size]++;
+       }
+       else
+               free(head);
+}
+
+void v_cmd_buf_set_size(VCMDBufHead *head, unsigned int size)
+{
+       if(head->address_size > size);
+               head->address_size = size;
+       head->size = size;
+}
+
+void v_cmd_buf_set_address_size(VCMDBufHead *head, unsigned int size)
+{
+       unsigned int i;
+
+       head->address_size = size;
+       head->address_sum = 0;
+       for(i = 1; i < size + 1; i++)
+               head->address_sum += i * i * (uint32)(((VCMDBuffer1500 *)head)->buf[i - 1]);
+}
+
+void v_cmd_buf_set_unique_address_size(VCMDBufHead *head, unsigned int size)
+{
+       static unsigned int i = 0;
+
+       head->address_size = size;
+       head->address_sum = i++;
+}
+
+boolean        v_cmd_buf_compare(VCMDBufHead *a, VCMDBufHead *b)
+{
+       unsigned int i;
+
+       if(a->address_sum != b->address_sum)
+               return FALSE;
+       if(a->address_size != b->address_size)
+               return FALSE;
+       for(i = 0; i < a->address_size; i++)
+               if(((VCMDBuffer1500 *)a)->buf[i] != ((VCMDBuffer1500 *)b)->buf[i])
+                       return FALSE;
+       return TRUE;
+}
diff --git a/extern/verse/dist/v_cmd_buf.h b/extern/verse/dist/v_cmd_buf.h
new file mode 100644 (file)
index 0000000..6eda764
--- /dev/null
@@ -0,0 +1,74 @@
+/*
+**
+*/
+
+#include <stdlib.h>
+
+#include "verse_header.h"
+#include "v_pack.h"
+
+#define        V_NOQ_MAX_PACKET_SIZE   1500
+
+typedef enum {
+       VCMDBS_10 = 0,
+       VCMDBS_20 = 1,
+       VCMDBS_30 = 2,
+       VCMDBS_80 = 3,
+       VCMDBS_160 = 4,
+       VCMDBS_320 = 5,
+       VCMDBS_1500 = 6,
+       VCMDBS_COUNT = 7
+} VCMDBufSize;
+
+typedef struct {
+       void                    *next;
+       uint32                  packet;
+       unsigned int    address_size;
+       unsigned int    address_sum;
+       VCMDBufSize             buf_size;
+       unsigned int    size;
+} VCMDBufHead;
+
+typedef struct {
+       VCMDBufHead     head;
+       uint8           buf[10];
+} VCMDBuffer10;
+
+typedef struct {
+       VCMDBufHead     head;
+       uint8           buf[20];
+} VCMDBuffer20;
+
+typedef struct {
+       VCMDBufHead head;
+       uint8           buf[30];
+} VCMDBuffer30;
+
+typedef struct {
+       VCMDBufHead     head;
+       uint8           buf[80];
+} VCMDBuffer80;
+
+typedef struct {
+       VCMDBufHead     head;
+       uint8           buf[160];
+} VCMDBuffer160;
+
+typedef struct {
+       VCMDBufHead     head;
+       uint8           buf[320];
+} VCMDBuffer320;
+
+
+typedef struct {
+       VCMDBufHead     head;
+       uint8           buf[1500];
+} VCMDBuffer1500;
+
+extern VCMDBufHead     *v_cmd_buf_allocate(VCMDBufSize buf_size);
+extern void            v_cmd_buf_free(VCMDBufHead *head);
+
+extern void            v_cmd_buf_set_size(VCMDBufHead *head, unsigned int size);
+extern void            v_cmd_buf_set_address_size(VCMDBufHead *head, unsigned int size);
+extern void            v_cmd_buf_set_unique_address_size(VCMDBufHead *head, unsigned int size);
+extern boolean         v_cmd_buf_compare(VCMDBufHead *a, VCMDBufHead *b);
diff --git a/extern/verse/dist/v_cmd_def_a.c b/extern/verse/dist/v_cmd_def_a.c
new file mode 100644 (file)
index 0000000..8557601
--- /dev/null
@@ -0,0 +1,94 @@
+/*
+ * Command definitions for audio node commands.
+*/
+
+#include <stdlib.h>
+#include <stdio.h>
+#include "verse_header.h"
+#include "v_cmd_gen.h"
+#include "v_cmd_buf.h"
+
+#if defined(V_GENERATE_FUNC_MODE)
+
+void v_gen_audio_cmd_def(void)
+{
+       v_cg_new_cmd(V_NT_AUDIO,                "a_buffer_create", 160, VCGCT_NORMAL);
+       v_cg_add_param(VCGP_NODE_ID,    "node_id");
+       v_cg_add_param(VCGP_BUFFER_ID,  "buffer_id");
+       v_cg_add_param(VCGP_END_ADDRESS, NULL);
+       v_cg_add_param(VCGP_NAME,               "name");
+       v_cg_add_param(VCGP_ENUM_NAME,  "VNABlockType");
+       v_cg_add_param(VCGP_ENUM,               "type");
+       v_cg_add_param(VCGP_REAL64,             "frequency");
+       v_cg_alias(FALSE, "a_buffer_destroy", "if(name[0] == 0)", 2, NULL);
+       v_cg_end_cmd();
+
+       v_cg_new_cmd(V_NT_AUDIO,                "a_buffer_subscribe", 161, VCGCT_NORMAL); 
+       v_cg_add_param(VCGP_NODE_ID,    "node_id");
+       v_cg_add_param(VCGP_BUFFER_ID,  "layer_id");
+       v_cg_add_param(VCGP_END_ADDRESS, NULL);
+       v_cg_alias(TRUE, "a_buffer_unsubscribe", NULL, 2, NULL);
+       v_cg_end_cmd();
+
+       v_cg_new_cmd(V_NT_AUDIO,                "a_block_set", 162, VCGCT_NORMAL); 
+       v_cg_add_param(VCGP_NODE_ID,    "node_id");
+       v_cg_add_param(VCGP_LAYER_ID,   "buffer_id");
+       v_cg_add_param(VCGP_UINT32,             "block_index");
+       v_cg_add_param(VCGP_END_ADDRESS, NULL);
+       v_cg_add_param(VCGP_ENUM_NAME,  "VNABlockType");
+       v_cg_add_param(VCGP_ENUM,               "type");
+       v_cg_add_param(VCGP_POINTER_TYPE,       "VNABlock");
+       v_cg_add_param(VCGP_POINTER,            "samples");
+
+       v_cg_add_param(VCGP_PACK_INLINE, "\tbuffer_pos += vnp_pack_audio_block(&buf[buffer_pos], type, samples);\n");
+
+       v_cg_add_param(VCGP_UNPACK_INLINE, "\tif(type <= VN_A_BLOCK_REAL64)\n\t{\n"
+       "\t\tVNABlock\tblock;\n"
+       "\t\tbuffer_pos += vnp_unpack_audio_block(&buf[buffer_pos], type, &block);\n"
+       "\t\tif(func_a_block_set != NULL)\n"
+       "\t\t\tfunc_a_block_set(v_fs_get_user_data(162), node_id, buffer_id, block_index, (VNABlockType) type, &block);\n"
+       "\t\treturn buffer_pos;\n"
+       "\t}\n");
+       v_cg_alias(FALSE, "a_block_clear", "if(type > VN_A_BLOCK_REAL64)", 3, NULL);
+       v_cg_end_cmd();
+
+
+       v_cg_new_cmd(V_NT_AUDIO,                "a_stream_create", 163, VCGCT_NORMAL);
+       v_cg_add_param(VCGP_NODE_ID,    "node_id");
+       v_cg_add_param(VCGP_LAYER_ID,   "stream_id");
+       v_cg_add_param(VCGP_END_ADDRESS, NULL);
+       v_cg_add_param(VCGP_NAME,               "name");
+       v_cg_alias(FALSE, "a_stream_destroy", "if(name[0] == 0)", 2, NULL);
+       v_cg_end_cmd();
+
+       v_cg_new_cmd(V_NT_AUDIO,                "a_stream_subscribe", 164, VCGCT_NORMAL); 
+       v_cg_add_param(VCGP_NODE_ID,    "node_id");
+       v_cg_add_param(VCGP_LAYER_ID,   "stream_id");
+       v_cg_add_param(VCGP_END_ADDRESS, NULL);
+       v_cg_alias(TRUE, "a_stream_unsubscribe", NULL, 2, NULL);
+       v_cg_end_cmd();
+
+       v_cg_new_cmd(V_NT_AUDIO,                "a_stream", 165, VCGCT_NORMAL); 
+       v_cg_add_param(VCGP_NODE_ID,    "node_id");
+       v_cg_add_param(VCGP_LAYER_ID,   "stream_id");
+       v_cg_add_param(VCGP_END_ADDRESS, NULL);
+       v_cg_add_param(VCGP_UINT32,             "time_s");
+       v_cg_add_param(VCGP_UINT32,             "time_f");
+       v_cg_add_param(VCGP_ENUM_NAME,  "VNABlockType");
+       v_cg_add_param(VCGP_ENUM,               "type");
+       v_cg_add_param(VCGP_REAL64,             "frequency");
+       v_cg_add_param(VCGP_POINTER_TYPE,       "VNABlock");
+       v_cg_add_param(VCGP_POINTER,    "samples");
+
+       v_cg_add_param(VCGP_PACK_INLINE, "\tbuffer_pos += vnp_pack_audio_block(&buf[buffer_pos], type, samples);\n");
+
+       v_cg_add_param(VCGP_UNPACK_INLINE, "\t{\n\t\tVNABlock\tblock;\n\tbuffer_pos += vnp_unpack_audio_block(&buf[buffer_pos], type, &block);\n"
+       "\t\tif(func_a_stream != NULL)\n"
+       "\t\t\tfunc_a_stream(v_fs_get_user_data(165), node_id, stream_id, time_s, time_f, (VNABlockType) type, frequency, &block);\n"
+       "\t\treturn buffer_pos;\n"
+       "\t}\n");
+
+       v_cg_end_cmd();
+}
+
+#endif
diff --git a/extern/verse/dist/v_cmd_def_b.c b/extern/verse/dist/v_cmd_def_b.c
new file mode 100644 (file)
index 0000000..b266b03
--- /dev/null
@@ -0,0 +1,44 @@
+
+#include <stdlib.h>
+#include <stdio.h>
+
+#include "verse_header.h"
+#include "v_cmd_gen.h"
+#include "v_cmd_buf.h"
+
+#if defined(V_GENERATE_FUNC_MODE)
+
+void v_gen_bitmap_cmd_def(void)
+{
+       v_cg_new_cmd(V_NT_BITMAP,               "b_dimensions_set", 80, VCGCT_NORMAL);
+       v_cg_add_param(VCGP_NODE_ID,    "node_id");
+       v_cg_add_param(VCGP_END_ADDRESS, NULL);
+       v_cg_add_param(VCGP_UINT16,             "width");
+       v_cg_add_param(VCGP_UINT16,             "height");
+       v_cg_add_param(VCGP_UINT16,             "depth");
+       v_cg_end_cmd();
+
+       v_cg_new_cmd(V_NT_BITMAP,               "b_layer_create", 81, VCGCT_NORMAL);
+       v_cg_add_param(VCGP_NODE_ID,    "node_id");
+       v_cg_add_param(VCGP_LAYER_ID,   "layer_id");
+       v_cg_add_param(VCGP_END_ADDRESS, NULL);
+       v_cg_add_param(VCGP_NAME,               "name");
+       v_cg_add_param(VCGP_ENUM_NAME,  "VNBLayerType");
+       v_cg_add_param(VCGP_ENUM,               "type");
+       v_cg_alias(FALSE, "b_layer_destroy", "if(name[0] == 0)", 2, NULL);
+       v_cg_end_cmd();
+
+       v_cg_new_cmd(V_NT_BITMAP,               "b_layer_subscribe", 82, VCGCT_NORMAL);
+       v_cg_add_param(VCGP_NODE_ID,    "node_id");
+       v_cg_add_param(VCGP_LAYER_ID,   "layer_id");
+       v_cg_add_param(VCGP_END_ADDRESS, NULL);
+       v_cg_add_param(VCGP_UINT8,              "level");
+       v_cg_alias(FALSE, "b_layer_unsubscribe", "if(level == 255)", 2, NULL);
+       v_cg_end_cmd();
+
+       v_cg_new_manual_cmd(83, "b_tile_set", "void verse_send_b_tile_set(VNodeID node_id, VLayerID layer_id, " 
+                               "uint16 tile_x, uint16 tile_y, uint16 z, VNBLayerType type, const VNBTile *tile)",
+                           NULL, NULL);
+}
+
+#endif
diff --git a/extern/verse/dist/v_cmd_def_c.c b/extern/verse/dist/v_cmd_def_c.c
new file mode 100644 (file)
index 0000000..317b45e
--- /dev/null
@@ -0,0 +1,35 @@
+
+#include <stdlib.h>
+#include <stdio.h>
+#include "verse_header.h"
+#include "v_cmd_gen.h"
+#include "v_cmd_buf.h"
+
+#if defined(V_GENERATE_FUNC_MODE)
+
+void v_gen_curve_cmd_def(void)
+{
+       v_cg_new_cmd(V_NT_CURVE,                "c_curve_create", 128, VCGCT_NORMAL);
+       v_cg_add_param(VCGP_NODE_ID,    "node_id");
+       v_cg_add_param(VCGP_LAYER_ID,   "curve_id");
+       v_cg_add_param(VCGP_END_ADDRESS, NULL);
+       v_cg_add_param(VCGP_NAME,               "name");
+       v_cg_add_param(VCGP_UINT8,              "dimensions");
+       v_cg_alias(FALSE, "c_curve_destroy", "if(name[0] == 0)", 2, NULL);
+       v_cg_end_cmd();
+
+       v_cg_new_cmd(V_NT_CURVE,                "c_curve_subscribe", 129, VCGCT_NORMAL); 
+       v_cg_add_param(VCGP_NODE_ID,    "node_id");
+       v_cg_add_param(VCGP_LAYER_ID,   "curve_id");
+       v_cg_add_param(VCGP_END_ADDRESS, NULL);
+       v_cg_alias(TRUE, "c_curve_unsubscribe", "if(!alias_bool)", 2, NULL);
+       v_cg_end_cmd();
+
+       v_cg_new_manual_cmd(130, "c_key_set", "void verse_send_c_key_set(VNodeID node_id, VLayerID curve_id, "
+                           "uint32 key_id, uint8 dimensions, const real64 *pre_value, const uint32 *pre_pos, "
+                           "const real64 *value, real64 pos, const real64 *post_value, const uint32 *post_pos)",
+                           "c_key_destroy", "void verse_send_c_key_destroy(VNodeID node_id, VLayerID curve_id, "
+                           "uint32 key_id)");
+}
+
+#endif
diff --git a/extern/verse/dist/v_cmd_def_g.c b/extern/verse/dist/v_cmd_def_g.c
new file mode 100644 (file)
index 0000000..d3149f0
--- /dev/null
@@ -0,0 +1,193 @@
+
+#include <stdlib.h>
+#include <stdio.h>
+#include "verse_header.h"
+#include "v_cmd_gen.h"
+#include "v_cmd_buf.h"
+
+#if defined(V_GENERATE_FUNC_MODE)
+
+void v_gen_geometry_cmd_def(void)
+{
+       unsigned int order[] = { 0, 2 };
+
+       v_cg_new_cmd(V_NT_GEOMETRY,             "g_layer_create", 48, VCGCT_NORMAL);
+       v_cg_add_param(VCGP_NODE_ID,    "node_id");
+       v_cg_add_param(VCGP_LAYER_ID,   "layer_id");
+       v_cg_add_param(VCGP_END_ADDRESS, NULL);
+       v_cg_add_param(VCGP_NAME,               "name");
+       v_cg_add_param(VCGP_ENUM_NAME,  "VNGLayerType");
+       v_cg_add_param(VCGP_ENUM,               "type");
+       v_cg_add_param(VCGP_UINT32,             "def_uint");
+       v_cg_add_param(VCGP_REAL64,             "def_real");
+       v_cg_alias(FALSE, "g_layer_destroy", "if(name[0] == 0)", 2, NULL);
+       v_cg_end_cmd();
+
+       v_cg_new_cmd(V_NT_GEOMETRY,             "g_layer_subscribe", 49, VCGCT_NORMAL); 
+       v_cg_add_param(VCGP_NODE_ID,    "node_id");
+       v_cg_add_param(VCGP_LAYER_ID,   "layer_id");
+       v_cg_add_param(VCGP_END_ADDRESS, NULL);
+       v_cg_add_param(VCGP_ENUM_NAME,  "VNRealFormat");
+       v_cg_add_param(VCGP_ENUM,               "type");
+       v_cg_alias(FALSE, "g_layer_unsubscribe", "if(type > VN_FORMAT_REAL64)", 2, NULL);
+       v_cg_end_cmd();
+
+       v_cg_new_cmd(V_NT_GEOMETRY,             "g_vertex_set_xyz_real32", 50, VCGCT_NORMAL); 
+       v_cg_add_param(VCGP_NODE_ID,    "node_id");
+       v_cg_add_param(VCGP_LAYER_ID,   "layer_id");
+       v_cg_add_param(VCGP_UINT32,             "vertex_id");
+       v_cg_add_param(VCGP_END_ADDRESS, NULL);
+       v_cg_add_param(VCGP_REAL32,             "x");
+       v_cg_add_param(VCGP_REAL32,             "y");
+       v_cg_add_param(VCGP_REAL32,             "z");
+       v_cg_alias(FALSE, "g_vertex_delete_real32", "if(x == V_REAL32_MAX || y == V_REAL32_MAX || z == V_REAL32_MAX)", 2, order);
+       v_cg_end_cmd();
+
+       v_cg_new_cmd(V_NT_GEOMETRY,             "g_vertex_set_xyz_real64", 51, VCGCT_NORMAL); 
+       v_cg_add_param(VCGP_NODE_ID,    "node_id");
+       v_cg_add_param(VCGP_LAYER_ID,   "layer_id");
+       v_cg_add_param(VCGP_UINT32,             "vertex_id");
+       v_cg_add_param(VCGP_END_ADDRESS, NULL);
+       v_cg_add_param(VCGP_REAL64,             "x");
+       v_cg_add_param(VCGP_REAL64,             "y");
+       v_cg_add_param(VCGP_REAL64,             "z");
+       v_cg_alias(FALSE, "g_vertex_delete_real64", "if(x == V_REAL64_MAX || y == V_REAL64_MAX || z == V_REAL64_MAX)", 2, order);
+       v_cg_end_cmd();
+       
+       v_cg_new_cmd(V_NT_GEOMETRY,             "g_vertex_set_uint32", 52, VCGCT_NORMAL); 
+       v_cg_add_param(VCGP_NODE_ID,    "node_id");
+       v_cg_add_param(VCGP_LAYER_ID,   "layer_id");
+       v_cg_add_param(VCGP_UINT32,             "vertex_id");
+       v_cg_add_param(VCGP_END_ADDRESS, NULL);
+       v_cg_add_param(VCGP_UINT32,             "value");
+       v_cg_end_cmd();
+       
+       v_cg_new_cmd(V_NT_GEOMETRY,             "g_vertex_set_real64", 53, VCGCT_NORMAL); 
+       v_cg_add_param(VCGP_NODE_ID,    "node_id");
+       v_cg_add_param(VCGP_LAYER_ID,   "layer_id");
+       v_cg_add_param(VCGP_UINT32,             "vertex_id");
+       v_cg_add_param(VCGP_END_ADDRESS, NULL);
+       v_cg_add_param(VCGP_REAL64,             "value");
+       v_cg_end_cmd();
+
+       v_cg_new_cmd(V_NT_GEOMETRY,             "g_vertex_set_real32", 54, VCGCT_NORMAL); 
+       v_cg_add_param(VCGP_NODE_ID,    "node_id");
+       v_cg_add_param(VCGP_LAYER_ID,   "layer_id");
+       v_cg_add_param(VCGP_UINT32,             "vertex_id");
+       v_cg_add_param(VCGP_END_ADDRESS, NULL);
+       v_cg_add_param(VCGP_REAL32,             "value");
+       v_cg_end_cmd();
+/*
+       v_cg_new_cmd(V_NT_GEOMETRY,             "g_vertex_delete", VCGCT_NORMAL); 
+       v_cg_add_param(VCGP_UINT32,             "vertex_id");
+       v_cg_end_cmd();
+*/
+       v_cg_new_cmd(V_NT_GEOMETRY,             "g_polygon_set_corner_uint32", 55, VCGCT_NORMAL); 
+       v_cg_add_param(VCGP_NODE_ID,    "node_id");
+       v_cg_add_param(VCGP_LAYER_ID,   "layer_id");
+       v_cg_add_param(VCGP_UINT32,             "polygon_id");
+       v_cg_add_param(VCGP_END_ADDRESS, NULL);
+       v_cg_add_param(VCGP_UINT32,             "v0");
+       v_cg_add_param(VCGP_UINT32,             "v1");
+       v_cg_add_param(VCGP_UINT32,             "v2");
+       v_cg_add_param(VCGP_UINT32,             "v3");
+       v_cg_alias(FALSE, "g_polygon_delete", "if(layer_id == (VLayerID) ~0)", 2, order);
+       v_cg_end_cmd();
+
+       v_cg_new_cmd(V_NT_GEOMETRY,             "g_polygon_set_corner_real64", 56, VCGCT_NORMAL); 
+       v_cg_add_param(VCGP_NODE_ID,    "node_id");
+       v_cg_add_param(VCGP_LAYER_ID,   "layer_id");
+       v_cg_add_param(VCGP_UINT32,             "polygon_id");
+       v_cg_add_param(VCGP_END_ADDRESS, NULL);
+       v_cg_add_param(VCGP_REAL64,             "v0");
+       v_cg_add_param(VCGP_REAL64,             "v1");
+       v_cg_add_param(VCGP_REAL64,             "v2");
+       v_cg_add_param(VCGP_REAL64,             "v3");
+       v_cg_end_cmd();
+
+       v_cg_new_cmd(V_NT_GEOMETRY,             "g_polygon_set_corner_real32", 57, VCGCT_NORMAL); 
+       v_cg_add_param(VCGP_NODE_ID,    "node_id");
+       v_cg_add_param(VCGP_LAYER_ID,   "layer_id");
+       v_cg_add_param(VCGP_UINT32,             "polygon_id");
+       v_cg_add_param(VCGP_END_ADDRESS, NULL);
+       v_cg_add_param(VCGP_REAL32,             "v0");
+       v_cg_add_param(VCGP_REAL32,             "v1");
+       v_cg_add_param(VCGP_REAL32,             "v2");
+       v_cg_add_param(VCGP_REAL32,             "v3");
+       v_cg_end_cmd();
+
+       v_cg_new_cmd(V_NT_GEOMETRY,             "g_polygon_set_face_uint8", 58, VCGCT_NORMAL); 
+       v_cg_add_param(VCGP_NODE_ID,    "node_id");
+       v_cg_add_param(VCGP_LAYER_ID,   "layer_id");
+       v_cg_add_param(VCGP_UINT32,             "polygon_id");
+       v_cg_add_param(VCGP_END_ADDRESS, NULL);
+       v_cg_add_param(VCGP_UINT8,              "value");
+       v_cg_end_cmd();
+
+       v_cg_new_cmd(V_NT_GEOMETRY,             "g_polygon_set_face_uint32", 59, VCGCT_NORMAL); 
+       v_cg_add_param(VCGP_NODE_ID,    "node_id");
+       v_cg_add_param(VCGP_LAYER_ID,   "layer_id");
+       v_cg_add_param(VCGP_UINT32,             "polygon_id");
+       v_cg_add_param(VCGP_END_ADDRESS, NULL);
+       v_cg_add_param(VCGP_UINT32,             "value");
+       v_cg_end_cmd();
+
+       v_cg_new_cmd(V_NT_GEOMETRY,             "g_polygon_set_face_real64", 60, VCGCT_NORMAL); 
+       v_cg_add_param(VCGP_NODE_ID,    "node_id");
+       v_cg_add_param(VCGP_LAYER_ID,   "layer_id");
+       v_cg_add_param(VCGP_UINT32,             "polygon_id");
+       v_cg_add_param(VCGP_END_ADDRESS, NULL);
+       v_cg_add_param(VCGP_REAL64,             "value");
+       v_cg_end_cmd();
+
+       v_cg_new_cmd(V_NT_GEOMETRY,             "g_polygon_set_face_real32", 61, VCGCT_NORMAL); 
+       v_cg_add_param(VCGP_NODE_ID,    "node_id");
+       v_cg_add_param(VCGP_LAYER_ID,   "layer_id");
+       v_cg_add_param(VCGP_UINT32,             "polygon_id");
+       v_cg_add_param(VCGP_END_ADDRESS, NULL);
+       v_cg_add_param(VCGP_REAL32,             "value");
+       v_cg_end_cmd();
+
+       v_cg_new_cmd(V_NT_GEOMETRY,             "g_crease_set_vertex", 62, VCGCT_NORMAL);
+       v_cg_add_param(VCGP_NODE_ID,    "node_id");
+       v_cg_add_param(VCGP_END_ADDRESS, NULL);
+       v_cg_add_param(VCGP_NAME,               "layer");
+       v_cg_add_param(VCGP_UINT32,             "def_crease");
+       v_cg_end_cmd();
+
+       v_cg_new_cmd(V_NT_GEOMETRY,             "g_crease_set_edge", 63, VCGCT_NORMAL);
+       v_cg_add_param(VCGP_NODE_ID,    "node_id");
+       v_cg_add_param(VCGP_END_ADDRESS, NULL);
+       v_cg_add_param(VCGP_NAME,               "layer");
+       v_cg_add_param(VCGP_UINT32,             "def_crease");
+       v_cg_end_cmd();
+
+       v_cg_new_cmd(V_NT_GEOMETRY,             "g_bone_create", 64, VCGCT_NORMAL);
+       v_cg_add_param(VCGP_NODE_ID,    "node_id");
+       v_cg_add_param(VCGP_UINT16,             "bone_id");
+       v_cg_add_param(VCGP_END_ADDRESS, NULL);
+       v_cg_add_param(VCGP_NAME,               "weight");
+       v_cg_add_param(VCGP_NAME,               "reference");
+       v_cg_add_param(VCGP_UINT16,             "parent");
+       v_cg_add_param(VCGP_REAL64,             "pos_x");
+       v_cg_add_param(VCGP_REAL64,             "pos_y");
+       v_cg_add_param(VCGP_REAL64,             "pos_z");
+       v_cg_add_param(VCGP_NAME,               "pos_label");
+       v_cg_add_param(VCGP_POINTER_TYPE,       "VNQuat64");
+       v_cg_add_param(VCGP_POINTER,            "rot");
+       v_cg_add_param(VCGP_NAME,               "rot_label");
+       v_cg_add_param(VCGP_PACK_INLINE,        "\tif(weight[0] != '\\0')\n\t\tbuffer_pos += vnp_pack_quat64(&buf[buffer_pos], rot);\n");
+       v_cg_add_param(VCGP_UNPACK_INLINE,      "\tif(weight[0] != 0)\n"
+       "\t{\n"
+       "\t\tVNQuat64\ttmp;\n"
+       "\t\tbuffer_pos += vnp_unpack_quat64(&buf[buffer_pos], &tmp);\n"
+       "\t\tif(func_g_bone_create != NULL)\n"
+       "\t\t\tfunc_g_bone_create(v_fs_get_user_data(64), node_id, bone_id, weight, reference, parent, pos_x, pos_y, pos_z, pos_label, &tmp, rot_label);\n"
+       "\t\treturn buffer_pos;\n"
+       "\t}\n");
+       v_cg_alias(FALSE, "g_bone_destroy", "if(weight[0] == 0)", 2, NULL);
+
+       v_cg_end_cmd();
+}
+
+#endif
diff --git a/extern/verse/dist/v_cmd_def_m.c b/extern/verse/dist/v_cmd_def_m.c
new file mode 100644 (file)
index 0000000..212c9e3
--- /dev/null
@@ -0,0 +1,273 @@
+
+#include <stdlib.h>
+#include <stdio.h>
+#include "verse_header.h"
+#include "v_cmd_gen.h"
+#include "v_cmd_buf.h"
+
+#if defined(V_GENERATE_FUNC_MODE)
+
+void v_gen_material_cmd_def(void)
+{      
+       v_cg_new_cmd(V_NT_MATERIAL,                     "m_fragment_create", 68, VCGCT_NORMAL);
+       v_cg_add_param(VCGP_NODE_ID,            "node_id");
+       v_cg_add_param(VCGP_FRAGMENT_ID,        "frag_id");
+       v_cg_add_param(VCGP_END_ADDRESS,        NULL);
+       v_cg_add_param(VCGP_ENUM_NAME,          "VNMFragmentType");
+       v_cg_add_param(VCGP_ENUM,                       "type");
+       v_cg_add_param(VCGP_POINTER_TYPE,       "VMatFrag");
+       v_cg_add_param(VCGP_POINTER,            "fragment");
+
+       v_cg_add_param(VCGP_PACK_INLINE,        "\tswitch(type)\n"
+       "\t{\n"
+       "\tcase VN_M_FT_COLOR :\n"
+       "\t\tbuffer_pos += vnp_raw_pack_real64(&buf[buffer_pos], fragment->color.red);\n"
+       "\t\tbuffer_pos += vnp_raw_pack_real64(&buf[buffer_pos], fragment->color.green);\n"
+       "\t\tbuffer_pos += vnp_raw_pack_real64(&buf[buffer_pos], fragment->color.blue);\n"
+       "\t\tbreak;\n"
+       "\tcase VN_M_FT_LIGHT :\n"
+       "\t\tbuffer_pos += vnp_raw_pack_uint8(&buf[buffer_pos], (uint8)fragment->light.type);\n"
+       "\t\tbuffer_pos += vnp_raw_pack_real64(&buf[buffer_pos], fragment->light.normal_falloff);\n"
+       "\t\tbuffer_pos += vnp_raw_pack_uint32(&buf[buffer_pos], fragment->light.brdf);\n"
+       "\t\tbuffer_pos += vnp_raw_pack_string(&buf[buffer_pos], fragment->light.brdf_r, 16);\n"
+       "\t\tbuffer_pos += vnp_raw_pack_string(&buf[buffer_pos], fragment->light.brdf_g, 16);\n"
+       "\t\tbuffer_pos += vnp_raw_pack_string(&buf[buffer_pos], fragment->light.brdf_b, 16);\n"
+       "\t\tbreak;\n"
+       "\tcase VN_M_FT_REFLECTION :\n"
+       "\t\tbuffer_pos += vnp_raw_pack_real64(&buf[buffer_pos], fragment->reflection.normal_falloff);\n"
+       "\t\tbreak;\n"
+       "\tcase VN_M_FT_TRANSPARENCY :\n"
+       "\t\tbuffer_pos += vnp_raw_pack_real64(&buf[buffer_pos], fragment->transparency.normal_falloff);\n"
+       "\t\tbuffer_pos += vnp_raw_pack_real64(&buf[buffer_pos], fragment->transparency.refraction_index);\n"
+       "\t\tbreak;\n"
+       "\tcase VN_M_FT_GEOMETRY :\n"
+       "\t\tbuffer_pos += vnp_raw_pack_string(&buf[buffer_pos], fragment->geometry.layer_r, 16);\n"
+       "\t\tbuffer_pos += vnp_raw_pack_string(&buf[buffer_pos], fragment->geometry.layer_g, 16);\n"
+       "\t\tbuffer_pos += vnp_raw_pack_string(&buf[buffer_pos], fragment->geometry.layer_b, 16);\n"
+       "\t\tbreak;\n"
+       "\tcase VN_M_FT_VOLUME :\n"
+       "\t\tbuffer_pos += vnp_raw_pack_real64(&buf[buffer_pos], fragment->volume.diffusion);\n"
+       "\t\tbuffer_pos += vnp_raw_pack_real64(&buf[buffer_pos], fragment->volume.col_r);\n"
+       "\t\tbuffer_pos += vnp_raw_pack_real64(&buf[buffer_pos], fragment->volume.col_g);\n"
+       "\t\tbuffer_pos += vnp_raw_pack_real64(&buf[buffer_pos], fragment->volume.col_b);\n"
+       "\t\tbreak;\n"
+       "\tcase VN_M_FT_VIEW :\n"
+       "\t\tbreak;\n"
+       "\tcase VN_M_FT_TEXTURE :\n"
+       "\t\tbuffer_pos += vnp_raw_pack_uint32(&buf[buffer_pos], fragment->texture.bitmap);\n"
+       "\t\tbuffer_pos += vnp_raw_pack_string(&buf[buffer_pos], fragment->texture.layer_r, 16);\n"
+       "\t\tbuffer_pos += vnp_raw_pack_string(&buf[buffer_pos], fragment->texture.layer_g, 16);\n"
+       "\t\tbuffer_pos += vnp_raw_pack_string(&buf[buffer_pos], fragment->texture.layer_b, 16);\n"
+       "\t\tbuffer_pos += vnp_raw_pack_uint8(&buf[buffer_pos], (uint8)fragment->texture.filtered);\n"
+       "\t\tbuffer_pos += vnp_raw_pack_uint16(&buf[buffer_pos], fragment->texture.mapping);\n"
+       "\t\tbreak;\n"
+       "\tcase VN_M_FT_NOISE :\n"
+       "\t\tbuffer_pos += vnp_raw_pack_uint8(&buf[buffer_pos], (uint8)fragment->noise.type);\n"
+       "\t\tbuffer_pos += vnp_raw_pack_uint16(&buf[buffer_pos], fragment->noise.mapping);\n"
+       "\t\tbreak;\n"
+       "\tcase VN_M_FT_BLENDER :\n"
+       "\t\tbuffer_pos += vnp_raw_pack_uint8(&buf[buffer_pos], (uint8)fragment->blender.type);\n"
+       "\t\tbuffer_pos += vnp_raw_pack_uint16(&buf[buffer_pos], fragment->blender.data_a);\n"
+       "\t\tbuffer_pos += vnp_raw_pack_uint16(&buf[buffer_pos], fragment->blender.data_b);\n"
+       "\t\tbuffer_pos += vnp_raw_pack_uint16(&buf[buffer_pos], fragment->blender.control);\n"
+       "\t\tbreak;\n"
+       "\tcase VN_M_FT_CLAMP :\n"
+       "\t\tbuffer_pos += vnp_raw_pack_uint8(&buf[buffer_pos], (uint8)fragment->clamp.min);\n"
+       "\t\tbuffer_pos += vnp_raw_pack_real64(&buf[buffer_pos], fragment->clamp.red);\n"
+       "\t\tbuffer_pos += vnp_raw_pack_real64(&buf[buffer_pos], fragment->clamp.green);\n"
+       "\t\tbuffer_pos += vnp_raw_pack_real64(&buf[buffer_pos], fragment->clamp.blue);\n"
+       "\t\t\tbuffer_pos += vnp_raw_pack_uint16(&buf[buffer_pos], fragment->clamp.data);\n"
+       "\t\tbreak;\n"
+       "\tcase VN_M_FT_MATRIX :\n"
+       "\t\t{\n"
+       "\t\t\tunsigned int i;\n"
+       "\t\t\tfor(i = 0; i < 16; i++)\n"
+       "\t\t\t\tbuffer_pos += vnp_raw_pack_real64(&buf[buffer_pos], fragment->matrix.matrix[i]);\n"
+       "\t\t\tbuffer_pos += vnp_raw_pack_uint16(&buf[buffer_pos], fragment->matrix.data);\n"
+       "\t\t}\n"
+       "\t\tbreak;\n"
+       "\tcase VN_M_FT_RAMP :\n"
+       "\t\tif(fragment->ramp.point_count == 0)\n"
+       "\t\t\treturn;\n"
+       "\t\t{\n"
+       "\t\t\tunsigned int i, pos;\n"
+       "\t\t\tdouble last;\n"
+       "\t\t\tbuffer_pos += vnp_raw_pack_uint8(&buf[buffer_pos], (uint8)fragment->ramp.type);\n"
+       "\t\t\tbuffer_pos += vnp_raw_pack_uint8(&buf[buffer_pos], (uint8)fragment->ramp.channel);\n"
+       "\t\t\tbuffer_pos += vnp_raw_pack_uint16(&buf[buffer_pos], fragment->ramp.mapping);\n"
+       "\t\t\tpos = buffer_pos;\n"
+       "\t\t\tbuffer_pos += vnp_raw_pack_uint8(&buf[buffer_pos], fragment->ramp.point_count);\n"
+       "\t\t\tlast = fragment->ramp.ramp[0].pos - 1;\n"
+       "\t\t\tfor(i = 0; i < fragment->ramp.point_count && fragment->ramp.ramp[i].pos > last && i < 48; i++)\n"
+       "\t\t\t{\n"
+       "\t\t\t\tbuffer_pos += vnp_raw_pack_real64(&buf[buffer_pos], fragment->ramp.ramp[i].pos);\n"
+       "\t\t\t\tlast = fragment->ramp.ramp[i].pos;\n"
+       "\t\t\t\tbuffer_pos += vnp_raw_pack_real64(&buf[buffer_pos], fragment->ramp.ramp[i].red);\n"
+       "\t\t\t\tbuffer_pos += vnp_raw_pack_real64(&buf[buffer_pos], fragment->ramp.ramp[i].green);\n"
+       "\t\t\t\tbuffer_pos += vnp_raw_pack_real64(&buf[buffer_pos], fragment->ramp.ramp[i].blue);\n"
+       "\t\t\t}\n\t\t\tif(i != fragment->ramp.point_count)\n"
+       "\t\t\t\tvnp_raw_pack_uint8(&buf[pos], i);\n"
+       "\t\t}\n"
+       "\t\tbreak;\n"
+       "\tcase VN_M_FT_ANIMATION :\n"
+       "\t\tbuffer_pos += vnp_raw_pack_string(&buf[buffer_pos], fragment->animation.label, 16);\n"
+       "\t\tbreak;\n"
+       "\tcase VN_M_FT_ALTERNATIVE :\n"
+       "\t\tbuffer_pos += vnp_raw_pack_uint16(&buf[buffer_pos], fragment->alternative.alt_a);\n"
+       "\t\tbuffer_pos += vnp_raw_pack_uint16(&buf[buffer_pos], fragment->alternative.alt_b);\n"
+       "\t\tbreak;\n"
+       "\tcase VN_M_FT_OUTPUT :\n"
+       "\t\tbuffer_pos += vnp_raw_pack_string(&buf[buffer_pos], fragment->output.label, 16);\n"
+       "\t\tbuffer_pos += vnp_raw_pack_uint16(&buf[buffer_pos], fragment->output.front);\n"
+       "\t\tbuffer_pos += vnp_raw_pack_uint16(&buf[buffer_pos], fragment->output.back);\n"
+       "\t\tbreak;\n"
+       "\t}\n");
+
+       v_cg_add_param(VCGP_UNPACK_INLINE,      "\tif(type <= VN_M_FT_OUTPUT)\n"
+       "\t{\n"
+       "\t\tVMatFrag frag;\n"
+       "\t\tuint8 temp;\n"
+       "\t\tswitch(type)\n"
+       "\t\t{\n"
+       "\t\tcase VN_M_FT_COLOR :\n"
+       "\t\t\tif(buffer_pos + 3 * 8 > buffer_length)\n"
+       "\t\t\t\treturn -1;\n"
+       "\t\t\tbuffer_pos += vnp_raw_unpack_real64(&buf[buffer_pos], &frag.color.red);\n"
+       "\t\t\tbuffer_pos += vnp_raw_unpack_real64(&buf[buffer_pos], &frag.color.green);\n"
+       "\t\t\tbuffer_pos += vnp_raw_unpack_real64(&buf[buffer_pos], &frag.color.blue);\n"
+       "\t\t\tbreak;\n"
+       "\t\tcase VN_M_FT_LIGHT :\n"
+       "\t\t\tif(buffer_pos + 13 > buffer_length)\n"
+       "\t\t\t\treturn -1;\n"
+       "\t\t\tbuffer_pos += vnp_raw_unpack_uint8(&buf[buffer_pos], &temp);\n"
+       "\t\t\tfrag.light.type = (VNMLightType)temp;\n"
+       "\t\t\tbuffer_pos += vnp_raw_unpack_real64(&buf[buffer_pos], &frag.light.normal_falloff);\n"
+       "\t\t\tbuffer_pos += vnp_raw_unpack_uint32(&buf[buffer_pos], &frag.light.brdf);\n"
+       "\t\t\tbuffer_pos += vnp_raw_unpack_string(&buf[buffer_pos], frag.light.brdf_r, 16, buffer_length - buffer_pos);\n"
+       "\t\t\tbuffer_pos += vnp_raw_unpack_string(&buf[buffer_pos], frag.light.brdf_g, 16, buffer_length - buffer_pos);\n"
+       "\t\t\tbuffer_pos += vnp_raw_unpack_string(&buf[buffer_pos], frag.light.brdf_b, 16, buffer_length - buffer_pos);\n"
+       "\t\t\tbreak;\n"
+       "\t\tcase VN_M_FT_REFLECTION :\n"
+       "\t\t\tif(buffer_pos + 8 > buffer_length)\n"
+       "\t\t\t\treturn -1;\n"
+       "\t\t\tbuffer_pos += vnp_raw_unpack_real64(&buf[buffer_pos], &frag.reflection.normal_falloff);\n"
+       "\t\t\tbreak;\n"
+       "\t\tcase VN_M_FT_TRANSPARENCY :\n"
+       "\t\t\tif(buffer_pos + 16 > buffer_length)\n"
+       "\t\t\t\treturn -1;\n"
+       "\t\t\tbuffer_pos += vnp_raw_unpack_real64(&buf[buffer_pos], &frag.transparency.normal_falloff);\n"
+       "\t\t\tbuffer_pos += vnp_raw_unpack_real64(&buf[buffer_pos], &frag.transparency.refraction_index);\n"
+       "\t\t\tbreak;\n"
+       "\t\tcase VN_M_FT_VOLUME :\n"
+       "\t\t\tif(buffer_pos + 34 > buffer_length)\n"
+       "\t\t\t\treturn -1;\n"
+       "\t\t\tbuffer_pos += vnp_raw_unpack_real64(&buf[buffer_pos], &frag.volume.diffusion);\n"
+       "\t\t\tbuffer_pos += vnp_raw_unpack_real64(&buf[buffer_pos], &frag.volume.col_r);\n"
+       "\t\t\tbuffer_pos += vnp_raw_unpack_real64(&buf[buffer_pos], &frag.volume.col_g);\n"
+       "\t\t\tbuffer_pos += vnp_raw_unpack_real64(&buf[buffer_pos], &frag.volume.col_b);\n"
+       "\t\t\tbreak;\n"
+       "\t\tcase VN_M_FT_VIEW :\n"
+       "\t\t\tbreak;\n"
+       "\t\tcase VN_M_FT_GEOMETRY :\n"
+       "\t\t\tbuffer_pos += vnp_raw_unpack_string(&buf[buffer_pos], frag.geometry.layer_r, 16, buffer_length - buffer_pos);\n"
+       "\t\t\tbuffer_pos += vnp_raw_unpack_string(&buf[buffer_pos], frag.geometry.layer_g, 16, buffer_length - buffer_pos);\n"
+       "\t\t\tbuffer_pos += vnp_raw_unpack_string(&buf[buffer_pos], frag.geometry.layer_b, 16, buffer_length - buffer_pos);\n"
+       "\t\t\tbreak;\n"
+       "\t\tcase VN_M_FT_TEXTURE :\n"
+       "\t\t\tif(buffer_pos + 10 > buffer_length)\n"
+       "\t\t\t\treturn -1;\n"
+       "\t\t\tbuffer_pos += vnp_raw_unpack_uint32(&buf[buffer_pos], &frag.texture.bitmap);\n"
+       "\t\t\tbuffer_pos += vnp_raw_unpack_string(&buf[buffer_pos], frag.texture.layer_r, 16, buffer_length - buffer_pos);\n"
+       "\t\t\tbuffer_pos += vnp_raw_unpack_string(&buf[buffer_pos], frag.texture.layer_g, 16, buffer_length - buffer_pos);\n"
+       "\t\t\tbuffer_pos += vnp_raw_unpack_string(&buf[buffer_pos], frag.texture.layer_b, 16, buffer_length - buffer_pos);\n"
+       "\t\t\tbuffer_pos += vnp_raw_unpack_uint8(&buf[buffer_pos], &temp);\n"
+       "\t\t\tfrag.texture.filtered = (VNMNoiseType)temp;\n"
+       "\t\t\tbuffer_pos += vnp_raw_unpack_uint16(&buf[buffer_pos], &frag.texture.mapping);\n"
+       "\t\t\tbreak;\n"
+       "\t\tcase VN_M_FT_NOISE :\n"
+       "\t\t\tif(buffer_pos + 3 > buffer_length)\n"
+       "\t\t\t\treturn -1;\n"
+       "\t\t\tbuffer_pos += vnp_raw_unpack_uint8(&buf[buffer_pos], &temp);\n"
+       "\t\t\tfrag.noise.type = (VNMNoiseType)temp;\n"
+       "\t\t\tbuffer_pos += vnp_raw_unpack_uint16(&buf[buffer_pos], &frag.noise.mapping);\n"
+       "\t\t\tbreak;\n"
+       "\t\tcase VN_M_FT_BLENDER :\n"
+       "\t\t\tif(buffer_pos + 7 > buffer_length)\n"
+       "\t\t\t\treturn -1;\n"
+       "\t\t\tbuffer_pos += vnp_raw_unpack_uint8(&buf[buffer_pos], &temp);\n"
+       "\t\t\tfrag.blender.type = (VNMBlendType)temp;\n"
+       "\t\t\tbuffer_pos += vnp_raw_unpack_uint16(&buf[buffer_pos], &frag.blender.data_a);\n"
+       "\t\t\tbuffer_pos += vnp_raw_unpack_uint16(&buf[buffer_pos], &frag.blender.data_b);\n"
+       "\t\t\tbuffer_pos += vnp_raw_unpack_uint16(&buf[buffer_pos], &frag.blender.control);\n"
+       "\t\t\tbreak;\n"
+       "\t\tcase VN_M_FT_CLAMP :\n"
+       "\t\t\tif(buffer_pos + 27 > buffer_length)\n"
+       "\t\t\t\treturn -1;\n"
+       "\t\t\tbuffer_pos += vnp_raw_unpack_uint8(&buf[buffer_pos], &temp);\n"
+       "\t\t\tfrag.clamp.min = (VNMBlendType)temp;\n"
+       "\t\t\tbuffer_pos += vnp_raw_unpack_real64(&buf[buffer_pos], &frag.clamp.red);\n"
+       "\t\t\tbuffer_pos += vnp_raw_unpack_real64(&buf[buffer_pos], &frag.clamp.green);\n"
+       "\t\t\tbuffer_pos += vnp_raw_unpack_real64(&buf[buffer_pos], &frag.clamp.blue);\n"
+       "\t\t\tbuffer_pos += vnp_raw_unpack_uint16(&buf[buffer_pos], &frag.clamp.data);\n"
+       "\t\t\tbreak;\n"
+       "\t\tcase VN_M_FT_MATRIX :\n"
+       "\t\t\tif(buffer_pos + 8 * 16 + 2 > buffer_length)\n"
+       "\t\t\t\treturn -1;\n"
+       "\t\t\telse\n"
+       "\t\t\t{\n"
+       "\t\t\t\tunsigned int i;\n"
+       "\t\t\t\tfor(i = 0; i < 16; i++)\n"
+       "\t\t\t\t\tbuffer_pos += vnp_raw_unpack_real64(&buf[buffer_pos], &frag.matrix.matrix[i]);\n"
+       "\t\t\t\tbuffer_pos += vnp_raw_unpack_uint16(&buf[buffer_pos], &frag.matrix.data);\n"
+       "\t\t\t}\n"
+       "\t\t\tbreak;\n"
+       "\t\tcase VN_M_FT_RAMP :\n"
+       "\t\t\tif(buffer_pos + 5 + 4 * 8 > buffer_length)\n"
+       "\t\t\t\treturn -1;\n"
+       "\t\t\telse\n"
+       "\t\t\t{\n"
+       "\t\t\t\tunsigned int i, pos;\n"
+       "\t\t\t\tbuffer_pos += vnp_raw_unpack_uint8(&buf[buffer_pos], &temp);\n"
+       "\t\t\t\tfrag.ramp.type = (VNMRampType)temp;\n"
+       "\t\t\t\tbuffer_pos += vnp_raw_unpack_uint8(&buf[buffer_pos], &temp);\n"
+       "\t\t\t\tfrag.ramp.channel = (VNMRampChannel)temp;\n"
+       "\t\t\t\tbuffer_pos += vnp_raw_unpack_uint16(&buf[buffer_pos], &frag.ramp.mapping);\n"
+       "\t\t\t\tpos = buffer_pos;\n"
+       "\t\t\t\tbuffer_pos += vnp_raw_unpack_uint8(&buf[buffer_pos], &frag.ramp.point_count);\n"
+       "\t\t\t\tfor(i = 0; i < frag.ramp.point_count && buffer_pos + 8 * 4 <= buffer_length && i < 48; i++)\n"
+       "\t\t\t\t{\n"
+       "\t\t\t\t\tbuffer_pos += vnp_raw_unpack_real64(&buf[buffer_pos], &frag.ramp.ramp[i].pos);\n"
+       "\t\t\t\t\tbuffer_pos += vnp_raw_unpack_real64(&buf[buffer_pos], &frag.ramp.ramp[i].red);\n"
+       "\t\t\t\t\tbuffer_pos += vnp_raw_unpack_real64(&buf[buffer_pos], &frag.ramp.ramp[i].green);\n"
+       "\t\t\t\t\tbuffer_pos += vnp_raw_unpack_real64(&buf[buffer_pos], &frag.ramp.ramp[i].blue);\n"
+       "\t\t\t\t}if(i != frag.ramp.point_count)\n"
+       "\t\t\t\t\tfrag.ramp.point_count = i;\n"
+       "\t\t\t}\n"
+       "\t\t\tbreak;\n"
+       "\t\tcase VN_M_FT_ANIMATION :\n"
+       "\t\t\tbuffer_pos += vnp_raw_unpack_string(&buf[buffer_pos], frag.animation.label, 16, buffer_length - buffer_pos);\n"
+       "\t\t\tbreak;\n"
+       "\t\tcase VN_M_FT_ALTERNATIVE :\n"
+       "\t\t\tif(buffer_pos + 4 > buffer_length)\n"
+       "\t\t\t\treturn -1;\n"
+       "\t\t\tbuffer_pos += vnp_raw_unpack_uint16(&buf[buffer_pos], &frag.alternative.alt_a);\n"
+       "\t\t\tbuffer_pos += vnp_raw_unpack_uint16(&buf[buffer_pos], &frag.alternative.alt_b);\n"
+       "\t\t\tbreak;\n"
+       "\t\tcase VN_M_FT_OUTPUT :\n"
+       "\t\t\tbuffer_pos += vnp_raw_unpack_string(&buf[buffer_pos], frag.output.label, 16, buffer_length - buffer_pos);\n"
+       "\t\t\tif(buffer_pos + 4 > buffer_length)\n"
+       "\t\t\t\treturn -1;\n"
+       "\t\t\tbuffer_pos += vnp_raw_unpack_uint16(&buf[buffer_pos], &frag.output.front);\n"
+       "\t\t\tbuffer_pos += vnp_raw_unpack_uint16(&buf[buffer_pos], &frag.output.back);\n"
+       "\t\t\tbreak;\n"
+       "\t\t}\n"
+       "\t\tif(func_m_fragment_create != NULL)\n"
+       "\t\t\tfunc_m_fragment_create(v_fs_get_user_data(68), node_id, frag_id, type, &frag);\n"
+       "\t\treturn buffer_pos;\n"
+       "\t}\n");
+       v_cg_alias(FALSE, "m_fragment_destroy", "if(type > VN_M_FT_OUTPUT)", 2, NULL);
+
+       v_cg_end_cmd();
+}
+
+#endif
diff --git a/extern/verse/dist/v_cmd_def_o.c b/extern/verse/dist/v_cmd_def_o.c
new file mode 100644 (file)
index 0000000..4fc5e89
--- /dev/null
@@ -0,0 +1,517 @@
+
+#include <stdlib.h>
+#include <stdio.h>
+#include "verse_header.h"
+#include "v_cmd_gen.h"
+#include "v_cmd_buf.h"
+
+#if defined(V_GENERATE_FUNC_MODE)
+
+void v_gen_object_cmd_def(void)
+{
+       v_cg_new_cmd(V_NT_OBJECT,               "o_transform_pos_real32", 32, VCGCT_NORMAL);
+       v_cg_add_param(VCGP_NODE_ID,    "node_id");
+       v_cg_add_param(VCGP_END_ADDRESS, NULL);
+       v_cg_add_param(VCGP_UINT32,             "time_s");
+       v_cg_add_param(VCGP_UINT32,             "time_f");
+       v_cg_add_param(VCGP_POINTER_TYPE,"real32");
+       v_cg_add_param(VCGP_POINTER,    "pos");
+       v_cg_add_param(VCGP_POINTER_TYPE,"real32");
+       v_cg_add_param(VCGP_POINTER,    "speed");
+       v_cg_add_param(VCGP_POINTER_TYPE,"real32");
+       v_cg_add_param(VCGP_POINTER,    "accelerate");
+       v_cg_add_param(VCGP_POINTER_TYPE,"real32");
+       v_cg_add_param(VCGP_POINTER,    "drag_normal");
+       v_cg_add_param(VCGP_PACK_INLINE, "\t{\n"
+       "\t\tunsigned char mask = 0;\n"
+       "\t\tunsigned int cmd;\n"
+       "\t\tcmd = buffer_pos++;\n"
+       "\t\tbuffer_pos += vnp_raw_pack_real32(&buf[buffer_pos], pos[0]);\n"
+       "\t\tbuffer_pos += vnp_raw_pack_real32(&buf[buffer_pos], pos[1]);\n"
+       "\t\tbuffer_pos += vnp_raw_pack_real32(&buf[buffer_pos], pos[2]);\n"
+       "\t\tif(speed != NULL && (speed[0] > 0.0000001 || speed[0] < -0.0000001 || speed[1] > 0.0000001 || speed[1] < -0.0000001 || speed[2] > 0.0000001 || speed[2] < -0.0000001))\n"
+       "\t\t{\n"
+       "\t\t\tmask |= 1;\n"
+       "\t\t\tbuffer_pos += vnp_raw_pack_real32(&buf[buffer_pos], speed[0]);\n"
+       "\t\t\tbuffer_pos += vnp_raw_pack_real32(&buf[buffer_pos], speed[1]);\n"
+       "\t\t\tbuffer_pos += vnp_raw_pack_real32(&buf[buffer_pos], speed[2]);\n"
+       "\t\t}\n"
+       "\t\tif(accelerate != NULL && (accelerate[0] > 0.0000001 || accelerate[0] < -0.0000001 || accelerate[1] > 0.0000001 || accelerate[1] < -0.0000001 || accelerate[2] > 0.0000001 || accelerate[2] < -0.0000001))\n"
+       "\t\t{\n"
+       "\t\t\tmask |= 2;\n"
+       "\t\t\tbuffer_pos += vnp_raw_pack_real32(&buf[buffer_pos], accelerate[0]);\n"
+       "\t\t\tbuffer_pos += vnp_raw_pack_real32(&buf[buffer_pos], accelerate[1]);\n"
+       "\t\t\tbuffer_pos += vnp_raw_pack_real32(&buf[buffer_pos], accelerate[2]);\n"
+       "\t\t}\n"
+       "\t\tif(drag_normal != NULL && (drag > 0.0000001 || drag < -0.0000001) && (drag_normal[0] > 0.0000001 || drag_normal[0] < -0.0000001 || drag_normal[1] > 0.0000001 || drag_normal[1] < -0.0000001 || drag_normal[2] > 0.0000001 || drag_normal[2] < -0.0000001))\n"
+       "\t\t{\n"
+       "\t\t\tmask |= 4;\n"
+       "\t\t\tbuffer_pos += vnp_raw_pack_real32(&buf[buffer_pos], drag_normal[0]);\n"
+       "\t\t\tbuffer_pos += vnp_raw_pack_real32(&buf[buffer_pos], drag_normal[1]);\n"
+       "\t\t\tbuffer_pos += vnp_raw_pack_real32(&buf[buffer_pos], drag_normal[2]);\n"
+       "\t\t}\n"
+       "\t\tif(drag > 0.0000001 || drag < -0.0000001)\n"
+       "\t\t{\n"
+       "\t\t\tmask |= 8;\n"
+       "\t\t\tbuffer_pos += vnp_raw_pack_real32(&buf[buffer_pos], drag);\n"
+       "\t\t}\n"
+       "\t\tvnp_raw_pack_uint8(&buf[cmd], mask);\n"
+       "\t}if(FALSE)\n");
+       v_cg_add_param(VCGP_UNPACK_INLINE, "\t{\n"
+       "\t\tfloat output[4][3];\n"
+       "\t\tunsigned int i, j;\n"
+       "\t\tchar mask, pow = 1;\n"
+       "\t\tbuffer_pos += vnp_raw_unpack_uint8(&buf[buffer_pos], &mask);\n"
+       "\t\tfor(j = 0; j < 3; j++)\n"
+       "\t\t\tbuffer_pos += vnp_raw_unpack_real32(&buf[buffer_pos], &output[0][j]);\n"
+       "\t\tfor(i = 1; i < 4; i++)\n"
+       "\t\t{\n"
+       "\t\t\tif((mask & pow) != 0)\n"
+       "\t\t\t\tfor(j = 0; j < 3; j++)\n"
+       "\t\t\t\t\tbuffer_pos += vnp_raw_unpack_real32(&buf[buffer_pos], &output[i][j]);\n"
+       "\t\t\telse\n"
+       "\t\t\t\tfor(j = 0; j < 3; j++)\n"
+       "\t\t\t\t\toutput[i][j] = 0;\n"
+       "\t\t\tpow *= 2;\n"
+       "\t\t}\n"
+       "\t\tif((mask & pow) != 0)\n"
+       "\t\t\tbuffer_pos += vnp_raw_unpack_real32(&buf[buffer_pos], &drag);\n"
+       "\t\telse\n"
+       "\t\t\tdrag = 0.0f;\n"
+       "\t\tif(func_o_transform_pos_real32 != NULL)\n"
+       "\t\t\tfunc_o_transform_pos_real32(v_fs_get_user_data(32), node_id, time_s, time_f, &output[0][0], &output[1][0], &output[2][0], &output[3][0], drag);\n"
+       "\t\treturn buffer_pos;\n"
+       "\t}\n");
+       v_cg_add_param(VCGP_REAL32,             "drag");        
+       v_cg_end_cmd();
+
+       v_cg_new_cmd(V_NT_OBJECT,               "o_transform_rot_real32", 33, VCGCT_NORMAL);
+       v_cg_add_param(VCGP_NODE_ID,    "node_id");
+       v_cg_add_param(VCGP_END_ADDRESS, NULL);
+       v_cg_add_param(VCGP_UINT32,             "time_s");
+       v_cg_add_param(VCGP_UINT32,             "time_f");
+       v_cg_add_param(VCGP_POINTER_TYPE,       "VNQuat32");
+       v_cg_add_param(VCGP_POINTER,            "rot");
+       v_cg_add_param(VCGP_POINTER_TYPE,       "VNQuat32");
+       v_cg_add_param(VCGP_POINTER,            "speed");
+       v_cg_add_param(VCGP_POINTER_TYPE,       "VNQuat32");
+       v_cg_add_param(VCGP_POINTER,            "accelerate");
+       v_cg_add_param(VCGP_POINTER_TYPE,       "VNQuat32");
+       v_cg_add_param(VCGP_POINTER,            "drag_normal");
+       v_cg_add_param(VCGP_PACK_INLINE, "\t{\n"
+       "\t\tuint8 mask = 0;\n"
+       "\t\tunsigned int maskpos;\n"
+       "\t\tmaskpos = buffer_pos++;\t\t/* Remember location, and reserve a byte for the mask. */\n"
+       "\t\tbuffer_pos += vnp_pack_quat32(&buf[buffer_pos], rot);\n"
+       "\t\tif(v_quat32_valid(speed))\n"
+       "\t\t{\n"
+       "\t\t\tmask |= 1;\n"
+       "\t\t\tbuffer_pos += vnp_pack_quat32(&buf[buffer_pos], speed);\n"
+       "\t\t}\n"
+       "\t\tif(v_quat32_valid(accelerate))\n"
+       "\t\t{\n"
+       "\t\t\tmask |= 2;\n"
+       "\t\t\tbuffer_pos += vnp_pack_quat32(&buf[buffer_pos], accelerate);\n"
+       "\t\t}\n"
+       "\t\tif(v_quat32_valid(drag_normal))\n"
+       "\t\t{\n"
+       "\t\t\tmask |= 4;\n"
+       "\t\t\tbuffer_pos += vnp_pack_quat32(&buf[buffer_pos], drag_normal);\n"
+       "\t\t}\n"
+       "\t\tif(drag > 0.0000001 || drag < -0.0000001)\n"
+       "\t\t{\n"
+       "\t\t\tmask |= 8;\n"
+       "\t\t\tbuffer_pos += vnp_raw_pack_real32(&buf[buffer_pos], drag);\n"
+       "\t\t}\n"
+       "\t\tvnp_raw_pack_uint8(&buf[maskpos], mask);\t/* Write the mask into start of command. */\n"
+       "\t}\n"
+       "\tif(FALSE)\n");
+       v_cg_add_param(VCGP_UNPACK_INLINE, "\t{\n"
+       "\t\tVNQuat32 trot, temp[3], *q[3];\n"
+       "\t\tunsigned int i;\n"
+       "\t\tuint8 mask, test;\n"
+       "\t\tbuffer_pos += vnp_raw_unpack_uint8(&buf[buffer_pos], &mask);\n"
+       "\t\tbuffer_pos += vnp_unpack_quat32(&buf[buffer_pos], &trot);\n"
+       "\t\tfor(i = 0, test = 1; i < sizeof temp / sizeof *temp; i++, test <<= 1)\n"
+       "\t\t{\n"
+       "\t\t\tif(mask & test)\t\t/* Field present? */\n"
+       "\t\t\t{\n"
+       "\t\t\t\tbuffer_pos += vnp_unpack_quat32(&buf[buffer_pos], &temp[i]);\n"
+       "\t\t\t\tq[i] = &temp[i];\n"
+       "\t\t\t}\n"
+       "\t\t\telse\n"
+       "\t\t\t\tq[i] = NULL;\n"
+       "\t\t}\n"
+       "\t\tif(mask & test)\n"
+       "\t\t\tbuffer_pos += vnp_raw_unpack_real32(&buf[buffer_pos], &drag);\n"
+       "\t\telse\n"
+       "\t\t\tdrag = 0.0;\n"
+       "\t\tif(func_o_transform_rot_real32 != NULL)\n"
+       "\t\t\tfunc_o_transform_rot_real32(v_fs_get_user_data(33), node_id, time_s, time_f, &trot, q[0], q[1], q[2], drag);\n"
+       "\t\treturn buffer_pos;\n"
+       "\t}\n");
+       v_cg_add_param(VCGP_REAL32,     "drag");
+       v_cg_end_cmd();
+
+       v_cg_new_cmd(V_NT_OBJECT,               "o_transform_scale_real32", 34, VCGCT_NORMAL);
+       v_cg_add_param(VCGP_NODE_ID,    "node_id");
+       v_cg_add_param(VCGP_END_ADDRESS, NULL);
+       v_cg_add_param(VCGP_REAL32,             "scale_x");     
+       v_cg_add_param(VCGP_REAL32,             "scale_y");     
+       v_cg_add_param(VCGP_REAL32,             "scale_z");     
+       v_cg_end_cmd();
+       
+       v_cg_new_cmd(V_NT_OBJECT,               "o_transform_pos_real64", 35, VCGCT_NORMAL);
+       v_cg_add_param(VCGP_NODE_ID,    "node_id");
+       v_cg_add_param(VCGP_END_ADDRESS, NULL);
+       v_cg_add_param(VCGP_UINT32,             "time_s");
+       v_cg_add_param(VCGP_UINT32,             "time_f");
+       v_cg_add_param(VCGP_POINTER_TYPE,"real64");
+       v_cg_add_param(VCGP_POINTER,    "pos");
+       v_cg_add_param(VCGP_POINTER_TYPE,"real64");
+       v_cg_add_param(VCGP_POINTER,    "speed");
+       v_cg_add_param(VCGP_POINTER_TYPE,"real64");
+       v_cg_add_param(VCGP_POINTER,    "accelerate");
+       v_cg_add_param(VCGP_POINTER_TYPE,"real64");
+       v_cg_add_param(VCGP_POINTER,    "drag_normal");
+       v_cg_add_param(VCGP_PACK_INLINE, "\t{\n"
+       "\t\tunsigned char mask = 0;\n"
+       "\t\tunsigned int cmd;\n"
+       "\t\tcmd = buffer_pos++;\n"
+       "\t\tbuffer_pos += vnp_raw_pack_real64(&buf[buffer_pos], pos[0]);\n"
+       "\t\tbuffer_pos += vnp_raw_pack_real64(&buf[buffer_pos], pos[1]);\n"
+       "\t\tbuffer_pos += vnp_raw_pack_real64(&buf[buffer_pos], pos[2]);\n"
+       "\t\tif(speed != NULL && (speed[0] > 0.0000001 || speed[0] < -0.0000001 || speed[1] > 0.0000001 || speed[1] < -0.0000001 || speed[2] > 0.0000001 || speed[2] < -0.0000001))\n"
+       "\t\t{\n"
+       "\t\t\tmask |= 1;\n"
+       "\t\t\tbuffer_pos += vnp_raw_pack_real64(&buf[buffer_pos], speed[0]);\n"
+       "\t\t\tbuffer_pos += vnp_raw_pack_real64(&buf[buffer_pos], speed[1]);\n"
+       "\t\t\tbuffer_pos += vnp_raw_pack_real64(&buf[buffer_pos], speed[2]);\n"
+       "\t\t}\n"
+       "\t\tif(accelerate != NULL && (accelerate[0] > 0.0000001 || accelerate[0] < -0.0000001 || accelerate[1] > 0.0000001 || accelerate[1] < -0.0000001 || accelerate[2] > 0.0000001 || accelerate[2] < -0.0000001))\n"
+       "\t\t{\n"
+       "\t\t\tmask |= 2;\n"
+       "\t\t\tbuffer_pos += vnp_raw_pack_real64(&buf[buffer_pos], accelerate[0]);\n"
+       "\t\t\tbuffer_pos += vnp_raw_pack_real64(&buf[buffer_pos], accelerate[1]);\n"
+       "\t\t\tbuffer_pos += vnp_raw_pack_real64(&buf[buffer_pos], accelerate[2]);\n"
+       "\t\t}\n"
+       "\t\tif(drag_normal != NULL && (drag > 0.0000001 || drag < -0.0000001) && (drag_normal[0] > 0.0000001 || drag_normal[0] < -0.0000001 || drag_normal[1] > 0.0000001 || drag_normal[1] < -0.0000001 || drag_normal[2] > 0.0000001 || drag_normal[2] < -0.0000001))\n"
+       "\t\t{\n"
+       "\t\t\tmask |= 4;\n"
+       "\t\t\tbuffer_pos += vnp_raw_pack_real64(&buf[buffer_pos], drag_normal[0]);\n"
+       "\t\t\tbuffer_pos += vnp_raw_pack_real64(&buf[buffer_pos], drag_normal[1]);\n"
+       "\t\t\tbuffer_pos += vnp_raw_pack_real64(&buf[buffer_pos], drag_normal[2]);\n"
+       "\t\t}\n"
+       "\t\tif(drag > 0.0000001 || drag < -0.0000001)\n"
+       "\t\t{\n"
+       "\t\t\tmask |= 8;\n"
+       "\t\t\tbuffer_pos += vnp_raw_pack_real64(&buf[buffer_pos], drag);\n"
+       "\t\t}\n"
+       "\t\tvnp_raw_pack_uint8(&buf[cmd], mask);\n"
+       "\t}if(FALSE)\n");
+       v_cg_add_param(VCGP_UNPACK_INLINE, "\t{\n"
+       "\t\tdouble output[4][3];\n"
+       "\t\tunsigned int i, j;\n"
+       "\t\tchar mask, pow = 1;\n"
+       "\t\tbuffer_pos += vnp_raw_unpack_uint8(&buf[buffer_pos], &mask);\n"
+       "\t\tfor(j = 0; j < 3; j++)\n"
+       "\t\t\tbuffer_pos += vnp_raw_unpack_real64(&buf[buffer_pos], &output[0][j]);\n"
+       "\t\tfor(i = 1; i < 4; i++)\n"
+       "\t\t{\n"
+       "\t\t\tif((mask & pow) != 0)\n"
+       "\t\t\t\tfor(j = 0; j < 3; j++)\n"
+       "\t\t\t\t\tbuffer_pos += vnp_raw_unpack_real64(&buf[buffer_pos], &output[i][j]);\n"
+       "\t\t\telse\n"
+       "\t\t\t\tfor(j = 0; j < 3; j++)\n"
+       "\t\t\t\t\toutput[i][j] = 0;\n"
+       "\t\t\tpow *= 2;\n"
+       "\t\t}\n"
+       "\t\tif((mask & pow) != 0)\n"
+       "\t\t\tbuffer_pos += vnp_raw_unpack_real64(&buf[buffer_pos], &drag);\n"
+       "\t\telse\n"
+       "\t\t\tdrag = 0.0;\n"
+       "\t\tif(func_o_transform_pos_real64 != NULL)\n"
+       "\t\t\tfunc_o_transform_pos_real64(v_fs_get_user_data(35), node_id, time_s, time_f, &output[0][0], &output[1][0], &output[2][0], &output[3][0], drag);\n"
+       "\t\treturn buffer_pos;\n"
+       "\t}\n");
+       v_cg_add_param(VCGP_REAL64,             "drag");        
+       v_cg_end_cmd();
+
+       v_cg_new_cmd(V_NT_OBJECT,               "o_transform_rot_real64", 36, VCGCT_NORMAL);
+       v_cg_add_param(VCGP_NODE_ID,    "node_id");
+       v_cg_add_param(VCGP_END_ADDRESS, NULL);
+       v_cg_add_param(VCGP_UINT32,             "time_s");
+       v_cg_add_param(VCGP_UINT32,             "time_f");
+       v_cg_add_param(VCGP_POINTER_TYPE,"VNQuat64");
+       v_cg_add_param(VCGP_POINTER,    "rot");
+       v_cg_add_param(VCGP_POINTER_TYPE,"VNQuat64");
+       v_cg_add_param(VCGP_POINTER,    "speed");
+       v_cg_add_param(VCGP_POINTER_TYPE,"VNQuat64");
+       v_cg_add_param(VCGP_POINTER,    "accelerate");
+       v_cg_add_param(VCGP_POINTER_TYPE,"VNQuat64");
+       v_cg_add_param(VCGP_POINTER,    "drag_normal");
+       v_cg_add_param(VCGP_PACK_INLINE, "\t{\n"
+       "\t\tuint8 mask = 0;\n"
+       "\t\tunsigned int maskpos;\n"
+       "\t\tmaskpos = buffer_pos++;\t\t/* Remember location, and reserve a byte for the mask. */\n"
+       "\t\tbuffer_pos += vnp_pack_quat64(&buf[buffer_pos], rot);\n"
+       "\t\tif(v_quat64_valid(speed))\n"
+       "\t\t{\n"
+       "\t\t\tmask |= 1;\n"
+       "\t\t\tbuffer_pos += vnp_pack_quat64(&buf[buffer_pos], speed);\n"
+       "\t\t}\n"
+       "\t\tif(v_quat64_valid(accelerate))\n"
+       "\t\t{\n"
+       "\t\t\tmask |= 2;\n"
+       "\t\t\tbuffer_pos += vnp_pack_quat64(&buf[buffer_pos], accelerate);\n"
+       "\t\t}\n"
+       "\t\tif(v_quat64_valid(drag_normal))\n"
+       "\t\t{\n"
+       "\t\t\tmask |= 4;\n"
+       "\t\t\tbuffer_pos += vnp_pack_quat64(&buf[buffer_pos], drag_normal);\n"
+       "\t\t}\n"
+       "\t\tif(drag > 0.0000001 || drag < -0.0000001)\n"
+       "\t\t{\n"
+       "\t\t\tmask |= 8;\n"
+       "\t\t\tbuffer_pos += vnp_raw_pack_real64(&buf[buffer_pos], drag);\n"
+       "\t\t}\n"
+       "\t\tvnp_raw_pack_uint8(&buf[maskpos], mask);\t/* Write the mask into start of command. */\n"
+       "\t}\n"
+       "\tif(FALSE)\n");
+       v_cg_add_param(VCGP_UNPACK_INLINE, "\t{\n"
+       "\t\tVNQuat64 trot, temp[3], *q[3];\n"
+       "\t\tunsigned int i;\n"
+       "\t\tuint8 mask, test;\n"
+       "\t\tbuffer_pos += vnp_raw_unpack_uint8(&buf[buffer_pos], &mask);\n"
+       "\t\tbuffer_pos += vnp_unpack_quat64(&buf[buffer_pos], &trot);\n"
+       "\t\tfor(i = 0, test = 1; i < sizeof temp / sizeof *temp; i++, test <<= 1)\n"
+       "\t\t{\n"
+       "\t\t\tif(mask & test)\t\t/* Field present? */\n"
+       "\t\t\t{\n"
+       "\t\t\t\tbuffer_pos += vnp_unpack_quat64(&buf[buffer_pos], &temp[i]);\n"
+       "\t\t\t\tq[i] = &temp[i];\n"
+       "\t\t\t}\n"
+       "\t\t\telse\n"
+       "\t\t\t\tq[i] = NULL;\n"
+       "\t\t}\n"
+       "\t\tif(mask & test)\n"
+       "\t\t\tbuffer_pos += vnp_raw_unpack_real64(&buf[buffer_pos], &drag);\n"
+       "\t\telse\n"
+       "\t\t\tdrag = 0.0;\n"
+       "\t\tif(func_o_transform_rot_real64 != NULL)\n"
+       "\t\t\tfunc_o_transform_rot_real64(v_fs_get_user_data(33), node_id, time_s, time_f, &trot, q[0], q[1], q[2], drag);\n"
+       "\t\treturn buffer_pos;\n"
+       "\t}\n");
+       v_cg_add_param(VCGP_REAL64,             "drag");        
+       v_cg_end_cmd();
+
+       v_cg_new_cmd(V_NT_OBJECT,               "o_transform_scale_real64", 37, VCGCT_NORMAL);
+       v_cg_add_param(VCGP_NODE_ID,    "node_id");
+       v_cg_add_param(VCGP_END_ADDRESS, NULL);
+       v_cg_add_param(VCGP_REAL64,             "scale_x");     
+       v_cg_add_param(VCGP_REAL64,             "scale_y");     
+       v_cg_add_param(VCGP_REAL64,             "scale_z");     
+       v_cg_end_cmd();
+
+       v_cg_new_cmd(V_NT_OBJECT,               "o_transform_subscribe", 38, VCGCT_NORMAL);
+       v_cg_add_param(VCGP_NODE_ID,    "node_id");
+       v_cg_add_param(VCGP_END_ADDRESS, NULL);
+       v_cg_add_param(VCGP_ENUM_NAME,  "VNRealFormat");
+       v_cg_add_param(VCGP_ENUM,               "type");
+       v_cg_alias(TRUE, "o_transform_unsubscribe", NULL, 4, NULL);
+       v_cg_end_cmd();
+
+       v_cg_new_cmd(V_NT_OBJECT,               "o_light_set", 39, VCGCT_NORMAL);
+       v_cg_add_param(VCGP_NODE_ID,    "node_id");
+       v_cg_add_param(VCGP_END_ADDRESS, NULL);
+       v_cg_add_param(VCGP_REAL64,             "light_r");     
+       v_cg_add_param(VCGP_REAL64,             "light_g");     
+       v_cg_add_param(VCGP_REAL64,             "light_b");     
+       v_cg_end_cmd();
+
+       v_cg_new_cmd(V_NT_OBJECT,               "o_link_set", 40, VCGCT_NORMAL);
+       v_cg_add_param(VCGP_NODE_ID,    "node_id");
+       v_cg_add_param(VCGP_UINT16,             "link_id");
+       v_cg_add_param(VCGP_END_ADDRESS, NULL);
+       v_cg_add_param(VCGP_NODE_ID,    "link");
+       v_cg_add_param(VCGP_NAME,               "label");
+       v_cg_add_param(VCGP_UINT32,             "target_id");
+       v_cg_alias(TRUE, "o_link_destroy", NULL, 2, NULL);
+       v_cg_end_cmd();
+
+       v_cg_new_cmd(V_NT_OBJECT,               "o_method_group_create", 41, VCGCT_NORMAL);
+       v_cg_add_param(VCGP_NODE_ID,    "node_id");
+       v_cg_add_param(VCGP_UINT16,             "group_id");
+       v_cg_add_param(VCGP_END_ADDRESS, NULL);
+       v_cg_add_param(VCGP_NAME,               "name");
+       v_cg_alias(FALSE, "o_method_group_destroy", "if(name[0] == 0)", 2, NULL);
+       v_cg_end_cmd();
+
+       v_cg_new_cmd(V_NT_OBJECT,               "o_method_group_subscribe", 42, VCGCT_NORMAL);
+       v_cg_add_param(VCGP_NODE_ID,    "node_id");
+       v_cg_add_param(VCGP_UINT16,             "group_id");
+       v_cg_add_param(VCGP_END_ADDRESS, NULL);
+       v_cg_alias(TRUE, "o_method_group_unsubscribe", NULL, 2, NULL);
+       v_cg_end_cmd();
+
+       v_cg_new_cmd(V_NT_OBJECT,               "o_method_create", 43, VCGCT_NORMAL);
+       v_cg_add_param(VCGP_NODE_ID,    "node_id");
+       v_cg_add_param(VCGP_UINT16,             "group_id");
+       v_cg_add_param(VCGP_UINT16,             "method_id");
+       v_cg_add_param(VCGP_END_ADDRESS, NULL);
+       v_cg_add_param(VCGP_LONG_NAME,  "name");
+       v_cg_add_param(VCGP_UINT8,              "param_count");
+       v_cg_add_param(VCGP_POINTER_TYPE,"VNOParamType");
+       v_cg_add_param(VCGP_POINTER,    "param_types");
+       v_cg_add_param(VCGP_POINTER_TYPE,"char *");
+       v_cg_add_param(VCGP_POINTER,    "param_names");
+       v_cg_add_param(VCGP_PACK_INLINE, "\t{\n"
+       "\t\tunsigned int i, j, sum = 1;\n"
+       "\t\tfor(i = 0; i < param_count; i++)\n"
+       "\t\t{\n"
+       "\t\t\tsum += 3;\n"
+       "\t\t\tfor(j = 0; param_names[i][j] != 0; j++);\n"
+       "\t\t}\n"
+       "\t\tif(sum + buffer_pos > 1500)\n"
+       "\t\t\treturn;\n"
+       "\t\tfor(i = 0; i < param_count; i++)\n"
+       "\t\t{\n"
+       "\t\t\tbuffer_pos += vnp_raw_pack_uint8(&buf[buffer_pos], param_types[i]);\n"
+       "\t\t\tbuffer_pos += vnp_raw_pack_string(&buf[buffer_pos], param_names[i], 1500 - buffer_pos);\n"
+       "\t\t}\n"
+       "\t}\n");
+       v_cg_add_param(VCGP_UNPACK_INLINE,      "\tif(param_count != 255)\n"
+       "\t{\n"
+       "\t\tunsigned int i, size, text = 0;\n"
+       "\t\tVNOParamType types[256];\n"
+       "\t\tuint8 t;\n"
+       "\t\tchar name_buf[1500], *names[256];\n"
+       "\t\tfor(i = 0; i < param_count; i++)\n"
+       "\t\t{\n"
+       "\t\t\tbuffer_pos += vnp_raw_unpack_uint8(&buf[buffer_pos], &t);\n"
+       "\t\t\ttypes[i] = t;\n"
+       "\t\t\tnames[i] = &name_buf[text];\n"
+       "\t\t\tsize = vnp_raw_unpack_string(&buf[buffer_pos], names[i], 1500 - buffer_pos, buffer_length - buffer_pos);\n"
+       "\t\t\tbuffer_pos += size;\n"
+       "\t\t\ttext += size;\n"
+       "\t\t}\n"
+       "\t\tif(func_o_method_create != NULL)\n"
+       "\t\t\tfunc_o_method_create(v_fs_get_user_data(43), node_id, group_id, method_id, name, param_count, types, (const char **) names);\n"
+       "\t\treturn buffer_pos;\n"
+       "\t}\n");
+       v_cg_alias(FALSE, "o_method_destroy", "if(name[0] == 0)", 3, NULL);
+       v_cg_end_cmd();
+
+       v_cg_new_cmd(V_NT_OBJECT,               "o_method_call", 44, VCGCT_UNIQUE);
+       v_cg_add_param(VCGP_NODE_ID,    "node_id");
+       v_cg_add_param(VCGP_UINT16,             "group_id");
+       v_cg_add_param(VCGP_UINT16,             "method_id");
+       v_cg_add_param(VCGP_NODE_ID,    "sender");
+       v_cg_add_param(VCGP_POINTER_TYPE, "VNOPackedParams");
+       v_cg_add_param(VCGP_POINTER,    "params");
+       v_cg_add_param(VCGP_PACK_INLINE, "\t{\n"
+       "\t\tunsigned int i;\n"
+       "\t\tuint16 size;\n"
+       "\t\tvnp_raw_unpack_uint16(params, &size);\n"
+       "\t\tfor(i = 0; i < size; i++)\n"
+       "\t\t\tbuffer_pos += vnp_raw_pack_uint8(&buf[buffer_pos], ((uint8 *)params)[i]);\n"
+       "\t\tfree((void *) params);\t/* Drop the const. */\n"
+       "\t}\n");
+       v_cg_add_param(VCGP_UNPACK_INLINE, "\t{\n"
+       "\t\tunsigned int i;\n"
+       "\t\tuint8 par[1500];\n"
+       "\t\tuint16 size;\n"
+       "\t\tvnp_raw_unpack_uint16(&buf[buffer_pos], &size);\n"
+       "\t\tfor(i = 0; i < size; i++)\n"
+       "\t\t\tbuffer_pos += vnp_raw_unpack_uint8(&buf[buffer_pos], &par[i]);\n"
+       "\t\tif(func_o_method_call != NULL)\n"
+       "\t\t\tfunc_o_method_call(v_fs_get_user_data(44), node_id, group_id, method_id, sender, par);\n"
+       "\t\treturn buffer_pos;\n"
+       "\t}\n");
+
+       v_cg_end_cmd();
+
+       v_cg_new_cmd(V_NT_OBJECT,               "o_anim_run", 45, VCGCT_UNIQUE);
+       v_cg_add_param(VCGP_NODE_ID,    "node_id");
+       v_cg_add_param(VCGP_UINT16,             "link_id");
+       v_cg_add_param(VCGP_END_ADDRESS, NULL);
+       v_cg_add_param(VCGP_UINT32,             "time_s");
+       v_cg_add_param(VCGP_UINT32,             "time_f");
+       v_cg_add_param(VCGP_UINT8,              "dimensions");
+       v_cg_add_param(VCGP_POINTER_TYPE, "real64");
+       v_cg_add_param(VCGP_POINTER,    "pos");
+       v_cg_add_param(VCGP_POINTER_TYPE, "real64");
+       v_cg_add_param(VCGP_POINTER,    "speed");
+       v_cg_add_param(VCGP_POINTER_TYPE, "real64");
+       v_cg_add_param(VCGP_POINTER,    "accel");
+       v_cg_add_param(VCGP_POINTER_TYPE, "real64");
+       v_cg_add_param(VCGP_POINTER,    "scale");
+       v_cg_add_param(VCGP_POINTER_TYPE, "real64");
+       v_cg_add_param(VCGP_POINTER,    "scale_speed");
+       v_cg_add_param(VCGP_PACK_INLINE, "\t{\n"
+       "\t\tunsigned char mask = 0;\n"
+       "\t\tunsigned int cmd, i;\n"
+       "\t\tcmd = buffer_pos++;\n"
+       "\t\tif(dimensions > 4)\n"
+       "\t\t\tdimensions = 4;\n"       
+       "\t\tfor(i = 0; i < dimensions; i++)\n"
+       "\t\t\tbuffer_pos += vnp_raw_pack_real64(&buf[buffer_pos], pos[i]);\n"
+       "\t\tif(speed != NULL)\n"
+       "\t\t{\n"
+       "\t\t\tmask |= 1;\n"
+       "\t\t\tfor(i = 0; i < dimensions; i++)\n"
+       "\t\t\t\tbuffer_pos += vnp_raw_pack_real64(&buf[buffer_pos], speed[i]);\n"
+       "\t\t}\n"
+       "\t\tif(accel != NULL)\n"
+       "\t\t{\n"
+       "\t\t\tmask |= 2;\n"
+       "\t\t\tfor(i = 0; i < dimensions; i++)\n"
+       "\t\t\t\tbuffer_pos += vnp_raw_pack_real64(&buf[buffer_pos], accel[i]);\n"
+       "\t\t}\n"
+       "\t\tif(scale != NULL)\n"
+       "\t\t{\n"
+       "\t\t\tmask |= 3;\n"
+       "\t\t\tfor(i = 0; i < dimensions; i++)\n"
+       "\t\t\t\tbuffer_pos += vnp_raw_pack_real64(&buf[buffer_pos], scale[i]);\n"
+       "\t\t}\n"
+       "\t\tif(scale_speed != NULL)\n"
+       "\t\t{\n"
+       "\t\t\tmask |= 4;\n"
+       "\t\t\tfor(i = 0; i < dimensions; i++)\n"
+       "\t\t\t\tbuffer_pos += vnp_raw_pack_real64(&buf[buffer_pos], scale_speed[i]);\n"
+       "\t\t}\n"
+       "\t\tvnp_raw_pack_uint8(&buf[cmd], mask);\n"
+       "\t}\n");
+       v_cg_add_param(VCGP_UNPACK_INLINE, "\t{\n"
+       "\t\tdouble output[5][4];\n"
+       "\t\tunsigned int i, j;\n"
+       "\t\tchar mask, pow = 1;\n"
+       "\t\tbuffer_pos += vnp_raw_unpack_uint8(&buf[buffer_pos], &mask);\n"
+       "\t\tif(dimensions > 4)\n"
+       "\t\t\tdimensions = 4;\n"
+       "\t\tfor(j = 0; j < dimensions; j++)\n"
+       "\t\t\tbuffer_pos += vnp_raw_unpack_real64(&buf[buffer_pos], &output[0][j]);\n"
+       "\t\tfor(i = 1; i < 5; i++)\n"
+       "\t\t{\n"
+       "\t\t\tif((mask & pow) != 0)\n"
+       "\t\t\t\tfor(j = 0; j < dimensions; j++)\n"
+       "\t\t\t\t\tbuffer_pos += vnp_raw_unpack_real64(&buf[buffer_pos], &output[i][j]);\n"
+       "\t\t\telse\n"
+       "\t\t\t\tfor(j = 0; j < dimensions; j++)\n"
+       "\t\t\t\t\toutput[i][j] = 0;\n"
+       "\t\t\tpow *= 2;\n"
+       "\t\t}\n"
+       "\t\tif(func_o_anim_run != NULL)\n"
+       "\t\t\tfunc_o_anim_run(v_fs_get_user_data(45), node_id, link_id, time_s, time_f, dimensions, &output[0][0], &output[1][0], &output[2][0], &output[3][0], &output[4][0]);\n"
+       "\t\treturn buffer_pos;\n"
+       "\t}\n");
+       v_cg_end_cmd();
+
+       v_cg_new_cmd(V_NT_OBJECT,               "o_hide", 46, VCGCT_NORMAL);
+       v_cg_add_param(VCGP_NODE_ID,    "node_id");
+       v_cg_add_param(VCGP_END_ADDRESS, NULL);
+       v_cg_add_param(VCGP_UINT8,              "hidden");
+       v_cg_end_cmd();
+}
+
+#endif
diff --git a/extern/verse/dist/v_cmd_def_s.c b/extern/verse/dist/v_cmd_def_s.c
new file mode 100644 (file)
index 0000000..a20e1da
--- /dev/null
@@ -0,0 +1,211 @@
+
+#include <stdlib.h>
+#include <stdio.h>
+#include "verse_header.h"
+#include "v_cmd_gen.h"
+#include "v_cmd_buf.h"
+
+#if defined(V_GENERATE_FUNC_MODE)
+
+void v_gen_system_cmd_def(void)
+{
+       v_cg_new_manual_cmd(0, "connect", "VSession verse_send_connect(const char *name, const char *pass, const char *address, const uint8 *expected_host_id)", NULL, NULL);
+
+       v_cg_new_manual_cmd(1, "connect_accept", "VSession verse_send_connect_accept(VNodeID avatar, const char *address, uint8 *host_id)", NULL, NULL);
+
+       v_cg_new_manual_cmd(2, "connect_terminate", "void verse_send_connect_terminate(const char *address, const char *bye)", NULL, NULL);
+       
+       v_cg_new_manual_cmd(5, "ping", "void verse_send_ping(const char *address, const char *message)", NULL, NULL);
+
+       v_cg_new_cmd(V_NT_SYSTEM,               "error_message", 6, VCGCT_UNIQUE);
+       v_cg_add_param(VCGP_LONG_NAME, "message");
+
+       v_cg_new_cmd(V_NT_SYSTEM,               "packet_ack", 7, VCGCT_INVISIBLE_SYSTEM);
+       v_cg_add_param(VCGP_UINT32,             "packet_id");
+       v_cg_add_param(VCGP_PACK_INLINE, "\tv_cmd_buf_set_unique_address_size(head, buffer_pos);\n"
+       "\tv_cmd_buf_set_size(head, buffer_pos);\n"
+       "\tv_noq_send_ack_nak_buf(v_con_get_network_queue(), head);\n"
+       "\treturn;\n");
+       v_cg_end_cmd();
+
+       v_cg_new_cmd(V_NT_SYSTEM,               "packet_nak", 8, VCGCT_INVISIBLE_SYSTEM);
+       v_cg_add_param(VCGP_UINT32,             "packet_id");
+       v_cg_add_param(VCGP_PACK_INLINE, "\tv_cmd_buf_set_unique_address_size(head, buffer_pos);\n"
+       "\tv_cmd_buf_set_size(head, buffer_pos);\n"
+       "\tv_noq_send_ack_nak_buf(v_con_get_network_queue(), head);\n"
+       "\treturn;\n");
+       v_cg_end_cmd();
+
+
+       v_cg_new_cmd(V_NT_SYSTEM,               "node_index_subscribe", 9, VCGCT_NORMAL);
+       v_cg_add_param(VCGP_UINT32,             "mask");
+       v_cg_add_param(VCGP_END_ADDRESS, NULL);
+       v_cg_end_cmd();
+
+       v_cg_new_cmd(V_NT_SYSTEM,               "node_create", 10, VCGCT_NORMAL);
+       v_cg_add_param(VCGP_NODE_ID,    "node_id");
+       v_cg_add_param(VCGP_END_ADDRESS, NULL);
+       v_cg_add_param(VCGP_ENUM_NAME,  "VNodeType");
+       v_cg_add_param(VCGP_ENUM,               "type");
+       v_cg_add_param(VCGP_ENUM_NAME,  "VNodeOwner");
+       v_cg_add_param(VCGP_ENUM,               "owner");
+       v_cg_alias(FALSE, "node_destroy", "if(owner == (uint8)-1 || type >= V_NT_NUM_TYPES)", 1, NULL);
+       v_cg_end_cmd();
+
+       v_cg_new_cmd(V_NT_SYSTEM,               "node_subscribe", 11, VCGCT_NORMAL);
+       v_cg_add_param(VCGP_NODE_ID,    "node_id");
+       v_cg_add_param(VCGP_END_ADDRESS, NULL);
+       v_cg_alias(TRUE, "node_unsubscribe", NULL, 1, NULL);
+       v_cg_end_cmd();
+
+       v_cg_new_cmd(V_NT_SYSTEM,               "tag_group_create", 16, VCGCT_NORMAL);
+       v_cg_add_param(VCGP_NODE_ID,    "node_id");
+       v_cg_add_param(VCGP_UINT16,             "group_id");
+       v_cg_add_param(VCGP_END_ADDRESS, NULL);
+       v_cg_add_param(VCGP_NAME,               "name");
+       v_cg_alias(FALSE, "tag_group_destroy", "if(name[0] == 0)", 2, NULL);
+       v_cg_end_cmd();
+
+       v_cg_new_cmd(V_NT_SYSTEM,               "tag_group_subscribe", 17, VCGCT_NORMAL);
+       v_cg_add_param(VCGP_NODE_ID,    "node_id");
+       v_cg_add_param(VCGP_UINT16,             "group_id");
+       v_cg_add_param(VCGP_END_ADDRESS, NULL);
+       v_cg_alias(TRUE, "tag_group_unsubscribe", NULL, 2, NULL);
+       v_cg_end_cmd();
+
+       v_cg_new_cmd(V_NT_SYSTEM,               "tag_create", 18, VCGCT_NORMAL);
+       v_cg_add_param(VCGP_NODE_ID,    "node_id");
+       v_cg_add_param(VCGP_UINT16,             "group_id");
+       v_cg_add_param(VCGP_UINT16,             "tag_id");
+       v_cg_add_param(VCGP_END_ADDRESS, NULL);
+       v_cg_add_param(VCGP_NAME,               "name");
+       v_cg_add_param(VCGP_ENUM_NAME,  "VNTagType");
+       v_cg_add_param(VCGP_ENUM,               "type");
+       v_cg_add_param(VCGP_POINTER_TYPE, "VNTag");
+       v_cg_add_param(VCGP_POINTER,    "tag"); 
+       v_cg_add_param(VCGP_PACK_INLINE, "\tif(type > VN_TAG_BLOB)\n"
+       "\t{\n"
+       "\t\tv_cmd_buf_free(head);\n"
+       "\t\treturn;\n"
+       "\t}\n"
+       "\tswitch(type)\n"
+       "\t{\n"
+       "\t\tcase VN_TAG_BOOLEAN :\n"
+       "\t\t\tbuffer_pos += vnp_raw_pack_uint8(&buf[buffer_pos], ((VNTag *)tag)->vboolean);\n"
+       "\t\tbreak;\n"
+       "\t\tcase VN_TAG_UINT32 :\n"
+       "\t\t\tbuffer_pos += vnp_raw_pack_uint32(&buf[buffer_pos], ((VNTag *)tag)->vuint32);\n"
+       "\t\tbreak;\n"
+       "\t\tcase VN_TAG_REAL64 :\n"
+       "\t\t\tbuffer_pos += vnp_raw_pack_real64(&buf[buffer_pos], ((VNTag *)tag)->vreal64);\n"
+       "\t\tbreak;\n"
+       "\t\tcase VN_TAG_STRING :\n"
+       "\t\t{\n"
+       "\t\t\tunsigned int i;\n"
+       "\t\t\tfor(i = 0; ((VNTag *)tag)->vstring[i] != 0 && i < VN_TAG_MAX_BLOB_SIZE; i++)\n"
+       "\t\t\t\tbuffer_pos += vnp_raw_pack_uint8(&buf[buffer_pos], ((VNTag *)tag)->vstring[i]);\n"
+       "\t\t\tbuffer_pos += vnp_raw_pack_uint8(&buf[buffer_pos], 0);\n"
+       "\t\t}\n"
+       "\t\tbreak;\n"
+       "\t\tcase VN_TAG_REAL64_VEC3 :\n"
+       "\t\t{\n"
+       "\t\t\tbuffer_pos += vnp_raw_pack_real64(&buf[buffer_pos], ((VNTag *)tag)->vreal64_vec3[0]);\n"
+       "\t\t\tbuffer_pos += vnp_raw_pack_real64(&buf[buffer_pos], ((VNTag *)tag)->vreal64_vec3[1]);\n"
+       "\t\t\tbuffer_pos += vnp_raw_pack_real64(&buf[buffer_pos], ((VNTag *)tag)->vreal64_vec3[2]);\n"
+       "\t\t}\n"
+       "\t\tbreak;\n"
+       "\t\tcase VN_TAG_LINK :\n"
+       "\t\t{\n"
+       "\t\t\tbuffer_pos += vnp_raw_pack_uint32(&buf[buffer_pos], ((VNTag *)tag)->vlink);\n"
+       "\t\t}\n"
+       "\t\tbreak;\n"
+       "\t\tcase VN_TAG_ANIMATION :\n"
+       "\t\t{\n"
+       "\t\t\tbuffer_pos += vnp_raw_pack_uint32(&buf[buffer_pos], ((VNTag *)tag)->vanimation.curve);\n"
+       "\t\t\tbuffer_pos += vnp_raw_pack_uint32(&buf[buffer_pos], ((VNTag *)tag)->vanimation.start);\n"
+       "\t\t\tbuffer_pos += vnp_raw_pack_uint32(&buf[buffer_pos], ((VNTag *)tag)->vanimation.end);\n"
+       "\t\t}\n"
+       "\t\tbreak;\n"
+       "\t\tcase VN_TAG_BLOB :\n"
+       "\t\t{\n"
+       "\t\t\tunsigned int i;\n"
+       "\t\t\tif(((VNTag *)tag)->vblob.size > VN_TAG_MAX_BLOB_SIZE)\n"
+       "\t\t\t\t((VNTag *)tag)->vblob.size = VN_TAG_MAX_BLOB_SIZE;\n"
+       "\t\t\tbuffer_pos += vnp_raw_pack_uint16(&buf[buffer_pos], ((VNTag *)tag)->vblob.size);\n"
+       "\t\t\tfor(i = 0; i < ((VNTag *)tag)->vblob.size; i++)\n"
+       "\t\t\t\tbuffer_pos += vnp_raw_pack_uint8(&buf[buffer_pos], ((uint8 *)((VNTag *)tag)->vblob.blob)[i]);\n"
+       "\t\t}\n"
+       "\t\tbreak;\n"
+       "\t\tdefault :\n"
+       "\t\t\t;\n"
+       "\t}\n");
+       v_cg_add_param(VCGP_UNPACK_INLINE, "\tif(type < VN_TAG_TYPE_COUNT)\n"
+       "\t{\n"
+       "\t\tVNTag tag;\n"
+       "\t\tunsigned int i;\n"
+       "\t\tchar string[VN_TAG_MAX_BLOB_SIZE];\n"
+       "\t\tswitch(type)\n"
+       "\t\t{\n"
+       "\t\t\tcase VN_TAG_BOOLEAN :\n"
+       "\t\t\t\tbuffer_pos += vnp_raw_unpack_uint8(&buf[buffer_pos], &tag.vboolean);\n"
+       "\t\t\tbreak;\n"
+       "\t\t\tcase VN_TAG_UINT32 :\n"
+       "\t\t\t\tbuffer_pos += vnp_raw_unpack_uint32(&buf[buffer_pos], &tag.vuint32);\n"
+       "\t\t\tbreak;\n"
+       "\t\t\tcase VN_TAG_REAL64 :\n"
+       "\t\t\t\tbuffer_pos += vnp_raw_unpack_real64(&buf[buffer_pos], &tag.vreal64);\n"
+       "\t\t\tbreak;\n"
+       "\t\t\tcase VN_TAG_STRING :\n"
+       "\t\t\t{\n"
+       "\t\t\t\ttag.vstring = string;\n"
+       "\t\t\t\tbuffer_pos += vnp_raw_unpack_string(&buf[buffer_pos], string, VN_TAG_MAX_BLOB_SIZE, buffer_length - buffer_pos);\n"
+       "\t\t\t}\n"
+       "\t\t\tbreak;\n"
+       "\t\t\tcase VN_TAG_REAL64_VEC3 :\n"
+       "\t\t\t{\n"
+       "\t\t\t\tbuffer_pos += vnp_raw_unpack_real64(&buf[buffer_pos], &tag.vreal64_vec3[0]);\n"
+       "\t\t\t\tbuffer_pos += vnp_raw_unpack_real64(&buf[buffer_pos], &tag.vreal64_vec3[1]);\n"
+       "\t\t\t\tbuffer_pos += vnp_raw_unpack_real64(&buf[buffer_pos], &tag.vreal64_vec3[2]);\n"
+       "\t\t\t}\n"
+       "\t\t\tbreak;\n"
+       "\t\t\tcase VN_TAG_LINK :\n"
+       "\t\t\t{\n"
+       "\t\t\t\tbuffer_pos += vnp_raw_unpack_uint32(&buf[buffer_pos], &tag.vlink);\n"
+       "\t\t\t}\n"
+       "\t\t\tbreak;\n"
+       "\t\t\tcase VN_TAG_ANIMATION :\n"
+       "\t\t\t{\n"
+       "\t\t\t\tbuffer_pos += vnp_raw_unpack_uint32(&buf[buffer_pos], &tag.vanimation.curve);\n"
+       "\t\t\t\tbuffer_pos += vnp_raw_unpack_uint32(&buf[buffer_pos], &tag.vanimation.start);\n"
+       "\t\t\t\tbuffer_pos += vnp_raw_unpack_uint32(&buf[buffer_pos], &tag.vanimation.end);\n"
+       "\t\t\t}\n"
+       "\t\t\tbreak;\n"
+       "\t\t\tcase VN_TAG_BLOB :\n"
+       "\t\t\t{\n"
+       "\t\t\t\tbuffer_pos += vnp_raw_unpack_uint16(&buf[buffer_pos], &tag.vblob.size);\n"
+       "\t\t\t\tif(tag.vblob.size > VN_TAG_MAX_BLOB_SIZE)\n"
+       "\t\t\t\t\ttag.vblob.size = VN_TAG_MAX_BLOB_SIZE;\n"
+       "\t\t\t\ttag.vblob.blob = string;\n"
+       "\t\t\t\tfor(i = 0; i < tag.vblob.size; i++)\n"
+       "\t\t\t\t\tbuffer_pos += vnp_raw_unpack_uint8(&buf[buffer_pos], &string[i]);\n"
+       "\t\t\t}\n"
+       "\t\t\tbreak;\n"
+       "\t\tdefault :\n"
+       "\t\t\t;\n"
+       "\t\t}\n"
+       "\t\tif(func_tag_create != NULL)\n"
+       "\t\tfunc_tag_create(v_fs_get_user_data(18), node_id, group_id, tag_id, name, type, &tag);\n"
+       "\t\treturn buffer_pos;\n"
+       "\t}\n");
+       v_cg_alias(FALSE, "tag_destroy", "if(type >= VN_TAG_TYPE_COUNT)", 3, NULL);
+       v_cg_end_cmd();
+
+       v_cg_new_cmd(V_NT_SYSTEM,               "node_name_set", 19, VCGCT_NORMAL); 
+       v_cg_add_param(VCGP_NODE_ID,    "node_id");
+       v_cg_add_param(VCGP_END_ADDRESS, NULL);
+       v_cg_add_param(VCGP_LONG_NAME,  "name");
+
+       v_cg_end_cmd();
+}
+
+#endif
diff --git a/extern/verse/dist/v_cmd_def_t.c b/extern/verse/dist/v_cmd_def_t.c
new file mode 100644 (file)
index 0000000..1e739aa
--- /dev/null
@@ -0,0 +1,36 @@
+
+#include <stdlib.h>
+#include <stdio.h>
+#include "verse_header.h"
+#include "v_cmd_gen.h"
+#include "v_cmd_buf.h"
+
+#if defined(V_GENERATE_FUNC_MODE)
+
+void v_gen_text_cmd_def(void)
+{
+       v_cg_new_cmd(V_NT_TEXT,                 "t_set_language", 96, VCGCT_NORMAL);
+       v_cg_add_param(VCGP_NODE_ID,    "node_id");
+       v_cg_add_param(VCGP_END_ADDRESS, NULL);
+       v_cg_add_param(VCGP_LONG_NAME,  "language");
+       v_cg_end_cmd();
+       
+       v_cg_new_cmd(V_NT_TEXT,                 "t_buffer_create", 97, VCGCT_NORMAL);
+       v_cg_add_param(VCGP_NODE_ID,    "node_id");
+       v_cg_add_param(VCGP_BUFFER_ID,  "buffer_id");
+       v_cg_add_param(VCGP_END_ADDRESS, NULL);
+       v_cg_add_param(VCGP_NAME,               "name");
+       v_cg_alias(FALSE, "t_buffer_destroy", "if(name[0] == 0)", 2, NULL);
+       v_cg_end_cmd();
+
+       v_cg_new_cmd(V_NT_TEXT,                 "t_buffer_subscribe", 98, VCGCT_NORMAL); 
+       v_cg_add_param(VCGP_NODE_ID,    "node_id");
+       v_cg_add_param(VCGP_BUFFER_ID,  "buffer_id");
+       v_cg_add_param(VCGP_END_ADDRESS, NULL);
+       v_cg_alias(TRUE, "t_buffer_unsubscribe", NULL, 2, NULL);
+       v_cg_end_cmd();
+
+       v_cg_new_manual_cmd(99, "t_text_set", "void verse_send_t_text_set(VNodeID node_id, VBufferID buffer_id, uint32 pos, uint32 length, const char *text)", NULL, NULL);
+}
+
+#endif
diff --git a/extern/verse/dist/v_cmd_gen.c b/extern/verse/dist/v_cmd_gen.c
new file mode 100644 (file)
index 0000000..ebe2735
--- /dev/null
@@ -0,0 +1,862 @@
+/*
+**
+*/
+
+#include <stdlib.h>
+#include <stdio.h>
+
+#include "verse_header.h"
+#include "v_cmd_buf.h"
+
+#include "v_cmd_gen.h"
+
+#if defined V_GENERATE_FUNC_MODE
+
+#define MAX_PARAMS_PER_CMD     32
+
+static struct {
+       FILE            *nodes[V_NT_NUM_TYPES_NETPACK];
+       FILE            *init;
+       FILE            *unpack;
+       FILE            *verse_h;
+       FILE            *internal_verse_h;
+       const char      *func_name;
+       VNodeType       type;
+       VCGCommandType command;
+       unsigned int    param_count;
+       VCGParam        param_type[MAX_PARAMS_PER_CMD];
+       const char      *param_name[MAX_PARAMS_PER_CMD];
+       unsigned int    cmd_id;
+       const char      *alias_name;
+       const char      *alias_qualifier;
+       unsigned int    alias_param;
+       unsigned int    *alias_param_array;
+       char            alias_bool_switch;
+} VCGData;
+
+extern void v_gen_system_cmd_def(void);
+extern void v_gen_object_cmd_def(void);
+extern void v_gen_geometry_cmd_def(void);
+extern void v_gen_material_cmd_def(void);
+extern void v_gen_bitmap_cmd_def(void);
+extern void v_gen_text_cmd_def(void);
+extern void v_gen_curve_cmd_def(void);
+extern void v_gen_audio_cmd_def(void);
+
+static void v_cg_init(void)
+{
+       int     i;
+       FILE    *f;
+
+       VCGData.nodes[V_NT_OBJECT] = fopen("v_gen_pack_o_node.c", "w");
+       VCGData.nodes[V_NT_GEOMETRY] = fopen("v_gen_pack_g_node.c", "w");  
+       VCGData.nodes[V_NT_MATERIAL] = fopen("v_gen_pack_m_node.c", "w");  
+       VCGData.nodes[V_NT_BITMAP] = fopen("v_gen_pack_b_node.c", "w");  
+       VCGData.nodes[V_NT_TEXT] = fopen("v_gen_pack_t_node.c", "w");  
+       VCGData.nodes[V_NT_CURVE] = fopen("v_gen_pack_c_node.c", "w");  
+       VCGData.nodes[V_NT_AUDIO] = fopen("v_gen_pack_a_node.c", "w");  
+       VCGData.nodes[V_NT_SYSTEM] = fopen("v_gen_pack_s_node.c", "w"); 
+       VCGData.init = fopen("v_gen_pack_init.c", "w");
+       VCGData.unpack = fopen("v_gen_unpack_func.h", "w");
+       VCGData.verse_h = fopen("verse.h", "w");
+       VCGData.internal_verse_h = fopen("v_internal_verse.h", "w");
+       for(i = 0; i < V_NT_NUM_TYPES_NETPACK + 1; i++)
+       {
+               if(i == V_NT_NUM_TYPES_NETPACK)
+                       f = VCGData.init;
+               else
+                       f = VCGData.nodes[i];
+               fprintf(f,
+                       "/*\n"
+                       "** This is automatically generated source code -- do not edit.\n"
+                       "** Changes are affected either by editing the corresponding protocol\n"
+                       "** definition file (v_cmd_def_X.c where X=node type), or by editing\n"
+                       "** the code generator itself, in v_cmd_gen.c.\n"
+                       "*/\n\n");
+               fprintf(f, "#include <stdlib.h>\n");
+               fprintf(f, "#include <stdio.h>\n\n");
+               fprintf(f, "#include \"v_cmd_gen.h\"\n");
+               fprintf(f, "#if !defined(V_GENERATE_FUNC_MODE)\n");
+               fprintf(f, "#include \"verse.h\"\n");
+               fprintf(f, "#include \"v_cmd_buf.h\"\n");
+               fprintf(f, "#include \"v_network_out_que.h\"\n");
+               fprintf(f, "#include \"v_network.h\"\n");
+               fprintf(f, "#include \"v_connection.h\"\n");
+               fprintf(f, "#include \"v_util.h\"\n\n");
+       }
+       VCGData.cmd_id = 0;
+       fprintf(f, "#include \"v_gen_unpack_func.h\"\n\n");
+       fprintf(f,
+               "#include \"verse.h\"\n\n\n"
+               "extern void verse_send_packet_ack(uint32 packet_id);\n"
+               "extern void verse_send_packet_nak(uint32 packet_id);\n\n");
+
+       fprintf(VCGData.init, "void init_pack_and_unpack(void)\n{\n");
+       fprintf(VCGData.verse_h,
+               "/*\n"
+               "** Verse API Header file (for use with libverse.a).\n"
+               "** This is automatically generated code; do not edit.\n"
+               "*/\n\n"
+               "\n"
+               "#if !defined VERSE_H\n"
+               "\n"
+               "#if defined __cplusplus\t\t/* Declare as C symbols for C++ users. */\n"
+               "extern \"C\" {\n"
+               "#endif\n\n"
+               "#define\tVERSE_H\n\n");
+       /* Copy contents of "verse_header.h" into output "verse.h". */
+       f = fopen("verse_header.h", "r");
+       while((i = fgetc(f)) != EOF)
+               fputc(i, VCGData.verse_h);
+       fclose(f);
+       fprintf(VCGData.verse_h, "\n/* Command sending functions begin. ----------------------------------------- */\n\n");
+}
+
+static void v_cg_close(void)
+{
+       unsigned int i;
+       for(i = 0; i < V_NT_NUM_TYPES_NETPACK; i++)
+       {
+               fprintf(VCGData.nodes[i], "#endif\n\n");
+       }
+       fprintf(VCGData.init, "}\n#endif\n\n");
+       fprintf(VCGData.verse_h,
+               "\n#if defined __cplusplus\n"
+               "}\n"
+               "#endif\n");
+       fprintf(VCGData.verse_h, "\n#endif\t\t/* VERSE_H */\n");
+}
+
+void v_cg_new_cmd(VCGCommandType type, const char *name, unsigned int cmd_id, VCGCommandType command)
+{
+       VCGData.param_count = 0;
+       VCGData.func_name = name;
+       VCGData.type = type;
+       VCGData.cmd_id = cmd_id;
+       VCGData.command = command;
+/*     printf("def: %u: %s\n", cmd_id, name);*/
+}
+
+void v_cg_new_manual_cmd(unsigned int cmd_id, const char *name, const char *def, const char *alias_name, const char *alias_def)
+{
+       fprintf(VCGData.verse_h, "extern %s;\n", def);
+       if(alias_def != NULL)
+               fprintf(VCGData.verse_h, "extern %s;\n", alias_def);
+       fprintf(VCGData.init, "\tv_fs_add_func(%i, v_unpack_%s, verse_send_%s, ", cmd_id, name, name);
+       if(alias_name != NULL)
+               fprintf(VCGData.init, "verse_send_%s);\n", alias_name);
+       else
+               fprintf(VCGData.init, "NULL);\n");
+       fprintf(VCGData.unpack, "extern unsigned int v_unpack_%s(const char *data, size_t length);\n", name);
+/*     printf("def: %u: %s\n", cmd_id, name);*/
+}
+
+void v_cg_alias(char bool_switch, const char *name, const char *qualifier, unsigned int param, unsigned int *param_array)
+{
+       VCGData.alias_name = name;
+       VCGData.alias_qualifier = qualifier;
+       VCGData.alias_param = param;
+       VCGData.alias_param_array = param_array;
+       VCGData.alias_bool_switch = bool_switch;
+}
+
+void v_cg_add_param(VCGParam type, const char *name)
+{
+       if(VCGData.param_count == MAX_PARAMS_PER_CMD)
+               exit(1);
+       VCGData.param_type[VCGData.param_count] = type;
+       VCGData.param_name[VCGData.param_count] = name;
+       VCGData.param_count++;
+}
+
+static void v_cg_gen_func_params(FILE *f, boolean types, boolean alias)
+{
+       unsigned int i;
+       unsigned int length, active;
+       length = VCGData.param_count;
+       if(alias)
+               length = VCGData.alias_param;
+       for(i = 0; i < length; i++)
+       {
+               if(alias && VCGData.alias_param_array != NULL)
+                       active = VCGData.alias_param_array[i];
+               else
+               {
+                       for(;(VCGData.param_type[i] == VCGP_PACK_INLINE || VCGData.param_type[i] == VCGP_UNPACK_INLINE || VCGData.param_type[i] == VCGP_POINTER_TYPE  || VCGData.param_type[i] == VCGP_ENUM_NAME) && i < VCGData.param_count; i++);
+                       if(i == VCGData.param_count)
+                               break;
+                       active = i;
+               }
+
+               if(active < VCGData.param_count && VCGData.param_type[active] != VCGP_END_ADDRESS)
+               {
+                       switch(VCGData.param_type[active])
+                       {
+                               case VCGP_UINT8 :
+                                       fprintf(f, "uint8 %s", VCGData.param_name[active]);
+                               break;
+                               case VCGP_UINT16 :
+                                       fprintf(f, "uint16 %s", VCGData.param_name[active]);
+                               break;
+                               case VCGP_UINT32 :
+                                       fprintf(f, "uint32 %s", VCGData.param_name[active]);
+                               break;
+                               case VCGP_REAL32 :
+                                       fprintf(f, "real32 %s", VCGData.param_name[active]);
+                               break;
+                               case VCGP_REAL64 :
+                                       fprintf(f, "real64 %s", VCGData.param_name[active]);
+                               break;
+                               case VCGP_POINTER :
+                                       if(active != 0 && VCGData.param_type[active - 1] == VCGP_POINTER_TYPE)
+                                               fprintf(f, "const %s *%s", VCGData.param_name[active - 1], VCGData.param_name[active]);
+                                       else
+                                               fprintf(f, "const void *%s", VCGData.param_name[active]);
+                               break;
+                               case VCGP_NAME :
+                                       if(types)
+                                               fprintf(f, "char %s[16]", VCGData.param_name[active]);
+                                       else
+                                               fprintf(f, "const char *%s", VCGData.param_name[active]);
+                               break;
+                               case VCGP_LONG_NAME :
+                                       if(types)
+                                               fprintf(f, "char %s[512]", VCGData.param_name[active]);
+                                       else
+                                               fprintf(f, "const char *%s", VCGData.param_name[active]);
+                               break;
+                               case VCGP_NODE_ID :
+                                       fprintf(f, "VNodeID %s", VCGData.param_name[active]);
+                               break;
+                               case VCGP_LAYER_ID :
+                                       fprintf(f, "VLayerID %s", VCGData.param_name[active]);
+                               break;
+                               case VCGP_BUFFER_ID :
+                                       fprintf(f, "VBufferID %s", VCGData.param_name[active]);
+                               break;
+                               case VCGP_FRAGMENT_ID :
+                                       fprintf(f, "VNMFragmentID %s", VCGData.param_name[active]);
+                               break;
+                               case VCGP_ENUM :
+/*                                     if(types)
+                                               fprintf(f, "uint8 %s", VCGData.param_name[active]);
+                                       else
+*/                                             fprintf(f, "%s %s", VCGData.param_name[active - 1], VCGData.param_name[active]);
+                               break;
+                       }
+                       if(types)
+                               fprintf(f, ";\n\t");
+                       else
+                       {
+                               for(;(VCGData.param_type[active + 1] == VCGP_END_ADDRESS || VCGData.param_type[active + 1] == VCGP_PACK_INLINE || VCGData.param_type[active + 1] == VCGP_UNPACK_INLINE || VCGData.param_type[active + 1] == VCGP_POINTER_TYPE) && active < VCGData.param_count; active++);
+                               if(active + 1 < length)
+                                       fprintf(f, ", ");
+                       }
+               }
+       }
+}
+
+static void v_cg_create_print(FILE *f, boolean send, boolean alias)
+{
+       unsigned int i, length, active;
+       const char *name;
+       if(VCGData.command == VCGCT_INVISIBLE_SYSTEM)
+               return;
+       name = VCGData.func_name;
+       if(alias)
+               name = VCGData.alias_name;
+       if(send)
+               fprintf(f, "\tprintf(\"send: verse_send_%s(", name);
+       else
+               fprintf(f, "\tprintf(\"receive: verse_send_%s(", name);
+
+       length = VCGData.param_count;
+       if(alias)
+               length = VCGData.alias_param;
+       for(i = 0; i < length; i++)
+       {
+               if(alias && VCGData.alias_param_array != NULL)
+                       active = VCGData.alias_param_array[i];
+               else
+                       active = i;
+
+               switch(VCGData.param_type[active])
+               {
+                       case VCGP_NODE_ID :
+                               fprintf(f, "%s = %%u ", VCGData.param_name[active]);
+                       break;
+                       case VCGP_UINT8 :
+                       case VCGP_UINT16 :
+                       case VCGP_UINT32 :
+                       case VCGP_LAYER_ID :
+                       case VCGP_BUFFER_ID :
+                       case VCGP_ENUM :
+                       case VCGP_FRAGMENT_ID :
+                               fprintf(f, "%s = %%u ", VCGData.param_name[active]);
+                       break;
+                       case VCGP_REAL32 :
+                       case VCGP_REAL64 :
+                               fprintf(f, "%s = %%f ", VCGData.param_name[active]);
+                       break;
+                       case VCGP_POINTER :
+                               if(send)
+                                       fprintf(f, "%s = %%p ", VCGData.param_name[active]);
+                       break;
+                       case VCGP_NAME :
+                       case VCGP_LONG_NAME :
+                               fprintf(f, "%s = %%s ", VCGData.param_name[active]);
+                       break;
+               }
+       }
+       if(send)
+               fprintf(f, ");\\n\"");
+       else
+               fprintf(f, "); callback = %%p\\n\"");
+
+       for(i = 0; i < length; i++)
+       {
+               if(alias && VCGData.alias_param_array != NULL)
+                       active = VCGData.alias_param_array[i];
+               else
+                       active = i;
+               switch(VCGData.param_type[active])
+               {
+                       case VCGP_NODE_ID :
+                               fprintf(f, ", %s", VCGData.param_name[active]);
+                       break;
+                       case VCGP_POINTER :
+                               if(!send)
+                                       break;
+                       case VCGP_UINT8 :
+                       case VCGP_UINT16 :
+                       case VCGP_UINT32 :
+                       case VCGP_LAYER_ID :
+                       case VCGP_BUFFER_ID :
+                       case VCGP_ENUM :
+                       case VCGP_FRAGMENT_ID :
+                       case VCGP_REAL32 :
+                       case VCGP_REAL64 :
+                       case VCGP_NAME :
+                       case VCGP_LONG_NAME :
+                               fprintf(f, ", %s", VCGData.param_name[active]);
+                       break;
+               }
+       }
+       if(send)
+               fprintf(f, ");\n");
+       else if(alias)
+               fprintf(f, ", v_fs_get_alias_user_func(%u));\n", VCGData.cmd_id);
+       else
+               fprintf(f, ", v_fs_get_user_func(%u));\n", VCGData.cmd_id);
+
+}
+
+static unsigned int v_cg_compute_command_size(unsigned int start, boolean end)
+{
+       unsigned int size = 0;
+       for(; start < VCGData.param_count; start++)
+       {
+               switch(VCGData.param_type[start])
+               {
+                       case  VCGP_UINT8 :
+                       case  VCGP_ENUM :
+                               size++;
+                               break;
+                       case  VCGP_UINT16 :
+                       case  VCGP_LAYER_ID :
+                       case  VCGP_BUFFER_ID :
+                       case  VCGP_FRAGMENT_ID :
+                               size += 2;
+                               break;
+                       case  VCGP_NODE_ID : 
+                       case  VCGP_UINT32 :
+                       case  VCGP_REAL32 :
+                               size += 4;
+                               break;
+                       case  VCGP_REAL64 :
+                               size += 8;
+                               break;
+                       case  VCGP_NAME :
+                               if(end)
+                                       return size;
+                               size += 16;
+                               break;
+                       case  VCGP_LONG_NAME :
+                               if(end)
+                                       return size;
+                               size += 512;
+                               break;
+                       case  VCGP_POINTER :
+                       case  VCGP_PACK_INLINE :
+                       case  VCGP_UNPACK_INLINE :
+                               if(end)
+                                       return size;
+                               size += 1500;
+                               break;
+                       case VCGP_END_ADDRESS :
+                               if(end)
+                                       return size;
+               }
+       }
+       return size;
+}
+
+void v_cg_set_command_address(FILE *f, boolean alias)
+{
+       unsigned int i, count = 0, length, size = 1, *param, def[] ={0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
+       for(i = 0; i < VCGData.param_count; i++)
+               if(VCGData.param_type[i] == VCGP_END_ADDRESS)
+                       break;
+       if(i == VCGData.param_count)
+               return;
+       if(alias)
+               length = VCGData.alias_param;
+       else
+               length = VCGData.param_count;
+
+       if(alias && VCGData.alias_param_array != 0)
+               param = VCGData.alias_param_array;
+       else
+               param = def;
+
+       if(i == VCGData.param_count)
+               return;
+       fprintf(f, "\tif(");
+       for(i = 0; i < length; i++)
+       {
+               switch(VCGData.param_type[param[i]])
+               {
+                       case  VCGP_UINT8 :
+                       case  VCGP_ENUM :
+                               size++;
+                               break;
+                       case  VCGP_UINT16 :
+                       case  VCGP_LAYER_ID :
+                       case  VCGP_BUFFER_ID :
+                       case  VCGP_FRAGMENT_ID :
+                               if(count++ != 0)
+                                       fprintf(f, " || ");
+                               fprintf(f, "%s == (uint16)(-1)", VCGData.param_name[param[i]]);
+                               size += 2;
+                               break;
+                       case  VCGP_NODE_ID : 
+                       case  VCGP_UINT32 :
+                       case  VCGP_REAL32 :
+                               if(count++ != 0)
+                                       fprintf(f, " || ");
+                               fprintf(f, "%s == (uint32)(-1)", VCGData.param_name[param[i]]);
+                               size += 4;
+                               break;
+                       case VCGP_END_ADDRESS :
+                               fprintf(f, ")\n");
+                               fprintf(f, "\t\tv_cmd_buf_set_unique_address_size(head, %u);\n", size);
+                               fprintf(f, "\telse\n");
+                               fprintf(f, "\t\tv_cmd_buf_set_address_size(head, %u);\n", size);
+                               return;
+               }
+       }
+       fprintf(f, ")\n");
+       fprintf(f, "\t\tv_cmd_buf_set_unique_address_size(head, %u);\n", size);
+       fprintf(f, "\telse\n");
+       fprintf(f, "\t\tv_cmd_buf_set_address_size(head, %u);\n", size);
+       return;
+}
+
+static const char * v_cg_compute_buffer_size(void)
+{
+       unsigned int size; 
+       size = v_cg_compute_command_size(0, FALSE) + 1;
+       if(size <= 10)
+               return "VCMDBS_10";
+       else if(size <= 20)
+               return "VCMDBS_20";
+       else if(size <= 30)
+               return "VCMDBS_30";
+       else if(size <= 80)
+               return "VCMDBS_80";
+       else if(size <= 160)
+               return "VCMDBS_160";
+       else if(size <= 320)
+               return "VCMDBS_320";
+       return "VCMDBS_1500";
+}
+
+static void v_cg_gen_pack(boolean alias)
+{
+       unsigned int i, j, size = 0, ad_size = 0;
+       boolean printed = FALSE;
+       boolean address = FALSE;
+       boolean no_param;
+
+       FILE *f;
+       f = VCGData.nodes[VCGData.type];
+       printf("generating function: verse_send_%s\n", VCGData.func_name);
+       if(alias)
+               fprintf(f, "void verse_send_%s(", VCGData.alias_name);
+       else
+               fprintf(f, "void verse_send_%s(", VCGData.func_name);
+       v_cg_gen_func_params(f, FALSE, alias);
+       fprintf(f, ")\n{\n\tuint8 *buf;\n");
+       fprintf(f, "\tunsigned int buffer_pos = 0;\n");
+       fprintf(f, "\tVCMDBufHead *head;\n");
+       fprintf(f, "\thead = v_cmd_buf_allocate(%s);/* Allocating the buffer */\n", v_cg_compute_buffer_size());
+       fprintf(f, "\tbuf = ((VCMDBuffer10 *)head)->buf;\n\n");
+
+       fprintf(f, "\tbuffer_pos += vnp_raw_pack_uint8(&buf[buffer_pos], %u);\t/* Pack the command. */\n", VCGData.cmd_id);
+
+       fprintf(f, "#if defined V_PRINT_SEND_COMMANDS\n");
+       v_cg_create_print(f, TRUE, alias);
+       fprintf(f, "#endif\n");
+
+       for(i = 0; i < VCGData.param_count; i++)
+       {
+               const char *param = VCGData.param_name[i];
+               no_param = FALSE;
+               if(alias)
+               {
+                       if(i >= VCGData.alias_param && VCGData.alias_param_array == NULL)
+                               no_param = TRUE;
+                       if(VCGData.alias_param_array != NULL)
+                       {
+                               for(j = 0; j < VCGData.alias_param; j++)
+                                       if(VCGData.alias_param_array[j] == i)
+                                               break;
+                               if(j == VCGData.alias_param)
+                                       no_param = TRUE;
+                       }
+               }
+
+               if(no_param)
+                       param = "-1";
+
+               switch(VCGData.param_type[i])
+               {
+                       case VCGP_UINT8 :
+                               fprintf(f, "\tbuffer_pos += vnp_raw_pack_uint8(&buf[buffer_pos], %s);\n", param);
+                       break;
+                       case VCGP_UINT16 :
+                               fprintf(f, "\tbuffer_pos += vnp_raw_pack_uint16(&buf[buffer_pos], %s);\n", param);
+                       break;
+                       case VCGP_UINT32 :
+                               fprintf(f, "\tbuffer_pos += vnp_raw_pack_uint32(&buf[buffer_pos], %s);\n", param);
+                       break;
+                       case VCGP_ENUM :
+                               fprintf(f, "\tbuffer_pos += vnp_raw_pack_uint8(&buf[buffer_pos], (uint8)%s);\n", param);
+                       break;
+               }
+               if(VCGData.param_type[i] == VCGP_REAL32)
+               {
+                       if(no_param)
+                               param = "V_REAL32_MAX";
+                       fprintf(f, "\tbuffer_pos += vnp_raw_pack_real32(&buf[buffer_pos], %s);\n", param);
+               }
+               if(VCGData.param_type[i] == VCGP_REAL64)
+               {
+                       if(no_param)
+                               param = "V_REAL64_MAX";
+                       fprintf(f, "\tbuffer_pos += vnp_raw_pack_real64(&buf[buffer_pos], %s);\n", param);
+               }
+               if(no_param)
+                       param = "NULL";
+               switch(VCGData.param_type[i])
+               {
+                       case VCGP_NAME :
+                               fprintf(f, "\tbuffer_pos += vnp_raw_pack_string(&buf[buffer_pos], %s, 16);\n", param);
+                       break;
+                       case VCGP_LONG_NAME :
+                               fprintf(f, "\tbuffer_pos += vnp_raw_pack_string(&buf[buffer_pos], %s, 512);\n", param);
+                       break;
+               }
+               if(no_param)
+                       param = "-1";
+               switch(VCGData.param_type[i])
+               {       
+                       case VCGP_NODE_ID :
+                               fprintf(f, "\tbuffer_pos += vnp_raw_pack_uint32(&buf[buffer_pos], %s);\n", param);
+                       break;
+                       case VCGP_LAYER_ID :
+                               fprintf(f, "\tbuffer_pos += vnp_raw_pack_uint16(&buf[buffer_pos], %s);\n", param);
+                       break;
+                       case VCGP_BUFFER_ID :
+                               fprintf(f, "\tbuffer_pos += vnp_raw_pack_uint16(&buf[buffer_pos], %s);\n", param);
+                       break;
+                       case VCGP_FRAGMENT_ID :
+                               fprintf(f, "\tbuffer_pos += vnp_raw_pack_uint16(&buf[buffer_pos], %s);\n", param);
+                       break;
+               }
+               if(!alias && VCGData.param_type[i] == VCGP_PACK_INLINE)
+                               fprintf(f, "%s", VCGData.param_name[i]);
+       }
+       if(VCGData.alias_name != NULL && VCGData.alias_bool_switch)
+       {
+               if(alias)
+                       fprintf(f, "\tbuffer_pos += vnp_raw_pack_uint8(&buf[buffer_pos], FALSE);\n");
+               else
+                       fprintf(f, "\tbuffer_pos += vnp_raw_pack_uint8(&buf[buffer_pos], TRUE);\n");
+       }
+       v_cg_set_command_address(f, alias);
+       fprintf(f, "\tv_cmd_buf_set_size(head, buffer_pos);\n");
+       
+       fprintf(f, "\tv_noq_send_buf(v_con_get_network_queue(), head);\n");
+       fprintf(f, "}\n\n");
+}
+
+static void v_cg_gen_unpack(void)
+{
+       FILE *f;
+       unsigned int i;
+       boolean printed = FALSE;
+
+       f = VCGData.nodes[VCGData.type];
+       printf("generating function: v_unpack_%s\n", VCGData.func_name);
+       fprintf(f, "unsigned int v_unpack_%s(const char *buf, size_t buffer_length)\n", VCGData.func_name);
+       fprintf(f, "{\n");
+       for(i = 0; i < VCGData.param_count && VCGData.param_type[i] != VCGP_ENUM; i++);
+       if(i < VCGData.param_count)
+               fprintf(f, "\tuint8 enum_temp;\n");
+       fprintf(f, "\tunsigned int buffer_pos = 0;\n");
+       fprintf(f, "\tvoid (* func_%s)(void *user_data, ", VCGData.func_name);
+       v_cg_gen_func_params(f, FALSE, FALSE);
+       fprintf(f, ");\n\t");
+       v_cg_gen_func_params(f, TRUE, FALSE);
+       if(VCGData.alias_name != NULL && VCGData.alias_bool_switch)
+               fprintf(f, "uint8\talias_bool;\n");
+       fprintf(f, "\n\tfunc_%s = v_fs_get_user_func(%u);\n", VCGData.func_name, VCGData.cmd_id);
+       fprintf(f, "\tif(buffer_length < %u)\n\t\treturn -1;\n", v_cg_compute_command_size(0, TRUE));
+       for(i = 0; i < VCGData.param_count; i++)
+       {
+               switch(VCGData.param_type[i])
+               {
+                       case VCGP_UINT8 :
+                               fprintf(f, "\tbuffer_pos += vnp_raw_unpack_uint8(&buf[buffer_pos], &%s);\n", VCGData.param_name[i]);
+                       break;
+                       case VCGP_UINT16 :
+                               fprintf(f, "\tbuffer_pos += vnp_raw_unpack_uint16(&buf[buffer_pos], &%s);\n", VCGData.param_name[i]);
+                       break;
+                       case VCGP_UINT32 :
+                               fprintf(f, "\tbuffer_pos += vnp_raw_unpack_uint32(&buf[buffer_pos], &%s);\n", VCGData.param_name[i]);
+                       break;
+                       case VCGP_REAL32 :
+                       fprintf(f, "\tbuffer_pos += vnp_raw_unpack_real32(&buf[buffer_pos], &%s);\n", VCGData.param_name[i]);
+                       break;
+                       case VCGP_REAL64 :
+                               fprintf(f, "\tbuffer_pos += vnp_raw_unpack_real64(&buf[buffer_pos], &%s);\n", VCGData.param_name[i]);
+                       break;
+                       case VCGP_POINTER_TYPE :
+                       break;
+                       case VCGP_POINTER :
+                       break;
+                       case VCGP_NAME :
+                               fprintf(f, "\tbuffer_pos += vnp_raw_unpack_string(&buf[buffer_pos], %s, 16, buffer_length - buffer_pos);\n", VCGData.param_name[i]);
+                               if(i + 1 < VCGData.param_count)
+                                       fprintf(f, "\tif(buffer_length < %u + buffer_pos)\n\t\treturn -1;\n", v_cg_compute_command_size(i + 1, TRUE));
+                       break;
+                       case VCGP_LONG_NAME :
+                               fprintf(f, "\tbuffer_pos += vnp_raw_unpack_string(&buf[buffer_pos], %s, 512, buffer_length - buffer_pos);\n", VCGData.param_name[i]);
+                               if(i + 1 < VCGData.param_count)
+                                       fprintf(f, "\tif(buffer_length < %u + buffer_pos)\n\t\treturn -1;\n", v_cg_compute_command_size(i + 1, TRUE));
+                       break;
+                       case VCGP_NODE_ID :
+                               fprintf(f, "\tbuffer_pos += vnp_raw_unpack_uint32(&buf[buffer_pos], &%s);\n", VCGData.param_name[i]);
+                       break;
+                       case VCGP_LAYER_ID :
+                               fprintf(f, "\tbuffer_pos += vnp_raw_unpack_uint16(&buf[buffer_pos], &%s);\n", VCGData.param_name[i]);
+                       break;
+                       case VCGP_BUFFER_ID :
+                               fprintf(f, "\tbuffer_pos += vnp_raw_unpack_uint16(&buf[buffer_pos], &%s);\n", VCGData.param_name[i]);
+                       break;
+                       case VCGP_FRAGMENT_ID :
+                               fprintf(f, "\tbuffer_pos += vnp_raw_unpack_uint16(&buf[buffer_pos], &%s);\n", VCGData.param_name[i]);
+                       break;
+                       case VCGP_ENUM :
+                               fprintf(f, "\tbuffer_pos += vnp_raw_unpack_uint8(&buf[buffer_pos], &enum_temp);\n");
+                               fprintf(f, "\t%s = (%s)enum_temp;\n", VCGData.param_name[i], VCGData.param_name[i - 1]);
+                       break;
+                       case VCGP_UNPACK_INLINE :
+                               if(!printed)
+                               {
+                                       fprintf(f, "#if defined V_PRINT_RECEIVE_COMMANDS\n");
+                                       if(VCGData.alias_name != NULL)
+                                       {
+                                               fprintf(f, "\t%s\n\t", VCGData.alias_qualifier);
+                                               v_cg_create_print(f, FALSE, TRUE);
+                                               fprintf(f, "\telse\n\t");
+                                       }
+                                       v_cg_create_print(f, FALSE, FALSE);
+                                       fprintf(f, "#endif\n");
+                                       printed = TRUE;
+                               }
+                               fprintf(f, "%s\n", VCGData.param_name[i++]);
+                       break;
+               }
+       }
+       if(VCGData.alias_name != NULL && VCGData.alias_bool_switch)
+       {
+               fprintf(f, "\tif(buffer_length < buffer_pos + 1)\n");
+               fprintf(f, "\t\treturn -1;\n");
+               fprintf(f, "\tbuffer_pos += vnp_raw_unpack_uint8(&buf[buffer_pos], &alias_bool);\n");
+       }
+       if(!printed)
+       {
+               fprintf(f, "#if defined V_PRINT_RECEIVE_COMMANDS\n");
+               if(VCGData.alias_name != NULL)
+               {
+                       if(VCGData.alias_qualifier != NULL)
+                               fprintf(f, "\t%s\n\t", VCGData.alias_qualifier);
+                       else
+                               fprintf(f, "\tif(!alias_bool)\n\t");
+                       v_cg_create_print(f, FALSE, TRUE);
+                       fprintf(f, "\telse\n\t");
+               }
+               v_cg_create_print(f, FALSE, FALSE);
+               fprintf(f, "#endif\n");
+               printed = TRUE;
+       }
+
+       if(VCGData.alias_name != NULL)
+       {
+               unsigned int    active;
+
+               if(VCGData.alias_bool_switch)
+                       fprintf(f, "\tif(!alias_bool)\n");
+               else
+                       fprintf(f, "\t%s\n", VCGData.alias_qualifier);
+               fprintf(f, "\t{\n");
+               fprintf(f, "\t\tvoid (* alias_%s)(void *user_data, ", VCGData.alias_name);
+               v_cg_gen_func_params(f, FALSE, TRUE);
+               fprintf(f, ");\n");
+               fprintf(f, "\t\talias_%s = v_fs_get_alias_user_func(%u);\n", VCGData.alias_name, VCGData.cmd_id);
+               fprintf(f, "\t\tif(alias_%s != NULL)\n", VCGData.alias_name);
+               fprintf(f, "\t\t\talias_%s(v_fs_get_alias_user_data(%u)", VCGData.alias_name, VCGData.cmd_id);
+               for(i = 0; i < VCGData.param_count && i < VCGData.alias_param; i++)
+               {
+                       if(VCGData.alias_param_array != NULL)
+                               active = VCGData.alias_param_array[i];
+                       else
+                               active = i;
+
+                       if(VCGData.param_type[active] != VCGP_PACK_INLINE &&
+                          VCGData.param_type[active] != VCGP_UNPACK_INLINE &&
+                          VCGData.param_type[active] != VCGP_END_ADDRESS &&
+                          VCGData.param_type[active] != VCGP_POINTER_TYPE)
+                       {
+                               if(VCGData.param_type[active] == VCGP_ENUM_NAME)
+                               {
+                                       fprintf(f, ", (%s)%s", VCGData.param_name[active], VCGData.param_name[active + 1]);
+                                       i++;
+                               }
+                               else
+                                       fprintf(f, ", %s", VCGData.param_name[active]);
+                       }
+               }
+               fprintf(f, ");\n\t\treturn buffer_pos;\n\t}\n");
+       }
+       
+       fprintf(f, "\tif(func_%s != NULL)\n", VCGData.func_name);
+       fprintf(f, "\t\tfunc_%s(v_fs_get_user_data(%u)", VCGData.func_name, VCGData.cmd_id);
+       for(i = 0; i < VCGData.param_count; i++)
+       {
+               if(VCGData.param_type[i] != VCGP_PACK_INLINE && VCGData.param_type[i] != VCGP_UNPACK_INLINE && VCGData.param_type[i] != VCGP_END_ADDRESS && VCGData.param_type[i] != VCGP_POINTER_TYPE)
+               {
+                       if(VCGData.param_type[i] == VCGP_ENUM_NAME)
+                       {
+                               fprintf(f, ", (%s) %s", VCGData.param_name[i], VCGData.param_name[i + 1]);
+                               i++;
+                       }
+                       else
+                               fprintf(f, ", %s", VCGData.param_name[i]);
+               }
+       }
+       fprintf(f, ");\n");
+       fprintf(f, "\n\treturn buffer_pos;\n");
+       fprintf(f, "}\n\n");
+}
+
+static void v_cg_gen_alias(void)
+{
+       FILE *f;
+       unsigned int i;
+       f = VCGData.nodes[VCGData.type];
+       fprintf(f, "void verse_send_%s(", VCGData.alias_name);
+       v_cg_gen_func_params(f, FALSE, TRUE);
+       fprintf(f, ")\n{\n");
+       fprintf(f, "\tverse_send_%s(", VCGData.func_name);
+       for(i = 0; i < VCGData.param_count; i++)
+               if(VCGData.param_type[i] != VCGP_ENUM_NAME && VCGData.param_type[i] != VCGP_PACK_INLINE && VCGData.param_type[i] != VCGP_UNPACK_INLINE && VCGData.param_type[i] != VCGP_END_ADDRESS && VCGData.param_type[i] != VCGP_POINTER_TYPE)
+                       fprintf(f, ", %s", VCGData.param_name[i]);
+       fprintf(f, "}\n\n");
+}
+
+static void v_cg_gen_init(void)
+{
+       FILE *f;
+       f = VCGData.init;
+       fprintf(f, "\tv_fs_add_func(%i, v_unpack_%s, verse_send_%s, ", VCGData.cmd_id, VCGData.func_name, VCGData.func_name);
+       if(VCGData.alias_name != NULL)
+               fprintf(f, "verse_send_%s);\n", VCGData.alias_name);
+       else
+               fprintf(f, "NULL);\n");
+}
+
+static void v_cg_gen_verse_h(void)
+{
+       FILE *f;
+       if(VCGData.command == VCGCT_INVISIBLE_SYSTEM)
+               f = VCGData.internal_verse_h;
+       else
+               f = VCGData.verse_h;
+       fprintf(f, "extern void verse_send_%s(", VCGData.func_name);
+       v_cg_gen_func_params(f, FALSE, FALSE);
+       fprintf(f, ");\n");
+       if(VCGData.alias_name != NULL)
+       {
+               fprintf(f, "extern void verse_send_%s(", VCGData.alias_name);
+               v_cg_gen_func_params(f, FALSE, TRUE);
+               fprintf(f, ");\n");
+       }
+}
+
+static void v_cg_gen_unpack_h(void)
+{
+       fprintf(VCGData.unpack, "extern unsigned int v_unpack_%s(const char *data, size_t length);\n", VCGData.func_name);
+}
+
+void v_cg_end_cmd(void)
+{
+       v_cg_gen_pack(FALSE);
+       if(VCGData.alias_name != NULL)
+               v_cg_gen_pack(TRUE);
+       v_cg_gen_unpack();
+       v_cg_gen_init();
+       v_cg_gen_verse_h();
+       v_cg_gen_unpack_h();
+       VCGData.alias_name = NULL;
+}
+
+int main(int argc, char *argv[])
+{
+       printf("start\n");
+       v_cg_init();
+       v_gen_system_cmd_def();
+       fprintf(VCGData.verse_h, "\n");
+       v_gen_object_cmd_def();
+       fprintf(VCGData.verse_h, "\n");
+       v_gen_geometry_cmd_def();
+       fprintf(VCGData.verse_h, "\n");
+       v_gen_material_cmd_def();
+       fprintf(VCGData.verse_h, "\n");
+       v_gen_bitmap_cmd_def();
+       fprintf(VCGData.verse_h, "\n");
+       v_gen_text_cmd_def();
+       fprintf(VCGData.verse_h, "\n");
+       v_gen_curve_cmd_def();
+       fprintf(VCGData.verse_h, "\n");
+       v_gen_audio_cmd_def();
+       fprintf(VCGData.verse_h, "\n");
+       v_cg_close();
+       printf("end\n");
+
+       return EXIT_SUCCESS;
+}
+
+#endif
diff --git a/extern/verse/dist/v_cmd_gen.h b/extern/verse/dist/v_cmd_gen.h
new file mode 100644 (file)
index 0000000..6cc19a8
--- /dev/null
@@ -0,0 +1,42 @@
+/*
+**
+*/
+
+/* Define this to at least build the code that regenerates the variable parts of the code. */
+/*#define V_GENERATE_FUNC_MODE*/
+
+typedef enum {
+       VCGP_UINT8,
+       VCGP_UINT16,
+       VCGP_UINT32,
+       VCGP_REAL32,
+       VCGP_REAL64,
+       VCGP_POINTER_TYPE,
+       VCGP_POINTER,
+       VCGP_NAME,
+       VCGP_LONG_NAME,
+       VCGP_NODE_ID,
+       VCGP_LAYER_ID,
+       VCGP_BUFFER_ID,
+       VCGP_FRAGMENT_ID,
+       VCGP_ENUM_NAME,
+       VCGP_ENUM,
+       VCGP_PACK_INLINE,
+       VCGP_UNPACK_INLINE,
+       VCGP_END_ADDRESS
+} VCGParam;
+
+typedef enum {
+       VCGCT_NORMAL,
+       VCGCT_UNIQUE,
+       VCGCT_ONCE,
+       VCGCT_INVISIBLE_SYSTEM, /* In the dark we are all invisible. */
+       VCGCT_ORDERED
+} VCGCommandType;
+
+extern void v_cg_new_cmd(VCGCommandType type, const char *name, unsigned int cmd_id, VCGCommandType command);
+extern void v_cg_add_param(VCGParam type, const char *name);
+extern void v_cg_alias(char bool_switch, const char *name, const char *qualifier,
+                      unsigned int param, unsigned int *param_array);
+extern void v_cg_end_cmd(void);
+extern void v_cg_new_manual_cmd(unsigned int cmd_id, const char *name, const char *params, const char *alias_name, const char *alias_params);
diff --git a/extern/verse/dist/v_connect.c b/extern/verse/dist/v_connect.c
new file mode 100644 (file)
index 0000000..ae21bcb
--- /dev/null
@@ -0,0 +1,490 @@
+/*
+**
+*/
+
+#include <ctype.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "v_cmd_gen.h"
+
+#if !defined V_GENERATE_FUNC_MODE
+
+#include "verse.h"
+#include "v_cmd_buf.h"
+#include "v_network_out_que.h"
+#include "v_network.h"
+#include "v_connection.h"
+#include "v_encryption.h"
+#include "v_util.h"
+
+extern void verse_send_packet_ack(uint32 packet_id);
+
+static void v_send_hidden_connect_contact(void) /*  Stage 0: Clinets inital call to connect to host */
+{
+       uint8 buf[V_ENCRYPTION_LOGIN_KEY_HALF_SIZE + 4 + 1 + 1], *key;
+       unsigned int i, buffer_pos = 0;
+       buffer_pos += vnp_raw_pack_uint32(&buf[buffer_pos], 0);/* Packing the packet id */
+       buffer_pos += vnp_raw_pack_uint8(&buf[buffer_pos], 0);/* Packing the command */
+       buffer_pos += vnp_raw_pack_uint8(&buf[buffer_pos], 0);/* Stage 0 */
+
+       key = v_con_get_my_key();
+       for(i = 0; i < V_ENCRYPTION_LOGIN_KEY_SIZE; i++)
+               buffer_pos += vnp_raw_pack_uint8(&buf[buffer_pos], key[V_ENCRYPTION_LOGIN_PUBLIC_START + i]);/* Packing the command */
+       for(i = 0; i < V_ENCRYPTION_LOGIN_KEY_SIZE; i++)
+               buffer_pos += vnp_raw_pack_uint8(&buf[buffer_pos], key[V_ENCRYPTION_LOGIN_N_START + i]);/* Packing the command */
+       
+       v_n_send_data(v_con_get_network_address(), buf, buffer_pos);
+}
+
+static void v_send_hidden_connect_send_key(void) /*  Stage 1: Hosts reply to any atempt to connect */
+{
+       uint8 buf[V_ENCRYPTION_LOGIN_KEY_SIZE * 3 + 4 + 1 + 1 + 1 + 4 + 4], *host_id;
+       unsigned int i, buffer_pos = 0, s, f;
+       buffer_pos += vnp_raw_pack_uint32(&buf[buffer_pos], 0);/* Packing the packet id */
+       buffer_pos += vnp_raw_pack_uint8(&buf[buffer_pos], 0);/* Packing the command */
+       buffer_pos += vnp_raw_pack_uint8(&buf[buffer_pos], 1);/* Stage 1 */
+       buffer_pos += vnp_raw_pack_uint8(&buf[buffer_pos], V_RELEASE_NUMBER);/* version */
+       v_n_get_current_time(&s, &f);
+       buffer_pos += vnp_raw_pack_uint32(&buf[buffer_pos], s);/* time, seconds */
+       buffer_pos += vnp_raw_pack_uint32(&buf[buffer_pos], f);/* time, fraction */
+       host_id = v_con_get_host_id();
+       for(i = 0; i < V_ENCRYPTION_LOGIN_KEY_SIZE; i++)
+               buffer_pos += vnp_raw_pack_uint8(&buf[buffer_pos], host_id[V_ENCRYPTION_LOGIN_PUBLIC_START + i]);
+       for(i = 0; i < V_ENCRYPTION_LOGIN_KEY_SIZE; i++)
+               buffer_pos += vnp_raw_pack_uint8(&buf[buffer_pos], host_id[V_ENCRYPTION_LOGIN_N_START + i]);
+       
+       v_n_send_data(v_con_get_network_address(), buf, buffer_pos);
+}
+
+static void v_send_hidden_connect_login(void) /* Stage 2: clients sends encrypted name and password */
+{
+       uint8           buf[1500], *key, name_pass[V_ENCRYPTION_LOGIN_KEY_SIZE], encrypted_key[V_ENCRYPTION_LOGIN_KEY_SIZE];
+       const char      *name, *pass;
+       unsigned int    buffer_pos = 0, i;
+
+       buffer_pos += vnp_raw_pack_uint32(&buf[buffer_pos], 1);/* Packing the packet id */
+       buffer_pos += vnp_raw_pack_uint8(&buf[buffer_pos], 0);/* Packing the command */
+       buffer_pos += vnp_raw_pack_uint8(&buf[buffer_pos], 2);/* Stage 2 */
+       name = v_con_get_name();
+       /* Pad data area with randomness. */
+       for(i = 0; i < sizeof name_pass; i++)
+               name_pass[i] = rand() >> 13;
+       v_strlcpy(name_pass, name, V_ENCRYPTION_LOGIN_KEY_SIZE / 2);
+       pass = v_con_get_pass();
+       v_strlcpy(name_pass + V_ENCRYPTION_LOGIN_KEY_SIZE / 2, pass, V_ENCRYPTION_LOGIN_KEY_SIZE / 2);
+       /* Make sure last (MSB) byte is clear, to guarantee that data < key for RSA math. */
+       name_pass[sizeof name_pass - 1] = 0;
+       key = v_con_get_other_key();
+       v_e_connect_encrypt(encrypted_key, name_pass, &key[V_ENCRYPTION_LOGIN_PUBLIC_START], &key[V_ENCRYPTION_LOGIN_N_START]);
+
+       for(i = 0; i < V_ENCRYPTION_LOGIN_KEY_SIZE; i++)
+               buffer_pos += vnp_raw_pack_uint8(&buf[buffer_pos], encrypted_key[i]);
+       v_n_send_data(v_con_get_network_address(), buf, buffer_pos);
+}
+
+static void v_send_hidden_connect_accept(void) /* Host accepts Clients connectionatempt and sends over data encryption key */
+{
+       uint8 buf[1500], *client_key, encrypted[V_ENCRYPTION_DATA_KEY_SIZE];
+       unsigned int i, buffer_pos = 0;
+
+       buffer_pos += vnp_raw_pack_uint32(&buf[buffer_pos], 1);/* Packing the packet id */
+       buffer_pos += vnp_raw_pack_uint8(&buf[buffer_pos], 1);/* Packing the command */
+       buffer_pos += vnp_raw_pack_uint32(&buf[buffer_pos], verse_session_get_avatar());
+       client_key = v_con_get_other_key();
+       v_e_connect_encrypt(encrypted, v_con_get_data_key(), &client_key[V_ENCRYPTION_LOGIN_PUBLIC_START], &client_key[V_ENCRYPTION_LOGIN_N_START]);
+       for(i = 0; i < V_ENCRYPTION_DATA_KEY_SIZE; i++)
+               buffer_pos += vnp_raw_pack_uint8(&buf[buffer_pos], encrypted[i]);
+       v_n_send_data(v_con_get_network_address(), buf, buffer_pos);
+}
+
+static void v_send_hidden_connect_terminate(VNetworkAddress *address, unsigned int packet_id, const char *bye) /* Host accepts Clients connectionatempt and sends over data encryption key */
+{
+       uint8 buf[1500];
+       unsigned int buffer_pos = 0;
+       buffer_pos += vnp_raw_pack_uint32(&buf[buffer_pos], packet_id);/* Packing the packet id */
+       buffer_pos += vnp_raw_pack_uint8(&buf[buffer_pos], 2);/* Packing the command */
+       buffer_pos += vnp_raw_pack_string(&buf[buffer_pos], bye, 512); /* pack message */
+       v_e_data_encrypt_command(buf, sizeof (uint32), buf + sizeof (uint32), buffer_pos, v_con_get_data_key());
+       v_n_send_data(address, buf, buffer_pos);
+}
+
+VSession verse_send_connect(const char *name, const char *pass, const char *address, const uint8 *expected_key)
+{
+       uint8 *my_key, *key;
+       unsigned int i;
+       VNetworkAddress a; 
+       VSession *session;
+       if(v_n_set_network_address(&a, address))
+       {
+#if defined(V_PRINT_SEND_COMMANDS)
+               char ip_string[32];
+#endif
+               session = v_con_connect(a.ip, a.port, V_CS_CONTACT);
+#if defined(V_PRINT_SEND_COMMANDS)
+               v_n_get_address_string(&a, ip_string);
+               printf("send: %p = verse_send_connect(name = %s, pass = %s, address = %s (%s), expected_key = %p)\n", session, name, pass, address, ip_string, expected_key);
+#endif
+               v_con_set_name_pass(name, pass);
+               if(expected_key != NULL)
+               {
+                       key = malloc((sizeof *key) * V_ENCRYPTION_LOGIN_KEY_HALF_SIZE);
+                       for(i = 0; i < V_ENCRYPTION_LOGIN_KEY_HALF_SIZE; i++)
+                               key[i] = expected_key[i];
+                       *v_con_get_expected_key() = key;
+               }
+               my_key = v_con_get_my_key();
+               v_e_connect_create_key(&my_key[V_ENCRYPTION_LOGIN_PRIVATE_START], &my_key[V_ENCRYPTION_LOGIN_PUBLIC_START], &my_key[V_ENCRYPTION_LOGIN_N_START]);
+               v_send_hidden_connect_contact();
+               v_con_inqueue_timer_update();   /* Reset timer in connection's in queue, above takes a while. */
+               return session;
+       }
+       else
+       {
+#if defined(V_PRINT_SEND_COMMANDS)
+               printf("send: NULL = verse_send_connect(name = %s, pass = %s, address = %s (Unressolved DNS), key = %p);\n", name, pass, address, key);
+#endif
+               return NULL;
+       }
+}
+
+void v_update_connection_pending(boolean resend)
+{
+       VSession (* func_connect)(void *user_data, const char *name, const char *pass, const char *address, const uint8 *key);
+       VSession (* func_connect_accept)(void *user_data, VNodeID avatar, char *address, uint8 *host_id);
+       void (* func_connect_termanate)(void *user_data, char *address, const char *bye);
+       char address_string[32];
+
+       switch(v_con_get_connect_stage())
+       {
+       case V_CS_CONTACT :             /* client tries to contact host */
+               if(resend)
+                       v_send_hidden_connect_contact();
+               break;
+       case V_CS_CONTACTED :           /* Host replies with challange */
+               if(resend)
+                       v_send_hidden_connect_send_key();
+               break;
+       case V_CS_PENDING_ACCEPT :      /* Client sends login */
+               if(resend)
+                       v_send_hidden_connect_login();
+               break;
+       case V_CS_PENDING_HOST_CALLBACK : /* Host got login waits for accept connect callback */
+               v_con_set_connect_stage(V_CS_PENDING_DECISION);
+               func_connect = v_fs_get_user_func(0);
+               v_n_get_address_string(v_con_get_network_address(), address_string);
+#if defined(V_PRINT_RECEIVE_COMMANDS)
+               printf("receive: verse_send_connect(address = %s, name = %s, pass = %s, key = NULL); callback = %p\n", address_string, v_con_get_name(), v_con_get_pass(), func_connect);
+#endif
+               if(func_connect != 0)
+                       func_connect(v_fs_get_user_data(0), v_con_get_name(), v_con_get_pass(), address_string, NULL);
+               break;
+       case V_CS_PENDING_CLIENT_CALLBACK_ACCEPT : /* Host got login waits for accept connect callback */
+               v_con_set_connect_stage(V_CS_CONNECTED);
+               func_connect_accept = v_fs_get_user_func(1);
+               v_n_get_address_string(v_con_get_network_address(), address_string);
+#if defined(V_PRINT_RECEIVE_COMMANDS)
+               printf("receive: func_connect_accept(avatar = %u, address = %s, name = %s, pass = %s, key = NULL); callback = %p\n",
+                      verse_session_get_avatar(), address_string, v_con_get_name(), v_con_get_pass(), func_connect);
+#endif
+               if(func_connect_accept != 0)
+                       func_connect_accept(v_fs_get_user_data(1), verse_session_get_avatar(), address_string, NULL);
+               break;
+       case V_CS_PENDING_CLIENT_CALLBACK_TERMINATE : /* Host got login waits for accept connect callback */
+               v_con_set_connect_stage(V_CS_CONNECTED);
+               func_connect_termanate = v_fs_get_user_func(2);
+               v_n_get_address_string(v_con_get_network_address(), address_string);
+#if defined(V_PRINT_RECEIVE_COMMANDS)
+               printf("receive: func_connect_termanate(address = %s, bye = %s); callback = %p\n", address_string, "no message", func_connect);
+#endif
+               if(func_connect_termanate != 0)
+                       func_connect_termanate(v_fs_get_user_data(2), address_string, "no message");
+               break;
+       default:
+               ;
+       }       
+}
+
+void v_unpack_connection(const char *buf, unsigned int buffer_length) /* un packing all stages of connect command */
+{
+       unsigned int buffer_pos, i, pack_id;
+       uint32 seconds, fractions, pre;
+       uint8 /*key[V_ENCRYPTION_LOGIN_KEY_SIZE], */stage, cmd_id, version;
+
+       if(buffer_length < 5)
+               return;
+       
+       buffer_pos = vnp_raw_unpack_uint32(buf, &pack_id);
+       buffer_pos += vnp_raw_unpack_uint8(&buf[buffer_pos], &cmd_id);
+       pre = v_con_get_connect_stage();
+       if(cmd_id == 0)
+       {
+               buffer_pos += vnp_raw_unpack_uint8(&buf[buffer_pos], &stage);
+               printf(" Handling connection, stage %u\n", stage);
+               if(stage == V_CS_IDLE && V_CS_IDLE == v_con_get_connect_stage()) /* reseved by host */
+               {
+                       uint8 *other_key, *my_key;
+
+                       verse_send_packet_ack(pack_id);
+                       my_key = v_con_get_my_key();
+                       v_con_set_data_key(v_e_data_create_key());
+                       other_key = v_con_get_other_key();
+                       for(i = 0; i < V_ENCRYPTION_LOGIN_KEY_SIZE; i++)
+                               buffer_pos += vnp_raw_unpack_uint8(&buf[buffer_pos], &other_key[V_ENCRYPTION_LOGIN_PUBLIC_START + i]);/* Packing the command */
+                       for(i = 0; i < V_ENCRYPTION_LOGIN_KEY_SIZE; i++)
+                               buffer_pos += vnp_raw_unpack_uint8(&buf[buffer_pos], &other_key[V_ENCRYPTION_LOGIN_N_START + i]);/* Packing the command */
+                       v_con_set_connect_stage(V_CS_CONTACTED);
+                       v_send_hidden_connect_send_key();
+                       return; 
+               }
+               if(stage == V_CS_CONTACT && V_CS_CONTACT == v_con_get_connect_stage())
+               {
+                       uint8 *other_key; /* *host_id, *my_key, a[V_ENCRYPTION_LOGIN_KEY_SIZE], b[V_ENCRYPTION_LOGIN_KEY_SIZE];*/
+                       verse_send_packet_ack(pack_id);
+                       buffer_pos += vnp_raw_unpack_uint8(&buf[buffer_pos], &version);
+                       if(version != V_RELEASE_NUMBER)
+                       {
+                       /*      char error_message[128];
+                               func_connect_deny = v_fs_get_user_func(2);
+                               #if defined(V_PRINT_RECEIVE_COMMANDS)
+                               printf("receive: verse_send_connect_deny(Host is running version %u you are running version %u); callback = %p\n", (uint32)version, (uint32)V_RELEASE_NUMBER func_connect_deny);
+                               #endif
+                               if(func_connect_deny != NULL)
+                               {
+                                       sprintf(error_message, "Host is running version %u you are running version %u", (uint32)version, (uint32)V_RELEASE_NUMBER);
+                                       func_connect_deny(v_fs_get_user_data(2), error_message);
+                               }*/
+                               return;
+                       }
+
+                       buffer_pos += vnp_raw_unpack_uint32(&buf[buffer_pos], &seconds);
+                       buffer_pos += vnp_raw_unpack_uint32(&buf[buffer_pos], &fractions);
+                       v_con_set_time(seconds, fractions);
+
+                       other_key = v_con_get_other_key();
+                       for(i = 0; i < V_ENCRYPTION_LOGIN_KEY_SIZE; i++)
+                               buffer_pos += vnp_raw_unpack_uint8(&buf[buffer_pos], &other_key[V_ENCRYPTION_LOGIN_PUBLIC_START + i]);
+                       for(i = 0; i < V_ENCRYPTION_DATA_KEY_SIZE; i++)
+                               buffer_pos += vnp_raw_unpack_uint8(&buf[buffer_pos], &other_key[V_ENCRYPTION_LOGIN_N_START + i]);
+       
+                       v_con_set_connect_stage(V_CS_PENDING_ACCEPT);
+                       v_send_hidden_connect_login();
+                       return; 
+               }
+#if 0
+               for(i = 0; i < V_ENCRYPTION_LOGIN_KEY_HALF_SIZE && encrypted_key[i] == 0; i++);
+                       if(i < 0)
+                       {
+                               other_key = v_con_get_my_key();
+                               v_e_connect_encrypt(decrypted_key, encrypted_key, &other_key[V_ENCRYPTION_LOGIN_PUBLIC_START + i], &other_key[V_ENCRYPTION_LOGIN_N_START + i]);
+                               for(i = 0; i < V_ENCRYPTION_LOGIN_KEY_HALF_SIZE && my_key[V_ENCRYPTION_LOGIN_PUBLIC_START + i] == decrypted_key[i]; i++);
+                               if(i < 0) /* Host is not who it appers top be */
+                               {
+                                       func_connect_deny = v_fs_get_user_func(2);
+#if defined(V_PRINT_RECEIVE_COMMANDS)
+                                       printf("receive: verse_send_connect_deny(Host failed identity check); callback = %p\n", func_connect_deny);
+#endif
+                                       if(func_connect_deny != NULL)
+                                               func_connect_deny(v_fs_get_user_data(2), "Host failed identity check");
+                                       return;
+                               }
+                       }
+#endif
+               if(stage == V_CS_CONTACTED && V_CS_CONTACTED == v_con_get_connect_stage()) /* reseved by host */
+               {
+                       char *host_id, unpack[V_ENCRYPTION_LOGIN_KEY_SIZE], data[V_ENCRYPTION_LOGIN_KEY_SIZE];
+                       VNetworkAddress *address;
+                       verse_send_packet_ack(pack_id);
+                       address = v_con_get_network_address();
+                       for(i = 0; i < V_ENCRYPTION_LOGIN_KEY_SIZE; i++)
+                               buffer_pos += vnp_raw_unpack_uint8(&buf[buffer_pos], &data[i]);
+                       host_id = v_con_get_host_id();
+                       v_e_connect_encrypt(unpack, data, &host_id[V_ENCRYPTION_LOGIN_PRIVATE_START], &host_id[V_ENCRYPTION_LOGIN_N_START]);
+                       v_con_set_name_pass(unpack, &unpack[V_ENCRYPTION_LOGIN_KEY_SIZE / 2]);
+                       v_con_set_connect_stage(V_CS_PENDING_HOST_CALLBACK);
+                       return; 
+               }
+       }
+       if(cmd_id == 1 && V_CS_PENDING_ACCEPT == v_con_get_connect_stage()) /* reseved by client */
+       {
+               uint8 *my_key, key[V_ENCRYPTION_DATA_KEY_SIZE], decrypted[V_ENCRYPTION_DATA_KEY_SIZE];
+               uint32 avatar;
+               verse_send_packet_ack(pack_id);
+               buffer_pos += vnp_raw_unpack_uint32(&buf[buffer_pos], &avatar);
+               v_con_set_avatar(avatar);
+               for(i = 0; i < V_ENCRYPTION_DATA_KEY_SIZE; i++)
+                       buffer_pos += vnp_raw_unpack_uint8(&buf[buffer_pos], &key[i]);
+               my_key = v_con_get_my_key();
+               v_e_connect_encrypt(decrypted, key, &my_key[V_ENCRYPTION_LOGIN_PRIVATE_START], &my_key[V_ENCRYPTION_LOGIN_N_START]);
+               v_con_set_data_key(decrypted);
+               v_con_set_connect_stage(V_CS_PENDING_CLIENT_CALLBACK_ACCEPT);
+               v_send_hidden_connect_send_key();
+               return; 
+       }
+       if(cmd_id == 2 && V_CS_PENDING_ACCEPT == v_con_get_connect_stage()) /* reseved by client */
+       {
+               verse_send_packet_ack(pack_id); 
+       /*      buffer_pos += vnp_raw_unpack_string(&buf[buffer_pos], name, 512, buffer_length - buffer_pos);
+       */      v_con_set_connect_stage(V_CS_PENDING_CLIENT_CALLBACK_TERMINATE);
+               return; 
+       }
+}
+
+VSession verse_send_connect_accept(VNodeID avatar, const char *address, uint8 *host_id)
+{
+       VNetworkAddress a;
+#if defined(V_PRINT_SEND_COMMANDS)
+       printf("send: verse_send_connect_accept(avatar = %u, address = %s, host_id = NULL);\n", avatar, address);
+#endif
+
+       if(!v_n_set_network_address(&a, address))
+               return NULL;
+       if(v_co_switch_connection(a.ip, a.port))
+       {
+               if(v_con_get_connect_stage() != V_CS_PENDING_DECISION)
+                       return NULL;
+               v_con_set_avatar(avatar);
+               v_con_set_connect_stage(V_CS_CONNECTED);
+               v_send_hidden_connect_accept();
+               return v_con_get_network_queue();
+       }
+       return NULL;
+}
+
+void v_callback_connect_terminate(const char *bye)
+{
+       void (* func_connect_terminate)(void *user_data, char *address, const char *bye);
+       char address_string[32];
+
+       printf("terminate (%s)\n", bye);
+       func_connect_terminate = v_fs_get_user_func(2);
+       v_n_get_address_string(v_con_get_network_address(), address_string);
+#if defined(V_PRINT_RECEIVE_COMMANDS)
+       printf("receive: verse_send_connect_terminate(address = %s, bye = %s); callback = %p\n", address_string, bye, func_connect_terminate);
+#endif
+       if(func_connect_terminate != 0)
+               func_connect_terminate(v_fs_get_user_data(2), address_string, bye);
+}
+
+void verse_send_connect_terminate(const char *address, const char *bye)
+{
+       VNetworkAddress a;
+#if defined(V_PRINT_RECEIVE_COMMANDS)
+       printf("send: verse_send_connect_terminate(address = %s, bye = %s);\n", address, bye);
+#endif
+
+       if(address == NULL)
+               v_send_hidden_connect_terminate(v_con_get_network_address(), v_noq_get_next_out_packet_id(v_con_get_network_queue()), bye);
+       else if(!v_n_set_network_address(&a, address))
+               return;
+       else if(v_co_switch_connection(a.ip, a.port))
+               v_send_hidden_connect_terminate(v_con_get_network_address(), v_noq_get_next_out_packet_id(v_con_get_network_queue()), bye);
+
+       if(v_con_get_connect_stage() != V_CS_PENDING_DECISION)
+               verse_session_destroy(v_con_get_network_queue());
+}
+
+void verse_send_ping(const char *address, const char *message)
+{
+       VNetworkAddress a;
+       if(v_n_set_network_address(&a, address))
+       {
+               unsigned int buffer_pos = 0;
+               uint8 buf[1500];
+               buffer_pos += vnp_raw_pack_uint32(&buf[buffer_pos], 0);/* Packing the Packet id */
+               buffer_pos += vnp_raw_pack_uint8(&buf[buffer_pos], 5);/* Packing the command */
+#if defined V_PRINT_SEND_COMMANDS
+               printf("send: verse_send_ping(address = %s text = %s);\n", address, message);
+#endif
+               buffer_pos += vnp_raw_pack_string(&buf[buffer_pos], message, 1400);
+               v_n_send_data(&a, buf, buffer_pos);
+       }
+#if defined V_PRINT_SEND_COMMANDS
+       else
+               printf("send: verse_send_ping(address = %s (FAULTY) message = %s);\n", address, message);
+#endif
+}
+
+unsigned int v_unpack_ping(const char *buf, size_t buffer_length)
+{
+       unsigned int buffer_pos = 0;
+       void (* func_ping)(void *user_data, const char *address, const char *text);
+       char address[64];
+       char message[1400];
+
+       func_ping = v_fs_get_user_func(5);
+       v_n_get_address_string(v_con_get_network_address(), address);
+       buffer_pos += vnp_raw_unpack_string(&buf[buffer_pos], message, 1400, buffer_length - buffer_pos);
+#if defined V_PRINT_RECEIVE_COMMANDS
+       printf("receive: verse_send_ping(address = %s message = %s ); callback = %p\n", address, message, v_fs_get_user_func(5));
+#endif
+       if(func_ping != NULL)
+               func_ping(v_fs_get_user_data(5), address, message);
+       return buffer_pos;
+}
+
+typedef struct {
+       uint32  ip;
+       uint16  port;
+       char    message[1400];
+       void    *next;
+} VPingCommand;
+
+static VPingCommand *v_ping_commands = NULL;
+
+boolean v_connect_unpack_ping(const char *buf, size_t buffer_length, uint32 ip, uint16 port)
+{
+       if(buffer_length > 5)
+       {
+               unsigned int buffer_pos = 0;
+               uint8 cmd_id;
+               uint32 pack_id;
+
+               buffer_pos = vnp_raw_unpack_uint32(&buf[buffer_pos], &pack_id);
+               buffer_pos += vnp_raw_unpack_uint8(&buf[buffer_pos], &cmd_id);
+               if(cmd_id == 5)
+               {
+                       if(NULL != v_fs_get_user_func(5))
+                       {
+                               VPingCommand *pc;
+
+                               pc = malloc(sizeof *pc);
+                               pc->ip = ip;
+                               pc->port = port;
+                               vnp_raw_unpack_string(&buf[buffer_pos], pc->message,
+                                                     sizeof pc->message, buffer_length - buffer_pos);
+                               pc->next = v_ping_commands;
+                               v_ping_commands = pc;
+                       }
+                       return TRUE;
+               }
+       }
+       return FALSE;
+}
+
+void v_ping_update(void)
+{
+       VPingCommand *cp;
+       void (* func_ping)(void *user_data, const char *address, const char *text);
+       VNetworkAddress a;
+       char address[64];
+       func_ping = v_fs_get_user_func(5);
+
+       while(v_ping_commands != NULL)
+       {
+               cp = v_ping_commands->next;
+               a.ip = v_ping_commands->ip;
+               a.port = v_ping_commands->port;
+               v_n_get_address_string(&a, address);    
+#if defined V_PRINT_RECEIVE_COMMANDS
+               printf("receive: verse_send_ping(address = %s message = %s ); callback = %p\n", address, v_ping_commands->message, v_fs_get_user_func(5));
+#endif
+               if(func_ping != NULL)
+                       func_ping(v_fs_get_user_data(5), address, v_ping_commands->message);
+               free(v_ping_commands);
+               v_ping_commands = cp;
+       }
+}
+
+#endif
diff --git a/extern/verse/dist/v_connection.c b/extern/verse/dist/v_connection.c
new file mode 100644 (file)
index 0000000..f7a4c23
--- /dev/null
@@ -0,0 +1,484 @@
+/*
+**
+*/
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "v_cmd_buf.h"
+#include "v_network_in_que.h"
+#include "v_network_out_que.h"
+#include "v_cmd_gen.h"
+#include "v_connection.h"
+#include "v_encryption.h"
+#include "v_util.h"
+
+#if !defined(V_GENERATE_FUNC_MODE)
+#include "verse.h"
+
+#define CONNECTION_CHUNK_SIZE  16
+#define V_MAX_CONNECT_PACKET_SIZE      1500
+#define V_CON_MAX_MICROSECOND_BETWEEN_SENDS    100
+#define V_RE_CONNECTON_TIME_OUT 4
+#define V_CONNECTON_TIME_OUT 30
+
+typedef struct {
+       VNetOutQueue    *out_queue;
+       VNetInQueue             in_queue;
+       VNetworkAddress network_address;
+       boolean                 connected;
+       unsigned int    avatar;
+/*     unsigned int    packet_id;*/
+       int32                   timedelta_s;
+       uint32                  timedelta_f;
+       boolean                 destroy_flag;
+       void                    *ordered_storage;
+       char                    name[V_ENCRYPTION_LOGIN_KEY_SIZE / 2];
+       char                    pass[V_ENCRYPTION_LOGIN_KEY_SIZE / 2];
+       VConnectStage   connect_stage;
+       unsigned int    stage_atempts;
+       uint8                   key_my[V_ENCRYPTION_LOGIN_KEY_FULL_SIZE];
+       uint8                   key_other[V_ENCRYPTION_LOGIN_KEY_FULL_SIZE];
+       uint8                   key_data[V_ENCRYPTION_DATA_KEY_SIZE];
+       uint8                   *expected_key;
+} VConnection;
+
+static struct {
+       VConnection             *con;
+       unsigned int    con_count;
+       unsigned int    current_connection;
+       VNetworkAddress *connect_address;
+       void                    *unified_func_storage;
+       uint16                  connect_port;
+       unsigned int    pending_packets;
+       uint8                   host_id[V_ENCRYPTION_LOGIN_KEY_FULL_SIZE];
+} VConData;
+
+extern void cmd_buf_init(void);
+
+void v_con_init(void) /* since verse doesnt have an init function this function is runned over an ove ard starts whit a check it it has run before */
+{
+       static boolean v_con_initialized = FALSE;
+
+       if(v_con_initialized)
+               return;
+       cmd_buf_init();
+       v_con_initialized = TRUE;
+       VConData.con = malloc(CONNECTION_CHUNK_SIZE * sizeof *VConData.con);
+       memset(VConData.con, 0, CONNECTION_CHUNK_SIZE * sizeof *VConData.con);  /* Clear the memory. */
+       VConData.con_count = 0;
+       VConData.pending_packets = 0;
+/*     v_e_connect_create_key(&VConData.host_id[V_ENCRYPTION_LOGIN_PRIVATE_START],
+                      &VConData.host_id[V_ENCRYPTION_LOGIN_PUBLIC_START],
+                      &VConData.host_id[V_ENCRYPTION_LOGIN_N_START]);*/ /* default host id if none is set by user */
+}
+
+void verse_set_port(uint16 port)
+{
+       v_n_set_port(port);
+}
+
+void verse_host_id_create(uint8 *id)
+{
+       v_e_connect_create_key(&id[V_ENCRYPTION_LOGIN_PRIVATE_START],
+                              &id[V_ENCRYPTION_LOGIN_PUBLIC_START], &id[V_ENCRYPTION_LOGIN_N_START]);
+}
+
+void verse_host_id_set(uint8 *id)
+{
+       memcpy(VConData.host_id, id, V_ENCRYPTION_LOGIN_KEY_FULL_SIZE);
+}
+
+extern void *v_fs_create_func_storage(void);
+extern void *v_create_ordered_storage(void);
+extern void v_destroy_ordered_storage(void *data);
+
+void *v_con_connect(uint32 ip, uint16 port, VConnectStage stage) /* creates a new connection slot */
+{
+       v_con_init(); /* init connections, if not done yet */
+       if((VConData.con_count - 1) % CONNECTION_CHUNK_SIZE == 0) /* do we need more slots for connections, then reallocate more space */
+               VConData.con = realloc(VConData.con, (sizeof *VConData.con) * (VConData.con_count + CONNECTION_CHUNK_SIZE));
+       VConData.con[VConData.con_count].out_queue = v_noq_create_network_queue(); /* create a out queue fo all out going commands */
+       v_niq_clear(&VConData.con[VConData.con_count].in_queue); /* clear and init the que of incomming packets.*/
+       VConData.con[VConData.con_count].connected = FALSE; /* not yet propperly connected and should not accept commands yet */
+       VConData.con[VConData.con_count].network_address.ip = ip; /* ip address of other side */
+       VConData.con[VConData.con_count].network_address.port = port; /* port used by other side */
+       VConData.con[VConData.con_count].avatar = 0; /* no avatar set yet*/
+/*     VConData.con[VConData.con_count].packet_id = 2;*/
+       VConData.con[VConData.con_count].destroy_flag = FALSE; /* this is a flag that is set once the connection is about to be destroyed.*/
+       VConData.con[VConData.con_count].ordered_storage = v_create_ordered_storage();
+       VConData.con[VConData.con_count].name[0] = 0; /* nouser name set yet */
+       VConData.con[VConData.con_count].pass[0] = 0; /* no password set yet */
+       VConData.con[VConData.con_count].connect_stage = stage; /* this is the stage of the connection, it show if the connection is ready, the init state depends if this is a client or host */
+       VConData.con[VConData.con_count].stage_atempts = 0; /* each stage in the connection prosess is atempted multiple times to avoid failiure if packets get lost*/
+       VConData.con[VConData.con_count].timedelta_s = 0; /* number of seconds since last incomming packet to the connection*/
+       VConData.con[VConData.con_count].timedelta_f = 0; /* number of fractions of a second since last incomming packet to the connection*/
+       VConData.con[VConData.con_count].expected_key = NULL; /* expected hist id if this is a client */
+       VConData.current_connection = VConData.con_count; /* set the new connection to the current*/
+       ++VConData.con_count; /* add one to the number of connections*/
+       return VConData.con[VConData.current_connection].out_queue;
+}
+
+void verse_session_destroy(VSession session) /* a session can not be destroyed right away, because this function might be called inside a call back from the session it tryes tpo destroy, therfor it only markes it*/
+{
+       unsigned int i;
+       for(i = 0; i < VConData.con_count && VConData.con[i].out_queue != session; i++);
+       if(i < VConData.con_count)
+       {
+               VConData.con[i].destroy_flag = TRUE;
+       }
+}
+
+void verse_session_set(VSession session) /* find a session and make it the current*/
+{
+       unsigned int i;
+       for(i = 0; i < VConData.con_count && session != VConData.con[i].out_queue; i++);
+       if(i < VConData.con_count)
+               VConData.current_connection = i;
+}
+
+VSession verse_session_get(void)
+{
+       if(VConData.current_connection < VConData.con_count)
+               return VConData.con[VConData.current_connection].out_queue;
+       return NULL;
+}
+
+uint32 v_co_find_connection(uint32 ip, uint16 port) /* if a packet comes form a ip address what connection does it belong to? */
+{
+       unsigned int i;
+
+       for(i = 0; i < VConData.con_count; i++)
+       {
+               if(ip == VConData.con[i].network_address.ip &&
+                  port == VConData.con[i].network_address.port &&
+                  VConData.con[i].destroy_flag == 0)
+               {
+                       return i;
+               }
+       }
+       return -1;
+}
+
+boolean v_co_switch_connection(uint32 ip, uint16 port) /* switches to the current connection to one ip address if it exists */
+{
+       unsigned int i;
+       for(i = 0; i < VConData.con_count; i++)
+       {
+               if(ip == VConData.con[i].network_address.ip && port == VConData.con[i].network_address.port)
+               {
+                       VConData.current_connection = i;
+                       return TRUE;
+               }
+       }
+       return FALSE;
+}
+
+void v_con_inqueue_timer_update(void)
+{
+       if(VConData.current_connection < VConData.con_count)
+       {
+               v_niq_timer_update(&VConData.con[VConData.current_connection].in_queue);
+       }
+}
+
+/*
+extern void    v_fs_buf_unpack(const uint8 *data, unsigned int length);
+extern void    v_fs_buf_store_pack(uint8 *data, unsigned int length);
+extern boolean v_fs_buf_unpack_stored(void);
+*/
+extern void v_unpack_connection(const char *buf, unsigned int buffer_length);
+
+extern void    verse_send_packet_nak(uint32 packet_id);
+extern void    v_callback_connect_terminate(const char *bye);
+extern boolean v_connect_unpack_ping(const char *buf, size_t buffer_length, uint32 ip, uint16 port);
+extern void    v_ping_update(void);
+void v_fs_unpack_beginning(uint8 *data, unsigned int length);
+
+/* Main function that receives and distributes all incoming packets. */
+boolean v_con_network_listen(void)
+{
+       VNetworkAddress address;
+       uint8 buf[V_MAX_CONNECT_PACKET_SIZE], *store;
+       int size = 0;
+       unsigned int connection;
+       uint32 packet_id;
+       boolean ret = FALSE;
+
+       v_con_init(); /* Init if needed. */
+       connection = VConData.current_connection; /* Store current connection in a local variable so that we can restore it later. */
+       size = v_n_receive_data(&address, buf, sizeof buf); /* Ask for incoming data from the network. */
+       while(size != -1 && size != 0) /* Did we get any data? */
+       {
+               VConData.current_connection = v_co_find_connection(address.ip, address.port); /* Is there a connection matching the IP and port? */
+               vnp_raw_unpack_uint32(buf, &packet_id); /* Unpack the ID of the packet. */
+/*             printf("got packet ID %u, %d bytes, connection %u\n", packet_id, size, VConData.current_connection);*/
+               if(VConData.current_connection < VConData.con_count &&
+                  !(VConData.con[VConData.current_connection].connect_stage == V_CS_CONNECTED && packet_id == 0)) /* If this isn't a packet from an existing connection, disregard it. */
+               {
+                       if(VConData.con[VConData.current_connection].connect_stage == V_CS_CONNECTED) /* Is this connection initialized? */
+                       {
+                               store = v_niq_store(&VConData.con[VConData.current_connection].in_queue, size, packet_id); /* Store the packet. */
+                               if(store != NULL)
+                               {
+                                       VConData.pending_packets++; /* We now have one more packet pending unpack. */
+                                       v_e_data_decrypt_packet(store, buf, size, VConData.con[VConData.current_connection].key_data); /* Decrypt the packet. */
+                                       v_fs_unpack_beginning(store, size);
+                               }
+                       }
+                       else
+                       {
+                               v_unpack_connection(buf, size); /* This is an ongoing connecton-attempt. */
+                               v_niq_timer_update(&VConData.con[VConData.current_connection].in_queue);
+                       }
+               }
+               else if(v_connect_unpack_ping(buf, size, address.ip, address.port))     /* Ping handled. */
+                       ;
+               else if(v_fs_func_accept_connections()) /* Do we accept connection-attempts? */
+               {
+                       if(VConData.current_connection >= VConData.con_count ||
+                          V_RE_CONNECTON_TIME_OUT < v_niq_time_out(&VConData.con[VConData.current_connection].in_queue)) /* Is it a new client, or an old client that we haven't heard form in some time? */
+                       {
+                               if(VConData.current_connection < VConData.con_count)
+                               {
+                                       VConData.con[VConData.current_connection].network_address.ip = 0;
+                                       VConData.con[VConData.current_connection].destroy_flag = TRUE; /* Destroy old connection if there is one. */
+                               }
+                               v_con_connect(address.ip, address.port, V_CS_IDLE); /* Create a new connection. */
+                               v_unpack_connection(buf, size); /* Unpack the connection-attempt. */
+                       }
+               }
+               else
+               {
+                       fprintf(stderr, __FILE__ ": Unhandled packet--dropping\n");
+                       fprintf(stderr, __FILE__ ": State: current=%u count=%u stage=%d id=%u\n",
+                              VConData.current_connection,
+                              VConData.con_count,
+                              VConData.con[VConData.current_connection].connect_stage,
+                              packet_id);
+               }
+               size = v_n_receive_data(&address, buf, sizeof buf); /* See if there are more incoming packets. */
+               ret = TRUE;
+       }
+       VConData.current_connection = connection; /* Reset the current connection. */
+
+       return ret;
+}
+
+extern void    v_update_connection_pending(boolean resend);
+
+boolean v_con_callback_update(void)
+{
+       static unsigned int seconds;
+       boolean output = FALSE;
+       unsigned int    size, connection, s;
+       VNetInPacked    *p;
+
+       v_n_get_current_time(&s, NULL);
+       connection = VConData.current_connection;
+       for(VConData.current_connection = 0; VConData.current_connection < VConData.con_count; VConData.current_connection++)
+               if(VConData.con[VConData.current_connection].connect_stage != V_CS_CONNECTED)
+                       v_update_connection_pending(s != seconds);
+       seconds = s;
+       VConData.current_connection = connection;
+       if(VConData.pending_packets == 0)
+               return FALSE;
+       if(VConData.con[VConData.current_connection].connect_stage == V_CS_CONNECTED)
+       {
+               while((p = v_niq_get(&VConData.con[VConData.current_connection].in_queue, &size)) != NULL)
+               {
+                       VConData.pending_packets--;
+                       v_fs_unpack(p->data, size);
+                       v_niq_release(&VConData.con[VConData.current_connection].in_queue, p);
+                       output = TRUE;
+               }
+               v_con_network_listen();
+       }
+       return output;
+}
+
+void verse_callback_update(unsigned int microseconds)
+{
+       unsigned int connection, passed;
+
+       v_ping_update();        /* Deliver any pending pings. */
+       connection = VConData.current_connection;
+       for(VConData.current_connection = 0; VConData.current_connection < VConData.con_count; VConData.current_connection++)
+       {
+               if(VConData.con[VConData.current_connection].connect_stage == V_CS_CONNECTED)
+                       v_noq_send_queue(VConData.con[VConData.current_connection].out_queue, &VConData.con[VConData.current_connection].network_address);
+               if(VConData.con[VConData.current_connection].destroy_flag == TRUE)
+               {
+                       v_noq_destroy_network_queue(VConData.con[VConData.current_connection].out_queue);
+                       VConData.pending_packets -= v_niq_free(&VConData.con[VConData.current_connection].in_queue);
+                       v_destroy_ordered_storage(VConData.con[VConData.current_connection].ordered_storage);
+                       if(VConData.con[VConData.current_connection].expected_key != NULL)
+                               free(VConData.con[VConData.current_connection].expected_key);
+                       VConData.con[VConData.current_connection] = VConData.con[--VConData.con_count];
+                       if(connection >= VConData.con_count)
+                               VConData.current_connection = 0;
+                       return;
+               }
+       }
+       VConData.current_connection = connection;
+
+       if(VConData.con_count > 0)
+       {
+/*             printf("checking timeout of stage %d connection %u\n",
+                      VConData.con[VConData.current_connection].connect_stage, VConData.current_connection);
+*/             if(V_CONNECTON_TIME_OUT < v_niq_time_out(&VConData.con[VConData.current_connection].in_queue))
+               {
+                       if(VConData.con[VConData.current_connection].connect_stage != V_CS_CONNECTED)
+                       {
+                               VConData.con[VConData.current_connection].destroy_flag = TRUE;
+                       }
+                       else
+                               v_callback_connect_terminate("connection timed out");
+               }
+       }
+
+       v_con_network_listen();
+       if(VConData.con_count > 0)
+               if(v_con_callback_update())
+                       return;
+       for(passed = 0; passed < microseconds && VConData.pending_packets == 0;)
+       {
+               boolean update;
+               if(microseconds - passed > V_CON_MAX_MICROSECOND_BETWEEN_SENDS) /* Still a long way to go? */
+                       passed += v_n_wait_for_incoming(V_CON_MAX_MICROSECOND_BETWEEN_SENDS);
+               else
+                       passed += v_n_wait_for_incoming(microseconds - passed);
+               do
+               {
+                       update = v_con_network_listen();
+                       connection = VConData.current_connection;
+                       for(VConData.current_connection = 0; VConData.current_connection < VConData.con_count; VConData.current_connection++)
+                       {
+                               if(VConData.con[VConData.current_connection].connect_stage == V_CS_CONNECTED)
+                               {
+                                       if(v_noq_send_queue(VConData.con[VConData.current_connection].out_queue, &VConData.con[VConData.current_connection].network_address))
+                                               update = TRUE;
+                               }
+                       }
+                       VConData.current_connection = connection;
+               } while(update);
+       }
+       if(VConData.con_count > 0)
+               v_con_callback_update();
+}
+
+void v_con_set_name_pass(const char *name, const char *pass)
+{
+       v_strlcpy(VConData.con[VConData.current_connection].name, name, sizeof VConData.con[VConData.current_connection].name);
+       v_strlcpy(VConData.con[VConData.current_connection].pass, pass, sizeof VConData.con[VConData.current_connection].pass);
+}
+
+const char * v_con_get_name(void)
+{
+       return VConData.con[VConData.current_connection].name;
+}
+
+const char * v_con_get_pass(void)
+{
+       return VConData.con[VConData.current_connection].pass;
+}
+
+void v_con_set_connect_stage(VConnectStage stage)
+{
+       VConData.con[VConData.current_connection].connect_stage = stage;
+       VConData.con[VConData.current_connection].stage_atempts = 0;
+}
+
+VConnectStage v_con_get_connect_stage(void)
+{
+       return VConData.con[VConData.current_connection].connect_stage;
+}
+
+uint8 *v_con_get_my_key(void)
+{
+       return VConData.con[VConData.current_connection].key_my;
+}
+
+uint8 *v_con_get_other_key(void)
+{
+       return VConData.con[VConData.current_connection].key_other;
+}
+
+uint8 **v_con_get_expected_key(void)
+{
+       return &VConData.con[VConData.current_connection].expected_key;
+}
+
+uint8 * v_con_get_host_id(void)
+{
+       return VConData.host_id;
+}
+
+void v_con_set_data_key(const uint8 *key)
+{
+       memcpy(VConData.con[VConData.current_connection].key_data, key, V_ENCRYPTION_DATA_KEY_SIZE);
+}
+
+const uint8 * v_con_get_data_key(void)
+{
+       return VConData.con[VConData.current_connection].key_data;
+}
+
+void * v_con_get_network_queue(void)
+{
+       return VConData.con[VConData.current_connection].out_queue;
+}
+
+VNetworkAddress * v_con_get_network_address(void)
+{
+       return &VConData.con[VConData.current_connection].network_address;
+}
+
+void * v_con_get_ordered_storage(void)
+{
+       return VConData.con[VConData.current_connection].ordered_storage;
+}
+
+void v_con_set_avatar(uint32 avatar)
+{
+       VConData.con[VConData.current_connection].avatar = avatar;
+}
+
+uint32 verse_session_get_avatar(void)
+{
+       return VConData.con[VConData.current_connection].avatar;
+}
+
+void verse_session_get_time(uint32 *seconds, uint32 *fractions)
+{
+       uint32 s, f;
+       v_n_get_current_time(&s, &f);
+       if((uint32)~0 - f < VConData.con[VConData.current_connection].timedelta_f)
+               s++;
+       if(seconds != NULL) 
+       {
+               if(VConData.con[VConData.current_connection].timedelta_s < 0)
+                       *seconds = s - (uint32)(-VConData.con[VConData.current_connection].timedelta_s);
+               else
+                       *seconds = s + VConData.con[VConData.current_connection].timedelta_s;
+       }
+       if(fractions != NULL)
+               *fractions = f + VConData.con[VConData.current_connection].timedelta_f;
+}
+
+void v_con_set_time(uint32 seconds, uint32 fractions)
+{
+       uint32 s, f;
+       v_n_get_current_time(&s, &f);
+
+       if(f < fractions)
+               s--;
+       if (s < seconds)
+               VConData.con[VConData.current_connection].timedelta_s = -(int)(seconds - s);
+       else
+               VConData.con[VConData.current_connection].timedelta_s = (int)(s - seconds);
+       VConData.con[VConData.current_connection].timedelta_f = f - fractions;
+}
+
+#endif
diff --git a/extern/verse/dist/v_connection.h b/extern/verse/dist/v_connection.h
new file mode 100644 (file)
index 0000000..1d2ac53
--- /dev/null
@@ -0,0 +1,73 @@
+/*
+**
+*/
+
+#include "v_network.h"
+
+typedef struct{
+       char    name[16];
+       char    pass[16];
+       uint8   key;
+       VNodeID avatar;
+}VSConnectionID;
+
+typedef enum{
+       V_CS_IDLE = 0, /* Host connection waiting for connection */
+       V_CS_CONTACT = 1, /* client tryes to contact host */
+       V_CS_CONTACTED = 2, /* Host replyes whit challange */
+       V_CS_PENDING_ACCEPT = 3, /* Client sends login */
+       V_CS_PENDING_HOST_CALLBACK = 4, /* Host got login waits for accept connect callback */
+       V_CS_PENDING_CLIENT_CALLBACK_ACCEPT = 5, /* Host got login waits for accept connect callback */
+       V_CS_PENDING_CLIENT_CALLBACK_TERMINATE = 6, /* Host got login waits for connect terminate callback */
+       V_CS_PENDING_DECISION = 7, /* Host got has executed Callback waits for accept command */
+       V_CS_CONNECTED = 8 /* Connection establiched */
+}VConnectStage;
+
+/* Connection related functions (v_connection.c) */
+
+extern boolean                         v_con_network_listen(void);
+
+extern void                            v_con_set_name_pass(const char *name, const char *pass);
+extern const char *                    v_con_get_name(void);
+extern const char *                    v_con_get_pass(void);
+
+extern void                            v_con_set_avatar(uint32 avatar);
+extern void                            v_con_set_time(uint32 seconds, uint32 fractions);
+
+extern void                            v_con_set_connect_stage(VConnectStage stage);
+extern VConnectStage   v_con_get_connect_stage(void);
+
+
+extern uint8                   *v_con_get_my_key(void);
+extern uint8                   *v_con_get_other_key(void);
+extern uint8                   *v_con_get_host_id(void);
+extern uint8                   **v_con_get_expected_key(void);
+
+extern void                            v_con_set_data_key(const uint8 *key);
+extern const uint8 *                   v_con_get_data_key(void);
+
+
+extern void *                  v_con_get_network_queue(void);
+extern VNetworkAddress *v_con_get_network_address(void);
+extern void *                  v_con_get_network_address_id(unsigned int id);
+extern unsigned int *  v_con_get_network_expected_packet(void);
+extern void *                  v_con_get_ordered_storage(void);
+extern void *                  v_con_get_func_storage(void);
+extern void *                  v_con_connect(uint32 ip, uint16 port, VConnectStage stage);
+extern unsigned int            v_con_get_network_address_count(void);
+
+extern boolean                 v_co_switch_connection(uint32 ip, uint16 port);
+
+extern void                    v_con_inqueue_timer_update(void);
+
+
+/* Func storage related functions (v_func_storage.c)*/
+extern void                            v_fs_unpack(uint8 *data, unsigned int length);
+
+extern boolean                 v_fs_func_accept_connections(void);
+extern void                            v_fs_add_func(unsigned int cmd_id, unsigned int (*unpack_func)(const char *buf, size_t buffer_length), void *pack_func, void *alias_func);
+
+extern void *                  v_fs_get_alias_user_func(unsigned int cmd_id);
+extern void *                  v_fs_get_alias_user_data(unsigned int cmd_id);
+extern void *                  v_fs_get_user_func(unsigned int cmd_id);
+extern void *                  v_fs_get_user_data(unsigned int cmd_id);
diff --git a/extern/verse/dist/v_encryption.c b/extern/verse/dist/v_encryption.c
new file mode 100644 (file)
index 0000000..aea0f8e
--- /dev/null
@@ -0,0 +1,255 @@
+/*
+ * Verse encryption routines. Implements RSA encryption/decryption plus fast XORx.
+*/
+
+#if !defined(V_GENERATE_FUNC_MODE)
+
+#include <ctype.h>
+#include <stdio.h>
+#include <string.h>
+
+#include "verse.h"
+#include "v_pack.h"
+#include "v_bignum.h"
+#include "v_encryption.h"
+
+#define        BITS    V_ENCRYPTION_LOGIN_KEY_BITS     /* Save some typing. */
+
+extern void    v_prime_set_random(VBigDig *x);
+extern void    v_prime_set_table(VBigDig *x, int i);
+
+const uint8 * v_e_data_create_key(void) /* possibly the worst key gen ever */
+{
+       static unsigned int counter = 0;
+       static uint8    buffer[V_ENCRYPTION_DATA_KEY_SIZE];
+       unsigned int    i, temp;
+
+       for(i = 0; i < V_ENCRYPTION_DATA_KEY_SIZE; i++) 
+       {
+               counter++;
+               temp = (counter << 13) ^ counter;
+               temp = (temp * (temp * temp * 15731 + 789221) + 1376312589) & 0x7fffffff;
+               buffer[i] = temp;
+       }
+       /* FIXME: This really isn't very pretty. */
+       buffer[0] &= 0x3f;      /* Make sure top word is... Low. For RSA compatibility. */
+
+/*     memset(buffer, 0, sizeof buffer);
+       fprintf(stderr, "**WARNING: XOR data encryption disabled\n");
+*/
+       return buffer;
+}
+
+void v_e_data_encrypt_command(uint8 *packet, size_t packet_size, const uint8 *command, size_t command_size, const uint8 *key)
+{
+       uint32  pos, i;
+
+       vnp_raw_unpack_uint32(packet, &pos);
+/*     printf("encrypting packet %u", pos);*/
+       pos = key[pos % V_ENCRYPTION_DATA_KEY_SIZE] + packet_size;
+/*     printf(" -> pos=%u (size %u)", pos, packet_size);
+       printf(", key begins: [");
+       for(i = 0; i < 16; i++)
+               printf(" %02X", key[(pos + i) % V_ENCRYPTION_DATA_KEY_SIZE]);
+       printf(" ]\n");
+*/
+       for(i = 0; i < command_size; i++)
+               packet[packet_size + i] = command[i] ^ key[(i + pos) % V_ENCRYPTION_DATA_KEY_SIZE];
+}
+
+void v_e_data_decrypt_packet(uint8 *to, const uint8 *from, size_t size, const uint8 *key)
+{
+       uint32  pos, i;
+
+       vnp_raw_unpack_uint32(from, &pos);
+/*     printf("decrypting packet %u", pos);*/
+       pos = key[pos % V_ENCRYPTION_DATA_KEY_SIZE];
+/*     printf(" -> pos=%u", pos);
+       printf(", key begins: [");
+       for(i = 0; i < 16; i++)
+               printf(" %02X", key[(i + pos) % V_ENCRYPTION_DATA_KEY_SIZE]);
+       printf(" ]\n");
+*/     for(i = 0; i < 4; i++)
+               to[i] = from[i];
+       for(i = 4; i < size; i++)
+               to[i] = from[i] ^ key[(i + pos) % V_ENCRYPTION_DATA_KEY_SIZE];
+}
+
+#endif
+
+/* From Knuth. Computes multiplicative inverse of u, modulo v. */
+void v_e_math_inv(VBigDig *inv, const VBigDig *u, const VBigDig *v)
+{
+       VBigDig VBIGNUM(u1, 2*BITS), VBIGNUM(u3, 2*BITS), VBIGNUM(v1, 2*BITS), VBIGNUM(v3, 2 *BITS),
+               VBIGNUM(t1, 2*BITS), VBIGNUM(t3, 2*BITS), VBIGNUM(q, 2*BITS),  VBIGNUM(w, 2*BITS);
+       int     iter = 1;
+
+       v_bignum_set_one(u1);
+       v_bignum_set_bignum(u3, u);
+       v_bignum_set_zero(v1);
+       v_bignum_set_bignum(v3, v);
+
+       while(!v_bignum_eq_zero(v3))
+       {
+               v_bignum_set_bignum(q, u3);
+               v_bignum_div(q, v3, t3);
+               v_bignum_set_bignum(w, q);
+               v_bignum_mul(w, v1);
+               v_bignum_set_bignum(t1, u1);
+               v_bignum_add(t1, w);
+
+               v_bignum_set_bignum(u1, v1);
+               v_bignum_set_bignum(v1, t1);
+               v_bignum_set_bignum(u3, v3);
+               v_bignum_set_bignum(v3, t3);
+               iter = -iter;
+       }
+       if(iter < 0)
+       {
+               v_bignum_set_bignum(inv, v);
+               v_bignum_sub(inv, u1);
+       }
+       else
+               v_bignum_set_bignum(inv, u1);
+}
+
+void v_e_connect_create_key(uint8 *private_key, uint8 *public_key, uint8 *n)
+{
+       VBigDig VBIGNUM(p, BITS / 2), VBIGNUM(q, BITS / 2), VBIGNUM(qmo, BITS / 2), VBIGNUM(phi, BITS),
+               VBIGNUM(pub, BITS), VBIGNUM(priv, BITS), VBIGNUM(mod, BITS);
+
+#if !defined _WIN32
+       /* FIXME: This is a security backdoor. Intent is simply to save time during testing. */
+       if(getenv("VERSE_NORSA") != NULL)
+       {
+               printf("VERSE: Found the NORSA envvar, using constant keys\n");
+               v_prime_set_table(p, 0);
+               v_prime_set_table(q, 1);
+               goto compute_phi;
+       }
+#endif
+/*     printf("find prime p\n");*/
+       v_prime_set_random(p);
+/*     printf("find prime q\n");*/
+       v_prime_set_random(q);
+compute_phi:
+/*     printf("done, computing key\n");*/
+/*     printf("p=");
+       v_bignum_print_hex_lf(p);
+       printf("q=");
+       v_bignum_print_hex_lf(q);
+*/     v_bignum_set_bignum(phi, p);
+       v_bignum_sub_digit(phi, 1);
+       v_bignum_set_bignum(qmo, q);
+       v_bignum_sub_digit(qmo, 1);
+       v_bignum_mul(phi, qmo);
+/*     printf("phi=");
+       v_bignum_print_hex_lf(phi);
+*/     v_bignum_set_string_hex(pub, "0x10001");
+       v_e_math_inv(priv, pub, phi);
+/*     printf(" pub=");
+       v_bignum_print_hex_lf(pub);
+       printf("priv=");
+       v_bignum_print_hex_lf(priv);
+*/
+       v_bignum_set_bignum(mod, p);
+       v_bignum_mul(mod, q);
+/*     printf(" mod=");
+       v_bignum_print_hex_lf(mod);
+       printf("key-creation finished\n");
+*/     /* Write out the keys. */
+       v_bignum_raw_export(pub, public_key);
+       v_bignum_raw_export(priv, private_key);
+       v_bignum_raw_export(mod, n);
+}
+
+void v_e_connect_encrypt(uint8 *output, const uint8 *data, const uint8 *key, const uint8 *key_n)
+{
+       VBigDig VBIGNUM(packet, BITS), VBIGNUM(expo, BITS), VBIGNUM(mod, BITS);
+
+       v_bignum_raw_import(packet, data);
+       v_bignum_raw_import(expo, key);
+       v_bignum_raw_import(mod, key_n);
+
+       /* Verify that data is less than the modulo, this is a prerequisite for encryption. */
+       if(!v_bignum_gte(mod, packet))
+       {
+               printf("*** WARNING. Data is not less than modulo, as it should be--encryption will break!\n");
+               printf(" RSA modulo: ");
+               v_bignum_print_hex_lf(mod);
+               printf("   RSA data: ");
+               v_bignum_print_hex_lf(packet);
+       }
+/*     printf("RSA key: ");
+       v_bignum_print_hex_lf(expo);
+       printf("RSA mod: ");
+       v_bignum_print_hex_lf(mod);
+       printf("RSA in:  ");
+       v_bignum_print_hex_lf(packet);
+       printf("bits in packet: %d, ", v_bignum_bit_msb(packet) + 1);
+       printf("bits in modulo: %d\n", v_bignum_bit_msb(mod) + 1);
+*/     v_bignum_pow_mod(packet, expo, mod);    /* Blam. */
+/*     printf("RSA out: ");
+       v_bignum_print_hex_lf(packet);
+*/     v_bignum_raw_export(packet, output);
+}
+
+#if defined CRYPTALONE
+void v_encrypt_test(void)
+{
+       uint8   k_priv[BITS / 8], k_pub[BITS / 8], k_n[BITS / 8], cipher[BITS / 8], plain[BITS / 8], decode[BITS / 8], i;
+
+       printf("testing RSA-crypto\n");
+       v_e_connect_create_key(k_pub, k_priv, k_n);
+/*     exit(0);*/
+       printf("key pair generated, encrypting something\n");
+       memset(plain, 0, sizeof plain);
+       strcpy(plain, "This is some text to encrypt, to give it something to chew on.");
+       printf("plain: %02X (%u)\n", plain[0], strlen(plain));
+       v_e_connect_encrypt(cipher, plain, k_pub, k_n);
+       printf("plain: %02X, cipher: %02X\n", plain[0], cipher[0]);
+       v_e_connect_encrypt(decode, cipher, k_priv, k_n);
+       printf("decoded: %02X: '", decode[0]);
+       for(i = 0; decode[i] != 0; i++)
+               putchar(decode[i]);
+       printf("'\n");
+/*     printf("\npublic key: ");
+       v_bignum_print_hex_lf(k_public);
+       printf("private key: ");
+       v_bignum_print_hex_lf(k_private);
+       v_bignum_set_string(msg, "123");
+       gettimeofday(&t1, NULL);
+       v_bignum_pow_mod(msg, k_private, k_n);
+       gettimeofday(&t2, NULL);
+       printf("encrypted: ");
+       v_bignum_print_hex_lf(msg);
+       printf("encrypted %u bits in %g s\n", BITS, t2.tv_sec - t1.tv_sec + 1.0E-6 * (t2.tv_usec - t1.tv_usec));
+
+       gettimeofday(&t1, NULL);
+       v_bignum_pow_mod(msg, k_public, k_n);
+       gettimeofday(&t2, NULL);
+       printf("decrypted: ");
+       v_bignum_print_hex_lf(msg);
+       printf("decrypted %u bits in %g s\n", BITS, t2.tv_sec - t1.tv_sec + 1.0E-6 * (t2.tv_usec - t1.tv_usec));
+       exit(0);
+*//*   v_e_encrypt(cipher, plain, &k_private, &k_n);
+       printf("encrypted data: ");
+       for(i = 0; i < sizeof cipher; i++)
+               printf("%c", isalnum(cipher[i]) ? cipher[i] : '?');
+       printf("\n\n");
+       printf("decrypting\n");
+       v_e_encrypt(decode, cipher, &k_public, &k_n);
+       printf("decrypted data: ");
+       for(i = 0; i < sizeof cipher; i++)
+               printf("%c", isalnum(decode[i]) ? decode[i] : '?');
+       printf("\n\n");
+*/
+}
+
+int main(void)
+{
+       v_encrypt_test();
+
+       return 0;
+}
+#endif
diff --git a/extern/verse/dist/v_encryption.h b/extern/verse/dist/v_encryption.h
new file mode 100644 (file)
index 0000000..cbfb5ff
--- /dev/null
@@ -0,0 +1,32 @@
+/*
+ * Verse encryption routines. There are two distinct flavors of encryption
+ * in use: one "heavy" for login/connection establishment security, and
+ * a far lighter symmetrical one that is applied to each data packet after
+ * the key has been exchanged during connection.
+*/
+
+#include "verse.h"
+
+/* Internal key size definitions. *MUST* be kept in sync with V_HOST_ID_SIZE in verse_header.h! */
+#define        V_ENCRYPTION_LOGIN_KEY_BITS      512
+#define V_ENCRYPTION_LOGIN_KEY_SIZE     (V_ENCRYPTION_LOGIN_KEY_BITS / 8)
+#define V_ENCRYPTION_LOGIN_KEY_FULL_SIZE (3 * V_ENCRYPTION_LOGIN_KEY_SIZE)
+#define V_ENCRYPTION_LOGIN_KEY_HALF_SIZE (2 * V_ENCRYPTION_LOGIN_KEY_SIZE)
+
+#define V_ENCRYPTION_LOGIN_PUBLIC_START         (0 * V_ENCRYPTION_LOGIN_KEY_SIZE)
+#define V_ENCRYPTION_LOGIN_PRIVATE_START (1 * V_ENCRYPTION_LOGIN_KEY_SIZE)
+#define V_ENCRYPTION_LOGIN_N_START      (2 * V_ENCRYPTION_LOGIN_KEY_SIZE)
+
+#define V_ENCRYPTION_DATA_KEY_SIZE      (V_ENCRYPTION_LOGIN_KEY_BITS / 8)
+
+/* Connection encryption. Heavy, and symmetrical, so encrypt() does both encryption
+ * and decryption given the proper key. Current algorithm used is RSA.
+*/
+extern void v_e_connect_create_key(uint8 *private_key, uint8 *public_key, uint8 *n);
+extern void v_e_connect_encrypt(uint8 *output, const uint8 *data, const uint8 *key, const uint8 *key_n);
+
+/* Actual data traffic encryption. Also symmetrical, with a single key. Uses XOR. */
+extern const uint8 *   v_e_data_create_key(void);
+extern void            v_e_data_encrypt_command(uint8 *packet, size_t packet_length,
+                                                const uint8 *command, size_t command_length, const uint8 *key);
+extern void            v_e_data_decrypt_packet(uint8 *to, const uint8 *from, size_t size, const uint8 *key);
diff --git a/extern/verse/dist/v_func_storage.c b/extern/verse/dist/v_func_storage.c
new file mode 100644 (file)
index 0000000..86c7815
--- /dev/null
@@ -0,0 +1,194 @@
+/*
+ * 
+*/
+
+#include <stdio.h>
+#include <stdlib.h>
+#include "verse_header.h"
+#include "v_pack.h"
+#include "v_cmd_gen.h"
+#include "v_connection.h"
+#if !defined(V_GENERATE_FUNC_MODE)
+#include "verse.h"
+#include "v_cmd_buf.h"
+#include "v_network_out_que.h"
+
+#define V_FS_MAX_CMDS  256
+
+extern void init_pack_and_unpack(void);
+
+static struct {
+       unsigned int    (*unpack_func[V_FS_MAX_CMDS])(const char *data, size_t length);
+       void            *pack_func[V_FS_MAX_CMDS];
+       void            *user_func[V_FS_MAX_CMDS];
+       void            *user_data[V_FS_MAX_CMDS];
+       void            *alias_pack_func[V_FS_MAX_CMDS];
+       void            *alias_user_func[V_FS_MAX_CMDS];
+       void            *alias_user_data[V_FS_MAX_CMDS];
+       boolean         call;
+} VCmdData;
+
+static boolean v_fs_initialized = FALSE;
+
+extern void verse_send_packet_ack(uint32 packet_id);
+extern void callback_send_packet_ack(void *user, uint32 packet_id);
+extern void verse_send_packet_nak(uint32 packet_id);
+extern void callback_send_packet_nak(void *user, uint32 packet_id);
+
+void v_fs_init(void)
+{
+       unsigned int i;
+       if(v_fs_initialized)
+               return;
+       for(i = 0; i < V_FS_MAX_CMDS; i++)
+       {
+               VCmdData.unpack_func[i] = NULL;
+               VCmdData.pack_func[i] = NULL;
+               VCmdData.user_func[i] = NULL;
+               VCmdData.user_data[i] = NULL;
+               VCmdData.alias_pack_func[i] = NULL;
+               VCmdData.alias_user_func[i] = NULL;
+               VCmdData.alias_user_data[i] = NULL;
+       }
+       #if !defined(V_GENERATE_FUNC_MODE)
+       init_pack_and_unpack();
+       #endif
+       for(i = 0; i < V_FS_MAX_CMDS && VCmdData.pack_func[i] != verse_send_packet_ack; i++);
+       VCmdData.user_func[i] = callback_send_packet_ack;
+       for(i = 0; i < V_FS_MAX_CMDS && VCmdData.pack_func[i] != verse_send_packet_nak; i++);
+       VCmdData.user_func[i] = callback_send_packet_nak;
+
+       v_fs_initialized = TRUE;
+}
+
+
+void v_fs_add_func(unsigned int cmd_id, unsigned int (*unpack_func)(const char *data, size_t length), void *pack_func, void *alias_func)
+{
+       VCmdData.unpack_func[cmd_id] = unpack_func;
+       VCmdData.pack_func[cmd_id] = pack_func;
+       VCmdData.alias_pack_func[cmd_id] = alias_func;
+}
+
+void *v_fs_get_user_func(unsigned int cmd_id)
+{
+/*     if(VCmdData.call)*/
+               return VCmdData.user_func[cmd_id];
+       return NULL;
+}
+
+void *v_fs_get_user_data(unsigned int cmd_id)
+{
+       return VCmdData.user_data[cmd_id];
+}
+
+void *v_fs_get_alias_user_func(unsigned int cmd_id)
+{
+/*     if(VCmdData.call)*/
+               return VCmdData.alias_user_func[cmd_id];
+       return NULL;
+}
+
+void *v_fs_get_alias_user_data(unsigned int cmd_id)
+{
+       return VCmdData.alias_user_data[cmd_id];
+}
+
+void verse_callback_set(void *command, void *callback, void *user)
+{
+       unsigned int i;
+       if(!v_fs_initialized)
+               v_fs_init();
+
+       for(i = 0; i < V_FS_MAX_CMDS; i++)
+       {
+               if(VCmdData.pack_func[i] == command)
+               {
+                       VCmdData.user_data[i] = user;
+                       VCmdData.user_func[i] = callback;
+                       return;
+               }
+               if(VCmdData.alias_pack_func[i] == command)
+               {
+                       VCmdData.alias_user_data[i] = user;
+                       VCmdData.alias_user_func[i] = callback;
+                       return;
+               }
+       }
+}
+
+/* Do we accept incoming connections, i.e. are we a host implementation? */
+boolean v_fs_func_accept_connections(void)
+{
+       return VCmdData.user_func[0] != NULL;
+}
+
+/* Inspect beginning of packet, looking for ACK or NAK commands. */
+void v_fs_unpack_beginning(const uint8 *data, unsigned int length)
+{
+       uint32 id, i = 4;
+       uint8 cmd_id;
+
+       i += vnp_raw_unpack_uint8(&data[i], &cmd_id);
+       while(i < length && (cmd_id == 7 || cmd_id == 8))
+       {
+               i += vnp_raw_unpack_uint32(&data[i], &id);
+               if(cmd_id == 7)
+                       callback_send_packet_ack(NULL, id);
+               else
+                       callback_send_packet_nak(NULL, id);
+               i += vnp_raw_unpack_uint8(&data[i], &cmd_id);
+       }
+}
+
+void v_fs_unpack(uint8 *data, unsigned int length)
+{
+       uint32 i, output, pack_id;
+       uint8 cmd_id, last = 255;
+
+       i = vnp_raw_unpack_uint32(data, &pack_id); /* each packet starts with a 32 bit id */
+       vnp_raw_unpack_uint8(&data[i], &cmd_id);
+       while(i < length && (cmd_id == 7 || cmd_id == 8))
+       {
+               i += 5;
+               vnp_raw_unpack_uint8(&data[i], &cmd_id);
+       }
+       while(i < length)
+       {
+               i += vnp_raw_unpack_uint8(&data[i], &cmd_id);
+               if(VCmdData.unpack_func[cmd_id] != NULL)
+               {
+                       VCmdData.call = TRUE;
+                       output = VCmdData.unpack_func[cmd_id](&data[i], length - i);
+                       if(output == (unsigned int) -1) /* Can this happen? Should be size_t or int, depending. */
+                       {
+                               printf("** Aborting decode, command %u unpacker returned failure\n", cmd_id);
+/*                             verse_send_packet_nak(pack_id);*/
+                               return;
+                       }
+                       last = cmd_id;
+                       i += output;
+               }
+               else    /* If unknown command byte was found, complain loudly and stop parsing packet. */
+               {
+                       size_t  j;
+
+                       printf("\n** Unknown command ID %u (0x%02X) encountered--aborting packet decode len=%u pos=%u last=%u\n", cmd_id, cmd_id, length, i, last);
+                       printf(" decoded %u bytes: ", --i);
+                       for(j = 0; j < i; j++)
+                               printf("%02X ", data[j]);
+                       printf("\n (packet id=%u)", pack_id);
+                       printf(" remaining %u bytes: ", length - i);
+                       for(j = i; j < length; j++)
+                               printf("%02X ", data[j]);
+                       printf("\n");
+/*                     *(char *) 0 = 0;*/
+                       break;
+               }
+       }
+/*     if(expected != NULL)
+               verse_send_packet_ack(pack_id);*/
+}
+
+extern unsigned int v_unpack_connection(const char *data, size_t length);
+
+#endif
diff --git a/extern/verse/dist/v_gen_pack_a_node.c b/extern/verse/dist/v_gen_pack_a_node.c
new file mode 100644 (file)
index 0000000..4d6c4a4
--- /dev/null
@@ -0,0 +1,521 @@
+/*
+** This is automatically generated source code -- do not edit.
+** Changes are affected either by editing the corresponding protocol
+** definition file (v_cmd_def_X.c where X=node type), or by editing
+** the code generator itself, in v_cmd_gen.c.
+*/
+
+#include <stdlib.h>
+#include <stdio.h>
+
+#include "v_cmd_gen.h"
+#if !defined(V_GENERATE_FUNC_MODE)
+#include "verse.h"
+#include "v_cmd_buf.h"
+#include "v_network_out_que.h"
+#include "v_network.h"
+#include "v_connection.h"
+#include "v_util.h"
+
+void verse_send_a_buffer_create(VNodeID node_id, VBufferID buffer_id, const char *name, VNABlockType type, real64 frequency)
+{
+       uint8 *buf;
+       unsigned int buffer_pos = 0;
+       VCMDBufHead *head;
+       head = v_cmd_buf_allocate(VCMDBS_80);/* Allocating the buffer */
+       buf = ((VCMDBuffer10 *)head)->buf;
+
+       buffer_pos += vnp_raw_pack_uint8(&buf[buffer_pos], 160);        /* Pack the command. */
+#if defined V_PRINT_SEND_COMMANDS
+       printf("send: verse_send_a_buffer_create(node_id = %u buffer_id = %u name = %s type = %u frequency = %f );\n", node_id, buffer_id, name, type, frequency);
+#endif
+       buffer_pos += vnp_raw_pack_uint32(&buf[buffer_pos], node_id);
+       buffer_pos += vnp_raw_pack_uint16(&buf[buffer_pos], buffer_id);
+       buffer_pos += vnp_raw_pack_string(&buf[buffer_pos], name, 16);
+       buffer_pos += vnp_raw_pack_uint8(&buf[buffer_pos], (uint8)type);
+       buffer_pos += vnp_raw_pack_real64(&buf[buffer_pos], frequency);
+       if(node_id == (uint32)(-1) || buffer_id == (uint16)(-1))
+               v_cmd_buf_set_unique_address_size(head, 7);
+       else
+               v_cmd_buf_set_address_size(head, 7);
+       v_cmd_buf_set_size(head, buffer_pos);
+       v_noq_send_buf(v_con_get_network_queue(), head);
+}
+
+void verse_send_a_buffer_destroy(VNodeID node_id, VBufferID buffer_id)
+{
+       uint8 *buf;
+       unsigned int buffer_pos = 0;
+       VCMDBufHead *head;
+       head = v_cmd_buf_allocate(VCMDBS_80);/* Allocating the buffer */
+       buf = ((VCMDBuffer10 *)head)->buf;
+
+       buffer_pos += vnp_raw_pack_uint8(&buf[buffer_pos], 160);        /* Pack the command. */
+#if defined V_PRINT_SEND_COMMANDS
+       printf("send: verse_send_a_buffer_destroy(node_id = %u buffer_id = %u );\n", node_id, buffer_id);
+#endif
+       buffer_pos += vnp_raw_pack_uint32(&buf[buffer_pos], node_id);
+       buffer_pos += vnp_raw_pack_uint16(&buf[buffer_pos], buffer_id);
+       buffer_pos += vnp_raw_pack_string(&buf[buffer_pos], NULL, 16);
+       buffer_pos += vnp_raw_pack_uint8(&buf[buffer_pos], (uint8)-1);
+       buffer_pos += vnp_raw_pack_real64(&buf[buffer_pos], V_REAL64_MAX);
+       if(node_id == (uint32)(-1) || buffer_id == (uint16)(-1))
+               v_cmd_buf_set_unique_address_size(head, 7);
+       else
+               v_cmd_buf_set_address_size(head, 7);
+       v_cmd_buf_set_size(head, buffer_pos);
+       v_noq_send_buf(v_con_get_network_queue(), head);
+}
+
+unsigned int v_unpack_a_buffer_create(const char *buf, size_t buffer_length)
+{
+       uint8 enum_temp;
+       unsigned int buffer_pos = 0;
+       void (* func_a_buffer_create)(void *user_data, VNodeID node_id, VBufferID buffer_id, const char *name, VNABlockType type, real64 frequency);
+       VNodeID node_id;
+       VBufferID buffer_id;
+       char name[16];
+       VNABlockType type;
+       real64 frequency;
+       
+       func_a_buffer_create = v_fs_get_user_func(160);
+       if(buffer_length < 6)
+               return -1;
+       buffer_pos += vnp_raw_unpack_uint32(&buf[buffer_pos], &node_id);
+       buffer_pos += vnp_raw_unpack_uint16(&buf[buffer_pos], &buffer_id);
+       buffer_pos += vnp_raw_unpack_string(&buf[buffer_pos], name, 16, buffer_length - buffer_pos);
+       if(buffer_length < 9 + buffer_pos)
+               return -1;
+       buffer_pos += vnp_raw_unpack_uint8(&buf[buffer_pos], &enum_temp);
+       type = (VNABlockType)enum_temp;
+       buffer_pos += vnp_raw_unpack_real64(&buf[buffer_pos], &frequency);
+#if defined V_PRINT_RECEIVE_COMMANDS
+       if(name[0] == 0)
+               printf("receive: verse_send_a_buffer_destroy(node_id = %u buffer_id = %u ); callback = %p\n", node_id, buffer_id, v_fs_get_alias_user_func(160));
+       else
+               printf("receive: verse_send_a_buffer_create(node_id = %u buffer_id = %u name = %s type = %u frequency = %f ); callback = %p\n", node_id, buffer_id, name, type, frequency, v_fs_get_user_func(160));
+#endif
+       if(name[0] == 0)
+       {
+               void (* alias_a_buffer_destroy)(void *user_data, VNodeID node_id, VBufferID buffer_id);
+               alias_a_buffer_destroy = v_fs_get_alias_user_func(160);
+               if(alias_a_buffer_destroy != NULL)
+                       alias_a_buffer_destroy(v_fs_get_alias_user_data(160), node_id, buffer_id);
+               return buffer_pos;
+       }
+       if(func_a_buffer_create != NULL)
+               func_a_buffer_create(v_fs_get_user_data(160), node_id, buffer_id, name, (VNABlockType) type, frequency);
+
+       return buffer_pos;
+}
+
+void verse_send_a_buffer_subscribe(VNodeID node_id, VBufferID layer_id)
+{
+       uint8 *buf;
+       unsigned int buffer_pos = 0;
+       VCMDBufHead *head;
+       head = v_cmd_buf_allocate(VCMDBS_10);/* Allocating the buffer */
+       buf = ((VCMDBuffer10 *)head)->buf;
+
+       buffer_pos += vnp_raw_pack_uint8(&buf[buffer_pos], 161);        /* Pack the command. */
+#if defined V_PRINT_SEND_COMMANDS
+       printf("send: verse_send_a_buffer_subscribe(node_id = %u layer_id = %u );\n", node_id, layer_id);
+#endif
+       buffer_pos += vnp_raw_pack_uint32(&buf[buffer_pos], node_id);
+       buffer_pos += vnp_raw_pack_uint16(&buf[buffer_pos], layer_id);
+       buffer_pos += vnp_raw_pack_uint8(&buf[buffer_pos], TRUE);
+       if(node_id == (uint32)(-1) || layer_id == (uint16)(-1))
+               v_cmd_buf_set_unique_address_size(head, 7);
+       else
+               v_cmd_buf_set_address_size(head, 7);
+       v_cmd_buf_set_size(head, buffer_pos);
+       v_noq_send_buf(v_con_get_network_queue(), head);
+}
+
+void verse_send_a_buffer_unsubscribe(VNodeID node_id, VBufferID layer_id)
+{
+       uint8 *buf;
+       unsigned int buffer_pos = 0;
+       VCMDBufHead *head;
+       head = v_cmd_buf_allocate(VCMDBS_10);/* Allocating the buffer */
+       buf = ((VCMDBuffer10 *)head)->buf;
+
+       buffer_pos += vnp_raw_pack_uint8(&buf[buffer_pos], 161);        /* Pack the command. */
+#if defined V_PRINT_SEND_COMMANDS
+       printf("send: verse_send_a_buffer_unsubscribe(node_id = %u layer_id = %u );\n", node_id, layer_id);
+#endif
+       buffer_pos += vnp_raw_pack_uint32(&buf[buffer_pos], node_id);
+       buffer_pos += vnp_raw_pack_uint16(&buf[buffer_pos], layer_id);
+       buffer_pos += vnp_raw_pack_uint8(&buf[buffer_pos], FALSE);
+       if(node_id == (uint32)(-1) || layer_id == (uint16)(-1))
+               v_cmd_buf_set_unique_address_size(head, 7);
+       else
+               v_cmd_buf_set_address_size(head, 7);
+       v_cmd_buf_set_size(head, buffer_pos);
+       v_noq_send_buf(v_con_get_network_queue(), head);
+}
+
+unsigned int v_unpack_a_buffer_subscribe(const char *buf, size_t buffer_length)
+{
+       unsigned int buffer_pos = 0;
+       void (* func_a_buffer_subscribe)(void *user_data, VNodeID node_id, VBufferID layer_id);
+       VNodeID node_id;
+       VBufferID layer_id;
+       uint8   alias_bool;
+
+       func_a_buffer_subscribe = v_fs_get_user_func(161);
+       if(buffer_length < 6)
+               return -1;
+       buffer_pos += vnp_raw_unpack_uint32(&buf[buffer_pos], &node_id);
+       buffer_pos += vnp_raw_unpack_uint16(&buf[buffer_pos], &layer_id);
+       if(buffer_length < buffer_pos + 1)
+               return -1;
+       buffer_pos += vnp_raw_unpack_uint8(&buf[buffer_pos], &alias_bool);
+#if defined V_PRINT_RECEIVE_COMMANDS
+       if(!alias_bool)
+               printf("receive: verse_send_a_buffer_unsubscribe(node_id = %u layer_id = %u ); callback = %p\n", node_id, layer_id, v_fs_get_alias_user_func(161));
+       else
+               printf("receive: verse_send_a_buffer_subscribe(node_id = %u layer_id = %u ); callback = %p\n", node_id, layer_id, v_fs_get_user_func(161));
+#endif
+       if(!alias_bool)
+       {
+               void (* alias_a_buffer_unsubscribe)(void *user_data, VNodeID node_id, VBufferID layer_id);
+               alias_a_buffer_unsubscribe = v_fs_get_alias_user_func(161);
+               if(alias_a_buffer_unsubscribe != NULL)
+                       alias_a_buffer_unsubscribe(v_fs_get_alias_user_data(161), node_id, layer_id);
+               return buffer_pos;
+       }
+       if(func_a_buffer_subscribe != NULL)
+               func_a_buffer_subscribe(v_fs_get_user_data(161), node_id, layer_id);
+
+       return buffer_pos;
+}
+
+void verse_send_a_block_set(VNodeID node_id, VLayerID buffer_id, uint32 block_index, VNABlockType type, const VNABlock *samples)
+{
+       uint8 *buf;
+       unsigned int buffer_pos = 0;
+       VCMDBufHead *head;
+       head = v_cmd_buf_allocate(VCMDBS_1500);/* Allocating the buffer */
+       buf = ((VCMDBuffer10 *)head)->buf;
+
+       buffer_pos += vnp_raw_pack_uint8(&buf[buffer_pos], 162);        /* Pack the command. */
+#if defined V_PRINT_SEND_COMMANDS
+       printf("send: verse_send_a_block_set(node_id = %u buffer_id = %u block_index = %u type = %u samples = %p );\n", node_id, buffer_id, block_index, type, samples);
+#endif
+       buffer_pos += vnp_raw_pack_uint32(&buf[buffer_pos], node_id);
+       buffer_pos += vnp_raw_pack_uint16(&buf[buffer_pos], buffer_id);
+       buffer_pos += vnp_raw_pack_uint32(&buf[buffer_pos], block_index);
+       buffer_pos += vnp_raw_pack_uint8(&buf[buffer_pos], (uint8)type);
+       buffer_pos += vnp_pack_audio_block(&buf[buffer_pos], type, samples);
+       if(node_id == (uint32)(-1) || buffer_id == (uint16)(-1) || block_index == (uint32)(-1))
+               v_cmd_buf_set_unique_address_size(head, 11);
+       else
+               v_cmd_buf_set_address_size(head, 11);
+       v_cmd_buf_set_size(head, buffer_pos);
+       v_noq_send_buf(v_con_get_network_queue(), head);
+}
+
+void verse_send_a_block_clear(VNodeID node_id, VLayerID buffer_id, uint32 block_index)
+{
+       uint8 *buf;
+       unsigned int buffer_pos = 0;
+       VCMDBufHead *head;
+       head = v_cmd_buf_allocate(VCMDBS_1500);/* Allocating the buffer */
+       buf = ((VCMDBuffer10 *)head)->buf;
+
+       buffer_pos += vnp_raw_pack_uint8(&buf[buffer_pos], 162);        /* Pack the command. */
+#if defined V_PRINT_SEND_COMMANDS
+       printf("send: verse_send_a_block_clear(node_id = %u buffer_id = %u block_index = %u );\n", node_id, buffer_id, block_index);
+#endif
+       buffer_pos += vnp_raw_pack_uint32(&buf[buffer_pos], node_id);
+       buffer_pos += vnp_raw_pack_uint16(&buf[buffer_pos], buffer_id);
+       buffer_pos += vnp_raw_pack_uint32(&buf[buffer_pos], block_index);
+       buffer_pos += vnp_raw_pack_uint8(&buf[buffer_pos], (uint8)-1);
+       if(node_id == (uint32)(-1) || buffer_id == (uint16)(-1) || block_index == (uint32)(-1))
+               v_cmd_buf_set_unique_address_size(head, 11);
+       else
+               v_cmd_buf_set_address_size(head, 11);
+       v_cmd_buf_set_size(head, buffer_pos);
+       v_noq_send_buf(v_con_get_network_queue(), head);
+}
+
+unsigned int v_unpack_a_block_set(const char *buf, size_t buffer_length)
+{
+       uint8 enum_temp;
+       unsigned int buffer_pos = 0;
+       void (* func_a_block_set)(void *user_data, VNodeID node_id, VLayerID buffer_id, uint32 block_index, VNABlockType type, const VNABlock *samples);
+       VNodeID node_id;
+       VLayerID buffer_id;
+       uint32 block_index;
+       VNABlockType type;
+       const VNABlock *samples;
+       
+       func_a_block_set = v_fs_get_user_func(162);
+       if(buffer_length < 10)
+               return -1;
+       buffer_pos += vnp_raw_unpack_uint32(&buf[buffer_pos], &node_id);
+       buffer_pos += vnp_raw_unpack_uint16(&buf[buffer_pos], &buffer_id);
+       buffer_pos += vnp_raw_unpack_uint32(&buf[buffer_pos], &block_index);
+       buffer_pos += vnp_raw_unpack_uint8(&buf[buffer_pos], &enum_temp);
+       type = (VNABlockType)enum_temp;
+#if defined V_PRINT_RECEIVE_COMMANDS
+       if(type > VN_A_BLOCK_REAL64)
+               printf("receive: verse_send_a_block_clear(node_id = %u buffer_id = %u block_index = %u ); callback = %p\n", node_id, buffer_id, block_index, v_fs_get_alias_user_func(162));
+       else
+               printf("receive: verse_send_a_block_set(node_id = %u buffer_id = %u block_index = %u type = %u ); callback = %p\n", node_id, buffer_id, block_index, type, v_fs_get_user_func(162));
+#endif
+       if(type <= VN_A_BLOCK_REAL64)
+       {
+               VNABlock        block;
+               buffer_pos += vnp_unpack_audio_block(&buf[buffer_pos], type, &block);
+               if(func_a_block_set != NULL)
+                       func_a_block_set(v_fs_get_user_data(162), node_id, buffer_id, block_index, (VNABlockType) type, &block);
+               return buffer_pos;
+       }
+
+       if(type > VN_A_BLOCK_REAL64)
+       {
+               void (* alias_a_block_clear)(void *user_data, VNodeID node_id, VLayerID buffer_id, uint32 block_index);
+               alias_a_block_clear = v_fs_get_alias_user_func(162);
+               if(alias_a_block_clear != NULL)
+                       alias_a_block_clear(v_fs_get_alias_user_data(162), node_id, buffer_id, block_index);
+               return buffer_pos;
+       }
+       if(func_a_block_set != NULL)
+               func_a_block_set(v_fs_get_user_data(162), node_id, buffer_id, block_index, (VNABlockType) type, samples);
+
+       return buffer_pos;
+}
+
+void verse_send_a_stream_create(VNodeID node_id, VLayerID stream_id, const char *name)
+{
+       uint8 *buf;
+       unsigned int buffer_pos = 0;
+       VCMDBufHead *head;
+       head = v_cmd_buf_allocate(VCMDBS_30);/* Allocating the buffer */
+       buf = ((VCMDBuffer10 *)head)->buf;
+
+       buffer_pos += vnp_raw_pack_uint8(&buf[buffer_pos], 163);        /* Pack the command. */
+#if defined V_PRINT_SEND_COMMANDS
+       printf("send: verse_send_a_stream_create(node_id = %u stream_id = %u name = %s );\n", node_id, stream_id, name);
+#endif
+       buffer_pos += vnp_raw_pack_uint32(&buf[buffer_pos], node_id);
+       buffer_pos += vnp_raw_pack_uint16(&buf[buffer_pos], stream_id);
+       buffer_pos += vnp_raw_pack_string(&buf[buffer_pos], name, 16);
+       if(node_id == (uint32)(-1) || stream_id == (uint16)(-1))
+               v_cmd_buf_set_unique_address_size(head, 7);
+       else
+               v_cmd_buf_set_address_size(head, 7);
+       v_cmd_buf_set_size(head, buffer_pos);
+       v_noq_send_buf(v_con_get_network_queue(), head);
+}
+
+void verse_send_a_stream_destroy(VNodeID node_id, VLayerID stream_id)
+{
+       uint8 *buf;
+       unsigned int buffer_pos = 0;
+       VCMDBufHead *head;
+       head = v_cmd_buf_allocate(VCMDBS_30);/* Allocating the buffer */
+       buf = ((VCMDBuffer10 *)head)->buf;
+
+       buffer_pos += vnp_raw_pack_uint8(&buf[buffer_pos], 163);        /* Pack the command. */
+#if defined V_PRINT_SEND_COMMANDS
+       printf("send: verse_send_a_stream_destroy(node_id = %u stream_id = %u );\n", node_id, stream_id);
+#endif
+       buffer_pos += vnp_raw_pack_uint32(&buf[buffer_pos], node_id);
+       buffer_pos += vnp_raw_pack_uint16(&buf[buffer_pos], stream_id);
+       buffer_pos += vnp_raw_pack_string(&buf[buffer_pos], NULL, 16);
+       if(node_id == (uint32)(-1) || stream_id == (uint16)(-1))
+               v_cmd_buf_set_unique_address_size(head, 7);
+       else
+               v_cmd_buf_set_address_size(head, 7);
+       v_cmd_buf_set_size(head, buffer_pos);
+       v_noq_send_buf(v_con_get_network_queue(), head);
+}
+
+unsigned int v_unpack_a_stream_create(const char *buf, size_t buffer_length)
+{
+       unsigned int buffer_pos = 0;
+       void (* func_a_stream_create)(void *user_data, VNodeID node_id, VLayerID stream_id, const char *name);
+       VNodeID node_id;
+       VLayerID stream_id;
+       char name[16];
+       
+       func_a_stream_create = v_fs_get_user_func(163);
+       if(buffer_length < 6)
+               return -1;
+       buffer_pos += vnp_raw_unpack_uint32(&buf[buffer_pos], &node_id);
+       buffer_pos += vnp_raw_unpack_uint16(&buf[buffer_pos], &stream_id);
+       buffer_pos += vnp_raw_unpack_string(&buf[buffer_pos], name, 16, buffer_length - buffer_pos);
+#if defined V_PRINT_RECEIVE_COMMANDS
+       if(name[0] == 0)
+               printf("receive: verse_send_a_stream_destroy(node_id = %u stream_id = %u ); callback = %p\n", node_id, stream_id, v_fs_get_alias_user_func(163));
+       else
+               printf("receive: verse_send_a_stream_create(node_id = %u stream_id = %u name = %s ); callback = %p\n", node_id, stream_id, name, v_fs_get_user_func(163));
+#endif
+       if(name[0] == 0)
+       {
+               void (* alias_a_stream_destroy)(void *user_data, VNodeID node_id, VLayerID stream_id);
+               alias_a_stream_destroy = v_fs_get_alias_user_func(163);
+               if(alias_a_stream_destroy != NULL)
+                       alias_a_stream_destroy(v_fs_get_alias_user_data(163), node_id, stream_id);
+               return buffer_pos;
+       }
+       if(func_a_stream_create != NULL)
+               func_a_stream_create(v_fs_get_user_data(163), node_id, stream_id, name);
+
+       return buffer_pos;
+}
+
+void verse_send_a_stream_subscribe(VNodeID node_id, VLayerID stream_id)
+{
+       uint8 *buf;
+       unsigned int buffer_pos = 0;
+       VCMDBufHead *head;
+       head = v_cmd_buf_allocate(VCMDBS_10);/* Allocating the buffer */
+       buf = ((VCMDBuffer10 *)head)->buf;
+
+       buffer_pos += vnp_raw_pack_uint8(&buf[buffer_pos], 164);        /* Pack the command. */
+#if defined V_PRINT_SEND_COMMANDS
+       printf("send: verse_send_a_stream_subscribe(node_id = %u stream_id = %u );\n", node_id, stream_id);
+#endif
+       buffer_pos += vnp_raw_pack_uint32(&buf[buffer_pos], node_id);
+       buffer_pos += vnp_raw_pack_uint16(&buf[buffer_pos], stream_id);
+       buffer_pos += vnp_raw_pack_uint8(&buf[buffer_pos], TRUE);
+       if(node_id == (uint32)(-1) || stream_id == (uint16)(-1))
+               v_cmd_buf_set_unique_address_size(head, 7);
+       else
+               v_cmd_buf_set_address_size(head, 7);
+       v_cmd_buf_set_size(head, buffer_pos);
+       v_noq_send_buf(v_con_get_network_queue(), head);
+}
+
+void verse_send_a_stream_unsubscribe(VNodeID node_id, VLayerID stream_id)
+{
+       uint8 *buf;
+       unsigned int buffer_pos = 0;
+       VCMDBufHead *head;
+       head = v_cmd_buf_allocate(VCMDBS_10);/* Allocating the buffer */
+       buf = ((VCMDBuffer10 *)head)->buf;
+
+       buffer_pos += vnp_raw_pack_uint8(&buf[buffer_pos], 164);        /* Pack the command. */
+#if defined V_PRINT_SEND_COMMANDS
+       printf("send: verse_send_a_stream_unsubscribe(node_id = %u stream_id = %u );\n", node_id, stream_id);
+#endif
+       buffer_pos += vnp_raw_pack_uint32(&buf[buffer_pos], node_id);
+       buffer_pos += vnp_raw_pack_uint16(&buf[buffer_pos], stream_id);
+       buffer_pos += vnp_raw_pack_uint8(&buf[buffer_pos], FALSE);
+       if(node_id == (uint32)(-1) || stream_id == (uint16)(-1))
+               v_cmd_buf_set_unique_address_size(head, 7);
+       else
+               v_cmd_buf_set_address_size(head, 7);
+       v_cmd_buf_set_size(head, buffer_pos);
+       v_noq_send_buf(v_con_get_network_queue(), head);
+}
+
+unsigned int v_unpack_a_stream_subscribe(const char *buf, size_t buffer_length)
+{
+       unsigned int buffer_pos = 0;
+       void (* func_a_stream_subscribe)(void *user_data, VNodeID node_id, VLayerID stream_id);
+       VNodeID node_id;
+       VLayerID stream_id;
+       uint8   alias_bool;
+
+       func_a_stream_subscribe = v_fs_get_user_func(164);
+       if(buffer_length < 6)
+               return -1;
+       buffer_pos += vnp_raw_unpack_uint32(&buf[buffer_pos], &node_id);
+       buffer_pos += vnp_raw_unpack_uint16(&buf[buffer_pos], &stream_id);
+       if(buffer_length < buffer_pos + 1)
+               return -1;
+       buffer_pos += vnp_raw_unpack_uint8(&buf[buffer_pos], &alias_bool);
+#if defined V_PRINT_RECEIVE_COMMANDS
+       if(!alias_bool)
+               printf("receive: verse_send_a_stream_unsubscribe(node_id = %u stream_id = %u ); callback = %p\n", node_id, stream_id, v_fs_get_alias_user_func(164));
+       else
+               printf("receive: verse_send_a_stream_subscribe(node_id = %u stream_id = %u ); callback = %p\n", node_id, stream_id, v_fs_get_user_func(164));
+#endif
+       if(!alias_bool)
+       {
+               void (* alias_a_stream_unsubscribe)(void *user_data, VNodeID node_id, VLayerID stream_id);
+               alias_a_stream_unsubscribe = v_fs_get_alias_user_func(164);
+               if(alias_a_stream_unsubscribe != NULL)
+                       alias_a_stream_unsubscribe(v_fs_get_alias_user_data(164), node_id, stream_id);
+               return buffer_pos;
+       }
+       if(func_a_stream_subscribe != NULL)
+               func_a_stream_subscribe(v_fs_get_user_data(164), node_id, stream_id);
+
+       return buffer_pos;
+}
+
+void verse_send_a_stream(VNodeID node_id, VLayerID stream_id, uint32 time_s, uint32 time_f, VNABlockType type, real64 frequency, const VNABlock *samples)
+{
+       uint8 *buf;
+       unsigned int buffer_pos = 0;
+       VCMDBufHead *head;
+       head = v_cmd_buf_allocate(VCMDBS_1500);/* Allocating the buffer */
+       buf = ((VCMDBuffer10 *)head)->buf;
+
+       buffer_pos += vnp_raw_pack_uint8(&buf[buffer_pos], 165);        /* Pack the command. */
+#if defined V_PRINT_SEND_COMMANDS
+       printf("send: verse_send_a_stream(node_id = %u stream_id = %u time_s = %u time_f = %u type = %u frequency = %f samples = %p );\n", node_id, stream_id, time_s, time_f, type, frequency, samples);
+#endif
+       buffer_pos += vnp_raw_pack_uint32(&buf[buffer_pos], node_id);
+       buffer_pos += vnp_raw_pack_uint16(&buf[buffer_pos], stream_id);
+       buffer_pos += vnp_raw_pack_uint32(&buf[buffer_pos], time_s);
+       buffer_pos += vnp_raw_pack_uint32(&buf[buffer_pos], time_f);
+       buffer_pos += vnp_raw_pack_uint8(&buf[buffer_pos], (uint8)type);
+       buffer_pos += vnp_raw_pack_real64(&buf[buffer_pos], frequency);
+       buffer_pos += vnp_pack_audio_block(&buf[buffer_pos], type, samples);
+       if(node_id == (uint32)(-1) || stream_id == (uint16)(-1))
+               v_cmd_buf_set_unique_address_size(head, 7);
+       else
+               v_cmd_buf_set_address_size(head, 7);
+       v_cmd_buf_set_size(head, buffer_pos);
+       v_noq_send_buf(v_con_get_network_queue(), head);
+}
+
+unsigned int v_unpack_a_stream(const char *buf, size_t buffer_length)
+{
+       uint8 enum_temp;
+       unsigned int buffer_pos = 0;
+       void (* func_a_stream)(void *user_data, VNodeID node_id, VLayerID stream_id, uint32 time_s, uint32 time_f, VNABlockType type, real64 frequency, const VNABlock *samples);
+       VNodeID node_id;
+       VLayerID stream_id;
+       uint32 time_s;
+       uint32 time_f;
+       VNABlockType type;
+       real64 frequency;
+       const VNABlock *samples;
+       
+       func_a_stream = v_fs_get_user_func(165);
+       if(buffer_length < 6)
+               return -1;
+       buffer_pos += vnp_raw_unpack_uint32(&buf[buffer_pos], &node_id);
+       buffer_pos += vnp_raw_unpack_uint16(&buf[buffer_pos], &stream_id);
+       buffer_pos += vnp_raw_unpack_uint32(&buf[buffer_pos], &time_s);
+       buffer_pos += vnp_raw_unpack_uint32(&buf[buffer_pos], &time_f);
+       buffer_pos += vnp_raw_unpack_uint8(&buf[buffer_pos], &enum_temp);
+       type = (VNABlockType)enum_temp;
+       buffer_pos += vnp_raw_unpack_real64(&buf[buffer_pos], &frequency);
+#if defined V_PRINT_RECEIVE_COMMANDS
+       printf("receive: verse_send_a_stream(node_id = %u stream_id = %u time_s = %u time_f = %u type = %u frequency = %f ); callback = %p\n", node_id, stream_id, time_s, time_f, type, frequency, v_fs_get_user_func(165));
+#endif
+       {
+               VNABlock        block;
+       buffer_pos += vnp_unpack_audio_block(&buf[buffer_pos], type, &block);
+               if(func_a_stream != NULL)
+                       func_a_stream(v_fs_get_user_data(165), node_id, stream_id, time_s, time_f, (VNABlockType) type, frequency, &block);
+               return buffer_pos;
+       }
+
+       if(func_a_stream != NULL)
+               func_a_stream(v_fs_get_user_data(165), node_id, stream_id, time_s, time_f, (VNABlockType) type, frequency, samples);
+
+       return buffer_pos;
+}
+
+#endif
+
diff --git a/extern/verse/dist/v_gen_pack_b_node.c b/extern/verse/dist/v_gen_pack_b_node.c
new file mode 100644 (file)
index 0000000..9ff7ab2
--- /dev/null
@@ -0,0 +1,238 @@
+/*
+** This is automatically generated source code -- do not edit.
+** Changes are affected either by editing the corresponding protocol
+** definition file (v_cmd_def_X.c where X=node type), or by editing
+** the code generator itself, in v_cmd_gen.c.
+*/
+
+#include <stdlib.h>
+#include <stdio.h>
+
+#include "v_cmd_gen.h"
+#if !defined(V_GENERATE_FUNC_MODE)
+#include "verse.h"
+#include "v_cmd_buf.h"
+#include "v_network_out_que.h"
+#include "v_network.h"
+#include "v_connection.h"
+#include "v_util.h"
+
+void verse_send_b_dimensions_set(VNodeID node_id, uint16 width, uint16 height, uint16 depth)
+{
+       uint8 *buf;
+       unsigned int buffer_pos = 0;
+       VCMDBufHead *head;
+       head = v_cmd_buf_allocate(VCMDBS_20);/* Allocating the buffer */
+       buf = ((VCMDBuffer10 *)head)->buf;
+
+       buffer_pos += vnp_raw_pack_uint8(&buf[buffer_pos], 80); /* Pack the command. */
+#if defined V_PRINT_SEND_COMMANDS
+       printf("send: verse_send_b_dimensions_set(node_id = %u width = %u height = %u depth = %u );\n", node_id, width, height, depth);
+#endif
+       buffer_pos += vnp_raw_pack_uint32(&buf[buffer_pos], node_id);
+       buffer_pos += vnp_raw_pack_uint16(&buf[buffer_pos], width);
+       buffer_pos += vnp_raw_pack_uint16(&buf[buffer_pos], height);
+       buffer_pos += vnp_raw_pack_uint16(&buf[buffer_pos], depth);
+       if(node_id == (uint32)(-1))
+               v_cmd_buf_set_unique_address_size(head, 5);
+       else
+               v_cmd_buf_set_address_size(head, 5);
+       v_cmd_buf_set_size(head, buffer_pos);
+       v_noq_send_buf(v_con_get_network_queue(), head);
+}
+
+unsigned int v_unpack_b_dimensions_set(const char *buf, size_t buffer_length)
+{
+       unsigned int buffer_pos = 0;
+       void (* func_b_dimensions_set)(void *user_data, VNodeID node_id, uint16 width, uint16 height, uint16 depth);
+       VNodeID node_id;
+       uint16 width;
+       uint16 height;
+       uint16 depth;
+       
+       func_b_dimensions_set = v_fs_get_user_func(80);
+       if(buffer_length < 4)
+               return -1;
+       buffer_pos += vnp_raw_unpack_uint32(&buf[buffer_pos], &node_id);
+       buffer_pos += vnp_raw_unpack_uint16(&buf[buffer_pos], &width);
+       buffer_pos += vnp_raw_unpack_uint16(&buf[buffer_pos], &height);
+       buffer_pos += vnp_raw_unpack_uint16(&buf[buffer_pos], &depth);
+#if defined V_PRINT_RECEIVE_COMMANDS
+       printf("receive: verse_send_b_dimensions_set(node_id = %u width = %u height = %u depth = %u ); callback = %p\n", node_id, width, height, depth, v_fs_get_user_func(80));
+#endif
+       if(func_b_dimensions_set != NULL)
+               func_b_dimensions_set(v_fs_get_user_data(80), node_id, width, height, depth);
+
+       return buffer_pos;
+}
+
+void verse_send_b_layer_create(VNodeID node_id, VLayerID layer_id, const char *name, VNBLayerType type)
+{
+       uint8 *buf;
+       unsigned int buffer_pos = 0;
+       VCMDBufHead *head;
+       head = v_cmd_buf_allocate(VCMDBS_30);/* Allocating the buffer */
+       buf = ((VCMDBuffer10 *)head)->buf;
+
+       buffer_pos += vnp_raw_pack_uint8(&buf[buffer_pos], 81); /* Pack the command. */
+#if defined V_PRINT_SEND_COMMANDS
+       printf("send: verse_send_b_layer_create(node_id = %u layer_id = %u name = %s type = %u );\n", node_id, layer_id, name, type);
+#endif
+       buffer_pos += vnp_raw_pack_uint32(&buf[buffer_pos], node_id);
+       buffer_pos += vnp_raw_pack_uint16(&buf[buffer_pos], layer_id);
+       buffer_pos += vnp_raw_pack_string(&buf[buffer_pos], name, 16);
+       buffer_pos += vnp_raw_pack_uint8(&buf[buffer_pos], (uint8)type);
+       if(node_id == (uint32)(-1) || layer_id == (uint16)(-1))
+               v_cmd_buf_set_unique_address_size(head, 7);
+       else
+               v_cmd_buf_set_address_size(head, 7);
+       v_cmd_buf_set_size(head, buffer_pos);
+       v_noq_send_buf(v_con_get_network_queue(), head);
+}
+
+void verse_send_b_layer_destroy(VNodeID node_id, VLayerID layer_id)
+{
+       uint8 *buf;
+       unsigned int buffer_pos = 0;
+       VCMDBufHead *head;
+       head = v_cmd_buf_allocate(VCMDBS_30);/* Allocating the buffer */
+       buf = ((VCMDBuffer10 *)head)->buf;
+
+       buffer_pos += vnp_raw_pack_uint8(&buf[buffer_pos], 81); /* Pack the command. */
+#if defined V_PRINT_SEND_COMMANDS
+       printf("send: verse_send_b_layer_destroy(node_id = %u layer_id = %u );\n", node_id, layer_id);
+#endif
+       buffer_pos += vnp_raw_pack_uint32(&buf[buffer_pos], node_id);
+       buffer_pos += vnp_raw_pack_uint16(&buf[buffer_pos], layer_id);
+       buffer_pos += vnp_raw_pack_string(&buf[buffer_pos], NULL, 16);
+       buffer_pos += vnp_raw_pack_uint8(&buf[buffer_pos], (uint8)-1);
+       if(node_id == (uint32)(-1) || layer_id == (uint16)(-1))
+               v_cmd_buf_set_unique_address_size(head, 7);
+       else
+               v_cmd_buf_set_address_size(head, 7);
+       v_cmd_buf_set_size(head, buffer_pos);
+       v_noq_send_buf(v_con_get_network_queue(), head);
+}
+
+unsigned int v_unpack_b_layer_create(const char *buf, size_t buffer_length)
+{
+       uint8 enum_temp;
+       unsigned int buffer_pos = 0;
+       void (* func_b_layer_create)(void *user_data, VNodeID node_id, VLayerID layer_id, const char *name, VNBLayerType type);
+       VNodeID node_id;
+       VLayerID layer_id;
+       char name[16];
+       VNBLayerType type;
+       
+       func_b_layer_create = v_fs_get_user_func(81);
+       if(buffer_length < 6)
+               return -1;
+       buffer_pos += vnp_raw_unpack_uint32(&buf[buffer_pos], &node_id);
+       buffer_pos += vnp_raw_unpack_uint16(&buf[buffer_pos], &layer_id);
+       buffer_pos += vnp_raw_unpack_string(&buf[buffer_pos], name, 16, buffer_length - buffer_pos);
+       if(buffer_length < 1 + buffer_pos)
+               return -1;
+       buffer_pos += vnp_raw_unpack_uint8(&buf[buffer_pos], &enum_temp);
+       type = (VNBLayerType)enum_temp;
+#if defined V_PRINT_RECEIVE_COMMANDS
+       if(name[0] == 0)
+               printf("receive: verse_send_b_layer_destroy(node_id = %u layer_id = %u ); callback = %p\n", node_id, layer_id, v_fs_get_alias_user_func(81));
+       else
+               printf("receive: verse_send_b_layer_create(node_id = %u layer_id = %u name = %s type = %u ); callback = %p\n", node_id, layer_id, name, type, v_fs_get_user_func(81));
+#endif
+       if(name[0] == 0)
+       {
+               void (* alias_b_layer_destroy)(void *user_data, VNodeID node_id, VLayerID layer_id);
+               alias_b_layer_destroy = v_fs_get_alias_user_func(81);
+               if(alias_b_layer_destroy != NULL)
+                       alias_b_layer_destroy(v_fs_get_alias_user_data(81), node_id, layer_id);
+               return buffer_pos;
+       }
+       if(func_b_layer_create != NULL)
+               func_b_layer_create(v_fs_get_user_data(81), node_id, layer_id, name, (VNBLayerType) type);
+
+       return buffer_pos;
+}
+
+void verse_send_b_layer_subscribe(VNodeID node_id, VLayerID layer_id, uint8 level)
+{
+       uint8 *buf;
+       unsigned int buffer_pos = 0;
+       VCMDBufHead *head;
+       head = v_cmd_buf_allocate(VCMDBS_10);/* Allocating the buffer */
+       buf = ((VCMDBuffer10 *)head)->buf;
+
+       buffer_pos += vnp_raw_pack_uint8(&buf[buffer_pos], 82); /* Pack the command. */
+#if defined V_PRINT_SEND_COMMANDS
+       printf("send: verse_send_b_layer_subscribe(node_id = %u layer_id = %u level = %u );\n", node_id, layer_id, level);
+#endif
+       buffer_pos += vnp_raw_pack_uint32(&buf[buffer_pos], node_id);
+       buffer_pos += vnp_raw_pack_uint16(&buf[buffer_pos], layer_id);
+       buffer_pos += vnp_raw_pack_uint8(&buf[buffer_pos], level);
+       if(node_id == (uint32)(-1) || layer_id == (uint16)(-1))
+               v_cmd_buf_set_unique_address_size(head, 7);
+       else
+               v_cmd_buf_set_address_size(head, 7);
+       v_cmd_buf_set_size(head, buffer_pos);
+       v_noq_send_buf(v_con_get_network_queue(), head);
+}
+
+void verse_send_b_layer_unsubscribe(VNodeID node_id, VLayerID layer_id)
+{
+       uint8 *buf;
+       unsigned int buffer_pos = 0;
+       VCMDBufHead *head;
+       head = v_cmd_buf_allocate(VCMDBS_10);/* Allocating the buffer */
+       buf = ((VCMDBuffer10 *)head)->buf;
+
+       buffer_pos += vnp_raw_pack_uint8(&buf[buffer_pos], 82); /* Pack the command. */
+#if defined V_PRINT_SEND_COMMANDS
+       printf("send: verse_send_b_layer_unsubscribe(node_id = %u layer_id = %u );\n", node_id, layer_id);
+#endif
+       buffer_pos += vnp_raw_pack_uint32(&buf[buffer_pos], node_id);
+       buffer_pos += vnp_raw_pack_uint16(&buf[buffer_pos], layer_id);
+       buffer_pos += vnp_raw_pack_uint8(&buf[buffer_pos], -1);
+       if(node_id == (uint32)(-1) || layer_id == (uint16)(-1))
+               v_cmd_buf_set_unique_address_size(head, 7);
+       else
+               v_cmd_buf_set_address_size(head, 7);
+       v_cmd_buf_set_size(head, buffer_pos);
+       v_noq_send_buf(v_con_get_network_queue(), head);
+}
+
+unsigned int v_unpack_b_layer_subscribe(const char *buf, size_t buffer_length)
+{
+       unsigned int buffer_pos = 0;
+       void (* func_b_layer_subscribe)(void *user_data, VNodeID node_id, VLayerID layer_id, uint8 level);
+       VNodeID node_id;
+       VLayerID layer_id;
+       uint8 level;
+       
+       func_b_layer_subscribe = v_fs_get_user_func(82);
+       if(buffer_length < 6)
+               return -1;
+       buffer_pos += vnp_raw_unpack_uint32(&buf[buffer_pos], &node_id);
+       buffer_pos += vnp_raw_unpack_uint16(&buf[buffer_pos], &layer_id);
+       buffer_pos += vnp_raw_unpack_uint8(&buf[buffer_pos], &level);
+#if defined V_PRINT_RECEIVE_COMMANDS
+       if(level == 255)
+               printf("receive: verse_send_b_layer_unsubscribe(node_id = %u layer_id = %u ); callback = %p\n", node_id, layer_id, v_fs_get_alias_user_func(82));
+       else
+               printf("receive: verse_send_b_layer_subscribe(node_id = %u layer_id = %u level = %u ); callback = %p\n", node_id, layer_id, level, v_fs_get_user_func(82));
+#endif
+       if(level == 255)
+       {
+               void (* alias_b_layer_unsubscribe)(void *user_data, VNodeID node_id, VLayerID layer_id);
+               alias_b_layer_unsubscribe = v_fs_get_alias_user_func(82);
+               if(alias_b_layer_unsubscribe != NULL)
+                       alias_b_layer_unsubscribe(v_fs_get_alias_user_data(82), node_id, layer_id);
+               return buffer_pos;
+       }
+       if(func_b_layer_subscribe != NULL)
+               func_b_layer_subscribe(v_fs_get_user_data(82), node_id, layer_id, level);
+
+       return buffer_pos;
+}
+
+#endif
+
diff --git a/extern/verse/dist/v_gen_pack_c_node.c b/extern/verse/dist/v_gen_pack_c_node.c
new file mode 100644 (file)
index 0000000..192eac5
--- /dev/null
@@ -0,0 +1,189 @@
+/*
+** This is automatically generated source code -- do not edit.
+** Changes are affected either by editing the corresponding protocol
+** definition file (v_cmd_def_X.c where X=node type), or by editing
+** the code generator itself, in v_cmd_gen.c.
+*/
+
+#include <stdlib.h>
+#include <stdio.h>
+
+#include "v_cmd_gen.h"
+#if !defined(V_GENERATE_FUNC_MODE)
+#include "verse.h"
+#include "v_cmd_buf.h"
+#include "v_network_out_que.h"
+#include "v_network.h"
+#include "v_connection.h"
+#include "v_util.h"
+
+void verse_send_c_curve_create(VNodeID node_id, VLayerID curve_id, const char *name, uint8 dimensions)
+{
+       uint8 *buf;
+       unsigned int buffer_pos = 0;
+       VCMDBufHead *head;
+       head = v_cmd_buf_allocate(VCMDBS_30);/* Allocating the buffer */
+       buf = ((VCMDBuffer10 *)head)->buf;
+
+       buffer_pos += vnp_raw_pack_uint8(&buf[buffer_pos], 128);        /* Pack the command. */
+#if defined V_PRINT_SEND_COMMANDS
+       printf("send: verse_send_c_curve_create(node_id = %u curve_id = %u name = %s dimensions = %u );\n", node_id, curve_id, name, dimensions);
+#endif
+       buffer_pos += vnp_raw_pack_uint32(&buf[buffer_pos], node_id);
+       buffer_pos += vnp_raw_pack_uint16(&buf[buffer_pos], curve_id);
+       buffer_pos += vnp_raw_pack_string(&buf[buffer_pos], name, 16);
+       buffer_pos += vnp_raw_pack_uint8(&buf[buffer_pos], dimensions);
+       if(node_id == (uint32)(-1) || curve_id == (uint16)(-1))
+               v_cmd_buf_set_unique_address_size(head, 7);
+       else
+               v_cmd_buf_set_address_size(head, 7);
+       v_cmd_buf_set_size(head, buffer_pos);
+       v_noq_send_buf(v_con_get_network_queue(), head);
+}
+
+void verse_send_c_curve_destroy(VNodeID node_id, VLayerID curve_id)
+{
+       uint8 *buf;
+       unsigned int buffer_pos = 0;
+       VCMDBufHead *head;
+       head = v_cmd_buf_allocate(VCMDBS_30);/* Allocating the buffer */
+       buf = ((VCMDBuffer10 *)head)->buf;
+
+       buffer_pos += vnp_raw_pack_uint8(&buf[buffer_pos], 128);        /* Pack the command. */
+#if defined V_PRINT_SEND_COMMANDS
+       printf("send: verse_send_c_curve_destroy(node_id = %u curve_id = %u );\n", node_id, curve_id);
+#endif
+       buffer_pos += vnp_raw_pack_uint32(&buf[buffer_pos], node_id);
+       buffer_pos += vnp_raw_pack_uint16(&buf[buffer_pos], curve_id);
+       buffer_pos += vnp_raw_pack_string(&buf[buffer_pos], NULL, 16);
+       buffer_pos += vnp_raw_pack_uint8(&buf[buffer_pos], -1);
+       if(node_id == (uint32)(-1) || curve_id == (uint16)(-1))
+               v_cmd_buf_set_unique_address_size(head, 7);
+       else
+               v_cmd_buf_set_address_size(head, 7);
+       v_cmd_buf_set_size(head, buffer_pos);
+       v_noq_send_buf(v_con_get_network_queue(), head);
+}
+
+unsigned int v_unpack_c_curve_create(const char *buf, size_t buffer_length)
+{
+       unsigned int buffer_pos = 0;
+       void (* func_c_curve_create)(void *user_data, VNodeID node_id, VLayerID curve_id, const char *name, uint8 dimensions);
+       VNodeID node_id;
+       VLayerID curve_id;
+       char name[16];
+       uint8 dimensions;
+       
+       func_c_curve_create = v_fs_get_user_func(128);
+       if(buffer_length < 6)
+               return -1;
+       buffer_pos += vnp_raw_unpack_uint32(&buf[buffer_pos], &node_id);
+       buffer_pos += vnp_raw_unpack_uint16(&buf[buffer_pos], &curve_id);
+       buffer_pos += vnp_raw_unpack_string(&buf[buffer_pos], name, 16, buffer_length - buffer_pos);
+       if(buffer_length < 1 + buffer_pos)
+               return -1;
+       buffer_pos += vnp_raw_unpack_uint8(&buf[buffer_pos], &dimensions);
+#if defined V_PRINT_RECEIVE_COMMANDS
+       if(name[0] == 0)
+               printf("receive: verse_send_c_curve_destroy(node_id = %u curve_id = %u ); callback = %p\n", node_id, curve_id, v_fs_get_alias_user_func(128));
+       else
+               printf("receive: verse_send_c_curve_create(node_id = %u curve_id = %u name = %s dimensions = %u ); callback = %p\n", node_id, curve_id, name, dimensions, v_fs_get_user_func(128));
+#endif
+       if(name[0] == 0)
+       {
+               void (* alias_c_curve_destroy)(void *user_data, VNodeID node_id, VLayerID curve_id);
+               alias_c_curve_destroy = v_fs_get_alias_user_func(128);
+               if(alias_c_curve_destroy != NULL)
+                       alias_c_curve_destroy(v_fs_get_alias_user_data(128), node_id, curve_id);
+               return buffer_pos;
+       }
+       if(func_c_curve_create != NULL)
+               func_c_curve_create(v_fs_get_user_data(128), node_id, curve_id, name, dimensions);
+
+       return buffer_pos;
+}
+
+void verse_send_c_curve_subscribe(VNodeID node_id, VLayerID curve_id)
+{
+       uint8 *buf;
+       unsigned int buffer_pos = 0;
+       VCMDBufHead *head;
+       head = v_cmd_buf_allocate(VCMDBS_10);/* Allocating the buffer */
+       buf = ((VCMDBuffer10 *)head)->buf;
+
+       buffer_pos += vnp_raw_pack_uint8(&buf[buffer_pos], 129);        /* Pack the command. */
+#if defined V_PRINT_SEND_COMMANDS
+       printf("send: verse_send_c_curve_subscribe(node_id = %u curve_id = %u );\n", node_id, curve_id);
+#endif
+       buffer_pos += vnp_raw_pack_uint32(&buf[buffer_pos], node_id);
+       buffer_pos += vnp_raw_pack_uint16(&buf[buffer_pos], curve_id);
+       buffer_pos += vnp_raw_pack_uint8(&buf[buffer_pos], TRUE);
+       if(node_id == (uint32)(-1) || curve_id == (uint16)(-1))
+               v_cmd_buf_set_unique_address_size(head, 7);
+       else
+               v_cmd_buf_set_address_size(head, 7);
+       v_cmd_buf_set_size(head, buffer_pos);
+       v_noq_send_buf(v_con_get_network_queue(), head);
+}
+
+void verse_send_c_curve_unsubscribe(VNodeID node_id, VLayerID curve_id)
+{
+       uint8 *buf;
+       unsigned int buffer_pos = 0;
+       VCMDBufHead *head;
+       head = v_cmd_buf_allocate(VCMDBS_10);/* Allocating the buffer */
+       buf = ((VCMDBuffer10 *)head)->buf;
+
+       buffer_pos += vnp_raw_pack_uint8(&buf[buffer_pos], 129);        /* Pack the command. */
+#if defined V_PRINT_SEND_COMMANDS
+       printf("send: verse_send_c_curve_unsubscribe(node_id = %u curve_id = %u );\n", node_id, curve_id);
+#endif
+       buffer_pos += vnp_raw_pack_uint32(&buf[buffer_pos], node_id);
+       buffer_pos += vnp_raw_pack_uint16(&buf[buffer_pos], curve_id);
+       buffer_pos += vnp_raw_pack_uint8(&buf[buffer_pos], FALSE);
+       if(node_id == (uint32)(-1) || curve_id == (uint16)(-1))
+               v_cmd_buf_set_unique_address_size(head, 7);
+       else
+               v_cmd_buf_set_address_size(head, 7);
+       v_cmd_buf_set_size(head, buffer_pos);
+       v_noq_send_buf(v_con_get_network_queue(), head);
+}
+
+unsigned int v_unpack_c_curve_subscribe(const char *buf, size_t buffer_length)
+{
+       unsigned int buffer_pos = 0;
+       void (* func_c_curve_subscribe)(void *user_data, VNodeID node_id, VLayerID curve_id);
+       VNodeID node_id;
+       VLayerID curve_id;
+       uint8   alias_bool;
+
+       func_c_curve_subscribe = v_fs_get_user_func(129);
+       if(buffer_length < 6)
+               return -1;
+       buffer_pos += vnp_raw_unpack_uint32(&buf[buffer_pos], &node_id);
+       buffer_pos += vnp_raw_unpack_uint16(&buf[buffer_pos], &curve_id);
+       if(buffer_length < buffer_pos + 1)
+               return -1;
+       buffer_pos += vnp_raw_unpack_uint8(&buf[buffer_pos], &alias_bool);
+#if defined V_PRINT_RECEIVE_COMMANDS
+       if(!alias_bool)
+               printf("receive: verse_send_c_curve_unsubscribe(node_id = %u curve_id = %u ); callback = %p\n", node_id, curve_id, v_fs_get_alias_user_func(129));
+       else
+               printf("receive: verse_send_c_curve_subscribe(node_id = %u curve_id = %u ); callback = %p\n", node_id, curve_id, v_fs_get_user_func(129));
+#endif
+       if(!alias_bool)
+       {
+               void (* alias_c_curve_unsubscribe)(void *user_data, VNodeID node_id, VLayerID curve_id);
+               alias_c_curve_unsubscribe = v_fs_get_alias_user_func(129);
+               if(alias_c_curve_unsubscribe != NULL)
+                       alias_c_curve_unsubscribe(v_fs_get_alias_user_data(129), node_id, curve_id);
+               return buffer_pos;
+       }
+       if(func_c_curve_subscribe != NULL)
+               func_c_curve_subscribe(v_fs_get_user_data(129), node_id, curve_id);
+
+       return buffer_pos;
+}
+
+#endif
+
diff --git a/extern/verse/dist/v_gen_pack_g_node.c b/extern/verse/dist/v_gen_pack_g_node.c
new file mode 100644 (file)
index 0000000..af147d2
--- /dev/null
@@ -0,0 +1,1162 @@
+/*
+** This is automatically generated source code -- do not edit.
+** Changes are affected either by editing the corresponding protocol
+** definition file (v_cmd_def_X.c where X=node type), or by editing
+** the code generator itself, in v_cmd_gen.c.
+*/
+
+#include <stdlib.h>
+#include <stdio.h>
+
+#include "v_cmd_gen.h"
+#if !defined(V_GENERATE_FUNC_MODE)
+#include "verse.h"
+#include "v_cmd_buf.h"
+#include "v_network_out_que.h"
+#include "v_network.h"
+#include "v_connection.h"
+#include "v_util.h"
+
+void verse_send_g_layer_create(VNodeID node_id, VLayerID layer_id, const char *name, VNGLayerType type, uint32 def_uint, real64 def_real)
+{
+       uint8 *buf;
+       unsigned int buffer_pos = 0;
+       VCMDBufHead *head;
+       head = v_cmd_buf_allocate(VCMDBS_80);/* Allocating the buffer */
+       buf = ((VCMDBuffer10 *)head)->buf;
+
+       buffer_pos += vnp_raw_pack_uint8(&buf[buffer_pos], 48); /* Pack the command. */
+#if defined V_PRINT_SEND_COMMANDS
+       printf("send: verse_send_g_layer_create(node_id = %u layer_id = %u name = %s type = %u def_uint = %u def_real = %f );\n", node_id, layer_id, name, type, def_uint, def_real);
+#endif
+       buffer_pos += vnp_raw_pack_uint32(&buf[buffer_pos], node_id);
+       buffer_pos += vnp_raw_pack_uint16(&buf[buffer_pos], layer_id);
+       buffer_pos += vnp_raw_pack_string(&buf[buffer_pos], name, 16);
+       buffer_pos += vnp_raw_pack_uint8(&buf[buffer_pos], (uint8)type);
+       buffer_pos += vnp_raw_pack_uint32(&buf[buffer_pos], def_uint);
+       buffer_pos += vnp_raw_pack_real64(&buf[buffer_pos], def_real);
+       if(node_id == (uint32)(-1) || layer_id == (uint16)(-1))
+               v_cmd_buf_set_unique_address_size(head, 7);
+       else
+               v_cmd_buf_set_address_size(head, 7);
+       v_cmd_buf_set_size(head, buffer_pos);
+       v_noq_send_buf(v_con_get_network_queue(), head);
+}
+
+void verse_send_g_layer_destroy(VNodeID node_id, VLayerID layer_id)
+{
+       uint8 *buf;
+       unsigned int buffer_pos = 0;
+       VCMDBufHead *head;
+       head = v_cmd_buf_allocate(VCMDBS_80);/* Allocating the buffer */
+       buf = ((VCMDBuffer10 *)head)->buf;
+
+       buffer_pos += vnp_raw_pack_uint8(&buf[buffer_pos], 48); /* Pack the command. */
+#if defined V_PRINT_SEND_COMMANDS
+       printf("send: verse_send_g_layer_destroy(node_id = %u layer_id = %u );\n", node_id, layer_id);
+#endif
+       buffer_pos += vnp_raw_pack_uint32(&buf[buffer_pos], node_id);
+       buffer_pos += vnp_raw_pack_uint16(&buf[buffer_pos], layer_id);
+       buffer_pos += vnp_raw_pack_string(&buf[buffer_pos], NULL, 16);
+       buffer_pos += vnp_raw_pack_uint8(&buf[buffer_pos], (uint8)-1);
+       buffer_pos += vnp_raw_pack_uint32(&buf[buffer_pos], -1);
+       buffer_pos += vnp_raw_pack_real64(&buf[buffer_pos], V_REAL64_MAX);
+       if(node_id == (uint32)(-1) || layer_id == (uint16)(-1))
+               v_cmd_buf_set_unique_address_size(head, 7);
+       else
+               v_cmd_buf_set_address_size(head, 7);
+       v_cmd_buf_set_size(head, buffer_pos);
+       v_noq_send_buf(v_con_get_network_queue(), head);
+}
+
+unsigned int v_unpack_g_layer_create(const char *buf, size_t buffer_length)
+{
+       uint8 enum_temp;
+       unsigned int buffer_pos = 0;
+       void (* func_g_layer_create)(void *user_data, VNodeID node_id, VLayerID layer_id, const char *name, VNGLayerType type, uint32 def_uint, real64 def_real);
+       VNodeID node_id;
+       VLayerID layer_id;
+       char name[16];
+       VNGLayerType type;
+       uint32 def_uint;
+       real64 def_real;
+       
+       func_g_layer_create = v_fs_get_user_func(48);
+       if(buffer_length < 6)
+               return -1;
+       buffer_pos += vnp_raw_unpack_uint32(&buf[buffer_pos], &node_id);
+       buffer_pos += vnp_raw_unpack_uint16(&buf[buffer_pos], &layer_id);
+       buffer_pos += vnp_raw_unpack_string(&buf[buffer_pos], name, 16, buffer_length - buffer_pos);
+       if(buffer_length < 13 + buffer_pos)
+               return -1;
+       buffer_pos += vnp_raw_unpack_uint8(&buf[buffer_pos], &enum_temp);
+       type = (VNGLayerType)enum_temp;
+       buffer_pos += vnp_raw_unpack_uint32(&buf[buffer_pos], &def_uint);
+       buffer_pos += vnp_raw_unpack_real64(&buf[buffer_pos], &def_real);
+#if defined V_PRINT_RECEIVE_COMMANDS
+       if(name[0] == 0)
+               printf("receive: verse_send_g_layer_destroy(node_id = %u layer_id = %u ); callback = %p\n", node_id, layer_id, v_fs_get_alias_user_func(48));
+       else
+               printf("receive: verse_send_g_layer_create(node_id = %u layer_id = %u name = %s type = %u def_uint = %u def_real = %f ); callback = %p\n", node_id, layer_id, name, type, def_uint, def_real, v_fs_get_user_func(48));
+#endif
+       if(name[0] == 0)
+       {
+               void (* alias_g_layer_destroy)(void *user_data, VNodeID node_id, VLayerID layer_id);
+               alias_g_layer_destroy = v_fs_get_alias_user_func(48);
+               if(alias_g_layer_destroy != NULL)
+                       alias_g_layer_destroy(v_fs_get_alias_user_data(48), node_id, layer_id);
+               return buffer_pos;
+       }
+       if(func_g_layer_create != NULL)
+               func_g_layer_create(v_fs_get_user_data(48), node_id, layer_id, name, (VNGLayerType) type, def_uint, def_real);
+
+       return buffer_pos;
+}
+
+void verse_send_g_layer_subscribe(VNodeID node_id, VLayerID layer_id, VNRealFormat type)
+{
+       uint8 *buf;
+       unsigned int buffer_pos = 0;
+       VCMDBufHead *head;
+       head = v_cmd_buf_allocate(VCMDBS_10);/* Allocating the buffer */
+       buf = ((VCMDBuffer10 *)head)->buf;
+
+       buffer_pos += vnp_raw_pack_uint8(&buf[buffer_pos], 49); /* Pack the command. */
+#if defined V_PRINT_SEND_COMMANDS
+       printf("send: verse_send_g_layer_subscribe(node_id = %u layer_id = %u type = %u );\n", node_id, layer_id, type);
+#endif
+       buffer_pos += vnp_raw_pack_uint32(&buf[buffer_pos], node_id);
+       buffer_pos += vnp_raw_pack_uint16(&buf[buffer_pos], layer_id);
+       buffer_pos += vnp_raw_pack_uint8(&buf[buffer_pos], (uint8)type);
+       if(node_id == (uint32)(-1) || layer_id == (uint16)(-1))
+               v_cmd_buf_set_unique_address_size(head, 7);
+       else
+               v_cmd_buf_set_address_size(head, 7);
+       v_cmd_buf_set_size(head, buffer_pos);
+       v_noq_send_buf(v_con_get_network_queue(), head);
+}
+
+void verse_send_g_layer_unsubscribe(VNodeID node_id, VLayerID layer_id)
+{
+       uint8 *buf;
+       unsigned int buffer_pos = 0;
+       VCMDBufHead *head;
+       head = v_cmd_buf_allocate(VCMDBS_10);/* Allocating the buffer */
+       buf = ((VCMDBuffer10 *)head)->buf;
+
+       buffer_pos += vnp_raw_pack_uint8(&buf[buffer_pos], 49); /* Pack the command. */
+#if defined V_PRINT_SEND_COMMANDS
+       printf("send: verse_send_g_layer_unsubscribe(node_id = %u layer_id = %u );\n", node_id, layer_id);
+#endif
+       buffer_pos += vnp_raw_pack_uint32(&buf[buffer_pos], node_id);
+       buffer_pos += vnp_raw_pack_uint16(&buf[buffer_pos], layer_id);
+       buffer_pos += vnp_raw_pack_uint8(&buf[buffer_pos], (uint8)-1);
+       if(node_id == (uint32)(-1) || layer_id == (uint16)(-1))
+               v_cmd_buf_set_unique_address_size(head, 7);
+       else
+               v_cmd_buf_set_address_size(head, 7);
+       v_cmd_buf_set_size(head, buffer_pos);
+       v_noq_send_buf(v_con_get_network_queue(), head);
+}
+
+unsigned int v_unpack_g_layer_subscribe(const char *buf, size_t buffer_length)
+{
+       uint8 enum_temp;
+       unsigned int buffer_pos = 0;
+       void (* func_g_layer_subscribe)(void *user_data, VNodeID node_id, VLayerID layer_id, VNRealFormat type);
+       VNodeID node_id;
+       VLayerID layer_id;
+       VNRealFormat type;
+       
+       func_g_layer_subscribe = v_fs_get_user_func(49);
+       if(buffer_length < 6)
+               return -1;
+       buffer_pos += vnp_raw_unpack_uint32(&buf[buffer_pos], &node_id);
+       buffer_pos += vnp_raw_unpack_uint16(&buf[buffer_pos], &layer_id);
+       buffer_pos += vnp_raw_unpack_uint8(&buf[buffer_pos], &enum_temp);
+       type = (VNRealFormat)enum_temp;
+#if defined V_PRINT_RECEIVE_COMMANDS
+       if(type > VN_FORMAT_REAL64)
+               printf("receive: verse_send_g_layer_unsubscribe(node_id = %u layer_id = %u ); callback = %p\n", node_id, layer_id, v_fs_get_alias_user_func(49));
+       else
+               printf("receive: verse_send_g_layer_subscribe(node_id = %u layer_id = %u type = %u ); callback = %p\n", node_id, layer_id, type, v_fs_get_user_func(49));
+#endif
+       if(type > VN_FORMAT_REAL64)
+       {
+               void (* alias_g_layer_unsubscribe)(void *user_data, VNodeID node_id, VLayerID layer_id);
+               alias_g_layer_unsubscribe = v_fs_get_alias_user_func(49);
+               if(alias_g_layer_unsubscribe != NULL)
+                       alias_g_layer_unsubscribe(v_fs_get_alias_user_data(49), node_id, layer_id);
+               return buffer_pos;
+       }
+       if(func_g_layer_subscribe != NULL)
+               func_g_layer_subscribe(v_fs_get_user_data(49), node_id, layer_id, (VNRealFormat) type);
+
+       return buffer_pos;
+}
+
+void verse_send_g_vertex_set_xyz_real32(VNodeID node_id, VLayerID layer_id, uint32 vertex_id, real32 x, real32 y, real32 z)
+{
+       uint8 *buf;
+       unsigned int buffer_pos = 0;
+       VCMDBufHead *head;
+       head = v_cmd_buf_allocate(VCMDBS_30);/* Allocating the buffer */
+       buf = ((VCMDBuffer10 *)head)->buf;
+
+       buffer_pos += vnp_raw_pack_uint8(&buf[buffer_pos], 50); /* Pack the command. */
+#if defined V_PRINT_SEND_COMMANDS
+       printf("send: verse_send_g_vertex_set_xyz_real32(node_id = %u layer_id = %u vertex_id = %u x = %f y = %f z = %f );\n", node_id, layer_id, vertex_id, x, y, z);
+#endif
+       buffer_pos += vnp_raw_pack_uint32(&buf[buffer_pos], node_id);
+       buffer_pos += vnp_raw_pack_uint16(&buf[buffer_pos], layer_id);
+       buffer_pos += vnp_raw_pack_uint32(&buf[buffer_pos], vertex_id);
+       buffer_pos += vnp_raw_pack_real32(&buf[buffer_pos], x);
+       buffer_pos += vnp_raw_pack_real32(&buf[buffer_pos], y);
+       buffer_pos += vnp_raw_pack_real32(&buf[buffer_pos], z);
+       if(node_id == (uint32)(-1) || layer_id == (uint16)(-1) || vertex_id == (uint32)(-1))
+               v_cmd_buf_set_unique_address_size(head, 11);
+       else
+               v_cmd_buf_set_address_size(head, 11);
+       v_cmd_buf_set_size(head, buffer_pos);
+       v_noq_send_buf(v_con_get_network_queue(), head);
+}
+
+void verse_send_g_vertex_delete_real32(VNodeID node_id, uint32 vertex_id)
+{
+       uint8 *buf;
+       unsigned int buffer_pos = 0;
+       VCMDBufHead *head;
+       head = v_cmd_buf_allocate(VCMDBS_30);/* Allocating the buffer */
+       buf = ((VCMDBuffer10 *)head)->buf;
+
+       buffer_pos += vnp_raw_pack_uint8(&buf[buffer_pos], 50); /* Pack the command. */
+#if defined V_PRINT_SEND_COMMANDS
+       printf("send: verse_send_g_vertex_delete_real32(node_id = %u vertex_id = %u );\n", node_id, vertex_id);
+#endif
+       buffer_pos += vnp_raw_pack_uint32(&buf[buffer_pos], node_id);
+       buffer_pos += vnp_raw_pack_uint16(&buf[buffer_pos], -1);
+       buffer_pos += vnp_raw_pack_uint32(&buf[buffer_pos], vertex_id);
+       buffer_pos += vnp_raw_pack_real32(&buf[buffer_pos], V_REAL32_MAX);
+       buffer_pos += vnp_raw_pack_real32(&buf[buffer_pos], V_REAL32_MAX);
+       buffer_pos += vnp_raw_pack_real32(&buf[buffer_pos], V_REAL32_MAX);
+       if(node_id == (uint32)(-1) || vertex_id == (uint32)(-1))
+               v_cmd_buf_set_unique_address_size(head, 9);
+       else
+               v_cmd_buf_set_address_size(head, 9);
+       v_cmd_buf_set_size(head, buffer_pos);
+       v_noq_send_buf(v_con_get_network_queue(), head);
+}
+
+unsigned int v_unpack_g_vertex_set_xyz_real32(const char *buf, size_t buffer_length)
+{
+       unsigned int buffer_pos = 0;
+       void (* func_g_vertex_set_xyz_real32)(void *user_data, VNodeID node_id, VLayerID layer_id, uint32 vertex_id, real32 x, real32 y, real32 z);
+       VNodeID node_id;
+       VLayerID layer_id;
+       uint32 vertex_id;
+       real32 x;
+       real32 y;
+       real32 z;
+       
+       func_g_vertex_set_xyz_real32 = v_fs_get_user_func(50);
+       if(buffer_length < 10)
+               return -1;
+       buffer_pos += vnp_raw_unpack_uint32(&buf[buffer_pos], &node_id);
+       buffer_pos += vnp_raw_unpack_uint16(&buf[buffer_pos], &layer_id);
+       buffer_pos += vnp_raw_unpack_uint32(&buf[buffer_pos], &vertex_id);
+       buffer_pos += vnp_raw_unpack_real32(&buf[buffer_pos], &x);
+       buffer_pos += vnp_raw_unpack_real32(&buf[buffer_pos], &y);
+       buffer_pos += vnp_raw_unpack_real32(&buf[buffer_pos], &z);
+#if defined V_PRINT_RECEIVE_COMMANDS
+       if(x == V_REAL32_MAX || y == V_REAL32_MAX || z == V_REAL32_MAX)
+               printf("receive: verse_send_g_vertex_delete_real32(node_id = %u vertex_id = %u ); callback = %p\n", node_id, vertex_id, v_fs_get_alias_user_func(50));
+       else
+               printf("receive: verse_send_g_vertex_set_xyz_real32(node_id = %u layer_id = %u vertex_id = %u x = %f y = %f z = %f ); callback = %p\n", node_id, layer_id, vertex_id, x, y, z, v_fs_get_user_func(50));
+#endif
+       if(x == V_REAL32_MAX || y == V_REAL32_MAX || z == V_REAL32_MAX)
+       {
+               void (* alias_g_vertex_delete_real32)(void *user_data, VNodeID node_id, uint32 vertex_id);
+               alias_g_vertex_delete_real32 = v_fs_get_alias_user_func(50);
+               if(alias_g_vertex_delete_real32 != NULL)
+                       alias_g_vertex_delete_real32(v_fs_get_alias_user_data(50), node_id, vertex_id);
+               return buffer_pos;
+       }
+       if(func_g_vertex_set_xyz_real32 != NULL)
+               func_g_vertex_set_xyz_real32(v_fs_get_user_data(50), node_id, layer_id, vertex_id, x, y, z);
+
+       return buffer_pos;
+}
+
+void verse_send_g_vertex_set_xyz_real64(VNodeID node_id, VLayerID layer_id, uint32 vertex_id, real64 x, real64 y, real64 z)
+{
+       uint8 *buf;
+       unsigned int buffer_pos = 0;
+       VCMDBufHead *head;
+       head = v_cmd_buf_allocate(VCMDBS_80);/* Allocating the buffer */
+       buf = ((VCMDBuffer10 *)head)->buf;
+
+       buffer_pos += vnp_raw_pack_uint8(&buf[buffer_pos], 51); /* Pack the command. */
+#if defined V_PRINT_SEND_COMMANDS
+       printf("send: verse_send_g_vertex_set_xyz_real64(node_id = %u layer_id = %u vertex_id = %u x = %f y = %f z = %f );\n", node_id, layer_id, vertex_id, x, y, z);
+#endif
+       buffer_pos += vnp_raw_pack_uint32(&buf[buffer_pos], node_id);
+       buffer_pos += vnp_raw_pack_uint16(&buf[buffer_pos], layer_id);
+       buffer_pos += vnp_raw_pack_uint32(&buf[buffer_pos], vertex_id);
+       buffer_pos += vnp_raw_pack_real64(&buf[buffer_pos], x);
+       buffer_pos += vnp_raw_pack_real64(&buf[buffer_pos], y);
+       buffer_pos += vnp_raw_pack_real64(&buf[buffer_pos], z);
+       if(node_id == (uint32)(-1) || layer_id == (uint16)(-1) || vertex_id == (uint32)(-1))
+               v_cmd_buf_set_unique_address_size(head, 11);
+       else
+               v_cmd_buf_set_address_size(head, 11);
+       v_cmd_buf_set_size(head, buffer_pos);
+       v_noq_send_buf(v_con_get_network_queue(), head);
+}
+
+void verse_send_g_vertex_delete_real64(VNodeID node_id, uint32 vertex_id)
+{
+       uint8 *buf;
+       unsigned int buffer_pos = 0;
+       VCMDBufHead *head;
+       head = v_cmd_buf_allocate(VCMDBS_80);/* Allocating the buffer */
+       buf = ((VCMDBuffer10 *)head)->buf;
+
+       buffer_pos += vnp_raw_pack_uint8(&buf[buffer_pos], 51); /* Pack the command. */
+#if defined V_PRINT_SEND_COMMANDS
+       printf("send: verse_send_g_vertex_delete_real64(node_id = %u vertex_id = %u );\n", node_id, vertex_id);
+#endif
+       buffer_pos += vnp_raw_pack_uint32(&buf[buffer_pos], node_id);
+       buffer_pos += vnp_raw_pack_uint16(&buf[buffer_pos], -1);
+       buffer_pos += vnp_raw_pack_uint32(&buf[buffer_pos], vertex_id);
+       buffer_pos += vnp_raw_pack_real64(&buf[buffer_pos], V_REAL64_MAX);
+       buffer_pos += vnp_raw_pack_real64(&buf[buffer_pos], V_REAL64_MAX);
+       buffer_pos += vnp_raw_pack_real64(&buf[buffer_pos], V_REAL64_MAX);
+       if(node_id == (uint32)(-1) || vertex_id == (uint32)(-1))
+               v_cmd_buf_set_unique_address_size(head, 9);
+       else
+               v_cmd_buf_set_address_size(head, 9);
+       v_cmd_buf_set_size(head, buffer_pos);
+       v_noq_send_buf(v_con_get_network_queue(), head);
+}
+
+unsigned int v_unpack_g_vertex_set_xyz_real64(const char *buf, size_t buffer_length)
+{
+       unsigned int buffer_pos = 0;
+       void (* func_g_vertex_set_xyz_real64)(void *user_data, VNodeID node_id, VLayerID layer_id, uint32 vertex_id, real64 x, real64 y, real64 z);
+       VNodeID node_id;
+       VLayerID layer_id;
+       uint32 vertex_id;
+       real64 x;
+       real64 y;
+       real64 z;
+       
+       func_g_vertex_set_xyz_real64 = v_fs_get_user_func(51);
+       if(buffer_length < 10)
+               return -1;
+       buffer_pos += vnp_raw_unpack_uint32(&buf[buffer_pos], &node_id);
+       buffer_pos += vnp_raw_unpack_uint16(&buf[buffer_pos], &layer_id);
+       buffer_pos += vnp_raw_unpack_uint32(&buf[buffer_pos], &vertex_id);
+       buffer_pos += vnp_raw_unpack_real64(&buf[buffer_pos], &x);
+       buffer_pos += vnp_raw_unpack_real64(&buf[buffer_pos], &y);
+       buffer_pos += vnp_raw_unpack_real64(&buf[buffer_pos], &z);
+#if defined V_PRINT_RECEIVE_COMMANDS
+       if(x == V_REAL64_MAX || y == V_REAL64_MAX || z == V_REAL64_MAX)
+               printf("receive: verse_send_g_vertex_delete_real64(node_id = %u vertex_id = %u ); callback = %p\n", node_id, vertex_id, v_fs_get_alias_user_func(51));
+       else
+               printf("receive: verse_send_g_vertex_set_xyz_real64(node_id = %u layer_id = %u vertex_id = %u x = %f y = %f z = %f ); callback = %p\n", node_id, layer_id, vertex_id, x, y, z, v_fs_get_user_func(51));
+#endif
+       if(x == V_REAL64_MAX || y == V_REAL64_MAX || z == V_REAL64_MAX)
+       {
+               void (* alias_g_vertex_delete_real64)(void *user_data, VNodeID node_id, uint32 vertex_id);
+               alias_g_vertex_delete_real64 = v_fs_get_alias_user_func(51);
+               if(alias_g_vertex_delete_real64 != NULL)
+                       alias_g_vertex_delete_real64(v_fs_get_alias_user_data(51), node_id, vertex_id);
+               return buffer_pos;
+       }
+       if(func_g_vertex_set_xyz_real64 != NULL)
+               func_g_vertex_set_xyz_real64(v_fs_get_user_data(51), node_id, layer_id, vertex_id, x, y, z);
+
+       return buffer_pos;
+}
+
+void verse_send_g_vertex_set_uint32(VNodeID node_id, VLayerID layer_id, uint32 vertex_id, uint32 value)
+{
+       uint8 *buf;
+       unsigned int buffer_pos = 0;
+       VCMDBufHead *head;
+       head = v_cmd_buf_allocate(VCMDBS_20);/* Allocating the buffer */
+       buf = ((VCMDBuffer10 *)head)->buf;
+
+       buffer_pos += vnp_raw_pack_uint8(&buf[buffer_pos], 52); /* Pack the command. */
+#if defined V_PRINT_SEND_COMMANDS
+       printf("send: verse_send_g_vertex_set_uint32(node_id = %u layer_id = %u vertex_id = %u value = %u );\n", node_id, layer_id, vertex_id, value);
+#endif
+       buffer_pos += vnp_raw_pack_uint32(&buf[buffer_pos], node_id);
+       buffer_pos += vnp_raw_pack_uint16(&buf[buffer_pos], layer_id);
+       buffer_pos += vnp_raw_pack_uint32(&buf[buffer_pos], vertex_id);
+       buffer_pos += vnp_raw_pack_uint32(&buf[buffer_pos], value);
+       if(node_id == (uint32)(-1) || layer_id == (uint16)(-1) || vertex_id == (uint32)(-1))
+               v_cmd_buf_set_unique_address_size(head, 11);
+       else
+               v_cmd_buf_set_address_size(head, 11);
+       v_cmd_buf_set_size(head, buffer_pos);
+       v_noq_send_buf(v_con_get_network_queue(), head);
+}
+
+unsigned int v_unpack_g_vertex_set_uint32(const char *buf, size_t buffer_length)
+{
+       unsigned int buffer_pos = 0;
+       void (* func_g_vertex_set_uint32)(void *user_data, VNodeID node_id, VLayerID layer_id, uint32 vertex_id, uint32 value);
+       VNodeID node_id;
+       VLayerID layer_id;
+       uint32 vertex_id;
+       uint32 value;
+       
+       func_g_vertex_set_uint32 = v_fs_get_user_func(52);
+       if(buffer_length < 10)
+               return -1;
+       buffer_pos += vnp_raw_unpack_uint32(&buf[buffer_pos], &node_id);
+       buffer_pos += vnp_raw_unpack_uint16(&buf[buffer_pos], &layer_id);
+       buffer_pos += vnp_raw_unpack_uint32(&buf[buffer_pos], &vertex_id);
+       buffer_pos += vnp_raw_unpack_uint32(&buf[buffer_pos], &value);
+#if defined V_PRINT_RECEIVE_COMMANDS
+       printf("receive: verse_send_g_vertex_set_uint32(node_id = %u layer_id = %u vertex_id = %u value = %u ); callback = %p\n", node_id, layer_id, vertex_id, value, v_fs_get_user_func(52));
+#endif
+       if(func_g_vertex_set_uint32 != NULL)
+               func_g_vertex_set_uint32(v_fs_get_user_data(52), node_id, layer_id, vertex_id, value);
+
+       return buffer_pos;
+}
+
+void verse_send_g_vertex_set_real64(VNodeID node_id, VLayerID layer_id, uint32 vertex_id, real64 value)
+{
+       uint8 *buf;
+       unsigned int buffer_pos = 0;
+       VCMDBufHead *head;
+       head = v_cmd_buf_allocate(VCMDBS_20);/* Allocating the buffer */
+       buf = ((VCMDBuffer10 *)head)->buf;
+
+       buffer_pos += vnp_raw_pack_uint8(&buf[buffer_pos], 53); /* Pack the command. */
+#if defined V_PRINT_SEND_COMMANDS
+       printf("send: verse_send_g_vertex_set_real64(node_id = %u layer_id = %u vertex_id = %u value = %f );\n", node_id, layer_id, vertex_id, value);
+#endif
+       buffer_pos += vnp_raw_pack_uint32(&buf[buffer_pos], node_id);
+       buffer_pos += vnp_raw_pack_uint16(&buf[buffer_pos], layer_id);
+       buffer_pos += vnp_raw_pack_uint32(&buf[buffer_pos], vertex_id);
+       buffer_pos += vnp_raw_pack_real64(&buf[buffer_pos], value);
+       if(node_id == (uint32)(-1) || layer_id == (uint16)(-1) || vertex_id == (uint32)(-1))
+               v_cmd_buf_set_unique_address_size(head, 11);
+       else
+               v_cmd_buf_set_address_size(head, 11);
+       v_cmd_buf_set_size(head, buffer_pos);
+       v_noq_send_buf(v_con_get_network_queue(), head);
+}
+
+unsigned int v_unpack_g_vertex_set_real64(const char *buf, size_t buffer_length)
+{
+       unsigned int buffer_pos = 0;
+       void (* func_g_vertex_set_real64)(void *user_data, VNodeID node_id, VLayerID layer_id, uint32 vertex_id, real64 value);
+       VNodeID node_id;
+       VLayerID layer_id;
+       uint32 vertex_id;
+       real64 value;
+       
+       func_g_vertex_set_real64 = v_fs_get_user_func(53);
+       if(buffer_length < 10)
+               return -1;
+       buffer_pos += vnp_raw_unpack_uint32(&buf[buffer_pos], &node_id);
+       buffer_pos += vnp_raw_unpack_uint16(&buf[buffer_pos], &layer_id);
+       buffer_pos += vnp_raw_unpack_uint32(&buf[buffer_pos], &vertex_id);
+       buffer_pos += vnp_raw_unpack_real64(&buf[buffer_pos], &value);
+#if defined V_PRINT_RECEIVE_COMMANDS
+       printf("receive: verse_send_g_vertex_set_real64(node_id = %u layer_id = %u vertex_id = %u value = %f ); callback = %p\n", node_id, layer_id, vertex_id, value, v_fs_get_user_func(53));
+#endif
+       if(func_g_vertex_set_real64 != NULL)
+               func_g_vertex_set_real64(v_fs_get_user_data(53), node_id, layer_id, vertex_id, value);
+
+       return buffer_pos;
+}
+
+void verse_send_g_vertex_set_real32(VNodeID node_id, VLayerID layer_id, uint32 vertex_id, real32 value)
+{
+       uint8 *buf;
+       unsigned int buffer_pos = 0;
+       VCMDBufHead *head;
+       head = v_cmd_buf_allocate(VCMDBS_20);/* Allocating the buffer */
+       buf = ((VCMDBuffer10 *)head)->buf;
+
+       buffer_pos += vnp_raw_pack_uint8(&buf[buffer_pos], 54); /* Pack the command. */
+#if defined V_PRINT_SEND_COMMANDS
+       printf("send: verse_send_g_vertex_set_real32(node_id = %u layer_id = %u vertex_id = %u value = %f );\n", node_id, layer_id, vertex_id, value);
+#endif
+       buffer_pos += vnp_raw_pack_uint32(&buf[buffer_pos], node_id);
+       buffer_pos += vnp_raw_pack_uint16(&buf[buffer_pos], layer_id);
+       buffer_pos += vnp_raw_pack_uint32(&buf[buffer_pos], vertex_id);
+       buffer_pos += vnp_raw_pack_real32(&buf[buffer_pos], value);
+       if(node_id == (uint32)(-1) || layer_id == (uint16)(-1) || vertex_id == (uint32)(-1))
+               v_cmd_buf_set_unique_address_size(head, 11);
+       else
+               v_cmd_buf_set_address_size(head, 11);
+       v_cmd_buf_set_size(head, buffer_pos);
+       v_noq_send_buf(v_con_get_network_queue(), head);
+}
+
+unsigned int v_unpack_g_vertex_set_real32(const char *buf, size_t buffer_length)
+{
+       unsigned int buffer_pos = 0;
+       void (* func_g_vertex_set_real32)(void *user_data, VNodeID node_id, VLayerID layer_id, uint32 vertex_id, real32 value);
+       VNodeID node_id;
+       VLayerID layer_id;
+       uint32 vertex_id;
+       real32 value;
+       
+       func_g_vertex_set_real32 = v_fs_get_user_func(54);
+       if(buffer_length < 10)
+               return -1;
+       buffer_pos += vnp_raw_unpack_uint32(&buf[buffer_pos], &node_id);
+       buffer_pos += vnp_raw_unpack_uint16(&buf[buffer_pos], &layer_id);
+       buffer_pos += vnp_raw_unpack_uint32(&buf[buffer_pos], &vertex_id);
+       buffer_pos += vnp_raw_unpack_real32(&buf[buffer_pos], &value);
+#if defined V_PRINT_RECEIVE_COMMANDS
+       printf("receive: verse_send_g_vertex_set_real32(node_id = %u layer_id = %u vertex_id = %u value = %f ); callback = %p\n", node_id, layer_id, vertex_id, value, v_fs_get_user_func(54));
+#endif
+       if(func_g_vertex_set_real32 != NULL)
+               func_g_vertex_set_real32(v_fs_get_user_data(54), node_id, layer_id, vertex_id, value);
+
+       return buffer_pos;
+}
+
+void verse_send_g_polygon_set_corner_uint32(VNodeID node_id, VLayerID layer_id, uint32 polygon_id, uint32 v0, uint32 v1, uint32 v2, uint32 v3)
+{
+       uint8 *buf;
+       unsigned int buffer_pos = 0;
+       VCMDBufHead *head;
+       head = v_cmd_buf_allocate(VCMDBS_30);/* Allocating the buffer */
+       buf = ((VCMDBuffer10 *)head)->buf;
+
+       buffer_pos += vnp_raw_pack_uint8(&buf[buffer_pos], 55); /* Pack the command. */
+#if defined V_PRINT_SEND_COMMANDS
+       printf("send: verse_send_g_polygon_set_corner_uint32(node_id = %u layer_id = %u polygon_id = %u v0 = %u v1 = %u v2 = %u v3 = %u );\n", node_id, layer_id, polygon_id, v0, v1, v2, v3);
+#endif
+       buffer_pos += vnp_raw_pack_uint32(&buf[buffer_pos], node_id);
+       buffer_pos += vnp_raw_pack_uint16(&buf[buffer_pos], layer_id);
+       buffer_pos += vnp_raw_pack_uint32(&buf[buffer_pos], polygon_id);
+       buffer_pos += vnp_raw_pack_uint32(&buf[buffer_pos], v0);
+       buffer_pos += vnp_raw_pack_uint32(&buf[buffer_pos], v1);
+       buffer_pos += vnp_raw_pack_uint32(&buf[buffer_pos], v2);
+       buffer_pos += vnp_raw_pack_uint32(&buf[buffer_pos], v3);
+       if(node_id == (uint32)(-1) || layer_id == (uint16)(-1) || polygon_id == (uint32)(-1))
+               v_cmd_buf_set_unique_address_size(head, 11);
+       else
+               v_cmd_buf_set_address_size(head, 11);
+       v_cmd_buf_set_size(head, buffer_pos);
+       v_noq_send_buf(v_con_get_network_queue(), head);
+}
+
+void verse_send_g_polygon_delete(VNodeID node_id, uint32 polygon_id)
+{
+       uint8 *buf;
+       unsigned int buffer_pos = 0;
+       VCMDBufHead *head;
+       head = v_cmd_buf_allocate(VCMDBS_30);/* Allocating the buffer */
+       buf = ((VCMDBuffer10 *)head)->buf;
+
+       buffer_pos += vnp_raw_pack_uint8(&buf[buffer_pos], 55); /* Pack the command. */
+#if defined V_PRINT_SEND_COMMANDS
+       printf("send: verse_send_g_polygon_delete(node_id = %u polygon_id = %u );\n", node_id, polygon_id);
+#endif
+       buffer_pos += vnp_raw_pack_uint32(&buf[buffer_pos], node_id);
+       buffer_pos += vnp_raw_pack_uint16(&buf[buffer_pos], -1);
+       buffer_pos += vnp_raw_pack_uint32(&buf[buffer_pos], polygon_id);
+       buffer_pos += vnp_raw_pack_uint32(&buf[buffer_pos], -1);
+       buffer_pos += vnp_raw_pack_uint32(&buf[buffer_pos], -1);
+       buffer_pos += vnp_raw_pack_uint32(&buf[buffer_pos], -1);
+       buffer_pos += vnp_raw_pack_uint32(&buf[buffer_pos], -1);
+       if(node_id == (uint32)(-1) || polygon_id == (uint32)(-1))
+               v_cmd_buf_set_unique_address_size(head, 9);
+       else
+               v_cmd_buf_set_address_size(head, 9);
+       v_cmd_buf_set_size(head, buffer_pos);
+       v_noq_send_buf(v_con_get_network_queue(), head);
+}
+
+unsigned int v_unpack_g_polygon_set_corner_uint32(const char *buf, size_t buffer_length)
+{
+       unsigned int buffer_pos = 0;
+       void (* func_g_polygon_set_corner_uint32)(void *user_data, VNodeID node_id, VLayerID layer_id, uint32 polygon_id, uint32 v0, uint32 v1, uint32 v2, uint32 v3);
+       VNodeID node_id;
+       VLayerID layer_id;
+       uint32 polygon_id;
+       uint32 v0;
+       uint32 v1;
+       uint32 v2;
+       uint32 v3;
+       
+       func_g_polygon_set_corner_uint32 = v_fs_get_user_func(55);
+       if(buffer_length < 10)
+               return -1;
+       buffer_pos += vnp_raw_unpack_uint32(&buf[buffer_pos], &node_id);
+       buffer_pos += vnp_raw_unpack_uint16(&buf[buffer_pos], &layer_id);
+       buffer_pos += vnp_raw_unpack_uint32(&buf[buffer_pos], &polygon_id);
+       buffer_pos += vnp_raw_unpack_uint32(&buf[buffer_pos], &v0);
+       buffer_pos += vnp_raw_unpack_uint32(&buf[buffer_pos], &v1);
+       buffer_pos += vnp_raw_unpack_uint32(&buf[buffer_pos], &v2);
+       buffer_pos += vnp_raw_unpack_uint32(&buf[buffer_pos], &v3);
+#if defined V_PRINT_RECEIVE_COMMANDS
+       if(layer_id == (VLayerID) ~0)
+               printf("receive: verse_send_g_polygon_delete(node_id = %u polygon_id = %u ); callback = %p\n", node_id, polygon_id, v_fs_get_alias_user_func(55));
+       else
+               printf("receive: verse_send_g_polygon_set_corner_uint32(node_id = %u layer_id = %u polygon_id = %u v0 = %u v1 = %u v2 = %u v3 = %u ); callback = %p\n", node_id, layer_id, polygon_id, v0, v1, v2, v3, v_fs_get_user_func(55));
+#endif
+       if(layer_id == (VLayerID) ~0)
+       {
+               void (* alias_g_polygon_delete)(void *user_data, VNodeID node_id, uint32 polygon_id);
+               alias_g_polygon_delete = v_fs_get_alias_user_func(55);
+               if(alias_g_polygon_delete != NULL)
+                       alias_g_polygon_delete(v_fs_get_alias_user_data(55), node_id, polygon_id);
+               return buffer_pos;
+       }
+       if(func_g_polygon_set_corner_uint32 != NULL)
+               func_g_polygon_set_corner_uint32(v_fs_get_user_data(55), node_id, layer_id, polygon_id, v0, v1, v2, v3);
+
+       return buffer_pos;
+}
+
+void verse_send_g_polygon_set_corner_real64(VNodeID node_id, VLayerID layer_id, uint32 polygon_id, real64 v0, real64 v1, real64 v2, real64 v3)
+{
+       uint8 *buf;
+       unsigned int buffer_pos = 0;
+       VCMDBufHead *head;
+       head = v_cmd_buf_allocate(VCMDBS_80);/* Allocating the buffer */
+       buf = ((VCMDBuffer10 *)head)->buf;
+
+       buffer_pos += vnp_raw_pack_uint8(&buf[buffer_pos], 56); /* Pack the command. */
+#if defined V_PRINT_SEND_COMMANDS
+       printf("send: verse_send_g_polygon_set_corner_real64(node_id = %u layer_id = %u polygon_id = %u v0 = %f v1 = %f v2 = %f v3 = %f );\n", node_id, layer_id, polygon_id, v0, v1, v2, v3);
+#endif
+       buffer_pos += vnp_raw_pack_uint32(&buf[buffer_pos], node_id);
+       buffer_pos += vnp_raw_pack_uint16(&buf[buffer_pos], layer_id);
+       buffer_pos += vnp_raw_pack_uint32(&buf[buffer_pos], polygon_id);
+       buffer_pos += vnp_raw_pack_real64(&buf[buffer_pos], v0);
+       buffer_pos += vnp_raw_pack_real64(&buf[buffer_pos], v1);
+       buffer_pos += vnp_raw_pack_real64(&buf[buffer_pos], v2);
+       buffer_pos += vnp_raw_pack_real64(&buf[buffer_pos], v3);
+       if(node_id == (uint32)(-1) || layer_id == (uint16)(-1) || polygon_id == (uint32)(-1))
+               v_cmd_buf_set_unique_address_size(head, 11);
+       else
+               v_cmd_buf_set_address_size(head, 11);
+       v_cmd_buf_set_size(head, buffer_pos);
+       v_noq_send_buf(v_con_get_network_queue(), head);
+}
+
+unsigned int v_unpack_g_polygon_set_corner_real64(const char *buf, size_t buffer_length)
+{
+       unsigned int buffer_pos = 0;
+       void (* func_g_polygon_set_corner_real64)(void *user_data, VNodeID node_id, VLayerID layer_id, uint32 polygon_id, real64 v0, real64 v1, real64 v2, real64 v3);
+       VNodeID node_id;
+       VLayerID layer_id;
+       uint32 polygon_id;
+       real64 v0;
+       real64 v1;
+       real64 v2;
+       real64 v3;
+       
+       func_g_polygon_set_corner_real64 = v_fs_get_user_func(56);
+       if(buffer_length < 10)
+               return -1;
+       buffer_pos += vnp_raw_unpack_uint32(&buf[buffer_pos], &node_id);
+       buffer_pos += vnp_raw_unpack_uint16(&buf[buffer_pos], &layer_id);
+       buffer_pos += vnp_raw_unpack_uint32(&buf[buffer_pos], &polygon_id);
+       buffer_pos += vnp_raw_unpack_real64(&buf[buffer_pos], &v0);
+       buffer_pos += vnp_raw_unpack_real64(&buf[buffer_pos], &v1);
+       buffer_pos += vnp_raw_unpack_real64(&buf[buffer_pos], &v2);
+       buffer_pos += vnp_raw_unpack_real64(&buf[buffer_pos], &v3);
+#if defined V_PRINT_RECEIVE_COMMANDS
+       printf("receive: verse_send_g_polygon_set_corner_real64(node_id = %u layer_id = %u polygon_id = %u v0 = %f v1 = %f v2 = %f v3 = %f ); callback = %p\n", node_id, layer_id, polygon_id, v0, v1, v2, v3, v_fs_get_user_func(56));
+#endif
+       if(func_g_polygon_set_corner_real64 != NULL)
+               func_g_polygon_set_corner_real64(v_fs_get_user_data(56), node_id, layer_id, polygon_id, v0, v1, v2, v3);
+
+       return buffer_pos;
+}
+
+void verse_send_g_polygon_set_corner_real32(VNodeID node_id, VLayerID layer_id, uint32 polygon_id, real32 v0, real32 v1, real32 v2, real32 v3)
+{
+       uint8 *buf;
+       unsigned int buffer_pos = 0;
+       VCMDBufHead *head;
+       head = v_cmd_buf_allocate(VCMDBS_30);/* Allocating the buffer */
+       buf = ((VCMDBuffer10 *)head)->buf;
+
+       buffer_pos += vnp_raw_pack_uint8(&buf[buffer_pos], 57); /* Pack the command. */
+#if defined V_PRINT_SEND_COMMANDS
+       printf("send: verse_send_g_polygon_set_corner_real32(node_id = %u layer_id = %u polygon_id = %u v0 = %f v1 = %f v2 = %f v3 = %f );\n", node_id, layer_id, polygon_id, v0, v1, v2, v3);
+#endif
+       buffer_pos += vnp_raw_pack_uint32(&buf[buffer_pos], node_id);
+       buffer_pos += vnp_raw_pack_uint16(&buf[buffer_pos], layer_id);
+       buffer_pos += vnp_raw_pack_uint32(&buf[buffer_pos], polygon_id);
+       buffer_pos += vnp_raw_pack_real32(&buf[buffer_pos], v0);
+       buffer_pos += vnp_raw_pack_real32(&buf[buffer_pos], v1);
+       buffer_pos += vnp_raw_pack_real32(&buf[buffer_pos], v2);
+       buffer_pos += vnp_raw_pack_real32(&buf[buffer_pos], v3);
+       if(node_id == (uint32)(-1) || layer_id == (uint16)(-1) || polygon_id == (uint32)(-1))
+               v_cmd_buf_set_unique_address_size(head, 11);
+       else
+               v_cmd_buf_set_address_size(head, 11);
+       v_cmd_buf_set_size(head, buffer_pos);
+       v_noq_send_buf(v_con_get_network_queue(), head);
+}
+
+unsigned int v_unpack_g_polygon_set_corner_real32(const char *buf, size_t buffer_length)
+{
+       unsigned int buffer_pos = 0;
+       void (* func_g_polygon_set_corner_real32)(void *user_data, VNodeID node_id, VLayerID layer_id, uint32 polygon_id, real32 v0, real32 v1, real32 v2, real32 v3);
+       VNodeID node_id;
+       VLayerID layer_id;
+       uint32 polygon_id;
+       real32 v0;
+       real32 v1;
+       real32 v2;
+       real32 v3;
+       
+       func_g_polygon_set_corner_real32 = v_fs_get_user_func(57);
+       if(buffer_length < 10)
+               return -1;
+       buffer_pos += vnp_raw_unpack_uint32(&buf[buffer_pos], &node_id);
+       buffer_pos += vnp_raw_unpack_uint16(&buf[buffer_pos], &layer_id);
+       buffer_pos += vnp_raw_unpack_uint32(&buf[buffer_pos], &polygon_id);
+       buffer_pos += vnp_raw_unpack_real32(&buf[buffer_pos], &v0);
+       buffer_pos += vnp_raw_unpack_real32(&buf[buffer_pos], &v1);
+       buffer_pos += vnp_raw_unpack_real32(&buf[buffer_pos], &v2);
+       buffer_pos += vnp_raw_unpack_real32(&buf[buffer_pos], &v3);
+#if defined V_PRINT_RECEIVE_COMMANDS
+       printf("receive: verse_send_g_polygon_set_corner_real32(node_id = %u layer_id = %u polygon_id = %u v0 = %f v1 = %f v2 = %f v3 = %f ); callback = %p\n", node_id, layer_id, polygon_id, v0, v1, v2, v3, v_fs_get_user_func(57));
+#endif
+       if(func_g_polygon_set_corner_real32 != NULL)
+               func_g_polygon_set_corner_real32(v_fs_get_user_data(57), node_id, layer_id, polygon_id, v0, v1, v2, v3);
+
+       return buffer_pos;
+}
+
+void verse_send_g_polygon_set_face_uint8(VNodeID node_id, VLayerID layer_id, uint32 polygon_id, uint8 value)
+{
+       uint8 *buf;
+       unsigned int buffer_pos = 0;
+       VCMDBufHead *head;
+       head = v_cmd_buf_allocate(VCMDBS_20);/* Allocating the buffer */
+       buf = ((VCMDBuffer10 *)head)->buf;
+
+       buffer_pos += vnp_raw_pack_uint8(&buf[buffer_pos], 58); /* Pack the command. */
+#if defined V_PRINT_SEND_COMMANDS
+       printf("send: verse_send_g_polygon_set_face_uint8(node_id = %u layer_id = %u polygon_id = %u value = %u );\n", node_id, layer_id, polygon_id, value);
+#endif
+       buffer_pos += vnp_raw_pack_uint32(&buf[buffer_pos], node_id);
+       buffer_pos += vnp_raw_pack_uint16(&buf[buffer_pos], layer_id);
+       buffer_pos += vnp_raw_pack_uint32(&buf[buffer_pos], polygon_id);
+       buffer_pos += vnp_raw_pack_uint8(&buf[buffer_pos], value);
+       if(node_id == (uint32)(-1) || layer_id == (uint16)(-1) || polygon_id == (uint32)(-1))
+               v_cmd_buf_set_unique_address_size(head, 11);
+       else
+               v_cmd_buf_set_address_size(head, 11);
+       v_cmd_buf_set_size(head, buffer_pos);
+       v_noq_send_buf(v_con_get_network_queue(), head);
+}
+
+unsigned int v_unpack_g_polygon_set_face_uint8(const char *buf, size_t buffer_length)
+{
+       unsigned int buffer_pos = 0;
+       void (* func_g_polygon_set_face_uint8)(void *user_data, VNodeID node_id, VLayerID layer_id, uint32 polygon_id, uint8 value);
+       VNodeID node_id;
+       VLayerID layer_id;
+       uint32 polygon_id;
+       uint8 value;
+       
+       func_g_polygon_set_face_uint8 = v_fs_get_user_func(58);
+       if(buffer_length < 10)
+               return -1;
+       buffer_pos += vnp_raw_unpack_uint32(&buf[buffer_pos], &node_id);
+       buffer_pos += vnp_raw_unpack_uint16(&buf[buffer_pos], &layer_id);
+       buffer_pos += vnp_raw_unpack_uint32(&buf[buffer_pos], &polygon_id);
+       buffer_pos += vnp_raw_unpack_uint8(&buf[buffer_pos], &value);
+#if defined V_PRINT_RECEIVE_COMMANDS
+       printf("receive: verse_send_g_polygon_set_face_uint8(node_id = %u layer_id = %u polygon_id = %u value = %u ); callback = %p\n", node_id, layer_id, polygon_id, value, v_fs_get_user_func(58));
+#endif
+       if(func_g_polygon_set_face_uint8 != NULL)
+               func_g_polygon_set_face_uint8(v_fs_get_user_data(58), node_id, layer_id, polygon_id, value);
+
+       return buffer_pos;
+}
+
+void verse_send_g_polygon_set_face_uint32(VNodeID node_id, VLayerID layer_id, uint32 polygon_id, uint32 value)
+{
+       uint8 *buf;
+       unsigned int buffer_pos = 0;
+       VCMDBufHead *head;
+       head = v_cmd_buf_allocate(VCMDBS_20);/* Allocating the buffer */
+       buf = ((VCMDBuffer10 *)head)->buf;
+
+       buffer_pos += vnp_raw_pack_uint8(&buf[buffer_pos], 59); /* Pack the command. */
+#if defined V_PRINT_SEND_COMMANDS
+       printf("send: verse_send_g_polygon_set_face_uint32(node_id = %u layer_id = %u polygon_id = %u value = %u );\n", node_id, layer_id, polygon_id, value);
+#endif
+       buffer_pos += vnp_raw_pack_uint32(&buf[buffer_pos], node_id);
+       buffer_pos += vnp_raw_pack_uint16(&buf[buffer_pos], layer_id);
+       buffer_pos += vnp_raw_pack_uint32(&buf[buffer_pos], polygon_id);
+       buffer_pos += vnp_raw_pack_uint32(&buf[buffer_pos], value);
+       if(node_id == (uint32)(-1) || layer_id == (uint16)(-1) || polygon_id == (uint32)(-1))
+               v_cmd_buf_set_unique_address_size(head, 11);
+       else
+               v_cmd_buf_set_address_size(head, 11);
+       v_cmd_buf_set_size(head, buffer_pos);
+       v_noq_send_buf(v_con_get_network_queue(), head);
+}
+
+unsigned int v_unpack_g_polygon_set_face_uint32(const char *buf, size_t buffer_length)
+{
+       unsigned int buffer_pos = 0;
+       void (* func_g_polygon_set_face_uint32)(void *user_data, VNodeID node_id, VLayerID layer_id, uint32 polygon_id, uint32 value);
+       VNodeID node_id;
+       VLayerID layer_id;
+       uint32 polygon_id;
+       uint32 value;
+       
+       func_g_polygon_set_face_uint32 = v_fs_get_user_func(59);
+       if(buffer_length < 10)
+               return -1;
+       buffer_pos += vnp_raw_unpack_uint32(&buf[buffer_pos], &node_id);
+       buffer_pos += vnp_raw_unpack_uint16(&buf[buffer_pos], &layer_id);
+       buffer_pos += vnp_raw_unpack_uint32(&buf[buffer_pos], &polygon_id);
+       buffer_pos += vnp_raw_unpack_uint32(&buf[buffer_pos], &value);
+#if defined V_PRINT_RECEIVE_COMMANDS
+       printf("receive: verse_send_g_polygon_set_face_uint32(node_id = %u layer_id = %u polygon_id = %u value = %u ); callback = %p\n", node_id, layer_id, polygon_id, value, v_fs_get_user_func(59));
+#endif
+       if(func_g_polygon_set_face_uint32 != NULL)
+               func_g_polygon_set_face_uint32(v_fs_get_user_data(59), node_id, layer_id, polygon_id, value);
+
+       return buffer_pos;
+}
+
+void verse_send_g_polygon_set_face_real64(VNodeID node_id, VLayerID layer_id, uint32 polygon_id, real64 value)
+{
+       uint8 *buf;
+       unsigned int buffer_pos = 0;
+       VCMDBufHead *head;
+       head = v_cmd_buf_allocate(VCMDBS_20);/* Allocating the buffer */
+       buf = ((VCMDBuffer10 *)head)->buf;
+
+       buffer_pos += vnp_raw_pack_uint8(&buf[buffer_pos], 60); /* Pack the command. */
+#if defined V_PRINT_SEND_COMMANDS
+       printf("send: verse_send_g_polygon_set_face_real64(node_id = %u layer_id = %u polygon_id = %u value = %f );\n", node_id, layer_id, polygon_id, value);
+#endif
+       buffer_pos += vnp_raw_pack_uint32(&buf[buffer_pos], node_id);
+       buffer_pos += vnp_raw_pack_uint16(&buf[buffer_pos], layer_id);
+       buffer_pos += vnp_raw_pack_uint32(&buf[buffer_pos], polygon_id);
+       buffer_pos += vnp_raw_pack_real64(&buf[buffer_pos], value);
+       if(node_id == (uint32)(-1) || layer_id == (uint16)(-1) || polygon_id == (uint32)(-1))
+               v_cmd_buf_set_unique_address_size(head, 11);
+       else
+               v_cmd_buf_set_address_size(head, 11);
+       v_cmd_buf_set_size(head, buffer_pos);
+       v_noq_send_buf(v_con_get_network_queue(), head);
+}
+
+unsigned int v_unpack_g_polygon_set_face_real64(const char *buf, size_t buffer_length)
+{
+       unsigned int buffer_pos = 0;
+       void (* func_g_polygon_set_face_real64)(void *user_data, VNodeID node_id, VLayerID layer_id, uint32 polygon_id, real64 value);
+       VNodeID node_id;
+       VLayerID layer_id;
+       uint32 polygon_id;
+       real64 value;
+       
+       func_g_polygon_set_face_real64 = v_fs_get_user_func(60);
+       if(buffer_length < 10)
+               return -1;
+       buffer_pos += vnp_raw_unpack_uint32(&buf[buffer_pos], &node_id);
+       buffer_pos += vnp_raw_unpack_uint16(&buf[buffer_pos], &layer_id);
+       buffer_pos += vnp_raw_unpack_uint32(&buf[buffer_pos], &polygon_id);
+       buffer_pos += vnp_raw_unpack_real64(&buf[buffer_pos], &value);
+#if defined V_PRINT_RECEIVE_COMMANDS
+       printf("receive: verse_send_g_polygon_set_face_real64(node_id = %u layer_id = %u polygon_id = %u value = %f ); callback = %p\n", node_id, layer_id, polygon_id, value, v_fs_get_user_func(60));
+#endif
+       if(func_g_polygon_set_face_real64 != NULL)
+               func_g_polygon_set_face_real64(v_fs_get_user_data(60), node_id, layer_id, polygon_id, value);
+
+       return buffer_pos;
+}
+
+void verse_send_g_polygon_set_face_real32(VNodeID node_id, VLayerID layer_id, uint32 polygon_id, real32 value)
+{
+       uint8 *buf;
+       unsigned int buffer_pos = 0;
+       VCMDBufHead *head;
+       head = v_cmd_buf_allocate(VCMDBS_20);/* Allocating the buffer */
+       buf = ((VCMDBuffer10 *)head)->buf;
+
+       buffer_pos += vnp_raw_pack_uint8(&buf[buffer_pos], 61); /* Pack the command. */
+#if defined V_PRINT_SEND_COMMANDS
+       printf("send: verse_send_g_polygon_set_face_real32(node_id = %u layer_id = %u polygon_id = %u value = %f );\n", node_id, layer_id, polygon_id, value);
+#endif
+       buffer_pos += vnp_raw_pack_uint32(&buf[buffer_pos], node_id);
+       buffer_pos += vnp_raw_pack_uint16(&buf[buffer_pos], layer_id);
+       buffer_pos += vnp_raw_pack_uint32(&buf[buffer_pos], polygon_id);
+       buffer_pos += vnp_raw_pack_real32(&buf[buffer_pos], value);
+       if(node_id == (uint32)(-1) || layer_id == (uint16)(-1) || polygon_id == (uint32)(-1))
+               v_cmd_buf_set_unique_address_size(head, 11);
+       else
+               v_cmd_buf_set_address_size(head, 11);
+       v_cmd_buf_set_size(head, buffer_pos);
+       v_noq_send_buf(v_con_get_network_queue(), head);
+}
+
+unsigned int v_unpack_g_polygon_set_face_real32(const char *buf, size_t buffer_length)
+{
+       unsigned int buffer_pos = 0;
+       void (* func_g_polygon_set_face_real32)(void *user_data, VNodeID node_id, VLayerID layer_id, uint32 polygon_id, real32 value);
+       VNodeID node_id;
+       VLayerID layer_id;
+       uint32 polygon_id;
+       real32 value;
+       
+       func_g_polygon_set_face_real32 = v_fs_get_user_func(61);
+       if(buffer_length < 10)
+               return -1;
+       buffer_pos += vnp_raw_unpack_uint32(&buf[buffer_pos], &node_id);
+       buffer_pos += vnp_raw_unpack_uint16(&buf[buffer_pos], &layer_id);
+       buffer_pos += vnp_raw_unpack_uint32(&buf[buffer_pos], &polygon_id);
+       buffer_pos += vnp_raw_unpack_real32(&buf[buffer_pos], &value);
+#if defined V_PRINT_RECEIVE_COMMANDS
+       printf("receive: verse_send_g_polygon_set_face_real32(node_id = %u layer_id = %u polygon_id = %u value = %f ); callback = %p\n", node_id, layer_id, polygon_id, value, v_fs_get_user_func(61));
+#endif
+       if(func_g_polygon_set_face_real32 != NULL)
+               func_g_polygon_set_face_real32(v_fs_get_user_data(61), node_id, layer_id, polygon_id, value);
+
+       return buffer_pos;
+}
+
+void verse_send_g_crease_set_vertex(VNodeID node_id, const char *layer, uint32 def_crease)
+{
+       uint8 *buf;
+       unsigned int buffer_pos = 0;
+       VCMDBufHead *head;
+       head = v_cmd_buf_allocate(VCMDBS_30);/* Allocating the buffer */
+       buf = ((VCMDBuffer10 *)head)->buf;
+
+       buffer_pos += vnp_raw_pack_uint8(&buf[buffer_pos], 62); /* Pack the command. */
+#if defined V_PRINT_SEND_COMMANDS
+       printf("send: verse_send_g_crease_set_vertex(node_id = %u layer = %s def_crease = %u );\n", node_id, layer, def_crease);
+#endif
+       buffer_pos += vnp_raw_pack_uint32(&buf[buffer_pos], node_id);
+       buffer_pos += vnp_raw_pack_string(&buf[buffer_pos], layer, 16);
+       buffer_pos += vnp_raw_pack_uint32(&buf[buffer_pos], def_crease);
+       if(node_id == (uint32)(-1))
+               v_cmd_buf_set_unique_address_size(head, 5);
+       else
+               v_cmd_buf_set_address_size(head, 5);
+       v_cmd_buf_set_size(head, buffer_pos);
+       v_noq_send_buf(v_con_get_network_queue(), head);
+}
+
+unsigned int v_unpack_g_crease_set_vertex(const char *buf, size_t buffer_length)
+{
+       unsigned int buffer_pos = 0;
+       void (* func_g_crease_set_vertex)(void *user_data, VNodeID node_id, const char *layer, uint32 def_crease);
+       VNodeID node_id;
+       char layer[16];
+       uint32 def_crease;
+       
+       func_g_crease_set_vertex = v_fs_get_user_func(62);
+       if(buffer_length < 4)
+               return -1;
+       buffer_pos += vnp_raw_unpack_uint32(&buf[buffer_pos], &node_id);
+       buffer_pos += vnp_raw_unpack_string(&buf[buffer_pos], layer, 16, buffer_length - buffer_pos);
+       if(buffer_length < 4 + buffer_pos)
+               return -1;
+       buffer_pos += vnp_raw_unpack_uint32(&buf[buffer_pos], &def_crease);
+#if defined V_PRINT_RECEIVE_COMMANDS
+       printf("receive: verse_send_g_crease_set_vertex(node_id = %u layer = %s def_crease = %u ); callback = %p\n", node_id, layer, def_crease, v_fs_get_user_func(62));
+#endif
+       if(func_g_crease_set_vertex != NULL)
+               func_g_crease_set_vertex(v_fs_get_user_data(62), node_id, layer, def_crease);
+
+       return buffer_pos;
+}
+
+void verse_send_g_crease_set_edge(VNodeID node_id, const char *layer, uint32 def_crease)
+{
+       uint8 *buf;
+       unsigned int buffer_pos = 0;
+       VCMDBufHead *head;
+       head = v_cmd_buf_allocate(VCMDBS_30);/* Allocating the buffer */
+       buf = ((VCMDBuffer10 *)head)->buf;
+
+       buffer_pos += vnp_raw_pack_uint8(&buf[buffer_pos], 63); /* Pack the command. */
+#if defined V_PRINT_SEND_COMMANDS
+       printf("send: verse_send_g_crease_set_edge(node_id = %u layer = %s def_crease = %u );\n", node_id, layer, def_crease);
+#endif
+       buffer_pos += vnp_raw_pack_uint32(&buf[buffer_pos], node_id);
+       buffer_pos += vnp_raw_pack_string(&buf[buffer_pos], layer, 16);
+       buffer_pos += vnp_raw_pack_uint32(&buf[buffer_pos], def_crease);
+       if(node_id == (uint32)(-1))
+               v_cmd_buf_set_unique_address_size(head, 5);
+       else
+               v_cmd_buf_set_address_size(head, 5);
+       v_cmd_buf_set_size(head, buffer_pos);
+       v_noq_send_buf(v_con_get_network_queue(), head);
+}
+
+unsigned int v_unpack_g_crease_set_edge(const char *buf, size_t buffer_length)
+{
+       unsigned int buffer_pos = 0;
+       void (* func_g_crease_set_edge)(void *user_data, VNodeID node_id, const char *layer, uint32 def_crease);
+       VNodeID node_id;
+       char layer[16];
+       uint32 def_crease;
+       
+       func_g_crease_set_edge = v_fs_get_user_func(63);
+       if(buffer_length < 4)
+               return -1;
+       buffer_pos += vnp_raw_unpack_uint32(&buf[buffer_pos], &node_id);
+       buffer_pos += vnp_raw_unpack_string(&buf[buffer_pos], layer, 16, buffer_length - buffer_pos);
+       if(buffer_length < 4 + buffer_pos)
+               return -1;
+       buffer_pos += vnp_raw_unpack_uint32(&buf[buffer_pos], &def_crease);
+#if defined V_PRINT_RECEIVE_COMMANDS
+       printf("receive: verse_send_g_crease_set_edge(node_id = %u layer = %s def_crease = %u ); callback = %p\n", node_id, layer, def_crease, v_fs_get_user_func(63));
+#endif
+       if(func_g_crease_set_edge != NULL)
+               func_g_crease_set_edge(v_fs_get_user_data(63), node_id, layer, def_crease);
+
+       return buffer_pos;
+}
+
+void verse_send_g_bone_create(VNodeID node_id, uint16 bone_id, const char *weight, const char *reference, uint16 parent, real64 pos_x, real64 pos_y, real64 pos_z, const char *pos_label, const VNQuat64 *rot, const char *rot_label)
+{
+       uint8 *buf;
+       unsigned int buffer_pos = 0;
+       VCMDBufHead *head;
+       head = v_cmd_buf_allocate(VCMDBS_1500);/* Allocating the buffer */
+       buf = ((VCMDBuffer10 *)head)->buf;
+
+       buffer_pos += vnp_raw_pack_uint8(&buf[buffer_pos], 64); /* Pack the command. */
+#if defined V_PRINT_SEND_COMMANDS
+       printf("send: verse_send_g_bone_create(node_id = %u bone_id = %u weight = %s reference = %s parent = %u pos_x = %f pos_y = %f pos_z = %f pos_label = %s rot = %p rot_label = %s );\n", node_id, bone_id, weight, reference, parent, pos_x, pos_y, pos_z, pos_label, rot, rot_label);
+#endif
+       buffer_pos += vnp_raw_pack_uint32(&buf[buffer_pos], node_id);
+       buffer_pos += vnp_raw_pack_uint16(&buf[buffer_pos]