aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPerttu Ahola <celeron55@gmail.com>2010-11-27 17:18:34 +0200
committerPerttu Ahola <celeron55@gmail.com>2010-11-27 17:18:34 +0200
commit24c4b7c68d283a4d1de72a3eb68f1268f1fe34e3 (patch)
treec65ee918cc55d7a631aa312a24cc34bb8dea47b4
parent4e249fb3fbf75f0359758760d88e22aa5b14533c (diff)
downloadminetest-24c4b7c68d283a4d1de72a3eb68f1268f1fe34e3.tar.gz
minetest-24c4b7c68d283a4d1de72a3eb68f1268f1fe34e3.tar.bz2
minetest-24c4b7c68d283a4d1de72a3eb68f1268f1fe34e3.zip
Working version before block send priorization update
-rw-r--r--doc/README.txt58
-rw-r--r--doc/gpl-2.0.txt339
-rw-r--r--minetest.conf.example5
-rw-r--r--src/client.cpp31
-rw-r--r--src/client.h2
-rw-r--r--src/clientserver.h42
-rw-r--r--src/constants.h23
-rw-r--r--src/debug.h57
-rw-r--r--src/main.cpp112
-rw-r--r--src/main.h5
-rw-r--r--src/map.cpp20
-rw-r--r--src/map.h23
-rw-r--r--src/mapblock.h5
-rw-r--r--src/mapblockobject.h6
-rw-r--r--src/server.cpp135
-rw-r--r--src/server.h43
-rw-r--r--src/utility.h10
17 files changed, 716 insertions, 200 deletions
diff --git a/doc/README.txt b/doc/README.txt
index ff07fc4a3..340d8f5f3 100644
--- a/doc/README.txt
+++ b/doc/README.txt
@@ -1,14 +1,6 @@
Minetest-c55
---------------
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
-OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
-THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
-FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
-IN THE SOFTWARE.
-
Copyright (c) 2010 Perttu Ahola <celeron55@gmail.com>
An InfiniMiner/Minecraft inspired game.
@@ -16,9 +8,13 @@ An InfiniMiner/Minecraft inspired game.
This is a development version:
- Don't expect it to work as well as a finished game will.
- Please report any bugs to me. That way I can fix them to the next release.
+ - debug.txt is very useful when the game crashes.
-Server information:
-- I usually have a server running at celer.oni.biz on port 30000
+Public servers:
+ kray.dy.fi :30000 (friend's server - usually in creative mode)
+ celer.oni.biz :30000 (main development server)
+- Both of these have very limited bandwidth and the game will become laggy
+ with 4-5 players.
- If you want to run a server, I can list you on my website and in here.
Features, as of now:
@@ -35,8 +31,9 @@ Controls:
- R: Toggle full view range
Configuration file:
-- Can be passed as parameter to the executable.
-- If not given as parameter, these are checked, in order:
+- An optional configuration file can be used. See minetest.conf.example.
+- Path to file can be passed as a parameter to the executable.
+- If not given as a parameter, these are checked, in order:
../minetest.conf
../../minetest.conf
@@ -50,14 +47,35 @@ Running on GNU/Linux:
LD_LIBRARY_PATH=. ./fasttest
- If it doesn't work, use wine. I aim at 100% compatibility with wine.
-COPYING (License of Minetest-c55):
-- This version of the game is FREEWARE.
-- You can play this version of the game without charge.
-- You can redistribute this version of the game without charge, only with
- these same license terms you are reading now, and provided that you give
- proper information about who has made the game (me) and where to get the
- original copy and new versions (http://celer.oni.biz/~celeron55/minetest).
-- You are not allowed to sell this game for a price.
+Compiling on GNU/Linux:
+- You need:
+* Irrlicht:
+ http://downloads.sourceforge.net/irrlicht/irrlicht-1.7.2.zip
+* JThread:
+ http://research.edm.uhasselt.be/~jori/page/index.php?n=CS.Jthread
+- Neither of which can probably be found from your distro's repository.
+- Compiling each of them should be fairly unproblematic, though.
+
+
+License of Minetest-c55
+-----------------------
+
+Minetest-c55
+Copyright (C) 2010 celeron55, Perttu Ahola <celeron55@gmail.com>
+
+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.,
+51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
Irrlicht
diff --git a/doc/gpl-2.0.txt b/doc/gpl-2.0.txt
new file mode 100644
index 000000000..d159169d1
--- /dev/null
+++ b/doc/gpl-2.0.txt
@@ -0,0 +1,339 @@
+ GNU GENERAL PUBLIC LICENSE
+ Version 2, June 1991
+
+ Copyright (C) 1989, 1991 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.
+
+ 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 Lesser 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.
+
+ GNU GENERAL PUBLIC LICENSE
+ 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
+
+ How to Apply These Terms to Your New Programs
+
+ If you develop a new program, and you want it to be of the greatest
+possible use to the public, the best way to achieve this is to make it
+free software which everyone can redistribute and change under these terms.
+
+ To do so, attach the following notices to the program. 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 program's name and a brief idea of what it does.>
+ Copyright (C) <year> <name of author>
+
+ 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.,
+ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+
+Also add information on how to contact you by electronic and paper mail.
+
+If the program is interactive, make it output a short notice like this
+when it starts in an interactive mode:
+
+ Gnomovision version 69, Copyright (C) year name of author
+ Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
+ This is free software, and you are welcome to redistribute it
+ under certain conditions; type `show c' for details.
+
+The hypothetical commands `show w' and `show c' should show the appropriate
+parts of the General Public License. Of course, the commands you use may
+be called something other than `show w' and `show c'; they could even be
+mouse-clicks or menu items--whatever suits your program.
+
+You should also get your employer (if you work as a programmer) or your
+school, if any, to sign a "copyright disclaimer" for the program, if
+necessary. Here is a sample; alter the names:
+
+ Yoyodyne, Inc., hereby disclaims all copyright interest in the program
+ `Gnomovision' (which makes passes at compilers) written by James Hacker.
+
+ <signature of Ty Coon>, 1 April 1989
+ Ty Coon, President of Vice
+
+This General Public License does not permit incorporating your program into
+proprietary programs. If your program is a subroutine library, you may
+consider it more useful to permit linking proprietary applications with the
+library. If this is what you want to do, use the GNU Lesser General
+Public License instead of this License.
diff --git a/minetest.conf.example b/minetest.conf.example
index 3dd4a1c5b..172032f40 100644
--- a/minetest.conf.example
+++ b/minetest.conf.example
@@ -37,8 +37,11 @@ mapgen_heightmap_blocksize = 64
mapgen_height_randmax = constant 70.0
mapgen_height_randfactor = constant 0.6
mapgen_height_base = linear 0 80 0
-mapgen_plants_amount = constant 1.0
+mapgen_plants_amount = 1.0
+# Set to true to enable creative mode (unlimited inventory)
creative_mode = false
+# Player and object positions are sent at intervals specified by this
+objectdata_inverval = 0.2
diff --git a/src/client.cpp b/src/client.cpp
index ee3269974..a4f0ffb07 100644
--- a/src/client.cpp
+++ b/src/client.cpp
@@ -14,10 +14,6 @@
#define sleep_ms(x) usleep(x*1000)
#endif
-/*
- FIXME: This thread can access the environment at any time
-*/
-
void * ClientUpdateThread::Thread()
{
ThreadStarted();
@@ -144,6 +140,22 @@ void Client::step(float dtime)
m_con.RunTimeouts(dtime);
}
+ /*
+ Packet counter
+ */
+ {
+ static float counter = -0.001;
+ counter -= dtime;
+ if(counter <= 0.0)
+ {
+ counter = 10.0;
+
+ dout_client<<"Client packetcounter:"<<std::endl;
+ m_packetcounter.print(dout_client);
+ m_packetcounter.clear();
+ }
+ }
+
{
/*
Delete unused sectors
@@ -171,7 +183,9 @@ void Client::step(float dtime)
if(num > 0)
{
- dstream<<DTIME<<"Client: Deleted blocks of "<<num
+ /*dstream<<DTIME<<"Client: Deleted blocks of "<<num
+ <<" unused sectors"<<std::endl;*/
+ dstream<<DTIME<<"Client: Deleted "<<num
<<" unused sectors"<<std::endl;
/*
@@ -433,11 +447,18 @@ void Client::Receive()
void Client::ProcessData(u8 *data, u32 datasize, u16 sender_peer_id)
{
DSTACK(__FUNCTION_NAME);
+
// Ignore packets that don't even fit a command
if(datasize < 2)
+ {
+ m_packetcounter.add(60000);
return;
+ }
ToClientCommand command = (ToClientCommand)readU16(&data[0]);
+
+ //dstream<<"Client: received command="<<command<<std::endl;
+ m_packetcounter.add((u16)command);
/*
If this check is removed, be sure to change the queue
diff --git a/src/client.h b/src/client.h
index 60c57927b..92375974a 100644
--- a/src/client.h
+++ b/src/client.h
@@ -266,6 +266,8 @@ private:
bool m_inventory_updated;
core::map<v3s16, bool> m_active_blocks;
+
+ PacketCounter m_packetcounter;
};
#endif
diff --git a/src/clientserver.h b/src/clientserver.h
index 802069216..2a80c34df 100644
--- a/src/clientserver.h
+++ b/src/clientserver.h
@@ -5,7 +5,7 @@
enum ToClientCommand
{
- TOCLIENT_INIT=0x10,
+ TOCLIENT_INIT = 0x10,
/*
Server's reply to TOSERVER_INIT.
Sent second after connected.
@@ -15,11 +15,11 @@ enum ToClientCommand
[3] v3s16 player's position + v3f(0,BS/2,0) floatToInt'd
*/
- TOCLIENT_BLOCKDATA=0x20, //TODO: Multiple blocks
- TOCLIENT_ADDNODE,
- TOCLIENT_REMOVENODE,
+ TOCLIENT_BLOCKDATA = 0x20, //TODO: Multiple blocks
+ TOCLIENT_ADDNODE = 0x21,
+ TOCLIENT_REMOVENODE = 0x22,
- TOCLIENT_PLAYERPOS,
+ TOCLIENT_PLAYERPOS = 0x23,
/*
[0] u16 command
// Followed by an arbitary number of these:
@@ -31,7 +31,7 @@ enum ToClientCommand
[N+2+12+12+4] s32 yaw*100
*/
- TOCLIENT_PLAYERINFO,
+ TOCLIENT_PLAYERINFO = 0x24,
/*
[0] u16 command
// Followed by an arbitary number of these:
@@ -40,22 +40,22 @@ enum ToClientCommand
[N] char[20] name
*/
- TOCLIENT_OPT_BLOCK_NOT_FOUND, // Not used
+ TOCLIENT_OPT_BLOCK_NOT_FOUND = 0x25, // Not used
- TOCLIENT_SECTORMETA,
+ TOCLIENT_SECTORMETA = 0x26, // Not used
/*
[0] u16 command
[2] u8 sector count
[3...] v2s16 pos + sector metadata
*/
- TOCLIENT_INVENTORY,
+ TOCLIENT_INVENTORY = 0x27,
/*
[0] u16 command
[2] serialized inventory
*/
- TOCLIENT_OBJECTDATA,
+ TOCLIENT_OBJECTDATA = 0x28,
/*
Sent as unreliable.
@@ -84,7 +84,7 @@ enum ToServerCommand
[3] u8[20] player_name
*/
- TOSERVER_INIT2,
+ TOSERVER_INIT2 = 0x11,
/*
Sent as an ACK for TOCLIENT_INIT.
After this, the server can send data.
@@ -93,10 +93,10 @@ enum ToServerCommand
*/
TOSERVER_GETBLOCK=0x20, // Not used
- TOSERVER_ADDNODE, // Not used
- TOSERVER_REMOVENODE, // deprecated
+ TOSERVER_ADDNODE = 0x21, // Not used
+ TOSERVER_REMOVENODE = 0x22, // deprecated
- TOSERVER_PLAYERPOS,
+ TOSERVER_PLAYERPOS = 0x23,
/*
[0] u16 command
[2] v3s32 position*100
@@ -105,7 +105,7 @@ enum ToServerCommand
[2+12+12+4] s32 yaw*100
*/
- TOSERVER_GOTBLOCKS,
+ TOSERVER_GOTBLOCKS = 0x24,
/*
[0] u16 command
[2] u8 count
@@ -114,7 +114,7 @@ enum ToServerCommand
...
*/
- TOSERVER_DELETEDBLOCKS,
+ TOSERVER_DELETEDBLOCKS = 0x25,
/*
[0] u16 command
[2] u8 count
@@ -123,14 +123,14 @@ enum ToServerCommand
...
*/
- TOSERVER_ADDNODE_FROM_INVENTORY, // deprecated
+ TOSERVER_ADDNODE_FROM_INVENTORY = 0x26, // deprecated
/*
[0] u16 command
[2] v3s16 pos
[8] u16 i
*/
- TOSERVER_CLICK_OBJECT,
+ TOSERVER_CLICK_OBJECT = 0x27,
/*
length: 13
[0] u16 command
@@ -140,7 +140,7 @@ enum ToServerCommand
[11] u16 item
*/
- TOSERVER_CLICK_GROUND,
+ TOSERVER_CLICK_GROUND = 0x28,
/*
length: 17
[0] u16 command
@@ -150,14 +150,14 @@ enum ToServerCommand
[15] u16 item
*/
- TOSERVER_RELEASE,
+ TOSERVER_RELEASE = 0x29,
/*
length: 3
[0] u16 command
[2] u8 button
*/
- TOSERVER_SIGNTEXT,
+ TOSERVER_SIGNTEXT = 0x30,
/*
u16 command
v3s16 blockpos
diff --git a/src/constants.h b/src/constants.h
index e91ded0eb..ee08e0ed4 100644
--- a/src/constants.h
+++ b/src/constants.h
@@ -23,9 +23,6 @@
#define SERVERMAP_DELETE_UNUSED_SECTORS_TIMEOUT (60*10)
#define SERVER_MAP_SAVE_INTERVAL (60)
-//#define SERVERMAP_DELETE_UNUSED_SECTORS_TIMEOUT (5)
-//#define SERVER_MAP_SAVE_INTERVAL (5)
-
#define FOV_ANGLE (PI/2.5)
// The absolute working limit is (2^15 - viewing_range).
@@ -44,29 +41,29 @@
#define FPS_DEFAULT_WANTED 30
#define FPS_DEFAULT_MAX 60
-#define FORCEDFETCH_RANGE 80
-
#define HEIGHTMAP_RANGE_NODES 300
-// The freetime ratio is dynamically kept high enough to make this
-// dtime jitter possible
-// Allow 50% = 0.1
-/*#define DTIME_JITTER_MAX_FRACTION 0.5
-#define FREETIME_RATIO_MIN 0.05
-#define FREETIME_RATIO_MAX 0.4*/
-
//#define FREETIME_RATIO 0.2
#define FREETIME_RATIO 0.15
+// Sectors are split to SECTOR_HEIGHTMAP_SPLIT^2 heightmaps
#define SECTOR_HEIGHTMAP_SPLIT 2
#define PLAYER_INVENTORY_SIZE (8*4)
#define SIGN_TEXT_MAX_LENGTH 50
-#define ACTIVE_OBJECT_D_BLOCKS 2
+// The distance of how far objects will be sent to client
+//#define ACTIVE_OBJECT_D_BLOCKS 2
+// Wether to catch all std::exceptions
#define CATCH_UNJANDLED_EXCEPTIONS 1
+/*
+ Collecting active blocks is stopped after object data
+ size reaches this
+*/
+#define MAX_OBJECTDATA_SIZE 450
+
#endif
diff --git a/src/debug.h b/src/debug.h
index 014456c0a..1780025a3 100644
--- a/src/debug.h
+++ b/src/debug.h
@@ -3,7 +3,7 @@
*/
/*
- Debug stack and assertion
+ Debug stuff
*/
#ifndef DEBUG_HEADER
@@ -172,5 +172,58 @@ private:
DEBUG_STACK_TEXT_SIZE, __VA_ARGS__);\
DebugStacker __debug_stacker(__buf);
-#endif
+/*
+ Packet counter
+*/
+
+class PacketCounter
+{
+public:
+ PacketCounter()
+ {
+ }
+
+ void add(u16 command)
+ {
+ core::map<u16, u16>::Node *n = m_packets.find(command);
+ if(n == NULL)
+ {
+ m_packets[command] = 1;
+ }
+ else
+ {
+ n->setValue(n->getValue()+1);
+ }
+ }
+
+ void clear()
+ {
+ for(core::map<u16, u16>::Iterator
+ i = m_packets.getIterator();
+ i.atEnd() == false; i++)
+ {
+ i.getNode()->setValue(0);
+ }
+ }
+
+ void print(std::ostream &o)
+ {
+ for(core::map<u16, u16>::Iterator
+ i = m_packets.getIterator();
+ i.atEnd() == false; i++)
+ {
+ o<<"cmd "<<i.getNode()->getKey()
+ <<" count "<<i.getNode()->getValue()
+ <<std::endl;
+ }
+ }
+
+private:
+ // command, count
+ core::map<u16, u16> m_packets;
+};
+
+
+#endif // DEBUG_HEADER
+
diff --git a/src/main.cpp b/src/main.cpp
index 971e0eac3..258119c4a 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -1,7 +1,24 @@
/*
-(c) 2010 Perttu Ahola <celeron55@gmail.com>
+Minetest-c55
+Copyright (C) 2010 celeron55, Perttu Ahola <celeron55@gmail.com>
+
+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.,
+51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+*/
-Minetest
+/*
+=============================== NOTES ==============================
NOTE: VBO cannot be turned on for fast-changing stuff because there
is an apparanet memory leak in irrlicht when using it
@@ -137,43 +154,39 @@ TODO: Make fetching sector's blocks more efficient when rendering
TODO: Make the video backend selectable
-TODO: A timestamp to blocks
-
-TODO: Client side:
- - The server sends all active objects of the active blocks
- at constant intervals. They should fit in a few packets.
- - The client keeps track of what blocks at the moment are
- having active objects in them.
- - All blocks going in and out of the active buffer are recorded.
- - For outgoing blocks, objects are removed from the blocks
- and from the scene
- - For incoming blocks, objects are added to the blocks and
- to the scene.
-
-TODO: Server side:
+Block object server side:
- A "near blocks" buffer, in which some nearby blocks are stored.
- For all blocks in the buffer, objects are stepped(). This
means they are active.
- - All blocks going in and out of the buffer are recorded.
- - For outgoing blocks, a timestamp is written.
- - For incoming blocks, the time difference is calculated and
+ - TODO All blocks going in and out of the buffer are recorded.
+ - TODO For outgoing blocks, a timestamp is written.
+ - TODO For incoming blocks, the time difference is calculated and
objects are stepped according to it.
+TODO: A timestamp to blocks
TODO: Add config parameters for server's sending and generating distance
-TODO: Make amount of trees and other plants configurable
- - Save to a metafile
-
TODO: Copy the text of the last picked sign to inventory in creative
mode
TODO: Untie client network operations from framerate
-TODO: Make a copy of close-range environment on client for showing
+SUGG: Make a copy of close-range environment on client for showing
on screen, with minimal mutexes to slow the main loop down
-TODO: Make a PACKET_COMBINED which contains many subpackets. Utilize
+SUGG: Make a PACKET_COMBINED which contains many subpackets. Utilize
it by sending more stuff in a single packet.
+ - Add a packet queue to RemoteClient, from which packets will be
+ combined with object data packets
+ - This is not exactly trivial: the object data packets are
+ sometimes very big by themselves
+
+SUGG: Split MapBlockObject serialization to to-client and to-disk
+ - This will allow saving ages of rats on disk but not sending
+ them to clients
+
+TODO: Fix the long-lived Server Block Emerge Jam bug
+ - Is it related to the client deleting blocks?
Doing now:
======================================================================
@@ -261,10 +274,6 @@ video::SMaterial g_materials[MATERIALS_COUNT];
// All range-related stuff below is locked behind this
JMutex g_range_mutex;
-// Blocks are generated in this range from the player
-// This is limited vertically to half by Client::fetchBlocks()
-s16 g_forcedfetch_range_nodes = FORCEDFETCH_RANGE;
-
// Blocks are viewed in this range from the player
s16 g_viewing_range_nodes = 60;
@@ -305,7 +314,10 @@ float g_client_delete_unused_sectors_timeout = 1200;
// Server stuff
bool g_creative_mode = false;
-MapgenParams g_mapgen_params;
+HMParams g_hm_params;
+MapParams g_map_params;
+float g_objectdata_interval = 0.2;
+u16 g_active_object_range = 2;
/*
Random stuff
@@ -395,21 +407,11 @@ bool parseConfigObject(std::istream &is)
}
else if(name == "viewing_range_nodes_max")
{
- s32 v = atoi(value.c_str());
- if(v < 0)
- v = 0;
- if(v > 32767)
- v = 32767;
- g_viewing_range_nodes_max = v;
+ g_viewing_range_nodes_max = stoi(value, 0, 32767);
}
else if(name == "viewing_range_nodes_min")
{
- s32 v = atoi(value.c_str());
- if(v < 0)
- v = 0;
- if(v > 32767)
- v = 32767;
- g_viewing_range_nodes_min = v;
+ g_viewing_range_nodes_min = stoi(value, 0, 32767);
}
else if(name=="screenW")
g_screenW = value;
@@ -439,19 +441,29 @@ bool parseConfigObject(std::istream &is)
{
s32 d = atoi(value.c_str());
if(d > 0 && (d & (d-1)) == 0)
- g_mapgen_params.heightmap_blocksize = d;
+ g_hm_params.heightmap_blocksize = d;
else
dstream<<"Invalid value in config file: \""
<<line<<"\""<<std::endl;
}
else if(name == "mapgen_height_randmax")
- g_mapgen_params.height_randmax = value;
+ g_hm_params.height_randmax = value;
else if(name == "mapgen_height_randfactor")
- g_mapgen_params.height_randfactor = value;
+ g_hm_params.height_randfactor = value;
else if(name == "mapgen_height_base")
- g_mapgen_params.height_base = value;
+ g_hm_params.height_base = value;
else if(name == "mapgen_plants_amount")
- g_mapgen_params.plants_amount = value;
+ {
+ std::istringstream vis(value);
+ vis>>g_map_params.plants_amount;
+ }
+ else if(name == "objectdata_inverval")
+ {
+ std::istringstream vis(value);
+ vis>>g_objectdata_interval;
+ }
+ else if(name == "active_object_range")
+ g_active_object_range = stoi(value, 0, 65535);
else
{
@@ -1161,7 +1173,9 @@ int main(int argc, char *argv[])
std::cout<<"========================"<<std::endl;
std::cout<<std::endl;
- Server server("../map", g_creative_mode, g_mapgen_params);
+ Server server("../map", g_creative_mode, g_hm_params,
+ g_map_params, g_objectdata_interval,
+ g_active_object_range);
server.start(port);
for(;;)
@@ -1429,7 +1443,9 @@ int main(int argc, char *argv[])
*/
SharedPtr<Server> server;
if(hosting){
- server = new Server("../map", g_creative_mode, g_mapgen_params);
+ server = new Server("../map", g_creative_mode, g_hm_params,
+ g_map_params, g_objectdata_interval,
+ g_active_object_range);
server->start(port);
}
diff --git a/src/main.h b/src/main.h
index 3118e5f52..59ef0ff03 100644
--- a/src/main.h
+++ b/src/main.h
@@ -12,7 +12,6 @@ extern std::string getTimestamp();
#include <jmutex.h>
extern JMutex g_range_mutex;
-extern s16 g_forcedfetch_range_nodes;
extern s16 g_viewing_range_nodes;
//extern s16 g_actual_viewing_range_nodes;
extern bool g_viewing_range_all;
@@ -42,9 +41,5 @@ extern video::SMaterial g_materials[MATERIALS_COUNT];
extern IrrlichtDevice *g_device;
-// Settings
-#include "map.h"
-extern MapgenParams g_mapgen_params;
-
#endif
diff --git a/src/map.cpp b/src/map.cpp
index c69c3f248..35bf8bb40 100644
--- a/src/map.cpp
+++ b/src/map.cpp
@@ -1160,7 +1160,7 @@ void Map::PrintInfo(std::ostream &out)
ServerMap
*/
-ServerMap::ServerMap(std::string savedir, MapgenParams params):
+ServerMap::ServerMap(std::string savedir, HMParams hmp, MapParams mp):
Map(dout_server),
m_heightmap(NULL)
{
@@ -1212,15 +1212,19 @@ ServerMap::ServerMap(std::string savedir, MapgenParams params):
}
dstream<<DTIME<<"Initializing new map."<<std::endl;
-
+
+ // Create master heightmap
ValueGenerator *maxgen =
- ValueGenerator::deSerialize(params.height_randmax);
+ ValueGenerator::deSerialize(hmp.height_randmax);
ValueGenerator *factorgen =
- ValueGenerator::deSerialize(params.height_randfactor);
+ ValueGenerator::deSerialize(hmp.height_randfactor);
ValueGenerator *basegen =
- ValueGenerator::deSerialize(params.height_base);
+ ValueGenerator::deSerialize(hmp.height_base);
m_heightmap = new UnlimitedHeightmap
- (params.heightmap_blocksize, maxgen, factorgen, basegen);
+ (hmp.heightmap_blocksize, maxgen, factorgen, basegen);
+
+ // Set map parameters
+ m_params = mp;
// Create zero sector
emergeSector(v2s16(0,0));
@@ -1386,7 +1390,7 @@ MapSector * ServerMap::emergeSector(v2s16 p2d)
{
// Avgslope is the derivative of a hill
float t = avgslope * avgslope;
- float a = MAP_BLOCKSIZE * 2;
+ float a = MAP_BLOCKSIZE * 2 * m_params.plants_amount;
u32 tree_max;
if(t > 0.03)
tree_max = a / (t/0.03);
@@ -1408,7 +1412,7 @@ MapSector * ServerMap::emergeSector(v2s16 p2d)
{
// Pitness usually goes at around -0.5...0.5
u32 bush_max = 0;
- u32 a = MAP_BLOCKSIZE * 3;
+ u32 a = MAP_BLOCKSIZE * 3.0 * m_params.plants_amount;
if(pitness > 0)
bush_max = (pitness*a*4);
if(bush_max > a)
diff --git a/src/map.h b/src/map.h
index ca3b0086b..482ab2ac7 100644
--- a/src/map.h
+++ b/src/map.h
@@ -242,21 +242,32 @@ public:
virtual void PrintInfo(std::ostream &out);
};
-struct MapgenParams
+// Master heightmap parameters
+struct HMParams
{
- MapgenParams()
+ HMParams()
{
heightmap_blocksize = 64;
height_randmax = "constant 70.0";
height_randfactor = "constant 0.6";
height_base = "linear 0 80 0";
- plants_amount = "1.0";
}
s16 heightmap_blocksize;
std::string height_randmax;
std::string height_randfactor;
std::string height_base;
- std::string plants_amount;
+};
+
+// Map parameters
+struct MapParams
+{
+ MapParams()
+ {
+ plants_amount = 1.0;
+ //max_objects_in_block = 30;
+ }
+ float plants_amount;
+ //u16 max_objects_in_block;
};
class ServerMap : public Map
@@ -265,7 +276,7 @@ public:
/*
savedir: directory to which map data should be saved
*/
- ServerMap(std::string savedir, MapgenParams params);
+ ServerMap(std::string savedir, HMParams hmp, MapParams mp);
~ServerMap();
s32 mapType() const
@@ -346,6 +357,8 @@ public:
private:
UnlimitedHeightmap *m_heightmap;
+ MapParams m_params;
+
std::string m_savedir;
bool m_map_saving_enabled;
};
diff --git a/src/mapblock.h b/src/mapblock.h
index 9fcfa0793..60f78b6ff 100644
--- a/src/mapblock.h
+++ b/src/mapblock.h
@@ -352,6 +352,11 @@ public:
m_objects.getObjects(origin, max_d, dest);
}
+ s32 getObjectCount()
+ {
+ return m_objects.getCount();
+ }
+
private:
/*
diff --git a/src/mapblockobject.h b/src/mapblockobject.h
index 1939cc896..15409bbd7 100644
--- a/src/mapblockobject.h
+++ b/src/mapblockobject.h
@@ -879,6 +879,12 @@ public:
// origin is relative to block
void getObjects(v3f origin, f32 max_d,
core::array<DistanceSortedObject> &dest);
+
+ // Number of objects
+ s32 getCount()
+ {
+ return m_objects.size();
+ }
private:
JMutex m_mutex;
diff --git a/src/server.cpp b/src/server.cpp
index a5f55ab5d..8969bdedd 100644
--- a/src/server.cpp
+++ b/src/server.cpp
@@ -284,56 +284,8 @@ void RemoteClient::SendBlocks(Server *server, float dtime)
v3s16 center = getNodeBlockPos(center_nodepos);
/*
- Find out what block the player is going to next and set
- center to it.
-
- Don't react to speeds under the initial value of highest_speed
- */
- /*f32 highest_speed = 0.1 * BS;
- v3s16 dir(0,0,0);
- if(abs(playerspeed.X) > highest_speed)
- {
- highest_speed = playerspeed.X;
- if(playerspeed.X > 0)
- dir = v3s16(1,0,0);
- else
- dir = v3s16(-1,0,0);
- }
- if(abs(playerspeed.Y) > highest_speed)
- {
- highest_speed = playerspeed.Y;
- if(playerspeed.Y > 0)
- dir = v3s16(0,1,0);
- else
- dir = v3s16(0,-1,0);
- }
- if(abs(playerspeed.Z) > highest_speed)
- {
- highest_speed = playerspeed.Z;
- if(playerspeed.Z > 0)
- dir = v3s16(0,0,1);
- else
- dir = v3s16(0,0,-1);
- }
-
- center += dir;*/
-
- /*
- Calculate the starting value of the block finder radius.
-
- The radius shall be the last used value minus the
- maximum moved distance.
+ Get the starting value of the block finder radius.
*/
- /*s16 d_start = m_last_block_find_d;
- if(max_moved >= d_start)
- {
- d_start = 0;
- }
- else
- {
- d_start -= max_moved;
- }*/
-
s16 last_nearest_unsent_d;
s16 d_start;
{
@@ -382,10 +334,6 @@ void RemoteClient::SendBlocks(Server *server, float dtime)
/*
TODO: Get this from somewhere
- TODO: Values more than 7 make placing and removing blocks very
- sluggish when the map is being generated. This is
- because d is looped every time from 0 to d_max if no
- blocks are found for sending.
*/
//s16 d_max = 7;
s16 d_max = 8;
@@ -659,6 +607,10 @@ void RemoteClient::SendObjectData(
in memory):
- Set blocks changed
- Add blocks to emerge queue if they are not found
+
+ SUGGESTION: These could be ignored from the backside of the player
+
+ TODO: Keep track of total size of packet and stop when it is too big
*/
Player *player = server->m_env.getPlayer(peer_id);
@@ -669,9 +621,14 @@ void RemoteClient::SendObjectData(
v3s16 center_nodepos = floatToInt(playerpos);
v3s16 center = getNodeBlockPos(center_nodepos);
- s16 d_max = ACTIVE_OBJECT_D_BLOCKS;
+ //s16 d_max = ACTIVE_OBJECT_D_BLOCKS;
+ s16 d_max = server->m_active_object_range;
+
+ // Number of blocks whose objects were written to bos
+ u16 blockcount = 0;
- core::map<v3s16, MapBlock*> blocks;
+ //core::map<v3s16, MapBlock*> blocks;
+ std::ostringstream bos(std::ios_base::binary);
for(s16 d = 0; d <= d_max; d++)
{
@@ -691,13 +648,18 @@ void RemoteClient::SendObjectData(
if(m_blocks_sent.find(p) == NULL)
continue;
}
-
+
+ // Try stepping block and add it to a send queue
try
{
// Get block
MapBlock *block = server->m_env.getMap().getBlockNoCreate(p);
+ // Skip block if there are no objects
+ if(block->getObjectCount() == 0)
+ continue;
+
// Step block if not in stepped_blocks and add to stepped_blocks
if(stepped_blocks.find(p) == NULL)
{
@@ -705,9 +667,28 @@ void RemoteClient::SendObjectData(
stepped_blocks.insert(p, true);
block->setChangedFlag();
}
-
- // Add block to queue
- blocks.insert(p, block);
+
+ /*
+ Write objects
+ */
+
+ // Write blockpos
+ writeV3S16(buf, p);
+ bos.write((char*)buf, 6);
+
+ // Write objects
+ block->serializeObjects(bos, serialization_version);
+
+ blockcount++;
+
+ /*
+ Stop collecting objects if data is already too big
+ */
+ // Sum of player and object data sizes
+ s32 sum = (s32)os.tellp() + 2 + (s32)bos.tellp();
+ // break out if data too big
+ if(sum > MAX_OBJECTDATA_SIZE)
+ d = d_max+1;
} //try
catch(InvalidPositionException &e)
@@ -729,12 +710,11 @@ void RemoteClient::SendObjectData(
}
}
+#if 0
/*
Write objects
*/
- u16 blockcount = blocks.size();
-
// Write block count
writeU16(buf, blockcount);
os.write((char*)buf, 2);
@@ -751,11 +731,21 @@ void RemoteClient::SendObjectData(
MapBlock *block = i.getNode()->getValue();
block->serializeObjects(os, serialization_version);
}
-
+#endif
+
+ // Write block count
+ writeU16(buf, blockcount);
+ os.write((char*)buf, 2);
+
+ // Write block objects
+ os<<bos.str();
+
/*
Send data
*/
+ //dstream<<"Server: Sending object data to "<<peer_id<<std::endl;
+
// Make data buffer
std::string s = os.str();
SharedBuffer<u8> data((u8*)s.c_str(), s.size());
@@ -898,13 +888,18 @@ u32 PIChecksum(core::list<PlayerInfo> &l)
Server::Server(
std::string mapsavedir,
bool creative_mode,
- MapgenParams mapgen_params
+ HMParams hm_params,
+ MapParams map_params,
+ float objectdata_interval,
+ u16 active_object_range
):
- m_env(new ServerMap(mapsavedir, mapgen_params), dout_server),
+ m_env(new ServerMap(mapsavedir, hm_params, map_params), dout_server),
m_con(PROTOCOL_ID, 512, CONNECTION_TIMEOUT, this),
m_thread(this),
m_emergethread(this),
- m_creative_mode(creative_mode)
+ m_creative_mode(creative_mode),
+ m_objectdata_interval(objectdata_interval),
+ m_active_object_range(active_object_range)
{
m_env_mutex.Init();
m_con_mutex.Init();
@@ -980,6 +975,7 @@ void Server::step(float dtime)
void Server::AsyncRunStep()
{
DSTACK(__FUNCTION_NAME);
+
float dtime;
{
JMutexAutoLock lock1(m_step_dtime_mutex);
@@ -1033,7 +1029,7 @@ void Server::AsyncRunStep()
// Run time- and client- related stuff
// NOTE: If you intend to add something here, check that it
- // doesn't fit in RemoteClient::SendBlocks for exampel.
+ // doesn't fit in RemoteClient::SendBlocks for example.
/*{
// Clients are behind connection lock
JMutexAutoLock lock(m_con_mutex);
@@ -1055,8 +1051,7 @@ void Server::AsyncRunStep()
{
static float counter = 0.0;
counter += dtime;
- //TODO: Get value from somewhere
- if(counter >= 0.1)
+ if(counter >= m_objectdata_interval)
{
JMutexAutoLock lock1(m_env_mutex);
JMutexAutoLock lock2(m_con_mutex);
@@ -1930,12 +1925,12 @@ void Server::peerAdded(con::Peer *peer)
bool r = player->inventory.addItem(item);
assert(r == true);
}
- // Rat
+ /*// Rat
{
InventoryItem *item = new MapBlockObjectItem("Rat");
bool r = player->inventory.addItem(item);
assert(r == true);
- }
+ }*/
}
else
{
diff --git a/src/server.h b/src/server.h
index 5c856333a..c178480d5 100644
--- a/src/server.h
+++ b/src/server.h
@@ -201,6 +201,28 @@ struct PlayerInfo
u32 PIChecksum(core::list<PlayerInfo> &l);
+/*
+ Used for queueing and sorting block transfers in containers
+
+ Lower priority number means higher priority.
+*/
+struct PrioritySortedBlockTransfer
+{
+ PrioritySortedBlockTransfer(float a_priority, v3s16 a_pos, u16 a_dest_peer)
+ {
+ priority = a_priority;
+ pos = a_pos;
+ dest_peer = a_dest_peer;
+ }
+ bool operator < (PrioritySortedBlockTransfer &other)
+ {
+ return priority < other.priority;
+ }
+ float priority;
+ v3s16 pos;
+ u16 a_dest_peer;
+};
+
class RemoteClient
{
public:
@@ -252,6 +274,8 @@ public:
void BlockEmerged();
// Increments timeouts and removes timed-out blocks from list
+ // NOTE: This doesn't fix the server-not-sending-block bug
+ // because it is related to emerging, not sending.
//void RunSendingTimeouts(float dtime, float timeout);
void PrintInfo(std::ostream &o)
@@ -310,6 +334,15 @@ private:
JMutex m_blocks_sending_mutex;
};
+/*struct ServerSettings
+{
+ ServerSettings()
+ {
+ creative_mode = false;
+ }
+ bool creative_mode;
+};*/
+
class Server : public con::PeerHandler
{
public:
@@ -319,7 +352,10 @@ public:
Server(
std::string mapsavedir,
bool creative_mode,
- MapgenParams mapgen_params
+ HMParams hm_params,
+ MapParams map_params,
+ float objectdata_inverval,
+ u16 active_object_range
);
~Server();
void start(unsigned short port);
@@ -377,8 +413,11 @@ private:
EmergeThread m_emergethread;
BlockEmergeQueue m_emerge_queue;
-
+
+ // Settings
bool m_creative_mode;
+ float m_objectdata_interval;
+ u16 m_active_object_range;
friend class EmergeThread;
friend class RemoteClient;
diff --git a/src/utility.h b/src/utility.h
index 4178e9d95..e6a09547b 100644
--- a/src/utility.h
+++ b/src/utility.h
@@ -603,5 +603,15 @@ inline bool is_yes(std::string s)
return false;
}
+inline s32 stoi(std::string s, s32 min, s32 max)
+{
+ s32 i = atoi(s.c_str());
+ if(i < min)
+ i = min;
+ if(i > max)
+ i = max;
+ return i;
+}
+
#endif