the game where you go into mines and start crafting! but for consoles (forked directly from smartcmd's github)
at main 266 lines 11 kB view raw
1#pragma once 2using namespace std; 3 4class DataLayer; 5class TileEntity; 6class Random; 7class ChunkSource; 8class EntitySelector; 9 10#include "SparseLightStorage.h" 11#include "CompressedTileStorage.h" 12#include "SparseDataStorage.h" 13 14#include "LightLayer.h" 15#include "Entity.h" 16#include "Level.h" 17 18#define SHARING_ENABLED 19class TileCompressData_SPU; 20 21#if 0//__PSVITA__ 22#define _ENTITIES_RW_SECTION 23#endif 24 25class LevelChunk 26{ 27 friend class TileCompressData_SPU; 28 friend class LevelRenderer; 29public: 30 byteArray biomes; // 4J Stu - Made public 31 32 // 4J Stu - No longer static in 1.8.2 33 const int ENTITY_BLOCKS_LENGTH; 34 static const int BLOCKS_LENGTH = Level::CHUNK_TILE_COUNT; // 4J added 35 36 static bool touchedSky; 37 38 enum EColumnFlag 39 { 40 eColumnFlag_recheck = 1, 41 eColumnFlag_biomeOk = 2, 42 eColumnFlag_biomeHasSnow = 4, 43 eColumnFlag_biomeHasRain = 8, 44 }; 45 46 // byteArray blocks; 47 // 4J - actual storage for blocks is now private with public methods to access it 48private: 49 CompressedTileStorage *lowerBlocks; // 0 - 127 50 CompressedTileStorage *upperBlocks; // 128 - 255 51public: 52 bool isRenderChunkEmpty(int y); 53 void setBlockData(byteArray data); // Set block data to that passed in in the input array of size 32768 54 void getBlockData(byteArray data); // Sets data in passed in array of size 32768, from the block data in this chunk 55 int getBlocksAllocatedSize(int *count0, int *count1, int *count2, int *count4, int *count8); 56 57 bool loaded; 58 unsigned char rainHeights[16*16]; // 4J - optimisation brought forward from 1.8.2 (was int arrayb in java though) 59 unsigned char columnFlags[16*8]; // 4J - lighting update brought forward from 1.8.2, was a bool array but now mixed with other flags in our version, and stored in nybbles 60 Level *level; 61 62 // 4J - actual storage for data is now private with public methods to access it 63private: 64 SparseDataStorage *lowerData; // 0 - 127 65 SparseDataStorage *upperData; // 128 - 255 66public: 67 void setDataData(byteArray data); // Set data to that passed in in the input array of size 32768 68 void getDataData(byteArray data); // Sets data in passed in array of size 16384, from the data in this chunk 69 70 // DataLayer *data; 71private: 72 // 4J - actual storage for sky & block lights is now private with new methods to be able to access it. 73 74 SparseLightStorage *lowerSkyLight; // 0 - 127 75 SparseLightStorage *upperSkyLight; // 128 - 255 76 SparseLightStorage *lowerBlockLight; // 0 - 127 77 SparseLightStorage *upperBlockLight; // 128 - 255 78public: 79 void getSkyLightData(byteArray data); // Get a byte array of length 16384 ( 128 x 16 x 16 x 0.5 ), containing sky light data. Ordering same as java version. 80 void getBlockLightData(byteArray data); // Get a byte array of length 16384 ( 128 x 16 x 16 x 0.5 ), containing block light data. Ordering same as java version. 81 void setSkyLightData(byteArray data); // Set sky light data to data passed in input byte array of length 16384. This data must be in original (java version) order 82 void setBlockLightData(byteArray data); // Set block light data to data passed in input byte array of length 16384. This data must be in original (java version) order 83 void setSkyLightDataAllBright(); // Set sky light data to be all fully lit 84 bool isLowerBlockStorageCompressed(); 85 int isLowerBlockLightStorageCompressed(); 86 int isLowerDataStorageCompressed(); 87 88 void writeCompressedBlockData(DataOutputStream *dos); 89 void writeCompressedDataData(DataOutputStream *dos); 90 void writeCompressedSkyLightData(DataOutputStream *dos); 91 void writeCompressedBlockLightData(DataOutputStream *dos); 92 93 void readCompressedBlockData(DataInputStream *dis); 94 void readCompressedDataData(DataInputStream *dis); 95 void readCompressedSkyLightData(DataInputStream *dis); 96 void readCompressedBlockLightData(DataInputStream *dis); 97 98 byteArray heightmap; 99 int minHeight; 100 int x, z; 101private: 102 bool hasGapsToCheck; 103public: 104 105 unordered_map<TilePos, shared_ptr<TileEntity>, TilePosKeyHash, TilePosKeyEq> tileEntities; 106 vector<shared_ptr<Entity> > **entityBlocks; 107 108 static const int sTerrainPopulatedFromHere = 2; 109 static const int sTerrainPopulatedFromW = 4; 110 static const int sTerrainPopulatedFromS = 8; 111 static const int sTerrainPopulatedFromSW = 16; 112 static const int sTerrainPopulatedAllAffecting = 30; // All the post-processing that can actually place tiles in this chunk are complete 113 static const int sTerrainPopulatedFromNW = 32; 114 static const int sTerrainPopulatedFromN = 64; 115 static const int sTerrainPopulatedFromNE = 128; 116 static const int sTerrainPopulatedFromE = 256; 117 static const int sTerrainPopulatedFromSE = 512; 118 static const int sTerrainPopulatedAllNeighbours = 1022; // The post-processing passes of all neighbours to this chunk are complete 119 static const int sTerrainPostPostProcessed = 1024; // This chunk has been post-post-processed, which is only done when all neighbours have been post-processed 120 121 short terrainPopulated; // 4J - changed from bool to bitfield within short 122 short *serverTerrainPopulated; // 4J added 123 124 void setUnsaved(bool unsaved); // 4J added 125protected: 126 // 4J Stu - Stopped this being private so we can add some more logic to it 127 bool m_unsaved; 128 129public: 130 bool dontSave; 131 bool lastSaveHadEntities; 132#ifdef SHARING_ENABLED 133 bool sharingTilesAndData; // 4J added 134#endif 135 bool emissiveAdded; // 4J added 136 void stopSharingTilesAndData(); // 4J added 137 virtual void reSyncLighting(); // 4J added 138 void startSharingTilesAndData(int forceMs = 0); // 4J added 139 __int64 lastUnsharedTime; // 4J added 140 __int64 lastSaveTime; 141 bool seenByPlayer; 142 int lowestHeightmap; 143 __int64 inhabitedTime; 144 145#ifdef _LARGE_WORLDS 146 bool m_bUnloaded; 147 CompoundTag *m_unloadedEntitiesTag; 148#endif 149 150 //static const int LIGHT_CHECK_MAX_POS = NUM_SECTIONS * 16 * 16; 151private: 152 int checkLightPosition; 153 154public: 155 virtual void init(Level *level, int x, int z); 156 LevelChunk(Level *level, int x, int z); 157 LevelChunk(Level *level, byteArray blocks, int x, int z); 158 LevelChunk(Level *level, int x, int z, LevelChunk *lc); 159 ~LevelChunk(); 160 161 virtual bool isAt(int x, int z); 162 163 virtual int getHeightmap(int x, int z); 164 int getHighestSectionPosition(); 165 virtual void recalcBlockLights(); 166 167 virtual void recalcHeightmapOnly(); 168 169 virtual void recalcHeightmap(); 170 171 virtual void lightLava(); 172 173private: 174 void lightGaps(int x, int z); 175 // 4J - changes for lighting brought forward from 1.8.2 176public: 177 void recheckGaps(bool bForce = false); // 4J - added parameter, made public 178private: 179 void lightGap(int x, int z, int source); 180 void lightGap(int x, int z, int y1, int y2); 181 182 void recalcHeight(int x, int yStart, int z); 183 184public: 185 virtual int getTileLightBlock(int x, int y, int z); 186 virtual int getTile(int x, int y, int z); 187 virtual bool setTileAndData(int x, int y, int z, int _tile, int _data); 188 virtual bool setTile(int x, int y, int z, int _tile); 189 virtual int getData(int x, int y, int z); 190 virtual bool setData(int x, int y, int z, int val, int mask, bool *maskedBitsChanged); // 4J added mask 191 virtual int getBrightness(LightLayer::variety layer, int x, int y, int z); 192 virtual void getNeighbourBrightnesses(int *brightnesses, LightLayer::variety layer, int x, int y, int z); // 4J added 193 virtual void setBrightness(LightLayer::variety layer, int x, int y, int z, int brightness); 194 virtual int getRawBrightness(int x, int y, int z, int skyDampen); 195 virtual void addEntity(shared_ptr<Entity> e); 196 virtual void removeEntity(shared_ptr<Entity> e); 197 virtual void removeEntity(shared_ptr<Entity> e, int yc); 198 virtual bool isSkyLit(int x, int y, int z); 199 virtual void skyBrightnessChanged(); 200 virtual shared_ptr<TileEntity> getTileEntity(int x, int y, int z); 201 virtual void addTileEntity(shared_ptr<TileEntity> te); 202 virtual void setTileEntity(int x, int y, int z, shared_ptr<TileEntity> tileEntity); 203 virtual void removeTileEntity(int x, int y, int z); 204 virtual void load(); 205 virtual void unload(bool unloadTileEntities) ; // 4J - added parameter 206 virtual bool containsPlayer(); // 4J - added 207#ifdef _LARGE_WORLDS 208 virtual bool isUnloaded(); 209#endif 210 virtual void markUnsaved(); 211 virtual void getEntities(shared_ptr<Entity> except, AABB *bb, vector<shared_ptr<Entity> > &es, const EntitySelector *selector); 212 virtual void getEntitiesOfClass(const type_info& ec, AABB *bb, vector<shared_ptr<Entity> > &es, const EntitySelector *selector); 213 virtual int countEntities(); 214 virtual bool shouldSave(bool force); 215 virtual int getBlocksAndData(byteArray *data, int x0, int y0, int z0, int x1, int y1, int z1, int p, bool includeLighting = true); // 4J - added includeLighting parameter 216 static void tileUpdatedCallback(int x, int y, int z, void *param, int yparam); // 4J added 217 virtual int setBlocksAndData(byteArray data, int x0, int y0, int z0, int x1, int y1, int z1, int p, bool includeLighting = true); // 4J - added includeLighting parameter 218 virtual bool testSetBlocksAndData(byteArray data, int x0, int y0, int z0, int x1, int y1, int z1, int p); // 4J added 219 virtual void setCheckAllLight(); 220 221 virtual Random *getRandom(__int64 l); 222 virtual bool isEmpty(); 223 virtual void attemptCompression(); 224 225#ifdef SHARING_ENABLED 226 static CRITICAL_SECTION m_csSharing; // 4J added 227#endif 228 // 4J added 229#ifdef _ENTITIES_RW_SECTION 230 static CRITICAL_RW_SECTION m_csEntities; // AP - we're using a RW critical so we can do multiple reads without contention 231#else 232 static CRITICAL_SECTION m_csEntities; 233#endif 234 static CRITICAL_SECTION m_csTileEntities; // 4J added 235 static void staticCtor(); 236 void checkPostProcess(ChunkSource *source, ChunkSource *parent, int x, int z); 237 void checkChests(ChunkSource *source, int x, int z ); // 4J added 238 int getTopRainBlock(int x, int z); // 4J - optimisation brought forward from 1.8.2 239 void tick(); // 4J - lighting change brought forward from 1.8.2 240 ChunkPos *getPos(); 241 bool isYSpaceEmpty(int y1, int y2); 242 void reloadBiomes(); // 4J added 243 virtual Biome *getBiome(int x, int z, BiomeSource *biomeSource); 244 byteArray getBiomes(); 245 void setBiomes(byteArray biomes); 246 bool biomeHasRain(int x, int z); // 4J added 247 bool biomeHasSnow(int x, int z); // 4J added 248private: 249 void updateBiomeFlags(int x, int z); // 4J added 250public: 251 void compressLighting(); // 4J added 252 void compressBlocks(); // 4J added 253 void compressData(); // 4J added 254 int getHighestNonEmptyY(); 255 byteArray getReorderedBlocksAndData(int x, int y, int z, int xs, int &ys, int zs); 256 static void reorderBlocksAndDataToXZY(int y0, int xs, int ys, int zs, byteArray *data); 257#ifdef LIGHT_COMPRESSION_STATS 258 int getBlockLightPlanesLower() { return lowerBlockLight->count; } 259 int getSkyLightPlanesLower() { return lowerSkyLight->count; } 260 int getBlockLightPlanesUpper() { return upperBlockLight->count; } 261 int getSkyLightPlanesUpper() { return upperSkyLight->count; } 262#endif 263#ifdef DATA_COMPRESSION_STATS 264 int getDataPlanes() { return data->count; } 265#endif 266};