]> git.lizzy.rs Git - dragonfireclient.git/blobdiff - src/mapblock.h
Node placement client-side prediction
[dragonfireclient.git] / src / mapblock.h
index f2d94753c9fba586f5f8bff26d6fe20220acfc4f..10ffc61ce181bb5c46b1b808fb8cd7079bf188f0 100644 (file)
@@ -3,16 +3,16 @@ 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
+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 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.
+GNU Lesser General Public License for more details.
 
-You should have received a copy of the GNU General Public License along
+You should have received a copy of the GNU Lesser 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.
 */
@@ -31,13 +31,14 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 #include "constants.h"
 #include "voxel.h"
 #include "staticobject.h"
-#include "mapblock_nodemod.h"
+#include "nodemetadata.h"
+#include "nodetimer.h"
 #include "modifiedstate.h"
 
 class Map;
 class NodeMetadataList;
 class IGameDef;
-class IWritableNodeDefManager;
+class MapBlockMesh;
 
 #define BLOCK_TIMESTAMP_UNDEFINED 0xffffffff
 
@@ -193,18 +194,6 @@ class MapBlock /*: public NodeContainer*/
                raiseModified(MOD_STATE_WRITE_NEEDED, "setIsUnderground");
        }
 
-#ifndef SERVER
-       void setMeshExpired(bool expired)
-       {
-               m_mesh_expired = expired;
-       }
-       
-       bool getMeshExpired()
-       {
-               return m_mesh_expired;
-       }
-#endif
-
        void setLightingExpired(bool expired)
        {
                if(expired != m_lighting_expired){
@@ -359,44 +348,6 @@ class MapBlock /*: public NodeContainer*/
                                        setNode(x0+x, y0+y, z0+z, node);
        }
 
-       /*
-               Graphics-related methods
-       */
-       
-       /*// A quick version with nodes passed as parameters
-       u8 getFaceLight(u32 daynight_ratio, MapNode n, MapNode n2,
-                       v3s16 face_dir);*/
-       /*// A more convenient version
-       u8 getFaceLight(u32 daynight_ratio, v3s16 p, v3s16 face_dir)
-       {
-               return getFaceLight(daynight_ratio,
-                               getNodeParentNoEx(p),
-                               getNodeParentNoEx(p + face_dir),
-                               face_dir);
-       }*/
-       u8 getFaceLight2(u32 daynight_ratio, v3s16 p, v3s16 face_dir,
-                       INodeDefManager *nodemgr)
-       {
-               return getFaceLight(daynight_ratio,
-                               getNodeParentNoEx(p),
-                               getNodeParentNoEx(p + face_dir),
-                               face_dir, nodemgr);
-       }
-       
-#ifndef SERVER // Only on client
-
-#if 1
-       /*
-               Thread-safely updates the whole mesh of the mapblock.
-               NOTE: Prefer generating the mesh separately and then using
-               replaceMesh().
-       */
-       void updateMesh(u32 daynight_ratio);
-#endif
-       // Replace the mesh with a new one
-       void replaceMesh(scene::SMesh *mesh_new);
-#endif
-       
        // See comments in mapblock.cpp
        bool propagateSunlight(core::map<v3s16, bool> & light_sources,
                        bool remove_light=false, bool *black_air_left=NULL);
@@ -406,64 +357,22 @@ class MapBlock /*: public NodeContainer*/
        // Copies data from VoxelManipulator getPosRelative()
        void copyFrom(VoxelManipulator &dst);
 
-#ifndef SERVER // Only on client
-       /*
-               Methods for setting temporary modifications to nodes for
-               drawing
-
-               returns true if the mod was different last time
-       */
-       bool setTempMod(v3s16 p, const NodeMod &mod)
-       {
-               /*dstream<<"setTempMod called on block"
-                               <<" ("<<p.X<<","<<p.Y<<","<<p.Z<<")"
-                               <<", mod.type="<<mod.type
-                               <<", mod.param="<<mod.param
-                               <<std::endl;*/
-               JMutexAutoLock lock(m_temp_mods_mutex);
-
-               return m_temp_mods.set(p, mod);
-       }
-       // Returns true if there was one
-       bool getTempMod(v3s16 p, NodeMod *mod)
-       {
-               JMutexAutoLock lock(m_temp_mods_mutex);
-
-               return m_temp_mods.get(p, mod);
-       }
-       bool clearTempMod(v3s16 p)
-       {
-               JMutexAutoLock lock(m_temp_mods_mutex);
-
-               return m_temp_mods.clear(p);
-       }
-       bool clearTempMods()
-       {
-               JMutexAutoLock lock(m_temp_mods_mutex);
-               
-               return m_temp_mods.clear();
-       }
-       void copyTempMods(NodeModMap &dst)
-       {
-               JMutexAutoLock lock(m_temp_mods_mutex);
-               m_temp_mods.copy(dst);
-       }
-#endif
-
        /*
                Update day-night lighting difference flag.
-               
                Sets m_day_night_differs to appropriate value.
-               
                These methods don't care about neighboring blocks.
-               It means that to know if a block really doesn't need a mesh
-               update between day and night, the neighboring blocks have
-               to be taken into account. Use Map::dayNightDiffed().
        */
-       void updateDayNightDiff();
+       void actuallyUpdateDayNightDiff();
+       /*
+               Call this to schedule what the previous function does to be done
+               when the value is actually needed.
+       */
+       void expireDayNightDiff();
 
-       bool dayNightDiffed()
+       bool getDayNightDiff()
        {
+               if(m_day_night_differs_expired)
+                       actuallyUpdateDayNightDiff();
                return m_day_night_differs;
        }
 
@@ -524,20 +433,20 @@ class MapBlock /*: public NodeContainer*/
        */
        
        // These don't write or read version by itself
-       void serialize(std::ostream &os, u8 version);
-       void deSerialize(std::istream &is, u8 version);
-
-       // Used after the basic ones when writing on disk (serverside)
-       void serializeDiskExtra(std::ostream &os, u8 version);
-       // In addition to doing other things, will add unknown blocks from
-       // id-name mapping to wndef
-       void deSerializeDiskExtra(std::istream &is, u8 version);
+       // Set disk to true for on-disk format, false for over-the-network format
+       void serialize(std::ostream &os, u8 version, bool disk);
+       // If disk == true: In addition to doing other things, will add
+       // unknown blocks from id-name mapping to wndef
+       void deSerialize(std::istream &is, u8 version, bool disk);
 
 private:
        /*
                Private methods
        */
 
+       void serialize_pre22(std::ostream &os, u8 version, bool disk);
+       void deSerialize_pre22(std::istream &is, u8 version, bool disk);
+
        /*
                Used only internally, because changes can't be tracked
        */
@@ -562,11 +471,12 @@ class MapBlock /*: public NodeContainer*/
        */
 
 #ifndef SERVER // Only on client
-       scene::SMesh *mesh;
-       JMutex mesh_mutex;
+       MapBlockMesh *mesh;
+       //JMutex mesh_mutex;
 #endif
        
-       NodeMetadataList *m_node_metadata;
+       NodeMetadataList m_node_metadata;
+       NodeTimerList m_node_timers;
        StaticObjectList m_static_objects;
        
 private:
@@ -617,23 +527,10 @@ class MapBlock /*: public NodeContainer*/
        
        // Whether day and night lighting differs
        bool m_day_night_differs;
+       bool m_day_night_differs_expired;
 
        bool m_generated;
        
-#ifndef SERVER // Only on client
-       /*
-               Set to true if the mesh has been ordered to be updated
-               sometime in the background.
-               In practice this is set when the day/night lighting switches.
-       */
-       bool m_mesh_expired;
-       
-       // Temporary modifications to nodes
-       // These are only used when drawing
-       NodeModMap m_temp_mods;
-       JMutex m_temp_mods_mutex;
-#endif
-       
        /*
                When block is removed from active blocks, this is set to gametime.
                Value BLOCK_TIMESTAMP_UNDEFINED=0xffffffff means there is no timestamp.