Recovered from microbel

This commit is contained in:
rot
2025-03-05 08:35:31 +01:00
committed by h7x4
commit 88b92402a8
601 changed files with 82177 additions and 0 deletions

1
common/lib/Makefile.am Normal file
View File

@@ -0,0 +1 @@
SUBDIRS=texture utils world gos srvcli geometry crypto

284
common/lib/Makefile.in Normal file
View File

@@ -0,0 +1,284 @@
# Makefile.in generated automatically by automake 1.4 from Makefile.am
# Copyright (C) 1994, 1995-8, 1999 Free Software Foundation, Inc.
# This Makefile.in is free software; the Free Software Foundation
# gives unlimited permission to copy and/or distribute it,
# with or without modifications, as long as this notice is preserved.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY, to the extent permitted by law; without
# even the implied warranty of MERCHANTABILITY or FITNESS FOR A
# PARTICULAR PURPOSE.
SHELL = @SHELL@
srcdir = @srcdir@
top_srcdir = @top_srcdir@
VPATH = @srcdir@
prefix = @prefix@
exec_prefix = @exec_prefix@
bindir = @bindir@
sbindir = @sbindir@
libexecdir = @libexecdir@
datadir = @datadir@
sysconfdir = @sysconfdir@
sharedstatedir = @sharedstatedir@
localstatedir = @localstatedir@
libdir = @libdir@
infodir = @infodir@
mandir = @mandir@
includedir = @includedir@
oldincludedir = /usr/include
DESTDIR =
pkgdatadir = $(datadir)/@PACKAGE@
pkglibdir = $(libdir)/@PACKAGE@
pkgincludedir = $(includedir)/@PACKAGE@
top_builddir = ../..
ACLOCAL = @ACLOCAL@
AUTOCONF = @AUTOCONF@
AUTOMAKE = @AUTOMAKE@
AUTOHEADER = @AUTOHEADER@
INSTALL = @INSTALL@
INSTALL_PROGRAM = @INSTALL_PROGRAM@ $(AM_INSTALL_PROGRAM_FLAGS)
INSTALL_DATA = @INSTALL_DATA@
INSTALL_SCRIPT = @INSTALL_SCRIPT@
transform = @program_transform_name@
NORMAL_INSTALL = :
PRE_INSTALL = :
POST_INSTALL = :
NORMAL_UNINSTALL = :
PRE_UNINSTALL = :
POST_UNINSTALL = :
CC = @CC@
CXX = @CXX@
GL_CFLAGS = @GL_CFLAGS@
GL_LIBS = @GL_LIBS@
LEX = @LEX@
MAKEINFO = @MAKEINFO@
NETLIBS = @NETLIBS@
PACKAGE = @PACKAGE@
RANLIB = @RANLIB@
TIFF_CFLAGS = @TIFF_CFLAGS@
TIFF_LIBS = @TIFF_LIBS@
VERSION = @VERSION@
YACC = @YACC@
SUBDIRS = texture utils world gos srvcli geometry crypto
mkinstalldirs = $(SHELL) $(top_srcdir)/mkinstalldirs
CONFIG_CLEAN_FILES =
DIST_COMMON = Makefile.am Makefile.in
DISTFILES = $(DIST_COMMON) $(SOURCES) $(HEADERS) $(TEXINFOS) $(EXTRA_DIST)
TAR = gtar
GZIP_ENV = --best
all: all-redirect
.SUFFIXES:
$(srcdir)/Makefile.in: Makefile.am $(top_srcdir)/configure.in $(ACLOCAL_M4)
cd $(top_srcdir) && $(AUTOMAKE) --foreign common/lib/Makefile
Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status $(BUILT_SOURCES)
cd $(top_builddir) \
&& CONFIG_FILES=$(subdir)/$@ CONFIG_HEADERS= $(SHELL) ./config.status
# This directory's subdirectories are mostly independent; you can cd
# into them and run `make' without going through this Makefile.
# To change the values of `make' variables: instead of editing Makefiles,
# (1) if the variable is set in `config.status', edit `config.status'
# (which will cause the Makefiles to be regenerated when you run `make');
# (2) otherwise, pass the desired values on the `make' command line.
@SET_MAKE@
all-recursive install-data-recursive install-exec-recursive \
installdirs-recursive install-recursive uninstall-recursive \
check-recursive installcheck-recursive info-recursive dvi-recursive:
@set fnord $(MAKEFLAGS); amf=$$2; \
dot_seen=no; \
target=`echo $@ | sed s/-recursive//`; \
list='$(SUBDIRS)'; for subdir in $$list; do \
echo "Making $$target in $$subdir"; \
if test "$$subdir" = "."; then \
dot_seen=yes; \
local_target="$$target-am"; \
else \
local_target="$$target"; \
fi; \
(cd $$subdir && $(MAKE) $(AM_MAKEFLAGS) $$local_target) \
|| case "$$amf" in *=*) exit 1;; *k*) fail=yes;; *) exit 1;; esac; \
done; \
if test "$$dot_seen" = "no"; then \
$(MAKE) $(AM_MAKEFLAGS) "$$target-am" || exit 1; \
fi; test -z "$$fail"
mostlyclean-recursive clean-recursive distclean-recursive \
maintainer-clean-recursive:
@set fnord $(MAKEFLAGS); amf=$$2; \
dot_seen=no; \
rev=''; list='$(SUBDIRS)'; for subdir in $$list; do \
rev="$$subdir $$rev"; \
test "$$subdir" = "." && dot_seen=yes; \
done; \
test "$$dot_seen" = "no" && rev=". $$rev"; \
target=`echo $@ | sed s/-recursive//`; \
for subdir in $$rev; do \
echo "Making $$target in $$subdir"; \
if test "$$subdir" = "."; then \
local_target="$$target-am"; \
else \
local_target="$$target"; \
fi; \
(cd $$subdir && $(MAKE) $(AM_MAKEFLAGS) $$local_target) \
|| case "$$amf" in *=*) exit 1;; *k*) fail=yes;; *) exit 1;; esac; \
done && test -z "$$fail"
tags-recursive:
list='$(SUBDIRS)'; for subdir in $$list; do \
test "$$subdir" = . || (cd $$subdir && $(MAKE) $(AM_MAKEFLAGS) tags); \
done
tags: TAGS
ID: $(HEADERS) $(SOURCES) $(LISP)
list='$(SOURCES) $(HEADERS)'; \
unique=`for i in $$list; do echo $$i; done | \
awk ' { files[$$0] = 1; } \
END { for (i in files) print i; }'`; \
here=`pwd` && cd $(srcdir) \
&& mkid -f$$here/ID $$unique $(LISP)
TAGS: tags-recursive $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) $(LISP)
tags=; \
here=`pwd`; \
list='$(SUBDIRS)'; for subdir in $$list; do \
if test "$$subdir" = .; then :; else \
test -f $$subdir/TAGS && tags="$$tags -i $$here/$$subdir/TAGS"; \
fi; \
done; \
list='$(SOURCES) $(HEADERS)'; \
unique=`for i in $$list; do echo $$i; done | \
awk ' { files[$$0] = 1; } \
END { for (i in files) print i; }'`; \
test -z "$(ETAGS_ARGS)$$unique$(LISP)$$tags" \
|| (cd $(srcdir) && etags $(ETAGS_ARGS) $$tags $$unique $(LISP) -o $$here/TAGS)
mostlyclean-tags:
clean-tags:
distclean-tags:
-rm -f TAGS ID
maintainer-clean-tags:
distdir = $(top_builddir)/$(PACKAGE)-$(VERSION)/$(subdir)
subdir = common/lib
distdir: $(DISTFILES)
here=`cd $(top_builddir) && pwd`; \
top_distdir=`cd $(top_distdir) && pwd`; \
distdir=`cd $(distdir) && pwd`; \
cd $(top_srcdir) \
&& $(AUTOMAKE) --include-deps --build-dir=$$here --srcdir-name=$(top_srcdir) --output-dir=$$top_distdir --foreign common/lib/Makefile
@for file in $(DISTFILES); do \
d=$(srcdir); \
if test -d $$d/$$file; then \
cp -pr $$/$$file $(distdir)/$$file; \
else \
test -f $(distdir)/$$file \
|| ln $$d/$$file $(distdir)/$$file 2> /dev/null \
|| cp -p $$d/$$file $(distdir)/$$file || :; \
fi; \
done
for subdir in $(SUBDIRS); do \
if test "$$subdir" = .; then :; else \
test -d $(distdir)/$$subdir \
|| mkdir $(distdir)/$$subdir \
|| exit 1; \
chmod 777 $(distdir)/$$subdir; \
(cd $$subdir && $(MAKE) $(AM_MAKEFLAGS) top_distdir=../$(top_distdir) distdir=../$(distdir)/$$subdir distdir) \
|| exit 1; \
fi; \
done
info-am:
info: info-recursive
dvi-am:
dvi: dvi-recursive
check-am: all-am
check: check-recursive
installcheck-am:
installcheck: installcheck-recursive
install-exec-am:
install-exec: install-exec-recursive
install-data-am:
install-data: install-data-recursive
install-am: all-am
@$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am
install: install-recursive
uninstall-am:
uninstall: uninstall-recursive
all-am: Makefile
all-redirect: all-recursive
install-strip:
$(MAKE) $(AM_MAKEFLAGS) AM_INSTALL_PROGRAM_FLAGS=-s install
installdirs: installdirs-recursive
installdirs-am:
mostlyclean-generic:
clean-generic:
distclean-generic:
-rm -f Makefile $(CONFIG_CLEAN_FILES)
-rm -f config.cache config.log stamp-h stamp-h[0-9]*
maintainer-clean-generic:
mostlyclean-am: mostlyclean-tags mostlyclean-generic
mostlyclean: mostlyclean-recursive
clean-am: clean-tags clean-generic mostlyclean-am
clean: clean-recursive
distclean-am: distclean-tags distclean-generic clean-am
distclean: distclean-recursive
maintainer-clean-am: maintainer-clean-tags maintainer-clean-generic \
distclean-am
@echo "This command is intended for maintainers to use;"
@echo "it deletes files that may require special tools to rebuild."
maintainer-clean: maintainer-clean-recursive
.PHONY: install-data-recursive uninstall-data-recursive \
install-exec-recursive uninstall-exec-recursive installdirs-recursive \
uninstalldirs-recursive all-recursive check-recursive \
installcheck-recursive info-recursive dvi-recursive \
mostlyclean-recursive distclean-recursive clean-recursive \
maintainer-clean-recursive tags tags-recursive mostlyclean-tags \
distclean-tags clean-tags maintainer-clean-tags distdir info-am info \
dvi-am dvi check check-am installcheck-am installcheck install-exec-am \
install-exec install-data-am install-data install-am install \
uninstall-am uninstall all-redirect all-am all installdirs-am \
installdirs mostlyclean-generic distclean-generic clean-generic \
maintainer-clean-generic clean mostlyclean distclean maintainer-clean
# Tell versions [3.59,3.63) of GNU make to not export all variables.
# Otherwise a system limit (for SysV at least) may be exceeded.
.NOEXPORT:

View File

@@ -0,0 +1,8 @@
INCLUDES = -I../../include
noinst_LIBRARIES = libcrypto.a
libcrypto_a_SOURCES = crypto.C bf_enc.c bf_cfb64.c bf_skey.c
libcrypto_a_LIBADD =

View File

@@ -0,0 +1,332 @@
# Makefile.in generated automatically by automake 1.4 from Makefile.am
# Copyright (C) 1994, 1995-8, 1999 Free Software Foundation, Inc.
# This Makefile.in is free software; the Free Software Foundation
# gives unlimited permission to copy and/or distribute it,
# with or without modifications, as long as this notice is preserved.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY, to the extent permitted by law; without
# even the implied warranty of MERCHANTABILITY or FITNESS FOR A
# PARTICULAR PURPOSE.
SHELL = @SHELL@
srcdir = @srcdir@
top_srcdir = @top_srcdir@
VPATH = @srcdir@
prefix = @prefix@
exec_prefix = @exec_prefix@
bindir = @bindir@
sbindir = @sbindir@
libexecdir = @libexecdir@
datadir = @datadir@
sysconfdir = @sysconfdir@
sharedstatedir = @sharedstatedir@
localstatedir = @localstatedir@
libdir = @libdir@
infodir = @infodir@
mandir = @mandir@
includedir = @includedir@
oldincludedir = /usr/include
DESTDIR =
pkgdatadir = $(datadir)/@PACKAGE@
pkglibdir = $(libdir)/@PACKAGE@
pkgincludedir = $(includedir)/@PACKAGE@
top_builddir = ../../..
ACLOCAL = @ACLOCAL@
AUTOCONF = @AUTOCONF@
AUTOMAKE = @AUTOMAKE@
AUTOHEADER = @AUTOHEADER@
INSTALL = @INSTALL@
INSTALL_PROGRAM = @INSTALL_PROGRAM@ $(AM_INSTALL_PROGRAM_FLAGS)
INSTALL_DATA = @INSTALL_DATA@
INSTALL_SCRIPT = @INSTALL_SCRIPT@
transform = @program_transform_name@
NORMAL_INSTALL = :
PRE_INSTALL = :
POST_INSTALL = :
NORMAL_UNINSTALL = :
PRE_UNINSTALL = :
POST_UNINSTALL = :
CC = @CC@
CXX = @CXX@
GL_CFLAGS = @GL_CFLAGS@
GL_LIBS = @GL_LIBS@
LEX = @LEX@
MAKEINFO = @MAKEINFO@
NETLIBS = @NETLIBS@
PACKAGE = @PACKAGE@
RANLIB = @RANLIB@
TIFF_CFLAGS = @TIFF_CFLAGS@
TIFF_LIBS = @TIFF_LIBS@
VERSION = @VERSION@
YACC = @YACC@
INCLUDES = -I../../include
noinst_LIBRARIES = libcrypto.a
libcrypto_a_SOURCES = crypto.C bf_enc.c bf_cfb64.c bf_skey.c
libcrypto_a_LIBADD =
mkinstalldirs = $(SHELL) $(top_srcdir)/mkinstalldirs
CONFIG_CLEAN_FILES =
LIBRARIES = $(noinst_LIBRARIES)
DEFS = @DEFS@ -I. -I$(srcdir)
CPPFLAGS = @CPPFLAGS@
LDFLAGS = @LDFLAGS@
LIBS = @LIBS@
X_CFLAGS = @X_CFLAGS@
X_LIBS = @X_LIBS@
X_EXTRA_LIBS = @X_EXTRA_LIBS@
X_PRE_LIBS = @X_PRE_LIBS@
libcrypto_a_DEPENDENCIES =
libcrypto_a_OBJECTS = crypto.o bf_enc.o bf_cfb64.o bf_skey.o
AR = ar
CXXFLAGS = @CXXFLAGS@
CXXCOMPILE = $(CXX) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS)
CXXLD = $(CXX)
CXXLINK = $(CXXLD) $(AM_CXXFLAGS) $(CXXFLAGS) $(LDFLAGS) -o $@
CFLAGS = @CFLAGS@
COMPILE = $(CC) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
CCLD = $(CC)
LINK = $(CCLD) $(AM_CFLAGS) $(CFLAGS) $(LDFLAGS) -o $@
DIST_COMMON = Makefile.am Makefile.in
DISTFILES = $(DIST_COMMON) $(SOURCES) $(HEADERS) $(TEXINFOS) $(EXTRA_DIST)
TAR = gtar
GZIP_ENV = --best
DEP_FILES = .deps/bf_cfb64.P .deps/bf_enc.P .deps/bf_skey.P \
.deps/crypto.P
SOURCES = $(libcrypto_a_SOURCES)
OBJECTS = $(libcrypto_a_OBJECTS)
all: all-redirect
.SUFFIXES:
.SUFFIXES: .C .S .c .o .s
$(srcdir)/Makefile.in: Makefile.am $(top_srcdir)/configure.in $(ACLOCAL_M4)
cd $(top_srcdir) && $(AUTOMAKE) --foreign common/lib/crypto/Makefile
Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status $(BUILT_SOURCES)
cd $(top_builddir) \
&& CONFIG_FILES=$(subdir)/$@ CONFIG_HEADERS= $(SHELL) ./config.status
mostlyclean-noinstLIBRARIES:
clean-noinstLIBRARIES:
-test -z "$(noinst_LIBRARIES)" || rm -f $(noinst_LIBRARIES)
distclean-noinstLIBRARIES:
maintainer-clean-noinstLIBRARIES:
.s.o:
$(COMPILE) -c $<
.S.o:
$(COMPILE) -c $<
mostlyclean-compile:
-rm -f *.o core *.core
clean-compile:
distclean-compile:
-rm -f *.tab.c
maintainer-clean-compile:
libcrypto.a: $(libcrypto_a_OBJECTS) $(libcrypto_a_DEPENDENCIES)
-rm -f libcrypto.a
$(AR) cru libcrypto.a $(libcrypto_a_OBJECTS) $(libcrypto_a_LIBADD)
$(RANLIB) libcrypto.a
.C.o:
$(CXXCOMPILE) -c $<
tags: TAGS
ID: $(HEADERS) $(SOURCES) $(LISP)
list='$(SOURCES) $(HEADERS)'; \
unique=`for i in $$list; do echo $$i; done | \
awk ' { files[$$0] = 1; } \
END { for (i in files) print i; }'`; \
here=`pwd` && cd $(srcdir) \
&& mkid -f$$here/ID $$unique $(LISP)
TAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) $(LISP)
tags=; \
here=`pwd`; \
list='$(SOURCES) $(HEADERS)'; \
unique=`for i in $$list; do echo $$i; done | \
awk ' { files[$$0] = 1; } \
END { for (i in files) print i; }'`; \
test -z "$(ETAGS_ARGS)$$unique$(LISP)$$tags" \
|| (cd $(srcdir) && etags $(ETAGS_ARGS) $$tags $$unique $(LISP) -o $$here/TAGS)
mostlyclean-tags:
clean-tags:
distclean-tags:
-rm -f TAGS ID
maintainer-clean-tags:
distdir = $(top_builddir)/$(PACKAGE)-$(VERSION)/$(subdir)
subdir = common/lib/crypto
distdir: $(DISTFILES)
here=`cd $(top_builddir) && pwd`; \
top_distdir=`cd $(top_distdir) && pwd`; \
distdir=`cd $(distdir) && pwd`; \
cd $(top_srcdir) \
&& $(AUTOMAKE) --include-deps --build-dir=$$here --srcdir-name=$(top_srcdir) --output-dir=$$top_distdir --foreign common/lib/crypto/Makefile
@for file in $(DISTFILES); do \
d=$(srcdir); \
if test -d $$d/$$file; then \
cp -pr $$/$$file $(distdir)/$$file; \
else \
test -f $(distdir)/$$file \
|| ln $$d/$$file $(distdir)/$$file 2> /dev/null \
|| cp -p $$d/$$file $(distdir)/$$file || :; \
fi; \
done
DEPS_MAGIC := $(shell mkdir .deps > /dev/null 2>&1 || :)
-include $(DEP_FILES)
mostlyclean-depend:
clean-depend:
distclean-depend:
-rm -rf .deps
maintainer-clean-depend:
%.o: %.c
@echo '$(COMPILE) -c $<'; \
$(COMPILE) -Wp,-MD,.deps/$(*F).pp -c $<
@-cp .deps/$(*F).pp .deps/$(*F).P; \
tr ' ' '\012' < .deps/$(*F).pp \
| sed -e 's/^\\$$//' -e '/^$$/ d' -e '/:$$/ d' -e 's/$$/ :/' \
>> .deps/$(*F).P; \
rm .deps/$(*F).pp
%.lo: %.c
@echo '$(LTCOMPILE) -c $<'; \
$(LTCOMPILE) -Wp,-MD,.deps/$(*F).pp -c $<
@-sed -e 's/^\([^:]*\)\.o[ ]*:/\1.lo \1.o :/' \
< .deps/$(*F).pp > .deps/$(*F).P; \
tr ' ' '\012' < .deps/$(*F).pp \
| sed -e 's/^\\$$//' -e '/^$$/ d' -e '/:$$/ d' -e 's/$$/ :/' \
>> .deps/$(*F).P; \
rm -f .deps/$(*F).pp
%.o: %.C
@echo '$(CXXCOMPILE) -c $<'; \
$(CXXCOMPILE) -Wp,-MD,.deps/$(*F).pp -c $<
@-cp .deps/$(*F).pp .deps/$(*F).P; \
tr ' ' '\012' < .deps/$(*F).pp \
| sed -e 's/^\\$$//' -e '/^$$/ d' -e '/:$$/ d' -e 's/$$/ :/' \
>> .deps/$(*F).P; \
rm .deps/$(*F).pp
%.lo: %.C
@echo '$(LTCXXCOMPILE) -c $<'; \
$(LTCXXCOMPILE) -Wp,-MD,.deps/$(*F).pp -c $<
@-sed -e 's/^\([^:]*\)\.o[ ]*:/\1.lo \1.o :/' \
< .deps/$(*F).pp > .deps/$(*F).P; \
tr ' ' '\012' < .deps/$(*F).pp \
| sed -e 's/^\\$$//' -e '/^$$/ d' -e '/:$$/ d' -e 's/$$/ :/' \
>> .deps/$(*F).P; \
rm -f .deps/$(*F).pp
info-am:
info: info-am
dvi-am:
dvi: dvi-am
check-am: all-am
check: check-am
installcheck-am:
installcheck: installcheck-am
install-exec-am:
install-exec: install-exec-am
install-data-am:
install-data: install-data-am
install-am: all-am
@$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am
install: install-am
uninstall-am:
uninstall: uninstall-am
all-am: Makefile $(LIBRARIES)
all-redirect: all-am
install-strip:
$(MAKE) $(AM_MAKEFLAGS) AM_INSTALL_PROGRAM_FLAGS=-s install
installdirs:
mostlyclean-generic:
clean-generic:
distclean-generic:
-rm -f Makefile $(CONFIG_CLEAN_FILES)
-rm -f config.cache config.log stamp-h stamp-h[0-9]*
maintainer-clean-generic:
mostlyclean-am: mostlyclean-noinstLIBRARIES mostlyclean-compile \
mostlyclean-tags mostlyclean-depend mostlyclean-generic
mostlyclean: mostlyclean-am
clean-am: clean-noinstLIBRARIES clean-compile clean-tags clean-depend \
clean-generic mostlyclean-am
clean: clean-am
distclean-am: distclean-noinstLIBRARIES distclean-compile \
distclean-tags distclean-depend distclean-generic \
clean-am
distclean: distclean-am
maintainer-clean-am: maintainer-clean-noinstLIBRARIES \
maintainer-clean-compile maintainer-clean-tags \
maintainer-clean-depend maintainer-clean-generic \
distclean-am
@echo "This command is intended for maintainers to use;"
@echo "it deletes files that may require special tools to rebuild."
maintainer-clean: maintainer-clean-am
.PHONY: mostlyclean-noinstLIBRARIES distclean-noinstLIBRARIES \
clean-noinstLIBRARIES maintainer-clean-noinstLIBRARIES \
mostlyclean-compile distclean-compile clean-compile \
maintainer-clean-compile tags mostlyclean-tags distclean-tags \
clean-tags maintainer-clean-tags distdir mostlyclean-depend \
distclean-depend clean-depend maintainer-clean-depend info-am info \
dvi-am dvi check check-am installcheck-am installcheck install-exec-am \
install-exec install-data-am install-data install-am install \
uninstall-am uninstall all-redirect all-am all installdirs \
mostlyclean-generic distclean-generic clean-generic \
maintainer-clean-generic clean mostlyclean distclean maintainer-clean
# Tell versions [3.59,3.63) of GNU make to not export all variables.
# Otherwise a system limit (for SysV at least) may be exceeded.
.NOEXPORT:

View File

@@ -0,0 +1,127 @@
/* crypto/bf/bf_cfb64.c */
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
* All rights reserved.
*
* This package is an SSL implementation written
* by Eric Young (eay@cryptsoft.com).
* The implementation was written so as to conform with Netscapes SSL.
*
* This library is free for commercial and non-commercial use as long as
* the following conditions are aheared to. The following conditions
* apply to all code found in this distribution, be it the RC4, RSA,
* lhash, DES, etc., code; not just the SSL code. The SSL documentation
* included with this distribution is covered by the same copyright terms
* except that the holder is Tim Hudson (tjh@cryptsoft.com).
*
* Copyright remains Eric Young's, and as such any Copyright notices in
* the code are not to be removed.
* If this package is used in a product, Eric Young should be given attribution
* as the author of the parts of the library used.
* This can be in the form of a textual message at program startup or
* in documentation (online or textual) provided with the package.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* "This product includes cryptographic software written by
* Eric Young (eay@cryptsoft.com)"
* The word 'cryptographic' can be left out if the rouines from the library
* being used are not cryptographic related :-).
* 4. If you include any Windows specific code (or a derivative thereof) from
* the apps directory (application code) you must include an acknowledgement:
* "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
*
* THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* The licence and distribution terms for any publically available version or
* derivative of this code cannot be changed. i.e. this code cannot simply be
* copied and put under another distribution licence
* [including the GNU Public Licence.]
*/
#include "blowfish.h"
#include "bf_locl.h"
/* The input and output encrypted as though 64bit cfb mode is being
* used. The extra state information to record how much of the
* 64bit block we have used is contained in *num;
*/
void BF_cfb64_encrypt(in, out, length, schedule, ivec, num, encrypt)
unsigned char *in;
unsigned char *out;
long length;
BF_KEY *schedule;
unsigned char *ivec;
int *num;
int encrypt;
{
register BF_LONG v0,v1,t;
register int n= *num;
register long l=length;
BF_LONG ti[2];
unsigned char *iv,c,cc;
iv=(unsigned char *)ivec;
if (encrypt)
{
while (l--)
{
if (n == 0)
{
n2l(iv,v0); ti[0]=v0;
n2l(iv,v1); ti[1]=v1;
BF_encrypt((BF_LONG *)ti,schedule);
iv=(unsigned char *)ivec;
t=ti[0]; l2n(t,iv);
t=ti[1]; l2n(t,iv);
iv=(unsigned char *)ivec;
}
c= *(in++)^iv[n];
*(out++)=c;
iv[n]=c;
n=(n+1)&0x07;
}
}
else
{
while (l--)
{
if (n == 0)
{
n2l(iv,v0); ti[0]=v0;
n2l(iv,v1); ti[1]=v1;
BF_encrypt((BF_LONG *)ti,schedule);
iv=(unsigned char *)ivec;
t=ti[0]; l2n(t,iv);
t=ti[1]; l2n(t,iv);
iv=(unsigned char *)ivec;
}
cc= *(in++);
c=iv[n];
iv[n]=cc;
*(out++)=c^cc;
n=(n+1)&0x07;
}
}
v0=v1=ti[0]=ti[1]=t=c=cc=0;
*num=n;
}

241
common/lib/crypto/bf_enc.c Normal file
View File

@@ -0,0 +1,241 @@
/* crypto/bf/bf_enc.c */
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
* All rights reserved.
*
* This package is an SSL implementation written
* by Eric Young (eay@cryptsoft.com).
* The implementation was written so as to conform with Netscapes SSL.
*
* This library is free for commercial and non-commercial use as long as
* the following conditions are aheared to. The following conditions
* apply to all code found in this distribution, be it the RC4, RSA,
* lhash, DES, etc., code; not just the SSL code. The SSL documentation
* included with this distribution is covered by the same copyright terms
* except that the holder is Tim Hudson (tjh@cryptsoft.com).
*
* Copyright remains Eric Young's, and as such any Copyright notices in
* the code are not to be removed.
* If this package is used in a product, Eric Young should be given attribution
* as the author of the parts of the library used.
* This can be in the form of a textual message at program startup or
* in documentation (online or textual) provided with the package.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* "This product includes cryptographic software written by
* Eric Young (eay@cryptsoft.com)"
* The word 'cryptographic' can be left out if the rouines from the library
* being used are not cryptographic related :-).
* 4. If you include any Windows specific code (or a derivative thereof) from
* the apps directory (application code) you must include an acknowledgement:
* "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
*
* THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* The licence and distribution terms for any publically available version or
* derivative of this code cannot be changed. i.e. this code cannot simply be
* copied and put under another distribution licence
* [including the GNU Public Licence.]
*/
#include "blowfish.h"
#include "bf_locl.h"
/* Blowfish as implemented from 'Blowfish: Springer-Verlag paper'
* (From LECTURE NOTES IN COIMPUTER SCIENCE 809, FAST SOFTWARE ENCRYPTION,
* CAMBRIDGE SECURITY WORKSHOP, CAMBRIDGE, U.K., DECEMBER 9-11, 1993)
*/
#if (BF_ROUNDS != 16) && (BF_ROUNDS != 20)
If you set BF_ROUNDS to some value other than 16 or 20, you will have
to modify the code.
#endif
void BF_encrypt(data,key)
BF_LONG *data;
BF_KEY *key;
{
register BF_LONG l,r,*p,*s;
p=key->P;
s= &(key->S[0]);
l=data[0];
r=data[1];
l^=p[0];
BF_ENC(r,l,s,p[ 1]);
BF_ENC(l,r,s,p[ 2]);
BF_ENC(r,l,s,p[ 3]);
BF_ENC(l,r,s,p[ 4]);
BF_ENC(r,l,s,p[ 5]);
BF_ENC(l,r,s,p[ 6]);
BF_ENC(r,l,s,p[ 7]);
BF_ENC(l,r,s,p[ 8]);
BF_ENC(r,l,s,p[ 9]);
BF_ENC(l,r,s,p[10]);
BF_ENC(r,l,s,p[11]);
BF_ENC(l,r,s,p[12]);
BF_ENC(r,l,s,p[13]);
BF_ENC(l,r,s,p[14]);
BF_ENC(r,l,s,p[15]);
BF_ENC(l,r,s,p[16]);
#if BF_ROUNDS == 20
BF_ENC(r,l,s,p[17]);
BF_ENC(l,r,s,p[18]);
BF_ENC(r,l,s,p[19]);
BF_ENC(l,r,s,p[20]);
#endif
r^=p[BF_ROUNDS+1];
data[1]=l&0xffffffffL;
data[0]=r&0xffffffffL;
}
#ifndef BF_DEFAULT_OPTIONS
void BF_decrypt(data,key)
BF_LONG *data;
BF_KEY *key;
{
register BF_LONG l,r,*p,*s;
p=key->P;
s= &(key->S[0]);
l=data[0];
r=data[1];
l^=p[BF_ROUNDS+1];
#if BF_ROUNDS == 20
BF_ENC(r,l,s,p[20]);
BF_ENC(l,r,s,p[19]);
BF_ENC(r,l,s,p[18]);
BF_ENC(l,r,s,p[17]);
#endif
BF_ENC(r,l,s,p[16]);
BF_ENC(l,r,s,p[15]);
BF_ENC(r,l,s,p[14]);
BF_ENC(l,r,s,p[13]);
BF_ENC(r,l,s,p[12]);
BF_ENC(l,r,s,p[11]);
BF_ENC(r,l,s,p[10]);
BF_ENC(l,r,s,p[ 9]);
BF_ENC(r,l,s,p[ 8]);
BF_ENC(l,r,s,p[ 7]);
BF_ENC(r,l,s,p[ 6]);
BF_ENC(l,r,s,p[ 5]);
BF_ENC(r,l,s,p[ 4]);
BF_ENC(l,r,s,p[ 3]);
BF_ENC(r,l,s,p[ 2]);
BF_ENC(l,r,s,p[ 1]);
r^=p[0];
data[1]=l&0xffffffffL;
data[0]=r&0xffffffffL;
}
void BF_cbc_encrypt(in, out, length, ks, iv, encrypt)
unsigned char *in;
unsigned char *out;
long length;
BF_KEY *ks;
unsigned char *iv;
int encrypt;
{
register BF_LONG tin0,tin1;
register BF_LONG tout0,tout1,xor0,xor1;
register long l=length;
BF_LONG tin[2];
if (encrypt)
{
n2l(iv,tout0);
n2l(iv,tout1);
iv-=8;
for (l-=8; l>=0; l-=8)
{
n2l(in,tin0);
n2l(in,tin1);
tin0^=tout0;
tin1^=tout1;
tin[0]=tin0;
tin[1]=tin1;
BF_encrypt(tin,ks);
tout0=tin[0];
tout1=tin[1];
l2n(tout0,out);
l2n(tout1,out);
}
if (l != -8)
{
n2ln(in,tin0,tin1,l+8);
tin0^=tout0;
tin1^=tout1;
tin[0]=tin0;
tin[1]=tin1;
BF_encrypt(tin,ks);
tout0=tin[0];
tout1=tin[1];
l2n(tout0,out);
l2n(tout1,out);
}
l2n(tout0,iv);
l2n(tout1,iv);
}
else
{
n2l(iv,xor0);
n2l(iv,xor1);
iv-=8;
for (l-=8; l>=0; l-=8)
{
n2l(in,tin0);
n2l(in,tin1);
tin[0]=tin0;
tin[1]=tin1;
BF_decrypt(tin,ks);
tout0=tin[0]^xor0;
tout1=tin[1]^xor1;
l2n(tout0,out);
l2n(tout1,out);
xor0=tin0;
xor1=tin1;
}
if (l != -8)
{
n2l(in,tin0);
n2l(in,tin1);
tin[0]=tin0;
tin[1]=tin1;
BF_decrypt(tin,ks);
tout0=tin[0]^xor0;
tout1=tin[1]^xor1;
l2nn(tout0,tout1,out,l+8);
xor0=tin0;
xor1=tin1;
}
l2n(xor0,iv);
l2n(xor1,iv);
}
tin0=tin1=tout0=tout1=xor0=xor1=0;
tin[0]=tin[1]=0;
}
#endif

119
common/lib/crypto/bf_skey.c Normal file
View File

@@ -0,0 +1,119 @@
/* crypto/bf/bf_skey.c */
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
* All rights reserved.
*
* This package is an SSL implementation written
* by Eric Young (eay@cryptsoft.com).
* The implementation was written so as to conform with Netscapes SSL.
*
* This library is free for commercial and non-commercial use as long as
* the following conditions are aheared to. The following conditions
* apply to all code found in this distribution, be it the RC4, RSA,
* lhash, DES, etc., code; not just the SSL code. The SSL documentation
* included with this distribution is covered by the same copyright terms
* except that the holder is Tim Hudson (tjh@cryptsoft.com).
*
* Copyright remains Eric Young's, and as such any Copyright notices in
* the code are not to be removed.
* If this package is used in a product, Eric Young should be given attribution
* as the author of the parts of the library used.
* This can be in the form of a textual message at program startup or
* in documentation (online or textual) provided with the package.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* "This product includes cryptographic software written by
* Eric Young (eay@cryptsoft.com)"
* The word 'cryptographic' can be left out if the rouines from the library
* being used are not cryptographic related :-).
* 4. If you include any Windows specific code (or a derivative thereof) from
* the apps directory (application code) you must include an acknowledgement:
* "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
*
* THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* The licence and distribution terms for any publically available version or
* derivative of this code cannot be changed. i.e. this code cannot simply be
* copied and put under another distribution licence
* [including the GNU Public Licence.]
*/
#include <stdio.h>
#include <string.h>
#include "blowfish.h"
#include "bf_locl.h"
#include "bf_pi.h"
void BF_set_key(key,len,data)
BF_KEY *key;
int len;
unsigned char *data;
{
int i;
BF_LONG *p,ri,in[2];
unsigned char *d,*end;
memcpy((char *)key,(char *)&bf_init,sizeof(BF_KEY));
p=key->P;
if (len > ((BF_ROUNDS+2)*4)) len=(BF_ROUNDS+2)*4;
d=data;
end= &(data[len]);
for (i=0; i<(BF_ROUNDS+2); i++)
{
ri= *(d++);
if (d >= end) d=data;
ri<<=8;
ri|= *(d++);
if (d >= end) d=data;
ri<<=8;
ri|= *(d++);
if (d >= end) d=data;
ri<<=8;
ri|= *(d++);
if (d >= end) d=data;
p[i]^=ri;
}
in[0]=0L;
in[1]=0L;
for (i=0; i<(BF_ROUNDS+2); i+=2)
{
BF_encrypt(in,key);
p[i ]=in[0];
p[i+1]=in[1];
}
p=key->S;
for (i=0; i<4*256; i+=2)
{
BF_encrypt(in,key);
p[i ]=in[0];
p[i+1]=in[1];
}
}

188
common/lib/crypto/crypto.C Normal file
View File

@@ -0,0 +1,188 @@
/*
* PVVMUD a 3D MUD
* Copyright (C) 1998-1999 Programvareverkstedet (pvv@pvv.org)
*
* 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.
*
* 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
*
*/
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include "crypto.H"
#include <errno.h>
#define MAXCRYPTSIZE 1024
#define int32 int
CCrypto::CCrypto(void) {
// Common
cryptKey=(BF_KEY *)malloc(sizeof(BF_KEY));
BF_set_key(cryptKey,19,(unsigned char *)"This is just a test");
// Reading part of the code
cryptBuf_r=(unsigned char *)malloc(4);
cryptSize_r=0;
cryptPos_r=0;
cryptState_r=0;
cryptN_r=0;
cryptIV_r[0]=0xfe;
cryptIV_r[1]=0xdc;
cryptIV_r[2]=0xba;
cryptIV_r[3]=0x98;
cryptIV_r[4]=0x76;
cryptIV_r[5]=0x54;
cryptIV_r[6]=0x32;
cryptIV_r[7]=0x10;
// Writing part of the code
cryptTempBuf=(unsigned char *)malloc(4);
cryptSize_w=0;
cryptPos_w=0;
cryptState_w=0;
cryptN_w=0;
cryptIV_w[0]=0xfe;
cryptIV_w[1]=0xdc;
cryptIV_w[2]=0xba;
cryptIV_w[3]=0x98;
cryptIV_w[4]=0x76;
cryptIV_w[5]=0x54;
cryptIV_w[6]=0x32;
cryptIV_w[7]=0x10;
}
CCrypto::~CCrypto(void) {
if (cryptBuf_r != NULL) free(cryptBuf_r);
if (cryptBuf_w != NULL) free(cryptTempBuf);
if (cryptKey != NULL) free(cryptKey);
};
ssize_t CCrypto::read(int fd, char **buf, size_t count) {
ssize_t bRead;
unsigned char *tempBuf;
int i,j;
while (1)
switch (cryptState_r) {
case 0:
bRead=::read(fd,(cryptBuf_r+cryptPos_r),(4-cryptPos_r));
if (bRead > 0) cryptPos_r+=bRead;
if (cryptPos_r < 4) return (-2);
cryptSize_r=*(int32 *)cryptBuf_r;
free(cryptBuf_r);
cryptBuf_r=(unsigned char *)malloc(cryptSize_r);
if (cryptBuf_r==NULL) printf("Couldn't allocate memory \n");
bRead=0;
cryptPos_r=0;
cryptState_r=1;
case 1:
bRead=::read(fd,(cryptBuf_r+cryptPos_r),(cryptSize_r-cryptPos_r));
if (bRead > 0) {
cryptPos_r+=bRead;
};
if (cryptPos_r < cryptSize_r) return (-2);
tempBuf=cryptBuf_r;
cryptBuf_r=(unsigned char *)malloc(cryptSize_r);
BF_cfb64_encrypt(tempBuf,cryptBuf_r,cryptSize_r,cryptKey,
cryptIV_r,&cryptN_r,BF_DECRYPT);
printf("Decrypting ... %i bytes ...\n",cryptSize_r);
free(tempBuf);
cryptPos_r=0;
cryptState_r=2;
case 2:
*buf=(char *)(cryptBuf_r+cryptPos_r);
j=MIN(cryptSize_r-cryptPos_r,count);
cryptPos_r+=j;
if (cryptPos_r==cryptSize_r) cryptState_r=3;
if (j==0) j=-2;
return(j);
case 3:
free(cryptBuf_r);
cryptBuf_r=(unsigned char *)malloc(4);
cryptPos_r=0;
cryptState_r=0;
};
}
ssize_t CCrypto::write(int fd, void *buf, size_t count) {
ssize_t bWrote;
int32 length,j;
unsigned char *tempBuf;
int i=0;
if (count == 0) return (0);
while(1)
switch(cryptState_w) {
case 0:
cryptSize_w = count;
cryptBuf_w = (unsigned char *)buf;
cryptTempPos = 0;
cryptPos_w = 0;
*(int32 *)(cryptTempBuf) = cryptSize_w;
cryptState_w = 1;
break;
case 1:
bWrote=1;
while (bWrote>0) {
bWrote=::write(fd,(cryptTempBuf+cryptTempPos),(4-cryptTempPos));
if (bWrote>0) cryptTempPos+=bWrote;;
};
if (cryptTempPos<4) return (0);
free(cryptTempBuf);
cryptTempBuf=(unsigned char *)malloc(cryptSize_w);
BF_cfb64_encrypt(cryptBuf_w, cryptTempBuf, cryptSize_w,
cryptKey, cryptIV_w, &cryptN_w, BF_ENCRYPT);
cryptPos_w = 0;
cryptState_w = 2;
break;
case 2:
cryptTempSize = MIN(cryptSize_w-cryptPos_w,MAXCRYPTSIZE);
cryptTempPos = 0;
cryptState_w = 3;
break;
case 3:
bWrote=1;
while(bWrote>0) {
bWrote=::write(fd,(void *)(cryptTempBuf+cryptPos_w+cryptTempPos),
(cryptTempSize-cryptTempPos));
if (bWrote>0) cryptTempPos+=bWrote;
};
if (cryptTempPos<cryptTempSize) return (0);
cryptPos_w+=cryptTempPos;
cryptState_w = 2;
if (cryptPos_w<cryptSize_w) break;
free(cryptTempBuf);
cryptTempBuf = (unsigned char *)malloc(4);
cryptState_w = 0;
printf("Encrypting : ... %i bytes ...\n",cryptSize_w);
return(cryptPos_w);
};
};

View File

@@ -0,0 +1,5 @@
INCLUDES = -I../../include
noinst_LIBRARIES = libgeometry.a
libgeometry_a_SOURCES = cache.C geometry.C int.C material.C readbog.C readmat.C vertex.C writebog.C

View File

@@ -0,0 +1,330 @@
# Makefile.in generated automatically by automake 1.4 from Makefile.am
# Copyright (C) 1994, 1995-8, 1999 Free Software Foundation, Inc.
# This Makefile.in is free software; the Free Software Foundation
# gives unlimited permission to copy and/or distribute it,
# with or without modifications, as long as this notice is preserved.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY, to the extent permitted by law; without
# even the implied warranty of MERCHANTABILITY or FITNESS FOR A
# PARTICULAR PURPOSE.
SHELL = @SHELL@
srcdir = @srcdir@
top_srcdir = @top_srcdir@
VPATH = @srcdir@
prefix = @prefix@
exec_prefix = @exec_prefix@
bindir = @bindir@
sbindir = @sbindir@
libexecdir = @libexecdir@
datadir = @datadir@
sysconfdir = @sysconfdir@
sharedstatedir = @sharedstatedir@
localstatedir = @localstatedir@
libdir = @libdir@
infodir = @infodir@
mandir = @mandir@
includedir = @includedir@
oldincludedir = /usr/include
DESTDIR =
pkgdatadir = $(datadir)/@PACKAGE@
pkglibdir = $(libdir)/@PACKAGE@
pkgincludedir = $(includedir)/@PACKAGE@
top_builddir = ../../..
ACLOCAL = @ACLOCAL@
AUTOCONF = @AUTOCONF@
AUTOMAKE = @AUTOMAKE@
AUTOHEADER = @AUTOHEADER@
INSTALL = @INSTALL@
INSTALL_PROGRAM = @INSTALL_PROGRAM@ $(AM_INSTALL_PROGRAM_FLAGS)
INSTALL_DATA = @INSTALL_DATA@
INSTALL_SCRIPT = @INSTALL_SCRIPT@
transform = @program_transform_name@
NORMAL_INSTALL = :
PRE_INSTALL = :
POST_INSTALL = :
NORMAL_UNINSTALL = :
PRE_UNINSTALL = :
POST_UNINSTALL = :
CC = @CC@
CXX = @CXX@
GL_CFLAGS = @GL_CFLAGS@
GL_LIBS = @GL_LIBS@
LEX = @LEX@
MAKEINFO = @MAKEINFO@
NETLIBS = @NETLIBS@
PACKAGE = @PACKAGE@
RANLIB = @RANLIB@
TIFF_CFLAGS = @TIFF_CFLAGS@
TIFF_LIBS = @TIFF_LIBS@
VERSION = @VERSION@
YACC = @YACC@
INCLUDES = -I../../include
noinst_LIBRARIES = libgeometry.a
libgeometry_a_SOURCES = cache.C geometry.C int.C material.C readbog.C readmat.C vertex.C writebog.C
mkinstalldirs = $(SHELL) $(top_srcdir)/mkinstalldirs
CONFIG_CLEAN_FILES =
LIBRARIES = $(noinst_LIBRARIES)
DEFS = @DEFS@ -I. -I$(srcdir)
CPPFLAGS = @CPPFLAGS@
LDFLAGS = @LDFLAGS@
LIBS = @LIBS@
X_CFLAGS = @X_CFLAGS@
X_LIBS = @X_LIBS@
X_EXTRA_LIBS = @X_EXTRA_LIBS@
X_PRE_LIBS = @X_PRE_LIBS@
libgeometry_a_LIBADD =
libgeometry_a_OBJECTS = cache.o geometry.o int.o material.o readbog.o \
readmat.o vertex.o writebog.o
AR = ar
CXXFLAGS = @CXXFLAGS@
CXXCOMPILE = $(CXX) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS)
CXXLD = $(CXX)
CXXLINK = $(CXXLD) $(AM_CXXFLAGS) $(CXXFLAGS) $(LDFLAGS) -o $@
DIST_COMMON = Makefile.am Makefile.in TODO
DISTFILES = $(DIST_COMMON) $(SOURCES) $(HEADERS) $(TEXINFOS) $(EXTRA_DIST)
TAR = gtar
GZIP_ENV = --best
DEP_FILES = .deps/cache.P .deps/geometry.P .deps/int.P .deps/material.P \
.deps/readbog.P .deps/readmat.P .deps/vertex.P .deps/writebog.P
SOURCES = $(libgeometry_a_SOURCES)
OBJECTS = $(libgeometry_a_OBJECTS)
all: all-redirect
.SUFFIXES:
.SUFFIXES: .C .S .c .o .s
$(srcdir)/Makefile.in: Makefile.am $(top_srcdir)/configure.in $(ACLOCAL_M4)
cd $(top_srcdir) && $(AUTOMAKE) --foreign common/lib/geometry/Makefile
Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status $(BUILT_SOURCES)
cd $(top_builddir) \
&& CONFIG_FILES=$(subdir)/$@ CONFIG_HEADERS= $(SHELL) ./config.status
mostlyclean-noinstLIBRARIES:
clean-noinstLIBRARIES:
-test -z "$(noinst_LIBRARIES)" || rm -f $(noinst_LIBRARIES)
distclean-noinstLIBRARIES:
maintainer-clean-noinstLIBRARIES:
.s.o:
$(COMPILE) -c $<
.S.o:
$(COMPILE) -c $<
mostlyclean-compile:
-rm -f *.o core *.core
clean-compile:
distclean-compile:
-rm -f *.tab.c
maintainer-clean-compile:
libgeometry.a: $(libgeometry_a_OBJECTS) $(libgeometry_a_DEPENDENCIES)
-rm -f libgeometry.a
$(AR) cru libgeometry.a $(libgeometry_a_OBJECTS) $(libgeometry_a_LIBADD)
$(RANLIB) libgeometry.a
.C.o:
$(CXXCOMPILE) -c $<
tags: TAGS
ID: $(HEADERS) $(SOURCES) $(LISP)
list='$(SOURCES) $(HEADERS)'; \
unique=`for i in $$list; do echo $$i; done | \
awk ' { files[$$0] = 1; } \
END { for (i in files) print i; }'`; \
here=`pwd` && cd $(srcdir) \
&& mkid -f$$here/ID $$unique $(LISP)
TAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) $(LISP)
tags=; \
here=`pwd`; \
list='$(SOURCES) $(HEADERS)'; \
unique=`for i in $$list; do echo $$i; done | \
awk ' { files[$$0] = 1; } \
END { for (i in files) print i; }'`; \
test -z "$(ETAGS_ARGS)$$unique$(LISP)$$tags" \
|| (cd $(srcdir) && etags $(ETAGS_ARGS) $$tags $$unique $(LISP) -o $$here/TAGS)
mostlyclean-tags:
clean-tags:
distclean-tags:
-rm -f TAGS ID
maintainer-clean-tags:
distdir = $(top_builddir)/$(PACKAGE)-$(VERSION)/$(subdir)
subdir = common/lib/geometry
distdir: $(DISTFILES)
here=`cd $(top_builddir) && pwd`; \
top_distdir=`cd $(top_distdir) && pwd`; \
distdir=`cd $(distdir) && pwd`; \
cd $(top_srcdir) \
&& $(AUTOMAKE) --include-deps --build-dir=$$here --srcdir-name=$(top_srcdir) --output-dir=$$top_distdir --foreign common/lib/geometry/Makefile
@for file in $(DISTFILES); do \
d=$(srcdir); \
if test -d $$d/$$file; then \
cp -pr $$/$$file $(distdir)/$$file; \
else \
test -f $(distdir)/$$file \
|| ln $$d/$$file $(distdir)/$$file 2> /dev/null \
|| cp -p $$d/$$file $(distdir)/$$file || :; \
fi; \
done
DEPS_MAGIC := $(shell mkdir .deps > /dev/null 2>&1 || :)
-include $(DEP_FILES)
mostlyclean-depend:
clean-depend:
distclean-depend:
-rm -rf .deps
maintainer-clean-depend:
%.o: %.c
@echo '$(COMPILE) -c $<'; \
$(COMPILE) -Wp,-MD,.deps/$(*F).pp -c $<
@-cp .deps/$(*F).pp .deps/$(*F).P; \
tr ' ' '\012' < .deps/$(*F).pp \
| sed -e 's/^\\$$//' -e '/^$$/ d' -e '/:$$/ d' -e 's/$$/ :/' \
>> .deps/$(*F).P; \
rm .deps/$(*F).pp
%.lo: %.c
@echo '$(LTCOMPILE) -c $<'; \
$(LTCOMPILE) -Wp,-MD,.deps/$(*F).pp -c $<
@-sed -e 's/^\([^:]*\)\.o[ ]*:/\1.lo \1.o :/' \
< .deps/$(*F).pp > .deps/$(*F).P; \
tr ' ' '\012' < .deps/$(*F).pp \
| sed -e 's/^\\$$//' -e '/^$$/ d' -e '/:$$/ d' -e 's/$$/ :/' \
>> .deps/$(*F).P; \
rm -f .deps/$(*F).pp
%.o: %.C
@echo '$(CXXCOMPILE) -c $<'; \
$(CXXCOMPILE) -Wp,-MD,.deps/$(*F).pp -c $<
@-cp .deps/$(*F).pp .deps/$(*F).P; \
tr ' ' '\012' < .deps/$(*F).pp \
| sed -e 's/^\\$$//' -e '/^$$/ d' -e '/:$$/ d' -e 's/$$/ :/' \
>> .deps/$(*F).P; \
rm .deps/$(*F).pp
%.lo: %.C
@echo '$(LTCXXCOMPILE) -c $<'; \
$(LTCXXCOMPILE) -Wp,-MD,.deps/$(*F).pp -c $<
@-sed -e 's/^\([^:]*\)\.o[ ]*:/\1.lo \1.o :/' \
< .deps/$(*F).pp > .deps/$(*F).P; \
tr ' ' '\012' < .deps/$(*F).pp \
| sed -e 's/^\\$$//' -e '/^$$/ d' -e '/:$$/ d' -e 's/$$/ :/' \
>> .deps/$(*F).P; \
rm -f .deps/$(*F).pp
info-am:
info: info-am
dvi-am:
dvi: dvi-am
check-am: all-am
check: check-am
installcheck-am:
installcheck: installcheck-am
install-exec-am:
install-exec: install-exec-am
install-data-am:
install-data: install-data-am
install-am: all-am
@$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am
install: install-am
uninstall-am:
uninstall: uninstall-am
all-am: Makefile $(LIBRARIES)
all-redirect: all-am
install-strip:
$(MAKE) $(AM_MAKEFLAGS) AM_INSTALL_PROGRAM_FLAGS=-s install
installdirs:
mostlyclean-generic:
clean-generic:
distclean-generic:
-rm -f Makefile $(CONFIG_CLEAN_FILES)
-rm -f config.cache config.log stamp-h stamp-h[0-9]*
maintainer-clean-generic:
mostlyclean-am: mostlyclean-noinstLIBRARIES mostlyclean-compile \
mostlyclean-tags mostlyclean-depend mostlyclean-generic
mostlyclean: mostlyclean-am
clean-am: clean-noinstLIBRARIES clean-compile clean-tags clean-depend \
clean-generic mostlyclean-am
clean: clean-am
distclean-am: distclean-noinstLIBRARIES distclean-compile \
distclean-tags distclean-depend distclean-generic \
clean-am
distclean: distclean-am
maintainer-clean-am: maintainer-clean-noinstLIBRARIES \
maintainer-clean-compile maintainer-clean-tags \
maintainer-clean-depend maintainer-clean-generic \
distclean-am
@echo "This command is intended for maintainers to use;"
@echo "it deletes files that may require special tools to rebuild."
maintainer-clean: maintainer-clean-am
.PHONY: mostlyclean-noinstLIBRARIES distclean-noinstLIBRARIES \
clean-noinstLIBRARIES maintainer-clean-noinstLIBRARIES \
mostlyclean-compile distclean-compile clean-compile \
maintainer-clean-compile tags mostlyclean-tags distclean-tags \
clean-tags maintainer-clean-tags distdir mostlyclean-depend \
distclean-depend clean-depend maintainer-clean-depend info-am info \
dvi-am dvi check check-am installcheck-am installcheck install-exec-am \
install-exec install-data-am install-data install-am install \
uninstall-am uninstall all-redirect all-am all installdirs \
mostlyclean-generic distclean-generic clean-generic \
maintainer-clean-generic clean mostlyclean distclean maintainer-clean
# Tell versions [3.59,3.63) of GNU make to not export all variables.
# Otherwise a system limit (for SysV at least) may be exceeded.
.NOEXPORT:

3
common/lib/geometry/TODO Normal file
View File

@@ -0,0 +1,3 @@
CPolygon materialId int -> DWORD

View File

@@ -0,0 +1,66 @@
/*
* PVVMUD a 3D MUD
* Copyright (C) 1998-1999 Programvareverkstedet (pvv@pvv.org)
*
* 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.
*
* 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
*
*/
#include "pvvmud.H"
#include "cache.H"
CCache::CCache(){
cache = new CObjectList();
}
CObject * CCache::failFunc(int id){
return NULL;
}
CObject* CCache::add(int id, CObject * item){
CObjectListItem * listItem = cache->getFirst();
while ( listItem != NULL ){
CCacheItem * cacheItem = (CCacheItem*)listItem->getObject();
if (cacheItem->getId() == id){
return cacheItem->setItem(item);
}
listItem = listItem->getNext();
}
CCacheItem * newItem = new CCacheItem(id,item);
cache->addLast((CObject*)newItem);
return NULL;
}
CObject * CCache::get(int id){
CObjectListItem * item = cache->getFirst();
while ( item != NULL ){
CCacheItem * cacheItem = (CCacheItem*)item->getObject();
if (cacheItem->getId() == id) return cacheItem->getItem();
item = item->getNext();
}
// Failed to find object in cache calling failFunc
CObject * newObject = failFunc(id);
if (newObject != NULL) add(id,newObject);
return newObject;
}
void CCache::clear(){
cache->deleteAll();
}

File diff suppressed because it is too large Load Diff

37
common/lib/geometry/int.C Normal file
View File

@@ -0,0 +1,37 @@
/*
* PVVMUD a 3D MUD
* Copyright (C) 1998-1999 Programvareverkstedet (pvv@pvv.org)
*
* 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.
*
* 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
*
*/
#include "pvvmud.H"
#include "int.H"
CInt::CInt(int index){
cInt = index;
}
CInt::~CInt(){
}
int CInt::getValue(){
return cInt;
}
int CInt::setValue(int value){
cInt = value;
return value;
}

View File

@@ -0,0 +1,184 @@
/*
* PVVMUD a 3D MUD
* Copyright (C) 1998-1999 Programvareverkstedet (pvv@pvv.org)
*
* 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.
*
* 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
*
*/
#include "pvvmud.H"
#include <stdlib.h>
#include <stdio.h>
#include "material.H"
CMaterial::CMaterial(){
m_id = -1;
m_textureId = MAT_NOTEXTURE;
setAmbient(0.2,0.2,0.2,1.0);
setDiffuse(0.8,0.8,0.8,1.0);
setSpecular(0.0,0.0,0.0,1.0);
setShininess(0.0F);
setEmission(0.0,0.0,0.0,1.0);
}
CMaterial::CMaterial(int materialId){
m_id = materialId;
m_textureId = MAT_NOTEXTURE;
setAmbient(0.2,0.2,0.2,1.0);
setDiffuse(0.8,0.8,0.8,1.0);
setSpecular(0.0,0.0,0.0,1.0);
setShininess(0.0F);
setEmission(0.0,0.0,0.0,1.0);
}
CMaterial::CMaterial(int materialId, char * name){
m_id = materialId;
CMaterial(m_id);
load(name);
}
void CMaterial::setId(int materialId){
m_id = materialId;
}
void CMaterial::RGBA_SetColor(RGBA_t rgba,float red, float green, float blue, float alpha){
rgba[0] = red;
rgba[1] = green;
rgba[2] = blue;
rgba[3] = alpha;
}
void CMaterial::RGBA_Print(RGBA_t rgba){
printf("%f %f %f %fi\n",rgba[0],rgba[1],rgba[2],rgba[3]);
}
void CMaterial::setTextureId(int textureId){
m_textureId = textureId;
}
int CMaterial::getTextureId() {
return m_textureId;
}
void CMaterial::setAmbient(float red, float green, float blue, float alpha){
RGBA_SetColor(m_ambient,red,green,blue,alpha);
}
void CMaterial::setDiffuse(float red, float green, float blue, float alpha){
RGBA_SetColor(m_diffuse,red,green,blue,alpha);
}
void CMaterial::setSpecular(float red, float green, float blue, float alpha){
RGBA_SetColor(m_specular,red,green,blue,alpha);
}
void CMaterial::setShininess(float shininess){
m_shininess[0] = shininess;
}
void CMaterial::setEmission(float red, float green, float blue, float alpha){
RGBA_SetColor(m_emission,red,green,blue,alpha);
}
BYTE CMaterial::getAmbientByte(int num){
return (BYTE)(m_ambient[num]*255.0F);
}
BYTE CMaterial::getDiffuseByte(int num){
return (BYTE)(m_diffuse[num]*255.0F);
}
BYTE CMaterial::getSpecularByte(int num){
return (BYTE)(m_specular[num]*255.0F);
}
BYTE CMaterial::getEmissionByte(int num){
return (BYTE)(m_emission[num]*255.0F);
}
BYTE CMaterial::getShininessByte(){
return (BYTE)(m_shininess[0]*255.0F);
}
float CMaterial::getAmbientFloat(int num){
return m_ambient[num];
}
float CMaterial::getDiffuseFloat(int num){
return m_diffuse[num];
}
float CMaterial::getSpecularFloat(int num){
return m_specular[num];
}
float CMaterial::getEmissionFloat(int num){
return m_emission[num];
}
float CMaterial::getShininessFloat(){
return m_shininess[0];
}
void CMaterial::setAmbient(int num,BYTE value){
m_ambient[num] = (float)(value) * (1.0F / 255.0F);
}
void CMaterial::setDiffuse(int num,BYTE value){
m_diffuse[num] = (float)(value) * (1.0F / 255.0F);
}
void CMaterial::setSpecular(int num,BYTE value){
m_specular[num] = (float)(value) * (1.0F / 255.0F);
}
void CMaterial::setEmission(int num,BYTE value){
m_emission[num] = (float)(value) * (1.0F / 255.0F);
}
void CMaterial::setShininess(BYTE value){
m_shininess[0] = (float)(value) * (1.0F / 255.0F);
}
int CMaterial::exec(CTextureCache * texCache){
return FALSE;
}
/******************************************************************************
*
*
* Add material to MaterialCache
*
******************************************************************************/
CMaterialCache::CMaterialCache():CCache(){
}
CMaterial* CMaterialCache::add(CMaterial * mat) {
return (CMaterial*)CCache::add(mat->getId(),mat);
}
CMaterial * CMaterialCache::get(int id){
return (CMaterial*)CCache::get(id);
}

View File

@@ -0,0 +1,160 @@
/*
* PVVMUD a 3D MUD
* Copyright (C) 1998-1999 Programvareverkstedet (pvv@pvv.org)
*
* 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.
*
* 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
*
*/
/******************************************************************************
*
* Utilities for reading BOG file format
*
* Standard: Useing standard suggested in bogfileformat.html with
* rcs version 1.2 from the pvvmud web pages
*
*
******************************************************************************/
#include "pvvmud.H"
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <iostream.h>
#include "geometry.H"
#include "bogfile.H"
#include "exception.H"
//void CGeometry::load(int objId, char * name) {
// setId(objId);
// load(name);
//}
void CGeometry::load(char * name) {
FILE * bog;
bog = fopen(name,"r");
if (bog == NULL){
cdebug << "Error: Failed to open BOG file " << name << "\n";
throw new CException();
}
readBOG(bog);
fclose(bog);
}
int CGeometry::readBOGCore(FILE * bog, int numV, int numN,
int numTC, int numP){
int ii,jj;
int type,gltype,materialId,index;
double d1,d2,d3;
CPolygon * poly;
for (ii = 0; ii < numV; ii++){
fscanf(bog,"%lf %lf %lf",&d1,&d2,&d3);
addVertex(d1,d2,d3);
}
for (ii = 0; ii < numN; ii++){
fscanf(bog,"%lf %lf %lf",&d1,&d2,&d3);
addNormal(d1,d2,d3);
}
for (ii = 0; ii < numTC; ii++){
fscanf(bog,"%lf %lf",&d1,&d2);
addTexCoord(d1,d2);
}
for (ii = 0; ii < numP; ii++){
fscanf(bog,"%i %i %i %i %i",&type,&materialId,&numV,&numN,&numTC);
switch (type){
case PT_Polygon: gltype = POLYGON_POLYGON; break;
case PT_Triangles: gltype = POLYGON_TRIANGLES; break;
case PT_Quads: gltype = POLYGON_QUADS; break;
case PT_Quad_strip: gltype = POLYGON_QUAD_STRIP; break;
case PT_Triangle_strip: gltype = POLYGON_TRIANGLE_STRIP; break;
case PT_Triangle_fan: gltype = POLYGON_TRIANGLE_FAN; break;
}
poly = new CPolygon(gltype,materialId,numV,numN,numTC);
for (jj = 0; jj < numV; jj++){
fscanf(bog,"%i",&index);
poly->addVertexIndex(index);
}
for (jj = 0; jj < numN; jj++){
fscanf(bog,"%i",&index);
poly->addNormalIndex(index);
}
for (jj = 0; jj < numTC; jj++){
fscanf(bog,"%i",&index);
poly->addTexCoordIndex(index);
}
addPolygon(poly);
}
return TRUE;
}
void CGeometry::readBOG(FILE * bog ){
CGeometry *geo=NULL,*lastgeo=NULL;
int version,numSub,subid;
int numV,numN,numTC,numP;
int ii;
char name[5];
// Read header : BOG <version> <numSubObjects>
fscanf(bog,"%s",name);
if (strcmp(name,"BOG") != 0){
throw new CException();
} else {
fscanf(bog,"%i %i",&version,&numSub);
if (version != 1) throw new CException();
}
geo = this;
for (ii = 0; ii < numSub; ii++){
fscanf(bog,"%i",&subid);
fscanf(bog,"%i %i %i %i",&numV,&numN,&numTC,&numP);
if (ii != 0){
geo = newGeometry(getId());
}
geo->setSize(numV,numN,numTC,numP);
if (lastgeo != NULL){
lastgeo->setNext(geo);
}
geo->setSubId(subid);
geo->readBOGCore(bog,numV,numN,numTC,numP);
lastgeo = geo;
}
}

View File

@@ -0,0 +1,155 @@
/*
* PVVMUD a 3D MUD
* Copyright (C) 1998-1999 Programvareverkstedet (pvv@pvv.org)
*
* 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.
*
* 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
*
*/
#include <stdio.h>
#include <string.h>
#include <iostream.h>
#include "pvvmud.H"
#include "material.H"
#include "matfile.H"
int CMaterial::load(char * fileName) {
char * sufix;
sufix = strrchr(fileName,'.');
if (sufix == NULL) {
cdebug << "Failed!\n";
return FALSE;
}
if ( (strcmp(sufix,".bmat")==0) || (strcmp(sufix,".BMAT")==0) ){
loadBMAT(fileName);
} else {
cdebug << "Failed!\n";
return FALSE;
}
return TRUE;
}
int CMaterial::loadBMAT(char * fileName) {
FILE * matFile;
matFile = fopen(fileName,"r");
if (matFile == NULL) {
return FALSE;
}
float red,green,blue,alpha,shininess;
int matfileid,id;
while (fscanf(matFile,"%i",&matfileid)==1){
switch (matfileid){
case MAT_TEXTURE:
fscanf(matFile,"%i\n",&id);
setTextureId(id);
break;
case MAT_AMBIENT:
fscanf(matFile,"%f %f %f %f\n",&red,&green,&blue,&alpha);
setAmbient(red,green,blue,alpha);
break;
case MAT_DIFFUSE:
fscanf(matFile,"%f %f %f %f\n",&red,&green,&blue,&alpha);
setDiffuse(red,green,blue,alpha);
break;
case MAT_SPECULAR:
fscanf(matFile,"%f %f %f %f\n",&red,&green,&blue,&alpha);
setSpecular(red,green,blue,alpha);
break;
case MAT_EMISSION:
fscanf(matFile,"%f %f %f %f\n",&red,&green,&blue,&alpha);
setEmission(red,green,blue,alpha);
break;
case MAT_SHININESS:
fscanf(matFile,"%f",&shininess);
setShininess(shininess);
break;
}
}
fclose(matFile);
return TRUE;
}
int CMaterial::save(char * name) {
FILE * matFile;
int ii;
matFile = fopen(name,"w");
if (matFile == NULL) {
return FALSE;
}
if (getTextureId() != MAT_NOTEXTURE)
fprintf(matFile,"%i %i\n",MAT_TEXTURE,getTextureId());
// Ambient
fprintf(matFile,"%i",MAT_AMBIENT);
for (ii = 0; ii < 4; ii++)
fprintf(matFile," %f",getAmbientFloat(ii));
fprintf(matFile,"\n");
// Diffuse
fprintf(matFile,"%i",MAT_DIFFUSE);
for (ii = 0; ii < 4; ii++)
fprintf(matFile," %f",getDiffuseFloat(ii));
fprintf(matFile,"\n");
// Specular
fprintf(matFile,"%i",MAT_SPECULAR);
for (ii = 0; ii < 4; ii++)
fprintf(matFile," %f",getSpecularFloat(ii));
fprintf(matFile,"\n");
// Emission
fprintf(matFile,"%i",MAT_EMISSION);
for (ii = 0; ii < 4; ii++)
fprintf(matFile," %f",getEmissionFloat(ii));
fprintf(matFile,"\n");
// Shininess
fprintf(matFile,"%i %f\n",MAT_SHININESS,getShininessFloat());
fclose(matFile);
return FALSE;
}

View File

@@ -0,0 +1,41 @@
/*
* PVVMUD a 3D MUD
* Copyright (C) 1998-1999 Programvareverkstedet (pvv@pvv.org)
*
* 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.
*
* 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
*
*/
#include "pvvmud.H"
#include "vertex.H"
double CVertex::getX() const {
return m_coord[0];
}
double CVertex::getY() const {
return m_coord[1];
}
double CVertex::getZ() const {
return m_coord[2];
}
CVector CVertex::operator-(const CVertex & vertex) const{
return CVector(getX()-vertex.getX(),
getY()-vertex.getY(),getZ()-vertex.getZ());
}

View File

@@ -0,0 +1,122 @@
/*
* PVVMUD a 3D MUD
* Copyright (C) 1998-1999 Programvareverkstedet (pvv@pvv.org)
*
* 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.
*
* 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
*
*/
#include "pvvmud.H"
#include <stdio.h>
#include "geometry.H"
#include "bogfile.H"
#include "exception.H"
int CGeometry::writeBOG( FILE * bog ){
CGeometry * geo;
CPolygon * poly;
int numVertices,numNormals,numTexCoords,numPolygons,ii,jj,nn;
int type,materialId,index,subid,numSubobj;
double x,y,z,u,v;
numSubobj = getNumSubobjects();
fprintf(bog,"BOG 1 %i\n",numSubobj);
// Requrcive algo. done iterative
geo = this;
for (nn = 0; nn < numSubobj; nn++){
subid = geo->getSubId();
numVertices = geo->getNumVertices();
numNormals = geo->getNumNormals();
numTexCoords = geo->getNumTexCoords();
numPolygons = geo->getNumPolygons();
fprintf(bog,"%i %i %i %i %i\n",subid,numVertices,numNormals,
numTexCoords,numPolygons);
for (ii = 0; ii < numVertices; ii ++){
geo->getVertex(ii,&x,&y,&z);
fprintf(bog,"%f %f %f\n",x,y,z);
}
for (ii = 0; ii < numNormals; ii ++){
geo->getNormal(ii,&x,&y,&z);
fprintf(bog,"%f %f %f\n",x,y,z);
}
for (ii = 0; ii < numTexCoords; ii ++){
geo->getTexCoord(ii,&u,&v);
fprintf(bog,"%f %f\n",u,v);
}
for (ii = 0; ii < numPolygons; ii ++){
poly = geo->getPolygon(ii);
poly->get(&type,&materialId,&numVertices,&numNormals,&numTexCoords);
switch (type){
case POLYGON_POLYGON: type = PT_Polygon; break;
case POLYGON_TRIANGLES: type = PT_Triangles; break;
case POLYGON_QUADS: type = PT_Quads; break;
case POLYGON_QUAD_STRIP: type = PT_Quad_strip; break;
case POLYGON_TRIANGLE_STRIP: type = PT_Triangle_strip; break;
case POLYGON_TRIANGLE_FAN: type = PT_Triangle_fan; break;
}
fprintf(bog,"%i %i %i %i %i\n",
type, materialId, numVertices, numNormals, numTexCoords );
for (jj = 0; jj < numVertices; jj++){
index = poly->getVertexIndex(jj);
if (jj != (numVertices-1))
fprintf(bog,"%i ",index);
else
fprintf(bog,"%i\n",index);
}
for (jj = 0; jj < numNormals; jj++){
index = poly->getNormalIndex(jj);
if (jj != (numNormals-1))
fprintf(bog,"%i ",index);
else
fprintf(bog,"%i\n",index);
}
for (jj = 0; jj < numTexCoords; jj++){
index = poly->getTexCoordIndex(jj);
if (jj != (numTexCoords-1))
fprintf(bog,"%i ",index);
else
fprintf(bog,"%i\n",index);
}
}
geo = geo->getNext();
}
return TRUE;
}
void CGeometry::save(char * name){
FILE * bog;
int res;
bog = fopen(name,"w");
if (bog == NULL){
fprintf(stderr,"Error: Failed to open file %s\n",name);
throw new CException();
}
writeBOG(bog);
fclose(bog);
}

View File

@@ -0,0 +1,3 @@
INCLUDES = -I../../include
noinst_LIBRARIES = libgos.a
libgos_a_SOURCES = gos.C gosmessage.C gosprotocol.C msggos.C

327
common/lib/gos/Makefile.in Normal file
View File

@@ -0,0 +1,327 @@
# Makefile.in generated automatically by automake 1.4 from Makefile.am
# Copyright (C) 1994, 1995-8, 1999 Free Software Foundation, Inc.
# This Makefile.in is free software; the Free Software Foundation
# gives unlimited permission to copy and/or distribute it,
# with or without modifications, as long as this notice is preserved.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY, to the extent permitted by law; without
# even the implied warranty of MERCHANTABILITY or FITNESS FOR A
# PARTICULAR PURPOSE.
SHELL = @SHELL@
srcdir = @srcdir@
top_srcdir = @top_srcdir@
VPATH = @srcdir@
prefix = @prefix@
exec_prefix = @exec_prefix@
bindir = @bindir@
sbindir = @sbindir@
libexecdir = @libexecdir@
datadir = @datadir@
sysconfdir = @sysconfdir@
sharedstatedir = @sharedstatedir@
localstatedir = @localstatedir@
libdir = @libdir@
infodir = @infodir@
mandir = @mandir@
includedir = @includedir@
oldincludedir = /usr/include
DESTDIR =
pkgdatadir = $(datadir)/@PACKAGE@
pkglibdir = $(libdir)/@PACKAGE@
pkgincludedir = $(includedir)/@PACKAGE@
top_builddir = ../../..
ACLOCAL = @ACLOCAL@
AUTOCONF = @AUTOCONF@
AUTOMAKE = @AUTOMAKE@
AUTOHEADER = @AUTOHEADER@
INSTALL = @INSTALL@
INSTALL_PROGRAM = @INSTALL_PROGRAM@ $(AM_INSTALL_PROGRAM_FLAGS)
INSTALL_DATA = @INSTALL_DATA@
INSTALL_SCRIPT = @INSTALL_SCRIPT@
transform = @program_transform_name@
NORMAL_INSTALL = :
PRE_INSTALL = :
POST_INSTALL = :
NORMAL_UNINSTALL = :
PRE_UNINSTALL = :
POST_UNINSTALL = :
CC = @CC@
CXX = @CXX@
GL_CFLAGS = @GL_CFLAGS@
GL_LIBS = @GL_LIBS@
LEX = @LEX@
MAKEINFO = @MAKEINFO@
NETLIBS = @NETLIBS@
PACKAGE = @PACKAGE@
RANLIB = @RANLIB@
TIFF_CFLAGS = @TIFF_CFLAGS@
TIFF_LIBS = @TIFF_LIBS@
VERSION = @VERSION@
YACC = @YACC@
INCLUDES = -I../../include
noinst_LIBRARIES = libgos.a
libgos_a_SOURCES = gos.C gosmessage.C gosprotocol.C msggos.C
mkinstalldirs = $(SHELL) $(top_srcdir)/mkinstalldirs
CONFIG_CLEAN_FILES =
LIBRARIES = $(noinst_LIBRARIES)
DEFS = @DEFS@ -I. -I$(srcdir)
CPPFLAGS = @CPPFLAGS@
LDFLAGS = @LDFLAGS@
LIBS = @LIBS@
X_CFLAGS = @X_CFLAGS@
X_LIBS = @X_LIBS@
X_EXTRA_LIBS = @X_EXTRA_LIBS@
X_PRE_LIBS = @X_PRE_LIBS@
libgos_a_LIBADD =
libgos_a_OBJECTS = gos.o gosmessage.o gosprotocol.o msggos.o
AR = ar
CXXFLAGS = @CXXFLAGS@
CXXCOMPILE = $(CXX) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS)
CXXLD = $(CXX)
CXXLINK = $(CXXLD) $(AM_CXXFLAGS) $(CXXFLAGS) $(LDFLAGS) -o $@
DIST_COMMON = Makefile.am Makefile.in TODO
DISTFILES = $(DIST_COMMON) $(SOURCES) $(HEADERS) $(TEXINFOS) $(EXTRA_DIST)
TAR = gtar
GZIP_ENV = --best
DEP_FILES = .deps/gos.P .deps/gosmessage.P .deps/gosprotocol.P \
.deps/msggos.P
SOURCES = $(libgos_a_SOURCES)
OBJECTS = $(libgos_a_OBJECTS)
all: all-redirect
.SUFFIXES:
.SUFFIXES: .C .S .c .o .s
$(srcdir)/Makefile.in: Makefile.am $(top_srcdir)/configure.in $(ACLOCAL_M4)
cd $(top_srcdir) && $(AUTOMAKE) --foreign common/lib/gos/Makefile
Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status $(BUILT_SOURCES)
cd $(top_builddir) \
&& CONFIG_FILES=$(subdir)/$@ CONFIG_HEADERS= $(SHELL) ./config.status
mostlyclean-noinstLIBRARIES:
clean-noinstLIBRARIES:
-test -z "$(noinst_LIBRARIES)" || rm -f $(noinst_LIBRARIES)
distclean-noinstLIBRARIES:
maintainer-clean-noinstLIBRARIES:
.s.o:
$(COMPILE) -c $<
.S.o:
$(COMPILE) -c $<
mostlyclean-compile:
-rm -f *.o core *.core
clean-compile:
distclean-compile:
-rm -f *.tab.c
maintainer-clean-compile:
libgos.a: $(libgos_a_OBJECTS) $(libgos_a_DEPENDENCIES)
-rm -f libgos.a
$(AR) cru libgos.a $(libgos_a_OBJECTS) $(libgos_a_LIBADD)
$(RANLIB) libgos.a
.C.o:
$(CXXCOMPILE) -c $<
tags: TAGS
ID: $(HEADERS) $(SOURCES) $(LISP)
list='$(SOURCES) $(HEADERS)'; \
unique=`for i in $$list; do echo $$i; done | \
awk ' { files[$$0] = 1; } \
END { for (i in files) print i; }'`; \
here=`pwd` && cd $(srcdir) \
&& mkid -f$$here/ID $$unique $(LISP)
TAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) $(LISP)
tags=; \
here=`pwd`; \
list='$(SOURCES) $(HEADERS)'; \
unique=`for i in $$list; do echo $$i; done | \
awk ' { files[$$0] = 1; } \
END { for (i in files) print i; }'`; \
test -z "$(ETAGS_ARGS)$$unique$(LISP)$$tags" \
|| (cd $(srcdir) && etags $(ETAGS_ARGS) $$tags $$unique $(LISP) -o $$here/TAGS)
mostlyclean-tags:
clean-tags:
distclean-tags:
-rm -f TAGS ID
maintainer-clean-tags:
distdir = $(top_builddir)/$(PACKAGE)-$(VERSION)/$(subdir)
subdir = common/lib/gos
distdir: $(DISTFILES)
here=`cd $(top_builddir) && pwd`; \
top_distdir=`cd $(top_distdir) && pwd`; \
distdir=`cd $(distdir) && pwd`; \
cd $(top_srcdir) \
&& $(AUTOMAKE) --include-deps --build-dir=$$here --srcdir-name=$(top_srcdir) --output-dir=$$top_distdir --foreign common/lib/gos/Makefile
@for file in $(DISTFILES); do \
d=$(srcdir); \
if test -d $$d/$$file; then \
cp -pr $$/$$file $(distdir)/$$file; \
else \
test -f $(distdir)/$$file \
|| ln $$d/$$file $(distdir)/$$file 2> /dev/null \
|| cp -p $$d/$$file $(distdir)/$$file || :; \
fi; \
done
DEPS_MAGIC := $(shell mkdir .deps > /dev/null 2>&1 || :)
-include $(DEP_FILES)
mostlyclean-depend:
clean-depend:
distclean-depend:
-rm -rf .deps
maintainer-clean-depend:
%.o: %.c
@echo '$(COMPILE) -c $<'; \
$(COMPILE) -Wp,-MD,.deps/$(*F).pp -c $<
@-cp .deps/$(*F).pp .deps/$(*F).P; \
tr ' ' '\012' < .deps/$(*F).pp \
| sed -e 's/^\\$$//' -e '/^$$/ d' -e '/:$$/ d' -e 's/$$/ :/' \
>> .deps/$(*F).P; \
rm .deps/$(*F).pp
%.lo: %.c
@echo '$(LTCOMPILE) -c $<'; \
$(LTCOMPILE) -Wp,-MD,.deps/$(*F).pp -c $<
@-sed -e 's/^\([^:]*\)\.o[ ]*:/\1.lo \1.o :/' \
< .deps/$(*F).pp > .deps/$(*F).P; \
tr ' ' '\012' < .deps/$(*F).pp \
| sed -e 's/^\\$$//' -e '/^$$/ d' -e '/:$$/ d' -e 's/$$/ :/' \
>> .deps/$(*F).P; \
rm -f .deps/$(*F).pp
%.o: %.C
@echo '$(CXXCOMPILE) -c $<'; \
$(CXXCOMPILE) -Wp,-MD,.deps/$(*F).pp -c $<
@-cp .deps/$(*F).pp .deps/$(*F).P; \
tr ' ' '\012' < .deps/$(*F).pp \
| sed -e 's/^\\$$//' -e '/^$$/ d' -e '/:$$/ d' -e 's/$$/ :/' \
>> .deps/$(*F).P; \
rm .deps/$(*F).pp
%.lo: %.C
@echo '$(LTCXXCOMPILE) -c $<'; \
$(LTCXXCOMPILE) -Wp,-MD,.deps/$(*F).pp -c $<
@-sed -e 's/^\([^:]*\)\.o[ ]*:/\1.lo \1.o :/' \
< .deps/$(*F).pp > .deps/$(*F).P; \
tr ' ' '\012' < .deps/$(*F).pp \
| sed -e 's/^\\$$//' -e '/^$$/ d' -e '/:$$/ d' -e 's/$$/ :/' \
>> .deps/$(*F).P; \
rm -f .deps/$(*F).pp
info-am:
info: info-am
dvi-am:
dvi: dvi-am
check-am: all-am
check: check-am
installcheck-am:
installcheck: installcheck-am
install-exec-am:
install-exec: install-exec-am
install-data-am:
install-data: install-data-am
install-am: all-am
@$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am
install: install-am
uninstall-am:
uninstall: uninstall-am
all-am: Makefile $(LIBRARIES)
all-redirect: all-am
install-strip:
$(MAKE) $(AM_MAKEFLAGS) AM_INSTALL_PROGRAM_FLAGS=-s install
installdirs:
mostlyclean-generic:
clean-generic:
distclean-generic:
-rm -f Makefile $(CONFIG_CLEAN_FILES)
-rm -f config.cache config.log stamp-h stamp-h[0-9]*
maintainer-clean-generic:
mostlyclean-am: mostlyclean-noinstLIBRARIES mostlyclean-compile \
mostlyclean-tags mostlyclean-depend mostlyclean-generic
mostlyclean: mostlyclean-am
clean-am: clean-noinstLIBRARIES clean-compile clean-tags clean-depend \
clean-generic mostlyclean-am
clean: clean-am
distclean-am: distclean-noinstLIBRARIES distclean-compile \
distclean-tags distclean-depend distclean-generic \
clean-am
distclean: distclean-am
maintainer-clean-am: maintainer-clean-noinstLIBRARIES \
maintainer-clean-compile maintainer-clean-tags \
maintainer-clean-depend maintainer-clean-generic \
distclean-am
@echo "This command is intended for maintainers to use;"
@echo "it deletes files that may require special tools to rebuild."
maintainer-clean: maintainer-clean-am
.PHONY: mostlyclean-noinstLIBRARIES distclean-noinstLIBRARIES \
clean-noinstLIBRARIES maintainer-clean-noinstLIBRARIES \
mostlyclean-compile distclean-compile clean-compile \
maintainer-clean-compile tags mostlyclean-tags distclean-tags \
clean-tags maintainer-clean-tags distdir mostlyclean-depend \
distclean-depend clean-depend maintainer-clean-depend info-am info \
dvi-am dvi check check-am installcheck-am installcheck install-exec-am \
install-exec install-data-am install-data install-am install \
uninstall-am uninstall all-redirect all-am all installdirs \
mostlyclean-generic distclean-generic clean-generic \
maintainer-clean-generic clean mostlyclean distclean maintainer-clean
# Tell versions [3.59,3.63) of GNU make to not export all variables.
# Otherwise a system limit (for SysV at least) may be exceeded.
.NOEXPORT:

4
common/lib/gos/TODO Normal file
View File

@@ -0,0 +1,4 @@
CGOS:quit() Function called from CCommunicate when link to server terminate.
This situation isn't handled correct in client code.
MsgGeometry: Polygon materialId int -> DWORD

74
common/lib/gos/gos.C Normal file
View File

@@ -0,0 +1,74 @@
/*
* PVVMUD a 3D MUD
* Copyright (C) 1998-1999 Programvareverkstedet (pvv@pvv.org)
*
* 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.
*
* 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
*
*/
#include "pvvmud.H"
#include <sys/types.h>
#include <netinet/in.h>
#include <iostream.h>
#include "gos.H"
#include "gosprotocol.H"
#include "gosmessage.H"
CGOS::CGOS(CTimeKeeper * timeKeeper, CInetAddress *addr){
socket = new CClientSocket(addr->getAddress(),addr->getPort());
socket->setNonBlocking();
CGOSProtocol * protocol = new CGOSProtocol(socket,timeKeeper);
protocol->setName("GOS");
setCommunicate(protocol);
}
void CGOS::quit(){
cdebug << "ERROR: Quit not impl.!\b";
}
void CGOS::request(int requestType,int requestId){
CMessage * msg = new CMsgGOSRequest(requestType,requestId);
getCommunicate()->sendMessage(msg,TRUE);
}
void CGOS::error(){
}
void CGOS::geometry(CGeometry * geometry){
delete geometry;
}
void CGOS::material(CMaterial * material){
delete material;
}
void CGOS::texture(CTexture * texture){
delete texture;
}
CGeometry * CGOS::newGeometry(int geometryId, int numVertices,
int numNormals, int numTexCoords, int numPolygons){
return new CGeometry(geometryId,numVertices,numNormals,
numTexCoords,numPolygons);
}
CMaterial * CGOS::newMaterial(int materialId){
return new CMaterial(materialId);
}
CTexture * CGOS::newTexture(int textureId){
return new CTexture(textureId);
}

118
common/lib/gos/gosmessage.C Normal file
View File

@@ -0,0 +1,118 @@
/*
* PVVMUD a 3D MUD
* Copyright (C) 1998-1999 Programvareverkstedet (pvv@pvv.org)
*
* 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.
*
* 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
*
*/
#include "pvvmud.H"
#include <iostream.h>
#include <limits.h>
#include <stdio.h>
#include "gosmessage.H"
#include "gos.H"
///////////////////////////////////////////////////////////////////////////////
// MsgGOSErrorGetGOS
CMsgGOSErrorGetGOS::CMsgGOSErrorGetGOS():CMsgGOSError(){
}
CMsgGOSErrorGetGOS * CMsgGOSErrorGetGOS::createMsg(){
return new CMsgGOSErrorGetGOS();
}
int CMsgGOSErrorGetGOS::executeMsg(){
// cdebug << "Error: " << getError() << "\n";
CGOS * gos = (CGOS*)getManager();
gos->error();
return true;
}
///////////////////////////////////////////////////////////////////////////////
// MsgGeometryGetGOS
CMsgGeometryGetGOS::CMsgGeometryGetGOS():CMsgGeometry(){
}
CMsgGeometryGetGOS * CMsgGeometryGetGOS::createMsg(){
return new CMsgGeometryGetGOS();
}
int CMsgGeometryGetGOS::executeMsg(){
// cdebug << "Executing get gos geometry " << getGeometryId() << "\n";
CGOS * gos = (CGOS*)getManager();
CGeometry * geometry = getGeometry();
if (geometry != NULL) gos->geometry(geometry);
return TRUE;
}
CGeometry * CMsgGeometryGetGOS::newGeometry(int geometryId, int numVertices,
int numNormals, int numTexCoords, int numPolygons){
CGOS * gos = (CGOS*)getManager();
return gos->newGeometry(geometryId,numVertices,numNormals,
numTexCoords,numPolygons);
}
///////////////////////////////////////////////////////////////////////////////
// MsgMaterialGetGOS
CMsgMaterialGetGOS::CMsgMaterialGetGOS():CMsgMaterial(){
}
CMsgMaterialGetGOS * CMsgMaterialGetGOS::createMsg(){
return new CMsgMaterialGetGOS();
}
int CMsgMaterialGetGOS::executeMsg(){
// cdebug << "Executing get gos material " << getMaterialId() << "\n";
CGOS * gos = (CGOS*)getManager();
CMaterial * material = getMaterial();
if (material != NULL) gos->material(material);
return TRUE;
}
CMaterial * CMsgMaterialGetGOS::newMaterial(int materialId){
CGOS * gos = (CGOS*)getManager();
return gos->newMaterial(materialId);
}
///////////////////////////////////////////////////////////////////////////////
// MsgTextureGetGOS
CMsgTextureGetGOS::CMsgTextureGetGOS():CMsgTexture(){
}
CMsgTextureGetGOS * CMsgTextureGetGOS::createMsg(){
return new CMsgTextureGetGOS();
}
int CMsgTextureGetGOS::executeMsg(){
// cdebug << "Executing get gos texture " << getTextureId() << "\n";
CGOS * gos = (CGOS*)getManager();
CTexture * texture = getTexture();
if (texture != NULL) gos->texture(texture);
return TRUE;
}
CTexture * CMsgTextureGetGOS::newTexture(int textureId){
CGOS * gos = (CGOS*)getManager();
return gos->newTexture(textureId);
}

View File

@@ -0,0 +1,37 @@
/*
* PVVMUD a 3D MUD
* Copyright (C) 1998-1999 Programvareverkstedet (pvv@pvv.org)
*
* 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.
*
* 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
*
*/
#include "pvvmud.H"
#include "gosprotocol.H"
#include "gosmessage.H"
#include "gos.H"
CGOSProtocol::CGOSProtocol(CSocket * socket,CTimeKeeper * timeKeeper)
:CCommunicate(socket,timeKeeper) {
addMsg((MsgCreateFunc_t)CMsgGOSErrorGetGOS::createMsg);
addMsg((MsgCreateFunc_t)CMsgGeometryGetGOS::createMsg);
addMsg((MsgCreateFunc_t)CMsgMaterialGetGOS::createMsg);
addMsg((MsgCreateFunc_t)CMsgTextureGetGOS::createMsg);
}
void CGOSProtocol::quit(){
CGOS * gos = (CGOS*)getManager();
gos->quit();
}

374
common/lib/gos/msggos.C Normal file
View File

@@ -0,0 +1,374 @@
/*
* PVVMUD a 3D MUD
* Copyright (C) 1998-1999 Programvareverkstedet (pvv@pvv.org)
*
* 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.
*
* 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
*
*/
#include "pvvmud.H"
#include <stdlib.h>
#include <iostream.h>
#include "msggos.H"
#include "texture.H"
///////////////////////////////////////////////////////////////////////////////
// MsgGOSError
CMsgGOSError::CMsgGOSError():CMessage(MSG_GOSERROR, sizeof(BYTE)){
setName("MsgGOSError");
writeByte(1,0); // Error
}
CMsgGOSError::CMsgGOSError(BYTE error):CMessage(MSG_GOSERROR, sizeof(BYTE)){
setName("MsgGOSError");
writeByte(1,error);
}
BYTE CMsgGOSError::getError(){
return readByte(1);
}
///////////////////////////////////////////////////////////////////////////////
// MsgGOSRequest
CMsgGOSRequest::CMsgGOSRequest():CMessage(MSG_GOSREQUEST, sizeof(BYTE) + sizeof(WORD)){
setName("MsgGOSRequest");
}
CMsgGOSRequest::CMsgGOSRequest(BYTE requestType,WORD objectId):CMessage(MSG_GOSREQUEST, sizeof(BYTE) + sizeof(WORD)){
setName("MsgGOSRequest");
writeByte(1,requestType);
writeWord(2,objectId);
}
BYTE CMsgGOSRequest::getRequestType(){
return readByte(1);
}
WORD CMsgGOSRequest::getObjectId(){
return readWord(2);
}
///////////////////////////////////////////////////////////////////////////////
// MsgGeometry
CMsgGeometry::CMsgGeometry():CMsgVarLength(MSG_GEOMETRY){
setName("MsgGeometry");
}
#define HEADSIZE (sizeof(DWORD)+sizeof(WORD)*4)
#define VERTEXSIZE (3*sizeof(DWORD))
#define NORMALSIZE (3*sizeof(DWORD))
#define TEXCOORDSIZE (2*sizeof(DWORD))
#define POLYGONHEADSIZE (sizeof(DWORD)+4*sizeof(WORD))
CMsgGeometry::CMsgGeometry(CGeometry & geometry):CMsgVarLength(MSG_GEOMETRY){
setName("MsgGeometry");
WORD numV,numN,numTC,numP;
int type,materialId,numVI,numNI,numTCI;
DWORD size = sizeof(DWORD)+sizeof(WORD); // GeometryId + NumSubObjects
WORD numSubObjects = 0;
// Calculate size
CGeometry * geo = &geometry;
while (geo != NULL){
numSubObjects++;
size += HEADSIZE;
numV = geo->getNumVertices();
numN = geo->getNumNormals();
numTC = geo->getNumTexCoords();
numP = geo->getNumPolygons();
size += numV*VERTEXSIZE+numN*NORMALSIZE+numTC*TEXCOORDSIZE;
while (numP-- > 0){
size += POLYGONHEADSIZE;
CPolygon * poly = geo->getPolygon(numP);
poly->get(&type,&materialId,&numVI,&numNI,&numTCI);
size += (numVI + numNI + numTCI)*sizeof(WORD);
}
geo = geo->getNext();
}
// Then the size is known
setBodyLength(size);
cdebug << "Geometry: size " << size << "\n";
// Write geometry
writeDWord(getLength(),geometry.getId());
writeWord(MSGCURRPOS,numSubObjects);
geo = &geometry;
while (geo != NULL){
numV = geo->getNumVertices();
numN = geo->getNumNormals();
numTC = geo->getNumTexCoords();
numP = geo->getNumPolygons();
// Write geometry head
writeWord(MSGCURRPOS,numV);
writeWord(MSGCURRPOS,numN);
writeWord(MSGCURRPOS,numTC);
writeWord(MSGCURRPOS,numP);
writeDWord(MSGCURRPOS,geo->getSubId());
// Write geometry body
// Vertices
while (numV-- > 0){
CVertex * vertex = geo->getVertex(numV);
writeDouble(MSGCURRPOS,vertex->getZ());
writeDouble(MSGCURRPOS,vertex->getY());
writeDouble(MSGCURRPOS,vertex->getX());
}
// Normals
while (numN-- > 0){
CNormal * normal = geo->getNormal(numN);
writeDouble(MSGCURRPOS,normal->getZ());
writeDouble(MSGCURRPOS,normal->getY());
writeDouble(MSGCURRPOS,normal->getX());
}
// TexCoords
while (numTC-- > 0){
CTexCoord * texCoord = geo->getTexCoord(numTC);
writeDouble(MSGCURRPOS,texCoord->getV());
writeDouble(MSGCURRPOS,texCoord->getU());
}
// Polygons
while (numP-- > 0){
CPolygon * poly = geo->getPolygon(numP);
// Write polygon head
poly->get(&type,&materialId,&numVI,&numNI,&numTCI);
writeDWord(MSGCURRPOS,materialId);
writeWord(MSGCURRPOS,type);
writeWord(MSGCURRPOS,numVI);
writeWord(MSGCURRPOS,numNI);
writeWord(MSGCURRPOS,numTCI);
// Write polygon body
// Vertex index list
while (numVI-- > 0){
writeWord(MSGCURRPOS,poly->getVertexIndex(numVI));
}
// Normal index list
while (numNI-- > 0){
writeWord(MSGCURRPOS,poly->getNormalIndex(numNI));
}
// TexCoord index list
while (numTCI-- > 0){
writeWord(MSGCURRPOS,poly->getTexCoordIndex(numTCI));
}
}
geo = geo->getNext();
}
}
DWORD CMsgGeometry::getGeometryId(){
return readDWord(getLength());
}
CGeometry* CMsgGeometry::getGeometry(){
// cdebug << "CMsgGeometry::getGeometry: Not impl.!\n";
CGeometry *geo = NULL;
// Set the current read pointer in correct position
DWORD geometryId = getGeometryId();
// Get number of subobjects and read them
WORD numSubObjects = readWord(MSGCURRPOS);
while (numSubObjects-- > 0){
// Read geometry head and create geometry
WORD numV = readWord(MSGCURRPOS);
WORD numN = readWord(MSGCURRPOS);
WORD numTC = readWord(MSGCURRPOS);
WORD numP = readWord(MSGCURRPOS);
CGeometry * newgeo = newGeometry(geometryId,numV,numN,numTC,numP);
newgeo->setNext(geo);
geo = newgeo;
geo->setSubId(readDWord(MSGCURRPOS));
// Read geometry body
// Vertices
while (numV-- > 0){
geo->setVertex(numV,readDouble(MSGCURRPOS),readDouble(MSGCURRPOS),readDouble(MSGCURRPOS));
}
// Normals
while (numN-- > 0){
geo->setNormal(numN,readDouble(MSGCURRPOS),readDouble(MSGCURRPOS),readDouble(MSGCURRPOS));
}
// TexCoords
while (numTC-- > 0){
geo->setTexCoord(numTC,readDouble(MSGCURRPOS),readDouble(MSGCURRPOS));
}
// Polygons
while (numP-- > 0){
int type,materialId,numVI,numNI,numTCI;
// Read polygon head
materialId = readDWord(MSGCURRPOS);
type = readWord(MSGCURRPOS);
numVI = readWord(MSGCURRPOS);
numNI = readWord(MSGCURRPOS);
numTCI = readWord(MSGCURRPOS);
CPolygon * poly = new CPolygon(type,materialId,numVI,numNI,numTCI);
// Read polygon body
// Read vertex index list
while (numVI-- > 0){
poly->setVertexIndex(numVI,readWord(MSGCURRPOS));
}
// Read normal index list
while (numNI-- > 0){
poly->setNormalIndex(numNI,readWord(MSGCURRPOS));
}
// Read texCoord index list
while (numTCI-- > 0){
poly->setTexCoordIndex(numTCI,readWord(MSGCURRPOS));
}
geo->setPolygon(numP,poly);
}
}
return geo;
}
CGeometry * CMsgGeometry::newGeometry(int geometryId, int numVertices,
int numNormals, int numTexCoords, int numPolygons){
return new CGeometry(geometryId,numVertices,numNormals,
numTexCoords,numPolygons);
}
///////////////////////////////////////////////////////////////////////////////
// MsgMaterial
CMsgMaterial::CMsgMaterial():CMessage(MSG_MATERIAL,sizeof(WORD)*2+4*4+1){
setName("MsgMaterial");
}
CMsgMaterial::CMsgMaterial(CMaterial & material):CMessage(MSG_MATERIAL,sizeof(WORD)*2+4*4+1){
cdebug << "CMegsMaterial\n";
setName("MsgMaterial");
writeWord(1,material.getId());
writeWord(3,material.getTextureId());
for (int ii = 0; ii < 4 ; ii++){
writeByte(5+ii,material.getAmbientByte(ii));
writeByte(9+ii,material.getDiffuseByte(ii));
writeByte(13+ii,material.getSpecularByte(ii));
writeByte(17+ii,material.getEmissionByte(ii));
}
writeByte(21,material.getShininessByte());
}
int CMsgMaterial::getMaterialId(){
return (short int)readWord(1);
}
int CMsgMaterial::getTextureId(){
return (short int)readWord(3);
}
BYTE CMsgMaterial::getAmbientByte(int num){
return readByte(5+num);
}
BYTE CMsgMaterial::getDiffuseByte(int num){
return readByte(9+num);
}
BYTE CMsgMaterial::getSpecularByte(int num){
return readByte(13+num);
}
BYTE CMsgMaterial::getEmissionByte(int num){
return readByte(17+num);
}
BYTE CMsgMaterial::getShininessByte(){
return readByte(21);
}
CMaterial* CMsgMaterial::getMaterial(){
CMaterial * material = newMaterial(getMaterialId());
material->setTextureId(getTextureId());
for (int ii = 0; ii < 4; ii++){
material->setAmbient(ii,getAmbientByte(ii));
material->setDiffuse(ii,getDiffuseByte(ii));
material->setSpecular(ii,getSpecularByte(ii));
material->setEmission(ii,getEmissionByte(ii));
}
material->setShininess(getShininessByte());
return material;
}
CMaterial * CMsgMaterial::newMaterial(int materialId){
return new CMaterial(materialId);
}
///////////////////////////////////////////////////////////////////////////////
// MsgTexture
CMsgTexture::CMsgTexture():CMsgVarLength(MSG_TEXTURE){
setName("MsgTexture");
}
CMsgTexture::CMsgTexture(CTexture & texture):CMsgVarLength(MSG_TEXTURE){
setName("MsgTexture");
CTextureMap * map = texture.getTextureMap();
setBodyLength(sizeof(WORD)*3 + map->getWidth()*map->getHeight()*sizeof(DWORD));
writeWord(getLength(),texture.getId());
writeWord(getLength()+2,map->getWidth());
writeWord(getLength()+4,map->getHeight());
writeBuf(getLength()+6,map->getData(),map->getWidth()*map->getHeight()*sizeof(DWORD));
}
WORD CMsgTexture::getTextureId(){
return readWord(getLength());
}
WORD CMsgTexture::getMapWidth(){
return readWord(getLength()+2);
}
WORD CMsgTexture::getMapHeight(){
return readWord(getLength()+4);
}
CTexture * CMsgTexture::getTexture(){
CTexture * texture = newTexture(getTextureId());
WORD width = getMapWidth();
WORD height = getMapHeight();
BYTE * data = (BYTE*)malloc(width*height*sizeof(DWORD));
readBuf(getLength()+6,data,width*height*sizeof(DWORD));
CTextureMap * map = new CTextureMap(width,height,data);
texture->setTextureMap(map);
return texture;
}
CTexture * CMsgTexture::newTexture(int textureId){
return new CTexture(textureId);
}

View File

@@ -0,0 +1,3 @@
INCLUDES = -I../../include
noinst_LIBRARIES = libsrvcli.a
libsrvcli_a_SOURCES = action.C bbox.C bsdtree.C communicate.C direction.C exception.C inetaddress.C manager.C message.C messagelist.C msgactionlist.C msgmsg.C msgserver.C msgsrvcli.C msgsrvgos.C msgvarlength.C object.C objectlist.C objectqueue.C position.C socket.C stream.C timekeeper.C viewpoint.C

View File

@@ -0,0 +1,336 @@
# Makefile.in generated automatically by automake 1.4 from Makefile.am
# Copyright (C) 1994, 1995-8, 1999 Free Software Foundation, Inc.
# This Makefile.in is free software; the Free Software Foundation
# gives unlimited permission to copy and/or distribute it,
# with or without modifications, as long as this notice is preserved.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY, to the extent permitted by law; without
# even the implied warranty of MERCHANTABILITY or FITNESS FOR A
# PARTICULAR PURPOSE.
SHELL = @SHELL@
srcdir = @srcdir@
top_srcdir = @top_srcdir@
VPATH = @srcdir@
prefix = @prefix@
exec_prefix = @exec_prefix@
bindir = @bindir@
sbindir = @sbindir@
libexecdir = @libexecdir@
datadir = @datadir@
sysconfdir = @sysconfdir@
sharedstatedir = @sharedstatedir@
localstatedir = @localstatedir@
libdir = @libdir@
infodir = @infodir@
mandir = @mandir@
includedir = @includedir@
oldincludedir = /usr/include
DESTDIR =
pkgdatadir = $(datadir)/@PACKAGE@
pkglibdir = $(libdir)/@PACKAGE@
pkgincludedir = $(includedir)/@PACKAGE@
top_builddir = ../../..
ACLOCAL = @ACLOCAL@
AUTOCONF = @AUTOCONF@
AUTOMAKE = @AUTOMAKE@
AUTOHEADER = @AUTOHEADER@
INSTALL = @INSTALL@
INSTALL_PROGRAM = @INSTALL_PROGRAM@ $(AM_INSTALL_PROGRAM_FLAGS)
INSTALL_DATA = @INSTALL_DATA@
INSTALL_SCRIPT = @INSTALL_SCRIPT@
transform = @program_transform_name@
NORMAL_INSTALL = :
PRE_INSTALL = :
POST_INSTALL = :
NORMAL_UNINSTALL = :
PRE_UNINSTALL = :
POST_UNINSTALL = :
CC = @CC@
CXX = @CXX@
GL_CFLAGS = @GL_CFLAGS@
GL_LIBS = @GL_LIBS@
LEX = @LEX@
MAKEINFO = @MAKEINFO@
NETLIBS = @NETLIBS@
PACKAGE = @PACKAGE@
RANLIB = @RANLIB@
TIFF_CFLAGS = @TIFF_CFLAGS@
TIFF_LIBS = @TIFF_LIBS@
VERSION = @VERSION@
YACC = @YACC@
INCLUDES = -I../../include
noinst_LIBRARIES = libsrvcli.a
libsrvcli_a_SOURCES = action.C bbox.C bsdtree.C communicate.C direction.C exception.C inetaddress.C manager.C message.C messagelist.C msgactionlist.C msgmsg.C msgserver.C msgsrvcli.C msgsrvgos.C msgvarlength.C object.C objectlist.C objectqueue.C position.C socket.C stream.C timekeeper.C viewpoint.C
mkinstalldirs = $(SHELL) $(top_srcdir)/mkinstalldirs
CONFIG_CLEAN_FILES =
LIBRARIES = $(noinst_LIBRARIES)
DEFS = @DEFS@ -I. -I$(srcdir)
CPPFLAGS = @CPPFLAGS@
LDFLAGS = @LDFLAGS@
LIBS = @LIBS@
X_CFLAGS = @X_CFLAGS@
X_LIBS = @X_LIBS@
X_EXTRA_LIBS = @X_EXTRA_LIBS@
X_PRE_LIBS = @X_PRE_LIBS@
libsrvcli_a_LIBADD =
libsrvcli_a_OBJECTS = action.o bbox.o bsdtree.o communicate.o \
direction.o exception.o inetaddress.o manager.o message.o messagelist.o \
msgactionlist.o msgmsg.o msgserver.o msgsrvcli.o msgsrvgos.o \
msgvarlength.o object.o objectlist.o objectqueue.o position.o socket.o \
stream.o timekeeper.o viewpoint.o
AR = ar
CXXFLAGS = @CXXFLAGS@
CXXCOMPILE = $(CXX) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS)
CXXLD = $(CXX)
CXXLINK = $(CXXLD) $(AM_CXXFLAGS) $(CXXFLAGS) $(LDFLAGS) -o $@
DIST_COMMON = Makefile.am Makefile.in TODO
DISTFILES = $(DIST_COMMON) $(SOURCES) $(HEADERS) $(TEXINFOS) $(EXTRA_DIST)
TAR = gtar
GZIP_ENV = --best
DEP_FILES = .deps/action.P .deps/bbox.P .deps/bsdtree.P \
.deps/communicate.P .deps/direction.P .deps/exception.P \
.deps/inetaddress.P .deps/manager.P .deps/message.P .deps/messagelist.P \
.deps/msgactionlist.P .deps/msgmsg.P .deps/msgserver.P \
.deps/msgsrvcli.P .deps/msgsrvgos.P .deps/msgvarlength.P .deps/object.P \
.deps/objectlist.P .deps/objectqueue.P .deps/position.P .deps/socket.P \
.deps/stream.P .deps/timekeeper.P .deps/viewpoint.P
SOURCES = $(libsrvcli_a_SOURCES)
OBJECTS = $(libsrvcli_a_OBJECTS)
all: all-redirect
.SUFFIXES:
.SUFFIXES: .C .S .c .o .s
$(srcdir)/Makefile.in: Makefile.am $(top_srcdir)/configure.in $(ACLOCAL_M4)
cd $(top_srcdir) && $(AUTOMAKE) --foreign common/lib/srvcli/Makefile
Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status $(BUILT_SOURCES)
cd $(top_builddir) \
&& CONFIG_FILES=$(subdir)/$@ CONFIG_HEADERS= $(SHELL) ./config.status
mostlyclean-noinstLIBRARIES:
clean-noinstLIBRARIES:
-test -z "$(noinst_LIBRARIES)" || rm -f $(noinst_LIBRARIES)
distclean-noinstLIBRARIES:
maintainer-clean-noinstLIBRARIES:
.s.o:
$(COMPILE) -c $<
.S.o:
$(COMPILE) -c $<
mostlyclean-compile:
-rm -f *.o core *.core
clean-compile:
distclean-compile:
-rm -f *.tab.c
maintainer-clean-compile:
libsrvcli.a: $(libsrvcli_a_OBJECTS) $(libsrvcli_a_DEPENDENCIES)
-rm -f libsrvcli.a
$(AR) cru libsrvcli.a $(libsrvcli_a_OBJECTS) $(libsrvcli_a_LIBADD)
$(RANLIB) libsrvcli.a
.C.o:
$(CXXCOMPILE) -c $<
tags: TAGS
ID: $(HEADERS) $(SOURCES) $(LISP)
list='$(SOURCES) $(HEADERS)'; \
unique=`for i in $$list; do echo $$i; done | \
awk ' { files[$$0] = 1; } \
END { for (i in files) print i; }'`; \
here=`pwd` && cd $(srcdir) \
&& mkid -f$$here/ID $$unique $(LISP)
TAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) $(LISP)
tags=; \
here=`pwd`; \
list='$(SOURCES) $(HEADERS)'; \
unique=`for i in $$list; do echo $$i; done | \
awk ' { files[$$0] = 1; } \
END { for (i in files) print i; }'`; \
test -z "$(ETAGS_ARGS)$$unique$(LISP)$$tags" \
|| (cd $(srcdir) && etags $(ETAGS_ARGS) $$tags $$unique $(LISP) -o $$here/TAGS)
mostlyclean-tags:
clean-tags:
distclean-tags:
-rm -f TAGS ID
maintainer-clean-tags:
distdir = $(top_builddir)/$(PACKAGE)-$(VERSION)/$(subdir)
subdir = common/lib/srvcli
distdir: $(DISTFILES)
here=`cd $(top_builddir) && pwd`; \
top_distdir=`cd $(top_distdir) && pwd`; \
distdir=`cd $(distdir) && pwd`; \
cd $(top_srcdir) \
&& $(AUTOMAKE) --include-deps --build-dir=$$here --srcdir-name=$(top_srcdir) --output-dir=$$top_distdir --foreign common/lib/srvcli/Makefile
@for file in $(DISTFILES); do \
d=$(srcdir); \
if test -d $$d/$$file; then \
cp -pr $$/$$file $(distdir)/$$file; \
else \
test -f $(distdir)/$$file \
|| ln $$d/$$file $(distdir)/$$file 2> /dev/null \
|| cp -p $$d/$$file $(distdir)/$$file || :; \
fi; \
done
DEPS_MAGIC := $(shell mkdir .deps > /dev/null 2>&1 || :)
-include $(DEP_FILES)
mostlyclean-depend:
clean-depend:
distclean-depend:
-rm -rf .deps
maintainer-clean-depend:
%.o: %.c
@echo '$(COMPILE) -c $<'; \
$(COMPILE) -Wp,-MD,.deps/$(*F).pp -c $<
@-cp .deps/$(*F).pp .deps/$(*F).P; \
tr ' ' '\012' < .deps/$(*F).pp \
| sed -e 's/^\\$$//' -e '/^$$/ d' -e '/:$$/ d' -e 's/$$/ :/' \
>> .deps/$(*F).P; \
rm .deps/$(*F).pp
%.lo: %.c
@echo '$(LTCOMPILE) -c $<'; \
$(LTCOMPILE) -Wp,-MD,.deps/$(*F).pp -c $<
@-sed -e 's/^\([^:]*\)\.o[ ]*:/\1.lo \1.o :/' \
< .deps/$(*F).pp > .deps/$(*F).P; \
tr ' ' '\012' < .deps/$(*F).pp \
| sed -e 's/^\\$$//' -e '/^$$/ d' -e '/:$$/ d' -e 's/$$/ :/' \
>> .deps/$(*F).P; \
rm -f .deps/$(*F).pp
%.o: %.C
@echo '$(CXXCOMPILE) -c $<'; \
$(CXXCOMPILE) -Wp,-MD,.deps/$(*F).pp -c $<
@-cp .deps/$(*F).pp .deps/$(*F).P; \
tr ' ' '\012' < .deps/$(*F).pp \
| sed -e 's/^\\$$//' -e '/^$$/ d' -e '/:$$/ d' -e 's/$$/ :/' \
>> .deps/$(*F).P; \
rm .deps/$(*F).pp
%.lo: %.C
@echo '$(LTCXXCOMPILE) -c $<'; \
$(LTCXXCOMPILE) -Wp,-MD,.deps/$(*F).pp -c $<
@-sed -e 's/^\([^:]*\)\.o[ ]*:/\1.lo \1.o :/' \
< .deps/$(*F).pp > .deps/$(*F).P; \
tr ' ' '\012' < .deps/$(*F).pp \
| sed -e 's/^\\$$//' -e '/^$$/ d' -e '/:$$/ d' -e 's/$$/ :/' \
>> .deps/$(*F).P; \
rm -f .deps/$(*F).pp
info-am:
info: info-am
dvi-am:
dvi: dvi-am
check-am: all-am
check: check-am
installcheck-am:
installcheck: installcheck-am
install-exec-am:
install-exec: install-exec-am
install-data-am:
install-data: install-data-am
install-am: all-am
@$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am
install: install-am
uninstall-am:
uninstall: uninstall-am
all-am: Makefile $(LIBRARIES)
all-redirect: all-am
install-strip:
$(MAKE) $(AM_MAKEFLAGS) AM_INSTALL_PROGRAM_FLAGS=-s install
installdirs:
mostlyclean-generic:
clean-generic:
distclean-generic:
-rm -f Makefile $(CONFIG_CLEAN_FILES)
-rm -f config.cache config.log stamp-h stamp-h[0-9]*
maintainer-clean-generic:
mostlyclean-am: mostlyclean-noinstLIBRARIES mostlyclean-compile \
mostlyclean-tags mostlyclean-depend mostlyclean-generic
mostlyclean: mostlyclean-am
clean-am: clean-noinstLIBRARIES clean-compile clean-tags clean-depend \
clean-generic mostlyclean-am
clean: clean-am
distclean-am: distclean-noinstLIBRARIES distclean-compile \
distclean-tags distclean-depend distclean-generic \
clean-am
distclean: distclean-am
maintainer-clean-am: maintainer-clean-noinstLIBRARIES \
maintainer-clean-compile maintainer-clean-tags \
maintainer-clean-depend maintainer-clean-generic \
distclean-am
@echo "This command is intended for maintainers to use;"
@echo "it deletes files that may require special tools to rebuild."
maintainer-clean: maintainer-clean-am
.PHONY: mostlyclean-noinstLIBRARIES distclean-noinstLIBRARIES \
clean-noinstLIBRARIES maintainer-clean-noinstLIBRARIES \
mostlyclean-compile distclean-compile clean-compile \
maintainer-clean-compile tags mostlyclean-tags distclean-tags \
clean-tags maintainer-clean-tags distdir mostlyclean-depend \
distclean-depend clean-depend maintainer-clean-depend info-am info \
dvi-am dvi check check-am installcheck-am installcheck install-exec-am \
install-exec install-data-am install-data install-am install \
uninstall-am uninstall all-redirect all-am all installdirs \
mostlyclean-generic distclean-generic clean-generic \
maintainer-clean-generic clean mostlyclean distclean maintainer-clean
# Tell versions [3.59,3.63) of GNU make to not export all variables.
# Otherwise a system limit (for SysV at least) may be exceeded.
.NOEXPORT:

5
common/lib/srvcli/TODO Normal file
View File

@@ -0,0 +1,5 @@
CMessage::writeDouble and readDouble has to be rewriten! Loose every
information less then 0.001

View File

@@ -0,0 +1,52 @@
/*
* PVVMUD a 3D MUD
* Copyright (C) 1998-1999 Programvareverkstedet (pvv@pvv.org)
*
* 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.
*
* 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
*
*/
#include "pvvmud.H"
#include "action.H"
CActionList::CActionList():CObjectList(){
currId = 0;
}
CAction * CActionList::getAction(int actionId){
CObjectListItem * item = getFirst();
while (item != NULL){
CAction * action = (CAction*)item->getObject();
if (action->getId() == actionId) return action;
item = item->getNext();
}
return NULL;
}
void CActionList::add(CAction * action){
action->setId(++currId);
CObjectList::addLast(action);
}
CAction::CAction(char * name){
id = 0;
setName(name);
}
void CAction::execute(){
}

68
common/lib/srvcli/bbox.C Normal file
View File

@@ -0,0 +1,68 @@
/*
* PVVMUD a 3D MUD
* Copyright (C) 1998-1999 Programvareverkstedet (pvv@pvv.org)
*
* 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.
*
* 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
*
*/
#include "pvvmud.H"
#include "bbox.H"
CBBox::CBBox(){
// p1 and p2 are initialized to (0,0,0)
}
CBBox::CBBox(double x1,double y1, double z1, double x2, double y2, double z2){
p1 = CPosition(MIN(x1,x2),MIN(y1,y2),MIN(z1,z2));
p2 = CPosition(MAX(x1,x2),MAX(y1,y2),MAX(z1,z2));
}
const CPosition & CBBox::getP1() const{
return p1;
}
const CPosition & CBBox::getP2() const{
return p2;
}
void CBBox::initialize(const CPosition & position){
p1 = p2 = position;
}
void CBBox::include(const CPosition & position){
int ii;
for (ii = 0; ii < 3 ; ii++){
if (position.getValue(ii) < p1.getValue(ii))
p1.setValue(ii,position.getValue(ii));
if (position.getValue(ii) > p2.getValue(ii))
p2.setValue(ii,position.getValue(ii));
}
}
int CBBox::inside(const CPosition & position) const{
return ((position >= p1) && (position <= p2));
}
int CBBox::insideXY(const CVector & position) const{
return ((position.getX() >= p1.getX()) && (position.getX() <= p2.getX()) &&
(position.getY() >= p1.getY()) && (position.getY() <= p2.getY()) );
}
ostream& operator<<(ostream&s,const CBBox& b) {
return s << "[ (" << b.getP1() << ") , (" << b.getP2() << ") ]";
}

100
common/lib/srvcli/bsdtree.C Normal file
View File

@@ -0,0 +1,100 @@
/*
* PVVMUD a 3D MUD
* Copyright (C) 1998-1999 Programvareverkstedet (pvv@pvv.org)
*
* 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.
*
* 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
*
*/
#include "pvvmud.H"
#include <iostream.h>
#include <stdio.h>
#include "bsdtree.H"
CBSDTreeNode::CBSDTreeNode(double a, double b, double c, double d){
this->a = a;
this->b = b;
this->c = c;
this->d = d;
inNode = NULL;
outNode = NULL;
}
int CBSDTreeNode::inside(double x, double y, double z){
if ( (a*x + b*y + c*z + d ) >= 0.0){
if (inNode != NULL) return inNode->inside(x,y,z);
else return TRUE;
} else {
if (outNode != NULL) return outNode->inside(x,y,z);
else return FALSE;
}
}
CBSDTree::CBSDTree(){
BSDTree = NULL;
}
int CBSDTree::load(char * fileName){
FILE * bsdFile;
if ((bsdFile = fopen(fileName,"r")) == NULL){
cdebug << "Failed to open bsdFile " << fileName << "\n";
return FALSE;
}
BSDTree = loadNode(bsdFile);
fclose(bsdFile);
return TRUE;
}
CBSDTreeNode * CBSDTree::loadNode(FILE * bsdFile){
CBSDTreeNode * node;
char nodeType[256];
double a,b,c,d;
if (fscanf(bsdFile,"%s",nodeType) == 1){
if (strcmp(nodeType,"NODE") == 0){
if (fscanf(bsdFile,"%lf %lf %lf %lf",&a,&b,&c,&d) == 4){
node = new CBSDTreeNode(a,b,c,d);
} else {
cdebug << "File format error in BSDTree file:"
<< " Error in parameters to NODE\n";
return NULL;
}
} else if (strcmp(nodeType,"IN") == 0){
return NULL;
} else if (strcmp(nodeType,"OUT") == 0){
return NULL;
} else {
cdebug << "File format error in BSDTree file: Unknown identifyer\n";
return FALSE;
}
node->setInChild( loadNode(bsdFile) );
node->setOutChild( loadNode(bsdFile) );
return node;
}
return NULL;
}
int CBSDTree::inside(double x, double y, double z){
if (BSDTree != NULL) return BSDTree->inside(x,y,z);
else return FALSE;
}
int CBSDTree::inside(const CPosition & position){
return inside(position.getX(),position.getY(),position.getZ());
}

View File

@@ -0,0 +1,220 @@
/*
* PVVMUD a 3D MUD
* Copyright (C) 1998-1999 Programvareverkstedet (pvv@pvv.org)
*
* 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.
*
* 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
*
*/
#include "pvvmud.H"
#include <iostream.h>
#include "communicate.H"
// Debug switches
#define LOGMESSAGES
CBadProtocolException::CBadProtocolException()
:CException("Bad protocol exception"){
}
class CWriteQueueItem: public CObject {
CMessage * m_message;
int m_delete;
public:
CWriteQueueItem(CMessage * message,int del){
m_message = message;
m_delete = del;
}
CMessage * getMessage(){
return m_message;
}
int getDelete(){
return m_delete;
}
};
CCommunicate::CCommunicate(CSocket * socket,CTimeKeeper * timeKeeper){
m_socket = socket;
stream = new CStream(m_socket->getFileDescriptor());
msgWriteQueue = new CObjectQueue();
// Add notification when ready for read or write
m_timeKeeper = timeKeeper;
if (m_timeKeeper != NULL){
m_timeKeeper->addFd(socket->getFileDescriptor(),this,
TIMEKEEPER_IN);
}
currReadMsg = NULL;
currWriteMsg = NULL;
msgList = new CMessageList();
}
CCommunicate::~CCommunicate(){
if (m_timeKeeper != NULL) m_timeKeeper->rmFd(m_socket->getFileDescriptor());
if (stream != NULL) delete stream;
if (m_socket != NULL) delete m_socket;
if (msgList != NULL){
msgList->deleteAll();
delete msgList;
}
}
CSocket * CCommunicate::getSocket(){
return m_socket;
}
void CCommunicate::quit(){
cdebug << "Quit communicate not impl.\n";
}
int CCommunicate::timeKeeperFD(int event){
try {
if (event & TIMEKEEPER_IN) readyToRead();
if (event & TIMEKEEPER_OUT) readyToWrite();
return TRUE;
} catch (CEmptyStreamException * e){
quit();
delete e;
return FALSE;
} catch (CException * e){
cdebug << *e << "\n";
quit();
delete e;
return FALSE;
}
}
void CCommunicate::readyToRead(){
int blocking = TRUE;
do {
if (currReadMsg == NULL){
try {
int id = stream->peepByte();
if ((currReadMsg = msgList->createMsg(id)) == NULL){
cdebug << "Unknown message id : " << id << "\n";
throw new CBadProtocolException();
}
currReadMsg->setManager(getManager());
} catch (CEmptyStreamException * e){
cdebug << *e << "\n";
delete e;
return;
}
}
int result = currReadMsg->recive(stream);
switch (result){
case MESSAGE_OK:
#ifdef LOGMESSAGES
cdebug << "Recive(\""<< getName() << "\"): "
<< currReadMsg->getName() << "\n";
#endif
currReadMsg->executeMsg();
delete currReadMsg;
currReadMsg = NULL;
blocking = FALSE;
break;
case MESSAGE_BLOCKING:
blocking = TRUE;
break;
}
} while (!blocking); // Quit if blocking
}
void CCommunicate::readyToWrite(){
int blocking = TRUE;
do {
// If no message in progres get message from queue
if (currWriteMsg == NULL){
CWriteQueueItem * queueItem = (CWriteQueueItem*)msgWriteQueue->getFIFO();
// Return if queue is empty
if (queueItem == NULL){
timeKeeperSetEvents(TIMEKEEPER_IN);
return;
}
currWriteMsg = queueItem->getMessage();
currWriteMsg->prepareSend();
currWriteDelete = queueItem->getDelete();
delete queueItem;
}
int result = currWriteMsg->send(stream);
switch (result){
case MESSAGE_OK:
#ifdef LOGMESSAGES
cdebug << "Send(\""<< getName() << "\"): "
<< currWriteMsg->getName() << "\n";
#endif
if (currWriteDelete) delete currWriteMsg;
currWriteMsg = NULL;
blocking = FALSE;
break;
case MESSAGE_BLOCKING:
timeKeeperSetEvents(TIMEKEEPER_IN | TIMEKEEPER_OUT);
blocking = TRUE;
break;
}
} while (!blocking); // Quit if blocking
}
void CCommunicate::sendMessage(CMessage * message,int del){
// cdebug << "Add to queue : " << message->getName()
// << " queue size " << msgWriteQueue->getNumItems() << "\n";
// Add message to write queue
msgWriteQueue->add(new CWriteQueueItem(message,del));
// Try to send new message
try {
readyToWrite();
} catch (CException * e){
cdebug << *e << "\n";
quit();
delete e;
}
}
void CCommunicate::setManager(CManager * manager){
this->manager = manager;
}
CManager * CCommunicate::getManager(){
return manager;
}
void CCommunicate::addMsg(MsgCreateFunc_t msgCreateFunc){
msgList->addMsg(msgCreateFunc);
}

View File

@@ -0,0 +1,133 @@
/*
* PVVMUD a 3D MUD
* Copyright (C) 1998-1999 Programvareverkstedet (pvv@pvv.org)
*
* 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.
*
* 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
*
*/
#include <math.h>
#include "pvvmud.H"
#include "direction.H"
#define NORMALIZE(index) \
direction[index] -= floor(direction[index]/360.0) * 360.0;
CDirection::CDirection(){
direction[0] = 0;
direction[1] = 0;
direction[2] = 0;
}
CDirection::CDirection(double * direction){
this->direction[0] = direction[0];
this->direction[1] = direction[1];
this->direction[2] = direction[2];
normalize();
}
CDirection::CDirection(double h, double r, double p){
direction[0] = h;
direction[1] = r;
direction[2] = p;
normalize();
}
CDirection& CDirection::operator= (const CDirection& direction) {
this->direction[0] = direction.direction[0];
this->direction[1] = direction.direction[1];
this->direction[2] = direction.direction[2];
return *this;
}
CDirection& CDirection::operator+= (const CDirection& direction) {
this->direction[0] += direction.direction[0];
this->direction[1] += direction.direction[1];
this->direction[2] += direction.direction[2];
normalize();
return *this;
}
CDirection CDirection::operator+ (const CDirection& direction) {
CDirection result;
result.direction[0] = this->direction[0] + direction.direction[0];
result.direction[1] = this->direction[1] + direction.direction[1];
result.direction[2] = this->direction[2] + direction.direction[2];
result.normalize();
return result;
}
CDirection CDirection::operator- () const {
CDirection result;
result.direction[0] = -direction[0];
result.direction[1] = -direction[1];
result.direction[2] = -direction[2];
result.normalize();
return result;
}
CDirection CDirection::operator* (double scale) const {
CDirection result;
result.direction[0] = direction[0]*scale;
result.direction[1] = direction[1]*scale;
result.direction[2] = direction[2]*scale;
result.normalize();
return result;
}
void CDirection::normalize(){
NORMALIZE(0);
NORMALIZE(1);
NORMALIZE(2);
}
double * CDirection::getVector(){
return direction;
}
double CDirection::getValue(int ii) const {
return direction[ii];
}
void CDirection::setValue(int ii,double value) {
direction[ii] += value;
NORMALIZE(ii);
}
double CDirection::rotateHeading(double deltaHeading){
direction[0] += deltaHeading;
NORMALIZE(0);
return direction[0];
}
double CDirection::rotateRoll(double deltaRoll){
direction[1] += deltaRoll;
NORMALIZE(1);
return direction[1];
}
double CDirection::rotatePitch(double deltaPitch){
direction[2] += deltaPitch;
NORMALIZE(2);
return direction[2];
}
ostream& operator<<(ostream&s,const CDirection& d){
return s << "(" << d.getHeading() << "," << d.getRoll()
<< "," << d.getPitch() << ")";
}

View File

@@ -0,0 +1,34 @@
/*
* PVVMUD a 3D MUD
* Copyright (C) 1998-1999 Programvareverkstedet (pvv@pvv.org)
*
* 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.
*
* 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
*
*/
#include "pvvmud.H"
#include "exception.H"
CException::CException(){
setName("Unknown exception");
}
CException::CException(char * message){
setName(message);
}
ostream& operator<<(ostream&s,CException& e){
return s << e.getName();
}

View File

@@ -0,0 +1,142 @@
/*
* PVVMUD a 3D MUD
* Copyright (C) 1998-1999 Programvareverkstedet (pvv@pvv.org)
*
* 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.
*
* 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
*
*/
#include "pvvmud.H"
#include <string.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <netdb.h>
#include <stdio.h>
#include <iostream.h>
#include "inetaddress.H"
#ifndef INADDR_NONE
#define INADDR_NONE -1
#endif
CUnknownHostException::CUnknownHostException()
:CException("Unknown host exception"){
}
CInetAddress::CInetAddress(){
setAddress(INADDR_NONE,0);
}
CInetAddress::CInetAddress(DWORD address){
setAddress(address,0);
}
CInetAddress::CInetAddress(DWORD address,WORD port){
setAddress(address,port);
}
CInetAddress::CInetAddress(char * hostName, WORD port){
struct hostent * hent;
char *portString;
portString=strchr(hostName,':');
if (portString) {
port=atoi(portString+1);
portString[0]=0;
// printf("%s , %s\n",hostName,portString+1);
cdebug << hostName << " , " << (portString+1) << "\n";
};
if (hostName) {
if (!strcmp("localhost",hostName)) {
// printf("Connecting to localhost, port : %i",port);
cdebug << "Connecting to localhost, port : " << port << "\n";
if (portString) portString[0]=':';
setAddress(INADDR_LOOPBACK,port);
return;
}
}
if ((hent = gethostbyname(hostName)) == NULL){
throw new CUnknownHostException();
}
if (portString) {
portString[0]=':';
}
//printf("Connecting to another server, port : %i",port);
cdebug << "Connecting to another server, port : " << port << "\n";
setAddress(htonl(*((DWORD*)hent->h_addr)),port);
}
CInetAddress::CInetAddress(char * hostName){
struct hostent * hent;
char *portString;
WORD port=0;
portString=strchr(hostName,':');
if (portString) {
port=atoi(portString+1);
};
if ((hent = gethostbyname(hostName)) == NULL){
throw new CUnknownHostException();
}
setAddress(htonl(*((DWORD*)hent->h_addr)),port);
}
void CInetAddress::setAddress(DWORD address,WORD port){
m_address = address;
m_port = port;
}
char * CInetAddress::getHostName(){
struct hostent * hent;
DWORD address;
address=htonl(m_address);
if ((hent = gethostbyaddr((char*)&address, sizeof m_address, AF_INET)) == NULL){
throw new CUnknownHostException();
}
return hent->h_name;
}
char * CInetAddress::getAddressString(){
static char addr[1024];
try {
sprintf(addr,"%s:%d",getHostName(),getPort());
} catch (CException * e){
cdebug << *e << "\n";
delete e;
DWORD naddr = htonl(getAddress());
struct in_addr * inaddr = (struct in_addr*)&naddr;
sprintf(addr,"%s:%d",inet_ntoa(*inaddr),getPort());
}
return addr;
}
ostream& operator<<(ostream&s,const CInetAddress& address){
return s << ((CInetAddress)address).getAddressString();
}

View File

@@ -0,0 +1,41 @@
/*
* PVVMUD a 3D MUD
* Copyright (C) 1998-1999 Programvareverkstedet (pvv@pvv.org)
*
* 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.
*
* 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
*
*/
#include "pvvmud.H"
#include <iostream.h>
#include "manager.H"
#include "communicate.H"
CManager::CManager(){
m_communicate = NULL;
}
CManager::CManager(CCommunicate * communicate){
setCommunicate(communicate);
}
CManager::~CManager(){
if (m_communicate != NULL) delete m_communicate;
}
void CManager::setCommunicate(CCommunicate * communicate){
m_communicate = communicate;
communicate->setManager(this);
}

234
common/lib/srvcli/message.C Normal file
View File

@@ -0,0 +1,234 @@
/*
* PVVMUD a 3D MUD
* Copyright (C) 1998-1999 Programvareverkstedet (pvv@pvv.org)
*
* 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.
*
* 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
*
*/
#include "pvvmud.H"
#include <stdlib.h>
#include <stdio.h>
#include <iostream.h>
#include "message.H"
#define WORD_MS_BYTE(w) (BYTE)( w >> 8 )
#define WORD_LS_BYTE(w) (BYTE)( w & 0xFF )
#define DWORD_MS_WORD(w) (WORD)( w >> 16 )
#define DWORD_LS_WORD(w) (WORD)( w & 0xFFFF )
#define WORD_FROM_BYTE(ms,ls) (WORD)( (WORD)ms << 8 | (WORD)ls)
#define DWORD_FROM_WORD(ms,ls) (DWORD)( (DWORD)ms << 16 | (DWORD)ls)
/******************************************************************************
*
* CMessage
*
******************************************************************************/
CMessage::CMessage(BYTE id, long length){
this->length = length+1;
message = (BYTE*)malloc(this->length);
msglength = this->length;
writeByte(0,id);
writeIndex = 0;
readIndex = 0;
}
CMessage::~CMessage(){
if (message != NULL) free(message);
}
void CMessage::reallocMessage(long size){
message = (BYTE*)realloc(message,length+size);
msglength = length+size;
}
BYTE CMessage::getId(){
return readByte(0);
}
long CMessage::getLength(){
return length;
}
CMessage * CMessage::createMsg(){
return (CMessage*)NULL;
}
int CMessage::reciveHead(CStream * stream){
return FALSE;
}
int CMessage::send(CStream * stream){
if (readIndex >= length){
return MESSAGE_OK;
}
long num = stream->writeBuf(&message[readIndex],length-readIndex);
if (num == -1) return MESSAGE_BLOCKING;
readIndex += num;
if (readIndex == length) return MESSAGE_OK;
return MESSAGE_BLOCKING;
}
int CMessage::recive(CStream * stream){
if (writeIndex >= length){
return MESSAGE_OK;
}
long num = stream->readBuf(&message[writeIndex],length-writeIndex);
if (num == -1) return MESSAGE_BLOCKING;
writeIndex += num;
if (writeIndex == length) return MESSAGE_OK;
return MESSAGE_BLOCKING;
}
int CMessage::reciveMessage(CStream * stream,long index,long size){
long num = stream->readBuf(&message[index],size);
if (num == -1) return MESSAGE_BLOCKING;
writeIndex += num;
if (num == size) return MESSAGE_OK;
return MESSAGE_BLOCKING;
}
int CMessage::sendMessage(CStream * stream,long index,long size){
long num = stream->writeBuf(&message[index],size);
if (num == -1) return MESSAGE_BLOCKING;
readIndex += num;
if (num == size) return MESSAGE_OK;
return MESSAGE_BLOCKING;
}
long CMessage::getWriteIndex(){
return writeIndex;
}
long CMessage::getReadIndex(){
return readIndex;
}
void CMessage::writeByte(long index,BYTE byte){
if (index < 0) index = currpos;
if ((index > msglength) || (index < 0) || (message == NULL)) throw new CException("Message write index out of range exception");
message[index] = byte;
currpos = index + 1;
}
void CMessage::writeWord(long index,WORD word){
writeByte(index,WORD_MS_BYTE(word));
writeByte(index+1,WORD_LS_BYTE(word));
}
void CMessage::writeDWord(long index,DWORD dword){
writeWord(index,DWORD_MS_WORD(dword));
writeWord(index+2,DWORD_LS_WORD(dword));
}
void CMessage::writeDouble(long index,double value){
long longval = (long)(value*1000.0);
writeDWord(index,(DWORD)longval);
}
void CMessage::writeBuf(long index,BYTE * buf,long size){
long ii;
for (ii = 0; ii < size; ii++){
writeByte(index+ii,buf[ii]);
}
}
void CMessage::writeString(long index,char * str){
writeBuf(index,(BYTE*)str,strlen(str)+1);
}
void CMessage::writePosition(long index,const CPosition& position){
for (long ii = 0; ii < 3; ii++){
writeDouble(index+ii*4,position.getValue(ii));
}
}
void CMessage::writeDirection(long index,const CDirection& direction){
for (long ii = 0; ii < 3; ii++){
writeDouble(index+ii*4,direction.getValue(ii));
}
}
BYTE CMessage::readByte(long index){
if (index < 0) index = currpos;
if ((index > msglength) || (index < 0) || (message == NULL)) {
char msg[1024];
sprintf(msg,"Message read index %li out of range %li exception"
,index,msglength);
throw new CException(msg);
}
currpos = index + 1;
return message[index];
}
WORD CMessage::readWord(long index){
return WORD_FROM_BYTE(readByte(index),readByte(index+1));
}
DWORD CMessage::readDWord(long index){
return DWORD_FROM_WORD(readWord(index),readWord(index+2));
}
double CMessage::readDouble(long index){
long longval;
longval = (long)DWORD_FROM_WORD(readWord(index),readWord(index+2));
return (double)longval / 1000.0;
}
void CMessage::readBuf(long index,BYTE * buf,long size){
long ii;
if (buf == NULL) throw new CException("Message buffer null exception");
for (ii = 0; ii < size; ii++){
buf[ii] = readByte(index+ii);
}
}
char * CMessage::readString(long index){
if (index < 0) index = currpos;
if ((index > msglength) || (index < 0) || (message == NULL)) throw new CException("Message readString index out of range exception");
long ii,size=0;
char * str;
// Find string size
while (((index+size) < msglength) && (readByte(index+size++) != '\0'));
// Malloc and copy string
str = (char*)malloc(size);
if (str == NULL) throw new CException("Out of memory exception");
for (ii = 0; ii < size; ii++) str[ii] = readByte(index+ii);
return str;
}
CPosition CMessage::readPosition(long index){
CPosition position;
for (long ii = 0; ii < 3; ii++){
position.setValue(ii,readDouble(index+ii*4));
}
return position;
}
CDirection CMessage::readDirection(long index){
CDirection direction;
for (long ii = 0; ii < 3; ii++){
direction.setValue(ii,readDouble(index+ii*4));
}
return direction;
}

View File

@@ -0,0 +1,64 @@
/*
* PVVMUD a 3D MUD
* Copyright (C) 1998-1999 Programvareverkstedet (pvv@pvv.org)
*
* 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.
*
* 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
*
*/
#include "pvvmud.H"
#include <iostream.h>
#include "messagelist.H"
CMessageItem::CMessageItem(BYTE id, int length, MsgCreateFunc_t msgCreateFunc){
this->id = id;
this->length = length;
this->msgCreateFunc = msgCreateFunc;
}
CMessageItem * CMessageList::getItem(BYTE id){
CObjectListItem * curr;
CMessageItem * msgItem;
curr = getFirst();
while (curr != NULL){
msgItem = (CMessageItem*)curr->getObject();
if (msgItem->id == id) return msgItem;
curr = curr->getNext();
}
return NULL;
}
void CMessageList::addMsg(MsgCreateFunc_t msgCreateFunc){
CMessage * msg = msgCreateFunc();
// cdebug << "Msg: id " << (int)msg->getId() << " length "
// << msg->getLength() << "\n";
addLast( new CMessageItem(msg->getId(),msg->getLength(),msgCreateFunc));
delete msg;
}
int CMessageList::getLength(BYTE id){
CMessageItem * msgItem;
msgItem = getItem(id);
if (msgItem != NULL) return msgItem->length;
return -1;
}
CMessage * CMessageList::createMsg(BYTE id){
CMessageItem * msgItem;
msgItem = getItem(id);
if (msgItem != NULL) return msgItem->msgCreateFunc();
return NULL;
}

67
common/lib/srvcli/mkmsgvar.pl Executable file
View File

@@ -0,0 +1,67 @@
#!/usr/bin/perl
foreach $name (@ARGV) {
$ucname = ucfirst $name;
$classname = "C$ucname";
$filename = lc $name;
$NAME = uc $name;
print "Creating H file $filename.H for class $classname\n";
open(file, "> ../../include/$filename.H") or die "Can't open $filename.H\n";
print file "#ifndef _", $NAME,"_H\n";
print file "#define _", $NAME,"_H\n";
print file "\n";
print file "#include \"msgvarlength.H\"\n";
print file "\n";
print file "class $classname : public CMsgVarLength \{\n";
print file "\n";
print file " arg\n";
print file "\n";
print file "public:\n";
print file " $classname();\n";
print file " $classname( arg );\n";
print file " ~$classname();\n";
print file " virtual void send(CStream * stream);\n";
print file " virtual void recive(CStream * stream);\n";
print file " getArg() { return arg; }\n";
print file "}\;\n";
print file "\n";
print file "#endif // _",$NAME,"_H\n";
close(file);
print "Creating C file $filename.C for class $classname\n";
open(file, "> $filename.C") or die "Can't open $filename.C\n";
print file "#include \"pvvmud.H\"\n";
print file "#include \"$filename.H\"\n";
print file "\n";
print file "$classname","::","$classname","():CMsgVarLength('?'){\n";
print file "\n";
print file "}\n";
print file "\n";
print file "$classname","::","$classname","( arg ):CMsgVarLength('?'){\n";
print file " setBodyLength( ? );\n";
print file "}\n";
print file "\n";
print file "$classname","::~","$classname","(){\n";
print file "\n";
print file "}\n";
print file "\n";
print file "void $classname","::recive(CStream * stream){\n";
print file "}\n";
print file "\n";
print file "void $classname","::send(CStream * stream){\n";
print file " CMsgVarLength::send(stream);\n";
print file "}\n";
print file "\n";
close(file);
}

View File

@@ -0,0 +1,68 @@
/*
* PVVMUD a 3D MUD
* Copyright (C) 1998-1999 Programvareverkstedet (pvv@pvv.org)
*
* 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.
*
* 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
*
*/
#include "pvvmud.H"
#include "msgactionlist.H"
CMsgActionList::CMsgActionList():CMsgVarLength(MSG_ACTIONLIST){
setName("MsgActionList");
setBodyLength( sizeof(WORD)*2 );
writeWord(getLength(),0); // ObjectId
setNumActions(0); // NumActions
}
CMsgActionList::CMsgActionList(WORD objectId):CMsgVarLength(MSG_ACTIONLIST){
setName("MsgActionList");
setBodyLength( sizeof(WORD)*2 );
writeWord(getLength(),objectId);
setNumActions(0); // NumActions
}
void CMsgActionList::setNumActions(int num){
writeWord(getLength()+2,num);
}
int CMsgActionList::getNumActions(){
return readWord(getLength()+2);
}
CObjectList* CMsgActionList::getActionList(){
CObjectList * actionList = new CObjectList();
WORD numActions = getNumActions();
while (numActions--){
int id = readWord(MSGCURRPOS);
CAction * action = new CAction(readString(MSGCURRPOS));
action->setId(id);
actionList->addLast( (CObject*)action );
}
return actionList;
}
void CMsgActionList::addAction(CAction * action){
int endpos = getBodyLength();
setBodyLength(endpos + sizeof(WORD) + strlen(action->getName())+1);
endpos += getLength();
writeWord(endpos,action->getId()); endpos +=2;
writeString(endpos,action->getName());
setNumActions(getNumActions()+1);
}
WORD CMsgActionList::getObjectId(){
return readWord(getLength());
}

View File

@@ -0,0 +1,46 @@
/*
* PVVMUD a 3D MUD
* Copyright (C) 1998-1999 Programvareverkstedet (pvv@pvv.org)
*
* 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.
*
* 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
*
*/
#include "pvvmud.H"
#include <string.h>
#include "msgmsg.H"
CMsgMsg::CMsgMsg():CMsgVarLength(MSG_MSG){
setName("MsgMsg");
}
CMsgMsg::CMsgMsg( const char * msg ):CMsgVarLength(MSG_MSG){
setName("MsgMsg");
setBodyLength( strlen(msg) );
writeBuf(getLength(),(BYTE*)msg,strlen(msg));
}
CMsgMsg::~CMsgMsg(){
}
int CMsgMsg::getMsgLength(){
return getBodyLength() + 1;
}
void CMsgMsg::getMsg(char * msg){
readBuf(getLength(),(BYTE*)msg,getBodyLength());
msg[getBodyLength()] = '\0';
}

View File

@@ -0,0 +1,36 @@
/*
* PVVMUD a 3D MUD
* Copyright (C) 1998-1999 Programvareverkstedet (pvv@pvv.org)
*
* 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.
*
* 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
*
*/
#include "pvvmud.H"
#include "msgserver.H"
CMsgServerLogin::CMsgServerLogin():CMessage(MSG_SERVERLOGIN,sizeof(DWORD)+sizeof(WORD)){
setName("ServerLogin");
}
CMsgServerLogin::CMsgServerLogin(CInetAddress & serverAddress):CMessage(MSG_SERVERLOGIN,sizeof(DWORD)+sizeof(WORD)){
setName("ServerLogin");
writeDWord(1,serverAddress.getAddress());
writeWord(5,serverAddress.getPort());
}
CInetAddress * CMsgServerLogin::getAddress(){
return new CInetAddress(readDWord(1),readWord(5));
}

View File

@@ -0,0 +1,350 @@
/*
* PVVMUD a 3D MUD
* Copyright (C) 1998-1999 Programvareverkstedet (pvv@pvv.org)
*
* 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.
*
* 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
*
*/
#include "pvvmud.H"
#include <unistd.h>
#include <string.h>
#include <stdio.h>
#include <math.h>
#include "msgsrvcli.H"
/******************************************************************************
*
* CMsgHello
*
******************************************************************************/
CMsgHello::CMsgHello():CMessage(MSG_HELLO,sizeof(WORD)){
setName("MsgHello");
}
CMsgHello::CMsgHello(WORD version):CMessage(MSG_HELLO,sizeof(WORD)){
setName("MsgHello");
writeWord(1,version);
}
WORD CMsgHello::getVersion(){
return readWord(1);
}
/******************************************************************************
*
* CMsgLogin
*
******************************************************************************/
#define MSGLOGINSIZE LOGINNAMELENGTH+LOGINPASSWDLENGTH+sizeof(BYTE)
CMsgLogin::CMsgLogin():CMessage(MSG_LOGIN,MSGLOGINSIZE){
setName("MsgLogin");
}
CMsgLogin::CMsgLogin(char * name, char * passwd, BOOL newUser)
:CMessage(MSG_LOGIN,MSGLOGINSIZE)
{
setName("MsgLogin");
if ((strlen(name) > LOGINNAMELENGTH) || (strlen(passwd) > LOGINPASSWDLENGTH))
throw new CException();
writeString(1,name);
writeString(1+LOGINNAMELENGTH,passwd);
writeByte(1+LOGINNAMELENGTH+LOGINPASSWDLENGTH,newUser);
}
char * CMsgLogin::getUserName(){
return readString(1);
}
char * CMsgLogin::getPasswd(){
return readString(1+LOGINNAMELENGTH);
}
BOOL CMsgLogin::getNewUser(){
return readByte(1+LOGINNAMELENGTH+LOGINPASSWDLENGTH);
}
/******************************************************************************
*
* CMsgServerInfo
*
******************************************************************************/
CMsgServerInfo::CMsgServerInfo()
:CMessage(MSG_SERVERINFO,2*sizeof(DWORD)+2*sizeof(WORD)){
setName("MsgServerInfo");
}
CMsgServerInfo::CMsgServerInfo(CInetAddress & worldSrvAddress,
CInetAddress & gosAddress)
:CMessage(MSG_SERVERINFO,2*sizeof(DWORD)+2*sizeof(WORD)){
setName("MsgServerInfo");
writeDWord(1,worldSrvAddress.getAddress());
writeWord(5,worldSrvAddress.getPort());
writeDWord(7,gosAddress.getAddress());
writeWord(11,gosAddress.getPort());
}
CInetAddress * CMsgServerInfo::getWorldSrvAddress(){
return new CInetAddress(readDWord(1),readWord(5));
}
CInetAddress * CMsgServerInfo::getGOSAddress(){
return new CInetAddress(readDWord(7),readWord(11));
}
/******************************************************************************
*
* CMsgGOSInfo
*
******************************************************************************/
CMsgGOSInfo::CMsgGOSInfo()
:CMessage(MSG_GOSINFO,sizeof(DWORD)+sizeof(WORD)){
setName("MsgGOSInfo");
}
CMsgGOSInfo::CMsgGOSInfo(CInetAddress & gosAddress)
:CMessage(MSG_GOSINFO,sizeof(DWORD)+sizeof(WORD)){
setName("MsgGOSInfo");
writeDWord(1,gosAddress.getAddress());
writeWord(5,gosAddress.getPort());
}
CInetAddress * CMsgGOSInfo::getGOSAddress(){
return new CInetAddress(readDWord(1),readWord(5));
}
/******************************************************************************
*
* CMsgBye
*
******************************************************************************/
CMsgBye::CMsgBye():CMessage(MSG_BYE,sizeof(WORD)){
setName("MsgBye");
}
CMsgBye::CMsgBye(WORD reason):CMessage(MSG_BYE,sizeof(WORD)){
setName("MsgBye");
writeWord(1,reason);
}
WORD CMsgBye::getReason(){
return readWord(1);
}
char * CMsgBye::getReasonString(WORD reason){
switch (reason){
case MSGBYE_QUIT:
return "Quit";
case MSGBYE_BADPROTOCOL:
return "Error in protocol";
case MSGBYE_UNKNOWN:
default:
return "Unkown";
}
}
/******************************************************************************
*
* CMsgGetWorld
*
******************************************************************************/
CMsgGetWorld::CMsgGetWorld():CMessage(MSG_GETWORLD,0){
setName("MsgGetWorld");
}
/******************************************************************************
*
* CMsgCommand
*
******************************************************************************/
CMsgCommand::CMsgCommand():CMessage(MSG_COMMAND,sizeof(WORD)){
setName("MsgCommand");
}
CMsgCommand::CMsgCommand(WORD command):CMessage(MSG_COMMAND,sizeof(WORD)){
setName("MsgCommand");
writeWord(1,command);
}
WORD CMsgCommand::getCommand(){
return readWord(1);
}
/******************************************************************************
*
* CMsgViewpoint
*
******************************************************************************/
CMsgViewpoint::CMsgViewpoint():CMessage(MSG_VIEWPOINT, sizeof(DWORD)*7){
setName("MsgViewpoint");
}
CMsgViewpoint::CMsgViewpoint(CViewpoint & viewpoint)
:CMessage(MSG_VIEWPOINT, sizeof(DWORD)*7){
setName("MsgViewpoint");
double *position = viewpoint.getPosition().getVector();
double *direction = viewpoint.getDirection().getVector();
for (int ii = 0; ii < 3 ; ii++){
writeDouble(1 + ii*8, position[ii] );
writeDouble(1 + ii*8+4, direction[ii] );
}
writeDWord(25,viewpoint.getTargetId());
}
void CMsgViewpoint::getPosition(CPosition & position){
double pos[3];
for (int ii = 0; ii < 3 ; ii++){
pos[ii] = readDouble(1+ii*8);
}
position = CPosition(pos);
}
void CMsgViewpoint::getDirection(CDirection & direction){
double dir[3];
for (int ii = 0; ii < 3 ; ii++){
dir[ii] = readDouble(1+ii*8+4);
}
direction = CDirection(dir);
}
DWORD CMsgViewpoint::getTargetId(){
return readDWord(25);
}
/******************************************************************************
*
* CMsgSelection
*
******************************************************************************/
CMsgSelection::CMsgSelection():CMessage(MSG_SELECTION,sizeof(WORD)){
setName("MsgSelection");
}
CMsgSelection::CMsgSelection(WORD objectId):CMessage(MSG_SELECTION,sizeof(WORD)){
setName("MsgSelection");
writeWord(1,objectId);
}
WORD CMsgSelection::getObjectId(){
return readWord(1);
}
/******************************************************************************
*
* CMsgAction
*
******************************************************************************/
CMsgAction::CMsgAction():CMessage(MSG_ACTION,sizeof(WORD)*2){
setName("MsgAction");
}
CMsgAction::CMsgAction(WORD objectId, WORD actionId):CMessage(MSG_ACTION,sizeof(WORD)*2){
setName("MsgAction");
writeWord(1,objectId);
writeWord(3,actionId);
}
WORD CMsgAction::getObjectId(){
return readWord(1);
}
WORD CMsgAction::getActionId(){
return readWord(3);
}
/******************************************************************************
*
* CMsgPlayerInfo
*
******************************************************************************/
CMsgPlayerInfo::CMsgPlayerInfo():CMessage(MSG_PLAYERINFO,sizeof(DWORD)){
setName("MsgPlayerInfo");
}
CMsgPlayerInfo::CMsgPlayerInfo(DWORD masterCellId):CMessage(MSG_PLAYERINFO,sizeof(DWORD)){
setName("MsgPlayerInfo");
writeDWord(1,masterCellId);
}
DWORD CMsgPlayerInfo::getMasterCellId(){
return readDWord(1);
}
/******************************************************************************
*
* CMsgPing
*
******************************************************************************/
CMsgPing::CMsgPing():CMessage(MSG_PING,sizeof(BYTE)){
setName("MsgPing");
}
CMsgPing::CMsgPing(BYTE sequenceNumber):CMessage(MSG_PING,sizeof(BYTE)){
setName("MsgPing");
writeByte(1,sequenceNumber);
}
BYTE CMsgPing::getSequenceNumber(){
return readByte(1);
}
/******************************************************************************
*
* CMsgPong
*
******************************************************************************/
CMsgPong::CMsgPong():CMessage(MSG_PONG,sizeof(BYTE)+sizeof(DWORD)){
setName("MsgPong");
}
CMsgPong::CMsgPong(BYTE sequenceNumber,DWORD serverTime):CMessage(MSG_PONG,sizeof(BYTE)+sizeof(DWORD)){
setName("MsgPong");
writeByte(1,sequenceNumber);
writeDWord(2,serverTime);
}
BYTE CMsgPong::getSequenceNumber(){
return readByte(1);
}
DWORD CMsgPong::getServerTime(){
return readDWord(2);
}

View File

@@ -0,0 +1,23 @@
/*
* PVVMUD a 3D MUD
* Copyright (C) 1998-1999 Programvareverkstedet (pvv@pvv.org)
*
* 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.
*
* 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
*
*/
#include "pvvmud.H"
#include "msgsrvgos.H"

View File

@@ -0,0 +1,65 @@
/*
* PVVMUD a 3D MUD
* Copyright (C) 1998-1999 Programvareverkstedet (pvv@pvv.org)
*
* 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.
*
* 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
*
*/
#include "pvvmud.H"
#include "msgvarlength.H"
CMsgVarLength::CMsgVarLength(BYTE id):CMessage(id,sizeof(DWORD)){
writeDWord(1,0);
}
long CMsgVarLength::getBodyLength(){
DWORD bodyLength = readDWord(1);
reallocMessage(bodyLength);
return (long)bodyLength;
}
void CMsgVarLength::setBodyLength(DWORD bodyLength){
reallocMessage(bodyLength);
writeDWord(1,bodyLength);
}
int CMsgVarLength::sendBody(CStream * stream){
long length = getBodyLength()-(getReadIndex()-getLength());
if (length == 0) return MESSAGE_OK;
return sendMessage(stream,getReadIndex(),length);
}
int CMsgVarLength::reciveBody(CStream * stream){
long length = getBodyLength()-(getWriteIndex()-getLength());
if (length == 0) return MESSAGE_OK;
return reciveMessage(stream,getWriteIndex(),length);
}
int CMsgVarLength::recive(CStream * stream){
if ( (CMessage::recive(stream)==MESSAGE_OK) &&
(reciveBody(stream)==MESSAGE_OK) ){
return MESSAGE_OK;
}
return MESSAGE_BLOCKING;
}
int CMsgVarLength::send(CStream * stream){
if ( (CMessage::send(stream)==MESSAGE_OK) &&
(sendBody(stream)==MESSAGE_OK) ){
return MESSAGE_OK;
}
return MESSAGE_BLOCKING;
}

View File

@@ -0,0 +1,39 @@
/*
* PVVMUD a 3D MUD
* Copyright (C) 1998-1999 Programvareverkstedet (pvv@pvv.org)
*
* 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.
*
* 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
*
*/
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include "pvvmud.H"
#include "object.H"
CObject::CObject(){
m_name = NULL;
}
CObject::~CObject(){
if (m_name != NULL) free(m_name);
}
void CObject::setName(char * name){
int length = strlen(name);
if (m_name != NULL) free(m_name);
m_name = (char*)malloc(length+1);
strcpy(m_name,name);
}

View File

@@ -0,0 +1,204 @@
/*
* PVVMUD a 3D MUD
* Copyright (C) 1998-1999 Programvareverkstedet (pvv@pvv.org)
*
* 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.
*
* 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
*
*/
#include <stdio.h>
#include "pvvmud.H"
#include "objectlist.H"
CObjectListItem::CObjectListItem(){
m_next = NULL;
m_prev = NULL;
m_object = NULL;
}
CObjectListItem::CObjectListItem(CObject * object){
m_next = NULL;
m_prev = NULL;
m_object = object;
}
void CObjectListItem::setObject(CObject * object){
m_object = object;
}
CObject * CObjectListItem::getObject(){
return m_object;
}
void CObjectListItem::setNext(CObjectListItem * next){
m_next = next;
}
CObjectListItem * CObjectListItem::getNext(){
return m_next;
}
void CObjectListItem::setPrev(CObjectListItem * prev){
m_prev = prev;
}
CObjectListItem * CObjectListItem::getPrev(){
return m_prev;
}
CObjectList::CObjectList(){
m_first = NULL;
m_last = NULL;
}
CObjectList::~CObjectList(){
deleteList();
}
void CObjectList::deleteList(){
CObjectListItem *item;
while ((item = removeFirst()) != NULL){
delete item;
}
}
void CObjectList::deleteAll(){
CObjectListItem *item;
while ((item = removeFirst()) != NULL){
CObject * object = item->getObject();
delete object;
delete item;
}
}
CObjectListItem * CObjectList::addFirst(CObject * obj){
CObjectListItem * item = new CObjectListItem(obj);
if (m_first != NULL){
item->setNext(m_first);
m_first->setPrev(item);
m_first = item;
} else {
m_first = m_last = item;
}
return item;
}
CObjectListItem * CObjectList::addLast(CObject * obj){
CObjectListItem * item = new CObjectListItem(obj);
if (m_last != NULL){
m_last->setNext(item);
item->setPrev(m_last);
m_last = item;
} else {
m_first = m_last = item;
}
return item;
}
CObjectListItem * CObjectList::removeFirst(){
if (m_first == NULL) return NULL;
CObjectListItem *item = m_first;
m_first = m_first->getNext();
if (m_first != NULL){
m_first->setPrev(NULL);
} else {
m_last = NULL;
}
if (item != NULL){
item->setNext(NULL);
item->setPrev(NULL);
}
return item;
}
CObjectListItem * CObjectList::removeLast(){
if (m_last == NULL) return NULL;
CObjectListItem *item = m_last;
m_last = m_last->getPrev();
if (m_last != NULL){
m_last->setNext(NULL);
} else {
m_first = NULL;
}
if (item != NULL){
item->setNext(NULL);
item->setPrev(NULL);
}
return item;
}
void CObjectList::remove(CObject * obj){
CObjectListItem *curr,*next,*prev;
curr = m_first;
prev = NULL;
while (curr != NULL){
next = curr->getNext();
if ( obj == curr->getObject()){
if (prev != NULL){
prev->setNext(next);
} else {
m_first = next;
}
if (next != NULL){
next->setPrev(prev);
} else {
m_last = prev;
}
delete curr;
return;
}
prev = curr;
curr = next;
}
}
CObjectListItem * CObjectList::getFirst(){
return m_first;
}
CObjectListItem * CObjectList::getLast(){
return m_last;
}
//CObjectListItem * CObjectList::getNext(CObjectListItem * objListItem){
// return objListItem->getNext();
//}
CObjectListItem * CObjectList::getItem(int index) {
int i=0;
CObjectListItem * item = getFirst();
while(item!=NULL && i<index) {
item = item->getNext();
i++;
}
if (i==index) return item;
else return NULL;
}
int CObjectList::getNumItems(){
CObjectListItem * item = getFirst();
int numItems = 0;
while (item != NULL){
item = item->getNext();
numItems++;
}
return numItems;
}

View File

@@ -0,0 +1,49 @@
/*
* PVVMUD a 3D MUD
* Copyright (C) 1998-1999 Programvareverkstedet (pvv@pvv.org)
*
* 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.
*
* 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
*
*/
#include "pvvmud.H"
#include "objectqueue.H"
CObjectQueue::CObjectQueue():CObjectList(){
}
CObjectQueue::~CObjectQueue(){
}
void CObjectQueue::add(CObject * object){
addFirst(object);
}
CObject * CObjectQueue::getFIFO(){
CObjectListItem * item = removeLast();
if (item == NULL) return NULL;
CObject * object = item->getObject();
delete item;
return object;
}
CObject * CObjectQueue::getStack(){
CObjectListItem * item = removeFirst();
if (item == NULL) return NULL;
CObject * object = item->getObject();
delete item;
return object;
}

View File

@@ -0,0 +1,107 @@
/*
* PVVMUD a 3D MUD
* Copyright (C) 1998-1999 Programvareverkstedet (pvv@pvv.org)
*
* 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.
*
* 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
*
*/
#include "pvvmud.H"
#include "position.H"
CPosition::CPosition(){
position[0] = 0;
position[1] = 0;
position[2] = 0;
}
CPosition::CPosition(double * position){
this->position[0] = position[0];
this->position[1] = position[1];
this->position[2] = position[2];
}
CPosition::CPosition(double x, double y, double z){
position[0] = x;
position[1] = y;
position[2] = z;
}
CPosition::~CPosition(){
}
CPosition& CPosition::operator= (const CPosition& position) {
this->position[0] = position.position[0];
this->position[1] = position.position[1];
this->position[2] = position.position[2];
return *this;
}
CPosition& CPosition::operator+= (const CPosition& position) {
this->position[0] += position.position[0];
this->position[1] += position.position[1];
this->position[2] += position.position[2];
return *this;
}
int CPosition::operator< (const CPosition& position) const {
return ((this->position[0] < position.position[0])&&
(this->position[1] < position.position[1])&&
(this->position[2] < position.position[2]));
}
int CPosition::operator> (const CPosition& position) const {
return ((this->position[0] > position.position[0])&&
(this->position[1] > position.position[1])&&
(this->position[2] > position.position[2]));
}
int CPosition::operator<= (const CPosition& position) const {
return ((this->position[0] <= position.position[0])&&
(this->position[1] <= position.position[1])&&
(this->position[2] <= position.position[2]));
}
int CPosition::operator>= (const CPosition& position) const {
return ((this->position[0] >= position.position[0])&&
(this->position[1] >= position.position[1])&&
(this->position[2] >= position.position[2]));
}
double * CPosition::getVector(){
return position;
}
CPosition CPosition::operator- (const CPosition& position) const{
CPosition result;
result.position[0] = this->position[0] - position.position[0];
result.position[1] = this->position[1] - position.position[1];
result.position[2] = this->position[2] - position.position[2];
return result;
}
CPosition CPosition::operator- () const{
CPosition result;
result.position[0] = - position[0];
result.position[1] = - position[1];
result.position[2] = - position[2];
return result;
}
ostream& operator<<(ostream&s,const CPosition& p){
return s << "(" << p.getX() << "," << p.getY() << "," << p.getZ() << ")";
}

195
common/lib/srvcli/socket.C Normal file
View File

@@ -0,0 +1,195 @@
/*
* PVVMUD a 3D MUD
* Copyright (C) 1998-1999 Programvareverkstedet (pvv@pvv.org)
*
* 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.
*
* 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
*
*/
#include "pvvmud.H"
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netdb.h>
#include <fcntl.h>
#include <errno.h>
#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include "socket.H"
#include "manager.H"
#include <sys/utsname.h>
// TODO:
// address and localAddress are not set systematically
//
CSocketException::CSocketException():CException("Socket exception"){
}
CSocket::CSocket(){
if((fd = socket(AF_INET, SOCK_STREAM, 0)) < 0){
throw new CSocketException();
}
}
#ifndef socklen_t
#define socklen_t int
#endif
CSocket::CSocket(int fd){
struct sockaddr_in sin;
socklen_t addrlen = sizeof(sin);
this->fd = fd;
addrlen = sizeof(sin);
getpeername(fd,(struct sockaddr*)&sin,&addrlen);
address = CInetAddress(ntohl(sin.sin_addr.s_addr),ntohs(sin.sin_port));
addrlen = sizeof(sin);
getsockname(fd,(struct sockaddr*)&sin,&addrlen);
localAddress = CInetAddress(ntohl(sin.sin_addr.s_addr),ntohs(sin.sin_port));
}
void CSocket::bind( char *addr, int port ) {
int opt = 1; /* For setting reuse_addr */
struct sockaddr_in sin; /* Address for socket */
struct linger ld; /* To set linger option */
localPort = port;
setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, (char *)&opt, sizeof(opt) );
ld.l_onoff = 0;
ld.l_linger = 0;
setsockopt(fd, SOL_SOCKET, SO_LINGER, (char *)&ld, sizeof(ld));
sin.sin_family = AF_INET;
sin.sin_port = htons(port);
sin.sin_addr.s_addr = htonl(INADDR_ANY);
// Try to bind the address to the socket.
if(::bind(fd, (struct sockaddr*)&sin, sizeof(sin)) < 0) {
throw new CSocketException();
}
socklen_t length = sizeof(sin);
getsockname(fd, (struct sockaddr*)&sin, &length);
if (strcmp(addr,"any")) {
if (!strcmp(addr,"localhost")) {
struct hostent *hptr;
struct utsname myname;
if (uname(&myname)<0) return;
if ((hptr=gethostbyname(myname.nodename))==NULL) return;
sin.sin_addr.s_addr = (*((DWORD*)hptr->h_addr_list[0]));
} else {
CInetAddress address(addr);
sin.sin_addr.s_addr = address.getAddress();
}
}
localAddress.setAddress(ntohl(sin.sin_addr.s_addr),ntohs(sin.sin_port));
}
void CSocket::listen(int number){
if (::listen(fd,number) < 0)
throw new CSocketException();
}
void CSocket::connect(unsigned long addr, int port){
struct sockaddr_in sin;
// address = CInetAddress(addr,port);
sin.sin_family = AF_INET;
sin.sin_port = htons(port);
sin.sin_addr.s_addr = htonl(addr);
if (::connect(fd, (struct sockaddr*)&sin, sizeof sin ) == -1) {
cdebug << "ERROR: Connect: " << strerror(errno) << "\n";
throw new CSocketException();
}
socklen_t length = sizeof(sin);
getpeername(fd,(struct sockaddr*)&sin,&length);
address = CInetAddress(ntohl(sin.sin_addr.s_addr),ntohs(sin.sin_port));
length = sizeof(sin);
getsockname(fd, (struct sockaddr*)&sin, &length);
localAddress.setAddress(ntohl(sin.sin_addr.s_addr),ntohs(sin.sin_port));
}
CStream * CSocket::getStream(){
return new CStream(fd);
}
void CSocket::close(){
::close(fd);
}
CClientSocket::CClientSocket(unsigned long addr, int port):CSocket(){
connect(addr,port);
}
CServerSocket::CServerSocket(int port):CSocket(){
bind("any",port);
listen(5);
}
CServerSocket::CServerSocket(char *addr, int port):CSocket(){
bind(addr,port);
listen(5);
}
CSocket * CServerSocket::accept(){
int n_sock; /* For accepting connection */
struct sockaddr_in sin; /* Address for socket */
socklen_t len; /* For use with accept() */
len = sizeof(sin);
if ((n_sock=::accept(getFileDescriptor(), (struct sockaddr*)&sin, &len)) < 0){
cdebug << "CServerSocket::accept Error: " << strerror(errno) << "\n";
throw new CSocketException();
} else {
return new CSocket(n_sock);
}
}
void CSocket::set_fl(int flags) /* flags are file status flags to turn o
n */
{
int val;
if ((val = fcntl(fd, F_GETFL, 0)) < 0)
perror("Error Socket: fcntl");
val |= flags;
if (fcntl(fd, F_SETFL, val) < 0)
perror("Error Socket: fcntl");
}
void CSocket::setNonBlocking(){
set_fl(O_NONBLOCK);
}

189
common/lib/srvcli/stream.C Normal file
View File

@@ -0,0 +1,189 @@
/*
* PVVMUD a 3D MUD
* Copyright (C) 1998-1999 Programvareverkstedet (pvv@pvv.org)
*
* 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.
*
* 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
*
*/
#include "pvvmud.H"
#include <unistd.h>
#include <iostream.h>
#include <string.h>
#include <stdlib.h>
#include <errno.h>
#include "stream.H"
#define INC_START if (++start >= STREAMSIZE) start = 0; size--
#define INC_STOP if (++stop >= STREAMSIZE) stop = 0; size++
/////////////////////////////////////////////////////////////////////////////
// Stream exceptions
CEmptyStreamException::CEmptyStreamException()
:CException("Empty stream exception"){
}
CEOFException::CEOFException():CException("EOF exception"){
}
CIOException::CIOException():CException("IO exception"){
}
/////////////////////////////////////////////////////////////////////////////
// Constructor and destructor
CStream::CStream(int fd){
start = stop = size = 0;
this->fd = fd;
}
CStream::~CStream(){
close(fd);
}
/////////////////////////////////////////////////////////////////////////////
// Private functions
/////////////////////////////////////////////////////////////////////////////
int CStream::writeInBuf(char * msg, int length){
int nn = 0;
if ((STREAMSIZE - size) < length) return FALSE;
while (nn < length){
buf[stop] = msg[nn++];
INC_STOP;
}
return TRUE;
}
unsigned long totalread = 0;
unsigned long totalwrite = 0;
int CStream::fillBuf(){
long length,max;
char rbuf[STREAMSIZE];
max = MIN(STREAMSIZE-size,READBUFSIZE);
#ifndef CRYPTO
length=::read(fd,&rbuf,max);
if (length > 0) {
totalread+=length;
writeInBuf(rbuf,length);
};
#else
length=CCrypto::read(fd,&m_rbuf,(STREAMSIZE-size));
if (length > 0) {
totalread+=length;
writeInBuf(m_rbuf,length);
};
#endif
// Check for errors
if ((max != 0) && (length == 0)){
throw new CEOFException();
} else if (length == -1){
switch(errno){
case EAGAIN: // Non-blocking I/O
break;
default:
cdebug << "Error reading socket: " << strerror(errno) << "\n";
throw new CIOException();
break;
}
}
return size;
}
/////////////////////////////////////////////////////////////////////////////
// Public functions
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// peepByte
//
// Description: Returning first byte in input stream without removing it from
// input buf.
//
// Return : First byte in input stream
//
// Exceptions : CEmptyStreamException, CEOFException, CIOException
//
BYTE CStream::peepByte(){
fillBuf();
if (size < 1) throw new CEmptyStreamException();
return buf[start];
}
/////////////////////////////////////////////////////////////////////////////
// readBuf
//
// Description: Read length bytes from stream
//
// Return : Number of bytes read or -1 if read would have blocked
//
// Exceptions : CEOFException , CIOException
//
int CStream::readBuf(BYTE * msg, int length){
if (fillBuf() == 0) return -1;
int nn = 0;
while ((size >= 1) && (nn < length)){
msg[nn++] = buf[start];
INC_START;
if (size == 0) fillBuf();
}
return nn;
}
/////////////////////////////////////////////////////////////////////////////
// writeBuf
//
// Description: Write length bytes to stream
//
// Return : Number of bytes writen or -1 if write would have blocked
//
// Exceptions : CEOFException , CIOException
//
int CStream::writeBuf(BYTE * buf,int length){
#ifdef CRYPTO
int num = CCrypto::write(fd,buf,length);
#else
int num = ::write(fd,buf,length);
#endif
if (num >= 0){
totalwrite += num;
} else {
if (num == -2) return -1; // Error handling in crypto-routines
switch (errno){
case EPIPE:
throw new CEOFException();
break;
case EAGAIN: // Non-Blocking I/O
return -1;
break;
default:
throw new CIOException();
break;
}
}
return num;
}

View File

@@ -0,0 +1,258 @@
/*
* PVVMUD a 3D MUD
* Copyright (C) 1998-1999 Programvareverkstedet (pvv@pvv.org)
*
* 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.
*
* 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
*
*/
#include "pvvmud.H"
#include <string.h>
#include <stdlib.h>
#include <limits.h>
#include <sys/types.h>
#include <iostream.h>
#include "timekeeper.H"
#include "exception.H"
#define mrealloc(ptr, size) ((ptr) ? realloc(ptr, size) : malloc(size))
#define nextsize(size) (((size)==0) ? 20 : ((size)*2))
// Infinite time not defined on all os
#ifndef INFTIM
#define INFTIM -1
#endif
//#define DEBUG_TIMEKEEPER
int CTimeKeeperItem::timeKeeperFD(int event){
return FALSE;
}
int CTimeKeeperItem::timeKeeperSetEvents(int event){
if (m_timeKeeper != NULL){
m_timeKeeper->setEvents(this,event);
return 1;
}
return 0;
}
int CTimeKeeperItem::timeKeeperHB(){
return FALSE;
}
CTimeKeeper::CTimeKeeper() {
hbs=NULL;
num_hbs=0; size_hbs=0;
fds=NULL; timeKeeperFD=NULL;
num_fdns=0; size_fds=0;
mintimeout=INT_MAX;
num=0;
running=0;
setTime();
}
CTimeKeeper::~CTimeKeeper(){
}
void
CTimeKeeper::setTime() {
struct timezone tzp;
gettimeofday(&lasttime, &tzp);
}
int
CTimeKeeper::getTime() {
struct timezone tzp;
struct timeval tv;
gettimeofday(&tv, &tzp);
return ((tv.tv_sec-lasttime.tv_sec)*1000
+(tv.tv_usec-lasttime.tv_usec)/1000);
}
int
CTimeKeeper::addFd(int fd, CTimeKeeperItem * fn, short events) {
fn->timeKeeperSetTimeKeeper(this);
if (size_fds<=num_fdns) {
size_fds = nextsize(size_fds);
fds = (struct pollfd *)mrealloc(fds, size_fds*sizeof(struct pollfd));
timeKeeperFD = (CTimeKeeperItem **)mrealloc(timeKeeperFD,size_fds*sizeof(CTimeKeeperItem*));
if ((fds == NULL) | (timeKeeperFD == NULL)){
throw new CException("Out of memory exception");
}
}
fds[num_fdns].fd = fd;
fds[num_fdns].events = events;
fds[num_fdns].revents = 0;
timeKeeperFD[num_fdns] = fn;
num_fdns++;
return 0;
}
#define MYmemmove(a,b,c) cdebug << "Memmove(Dest= " << a << ",Src= " << b << ",Length= " << c << ");\n"; memmove(a,b,c)
int
CTimeKeeper::rmFd(int fd) {
int i = num_fdns-1;
while (i >= 0){
// for (i=0; i<num_fdns; i++) {
if (fds[i].fd == fd) {
#ifdef DEBUG_TIMEKEEPER
cdebug << "CTimeKeeper::rmFD ( " << fd << " ) at pos : " << i << "\n";
#endif
memmove(&fds[i], &fds[i+1], (DWORD)&fds[num_fdns]-(DWORD)&fds[i+1]);
memmove(&timeKeeperFD[i], &timeKeeperFD[i+1], (DWORD)&timeKeeperFD[num_fdns]-(DWORD)&timeKeeperFD[i+1]);
num_fdns--;
return 1;
}
i--;
}
return 0;
}
int CTimeKeeper::setEvents(CTimeKeeperItem * fn,short events){
int i;
for (i=0; i<num_fdns; i++) {
if (timeKeeperFD[i] == fn) {
fds[i].events = events;
return 1;
}
}
return 0;
}
int
CTimeKeeper::addHeartBeat(int timeout, CTimeKeeperItem * fn) {
int nsize, i;
void *nptr;
if (size_hbs<=num_hbs) {
nsize = nextsize(size_hbs);
nptr = mrealloc(hbs, nsize*sizeof(struct heartbeat));
if (!nptr) return 1;
size_hbs = nsize;
hbs = (struct heartbeat *)nptr;
}
/* round down to nearest 2^n */
for (i=0; timeout &= ~(1<<i) ; i++);
timeout = 1<<i;
hbs[num_hbs].timeout = timeout;
if (timeout < mintimeout) mintimeout=timeout;
hbs[num_hbs].fn = fn;
num_hbs++;
return 0;
}
int
CTimeKeeper::rmHeartBeat(CTimeKeeperItem * fn) {
int i, j;
for (i=0; i<num_hbs; i++) {
if (hbs[i].fn == fn) {
memmove(&hbs[i], &hbs[i+1], &hbs[num_hbs]-&hbs[i+1]);
num_hbs--;
mintimeout = INT_MAX;
for (j=0; j<num_hbs; j++) {
if (hbs[i].timeout < mintimeout)
mintimeout=hbs[i].timeout;
}
return 1;
}
}
return 0;
}
void
CTimeKeeper::stopLoop() {
running=0;
}
void
CTimeKeeper::mainLoop() {
running=1;
while (running) {
poll( ((mintimeout == INT_MAX) ? INFTIM : mintimeout) );
}
}
void
CTimeKeeper::poll(int timeOut) {
int nready, i;
nready = ::poll(fds, num_fdns,timeOut);
// cdebug << "Poll : " << nready << "\n";
#ifdef DEBUG_TIMEKEEPER
if (nready > 0){
cdebug << "CTimeKeeper::poll(...)\n";
cdebug << " nready : " << nready << "\n";
i = num_fdns-1;
while (i >= 0){
cdebug << " fds[" << i << "].fd : " << fds[i].fd << "\n";
cdebug << " fds[" << i << "].events : " << fds[i].events << "\n";
cdebug << " fds[" << i << "].revents : " << fds[i].revents << "\n";
cdebug << " timeKeeperFD[" << i << "].getName() : "
<< timeKeeperFD[i]->getName() << "\n";
i--;
}
}
#endif
// for (i=0; nready > 0 && i < num_fdns; i++) {
i = num_fdns-1; // New
while (i >= 0){ // New
if (fds[i].revents) {
// cdebug << "Event : " << fds[i].revents << "\n";
if (!timeKeeperFD[i]->timeKeeperFD(fds[i].revents)){
rmFd(fds[i].fd);
// i--;
} else {
fds[i].revents=0;
}
// nready--;
}
i--; // New
}
if ( getTime() >= mintimeout ) {
for (i=0; i < num_hbs; i++) {
if (!(num % (hbs[i].timeout/mintimeout))) {
if (!hbs[i].fn->timeKeeperHB()){
rmHeartBeat(hbs[i].fn);
i--;
}
}
}
num++;
setTime();
}
}

View File

@@ -0,0 +1,50 @@
/*
* PVVMUD a 3D MUD
* Copyright (C) 1998-1999 Programvareverkstedet (pvv@pvv.org)
*
* 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.
*
* 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
*
*/
#include "pvvmud.H"
#include "viewpoint.H"
CViewpoint::CViewpoint(){
}
void CViewpoint::setPosition( const CPosition & position ){
this->position = position;
}
CPosition & CViewpoint::getPosition(){
return position;
}
void CViewpoint::setDirection( const CDirection & direction ){
this->direction = direction;
}
CDirection & CViewpoint::getDirection(){
return direction;
}
void CViewpoint::setTargetId(DWORD targetId){
m_targetId = targetId;
}
DWORD CViewpoint::getTargetId(){
return m_targetId;
}

View File

@@ -0,0 +1,8 @@
INCLUDES = -I../../include
noinst_LIBRARIES = libtexture.a
libtexture_a_SOURCES = texture.C texturemap.C \
load_rgb.C \
load_tiff.C save_tiff.C \
load_tex.C save_tex.C

View File

@@ -0,0 +1,331 @@
# Makefile.in generated automatically by automake 1.4 from Makefile.am
# Copyright (C) 1994, 1995-8, 1999 Free Software Foundation, Inc.
# This Makefile.in is free software; the Free Software Foundation
# gives unlimited permission to copy and/or distribute it,
# with or without modifications, as long as this notice is preserved.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY, to the extent permitted by law; without
# even the implied warranty of MERCHANTABILITY or FITNESS FOR A
# PARTICULAR PURPOSE.
SHELL = @SHELL@
srcdir = @srcdir@
top_srcdir = @top_srcdir@
VPATH = @srcdir@
prefix = @prefix@
exec_prefix = @exec_prefix@
bindir = @bindir@
sbindir = @sbindir@
libexecdir = @libexecdir@
datadir = @datadir@
sysconfdir = @sysconfdir@
sharedstatedir = @sharedstatedir@
localstatedir = @localstatedir@
libdir = @libdir@
infodir = @infodir@
mandir = @mandir@
includedir = @includedir@
oldincludedir = /usr/include
DESTDIR =
pkgdatadir = $(datadir)/@PACKAGE@
pkglibdir = $(libdir)/@PACKAGE@
pkgincludedir = $(includedir)/@PACKAGE@
top_builddir = ../../..
ACLOCAL = @ACLOCAL@
AUTOCONF = @AUTOCONF@
AUTOMAKE = @AUTOMAKE@
AUTOHEADER = @AUTOHEADER@
INSTALL = @INSTALL@
INSTALL_PROGRAM = @INSTALL_PROGRAM@ $(AM_INSTALL_PROGRAM_FLAGS)
INSTALL_DATA = @INSTALL_DATA@
INSTALL_SCRIPT = @INSTALL_SCRIPT@
transform = @program_transform_name@
NORMAL_INSTALL = :
PRE_INSTALL = :
POST_INSTALL = :
NORMAL_UNINSTALL = :
PRE_UNINSTALL = :
POST_UNINSTALL = :
CC = @CC@
CXX = @CXX@
GL_CFLAGS = @GL_CFLAGS@
GL_LIBS = @GL_LIBS@
LEX = @LEX@
MAKEINFO = @MAKEINFO@
NETLIBS = @NETLIBS@
PACKAGE = @PACKAGE@
RANLIB = @RANLIB@
TIFF_CFLAGS = @TIFF_CFLAGS@
TIFF_LIBS = @TIFF_LIBS@
VERSION = @VERSION@
YACC = @YACC@
INCLUDES = -I../../include
noinst_LIBRARIES = libtexture.a
libtexture_a_SOURCES = texture.C texturemap.C load_rgb.C load_tiff.C save_tiff.C load_tex.C save_tex.C
mkinstalldirs = $(SHELL) $(top_srcdir)/mkinstalldirs
CONFIG_CLEAN_FILES =
LIBRARIES = $(noinst_LIBRARIES)
DEFS = @DEFS@ -I. -I$(srcdir)
CPPFLAGS = @CPPFLAGS@
LDFLAGS = @LDFLAGS@
LIBS = @LIBS@
X_CFLAGS = @X_CFLAGS@
X_LIBS = @X_LIBS@
X_EXTRA_LIBS = @X_EXTRA_LIBS@
X_PRE_LIBS = @X_PRE_LIBS@
libtexture_a_LIBADD =
libtexture_a_OBJECTS = texture.o texturemap.o load_rgb.o load_tiff.o \
save_tiff.o load_tex.o save_tex.o
AR = ar
CXXFLAGS = @CXXFLAGS@
CXXCOMPILE = $(CXX) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS)
CXXLD = $(CXX)
CXXLINK = $(CXXLD) $(AM_CXXFLAGS) $(CXXFLAGS) $(LDFLAGS) -o $@
DIST_COMMON = Makefile.am Makefile.in
DISTFILES = $(DIST_COMMON) $(SOURCES) $(HEADERS) $(TEXINFOS) $(EXTRA_DIST)
TAR = gtar
GZIP_ENV = --best
DEP_FILES = .deps/load_rgb.P .deps/load_tex.P .deps/load_tiff.P \
.deps/save_tex.P .deps/save_tiff.P .deps/texture.P .deps/texturemap.P
SOURCES = $(libtexture_a_SOURCES)
OBJECTS = $(libtexture_a_OBJECTS)
all: all-redirect
.SUFFIXES:
.SUFFIXES: .C .S .c .o .s
$(srcdir)/Makefile.in: Makefile.am $(top_srcdir)/configure.in $(ACLOCAL_M4)
cd $(top_srcdir) && $(AUTOMAKE) --foreign common/lib/texture/Makefile
Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status $(BUILT_SOURCES)
cd $(top_builddir) \
&& CONFIG_FILES=$(subdir)/$@ CONFIG_HEADERS= $(SHELL) ./config.status
mostlyclean-noinstLIBRARIES:
clean-noinstLIBRARIES:
-test -z "$(noinst_LIBRARIES)" || rm -f $(noinst_LIBRARIES)
distclean-noinstLIBRARIES:
maintainer-clean-noinstLIBRARIES:
.s.o:
$(COMPILE) -c $<
.S.o:
$(COMPILE) -c $<
mostlyclean-compile:
-rm -f *.o core *.core
clean-compile:
distclean-compile:
-rm -f *.tab.c
maintainer-clean-compile:
libtexture.a: $(libtexture_a_OBJECTS) $(libtexture_a_DEPENDENCIES)
-rm -f libtexture.a
$(AR) cru libtexture.a $(libtexture_a_OBJECTS) $(libtexture_a_LIBADD)
$(RANLIB) libtexture.a
.C.o:
$(CXXCOMPILE) -c $<
tags: TAGS
ID: $(HEADERS) $(SOURCES) $(LISP)
list='$(SOURCES) $(HEADERS)'; \
unique=`for i in $$list; do echo $$i; done | \
awk ' { files[$$0] = 1; } \
END { for (i in files) print i; }'`; \
here=`pwd` && cd $(srcdir) \
&& mkid -f$$here/ID $$unique $(LISP)
TAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) $(LISP)
tags=; \
here=`pwd`; \
list='$(SOURCES) $(HEADERS)'; \
unique=`for i in $$list; do echo $$i; done | \
awk ' { files[$$0] = 1; } \
END { for (i in files) print i; }'`; \
test -z "$(ETAGS_ARGS)$$unique$(LISP)$$tags" \
|| (cd $(srcdir) && etags $(ETAGS_ARGS) $$tags $$unique $(LISP) -o $$here/TAGS)
mostlyclean-tags:
clean-tags:
distclean-tags:
-rm -f TAGS ID
maintainer-clean-tags:
distdir = $(top_builddir)/$(PACKAGE)-$(VERSION)/$(subdir)
subdir = common/lib/texture
distdir: $(DISTFILES)
here=`cd $(top_builddir) && pwd`; \
top_distdir=`cd $(top_distdir) && pwd`; \
distdir=`cd $(distdir) && pwd`; \
cd $(top_srcdir) \
&& $(AUTOMAKE) --include-deps --build-dir=$$here --srcdir-name=$(top_srcdir) --output-dir=$$top_distdir --foreign common/lib/texture/Makefile
@for file in $(DISTFILES); do \
d=$(srcdir); \
if test -d $$d/$$file; then \
cp -pr $$/$$file $(distdir)/$$file; \
else \
test -f $(distdir)/$$file \
|| ln $$d/$$file $(distdir)/$$file 2> /dev/null \
|| cp -p $$d/$$file $(distdir)/$$file || :; \
fi; \
done
DEPS_MAGIC := $(shell mkdir .deps > /dev/null 2>&1 || :)
-include $(DEP_FILES)
mostlyclean-depend:
clean-depend:
distclean-depend:
-rm -rf .deps
maintainer-clean-depend:
%.o: %.c
@echo '$(COMPILE) -c $<'; \
$(COMPILE) -Wp,-MD,.deps/$(*F).pp -c $<
@-cp .deps/$(*F).pp .deps/$(*F).P; \
tr ' ' '\012' < .deps/$(*F).pp \
| sed -e 's/^\\$$//' -e '/^$$/ d' -e '/:$$/ d' -e 's/$$/ :/' \
>> .deps/$(*F).P; \
rm .deps/$(*F).pp
%.lo: %.c
@echo '$(LTCOMPILE) -c $<'; \
$(LTCOMPILE) -Wp,-MD,.deps/$(*F).pp -c $<
@-sed -e 's/^\([^:]*\)\.o[ ]*:/\1.lo \1.o :/' \
< .deps/$(*F).pp > .deps/$(*F).P; \
tr ' ' '\012' < .deps/$(*F).pp \
| sed -e 's/^\\$$//' -e '/^$$/ d' -e '/:$$/ d' -e 's/$$/ :/' \
>> .deps/$(*F).P; \
rm -f .deps/$(*F).pp
%.o: %.C
@echo '$(CXXCOMPILE) -c $<'; \
$(CXXCOMPILE) -Wp,-MD,.deps/$(*F).pp -c $<
@-cp .deps/$(*F).pp .deps/$(*F).P; \
tr ' ' '\012' < .deps/$(*F).pp \
| sed -e 's/^\\$$//' -e '/^$$/ d' -e '/:$$/ d' -e 's/$$/ :/' \
>> .deps/$(*F).P; \
rm .deps/$(*F).pp
%.lo: %.C
@echo '$(LTCXXCOMPILE) -c $<'; \
$(LTCXXCOMPILE) -Wp,-MD,.deps/$(*F).pp -c $<
@-sed -e 's/^\([^:]*\)\.o[ ]*:/\1.lo \1.o :/' \
< .deps/$(*F).pp > .deps/$(*F).P; \
tr ' ' '\012' < .deps/$(*F).pp \
| sed -e 's/^\\$$//' -e '/^$$/ d' -e '/:$$/ d' -e 's/$$/ :/' \
>> .deps/$(*F).P; \
rm -f .deps/$(*F).pp
info-am:
info: info-am
dvi-am:
dvi: dvi-am
check-am: all-am
check: check-am
installcheck-am:
installcheck: installcheck-am
install-exec-am:
install-exec: install-exec-am
install-data-am:
install-data: install-data-am
install-am: all-am
@$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am
install: install-am
uninstall-am:
uninstall: uninstall-am
all-am: Makefile $(LIBRARIES)
all-redirect: all-am
install-strip:
$(MAKE) $(AM_MAKEFLAGS) AM_INSTALL_PROGRAM_FLAGS=-s install
installdirs:
mostlyclean-generic:
clean-generic:
distclean-generic:
-rm -f Makefile $(CONFIG_CLEAN_FILES)
-rm -f config.cache config.log stamp-h stamp-h[0-9]*
maintainer-clean-generic:
mostlyclean-am: mostlyclean-noinstLIBRARIES mostlyclean-compile \
mostlyclean-tags mostlyclean-depend mostlyclean-generic
mostlyclean: mostlyclean-am
clean-am: clean-noinstLIBRARIES clean-compile clean-tags clean-depend \
clean-generic mostlyclean-am
clean: clean-am
distclean-am: distclean-noinstLIBRARIES distclean-compile \
distclean-tags distclean-depend distclean-generic \
clean-am
distclean: distclean-am
maintainer-clean-am: maintainer-clean-noinstLIBRARIES \
maintainer-clean-compile maintainer-clean-tags \
maintainer-clean-depend maintainer-clean-generic \
distclean-am
@echo "This command is intended for maintainers to use;"
@echo "it deletes files that may require special tools to rebuild."
maintainer-clean: maintainer-clean-am
.PHONY: mostlyclean-noinstLIBRARIES distclean-noinstLIBRARIES \
clean-noinstLIBRARIES maintainer-clean-noinstLIBRARIES \
mostlyclean-compile distclean-compile clean-compile \
maintainer-clean-compile tags mostlyclean-tags distclean-tags \
clean-tags maintainer-clean-tags distdir mostlyclean-depend \
distclean-depend clean-depend maintainer-clean-depend info-am info \
dvi-am dvi check check-am installcheck-am installcheck install-exec-am \
install-exec install-data-am install-data install-am install \
uninstall-am uninstall all-redirect all-am all installdirs \
mostlyclean-generic distclean-generic clean-generic \
maintainer-clean-generic clean mostlyclean distclean maintainer-clean
# Tell versions [3.59,3.63) of GNU make to not export all variables.
# Otherwise a system limit (for SysV at least) may be exceeded.
.NOEXPORT:

View File

@@ -0,0 +1,280 @@
/*
* PVVMUD a 3D MUD
* Copyright (C) 1998-1999 Programvareverkstedet (pvv@pvv.org)
*
* 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.
*
* 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
*
*/
#include "pvvmud.H"
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "texture.H"
#include "load_rgb.H"
#include "exception.H"
#include <iostream.h>
#define IMAGIC 0x01da
#define IMAGIC_SWAP 0xda01
#define SWAP_SHORT_BYTES(x) ((((x) & 0xff) << 8) | (((x) & 0xff00) >> 8))
#define SWAP_LONG_BYTES(x) (((((x) & 0xff) << 24) | (((x) & 0xff00) << 8)) | \
((((x) & 0xff0000) >> 8) | (((x) & 0xff000000) >> 24)))
typedef struct
{
unsigned short imagic;
unsigned short type;
unsigned short dim;
unsigned short sizeX, sizeY, sizeZ;
unsigned long min, max;
unsigned long wasteBytes;
char name[80];
unsigned long colorMap;
FILE *file;
unsigned char *tmp[5];
unsigned long rleEnd;
unsigned long *rowStart;
unsigned long *rowSize;
} Image_RGB;
static Image_RGB *ImageRGB_Open(char *fileName)
{
Image_RGB *image;
unsigned long *rowStart, *rowSize, ulTmp;
int x, i;
image = (Image_RGB *)malloc(sizeof(Image_RGB));
if (image == NULL)
{
cdebug << "Out of memory!\n";
exit(-1);
}
if ((image->file = fopen(fileName, "rb")) == NULL)
{
perror(fileName);
exit(-1);
}
/*
* Read the image header
*/
fread(image, 1, 12, image->file);
/*
* Check byte order
*/
if (image->imagic == IMAGIC_SWAP)
{
image->type = SWAP_SHORT_BYTES(image->type);
image->dim = SWAP_SHORT_BYTES(image->dim);
image->sizeX = SWAP_SHORT_BYTES(image->sizeX);
image->sizeY = SWAP_SHORT_BYTES(image->sizeY);
image->sizeZ = SWAP_SHORT_BYTES(image->sizeZ);
}
for ( i = 0 ; i <= image->sizeZ ; i++ )
{
image->tmp[i] = (unsigned char *)malloc(image->sizeX*256);
if (image->tmp[i] == NULL )
{
cdebug << "Out of memory!\n";
exit(-1);
}
}
if ((image->type & 0xFF00) == 0x0100) /* RLE image */
{
x = image->sizeY * image->sizeZ * sizeof(long);
image->rowStart = (unsigned long *)malloc(x);
image->rowSize = (unsigned long *)malloc(x);
if (image->rowStart == NULL || image->rowSize == NULL)
{
cdebug << "Out of memory!\n";
exit(-1);
}
image->rleEnd = 512 + (2 * x);
fseek(image->file, 512, SEEK_SET);
fread(image->rowStart, 1, x, image->file);
fread(image->rowSize, 1, x, image->file);
if (image->imagic == IMAGIC_SWAP)
{
x /= sizeof(long);
rowStart = image->rowStart;
rowSize = image->rowSize;
while (x--)
{
ulTmp = *rowStart;
*rowStart++ = SWAP_LONG_BYTES(ulTmp);
ulTmp = *rowSize;
*rowSize++ = SWAP_LONG_BYTES(ulTmp);
}
}
}
return image;
}
static void ImageRGB_Close( Image_RGB *image)
{
int i;
fclose(image->file);
for ( i = 0 ; i <= image->sizeZ ; i++ )
free(image->tmp[i]);
free(image);
}
static void ImageRGB_GetRow( Image_RGB *image, unsigned char *buf, int y, int z)
{
unsigned char *iPtr, *oPtr, pixel;
int count;
if ((image->type & 0xFF00) == 0x0100) /* RLE image */
{
fseek(image->file, image->rowStart[y+z*image->sizeY], SEEK_SET);
fread(image->tmp[0], 1, (unsigned int)image->rowSize[y+z*image->sizeY],
image->file);
iPtr = image->tmp[0];
oPtr = buf;
while (1)
{
pixel = *iPtr++;
count = (int)(pixel & 0x7F);
if (!count)
return;
if (pixel & 0x80)
{
while (count--)
{
*oPtr++ = *iPtr++;
}
}
else
{
pixel = *iPtr++;
while (count--)
{
*oPtr++ = pixel;
}
}
}
}
else /* verbatim image */
{
fseek(image->file, 512+(y*image->sizeX)+(z*image->sizeX*image->sizeY),
SEEK_SET);
fread(buf, 1, image->sizeX, image->file);
}
}
static void ImageRGB_GetRawData( Image_RGB *image, char *data)
{
int i, j, k;
int remain;
switch ( image->sizeZ )
{
case 1:
remain = image->sizeX % 4;
break;
case 2:
remain = image->sizeX % 2;
break;
case 3:
remain = (image->sizeX * 3) & 0x3;
if (remain)
remain = 4 - remain;
break;
case 4:
remain = 0;
break;
}
for (i = 0; i < image->sizeY; i++)
{
for ( k = 0; k < image->sizeZ ; k++ )
ImageRGB_GetRow(image, image->tmp[k+1], i, k);
for (j = 0; j < image->sizeX; j++)
for ( k = 1; k <= image->sizeZ ; k++ )
*data++ = *(image->tmp[k] + j);
data += remain;
}
}
void CTextureMap::loadRGB(char *fileName)
{
Image_RGB *image;
IMAGE_RGB_t *final;
int sx,ii,rgbIndex;
unsigned char * rgbData;
image = ImageRGB_Open(fileName);
if (image == NULL){
throw new CException();
}
final = (IMAGE_RGB_t *)malloc(sizeof(IMAGE_RGB_t));
if (final == NULL)
{
cdebug << "Out of memory!\n";
exit(-1);
}
final->imagic = image->imagic;
final->type = image->type;
final->dim = image->dim;
final->sizeX = image->sizeX;
final->sizeY = image->sizeY;
final->sizeZ = image->sizeZ;
/*
* Round up so rows are long-word aligned
*/
sx = ( (image->sizeX) * (image->sizeZ) + 3) >> 2;
rgbData = (unsigned char *)malloc( sx * image->sizeY * sizeof(unsigned int));
if (rgbData == NULL) {
cdebug << "Out of memory!\n";
exit(-1);
}
final->data
= (unsigned long *)malloc( image->sizeX * image->sizeY * sizeof(unsigned long));
if (final->data == NULL) {
cdebug << "Out of memory!\n";
exit(-1);
}
ImageRGB_GetRawData(image, (char*)rgbData);
ImageRGB_Close(image);
m_width = final->sizeX;
m_height = final->sizeY;
rgbIndex = 0;
for (ii = 0; ii < m_width*m_height; ii++){
final->data[ii] = ((DWORD)(rgbData[rgbIndex+2]) << 16) +
((DWORD)(rgbData[rgbIndex+1]) << 8) +
(DWORD)(rgbData[rgbIndex]) + 0xFF000000;
rgbIndex += 3;
}
m_data = (unsigned char*)final->data;
free(final);
free(rgbData);
}

View File

@@ -0,0 +1,33 @@
/*
* PVVMUD a 3D MUD
* Copyright (C) 1998-1999 Programvareverkstedet (pvv@pvv.org)
*
* 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.
*
* 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
*
*/
#ifndef _IMAGE_RGB_H
#define _IMAGE_RGB_H
typedef struct
{
unsigned short imagic;
unsigned short type;
unsigned short dim;
unsigned short sizeX, sizeY, sizeZ;
char name[128];
unsigned long *data;
} IMAGE_RGB_t;
#endif /* _IMAGE_RGB_H */

View File

@@ -0,0 +1,35 @@
/*
* PVVMUD a 3D MUD
* Copyright (C) 1998-1999 Programvareverkstedet (pvv@pvv.org)
*
* 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.
*
* 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
*
*/
#ifndef _IMAGE_RGB_H
#define _IMAGE_RGB_H
typedef struct
{
unsigned short imagic;
unsigned short type;
unsigned short dim;
unsigned short sizeX, sizeY, sizeZ;
char name[128];
unsigned char *data;
} IMAGE_RGB_t;
TextureMap_t *ImageRGB_Load(char *);
#endif /* _IMAGE_RGB_H */

View File

@@ -0,0 +1,52 @@
/*
* PVVMUD a 3D MUD
* Copyright (C) 1998-1999 Programvareverkstedet (pvv@pvv.org)
*
* 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.
*
* 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
*
*/
#include "pvvmud.H"
#include <stdio.h>
#include <stdlib.h>
#include <strings.h>
#include <iostream.h>
#include "texture.H"
#include "exception.H"
void CTextureMap::loadTEX(char * fileName){
char idString[16];
DWORD *data,value;
int version,ii,jj,counter;
FILE * file = fopen(fileName,"r");
if (file == NULL){
throw new CException();
}
fscanf(file,"%s %i\n",idString,&version);
if (strcmp(idString,"TEX") != 0 || version != 1){
fclose(file);
throw new CException("Unknown file format!");
}
fscanf(file,"%hu %hu\n",&m_width,&m_height);
data = (DWORD*)malloc(m_width*m_height*sizeof(DWORD));
counter = 0;
for (ii = 0; ii < m_height; ii ++){
for (jj = 0; jj < m_width; jj++){
fscanf(file,"%lX",&value);
data[counter++] = value;
}
}
m_data = (BYTE*)data;
fclose(file);
}

View File

@@ -0,0 +1,65 @@
/*
* PVVMUD a 3D MUD
* Copyright (C) 1998-1999 Programvareverkstedet (pvv@pvv.org)
*
* 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.
*
* 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
*
*/
#include "pvvmud.H"
#include <stdlib.h>
#include <tiffio.h>
#include "texture.H"
#include "exception.H"
/******************************************************************************
* load_tiff *
* input tiff_file_name File name of tiff file to open *
* retun NULL if failed to open tiff. *
* Created 17/11-1997 by Anders Reggestad *
******************************************************************************/
void CTextureMap::loadTIFF(char * tiff_file_name){
uint32 w, h, ii;
uint32 * tif_raster;
TIFF* tif;
tif = TIFFOpen( tiff_file_name, "r" );
if (tif == NULL){
throw new CException("Failed to open tiff file");
}
TIFFGetField(tif, TIFFTAG_IMAGEWIDTH, &w);
TIFFGetField(tif, TIFFTAG_IMAGELENGTH, &h);
m_width = w;
m_height = h;
m_data = (unsigned char*)malloc(w*h*sizeof(DWORD));
tif_raster = (uint32*)_TIFFmalloc( w*h*sizeof(uint32) );
if (tif_raster == NULL){
throw new CException("Failed to malloc tif_raster");
}
if (TIFFReadRGBAImage(tif, w, h, tif_raster, 0)){
for (ii=0; ii < w*h; ii++)
((DWORD*)m_data)[ii] = tif_raster[ii];
}
_TIFFfree( tif_raster );
TIFFClose( tif );
}

View File

@@ -0,0 +1,50 @@
/*
* PVVMUD a 3D MUD
* Copyright (C) 1998-1999 Programvareverkstedet (pvv@pvv.org)
*
* 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.
*
* 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
*
*/
#include "pvvmud.H"
#include <stdio.h>
#include <stdlib.h>
#include <strings.h>
#include <iostream.h>
#include "texture.H"
#include "exception.H"
void CTextureMap::saveTEX(char * fileName){
int ii,jj,count;
DWORD * data;
FILE * file = fopen(fileName,"w+");
if (file == NULL) throw new CException();
fprintf(file,"TEX 1\n%i %i\n",
getWidth(),
getHeight());
count = 0;
data = (DWORD*)getData();
if (data == NULL) {
fclose(file);
throw new CException();
}
for (ii = 0; ii < getHeight(); ii ++){
for (jj = 1; jj <= getWidth(); jj ++){
fprintf(file,"%08lX",data[count++]);
if (jj != getWidth()) fprintf(file," ");
}
fprintf(file,"\n");
}
fclose(file);
}

View File

@@ -0,0 +1,70 @@
/*
* PVVMUD a 3D MUD
* Copyright (C) 1998-1999 Programvareverkstedet (pvv@pvv.org)
*
* 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.
*
* 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
*
*/
#include "pvvmud.H"
#include <stdlib.h>
#include <tiffio.h>
#include "texture.H"
#include "exception.H"
/******************************************************************************
* save_tiff *
* input tiff_file_name File name of tiff file to create *
* retun NULL if failed to open tiff. *
* Created 23/11-1999 by Anders Reggestad *
******************************************************************************/
void CTextureMap::saveTIFF(char * tiff_file_name){
int width,height,ii;
uint32 *data,*tif_raster;
TIFF* tif;
tif = TIFFOpen( tiff_file_name, "w" );
if (tif == NULL){
cdebug << "ERROR: Faild to create tiff file: " << tiff_file_name << endl;
throw new CException();
}
width = getWidth();
height = getHeight();
data = (uint32*)getData();
TIFFSetField(tif, TIFFTAG_IMAGEWIDTH, width);
TIFFSetField(tif, TIFFTAG_IMAGELENGTH, height);
TIFFSetField(tif, TIFFTAG_PLANARCONFIG, 1);
TIFFSetField(tif, TIFFTAG_SAMPLESPERPIXEL, 4);
TIFFSetField(tif, TIFFTAG_EXTRASAMPLES, 0);
TIFFSetField(tif, TIFFTAG_BITSPERSAMPLE, 8, 8, 8, 8);
TIFFSetField(tif, TIFFTAG_COMPRESSION, 1);
TIFFSetField(tif, TIFFTAG_PHOTOMETRIC, 2);
// TIFFSetField(tif, TIFFTAG_STRIPOFFSETS, 0);
TIFFSetField(tif, TIFFTAG_ROWSPERSTRIP, height);
// TIFFSetField(tif, TIFFTAG_STRIPBYTECOUNTS, height*width*4);
TIFFSetField(tif, TIFFTAG_XRESOLUTION, 1);
TIFFSetField(tif, TIFFTAG_YRESOLUTION, 1);
TIFFSetField(tif, TIFFTAG_RESOLUTIONUNIT, 1);
for (ii = 0; ii < height; ii++){
TIFFWriteScanline(tif,&data[(height-ii-1)*width], ii, 0);
}
TIFFClose( tif );
}

View File

@@ -0,0 +1,153 @@
/*
* PVVMUD a 3D MUD
* Copyright (C) 1998-1999 Programvareverkstedet (pvv@pvv.org)
*
* 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.
*
* 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
*
*/
#include "pvvmud.H"
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include "texture.H"
#include "exception.H"
/******************************************************************************
*
* Create texture
*
*****************************************************************************/
CTexture::CTexture(){
m_id = -1;
m_state = 0;
m_textureMap = NULL;
}
/******************************************************************************
*
* Create texture with given id
*
*****************************************************************************/
CTexture::CTexture(int id){
m_id = id;
m_state = 0;
m_textureMap = NULL;
}
/******************************************************************************
*
* Create texture with given id
*
*****************************************************************************/
CTexture::~CTexture(){
if (m_textureMap != NULL) delete m_textureMap;
}
/******************************************************************************
*
* Test if texturemap is loaded
*
*****************************************************************************/
int CTexture::loaded(){
return ((m_state & TEX_STATE_LOADED)==TEX_STATE_LOADED);
}
/******************************************************************************
*
* Set texturemap to use with texture
*
*****************************************************************************/
void CTexture::setTextureMap(CTextureMap * textureMap){
if (m_textureMap != NULL) delete m_textureMap;
m_textureMap = textureMap;
m_state = m_state | TEX_STATE_LOADED;
}
/******************************************************************************
*
* Get texturemap from texture.
*
*****************************************************************************/
CTextureMap * CTexture::getTextureMap(){
return m_textureMap;
}
/******************************************************************************
*
* Exec texture
*
*****************************************************************************/
int CTexture::exec(){
return FALSE;
}
/******************************************************************************
*
* Load texture
*
*****************************************************************************/
void CTexture::load(char * fileName){
CTextureMap * map = new CTextureMap();
map->load(fileName);
setTextureMap(map);
}
/******************************************************************************
*
* Save texture
*
*****************************************************************************/
void CTexture::save(char * fileName){
m_textureMap->save(fileName);
}
/******************************************************************************
*
* Add texture to TextureCache
*
*****************************************************************************/
CTextureCache::CTextureCache():CCache(){
}
CTexture * CTextureCache::add(CTexture * texture){
return (CTexture*)CCache::add(texture->getId(), (CObject*)texture );
}
CTexture * CTextureCache::get(int id){
return (CTexture*)CCache::get(id);
}

View File

@@ -0,0 +1,99 @@
/*
* PVVMUD a 3D MUD
* Copyright (C) 1998-1999 Programvareverkstedet (pvv@pvv.org)
*
* 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.
*
* 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
*
*/
#include "pvvmud.H"
#include <stdio.h>
#include <stdlib.h>
#include <strings.h>
#include <iostream.h>
#include "texture.H"
#include "exception.H"
CTextureMap::CTextureMap(){
m_width = 0;
m_height = 0;
m_data = NULL;
}
CTextureMap::CTextureMap(WORD width, WORD height, BYTE * data){
setMap(width,height,data);
}
CTextureMap::~CTextureMap(){
if (m_data != NULL) free(m_data);
}
WORD CTextureMap::getWidth(){
return m_width;
}
WORD CTextureMap::getHeight(){
return m_height;
}
BYTE * CTextureMap::getData(){
return m_data;
}
void CTextureMap::setMap(WORD width, WORD height, BYTE * data){
m_width = width;
m_height = height;
m_data = (BYTE*)malloc(m_width*m_height*sizeof(DWORD));
memcpy(m_data,data,m_width*m_height*sizeof(DWORD));
}
void CTextureMap::load(char * fileName){
char * sufix;
if (m_data != NULL) free(m_data);
m_width = m_height = 0;
m_data = NULL;
sufix = strrchr(fileName,'.');
if ( (strncmp(sufix,".tif",4)==0) || (strncmp(sufix,".TIF",4)==0) ){
loadTIFF(fileName);
} else if ( (strcmp(sufix,".rgb")==0) || (strcmp(sufix,".RGB")==0) ){
loadRGB(fileName);
} else if ( (strcmp(sufix,".tex")==0) || (strcmp(sufix,".TEX")==0) ){
loadTEX(fileName);
} else {
cdebug << "Failed!";
throw new CException();
}
}
void CTextureMap::save(char * fileName){
char * sufix;
sufix = strrchr(fileName,'.');
if ( (strncmp(sufix,".tif",4)==0) || (strncmp(sufix,".TIF",4)==0) ){
saveTIFF(fileName);
} else /* if ( (strcmp(sufix,".rgb")==0) || (strcmp(sufix,".RGB")==0) ){
saveRGB(fileName);
} else */ if ( (strcmp(sufix,".tex")==0) || (strcmp(sufix,".TEX")==0) ){
saveTEX(fileName);
} else {
cdebug << "Failed!";
throw new CException();
}
}

View File

@@ -0,0 +1,4 @@
INCLUDES = -I../../include
noinst_LIBRARIES = libpvvmudutils.a
libpvvmudutils_a_SOURCES = beam.C crossindex.C doublearray.C intarray.C matrix.C namedb.C objectarray.C plane.C time.C vector.C option.C getopt.c getopt1.c pingpong.C commandparser.C keyframe.C spline.C

View File

@@ -0,0 +1,337 @@
# Makefile.in generated automatically by automake 1.4 from Makefile.am
# Copyright (C) 1994, 1995-8, 1999 Free Software Foundation, Inc.
# This Makefile.in is free software; the Free Software Foundation
# gives unlimited permission to copy and/or distribute it,
# with or without modifications, as long as this notice is preserved.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY, to the extent permitted by law; without
# even the implied warranty of MERCHANTABILITY or FITNESS FOR A
# PARTICULAR PURPOSE.
SHELL = @SHELL@
srcdir = @srcdir@
top_srcdir = @top_srcdir@
VPATH = @srcdir@
prefix = @prefix@
exec_prefix = @exec_prefix@
bindir = @bindir@
sbindir = @sbindir@
libexecdir = @libexecdir@
datadir = @datadir@
sysconfdir = @sysconfdir@
sharedstatedir = @sharedstatedir@
localstatedir = @localstatedir@
libdir = @libdir@
infodir = @infodir@
mandir = @mandir@
includedir = @includedir@
oldincludedir = /usr/include
DESTDIR =
pkgdatadir = $(datadir)/@PACKAGE@
pkglibdir = $(libdir)/@PACKAGE@
pkgincludedir = $(includedir)/@PACKAGE@
top_builddir = ../../..
ACLOCAL = @ACLOCAL@
AUTOCONF = @AUTOCONF@
AUTOMAKE = @AUTOMAKE@
AUTOHEADER = @AUTOHEADER@
INSTALL = @INSTALL@
INSTALL_PROGRAM = @INSTALL_PROGRAM@ $(AM_INSTALL_PROGRAM_FLAGS)
INSTALL_DATA = @INSTALL_DATA@
INSTALL_SCRIPT = @INSTALL_SCRIPT@
transform = @program_transform_name@
NORMAL_INSTALL = :
PRE_INSTALL = :
POST_INSTALL = :
NORMAL_UNINSTALL = :
PRE_UNINSTALL = :
POST_UNINSTALL = :
CC = @CC@
CXX = @CXX@
GL_CFLAGS = @GL_CFLAGS@
GL_LIBS = @GL_LIBS@
LEX = @LEX@
MAKEINFO = @MAKEINFO@
NETLIBS = @NETLIBS@
PACKAGE = @PACKAGE@
RANLIB = @RANLIB@
TIFF_CFLAGS = @TIFF_CFLAGS@
TIFF_LIBS = @TIFF_LIBS@
VERSION = @VERSION@
YACC = @YACC@
INCLUDES = -I../../include
noinst_LIBRARIES = libpvvmudutils.a
libpvvmudutils_a_SOURCES = beam.C crossindex.C doublearray.C intarray.C matrix.C namedb.C objectarray.C plane.C time.C vector.C option.C getopt.c getopt1.c pingpong.C commandparser.C keyframe.C spline.C
mkinstalldirs = $(SHELL) $(top_srcdir)/mkinstalldirs
CONFIG_CLEAN_FILES =
LIBRARIES = $(noinst_LIBRARIES)
DEFS = @DEFS@ -I. -I$(srcdir)
CPPFLAGS = @CPPFLAGS@
LDFLAGS = @LDFLAGS@
LIBS = @LIBS@
X_CFLAGS = @X_CFLAGS@
X_LIBS = @X_LIBS@
X_EXTRA_LIBS = @X_EXTRA_LIBS@
X_PRE_LIBS = @X_PRE_LIBS@
libpvvmudutils_a_LIBADD =
libpvvmudutils_a_OBJECTS = beam.o crossindex.o doublearray.o intarray.o \
matrix.o namedb.o objectarray.o plane.o time.o vector.o option.o \
getopt.o getopt1.o pingpong.o commandparser.o keyframe.o spline.o
AR = ar
CXXFLAGS = @CXXFLAGS@
CXXCOMPILE = $(CXX) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS)
CXXLD = $(CXX)
CXXLINK = $(CXXLD) $(AM_CXXFLAGS) $(CXXFLAGS) $(LDFLAGS) -o $@
CFLAGS = @CFLAGS@
COMPILE = $(CC) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
CCLD = $(CC)
LINK = $(CCLD) $(AM_CFLAGS) $(CFLAGS) $(LDFLAGS) -o $@
DIST_COMMON = Makefile.am Makefile.in
DISTFILES = $(DIST_COMMON) $(SOURCES) $(HEADERS) $(TEXINFOS) $(EXTRA_DIST)
TAR = gtar
GZIP_ENV = --best
DEP_FILES = .deps/beam.P .deps/commandparser.P .deps/crossindex.P \
.deps/doublearray.P .deps/getopt.P .deps/getopt1.P .deps/intarray.P \
.deps/keyframe.P .deps/matrix.P .deps/namedb.P .deps/objectarray.P \
.deps/option.P .deps/pingpong.P .deps/plane.P .deps/spline.P \
.deps/time.P .deps/vector.P
SOURCES = $(libpvvmudutils_a_SOURCES)
OBJECTS = $(libpvvmudutils_a_OBJECTS)
all: all-redirect
.SUFFIXES:
.SUFFIXES: .C .S .c .o .s
$(srcdir)/Makefile.in: Makefile.am $(top_srcdir)/configure.in $(ACLOCAL_M4)
cd $(top_srcdir) && $(AUTOMAKE) --foreign common/lib/utils/Makefile
Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status $(BUILT_SOURCES)
cd $(top_builddir) \
&& CONFIG_FILES=$(subdir)/$@ CONFIG_HEADERS= $(SHELL) ./config.status
mostlyclean-noinstLIBRARIES:
clean-noinstLIBRARIES:
-test -z "$(noinst_LIBRARIES)" || rm -f $(noinst_LIBRARIES)
distclean-noinstLIBRARIES:
maintainer-clean-noinstLIBRARIES:
.s.o:
$(COMPILE) -c $<
.S.o:
$(COMPILE) -c $<
mostlyclean-compile:
-rm -f *.o core *.core
clean-compile:
distclean-compile:
-rm -f *.tab.c
maintainer-clean-compile:
libpvvmudutils.a: $(libpvvmudutils_a_OBJECTS) $(libpvvmudutils_a_DEPENDENCIES)
-rm -f libpvvmudutils.a
$(AR) cru libpvvmudutils.a $(libpvvmudutils_a_OBJECTS) $(libpvvmudutils_a_LIBADD)
$(RANLIB) libpvvmudutils.a
.C.o:
$(CXXCOMPILE) -c $<
tags: TAGS
ID: $(HEADERS) $(SOURCES) $(LISP)
list='$(SOURCES) $(HEADERS)'; \
unique=`for i in $$list; do echo $$i; done | \
awk ' { files[$$0] = 1; } \
END { for (i in files) print i; }'`; \
here=`pwd` && cd $(srcdir) \
&& mkid -f$$here/ID $$unique $(LISP)
TAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) $(LISP)
tags=; \
here=`pwd`; \
list='$(SOURCES) $(HEADERS)'; \
unique=`for i in $$list; do echo $$i; done | \
awk ' { files[$$0] = 1; } \
END { for (i in files) print i; }'`; \
test -z "$(ETAGS_ARGS)$$unique$(LISP)$$tags" \
|| (cd $(srcdir) && etags $(ETAGS_ARGS) $$tags $$unique $(LISP) -o $$here/TAGS)
mostlyclean-tags:
clean-tags:
distclean-tags:
-rm -f TAGS ID
maintainer-clean-tags:
distdir = $(top_builddir)/$(PACKAGE)-$(VERSION)/$(subdir)
subdir = common/lib/utils
distdir: $(DISTFILES)
here=`cd $(top_builddir) && pwd`; \
top_distdir=`cd $(top_distdir) && pwd`; \
distdir=`cd $(distdir) && pwd`; \
cd $(top_srcdir) \
&& $(AUTOMAKE) --include-deps --build-dir=$$here --srcdir-name=$(top_srcdir) --output-dir=$$top_distdir --foreign common/lib/utils/Makefile
@for file in $(DISTFILES); do \
d=$(srcdir); \
if test -d $$d/$$file; then \
cp -pr $$/$$file $(distdir)/$$file; \
else \
test -f $(distdir)/$$file \
|| ln $$d/$$file $(distdir)/$$file 2> /dev/null \
|| cp -p $$d/$$file $(distdir)/$$file || :; \
fi; \
done
DEPS_MAGIC := $(shell mkdir .deps > /dev/null 2>&1 || :)
-include $(DEP_FILES)
mostlyclean-depend:
clean-depend:
distclean-depend:
-rm -rf .deps
maintainer-clean-depend:
%.o: %.c
@echo '$(COMPILE) -c $<'; \
$(COMPILE) -Wp,-MD,.deps/$(*F).pp -c $<
@-cp .deps/$(*F).pp .deps/$(*F).P; \
tr ' ' '\012' < .deps/$(*F).pp \
| sed -e 's/^\\$$//' -e '/^$$/ d' -e '/:$$/ d' -e 's/$$/ :/' \
>> .deps/$(*F).P; \
rm .deps/$(*F).pp
%.lo: %.c
@echo '$(LTCOMPILE) -c $<'; \
$(LTCOMPILE) -Wp,-MD,.deps/$(*F).pp -c $<
@-sed -e 's/^\([^:]*\)\.o[ ]*:/\1.lo \1.o :/' \
< .deps/$(*F).pp > .deps/$(*F).P; \
tr ' ' '\012' < .deps/$(*F).pp \
| sed -e 's/^\\$$//' -e '/^$$/ d' -e '/:$$/ d' -e 's/$$/ :/' \
>> .deps/$(*F).P; \
rm -f .deps/$(*F).pp
%.o: %.C
@echo '$(CXXCOMPILE) -c $<'; \
$(CXXCOMPILE) -Wp,-MD,.deps/$(*F).pp -c $<
@-cp .deps/$(*F).pp .deps/$(*F).P; \
tr ' ' '\012' < .deps/$(*F).pp \
| sed -e 's/^\\$$//' -e '/^$$/ d' -e '/:$$/ d' -e 's/$$/ :/' \
>> .deps/$(*F).P; \
rm .deps/$(*F).pp
%.lo: %.C
@echo '$(LTCXXCOMPILE) -c $<'; \
$(LTCXXCOMPILE) -Wp,-MD,.deps/$(*F).pp -c $<
@-sed -e 's/^\([^:]*\)\.o[ ]*:/\1.lo \1.o :/' \
< .deps/$(*F).pp > .deps/$(*F).P; \
tr ' ' '\012' < .deps/$(*F).pp \
| sed -e 's/^\\$$//' -e '/^$$/ d' -e '/:$$/ d' -e 's/$$/ :/' \
>> .deps/$(*F).P; \
rm -f .deps/$(*F).pp
info-am:
info: info-am
dvi-am:
dvi: dvi-am
check-am: all-am
check: check-am
installcheck-am:
installcheck: installcheck-am
install-exec-am:
install-exec: install-exec-am
install-data-am:
install-data: install-data-am
install-am: all-am
@$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am
install: install-am
uninstall-am:
uninstall: uninstall-am
all-am: Makefile $(LIBRARIES)
all-redirect: all-am
install-strip:
$(MAKE) $(AM_MAKEFLAGS) AM_INSTALL_PROGRAM_FLAGS=-s install
installdirs:
mostlyclean-generic:
clean-generic:
distclean-generic:
-rm -f Makefile $(CONFIG_CLEAN_FILES)
-rm -f config.cache config.log stamp-h stamp-h[0-9]*
maintainer-clean-generic:
mostlyclean-am: mostlyclean-noinstLIBRARIES mostlyclean-compile \
mostlyclean-tags mostlyclean-depend mostlyclean-generic
mostlyclean: mostlyclean-am
clean-am: clean-noinstLIBRARIES clean-compile clean-tags clean-depend \
clean-generic mostlyclean-am
clean: clean-am
distclean-am: distclean-noinstLIBRARIES distclean-compile \
distclean-tags distclean-depend distclean-generic \
clean-am
distclean: distclean-am
maintainer-clean-am: maintainer-clean-noinstLIBRARIES \
maintainer-clean-compile maintainer-clean-tags \
maintainer-clean-depend maintainer-clean-generic \
distclean-am
@echo "This command is intended for maintainers to use;"
@echo "it deletes files that may require special tools to rebuild."
maintainer-clean: maintainer-clean-am
.PHONY: mostlyclean-noinstLIBRARIES distclean-noinstLIBRARIES \
clean-noinstLIBRARIES maintainer-clean-noinstLIBRARIES \
mostlyclean-compile distclean-compile clean-compile \
maintainer-clean-compile tags mostlyclean-tags distclean-tags \
clean-tags maintainer-clean-tags distdir mostlyclean-depend \
distclean-depend clean-depend maintainer-clean-depend info-am info \
dvi-am dvi check check-am installcheck-am installcheck install-exec-am \
install-exec install-data-am install-data install-am install \
uninstall-am uninstall all-redirect all-am all installdirs \
mostlyclean-generic distclean-generic clean-generic \
maintainer-clean-generic clean mostlyclean distclean maintainer-clean
# Tell versions [3.59,3.63) of GNU make to not export all variables.
# Otherwise a system limit (for SysV at least) may be exceeded.
.NOEXPORT:

80
common/lib/utils/beam.C Normal file
View File

@@ -0,0 +1,80 @@
/*
* PVVMUD a 3D MUD
* Copyright (C) 1998-1999 Programvareverkstedet (pvv@pvv.org)
*
* 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.
*
* 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
*
*/
#include "pvvmud.H"
#include "beam.H"
CBeam::CBeam(){
}
CBeam::CBeam(const CVector & point,const CVector & direction){
m_point = point;
m_direction = direction;
}
CBeam::CBeam(const CVertex & point,const CVector & direction){
m_point = CVector(point.getX(),point.getY(),point.getZ());
m_direction = direction;
}
CBeam::CBeam(const CPosition & point,const CVector & direction){
m_point = CVector(point.getX(),point.getY(),point.getZ());
m_direction = direction;
}
const CVector & CBeam::getPoint() const{
return m_point;
}
const CVector & CBeam::getDirection() const{
return m_direction;
}
CBeam CBeam::operator+ (const CPosition& position) const{
CBeam result;
result = *this;
CVector pos(position.getX(),position.getY(),position.getZ());
result.m_point += pos;
return result;
}
void CBeam::transform(const CMatrix & transformation){
CVector p2 = m_point + m_direction;
m_point.transform(transformation);
p2.transform(transformation);
m_direction = p2 - m_point;
}
///////////////////////////////////////////////////////////////////////////////
// CBeam::intersect
// Info : Check intersection between beam and a bBox
// Return : Return true if beam intersect with bBox
// Implementation: HACK only check if point inside in XY plane
///////////////////////////////////////////////////////////////////////////////
int CBeam::intersect(const CBBox & bBox) const {
// cdebug << "CBeam::intersect : Hack impl.\n";
return bBox.insideXY(m_point);
}
ostream& operator<<(ostream&s,const CBeam& b){
return s << "( P: " << b.getPoint() << ", D: " << b.getDirection() << " )";
}

View File

@@ -0,0 +1,114 @@
/*
* PVVMUD a 3D MUD
* Copyright (C) 1998-1999 Programvareverkstedet (pvv@pvv.org)
*
* 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.
*
* 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
*
*/
#include "commandparser.H"
CCommandParser::CCommand::CCommand(string & commandString,CommandFunc_t commandFunc){
m_commandString = commandString;
m_commandFunc = commandFunc;
}
string & CCommandParser::CCommand::getCommandString(){
return m_commandString;
}
void CCommandParser::CCommand::executeCommand(argv_t & argv,
CCommandParser * parser)
{
(parser->*m_commandFunc)(argv);
}
CCommandParser::CCommandParser(){
m_commandPrefix = '/';
}
///////////////////////////////////////////////////////////////////////////////
// parseCommand
// Parse commands on the form "/command", "/command arg...", "Message..."
// Side effects on commandString:
// Any command with arguments will be null terminated before arguments
///////////////////////////////////////////////////////////////////////////////
void CCommandParser::parseCommand(const string & commandString){
string command = commandString;
if (command[0] != m_commandPrefix){ // Is this a message?
commandChat(command);
} else { // No it is a command
command.erase(0,1); // Don't need leading '/'
argv_t argv;
createArgv(command,argv);
for (int index = 0; index < m_commandList.size(); index++){
if (m_commandList[index].getCommandString() == argv[0]){
m_commandList[index].executeCommand(argv,this);
return;
}
}
commandUnknown(commandString);
}
}
void CCommandParser::setCommandPrefix(char commandPrefix){
m_commandPrefix = commandPrefix;
}
///////////////////////////////////////////////////////////////////////////////
// createArgv
// Convert string to table of strings
///////////////////////////////////////////////////////////////////////////////
void CCommandParser::createArgv(string & argString, argv_t & argv){
string::size_type pos;
// Remove all double spaces
while ((pos = argString.find(" ")) != string::npos)
argString.replace(pos,2," ");
// Create argv
string::size_type last = 0;
string::size_type next;
while ((next = argString.find(" ",last)) != string::npos) {
argv.push_back(string(argString,last,next-last));
last = next + 1;
}
next = argString.size();
argv.push_back(string(argString,last,next));
}
///////////////////////////////////////////////////////////////////////////////
// addCommand
///////////////////////////////////////////////////////////////////////////////
void CCommandParser::addCommand(string commandString,
CommandFunc_t commandFunc)
{
m_commandList.push_back( CCommand(commandString,commandFunc));
}
void CCommandParser::commandChat(const string & chatMessage){
commandUnknown(chatMessage);
}
void CCommandParser::commandUnknown(const string & commandString){
}

View File

@@ -0,0 +1,64 @@
/*
* PVVMUD a 3D MUD
* Copyright (C) 1998-1999 Programvareverkstedet (pvv@pvv.org)
*
* 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.
*
* 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
*
*/
#include <stdlib.h>
#include "mudtypes.h"
#include "crossindex.H"
CCrossIndexItem::CCrossIndexItem(int indexA,int indexB) {
next = NULL;
this->indexA = indexA;
this->indexB = indexB;
}
CCrossIndexItem * CCrossIndex::add(int indexA,int indexB){
CCrossIndexItem *newItem = new CCrossIndexItem(indexA,indexB);
newItem->setNext(first);
first=newItem;
return newItem;
}
int CCrossIndex::getA(int indexB){
CCrossIndexItem * currItem;
currItem = first;
while (currItem != NULL) {
if (currItem->getIndexB() == indexB) return currItem->getIndexA();
currItem = currItem->getNext();
}
return -1;
}
int CCrossIndex::getB(int indexA){
CCrossIndexItem * currItem;
currItem = first;
while (currItem != NULL) {
if (currItem->getIndexA() == indexA) return currItem->getIndexB();
currItem = currItem->getNext();
}
return -1;
}

View File

@@ -0,0 +1,82 @@
/*
* PVVMUD a 3D MUD
* Copyright (C) 1998-1999 Programvareverkstedet (pvv@pvv.org)
*
* 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.
*
* 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
*
*/
#include "pvvmud.H"
#include <stdlib.h>
#include <iostream.h>
#include "doublearray.H"
CDoubleArray::CDoubleArray(){
m_size = 0;
m_num = 0;
m_array = NULL;
}
CDoubleArray::~CDoubleArray(){
if (m_array != NULL) free(m_array);
}
int CDoubleArray::add( double num ){
if (m_num >= m_size){
if (m_array == NULL){
m_array = (double*)malloc(sizeof(double)*4);
m_size = 4;
} else {
m_array = (double*)realloc(m_array,sizeof(double)*m_size*2);
m_size *=2;
}
}
m_array[m_num] = num;
return m_num++;
}
int CDoubleArray::add( CDoubleArray * doubleArray ){
int ii,tmp;
int num = doubleArray->getNumElements();
for (ii = 0; ii < num; ii ++){
tmp = add(doubleArray->get(ii));
}
return tmp;
}
int CDoubleArray::insert( double num ){
cdebug << "WARNING: CDoubleArray::insert NOT IMPLEMENTED!\n";
return 0;
}
double CDoubleArray::get( int index ) const{
return m_array[index];
}
int CDoubleArray::getNumElements() const{
return m_num;
}
void CDoubleArray::deleteAll(){
m_num = 0;
}
ostream& operator<<(ostream&s,const CDoubleArray& d) {
int index;
s << "[ ";
for (index = 0; index < d.getNumElements(); index ++)
s << d.get(index) << " ";
return s << "]";
}

1050
common/lib/utils/getopt.c Normal file

File diff suppressed because it is too large Load Diff

131
common/lib/utils/getopt.h Normal file
View File

@@ -0,0 +1,131 @@
/* Declarations for getopt.
Copyright (C) 1989,90,91,92,93,94,96,97 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public License as
published by the Free Software Foundation; either version 2 of the
License, or (at your option) any later version.
The GNU C Library 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
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with the GNU C Library; see the file COPYING.LIB. If not,
write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA. */
#ifndef _GETOPT_H
#define _GETOPT_H 1
#ifdef __cplusplus
extern "C" {
#endif
/* For communication from `getopt' to the caller.
When `getopt' finds an option that takes an argument,
the argument value is returned here.
Also, when `ordering' is RETURN_IN_ORDER,
each non-option ARGV-element is returned here. */
extern char *optarg;
/* Index in ARGV of the next element to be scanned.
This is used for communication to and from the caller
and for communication between successive calls to `getopt'.
On entry to `getopt', zero means this is the first call; initialize.
When `getopt' returns -1, this is the index of the first of the
non-option elements that the caller should itself scan.
Otherwise, `optind' communicates from one call to the next
how much of ARGV has been scanned so far. */
extern int optind;
/* Callers store zero here to inhibit the error message `getopt' prints
for unrecognized options. */
extern int opterr;
/* Set to an option character which was unrecognized. */
extern int optopt;
/* Describe the long-named options requested by the application.
The LONG_OPTIONS argument to getopt_long or getopt_long_only is a vector
of `struct option' terminated by an element containing a name which is
zero.
The field `has_arg' is:
no_argument (or 0) if the option does not take an argument,
required_argument (or 1) if the option requires an argument,
optional_argument (or 2) if the option takes an optional argument.
If the field `flag' is not NULL, it points to a variable that is set
to the value given in the field `val' when the option is found, but
left unchanged if the option is not found.
To have a long-named option do something other than set an `int' to
a compiled-in constant, such as set a value from `optarg', set the
option's `flag' field to zero and its `val' field to a nonzero
value (the equivalent single-letter option character, if there is
one). For long options that have a zero `flag' field, `getopt'
returns the contents of the `val' field. */
struct option
{
#if defined (__STDC__) && __STDC__
const char *name;
#else
char *name;
#endif
/* has_arg can't be an enum because some compilers complain about
type mismatches in all the code that assumes it is an int. */
int has_arg;
int *flag;
int val;
};
/* Names for the values of the `has_arg' field of `struct option'. */
#define no_argument 0
#define required_argument 1
#define optional_argument 2
#if defined (__STDC__) && __STDC__
#ifdef __GNU_LIBRARY__
/* Many other libraries have conflicting prototypes for getopt, with
differences in the consts, in stdlib.h. To avoid compilation
errors, only prototype getopt for the GNU C library. */
extern int getopt (int argc, char *const *argv, const char *shortopts);
#else /* not __GNU_LIBRARY__ */
extern int getopt ();
#endif /* __GNU_LIBRARY__ */
extern int getopt_long (int argc, char *const *argv, const char *shortopts,
const struct option *longopts, int *longind);
extern int getopt_long_only (int argc, char *const *argv,
const char *shortopts,
const struct option *longopts, int *longind);
/* Internal only. Users should not call this directly. */
extern int _getopt_internal (int argc, char *const *argv,
const char *shortopts,
const struct option *longopts, int *longind,
int long_only);
#else /* not __STDC__ */
extern int getopt ();
extern int getopt_long ();
extern int getopt_long_only ();
extern int _getopt_internal ();
#endif /* __STDC__ */
#ifdef __cplusplus
}
#endif
#endif /* _GETOPT_H */

187
common/lib/utils/getopt1.c Normal file
View File

@@ -0,0 +1,187 @@
/* getopt_long and getopt_long_only entry points for GNU getopt.
Copyright (C) 1987,88,89,90,91,92,93,94,96,97 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public License as
published by the Free Software Foundation; either version 2 of the
License, or (at your option) any later version.
The GNU C Library 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
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with the GNU C Library; see the file COPYING.LIB. If not,
write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA. */
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include "getopt.h"
#if !defined (__STDC__) || !__STDC__
/* This is a separate conditional since some stdc systems
reject `defined (const)'. */
#ifndef const
#define const
#endif
#endif
#include <stdio.h>
/* Comment out all this code if we are using the GNU C Library, and are not
actually compiling the library itself. This code is part of the GNU C
Library, but also included in many other GNU distributions. Compiling
and linking in this code is a waste when using the GNU C library
(especially if it is a shared library). Rather than having every GNU
program understand `configure --with-gnu-libc' and omit the object files,
it is simpler to just do this in the source for each such file. */
#define GETOPT_INTERFACE_VERSION 2
#if !defined (_LIBC) && defined (__GLIBC__) && __GLIBC__ >= 2
#include <gnu-versions.h>
#if _GNU_GETOPT_INTERFACE_VERSION == GETOPT_INTERFACE_VERSION
#define ELIDE_CODE
#endif
#endif
#ifndef ELIDE_CODE
/* This needs to come after some library #include
to get __GNU_LIBRARY__ defined. */
#ifdef __GNU_LIBRARY__
#include <stdlib.h>
#endif
#ifndef NULL
#define NULL 0
#endif
int
getopt_long (argc, argv, options, long_options, opt_index)
int argc;
char *const *argv;
const char *options;
const struct option *long_options;
int *opt_index;
{
return _getopt_internal (argc, argv, options, long_options, opt_index, 0);
}
/* Like getopt_long, but '-' as well as '--' can indicate a long option.
If an option that starts with '-' (not '--') doesn't match a long option,
but does match a short option, it is parsed as a short option
instead. */
int
getopt_long_only (argc, argv, options, long_options, opt_index)
int argc;
char *const *argv;
const char *options;
const struct option *long_options;
int *opt_index;
{
return _getopt_internal (argc, argv, options, long_options, opt_index, 1);
}
#endif /* Not ELIDE_CODE. */
#ifdef TEST
#include <stdio.h>
int
main (argc, argv)
int argc;
char **argv;
{
int c;
int digit_optind = 0;
while (1)
{
int this_option_optind = optind ? optind : 1;
int option_index = 0;
static struct option long_options[] =
{
{"add", 1, 0, 0},
{"append", 0, 0, 0},
{"delete", 1, 0, 0},
{"verbose", 0, 0, 0},
{"create", 0, 0, 0},
{"file", 1, 0, 0},
{0, 0, 0, 0}
};
c = getopt_long (argc, argv, "abc:d:0123456789",
long_options, &option_index);
if (c == -1)
break;
switch (c)
{
case 0:
printf ("option %s", long_options[option_index].name);
if (optarg)
printf (" with arg %s", optarg);
printf ("\n");
break;
case '0':
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
case '8':
case '9':
if (digit_optind != 0 && digit_optind != this_option_optind)
printf ("digits occur in two different argv-elements.\n");
digit_optind = this_option_optind;
printf ("option %c\n", c);
break;
case 'a':
printf ("option a\n");
break;
case 'b':
printf ("option b\n");
break;
case 'c':
printf ("option c with value `%s'\n", optarg);
break;
case 'd':
printf ("option d with value `%s'\n", optarg);
break;
case '?':
break;
default:
printf ("?? getopt returned character code 0%o ??\n", c);
}
}
if (optind < argc)
{
printf ("non-option ARGV-elements: ");
while (optind < argc)
printf ("%s ", argv[optind++]);
printf ("\n");
}
exit (0);
}
#endif /* TEST */

113
common/lib/utils/intarray.C Normal file
View File

@@ -0,0 +1,113 @@
/*
* PVVMUD a 3D MUD
* Copyright (C) 1998-1999 Programvareverkstedet (pvv@pvv.org)
*
* 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.
*
* 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
*
*/
#include "pvvmud.H"
#include <stdlib.h>
#include "intarray.H"
#include "exception.H"
CIntArray::CIntArray(){
m_size = 0;
m_num = 0;
m_array = NULL;
}
CIntArray::CIntArray(int size){
if (size > 0){
m_size = size;
m_num = 0;
m_array = (int*)malloc(m_size*sizeof(int));
} else {
m_size = 0;
m_num = 0;
m_array = NULL;
}
}
CIntArray::CIntArray(const CIntArray & array){
int ii;
m_size = array.m_num;
m_num = array.m_num;
m_array = (int*)malloc(m_size*sizeof(int));
for (ii = 0; ii < m_num; ii++) m_array[ii] = array.m_array[ii];
}
CIntArray::~CIntArray() {
if (m_array != NULL) free(m_array);
}
int CIntArray::add(int num){
if (m_num >= m_size || m_array == NULL) {
if (m_size <= 0) m_size = 16;
else m_size = m_size*2;
m_array = (int*)realloc(m_array,m_size*sizeof(int));
}
if (m_array != NULL) m_array[m_num] = num;
return m_num++;
}
int CIntArray::set(int index, int num){
if ((index < m_size) && (index >= 0)){
m_array[index] = num;
if (m_num <= index) m_num = index+1;
return true;
}
return false;
}
int CIntArray::get( int index ) const{
if (index < 0 || index >= m_num || m_array == NULL)
throw new CException("OutOfBound exception");
return m_array[index];
}
int CIntArray::getNumElements() const{
return m_num;
}
int CIntArray::find(int value) const{
int index,num = getNumElements();
for (index = 0; index < num; index++){
if (get(index) == value) return index;
}
return -1;
}
CIntArray CIntArray::substracSet( const CIntArray & array ) const {
CIntArray result;
int index,num = getNumElements();
for (index = 0; index < num; index++){
int value = get(index);
if (array.find(value) == -1) result.add(value);
}
return result;
}
CIntArray CIntArray::unionSet( const CIntArray & array ) const {
CIntArray result;
int index,num = getNumElements();
for (index = 0; index < num; index++){
int value = get(index);
if (array.find(value) != -1) result.add(value);
}
return result;
}

View File

@@ -0,0 +1,73 @@
/*
* PVVMUD a 3D MUD
* Copyright (C) 1998-1999 Programvareverkstedet (pvv@pvv.org)
*
* 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.
*
* 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
*
*/
#include "pvvmud.H"
#include "keyframe.H"
CInterpolate::CInterpolate(){
}
void CInterpolate::addControlVector(CKeyFrame * keyFrame,
const ControlVector_t & controlVector)
{
for (int index = 0; index < controlVector.size(); index++){
keyFrame->addControlVector(controlVector[index]);
}
}
CVector CInterpolate::interpolate(double time, ControlVector_t * controlVector){
int size = (*controlVector).size();
if (size == 0) return CVector(0.0,0.0,0.0);
if (size == 1) return (*controlVector)[0];
int start = (int)floor((size-1) * time);
int stop = start + 1;
time = (size-1)*time-start;
return interpolate(start,time,controlVector);
}
CVector CInterpolate::interpolate(int start, double time,
ControlVector_t * controlVector)
{
return (*controlVector)[start]
+ ((*controlVector)[start+1]-(*controlVector)[start])*time;
}
CKeyFrame::CKeyFrame(CInterpolate * interpolate){
m_controlVector = new ControlVector_t();
m_interpolate = interpolate;
}
CKeyFrame::~CKeyFrame(){
delete m_controlVector;
delete m_interpolate;
}
void CKeyFrame::addControlVector(const CVector & vector){
m_controlVector->push_back(vector);
}
void CKeyFrame::addControlVector(const ControlVector_t & controlVector){
m_interpolate->addControlVector(this,controlVector);
}
CVector CKeyFrame::interpolate(double time){
return m_interpolate->interpolate(time, m_controlVector);
}

189
common/lib/utils/matrix.C Normal file
View File

@@ -0,0 +1,189 @@
/*
* PVVMUD a 3D MUD
* Copyright (C) 1998-1999 Programvareverkstedet (pvv@pvv.org)
*
* 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.
*
* 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
*
*/
#include "pvvmud.H"
#include <math.h>
#include "matrix.H"
#include "vector.H"
////////////////////////////////////////////////////////////////////////////////
//
// Matrix vector format
//
// m = | m0 m4 m8 m12 |
// | m1 m5 m9 m13 |
// | m2 m6 m10 m14 |
// | m3 m7 m11 m15 |
//
//
////////////////////////////////////////////////////////////////////////////////
CMatrix::CMatrix(){
loadIdentity();
}
CMatrix::CMatrix(const CMatrix & matrix){
int ii;
for (ii = 0; ii < 16; ii++) m_matrix[ii] = matrix.m_matrix[ii];
}
CMatrix::CMatrix(double m0, double m4, double m8, double m12,
double m1, double m5, double m9, double m13,
double m2, double m6, double m10, double m14,
double m3, double m7, double m11, double m15)
{
m_matrix[0] = m0;
m_matrix[1] = m1;
m_matrix[2] = m2;
m_matrix[3] = m3;
m_matrix[4] = m4;
m_matrix[5] = m5;
m_matrix[6] = m6;
m_matrix[7] = m7;
m_matrix[8] = m8;
m_matrix[9] = m9;
m_matrix[10] = m10;
m_matrix[11] = m11;
m_matrix[12] = m12;
m_matrix[13] = m13;
m_matrix[14] = m14;
m_matrix[15] = m15;
}
CMatrix::CMatrix(CVector & v0, CVector & v1, CVector & v2, CVector & v3){
m_matrix[0] = v0.getX();
m_matrix[1] = v0.getY();
m_matrix[2] = v0.getZ();
m_matrix[3] = 0.0;
m_matrix[4] = v1.getX();
m_matrix[5] = v1.getY();
m_matrix[6] = v1.getZ();
m_matrix[7] = 0.0;
m_matrix[8] = v2.getX();
m_matrix[9] = v2.getY();
m_matrix[10] = v2.getZ();
m_matrix[11] = 0.0;
m_matrix[12] = v3.getX();
m_matrix[13] = v3.getY();
m_matrix[14] = v3.getZ();
m_matrix[15] = 1.0;
}
double * CMatrix::getVector(){
return m_matrix;
}
void CMatrix::multiply(const CMatrix & matrix){
CMatrix Temp(*this);
int ii,jj,kk;
for (ii = 0; ii < 4; ii++){
for (jj = 0; jj < 4; jj ++){
double sum = 0;
for (kk = 0; kk < 4; kk++){
sum += Temp.m_matrix[ii+kk*4]*matrix.m_matrix[jj*4+kk];
}
m_matrix[ii+jj*4] = sum;
}
}
}
void CMatrix::loadIdentity(){
int i;
for (i = 0; i < 16; i++){
if ((i % 5) == 0) m_matrix[i] = 1.0;
else m_matrix[i] = 0.0;
}
//m_matrix[0] = m_matrix[5] = m_matrix[10] = m_matrix[15] = 0;
}
void CMatrix::rotate(const CDirection & direction){
rotate(direction.getHeading(),0.0,0.0,1.0);
rotate(direction.getRoll(),0.0,1.0,0.0);
rotate(direction.getPitch(),1.0,0.0,0.0);
}
void CMatrix::rotate(double angle,double xx,double yy,double zz){
CMatrix r;
double rad_ang = angle*PI/180;
double sina = sin(rad_ang);
double cosa = cos(rad_ang);
r.m_matrix[0] = xx*xx + cosa*(1-xx*xx);
r.m_matrix[1] = xx*yy*(1-cosa) + zz*sina;
r.m_matrix[2] = zz*xx*(1-cosa) - yy*sina;
r.m_matrix[3] = 0.0f;
r.m_matrix[4] = xx*yy*(1-cosa) - zz*sina;
r.m_matrix[5] = yy*yy + cosa*(1-yy*yy);
r.m_matrix[6] = yy*zz*(1-cosa) + xx*sina;
r.m_matrix[7] = 0.0f;
r.m_matrix[8] = zz*xx*(1-cosa) + yy*sina;
r.m_matrix[9] = yy*zz*(1-cosa) - xx*sina;
r.m_matrix[10]= zz*zz + cosa*(1-zz*zz);
r.m_matrix[11]= 0.0f;
r.m_matrix[12]= 0.0f;
r.m_matrix[13]= 0.0f;
r.m_matrix[14]= 0.0f;
r.m_matrix[15]= 1.0f;
multiply(r);
}
void CMatrix::translate(const CPosition & position){
CMatrix trans;
trans.m_matrix[12] = position.getX();
trans.m_matrix[13] = position.getY();
trans.m_matrix[14] = position.getZ();
multiply(trans);
}
void CMatrix::transpose(){
int ii,jj;
for (ii = 1; ii < 4; ii++){
for (jj = 0; jj < ii; jj ++){
double tmp = m_matrix[ii+jj*4];
m_matrix[ii+jj*4] = m_matrix[ii*4+jj];
m_matrix[ii*4+jj] = tmp;
}
}
}
CMatrix operator*(const CMatrix & m1, const CMatrix & m2){
CMatrix result(m1);
result.multiply(m2);
return result;
}
ostream& operator<<(ostream&s,const CMatrix& matrix) {
int ii;
double * m = ((CMatrix)matrix).getVector();
s << "[" << m[0];
for (ii = 1; ii < 16; ii++){
s << "," << m[ii];
}
return s << "]";
}

158
common/lib/utils/namedb.C Normal file
View File

@@ -0,0 +1,158 @@
/*
* PVVMUD a 3D MUD
* Copyright (C) 1998-1999 Programvareverkstedet (pvv@pvv.org)
*
* 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.
*
* 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
*
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "namedb.H"
#include "crossindex.H"
#include "exception.H"
CNameDBItem::CNameDBItem(int id,char *name) {
next=NULL;
this->id=id;
this->name=new char[strlen(name)+1];
strcpy(this->name,name);
}
int CNameDB::insert(char * name) {
CNameDBItem *newItem,*currItem,*nextItem;
if (first == NULL){
first = new CNameDBItem(++currentId,name);
return currentId;
}
currItem = NULL;
nextItem = first;
while ((nextItem != NULL) && (strcmp(nextItem->getName(),name)<=0)) {
currItem = nextItem;
nextItem = currItem->getNext();
}
if ((currItem != NULL) && (strcmp(currItem->getName(),name)==0))
return currItem->getId();
newItem = new CNameDBItem(++currentId,name);
newItem->setNext(nextItem);
if (currItem == NULL) first = newItem;
else currItem->setNext(newItem);
return currentId;
}
int CNameDB::add(int id, char * name) {
//NameDBItem_t *newItem,*currItem,*nextItem;
CNameDBItem *newItem;
newItem = new CNameDBItem(id,name);
if (currentId < id ) currentId = id;
newItem->setNext(first);
first = newItem;
return id;
}
char * CNameDB::findName(int id){
CNameDBItem * currItem;
currItem = first;
while (currItem != NULL){
if (currItem->getId() == id) return currItem->getName();
currItem = currItem->getNext();
}
return NULL;
}
int CNameDB::findId(char * name){
CNameDBItem * currItem;
currItem = first;
while (currItem != NULL){
if (strcmp(currItem->getName(),name) == 0) return currItem->getId();
currItem = currItem->getNext();
}
return -1;
}
void CNameDB::save(char *fileName){
FILE * ndbFile;
ndbFile = fopen(fileName,"w+");
if (ndbFile == NULL) throw new CException();
writeNDB(ndbFile);
fclose(ndbFile);
}
void CNameDB::load(char *fileName){
FILE * ndbFile;
ndbFile = fopen(fileName,"r");
if (ndbFile == NULL) throw new CException();
readNDB(ndbFile);
fclose(ndbFile);
}
void CNameDB::writeNDB(FILE * ndbfile){
CNameDBItem * currItem;
currItem = first;
while(currItem != NULL){
fprintf(ndbfile,"%i : %s\n",currItem->getId(),currItem->getName());
currItem = currItem->getNext();
}
}
void CNameDB::readNDB(FILE * ndbfile) {
char name[256];
int id;
while (fscanf(ndbfile,"%i : %255s\n",&id,name)==2 ){
add(id,name);
}
}
CCrossIndex * CNameDB::merge(CNameDB * mergeDB){
CCrossIndex * crossIndex;
CNameDBItem * mergeItem;
crossIndex = new CCrossIndex;
mergeItem = mergeDB->getFirst();
while (mergeItem != NULL){
crossIndex->add(insert(mergeItem->getName()),mergeItem->getId());
mergeItem = mergeItem->getNext();
}
return crossIndex;
}

View File

@@ -0,0 +1,99 @@
/*
* PVVMUD a 3D MUD
* Copyright (C) 1998-1999 Programvareverkstedet (pvv@pvv.org)
*
* 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.
*
* 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
*
*/
#include "pvvmud.H"
#include <stdlib.h>
#include <iostream.h>
#include "objectarray.H"
CObjectArray::CObjectArray(){
m_grow = -1;
m_size = 0;
m_num = 0;
m_array = NULL;
cdebug<< "WARNING: CObjectArray::CObjectArray FUNCTIONALITY NOT IMPLEMENTED!\n";
}
CObjectArray::CObjectArray(int size){
m_grow = 0;
m_size = size;
m_num = 0;
m_array = (CObject**)malloc(sizeof(CObject*)*size);
for (int ii = 0; ii < m_size; ii++) m_array[ii] = NULL;
}
CObjectArray::CObjectArray(int size,int grow){
m_grow = grow;
m_size = size;
m_num = 0;
m_array = (CObject**)malloc(sizeof(CObject*)*size);
for (int ii = 0; ii < m_size; ii++) m_array[ii] = NULL;
cdebug<< "WARNING: CObjectArray::CObjectArray FUNCTIONALITY NOT IMPLEMENTED!\n";
}
CObjectArray::~CObjectArray(){
if (m_array != NULL) free(m_array);
}
void CObjectArray::deleteList(){
m_num = 0;
}
void CObjectArray::deleteAll(){
while (m_num > 0){
m_num--;
delete m_array[m_num];
}
}
int CObjectArray::add(CObject * obj){
if (m_num < m_size){
int index = m_num++;
m_array[index] = obj;
return index;
} else {
cdebug << "WARNING: CObjectArray::add NOT IMPLEMENTED!\n";
}
}
void CObjectArray::insert(int index,CObject * obj){
cdebug << "WARNING: CObjectArray::insert NOT IMPLEMENTED!\n";
}
void CObjectArray::set(int index,CObject * obj){
m_array[index] = obj;
if (m_num <= index) m_num = index+1;
}
CObject* CObjectArray::getItem(int index){
return m_array[index];
}
void CObjectArray::remove(CObject * obj){
cdebug << "WARNING: CObjectArray::remove NOT IMPLEMENTED!\n";
}
void CObjectArray::remove(int index){
cdebug << "WARNING: CObjectArray::remove NOT IMPLEMENTED!\n";
}
int CObjectArray::getNumElements(){
return m_num;
}

353
common/lib/utils/option.C Normal file
View File

@@ -0,0 +1,353 @@
/*
* PVVMUD a 3D MUD
* Copyright (C) 1998-1999 Programvareverkstedet (pvv@pvv.org)
*
* 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.
*
* 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
*
*/
#include "pvvmud.H"
#include "option.H"
#ifdef _HAVE_GETOPT_LONG
#include <getopt.h>
#else
#include "getopt.h"
#endif // _HAVE_GETOPT_LONG
#include <iostream.h>
#include <string.h>
#include <stdlib.h>
char * COptionItem::m_typeString[] = {"string","integer","double"};
COptionItem::COptionItem(char * name, char abbreviation, char * strValue){
setName(name);
setAbbreviation(abbreviation);
setValue(strValue);
}
COptionItem::COptionItem(char * name, char abbreviation, int intValue){
setName(name);
setAbbreviation(abbreviation);
setValue(intValue);
}
COptionItem::COptionItem(char * name, char abbreviation, double doubleValue){
setName(name);
setAbbreviation(abbreviation);
setValue(doubleValue);
}
void COptionItem::setAbbreviation(char abbreviation){
m_abbreviation = abbreviation;
}
char COptionItem::getAbbreviation(){
return m_abbreviation;
}
void COptionItem::setValue(char * strValue){
m_type = STR_VALUE;
if (m_value.strValue != NULL) cdebug << "COptionItem::setValue(char * strValue) Posible memory leak!\n";
m_value.strValue = (char*)malloc(strlen(strValue)+1);
strcpy(m_value.strValue,strValue);
}
void COptionItem::setValue(int intValue){
m_type = INT_VALUE;
m_value.intValue = intValue;
}
void COptionItem::setValue(double doubleValue){
m_type = DOUBLE_VALUE;
m_value.doubleValue = doubleValue;
}
void COptionItem::updateValue(char * valueString){
switch (m_type){
case STR_VALUE: setValue(valueString); break;
case INT_VALUE: setValue(atoi(valueString)); break;
case DOUBLE_VALUE: setValue(atof(valueString)); break;
}
}
char * COptionItem::getString(){
if (m_type != STR_VALUE){
cdebug << "COptionItem " << getName() << " don't have string!\n";
return "Don't have string\n";
}
return m_value.strValue;
}
int COptionItem::getInt(){
if (m_type != INT_VALUE){
cdebug << "COptionItem " << getName() << " don't have int!\n";
return 0;
}
return m_value.intValue;
}
double COptionItem::getDouble(){
if (m_type != DOUBLE_VALUE){
cdebug << "COptionItem " << getName() << " don't have double!\n";
return 0.0;
}
return m_value.doubleValue;
}
void COptionItem::dump(){
cdebug << "Item: " << getName() << " Type: " << m_typeString[m_type]
<< " Abbreviation: " << getAbbreviation() << " Value: ";
switch (m_type){
case STR_VALUE:
cdebug << m_value.strValue;
break;
case INT_VALUE:
cdebug << m_value.intValue;
break;
case DOUBLE_VALUE:
cdebug << m_value.doubleValue;
break;
}
cdebug << "\n";
}
COption::COption(){
}
void COption::setValue(char * name, char abbreviation, char * strValue){
COptionItem * item = findOptionItem(name);
if (item == NULL){
item = new COptionItem(name,abbreviation,strValue);
addFirst(item);
} else {
item->setValue(strValue);
}
}
void COption::setValue(char * name, char abbreviation, int intValue){
COptionItem * item = findOptionItem(name);
if (item == NULL){
item = new COptionItem(name,abbreviation,intValue);
addFirst(item);
} else {
item->setValue(intValue);
}
}
void COption::setValue(char * name, char abbreviation, double doubleValue){
COptionItem * item = findOptionItem(name);
if (item == NULL){
item = new COptionItem(name,abbreviation,doubleValue);
addFirst(item);
} else {
item->setValue(doubleValue);
}
}
char * COption::getString(char * name){
COptionItem * item = findOptionItem(name);
if (item != NULL){
return item->getString();
} else {
cdebug << "COption::getString() : Unknown name " << name << "\n";
return "Unknown name\n";
}
}
int COption::getInt(char * name){
COptionItem * item = findOptionItem(name);
if (item != NULL){
return item->getInt();
} else {
cdebug << "COption::getInt() : Unknown name " << name << "\n";
return 0;
}
}
double COption::getDouble(char * name){
COptionItem * item = findOptionItem(name);
if (item != NULL){
return item->getDouble();
} else {
cdebug << "COption::getDouble() : Unknown name " << name << "\n";
return 0.0;
}
}
void COption::parseArguments(int argc, char * argv[]){
int maxNumItems = getNumItems();
// Alloc memory for optstring
int optStringMaxLength = maxNumItems*2+sizeof(char);
char * optString =(char*)malloc(sizeof(char)*optStringMaxLength);
memset(optString,0,sizeof(char)*optStringMaxLength);
char* optStringPtr = optString;
// Alloc memory for longopt structs
struct option * longOpts =
(struct option*)malloc(sizeof(struct option)*(maxNumItems+1));
memset(longOpts,0,sizeof(struct option)*(maxNumItems+1));
struct option * longOptsPtr = longOpts;
// Build longOpts array and optString
CObjectListItem * item = getFirst();
while (item != NULL){
COptionItem * optionItem = (COptionItem*)item->getObject();
if (optionItem->getName() != NULL){
longOptsPtr->name = optionItem->getName();
// TODO: Incoude test for required arguemnt, no argument
// or optional argument
longOptsPtr->has_arg = required_argument;
longOptsPtr->flag = NULL; // getopt_long return val
longOptsPtr->val = 0;
longOptsPtr++;
}
if (optionItem->getAbbreviation() != '\0'){
*optStringPtr++ = optionItem->getAbbreviation();
// TODO: Include test if option is needed or optional.
// Put ':' in optString if needed and '::' if optional.
*optStringPtr++ = ':';
}
item = item->getNext();
}
// Optionure getopt_long
// opterr = 0; // Turn off printing of error messages to stderr
int c,optionIndex;
while ((c = getopt_long(argc,argv,optString,
longOpts,&optionIndex)) != EOF){
switch (c){
case 0: // Long option
cdebug << "Long option " << longOpts[optionIndex].name;
if (optarg){
cdebug << " with arg " << optarg;
updateName(longOpts[optionIndex].name,optarg);
}
cdebug << "\n";
break;
case ':': // Missing parameter
// cdebug << "WARNING: Option '" << optarg << "' missing parameter!\n";
break;
case '?': // Unknown option
// cdebug << "WARNING: Unknown option '" << argv[optind] <<"'\n";
break;
default: // Option char
cdebug << "Option " << (char)c;
if (optarg){
cdebug << " with value " << optarg;
updateAbbreviation(c,optarg);
}
cdebug << "\n";
break;
}
}
// Free memory
free(optString);
free(longOpts);
}
void COption::loadOption(char * fileName){
FILE * file = fopen(fileName,"rt");
if (file != NULL){
loadOption(file);
fclose(file);
} else {
cdebug << "Failed to load optionuration file : " << fileName << "\n";
}
}
#define MAX_LINELENGTH 1024
int getLine(FILE * file, char * line, int length){
int index,ch;
do {
for (index = 0; (index < (length-1)) && ((ch = fgetc(file)) != EOF ) && (ch != '\n') && (ch != '#'); index++)
line[index] = ch;
line[index] = '\0';
if (ch == '#') while (((ch = fgetc(file)) != EOF) && (ch != '\n'));
} while ( (index == 0) && (ch != EOF) );
return index;
}
void COption::loadOption(FILE * file){
char line[MAX_LINELENGTH];
while (getLine(file,line,MAX_LINELENGTH) > 0){
char * chVal = strchr(line,'=');
if (chVal != NULL){
*chVal = '\0'; chVal++; // Cut string in two pices
updateName(line,chVal);
}
// cdebug << "Line: " << line << "\n";
}
}
void COption::updateName(const char * name, char * valueString){
COptionItem * optionItem = findOptionItem(name);
if (optionItem != NULL){
optionItem->updateValue(valueString);
}
}
void COption::updateAbbreviation(char abbreviation, char * valueString){
COptionItem * optionItem = findOptionItemByAbbreviation(abbreviation);
if (optionItem != NULL){
optionItem->updateValue(valueString);
}
}
void COption::dump(){
CObjectListItem * item = getFirst();
while (item != NULL){
COptionItem * optionItem = (COptionItem*)item->getObject();
optionItem->dump();
item = item->getNext();
}
}
COptionItem * COption::findOptionItem(const char * name){
CObjectListItem * item = getFirst();
while (item != NULL){
COptionItem * optionItem = (COptionItem*)item->getObject();
if ((optionItem->getName() != NULL) && (strcmp(name,optionItem->getName())) == 0){
return optionItem;
}
item = item->getNext();
}
return NULL;
}
COptionItem * COption::findOptionItemByAbbreviation(char abbreviation){
CObjectListItem * item = getFirst();
while (item != NULL){
COptionItem * optionItem = (COptionItem*)item->getObject();
if (abbreviation == optionItem->getAbbreviation()){
return optionItem;
}
item = item->getNext();
}
return NULL;
}

111
common/lib/utils/pingpong.C Normal file
View File

@@ -0,0 +1,111 @@
/*
* PVVMUD a 3D MUD
* Copyright (C) 1998-1999 Programvareverkstedet (pvv@pvv.org)
*
* 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.
*
* 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
*
*/
#include <algorithm>
#include "pvvmud.H"
#include "pingpong.H"
CPingPong::CPingPong(BYTE maxPing){
m_currPing = 0;
m_numPing = 0;
m_maxPing = maxPing;
m_pingPong = (pingPong_t*)malloc(m_maxPing*sizeof(pingPong_t));
for (int index = 0; index < m_maxPing; index++)
m_pingPong[index].state = PS_NOTUSED;
m_firstPing = TRUE;
}
CPingPong::~CPingPong(){
free(m_pingPong);
}
delta_t CPingPong::getDeltaVector(DWORD * deltaTime){
delta_t delta(m_numPing);
for (int index = 0; index < m_numPing; index++){
delta[index] = m_pingPong[index].reciveTime
- m_pingPong[index].sendTime;
}
sort(delta.begin(),delta.end());
*deltaTime = delta[m_numPing/2];
return delta;
}
BYTE CPingPong::sendPing(DWORD sendTime){
BYTE currPing = m_currPing;
m_currPing++;
if (m_numPing < m_currPing) m_numPing = m_currPing;
if (m_currPing >= m_maxPing) m_currPing = 0;
m_pingPong[currPing].sendTime = sendTime;
m_pingPong[currPing].state = PS_WAIT;
return currPing;
}
long CPingPong::recivePong(DWORD reciveTime, BYTE sequenceNumber,
DWORD serverTime)
{
m_pingPong[sequenceNumber].reciveTime = reciveTime;
m_pingPong[sequenceNumber].serverTime = serverTime;
m_pingPong[sequenceNumber].state = PS_OK;
DWORD sendTime = m_pingPong[sequenceNumber].sendTime;
DWORD timeDelta = reciveTime - sendTime;
if (timeDelta > 10000){
m_pingPong[sequenceNumber].state = PS_BAD;
}
DWORD deltaTime;
delta_t delta = getDeltaVector(&deltaTime);
long timediff = sendTime - (serverTime + deltaTime/2);
if (m_firstPing){
m_firstPing = FALSE;
return timediff;
}
return timediff/2;
}
ostream& operator<<(ostream&s,CPingPong&p){
s << (int)p.m_numPing << "/" << (int)p.m_maxPing << " :";
DWORD deltaTime;
delta_t delta = p.getDeltaVector(&deltaTime);
for (int index = 0; index < p.m_numPing; index++){
s << " " << delta[index];
}
s << " : " << deltaTime/2;
return s;
}

74
common/lib/utils/plane.C Normal file
View File

@@ -0,0 +1,74 @@
/*
* PVVMUD a 3D MUD
* Copyright (C) 1998-1999 Programvareverkstedet (pvv@pvv.org)
*
* 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.
*
* 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
*
*/
#include "pvvmud.H"
#include "plane.H"
CPlane::CPlane(){
m_a = m_b = m_c = m_d = 0.0;
}
CPlane::CPlane(const CVector & point,const CVector & normal){
m_a = normal.getX();
m_b = normal.getY();
m_c = normal.getZ();
m_d = -(m_a*point.getX()+m_b*point.getY()+m_c*point.getZ());
// Normalize plane
double k = 1/sqrt(m_a*m_a+m_b*m_b+m_c*m_c);
m_a *= k; m_b *= k; m_c *= k; m_d *= k;
}
CPlane::CPlane(const CVertex & point,const CVector & normal){
CVector vector(point);
*this = CPlane(vector,normal);
}
CPlane::CPlane(const CVertex & v1,const CVertex & v2,const CVertex & v3){
CVector edge = v2-v1;
*this = CPlane(v1,edge.cross(v3-v2));
}
double CPlane::distance(const CVector & position){
return (m_a*position.getX()+m_b*position.getY()+m_c*position.getZ()+m_d);
}
double CPlane::getA() const {
return m_a;
}
double CPlane::getB() const {
return m_b;
}
double CPlane::getC() const {
return m_c;
}
double CPlane::getD() const {
return m_d;
}
ostream& operator<<(ostream&s,const CPlane& p){
return s << "(" << p.getA() << "," << p.getB() << ","
<< p.getC() << "," << p.getD() << ")";
}

156
common/lib/utils/spline.C Normal file
View File

@@ -0,0 +1,156 @@
/*
* PVVMUD a 3D MUD
* Copyright (C) 1998-1999 Programvareverkstedet (pvv@pvv.org)
*
* 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.
*
* 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
*
*/
#include "pvvmud.H"
#include "spline.H"
////////////////////////////////////////////////////////////////////////////////
//
// CSpline
//
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
// Constructor
CSpline::CSpline(CMatrix * basis){
m_basis = basis;
m_basis->transpose();
}
////////////////////////////////////////////////////////////////////////////////
// interpolate
CVector CSpline::interpolate(double time, ControlVector_t * controlVector){
int size = (*controlVector).size();
if (size < 4) return CVector(0.0,0.0,0.0);
double numSeg = floor(size/4);
double seg = floor(numSeg*time) ;
if (seg == numSeg) seg--;
int start = (int)seg*4;
time = time*numSeg - seg;
CMatrix control((*controlVector)[start],(*controlVector)[start+1],
(*controlVector)[start+2],(*controlVector)[start+3]);
return interpolate(time,control);
}
////////////////////////////////////////////////////////////////////////////////
// interpolate
CVector CSpline::interpolate(double time, CMatrix & control){
CMatrix coefficients = control*(*m_basis);
CVector u(time*time*time,time*time,time,1);
return coefficients*u;
}
////////////////////////////////////////////////////////////////////////////////
//
// CCatmulRom
//
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
// Constructor
CCatmullRom::CCatmullRom(double s)
:CSpline(new CMatrix( -s, 2.0-s, s-2.0, s,
2.0*s, s-3.0, 3.0-2.0*s, -s,
-s, 0.0, s, 0.0,
0.0, 1.0, 0.0, 0.0))
{
}
////////////////////////////////////////////////////////////////////////////////
// addControlVector
void CCatmullRom::addControlVector(CKeyFrame * keyFrame,
const ControlVector_t & controlVector)
{
for (int index = 0; index < (controlVector.size()-3); index++){
keyFrame->addControlVector(controlVector[index]);
keyFrame->addControlVector(controlVector[index+1]);
keyFrame->addControlVector(controlVector[index+2]);
keyFrame->addControlVector(controlVector[index+3]);
}
}
////////////////////////////////////////////////////////////////////////////////
//
// Bezier
//
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
// Constructor
CBezier::CBezier():CSpline(&m_bezier){
}
////////////////////////////////////////////////////////////////////////////////
// addControlVector
void CBezier::addControlVector(CKeyFrame * keyFrame,
const ControlVector_t & controlVector)
{
for (int index = 0; index < ((controlVector.size()-4)/3 +1); index++){
keyFrame->addControlVector(controlVector[index*3]);
keyFrame->addControlVector(controlVector[index*3+1]);
keyFrame->addControlVector(controlVector[index*3+2]);
keyFrame->addControlVector(controlVector[index*3+3]);
}
}
////////////////////////////////////////////////////////////////////////////////
// static basis
CMatrix CBezier::m_bezier( -1.0, 3.0, -3.0, 1.0,
3.0, -6.0, 3.0, 0.0,
-3.0, 3.0, 0.0, 0.0,
1.0, 0.0, 0.0, 0.0);
////////////////////////////////////////////////////////////////////////////////
//
// Hermite
//
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
// Constructor
CHermite::CHermite():CSpline(&m_hermite){
}
////////////////////////////////////////////////////////////////////////////////
// addControlVector
void CHermite::addControlVector(CKeyFrame * keyFrame,
const ControlVector_t & controlVector)
{
for (int index = 0; index < ((controlVector.size()-4)/2 +1); index++){
keyFrame->addControlVector(controlVector[index*2]);
keyFrame->addControlVector(controlVector[index*2+2]);
keyFrame->addControlVector(controlVector[index*2+1]);
keyFrame->addControlVector(controlVector[index*2+3]);
}
}
////////////////////////////////////////////////////////////////////////////////
// static basis
CMatrix CHermite::m_hermite( 2.0, -2.0, 1.0, 1.0,
-3.0, 3.0, -2.0, -1.0,
0.0, 0.0, 1.0, 0.0,
1.0, 0.0, 0.0, 0.0);

55
common/lib/utils/time.C Normal file
View File

@@ -0,0 +1,55 @@
/*
* PVVMUD a 3D MUD
* Copyright (C) 1998-1999 Programvareverkstedet (pvv@pvv.org)
*
* 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.
*
* 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
*
*/
#include "pvvmud.H"
#include "time.H"
#include <sys/time.h>
CTime::CTime(){
sec = 0;
msec = 0;
}
void CTime::getTime(){
timeval curr;
gettimeofday(&curr,NULL);
sec = curr.tv_sec;
msec = curr.tv_usec/1000;
}
void CTime::add(long msec){
msec += msec;
while (msec > 1000){
msec -= 1000;
sec++;
}
}
long CTime::diff(const CTime & time){
return (sec-time.sec)*1000 + msec - time.msec;
}
CTime& CTime::operator=(const CTime& time){
msec = time.msec;
sec = time.sec;
return *this;
}

169
common/lib/utils/vector.C Normal file
View File

@@ -0,0 +1,169 @@
/*
* PVVMUD a 3D MUD
* Copyright (C) 1998-1999 Programvareverkstedet (pvv@pvv.org)
*
* 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.
*
* 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
*
*/
#include "pvvmud.H"
#include <iostream.h>
#include "vector.H"
#include "vertex.H"
CVector::CVector(){
m_vector[0] = 0.0;
m_vector[1] = 0.0;
m_vector[2] = 0.0;
m_vector[3] = 1.0;
}
CVector::CVector(const CVector & vector){
m_vector[0] = vector.m_vector[0];
m_vector[1] = vector.m_vector[1];
m_vector[2] = vector.m_vector[2];
m_vector[3] = vector.m_vector[3];
}
CVector::CVector(double x, double y, double z){
m_vector[0] = x;
m_vector[1] = y;
m_vector[2] = z;
m_vector[3] = 1;
}
CVector::CVector(double x, double y, double z, double d){
m_vector[0] = x;
m_vector[1] = y;
m_vector[2] = z;
m_vector[3] = d;
}
CVector::CVector(const CVertex & vertex){
m_vector[0] = vertex.getX();
m_vector[1] = vertex.getY();
m_vector[2] = vertex.getZ();
m_vector[3] = 1;
}
double CVector::getX() const{
return m_vector[0];
}
double CVector::getY() const{
return m_vector[1];
}
double CVector::getZ() const{
return m_vector[2];
}
// Theory: The cross product is this determinant
//
// | i j k |
// det | m_vector[0] m_vector[1] m_vector[2] |
// | vector.m_vector[0] vector.m_vector[1] vector.m_vector[2] |
CVector CVector::cross( const CVector & vector ){
return CVector(
m_vector[1]*vector.m_vector[2] - m_vector[2]*vector.m_vector[1],
-m_vector[0]*vector.m_vector[2] + m_vector[2]*vector.m_vector[0],
m_vector[0]*vector.m_vector[1] - m_vector[1]*vector.m_vector[0]);
}
CVector& CVector::operator+=( const CVector & vector ){
int i;
for (i = 0; i < 3 ; i ++){
m_vector[i] += vector.m_vector[i];
}
return *this;
}
CVector CVector::operator+( const CVector & vector ) const{
CVector result;
int i;
for (i = 0; i < 3 ; i ++){
result.m_vector[i] = m_vector[i] + vector.m_vector[i];
}
result.m_vector[3] = 1;
return result;
}
CVector CVector::operator*( double scale ) const{
CVector result;
int i;
for (i = 0; i < 3 ; i ++){
result.m_vector[i] = m_vector[i]*scale;
}
result.m_vector[3] = 1;
return result;
}
CVector CVector::operator-( const CVector & vector ) const{
CVector result;
int i;
for (i = 0; i < 3 ; i ++){
result.m_vector[i] = m_vector[i] - vector.m_vector[i];
}
result.m_vector[3] = 1;
return result;
}
void CVector::transform(const CMatrix & transformation){
int ii,jj;
double sum;
//
// This create a compilation error with some compilers!
//
// double * m = ((CMatrix)transformation).getVector();
// CVector temp = *this;
// if (m == temp.m_vector)
// cdebug << "Error in compilation of CVector::transform !!!!\n";
//
CVector temp = *this;
CMatrix * ptrTransformation = (CMatrix*)&transformation;
double * m = ptrTransformation->getVector();
for (ii = 0; ii < 4; ii++){
sum = 0.0;
for (jj = 0; jj < 4; jj ++){
sum += m[ii+jj*4]*temp.m_vector[jj];
}
m_vector[ii] = sum;
}
}
CVector operator*(const CMatrix & m1, const CVector & v1){
CVector result;
double sum, *m = ((CMatrix)m1).getVector();
int ii,jj;
for (ii = 0; ii < 4; ii++){
sum = 0.0;
for (jj = 0; jj < 4; jj ++){
sum += m[ii+jj*4]*v1.m_vector[jj];
}
result.m_vector[ii] = sum;
}
return result;
}
ostream& operator<<(ostream&s,const CVector& v) {
return s << "[" << v.getX() << "," << v.getY() << "," << v.getZ() << "]";
}

View File

@@ -0,0 +1,5 @@
INCLUDES = -I../../include
noinst_LIBRARIES = libworld.a
libworld_a_SOURCES = cellpvs.C listener.C msgworld.C waobject.C waupdateposition.C worldanimation.C worldobject.C worldworld.C waupdatedirection.C wacreateobject.C waremoveobject.C worldhierarchy.C waupdatehierarchy.C warotate.C

View File

@@ -0,0 +1,335 @@
# Makefile.in generated automatically by automake 1.4 from Makefile.am
# Copyright (C) 1994, 1995-8, 1999 Free Software Foundation, Inc.
# This Makefile.in is free software; the Free Software Foundation
# gives unlimited permission to copy and/or distribute it,
# with or without modifications, as long as this notice is preserved.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY, to the extent permitted by law; without
# even the implied warranty of MERCHANTABILITY or FITNESS FOR A
# PARTICULAR PURPOSE.
SHELL = @SHELL@
srcdir = @srcdir@
top_srcdir = @top_srcdir@
VPATH = @srcdir@
prefix = @prefix@
exec_prefix = @exec_prefix@
bindir = @bindir@
sbindir = @sbindir@
libexecdir = @libexecdir@
datadir = @datadir@
sysconfdir = @sysconfdir@
sharedstatedir = @sharedstatedir@
localstatedir = @localstatedir@
libdir = @libdir@
infodir = @infodir@
mandir = @mandir@
includedir = @includedir@
oldincludedir = /usr/include
DESTDIR =
pkgdatadir = $(datadir)/@PACKAGE@
pkglibdir = $(libdir)/@PACKAGE@
pkgincludedir = $(includedir)/@PACKAGE@
top_builddir = ../../..
ACLOCAL = @ACLOCAL@
AUTOCONF = @AUTOCONF@
AUTOMAKE = @AUTOMAKE@
AUTOHEADER = @AUTOHEADER@
INSTALL = @INSTALL@
INSTALL_PROGRAM = @INSTALL_PROGRAM@ $(AM_INSTALL_PROGRAM_FLAGS)
INSTALL_DATA = @INSTALL_DATA@
INSTALL_SCRIPT = @INSTALL_SCRIPT@
transform = @program_transform_name@
NORMAL_INSTALL = :
PRE_INSTALL = :
POST_INSTALL = :
NORMAL_UNINSTALL = :
PRE_UNINSTALL = :
POST_UNINSTALL = :
CC = @CC@
CXX = @CXX@
GL_CFLAGS = @GL_CFLAGS@
GL_LIBS = @GL_LIBS@
LEX = @LEX@
MAKEINFO = @MAKEINFO@
NETLIBS = @NETLIBS@
PACKAGE = @PACKAGE@
RANLIB = @RANLIB@
TIFF_CFLAGS = @TIFF_CFLAGS@
TIFF_LIBS = @TIFF_LIBS@
VERSION = @VERSION@
YACC = @YACC@
INCLUDES = -I../../include
noinst_LIBRARIES = libworld.a
libworld_a_SOURCES = cellpvs.C listener.C msgworld.C waobject.C waupdateposition.C worldanimation.C worldobject.C worldworld.C waupdatedirection.C wacreateobject.C waremoveobject.C worldhierarchy.C waupdatehierarchy.C warotate.C
mkinstalldirs = $(SHELL) $(top_srcdir)/mkinstalldirs
CONFIG_CLEAN_FILES =
LIBRARIES = $(noinst_LIBRARIES)
DEFS = @DEFS@ -I. -I$(srcdir)
CPPFLAGS = @CPPFLAGS@
LDFLAGS = @LDFLAGS@
LIBS = @LIBS@
X_CFLAGS = @X_CFLAGS@
X_LIBS = @X_LIBS@
X_EXTRA_LIBS = @X_EXTRA_LIBS@
X_PRE_LIBS = @X_PRE_LIBS@
libworld_a_LIBADD =
libworld_a_OBJECTS = cellpvs.o listener.o msgworld.o waobject.o \
waupdateposition.o worldanimation.o worldobject.o worldworld.o \
waupdatedirection.o wacreateobject.o waremoveobject.o worldhierarchy.o \
waupdatehierarchy.o warotate.o
AR = ar
CXXFLAGS = @CXXFLAGS@
CXXCOMPILE = $(CXX) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS)
CXXLD = $(CXX)
CXXLINK = $(CXXLD) $(AM_CXXFLAGS) $(CXXFLAGS) $(LDFLAGS) -o $@
DIST_COMMON = Makefile.am Makefile.in
DISTFILES = $(DIST_COMMON) $(SOURCES) $(HEADERS) $(TEXINFOS) $(EXTRA_DIST)
TAR = gtar
GZIP_ENV = --best
DEP_FILES = .deps/cellpvs.P .deps/listener.P .deps/msgworld.P \
.deps/wacreateobject.P .deps/waobject.P .deps/waremoveobject.P \
.deps/warotate.P .deps/waupdatedirection.P .deps/waupdatehierarchy.P \
.deps/waupdateposition.P .deps/worldanimation.P .deps/worldhierarchy.P \
.deps/worldobject.P .deps/worldworld.P
SOURCES = $(libworld_a_SOURCES)
OBJECTS = $(libworld_a_OBJECTS)
all: all-redirect
.SUFFIXES:
.SUFFIXES: .C .S .c .o .s
$(srcdir)/Makefile.in: Makefile.am $(top_srcdir)/configure.in $(ACLOCAL_M4)
cd $(top_srcdir) && $(AUTOMAKE) --foreign common/lib/world/Makefile
Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status $(BUILT_SOURCES)
cd $(top_builddir) \
&& CONFIG_FILES=$(subdir)/$@ CONFIG_HEADERS= $(SHELL) ./config.status
mostlyclean-noinstLIBRARIES:
clean-noinstLIBRARIES:
-test -z "$(noinst_LIBRARIES)" || rm -f $(noinst_LIBRARIES)
distclean-noinstLIBRARIES:
maintainer-clean-noinstLIBRARIES:
.s.o:
$(COMPILE) -c $<
.S.o:
$(COMPILE) -c $<
mostlyclean-compile:
-rm -f *.o core *.core
clean-compile:
distclean-compile:
-rm -f *.tab.c
maintainer-clean-compile:
libworld.a: $(libworld_a_OBJECTS) $(libworld_a_DEPENDENCIES)
-rm -f libworld.a
$(AR) cru libworld.a $(libworld_a_OBJECTS) $(libworld_a_LIBADD)
$(RANLIB) libworld.a
.C.o:
$(CXXCOMPILE) -c $<
tags: TAGS
ID: $(HEADERS) $(SOURCES) $(LISP)
list='$(SOURCES) $(HEADERS)'; \
unique=`for i in $$list; do echo $$i; done | \
awk ' { files[$$0] = 1; } \
END { for (i in files) print i; }'`; \
here=`pwd` && cd $(srcdir) \
&& mkid -f$$here/ID $$unique $(LISP)
TAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) $(LISP)
tags=; \
here=`pwd`; \
list='$(SOURCES) $(HEADERS)'; \
unique=`for i in $$list; do echo $$i; done | \
awk ' { files[$$0] = 1; } \
END { for (i in files) print i; }'`; \
test -z "$(ETAGS_ARGS)$$unique$(LISP)$$tags" \
|| (cd $(srcdir) && etags $(ETAGS_ARGS) $$tags $$unique $(LISP) -o $$here/TAGS)
mostlyclean-tags:
clean-tags:
distclean-tags:
-rm -f TAGS ID
maintainer-clean-tags:
distdir = $(top_builddir)/$(PACKAGE)-$(VERSION)/$(subdir)
subdir = common/lib/world
distdir: $(DISTFILES)
here=`cd $(top_builddir) && pwd`; \
top_distdir=`cd $(top_distdir) && pwd`; \
distdir=`cd $(distdir) && pwd`; \
cd $(top_srcdir) \
&& $(AUTOMAKE) --include-deps --build-dir=$$here --srcdir-name=$(top_srcdir) --output-dir=$$top_distdir --foreign common/lib/world/Makefile
@for file in $(DISTFILES); do \
d=$(srcdir); \
if test -d $$d/$$file; then \
cp -pr $$/$$file $(distdir)/$$file; \
else \
test -f $(distdir)/$$file \
|| ln $$d/$$file $(distdir)/$$file 2> /dev/null \
|| cp -p $$d/$$file $(distdir)/$$file || :; \
fi; \
done
DEPS_MAGIC := $(shell mkdir .deps > /dev/null 2>&1 || :)
-include $(DEP_FILES)
mostlyclean-depend:
clean-depend:
distclean-depend:
-rm -rf .deps
maintainer-clean-depend:
%.o: %.c
@echo '$(COMPILE) -c $<'; \
$(COMPILE) -Wp,-MD,.deps/$(*F).pp -c $<
@-cp .deps/$(*F).pp .deps/$(*F).P; \
tr ' ' '\012' < .deps/$(*F).pp \
| sed -e 's/^\\$$//' -e '/^$$/ d' -e '/:$$/ d' -e 's/$$/ :/' \
>> .deps/$(*F).P; \
rm .deps/$(*F).pp
%.lo: %.c
@echo '$(LTCOMPILE) -c $<'; \
$(LTCOMPILE) -Wp,-MD,.deps/$(*F).pp -c $<
@-sed -e 's/^\([^:]*\)\.o[ ]*:/\1.lo \1.o :/' \
< .deps/$(*F).pp > .deps/$(*F).P; \
tr ' ' '\012' < .deps/$(*F).pp \
| sed -e 's/^\\$$//' -e '/^$$/ d' -e '/:$$/ d' -e 's/$$/ :/' \
>> .deps/$(*F).P; \
rm -f .deps/$(*F).pp
%.o: %.C
@echo '$(CXXCOMPILE) -c $<'; \
$(CXXCOMPILE) -Wp,-MD,.deps/$(*F).pp -c $<
@-cp .deps/$(*F).pp .deps/$(*F).P; \
tr ' ' '\012' < .deps/$(*F).pp \
| sed -e 's/^\\$$//' -e '/^$$/ d' -e '/:$$/ d' -e 's/$$/ :/' \
>> .deps/$(*F).P; \
rm .deps/$(*F).pp
%.lo: %.C
@echo '$(LTCXXCOMPILE) -c $<'; \
$(LTCXXCOMPILE) -Wp,-MD,.deps/$(*F).pp -c $<
@-sed -e 's/^\([^:]*\)\.o[ ]*:/\1.lo \1.o :/' \
< .deps/$(*F).pp > .deps/$(*F).P; \
tr ' ' '\012' < .deps/$(*F).pp \
| sed -e 's/^\\$$//' -e '/^$$/ d' -e '/:$$/ d' -e 's/$$/ :/' \
>> .deps/$(*F).P; \
rm -f .deps/$(*F).pp
info-am:
info: info-am
dvi-am:
dvi: dvi-am
check-am: all-am
check: check-am
installcheck-am:
installcheck: installcheck-am
install-exec-am:
install-exec: install-exec-am
install-data-am:
install-data: install-data-am
install-am: all-am
@$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am
install: install-am
uninstall-am:
uninstall: uninstall-am
all-am: Makefile $(LIBRARIES)
all-redirect: all-am
install-strip:
$(MAKE) $(AM_MAKEFLAGS) AM_INSTALL_PROGRAM_FLAGS=-s install
installdirs:
mostlyclean-generic:
clean-generic:
distclean-generic:
-rm -f Makefile $(CONFIG_CLEAN_FILES)
-rm -f config.cache config.log stamp-h stamp-h[0-9]*
maintainer-clean-generic:
mostlyclean-am: mostlyclean-noinstLIBRARIES mostlyclean-compile \
mostlyclean-tags mostlyclean-depend mostlyclean-generic
mostlyclean: mostlyclean-am
clean-am: clean-noinstLIBRARIES clean-compile clean-tags clean-depend \
clean-generic mostlyclean-am
clean: clean-am
distclean-am: distclean-noinstLIBRARIES distclean-compile \
distclean-tags distclean-depend distclean-generic \
clean-am
distclean: distclean-am
maintainer-clean-am: maintainer-clean-noinstLIBRARIES \
maintainer-clean-compile maintainer-clean-tags \
maintainer-clean-depend maintainer-clean-generic \
distclean-am
@echo "This command is intended for maintainers to use;"
@echo "it deletes files that may require special tools to rebuild."
maintainer-clean: maintainer-clean-am
.PHONY: mostlyclean-noinstLIBRARIES distclean-noinstLIBRARIES \
clean-noinstLIBRARIES maintainer-clean-noinstLIBRARIES \
mostlyclean-compile distclean-compile clean-compile \
maintainer-clean-compile tags mostlyclean-tags distclean-tags \
clean-tags maintainer-clean-tags distdir mostlyclean-depend \
distclean-depend clean-depend maintainer-clean-depend info-am info \
dvi-am dvi check check-am installcheck-am installcheck install-exec-am \
install-exec install-data-am install-data install-am install \
uninstall-am uninstall all-redirect all-am all installdirs \
mostlyclean-generic distclean-generic clean-generic \
maintainer-clean-generic clean mostlyclean distclean maintainer-clean
# Tell versions [3.59,3.63) of GNU make to not export all variables.
# Otherwise a system limit (for SysV at least) may be exceeded.
.NOEXPORT:

View File

@@ -0,0 +1,99 @@
/*
* PVVMUD a 3D MUD
* Copyright (C) 1998-1999 Programvareverkstedet (pvv@pvv.org)
*
* 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.
*
* 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
*
*/
#include "pvvmud.H"
#include "cellpvs.H"
#include "worldworld.H"
#include "worldobject.H"
CPVCell::CPVCell(DWORD cellId, const CPosition & position){
m_cellId = cellId;
m_position = position;
}
DWORD CPVCell::getCellId(){
return m_cellId;
}
CPosition CPVCell::getPosition(){
return m_position;
}
CCellPVS::CCellPVS(CWorldWorld * world){
m_world = world;
}
CWorldWorld * CCellPVS::getWorld(){
return m_world;
}
CPVCell* CCellPVS::addPVCell(DWORD cellId, const CPosition & position){
CPVCell * pvCell = new CPVCell(cellId,position);
addLast((CObject*)pvCell);
return pvCell;
}
CObjectListItem * CCellPVS::getFirstPVCell(){
return getFirst();
}
CPosition CCellPVS::getPVCellPosition(CWorldObject * cell){
CPosition position;
CObjectListItem * item = getFirstPVCell();
while (item != NULL){
CPVCell * pvCell = (CPVCell*)item->getObject();
if (pvCell->getCellId() == cell->getObjectId()){
return pvCell->getPosition();
}
item = item->getNext();
}
return position;
}
CWorldObject * CCellPVS::findCell(CPosition * position){
cdebug << "Check if pos : " << *position << "\n";
CObjectListItem * item = getFirstPVCell();
while (item != NULL){
CPVCell * pvCell = (CPVCell*)item->getObject();
CWorldObject * cell;
cell = getWorld()->getObject(pvCell->getCellId());
CPosition newpos = *position - pvCell->getPosition();
cdebug << "Check " << cell->getName() << " Pos : " << newpos << "\n";
if (cell->checkPosition(newpos)){
*position = newpos;
return cell;
}
item = item->getNext();
}
return NULL;
}

View File

@@ -0,0 +1,26 @@
/*
* PVVMUD a 3D MUD
* Copyright (C) 1998-1999 Programvareverkstedet (pvv@pvv.org)
*
* 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.
*
* 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
*
*/
#include "pvvmud.H"
#include "listener.H"
CListener::CListener(){
}

341
common/lib/world/msgworld.C Normal file
View File

@@ -0,0 +1,341 @@
/*
* PVVMUD a 3D MUD
* Copyright (C) 1998-1999 Programvareverkstedet (pvv@pvv.org)
*
* 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.
*
* 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
*
*/
#include "pvvmud.H"
#include "msgworld.H"
#include "position.H"
#include "direction.H"
/*
///////////////////////////////////////////////////////////////////////////////
//
// CMsgSection
//
///////////////////////////////////////////////////////////////////////////////
CMsgSection::CMsgSection():CMessage(MSG_SECTION,sizeof(DWORD)+sizeof(BYTE)){
setName("MsgSection");
}
CMsgSection::CMsgSection( DWORD sectionId, BOOL create )
:CMessage(MSG_SECTION,sizeof(DWORD) + sizeof(BYTE)){
setName("MsgSection");
writeDWord(1,sectionId);
writeByte(5,create);
}
DWORD CMsgSection::getSectionId(){
return readDWord(1);
}
BOOL CMsgSection::getCreate(){
return readByte(5);
}
///////////////////////////////////////////////////////////////////////////////
//
// CMsgCell
//
///////////////////////////////////////////////////////////////////////////////
CMsgCell::CMsgCell():CMessage(MSG_CELL,5*sizeof(DWORD)){
setName("MsgCell");
}
CMsgCell::CMsgCell( DWORD cellId, DWORD geometryId,
const CPosition & position):CMessage(MSG_CELL,5*sizeof(DWORD)){
setName("MsgCell");
writeDWord(1,cellId);
writeDWord(5,geometryId);
writePosition(9,position);
}
DWORD CMsgCell::getCellId(){
return readDWord(1);
}
DWORD CMsgCell::getGeometryId(){
return readDWord(5);
}
CPosition CMsgCell::getPosition(){
return readPosition(9);
}
///////////////////////////////////////////////////////////////////////////////
//
// CMsgRemoveCell
//
///////////////////////////////////////////////////////////////////////////////
CMsgRemoveCell::CMsgRemoveCell():CMessage(MSG_REMOVECELL,1*sizeof(DWORD)){
setName("MsgRemoveCell");
}
CMsgRemoveCell::CMsgRemoveCell( DWORD cellId )
:CMessage(MSG_REMOVECELL,1*sizeof(DWORD)){
setName("MsgRemoveCell");
writeDWord(1,cellId);
}
DWORD CMsgRemoveCell::getCellId(){
return readDWord(1);
}
*/
///////////////////////////////////////////////////////////////////////////////
//
// CMsgObject
//
///////////////////////////////////////////////////////////////////////////////
CMsgObject::CMsgObject():CMessage(MSG_OBJECT,9*sizeof(DWORD)){
setName("MsgObject");
}
CMsgObject::CMsgObject( DWORD objectId, DWORD geometryId, DWORD parentId,
const CPosition & position,
const CDirection & direction ):CMessage(MSG_OBJECT,9*sizeof(DWORD)){
setName("MsgObject");
writeDWord(1,objectId);
writeDWord(5,geometryId);
writeDWord(9,parentId);
writePosition(13,position);
writeDirection(25,direction);
}
DWORD CMsgObject::getObjectId(){
return readDWord(1);
}
DWORD CMsgObject::getGeometryId(){
return readDWord(5);
}
DWORD CMsgObject::getParentId(){
return readDWord(9);
}
CPosition CMsgObject::getPosition(){
return readPosition(13);
}
CDirection CMsgObject::getDirection(){
return readDirection(25);
}
///////////////////////////////////////////////////////////////////////////////
//
// CMsgRemoveObject
//
///////////////////////////////////////////////////////////////////////////////
CMsgRemoveObject::CMsgRemoveObject():CMessage(MSG_REMOVEOBJECT,2*sizeof(DWORD)){
setName("MsgRemoveObject");
}
CMsgRemoveObject::CMsgRemoveObject( DWORD objectId,
DWORD parentId ):CMessage(MSG_REMOVEOBJECT,2*sizeof(DWORD)){
setName("MsgRemoveObject");
writeDWord(1,objectId);
writeDWord(5,parentId);
}
DWORD CMsgRemoveObject::getObjectId(){
return readDWord(1);
}
DWORD CMsgRemoveObject::getParentId(){
return readDWord(5);
}
///////////////////////////////////////////////////////////////////////////////
//
// CMsgChangeMasterCell
//
///////////////////////////////////////////////////////////////////////////////
CMsgChangeMasterCell::CMsgChangeMasterCell():CMessage(MSG_CHANGEMASTERCELL,sizeof(DWORD)){
setName("MsgChangeMasterCell");
}
CMsgChangeMasterCell::CMsgChangeMasterCell( DWORD newMasterCellId)
:CMessage(MSG_CHANGEMASTERCELL,sizeof(DWORD)){
setName("MsgChangeMasterCell");
writeDWord(1,newMasterCellId);
}
DWORD CMsgChangeMasterCell::getNewMasterCellId(){
return readDWord(1);
}
///////////////////////////////////////////////////////////////////////////////
//
// CMsgPVCell
//
///////////////////////////////////////////////////////////////////////////////
CMsgPVCell::CMsgPVCell():CMessage(MSG_PVCELL,5*sizeof(DWORD)){
setName("MsgPVCell");
}
CMsgPVCell::CMsgPVCell( DWORD cellId, DWORD PVCellId,
const CPosition & position ):CMessage(MSG_PVCELL,5*sizeof(DWORD)){
setName("MsgPVCell");
writeDWord(1,cellId);
writeDWord(5,PVCellId);
for (int ii = 0; ii < 3; ii++){
writeDouble(9+ii*4,position.getValue(ii));
}
}
DWORD CMsgPVCell::getCellId(){
return readDWord(1);
}
DWORD CMsgPVCell::getPVCellId(){
return readDWord(5);
}
CPosition CMsgPVCell::getPosition(){
return CPosition(readDouble(9),readDouble(13),readDouble(17));
}
///////////////////////////////////////////////////////////////////////////////
//
// CMsgUpdatePosition
//
///////////////////////////////////////////////////////////////////////////////
CMsgUpdatePosition::CMsgUpdatePosition()
:CMessage(MSG_UPDATEPOSITION,4*sizeof(DWORD)){
setName("MsgUpdatePosition");
}
CMsgUpdatePosition::CMsgUpdatePosition(DWORD objectId,const CPosition& position)
:CMessage(MSG_UPDATEPOSITION,sizeof(DWORD)*4){
setName("MsgUpdatePosition");
writeDWord(1,objectId);
writePosition(5,position);
}
DWORD CMsgUpdatePosition::getObjectId(){
return readDWord(1);
}
CPosition CMsgUpdatePosition::getPosition(){
return readPosition(5);
}
///////////////////////////////////////////////////////////////////////////////
//
// CMsgUpdateDirection
//
///////////////////////////////////////////////////////////////////////////////
CMsgUpdateDirection::CMsgUpdateDirection()
:CMessage(MSG_UPDATEDIRECTION,4*sizeof(DWORD)){
setName("MsgUpdateDirection");
}
CMsgUpdateDirection::CMsgUpdateDirection(DWORD objectId,const CDirection& direction):CMessage(MSG_UPDATEDIRECTION, 4*sizeof(DWORD)){
setName("MsgUpdateDirection");
writeDWord(1,objectId);
writeDirection(5,direction);
}
DWORD CMsgUpdateDirection::getObjectId(){
return readDWord(1);
}
CDirection CMsgUpdateDirection::getDirection(){
return readDirection(5);
}
///////////////////////////////////////////////////////////////////////////////
//
// CMsgUpdateHierarchy
//
///////////////////////////////////////////////////////////////////////////////
CMsgUpdateHierarchy::CMsgUpdateHierarchy()
:CMessage(MSG_UPDATEHIERARCHY,2*sizeof(DWORD)){
setName("MsgUpdateHierarchy");
}
CMsgUpdateHierarchy::CMsgUpdateHierarchy(DWORD objectId, DWORD parentId):CMessage(MSG_UPDATEHIERARCHY, 2*sizeof(DWORD)){
setName("MsgUpdateHierarchy");
writeDWord(1,objectId);
writeDWord(5,parentId);
}
DWORD CMsgUpdateHierarchy::getObjectId(){
return readDWord(1);
}
DWORD CMsgUpdateHierarchy::getParentId(){
return readDWord(5);
}
///////////////////////////////////////////////////////////////////////////////
//
// CMsgRotate
//
///////////////////////////////////////////////////////////////////////////////
CMsgRotate::CMsgRotate()
:CMessage(MSG_ROTATE,4*sizeof(DWORD)){
setName("MsgRotate");
}
CMsgRotate::CMsgRotate(DWORD objectId, const CDirection& angleSpeed):CMessage(MSG_ROTATE, 4*sizeof(DWORD)){
setName("MsgRotate");
writeDWord(1,objectId);
writeDirection(5,angleSpeed);
}
DWORD CMsgRotate::getObjectId(){
return readDWord(1);
}
CDirection CMsgRotate::getAngleSpeed(){
return readDirection(5);
}

View File

@@ -0,0 +1,87 @@
/*
* PVVMUD a 3D MUD
* Copyright (C) 1998-1999 Programvareverkstedet (pvv@pvv.org)
*
* 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.
*
* 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
*
*/
#include <stdlib.h>
#include "pvvmud.H"
#include "wacreateobject.H"
#include "worldworld.H"
#include "msgworld.H"
CWACreateObject::CWACreateObject( CWorldObject * object ) : CWAObject(object->getObjectId()){
m_object = object;
m_geometryId = object->getGeometryId();
m_parentId = object->getParentId();
m_position = object->getPosition();
m_direction = object->getDirection();
m_objectType = (char*)malloc(strlen(object->getObjectType())+1);
strcpy(m_objectType,object->getObjectType());
}
CWACreateObject::CWACreateObject( char * objectType, DWORD objectId , DWORD geometryId, DWORD parentId, const CPosition & position, const CDirection & direction ): CWAObject(objectId){
m_object = NULL;
m_geometryId = geometryId;
m_parentId = parentId;
m_position = position;
m_direction = direction;
m_objectType = (char*)malloc(strlen(objectType)+1);
strcpy(m_objectType,objectType);
}
CWACreateObject::~CWACreateObject(){
if (m_objectType != NULL) free ( m_objectType );
}
CMessage * CWACreateObject::createMessage(){
return new CMsgObject(getObjectId(),m_geometryId,m_parentId,m_position,m_direction);
}
int CWACreateObject::animate( DWORD time ){
cdebug << "CWAObject::animate ( " << time << " ) create object "
<< getObjectId() << " geometry " << m_geometryId
<< " parent ";
(m_parentId == ID_UNKNOWN ? cdebug << "-1" : cdebug << m_parentId);
cdebug << " position " << m_position
<< " direction " << m_direction << endl;
CWorldObject * object = m_object;
if (m_parentId == -1){
if (m_object == NULL) object = getWorld()->newObject(m_objectType,getObjectId(),NULL,m_geometryId,m_position,m_direction);
getWorld()->_addObject( object );
} else {
CWorldObject * parent = getWorld()->getObject( m_parentId );
if (parent == NULL) return FALSE;
if (object == NULL){
object = getWorld()->newObject( m_objectType, getObjectId(), parent, m_geometryId,m_position,m_direction);
}
parent->_addObject( object );
}
return FALSE;
}

View File

@@ -0,0 +1,39 @@
/*
* PVVMUD a 3D MUD
* Copyright (C) 1998-1999 Programvareverkstedet (pvv@pvv.org)
*
* 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.
*
* 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
*
*/
#include "pvvmud.H"
#include "waobject.H"
#include "worldworld.H"
//#include "worldlistener.H"
CWAObject::CWAObject( DWORD objectId ):CWorldAnimation(objectId){
// m_objectId = objectId;
}
/*
DWORD CWAObject::getObjectId(){
return m_objectId;
}
CWorldObject * CWAObject::getObject(){
return getWorld()->getObject( m_objectId );
}
*/

View File

@@ -0,0 +1,48 @@
/*
* PVVMUD a 3D MUD
* Copyright (C) 1998-1999 Programvareverkstedet (pvv@pvv.org)
*
* 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.
*
* 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
*
*/
#include "pvvmud.H"
#include "waremoveobject.H"
#include "worldworld.H"
#include "msgworld.H"
CWARemoveObject::CWARemoveObject( DWORD objectId , DWORD parentId): CWAObject(objectId){
m_parentId = parentId;
}
CMessage * CWARemoveObject::createMessage(){
return new CMsgRemoveObject(getObjectId(),m_parentId);
}
int CWARemoveObject::animate( DWORD time ){
cdebug << "CWAObject::animate ( " << time << " ) remove object " << getObjectId() << " parent " << m_parentId << endl;
if (m_parentId == -1){
getWorld()->_removeObject(getWorld()->getObject(getObjectId()));
} else {
CWorldObject * parent = getWorld()->getObject(m_parentId);
parent->_removeObject(parent->getObject(getObjectId()));
}
return FALSE;
}

View File

@@ -0,0 +1,52 @@
/*
* PVVMUD a 3D MUD
* Copyright (C) 1998-1999 Programvareverkstedet (pvv@pvv.org)
*
* 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.
*
* 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
*
*/
#include "pvvmud.H"
#include "warotate.H"
#include "msgworld.H"
CWARotate::CWARotate( DWORD objectId, const CDirection & angleSpeed )
:CWAObject(objectId){
m_angleSpeed = angleSpeed;
}
CMessage * CWARotate::createMessage(){
return new CMsgRotate( getObjectId(), m_angleSpeed );
}
int CWARotate::animate( DWORD time, DWORD deltaTime ){
cdebug << "CWARotate::animate ( " << time << ", " << deltaTime
<< " ) angle speed " << m_angleSpeed;
CWorldObject * object = getObject();
if (object == NULL){
cdebug << " Failed to find object!" << endl;
return FALSE;
}
CDirection dir = object->getDirection();
dir = dir + m_angleSpeed * ((double)deltaTime/1000.0);
cdebug << " new direction " << dir << endl;
object->_updateDirection( dir );
return TRUE; // Dont delete this animation yet!
}

View File

@@ -0,0 +1,39 @@
/*
* PVVMUD a 3D MUD
* Copyright (C) 1998-1999 Programvareverkstedet (pvv@pvv.org)
*
* 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.
*
* 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
*
*/
#include "pvvmud.H"
#include "waupdatedirection.H"
#include "msgworld.H"
CWAUpdateDirection::CWAUpdateDirection( DWORD objectId, const CDirection & direction )
:CWAObject(objectId){
m_direction = direction;
}
CMessage * CWAUpdateDirection::createMessage(){
return new CMsgUpdateDirection( getObjectId(), m_direction );
}
int CWAUpdateDirection::animate( DWORD time ){
cdebug << "CWAUpdateDirection::animate ( " << time << " ) set direction " << m_direction << endl;
CWorldObject * object = getObject();
object->_updateDirection( m_direction );
return FALSE;
}

View File

@@ -0,0 +1,49 @@
/*
* PVVMUD a 3D MUD
* Copyright (C) 1998-1999 Programvareverkstedet (pvv@pvv.org)
*
* 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.
*
* 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
*
*/
#include "pvvmud.H"
#include "waupdatehierarchy.H"
#include "worldworld.H"
#include "msgworld.H"
CWAUpdateHierarchy::CWAUpdateHierarchy( DWORD objectId , DWORD parentId): CWAObject(objectId){
m_parentId = parentId;
}
CMessage * CWAUpdateHierarchy::createMessage(){
return new CMsgUpdateHierarchy(getObjectId(),m_parentId);
}
int CWAUpdateHierarchy::animate( DWORD time ){
cdebug << "CWAUpdateHierarchy::animate ( " << time << " ) update hierarchy " << getObjectId() << " parent " << m_parentId << endl;
if (m_parentId == -1){
cdebug << "ERROR cant update hierarchy on cell objects" << endl;
} else {
CWorldObject * parent = getWorld()->getObject(m_parentId);
CWorldObject * object = getWorld()->getObject(getObjectId());
object->_setParent(parent);
}
return FALSE;
}

View File

@@ -0,0 +1,39 @@
/*
* PVVMUD a 3D MUD
* Copyright (C) 1998-1999 Programvareverkstedet (pvv@pvv.org)
*
* 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.
*
* 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
*
*/
#include "pvvmud.H"
#include "waupdateposition.H"
#include "msgworld.H"
CWAUpdatePosition::CWAUpdatePosition( DWORD objectId, const CPosition & position )
:CWAObject(objectId){
m_position = position;
}
CMessage * CWAUpdatePosition::createMessage(){
return new CMsgUpdatePosition( getObjectId(), m_position );
}
int CWAUpdatePosition::animate( DWORD time ){
cdebug << "CWAUpdatePosition::animate ( " << time << " ) set position " << m_position << endl;
CWorldObject * object = getObject();
object->_updatePosition( m_position );
return FALSE;
}

View File

@@ -0,0 +1,138 @@
/*
* PVVMUD a 3D MUD
* Copyright (C) 1998-1999 Programvareverkstedet (pvv@pvv.org)
*
* 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.
*
* 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
*
*/
#include "pvvmud.H"
#include "worldanimation.H"
#include "worldworld.H"
#include "worldobject.H"
CWorldAnimationList::CWorldAnimationList(){
m_lastTime = 0;
}
void CWorldAnimationList::add( CWorldAnimation * animation , DWORD time ){
DWORD deltaTime;
if (m_lastTime == 0)
deltaTime = 0;
else
deltaTime = time - m_lastTime;
if (animation->animate( time, deltaTime )){
addLast( (CObject*)animation );
} else {
delete animation;
}
}
void CWorldAnimationList::animate( DWORD time ){
CObjectListItem * item = getFirst();
while (item != NULL){
CWorldAnimation * animation = (CWorldAnimation*)item->getObject();
item = item->getNext();
// if (time >= animation->getStartTime()){
// if (time >= animation->getStopTime()) {
// remove( animation );
// } else {
DWORD deltaTime;
if (m_lastTime == 0)
deltaTime = 0;
else
deltaTime = time - m_lastTime;
m_lastTime = time;
if (!animation->animate( time, deltaTime )){
remove( animation );
delete animation;
}
// }
// }
}
}
void CWorldAnimationList::clearList(){
deleteAll();
}
void CWorldAnimationList::sendObjectAnimation( DWORD objectId,
CListener * listener)
{
CObjectListItem * item = getFirst();
while (item != NULL){
CWorldAnimation * animation = (CWorldAnimation*)item->getObject();
item = item->getNext();
if (animation->getObjectId() == objectId){
listener->sendAnimation( animation );
}
}
}
CWorldAnimation::CWorldAnimation(DWORD objectId){
m_world = NULL;
m_startTime = m_stopTime = 0;
m_objectId = objectId;
}
CWorldAnimation::~CWorldAnimation(){
}
CWorldWorld * CWorldAnimation::getWorld(){
return m_world;
}
void CWorldAnimation::setWorld( CWorldWorld * world ){
m_world = world;
}
DWORD CWorldAnimation::getObjectId(){
return m_objectId;
}
CWorldObject * CWorldAnimation::getObject(){
return getWorld()->getObject( m_objectId );
}
//////////////////////////////////////////////////////////////////////////////
// Function : animate
// Return : TRUE if more animation to do
// FALSE if end of animation
//
int CWorldAnimation::animate( DWORD time, DWORD deltaTime ){
return animate( time );
}
//////////////////////////////////////////////////////////////////////////////
// Function : animate
// Return : TRUE if more animation to do
// FALSE if end of animation
//
int CWorldAnimation::animate( DWORD time ){
return FALSE;
}

View File

@@ -0,0 +1,140 @@
/*
* PVVMUD a 3D MUD
* Copyright (C) 1998-1999 Programvareverkstedet (pvv@pvv.org)
*
* 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.
*
* 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
*
*/
#include "pvvmud.H"
#include "worldhierarchy.H"
#include "worldworld.H"
#include "wacreateobject.H"
#include "waremoveobject.H"
#include "waupdatehierarchy.H"
CWorldHierarchy::CWorldHierarchy(DWORD objectId, CWorldHierarchy * parent){
m_objectId = objectId;
m_parent = parent;
if ((m_objectId != ID_UNKNOWN) && (m_parent == NULL)){
cdebug << "ERROR: Have to have a parent!\n";
void (*a)() = NULL;
a();
}
}
CWorldHierarchy::~CWorldHierarchy(){
if (m_parent != NULL)
cdebug << "WARNING CWorldHierarchy::~CWorldHierarchy "
<< "Parent not NULL!" << endl;
if (getNumItems() > 0)
cdebug << "WARNING CWorldHierarchy::~CWorldHierarchy "
<< "Subobject not removed!" << endl;
}
DWORD CWorldHierarchy::getObjectId(){
return m_objectId;
}
CWorldHierarchy * CWorldHierarchy::getParent(){
return m_parent;
}
DWORD CWorldHierarchy::getParentId(){
if (m_parent == NULL) return ID_UNKNOWN;
return m_parent->getObjectId();
}
CWorldWorld * CWorldHierarchy::getWorld(){
return m_parent->getWorld();
}
void CWorldHierarchy::_addObject(CWorldObject * object){
addLast((CObject*)object);
}
void CWorldHierarchy::_removeObject(CWorldObject * object){
remove((CObject*)object);
}
void CWorldHierarchy::_setParent(CWorldHierarchy * parent){
// Unlink from old parent
if (m_parent != NULL){
m_parent->_removeObject((CWorldObject*)this);
}
m_parent = parent;
// Link to new parent
if (m_parent != NULL){
m_parent->_addObject((CWorldObject*)this);
}
}
void CWorldHierarchy::addObject(CWorldObject * object){
CWorldWorld * world = getWorld();
world->addAnimation(new CWACreateObject(object), this );
}
void CWorldHierarchy::removeObject(CWorldObject * object){
CWorldWorld * world = getWorld();
world->addAnimation(new CWARemoveObject(object->getObjectId(),
object->getParentId()), this );
}
void CWorldHierarchy::setParent(CWorldObject * parent){
CWorldWorld * world = getWorld();
world->addAnimation(new CWAUpdateHierarchy(getObjectId(),
parent->getObjectId()), this );
}
CWorldObject * CWorldHierarchy::getObject( DWORD objectId ){
// Check if this is the object!
if (objectId == getObjectId()) return (CWorldObject*)this;
// Check child objects
CObjectListItem * item = getFirst();
while (item != NULL){
CWorldObject * object = (CWorldObject*)item->getObject();
if ((object = object->getObject(objectId)) != NULL) return object;
item = item->getNext();
}
return NULL;
}
CWorldObject * CWorldHierarchy::getObject( char * name ){
// Check if this is the object!
if (getName() != NULL && strcmp(name,getName()) == 0) return (CWorldObject*)this;
// Check child objects
CObjectListItem * item = getFirst();
while (item != NULL){
CWorldObject * object = (CWorldObject*)item->getObject();
if ((object = object->getObject(name)) != NULL) return object;
item = item->getNext();
}
return NULL;
}

View File

@@ -0,0 +1,244 @@
/*
* PVVMUD a 3D MUD
* Copyright (C) 1998-1999 Programvareverkstedet (pvv@pvv.org)
*
* 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.
*
* 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
*
*/
#include "pvvmud.H"
#include "worldobject.H"
#include "worldworld.H"
#include "waupdateposition.H"
#include "waupdatedirection.H"
#include "warotate.H"
CWorldObject::CWorldObject(DWORD objectId, CWorldHierarchy * parent, DWORD geometryId, const CPosition & position, const CDirection & direction):CWorldHierarchy(objectId,parent){
m_geometryId = geometryId;
m_bBox = NULL;
m_BSDTree = NULL;
m_collidable = 0;
m_cellPVS = NULL;
_updatePosition(position);
_updateDirection(direction);
}
CWorldObject::~CWorldObject(){
if (m_bBox != NULL) delete m_bBox;
if (m_BSDTree != NULL) delete m_BSDTree;
if (m_cellPVS != NULL) delete m_cellPVS;
}
DWORD CWorldObject::getGeometryId(){
return m_geometryId;
}
CPosition & CWorldObject::getPosition(){
return m_position;
}
CDirection & CWorldObject::getDirection(){
return m_direction;
}
char * CWorldObject::getObjectType(){
return "object";
}
CWorldObject * CWorldObject::getMasterCell(){
if (getParentId() == ID_UNKNOWN) return this;
CWorldObject * parent = (CWorldObject*)getParent();
if (parent != NULL) return parent->getMasterCell();
return NULL;
}
CGeometry * CWorldObject::getGeometry(){
cdebug << "CWorldObject::getGeometry: Not overloaded!\n";
return NULL;
}
CPVCell* CWorldObject::addPVCell(DWORD PVCellId, const CPosition & position){
if (m_cellPVS == NULL) m_cellPVS = new CCellPVS(getWorld());
return m_cellPVS->addPVCell(PVCellId,position);
}
CCellPVS* CWorldObject::getPVS(){
return m_cellPVS;
}
void CWorldObject::updatePosition( const CPosition & position ){
// cdebug << "CWorldObject::updatePosition " << position << " on object " << getObjectId() << "\n";
CWorldWorld * world = getWorld();
world->addAnimation(new CWAUpdatePosition(getObjectId(),position), this );
}
void CWorldObject::updateDirection( const CDirection & direction ){
// cdebug << "CWorldObject::updateDirection " << direction << " on object " << getObjectId() << "\n";
CWorldWorld * world = getWorld();
world->addAnimation(new CWAUpdateDirection(getObjectId(),direction), this );
}
void CWorldObject::rotate( const CDirection & angleSpeed ){
// cdebug << "CWorldObject::rotate " << angleSpeed << " on object " << getObjectId() << "\n";
CWorldWorld * world = getWorld();
world->addAnimation(new CWARotate(getObjectId(),angleSpeed), this );
}
void CWorldObject::_updateDirection( const CDirection & direction ){
// cdebug << "CWorldObject::_updateDirection " << direction << " on object " << getObjectId() << "\n";
m_direction = direction;
}
void CWorldObject::_updatePosition( const CPosition & position ){
// cdebug << "CWorldObject::_updatePosition " << position << " on object " << getObjectId() << "\n";
m_position = position;
}
void CWorldObject::setBBox( CBBox * bBox ){
m_bBox = bBox;
}
CBBox * CWorldObject::getBBox( ){
return m_bBox;
}
void CWorldObject::setCollidable(BYTE coll){
m_collidable =coll;
}
BYTE CWorldObject::getCollidable(){
return m_collidable ;
}
void CWorldObject::setBSDTree( CBSDTree * BSDTree ){
m_BSDTree = BSDTree;
}
CBSDTree * CWorldObject::getBSDTree( ){
return m_BSDTree;
}
CWorldObject * CWorldObject::createObject( char * objectName, DWORD objectId,
DWORD geometryId, const CPosition & position, const CDirection & direction ){
CWorldObject * object =
getWorld()->newObject(objectName, objectId,this,geometryId,position,direction);
addObject( object );
return object;
}
int CWorldObject::checkPosition(const CPosition & position){
if (m_BSDTree != NULL) return m_BSDTree->inside( position );
else if (getBBox() != NULL) return getBBox()->inside( position );
else return FALSE;
}
int CWorldObject::moveTo( CWorldObject * parent ){
setParent( parent );
return TRUE;
}
void CWorldObject::getGlobalTransform( CMatrix & transform ){
getTransform( transform );
if (getParentId() != ID_UNKNOWN){
CWorldObject * parent = (CWorldObject*)getParent();
if (parent != NULL) parent->getGlobalTransform( transform );
}
}
void CWorldObject::getTransform( CMatrix & transform ){
transform.translate( getPosition() );
transform.rotate( getDirection() );
}
void CWorldObject::getInvGlobalTransform( CMatrix & transform ){
getInvTransform( transform );
if (getParentId() != ID_UNKNOWN){
CWorldObject * parent = (CWorldObject*)getParent();
if (parent != NULL) parent->getInvGlobalTransform( transform );
}
}
void CWorldObject::getInvTransform( CMatrix & transform ){
transform.rotate( -getDirection() );
transform.translate( -getPosition() );
}
void CWorldObject::distances(CDoubleArray & distArray, const CBeam & beam,
double min, double max){
if (m_collidable ) return;
CGeometry * geometry = getGeometry();
CMatrix transform;
getInvTransform(transform);
CBeam objBeam = beam;
objBeam.transform(transform);
if (geometry != NULL){
if ( objBeam.intersect(geometry->calculateBBox())){
cdebug << "CWorldObject( " << getName()
<< " )::distances: Beam " << objBeam << "\n";
geometry->distances(distArray,objBeam,min,max);
// Test sub objects
CObjectListItem * item = getFirst();
while (item != NULL){
CWorldObject * obj = (CWorldObject*)item->getObject();
obj->distances(distArray,objBeam,min,max);
item = item->getNext();
}
} else {
cdebug << "CWorldObject( " << getName()
<< " )::distances: Don't intersect!\n";
}
} else {
cdebug << "CWorldObject( " << getName()
<< " )::distances: Don't have geometry!\n";
}
}
void CWorldObject::dump(int tab){
int ii;
for (ii = 0; ii < tab; ii++) cdebug << "\t";
cdebug << "Object: Id: " << getObjectId() << " Geo: " << getGeometryId() << " Pos: " << getPosition() << " Dir: " << getDirection() << "\n";
CObjectListItem * item = getFirst();
while (item != NULL){
CWorldObject * object = (CWorldObject*)item->getObject();
object->dump(tab+1);
item = item->getNext();
}
}

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