From d3e67b912a97834dbf0711b5d3dbbc0bd3d29ee8 Mon Sep 17 00:00:00 2001 From: "(no author)" <(no author)@0f7e0d06-a6f9-0310-a55f-d5f984f55e4c> Date: Thu, 10 Feb 2005 23:10:51 +0000 Subject: This commit was manufactured by cvs2svn to create branch 'hugues'. git-svn-id: file:///usr/local/opt/svn/repos/glagen@4 0f7e0d06-a6f9-0310-a55f-d5f984f55e4c --- branches/hugues/glagen/3d/Archs.txt | 13 + branches/hugues/glagen/3d/Fixme.txt | 13 + branches/hugues/glagen/3d/GPL.txt | 292 +++++++++ branches/hugues/glagen/3d/Glagen.dev | 345 ++++++++++ branches/hugues/glagen/3d/Glagen.ico | Bin 0 -> 29766 bytes branches/hugues/glagen/3d/Greatings.txt | 18 + branches/hugues/glagen/3d/Makefile | 139 ++++ branches/hugues/glagen/3d/Makefile.mac | 138 ++++ branches/hugues/glagen/3d/Makefile.macosx | 133 ++++ branches/hugues/glagen/3d/Makefile.windows | 98 +++ branches/hugues/glagen/3d/data_glagen.hh | 115 ++++ branches/hugues/glagen/3d/display.cc | 411 ++++++++++++ branches/hugues/glagen/3d/display.hh | 44 ++ branches/hugues/glagen/3d/dot.cc | 184 ++++++ branches/hugues/glagen/3d/dot.hh | 84 +++ branches/hugues/glagen/3d/dot_gl.cc | 83 +++ branches/hugues/glagen/3d/end.cc | 53 ++ branches/hugues/glagen/3d/end.hh | 39 ++ branches/hugues/glagen/3d/frame.cc | 152 +++++ branches/hugues/glagen/3d/frame.hh | 69 ++ branches/hugues/glagen/3d/glagen | Bin 0 -> 886824 bytes branches/hugues/glagen/3d/header.cc | 28 + branches/hugues/glagen/3d/isosahedron.cc | 220 +++++++ branches/hugues/glagen/3d/isosahedron.hh | 38 ++ branches/hugues/glagen/3d/library.cc | 100 +++ branches/hugues/glagen/3d/library.hh | 40 ++ branches/hugues/glagen/3d/main.cc | 132 ++++ branches/hugues/glagen/3d/matrix3d.cc | 216 ++++++ branches/hugues/glagen/3d/matrix3d.hh | 80 +++ branches/hugues/glagen/3d/misc.cc | 43 ++ branches/hugues/glagen/3d/misc.hh | 38 ++ branches/hugues/glagen/3d/perlin.cc | 347 ++++++++++ branches/hugues/glagen/3d/perlin.hh | 39 ++ branches/hugues/glagen/3d/simul.cc | 409 ++++++++++++ branches/hugues/glagen/3d/simul.hh | 41 ++ branches/hugues/glagen/3d/time.hh | 36 + branches/hugues/glagen/3d/time_unix.cc | 51 ++ branches/hugues/glagen/3d/time_windows.cc | 53 ++ branches/hugues/glagen/3d/triangle.cc | 729 +++++++++++++++++++++ branches/hugues/glagen/3d/triangle.hh | 122 ++++ branches/hugues/glagen/3d/triangle_gl.cc | 180 +++++ branches/hugues/glagen/3d/vector.cc | 252 +++++++ branches/hugues/glagen/3d/vector.hh | 77 +++ branches/hugues/glagen/algo_distribue/Distribue.cc | 1 + branches/hugues/glagen/algo_distribue/Distribue.hh | 97 +++ branches/hugues/glagen/algo_distribue/Makefile | 51 ++ branches/hugues/glagen/algo_distribue/main.cc | 113 ++++ .../hugues/glagen/algo_distribue/network/Client.cc | 1 + .../hugues/glagen/algo_distribue/network/Client.hh | 113 ++++ .../hugues/glagen/algo_distribue/network/Makefile | 62 ++ .../hugues/glagen/algo_distribue/network/Server.cc | 1 + .../hugues/glagen/algo_distribue/network/Server.hh | 218 ++++++ .../glagen/algo_distribue/network/data/Data.cc | 1 + .../glagen/algo_distribue/network/data/Data.hh | 78 +++ .../algo_distribue/network/data/Data_exemple.cc | 1 + .../algo_distribue/network/data/Data_exemple.hh | 66 ++ .../algo_distribue/network/data/Data_string.cc | 1 + .../algo_distribue/network/data/Data_string.hh | 60 ++ .../glagen/algo_distribue/network/main_client.cc | 54 ++ .../glagen/algo_distribue/network/main_server.cc | 73 +++ .../hugues/glagen/algo_distribue/tools/matrix.cc | 3 + .../hugues/glagen/algo_distribue/tools/matrix.hh | 324 +++++++++ .../hugues/glagen/algo_distribue/tree/Makefile | 45 ++ branches/hugues/glagen/algo_distribue/tree/main.cc | 99 +++ branches/hugues/glagen/algo_distribue/tree/node.cc | 11 + branches/hugues/glagen/algo_distribue/tree/node.hh | 78 +++ branches/hugues/glagen/algo_distribue/tree/tree.cc | 11 + branches/hugues/glagen/algo_distribue/tree/tree.hh | 51 ++ branches/hugues/glagen/dll/.emacs.desktop | 93 +++ branches/hugues/glagen/dll/MANUAL | 138 ++++ branches/hugues/glagen/dll/Makefile | 72 ++ branches/hugues/glagen/dll/NOTES | 13 + branches/hugues/glagen/dll/README | 237 +++++++ .../hugues/glagen/dll/classes/Data_property.cc | 30 + .../hugues/glagen/dll/classes/Data_property.hh | 88 +++ branches/hugues/glagen/dll/classes/Data_string.cc | 1 + branches/hugues/glagen/dll/classes/Data_string.hh | 62 ++ .../glagen/dll/classes/GLG-libraries-devel.cc | 32 + .../glagen/dll/classes/GLG-libraries-devel.hh | 1 + branches/hugues/glagen/dll/classes/dot.cc | 100 +++ branches/hugues/glagen/dll/classes/dot.hh | 49 ++ branches/hugues/glagen/dll/classes/libclass.cc | 391 +++++++++++ branches/hugues/glagen/dll/classes/libclass.hh | 91 +++ branches/hugues/glagen/dll/classes/matrix.cc | 3 + branches/hugues/glagen/dll/classes/matrix.hh | 324 +++++++++ branches/hugues/glagen/dll/classes/node.cc | 11 + branches/hugues/glagen/dll/classes/node.hh | 82 +++ .../hugues/glagen/dll/create_dotproperty_init.cc | 86 +++ .../hugues/glagen/dll/create_dotproperty_init.hh | 0 branches/hugues/glagen/dll/header.cc | 28 + branches/hugues/glagen/dll/includes/errors.hh | 19 + branches/hugues/glagen/dll/libraryloader.cc | 322 +++++++++ branches/hugues/glagen/dll/libraryloader.hh | 41 ++ branches/hugues/glagen/dll/main.cc | 21 + branches/hugues/glagen/dll/main.hh | 1 + .../hugues/glagen/dll/samples2/gps/libtoto.gps | 4 + branches/hugues/glagen/trucs | 10 + 97 files changed, 9657 insertions(+) create mode 100644 branches/hugues/glagen/3d/Archs.txt create mode 100644 branches/hugues/glagen/3d/Fixme.txt create mode 100644 branches/hugues/glagen/3d/GPL.txt create mode 100644 branches/hugues/glagen/3d/Glagen.dev create mode 100644 branches/hugues/glagen/3d/Glagen.ico create mode 100644 branches/hugues/glagen/3d/Greatings.txt create mode 100644 branches/hugues/glagen/3d/Makefile create mode 100644 branches/hugues/glagen/3d/Makefile.mac create mode 100644 branches/hugues/glagen/3d/Makefile.macosx create mode 100644 branches/hugues/glagen/3d/Makefile.windows create mode 100644 branches/hugues/glagen/3d/data_glagen.hh create mode 100644 branches/hugues/glagen/3d/display.cc create mode 100644 branches/hugues/glagen/3d/display.hh create mode 100644 branches/hugues/glagen/3d/dot.cc create mode 100644 branches/hugues/glagen/3d/dot.hh create mode 100644 branches/hugues/glagen/3d/dot_gl.cc create mode 100644 branches/hugues/glagen/3d/end.cc create mode 100644 branches/hugues/glagen/3d/end.hh create mode 100644 branches/hugues/glagen/3d/frame.cc create mode 100644 branches/hugues/glagen/3d/frame.hh create mode 100755 branches/hugues/glagen/3d/glagen create mode 100644 branches/hugues/glagen/3d/header.cc create mode 100644 branches/hugues/glagen/3d/isosahedron.cc create mode 100644 branches/hugues/glagen/3d/isosahedron.hh create mode 100644 branches/hugues/glagen/3d/library.cc create mode 100644 branches/hugues/glagen/3d/library.hh create mode 100644 branches/hugues/glagen/3d/main.cc create mode 100644 branches/hugues/glagen/3d/matrix3d.cc create mode 100644 branches/hugues/glagen/3d/matrix3d.hh create mode 100644 branches/hugues/glagen/3d/misc.cc create mode 100644 branches/hugues/glagen/3d/misc.hh create mode 100644 branches/hugues/glagen/3d/perlin.cc create mode 100644 branches/hugues/glagen/3d/perlin.hh create mode 100644 branches/hugues/glagen/3d/simul.cc create mode 100644 branches/hugues/glagen/3d/simul.hh create mode 100644 branches/hugues/glagen/3d/time.hh create mode 100644 branches/hugues/glagen/3d/time_unix.cc create mode 100644 branches/hugues/glagen/3d/time_windows.cc create mode 100644 branches/hugues/glagen/3d/triangle.cc create mode 100644 branches/hugues/glagen/3d/triangle.hh create mode 100644 branches/hugues/glagen/3d/triangle_gl.cc create mode 100644 branches/hugues/glagen/3d/vector.cc create mode 100644 branches/hugues/glagen/3d/vector.hh create mode 100644 branches/hugues/glagen/algo_distribue/Distribue.cc create mode 100644 branches/hugues/glagen/algo_distribue/Distribue.hh create mode 100644 branches/hugues/glagen/algo_distribue/Makefile create mode 100644 branches/hugues/glagen/algo_distribue/main.cc create mode 100644 branches/hugues/glagen/algo_distribue/network/Client.cc create mode 100644 branches/hugues/glagen/algo_distribue/network/Client.hh create mode 100644 branches/hugues/glagen/algo_distribue/network/Makefile create mode 100644 branches/hugues/glagen/algo_distribue/network/Server.cc create mode 100644 branches/hugues/glagen/algo_distribue/network/Server.hh create mode 100644 branches/hugues/glagen/algo_distribue/network/data/Data.cc create mode 100644 branches/hugues/glagen/algo_distribue/network/data/Data.hh create mode 100644 branches/hugues/glagen/algo_distribue/network/data/Data_exemple.cc create mode 100644 branches/hugues/glagen/algo_distribue/network/data/Data_exemple.hh create mode 100644 branches/hugues/glagen/algo_distribue/network/data/Data_string.cc create mode 100644 branches/hugues/glagen/algo_distribue/network/data/Data_string.hh create mode 100644 branches/hugues/glagen/algo_distribue/network/main_client.cc create mode 100644 branches/hugues/glagen/algo_distribue/network/main_server.cc create mode 100644 branches/hugues/glagen/algo_distribue/tools/matrix.cc create mode 100644 branches/hugues/glagen/algo_distribue/tools/matrix.hh create mode 100644 branches/hugues/glagen/algo_distribue/tree/Makefile create mode 100644 branches/hugues/glagen/algo_distribue/tree/main.cc create mode 100644 branches/hugues/glagen/algo_distribue/tree/node.cc create mode 100644 branches/hugues/glagen/algo_distribue/tree/node.hh create mode 100644 branches/hugues/glagen/algo_distribue/tree/tree.cc create mode 100644 branches/hugues/glagen/algo_distribue/tree/tree.hh create mode 100644 branches/hugues/glagen/dll/.emacs.desktop create mode 100644 branches/hugues/glagen/dll/MANUAL create mode 100644 branches/hugues/glagen/dll/Makefile create mode 100644 branches/hugues/glagen/dll/NOTES create mode 100644 branches/hugues/glagen/dll/README create mode 100644 branches/hugues/glagen/dll/classes/Data_property.cc create mode 100644 branches/hugues/glagen/dll/classes/Data_property.hh create mode 100644 branches/hugues/glagen/dll/classes/Data_string.cc create mode 100644 branches/hugues/glagen/dll/classes/Data_string.hh create mode 100644 branches/hugues/glagen/dll/classes/GLG-libraries-devel.cc create mode 100644 branches/hugues/glagen/dll/classes/GLG-libraries-devel.hh create mode 100644 branches/hugues/glagen/dll/classes/dot.cc create mode 100644 branches/hugues/glagen/dll/classes/dot.hh create mode 100644 branches/hugues/glagen/dll/classes/libclass.cc create mode 100644 branches/hugues/glagen/dll/classes/libclass.hh create mode 100644 branches/hugues/glagen/dll/classes/matrix.cc create mode 100644 branches/hugues/glagen/dll/classes/matrix.hh create mode 100644 branches/hugues/glagen/dll/classes/node.cc create mode 100644 branches/hugues/glagen/dll/classes/node.hh create mode 100644 branches/hugues/glagen/dll/create_dotproperty_init.cc create mode 100644 branches/hugues/glagen/dll/create_dotproperty_init.hh create mode 100644 branches/hugues/glagen/dll/header.cc create mode 100644 branches/hugues/glagen/dll/includes/errors.hh create mode 100644 branches/hugues/glagen/dll/libraryloader.cc create mode 100644 branches/hugues/glagen/dll/libraryloader.hh create mode 100644 branches/hugues/glagen/dll/main.cc create mode 100644 branches/hugues/glagen/dll/main.hh create mode 100644 branches/hugues/glagen/dll/samples2/gps/libtoto.gps create mode 100644 branches/hugues/glagen/trucs (limited to 'branches/hugues') diff --git a/branches/hugues/glagen/3d/Archs.txt b/branches/hugues/glagen/3d/Archs.txt new file mode 100644 index 0000000..a39618d --- /dev/null +++ b/branches/hugues/glagen/3d/Archs.txt @@ -0,0 +1,13 @@ + +The Glagen's 3D engine ha been ported on: + + * GNU/Linux (Debian, Mandrake); + * MacOS X; + * FreeBSD, NetBSD and OpenBSD; + * Microsoft Windows. + +To do : + + * Test on other GNU/Linux distributions (Redhat, Slackware at least); + * Test on GNU/Hurd, if possible; + * Maybe on Solaris. diff --git a/branches/hugues/glagen/3d/Fixme.txt b/branches/hugues/glagen/3d/Fixme.txt new file mode 100644 index 0000000..6a57b48 --- /dev/null +++ b/branches/hugues/glagen/3d/Fixme.txt @@ -0,0 +1,13 @@ +To fix : + + * Find a fast distace approximation. + + * The light! + + * Add 2D graphics (Head Up Display, fonts...). + + * Bug when near the ground; + + * Try different noise; + + * Increase definatly the precision depth. diff --git a/branches/hugues/glagen/3d/GPL.txt b/branches/hugues/glagen/3d/GPL.txt new file mode 100644 index 0000000..0dd1a53 --- /dev/null +++ b/branches/hugues/glagen/3d/GPL.txt @@ -0,0 +1,292 @@ +GNU GENERAL PUBLIC LICENSE + +Version 2, June 1991 + +Copyright (C) 1989, 1991 Free Software Foundation, Inc. +59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + +Everyone is permitted to copy and distribute verbatim copies +of this license document, but changing it is not allowed. + +Preamble + +The licenses for most software are designed to take away your freedom +to share and change it. By contrast, the GNU General Public License is +intended to guarantee your freedom to share and change free +software--to make sure the software is free for all its users. This +General Public License applies to most of the Free Software +Foundation's software and to any other program whose authors commit to +using it. (Some other Free Software Foundation software is covered by +the GNU Library General Public License instead.) You can apply it to +your programs, too. + +When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +this service if you wish), that you receive source code or can get it +if you want it, that you can change the software or use pieces of it +in new free programs; and that you know you can do these things. + +To protect your rights, we need to make restrictions that forbid +anyone to deny you these rights or to ask you to surrender the +rights. These restrictions translate to certain responsibilities for +you if you distribute copies of the software, or if you modify it. + +For example, if you distribute copies of such a program, whether +gratis or for a fee, you must give the recipients all the rights that +you have. You must make sure that they, too, receive or can get the +source code. And you must show them these terms so they know their +rights. + +We protect your rights with two steps: (1) copyright the software, and +(2) offer you this license which gives you legal permission to copy, +distribute and/or modify the software. + +Also, for each author's protection and ours, we want to make certain +that everyone understands that there is no warranty for this free +software. If the software is modified by someone else and passed on, +we want its recipients to know that what they have is not the +original, so that any problems introduced by others will not reflect +on the original authors' reputations. + +Finally, any free program is threatened constantly by software +patents. We wish to avoid the danger that redistributors of a free +program will individually obtain patent licenses, in effect making the +program proprietary. To prevent this, we have made it clear that any +patent must be licensed for everyone's free use or not licensed at +all. + +The precise terms and conditions for copying, distribution and +modification follow. TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION +AND MODIFICATION + +0. This License applies to any program or other work which contains a + notice placed by the copyright holder saying it may be distributed + under the terms of this General Public License. The "Program", + below, refers to any such program or work, and a "work based on the + Program" means either the Program or any derivative work under + copyright law: that is to say, a work containing the Program or a + portion of it, either verbatim or with modifications and/or + translated into another language. (Hereinafter, translation is + included without limitation in the term "modification".) Each + licensee is addressed as "you". + + Activities other than copying, distribution and modification are + not covered by this License; they are outside its scope. The act of + running the Program is not restricted, and the output from the + Program is covered only if its contents constitute a work based on + the Program (independent of having been made by running the + Program). Whether that is true depends on what the Program does. + +1. You may copy and distribute verbatim copies of the Program's source + code as you receive it, in any medium, provided that you + conspicuously and appropriately publish on each copy an appropriate + copyright notice and disclaimer of warranty; keep intact all the + notices that refer to this License and to the absence of any + warranty; and give any other recipients of the Program a copy of + this License along with the Program. + + You may charge a fee for the physical act of transferring a copy, + and you may at your option offer warranty protection in exchange + for a fee. + +2. You may modify your copy or copies of the Program or any portion of + it, thus forming a work based on the Program, and copy and + distribute such modifications or work under the terms of Section 1 + above, provided that you also meet all of these conditions: + + * a) You must cause the modified files to carry prominent notices + stating that you changed the files and the date of any change. + + * b) You must cause any work that you distribute or publish, that + in whole or in part contains or is derived from the Program or + any part thereof, to be licensed as a whole at no charge to all + third parties under the terms of this License. + + * c) If the modified program normally reads commands interactively + when run, you must cause it, when started running for such + interactive use in the most ordinary way, to print or display an + announcement including an appropriate copyright notice and a + notice that there is no warranty (or else, saying that you + provide a warranty) and that users may redistribute the program + under these conditions, and telling the user how to view a copy + of this License. (Exception: if the Program itself is + interactive but does not normally print such an announcement, + your work based on the Program is not required to print an + announcement.) + + These requirements apply to the modified work as a whole. If + identifiable sections of that work are not derived from the + Program, and can be reasonably considered independent and separate + works in themselves, then this License, and its terms, do not apply + to those sections when you distribute them as separate works. But + when you distribute the same sections as part of a whole which is a + work based on the Program, the distribution of the whole must be on + the terms of this License, whose permissions for other licensees + extend to the entire whole, and thus to each and every part + regardless of who wrote it. + + Thus, it is not the intent of this section to claim rights or + contest your rights to work written entirely by you; rather, the + intent is to exercise the right to control the distribution of + derivative or collective works based on the Program. + + In addition, mere aggregation of another work not based on the + Program with the Program (or with a work based on the Program) on a + volume of a storage or distribution medium does not bring the other + work under the scope of this License. + +3. You may copy and distribute the Program (or a work based on it, + under Section 2) in object code or executable form under the terms + of Sections 1 and 2 above provided that you also do one of the + following: + + * a) Accompany it with the complete corresponding machine-readable + source code, which must be distributed under the terms of + Sections 1 and 2 above on a medium customarily used for software + interchange; or, + + * b) Accompany it with a written offer, valid for at least three + years, to give any third party, for a charge no more than your + cost of physically performing source distribution, a complete + machine-readable copy of the corresponding source code, to be + distributed under the terms of Sections 1 and 2 above on a + medium customarily used for software interchange; or, + + * c) Accompany it with the information you received as to the + offer to distribute corresponding source code. (This alternative + is allowed only for noncommercial distribution and only if you + received the program in object code or executable form with such + an offer, in accord with Subsection b above.) + + The source code for a work means the preferred form of the work for + making modifications to it. For an executable work, complete source + code means all the source code for all modules it contains, plus + any associated interface definition files, plus the scripts used to + control compilation and installation of the executable. However, as + a special exception, the source code distributed need not include + anything that is normally distributed (in either source or binary + form) with the major components (compiler, kernel, and so on) of + the operating system on which the executable runs, unless that + component itself accompanies the executable. + + If distribution of executable or object code is made by offering + access to copy from a designated place, then offering equivalent + access to copy the source code from the same place counts as + distribution of the source code, even though third parties are not + compelled to copy the source along with the object code. + +4. You may not copy, modify, sublicense, or distribute the Program + except as expressly provided under this License. Any attempt + otherwise to copy, modify, sublicense or distribute the Program is + void, and will automatically terminate your rights under this + License. However, parties who have received copies, or rights, from + you under this License will not have their licenses terminated so + long as such parties remain in full compliance. + +5. You are not required to accept this License, since you have not + signed it. However, nothing else grants you permission to modify or + distribute the Program or its derivative works. These actions are + prohibited by law if you do not accept this License. Therefore, by + modifying or distributing the Program (or any work based on the + Program), you indicate your acceptance of this License to do so, + and all its terms and conditions for copying, distributing or + modifying the Program or works based on it. + +6. Each time you redistribute the Program (or any work based on the + Program), the recipient automatically receives a license from the + original licensor to copy, distribute or modify the Program subject + to these terms and conditions. You may not impose any further + restrictions on the recipients' exercise of the rights granted + herein. You are not responsible for enforcing compliance by third + parties to this License. + +7. If, as a consequence of a court judgment or allegation of patent + infringement or for any other reason (not limited to patent + issues), conditions are imposed on you (whether by court order, + agreement or otherwise) that contradict the conditions of this + License, they do not excuse you from the conditions of this + License. If you cannot distribute so as to satisfy simultaneously + your obligations under this License and any other pertinent + obligations, then as a consequence you may not distribute the + Program at all. For example, if a patent license would not permit + royalty-free redistribution of the Program by all those who receive + copies directly or indirectly through you, then the only way you + could satisfy both it and this License would be to refrain entirely + from distribution of the Program. + + If any portion of this section is held invalid or unenforceable + under any particular circumstance, the balance of the section is + intended to apply and the section as a whole is intended to apply + in other circumstances. + + It is not the purpose of this section to induce you to infringe any + patents or other property right claims or to contest validity of + any such claims; this section has the sole purpose of protecting + the integrity of the free software distribution system, which is + implemented by public license practices. Many people have made + generous contributions to the wide range of software distributed + through that system in reliance on consistent application of that + system; it is up to the author/donor to decide if he or she is + willing to distribute software through any other system and a + licensee cannot impose that choice. + + This section is intended to make thoroughly clear what is believed + to be a consequence of the rest of this License. + +8. If the distribution and/or use of the Program is restricted in + certain countries either by patents or by copyrighted interfaces, + the original copyright holder who places the Program under this + License may add an explicit geographical distribution limitation + excluding those countries, so that distribution is permitted only + in or among countries not thus excluded. In such case, this License + incorporates the limitation as if written in the body of this + License. + +9. The Free Software Foundation may publish revised and/or new + versions of the General Public License from time to time. Such new + versions will be similar in spirit to the present version, but may + differ in detail to address new problems or concerns. + + Each version is given a distinguishing version number. If the + Program specifies a version number of this License which applies to + it and "any later version", you have the option of following the + terms and conditions either of that version or of any later version + published by the Free Software Foundation. If the Program does not + specify a version number of this License, you may choose any + version ever published by the Free Software Foundation. + +10. If you wish to incorporate parts of the Program into other free + programs whose distribution conditions are different, write to the + author to ask for permission. For software which is copyrighted by + the Free Software Foundation, write to the Free Software + Foundation; we sometimes make exceptions for this. Our decision + will be guided by the two goals of preserving the free status of + all derivatives of our free software and of promoting the sharing + and reuse of software generally. + +NO WARRANTY + +11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO + WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE + LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS + AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY + OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND + PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE + DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR + OR CORRECTION. + +12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN + WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY + MODIFY AND/OR REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE + LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, + INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR + INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF + DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU + OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY + OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN + ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + +END OF TERMS AND CONDITIONS diff --git a/branches/hugues/glagen/3d/Glagen.dev b/branches/hugues/glagen/3d/Glagen.dev new file mode 100644 index 0000000..6dc18da --- /dev/null +++ b/branches/hugues/glagen/3d/Glagen.dev @@ -0,0 +1,345 @@ +[Project] +FileName=Glagen.dev +Name=Glagen +UnitCount=20 +Type=0 +Ver=1 +ObjFiles= +Includes= +Libs= +PrivateResource=Glagen_private.rc +ResourceIncludes= +MakeIncludes= +Compiler= +CppCompiler=_@@_ +Linker=-lopengl32 -lglu32 -lglut32_@@_ +IsCpp=1 +Icon=Glagen.ico +ExeOutput= +ObjectOutput= +OverrideOutput=1 +OverrideOutputName=Glagen.exe +HostApplication= +Folders=Classes,Implementation +CommandLine= +IncludeVersionInfo=1 +SupportXPThemes=0 +CompilerSet=0 +CompilerSettings=000000000100100000 + +[Unit1] +FileName=display.cc +CompileCpp=1 +Folder=Implementation +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit2] +FileName=dot.cc +CompileCpp=1 +Folder=Implementation +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit3] +FileName=dot_gl.cc +CompileCpp=1 +Folder=Implementation +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit4] +FileName=end.cc +CompileCpp=1 +Folder=Implementation +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit5] +FileName=frame.cc +CompileCpp=1 +Folder=Implementation +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit6] +FileName=isosahedron.cc +CompileCpp=1 +Folder=Implementation +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit7] +FileName=library.cc +CompileCpp=1 +Folder=Implementation +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit8] +FileName=main.cc +CompileCpp=1 +Folder=Implementation +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit9] +FileName=matrix3d.cc +CompileCpp=1 +Folder=Implementation +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit10] +FileName=misc.cc +CompileCpp=1 +Folder=Implementation +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit11] +FileName=perlin.cc +CompileCpp=1 +Folder=Implementation +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit12] +FileName=simul.cc +CompileCpp=1 +Folder=Implementation +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit13] +FileName=triangle.cc +CompileCpp=1 +Folder=Implementation +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit14] +FileName=triangle_gl.cc +CompileCpp=1 +Folder=Implementation +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit15] +FileName=vector.cc +CompileCpp=1 +Folder=Implementation +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit16] +FileName=data_glagen.hh +CompileCpp=1 +Folder=Classes +Compile=0 +Link=0 +Priority=1000 +OverrideBuildCmd=1 +BuildCmd= + +[Unit17] +FileName=display.hh +CompileCpp=1 +Folder=Classes +Compile=0 +Link=0 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit18] +FileName=dot.hh +Folder=Classes +Compile=0 +Link=0 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit19] +FileName=end.hh +Folder=Classes +Compile=0 +Link=0 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit20] +FileName=frame.hh +Folder=Classes +Compile=0 +Link=0 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit21] +FileName=isosahedron.hh +Folder=Classes +Compile=0 +Link=0 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit22] +FileName=library.hh +Folder=Classes +Compile=0 +Link=0 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit23] +FileName=matrix3d.hh +Folder=Classes +Compile=0 +Link=0 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit24] +FileName=misc.hh +Folder=Classes +Compile=0 +Link=0 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit25] +FileName=perlin.hh +Folder=Classes +Compile=0 +Link=0 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit26] +FileName=simul.hh +Folder=Classes +Compile=0 +Link=0 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit27] +FileName=triangle.hh +Folder=Classes +Compile=0 +Link=0 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit28] +FileName=vector.hh +Folder=Classes +Compile=0 +Link=0 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit29] +FileName=time.hh +Folder=Classes +Compile=0 +Link=0 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit30] +FileName=time_windows.cc +Folder=Implementation +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= +CompileCpp=1 + +[Unit31] +FileName=time_windows.cc +CompileCpp=1 +Folder=Implementation +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[VersionInfo] +Major=0 +Minor=0 +Release=9 +Build=0 +LanguageID=1033 +CharsetID=1252 +CompanyName=www.glagen.org +FileVersion=0.0.9.0 +FileDescription=GPL Landscape Generator +InternalName=glagen.exe +LegalCopyright=Copyright 2003, www.glagen.org +LegalTrademarks= +OriginalFilename=glagen.exe +ProductName=Glagen +ProductVersion=Alpha 0.0.9.0 +AutoIncBuildNr=0 + diff --git a/branches/hugues/glagen/3d/Glagen.ico b/branches/hugues/glagen/3d/Glagen.ico new file mode 100644 index 0000000..acb0589 Binary files /dev/null and b/branches/hugues/glagen/3d/Glagen.ico differ diff --git a/branches/hugues/glagen/3d/Greatings.txt b/branches/hugues/glagen/3d/Greatings.txt new file mode 100644 index 0000000..5f1c204 --- /dev/null +++ b/branches/hugues/glagen/3d/Greatings.txt @@ -0,0 +1,18 @@ + +For their help, we would especially thanks : + + +Dr. Thierry Geraud : very good ideas for the general design + of the library engine of the project. + +Jon Harrop : lot's of explainations about the detail + increasing. + +EpiDemic's team : many tips about OpenGl. + +EpiMac : for there help to port Glagen on Mac OS X. + +EPITA : because this project was part of our + degree. + +And many others... diff --git a/branches/hugues/glagen/3d/Makefile b/branches/hugues/glagen/3d/Makefile new file mode 100644 index 0000000..a7d46b5 --- /dev/null +++ b/branches/hugues/glagen/3d/Makefile @@ -0,0 +1,139 @@ +##============================================================================= +## +## 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 +## +## Makefile for Glagen : made by Zavie (Julien Guertault) +## +## www.glagen.org +## +##============================================================================= + +NAME = glagen + +DIRECTORY = 3d + +ARCHIVE = tar -cvzf + +CC = g++ + +ECHO = @echo + +RM = rm -f + +SRC = main.cc \ + display.cc \ + dot.cc \ + dot_gl.cc \ + end.cc \ + frame.cc \ + isosahedron.cc \ + library.cc \ + matrix3d.cc \ + misc.cc \ + perlin.cc \ + simul.cc \ + time_unix.cc \ + triangle.cc \ + triangle_gl.cc \ + vector.cc + +DEBUG_FLAGS = -ggdb3 + +OPTIM_FLAGS = -O3 \ + -ffast-math \ + -funroll-loops \ + -felide-constructors \ + -fexpensive-optimizations \ + -finline-functions + +WARNING_FLAGS = -Wall \ + -W \ + -Wstrict-prototypes + +CFLAGS = $(DEBUG_FLAGS) \ + $(WARNING_FLAGS) + +# CFLAGS = $(OPTIM_FLAGS) \ +# $(WARNING_FLAGS) + +# CFLAGS = $(DEBUG_FLAGS) \ +# $(OPTIM_FLAGS) \ +# $(WARNING_FLAGS) + +#GTK_IFLAGS = `gtk-config --cflags` + +OPENGL_IFLAGS = -I/usr/include \ + -I/usr/include/GL \ + -I/usr/X11R6/include \ + -I/usr/X11R6/include/GL + +IFLAGS = $(OPENGL_IFLAGS) + +#GTK_LFLAGS = `gtk-config --libs` + +OPENGL_LFLAGS = -L/usr/X11R6/lib \ + -lX11 \ + -lGL \ + -lGLU \ + -lglut + +LFLAGS = -L/usr/lib \ + -L/usr/pkg/lib \ + -lc \ + -lm \ + $(OPENGL_LFLAGS) + +OBJ = $(SRC:.cc=.o) + +all : $(NAME) + +$(NAME) : $(OBJ) + $(CC) $(OBJ) $(LFLAGS) -o $(NAME) + +.cc.o : + $(CC) $(CFLAGS) $(IFLAGS) $< -c -o $@ + +clean : + $(RM) $(OBJ) + $(RM) *~ \#*\# + +distclean : clean + $(RM) $(NAME) + +separator : + $(ECHO) "------------------------------------------" + +re : clean all + +run : all + ./$(NAME) + +tarball : distclean separator + $(ECHO) "Archiving..." + cd .. && $(ARCHIVE) $(NAME).tar.gz $(DIRECTORY) + $(ECHO) "Done !" + +install : + $(ECHO) "Not implemented yet." + +love : + $(ECHO) "Sorry, I have a headache..." diff --git a/branches/hugues/glagen/3d/Makefile.mac b/branches/hugues/glagen/3d/Makefile.mac new file mode 100644 index 0000000..7e4d5d9 --- /dev/null +++ b/branches/hugues/glagen/3d/Makefile.mac @@ -0,0 +1,138 @@ +##============================================================================= +## +## 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 +## +## Makefile.mac for Glagen : made by Zavie (Julien Guertault) +## +## www.glagen.org +## +##============================================================================= + +NAME = glagen + +DIRECTORY = 3d + +ARCHIVE = tar -cvzf + +CC = g++ + +ECHO = @echo + +RM = rm -f + +SRC = main.cc \ + display.cc \ + dot.cc \ + dot_gl.cc \ + end.cc \ + frame.cc \ + isosahedron.cc \ + library.cc \ + matrix3d.cc \ + misc.cc \ + perlin.cc \ + simul.cc \ + time_unix.cc \ + triangle.cc \ + triangle_gl.cc \ + vector.cc + +OPTIM_FLAGS = -O3 \ + -ffast-math \ + -funroll-loops \ + -felide-constructors \ + -fexpensive-optimizations \ + -finline-functions + +WARNING_FLAGS = -Wall \ + -W \ + -Wstrict-prototypes + +CFLAGS = $(DEBUG_FLAGS) \ + $(WARNING_FLAGS) \ + -DDARWIN + +# CFLAGS = $(OPTIM_FLAGS) \ +# $(WARNING_FLAGS) \ +# -DDARWIN + +# CFLAGS = $(DEBUG_FLAGS) \ +# $(OPTIM_FLAGS) \ +# $(WARNING_FLAGS) \ +# -DDARWIN + +# Sorry for that... +# I'll try to do something better soon. + +#GTK_IFLAGS = `gtk-config --cflags` + +OPENGL_IFLAGS = -I/usr/X11R6/include \ + -I/System/Library/Frameworks/OpenGL.framework/Versions/A/Headers \ + -I/System/Library/Frameworks/GLUT.framework/Versions/A/Headers + +IFLAGS = -I/usr/include \ + $(OPENGL_IFLAGS) + +#GTK_LFLAGS = `gtk-config --libs` + +OPENGL_LFLAGS = -L/usr/X11R6/lib \ + -L/sw/lib \ + -lX11 \ + -lGL \ + -lGLU \ + -lglut + +LFLAGS = -L/usr/lib \ + -L/usr/pkg/lib \ + -lc \ + -lm \ + $(OPENGL_LFLAGS) + +OBJ = $(SRC:.cc=.o) + +all : $(NAME) + +$(NAME) : $(OBJ) + $(CC) $(OBJ) $(LFLAGS) -o $(NAME) + +.cc.o : + $(CC) $(CFLAGS) $(IFLAGS) $< -c -o $@ + +clean : + $(RM) $(OBJ) + $(RM) *~ \#*\# + +distclean : clean + $(RM) $(NAME) + +separator : + $(ECHO) "------------------------------------------" + +re : clean all + +tarball : distclean separator + $(ECHO) "Archiving..." + cd .. && $(ARCHIVE) $(NAME).tar.gz $(DIRECTORY) + $(ECHO) "Done !" + +love : + $(ECHO) "Sorry, I have a headache..." diff --git a/branches/hugues/glagen/3d/Makefile.macosx b/branches/hugues/glagen/3d/Makefile.macosx new file mode 100644 index 0000000..37b8e5b --- /dev/null +++ b/branches/hugues/glagen/3d/Makefile.macosx @@ -0,0 +1,133 @@ +##============================================================================= +## +## 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 +## +## Makefile.mac for Glagen : made by Zavie (Julien Guertault) +## +## www.glagen.org +## +##============================================================================= + +NAME = glagen + +DIRECTORY = 3d + +ARCHIVE = tar -cvzf + +CC = g++ + +ECHO = @echo + +RM = rm -f + +SRC = main.cc \ + display.cc \ + dot.cc \ + dot_gl.cc \ + end.cc \ + frame.cc \ + isosahedron.cc \ + library.cc \ + matrix3d.cc \ + perlin.cc \ + simul.cc \ + triangle.cc \ + triangle_gl.cc \ + vector.cc + +OPTIM_FLAGS = -O3 \ + -ffast-math \ + -funroll-loops \ + -felide-constructors \ + -fexpensive-optimizations \ + -finline-functions + +WARNING_FLAGS = -Wall \ + -W \ + -Wstrict-prototypes + +CFLAGS = $(DEBUG_FLAGS) \ + $(WARNING_FLAGS) \ + -DDARWIN + +# CFLAGS = $(OPTIM_FLAGS) \ +# $(WARNING_FLAGS) \ +# -DDARWIN + +# CFLAGS = $(DEBUG_FLAGS) \ +# $(OPTIM_FLAGS) \ +# $(WARNING_FLAGS) \ +# -DDARWIN + +# Sorry for that... +# I'll try to do something better soon. + +#GTK_IFLAGS = `gtk-config --cflags` + +OPENGL_IFLAGS = -I/usr/X11R6/include \ + -I/System/Library/Frameworks/OpenGL.framework/Versions/A/Headers \ + -I/System/Library/Frameworks/GLUT.framework/Versions/A/Headers + +IFLAGS = -I/usr/include \ + $(OPENGL_IFLAGS) + +#GTK_LFLAGS = `gtk-config --libs` + +OPENGL_LFLAGS = -L/usr/X11R6/lib \ + -L/sw/lib \ + -lX11 \ + -lGL \ + -lGLU \ + -lglut + +LFLAGS = -L/usr/lib \ + -L/usr/pkg/lib \ + -lc \ + -lm \ + $(OPENGL_LFLAGS) + +OBJ = $(SRC:.cc=.o) + +all : $(NAME) + +$(NAME) : $(OBJ) + $(CC) $(OBJ) $(LFLAGS) -o $(NAME) + +.cc.o : + $(CC) $(CFLAGS) $(IFLAGS) $< -c -o $@ + +clean : + $(RM) $(OBJ) + $(RM) *~ \#*\# + +distclean : clean + $(RM) $(NAME) + +re : clean all + +tarball : distclean + $(ECHO) "Archiving..." + cd .. && $(ARCHIVE) $(NAME).tar.gz $(DIRECTORY) + $(ECHO) "Done !" + +love : + $(ECHO) "Sorry, I have a headache..." diff --git a/branches/hugues/glagen/3d/Makefile.windows b/branches/hugues/glagen/3d/Makefile.windows new file mode 100644 index 0000000..1a9a741 --- /dev/null +++ b/branches/hugues/glagen/3d/Makefile.windows @@ -0,0 +1,98 @@ +##============================================================================= +## +## 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 +## +## Makefile.win for Glagen : made by Zavie (Julien Guertault) +## +## www.glagen.org +## +##============================================================================= + +# Note : Makefile.win is overwritten by Dev-C++ when compiling + +NAME = glagen.exe + +CC = g++.exe + +WINDRES = windres.exe + +DEVCPP = # Put here the directory of the compiler : "C:/Dev-Cpp" + +SRC = main.cc \ + display.cc \ + dot.cc \ + dot_gl.cc \ + end.cc \ + frame.cc \ + isosahedron.cc \ + library.cc \ + matrix3d.cc \ + misc.cc \ + perlin.cc \ + simul.cc \ + time_unix.cc \ + triangle.cc \ + triangle_gl.cc \ + vector.cc + +RC = Glagen_private.rc + +RES = Glagen_private.res + +OPTIM_FLAGS = -fexpensive-optimizations -O3 + +IFLAGS = -I"$(DEVCPP)/include" \ + -I"$(DEVCPP)/include/c++" \ + -I"$(DEVCPP)/include/c++/mingw32" \ + -I"$(DEVCPP)/include/c++/backward" + +CFLAGS = $(OPTIM_FLAGS) \ + -DWINDOWS + +LFLAGS = -L"$(DEVCPP)/lib" \ + -mwindows \ + -lopengl32 \ + -lglu32 \ + -lglut32 + +OBJ = $(SRC:.cc=.o) + + +all: all-before $(NAME) all-after + +$(NAME): $(OBJ) + $(CPP) $(OBJ) -o $(NAME) $(LIBS) + +.cc.o : + $(CC) $(CFLAGS) $(IFLAGS) $< -c -o $@ + +$(RES): $(RC) + $(WINDRES) -i $(RC) -I rc -o $(RES) -O coff + +clean : + $(RM) $(OBJ) + $(RM) *~ \#*\# + +distclean : clean + $(RM) $(NAME) + +re : clean all diff --git a/branches/hugues/glagen/3d/data_glagen.hh b/branches/hugues/glagen/3d/data_glagen.hh new file mode 100644 index 0000000..e02332b --- /dev/null +++ b/branches/hugues/glagen/3d/data_glagen.hh @@ -0,0 +1,115 @@ +//============================================================================= +// +// 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_glagen.hh for Glagen : made by Zavie (Julien Guertault) +// +// www.glagen.org +// +//============================================================================= + +#ifndef DATA_GLAGEN_HH_ +# define DATA_GLAGEN_HH_ + +#ifdef DARWIN +# define float double +# define sqrtf sqrt +# define sinf sin +# define cosf cos +#endif + +#include +#include +#include "frame.hh" + +typedef struct +{ + class Frame frame; + float speed; + float altitude; +} observer_t; + +typedef enum + { + none, + surface, + object, + non_material, + other + } kind_lib_t; + +typedef struct +{ + kind_lib_t kind; + size_t size; + void *data; +} property_t; + +typedef struct +{ + kind_lib_t kind; + bool dynamic; + void (*run)(class Dot *, unsigned int); + char *name; +} library_t; + +typedef struct +{ + observer_t observer; + struct timeval time; + long start_time; + float float_time; + char step; + float size; + float square_size; + class Triangle *ref; + class Triangle *current; + int property; + library_t library[5]; + float split_dist_limit; + float split_norm_limit; + unsigned int triangles; + unsigned int max_triangles; + bool display_normal; + bool display_planet; + bool display_all; + bool third_view; + bool zoom; + bool light; + int mode; + int depth_test; + int x; + int y; +} glagen_t; + +extern glagen_t glagen; + +typedef struct +{ + float height; + float red; + float green; + float blue; + float alpha; +} surface_t; + +#endif // DATA_GLAGEN_HH_ diff --git a/branches/hugues/glagen/3d/display.cc b/branches/hugues/glagen/3d/display.cc new file mode 100644 index 0000000..a956274 --- /dev/null +++ b/branches/hugues/glagen/3d/display.cc @@ -0,0 +1,411 @@ +//============================================================================= +// +// 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 +// +// display.cc for Glagen : made by Zavie (Julien Guertault) +// +// www.glagen.org +// +//============================================================================= + +#include +#include +#include + +#ifndef DARWIN +# include +# include +# include +#else +# include +# include +# include +#endif + +#include "data_glagen.hh" +#include "end.hh" +#include "library.hh" +#include "time.hh" +#include "triangle.hh" + +bool pressed; +int x; +int y; +int xold; +int yold; + +static const GLfloat L0position[] = { 0.0, 1.0, -2.0, 0.0 }; +static const GLfloat L0ambient[] = { 0.0, 0.0, 0.0, 1.0 }; +static const GLfloat L0diffuse[] = { 1.0, 1.0, 1.0, 1.0 }; +static const GLfloat L0specular[] = { 1.0, 1.0, 1.0, 1.0 }; +static const GLfloat Mshiny = 50; + +void display_frame () +{ + Frame *o = &glagen.observer.frame; + + update_time (); + + glagen.step = glagen.step + 1; + if (glagen.display_planet == true) + library_caller (glagen.ref); + glagen.step = glagen.step + 1; + glagen.ref->Update_normal_visitor (); + glagen.step = glagen.step + 1; + + glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + glLoadIdentity (); + + // Third person view : the observer is represented by a frame + if (glagen.third_view == true) + { + // View initialization in third person view mode + gluPerspective(45, + float(glagen.x) / float(glagen.y), + 0.5, + 8.0); + gluLookAt (-4, 4, -4, + 1, -1, 1, + 0, 1, 0); + + // The frame representing the user's position + if (glagen.light == true) + glDisable(GL_LIGHTING); + glBegin (GL_LINES); + glColor3f(1.0, 1.0, 0.0); + glVertex3f(o->Origin_X (), o->Origin_Y (), o->Origin_Z ()); + glVertex3f(o->Origin_X () + o->Basis_X ().X () / 2, + o->Origin_Y () + o->Basis_X ().Y () / 2, + o->Origin_Z () + o->Basis_X ().Z () / 2); + glColor3f(0.0, 1.0, 1.0); + glVertex3f(o->Origin_X (), o->Origin_Y (), o->Origin_Z ()); + glVertex3f(o->Origin_X () + o->Basis_Y ().X () / 2, + o->Origin_Y () + o->Basis_Y ().Y () / 2, + o->Origin_Z () + o->Basis_Y ().Z () / 2); + glColor3f(1.0, 0.0, 1.0); + glVertex3f(o->Origin_X (), o->Origin_Y (), o->Origin_Z ()); + glVertex3f(o->Origin_X () + o->Basis_Z ().X () / 2, + o->Origin_Y () + o->Basis_Z ().Y () / 2, + o->Origin_Z () + o->Basis_Z ().Z () / 2); + + // Then the projection of the user's position on the planet's frame + glColor3f(1.0, 1.0, 1.0); + glVertex3f(0, 0, 0); + glVertex3f(o->Origin_X (), o->Origin_Y (), o->Origin_Z ()); + + glColor3f(1.0, 0.0, 0.0); + glVertex3f(0, 0, 0); + glVertex3f(o->Origin_X (), 0, 0); + + glColor3f(0.0, 1.0, 0.0); + glVertex3f(o->Origin_X (), 0, 0); + glVertex3f(o->Origin_X (), o->Origin_Y (), 0); + + glColor3f(0.0, 0.0, 1.0); + glVertex3f(o->Origin_X (), o->Origin_Y (), 0); + glVertex3f(o->Origin_X (), o->Origin_Y (), o->Origin_Z ()); + + glEnd (); + if (glagen.light == true) + glEnable(GL_LIGHTING); + } + else + { + // View initialization in normal view + if (glagen.x > glagen.y) + gluPerspective(45 * float(glagen.y) / float(glagen.x), + float(glagen.x) / float(glagen.y), + glagen.observer.altitude / 2, + glagen.observer.altitude + 1); + else + gluPerspective(45, + float(glagen.x) / float(glagen.y), + glagen.observer.altitude / 2, + glagen.observer.altitude + 1); + gluLookAt (o->Origin_X (), o->Origin_Y (), o->Origin_Z (), + o->Origin_X () + o->Basis_Z ().X (), + o->Origin_Y () + o->Basis_Z ().Y (), + o->Origin_Z () + o->Basis_Z ().Z (), + o->Basis_Y ().X (), o->Basis_Y ().Y (), o->Basis_Y (). Z ()); + } + + + // The light + if (glagen.light == true) + { + glLightfv(GL_LIGHT0, GL_POSITION, L0position); + glEnable(GL_LIGHTING); + } + + // The line calling the planet's display is just here + glagen.ref->Display (0); + glagen.step = glagen.step + 1; + + if (glagen.light == true) + glDisable (GL_LIGHTING); + +// // Uncomment those lines for an atmosphere === + glEnable (GL_BLEND); + glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); +// for (int current = 1; current < 100; current ++) +// { +// glagen.ref->Display (current); +// glagen.step = glagen.step + 1; +// } +// glDisable (GL_BLEND); +// // + + glFlush (); + + // On echange les buffers + glutSwapBuffers (); + glutPostRedisplay(); +} + +// +// Simple keyboard events catching +// +void Keyboard (unsigned char key_stroke, int, int) +{ + switch (key_stroke) + { + // Quit + case 'q': + case 'Q': + case 27: + end_all(); + } +} + +// +// Other keyboard events catching +// +void Keyboard_Special (int key_stroke, int, int) +{ + Frame *o = &glagen.observer.frame; + float ox = o->Origin_X (); + float oy = o->Origin_Y (); + float oz = o->Origin_Z (); + + switch (key_stroke) + { + case GLUT_KEY_UP: + o->Translate (o->Basis_Z () * glagen.observer.speed); + glagen.observer.speed = glagen.observer.altitude / 50; + glagen.observer.altitude = sqrtf (ox * ox + oy * oy + oz * oz) - 1; + if (glagen.zoom) + glagen.ref->Split_visitor (); + glagen.step = glagen.step + 1; + glagen.ref->Hide_visitor (); + glagen.step = glagen.step + 1; + break; + case GLUT_KEY_DOWN: + o->Translate (o->Basis_Z () * -glagen.observer.speed); + glagen.observer.speed = glagen.observer.altitude / 50; + glagen.observer.altitude = sqrtf (ox * ox + oy * oy + oz * oz) - 1; + if (glagen.zoom) + glagen.ref->Split_visitor (); + glagen.step = glagen.step + 1; + glagen.ref->Hide_visitor (); + glagen.step = glagen.step + 1; + break; + case GLUT_KEY_LEFT: + o->Translate (o->Basis_X () * glagen.observer.speed); + glagen.observer.speed = glagen.observer.altitude / 50; + glagen.observer.altitude = sqrtf (ox * ox + oy * oy + oz * oz) - 1; + if (glagen.zoom) + glagen.ref->Split_visitor (); + glagen.step = glagen.step + 1; + glagen.ref->Hide_visitor (); + glagen.step = glagen.step + 1; + break; + case GLUT_KEY_RIGHT: + o->Translate (o->Basis_X () * -glagen.observer.speed); + glagen.observer.speed = glagen.observer.altitude / 50; + glagen.observer.altitude = sqrtf (ox * ox + oy * oy + oz * oz) - 1; + if (glagen.zoom) + glagen.ref->Split_visitor (); + glagen.step = glagen.step + 1; + glagen.ref->Hide_visitor (); + glagen.step = glagen.step + 1; + break; + case GLUT_KEY_PAGE_UP: + o->Translate (o->Basis_Y () * glagen.observer.speed); + glagen.observer.speed = glagen.observer.altitude / 50; + glagen.observer.altitude = sqrtf (ox * ox + oy * oy + oz * oz) - 1; + if (glagen.zoom) + glagen.ref->Split_visitor (); + glagen.step = glagen.step + 1; + glagen.ref->Hide_visitor (); + glagen.step = glagen.step + 1; + break; + case GLUT_KEY_PAGE_DOWN: + o->Translate (o->Basis_Y () * -glagen.observer.speed); + glagen.observer.speed = glagen.observer.altitude / 50; + glagen.observer.altitude = sqrtf (ox * ox + oy * oy + oz * oz) - 1; + if (glagen.zoom) + glagen.ref->Split_visitor (); + glagen.step = glagen.step + 1; + glagen.ref->Hide_visitor (); + glagen.step = glagen.step + 1; + break; + case GLUT_KEY_F1: + if (glagen.mode == 1) + glPolygonMode (GL_FRONT_AND_BACK, GL_LINE); + else + { + if (glagen.mode == 2) + glPolygonMode (GL_FRONT_AND_BACK, GL_POINT); + else + glPolygonMode (GL_FRONT_AND_BACK, GL_FILL); + } + glagen.mode++; + if (glagen.mode > 3) + glagen.mode = 1; + glutPostRedisplay (); + break; + case GLUT_KEY_F2: + glagen.depth_test = !glagen.depth_test; + if (glagen.depth_test == true) + glEnable (GL_DEPTH_TEST); + else + glDisable (GL_DEPTH_TEST); + glutPostRedisplay (); + break; + case GLUT_KEY_F3: + glagen.display_normal = !glagen.display_normal; + break; + case GLUT_KEY_F4: + glagen.display_planet = !glagen.display_planet; + break; + case GLUT_KEY_F5: + glagen.display_all = !glagen.display_all; + break; + case GLUT_KEY_F6: + glagen.third_view = !glagen.third_view; + break; + case GLUT_KEY_F7: + glagen.light = !glagen.light; + break; + } +// { +// float alt = glagen.observer.altitude * 12000000; +// if (alt > 1000) +// printf ("%.3f km\n", alt / 1000); +// else +// printf ("%.3f m\n", alt); +// } +} + +void reshape (int x, int y) +{ + glagen.x = x; + glagen.y = y; + glViewport (0, 0, x, y); + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + glMatrixMode(GL_MODELVIEW); +} + +void mouse(int button, int state, int x, int y) +{ + // sleft button pressed + if (button == GLUT_LEFT_BUTTON && state == GLUT_DOWN) + pressed = true; + // left button released + if (button == GLUT_LEFT_BUTTON && state == GLUT_UP) + { + pressed = false; + if (glagen.zoom) + glagen.ref->Split_visitor (); + glagen.step = glagen.step + 1; + glagen.ref->Hide_visitor (); + glagen.step = glagen.step + 1; + } + xold = x; // saving position + yold = y; +} + +void mousemotion(int x, int y) +{ + float angle[3]; + + if (pressed) // left button + { + angle[0] = (y - yold) / 100.0; + angle[1] = (xold - x) / 100.0; + angle[2] = 0; + } + else + { + angle[0] = 0; + angle[1] = 0; + angle[2] = (xold - x) / 50.0; + } + + glagen.observer.frame.Rotate (angle[0], glagen.observer.frame.Basis_X ()); + glagen.observer.frame.Rotate (angle[1], glagen.observer.frame.Basis_Y ()); + glagen.observer.frame.Rotate (angle[2], glagen.observer.frame.Basis_Z ()); + glagen.ref->Hide_visitor (); + glagen.step = glagen.step + 1; + glutPostRedisplay (); + xold = x; + yold = y; +} + +void display(int *narg, char ***args) +{ + // Glut + glutInit (narg, *args); + glutInitDisplayMode (GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH); + glutInitWindowSize (600, 600); + glutCreateWindow ("Test Glagen"); + + // OpenGL + glClearColor (0.0, 0.0, 0.0, 0.0); + glColor3f (1.0, 1.0, 1.0); + glEnable (GL_DEPTH_TEST); + glagen.mode = 1; + glPolygonMode (GL_FRONT_AND_BACK, GL_FILL); + + // Light + glLightModeli (GL_LIGHT_MODEL_LOCAL_VIEWER, GL_TRUE); + glEnable (GL_LIGHTING); + glEnable (GL_LIGHT0); + glLightfv (GL_LIGHT0, GL_DIFFUSE, L0diffuse); + glLightfv (GL_LIGHT0, GL_SPECULAR, L0specular); + glLightfv (GL_LIGHT0, GL_AMBIENT, L0ambient); + glEnable (GL_COLOR_MATERIAL); + glDisable (GL_LIGHTING); + + // Events functions + glutDisplayFunc (display_frame); + glutKeyboardFunc (Keyboard); + glutSpecialFunc (Keyboard_Special); + glutReshapeFunc (reshape); + glutMouseFunc (mouse); + glutMotionFunc (mousemotion); + + // Glut main loop ;-) + glutMainLoop (); + return; +} diff --git a/branches/hugues/glagen/3d/display.hh b/branches/hugues/glagen/3d/display.hh new file mode 100644 index 0000000..da18a8f --- /dev/null +++ b/branches/hugues/glagen/3d/display.hh @@ -0,0 +1,44 @@ +//============================================================================= +// +// 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 +// +// display.hh for Glagen : made by Zavie (Julien Guertault) +// +// www.glagen.org +// +//============================================================================= + +#ifndef DISPLAY_HH_ +# define DISPLAY_HH_ + +#include "dot.hh" +#include "triangle.hh" + +void display_frame (); +void Keyboard (unsigned char, int, int); +void Keyboard_Special (int, int, int); +void reshape (int, int); +void mouse (int, int, int, int); +void mousemotion (int, int); +void display (int *, char ***); + +#endif // DISPLAY_HH_ diff --git a/branches/hugues/glagen/3d/dot.cc b/branches/hugues/glagen/3d/dot.cc new file mode 100644 index 0000000..86df62b --- /dev/null +++ b/branches/hugues/glagen/3d/dot.cc @@ -0,0 +1,184 @@ +//============================================================================= +// +// 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 +// +// dot.cc for Glagen : made by Zavie (Julien Guertault) +// +// www.glagen.org +// +//============================================================================= + +#include +#include +#include "data_glagen.hh" +#include "dot.hh" + +// Constructor and destructor +Dot :: Dot (const float x, const float y, const float z): + _x(x), _y(y), _z(z), _use(0), _computed(false) +{ + _normal = Vector (0, 0, 0); + _property = new property_t *[glagen.property]; // delete : dot.cc l61 + for (int current = 0; current < glagen.property; current++) + _property[current] = NULL; + for (int current = 0; current < 6; current++) + _owner[current] = NULL; + step = glagen.step; +} + +Dot :: ~Dot () +{ + if (_property != NULL) + { + for (int current = 0; current < glagen.property; current++) + if (_property[current] != NULL) + { + if (_property[current]->data != NULL) + delete _property[current]->data; // FIXME : warning here. + delete _property[current]; + } + delete _property; + } +} + + +// ======================================================================= Read + +float Dot :: x () const { return _x; } +float Dot :: y () const { return _y; } +float Dot :: z () const { return _z; } + +Triangle *Dot :: Owner (int triangle) const +{ + if (triangle >= 0 && triangle < 6) + return _owner[triangle]; + return NULL; +} + +Vector &Dot :: Normal () { return _normal; } + +property_t *Dot :: Property (const int i) const +{ + return _property[i]; +} + +bool Dot :: Is_computed () const +{ + return _computed; +} + +bool Dot :: Is_checked () const +{ + return (step == glagen.step); +} + + +// ====================================================================== Write + +void Dot :: Set (const float x, const float y, const float z) +{ + _x = x; + _y = y; + _z = z; +} + +void Dot :: Use (Triangle *old_one, Triangle *new_one) +{ + Change_owner (old_one, new_one); + _use = _use + 1; +} + +bool Dot :: Drop (Triangle *old_one, Triangle *new_one) +{ + Change_owner (old_one, new_one); + _use = _use - 1; + return (_use <= 0); +} + +void Dot :: Update_normal () +{ + int count = 0; + + if (step == glagen.step) + return; + step = glagen.step; + + _normal.Set (0, 0, 0); + for (int current = 0; current < 6; current++) + if (_owner[current] != NULL) + { + _normal = _normal + _owner[current]->Normal_real (); + count++; + } + if (count != 0) + _normal = _normal / count; +} + +void Dot :: Del_property (const int i) +{ + if (_property[i] != NULL) + { + delete _property[i]; + _property[i] = NULL; + } +} + +void Dot :: Set_property (const int i, property_t *property) +{ + _property[i] = property; +} + +void Dot :: Computed () { _computed = true; } + +void Dot :: Checked () { step = glagen.step; } + +// ====================================================================== Other + +Dot *Dot :: Middle (const Dot *b) +{ + float xc = (x () + b->x ()) / 2; + float yc = (y () + b->y ()) / 2; + float zc = (z () + b->z ()) / 2; + float adjust = sqrtf (glagen.square_size / (xc * xc + yc * yc + zc * zc)); + xc = xc * adjust; + yc = yc * adjust; + zc = zc * adjust; + return new Dot (xc, yc, zc); // delete : triangle.cc l99, 101, 103 +} + +// ================================================================== Protected + +void Dot :: Change_owner (Triangle *old_one, Triangle *new_one) +{ + for (int current = 0; current < 6; current++) + if (_owner[current] == old_one) + { + _owner[current] = new_one; + return; + } + for (int current = 0; current < 6; current++) + if (_owner[current] == NULL) + { + _owner[current] = new_one; + return; + } +} diff --git a/branches/hugues/glagen/3d/dot.hh b/branches/hugues/glagen/3d/dot.hh new file mode 100644 index 0000000..8e17049 --- /dev/null +++ b/branches/hugues/glagen/3d/dot.hh @@ -0,0 +1,84 @@ +//============================================================================= +// +// 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 +// +// dot.hh for Glagen : made by Zavie (Julien Guertault) +// +// www.glagen.org +// +//============================================================================= + +#ifndef DOT_HH_ +# define DOT_HH_ + +#include "data_glagen.hh" +#include "triangle.hh" + +class Dot +{ +public: + + // Constructor and destructor + Dot (const float, const float, const float); + ~Dot (); + + // Read + float x () const; + float y () const; + float z () const; + + class Triangle *Owner (const int) const; + class Vector &Normal (); + + property_t *Property (const int) const; + bool Is_computed () const; + bool Is_checked () const; + + // Write + void Set (const float, const float, const float); + void Use (class Triangle *, class Triangle *); + bool Drop (class Triangle *, class Triangle *); + void Update_normal (); + void Del_property (const int); + void Set_property (const int, property_t *); + void Computed (); + void Checked (); + + // Other + Dot *Middle (const Dot *); + void Display (const unsigned int); + +protected: + void Change_owner (class Triangle *, class Triangle *); + + float _x; + float _y; + float _z; + unsigned char _use; + class Triangle *_owner[6]; + class Vector _normal; + property_t **_property; + bool _computed; + char step; +}; + +#endif // DOT_HH_ diff --git a/branches/hugues/glagen/3d/dot_gl.cc b/branches/hugues/glagen/3d/dot_gl.cc new file mode 100644 index 0000000..463df20 --- /dev/null +++ b/branches/hugues/glagen/3d/dot_gl.cc @@ -0,0 +1,83 @@ +//============================================================================= +// +// 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 +// +// dot_gl.cc for Glagen : made by Zavie (Julien Guertault) +// +// www.glagen.org +// +//============================================================================= + +#ifndef DARWIN +# include +# include +#else +# include +# include +#endif + +#include "data_glagen.hh" +#include "dot.hh" + +// +// Call the appropriate OpenGl functions for the dot +// +void Dot :: Display (const unsigned int id) +{ + surface_t *surface; + float adjust; + + if (glagen.display_planet) + { + if (NULL == _property[id]) + { + adjust = 0; + glColor3f ((1 + _x) / 2, (1 + _y) / 2, (1 + _z) / 2); + } + else + { + surface = static_cast (_property[id]->data); + if (NULL == surface) + { + adjust = 0; + glColor3f ((1 + _x) / 2, (1 + _y) / 2, (1 + _z) / 2); + } + else + { + adjust = surface->height; + glColor4f (surface->red, + surface->green, + surface->blue, + surface->alpha); + } + } + } + else + { + adjust = 0; + glColor3f ((1 + _x) / 2, (1 + _y) / 2, (1 + _z) / 2); + } + glNormal3f(_normal.X (), _normal.Y (), _normal.Z ()); + glVertex3f ((glagen.size + adjust) * _x, + (glagen.size + adjust) * _y, + (glagen.size + adjust) * _z); +} diff --git a/branches/hugues/glagen/3d/end.cc b/branches/hugues/glagen/3d/end.cc new file mode 100644 index 0000000..a16a634 --- /dev/null +++ b/branches/hugues/glagen/3d/end.cc @@ -0,0 +1,53 @@ +//============================================================================= +// +// 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 +// +// main.cc for Glagen : made by Zavie (Julien Guertault) +// +// www.glagen.org +// +//============================================================================= + +#include "data_glagen.hh" +#include "triangle.hh" + +void destroy_tree (Triangle *triangle) +{ + Triangle *next; + bool continue_deleting = true; + + while (continue_deleting) + { + if (0 == (next = triangle->Neighbor_ab ())) + if (0 == (next = triangle->Neighbor_bc ())) + if (0 == (next = triangle->Neighbor_ca ())) + continue_deleting = false; + delete triangle; + triangle = next; + } + exit (0); +} + +void end_all () +{ + destroy_tree(glagen.ref); +} diff --git a/branches/hugues/glagen/3d/end.hh b/branches/hugues/glagen/3d/end.hh new file mode 100644 index 0000000..402c4b2 --- /dev/null +++ b/branches/hugues/glagen/3d/end.hh @@ -0,0 +1,39 @@ +//============================================================================= +// +// 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 +// +// main.cc for Glagen : made by Zavie (Julien Guertault) +// +// www.glagen.org +// +//============================================================================= + +#ifndef END_HH_ +# define END_HH_ + +#include "data_glagen.hh" +#include "triangle.hh" + +void destroy_tree (Triangle *); +void end_all (); + +#endif // END_HH_ diff --git a/branches/hugues/glagen/3d/frame.cc b/branches/hugues/glagen/3d/frame.cc new file mode 100644 index 0000000..6f3aabd --- /dev/null +++ b/branches/hugues/glagen/3d/frame.cc @@ -0,0 +1,152 @@ +//============================================================================= +// +// 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 +// +// frame.cc for Glagen : made by Zavie (Julien Guertault) +// +// www.glagen.org +// +//============================================================================= + +#include "data_glagen.hh" +#include "frame.hh" +#include "matrix3d.hh" +#include "vector.hh" + +// ================================================ Constructors and destructor + +Frame :: Frame () +{ + _origin[0] = 0; + _origin[1] = 0; + _origin[2] = 0; + _basis[0] = Vector(1, 0, 0); + _basis[1] = Vector(0, 1, 0); + _basis[2] = Vector(0, 0, 1); +} + +Frame :: Frame (float origin[3]) +{ + _origin[0] = origin[0]; + _origin[1] = origin[1]; + _origin[2] = origin[2]; + _basis[0] = Vector(1, 0, 0); + _basis[1] = Vector(0, 1, 0); + _basis[2] = Vector(0, 0, 1); +} + +Frame :: Frame (float origin[3], Vector basis[3]) +{ + _origin[0] = origin[0]; + _origin[1] = origin[1]; + _origin[2] = origin[2]; + _basis[0] = Vector(basis[0]); + _basis[1] = Vector(basis[1]); + _basis[2] = Vector(basis[2]); +} + +Frame :: ~Frame () {} + +// ==================================================================== Reading + +float Frame :: Origin_X () const { return _origin[0]; } +float Frame :: Origin_Y () const { return _origin[1]; } +float Frame :: Origin_Z () const { return _origin[2]; } +Vector Frame :: Basis_X () const { return _basis[0]; } +Vector Frame :: Basis_Y () const { return _basis[1]; } +Vector Frame :: Basis_Z () const { return _basis[2]; } + +Vector Frame :: View () { return Vector (_basis[2]); } + +Matrix44 Frame :: GetMatrix () +{ + int x; + float basis_matrix[3][3]; + + for (x = 0; x < 3; x++) + { + basis_matrix[x][0] = _basis[x].X (); + basis_matrix[x][1] = _basis[x].Y (); + basis_matrix[x][2] = _basis[x].Z (); + } + Matrix44 rot_matrix(basis_matrix); + Matrix44 trans_matrix(_origin); + return Matrix44 (trans_matrix * rot_matrix); +} + +Matrix44 Frame :: GetCamMatrix () +{ + int x; + float basis_matrix[3][3]; + + for (x = 0; x < 3; x++) + { + basis_matrix[x][0] = _basis[x].X (); + basis_matrix[x][1] = _basis[x].Y (); + basis_matrix[x][2] = _basis[x].Z (); + } + Matrix44 rot_matrix(basis_matrix); + Matrix44 trans_matrix(_origin); + return Matrix44 (rot_matrix * trans_matrix); +} + +// ==================================================================== Writing + +void Frame :: Reset_origin () +{ + _origin[0] = 0; + _origin[1] = 0; + _origin[2] = 0; +} + +void Frame :: Reset_basis () +{ + _basis[0].Set (1, 0, 0) ; + _basis[1].Set (0, 1, 0) ; + _basis[2].Set (0, 0, 1) ; +} + +void Frame :: Set_origin (const float origin[3]) +{ + _origin[0] = origin[0]; + _origin[1] = origin[1]; + _origin[2] = origin[2]; +} + +void Frame :: Translate (const Vector v) +{ + _origin[0] = _origin[0] + v.X (); + _origin[1] = _origin[1] + v.Y (); + _origin[2] = _origin[2] + v.Z (); +} + +void Frame :: Rotate (const float angle, const Vector v) +{ + Matrix33 rot (angle, v); + + _basis[0] = rot * _basis[0]; + _basis[1] = rot * _basis[1]; + _basis[2] = rot * _basis[2]; + _basis[0].Normalize (); + _basis[1].Normalize (); + _basis[2].Normalize (); +} diff --git a/branches/hugues/glagen/3d/frame.hh b/branches/hugues/glagen/3d/frame.hh new file mode 100644 index 0000000..2fd125f --- /dev/null +++ b/branches/hugues/glagen/3d/frame.hh @@ -0,0 +1,69 @@ +//============================================================================= +// +// 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 +// +// frame.hh for Glagen : made by Zavie (Julien Guertault) +// +// www.glagen.org +// +//============================================================================= + +#ifndef FRAME_HH_ +# define FRAME_HH_ + +#include "matrix3d.hh" +#include "vector.hh" + +class Frame +{ +public: + // Constructors and destructor + Frame (); + Frame (float origin[3]); + Frame (float origin[3], class Vector basis[3]); + ~Frame(); + + // Reading + float Origin_X () const; + float Origin_Y () const; + float Origin_Z () const; + class Vector Basis_X () const; + class Vector Basis_Y () const; + class Vector Basis_Z () const; + + class Vector View (); + Matrix44 GetMatrix (); + Matrix44 GetCamMatrix (); + + // Writing + void Reset_origin (); + void Reset_basis (); + void Set_origin (const float origin[3]); + void Translate (const class Vector); + void Rotate (const float, const class Vector); + +protected: + float _origin[3]; + class Vector _basis[3]; +}; + +#endif // FRAME_HH_ diff --git a/branches/hugues/glagen/3d/glagen b/branches/hugues/glagen/3d/glagen new file mode 100755 index 0000000..c387ba1 Binary files /dev/null and b/branches/hugues/glagen/3d/glagen differ diff --git a/branches/hugues/glagen/3d/header.cc b/branches/hugues/glagen/3d/header.cc new file mode 100644 index 0000000..cdcdf6d --- /dev/null +++ b/branches/hugues/glagen/3d/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 Zavie (Julien Guertault) +// +// www.glagen.org +// +//============================================================================= diff --git a/branches/hugues/glagen/3d/isosahedron.cc b/branches/hugues/glagen/3d/isosahedron.cc new file mode 100644 index 0000000..1f3fc71 --- /dev/null +++ b/branches/hugues/glagen/3d/isosahedron.cc @@ -0,0 +1,220 @@ +//============================================================================= +// +// 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 +// +// isosahedron.cc for Glagen : made by Zavie (Julien Guertault) +// +// www.glagen.org +// +//============================================================================= + +#include +#include "data_glagen.hh" +#include "dot.hh" +#include "triangle.hh" + +// The regular polyhedron we use to create the planet is an isosahedron : +// 20 triangular faces, 12 vertex and 30 edges +// +// Vertex coordinates : +// +// { 0, 1, 0 } = P0 +// { sqrtf((5 - sqrtf(5)) / 10), (sqrtf(5)) / 5, -(5 + sqrtf(5)) / 10 } = P1 +// { -sqrtf((5 - sqrtf(5)) / 10), (sqrtf(5)) / 5, -(5 + sqrtf(5)) / 10 } = P2 +// { -sqrtf((5 + sqrtf(5)) / 10), (sqrtf(5)) / 5, (5 - sqrtf(5)) / 10 } = P3 +// { 0, (sqrtf(5)) / 5, 2 x ((sqrtf(5)) / 5) } = P4 +// { sqrtf((5 + sqrtf(5)) / 10), (sqrtf(5)) / 5, (5 - sqrtf(5)) / 10 } = P5 +// { sqrtf((5 - sqrtf(5)) / 10), -(sqrtf(5)) / 5, (5 + sqrtf(5)) / 10 } = P6 +// { -sqrtf((5 - sqrtf(5)) / 10), -(sqrtf(5)) / 5, (5 + sqrtf(5)) / 10 } = P7 +// { -sqrtf((5 + sqrtf(5)) / 10), -(sqrtf(5)) / 5, -(5 - sqrtf(5)) / 10 } = P8 +// { 0, -(sqrtf(5)) / 5, -2 x ((sqrtf(5)) / 5) } = P9 +// { sqrtf((5 + sqrtf(5)) / 10), -(sqrtf(5)) / 5, -(5 + sqrtf(5)) / 10 } = P10 +// { 0, -1, 0 } = P11 +// +// Faces : +// +// F0 = P0, P1, P2 +// F1 = P0, P2, P3 +// F2 = P0, P3, P4 +// F3 = P0, P4, P5 +// F4 = P0, P5, P1 +// F5 = P2, P1, P9 +// F6 = P8, P2, P9 +// F7 = P3, P2, P8 +// F8 = P7, P3, P8 +// F9 = P4, P3, P7 +// F10 = P6, P4, P7 +// F11 = P5, P4, P6 +// F12 = P10, P5, P6 +// F13 = P10, P1, P5 +// F14 = P9, P1, P10 +// F15 = P11, P8, P9 +// F16 = P11, P7, P8 +// F17 = P11, P6, P7 +// F18 = P11, P10, P6 +// F19 = P11, P9, P10 + +Triangle *isosahedron (float size) +{ + Dot *vertex[12]; + Triangle *face[20]; + float expr_1 = size * sqrtf((5 + sqrtf(5)) / 10); + float expr_2 = size * sqrtf((5 - sqrtf(5)) / 10); + float expr_3 = size * (5 + sqrtf(5)) / 10; + float expr_4 = size * (5 - sqrtf(5)) / 10; + float expr_5 = size * (sqrtf(5)) / 5; + + // Creation of the vertex + vertex[0] = new Dot ( 0, 1, 0); + vertex[1] = new Dot ( expr_2, expr_5, -expr_3); + vertex[2] = new Dot (-expr_2, expr_5, -expr_3); + vertex[3] = new Dot (-expr_1, expr_5, expr_4); + vertex[4] = new Dot ( 0, expr_5, 2 * expr_5); + vertex[5] = new Dot ( expr_1, expr_5, expr_4); + vertex[6] = new Dot ( expr_2, -expr_5, expr_3); + vertex[7] = new Dot (-expr_2, -expr_5, expr_3); + vertex[8] = new Dot (-expr_1, -expr_5, -expr_4); + vertex[9] = new Dot ( 0, -expr_5, -2 * expr_5); + vertex[10] = new Dot ( expr_1, -expr_5, -expr_4); + vertex[11] = new Dot ( 0, -1, 0); + + // Creation of the triangles + face[0] = new Triangle (vertex[0], vertex[1], vertex[2], NULL); + face[1] = new Triangle (vertex[0], vertex[2], vertex[3], NULL); + face[2] = new Triangle (vertex[0], vertex[3], vertex[4], NULL); + face[3] = new Triangle (vertex[0], vertex[4], vertex[5], NULL); + face[4] = new Triangle (vertex[0], vertex[5], vertex[1], NULL); + face[5] = new Triangle (vertex[2], vertex[1], vertex[9], NULL); + face[6] = new Triangle (vertex[8], vertex[2], vertex[9], NULL); + face[7] = new Triangle (vertex[3], vertex[2], vertex[8], NULL); + face[8] = new Triangle (vertex[7], vertex[3], vertex[8], NULL); + face[9] = new Triangle (vertex[4], vertex[3], vertex[7], NULL); + face[10] = new Triangle (vertex[6], vertex[4], vertex[7], NULL); + face[11] = new Triangle (vertex[5], vertex[4], vertex[6], NULL); + face[12] = new Triangle (vertex[10], vertex[5], vertex[6], NULL); + face[13] = new Triangle (vertex[10], vertex[1], vertex[5], NULL); + face[14] = new Triangle (vertex[9], vertex[1], vertex[10], NULL); + face[15] = new Triangle (vertex[11], vertex[8], vertex[9], NULL); + face[16] = new Triangle (vertex[11], vertex[7], vertex[8], NULL); + face[17] = new Triangle (vertex[11], vertex[6], vertex[7], NULL); + face[18] = new Triangle (vertex[11], vertex[10], vertex[6], NULL); + face[19] = new Triangle (vertex[11], vertex[9], vertex[10], NULL); + + // Setting up of the connexity + face[0]->Make_connexity (face[1]); + face[0]->Make_connexity (face[4]); + face[0]->Make_connexity (face[5]); + + face[1]->Make_connexity (face[0]); + face[1]->Make_connexity (face[2]); + face[1]->Make_connexity (face[7]); + + face[2]->Make_connexity (face[1]); + face[2]->Make_connexity (face[3]); + face[2]->Make_connexity (face[9]); + + face[3]->Make_connexity (face[2]); + face[3]->Make_connexity (face[4]); + face[3]->Make_connexity (face[11]); + + face[4]->Make_connexity (face[0]); + face[4]->Make_connexity (face[3]); + face[4]->Make_connexity (face[13]); + + face[5]->Make_connexity (face[0]); + face[5]->Make_connexity (face[6]); + face[5]->Make_connexity (face[14]); + + face[6]->Make_connexity (face[5]); + face[6]->Make_connexity (face[7]); + face[6]->Make_connexity (face[15]); + + face[7]->Make_connexity (face[1]); + face[7]->Make_connexity (face[6]); + face[7]->Make_connexity (face[8]); + + face[8]->Make_connexity (face[7]); + face[8]->Make_connexity (face[9]); + face[8]->Make_connexity (face[16]); + + face[9]->Make_connexity (face[2]); + face[9]->Make_connexity (face[8]); + face[9]->Make_connexity (face[10]); + + face[10]->Make_connexity (face[9]); + face[10]->Make_connexity (face[11]); + face[10]->Make_connexity (face[17]); + + face[11]->Make_connexity (face[3]); + face[11]->Make_connexity (face[10]); + face[11]->Make_connexity (face[12]); + + face[12]->Make_connexity (face[11]); + face[12]->Make_connexity (face[13]); + face[12]->Make_connexity (face[18]); + + face[13]->Make_connexity (face[4]); + face[13]->Make_connexity (face[12]); + face[13]->Make_connexity (face[14]); + + face[14]->Make_connexity (face[5]); + face[14]->Make_connexity (face[13]); + face[14]->Make_connexity (face[19]); + + face[15]->Make_connexity (face[6]); + face[15]->Make_connexity (face[16]); + face[15]->Make_connexity (face[19]); + + face[16]->Make_connexity (face[8]); + face[16]->Make_connexity (face[15]); + face[16]->Make_connexity (face[17]); + + face[17]->Make_connexity (face[10]); + face[17]->Make_connexity (face[16]); + face[17]->Make_connexity (face[18]); + + face[18]->Make_connexity (face[12]); + face[18]->Make_connexity (face[17]); + face[18]->Make_connexity (face[19]); + + face[19]->Make_connexity (face[14]); + face[19]->Make_connexity (face[15]); + face[19]->Make_connexity (face[18]); + + return face[0]; +} + +void split_all (Triangle *triangle) +{ + if (triangle->Is_checked ()) + return; + triangle->Checked (); + + triangle->Split (); + + if (triangle->Neighbor_ab () != 0) + split_all (triangle->Neighbor_ab ()); + if (triangle->Neighbor_bc () != 0) + split_all (triangle->Neighbor_bc ()); + if (triangle->Neighbor_ca () != 0) + split_all (triangle->Neighbor_ca ()); +} diff --git a/branches/hugues/glagen/3d/isosahedron.hh b/branches/hugues/glagen/3d/isosahedron.hh new file mode 100644 index 0000000..f339154 --- /dev/null +++ b/branches/hugues/glagen/3d/isosahedron.hh @@ -0,0 +1,38 @@ +//============================================================================= +// +// 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 +// +// isosahedron.hh for Glagen : made by Zavie (Julien Guertault) +// +// www.glagen.org +// +//============================================================================= + +#ifndef ISOSAHEDRON_HH_ +# define ISOSAHEDRON_HH_ + +#include "triangle.hh" + +Triangle *isosahedron (float); +void split_all (Triangle *); + +#endif // ISOCAHEDRON_HH_ diff --git a/branches/hugues/glagen/3d/library.cc b/branches/hugues/glagen/3d/library.cc new file mode 100644 index 0000000..19d706f --- /dev/null +++ b/branches/hugues/glagen/3d/library.cc @@ -0,0 +1,100 @@ +//============================================================================= +// +// 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 +// +// library.cc for Glagen : made by Zavie (Julien Guertault) +// +// www.glagen.org +// +//============================================================================= + +#include "dot.hh" +#include "triangle.hh" +#include "data_glagen.hh" +#include "simul.hh" + +// This visitor applies the given library to each dot +void library_visitor (void (library)(Dot*, unsigned int), + bool dynamic, + Triangle *triangle) +{ + if (triangle->Is_checked ()) + return; + + if (triangle->A ()->Is_checked () == false && + (dynamic == true || + triangle->A ()->Is_computed () == false)) + { + library (triangle->A (), triangle->Level ()); + triangle->A ()->Computed (); + triangle->A ()->Checked (); + } + if (triangle->B ()->Is_checked () == false && + (dynamic == true || + triangle->B ()->Is_computed () == false)) + { + library (triangle->B (), triangle->Level ()); + triangle->B ()->Computed (); + triangle->B ()->Checked (); + } + if (triangle->C ()->Is_checked () == false && + (dynamic == true || + triangle->C ()->Is_computed () == false)) + { + library (triangle->C (), triangle->Level ()); + triangle->C ()->Computed (); + triangle->C ()->Checked (); + } + + if (triangle->Is_split ()) + { + library_visitor (library, dynamic, triangle->Child_center ()); + library_visitor (library, dynamic, triangle->Child_a ()); + library_visitor (library, dynamic, triangle->Child_b ()); + library_visitor (library, dynamic, triangle->Child_c ()); + } + + triangle->Checked (); + if (triangle->Father() == NULL) + { + if (triangle->Neighbor_ab () != NULL) + library_visitor (library, dynamic, triangle->Neighbor_ab ()); + if (triangle->Neighbor_bc () != NULL) + library_visitor (library, dynamic, triangle->Neighbor_bc ()); + if (triangle->Neighbor_ca () != NULL) + library_visitor (library, dynamic, triangle->Neighbor_ca ()); + } +} + +// Here we call the visitor for each library +void library_caller (Triangle *triangle) +{ + void *(lib)(Dot *, unsigned int); + + for (int current = 0; glagen.library[current].kind != none; current++) + { + library_visitor (glagen.library[current].run, + glagen.library[current].dynamic, + triangle); + glagen.step = glagen.step + 1; + } +} diff --git a/branches/hugues/glagen/3d/library.hh b/branches/hugues/glagen/3d/library.hh new file mode 100644 index 0000000..acb262f --- /dev/null +++ b/branches/hugues/glagen/3d/library.hh @@ -0,0 +1,40 @@ +//============================================================================= +// +// 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 +// +// library.cc for Glagen : made by Zavie (Julien Guertault) +// +// www.glagen.org +// +//============================================================================= + +#ifndef LIBRARY_VISITOR_HH_ +# define LIBRARY_VISITOR_HH_ + +#include "triangle.hh" + +void library_visitor (void *(library)(Dot*, unsigned int), + bool, + Triangle *); +void library_caller (Triangle *); + +#endif // LIBRARY_VISITOR_HH_ diff --git a/branches/hugues/glagen/3d/main.cc b/branches/hugues/glagen/3d/main.cc new file mode 100644 index 0000000..d2d3561 --- /dev/null +++ b/branches/hugues/glagen/3d/main.cc @@ -0,0 +1,132 @@ +//============================================================================= +// +// 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 +// +// main.cc for Glagen : made by Zavie (Julien Guertault) +// +// www.glagen.org +// +//============================================================================= + +#include +#include +#include +#include +#include "dot.hh" +#include "data_glagen.hh" +#include "display.hh" +#include "frame.hh" +#include "isosahedron.hh" +#include "library.hh" +#include "matrix3d.hh" +#include "perlin.hh" +#include "time.hh" +#include "triangle.hh" +#include "simul.hh" + +glagen_t glagen; + +void init_all () +{ + float origin[3]; + + Perlin_init (); + origin[0] = 0; + origin[1] = 0; + origin[2] = -3; + glagen.observer.frame.Set_origin (origin); + glagen.observer.altitude = sqrtf (glagen.observer.frame.Origin_X () * + glagen.observer.frame.Origin_X () + + glagen.observer.frame.Origin_Y () * + glagen.observer.frame.Origin_Y () + + glagen.observer.frame.Origin_Z () * + glagen.observer.frame.Origin_Z ()) - 1; + glagen.observer.speed = 0.1 + glagen.observer.altitude / 50; + glagen.triangles = 0; + + init_time (); + + //Limite : entre 50000 et 200000... + glagen.max_triangles = 100000; + glagen.step = 0; + glagen.size = 1; + glagen.square_size = glagen.size * glagen.size; + // + // Simulation + // + glagen.property = 200; + // 0.05 et 0.4 is quite good + glagen.split_dist_limit = 0.05; + glagen.split_norm_limit = 0.4; + // + glagen.ref = isosahedron (glagen.size); + glagen.step++; + + // Debug options + glagen.display_normal = false; + glagen.display_planet = true; + glagen.display_all = false; + glagen.third_view = false; + glagen.zoom = true; + glagen.depth_test = true; + glagen.light = false; +} + +int main (int narg, char **args) +{ +// printf("int : %d\n", sizeof (int)); + init_all(); + simule_lib_load(); + + if (glagen.zoom) + { + glagen.current = glagen.ref; + glagen.ref->Split_visitor (); + glagen.step = glagen.step + 1; + glagen.ref->Hide_visitor (); + } + else + { + split_all (glagen.ref); + glagen.step++; + split_all (glagen.ref->Child_center ()); + glagen.step++; + split_all (glagen.ref->Child_center ()->Child_center ()); + glagen.step++; + split_all (glagen.ref->Child_center ()->Child_center ()-> + Child_center ()); + glagen.step++; + split_all (glagen.ref->Child_center ()->Child_center ()-> + Child_center ()->Child_center ()); + glagen.step++; + glagen.current = glagen.ref-> + Child_center ()-> + Child_center ()-> + Child_center ()-> + Child_center ()-> + Child_center (); + } + library_caller (glagen.ref); + glagen.step++; + display (&narg, &args); + return 0; +} diff --git a/branches/hugues/glagen/3d/matrix3d.cc b/branches/hugues/glagen/3d/matrix3d.cc new file mode 100644 index 0000000..c02ac39 --- /dev/null +++ b/branches/hugues/glagen/3d/matrix3d.cc @@ -0,0 +1,216 @@ +//============================================================================= +// +// 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 +// +// matrix.cc for Glagen : made by Zavie (Julien Guertault) +// +// www.glagen.org +// +//============================================================================= + +#include +#include "data_glagen.hh" +#include "matrix3d.hh" +#include "vector.hh" + +// =============================================== Constructors and destructors + +Matrix33 :: Matrix33 () +{ + for (int y = 0; y < 3; y++) + for (int x = 0; x < 3; x++) + mat[x][y] = (x == y ? 1 : 0); +} + +Matrix33 :: Matrix33 (const class Matrix33 &source) +{ + for (int y = 0; y < 3; y++) + for (int x = 0; x < 3; x++) + mat[x][y] = source.A(x, y); +} + +Matrix33 :: Matrix33 (const float m[3][3]) +{ + for (int y = 0; y < 3; y++) + { + for (int x = 0; x < 3; x++) + mat[x][y] = m[x][y]; + mat[3][y] = 0; + } + mat[0][3] = 0; + mat[1][3] = 0; + mat[2][3] = 0; + mat[3][3] = 1; +} + +Matrix33 :: Matrix33 (const float angle, const Vector &v) +{ + float c = cosf (angle); + float s = sinf (angle); + float t = 1 - c; + float val[] = {t * v.X () * v.X () + c, + t * v.X () * v.Y () - s * v.Z (), + t * v.X () * v.Z () + s * v.Y (), + + t * v.X () * v.Y () + s * v.Z (), + t * v.Y () * v.Y () + c, + t * v.Y () * v.Z () - s * v.X (), + + t * v.X () * v.Z () - s * v.Y (), + t * v.Y () * v.Z () + s * v.X (), + t * v.Z () * v.Z () + c}; + for (int j = 0; j < 3; j++) + for (int i = 0; i < 3; i++) + mat[i][j] = val[3 * j + i]; +} + +Matrix33 :: ~Matrix33 () {} + +Matrix44 :: Matrix44 () +{ + for (int y = 0; y < 4; y++) + for (int x = 0; x < 4; x++) + mat[x][y] = (x == y ? 1 : 0); +} + +Matrix44 :: Matrix44 (const class Matrix44 &source) +{ + for (int y = 0; y < 4; y++) + for (int x = 0; x < 4; x++) + mat[x][y] = source.A(x, y); +} + +Matrix44 :: Matrix44 (const class Matrix33 &source) +{ + for (int y = 0; y < 3; y++) + for (int x = 0; x < 3; x++) + mat[x][y] = source.A(x, y); + mat[3][3] = 1; +} + +Matrix44 :: Matrix44 (const float m[4][4]) +{ + for (int y = 0; y < 4; y++) + for (int x = 0; x < 4; x++) + mat[x][y] = m[x][y]; +} + +Matrix44 :: Matrix44 (const float m[3][3]) +{ + for (int y = 0; y < 3; y++) + { + for (int x = 0; x < 3; x++) + mat[x][y] = m[x][y]; + mat[3][y] = 0; + } + mat[0][3] = 0; + mat[1][3] = 0; + mat[2][3] = 0; + mat[3][3] = 1; +} + +// Create a translation matrix from a vector +Matrix44 :: Matrix44(const float colon[3]) +{ + for (int y = 0; y < 4; y++) + for (int x = 0; x < 4; x++) + if (x == y) + mat[x][y] = 1; + else + mat[x][y] = 0; + mat[3][0] = colon[0]; + mat[3][1] = colon[1]; + mat[3][2] = colon[2]; +} + +Matrix44 :: ~Matrix44() {} + + +// ====================================================== The matrix's elements + +float Matrix33 :: A(const int x, const int y) const +{ + if (x >= 0 && x < 3 && + y >= 0 && y < 3) + return mat[x][y]; + else + return 0; +} + +float Matrix44 :: A(const int x, const int y) const +{ + if (x >= 0 && x < 4 && + y >= 0 && y < 4) + return mat[x][y]; + else + return 0; +} + +// Orthonormalize +void Matrix33 :: OrthonormalizeOrientation () +{ + Vector X (mat[0][0], mat[1][0], mat[2][0]); + Vector Y (mat[0][1], mat[1][1], mat[2][1]); + Vector Z; + + X.Normalize(); + Z = (X ^ Y); + Z.Normalize(); + Y = (Z ^ X); + Y.Normalize(); + + mat[0][0] = X.X (); mat[0][1] = Y.X (); mat[0][2] = Z.X (); + mat[1][0] = X.Y (); mat[1][1] = Y.Y (); mat[1][2] = Z.Y (); + mat[2][0] = X.Z (); mat[2][1] = Y.Z (); mat[2][2] = Z.Z (); +} + + +// ================================================================== Operators + +Vector Matrix33 :: operator * (const Vector &v) const +{ + float out[3]; + + out[0] = (A (0, 0) * v.X () + + A (1, 0) * v.Y () + + A (2, 0) * v.Z ()); + out[1] = (A (0, 1) * v.X () + + A (1, 1) * v.Y () + + A (2, 1) * v.Z ()); + out[2] = (A (0, 2) * v.X () + + A (1, 2) * v.Y () + + A (2, 2) * v.Z ()); + return Vector (out[0], out[1], out[2]); +} + +Matrix44 Matrix44 :: operator * (const Matrix44 &source) const +{ + float out[4][4]; + + for (int y = 0; y < 4; y++) + for (int x = 0; x < 4; x++) + out[x][y] = (A(0, y) * source.A(x, 0) + + A(1, y) * source.A(x, 1) + + A(2, y) * source.A(x, 2) + + A(3, y) * source.A(x, 3)); + return Matrix44(out); +} diff --git a/branches/hugues/glagen/3d/matrix3d.hh b/branches/hugues/glagen/3d/matrix3d.hh new file mode 100644 index 0000000..859f480 --- /dev/null +++ b/branches/hugues/glagen/3d/matrix3d.hh @@ -0,0 +1,80 @@ +//============================================================================= +// +// 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 +// +// matrix.hh for Glagen : made by Zavie (Julien Guertault) +// +// www.glagen.org +// +//============================================================================= + +#ifndef MATRIX3D_HH_ +# define MATRIX3D_HH_ + +class Matrix33 +{ +public : + + //Constructors and destructor + Matrix33 (); + Matrix33 (const class Matrix33 &); + Matrix33 (const float m[3][3]); + Matrix33 (const float, const class Vector &); + ~Matrix33 (); + + // Matrix itself + float A (const int, const int) const; + + // Orthonormalize + void OrthonormalizeOrientation (); + + // Operator + class Vector operator * (const class Vector &) const; + +protected : + float mat[3][3]; +}; + +class Matrix44 +{ +public : + + //Constructors and destructor + Matrix44 (); + Matrix44 (const class Matrix44 &); + Matrix44 (const class Matrix33 &); + Matrix44 (const float m[3][3]); + Matrix44 (const float m[4][4]); + Matrix44 (const float colon[3]); + ~Matrix44 (); + + //Matrix itself + float A (const int, const int) const; + + //Operator + Matrix44 operator * (const Matrix44 &) const; + +protected : + float mat[4][4]; +}; + +#endif // MATRIX3D diff --git a/branches/hugues/glagen/3d/misc.cc b/branches/hugues/glagen/3d/misc.cc new file mode 100644 index 0000000..caf7264 --- /dev/null +++ b/branches/hugues/glagen/3d/misc.cc @@ -0,0 +1,43 @@ +//============================================================================= +// +// 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 +// +// misc.cc for Glagen : made by Zavie (Julien Guertault) +// +// www.glagen.org +// +//============================================================================= + +#include +#include "data_glagen.hh" + +// +// This function is supposed to compute very fast a good approximation +// of the distance. +// The quality of this function is very important for the frame-rate +// +float Approx_dist (float x, float y, float z) +{ + // Well, I still have to fond an approximation ^_^ + // I suppose I will use Taylor Lagrange, or something like that. + return (sqrt (x * x + y * y + z * z)); +} diff --git a/branches/hugues/glagen/3d/misc.hh b/branches/hugues/glagen/3d/misc.hh new file mode 100644 index 0000000..696d5a4 --- /dev/null +++ b/branches/hugues/glagen/3d/misc.hh @@ -0,0 +1,38 @@ +//============================================================================= +// +// 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 +// +// misc.hh for Glagen : made by Zavie (Julien Guertault) +// +// www.glagen.org +// +//============================================================================= + + +#ifndef MISC_HH_ +# define MISC_HH_ + +#include "data_glagen.hh" + +float Approx_dist (float, float, float); + +#endif // MISC_HH_ diff --git a/branches/hugues/glagen/3d/perlin.cc b/branches/hugues/glagen/3d/perlin.cc new file mode 100644 index 0000000..5cb4aee --- /dev/null +++ b/branches/hugues/glagen/3d/perlin.cc @@ -0,0 +1,347 @@ +//============================================================================= +// +// 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 +// +// perlin.cc for Glagen : made by Zavie (Julien Guertault) +// +// www.glagen.org +// +//============================================================================= + +// Original implementation fo Perlin noice. +// It can be found on : +// http://mrl.nyu.edu/~perlin/doc/oscar.html#noise +// +// The 4th dimension noise has been added for our needs + +// coherent noise function over 1, 2 or 3 dimensions +// (copyright Ken Perlin) + +#include +#include +#include "data_glagen.hh" + +#define B 0x100 +#define BM 0xff + +#define N 0x1000 +#define NP 12 /* 2^N */ +#define NM 0xfff + +static int p[B + B + 2]; +static float g4[B + B + 2][4]; +static float g3[B + B + 2][3]; +static float g2[B + B + 2][2]; +static float g1[B + B + 2]; + +#define s_curve(t) ( t * t * (3. - 2. * t) ) + +#define lerp(t, a, b) ( a + t * (b - a) ) + +#define setup(i,b0,b1,r0,r1)\ + t = vec[i] + N;\ + b0 = ((int)t) & BM;\ + b1 = (b0+1) & BM;\ + r0 = t - (int)t;\ + r1 = r0 - 1.; + +float GLG_Perlin_noise_1D (float arg) +{ + int bx0, bx1; + float rx0, rx1; + float sx; + float t, u, v; + float vec[1]; + + vec[0] = arg; + + setup(0, bx0,bx1, rx0,rx1); + + sx = s_curve(rx0); + + u = rx0 * g1[ p[ bx0 ] ]; + v = rx1 * g1[ p[ bx1 ] ]; + + return lerp(sx, u, v); +} + +float GLG_Perlin_noise_2D (float vec[2]) +{ + int bx0, bx1; + int by0, by1; + int b00, b10, b01, b11; + float rx0, rx1; + float ry0, ry1; + float *q, sx, sy; + float a, b; + float t, u, v; + register int i, j; + + setup(0, bx0,bx1, rx0,rx1); + setup(1, by0,by1, ry0,ry1); + + i = p[ bx0 ]; + j = p[ bx1 ]; + + b00 = p[ i + by0 ]; + b10 = p[ j + by0 ]; + b01 = p[ i + by1 ]; + b11 = p[ j + by1 ]; + + sx = s_curve(rx0); + sy = s_curve(ry0); + +#define at2(rx,ry) ( rx * q[0] + ry * q[1] ) + + q = g2[ b00 ] ; u = at2(rx0,ry0); + q = g2[ b10 ] ; v = at2(rx1,ry0); + a = lerp(sx, u, v); + + q = g2[ b01 ] ; u = at2(rx0,ry1); + q = g2[ b11 ] ; v = at2(rx1,ry1); + b = lerp(sx, u, v); + + return lerp(sy, a, b); +} + +float GLG_Perlin_noise_3D (float vec[3]) +{ + int bx0, bx1; + int by0, by1; + int bz0, bz1; + int b00, b10, b01, b11; + float rx0, rx1; + float ry0, ry1; + float rz0, rz1; + float *q, sy, sz; + float a, b, c, d; + float t, u, v; + register int i, j; + + setup(0, bx0,bx1, rx0,rx1); + setup(1, by0,by1, ry0,ry1); + setup(2, bz0,bz1, rz0,rz1); + + i = p[ bx0 ]; + j = p[ bx1 ]; + + b00 = p[ i + by0 ]; + b10 = p[ j + by0 ]; + b01 = p[ i + by1 ]; + b11 = p[ j + by1 ]; + + t = s_curve(rx0); + sy = s_curve(ry0); + sz = s_curve(rz0); + +#define at3(rx,ry,rz) ( rx * q[0] + ry * q[1] + rz * q[2] ) + + q = g3[ b00 + bz0 ] ; u = at3(rx0,ry0,rz0); + q = g3[ b10 + bz0 ] ; v = at3(rx1,ry0,rz0); + a = lerp(t, u, v); + + q = g3[ b01 + bz0 ] ; u = at3(rx0,ry1,rz0); + q = g3[ b11 + bz0 ] ; v = at3(rx1,ry1,rz0); + b = lerp(t, u, v); + + c = lerp(sy, a, b); + + q = g3[ b00 + bz1 ] ; u = at3(rx0,ry0,rz1); + q = g3[ b10 + bz1 ] ; v = at3(rx1,ry0,rz1); + a = lerp(t, u, v); + + q = g3[ b01 + bz1 ] ; u = at3(rx0,ry1,rz1); + q = g3[ b11 + bz1 ] ; v = at3(rx1,ry1,rz1); + b = lerp(t, u, v); + + d = lerp(sy, a, b); + + return lerp(sz, c, d); +} + +float GLG_Perlin_noise_4D (float vec[4]) +{ + int bx0, bx1; + int by0, by1; + int bz0, bz1; + int bt0, bt1; + register int a0, a1; + int b00, b10, b01, b11; + int c000, c001, c010, c011, c100, c101, c110, c111; + float rx0, rx1; + float ry0, ry1; + float rz0, rz1; + float rt0, rt1; + float *q, sx, sy, sz, st; + float a, b, c, d, e, f; + float t, u, v; + + setup(0, bx0,bx1, rx0,rx1); + setup(1, by0,by1, ry0,ry1); + setup(2, bz0,bz1, rz0,rz1); + setup(3, bt0,bt1, rt0,rt1); + + a0 = p[ bx0 ]; + a1 = p[ bx1 ]; + + b00 = p[ a0 + by0 ]; + b10 = p[ a1 + by0 ]; + b01 = p[ a0 + by1 ]; + b11 = p[ a1 + by1 ]; + + c000 = p[ b00 + bz0 ]; + c100 = p[ b10 + bz0 ]; + c010 = p[ b01 + bz0 ]; + c110 = p[ b11 + bz0 ]; + c001 = p[ b00 + bz1 ]; + c101 = p[ b10 + bz1 ]; + c011 = p[ b01 + bz1 ]; + c111 = p[ b11 + bz1 ]; + + sx = s_curve(rx0); + sy = s_curve(ry0); + sz = s_curve(rz0); + st = s_curve(rt0); + +#define at4(rx, ry, rz, rt) ( rx * q[0] + ry * q[1] + rz * q[2] + rt * q[3]) + + q = g4[c000 + bt0]; u = at4(rx0, ry0, rz0, rt0); + q = g4[c100 + bt0]; v = at4(rx1, ry0, rz0, rt0); + a = lerp(sx, u, v); + + q = g4[c010 + bt0]; u = at4(rx0, ry1, rz0, rt0); + q = g4[c110 + bt0]; v = at4(rx1, ry1, rz0, rt0); + b = lerp(sx, u, v); + + c = lerp (sy, a, b); + + q = g4[c001 + bt0]; u = at4(rx0, ry0, rz1, rt0); + q = g4[c101 + bt0]; v = at4(rx1, ry0, rz1, rt0); + a = lerp(sx, u, v); + + q = g4[c011 + bt0]; u = at4(rx0, ry1, rz1, rt0); + q = g4[c111 + bt0]; v = at4(rx1, ry1, rz1, rt0); + b = lerp(sx, u, v); + + d = lerp (sy, a, b); + + + e = lerp (sz, c, d); + + + q = g4[c000 + bt1]; u = at4(rx0, ry0, rz0, rt1); + q = g4[c100 + bt1]; v = at4(rx1, ry0, rz0, rt1); + a = lerp(sx, u, v); + + q = g4[c010 + bt1]; u = at4(rx0, ry1, rz0, rt1); + q = g4[c110 + bt1]; v = at4(rx1, ry1, rz0, rt1); + b = lerp(sx, u, v); + + c = lerp (sy, a, b); + + q = g4[c001 + bt1]; u = at4(rx0, ry0, rz1, rt1); + q = g4[c101 + bt1]; v = at4(rx1, ry0, rz1, rt1); + a = lerp(sx, u, v); + + q = g4[c011 + bt1]; u = at4(rx0, ry1, rz1, rt1); + q = g4[c111 + bt1]; v = at4(rx1, ry1, rz1, rt1); + b = lerp(sx, u, v); + + d = lerp (sy, a, b); + + + f = lerp (sz, c, d); + + + return lerp (st, e, f); +} + +static void normalize2 (float v[2]) +{ + float s; + + s = sqrtf(v[0] * v[0] + v[1] * v[1]); + v[0] = v[0] / s; + v[1] = v[1] / s; +} + +static void normalize3 (float v[3]) +{ + float s; + + s = sqrtf(v[0] * v[0] + v[1] * v[1] + v[2] * v[2]); + v[0] = v[0] / s; + v[1] = v[1] / s; + v[2] = v[2] / s; +} + +static void normalize4 (float v[4]) +{ + float s; + + s = sqrtf(v[0] * v[0] + v[1] * v[1] + v[2] * v[2] + v[3] * v[3]); + v[0] = v[0] / s; + v[1] = v[1] / s; + v[2] = v[2] / s; + v[3] = v[3] / s; +} + +void Perlin_init () +{ + int i, j, k; + + for (i = 0 ; i < B ; i++) + { + p[i] = i; + + g1[i] = (float)((rand() % (B + B)) - B) / B; + + for (j = 0 ; j < 2 ; j++) + g2[i][j] = (float)((rand() % (B + B)) - B) / B; + normalize2(g2[i]); + + for (j = 0 ; j < 3 ; j++) + g3[i][j] = (float)((rand() % (B + B)) - B) / B; + normalize3(g3[i]); + + for (j = 0 ; j < 4 ; j++) + g4[i][j] = (float)((rand() % (B + B)) - B) / B; + normalize4(g4[i]); + } + + while (--i) + { + k = p[i]; + p[i] = p[j = rand() % B]; + p[j] = k; + } + + for (i = 0 ; i < B + 2 ; i++) + { + p[B + i] = p[i]; + g1[B + i] = g1[i]; + for (j = 0 ; j < 2 ; j++) + g2[B + i][j] = g2[i][j]; + for (j = 0 ; j < 3 ; j++) + g3[B + i][j] = g3[i][j]; + } +} diff --git a/branches/hugues/glagen/3d/perlin.hh b/branches/hugues/glagen/3d/perlin.hh new file mode 100644 index 0000000..3deb1c9 --- /dev/null +++ b/branches/hugues/glagen/3d/perlin.hh @@ -0,0 +1,39 @@ +//============================================================================= +// +// 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 +// +// perlin.hh for Glagen : made by Zavie (Julien Guertault) +// +// www.glagen.org +// +//============================================================================= + +#ifndef PERLIN_HH_ +# define PERLIN_HH_ + +float GLG_Perlin_noise_1D (float); +float GLG_Perlin_noise_2D (float vec[2]); +float GLG_Perlin_noise_3D (float vec[3]); +float GLG_Perlin_noise_4D (float vec[4]); +void Perlin_init (); + +#endif // PERLIN_HH_ diff --git a/branches/hugues/glagen/3d/simul.cc b/branches/hugues/glagen/3d/simul.cc new file mode 100644 index 0000000..d68daa5 --- /dev/null +++ b/branches/hugues/glagen/3d/simul.cc @@ -0,0 +1,409 @@ +//============================================================================= +// +// 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 +// +// simul.cc for Glagen : made by Zavie (Julien Guertault) +// +// www.glagen.org +// +//============================================================================= + +#include +#include "dot.hh" +#include "data_glagen.hh" +#include "perlin.hh" + +// +// A garder : une librairie de simulation du Soleil +// +void surface_solaire (Dot *m, unsigned int) +{ + property_t *property; + surface_t *data; + float param[4]; + float sum; + + if (m->Property (0) == NULL) + { + property = new property_t; // delete : dot.cc l59 + property->kind = surface; + property->size = sizeof (surface_t); + data = new surface_t; // delete : dot.cc l58 + property->data = data; + m->Set_property (0, property); + } + else + { + property = m->Property (0); + data = static_cast (property->data); + } + + param[0] = 10 * m->x () * 2; + param[1] = 10 * m->y () * 2; + param[2] = 10 * m->z () * 2; + param[3] = glagen.float_time; + sum = GLG_Perlin_noise_4D (param) / 40.0; + param[0] = 20 * m->x () * 2; + param[1] = 20 * m->y () * 2; + param[2] = 20 * m->z () * 2; + param[3] = glagen.float_time; + sum = sum + GLG_Perlin_noise_4D (param) / 80.0; + param[0] = 40 * m->x () * 2; + param[1] = 40 * m->y () * 2; + param[2] = 40 * m->z () * 2; + param[3] = glagen.float_time; + sum = sum + GLG_Perlin_noise_4D (param) / 160.0; + data->height = 1.5 * sum; + + data->red = 1; + data->green = (1 + 40 * data->height) / 2; + data->blue = (data->height * data->height * 1600); + data->alpha = (1 + 40 * data->height) / 2; +} + +void atmosphere_solaire (Dot *m, unsigned int) +{ + property_t *property; + surface_t *data; + float param[4]; + float sum; + + for (int layer = 0; layer < 100; layer++) + { + if (m->Property (layer + 1) == NULL) + { + property = new property_t; // delete : dot.cc l59 + property->kind = surface; + property->size = sizeof (surface_t); + data = new surface_t; // delete : dot.cc l58 + property->data = data; + m->Set_property (layer + 1, property); + } + else + { + property = static_cast (m->Property (layer + 1)); + data = static_cast (property->data); + } + param[0] = 3 * m->x () * 2; + param[1] = 3 * m->y () * 2; + param[2] = 3 * m->z () * 2; + param[3] = (-(layer)/3.0 + glagen.float_time + 20) / 20.0; + sum = GLG_Perlin_noise_4D (param); + sum = sum * sum; + sum = sum * sum; + data->height = 0.01 + 0.006 * layer; + data->red = 1; + data->green = 0.8 - 7 * sum; + data->blue = 0; + data->alpha = 0.005 + (120 * sum) / (sqrtf((layer + 1.0) / 71) * 71); + } +} + +// +// Un essai de simulation de sol +// +void essai_terrain (Dot *m, unsigned int level) +{ + property_t *property; + surface_t *data; + unsigned int alpha; + float param[3]; + float sum; + + if (m->Property (0) == NULL) + { + property = new property_t; // delete : dot.cc l59 + property->kind = surface; + property->size = sizeof (surface_t); + data = new surface_t; // delete : dot.cc l58 + property->data = data; + m->Set_property (0, property); + } + else + { + property = static_cast (m->Property (0)); + data = static_cast (property->data); + } + + sum = 0; + alpha = 1; + param[0] = alpha * m->x () * 3; + param[1] = alpha * m->y () * 3; + param[2] = alpha * m->z () * 3; + sum = sum + GLG_Perlin_noise_3D (param) / (10.0 * alpha); + for (unsigned int current = 0; current < 2 * level; current++) + { + alpha = 2 * alpha; + param[0] = alpha * m->x () * 3; + param[1] = alpha * m->y () * 3; + param[2] = alpha * m->z () * 3; + sum = sum + GLG_Perlin_noise_3D (param) / (10.0 * alpha); + } + + if (sum < 0) + data->height = 0; + else + data->height = sum; // 10; + + if (data->height <= 0) + { + data->red = 0.0; + data->green = 0.015 * (1 - sum); + data->blue = 0.40 * (1 - sum); + } + else + { + if (data->height < 0.005) + { + data->red = 0.52; + data->green = 0.46; + data->blue = 0.28; + } + else + if (data->height > 0.04) + { + if (data->height > 0.0055) + { + data->red = 0.9 + 4 * data->height; + data->green = 0.9 + 4 * data->height; + data->blue = 0.9 + 4 * data->height; + } + else + { + data->red = 0.55; + data->green = 0.41; + data->blue = 0.28; + } + } + else + { + data->red = 0.35; + data->green = 0.5; + data->blue = 0.21; + } + } + data->alpha = 1; +} + +// +// Un autre essai de simulation de sol +// +void essai_terrain_mono (Dot *m, unsigned int level) +{ + property_t *property; + surface_t *data; + unsigned int alpha; + float param[3]; + float sum; + + if (m->Property (0) == NULL) + { + property = new property_t; // delete : dot.cc l59 + property->kind = surface; + property->size = sizeof (surface_t); + data = new surface_t; // delete : dot.cc l58 + property->data = data; + m->Set_property (0, property); + } + else + { + property = static_cast (m->Property (0)); + data = static_cast (property->data); + } + + sum = 0; + alpha = 1; + param[0] = alpha * m->x () * 3; + param[1] = alpha * m->y () * 3; + param[2] = alpha * m->z () * 3; + sum = sum + GLG_Perlin_noise_3D (param) / (10.0 * alpha); + for (unsigned int current = 0; current < 2 * level; current++) + { + alpha = 2 * alpha; + param[0] = alpha * m->x () * 3; + param[1] = alpha * m->y () * 3; + param[2] = alpha * m->z () * 3; + sum = sum + GLG_Perlin_noise_3D (param) / (10.0 * alpha); + } + +// if (sum < 0) +// data->height = 0; +// else + data->height = sum * 2; + + data->red = 1; + data->green = 1; + data->blue = 1; + data->alpha = 1; +} + +// +// La planete rouge +// +void essai_mars (Dot *m, unsigned int level) +{ + property_t *property; + surface_t *data; + unsigned int alpha; + float param[3]; + float sum; + + if (m->Property (0) == NULL) + { + property = new property_t; // delete : dot.cc l59 + property->kind = surface; + property->size = sizeof (surface_t); + data = new surface_t; // delete : dot.cc l58 + property->data = data; + m->Set_property (0, property); + } + else + { + property = static_cast (m->Property (0)); + data = static_cast (property->data); + } + + sum = 0; + alpha = 1; + param[0] = m->x () * 3; + param[1] = m->y () * 3; + param[2] = m->z () * 3; + sum = sum + GLG_Perlin_noise_3D (param) / 10.0; + for (unsigned int current = 0; current < 2 * level; current++) + { + alpha = 2 * alpha; + param[0] = m->x () * 3 * alpha; + param[1] = m->y () * 3 * alpha; + param[2] = m->z () * 3 * alpha; + sum = sum + GLG_Perlin_noise_3D (param) / (10.0 * alpha); + } + + // + // - 0.2 < sum < 0.2 + // + + data->height = sum; + + if (data->height <= 0) + { +// data->red = 0.0; +// data->green = 1.0; +// data->blue = 1.0; + data->red = 0.07 + 0.70 / (-sum); + data->green = 0.07 + 0.20 / (-sum); + data->blue = 0.05; + } + else + { + data->red = 0.77 + (1.05 * sum); + data->green = 0.27 + (1.25 * sum); + data->blue = 0.05 + (0.17 * sum); + } + data->alpha = 1; +} + +// +// Un effet colore sympatique +// +void essai_sympa (Dot *m, unsigned int level) +{ + property_t *property; + surface_t *data; + unsigned int alpha; + float param[4]; + float sum; + int sum_int; + + if (m->Property (0) == NULL) + { + property = new property_t; // delete : dot.cc l59 + property->kind = surface; + property->size = sizeof (surface_t); + data = new surface_t; // delete : dot.cc l58 + property->data = data; + m->Set_property (0, property); + } + else + { + property = static_cast (m->Property (0)); + data = static_cast (property->data); + } + + sum = 0; + alpha = 1; + param[0] = alpha * m->x () * 3; + param[1] = alpha * m->y () * 3; + param[2] = alpha * m->z () * 3; + param[3] = glagen.float_time; + sum = sum + GLG_Perlin_noise_3D (param) / (10.0 * alpha); + for (unsigned int current = 0; current < 2 * level; current++) + { + alpha = 2 * alpha; + param[0] = alpha * m->x () * 3; + param[1] = alpha * m->y () * 3; + param[2] = alpha * m->z () * 3; + param[3] = alpha * glagen.float_time; + sum = sum + GLG_Perlin_noise_3D (param) / (10.0 * alpha); + } + data->height = 0; + sum_int = (int)(1200 * ((10 * sum) + 0.5)); +// data->red = ((sum_int % 200) * 6) / 1200.0; +// data->green = ((sum_int % 120) * 10) / 1200.0; +// data->blue = ((sum_int % 100) * 12) / 1200.0; + data->red = ((sum_int % 1200) * 1) / 1200.0; + data->green = ((sum_int % 1200) * 1) / 1200.0; + data->blue = ((sum_int % 600) * 2) / 1200.0; + data->alpha = 1; +} + +void simule_lib_load () +{ +// glagen.library[0].kind = none; + +// glagen.library[0].kind = surface; +// glagen.library[0].dynamic = false; +// glagen.library[0].run = essai_terrain; +// glagen.library[0].name = "Terrain"; + +// glagen.library[0].kind = surface; +// glagen.library[0].dynamic = false; +// glagen.library[0].run = essai_terrain_mono; +// glagen.library[0].name = "Relief"; + +// glagen.library[0].kind = surface; +// glagen.library[0].dynamic = false; +// glagen.library[0].run = essai_sympa; +// glagen.library[0].name = "Couleurs"; + + glagen.library[0].kind = surface; + glagen.library[0].dynamic = true; + glagen.library[0].run = surface_solaire; + glagen.library[0].name = "surface_solaire"; + +// glagen.library[1].kind = surface; +// glagen.library[1].dynamic = true; +// glagen.library[1].run = atmosphere_solaire; +// glagen.library[1].name = "atmosphere_solaire"; + + // Don't forget the end marker : + glagen.library[1].kind = none; +} diff --git a/branches/hugues/glagen/3d/simul.hh b/branches/hugues/glagen/3d/simul.hh new file mode 100644 index 0000000..cf2bd68 --- /dev/null +++ b/branches/hugues/glagen/3d/simul.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 +// +// simul.hh for Glagen : made by Zavie (Julien Guertault) +// +// www.glagen.org +// +//============================================================================= + +#ifndef SIMUL_HH_ +# define SIMUL_HH_ + +#include "dot.hh" + +void surface_solaire (Dot *, unsigned int); +void atmosphere_solaire (Dot *, unsigned int); +void essai_terrain (Dot *, unsigned int); +void simule_lib_load (); + + +#endif // SIMUL_HH_ diff --git a/branches/hugues/glagen/3d/time.hh b/branches/hugues/glagen/3d/time.hh new file mode 100644 index 0000000..8afe7ed --- /dev/null +++ b/branches/hugues/glagen/3d/time.hh @@ -0,0 +1,36 @@ +//============================================================================= +// +// 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 +// +// time.hh for Glagen : made by Zavie (Julien Guertault) +// +// www.glagen.org +// +//============================================================================= + +#ifndef TIME_HH_ +# define TIME_HH_ + +void init_time (); +void update_time (); + +#endif // TIME_HH_ diff --git a/branches/hugues/glagen/3d/time_unix.cc b/branches/hugues/glagen/3d/time_unix.cc new file mode 100644 index 0000000..013e2a6 --- /dev/null +++ b/branches/hugues/glagen/3d/time_unix.cc @@ -0,0 +1,51 @@ +//============================================================================= +// +// 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 +// +// time_unix.cc for Glagen : made by Zavie (Julien Guertault) +// +// www.glagen.org +// +//============================================================================= + +#include +#include +#include "data_glagen.hh" + + +void init_time () +{ + if (gettimeofday (&(glagen.time), NULL) != 0) + exit (errno); + glagen.start_time = glagen.time.tv_sec; + glagen.time.tv_sec = 0; + glagen.float_time = (glagen.time.tv_usec / 1000) / 1000.0; +} + +void update_time () +{ + if (gettimeofday (&(glagen.time), NULL) != 0) + exit (errno); + glagen.time.tv_sec = glagen.time.tv_sec - glagen.start_time; + glagen.float_time = (glagen.time.tv_sec + + (glagen.time.tv_usec / 1000) / 1000.0); +} diff --git a/branches/hugues/glagen/3d/time_windows.cc b/branches/hugues/glagen/3d/time_windows.cc new file mode 100644 index 0000000..32a5d3d --- /dev/null +++ b/branches/hugues/glagen/3d/time_windows.cc @@ -0,0 +1,53 @@ +//============================================================================= +// +// 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 +// +// time_windows.cc for Glagen : made by Zavie (Julien Guertault) +// +// www.glagen.org +// +//============================================================================= + +#include +#include "data_glagen.hh" + +void init_time () +{ + int s = GetTickCount() / 1000; + int ms = GetTickCount() % 1000; + + glagen.start_time = s; + glagen.time.tv_sec = 0; + glagen.time.tv_usec = ms * 1000; + glagen.float_time = (glagen.time.tv_usec / 1000) / 1000.0; +} + +void update_time () +{ + int s = GetTickCount() / 1000; + int ms = GetTickCount() % 1000; + + glagen.time.tv_sec = s - glagen.start_time; + glagen.time.tv_usec = ms * 1000; + glagen.float_time = (glagen.time.tv_sec + + (glagen.time.tv_usec / 1000) / 1000.0); +} diff --git a/branches/hugues/glagen/3d/triangle.cc b/branches/hugues/glagen/3d/triangle.cc new file mode 100644 index 0000000..ee80216 --- /dev/null +++ b/branches/hugues/glagen/3d/triangle.cc @@ -0,0 +1,729 @@ +//============================================================================= +// +// 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 +// +// triangle.cc for Glagen : made by Zavie (Julien Guertault) +// +// www.glagen.org +// +//============================================================================= + +#include +#include +#include "data_glagen.hh" +#include "dot.hh" +#include "misc.hh" +#include "triangle.hh" +#include "vector.hh" + +// ================================================= Constructor and destructor + +Triangle :: Triangle (Dot *a, + Dot *b, + Dot *c, + Triangle *father): + _a(a), _b(b), _c(c), + _neighbor_ab(NULL), _neighbor_bc(NULL), _neighbor_ca(NULL), + _father(father), + _child_a(NULL), _child_b(NULL), _child_c(NULL), _child_center(NULL), + _visible(true) +{ + Vector v1; + Vector v2; + + glagen.triangles = glagen.triangles + 1; + if (glagen.triangles > glagen.max_triangles) + exit (1); + if (father == NULL) + _level = 0; + else + _level = father->Level () + 1; + + a->Use (father, this); + b->Use (father, this); + c->Use (father, this); + + _center = Vector ((a->x () + b->x () + c-> x()) / 3, + (a->y () + b->y () + c-> y()) / 3, + (a->z () + b->z () + c-> z()) / 3); + + v1 = Vector (a->x () - b->x (), a->y () - b->y (), a->z () - b->z ()); + v2 = Vector (a->x () - c->x (), a->y () - c->y (), a->z () - c->z ()); + _normal = Vector (v1 ^ v2); + _size = _normal.Norm (); + _normal = _normal / _size; + _normal_real = _normal; + _size = sqrtf (_size / 2); + + step = glagen.step - 1; +} + +Triangle :: ~Triangle () +{ + if (_child_center != NULL) + { + delete _child_center; + delete _child_a; + delete _child_b; + delete _child_c; + } + + // Del the old connexity + if (_neighbor_ab != NULL) + _neighbor_ab->Del_connexity (this); + if (_neighbor_bc != NULL) + _neighbor_bc->Del_connexity (this); + if (_neighbor_ca != NULL) + _neighbor_ca->Del_connexity (this); + + // Tell the vertices they aren't used by this triangle anymore + if (_a->Drop (this, _father)) + delete _a; + if (_b->Drop (this, _father)) + delete _b; + if (_c->Drop (this, _father)) + delete _c; + + if (_father != NULL) + _father->Child_dead (this); + + glagen.triangles = glagen.triangles - 1; +} + + +// ======================================================================= Read + +// The level +unsigned int Triangle :: Level () const { return _level; } + +// The vertices +Dot *Triangle :: A () const { return _a; } +Dot *Triangle :: B () const { return _b; } +Dot *Triangle :: C () const { return _c; } + +// The neighborhood +Triangle *Triangle :: Neighbor_ab () const { return _neighbor_ab; } +Triangle *Triangle :: Neighbor_bc () const { return _neighbor_bc; } +Triangle *Triangle :: Neighbor_ca () const { return _neighbor_ca; } + +// The father +Triangle *Triangle :: Father () const { return _father; } + +// The childs +Triangle *Triangle :: Child_a() const { return _child_a; } +Triangle *Triangle :: Child_b() const { return _child_b; } +Triangle *Triangle :: Child_c() const { return _child_c; } +Triangle *Triangle :: Child_center() const { return _child_center; } +Triangle *Triangle :: Child (Dot *match) const +{ + if (match == _a) + return _child_a; + if (match == _b) + return _child_b; + if (match == _c) + return _child_c; + return NULL; +} + +Vector &Triangle :: Normal () { return _normal; } +Vector &Triangle :: Normal_real () { return _normal_real; } + +float Triangle :: Size () const { return _size; } + +// Is this triangle split ? +bool Triangle :: Is_split () const +{ + return (_child_center != NULL); +} + +// In the current turn, has this triangle been checked ? +bool Triangle :: Is_checked () const +{ + return (step == glagen.step); +} + +// According to the position of the observer, does this triangle +// need to be split ? +float Triangle :: To_split () const +{ + float x = _center.X () - glagen.observer.frame.Origin_X (); + float y = _center.Y () - glagen.observer.frame.Origin_Y (); + float z = _center.Z () - glagen.observer.frame.Origin_Z (); +// float dist = x * x + y * y + z * z; + float dist = Approx_dist(x, y, z); +// float alpha = dist / (_size * _size); + float alpha = (dist * dist) / (_size * _size); + + // Special case : + // if over the horizon, the result is increased +// if (dist > 100 * glagen.observer.altitude * glagen.observer.altitude) + if (dist > 10 * glagen.observer.altitude) + alpha = alpha * alpha / 2; +// if (dist > 1000 * glagen.observer.altitude * glagen.observer.altitude) + if (dist > 32 * glagen.observer.altitude) + alpha = alpha * alpha / 2; + if (!_visible) + alpha = (alpha * alpha) / 2; + return (alpha); +} + +// According to the position of the observer, does this triangle +// need to be merged ? +bool Triangle :: Is_visible () const { return _visible; } + +// ====================================================================== Write + +// This triangle must set a reference to the given other one +void Triangle :: Make_connexity (Triangle *neighborhood) +{ + // Find on which side is the other triangle and then set the connexity + if ((neighborhood->A () == _a) + || (neighborhood->B () == _a) + || (neighborhood->C () == _a)) + { + if ((neighborhood->A () == _b) + || (neighborhood->B () == _b) + || (neighborhood->C () == _b)) + _neighbor_ab = neighborhood; + else + _neighbor_ca = neighborhood; + } + else + _neighbor_bc = neighborhood; +} + +// This triangle must forget its reference to the given other one +void Triangle :: Del_connexity (Triangle *related) +{ + // Find the connexity and delete it + if (_neighbor_ab == related) + _neighbor_ab = NULL; + if (_neighbor_bc == related) + _neighbor_bc = NULL; + if (_neighbor_ca == related) + _neighbor_ca = NULL; +} + +// The split function +void Triangle :: Split () +{ + Dot *d; + Dot *e; + Dot *f; + Triangle *neighbor_af; + Triangle *neighbor_ae; + Triangle *neighbor_bd; + Triangle *neighbor_bf; + Triangle *neighbor_ce; + Triangle *neighbor_cd; + + // Test if the triangle is already split + if (Is_split ()) + return; + + // Check the differences of iterations + if (_neighbor_ab == NULL || _neighbor_bc == NULL || _neighbor_ca == NULL) + _father->Split_neighbor(); + + // Find / create vertex + if (_neighbor_bc->Is_split ()) + { + // Identify and save the future connexity + neighbor_bd = _neighbor_bc->Child (_b); + neighbor_cd = _neighbor_bc->Child (_c); + + // Pop the vertex to use + if (neighbor_bd->B () == neighbor_cd->C ()) + d = neighbor_bd->B (); + else + d = neighbor_bd->C (); + } + else + { + // Create the vertex and set the connexity to NULL + d = _b->Middle (_c); // new ; delete : triangle.cc l99, 101, 103 + neighbor_bd = NULL; + neighbor_cd = NULL; + } + + // The same for each side + if (_neighbor_ca->Is_split ()) + { + neighbor_ce = _neighbor_ca->Child (_c); + neighbor_ae = _neighbor_ca->Child (_a); + if (neighbor_ce->B () == neighbor_ae->C ()) + e = neighbor_ce->B (); + else + e = neighbor_ce->C (); + } + else + { + e = _c->Middle (_a); // new ; delete : triangle.cc l99, 101, 103 + neighbor_ce = NULL; + neighbor_ae = NULL; + } + + if (_neighbor_ab->Is_split ()) + { + neighbor_af = _neighbor_ab->Child (_a); + neighbor_bf = _neighbor_ab->Child (_b); + if (neighbor_af->B () == neighbor_bf->C ()) + f = neighbor_af->B (); + else + f = neighbor_af->C (); + } + else + { + f = _a->Middle (_b); // new ; delete : triangle.cc l99, 101, 103 + neighbor_af = NULL; + neighbor_bf = NULL; + } + + // Create triangles + _child_center = new Triangle (d, e, f, this); // delete : triangle.cc l90 + _child_a = new Triangle (_a, f, e, this); // delete : triangle.cc l91 + _child_b = new Triangle (_b, d, f, this); // delete : triangle.cc l92 + _child_c = new Triangle (_c, e, d, this); // delete : triangle.cc l93 + + // Set the final connexity + if (neighbor_af != NULL) + { + _child_a->Make_connexity (neighbor_af); + neighbor_af->Make_connexity (_child_a); + } + if (neighbor_ae != NULL) + { + _child_a->Make_connexity (neighbor_ae); + neighbor_ae->Make_connexity (_child_a); + } + if (neighbor_bd != NULL) + { + _child_b->Make_connexity (neighbor_bd); + neighbor_bd->Make_connexity (_child_b); + } + if (neighbor_bf != NULL) + { + _child_b->Make_connexity (neighbor_bf); + neighbor_bf->Make_connexity (_child_b); + } + if (neighbor_ce != NULL) + { + _child_c->Make_connexity (neighbor_ce); + neighbor_ce->Make_connexity (_child_c); + } + if (neighbor_cd != NULL) + { + _child_c->Make_connexity (neighbor_cd); + neighbor_cd->Make_connexity (_child_c); + } + + _child_a->Make_connexity (_child_center); + _child_b->Make_connexity (_child_center); + _child_c->Make_connexity (_child_center); + _child_center->Make_connexity (_child_a); + _child_center->Make_connexity (_child_b); + _child_center->Make_connexity (_child_c); + + // Check for chained reactions + if (_neighbor_ab != NULL) + _neighbor_ab->Check_T (); + if (_neighbor_bc != NULL) + _neighbor_bc->Check_T (); + if (_neighbor_ca != NULL) + _neighbor_ca->Check_T (); +} + +// Check if a triangle needs to be split just because too many +// triangles in the neighborhood are split. +void Triangle :: Check_T () +{ + int warning; + + // The T problem only occurs if the triangle isn't Split + if (_child_center != NULL) + return; + warning = 0; + if (_neighbor_ab != NULL) + if (_neighbor_ab->Is_split ()) + warning = warning + 1; + if (_neighbor_bc != NULL) + if (_neighbor_bc->Is_split ()) + warning = warning + 1; + if (_neighbor_ca != NULL) + if (_neighbor_ca->Is_split ()) + warning = warning + 1; + if (warning > 1) + Split (); +} + +// The big merging function : we are not sure it will really merge +// the triangle, but at least, it will merge the children. +void Triangle :: Merge () +{ + unsigned char i; + + if (Is_split()) + { + // First we merge the children + _child_center->Merge_simple (); + _child_a->Merge_simple (); + _child_b->Merge_simple (); + _child_c->Merge_simple (); + + // Then we check the neighborhood + i = 0; + if (_neighbor_ab != NULL) + if (_neighbor_ab->Is_split ()) + { + _neighbor_ab->Front_attack (_a, _b); + i = i + 1; + } + if (_neighbor_bc != NULL) + if (_neighbor_bc->Is_split ()) + { + _neighbor_bc->Front_attack (_b, _c); + i = i + 1; + } + if (_neighbor_ca != NULL) + if (_neighbor_ca->Is_split ()) + { + _neighbor_ca->Front_attack (_c, _a); + i = i + 1; + } + + // If there's only one split neighbor triangle, then we can + // also destroy the children. Else we can't because it would + // have too much unexpected effects + if (i < 2) + { + // Destroy the child + delete _child_center; + delete _child_a; + delete _child_b; + delete _child_c; + + // Don't forget to change the pointers ! + _child_center = NULL; + _child_a = NULL; + _child_b = NULL; + _child_c = NULL; + } + } +} + +// Just a merge function without T case management +void Triangle :: Merge_simple () +{ + if (_child_center != NULL) + { + // Recursive merge + _child_center->Merge_simple (); + _child_a->Merge_simple (); + _child_b->Merge_simple (); + _child_c->Merge_simple (); + + // Destroy the child + delete _child_center; + delete _child_a; + delete _child_b; + delete _child_c; + + // Don't forget to change the pointers ! + _child_center = NULL; + _child_a = NULL; + _child_b = NULL; + _child_c = NULL; + } +} + +// Check the triangle for T cases when the neigbor triangle is merged +void Triangle :: Front_attack (Dot *quad_a, Dot *quad_d) +{ + Dot *quad_b; + Dot *quad_c; + Triangle *triangle_ab; + Triangle *triangle_cd; + Triangle *last_child; + + triangle_ab = Child (quad_a); + triangle_cd = Child (quad_d); + if (quad_a == _a) + { + if (quad_d == _b) + last_child = _child_c; + else + last_child = _child_b; + } + else + if (quad_a == _b) + { + if (quad_d == _c) + last_child = _child_a; + else + last_child = _child_c; + } + else + if (quad_d == _a) + last_child = _child_b; + else + last_child = _child_a; + + triangle_ab->Merge_simple (); + _child_center->Merge_simple (); + triangle_cd->Merge_simple (); + + if (triangle_ab->B () == triangle_cd->C ()) + { + quad_b = triangle_ab->C (); + quad_c = triangle_cd->B (); + if (triangle_ab->Neighbor_ca () != NULL) + if (triangle_ab->Neighbor_ca ()->Is_split ()) + triangle_ab->Neighbor_ca ()->Front_attack (quad_a, quad_b); + if (triangle_cd->Neighbor_ab () != NULL) + if (triangle_cd->Neighbor_ab ()->Is_split ()) + triangle_cd->Neighbor_ab ()->Front_attack (quad_c, quad_d); + } + else + { + quad_b = triangle_ab->B (); + quad_c = triangle_cd->C (); + if (triangle_ab->Neighbor_ab () != NULL) + if (triangle_ab->Neighbor_ab ()->Is_split ()) + triangle_ab->Neighbor_ab ()->Front_attack (quad_a, quad_b); + if (triangle_cd->Neighbor_ca () != NULL) + if (triangle_cd->Neighbor_ca ()->Is_split ()) + triangle_cd->Neighbor_ca ()->Front_attack (quad_c, quad_d); + } + if (last_child->Is_split ()) + last_child->Front_attack (quad_b, quad_c); +} + +// Check all the triangles to apply split or merge +void Triangle :: Split_visitor () +{ + if (step == glagen.step) + return; + step = glagen.step; + + float to_split = To_split (); + + if (to_split != 0) + { + if (to_split > 350) + Merge (); + else + { + if (glagen.triangles <= glagen.max_triangles) + if (to_split < 300) + if (false == Is_split ()) + Split (); + + if (Is_split ()) + { + // We check the childs + _child_center->Split_visitor (); + _child_a->Split_visitor (); + _child_b->Split_visitor (); + _child_c->Split_visitor (); + } + } + } + + // If there's no father, it means it's one of the root + // triangles and we can go to check the neighborhood + if (NULL == _father) + { + _neighbor_ab->Split_visitor (); + _neighbor_bc->Split_visitor (); + _neighbor_ca->Split_visitor (); + } +} + +// The visitor that computes if a triangle is visible or not. +bool Triangle :: Hide_visitor () +{ + if (step != glagen.step) + { + step = glagen.step; + if (Is_split ()) + { + _visible = _child_a->Hide_visitor (); + _visible = _child_b->Hide_visitor () || _visible; + _visible = _child_c->Hide_visitor () || _visible; + _visible = _child_center->Hide_visitor () || _visible; + } + else + { + // Let compute if it is visible... + + // We construct the vector from the center of to planet to + // the observer + Vector v = Vector (glagen.observer.frame.Origin_X () - _center.X (), + glagen.observer.frame.Origin_Y () - _center.Y (), + glagen.observer.frame.Origin_Z () - + _center.Z ()); + // We compute the scalar product to know how far it is + _visible = ((_normal * v) > 0); + + // Now, let compute if it is in the vision field + if (_visible == true) + { + v.Approx_normalize (); + _visible = (v * glagen.observer.frame.Basis_Z () < -0.70); + } + } + + // If there's no father, it means it's one of the root + // triangles and we can go to check the neighborhood + if (NULL == _father) + { + _neighbor_ab->Hide_visitor (); + _neighbor_bc->Hide_visitor (); + _neighbor_ca->Hide_visitor (); + } + } + return _visible; +} + +// Called by a child when deleted +void Triangle :: Child_dead (Triangle *child) +{ + if (_child_center == child) + _child_center = NULL; + if (_child_a == child) + _child_a = NULL; + if (_child_b == child) + _child_b = NULL; + if (_child_c == child) + _child_c = NULL; +} + +// This triangle is checked +void Triangle :: Checked () { step = glagen.step; } + + +// ====================================================================== Other + +// Split the neighborhood triangles +void Triangle :: Split_neighbor () +{ + if (_neighbor_ab != NULL) + _neighbor_ab->Split (); + if (_neighbor_bc != NULL) + _neighbor_bc->Split (); + if (_neighbor_ca != NULL) + _neighbor_ca->Split (); +} + +// Update the normal vector, if the triangle is moving. +void Triangle :: Update_normal () +{ + surface_t *surface; + float adjust = 0; + + // Get the position of the dot A + if (glagen.display_planet == true) + { + if (NULL == _a->Property (0)) + adjust = 0; + else + { + surface = static_cast (_a->Property (0)->data); + if (NULL == surface) + adjust = 0; + else + adjust = surface->height; + } + } + float ax = _a->x () * (glagen.size + adjust); + float ay = _a->y () * (glagen.size + adjust); + float az = _a->z () * (glagen.size + adjust); + + // Get the position of the dot B + if (glagen.display_planet) + { + if (NULL == _b->Property (0)) + adjust = 0; + else + { + surface = static_cast (_b->Property (0)->data); + if (NULL == surface) + adjust = 0; + else + adjust = surface->height; + } + } + float bx = _b->x () * (glagen.size + adjust); + float by = _b->y () * (glagen.size + adjust); + float bz = _b->z () * (glagen.size + adjust); + + // Get the position of the dot C + if (glagen.display_planet) + { + if (NULL == _c->Property (0)) + adjust = 0; + else + { + surface = static_cast (_c->Property (0)->data); + if (NULL == surface) + adjust = 0; + else + adjust = surface->height; + } + } + float cx = _c->x () * (glagen.size + adjust); + float cy = _c->y () * (glagen.size + adjust); + float cz = _c->z () * (glagen.size + adjust); + + Vector v1 = Vector (ax - bx, ay - by, az - bz); + Vector v2 = Vector (ax - cx, ay - cy, az - cz); + _normal_real = Vector (v1 ^ v2); + _normal_real.Normalize (); +} + +void Triangle :: Update_normal_visitor () +{ + if (step == glagen.step) + return; + step = glagen.step; + + Update_normal (); + + if (_child_center != NULL) + { + _child_center->Update_normal_visitor (); + _child_a->Update_normal_visitor (); + _child_b->Update_normal_visitor (); + _child_c->Update_normal_visitor (); + } + + if (NULL == _father) + { + _neighbor_ab->Update_normal_visitor (); + _neighbor_bc->Update_normal_visitor (); + _neighbor_ca->Update_normal_visitor (); + } + + _a->Update_normal (); + _b->Update_normal (); + _c->Update_normal (); +} diff --git a/branches/hugues/glagen/3d/triangle.hh b/branches/hugues/glagen/3d/triangle.hh new file mode 100644 index 0000000..3a3903f --- /dev/null +++ b/branches/hugues/glagen/3d/triangle.hh @@ -0,0 +1,122 @@ +//============================================================================= +// +// 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 +// +// triangle.hh for Glagen : made by Zavie (Julien Guertault) +// +// www.glagen.org +// +//============================================================================= + +#ifndef TRIANGLE_HH_ +# define TRIANGLE_HH_ + +#include +#include "data_glagen.hh" +#include "dot.hh" +#include "vector.hh" + +class Triangle +{ +public: + + //Constructor and destructor + Triangle (class Dot *, class Dot *, class Dot *, Triangle *); + ~Triangle (); + + // Read + unsigned int Level () const; + + Dot *A () const; + Dot *B () const; + Dot *C () const; + + Triangle *Neighbor_ab () const; + Triangle *Neighbor_bc () const; + Triangle *Neighbor_ca () const; + + Triangle *Father () const; + + Triangle *Child_a() const; + Triangle *Child_b() const; + Triangle *Child_c() const; + Triangle *Child_center() const; + Triangle *Child (Dot *match) const; + + Vector &Normal (); + Vector &Normal_real (); + + float Size () const; + bool Is_split () const; + bool Is_checked () const; + float To_split () const; + bool Is_visible () const; + + // Write + void Make_connexity (Triangle *); + void Del_connexity (Triangle *); + void Split (); + void Check_T (); + void Merge (); + void Merge_simple (); + void Front_attack (Dot *, Dot *); + void Split_visitor (); + bool Hide_visitor (); + void Child_dead (Triangle *); + void Checked (); + + // Other + void Split_neighbor (); + void Update_normal (); + void Update_normal_visitor (); + bool T_case (const unsigned int); + void Display (const unsigned int); + +protected: + unsigned int _level; + + Dot *_a; + Dot *_b; + Dot *_c; + + Triangle *_neighbor_ab; + Triangle *_neighbor_bc; + Triangle *_neighbor_ca; + + Triangle *_father; + + Triangle *_child_a; + Triangle *_child_b; + Triangle *_child_c; + Triangle *_child_center; + + bool _visible; + + Vector _center; + Vector _normal; + Vector _normal_real; + float _size; + + char step; +}; + +#endif // TRIANGLE_HH_ diff --git a/branches/hugues/glagen/3d/triangle_gl.cc b/branches/hugues/glagen/3d/triangle_gl.cc new file mode 100644 index 0000000..173db4f --- /dev/null +++ b/branches/hugues/glagen/3d/triangle_gl.cc @@ -0,0 +1,180 @@ +//============================================================================= +// +// 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 +// +// triangle.cc for Glagen : made by Zavie (Julien Guertault) +// +// www.glagen.org +// +//============================================================================= + +#ifndef DARWIN +# include +# include +#else +# include +# include +#endif + +#include "data_glagen.hh" +#include "dot.hh" +#include "triangle.hh" + +// +// Manage the T-case (when the has a 4th point) +// +bool Triangle :: T_case (const unsigned int id) +{ + Dot *middle; + Triangle *child1; + Triangle *child2; + + // Is there a triangle on this side ? + if (_neighbor_ab != NULL) + + // Then is it split ? + if (_neighbor_ab->Is_split ()) + { + // Find the dangling vertex + child1 = _neighbor_ab->Child (_a); + child2 = _neighbor_ab->Child (_b); + if (child1->B () == child2->C ()) + middle = child1->B (); + else + middle = child1->C (); + + // Display two triangles instead of just one + glBegin (GL_TRIANGLES); + _b->Display (id); + _c->Display (id); + middle->Display (id); + _c->Display (id); + _a->Display (id); + middle->Display (id); + glEnd (); + + // The T case is fixed + return true; + } + if (_neighbor_bc != NULL) + if (_neighbor_bc->Is_split ()) + { + child1 = _neighbor_bc->Child (_b); + child2 = _neighbor_bc->Child (_c); + if (child1->B () == child2->C ()) + middle = child1->B (); + else + middle = child1->C (); + glBegin (GL_TRIANGLES); + _a->Display (id); + _b->Display (id); + middle->Display (id); + _c->Display (id); + _a->Display (id); + middle->Display (id); + glEnd (); + return true; + } + if (_neighbor_ca != NULL) + if (_neighbor_ca->Is_split ()) + { + child1 = _neighbor_ca->Child (_c); + child2 = _neighbor_ca->Child (_a); + if (child1->B () == child2->C ()) + middle = child1->B (); + else + middle = child1->C (); + glBegin (GL_TRIANGLES); + _b->Display (id); + _c->Display (id); + middle->Display (id); + _a->Display (id); + _b->Display (id); + middle->Display (id); + glEnd (); + return true; + } + // In fact there's no T-case for this triangle + return false; +} + +// +// Display the faces included in the triangle (general case) +// +void Triangle :: Display (const unsigned int id) +{ + // Test if this triangle has been visited yet + if (step == glagen.step) + return; + step = glagen.step; + + if (glagen.display_all == true || _visible == true) + { + // If the triangle has childs, we visit them instead + if (_child_center != NULL) + { + _child_a->Display (id); + _child_b->Display (id); + _child_c->Display (id); + _child_center->Display (id); + } + else + { + // T-case managment + if (false == T_case (id)) + { + if (glagen.display_normal == true) + { + float x = (_a->x () + _b->x () + _c->x ()) / 3; + float y = (_a->y () + _b->y () + _c->y ()) / 3; + float z = (_a->z () + _b->z () + _c->z ()) / 3; + + // Display the normal vector + if (glagen.light) + glDisable(GL_LIGHTING); + glBegin (GL_LINES); + glColor3f(1.0, 0.2, 0.0); + glVertex3f(x, y, z); + glVertex3f(x + _normal_real.X () / 100, + y + _normal_real.Y () / 100, + z + _normal_real.Z () / 100); + glEnd (); + if (glagen.light) + glEnable(GL_LIGHTING); + } + // Could it be more simple ? + glBegin (GL_TRIANGLES); + _a->Display (id); + _b->Display (id); + _c->Display (id); + glEnd (); + } + } + } + // Recursive call at the top of the three + if (NULL == Father ()) + { + _neighbor_ab->Display (id); + _neighbor_bc->Display (id); + _neighbor_ca->Display (id); + } +} diff --git a/branches/hugues/glagen/3d/vector.cc b/branches/hugues/glagen/3d/vector.cc new file mode 100644 index 0000000..06e3085 --- /dev/null +++ b/branches/hugues/glagen/3d/vector.cc @@ -0,0 +1,252 @@ +//============================================================================= +// +// 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 +// +// vector.cc for Glagen : made by Zavie (Julien Guertault) +// +// www.glagen.org +// +//============================================================================= + +#include +#include "data_glagen.hh" +#include "misc.hh" +#include "vector.hh" + +// ================================================ Constructors and destructor + +Vector :: Vector () +{ + vect[0] = 0; + vect[1] = 0; + vect[2] = 0; +} + +Vector :: Vector (const Vector &source) +{ + vect[0] = source.X (); + vect[1] = source.Y (); + vect[2] = source.Z (); +} + +Vector :: Vector (const float x, const float y, const float z) +{ + vect[0] = x; + vect[1] = y; + vect[2] = z; +} + +Vector :: ~Vector () {} + + +// ======================================================================= Read + +float Vector :: X () const { return vect[0]; } +float Vector :: Y () const { return vect[1]; } +float Vector :: Z () const { return vect[2]; } + +float Vector :: Norm () const +{ + return (sqrtf(vect[0] * vect[0] + + vect[1] * vect[1] + + vect[2] * vect[2])); +} + +// Fast norm approximation computing +float Vector :: Approx_norm () const +{ + return (Approx_dist(vect[0], vect[1], vect[2])); +} + + +// ====================================================================== Write + +void Vector :: Set (const float x, const float y, const float z) +{ + vect[0] = x; + vect[1] = y; + vect[2] = z; +} + +void Vector :: Set_X (const float x){ vect[0] = x;} +void Vector :: Set_Y (const float y){ vect[1] = y;} +void Vector :: Set_Z (const float z){ vect[2] = z;} + +void Vector :: Normalize () +{ + float norm = Norm (); + vect[0] = vect[0] / norm; + vect[1] = vect[1] / norm; + vect[2] = vect[2] / norm; +} + +void Vector :: Approx_normalize () +{ + float norm = Approx_norm (); + vect[0] = vect[0] / norm; + vect[1] = vect[1] / norm; + vect[2] = vect[2] / norm; +} + +void Vector :: Rotate (const Vector &axis, const float angle) +{ + float cosinus = cosf (angle); + float sinus = sinf (angle); + float cos_bis = (1 - cosinus) * axis.X (); + float cos_third = (1 - cosinus) * axis.Y (); + + float x = (cosinus + cos_bis * axis.X ()) * vect[0]; + x = x + (cos_bis * axis.Y () - axis.Z () * sinus) * vect[1]; + x = x + (cos_bis * axis.Z () + axis.Y () * sinus) * vect[2]; + + float y = (cos_bis * axis.Y () + axis.Z () * sinus) * vect[0]; + y = y + (cosinus + cos_third * axis.Y ()) * vect[1]; + y = y + (cos_third * axis.Z () - axis.X () * sinus) * vect[2]; + + float z = (cos_bis * axis.Z () - axis.Y () * sinus) * vect[0]; + z = z + (cos_third * axis.Z () + axis.X () * sinus) * vect[1]; + z = z + (cosinus + (1 - cosinus) * axis.Z () * axis.Z ()) * vect[2]; + + vect[0] = x; + vect[1] = y; + vect[2] = z; +} + + +// ================================================================== Operators + +// @ +// @ +// @@@@@ +// @ +// @ +Vector Vector :: operator + (const class Vector &v) const +{ + return Vector(vect[0] + v.X (), + vect[1] + v.Y (), + vect[2] + v.Z ()); +} + +// +// +// @@@@@ +// +// +Vector Vector :: operator - (const class Vector &v) const +{ + return Vector(vect[0] - v.X (), + vect[1] - v.Y (), + vect[2] - v.Z ()); +} + +// +// @ +// @@@ +// @ +// +float Vector :: operator * (const class Vector &v) const +{ + return (vect[0] * v.X () + + vect[1] * v.Y () + + vect[2] * v.Z ()); +} + +// @ +// @ @ +// @ @ +// +// +Vector Vector :: operator ^ (const class Vector &v) const +{ + return Vector((vect[1] * v.Z ()) - (vect[2] * v.Y ()), + (vect[2] * v.X ()) - (vect[0] * v.Z ()), + (vect[0] * v.Y ()) - (vect[1] * v.X ())); +} + +// @ +// @ @@@@@ +// @@@@@ +// @ @@@@@ +// @ +Vector Vector :: operator += (const class Vector &v) +{ + *this = *this + v; + return *this; +} + +// +// @@@@@ +// @@@@@ +// @@@@@ +// +Vector Vector :: operator -= (const class Vector &v) +{ + *this = *this - v; + return *this; +} + + +// @@@ +// @ @ +// @@@ @@@@ +// @ @ @ +// @@@ @ +Vector Vector :: operator * (const float &a) const +{ + return Vector(X () * a, + Y () * a, + Z () * a); +} + +// @ @@@ +// @ @ +// @ @@@@ +// @ @ @ +// @ @@@ @ +Vector Vector :: operator / (const float &a) const +{ + return Vector(X () / a, + Y () / a, + Z () / a); +} + +// @@@ +// @ @@@@@ @ +// @@@ @@@@ +// @ @@@@@ @ @ +// @@@ @ +Vector Vector :: operator *= (const float &a) +{ + *this = *this * a; + return *this; +} + +// @ @@@ +// @ @@@@@ @ +// @ @@@@ +// @ @@@@@ @ @ +// @ @@@ @ +Vector Vector :: operator /= (const float &a) +{ + *this = *this / a; + return *this; +} diff --git a/branches/hugues/glagen/3d/vector.hh b/branches/hugues/glagen/3d/vector.hh new file mode 100644 index 0000000..2a7a47f --- /dev/null +++ b/branches/hugues/glagen/3d/vector.hh @@ -0,0 +1,77 @@ +//============================================================================= +// +// 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 +// +// vector.hh for Glagen : made by Zavie (Julien Guertault) +// +// www.glagen.org +// +//============================================================================= + +#ifndef VECTOR_HH_ +# define VECTOR_HH_ + +class Vector +{ +public : + + // Constructors and destructor + Vector (); + Vector (const Vector &); + Vector (const float, const float, const float); + ~Vector (); + + // Read + float X () const; + float Y () const; + float Z () const; + + float Norm () const; + float Approx_norm () const; + + // Write + void Set (const float, const float, const float); + void Set_X (const float); + void Set_Y (const float); + void Set_Z (const float); + void Normalize (); + void Approx_normalize (); + void Rotate (const Vector &, const float); + + // Operators + Vector operator + (const class Vector &) const; + Vector operator - (const class Vector &) const; + float operator * (const class Vector &) const; + Vector operator ^ (const class Vector &) const; + Vector operator += (const class Vector &); + Vector operator -= (const class Vector &); + + Vector operator * (const float &) const; + Vector operator / (const float &) const; + Vector operator *= (const float &); + Vector operator /= (const float &); + +protected : + float vect[3]; +}; + +#endif diff --git a/branches/hugues/glagen/algo_distribue/Distribue.cc b/branches/hugues/glagen/algo_distribue/Distribue.cc new file mode 100644 index 0000000..09efc50 --- /dev/null +++ b/branches/hugues/glagen/algo_distribue/Distribue.cc @@ -0,0 +1 @@ +#include "Distribue.hh" diff --git a/branches/hugues/glagen/algo_distribue/Distribue.hh b/branches/hugues/glagen/algo_distribue/Distribue.hh new file mode 100644 index 0000000..ff3b76d --- /dev/null +++ b/branches/hugues/glagen/algo_distribue/Distribue.hh @@ -0,0 +1,97 @@ +// Classe Distribue + + + +#ifndef DISTRIBUE_HH_ +# define DISTRIBUE_HH_ + +#include "tree/tree.hh" +#include "tree/node.hh" +#include "network/data/Data.hh" +#include "network/Server.hh" +#include "tools/matrix.hh" + +template class Distribue +{ +public: + Distribue(const Tree& tree) + : _tree(tree), + _size(tree.get_node_root().get_number_node()), + _mat(new Matrix (_size, _size)) + { + unsigned int ptr1 = 0, ptr2 = 0; + std::list< Node > ptr_node = *new std::list< Node >; + ptr_node.push_back(tree.get_node_root()); + while (ptr_node.size()) + { + std::list< Node >::iterator childs = ptr_node.begin(); + std::list< Node >::iterator child = + childs->get_childs()->begin(); + for (; child != childs->get_childs()->end(); ++child) + { + ptr_node.push_back(*child); + (*_mat)(++ptr2, ptr1) = 1; + } + ptr_node.pop_front(); + ptr1++; + } + } + + void depend(std::list& data, const unsigned int& ptr) + { + data.push_back(_tree.get_node_root().get_node_course_width(ptr).get_data()); + for (unsigned int i = 0; i < _size; ++i) + if ((*_mat)(i, ptr)) + depend(data, i); + } + + void transfer(Server& server) + { + // Calcul du nombre de client necessaire + unsigned int j = 0; + std::list< list > list_data = + *new std::list< list >; + std::list data = *new std::list; + for (unsigned int i = 1; i < _size; ++i) + { + if ((*_mat)(i, 0)) // Ne prend que les noeuds fils du noeud root + { + ++j; + this->depend(data, i); + list_data.push_back(data); + data = *new std::list; + } + } + if (server.get_nb_client() < j) + { + std::cout << "Need more client" << std::endl; + exit(-1); + } + + std::list::const_iterator fd_client = + server.get_list_fd()->begin(); + data = *new std::list; + for (unsigned int i = 1; i < _size; ++i) + { + if ((*_mat)(i, 0)) // Ne prend que les noeuds fils du noeud root + { + ++j; + this->depend(data, i); + server.send_data(*fd_client++, Data(&data)); + data = *new std::list; + } + } + } + + Matrix& get_matrix() + { + return (*_mat); + } + +private: + Tree _tree; + unsigned int _size; + Matrix *_mat; +}; + +#endif // DISTRIBUTE_HH_ diff --git a/branches/hugues/glagen/algo_distribue/Makefile b/branches/hugues/glagen/algo_distribue/Makefile new file mode 100644 index 0000000..fb30eba --- /dev/null +++ b/branches/hugues/glagen/algo_distribue/Makefile @@ -0,0 +1,51 @@ +## +## Makefile for in +## +## Made by meng-tih lam +## Login +## +## Started on Thu Feb 7 19:08:57 2002 meng-tih lam + +## + +NAME = glagen_divide +SRC_TOOLS = tools/matrix.cc +SRC_DATA = network/data/Data.cc network/data/Data_exemple.cc +SRC_TREE = tree/node.cc tree/tree.cc +SRC_NETWORK = network/Server.cc network/Client.cc +SRC_MAIN = Distribue.cc main.cc +SRCS = ${SRC_TOOLS} ${SRC_TREE} ${SRC_NETWORK}\ + ${SRC_DATA} ${SRC_MAIN} + +OBJS = $(SRCS:.cc=.o) + +ARCHI_i586 = -g2 -Wall -W -Werror -O3 +ARCHI_NetBSD = -g2 -Wall -W -Werror -O3 -I/usr/X11R6/include +ARCHI_sun4 = -g2 -Wall -W -Werror -O3 +ARCHI_alpha = -g2 -Wall -W -Werror -O3 + +LIB_i586 = +LIB_NetBSD = -L/usr/pkg/lib -L/usr/X11R6/lib -lGL -lGLU -lglut +LIB_alpha = +LIB_sun4 = + +CPPFLAGS = -I. +CC = g++ +RM = rm -f + +.PHONY: all clean deps + +all: $(OBJS) + $(CC) -o $(NAME) $(CFLAGS) $(OBJS)\ + $(LIB_${HOSTTYPE}) $(ARCHI_${HOSTTYPE}) + +.cc.o: + $(CC) $(ARCHI_${HOSTTYPE}) $(CPPFLAGS) -c $< -o $(<:.cc=.o) + +clean: + $(RM) $(OBJS) $(NAME) *~ \#*\# + +deps: + makedepend $(SRC) 2>/dev/null + +re: clean all diff --git a/branches/hugues/glagen/algo_distribue/main.cc b/branches/hugues/glagen/algo_distribue/main.cc new file mode 100644 index 0000000..e78d461 --- /dev/null +++ b/branches/hugues/glagen/algo_distribue/main.cc @@ -0,0 +1,113 @@ +// Algo distribue + +// glagen_divide [n] +// n indique le nombre d'ordinateur en reseau exclut le serveur + +#include +#include +#include + +// Load Tree +#include "tree/node.hh" +#include "tree/tree.hh" + +// Load Network +#include "network/Server.hh" +#include "network/Client.hh" + +// Load Data +#include "network/data/Data_string.hh" + +// Load Tool +#include "tools/matrix.hh" + +#include "Distribue.hh" + +#include +#include + +// Prototype : test d'essais avec 2 clients +// On changera suivant les donnees passes par GTK +// Il faut que le nombre de client soit superieur ou egale +// au nombre de noeud fils par rapport au noeud principal +#define NB_CLIENT 2 + +char gl_handle; + +Tree *create_tree(); + +void help(char *prog_name) +{ + std::cout << prog_name << " [port]" << std::endl; + exit(0); +} + +void signal_alarm(int) +{ + gl_handle = gl_handle | 1; +} + +void check_args(int argc, char *argv1, char *argv2) +{ + int current; + + if (argc != 2) + { + std::cerr << "Error server : Error parameters" << std::endl; + help(argv1); + } + for (current = 0; argv2[current] != '\0'; current++) + if (argv2[current] < '0' || argv2[current] > '9') + { + std::cerr << "Error server : Error parameters" << std::endl; + help(argv1); + } +} + +int main(int argc, char *argv[]) +{ + // Exemple de creation d'un arbre (donnees string) + // On peut appele une classe abstraite dont ses fils sont + // les types de donnees des librairies (ex: Tree) + Tree* tree; + tree = create_tree(); + + // Calcul de l'algo distribue : calcul l'attribution des taches + // pour chaque client + Distribue network(*tree); + std::cout << "Matrice calcule" << std::endl + << network.get_matrix() << std::endl; + + // Execution du serveur + check_args(argc, argv[0], argv[1]); + Server server(atoi(argv[1]), NB_CLIENT); + + // Transfert des donnees + network.transfer(server); + + return (0); +} + + + +Tree *create_tree() +{ + string root = "Connection..."; + string a = "Est-ce que ca fonctionne ?"; + string b = "1212123"; + string c = "OK recu 5/5"; + Tree tree(root); + tree.add_node(a); + tree.add_node(b); + tree.add_node(c); + + Tree* main_tree = new Tree(string("Execution...")); + main_tree->add_tree(tree); + + Tree tree2(string("Une tentative de suicide")); + tree2.add_node(string("Ou ca?")); + tree2.add_node(string("A Epita")); + tree2.add_node(string("Ping pong ping")); + main_tree->add_tree(tree2); + return (main_tree); +} diff --git a/branches/hugues/glagen/algo_distribue/network/Client.cc b/branches/hugues/glagen/algo_distribue/network/Client.cc new file mode 100644 index 0000000..23ccb2c --- /dev/null +++ b/branches/hugues/glagen/algo_distribue/network/Client.cc @@ -0,0 +1 @@ +#include "Client.hh" diff --git a/branches/hugues/glagen/algo_distribue/network/Client.hh b/branches/hugues/glagen/algo_distribue/network/Client.hh new file mode 100644 index 0000000..923b83e --- /dev/null +++ b/branches/hugues/glagen/algo_distribue/network/Client.hh @@ -0,0 +1,113 @@ +// Classe Client + +#ifndef CLIENT_HH_ +# define CLIENT_HH_ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "data/Data.hh" + +class Client +{ +public: + Client(char* host, const int& port) + { + char *c; + int sock; + struct sockaddr_in sa; + long addr; + struct hostent *host_info; + + if ((host_info = gethostbyname(host)) == 0) + this->error(); + c = host_info->h_addr; + addr = c[0] << 24 | c[1] << 16 | c[2] << 8 | c[3]; + if ((sock = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP)) == -1) + this->error(); + sa.sin_family = AF_INET; + sa.sin_port = htons(port); + sa.sin_addr.s_addr = htonl(addr); + if (connect(sock, (struct sockaddr *)&sa, sizeof (sa)) == -1) + this->error(); + _fd_server = sock; + } + + void error() + { + std::cerr << "Error client : "; + perror(""); + exit(errno); + } + + template + void send_data(const Data& data) const + { + data.send(_fd_server); + } + + template + void received_data(Data& data) + { + data.receive(_fd_server); + } + + void wait_signal() + { + unsigned char sig = 0; + read(_fd_server, &sig, sizeof(unsigned char)); + if (sig != 42) + { + std::cout << "Erreur de transmission" << std::endl; + exit(1); + } + std::cout << "En communication avec le serveur..." << std::endl; + } + + void send_signal() + { + unsigned char sig = 42; + write(_fd_server, &sig, sizeof(unsigned char)); + } + + int do_select() + { + fd_set rd; + char buf[256]; + int n; + + FD_ZERO(&rd); + FD_SET(0, &rd); + FD_SET(_fd_server, &rd); + if (select(_fd_server + 1, &rd, 0, 0, 0) == -1) + this->error(); + if (FD_ISSET(_fd_server, &rd)) + { + n = read(_fd_server, buf, 150); + if (n <= 0) + return (1); + write(1, buf, n); + fflush(0); + } + if (FD_ISSET(0, &rd)) + { + n = read(0, buf, 100); + write(_fd_server, buf, n); + } + return (0); + } + + +private: + int _fd_server; +}; + +#endif // CLIENT_HH_ diff --git a/branches/hugues/glagen/algo_distribue/network/Makefile b/branches/hugues/glagen/algo_distribue/network/Makefile new file mode 100644 index 0000000..18878df --- /dev/null +++ b/branches/hugues/glagen/algo_distribue/network/Makefile @@ -0,0 +1,62 @@ +## +## Makefile for in +## +## Made by meng-tih lam +## Login +## +## Started on Thu Feb 7 19:08:57 2002 meng-tih lam + +## + +NAME_SERVER = glagen_server +NAME_CLIENT = glagen_client +SRC_DATA = data/Data.cc\ + data/Data_exemple.cc\ + data/Data_string.cc +SRC_SERVER = Server.cc main_server.cc +SRC_CLIENT = Client.cc main_client.cc + +OBJ_SERVER = $(SRC:.cc=.o) $(SRC_SERVER:.cc=.o) +OBJ_CLIENT = $(SRC:.cc=.o) $(SRC_CLIENT:.cc=.o) + +ARCHI_i586 = -g2 -Wall -W -Werror -O3 +ARCHI_NetBSD = -g2 -Wall -W -Werror -O3 -I/usr/X11R6/include +ARCHI_sun4 = -g2 -Wall -W -Werror -O3 +ARCHI_alpha = -g2 -Wall -W -Werror -O3 + +LIB_i586 = -lc +LIB_NetBSD = -L/usr/pkg/lib -L/usr/X11R6/lib -lGL -lGLU -lglut -lc +LIB_alpha = +LIB_sun4 = -lsocket -lnsl + +CPPFLAGS = -I. +CC = g++ +RM = rm -f + +.PHONY: all clean deps + +all: server client + +server: $(NAME_SERVER) + +client: $(NAME_CLIENT) + +$(NAME_SERVER): $(OBJ_SERVER) + $(CC) -o $(NAME_SERVER) $(CFLAGS) $(OBJ_SERVER)\ + $(LIB_${HOSTTYPE}) $(ARCHI_${HOSTTYPE}) + +$(NAME_CLIENT): $(OBJ_CLIENT) + $(CC) -o $(NAME_CLIENT) $(CFLAGS) $(OBJ_CLIENT)\ + $(LIB_${HOSTTYPE}) $(ARCHI_${HOSTTYPE}) + +.cc.o: + $(CC) $(ARCHI_${HOSTTYPE}) $(CPPFLAGS) -c $< + +clean: + $(RM) $(OBJ_SERVER) $(OBJ_CLIENT) $(NAME_SERVER) $(NAME_CLIENT)\ + *~ \#*\# + +deps: + makedepend $(SRC) 2>/dev/null + +re: clean all diff --git a/branches/hugues/glagen/algo_distribue/network/Server.cc b/branches/hugues/glagen/algo_distribue/network/Server.cc new file mode 100644 index 0000000..63f45ff --- /dev/null +++ b/branches/hugues/glagen/algo_distribue/network/Server.cc @@ -0,0 +1 @@ +#include "Server.hh" diff --git a/branches/hugues/glagen/algo_distribue/network/Server.hh b/branches/hugues/glagen/algo_distribue/network/Server.hh new file mode 100644 index 0000000..fdfecb4 --- /dev/null +++ b/branches/hugues/glagen/algo_distribue/network/Server.hh @@ -0,0 +1,218 @@ +// Classe Server + +#ifndef SERVER_HH_ +# define SERVER_HH_ + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include "data/Data.hh" + +extern char gl_handle; + +extern void signal_alarm(int); + +template class Data; + +class Server +{ +public: + Server(const int& port, const unsigned int& nb_client_max) + { + _port = port; + _client_max = nb_client_max; + _fd = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP); + _sock_in = new struct sockaddr_in; + _sock_in->sin_family = PF_INET; + _sock_in->sin_port = htons(port); + _sock_in->sin_addr.s_addr = INADDR_ANY; + if ((bind(_fd, (struct sockaddr *)_sock_in, sizeof (*_sock_in)) == -1) + || (listen(_fd, 5) == -1)) + this->error(); + std::cout << "Server started. Listening on port " << _port << std::endl; + _fd_client = new std::list; + this->start_signal(); + this->start(); + } + + void start() + { + int fd_client; + socklen_t len; + struct sockaddr_in sock_client; + + len = sizeof (struct sockaddr_in); + while (gl_handle != -1 && this->_fd_client->size() < _client_max) + { + fd_client = 0; + if ((fd_client = accept(this->_fd, + (struct sockaddr *)&(sock_client), &len)) > 0) + gl_handle = gl_handle | 2; + std::list list_fd; + if (2 == (gl_handle & 2)) + { + this->accept_client(fd_client); + this->send_signal(fd_client); + std::cout << "Number of connected clients :" + << this->_fd_client->size() << std::endl; + } + gl_handle = 0; + this->test_client(); + } + } + + void test_client() + { + if (_fd_client->size()) + { + std::list::const_iterator fd_client_tmp; + std::list::const_iterator fd_client = _fd_client->begin(); + int i = 0; + while (fd_client != _fd_client->end()) + { + i++; + char c = 0; + errno = 0; + fd_client_tmp = fd_client; + read(*fd_client, &c, sizeof(char)); + ++fd_client; + if (errno == 0) + this->remove_client(*fd_client_tmp); + } + } + } + + void error() + { + std::cerr << "Error server : "; + perror(""); + exit(errno); + } + + void remove_client(const int& fd) + { + _fd_client->remove(fd); + std::cout << "Client in the file descriptor : " << fd + << " are disconnected" << std::endl; + std::cout << "Number of connected clients :" + << this->_fd_client->size() << std::endl; + } + + void wait_signal(std::list& list_fd) // retourne la liste des files descriptors a lire + { + struct pollfd poll_fd[_fd_client->size()]; + std::list::const_iterator fd = _fd_client->begin(); + for (int i = 0; fd != _fd_client->end(); ++fd, ++i) + { + poll_fd[i].fd = *fd; + poll_fd[i].events = POLLIN; + } + if (poll(poll_fd, _fd_client->size(), 0) < 0) + assert(0); + for (unsigned int i = 0; i < _fd_client->size(); ++i) + if (poll_fd[i].revents != 0) + { + unsigned char sig = 0; + unsigned int length = 0; + do + { + errno = 0; + length = read(poll_fd[i].fd, &sig, sizeof(unsigned char)); + } + while (errno == 4); + if (errno) + { + perror(""); + exit(errno); + } + if (length == 0) + remove_client(poll_fd[i].fd); + else + if (sig == 42) + { + list_fd.push_back(poll_fd[i].fd); + std::cout << "Reception signal sur le file descriptor :" + << poll_fd[i].fd << std::endl; + } + else + { + std::cout << "Erreur de reception sur le file descriptor :" + << poll_fd[i].fd << std::endl; + exit(2); + } + poll_fd[i].revents = 0; + } + } + + void send_signal(const int& fd) + { + unsigned char sig = 42; + write(fd, &sig, sizeof(unsigned char)); + } + + void start_signal() + { + struct sigaction alarm; + + alarm.sa_handler = signal_alarm; + alarm.sa_flags = 0; + sigemptyset(&(alarm.sa_mask)); + sigaddset(&(alarm.sa_mask), SIGALRM); + sigaction(SIGALRM, &alarm, 0); + ualarm(1, 100000); + } + + template + void send_data(const int& fd, const Data& data) + { + data.send(fd); + } + + template + void send_data(const Data& data, + const std::list& fd_client) + { + std::list::const_iterator fd = fd_client.begin(); + for (; fd != fd_client.end(); ++fd) + data.send(*fd); + } + + template + void received_data(Data& data, const std::list& fd_client) + { + std::list::const_iterator fd = fd_client.begin(); + for (; fd != fd_client.end(); ++fd) + data.receive(*fd); + } + + void accept_client(const int& fd) + { + std::cout << "Client connected on file descriptor: " << fd << std::endl; + _fd_client->push_back(fd); + } + + int get_fd() const { return (_fd); } + + int get_port() const { return (_port); } + + std::list* get_list_fd() const { return (_fd_client); } + + unsigned int get_nb_client() const { return (_fd_client->size()); } + +private: + std::list *_fd_client; + struct sockaddr_in *_sock_in; + int _port; + unsigned int _client_max; + int _fd; +}; + +#endif // SERVER_HH_ diff --git a/branches/hugues/glagen/algo_distribue/network/data/Data.cc b/branches/hugues/glagen/algo_distribue/network/data/Data.cc new file mode 100644 index 0000000..d3bbe6a --- /dev/null +++ b/branches/hugues/glagen/algo_distribue/network/data/Data.cc @@ -0,0 +1 @@ +#include "Data.hh" diff --git a/branches/hugues/glagen/algo_distribue/network/data/Data.hh b/branches/hugues/glagen/algo_distribue/network/data/Data.hh new file mode 100644 index 0000000..3b630ff --- /dev/null +++ b/branches/hugues/glagen/algo_distribue/network/data/Data.hh @@ -0,0 +1,78 @@ +// Classe Data + +// Dans le TYPEDATA, il faut l'implementation de toString (retourne un string) +// et de type (retourne unsigned short int) + +// Type 0: char +// Type 1: unsigned char +// Type 2: int +// Type 3: unsigned int +// Type 4: short int +// Type 5: unsigned short int +// Type 6: long int +// Type 7: unsigned long int +// Type 8: float +// Type 9: double +// Type 10: long double + +#ifndef DATA_HH_ +# define DATA_HH_ + +#include +#include +#include + +#include + +template class Data +{ +public: + Data() : _data(new std::list) {}; + + Data(std::list* data) : _data(data) {}; + + void error() + { + perror(""); + exit(errno); + } + + void add_data(const TYPEDATA& data) { _data->push_back(data); }; + + void send(const int& fd) const + { + std::list::iterator data = _data->begin(); + unsigned int size = _data->size(); + std::cout << "Taille a ecrire:" << size << std::endl; + write(fd, &size, sizeof(unsigned int)); + for (; data != _data->end(); ++data) + data->write_data(fd); + } + + void receive(const int& fd) + { + unsigned int size = 0; + do + { + errno = 0; + read(fd, &size, sizeof(unsigned int)); + } + while(errno == 4); + if (errno) + this->error(); + std::cout << "Taille lu: " << size << std::endl; + TYPEDATA data; + for (unsigned int i = 0; i < size; ++i) + { + data.read_data(fd); + _data->push_back(data); + } + } + + std::list* get_data() { return (_data); } + +private: + std::list* _data; +}; + +#endif // DATA_HH_ diff --git a/branches/hugues/glagen/algo_distribue/network/data/Data_exemple.cc b/branches/hugues/glagen/algo_distribue/network/data/Data_exemple.cc new file mode 100644 index 0000000..9578493 --- /dev/null +++ b/branches/hugues/glagen/algo_distribue/network/data/Data_exemple.cc @@ -0,0 +1 @@ +#include "Data_exemple.hh" diff --git a/branches/hugues/glagen/algo_distribue/network/data/Data_exemple.hh b/branches/hugues/glagen/algo_distribue/network/data/Data_exemple.hh new file mode 100644 index 0000000..ca1291b --- /dev/null +++ b/branches/hugues/glagen/algo_distribue/network/data/Data_exemple.hh @@ -0,0 +1,66 @@ +// Classe Data_exemple + +// Un exemple sur un point de coordonnees 3D + +#ifndef DATA_EXEMPLE_HH_ +# define DATA_EXEMPLE_HH_ + +#include +#include // Pour write/read + +#include + +class Data_exemple +{ +public: + Data_exemple() : _x(0), _y(0), _z(0) {}; + Data_exemple(int x, int y, int z) : _x(x), _y(y), _z(z) {}; + + void write_data(const int& fd) const + { + std::cout << "Donnees envoyes au serveur" << std::endl; + std::cout << _x << std::endl; + std::cout << _y << std::endl; + std::cout << _z << std::endl; + write(fd, &_x, sizeof(int)); + write(fd, &_y, sizeof(int)); + write(fd, &_z, sizeof(int)); + } + + void read_data(const int& fd) + { + do + { + errno = 0; + read(fd, &_x, sizeof(int)); + } + while (errno == 4); + + do + { + errno = 0; + read(fd, &_y, sizeof(int)); + } + while (errno == 4); + + do + { + errno = 0; + read(fd, &_z, sizeof(int)); + } + while (errno == 4); + + std::cout << "Reception message sur le file descriptor :" << fd + << std::endl; + std::cout << _x << std::endl; + std::cout << _y << std::endl; + std::cout << _z << std::endl; + } + +private: + int _x; + int _y; + int _z; +}; + +#endif // DATA_EXEMPLE diff --git a/branches/hugues/glagen/algo_distribue/network/data/Data_string.cc b/branches/hugues/glagen/algo_distribue/network/data/Data_string.cc new file mode 100644 index 0000000..9578493 --- /dev/null +++ b/branches/hugues/glagen/algo_distribue/network/data/Data_string.cc @@ -0,0 +1 @@ +#include "Data_exemple.hh" diff --git a/branches/hugues/glagen/algo_distribue/network/data/Data_string.hh b/branches/hugues/glagen/algo_distribue/network/data/Data_string.hh new file mode 100644 index 0000000..a395725 --- /dev/null +++ b/branches/hugues/glagen/algo_distribue/network/data/Data_string.hh @@ -0,0 +1,60 @@ +#ifndef DATA_STRING_HH_ +# define DATA_STRING_HH_ + +#include +#include +#include // Pour write/read + +#include + +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/branches/hugues/glagen/algo_distribue/network/main_client.cc b/branches/hugues/glagen/algo_distribue/network/main_client.cc new file mode 100644 index 0000000..66cb083 --- /dev/null +++ b/branches/hugues/glagen/algo_distribue/network/main_client.cc @@ -0,0 +1,54 @@ +// Main du client + +#include +#include +#include "Client.hh" +#include "data/Data_exemple.hh" +#include "data/Data_string.hh" + +void help(char *prog_name) +{ + std::cout << prog_name << " [hostname] [port]" << std::endl; + exit(0); +} + +void check_args(int argc, char **argv) +{ + int current; + + if (argc != 3) + { + std::cerr << "Error client : Error parameters" << std::endl; + help(argv[0]); + } + for (current = 0; argv[2][current] != '\0'; current++) + if (argv[2][current] < '0' || argv[2][current] > '9') + { + std::cerr << "Error client : Error parameters" << std::endl; + help(argv[0]); + } +} + +int main(int argc, char **argv) +{ + check_args(argc, argv); + Client client(argv[1], atoi(argv[2])); +// Data data; +// data.add_data(Data_exemple(10, 11, 13)); +// data.add_data(Data_exemple(1, 4, 81)); + client.wait_signal(); +// client.send_signal(); +// client.send_data(data); + +// Data data_string; +// client.received_data(data_string); + + // On devrait implementer un numero a chaque classe associe + // Je fais ca pour l'instant comme si on connait deja le type de classe + // c'est juste pour tester + Data data_string; + client.received_data(data_string); + + while (0 == client.do_select()); + return (0); +} diff --git a/branches/hugues/glagen/algo_distribue/network/main_server.cc b/branches/hugues/glagen/algo_distribue/network/main_server.cc new file mode 100644 index 0000000..4fafd09 --- /dev/null +++ b/branches/hugues/glagen/algo_distribue/network/main_server.cc @@ -0,0 +1,73 @@ +// Main du reseau server + +#include +#include "Server.hh" +#include "data/Data_exemple.hh" +#include "data/Data_string.hh" + +char gl_handle; + +void help(char *prog_name) +{ + std::cout << prog_name << " [port]" << std::endl; + exit(0); +} + +void signal_alarm(int) +{ + gl_handle = gl_handle | 1; +} + +void check_args(int argc, char *argv1, char *argv2) +{ + int current; + + if (argc != 2) + { + std::cerr << "Error server : Error parameters" << std::endl; + help(argv1); + } + for (current = 0; argv2[current] != '\0'; current++) + if (argv2[current] < '0' || argv2[current] > '9') + { + std::cerr << "Error server : Error parameters" << std::endl; + help(argv1); + } +} + +int main(int argc, char* argv[]) +{ +// int fd_client; +// socklen_t len; +// struct sockaddr_in sock_client; + +// len = sizeof (struct sockaddr_in); + check_args(argc, argv[0], argv[1]); + Server server(atoi(argv[1]), 3); + server.get_list_fd(); +// server.start_signal(); +// while (gl_handle != -1) +// { +// fd_client = 0; +// if ((fd_client = accept(server.get_fd(), +// (struct sockaddr *)&(sock_client), &len)) > 0) +// gl_handle = gl_handle | 2; +// std::list list_fd; +// if (2 == (gl_handle & 2)) +// { +// server.accept_client(fd_client); +// server.send_signal(fd_client); +// } +// Data data; +// server.wait_signal(list_fd); +// server.received_data(data, list_fd); + +// Data data_string; +// Data_string ack("Aknowledge"); +// data_string.add_data(ack); +// server.send_data(data_string, list_fd); + +// gl_handle = 0; +// } +// return (0); +} diff --git a/branches/hugues/glagen/algo_distribue/tools/matrix.cc b/branches/hugues/glagen/algo_distribue/tools/matrix.cc new file mode 100644 index 0000000..7991769 --- /dev/null +++ b/branches/hugues/glagen/algo_distribue/tools/matrix.cc @@ -0,0 +1,3 @@ + + +#include "matrix.hh" diff --git a/branches/hugues/glagen/algo_distribue/tools/matrix.hh b/branches/hugues/glagen/algo_distribue/tools/matrix.hh new file mode 100644 index 0000000..4894360 --- /dev/null +++ b/branches/hugues/glagen/algo_distribue/tools/matrix.hh @@ -0,0 +1,324 @@ +// matrix.hh + +#include + +#ifndef MATRIX_HH_ +# define MATRIX_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/branches/hugues/glagen/algo_distribue/tree/Makefile b/branches/hugues/glagen/algo_distribue/tree/Makefile new file mode 100644 index 0000000..895117b --- /dev/null +++ b/branches/hugues/glagen/algo_distribue/tree/Makefile @@ -0,0 +1,45 @@ +## +## Makefile for in +## +## Made by meng-tih lam +## Login +## +## Started on Thu Feb 7 19:08:57 2002 meng-tih lam + +## + +NAME = glagen_tree +SRCS = node.cc tree.cc main.cc + +OBJS = $(SRCS:.cc=.o) + +ARCHI_i586 = -g2 -Wall -W -Werror -O3 +ARCHI_NetBSD = -g2 -Wall -W -Werror -O3 -I/usr/X11R6/include +ARCHI_sun4 = -g2 -Wall -W -Werror -O3 +ARCHI_alpha = -g2 -Wall -W -Werror -O3 + +LIB_i586 = +LIB_NetBSD = -L/usr/pkg/lib -L/usr/X11R6/lib -lGL -lGLU -lglut +LIB_alpha = +LIB_sun4 = + +CPPFLAGS = -I. +CC = g++ +RM = rm -f + +.PHONY: all clean deps + +all: $(OBJS) + $(CC) -o $(NAME) $(CFLAGS) $(OBJS)\ + $(LIB_${HOSTTYPE}) $(ARCHI_${HOSTTYPE}) + +.cc.o: + $(CC) $(ARCHI_${HOSTTYPE}) $(CPPFLAGS) -c $< + +clean: + $(RM) $(OBJS) $(NAME) *~ \#*\# + +deps: + makedepend $(SRC) 2>/dev/null + +re: clean all diff --git a/branches/hugues/glagen/algo_distribue/tree/main.cc b/branches/hugues/glagen/algo_distribue/tree/main.cc new file mode 100644 index 0000000..3b6f02d --- /dev/null +++ b/branches/hugues/glagen/algo_distribue/tree/main.cc @@ -0,0 +1,99 @@ +// +// main.cc for in +// +// Made by meng-tih lam +// Login +// +// Started on Fri Aug 16 02:41:45 2002 meng-tih lam +// + +#include +#include +#include + +#include "node.hh" +#include "tree.hh" + +// Pour construire un arbre, il faut d'abord faire les fils +// et les raccoller avec le pere avec la methode add_tree + +int test_tree() +{ + // ** Exemple avec la classe ** + // ** On peut mettre n'importe classe ** + + // * Support du sous-arbre * + string root = "Connection..."; + string a = "Est-ce que ca fonctionne ?"; + string b = "1212123"; + string c = "OK recu 5/5"; + Tree tree(root); + tree.add_node(a); + tree.add_node(b); + tree.add_node(c); + + // Affichage root de l'arbre + std::cout << "root: " << tree.get_node_root().get_data() << std::endl; + + // Affichage de ses fils + unsigned int nb_childs = tree.get_nb_childs(); + for (unsigned int i = 0; i < nb_childs; ++i) + std::cout << tree.get_child(i).get_data() << std::endl; + std::cout << std::endl << std::endl; + + + + // * Support Arbre principale * + Tree main_tree("Execution..."); + + // Voici la methode pour lier un arbre et un sous-arbre + main_tree.add_tree(tree); + + std::cout << "root main: " << main_tree.get_node_root().get_data() + << std::endl; + unsigned int nb_childs2 = main_tree.get_nb_childs(); + + // Ici arbre sur 2 niveaux (Bien sur qu'on peut faire en recursivite ^_^) + for (unsigned int i = 0; i < nb_childs2; ++i) + { + nb_childs = main_tree.get_child(i).get_nb_childs(); + std::cout << main_tree.get_child(i).get_data() << std::endl; + for (unsigned int j = 0; j < nb_childs; ++j) + std::cout << main_tree.get_child(i).get_child(j).get_data() + << std::endl; + } + std::cout << std::endl << std::endl; + + + + + // * Allez on rajoute pour compliquer les choses * + Tree tree2("Une tentative de suicide"); + tree2.add_node("Ou ca?"); + tree2.add_node("A Epita"); + tree2.add_node("Ping pong ping"); + main_tree.add_tree(tree2); + + std::cout << "root main: " << main_tree.get_node_root().get_data() + << std::endl; + nb_childs2 = main_tree.get_nb_childs(); + + // Ici arbre sur 2 niveaux (Bien sur qu'on peut faire en recursivite ^_^) + for (unsigned int i = 0; i < nb_childs2; ++i) + { + nb_childs = main_tree.get_child(i).get_nb_childs(); + std::cout << main_tree.get_child(i).get_data() << std::endl; + for (unsigned int j = 0; j < nb_childs; ++j) + std::cout << main_tree.get_child(i).get_child(j).get_data() + << std::endl; + } + + return (0); +} + + +int main() +{ + test_tree(); + return (0); +} diff --git a/branches/hugues/glagen/algo_distribue/tree/node.cc b/branches/hugues/glagen/algo_distribue/tree/node.cc new file mode 100644 index 0000000..a3ae387 --- /dev/null +++ b/branches/hugues/glagen/algo_distribue/tree/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/branches/hugues/glagen/algo_distribue/tree/node.hh b/branches/hugues/glagen/algo_distribue/tree/node.hh new file mode 100644 index 0000000..b80a699 --- /dev/null +++ b/branches/hugues/glagen/algo_distribue/tree/node.hh @@ -0,0 +1,78 @@ + +#ifndef NODE_HH_ +# define NODE_HH_ + +#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/branches/hugues/glagen/algo_distribue/tree/tree.cc b/branches/hugues/glagen/algo_distribue/tree/tree.cc new file mode 100644 index 0000000..047ca89 --- /dev/null +++ b/branches/hugues/glagen/algo_distribue/tree/tree.cc @@ -0,0 +1,11 @@ +// +// tree.cc for in +// +// Made by meng-tih lam +// Login +// +// Started on Fri Aug 16 02:45:56 2002 meng-tih lam +// Last update Fri Aug 16 17:11:24 2002 meng-tih lam +// + +#include "tree.hh" diff --git a/branches/hugues/glagen/algo_distribue/tree/tree.hh b/branches/hugues/glagen/algo_distribue/tree/tree.hh new file mode 100644 index 0000000..86ce136 --- /dev/null +++ b/branches/hugues/glagen/algo_distribue/tree/tree.hh @@ -0,0 +1,51 @@ + + +#ifndef TREE_HH_ +# define TREE_HH_ + +#include +#include +#include "node.hh" +// Rajouter l'include correspondant a la template de TYPENODE +// + implemente le std::cout abstrait pour les tests + +template class Tree +{ +public: + // Construit la racine de l'arbre avec l'info dans son contenu + Tree(const TYPENODE& value) : _root(new Node(value)) {} + + Tree(const Tree& value) : _root(value._root) {} + + // Ajoute un noeud fils (avec info) a l'arbre + void add_node(const TYPENODE& value) { _root->add_child(value); } + + // Renvoie la racine de l'arbre de type Node + Node& get_node_root() const { return (*_root); } + + // Ajoute un autre arbre a la racine de l'arbre courant + void add_tree(const Tree &value) + { + _root->add_tree_node(value.get_node_root()); + } + + // Renvoie la liste de Node de ses fils + std::list< Node >& get_childs() { return _root->get_childs(); } + + // Information du nombre de fils + const unsigned int get_nb_childs() const + { + return (_root->get_nb_childs()); + } + + // Renvoie le noeud fils suivant le numero a partir de 0 + Node get_child(const unsigned int& i) const + { + return (_root->get_child(i)); + } + +private: + Node *_root; +}; + +#endif // TREE_HH_ diff --git a/branches/hugues/glagen/dll/.emacs.desktop b/branches/hugues/glagen/dll/.emacs.desktop new file mode 100644 index 0000000..5c1f534 --- /dev/null +++ b/branches/hugues/glagen/dll/.emacs.desktop @@ -0,0 +1,93 @@ +;; -*- coding: emacs-mule; -*- +;; -------------------------------------------------------------------------- +;; Desktop File for Emacs +;; -------------------------------------------------------------------------- +;; Created Mon Sep 23 16:32:32 2002 +;; Emacs version 21.2.1 + +;; Global section: +(setq desktop-missing-file-warning nil) +(setq tags-file-name nil) +(setq tags-table-list nil) +(setq search-ring '("glg_i" "GLG_i" "pallo" "exit" "return" "size" "###" "disp" "disp " "const" "getL" "GL_" "emacs")) +(setq regexp-search-ring nil) +(setq register-alist nil) + +;; Buffer section: +(desktop-create-buffer 205 + "/u/a2/hiegel_h/.mylogin" + ".mylogin" + 'fundamental-mode + nil + 457 + '(429 nil) + nil + nil + nil) + +(desktop-create-buffer 205 + "/u/a2/hiegel_h/projects/glagen/dll/classes/matrix.hh" + "matrix.hh" + 'c++-mode + '(abbrev-mode) + 513 + '(nil nil) + nil + nil + nil) + +(desktop-create-buffer 205 + "/u/a2/hiegel_h/projects/glagen/3d/data_glagen.hh" + "data_glagen.hh" + 'c++-mode + '(abbrev-mode) + 1629 + '(1540 t) + nil + nil + nil) + +(desktop-create-buffer 205 + "/u/a2/hiegel_h/projects/glagen/dll/Makefile" + "Makefile" + 'makefile-mode + nil + 447 + '(nil nil) + nil + nil + nil) + +(desktop-create-buffer 205 + "/u/a2/hiegel_h/projects/glagen/dll/libraryloader.cc" + "libraryloader.cc" + 'c++-mode + '(abbrev-mode) + 8093 + '(3155 nil) + nil + nil + nil) + +(desktop-create-buffer 205 + "/u/a2/hiegel_h/projects/glagen/rapport+hiegel_h+EN.txt" + "rapport+hiegel_h+EN.txt" + 'text-mode + '(auto-fill-mode) + 418 + '(nil nil) + nil + nil + nil) + +(desktop-create-buffer 205 + "/u/a2/hiegel_h/projects/glagen/dll/classes/libclass.cc" + "libclass.cc" + 'c++-mode + '(abbrev-mode) + 1095 + '(1 nil) + nil + nil + nil) + diff --git a/branches/hugues/glagen/dll/MANUAL b/branches/hugues/glagen/dll/MANUAL new file mode 100644 index 0000000..5e7cfa0 --- /dev/null +++ b/branches/hugues/glagen/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/branches/hugues/glagen/dll/Makefile b/branches/hugues/glagen/dll/Makefile new file mode 100644 index 0000000..b3db10d --- /dev/null +++ b/branches/hugues/glagen/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/branches/hugues/glagen/dll/NOTES b/branches/hugues/glagen/dll/NOTES new file mode 100644 index 0000000..19b48fa --- /dev/null +++ b/branches/hugues/glagen/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/branches/hugues/glagen/dll/README b/branches/hugues/glagen/dll/README new file mode 100644 index 0000000..36d270e --- /dev/null +++ b/branches/hugues/glagen/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/branches/hugues/glagen/dll/classes/Data_property.cc b/branches/hugues/glagen/dll/classes/Data_property.cc new file mode 100644 index 0000000..3be4b27 --- /dev/null +++ b/branches/hugues/glagen/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/branches/hugues/glagen/dll/classes/Data_property.hh b/branches/hugues/glagen/dll/classes/Data_property.hh new file mode 100644 index 0000000..b4d0c4d --- /dev/null +++ b/branches/hugues/glagen/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/branches/hugues/glagen/dll/classes/Data_string.cc b/branches/hugues/glagen/dll/classes/Data_string.cc new file mode 100644 index 0000000..49fe4ff --- /dev/null +++ b/branches/hugues/glagen/dll/classes/Data_string.cc @@ -0,0 +1 @@ +#include "Data_string.hh" diff --git a/branches/hugues/glagen/dll/classes/Data_string.hh b/branches/hugues/glagen/dll/classes/Data_string.hh new file mode 100644 index 0000000..a5f9131 --- /dev/null +++ b/branches/hugues/glagen/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/branches/hugues/glagen/dll/classes/GLG-libraries-devel.cc b/branches/hugues/glagen/dll/classes/GLG-libraries-devel.cc new file mode 100644 index 0000000..002d479 --- /dev/null +++ b/branches/hugues/glagen/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/branches/hugues/glagen/dll/classes/GLG-libraries-devel.hh b/branches/hugues/glagen/dll/classes/GLG-libraries-devel.hh new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/branches/hugues/glagen/dll/classes/GLG-libraries-devel.hh @@ -0,0 +1 @@ + diff --git a/branches/hugues/glagen/dll/classes/dot.cc b/branches/hugues/glagen/dll/classes/dot.cc new file mode 100644 index 0000000..10e766a --- /dev/null +++ b/branches/hugues/glagen/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/branches/hugues/glagen/dll/classes/dot.hh b/branches/hugues/glagen/dll/classes/dot.hh new file mode 100644 index 0000000..e13f23c --- /dev/null +++ b/branches/hugues/glagen/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/branches/hugues/glagen/dll/classes/libclass.cc b/branches/hugues/glagen/dll/classes/libclass.cc new file mode 100644 index 0000000..730026f --- /dev/null +++ b/branches/hugues/glagen/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/branches/hugues/glagen/dll/classes/libclass.hh b/branches/hugues/glagen/dll/classes/libclass.hh new file mode 100644 index 0000000..33a2fde --- /dev/null +++ b/branches/hugues/glagen/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/branches/hugues/glagen/dll/classes/matrix.cc b/branches/hugues/glagen/dll/classes/matrix.cc new file mode 100644 index 0000000..7991769 --- /dev/null +++ b/branches/hugues/glagen/dll/classes/matrix.cc @@ -0,0 +1,3 @@ + + +#include "matrix.hh" diff --git a/branches/hugues/glagen/dll/classes/matrix.hh b/branches/hugues/glagen/dll/classes/matrix.hh new file mode 100644 index 0000000..f49ea17 --- /dev/null +++ b/branches/hugues/glagen/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/branches/hugues/glagen/dll/classes/node.cc b/branches/hugues/glagen/dll/classes/node.cc new file mode 100644 index 0000000..a3ae387 --- /dev/null +++ b/branches/hugues/glagen/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/branches/hugues/glagen/dll/classes/node.hh b/branches/hugues/glagen/dll/classes/node.hh new file mode 100644 index 0000000..3d8c838 --- /dev/null +++ b/branches/hugues/glagen/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/branches/hugues/glagen/dll/create_dotproperty_init.cc b/branches/hugues/glagen/dll/create_dotproperty_init.cc new file mode 100644 index 0000000..56de80d --- /dev/null +++ b/branches/hugues/glagen/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/branches/hugues/glagen/dll/create_dotproperty_init.hh b/branches/hugues/glagen/dll/create_dotproperty_init.hh new file mode 100644 index 0000000..e69de29 diff --git a/branches/hugues/glagen/dll/header.cc b/branches/hugues/glagen/dll/header.cc new file mode 100644 index 0000000..92e361a --- /dev/null +++ b/branches/hugues/glagen/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/branches/hugues/glagen/dll/includes/errors.hh b/branches/hugues/glagen/dll/includes/errors.hh new file mode 100644 index 0000000..00267fb --- /dev/null +++ b/branches/hugues/glagen/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/branches/hugues/glagen/dll/libraryloader.cc b/branches/hugues/glagen/dll/libraryloader.cc new file mode 100644 index 0000000..9e8b67a --- /dev/null +++ b/branches/hugues/glagen/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/branches/hugues/glagen/dll/libraryloader.hh b/branches/hugues/glagen/dll/libraryloader.hh new file mode 100644 index 0000000..f23810b --- /dev/null +++ b/branches/hugues/glagen/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/branches/hugues/glagen/dll/main.cc b/branches/hugues/glagen/dll/main.cc new file mode 100644 index 0000000..ac744f7 --- /dev/null +++ b/branches/hugues/glagen/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/branches/hugues/glagen/dll/main.hh b/branches/hugues/glagen/dll/main.hh new file mode 100644 index 0000000..a812196 --- /dev/null +++ b/branches/hugues/glagen/dll/main.hh @@ -0,0 +1 @@ +##Trippant ! on se touche la bite dans ce main.hh !!## diff --git a/branches/hugues/glagen/dll/samples2/gps/libtoto.gps b/branches/hugues/glagen/dll/samples2/gps/libtoto.gps new file mode 100644 index 0000000..b70c38b --- /dev/null +++ b/branches/hugues/glagen/dll/samples2/gps/libtoto.gps @@ -0,0 +1,4 @@ +NAME: libtoto +VERSION: 0.0 +DEPS: libtata==0.0 +AUTHOR: gus diff --git a/branches/hugues/glagen/trucs b/branches/hugues/glagen/trucs new file mode 100644 index 0000000..8589cba --- /dev/null +++ b/branches/hugues/glagen/trucs @@ -0,0 +1,10 @@ +Fonction a passer lors de l'Init : + +int GLG_palloc(kind..) +int GLG_read(...) +int GLG_write() +void GLG_perlin() + double GLG_Perlin_noise_1D(double arg); + float GLG_Perlin_noise_2D(float vec[2]); + float GLG_Perlin_noise_3D(float vec[3]); + float GLG_Perlin_noise_4D(float vec[4]); -- cgit v1.2.3