From 56cc59cf44ec64440ba4d1c0d005196195c758e6 Mon Sep 17 00:00:00 2001 From: hugues Date: Sat, 25 Mar 2006 15:07:51 +0000 Subject: Nettoyage du repository glagen git-svn-id: file:///usr/local/opt/svn/repos/glagen@12 0f7e0d06-a6f9-0310-a55f-d5f984f55e4c --- dll/MANUAL | 138 +++++++++++++ dll/Makefile | 72 +++++++ dll/NOTES | 13 ++ dll/README | 237 ++++++++++++++++++++++ dll/classes/Data_property.cc | 30 +++ dll/classes/Data_property.hh | 88 +++++++++ dll/classes/Data_string.cc | 1 + dll/classes/Data_string.hh | 62 ++++++ dll/classes/GLG-libraries-devel.cc | 32 +++ dll/classes/GLG-libraries-devel.hh | 1 + dll/classes/dot.cc | 100 ++++++++++ dll/classes/dot.hh | 49 +++++ dll/classes/libclass.cc | 391 +++++++++++++++++++++++++++++++++++++ dll/classes/libclass.hh | 91 +++++++++ dll/classes/matrix.cc | 3 + dll/classes/matrix.hh | 324 ++++++++++++++++++++++++++++++ dll/classes/node.cc | 11 ++ dll/classes/node.hh | 82 ++++++++ dll/create_dotproperty_init.cc | 86 ++++++++ dll/create_dotproperty_init.hh | 0 dll/header.cc | 28 +++ dll/includes/errors.hh | 19 ++ dll/libraryloader.cc | 322 ++++++++++++++++++++++++++++++ dll/libraryloader.hh | 41 ++++ dll/main.cc | 21 ++ dll/main.hh | 1 + dll/samples2/gps/libtoto.gps | 4 + 27 files changed, 2247 insertions(+) create mode 100644 dll/MANUAL create mode 100644 dll/Makefile create mode 100644 dll/NOTES create mode 100644 dll/README create mode 100644 dll/classes/Data_property.cc create mode 100644 dll/classes/Data_property.hh create mode 100644 dll/classes/Data_string.cc create mode 100644 dll/classes/Data_string.hh create mode 100644 dll/classes/GLG-libraries-devel.cc create mode 100644 dll/classes/GLG-libraries-devel.hh create mode 100644 dll/classes/dot.cc create mode 100644 dll/classes/dot.hh create mode 100644 dll/classes/libclass.cc create mode 100644 dll/classes/libclass.hh create mode 100644 dll/classes/matrix.cc create mode 100644 dll/classes/matrix.hh create mode 100644 dll/classes/node.cc create mode 100644 dll/classes/node.hh create mode 100644 dll/create_dotproperty_init.cc create mode 100644 dll/create_dotproperty_init.hh create mode 100644 dll/header.cc create mode 100644 dll/includes/errors.hh create mode 100644 dll/libraryloader.cc create mode 100644 dll/libraryloader.hh create mode 100644 dll/main.cc create mode 100644 dll/main.hh create mode 100644 dll/samples2/gps/libtoto.gps (limited to 'dll') diff --git a/dll/MANUAL b/dll/MANUAL new file mode 100644 index 0000000..5e7cfa0 --- /dev/null +++ b/dll/MANUAL @@ -0,0 +1,138 @@ + + ============================= + Dynamic Library Loader Module + ============================= + GLAGEN - 2002 - Hugues HIEGEL + + + + + I. What is it ? + + +The Dynamic Library Loader Module (DLL Module) is part of the GLAGEN +Engine. It goals is to provide to the end-user a flexible usage of +external C/C++ libraries (*.so) . + +At this time, only C++ libraries are supported, because the main DLL +Module is already written in C++. It should be easy to allow C-written +libraries, but du to a lack of time, it should appear.. later. + + + + II. How does it work ? + + +The DLL Engine reads all libraries, especially their Names and +Dependancies, and then builds a dependancies tree. This last would be +used by the Network module (written by lam_m), and should determine in +which order each library would be executed in the main loop. +For example: + + library A needs nobody, alike library B. Libraries AC and AD needs + A, BE and BF need B, ACG needs AC and BFH needs BF. + We would obtain such a tree: + + (root) + \__________________ + | | + A B + \_______ \_____ + | | | | + AC AD BE BF + \_ \_ + | | + ACG BFH + + + Then the execution order would be done in such an order, reading + the tree top-bottom and left-right: + A-AC-ACG-AD-B-BE-BF-BFH + + Like that, we are certain that any library would be able to read + the results of one of its dependancies. + +I did a Library class that contains a lot of infos about each +library.so. For each library file, I effectively create a new Library +instance, and initialize it by opening the library, ang trying to get +infos using dlsym and some canonical symbols (See section above for +more info about libraries' symbols). If the library do answer to the +required ones, then it is stored, else it is immediately closed and +forgotten. + +Along the program, we will mainly work with list of Libraries, for +this class is our swiss tool. + + + + III. The Library class + + +You should find prototypes & declarations in the +./dll/classes/libclass.hh file and definitions & implementations in +the ./dll/classes/libclass.cc file in the root of the glagen devel +directory. + +The Library class mainly consists of: + + a Filename string, + a handler void pointer, + and some important methods. + +I'll explain each method. + +III.1 Methods + + III.1a Library(), Library(string Filename) +These are the creators. They only create a new class. +The one with the string also initializes the Filename property to the +given value. + + III.1b ~Library() +The destructor. +It cleans the Library class, although it is not really necessary in +the measure we work on variables (not pointers), + + III.1c LoadLib(), LoadLib(string Filename) +This is one of the most important methods. It opens the file, tries to +obtain an handler and if succeed, stores this handler in the correct +property. +Then we call, if found, the GLG_Hello() symbol, in which the +devel-user should output some text in cout.. As he feels it. +It would be called once during the whole glagen process' life. +(Maybe two if using the network). +This method is used to obtain infos such as Library name and +dependancies, in order to sort it and check that no dependancy is +missing. Elsewhere, it would tell you the name of missing libraries +and ignore this one. And continue with next library. + + III.1d Initialize() +The great one. This method would be called once in the loading process +to calculate data size on the server, and then another time once +loaded in a client, to preserve an area in the data memory. +In this method, we would ask the user library to make as many palloc() +as it wants, each palloc, in the order, being allocating some data +memory. +For example: + + Library Foo needs to use and/or share three sorts of data in the + whole glagen process, for example a surface information, a color + one and the age of the captain. + Foo should have a GLG_Init() function like this : + + GLG_Init(...) + { + ... + palloc(surface, ...); + palloc(color, ...); + palloc(captainage, ...); + ... + } + + The library class linked with this library would then ask the + server for some memory rooms, and then stores three (because of + the three palloc()) keys in some deep owned property. + During the main loop, the library should only ask to read or + write its third room to obtain or modify the captainage. + + III.1e diff --git a/dll/Makefile b/dll/Makefile new file mode 100644 index 0000000..b3db10d --- /dev/null +++ b/dll/Makefile @@ -0,0 +1,72 @@ +################################################################ +# GLAGEN Project (http://www.planetmarvin.zyns.com/) # +# Makefile done by Titi # +# i686 specifications added by Onidwa # +################################################################ + +CC = g++ +RM = rm -fr + +NAME = glagen-$(MODULE)-$(VERSION).$(SUBVERSION) +MODULE = libloader +VERSION = 2 +SUBVERSION = 01b + +KERNEL = `uname -s` + +DEBUG = + +OBJS = $(SRCS:.cc=.o) +HDRS = $(SRCS:.cc=.hh) +SRCS = classes/libclass.cc\ + classes/matrix.cc\ + classes/node.cc\ + classes/Data_string.cc\ + classes/Data_property.cc\ + create_dotproperty_init.cc\ + libraryloader.cc\ + main.cc + +ARCHI_NetBSD = $(DEBUG) -g2 -Wall -W -O3 +CPP_NetBSD = -I/usr/include\ + -I/usr/include/GL\ + -I/usr/X11R6/include +LIB_NetBSD = -L/usr/X11R6/lib\ + -L/usr/lib\ + -L/usr/pkg/lib\ + -lc\ + -lm\ + -lX11\ + -lGL\ + -lGLU\ + -lglut + +ARCHI_Linux = $(DEBUG) -g2 -O3 -I/usr/X11R6/include +LIB_Linux = -L/usr/X11R6/lib\ + -L/usr/include\ + -L/usr/lib\ + -L/usr/pkg/lib\ + -lc\ + -lm\ + -lX11\ + -lGL\ + -lGLU\ + -lglut +CPP_Linux = -I.\ + -I/usr/include + +.PHONY: all clean deps + +all: $(OBJS) + $(CC) -o $(NAME) $(CPP_Linux) $(OBJS) $(LIB_Linux) $(ARCHI_Linux) + +.cc.o: + $(CC) $(ARCHI_Linux) $(CPP_Linux) -c $< -o $(<:.cc=.o) + +clean: + $(RM) $(OBJS) $(NAME) *~ */*~ \#*\# + +deps: + makedepend $(SRC) 2>/dev/null + +re: clean all diff --git a/dll/NOTES b/dll/NOTES new file mode 100644 index 0000000..19b48fa --- /dev/null +++ b/dll/NOTES @@ -0,0 +1,13 @@ + +Parcours de la matrice d'adjacence, +a chaque fois que je tombe sur un noeud +de dependance, j'ajoute un fils et je +mets cette dependance a zero. + +Je continue jusqu'a ce que tout le monde ait +0 dependances (matriciellement parlant) + +Probleme... + +Des dependances croisees, en dehors de la matrice.. +On va dire que pour le moment, on s'en fout. diff --git a/dll/README b/dll/README new file mode 100644 index 0000000..36d270e --- /dev/null +++ b/dll/README @@ -0,0 +1,237 @@ + + ============================= + Dynamic Library Loader Module + ============================= + GLAGEN - 2002 - Hugues HIEGEL + + + + + I. What is it ? + + +The Dynamic Library Loader Module (DLL Module) is part of the GLAGEN +Engine. It goals is to provide to the end-user a flexible usage of +external C/C++ libraries (*.so) . + +At this time, only C++ libraries are supported, because the main DLL +Module is already written in C++. It should be easy to allow C-written +libraries, but du to a lack of time, it should appear.. later. + + + II. How does it work ? + + +The DLL Engine reads all libraries, especially their Names and +Dependancies, and then builds a dependancies tree. This last would be +used by the Network module (written by lam_m), and should determine in +which order each library would be executed in the main loop. +For example: + + library A needs nobody, alike library B. Libraries AC and AD needs + A, BE and BF need B, ACG needs AC and BFH needs BF. + We would obtain such a tree: + + (root) + \__________________ + | | + A B + \_______ \_____ + | | | | + AC AD BE BF + \_ \_ + | | + ACG BFH + + + Then the execution order would be done in such an order, reading + the tree top-to-bottom, then left-to-right: + A-AC-ACG-AD-B-BE-BF-BFH + + Like that, we are certain that any library would be able to read + the results of one of its dependancies. + +I did a Library class that contains a lot of infos about each +library.so. For each library file, I effectively create a new Library +instance, and initialize it by opening the library, ang trying to get +infos using dlsym and some canonical symbols (See section above for +more info about libraries' symbols). If the library do answer to the +required ones, then it is stored, else it is immediately closed and +forgotten. + +Along the program, we will mainly work with list of Libraries, for +this class is our swiss tool. + + + + III. The Library class + +In this section, I will explain the main characteristics of this class +and the method used. + + III.0 Hello, Bye + +First of all, we allow the user to make two functions in its library : +GLG_Hello and GLG_Bye, in which he could put an hello and bye message +to the standard out. For example. He also could wathever he wants in +them, but no initialisation. These would be desribed in the next +chapter. Hello and Bye are there just to give flexibility and a bit of +fun. + + III.1 Initialisation + +Creating a new Library class and Loading it consists in giving a +library filename, trying to open it, then trying to obtain a DL +handler. +If a handler is obtained, we load some Symbols to check if it is +a real GLAGEN library : the .so must return a name as a string in +respond to the call at GLG_Name(). Then we try to get its dependancies. +These infos are finally used to generate the dependances tree ahead. +The dependancies are given under a list of string, that make the +treatment easier. + +Each library is allowed to use as many properties it wants for every +3d engine's dot. Each dot has a list of properties, and this list is +created by a recursive call of every library's GLG_Init symbol. Each +library class associated with each library file retains for each +property requested its position in the global list of properties. +For example: + + Library Foo needs to use and/or share three sorts of data in the + whole glagen process, for example a surface information, a color + one and the age of the captain. + Foo should have a GLG_Init() function like this : + + GLG_Init(...) + { + ... + palloc(surface, ...); + palloc(color, ...); + palloc(captainage, ...); + ... + } + + The library class linked with this library would then ask the + server for some memory rooms, and then stores three (because of + the three palloc()) keys in some deep owned property. + During the main loop, the library should only ask to read or + write its third room to obtain or modify the captainage. + It doesn't even know the captainage is really stored in some + 42nd room in the whole 'memory'. + +palloc() is a function that calls itself a method of the current +calling library, so this library can stores the global acces method on +the local machine. +For that, the initialize() method gives a pointer to (this) to the +GLG_Init of the dll. Then this dll has nothing to do qith this +pointer, just give it as a parameter to palloc(). This palloc(), +defined out of the library class, calls then the REF->_palloc() method. +I didn't found a simpliest method to do that, because I didn't want +the dll developper hav to know anything about the Library class. +If I forced him to call REF->_palloc() instead of palloc(REF), he +would have to know the REF* prototype for its GLG_Init definition, +then he would have to use the libraryclass header. +My goal is to provide him a 'totally' independant code. So, I choose +to make him take a void* REF in its GLG_Init(), and then give this +void* REF to palloc, which takes it as a Libary*. +See code for more details : ./dll/classes/libclass.hh and a sample +library code. + + + III.2 Global properties accesses + +Two functions allow libraries to access dots properties, in read or +write mode. +For example: + + Library17 has 3 dots properties, declared in order (the 1st in + first place, the 2nd in second place and the 3rd in last). + The library's user know what is the first property, what is the + second, and what is the third. For example, he decides the first + property is the color, the second the height, and + god-know-whatever is the third. When he wants to access the color + property, he would only call a GLG_read(2, ...) function. + This function will then call a method of the current class to get + the REAL position of this 2nd element in the whole list of + properties, shared by many other libraries.. + And then, the access of the '2nd' element would be transparent to + the user. + +There is also a GLG_write function based on same principle. They both +looks like read and write standard C functions, which is absolutely +natural. + +The main difficulty of these functions were that I didn't know in +which level the efficient read and write should be done. In the +library engine ? In which level ? Client-side ? Server-side ? If +ti is in Client-side, how would the server know ? If it is in +Server-side, how would the Client know ?? + +So, we decided to keep one dot property tab in each computer (clients +and server), make all inits, reads and writes in the local computer. +A first initialisation is made in the server, to know the global size +of a dot property tab. Then a second is done in each client, which +returns to the server the total size found. Then the server knows what +it will allocate for each client. +Example: + + The server loads libraries A, AC and B. A needs 4 bytes, AC needs + 3, and B needs 5. The server knows that A and AC will be sent to + the client1. Then he allocates 4+3 then 7 bytes to client1, and + the 5 last bytes to client2. Client1 receives A and AC, reads them + and finds 7 bytes to allocate locally. Client2 will find 5 bytes + to allocate locally. After each main loop, client1 will send its 7 + bytes to the server, who will put them in right place. Client2 + sends its 5 bytes, and the server puts them in back of the 7 first + bytes. + +That is trivial. Although this is the network part, I did the routine +to make that. The source code can be found in +create_dotproperty_init.cc file. It has to be included in right place +in the clients and server main functions. + + + III.3 Main loop + +Not yet fully implemented. +The main loop call is called GLG_Main, and would take as argument a +Dot* pointer. Then the user has to include the dot.hh header, found in +the 3d engine directory or in the ./classes folder. +In this main loop, the user just has to read and write properties in +the given Dot. The time and other dot-independant informations should +be given in a method that has not really been specified at this time. +The read function calls should be done specifiying a library name, and +the result will be given only if the current library has read access +to the given one. There, the dependancies takes all its meaning. +But why would we do more processing by checking the permissions ? This +permitts Glagen to be a clean processus. +However, a library could read its dependancies properties and +recursively the dependancies of its dependancies. That would look more +natural in this way. +Note that there are two 'system' properties, such as primary color and +primary height of the dot. 'Primary', because one 'dot' should +represent superposed surfaces' dots. +Finally, some Perlin noise functions should have been given in this +level, allowing the user to make realistic world renderings. +Just see the sun example in our website to be convinced ;) + + + IV. Conclusion + +This part is not yet finished, due to some difficulties to understand +how would my module work in the global project. The mainloop call +is not realy finished, but some minor changes have to be done. +The main squeletton is already the module itself, so I am globally +satisfied about my work, although I would be more satisfied if it were +really included in the final project. +Since it is under GPL, I would not abandon it. I spent too much time +on it to give forfeit. Without the pressure of the school, I would +certainly end my module and best it in great state of spirit. + +The main reason, I think, that I didn't finish my part in time, is +that I spent to much time on making a clean code. A program that +doesn't bug without reason. This is the most important to me. +If I made a code in the only goal to make a finished product, I would +certainly hav missed lots of bugs, and the final result code would +have been so awful I would never continue it. +did diff --git a/dll/classes/Data_property.cc b/dll/classes/Data_property.cc new file mode 100644 index 0000000..3be4b27 --- /dev/null +++ b/dll/classes/Data_property.cc @@ -0,0 +1,30 @@ +//============================================================================= +// +// Glagen : a planet sized landscape generator +// Copyright (C) 2002 Julien Guertault, Hugues Hiegel, Meng-Tih Lam +// +// 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. +// +//============================================================================= +// +// Glagen : GPL LAndscape GENerator +// +// Data_property.cc for Glagen : made by Titi (Meng-tih LAM) +// +// www.glagen.org +// +//============================================================================= + +#include "Data_property.hh" diff --git a/dll/classes/Data_property.hh b/dll/classes/Data_property.hh new file mode 100644 index 0000000..b4d0c4d --- /dev/null +++ b/dll/classes/Data_property.hh @@ -0,0 +1,88 @@ +//============================================================================= +// +// Glagen : a planet sized landscape generator +// Copyright (C) 2002 Julien Guertault, Hugues Hiegel, Meng-Tih Lam +// +// 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. +// +//============================================================================= +// +// Glagen : GPL LAndscape GENerator +// +// Data_property.hh for Glagen : made by Titi (Meng-tih LAM) +// +// www.glagen.org +// +//============================================================================= + +#ifndef DATA_PROPERTY_HH_ +# define DATA_PROPERTY_HH_ + +#include +#include +#include // Pour write/read + +#include + +#include "../../3d/data_glagen.hh" + +class Data_property +{ +public: + Data_property() : _data(0), _size(0), _type(kind_lib_t(none)) {} + Data_property(void* data, size_t size, kind_lib_t type) + : _data(data), + _size(size), + _type(type) + {} + + void write_data(const int& fd) const + { + write(fd, &_type, sizeof(int)); + write(fd, &_size, sizeof(int)); + write(fd, _data, _size * sizeof(void *)); + } + + void read_data(const int& fd) + { + do + { + errno = 0; + read(fd, &_type, sizeof(int)); + } + while (errno == 4); + + do + { + errno = 0; + read(fd, &_size, sizeof(int)); + } + while (errno == 4); + + do + { + errno = 0; + read(fd, _data, _size * sizeof(void *)); + } + while (errno == 4); + } + +protected: + void *_data; + size_t _size; + kind_lib_t _type; +}; + +#endif // DATA_PROPERTY_HH_ diff --git a/dll/classes/Data_string.cc b/dll/classes/Data_string.cc new file mode 100644 index 0000000..49fe4ff --- /dev/null +++ b/dll/classes/Data_string.cc @@ -0,0 +1 @@ +#include "Data_string.hh" diff --git a/dll/classes/Data_string.hh b/dll/classes/Data_string.hh new file mode 100644 index 0000000..a5f9131 --- /dev/null +++ b/dll/classes/Data_string.hh @@ -0,0 +1,62 @@ +#ifndef DATA_STRING_HH_ +# define DATA_STRING_HH_ + +#include +#include +#include // Pour write/read + +#include + +using namespace std; + +class Data_string +{ +public: + Data_string() : _str("") {}; + Data_string(const string& str) : _str(str) {}; + + void write_data(const int& fd) const + { + + std::cout << "Donnees envoyes" << std::endl << _str << std::endl; + unsigned int size = _str.size(); + write(fd, &size, sizeof(unsigned int)); + for (unsigned int i = 0; i < size; ++i) + { + char car = _str[i]; + write(fd, &car, sizeof(char)); + } + } + + void read_data(const int& fd) + { + unsigned int size = 0; + do + { + errno = 0; + read(fd, &size, sizeof(size)); + } + while (errno == 4); + + _str = ""; + for (unsigned int i = 0; i < size; ++i) + { + char car; + do + { + errno = 0; + read(fd, &car, sizeof(char)); + } + while (errno == 4); + _str += car; + } + + std::cout << "Reception message sur le file descriptor :" << fd + << std::endl << _str << std::endl; + } + +private: + string _str; +}; + +#endif // DATA_STRING diff --git a/dll/classes/GLG-libraries-devel.cc b/dll/classes/GLG-libraries-devel.cc new file mode 100644 index 0000000..002d479 --- /dev/null +++ b/dll/classes/GLG-libraries-devel.cc @@ -0,0 +1,32 @@ +//============================================================================= +// +// Glagen : a planet sized landscape generator +// Copyright (C) 2002 Julien Guertault, Hugues Hiegel, Meng-Tih Lam +// +// 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. +// +//============================================================================= +// +// Glagen : GPL LAndscape GENerator +// +// GLG-libraries-devel.cc for Glagen : made by Hugues HIEGEL +// +// www.glagen.org +// +//============================================================================= + +#include "GLG-libraries-devel.hh" +#include "libclass.hh" + diff --git a/dll/classes/GLG-libraries-devel.hh b/dll/classes/GLG-libraries-devel.hh new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/dll/classes/GLG-libraries-devel.hh @@ -0,0 +1 @@ + diff --git a/dll/classes/dot.cc b/dll/classes/dot.cc new file mode 100644 index 0000000..10e766a --- /dev/null +++ b/dll/classes/dot.cc @@ -0,0 +1,100 @@ +// +// dot.cc for Glagen in ~/Galgen/3d +// +// Made by Zavie +// Login +// +// Started on Fri Aug 16 17:08:16 2002 Zavie +// + +#include +#include +#include +#include "data_glagen.hh" +#include "dot.hh" + +// Constructor and destructor +Dot :: Dot (double x, double y, double z) +{ + int current; + + _x = x; + _y = y; + _z = z; + _use = 0; + _property = new void *[GL_property]; + for (current = 0; current < GL_property; current++) + _property[current] = NULL; + step = GL_step; +} + +Dot :: ~Dot () +{ + int current; + + for (current = 0; current < GL_property; current++) + if (_property[current] != NULL) + delete _property[current]; +} + +// Reading +double Dot :: x () { return _x; } +double Dot :: y () { return _y; } +double Dot :: z () { return _z; } + +void *Dot :: Property (int i) +{ + return _property[i]; +} +bool Dot :: Is_checked () { return (step == GL_step); } + +// Writing +void Dot :: set (double x, double y, double z) +{ + _x = x; + _y = y; + _z = z; +} + +void Dot :: Use () { _use = _use + 1; } + +void Dot :: Drop () +{ + _use = _use - 1; + if (0 == _use) + { + delete this; + printf("destroy !\n"); + } +} + +void Dot :: Del_property (int i) +{ + delete _property[i]; + _property[i] = NULL; +} + +void Dot :: Set_property (int i, void *property) +{ + _property[i] = property; +} + +void Dot :: Checked () { step = GL_step; } + +// Other tools +Dot *Dot :: Middle (Dot *b) +{ + double xc; + double yc; + double zc; + double adjust; + + xc = (this->x () + b->x ()) / 2; + yc = (this->y () + b->y ()) / 2; + zc = (this->z () + b->z ()) / 2; + adjust = sqrt (GL_square_size / (xc * xc + yc * yc + zc * zc)); + xc = xc * adjust; + yc = yc * adjust; + zc = zc * adjust; + return new Dot (xc, yc, zc); +} diff --git a/dll/classes/dot.hh b/dll/classes/dot.hh new file mode 100644 index 0000000..e13f23c --- /dev/null +++ b/dll/classes/dot.hh @@ -0,0 +1,49 @@ +// +// dot.hh for Glagen in ~/Galgen/3d +// +// Made by Zavie +// Login +// +// Started on Fri Aug 16 17:08:16 2002 Zavie +// + +#ifndef DOT_HH_ +# define DOT_HH_ + +class Dot +{ +public: + + // Constructor and destructor + Dot (double x, double y, double z); + ~Dot (); + + // Reading + double x (); + double y (); + double z (); + + void *Property (int i); + bool Is_checked (); + + // Writing + void set (double x, double y, double z); + void Use (); + void Drop (); + void Del_property (int i); + void Set_property (int i, void *property); + void Checked (); + + // Other tools + Dot *Middle (Dot *b); + +protected: + double _x; + double _y; + double _z; + unsigned char _use; + void **_property; + char step; +}; + +#endif // DOT_HH_ diff --git a/dll/classes/libclass.cc b/dll/classes/libclass.cc new file mode 100644 index 0000000..730026f --- /dev/null +++ b/dll/classes/libclass.cc @@ -0,0 +1,391 @@ +//============================================================================= +// +// Glagen : a planet sized landscape generator +// Copyright (C) 2002 Julien Guertault, Hugues Hiegel, Meng-Tih Lam +// +// 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. +// +//============================================================================= +// +// Glagen : GPL LAndscape GENerator +// +// libclass.cc for Glagen : made by Hugues HIEGEL +// +// www.glagen.org +// +//============================================================================= +//--LIBRARY CLASS IMPLEMENTATION--// + +#include +#include +#include +#include +#include + +#include "../includes/errors.hh" +#include "libclass.hh" + +using std::cout; +using std::cerr; +using std::endl; + +/****************************************** +* Constructors * +* && Destructors * +******************************************/ +Library::Library() +{ +} + +Library::Library(string Filename) +{ + this->Filename = Filename; + this->properties.clear(); +} + +Library::~Library() +{ + if (this->handler) + this->UnloadLib(); + this->Filename = ""; + this->properties.clear(); +} + +/****************************************** +* Loaders * +* -just loads libs files- * +******************************************/ +int Library::LoadLib(string Filename) +{ + this->Filename = Filename; + return this->LoadLib(); +} + +int Library::LoadLib() +{ + + this->properties.clear(); + + /* + ** Tries to open the library itself + */ + this->handler = dlopen(Filename.c_str(), RTLD_LAZY); + + if (!(this->handler)) /* This is not a library */ + { + cerr << "#Err " << ERR_OPENLIB + << ": " << dlerror() << "" << endl; + return ERR_OPENLIB; + } + + typedef string (*name_t)(); + name_t Name = (name_t) dlsym(this->handler, "GLG_Name"); + if (!Name) + { + cerr << "#Err " << ERR_LIBSYMBOL + << ": Missing symbol 'string GLG_Name()' in " + << this->Filename << "" << endl; + return ERR_LIBSYMBOL; + } + + cout << "Loading library: "; + cout << Name(); + + // This shows the dependancies in loading time. + list deps; + std::list::iterator deps_i; + deps = this->getDependancies(); + if (! deps.empty()) + { + cout << " {"; + for (deps_i = deps.begin(); + deps_i != deps.end(); + deps_i++) + cout << *deps_i << ", "; + cout << "}"; + } + cout << endl; + + typedef void* (*hello_t)(); + hello_t Hello = (hello_t) dlsym(this->handler, "GLG_Hello"); + if (Hello) + Hello(); + + return 0; +} + +int Library::Initialize() +{ + cout << "Moteur\tlibrary::initialize " << endl ; + + // typedef int (*init_t)(void*, Library*); + // init_t Init = (init_t) dlsym(this->handler, "GLG_Init"); + // if (Init) + // Init(palloc, this); + + /*********************************************** + ** typedef struct dot_property_t { ** + ** int pos; ** + ** size_t size; ** + ** }; ** + ** ** + ** std::list this->properties ** + ***********************************************/ + return 0; + +} + +int Library::MainLoop(Dot* dot) +{ + cout << "Moteur\tlibrary::mainloop " << endl ; + + typedef int (*main_t)(Dot*, void*); + main_t _Main = (main_t) dlsym(this->handler, "GLG_Main"); + if (_Main) + _Main(dot, NULL); + + return 0; + +} + +/****************************************** +* Miscellaneous stuffs * +* Useful functions * +******************************************/ +list Library::getDependancies() const +{ + + /* + ** Gets all library's dependancies + */ + + typedef list (*deps_t)(); + deps_t Deps = (deps_t) dlsym(this->handler, "GLG_Dependancies"); + + list deps; + deps.clear(); + + if (!Deps) + return deps; + + deps = Deps(); + return deps; +} + +string Library::getName() const +{ + + /* + ** Gets the library's basename + */ + + typedef string (*name_t)(); + name_t Name = (name_t) dlsym(this->handler, "GLG_Name"); + + if (!Name) + return this->Filename; + + return Name(); +} + + +string Library::getFilename() const +{ + return this->Filename; +} + +list Library::getDotProperties() const +{ + return this->properties; +} + + +int Library::getRealPos(int pos) const +{ + std::list::const_iterator prop_i; + int i = 0; + + for (prop_i = this->properties.begin(); + (i < pos) && (prop_i != this->properties.end()); + prop_i++) + i++; + + if (i != pos) + return (-1); + return (prop_i->pos); +} + + +int Library::AccesAllowed(string& ToLib) const +{ + if (ToLib == this->getName()) + return 1; + + int allowed = 0; + + std::list deps = this->getDependancies(); + std::list::const_iterator dep_i; + + for (dep_i = deps.begin(); + !allowed && (dep_i != deps.end()); + dep_i++) + allowed = (*dep_i == ToLib); + + return allowed; + +} + +/****************************************** +* Unloader * +* -closes the library handler if exists- * +******************************************/ +void Library::UnloadLib() +{ + using std::cout; + using std::cerr; + using std::endl; + + /* + ** Asks the library to say 'Bye' + */ + cout << "Closing library: "; + + typedef string (*name_t)(); + name_t Name = (name_t) dlsym(this->handler, "GLG_Name"); + cout << Name() << endl; + + typedef string (*bye_t)(); + bye_t Bye = (bye_t) dlsym(this->handler, "GLG_Bye"); + if (Bye) + Bye(); + + dlclose(this->handler); +} + +/****************************************** +* _palloc * +* stores infos on dot properties needed * +******************************************/ +void Library::_palloc(kind_lib_t type, size_t size) +{ + // in (*this) handler, we will store all this shit. + GLG_property_pos++; + + cout << "\tThis is this->_palloc" << endl; + + dot_property_t property; + property.pos = GLG_property_pos; + property.size = size; + property.type = type; + + this->properties.push_back(property); + + return ; +} + + +/****************************************** +* Utilities * +* external functions needed for developers* +******************************************/ + +/* I am sure I know that ?? */ +extern list Client_DotPropertyTab; +extern const list list_libs; + +Library* getLibraryByName(const string Name, const list list_libs) +{ + std::list::const_iterator lib_i; + for (lib_i = list_libs.begin(); + (lib_i->getName() != Name) && (lib_i != list_libs.end()); + lib_i++) + ; + /* Yeah, we got the library. */ + + Library* toto = NULL; + (*toto) = *lib_i; + return (toto); +} + +void GLG_write(int pos, size_t size, void* data, Library* REF) +{ + int real_pos = REF->getRealPos(pos); + if (real_pos > -1) + { + std::list::const_iterator prop_i; + int i = 0; + for (prop_i = Client_DotPropertyTab.begin(); + (i < real_pos) && (prop_i != Client_DotPropertyTab.end()); + prop_i++) + ; + if (i == real_pos) + memcpy(prop_i->data, data, size); /* ou alors j'ai rien compris */ + } + +} + +void GLG_read(string& LibName, int pos, size_t size, void* data, Library* REF) +{ + cout << REF->getName() << " hvufidoshvuiovhfudsviofdhvudiso" << endl; + + if (/*REF->AccessAllowed(LibName)*/ 1) + { + + Library* Lib = getLibraryByName(LibName, list_libs); + + int real_pos = Lib->getRealPos(pos); + if (real_pos > -1) + { + std::list::const_iterator prop_i; + int i = 0; + for (prop_i = Client_DotPropertyTab.begin(); + (i < real_pos) && (prop_i != Client_DotPropertyTab.end()); + prop_i++) + ; + if (i == real_pos) + memcpy(data, prop_i->data, size); /* ou alors j'ai rien compris */ + } + } + + return ; +} + +void GLG_read(int pos, size_t size, void* data, Library* REF) +{ + string toto = REF->getName(); + GLG_read(toto, pos, size, data, REF); +} + +void palloc(kind_lib_t type, size_t size, Library* REF) +{ + cout << "\tThis is palloc itself" << endl; + + /************************************************* + ** ** + ** From a .so, we cannot call a class method. ** + ** But we need to do that !! ** + ** ** + ** So, I made this little shortcut : ** + ** a function that takes a class pointer, ** + ** and that calls the real method. ** + ** ** + ** So easy. ** + ** ** + *************************************************/ + + REF->_palloc(type, size); + return ; +} + diff --git a/dll/classes/libclass.hh b/dll/classes/libclass.hh new file mode 100644 index 0000000..33a2fde --- /dev/null +++ b/dll/classes/libclass.hh @@ -0,0 +1,91 @@ +//============================================================================= +// +// Glagen : a planet sized landscape generator +// Copyright (C) 2002 Julien Guertault, Hugues Hiegel, Meng-Tih Lam +// +// 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. +// +//============================================================================= +// +// Glagen : GPL LAndscape GENerator +// +// libclass.hh for Glagen : made by Hugues HIEGEL +// +// www.glagen.org +// +//============================================================================= +//--LIBRARY CLASS DEFINITION--// + +#include +#include +#include + +#include "../../3d/data_glagen.hh" +#include "Data_property.hh" + +#ifndef LIBCLASS_HH_ +# define LIBCLASS_HH_ + +using namespace std; +extern int GLG_property_pos; + +typedef struct dot_property_t { + int pos; + size_t size; + kind_lib_t type; +}; + +class Library +{ +public: + + Library(); + Library(string Filename); + virtual ~Library(); + + // int FirstLoad(); // ??? + int LoadLib(); + int LoadLib(string Filename); + int Initialize(); + int MainLoop(Dot* dot); + void _palloc(kind_lib_t type, size_t size); + + // int MainLoop(Dot* dot, ...); + + int Uninitialize(); + void UnloadLib(); + + list getDependancies() const; + string getName() const; + string getFilename() const; + list getDotProperties() const; + int getRealPos(const int pos) const; + int AccesAllowed(string& ToLib) const; + +private: + string Filename; + void *handler; + std::list dependancies; + std::list properties; + +}; + +void palloc(kind_lib_t type, size_t size, Library* REF); + +void GLG_write(int pos, size_t size, void* data, Library* REF); +void GLG_read(string& LibName, int pos, size_t size, void* data, Library* REF); +void GLG_read(int pos, size_t size, void* data, Library* REF); + +#endif //LIBCLASS_HH_ diff --git a/dll/classes/matrix.cc b/dll/classes/matrix.cc new file mode 100644 index 0000000..7991769 --- /dev/null +++ b/dll/classes/matrix.cc @@ -0,0 +1,3 @@ + + +#include "matrix.hh" diff --git a/dll/classes/matrix.hh b/dll/classes/matrix.hh new file mode 100644 index 0000000..f49ea17 --- /dev/null +++ b/dll/classes/matrix.hh @@ -0,0 +1,324 @@ +// matrix.hh + +#include + +#ifndef REALMATRIX_HH_ +# define REALMATRIX_HH_ + +// la class TYPE ne peut etre que de type nombre (ex: double, int, long,...) + +template class Matrix +{ +public: + // Constructor + Matrix(const unsigned int i, const unsigned int j) + { + this->_i = i; + this->_j = j; + this->_lines = new _line[i]; // Create lines... + for (unsigned int k = 0; k < i; ++k) + this->_lines[k] = new TYPE[j]; // ...and create column + for (unsigned int k = 0; k < i; ++k) + for (unsigned int l = 0; l < j; ++l) + this->_lines[k][l] = 0; + } + + // Constructor by copy + Matrix(const Matrix& mat) + { + this->_i = mat._i; + this->_j = mat._j; + this->_lines = new _line[this->_i]; + for (unsigned int k = 0; k < this->_i; ++k) + { + this->_lines[k] = new TYPE[this->_j]; + for (unsigned int l = 0; l < this->_j; ++l) + this->_lines[k][l] = mat._lines[k][l]; + } + } + + // Destructor + ~Matrix() + { + if (this->_i != 0 || this->_j != 0) + { + for (unsigned int i = 0; i < this->_i; i++) + delete [] this->_lines[i]; + delete [] this->_lines; + } + } + + // Affected operator + Matrix& operator=(const Matrix& mat) + { + if (&mat != this) + { + if (mat._i != this->_i || mat._j != this->_j) // Test dim + { + this->~Matrix(); // Destroy... + this->_i = mat._i; + this->_j = mat._j; + this->_lines = new _line[this->_i]; // ...and realloc + for (unsigned int i = 0; i < this->_i; ++i) + this->_lines[i] = new TYPE[this->_j]; + } + for (unsigned int i = 0; i < this->_i; ++i) // Copy + for (unsigned int j = 0; j < this->_j; ++j) + this->_lines[i][j] = mat._lines[i][j]; + } + return (*this); + } + + // Add elements to matrix + Matrix& add_elems(const int& nb) + { + Matrix mat(this->_i + nb, this->_j + nb); + for (unsigned int i = 0; i < this->_i; i++) + for (unsigned int j = 0; j < this->_j; j++) + mat(i, j) = this->_lines[i][j]; + *this = mat; + return (*this); + } + + // Add matrix to matrix + Matrix& add_mat(const Matrix& mat) + { + unsigned int i = this->_i; + unsigned int j = this->_j; + this->add_elems(mat._i); + for (unsigned int k = i; k < this->_i; k++) + for (unsigned int l = j; l < this->_j; l++) + this->_lines[k][l] = mat(k - i, l - j); + return (*this); + } + + // Add of matrix + Matrix operator+(const Matrix& mat) + { + Matrix mat_tmp(this->_i, mat._j); + if (this->_i != mat._i || this->_j != mat._j) + { + std::cerr << "Error of addiction of 2 matrix (dimensions)"\ + << std::endl; + return (mat_tmp); + } + for (unsigned int i = 0; i < this->_i; ++i) + for (unsigned int j = 0; j < this->_j; ++j) + mat_tmp._lines[i][j] = this->_lines[i][j] + mat._lines[i][j]; + return (mat_tmp); + } + + Matrix operator+(const Matrix& mat) const + { + Matrix mat_tmp(this->_i, mat._j); + if (this->_i != mat._i || this->_j != mat._j) + { + std::cerr << "Error of addiction of 2 matrix (dimensions)"\ + << std::endl; + return (mat_tmp); + } + for (unsigned int i = 0; i < this->_i; ++i) + for (unsigned int j = 0; j < this->_j; ++j) + mat_tmp._lines[i][j] = this->_lines[i][j] + mat._lines[i][j]; + return (mat_tmp); + } + + // Sub matrix + Matrix operator-(const Matrix& mat) + { + Matrix mat_tmp(this->_i, mat._j); + if (this->_i != mat._i || this->_j != mat._j) + { + std::cerr << "Error of substraction of 2 matrix (dimensions)"\ + << std::endl; + return (mat_tmp); + } + for (unsigned int i = 0; i < this->_i; ++i) + for (unsigned int j = 0; j < this->_j; ++j) + mat_tmp._lines[i][j] = this->_lines[i][j] - mat._lines[i][j]; + return (mat_tmp); + } + + Matrix operator-(const Matrix& mat) const + { + Matrix mat_tmp(this->_i, mat._j); + if (this->_i != this->_j || this->_i != mat._i || mat._i != mat._j) + { + std::cerr << "Error of substraction of 2 matrix (dimensions)"\ + << std::endl; + return (mat_tmp); + } + for (unsigned int i = 0; i < this->_i; ++i) + for (unsigned int j = 0; j < this->_j; ++j) + mat_tmp._lines[i][j] = this->_lines[i][j] - mat._lines[i][j]; + return (mat_tmp); + } + + // Multiplication of matrix + Matrix operator*(const Matrix& mat) + { + Matrix mat_tmp(this->_i, mat._j); + if (this->_j != mat._i) // Check dimension + { + std::cerr << "Error of produce of 2 matrix (dimensions)"\ + << std::endl; + return (mat_tmp); + } + for (unsigned int i = 0; i < this->_i; ++i) + { + for (unsigned int j = 0; j < mat._j; ++j) + { + TYPE res = 0; + // Produce lines and column of matrix + for (unsigned int k = 0; k < this->_j; ++k) + res += this->_lines[i][k] * mat._lines[k][j]; + mat_tmp._lines[i][j] = res; + } + } + return (mat_tmp); + } + + // Multiplication with real + Matrix& operator*(const TYPE& nbr) + { + for (unsigned int i = 0; i < this->_i; i++) + for (unsigned int j = 0; j < this->_j; j++) + { + this->_lines[i][j] *= nbr; + } + return (*this); + } + + // Divide with real + Matrix& operator/(const TYPE& nbr) + { + for (unsigned int i = 0; i < this->_i; i++) + for (unsigned int j = 0; j < this->_j; j++) + { + this->_lines[i][j] /= nbr; + } + return (*this); + } + + //Get dimension of matrix + const int get_dim() const + { + if (this->_i != this->_j) + { + std::cerr << "Matrix isn't nxn, cannot give dimension" << std::endl; + return (0); + } + return (this->_i); + } + + // Operator to change mat(i, j) + // to can write mat(i, j) = ... + TYPE& operator()(unsigned int i, unsigned int j) + { + return (this->_lines[i][j]); + } + + // Operator to access mat(i, j) + // to can write int x = mat(i, j) + TYPE operator()(unsigned int i, unsigned int j) const + { + return (this->_lines[i][j]); + } + + // Test matrix nul + const bool test_nul() const + { + for (unsigned int i = 0; i < this->_i; i++) + for (unsigned int j = 0; j < this->_j; j++) + if (this->_lines[i][j] != 0) + return (0); + return (1); + } + + // Test diagonal matrix nul + const int test_diag() const + { + for (unsigned int i = 0; i < this->_i; i++) + if (this->_lines[i][i] != 0) + return (i); + return (-1); + } + + // Test diagonal matrix nul with element + const int test_diag(const unsigned int& j) const + { + for (unsigned int i = 0; i < this->_i; i++) + if (this->_lines[i][i] != 0 && i == j) + return (i); + return (-1); + } + + // Calculate trace + const TYPE trace() const + { + TYPE res = 0; + if (this->_i != this->_j) + { + std::cerr << "Matrix isn't nxn, cannot give trace" << std::endl; + return (0); + } + for (unsigned int i = 0; i < this->_i; i++) + res += this->_lines[i][i]; + return (res); + } + + // Transpose + Matrix& transpose() + { + if (this->_i != this->_j) + { + std::cerr << "Matrix isn't nxn, cannot transpose" << std::endl; + return (*this); + } + TYPE tmp = 0; + for (unsigned int i = 0; i < this->_i; i++) + for (unsigned int j = 0; j < i; j++) + { + tmp = this->_lines[i][j]; + this->_lines[i][j] = this->_lines[j][i]; + this->_lines[j][i] = tmp; + } + return (*this); + } + + Matrix transpose() const + { + Matrix mat(this->_j, this->_i); + for (unsigned int i = 0; i < this->_i; i++) + for (unsigned int j = 0; j < this->_j; j++) + mat._lines[i][j] = this->_lines[j][i]; + return (mat); + } + + // Display matrix + void print(std::ostream &os) const + { + for (unsigned int i = 0; i < this->_i; ++i) + { + for (unsigned int j = 0; j < this->_j; ++j) + os << this->_lines[i][j] << " "; + os << std::endl; + } + } + +protected: + typedef TYPE* _line; + _line* _lines; + unsigned int _i; // Number of lines + unsigned int _j; // Number of column +}; + +template +inline std::ostream& operator<<(std::ostream& ostr, const Matrix& stream) +{ + stream.print(ostr); + return (ostr); +} + + +#endif // MATRIX_HH diff --git a/dll/classes/node.cc b/dll/classes/node.cc new file mode 100644 index 0000000..a3ae387 --- /dev/null +++ b/dll/classes/node.cc @@ -0,0 +1,11 @@ +// +// node.cc for in +// +// Made by meng-tih lam +// Login +// +// Started on Fri Aug 16 02:40:40 2002 meng-tih lam +// Last update Fri Aug 16 02:41:05 2002 meng-tih lam +// + +#include "node.hh" diff --git a/dll/classes/node.hh b/dll/classes/node.hh new file mode 100644 index 0000000..3d8c838 --- /dev/null +++ b/dll/classes/node.hh @@ -0,0 +1,82 @@ + +#ifndef NODE_HH_ +# define NODE_HH_ + +using namespace std; + +#include +#include + +// Rajouter l'include correspondant a la template de TYPENODE +// + implemente le std::cout abtrait pour les tests + +template class Tree; // Declaration prealable + +template class Node +{ + friend class Tree; + +public: + Node(const TYPENODE &d) : _link(new std::list), _data(d) {} + + void add_child(const TYPENODE& value) { _link->push_back(Node(value)); } + + void add_tree_node(const Node& value) { _link->push_back(value); } + + TYPENODE get_data() const { return (_data); } + + const unsigned int get_nb_childs() const { return (_link->size()); } + + std::list* get_childs() const { return (_link); } + + unsigned int get_number_node() const + { + unsigned int number_childs = _link->size(); + std::list::const_iterator child = _link->begin(); + unsigned int number_node = 1; + for (unsigned int tmp = 0; tmp != number_childs; ++tmp) + { + number_node += child->get_number_node(); + ++child; + } + return (number_node); + } + + // Renvoie le noeud fils suivant le numero a partir de 0 + Node get_child(const unsigned int& i) const + { + assert(i < _link->size()); + std::list::const_iterator child = _link->begin(); + for (unsigned int tmp = 0; tmp != i; ++tmp) + ++child; + return (*child); + } + + // Numerotation de l'arbre suivant un parcours en largeur de 0 a n + Node get_node_course_width(const int& ptr) const + { + int rptr = ptr; + std::list ptr_node = *new std::list; + ptr_node.push_back(*this); + while (ptr_node.size()) + { + std::list::iterator childs = ptr_node.begin(); + std::list::iterator child = childs->get_childs()->begin(); + for (; child != childs->get_childs()->end(); ++child) + { + ptr_node.push_back(*child); + if (--rptr == 0) + return (*child); + } + ptr_node.pop_front(); + } + return (*this); + } + +private: + + std::list *_link; // Pointeur vers le sous-arbre + TYPENODE _data; +}; + +#endif // NODE_HH_ diff --git a/dll/create_dotproperty_init.cc b/dll/create_dotproperty_init.cc new file mode 100644 index 0000000..56de80d --- /dev/null +++ b/dll/create_dotproperty_init.cc @@ -0,0 +1,86 @@ +//============================================================================= +// +// Glagen : a planet sized landscape generator +// Copyright (C) 2002 Julien Guertault, Hugues Hiegel, Meng-Tih Lam +// +// 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. +// +//============================================================================= +// +// Glagen : GPL LAndscape GENerator +// +// create_dotproperty_init.cc for Glagen : speedy made by Hugues HIEGEL +// +// www.glagen.org +// +//============================================================================= + +#include +#include "classes/libclass.hh" +#include "../3d/data_glagen.hh" + +/***************************************************************** +** Surement la plus crade de mes creations. ** +** La faute a ma comprehension qui a l'acuite de la ** +** bave d'escargot sur le sable Saharien. ** +*****************************************************************/ + +list Client_DotPropertyTab; +int GLG_property_pos = 0; + +list Create_DotProperty_Init(list ClientLibraries) +{ + std::list::iterator lib_i; + std::list PropertyList; + std::list PropLibList; + std::list::const_iterator libprop_i; + property_t prop; + + + /************************************* + ** We open libraries one by one ** + ** according the list order ** + *************************************/ + + for (lib_i = ClientLibraries.begin(); + lib_i != ClientLibraries.end(); + lib_i++) + { + lib_i->Initialize(); + + /************************************** + ** Then we read the properties one ** + ** by one according the library.. ** + **************************************/ + + PropLibList = lib_i->getDotProperties(); + for (libprop_i = PropLibList.begin(); + libprop_i != PropLibList.end(); + libprop_i++) + { + + prop.kind = libprop_i->type; + prop.size = libprop_i->size; + prop.data = malloc(libprop_i->size); + + PropertyList.push_back(prop); + + } + + } + + return PropertyList; + +} diff --git a/dll/create_dotproperty_init.hh b/dll/create_dotproperty_init.hh new file mode 100644 index 0000000..e69de29 diff --git a/dll/header.cc b/dll/header.cc new file mode 100644 index 0000000..92e361a --- /dev/null +++ b/dll/header.cc @@ -0,0 +1,28 @@ +//============================================================================= +// +// Glagen : a planet sized landscape generator +// Copyright (C) 2002 Julien Guertault, Hugues Hiegel, Meng-Tih Lam +// +// 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. +// +//============================================================================= +// +// Glagen : GPL LAndscape GENerator +// +// for Glagen : made by Hugues HIEGEL +// +// www.glagen.org +// +//============================================================================= diff --git a/dll/includes/errors.hh b/dll/includes/errors.hh new file mode 100644 index 0000000..00267fb --- /dev/null +++ b/dll/includes/errors.hh @@ -0,0 +1,19 @@ +/* +** +** GLAGEN Project Errors values +** 2002 aug 25 +** +** (made by hiegel_h) +*/ + +#define ERR_ARGNUM 1 +#define ERR_OPENFILE 2 + +#define ERR_NOLIBARG 3 +#define ERR_LIBMISSING 4 +#define ERR_OPENLIB 2 +#define ERR_LIBSYMBOL 10 +#define ERR_LIBNAME 11 + +#define ERR_NOROOTLIB 21 + diff --git a/dll/libraryloader.cc b/dll/libraryloader.cc new file mode 100644 index 0000000..9e8b67a --- /dev/null +++ b/dll/libraryloader.cc @@ -0,0 +1,322 @@ +//============================================================================= +// +// Glagen : a planet sized landscape generator +// Copyright (C) 2002 Julien Guertault, Hugues Hiegel, Meng-Tih Lam +// +// 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. +// +//============================================================================= +// +// Glagen : GPL LAndscape GENerator +// +// libraryloader.cc for Glagen : made by Hugues HIEGEL +// +// www.glagen.org +// +//============================================================================= + +#include +#include +#include + +#include "includes/errors.hh" +#include "classes/libclass.hh" +#include "libraryloader.hh" + +#include "classes/node.hh" +#include "classes/matrix.hh" +#include "classes/Data_string.hh" + + +using std::cout; +using std::cerr; +using std::endl; + +int +getLibID(const std::list* libids, + const string& name) +{ + // Searchs for an ID of the given library name + + if (libids->empty()) + return (-1); + + int libid = 0; + std::list::const_iterator libids_i = NULL; + + for (libids_i = libids->begin(); + (libids_i != libids->end()) && ((libids_i->getName()) != name); + libids_i++) + libid++; + + if (libid == (signed)libids->size()) + return (-1); + + return libid; + +} + + +void +RecursiveAddNode(const Node* Root, + Matrix* Adj, + const int size) +{ + int curr_node = 0; + const int nb_childs = Root->get_nb_childs(); + + if (nb_childs) + { + for (curr_node = 0; curr_node < nb_childs; curr_node++) + { + Node node = Root->get_child(curr_node); + + // Which library is a potentially dependancy ? + int curr_lib = node.get_data(); + + // Which libraries need it ? + for (int i_ = 0; i_ < size; i_++) + if ((*Adj)(i_, curr_lib) == 1) + { + node.add_child(i_); + (*Adj)(i_, curr_lib) = 2; + } + RecursiveAddNode(&node, Adj, size); + } + } + + return; + +} + +void +Int2Datanode(Node* Root, + Node* Final, + list* list_libs) +{ + int curr_node = 0; + const int nb_childs = Root->get_nb_childs(); + std::list::const_iterator libid_i; + int i; + int I; + + if (nb_childs) + { + for (curr_node = 0; curr_node < nb_childs; curr_node++) + { + Node node = Root->get_child(curr_node); + I = node.get_data(); + + libid_i = list_libs->begin(); + for (i = 0; i < I; i++) + libid_i++; + + Final->add_child(Data_string(libid_i->getFilename())); + Node TotoMesCouilles = + Final->get_child(Final->get_nb_childs() - 1); + Int2Datanode(&node, &TotoMesCouilles, list_libs); + } + } + + return; + +} + +// +// # +// # #### ## ##### ###### ##### +// # # # # # # # # # # +// # # # # # # # ##### # # +// # # # ###### # # # ##### ### ### +// # # # # # # # # # # ### ### +// ####### #### # # ##### ###### # # ### ### +// + + +Node +LibraryLoader(const list& LibFiles) +{ + + /**************************************************************/ + /* Opens all selected libraries and sort them by dependancies */ + /**************************************************************/ + + /*\****************\* Declarations *\***************\*/ + + /* Pointer needed to manipulate libraries */ + Library* current_loading (NULL); + string libname; + + /* List of loaded libraries needed to construct the deps tree */ + std::list libids; + libids.clear(); + int libid; + + /***********************************/ + /* Loads libraries and stores them */ + /***********************************/ + for (std::list::const_iterator libfile_i = LibFiles.begin(); + libfile_i != LibFiles.end(); + libfile_i++) + { + current_loading = new Library (*libfile_i); // Creates new class + + if (! current_loading->LoadLib()) + { + + /********************************************** + ** just for test purposes ** + ** it has nothing to do there ** + ** if it isn't commented.. comment it ! ** + **********************************************/ + //current_loading->Initialize(); +apao + if (getLibID(&libids, current_loading->getName()) == -1) + libids.push_back(*current_loading); // Stores the lib + else + { + cerr << "Library " + << current_loading->getName() + << " is already loaded !" << endl; + delete current_loading; + } + } + else + delete current_loading; + + } + + + + /*\****************\* Declarations *\***************\*/ + + int size = libids.size(); + + /* Matrix of dependancies */ + Matrix adjacence (size, size); + int i_ = 0, j_ = 0; + + /* List needed to manipulate dependancies of current lib */ + std::list deps; + deps.clear(); + + /* Lists iterators to iterate lists ;o) */ + std::list::const_iterator libid_i; + std::list::const_iterator dep_i; + + /**************************************/ + /* Second parsing to get dependancies */ + /**************************************/ + + for (libid_i = libids.begin(); libid_i != libids.end(); libid_i++) + { + deps = libid_i->getDependancies(); + + if (! deps.empty()) + for (dep_i = deps.begin(); + dep_i != deps.end(); + dep_i++) + { + libid = getLibID(&libids, *dep_i); + if (!(libid < 0)) + adjacence(i_, libid) = 1; + else + { + cerr + << "#ERR " << ERR_LIBMISSING + << ": Missing library: " + << *dep_i << "" << endl; + exit(ERR_LIBMISSING); + } + } + + i_++; + + } + + cout << "-- " << endl << adjacence << "-- " << endl; + + + /*\****************\* Declarations *\***************\*/ + /* The root node of sorted libraries tree */ + Node root (-1); + + int n_deps; + + /***************************************/ + /* Search for potential root libraries */ + /***************************************/ + + for (i_ = 0; + i_ < size; + i_++) + { + n_deps = 0; + for (j_ = 0; j_ < size; j_++) + if (adjacence(i_, j_)) + n_deps += 1; + + cout << i_ << " : " << n_deps; + + if (n_deps == 0) /* This is a root library */ + { + root.add_child(i_); + cout << " Added in Root tree !"; + } + cout << "" << endl; + } + + cout << endl << "Root has " << root.get_nb_childs() << " childs.." + << endl << endl; + + if (!root.get_nb_childs()) /* No independant library found.. */ + { + cerr << "#ERR " << ERR_NOROOTLIB + << ": No independant library found.." << endl; + exit(ERR_NOROOTLIB); + } + + /***********************************/ + /* Recursive addition of each node */ + /***********************************/ + + RecursiveAddNode(&root, &adjacence, size); + + cout << "-- " << endl << adjacence << "-- " << endl; + + /******************************************************/ + /* Checks if every Library has been added in the tree */ + /******************************************************/ + + for (i_ = 0; + i_ < size; + i_++) + for (j_ = 0; + j_ < size; + j_++) + if (adjacence(i_, j_) == 1) + { + cerr << "#Err " << ERR_NOROOTLIB + << ": Infinite loop in library dependancies;" << endl; + exit(ERR_NOROOTLIB); + } + + Node FinalResult (Data_string("")); + Int2Datanode(&root, &FinalResult, &libids); + + // WHEEEE !! IT'S THE END !!! I CAN'T BELIEVE IT !! + return FinalResult; +} + diff --git a/dll/libraryloader.hh b/dll/libraryloader.hh new file mode 100644 index 0000000..f23810b --- /dev/null +++ b/dll/libraryloader.hh @@ -0,0 +1,41 @@ +//============================================================================= +// +// Glagen : a planet sized landscape generator +// Copyright (C) 2002 Julien Guertault, Hugues Hiegel, Meng-Tih Lam +// +// 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. +// +//============================================================================= +// +// Glagen : GPL LAndscape GENerator +// +// maintest.hh for Glagen : made by Hugues HIEGEL +// +// www.glagen.org +// +//============================================================================= + +#ifndef LIBRARYLOADER_CC_ +# define LIBRARYLOADER_CC_ + +#include "classes/libclass.hh" +#include "classes/node.hh" +#include "classes/Data_string.hh" + +extern int GLG_property_pos; + +Node LibraryLoader(const list& LibFiles); + +#endif //LIBRARYLOADER_CC_ diff --git a/dll/main.cc b/dll/main.cc new file mode 100644 index 0000000..ac744f7 --- /dev/null +++ b/dll/main.cc @@ -0,0 +1,21 @@ +#include +#include +#include "libraryloader.hh" + + +extern int GLG_property_pos; +list Libs; + +int +main(int argc, + char **argv) +{ + + for (int i = 1; i < argc; i++) + Libs.push_back(argv[i]); + + GLG_property_pos = 0; + + LibraryLoader(Libs); + return 0; +} diff --git a/dll/main.hh b/dll/main.hh new file mode 100644 index 0000000..a812196 --- /dev/null +++ b/dll/main.hh @@ -0,0 +1 @@ +##Trippant ! on se touche la bite dans ce main.hh !!## diff --git a/dll/samples2/gps/libtoto.gps b/dll/samples2/gps/libtoto.gps new file mode 100644 index 0000000..b70c38b --- /dev/null +++ b/dll/samples2/gps/libtoto.gps @@ -0,0 +1,4 @@ +NAME: libtoto +VERSION: 0.0 +DEPS: libtata==0.0 +AUTHOR: gus -- cgit v1.2.3