mirror of
https://github.com/joe7575/tubelib2.git
synced 2024-11-24 16:33:44 +01:00
v0.5 node meta data removed, memory cache added instead of
This commit is contained in:
parent
78ea6da8c0
commit
396a7ac3fd
502
LICENSE.txt
Normal file
502
LICENSE.txt
Normal file
@ -0,0 +1,502 @@
|
|||||||
|
GNU LESSER GENERAL PUBLIC LICENSE
|
||||||
|
Version 2.1, February 1999
|
||||||
|
|
||||||
|
Copyright (C) 1991, 1999 Free Software Foundation, Inc.
|
||||||
|
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
Everyone is permitted to copy and distribute verbatim copies
|
||||||
|
of this license document, but changing it is not allowed.
|
||||||
|
|
||||||
|
[This is the first released version of the Lesser GPL. It also counts
|
||||||
|
as the successor of the GNU Library Public License, version 2, hence
|
||||||
|
the version number 2.1.]
|
||||||
|
|
||||||
|
Preamble
|
||||||
|
|
||||||
|
The licenses for most software are designed to take away your
|
||||||
|
freedom to share and change it. By contrast, the GNU General Public
|
||||||
|
Licenses are intended to guarantee your freedom to share and change
|
||||||
|
free software--to make sure the software is free for all its users.
|
||||||
|
|
||||||
|
This license, the Lesser General Public License, applies to some
|
||||||
|
specially designated software packages--typically libraries--of the
|
||||||
|
Free Software Foundation and other authors who decide to use it. You
|
||||||
|
can use it too, but we suggest you first think carefully about whether
|
||||||
|
this license or the ordinary General Public License is the better
|
||||||
|
strategy to use in any particular case, based on the explanations below.
|
||||||
|
|
||||||
|
When we speak of free software, we are referring to freedom of use,
|
||||||
|
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 and use pieces of
|
||||||
|
it in new free programs; and that you are informed that you can do
|
||||||
|
these things.
|
||||||
|
|
||||||
|
To protect your rights, we need to make restrictions that forbid
|
||||||
|
distributors to deny you these rights or to ask you to surrender these
|
||||||
|
rights. These restrictions translate to certain responsibilities for
|
||||||
|
you if you distribute copies of the library or if you modify it.
|
||||||
|
|
||||||
|
For example, if you distribute copies of the library, whether gratis
|
||||||
|
or for a fee, you must give the recipients all the rights that we gave
|
||||||
|
you. You must make sure that they, too, receive or can get the source
|
||||||
|
code. If you link other code with the library, you must provide
|
||||||
|
complete object files to the recipients, so that they can relink them
|
||||||
|
with the library after making changes to the library and recompiling
|
||||||
|
it. And you must show them these terms so they know their rights.
|
||||||
|
|
||||||
|
We protect your rights with a two-step method: (1) we copyright the
|
||||||
|
library, and (2) we offer you this license, which gives you legal
|
||||||
|
permission to copy, distribute and/or modify the library.
|
||||||
|
|
||||||
|
To protect each distributor, we want to make it very clear that
|
||||||
|
there is no warranty for the free library. Also, if the library is
|
||||||
|
modified by someone else and passed on, the recipients should know
|
||||||
|
that what they have is not the original version, so that the original
|
||||||
|
author's reputation will not be affected by problems that might be
|
||||||
|
introduced by others.
|
||||||
|
|
||||||
|
Finally, software patents pose a constant threat to the existence of
|
||||||
|
any free program. We wish to make sure that a company cannot
|
||||||
|
effectively restrict the users of a free program by obtaining a
|
||||||
|
restrictive license from a patent holder. Therefore, we insist that
|
||||||
|
any patent license obtained for a version of the library must be
|
||||||
|
consistent with the full freedom of use specified in this license.
|
||||||
|
|
||||||
|
Most GNU software, including some libraries, is covered by the
|
||||||
|
ordinary GNU General Public License. This license, the GNU Lesser
|
||||||
|
General Public License, applies to certain designated libraries, and
|
||||||
|
is quite different from the ordinary General Public License. We use
|
||||||
|
this license for certain libraries in order to permit linking those
|
||||||
|
libraries into non-free programs.
|
||||||
|
|
||||||
|
When a program is linked with a library, whether statically or using
|
||||||
|
a shared library, the combination of the two is legally speaking a
|
||||||
|
combined work, a derivative of the original library. The ordinary
|
||||||
|
General Public License therefore permits such linking only if the
|
||||||
|
entire combination fits its criteria of freedom. The Lesser General
|
||||||
|
Public License permits more lax criteria for linking other code with
|
||||||
|
the library.
|
||||||
|
|
||||||
|
We call this license the "Lesser" General Public License because it
|
||||||
|
does Less to protect the user's freedom than the ordinary General
|
||||||
|
Public License. It also provides other free software developers Less
|
||||||
|
of an advantage over competing non-free programs. These disadvantages
|
||||||
|
are the reason we use the ordinary General Public License for many
|
||||||
|
libraries. However, the Lesser license provides advantages in certain
|
||||||
|
special circumstances.
|
||||||
|
|
||||||
|
For example, on rare occasions, there may be a special need to
|
||||||
|
encourage the widest possible use of a certain library, so that it becomes
|
||||||
|
a de-facto standard. To achieve this, non-free programs must be
|
||||||
|
allowed to use the library. A more frequent case is that a free
|
||||||
|
library does the same job as widely used non-free libraries. In this
|
||||||
|
case, there is little to gain by limiting the free library to free
|
||||||
|
software only, so we use the Lesser General Public License.
|
||||||
|
|
||||||
|
In other cases, permission to use a particular library in non-free
|
||||||
|
programs enables a greater number of people to use a large body of
|
||||||
|
free software. For example, permission to use the GNU C Library in
|
||||||
|
non-free programs enables many more people to use the whole GNU
|
||||||
|
operating system, as well as its variant, the GNU/Linux operating
|
||||||
|
system.
|
||||||
|
|
||||||
|
Although the Lesser General Public License is Less protective of the
|
||||||
|
users' freedom, it does ensure that the user of a program that is
|
||||||
|
linked with the Library has the freedom and the wherewithal to run
|
||||||
|
that program using a modified version of the Library.
|
||||||
|
|
||||||
|
The precise terms and conditions for copying, distribution and
|
||||||
|
modification follow. Pay close attention to the difference between a
|
||||||
|
"work based on the library" and a "work that uses the library". The
|
||||||
|
former contains code derived from the library, whereas the latter must
|
||||||
|
be combined with the library in order to run.
|
||||||
|
|
||||||
|
GNU LESSER GENERAL PUBLIC LICENSE
|
||||||
|
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
|
||||||
|
|
||||||
|
0. This License Agreement applies to any software library or other
|
||||||
|
program which contains a notice placed by the copyright holder or
|
||||||
|
other authorized party saying it may be distributed under the terms of
|
||||||
|
this Lesser General Public License (also called "this License").
|
||||||
|
Each licensee is addressed as "you".
|
||||||
|
|
||||||
|
A "library" means a collection of software functions and/or data
|
||||||
|
prepared so as to be conveniently linked with application programs
|
||||||
|
(which use some of those functions and data) to form executables.
|
||||||
|
|
||||||
|
The "Library", below, refers to any such software library or work
|
||||||
|
which has been distributed under these terms. A "work based on the
|
||||||
|
Library" means either the Library or any derivative work under
|
||||||
|
copyright law: that is to say, a work containing the Library or a
|
||||||
|
portion of it, either verbatim or with modifications and/or translated
|
||||||
|
straightforwardly into another language. (Hereinafter, translation is
|
||||||
|
included without limitation in the term "modification".)
|
||||||
|
|
||||||
|
"Source code" for a work means the preferred form of the work for
|
||||||
|
making modifications to it. For a library, 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 library.
|
||||||
|
|
||||||
|
Activities other than copying, distribution and modification are not
|
||||||
|
covered by this License; they are outside its scope. The act of
|
||||||
|
running a program using the Library is not restricted, and output from
|
||||||
|
such a program is covered only if its contents constitute a work based
|
||||||
|
on the Library (independent of the use of the Library in a tool for
|
||||||
|
writing it). Whether that is true depends on what the Library does
|
||||||
|
and what the program that uses the Library does.
|
||||||
|
|
||||||
|
1. You may copy and distribute verbatim copies of the Library's
|
||||||
|
complete 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 distribute a copy of this License along with the
|
||||||
|
Library.
|
||||||
|
|
||||||
|
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 Library or any portion
|
||||||
|
of it, thus forming a work based on the Library, 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) The modified work must itself be a software library.
|
||||||
|
|
||||||
|
b) You must cause the files modified to carry prominent notices
|
||||||
|
stating that you changed the files and the date of any change.
|
||||||
|
|
||||||
|
c) You must cause the whole of the work to be licensed at no
|
||||||
|
charge to all third parties under the terms of this License.
|
||||||
|
|
||||||
|
d) If a facility in the modified Library refers to a function or a
|
||||||
|
table of data to be supplied by an application program that uses
|
||||||
|
the facility, other than as an argument passed when the facility
|
||||||
|
is invoked, then you must make a good faith effort to ensure that,
|
||||||
|
in the event an application does not supply such function or
|
||||||
|
table, the facility still operates, and performs whatever part of
|
||||||
|
its purpose remains meaningful.
|
||||||
|
|
||||||
|
(For example, a function in a library to compute square roots has
|
||||||
|
a purpose that is entirely well-defined independent of the
|
||||||
|
application. Therefore, Subsection 2d requires that any
|
||||||
|
application-supplied function or table used by this function must
|
||||||
|
be optional: if the application does not supply it, the square
|
||||||
|
root function must still compute square roots.)
|
||||||
|
|
||||||
|
These requirements apply to the modified work as a whole. If
|
||||||
|
identifiable sections of that work are not derived from the Library,
|
||||||
|
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 Library, 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 Library.
|
||||||
|
|
||||||
|
In addition, mere aggregation of another work not based on the Library
|
||||||
|
with the Library (or with a work based on the Library) on a volume of
|
||||||
|
a storage or distribution medium does not bring the other work under
|
||||||
|
the scope of this License.
|
||||||
|
|
||||||
|
3. You may opt to apply the terms of the ordinary GNU General Public
|
||||||
|
License instead of this License to a given copy of the Library. To do
|
||||||
|
this, you must alter all the notices that refer to this License, so
|
||||||
|
that they refer to the ordinary GNU General Public License, version 2,
|
||||||
|
instead of to this License. (If a newer version than version 2 of the
|
||||||
|
ordinary GNU General Public License has appeared, then you can specify
|
||||||
|
that version instead if you wish.) Do not make any other change in
|
||||||
|
these notices.
|
||||||
|
|
||||||
|
Once this change is made in a given copy, it is irreversible for
|
||||||
|
that copy, so the ordinary GNU General Public License applies to all
|
||||||
|
subsequent copies and derivative works made from that copy.
|
||||||
|
|
||||||
|
This option is useful when you wish to copy part of the code of
|
||||||
|
the Library into a program that is not a library.
|
||||||
|
|
||||||
|
4. You may copy and distribute the Library (or a portion or
|
||||||
|
derivative of it, under Section 2) in object code or executable form
|
||||||
|
under the terms of Sections 1 and 2 above provided that you 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.
|
||||||
|
|
||||||
|
If distribution of 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 satisfies the requirement to
|
||||||
|
distribute the source code, even though third parties are not
|
||||||
|
compelled to copy the source along with the object code.
|
||||||
|
|
||||||
|
5. A program that contains no derivative of any portion of the
|
||||||
|
Library, but is designed to work with the Library by being compiled or
|
||||||
|
linked with it, is called a "work that uses the Library". Such a
|
||||||
|
work, in isolation, is not a derivative work of the Library, and
|
||||||
|
therefore falls outside the scope of this License.
|
||||||
|
|
||||||
|
However, linking a "work that uses the Library" with the Library
|
||||||
|
creates an executable that is a derivative of the Library (because it
|
||||||
|
contains portions of the Library), rather than a "work that uses the
|
||||||
|
library". The executable is therefore covered by this License.
|
||||||
|
Section 6 states terms for distribution of such executables.
|
||||||
|
|
||||||
|
When a "work that uses the Library" uses material from a header file
|
||||||
|
that is part of the Library, the object code for the work may be a
|
||||||
|
derivative work of the Library even though the source code is not.
|
||||||
|
Whether this is true is especially significant if the work can be
|
||||||
|
linked without the Library, or if the work is itself a library. The
|
||||||
|
threshold for this to be true is not precisely defined by law.
|
||||||
|
|
||||||
|
If such an object file uses only numerical parameters, data
|
||||||
|
structure layouts and accessors, and small macros and small inline
|
||||||
|
functions (ten lines or less in length), then the use of the object
|
||||||
|
file is unrestricted, regardless of whether it is legally a derivative
|
||||||
|
work. (Executables containing this object code plus portions of the
|
||||||
|
Library will still fall under Section 6.)
|
||||||
|
|
||||||
|
Otherwise, if the work is a derivative of the Library, you may
|
||||||
|
distribute the object code for the work under the terms of Section 6.
|
||||||
|
Any executables containing that work also fall under Section 6,
|
||||||
|
whether or not they are linked directly with the Library itself.
|
||||||
|
|
||||||
|
6. As an exception to the Sections above, you may also combine or
|
||||||
|
link a "work that uses the Library" with the Library to produce a
|
||||||
|
work containing portions of the Library, and distribute that work
|
||||||
|
under terms of your choice, provided that the terms permit
|
||||||
|
modification of the work for the customer's own use and reverse
|
||||||
|
engineering for debugging such modifications.
|
||||||
|
|
||||||
|
You must give prominent notice with each copy of the work that the
|
||||||
|
Library is used in it and that the Library and its use are covered by
|
||||||
|
this License. You must supply a copy of this License. If the work
|
||||||
|
during execution displays copyright notices, you must include the
|
||||||
|
copyright notice for the Library among them, as well as a reference
|
||||||
|
directing the user to the copy of this License. Also, you must do one
|
||||||
|
of these things:
|
||||||
|
|
||||||
|
a) Accompany the work with the complete corresponding
|
||||||
|
machine-readable source code for the Library including whatever
|
||||||
|
changes were used in the work (which must be distributed under
|
||||||
|
Sections 1 and 2 above); and, if the work is an executable linked
|
||||||
|
with the Library, with the complete machine-readable "work that
|
||||||
|
uses the Library", as object code and/or source code, so that the
|
||||||
|
user can modify the Library and then relink to produce a modified
|
||||||
|
executable containing the modified Library. (It is understood
|
||||||
|
that the user who changes the contents of definitions files in the
|
||||||
|
Library will not necessarily be able to recompile the application
|
||||||
|
to use the modified definitions.)
|
||||||
|
|
||||||
|
b) Use a suitable shared library mechanism for linking with the
|
||||||
|
Library. A suitable mechanism is one that (1) uses at run time a
|
||||||
|
copy of the library already present on the user's computer system,
|
||||||
|
rather than copying library functions into the executable, and (2)
|
||||||
|
will operate properly with a modified version of the library, if
|
||||||
|
the user installs one, as long as the modified version is
|
||||||
|
interface-compatible with the version that the work was made with.
|
||||||
|
|
||||||
|
c) Accompany the work with a written offer, valid for at
|
||||||
|
least three years, to give the same user the materials
|
||||||
|
specified in Subsection 6a, above, for a charge no more
|
||||||
|
than the cost of performing this distribution.
|
||||||
|
|
||||||
|
d) If distribution of the work is made by offering access to copy
|
||||||
|
from a designated place, offer equivalent access to copy the above
|
||||||
|
specified materials from the same place.
|
||||||
|
|
||||||
|
e) Verify that the user has already received a copy of these
|
||||||
|
materials or that you have already sent this user a copy.
|
||||||
|
|
||||||
|
For an executable, the required form of the "work that uses the
|
||||||
|
Library" must include any data and utility programs needed for
|
||||||
|
reproducing the executable from it. However, as a special exception,
|
||||||
|
the materials to be 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.
|
||||||
|
|
||||||
|
It may happen that this requirement contradicts the license
|
||||||
|
restrictions of other proprietary libraries that do not normally
|
||||||
|
accompany the operating system. Such a contradiction means you cannot
|
||||||
|
use both them and the Library together in an executable that you
|
||||||
|
distribute.
|
||||||
|
|
||||||
|
7. You may place library facilities that are a work based on the
|
||||||
|
Library side-by-side in a single library together with other library
|
||||||
|
facilities not covered by this License, and distribute such a combined
|
||||||
|
library, provided that the separate distribution of the work based on
|
||||||
|
the Library and of the other library facilities is otherwise
|
||||||
|
permitted, and provided that you do these two things:
|
||||||
|
|
||||||
|
a) Accompany the combined library with a copy of the same work
|
||||||
|
based on the Library, uncombined with any other library
|
||||||
|
facilities. This must be distributed under the terms of the
|
||||||
|
Sections above.
|
||||||
|
|
||||||
|
b) Give prominent notice with the combined library of the fact
|
||||||
|
that part of it is a work based on the Library, and explaining
|
||||||
|
where to find the accompanying uncombined form of the same work.
|
||||||
|
|
||||||
|
8. You may not copy, modify, sublicense, link with, or distribute
|
||||||
|
the Library except as expressly provided under this License. Any
|
||||||
|
attempt otherwise to copy, modify, sublicense, link with, or
|
||||||
|
distribute the Library 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.
|
||||||
|
|
||||||
|
9. 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 Library or its derivative works. These actions are
|
||||||
|
prohibited by law if you do not accept this License. Therefore, by
|
||||||
|
modifying or distributing the Library (or any work based on the
|
||||||
|
Library), you indicate your acceptance of this License to do so, and
|
||||||
|
all its terms and conditions for copying, distributing or modifying
|
||||||
|
the Library or works based on it.
|
||||||
|
|
||||||
|
10. Each time you redistribute the Library (or any work based on the
|
||||||
|
Library), the recipient automatically receives a license from the
|
||||||
|
original licensor to copy, distribute, link with or modify the Library
|
||||||
|
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 with
|
||||||
|
this License.
|
||||||
|
|
||||||
|
11. 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 Library at all. For example, if a patent
|
||||||
|
license would not permit royalty-free redistribution of the Library 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 Library.
|
||||||
|
|
||||||
|
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.
|
||||||
|
|
||||||
|
12. If the distribution and/or use of the Library is restricted in
|
||||||
|
certain countries either by patents or by copyrighted interfaces, the
|
||||||
|
original copyright holder who places the Library 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.
|
||||||
|
|
||||||
|
13. The Free Software Foundation may publish revised and/or new
|
||||||
|
versions of the Lesser 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 Library
|
||||||
|
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 Library does not specify a
|
||||||
|
license version number, you may choose any version ever published by
|
||||||
|
the Free Software Foundation.
|
||||||
|
|
||||||
|
14. If you wish to incorporate parts of the Library into other free
|
||||||
|
programs whose distribution conditions are incompatible with these,
|
||||||
|
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
|
||||||
|
|
||||||
|
15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO
|
||||||
|
WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW.
|
||||||
|
EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR
|
||||||
|
OTHER PARTIES PROVIDE THE LIBRARY "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
|
||||||
|
LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME
|
||||||
|
THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
|
||||||
|
|
||||||
|
16. 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 LIBRARY 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
|
||||||
|
LIBRARY (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 LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF
|
||||||
|
SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
|
||||||
|
DAMAGES.
|
||||||
|
|
||||||
|
END OF TERMS AND CONDITIONS
|
||||||
|
|
||||||
|
How to Apply These Terms to Your New Libraries
|
||||||
|
|
||||||
|
If you develop a new library, and you want it to be of the greatest
|
||||||
|
possible use to the public, we recommend making it free software that
|
||||||
|
everyone can redistribute and change. You can do so by permitting
|
||||||
|
redistribution under these terms (or, alternatively, under the terms of the
|
||||||
|
ordinary General Public License).
|
||||||
|
|
||||||
|
To apply these terms, attach the following notices to the library. It is
|
||||||
|
safest to attach them to the start of each source file to most effectively
|
||||||
|
convey the exclusion of warranty; and each file should have at least the
|
||||||
|
"copyright" line and a pointer to where the full notice is found.
|
||||||
|
|
||||||
|
<one line to give the library's name and a brief idea of what it does.>
|
||||||
|
Copyright (C) <year> <name of author>
|
||||||
|
|
||||||
|
This library is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU Lesser General Public
|
||||||
|
License as published by the Free Software Foundation; either
|
||||||
|
version 2.1 of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
This library is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public
|
||||||
|
License along with this library; if not, write to the Free Software
|
||||||
|
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
|
||||||
|
Also add information on how to contact you by electronic and paper mail.
|
||||||
|
|
||||||
|
You should also get your employer (if you work as a programmer) or your
|
||||||
|
school, if any, to sign a "copyright disclaimer" for the library, if
|
||||||
|
necessary. Here is a sample; alter the names:
|
||||||
|
|
||||||
|
Yoyodyne, Inc., hereby disclaims all copyright interest in the
|
||||||
|
library `Frob' (a library for tweaking knobs) written by James Random Hacker.
|
||||||
|
|
||||||
|
<signature of Ty Coon>, 1 April 1990
|
||||||
|
Ty Coon, President of Vice
|
||||||
|
|
||||||
|
That's all there is to it!
|
@ -44,10 +44,10 @@ All other nodes are build by means of axis/rotation variants based on param2
|
|||||||
|
|
||||||
The 3 free MSB bits of param2 of tube nodes are used to store the number of connections (0..2).
|
The 3 free MSB bits of param2 of tube nodes are used to store the number of connections (0..2).
|
||||||
|
|
||||||
The data of the peer head tube are stored as meta data: "peer_pos" and "peer_dir"
|
The data of the peer head tube are stored in memory 'self.connCache'
|
||||||
|
|
||||||
Tubelib2 provides an update mechanism for connected "secondary" nodes. A callback function
|
Tubelib2 provides an update mechanism for connected "secondary" nodes. A callback function
|
||||||
"tubelib2_on_update" will be called for every change on the connected tubes.
|
func(node, pos, out_dir, peer_pos, peer_in_dir) will be called for every change on the connected tubes.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -65,3 +65,4 @@ Textures: CC0
|
|||||||
- 2018-10-27 v0.2 * Tested against and enhanced for the hyperloop mod.
|
- 2018-10-27 v0.2 * Tested against and enhanced for the hyperloop mod.
|
||||||
- 2018-10-27 v0.3 * Further improvements.
|
- 2018-10-27 v0.3 * Further improvements.
|
||||||
- 2018-11-09 v0.4 * on_update function for secondary nodes introduced
|
- 2018-11-09 v0.4 * on_update function for secondary nodes introduced
|
||||||
|
- 2018-12-16 v0.5 * meta data removed, memory cache added instead of
|
||||||
|
87
design.txt
87
design.txt
@ -68,90 +68,3 @@ dir1/dir2 1/2 1/4 2/3 3/4
|
|||||||
axis/rot 2/3 3/2 1/3 1/1
|
axis/rot 2/3 3/2 1/3 1/1
|
||||||
|
|
||||||
|
|
||||||
####################################################
|
|
||||||
|
|
||||||
after_place_node()
|
|
||||||
update_after_place_node()
|
|
||||||
get_meta()
|
|
||||||
repair_tube_line()
|
|
||||||
get_pos()
|
|
||||||
update_secondary_node()
|
|
||||||
|
|
||||||
after_place_tube()
|
|
||||||
update_after_place_tube()
|
|
||||||
del_meta()
|
|
||||||
repair_tube_line()
|
|
||||||
add_meta()
|
|
||||||
update_secondary_node()
|
|
||||||
|
|
||||||
after_dig_node()
|
|
||||||
update_after_dig_node()
|
|
||||||
get_meta()
|
|
||||||
repair_tube_line()
|
|
||||||
get_pos()
|
|
||||||
add_meta()
|
|
||||||
update_secondary_node()
|
|
||||||
|
|
||||||
after_dig_tube()
|
|
||||||
update_after_dig_tube()
|
|
||||||
get_meta()
|
|
||||||
repair_tube_line()
|
|
||||||
get_pos()
|
|
||||||
add_meta()
|
|
||||||
update_secondary_node()
|
|
||||||
|
|
||||||
get_connected_node_pos()
|
|
||||||
get_meta()
|
|
||||||
repair_tube_line()
|
|
||||||
get_pos()
|
|
||||||
|
|
||||||
tool_repair_tubes()
|
|
||||||
determine_dirs()
|
|
||||||
repair_tube_line()
|
|
||||||
add_meta()
|
|
||||||
update_secondary_node()
|
|
||||||
|
|
||||||
tool_remove_tube()
|
|
||||||
remove_tube()
|
|
||||||
repair_tube_line()
|
|
||||||
get_pos()
|
|
||||||
add_meta()
|
|
||||||
update_secondary_node()
|
|
||||||
|
|
||||||
#####################################################################
|
|
||||||
|
|
||||||
primary_node()
|
|
||||||
secondary_node()
|
|
||||||
get_primary_dir()
|
|
||||||
get_pos()
|
|
||||||
|
|
||||||
del_meta()
|
|
||||||
get_meta()
|
|
||||||
add_meta()
|
|
||||||
|
|
||||||
repair_tube_line()
|
|
||||||
update_secondary_node()
|
|
||||||
|
|
||||||
update_after_place_node()
|
|
||||||
update_after_dig_node()
|
|
||||||
update_after_place_tube()
|
|
||||||
update_after_dig_tube()
|
|
||||||
|
|
||||||
#####################################################################
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Neuer Ansatz
|
|
||||||
============
|
|
||||||
|
|
||||||
+------+ +------+
|
|
||||||
|peer->| |<-peer|
|
|
||||||
| |<--------------->| |
|
|
||||||
|dir-> | | <-dir|
|
|
||||||
+------+ +------+
|
|
||||||
|
|
||||||
Beim Setzen eines Nodes x werden immer die Meta-Daten in f1 und f2 aktualisiert
|
|
||||||
sowie die Secundary Update-Funktion von S1 und S2 aufgerufen.
|
|
||||||
|
|
||||||
[S1][f1]----[n1] x [n2]----[f2][S2]
|
|
||||||
|
|
||||||
|
2
init.lua
2
init.lua
@ -1,7 +1,7 @@
|
|||||||
tubelib2 = {}
|
tubelib2 = {}
|
||||||
|
|
||||||
dofile(minetest.get_modpath("tubelib2") .. "/tube_api.lua")
|
|
||||||
dofile(minetest.get_modpath("tubelib2") .. "/internal2.lua")
|
dofile(minetest.get_modpath("tubelib2") .. "/internal2.lua")
|
||||||
dofile(minetest.get_modpath("tubelib2") .. "/internal1.lua")
|
dofile(minetest.get_modpath("tubelib2") .. "/internal1.lua")
|
||||||
|
dofile(minetest.get_modpath("tubelib2") .. "/tube_api.lua")
|
||||||
-- Only for testing/demo purposes
|
-- Only for testing/demo purposes
|
||||||
dofile(minetest.get_modpath("tubelib2") .. "/tube_test.lua")
|
dofile(minetest.get_modpath("tubelib2") .. "/tube_test.lua")
|
||||||
|
219
internal1.lua
219
internal1.lua
@ -22,32 +22,39 @@ local M = minetest.get_meta
|
|||||||
local Tube = tubelib2.Tube
|
local Tube = tubelib2.Tube
|
||||||
local Turn180Deg = tubelib2.Turn180Deg
|
local Turn180Deg = tubelib2.Turn180Deg
|
||||||
local Dir6dToVector = tubelib2.Dir6dToVector
|
local Dir6dToVector = tubelib2.Dir6dToVector
|
||||||
|
local encode_param2 = tubelib2.encode_param2
|
||||||
local tValidNum = {[0] = true, true, true} -- 0..2 are valid
|
local tValidNum = {[0] = true, true, true} -- 0..2 are valid
|
||||||
|
|
||||||
--------------------------------------------------------------------------------------
|
-- format and return given data as table
|
||||||
-- node get/test functions
|
local function get_tube_data(pos, dir1, dir2, num_tubes)
|
||||||
--------------------------------------------------------------------------------------
|
local param2, tube_type = encode_param2(dir1, dir2, num_tubes)
|
||||||
|
return pos, param2, tube_type, num_tubes
|
||||||
|
end
|
||||||
|
|
||||||
-- Check if node at given position is a tube node
|
local function fdir(self, player)
|
||||||
-- If dir == nil then node_pos = pos
|
local pitch = player:get_look_pitch()
|
||||||
-- Function returns the new pos or nil
|
if pitch > 1.0 and self.valid_dirs[6] then -- up?
|
||||||
function Tube:primary_node(pos, dir)
|
return 6
|
||||||
local npos, node = self:get_node(pos, dir)
|
elseif pitch < -1.0 and self.valid_dirs[5] then -- down?
|
||||||
if self.primary_node_names[node.name] then
|
return 5
|
||||||
return npos, node
|
elseif not self.valid_dirs[1] then
|
||||||
|
return 6
|
||||||
|
else
|
||||||
|
return minetest.dir_to_facedir(player:get_look_dir()) + 1
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Check if node at given position is a secondary node
|
local function get_player_data(self, placer, pointed_thing)
|
||||||
-- If dir == nil then node_pos = pos
|
if placer and pointed_thing and pointed_thing.type == "node" then
|
||||||
-- Function returns the new pos or nil
|
if placer:get_player_control().sneak then
|
||||||
function Tube:secondary_node(pos, dir)
|
return pointed_thing.under, fdir(placer)
|
||||||
local npos, node = self:get_node(pos, dir)
|
else
|
||||||
if self.secondary_node_names[node.name] then
|
return nil, fdir(self, placer)
|
||||||
return npos
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
-- Used to determine the node side to the tube connection.
|
-- Used to determine the node side to the tube connection.
|
||||||
-- Function returns the first found dir value
|
-- Function returns the first found dir value
|
||||||
-- to a primary node.
|
-- to a primary node.
|
||||||
@ -61,133 +68,37 @@ function Tube:get_primary_dir(pos)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Return the new pos behind pos/dir and the dir our of the node.
|
-- pos/dir are the pos of the stable secondary node pointing to the head tube node.
|
||||||
function Tube:get_pos(pos, dir)
|
function Tube:del_from_cache(pos, dir)
|
||||||
return vector.add(pos, Dir6dToVector[dir or 0]), Turn180Deg[dir]
|
local key = S(pos)
|
||||||
end
|
if self.connCache[key] and self.connCache[key][dir] then
|
||||||
|
local pos2 = self.connCache[key][dir].pos2
|
||||||
|
local dir2 = self.connCache[key][dir].dir2
|
||||||
--------------------------------------------------------------------------------------
|
local key2 = S(pos2)
|
||||||
-- get/del/add meta data functions
|
if self.connCache[key2] and self.connCache[key2][dir2] then
|
||||||
--------------------------------------------------------------------------------------
|
self.connCache[key2][dir2] = nil
|
||||||
|
|
||||||
function Tube:del_meta(pos, dir)
|
|
||||||
local npos, node = self:get_node(pos, dir)
|
|
||||||
if self.primary_node_names[node.name] then
|
|
||||||
local meta = M(npos)
|
|
||||||
local peer_pos = meta:get_string("peer_pos")
|
|
||||||
local peer_dir = meta:get_int("peer_dir")
|
|
||||||
meta:from_table(nil)
|
|
||||||
if peer_pos ~= "" then
|
|
||||||
return P(peer_pos), peer_dir
|
|
||||||
end
|
end
|
||||||
end
|
self.connCache[key][dir] = nil
|
||||||
return self:repair_tube_line(pos, dir)
|
|
||||||
end
|
|
||||||
|
|
||||||
function Tube:get_meta(pos, dir)
|
|
||||||
local npos = vector.add(pos, Dir6dToVector[dir or 0])
|
|
||||||
local meta = M(npos)
|
|
||||||
local peer_pos = meta:get_string("peer_pos")
|
|
||||||
local peer_dir = meta:get_int("peer_dir")
|
|
||||||
if peer_pos ~= "" then
|
|
||||||
return P(peer_pos), peer_dir
|
|
||||||
end
|
|
||||||
return self:repair_tube_line(pos, dir)
|
|
||||||
end
|
|
||||||
|
|
||||||
-- Like get_meta(), but repair data if necessary
|
|
||||||
function Tube:repair_meta(pos, dir)
|
|
||||||
local npos = vector.add(pos, Dir6dToVector[dir or 0])
|
|
||||||
local meta = M(npos)
|
|
||||||
local peer_pos = meta:get_string("peer_pos")
|
|
||||||
local peer_dir = meta:get_int("peer_dir")
|
|
||||||
if peer_pos ~= "" then
|
|
||||||
return P(peer_pos), peer_dir
|
|
||||||
end
|
|
||||||
peer_pos, peer_dir = self:repair_tube_line(pos, dir)
|
|
||||||
self:add_meta(npos, peer_pos, peer_dir)
|
|
||||||
return peer_pos, peer_dir
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
function Tube:get_oldmeta(pos, dir, oldmetadata)
|
|
||||||
if oldmetadata.fields and oldmetadata.fields.peer_pos then
|
|
||||||
return P(oldmetadata.fields.peer_pos), tonumber(oldmetadata.fields.peer_dir)
|
|
||||||
end
|
|
||||||
return self:repair_tube_line(pos, dir)
|
|
||||||
end
|
|
||||||
|
|
||||||
-- Add meta data from the other tube head node
|
|
||||||
function Tube:add_meta(pos, peer_pos, peer_dir)
|
|
||||||
local _, node = self:get_node(pos)
|
|
||||||
if self.primary_node_names[node.name] then
|
|
||||||
if self.show_infotext then
|
|
||||||
M(pos):set_string("infotext", S(peer_pos))
|
|
||||||
end
|
|
||||||
M(pos):set_string("peer_pos", S(peer_pos))
|
|
||||||
M(pos):set_int("peer_dir", peer_dir)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
--------------------------------------------------------------------------------------
|
-- pos/dir are the pos of the secondary nodes pointing to the head tube nodes.
|
||||||
-- Further helper functions
|
function Tube:add_to_cache(pos1, dir1, pos2, dir2)
|
||||||
--------------------------------------------------------------------------------------
|
local key = S(pos1)
|
||||||
|
if not self.connCache[key] then
|
||||||
|
self.connCache[key] = {}
|
||||||
|
end
|
||||||
|
self.connCache[key][dir1] = {pos2 = pos2, dir2 = dir2}
|
||||||
|
end
|
||||||
|
|
||||||
-- Do a correction of param2, delete meta data of all 2-conn-tubes,
|
-- pos/dir are the pos of the secondary nodes pointing to the head tube nodes.
|
||||||
-- and return peer_pos, peer_dir, and number of tube nodes.
|
function Tube:update_secondary_node(pos1, dir1, pos2, dir2)
|
||||||
function Tube:repair_tube_line(pos, dir)
|
local _, node = self:get_node(pos1)
|
||||||
local get_next_tube = function(self, pos, dir)
|
|
||||||
local npos, dir1, dir2, num = self:determine_next_node(pos, dir)
|
|
||||||
if dir1 then
|
|
||||||
M(npos):from_table(nil)
|
|
||||||
if Turn180Deg[dir] == dir1 then
|
|
||||||
return npos, dir2, num
|
|
||||||
else
|
|
||||||
return npos, dir1, num
|
|
||||||
end
|
|
||||||
end
|
|
||||||
return self:get_next_teleport_node(pos, dir)
|
|
||||||
end
|
|
||||||
-- do a correction of "number of neighbours" for all nodes in between
|
|
||||||
local repair_tube = function(self, pos, dir)
|
|
||||||
local _, node = self:primary_node(pos, dir)
|
|
||||||
if node then
|
|
||||||
node.param2 = (2 * 32) + (node.param2 % 32)
|
|
||||||
minetest.swap_node(pos, node)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
local cnt = 0
|
|
||||||
if not dir then return pos, dir, cnt end
|
|
||||||
while cnt <= self.max_tube_length do
|
|
||||||
local new_pos, new_dir, num = get_next_tube(self, pos, dir)
|
|
||||||
if not new_dir then break end
|
|
||||||
if cnt > 0 and num ~= 2 then
|
|
||||||
repair_tube(self, pos, dir)
|
|
||||||
end
|
|
||||||
pos, dir = new_pos, new_dir
|
|
||||||
cnt = cnt + 1
|
|
||||||
end
|
|
||||||
return pos, dir, cnt
|
|
||||||
end
|
|
||||||
|
|
||||||
-- fpos,fdir points to the secondary node to be updated.
|
|
||||||
-- npos,ndir are used to calculate the connection data to be stored.
|
|
||||||
function Tube:update_secondary_node(fpos,fdir, npos,ndir)
|
|
||||||
-- [s]<-[n]----[f]->[s]
|
|
||||||
print("update_secondary_node", S(fpos), fdir)
|
|
||||||
local fpos2, node = self:get_node(fpos, fdir)
|
|
||||||
if self.secondary_node_names[node.name] and self.clbk_update_secondary_node then
|
if self.secondary_node_names[node.name] and self.clbk_update_secondary_node then
|
||||||
local npos2 = self:get_pos(npos, ndir)
|
self.clbk_update_secondary_node(node, pos1, dir1, pos2, Turn180Deg[dir2])
|
||||||
if vector.equals(npos2, fpos2) then -- last tube removed?
|
|
||||||
npos2,ndir = nil,nil -- used to delete the data base
|
|
||||||
end
|
|
||||||
self.clbk_update_secondary_node(node, fpos2, Turn180Deg[fdir], npos2, ndir)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
--------------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------------
|
||||||
-- pairing functions
|
-- pairing functions
|
||||||
--------------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------------
|
||||||
@ -213,7 +124,7 @@ function Tube:update_after_place_node(pos, dirs)
|
|||||||
for _,dir in ipairs(dirs) do
|
for _,dir in ipairs(dirs) do
|
||||||
local npos, d1, d2, num = self:add_tube_dir(pos, dir)
|
local npos, d1, d2, num = self:add_tube_dir(pos, dir)
|
||||||
if npos and self.valid_dirs[d1] and self.valid_dirs[d2] and tValidNum[num]then
|
if npos and self.valid_dirs[d1] and self.valid_dirs[d2] and tValidNum[num]then
|
||||||
self.clbk_after_place_tube(self:tube_data_to_table(npos, d1, d2, num))
|
self.clbk_after_place_tube(get_tube_data(npos, d1, d2, num))
|
||||||
lRes[#lRes+1] = dir
|
lRes[#lRes+1] = dir
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -227,7 +138,7 @@ function Tube:update_after_dig_node(pos, dirs)
|
|||||||
for _,dir in ipairs(dirs) do
|
for _,dir in ipairs(dirs) do
|
||||||
local npos, d1, d2, num = self:del_tube_dir(pos, dir)
|
local npos, d1, d2, num = self:del_tube_dir(pos, dir)
|
||||||
if npos and self.valid_dirs[d1] and self.valid_dirs[d2] and tValidNum[num]then
|
if npos and self.valid_dirs[d1] and self.valid_dirs[d2] and tValidNum[num]then
|
||||||
self.clbk_after_place_tube(self:tube_data_to_table(npos, d1, d2, num))
|
self.clbk_after_place_tube(get_tube_data(npos, d1, d2, num))
|
||||||
lRes[#lRes+1] = dir
|
lRes[#lRes+1] = dir
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -235,55 +146,47 @@ function Tube:update_after_dig_node(pos, dirs)
|
|||||||
end
|
end
|
||||||
|
|
||||||
function Tube:update_after_place_tube(pos, placer, pointed_thing)
|
function Tube:update_after_place_tube(pos, placer, pointed_thing)
|
||||||
local preferred_pos, fdir = self:get_player_data(placer, pointed_thing)
|
local preferred_pos, fdir = get_player_data(self, placer, pointed_thing)
|
||||||
local dir1, dir2, num_tubes = self:determine_tube_dirs(pos, preferred_pos, fdir)
|
local dir1, dir2, num_tubes = self:determine_tube_dirs(pos, preferred_pos, fdir)
|
||||||
if dir1 == nil then
|
if dir1 == nil then
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
if self.valid_dirs[dir1] and self.valid_dirs[dir2] and tValidNum[num_tubes]then
|
if self.valid_dirs[dir1] and self.valid_dirs[dir2] and tValidNum[num_tubes]then
|
||||||
self.clbk_after_place_tube(self:tube_data_to_table(pos, dir1, dir2, num_tubes))
|
self.clbk_after_place_tube(get_tube_data(pos, dir1, dir2, num_tubes))
|
||||||
end
|
end
|
||||||
|
|
||||||
if num_tubes >= 1 then
|
if num_tubes >= 1 then
|
||||||
local npos, d1, d2, num = self:add_tube_dir(pos, dir1)
|
local npos, d1, d2, num = self:add_tube_dir(pos, dir1)
|
||||||
if npos and self.valid_dirs[d1] and self.valid_dirs[d2] and tValidNum[num]then
|
if npos and self.valid_dirs[d1] and self.valid_dirs[d2] and tValidNum[num]then
|
||||||
self.clbk_after_place_tube(self:tube_data_to_table(npos, d1, d2, num))
|
self.clbk_after_place_tube(get_tube_data(npos, d1, d2, num))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if num_tubes >= 2 then
|
if num_tubes >= 2 then
|
||||||
local npos, d1, d2, num = self:add_tube_dir(pos, dir2)
|
local npos, d1, d2, num = self:add_tube_dir(pos, dir2)
|
||||||
if npos and self.valid_dirs[d1] and self.valid_dirs[d2] and tValidNum[num]then
|
if npos and self.valid_dirs[d1] and self.valid_dirs[d2] and tValidNum[num]then
|
||||||
self.clbk_after_place_tube(self:tube_data_to_table(npos, d1, d2, num))
|
self.clbk_after_place_tube(get_tube_data(npos, d1, d2, num))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
return true, dir1, dir2, num_tubes
|
return true, dir1, dir2, num_tubes
|
||||||
end
|
end
|
||||||
|
|
||||||
function Tube:update_after_dig_tube(pos, param2)
|
function Tube:update_after_dig_tube(pos, param2)
|
||||||
local dir1, dir2, num_tubes = self:decode_param2(pos, param2)
|
local dir1, dir2 = self:decode_param2(pos, param2)
|
||||||
|
|
||||||
local lRes = {}
|
|
||||||
local npos, d1, d2, num = self:del_tube_dir(pos, dir1)
|
local npos, d1, d2, num = self:del_tube_dir(pos, dir1)
|
||||||
if npos and self.valid_dirs[d1] and self.valid_dirs[d2] and tValidNum[num]then
|
if npos and self.valid_dirs[d1] and self.valid_dirs[d2] and tValidNum[num]then
|
||||||
self.clbk_after_place_tube(self:tube_data_to_table(npos, d1, d2, num))
|
self.clbk_after_place_tube(get_tube_data(npos, d1, d2, num))
|
||||||
lRes[#lRes+1] = dir1
|
else
|
||||||
|
dir1 = nil
|
||||||
end
|
end
|
||||||
|
|
||||||
npos, d1, d2, num = self:del_tube_dir(pos, dir2)
|
npos, d1, d2, num = self:del_tube_dir(pos, dir2)
|
||||||
if npos and self.valid_dirs[d1] and self.valid_dirs[d2] and tValidNum[num]then
|
if npos and self.valid_dirs[d1] and self.valid_dirs[d2] and tValidNum[num]then
|
||||||
self.clbk_after_place_tube(self:tube_data_to_table(npos, d1, d2, num))
|
self.clbk_after_place_tube(get_tube_data(npos, d1, d2, num))
|
||||||
lRes[#lRes+1] = dir2
|
else
|
||||||
end
|
dir2 = nil
|
||||||
return lRes
|
|
||||||
end
|
|
||||||
|
|
||||||
function Tube:update_secondary_nodes_after_dig_tube(pos)
|
|
||||||
local d1, d2 = self:determine_dir1_dir2_and_num_conn(pos)
|
|
||||||
if d1 then
|
|
||||||
self:update_secondary_node(pos,d1, pos,d1)
|
|
||||||
end
|
|
||||||
if d2 then
|
|
||||||
self:update_secondary_node(pos,d2, pos,d2)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
return dir1, dir2
|
||||||
end
|
end
|
||||||
|
165
internal2.lua
165
internal2.lua
@ -20,6 +20,7 @@ local M = minetest.get_meta
|
|||||||
|
|
||||||
local Turn180Deg = {[0]=0,3,4,1,2,6,5}
|
local Turn180Deg = {[0]=0,3,4,1,2,6,5}
|
||||||
tubelib2.Turn180Deg = Turn180Deg
|
tubelib2.Turn180Deg = Turn180Deg
|
||||||
|
tubelib2.Tube = {}
|
||||||
|
|
||||||
-- To calculate param2 based on dir6d information
|
-- To calculate param2 based on dir6d information
|
||||||
local DirToParam2 = {
|
local DirToParam2 = {
|
||||||
@ -74,21 +75,6 @@ local VectorToDir6d = {
|
|||||||
-- Local Functions
|
-- Local Functions
|
||||||
--
|
--
|
||||||
|
|
||||||
local function Tbl(list)
|
|
||||||
local tbl = {}
|
|
||||||
for _,item in ipairs(list) do
|
|
||||||
tbl[item] = true
|
|
||||||
end
|
|
||||||
return tbl
|
|
||||||
end
|
|
||||||
|
|
||||||
-- Return val in the range of min and max
|
|
||||||
local function range(val, min, max)
|
|
||||||
if val > max then return max end
|
|
||||||
if val < min then return min end
|
|
||||||
return val
|
|
||||||
end
|
|
||||||
|
|
||||||
local function get_node_lvm(pos)
|
local function get_node_lvm(pos)
|
||||||
local node = minetest.get_node_or_nil(pos)
|
local node = minetest.get_node_or_nil(pos)
|
||||||
if node then
|
if node then
|
||||||
@ -107,6 +93,42 @@ local function get_node_lvm(pos)
|
|||||||
return node
|
return node
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local function get_next_tube(self, pos, dir)
|
||||||
|
local npos = vector.add(pos, Dir6dToVector[dir or 0])
|
||||||
|
local node = get_node_lvm(npos)
|
||||||
|
if self.primary_node_names[node.name] then
|
||||||
|
-- decode param2
|
||||||
|
local val = Param2ToDir[node.param2 % 32]
|
||||||
|
if val then
|
||||||
|
local dir1, dir2 = math.floor(val / 10), val % 10
|
||||||
|
local num_conn = math.floor(node.param2 / 32)
|
||||||
|
if Turn180Deg[dir] == dir1 then
|
||||||
|
return npos, dir2, num_conn
|
||||||
|
else
|
||||||
|
return npos, dir1, num_conn
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return self:get_next_teleport_node(pos, dir)
|
||||||
|
end
|
||||||
|
|
||||||
|
local function repair_tube(self, pos, dir)
|
||||||
|
local node = get_node_lvm(pos, dir)
|
||||||
|
if self.primary_node_names[node.name] then
|
||||||
|
node.param2 = (2 * 32) + (node.param2 % 32)
|
||||||
|
minetest.set_node(pos, node)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Return param2 and tube type ("A"/"S")
|
||||||
|
function tubelib2.encode_param2(dir1, dir2, num_conn)
|
||||||
|
if dir1 > dir2 then
|
||||||
|
dir1, dir2 = dir2, dir1
|
||||||
|
end
|
||||||
|
local param2, _type = unpack(DirToParam2[dir1 * 10 + dir2] or {0, "S"})
|
||||||
|
return (num_conn * 32) + param2, _type
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
--
|
--
|
||||||
-- Tubelib2 Methods
|
-- Tubelib2 Methods
|
||||||
@ -114,38 +136,26 @@ end
|
|||||||
|
|
||||||
local Tube = tubelib2.Tube
|
local Tube = tubelib2.Tube
|
||||||
|
|
||||||
function Tube:fdir(player)
|
-- Check if node at given position is a tube node
|
||||||
local pitch = player:get_look_pitch()
|
-- If dir == nil then node_pos = pos
|
||||||
if pitch > 1.0 and self.valid_dirs[6] then -- up?
|
-- Function returns the new pos or nil
|
||||||
return 6
|
function Tube:primary_node(pos, dir)
|
||||||
elseif pitch < -1.0 and self.valid_dirs[5] then -- down?
|
local npos, node = self:get_node(pos, dir)
|
||||||
return 5
|
if self.primary_node_names[node.name] then
|
||||||
elseif not self.valid_dirs[1] then
|
return npos, node
|
||||||
return 6
|
|
||||||
else
|
|
||||||
return minetest.dir_to_facedir(player:get_look_dir()) + 1
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function Tube:get_player_data(placer, pointed_thing)
|
-- Check if node at given position is a secondary node
|
||||||
if placer and pointed_thing and pointed_thing.type == "node" then
|
-- If dir == nil then node_pos = pos
|
||||||
if placer:get_player_control().sneak then
|
-- Function returns the new pos or nil
|
||||||
return pointed_thing.under, self:fdir(placer)
|
function Tube:secondary_node(pos, dir)
|
||||||
else
|
local npos, node = self:get_node(pos, dir)
|
||||||
return nil, self:fdir(placer)
|
if self.secondary_node_names[node.name] then
|
||||||
end
|
return npos
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Return param2 and tube type ("A"/"S")
|
|
||||||
function Tube:encode_param2(dir1, dir2, num_conn)
|
|
||||||
if dir1 > dir2 then
|
|
||||||
dir1, dir2 = dir2, dir1
|
|
||||||
end
|
|
||||||
local param2, _type = unpack(DirToParam2[dir1 * 10 + dir2] or {0, "S"})
|
|
||||||
return (num_conn * 32) + param2, _type
|
|
||||||
end
|
|
||||||
|
|
||||||
-- Check if node has a connection on the given dir
|
-- Check if node has a connection on the given dir
|
||||||
function Tube:connected(pos, dir)
|
function Tube:connected(pos, dir)
|
||||||
local npos = vector.add(pos, Dir6dToVector[dir or 0])
|
local npos = vector.add(pos, Dir6dToVector[dir or 0])
|
||||||
@ -154,21 +164,6 @@ function Tube:connected(pos, dir)
|
|||||||
or self.secondary_node_names[node.name]
|
or self.secondary_node_names[node.name]
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Determine dirs via surrounding nodes
|
|
||||||
function Tube:determine_dir1_dir2_and_num_conn(pos)
|
|
||||||
local dirs = {}
|
|
||||||
for dir = 1, 6 do
|
|
||||||
if self:connected(pos, dir) then
|
|
||||||
dirs[#dirs+1] = dir
|
|
||||||
end
|
|
||||||
end
|
|
||||||
if #dirs == 1 then
|
|
||||||
return dirs[1], nil, 1
|
|
||||||
elseif #dirs == 2 then
|
|
||||||
return dirs[1], dirs[2], 2
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
-- Return dir1, dir2, num_conn
|
-- Return dir1, dir2, num_conn
|
||||||
function Tube:decode_param2(pos, param2)
|
function Tube:decode_param2(pos, param2)
|
||||||
local val = Param2ToDir[param2 % 32]
|
local val = Param2ToDir[param2 % 32]
|
||||||
@ -177,14 +172,6 @@ function Tube:decode_param2(pos, param2)
|
|||||||
local num_conn = math.floor(param2 / 32)
|
local num_conn = math.floor(param2 / 32)
|
||||||
return dir1, dir2, num_conn
|
return dir1, dir2, num_conn
|
||||||
end
|
end
|
||||||
-- determine dirs via surrounding nodes
|
|
||||||
return self:determine_dir1_dir2_and_num_conn(pos)
|
|
||||||
|
|
||||||
end
|
|
||||||
|
|
||||||
-- No connection to both sides
|
|
||||||
function Tube:first_placed_node(pos, param2)
|
|
||||||
return math.floor(param2 / 32) == 0
|
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Return node next to pos in direction 'dir'
|
-- Return node next to pos in direction 'dir'
|
||||||
@ -280,20 +267,6 @@ function Tube:determine_tube_dirs(pos, preferred_pos, fdir)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function Tube:determine_next_node(pos, dir)
|
|
||||||
local npos, node = self:get_node(pos, dir)
|
|
||||||
if self.primary_node_names[node.name] then
|
|
||||||
local d1,d2,num = self:decode_param2(npos, node.param2)
|
|
||||||
return npos, d1, d2, num
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
-- format and return given data as table
|
|
||||||
function Tube:tube_data_to_table(pos, dir1, dir2, num_tubes)
|
|
||||||
local param2, tube_type = self:encode_param2(dir1, dir2, num_tubes)
|
|
||||||
return pos, param2, tube_type, num_tubes
|
|
||||||
end
|
|
||||||
|
|
||||||
-- Determine a tube side without connection, increment the number of connections
|
-- Determine a tube side without connection, increment the number of connections
|
||||||
-- and return the new data to be able to update the node:
|
-- and return the new data to be able to update the node:
|
||||||
-- new_pos, dir1, dir2, num_connections (1, 2)
|
-- new_pos, dir1, dir2, num_connections (1, 2)
|
||||||
@ -354,15 +327,31 @@ function Tube:get_next_teleport_node(pos, dir)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function Tube:remove_tube(pos, sound)
|
function Tube:dbg_out()
|
||||||
local node = get_node_lvm(pos)
|
for pos1,item1 in pairs(self.connCache) do
|
||||||
if self.primary_node_names[node.name] then
|
for dir1,item2 in pairs(item1) do
|
||||||
minetest.sound_play({
|
print("pos1="..pos1..", dir1="..dir1..", pos2="..S(item2.pos2)..", dir2="..item2.dir2)
|
||||||
name=sound},{
|
end
|
||||||
gain=1,
|
|
||||||
max_hear_distance=5,
|
|
||||||
loop=false})
|
|
||||||
minetest.remove_node(pos)
|
|
||||||
return node, {}
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- Walk to the end of the tube line and return pos and outdir of both head tube nodes.
|
||||||
|
-- If no tube is available, return nil
|
||||||
|
function Tube:walk_tube_line(pos, dir)
|
||||||
|
local cnt = 0
|
||||||
|
if dir then
|
||||||
|
while cnt <= self.max_tube_length do
|
||||||
|
local new_pos, new_dir, num = get_next_tube(self, pos, dir)
|
||||||
|
if not new_dir then break end
|
||||||
|
if cnt > 0 and num ~= 2 then
|
||||||
|
repair_tube(self, new_pos, new_dir)
|
||||||
|
end
|
||||||
|
pos, dir = new_pos, new_dir
|
||||||
|
cnt = cnt + 1
|
||||||
|
end
|
||||||
|
if cnt > 0 then
|
||||||
|
return pos, dir, cnt
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return table.copy(pos), dir, 0
|
||||||
|
end
|
||||||
|
141
tube_api.lua
141
tube_api.lua
@ -13,7 +13,7 @@
|
|||||||
]]--
|
]]--
|
||||||
|
|
||||||
-- Version for compatibility checks, see readme.md/history
|
-- Version for compatibility checks, see readme.md/history
|
||||||
tubelib2.version = 0.4
|
tubelib2.version = 0.5
|
||||||
|
|
||||||
-- for lazy programmers
|
-- for lazy programmers
|
||||||
local S = function(pos) if pos then return minetest.pos_to_string(pos) end end
|
local S = function(pos) if pos then return minetest.pos_to_string(pos) end end
|
||||||
@ -34,11 +34,42 @@ local function Tbl(list)
|
|||||||
end
|
end
|
||||||
|
|
||||||
-- Tubelib2 Class
|
-- Tubelib2 Class
|
||||||
tubelib2.Tube = {}
|
|
||||||
local Tube = tubelib2.Tube
|
local Tube = tubelib2.Tube
|
||||||
local Turn180Deg = tubelib2.Turn180Deg
|
local Turn180Deg = tubelib2.Turn180Deg
|
||||||
|
local Dir6dToVector = tubelib2.Dir6dToVector
|
||||||
|
|
||||||
|
|
||||||
|
local function get_pos(pos, dir)
|
||||||
|
return vector.add(pos, Dir6dToVector[dir or 0])
|
||||||
|
end
|
||||||
|
|
||||||
|
local function update1(self, pos, dir)
|
||||||
|
local fpos,fdir = self:walk_tube_line(pos, dir)
|
||||||
|
-- Translate pos/dir pointing to the secondary node into
|
||||||
|
-- spos/sdir of the secondary node pointing to the tube.
|
||||||
|
local spos, sdir = get_pos(fpos,fdir), Turn180Deg[fdir]
|
||||||
|
self:del_from_cache(spos, sdir)
|
||||||
|
self:add_to_cache(pos, dir, spos, sdir)
|
||||||
|
self:add_to_cache(spos, sdir, pos, dir)
|
||||||
|
self:update_secondary_node(pos, dir, spos, sdir)
|
||||||
|
self:update_secondary_node(spos, sdir, pos, dir)
|
||||||
|
end
|
||||||
|
|
||||||
|
local function update2(self, pos1, dir1, pos2, dir2)
|
||||||
|
local fpos1,fdir1 = self:walk_tube_line(pos1, dir1)
|
||||||
|
local fpos2,fdir2 = self:walk_tube_line(pos2, dir2)
|
||||||
|
-- Translate fpos/fdir pointing to the secondary node into
|
||||||
|
-- spos/sdir of the secondary node pointing to the tube.
|
||||||
|
local spos1, sdir1 = get_pos(fpos1,fdir1), Turn180Deg[fdir1]
|
||||||
|
local spos2, sdir2 = get_pos(fpos2,fdir2), Turn180Deg[fdir2]
|
||||||
|
self:del_from_cache(spos1, sdir1)
|
||||||
|
self:del_from_cache(spos2, sdir2)
|
||||||
|
self:add_to_cache(spos1, sdir1, spos2, sdir2)
|
||||||
|
self:add_to_cache(spos2, sdir2, spos1, sdir1)
|
||||||
|
self:update_secondary_node(spos1, sdir1, spos2, sdir2)
|
||||||
|
self:update_secondary_node(spos2, sdir2, spos1, sdir1)
|
||||||
|
end
|
||||||
|
|
||||||
--
|
--
|
||||||
-- API Functions
|
-- API Functions
|
||||||
--
|
--
|
||||||
@ -52,6 +83,7 @@ function Tube:new(attr)
|
|||||||
show_infotext = attr.show_infotext or false,
|
show_infotext = attr.show_infotext or false,
|
||||||
clbk_after_place_tube = attr.after_place_tube,
|
clbk_after_place_tube = attr.after_place_tube,
|
||||||
pairingList = {}, -- teleporting nodes
|
pairingList = {}, -- teleporting nodes
|
||||||
|
connCache = {}, -- connection cache {pos1 = {dir1 = {pos2 = pos2, dir2 = dir2},...}
|
||||||
}
|
}
|
||||||
o.valid_dirs = Tbl(o.dirs_to_check)
|
o.valid_dirs = Tbl(o.dirs_to_check)
|
||||||
setmetatable(o, self)
|
setmetatable(o, self)
|
||||||
@ -72,16 +104,17 @@ function Tube:register_on_tube_update(update_secondary_node)
|
|||||||
self.clbk_update_secondary_node = update_secondary_node
|
self.clbk_update_secondary_node = update_secondary_node
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function Tube:get_pos(pos, dir)
|
||||||
|
return vector.add(pos, Dir6dToVector[dir or 0])
|
||||||
|
end
|
||||||
|
|
||||||
-- To be called after a secondary node is placed.
|
-- To be called after a secondary node is placed.
|
||||||
-- dirs is a list with valid dirs, like: {1,2,3,4}
|
-- dirs is a list with valid dirs, like: {1,2,3,4}
|
||||||
function Tube:after_place_node(pos, dirs)
|
function Tube:after_place_node(pos, dirs)
|
||||||
-- [s][f]----[n] x
|
-- [s][f]----[n] x
|
||||||
-- s..secondary, f..far, n..near, x..node to be placed
|
-- s..secondary, f..far, n..near, x..node to be placed
|
||||||
for _,dir in ipairs(self:update_after_place_node(pos, dirs)) do
|
for _,dir in ipairs(self:update_after_place_node(pos, dirs)) do
|
||||||
local fpos,fdir = self:repair_meta(pos, dir)
|
update1(self, pos, dir)
|
||||||
local npos, ndir = self:get_pos(pos, dir)
|
|
||||||
self:update_secondary_node(fpos,fdir, npos,ndir)
|
|
||||||
self:update_secondary_node(npos,ndir, fpos,fdir)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -90,14 +123,9 @@ end
|
|||||||
function Tube:after_place_tube(pos, placer, pointed_thing)
|
function Tube:after_place_tube(pos, placer, pointed_thing)
|
||||||
-- [s1][f1]----[n1] x [n2]-----[f2][s2]
|
-- [s1][f1]----[n1] x [n2]-----[f2][s2]
|
||||||
-- s..secondary, f..far, n..near, x..node to be placed
|
-- s..secondary, f..far, n..near, x..node to be placed
|
||||||
local res,dir1,dir2,cnt = self:update_after_place_tube(pos, placer, pointed_thing)
|
local res,dir1,dir2 = self:update_after_place_tube(pos, placer, pointed_thing)
|
||||||
if res and cnt > 0 then -- other nodes around?
|
if res then -- node placed?
|
||||||
local fpos1,fdir1 = self:del_meta(pos, dir1)
|
update2(self, pos, dir1, pos, dir2)
|
||||||
local fpos2,fdir2 = self:del_meta(pos, dir2)
|
|
||||||
self:add_meta(fpos1, fpos2,fdir2)
|
|
||||||
self:add_meta(fpos2, fpos1,fdir1)
|
|
||||||
self:update_secondary_node(fpos1,fdir1, fpos2,fdir2)
|
|
||||||
self:update_secondary_node(fpos2,fdir2, fpos1,fdir1)
|
|
||||||
end
|
end
|
||||||
return res
|
return res
|
||||||
end
|
end
|
||||||
@ -106,26 +134,27 @@ function Tube:after_dig_node(pos, dirs)
|
|||||||
-- [s][f]----[n] x
|
-- [s][f]----[n] x
|
||||||
-- s..secondary, f..far, n..near, x..node to be removed
|
-- s..secondary, f..far, n..near, x..node to be removed
|
||||||
for _,dir in ipairs(self:update_after_dig_node(pos, dirs)) do
|
for _,dir in ipairs(self:update_after_dig_node(pos, dirs)) do
|
||||||
local fpos,fdir = self:get_meta(pos, dir)
|
update1(self, pos, dir)
|
||||||
local npos,ndir = self:get_pos(pos, dir)
|
|
||||||
self:add_meta(npos, fpos,fdir)
|
|
||||||
self:add_meta(fpos, npos,ndir)
|
|
||||||
self:update_secondary_node(fpos,fdir, npos,ndir)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- To be called after a tube/primary node is removed.
|
-- To be called after a tube/primary node is removed.
|
||||||
function Tube:after_dig_tube(pos, oldnode, oldmetadata)
|
function Tube:after_dig_tube(pos, oldnode)
|
||||||
-- [s1][f1]----[n1] x [n2]-----[f2][s2]
|
-- [s1][f1]----[n1] x [n2]-----[f2][s2]
|
||||||
-- s..secondary, f..far, n..near, x..node to be removed
|
-- s..secondary, f..far, n..near, x..node to be removed
|
||||||
for _,dir in ipairs(self:update_after_dig_tube(pos, oldnode.param2)) do
|
|
||||||
local fpos,fdir = self:get_oldmeta(pos, dir, oldmetadata)
|
-- update tubes
|
||||||
local npos,ndir = self:get_pos(pos, dir)
|
local dir1, dir2 = self:update_after_dig_tube(pos, oldnode.param2)
|
||||||
self:add_meta(npos, fpos,fdir)
|
if dir1 then update1(self, pos, dir1) end
|
||||||
self:add_meta(fpos, npos,ndir)
|
if dir2 then update1(self, pos, dir2) end
|
||||||
self:update_secondary_node(fpos,fdir, npos,ndir)
|
|
||||||
end
|
-- Update secondary nodes, if right beside
|
||||||
self:update_secondary_nodes_after_dig_tube(pos)
|
dir1, dir2 = self:decode_param2(pos, oldnode.param2)
|
||||||
|
local npos1,ndir1 = get_pos(pos, dir1),Turn180Deg[dir1]
|
||||||
|
local npos2,ndir2 = get_pos(pos, dir2),Turn180Deg[dir2]
|
||||||
|
self:del_from_cache(npos1,ndir1)
|
||||||
|
self:update_secondary_node(npos1,ndir1)
|
||||||
|
self:update_secondary_node(npos2,ndir2)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
@ -134,38 +163,29 @@ end
|
|||||||
-- The returned pos is the destination position, dir
|
-- The returned pos is the destination position, dir
|
||||||
-- is the direction into the destination node.
|
-- is the direction into the destination node.
|
||||||
function Tube:get_connected_node_pos(pos, dir)
|
function Tube:get_connected_node_pos(pos, dir)
|
||||||
local fpos,fdir = self:repair_meta(pos, dir)
|
local key = S(pos)
|
||||||
local npos,ndir = self:get_pos(fpos,fdir)
|
if self.connCache[key] and self.connCache[key][dir] then
|
||||||
-- only one tube with wrong dir info?
|
local item = self.connCache[key][dir]
|
||||||
if vector.equals(pos, npos) then
|
return item.pos2, Turn180Deg[item.dir2]
|
||||||
fpos,fdir = self:del_meta(pos, dir)
|
end
|
||||||
npos,ndir = self:get_pos(fpos,fdir)
|
local fpos,fdir = self:walk_tube_line(pos, dir)
|
||||||
end
|
local spos = get_pos(fpos,fdir)
|
||||||
return npos, fdir
|
self:add_to_cache(pos, dir, spos, Turn180Deg[fdir])
|
||||||
|
self:add_to_cache(spos, Turn180Deg[fdir], pos, dir)
|
||||||
|
return spos, fdir
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
-- To be called from a repair tool in the case of a "WorldEdit" or with
|
|
||||||
-- legacy nodes corrupted tube line.
|
|
||||||
function Tube:tool_repair_tube(pos)
|
|
||||||
local res,dir1,dir2 = self:determine_next_node(pos)
|
|
||||||
if res then
|
|
||||||
local fpos1,fdir1,cnt1 = self:repair_tube_line(pos, dir1)
|
|
||||||
local fpos2,fdir2,cnt2 = self:repair_tube_line(pos, dir2)
|
|
||||||
self:add_meta(fpos1, fpos2,fdir2)
|
|
||||||
self:add_meta(fpos2, fpos1,fdir1)
|
|
||||||
self:update_secondary_node(fpos1,fdir1, fpos2,fdir2)
|
|
||||||
self:update_secondary_node(fpos2,fdir2, fpos1,fdir1)
|
|
||||||
return dir1, dir2, fpos1, fpos2, fdir1, fdir2, cnt1 or 0, cnt2 or 0
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
-- To be called from a repair tool in the case, tube nodes are "unbreakable".
|
-- To be called from a repair tool in the case, tube nodes are "unbreakable".
|
||||||
function Tube:tool_remove_tube(pos, sound)
|
function Tube:tool_remove_tube(pos, sound)
|
||||||
local oldnode, oldmeta = self:remove_tube(pos, sound)
|
local _,node = self:get_node(pos)
|
||||||
if oldnode then
|
if self.primary_node_names[node.name] then
|
||||||
self:after_dig_tube(pos, oldnode, oldmeta)
|
minetest.sound_play({name=sound},{
|
||||||
|
pos=pos,
|
||||||
|
gain=1,
|
||||||
|
max_hear_distance=5,
|
||||||
|
loop=false})
|
||||||
|
minetest.remove_node(pos)
|
||||||
|
self:after_dig_tube(pos, node)
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
return false
|
return false
|
||||||
@ -189,16 +209,9 @@ function Tube:pairing(pos, channel)
|
|||||||
if self.pairingList[channel] and pos ~= self.pairingList[channel] then
|
if self.pairingList[channel] and pos ~= self.pairingList[channel] then
|
||||||
-- store peer position on both nodes
|
-- store peer position on both nodes
|
||||||
local peer_pos = self.pairingList[channel]
|
local peer_pos = self.pairingList[channel]
|
||||||
|
|
||||||
local tube_dir1 = self:store_teleport_data(pos, peer_pos)
|
local tube_dir1 = self:store_teleport_data(pos, peer_pos)
|
||||||
local tube_dir2 = self:store_teleport_data(peer_pos, pos)
|
local tube_dir2 = self:store_teleport_data(peer_pos, pos)
|
||||||
local fpos1,fdir1 = self:repair_tube_line(pos, tube_dir1)
|
update2(self, pos, tube_dir1, peer_pos, tube_dir2)
|
||||||
local fpos2,fdir2 = self:repair_tube_line(peer_pos, tube_dir2)
|
|
||||||
self:add_meta(fpos1, fpos2,fdir2)
|
|
||||||
self:add_meta(fpos2, fpos1,fdir1)
|
|
||||||
self:update_secondary_node(fpos1,fdir1, fpos2,fdir2)
|
|
||||||
self:update_secondary_node(fpos2,fdir2, fpos1,fdir1)
|
|
||||||
|
|
||||||
self.pairingList[channel] = nil
|
self.pairingList[channel] = nil
|
||||||
return true
|
return true
|
||||||
else
|
else
|
||||||
|
@ -42,9 +42,9 @@ Tube:register_on_tube_update(function(node, pos, out_dir, peer_pos, peer_in_dir)
|
|||||||
print(S(pos).." to the "..sdir..": Not connected")
|
print(S(pos).." to the "..sdir..": Not connected")
|
||||||
elseif Tube:secondary_node(peer_pos) then
|
elseif Tube:secondary_node(peer_pos) then
|
||||||
local node = minetest.get_node(peer_pos)
|
local node = minetest.get_node(peer_pos)
|
||||||
print(S(pos).." to the "..sdir..": Connected with "..node.name)
|
print(S(pos).." to the "..sdir..": Connected with "..node.name.." at "..S(peer_pos).."/"..peer_in_dir)
|
||||||
else
|
else
|
||||||
print(S(pos).." to the "..sdir..": Connected with "..S(peer_pos))
|
print(S(pos).." to the "..sdir..": Connected with "..S(peer_pos).."/"..peer_in_dir)
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
@ -247,45 +247,12 @@ minetest.register_node("tubelib2:teleporter", {
|
|||||||
sounds = default.node_sound_glass_defaults(),
|
sounds = default.node_sound_glass_defaults(),
|
||||||
})
|
})
|
||||||
|
|
||||||
--local function read_param2(pos, player)
|
|
||||||
-- local node = minetest.get_node(pos)
|
|
||||||
-- local num = math.floor(node.param2/32)
|
|
||||||
-- local axis = math.floor(node.param2/4) % 8
|
|
||||||
-- local rot = node.param2 % 4
|
|
||||||
-- minetest.chat_send_player(player:get_player_name(), "[Tubelib2] param2 = "..node.param2.."/"..num.."/"..axis.."/"..rot)
|
|
||||||
--end
|
|
||||||
|
|
||||||
local function read_param2(pos, player)
|
local function read_param2(pos, player)
|
||||||
local node = minetest.get_node(pos)
|
local node = minetest.get_node(pos)
|
||||||
local dir1, dir2, num_tubes = Tube:decode_param2(pos, node.param2)
|
local dir1, dir2, num_tubes = Tube:decode_param2(pos, node.param2)
|
||||||
minetest.chat_send_player(player:get_player_name(), "[Tubelib2] pos="..S(pos)..", dir1="..dir1..", dir2="..dir2..", num_tubes="..num_tubes)
|
minetest.chat_send_player(player:get_player_name(), "[Tubelib2] pos="..S(pos)..", dir1="..dir1..", dir2="..dir2..", num_tubes="..num_tubes)
|
||||||
end
|
end
|
||||||
|
|
||||||
local function chat_message(dir, cnt, peer_pos, peer_dir)
|
|
||||||
local sdir = tubelib2.dir_to_string(dir)
|
|
||||||
if Tube:secondary_node(peer_pos, peer_dir) then
|
|
||||||
local npos, node = Tube:get_node(peer_pos, peer_dir)
|
|
||||||
return "[Tubelib2] To the "..sdir..": "..cnt.." tube nodes to "..node.name.." at "..S(npos)
|
|
||||||
else
|
|
||||||
return "[Tubelib2] To the "..sdir..": "..cnt.." tube nodes to "..S(peer_pos)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
local function repair_tubes(itemstack, placer, pointed_thing)
|
|
||||||
if pointed_thing.type == "node" then
|
|
||||||
local pos = pointed_thing.under
|
|
||||||
local t = minetest.get_us_time()
|
|
||||||
local dir1, dir2, fpos1, fpos2, fdir1, fdir2, cnt1, cnt2 =
|
|
||||||
Tube:tool_repair_tube(pos, placer, pointed_thing)
|
|
||||||
t = minetest.get_us_time() - t
|
|
||||||
print("time", t)
|
|
||||||
if fpos1 and fpos2 then
|
|
||||||
minetest.chat_send_player(placer:get_player_name(), chat_message(dir1, cnt1, fpos1, fdir1))
|
|
||||||
minetest.chat_send_player(placer:get_player_name(), chat_message(dir2, cnt2, fpos2, fdir2))
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
local function remove_tube(itemstack, placer, pointed_thing)
|
local function remove_tube(itemstack, placer, pointed_thing)
|
||||||
if pointed_thing.type == "node" then
|
if pointed_thing.type == "node" then
|
||||||
local pos = pointed_thing.under
|
local pos = pointed_thing.under
|
||||||
@ -303,6 +270,31 @@ local function remove_tube(itemstack, placer, pointed_thing)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local function walk(itemstack, placer, pointed_thing)
|
||||||
|
if pointed_thing.type == "node" then
|
||||||
|
local pos = pointed_thing.under
|
||||||
|
local dir = (minetest.dir_to_facedir(placer:get_look_dir()) % 4) + 1
|
||||||
|
local t = minetest.get_us_time()
|
||||||
|
local pos1, outdir1, pos2, outdir2, cnt = Tube:walk(pos, dir)
|
||||||
|
t = minetest.get_us_time() - t
|
||||||
|
print("time", t)
|
||||||
|
if pos1 then
|
||||||
|
local s = "[Tubelib2] pos1="..S(pos1)..", outdir1="..outdir1..", pos2="..S(pos2)..", outdir2="..outdir2..", cnt="..cnt
|
||||||
|
minetest.chat_send_player(placer:get_player_name(), s)
|
||||||
|
end
|
||||||
|
else
|
||||||
|
local dir = (minetest.dir_to_facedir(placer:get_look_dir()) % 4) + 1
|
||||||
|
minetest.chat_send_player(placer:get_player_name(),
|
||||||
|
"[Tool Help] dir="..dir.."\n"..
|
||||||
|
" left: remove node\n"..
|
||||||
|
" right: repair tube line\n")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
local function debug(itemstack, placer, pointed_thing)
|
||||||
|
Tube:dbg_out()
|
||||||
|
end
|
||||||
|
|
||||||
-- Tool for tube workers to crack a protected tube line
|
-- Tool for tube workers to crack a protected tube line
|
||||||
minetest.register_node("tubelib2:tool", {
|
minetest.register_node("tubelib2:tool", {
|
||||||
description = "Tubelib2 Tool",
|
description = "Tubelib2 Tool",
|
||||||
@ -311,7 +303,7 @@ minetest.register_node("tubelib2:tool", {
|
|||||||
use_texture_alpha = true,
|
use_texture_alpha = true,
|
||||||
groups = {cracky=1, book=1},
|
groups = {cracky=1, book=1},
|
||||||
on_use = remove_tube,
|
on_use = remove_tube,
|
||||||
on_place = repair_tubes,
|
on_place = debug,
|
||||||
node_placement_prediction = "",
|
node_placement_prediction = "",
|
||||||
stack_max = 1,
|
stack_max = 1,
|
||||||
})
|
})
|
||||||
|
Loading…
Reference in New Issue
Block a user