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

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);
}