From 7ddfaeb59e5d77ee94822edc09a82c571a6e6b58 Mon Sep 17 00:00:00 2001 From: MatthewBeshay <92357869+MatthewBeshay@users.noreply.github.com> Date: Tue, 31 Mar 2026 12:06:19 +1100 Subject: [PATCH] refactor: remove arrayWithLength, replace with std::vector Eliminates the custom arrayWithLength wrapper and all typedefs, replacing with std::vector directly. --- .../Minecraft.Client/Common/Consoles_App.cpp | 15 +- .../Minecraft.Client/Common/Consoles_App.h | 2 +- .../Source Files/Colours/ColourTable.cpp | 2 +- .../Common/Source Files/DLC/DLCManager.cpp | 4 +- .../GameRules/GameRuleManager.cpp | 108 ++++---- .../LevelGeneration/ConsoleSchematicFile.cpp | 133 +++++----- .../LevelGeneration/ConsoleSchematicFile.h | 8 +- .../LevelGenerationOptions.cpp | 2 +- .../Leaderboards/SonyLeaderboardManager.cpp | 2 +- .../Source Files/Localisation/StringTable.cpp | 10 +- .../Source Files/Localisation/StringTable.h | 2 +- .../Common/Source Files/Network/Socket.cpp | 35 ++- .../Common/Source Files/Network/Socket.h | 20 +- .../UI/All Platforms/ArchiveFile.cpp | 29 ++- .../UI/All Platforms/ArchiveFile.h | 2 +- .../UI/All Platforms/IUIScene_AnvilMenu.cpp | 2 +- .../UI/All Platforms/IUIScene_BeaconMenu.cpp | 4 +- .../All Platforms/IUIScene_CraftingMenu.cpp | 6 +- .../All Platforms/IUIScene_CreativeMenu.cpp | 12 +- .../UI/Scenes/Debug/UIScene_DebugOverlay.cpp | 2 +- .../UIScene_LoadOrJoinMenu.cpp | 19 +- .../UIScene_MainMenu.cpp | 2 +- .../Common/Source Files/UI/UIController.cpp | 17 +- .../Common/Source Files/UI/UIController.h | 6 +- .../Common/Source Files/UI/UIScene.cpp | 4 +- .../Header Files/BufferedImage.h | 2 +- .../Source Files/BufferedImage.cpp | 10 +- .../net/minecraft/client/Minecraft.cpp | 12 +- .../net/minecraft/client/Minecraft.h | 2 +- .../net/minecraft/client/gui/Font.cpp | 2 +- .../client/gui/JoinMultiplayerScreen.cpp | 2 +- .../net/minecraft/client/gui/Minimap.cpp | 2 +- .../net/minecraft/client/gui/Minimap.h | 2 +- .../net/minecraft/client/model/BlazeModel.cpp | 8 +- .../net/minecraft/client/model/BlazeModel.h | 2 +- .../net/minecraft/client/model/GhastModel.cpp | 6 +- .../client/model/SilverfishModel.cpp | 16 +- .../minecraft/client/model/SilverfishModel.h | 4 +- .../net/minecraft/client/model/SkiModel.cpp | 4 +- .../net/minecraft/client/model/SkiModel.h | 2 +- .../net/minecraft/client/model/SquidModel.cpp | 10 +- .../client/model/WitherBossModel.cpp | 8 +- .../minecraft/client/model/WitherBossModel.h | 4 +- .../client/model/dragon/DragonModel.cpp | 8 +- .../minecraft/client/model/geom/ModelPart.cpp | 2 +- .../client/multiplayer/ClientConnection.cpp | 18 +- .../multiplayer/MultiPlayerChunkCache.cpp | 8 +- .../multiplayer/MultiPlayerLocalPlayer.cpp | 9 +- .../multiplayer/MultiPlayerLocalPlayer.h | 4 +- .../client/particle/FireworksParticles.cpp | 56 ++--- .../client/particle/FireworksParticles.h | 12 +- .../minecraft/client/player/LocalPlayer.cpp | 7 +- .../net/minecraft/client/player/LocalPlayer.h | 4 +- .../net/minecraft/client/renderer/Chunk.cpp | 6 +- .../client/renderer/GameRenderer.cpp | 2 +- .../minecraft/client/renderer/GameRenderer.h | 2 +- .../client/renderer/LevelRenderer.cpp | 59 +++-- .../minecraft/client/renderer/LevelRenderer.h | 2 +- .../minecraft/client/renderer/Tesselator.cpp | 42 ++-- .../minecraft/client/renderer/Tesselator.h | 2 +- .../minecraft/client/renderer/Textures.cpp | 63 +++-- .../net/minecraft/client/renderer/Textures.h | 16 +- .../client/renderer/culling/Frustum.cpp | 10 +- .../client/renderer/culling/FrustumData.cpp | 9 +- .../client/renderer/culling/FrustumData.h | 6 +- .../renderer/entity/EnderDragonRenderer.cpp | 2 +- .../client/renderer/texture/Stitcher.cpp | 2 +- .../client/renderer/texture/Texture.cpp | 37 ++- .../client/renderer/texture/Texture.h | 2 +- .../renderer/tileentity/SignRenderer.cpp | 6 +- .../client/resources/ResourceLocation.h | 17 +- .../client/skins/AbstractTexturePack.cpp | 12 +- .../minecraft/client/skins/DLCTexturePack.cpp | 7 +- .../client/skins/DefaultTexturePack.cpp | 6 +- .../minecraft/client/title/TitleScreen.cpp | 2 +- .../net/minecraft/server/MinecraftServer.cpp | 55 ++-- .../net/minecraft/server/MinecraftServer.h | 2 +- .../net/minecraft/server/PlayerList.cpp | 2 +- .../net/minecraft/server/PlayerList.h | 2 +- .../server/commands/TeleportCommand.cpp | 14 +- .../server/commands/TeleportCommand.h | 2 +- .../minecraft/server/level/PlayerChunkMap.cpp | 4 +- .../minecraft/server/level/PlayerChunkMap.h | 2 +- .../server/level/ServerChunkCache.cpp | 3 +- .../minecraft/server/level/ServerLevel.cpp | 8 +- .../net/minecraft/server/level/ServerLevel.h | 2 +- .../minecraft/server/level/ServerPlayer.cpp | 19 +- .../net/minecraft/server/level/ServerPlayer.h | 2 +- .../server/network/PlayerConnection.cpp | 5 +- .../server/network/ServerConnection.cpp | 2 +- .../ConsoleHelpers/ArrayWithLength.h | 105 +------- .../ConsoleSaveFileInputStream.cpp | 12 +- .../ConsoleSaveFileInputStream.h | 4 +- .../ConsoleSaveFileOriginal.cpp | 4 +- .../ConsoleSaveFileOutputStream.cpp | 14 +- .../ConsoleSaveFileOutputStream.h | 4 +- .../ConsoleSaveFileSplit.cpp | 3 +- .../ConsoleSaveFileIO/FileHeader.cpp | 4 +- .../Source Files/compression.cpp | 2 +- .../net/minecraft/commands/Command.h | 2 +- .../minecraft/commands/CommandDispatcher.cpp | 2 +- .../minecraft/commands/CommandDispatcher.h | 2 +- .../net/minecraft/commands/PlayerSelector.h | 8 +- .../common/DefaultGameModeCommand.cpp | 4 +- .../commands/common/DefaultGameModeCommand.h | 2 +- .../commands/common/EffectCommand.cpp | 10 +- .../minecraft/commands/common/EffectCommand.h | 2 +- .../commands/common/EnchantItemCommand.cpp | 2 +- .../commands/common/EnchantItemCommand.h | 2 +- .../commands/common/ExperienceCommand.cpp | 6 +- .../commands/common/ExperienceCommand.h | 2 +- .../commands/common/GameDifficultyCommand.h | 4 +- .../commands/common/GameModeCommand.cpp | 8 +- .../commands/common/GameModeCommand.h | 2 +- .../commands/common/GameRuleCommand.h | 10 +- .../commands/common/GiveItemCommand.cpp | 2 +- .../commands/common/GiveItemCommand.h | 2 +- .../minecraft/commands/common/KillCommand.cpp | 2 +- .../minecraft/commands/common/KillCommand.h | 2 +- .../commands/common/PlaySoundCommand.h | 14 +- .../commands/common/SetPlayerTimeoutCommand.h | 2 +- .../commands/common/SpreadPlayersCommand.h | 20 +- .../minecraft/commands/common/TimeCommand.cpp | 8 +- .../minecraft/commands/common/TimeCommand.h | 2 +- .../commands/common/ToggleDownfallCommand.cpp | 4 +- .../commands/common/ToggleDownfallCommand.h | 2 +- .../commands/common/WeatherCommand.h | 6 +- .../net/minecraft/locale/Language.cpp | 4 +- .../network/packet/AwardStatPacket.cpp | 27 +- .../network/packet/AwardStatPacket.h | 6 +- .../packet/BlockRegionUpdatePacket.cpp | 29 ++- .../network/packet/BlockRegionUpdatePacket.h | 2 +- .../network/packet/ChunkTilesUpdatePacket.cpp | 17 +- .../network/packet/ChunkTilesUpdatePacket.h | 8 +- .../network/packet/ComplexItemDataPacket.cpp | 17 +- .../network/packet/ComplexItemDataPacket.h | 4 +- .../packet/ContainerSetContentPacket.cpp | 14 +- .../packet/ContainerSetContentPacket.h | 2 +- .../network/packet/CustomPayloadPacket.cpp | 13 +- .../network/packet/CustomPayloadPacket.h | 4 +- .../network/packet/GameCommandPacket.cpp | 16 +- .../network/packet/GameCommandPacket.h | 4 +- .../net/minecraft/network/packet/Packet.cpp | 18 +- .../net/minecraft/network/packet/Packet.h | 4 +- .../network/packet/RemoveEntitiesPacket.cpp | 13 +- .../network/packet/RemoveEntitiesPacket.h | 4 +- .../packet/UpdateGameRuleProgressPacket.cpp | 14 +- .../packet/UpdateGameRuleProgressPacket.h | 2 +- .../net/minecraft/stats/CommonStats.cpp | 46 ++-- .../net/minecraft/stats/CommonStats.h | 34 +-- .../net/minecraft/stats/DurangoStats.h | 92 +++---- .../net/minecraft/stats/GenericStats.cpp | 226 ++++++++--------- .../net/minecraft/stats/GenericStats.h | 236 +++++++++--------- .../net/minecraft/stats/Stat.h | 2 +- .../net/minecraft/stats/Stats.cpp | 26 +- .../net/minecraft/stats/Stats.h | 14 +- .../net/minecraft/util/WeighedRandom.cpp | 10 +- .../net/minecraft/util/WeighedRandom.h | 6 +- .../net/minecraft/util/WeighedTreasure.cpp | 14 +- .../net/minecraft/util/WeighedTreasure.h | 6 +- .../net/minecraft/world/SimpleContainer.cpp | 2 +- .../net/minecraft/world/SimpleContainer.h | 2 +- .../net/minecraft/world/WorldlyContainer.h | 2 +- .../net/minecraft/world/entity/Entity.cpp | 4 +- .../net/minecraft/world/entity/Entity.h | 2 +- .../minecraft/world/entity/LivingEntity.cpp | 13 +- .../net/minecraft/world/entity/LivingEntity.h | 4 +- .../net/minecraft/world/entity/Mob.cpp | 20 +- .../net/minecraft/world/entity/Mob.h | 6 +- .../minecraft/world/entity/MobCategory.cpp | 2 +- .../net/minecraft/world/entity/MobCategory.h | 2 +- .../world/entity/animal/EntityHorse.cpp | 5 +- .../world/entity/animal/EntityHorse.h | 6 +- .../entity/boss/enderdragon/EnderDragon.cpp | 63 +++-- .../entity/boss/enderdragon/EnderDragon.h | 12 +- .../world/entity/item/MinecartContainer.cpp | 9 +- .../world/entity/item/MinecartContainer.h | 2 +- .../world/entity/player/Inventory.cpp | 108 ++++---- .../minecraft/world/entity/player/Inventory.h | 4 +- .../minecraft/world/entity/player/Player.cpp | 12 +- .../minecraft/world/entity/player/Player.h | 4 +- .../world/inventory/AbstractContainerMenu.cpp | 4 +- .../world/inventory/AbstractContainerMenu.h | 2 +- .../world/inventory/CraftingContainer.cpp | 4 +- .../world/inventory/CraftingContainer.h | 2 +- .../minecraft/world/inventory/MenuBackup.cpp | 8 +- .../minecraft/world/inventory/MenuBackup.h | 2 +- .../world/inventory/MerchantContainer.cpp | 7 +- .../world/inventory/MerchantContainer.h | 3 +- .../minecraft/world/item/ColoredTileItem.cpp | 15 +- .../minecraft/world/item/ColoredTileItem.h | 4 +- .../net/minecraft/world/item/DiggerItem.cpp | 4 +- .../net/minecraft/world/item/DiggerItem.h | 4 +- .../world/item/FireworksChargeItem.cpp | 22 +- .../net/minecraft/world/item/HatchetItem.cpp | 20 +- .../net/minecraft/world/item/HatchetItem.h | 2 +- .../net/minecraft/world/item/Item.cpp | 2 +- .../net/minecraft/world/item/Item.h | 2 +- .../net/minecraft/world/item/MapItem.cpp | 5 +- .../net/minecraft/world/item/PickaxeItem.cpp | 50 ++-- .../net/minecraft/world/item/PickaxeItem.h | 2 +- .../net/minecraft/world/item/ShovelItem.cpp | 24 +- .../net/minecraft/world/item/ShovelItem.h | 2 +- .../minecraft/world/item/WrittenBookItem.h | 2 +- .../world/item/crafting/FireworksRecipe.cpp | 10 +- .../world/item/enchantment/Enchantment.cpp | 2 +- .../world/item/enchantment/Enchantment.h | 2 +- .../item/enchantment/EnchantmentHelper.cpp | 18 +- .../item/enchantment/EnchantmentHelper.h | 6 +- .../minecraft/world/level/FoliageColor.cpp | 6 +- .../net/minecraft/world/level/FoliageColor.h | 4 +- .../net/minecraft/world/level/GrassColor.cpp | 6 +- .../net/minecraft/world/level/GrassColor.h | 4 +- .../net/minecraft/world/level/Level.cpp | 12 +- .../net/minecraft/world/level/Level.h | 4 +- .../net/minecraft/world/level/MobSpawner.cpp | 2 +- .../net/minecraft/world/level/Region.cpp | 36 ++- .../net/minecraft/world/level/Region.h | 2 +- .../net/minecraft/world/level/WaterColor.cpp | 6 +- .../net/minecraft/world/level/WaterColor.h | 4 +- .../world/level/biome/BiomeCache.cpp | 22 +- .../minecraft/world/level/biome/BiomeCache.h | 12 +- .../world/level/biome/BiomeSource.cpp | 113 ++++----- .../minecraft/world/level/biome/BiomeSource.h | 28 +-- .../world/level/biome/FixedBiomeSource.cpp | 53 ++-- .../world/level/biome/FixedBiomeSource.h | 24 +- .../world/level/chunk/BlockReplacements.cpp | 6 +- .../world/level/chunk/BlockReplacements.h | 4 +- .../level/chunk/CompressedTileStorage.cpp | 46 ++-- .../world/level/chunk/CompressedTileStorage.h | 12 +- .../minecraft/world/level/chunk/DataLayer.cpp | 9 +- .../minecraft/world/level/chunk/DataLayer.h | 4 +- .../world/level/chunk/EmptyLevelChunk.cpp | 11 +- .../world/level/chunk/EmptyLevelChunk.h | 10 +- .../world/level/chunk/LevelChunk.cpp | 123 +++++---- .../minecraft/world/level/chunk/LevelChunk.h | 38 +-- .../world/level/chunk/ReadOnlyChunkCache.cpp | 8 +- .../world/level/chunk/ReadOnlyChunkCache.h | 4 +- .../world/level/chunk/SparseDataStorage.cpp | 25 +- .../world/level/chunk/SparseDataStorage.h | 8 +- .../world/level/chunk/SparseLightStorage.cpp | 27 +- .../world/level/chunk/SparseLightStorage.h | 8 +- .../world/level/chunk/WaterLevelChunk.cpp | 8 +- .../world/level/chunk/WaterLevelChunk.h | 8 +- .../chunk/storage/McRegionChunkStorage.cpp | 16 +- .../chunk/storage/McRegionChunkStorage.h | 2 +- .../world/level/chunk/storage/NbtSlotFile.cpp | 15 +- .../world/level/chunk/storage/NbtSlotFile.h | 2 +- .../level/chunk/storage/OldChunkStorage.cpp | 54 ++-- .../level/chunk/storage/OldChunkStorage.h | 8 +- .../world/level/chunk/storage/RegionFile.cpp | 10 +- .../world/level/chunk/storage/RegionFile.h | 4 +- .../world/level/chunk/storage/ZoneFile.cpp | 3 +- .../world/level/chunk/storage/ZoneFile.h | 2 +- .../world/level/chunk/storage/ZoneIo.cpp | 4 +- .../world/level/chunk/storage/ZoneIo.h | 2 +- .../world/level/levelgen/CanyonFeature.cpp | 4 +- .../world/level/levelgen/CanyonFeature.h | 4 +- .../level/levelgen/CustomLevelSource.cpp | 41 ++- .../world/level/levelgen/CustomLevelSource.h | 10 +- .../world/level/levelgen/DungeonFeature.cpp | 6 +- .../world/level/levelgen/DungeonFeature.h | 6 +- .../world/level/levelgen/FlatLevelSource.cpp | 8 +- .../world/level/levelgen/FlatLevelSource.h | 2 +- .../level/levelgen/HellFlatLevelSource.cpp | 10 +- .../level/levelgen/HellFlatLevelSource.h | 4 +- .../level/levelgen/HellRandomLevelSource.cpp | 41 ++- .../level/levelgen/HellRandomLevelSource.h | 6 +- .../world/level/levelgen/LargeCaveFeature.cpp | 6 +- .../world/level/levelgen/LargeCaveFeature.h | 6 +- .../world/level/levelgen/LargeFeature.cpp | 2 +- .../world/level/levelgen/LargeFeature.h | 4 +- .../level/levelgen/LargeHellCaveFeature.cpp | 6 +- .../level/levelgen/LargeHellCaveFeature.h | 6 +- .../level/levelgen/RandomLevelSource.cpp | 53 ++-- .../world/level/levelgen/RandomLevelSource.h | 12 +- .../levelgen/TheEndLevelRandomLevelSource.cpp | 35 +-- .../levelgen/TheEndLevelRandomLevelSource.h | 10 +- .../levelgen/feature/BonusChestFeature.cpp | 2 +- .../levelgen/feature/BonusChestFeature.h | 4 +- .../levelgen/feature/MonsterRoomFeature.cpp | 6 +- .../levelgen/structure/BlockGenMethods.cpp | 8 +- .../levelgen/structure/BlockGenMethods.h | 8 +- .../level/levelgen/structure/BoundingBox.cpp | 6 +- .../level/levelgen/structure/BoundingBox.h | 2 +- .../levelgen/structure/MineShaftPieces.cpp | 6 +- .../levelgen/structure/MineShaftPieces.h | 4 +- .../levelgen/structure/NetherBridgePieces.cpp | 4 +- .../structure/ScatteredFeaturePieces.cpp | 16 +- .../levelgen/structure/StrongholdPieces.cpp | 19 +- .../levelgen/structure/StructureFeature.cpp | 5 +- .../levelgen/structure/StructureFeature.h | 2 +- .../levelgen/structure/StructurePiece.cpp | 4 +- .../level/levelgen/structure/StructurePiece.h | 4 +- .../levelgen/structure/VillagePieces.cpp | 4 +- .../level/levelgen/structure/VillagePieces.h | 2 +- .../world/level/levelgen/synth/FastNoise.cpp | 8 +- .../world/level/levelgen/synth/FastNoise.h | 2 +- .../level/levelgen/synth/ImprovedNoise.cpp | 2 +- .../level/levelgen/synth/ImprovedNoise.h | 2 +- .../level/levelgen/synth/PerlinNoise.cpp | 10 +- .../world/level/levelgen/synth/PerlinNoise.h | 4 +- .../levelgen/synth/PerlinSimplexNoise.cpp | 19 +- .../level/levelgen/synth/PerlinSimplexNoise.h | 6 +- .../level/levelgen/synth/SimplexNoise.cpp | 4 +- .../world/level/levelgen/synth/SimplexNoise.h | 4 +- .../world/level/levelgen/synth/Synth.cpp | 4 +- .../world/level/levelgen/synth/Synth.h | 2 +- .../level/newbiome/layer/AddIslandLayer.cpp | 6 +- .../level/newbiome/layer/AddIslandLayer.h | 2 +- .../newbiome/layer/AddMushroomIslandLayer.cpp | 6 +- .../newbiome/layer/AddMushroomIslandLayer.h | 2 +- .../level/newbiome/layer/AddSnowLayer.cpp | 6 +- .../world/level/newbiome/layer/AddSnowLayer.h | 2 +- .../level/newbiome/layer/BiomeInitLayer.cpp | 17 +- .../level/newbiome/layer/BiomeInitLayer.h | 4 +- .../newbiome/layer/BiomeOverrideLayer.cpp | 12 +- .../level/newbiome/layer/BiomeOverrideLayer.h | 4 +- .../level/newbiome/layer/DownfallLayer.cpp | 6 +- .../level/newbiome/layer/DownfallLayer.h | 2 +- .../newbiome/layer/DownfallMixerLayer.cpp | 8 +- .../level/newbiome/layer/DownfallMixerLayer.h | 2 +- .../world/level/newbiome/layer/FlatLayer.cpp | 4 +- .../world/level/newbiome/layer/FlatLayer.h | 2 +- .../level/newbiome/layer/FuzzyZoomLayer.cpp | 14 +- .../level/newbiome/layer/FuzzyZoomLayer.h | 2 +- .../layer/GrowMushroomIslandLayer.cpp | 6 +- .../newbiome/layer/GrowMushroomIslandLayer.h | 2 +- .../level/newbiome/layer/IslandLayer.cpp | 4 +- .../world/level/newbiome/layer/IslandLayer.h | 2 +- .../world/level/newbiome/layer/Layer.cpp | 4 +- .../world/level/newbiome/layer/Layer.h | 4 +- .../level/newbiome/layer/RegionHillsLayer.cpp | 6 +- .../level/newbiome/layer/RegionHillsLayer.h | 2 +- .../level/newbiome/layer/RiverInitLayer.cpp | 6 +- .../level/newbiome/layer/RiverInitLayer.h | 2 +- .../world/level/newbiome/layer/RiverLayer.cpp | 6 +- .../world/level/newbiome/layer/RiverLayer.h | 2 +- .../level/newbiome/layer/RiverMixerLayer.cpp | 8 +- .../level/newbiome/layer/RiverMixerLayer.h | 2 +- .../world/level/newbiome/layer/ShoreLayer.cpp | 6 +- .../world/level/newbiome/layer/ShoreLayer.h | 2 +- .../level/newbiome/layer/SmoothLayer.cpp | 6 +- .../world/level/newbiome/layer/SmoothLayer.h | 2 +- .../level/newbiome/layer/SmoothZoomLayer.cpp | 13 +- .../level/newbiome/layer/SmoothZoomLayer.h | 2 +- .../level/newbiome/layer/SwampRiversLayer.cpp | 6 +- .../level/newbiome/layer/SwampRiversLayer.h | 2 +- .../level/newbiome/layer/TemperatureLayer.cpp | 6 +- .../level/newbiome/layer/TemperatureLayer.h | 2 +- .../newbiome/layer/TemperatureMixerLayer.cpp | 8 +- .../newbiome/layer/TemperatureMixerLayer.h | 2 +- .../level/newbiome/layer/VoronoiZoom.cpp | 15 +- .../world/level/newbiome/layer/VoronoiZoom.h | 2 +- .../world/level/newbiome/layer/ZoomLayer.cpp | 14 +- .../world/level/newbiome/layer/ZoomLayer.h | 2 +- .../world/level/pathfinder/BinaryHeap.cpp | 11 +- .../world/level/pathfinder/BinaryHeap.h | 2 +- .../minecraft/world/level/pathfinder/Path.cpp | 21 +- .../minecraft/world/level/pathfinder/Path.h | 6 +- .../world/level/pathfinder/PathFinder.cpp | 20 +- .../world/level/pathfinder/PathFinder.h | 2 +- .../level/saveddata/MapItemSavedData.cpp | 59 ++--- .../world/level/saveddata/MapItemSavedData.h | 14 +- .../level/storage/DirectoryLevelStorage.cpp | 11 +- .../level/storage/DirectoryLevelStorage.h | 2 +- .../minecraft/world/level/tile/LeafTile.cpp | 2 +- .../net/minecraft/world/level/tile/Tile.cpp | 4 +- .../tile/entity/BrewingStandTileEntity.cpp | 35 ++- .../tile/entity/BrewingStandTileEntity.h | 8 +- .../level/tile/entity/ChestTileEntity.cpp | 42 ++-- .../world/level/tile/entity/ChestTileEntity.h | 2 +- .../level/tile/entity/DispenserTileEntity.cpp | 19 +- .../level/tile/entity/DispenserTileEntity.h | 2 +- .../level/tile/entity/FurnaceTileEntity.cpp | 28 +-- .../level/tile/entity/FurnaceTileEntity.h | 10 +- .../level/tile/entity/HopperTileEntity.cpp | 23 +- .../level/tile/entity/HopperTileEntity.h | 2 +- minecraft/java/include/java/Arrays.h | 28 +-- minecraft/java/include/java/ByteBuffer.h | 12 +- minecraft/java/include/java/FloatBuffer.h | 2 +- .../InputOutputStream/BufferedOutputStream.h | 6 +- .../InputOutputStream/ByteArrayInputStream.h | 12 +- .../InputOutputStream/ByteArrayOutputStream.h | 10 +- .../java/InputOutputStream/DataInput.h | 6 +- .../java/InputOutputStream/DataInputStream.h | 8 +- .../java/InputOutputStream/DataOutput.h | 4 +- .../java/InputOutputStream/DataOutputStream.h | 4 +- .../java/InputOutputStream/FileInputStream.h | 4 +- .../java/InputOutputStream/FileOutputStream.h | 4 +- .../java/InputOutputStream/GZIPInputStream.h | 4 +- .../java/InputOutputStream/GZIPOutputStream.h | 4 +- .../java/InputOutputStream/InputStream.h | 4 +- .../java/InputOutputStream/OutputStream.h | 4 +- minecraft/java/include/java/IntBuffer.h | 4 +- minecraft/java/include/java/System.h | 24 +- minecraft/java/src/ByteBuffer.cpp | 30 +-- minecraft/java/src/File.cpp | 4 +- minecraft/java/src/FloatBuffer.cpp | 8 +- .../BufferedOutputStream.cpp | 15 +- .../ByteArrayInputStream.cpp | 19 +- .../ByteArrayOutputStream.cpp | 27 +- .../src/InputOutputStream/DataInputStream.cpp | 32 +-- .../InputOutputStream/DataOutputStream.cpp | 13 +- .../src/InputOutputStream/FileInputStream.cpp | 10 +- .../InputOutputStream/FileOutputStream.cpp | 12 +- minecraft/java/src/IntBuffer.cpp | 18 +- minecraft/java/src/system.cpp | 38 +-- minecraft/nbt/include/nbt/ByteArrayTag.h | 22 +- minecraft/nbt/include/nbt/CompoundTag.h | 12 +- minecraft/nbt/include/nbt/IntArrayTag.h | 28 +-- minecraft/nbt/include/nbt/NbtIo.h | 4 +- minecraft/nbt/src/NbtIo.cpp | 8 +- minecraft/nbt/src/Tag.cpp | 2 +- 414 files changed, 2412 insertions(+), 2724 deletions(-) diff --git a/minecraft/Minecraft.Client/Common/Consoles_App.cpp b/minecraft/Minecraft.Client/Common/Consoles_App.cpp index f0d41d175..090eb50a9 100644 --- a/minecraft/Minecraft.Client/Common/Consoles_App.cpp +++ b/minecraft/Minecraft.Client/Common/Consoles_App.cpp @@ -2904,9 +2904,9 @@ void CMinecraftApp::HandleXuiActions(void) { // If there's a non-null level then, for our // purposes, the game has started bool gameStarted = false; - for (int j = 0; j < pMinecraft->levels.length; + for (int j = 0; j < pMinecraft->levels.size(); j++) { - if (pMinecraft->levels.data[j] != nullptr) { + if (pMinecraft->levels.data()[j] != nullptr) { gameStarted = true; break; } @@ -3683,9 +3683,8 @@ void CMinecraftApp::loadStringTable() { } std::wstring localisationFile = L"languages.loc"; if (m_mediaArchive->hasFile(localisationFile)) { - byteArray locFile = m_mediaArchive->getFile(localisationFile); - m_stringTable = new StringTable(locFile.data, locFile.length); - delete[] locFile.data; + std::vector locFile = m_mediaArchive->getFile(localisationFile); + m_stringTable = new StringTable(locFile.data(), locFile.size()); } else { m_stringTable = nullptr; assert(false); @@ -4713,12 +4712,12 @@ void CMinecraftApp::GetTPD(int iConfig, std::uint8_t** ppbData, // if(fileSize!=0) // { // FileInputStream fis(gtsFile); -// byteArray ba((int)fileSize); +// std::vector ba((int)fileSize); // fis.read(ba); // fis.close(); // // bRes=StorageManager.WriteTMSFile(iQuadrant,eStorageFacility,(wchar_t -// *)wsFile->c_str(),ba.data, ba.length); +// *)wsFile->c_str(),ba.data(), ba.size()); // // } // #endif @@ -7266,7 +7265,7 @@ bool CMinecraftApp::hasArchiveFile(const std::wstring& filename) { return m_mediaArchive->hasFile(filename); } -byteArray CMinecraftApp::getArchiveFile(const std::wstring& filename) { +std::vector CMinecraftApp::getArchiveFile(const std::wstring& filename) { TexturePack* tPack = nullptr; Minecraft* pMinecraft = Minecraft::GetInstance(); if (pMinecraft && pMinecraft->skins) diff --git a/minecraft/Minecraft.Client/Common/Consoles_App.h b/minecraft/Minecraft.Client/Common/Consoles_App.h index 154d054f4..b29e85540 100644 --- a/minecraft/Minecraft.Client/Common/Consoles_App.h +++ b/minecraft/Minecraft.Client/Common/Consoles_App.h @@ -501,7 +501,7 @@ protected: public: int getArchiveFileSize(const std::wstring& filename); bool hasArchiveFile(const std::wstring& filename); - byteArray getArchiveFile(const std::wstring& filename); + std::vector getArchiveFile(const std::wstring& filename); private: static int BannedLevelDialogReturned(void* pParam, int iPad, diff --git a/minecraft/Minecraft.Client/Common/Source Files/Colours/ColourTable.cpp b/minecraft/Minecraft.Client/Common/Source Files/Colours/ColourTable.cpp index 4e7fecc37..ba0c8c74f 100644 --- a/minecraft/Minecraft.Client/Common/Source Files/Colours/ColourTable.cpp +++ b/minecraft/Minecraft.Client/Common/Source Files/Colours/ColourTable.cpp @@ -343,7 +343,7 @@ ColourTable::ColourTable(ColourTable* defaultColours, std::uint8_t* pbData, } void ColourTable::loadColoursFromData(std::uint8_t* pbData, std::uint32_t dataLength) { - byteArray src(pbData, dataLength); + std::vector src(pbData, pbData + dataLength); ByteArrayInputStream bais(src); DataInputStream dis(&bais); diff --git a/minecraft/Minecraft.Client/Common/Source Files/DLC/DLCManager.cpp b/minecraft/Minecraft.Client/Common/Source Files/DLC/DLCManager.cpp index 108eba660..c8a05c5d0 100644 --- a/minecraft/Minecraft.Client/Common/Source Files/DLC/DLCManager.cpp +++ b/minecraft/Minecraft.Client/Common/Source Files/DLC/DLCManager.cpp @@ -393,8 +393,8 @@ bool DLCManager::readDLCDataFile(unsigned int& dwFilesProcessed, bool fromArchive) { std::wstring wPath = convStringToWstring(path); if (fromArchive && app.getArchiveFileSize(wPath) >= 0) { - byteArray bytes = app.getArchiveFile(wPath); - return processDLCDataFile(dwFilesProcessed, bytes.data, bytes.length, + std::vector bytes = app.getArchiveFile(wPath); + return processDLCDataFile(dwFilesProcessed, bytes.data(), bytes.size(), pack); } else if (fromArchive) return false; diff --git a/minecraft/Minecraft.Client/Common/Source Files/GameRules/GameRuleManager.cpp b/minecraft/Minecraft.Client/Common/Source Files/GameRules/GameRuleManager.cpp index 56ac2b884..26d0b7473 100644 --- a/minecraft/Minecraft.Client/Common/Source Files/GameRules/GameRuleManager.cpp +++ b/minecraft/Minecraft.Client/Common/Source Files/GameRules/GameRuleManager.cpp @@ -155,7 +155,8 @@ void GameRuleManager::loadGameRules(LevelGenerationOptions* lgo, uint8_t* dIn, unsigned int dSize) { app.DebugPrintf("GameRuleManager::LoadingGameRules:\n"); - ByteArrayInputStream bais(byteArray(dIn, dSize)); + std::vector inputBuf(dIn, dIn + dSize); + ByteArrayInputStream bais(inputBuf); DataInputStream dis(&bais); // Read file header. @@ -181,45 +182,43 @@ void GameRuleManager::loadGameRules(LevelGenerationOptions* lgo, uint8_t* dIn, // Decompress File Body - byteArray content(new std::uint8_t[decomp_len], decomp_len), - compr_content(new std::uint8_t[compr_len], compr_len); + std::vector content(decomp_len); + std::vector compr_content(compr_len); dis.read(compr_content); Compression::getCompression()->SetDecompressionType( (Compression::ECompressionTypes)compression_type); + unsigned int contentSize = decomp_len; Compression::getCompression()->DecompressLZXRLE( - content.data, &content.length, compr_content.data, - compr_content.length); + content.data(), &contentSize, compr_content.data(), + compr_content.size()); + content.resize(contentSize); Compression::getCompression()->SetDecompressionType( SAVE_FILE_PLATFORM_LOCAL); dis.close(); bais.close(); - delete[] compr_content.data; ByteArrayInputStream bais2(content); DataInputStream dis2(&bais2); // Read StringTable. - byteArray bStringTable; - bStringTable.length = dis2.readInt(); - bStringTable.data = new std::uint8_t[bStringTable.length]; + unsigned int bStringTableSize = dis2.readInt(); + std::vector bStringTable(bStringTableSize); dis2.read(bStringTable); StringTable* strings = - new StringTable(bStringTable.data, bStringTable.length); + new StringTable(bStringTable.data(), bStringTable.size()); // Read RuleFile. - byteArray bRuleFile; - bRuleFile.length = content.length - bStringTable.length; - bRuleFile.data = new std::uint8_t[bRuleFile.length]; + std::vector bRuleFile(content.size() - bStringTable.size()); dis2.read(bRuleFile); // 4J-JEV: I don't believe that the path-name is ever used. // DLCGameRulesFile *dlcgr = new DLCGameRulesFile(L"__PLACEHOLDER__"); - // dlcgr->addData(bRuleFile.data,bRuleFile.length); + // dlcgr->addData(bRuleFile.data(),bRuleFile.size()); - if (readRuleFile(lgo, bRuleFile.data, bRuleFile.length, strings)) { + if (readRuleFile(lgo, bRuleFile.data(), bRuleFile.size(), strings)) { // Set current gen options and ruleset. // createdLevelGenerationOptions->setFromSaveGame(true); lgo->setSrc(LevelGenerationOptions::eSrc_fromSave); @@ -229,7 +228,6 @@ void GameRuleManager::loadGameRules(LevelGenerationOptions* lgo, uint8_t* dIn, delete lgo; } - // delete [] content.data; // Close and return. dis2.close(); @@ -275,9 +273,9 @@ void GameRuleManager::saveGameRules(uint8_t** dOut, unsigned int* dSize) { compr_dos.writeByte( Compression::eCompressionType_None); // compression type for (int i = 0; i < 2; i++) compr_dos.writeByte(0x0); // Padding. - compr_dos.writeInt(0); // StringLookup.length - compr_dos.writeInt(0); // SchematicFiles.length - compr_dos.writeInt(0); // XmlObjects.length + compr_dos.writeInt(0); // StringLookup.size() + compr_dos.writeInt(0); // SchematicFiles.size() + compr_dos.writeInt(0); // XmlObjects.size() } else { StringTable* st = m_currentGameRuleDefinitions->getStringTable(); @@ -286,10 +284,12 @@ void GameRuleManager::saveGameRules(uint8_t** dOut, unsigned int* dSize) { "GameRuleManager::saveGameRules: StringTable == nullptr!"); } else { // Write string table. - byteArray stba; + uint8_t* stbaPtr = nullptr; + unsigned int stbaSize = 0; m_currentGameRuleDefinitions->getStringTable()->getData( - &stba.data, &stba.length); - compr_dos.writeInt(stba.length); + &stbaPtr, &stbaSize); + std::vector stba(stbaPtr, stbaPtr + stbaSize); + compr_dos.writeInt(stba.size()); compr_dos.write(stba); // Write game rule file to second @@ -299,30 +299,29 @@ void GameRuleManager::saveGameRules(uint8_t** dOut, unsigned int* dSize) { } // Compress compr_dos and write to dos. - byteArray compr_ba(new std::uint8_t[compr_baos.buf.length], - compr_baos.buf.length); + std::vector compr_ba(compr_baos.buf.size()); + unsigned int compr_ba_size = compr_ba.size(); Compression::getCompression()->CompressLZXRLE( - compr_ba.data, &compr_ba.length, compr_baos.buf.data, - compr_baos.buf.length); + compr_ba.data(), &compr_ba_size, compr_baos.buf.data(), + compr_baos.buf.size()); + compr_ba.resize(compr_ba_size); - app.DebugPrintf("\tcompr_ba.length=%d.\n\tcompr_baos.buf.length=%d.\n", - compr_ba.length, compr_baos.buf.length); + app.DebugPrintf("\tcompr_ba.size()=%d.\n\tcompr_baos.buf.size()=%d.\n", + compr_ba.size(), compr_baos.buf.size()); - dos.writeInt(compr_ba.length); // Write length - dos.writeInt(compr_baos.buf.length); + dos.writeInt(compr_ba.size()); // Write length + dos.writeInt(compr_baos.buf.size()); dos.write(compr_ba); - delete[] compr_ba.data; compr_dos.close(); compr_baos.close(); // -- END COMPRESSED -- // // return - *dSize = baos.buf.length; - *dOut = baos.buf.data; - - baos.buf.data = nullptr; + *dSize = baos.buf.size(); + *dOut = new uint8_t[baos.buf.size()]; + memcpy(*dOut, baos.buf.data(), baos.buf.size()); dos.close(); baos.close(); @@ -357,9 +356,9 @@ void GameRuleManager::writeRuleFile(DataOutputStream* dos) { file->save(&fileDos); dos->writeUTF(filename); - // dos->writeInt(file->m_data.length); - dos->writeInt(fileBaos.buf.length); - dos->write((byteArray)fileBaos.buf); + // dos->writeInt(file->m_data.size()); + dos->writeInt(fileBaos.buf.size()); + dos->write((std::vector)fileBaos.buf); fileDos.close(); fileBaos.close(); @@ -383,9 +382,9 @@ bool GameRuleManager::readRuleFile( // std::uint32_t dataLength = 0; // std::uint8_t *data = dlcFile->getData(dataLength); - // byteArray data(pbData,dwLen); + // std::vector data(pbData,dwLen); - byteArray data(dIn, dSize); + std::vector data(dIn, dIn + dSize); ByteArrayInputStream bais(data); DataInputStream dis(&bais); @@ -414,22 +413,24 @@ bool GameRuleManager::readRuleFile( } else { unsigned int uncompressedSize = dis.readInt(); unsigned int compressedSize = dis.readInt(); - byteArray compressedBuffer(compressedSize); + std::vector compressedBuffer(compressedSize); dis.read(compressedBuffer); - byteArray decompressedBuffer = byteArray(uncompressedSize); + std::vector decompressedBuffer = std::vector(uncompressedSize); + unsigned int decompressedSize = uncompressedSize; switch (compressionType) { case Compression::eCompressionType_None: - memcpy(decompressedBuffer.data, compressedBuffer.data, + memcpy(decompressedBuffer.data(), compressedBuffer.data(), uncompressedSize); break; case Compression::eCompressionType_RLE: app.DebugPrintf("De-compressing game rules with: RLE\n"); Compression::getCompression()->Decompress( - decompressedBuffer.data, &decompressedBuffer.length, - compressedBuffer.data, compressedSize); + decompressedBuffer.data(), &decompressedSize, + compressedBuffer.data(), compressedSize); + decompressedBuffer.resize(decompressedSize); break; default: @@ -441,8 +442,9 @@ bool GameRuleManager::readRuleFile( // compression type. (need to assert that the data is compressed // with it though). Compression::getCompression()->DecompressLZXRLE( - decompressedBuffer.data, &decompressedBuffer.length, - compressedBuffer.data, compressedSize); + decompressedBuffer.data(), &decompressedSize, + compressedBuffer.data(), compressedSize); + decompressedBuffer.resize(decompressedSize); break; /* 4J-JEV: Each platform has only 1 method of compression, @@ -452,21 +454,19 @@ bool GameRuleManager::readRuleFile( app.DebugPrintf("De-compressing game rules with: LZX+RLE\n"); Compression::getCompression()->DecompressLZXRLE( - decompressedBuffer.data, &uncompressedSize, - compressedBuffer.data, compressedSize); break; default: + decompressedBuffer.data(), &uncompressedSize, + compressedBuffer.data(), compressedSize); break; default: app.DebugPrintf("Invalid compression type %d found\n", compressionType); __debugbreak(); - delete [] compressedBuffer.data; delete - [] decompressedBuffer.data; dis.close(); bais.reset(); + [] decompressedBuffer.data(); dis.close(); bais.reset(); if(!gameRulesAdded) delete gameRules; return false; */ }; - delete[] compressedBuffer.data; contentBais = new ByteArrayInputStream(decompressedBuffer); contentDis = new DataInputStream(contentBais); @@ -513,11 +513,11 @@ bool GameRuleManager::readRuleFile( for (unsigned int i = 0; i < numFiles; i++) { std::wstring sFilename = contentDis->readUTF(); int length = contentDis->readInt(); - byteArray ba(length); + std::vector ba(length); contentDis->read(ba); - levelGenerator->loadSchematicFile(sFilename, ba.data, ba.length); + levelGenerator->loadSchematicFile(sFilename, ba.data(), ba.size()); } LEVEL_GEN_ID lgoID = LEVEL_GEN_ID_NULL; diff --git a/minecraft/Minecraft.Client/Common/Source Files/GameRules/LevelGeneration/ConsoleSchematicFile.cpp b/minecraft/Minecraft.Client/Common/Source Files/GameRules/LevelGeneration/ConsoleSchematicFile.cpp index 19806ddba..4a63c0e36 100644 --- a/minecraft/Minecraft.Client/Common/Source Files/GameRules/LevelGeneration/ConsoleSchematicFile.cpp +++ b/minecraft/Minecraft.Client/Common/Source Files/GameRules/LevelGeneration/ConsoleSchematicFile.cpp @@ -15,12 +15,11 @@ ConsoleSchematicFile::ConsoleSchematicFile() { m_xSize = m_ySize = m_zSize = 0; m_refCount = 1; - m_data.data = nullptr; + m_data.clear(); } ConsoleSchematicFile::~ConsoleSchematicFile() { app.DebugPrintf("Deleting schematic file\n"); - if (m_data.data != nullptr) delete[] m_data.data; } void ConsoleSchematicFile::save(DataOutputStream* dos) { @@ -33,16 +32,17 @@ void ConsoleSchematicFile::save(DataOutputStream* dos) { dos->writeInt(m_ySize); dos->writeInt(m_zSize); - byteArray ba(new std::uint8_t[m_data.length], m_data.length); + std::vector ba(m_data.size()); + unsigned int baSize = ba.size(); Compression::getCompression()->CompressLZXRLE( - ba.data, &ba.length, m_data.data, m_data.length); + ba.data(), &baSize, m_data.data(), m_data.size()); + ba.resize(baSize); - dos->writeInt(ba.length); + dos->writeInt(ba.size()); dos->write(ba); save_tags(dos); - delete[] ba.data; } } @@ -67,30 +67,30 @@ void ConsoleSchematicFile::load(DataInputStream* dis) { m_zSize = dis->readInt(); int compressedSize = dis->readInt(); - byteArray compressedBuffer(compressedSize); + std::vector compressedBuffer(compressedSize); dis->readFully(compressedBuffer); - if (m_data.data != nullptr) { - delete[] m_data.data; - m_data.data = nullptr; - } + m_data.clear(); if (compressionType == Compression::eCompressionType_None) { m_data = compressedBuffer; } else { unsigned int outputSize = m_xSize * m_ySize * m_zSize * 3 / 2; - m_data = byteArray(outputSize); + m_data = std::vector(outputSize); + unsigned int m_dataSize = outputSize; switch (compressionType) { case Compression::eCompressionType_RLE: Compression::getCompression()->DecompressRLE( - m_data.data, &m_data.length, compressedBuffer.data, + m_data.data(), &m_dataSize, compressedBuffer.data(), compressedSize); + m_data.resize(m_dataSize); break; case APPROPRIATE_COMPRESSION_TYPE: Compression::getCompression()->DecompressLZXRLE( - m_data.data, &m_data.length, compressedBuffer.data, + m_data.data(), &m_dataSize, compressedBuffer.data(), compressedSize); + m_data.resize(m_dataSize); break; default: app.DebugPrintf( @@ -100,13 +100,13 @@ void ConsoleSchematicFile::load(DataInputStream* dis) { Compression::getCompression()->SetDecompressionType( (Compression::ECompressionTypes)compressionType); Compression::getCompression()->DecompressLZXRLE( - m_data.data, &m_data.length, compressedBuffer.data, + m_data.data(), &m_dataSize, compressedBuffer.data(), compressedSize); + m_data.resize(m_dataSize); Compression::getCompression()->SetDecompressionType( APPROPRIATE_COMPRESSION_TYPE); }; - delete[] compressedBuffer.data; } // READ TAGS // @@ -212,11 +212,11 @@ int64_t ConsoleSchematicFile::applyBlocksAndData(LevelChunk* chunk, int rowBlockCount = getYSize() * getZSize(); int totalBlockCount = getXSize() * rowBlockCount; - byteArray blockData = byteArray(Level::CHUNK_TILE_COUNT); + std::vector blockData = std::vector(Level::CHUNK_TILE_COUNT); PIXBeginNamedEvent(0, "Getting block data"); chunk->getBlockData(blockData); PIXEndNamedEvent(); - byteArray dataData = byteArray(Level::HALF_CHUNK_TILE_COUNT); + std::vector dataData = std::vector(Level::HALF_CHUNK_TILE_COUNT); PIXBeginNamedEvent(0, "Getting Data data"); chunk->getDataData(dataData); PIXEndNamedEvent(); @@ -283,7 +283,7 @@ int64_t ConsoleSchematicFile::applyBlocksAndData(LevelChunk* chunk, } // 4J Stu - Hack for ME pack to replace sand with end stone in schematics - // for(int i = 0; i < blockData.length; ++i) + // for(int i = 0; i < blockData.size(); ++i) //{ // if(blockData[i] == Tile::sand_Id || blockData[i] == Tile::sandStone_Id) // { @@ -294,12 +294,10 @@ int64_t ConsoleSchematicFile::applyBlocksAndData(LevelChunk* chunk, PIXBeginNamedEvent(0, "Setting Block data"); chunk->setBlockData(blockData); PIXEndNamedEvent(); - delete[] blockData.data; // 4jcraft changed to array delete chunk->recalcHeightmapOnly(); PIXBeginNamedEvent(0, "Setting Data data"); chunk->setDataData(dataData); PIXEndNamedEvent(); - delete[] dataData.data; // 4jcraft, same here // A basic pass through to roughly do the lighting. At this point of // post-processing, we don't have all the neighbouring chunks loaded in, so @@ -627,11 +625,11 @@ void ConsoleSchematicFile::generateSchematicFile( // Write zSize if (dos != nullptr) dos->writeInt(zSize); - // byteArray rawBuffer = level->getBlocksAndData(xStart, yStart, zStart, + // std::vector rawBuffer = level->getBlocksAndData(xStart, yStart, zStart, // xSize, ySize, zSize, false); int xRowSize = ySize * zSize; int blockCount = xSize * xRowSize; - byteArray result(blockCount * 3 / 2); + std::vector result(blockCount * 3 / 2); // Position pointers into the data when not ordered by chunk int p = 0; @@ -679,24 +677,23 @@ void ConsoleSchematicFile::generateSchematicFile( switch (compressionType) { case Compression::eCompressionType_LZXRLE: Compression::getCompression()->CompressLZXRLE( - ucTemp, &inputSize, result.data, (unsigned int)result.length); + ucTemp, &inputSize, result.data(), (unsigned int)result.size()); break; case Compression::eCompressionType_RLE: Compression::getCompression()->CompressRLE( - ucTemp, &inputSize, result.data, (unsigned int)result.length); + ucTemp, &inputSize, result.data(), (unsigned int)result.size()); break; case Compression::eCompressionType_None: default: - memcpy(ucTemp, result.data, inputSize); + memcpy(ucTemp, result.data(), inputSize); break; }; - delete[] result.data; - byteArray buffer = byteArray(ucTemp, inputSize); + std::vector buffer = std::vector(ucTemp, ucTemp + inputSize); + delete[] ucTemp; if (dos != nullptr) dos->writeInt(inputSize); if (dos != nullptr) dos->write(buffer); - delete[] buffer.data; CompoundTag tag; ListTag* tileEntitiesTag = @@ -785,7 +782,7 @@ void ConsoleSchematicFile::generateSchematicFile( if (dos != nullptr) NbtIo::write(&tag, dos); } -void ConsoleSchematicFile::getBlocksAndData(LevelChunk* chunk, byteArray* data, +void ConsoleSchematicFile::getBlocksAndData(LevelChunk* chunk, std::vector* data, int x0, int y0, int z0, int x1, int y1, int z1, int& blocksP, int& dataP, int& blockLightP, @@ -797,21 +794,21 @@ void ConsoleSchematicFile::getBlocksAndData(LevelChunk* chunk, byteArray* data, // int zs = z1 - z0; // if (xs * ys * zs == LevelChunk::BLOCKS_LENGTH) //{ - // byteArray blockData = byteArray(data->data + blocksP, + // std::vector blockData = std::vector(data->data + blocksP, // Level::CHUNK_TILE_COUNT); chunk->getBlockData(blockData); - // blocksP += blockData.length; + // blocksP += blockData.size(); - // byteArray dataData = byteArray(data->data + dataP, 16384); + // std::vector dataData = std::vector(data->data + dataP, 16384); // chunk->getBlockLightData(dataData); - // dataP += dataData.length; + // dataP += dataData.size(); - // byteArray blockLightData = byteArray(data->data + blockLightP, 16384); + // std::vector blockLightData = std::vector(data->data + blockLightP, 16384); // chunk->getBlockLightData(blockLightData); - // blockLightP += blockLightData.length; + // blockLightP += blockLightData.size(); - // byteArray skyLightData = byteArray(data->data + skyLightP, 16384); + // std::vector skyLightData = std::vector(data->data + skyLightP, 16384); // chunk->getSkyLightData(skyLightData); - // skyLightP += skyLightData.length; + // skyLightP += skyLightData.size(); // return; //} @@ -834,7 +831,7 @@ void ConsoleSchematicFile::getBlocksAndData(LevelChunk* chunk, byteArray* data, bHasUpper = true; } - byteArray blockData = byteArray(Level::CHUNK_TILE_COUNT); + std::vector blockData = std::vector(Level::CHUNK_TILE_COUNT); chunk->getBlockData(blockData); for (int x = x0; x < x1; x++) for (int z = z0; z < z1; z++) { @@ -842,7 +839,7 @@ void ConsoleSchematicFile::getBlocksAndData(LevelChunk* chunk, byteArray* data, int slot = x << Level::genDepthBitsPlusFour | z << Level::genDepthBits | lowerY0; int len = lowerY1 - lowerY0; - System::arraycopy(blockData, slot, data, blocksP, len); + std::copy(blockData.data() + slot, blockData.data() + slot + len, data->data() + blocksP); blocksP += len; } if (bHasUpper) { @@ -850,13 +847,12 @@ void ConsoleSchematicFile::getBlocksAndData(LevelChunk* chunk, byteArray* data, z << Level::genDepthBits | upperY0) + Level::COMPRESSED_CHUNK_SECTION_TILES; int len = upperY1 - upperY0; - System::arraycopy(blockData, slot, data, blocksP, len); + std::copy(blockData.data() + slot, blockData.data() + slot + len, data->data() + blocksP); blocksP += len; } } - delete blockData.data; - byteArray dataData = byteArray(Level::CHUNK_TILE_COUNT); + std::vector dataData = std::vector(Level::CHUNK_TILE_COUNT); chunk->getDataData(dataData); for (int x = x0; x < x1; x++) for (int z = z0; z < z1; z++) { @@ -865,7 +861,7 @@ void ConsoleSchematicFile::getBlocksAndData(LevelChunk* chunk, byteArray* data, z << Level::genDepthBits | lowerY0) >> 1; int len = (lowerY1 - lowerY0) / 2; - System::arraycopy(dataData, slot, data, dataP, len); + std::copy(dataData.data() + slot, dataData.data() + slot + len, data->data() + dataP); dataP += len; } if (bHasUpper) { @@ -874,15 +870,14 @@ void ConsoleSchematicFile::getBlocksAndData(LevelChunk* chunk, byteArray* data, Level::COMPRESSED_CHUNK_SECTION_TILES) >> 1; int len = (upperY1 - upperY0) / 2; - System::arraycopy(dataData, slot, data, dataP, len); + std::copy(dataData.data() + slot, dataData.data() + slot + len, data->data() + dataP); dataP += len; } } - delete dataData.data; // 4J Stu - Allow ignoring light data if (blockLightP > -1) { - byteArray blockLightData = byteArray(Level::HALF_CHUNK_TILE_COUNT); + std::vector blockLightData = std::vector(Level::HALF_CHUNK_TILE_COUNT); chunk->getBlockLightData(blockLightData); for (int x = x0; x < x1; x++) for (int z = z0; z < z1; z++) { @@ -891,8 +886,7 @@ void ConsoleSchematicFile::getBlocksAndData(LevelChunk* chunk, byteArray* data, z << Level::genDepthBits | lowerY0) >> 1; int len = (lowerY1 - lowerY0) / 2; - System::arraycopy(blockLightData, slot, data, blockLightP, - len); + std::copy(blockLightData.data() + slot, blockLightData.data() + slot + len, data->data() + blockLightP); blockLightP += len; } if (bHasUpper) { @@ -901,17 +895,15 @@ void ConsoleSchematicFile::getBlocksAndData(LevelChunk* chunk, byteArray* data, 1) + (Level::COMPRESSED_CHUNK_SECTION_TILES / 2); int len = (upperY1 - upperY0) / 2; - System::arraycopy(blockLightData, slot, data, blockLightP, - len); + std::copy(blockLightData.data() + slot, blockLightData.data() + slot + len, data->data() + blockLightP); blockLightP += len; } } - delete blockLightData.data; } // 4J Stu - Allow ignoring light data if (skyLightP > -1) { - byteArray skyLightData = byteArray(Level::HALF_CHUNK_TILE_COUNT); + std::vector skyLightData = std::vector(Level::HALF_CHUNK_TILE_COUNT); chunk->getSkyLightData(skyLightData); for (int x = x0; x < x1; x++) for (int z = z0; z < z1; z++) { @@ -920,7 +912,7 @@ void ConsoleSchematicFile::getBlocksAndData(LevelChunk* chunk, byteArray* data, z << Level::genDepthBits | lowerY0) >> 1; int len = (lowerY1 - lowerY0) / 2; - System::arraycopy(skyLightData, slot, data, skyLightP, len); + std::copy(skyLightData.data() + slot, skyLightData.data() + slot + len, data->data() + skyLightP); skyLightP += len; } if (bHasUpper) { @@ -929,19 +921,18 @@ void ConsoleSchematicFile::getBlocksAndData(LevelChunk* chunk, byteArray* data, 1) + (Level::COMPRESSED_CHUNK_SECTION_TILES / 2); int len = (upperY1 - upperY0) / 2; - System::arraycopy(skyLightData, slot, data, skyLightP, len); + std::copy(skyLightData.data() + slot, skyLightData.data() + slot + len, data->data() + skyLightP); skyLightP += len; } } - delete skyLightData.data; } return; } void ConsoleSchematicFile::setBlocksAndData( - LevelChunk* chunk, byteArray blockData, byteArray dataData, - byteArray inputData, int x0, int y0, int z0, int x1, int y1, int z1, + LevelChunk* chunk, std::vector& blockData, std::vector& dataData, + std::vector inputData, int x0, int y0, int z0, int x1, int y1, int z1, int& blocksP, int& dataP, int& blockLightP, int& skyLightP) { bool bHasLower, bHasUpper; bHasLower = bHasUpper = false; @@ -968,7 +959,7 @@ void ConsoleSchematicFile::setBlocksAndData( int slot = x << Level::genDepthBitsPlusFour | z << Level::genDepthBits | lowerY0; int len = lowerY1 - lowerY0; - System::arraycopy(inputData, blocksP, &blockData, slot, len); + std::copy(inputData.data() + blocksP, inputData.data() + blocksP + len, blockData.data() + slot); blocksP += len; } if (bHasUpper) { @@ -976,7 +967,7 @@ void ConsoleSchematicFile::setBlocksAndData( z << Level::genDepthBits | upperY0) + Level::COMPRESSED_CHUNK_SECTION_TILES; int len = upperY1 - upperY0; - System::arraycopy(inputData, blocksP, &blockData, slot, len); + std::copy(inputData.data() + blocksP, inputData.data() + blocksP + len, blockData.data() + slot); blocksP += len; } } @@ -990,7 +981,7 @@ void ConsoleSchematicFile::setBlocksAndData( z << Level::genDepthBits | lowerY0) >> 1; int len = (lowerY1 - lowerY0) / 2; - System::arraycopy(inputData, dataP, &dataData, slot, len); + std::copy(inputData.data() + dataP, inputData.data() + dataP + len, dataData.data() + slot); dataP += len; } if (bHasUpper) { @@ -999,14 +990,14 @@ void ConsoleSchematicFile::setBlocksAndData( Level::COMPRESSED_CHUNK_SECTION_TILES) >> 1; int len = (upperY1 - upperY0) / 2; - System::arraycopy(inputData, dataP, &dataData, slot, len); + std::copy(inputData.data() + dataP, inputData.data() + dataP + len, dataData.data() + slot); dataP += len; } } PIXEndNamedEvent(); // 4J Stu - Allow ignoring light data if (blockLightP > -1) { - byteArray blockLightData = byteArray(Level::HALF_CHUNK_TILE_COUNT); + std::vector blockLightData = std::vector(Level::HALF_CHUNK_TILE_COUNT); chunk->getBlockLightData(blockLightData); for (int x = x0; x < x1; x++) for (int z = z0; z < z1; z++) { @@ -1015,8 +1006,7 @@ void ConsoleSchematicFile::setBlocksAndData( z << Level::genDepthBits | lowerY0) >> 1; int len = (lowerY1 - lowerY0) / 2; - System::arraycopy(inputData, blockLightP, &blockLightData, - slot, len); + std::copy(inputData.data() + blockLightP, inputData.data() + blockLightP + len, blockLightData.data() + slot); blockLightP += len; } if (bHasUpper) { @@ -1025,18 +1015,16 @@ void ConsoleSchematicFile::setBlocksAndData( 1) + (Level::COMPRESSED_CHUNK_SECTION_TILES / 2); int len = (upperY1 - upperY0) / 2; - System::arraycopy(inputData, blockLightP, &blockLightData, - slot, len); + std::copy(inputData.data() + blockLightP, inputData.data() + blockLightP + len, blockLightData.data() + slot); blockLightP += len; } } chunk->setBlockLightData(blockLightData); - delete blockLightData.data; } // 4J Stu - Allow ignoring light data if (skyLightP > -1) { - byteArray skyLightData = byteArray(Level::HALF_CHUNK_TILE_COUNT); + std::vector skyLightData = std::vector(Level::HALF_CHUNK_TILE_COUNT); chunk->getSkyLightData(skyLightData); for (int x = x0; x < x1; x++) for (int z = z0; z < z1; z++) { @@ -1045,8 +1033,7 @@ void ConsoleSchematicFile::setBlocksAndData( z << Level::genDepthBits | lowerY0) >> 1; int len = (lowerY1 - lowerY0) / 2; - System::arraycopy(inputData, skyLightP, &skyLightData, slot, - len); + std::copy(inputData.data() + skyLightP, inputData.data() + skyLightP + len, skyLightData.data() + slot); skyLightP += len; } if (bHasUpper) { @@ -1054,13 +1041,11 @@ void ConsoleSchematicFile::setBlocksAndData( z << Level::genDepthBits | upperY0) + (Level::COMPRESSED_CHUNK_SECTION_TILES / 2); int len = (upperY1 - upperY0) / 2; - System::arraycopy(inputData, skyLightP, &skyLightData, slot, - len); + std::copy(inputData.data() + skyLightP, inputData.data() + skyLightP + len, skyLightData.data() + slot); skyLightP += len; } } chunk->setSkyLightData(skyLightData); - delete skyLightData.data; } } diff --git a/minecraft/Minecraft.Client/Common/Source Files/GameRules/LevelGeneration/ConsoleSchematicFile.h b/minecraft/Minecraft.Client/Common/Source Files/GameRules/LevelGeneration/ConsoleSchematicFile.h index b7b0df583..7a0493ff2 100644 --- a/minecraft/Minecraft.Client/Common/Source Files/GameRules/LevelGeneration/ConsoleSchematicFile.h +++ b/minecraft/Minecraft.Client/Common/Source Files/GameRules/LevelGeneration/ConsoleSchematicFile.h @@ -57,7 +57,7 @@ private: std::vector > m_entities; public: - byteArray m_data; + std::vector m_data; public: ConsoleSchematicFile(); @@ -82,8 +82,8 @@ public: int xEnd, int yEnd, int zEnd, bool bSaveMobs, Compression::ECompressionTypes); - static void setBlocksAndData(LevelChunk* chunk, byteArray blockData, - byteArray dataData, byteArray data, int x0, + static void setBlocksAndData(LevelChunk* chunk, std::vector& blockData, + std::vector& dataData, std::vector data, int x0, int y0, int z0, int x1, int y1, int z1, int& blocksP, int& dataP, int& blockLightP, int& skyLightP); @@ -92,7 +92,7 @@ private: void save_tags(DataOutputStream* dos); void load_tags(DataInputStream* dis); - static void getBlocksAndData(LevelChunk* chunk, byteArray* data, int x0, + static void getBlocksAndData(LevelChunk* chunk, std::vector* data, int x0, int y0, int z0, int x1, int y1, int z1, int& blocksP, int& dataP, int& blockLightP, int& skyLightP); diff --git a/minecraft/Minecraft.Client/Common/Source Files/GameRules/LevelGeneration/LevelGenerationOptions.cpp b/minecraft/Minecraft.Client/Common/Source Files/GameRules/LevelGeneration/LevelGenerationOptions.cpp index 8c1091ce0..66d262e3f 100644 --- a/minecraft/Minecraft.Client/Common/Source Files/GameRules/LevelGeneration/LevelGenerationOptions.cpp +++ b/minecraft/Minecraft.Client/Common/Source Files/GameRules/LevelGeneration/LevelGenerationOptions.cpp @@ -360,7 +360,7 @@ ConsoleSchematicFile* LevelGenerationOptions::loadSchematicFile( } ConsoleSchematicFile* schematic = nullptr; - byteArray data(pbData, dataLength); + std::vector data(pbData, pbData + dataLength); ByteArrayInputStream bais(data); DataInputStream dis(&bais); schematic = new ConsoleSchematicFile(); diff --git a/minecraft/Minecraft.Client/Common/Source Files/Leaderboards/SonyLeaderboardManager.cpp b/minecraft/Minecraft.Client/Common/Source Files/Leaderboards/SonyLeaderboardManager.cpp index 2bd9938ce..f9a23c375 100644 --- a/minecraft/Minecraft.Client/Common/Source Files/Leaderboards/SonyLeaderboardManager.cpp +++ b/minecraft/Minecraft.Client/Common/Source Files/Leaderboards/SonyLeaderboardManager.cpp @@ -973,7 +973,7 @@ void SonyLeaderboardManager::initReadScoreStruct(ReadScore& out, // Convert to std::wstring and copy name. std::wstring wstrName = - convStringToWstring(std::string(rankData.npId.handle.data)).c_str(); + convStringToWstring(std::string(rankData.npId.handle.data())).c_str(); // memcpy(&out.m_name, wstrName.c_str(), XUSER_NAME_SIZE); out.m_name = wstrName; } diff --git a/minecraft/Minecraft.Client/Common/Source Files/Localisation/StringTable.cpp b/minecraft/Minecraft.Client/Common/Source Files/Localisation/StringTable.cpp index a667d1a3f..f92a32b16 100644 --- a/minecraft/Minecraft.Client/Common/Source Files/Localisation/StringTable.cpp +++ b/minecraft/Minecraft.Client/Common/Source Files/Localisation/StringTable.cpp @@ -6,7 +6,7 @@ StringTable::StringTable(void) {} // Load string table from a binary blob, filling out with the current // localisation data only StringTable::StringTable(std::uint8_t* pbData, unsigned int dataSize) { - src = byteArray(pbData, dataSize); + src = std::vector(pbData, pbData + dataSize); ProcessStringTableData(); } @@ -67,7 +67,7 @@ void StringTable::ProcessStringTableData(void) { if (foundLang) { dis.skip(bytesToSkip); - byteArray langData(dataSize); + std::vector langData(dataSize); dis.read(langData); dis.close(); @@ -119,12 +119,12 @@ void StringTable::ProcessStringTableData(void) { } StringTable::~StringTable(void) { - // delete src.data; TODO 4J-JEV: ? + // delete src.data(); TODO 4J-JEV: ? } void StringTable::getData(std::uint8_t** ppData, unsigned int* pSize) { - *ppData = src.data; - *pSize = src.length; + *ppData = src.data(); + *pSize = src.size(); } const wchar_t* StringTable::getString(const std::wstring& id) { diff --git a/minecraft/Minecraft.Client/Common/Source Files/Localisation/StringTable.h b/minecraft/Minecraft.Client/Common/Source Files/Localisation/StringTable.h index 67fdb622d..f7ebafec4 100644 --- a/minecraft/Minecraft.Client/Common/Source Files/Localisation/StringTable.h +++ b/minecraft/Minecraft.Client/Common/Source Files/Localisation/StringTable.h @@ -11,7 +11,7 @@ private: std::unordered_map m_stringsMap; std::vector m_stringsVec; - byteArray src; + std::vector src; public: // enum eLocale diff --git a/minecraft/Minecraft.Client/Common/Source Files/Network/Socket.cpp b/minecraft/Minecraft.Client/Common/Source Files/Network/Socket.cpp index 01bbef44b..c6c472e74 100644 --- a/minecraft/Minecraft.Client/Common/Source Files/Network/Socket.cpp +++ b/minecraft/Minecraft.Client/Common/Source Files/Network/Socket.cpp @@ -265,13 +265,13 @@ int Socket::SocketInputStreamLocal::read() { // Try and get an input array of bytes, blocking until enough bytes are // available -int Socket::SocketInputStreamLocal::read(byteArray b) { - return read(b, 0, b.length); +int Socket::SocketInputStreamLocal::read(std::vector& b) { + return read(b, 0, b.size()); } // Try and get an input range of bytes, blocking until enough bytes are // available -int Socket::SocketInputStreamLocal::read(byteArray b, unsigned int offset, +int Socket::SocketInputStreamLocal::read(std::vector& b, unsigned int offset, unsigned int length) { while (m_streamOpen) { { @@ -318,11 +318,11 @@ void Socket::SocketOutputStreamLocal::write(unsigned int b) { } } -void Socket::SocketOutputStreamLocal::write(byteArray b) { - write(b, 0, b.length); +void Socket::SocketOutputStreamLocal::write(const std::vector& b) { + write(b, 0, b.size()); } -void Socket::SocketOutputStreamLocal::write(byteArray b, unsigned int offset, +void Socket::SocketOutputStreamLocal::write(const std::vector& b, unsigned int offset, unsigned int length) { if (m_streamOpen != true) { return; @@ -378,13 +378,13 @@ int Socket::SocketInputStreamNetwork::read() { // Try and get an input array of bytes, blocking until enough bytes are // available -int Socket::SocketInputStreamNetwork::read(byteArray b) { - return read(b, 0, b.length); +int Socket::SocketInputStreamNetwork::read(std::vector& b) { + return read(b, 0, b.size()); } // Try and get an input range of bytes, blocking until enough bytes are // available -int Socket::SocketInputStreamNetwork::read(byteArray b, unsigned int offset, +int Socket::SocketInputStreamNetwork::read(std::vector& b, unsigned int offset, unsigned int length) { while (m_streamOpen) { { @@ -420,24 +420,21 @@ Socket::SocketOutputStreamNetwork::SocketOutputStreamNetwork(Socket* socket, void Socket::SocketOutputStreamNetwork::write(unsigned int b) { if (m_streamOpen != true) return; - byteArray barray; - std::uint8_t bb; - bb = (std::uint8_t)b; - barray.data = &bb; - barray.length = 1; + std::uint8_t bb = (std::uint8_t)b; + std::vector barray(1, bb); write(barray, 0, 1); } -void Socket::SocketOutputStreamNetwork::write(byteArray b) { - write(b, 0, b.length); +void Socket::SocketOutputStreamNetwork::write(const std::vector& b) { + write(b, 0, b.size()); } -void Socket::SocketOutputStreamNetwork::write(byteArray b, unsigned int offset, +void Socket::SocketOutputStreamNetwork::write(const std::vector& b, unsigned int offset, unsigned int length) { writeWithFlags(b, offset, length, 0); } -void Socket::SocketOutputStreamNetwork::writeWithFlags(byteArray b, +void Socket::SocketOutputStreamNetwork::writeWithFlags(const std::vector& b, unsigned int offset, unsigned int length, int flags) { @@ -463,7 +460,7 @@ void Socket::SocketOutputStreamNetwork::writeWithFlags(byteArray b, } } else { XRNM_SEND_BUFFER buffer; - buffer.pbyData = &b[offset]; + buffer.pbyData = const_cast(&b[offset]); buffer.dwDataSize = length; INetworkPlayer* hostPlayer = g_NetworkManager.GetHostPlayer(); diff --git a/minecraft/Minecraft.Client/Common/Source Files/Network/Socket.h b/minecraft/Minecraft.Client/Common/Source Files/Network/Socket.h index f17b60589..0e45e10d4 100644 --- a/minecraft/Minecraft.Client/Common/Source Files/Network/Socket.h +++ b/minecraft/Minecraft.Client/Common/Source Files/Network/Socket.h @@ -27,7 +27,7 @@ public: class SocketOutputStream : public OutputStream { public: // The flags are those that can be used for the QNet SendData function - virtual void writeWithFlags(byteArray b, unsigned int offset, + virtual void writeWithFlags(const std::vector& b, unsigned int offset, unsigned int length, int flags) { write(b, offset, length); } @@ -45,8 +45,8 @@ private: SocketInputStreamLocal(int queueIdx); virtual int read(); - virtual int read(byteArray b); - virtual int read(byteArray b, unsigned int offset, unsigned int length); + virtual int read(std::vector& b); + virtual int read(std::vector& b, unsigned int offset, unsigned int length); virtual void close(); virtual int64_t skip(int64_t n) { return n; @@ -65,8 +65,8 @@ private: SocketOutputStreamLocal(int queueIdx); virtual void write(unsigned int b); - virtual void write(byteArray b); - virtual void write(byteArray b, unsigned int offset, + virtual void write(const std::vector& b); + virtual void write(const std::vector& b, unsigned int offset, unsigned int length); virtual void close(); virtual void flush() {} @@ -81,8 +81,8 @@ private: SocketInputStreamNetwork(Socket* socket, int queueIdx); virtual int read(); - virtual int read(byteArray b); - virtual int read(byteArray b, unsigned int offset, unsigned int length); + virtual int read(std::vector& b); + virtual int read(std::vector& b, unsigned int offset, unsigned int length); virtual void close(); virtual int64_t skip(int64_t n) { return n; @@ -98,10 +98,10 @@ private: SocketOutputStreamNetwork(Socket* socket, int queueIdx); virtual void write(unsigned int b); - virtual void write(byteArray b); - virtual void write(byteArray b, unsigned int offset, + virtual void write(const std::vector& b); + virtual void write(const std::vector& b, unsigned int offset, unsigned int length); - virtual void writeWithFlags(byteArray b, unsigned int offset, + virtual void writeWithFlags(const std::vector& b, unsigned int offset, unsigned int length, int flags); virtual void close(); virtual void flush() {} diff --git a/minecraft/Minecraft.Client/Common/Source Files/UI/All Platforms/ArchiveFile.cpp b/minecraft/Minecraft.Client/Common/Source Files/UI/All Platforms/ArchiveFile.cpp index 15e26f8d2..4e49486c1 100644 --- a/minecraft/Minecraft.Client/Common/Source Files/UI/All Platforms/ArchiveFile.cpp +++ b/minecraft/Minecraft.Client/Common/Source Files/UI/All Platforms/ArchiveFile.cpp @@ -45,13 +45,13 @@ ArchiveFile::ArchiveFile(File file) { FileInputStream fis(file); #if defined(_WINDOWS64) - byteArray readArray(file.length()); + std::vector readArray(file.length()); fis.read(readArray, 0, file.length()); ByteArrayInputStream bais(readArray); DataInputStream dis(&bais); - m_cachedData = readArray.data; + m_cachedData = readArray.data(); #else DataInputStream dis(&fis); #endif @@ -86,8 +86,8 @@ int ArchiveFile::getFileSize(const std::wstring& filename) { return hasFile(filename) ? m_index.at(filename)->filesize : -1; } -byteArray ArchiveFile::getFile(const std::wstring& filename) { - byteArray out; +std::vector ArchiveFile::getFile(const std::wstring& filename) { + std::vector out; auto it = m_index.find(filename); if (it == m_index.end()) { @@ -102,17 +102,17 @@ byteArray ArchiveFile::getFile(const std::wstring& filename) { PMetaData data = it->second; #if defined(_WINDOWS64) - out = byteArray(data->filesize); + out = std::vector(data->filesize); - memcpy(out.data, m_cachedData + data->ptr, data->filesize); + memcpy(out.data(), m_cachedData + data->ptr, data->filesize); #else const unsigned int fileSize = static_cast(data->filesize); std::uint8_t* pbData = new std::uint8_t[fileSize == 0 ? 1 : fileSize]; - out = byteArray(pbData, fileSize); + out = std::vector(pbData, pbData + fileSize); const PortableFileIO::BinaryReadResult readResult = PortableFileIO::ReadBinaryFileSegment( m_sourcefile.getPath(), static_cast(data->ptr), - out.data, static_cast(data->filesize)); + out.data(), static_cast(data->filesize)); if (readResult.status != PortableFileIO::BinaryReadStatus::ok) { app.DebugPrintf("Failed to read archive file segment\n"); @@ -121,7 +121,7 @@ byteArray ArchiveFile::getFile(const std::wstring& filename) { #endif // Compressed filenames are preceeded with an asterisk. - if (data->isCompressed && out.data != nullptr) { + if (data->isCompressed && !out.empty()) { /* 4J-JEV: * If a compressed file is accessed before compression object is * initialized it will crash here (Compression::getCompression). @@ -136,16 +136,15 @@ byteArray ArchiveFile::getFile(const std::wstring& filename) { std::uint8_t* uncompressedBuffer = new std::uint8_t[decompressedSize]; Compression::getCompression()->Decompress( - uncompressedBuffer, &decompressedSize, out.data + 4, - out.length - 4); + uncompressedBuffer, &decompressedSize, out.data() + 4, + out.size() - 4); - delete[] out.data; - out.data = uncompressedBuffer; - out.length = decompressedSize; + out = std::vector(uncompressedBuffer, uncompressedBuffer + decompressedSize); + delete[] uncompressedBuffer; } - assert(out.data != nullptr); // THERE IS NO FILE WITH THIS NAME! + assert(!out.empty()); // THERE IS NO FILE WITH THIS NAME! } return out; diff --git a/minecraft/Minecraft.Client/Common/Source Files/UI/All Platforms/ArchiveFile.h b/minecraft/Minecraft.Client/Common/Source Files/UI/All Platforms/ArchiveFile.h index 5c88db24d..1c74d0d98 100644 --- a/minecraft/Minecraft.Client/Common/Source Files/UI/All Platforms/ArchiveFile.h +++ b/minecraft/Minecraft.Client/Common/Source Files/UI/All Platforms/ArchiveFile.h @@ -31,5 +31,5 @@ public: std::vector* getFileList(); bool hasFile(const std::wstring& filename); int getFileSize(const std::wstring& filename); - byteArray getFile(const std::wstring& filename); + std::vector getFile(const std::wstring& filename); }; diff --git a/minecraft/Minecraft.Client/Common/Source Files/UI/All Platforms/IUIScene_AnvilMenu.cpp b/minecraft/Minecraft.Client/Common/Source Files/UI/All Platforms/IUIScene_AnvilMenu.cpp index 0048b675d..6c6d6c63d 100644 --- a/minecraft/Minecraft.Client/Common/Source Files/UI/All Platforms/IUIScene_AnvilMenu.cpp +++ b/minecraft/Minecraft.Client/Common/Source Files/UI/All Platforms/IUIScene_AnvilMenu.cpp @@ -198,7 +198,7 @@ void IUIScene_AnvilMenu::updateItemName() { m_repairMenu->setItemName(m_itemName); - // Convert to byteArray + // Convert to std::vector ByteArrayOutputStream baos; DataOutputStream dos(&baos); dos.writeUTF(m_itemName); diff --git a/minecraft/Minecraft.Client/Common/Source Files/UI/All Platforms/IUIScene_BeaconMenu.cpp b/minecraft/Minecraft.Client/Common/Source Files/UI/All Platforms/IUIScene_BeaconMenu.cpp index 2295874d1..ba2ad0c8b 100644 --- a/minecraft/Minecraft.Client/Common/Source Files/UI/All Platforms/IUIScene_BeaconMenu.cpp +++ b/minecraft/Minecraft.Client/Common/Source Files/UI/All Platforms/IUIScene_BeaconMenu.cpp @@ -267,7 +267,7 @@ void IUIScene_BeaconMenu::handleTick() { m_initPowerButtons = false; for (int tier = 0; tier <= 2; tier++) { int count = BeaconTileEntity:: - BEACON_EFFECTS_EFFECTS; // BEACON_EFFECTS[tier].length; + BEACON_EFFECTS_EFFECTS; // BEACON_EFFECTS[tier].size(); int totalWidth = count * 22 + (count - 1) * 2; for (int c = 0; c < count; c++) { @@ -295,7 +295,7 @@ void IUIScene_BeaconMenu::handleTick() { int tier = 3; int count = BeaconTileEntity::BEACON_EFFECTS_EFFECTS + - 1; // BEACON_EFFECTS[tier].length + 1; + 1; // BEACON_EFFECTS[tier].size() + 1; int totalWidth = count * 22 + (count - 1) * 2; for (int c = 0; c < count - 1; c++) { diff --git a/minecraft/Minecraft.Client/Common/Source Files/UI/All Platforms/IUIScene_CraftingMenu.cpp b/minecraft/Minecraft.Client/Common/Source Files/UI/All Platforms/IUIScene_CraftingMenu.cpp index be0a4bbfb..575ff6f11 100644 --- a/minecraft/Minecraft.Client/Common/Source Files/UI/All Platforms/IUIScene_CraftingMenu.cpp +++ b/minecraft/Minecraft.Client/Common/Source Files/UI/All Platforms/IUIScene_CraftingMenu.cpp @@ -614,7 +614,7 @@ void IUIScene_CraftingMenu::CheckRecipesAvailable() { if (m_pPlayer && m_pPlayer->inventory) { // dump out the inventory /* for (unsigned int k = 0; k < - m_pPlayer->inventory->items.length; k++) + m_pPlayer->inventory->items.size(); k++) { if (m_pPlayer->inventory->items[k] != nullptr) { @@ -696,7 +696,7 @@ void IUIScene_CraftingMenu::CheckRecipesAvailable() { int iTotalCount = 0; // Does the player have this ingredient? - for (unsigned int k = 0; k < m_pPlayer->inventory->items.length; + for (unsigned int k = 0; k < m_pPlayer->inventory->items.size(); k++) { if (m_pPlayer->inventory->items[k] != nullptr) { // do they have the ingredient, and the aux value @@ -723,7 +723,7 @@ void IUIScene_CraftingMenu::CheckRecipesAvailable() { // inventory for (unsigned int l = 0; - l < m_pPlayer->inventory->items.length; + l < m_pPlayer->inventory->items.size(); l++) { if (m_pPlayer->inventory->items[l] != nullptr) { diff --git a/minecraft/Minecraft.Client/Common/Source Files/UI/All Platforms/IUIScene_CreativeMenu.cpp b/minecraft/Minecraft.Client/Common/Source Files/UI/All Platforms/IUIScene_CreativeMenu.cpp index 2ce9fa228..b01ca970c 100644 --- a/minecraft/Minecraft.Client/Common/Source Files/UI/All Platforms/IUIScene_CreativeMenu.cpp +++ b/minecraft/Minecraft.Client/Common/Source Files/UI/All Platforms/IUIScene_CreativeMenu.cpp @@ -505,7 +505,7 @@ void IUIScene_CreativeMenu::staticCtor() { ITEM(Item::horseArmorGold_Id) ITEM(Item::horseArmorMetal_Id) - for (unsigned int i = 0; i < Enchantment::enchantments.length; ++i) { + for (unsigned int i = 0; i < Enchantment::enchantments.size(); ++i) { Enchantment* enchantment = Enchantment::enchantments[i]; if (enchantment == nullptr || enchantment->category == nullptr) continue; @@ -1450,12 +1450,12 @@ void IUIScene_CreativeMenu::BuildFirework( // diamonds give trails if (trail) expTag->putBoolean(FireworksItem::TAG_E_TRAIL, true); - intArray colorArray(colors.size()); - for (int i = 0; i < colorArray.length; i++) { + std::vector colorArray(colors.size()); + for (int i = 0; i < colorArray.size(); i++) { colorArray[i] = colors.at(i); } expTag->putIntArray(FireworksItem::TAG_E_COLORS, colorArray); - // delete colorArray.data; + // delete colorArray.data(); expTag->putByte(FireworksItem::TAG_E_TYPE, type); @@ -1467,8 +1467,8 @@ void IUIScene_CreativeMenu::BuildFirework( std::vector colors; colors.push_back(DyePowderItem::COLOR_RGB[fadeColor]); - intArray colorArray(colors.size()); - for (int i = 0; i < colorArray.length; i++) { + std::vector colorArray(colors.size()); + for (int i = 0; i < colorArray.size(); i++) { colorArray[i] = colors.at(i); } expTag->putIntArray(FireworksItem::TAG_E_FADECOLORS, colorArray); diff --git a/minecraft/Minecraft.Client/Common/Source Files/UI/Scenes/Debug/UIScene_DebugOverlay.cpp b/minecraft/Minecraft.Client/Common/Source Files/UI/Scenes/Debug/UIScene_DebugOverlay.cpp index 02bc452dd..e2c7e28e8 100644 --- a/minecraft/Minecraft.Client/Common/Source Files/UI/Scenes/Debug/UIScene_DebugOverlay.cpp +++ b/minecraft/Minecraft.Client/Common/Source Files/UI/Scenes/Debug/UIScene_DebugOverlay.cpp @@ -47,7 +47,7 @@ UIScene_DebugOverlay::UIScene_DebugOverlay(int iPad, void* initData, m_buttonListItems.init(eControl_Items); int listId = 0; - for (unsigned int i = 0; i < Item::items.length; ++i) { + for (unsigned int i = 0; i < Item::items.size(); ++i) { if (Item::items[i] != nullptr) { m_itemIds.push_back(i); m_buttonListItems.addItem( diff --git a/minecraft/Minecraft.Client/Common/Source Files/UI/Scenes/Frontend Menu screens/UIScene_LoadOrJoinMenu.cpp b/minecraft/Minecraft.Client/Common/Source Files/UI/Scenes/Frontend Menu screens/UIScene_LoadOrJoinMenu.cpp index 39df0046f..d5854f2b9 100644 --- a/minecraft/Minecraft.Client/Common/Source Files/UI/Scenes/Frontend Menu screens/UIScene_LoadOrJoinMenu.cpp +++ b/minecraft/Minecraft.Client/Common/Source Files/UI/Scenes/Frontend Menu screens/UIScene_LoadOrJoinMenu.cpp @@ -1300,7 +1300,7 @@ void UIScene_LoadOrJoinMenu::LoadSaveFromDisk( int64_t fileSize = saveFile->length(); FileInputStream fis(*saveFile); - byteArray ba(fileSize); + std::vector ba(fileSize); fis.read(ba); fis.close(); @@ -1319,7 +1319,7 @@ void UIScene_LoadOrJoinMenu::LoadSaveFromDisk( g_NetworkManager.HostGame(0, isClientSide, isPrivate, maxPlayers, 0); LoadSaveDataThreadParam* saveData = - new LoadSaveDataThreadParam(ba.data, ba.length, saveFile->getName()); + new LoadSaveDataThreadParam(ba.data(), ba.size(), saveFile->getName()); NetworkGameInitData* param = new NetworkGameInitData(); param->seed = 0; @@ -1364,7 +1364,7 @@ void UIScene_LoadOrJoinMenu::LoadSaveFromCloud() { int64_t fileSize = cloudFile.length(); FileInputStream fis(cloudFile); - byteArray ba(fileSize); + std::vector ba(fileSize); fis.read(ba); fis.close(); @@ -1383,7 +1383,7 @@ void UIScene_LoadOrJoinMenu::LoadSaveFromCloud() { g_NetworkManager.HostGame(0, isClientSide, isPrivate, maxPlayers, 0); LoadSaveDataThreadParam* saveData = - new LoadSaveDataThreadParam(ba.data, ba.length, cloudFile.getName()); + new LoadSaveDataThreadParam(ba.data(), ba.size(), cloudFile.getName()); NetworkGameInitData* param = new NetworkGameInitData(); param->seed = app.getRemoteStorage()->getSaveSeed(); @@ -1882,9 +1882,9 @@ int UIScene_LoadOrJoinMenu::DownloadSonyCrossSaveThreadProc(void* lpParameter) { break; case eSaveTransfer_CreatingNewSave: { unsigned int fileSize = StorageManager.GetSaveSize(); - byteArray ba(fileSize); - StorageManager.GetSaveData(ba.data, &fileSize); - assert(ba.length == fileSize); + std::vector ba(fileSize); + StorageManager.GetSaveData(ba.data(), &fileSize); + assert(ba.size() == fileSize); StorageManager.ResetSaveData(); { @@ -1925,7 +1925,7 @@ int UIScene_LoadOrJoinMenu::DownloadSonyCrossSaveThreadProc(void* lpParameter) { #if defined(SPLIT_SAVES) ConsoleSaveFileOriginal oldFormatSave( - wSaveName, ba.data, ba.length, false, + wSaveName, ba.data(), ba.size(), false, app.getRemoteStorage()->getSavePlatform()); pSave = new ConsoleSaveFileSplit(&oldFormatSave, false, pMinecraft->progressRenderer); @@ -1936,13 +1936,12 @@ int UIScene_LoadOrJoinMenu::DownloadSonyCrossSaveThreadProc(void* lpParameter) { pClass->m_eSaveTransferState = eSaveTransfer_Saving; #else pSave = new ConsoleSaveFileOriginal( - wSaveName, ba.data, ba.length, false, + wSaveName, ba.data(), ba.size(), false, app.getRemoteStorage()->getSavePlatform()); pClass->m_eSaveTransferState = eSaveTransfer_Converting; pMinecraft->progressRenderer->progressStage( IDS_SAVETRANSFER_STAGE_CONVERTING); #endif - delete ba.data; } break; case eSaveTransfer_Converting: { pSave->ConvertToLocalPlatform(); // check if we need to convert diff --git a/minecraft/Minecraft.Client/Common/Source Files/UI/Scenes/Frontend Menu screens/UIScene_MainMenu.cpp b/minecraft/Minecraft.Client/Common/Source Files/UI/Scenes/Frontend Menu screens/UIScene_MainMenu.cpp index d95ad9050..6d96d01b0 100644 --- a/minecraft/Minecraft.Client/Common/Source Files/UI/Scenes/Frontend Menu screens/UIScene_MainMenu.cpp +++ b/minecraft/Minecraft.Client/Common/Source Files/UI/Scenes/Frontend Menu screens/UIScene_MainMenu.cpp @@ -53,7 +53,7 @@ UIScene_MainMenu::UIScene_MainMenu(int iPad, void* initData, std::wstring filename = L"splashes.txt"; if (app.hasArchiveFile(filename)) { - byteArray splashesArray = app.getArchiveFile(filename); + std::vector splashesArray = app.getArchiveFile(filename); ByteArrayInputStream bais(splashesArray); InputStreamReader isr(&bais); BufferedReader br(&isr); diff --git a/minecraft/Minecraft.Client/Common/Source Files/UI/UIController.cpp b/minecraft/Minecraft.Client/Common/Source Files/UI/UIController.cpp index ed006a097..9a44a4ca4 100644 --- a/minecraft/Minecraft.Client/Common/Source Files/UI/UIController.cpp +++ b/minecraft/Minecraft.Client/Common/Source Files/UI/UIController.cpp @@ -451,7 +451,6 @@ void UIController::tick() { int64_t currentTime = System::currentTimeMillis(); for (auto it = m_cachedMovieData.begin(); it != m_cachedMovieData.end();) { if (it->second.m_expiry < currentTime) { - delete[] it->second.m_ba.data; it = m_cachedMovieData.erase(it); } else { ++it; @@ -535,13 +534,12 @@ IggyLibrary UIController::loadSkin(const std::wstring& skinPath, // 4J Stu - We need to load the platformskin before the normal skin, as the // normal skin requires some elements from the platform skin if (!skinPath.empty() && app.hasArchiveFile(skinPath)) { - byteArray baFile = app.getArchiveFile(skinPath); + std::vector baFile = app.getArchiveFile(skinPath); const std::u16string convSkinName = wstring_to_u16string(skinName); lib = IggyLibraryCreateFromMemoryUTF16( - convSkinName.data(), (void*)baFile.data, baFile.length, nullptr); + convSkinName.data(), (void*)baFile.data(), baFile.size(), nullptr); - delete[] baFile.data; #if defined(_DEBUG) IggyMemoryUseInfo memoryInfo; rrbool res; @@ -675,12 +673,12 @@ void UIController::CleanUpSkinReload() { m_queuedMessageBoxData.clear(); } -byteArray UIController::getMovieData(const std::wstring& filename) { +std::vector UIController::getMovieData(const std::wstring& filename) { // Cache everything we load in the current tick int64_t targetTime = System::currentTimeMillis() + (1000LL * 60); auto it = m_cachedMovieData.find(filename); if (it == m_cachedMovieData.end()) { - byteArray baFile = app.getArchiveFile(filename); + std::vector baFile = app.getArchiveFile(filename); CachedMovieData cmd; cmd.m_ba = baFile; cmd.m_expiry = targetTime; @@ -1092,9 +1090,9 @@ GDrawTexture* RADLINK UIController::TextureSubstitutionCreateCallback( if (it != uiController->m_substitutionTextures.end()) { app.DebugPrintf("Found substitution texture %ls, with %d bytes\n", - (wchar_t*)texture_name, it->second.length); + (wchar_t*)texture_name, it->second.size()); - BufferedImage image(it->second.data, it->second.length); + BufferedImage image(it->second.data(), it->second.size()); if (image.getData() != nullptr) { image.preMultiplyAlpha(); Textures* t = Minecraft::GetInstance()->textures; @@ -1145,7 +1143,7 @@ void UIController::registerSubstitutionTexture(const std::wstring& textureName, // Remove it if it already exists unregisterSubstitutionTexture(textureName, false); - m_substitutionTextures[textureName] = byteArray(pbData, dwLength); + m_substitutionTextures[textureName] = std::vector(pbData, pbData + dwLength); } void UIController::unregisterSubstitutionTexture( @@ -1153,7 +1151,6 @@ void UIController::unregisterSubstitutionTexture( auto it = m_substitutionTextures.find(textureName); if (it != m_substitutionTextures.end()) { - if (deleteData) delete[] it->second.data; m_substitutionTextures.erase(it); } } diff --git a/minecraft/Minecraft.Client/Common/Source Files/UI/UIController.h b/minecraft/Minecraft.Client/Common/Source Files/UI/UIController.h index 903a03b65..5186ecc1a 100644 --- a/minecraft/Minecraft.Client/Common/Source Files/UI/UIController.h +++ b/minecraft/Minecraft.Client/Common/Source Files/UI/UIController.h @@ -136,10 +136,10 @@ private: static std::uint32_t m_dwTrialTimerLimitSecs; - std::unordered_map m_substitutionTextures; + std::unordered_map> m_substitutionTextures; typedef struct _CachedMovieData { - byteArray m_ba; + std::vector m_ba; int64_t m_expiry; } CachedMovieData; std::unordered_map m_cachedMovieData; @@ -216,7 +216,7 @@ private: static int reloadSkinThreadProc(void* lpParam); public: - byteArray getMovieData(const std::wstring& filename); + std::vector getMovieData(const std::wstring& filename); // INPUT private: diff --git a/minecraft/Minecraft.Client/Common/Source Files/UI/UIScene.cpp b/minecraft/Minecraft.Client/Common/Source Files/UI/UIScene.cpp index f0d6ea99a..0f282b16b 100644 --- a/minecraft/Minecraft.Client/Common/Source Files/UI/UIScene.cpp +++ b/minecraft/Minecraft.Client/Common/Source Files/UI/UIScene.cpp @@ -289,9 +289,9 @@ void UIScene::loadMovie() { } } - byteArray baFile = ui.getMovieData(moviePath.c_str()); + std::vector baFile = ui.getMovieData(moviePath.c_str()); int64_t beforeLoad = ui.iggyAllocCount; - swf = IggyPlayerCreateFromMemory(baFile.data, baFile.length, nullptr); + swf = IggyPlayerCreateFromMemory(baFile.data(), baFile.size(), nullptr); int64_t afterLoad = ui.iggyAllocCount; IggyPlayerInitializeAndTickRS(swf); int64_t afterTick = ui.iggyAllocCount; diff --git a/minecraft/Minecraft.Client/Header Files/BufferedImage.h b/minecraft/Minecraft.Client/Header Files/BufferedImage.h index 23e82ab81..d70d19914 100644 --- a/minecraft/Minecraft.Client/Header Files/BufferedImage.h +++ b/minecraft/Minecraft.Client/Header Files/BufferedImage.h @@ -24,7 +24,7 @@ public: int getWidth(); int getHeight(); - void getRGB(int startX, int startY, int w, int h, intArray out, int offset, + void getRGB(int startX, int startY, int w, int h, std::vector& out, int offset, int scansize, int level = 0); // 4J Added level param int* getData(); // 4J added int* getData(int level); // 4J added diff --git a/minecraft/Minecraft.Client/Source Files/BufferedImage.cpp b/minecraft/Minecraft.Client/Source Files/BufferedImage.cpp index 649ee0576..210ade711 100644 --- a/minecraft/Minecraft.Client/Source Files/BufferedImage.cpp +++ b/minecraft/Minecraft.Client/Source Files/BufferedImage.cpp @@ -92,8 +92,8 @@ BufferedImage::BufferedImage(const std::wstring& File, } else { std::wstring archiveKey = L"res/" + fileName; if (app.hasArchiveFile(archiveKey)) { - byteArray ba = app.getArchiveFile(archiveKey); - hr = RenderManager.LoadTextureData(ba.data, ba.length, + std::vector ba = app.getArchiveFile(archiveKey); + hr = RenderManager.LoadTextureData(ba.data(), ba.size(), &ImageInfo, &data[l]); } } @@ -182,7 +182,7 @@ int BufferedImage::getWidth() { return width; } int BufferedImage::getHeight() { return height; } -void BufferedImage::getRGB(int startX, int startY, int w, int h, intArray out, +void BufferedImage::getRGB(int startX, int startY, int w, int h, std::vector& out, int offset, int scansize, int level) { int ww = width >> level; for (int y = 0; y < h; y++) { @@ -219,7 +219,7 @@ BufferedImage* BufferedImage::getSubimage(int x, int y, int w, int h) { // TODO - 4J Implement BufferedImage* img = new BufferedImage(w, h, 0); - intArray arrayWrapper(img->data[0], w * h); + std::vector arrayWrapper(img->data[0], img->data[0] + w * h); this->getRGB(x, y, w, h, arrayWrapper, 0, w); int level = 1; @@ -230,7 +230,7 @@ BufferedImage* BufferedImage::getSubimage(int x, int y, int w, int h) { int xx = x >> level; int yy = y >> level; img->data[level] = new int[ww * hh]; - intArray levelWrapper(img->data[level], ww * hh); + std::vector levelWrapper(img->data[level], img->data[level] + ww * hh); this->getRGB(xx, yy, ww, hh, levelWrapper, 0, ww, level); ++level; diff --git a/minecraft/Minecraft.Client/net/minecraft/client/Minecraft.cpp b/minecraft/Minecraft.Client/net/minecraft/client/Minecraft.cpp index a1eee0749..8076f5c93 100644 --- a/minecraft/Minecraft.Client/net/minecraft/client/Minecraft.cpp +++ b/minecraft/Minecraft.Client/net/minecraft/client/Minecraft.cpp @@ -104,7 +104,7 @@ Minecraft::Minecraft(Component* mouseComponent, Canvas* parent, timer = new Timer(SharedConstants::TICKS_PER_SECOND); oldLevel = nullptr; // 4J Stu added level = nullptr; - levels = MultiPlayerLevelArray(3); // 4J Added + levels = std::vector(3); // 4J Added levelRenderer = nullptr; player = nullptr; cameraTargetPlayer = nullptr; @@ -1542,7 +1542,7 @@ void Minecraft::run_middle() { // 4J - added - now do the equivalent of level::animateTick, // but taking into account the positions of all our players - for (int l = 0; l < levels.length; l++) { + for (int l = 0; l < levels.size(); l++) { if (levels[l]) { levels[l]->animateTickDoWork(); } @@ -3549,7 +3549,7 @@ void Minecraft::tick(bool bFirst, bool bUpdateTextures) { SparseDataStorage::tick(); // 4J added } - for (unsigned int i = 0; i < levels.length; ++i) { + for (unsigned int i = 0; i < levels.size(); ++i) { if (player->level != levels[i]) continue; // Don't tick if the current player isn't in this // level @@ -3722,7 +3722,7 @@ void Minecraft::setLevel(MultiPlayerLevel* level, int message /*=-1*/, // non-nullptr gameRenderer->DisableUpdateThread(); - for (unsigned int i = 0; i < levels.length; ++i) { + for (unsigned int i = 0; i < levels.size(); ++i) { // 4J We only need to save out in multiplayer is we are setting the // level to nullptr If we ever go back to making single player only then // this will not work properly! @@ -4192,9 +4192,9 @@ void Minecraft::main() { L"Player" + _toString(System::currentTimeMillis() % 1000); sessionId = L"-"; /* 4J - TODO - get a session ID from somewhere? - if (args.length > 0) name = args[0]; + if (args.size() > 0) name = args[0]; sessionId = "-"; - if (args.length > 1) sessionId = args[1]; + if (args.size() > 1) sessionId = args[1]; */ } diff --git a/minecraft/Minecraft.Client/net/minecraft/client/Minecraft.h b/minecraft/Minecraft.Client/net/minecraft/client/Minecraft.h index 597badcb1..952b27c54 100644 --- a/minecraft/Minecraft.Client/net/minecraft/client/Minecraft.h +++ b/minecraft/Minecraft.Client/net/minecraft/client/Minecraft.h @@ -98,7 +98,7 @@ public: LevelRenderer* levelRenderer; std::shared_ptr player; - MultiPlayerLevelArray levels; + std::vector levels; std::shared_ptr localplayers[XUSER_MAX_COUNT]; MultiPlayerGameMode* localgameModes[XUSER_MAX_COUNT]; diff --git a/minecraft/Minecraft.Client/net/minecraft/client/gui/Font.cpp b/minecraft/Minecraft.Client/net/minecraft/client/gui/Font.cpp index 692a4689b..abb2c2e28 100644 --- a/minecraft/Minecraft.Client/net/minecraft/client/gui/Font.cpp +++ b/minecraft/Minecraft.Client/net/minecraft/client/gui/Font.cpp @@ -55,7 +55,7 @@ Font::Font(Options* options, const std::wstring& name, Textures* textures, int w = img->getWidth(); int h = img->getHeight(); - intArray rawPixels(w * h); + std::vector rawPixels(w * h); img->getRGB(0, 0, w, h, rawPixels, 0, w); for (int i = 0; i < charC; i++) { diff --git a/minecraft/Minecraft.Client/net/minecraft/client/gui/JoinMultiplayerScreen.cpp b/minecraft/Minecraft.Client/net/minecraft/client/gui/JoinMultiplayerScreen.cpp index 6de045d63..618f8e28f 100644 --- a/minecraft/Minecraft.Client/net/minecraft/client/gui/JoinMultiplayerScreen.cpp +++ b/minecraft/Minecraft.Client/net/minecraft/client/gui/JoinMultiplayerScreen.cpp @@ -66,7 +66,7 @@ void JoinMultiplayerScreen::buttonClicked(Button* button) { // 4J - TODO // minecraft->setScreen(new ConnectScreen(minecraft, parts[0], - // parts.length > 1 ? parseInt(parts[1], 25565) : 25565)); + // parts.size() > 1 ? parseInt(parts[1], 25565) : 25565)); } } diff --git a/minecraft/Minecraft.Client/net/minecraft/client/gui/Minimap.cpp b/minecraft/Minecraft.Client/net/minecraft/client/gui/Minimap.cpp index 9fdd2d51f..2b88ab3c1 100644 --- a/minecraft/Minecraft.Client/net/minecraft/client/gui/Minimap.cpp +++ b/minecraft/Minecraft.Client/net/minecraft/client/gui/Minimap.cpp @@ -13,7 +13,7 @@ bool Minimap::genLUT = true; // 4J added Minimap::Minimap(Font* font, Options* options, Textures* textures, bool optimised) { - this->pixels = intArray(w * h); + this->pixels = std::vector(w * h); this->options = options; this->font = font; BufferedImage* img = new BufferedImage(w, h, BufferedImage::TYPE_INT_ARGB); diff --git a/minecraft/Minecraft.Client/net/minecraft/client/gui/Minimap.h b/minecraft/Minecraft.Client/net/minecraft/client/gui/Minimap.h index 5120e4a5e..07a615242 100644 --- a/minecraft/Minecraft.Client/net/minecraft/client/gui/Minimap.h +++ b/minecraft/Minecraft.Client/net/minecraft/client/gui/Minimap.h @@ -14,7 +14,7 @@ private: static bool genLUT; // 4J added int renderCount; // 4J added bool m_optimised; // 4J Added - intArray pixels; + std::vector pixels; int mapTexture; Options* options; Font* font; diff --git a/minecraft/Minecraft.Client/net/minecraft/client/model/BlazeModel.cpp b/minecraft/Minecraft.Client/net/minecraft/client/model/BlazeModel.cpp index 11cc5ce1d..0e1be6311 100644 --- a/minecraft/Minecraft.Client/net/minecraft/client/model/BlazeModel.cpp +++ b/minecraft/Minecraft.Client/net/minecraft/client/model/BlazeModel.cpp @@ -4,9 +4,9 @@ #include "geom/ModelPart.h" BlazeModel::BlazeModel() : Model() { - upperBodyParts = ModelPartArray(12); + upperBodyParts = std::vector(12); - for (unsigned int i = 0; i < upperBodyParts.length; i++) { + for (unsigned int i = 0; i < upperBodyParts.size(); i++) { upperBodyParts[i] = new ModelPart(this, 0, 16); upperBodyParts[i]->addBox(0, 0, 0, 2, 8, 2); } @@ -17,7 +17,7 @@ BlazeModel::BlazeModel() : Model() { // 4J added - compile now to avoid random performance hit first time cubes // are rendered 4J Stu - Not just performance, but alpha+depth tests don't // work right unless we compile here - for (unsigned int i = 0; i < upperBodyParts.length; i++) { + for (unsigned int i = 0; i < upperBodyParts.size(); i++) { upperBodyParts[i]->compile(1.0f / 16.0f); } head->compile(1.0f / 16.0f); @@ -31,7 +31,7 @@ void BlazeModel::render(std::shared_ptr entity, float time, float r, setupAnim(time, r, bob, yRot, xRot, scale, entity); head->render(scale, usecompiled); - for (unsigned int i = 0; i < upperBodyParts.length; i++) { + for (unsigned int i = 0; i < upperBodyParts.size(); i++) { upperBodyParts[i]->render(scale, usecompiled); } } diff --git a/minecraft/Minecraft.Client/net/minecraft/client/model/BlazeModel.h b/minecraft/Minecraft.Client/net/minecraft/client/model/BlazeModel.h index f14203371..0cc447cee 100644 --- a/minecraft/Minecraft.Client/net/minecraft/client/model/BlazeModel.h +++ b/minecraft/Minecraft.Client/net/minecraft/client/model/BlazeModel.h @@ -3,7 +3,7 @@ class BlazeModel : public Model { private: - ModelPartArray upperBodyParts; + std::vector upperBodyParts; ModelPart* head; public: diff --git a/minecraft/Minecraft.Client/net/minecraft/client/model/GhastModel.cpp b/minecraft/Minecraft.Client/net/minecraft/client/model/GhastModel.cpp index 764b308c5..92b9ca1ae 100644 --- a/minecraft/Minecraft.Client/net/minecraft/client/model/GhastModel.cpp +++ b/minecraft/Minecraft.Client/net/minecraft/client/model/GhastModel.cpp @@ -11,7 +11,7 @@ GhastModel::GhastModel() : Model() { body->y += (8 + 16) + yoffs; Random* random = new Random(1660); - for (int i = 0; i < TENTACLESLENGTH; i++) // 4J - 9 was tentacles.length + for (int i = 0; i < TENTACLESLENGTH; i++) // 4J - 9 was tentacles.size() { tentacles[i] = new ModelPart(this, 0, 0); @@ -37,7 +37,7 @@ void GhastModel::setupAnim(float time, float r, float bob, float yRot, float xRot, float scale, std::shared_ptr entity, unsigned int uiBitmaskOverrideAnim) { - for (int i = 0; i < TENTACLESLENGTH; i++) // 4J - 9 was tentacles.length + for (int i = 0; i < TENTACLESLENGTH; i++) // 4J - 9 was tentacles.size() { tentacles[i]->xRot = 0.2f * Mth::sin(bob * 0.3f + i) + 0.4f; } @@ -52,7 +52,7 @@ void GhastModel::render(std::shared_ptr entity, float time, float r, glTranslatef(0, .6f, 0); body->render(scale, usecompiled); - for (int i = 0; i < TENTACLESLENGTH; i++) // 4J - 9 was tentacles.length + for (int i = 0; i < TENTACLESLENGTH; i++) // 4J - 9 was tentacles.size() { tentacles[i]->render(scale, usecompiled); } diff --git a/minecraft/Minecraft.Client/net/minecraft/client/model/SilverfishModel.cpp b/minecraft/Minecraft.Client/net/minecraft/client/model/SilverfishModel.cpp index 044e353bd..51471cd46 100644 --- a/minecraft/Minecraft.Client/net/minecraft/client/model/SilverfishModel.cpp +++ b/minecraft/Minecraft.Client/net/minecraft/client/model/SilverfishModel.cpp @@ -13,21 +13,21 @@ const int SilverfishModel::BODY_TEXS[BODY_COUNT][2] = { }; SilverfishModel::SilverfishModel() { - bodyParts = ModelPartArray(BODY_COUNT); + bodyParts = std::vector(BODY_COUNT); float placement = -3.5f; - for (unsigned int i = 0; i < bodyParts.length; i++) { + for (unsigned int i = 0; i < bodyParts.size(); i++) { bodyParts[i] = new ModelPart(this, BODY_TEXS[i][0], BODY_TEXS[i][1]); bodyParts[i]->addBox(BODY_SIZES[i][0] * -0.5f, 0, BODY_SIZES[i][2] * -0.5f, BODY_SIZES[i][0], BODY_SIZES[i][1], BODY_SIZES[i][2]); bodyParts[i]->setPos(0.0f, 24.0f - (float)BODY_SIZES[i][1], placement); zPlacement[i] = placement; - if (i < bodyParts.length - 1) { + if (i < bodyParts.size() - 1) { placement += (BODY_SIZES[i][2] + BODY_SIZES[i + 1][2]) * .5f; } } - bodyLayers = ModelPartArray(3); + bodyLayers = std::vector(3); bodyLayers[0] = new ModelPart(this, 20, 0); bodyLayers[0]->addBox(-5, 0, BODY_SIZES[2][2] * -0.5f, 10, 8, BODY_SIZES[2][2]); @@ -43,7 +43,7 @@ SilverfishModel::SilverfishModel() { // 4J added - compile now to avoid random performance hit first time cubes // are rendered - for (unsigned int i = 0; i < bodyParts.length; i++) { + for (unsigned int i = 0; i < bodyParts.size(); i++) { bodyParts[i]->compile(1.0f / 16.0f); } bodyLayers[0]->compile(1.0f / 16.0f); @@ -58,10 +58,10 @@ void SilverfishModel::render(std::shared_ptr entity, float time, float scale, bool usecompiled) { setupAnim(time, r, bob, yRot, xRot, scale, entity); - for (unsigned int i = 0; i < bodyParts.length; i++) { + for (unsigned int i = 0; i < bodyParts.size(); i++) { bodyParts[i]->render(scale, usecompiled); } - for (unsigned int i = 0; i < bodyLayers.length; i++) { + for (unsigned int i = 0; i < bodyLayers.size(); i++) { bodyLayers[i]->render(scale, usecompiled); } } @@ -70,7 +70,7 @@ void SilverfishModel::setupAnim(float time, float r, float bob, float yRot, float xRot, float scale, std::shared_ptr entity, unsigned int uiBitmaskOverrideAnim) { - for (unsigned int i = 0; i < bodyParts.length; i++) { + for (unsigned int i = 0; i < bodyParts.size(); i++) { bodyParts[i]->yRot = Mth::cos(bob * .9f + i * .15f * M_PI) * M_PI * .05f * (1 + abs((int)i - 2)); bodyParts[i]->x = diff --git a/minecraft/Minecraft.Client/net/minecraft/client/model/SilverfishModel.h b/minecraft/Minecraft.Client/net/minecraft/client/model/SilverfishModel.h index 5e4d1028f..738eddbd9 100644 --- a/minecraft/Minecraft.Client/net/minecraft/client/model/SilverfishModel.h +++ b/minecraft/Minecraft.Client/net/minecraft/client/model/SilverfishModel.h @@ -7,8 +7,8 @@ private: static const int BODY_COUNT = 7; private: - ModelPartArray bodyParts; - ModelPartArray bodyLayers; + std::vector bodyParts; + std::vector bodyLayers; float zPlacement[BODY_COUNT]; static const int BODY_SIZES[BODY_COUNT][3]; diff --git a/minecraft/Minecraft.Client/net/minecraft/client/model/SkiModel.cpp b/minecraft/Minecraft.Client/net/minecraft/client/model/SkiModel.cpp index efee965a0..0c1ba585c 100644 --- a/minecraft/Minecraft.Client/net/minecraft/client/model/SkiModel.cpp +++ b/minecraft/Minecraft.Client/net/minecraft/client/model/SkiModel.cpp @@ -14,7 +14,7 @@ void SkiModel::_init(bool leftSki) { xOffTex = 14; } - cubes = ModelPartArray(2); + cubes = std::vector(2); cubes[0] = new ModelPart(this, xOffTex, 0); cubes[1] = new ModelPart(this, xOffTex, 5); @@ -28,7 +28,7 @@ void SkiModel::_init(bool leftSki) { void SkiModel::render(std::shared_ptr entity, float time, float r, float bob, float yRot, float xRot, float scale, bool usecompiled) { - for (int i = 0; i < cubes.length; i++) { + for (int i = 0; i < cubes.size(); i++) { cubes[i]->render(scale, usecompiled); } } diff --git a/minecraft/Minecraft.Client/net/minecraft/client/model/SkiModel.h b/minecraft/Minecraft.Client/net/minecraft/client/model/SkiModel.h index f82119102..8680ffc2a 100644 --- a/minecraft/Minecraft.Client/net/minecraft/client/model/SkiModel.h +++ b/minecraft/Minecraft.Client/net/minecraft/client/model/SkiModel.h @@ -4,7 +4,7 @@ class SkiModel : public Model { public: - ModelPartArray cubes; + std::vector cubes; private: bool leftSki; diff --git a/minecraft/Minecraft.Client/net/minecraft/client/model/SquidModel.cpp b/minecraft/Minecraft.Client/net/minecraft/client/model/SquidModel.cpp index 5f4c73f40..778d45bb0 100644 --- a/minecraft/Minecraft.Client/net/minecraft/client/model/SquidModel.cpp +++ b/minecraft/Minecraft.Client/net/minecraft/client/model/SquidModel.cpp @@ -9,12 +9,12 @@ SquidModel::SquidModel() : Model() { body->addBox(-6, -8, -6, 12, 16, 12); body->y += (8 + 16) + yoffs; - for (int i = 0; i < TENTACLES_LENGTH; i++) // 4J - 8 was tentacles.length + for (int i = 0; i < TENTACLES_LENGTH; i++) // 4J - 8 was tentacles.size() { tentacles[i] = new ModelPart(this, 48, 0); double angle = i * M_PI * 2.0 / - (double)TENTACLES_LENGTH; // 4J - 8 was tentacles.length + (double)TENTACLES_LENGTH; // 4J - 8 was tentacles.size() float xo = Mth::cos((float)angle) * 5; float yo = Mth::sin((float)angle) * 5; tentacles[i]->addBox(-1, 0, -1, 2, 18, 2); @@ -24,7 +24,7 @@ SquidModel::SquidModel() : Model() { tentacles[i]->y = (float)(31 + yoffs); angle = i * M_PI * -2.0 / (double)TENTACLES_LENGTH + - M_PI * .5; // 4J - 8 was tentacles.length + M_PI * .5; // 4J - 8 was tentacles.size() tentacles[i]->yRot = (float)angle; // 4J added - compile now to avoid random performance hit first time @@ -38,7 +38,7 @@ void SquidModel::setupAnim(float time, float r, float bob, float yRot, float xRot, float scale, std::shared_ptr entity, unsigned int uiBitmaskOverrideAnim) { - for (int i = 0; i < TENTACLES_LENGTH; i++) // 4J - 8 was tentacles.length + for (int i = 0; i < TENTACLES_LENGTH; i++) // 4J - 8 was tentacles.size() { // tentacle angle is calculated in SquidRenderer tentacles[i]->xRot = bob; @@ -52,7 +52,7 @@ void SquidModel::render(std::shared_ptr entity, float time, float r, body->render(scale, usecompiled); for (int i = 0; i < TENTACLES_LENGTH; - i++) // 4J - 8 was tentacles.length // 4J Stu - Was 9 but I made it 8 + i++) // 4J - 8 was tentacles.size() // 4J Stu - Was 9 but I made it 8 // as the array is [0,8) { tentacles[i]->render(scale, usecompiled); diff --git a/minecraft/Minecraft.Client/net/minecraft/client/model/WitherBossModel.cpp b/minecraft/Minecraft.Client/net/minecraft/client/model/WitherBossModel.cpp index 36e68e445..b13b2d17d 100644 --- a/minecraft/Minecraft.Client/net/minecraft/client/model/WitherBossModel.cpp +++ b/minecraft/Minecraft.Client/net/minecraft/client/model/WitherBossModel.cpp @@ -7,7 +7,7 @@ WitherBossModel::WitherBossModel() { texWidth = 64; texHeight = 64; - upperBodyParts = ModelPartArray(3); + upperBodyParts = std::vector(3); upperBodyParts[0] = new ModelPart(this, 0, 16); upperBodyParts[0]->addBox(-10, 3.9f, -.5f, 20, 3, 3); @@ -23,7 +23,7 @@ WitherBossModel::WitherBossModel() { upperBodyParts[2] = new ModelPart(this, 12, 22); upperBodyParts[2]->addBox(0, 0, 0, 3, 6, 3); - heads = ModelPartArray(3); + heads = std::vector(3); heads[0] = new ModelPart(this, 0, 0); heads[0]->addBox(-4, -4, -4, 8, 8, 8); heads[1] = new ModelPart(this, 32, 0); @@ -43,10 +43,10 @@ void WitherBossModel::render(std::shared_ptr entity, float time, float scale, bool usecompiled) { setupAnim(time, r, bob, yRot, xRot, scale, entity); - for (int i = 0; i < heads.length; i++) { + for (int i = 0; i < heads.size(); i++) { heads[i]->render(scale, usecompiled); } - for (int i = 0; i < upperBodyParts.length; i++) { + for (int i = 0; i < upperBodyParts.size(); i++) { upperBodyParts[i]->render(scale, usecompiled); } } diff --git a/minecraft/Minecraft.Client/net/minecraft/client/model/WitherBossModel.h b/minecraft/Minecraft.Client/net/minecraft/client/model/WitherBossModel.h index b0f090ffb..817d2ddd0 100644 --- a/minecraft/Minecraft.Client/net/minecraft/client/model/WitherBossModel.h +++ b/minecraft/Minecraft.Client/net/minecraft/client/model/WitherBossModel.h @@ -4,8 +4,8 @@ class WitherBossModel : public Model { private: - ModelPartArray upperBodyParts; - ModelPartArray heads; + std::vector upperBodyParts; + std::vector heads; public: WitherBossModel(); diff --git a/minecraft/Minecraft.Client/net/minecraft/client/model/dragon/DragonModel.cpp b/minecraft/Minecraft.Client/net/minecraft/client/model/dragon/DragonModel.cpp index 5508dc16e..239f4edf1 100644 --- a/minecraft/Minecraft.Client/net/minecraft/client/model/dragon/DragonModel.cpp +++ b/minecraft/Minecraft.Client/net/minecraft/client/model/dragon/DragonModel.cpp @@ -134,12 +134,12 @@ void DragonModel::render(std::shared_ptr entity, float time, float r, float rotScale = 1.5f; double startComponents[3]; - doubleArray start = doubleArray(startComponents, 3); + std::vector start = std::vector(startComponents, startComponents + 3); dragon->getLatencyPos(start, 6, a); double latencyPosAComponents[3], latencyPosBComponents[3]; - doubleArray latencyPosA = doubleArray(latencyPosAComponents, 3); - doubleArray latencyPosB = doubleArray(latencyPosBComponents, 3); + std::vector latencyPosA = std::vector(latencyPosAComponents, latencyPosAComponents + 3); + std::vector latencyPosB = std::vector(latencyPosBComponents, latencyPosBComponents + 3); dragon->getLatencyPos(latencyPosA, 5, a); dragon->getLatencyPos(latencyPosB, 10, a); float rot2 = rotWrap(latencyPosA[0] - latencyPosB[0]); @@ -152,7 +152,7 @@ void DragonModel::render(std::shared_ptr entity, float time, float r, yy = 20.0f; zz = -12.0f; double pComponents[3]; - doubleArray p = doubleArray(pComponents, 3); + std::vector p = std::vector(pComponents, pComponents + 3); for (int i = 0; i < 5; i++) { dragon->getLatencyPos(p, 5 - i, a); diff --git a/minecraft/Minecraft.Client/net/minecraft/client/model/geom/ModelPart.cpp b/minecraft/Minecraft.Client/net/minecraft/client/model/geom/ModelPart.cpp index a1efa00c9..99e5d0601 100644 --- a/minecraft/Minecraft.Client/net/minecraft/client/model/geom/ModelPart.cpp +++ b/minecraft/Minecraft.Client/net/minecraft/client/model/geom/ModelPart.cpp @@ -50,7 +50,7 @@ void ModelPart::construct(Model* model, int xTexOffs, int yTexOffs) { } void ModelPart::addChild(ModelPart* child) { - // if (children == nullptr) children = new ModelPartArray; + // if (children == nullptr) children = new std::vector; children.push_back(child); } diff --git a/minecraft/Minecraft.Client/net/minecraft/client/multiplayer/ClientConnection.cpp b/minecraft/Minecraft.Client/net/minecraft/client/multiplayer/ClientConnection.cpp index 4d027ded3..8440f48e5 100644 --- a/minecraft/Minecraft.Client/net/minecraft/client/multiplayer/ClientConnection.cpp +++ b/minecraft/Minecraft.Client/net/minecraft/client/multiplayer/ClientConnection.cpp @@ -603,7 +603,7 @@ void ClientConnection::handleAddEntity( e->getSubEntities(); if (subEntities != nullptr) { int offs = packet->id - e->entityId; - // for (int i = 0; i < subEntities.length; i++) + // for (int i = 0; i < subEntities.size(); i++) for (auto it = subEntities->begin(); it != subEntities->end(); ++it) { (*it)->entityId += offs; @@ -915,7 +915,7 @@ void ClientConnection::handleMoveEntitySmall( void ClientConnection::handleRemoveEntity( std::shared_ptr packet) { - for (int i = 0; i < packet->ids.length; i++) { + for (int i = 0; i < packet->ids.size(); i++) { level->removeEntity(packet->ids[i]); } } @@ -1087,7 +1087,7 @@ void ClientConnection::handleBlockRegionUpdate( int y1 = packet->y + packet->ys; if (packet->bIsFullChunk) { y1 = Level::maxBuildHeight; - if (packet->buffer.length > 0) { + if (packet->buffer.size() > 0) { PIXBeginNamedEvent(0, "Reordering to XZY"); LevelChunk::reorderBlocksAndDataToXZY(packet->y, packet->xs, packet->ys, packet->zs, @@ -1998,7 +1998,7 @@ void ClientConnection::handleAddMob(std::shared_ptr packet) { std::vector >* subEntities = mob->getSubEntities(); if (subEntities != nullptr) { int offs = packet->id - mob->entityId; - // for (int i = 0; i < subEntities.length; i++) + // for (int i = 0; i < subEntities.size(); i++) for (auto it = subEntities->begin(); it != subEntities->end(); ++it) { // subEntities[i].entityId += offs; (*it)->entityId += offs; @@ -2975,8 +2975,9 @@ void ClientConnection::handleLevelEvent( void ClientConnection::handleAwardStat( std::shared_ptr packet) { + std::vector paramData = packet->getParamData(); minecraft->localplayers[m_userIndex]->awardStatFromServer( - GenericStats::stat(packet->statId), packet->getParamData()); + GenericStats::stat(packet->statId), paramData); } void ClientConnection::handleUpdateMobEffect( @@ -3269,7 +3270,7 @@ void ClientConnection::handleServerSettingsChanged( if (packet->action == ServerSettingsChangedPacket::HOST_IN_GAME_SETTINGS) { app.SetGameHostOption(eGameHostOption_All, packet->data); } else if (packet->action == ServerSettingsChangedPacket::HOST_DIFFICULTY) { - for (unsigned int i = 0; i < minecraft->levels.length; ++i) { + for (unsigned int i = 0; i < minecraft->levels.size(); ++i) { if (minecraft->levels[i] != nullptr) { app.DebugPrintf( "ClientConnection::handleServerSettingsChanged - " @@ -3306,8 +3307,8 @@ void ClientConnection::handleUpdateGameRuleProgressPacket( if (string != nullptr) { std::wstring message(string); message = GameRuleDefinition::generateDescriptionString( - packet->m_definitionType, message, packet->m_data.data, - packet->m_data.length); + packet->m_definitionType, message, packet->m_data.data(), + packet->m_data.size()); if (minecraft->localgameModes[m_userIndex] != nullptr) { minecraft->localgameModes[m_userIndex]->getTutorial()->setMessage( message, packet->m_icon, packet->m_auxValue); @@ -3322,7 +3323,6 @@ void ClientConnection::handleUpdateGameRuleProgressPacket( app.SetSpecialTutorialCompletionFlag(m_userIndex, packet->m_dataTag - 1); } - delete[] packet->m_data.data; } // 4J Stu - TU-1 hotfix diff --git a/minecraft/Minecraft.Client/net/minecraft/client/multiplayer/MultiPlayerChunkCache.cpp b/minecraft/Minecraft.Client/net/minecraft/client/multiplayer/MultiPlayerChunkCache.cpp index 5f2878865..549933646 100644 --- a/minecraft/Minecraft.Client/net/minecraft/client/multiplayer/MultiPlayerChunkCache.cpp +++ b/minecraft/Minecraft.Client/net/minecraft/client/multiplayer/MultiPlayerChunkCache.cpp @@ -17,13 +17,14 @@ MultiPlayerChunkCache::MultiPlayerChunkCache(Level* level) { hasData = new bool[XZSIZE * XZSIZE]; memset(hasData, 0, sizeof(bool) * XZSIZE * XZSIZE); + std::vector emptyBlocks(16 * 16 * Level::maxBuildHeight); emptyChunk = new EmptyLevelChunk( - level, byteArray(16 * 16 * Level::maxBuildHeight), 0, 0); + level, emptyBlocks, 0, 0); // For normal world dimension, create a chunk that can be used to create the // illusion of infinite water at the edge of the world if (level->dimension->id == 0) { - byteArray bytes = byteArray(16 * 16 * 128); + std::vector bytes = std::vector(16 * 16 * 128); // Superflat.... make grass, not water... if (level->getLevelData()->getGenerator() == LevelType::lvl_flat) { @@ -54,7 +55,6 @@ MultiPlayerChunkCache::MultiPlayerChunkCache(Level* level) { waterChunk = new WaterLevelChunk(level, bytes, 0, 0); - delete[] bytes.data; if (level->getLevelData()->getGenerator() == LevelType::lvl_flat) { for (int x = 0; x < 16; x++) @@ -189,7 +189,7 @@ LevelChunk* MultiPlayerChunkCache::create(int x, int z) { } else { // Passing an empty array into the LevelChunk ctor, which it now // detects and sets up the chunk as compressed & empty - byteArray bytes; + std::vector bytes; chunk = new LevelChunk(level, bytes, x, z); diff --git a/minecraft/Minecraft.Client/net/minecraft/client/multiplayer/MultiPlayerLocalPlayer.cpp b/minecraft/Minecraft.Client/net/minecraft/client/multiplayer/MultiPlayerLocalPlayer.cpp index 9e51e8644..fcdbfd815 100644 --- a/minecraft/Minecraft.Client/net/minecraft/client/multiplayer/MultiPlayerLocalPlayer.cpp +++ b/minecraft/Minecraft.Client/net/minecraft/client/multiplayer/MultiPlayerLocalPlayer.cpp @@ -286,25 +286,22 @@ void MultiplayerLocalPlayer::hurtTo(float newHealth, } } -void MultiplayerLocalPlayer::awardStat(Stat* stat, byteArray param) { +void MultiplayerLocalPlayer::awardStat(Stat* stat, const std::vector& param) { if (stat == nullptr) { - delete[] param.data; return; } if (stat->awardLocallyOnly) { LocalPlayer::awardStat(stat, param); } else { - delete[] param.data; return; } } -void MultiplayerLocalPlayer::awardStatFromServer(Stat* stat, byteArray param) { +void MultiplayerLocalPlayer::awardStatFromServer(Stat* stat, std::vector& param) { if (stat != nullptr && !stat->awardLocallyOnly) { LocalPlayer::awardStat(stat, param); - } else - delete[] param.data; + } } void MultiplayerLocalPlayer::onUpdateAbilities() { diff --git a/minecraft/Minecraft.Client/net/minecraft/client/multiplayer/MultiPlayerLocalPlayer.h b/minecraft/Minecraft.Client/net/minecraft/client/multiplayer/MultiPlayerLocalPlayer.h index c52a7ea7a..eb0df8772 100644 --- a/minecraft/Minecraft.Client/net/minecraft/client/multiplayer/MultiPlayerLocalPlayer.h +++ b/minecraft/Minecraft.Client/net/minecraft/client/multiplayer/MultiPlayerLocalPlayer.h @@ -70,8 +70,8 @@ public: virtual void closeContainer(); void clientSideCloseContainer(); virtual void hurtTo(float newHealth, ETelemetryChallenges damageSource); - virtual void awardStat(Stat* stat, byteArray param); - void awardStatFromServer(Stat* stat, byteArray param); + virtual void awardStat(Stat* stat, const std::vector& param); + void awardStatFromServer(Stat* stat, std::vector& param); void onUpdateAbilities(); bool isLocalPlayer(); diff --git a/minecraft/Minecraft.Client/net/minecraft/client/particle/FireworksParticles.cpp b/minecraft/Minecraft.Client/net/minecraft/client/particle/FireworksParticles.cpp index 704d1e892..cee4981f0 100644 --- a/minecraft/Minecraft.Client/net/minecraft/client/particle/FireworksParticles.cpp +++ b/minecraft/Minecraft.Client/net/minecraft/client/particle/FireworksParticles.cpp @@ -90,8 +90,8 @@ void FireworksParticles::FireworksStarter::tick() { int type = compoundTag->getByte(FireworksItem::TAG_E_TYPE); bool trail = compoundTag->getBoolean(FireworksItem::TAG_E_TRAIL); bool flicker = compoundTag->getBoolean(FireworksItem::TAG_E_FLICKER); - intArray colors = compoundTag->getIntArray(FireworksItem::TAG_E_COLORS); - intArray fadeColors = + std::vector colors = compoundTag->getIntArray(FireworksItem::TAG_E_COLORS); + std::vector fadeColors = compoundTag->getIntArray(FireworksItem::TAG_E_FADECOLORS); if (type == FireworksItem::TYPE_BIG) { @@ -106,10 +106,10 @@ void FireworksParticles::FireworksStarter::tick() { 150.0 / 245.0, -197.0 / 245.0, 0.0, -88.0 / 245.0, }; - coords2DArray coordsArray(6, 2); - for (unsigned int i = 0; i < coordsArray.length; ++i) { - for (unsigned int j = 0; j < coordsArray[i]->length; ++j) { - coordsArray[i]->data[j] = coords[i][j]; + std::vector> coordsArray(6, std::vector(2)); + for (unsigned int i = 0; i < coordsArray.size(); ++i) { + for (unsigned int j = 0; j < coordsArray[i].size(); ++j) { + coordsArray[i][j] = coords[i][j]; } } @@ -117,19 +117,16 @@ void FireworksParticles::FireworksStarter::tick() { createParticleShape(.5, coordsArray, colors, fadeColors, trail, flicker, false); - for (unsigned int i = 0; i < coordsArray.length; ++i) { - delete[] coordsArray[i]->data; - } - delete[] coordsArray.data; + // vector cleans up automatically } else if (type == FireworksItem::TYPE_CREEPER) { double coords[12][2] = { 0.0, 0.2, 0.2, 0.2, 0.2, 0.6, 0.6, 0.6, 0.6, 0.2, 0.2, 0.2, 0.2, 0.0, 0.4, 0.0, 0.4, -0.6, 0.2, -0.6, 0.2, -0.4, 0.0, -0.4, }; - coords2DArray coordsArray(12, 2); - for (unsigned int i = 0; i < coordsArray.length; ++i) { - for (unsigned int j = 0; j < coordsArray[i]->length; ++j) { - coordsArray[i]->data[j] = coords[i][j]; + std::vector> coordsArray(12, std::vector(2)); + for (unsigned int i = 0; i < coordsArray.size(); ++i) { + for (unsigned int j = 0; j < coordsArray[i].size(); ++j) { + coordsArray[i][j] = coords[i][j]; } } @@ -137,10 +134,7 @@ void FireworksParticles::FireworksStarter::tick() { createParticleShape(.5, coordsArray, colors, fadeColors, trail, flicker, true); - for (unsigned int i = 0; i < coordsArray.length; ++i) { - delete[] coordsArray[i]->data; - } - delete[] coordsArray.data; + // vector cleans up automatically } else if (type == FireworksItem::TYPE_BURST) { createParticleBurst(colors, fadeColors, trail, flicker); } else { @@ -187,7 +181,7 @@ bool FireworksParticles::FireworksStarter::isFarAwayFromCamera() { void FireworksParticles::FireworksStarter::createParticle( double x, double y, double z, double xa, double ya, double za, - intArray rgbColors, intArray fadeColors, bool trail, bool flicker) { + const std::vector& rgbColors, const std::vector& fadeColors, bool trail, bool flicker) { std::shared_ptr fireworksSparkParticle = std::shared_ptr( new FireworksSparkParticle(level, x, y, z, xa, ya, za, engine)); @@ -195,17 +189,17 @@ void FireworksParticles::FireworksStarter::createParticle( fireworksSparkParticle->setTrail(trail); fireworksSparkParticle->setFlicker(flicker); - int color = random->nextInt(rgbColors.length); + int color = random->nextInt(rgbColors.size()); fireworksSparkParticle->setColor(rgbColors[color]); - if (/*fadeColors != nullptr &&*/ fadeColors.length > 0) { + if (/*fadeColors != nullptr &&*/ fadeColors.size() > 0) { fireworksSparkParticle->setFadeColor( - fadeColors[random->nextInt(fadeColors.length)]); + fadeColors[random->nextInt(fadeColors.size())]); } engine->add(fireworksSparkParticle); } void FireworksParticles::FireworksStarter::createParticleBall( - double baseSpeed, int steps, intArray rgbColors, intArray fadeColors, + double baseSpeed, int steps, const std::vector& rgbColors, const std::vector& fadeColors, bool trail, bool flicker) { double xx = x; double yy = y; @@ -236,10 +230,10 @@ void FireworksParticles::FireworksStarter::createParticleBall( } void FireworksParticles::FireworksStarter::createParticleShape( - double baseSpeed, coords2DArray coords, intArray rgbColors, - intArray fadeColors, bool trail, bool flicker, bool flat) { - double sx = coords[0]->data[0]; - double sy = coords[0]->data[1]; + double baseSpeed, std::vector> coords, const std::vector& rgbColors, + const std::vector& fadeColors, bool trail, bool flicker, bool flat) { + double sx = coords[0][0]; + double sy = coords[0][1]; { createParticle(x, y, z, sx * baseSpeed, sy * baseSpeed, 0, rgbColors, @@ -254,9 +248,9 @@ void FireworksParticles::FireworksStarter::createParticleShape( double ox = sx; double oy = sy; - for (int c = 1; c < coords.length; c++) { - double tx = coords[c]->data[0]; - double ty = coords[c]->data[1]; + for (int c = 1; c < coords.size(); c++) { + double tx = coords[c][0]; + double ty = coords[c][1]; for (double subStep = .25; subStep <= 1.0; subStep += .25) { double xa = (ox + (tx - ox) * subStep) * baseSpeed; @@ -277,7 +271,7 @@ void FireworksParticles::FireworksStarter::createParticleShape( } void FireworksParticles::FireworksStarter::createParticleBurst( - intArray rgbColors, intArray fadeColors, bool trail, bool flicker) { + const std::vector& rgbColors, const std::vector& fadeColors, bool trail, bool flicker) { double baseOffX = random->nextGaussian() * .05; double baseOffZ = random->nextGaussian() * .05; diff --git a/minecraft/Minecraft.Client/net/minecraft/client/particle/FireworksParticles.h b/minecraft/Minecraft.Client/net/minecraft/client/particle/FireworksParticles.h index da3895e25..a86a68d82 100644 --- a/minecraft/Minecraft.Client/net/minecraft/client/particle/FireworksParticles.h +++ b/minecraft/Minecraft.Client/net/minecraft/client/particle/FireworksParticles.h @@ -25,14 +25,14 @@ public: virtual void tick(); bool isFarAwayFromCamera(); void createParticle(double x, double y, double z, double xa, double ya, - double za, intArray rgbColors, intArray fadeColors, + double za, const std::vector& rgbColors, const std::vector& fadeColors, bool trail, bool flicker); - void createParticleBall(double baseSpeed, int steps, intArray rgbColors, - intArray fadeColors, bool trail, bool flicker); - void createParticleShape(double baseSpeed, coords2DArray coords, - intArray rgbColors, intArray fadeColors, + void createParticleBall(double baseSpeed, int steps, const std::vector& rgbColors, + const std::vector& fadeColors, bool trail, bool flicker); + void createParticleShape(double baseSpeed, std::vector> coords, + const std::vector& rgbColors, const std::vector& fadeColors, bool trail, bool flicker, bool flat); - void createParticleBurst(intArray rgbColors, intArray fadeColors, + void createParticleBurst(const std::vector& rgbColors, const std::vector& fadeColors, bool trail, bool flicker); public: diff --git a/minecraft/Minecraft.Client/net/minecraft/client/player/LocalPlayer.cpp b/minecraft/Minecraft.Client/net/minecraft/client/player/LocalPlayer.cpp index 933cfcb53..dc4dd8d4a 100644 --- a/minecraft/Minecraft.Client/net/minecraft/client/player/LocalPlayer.cpp +++ b/minecraft/Minecraft.Client/net/minecraft/client/player/LocalPlayer.cpp @@ -797,9 +797,8 @@ void LocalPlayer::displayClientMessage(int messageId) { minecraft->gui->displayClientMessage(messageId, GetXboxPad()); } -void LocalPlayer::awardStat(Stat* stat, byteArray param) { +void LocalPlayer::awardStat(Stat* stat, const std::vector& param) { int count = CommonStats::readParam(param); - delete[] param.data; if (!app.CanRecordStatsAndAchievements()) return; if (stat == nullptr) return; @@ -1596,7 +1595,7 @@ void LocalPlayer::handleCollectItem(std::shared_ptr item) { if (item != nullptr) { unsigned int itemCountAnyAux = 0; unsigned int itemCountThisAux = 0; - for (unsigned int k = 0; k < inventory->items.length; ++k) { + for (unsigned int k = 0; k < inventory->items.size(); ++k) { if (inventory->items[k] != nullptr) { // do they have the item if (inventory->items[k]->id == item->id) { @@ -1623,6 +1622,6 @@ void LocalPlayer::handleCollectItem(std::shared_ptr item) { } void LocalPlayer::SetPlayerAdditionalModelParts( - std::vector pAdditionalModelParts) { + std::vector& pAdditionalModelParts) { m_pAdditionalModelParts = pAdditionalModelParts; } diff --git a/minecraft/Minecraft.Client/net/minecraft/client/player/LocalPlayer.h b/minecraft/Minecraft.Client/net/minecraft/client/player/LocalPlayer.h index 18e919275..452143f51 100644 --- a/minecraft/Minecraft.Client/net/minecraft/client/player/LocalPlayer.h +++ b/minecraft/Minecraft.Client/net/minecraft/client/player/LocalPlayer.h @@ -143,7 +143,7 @@ public: virtual void respawn(); virtual void animateRespawn(); virtual void displayClientMessage(int messageId); - virtual void awardStat(Stat* stat, byteArray param); + virtual void awardStat(Stat* stat, const std::vector& param); virtual int ThirdPersonView() { return m_iThirdPersonView; } // 4J - have changed 3rd person view to be 0 if not enabled, 1 for mode like // original, 2 reversed mode @@ -231,7 +231,7 @@ public: virtual void handleCollectItem(std::shared_ptr item); void SetPlayerAdditionalModelParts( - std::vector pAdditionalModelParts); + std::vector& pAdditionalModelParts); private: std::vector m_pAdditionalModelParts; diff --git a/minecraft/Minecraft.Client/net/minecraft/client/renderer/Chunk.cpp b/minecraft/Minecraft.Client/net/minecraft/client/renderer/Chunk.cpp index f32b334ab..92ff48f65 100644 --- a/minecraft/Minecraft.Client/net/minecraft/client/renderer/Chunk.cpp +++ b/minecraft/Minecraft.Client/net/minecraft/client/renderer/Chunk.cpp @@ -262,9 +262,9 @@ void Chunk::rebuild() { #else static unsigned char tileIds[16 * 16 * Level::maxBuildHeight]; #endif - byteArray tileArray = byteArray(tileIds, 16 * 16 * Level::maxBuildHeight); - level->getChunkAt(x, z)->getBlockData( - tileArray); // 4J - TODO - now our data has been re-arranged, we could + std::vector tileArray(16 * 16 * Level::maxBuildHeight); + level->getChunkAt(x, z)->getBlockData(tileArray); + memcpy(tileIds, tileArray.data(), 16 * 16 * Level::maxBuildHeight); // 4J - TODO - now our data has been re-arranged, we could // just extra the vertical slice of this chunk rather than // the whole thing diff --git a/minecraft/Minecraft.Client/net/minecraft/client/renderer/GameRenderer.cpp b/minecraft/Minecraft.Client/net/minecraft/client/renderer/GameRenderer.cpp index 79b39f957..c64860bc5 100644 --- a/minecraft/Minecraft.Client/net/minecraft/client/renderer/GameRenderer.cpp +++ b/minecraft/Minecraft.Client/net/minecraft/client/renderer/GameRenderer.cpp @@ -163,7 +163,7 @@ GameRenderer::GameRenderer(Minecraft* mc) { } delete img; for (int i = 0; i < NUM_LIGHT_TEXTURES; i++) - lightPixels[i] = intArray(16 * 16); + lightPixels[i] = std::vector(16 * 16); #if defined(MULTITHREAD_ENABLE) m_updateEvents = new C4JThread::EventArray( diff --git a/minecraft/Minecraft.Client/net/minecraft/client/renderer/GameRenderer.h b/minecraft/Minecraft.Client/net/minecraft/client/renderer/GameRenderer.h index 1b63fd68a..3121aad5a 100644 --- a/minecraft/Minecraft.Client/net/minecraft/client/renderer/GameRenderer.h +++ b/minecraft/Minecraft.Client/net/minecraft/client/renderer/GameRenderer.h @@ -67,7 +67,7 @@ private: // lightTexture per level, to support // split screen int getLightTexture(int iPad, Level* level); // 4J added - intArray lightPixels[NUM_LIGHT_TEXTURES]; + std::vector lightPixels[NUM_LIGHT_TEXTURES]; float fov[4]; float oFov[4]; diff --git a/minecraft/Minecraft.Client/net/minecraft/client/renderer/LevelRenderer.cpp b/minecraft/Minecraft.Client/net/minecraft/client/renderer/LevelRenderer.cpp index ba168552a..c932a9fe3 100644 --- a/minecraft/Minecraft.Client/net/minecraft/client/renderer/LevelRenderer.cpp +++ b/minecraft/Minecraft.Client/net/minecraft/client/renderer/LevelRenderer.cpp @@ -160,7 +160,7 @@ LevelRenderer::LevelRenderer(Minecraft* mc, Textures* textures) { // sortedChunks[i] = nullptr; // 4J - removed - not // sorting // our chunks anymore - chunks[i] = ClipChunkArray(); + chunks[i] = std::vector(); lastPlayerCount[i] = 0; } @@ -373,14 +373,12 @@ void LevelRenderer::setLevel(int playerIndex, MultiPlayerLevel* level) { } else { // printf("NULLing player %d, chunks @ // 0x%x\n",playerIndex,chunks[playerIndex]); - if (chunks[playerIndex].data != nullptr) { - for (unsigned int i = 0; i < chunks[playerIndex].length; i++) { + if (!chunks[playerIndex].empty()) { + for (unsigned int i = 0; i < chunks[playerIndex].size(); i++) { chunks[playerIndex][i].chunk->_delete(); delete chunks[playerIndex][i].chunk; } - delete chunks[playerIndex].data; - chunks[playerIndex].data = nullptr; - chunks[playerIndex].length = 0; + chunks[playerIndex].clear(); // delete sortedChunks[playerIndex]; // 4J - // removed - not sorting our chunks anymore // sortedChunks[playerIndex] = nullptr; // 4J - removed - not @@ -447,17 +445,16 @@ void LevelRenderer::allChanged(int playerIndex) { yChunks = Level::maxBuildHeight / CHUNK_SIZE; zChunks = dist; - if (chunks[playerIndex].data != nullptr) { - for (unsigned int i = 0; i < chunks[playerIndex].length; i++) { + if (!chunks[playerIndex].empty()) { + for (unsigned int i = 0; i < chunks[playerIndex].size(); i++) { chunks[playerIndex][i].chunk->_delete(); delete chunks[playerIndex][i].chunk; } - delete chunks[playerIndex].data; // delete sortedChunks[playerIndex]; // 4J - removed //- not sorting our chunks anymore } - chunks[playerIndex] = ClipChunkArray(xChunks * yChunks * zChunks); + chunks[playerIndex] = std::vector(xChunks * yChunks * zChunks); // sortedChunks[playerIndex] = new vector(xChunks * yChunks * // zChunks); // 4J - removed - not sorting our chunks anymore int id = 0; @@ -744,14 +741,14 @@ int LevelRenderer::render(std::shared_ptr player, int layer, glColor4f(1, 1, 1, 1); mc->gameRenderer->turnOnLightLayer(alpha); - int count = renderChunks(0, (int)chunks[playerIndex].length, layer, alpha); + int count = renderChunks(0, (int)chunks[playerIndex].size(), layer, alpha); mc->gameRenderer->turnOffLightLayer(alpha); return count; } int LevelRenderer::renderChunks(int from, int to, int layer, double alpha) { int playerIndex = mc->player->GetXboxPad(); - if (chunks[playerIndex].data == nullptr) return 0; + if (chunks[playerIndex].empty()) return 0; mc->gameRenderer->turnOnLightLayer(alpha); std::shared_ptr player = mc->cameraTargetPlayer; double xOff = player->xOld + (player->x - player->xOld) * alpha; @@ -764,16 +761,16 @@ int LevelRenderer::renderChunks(int from, int to, int layer, double alpha) { bool first = true; int count = 0; - ClipChunk* pClipChunk = chunks[playerIndex].data; + ClipChunk* pClipChunk = chunks[playerIndex].data(); unsigned char emptyFlag = LevelRenderer::CHUNK_FLAG_EMPTY0 << layer; static thread_local std::vector sortList; sortList.clear(); - if (sortList.capacity() < (size_t)chunks[playerIndex].length) { - sortList.reserve(chunks[playerIndex].length); + if (sortList.capacity() < (size_t)chunks[playerIndex].size()) { + sortList.reserve(chunks[playerIndex].size()); } { FRAME_PROFILE_SCOPE(ChunkCollect); - for (int i = 0; i < chunks[playerIndex].length; i++, pClipChunk++) { + for (int i = 0; i < chunks[playerIndex].size(); i++, pClipChunk++) { if (!pClipChunk->visible) continue; // This will be set if the chunk isn't visible, or // isn't compiled, or has both empty flags set @@ -1775,9 +1772,9 @@ bool LevelRenderer::updateDirtyChunks() { // shared_ptr it should live as long as we need it std::shared_ptr player = mc->localplayers[p]; if (player == nullptr) continue; - if (chunks[p].data == nullptr) continue; + if (chunks[p].empty()) continue; if (level[p] == nullptr) continue; - if (chunks[p].length != xChunks * zChunks * CHUNK_Y_COUNT) + if (chunks[p].size() != xChunks * zChunks * CHUNK_Y_COUNT) continue; int px = (int)player->x; int py = (int)player->y; @@ -2432,7 +2429,7 @@ bool inline clip(float* bb, float* frustum) { // gives better performances but mostly breaks chunk rendering void LevelRenderer::cull(Culler* culler, float a) { int playerIndex = mc->player->GetXboxPad(); - if (chunks[playerIndex].data == nullptr) return; + if (chunks[playerIndex].empty()) return; FrustumCuller* fc = (FrustumCuller*)culler; FrustumData* fd = fc->frustum; @@ -2450,7 +2447,7 @@ void LevelRenderer::cull(Culler* culler, float a) { #if defined(OCCLUSION_MODE_NONE) // just check if chunk is compiled and non-empty - for (unsigned int i = 0; i < chunks[playerIndex].length; i++) { + for (unsigned int i = 0; i < chunks[playerIndex].size(); i++) { ClipChunk* cc = &chunks[playerIndex][i]; if (cc->globalIdx < 0) { cc->visible = false; @@ -2467,7 +2464,7 @@ void LevelRenderer::cull(Culler* culler, float a) { #elif defined(OCCLUSION_MODE_FRUSTUM) // Just ~~monika~~ frustum culling - for (unsigned int i = 0; i < chunks[playerIndex].length; i++) { + for (unsigned int i = 0; i < chunks[playerIndex].size(); i++) { ClipChunk* cc = &chunks[playerIndex][i]; if (cc->globalIdx < 0) { cc->visible = false; @@ -2497,7 +2494,7 @@ void LevelRenderer::cull(Culler* culler, float a) { // For now, fall back to frustum culling #warning \ "OCCLUSION_MODE_HARDWARE is not implemented yet, falling back to frustum culling" - for (unsigned int i = 0; i < chunks[playerIndex].length; i++) { + for (unsigned int i = 0; i < chunks[playerIndex].size(); i++) { ClipChunk* cc = &chunks[playerIndex][i]; if (cc->globalIdx < 0) { cc->visible = false; @@ -2547,7 +2544,7 @@ void LevelRenderer::cull(Culler* culler, float a) { int minCx = INT_MAX, minCy = INT_MAX, minCz = INT_MAX; int maxCx = INT_MIN, maxCy = INT_MIN, maxCz = INT_MIN; - for (unsigned int i = 0; i < chunks[playerIndex].length; i++) { + for (unsigned int i = 0; i < chunks[playerIndex].size(); i++) { ClipChunk* cc = &chunks[playerIndex][i]; cc->visible = false; if (cc->globalIdx < 0) continue; @@ -2576,7 +2573,7 @@ void LevelRenderer::cull(Culler* culler, float a) { } memset(m_bfsGrid.data(), 0, gridSize * sizeof(ClipChunk*)); - for (unsigned int i = 0; i < chunks[playerIndex].length; i++) { + for (unsigned int i = 0; i < chunks[playerIndex].size(); i++) { ClipChunk* cc = &chunks[playerIndex][i]; if (cc->globalIdx < 0) continue; int lx = intFloorDiv(cc->chunk->x, CHUNK_XZSIZE) - minCx; @@ -2617,7 +2614,7 @@ void LevelRenderer::cull(Culler* culler, float a) { if (!startChunk) { float minDist = 1e30f; - for (unsigned int i = 0; i < chunks[playerIndex].length; i++) { + for (unsigned int i = 0; i < chunks[playerIndex].size(); i++) { ClipChunk* cc = &chunks[playerIndex][i]; if (cc->globalIdx < 0) continue; float midX = cc->chunk->x + CHUNK_XZSIZE * 0.5f; @@ -2642,17 +2639,17 @@ void LevelRenderer::cull(Culler* culler, float a) { static thread_local std::vector q; q.clear(); - q.reserve(chunks[playerIndex].length); + q.reserve(chunks[playerIndex].size()); int qHead = 0; - int visitedSize = chunks[playerIndex].length; + int visitedSize = chunks[playerIndex].size(); if (m_bfsVisitedFaces[playerIndex].size() < visitedSize) { m_bfsVisitedFaces[playerIndex].resize(visitedSize, 0); } memset(m_bfsVisitedFaces[playerIndex].data(), 0, visitedSize); q.push_back({startChunk, -1}); - m_bfsVisitedFaces[playerIndex][startChunk - chunks[playerIndex].data] = + m_bfsVisitedFaces[playerIndex][startChunk - chunks[playerIndex].data()] = 0x3F; static const int OFFSETS[6][3] = { @@ -2725,7 +2722,7 @@ void LevelRenderer::cull(Culler* culler, float a) { ClipChunk* neighbor = getChunkAt(nx, ny, nz); if (!neighbor) continue; - int nIdx = neighbor - chunks[playerIndex].data; + int nIdx = neighbor - chunks[playerIndex].data(); int nextIncFace = outFace ^ 1; if ((m_bfsVisitedFaces[playerIndex][nIdx] & (1 << nextIncFace)) != @@ -4058,8 +4055,8 @@ int LevelRenderer::checkAllPresentChunks(bool* faultFound) { int playerIndex = mc->player->GetXboxPad(); // 4J added int presentCount = 0; - ClipChunk* pClipChunk = chunks[playerIndex].data; - for (int i = 0; i < chunks[playerIndex].length; i++, pClipChunk++) { + ClipChunk* pClipChunk = chunks[playerIndex].data(); + for (int i = 0; i < chunks[playerIndex].size(); i++, pClipChunk++) { if (pClipChunk->chunk->y == 0) { bool chunkPresent = level[0]->reallyHasChunk( pClipChunk->chunk->x >> 4, pClipChunk->chunk->z >> 4); diff --git a/minecraft/Minecraft.Client/net/minecraft/client/renderer/LevelRenderer.h b/minecraft/Minecraft.Client/net/minecraft/client/renderer/LevelRenderer.h index f10324a19..e2d7c5f01 100644 --- a/minecraft/Minecraft.Client/net/minecraft/client/renderer/LevelRenderer.h +++ b/minecraft/Minecraft.Client/net/minecraft/client/renderer/LevelRenderer.h @@ -170,7 +170,7 @@ private: Textures* textures; // std::vector *sortedChunks[4]; // 4J - removed - not // sorting our chunks anymore - ClipChunkArray chunks[4]; // 4J - now one per player + std::vector chunks[4]; // 4J - now one per player int lastPlayerCount[4]; // 4J - added int xChunks, yChunks, zChunks; int chunkLists; diff --git a/minecraft/Minecraft.Client/net/minecraft/client/renderer/Tesselator.cpp b/minecraft/Minecraft.Client/net/minecraft/client/renderer/Tesselator.cpp index b6d1aa4f4..df8982744 100644 --- a/minecraft/Minecraft.Client/net/minecraft/client/renderer/Tesselator.cpp +++ b/minecraft/Minecraft.Client/net/minecraft/client/renderer/Tesselator.cpp @@ -63,7 +63,7 @@ Tesselator::Tesselator(int size) { this->size = size; - _array = new intArray(size); + _array = new std::vector(size); vboMode = USE_VBO; // 4J removed - && @@ -91,7 +91,7 @@ void Tesselator::end() { // 0xffffffff) so DrawVertices skips glColor for these vertices, // letting any caller-set GL colour (e.g. sky colour) pass through // unmodified. - unsigned int* pColData = (unsigned int*)_array->data; + unsigned int* pColData = (unsigned int*)_array->data(); pColData += 5; for (int i = 0; i < vertices; i++) { *pColData = 0x00000000; @@ -101,7 +101,7 @@ void Tesselator::end() { if (mode == GL_QUADS && TRIANGLE_MODE) { // glDrawArrays(GL_TRIANGLES, 0, vertices); // 4J - changed for xbox RenderManager.DrawVertices( - C4JRender::PRIMITIVE_TYPE_TRIANGLE_LIST, vertices, _array->data, + C4JRender::PRIMITIVE_TYPE_TRIANGLE_LIST, vertices, _array->data(), useCompactFormat360 ? C4JRender::VERTEX_TYPE_COMPRESSED : C4JRender::VERTEX_TYPE_PF3_TF2_CB4_NB4_XW1, @@ -118,20 +118,20 @@ void Tesselator::end() { int vertexCount = vertices; if (useCompactFormat360) { RenderManager.DrawVertices( - (C4JRender::ePrimitiveType)mode, vertexCount, _array->data, + (C4JRender::ePrimitiveType)mode, vertexCount, _array->data(), C4JRender::VERTEX_TYPE_COMPRESSED, C4JRender::PIXEL_SHADER_TYPE_STANDARD); } else { if (useProjectedTexturePixelShader) { RenderManager.DrawVertices( (C4JRender::ePrimitiveType)mode, vertexCount, - _array->data, + _array->data(), C4JRender::VERTEX_TYPE_PF3_TF2_CB4_NB4_XW1_TEXGEN, C4JRender::PIXEL_SHADER_TYPE_PROJECTION); } else { RenderManager.DrawVertices( (C4JRender::ePrimitiveType)mode, vertexCount, - _array->data, + _array->data(), C4JRender::VERTEX_TYPE_PF3_TF2_CB4_NB4_XW1, C4JRender::PIXEL_SHADER_TYPE_STANDARD); } @@ -321,7 +321,7 @@ void Tesselator::packCompactQuad() { m_iz[i] -= basez << 7; } // Now write the data out - unsigned int* data = (unsigned int*)&_array->data[p]; + unsigned int* data = (unsigned int*)&_array->data()[p]; for (int i = 0; i < 4; i++) { data[i * 2 + 0] = (m_ix[i] << 8) | (m_iy[i]); @@ -454,7 +454,7 @@ void Tesselator::vertex(float x, float y, float z) { ipackedcol -= 32768; // -32768 to 32767 range ipackedcol &= 0xffff; - std::int16_t* pShortData = (std::int16_t*)&_array->data[p]; + std::int16_t* pShortData = (std::int16_t*)&_array->data()[p]; pShortData[0] = (((int)((x + xo) * 1024.0f)) & 0xffff); pShortData[1] = (((int)((y + yo) * 1024.0f)) & 0xffff); @@ -490,16 +490,16 @@ void Tesselator::vertex(float x, float y, float z) { for (int i = 0; i < 2; i++) { int offs = 8 * (3 - i); if (hasTexture) { - _array->data[p + 3] = _array->data[p - offs + 3]; - _array->data[p + 4] = _array->data[p - offs + 4]; + _array->data()[p + 3] = _array->data()[p - offs + 3]; + _array->data()[p + 4] = _array->data()[p - offs + 4]; } if (hasColor) { - _array->data[p + 5] = _array->data[p - offs + 5]; + _array->data()[p + 5] = _array->data()[p - offs + 5]; } - _array->data[p + 0] = _array->data[p - offs + 0]; - _array->data[p + 1] = _array->data[p - offs + 1]; - _array->data[p + 2] = _array->data[p - offs + 2]; + _array->data()[p + 0] = _array->data()[p - offs + 0]; + _array->data()[p + 1] = _array->data()[p - offs + 1]; + _array->data()[p + 2] = _array->data()[p - offs + 2]; vertices++; p += 8; @@ -507,15 +507,15 @@ void Tesselator::vertex(float x, float y, float z) { } if (hasTexture) { - float* fdata = (float*)(_array->data + p + 3); + float* fdata = (float*)(_array->data() + p + 3); *fdata++ = uu; *fdata++ = v; } if (hasColor) { - _array->data[p + 5] = col; + _array->data()[p + 5] = col; } if (hasNormal) { - _array->data[p + 6] = _normal; + _array->data()[p + 6] = _normal; } if (hasTexture2) { // 4jcraft: we will be lighting the blocks right in here @@ -524,20 +524,20 @@ void Tesselator::vertex(float x, float y, float z) { std::int16_t tex2V; packLinuxLightmapCoords(_tex2, tex2U, tex2V); logLinuxPackedLightmapCoords("standard", _tex2, tex2U, tex2V); - std::int16_t* pShortArray = (std::int16_t*)&_array->data[p + 7]; + std::int16_t* pShortArray = (std::int16_t*)&_array->data()[p + 7]; pShortArray[0] = tex2U; pShortArray[1] = tex2V; #else - _array->data[p + 7] = _tex2; + _array->data()[p + 7] = _tex2; #endif } else { // -512 each for u/v will mean that the renderer will use global // settings (set via RenderManager.StateSetVertexTextureUV) rather // than these local ones - *(unsigned int*)(&_array->data[p + 7]) = 0xfe00fe00; + *(unsigned int*)(&_array->data()[p + 7]) = 0xfe00fe00; } - float* fdata = (float*)(_array->data + p); + float* fdata = (float*)(_array->data() + p); *fdata++ = (x + xo); *fdata++ = (y + yo); *fdata++ = (z + zo); diff --git a/minecraft/Minecraft.Client/net/minecraft/client/renderer/Tesselator.h b/minecraft/Minecraft.Client/net/minecraft/client/renderer/Tesselator.h index d6a7283ef..6b213c188 100644 --- a/minecraft/Minecraft.Client/net/minecraft/client/renderer/Tesselator.h +++ b/minecraft/Minecraft.Client/net/minecraft/client/renderer/Tesselator.h @@ -13,7 +13,7 @@ private: static const int MAX_MEMORY_USE = 16 * 1024 * 1024; static const int MAX_FLOATS = MAX_MEMORY_USE / 4 / 2; - intArray* _array; + std::vector* _array; int vertices; float u, v; diff --git a/minecraft/Minecraft.Client/net/minecraft/client/renderer/Textures.cpp b/minecraft/Minecraft.Client/net/minecraft/client/renderer/Textures.cpp index 2a288c7e2..2b4e65b77 100644 --- a/minecraft/Minecraft.Client/net/minecraft/client/renderer/Textures.cpp +++ b/minecraft/Minecraft.Client/net/minecraft/client/renderer/Textures.cpp @@ -330,21 +330,20 @@ void Textures::loadIndexedTextures() { } } -intArray Textures::loadTexturePixels(TEXTURE_NAME texId, +std::vector Textures::loadTexturePixels(TEXTURE_NAME texId, const std::wstring& resourceName) { TexturePack* skin = skins->getSelected(); { - intArray id = pixelsMap[resourceName]; + std::vector id = pixelsMap[resourceName]; // 4J - if resourceName isn't in the map, it should add an element and - // as that will use the default constructor, its internal data pointer - // will be nullptr - if (id.data != nullptr) return id; + // as that will use the default constructor, its vector will be empty + if (!id.empty()) return id; } // 4J - removed try/catch // try { - intArray res; + std::vector res; // wstring in = skin->getResource(resourceName); if (false) // 4J - removed - was ( in == nullptr) { @@ -368,14 +367,14 @@ intArray Textures::loadTexturePixels(TEXTURE_NAME texId, */ } -intArray Textures::loadTexturePixels(BufferedImage* img) { +std::vector Textures::loadTexturePixels(BufferedImage* img) { int w = img->getWidth(); int h = img->getHeight(); - intArray pixels(w * h); + std::vector pixels(w * h); return loadTexturePixels(img, pixels); } -intArray Textures::loadTexturePixels(BufferedImage* img, intArray pixels) { +std::vector Textures::loadTexturePixels(BufferedImage* img, std::vector& pixels) { int w = img->getWidth(); int h = img->getHeight(); img->getRGB(0, 0, w, h, pixels, 0, w); @@ -442,7 +441,7 @@ void Textures::bindTextureLayers(ResourceLocation* resource) { } else { // Cache by layer signature so the merge cost is only paid once per // horse texture combination. - intArray mergedPixels; + std::vector mergedPixels; int mergedWidth = 0; int mergedHeight = 0; bool hasMergedPixels = false; @@ -461,14 +460,14 @@ void Textures::bindTextureLayers(ResourceLocation* resource) { int width = image->getWidth(); int height = image->getHeight(); - intArray layerPixels = loadTexturePixels(image); + std::vector layerPixels = loadTexturePixels(image); delete image; if (!hasMergedPixels) { mergedWidth = width; mergedHeight = height; - mergedPixels = intArray(width * height); - memcpy(mergedPixels.data, layerPixels.data, + mergedPixels = std::vector(width * height); + memcpy(mergedPixels.data(), layerPixels.data(), width * height * sizeof(int)); hasMergedPixels = true; } else if (width == mergedWidth && height == mergedHeight) { @@ -506,15 +505,13 @@ void Textures::bindTextureLayers(ResourceLocation* resource) { } } - delete[] layerPixels.data; } if (hasMergedPixels) { BufferedImage* mergedImage = new BufferedImage( mergedWidth, mergedHeight, BufferedImage::TYPE_INT_ARGB); - memcpy(mergedImage->getData(), mergedPixels.data, + memcpy(mergedImage->getData(), mergedPixels.data(), mergedWidth * mergedHeight * sizeof(int)); - delete[] mergedPixels.data; id = getTexture(mergedImage, C4JRender::TEXTURE_FORMAT_RxGyBzAw, false); } else { @@ -699,15 +696,15 @@ void Textures::loadTexture(BufferedImage* img, int id, bool blur, bool clamp) { int w = img->getWidth(); int h = img->getHeight(); - intArray rawPixels(w * h); + std::vector rawPixels(w * h); img->getRGB(0, 0, w, h, rawPixels, 0, w); if (options != nullptr && options->anaglyph3d) { rawPixels = anaglyph(rawPixels); } - byteArray newPixels(w * h * 4); - for (unsigned int i = 0; i < rawPixels.length; i++) { + std::vector newPixels(w * h * 4); + for (unsigned int i = 0; i < rawPixels.size(); i++) { int a = (rawPixels[i] >> 24) & 0xff; int r = (rawPixels[i] >> 16) & 0xff; int g = (rawPixels[i] >> 8) & 0xff; @@ -722,10 +719,8 @@ void Textures::loadTexture(BufferedImage* img, int id, bool blur, bool clamp) { ByteBuffer* pixels = MemoryTracker::createByteBuffer(w * h * 4); pixels->clear(); pixels->put(newPixels); - pixels->position(0)->limit(newPixels.length); + pixels->position(0)->limit(newPixels.size()); - delete[] rawPixels.data; - delete[] newPixels.data; if (MIPMAP) { // 4J-PB - In the new XDK, the CreateTexture will fail if the number of @@ -810,9 +805,9 @@ void Textures::loadTexture(BufferedImage* img, int id, bool blur, bool clamp) { MemSect(0); } -intArray Textures::anaglyph(intArray rawPixels) { - intArray result(rawPixels.length); - for (unsigned int i = 0; i < rawPixels.length; i++) { +std::vector Textures::anaglyph(std::vector& rawPixels) { + std::vector result(rawPixels.size()); + for (unsigned int i = 0; i < rawPixels.size(); i++) { int a = (rawPixels[i] >> 24) & 0xff; int r = (rawPixels[i] >> 16) & 0xff; int g = (rawPixels[i] >> 8) & 0xff; @@ -825,12 +820,11 @@ intArray Textures::anaglyph(intArray rawPixels) { result[i] = a << 24 | rr << 16 | gg << 8 | bb; } - delete[] rawPixels.data; return result; } -void Textures::replaceTexture(intArray rawPixels, int w, int h, int id) { +void Textures::replaceTexture(std::vector& rawPixels, int w, int h, int id) { bind(id); // Removed in Java @@ -846,8 +840,8 @@ void Textures::replaceTexture(intArray rawPixels, int w, int h, int id) { rawPixels = anaglyph(rawPixels); } - byteArray newPixels(w * h * 4); - for (unsigned int i = 0; i < rawPixels.length; i++) { + std::vector newPixels(w * h * 4); + for (unsigned int i = 0; i < rawPixels.size(); i++) { int a = (rawPixels[i] >> 24) & 0xff; int r = (rawPixels[i] >> 16) & 0xff; int g = (rawPixels[i] >> 8) & 0xff; @@ -871,8 +865,7 @@ void Textures::replaceTexture(intArray rawPixels, int w, int h, int id) { ByteBuffer* pixels = MemoryTracker::createByteBuffer( w * h * 4); // 4J - now creating dynamically pixels->put(newPixels); - pixels->position(0)->limit(newPixels.length); - delete[] newPixels.data; + pixels->position(0)->limit(newPixels.size()); // New // glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, w, h, GL12.GL_BGRA, @@ -887,7 +880,7 @@ void Textures::replaceTexture(intArray rawPixels, int w, int h, int id) { // 4J - added. This is a more minimal version of replaceTexture that assumes the // texture bytes are already in order, and so doesn't do any of the extra // copying round that the original java version does -void Textures::replaceTextureDirect(intArray rawPixels, int w, int h, int id) { +void Textures::replaceTextureDirect(const std::vector& rawPixels, int w, int h, int id) { glBindTexture(GL_TEXTURE_2D, id); // Remove in Java @@ -899,13 +892,13 @@ void Textures::replaceTextureDirect(intArray rawPixels, int w, int h, int id) { glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); - RenderManager.TextureDataUpdate(0, 0, w, h, rawPixels.data, 0); + RenderManager.TextureDataUpdate(0, 0, w, h, const_cast(rawPixels.data()), 0); } // 4J - added. This is a more minimal version of replaceTexture that assumes the // texture bytes are already in order, and so doesn't do any of the extra // copying round that the original java version does -void Textures::replaceTextureDirect(shortArray rawPixels, int w, int h, +void Textures::replaceTextureDirect(const std::vector& rawPixels, int w, int h, int id) { glBindTexture(GL_TEXTURE_2D, id); @@ -918,7 +911,7 @@ void Textures::replaceTextureDirect(shortArray rawPixels, int w, int h, glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); - RenderManager.TextureDataUpdate(0, 0, w, h, rawPixels.data, 0); + RenderManager.TextureDataUpdate(0, 0, w, h, const_cast(rawPixels.data()), 0); } void Textures::releaseTexture(int id) { diff --git a/minecraft/Minecraft.Client/net/minecraft/client/renderer/Textures.h b/minecraft/Minecraft.Client/net/minecraft/client/renderer/Textures.h index 4f1284f3b..458a83f03 100644 --- a/minecraft/Minecraft.Client/net/minecraft/client/renderer/Textures.h +++ b/minecraft/Minecraft.Client/net/minecraft/client/renderer/Textures.h @@ -274,7 +274,7 @@ private: static int preLoadedIdx[TN_COUNT]; std::unordered_map idMap; - std::unordered_map pixelsMap; + std::unordered_map> pixelsMap; std::unordered_map loadedImages; // IntBuffer *pixels; // 4J - removed so we don't have a permanent // buffer kicking round using up 1MB @@ -299,12 +299,12 @@ private: void loadIndexedTextures(); // 4J Added public: - intArray loadTexturePixels(TEXTURE_NAME texId, + std::vector loadTexturePixels(TEXTURE_NAME texId, const std::wstring& resourceName); private: - intArray loadTexturePixels(BufferedImage* img); - intArray loadTexturePixels(BufferedImage* img, intArray pixels); + std::vector loadTexturePixels(BufferedImage* img); + std::vector loadTexturePixels(BufferedImage* img, std::vector& pixels); void setTextureFormat(const std::wstring& resourceName); // 4J added public: @@ -334,13 +334,13 @@ public: void loadTexture(BufferedImage* img, int id, bool blur, bool clamp); private: - intArray anaglyph(intArray rawPixels); + std::vector anaglyph(std::vector& rawPixels); public: - void replaceTexture(intArray rawPixels, int w, int h, int id); - void replaceTextureDirect(intArray rawPixels, int w, int h, + void replaceTexture(std::vector& rawPixels, int w, int h, int id); + void replaceTextureDirect(const std::vector& rawPixels, int w, int h, int id); // 4J added as optimisation - void replaceTextureDirect(shortArray rawPixels, int w, int h, + void replaceTextureDirect(const std::vector& rawPixels, int w, int h, int id); // 4J added as optimisation void releaseTexture(int id); int loadHttpTexture(const std::wstring& url, const std::wstring& backup); diff --git a/minecraft/Minecraft.Client/net/minecraft/client/renderer/culling/Frustum.cpp b/minecraft/Minecraft.Client/net/minecraft/client/renderer/culling/Frustum.cpp index 28bcf85d4..a2e84f439 100644 --- a/minecraft/Minecraft.Client/net/minecraft/client/renderer/culling/Frustum.cpp +++ b/minecraft/Minecraft.Client/net/minecraft/client/renderer/culling/Frustum.cpp @@ -49,14 +49,14 @@ void Frustum::calculateFrustum() { // queries. // Camera::prepare() already captures both matrices every frame :) // i spent an ungodly amount of time on this simple fix. - memcpy(proj.data, RenderManager.MatrixGet(GL_PROJECTION_MATRIX), + memcpy(proj.data(), RenderManager.MatrixGet(GL_PROJECTION_MATRIX), 16 * sizeof(float)); - memcpy(modl.data, RenderManager.MatrixGet(GL_MODELVIEW_MATRIX), + memcpy(modl.data(), RenderManager.MatrixGet(GL_MODELVIEW_MATRIX), 16 * sizeof(float)); - float* p = proj.data; - float* m = modl.data; - float* c = clip.data; + float* p = proj.data(); + float* m = modl.data(); + float* c = clip.data(); c[0] = m[0] * p[0] + m[1] * p[4] + m[2] * p[8] + m[3] * p[12]; c[1] = m[0] * p[1] + m[1] * p[5] + m[2] * p[9] + m[3] * p[13]; diff --git a/minecraft/Minecraft.Client/net/minecraft/client/renderer/culling/FrustumData.cpp b/minecraft/Minecraft.Client/net/minecraft/client/renderer/culling/FrustumData.cpp index 448c04a53..0c6f2fefd 100644 --- a/minecraft/Minecraft.Client/net/minecraft/client/renderer/culling/FrustumData.cpp +++ b/minecraft/Minecraft.Client/net/minecraft/client/renderer/culling/FrustumData.cpp @@ -8,15 +8,12 @@ FrustumData::FrustumData() { for (int i = 0; i < 6; i++) { this->m_Frustum[i] = new float[4]; } - proj = floatArray(16); - modl = floatArray(16); - clip = floatArray(16); + proj = std::vector(16); + modl = std::vector(16); + clip = std::vector(16); } FrustumData::~FrustumData() { - delete[] proj.data; - delete[] modl.data; - delete[] clip.data; for (int i = 0; i < 6; i++) delete[] m_Frustum[i]; delete[] m_Frustum; } diff --git a/minecraft/Minecraft.Client/net/minecraft/client/renderer/culling/FrustumData.h b/minecraft/Minecraft.Client/net/minecraft/client/renderer/culling/FrustumData.h index 6db5350da..f18ff4ab9 100644 --- a/minecraft/Minecraft.Client/net/minecraft/client/renderer/culling/FrustumData.h +++ b/minecraft/Minecraft.Client/net/minecraft/client/renderer/culling/FrustumData.h @@ -19,9 +19,9 @@ public: static const int D = 3; // The distance the plane is from the origin float** m_Frustum; - floatArray proj; - floatArray modl; - floatArray clip; + std::vector proj; + std::vector modl; + std::vector clip; FrustumData(); ~FrustumData(); diff --git a/minecraft/Minecraft.Client/net/minecraft/client/renderer/entity/EnderDragonRenderer.cpp b/minecraft/Minecraft.Client/net/minecraft/client/renderer/entity/EnderDragonRenderer.cpp index 53f0b998a..043ce2d16 100644 --- a/minecraft/Minecraft.Client/net/minecraft/client/renderer/entity/EnderDragonRenderer.cpp +++ b/minecraft/Minecraft.Client/net/minecraft/client/renderer/entity/EnderDragonRenderer.cpp @@ -30,7 +30,7 @@ void EnderDragonRenderer::setupRotations(std::shared_ptr _mob, // 4J - reorganised a bit so we can free allocations double lpComponents[3]; - doubleArray lp = doubleArray(lpComponents, 3); + std::vector lp = std::vector(lpComponents, lpComponents + 3); mob->getLatencyPos(lp, 7, a); float yr = lp[0]; // mob->getLatencyPos(lp, 5, a); diff --git a/minecraft/Minecraft.Client/net/minecraft/client/renderer/texture/Stitcher.cpp b/minecraft/Minecraft.Client/net/minecraft/client/renderer/texture/Stitcher.cpp index 8a60d7f94..90a5277dc 100644 --- a/minecraft/Minecraft.Client/net/minecraft/client/renderer/texture/Stitcher.cpp +++ b/minecraft/Minecraft.Client/net/minecraft/client/renderer/texture/Stitcher.cpp @@ -72,7 +72,7 @@ void Stitcher::stitch() { stitchedTexture = nullptr; - // for (int i = 0; i < textureHolders.length; i++) + // for (int i = 0; i < textureHolders.size(); i++) for (auto it = texturesToBeStitched.begin(); it != texturesToBeStitched.end(); ++it) { TextureHolder* textureHolder = *it; // textureHolders[i]; diff --git a/minecraft/Minecraft.Client/net/minecraft/client/renderer/texture/Texture.cpp b/minecraft/Minecraft.Client/net/minecraft/client/renderer/texture/Texture.cpp index 18533fb70..94daf2648 100644 --- a/minecraft/Minecraft.Client/net/minecraft/client/renderer/texture/Texture.cpp +++ b/minecraft/Minecraft.Client/net/minecraft/client/renderer/texture/Texture.cpp @@ -88,33 +88,31 @@ void Texture::_init(const std::wstring& name, int mode, int width, int height, if (width == -1 || height == -1) { valid = false; } else { - byteArray tempBytes = byteArray(width * height * depth * 4); - for (int index = 0; index < tempBytes.length; index++) { + std::vector tempBytes = std::vector(width * height * depth * 4); + for (int index = 0; index < tempBytes.size(); index++) { tempBytes[index] = 0; } - data[0] = ByteBuffer::allocateDirect(tempBytes.length); + data[0] = ByteBuffer::allocateDirect(tempBytes.size()); data[0]->clear(); data[0]->put(tempBytes); - data[0]->position(0)->limit(tempBytes.length); + data[0]->position(0)->limit(tempBytes.size()); - delete[] tempBytes.data; if (mipmapped) { for (unsigned int level = 1; level < m_iMipLevels; ++level) { int ww = width >> level; int hh = height >> level; - byteArray tempBytes = byteArray(ww * hh * depth * 4); - for (int index = 0; index < tempBytes.length; index++) { + std::vector tempBytes = std::vector(ww * hh * depth * 4); + for (int index = 0; index < tempBytes.size(); index++) { tempBytes[index] = 0; } - data[level] = ByteBuffer::allocateDirect(tempBytes.length); + data[level] = ByteBuffer::allocateDirect(tempBytes.size()); data[level]->clear(); data[level]->put(tempBytes); - data[level]->position(0)->limit(tempBytes.length); + data[level]->position(0)->limit(tempBytes.size()); - delete[] tempBytes.data; } } @@ -265,7 +263,7 @@ void Texture::blit(int x, int y, Texture* source, bool rotated) { } } -void Texture::transferFromBuffer(intArray buffer) { +void Texture::transferFromBuffer(const std::vector& buffer) { // if (depth == 1) { // return; // } @@ -353,11 +351,11 @@ void Texture::transferFromImage(BufferedImage* image) { // #endif int* byteRemap = ((format == TFMT_BGRA) ? byteRemapBGRA : byteRemapRGBA); - intArray tempPixels = intArray(width * height); + std::vector tempPixels = std::vector(width * height); int transparency = image->getTransparency(); image->getRGB(0, 0, width, height, tempPixels, 0, imgWidth); - byteArray tempBytes = byteArray(width * height * 4); + std::vector tempBytes = std::vector(width * height * 4); for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) { int intIndex = y * width + x; @@ -384,13 +382,12 @@ void Texture::transferFromImage(BufferedImage* image) { } MemSect(51); - data[0] = ByteBuffer::allocateDirect(tempBytes.length); + data[0] = ByteBuffer::allocateDirect(tempBytes.size()); MemSect(0); data[0]->clear(); data[0]->put(tempBytes); - data[0]->limit(tempBytes.length); + data[0]->limit(tempBytes.size()); - delete[] tempBytes.data; if (mipmapped || image->getData(1) != nullptr) { mipmapped = true; @@ -398,7 +395,7 @@ void Texture::transferFromImage(BufferedImage* image) { int ww = width >> level; int hh = height >> level; - byteArray tempBytes = byteArray(ww * hh * 4); + std::vector tempBytes = std::vector(ww * hh * 4); unsigned int* tempData = new unsigned int[ww * hh]; if (image->getData(level)) { @@ -469,17 +466,15 @@ void Texture::transferFromImage(BufferedImage* image) { } MemSect(51); - data[level] = ByteBuffer::allocateDirect(tempBytes.length); + data[level] = ByteBuffer::allocateDirect(tempBytes.size()); MemSect(0); data[level]->clear(); data[level]->put(tempBytes); - data[level]->limit(tempBytes.length); - delete[] tempBytes.data; + data[level]->limit(tempBytes.size()); delete[] tempData; } } - delete[] tempPixels.data; if (immediateUpdate) { updateOnGPU(); diff --git a/minecraft/Minecraft.Client/net/minecraft/client/renderer/texture/Texture.h b/minecraft/Minecraft.Client/net/minecraft/client/renderer/texture/Texture.h index 9d4ac284d..e40981560 100644 --- a/minecraft/Minecraft.Client/net/minecraft/client/renderer/texture/Texture.h +++ b/minecraft/Minecraft.Client/net/minecraft/client/renderer/texture/Texture.h @@ -87,7 +87,7 @@ public: void writeAsPNG(const std::wstring& filename); void blit(int x, int y, Texture* source); void blit(int x, int y, Texture* source, bool rotated); - void transferFromBuffer(intArray buffer); + void transferFromBuffer(const std::vector& buffer); void transferFromImage(BufferedImage* image); int getManagerId(); int getGlId(); diff --git a/minecraft/Minecraft.Client/net/minecraft/client/renderer/tileentity/SignRenderer.cpp b/minecraft/Minecraft.Client/net/minecraft/client/renderer/tileentity/SignRenderer.cpp index 7643164a3..4bb380dcd 100644 --- a/minecraft/Minecraft.Client/net/minecraft/client/renderer/tileentity/SignRenderer.cpp +++ b/minecraft/Minecraft.Client/net/minecraft/client/renderer/tileentity/SignRenderer.cpp @@ -64,7 +64,7 @@ void SignRenderer::render(std::shared_ptr _sign, double x, double y, // Get the current language setting from the console std::uint32_t dwLanguage = XGetLanguage(); - for (int i = 0; i < MAX_SIGN_LINES; i++) // 4J - was sign.messages.length + for (int i = 0; i < MAX_SIGN_LINES; i++) // 4J - was sign.messages.size() { if (sign->IsVerified()) { if (sign->IsCensored()) { @@ -99,11 +99,11 @@ void SignRenderer::render(std::shared_ptr _sign, double x, double y, msg = L"> " + msg + L" <"; font->draw(msg, -font->width(msg) / 2, i * 10 - (MAX_SIGN_LINES) * 5, - col); // 4J - (MAX_SIGN_LINES) was sign.messages.length + col); // 4J - (MAX_SIGN_LINES) was sign.messages.size() } else { font->draw(msg, -font->width(msg) / 2, i * 10 - (MAX_SIGN_LINES) * 5, - col); // 4J - (MAX_SIGN_LINES) was sign.messages.length + col); // 4J - (MAX_SIGN_LINES) was sign.messages.size() } } glDepthMask(true); diff --git a/minecraft/Minecraft.Client/net/minecraft/client/resources/ResourceLocation.h b/minecraft/Minecraft.Client/net/minecraft/client/resources/ResourceLocation.h index 975a7368d..f33416e3a 100644 --- a/minecraft/Minecraft.Client/net/minecraft/client/resources/ResourceLocation.h +++ b/minecraft/Minecraft.Client/net/minecraft/client/resources/ResourceLocation.h @@ -1,7 +1,7 @@ #pragma once #include "../renderer/Textures.h" -typedef arrayWithLength<_TEXTURE_NAME> textureNameArray; +typedef std::vector<_TEXTURE_NAME> textureNameArray; class ResourceLocation { private: textureNameArray m_texture; @@ -15,8 +15,7 @@ public: } ResourceLocation(_TEXTURE_NAME texture) { - m_texture = textureNameArray(1); - m_texture[0] = texture; + m_texture = {texture}; m_preloaded = true; } @@ -25,23 +24,23 @@ public: m_preloaded = false; } - ResourceLocation(intArray textures) { - m_texture = textureNameArray(textures.length); - for (unsigned int i = 0; i < textures.length; ++i) { + ResourceLocation(std::vector textures) { + m_texture.resize(textures.size()); + for (unsigned int i = 0; i < textures.size(); ++i) { m_texture[i] = (_TEXTURE_NAME)textures[i]; } m_preloaded = true; } - ~ResourceLocation() { delete m_texture.data; } + ~ResourceLocation() = default; _TEXTURE_NAME getTexture() { return m_texture[0]; } _TEXTURE_NAME getTexture(int idx) { return m_texture[idx]; } - int getTextureCount() { return m_texture.length; } + int getTextureCount() { return m_texture.size(); } std::wstring getPath() { return m_path; } bool isPreloaded() { return m_preloaded; } -}; \ No newline at end of file +}; diff --git a/minecraft/Minecraft.Client/net/minecraft/client/skins/AbstractTexturePack.cpp b/minecraft/Minecraft.Client/net/minecraft/client/skins/AbstractTexturePack.cpp index 8f8c35015..a9813cc44 100644 --- a/minecraft/Minecraft.Client/net/minecraft/client/skins/AbstractTexturePack.cpp +++ b/minecraft/Minecraft.Client/net/minecraft/client/skins/AbstractTexturePack.cpp @@ -169,15 +169,14 @@ void AbstractTexturePack::loadDefaultColourTable() { if (coloursFile.exists()) { uint32_t dataLength = coloursFile.length(); - byteArray data(dataLength); + std::vector data(dataLength); FileInputStream fis(coloursFile); fis.read(data, 0, dataLength); fis.close(); if (m_colourTable != nullptr) delete m_colourTable; - m_colourTable = new ColourTable(data.data, dataLength); + m_colourTable = new ColourTable(data.data(), dataLength); - delete[] data.data; } else { app.DebugPrintf("Failed to load the default colours table\n"); app.FatalLoadError(); @@ -186,11 +185,10 @@ void AbstractTexturePack::loadDefaultColourTable() { void AbstractTexturePack::loadDefaultHTMLColourTable() { if (app.hasArchiveFile(L"HTMLColours.col")) { - byteArray textColours = app.getArchiveFile(L"HTMLColours.col"); - m_colourTable->loadColoursFromData(textColours.data, - textColours.length); + std::vector textColours = app.getArchiveFile(L"HTMLColours.col"); + m_colourTable->loadColoursFromData(textColours.data(), + textColours.size()); - delete[] textColours.data; } } diff --git a/minecraft/Minecraft.Client/net/minecraft/client/skins/DLCTexturePack.cpp b/minecraft/Minecraft.Client/net/minecraft/client/skins/DLCTexturePack.cpp index b838dea52..26ecb6cc1 100644 --- a/minecraft/Minecraft.Client/net/minecraft/client/skins/DLCTexturePack.cpp +++ b/minecraft/Minecraft.Client/net/minecraft/client/skins/DLCTexturePack.cpp @@ -207,11 +207,10 @@ void DLCTexturePack::loadColourTable() { // Load the text colours if (app.hasArchiveFile(L"HTMLColours.col")) { - byteArray textColours = app.getArchiveFile(L"HTMLColours.col"); - m_colourTable->loadColoursFromData(textColours.data, - textColours.length); + std::vector textColours = app.getArchiveFile(L"HTMLColours.col"); + m_colourTable->loadColoursFromData(textColours.data(), + textColours.size()); - delete[] textColours.data; } } diff --git a/minecraft/Minecraft.Client/net/minecraft/client/skins/DefaultTexturePack.cpp b/minecraft/Minecraft.Client/net/minecraft/client/skins/DefaultTexturePack.cpp index 9d6fbaa44..f195ab91b 100644 --- a/minecraft/Minecraft.Client/net/minecraft/client/skins/DefaultTexturePack.cpp +++ b/minecraft/Minecraft.Client/net/minecraft/client/skins/DefaultTexturePack.cpp @@ -14,9 +14,9 @@ DefaultTexturePack::DefaultTexturePack() void DefaultTexturePack::loadIcon() { if (app.hasArchiveFile(L"Graphics\\TexturePackIcon.png")) { - byteArray ba = app.getArchiveFile(L"Graphics\\TexturePackIcon.png"); - m_iconData = ba.data; - m_iconSize = static_cast(ba.length); + std::vector ba = app.getArchiveFile(L"Graphics\\TexturePackIcon.png"); + m_iconData = ba.data(); + m_iconSize = static_cast(ba.size()); } } diff --git a/minecraft/Minecraft.Client/net/minecraft/client/title/TitleScreen.cpp b/minecraft/Minecraft.Client/net/minecraft/client/title/TitleScreen.cpp index bb2c29631..3be3b8b9c 100644 --- a/minecraft/Minecraft.Client/net/minecraft/client/title/TitleScreen.cpp +++ b/minecraft/Minecraft.Client/net/minecraft/client/title/TitleScreen.cpp @@ -30,7 +30,7 @@ TitleScreen::TitleScreen() { std::wstring filename = L"splashes.txt"; if (app.hasArchiveFile(filename)) { - byteArray splashesArray = app.getArchiveFile(filename); + std::vector splashesArray = app.getArchiveFile(filename); ByteArrayInputStream bais(splashesArray); InputStreamReader isr(&bais); BufferedReader br(&isr); diff --git a/minecraft/Minecraft.Client/net/minecraft/server/MinecraftServer.cpp b/minecraft/Minecraft.Client/net/minecraft/server/MinecraftServer.cpp index 85e935c8f..d634bd4a1 100644 --- a/minecraft/Minecraft.Client/net/minecraft/server/MinecraftServer.cpp +++ b/minecraft/Minecraft.Client/net/minecraft/server/MinecraftServer.cpp @@ -339,7 +339,7 @@ bool MinecraftServer::loadLevel(LevelStorageSource* storageSource, ProgressRenderer* mcprogress = Minecraft::GetInstance()->progressRenderer; // 4J TODO - free levels here if there are already some? - levels = ServerLevelArray(3); + levels = std::vector(3); int gameTypeId = settings->getInt( L"gamemode", @@ -412,7 +412,7 @@ bool MinecraftServer::loadLevel(LevelStorageSource* storageSource, // ConsoleSaveFile( L"" ), L"", L"", 0); // original // McRegionLevelStorage *storage = new McRegionLevelStorage(File(L"."), // name, true); // TODO - for (unsigned int i = 0; i < levels.length; i++) { + for (unsigned int i = 0; i < levels.size(); i++) { if (s_bServerHalted || !g_NetworkManager.IsInSession()) { return false; } @@ -510,19 +510,18 @@ bool MinecraftServer::loadLevel(LevelStorageSource* storageSource, ConsoleSaveFile* csf = getLevel(0)->getLevelStorage()->getSaveFile(); if (csf->doesFileExist(filepath)) { unsigned int numberOfBytesRead; - byteArray ba_gameRules; + std::vector ba_gameRules; FileEntry* fe = csf->createFile(filepath); - ba_gameRules.length = fe->getFileSize(); - ba_gameRules.data = new std::uint8_t[ba_gameRules.length]; + ba_gameRules.resize(fe->getFileSize()); csf->setFilePointer(fe, 0, SaveFileSeekOrigin::Begin); - csf->readFile(fe, ba_gameRules.data, ba_gameRules.length, + csf->readFile(fe, ba_gameRules.data(), ba_gameRules.size(), &numberOfBytesRead); - assert(numberOfBytesRead == ba_gameRules.length); + assert(numberOfBytesRead == ba_gameRules.size()); - app.m_gameRules.loadGameRules(ba_gameRules.data, ba_gameRules.length); + app.m_gameRules.loadGameRules(ba_gameRules.data(), ba_gameRules.size()); csf->closeHandle(fe); } @@ -544,7 +543,7 @@ bool MinecraftServer::loadLevel(LevelStorageSource* storageSource, // 4J Stu - This loop is changed in 1.0.1 to only process the first level // (ie the overworld), but I think we still want to do them all int i = 0; - for (int i = 0; i < levels.length; i++) { + for (int i = 0; i < levels.size(); i++) { // logger.info("Preparing start region for level " + i); if (i == 0 || settings->getBoolean(L"allow-nether", true)) { ServerLevel* level = levels[i]; @@ -773,7 +772,7 @@ void MinecraftServer::endProgress() { void MinecraftServer::saveAllChunks() { // logger.info("Saving chunks"); - for (unsigned int i = 0; i < levels.length; i++) { + for (unsigned int i = 0; i < levels.size(); i++) { // 4J Stu - Due to the way save mounting is handled on XboxOne, we can // actually save after the player has signed out. if (m_bPrimaryPlayerSignedOut) break; @@ -781,7 +780,7 @@ void MinecraftServer::saveAllChunks() { // level.dat with the data from the nethers leveldata. Fix for #7418 - // Functional: Gameplay: Saving after sleeping in a bed will place // player at nighttime when restarting. - ServerLevel* level = levels[levels.length - 1 - i]; + ServerLevel* level = levels[levels.size() - 1 - i]; if (level) // 4J - added check as level can be nullptr if we end up in // stopServer really early on due to network failure { @@ -790,7 +789,7 @@ void MinecraftServer::saveAllChunks() { // Only close the level storage when we have saved the last level, // otherwise we need to recreate the region files when saving the // next levels - if (i == (levels.length - 1)) { + if (i == (levels.size() - 1)) { level->closeLevelStorage(); } } @@ -807,20 +806,20 @@ void MinecraftServer::saveGameRules() { } else #endif { - byteArray ba; - ba.data = nullptr; - app.m_gameRules.saveGameRules(&ba.data, &ba.length); + uint8_t* baPtr = nullptr; + unsigned int baSize = 0; + app.m_gameRules.saveGameRules(&baPtr, &baSize); - if (ba.data != nullptr) { + if (baPtr != nullptr) { + std::vector ba(baPtr, baPtr + baSize); ConsoleSaveFile* csf = getLevel(0)->getLevelStorage()->getSaveFile(); FileEntry* fe = csf->createFile(ConsoleSavePath(GAME_RULE_SAVENAME)); csf->setFilePointer(fe, 0, SaveFileSeekOrigin::Begin); unsigned int length; - csf->writeFile(fe, ba.data, ba.length, &length); + csf->writeFile(fe, ba.data(), ba.size(), &length); - delete[] ba.data; csf->closeHandle(fe); } @@ -842,13 +841,13 @@ void MinecraftServer::Suspend() { if (players != nullptr) { players->saveAll(nullptr); } - for (unsigned int j = 0; j < levels.length; j++) { + for (unsigned int j = 0; j < levels.size(); j++) { if (s_bServerHalted) break; // 4J Stu - Save the levels in reverse order so we don't overwrite // the level.dat with the data from the nethers leveldata. Fix for // #7418 - Functional: Gameplay: Saving after sleeping in a bed will // place player at nighttime when restarting. - ServerLevel* level = levels[levels.length - 1 - j]; + ServerLevel* level = levels[levels.size() - 1 - j]; level->Suspend(); } if (!s_bServerHalted) { @@ -907,7 +906,7 @@ void MinecraftServer::stopServer(bool didInit) { // the level.dat with the data from the nethers leveldata. Fix for // #7418 - Functional: Gameplay: Saving after sleeping in a bed will // place player at nighttime when restarting. - // for (unsigned int i = levels.length - 1; i >= 0; i--) + // for (unsigned int i = levels.size() - 1; i >= 0; i--) //{ // ServerLevel *level = levels[i]; // if (level != nullptr) @@ -937,7 +936,7 @@ void MinecraftServer::stopServer(bool didInit) { // files have completed saving. // 4J-PB remove the server levels - unsigned int iServerLevelC = levels.length; + unsigned int iServerLevelC = levels.size(); for (unsigned int i = 0; i < iServerLevelC; i++) { if (levels[i] != nullptr) { delete levels[i]; @@ -1149,7 +1148,7 @@ void MinecraftServer::run(int64_t seed, void* lpParameter) { } if (MinecraftServer::setTimeAtEndOfTick) { MinecraftServer::setTimeAtEndOfTick = false; - for (unsigned int i = 0; i < levels.length; i++) { + for (unsigned int i = 0; i < levels.size(); i++) { // if (i == 0 || // settings->getBoolean(L"allow-nether", true)) //// 4J removed - we always have nether @@ -1161,7 +1160,7 @@ void MinecraftServer::run(int64_t seed, void* lpParameter) { } if (MinecraftServer::setTimeOfDayAtEndOfTick) { MinecraftServer::setTimeOfDayAtEndOfTick = false; - for (unsigned int i = 0; i < levels.length; i++) { + for (unsigned int i = 0; i < levels.size(); i++) { if (i == 0 || settings->getBoolean(L"allow-nether", true)) { ServerLevel* level = levels[i]; level->setDayTime(MinecraftServer::setTimeOfDay); @@ -1189,7 +1188,7 @@ void MinecraftServer::run(int64_t seed, void* lpParameter) { std::shared_ptr( new UpdateProgressPacket(20))); - for (unsigned int j = 0; j < levels.length; j++) { + for (unsigned int j = 0; j < levels.size(); j++) { if (s_bServerHalted) break; // 4J Stu - Save the levels in reverse order so we // don't overwrite the level.dat with the data from @@ -1197,7 +1196,7 @@ void MinecraftServer::run(int64_t seed, void* lpParameter) { // Functional: Gameplay: Saving after sleeping in a // bed will place player at nighttime when // restarting. - ServerLevel* level = levels[levels.length - 1 - j]; + ServerLevel* level = levels[levels.size() - 1 - j]; level->save( true, Minecraft::GetInstance()->progressRenderer, @@ -1423,7 +1422,7 @@ void MinecraftServer::tick() { pMinecraft->options->difficulty) ) ); }*/ - for (unsigned int i = 0; i < levels.length; i++) { + for (unsigned int i = 0; i < levels.size(); i++) { // if (i == 0 || settings->getBoolean(L"allow-nether", true)) // // 4J removed - we always have nether { @@ -1715,7 +1714,7 @@ void MinecraftServer::cycleSlowQueueIndex() { // which case it will return false and nothing is set up. bool MinecraftServer::flagEntitiesToBeRemoved(unsigned int* flags) { bool removedFound = false; - for (unsigned int i = 0; i < levels.length; i++) { + for (unsigned int i = 0; i < levels.size(); i++) { ServerLevel* level = levels[i]; if (level) { level->flagEntitiesToBeRemoved(flags, &removedFound); diff --git a/minecraft/Minecraft.Client/net/minecraft/server/MinecraftServer.h b/minecraft/Minecraft.Client/net/minecraft/server/MinecraftServer.h index c1d114a37..d87e31e82 100644 --- a/minecraft/Minecraft.Client/net/minecraft/server/MinecraftServer.h +++ b/minecraft/Minecraft.Client/net/minecraft/server/MinecraftServer.h @@ -77,7 +77,7 @@ private: public: ServerConnection* connection; Settings* settings; - ServerLevelArray levels; + std::vector levels; private: PlayerList* players; diff --git a/minecraft/Minecraft.Client/net/minecraft/server/PlayerList.cpp b/minecraft/Minecraft.Client/net/minecraft/server/PlayerList.cpp index 18c487281..7c47123d7 100644 --- a/minecraft/Minecraft.Client/net/minecraft/server/PlayerList.cpp +++ b/minecraft/Minecraft.Client/net/minecraft/server/PlayerList.cpp @@ -328,7 +328,7 @@ void PlayerList::updateEntireScoreboard(ServerScoreboard* scoreboard, //} } -void PlayerList::setLevel(ServerLevelArray levels) { +void PlayerList::setLevel(std::vector& levels) { playerIo = levels[0]->getLevelStorage()->getPlayerIO(); } diff --git a/minecraft/Minecraft.Client/net/minecraft/server/PlayerList.h b/minecraft/Minecraft.Client/net/minecraft/server/PlayerList.h index 49e49956c..fd67ffe34 100644 --- a/minecraft/Minecraft.Client/net/minecraft/server/PlayerList.h +++ b/minecraft/Minecraft.Client/net/minecraft/server/PlayerList.h @@ -78,7 +78,7 @@ protected: std::shared_ptr player); public: - void setLevel(ServerLevelArray levels); + void setLevel(std::vector& levels); void changeDimension(std::shared_ptr player, ServerLevel* from); int getMaxRange(); diff --git a/minecraft/Minecraft.Client/net/minecraft/server/commands/TeleportCommand.cpp b/minecraft/Minecraft.Client/net/minecraft/server/commands/TeleportCommand.cpp index 83b48c52a..68b9c1bf8 100644 --- a/minecraft/Minecraft.Client/net/minecraft/server/commands/TeleportCommand.cpp +++ b/minecraft/Minecraft.Client/net/minecraft/server/commands/TeleportCommand.cpp @@ -12,7 +12,7 @@ EGameCommand TeleportCommand::getId() { return eGameCommand_Teleport; } void TeleportCommand::execute(std::shared_ptr source, - byteArray commandData) { + std::vector& commandData) { ByteArrayInputStream bais(commandData); DataInputStream dis(&bais); @@ -49,20 +49,20 @@ void TeleportCommand::execute(std::shared_ptr source, } } - // if (args.length >= 1) { + // if (args.size() >= 1) { // MinecraftServer server = MinecraftServer.getInstance(); // ServerPlayer victim; - // if (args.length == 2 || args.length == 4) { + // if (args.size() == 2 || args.size() == 4) { // victim = server.getPlayers().getPlayer(args[0]); // if (victim == null) throw new PlayerNotFoundException(); // } else { // victim = (ServerPlayer) convertSourceToPlayer(source); // } - // if (args.length == 3 || args.length == 4) { + // if (args.size() == 3 || args.size() == 4) { // if (victim.level != null) { - // int pos = args.length - 3; + // int pos = args.size() - 3; // int maxPos = Level.MAX_LEVEL_SIZE; // int x = convertArgToInt(source, args[pos++], -maxPos, // maxPos); int y = convertArgToInt(source, @@ -73,9 +73,9 @@ void TeleportCommand::execute(std::shared_ptr source, // logAdminAction(source, "commands.tp.coordinates", // victim.getAName(), x, y, z); // } - // } else if (args.length == 1 || args.length == 2) { + // } else if (args.size() == 1 || args.size() == 2) { // ServerPlayer destination = - // server.getPlayers().getPlayer(args[args.length - 1]); if + // server.getPlayers().getPlayer(args[args.size() - 1]); if // (destination == null) throw new PlayerNotFoundException(); // victim.connection.teleport(destination.x, destination.y, diff --git a/minecraft/Minecraft.Client/net/minecraft/server/commands/TeleportCommand.h b/minecraft/Minecraft.Client/net/minecraft/server/commands/TeleportCommand.h index 85a678dcb..dd0efd466 100644 --- a/minecraft/Minecraft.Client/net/minecraft/server/commands/TeleportCommand.h +++ b/minecraft/Minecraft.Client/net/minecraft/server/commands/TeleportCommand.h @@ -6,7 +6,7 @@ class TeleportCommand : public Command { public: virtual EGameCommand getId(); virtual void execute(std::shared_ptr source, - byteArray commandData); + std::vector& commandData); static std::shared_ptr preparePacket( PlayerUID subject, PlayerUID destination); diff --git a/minecraft/Minecraft.Client/net/minecraft/server/level/PlayerChunkMap.cpp b/minecraft/Minecraft.Client/net/minecraft/server/level/PlayerChunkMap.cpp index 041241def..7b556bf8e 100644 --- a/minecraft/Minecraft.Client/net/minecraft/server/level/PlayerChunkMap.cpp +++ b/minecraft/Minecraft.Client/net/minecraft/server/level/PlayerChunkMap.cpp @@ -17,7 +17,7 @@ PlayerChunkMap::PlayerChunk::PlayerChunk(int x, int z, PlayerChunkMap* pcm) : pos(x, z) { // 4J - added initialisers changes = 0; - changedTiles = shortArray(MAX_CHANGES_BEFORE_RESEND); + changedTiles = std::vector(MAX_CHANGES_BEFORE_RESEND); xChangeMin = xChangeMax = 0; yChangeMin = yChangeMax = 0; zChangeMin = zChangeMax = 0; @@ -29,7 +29,7 @@ PlayerChunkMap::PlayerChunk::PlayerChunk(int x, int z, PlayerChunkMap* pcm) parent->getLevel()->cache->create(x, z); } -PlayerChunkMap::PlayerChunk::~PlayerChunk() { delete changedTiles.data; } +PlayerChunkMap::PlayerChunk::~PlayerChunk() {} // 4J added - construct an an array of flags that indicate which entities are // still waiting to have network packets sent out to say that they have been diff --git a/minecraft/Minecraft.Client/net/minecraft/server/level/PlayerChunkMap.h b/minecraft/Minecraft.Client/net/minecraft/server/level/PlayerChunkMap.h index c08c0235e..08fc0930f 100644 --- a/minecraft/Minecraft.Client/net/minecraft/server/level/PlayerChunkMap.h +++ b/minecraft/Minecraft.Client/net/minecraft/server/level/PlayerChunkMap.h @@ -37,7 +37,7 @@ public: // int x, z; ChunkPos pos; - shortArray changedTiles; + std::vector changedTiles; int changes; int xChangeMin, xChangeMax; int yChangeMin, yChangeMax; diff --git a/minecraft/Minecraft.Client/net/minecraft/server/level/ServerChunkCache.cpp b/minecraft/Minecraft.Client/net/minecraft/server/level/ServerChunkCache.cpp index 27432c726..6e4fbd7e5 100644 --- a/minecraft/Minecraft.Client/net/minecraft/server/level/ServerChunkCache.cpp +++ b/minecraft/Minecraft.Client/net/minecraft/server/level/ServerChunkCache.cpp @@ -23,8 +23,9 @@ ServerChunkCache::ServerChunkCache(ServerLevel* level, ChunkStorage* storage, autoCreate = false; // 4J added + std::vector emptyBlocks(Level::CHUNK_TILE_COUNT); emptyChunk = - new EmptyLevelChunk(level, byteArray(Level::CHUNK_TILE_COUNT), 0, 0); + new EmptyLevelChunk(level, emptyBlocks, 0, 0); this->level = level; this->storage = storage; diff --git a/minecraft/Minecraft.Client/net/minecraft/server/level/ServerLevel.cpp b/minecraft/Minecraft.Client/net/minecraft/server/level/ServerLevel.cpp index fff54c9f7..f6bbd39f5 100644 --- a/minecraft/Minecraft.Client/net/minecraft/server/level/ServerLevel.cpp +++ b/minecraft/Minecraft.Client/net/minecraft/server/level/ServerLevel.cpp @@ -42,7 +42,7 @@ #include "../../../../Common/ShutdownManager.h" #include "PlayerChunkMap.h" -WeighedTreasureArray ServerLevel::RANDOM_BONUS_ITEMS; +std::vector ServerLevel::RANDOM_BONUS_ITEMS; C4JThread* ServerLevel::m_updateThread = nullptr; C4JThread::EventArray* ServerLevel::m_updateTrigger; @@ -65,7 +65,7 @@ void ServerLevel::staticCtor() { m_updateThread->setProcessor(CPU_CORE_TILE_UPDATE); m_updateThread->run(); - RANDOM_BONUS_ITEMS = WeighedTreasureArray(20); + RANDOM_BONUS_ITEMS = std::vector(20); RANDOM_BONUS_ITEMS[0] = new WeighedTreasure(Item::stick_Id, 0, 1, 3, 10); RANDOM_BONUS_ITEMS[1] = new WeighedTreasure(Tile::wood_Id, 0, 1, 3, 10); @@ -1008,7 +1008,7 @@ void ServerLevel::entityAdded(std::shared_ptr e) { entitiesById[e->entityId] = e; std::vector >* es = e->getSubEntities(); if (es != nullptr) { - // for (int i = 0; i < es.length; i++) + // for (int i = 0; i < es.size(); i++) for (auto it = es->begin(); it != es->end(); ++it) { entitiesById.insert( intEntityMap::value_type((*it)->entityId, (*it))); @@ -1022,7 +1022,7 @@ void ServerLevel::entityRemoved(std::shared_ptr e) { entitiesById.erase(e->entityId); std::vector >* es = e->getSubEntities(); if (es != nullptr) { - // for (int i = 0; i < es.length; i++) + // for (int i = 0; i < es.size(); i++) for (auto it = es->begin(); it != es->end(); ++it) { entitiesById.erase((*it)->entityId); } diff --git a/minecraft/Minecraft.Client/net/minecraft/server/level/ServerLevel.h b/minecraft/Minecraft.Client/net/minecraft/server/level/ServerLevel.h index 69583e728..0430c0f07 100644 --- a/minecraft/Minecraft.Client/net/minecraft/server/level/ServerLevel.h +++ b/minecraft/Minecraft.Client/net/minecraft/server/level/ServerLevel.h @@ -41,7 +41,7 @@ private: MobSpawner* mobSpawner; int emptyTime; bool m_bAtLeastOnePlayerSleeping; // 4J Added - static WeighedTreasureArray + static std::vector RANDOM_BONUS_ITEMS; // 4J - brought forward from 1.3.2 std::vector tileEvents[2]; diff --git a/minecraft/Minecraft.Client/net/minecraft/server/level/ServerPlayer.cpp b/minecraft/Minecraft.Client/net/minecraft/server/level/ServerPlayer.cpp index 0b377b389..008c1ae9b 100644 --- a/minecraft/Minecraft.Client/net/minecraft/server/level/ServerPlayer.cpp +++ b/minecraft/Minecraft.Client/net/minecraft/server/level/ServerPlayer.cpp @@ -52,7 +52,7 @@ ServerPlayer::ServerPlayer(MinecraftServer* server, Level* level, latency = 0; wonGame = false; m_enteredEndExitPortal = false; - // lastCarried = arrayWithLength>(5); + // lastCarried = std::vector>(5); lastActionTime = 0; viewDistance = server->getPlayers()->getViewDistance(); @@ -133,7 +133,6 @@ ServerPlayer::ServerPlayer(MinecraftServer* server, Level* level, } ServerPlayer::~ServerPlayer() { - // delete [] lastCarried.data; } // 4J added - add bits to a flag array that is passed in, to represent those @@ -185,13 +184,12 @@ void ServerPlayer::readAdditionalSaveData(CompoundTag* entityTag) { GameRulesInstance* grs = gameMode->getGameRules(); if (entityTag->contains(L"GameRules") && grs != nullptr) { - byteArray ba = entityTag->getByteArray(L"GameRules"); + std::vector ba = entityTag->getByteArray(L"GameRules"); ByteArrayInputStream bais(ba); DataInputStream dis(&bais); grs->read(&dis); dis.close(); bais.close(); - // delete [] ba.data; } } @@ -204,7 +202,7 @@ void ServerPlayer::addAdditonalSaveData(CompoundTag* entityTag) { DataOutputStream dos(&baos); grs->write(&dos); entityTag->putByteArray(L"GameRules", baos.buf); - baos.buf.data = nullptr; + baos.buf.clear(); dos.close(); baos.close(); } @@ -256,7 +254,7 @@ void ServerPlayer::flushEntitiesToRemove() { while (!entitiesToRemove.empty()) { int sz = entitiesToRemove.size(); int amount = std::min(sz, RemoveEntitiesPacket::MAX_PER_PACKET); - intArray ids(amount); + std::vector ids(amount); int pos = 0; auto it = entitiesToRemove.begin(); @@ -1310,20 +1308,17 @@ void ServerPlayer::setPlayerInput(float xxa, float yya, bool jumping, } } -void ServerPlayer::awardStat(Stat* stat, byteArray param) { +void ServerPlayer::awardStat(Stat* stat, const std::vector& param) { if (stat == nullptr) { - delete[] param.data; return; } if (!stat->awardLocallyOnly) { - int count = *((int*)param.data); - delete[] param.data; + int count = *((int*)param.data()); connection->send(std::shared_ptr( new AwardStatPacket(stat->id, count))); - } else - delete[] param.data; + } } void ServerPlayer::disconnect() { diff --git a/minecraft/Minecraft.Client/net/minecraft/server/level/ServerPlayer.h b/minecraft/Minecraft.Client/net/minecraft/server/level/ServerPlayer.h index 50a266a56..4de3fd53b 100644 --- a/minecraft/Minecraft.Client/net/minecraft/server/level/ServerPlayer.h +++ b/minecraft/Minecraft.Client/net/minecraft/server/level/ServerPlayer.h @@ -140,7 +140,7 @@ public: void doCloseContainer(); void setPlayerInput(float xa, float ya, bool jumping, bool sneaking); - virtual void awardStat(Stat* stat, byteArray param); + virtual void awardStat(Stat* stat, const std::vector& param); void disconnect(); void resetSentInfo(); diff --git a/minecraft/Minecraft.Client/net/minecraft/server/network/PlayerConnection.cpp b/minecraft/Minecraft.Client/net/minecraft/server/network/PlayerConnection.cpp index 543b29dd9..a9235a93c 100644 --- a/minecraft/Minecraft.Client/net/minecraft/server/network/PlayerConnection.cpp +++ b/minecraft/Minecraft.Client/net/minecraft/server/network/PlayerConnection.cpp @@ -1216,7 +1216,7 @@ void PlayerConnection::handleSetCreativeModeSlot( packet->slotNum < (InventoryMenu::USE_ROW_SLOT_START + Inventory::getSelectionSize())); bool validItem = item == nullptr || - (item->id < Item::items.length && item->id >= 0 && + (item->id < Item::items.size() && item->id >= 0 && Item::items[item->id] != nullptr); bool validData = item == nullptr || @@ -1586,8 +1586,7 @@ void PlayerConnection::handleCustomPayload( customPayloadPacket->identifier) == 0) { AnvilMenu* menu = dynamic_cast(player->containerMenu); if (menu) { - if (customPayloadPacket->data.data == nullptr || - customPayloadPacket->data.length < 1) { + if (customPayloadPacket->data.empty()) { menu->setItemName(L""); } else { ByteArrayInputStream bais(customPayloadPacket->data); diff --git a/minecraft/Minecraft.Client/net/minecraft/server/network/ServerConnection.cpp b/minecraft/Minecraft.Client/net/minecraft/server/network/ServerConnection.cpp index 0849efc2a..6cd731fde 100644 --- a/minecraft/Minecraft.Client/net/minecraft/server/network/ServerConnection.cpp +++ b/minecraft/Minecraft.Client/net/minecraft/server/network/ServerConnection.cpp @@ -156,7 +156,7 @@ void ServerConnection::handleServerSettingsChanged( Minecraft* pMinecraft = Minecraft::GetInstance(); if (packet->action == ServerSettingsChangedPacket::HOST_DIFFICULTY) { - for (unsigned int i = 0; i < pMinecraft->levels.length; ++i) { + for (unsigned int i = 0; i < pMinecraft->levels.size(); ++i) { if (pMinecraft->levels[i] != nullptr) { app.DebugPrintf( "ClientConnection::handleServerSettingsChanged - " diff --git a/minecraft/Minecraft.World/ConsoleHelpers/ArrayWithLength.h b/minecraft/Minecraft.World/ConsoleHelpers/ArrayWithLength.h index b3e0c4b0c..0e0d36ac2 100644 --- a/minecraft/Minecraft.World/ConsoleHelpers/ArrayWithLength.h +++ b/minecraft/Minecraft.World/ConsoleHelpers/ArrayWithLength.h @@ -1,82 +1,10 @@ #pragma once #include +#include #include #include - -// Note - this is meant to be a really simple wrapper round a pointer just to be -// able to add a length value to arrays. -// As such, it shouldn't delete its data in a destructor as shallow copies will -// be made of this and we don't want to free the data just because one of those -// has gone out of scope -template -class arrayWithLength { -public: - T* data; - unsigned int length; - arrayWithLength() { - data = nullptr; - length = 0; - } - arrayWithLength(unsigned int elements, bool bClearArray = true) { - assert(elements != 0); - data = new T[elements]; - if (bClearArray) { - memset((void*)data, 0, sizeof(T) * elements); - } - this->length = elements; - } - - // 4J Stu Added this ctor so I static init arrays in the Item derivation - // tree - arrayWithLength(T data[], unsigned int elements) { - this->data = data; - this->length = elements; - } - - //~arrayWithLength() { delete[] data; } - - void resize(unsigned int elements) { - assert(elements > length); - T* temp = new T[elements]; - memset((void*)temp, 0, sizeof(T) * elements); - - if (data != nullptr) { - std::copy(data, data + length, temp); - - delete[] data; - } - data = temp; - length = elements; - } - - T& operator[](unsigned int i) { return data[i]; } - T operator[](unsigned int i) const { return data[i]; } -}; - -// TODO 4J Stu - This looks right, but is it? -template -class array2DWithLength { - typedef arrayWithLength* _parrayWithLength; - -public: - _parrayWithLength* data; - unsigned int length; - array2DWithLength() { - data = nullptr; - length = 0; - } - array2DWithLength(unsigned int dimA, unsigned int dimB) { - data = new _parrayWithLength[dimA]; - this->length = dimA; - - for (unsigned int i = 0; i < length; i++) - data[i] = new arrayWithLength(dimB); - } - - _parrayWithLength& operator[](unsigned int i) { return data[i]; } - _parrayWithLength operator[](unsigned int i) const { return data[i]; } -}; +#include class Biome; class LevelChunk; @@ -99,32 +27,3 @@ class Layer; class ModelPart; class Enchantment; class ClipChunk; - -typedef arrayWithLength doubleArray; -typedef array2DWithLength coords2DArray; -typedef arrayWithLength byteArray; -typedef arrayWithLength charArray; -typedef arrayWithLength shortArray; -typedef arrayWithLength intArray; -typedef arrayWithLength floatArray; -typedef arrayWithLength BiomeArray; -typedef arrayWithLength LevelChunkArray; -typedef array2DWithLength LevelChunk2DArray; -typedef arrayWithLength NodeArray; -typedef arrayWithLength ItemArray; -typedef arrayWithLength TileArray; -typedef arrayWithLength StatArray; -typedef arrayWithLength MobCategoryArray; -typedef arrayWithLength FileArray; -typedef arrayWithLength ServerLevelArray; -typedef arrayWithLength MultiPlayerLevelArray; -typedef arrayWithLength LevelArray; -typedef arrayWithLength LevelRendererArray; -typedef arrayWithLength WeighedRandomItemArray; -typedef arrayWithLength WeighedTreasureArray; -typedef arrayWithLength > LayerArray; -// typedef arrayWithLength CubeArray; -typedef arrayWithLength ModelPartArray; -typedef arrayWithLength EnchantmentArray; -typedef arrayWithLength ClipChunkArray; - diff --git a/minecraft/Minecraft.World/ConsoleHelpers/ConsoleSaveFileIO/ConsoleSaveFileInputStream.cpp b/minecraft/Minecraft.World/ConsoleHelpers/ConsoleSaveFileIO/ConsoleSaveFileInputStream.cpp index 002c6c8bb..36f0500eb 100644 --- a/minecraft/Minecraft.World/ConsoleHelpers/ConsoleSaveFileIO/ConsoleSaveFileInputStream.cpp +++ b/minecraft/Minecraft.World/ConsoleHelpers/ConsoleSaveFileIO/ConsoleSaveFileInputStream.cpp @@ -45,18 +45,18 @@ int ConsoleSaveFileInputStream::read() { return static_cast(byteRead); } -// Reads up to b.length bytes of data from this input stream into an array of +// Reads up to b.size() bytes of data from this input stream into an array of // bytes. This method blocks until some input is available. Parameters: b - the // buffer into which the data is read. Returns: the total number of bytes read // into the buffer, or -1 if there is no more data because the end of the file // has been reached. -int ConsoleSaveFileInputStream::read(byteArray b) { +int ConsoleSaveFileInputStream::read(std::vector& b) { unsigned int numberOfBytesRead; bool result = m_saveFile->readFile(m_file, - &b.data, // data buffer - b.length, // number of bytes to read + b.data(), // data buffer + b.size(), // number of bytes to read &numberOfBytesRead // number of bytes read ); @@ -78,10 +78,10 @@ int ConsoleSaveFileInputStream::read(byteArray b) { // b len - the maximum number of bytes read. Returns: the total number of bytes // read into the buffer, or -1 if there is no more data because the end of the // file has been reached. -int ConsoleSaveFileInputStream::read(byteArray b, unsigned int offset, +int ConsoleSaveFileInputStream::read(std::vector& b, unsigned int offset, unsigned int length) { // 4J Stu - We don't want to read any more than the array buffer can hold - assert(length <= (b.length - offset)); + assert(length <= (b.size() - offset)); unsigned int numberOfBytesRead; diff --git a/minecraft/Minecraft.World/ConsoleHelpers/ConsoleSaveFileIO/ConsoleSaveFileInputStream.h b/minecraft/Minecraft.World/ConsoleHelpers/ConsoleSaveFileIO/ConsoleSaveFileInputStream.h index 7790a4d58..f9705ef48 100644 --- a/minecraft/Minecraft.World/ConsoleHelpers/ConsoleSaveFileIO/ConsoleSaveFileInputStream.h +++ b/minecraft/Minecraft.World/ConsoleHelpers/ConsoleSaveFileIO/ConsoleSaveFileInputStream.h @@ -15,8 +15,8 @@ public: const ConsoleSavePath& file); ConsoleSaveFileInputStream(ConsoleSaveFile* saveFile, FileEntry* file); virtual int read(); - virtual int read(byteArray b); - virtual int read(byteArray b, unsigned int offset, unsigned int length); + virtual int read(std::vector& b); + virtual int read(std::vector& b, unsigned int offset, unsigned int length); virtual void close(); virtual int64_t skip(int64_t n) { return n; } diff --git a/minecraft/Minecraft.World/ConsoleHelpers/ConsoleSaveFileIO/ConsoleSaveFileOriginal.cpp b/minecraft/Minecraft.World/ConsoleHelpers/ConsoleSaveFileIO/ConsoleSaveFileOriginal.cpp index 87dd81504..397fbd230 100644 --- a/minecraft/Minecraft.World/ConsoleHelpers/ConsoleSaveFileIO/ConsoleSaveFileOriginal.cpp +++ b/minecraft/Minecraft.World/ConsoleHelpers/ConsoleSaveFileIO/ConsoleSaveFileOriginal.cpp @@ -819,7 +819,7 @@ void ConsoleSaveFileOriginal::ConvertRegionFile(File sourceFile) { sourceRegionFile.getChunkDataInputStream(x, z); if (dis) { - byteArray inData(1024 * 1024); + std::vector inData(1024 * 1024); int read = dis->read(inData); dis->close(); dis->deleteChildStream(); @@ -832,7 +832,7 @@ void ConsoleSaveFileOriginal::ConvertRegionFile(File sourceFile) { dos->close(); dos->deleteChildStream(); delete dos; - delete inData.data; + // vector cleans up automatically } } } diff --git a/minecraft/Minecraft.World/ConsoleHelpers/ConsoleSaveFileIO/ConsoleSaveFileOutputStream.cpp b/minecraft/Minecraft.World/ConsoleHelpers/ConsoleSaveFileIO/ConsoleSaveFileOutputStream.cpp index 27b02a4d7..49944f0e1 100644 --- a/minecraft/Minecraft.World/ConsoleHelpers/ConsoleSaveFileIO/ConsoleSaveFileOutputStream.cpp +++ b/minecraft/Minecraft.World/ConsoleHelpers/ConsoleSaveFileIO/ConsoleSaveFileOutputStream.cpp @@ -55,21 +55,21 @@ void ConsoleSaveFileOutputStream::write(unsigned int b) { } } -// Writes b.length bytes from the specified byte array to this file output +// Writes b.size() bytes from the specified byte array to this file output // stream. Parameters: b - the data. -void ConsoleSaveFileOutputStream::write(byteArray b) { +void ConsoleSaveFileOutputStream::write(const std::vector& b) { unsigned int numberOfBytesWritten; bool result = m_saveFile->writeFile(m_file, - &b.data, // data buffer - b.length, // number of bytes to write + b.data(), // data buffer + b.size(), // number of bytes to write &numberOfBytesWritten // number of bytes written ); if (!result) { // TODO 4J Stu - Some kind of error handling - } else if (numberOfBytesWritten == 0 || numberOfBytesWritten != b.length) { + } else if (numberOfBytesWritten == 0 || numberOfBytesWritten != b.size()) { // File pointer is past the end of the file } } @@ -77,10 +77,10 @@ void ConsoleSaveFileOutputStream::write(byteArray b) { // Writes len bytes from the specified byte array starting at offset off to this // file output stream. Parameters: b - the data. off - the start offset in the // data. len - the number of bytes to write. -void ConsoleSaveFileOutputStream::write(byteArray b, unsigned int offset, +void ConsoleSaveFileOutputStream::write(const std::vector& b, unsigned int offset, unsigned int length) { // 4J Stu - We don't want to write any more than the array buffer holds - assert(length <= (b.length - offset)); + assert(length <= (b.size() - offset)); unsigned int numberOfBytesWritten; diff --git a/minecraft/Minecraft.World/ConsoleHelpers/ConsoleSaveFileIO/ConsoleSaveFileOutputStream.h b/minecraft/Minecraft.World/ConsoleHelpers/ConsoleSaveFileIO/ConsoleSaveFileOutputStream.h index 6d0a40155..3ca2d7c82 100644 --- a/minecraft/Minecraft.World/ConsoleHelpers/ConsoleSaveFileIO/ConsoleSaveFileOutputStream.h +++ b/minecraft/Minecraft.World/ConsoleHelpers/ConsoleSaveFileIO/ConsoleSaveFileOutputStream.h @@ -15,8 +15,8 @@ public: const ConsoleSavePath& file); ConsoleSaveFileOutputStream(ConsoleSaveFile* saveFile, FileEntry* file); virtual void write(unsigned int b); - virtual void write(byteArray b); - virtual void write(byteArray b, unsigned int offset, unsigned int length); + virtual void write(const std::vector& b); + virtual void write(const std::vector& b, unsigned int offset, unsigned int length); virtual void close(); virtual void flush() {} diff --git a/minecraft/Minecraft.World/ConsoleHelpers/ConsoleSaveFileIO/ConsoleSaveFileSplit.cpp b/minecraft/Minecraft.World/ConsoleHelpers/ConsoleSaveFileIO/ConsoleSaveFileSplit.cpp index dae092929..9e0a0da17 100644 --- a/minecraft/Minecraft.World/ConsoleHelpers/ConsoleSaveFileIO/ConsoleSaveFileSplit.cpp +++ b/minecraft/Minecraft.World/ConsoleHelpers/ConsoleSaveFileIO/ConsoleSaveFileSplit.cpp @@ -1542,7 +1542,7 @@ void ConsoleSaveFileSplit::ConvertRegionFile(File sourceFile) { sourceRegionFile.getChunkDataInputStream(x, z); if (dis) { - byteArray inData(1024 * 1024); + std::vector inData(1024 * 1024); int read = dis->read(inData); dis->close(); dis->deleteChildStream(); @@ -1555,7 +1555,6 @@ void ConsoleSaveFileSplit::ConvertRegionFile(File sourceFile) { dos->close(); dos->deleteChildStream(); delete dos; - delete inData.data; } } } diff --git a/minecraft/Minecraft.World/ConsoleHelpers/ConsoleSaveFileIO/FileHeader.cpp b/minecraft/Minecraft.World/ConsoleHelpers/ConsoleSaveFileIO/FileHeader.cpp index e5124ba60..b998ff3f2 100644 --- a/minecraft/Minecraft.World/ConsoleHelpers/ConsoleSaveFileIO/FileHeader.cpp +++ b/minecraft/Minecraft.World/ConsoleHelpers/ConsoleSaveFileIO/FileHeader.cpp @@ -109,8 +109,8 @@ void FileHeader::WriteHeader(void* saveMem) { for (unsigned int i = 0; i < fileTable.size(); ++i) { // wprintf(L"File: %ls, Start = %d, Length = %d, End = %d\n", // fileTable[i]->data.filename, fileTable[i]->data.startOffset, - // fileTable[i]->data.length, fileTable[i]->data.startOffset + - // fileTable[i]->data.length); + // fileTable[i]->data.size(), fileTable[i]->data.startOffset + + // fileTable[i]->data.size()); memcpy((void*)headerPosition, &fileTable[i]->data, sizeof(FileEntrySaveData)); // assert(numberOfBytesWritten == sizeof(FileEntrySaveData)); diff --git a/minecraft/Minecraft.World/Source Files/compression.cpp b/minecraft/Minecraft.World/Source Files/compression.cpp index 0237fe7de..a990b0b19 100644 --- a/minecraft/Minecraft.World/Source Files/compression.cpp +++ b/minecraft/Minecraft.World/Source Files/compression.cpp @@ -370,7 +370,7 @@ int32_t Compression::DecompressWithType(void* pDestination, pbDestSize[3 - i] = pbSource[i]; } - byteArray uncompr = byteArray(*pDestSize); + std::vector uncompr = std::vector(*pDestSize); // Build decompression stream z_stream strm; diff --git a/minecraft/Minecraft.World/net/minecraft/commands/Command.h b/minecraft/Minecraft.World/net/minecraft/commands/Command.h index 50d624d46..7b2c87adf 100644 --- a/minecraft/Minecraft.World/net/minecraft/commands/Command.h +++ b/minecraft/Minecraft.World/net/minecraft/commands/Command.h @@ -29,7 +29,7 @@ public: virtual EGameCommand getId() = 0; virtual int getPermissionLevel(); virtual void execute(std::shared_ptr source, - byteArray commandData) = 0; + std::vector& commandData) = 0; virtual bool canExecute(std::shared_ptr source); static void logAdminAction(std::shared_ptr source, diff --git a/minecraft/Minecraft.World/net/minecraft/commands/CommandDispatcher.cpp b/minecraft/Minecraft.World/net/minecraft/commands/CommandDispatcher.cpp index a1ce0c9db..7f451b2fd 100644 --- a/minecraft/Minecraft.World/net/minecraft/commands/CommandDispatcher.cpp +++ b/minecraft/Minecraft.World/net/minecraft/commands/CommandDispatcher.cpp @@ -4,7 +4,7 @@ int CommandDispatcher::performCommand(std::shared_ptr sender, EGameCommand command, - byteArray commandData) { + std::vector& commandData) { auto it = commandsById.find(command); if (it != commandsById.end()) { diff --git a/minecraft/Minecraft.World/net/minecraft/commands/CommandDispatcher.h b/minecraft/Minecraft.World/net/minecraft/commands/CommandDispatcher.h index 968815d67..44359a21e 100644 --- a/minecraft/Minecraft.World/net/minecraft/commands/CommandDispatcher.h +++ b/minecraft/Minecraft.World/net/minecraft/commands/CommandDispatcher.h @@ -10,6 +10,6 @@ private: public: int performCommand(std::shared_ptr sender, - EGameCommand command, byteArray commandData); + EGameCommand command, std::vector& commandData); Command* addCommand(Command* command); }; \ No newline at end of file diff --git a/minecraft/Minecraft.World/net/minecraft/commands/PlayerSelector.h b/minecraft/Minecraft.World/net/minecraft/commands/PlayerSelector.h index 1cd04d966..d114ed47c 100644 --- a/minecraft/Minecraft.World/net/minecraft/commands/PlayerSelector.h +++ b/minecraft/Minecraft.World/net/minecraft/commands/PlayerSelector.h @@ -46,17 +46,17 @@ Pattern.compile("\\G(\\w+)=([-!]?[\\w-]*)(?:$|,)"); public static ServerPlayer getPlayer(CommandSender source, String input) { ServerPlayer[] result = getPlayers(source, input); - if (result == null || result.length != 1) return null; + if (result == null || result.size() != 1) return null; return result[0]; } public static String getPlayerNames(CommandSender source, String input) { ServerPlayer[] result = getPlayers(source, input); - if (result == null || result.length == 0) return null; - String[] names = new String[result.length]; + if (result == null || result.size() == 0) return null; + String[] names = new String[result.size()]; - for (int i = 0; i < names.length; i++) { + for (int i = 0; i < names.size(); i++) { names[i] = result[i].getDisplayName(); } diff --git a/minecraft/Minecraft.World/net/minecraft/commands/common/DefaultGameModeCommand.cpp b/minecraft/Minecraft.World/net/minecraft/commands/common/DefaultGameModeCommand.cpp index f5b293447..0bb81fad1 100644 --- a/minecraft/Minecraft.World/net/minecraft/commands/common/DefaultGameModeCommand.cpp +++ b/minecraft/Minecraft.World/net/minecraft/commands/common/DefaultGameModeCommand.cpp @@ -7,8 +7,8 @@ EGameCommand DefaultGameModeCommand::getId() { } void DefaultGameModeCommand::execute(std::shared_ptr source, - byteArray commandData) { - // if (args.length > 0) { + std::vector& commandData) { + // if (args.size() > 0) { // GameType newMode = getModeForString(source, args[0]); // doSetGameType(newMode); diff --git a/minecraft/Minecraft.World/net/minecraft/commands/common/DefaultGameModeCommand.h b/minecraft/Minecraft.World/net/minecraft/commands/common/DefaultGameModeCommand.h index 476f6ed4e..76ea4f93d 100644 --- a/minecraft/Minecraft.World/net/minecraft/commands/common/DefaultGameModeCommand.h +++ b/minecraft/Minecraft.World/net/minecraft/commands/common/DefaultGameModeCommand.h @@ -8,7 +8,7 @@ class DefaultGameModeCommand : public GameModeCommand { public: virtual EGameCommand getId(); virtual void execute(std::shared_ptr source, - byteArray commandData); + std::vector& commandData); protected: void doSetGameType(GameType* newGameType); diff --git a/minecraft/Minecraft.World/net/minecraft/commands/common/EffectCommand.cpp b/minecraft/Minecraft.World/net/minecraft/commands/common/EffectCommand.cpp index 5021a4bad..709f08ab0 100644 --- a/minecraft/Minecraft.World/net/minecraft/commands/common/EffectCommand.cpp +++ b/minecraft/Minecraft.World/net/minecraft/commands/common/EffectCommand.cpp @@ -11,8 +11,8 @@ std::wstring EffectCommand::getUsage(CommandSender* source) { } void EffectCommand::execute(std::shared_ptr source, - byteArray commandData) { - // if (args.length >= 2) + std::vector& commandData) { + // if (args.size() >= 2) //{ // Player player = convertToPlayer(source, args[0]); @@ -30,12 +30,12 @@ void EffectCommand::execute(std::shared_ptr source, // int seconds = 30; // int amplifier = 0; - // if (effectId < 0 || effectId >= MobEffect.effects.length || + // if (effectId < 0 || effectId >= MobEffect.effects.size() || // MobEffect.effects[effectId] == null) { throw new // InvalidNumberException("commands.effect.notFound", effectId); // } - // if (args.length >= 3) { + // if (args.size() >= 3) { // seconds = convertArgToInt(source, args[2], 0, 1000000); // if (MobEffect.effects[effectId].isInstantenous()) { // duration = seconds; @@ -47,7 +47,7 @@ void EffectCommand::execute(std::shared_ptr source, // duration = 1; // } - // if (args.length >= 4) { + // if (args.size() >= 4) { // amplifier = convertArgToInt(source, args[3], 0, 255); // } diff --git a/minecraft/Minecraft.World/net/minecraft/commands/common/EffectCommand.h b/minecraft/Minecraft.World/net/minecraft/commands/common/EffectCommand.h index 436a9084f..94c891b16 100644 --- a/minecraft/Minecraft.World/net/minecraft/commands/common/EffectCommand.h +++ b/minecraft/Minecraft.World/net/minecraft/commands/common/EffectCommand.h @@ -7,7 +7,7 @@ public: EGameCommand getId(); int getPermissionLevel(); std::wstring getUsage(CommandSender* source); - void execute(std::shared_ptr source, byteArray commandData); + void execute(std::shared_ptr source, std::vector& commandData); protected: std::wstring getPlayerNames(); diff --git a/minecraft/Minecraft.World/net/minecraft/commands/common/EnchantItemCommand.cpp b/minecraft/Minecraft.World/net/minecraft/commands/common/EnchantItemCommand.cpp index c5abe1538..038e3eded 100644 --- a/minecraft/Minecraft.World/net/minecraft/commands/common/EnchantItemCommand.cpp +++ b/minecraft/Minecraft.World/net/minecraft/commands/common/EnchantItemCommand.cpp @@ -10,7 +10,7 @@ EGameCommand EnchantItemCommand::getId() { return eGameCommand_EnchantItem; } int EnchantItemCommand::getPermissionLevel() { return LEVEL_GAMEMASTERS; } void EnchantItemCommand::execute(std::shared_ptr source, - byteArray commandData) { + std::vector& commandData) { ByteArrayInputStream bais(commandData); DataInputStream dis(&bais); diff --git a/minecraft/Minecraft.World/net/minecraft/commands/common/EnchantItemCommand.h b/minecraft/Minecraft.World/net/minecraft/commands/common/EnchantItemCommand.h index 77f914683..dde988f66 100644 --- a/minecraft/Minecraft.World/net/minecraft/commands/common/EnchantItemCommand.h +++ b/minecraft/Minecraft.World/net/minecraft/commands/common/EnchantItemCommand.h @@ -9,7 +9,7 @@ public: virtual EGameCommand getId(); int getPermissionLevel(); virtual void execute(std::shared_ptr source, - byteArray commandData); + std::vector& commandData); static std::shared_ptr preparePacket( std::shared_ptr player, int enchantmentId, diff --git a/minecraft/Minecraft.World/net/minecraft/commands/common/ExperienceCommand.cpp b/minecraft/Minecraft.World/net/minecraft/commands/common/ExperienceCommand.cpp index 22ecc2299..fad76a451 100644 --- a/minecraft/Minecraft.World/net/minecraft/commands/common/ExperienceCommand.cpp +++ b/minecraft/Minecraft.World/net/minecraft/commands/common/ExperienceCommand.cpp @@ -10,8 +10,8 @@ EGameCommand ExperienceCommand::getId() { return eGameCommand_Experience; } int ExperienceCommand::getPermissionLevel() { return LEVEL_GAMEMASTERS; } void ExperienceCommand::execute(std::shared_ptr source, - byteArray commandData) { - // if (args.length > 0) { + std::vector& commandData) { + // if (args.size() > 0) { // Player player; // String inputAmount = args[0]; // @@ -25,7 +25,7 @@ void ExperienceCommand::execute(std::shared_ptr source, // // if (take) amount *= -1; // - // if (args.length > 1) { + // if (args.size() > 1) { // player = convertToPlayer(source, args[1]); // } else { // player = convertSourceToPlayer(source); diff --git a/minecraft/Minecraft.World/net/minecraft/commands/common/ExperienceCommand.h b/minecraft/Minecraft.World/net/minecraft/commands/common/ExperienceCommand.h index 54dbe732c..6a1a52383 100644 --- a/minecraft/Minecraft.World/net/minecraft/commands/common/ExperienceCommand.h +++ b/minecraft/Minecraft.World/net/minecraft/commands/common/ExperienceCommand.h @@ -9,5 +9,5 @@ public: virtual EGameCommand getId(); virtual int getPermissionLevel(); virtual void execute(std::shared_ptr source, - byteArray commandData); + std::vector& commandData); }; \ No newline at end of file diff --git a/minecraft/Minecraft.World/net/minecraft/commands/common/GameDifficultyCommand.h b/minecraft/Minecraft.World/net/minecraft/commands/common/GameDifficultyCommand.h index e268d689a..04364a24f 100644 --- a/minecraft/Minecraft.World/net/minecraft/commands/common/GameDifficultyCommand.h +++ b/minecraft/Minecraft.World/net/minecraft/commands/common/GameDifficultyCommand.h @@ -36,7 +36,7 @@ public class GameDifficultyCommand extends BaseCommand { @Override public void execute(CommandSender source, String[] args) { - if (args.length > 0) { + if (args.size() > 0) { int newDiff = getDifficultyForString(source, args[0]); MinecraftServer.getInstance().setDifficulty(newDiff); @@ -63,7 +63,7 @@ convertArgToInt(source, name, 0, 3); @Override public List matchArguments(CommandSender source, String[] args) { - if (args.length == 1) { + if (args.size() == 1) { return matchArguments(args, "peaceful", "easy", "normal", "hard"); } diff --git a/minecraft/Minecraft.World/net/minecraft/commands/common/GameModeCommand.cpp b/minecraft/Minecraft.World/net/minecraft/commands/common/GameModeCommand.cpp index 507973245..8c40c622e 100644 --- a/minecraft/Minecraft.World/net/minecraft/commands/common/GameModeCommand.cpp +++ b/minecraft/Minecraft.World/net/minecraft/commands/common/GameModeCommand.cpp @@ -7,10 +7,10 @@ EGameCommand GameModeCommand::getId() { return eGameCommand_GameMode; } int GameModeCommand::getPermissionLevel() { return LEVEL_GAMEMASTERS; } void GameModeCommand::execute(std::shared_ptr source, - byteArray commandData) { - // if (args.length > 0) { + std::vector& commandData) { + // if (args.size() > 0) { // GameType newMode = getModeForString(source, args[0]); - // Player player = args.length >= 2 ? convertToPlayer(source, args[1]) : + // Player player = args.size() >= 2 ? convertToPlayer(source, args[1]) : // convertSourceToPlayer(source); // player.setGameMode(newMode); @@ -46,6 +46,6 @@ GameType* GameModeCommand::getModeForString( // name.equalsIgnoreCase("a")) { return GameType.ADVENTURE; } else { // return // LevelSettings.validateGameType(convertArgToInt(source, name, 0, - // GameType.values().length - 2)); + // GameType.values().size() - 2)); // } } \ No newline at end of file diff --git a/minecraft/Minecraft.World/net/minecraft/commands/common/GameModeCommand.h b/minecraft/Minecraft.World/net/minecraft/commands/common/GameModeCommand.h index 87f9c1eec..552028bf9 100644 --- a/minecraft/Minecraft.World/net/minecraft/commands/common/GameModeCommand.h +++ b/minecraft/Minecraft.World/net/minecraft/commands/common/GameModeCommand.h @@ -9,7 +9,7 @@ public: virtual EGameCommand getId(); int getPermissionLevel(); virtual void execute(std::shared_ptr source, - byteArray commandData); + std::vector& commandData); protected: GameType* getModeForString(std::shared_ptr source, diff --git a/minecraft/Minecraft.World/net/minecraft/commands/common/GameRuleCommand.h b/minecraft/Minecraft.World/net/minecraft/commands/common/GameRuleCommand.h index 27baea538..e7ca5bfa0 100644 --- a/minecraft/Minecraft.World/net/minecraft/commands/common/GameRuleCommand.h +++ b/minecraft/Minecraft.World/net/minecraft/commands/common/GameRuleCommand.h @@ -30,7 +30,7 @@ public class GameRuleCommand extends BaseCommand { @Override public void execute(CommandSender source, String[] args) { - if (args.length == 2) { + if (args.size() == 2) { String rule = args[0]; String value = args[1]; @@ -44,7 +44,7 @@ public class GameRuleCommand extends BaseCommand { } return; - } else if (args.length == 1) { + } else if (args.size() == 1) { String rule = args[0]; GameRules rules = getRules(); @@ -56,7 +56,7 @@ public class GameRuleCommand extends BaseCommand { } return; - } else if (args.length == 0) { + } else if (args.size() == 0) { GameRules rules = getRules(); source.sendMessage(ChatMessageComponent.forPlainText(joinStrings(rules.getRuleNames()))); return; @@ -67,9 +67,9 @@ public class GameRuleCommand extends BaseCommand { @Override public List matchArguments(CommandSender source, String[] args) { - if (args.length == 1) { + if (args.size() == 1) { return matchArguments(args, getRules().getRuleNames()); - } else if (args.length == 2) { + } else if (args.size() == 2) { return matchArguments(args, "true", "false"); } diff --git a/minecraft/Minecraft.World/net/minecraft/commands/common/GiveItemCommand.cpp b/minecraft/Minecraft.World/net/minecraft/commands/common/GiveItemCommand.cpp index a62fed7a3..46feb8ed0 100644 --- a/minecraft/Minecraft.World/net/minecraft/commands/common/GiveItemCommand.cpp +++ b/minecraft/Minecraft.World/net/minecraft/commands/common/GiveItemCommand.cpp @@ -11,7 +11,7 @@ EGameCommand GiveItemCommand::getId() { return eGameCommand_Give; } int GiveItemCommand::getPermissionLevel() { return LEVEL_GAMEMASTERS; } void GiveItemCommand::execute(std::shared_ptr source, - byteArray commandData) { + std::vector& commandData) { ByteArrayInputStream bais(commandData); DataInputStream dis(&bais); diff --git a/minecraft/Minecraft.World/net/minecraft/commands/common/GiveItemCommand.h b/minecraft/Minecraft.World/net/minecraft/commands/common/GiveItemCommand.h index 3df5ac671..31158a1b4 100644 --- a/minecraft/Minecraft.World/net/minecraft/commands/common/GiveItemCommand.h +++ b/minecraft/Minecraft.World/net/minecraft/commands/common/GiveItemCommand.h @@ -9,7 +9,7 @@ public: virtual EGameCommand getId(); virtual int getPermissionLevel(); virtual void execute(std::shared_ptr source, - byteArray commandData); + std::vector& commandData); public: static std::shared_ptr preparePacket( diff --git a/minecraft/Minecraft.World/net/minecraft/commands/common/KillCommand.cpp b/minecraft/Minecraft.World/net/minecraft/commands/common/KillCommand.cpp index 732313952..d34a086dc 100644 --- a/minecraft/Minecraft.World/net/minecraft/commands/common/KillCommand.cpp +++ b/minecraft/Minecraft.World/net/minecraft/commands/common/KillCommand.cpp @@ -10,7 +10,7 @@ EGameCommand KillCommand::getId() { return eGameCommand_Kill; } int KillCommand::getPermissionLevel() { return LEVEL_ALL; } void KillCommand::execute(std::shared_ptr source, - byteArray commandData) { + std::vector& commandData) { std::shared_ptr player = std::dynamic_pointer_cast(source); player->hurt(DamageSource::outOfWorld, std::numeric_limits::max()); diff --git a/minecraft/Minecraft.World/net/minecraft/commands/common/KillCommand.h b/minecraft/Minecraft.World/net/minecraft/commands/common/KillCommand.h index 43a7c40ee..5480a593a 100644 --- a/minecraft/Minecraft.World/net/minecraft/commands/common/KillCommand.h +++ b/minecraft/Minecraft.World/net/minecraft/commands/common/KillCommand.h @@ -7,5 +7,5 @@ public: virtual EGameCommand getId(); virtual int getPermissionLevel(); virtual void execute(std::shared_ptr source, - byteArray commandData); + std::vector& commandData); }; \ No newline at end of file diff --git a/minecraft/Minecraft.World/net/minecraft/commands/common/PlaySoundCommand.h b/minecraft/Minecraft.World/net/minecraft/commands/common/PlaySoundCommand.h index d3f82641a..e591c8ec0 100644 --- a/minecraft/Minecraft.World/net/minecraft/commands/common/PlaySoundCommand.h +++ b/minecraft/Minecraft.World/net/minecraft/commands/common/PlaySoundCommand.h @@ -28,7 +28,7 @@ public class PlaySoundCommand extends BaseCommand { @Override public void execute(CommandSender source, String[] args) { - if (args.length < 2) { + if (args.size() < 2) { throw new UsageException(getUsage(source)); } @@ -42,14 +42,14 @@ public class PlaySoundCommand extends BaseCommand { double pitch = 1; double minVolume = 0; - if (args.length > index) x = convertArgToCoordinate(source, x, -args[index++]); if (args.length > index) y = convertArgToCoordinate(source, y, -args[index++], 0, 0); if (args.length > index) z = + if (args.size() > index) x = convertArgToCoordinate(source, x, +args[index++]); if (args.size() > index) y = convertArgToCoordinate(source, y, +args[index++], 0, 0); if (args.size() > index) z = convertArgToCoordinate(source, z, args[index++]); - if (args.length > index) volume = convertArgToDouble(source, -args[index++], 0, Float.MAX_VALUE); if (args.length > index) pitch = -convertArgToDouble(source, args[index++], 0, 2); if (args.length > index) + if (args.size() > index) volume = convertArgToDouble(source, +args[index++], 0, Float.MAX_VALUE); if (args.size() > index) pitch = +convertArgToDouble(source, args[index++], 0, 2); if (args.size() > index) minVolume = convertArgToDouble(source, args[index++], 0, 1); double maxDist = volume > 1 ? volume * 16 : 16; diff --git a/minecraft/Minecraft.World/net/minecraft/commands/common/SetPlayerTimeoutCommand.h b/minecraft/Minecraft.World/net/minecraft/commands/common/SetPlayerTimeoutCommand.h index 11bf91033..c870267ec 100644 --- a/minecraft/Minecraft.World/net/minecraft/commands/common/SetPlayerTimeoutCommand.h +++ b/minecraft/Minecraft.World/net/minecraft/commands/common/SetPlayerTimeoutCommand.h @@ -23,7 +23,7 @@ public class SetPlayerTimeoutCommand extends BaseCommand { } public void execute(CommandSender source, String[] args) { - if (args.length == 1) { + if (args.size() == 1) { int timeout = convertArgToInt(source, args[0], 0); MinecraftServer.getInstance().setPlayerIdleTimeout(timeout); logAdminAction(source, "commands.setidletimeout.success", timeout); diff --git a/minecraft/Minecraft.World/net/minecraft/commands/common/SpreadPlayersCommand.h b/minecraft/Minecraft.World/net/minecraft/commands/common/SpreadPlayersCommand.h index b3d6e2888..2785e7dcc 100644 --- a/minecraft/Minecraft.World/net/minecraft/commands/common/SpreadPlayersCommand.h +++ b/minecraft/Minecraft.World/net/minecraft/commands/common/SpreadPlayersCommand.h @@ -39,7 +39,7 @@ public class SpreadPlayersCommand extends BaseCommand { @Override public void execute(CommandSender source, String[] args) { - if (args.length < 6) throw new + if (args.size() < 6) throw new UsageException("commands.spreadplayers.usage"); int index = 0; double x = convertArgToCoordinate(source, Double.NaN, args[index++]); double z = convertArgToCoordinate(source, Double.NaN, args[index++]); double minDist = @@ -49,13 +49,13 @@ convertArgToBoolean(source, args[index++]); List players = Lists.newArrayList(); - while (index < args.length) { + while (index < args.size()) { String arg = args[index++]; if (PlayerSelector.isPattern(arg)) { ServerPlayer[] result = PlayerSelector.getPlayers(source, arg); - if (result != null && result.length != 0) { + if (result != null && result.size() != 0) { Collections.addAll(players, result); } else { throw new PlayerNotFoundException(); @@ -97,8 +97,8 @@ maxX, maxZ, positions, respectTeams); double avgDistance = setPlayerPositions(players, level, positions, respectTeams); logAdminAction(source, "commands.spreadplayers.success." + (respectTeams -? "teams" : "players"), positions.length, center.x, center.z); if -(positions.length > 1) +? "teams" : "players"), positions.size(), center.x, center.z); if +(positions.size() > 1) source.sendMessage(ChatMessageComponent.forTranslation("commands.spreadplayers.info." + (respectTeams ? "teams" : "players"), String.format("%.2f", avgDistance), iterations)); @@ -126,12 +126,12 @@ positions, bool respectTeams) { bool hasCollisions = true; int iteration; for (iteration = 0; iteration < MAX_ITERATION_COUNT && hasCollisions; iteration++) { hasCollisions = false; minDistance = Float.MAX_VALUE; - for (int i = 0; i < positions.length; i++) { + for (int i = 0; i < positions.size(); i++) { Position position = positions[i]; int neighbourCount = 0; Position averageNeighbourPos = new Position(); - for (int j = 0; j < positions.length; j++) { + for (int j = 0; j < positions.size(); j++) { if (i == j) continue; Position neighbour = positions[j]; @@ -177,7 +177,7 @@ iteration++) { hasCollisions = false; minDistance = Float.MAX_VALUE; if (iteration >= MAX_ITERATION_COUNT) { throw new CommandException("commands.spreadplayers.failure." + -(respectTeams ? "teams" : "players"), positions.length, center.x, center.z, +(respectTeams ? "teams" : "players"), positions.size(), center.x, center.z, String.format("%.2f", minDistance)); } @@ -209,7 +209,7 @@ player).getTeam() : null; position.getSpawnY(level), Mth.floor(position.z) + 0.5); double closest = Double.MAX_VALUE; - for (int j = 0; j < positions.length; j++) { + for (int j = 0; j < positions.size(); j++) { if (position == positions[j]) continue; double dist = position.dist(positions[j]); @@ -226,7 +226,7 @@ position.getSpawnY(level), Mth.floor(position.z) + 0.5); minX, double minZ, double maxX, double maxZ) { Position[] result = new Position[count]; - for (int i = 0; i < result.length; i++) { + for (int i = 0; i < result.size(); i++) { Position position = new Position(); position.randomize(random, minX, minZ, maxX, maxZ); diff --git a/minecraft/Minecraft.World/net/minecraft/commands/common/TimeCommand.cpp b/minecraft/Minecraft.World/net/minecraft/commands/common/TimeCommand.cpp index adc76d7d3..149585431 100644 --- a/minecraft/Minecraft.World/net/minecraft/commands/common/TimeCommand.cpp +++ b/minecraft/Minecraft.World/net/minecraft/commands/common/TimeCommand.cpp @@ -10,7 +10,7 @@ EGameCommand TimeCommand::getId() { return eGameCommand_Time; } int TimeCommand::getPermissionLevel() { return LEVEL_GAMEMASTERS; } void TimeCommand::execute(std::shared_ptr source, - byteArray commandData) { + std::vector& commandData) { ByteArrayInputStream bais(commandData); DataInputStream dis(&bais); @@ -24,7 +24,7 @@ void TimeCommand::execute(std::shared_ptr source, // logAdminAction(source, "commands.time.set", amount); logAdminAction(source, ChatPacket::e_ChatCustom, L"commands.time.set"); - // if (args.length > 1) { + // if (args.size() > 1) { // if (args[0].equals("set")) { // int amount; @@ -52,13 +52,13 @@ void TimeCommand::execute(std::shared_ptr source, } void TimeCommand::doSetTime(std::shared_ptr source, int value) { - for (int i = 0; i < MinecraftServer::getInstance()->levels.length; i++) { + for (int i = 0; i < MinecraftServer::getInstance()->levels.size(); i++) { MinecraftServer::getInstance()->levels[i]->setDayTime(value); } } void TimeCommand::doAddTime(std::shared_ptr source, int value) { - for (int i = 0; i < MinecraftServer::getInstance()->levels.length; i++) { + for (int i = 0; i < MinecraftServer::getInstance()->levels.size(); i++) { ServerLevel* level = MinecraftServer::getInstance()->levels[i]; level->setDayTime(level->getDayTime() + value); } diff --git a/minecraft/Minecraft.World/net/minecraft/commands/common/TimeCommand.h b/minecraft/Minecraft.World/net/minecraft/commands/common/TimeCommand.h index 18db1ca21..ba382affc 100644 --- a/minecraft/Minecraft.World/net/minecraft/commands/common/TimeCommand.h +++ b/minecraft/Minecraft.World/net/minecraft/commands/common/TimeCommand.h @@ -7,7 +7,7 @@ public: virtual EGameCommand getId(); virtual int getPermissionLevel(); virtual void execute(std::shared_ptr source, - byteArray commandData); + std::vector& commandData); protected: void doSetTime(std::shared_ptr source, int value); diff --git a/minecraft/Minecraft.World/net/minecraft/commands/common/ToggleDownfallCommand.cpp b/minecraft/Minecraft.World/net/minecraft/commands/common/ToggleDownfallCommand.cpp index 65eaf9caf..0963cdf9c 100644 --- a/minecraft/Minecraft.World/net/minecraft/commands/common/ToggleDownfallCommand.cpp +++ b/minecraft/Minecraft.World/net/minecraft/commands/common/ToggleDownfallCommand.cpp @@ -14,7 +14,7 @@ EGameCommand ToggleDownfallCommand::getId() { int ToggleDownfallCommand::getPermissionLevel() { return LEVEL_GAMEMASTERS; } void ToggleDownfallCommand::execute(std::shared_ptr source, - byteArray commandData) { + std::vector& commandData) { doToggleDownfall(); logAdminAction(source, ChatPacket::e_ChatCustom, L"commands.downfall.success"); @@ -28,5 +28,5 @@ void ToggleDownfallCommand::doToggleDownfall() { std::shared_ptr ToggleDownfallCommand::preparePacket() { return std::shared_ptr( - new GameCommandPacket(eGameCommand_ToggleDownfall, byteArray())); + new GameCommandPacket(eGameCommand_ToggleDownfall, std::vector())); } \ No newline at end of file diff --git a/minecraft/Minecraft.World/net/minecraft/commands/common/ToggleDownfallCommand.h b/minecraft/Minecraft.World/net/minecraft/commands/common/ToggleDownfallCommand.h index 944fcc969..414f7920a 100644 --- a/minecraft/Minecraft.World/net/minecraft/commands/common/ToggleDownfallCommand.h +++ b/minecraft/Minecraft.World/net/minecraft/commands/common/ToggleDownfallCommand.h @@ -8,7 +8,7 @@ public: virtual EGameCommand getId(); virtual int getPermissionLevel(); virtual void execute(std::shared_ptr source, - byteArray commandData); + std::vector& commandData); protected: void doToggleDownfall(); diff --git a/minecraft/Minecraft.World/net/minecraft/commands/common/WeatherCommand.h b/minecraft/Minecraft.World/net/minecraft/commands/common/WeatherCommand.h index 353841095..2c19513e9 100644 --- a/minecraft/Minecraft.World/net/minecraft/commands/common/WeatherCommand.h +++ b/minecraft/Minecraft.World/net/minecraft/commands/common/WeatherCommand.h @@ -29,12 +29,12 @@ public class WeatherCommand extends BaseCommand { @Override public void execute(CommandSender source, String[] args) { - if (args.length < 1 || args.length > 2) { + if (args.size() < 1 || args.size() > 2) { throw new UsageException("commands.weather.usage"); } int duration = (300 + new Random().nextInt(600)) * -SharedConstants.TICKS_PER_SECOND; if (args.length >= 2) { duration = +SharedConstants.TICKS_PER_SECOND; if (args.size() >= 2) { duration = convertArgToInt(source, args[1], 1, 1000000) * SharedConstants.TICKS_PER_SECOND; } @@ -62,7 +62,7 @@ convertArgToInt(source, args[1], 1, 1000000) * SharedConstants.TICKS_PER_SECOND; @Override public List matchArguments(CommandSender source, String[] args) { - if (args.length == 1) { + if (args.size() == 1) { return matchArguments(args, "clear", "rain", "thunder"); } diff --git a/minecraft/Minecraft.World/net/minecraft/locale/Language.cpp b/minecraft/Minecraft.World/net/minecraft/locale/Language.cpp index bfdb7b81e..47d81ce59 100644 --- a/minecraft/Minecraft.World/net/minecraft/locale/Language.cpp +++ b/minecraft/Minecraft.World/net/minecraft/locale/Language.cpp @@ -25,10 +25,10 @@ Language::Language() { // InputStreamReader reader(stream); // BufferedReader bufferedReader(&reader); // std::wstring line; - byteArray buffer((unsigned int)fileSize); + std::vector buffer((unsigned int)fileSize); int bytesRead = stream->read(buffer, 0, (unsigned int)fileSize); if (bytesRead > 0) { - std::string content(reinterpret_cast(buffer.data), + std::string content(reinterpret_cast(buffer.data()), bytesRead); std::istringstream iss(content); std::string line; diff --git a/minecraft/Minecraft.World/net/minecraft/network/packet/AwardStatPacket.cpp b/minecraft/Minecraft.World/net/minecraft/network/packet/AwardStatPacket.cpp index e73aa9b47..75f964cbb 100644 --- a/minecraft/Minecraft.World/net/minecraft/network/packet/AwardStatPacket.cpp +++ b/minecraft/Minecraft.World/net/minecraft/network/packet/AwardStatPacket.cpp @@ -5,8 +5,7 @@ #include "AwardStatPacket.h" AwardStatPacket::AwardStatPacket() { - this->m_paramData.data = nullptr; - this->m_paramData.length = 0; + this->m_paramData.clear(); } AwardStatPacket::AwardStatPacket(int statId, int count) { @@ -17,26 +16,22 @@ AwardStatPacket::AwardStatPacket(int statId, int count) { // and memcpy of the integer into the array // reason: operator missmatch, array is deleted with delete[] // and typesafety - this->m_paramData.data = new uint8_t[sizeof(int)]; - memcpy(this->m_paramData.data, &count, sizeof(int)); - this->m_paramData.length = sizeof(int); + this->m_paramData.resize(sizeof(int)); + memcpy(this->m_paramData.data(), &count, sizeof(int)); } -AwardStatPacket::AwardStatPacket(int statId, byteArray paramData) { +AwardStatPacket::AwardStatPacket(int statId, std::vector& paramData) { this->statId = statId; this->m_paramData = paramData; } AwardStatPacket::~AwardStatPacket() { - if (m_paramData.data != nullptr) { - delete[] m_paramData.data; - m_paramData.data = nullptr; - } + m_paramData.clear(); } void AwardStatPacket::handle(PacketListener* listener) { listener->handleAwardStat(shared_from_this()); - m_paramData.data = nullptr; + m_paramData.clear(); } void AwardStatPacket::read(DataInputStream* dis) // throws IOException @@ -46,7 +41,7 @@ void AwardStatPacket::read(DataInputStream* dis) // throws IOException // Read parameter blob. int length = dis->readInt(); if (length > 0) { - m_paramData = byteArray(length); + m_paramData = std::vector(length); dis->readFully(m_paramData); } } @@ -54,8 +49,8 @@ void AwardStatPacket::read(DataInputStream* dis) // throws IOException void AwardStatPacket::write(DataOutputStream* dos) // throws IOException { dos->writeInt(statId); - dos->writeInt(m_paramData.length); - if (m_paramData.length > 0) dos->write(m_paramData); + dos->writeInt(m_paramData.size()); + if (m_paramData.size() > 0) dos->write(m_paramData); } int AwardStatPacket::getEstimatedSize() { return 6; } @@ -63,7 +58,7 @@ int AwardStatPacket::getEstimatedSize() { return 6; } bool AwardStatPacket::isAync() { return true; } // On most platforms we only store 'count' in an AwardStatPacket. -int AwardStatPacket::getCount() { return *((int*)this->m_paramData.data); } +int AwardStatPacket::getCount() { return *((int*)this->m_paramData.data()); } // On Durango we store 'Event' parameters here in a blob. -byteArray AwardStatPacket::getParamData() { return m_paramData; } +std::vector AwardStatPacket::getParamData() { return m_paramData; } diff --git a/minecraft/Minecraft.World/net/minecraft/network/packet/AwardStatPacket.h b/minecraft/Minecraft.World/net/minecraft/network/packet/AwardStatPacket.h index 9ed69e256..88f71045a 100644 --- a/minecraft/Minecraft.World/net/minecraft/network/packet/AwardStatPacket.h +++ b/minecraft/Minecraft.World/net/minecraft/network/packet/AwardStatPacket.h @@ -9,12 +9,12 @@ public: // 4J-JEV: Changed to allow for Durango events. protected: - byteArray m_paramData; + std::vector m_paramData; public: AwardStatPacket(); AwardStatPacket(int statId, int count); - AwardStatPacket(int statId, byteArray paramData); + AwardStatPacket(int statId, std::vector& paramData); ~AwardStatPacket(); virtual void handle(PacketListener* listener); @@ -31,5 +31,5 @@ public: public: // 4J-JEV: New getters to help prevent unsafe access int getCount(); - byteArray getParamData(); + std::vector getParamData(); }; diff --git a/minecraft/Minecraft.World/net/minecraft/network/packet/BlockRegionUpdatePacket.cpp b/minecraft/Minecraft.World/net/minecraft/network/packet/BlockRegionUpdatePacket.cpp index 20502df18..b7b1e2ff5 100644 --- a/minecraft/Minecraft.World/net/minecraft/network/packet/BlockRegionUpdatePacket.cpp +++ b/minecraft/Minecraft.World/net/minecraft/network/packet/BlockRegionUpdatePacket.cpp @@ -15,7 +15,7 @@ 0x02 // added so we can still send a byte for ys, which really needs the // range 0-256 -BlockRegionUpdatePacket::~BlockRegionUpdatePacket() { delete[] buffer.data; } +BlockRegionUpdatePacket::~BlockRegionUpdatePacket() {} BlockRegionUpdatePacket::BlockRegionUpdatePacket() { shouldDelay = true; @@ -46,7 +46,7 @@ BlockRegionUpdatePacket::BlockRegionUpdatePacket(int x, int y, int z, int xs, // compress better // TODO - we should be using compressed data directly here rather than // decompressing first and then recompressing... - byteArray rawBuffer; + std::vector rawBuffer; if (xs == 16 && ys == Level::maxBuildHeight && zs == 16 && ((x & 15) == 0) && (y == 0) && ((z & 15) == 0)) { @@ -61,9 +61,9 @@ BlockRegionUpdatePacket::BlockRegionUpdatePacket(int x, int y, int z, int xs, MemSect(0); } - if (rawBuffer.length == 0) { + if (rawBuffer.size() == 0) { size = 0; - buffer = byteArray(); + buffer = std::vector(); } else { // We don't know how this will compress - just make a fixed length // buffer to initially decompress into Some small sets of blocks can end @@ -72,14 +72,14 @@ BlockRegionUpdatePacket::BlockRegionUpdatePacket(int x, int y, int z, int xs, unsigned int inputSize = (256 * 16 * 16 * 5) / 2; Compression::getCompression()->CompressLZXRLE( - ucTemp, &inputSize, rawBuffer.data, (unsigned int)rawBuffer.length); + ucTemp, &inputSize, rawBuffer.data(), (unsigned int)rawBuffer.size()); // app.DebugPrintf("Chunk (%d,%d) compressed from %d to size %d\n", - // x>>4, z>>4, rawBuffer.length, inputSize); + // x>>4, z>>4, rawBuffer.size(), inputSize); unsigned char* ucTemp2 = new unsigned char[inputSize]; memcpy(ucTemp2, ucTemp, inputSize); delete[] ucTemp; - buffer = byteArray(ucTemp2, inputSize); - delete[] rawBuffer.data; + buffer = std::vector(ucTemp2, ucTemp2 + inputSize); + delete[] ucTemp2; size = inputSize; } } @@ -102,20 +102,20 @@ void BlockRegionUpdatePacket::read(DataInputStream* dis) // throws IOException size &= 0x3fffffff; if (size == 0) { - buffer = byteArray(); + buffer = std::vector(); } else { - byteArray compressedBuffer(size); + std::vector compressedBuffer(size); bool success = dis->readFully(compressedBuffer); int bufferSize = xs * ys * zs * 5 / 2; // Add the size of the biome data if it's a full chunk if (bIsFullChunk) bufferSize += (16 * 16); - buffer = byteArray(bufferSize); - unsigned int outputSize = buffer.length; + buffer = std::vector(bufferSize); + unsigned int outputSize = buffer.size(); if (success) { Compression::getCompression()->DecompressLZXRLE( - buffer.data, &outputSize, compressedBuffer.data, size); + buffer.data(), &outputSize, compressedBuffer.data(), size); } else { app.DebugPrintf( "Not decompressing packet that wasn't fully read\n"); @@ -124,8 +124,7 @@ void BlockRegionUpdatePacket::read(DataInputStream* dis) // throws IOException // printf("Block (%d %d %d), (%d %d %d) coming in decomp from %d to //%d\n",x,y,z,xs,ys,zs,size,outputSize); - delete[] compressedBuffer.data; - assert(buffer.length == outputSize); + assert(buffer.size() == outputSize); } } diff --git a/minecraft/Minecraft.World/net/minecraft/network/packet/BlockRegionUpdatePacket.h b/minecraft/Minecraft.World/net/minecraft/network/packet/BlockRegionUpdatePacket.h index 75ab4bd12..c4cf6d876 100644 --- a/minecraft/Minecraft.World/net/minecraft/network/packet/BlockRegionUpdatePacket.h +++ b/minecraft/Minecraft.World/net/minecraft/network/packet/BlockRegionUpdatePacket.h @@ -10,7 +10,7 @@ class BlockRegionUpdatePacket public: int x, y, z; int xs, ys, zs; - byteArray buffer; + std::vector buffer; int levelIdx; bool bIsFullChunk; // 4J Added diff --git a/minecraft/Minecraft.World/net/minecraft/network/packet/ChunkTilesUpdatePacket.cpp b/minecraft/Minecraft.World/net/minecraft/network/packet/ChunkTilesUpdatePacket.cpp index be66182fd..be319f9da 100644 --- a/minecraft/Minecraft.World/net/minecraft/network/packet/ChunkTilesUpdatePacket.cpp +++ b/minecraft/Minecraft.World/net/minecraft/network/packet/ChunkTilesUpdatePacket.cpp @@ -8,9 +8,6 @@ #include "../../world/level/dimension/Dimension.h" ChunkTilesUpdatePacket::~ChunkTilesUpdatePacket() { - delete[] blocks.data; - delete[] data.data; - delete[] positions.data; } ChunkTilesUpdatePacket::ChunkTilesUpdatePacket() { @@ -21,16 +18,16 @@ ChunkTilesUpdatePacket::ChunkTilesUpdatePacket() { } ChunkTilesUpdatePacket::ChunkTilesUpdatePacket(int xc, int zc, - shortArray positions, + std::vector& positions, uint8_t count, Level* level) { shouldDelay = true; this->xc = xc; this->zc = zc; this->count = count; - this->positions = shortArray((short int)count); + this->positions = std::vector((short int)count); - this->blocks = byteArray((unsigned int)count); - this->data = byteArray((unsigned int)count); + this->blocks = std::vector((unsigned int)count); + this->data = std::vector((unsigned int)count); LevelChunk* levelChunk = level->getChunk(xc, zc); for (int i = 0; (uint8_t)i < count; i++) { int x = (positions[i] >> 12) & 15; @@ -67,9 +64,9 @@ void ChunkTilesUpdatePacket::read(DataInputStream* dis) // throws IOException levelIdx = (countAndFlags >> 5) & 3; count = (uint8_t)countAndFlags & (uint8_t)0x1f; - positions = shortArray((short int)count); - blocks = byteArray((unsigned int)count); - data = byteArray((unsigned int)count); + positions = std::vector((short int)count); + blocks = std::vector((unsigned int)count); + data = std::vector((unsigned int)count); int currentBlockType = -1; for (int i = 0; (uint8_t)i < count; i++) { diff --git a/minecraft/Minecraft.World/net/minecraft/network/packet/ChunkTilesUpdatePacket.h b/minecraft/Minecraft.World/net/minecraft/network/packet/ChunkTilesUpdatePacket.h index 6ac842e1a..00a292313 100644 --- a/minecraft/Minecraft.World/net/minecraft/network/packet/ChunkTilesUpdatePacket.h +++ b/minecraft/Minecraft.World/net/minecraft/network/packet/ChunkTilesUpdatePacket.h @@ -9,15 +9,15 @@ class ChunkTilesUpdatePacket public std::enable_shared_from_this { public: int xc, zc; - shortArray positions; - byteArray blocks; - byteArray data; + std::vector positions; + std::vector blocks; + std::vector data; uint8_t count; // 4J Was int but never has a value higher than 10 int levelIdx; ChunkTilesUpdatePacket(); ~ChunkTilesUpdatePacket(); - ChunkTilesUpdatePacket(int xc, int zc, shortArray positions, uint8_t count, + ChunkTilesUpdatePacket(int xc, int zc, std::vector& positions, uint8_t count, Level* level); virtual void read(DataInputStream* dis); diff --git a/minecraft/Minecraft.World/net/minecraft/network/packet/ComplexItemDataPacket.cpp b/minecraft/Minecraft.World/net/minecraft/network/packet/ComplexItemDataPacket.cpp index 72800cff4..84fe4b78f 100644 --- a/minecraft/Minecraft.World/net/minecraft/network/packet/ComplexItemDataPacket.cpp +++ b/minecraft/Minecraft.World/net/minecraft/network/packet/ComplexItemDataPacket.cpp @@ -4,7 +4,8 @@ #include "PacketListener.h" #include "ComplexItemDataPacket.h" -ComplexItemDataPacket::~ComplexItemDataPacket() { delete[] data.data; } + +ComplexItemDataPacket::~ComplexItemDataPacket() {} ComplexItemDataPacket::ComplexItemDataPacket() { shouldDelay = true; @@ -12,14 +13,14 @@ ComplexItemDataPacket::ComplexItemDataPacket() { } ComplexItemDataPacket::ComplexItemDataPacket(short itemType, short itemId, - charArray data) { + std::vector& data) { shouldDelay = true; this->itemType = itemType; this->itemId = itemId; // Take copy of array passed in as we want the packets to have full // ownership of any data they reference - this->data = charArray(data.length); - memcpy(this->data.data, data.data, data.length); + this->data = std::vector(data.size()); + memcpy(this->data.data(), data.data(), data.size()); } void ComplexItemDataPacket::read(DataInputStream* dis) // throws IOException @@ -27,7 +28,7 @@ void ComplexItemDataPacket::read(DataInputStream* dis) // throws IOException itemType = dis->readShort(); itemId = dis->readShort(); - data = charArray(dis->readUnsignedShort() & 0xffff); + data = std::vector(dis->readUnsignedShort() & 0xffff); dis->readFully(data); } @@ -35,9 +36,9 @@ void ComplexItemDataPacket::write(DataOutputStream* dos) // throws IOException { dos->writeShort(itemType); dos->writeShort(itemId); - dos->writeUnsignedShort(data.length); + dos->writeUnsignedShort(data.size()); - byteArray ba((uint8_t*)data.data, data.length); + std::vector ba((uint8_t*)data.data(), (uint8_t*)data.data() + data.size()); dos->write(ba); } @@ -46,5 +47,5 @@ void ComplexItemDataPacket::handle(PacketListener* listener) { } int ComplexItemDataPacket::getEstimatedSize() { - return 2 + 2 + 2 + data.length; + return 2 + 2 + 2 + data.size(); } diff --git a/minecraft/Minecraft.World/net/minecraft/network/packet/ComplexItemDataPacket.h b/minecraft/Minecraft.World/net/minecraft/network/packet/ComplexItemDataPacket.h index 9f51b1c2a..8fc8cbbe3 100644 --- a/minecraft/Minecraft.World/net/minecraft/network/packet/ComplexItemDataPacket.h +++ b/minecraft/Minecraft.World/net/minecraft/network/packet/ComplexItemDataPacket.h @@ -8,11 +8,11 @@ class ComplexItemDataPacket public: short itemType; short itemId; - charArray data; + std::vector data; ComplexItemDataPacket(); ~ComplexItemDataPacket(); - ComplexItemDataPacket(short itemType, short itemId, charArray data); + ComplexItemDataPacket(short itemType, short itemId, std::vector& data); virtual void read(DataInputStream* dis); virtual void write(DataOutputStream* dos); diff --git a/minecraft/Minecraft.World/net/minecraft/network/packet/ContainerSetContentPacket.cpp b/minecraft/Minecraft.World/net/minecraft/network/packet/ContainerSetContentPacket.cpp index 294cd599c..63d07c7f1 100644 --- a/minecraft/Minecraft.World/net/minecraft/network/packet/ContainerSetContentPacket.cpp +++ b/minecraft/Minecraft.World/net/minecraft/network/packet/ContainerSetContentPacket.cpp @@ -5,15 +5,15 @@ #include "PacketListener.h" #include "ContainerSetContentPacket.h" -ContainerSetContentPacket::~ContainerSetContentPacket() { delete[] items.data; } +ContainerSetContentPacket::~ContainerSetContentPacket() {} ContainerSetContentPacket::ContainerSetContentPacket() { containerId = 0; } ContainerSetContentPacket::ContainerSetContentPacket( int containerId, std::vector >* newItems) { this->containerId = containerId; - items = arrayWithLength>((int)newItems->size()); - for (unsigned int i = 0; i < items.length; i++) { + items = std::vector>((int)newItems->size()); + for (unsigned int i = 0; i < items.size(); i++) { std::shared_ptr item = newItems->at(i); items[i] = item == nullptr ? nullptr : item->copy(); } @@ -24,7 +24,7 @@ void ContainerSetContentPacket::read( { containerId = (int)dis->readByte(); int count = dis->readShort(); - items = arrayWithLength>(count); + items = std::vector>(count); for (int i = 0; i < count; i++) { items[i] = readItem(dis); } @@ -34,8 +34,8 @@ void ContainerSetContentPacket::write( DataOutputStream* dos) // throws IOException { dos->writeByte((uint8_t)containerId); - dos->writeShort(items.length); - for (unsigned int i = 0; i < items.length; i++) { + dos->writeShort(items.size()); + for (unsigned int i = 0; i < items.size(); i++) { writeItem(items[i], dos); } } @@ -45,5 +45,5 @@ void ContainerSetContentPacket::handle(PacketListener* listener) { } int ContainerSetContentPacket::getEstimatedSize() { - return 3 + items.length * 5; + return 3 + items.size() * 5; } diff --git a/minecraft/Minecraft.World/net/minecraft/network/packet/ContainerSetContentPacket.h b/minecraft/Minecraft.World/net/minecraft/network/packet/ContainerSetContentPacket.h index 4ab0cb258..6a45a8ced 100644 --- a/minecraft/Minecraft.World/net/minecraft/network/packet/ContainerSetContentPacket.h +++ b/minecraft/Minecraft.World/net/minecraft/network/packet/ContainerSetContentPacket.h @@ -7,7 +7,7 @@ class ContainerSetContentPacket public std::enable_shared_from_this { public: int containerId; - arrayWithLength> items; + std::vector> items; ContainerSetContentPacket(); ~ContainerSetContentPacket(); diff --git a/minecraft/Minecraft.World/net/minecraft/network/packet/CustomPayloadPacket.cpp b/minecraft/Minecraft.World/net/minecraft/network/packet/CustomPayloadPacket.cpp index 2ed958ceb..ddeea10cc 100644 --- a/minecraft/Minecraft.World/net/minecraft/network/packet/CustomPayloadPacket.cpp +++ b/minecraft/Minecraft.World/net/minecraft/network/packet/CustomPayloadPacket.cpp @@ -18,12 +18,12 @@ const std::wstring CustomPayloadPacket::SET_ITEM_NAME_PACKET = L"MC|ItemName"; CustomPayloadPacket::CustomPayloadPacket() {} CustomPayloadPacket::CustomPayloadPacket(const std::wstring& identifier, - byteArray data) { + std::vector data) { this->identifier = identifier; this->data = data; - if (data.data != nullptr) { - length = data.length; + if (!data.empty()) { + length = data.size(); if (length > std::numeric_limits::max()) { app.DebugPrintf("Payload may not be larger than 32K\n"); @@ -41,10 +41,7 @@ void CustomPayloadPacket::read(DataInputStream* dis) { length = dis->readShort(); if (length > 0 && length < std::numeric_limits::max()) { - if (data.data != nullptr) { - delete[] data.data; - } - data = byteArray(length); + data = std::vector(length); dis->readFully(data); } } @@ -52,7 +49,7 @@ void CustomPayloadPacket::read(DataInputStream* dis) { void CustomPayloadPacket::write(DataOutputStream* dos) { writeUtf(identifier, dos); dos->writeShort((short)length); - if (data.data != nullptr) { + if (!data.empty()) { dos->write(data); } } diff --git a/minecraft/Minecraft.World/net/minecraft/network/packet/CustomPayloadPacket.h b/minecraft/Minecraft.World/net/minecraft/network/packet/CustomPayloadPacket.h index cf4fa2946..bdc8972ad 100644 --- a/minecraft/Minecraft.World/net/minecraft/network/packet/CustomPayloadPacket.h +++ b/minecraft/Minecraft.World/net/minecraft/network/packet/CustomPayloadPacket.h @@ -18,10 +18,10 @@ public: std::wstring identifier; int length; - byteArray data; + std::vector data; CustomPayloadPacket(); - CustomPayloadPacket(const std::wstring& identifier, byteArray data); + CustomPayloadPacket(const std::wstring& identifier, std::vector data); virtual void read(DataInputStream* dis); virtual void write(DataOutputStream* dos); diff --git a/minecraft/Minecraft.World/net/minecraft/network/packet/GameCommandPacket.cpp b/minecraft/Minecraft.World/net/minecraft/network/packet/GameCommandPacket.cpp index e3e428ec2..81b1901e3 100644 --- a/minecraft/Minecraft.World/net/minecraft/network/packet/GameCommandPacket.cpp +++ b/minecraft/Minecraft.World/net/minecraft/network/packet/GameCommandPacket.cpp @@ -6,13 +6,15 @@ GameCommandPacket::GameCommandPacket() { length = 0; } -GameCommandPacket::GameCommandPacket(EGameCommand command, byteArray data) { +GameCommandPacket::~GameCommandPacket() {} + +GameCommandPacket::GameCommandPacket(EGameCommand command, std::vector data) { this->command = command; this->data = data; length = 0; - if (data.data != nullptr) { - length = data.length; + if (!data.empty()) { + length = data.size(); if (length > std::numeric_limits::max()) { app.DebugPrintf("Payload may not be larger than 32K\n"); @@ -25,17 +27,13 @@ GameCommandPacket::GameCommandPacket(EGameCommand command, byteArray data) { } } -GameCommandPacket::~GameCommandPacket() { delete[] data.data; } void GameCommandPacket::read(DataInputStream* dis) { command = (EGameCommand)dis->readInt(); length = dis->readShort(); if (length > 0 && length < std::numeric_limits::max()) { - if (data.data != nullptr) { - delete[] data.data; - } - data = byteArray(length); + data = std::vector(length); dis->readFully(data); } } @@ -43,7 +41,7 @@ void GameCommandPacket::read(DataInputStream* dis) { void GameCommandPacket::write(DataOutputStream* dos) { dos->writeInt(command); dos->writeShort((short)length); - if (data.data != nullptr) { + if (!data.empty()) { dos->write(data); } } diff --git a/minecraft/Minecraft.World/net/minecraft/network/packet/GameCommandPacket.h b/minecraft/Minecraft.World/net/minecraft/network/packet/GameCommandPacket.h index 453d61fca..50d4f6f23 100644 --- a/minecraft/Minecraft.World/net/minecraft/network/packet/GameCommandPacket.h +++ b/minecraft/Minecraft.World/net/minecraft/network/packet/GameCommandPacket.h @@ -9,10 +9,10 @@ class GameCommandPacket public: EGameCommand command; int length; - byteArray data; + std::vector data; GameCommandPacket(); - GameCommandPacket(EGameCommand command, byteArray data); + GameCommandPacket(EGameCommand command, std::vector data); ~GameCommandPacket(); virtual void read(DataInputStream* dis); diff --git a/minecraft/Minecraft.World/net/minecraft/network/packet/Packet.cpp b/minecraft/Minecraft.World/net/minecraft/network/packet/Packet.cpp index 8d8b14131..1859c4e87 100644 --- a/minecraft/Minecraft.World/net/minecraft/network/packet/Packet.cpp +++ b/minecraft/Minecraft.World/net/minecraft/network/packet/Packet.cpp @@ -357,23 +357,23 @@ std::shared_ptr Packet::getPacket(int id) { return idToCreateMap[id](); } -void Packet::writeBytes(DataOutputStream* dataoutputstream, byteArray bytes) { - dataoutputstream->writeShort(bytes.length); +void Packet::writeBytes(DataOutputStream* dataoutputstream, const std::vector& bytes) { + dataoutputstream->writeShort(bytes.size()); dataoutputstream->write(bytes); } -byteArray Packet::readBytes(DataInputStream* datainputstream) { +std::vector Packet::readBytes(DataInputStream* datainputstream) { int size = datainputstream->readShort(); if (size < 0) { app.DebugPrintf("Key was smaller than nothing! Weird key!"); #if !defined(_CONTENT_PACKAGE) __debugbreak(); #endif - return byteArray(); + return std::vector(); // throw new IOException("Key was smaller than nothing! Weird key!"); } - byteArray bytes(size); + std::vector bytes(size); datainputstream->readFully(bytes); return bytes; @@ -604,10 +604,9 @@ void Packet::writeItem(std::shared_ptr item, CompoundTag* Packet::readNbt(DataInputStream* dis) { int size = dis->readShort(); if (size < 0) return nullptr; - byteArray buff(size); + std::vector buff(size); dis->readFully(buff); CompoundTag* result = (CompoundTag*)NbtIo::decompress(buff); - delete[] buff.data; return result; } @@ -615,9 +614,8 @@ void Packet::writeNbt(CompoundTag* tag, DataOutputStream* dos) { if (tag == nullptr) { dos->writeShort(-1); } else { - byteArray buff = NbtIo::compress(tag); - dos->writeShort((short)buff.length); + std::vector buff = NbtIo::compress(tag); + dos->writeShort((short)buff.size()); dos->write(buff); - delete[] buff.data; } } diff --git a/minecraft/Minecraft.World/net/minecraft/network/packet/Packet.h b/minecraft/Minecraft.World/net/minecraft/network/packet/Packet.h index f84357d98..10d05b520 100644 --- a/minecraft/Minecraft.World/net/minecraft/network/packet/Packet.h +++ b/minecraft/Minecraft.World/net/minecraft/network/packet/Packet.h @@ -72,8 +72,8 @@ public: // 4J Added static bool canSendToAnyClient(std::shared_ptr packet); - static void writeBytes(DataOutputStream* dataoutputstream, byteArray bytes); - static byteArray readBytes(DataInputStream* datainputstream); + static void writeBytes(DataOutputStream* dataoutputstream, const std::vector& bytes); + static std::vector readBytes(DataInputStream* datainputstream); virtual int getId() = 0; diff --git a/minecraft/Minecraft.World/net/minecraft/network/packet/RemoveEntitiesPacket.cpp b/minecraft/Minecraft.World/net/minecraft/network/packet/RemoveEntitiesPacket.cpp index 73277fdb6..d1e642ec3 100644 --- a/minecraft/Minecraft.World/net/minecraft/network/packet/RemoveEntitiesPacket.cpp +++ b/minecraft/Minecraft.World/net/minecraft/network/packet/RemoveEntitiesPacket.cpp @@ -7,24 +7,23 @@ RemoveEntitiesPacket::RemoveEntitiesPacket() {} -RemoveEntitiesPacket::RemoveEntitiesPacket(intArray ids) { this->ids = ids; } +RemoveEntitiesPacket::RemoveEntitiesPacket(std::vector& ids) { this->ids = ids; } RemoveEntitiesPacket::~RemoveEntitiesPacket() { - delete[] ids.data; // 4jcraft, changed to [] } void RemoveEntitiesPacket::read(DataInputStream* dis) // throws IOException { - ids = intArray(dis->readByte()); - for (unsigned int i = 0; i < ids.length; ++i) { + ids = std::vector(dis->readByte()); + for (unsigned int i = 0; i < ids.size(); ++i) { ids[i] = dis->readInt(); } } void RemoveEntitiesPacket::write(DataOutputStream* dos) // throws IOException { - dos->writeByte(ids.length); - for (unsigned int i = 0; i < ids.length; ++i) { + dos->writeByte(ids.size()); + for (unsigned int i = 0; i < ids.size(); ++i) { dos->writeInt(ids[i]); } } @@ -33,7 +32,7 @@ void RemoveEntitiesPacket::handle(PacketListener* listener) { listener->handleRemoveEntity(shared_from_this()); } -int RemoveEntitiesPacket::getEstimatedSize() { return 1 + (ids.length * 4); } +int RemoveEntitiesPacket::getEstimatedSize() { return 1 + (ids.size() * 4); } /* 4J: These are necesary on the PS3. diff --git a/minecraft/Minecraft.World/net/minecraft/network/packet/RemoveEntitiesPacket.h b/minecraft/Minecraft.World/net/minecraft/network/packet/RemoveEntitiesPacket.h index eb95a9115..ae1294f83 100644 --- a/minecraft/Minecraft.World/net/minecraft/network/packet/RemoveEntitiesPacket.h +++ b/minecraft/Minecraft.World/net/minecraft/network/packet/RemoveEntitiesPacket.h @@ -9,10 +9,10 @@ class RemoveEntitiesPacket public: static const int MAX_PER_PACKET = std::numeric_limits::max(); - intArray ids; + std::vector ids; RemoveEntitiesPacket(); - RemoveEntitiesPacket(intArray ids); + RemoveEntitiesPacket(std::vector& ids); ~RemoveEntitiesPacket(); virtual void read(DataInputStream* dis); diff --git a/minecraft/Minecraft.World/net/minecraft/network/packet/UpdateGameRuleProgressPacket.cpp b/minecraft/Minecraft.World/net/minecraft/network/packet/UpdateGameRuleProgressPacket.cpp index 59d8018d1..b56f7f0c4 100644 --- a/minecraft/Minecraft.World/net/minecraft/network/packet/UpdateGameRuleProgressPacket.cpp +++ b/minecraft/Minecraft.World/net/minecraft/network/packet/UpdateGameRuleProgressPacket.cpp @@ -22,10 +22,10 @@ UpdateGameRuleProgressPacket::UpdateGameRuleProgressPacket( m_dataTag = dataTag; if (dataLength > 0) { - m_data = byteArray(dataLength); - memcpy(m_data.data, data, dataLength); + m_data = std::vector(dataLength); + memcpy(m_data.data(), data, dataLength); } else { - m_data = byteArray(); + m_data = std::vector(); } } @@ -40,10 +40,10 @@ void UpdateGameRuleProgressPacket::read( int dataLength = dis->readInt(); if (dataLength > 0) { - m_data = byteArray(dataLength); + m_data = std::vector(dataLength); dis->readFully(m_data); } else { - m_data = byteArray(); + m_data = std::vector(); } } @@ -55,7 +55,7 @@ void UpdateGameRuleProgressPacket::write( dos->writeInt(m_icon); dos->writeByte(m_auxValue); dos->writeInt(m_dataTag); - dos->writeInt(m_data.length); + dos->writeInt(m_data.size()); dos->write(m_data); } @@ -64,5 +64,5 @@ void UpdateGameRuleProgressPacket::handle(PacketListener* listener) { } int UpdateGameRuleProgressPacket::getEstimatedSize() { - return (int)m_messageId.length() + 4 + m_data.length; + return (int)m_messageId.length() + 4 + m_data.size(); } \ No newline at end of file diff --git a/minecraft/Minecraft.World/net/minecraft/network/packet/UpdateGameRuleProgressPacket.h b/minecraft/Minecraft.World/net/minecraft/network/packet/UpdateGameRuleProgressPacket.h index 3975037d2..f53bf852e 100644 --- a/minecraft/Minecraft.World/net/minecraft/network/packet/UpdateGameRuleProgressPacket.h +++ b/minecraft/Minecraft.World/net/minecraft/network/packet/UpdateGameRuleProgressPacket.h @@ -10,7 +10,7 @@ public: std::wstring m_messageId; int m_icon, m_auxValue; int m_dataTag; - byteArray m_data; + std::vector m_data; UpdateGameRuleProgressPacket(); UpdateGameRuleProgressPacket(ConsoleGameRules::EGameRuleType definitionType, diff --git a/minecraft/Minecraft.World/net/minecraft/stats/CommonStats.cpp b/minecraft/Minecraft.World/net/minecraft/stats/CommonStats.cpp index 9499ba0ad..eacdeb544 100644 --- a/minecraft/Minecraft.World/net/minecraft/stats/CommonStats.cpp +++ b/minecraft/Minecraft.World/net/minecraft/stats/CommonStats.cpp @@ -97,7 +97,7 @@ Stat* CommonStats::get_blocksMined(int blockId) { Stat* CommonStats::get_itemsCollected(int itemId, int itemAux) { // 4J-JEV: We don't need itemsCollected(emerald) so I'm using it to // stor itemsBought(emerald) so I don't have to make yet another massive - // StatArray for Items Bought. + // std::vector& for Items Bought. #if defined(_EXTENDED_ACHIEVEMENTS) if (itemId == Tile::wool_Id) return Stats::rainbowCollection[itemAux]; #endif @@ -128,7 +128,7 @@ Stat* CommonStats::get_itemsUsed(int itemId) { Stat* CommonStats::get_itemsBought(int itemId) { // 4J-JEV: We don't need itemsCollected(emerald) so I'm using it to // stor itemsBought(emerald) so I don't have to make yet another massive - // StatArray for Items Bought. + // std::vector& for Items Bought. if (itemId == Item::emerald_Id) return Stats::itemsCollected[itemId]; @@ -272,73 +272,73 @@ Stat* CommonStats::get_achievement(eAward achievementId) { } } -byteArray CommonStats::getParam_walkOneM(int distance) { +std::vector CommonStats::getParam_walkOneM(int distance) { return makeParam(distance); } -byteArray CommonStats::getParam_swimOneM(int distance) { +std::vector CommonStats::getParam_swimOneM(int distance) { return makeParam(distance); } -byteArray CommonStats::getParam_fallOneM(int distance) { +std::vector CommonStats::getParam_fallOneM(int distance) { return makeParam(distance); } -byteArray CommonStats::getParam_climbOneM(int distance) { +std::vector CommonStats::getParam_climbOneM(int distance) { return makeParam(distance); } -byteArray CommonStats::getParam_minecartOneM(int distance) { +std::vector CommonStats::getParam_minecartOneM(int distance) { return makeParam(distance); } -byteArray CommonStats::getParam_boatOneM(int distance) { +std::vector CommonStats::getParam_boatOneM(int distance) { return makeParam(distance); } -byteArray CommonStats::getParam_pigOneM(int distance) { +std::vector CommonStats::getParam_pigOneM(int distance) { return makeParam(distance); } -byteArray CommonStats::getParam_blocksMined(int id, int data, int count) { +std::vector CommonStats::getParam_blocksMined(int id, int data, int count) { return makeParam(count); } -byteArray CommonStats::getParam_itemsCollected(int id, int aux, int count) { +std::vector CommonStats::getParam_itemsCollected(int id, int aux, int count) { return makeParam(count); } -byteArray CommonStats::getParam_itemsCrafted(int id, int aux, int count) { +std::vector CommonStats::getParam_itemsCrafted(int id, int aux, int count) { return makeParam(count); } -byteArray CommonStats::getParam_itemsSmelted(int id, int aux, int count) { +std::vector CommonStats::getParam_itemsSmelted(int id, int aux, int count) { return makeParam(count); } -byteArray CommonStats::getParam_itemsUsed(int id, int aux, int count) { +std::vector CommonStats::getParam_itemsUsed(int id, int aux, int count) { return makeParam(count); } -byteArray CommonStats::getParam_itemsBought(int id, int aux, int count) { +std::vector CommonStats::getParam_itemsBought(int id, int aux, int count) { return makeParam(count); } -byteArray CommonStats::getParam_time(int timediff) { +std::vector CommonStats::getParam_time(int timediff) { return makeParam(timediff); } -byteArray CommonStats::getParam_noArgs() { return makeParam(); } +std::vector CommonStats::getParam_noArgs() { return makeParam(); } -byteArray CommonStats::makeParam(int count) { - byteArray out(sizeof(int)); - memcpy(out.data, &count, sizeof(int)); +std::vector CommonStats::makeParam(int count) { + std::vector out(sizeof(int)); + memcpy(out.data(), &count, sizeof(int)); return out; } -int CommonStats::readParam(byteArray paramBlob) { - if (paramBlob.length == sizeof(int)) - return *((int*)paramBlob.data); +int CommonStats::readParam(const std::vector& paramBlob) { + if (paramBlob.size() == sizeof(int)) + return *((int*)paramBlob.data()); else return 1; } \ No newline at end of file diff --git a/minecraft/Minecraft.World/net/minecraft/stats/CommonStats.h b/minecraft/Minecraft.World/net/minecraft/stats/CommonStats.h index 931b53cd4..685ff1a96 100644 --- a/minecraft/Minecraft.World/net/minecraft/stats/CommonStats.h +++ b/minecraft/Minecraft.World/net/minecraft/stats/CommonStats.h @@ -52,28 +52,28 @@ protected: virtual Stat* get_achievement(eAward achievementId); - virtual byteArray getParam_walkOneM(int distance); - virtual byteArray getParam_swimOneM(int distance); - virtual byteArray getParam_fallOneM(int distance); - virtual byteArray getParam_climbOneM(int distance); - virtual byteArray getParam_minecartOneM(int distance); - virtual byteArray getParam_boatOneM(int distance); - virtual byteArray getParam_pigOneM(int distance); + virtual std::vector getParam_walkOneM(int distance); + virtual std::vector getParam_swimOneM(int distance); + virtual std::vector getParam_fallOneM(int distance); + virtual std::vector getParam_climbOneM(int distance); + virtual std::vector getParam_minecartOneM(int distance); + virtual std::vector getParam_boatOneM(int distance); + virtual std::vector getParam_pigOneM(int distance); - virtual byteArray getParam_blocksMined(int id, int data, int count); - virtual byteArray getParam_itemsCollected(int id, int aux, int count); - virtual byteArray getParam_itemsCrafted(int id, int aux, int count); - virtual byteArray getParam_itemsSmelted(int id, int aux, int count); - virtual byteArray getParam_itemsUsed(int id, int aux, int count); - virtual byteArray getParam_itemsBought(int id, int aux, int count); + virtual std::vector getParam_blocksMined(int id, int data, int count); + virtual std::vector getParam_itemsCollected(int id, int aux, int count); + virtual std::vector getParam_itemsCrafted(int id, int aux, int count); + virtual std::vector getParam_itemsSmelted(int id, int aux, int count); + virtual std::vector getParam_itemsUsed(int id, int aux, int count); + virtual std::vector getParam_itemsBought(int id, int aux, int count); - virtual byteArray getParam_time(int timediff); + virtual std::vector getParam_time(int timediff); - virtual byteArray getParam_noArgs(); + virtual std::vector getParam_noArgs(); protected: - static byteArray makeParam(int count = 1); + static std::vector makeParam(int count = 1); public: - static int readParam(byteArray paramBlob); + static int readParam(const std::vector& paramBlob); }; \ No newline at end of file diff --git a/minecraft/Minecraft.World/net/minecraft/stats/DurangoStats.h b/minecraft/Minecraft.World/net/minecraft/stats/DurangoStats.h index 7e4df31d2..3cc42142d 100644 --- a/minecraft/Minecraft.World/net/minecraft/stats/DurangoStats.h +++ b/minecraft/Minecraft.World/net/minecraft/stats/DurangoStats.h @@ -42,8 +42,8 @@ public: int mergeIds(int itemId); virtual void handleParamBlob(std::shared_ptr plr, - byteArray param); - static byteArray createParamBlob(eAcquisitionMethod methodId, int itemId, + std::vector& param); + static std::vector createParamBlob(eAcquisitionMethod methodId, int itemId, int itemAux, int itemCount); }; @@ -61,8 +61,8 @@ public: int mobType, weaponId, distance, damage; } Param; virtual void handleParamBlob(std::shared_ptr plr, - byteArray param); - static byteArray createParamBlob(std::shared_ptr plr, + std::vector& param); + static std::vector createParamBlob(std::shared_ptr plr, std::shared_ptr mob, DamageSource* dmgSrc); }; @@ -87,8 +87,8 @@ public: int interactionType, mobId; } Param; virtual void handleParamBlob(std::shared_ptr plr, - byteArray param); - static byteArray createParamBlob(eInteract interactionId, int entityId); + std::vector& param); + static std::vector createParamBlob(eInteract interactionId, int entityId); }; class DsTravel : public Stat { @@ -118,8 +118,8 @@ public: int distance; } Param; virtual void handleParamBlob(std::shared_ptr plr, - byteArray paramBlob); - static byteArray createParamBlob(eMethod method, int distance); + std::vector& paramBlob); + static std::vector createParamBlob(eMethod method, int distance); void flush(std::shared_ptr plr); @@ -136,8 +136,8 @@ public: int itemId, aux, count, health, hunger; } Param; virtual void handleParamBlob(std::shared_ptr plr, - byteArray paramBlob); - static byteArray createParamBlob(int itemId, int aux, int count, int health, + std::vector& paramBlob); + static std::vector createParamBlob(int itemId, int aux, int count, int health, int hunger); }; @@ -146,18 +146,18 @@ public: DsAchievement(int id, const std::wstring& name); virtual void handleParamBlob(std::shared_ptr plr, - byteArray paramBlob); + std::vector& paramBlob); typedef struct { eAward award; } SmallParam; - static byteArray createSmallParamBlob(eAward id); + static std::vector createSmallParamBlob(eAward id); typedef struct { eAward award; int count; } LargeParam; - static byteArray createLargeParamBlob(eAward id, int count); + static std::vector createLargeParamBlob(eAward id, int count); }; class DsChangedDimension : public Stat { @@ -167,8 +167,8 @@ public: int fromDimId, toDimId; } Param; virtual void handleParamBlob(std::shared_ptr plr, - byteArray paramBlob); - static byteArray createParamBlob(int fromDimId, int toDimId); + std::vector& paramBlob); + static std::vector createParamBlob(int fromDimId, int toDimId); }; class DsEnteredBiome : public Stat { @@ -178,8 +178,8 @@ public: int biomeId; } Param; virtual void handleParamBlob(std::shared_ptr plr, - byteArray paramBlob); - static byteArray createParamBlob(int biomeId); + std::vector& paramBlob); + static std::vector createParamBlob(int biomeId); }; class DurangoStats : public GenericStats { @@ -266,46 +266,46 @@ protected: // Parameters - virtual byteArray getParam_walkOneM(int distance); - virtual byteArray getParam_swimOneM(int distance); - virtual byteArray getParam_fallOneM(int distance); - virtual byteArray getParam_climbOneM(int distance); - virtual byteArray getParam_minecartOneM(int distance); - virtual byteArray getParam_boatOneM(int distance); - virtual byteArray getParam_pigOneM(int distance); + virtual std::vector getParam_walkOneM(int distance); + virtual std::vector getParam_swimOneM(int distance); + virtual std::vector getParam_fallOneM(int distance); + virtual std::vector getParam_climbOneM(int distance); + virtual std::vector getParam_minecartOneM(int distance); + virtual std::vector getParam_boatOneM(int distance); + virtual std::vector getParam_pigOneM(int distance); - virtual byteArray getParam_cowsMilked(); + virtual std::vector getParam_cowsMilked(); - virtual byteArray getParam_blocksPlaced(int blockId, int data, int count); - virtual byteArray getParam_blocksMined(int blockId, int data, int count); - virtual byteArray getParam_itemsCollected(int id, int aux, int count); - virtual byteArray getParam_itemsCrafted(int id, int aux, int count); - virtual byteArray getParam_itemsUsed(std::shared_ptr plr, + virtual std::vector getParam_blocksPlaced(int blockId, int data, int count); + virtual std::vector getParam_blocksMined(int blockId, int data, int count); + virtual std::vector getParam_itemsCollected(int id, int aux, int count); + virtual std::vector getParam_itemsCrafted(int id, int aux, int count); + virtual std::vector getParam_itemsUsed(std::shared_ptr plr, std::shared_ptr itm); - virtual byteArray getParam_itemsBought(int id, int aux, int count); + virtual std::vector getParam_itemsBought(int id, int aux, int count); - virtual byteArray getParam_mobKill(std::shared_ptr plr, + virtual std::vector getParam_mobKill(std::shared_ptr plr, std::shared_ptr mob, DamageSource* dmgSrc); - virtual byteArray getParam_breedEntity(eINSTANCEOF entityId); - virtual byteArray getParam_tamedEntity(eINSTANCEOF entityId); - virtual byteArray getParam_curedEntity(eINSTANCEOF entityId); - virtual byteArray getParam_craftedEntity(eINSTANCEOF entityId); - virtual byteArray getParam_shearedEntity(eINSTANCEOF entityId); + virtual std::vector getParam_breedEntity(eINSTANCEOF entityId); + virtual std::vector getParam_tamedEntity(eINSTANCEOF entityId); + virtual std::vector getParam_curedEntity(eINSTANCEOF entityId); + virtual std::vector getParam_craftedEntity(eINSTANCEOF entityId); + virtual std::vector getParam_shearedEntity(eINSTANCEOF entityId); - virtual byteArray getParam_time(int timediff); + virtual std::vector getParam_time(int timediff); - virtual byteArray getParam_changedDimension(int from, int to); - virtual byteArray getParam_enteredBiome(int biomeId); + virtual std::vector getParam_changedDimension(int from, int to); + virtual std::vector getParam_enteredBiome(int biomeId); - virtual byteArray getParam_achievement(eAward id); + virtual std::vector getParam_achievement(eAward id); - virtual byteArray getParam_onARail(int dist); - virtual byteArray getParam_chestfulOfCobblestone(int count); - // virtual byteArray getParam_openInventory( - virtual byteArray getParam_overkill(int dmg); - virtual byteArray getParam_musicToMyEars(int recordId); + virtual std::vector getParam_onARail(int dist); + virtual std::vector getParam_chestfulOfCobblestone(int count); + // virtual std::vector getParam_openInventory( + virtual std::vector getParam_overkill(int dmg); + virtual std::vector getParam_musicToMyEars(int recordId); // Helpers diff --git a/minecraft/Minecraft.World/net/minecraft/stats/GenericStats.cpp b/minecraft/Minecraft.World/net/minecraft/stats/GenericStats.cpp index 1c4607499..02d912c67 100644 --- a/minecraft/Minecraft.World/net/minecraft/stats/GenericStats.cpp +++ b/minecraft/Minecraft.World/net/minecraft/stats/GenericStats.cpp @@ -398,120 +398,120 @@ Stat* GenericStats::lionTamer() { #endif } -byteArray GenericStats::getParam_walkOneM(int distance) { +std::vector GenericStats::getParam_walkOneM(int distance) { return getParam_noArgs(); // Really just a count on most platforms. } -byteArray GenericStats::getParam_swimOneM(int distance) { +std::vector GenericStats::getParam_swimOneM(int distance) { return getParam_noArgs(); // Really just a count on most platforms. } -byteArray GenericStats::getParam_fallOneM(int distance) { +std::vector GenericStats::getParam_fallOneM(int distance) { return getParam_noArgs(); // Really just a count on most platforms. } -byteArray GenericStats::getParam_climbOneM(int distance) { +std::vector GenericStats::getParam_climbOneM(int distance) { return getParam_noArgs(); // Really just a count on most platforms. } -byteArray GenericStats::getParam_minecartOneM(int distance) { +std::vector GenericStats::getParam_minecartOneM(int distance) { return getParam_noArgs(); // Really just a count on most platforms. } -byteArray GenericStats::getParam_boatOneM(int distance) { +std::vector GenericStats::getParam_boatOneM(int distance) { return getParam_noArgs(); // Really just a count on most platforms. } -byteArray GenericStats::getParam_pigOneM(int distance) { +std::vector GenericStats::getParam_pigOneM(int distance) { return getParam_noArgs(); // Really just a count on most platforms. } -byteArray GenericStats::getParam_cowsMilked() { return getParam_noArgs(); } +std::vector GenericStats::getParam_cowsMilked() { return getParam_noArgs(); } -byteArray GenericStats::getParam_blocksPlaced(int id, int data, int count) { +std::vector GenericStats::getParam_blocksPlaced(int id, int data, int count) { return getParam_noArgs(); // Really just a count on most platforms. } -byteArray GenericStats::getParam_blocksMined(int id, int data, int count) { +std::vector GenericStats::getParam_blocksMined(int id, int data, int count) { return getParam_noArgs(); // Really just a count on most platforms. } -byteArray GenericStats::getParam_itemsCollected(int id, int aux, int count) { +std::vector GenericStats::getParam_itemsCollected(int id, int aux, int count) { return getParam_noArgs(); // Really just a count on most platforms. } -byteArray GenericStats::getParam_itemsCrafted(int id, int aux, int count) { +std::vector GenericStats::getParam_itemsCrafted(int id, int aux, int count) { return getParam_noArgs(); // Really just a count on most platforms. } -byteArray GenericStats::getParam_itemsSmelted(int id, int aux, int count) { +std::vector GenericStats::getParam_itemsSmelted(int id, int aux, int count) { return this->getParam_itemsCrafted(id, aux, count); } -byteArray GenericStats::getParam_itemsUsed(std::shared_ptr plr, +std::vector GenericStats::getParam_itemsUsed(std::shared_ptr plr, std::shared_ptr itm) { return getParam_noArgs(); // Really just a count on most platforms. } -byteArray GenericStats::getParam_itemsBought(int id, int aux, int count) { +std::vector GenericStats::getParam_itemsBought(int id, int aux, int count) { return getParam_noArgs(); } -byteArray GenericStats::getParam_mobKill(std::shared_ptr plr, +std::vector GenericStats::getParam_mobKill(std::shared_ptr plr, std::shared_ptr mob, DamageSource* dmgSrc) { return getParam_noArgs(); // Really just a count on most platforms. } -byteArray GenericStats::getParam_breedEntity(eINSTANCEOF entityId) { +std::vector GenericStats::getParam_breedEntity(eINSTANCEOF entityId) { return getParam_noArgs(); // Really just a count on most platforms. } -byteArray GenericStats::getParam_tamedEntity(eINSTANCEOF entityId) { +std::vector GenericStats::getParam_tamedEntity(eINSTANCEOF entityId) { return getParam_noArgs(); // Really just a count on most platforms. } -byteArray GenericStats::getParam_curedEntity(eINSTANCEOF entityId) { +std::vector GenericStats::getParam_curedEntity(eINSTANCEOF entityId) { return getParam_noArgs(); // Really just a count on most platforms. } -byteArray GenericStats::getParam_craftedEntity(eINSTANCEOF entityId) { +std::vector GenericStats::getParam_craftedEntity(eINSTANCEOF entityId) { return getParam_noArgs(); // Really just a count on most platforms. } -byteArray GenericStats::getParam_shearedEntity(eINSTANCEOF entityId) { +std::vector GenericStats::getParam_shearedEntity(eINSTANCEOF entityId) { return getParam_noArgs(); // Really just a count on most platforms. } -byteArray GenericStats::getParam_time(int timediff) { +std::vector GenericStats::getParam_time(int timediff) { return getParam_noArgs(); // Really just a count on most platforms. } -byteArray GenericStats::getParam_changedDimension(int from, int to) { +std::vector GenericStats::getParam_changedDimension(int from, int to) { return getParam_noArgs(); // Really just a count on most platforms. } -byteArray GenericStats::getParam_enteredBiome(int biomeId) { +std::vector GenericStats::getParam_enteredBiome(int biomeId) { return getParam_noArgs(); // Really just a count on most platforms. } -byteArray GenericStats::getParam_achievement(eAward id) { +std::vector GenericStats::getParam_achievement(eAward id) { return getParam_noArgs(); // Really just a count on most platforms. } -byteArray GenericStats::getParam_onARail(int distance) { +std::vector GenericStats::getParam_onARail(int distance) { return getParam_achievement(eAward_OnARail); } -byteArray GenericStats::getParam_overkill(int damage) { +std::vector GenericStats::getParam_overkill(int damage) { return getParam_achievement(eAward_overkill); } -byteArray GenericStats::getParam_openInventory(int menuId) { +std::vector GenericStats::getParam_openInventory(int menuId) { return getParam_achievement(eAward_TakingInventory); } -byteArray GenericStats::getParam_chestfulOfCobblestone(int cobbleStone) { +std::vector GenericStats::getParam_chestfulOfCobblestone(int cobbleStone) { #if defined(_EXTENDED_ACHIEVEMENTS) return getParam_achievement(eAward_chestfulOfCobblestone); #else @@ -519,7 +519,7 @@ byteArray GenericStats::getParam_chestfulOfCobblestone(int cobbleStone) { #endif } -byteArray GenericStats::getParam_musicToMyEars(int recordId) { +std::vector GenericStats::getParam_musicToMyEars(int recordId) { #if defined(_EXTENDED_ACHIEVEMENTS) return getParam_achievement(eAward_musicToMyEars); #else @@ -527,63 +527,63 @@ byteArray GenericStats::getParam_musicToMyEars(int recordId) { #endif } -byteArray GenericStats::getParam_noArgs() { - return byteArray(); // TODO +std::vector GenericStats::getParam_noArgs() { + return std::vector(); // TODO } -byteArray GenericStats::param_walk(int distance) { +std::vector GenericStats::param_walk(int distance) { return instance->getParam_walkOneM(distance); } -byteArray GenericStats::param_swim(int distance) { +std::vector GenericStats::param_swim(int distance) { return instance->getParam_swimOneM(distance); } -byteArray GenericStats::param_fall(int distance) { +std::vector GenericStats::param_fall(int distance) { return instance->getParam_fallOneM(distance); } -byteArray GenericStats::param_climb(int distance) { +std::vector GenericStats::param_climb(int distance) { return instance->getParam_climbOneM(distance); } -byteArray GenericStats::param_minecart(int distance) { +std::vector GenericStats::param_minecart(int distance) { return instance->getParam_minecartOneM(distance); } -byteArray GenericStats::param_boat(int distance) { +std::vector GenericStats::param_boat(int distance) { return instance->getParam_boatOneM(distance); } -byteArray GenericStats::param_pig(int distance) { +std::vector GenericStats::param_pig(int distance) { return instance->getParam_pigOneM(distance); } -byteArray GenericStats::param_cowsMilked() { +std::vector GenericStats::param_cowsMilked() { return instance->getParam_cowsMilked(); } -byteArray GenericStats::param_blocksPlaced(int id, int data, int count) { +std::vector GenericStats::param_blocksPlaced(int id, int data, int count) { return instance->getParam_blocksPlaced(id, data, count); } -byteArray GenericStats::param_blocksMined(int id, int data, int count) { +std::vector GenericStats::param_blocksMined(int id, int data, int count) { return instance->getParam_blocksMined(id, data, count); } -byteArray GenericStats::param_itemsCollected(int id, int aux, int count) { +std::vector GenericStats::param_itemsCollected(int id, int aux, int count) { return instance->getParam_itemsCollected(id, aux, count); } -byteArray GenericStats::param_itemsCrafted(int id, int aux, int count) { +std::vector GenericStats::param_itemsCrafted(int id, int aux, int count) { return instance->getParam_itemsCrafted(id, aux, count); } -byteArray GenericStats::param_itemsSmelted(int id, int aux, int count) { +std::vector GenericStats::param_itemsSmelted(int id, int aux, int count) { return instance->getParam_itemsSmelted(id, aux, count); } -byteArray GenericStats::param_itemsUsed(std::shared_ptr plr, +std::vector GenericStats::param_itemsUsed(std::shared_ptr plr, std::shared_ptr itm) { if ((plr != nullptr) && (itm != nullptr)) return instance->getParam_itemsUsed(plr, itm); @@ -591,11 +591,11 @@ byteArray GenericStats::param_itemsUsed(std::shared_ptr plr, return instance->getParam_noArgs(); } -byteArray GenericStats::param_itemsBought(int id, int aux, int count) { +std::vector GenericStats::param_itemsBought(int id, int aux, int count) { return instance->getParam_itemsBought(id, aux, count); } -byteArray GenericStats::param_mobKill(std::shared_ptr plr, +std::vector GenericStats::param_mobKill(std::shared_ptr plr, std::shared_ptr mob, DamageSource* dmgSrc) { if ((plr != nullptr) && (mob != nullptr)) @@ -604,141 +604,141 @@ byteArray GenericStats::param_mobKill(std::shared_ptr plr, return instance->getParam_noArgs(); } -byteArray GenericStats::param_breedEntity(eINSTANCEOF entityId) { +std::vector GenericStats::param_breedEntity(eINSTANCEOF entityId) { return instance->getParam_breedEntity(entityId); } -byteArray GenericStats::param_tamedEntity(eINSTANCEOF entityId) { +std::vector GenericStats::param_tamedEntity(eINSTANCEOF entityId) { return instance->getParam_tamedEntity(entityId); } -byteArray GenericStats::param_curedEntity(eINSTANCEOF entityId) { +std::vector GenericStats::param_curedEntity(eINSTANCEOF entityId) { return instance->getParam_curedEntity(entityId); } -byteArray GenericStats::param_craftedEntity(eINSTANCEOF entityId) { +std::vector GenericStats::param_craftedEntity(eINSTANCEOF entityId) { return instance->getParam_craftedEntity(entityId); } -byteArray GenericStats::param_shearedEntity(eINSTANCEOF entityId) { +std::vector GenericStats::param_shearedEntity(eINSTANCEOF entityId) { return instance->getParam_shearedEntity(entityId); } -byteArray GenericStats::param_time(int timediff) { +std::vector GenericStats::param_time(int timediff) { return instance->getParam_time(timediff); } -byteArray GenericStats::param_changedDimension(int from, int to) { +std::vector GenericStats::param_changedDimension(int from, int to) { return instance->getParam_changedDimension(from, to); } -byteArray GenericStats::param_enteredBiome(int biomeId) { +std::vector GenericStats::param_enteredBiome(int biomeId) { return instance->getParam_enteredBiome(biomeId); } -byteArray GenericStats::param_noArgs() { return instance->getParam_noArgs(); } +std::vector GenericStats::param_noArgs() { return instance->getParam_noArgs(); } -byteArray GenericStats::param_openInventory() { +std::vector GenericStats::param_openInventory() { return instance->getParam_achievement(eAward_TakingInventory); } -byteArray GenericStats::param_mineWood() { +std::vector GenericStats::param_mineWood() { return instance->getParam_achievement(eAward_GettingWood); } -byteArray GenericStats::param_buildWorkbench() { +std::vector GenericStats::param_buildWorkbench() { return instance->getParam_achievement(eAward_Benchmarking); } -byteArray GenericStats::param_buildPickaxe() { +std::vector GenericStats::param_buildPickaxe() { return instance->getParam_achievement(eAward_TimeToMine); } -byteArray GenericStats::param_buildFurnace() { +std::vector GenericStats::param_buildFurnace() { return instance->getParam_achievement(eAward_HotTopic); } -byteArray GenericStats::param_acquireIron() { +std::vector GenericStats::param_acquireIron() { return instance->getParam_achievement(eAward_AquireHardware); } -byteArray GenericStats::param_buildHoe() { +std::vector GenericStats::param_buildHoe() { return instance->getParam_achievement(eAward_TimeToFarm); } -byteArray GenericStats::param_makeBread() { +std::vector GenericStats::param_makeBread() { return instance->getParam_achievement(eAward_BakeBread); } -byteArray GenericStats::param_bakeCake() { +std::vector GenericStats::param_bakeCake() { return instance->getParam_achievement(eAward_TheLie); } -byteArray GenericStats::param_buildBetterPickaxe() { +std::vector GenericStats::param_buildBetterPickaxe() { return instance->getParam_achievement(eAward_GettingAnUpgrade); } -byteArray GenericStats::param_cookFish() { +std::vector GenericStats::param_cookFish() { return instance->getParam_achievement(eAward_DeliciousFish); } -byteArray GenericStats::param_onARail(int distance) { +std::vector GenericStats::param_onARail(int distance) { return instance->getParam_onARail(distance); } -byteArray GenericStats::param_buildSword() { +std::vector GenericStats::param_buildSword() { return instance->getParam_achievement(eAward_TimeToStrike); } -byteArray GenericStats::param_killEnemy() { +std::vector GenericStats::param_killEnemy() { return instance->getParam_achievement(eAward_MonsterHunter); } -byteArray GenericStats::param_killCow() { +std::vector GenericStats::param_killCow() { return instance->getParam_achievement(eAward_CowTipper); } -byteArray GenericStats::param_flyPig() { +std::vector GenericStats::param_flyPig() { return instance->getParam_achievement(eAward_WhenPigsFly); } -byteArray GenericStats::param_snipeSkeleton() { +std::vector GenericStats::param_snipeSkeleton() { return instance->getParam_achievement(eAward_snipeSkeleton); } -byteArray GenericStats::param_diamonds() { +std::vector GenericStats::param_diamonds() { return instance->getParam_achievement(eAward_diamonds); } -byteArray GenericStats::param_ghast() { +std::vector GenericStats::param_ghast() { return instance->getParam_achievement(eAward_ghast); } -byteArray GenericStats::param_blazeRod() { +std::vector GenericStats::param_blazeRod() { return instance->getParam_achievement(eAward_blazeRod); } -byteArray GenericStats::param_potion() { +std::vector GenericStats::param_potion() { return instance->getParam_achievement(eAward_potion); } -byteArray GenericStats::param_theEnd() { +std::vector GenericStats::param_theEnd() { return instance->getParam_achievement(eAward_theEnd); } -byteArray GenericStats::param_winGame() { +std::vector GenericStats::param_winGame() { return instance->getParam_achievement(eAward_winGame); } -byteArray GenericStats::param_enchantments() { +std::vector GenericStats::param_enchantments() { return instance->getParam_achievement(eAward_enchantments); } -byteArray GenericStats::param_overkill(int dmg) { +std::vector GenericStats::param_overkill(int dmg) { return instance->getParam_overkill(dmg); } -byteArray GenericStats::param_bookcase() { +std::vector GenericStats::param_bookcase() { #if defined(_EXTENDED_ACHIEVEMENTS) return instance->getParam_achievement(eAward_bookcase); #else @@ -746,47 +746,47 @@ byteArray GenericStats::param_bookcase() { #endif } -byteArray GenericStats::param_leaderOfThePack() { +std::vector GenericStats::param_leaderOfThePack() { return instance->getParam_achievement(eAward_LeaderOfThePack); } -byteArray GenericStats::param_MOARTools() { +std::vector GenericStats::param_MOARTools() { return instance->getParam_achievement(eAward_MOARTools); } -byteArray GenericStats::param_dispenseWithThis() { +std::vector GenericStats::param_dispenseWithThis() { return instance->getParam_achievement(eAward_DispenseWithThis); } -byteArray GenericStats::param_InToTheNether() { +std::vector GenericStats::param_InToTheNether() { return instance->getParam_achievement(eAward_InToTheNether); } -byteArray GenericStats::param_socialPost() { +std::vector GenericStats::param_socialPost() { return instance->getParam_achievement(eAward_socialPost); } -byteArray GenericStats::param_eatPorkChop() { +std::vector GenericStats::param_eatPorkChop() { return instance->getParam_achievement(eAward_eatPorkChop); } -byteArray GenericStats::param_play100Days() { +std::vector GenericStats::param_play100Days() { return instance->getParam_achievement(eAward_play100Days); } -byteArray GenericStats::param_arrowKillCreeper() { +std::vector GenericStats::param_arrowKillCreeper() { return instance->getParam_achievement(eAward_arrowKillCreeper); } -byteArray GenericStats::param_mine100Blocks() { +std::vector GenericStats::param_mine100Blocks() { return instance->getParam_achievement(eAward_mine100Blocks); } -byteArray GenericStats::param_kill10Creepers() { +std::vector GenericStats::param_kill10Creepers() { return instance->getParam_achievement(eAward_kill10Creepers); } -byteArray GenericStats::param_adventuringTime() { +std::vector GenericStats::param_adventuringTime() { #if defined(_EXTENDED_ACHIEVEMENTS) return instance->getParam_achievement(eAward_adventuringTime); #else @@ -794,7 +794,7 @@ byteArray GenericStats::param_adventuringTime() { #endif } -byteArray GenericStats::param_repopulation() { +std::vector GenericStats::param_repopulation() { #if defined(_EXTENDED_ACHIEVEMENTS) return instance->getParam_achievement(eAward_repopulation); #else @@ -802,7 +802,7 @@ byteArray GenericStats::param_repopulation() { #endif } -byteArray GenericStats::param_porkChop() { +std::vector GenericStats::param_porkChop() { #if defined(_EXTENDED_ACHIEVEMENTS) return instance->getParam_achievement(eAward_eatPorkChop); #else @@ -810,7 +810,7 @@ byteArray GenericStats::param_porkChop() { #endif } -byteArray GenericStats::param_diamondsToYou() { +std::vector GenericStats::param_diamondsToYou() { #if defined(_EXTENDED_ACHIEVEMENTS) return instance->getParam_achievement(eAward_diamondsToYou); #else @@ -818,7 +818,7 @@ byteArray GenericStats::param_diamondsToYou() { #endif } -byteArray GenericStats::param_passingTheTime() { +std::vector GenericStats::param_passingTheTime() { #if defined(_EXTENDED_ACHIEVEMENTS) return instance->getParam_achievement(eAward_play100Days); #else @@ -826,7 +826,7 @@ byteArray GenericStats::param_passingTheTime() { #endif } -byteArray GenericStats::param_archer() { +std::vector GenericStats::param_archer() { #if defined(_EXTENDED_ACHIEVEMENTS) return instance->getParam_achievement(eAward_arrowKillCreeper); #else @@ -834,7 +834,7 @@ byteArray GenericStats::param_archer() { #endif } -byteArray GenericStats::param_theHaggler() { +std::vector GenericStats::param_theHaggler() { #if defined(_EXTENDED_ACHIEVEMENTS) return instance->getParam_achievement(eAward_theHaggler); #else @@ -842,7 +842,7 @@ byteArray GenericStats::param_theHaggler() { #endif } -byteArray GenericStats::param_potPlanter() { +std::vector GenericStats::param_potPlanter() { #if defined(_EXTENDED_ACHIEVEMENTS) return instance->getParam_achievement(eAward_potPlanter); #else @@ -850,7 +850,7 @@ byteArray GenericStats::param_potPlanter() { #endif } -byteArray GenericStats::param_itsASign() { +std::vector GenericStats::param_itsASign() { #if defined(_EXTENDED_ACHIEVEMENTS) return instance->getParam_achievement(eAward_itsASign); #else @@ -858,7 +858,7 @@ byteArray GenericStats::param_itsASign() { #endif } -byteArray GenericStats::param_ironBelly() { +std::vector GenericStats::param_ironBelly() { #if defined(_EXTENDED_ACHIEVEMENTS) return instance->getParam_achievement(eAward_ironBelly); #else @@ -866,7 +866,7 @@ byteArray GenericStats::param_ironBelly() { #endif } -byteArray GenericStats::param_haveAShearfulDay() { +std::vector GenericStats::param_haveAShearfulDay() { #if defined(_EXTENDED_ACHIEVEMENTS) return instance->getParam_achievement(eAward_haveAShearfulDay); #else @@ -874,7 +874,7 @@ byteArray GenericStats::param_haveAShearfulDay() { #endif } -byteArray GenericStats::param_rainbowCollection() { +std::vector GenericStats::param_rainbowCollection() { #if defined(_EXTENDED_ACHIEVEMENTS) return instance->getParam_achievement(eAward_rainbowCollection); #else @@ -882,7 +882,7 @@ byteArray GenericStats::param_rainbowCollection() { #endif } -byteArray GenericStats::param_stayinFrosty() { +std::vector GenericStats::param_stayinFrosty() { #if defined(_EXTENDED_ACHIEVEMENTS) return instance->getParam_achievement(eAward_stayinFrosty); #else @@ -890,11 +890,11 @@ byteArray GenericStats::param_stayinFrosty() { #endif } -byteArray GenericStats::param_chestfulOfCobblestone(int cobbleStone) { +std::vector GenericStats::param_chestfulOfCobblestone(int cobbleStone) { return instance->getParam_chestfulOfCobblestone(cobbleStone); } -byteArray GenericStats::param_renewableEnergy() { +std::vector GenericStats::param_renewableEnergy() { #if defined(_EXTENDED_ACHIEVEMENTS) return instance->getParam_achievement(eAward_renewableEnergy); #else @@ -902,11 +902,11 @@ byteArray GenericStats::param_renewableEnergy() { #endif } -byteArray GenericStats::param_musicToMyEars(int recordId) { +std::vector GenericStats::param_musicToMyEars(int recordId) { return instance->getParam_musicToMyEars(recordId); } -byteArray GenericStats::param_bodyGuard() { +std::vector GenericStats::param_bodyGuard() { #if defined(_EXTENDED_ACHIEVEMENTS) return instance->getParam_achievement(eAward_bodyGuard); #else @@ -914,7 +914,7 @@ byteArray GenericStats::param_bodyGuard() { #endif } -byteArray GenericStats::param_ironMan() { +std::vector GenericStats::param_ironMan() { #if defined(_EXTENDED_ACHIEVEMENTS) return instance->getParam_achievement(eAward_ironMan); #else @@ -922,7 +922,7 @@ byteArray GenericStats::param_ironMan() { #endif } -byteArray GenericStats::param_zombieDoctor() { +std::vector GenericStats::param_zombieDoctor() { #if defined(_EXTENDED_ACHIEVEMENTS) return instance->getParam_achievement(eAward_zombieDoctor); #else @@ -930,7 +930,7 @@ byteArray GenericStats::param_zombieDoctor() { #endif } -byteArray GenericStats::param_lionTamer() { +std::vector GenericStats::param_lionTamer() { #if defined(_EXTENDED_ACHIEVEMENTS) return instance->getParam_achievement(eAward_lionTamer); #else diff --git a/minecraft/Minecraft.World/net/minecraft/stats/GenericStats.h b/minecraft/Minecraft.World/net/minecraft/stats/GenericStats.h index c867dbb3e..61b4facea 100644 --- a/minecraft/Minecraft.World/net/minecraft/stats/GenericStats.h +++ b/minecraft/Minecraft.World/net/minecraft/stats/GenericStats.h @@ -185,111 +185,111 @@ public: // STAT PARAMS - STATIC // - static byteArray param_walk(int distance); - static byteArray param_swim(int distance); - static byteArray param_fall(int distance); - static byteArray param_climb(int distance); - static byteArray param_minecart(int distance); - static byteArray param_boat(int distance); - static byteArray param_pig(int distance); + static std::vector param_walk(int distance); + static std::vector param_swim(int distance); + static std::vector param_fall(int distance); + static std::vector param_climb(int distance); + static std::vector param_minecart(int distance); + static std::vector param_boat(int distance); + static std::vector param_pig(int distance); - static byteArray param_cowsMilked(); + static std::vector param_cowsMilked(); - static byteArray param_blocksPlaced(int id, int data, int count); - static byteArray param_blocksMined(int id, int data, int count); - static byteArray param_itemsCollected(int id, int aux, int count); - static byteArray param_itemsCrafted(int id, int aux, int count); - static byteArray param_itemsSmelted(int id, int aux, int cound); - static byteArray param_itemsUsed(std::shared_ptr plr, + static std::vector param_blocksPlaced(int id, int data, int count); + static std::vector param_blocksMined(int id, int data, int count); + static std::vector param_itemsCollected(int id, int aux, int count); + static std::vector param_itemsCrafted(int id, int aux, int count); + static std::vector param_itemsSmelted(int id, int aux, int cound); + static std::vector param_itemsUsed(std::shared_ptr plr, std::shared_ptr itm); - static byteArray param_itemsBought(int id, int aux, int count); + static std::vector param_itemsBought(int id, int aux, int count); - static byteArray param_mobKill(std::shared_ptr plr, + static std::vector param_mobKill(std::shared_ptr plr, std::shared_ptr mob, DamageSource* dmgSrc); - static byteArray param_breedEntity(eINSTANCEOF mobType); - static byteArray param_tamedEntity(eINSTANCEOF mobType); - static byteArray param_curedEntity(eINSTANCEOF mobType); - static byteArray param_craftedEntity(eINSTANCEOF mobType); - static byteArray param_shearedEntity(eINSTANCEOF mobType); + static std::vector param_breedEntity(eINSTANCEOF mobType); + static std::vector param_tamedEntity(eINSTANCEOF mobType); + static std::vector param_curedEntity(eINSTANCEOF mobType); + static std::vector param_craftedEntity(eINSTANCEOF mobType); + static std::vector param_shearedEntity(eINSTANCEOF mobType); - static byteArray param_time(int timediff); + static std::vector param_time(int timediff); - static byteArray param_changedDimension(int from, int to); - static byteArray param_enteredBiome(int biomeId); + static std::vector param_changedDimension(int from, int to); + static std::vector param_enteredBiome(int biomeId); - // static byteArray param_achievement(eAward id); + // static std::vector param_achievement(eAward id); - // static byteArray param_ach_onARail(); - // static byteArray param_overkill(int damage); //TODO - // static byteArray param_openInventory(int menuId); - // static byteArray param_chestfulOfCobblestone(); - // static byteArray param_musicToMyEars(int recordId); + // static std::vector param_ach_onARail(); + // static std::vector param_overkill(int damage); //TODO + // static std::vector param_openInventory(int menuId); + // static std::vector param_chestfulOfCobblestone(); + // static std::vector param_musicToMyEars(int recordId); - static byteArray param_noArgs(); + static std::vector param_noArgs(); // STATIC + VIRTUAL - ACHIEVEMENT - PARAMS // - static byteArray param_openInventory(); - static byteArray param_mineWood(); - static byteArray param_buildWorkbench(); - static byteArray param_buildPickaxe(); - static byteArray param_buildFurnace(); - static byteArray param_acquireIron(); - static byteArray param_buildHoe(); - static byteArray param_makeBread(); - static byteArray param_bakeCake(); - static byteArray param_buildBetterPickaxe(); - static byteArray param_cookFish(); - static byteArray param_onARail(int distance); - static byteArray param_buildSword(); - static byteArray param_killEnemy(); - static byteArray param_killCow(); - static byteArray param_flyPig(); - static byteArray param_snipeSkeleton(); - static byteArray param_diamonds(); - static byteArray param_ghast(); - static byteArray param_blazeRod(); - static byteArray param_potion(); - static byteArray param_theEnd(); - static byteArray param_winGame(); - static byteArray param_enchantments(); - static byteArray param_overkill(int dmg); - static byteArray param_bookcase(); + static std::vector param_openInventory(); + static std::vector param_mineWood(); + static std::vector param_buildWorkbench(); + static std::vector param_buildPickaxe(); + static std::vector param_buildFurnace(); + static std::vector param_acquireIron(); + static std::vector param_buildHoe(); + static std::vector param_makeBread(); + static std::vector param_bakeCake(); + static std::vector param_buildBetterPickaxe(); + static std::vector param_cookFish(); + static std::vector param_onARail(int distance); + static std::vector param_buildSword(); + static std::vector param_killEnemy(); + static std::vector param_killCow(); + static std::vector param_flyPig(); + static std::vector param_snipeSkeleton(); + static std::vector param_diamonds(); + static std::vector param_ghast(); + static std::vector param_blazeRod(); + static std::vector param_potion(); + static std::vector param_theEnd(); + static std::vector param_winGame(); + static std::vector param_enchantments(); + static std::vector param_overkill(int dmg); + static std::vector param_bookcase(); - static byteArray param_leaderOfThePack(); - static byteArray param_MOARTools(); - static byteArray param_dispenseWithThis(); - static byteArray param_InToTheNether(); + static std::vector param_leaderOfThePack(); + static std::vector param_MOARTools(); + static std::vector param_dispenseWithThis(); + static std::vector param_InToTheNether(); - static byteArray param_socialPost(); - static byteArray param_eatPorkChop(); - static byteArray param_play100Days(); - static byteArray param_arrowKillCreeper(); - static byteArray param_mine100Blocks(); - static byteArray param_kill10Creepers(); + static std::vector param_socialPost(); + static std::vector param_eatPorkChop(); + static std::vector param_play100Days(); + static std::vector param_arrowKillCreeper(); + static std::vector param_mine100Blocks(); + static std::vector param_kill10Creepers(); - static byteArray param_adventuringTime(); - static byteArray param_repopulation(); - static byteArray param_porkChop(); - static byteArray param_diamondsToYou(); - static byteArray param_passingTheTime(); - static byteArray param_archer(); - static byteArray param_theHaggler(); - static byteArray param_potPlanter(); - static byteArray param_itsASign(); - static byteArray param_ironBelly(); - static byteArray param_haveAShearfulDay(); - static byteArray param_rainbowCollection(); - static byteArray param_stayinFrosty(); - static byteArray param_chestfulOfCobblestone(int cobbleStone); - static byteArray param_renewableEnergy(); - static byteArray param_musicToMyEars(int recordId); - static byteArray param_bodyGuard(); - static byteArray param_ironMan(); - static byteArray param_zombieDoctor(); - static byteArray param_lionTamer(); + static std::vector param_adventuringTime(); + static std::vector param_repopulation(); + static std::vector param_porkChop(); + static std::vector param_diamondsToYou(); + static std::vector param_passingTheTime(); + static std::vector param_archer(); + static std::vector param_theHaggler(); + static std::vector param_potPlanter(); + static std::vector param_itsASign(); + static std::vector param_ironBelly(); + static std::vector param_haveAShearfulDay(); + static std::vector param_rainbowCollection(); + static std::vector param_stayinFrosty(); + static std::vector param_chestfulOfCobblestone(int cobbleStone); + static std::vector param_renewableEnergy(); + static std::vector param_musicToMyEars(int recordId); + static std::vector param_bodyGuard(); + static std::vector param_ironMan(); + static std::vector param_zombieDoctor(); + static std::vector param_lionTamer(); protected: // ACHIEVEMENTS - VIRTUAL // @@ -346,49 +346,49 @@ protected: // STAT PARAMS - VIRTUAL // - virtual byteArray getParam_walkOneM(int distance); - virtual byteArray getParam_swimOneM(int distance); - virtual byteArray getParam_fallOneM(int distance); - virtual byteArray getParam_climbOneM(int distance); - virtual byteArray getParam_minecartOneM(int distance); - virtual byteArray getParam_boatOneM(int distance); - virtual byteArray getParam_pigOneM(int distance); + virtual std::vector getParam_walkOneM(int distance); + virtual std::vector getParam_swimOneM(int distance); + virtual std::vector getParam_fallOneM(int distance); + virtual std::vector getParam_climbOneM(int distance); + virtual std::vector getParam_minecartOneM(int distance); + virtual std::vector getParam_boatOneM(int distance); + virtual std::vector getParam_pigOneM(int distance); - virtual byteArray getParam_cowsMilked(); + virtual std::vector getParam_cowsMilked(); - virtual byteArray getParam_blocksPlaced(int id, int data, int count); - virtual byteArray getParam_blocksMined(int id, int data, int count); - virtual byteArray getParam_itemsCollected(int id, int aux, int count); - virtual byteArray getParam_itemsCrafted(int id, int aux, int count); - virtual byteArray getParam_itemsSmelted(int id, int aux, int count); - virtual byteArray getParam_itemsUsed(std::shared_ptr plr, + virtual std::vector getParam_blocksPlaced(int id, int data, int count); + virtual std::vector getParam_blocksMined(int id, int data, int count); + virtual std::vector getParam_itemsCollected(int id, int aux, int count); + virtual std::vector getParam_itemsCrafted(int id, int aux, int count); + virtual std::vector getParam_itemsSmelted(int id, int aux, int count); + virtual std::vector getParam_itemsUsed(std::shared_ptr plr, std::shared_ptr itm); - virtual byteArray getParam_itemsBought(int id, int aux, int count); + virtual std::vector getParam_itemsBought(int id, int aux, int count); - virtual byteArray getParam_mobKill(std::shared_ptr plr, + virtual std::vector getParam_mobKill(std::shared_ptr plr, std::shared_ptr mob, DamageSource* dmgSrc); - virtual byteArray getParam_breedEntity(eINSTANCEOF entityId); - virtual byteArray getParam_tamedEntity(eINSTANCEOF entityId); - virtual byteArray getParam_curedEntity(eINSTANCEOF entityId); - virtual byteArray getParam_craftedEntity(eINSTANCEOF entityId); - virtual byteArray getParam_shearedEntity(eINSTANCEOF entityId); + virtual std::vector getParam_breedEntity(eINSTANCEOF entityId); + virtual std::vector getParam_tamedEntity(eINSTANCEOF entityId); + virtual std::vector getParam_curedEntity(eINSTANCEOF entityId); + virtual std::vector getParam_craftedEntity(eINSTANCEOF entityId); + virtual std::vector getParam_shearedEntity(eINSTANCEOF entityId); - virtual byteArray getParam_time(int timediff); + virtual std::vector getParam_time(int timediff); - virtual byteArray getParam_changedDimension(int from, int to); - virtual byteArray getParam_enteredBiome(int biomeId); + virtual std::vector getParam_changedDimension(int from, int to); + virtual std::vector getParam_enteredBiome(int biomeId); - virtual byteArray getParam_achievement(eAward id); + virtual std::vector getParam_achievement(eAward id); - virtual byteArray getParam_onARail(int distance); - virtual byteArray getParam_overkill(int damage); - virtual byteArray getParam_openInventory(int menuId); - virtual byteArray getParam_chestfulOfCobblestone(int cobbleStone); - virtual byteArray getParam_musicToMyEars(int recordId); + virtual std::vector getParam_onARail(int distance); + virtual std::vector getParam_overkill(int damage); + virtual std::vector getParam_openInventory(int menuId); + virtual std::vector getParam_chestfulOfCobblestone(int cobbleStone); + virtual std::vector getParam_musicToMyEars(int recordId); - virtual byteArray getParam_noArgs(); + virtual std::vector getParam_noArgs(); }; // Req Stats \ No newline at end of file diff --git a/minecraft/Minecraft.World/net/minecraft/stats/Stat.h b/minecraft/Minecraft.World/net/minecraft/stats/Stat.h index c4a7c997c..8115f0f53 100644 --- a/minecraft/Minecraft.World/net/minecraft/stats/Stat.h +++ b/minecraft/Minecraft.World/net/minecraft/stats/Stat.h @@ -52,7 +52,7 @@ public: public: // 4J-JEV, for Durango stats virtual void handleParamBlob(std::shared_ptr plr, - byteArray param) { + std::vector& param) { app.DebugPrintf("'Stat.h', Unhandled AwardStat blob.\n"); return; } diff --git a/minecraft/Minecraft.World/net/minecraft/stats/Stats.cpp b/minecraft/Minecraft.World/net/minecraft/stats/Stats.cpp index 9d395c2af..8b2124cd0 100644 --- a/minecraft/Minecraft.World/net/minecraft/stats/Stats.cpp +++ b/minecraft/Minecraft.World/net/minecraft/stats/Stats.cpp @@ -55,14 +55,14 @@ Stat* Stats::befriendsWolf = nullptr; Stat* Stats::totalBlocksMined = nullptr; Stat* Stats::timePlayed = nullptr; -StatArray Stats::blocksMined; -StatArray Stats::itemsCollected; -StatArray Stats::itemsCrafted; +std::vector Stats::blocksMined; +std::vector Stats::itemsCollected; +std::vector Stats::itemsCrafted; #if defined(_EXTENDED_ACHIEVEMENTS) -StatArray Stats::blocksPlaced; -StatArray Stats::rainbowCollection; -StatArray Stats::biomesVisisted; +std::vector Stats::blocksPlaced; +std::vector Stats::rainbowCollection; +std::vector Stats::biomesVisisted; #endif Stat* Stats::killsEnderdragon = @@ -162,7 +162,7 @@ bool Stats::blockStatsLoaded = false; // These stats are directly followed by the achievemnts in the profile data, so // cannot be changed without migrating the profile data void Stats::buildBlockStats() { - blocksMined = StatArray(32000); + blocksMined = std::vector(32000); ItemStat* newStat = new ItemStat(BLOCKS_MINED_OFFSET + 0, L"mineBlock.dirt", Tile::dirt->id); @@ -300,7 +300,7 @@ void Stats::buildCraftableStats() { // Collected stats - itemsCollected = StatArray(32000); + itemsCollected = std::vector(32000); ItemStat* newStat = new ItemStat(ITEMS_COLLECTED_OFFSET + 0, L"collectItem.egg", Item::egg->id); @@ -338,7 +338,7 @@ void Stats::buildCraftableStats() { // Crafted stats - itemsCrafted = StatArray(32000); + itemsCrafted = std::vector(32000); newStat = new ItemStat(ITEMS_CRAFTED_OFFSET + 0, L"craftItem.plank", Tile::wood->id); @@ -582,7 +582,7 @@ void Stats::buildAdditionalStats() { // 4J-JEV: We don't need itemsCollected(emerald) so I'm using it to // stor itemsBought(emerald) so I don't have to make yet another massive - // StatArray for Items Bought. + // std::vector& for Items Bought. itemStat = new ItemStat(offset++, L"itemsBought.emerald", Item::emerald_Id); itemsCollectedStats->push_back(itemStat); @@ -593,7 +593,7 @@ void Stats::buildAdditionalStats() { // LARGE WHEN THEY ARE GOING TO BE MOSTLY EMPTY!!! // Either way, I'm making this one smaller because // we don't need those record items (and we only need 2). - blocksPlaced = StatArray(1000); + blocksPlaced = std::vector(1000); itemStat = new ItemStat(offset++, L"blockPlaced.flowerPot", Tile::flowerPot_Id); @@ -614,7 +614,7 @@ void Stats::buildAdditionalStats() { GeneralStat* generalStat = nullptr; - rainbowCollection = StatArray(16); + rainbowCollection = std::vector(16); for (unsigned int i = 0; i < 16; i++) { generalStat = new GeneralStat( offset++, L"rainbowCollection." + _toString(i)); @@ -623,7 +623,7 @@ void Stats::buildAdditionalStats() { generalStat->postConstruct(); } - biomesVisisted = StatArray(23); + biomesVisisted = std::vector(23); for (unsigned int i = 0; i < 23; i++) { generalStat = new GeneralStat( offset++, L"biomesVisited." + _toString(i)); diff --git a/minecraft/Minecraft.World/net/minecraft/stats/Stats.h b/minecraft/Minecraft.World/net/minecraft/stats/Stats.h index 7f825d320..d53a7e6df 100644 --- a/minecraft/Minecraft.World/net/minecraft/stats/Stats.h +++ b/minecraft/Minecraft.World/net/minecraft/stats/Stats.h @@ -56,13 +56,13 @@ public: // per day! Stored as large stat so it doesn't max out // before reaching 100 days ( 2,400,000 ticks ). - // static StatArray mobsKilled; - static StatArray blocksMined; - static StatArray itemsCollected; - static StatArray itemsCrafted; + // static std::vector mobsKilled; + static std::vector blocksMined; + static std::vector itemsCollected; + static std::vector itemsCrafted; #if (defined _EXTENDED_ACHIEVEMENTS) && (!0) - static StatArray blocksPlaced; + static std::vector blocksPlaced; #endif // Added TU9 @@ -72,8 +72,8 @@ public: // present when the Enderdragon has died #if (defined _EXTENDED_ACHIEVEMENTS) && (!0) - static StatArray biomesVisisted; - static StatArray rainbowCollection; + static std::vector biomesVisisted; + static std::vector rainbowCollection; #endif static void staticCtor(); diff --git a/minecraft/Minecraft.World/net/minecraft/util/WeighedRandom.cpp b/minecraft/Minecraft.World/net/minecraft/util/WeighedRandom.cpp index 237030d3e..a51bfe72e 100644 --- a/minecraft/Minecraft.World/net/minecraft/util/WeighedRandom.cpp +++ b/minecraft/Minecraft.World/net/minecraft/util/WeighedRandom.cpp @@ -31,23 +31,23 @@ WeighedRandomItem* WeighedRandom::getRandomItem( return getRandomItem(random, items, getTotalWeight(items)); } -int WeighedRandom::getTotalWeight(WeighedRandomItemArray items) { +int WeighedRandom::getTotalWeight(const std::vector& items) { int totalWeight = 0; - for (unsigned int i = 0; i < items.length; i++) { + for (unsigned int i = 0; i < items.size(); i++) { totalWeight += items[i]->randomWeight; } return totalWeight; } WeighedRandomItem* WeighedRandom::getRandomItem(Random* random, - WeighedRandomItemArray items, + const std::vector& items, int totalWeight) { if (totalWeight <= 0) { __debugbreak(); } int selection = random->nextInt(totalWeight); - for (unsigned int i = 0; i < items.length; i++) { + for (unsigned int i = 0; i < items.size(); i++) { selection -= items[i]->randomWeight; if (selection < 0) { return items[i]; @@ -57,6 +57,6 @@ WeighedRandomItem* WeighedRandom::getRandomItem(Random* random, } WeighedRandomItem* WeighedRandom::getRandomItem(Random* random, - WeighedRandomItemArray items) { + const std::vector& items) { return getRandomItem(random, items, getTotalWeight(items)); } \ No newline at end of file diff --git a/minecraft/Minecraft.World/net/minecraft/util/WeighedRandom.h b/minecraft/Minecraft.World/net/minecraft/util/WeighedRandom.h index af1a0e54f..27b7ed518 100644 --- a/minecraft/Minecraft.World/net/minecraft/util/WeighedRandom.h +++ b/minecraft/Minecraft.World/net/minecraft/util/WeighedRandom.h @@ -21,10 +21,10 @@ public: int totalWeight); static WeighedRandomItem* getRandomItem( Random* random, std::vector* items); - static int getTotalWeight(WeighedRandomItemArray items); + static int getTotalWeight(const std::vector& items); static WeighedRandomItem* getRandomItem(Random* random, - WeighedRandomItemArray items, + const std::vector& items, int totalWeight); static WeighedRandomItem* getRandomItem(Random* random, - WeighedRandomItemArray items); + const std::vector& items); }; diff --git a/minecraft/Minecraft.World/net/minecraft/util/WeighedTreasure.cpp b/minecraft/Minecraft.World/net/minecraft/util/WeighedTreasure.cpp index 0e9a919ae..521a14f68 100644 --- a/minecraft/Minecraft.World/net/minecraft/util/WeighedTreasure.cpp +++ b/minecraft/Minecraft.World/net/minecraft/util/WeighedTreasure.cpp @@ -21,13 +21,13 @@ WeighedTreasure::WeighedTreasure(std::shared_ptr item, this->maxCount = maxCount; } -void WeighedTreasure::addChestItems(Random* random, WeighedTreasureArray items, +void WeighedTreasure::addChestItems(Random* random, const std::vector& items, std::shared_ptr dest, int numRolls) { for (int r = 0; r < numRolls; r++) { WeighedTreasure* treasure = (WeighedTreasure*)WeighedRandom::getRandomItem( - random, *((WeighedRandomItemArray*)&items)); + random, *((std::vector*)&items)); int count = treasure->minCount + @@ -48,12 +48,12 @@ void WeighedTreasure::addChestItems(Random* random, WeighedTreasureArray items, } void WeighedTreasure::addDispenserItems( - Random* random, WeighedTreasureArray items, + Random* random, const std::vector& items, std::shared_ptr dest, int numRolls) { for (int r = 0; r < numRolls; r++) { WeighedTreasure* treasure = (WeighedTreasure*)WeighedRandom::getRandomItem( - random, *((WeighedRandomItemArray*)&items)); + random, *((std::vector*)&items)); int count = treasure->minCount + @@ -73,12 +73,12 @@ void WeighedTreasure::addDispenserItems( } } -WeighedTreasureArray WeighedTreasure::addToTreasure(WeighedTreasureArray items, +std::vector WeighedTreasure::addToTreasure(std::vector& items, WeighedTreasure* extra) { - WeighedTreasureArray result(items.length + 1); + std::vector result(items.size() + 1); int i = 0; - for (int j = 0; j < items.length; j++) { + for (int j = 0; j < items.size(); j++) { result[i++] = items[j]; } diff --git a/minecraft/Minecraft.World/net/minecraft/util/WeighedTreasure.h b/minecraft/Minecraft.World/net/minecraft/util/WeighedTreasure.h index 5bc65fcc7..49f7d2040 100644 --- a/minecraft/Minecraft.World/net/minecraft/util/WeighedTreasure.h +++ b/minecraft/Minecraft.World/net/minecraft/util/WeighedTreasure.h @@ -14,11 +14,11 @@ public: WeighedTreasure(std::shared_ptr item, int minCount, int maxCount, int weight); - static void addChestItems(Random* random, WeighedTreasureArray items, + static void addChestItems(Random* random, const std::vector& items, std::shared_ptr dest, int numRolls); - static void addDispenserItems(Random* random, WeighedTreasureArray items, + static void addDispenserItems(Random* random, const std::vector& items, std::shared_ptr dest, int numRolls); - static WeighedTreasureArray addToTreasure(WeighedTreasureArray items, + static std::vector addToTreasure(std::vector& items, WeighedTreasure* extra); }; \ No newline at end of file diff --git a/minecraft/Minecraft.World/net/minecraft/world/SimpleContainer.cpp b/minecraft/Minecraft.World/net/minecraft/world/SimpleContainer.cpp index 28a681b33..21c8d3f71 100644 --- a/minecraft/Minecraft.World/net/minecraft/world/SimpleContainer.cpp +++ b/minecraft/Minecraft.World/net/minecraft/world/SimpleContainer.cpp @@ -11,7 +11,7 @@ SimpleContainer::SimpleContainer(int name, std::wstring stringName, this->stringName = stringName; this->customName = customName; this->size = size; - items = new arrayWithLength>(size); + items = new std::vector>(size); listeners = nullptr; } diff --git a/minecraft/Minecraft.World/net/minecraft/world/SimpleContainer.h b/minecraft/Minecraft.World/net/minecraft/world/SimpleContainer.h index e82f56537..2fcaca85b 100644 --- a/minecraft/Minecraft.World/net/minecraft/world/SimpleContainer.h +++ b/minecraft/Minecraft.World/net/minecraft/world/SimpleContainer.h @@ -8,7 +8,7 @@ private: int name; std::wstring stringName; int size; - arrayWithLength>* items; + std::vector>* items; std::vector* listeners; bool customName; diff --git a/minecraft/Minecraft.World/net/minecraft/world/WorldlyContainer.h b/minecraft/Minecraft.World/net/minecraft/world/WorldlyContainer.h index 0453f602a..b06c4f1f4 100644 --- a/minecraft/Minecraft.World/net/minecraft/world/WorldlyContainer.h +++ b/minecraft/Minecraft.World/net/minecraft/world/WorldlyContainer.h @@ -4,7 +4,7 @@ class WorldlyContainer : public Container { public: - virtual intArray getSlotsForFace(int face) = 0; + virtual std::vector getSlotsForFace(int face) = 0; virtual bool canPlaceItemThroughFace(int slot, std::shared_ptr item, int face) = 0; diff --git a/minecraft/Minecraft.World/net/minecraft/world/entity/Entity.cpp b/minecraft/Minecraft.World/net/minecraft/world/entity/Entity.cpp index c25ac1c7a..17cb728a1 100644 --- a/minecraft/Minecraft.World/net/minecraft/world/entity/Entity.cpp +++ b/minecraft/Minecraft.World/net/minecraft/world/entity/Entity.cpp @@ -1569,9 +1569,9 @@ void Entity::handleEntityEvent(uint8_t eventId) {} void Entity::animateHurt() {} -arrayWithLength> Entity::getEquipmentSlots() // ItemInstance[] +std::vector> Entity::getEquipmentSlots() // ItemInstance[] { - return arrayWithLength>(); // Default ctor creates nullptr internal array + return std::vector>(); // Default ctor creates nullptr internal array } // 4J Stu - Brought forward change from 1.3 to fix #64688 - Customer diff --git a/minecraft/Minecraft.World/net/minecraft/world/entity/Entity.h b/minecraft/Minecraft.World/net/minecraft/world/entity/Entity.h index 730da5986..5b0a67648 100644 --- a/minecraft/Minecraft.World/net/minecraft/world/entity/Entity.h +++ b/minecraft/Minecraft.World/net/minecraft/world/entity/Entity.h @@ -350,7 +350,7 @@ public: virtual void lerpMotion(double xd, double yd, double zd); virtual void handleEntityEvent(uint8_t eventId); virtual void animateHurt(); - virtual arrayWithLength> getEquipmentSlots(); // ItemInstance[] + virtual std::vector> getEquipmentSlots(); // ItemInstance[] virtual void setEquippedSlot( int slot, std::shared_ptr item); // 4J Stu - Brought forward change from 1.3 to fix diff --git a/minecraft/Minecraft.World/net/minecraft/world/entity/LivingEntity.cpp b/minecraft/Minecraft.World/net/minecraft/world/entity/LivingEntity.cpp index 4029ac3fb..d692871ff 100644 --- a/minecraft/Minecraft.World/net/minecraft/world/entity/LivingEntity.cpp +++ b/minecraft/Minecraft.World/net/minecraft/world/entity/LivingEntity.cpp @@ -44,7 +44,7 @@ AttributeModifier* LivingEntity::SPEED_MODIFIER_SPRINTING = void LivingEntity::_init() { attributes = nullptr; combatTracker = new CombatTracker(this); - lastEquipment = arrayWithLength>(5); + lastEquipment = std::vector>(5); swinging = false; swingTime = 0; @@ -127,7 +127,6 @@ LivingEntity::~LivingEntity() { delete attributes; delete combatTracker; - if (lastEquipment.data != nullptr) delete[] lastEquipment.data; } void LivingEntity::defineSynchedData() { @@ -357,8 +356,8 @@ void LivingEntity::addAdditonalSaveData(CompoundTag* entityTag) { entityTag->putShort(L"AttackTime", (short)attackTime); entityTag->putFloat(L"AbsorptionAmount", getAbsorptionAmount()); - arrayWithLength> items = getEquipmentSlots(); - for (unsigned int i = 0; i < items.length; ++i) { + std::vector> items = getEquipmentSlots(); + for (unsigned int i = 0; i < items.size(); ++i) { std::shared_ptr item = items[i]; if (item != nullptr) { attributes->removeItemModifiers(item); @@ -368,7 +367,7 @@ void LivingEntity::addAdditonalSaveData(CompoundTag* entityTag) { entityTag->put(L"Attributes", SharedMonsterAttributes::saveAttributes(getAttributes())); - for (unsigned int i = 0; i < items.length; ++i) { + for (unsigned int i = 0; i < items.size(); ++i) { std::shared_ptr item = items[i]; if (item != nullptr) { attributes->addItemModifiers(item); @@ -951,8 +950,8 @@ void LivingEntity::animateHurt() { */ int LivingEntity::getArmorValue() { int val = 0; - arrayWithLength> items = getEquipmentSlots(); - for (unsigned int i = 0; i < items.length; ++i) { + std::vector> items = getEquipmentSlots(); + for (unsigned int i = 0; i < items.size(); ++i) { std::shared_ptr item = items[i]; if (item != nullptr && dynamic_cast(item->getItem()) != nullptr) { diff --git a/minecraft/Minecraft.World/net/minecraft/world/entity/LivingEntity.h b/minecraft/Minecraft.World/net/minecraft/world/entity/LivingEntity.h index eddf7caa9..4631b1586 100644 --- a/minecraft/Minecraft.World/net/minecraft/world/entity/LivingEntity.h +++ b/minecraft/Minecraft.World/net/minecraft/world/entity/LivingEntity.h @@ -56,7 +56,7 @@ private: BaseAttributeMap* attributes; CombatTracker* combatTracker; std::unordered_map activeEffects; - arrayWithLength> lastEquipment; + std::vector> lastEquipment; public: bool swinging; @@ -242,7 +242,7 @@ public: std::shared_ptr item) = 0; virtual void setSprinting(bool value); - virtual arrayWithLength> getEquipmentSlots() = 0; + virtual std::vector> getEquipmentSlots() = 0; virtual Icon* getItemInHandIcon(std::shared_ptr item, int layer); diff --git a/minecraft/Minecraft.World/net/minecraft/world/entity/Mob.cpp b/minecraft/Minecraft.World/net/minecraft/world/entity/Mob.cpp index f8ac18ee8..77b8704d5 100644 --- a/minecraft/Minecraft.World/net/minecraft/world/entity/Mob.cpp +++ b/minecraft/Minecraft.World/net/minecraft/world/entity/Mob.cpp @@ -43,8 +43,8 @@ void Mob::_init() { target = nullptr; sensing = nullptr; - equipment = arrayWithLength>(5); - dropChances = floatArray(5); + equipment = std::vector>(5); + dropChances = std::vector(5); for (unsigned int i = 0; i < 5; ++i) { equipment[i] = nullptr; dropChances[i] = 0.0f; @@ -91,8 +91,6 @@ Mob::~Mob() { if (leashInfoTag != nullptr) delete leashInfoTag; - if (equipment.data != nullptr) delete[] equipment.data; - delete[] dropChances.data; } void Mob::registerAttributes() { @@ -157,8 +155,8 @@ int Mob::getExperienceReward(std::shared_ptr killedBy) { if (xpReward > 0) { int result = xpReward; - arrayWithLength> slots = getEquipmentSlots(); - for (int i = 0; i < slots.length; i++) { + std::vector> slots = getEquipmentSlots(); + for (int i = 0; i < (int)slots.size(); i++) { if (slots[i] != nullptr && dropChances[i] <= 1) { result += 1 + random->nextInt(3); } @@ -222,7 +220,7 @@ void Mob::addAdditonalSaveData(CompoundTag* entityTag) { entityTag->putBoolean(L"PersistenceRequired", persistenceRequired); ListTag* gear = new ListTag(); - for (int i = 0; i < equipment.length; i++) { + for (int i = 0; i < equipment.size(); i++) { CompoundTag* tag = new CompoundTag(); if (equipment[i] != nullptr) equipment[i]->save(tag); gear->add(tag); @@ -230,7 +228,7 @@ void Mob::addAdditonalSaveData(CompoundTag* entityTag) { entityTag->put(L"Equipment", gear); ListTag* dropChanceList = new ListTag(); - for (int i = 0; i < dropChances.length; i++) { + for (int i = 0; i < dropChances.size(); i++) { dropChanceList->add(new FloatTag(_toString(i), dropChances[i])); } entityTag->put(L"DropChances", dropChanceList); @@ -270,7 +268,7 @@ void Mob::readAdditionalSaveData(CompoundTag* tag) { ListTag* gear = (ListTag*)tag->getList(L"Equipment"); - for (int i = 0; i < equipment.length; i++) { + for (int i = 0; i < equipment.size(); i++) { equipment[i] = ItemInstance::fromTag(gear->get(i)); } } @@ -563,10 +561,10 @@ void Mob::setEquippedSlot(int slot, std::shared_ptr item) { equipment[slot] = item; } -arrayWithLength> Mob::getEquipmentSlots() { return equipment; } +std::vector> Mob::getEquipmentSlots() { return equipment; } void Mob::dropEquipment(bool byPlayer, int playerBonusLevel) { - for (int slot = 0; slot < getEquipmentSlots().length; slot++) { + for (int slot = 0; slot < (int)getEquipmentSlots().size(); slot++) { std::shared_ptr item = getCarried(slot); bool preserve = dropChances[slot] > 1; diff --git a/minecraft/Minecraft.World/net/minecraft/world/entity/Mob.h b/minecraft/Minecraft.World/net/minecraft/world/entity/Mob.h index 6f80d5d51..5761346b2 100644 --- a/minecraft/Minecraft.World/net/minecraft/world/entity/Mob.h +++ b/minecraft/Minecraft.World/net/minecraft/world/entity/Mob.h @@ -59,10 +59,10 @@ private: std::shared_ptr target; Sensing* sensing; - arrayWithLength> equipment; + std::vector> equipment; protected: - floatArray dropChances; + std::vector dropChances; private: bool _canPickUpLoot; @@ -158,7 +158,7 @@ public: virtual std::shared_ptr getCarried(int slot); virtual std::shared_ptr getArmor(int pos); virtual void setEquippedSlot(int slot, std::shared_ptr item); - virtual arrayWithLength> getEquipmentSlots(); + virtual std::vector> getEquipmentSlots(); protected: virtual void dropEquipment(bool byPlayer, int playerBonusLevel); diff --git a/minecraft/Minecraft.World/net/minecraft/world/entity/MobCategory.cpp b/minecraft/Minecraft.World/net/minecraft/world/entity/MobCategory.cpp index b744784f9..e9b0cc550 100644 --- a/minecraft/Minecraft.World/net/minecraft/world/entity/MobCategory.cpp +++ b/minecraft/Minecraft.World/net/minecraft/world/entity/MobCategory.cpp @@ -14,7 +14,7 @@ MobCategory* MobCategory::creature_wolf = nullptr; MobCategory* MobCategory::creature_chicken = nullptr; MobCategory* MobCategory::creature_mushroomcow = nullptr; -MobCategoryArray MobCategory::values = MobCategoryArray(7); +std::vector MobCategory::values = std::vector(7); void MobCategory::staticCtor() { // 4J - adjusted the max levels here for the xbox version, which now diff --git a/minecraft/Minecraft.World/net/minecraft/world/entity/MobCategory.h b/minecraft/Minecraft.World/net/minecraft/world/entity/MobCategory.h index 9a53c87b6..a8348c443 100644 --- a/minecraft/Minecraft.World/net/minecraft/world/entity/MobCategory.h +++ b/minecraft/Minecraft.World/net/minecraft/world/entity/MobCategory.h @@ -90,7 +90,7 @@ public: // 4J Stu Sometimes we want to access the values by name, other times // iterate over all values Added these arrays so we can static initialise a // collection which we can iterate over - static MobCategoryArray values; + static std::vector values; private: const int m_max; diff --git a/minecraft/Minecraft.World/net/minecraft/world/entity/animal/EntityHorse.cpp b/minecraft/Minecraft.World/net/minecraft/world/entity/animal/EntityHorse.cpp index 1f021d109..a17f3ea77 100644 --- a/minecraft/Minecraft.World/net/minecraft/world/entity/animal/EntityHorse.cpp +++ b/minecraft/Minecraft.World/net/minecraft/world/entity/animal/EntityHorse.cpp @@ -88,7 +88,7 @@ EntityHorse::EntityHorse(Level* level) : Animal(level) { layerTextureHashName = L""; - layerTextureLayers = intArray(3); + layerTextureLayers = std::vector(3); for (unsigned int i = 0; i < 3; ++i) { layerTextureLayers[i] = -1; } @@ -110,7 +110,6 @@ EntityHorse::EntityHorse(Level* level) : Animal(level) { createInventory(); } -EntityHorse::~EntityHorse() { delete[] layerTextureLayers.data; } void EntityHorse::defineSynchedData() { Animal::defineSynchedData(); @@ -631,7 +630,7 @@ std::wstring EntityHorse::getLayeredTextureHashName() { return layerTextureHashName; } -intArray EntityHorse::getLayeredTextureLayers() { +std::vector EntityHorse::getLayeredTextureLayers() { if (layerTextureHashName.empty()) { rebuildLayeredTextureInfo(); } diff --git a/minecraft/Minecraft.World/net/minecraft/world/entity/animal/EntityHorse.h b/minecraft/Minecraft.World/net/minecraft/world/entity/animal/EntityHorse.h index 1c8466184..d26ad017b 100644 --- a/minecraft/Minecraft.World/net/minecraft/world/entity/animal/EntityHorse.h +++ b/minecraft/Minecraft.World/net/minecraft/world/entity/animal/EntityHorse.h @@ -123,7 +123,7 @@ private: public: EntityHorse(Level* world); - ~EntityHorse(); + ~EntityHorse() = default; protected: virtual void defineSynchedData(); @@ -231,7 +231,7 @@ public: private: std::wstring layerTextureHashName; - intArray layerTextureLayers; + std::vector layerTextureLayers; private: virtual void clearLayeredTextureInfo(); @@ -239,7 +239,7 @@ private: public: virtual std::wstring getLayeredTextureHashName(); - virtual intArray getLayeredTextureLayers(); + virtual std::vector getLayeredTextureLayers(); virtual void openInventory(std::shared_ptr player); virtual bool mobInteract(std::shared_ptr player); diff --git a/minecraft/Minecraft.World/net/minecraft/world/entity/boss/enderdragon/EnderDragon.cpp b/minecraft/Minecraft.World/net/minecraft/world/entity/boss/enderdragon/EnderDragon.cpp index 7c00d8bbe..c5a87a915 100644 --- a/minecraft/Minecraft.World/net/minecraft/world/entity/boss/enderdragon/EnderDragon.cpp +++ b/minecraft/Minecraft.World/net/minecraft/world/entity/boss/enderdragon/EnderDragon.cpp @@ -82,7 +82,7 @@ void EnderDragon::_init() { positions[i][2] = 0; } - m_nodes = new NodeArray(24); + m_nodes = new std::vector(24); openSet = new BinaryHeap(); m_currentPath = nullptr; } @@ -141,11 +141,11 @@ void EnderDragon::AddParts() { } EnderDragon::~EnderDragon() { - if (m_nodes->data != nullptr) { - for (unsigned int i = 0; i < m_nodes->length; ++i) { - if (m_nodes->data[i] != nullptr) delete m_nodes->data[i]; + if (m_nodes != nullptr) { + for (unsigned int i = 0; i < m_nodes->size(); ++i) { + if ((*m_nodes)[i] != nullptr) delete (*m_nodes)[i]; } - delete[] m_nodes->data; + delete m_nodes; } delete openSet; if (m_currentPath != nullptr) delete m_currentPath; @@ -165,7 +165,7 @@ void EnderDragon::defineSynchedData() { e_EnderdragonAction_HoldingPattern); } -void EnderDragon::getLatencyPos(doubleArray result, int step, float a) { +void EnderDragon::getLatencyPos(std::vector& result, int step, float a) { if (getHealth() <= 0) { a = 0; } @@ -617,8 +617,8 @@ void EnderDragon::aiStep() { wing2->bbWidth = 4; // double latencyPosAcomponents[3],latencyPosBcomponents[3]; - // doubleArray latencyPosA = doubleArray(latencyPosAcomponents,3); - // doubleArray latencyPosB = doubleArray(latencyPosBcomponents,3); + // std::vector latencyPosA = std::vector(latencyPosAcomponents,3); + // std::vector latencyPosB = std::vector(latencyPosBcomponents,3); // getLatencyPos(latencyPosA, 5, 1); // getLatencyPos(latencyPosB, 10, 1); @@ -657,12 +657,12 @@ void EnderDragon::aiStep() { } double p1components[3]; - doubleArray p1 = doubleArray(p1components, 3); + std::vector p1 = std::vector(p1components, p1components + 3); getLatencyPos(p1, 5, 1); { // double p0components[3]; - // doubleArray p0 = doubleArray(p0components, 3); + // std::vector p0 = std::vector(p0components, p0components + 3); // getLatencyPos(p0, 0, 1); double yRotDiff = getHeadYRotDiff(1); @@ -712,7 +712,7 @@ void EnderDragon::aiStep() { if (i == 2) part = tail3; double p0components[3]; - doubleArray p0 = doubleArray(p0components, 3); + std::vector p0 = std::vector(p0components, p0components + 3); getLatencyPos(p0, 12 + i * 2, 1); float rot = yRot * M_PI / 180 + rotWrap(p0[0] - p1[0]) * M_PI / 180 * (1); @@ -1516,7 +1516,7 @@ void EnderDragon::navigateToNextPathNode() { int EnderDragon::findClosestNode() { // Setup all the nodes on the first time this is called - if (m_nodes->data[0] == nullptr) { + if ((*m_nodes)[0] == nullptr) { // Path nodes for navigation // 0 - 11 are the outer ring at 60 blocks from centre // 12 - 19 are the middle ring at 40 blocks from centre @@ -1551,7 +1551,7 @@ int EnderDragon::findClosestNode() { app.DebugPrintf("Node %d is at (%d,%d,%d)\n", i, nodeX, nodeY, nodeZ); - m_nodes->data[i] = new Node(nodeX, nodeY, nodeZ); + (*m_nodes)[i] = new Node(nodeX, nodeY, nodeZ); // level->setTile(nodeX,nodeY,nodeZ,Tile::obsidian_Id); } @@ -1606,8 +1606,8 @@ int EnderDragon::findClosestNode(double tX, double tY, double tZ) { startIndex = 12; } for (unsigned int i = startIndex; i < 24; ++i) { - if (m_nodes->data[i] != nullptr) { - float dist = m_nodes->data[i]->distanceTo(currentPos); + if ((*m_nodes)[i] != nullptr) { + float dist = (*m_nodes)[i]->distanceTo(currentPos); if (dist < closestDist) { closestDist = dist; closestIndex = i; @@ -1622,7 +1622,7 @@ int EnderDragon::findClosestNode(double tX, double tY, double tZ) { Path* EnderDragon::findPath(int startIndex, int endIndex, Node* finalNode /* = nullptr */) { for (unsigned int i = 0; i < 24; ++i) { - Node* n = m_nodes->data[i]; + Node* n = (*m_nodes)[i]; n->closed = false; n->f = 0; n->g = 0; @@ -1631,8 +1631,8 @@ Path* EnderDragon::findPath(int startIndex, int endIndex, n->heapIdx = -1; } - Node* from = m_nodes->data[startIndex]; - Node* to = m_nodes->data[endIndex]; + Node* from = (*m_nodes)[startIndex]; + Node* to = (*m_nodes)[endIndex]; from->g = 0; from->h = from->distanceTo(to); @@ -1669,7 +1669,7 @@ Path* EnderDragon::findPath(int startIndex, int endIndex, unsigned int xIndex = 0; for (unsigned int i = 0; i < 24; ++i) { - if (m_nodes->data[i] == x) { + if ((*m_nodes)[i] == x) { xIndex = i; break; } @@ -1677,7 +1677,7 @@ Path* EnderDragon::findPath(int startIndex, int endIndex, for (int i = minimumNodeIndex; i < 24; i++) { if (m_nodeAdjacency[xIndex] & (1 << i)) { - Node* y = m_nodes->data[i]; + Node* y = (*m_nodes)[i]; if (y->closed) continue; @@ -1716,15 +1716,14 @@ Path* EnderDragon::reconstruct_path(Node* from, Node* to) { n = n->cameFrom; } - NodeArray nodes = NodeArray(count); + std::vector nodes = std::vector(count); n = to; - nodes.data[--count] = n; + nodes.data()[--count] = n; while (n->cameFrom != nullptr) { n = n->cameFrom; - nodes.data[--count] = n; + nodes.data()[--count] = n; } Path* ret = new Path(nodes); - delete[] nodes.data; return ret; } @@ -1760,8 +1759,8 @@ float EnderDragon::getTilt(float a) { // else { double latencyPosAcomponents[3], latencyPosBcomponents[3]; - doubleArray latencyPosA = doubleArray(latencyPosAcomponents, 3); - doubleArray latencyPosB = doubleArray(latencyPosBcomponents, 3); + std::vector latencyPosA = std::vector(latencyPosAcomponents, latencyPosAcomponents + 3); + std::vector latencyPosB = std::vector(latencyPosBcomponents, latencyPosBcomponents + 3); getLatencyPos(latencyPosA, 5, a); getLatencyPos(latencyPosB, 10, a); @@ -1780,11 +1779,11 @@ double EnderDragon::getHeadYOffset(float a) { headYOffset = -1.0; } else { double p1components[3]; - doubleArray p1 = doubleArray(p1components, 3); + std::vector p1 = std::vector(p1components, p1components + 3); getLatencyPos(p1, 5, 1); double p0components[3]; - doubleArray p0 = doubleArray(p0components, 3); + std::vector p0 = std::vector(p0components, p0components + 3); getLatencyPos(p0, 0, 1); headYOffset = (p0[1] - p1[1]) * 1; @@ -1804,8 +1803,8 @@ double EnderDragon::getHeadYRotDiff(float a) { return result; } -double EnderDragon::getHeadPartYOffset(int partIndex, doubleArray bodyPos, - doubleArray partPos) { +double EnderDragon::getHeadPartYOffset(int partIndex, std::vector& bodyPos, + std::vector& partPos) { double result = 0.0; if (getSynchedAction() == e_EnderdragonAction_Landing || getSynchedAction() == e_EnderdragonAction_Takeoff) { @@ -1832,8 +1831,8 @@ double EnderDragon::getHeadPartYOffset(int partIndex, doubleArray bodyPos, return result; } -double EnderDragon::getHeadPartYRotDiff(int partIndex, doubleArray bodyPos, - doubleArray partPos) { +double EnderDragon::getHeadPartYRotDiff(int partIndex, std::vector& bodyPos, + std::vector& partPos) { double result = 0.0; // if( getSynchedAction() == e_EnderdragonAction_Sitting_Flaming || // getSynchedAction() == e_EnderdragonAction_Sitting_Scanning || diff --git a/minecraft/Minecraft.World/net/minecraft/world/entity/boss/enderdragon/EnderDragon.h b/minecraft/Minecraft.World/net/minecraft/world/entity/boss/enderdragon/EnderDragon.h index 62f680cfb..ebed54402 100644 --- a/minecraft/Minecraft.World/net/minecraft/world/entity/boss/enderdragon/EnderDragon.h +++ b/minecraft/Minecraft.World/net/minecraft/world/entity/boss/enderdragon/EnderDragon.h @@ -61,7 +61,7 @@ private: double m_headYRot; AABB m_acidArea; - NodeArray* m_nodes; + std::vector* m_nodes; int m_nodeAdjacency[24]; BinaryHeap* openSet; Path* m_currentPath; @@ -123,7 +123,7 @@ protected: virtual void defineSynchedData(); public: - void getLatencyPos(doubleArray result, int step, float a); + void getLatencyPos(std::vector& result, int step, float a); virtual void aiStep(); private: @@ -184,10 +184,10 @@ public: float getTilt(float a); double getHeadYOffset(float a); double getHeadYRotDiff(float a); - double getHeadPartYOffset(int partIndex, doubleArray bodyPos, - doubleArray partPos); - double getHeadPartYRotDiff(int partIndex, doubleArray bodyPos, - doubleArray partPos); + double getHeadPartYOffset(int partIndex, std::vector& bodyPos, + std::vector& partPos); + double getHeadPartYRotDiff(int partIndex, std::vector& bodyPos, + std::vector& partPos); Vec3 getHeadLookVector(float a); virtual std::wstring getAName() { return app.GetString(IDS_ENDERDRAGON); }; diff --git a/minecraft/Minecraft.World/net/minecraft/world/entity/item/MinecartContainer.cpp b/minecraft/Minecraft.World/net/minecraft/world/entity/item/MinecartContainer.cpp index 101291085..bdfa012f9 100644 --- a/minecraft/Minecraft.World/net/minecraft/world/entity/item/MinecartContainer.cpp +++ b/minecraft/Minecraft.World/net/minecraft/world/entity/item/MinecartContainer.cpp @@ -7,7 +7,7 @@ #include "MinecartContainer.h" void MinecartContainer::_init() { - items = arrayWithLength>(9 * 4); + items = std::vector>(9 * 4); dropEquipment = true; // 4J Stu - This function call had to be moved here from the Entity ctor to @@ -164,7 +164,7 @@ void MinecartContainer::addAdditonalSaveData(CompoundTag* base) { ListTag* listTag = new ListTag(); - for (int i = 0; i < items.length; i++) { + for (int i = 0; i < items.size(); i++) { if (items[i] != nullptr) { CompoundTag* tag = new CompoundTag(); tag->putByte(L"Slot", (uint8_t)i); @@ -180,12 +180,11 @@ void MinecartContainer::readAdditionalSaveData(CompoundTag* base) { ListTag* inventoryList = (ListTag*)base->getList(L"Items"); - delete[] items.data; - items = arrayWithLength>(getContainerSize()); + items = std::vector>(getContainerSize()); for (int i = 0; i < inventoryList->size(); i++) { CompoundTag* tag = inventoryList->get(i); int slot = tag->getByte(L"Slot") & 0xff; - if (slot >= 0 && slot < items.length) + if (slot >= 0 && slot < (int)items.size()) items[slot] = ItemInstance::fromTag(tag); } } diff --git a/minecraft/Minecraft.World/net/minecraft/world/entity/item/MinecartContainer.h b/minecraft/Minecraft.World/net/minecraft/world/entity/item/MinecartContainer.h index 2b4595fec..e7555763e 100644 --- a/minecraft/Minecraft.World/net/minecraft/world/entity/item/MinecartContainer.h +++ b/minecraft/Minecraft.World/net/minecraft/world/entity/item/MinecartContainer.h @@ -5,7 +5,7 @@ class MinecartContainer : public Minecart, public virtual Container { private: - arrayWithLength> items; + std::vector> items; bool dropEquipment; void _init(); diff --git a/minecraft/Minecraft.World/net/minecraft/world/entity/player/Inventory.cpp b/minecraft/Minecraft.World/net/minecraft/world/entity/player/Inventory.cpp index ae2bcc920..70190392a 100644 --- a/minecraft/Minecraft.World/net/minecraft/world/entity/player/Inventory.cpp +++ b/minecraft/Minecraft.World/net/minecraft/world/entity/player/Inventory.cpp @@ -17,8 +17,8 @@ const int Inventory::SELECTION_SIZE = 9; // we don't want to also keep a shared_ptr of it. If we pass it on we should use // shared_from_this() though Inventory::Inventory(Player* player) { - items = arrayWithLength>(INVENTORY_SIZE); - armor = arrayWithLength>(4); + items = std::vector>(INVENTORY_SIZE); + armor = std::vector>(4); selected = 0; @@ -30,8 +30,6 @@ Inventory::Inventory(Player* player) { } Inventory::~Inventory() { - delete[] items.data; - delete[] armor.data; } std::shared_ptr Inventory::getSelected() { @@ -56,14 +54,14 @@ bool Inventory::IsHeldItem() { int Inventory::getSelectionSize() { return SELECTION_SIZE; } int Inventory::getSlot(int tileId) { - for (unsigned int i = 0; i < items.length; i++) { + for (unsigned int i = 0; i < items.size(); i++) { if (items[i] != nullptr && items[i]->id == tileId) return i; } return -1; } int Inventory::getSlot(int tileId, int data) { - for (int i = 0; i < items.length; i++) { + for (int i = 0; i < items.size(); i++) { if (items[i] != nullptr && items[i]->id == tileId && items[i]->getAuxValue() == data) return i; @@ -72,7 +70,7 @@ int Inventory::getSlot(int tileId, int data) { } int Inventory::getSlotWithRemainingSpace(std::shared_ptr item) { - for (unsigned int i = 0; i < items.length; i++) { + for (unsigned int i = 0; i < items.size(); i++) { if (items[i] != nullptr && items[i]->id == item->id && items[i]->isStackable() && items[i]->count < items[i]->getMaxStackSize() && @@ -87,7 +85,7 @@ int Inventory::getSlotWithRemainingSpace(std::shared_ptr item) { } int Inventory::getFreeSlot() { - for (unsigned int i = 0; i < items.length; i++) { + for (unsigned int i = 0; i < items.size(); i++) { if (items[i] == nullptr) return i; } return -1; @@ -130,7 +128,7 @@ void Inventory::swapPaint(int wheel) { int Inventory::clearInventory(int id, int data) { int count = 0; - for (int i = 0; i < items.length; i++) { + for (int i = 0; i < items.size(); i++) { std::shared_ptr item = items[i]; if (item == nullptr) continue; if (id > -1 && item->id != id) continue; @@ -139,7 +137,7 @@ int Inventory::clearInventory(int id, int data) { count += item->count; items[i] = nullptr; } - for (int i = 0; i < armor.length; i++) { + for (int i = 0; i < armor.size(); i++) { std::shared_ptr item = armor[i]; if (item == nullptr) continue; if (id > -1 && item->id != id) continue; @@ -227,7 +225,7 @@ int Inventory::addResource(std::shared_ptr itemInstance) { } void Inventory::tick() { - for (unsigned int i = 0; i < items.length; i++) { + for (unsigned int i = 0; i < items.size(); i++) { if (items[i] != nullptr) { items[i]->inventoryTick(player->level, player->shared_from_this(), i, selected == i); @@ -255,7 +253,7 @@ void Inventory::removeResources(std::shared_ptr item) { if (item == nullptr) return; int countToRemove = item->count; - for (unsigned int i = 0; i < items.length; i++) { + for (unsigned int i = 0; i < items.size(); i++) { if (items[i] != nullptr && items[i]->sameItemWithTags(item)) { int slotCount = items[i]->count; items[i]->count -= countToRemove; @@ -344,10 +342,9 @@ bool Inventory::add(std::shared_ptr item) { std::shared_ptr Inventory::removeItem(unsigned int slot, int count) { - arrayWithLength> pile = items; - if (slot >= items.length) { - pile = armor; - slot -= items.length; + std::vector>& pile = (slot >= items.size()) ? armor : items; + if (slot >= items.size()) { + slot -= items.size(); } if (pile[slot] != nullptr) { @@ -365,10 +362,9 @@ std::shared_ptr Inventory::removeItem(unsigned int slot, } std::shared_ptr Inventory::removeItemNoUpdate(int slot) { - arrayWithLength> pile = items; - if (slot >= items.length) { - pile = armor; - slot -= items.length; + std::vector>& pile = (slot >= (int)items.size()) ? armor : items; + if (slot >= (int)items.size()) { + slot -= items.size(); } if (pile[slot] != nullptr) { @@ -396,17 +392,17 @@ void Inventory::setItem(unsigned int slot, std::shared_ptr item) { } #endif // 4J Stu - Changed this a little from Java to be less funn - if (slot >= items.length) { - armor[slot - items.length] = item; + if (slot >= items.size()) { + armor[slot - items.size()] = item; } else { items[slot] = item; } player->handleCollectItem(item); /* - arrayWithLength>& pile = items; - if (slot >= pile.length) + std::vector>& pile = items; + if (slot >= pile.size()) { - slot -= pile.length; + slot -= pile.size(); pile = armor; } @@ -422,7 +418,7 @@ float Inventory::getDestroySpeed(Tile* tile) { } ListTag* Inventory::save(ListTag* listTag) { - for (unsigned int i = 0; i < items.length; i++) { + for (unsigned int i = 0; i < items.size(); i++) { if (items[i] != nullptr) { CompoundTag* tag = new CompoundTag(); tag->putByte(L"Slot", (uint8_t)i); @@ -430,7 +426,7 @@ ListTag* Inventory::save(ListTag* listTag) { listTag->add(tag); } } - for (unsigned int i = 0; i < armor.length; i++) { + for (unsigned int i = 0; i < armor.size(); i++) { if (armor[i] != nullptr) { CompoundTag* tag = new CompoundTag(); tag->putByte(L"Slot", (uint8_t)(i + 100)); @@ -442,43 +438,37 @@ ListTag* Inventory::save(ListTag* listTag) { } void Inventory::load(ListTag* inventoryList) { - if (items.data != nullptr) { - delete[] items.data; - items.data = nullptr; - } - if (armor.data != nullptr) { - delete[] armor.data; - armor.data = nullptr; - } - items = arrayWithLength>(INVENTORY_SIZE); - armor = arrayWithLength>(4); + items.clear(); + armor.clear(); + items = std::vector>(INVENTORY_SIZE); + armor = std::vector>(4); for (int i = 0; i < inventoryList->size(); i++) { CompoundTag* tag = inventoryList->get(i); unsigned int slot = tag->getByte(L"Slot") & 0xff; std::shared_ptr item = std::shared_ptr(ItemInstance::fromTag(tag)); if (item != nullptr) { - if (slot >= 0 && slot < items.length) items[slot] = item; - if (slot >= 100 && slot < armor.length + 100) + if (slot >= 0 && slot < items.size()) items[slot] = item; + if (slot >= 100 && slot < armor.size() + 100) armor[slot - 100] = item; } } } -unsigned int Inventory::getContainerSize() { return items.length + 4; } +unsigned int Inventory::getContainerSize() { return items.size() + 4; } std::shared_ptr Inventory::getItem(unsigned int slot) { // 4J Stu - Changed this a little from the Java so it's less funny - if (slot >= items.length) { - return armor[slot - items.length]; + if (slot >= items.size()) { + return armor[slot - items.size()]; } else { return items[slot]; } /* - arrayWithLength> pile = items; - if (slot >= pile.length) + std::vector> pile = items; + if (slot >= pile.size()) { - slot -= pile.length; + slot -= pile.size(); pile = armor; } @@ -508,7 +498,7 @@ std::shared_ptr Inventory::getArmor(int layer) { int Inventory::getArmorValue() { int val = 0; - for (unsigned int i = 0; i < armor.length; i++) { + for (unsigned int i = 0; i < armor.size(); i++) { if (armor[i] != nullptr && dynamic_cast(armor[i]->getItem()) != nullptr) { int baseProtection = @@ -525,7 +515,7 @@ void Inventory::hurtArmor(float dmg) { if (dmg < 1) { dmg = 1; } - for (unsigned int i = 0; i < armor.length; i++) { + for (unsigned int i = 0; i < armor.size(); i++) { if (armor[i] != nullptr && dynamic_cast(armor[i]->getItem()) != nullptr) { armor[i]->hurtAndBreak((int)dmg, @@ -539,13 +529,13 @@ void Inventory::hurtArmor(float dmg) { } void Inventory::dropAll() { - for (unsigned int i = 0; i < items.length; i++) { + for (unsigned int i = 0; i < items.size(); i++) { if (items[i] != nullptr) { player->drop(items[i], true); items[i] = nullptr; } } - for (unsigned int i = 0; i < armor.length; i++) { + for (unsigned int i = 0; i < armor.size(); i++) { if (armor[i] != nullptr) { player->drop(armor[i], true); armor[i] = nullptr; @@ -556,10 +546,10 @@ void Inventory::dropAll() { void Inventory::setChanged() { changed = true; } bool Inventory::isSame(std::shared_ptr copy) { - for (unsigned int i = 0; i < items.length; i++) { + for (unsigned int i = 0; i < items.size(); i++) { if (!isSame(copy->items[i], items[i])) return false; } - for (unsigned int i = 0; i < armor.length; i++) { + for (unsigned int i = 0; i < armor.size(); i++) { if (!isSame(copy->armor[i], armor[i])) return false; } return true; @@ -577,10 +567,10 @@ bool Inventory::isSame(std::shared_ptr a, std::shared_ptr Inventory::copy() { std::shared_ptr copy = std::shared_ptr(new Inventory(nullptr)); - for (unsigned int i = 0; i < items.length; i++) { + for (unsigned int i = 0; i < items.size(); i++) { copy->items[i] = items[i] != nullptr ? items[i]->copy() : nullptr; } - for (unsigned int i = 0; i < armor.length; i++) { + for (unsigned int i = 0; i < armor.size(); i++) { copy->armor[i] = armor[i] != nullptr ? armor[i]->copy() : nullptr; } return copy; @@ -601,11 +591,11 @@ bool Inventory::stillValid(std::shared_ptr player) { } bool Inventory::contains(std::shared_ptr itemInstance) { - for (unsigned int i = 0; i < armor.length; i++) { + for (unsigned int i = 0; i < armor.size(); i++) { if (armor[i] != nullptr && armor[i]->sameItem(itemInstance)) return true; } - for (unsigned int i = 0; i < items.length; i++) { + for (unsigned int i = 0; i < items.size(); i++) { if (items[i] != nullptr && items[i]->sameItem(itemInstance)) return true; } @@ -625,10 +615,10 @@ bool Inventory::canPlaceItem(int slot, std::shared_ptr item) { } void Inventory::replaceWith(std::shared_ptr other) { - for (int i = 0; i < items.length; i++) { + for (int i = 0; i < items.size(); i++) { items[i] = ItemInstance::clone(other->items[i]); } - for (int i = 0; i < armor.length; i++) { + for (int i = 0; i < armor.size(); i++) { armor[i] = ItemInstance::clone(other->armor[i]); } @@ -638,12 +628,12 @@ void Inventory::replaceWith(std::shared_ptr other) { int Inventory::countMatches(std::shared_ptr itemInstance) { if (itemInstance == nullptr) return 0; int count = 0; - // for (unsigned int i = 0; i < armor.length; i++) + // for (unsigned int i = 0; i < armor.size(); i++) //{ // if (armor[i] != nullptr && armor[i]->sameItem(itemInstance)) count += // items[i]->count; // } - for (unsigned int i = 0; i < items.length; i++) { + for (unsigned int i = 0; i < items.size(); i++) { if (items[i] != nullptr && items[i]->sameItemWithTags(itemInstance)) count += items[i]->count; } diff --git a/minecraft/Minecraft.World/net/minecraft/world/entity/player/Inventory.h b/minecraft/Minecraft.World/net/minecraft/world/entity/player/Inventory.h index 8d3dc01cd..7e1b308a1 100644 --- a/minecraft/Minecraft.World/net/minecraft/world/entity/player/Inventory.h +++ b/minecraft/Minecraft.World/net/minecraft/world/entity/player/Inventory.h @@ -16,8 +16,8 @@ private: static const int SELECTION_SIZE; public: - arrayWithLength> items; - arrayWithLength> armor; + std::vector> items; + std::vector> armor; int selected; Player* player; // This is owned by shared_ptrs, but we are owned by it diff --git a/minecraft/Minecraft.World/net/minecraft/world/entity/player/Player.cpp b/minecraft/Minecraft.World/net/minecraft/world/entity/player/Player.cpp index 47858f8d6..87a75220f 100644 --- a/minecraft/Minecraft.World/net/minecraft/world/entity/player/Player.cpp +++ b/minecraft/Minecraft.World/net/minecraft/world/entity/player/Player.cpp @@ -1191,12 +1191,12 @@ int Player::getArmorValue() { return inventory->getArmorValue(); } float Player::getArmorCoverPercentage() { int count = 0; - for (int i = 0; i < inventory->armor.length; i++) { + for (int i = 0; i < inventory->armor.size(); i++) { if (inventory->armor[i] != nullptr) { count++; } } - return (float)count / (float)inventory->armor.length; + return (float)count / (float)inventory->armor.size(); } void Player::actuallyHurt(DamageSource* source, float dmg) { @@ -1716,10 +1716,8 @@ void Player::setRespawnPosition(Pos* respawnPosition, bool forced) { } } -void Player::awardStat(Stat* stat, byteArray paramBlob) { - if (paramBlob.data != nullptr) { - delete[] paramBlob.data; - } +void Player::awardStat(Stat* stat, const std::vector& paramBlob) { + // Intentionally empty - base implementation does nothing } void Player::jumpFromGround() { @@ -2200,7 +2198,7 @@ bool Player::isInvisibleTo(std::shared_ptr player) { return isInvisible(); } -arrayWithLength> Player::getEquipmentSlots() { return inventory->armor; } +std::vector> Player::getEquipmentSlots() { return inventory->armor; } bool Player::isCapeHidden() { return getPlayerFlag(FLAG_HIDE_CAPE); } diff --git a/minecraft/Minecraft.World/net/minecraft/world/entity/player/Player.h b/minecraft/Minecraft.World/net/minecraft/world/entity/player/Player.h index 15bb74aa6..005c77a79 100644 --- a/minecraft/Minecraft.World/net/minecraft/world/entity/player/Player.h +++ b/minecraft/Minecraft.World/net/minecraft/world/entity/player/Player.h @@ -349,7 +349,7 @@ public: virtual Pos* getRespawnPosition(); virtual bool isRespawnForced(); virtual void setRespawnPosition(Pos* respawnPosition, bool forced); - virtual void awardStat(Stat* stat, byteArray param); + virtual void awardStat(Stat* stat, const std::vector& param); protected: void jumpFromGround(); @@ -414,7 +414,7 @@ public: virtual std::shared_ptr getCarriedItem(); virtual void setEquippedSlot(int slot, std::shared_ptr item); virtual bool isInvisibleTo(std::shared_ptr player); - virtual arrayWithLength> getEquipmentSlots(); + virtual std::vector> getEquipmentSlots(); virtual bool isCapeHidden(); virtual bool isPushedByWater(); virtual Scoreboard* getScoreboard(); diff --git a/minecraft/Minecraft.World/net/minecraft/world/inventory/AbstractContainerMenu.cpp b/minecraft/Minecraft.World/net/minecraft/world/inventory/AbstractContainerMenu.cpp index 49648b898..44b620784 100644 --- a/minecraft/Minecraft.World/net/minecraft/world/inventory/AbstractContainerMenu.cpp +++ b/minecraft/Minecraft.World/net/minecraft/world/inventory/AbstractContainerMenu.cpp @@ -501,8 +501,8 @@ void AbstractContainerMenu::setItem(unsigned int slot, getSlot(slot)->set(item); } -void AbstractContainerMenu::setAll(arrayWithLength>* items) { - for (unsigned int i = 0; i < items->length; i++) { +void AbstractContainerMenu::setAll(std::vector>* items) { + for (unsigned int i = 0; i < items->size(); i++) { getSlot(i)->set((*items)[i]); } } diff --git a/minecraft/Minecraft.World/net/minecraft/world/inventory/AbstractContainerMenu.h b/minecraft/Minecraft.World/net/minecraft/world/inventory/AbstractContainerMenu.h index 7fd0b48bc..f14d9375a 100644 --- a/minecraft/Minecraft.World/net/minecraft/world/inventory/AbstractContainerMenu.h +++ b/minecraft/Minecraft.World/net/minecraft/world/inventory/AbstractContainerMenu.h @@ -90,7 +90,7 @@ public: // but wasn't using it, so removed to simplify things bool isPauseScreen(); void setItem(unsigned int slot, std::shared_ptr item); - void setAll(arrayWithLength>* items); + void setAll(std::vector>* items); virtual void setData(int id, int value); short backup(std::shared_ptr inventory); diff --git a/minecraft/Minecraft.World/net/minecraft/world/inventory/CraftingContainer.cpp b/minecraft/Minecraft.World/net/minecraft/world/inventory/CraftingContainer.cpp index 1de581167..ec78d54ea 100644 --- a/minecraft/Minecraft.World/net/minecraft/world/inventory/CraftingContainer.cpp +++ b/minecraft/Minecraft.World/net/minecraft/world/inventory/CraftingContainer.cpp @@ -9,12 +9,12 @@ CraftingContainer::~CraftingContainer() {} CraftingContainer::CraftingContainer(AbstractContainerMenu* menu, unsigned int w, unsigned int h) { unsigned int size = w * h; - items = new arrayWithLength>(size); + items = new std::vector>(size); this->menu = menu; this->width = w; } -unsigned int CraftingContainer::getContainerSize() { return items->length; } +unsigned int CraftingContainer::getContainerSize() { return items->size(); } std::shared_ptr CraftingContainer::getItem(unsigned int slot) { if (slot >= getContainerSize()) { diff --git a/minecraft/Minecraft.World/net/minecraft/world/inventory/CraftingContainer.h b/minecraft/Minecraft.World/net/minecraft/world/inventory/CraftingContainer.h index 911e8dbd8..732d2bbcd 100644 --- a/minecraft/Minecraft.World/net/minecraft/world/inventory/CraftingContainer.h +++ b/minecraft/Minecraft.World/net/minecraft/world/inventory/CraftingContainer.h @@ -6,7 +6,7 @@ class AbstractContainerMenu; class CraftingContainer : public Container { private: - arrayWithLength>* items; + std::vector>* items; unsigned int width; AbstractContainerMenu* menu; diff --git a/minecraft/Minecraft.World/net/minecraft/world/inventory/MenuBackup.cpp b/minecraft/Minecraft.World/net/minecraft/world/inventory/MenuBackup.cpp index 1c4a0e60a..3083a37ed 100644 --- a/minecraft/Minecraft.World/net/minecraft/world/inventory/MenuBackup.cpp +++ b/minecraft/Minecraft.World/net/minecraft/world/inventory/MenuBackup.cpp @@ -7,15 +7,15 @@ MenuBackup::MenuBackup(std::shared_ptr inventory, AbstractContainerMenu* menu) { - backups = new std::unordered_map>*>(); + backups = new std::unordered_map>*>(); this->inventory = inventory; this->menu = menu; } void MenuBackup::save(short changeUid) { - arrayWithLength>* backup = - new arrayWithLength>((int)menu->slots.size() + 1); + std::vector>* backup = + new std::vector>((int)menu->slots.size() + 1); (*backup)[0] = ItemInstance::clone(inventory->getCarried()); for (unsigned int i = 0; i < menu->slots.size(); i++) { (*backup)[i + 1] = ItemInstance::clone(menu->slots.at(i)->getItem()); @@ -33,7 +33,7 @@ void MenuBackup::deleteBackup(short changeUid) { } void MenuBackup::rollback(short changeUid) { - arrayWithLength>* backup = backups->at(changeUid); + std::vector>* backup = backups->at(changeUid); backups->clear(); inventory->setCarried((*backup)[0]); for (unsigned int i = 0; i < menu->slots.size(); i++) { diff --git a/minecraft/Minecraft.World/net/minecraft/world/inventory/MenuBackup.h b/minecraft/Minecraft.World/net/minecraft/world/inventory/MenuBackup.h index 36dfa4fd0..0941e7fff 100644 --- a/minecraft/Minecraft.World/net/minecraft/world/inventory/MenuBackup.h +++ b/minecraft/Minecraft.World/net/minecraft/world/inventory/MenuBackup.h @@ -5,7 +5,7 @@ class Inventory; class MenuBackup { private: - std::unordered_map>*>* backups; + std::unordered_map>*>* backups; std::shared_ptr inventory; AbstractContainerMenu* menu; diff --git a/minecraft/Minecraft.World/net/minecraft/world/inventory/MerchantContainer.cpp b/minecraft/Minecraft.World/net/minecraft/world/inventory/MerchantContainer.cpp index 8d26e501a..e466a99bc 100644 --- a/minecraft/Minecraft.World/net/minecraft/world/inventory/MerchantContainer.cpp +++ b/minecraft/Minecraft.World/net/minecraft/world/inventory/MerchantContainer.cpp @@ -3,11 +3,13 @@ #include "MerchantMenu.h" #include "MerchantContainer.h" +MerchantContainer::~MerchantContainer() {} + MerchantContainer::MerchantContainer(std::shared_ptr player, std::shared_ptr villager) { this->player = player; merchant = villager; - items = arrayWithLength>(3); + items = std::vector>(3); items[0] = nullptr; items[1] = nullptr; items[2] = nullptr; @@ -15,9 +17,8 @@ MerchantContainer::MerchantContainer(std::shared_ptr player, selectionHint = 0; } -MerchantContainer::~MerchantContainer() { delete[] items.data; } -unsigned int MerchantContainer::getContainerSize() { return items.length; } +unsigned int MerchantContainer::getContainerSize() { return items.size(); } std::shared_ptr MerchantContainer::getItem(unsigned int slot) { return items[slot]; diff --git a/minecraft/Minecraft.World/net/minecraft/world/inventory/MerchantContainer.h b/minecraft/Minecraft.World/net/minecraft/world/inventory/MerchantContainer.h index 63c8f5150..97fd4402a 100644 --- a/minecraft/Minecraft.World/net/minecraft/world/inventory/MerchantContainer.h +++ b/minecraft/Minecraft.World/net/minecraft/world/inventory/MerchantContainer.h @@ -1,7 +1,6 @@ #pragma once #include "../Container.h" -#include "../../../../ConsoleHelpers/ArrayWithLength.h" class Merchant; class Player; @@ -10,7 +9,7 @@ class MerchantRecipe; class MerchantContainer : public Container { private: std::shared_ptr merchant; - arrayWithLength> items; + std::vector> items; std::shared_ptr player; MerchantRecipe* activeRecipe; int selectionHint; diff --git a/minecraft/Minecraft.World/net/minecraft/world/item/ColoredTileItem.cpp b/minecraft/Minecraft.World/net/minecraft/world/item/ColoredTileItem.cpp index 7cf1225f1..ca75b9c19 100644 --- a/minecraft/Minecraft.World/net/minecraft/world/item/ColoredTileItem.cpp +++ b/minecraft/Minecraft.World/net/minecraft/world/item/ColoredTileItem.cpp @@ -12,8 +12,6 @@ ColoredTileItem::ColoredTileItem(int id, bool stackedByData) : TileItem(id) { } ColoredTileItem::~ColoredTileItem() { - if (descriptionPostfixes.data != nullptr) - delete[] descriptionPostfixes.data; } int ColoredTileItem::getColor(std::shared_ptr item, @@ -28,11 +26,10 @@ Icon* ColoredTileItem::getIcon(int auxValue) { int ColoredTileItem::getLevelDataForAuxValue(int auxValue) { return auxValue; } ColoredTileItem* ColoredTileItem::setDescriptionPostfixes( - intArray descriptionPostfixes) { - if (this->descriptionPostfixes.data != nullptr) - delete this->descriptionPostfixes.data; - this->descriptionPostfixes = intArray(descriptionPostfixes.length); - for (unsigned int i = 0; i < descriptionPostfixes.length; ++i) { + std::vector& descriptionPostfixes) { + this->descriptionPostfixes.clear(); + this->descriptionPostfixes = std::vector(descriptionPostfixes.size()); + for (unsigned int i = 0; i < descriptionPostfixes.size(); ++i) { this->descriptionPostfixes[i] = descriptionPostfixes[i]; } @@ -41,11 +38,11 @@ ColoredTileItem* ColoredTileItem::setDescriptionPostfixes( unsigned int ColoredTileItem::getDescriptionId( std::shared_ptr instance) { - if (descriptionPostfixes.data == nullptr) { + if (descriptionPostfixes.empty()) { return TileItem::getDescriptionId(instance); } int id = instance->getAuxValue(); - if (id >= 0 && id < descriptionPostfixes.length) { + if (id >= 0 && id < descriptionPostfixes.size()) { return descriptionPostfixes [id]; // TileItem::getDescriptionId(instance) // + "." + descriptionPostfixes[id]; diff --git a/minecraft/Minecraft.World/net/minecraft/world/item/ColoredTileItem.h b/minecraft/Minecraft.World/net/minecraft/world/item/ColoredTileItem.h index db41bfabe..f1bd89a55 100644 --- a/minecraft/Minecraft.World/net/minecraft/world/item/ColoredTileItem.h +++ b/minecraft/Minecraft.World/net/minecraft/world/item/ColoredTileItem.h @@ -9,7 +9,7 @@ private: // Was const, but removing that so we don't have to make all the functions // const as well! Tile* colorTile; - intArray descriptionPostfixes; + std::vector descriptionPostfixes; public: using TileItem::getColor; @@ -20,7 +20,7 @@ public: virtual Icon* getIcon(int auxValue); virtual int getLevelDataForAuxValue(int auxValue); - ColoredTileItem* setDescriptionPostfixes(intArray descriptionPostfixes); + ColoredTileItem* setDescriptionPostfixes(std::vector& descriptionPostfixes); virtual unsigned int getDescriptionId( std::shared_ptr instance); }; diff --git a/minecraft/Minecraft.World/net/minecraft/world/item/DiggerItem.cpp b/minecraft/Minecraft.World/net/minecraft/world/item/DiggerItem.cpp index 21412d6bb..d987a471b 100644 --- a/minecraft/Minecraft.World/net/minecraft/world/item/DiggerItem.cpp +++ b/minecraft/Minecraft.World/net/minecraft/world/item/DiggerItem.cpp @@ -7,7 +7,7 @@ #include "DiggerItem.h" DiggerItem::DiggerItem(int id, float attackDamage, const Tier* tier, - TileArray* tiles) + std::vector* tiles) : Item(id), tier(tier) { // this->tier = tier; this->tiles = tiles; @@ -19,7 +19,7 @@ DiggerItem::DiggerItem(int id, float attackDamage, const Tier* tier, float DiggerItem::getDestroySpeed(std::shared_ptr itemInstance, Tile* tile) { - for (unsigned int i = 0; i < tiles->length; i++) + for (unsigned int i = 0; i < tiles->size(); i++) if ((*tiles)[i] == tile) return speed; return 1; } diff --git a/minecraft/Minecraft.World/net/minecraft/world/item/DiggerItem.h b/minecraft/Minecraft.World/net/minecraft/world/item/DiggerItem.h index 549c1f0d3..05fd30be1 100644 --- a/minecraft/Minecraft.World/net/minecraft/world/item/DiggerItem.h +++ b/minecraft/Minecraft.World/net/minecraft/world/item/DiggerItem.h @@ -6,7 +6,7 @@ class Mob; class DiggerItem : public Item { private: - TileArray* tiles; + std::vector* tiles; protected: float speed; @@ -17,7 +17,7 @@ private: protected: const Tier* tier; - DiggerItem(int id, float attackDamage, const Tier* tier, TileArray* tiles); + DiggerItem(int id, float attackDamage, const Tier* tier, std::vector* tiles); public: virtual float getDestroySpeed(std::shared_ptr itemInstance, diff --git a/minecraft/Minecraft.World/net/minecraft/world/item/FireworksChargeItem.cpp b/minecraft/Minecraft.World/net/minecraft/world/item/FireworksChargeItem.cpp index b7b07e885..a7d11afb8 100644 --- a/minecraft/Minecraft.World/net/minecraft/world/item/FireworksChargeItem.cpp +++ b/minecraft/Minecraft.World/net/minecraft/world/item/FireworksChargeItem.cpp @@ -18,21 +18,21 @@ int FireworksChargeItem::getColor(std::shared_ptr item, Tag* colorTag = getExplosionTagField(item, FireworksItem::TAG_E_COLORS); if (colorTag != nullptr) { IntArrayTag* colors = (IntArrayTag*)colorTag; - if (colors->data.length == 1) { + if (colors->data.size() == 1) { return colors->data[0]; } int totalRed = 0; int totalGreen = 0; int totalBlue = 0; - for (unsigned int i = 0; i < colors->data.length; ++i) { + for (unsigned int i = 0; i < colors->data.size(); ++i) { int c = colors->data[i]; totalRed += (c & 0xff0000) >> 16; totalGreen += (c & 0x00ff00) >> 8; totalBlue += (c & 0x0000ff) >> 0; } - totalRed /= colors->data.length; - totalGreen /= colors->data.length; - totalBlue /= colors->data.length; + totalRed /= colors->data.size(); + totalGreen /= colors->data.size(); + totalBlue /= colors->data.size(); return (totalRed << 16) | (totalGreen << 8) | totalBlue; } return 0x8a8a8a; @@ -93,11 +93,11 @@ void FireworksChargeItem::appendHoverText(CompoundTag* expTag, } // colors - intArray colorList = expTag->getIntArray(FireworksItem::TAG_E_COLORS); - if (colorList.length > 0) { + std::vector colorList = expTag->getIntArray(FireworksItem::TAG_E_COLORS); + if (colorList.size() > 0) { bool first = true; std::wstring output = L""; - for (unsigned int i = 0; i < colorList.length; ++i) { + for (unsigned int i = 0; i < colorList.size(); ++i) { int c = colorList[i]; if (!first) { output += @@ -123,12 +123,12 @@ void FireworksChargeItem::appendHoverText(CompoundTag* expTag, } // has fade? - intArray fadeList = expTag->getIntArray(FireworksItem::TAG_E_FADECOLORS); - if (fadeList.length > 0) { + std::vector fadeList = expTag->getIntArray(FireworksItem::TAG_E_FADECOLORS); + if (fadeList.size() > 0) { bool first = true; std::wstring output = std::wstring(app.GetString(IDS_FIREWORKS_CHARGE_FADE_TO)) + L" "; - for (unsigned int i = 0; i < fadeList.length; ++i) { + for (unsigned int i = 0; i < fadeList.size(); ++i) { int c = fadeList[i]; if (!first) { output += diff --git a/minecraft/Minecraft.World/net/minecraft/world/item/HatchetItem.cpp b/minecraft/Minecraft.World/net/minecraft/world/item/HatchetItem.cpp index 618ef9a4f..34dbd7b56 100644 --- a/minecraft/Minecraft.World/net/minecraft/world/item/HatchetItem.cpp +++ b/minecraft/Minecraft.World/net/minecraft/world/item/HatchetItem.cpp @@ -2,19 +2,19 @@ #include "../level/tile/net.minecraft.world.level.tile.h" #include "HatchetItem.h" -TileArray* HatchetItem::diggables = nullptr; +std::vector* HatchetItem::diggables = nullptr; void HatchetItem::staticCtor() { - HatchetItem::diggables = new TileArray(HATCHET_DIGGABLES); - diggables->data[0] = Tile::wood; - diggables->data[1] = Tile::bookshelf; - diggables->data[2] = Tile::treeTrunk; - diggables->data[3] = Tile::chest; + HatchetItem::diggables = new std::vector(HATCHET_DIGGABLES); + (*diggables)[0] = Tile::wood; + (*diggables)[1] = Tile::bookshelf; + (*diggables)[2] = Tile::treeTrunk; + (*diggables)[3] = Tile::chest; // 4J - brought forward from 1.2.3 - diggables->data[4] = Tile::stoneSlab; - diggables->data[5] = Tile::stoneSlabHalf; - diggables->data[6] = Tile::pumpkin; - diggables->data[7] = Tile::litPumpkin; + (*diggables)[4] = Tile::stoneSlab; + (*diggables)[5] = Tile::stoneSlabHalf; + (*diggables)[6] = Tile::pumpkin; + (*diggables)[7] = Tile::litPumpkin; } HatchetItem::HatchetItem(int id, const Tier* tier) diff --git a/minecraft/Minecraft.World/net/minecraft/world/item/HatchetItem.h b/minecraft/Minecraft.World/net/minecraft/world/item/HatchetItem.h index a07918cf3..ccf60d72d 100644 --- a/minecraft/Minecraft.World/net/minecraft/world/item/HatchetItem.h +++ b/minecraft/Minecraft.World/net/minecraft/world/item/HatchetItem.h @@ -5,7 +5,7 @@ #define HATCHET_DIGGABLES 8 class HatchetItem : public DiggerItem { private: - static TileArray* diggables; + static std::vector* diggables; public: static void staticCtor(); diff --git a/minecraft/Minecraft.World/net/minecraft/world/item/Item.cpp b/minecraft/Minecraft.World/net/minecraft/world/item/Item.cpp index e88a66b98..4a39f4d70 100644 --- a/minecraft/Minecraft.World/net/minecraft/world/item/Item.cpp +++ b/minecraft/Minecraft.World/net/minecraft/world/item/Item.cpp @@ -32,7 +32,7 @@ const _Tier* _Tier::GOLD = new _Tier(0, 32, 12, 0, 22); Random* Item::random = new Random(); -ItemArray Item::items = ItemArray(ITEM_NUM_COUNT); +std::vector Item::items = std::vector(ITEM_NUM_COUNT); Item* Item::shovel_iron = nullptr; Item* Item::pickAxe_iron = nullptr; diff --git a/minecraft/Minecraft.World/net/minecraft/world/item/Item.h b/minecraft/Minecraft.World/net/minecraft/world/item/Item.h index 40bb2bbcc..d75abd2de 100644 --- a/minecraft/Minecraft.World/net/minecraft/world/item/Item.h +++ b/minecraft/Minecraft.World/net/minecraft/world/item/Item.h @@ -180,7 +180,7 @@ private: static const int MAX_STACK_SIZE = Container::LARGE_MAX_STACK_SIZE; public: - static ItemArray items; + static std::vector items; static Item* shovel_iron; static Item* pickAxe_iron; diff --git a/minecraft/Minecraft.World/net/minecraft/world/item/MapItem.cpp b/minecraft/Minecraft.World/net/minecraft/world/item/MapItem.cpp index bbb158e12..1b7190fa9 100644 --- a/minecraft/Minecraft.World/net/minecraft/world/item/MapItem.cpp +++ b/minecraft/Minecraft.World/net/minecraft/world/item/MapItem.cpp @@ -292,15 +292,14 @@ void MapItem::inventoryTick(std::shared_ptr itemInstance, std::shared_ptr MapItem::getUpdatePacket( std::shared_ptr itemInstance, Level* level, std::shared_ptr player) { - charArray data = MapItem::getSavedData(itemInstance, level) + std::vector data = MapItem::getSavedData(itemInstance, level) ->getUpdatePacket(itemInstance, level, player); - if (data.data == nullptr || data.length == 0) return nullptr; + if (data.empty()) return nullptr; std::shared_ptr retval = std::shared_ptr(new ComplexItemDataPacket( (short)Item::map->id, (short)itemInstance->getAuxValue(), data)); - delete data.data; return retval; } diff --git a/minecraft/Minecraft.World/net/minecraft/world/item/PickaxeItem.cpp b/minecraft/Minecraft.World/net/minecraft/world/item/PickaxeItem.cpp index 9f317ff26..9328f7542 100644 --- a/minecraft/Minecraft.World/net/minecraft/world/item/PickaxeItem.cpp +++ b/minecraft/Minecraft.World/net/minecraft/world/item/PickaxeItem.cpp @@ -2,33 +2,33 @@ #include "../level/tile/net.minecraft.world.level.tile.h" #include "PickaxeItem.h" -TileArray PickaxeItem::diggables; +std::vector PickaxeItem::diggables; void PickaxeItem::staticCtor() { - PickaxeItem::diggables = TileArray(PICKAXE_DIGGABLES); - diggables.data[0] = Tile::cobblestone; - diggables.data[1] = Tile::stoneSlab; - diggables.data[2] = Tile::stoneSlabHalf; - diggables.data[3] = Tile::stone; - diggables.data[4] = Tile::sandStone; - diggables.data[5] = Tile::mossyCobblestone; - diggables.data[6] = Tile::ironOre; - diggables.data[7] = Tile::ironBlock; - diggables.data[8] = Tile::coalOre; - diggables.data[9] = Tile::goldBlock; - diggables.data[10] = Tile::goldOre; - diggables.data[11] = Tile::diamondOre; - diggables.data[12] = Tile::diamondBlock; - diggables.data[13] = Tile::ice; - diggables.data[14] = Tile::netherRack; - diggables.data[15] = Tile::lapisOre; - diggables.data[16] = Tile::lapisBlock; - diggables.data[17] = Tile::redStoneOre; - diggables.data[18] = Tile::redStoneOre_lit; - diggables.data[19] = Tile::rail; - diggables.data[20] = Tile::detectorRail; - diggables.data[21] = Tile::goldenRail; - diggables.data[21] = Tile::activatorRail; + PickaxeItem::diggables = std::vector(PICKAXE_DIGGABLES); + diggables[0] = Tile::cobblestone; + diggables[1] = Tile::stoneSlab; + diggables[2] = Tile::stoneSlabHalf; + diggables[3] = Tile::stone; + diggables[4] = Tile::sandStone; + diggables[5] = Tile::mossyCobblestone; + diggables[6] = Tile::ironOre; + diggables[7] = Tile::ironBlock; + diggables[8] = Tile::coalOre; + diggables[9] = Tile::goldBlock; + diggables[10] = Tile::goldOre; + diggables[11] = Tile::diamondOre; + diggables[12] = Tile::diamondBlock; + diggables[13] = Tile::ice; + diggables[14] = Tile::netherRack; + diggables[15] = Tile::lapisOre; + diggables[16] = Tile::lapisBlock; + diggables[17] = Tile::redStoneOre; + diggables[18] = Tile::redStoneOre_lit; + diggables[19] = Tile::rail; + diggables[20] = Tile::detectorRail; + diggables[21] = Tile::goldenRail; + diggables[21] = Tile::activatorRail; } PickaxeItem::PickaxeItem(int id, const Tier* tier) diff --git a/minecraft/Minecraft.World/net/minecraft/world/item/PickaxeItem.h b/minecraft/Minecraft.World/net/minecraft/world/item/PickaxeItem.h index 082428257..76233b498 100644 --- a/minecraft/Minecraft.World/net/minecraft/world/item/PickaxeItem.h +++ b/minecraft/Minecraft.World/net/minecraft/world/item/PickaxeItem.h @@ -6,7 +6,7 @@ class PickaxeItem : public DiggerItem { private: - static TileArray diggables; + static std::vector diggables; public: // static void staticCtor(); diff --git a/minecraft/Minecraft.World/net/minecraft/world/item/ShovelItem.cpp b/minecraft/Minecraft.World/net/minecraft/world/item/ShovelItem.cpp index a03c42d9c..df4765aba 100644 --- a/minecraft/Minecraft.World/net/minecraft/world/item/ShovelItem.cpp +++ b/minecraft/Minecraft.World/net/minecraft/world/item/ShovelItem.cpp @@ -3,20 +3,20 @@ #include "../level/tile/net.minecraft.world.level.tile.h" #include "ShovelItem.h" -TileArray* ShovelItem::diggables = nullptr; +std::vector* ShovelItem::diggables = nullptr; void ShovelItem::staticCtor() { - ShovelItem::diggables = new TileArray(SHOVEL_DIGGABLES); - diggables->data[0] = Tile::grass; - diggables->data[1] = Tile::dirt; - diggables->data[2] = Tile::sand; - diggables->data[3] = Tile::gravel; - diggables->data[4] = Tile::topSnow; - diggables->data[5] = Tile::snow; - diggables->data[6] = Tile::clay; - diggables->data[7] = Tile::farmland; - diggables->data[8] = Tile::soulsand; - diggables->data[9] = Tile::mycel; + ShovelItem::diggables = new std::vector(SHOVEL_DIGGABLES); + (*diggables)[0] = Tile::grass; + (*diggables)[1] = Tile::dirt; + (*diggables)[2] = Tile::sand; + (*diggables)[3] = Tile::gravel; + (*diggables)[4] = Tile::topSnow; + (*diggables)[5] = Tile::snow; + (*diggables)[6] = Tile::clay; + (*diggables)[7] = Tile::farmland; + (*diggables)[8] = Tile::soulsand; + (*diggables)[9] = Tile::mycel; } ShovelItem::ShovelItem(int id, const Tier* tier) diff --git a/minecraft/Minecraft.World/net/minecraft/world/item/ShovelItem.h b/minecraft/Minecraft.World/net/minecraft/world/item/ShovelItem.h index ac9211f91..1dd8f6673 100644 --- a/minecraft/Minecraft.World/net/minecraft/world/item/ShovelItem.h +++ b/minecraft/Minecraft.World/net/minecraft/world/item/ShovelItem.h @@ -4,7 +4,7 @@ #define SHOVEL_DIGGABLES 10 class ShovelItem : public DiggerItem { private: - static TileArray* diggables; + static std::vector* diggables; public: static void staticCtor(); diff --git a/minecraft/Minecraft.World/net/minecraft/world/item/WrittenBookItem.h b/minecraft/Minecraft.World/net/minecraft/world/item/WrittenBookItem.h index c46853ecf..8edca1b4c 100644 --- a/minecraft/Minecraft.World/net/minecraft/world/item/WrittenBookItem.h +++ b/minecraft/Minecraft.World/net/minecraft/world/item/WrittenBookItem.h @@ -57,7 +57,7 @@ player, List lines, bool advanced) { StringTag authorTag = (StringTag) itemTag.get(TAG_AUTHOR); if (authorTag != null) { lines.add(ChatFormatting.GRAY -+ String.format(I18n.get("book.byAuthor", authorTag.data))); ++ String.format(I18n.get("book.byAuthor", authorTag.data()))); } } } diff --git a/minecraft/Minecraft.World/net/minecraft/world/item/crafting/FireworksRecipe.cpp b/minecraft/Minecraft.World/net/minecraft/world/item/crafting/FireworksRecipe.cpp index 49100e9dd..b554ccb41 100644 --- a/minecraft/Minecraft.World/net/minecraft/world/item/crafting/FireworksRecipe.cpp +++ b/minecraft/Minecraft.World/net/minecraft/world/item/crafting/FireworksRecipe.cpp @@ -156,8 +156,8 @@ bool FireworksRecipe::matches(std::shared_ptr craftSlots, type = FireworksItem::TYPE_CREEPER; } } - intArray colorArray(colors.size()); - for (int i = 0; i < colorArray.length; i++) { + std::vector colorArray(colors.size()); + for (int i = 0; i < colorArray.size(); i++) { colorArray[i] = colors.at(i); } expTag->putIntArray(FireworksItem::TAG_E_COLORS, colorArray); @@ -185,22 +185,20 @@ bool FireworksRecipe::matches(std::shared_ptr craftSlots, resultItem->count = 1; } } - intArray colorArray(colors.size()); - for (int i = 0; i < colorArray.length; i++) { + std::vector colorArray(colors.size()); + for (int i = 0; i < colorArray.size(); i++) { colorArray[i] = colors.at(i); } if (resultItem != nullptr && resultItem->hasTag()) { CompoundTag* compound = resultItem->getTag()->getCompound(FireworksItem::TAG_EXPLOSION); if (compound == nullptr) { - delete colorArray.data; setResultItem(resultItem); return false; } compound->putIntArray(FireworksItem::TAG_E_FADECOLORS, colorArray); } else { - delete colorArray.data; setResultItem(resultItem); return false; diff --git a/minecraft/Minecraft.World/net/minecraft/world/item/enchantment/Enchantment.cpp b/minecraft/Minecraft.World/net/minecraft/world/item/enchantment/Enchantment.cpp index d7776062c..e14b0a2f7 100644 --- a/minecraft/Minecraft.World/net/minecraft/world/item/enchantment/Enchantment.cpp +++ b/minecraft/Minecraft.World/net/minecraft/world/item/enchantment/Enchantment.cpp @@ -4,7 +4,7 @@ #include "Enchantment.h" // Enchantment *Enchantment::enchantments[256]; -EnchantmentArray Enchantment::enchantments = EnchantmentArray(256); +std::vector Enchantment::enchantments = std::vector(256); std::vector Enchantment::validEnchantments; Enchantment* Enchantment::allDamageProtection = nullptr; diff --git a/minecraft/Minecraft.World/net/minecraft/world/item/enchantment/Enchantment.h b/minecraft/Minecraft.World/net/minecraft/world/item/enchantment/Enchantment.h index dc089d3e1..37452c8aa 100644 --- a/minecraft/Minecraft.World/net/minecraft/world/item/enchantment/Enchantment.h +++ b/minecraft/Minecraft.World/net/minecraft/world/item/enchantment/Enchantment.h @@ -9,7 +9,7 @@ class Enchantment // implements Descriptive { { public: // static Enchantment *enchantments[256]; - static EnchantmentArray enchantments; + static std::vector enchantments; static std::vector validEnchantments; static const int FREQ_COMMON = 10; diff --git a/minecraft/Minecraft.World/net/minecraft/world/item/enchantment/EnchantmentHelper.cpp b/minecraft/Minecraft.World/net/minecraft/world/item/enchantment/EnchantmentHelper.cpp index 042007161..455b9011b 100644 --- a/minecraft/Minecraft.World/net/minecraft/world/item/enchantment/EnchantmentHelper.cpp +++ b/minecraft/Minecraft.World/net/minecraft/world/item/enchantment/EnchantmentHelper.cpp @@ -86,11 +86,11 @@ void EnchantmentHelper::setEnchantments( } int EnchantmentHelper::getEnchantmentLevel(int enchantmentId, - arrayWithLength> inventory) { - if (inventory.data == nullptr) return 0; + std::vector> inventory) { + if (inventory.empty()) return 0; int bestLevel = 0; // for (ItemInstance piece : inventory) - for (unsigned int i = 0; i < inventory.length; ++i) { + for (unsigned int i = 0; i < inventory.size(); ++i) { int newLevel = getEnchantmentLevel(enchantmentId, inventory[i]); if (newLevel > bestLevel) { bestLevel = newLevel; @@ -121,9 +121,9 @@ void EnchantmentHelper::runIterationOnItem( } void EnchantmentHelper::runIterationOnInventory( - EnchantmentIterationMethod& method, arrayWithLength> inventory) { + EnchantmentIterationMethod& method, std::vector> inventory) { // for (ItemInstance piece : inventory) - for (unsigned int i = 0; i < inventory.length; ++i) { + for (unsigned int i = 0; i < inventory.size(); ++i) { runIterationOnItem(method, inventory[i]); } } @@ -143,7 +143,7 @@ EnchantmentHelper::GetDamageProtectionIteration * @param source * @return */ -int EnchantmentHelper::getDamageProtection(arrayWithLength> armor, +int EnchantmentHelper::getDamageProtection(std::vector> armor, DamageSource* source) { getDamageProtectionIteration.sum = 0; getDamageProtectionIteration.source = source; @@ -239,8 +239,8 @@ int EnchantmentHelper::getArmorThorns(std::shared_ptr source) { std::shared_ptr EnchantmentHelper::getRandomItemWith( Enchantment* enchantment, std::shared_ptr source) { - arrayWithLength> items = source->getEquipmentSlots(); - for (unsigned int i = 0; i < items.length; ++i) { + std::vector> items = source->getEquipmentSlots(); + for (unsigned int i = 0; i < items.size(); ++i) { std::shared_ptr item = items[i]; if (item != nullptr && getEnchantmentLevel(enchantment->id, item) > 0) { return item; @@ -435,7 +435,7 @@ EnchantmentHelper::getAvailableEnchantmentResults( bool isBook = itemInstance->id == Item::book_Id; // for (Enchantment e : Enchantment.enchantments) - for (unsigned int i = 0; i < Enchantment::enchantments.length; ++i) { + for (unsigned int i = 0; i < Enchantment::enchantments.size(); ++i) { Enchantment* e = Enchantment::enchantments[i]; if (e == nullptr) { continue; diff --git a/minecraft/Minecraft.World/net/minecraft/world/item/enchantment/EnchantmentHelper.h b/minecraft/Minecraft.World/net/minecraft/world/item/enchantment/EnchantmentHelper.h index 97588932d..1ff563509 100644 --- a/minecraft/Minecraft.World/net/minecraft/world/item/enchantment/EnchantmentHelper.h +++ b/minecraft/Minecraft.World/net/minecraft/world/item/enchantment/EnchantmentHelper.h @@ -19,7 +19,7 @@ public: std::shared_ptr item); static int getEnchantmentLevel(int enchantmentId, - arrayWithLength> inventory); + std::vector> inventory); private: class EnchantmentIterationMethod { @@ -30,7 +30,7 @@ private: static void runIterationOnItem(EnchantmentIterationMethod& method, std::shared_ptr piece); static void runIterationOnInventory(EnchantmentIterationMethod& method, - arrayWithLength> inventory); + std::vector> inventory); class GetDamageProtectionIteration : public EnchantmentIterationMethod { public: @@ -50,7 +50,7 @@ private: * @return */ public: - static int getDamageProtection(arrayWithLength> armor, + static int getDamageProtection(std::vector> armor, DamageSource* source); private: diff --git a/minecraft/Minecraft.World/net/minecraft/world/level/FoliageColor.cpp b/minecraft/Minecraft.World/net/minecraft/world/level/FoliageColor.cpp index 14b827435..5e0762fb0 100644 --- a/minecraft/Minecraft.World/net/minecraft/world/level/FoliageColor.cpp +++ b/minecraft/Minecraft.World/net/minecraft/world/level/FoliageColor.cpp @@ -3,11 +3,11 @@ #include "FoliageColor.h" // 4J Stu - Don't use this any more -// intArray FoliageColor::pixels; +// std::vector FoliageColor::pixels; // -// void FoliageColor::init(intArray pixels) +// void FoliageColor::init(std::vector& pixels) //{ -// int *oldData = FoliageColor::pixels.data; +// int *oldData = FoliageColor::pixels.data(); // FoliageColor::pixels = pixels; // delete[] oldData; //} diff --git a/minecraft/Minecraft.World/net/minecraft/world/level/FoliageColor.h b/minecraft/Minecraft.World/net/minecraft/world/level/FoliageColor.h index ed08c310a..5995baa77 100644 --- a/minecraft/Minecraft.World/net/minecraft/world/level/FoliageColor.h +++ b/minecraft/Minecraft.World/net/minecraft/world/level/FoliageColor.h @@ -3,10 +3,10 @@ class FoliageColor { // 4J Stu - We don't want to use this any more // private: - // static intArray pixels; + // static std::vector pixels; // // public: - // static void init(intArray pixels); + // static void init(std::vector& pixels); // static int get(double temp, double rain); public: diff --git a/minecraft/Minecraft.World/net/minecraft/world/level/GrassColor.cpp b/minecraft/Minecraft.World/net/minecraft/world/level/GrassColor.cpp index 2a92be999..2b0aa7985 100644 --- a/minecraft/Minecraft.World/net/minecraft/world/level/GrassColor.cpp +++ b/minecraft/Minecraft.World/net/minecraft/world/level/GrassColor.cpp @@ -2,11 +2,11 @@ #include "GrassColor.h" // 4J Stu - Don't want to do this any more -// intArray GrassColor::pixels; +// std::vector GrassColor::pixels; // -// void GrassColor::init(intArray pixels) +// void GrassColor::init(std::vector& pixels) //{ -// int *oldData = GrassColor::pixels.data; +// int *oldData = GrassColor::pixels.data(); // GrassColor::pixels = pixels; // delete [] oldData; //} diff --git a/minecraft/Minecraft.World/net/minecraft/world/level/GrassColor.h b/minecraft/Minecraft.World/net/minecraft/world/level/GrassColor.h index 54d7d24d4..5c3df0c11 100644 --- a/minecraft/Minecraft.World/net/minecraft/world/level/GrassColor.h +++ b/minecraft/Minecraft.World/net/minecraft/world/level/GrassColor.h @@ -3,9 +3,9 @@ class GrassColor { // 4J Stu - We don't use this any more // private: - // static intArray pixels; + // static std::vector pixels; // public: // - // static void init(intArray pixels); + // static void init(std::vector& pixels); // static int get(double temp, double rain); }; \ No newline at end of file diff --git a/minecraft/Minecraft.World/net/minecraft/world/level/Level.cpp b/minecraft/Minecraft.World/net/minecraft/world/level/Level.cpp index 5ff706c9f..875ba4e21 100644 --- a/minecraft/Minecraft.World/net/minecraft/world/level/Level.cpp +++ b/minecraft/Minecraft.World/net/minecraft/world/level/Level.cpp @@ -3219,7 +3219,7 @@ void Level::checkLight(LightLayer::variety layer, int xc, int yc, int zc, (toCheckCount < (32 * 32 * 32))) // 4J - 32 * 32 * 32 - // was toCheck.length + // was toCheck.size() { toCheck[toCheckCount++] = (xx - xc + 32) | @@ -3297,7 +3297,7 @@ void Level::checkLight(LightLayer::variety layer, int xc, int yc, int zc, bool withinBounds = toCheckCount < (32 * 32 * 32) - - 6; // 4J - 32 * 32 * 32 was toCheck.length + 6; // 4J - 32 * 32 * 32 was toCheck.size() if (xd + yd + zd < 17 && withinBounds) { // 4J - added extra checks here to stop lighting updates // moving out of the actual fixed world and into the @@ -3800,9 +3800,9 @@ std::shared_ptr Level::getPlayerByUUID(const std::wstring& name) { } // 4J Stu - Removed in 1.2.3 ? -byteArray Level::getBlocksAndData(int x, int y, int z, int xs, int ys, int zs, +std::vector Level::getBlocksAndData(int x, int y, int z, int xs, int ys, int zs, bool includeLighting /* = true*/) { - byteArray result(xs * ys * zs * 5 / 2); + std::vector result(xs * ys * zs * 5 / 2); int xc0 = x >> 4; int zc0 = z >> 4; int xc1 = (x + xs - 1) >> 4; @@ -3834,7 +3834,7 @@ byteArray Level::getBlocksAndData(int x, int y, int z, int xs, int ys, int zs, // 4J Stu - Removed in 1.2.3 ? void Level::setBlocksAndData(int x, int y, int z, int xs, int ys, int zs, - byteArray data, bool includeLighting /* = true*/) { + std::vector& data, bool includeLighting /* = true*/) { int xc0 = x >> 4; int zc0 = z >> 4; int xc1 = (x + xs - 1) >> 4; @@ -3873,7 +3873,7 @@ void Level::setBlocksAndData(int x, int y, int z, int xs, int ys, int zs, lc->stopSharingTilesAndData(); PIXEndNamedEvent(); } - if (p < data.length) + if (p < data.size()) p = lc->setBlocksAndData(data, x0, y0, z0, x1, y1, z1, p, includeLighting); setTilesDirty(xc * 16 + x0, y0, zc * 16 + z0, xc * 16 + x1, y1, diff --git a/minecraft/Minecraft.World/net/minecraft/world/level/Level.h b/minecraft/Minecraft.World/net/minecraft/world/level/Level.h index f52c6b870..bbb4b5bd7 100644 --- a/minecraft/Minecraft.World/net/minecraft/world/level/Level.h +++ b/minecraft/Minecraft.World/net/minecraft/world/level/Level.h @@ -554,10 +554,10 @@ public: std::shared_ptr getPlayerByName(const std::wstring& name); std::shared_ptr getPlayerByUUID( const std::wstring& name); // 4J Added - byteArray getBlocksAndData(int x, int y, int z, int xs, int ys, int zs, + std::vector getBlocksAndData(int x, int y, int z, int xs, int ys, int zs, bool includeLighting = true); void setBlocksAndData(int x, int y, int z, int xs, int ys, int zs, - byteArray data, bool includeLighting = true); + std::vector& data, bool includeLighting = true); virtual void disconnect(bool sendDisconnect = true); void checkSession(); void setGameTime(int64_t time); diff --git a/minecraft/Minecraft.World/net/minecraft/world/level/MobSpawner.cpp b/minecraft/Minecraft.World/net/minecraft/world/level/MobSpawner.cpp index fccc33812..ff92a1281 100644 --- a/minecraft/Minecraft.World/net/minecraft/world/level/MobSpawner.cpp +++ b/minecraft/Minecraft.World/net/minecraft/world/level/MobSpawner.cpp @@ -109,7 +109,7 @@ const int MobSpawner::tick(ServerLevel* level, bool spawnEnemies, Pos* spawnPos = level->getSharedSpawnPos(); MemSect(0); - for (unsigned int i = 0; i < MobCategory::values.length; i++) { + for (unsigned int i = 0; i < MobCategory::values.size(); i++) { MobCategory* mobCategory = MobCategory::values[i]; if ((mobCategory->isFriendly() && !spawnFriendlies) || (!mobCategory->isFriendly() && !spawnEnemies) || diff --git a/minecraft/Minecraft.World/net/minecraft/world/level/Region.cpp b/minecraft/Minecraft.World/net/minecraft/world/level/Region.cpp index 9228f582d..52a77af9e 100644 --- a/minecraft/Minecraft.World/net/minecraft/world/level/Region.cpp +++ b/minecraft/Minecraft.World/net/minecraft/world/level/Region.cpp @@ -10,12 +10,6 @@ #include "Region.h" Region::~Region() { - for (unsigned int i = 0; i < chunks->length; ++i) { - LevelChunkArray* lca = (*chunks)[i]; - delete[] lca->data; - delete lca; - } - delete[] chunks->data; delete chunks; // AP - added a caching system for Chunk::rebuild to take advantage of @@ -33,22 +27,20 @@ Region::Region(Level* level, int x1, int y1, int z1, int x2, int y2, int z2, int xc2 = (x2 + r) >> 4; int zc2 = (z2 + r) >> 4; - chunks = new LevelChunk2DArray(xc2 - xc1 + 1, zc2 - zc1 + 1); + chunks = new std::vector>(xc2 - xc1 + 1, std::vector(zc2 - zc1 + 1, nullptr)); allEmpty = true; for (int xc = xc1; xc <= xc2; xc++) { for (int zc = zc1; zc <= zc2; zc++) { LevelChunk* chunk = level->getChunk(xc, zc); if (chunk != nullptr) { - LevelChunkArray* lca = (*chunks)[xc - xc1]; - lca->data[zc - zc1] = chunk; + (*chunks)[xc - xc1][zc - zc1] = chunk; } } } for (int xc = (x1 >> 4); xc <= (x2 >> 4); xc++) { for (int zc = (z1 >> 4); zc <= (z2 >> 4); zc++) { - LevelChunkArray* lca = (*chunks)[xc - xc1]; - LevelChunk* chunk = lca->data[zc - zc1]; + LevelChunk* chunk = (*chunks)[xc - xc1][zc - zc1]; if (chunk != nullptr) { if (!chunk->isYSpaceEmpty(y1, y2)) { allEmpty = false; @@ -75,12 +67,12 @@ int Region::getTile(int x, int y, int z) { xc -= xc1; zc -= zc1; - if (xc < 0 || xc >= (int)chunks->length || zc < 0 || - zc >= (int)(*chunks)[xc]->length) { + if (xc < 0 || xc >= (int)chunks->size() || zc < 0 || + zc >= (int)(*chunks)[xc].size()) { return 0; } - LevelChunk* lc = (*chunks)[xc]->data[zc]; + LevelChunk* lc = (*chunks)[xc][zc]; if (lc == nullptr) return 0; return lc->getTile(x & 15, y, z & 15); @@ -104,12 +96,12 @@ LevelChunk* Region::getLevelChunk(int x, int y, int z) { int xc = (x >> 4) - xc1; int zc = (z >> 4) - zc1; - if (xc < 0 || xc >= (int)chunks->length || zc < 0 || - zc >= (int)(*chunks)[xc]->length) { + if (xc < 0 || xc >= (int)chunks->size() || zc < 0 || + zc >= (int)(*chunks)[xc].size()) { return nullptr; } - LevelChunk* lc = (*chunks)[xc]->data[zc]; + LevelChunk* lc = (*chunks)[xc][zc]; return lc; } @@ -117,7 +109,7 @@ std::shared_ptr Region::getTileEntity(int x, int y, int z) { int xc = (x >> 4) - xc1; int zc = (z >> 4) - zc1; - return (*chunks)[xc]->data[zc]->getTileEntity(x & 15, y, z & 15); + return (*chunks)[xc][zc]->getTileEntity(x & 15, y, z & 15); } int Region::getLightColor(int x, int y, int z, int emitt, int tileId /*=-1*/) { @@ -179,7 +171,7 @@ int Region::getRawBrightness(int x, int y, int z, bool propagate) { int xc = (x >> 4) - xc1; int zc = (z >> 4) - zc1; - return (*chunks)[xc]->data[zc]->getRawBrightness(x & 15, y, z & 15, + return (*chunks)[xc][zc]->getRawBrightness(x & 15, y, z & 15, level->skyDarken); } @@ -189,7 +181,7 @@ int Region::getData(int x, int y, int z) { int xc = (x >> 4) - xc1; int zc = (z >> 4) - zc1; - return (*chunks)[xc]->data[zc]->getData(x & 15, y, z & 15); + return (*chunks)[xc][zc]->getData(x & 15, y, z & 15); } Material* Region::getMaterial(int x, int y, int z) { @@ -290,7 +282,7 @@ int Region::getBrightnessPropagate(LightLayer::variety layer, int x, int y, int xc = (x >> 4) - xc1; int zc = (z >> 4) - zc1; - return (*chunks)[xc]->data[zc]->getBrightness(layer, x & 15, y, z & 15); + return (*chunks)[xc][zc]->getBrightness(layer, x & 15, y, z & 15); } // 4J - brought forward from 1.8.2 @@ -309,7 +301,7 @@ int Region::getBrightness(LightLayer::variety layer, int x, int y, int z) { int xc = (x >> 4) - xc1; int zc = (z >> 4) - zc1; - return (*chunks)[xc]->data[zc]->getBrightness(layer, x & 15, y, z & 15); + return (*chunks)[xc][zc]->getBrightness(layer, x & 15, y, z & 15); } int Region::getMaxBuildHeight() { return Level::maxBuildHeight; } diff --git a/minecraft/Minecraft.World/net/minecraft/world/level/Region.h b/minecraft/Minecraft.World/net/minecraft/world/level/Region.h index 33b72d65e..22c93043a 100644 --- a/minecraft/Minecraft.World/net/minecraft/world/level/Region.h +++ b/minecraft/Minecraft.World/net/minecraft/world/level/Region.h @@ -9,7 +9,7 @@ class BiomeSource; class Region : public LevelSource { private: int xc1, zc1; - LevelChunk2DArray* chunks; + std::vector>* chunks; Level* level; bool allEmpty; diff --git a/minecraft/Minecraft.World/net/minecraft/world/level/WaterColor.cpp b/minecraft/Minecraft.World/net/minecraft/world/level/WaterColor.cpp index f5bfaf018..a160c3a4d 100644 --- a/minecraft/Minecraft.World/net/minecraft/world/level/WaterColor.cpp +++ b/minecraft/Minecraft.World/net/minecraft/world/level/WaterColor.cpp @@ -3,11 +3,11 @@ #include "WaterColor.h" // 4J Stu - Not using this any more -// intArray WaterColor::pixels; +// std::vector WaterColor::pixels; // -// void WaterColor::init(intArray pixels) +// void WaterColor::init(std::vector& pixels) //{ -// int *oldData = WaterColor::pixels.data; +// int *oldData = WaterColor::pixels.data(); // WaterColor::pixels = pixels; // delete [] oldData; //} diff --git a/minecraft/Minecraft.World/net/minecraft/world/level/WaterColor.h b/minecraft/Minecraft.World/net/minecraft/world/level/WaterColor.h index 34e7755e3..05b2ea907 100644 --- a/minecraft/Minecraft.World/net/minecraft/world/level/WaterColor.h +++ b/minecraft/Minecraft.World/net/minecraft/world/level/WaterColor.h @@ -3,10 +3,10 @@ class WaterColor { // 4J Stu - Not using this (and it wasn't ever used anyway...) // private: - // static intArray pixels; + // static std::vector pixels; // // public: - // static void init(intArray pixels); + // static void init(std::vector& pixels); // // public: // static int get(double temp, double rain); diff --git a/minecraft/Minecraft.World/net/minecraft/world/level/biome/BiomeCache.cpp b/minecraft/Minecraft.World/net/minecraft/world/level/biome/BiomeCache.cpp index 84be648be..67f8d50be 100644 --- a/minecraft/Minecraft.World/net/minecraft/world/level/biome/BiomeCache.cpp +++ b/minecraft/Minecraft.World/net/minecraft/world/level/biome/BiomeCache.cpp @@ -6,12 +6,12 @@ #include "java/System.h" BiomeCache::Block::Block(int x, int z, BiomeCache* parent) { - // temps = floatArray(ZONE_SIZE * ZONE_SIZE, false); // MGH - + // temps = std::vector(ZONE_SIZE * ZONE_SIZE, false); // MGH - // added "no clear" flag to arrayWithLength downfall = - // floatArray(ZONE_SIZE - // * ZONE_SIZE, false); biomes = BiomeArray(ZONE_SIZE * ZONE_SIZE, + // std::vector(ZONE_SIZE + // * ZONE_SIZE, false); biomes = std::vector(ZONE_SIZE * ZONE_SIZE, // false); - biomeIndices = byteArray(ZONE_SIZE * ZONE_SIZE, false); + biomeIndices = std::vector(ZONE_SIZE * ZONE_SIZE, false); lastUse = 0; this->x = x; @@ -29,10 +29,6 @@ BiomeCache::Block::Block(int x, int z, BiomeCache* parent) { } BiomeCache::Block::~Block() { - // delete [] temps.data; - // delete [] downfall.data; - // delete [] biomes.data; - delete[] biomeIndices.data; } Biome* BiomeCache::Block::getBiome(int x, int z) { @@ -134,14 +130,14 @@ void BiomeCache::update() { } } -BiomeArray BiomeCache::getBiomeBlockAt(int x, int z) { - byteArray indices = getBlockAt(x, z)->biomeIndices; - BiomeArray biomes(indices.length); - for (int i = 0; i < indices.length; i++) +std::vector BiomeCache::getBiomeBlockAt(int x, int z) { + std::vector indices = getBlockAt(x, z)->biomeIndices; + std::vector biomes(indices.size()); + for (int i = 0; i < indices.size(); i++) biomes[i] = Biome::biomes[indices[i]]; return biomes; } -byteArray BiomeCache::getBiomeIndexBlockAt(int x, int z) { +std::vector BiomeCache::getBiomeIndexBlockAt(int x, int z) { return getBlockAt(x, z)->biomeIndices; } \ No newline at end of file diff --git a/minecraft/Minecraft.World/net/minecraft/world/level/biome/BiomeCache.h b/minecraft/Minecraft.World/net/minecraft/world/level/biome/BiomeCache.h index cbf046c69..44b11a0bb 100644 --- a/minecraft/Minecraft.World/net/minecraft/world/level/biome/BiomeCache.h +++ b/minecraft/Minecraft.World/net/minecraft/world/level/biome/BiomeCache.h @@ -17,10 +17,10 @@ public: public: // MGH - changed this to just cache biome indices, as we have direct // access to the data if we know the index. - // floatArray temps; - // floatArray downfall; - // BiomeArray biomes; - byteArray biomeIndices; + // std::vector temps; + // std::vector downfall; + // std::vector biomes; + std::vector biomeIndices; int x, z; int64_t lastUse; @@ -45,8 +45,8 @@ public: float getTemperature(int x, int z); float getDownfall(int x, int z); void update(); - BiomeArray getBiomeBlockAt(int x, int z); - byteArray getBiomeIndexBlockAt(int x, int z); + std::vector getBiomeBlockAt(int x, int z); + std::vector getBiomeIndexBlockAt(int x, int z); private: std::mutex m_CS; diff --git a/minecraft/Minecraft.World/net/minecraft/world/level/biome/BiomeSource.cpp b/minecraft/Minecraft.World/net/minecraft/world/level/biome/BiomeSource.cpp index 5561e5ed7..329b694fd 100644 --- a/minecraft/Minecraft.World/net/minecraft/world/level/biome/BiomeSource.cpp +++ b/minecraft/Minecraft.World/net/minecraft/world/level/biome/BiomeSource.cpp @@ -30,11 +30,10 @@ void BiomeSource::_init() { void BiomeSource::_init(int64_t seed, LevelType* generator) { _init(); - LayerArray layers = Layer::getDefaultLayers(seed, generator); + std::vector> layers = Layer::getDefaultLayers(seed, generator); layer = layers[0]; zoomedLayer = layers[1]; - delete[] layers.data; } BiomeSource::BiomeSource() { _init(); } @@ -64,8 +63,8 @@ float BiomeSource::getDownfall(int x, int z) const { // 4J - note that caller is responsible for deleting returned array. // temperatures array is for output only. -floatArray BiomeSource::getDownfallBlock(int x, int z, int w, int h) const { - floatArray downfalls; +std::vector BiomeSource::getDownfallBlock(int x, int z, int w, int h) const { + std::vector downfalls; getDownfallBlock(downfalls, x, z, w, h); return downfalls; } @@ -73,15 +72,14 @@ floatArray BiomeSource::getDownfallBlock(int x, int z, int w, int h) const { // 4J - note that caller is responsible for deleting returned array. // temperatures array is for output only. 4J - removal of separate temperature & // downfall layers brought forward from 1.2.3 -void BiomeSource::getDownfallBlock(floatArray& downfalls, int x, int z, int w, +void BiomeSource::getDownfallBlock(std::vector& downfalls, int x, int z, int w, int h) const { // if (downfalls == nullptr || downfalls->length < w * h) - if (downfalls.data == nullptr || downfalls.length < w * h) { - if (downfalls.data != nullptr) delete[] downfalls.data; - downfalls = floatArray(w * h); + if (downfalls.empty() || downfalls.size() < (unsigned int)(w * h)) { + downfalls = std::vector(w * h); } - intArray result = zoomedLayer->getArea(x, z, w, h); + std::vector result = zoomedLayer->getArea(x, z, w, h); for (int i = 0; i < w * h; i++) { float d = (float)Biome::biomes[result[i]]->getDownfallInt() / 65536.0f; if (d > 1) d = 1; @@ -100,8 +98,8 @@ float BiomeSource::getTemperature(int x, int y, int z) const { // 4J - brought forward from 1.2.3 float BiomeSource::scaleTemp(float temp, int y) const { return temp; } -floatArray BiomeSource::getTemperatureBlock(int x, int z, int w, int h) const { - floatArray temperatures; +std::vector BiomeSource::getTemperatureBlock(int x, int z, int w, int h) const { + std::vector temperatures; getTemperatureBlock(temperatures, x, z, w, h); return temperatures; } @@ -109,15 +107,14 @@ floatArray BiomeSource::getTemperatureBlock(int x, int z, int w, int h) const { // 4J - note that caller is responsible for deleting returned array. // temperatures array is for output only. 4J - removal of separate temperature & // downfall layers brought forward from 1.2.3 -void BiomeSource::getTemperatureBlock(floatArray& temperatures, int x, int z, +void BiomeSource::getTemperatureBlock(std::vector& temperatures, int x, int z, int w, int h) const { - // if (temperatures == null || temperatures.length < w * h) { - if (temperatures.data == nullptr || temperatures.length < w * h) { - if (temperatures.data != nullptr) delete[] temperatures.data; - temperatures = floatArray(w * h); + // if (temperatures == null || temperatures.size() < w * h) { + if (temperatures.empty() || temperatures.size() < (unsigned int)(w * h)) { + temperatures = std::vector(w * h); } - intArray result = zoomedLayer->getArea(x, z, w, h); + std::vector result = zoomedLayer->getArea(x, z, w, h); for (int i = 0; i < w * h; i++) { float t = (float)Biome::biomes[result[i]]->getTemperatureInt() / 65536.0f; @@ -126,30 +123,29 @@ void BiomeSource::getTemperatureBlock(floatArray& temperatures, int x, int z, } } -BiomeArray BiomeSource::getRawBiomeBlock(int x, int z, int w, int h) const { - BiomeArray biomes; +std::vector BiomeSource::getRawBiomeBlock(int x, int z, int w, int h) const { + std::vector biomes; getRawBiomeBlock(biomes, x, z, w, h); return biomes; } // 4J added -void BiomeSource::getRawBiomeIndices(intArray& biomes, int x, int z, int w, +void BiomeSource::getRawBiomeIndices(std::vector& biomes, int x, int z, int w, int h) const { - intArray result = layer->getArea(x, z, w, h); + std::vector result = layer->getArea(x, z, w, h); for (int i = 0; i < w * h; i++) { biomes[i] = result[i]; } } -void BiomeSource::getRawBiomeBlock(BiomeArray& biomes, int x, int z, int w, +void BiomeSource::getRawBiomeBlock(std::vector& biomes, int x, int z, int w, int h) const { - // if (biomes == null || biomes.length < w * h) - if (biomes.data == nullptr || biomes.length < w * h) { - if (biomes.data != nullptr) delete[] biomes.data; - biomes = BiomeArray(w * h); + // if (biomes == null || biomes.size() < w * h) + if (biomes.empty() || biomes.size() < (unsigned int)(w * h)) { + biomes = std::vector(w * h); } - intArray result = layer->getArea(x, z, w, h); + std::vector result = layer->getArea(x, z, w, h); for (int i = 0; i < w * h; i++) { biomes[i] = Biome::biomes[result[i]]; #if !defined(_CONTENT_PACKAGE) @@ -161,63 +157,60 @@ void BiomeSource::getRawBiomeBlock(BiomeArray& biomes, int x, int z, int w, } } -BiomeArray BiomeSource::getBiomeBlock(int x, int z, int w, int h) const { +std::vector BiomeSource::getBiomeBlock(int x, int z, int w, int h) const { if (w == 16 && h == 16 && (x & 0xf) == 0 && (z & 0xf) == 0) { return cache->getBiomeBlockAt(x, z); } - BiomeArray biomes; + std::vector biomes; getBiomeBlock(biomes, x, z, w, h, true); return biomes; } // 4J - caller is responsible for deleting biomes array -void BiomeSource::getBiomeBlock(BiomeArray& biomes, int x, int z, int w, int h, +void BiomeSource::getBiomeBlock(std::vector& biomes, int x, int z, int w, int h, bool useCache) const { - // if (biomes == null || biomes.length < w * h) - if (biomes.data == nullptr || biomes.length < w * h) { - if (biomes.data != nullptr) delete[] biomes.data; - biomes = BiomeArray(w * h); + // if (biomes == null || biomes.size() < w * h) + if (biomes.empty() || biomes.size() < w * h) { + biomes = std::vector(w * h); } if (useCache && w == 16 && h == 16 && (x & 0xf) == 0 && (z & 0xf) == 0) { - BiomeArray tmp = cache->getBiomeBlockAt(x, z); - System::arraycopy(tmp, 0, &biomes, 0, w * h); - delete[] tmp.data; // MGH - added, the caching creates this array from + std::vector tmp = cache->getBiomeBlockAt(x, z); + std::copy(tmp.begin(), tmp.begin() + w * h, biomes.begin()); // the indices now. //4jcraft made it array delete // return biomes; } - intArray result = zoomedLayer->getArea(x, z, w, h); + std::vector result = zoomedLayer->getArea(x, z, w, h); for (int i = 0; i < w * h; i++) { biomes[i] = Biome::biomes[result[i]]; } } -byteArray BiomeSource::getBiomeIndexBlock(int x, int z, int w, int h) const { +std::vector BiomeSource::getBiomeIndexBlock(int x, int z, int w, int h) const { if (w == 16 && h == 16 && (x & 0xf) == 0 && (z & 0xf) == 0) { return cache->getBiomeIndexBlockAt(x, z); } - byteArray biomeIndices; + std::vector biomeIndices; getBiomeIndexBlock(biomeIndices, x, z, w, h, true); return biomeIndices; } // 4J - caller is responsible for deleting biomes array -void BiomeSource::getBiomeIndexBlock(byteArray& biomeIndices, int x, int z, +void BiomeSource::getBiomeIndexBlock(std::vector& biomeIndices, int x, int z, int w, int h, bool useCache) const { - // if (biomes == null || biomes.length < w * h) - if (biomeIndices.data == nullptr || biomeIndices.length < w * h) { - if (biomeIndices.data != nullptr) delete[] biomeIndices.data; - biomeIndices = byteArray(w * h); + // if (biomes == null || biomes.size() < w * h) + if (biomeIndices.empty() || biomeIndices.size() < w * h) { + biomeIndices = std::vector(w * h); } if (useCache && w == 16 && h == 16 && (x & 0xf) == 0 && (z & 0xf) == 0) { - byteArray tmp = cache->getBiomeIndexBlockAt(x, z); - System::arraycopy(tmp, 0, &biomeIndices, 0, w * h); + std::vector tmp = cache->getBiomeIndexBlockAt(x, z); + std::copy(tmp.begin(), tmp.begin() + w * h, biomeIndices.begin()); // return biomes; } - intArray result = zoomedLayer->getArea(x, z, w, h); + std::vector result = zoomedLayer->getArea(x, z, w, h); for (int i = 0; i < w * h; i++) { biomeIndices[i] = (uint8_t)result[i]; } @@ -231,7 +224,7 @@ void BiomeSource::getBiomeIndexBlock(byteArray& biomeIndices, int x, int z, * NO other biomes, add a margin of at least four blocks to the radius */ bool BiomeSource::containsOnly(int x, int z, int r, - std::vector allowed) { + const std::vector& allowed) { int x0 = ((x - r) >> 2); int z0 = ((z - r) >> 2); int x1 = ((x + r) >> 2); @@ -240,7 +233,7 @@ bool BiomeSource::containsOnly(int x, int z, int r, int w = x1 - x0 + 1; int h = z1 - z0 + 1; - intArray biomes = layer->getArea(x0, z0, w, h); + std::vector biomes = layer->getArea(x0, z0, w, h); for (int i = 0; i < w * h; i++) { Biome* b = Biome::biomes[biomes[i]]; if (find(allowed.begin(), allowed.end(), b) == allowed.end()) @@ -266,7 +259,7 @@ bool BiomeSource::containsOnly(int x, int z, int r, Biome* allowed) { int w = x1 - x0; int h = z1 - z0; int biomesCount = w * h; - intArray biomes = layer->getArea(x0, z0, w, h); + std::vector biomes = layer->getArea(x0, z0, w, h); for (unsigned int i = 0; i < biomesCount; i++) { Biome* b = Biome::biomes[biomes[i]]; if (allowed != b) return false; @@ -290,7 +283,7 @@ TilePos* BiomeSource::findBiome(int x, int z, int r, Biome* toFind, int w = x1 - x0 + 1; int h = z1 - z0 + 1; - intArray biomes = layer->getArea(x0, z0, w, h); + std::vector biomes = layer->getArea(x0, z0, w, h); TilePos* res = nullptr; int found = 0; int biomesCount = w * h; @@ -316,7 +309,7 @@ TilePos* BiomeSource::findBiome(int x, int z, int r, Biome* toFind, * Returns null if the biome wasn't found */ TilePos* BiomeSource::findBiome(int x, int z, int r, - std::vector allowed, Random* random) { + const std::vector& allowed, Random* random) { int x0 = ((x - r) >> 2); int z0 = ((z - r) >> 2); int x1 = ((x + r) >> 2); @@ -325,7 +318,7 @@ TilePos* BiomeSource::findBiome(int x, int z, int r, int w = x1 - x0 + 1; int h = z1 - z0 + 1; MemSect(50); - intArray biomes = layer->getArea(x0, z0, w, h); + std::vector biomes = layer->getArea(x0, z0, w, h); TilePos* res = nullptr; int found = 0; for (unsigned int i = 0; i < w * h; i++) { @@ -381,7 +374,7 @@ int64_t BiomeSource::findSeed(LevelType* generator) { static const int biomeOffset = -(biomeWidth / 2); // Storage for our biome indices - intArray indices = intArray(biomeWidth * biomeWidth); + std::vector indices = std::vector(biomeWidth * biomeWidth); // Storage for the fractional amounts of each biome that will be // calculated @@ -412,14 +405,13 @@ int64_t BiomeSource::findSeed(LevelType* generator) { // Clean up delete pr; - delete[] indices.data; #if defined(DEBUG_SEEDS) app.DebugPrintf("%d: %d tries taken, seed used is %lld\n", k, tryCount, bestSeed); BiomeSource* biomeSource = new BiomeSource(bestSeed); - BiomeArray biomes = biomeSource->getBiomeBlock(-27 * 16, -27 * 16, + std::vector biomes = biomeSource->getBiomeBlock(-27 * 16, -27 * 16, 54 * 16, 54 * 16); unsigned int* pixels = new unsigned int[54 * 16 * 54 * 16]; @@ -469,7 +461,6 @@ int64_t BiomeSource::findSeed(LevelType* generator) { RenderManager.SaveTextureData(buf, &srcInfo, (int*)pixels); delete[] pixels; - delete biomes.data; delete biomeSource; #endif } @@ -479,17 +470,17 @@ int64_t BiomeSource::findSeed(LevelType* generator) { } // 4J added - get the fractional amounts of each biome type in the given indices -void BiomeSource::getFracs(intArray indices, float* fracs) { +void BiomeSource::getFracs(std::vector& indices, float* fracs) { for (int i = 0; i < Biome::BIOME_COUNT; i++) { fracs[i] = 0.0f; } - for (int i = 0; i < indices.length; i++) { + for (int i = 0; i < indices.size(); i++) { fracs[indices[i]] += 1.0f; } for (int i = 0; i < Biome::BIOME_COUNT; i++) { - fracs[i] /= (float)(indices.length); + fracs[i] /= (float)(indices.size()); } } diff --git a/minecraft/Minecraft.World/net/minecraft/world/level/biome/BiomeSource.h b/minecraft/Minecraft.World/net/minecraft/world/level/biome/BiomeSource.h index 095167aca..10b3d5d5d 100644 --- a/minecraft/Minecraft.World/net/minecraft/world/level/biome/BiomeSource.h +++ b/minecraft/Minecraft.World/net/minecraft/world/level/biome/BiomeSource.h @@ -34,7 +34,7 @@ public: private: static bool getIsMatch(float* frac); // 4J added - static void getFracs(intArray indices, float* fracs); // 4J added + static void getFracs(std::vector& indices, float* fracs); // 4J added public: static int64_t findSeed(LevelType* generator); // 4J added virtual ~BiomeSource(); @@ -46,8 +46,8 @@ public: // 4J - changed the interface for these methods, mainly for thread safety virtual float getDownfall(int x, int z) const; - virtual floatArray getDownfallBlock(int x, int z, int w, int h) const; - virtual void getDownfallBlock(floatArray& downfalls, int x, int z, int w, + virtual std::vector getDownfallBlock(int x, int z, int w, int h) const; + virtual void getDownfallBlock(std::vector& downfalls, int x, int z, int w, int h) const; // 4J - changed the interface for these methods, mainly for thread safety @@ -55,21 +55,21 @@ public: virtual float getTemperature(int x, int y, int z) const; float scaleTemp(float temp, int y) const; // 4J - brought forward from 1.2.3 - virtual floatArray getTemperatureBlock(int x, int z, int w, int h) const; - virtual void getTemperatureBlock(floatArray& temperatures, int x, int z, + virtual std::vector getTemperatureBlock(int x, int z, int w, int h) const; + virtual void getTemperatureBlock(std::vector& temperatures, int x, int z, int w, int h) const; - virtual BiomeArray getRawBiomeBlock(int x, int z, int w, int h) const; - virtual void getRawBiomeBlock(BiomeArray& biomes, int x, int z, int w, + virtual std::vector getRawBiomeBlock(int x, int z, int w, int h) const; + virtual void getRawBiomeBlock(std::vector& biomes, int x, int z, int w, int h) const; - virtual void getRawBiomeIndices(intArray& biomes, int x, int z, int w, + virtual void getRawBiomeIndices(std::vector& biomes, int x, int z, int w, int h) const; // 4J added - virtual BiomeArray getBiomeBlock(int x, int z, int w, int h) const; - virtual void getBiomeBlock(BiomeArray& biomes, int x, int z, int w, int h, + virtual std::vector getBiomeBlock(int x, int z, int w, int h) const; + virtual void getBiomeBlock(std::vector& biomes, int x, int z, int w, int h, bool useCache) const; - virtual byteArray getBiomeIndexBlock(int x, int z, int w, int h) const; - virtual void getBiomeIndexBlock(byteArray& biomeIndices, int x, int z, + virtual std::vector getBiomeIndexBlock(int x, int z, int w, int h) const; + virtual void getBiomeIndexBlock(std::vector& biomeIndices, int x, int z, int w, int h, bool useCache) const; /** @@ -79,7 +79,7 @@ public: * This is a bit of a rough check, to make it as fast as possible. To ensure * NO other biomes, add a margin of at least four blocks to the radius */ - virtual bool containsOnly(int x, int z, int r, std::vector allowed); + virtual bool containsOnly(int x, int z, int r, const std::vector& allowed); /** * Checks if an area around a block contains only the specified biome. @@ -105,7 +105,7 @@ public: * * Returns null if the biome wasn't found */ - virtual TilePos* findBiome(int x, int z, int r, std::vector allowed, + virtual TilePos* findBiome(int x, int z, int r, const std::vector& allowed, Random* random); void update(); diff --git a/minecraft/Minecraft.World/net/minecraft/world/level/biome/FixedBiomeSource.cpp b/minecraft/Minecraft.World/net/minecraft/world/level/biome/FixedBiomeSource.cpp index 98ef08534..72109b529 100644 --- a/minecraft/Minecraft.World/net/minecraft/world/level/biome/FixedBiomeSource.cpp +++ b/minecraft/Minecraft.World/net/minecraft/world/level/biome/FixedBiomeSource.cpp @@ -15,65 +15,62 @@ Biome* FixedBiomeSource::getBiome(int x, int z) { return biome; } float FixedBiomeSource::getTemperature(int x, int z) { return temperature; } -void FixedBiomeSource::getTemperatureBlock(floatArray& temperatures, int x, +void FixedBiomeSource::getTemperatureBlock(std::vector& temperatures, int x, int z, int w, int h) const { - if (temperatures.data == nullptr || temperatures.length < w * h) { - if (temperatures.data != nullptr) delete[] temperatures.data; - temperatures = floatArray(w * h); + if (temperatures.empty() || temperatures.size() < (unsigned int)(w * h)) { + temperatures = std::vector(w * h); } Arrays::fill(temperatures, 0, w * h, temperature); } -floatArray FixedBiomeSource::getTemperatureBlock(int x, int z, int w, +std::vector FixedBiomeSource::getTemperatureBlock(int x, int z, int w, int h) const { - floatArray temps(w * h); + std::vector temps(w * h); getTemperatureBlock(temps, x, z, w, h); return temps; } // 4J - note that caller is responsible for deleting returned array. // temperatures array is for output only. -void FixedBiomeSource::getTemperatureBlock(doubleArray& temperatures, int x, +void FixedBiomeSource::getTemperatureBlock(std::vector& temperatures, int x, int z, int w, int h) const { - temperatures = doubleArray(w * h); + temperatures = std::vector(w * h); Arrays::fill(temperatures, 0, w * h, (double)temperature); } -void FixedBiomeSource::getDownfallBlock(floatArray& downfalls, int x, int z, +void FixedBiomeSource::getDownfallBlock(std::vector& downfalls, int x, int z, int w, int h) const { - if (downfalls.data == nullptr || downfalls.length < w * h) { - if (downfalls.data != nullptr) delete[] downfalls.data; - downfalls = floatArray(w * h); + if (downfalls.empty() || downfalls.size() < (unsigned int)(w * h)) { + downfalls = std::vector(w * h); } Arrays::fill(downfalls, 0, w * h, downfall); } -floatArray FixedBiomeSource::getDownfallBlock(int x, int z, int w, +std::vector FixedBiomeSource::getDownfallBlock(int x, int z, int w, int h) const { - floatArray downfalls(w * h); + std::vector downfalls(w * h); getDownfallBlock(downfalls, x, z, w, h); return downfalls; } float FixedBiomeSource::getDownfall(int x, int z) const { return downfall; } -void FixedBiomeSource::getDownfallBlock(doubleArray downfalls, int x, int z, +void FixedBiomeSource::getDownfallBlock(std::vector& downfalls, int x, int z, int w, int h) { - if (downfalls.data == nullptr || downfalls.length < w * h) { - if (downfalls.data != nullptr) delete[] downfalls.data; - downfalls = doubleArray(w * h); + if (downfalls.empty() || downfalls.size() < (unsigned int)(w * h)) { + downfalls = std::vector(w * h); } Arrays::fill(downfalls, 0, w * h, (double)downfall); } // 4J - caller is responsible for deleting biomes array, plus any optional // arrays output if pointers are passed in (_temperatures, _downfalls) -void FixedBiomeSource::getBiomeBlock(BiomeArray& biomes, int x, int z, int w, +void FixedBiomeSource::getBiomeBlock(std::vector& biomes, int x, int z, int w, int h, bool useCache) const { MemSect(36); - biomes = BiomeArray(w * h); + biomes = std::vector(w * h); MemSect(0); Arrays::fill(biomes, 0, w * h, biome); @@ -81,10 +78,10 @@ void FixedBiomeSource::getBiomeBlock(BiomeArray& biomes, int x, int z, int w, // 4J - caller is responsible for deleting biomes array, plus any optional // arrays output if pointers are passed in (_temperatures, _downfalls) -void FixedBiomeSource::getBiomeIndexBlock(byteArray& biomeIndices, int x, int z, +void FixedBiomeSource::getBiomeIndexBlock(std::vector& biomeIndices, int x, int z, int w, int h, bool useCache) const { MemSect(36); - biomeIndices = byteArray(w * h); + biomeIndices = std::vector(w * h); MemSect(0); int biomeIndex = biome->id; Arrays::fill(biomeIndices, 0, w * h, biomeIndex); @@ -93,10 +90,10 @@ void FixedBiomeSource::getBiomeIndexBlock(byteArray& biomeIndices, int x, int z, // 4J-PB added in from beyond 1.8.2 // 4J - caller is responsible for deleting biomes array, plus any optional // arrays output if pointers are passed in (_temperatures, _downfalls) -void FixedBiomeSource::getRawBiomeBlock(BiomeArray& biomes, int x, int z, int w, +void FixedBiomeSource::getRawBiomeBlock(std::vector& biomes, int x, int z, int w, int h) const { MemSect(36); - biomes = BiomeArray(w * h); + biomes = std::vector(w * h); MemSect(0); Arrays::fill(biomes, 0, w * h, biome); @@ -105,9 +102,9 @@ void FixedBiomeSource::getRawBiomeBlock(BiomeArray& biomes, int x, int z, int w, // 4J-PB added in from beyond 1.8.2 // 4J - caller is responsible for deleting biomes array, plus any optional // arrays output if pointers are passed in (_temperatures, _downfalls) -BiomeArray FixedBiomeSource::getRawBiomeBlock(int x, int z, int w, +std::vector FixedBiomeSource::getRawBiomeBlock(int x, int z, int w, int h) const { - BiomeArray biomes; + std::vector biomes; getRawBiomeBlock(biomes, x, z, w, h); return biomes; } @@ -122,7 +119,7 @@ TilePos* FixedBiomeSource::findBiome(int x, int z, int r, Biome* toFind, } TilePos* FixedBiomeSource::findBiome(int x, int z, int r, - std::vector allowed, + const std::vector& allowed, Random* random) { if (find(allowed.begin(), allowed.end(), biome) != allowed.end()) { return new TilePos(x - r + random->nextInt(r * 2 + 1), 0, @@ -137,6 +134,6 @@ bool FixedBiomeSource::containsOnly(int x, int z, int r, Biome* allowed) { } bool FixedBiomeSource::containsOnly(int x, int z, int r, - std::vector allowed) { + const std::vector& allowed) { return find(allowed.begin(), allowed.end(), biome) != allowed.end(); } \ No newline at end of file diff --git a/minecraft/Minecraft.World/net/minecraft/world/level/biome/FixedBiomeSource.h b/minecraft/Minecraft.World/net/minecraft/world/level/biome/FixedBiomeSource.h index 4148e3b2e..06b5239e4 100644 --- a/minecraft/Minecraft.World/net/minecraft/world/level/biome/FixedBiomeSource.h +++ b/minecraft/Minecraft.World/net/minecraft/world/level/biome/FixedBiomeSource.h @@ -14,32 +14,32 @@ public: virtual Biome* getBiome(ChunkPos* cp); virtual Biome* getBiome(int x, int z); virtual float getTemperature(int x, int z); - virtual void getTemperatureBlock(floatArray& temperatures, int x, int z, + virtual void getTemperatureBlock(std::vector& temperatures, int x, int z, int w, int h) const; - virtual floatArray getTemperatureBlock(int x, int z, int w, int h) const; - virtual void getTemperatureBlock(doubleArray& temperatures, int x, int z, + virtual std::vector getTemperatureBlock(int x, int z, int w, int h) const; + virtual void getTemperatureBlock(std::vector& temperatures, int x, int z, int w, int h) const; - virtual void getDownfallBlock(floatArray& downfalls, int x, int z, int w, + virtual void getDownfallBlock(std::vector& downfalls, int x, int z, int w, int h) const; - virtual floatArray getDownfallBlock(int x, int z, int w, int h) const; + virtual std::vector getDownfallBlock(int x, int z, int w, int h) const; virtual float getDownfall(int x, int z) const; - virtual void getDownfallBlock(doubleArray downfalls, int x, int z, int w, + virtual void getDownfallBlock(std::vector& downfalls, int x, int z, int w, int h); - virtual void getBiomeBlock(BiomeArray& biomes, int x, int z, int w, int h, + virtual void getBiomeBlock(std::vector& biomes, int x, int z, int w, int h, bool useCache) const; - virtual void getBiomeIndexBlock(byteArray& biomeIndices, int x, int z, + virtual void getBiomeIndexBlock(std::vector& biomeIndices, int x, int z, int w, int h, bool useCache) const; // 4J-PB added in from beyond 1.8.2 - virtual BiomeArray getRawBiomeBlock(int x, int z, int w, int h) const; - virtual void getRawBiomeBlock(BiomeArray& biomes, int x, int z, int w, + virtual std::vector getRawBiomeBlock(int x, int z, int w, int h) const; + virtual void getRawBiomeBlock(std::vector& biomes, int x, int z, int w, int h) const; //////////////////////////////////// virtual TilePos* findBiome(int x, int z, int r, Biome* toFind, Random* random); - virtual TilePos* findBiome(int x, int z, int r, std::vector allowed, + virtual TilePos* findBiome(int x, int z, int r, const std::vector& allowed, Random* random); virtual bool containsOnly(int x, int z, int r, Biome* allowed); - virtual bool containsOnly(int x, int z, int r, std::vector allowed); + virtual bool containsOnly(int x, int z, int r, const std::vector& allowed); }; diff --git a/minecraft/Minecraft.World/net/minecraft/world/level/chunk/BlockReplacements.cpp b/minecraft/Minecraft.World/net/minecraft/world/level/chunk/BlockReplacements.cpp index 54cf95874..e58dc70d9 100644 --- a/minecraft/Minecraft.World/net/minecraft/world/level/chunk/BlockReplacements.cpp +++ b/minecraft/Minecraft.World/net/minecraft/world/level/chunk/BlockReplacements.cpp @@ -2,7 +2,7 @@ #include "BlockReplacements.h" #include "../tile/net.minecraft.world.level.tile.h" -byteArray BlockReplacements::replacements = byteArray(256); +std::vector BlockReplacements::replacements = std::vector(256); void BlockReplacements::staticCtor() { for (int i = 0; i < 256; i++) { @@ -14,8 +14,8 @@ void BlockReplacements::staticCtor() { } } -void BlockReplacements::replace(byteArray blocks) { - for (unsigned int i = 0; i < blocks.length; i++) { +void BlockReplacements::replace(std::vector& blocks) { + for (unsigned int i = 0; i < blocks.size(); i++) { blocks[i] = replacements[blocks[i] & 0xff]; } } \ No newline at end of file diff --git a/minecraft/Minecraft.World/net/minecraft/world/level/chunk/BlockReplacements.h b/minecraft/Minecraft.World/net/minecraft/world/level/chunk/BlockReplacements.h index 20fadd63f..481787814 100644 --- a/minecraft/Minecraft.World/net/minecraft/world/level/chunk/BlockReplacements.h +++ b/minecraft/Minecraft.World/net/minecraft/world/level/chunk/BlockReplacements.h @@ -5,8 +5,8 @@ public: static void staticCtor(); private: - static byteArray replacements; + static std::vector replacements; public: - static void replace(byteArray blocks); + static void replace(std::vector& blocks); }; \ No newline at end of file diff --git a/minecraft/Minecraft.World/net/minecraft/world/level/chunk/CompressedTileStorage.cpp b/minecraft/Minecraft.World/net/minecraft/world/level/chunk/CompressedTileStorage.cpp index 870a964e7..5126fe8c8 100644 --- a/minecraft/Minecraft.World/net/minecraft/world/level/chunk/CompressedTileStorage.cpp +++ b/minecraft/Minecraft.World/net/minecraft/world/level/chunk/CompressedTileStorage.cpp @@ -51,7 +51,7 @@ CompressedTileStorage::CompressedTileStorage(CompressedTileStorage* copyFrom) { #endif } -CompressedTileStorage::CompressedTileStorage(byteArray initFrom, +CompressedTileStorage::CompressedTileStorage(std::vector& initFrom, unsigned int initOffset) { indicesAndData = nullptr; allocatedSize = 0; @@ -68,7 +68,7 @@ CompressedTileStorage::CompressedTileStorage(byteArray initFrom, for (int i = 0; i < 512; i++) { indices[i] = INDEX_TYPE_0_OR_8_BIT | (offset << 1); - if (initFrom.data) { + if (!initFrom.empty()) { for (int j = 0; j < 64; j++) { *data++ = initFrom[getIndex(i, j) + initOffset]; } @@ -236,11 +236,11 @@ inline void CompressedTileStorage::getBlock(int* block, int x, int y, int z) { } // Set all tile values from a data array of length 32768 (128 x 16 x 16). -void CompressedTileStorage::setData(byteArray dataIn, unsigned int inOffset) { +void CompressedTileStorage::setData(std::vector& dataIn, unsigned int inOffset) { unsigned short _blockIndices[512]; std::lock_guard lock(cs_write); - unsigned char* data = dataIn.data + inOffset; + unsigned char* data = dataIn.data() + inOffset; // Is the destination fully uncompressed? If so just write our data in - // this happens when writing schematics and we don't want this setting of @@ -407,13 +407,13 @@ void CompressedTileStorage::setData(byteArray dataIn, unsigned int inOffset) { // AP - When called in pairs from LevelChunk::getBlockData this version of // getData reduces the time from ~5.2ms to ~1.6ms on the Vita Gets all tile // values into an array of length 32768. -void CompressedTileStorage::getData(byteArray retArray, +void CompressedTileStorage::getData(std::vector& retArray, unsigned int retOffset) { unsigned short* blockIndices = (unsigned short*)indicesAndData; unsigned char* data = indicesAndData + 1024; int k = 0; - unsigned char* Array = &retArray.data[retOffset]; + unsigned char* Array = &retArray.data()[retOffset]; int* Table = CompressedTile_StorageIndexTable; for (int i = 0; i < 512; i++) { int indexType = blockIndices[i] & INDEX_TYPE_MASK; @@ -478,7 +478,7 @@ void CompressedTileStorage::getData(byteArray retArray, #else // Gets all tile values into an array of length 32768. -void CompressedTileStorage::getData(byteArray retArray, +void CompressedTileStorage::getData(std::vector& retArray, unsigned int retOffset) { unsigned short* blockIndices = (unsigned short*)indicesAndData; unsigned char* data = indicesAndData + 1024; @@ -663,12 +663,12 @@ void CompressedTileStorage::set(int x, int y, int z, int val) { // Sets a region of tile values with the data at offset position in the array // dataIn - external ordering compatible with java DataLayer -int CompressedTileStorage::setDataRegion(byteArray dataIn, int x0, int y0, +int CompressedTileStorage::setDataRegion(std::vector& dataIn, int x0, int y0, int z0, int x1, int y1, int z1, int offset, tileUpdatedCallback callback, void* param, int yparam) { - unsigned char* pucIn = &dataIn.data[offset]; + unsigned char* pucIn = &dataIn.data()[offset]; if (callback) { for (int x = x0; x < x1; x++) { @@ -691,16 +691,16 @@ int CompressedTileStorage::setDataRegion(byteArray dataIn, int x0, int y0, } } } - ptrdiff_t count = pucIn - &dataIn.data[offset]; + ptrdiff_t count = pucIn - &dataIn.data()[offset]; return (int)count; } // Tests whether setting data would actually change anything -bool CompressedTileStorage::testSetDataRegion(byteArray dataIn, int x0, int y0, +bool CompressedTileStorage::testSetDataRegion(std::vector& dataIn, int x0, int y0, int z0, int x1, int y1, int z1, int offset) { - unsigned char* pucIn = &dataIn.data[offset]; + unsigned char* pucIn = &dataIn.data()[offset]; for (int x = x0; x < x1; x++) { for (int z = z0; z < z1; z++) { for (int y = y0; y < y1; y++) { @@ -715,10 +715,10 @@ bool CompressedTileStorage::testSetDataRegion(byteArray dataIn, int x0, int y0, // Updates the data at offset position dataInOut with a region of tile // information - external ordering compatible with java DataLayer -int CompressedTileStorage::getDataRegion(byteArray dataInOut, int x0, int y0, +int CompressedTileStorage::getDataRegion(std::vector& dataInOut, int x0, int y0, int z0, int x1, int y1, int z1, int offset) { - unsigned char* pucOut = &dataInOut.data[offset]; + unsigned char* pucOut = &dataInOut.data()[offset]; for (int x = x0; x < x1; x++) { for (int z = z0; z < z1; z++) { for (int y = y0; y < y1; y++) { @@ -726,7 +726,7 @@ int CompressedTileStorage::getDataRegion(byteArray dataInOut, int x0, int y0, } } } - ptrdiff_t count = pucOut - &dataInOut.data[offset]; + ptrdiff_t count = pucOut - &dataInOut.data()[offset]; return (int)count; } @@ -1194,20 +1194,19 @@ void CompressedTileStorage::write(DataOutputStream* dos) { if (LOCALSYTEM_ENDIAN == BIGENDIAN) { // The first 1024 bytes are an array of shorts, so we need to // reverse the endianness - byteArray indicesCopy(1024); - memcpy(indicesCopy.data, indicesAndData, 1024); - reverseIndices(indicesCopy.data); + std::vector indicesCopy(1024); + memcpy(indicesCopy.data(), indicesAndData, 1024); + reverseIndices(indicesCopy.data()); dos->write(indicesCopy); - delete[] indicesCopy.data; // Write the rest of the data if (allocatedSize > 1024) { - byteArray dataWrapper(indicesAndData + 1024, - allocatedSize - 1024); + std::vector dataWrapper(indicesAndData + 1024, + indicesAndData + allocatedSize); dos->write(dataWrapper); } } else { - byteArray wrapper(indicesAndData, allocatedSize); + std::vector wrapper(indicesAndData, indicesAndData + allocatedSize); dos->write(wrapper); } } @@ -1225,8 +1224,9 @@ void CompressedTileStorage::read(DataInputStream* dis) { indicesAndData = (unsigned char*)XPhysicalAlloc( allocatedSize, MAXULONG_PTR, 4096, PAGE_READWRITE); - byteArray wrapper(indicesAndData, allocatedSize); + std::vector wrapper(allocatedSize); dis->readFully(wrapper); + memcpy(indicesAndData, wrapper.data(), allocatedSize); if (LOCALSYTEM_ENDIAN == BIGENDIAN) { reverseIndices(indicesAndData); } diff --git a/minecraft/Minecraft.World/net/minecraft/world/level/chunk/CompressedTileStorage.h b/minecraft/Minecraft.World/net/minecraft/world/level/chunk/CompressedTileStorage.h index 66452e5a5..a4fd03376 100644 --- a/minecraft/Minecraft.World/net/minecraft/world/level/chunk/CompressedTileStorage.h +++ b/minecraft/Minecraft.World/net/minecraft/world/level/chunk/CompressedTileStorage.h @@ -103,7 +103,7 @@ public: CompressedTileStorage( CompressedTileStorage* copyFrom); // ctor with deep copy CompressedTileStorage( - byteArray dataIn, + std::vector& dataIn, unsigned int initOffset); // Construct with data in passed in array of // length 32768 (128 x 16 x 16) CompressedTileStorage(bool isEmpty); @@ -119,10 +119,10 @@ private: public: void setData( - byteArray dataIn, + std::vector& dataIn, unsigned int inOffset); // Set all tile values from a data array of // length 32768 (128 x 16 x 16). - void getData(byteArray retArray, + void getData(std::vector& retArray, unsigned int retOffset); // Gets all tile values into an array // of length 32768. int get(int x, int y, int z); // Get an individual tile value @@ -130,17 +130,17 @@ public: typedef void (*tileUpdatedCallback)(int x, int y, int z, void* param, int yparam); int setDataRegion( - byteArray dataIn, int x0, int y0, int z0, int x1, int y1, int z1, + std::vector& dataIn, int x0, int y0, int z0, int x1, int y1, int z1, int offset, tileUpdatedCallback callback, void* param, int yparam); // Sets a region of tile values with the data at offset // position in the array dataIn - external ordering // compatible with java DataLayer - bool testSetDataRegion(byteArray dataIn, int x0, int y0, int z0, int x1, + bool testSetDataRegion(std::vector& dataIn, int x0, int y0, int z0, int x1, int y1, int z1, int offset); // Tests whether setting data would // actually change anything int getDataRegion( - byteArray dataInOut, int x0, int y0, int z0, int x1, int y1, int z1, + std::vector& dataInOut, int x0, int y0, int z0, int x1, int y1, int z1, int offset); // Updates the data at offset position dataInOut with a // region of tile information - external ordering // compatible with java DataLayer diff --git a/minecraft/Minecraft.World/net/minecraft/world/level/chunk/DataLayer.cpp b/minecraft/Minecraft.World/net/minecraft/world/level/chunk/DataLayer.cpp index 24c50c0ca..f90ab5b9b 100644 --- a/minecraft/Minecraft.World/net/minecraft/world/level/chunk/DataLayer.cpp +++ b/minecraft/Minecraft.World/net/minecraft/world/level/chunk/DataLayer.cpp @@ -3,15 +3,14 @@ DataLayer::DataLayer(int length, int depthBits) : depthBits(depthBits), depthBitsPlusFour(depthBits + 4) { - data = byteArray(length >> 1); + data = std::vector(length >> 1); } -DataLayer::DataLayer(byteArray data, int depthBits) +DataLayer::DataLayer(std::vector& data, int depthBits) : depthBits(depthBits), depthBitsPlusFour(depthBits + 4) { this->data = data; } -DataLayer::~DataLayer() { delete[] data.data; } int DataLayer::get(int x, int y, int z) { int pos = (x << depthBitsPlusFour | z << depthBits | y); @@ -38,11 +37,11 @@ void DataLayer::set(int x, int y, int z, int val) { } } -bool DataLayer::isValid() { return data.data != nullptr; } +bool DataLayer::isValid() { return !data.empty(); } void DataLayer::setAll(int br) { uint8_t val = (uint8_t)(br & (br << 4)); - for (unsigned int i = 0; i < data.length; i++) { + for (unsigned int i = 0; i < data.size(); i++) { data[i] = val; } } \ No newline at end of file diff --git a/minecraft/Minecraft.World/net/minecraft/world/level/chunk/DataLayer.h b/minecraft/Minecraft.World/net/minecraft/world/level/chunk/DataLayer.h index f6e2ed9bf..1c96af9ce 100644 --- a/minecraft/Minecraft.World/net/minecraft/world/level/chunk/DataLayer.h +++ b/minecraft/Minecraft.World/net/minecraft/world/level/chunk/DataLayer.h @@ -2,7 +2,7 @@ class DataLayer { public: - byteArray data; + std::vector data; private: const int depthBits; @@ -10,7 +10,7 @@ private: public: DataLayer(int length, int depthBits); - DataLayer(byteArray data, int depthBits); + DataLayer(std::vector& data, int depthBits); ~DataLayer(); int get(int x, int y, int z); diff --git a/minecraft/Minecraft.World/net/minecraft/world/level/chunk/EmptyLevelChunk.cpp b/minecraft/Minecraft.World/net/minecraft/world/level/chunk/EmptyLevelChunk.cpp index 519f2cee7..7b9fb695f 100644 --- a/minecraft/Minecraft.World/net/minecraft/world/level/chunk/EmptyLevelChunk.cpp +++ b/minecraft/Minecraft.World/net/minecraft/world/level/chunk/EmptyLevelChunk.cpp @@ -13,10 +13,9 @@ EmptyLevelChunk::EmptyLevelChunk(Level* level, int x, int z) LevelChunk::sTerrainPostPostProcessed; } -EmptyLevelChunk::EmptyLevelChunk(Level* level, byteArray blocks, int x, int z) +EmptyLevelChunk::EmptyLevelChunk(Level* level, std::vector& blocks, int x, int z) : LevelChunk(level, blocks, x, z) { dontSave = true; - delete[] blocks.data; // Set this as fully post-processed, so we don't try and run post-processing // on any edge chunks that will overlap into real chunks terrainPopulated = LevelChunk::sTerrainPopulatedAllNeighbours | @@ -118,9 +117,9 @@ int EmptyLevelChunk::countEntities() { return 0; } bool EmptyLevelChunk::shouldSave(bool force) { return false; } -void EmptyLevelChunk::setBlocks(byteArray newBlocks, int sub) {} +void EmptyLevelChunk::setBlocks(std::vector& newBlocks, int sub) {} -int EmptyLevelChunk::getBlocksAndData(byteArray data, int x0, int y0, int z0, +int EmptyLevelChunk::getBlocksAndData(std::vector& data, int x0, int y0, int z0, int x1, int y1, int z1, int p, bool includeLighting /* = true*/) { int xs = x1 - x0; @@ -139,7 +138,7 @@ int EmptyLevelChunk::getBlocksAndData(byteArray data, int x0, int y0, int z0, return len; } -int EmptyLevelChunk::setBlocksAndData(byteArray data, int x0, int y0, int z0, +int EmptyLevelChunk::setBlocksAndData(std::vector& data, int x0, int y0, int z0, int x1, int y1, int z1, int p, bool includeLighting /* = true*/) { int xs = x1 - x0; @@ -154,7 +153,7 @@ int EmptyLevelChunk::setBlocksAndData(byteArray data, int x0, int y0, int z0, } } -bool EmptyLevelChunk::testSetBlocksAndData(byteArray data, int x0, int y0, +bool EmptyLevelChunk::testSetBlocksAndData(std::vector& data, int x0, int y0, int z0, int x1, int y1, int z1, int p) { return false; diff --git a/minecraft/Minecraft.World/net/minecraft/world/level/chunk/EmptyLevelChunk.h b/minecraft/Minecraft.World/net/minecraft/world/level/chunk/EmptyLevelChunk.h index eaa165237..1a025aacc 100644 --- a/minecraft/Minecraft.World/net/minecraft/world/level/chunk/EmptyLevelChunk.h +++ b/minecraft/Minecraft.World/net/minecraft/world/level/chunk/EmptyLevelChunk.h @@ -11,7 +11,7 @@ public: using LevelChunk::getEntitiesOfClass; EmptyLevelChunk(Level* level, int x, int z); - EmptyLevelChunk(Level* level, byteArray blocks, int x, int z); + EmptyLevelChunk(Level* level, std::vector& blocks, int x, int z); bool isAt(int x, int z); int getHeightmap(int x, int z); void recalcBlockLights(); @@ -52,14 +52,14 @@ public: EntitySelector* selector); int countEntities(); bool shouldSave(bool force); - void setBlocks(byteArray newBlocks, int sub); + void setBlocks(std::vector& newBlocks, int sub); int getBlocksAndData( - byteArray data, int x0, int y0, int z0, int x1, int y1, int z1, int p, + std::vector& data, int x0, int y0, int z0, int x1, int y1, int z1, int p, bool includeLighting = true); // 4J - added includeLighting parameter int setBlocksAndData( - byteArray data, int x0, int y0, int z0, int x1, int y1, int z1, int p, + std::vector& data, int x0, int y0, int z0, int x1, int y1, int z1, int p, bool includeLighting = true); // 4J - added includeLighting parameter - bool testSetBlocksAndData(byteArray data, int x0, int y0, int z0, int x1, + bool testSetBlocksAndData(std::vector& data, int x0, int y0, int z0, int x1, int y1, int z1, int p); // 4J added Random* getRandom(int64_t l); bool isEmpty(); diff --git a/minecraft/Minecraft.World/net/minecraft/world/level/chunk/LevelChunk.cpp b/minecraft/Minecraft.World/net/minecraft/world/level/chunk/LevelChunk.cpp index e46b0c1e0..324c19a66 100644 --- a/minecraft/Minecraft.World/net/minecraft/world/level/chunk/LevelChunk.cpp +++ b/minecraft/Minecraft.World/net/minecraft/world/level/chunk/LevelChunk.cpp @@ -31,7 +31,7 @@ bool LevelChunk::touchedSky = false; void LevelChunk::staticCtor() {} void LevelChunk::init(Level* level, int x, int z) { - biomes = byteArray(16 * 16); + biomes = std::vector(16 * 16); for (int i = 0; i < 16 * 16; i++) { biomes[i] = 0xff; } @@ -58,7 +58,7 @@ void LevelChunk::init(Level* level, int x, int z) { this->x = x; this->z = z; MemSect(1); - heightmap = byteArray(16 * 16); + heightmap = std::vector(16 * 16); { std::lock_guard lock(m_csEntities); for (int i = 0; i < ENTITY_BLOCKS_LENGTH; i++) { @@ -127,7 +127,7 @@ LevelChunk::LevelChunk(Level* level, int x, int z) // 4J - note that since we now compress the block storage, the parameter blocks // is used as a source of data, but doesn't get used As the source data so needs // to be deleted after calling this ctor. -LevelChunk::LevelChunk(Level* level, byteArray blocks, int x, int z) +LevelChunk::LevelChunk(Level* level, std::vector& blocks, int x, int z) : ENTITY_BLOCKS_LENGTH(Level::maxBuildHeight / 16) { init(level, x, z); @@ -137,7 +137,7 @@ LevelChunk::LevelChunk(Level* level, byteArray blocks, int x, int z) // all data as empty/compressed as possible. On the client we get the full // data for the chunk as a single update in a block region update packet, // and so there is a single point where it is good to compress the data. - bool createEmpty = (blocks.data == nullptr); + bool createEmpty = blocks.empty(); if (createEmpty) { lowerBlocks = new CompressedTileStorage(true); @@ -153,11 +153,11 @@ LevelChunk::LevelChunk(Level* level, byteArray blocks, int x, int z) lowerSkyLight = new SparseLightStorage(true); lowerBlockLight = new SparseLightStorage(false); } - // skyLight = new DataLayer(blocks.length, level->depthBits); - // blockLight = new DataLayer(blocks.length, level->depthBits); + // skyLight = new DataLayer(blocks.size(), level->depthBits); + // blockLight = new DataLayer(blocks.size(), level->depthBits); if (Level::maxBuildHeight > Level::COMPRESSED_CHUNK_SECTION_HEIGHT) { - if (blocks.length > Level::COMPRESSED_CHUNK_SECTION_TILES) + if (blocks.size() > Level::COMPRESSED_CHUNK_SECTION_TILES) upperBlocks = new CompressedTileStorage( blocks, Level::COMPRESSED_CHUNK_SECTION_TILES); else @@ -187,7 +187,7 @@ LevelChunk::LevelChunk(Level* level, int x, int z, LevelChunk* lc) init(level, x, z); // 4J Stu - Copy over the biome data - memcpy(biomes.data, lc->biomes.data, biomes.length); + memcpy(biomes.data(), lc->biomes.data(), biomes.size()); #if defined(SHARING_ENABLED) lowerBlocks = lc->lowerBlocks; @@ -270,13 +270,13 @@ void LevelChunk::stopSharingTilesAndData() { } /* - newDataLayer = new DataLayer(skyLight->data.length*2, level->depthBits); - XMemCpy(newDataLayer->data.data, skyLight->data.data, - skyLight->data.length); skyLight = newDataLayer; + newDataLayer = new DataLayer(skyLight->data.size()*2, level->depthBits); + XMemCpy(newDataLayer->data.data(), skyLight->data.data(), + skyLight->data.size()); skyLight = newDataLayer; - newDataLayer = new DataLayer(blockLight->data.length*2, - level->depthBits); XMemCpy(newDataLayer->data.data, - blockLight->data.data, blockLight->data.length); blockLight = + newDataLayer = new DataLayer(blockLight->data.size()*2, + level->depthBits); XMemCpy(newDataLayer->data.data(), + blockLight->data.data(), blockLight->data.size()); blockLight = newDataLayer; */ @@ -417,12 +417,10 @@ LevelChunk::~LevelChunk() { if (upperSkyLight) delete upperSkyLight; if (upperBlockLight) delete upperBlockLight; - delete[] heightmap.data; for (int i = 0; i < ENTITY_BLOCKS_LENGTH; ++i) delete entityBlocks[i]; delete[] entityBlocks; - delete[] biomes.data; #if defined(_LARGE_WORLDS) delete m_unloadedEntitiesTag; @@ -438,7 +436,7 @@ int LevelChunk::getHeightmap(int x, int z) { int LevelChunk::getHighestSectionPosition() { return Level::maxBuildHeight - 16; // 4J Stu - Unused - // for (int i = sections.length - 1; i >= 0; i--) { + // for (int i = sections.size() - 1; i >= 0; i--) { // if (sections[i] != null) { // && !sections[i].isEmpty()) { // return sections[i].getYPosition(); // } @@ -1633,7 +1631,7 @@ bool LevelChunk::shouldSave(bool force) { return m_unsaved; } -int LevelChunk::getBlocksAndData(byteArray* data, int x0, int y0, int z0, +int LevelChunk::getBlocksAndData(std::vector* data, int x0, int y0, int z0, int x1, int y1, int z1, int p, bool includeLighting /* = true*/) { int xs = x1 - x0; @@ -1704,7 +1702,7 @@ int LevelChunk::getBlocksAndData(byteArray* data, int x0, int y0, int z0, } // 4J added - return true if setBlocksAndData would change any blocks -bool LevelChunk::testSetBlocksAndData(byteArray data, int x0, int y0, int z0, +bool LevelChunk::testSetBlocksAndData(std::vector& data, int x0, int y0, int z0, int x1, int y1, int z1, int p) { bool changed = false; @@ -1733,7 +1731,7 @@ void LevelChunk::tileUpdatedCallback(int x, int y, int z, void* param, lc->level->checkLight(xx, yy, zz); } -int LevelChunk::setBlocksAndData(byteArray data, int x0, int y0, int z0, int x1, +int LevelChunk::setBlocksAndData(std::vector& data, int x0, int y0, int z0, int x1, int y1, int z1, int p, bool includeLighting /* = true*/) { // If includeLighting is set, then this is a full chunk's worth of data that @@ -1744,7 +1742,7 @@ int LevelChunk::setBlocksAndData(byteArray data, int x0, int y0, int z0, int x1, // in anyway. if (includeLighting) { GameRenderer::AddForDelete(lowerBlocks); - byteArray emptyByteArray; + std::vector emptyByteArray; lowerBlocks = new CompressedTileStorage(emptyByteArray, 0); GameRenderer::FinishedReassigning(); @@ -1819,8 +1817,8 @@ int LevelChunk::setBlocksAndData(byteArray data, int x0, int y0, int z0, int x1, data, x0, std::max(y0 - compressedHeight, 0), z0, x1, y1 - Level::COMPRESSED_CHUNK_SECTION_HEIGHT, z1, p); - memcpy(biomes.data, &data.data[p], biomes.length); - p += biomes.length; + memcpy(biomes.data(), &data.data()[p], biomes.size()); + p += biomes.size(); } else { // Because the host's local client shares data with it, the lighting // updates that are done via callbacks in the setDataRegion calls above @@ -1991,10 +1989,9 @@ Biome* LevelChunk::getBiome(int x, int z, BiomeSource* biomeSource) { return Biome::biomes[value]; } -byteArray LevelChunk::getBiomes() { return biomes; } +std::vector LevelChunk::getBiomes() { return biomes; } -void LevelChunk::setBiomes(byteArray biomes) { - if (this->biomes.data != nullptr) delete[] this->biomes.data; +void LevelChunk::setBiomes(std::vector& biomes) { this->biomes = biomes; } @@ -2050,7 +2047,7 @@ void LevelChunk::updateBiomeFlags(int x, int z) { if ((columnFlags[slot] & (eColumnFlag_biomeOk << shift)) == 0) { int xOffs = (this->x * 16) + x; int zOffs = (this->z * 16) + z; - BiomeArray biomes; + std::vector biomes; level->getBiomeSource()->getBiomeBlock(biomes, xOffs, zOffs, 1, 1, true); if (biomes[0]->hasRain()) @@ -2058,65 +2055,64 @@ void LevelChunk::updateBiomeFlags(int x, int z) { if (biomes[0]->hasSnow()) columnFlags[slot] |= (eColumnFlag_biomeHasSnow << shift); columnFlags[slot] |= (eColumnFlag_biomeOk << shift); - delete biomes.data; } } // Get a byte array of length 16384 ( 128 x 16 x 16 x 0.5 ), containing data. // Ordering same as java version if originalOrder set; -void LevelChunk::getDataData(byteArray data) { +void LevelChunk::getDataData(std::vector& data) { lowerData->getData(data, 0); - if (data.length > Level::COMPRESSED_CHUNK_SECTION_TILES / 2) + if (data.size() > Level::COMPRESSED_CHUNK_SECTION_TILES / 2) upperData->getData(data, Level::COMPRESSED_CHUNK_SECTION_TILES / 2); } // Set data to data passed in input byte array of length 16384. This data must // be in original (java version) order if originalOrder set. -void LevelChunk::setDataData(byteArray data) { +void LevelChunk::setDataData(std::vector& data) { if (lowerData == nullptr) lowerData = new SparseDataStorage(); if (upperData == nullptr) upperData = new SparseDataStorage(true); lowerData->setData(data, 0); - if (data.length > Level::COMPRESSED_CHUNK_SECTION_TILES / 2) + if (data.size() > Level::COMPRESSED_CHUNK_SECTION_TILES / 2) upperData->setData(data, Level::COMPRESSED_CHUNK_SECTION_TILES / 2); } // Get a byte array of length 16384 ( 128 x 16 x 16 x 0.5 ), containing sky // light data. Ordering same as java version if originalOrder set; -void LevelChunk::getSkyLightData(byteArray data) { +void LevelChunk::getSkyLightData(std::vector& data) { lowerSkyLight->getData(data, 0); - if (data.length > Level::COMPRESSED_CHUNK_SECTION_TILES / 2) + if (data.size() > Level::COMPRESSED_CHUNK_SECTION_TILES / 2) upperSkyLight->getData(data, Level::COMPRESSED_CHUNK_SECTION_TILES / 2); } // Get a byte array of length 16384 ( 128 x 16 x 16 x 0.5 ), containing block // light data. Ordering same as java version if originalOrder set; -void LevelChunk::getBlockLightData(byteArray data) { +void LevelChunk::getBlockLightData(std::vector& data) { lowerBlockLight->getData(data, 0); - if (data.length > Level::COMPRESSED_CHUNK_SECTION_TILES / 2) + if (data.size() > Level::COMPRESSED_CHUNK_SECTION_TILES / 2) upperBlockLight->getData(data, Level::COMPRESSED_CHUNK_SECTION_TILES / 2); } // Set sky light data to data passed in input byte array of length 16384. This // data must be in original (java version) order if originalOrder set. -void LevelChunk::setSkyLightData(byteArray data) { +void LevelChunk::setSkyLightData(std::vector& data) { if (lowerSkyLight == nullptr) lowerSkyLight = new SparseLightStorage(true); if (upperSkyLight == nullptr) upperSkyLight = new SparseLightStorage(true, true); lowerSkyLight->setData(data, 0); - if (data.length > Level::COMPRESSED_CHUNK_SECTION_TILES / 2) + if (data.size() > Level::COMPRESSED_CHUNK_SECTION_TILES / 2) upperSkyLight->setData(data, Level::COMPRESSED_CHUNK_SECTION_TILES / 2); } // Set block light data to data passed in input byte array of length 16384. This // data must be in original (java version) order if originalOrder set. -void LevelChunk::setBlockLightData(byteArray data) { +void LevelChunk::setBlockLightData(std::vector& data) { if (lowerBlockLight == nullptr) lowerBlockLight = new SparseLightStorage(false); if (upperBlockLight == nullptr) upperBlockLight = new SparseLightStorage(false, true); lowerBlockLight->setData(data, 0); - if (data.length > Level::COMPRESSED_CHUNK_SECTION_TILES / 2) + if (data.size() > Level::COMPRESSED_CHUNK_SECTION_TILES / 2) upperBlockLight->setData(data, Level::COMPRESSED_CHUNK_SECTION_TILES / 2); } @@ -2291,16 +2287,16 @@ bool LevelChunk::isRenderChunkEmpty(int y) { } // Set block data to that passed in in the input array of size 32768 -void LevelChunk::setBlockData(byteArray data) { +void LevelChunk::setBlockData(std::vector& data) { lowerBlocks->setData(data, 0); - if (data.length > Level::COMPRESSED_CHUNK_SECTION_TILES) + if (data.size() > Level::COMPRESSED_CHUNK_SECTION_TILES) upperBlocks->setData(data, Level::COMPRESSED_CHUNK_SECTION_TILES); } // Sets data in passed in array of size 32768, from the block data in this chunk -void LevelChunk::getBlockData(byteArray data) { +void LevelChunk::getBlockData(std::vector& data) { lowerBlocks->getData(data, 0); - if (data.length > Level::COMPRESSED_CHUNK_SECTION_TILES) + if (data.size() > Level::COMPRESSED_CHUNK_SECTION_TILES) upperBlocks->getData(data, Level::COMPRESSED_CHUNK_SECTION_TILES); } @@ -2326,7 +2322,7 @@ int LevelChunk::getHighestNonEmptyY() { return highestNonEmptyY; } -byteArray LevelChunk::getReorderedBlocksAndData(int x0, int y0, int z0, int xs, +std::vector LevelChunk::getReorderedBlocksAndData(int x0, int y0, int z0, int xs, int& ys, int zs) { int highestNonEmpty = getHighestNonEmptyY(); @@ -2340,7 +2336,7 @@ byteArray LevelChunk::getReorderedBlocksAndData(int x0, int y0, int z0, int xs, unsigned int tileCount = xs * ys * zs; unsigned int halfTileCount = tileCount / 2; - byteArray data = byteArray(tileCount + (3 * halfTileCount) + biomes.length); + std::vector data = std::vector(tileCount + (3 * halfTileCount) + biomes.size()); for (int x = 0; x < xs; x++) { for (int z = 0; z < zs; z++) { for (int y = 0; y < ys; y++) { @@ -2384,11 +2380,11 @@ byteArray LevelChunk::getReorderedBlocksAndData(int x0, int y0, int z0, int xs, data, x0, std::max(y0 - compressedHeight, 0), z0, x1, y1 - Level::COMPRESSED_CHUNK_SECTION_HEIGHT, z1, p); - memcpy(&data.data[p], biomes.data, biomes.length); + memcpy(&data.data()[p], biomes.data(), biomes.size()); return data; - // byteArray rawBuffer = byteArray( Level::CHUNK_TILE_COUNT + (3* + // std::vector rawBuffer = std::vector( Level::CHUNK_TILE_COUNT + (3* // Level::HALF_CHUNK_TILE_COUNT) ); for( int x = 0; x < 16; x++ ) //{ // for( int z = 0; z < 16; z++ ) @@ -2405,19 +2401,19 @@ byteArray LevelChunk::getReorderedBlocksAndData(int x0, int y0, int z0, int xs, // unsigned int offset = Level::CHUNK_TILE_COUNT; //// Don't bother reordering block data, block light or sky light as they /// don't seem to make much difference - // byteArray dataData = byteArray(rawBuffer.data+offset, + // std::vector dataData = std::vector(rawBuffer.data()+offset, // Level::HALF_CHUNK_TILE_COUNT); lc->getDataData(dataData); offset += - // Level::HALF_CHUNK_TILE_COUNT; byteArray blockLightData = - // byteArray(rawBuffer.data + offset, Level::HALF_CHUNK_TILE_COUNT); offset - // += Level::HALF_CHUNK_TILE_COUNT; byteArray skyLightData = - // byteArray(rawBuffer.data + offset, Level::HALF_CHUNK_TILE_COUNT); + // Level::HALF_CHUNK_TILE_COUNT; std::vector blockLightData = + // std::vector(rawBuffer.data() + offset, Level::HALF_CHUNK_TILE_COUNT); offset + // += Level::HALF_CHUNK_TILE_COUNT; std::vector skyLightData = + // std::vector(rawBuffer.data() + offset, Level::HALF_CHUNK_TILE_COUNT); // lc->getBlockLightData(blockLightData); // lc->getSkyLightData(skyLightData); // return rawBuffer; } void LevelChunk::reorderBlocksAndDataToXZY(int y0, int xs, int ys, int zs, - byteArray* data) { + std::vector* data) { int y1 = y0 + ys; unsigned int tileCount = xs * ys * zs; unsigned int halfTileCount = tileCount / 2; @@ -2428,8 +2424,8 @@ void LevelChunk::reorderBlocksAndDataToXZY(int y0, int xs, int ys, int zs, int upperSlotOffset = xs * zs * lowerYSpan; int biomesLength = 16 * 16; - byteArray newBuffer = - byteArray(tileCount + (3 * halfTileCount) + biomesLength); + std::vector newBuffer = + std::vector(tileCount + (3 * halfTileCount) + biomesLength); for (int x = 0; x < xs; x++) { for (int z = 0; z < zs; z++) { for (int y = 0; y < ys; y++) { @@ -2444,15 +2440,14 @@ void LevelChunk::reorderBlocksAndDataToXZY(int y0, int xs, int ys, int zs, int slot = (x * zs * ySpan) + (z * ySpan) + slotY; int slot2 = (y * xs * zs) + (z * xs) + x; - newBuffer[slot + targetSlotOffset] = data->data[slot2]; + newBuffer[slot + targetSlotOffset] = (*data)[slot2]; } } } // Copy over block data, block light, skylight and biomes as-is - memcpy(newBuffer.data + tileCount, data->data + tileCount, + memcpy(newBuffer.data() + tileCount, data->data() + tileCount, 3 * halfTileCount + biomesLength); - delete[] data->data; - data->data = newBuffer.data; + *data = std::move(newBuffer); // int p = 0; // setBlocksAndData(*data, x0, y0, z0, x1, y1, z1, p); @@ -2462,7 +2457,7 @@ void LevelChunk::reorderBlocksAndDataToXZY(int y0, int xs, int ys, int zs, // if( xs == 16 && ys == 128 && zs == 16 && ( ( x & 15 ) == 0 ) && ( y == 0 // ) && ( ( z & 15 ) == 0 ) ) //{ - // byteArray newBuffer = byteArray(81920); + // std::vector newBuffer = std::vector(81920); // for( int x = 0; x < 16; x++ ) // { // for( int z = 0; z < 16; z++ ) @@ -2477,8 +2472,8 @@ void LevelChunk::reorderBlocksAndDataToXZY(int y0, int xs, int ys, int zs, // } // } // // Copy over block data, block light & skylight as-is - // memcpy(newBuffer.data + 32768, buffer.data + 32768, 49152); - // delete buffer.data; - // buffer.data = newBuffer.data; + // memcpy(newBuffer.data() + 32768, buffer.data() + 32768, 49152); + // delete buffer.data(); + // buffer.data() = newBuffer.data(); //} } diff --git a/minecraft/Minecraft.World/net/minecraft/world/level/chunk/LevelChunk.h b/minecraft/Minecraft.World/net/minecraft/world/level/chunk/LevelChunk.h index 7c0a55feb..bd183c9ef 100644 --- a/minecraft/Minecraft.World/net/minecraft/world/level/chunk/LevelChunk.h +++ b/minecraft/Minecraft.World/net/minecraft/world/level/chunk/LevelChunk.h @@ -24,7 +24,7 @@ class LevelChunk { friend class LevelRenderer; public: - byteArray biomes; // 4J Stu - Made public + std::vector biomes; // 4J Stu - Made public // 4J Stu - No longer static in 1.8.2 const int ENTITY_BLOCKS_LENGTH; @@ -39,7 +39,7 @@ public: eColumnFlag_biomeHasRain = 8, }; - // byteArray blocks; + // std::vector blocks; // 4J - actual storage for blocks is now private with public methods to // access it private: @@ -47,10 +47,10 @@ private: CompressedTileStorage* upperBlocks; // 128 - 255 public: bool isRenderChunkEmpty(int y); - void setBlockData(byteArray data); // Set block data to that passed in in + void setBlockData(std::vector& data); // Set block data to that passed in in // the input array of size 32768 void getBlockData( - byteArray data); // Sets data in passed in array of size 32768, from + std::vector& data); // Sets data in passed in array of size 32768, from // the block data in this chunk int getBlocksAllocatedSize(int* count0, int* count1, int* count2, int* count4, int* count8); @@ -71,9 +71,9 @@ private: SparseDataStorage* lowerData; // 0 - 127 SparseDataStorage* upperData; // 128 - 255 public: - void setDataData(byteArray data); // Set data to that passed in in the + void setDataData(std::vector& data); // Set data to that passed in in the // input array of size 32768 - void getDataData(byteArray data); // Sets data in passed in array of size + void getDataData(std::vector& data); // Sets data in passed in array of size // 16384, from the data in this chunk // DataLayer *data; @@ -87,19 +87,19 @@ private: SparseLightStorage* upperBlockLight; // 128 - 255 public: void getSkyLightData( - byteArray + std::vector& 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. void getBlockLightData( - byteArray data); // Get a byte array of length 16384 ( 128 x 16 x 16 x + std::vector& 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. void setSkyLightData( - byteArray data); // Set sky light data to data passed in input byte + std::vector& data); // Set sky light data to data passed in input byte // array of length 16384. This data must be in // original (java version) order void setBlockLightData( - byteArray data); // Set block light data to data passed in input byte + std::vector& data); // Set block light data to data passed in input byte // array of length 16384. This data must be in // original (java version) order void setSkyLightDataAllBright(); // Set sky light data to be all fully lit @@ -117,7 +117,7 @@ public: void readCompressedSkyLightData(DataInputStream* dis); void readCompressedBlockLightData(DataInputStream* dis); - byteArray heightmap; + std::vector heightmap; int minHeight; int x, z; @@ -185,7 +185,7 @@ private: public: virtual void init(Level* level, int x, int z); LevelChunk(Level* level, int x, int z); - LevelChunk(Level* level, byteArray blocks, int x, int z); + LevelChunk(Level* level, std::vector& blocks, int x, int z); LevelChunk(Level* level, int x, int z, LevelChunk* lc); virtual ~LevelChunk(); @@ -253,14 +253,14 @@ public: virtual int countEntities(); virtual bool shouldSave(bool force); virtual int getBlocksAndData( - byteArray* data, int x0, int y0, int z0, int x1, int y1, int z1, int p, + std::vector* data, int x0, int y0, int z0, int x1, int y1, int z1, int p, bool includeLighting = true); // 4J - added includeLighting parameter static void tileUpdatedCallback(int x, int y, int z, void* param, int yparam); // 4J added virtual int setBlocksAndData( - byteArray data, int x0, int y0, int z0, int x1, int y1, int z1, int p, + std::vector& data, int x0, int y0, int z0, int x1, int y1, int z1, int p, bool includeLighting = true); // 4J - added includeLighting parameter - virtual bool testSetBlocksAndData(byteArray data, int x0, int y0, int z0, + virtual bool testSetBlocksAndData(std::vector& data, int x0, int y0, int z0, int x1, int y1, int z1, int p); // 4J added virtual void setCheckAllLight(); @@ -286,8 +286,8 @@ public: bool isYSpaceEmpty(int y1, int y2); void reloadBiomes(); // 4J added virtual Biome* getBiome(int x, int z, BiomeSource* biomeSource); - byteArray getBiomes(); - void setBiomes(byteArray biomes); + std::vector getBiomes(); + void setBiomes(std::vector& biomes); bool biomeHasRain(int x, int z); // 4J added bool biomeHasSnow(int x, int z); // 4J added private: @@ -297,10 +297,10 @@ public: void compressBlocks(); // 4J added void compressData(); // 4J added int getHighestNonEmptyY(); - byteArray getReorderedBlocksAndData(int x, int y, int z, int xs, int& ys, + std::vector getReorderedBlocksAndData(int x, int y, int z, int xs, int& ys, int zs); static void reorderBlocksAndDataToXZY(int y0, int xs, int ys, int zs, - byteArray* data); + std::vector* data); #if defined(LIGHT_COMPRESSION_STATS) int getBlockLightPlanesLower() { return lowerBlockLight->count; } int getSkyLightPlanesLower() { return lowerSkyLight->count; } diff --git a/minecraft/Minecraft.World/net/minecraft/world/level/chunk/ReadOnlyChunkCache.cpp b/minecraft/Minecraft.World/net/minecraft/world/level/chunk/ReadOnlyChunkCache.cpp index acdc71e59..3674abc8a 100644 --- a/minecraft/Minecraft.World/net/minecraft/world/level/chunk/ReadOnlyChunkCache.cpp +++ b/minecraft/Minecraft.World/net/minecraft/world/level/chunk/ReadOnlyChunkCache.cpp @@ -4,19 +4,17 @@ #include "../biome/Biome.h" ReadOnlyChunkCache::ReadOnlyChunkCache(Level* level, ChunkStorage* storage) { - chunks = LevelChunkArray(LEN * LEN); - emptyPixels = byteArray(Level::CHUNK_TILE_COUNT); + chunks = std::vector(LEN * LEN); + emptyPixels = std::vector(Level::CHUNK_TILE_COUNT); this->level = level; this->storage = storage; } ReadOnlyChunkCache::~ReadOnlyChunkCache() { - for (unsigned int i = 0; i < chunks.length; ++i) delete chunks[i]; + for (unsigned int i = 0; i < chunks.size(); ++i) delete chunks[i]; - delete[] chunks.data; - delete[] emptyPixels.data; } bool ReadOnlyChunkCache::hasChunk(int x, int z) { diff --git a/minecraft/Minecraft.World/net/minecraft/world/level/chunk/ReadOnlyChunkCache.h b/minecraft/Minecraft.World/net/minecraft/world/level/chunk/ReadOnlyChunkCache.h index 01c421c99..f6eff229c 100644 --- a/minecraft/Minecraft.World/net/minecraft/world/level/chunk/ReadOnlyChunkCache.h +++ b/minecraft/Minecraft.World/net/minecraft/world/level/chunk/ReadOnlyChunkCache.h @@ -10,7 +10,7 @@ class ReadOnlyChunkCache : public ChunkSource { private: static const int LEN = 16; static const int LEN_MASK = LEN - 1; - LevelChunkArray chunks; + std::vector chunks; Level* level; ChunkStorage* storage; @@ -19,7 +19,7 @@ public: virtual ~ReadOnlyChunkCache(); virtual bool hasChunk(int x, int z); - byteArray emptyPixels; + std::vector emptyPixels; virtual LevelChunk* create(int x, int z); virtual LevelChunk* getChunk(int x, int z); diff --git a/minecraft/Minecraft.World/net/minecraft/world/level/chunk/SparseDataStorage.cpp b/minecraft/Minecraft.World/net/minecraft/world/level/chunk/SparseDataStorage.cpp index a3114c574..e58ac5574 100644 --- a/minecraft/Minecraft.World/net/minecraft/world/level/chunk/SparseDataStorage.cpp +++ b/minecraft/Minecraft.World/net/minecraft/world/level/chunk/SparseDataStorage.cpp @@ -115,7 +115,7 @@ SparseDataStorage::SparseDataStorage(SparseDataStorage* copyFrom) { // Set all data values from a data array of length 16384 (128 x 16 x 16 x 0.5). // Source data must have same order as original java game -void SparseDataStorage::setData(byteArray dataIn, unsigned int inOffset) { +void SparseDataStorage::setData(std::vector& dataIn, unsigned int inOffset) { // Original order is defined as: // pos = (x << 11 | z << 7 | y); // slot = pos >> 1; @@ -193,8 +193,8 @@ void SparseDataStorage::setData(byteArray dataIn, unsigned int inOffset) { // Gets all data values into an array of length 16384. Destination data will // have same order as original java game. -void SparseDataStorage::getData(byteArray retArray, unsigned int retOffset) { - XMemSet(retArray.data + +retOffset, 0, 16384); +void SparseDataStorage::getData(std::vector& retArray, unsigned int retOffset) { + XMemSet(retArray.data() + +retOffset, 0, 16384); unsigned char *planeIndices, *data; getPlaneIndicesAndData(&planeIndices, &data); @@ -212,7 +212,7 @@ void SparseDataStorage::getData(byteArray retArray, unsigned int retOffset) { } else { int part = y & 1; int shift = 4 * part; - unsigned char* pucOut = &retArray.data[(y >> 1) + +retOffset]; + unsigned char* pucOut = &retArray.data()[(y >> 1) + +retOffset]; unsigned char* pucIn = &data[planeIndices[y] * 128]; for (int xz = 0; xz < 128; xz++) // 128 in loop (16 x 16 x 0.5) as input data is being @@ -293,13 +293,13 @@ void SparseDataStorage::set(int x, int y, int z, int val) { // packed in nyblles in this dimension, and the code didn't make any attempt to // unpack it. This behaviour is copied here for compatibility even though our // source data isn't packed this way. Returns size of data copied. -int SparseDataStorage::setDataRegion(byteArray dataIn, int x0, int y0, int z0, +int SparseDataStorage::setDataRegion(std::vector& dataIn, int x0, int y0, int z0, int x1, int y1, int z1, int offset, tileUpdatedCallback callback, void* param, int yparam) { // Actual setting of data happens when calling set method so no need to lock // here - unsigned char* pucIn = &dataIn.data[offset]; + unsigned char* pucIn = &dataIn.data()[offset]; if (callback) { for (int x = x0; x < x1; x++) { for (int z = z0; z < z1; z++) { @@ -341,7 +341,7 @@ int SparseDataStorage::setDataRegion(byteArray dataIn, int x0, int y0, int z0, } } } - ptrdiff_t count = pucIn - &dataIn.data[offset]; + ptrdiff_t count = pucIn - &dataIn.data()[offset]; return (int)count; } @@ -353,10 +353,10 @@ int SparseDataStorage::setDataRegion(byteArray dataIn, int x0, int y0, int z0, // packed in nyblles in this dimension, and the code didn't make any attempt to // unpack it. This behaviour is copied here for compatibility even though our // source data isn't packed this way Returns size of data copied. -int SparseDataStorage::getDataRegion(byteArray dataInOut, int x0, int y0, +int SparseDataStorage::getDataRegion(std::vector& dataInOut, int x0, int y0, int z0, int x1, int y1, int z1, int offset) { - unsigned char* pucOut = &dataInOut.data[offset]; + unsigned char* pucOut = &dataInOut.data()[offset]; for (int x = x0; x < x1; x++) { for (int z = z0; z < z1; z++) { // Emulate how data was extracted from DataLayer... see comment @@ -372,7 +372,7 @@ int SparseDataStorage::getDataRegion(byteArray dataInOut, int x0, int y0, } } } - ptrdiff_t count = pucOut - &dataInOut.data[offset]; + ptrdiff_t count = pucOut - &dataInOut.data()[offset]; return (int)count; } @@ -598,15 +598,16 @@ void SparseDataStorage::write(DataOutputStream* dos) { dos->writeInt(count); unsigned char* dataPointer = (unsigned char*)(dataAndCount & 0x0000ffffffffffff); - byteArray wrapper(dataPointer, count * 128 + 128); + std::vector wrapper(dataPointer, dataPointer + count * 128 + 128); dos->write(wrapper); } void SparseDataStorage::read(DataInputStream* dis) { int count = dis->readInt(); unsigned char* dataPointer = (unsigned char*)malloc(count * 128 + 128); - byteArray wrapper(dataPointer, count * 128 + 128); + std::vector wrapper(count * 128 + 128); dis->readFully(wrapper); + memcpy(dataPointer, wrapper.data(), count * 128 + 128); int64_t newDataAndCount = ((int64_t)dataPointer) & 0x0000ffffffffffffL; diff --git a/minecraft/Minecraft.World/net/minecraft/world/level/chunk/SparseDataStorage.h b/minecraft/Minecraft.World/net/minecraft/world/level/chunk/SparseDataStorage.h index efe32b763..ca720969f 100644 --- a/minecraft/Minecraft.World/net/minecraft/world/level/chunk/SparseDataStorage.h +++ b/minecraft/Minecraft.World/net/minecraft/world/level/chunk/SparseDataStorage.h @@ -77,10 +77,10 @@ public: ~SparseDataStorage(); void setData( - byteArray dataIn, + std::vector& dataIn, unsigned int inOffset); // Set all data values from a data array of // length 16384 (128 x 16 x 16 x 0.5). - void getData(byteArray retArray, + void getData(std::vector& retArray, unsigned int retOffset); // Gets all data values into an array // of length 16384. int get(int x, int y, int z); // Get an individual data value @@ -88,13 +88,13 @@ public: typedef void (*tileUpdatedCallback)(int x, int y, int z, void* param, int yparam); int setDataRegion( - byteArray dataIn, int x0, int y0, int z0, int x1, int y1, int z1, + std::vector& dataIn, int x0, int y0, int z0, int x1, int y1, int z1, int offset, tileUpdatedCallback callback, void* param, int yparam); // Sets a region of data values with the data at offset // position in the array dataIn - external ordering // compatible with java DataLayer int getDataRegion( - byteArray dataInOut, int x0, int y0, int z0, int x1, int y1, int z1, + std::vector& dataInOut, int x0, int y0, int z0, int x1, int y1, int z1, int offset); // Updates the data at offset position dataInOut with a // region of data information - external ordering // compatible with java DataLayer diff --git a/minecraft/Minecraft.World/net/minecraft/world/level/chunk/SparseLightStorage.cpp b/minecraft/Minecraft.World/net/minecraft/world/level/chunk/SparseLightStorage.cpp index 8097ed332..c550102f4 100644 --- a/minecraft/Minecraft.World/net/minecraft/world/level/chunk/SparseLightStorage.cpp +++ b/minecraft/Minecraft.World/net/minecraft/world/level/chunk/SparseLightStorage.cpp @@ -116,7 +116,7 @@ SparseLightStorage::SparseLightStorage(SparseLightStorage* copyFrom) { // Set all lighting values from a data array of length 16384 (128 x 16 x 16 x // 0.5). Source data must have same order as original java game -void SparseLightStorage::setData(byteArray dataIn, unsigned int inOffset) { +void SparseLightStorage::setData(std::vector& dataIn, unsigned int inOffset) { // Original order is defined as: // pos = (x << 11 | z << 7 | y); // slot = pos >> 1; @@ -195,8 +195,8 @@ void SparseLightStorage::setData(byteArray dataIn, unsigned int inOffset) { // Gets all lighting values into an array of length 16384. Destination data will // have same order as original java game. -void SparseLightStorage::getData(byteArray retArray, unsigned int retOffset) { - XMemSet(retArray.data + retOffset, 0, 16384); +void SparseLightStorage::getData(std::vector& retArray, unsigned int retOffset) { + XMemSet(retArray.data() + retOffset, 0, 16384); unsigned char *planeIndices, *data; getPlaneIndicesAndData(&planeIndices, &data); @@ -214,7 +214,7 @@ void SparseLightStorage::getData(byteArray retArray, unsigned int retOffset) { } else if (planeIndices[y] == ALL_15_INDEX) { int part = y & 1; unsigned char value = 15 << (part * 4); - unsigned char* pucOut = &retArray.data[(y >> 1) + retOffset]; + unsigned char* pucOut = &retArray.data()[(y >> 1) + retOffset]; for (int xz = 0; xz < 256; xz++) { *pucOut |= value; pucOut += 64; @@ -222,7 +222,7 @@ void SparseLightStorage::getData(byteArray retArray, unsigned int retOffset) { } else { int part = y & 1; int shift = 4 * part; - unsigned char* pucOut = &retArray.data[(y >> 1) + retOffset]; + unsigned char* pucOut = &retArray.data()[(y >> 1) + retOffset]; unsigned char* pucIn = &data[planeIndices[y] * 128]; for (int xz = 0; xz < 128; xz++) // 128 in loop (16 x 16 x 0.5) as input data is being @@ -322,11 +322,11 @@ void SparseLightStorage::setAllBright() { // code didn't make any attempt to unpack it. This behaviour is copied here for // compatibility even though our source data isn't packed this way. Returns size // of data copied. -int SparseLightStorage::setDataRegion(byteArray dataIn, int x0, int y0, int z0, +int SparseLightStorage::setDataRegion(std::vector& dataIn, int x0, int y0, int z0, int x1, int y1, int z1, int offset) { // Actual setting of data happens when calling set method so no need to lock // here - unsigned char* pucIn = &dataIn.data[offset]; + unsigned char* pucIn = &dataIn.data()[offset]; for (int x = x0; x < x1; x++) { for (int z = z0; z < z1; z++) { // Emulate how data was extracted from DataLayer... see comment @@ -342,7 +342,7 @@ int SparseLightStorage::setDataRegion(byteArray dataIn, int x0, int y0, int z0, } } } - ptrdiff_t count = pucIn - &dataIn.data[offset]; + ptrdiff_t count = pucIn - &dataIn.data()[offset]; return (int)count; } @@ -354,10 +354,10 @@ int SparseLightStorage::setDataRegion(byteArray dataIn, int x0, int y0, int z0, // packed in nyblles in this dimension, and the code didn't make any attempt to // unpack it. This behaviour is copied here for compatibility even though our // source data isn't packed this way Returns size of data copied. -int SparseLightStorage::getDataRegion(byteArray dataInOut, int x0, int y0, +int SparseLightStorage::getDataRegion(std::vector& dataInOut, int x0, int y0, int z0, int x1, int y1, int z1, int offset) { - unsigned char* pucOut = &dataInOut.data[offset]; + unsigned char* pucOut = &dataInOut.data()[offset]; for (int x = x0; x < x1; x++) { for (int z = z0; z < z1; z++) { // Emulate how data was extracted from DataLayer... see comment @@ -373,7 +373,7 @@ int SparseLightStorage::getDataRegion(byteArray dataInOut, int x0, int y0, } } } - ptrdiff_t count = pucOut - &dataInOut.data[offset]; + ptrdiff_t count = pucOut - &dataInOut.data()[offset]; return (int)count; } @@ -608,15 +608,16 @@ void SparseLightStorage::write(DataOutputStream* dos) { dos->writeInt(count); unsigned char* dataPointer = (unsigned char*)(dataAndCount & 0x0000ffffffffffff); - byteArray wrapper(dataPointer, count * 128 + 128); + std::vector wrapper(dataPointer, dataPointer + count * 128 + 128); dos->write(wrapper); } void SparseLightStorage::read(DataInputStream* dis) { int count = dis->readInt(); unsigned char* dataPointer = (unsigned char*)malloc(count * 128 + 128); - byteArray wrapper(dataPointer, count * 128 + 128); + std::vector wrapper(count * 128 + 128); dis->readFully(wrapper); + memcpy(dataPointer, wrapper.data(), count * 128 + 128); int64_t newDataAndCount = ((int64_t)dataPointer) & 0x0000ffffffffffffL; diff --git a/minecraft/Minecraft.World/net/minecraft/world/level/chunk/SparseLightStorage.h b/minecraft/Minecraft.World/net/minecraft/world/level/chunk/SparseLightStorage.h index 49c554309..0e594ef54 100644 --- a/minecraft/Minecraft.World/net/minecraft/world/level/chunk/SparseLightStorage.h +++ b/minecraft/Minecraft.World/net/minecraft/world/level/chunk/SparseLightStorage.h @@ -80,22 +80,22 @@ public: ~SparseLightStorage(); void setData( - byteArray dataIn, + std::vector& dataIn, unsigned int inOffset); // Set all lighting values from a data array of // length 16384 (128 x 16 x 16 x 0.5). - void getData(byteArray retArray, + void getData(std::vector& retArray, unsigned int retOffset); // Gets all lighting values into an // array of length 16384. int get(int x, int y, int z); // Get an individual lighting value void set(int x, int y, int z, int val); // Set an individual lighting value void setAllBright(); // Set all lighting values to fully bright int setDataRegion( - byteArray dataIn, int x0, int y0, int z0, int x1, int y1, int z1, + std::vector& dataIn, int x0, int y0, int z0, int x1, int y1, int z1, int offset); // Sets a region of lighting values with the data at // offset position in the array dataIn - external ordering // compatible with java DataLayer int getDataRegion( - byteArray dataInOut, int x0, int y0, int z0, int x1, int y1, int z1, + std::vector& dataInOut, int x0, int y0, int z0, int x1, int y1, int z1, int offset); // Updates the data at offset position dataInOut with a // region of lighting information - external ordering // compatible with java DataLayer diff --git a/minecraft/Minecraft.World/net/minecraft/world/level/chunk/WaterLevelChunk.cpp b/minecraft/Minecraft.World/net/minecraft/world/level/chunk/WaterLevelChunk.cpp index 81bf47386..1f302e1ed 100644 --- a/minecraft/Minecraft.World/net/minecraft/world/level/chunk/WaterLevelChunk.cpp +++ b/minecraft/Minecraft.World/net/minecraft/world/level/chunk/WaterLevelChunk.cpp @@ -5,7 +5,7 @@ #include "WaterLevelChunk.h" #include "../biome/net.minecraft.world.level.biome.h" -WaterLevelChunk::WaterLevelChunk(Level* level, byteArray blocks, int x, int z) +WaterLevelChunk::WaterLevelChunk(Level* level, std::vector& blocks, int x, int z) : LevelChunk(level, blocks, x, z) { dontSave = true; // Set this as fully post-processed, so we don't try and run post-processing @@ -82,9 +82,9 @@ int WaterLevelChunk::countEntities() { return 0; } bool WaterLevelChunk::shouldSave(bool force) { return false; } -void WaterLevelChunk::setBlocks(byteArray newBlocks, int sub) {} +void WaterLevelChunk::setBlocks(std::vector& newBlocks, int sub) {} -int WaterLevelChunk::setBlocksAndData(byteArray data, int x0, int y0, int z0, +int WaterLevelChunk::setBlocksAndData(std::vector& data, int x0, int y0, int z0, int x1, int y1, int z1, int p, bool includeLighting /* = true*/) { int xs = x1 - x0; @@ -100,7 +100,7 @@ int WaterLevelChunk::setBlocksAndData(byteArray data, int x0, int y0, int z0, } } -bool WaterLevelChunk::testSetBlocksAndData(byteArray data, int x0, int y0, +bool WaterLevelChunk::testSetBlocksAndData(std::vector& data, int x0, int y0, int z0, int x1, int y1, int z1, int p) { return false; diff --git a/minecraft/Minecraft.World/net/minecraft/world/level/chunk/WaterLevelChunk.h b/minecraft/Minecraft.World/net/minecraft/world/level/chunk/WaterLevelChunk.h index f7e8f71fd..b8148f654 100644 --- a/minecraft/Minecraft.World/net/minecraft/world/level/chunk/WaterLevelChunk.h +++ b/minecraft/Minecraft.World/net/minecraft/world/level/chunk/WaterLevelChunk.h @@ -9,7 +9,7 @@ public: using LevelChunk::getEntities; using LevelChunk::getEntitiesOfClass; - WaterLevelChunk(Level* level, byteArray blocks, int x, int z); + WaterLevelChunk(Level* level, std::vector& blocks, int x, int z); bool isAt(int x, int z); void recalcBlockLights(); void recalcHeightmapOnly(); @@ -44,11 +44,11 @@ public: std::vector >& es); int countEntities(); bool shouldSave(bool force); - void setBlocks(byteArray newBlocks, int sub); + void setBlocks(std::vector& newBlocks, int sub); int setBlocksAndData( - byteArray data, int x0, int y0, int z0, int x1, int y1, int z1, int p, + std::vector& data, int x0, int y0, int z0, int x1, int y1, int z1, int p, bool includeLighting = true); // 4J - added includeLighting parameter; - bool testSetBlocksAndData(byteArray data, int x0, int y0, int z0, int x1, + bool testSetBlocksAndData(std::vector& data, int x0, int y0, int z0, int x1, int y1, int z1, int p); Random* getRandom(int64_t l); virtual Biome* getBiome(int x, int z, BiomeSource* biomeSource); diff --git a/minecraft/Minecraft.World/net/minecraft/world/level/chunk/storage/McRegionChunkStorage.cpp b/minecraft/Minecraft.World/net/minecraft/world/level/chunk/storage/McRegionChunkStorage.cpp index 4727c9f97..8b943dd81 100644 --- a/minecraft/Minecraft.World/net/minecraft/world/level/chunk/storage/McRegionChunkStorage.cpp +++ b/minecraft/Minecraft.World/net/minecraft/world/level/chunk/storage/McRegionChunkStorage.cpp @@ -58,8 +58,8 @@ McRegionChunkStorage::McRegionChunkStorage(ConsoleSaveFile* saveFile, NbtIo::write(tag, &dos); delete tag; - byteArray savedData(bos.size()); - memcpy(savedData.data, bos.buf.data, bos.size()); + std::vector savedData(bos.size()); + memcpy(savedData.data(), bos.buf.data(), bos.size()); m_entityData[index] = savedData; } @@ -68,9 +68,7 @@ McRegionChunkStorage::McRegionChunkStorage(ConsoleSaveFile* saveFile, } McRegionChunkStorage::~McRegionChunkStorage() { - for (auto it = m_entityData.begin(); it != m_entityData.end(); ++it) { - delete it->second.data; - } + // vectors manage their own memory; clearing the map is sufficient } LevelChunk* McRegionChunkStorage::load(Level* level, int x, int z) { @@ -88,7 +86,6 @@ LevelChunk* McRegionChunkStorage::load(Level* level, int x, int z) { auto it = m_entityData.find(index); if (it != m_entityData.end()) { - delete it->second.data; m_entityData.erase(it); } } @@ -257,7 +254,6 @@ void McRegionChunkStorage::saveEntities(Level* level, LevelChunk* levelChunk) { uint64_t index = ((uint64_t)(uint32_t)(levelChunk->x) << 32) | (((uint64_t)(uint32_t)(levelChunk->z))); - delete[] m_entityData[index].data; CompoundTag* newTag = new CompoundTag(); bool savedEntities = @@ -268,8 +264,8 @@ void McRegionChunkStorage::saveEntities(Level* level, LevelChunk* levelChunk) { DataOutputStream dos(&bos); NbtIo::write(newTag, &dos); - byteArray savedData(bos.size()); - memcpy(savedData.data, bos.buf.data, bos.size()); + std::vector savedData(bos.size()); + memcpy(savedData.data(), bos.buf.data(), bos.size()); m_entityData[index] = savedData; } else { @@ -317,7 +313,7 @@ void McRegionChunkStorage::flush() { for (auto it = m_entityData.begin(); it != m_entityData.end(); ++it) { dos.writeLong(it->first); - dos.write(it->second, 0, it->second.length); + dos.write(it->second, 0, it->second.size()); } bos.flush(); PIXEndNamedEvent(); diff --git a/minecraft/Minecraft.World/net/minecraft/world/level/chunk/storage/McRegionChunkStorage.h b/minecraft/Minecraft.World/net/minecraft/world/level/chunk/storage/McRegionChunkStorage.h index cbecdfa93..8a800830c 100644 --- a/minecraft/Minecraft.World/net/minecraft/world/level/chunk/storage/McRegionChunkStorage.h +++ b/minecraft/Minecraft.World/net/minecraft/world/level/chunk/storage/McRegionChunkStorage.h @@ -16,7 +16,7 @@ private: ConsoleSaveFile* m_saveFile; static std::mutex cs_memory; - std::unordered_map m_entityData; + std::unordered_map> m_entityData; static std::deque s_chunkDataQueue; static int s_runningThreadCount; diff --git a/minecraft/Minecraft.World/net/minecraft/world/level/chunk/storage/NbtSlotFile.cpp b/minecraft/Minecraft.World/net/minecraft/world/level/chunk/storage/NbtSlotFile.cpp index 6b60cbb67..4eb1eb358 100644 --- a/minecraft/Minecraft.World/net/minecraft/world/level/chunk/storage/NbtSlotFile.cpp +++ b/minecraft/Minecraft.World/net/minecraft/world/level/chunk/storage/NbtSlotFile.cpp @@ -36,7 +36,7 @@ bool WriteExact(std::FILE* file, const void* buffer, std::size_t size) { } } // namespace -byteArray NbtSlotFile::READ_BUFFER(1024 * 1024); +std::vector NbtSlotFile::READ_BUFFER(1024 * 1024); int64_t NbtSlotFile::largest = 0; NbtSlotFile::NbtSlotFile(File file) { @@ -138,7 +138,7 @@ std::vector* NbtSlotFile::readAll(int slot) { // IOException("Wrong slot! Got " + oldSlot + ", expected // " + expectedSlot); // 4J - TODO - ReadExact(raf, READ_BUFFER.data + pos, size); + ReadExact(raf, READ_BUFFER.data() + pos, size); if (continuesAt >= 0) { pos += size; @@ -182,10 +182,10 @@ void NbtSlotFile::replaceSlot(int slot, std::vector* tags) { auto itEndTags = tags->end(); for (auto it = tags->begin(); it != itEndTags; it++) { CompoundTag* tag = *it; // tags->at(i); - byteArray compressed = NbtIo::compress(tag); - if (compressed.length > largest) { + std::vector compressed = NbtIo::compress(tag); + if (compressed.size() > largest) { wchar_t buf[256]; - largest = compressed.length; + largest = compressed.size(); #ifndef _CONTENT_PACKAGE swprintf(buf, 256, L"New largest: %I64d (%ls)\n", largest, tag->getString(L"id").c_str()); @@ -194,7 +194,7 @@ void NbtSlotFile::replaceSlot(int slot, std::vector* tags) { } int pos = 0; - int remaining = compressed.length; + int remaining = compressed.size(); if (remaining == 0) continue; int nextFileSlot = getFreeSlot(); @@ -224,7 +224,7 @@ void NbtSlotFile::replaceSlot(int slot, std::vector* tags) { WriteExact(raf, &lastFileSlot, sizeof(lastFileSlot)); seekSlot(fileSlot); - WriteExact(raf, compressed.data + pos, toWrite); + WriteExact(raf, compressed.data() + pos, toWrite); if (remaining > 0) { lastFileSlot = fileSlot; @@ -232,7 +232,6 @@ void NbtSlotFile::replaceSlot(int slot, std::vector* tags) { currentSlot = -slot - 1; } } - delete[] compressed.data; } auto itEndToRep = toReplace->end(); diff --git a/minecraft/Minecraft.World/net/minecraft/world/level/chunk/storage/NbtSlotFile.h b/minecraft/Minecraft.World/net/minecraft/world/level/chunk/storage/NbtSlotFile.h index 5abb42b74..d0c6355b1 100644 --- a/minecraft/Minecraft.World/net/minecraft/world/level/chunk/storage/NbtSlotFile.h +++ b/minecraft/Minecraft.World/net/minecraft/world/level/chunk/storage/NbtSlotFile.h @@ -7,7 +7,7 @@ class NbtSlotFile { private: - static byteArray READ_BUFFER; + static std::vector READ_BUFFER; static const int FILE_HEADER_SIZE = 1024; static const int MAGIC_NUMBER = 0x13737001; diff --git a/minecraft/Minecraft.World/net/minecraft/world/level/chunk/storage/OldChunkStorage.cpp b/minecraft/Minecraft.World/net/minecraft/world/level/chunk/storage/OldChunkStorage.cpp index 73eb75872..e0cea9a5b 100644 --- a/minecraft/Minecraft.World/net/minecraft/world/level/chunk/storage/OldChunkStorage.cpp +++ b/minecraft/Minecraft.World/net/minecraft/world/level/chunk/storage/OldChunkStorage.cpp @@ -16,17 +16,13 @@ OldChunkStorage::ThreadStorage* OldChunkStorage::m_defaultThreadStorage = nullptr; OldChunkStorage::ThreadStorage::ThreadStorage() { - blockData = byteArray(Level::CHUNK_TILE_COUNT); - dataData = byteArray(Level::HALF_CHUNK_TILE_COUNT); - skyLightData = byteArray(Level::HALF_CHUNK_TILE_COUNT); - blockLightData = byteArray(Level::HALF_CHUNK_TILE_COUNT); + blockData = std::vector(Level::CHUNK_TILE_COUNT); + dataData = std::vector(Level::HALF_CHUNK_TILE_COUNT); + skyLightData = std::vector(Level::HALF_CHUNK_TILE_COUNT); + blockLightData = std::vector(Level::HALF_CHUNK_TILE_COUNT); } OldChunkStorage::ThreadStorage::~ThreadStorage() { - delete[] blockData.data; - delete[] dataData.data; - delete[] skyLightData.data; - delete[] blockLightData.data; } void OldChunkStorage::CreateNewThreadStorage() { @@ -315,20 +311,20 @@ void OldChunkStorage::save(LevelChunk* lc, Level* level, CompoundTag* tag) { ThreadStorage* tls = m_tlsStorage; PIXBeginNamedEvent(0, "Getting block data"); - // static byteArray blockData = byteArray(32768); + // static std::vector blockData = std::vector(32768); lc->getBlockData(tls->blockData); tag->putByteArray(L"Blocks", tls->blockData); PIXEndNamedEvent(); PIXBeginNamedEvent(0, "Getting data data"); - // static byteArray dataData = byteArray(16384); + // static std::vector dataData = std::vector(16384); lc->getDataData(tls->dataData); tag->putByteArray(L"Data", tls->dataData); PIXEndNamedEvent(); PIXBeginNamedEvent(0, "Getting sky and block light data"); - // static byteArray skyLightData = byteArray(16384); - // static byteArray blockLightData = byteArray(16384); + // static std::vector skyLightData = std::vector(16384); + // static std::vector blockLightData = std::vector(16384); lc->getSkyLightData(tls->skyLightData); lc->getBlockLightData(tls->blockLightData); tag->putByteArray(L"SkyLight", tls->skyLightData); @@ -341,7 +337,8 @@ void OldChunkStorage::save(LevelChunk* lc, Level* level, CompoundTag* tag) { lc->terrainPopulated); // 4J - changed from "TerrainPopulated" to // "TerrainPopulatedFlags" as now stores a // bitfield, java stores a bool - tag->putByteArray(L"Biomes", lc->getBiomes()); + std::vector biomeData = lc->getBiomes(); + tag->putByteArray(L"Biomes", biomeData); PIXBeginNamedEvent(0, "Saving entities"); #if !defined(SPLIT_SAVES) @@ -455,9 +452,8 @@ LevelChunk* OldChunkStorage::load(Level* level, DataInputStream* dis) { app.GetGameSettingsDebugMask(ProfileManager.GetPrimaryPad()) & (1L << eDebugSetting_EnableBiomeOverride)) { // Read the biome data from the stream, but don't use it - byteArray dummyBiomes(levelChunk->biomes.length); + std::vector dummyBiomes(levelChunk->biomes.size()); dis->readFully(dummyBiomes); - delete[] dummyBiomes.data; } else #endif { @@ -501,32 +497,39 @@ LevelChunk* OldChunkStorage::load(Level* level, CompoundTag* tag) { // 4J - the original code uses the data in the tag directly, but this is now // just used as a source when creating the compressed data, so we need to // free up the data in the tag once we are done - levelChunk->setBlockData(tag->getByteArray(L"Blocks")); - delete[] tag->getByteArray(L"Blocks").data; + { + auto blocks = tag->getByteArray(L"Blocks"); + levelChunk->setBlockData(blocks); + } // levelChunk->blocks = tag->getByteArray(L"Blocks"); // 4J - the original code uses the data in the tag directly, but this is now // just used as a source when creating the compressed data, so we need to // free up the data in the tag once we are done - levelChunk->setDataData(tag->getByteArray(L"Data")); - delete[] tag->getByteArray(L"Data").data; + { + auto data = tag->getByteArray(L"Data"); + levelChunk->setDataData(data); + } // 4J - changed to use our new methods for accessing lighting - levelChunk->setSkyLightData(tag->getByteArray(L"SkyLight")); - levelChunk->setBlockLightData(tag->getByteArray(L"BlockLight")); + { + auto skyLight = tag->getByteArray(L"SkyLight"); + levelChunk->setSkyLightData(skyLight); + } + { + auto blockLight = tag->getByteArray(L"BlockLight"); + levelChunk->setBlockLightData(blockLight); + } // In the original code (commented out below) constructing DataLayers from // these arrays uses the data directly and so it doesn't need deleted. The // new setSkyLightData/setBlockLightData take a copy of the data so we need // to delete the local one now - delete[] tag->getByteArray(L"SkyLight").data; - delete[] tag->getByteArray(L"BlockLight").data; // levelChunk->skyLight = new DataLayer(tag->getByteArray(L"SkyLight"), // level->depthBits); levelChunk->blockLight = new // DataLayer(tag->getByteArray(L"BlockLight"), level->depthBits); - delete[] levelChunk->heightmap.data; levelChunk->heightmap = tag->getByteArray(L"HeightMap"); // 4J - TerrainPopulated was a bool (java), then changed to be a byte // bitfield, then replaced with TerrainPopulatedShort to store a wider @@ -567,7 +570,8 @@ LevelChunk* OldChunkStorage::load(Level* level, CompoundTag* tag) { #endif { if (tag->contains(L"Biomes")) { - levelChunk->setBiomes(tag->getByteArray(L"Biomes")); + auto biomes = tag->getByteArray(L"Biomes"); + levelChunk->setBiomes(biomes); } } diff --git a/minecraft/Minecraft.World/net/minecraft/world/level/chunk/storage/OldChunkStorage.h b/minecraft/Minecraft.World/net/minecraft/world/level/chunk/storage/OldChunkStorage.h index d11a948bd..d6eb993a3 100644 --- a/minecraft/Minecraft.World/net/minecraft/world/level/chunk/storage/OldChunkStorage.h +++ b/minecraft/Minecraft.World/net/minecraft/world/level/chunk/storage/OldChunkStorage.h @@ -13,10 +13,10 @@ private: // 4J added so we can have separate storage arrays for different threads class ThreadStorage { public: - byteArray blockData; - byteArray dataData; - byteArray skyLightData; - byteArray blockLightData; + std::vector blockData; + std::vector dataData; + std::vector skyLightData; + std::vector blockLightData; ThreadStorage(); ~ThreadStorage(); diff --git a/minecraft/Minecraft.World/net/minecraft/world/level/chunk/storage/RegionFile.cpp b/minecraft/Minecraft.World/net/minecraft/world/level/chunk/storage/RegionFile.cpp index 288f3cf5e..635f0fcce 100644 --- a/minecraft/Minecraft.World/net/minecraft/world/level/chunk/storage/RegionFile.cpp +++ b/minecraft/Minecraft.World/net/minecraft/world/level/chunk/storage/RegionFile.cpp @@ -6,7 +6,7 @@ #include "../../../../../../ConsoleHelpers/ConsoleSaveFileIO/ConsoleSaveFile.h" -byteArray RegionFile::emptySector(SECTOR_BYTES); +std::vector RegionFile::emptySector(SECTOR_BYTES); RegionFile::RegionFile(ConsoleSaveFile* saveFile, File* path) { _lastModified = 0; @@ -260,8 +260,10 @@ DataInputStream* RegionFile::getChunkDataInputStream( delete[] data; // 4J - was InflaterInputStream in here too, but we've already decompressed + std::vector decompData(decomp, decomp + readDecompLength); + delete[] decomp; DataInputStream* ret = new DataInputStream( - new ByteArrayInputStream(byteArray(decomp, readDecompLength))); + new ByteArrayInputStream(decompData)); return ret; // } catch (IOException e) { @@ -392,8 +394,8 @@ void RegionFile::write(int x, int z, std::uint8_t* data, #endif unsigned int numberOfBytesWritten = 0; for (int i = 0; i < sectorsNeeded; ++i) { - // WriteFile(file,emptySector.data,SECTOR_BYTES,&numberOfBytesWritten,nullptr); - m_saveFile->writeFile(fileEntry, emptySector.data, + // WriteFile(file,emptySector.data(),SECTOR_BYTES,&numberOfBytesWritten,nullptr); + m_saveFile->writeFile(fileEntry, emptySector.data(), SECTOR_BYTES, &numberOfBytesWritten); sectorFree->push_back(false); } diff --git a/minecraft/Minecraft.World/net/minecraft/world/level/chunk/storage/RegionFile.h b/minecraft/Minecraft.World/net/minecraft/world/level/chunk/storage/RegionFile.h index 2308ecb3f..f565221b7 100644 --- a/minecraft/Minecraft.World/net/minecraft/world/level/chunk/storage/RegionFile.h +++ b/minecraft/Minecraft.World/net/minecraft/world/level/chunk/storage/RegionFile.h @@ -19,7 +19,7 @@ private: static const int SECTOR_INTS = SECTOR_BYTES / 4; static const int CHUNK_HEADER_SIZE = 8; - static byteArray emptySector; + static std::vector emptySector; File* fileName; // void* file; @@ -61,7 +61,7 @@ public: this->x = x; this->z = z; } - void close() { rf->write(x, z, buf.data, count); } + void close() { rf->write(x, z, buf.data(), count); } }; /* write a chunk at (x,z) with length bytes of data to disk */ diff --git a/minecraft/Minecraft.World/net/minecraft/world/level/chunk/storage/ZoneFile.cpp b/minecraft/Minecraft.World/net/minecraft/world/level/chunk/storage/ZoneFile.cpp index 76387eceb..813eb1855 100644 --- a/minecraft/Minecraft.World/net/minecraft/world/level/chunk/storage/ZoneFile.cpp +++ b/minecraft/Minecraft.World/net/minecraft/world/level/chunk/storage/ZoneFile.cpp @@ -51,7 +51,6 @@ ZoneFile::ZoneFile(int64_t key, File file, File entityFile) // } } -ZoneFile::~ZoneFile() { delete[] slots.data; } void ZoneFile::readHeader() { ZoneIo* zoneIo = new ZoneIo(channel, 0); @@ -79,7 +78,7 @@ void ZoneFile::writeHeader() { bb->putShort((short)0); bb->putShort((short)slotCount); bb->putShortArray(slots); - bb->position(bb->position() + slots.length * 2); + bb->position(bb->position() + slots.size() * 2); bb->flip(); zoneIo->write(bb, FILE_HEADER_SIZE); } diff --git a/minecraft/Minecraft.World/net/minecraft/world/level/chunk/storage/ZoneFile.h b/minecraft/Minecraft.World/net/minecraft/world/level/chunk/storage/ZoneFile.h index 8f3f46b94..784aedee0 100644 --- a/minecraft/Minecraft.World/net/minecraft/world/level/chunk/storage/ZoneFile.h +++ b/minecraft/Minecraft.World/net/minecraft/world/level/chunk/storage/ZoneFile.h @@ -14,7 +14,7 @@ private: static const int slotsLength; - shortArray slots; + std::vector slots; short slotCount; public: diff --git a/minecraft/Minecraft.World/net/minecraft/world/level/chunk/storage/ZoneIo.cpp b/minecraft/Minecraft.World/net/minecraft/world/level/chunk/storage/ZoneIo.cpp index d987dc868..c95b9adac 100644 --- a/minecraft/Minecraft.World/net/minecraft/world/level/chunk/storage/ZoneIo.cpp +++ b/minecraft/Minecraft.World/net/minecraft/world/level/chunk/storage/ZoneIo.cpp @@ -17,7 +17,7 @@ ZoneIo::ZoneIo(std::FILE* channel, int64_t pos) { this->pos = pos; } -void ZoneIo::write(byteArray bb, int size) { +void ZoneIo::write(std::vector bb, int size) { ByteBuffer* buff = ByteBuffer::wrap(bb); // if (bb.length != size) throw new IllegalArgumentException("Expected " // + size + " bytes, got " + bb.length); // 4J - TODO @@ -35,7 +35,7 @@ void ZoneIo::write(ByteBuffer* bb, int size) { } ByteBuffer* ZoneIo::read(int size) { - byteArray bb = byteArray(size); + std::vector bb = std::vector(size); SeekFile(channel, pos); ByteBuffer* buff = ByteBuffer::wrap(bb); // 4J - to investigate - why is this buffer flipped before anything goes in diff --git a/minecraft/Minecraft.World/net/minecraft/world/level/chunk/storage/ZoneIo.h b/minecraft/Minecraft.World/net/minecraft/world/level/chunk/storage/ZoneIo.h index 74f74ea91..3ea912fa2 100644 --- a/minecraft/Minecraft.World/net/minecraft/world/level/chunk/storage/ZoneIo.h +++ b/minecraft/Minecraft.World/net/minecraft/world/level/chunk/storage/ZoneIo.h @@ -12,7 +12,7 @@ private: public: ZoneIo(std::FILE* channel, int64_t pos); - void write(byteArray bb, int size); + void write(std::vector bb, int size); void write(ByteBuffer* bb, int size); ByteBuffer* read(int size); diff --git a/minecraft/Minecraft.World/net/minecraft/world/level/levelgen/CanyonFeature.cpp b/minecraft/Minecraft.World/net/minecraft/world/level/levelgen/CanyonFeature.cpp index 243bc3033..5923adec5 100644 --- a/minecraft/Minecraft.World/net/minecraft/world/level/levelgen/CanyonFeature.cpp +++ b/minecraft/Minecraft.World/net/minecraft/world/level/levelgen/CanyonFeature.cpp @@ -5,7 +5,7 @@ #include "../biome/net.minecraft.world.level.biome.h" void CanyonFeature::addTunnel(int64_t seed, int xOffs, int zOffs, - byteArray blocks, double xCave, double yCave, + std::vector& blocks, double xCave, double yCave, double zCave, float thickness, float yRot, float xRot, int step, int dist, double yScale) { MemSect(49); @@ -157,7 +157,7 @@ void CanyonFeature::addTunnel(int64_t seed, int xOffs, int zOffs, } void CanyonFeature::addFeature(Level* level, int x, int z, int xOffs, int zOffs, - byteArray blocks) { + std::vector& blocks) { if (random->nextInt(50) != 0) return; double xCave = x * 16 + random->nextInt(16); diff --git a/minecraft/Minecraft.World/net/minecraft/world/level/levelgen/CanyonFeature.h b/minecraft/Minecraft.World/net/minecraft/world/level/levelgen/CanyonFeature.h index e35668b8e..9209bed98 100644 --- a/minecraft/Minecraft.World/net/minecraft/world/level/levelgen/CanyonFeature.h +++ b/minecraft/Minecraft.World/net/minecraft/world/level/levelgen/CanyonFeature.h @@ -8,9 +8,9 @@ private: float rs[1024]; protected: - void addTunnel(int64_t seed, int xOffs, int zOffs, byteArray blocks, + void addTunnel(int64_t seed, int xOffs, int zOffs, std::vector& blocks, double xCave, double yCave, double zCave, float thickness, float yRot, float xRot, int step, int dist, double yScale); virtual void addFeature(Level* level, int x, int z, int xOffs, int zOffs, - byteArray blocks); + std::vector& blocks); }; diff --git a/minecraft/Minecraft.World/net/minecraft/world/level/levelgen/CustomLevelSource.cpp b/minecraft/Minecraft.World/net/minecraft/world/level/levelgen/CustomLevelSource.cpp index 3f9a55b7f..6d4fff859 100644 --- a/minecraft/Minecraft.World/net/minecraft/world/level/levelgen/CustomLevelSource.cpp +++ b/minecraft/Minecraft.World/net/minecraft/world/level/levelgen/CustomLevelSource.cpp @@ -19,7 +19,7 @@ CustomLevelSource::CustomLevelSource(Level* level, int64_t seed, #if defined(_OVERRIDE_HEIGHTMAP) m_XZSize = level->getLevelData()->getXZSize(); - m_heightmapOverride = byteArray((m_XZSize * 16) * (m_XZSize * 16)); + m_heightmapOverride = std::vector((m_XZSize * 16) * (m_XZSize * 16)); #if defined(_UNICODE) std::wstring path = L"GAME:\\GameRules\\heightmap.bin"; @@ -39,11 +39,11 @@ CustomLevelSource::CustomLevelSource(Level* level, int64_t seed, assert(false); } else { uint32_t bytesRead, dwFileSize = GetFileSize(file, nullptr); - if (dwFileSize > m_heightmapOverride.length) { + if (dwFileSize > m_heightmapOverride.size()) { app.DebugPrintf("Heightmap binary is too large!!\n"); __debugbreak(); } - bool bSuccess = ReadFile(file, m_heightmapOverride.data, dwFileSize, + bool bSuccess = ReadFile(file, m_heightmapOverride.data(), dwFileSize, &bytesRead, nullptr); if (bSuccess == false) { @@ -52,7 +52,7 @@ CustomLevelSource::CustomLevelSource(Level* level, int64_t seed, CloseHandle(file); } - m_waterheightOverride = byteArray((m_XZSize * 16) * (m_XZSize * 16)); + m_waterheightOverride = std::vector((m_XZSize * 16) * (m_XZSize * 16)); #if defined(_UNICODE) std::wstring waterHeightPath = L"GAME:\\GameRules\\waterheight.bin"; @@ -69,15 +69,15 @@ CustomLevelSource::CustomLevelSource(Level* level, int64_t seed, if (file == INVALID_HANDLE_VALUE) { uint32_t error = GetLastError(); // assert(false); - memset(m_waterheightOverride.data, level->seaLevel, - m_waterheightOverride.length); + memset(m_waterheightOverride.data(), level->seaLevel, + m_waterheightOverride.size()); } else { uint32_t bytesRead, dwFileSize = GetFileSize(file, nullptr); - if (dwFileSize > m_waterheightOverride.length) { + if (dwFileSize > m_waterheightOverride.size()) { app.DebugPrintf("waterheight binary is too large!!\n"); __debugbreak(); } - bool bSuccess = ReadFile(file, m_waterheightOverride.data, dwFileSize, + bool bSuccess = ReadFile(file, m_waterheightOverride.data(), dwFileSize, &bytesRead, nullptr); if (bSuccess == false) { @@ -116,7 +116,7 @@ CustomLevelSource::~CustomLevelSource() { #endif } -void CustomLevelSource::prepareHeights(int xOffs, int zOffs, byteArray blocks) { +void CustomLevelSource::prepareHeights(int xOffs, int zOffs, std::vector& blocks) { #if defined(_OVERRIDE_HEIGHTMAP) int xChunks = 16 / CHUNK_WIDTH; int yChunks = Level::maxBuildHeight / CHUNK_HEIGHT; @@ -237,8 +237,8 @@ void CustomLevelSource::prepareHeights(int xOffs, int zOffs, byteArray blocks) { #endif } -void CustomLevelSource::buildSurfaces(int xOffs, int zOffs, byteArray blocks, - BiomeArray biomes) { +void CustomLevelSource::buildSurfaces(int xOffs, int zOffs, std::vector& blocks, + std::vector& biomes) { #if defined(_OVERRIDE_HEIGHTMAP) int waterHeight = level->seaLevel; int xMapStart = xOffs + m_XZSize / 2; @@ -246,7 +246,7 @@ void CustomLevelSource::buildSurfaces(int xOffs, int zOffs, byteArray blocks, double s = 1 / 32.0; - doubleArray depthBuffer(16 * + std::vector depthBuffer(16 * 16); // 4J - used to be declared with class level // scope but moved here for thread safety @@ -340,7 +340,6 @@ void CustomLevelSource::buildSurfaces(int xOffs, int zOffs, byteArray blocks, } } - delete[] depthBuffer.data; #endif } @@ -362,8 +361,8 @@ LevelChunk* CustomLevelSource::getChunk(int xOffs, int zOffs) { uint8_t* tileData = (uint8_t*)XPhysicalAlloc(blocksSize, MAXULONG_PTR, 4096, PAGE_READWRITE); XMemSet128(tileData, 0, blocksSize); - byteArray blocks = byteArray(tileData, blocksSize); - // byteArray blocks = byteArray(16 * level->depth * 16); + std::vector blocks = std::vector(tileData, tileData + blocksSize); + // std::vector blocks = std::vector(16 * level->depth * 16); // LevelChunk *levelChunk = new LevelChunk(level, blocks, xOffs, zOffs); // // 4J - moved to below @@ -372,13 +371,12 @@ LevelChunk* CustomLevelSource::getChunk(int xOffs, int zOffs) { // 4J - Some changes made here to how biomes, temperatures and downfalls are // passed around for thread safety - BiomeArray biomes; + std::vector biomes; level->getBiomeSource()->getBiomeBlock(biomes, xOffs * 16, zOffs * 16, 16, 16, true); buildSurfaces(xOffs, zOffs, blocks, biomes); - delete[] biomes.data; caveFeature->apply(this, level, xOffs, zOffs, blocks); // 4J Stu Design Change - 1.8 gen goes stronghold, mineshaft, village, @@ -617,10 +615,11 @@ void CustomLevelSource::recreateLogicStructuresForChunk(int chunkX, int chunkZ) { if (generateStructures) { #if defined(_OVERRIDE_HEIGHTMAP) - mineShaftFeature->apply(this, level, chunkX, chunkZ, byteArray()); - villageFeature->apply(this, level, chunkX, chunkZ, byteArray()); - strongholdFeature->apply(this, level, chunkX, chunkZ, byteArray()); - scatteredFeature->apply(this, level, chunkX, chunkZ, byteArray()); + std::vector emptyBlocks; + mineShaftFeature->apply(this, level, chunkX, chunkZ, emptyBlocks); + villageFeature->apply(this, level, chunkX, chunkZ, emptyBlocks); + strongholdFeature->apply(this, level, chunkX, chunkZ, emptyBlocks); + scatteredFeature->apply(this, level, chunkX, chunkZ, emptyBlocks); #endif } } diff --git a/minecraft/Minecraft.World/net/minecraft/world/level/levelgen/CustomLevelSource.h b/minecraft/Minecraft.World/net/minecraft/world/level/levelgen/CustomLevelSource.h index 226c0a0ca..521d2d0d9 100644 --- a/minecraft/Minecraft.World/net/minecraft/world/level/levelgen/CustomLevelSource.h +++ b/minecraft/Minecraft.World/net/minecraft/world/level/levelgen/CustomLevelSource.h @@ -35,8 +35,8 @@ private: Level* level; #endif - byteArray m_heightmapOverride; - byteArray m_waterheightOverride; + std::vector m_heightmapOverride; + std::vector m_waterheightOverride; private: const bool generateStructures; @@ -46,11 +46,11 @@ public: ~CustomLevelSource(); public: - void prepareHeights(int xOffs, int zOffs, byteArray blocks); + void prepareHeights(int xOffs, int zOffs, std::vector& blocks); public: - void buildSurfaces(int xOffs, int zOffs, byteArray blocks, - BiomeArray biomes); + void buildSurfaces(int xOffs, int zOffs, std::vector& blocks, + std::vector& biomes); private: virtual LevelChunk* create(int x, int z); diff --git a/minecraft/Minecraft.World/net/minecraft/world/level/levelgen/DungeonFeature.cpp b/minecraft/Minecraft.World/net/minecraft/world/level/levelgen/DungeonFeature.cpp index b89454122..8a32f1387 100644 --- a/minecraft/Minecraft.World/net/minecraft/world/level/levelgen/DungeonFeature.cpp +++ b/minecraft/Minecraft.World/net/minecraft/world/level/levelgen/DungeonFeature.cpp @@ -3,13 +3,13 @@ #include "DungeonFeature.h" #include "../tile/net.minecraft.world.level.tile.h" -void DungeonFeature::addRoom(int xOffs, int zOffs, byteArray blocks, +void DungeonFeature::addRoom(int xOffs, int zOffs, std::vector& blocks, double xRoom, double yRoom, double zRoom) { addTunnel(xOffs, zOffs, blocks, xRoom, yRoom, zRoom, 1 + random->nextFloat() * 6, 0, 0, -1, -1, 0.5); } -void DungeonFeature::addTunnel(int xOffs, int zOffs, byteArray blocks, +void DungeonFeature::addTunnel(int xOffs, int zOffs, std::vector& blocks, double xCave, double yCave, double zCave, float thickness, float yRot, float xRot, int step, int dist, double yScale) { @@ -152,7 +152,7 @@ void DungeonFeature::addTunnel(int xOffs, int zOffs, byteArray blocks, } void DungeonFeature::addFeature(Level* level, int x, int z, int xOffs, - int zOffs, byteArray blocks) { + int zOffs, std::vector& blocks) { int caves = random->nextInt(random->nextInt(random->nextInt(40) + 1) + 1); if (random->nextInt(15) != 0) caves = 0; diff --git a/minecraft/Minecraft.World/net/minecraft/world/level/levelgen/DungeonFeature.h b/minecraft/Minecraft.World/net/minecraft/world/level/levelgen/DungeonFeature.h index 598c60d89..bd59c2f77 100644 --- a/minecraft/Minecraft.World/net/minecraft/world/level/levelgen/DungeonFeature.h +++ b/minecraft/Minecraft.World/net/minecraft/world/level/levelgen/DungeonFeature.h @@ -4,12 +4,12 @@ class Level; class DungeonFeature : public LargeFeature { - void addRoom(int xOffs, int zOffs, byteArray blocks, double xRoom, + void addRoom(int xOffs, int zOffs, std::vector& blocks, double xRoom, double yRoom, double zRoom); - void addTunnel(int xOffs, int zOffs, byteArray blocks, double xCave, + void addTunnel(int xOffs, int zOffs, std::vector& blocks, double xCave, double yCave, double zCave, float thickness, float yRot, float xRot, int step, int dist, double yScale); virtual void addFeature(Level* level, int x, int z, int xOffs, int zOffs, - byteArray blocks); + std::vector& blocks); }; diff --git a/minecraft/Minecraft.World/net/minecraft/world/level/levelgen/FlatLevelSource.cpp b/minecraft/Minecraft.World/net/minecraft/world/level/levelgen/FlatLevelSource.cpp index 3fe83f6e7..6dfbf757a 100644 --- a/minecraft/Minecraft.World/net/minecraft/world/level/levelgen/FlatLevelSource.cpp +++ b/minecraft/Minecraft.World/net/minecraft/world/level/levelgen/FlatLevelSource.cpp @@ -30,8 +30,8 @@ FlatLevelSource::~FlatLevelSource() { delete villageFeature; } -void FlatLevelSource::prepareHeights(byteArray blocks) { - int height = blocks.length / (16 * 16); +void FlatLevelSource::prepareHeights(std::vector& blocks) { + int height = blocks.size() / (16 * 16); for (int xc = 0; xc < 16; xc++) { for (int zc = 0; zc < 16; zc++) { @@ -59,8 +59,8 @@ LevelChunk* FlatLevelSource::getChunk(int xOffs, int zOffs) { uint8_t* tileData = (uint8_t*)XPhysicalAlloc(chunksSize, MAXULONG_PTR, 4096, PAGE_READWRITE); XMemSet128(tileData, 0, chunksSize); - byteArray blocks = byteArray(tileData, chunksSize); - // byteArray blocks = byteArray(16 * level->depth * 16); + std::vector blocks = std::vector(tileData, tileData + chunksSize); + // std::vector blocks = std::vector(16 * level->depth * 16); prepareHeights(blocks); // LevelChunk *levelChunk = new LevelChunk(level, blocks, xOffs, zOffs); diff --git a/minecraft/Minecraft.World/net/minecraft/world/level/levelgen/FlatLevelSource.h b/minecraft/Minecraft.World/net/minecraft/world/level/levelgen/FlatLevelSource.h index 18773c802..7e0c4a840 100644 --- a/minecraft/Minecraft.World/net/minecraft/world/level/levelgen/FlatLevelSource.h +++ b/minecraft/Minecraft.World/net/minecraft/world/level/levelgen/FlatLevelSource.h @@ -27,7 +27,7 @@ public: ~FlatLevelSource(); private: - void prepareHeights(byteArray blocks); + void prepareHeights(std::vector& blocks); public: virtual LevelChunk* create(int x, int z); diff --git a/minecraft/Minecraft.World/net/minecraft/world/level/levelgen/HellFlatLevelSource.cpp b/minecraft/Minecraft.World/net/minecraft/world/level/levelgen/HellFlatLevelSource.cpp index 69dc6e181..6d0eb17a9 100644 --- a/minecraft/Minecraft.World/net/minecraft/world/level/levelgen/HellFlatLevelSource.cpp +++ b/minecraft/Minecraft.World/net/minecraft/world/level/levelgen/HellFlatLevelSource.cpp @@ -21,8 +21,8 @@ HellFlatLevelSource::~HellFlatLevelSource() { } void HellFlatLevelSource::prepareHeights(int xOffs, int zOffs, - byteArray blocks) { - int height = blocks.length / (16 * 16); + std::vector& blocks) { + int height = blocks.size() / (16 * 16); for (int xc = 0; xc < 16; xc++) { for (int zc = 0; zc < 16; zc++) { @@ -39,7 +39,7 @@ void HellFlatLevelSource::prepareHeights(int xOffs, int zOffs, } void HellFlatLevelSource::buildSurfaces(int xOffs, int zOffs, - byteArray blocks) { + std::vector& blocks) { for (int x = 0; x < 16; x++) { for (int z = 0; z < 16; z++) { for (int y = Level::genDepthMinusOne; y >= 0; y--) { @@ -99,8 +99,8 @@ LevelChunk* HellFlatLevelSource::getChunk(int xOffs, int zOffs) { uint8_t* tileData = (uint8_t*)XPhysicalAlloc(chunksSize, MAXULONG_PTR, 4096, PAGE_READWRITE); XMemSet128(tileData, 0, chunksSize); - byteArray blocks = byteArray(tileData, chunksSize); - // byteArray blocks = byteArray(16 * level->depth * 16); + std::vector blocks = std::vector(tileData, tileData + chunksSize); + // std::vector blocks = std::vector(16 * level->depth * 16); prepareHeights(xOffs, zOffs, blocks); buildSurfaces(xOffs, zOffs, blocks); diff --git a/minecraft/Minecraft.World/net/minecraft/world/level/levelgen/HellFlatLevelSource.h b/minecraft/Minecraft.World/net/minecraft/world/level/levelgen/HellFlatLevelSource.h index af987c683..2e15625bb 100644 --- a/minecraft/Minecraft.World/net/minecraft/world/level/levelgen/HellFlatLevelSource.h +++ b/minecraft/Minecraft.World/net/minecraft/world/level/levelgen/HellFlatLevelSource.h @@ -29,10 +29,10 @@ public: ~HellFlatLevelSource(); private: - void prepareHeights(int xOffs, int zOffs, byteArray blocks); + void prepareHeights(int xOffs, int zOffs, std::vector& blocks); public: - void buildSurfaces(int xOffs, int zOffs, byteArray blocks); + void buildSurfaces(int xOffs, int zOffs, std::vector& blocks); LevelChunk* create(int x, int z); LevelChunk* getChunk(int xOffs, int zOffs); diff --git a/minecraft/Minecraft.World/net/minecraft/world/level/levelgen/HellRandomLevelSource.cpp b/minecraft/Minecraft.World/net/minecraft/world/level/levelgen/HellRandomLevelSource.cpp index be1884c7f..b7d24852f 100644 --- a/minecraft/Minecraft.World/net/minecraft/world/level/levelgen/HellRandomLevelSource.cpp +++ b/minecraft/Minecraft.World/net/minecraft/world/level/levelgen/HellRandomLevelSource.cpp @@ -48,14 +48,14 @@ HellRandomLevelSource::~HellRandomLevelSource() { } void HellRandomLevelSource::prepareHeights(int xOffs, int zOffs, - byteArray blocks) { + std::vector& blocks) { int xChunks = 16 / CHUNK_WIDTH; int waterHeight = 32; int xSize = xChunks + 1; int ySize = Level::genDepth / CHUNK_HEIGHT + 1; int zSize = xChunks + 1; - doubleArray buffer; // 4J - used to be declared with class level scope but + std::vector buffer; // 4J - used to be declared with class level scope but // tidying up for thread safety reasons buffer = getHeights(buffer, xOffs * xChunks, 0, zOffs * xChunks, xSize, ySize, zSize); @@ -134,20 +134,19 @@ void HellRandomLevelSource::prepareHeights(int xOffs, int zOffs, } } } - delete[] buffer.data; } void HellRandomLevelSource::buildSurfaces(int xOffs, int zOffs, - byteArray blocks) { + std::vector& blocks) { int waterHeight = Level::genDepth - 64; double s = 1 / 32.0; - doubleArray sandBuffer(16 * + std::vector sandBuffer(16 * 16); // 4J - used to be declared with class level // scope but moved here for thread safety - doubleArray gravelBuffer(16 * 16); - doubleArray depthBuffer(16 * 16); + std::vector gravelBuffer(16 * 16); + std::vector depthBuffer(16 * 16); sandBuffer = perlinNoise2->getRegion(sandBuffer, xOffs * 16, zOffs * 16, 0, 16, 16, 1, s, s, 1); @@ -276,9 +275,6 @@ void HellRandomLevelSource::buildSurfaces(int xOffs, int zOffs, } } } - delete[] sandBuffer.data; - delete[] gravelBuffer.data; - delete[] depthBuffer.data; } LevelChunk* HellRandomLevelSource::create(int x, int z) { @@ -294,8 +290,8 @@ LevelChunk* HellRandomLevelSource::getChunk(int xOffs, int zOffs) { uint8_t* tileData = (uint8_t*)XPhysicalAlloc(blocksSize, MAXULONG_PTR, 4096, PAGE_READWRITE); XMemSet128(tileData, 0, blocksSize); - byteArray blocks = byteArray(tileData, blocksSize); - // byteArray blocks = byteArray(16 * level->depth * 16); + std::vector blocks = std::vector(tileData, tileData + blocksSize); + // std::vector blocks = std::vector(16 * level->depth * 16); prepareHeights(xOffs, zOffs, blocks); buildSurfaces(xOffs, zOffs, blocks); @@ -325,17 +321,17 @@ void HellRandomLevelSource::lightChunk(LevelChunk* lc) { lc->recalcHeightmap(); } -doubleArray HellRandomLevelSource::getHeights(doubleArray buffer, int x, int y, +std::vector HellRandomLevelSource::getHeights(std::vector& buffer, int x, int y, int z, int xSize, int ySize, int zSize) { - if (buffer.data == nullptr) { - buffer = doubleArray(xSize * ySize * zSize); + if (buffer.empty()) { + buffer = std::vector(xSize * ySize * zSize); } double s = 1 * 684.412; double hs = 1 * 684.412 * 3; - doubleArray pnr, ar, br, sr, dr, fi, + std::vector pnr, ar, br, sr, dr, fi, fis; // 4J - used to be declared with class level scope but moved here // for thread safety @@ -349,7 +345,7 @@ doubleArray HellRandomLevelSource::getHeights(doubleArray buffer, int x, int y, int p = 0; int pp = 0; - doubleArray yoffs = doubleArray(ySize); + std::vector yoffs = std::vector(ySize); for (int yy = 0; yy < ySize; yy++) { yoffs[yy] = cos(yy * M_PI * 6 / (double)ySize) * 2; @@ -423,14 +419,6 @@ doubleArray HellRandomLevelSource::getHeights(doubleArray buffer, int x, int y, } } - delete[] pnr.data; - delete[] ar.data; - delete[] br.data; - delete[] sr.data; - delete[] dr.data; - delete[] fi.data; - delete[] fis.data; - delete[] yoffs.data; return buffer; } @@ -561,5 +549,6 @@ TilePos* HellRandomLevelSource::findNearestMapFeature( void HellRandomLevelSource::recreateLogicStructuresForChunk(int chunkX, int chunkZ) { - netherBridgeFeature->apply(this, level, chunkX, chunkZ, byteArray()); + std::vector emptyBlocks; + netherBridgeFeature->apply(this, level, chunkX, chunkZ, emptyBlocks); } diff --git a/minecraft/Minecraft.World/net/minecraft/world/level/levelgen/HellRandomLevelSource.h b/minecraft/Minecraft.World/net/minecraft/world/level/levelgen/HellRandomLevelSource.h index 5da7d9a0e..90087ceea 100644 --- a/minecraft/Minecraft.World/net/minecraft/world/level/levelgen/HellRandomLevelSource.h +++ b/minecraft/Minecraft.World/net/minecraft/world/level/levelgen/HellRandomLevelSource.h @@ -42,10 +42,10 @@ public: NetherBridgeFeature* netherBridgeFeature; private: - void prepareHeights(int xOffs, int zOffs, byteArray blocks); + void prepareHeights(int xOffs, int zOffs, std::vector& blocks); public: - void buildSurfaces(int xOffs, int zOffs, byteArray blocks); + void buildSurfaces(int xOffs, int zOffs, std::vector& blocks); private: LargeFeature* caveFeature; @@ -56,7 +56,7 @@ public: virtual void lightChunk(LevelChunk* lc); // 4J added private: - doubleArray getHeights(doubleArray buffer, int x, int y, int z, int xSize, + std::vector getHeights(std::vector& buffer, int x, int y, int z, int xSize, int ySize, int zSize); public: diff --git a/minecraft/Minecraft.World/net/minecraft/world/level/levelgen/LargeCaveFeature.cpp b/minecraft/Minecraft.World/net/minecraft/world/level/levelgen/LargeCaveFeature.cpp index b04a7e263..753d6b4bd 100644 --- a/minecraft/Minecraft.World/net/minecraft/world/level/levelgen/LargeCaveFeature.cpp +++ b/minecraft/Minecraft.World/net/minecraft/world/level/levelgen/LargeCaveFeature.cpp @@ -5,14 +5,14 @@ #include "LargeCaveFeature.h" void LargeCaveFeature::addRoom(int64_t seed, int xOffs, int zOffs, - byteArray blocks, double xRoom, double yRoom, + std::vector& blocks, double xRoom, double yRoom, double zRoom) { addTunnel(seed, xOffs, zOffs, blocks, xRoom, yRoom, zRoom, 1 + random->nextFloat() * 6, 0, 0, -1, -1, 0.5); } void LargeCaveFeature::addTunnel(int64_t seed, int xOffs, int zOffs, - byteArray blocks, double xCave, double yCave, + std::vector& blocks, double xCave, double yCave, double zCave, float thickness, float yRot, float xRot, int step, int dist, double yScale) { @@ -162,7 +162,7 @@ void LargeCaveFeature::addTunnel(int64_t seed, int xOffs, int zOffs, } void LargeCaveFeature::addFeature(Level* level, int x, int z, int xOffs, - int zOffs, byteArray blocks) { + int zOffs, std::vector& blocks) { int caves = random->nextInt(random->nextInt(random->nextInt(40) + 1) + 1); if (random->nextInt(15) != 0) caves = 0; diff --git a/minecraft/Minecraft.World/net/minecraft/world/level/levelgen/LargeCaveFeature.h b/minecraft/Minecraft.World/net/minecraft/world/level/levelgen/LargeCaveFeature.h index aa02f615a..789470684 100644 --- a/minecraft/Minecraft.World/net/minecraft/world/level/levelgen/LargeCaveFeature.h +++ b/minecraft/Minecraft.World/net/minecraft/world/level/levelgen/LargeCaveFeature.h @@ -4,11 +4,11 @@ class LargeCaveFeature : public LargeFeature { protected: - void addRoom(int64_t seed, int xOffs, int zOffs, byteArray blocks, + void addRoom(int64_t seed, int xOffs, int zOffs, std::vector& blocks, double xRoom, double yRoom, double zRoom); - void addTunnel(int64_t seed, int xOffs, int zOffs, byteArray blocks, + void addTunnel(int64_t seed, int xOffs, int zOffs, std::vector& blocks, double xCave, double yCave, double zCave, float thickness, float yRot, float xRot, int step, int dist, double yScale); virtual void addFeature(Level* level, int x, int z, int xOffs, int zOffs, - byteArray blocks); + std::vector& blocks); }; diff --git a/minecraft/Minecraft.World/net/minecraft/world/level/levelgen/LargeFeature.cpp b/minecraft/Minecraft.World/net/minecraft/world/level/levelgen/LargeFeature.cpp index c3426d14e..72d1a466c 100644 --- a/minecraft/Minecraft.World/net/minecraft/world/level/levelgen/LargeFeature.cpp +++ b/minecraft/Minecraft.World/net/minecraft/world/level/levelgen/LargeFeature.cpp @@ -12,7 +12,7 @@ LargeFeature::LargeFeature() { LargeFeature::~LargeFeature() { delete random; } void LargeFeature::apply(ChunkSource* ChunkSource, Level* level, int xOffs, - int zOffs, byteArray blocks) { + int zOffs, std::vector& blocks) { int r = radius; this->level = level; diff --git a/minecraft/Minecraft.World/net/minecraft/world/level/levelgen/LargeFeature.h b/minecraft/Minecraft.World/net/minecraft/world/level/levelgen/LargeFeature.h index cfdc16255..f4b43ea68 100644 --- a/minecraft/Minecraft.World/net/minecraft/world/level/levelgen/LargeFeature.h +++ b/minecraft/Minecraft.World/net/minecraft/world/level/levelgen/LargeFeature.h @@ -17,9 +17,9 @@ public: virtual ~LargeFeature(); virtual void apply(ChunkSource* ChunkSource, Level* level, int xOffs, - int zOffs, byteArray blocks); + int zOffs, std::vector& blocks); protected: virtual void addFeature(Level* level, int x, int z, int xOffs, int zOffs, - byteArray blocks) {} + std::vector& blocks) {} }; \ No newline at end of file diff --git a/minecraft/Minecraft.World/net/minecraft/world/level/levelgen/LargeHellCaveFeature.cpp b/minecraft/Minecraft.World/net/minecraft/world/level/levelgen/LargeHellCaveFeature.cpp index 8f93e74be..eebb98c77 100644 --- a/minecraft/Minecraft.World/net/minecraft/world/level/levelgen/LargeHellCaveFeature.cpp +++ b/minecraft/Minecraft.World/net/minecraft/world/level/levelgen/LargeHellCaveFeature.cpp @@ -4,14 +4,14 @@ #include "../tile/net.minecraft.world.level.tile.h" void LargeHellCaveFeature::addRoom(int64_t seed, int xOffs, int zOffs, - byteArray blocks, double xRoom, double yRoom, + std::vector& blocks, double xRoom, double yRoom, double zRoom) { addTunnel(seed, xOffs, zOffs, blocks, xRoom, yRoom, zRoom, 1 + random->nextFloat() * 6, 0, 0, -1, -1, 0.5); } void LargeHellCaveFeature::addTunnel(int64_t seed, int xOffs, int zOffs, - byteArray blocks, double xCave, + std::vector& blocks, double xCave, double yCave, double zCave, float thickness, float yRot, float xRot, int step, int dist, double yScale) { @@ -146,7 +146,7 @@ void LargeHellCaveFeature::addTunnel(int64_t seed, int xOffs, int zOffs, } void LargeHellCaveFeature::addFeature(Level* level, int x, int z, int xOffs, - int zOffs, byteArray blocks) { + int zOffs, std::vector& blocks) { int caves = random->nextInt(random->nextInt(random->nextInt(10) + 1) + 1); if (random->nextInt(5) != 0) caves = 0; diff --git a/minecraft/Minecraft.World/net/minecraft/world/level/levelgen/LargeHellCaveFeature.h b/minecraft/Minecraft.World/net/minecraft/world/level/levelgen/LargeHellCaveFeature.h index 1a55d6653..8b2b4f7d4 100644 --- a/minecraft/Minecraft.World/net/minecraft/world/level/levelgen/LargeHellCaveFeature.h +++ b/minecraft/Minecraft.World/net/minecraft/world/level/levelgen/LargeHellCaveFeature.h @@ -4,11 +4,11 @@ class LargeHellCaveFeature : public LargeFeature { protected: - void addRoom(int64_t seed, int xOffs, int zOffs, byteArray blocks, + void addRoom(int64_t seed, int xOffs, int zOffs, std::vector& blocks, double xRoom, double yRoom, double zRoom); - void addTunnel(int64_t seed, int xOffs, int zOffs, byteArray blocks, + void addTunnel(int64_t seed, int xOffs, int zOffs, std::vector& blocks, double xCave, double yCave, double zCave, float thickness, float yRot, float xRot, int step, int dist, double yScale); virtual void addFeature(Level* level, int x, int z, int xOffs, int zOffs, - byteArray blocks); + std::vector& blocks); }; diff --git a/minecraft/Minecraft.World/net/minecraft/world/level/levelgen/RandomLevelSource.cpp b/minecraft/Minecraft.World/net/minecraft/world/level/levelgen/RandomLevelSource.cpp index d1ee6b2f3..60d0cd8ff 100644 --- a/minecraft/Minecraft.World/net/minecraft/world/level/levelgen/RandomLevelSource.cpp +++ b/minecraft/Minecraft.World/net/minecraft/world/level/levelgen/RandomLevelSource.cpp @@ -78,7 +78,6 @@ RandomLevelSource::~RandomLevelSource() { delete forestNoise; - if (pows.data != nullptr) delete[] pows.data; } int g_numPrepareHeightCalls = 0; @@ -221,7 +220,7 @@ float RandomLevelSource::getHeightFalloff(int xxx, int zzz, int* pEMin) { #endif -void RandomLevelSource::prepareHeights(int xOffs, int zOffs, byteArray blocks) { +void RandomLevelSource::prepareHeights(int xOffs, int zOffs, std::vector& blocks) { LARGE_INTEGER startTime; int xChunks = 16 / CHUNK_WIDTH; int yChunks = Level::genDepth / CHUNK_HEIGHT; @@ -231,14 +230,14 @@ void RandomLevelSource::prepareHeights(int xOffs, int zOffs, byteArray blocks) { int ySize = Level::genDepth / CHUNK_HEIGHT + 1; int zSize = xChunks + 1; - BiomeArray biomes; // 4J created locally here for thread safety, java has + std::vector biomes; // 4J created locally here for thread safety, java has // this as a class member level->getBiomeSource()->getRawBiomeBlock(biomes, xOffs * CHUNK_WIDTH - 2, zOffs * CHUNK_WIDTH - 2, xSize + 5, zSize + 5); - doubleArray buffer; // 4J - used to be declared with class level scope but + std::vector buffer; // 4J - used to be declared with class level scope but // tidying up for thread safety reasons buffer = getHeights(buffer, xOffs * xChunks, 0, zOffs * xChunks, xSize, ySize, zSize, biomes); @@ -364,17 +363,15 @@ void RandomLevelSource::prepareHeights(int xOffs, int zOffs, byteArray blocks) { g_averagePrepareHeightsTime.QuadPart = g_totalPrepareHeightsTime.QuadPart / g_numPrepareHeightCalls; - delete[] buffer.data; - delete[] biomes.data; } -void RandomLevelSource::buildSurfaces(int xOffs, int zOffs, byteArray blocks, - BiomeArray biomes) { +void RandomLevelSource::buildSurfaces(int xOffs, int zOffs, std::vector& blocks, + std::vector& biomes) { int waterHeight = level->seaLevel; double s = 1 / 32.0; - doubleArray depthBuffer(16 * + std::vector depthBuffer(16 * 16); // 4J - used to be declared with class level // scope but moved here for thread safety @@ -455,7 +452,6 @@ void RandomLevelSource::buildSurfaces(int xOffs, int zOffs, byteArray blocks, } } - delete[] depthBuffer.data; } LevelChunk* RandomLevelSource::create(int x, int z) { return getChunk(x, z); } @@ -469,8 +465,8 @@ LevelChunk* RandomLevelSource::getChunk(int xOffs, int zOffs) { uint8_t* tileData = (uint8_t*)XPhysicalAlloc(blocksSize, MAXULONG_PTR, 4096, PAGE_READWRITE); XMemSet128(tileData, 0, blocksSize); - byteArray blocks = byteArray(tileData, blocksSize); - // byteArray blocks = byteArray(16 * level->depth * 16); + std::vector blocks = std::vector(tileData, tileData + blocksSize); + // std::vector blocks = std::vector(16 * level->depth * 16); // LevelChunk *levelChunk = new LevelChunk(level, blocks, xOffs, zOffs); // // 4J - moved to below @@ -479,13 +475,12 @@ LevelChunk* RandomLevelSource::getChunk(int xOffs, int zOffs) { // 4J - Some changes made here to how biomes, temperatures and downfalls are // passed around for thread safety - BiomeArray biomes; + std::vector biomes; level->getBiomeSource()->getBiomeBlock(biomes, xOffs * 16, zOffs * 16, 16, 16, true); buildSurfaces(xOffs, zOffs, blocks, biomes); - delete[] biomes.data; caveFeature->apply(this, level, xOffs, zOffs, blocks); // 4J Stu Design Change - 1.8 gen goes stronghold, mineshaft, village, @@ -526,14 +521,14 @@ LevelChunk* RandomLevelSource::getChunk(int xOffs, int zOffs) { // does the same. void RandomLevelSource::lightChunk(LevelChunk* lc) { lc->recalcHeightmap(); } -doubleArray RandomLevelSource::getHeights(doubleArray buffer, int x, int y, +std::vector RandomLevelSource::getHeights(std::vector& buffer, int x, int y, int z, int xSize, int ySize, - int zSize, BiomeArray& biomes) { - if (buffer.data == nullptr) { - buffer = doubleArray(xSize * ySize * zSize); + int zSize, std::vector& biomes) { + if (buffer.empty()) { + buffer = std::vector(xSize * ySize * zSize); } - if (pows.data == nullptr) { - pows = floatArray(5 * 5); + if (pows.empty()) { + pows = std::vector(5 * 5); for (int xb = -2; xb <= 2; xb++) { for (int zb = -2; zb <= 2; zb++) { float ppp = 10.0f / Mth::sqrt(xb * xb + zb * zb + 0.2f); @@ -545,7 +540,7 @@ doubleArray RandomLevelSource::getHeights(doubleArray buffer, int x, int y, double s = 1 * 684.412; double hs = 1 * 684.412; - doubleArray pnr, ar, br, sr, dr, fi, + std::vector pnr, ar, br, sr, dr, fi, fis; // 4J - used to be declared with class level scope but moved here // for thread safety @@ -651,13 +646,6 @@ doubleArray RandomLevelSource::getHeights(doubleArray buffer, int x, int y, } } - delete[] pnr.data; - delete[] ar.data; - delete[] br.data; - delete[] sr.data; - delete[] dr.data; - delete[] fi.data; - delete[] fis.data; return buffer; } @@ -869,9 +857,10 @@ TilePos* RandomLevelSource::findNearestMapFeature( void RandomLevelSource::recreateLogicStructuresForChunk(int chunkX, int chunkZ) { if (generateStructures) { - mineShaftFeature->apply(this, level, chunkX, chunkZ, byteArray()); - villageFeature->apply(this, level, chunkX, chunkZ, byteArray()); - strongholdFeature->apply(this, level, chunkX, chunkZ, byteArray()); - scatteredFeature->apply(this, level, chunkX, chunkZ, byteArray()); + std::vector emptyBlocks; + mineShaftFeature->apply(this, level, chunkX, chunkZ, emptyBlocks); + villageFeature->apply(this, level, chunkX, chunkZ, emptyBlocks); + strongholdFeature->apply(this, level, chunkX, chunkZ, emptyBlocks); + scatteredFeature->apply(this, level, chunkX, chunkZ, emptyBlocks); } } diff --git a/minecraft/Minecraft.World/net/minecraft/world/level/levelgen/RandomLevelSource.h b/minecraft/Minecraft.World/net/minecraft/world/level/levelgen/RandomLevelSource.h index 7373d96c0..2118de68c 100644 --- a/minecraft/Minecraft.World/net/minecraft/world/level/levelgen/RandomLevelSource.h +++ b/minecraft/Minecraft.World/net/minecraft/world/level/levelgen/RandomLevelSource.h @@ -42,7 +42,7 @@ private: Level* level; const bool generateStructures; - floatArray pows; + std::vector pows; public: RandomLevelSource(Level* level, int64_t seed, bool generateStructures); @@ -55,11 +55,11 @@ public: #endif float getHeightFalloff(int xxx, int zzz, int* pEMin); - void prepareHeights(int xOffs, int zOffs, byteArray blocks); + void prepareHeights(int xOffs, int zOffs, std::vector& blocks); public: - void buildSurfaces(int xOffs, int zOffs, byteArray blocks, - BiomeArray biomes); + void buildSurfaces(int xOffs, int zOffs, std::vector& blocks, + std::vector& biomes); private: LargeFeature* caveFeature; @@ -77,8 +77,8 @@ public: virtual void lightChunk(LevelChunk* lc); // 4J added private: - doubleArray getHeights(doubleArray buffer, int x, int y, int z, int xSize, - int ySize, int zSize, BiomeArray& biomes); + std::vector getHeights(std::vector& buffer, int x, int y, int z, int xSize, + int ySize, int zSize, std::vector& biomes); public: virtual bool hasChunk(int x, int y); diff --git a/minecraft/Minecraft.World/net/minecraft/world/level/levelgen/TheEndLevelRandomLevelSource.cpp b/minecraft/Minecraft.World/net/minecraft/world/level/levelgen/TheEndLevelRandomLevelSource.cpp index 5a0c935f6..7edaf4dbe 100644 --- a/minecraft/Minecraft.World/net/minecraft/world/level/levelgen/TheEndLevelRandomLevelSource.cpp +++ b/minecraft/Minecraft.World/net/minecraft/world/level/levelgen/TheEndLevelRandomLevelSource.cpp @@ -36,9 +36,9 @@ TheEndLevelRandomLevelSource::~TheEndLevelRandomLevelSource() { } void TheEndLevelRandomLevelSource::prepareHeights(int xOffs, int zOffs, - byteArray blocks, - BiomeArray biomes) { - doubleArray buffer; // 4J - used to be declared with class level scope but + std::vector& blocks, + std::vector& biomes) { + std::vector buffer; // 4J - used to be declared with class level scope but // tidying up for thread safety reasons int xChunks = 16 / CHUNK_WIDTH; @@ -121,12 +121,11 @@ void TheEndLevelRandomLevelSource::prepareHeights(int xOffs, int zOffs, } } } - delete[] buffer.data; } void TheEndLevelRandomLevelSource::buildSurfaces(int xOffs, int zOffs, - byteArray blocks, - BiomeArray biomes) { + std::vector& blocks, + std::vector& biomes) { for (int x = 0; x < 16; x++) { for (int z = 0; z < 16; z++) { int runDepth = 1; @@ -171,15 +170,15 @@ LevelChunk* TheEndLevelRandomLevelSource::create(int x, int z) { LevelChunk* TheEndLevelRandomLevelSource::getChunk(int xOffs, int zOffs) { random->setSeed(xOffs * 341873128712l + zOffs * 132897987541l); - BiomeArray biomes; + std::vector biomes; // 4J - now allocating this with a physical alloc & bypassing general memory // management so that it will get cleanly freed unsigned int blocksSize = Level::genDepth * 16 * 16; uint8_t* tileData = (uint8_t*)XPhysicalAlloc(blocksSize, MAXULONG_PTR, 4096, PAGE_READWRITE); XMemSet128(tileData, 0, blocksSize); - byteArray blocks = byteArray(tileData, blocksSize); - // byteArray blocks = byteArray(16 * level->depth * 16); + std::vector blocks = std::vector(tileData, tileData + blocksSize); + // std::vector blocks = std::vector(16 * level->depth * 16); // LevelChunk *levelChunk = new LevelChunk(level, blocks, xOffs, zOffs); // // 4J moved below @@ -198,24 +197,23 @@ LevelChunk* TheEndLevelRandomLevelSource::getChunk(int xOffs, int zOffs) { levelChunk->recalcHeightmap(); - // delete blocks.data; // Don't delete the blocks as the array data is + // delete blocks.data(); // Don't delete the blocks as the array data is // actually owned by the chunk now - delete biomes.data; return levelChunk; } -doubleArray TheEndLevelRandomLevelSource::getHeights(doubleArray buffer, int x, +std::vector TheEndLevelRandomLevelSource::getHeights(std::vector& buffer, int x, int y, int z, int xSize, int ySize, int zSize) { - if (buffer.data == nullptr) { - buffer = doubleArray(xSize * ySize * zSize); + if (buffer.empty()) { + buffer = std::vector(xSize * ySize * zSize); } double s = 1 * 684.412; double hs = 1 * 684.412; - doubleArray pnr, ar, br, sr, dr, fi, + std::vector pnr, ar, br, sr, dr, fi, fis; // 4J - used to be declared with class level scope but moved here // for thread safety @@ -296,13 +294,6 @@ doubleArray TheEndLevelRandomLevelSource::getHeights(doubleArray buffer, int x, } } - delete[] pnr.data; - delete[] ar.data; - delete[] br.data; - delete[] sr.data; - delete[] dr.data; - delete[] fi.data; - delete[] fis.data; return buffer; } diff --git a/minecraft/Minecraft.World/net/minecraft/world/level/levelgen/TheEndLevelRandomLevelSource.h b/minecraft/Minecraft.World/net/minecraft/world/level/levelgen/TheEndLevelRandomLevelSource.h index b154c8d75..d4217c816 100644 --- a/minecraft/Minecraft.World/net/minecraft/world/level/levelgen/TheEndLevelRandomLevelSource.h +++ b/minecraft/Minecraft.World/net/minecraft/world/level/levelgen/TheEndLevelRandomLevelSource.h @@ -33,17 +33,17 @@ public: TheEndLevelRandomLevelSource(Level* level, int64_t seed); ~TheEndLevelRandomLevelSource(); - void prepareHeights(int xOffs, int zOffs, byteArray blocks, - BiomeArray biomes); - void buildSurfaces(int xOffs, int zOffs, byteArray blocks, - BiomeArray biomes); + void prepareHeights(int xOffs, int zOffs, std::vector& blocks, + std::vector& biomes); + void buildSurfaces(int xOffs, int zOffs, std::vector& blocks, + std::vector& biomes); public: virtual LevelChunk* create(int x, int z); virtual LevelChunk* getChunk(int xOffs, int zOffs); private: - doubleArray getHeights(doubleArray buffer, int x, int y, int z, int xSize, + std::vector getHeights(std::vector& buffer, int x, int y, int z, int xSize, int ySize, int zSize); public: diff --git a/minecraft/Minecraft.World/net/minecraft/world/level/levelgen/feature/BonusChestFeature.cpp b/minecraft/Minecraft.World/net/minecraft/world/level/levelgen/feature/BonusChestFeature.cpp index c105fb715..3eda0b207 100644 --- a/minecraft/Minecraft.World/net/minecraft/world/level/levelgen/feature/BonusChestFeature.cpp +++ b/minecraft/Minecraft.World/net/minecraft/world/level/levelgen/feature/BonusChestFeature.cpp @@ -6,7 +6,7 @@ #include "../../../../util/WeighedTreasure.h" #include "../structure/StructurePiece.h" -BonusChestFeature::BonusChestFeature(WeighedTreasureArray treasureList, +BonusChestFeature::BonusChestFeature(std::vector& treasureList, int numRolls) : treasureList(treasureList), numRolls(numRolls) {} diff --git a/minecraft/Minecraft.World/net/minecraft/world/level/levelgen/feature/BonusChestFeature.h b/minecraft/Minecraft.World/net/minecraft/world/level/levelgen/feature/BonusChestFeature.h index 0b8f67bd1..e546a0e4e 100644 --- a/minecraft/Minecraft.World/net/minecraft/world/level/levelgen/feature/BonusChestFeature.h +++ b/minecraft/Minecraft.World/net/minecraft/world/level/levelgen/feature/BonusChestFeature.h @@ -6,11 +6,11 @@ class Level; class BonusChestFeature : public Feature { private: - const WeighedTreasureArray treasureList; + const std::vector treasureList; const int numRolls; public: - BonusChestFeature(WeighedTreasureArray treasureList, int numRolls); + BonusChestFeature(std::vector& treasureList, int numRolls); virtual bool place(Level* level, Random* random, int x, int y, int z); bool place(Level* level, Random* random, int x, int y, int z, diff --git a/minecraft/Minecraft.World/net/minecraft/world/level/levelgen/feature/MonsterRoomFeature.cpp b/minecraft/Minecraft.World/net/minecraft/world/level/levelgen/feature/MonsterRoomFeature.cpp index 876791016..3595058f7 100644 --- a/minecraft/Minecraft.World/net/minecraft/world/level/levelgen/feature/MonsterRoomFeature.cpp +++ b/minecraft/Minecraft.World/net/minecraft/world/level/levelgen/feature/MonsterRoomFeature.cpp @@ -96,9 +96,9 @@ bool MonsterRoomFeature::place(Level* level, Random* random, int x, int y, level->setTileAndData(xc, yc, zc, Tile::chest_Id, 0, Tile::UPDATE_CLIENTS); - WeighedTreasureArray wrapperArray(monsterRoomTreasure, - TREASURE_ITEMS_COUNT); - WeighedTreasureArray treasure = WeighedTreasure::addToTreasure( + std::vector wrapperArray(monsterRoomTreasure, + monsterRoomTreasure + TREASURE_ITEMS_COUNT); + std::vector treasure = WeighedTreasure::addToTreasure( wrapperArray, Item::enchantedBook->createForRandomTreasure(random)); std::shared_ptr chest = diff --git a/minecraft/Minecraft.World/net/minecraft/world/level/levelgen/structure/BlockGenMethods.cpp b/minecraft/Minecraft.World/net/minecraft/world/level/levelgen/structure/BlockGenMethods.cpp index 2f47b5aff..2a3e15912 100644 --- a/minecraft/Minecraft.World/net/minecraft/world/level/levelgen/structure/BlockGenMethods.cpp +++ b/minecraft/Minecraft.World/net/minecraft/world/level/levelgen/structure/BlockGenMethods.cpp @@ -3,7 +3,7 @@ #include "../../net.minecraft.world.level.h" #include "BlockGenMethods.h" -void BlockGenMethods::generateBox(Level* level, byteArray blocks, int sx, +void BlockGenMethods::generateBox(Level* level, std::vector& blocks, int sx, int sy, int sz, int ex, int ey, int ez, std::uint8_t edge, std::uint8_t filling) { sx = Mth::clamp(sx, 0, 15); @@ -29,7 +29,7 @@ void BlockGenMethods::generateBox(Level* level, byteArray blocks, int sx, } } -void BlockGenMethods::generateFrame(Level* level, byteArray blocks, int sx, +void BlockGenMethods::generateFrame(Level* level, std::vector& blocks, int sx, int sy, int ex, int ey, int flatZ, int direction, std::uint8_t edge, std::uint8_t filling) { @@ -84,7 +84,7 @@ void BlockGenMethods::generateFrame(Level* level, byteArray blocks, int sx, } } -void BlockGenMethods::generateDirectionLine(Level* level, byteArray blocks, +void BlockGenMethods::generateDirectionLine(Level* level, std::vector& blocks, int sx, int sy, int sz, int ex, int ey, int ez, int startDirection, int endDirection, @@ -182,7 +182,7 @@ void BlockGenMethods::generateDirectionLine(Level* level, byteArray blocks, } } -void BlockGenMethods::generateLine(Level* level, byteArray blocks, int sx, +void BlockGenMethods::generateLine(Level* level, std::vector& blocks, int sx, int sy, int sz, int ex, int ey, int ez, std::uint8_t block) { generateDirectionLine(level, blocks, sx, sy, sz, ex, ey, ez, 0, 0, block); diff --git a/minecraft/Minecraft.World/net/minecraft/world/level/levelgen/structure/BlockGenMethods.h b/minecraft/Minecraft.World/net/minecraft/world/level/levelgen/structure/BlockGenMethods.h index 2e62430dd..b9e3fafa5 100644 --- a/minecraft/Minecraft.World/net/minecraft/world/level/levelgen/structure/BlockGenMethods.h +++ b/minecraft/Minecraft.World/net/minecraft/world/level/levelgen/structure/BlockGenMethods.h @@ -5,17 +5,17 @@ class BlockGenMethods { public: - static void generateBox(Level* level, byteArray blocks, int sx, int sy, + static void generateBox(Level* level, std::vector& blocks, int sx, int sy, int sz, int ex, int ey, int ez, std::uint8_t edge, std::uint8_t filling); - static void generateFrame(Level* level, byteArray blocks, int sx, int sy, + static void generateFrame(Level* level, std::vector& blocks, int sx, int sy, int ex, int ey, int flatZ, int direction, std::uint8_t edge, std::uint8_t filling); - static void generateDirectionLine(Level* level, byteArray blocks, int sx, + static void generateDirectionLine(Level* level, std::vector& blocks, int sx, int sy, int sz, int ex, int ey, int ez, int startDirection, int endDirection, std::uint8_t block); - static void generateLine(Level* level, byteArray blocks, int sx, int sy, + static void generateLine(Level* level, std::vector& blocks, int sx, int sy, int sz, int ex, int ey, int ez, std::uint8_t block); }; diff --git a/minecraft/Minecraft.World/net/minecraft/world/level/levelgen/structure/BoundingBox.cpp b/minecraft/Minecraft.World/net/minecraft/world/level/levelgen/structure/BoundingBox.cpp index 6bcffc5fe..9822ef066 100644 --- a/minecraft/Minecraft.World/net/minecraft/world/level/levelgen/structure/BoundingBox.cpp +++ b/minecraft/Minecraft.World/net/minecraft/world/level/levelgen/structure/BoundingBox.cpp @@ -13,8 +13,8 @@ BoundingBox::BoundingBox() { z1 = 0; } -BoundingBox::BoundingBox(intArray sourceData) { - if (sourceData.length == 6) { +BoundingBox::BoundingBox(const std::vector& sourceData) { + if (sourceData.size() == 6) { x0 = sourceData[0]; y0 = sourceData[1]; z0 = sourceData[2]; @@ -175,5 +175,5 @@ IntArrayTag* BoundingBox::createTag(const std::wstring& name) { data[4] = y1; data[5] = z1; - return new IntArrayTag(name, intArray(data, 6)); + return new IntArrayTag(name, std::vector(data, data + 6)); } \ No newline at end of file diff --git a/minecraft/Minecraft.World/net/minecraft/world/level/levelgen/structure/BoundingBox.h b/minecraft/Minecraft.World/net/minecraft/world/level/levelgen/structure/BoundingBox.h index 9d57f09f0..07dfbae29 100644 --- a/minecraft/Minecraft.World/net/minecraft/world/level/levelgen/structure/BoundingBox.h +++ b/minecraft/Minecraft.World/net/minecraft/world/level/levelgen/structure/BoundingBox.h @@ -7,7 +7,7 @@ public: int x0, y0, z0, x1, y1, z1; BoundingBox(); - BoundingBox(intArray sourceData); + BoundingBox(const std::vector& sourceData); static BoundingBox* getUnknownBox(); static BoundingBox* orientBox(int footX, int footY, int footZ, int offX, int offY, int offZ, int width, int height, diff --git a/minecraft/Minecraft.World/net/minecraft/world/level/levelgen/structure/MineShaftPieces.cpp b/minecraft/Minecraft.World/net/minecraft/world/level/levelgen/structure/MineShaftPieces.cpp index 709e58bc8..9b6a8407a 100644 --- a/minecraft/Minecraft.World/net/minecraft/world/level/levelgen/structure/MineShaftPieces.cpp +++ b/minecraft/Minecraft.World/net/minecraft/world/level/levelgen/structure/MineShaftPieces.cpp @@ -9,11 +9,11 @@ #include "../../../../util/WeighedTreasure.h" #include "MineShaftPieces.h" -WeighedTreasureArray MineShaftPieces::smallTreasureItems; +std::vector MineShaftPieces::smallTreasureItems; ; void MineShaftPieces::staticCtor() { - smallTreasureItems = WeighedTreasureArray(13); + smallTreasureItems = std::vector(13); smallTreasureItems[0] = new WeighedTreasure(Item::ironIngot_Id, 0, 1, 5, 10); smallTreasureItems[1] = new WeighedTreasure(Item::goldIngot_Id, 0, 1, 3, 5); @@ -463,7 +463,7 @@ void MineShaftPieces::MineShaftCorridor::addChildren( bool MineShaftPieces::MineShaftCorridor::createChest( Level* level, BoundingBox* chunkBB, Random* random, int x, int y, int z, - WeighedTreasureArray treasure, int numRolls) { + const std::vector& treasure, int numRolls) { int worldX = getWorldX(x, z); int worldY = getWorldY(y); int worldZ = getWorldZ(x, z); diff --git a/minecraft/Minecraft.World/net/minecraft/world/level/levelgen/structure/MineShaftPieces.h b/minecraft/Minecraft.World/net/minecraft/world/level/levelgen/structure/MineShaftPieces.h index 696094b86..40e7bb7f0 100644 --- a/minecraft/Minecraft.World/net/minecraft/world/level/levelgen/structure/MineShaftPieces.h +++ b/minecraft/Minecraft.World/net/minecraft/world/level/levelgen/structure/MineShaftPieces.h @@ -92,7 +92,7 @@ public: protected: virtual bool createChest(Level* level, BoundingBox* chunkBB, Random* random, int x, int y, int z, - WeighedTreasureArray treasure, int numRolls); + const std::vector& treasure, int numRolls); public: virtual bool postProcess(Level* level, Random* random, @@ -168,7 +168,7 @@ public: /* @formatter:off */ private: - static WeighedTreasureArray smallTreasureItems; + static std::vector smallTreasureItems; /* @formatter:on */ public: diff --git a/minecraft/Minecraft.World/net/minecraft/world/level/levelgen/structure/NetherBridgePieces.cpp b/minecraft/Minecraft.World/net/minecraft/world/level/levelgen/structure/NetherBridgePieces.cpp index e57a4dd3d..0b91e947a 100644 --- a/minecraft/Minecraft.World/net/minecraft/world/level/levelgen/structure/NetherBridgePieces.cpp +++ b/minecraft/Minecraft.World/net/minecraft/world/level/levelgen/structure/NetherBridgePieces.cpp @@ -1654,7 +1654,7 @@ bool NetherBridgePieces::CastleSmallCorridorRightTurnPiece::postProcess( if (chunkBB->isInside(x, y, z)) { isNeedingChest = false; createChest(level, chunkBB, random, 1, 2, 3, - WeighedTreasureArray(fortressTreasureItems, + std::vector(fortressTreasureItems, fortressTreasureItems + FORTRESS_TREASURE_ITEMS_COUNT), 2 + random->nextInt(4)); } @@ -1762,7 +1762,7 @@ bool NetherBridgePieces::CastleSmallCorridorLeftTurnPiece::postProcess( if (chunkBB->isInside(x, y, z)) { isNeedingChest = false; createChest(level, chunkBB, random, 3, 2, 3, - WeighedTreasureArray(fortressTreasureItems, + std::vector(fortressTreasureItems, fortressTreasureItems + FORTRESS_TREASURE_ITEMS_COUNT), 2 + random->nextInt(4)); } diff --git a/minecraft/Minecraft.World/net/minecraft/world/level/levelgen/structure/ScatteredFeaturePieces.cpp b/minecraft/Minecraft.World/net/minecraft/world/level/levelgen/structure/ScatteredFeaturePieces.cpp index 5bdced3dc..b420daf21 100644 --- a/minecraft/Minecraft.World/net/minecraft/world/level/levelgen/structure/ScatteredFeaturePieces.cpp +++ b/minecraft/Minecraft.World/net/minecraft/world/level/levelgen/structure/ScatteredFeaturePieces.cpp @@ -449,9 +449,7 @@ bool ScatteredFeaturePieces::DesertPyramidPiece::postProcess( int zo = Direction::STEP_Z[i] * 2; hasPlacedChest[i] = createChest( level, chunkBB, random, 10 + xo, -11, 10 + zo, - WeighedTreasure::addToTreasure( - WeighedTreasureArray(treasureItems, TREASURE_ITEMS_COUNT), - Item::enchantedBook->createForRandomTreasure(random)), + [&]() { auto items = std::vector(treasureItems, treasureItems + TREASURE_ITEMS_COUNT); return WeighedTreasure::addToTreasure(items, Item::enchantedBook->createForRandomTreasure(random)); }(), 2 + random->nextInt(5)); } } @@ -702,7 +700,7 @@ bool ScatteredFeaturePieces::JunglePyramidPiece::postProcess( if (!placedTrap1) { placedTrap1 = createDispenser( level, chunkBB, random, 3, -2, 1, Facing::NORTH, - WeighedTreasureArray(dispenserItems, DISPENSER_ITEMS_COUNT), 2); + std::vector(dispenserItems, dispenserItems + DISPENSER_ITEMS_COUNT), 2); } placeBlock(level, Tile::vine_Id, 0xf, 3, -2, 2, chunkBB); @@ -729,16 +727,14 @@ bool ScatteredFeaturePieces::JunglePyramidPiece::postProcess( if (!placedTrap2) { placedTrap2 = createDispenser( level, chunkBB, random, 9, -2, 3, Facing::WEST, - WeighedTreasureArray(dispenserItems, DISPENSER_ITEMS_COUNT), 2); + std::vector(dispenserItems, dispenserItems + DISPENSER_ITEMS_COUNT), 2); } placeBlock(level, Tile::vine_Id, 0xf, 8, -1, 3, chunkBB); placeBlock(level, Tile::vine_Id, 0xf, 8, -2, 3, chunkBB); if (!placedMainChest) { placedMainChest = createChest( level, chunkBB, random, 8, -3, 3, - WeighedTreasure::addToTreasure( - WeighedTreasureArray(treasureItems, TREASURE_ITEMS_COUNT), - Item::enchantedBook->createForRandomTreasure(random)), + [&]() { auto items = std::vector(treasureItems, treasureItems + TREASURE_ITEMS_COUNT); return WeighedTreasure::addToTreasure(items, Item::enchantedBook->createForRandomTreasure(random)); }(), 2 + random->nextInt(5)); } placeBlock(level, Tile::mossyCobblestone_Id, 0, 9, -3, 2, chunkBB); @@ -794,9 +790,7 @@ bool ScatteredFeaturePieces::JunglePyramidPiece::postProcess( if (!placedHiddenChest) { placedHiddenChest = createChest( level, chunkBB, random, 9, -3, 10, - WeighedTreasure::addToTreasure( - WeighedTreasureArray(treasureItems, TREASURE_ITEMS_COUNT), - Item::enchantedBook->createForRandomTreasure(random)), + [&]() { auto items = std::vector(treasureItems, treasureItems + TREASURE_ITEMS_COUNT); return WeighedTreasure::addToTreasure(items, Item::enchantedBook->createForRandomTreasure(random)); }(), 2 + random->nextInt(5)); } diff --git a/minecraft/Minecraft.World/net/minecraft/world/level/levelgen/structure/StrongholdPieces.cpp b/minecraft/Minecraft.World/net/minecraft/world/level/levelgen/structure/StrongholdPieces.cpp index 0807bc1c3..6a96b9dcc 100644 --- a/minecraft/Minecraft.World/net/minecraft/world/level/levelgen/structure/StrongholdPieces.cpp +++ b/minecraft/Minecraft.World/net/minecraft/world/level/levelgen/structure/StrongholdPieces.cpp @@ -908,9 +908,7 @@ bool StrongholdPieces::ChestCorridor::postProcess(Level* level, Random* random, hasPlacedChest = true; createChest( level, chunkBB, random, 3, 2, 3, - WeighedTreasure::addToTreasure( - WeighedTreasureArray(treasureItems, TREASURE_ITEMS_COUNT), - Item::enchantedBook->createForRandomTreasure(random)), + [&]() { auto items = std::vector(treasureItems, treasureItems + TREASURE_ITEMS_COUNT); return WeighedTreasure::addToTreasure(items, Item::enchantedBook->createForRandomTreasure(random)); }(), 2 + random->nextInt(2)); } } @@ -1263,10 +1261,7 @@ bool StrongholdPieces::RoomCrossing::postProcess(Level* level, Random* random, createChest( level, chunkBB, random, 3, 4, 8, - WeighedTreasure::addToTreasure( - WeighedTreasureArray(smallTreasureItems, - SMALL_TREASURE_ITEMS_COUNT), - Item::enchantedBook->createForRandomTreasure(random)), + [&]() { auto items = std::vector(smallTreasureItems, smallTreasureItems + SMALL_TREASURE_ITEMS_COUNT); return WeighedTreasure::addToTreasure(items, Item::enchantedBook->createForRandomTreasure(random)); }(), 1 + random->nextInt(4)); // System.out.println("Created chest at " + getWorldX(3, 8) + // "," + getWorldY(4) + "," + getWorldZ(3, 8)); @@ -1564,19 +1559,13 @@ bool StrongholdPieces::Library::postProcess(Level* level, Random* random, // place chests createChest( level, chunkBB, random, 3, 3, 5, - WeighedTreasure::addToTreasure( - WeighedTreasureArray(libraryTreasureItems, - LIBRARY_TREASURE_ITEMS_COUNT), - Item::enchantedBook->createForRandomTreasure(random, 1, 5, 2)), + [&]() { auto items = std::vector(libraryTreasureItems, libraryTreasureItems + LIBRARY_TREASURE_ITEMS_COUNT); return WeighedTreasure::addToTreasure(items, Item::enchantedBook->createForRandomTreasure(random, 1, 5, 2)); }(), 1 + random->nextInt(4)); if (isTall) { placeBlock(level, 0, 0, width - 2, tallHeight - 2, 1, chunkBB); createChest( level, chunkBB, random, width - 2, tallHeight - 3, 1, - WeighedTreasure::addToTreasure( - WeighedTreasureArray(libraryTreasureItems, - LIBRARY_TREASURE_ITEMS_COUNT), - Item::enchantedBook->createForRandomTreasure(random, 1, 5, 2)), + [&]() { auto items = std::vector(libraryTreasureItems, libraryTreasureItems + LIBRARY_TREASURE_ITEMS_COUNT); return WeighedTreasure::addToTreasure(items, Item::enchantedBook->createForRandomTreasure(random, 1, 5, 2)); }(), 1 + random->nextInt(4)); } diff --git a/minecraft/Minecraft.World/net/minecraft/world/level/levelgen/structure/StructureFeature.cpp b/minecraft/Minecraft.World/net/minecraft/world/level/levelgen/structure/StructureFeature.cpp index 87a5be4e0..db724ddea 100644 --- a/minecraft/Minecraft.World/net/minecraft/world/level/levelgen/structure/StructureFeature.cpp +++ b/minecraft/Minecraft.World/net/minecraft/world/level/levelgen/structure/StructureFeature.cpp @@ -21,7 +21,7 @@ StructureFeature::~StructureFeature() { } void StructureFeature::addFeature(Level* level, int x, int z, int xOffs, - int zOffs, byteArray blocks) { + int zOffs, std::vector& blocks) { // this method is called for each chunk within 8 chunk's distance from // the chunk being generated, but not all chunks are the sources of // structures @@ -177,7 +177,8 @@ TilePos* StructureFeature::getNearestGeneratedFeature(Level* level, int cellX, int64_t zz = (cellZ >> 4) * zScale; random->setSeed(xx ^ zz ^ level->getSeed()); - addFeature(level, cellX >> 4, cellZ >> 4, 0, 0, byteArray()); + std::vector emptyBlocks; + addFeature(level, cellX >> 4, cellZ >> 4, 0, 0, emptyBlocks); double minDistance = DBL_MAX; TilePos* selected = nullptr; diff --git a/minecraft/Minecraft.World/net/minecraft/world/level/levelgen/structure/StructureFeature.h b/minecraft/Minecraft.World/net/minecraft/world/level/levelgen/structure/StructureFeature.h index 3ad27f63b..16a407cce 100644 --- a/minecraft/Minecraft.World/net/minecraft/world/level/levelgen/structure/StructureFeature.h +++ b/minecraft/Minecraft.World/net/minecraft/world/level/levelgen/structure/StructureFeature.h @@ -32,7 +32,7 @@ public: virtual std::wstring getFeatureName() = 0; virtual void addFeature(Level* level, int x, int z, int xOffs, int zOffs, - byteArray blocks); + std::vector& blocks); bool postProcess(Level* level, Random* random, int chunkX, int chunkZ); bool isIntersection(int cellX, int cellZ); diff --git a/minecraft/Minecraft.World/net/minecraft/world/level/levelgen/structure/StructurePiece.cpp b/minecraft/Minecraft.World/net/minecraft/world/level/levelgen/structure/StructurePiece.cpp index 23d8aa558..26a3d7777 100644 --- a/minecraft/Minecraft.World/net/minecraft/world/level/levelgen/structure/StructurePiece.cpp +++ b/minecraft/Minecraft.World/net/minecraft/world/level/levelgen/structure/StructurePiece.cpp @@ -649,7 +649,7 @@ void StructurePiece::fillColumnDown(Level* level, int tile, int tileData, int x, bool StructurePiece::createChest(Level* level, BoundingBox* chunkBB, Random* random, int x, int y, int z, - WeighedTreasureArray treasure, int numRolls) { + const std::vector& treasure, int numRolls) { int worldX = getWorldX(x, z); int worldY = getWorldY(y); int worldZ = getWorldZ(x, z); @@ -672,7 +672,7 @@ bool StructurePiece::createChest(Level* level, BoundingBox* chunkBB, bool StructurePiece::createDispenser(Level* level, BoundingBox* chunkBB, Random* random, int x, int y, int z, - int facing, WeighedTreasureArray items, + int facing, const std::vector& items, int numRolls) { int worldX = getWorldX(x, z); int worldY = getWorldY(y); diff --git a/minecraft/Minecraft.World/net/minecraft/world/level/levelgen/structure/StructurePiece.h b/minecraft/Minecraft.World/net/minecraft/world/level/levelgen/structure/StructurePiece.h index f571d9d78..28dcc7f89 100644 --- a/minecraft/Minecraft.World/net/minecraft/world/level/levelgen/structure/StructurePiece.h +++ b/minecraft/Minecraft.World/net/minecraft/world/level/levelgen/structure/StructurePiece.h @@ -160,11 +160,11 @@ public: virtual void fillColumnDown(Level* level, int tile, int tileData, int x, int startY, int z, BoundingBox* chunkBB); virtual bool createChest(Level* level, BoundingBox* chunkBB, Random* random, - int x, int y, int z, WeighedTreasureArray treasure, + int x, int y, int z, const std::vector& treasure, int numRolls); virtual bool createDispenser(Level* level, BoundingBox* chunkBB, Random* random, int x, int y, int z, - int facing, WeighedTreasureArray items, + int facing, const std::vector& items, int numRolls); protected: diff --git a/minecraft/Minecraft.World/net/minecraft/world/level/levelgen/structure/VillagePieces.cpp b/minecraft/Minecraft.World/net/minecraft/world/level/levelgen/structure/VillagePieces.cpp index c896744db..c9745141f 100644 --- a/minecraft/Minecraft.World/net/minecraft/world/level/levelgen/structure/VillagePieces.cpp +++ b/minecraft/Minecraft.World/net/minecraft/world/level/levelgen/structure/VillagePieces.cpp @@ -15,7 +15,7 @@ #include "java/JavaMath.h" #include "../../biome/BiomeSource.h" -WeighedTreasureArray VillagePieces::Smithy::treasureItems; +std::vector VillagePieces::Smithy::treasureItems; void VillagePieces::loadStatic() { StructureFeatureIO::setPieceId(eStructurePiece_BookHouse, BookHouse::Create, @@ -1705,7 +1705,7 @@ bool VillagePieces::TwoRoomHouse::postProcess(Level* level, Random* random, } void VillagePieces::Smithy::staticCtor() { - treasureItems = WeighedTreasureArray(17); + treasureItems = std::vector(17); treasureItems[0] = new WeighedTreasure(Item::diamond_Id, 0, 1, 3, 3); treasureItems[1] = new WeighedTreasure(Item::ironIngot_Id, 0, 1, 5, 10); treasureItems[2] = new WeighedTreasure(Item::goldIngot_Id, 0, 1, 3, 5); diff --git a/minecraft/Minecraft.World/net/minecraft/world/level/levelgen/structure/VillagePieces.h b/minecraft/Minecraft.World/net/minecraft/world/level/levelgen/structure/VillagePieces.h index 5ba7b1063..4c0f8614b 100644 --- a/minecraft/Minecraft.World/net/minecraft/world/level/levelgen/structure/VillagePieces.h +++ b/minecraft/Minecraft.World/net/minecraft/world/level/levelgen/structure/VillagePieces.h @@ -412,7 +412,7 @@ public: bool hasPlacedChest; - static WeighedTreasureArray treasureItems; + static std::vector treasureItems; public: static void staticCtor(); diff --git a/minecraft/Minecraft.World/net/minecraft/world/level/levelgen/synth/FastNoise.cpp b/minecraft/Minecraft.World/net/minecraft/world/level/levelgen/synth/FastNoise.cpp index 49cb1144c..d84909170 100644 --- a/minecraft/Minecraft.World/net/minecraft/world/level/levelgen/synth/FastNoise.cpp +++ b/minecraft/Minecraft.World/net/minecraft/world/level/levelgen/synth/FastNoise.cpp @@ -24,13 +24,13 @@ FastNoise::~FastNoise() { delete[] noiseMaps; } -doubleArray FastNoise::getRegion(doubleArray buffer, double x, double y, +std::vector FastNoise::getRegion(std::vector& buffer, double x, double y, double z, int xSize, int ySize, int zSize, double xScale, double yScale, double zScale) { - if (buffer.data == nullptr) - buffer = doubleArray(xSize * ySize * zSize); + if (buffer.empty()) + buffer = std::vector(xSize * ySize * zSize); else - for (unsigned int i = 0; i < buffer.length; i++) buffer[i] = 0; + for (unsigned int i = 0; i < buffer.size(); i++) buffer[i] = 0; double pow = 1; int AA = 487211441; diff --git a/minecraft/Minecraft.World/net/minecraft/world/level/levelgen/synth/FastNoise.h b/minecraft/Minecraft.World/net/minecraft/world/level/levelgen/synth/FastNoise.h index c1ebbec3f..fe8c36621 100644 --- a/minecraft/Minecraft.World/net/minecraft/world/level/levelgen/synth/FastNoise.h +++ b/minecraft/Minecraft.World/net/minecraft/world/level/levelgen/synth/FastNoise.h @@ -12,7 +12,7 @@ public: void init(Random* random, int levels); ~FastNoise(); - doubleArray getRegion(doubleArray buffer, double x, double y, double z, + std::vector getRegion(std::vector& buffer, double x, double y, double z, int xSize, int ySize, int zSize, double xScale, double yScale, double zScale); }; \ No newline at end of file diff --git a/minecraft/Minecraft.World/net/minecraft/world/level/levelgen/synth/ImprovedNoise.cpp b/minecraft/Minecraft.World/net/minecraft/world/level/levelgen/synth/ImprovedNoise.cpp index 4ece4a30b..6089fa764 100644 --- a/minecraft/Minecraft.World/net/minecraft/world/level/levelgen/synth/ImprovedNoise.cpp +++ b/minecraft/Minecraft.World/net/minecraft/world/level/levelgen/synth/ImprovedNoise.cpp @@ -104,7 +104,7 @@ double ImprovedNoise::getValue(double x, double y, double z) { return noise(x, y, z); } -void ImprovedNoise::add(doubleArray buffer, double _x, double _y, double _z, +void ImprovedNoise::add(std::vector& buffer, double _x, double _y, double _z, int xSize, int ySize, int zSize, double xs, double ys, double zs, double pow) { if (ySize == 1) { diff --git a/minecraft/Minecraft.World/net/minecraft/world/level/levelgen/synth/ImprovedNoise.h b/minecraft/Minecraft.World/net/minecraft/world/level/levelgen/synth/ImprovedNoise.h index 6573fbb47..a012950b5 100644 --- a/minecraft/Minecraft.World/net/minecraft/world/level/levelgen/synth/ImprovedNoise.h +++ b/minecraft/Minecraft.World/net/minecraft/world/level/levelgen/synth/ImprovedNoise.h @@ -25,6 +25,6 @@ public: virtual double getValue(double x, double y); double getValue(double x, double y, double z); - void add(doubleArray buffer, double _x, double _y, double _z, int xSize, + void add(std::vector& buffer, double _x, double _y, double _z, int xSize, int ySize, int zSize, double xs, double ys, double zs, double pow); }; diff --git a/minecraft/Minecraft.World/net/minecraft/world/level/levelgen/synth/PerlinNoise.cpp b/minecraft/Minecraft.World/net/minecraft/world/level/levelgen/synth/PerlinNoise.cpp index 7ef6d9b9f..7b06a1858 100644 --- a/minecraft/Minecraft.World/net/minecraft/world/level/levelgen/synth/PerlinNoise.cpp +++ b/minecraft/Minecraft.World/net/minecraft/world/level/levelgen/synth/PerlinNoise.cpp @@ -50,14 +50,14 @@ double PerlinNoise::getValue(double x, double y, double z) { return value; } -doubleArray PerlinNoise::getRegion(doubleArray buffer, int x, int y, int z, +std::vector PerlinNoise::getRegion(std::vector& buffer, int x, int y, int z, int xSize, int ySize, int zSize, double xScale, double yScale, double zScale) { - if (buffer.data == nullptr) - buffer = doubleArray(xSize * ySize * zSize); + if (buffer.empty()) + buffer = std::vector(xSize * ySize * zSize); else - for (unsigned int i = 0; i < buffer.length; i++) buffer[i] = 0; + for (unsigned int i = 0; i < buffer.size(); i++) buffer[i] = 0; double pow = 1; @@ -83,7 +83,7 @@ doubleArray PerlinNoise::getRegion(doubleArray buffer, int x, int y, int z, return buffer; } -doubleArray PerlinNoise::getRegion(doubleArray sr, int x, int z, int xSize, +std::vector PerlinNoise::getRegion(std::vector& sr, int x, int z, int xSize, int zSize, double xScale, double zScale, double pow) { return getRegion(sr, x, 10, z, xSize, 1, zSize, xScale, 1, zScale); diff --git a/minecraft/Minecraft.World/net/minecraft/world/level/levelgen/synth/PerlinNoise.h b/minecraft/Minecraft.World/net/minecraft/world/level/levelgen/synth/PerlinNoise.h index 2429f52d0..824400cb2 100644 --- a/minecraft/Minecraft.World/net/minecraft/world/level/levelgen/synth/PerlinNoise.h +++ b/minecraft/Minecraft.World/net/minecraft/world/level/levelgen/synth/PerlinNoise.h @@ -18,9 +18,9 @@ public: virtual double getValue(double x, double y); double getValue(double x, double y, double z); - doubleArray getRegion(doubleArray buffer, int x, int y, int z, int xSize, + std::vector getRegion(std::vector& buffer, int x, int y, int z, int xSize, int ySize, int zSize, double xScale, double yScale, double zScale); - doubleArray getRegion(doubleArray sr, int x, int z, int xSize, int zSize, + std::vector getRegion(std::vector& sr, int x, int z, int xSize, int zSize, double xScale, double zScale, double pow); }; diff --git a/minecraft/Minecraft.World/net/minecraft/world/level/levelgen/synth/PerlinSimplexNoise.cpp b/minecraft/Minecraft.World/net/minecraft/world/level/levelgen/synth/PerlinSimplexNoise.cpp index 73743c5c0..dc84a6a10 100644 --- a/minecraft/Minecraft.World/net/minecraft/world/level/levelgen/synth/PerlinSimplexNoise.cpp +++ b/minecraft/Minecraft.World/net/minecraft/world/level/levelgen/synth/PerlinSimplexNoise.cpp @@ -52,7 +52,7 @@ double PerlinSimplexNoise::getValue(double x, double y, double z) { return value; } -doubleArray PerlinSimplexNoise::getRegion(doubleArray buffer, double x, +std::vector PerlinSimplexNoise::getRegion(std::vector& buffer, double x, double y, int xSize, int ySize, double xScale, double yScale, double sizeScale) { @@ -60,18 +60,17 @@ doubleArray PerlinSimplexNoise::getRegion(doubleArray buffer, double x, 0.5); } -doubleArray PerlinSimplexNoise::getRegion(doubleArray buffer, double x, +std::vector PerlinSimplexNoise::getRegion(std::vector& buffer, double x, double y, int xSize, int ySize, double xScale, double yScale, double sizeScale, double powScale) { xScale /= 1.5; yScale /= 1.5; - if (buffer.data == nullptr || (int)buffer.length < xSize * ySize) { - if (buffer.data) delete[] buffer.data; - buffer = doubleArray(xSize * ySize); + if (buffer.empty() || (int)buffer.size() < xSize * ySize) { + buffer = std::vector(xSize * ySize); } else - for (unsigned int i = 0; i < buffer.length; i++) buffer[i] = 0; + for (unsigned int i = 0; i < buffer.size(); i++) buffer[i] = 0; double pow = 1; double scale = 1; @@ -85,17 +84,17 @@ doubleArray PerlinSimplexNoise::getRegion(doubleArray buffer, double x, return buffer; } -doubleArray PerlinSimplexNoise::getRegion(doubleArray buffer, double x, +std::vector PerlinSimplexNoise::getRegion(std::vector& buffer, double x, double y, double z, int xSize, int ySize, int zSize, double xScale, double yScale, double zScale) { xScale /= 1.5; yScale /= 1.5; - if (buffer.data == nullptr) - buffer = doubleArray(xSize * ySize * zSize); + if (buffer.empty()) + buffer = std::vector(xSize * ySize * zSize); else - for (unsigned int i = 0; i < buffer.length; i++) buffer[i] = 0; + for (unsigned int i = 0; i < buffer.size(); i++) buffer[i] = 0; double pow = 1; diff --git a/minecraft/Minecraft.World/net/minecraft/world/level/levelgen/synth/PerlinSimplexNoise.h b/minecraft/Minecraft.World/net/minecraft/world/level/levelgen/synth/PerlinSimplexNoise.h index 7331299c9..539c67640 100644 --- a/minecraft/Minecraft.World/net/minecraft/world/level/levelgen/synth/PerlinSimplexNoise.h +++ b/minecraft/Minecraft.World/net/minecraft/world/level/levelgen/synth/PerlinSimplexNoise.h @@ -16,13 +16,13 @@ public: virtual double getValue(double x, double y); double getValue(double x, double y, double z); - doubleArray getRegion(doubleArray buffer, double x, double y, int xSize, + std::vector getRegion(std::vector& buffer, double x, double y, int xSize, int ySize, double xScale, double yScale, double sizeScale); - doubleArray getRegion(doubleArray buffer, double x, double y, int xSize, + std::vector getRegion(std::vector& buffer, double x, double y, int xSize, int ySize, double xScale, double yScale, double sizeScale, double powScale); - doubleArray getRegion(doubleArray buffer, double x, double y, double z, + std::vector getRegion(std::vector& buffer, double x, double y, double z, int xSize, int ySize, int zSize, double xScale, double yScale, double zScale); }; \ No newline at end of file diff --git a/minecraft/Minecraft.World/net/minecraft/world/level/levelgen/synth/SimplexNoise.cpp b/minecraft/Minecraft.World/net/minecraft/world/level/levelgen/synth/SimplexNoise.cpp index 2911b0c07..b4b9317ba 100644 --- a/minecraft/Minecraft.World/net/minecraft/world/level/levelgen/synth/SimplexNoise.cpp +++ b/minecraft/Minecraft.World/net/minecraft/world/level/levelgen/synth/SimplexNoise.cpp @@ -240,7 +240,7 @@ double SimplexNoise::getValue(double xin, double yin, double zin) { return 32.0 * (n0 + n1 + n2 + n3); } -void SimplexNoise::add(doubleArray buffer, double _x, double _y, int xSize, +void SimplexNoise::add(std::vector& buffer, double _x, double _y, int xSize, int ySize, double xs, double ys, double pow) { int pp = 0; for (int xx = 0; xx < xSize; xx++) { @@ -316,7 +316,7 @@ void SimplexNoise::add(doubleArray buffer, double _x, double _y, int xSize, } } } -void SimplexNoise::add(doubleArray buffer, double _x, double _y, double _z, +void SimplexNoise::add(std::vector& buffer, double _x, double _y, double _z, int xSize, int ySize, int zSize, double xs, double ys, double zs, double pow) { int pp = 0; diff --git a/minecraft/Minecraft.World/net/minecraft/world/level/levelgen/synth/SimplexNoise.h b/minecraft/Minecraft.World/net/minecraft/world/level/levelgen/synth/SimplexNoise.h index 8566a9521..6f177174b 100644 --- a/minecraft/Minecraft.World/net/minecraft/world/level/levelgen/synth/SimplexNoise.h +++ b/minecraft/Minecraft.World/net/minecraft/world/level/levelgen/synth/SimplexNoise.h @@ -33,8 +33,8 @@ public: // 3D simplex noise double getValue(double xin, double yin, double zin); - void add(doubleArray buffer, double _x, double _y, int xSize, int ySize, + void add(std::vector& buffer, double _x, double _y, int xSize, int ySize, double xs, double ys, double pow); - void add(doubleArray buffer, double _x, double _y, double _z, int xSize, + void add(std::vector& buffer, double _x, double _y, double _z, int xSize, int ySize, int zSize, double xs, double ys, double zs, double pow); }; diff --git a/minecraft/Minecraft.World/net/minecraft/world/level/levelgen/synth/Synth.cpp b/minecraft/Minecraft.World/net/minecraft/world/level/levelgen/synth/Synth.cpp index 0eacc8099..4d1e9867b 100644 --- a/minecraft/Minecraft.World/net/minecraft/world/level/levelgen/synth/Synth.cpp +++ b/minecraft/Minecraft.World/net/minecraft/world/level/levelgen/synth/Synth.cpp @@ -1,8 +1,8 @@ #include "../../../../../../Header Files/stdafx.h" #include "Synth.h" -doubleArray Synth::create(int width, int height) { - doubleArray result = doubleArray(width * height); +std::vector Synth::create(int width, int height) { + std::vector result = std::vector(width * height); for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) { result[x + y * width] = getValue(x, y); diff --git a/minecraft/Minecraft.World/net/minecraft/world/level/levelgen/synth/Synth.h b/minecraft/Minecraft.World/net/minecraft/world/level/levelgen/synth/Synth.h index c2685b040..1e4bc85ad 100644 --- a/minecraft/Minecraft.World/net/minecraft/world/level/levelgen/synth/Synth.h +++ b/minecraft/Minecraft.World/net/minecraft/world/level/levelgen/synth/Synth.h @@ -4,5 +4,5 @@ public: virtual double getValue(double x, double y) = 0; virtual ~Synth() {} - doubleArray create(int width, int height); + std::vector create(int width, int height); }; diff --git a/minecraft/Minecraft.World/net/minecraft/world/level/newbiome/layer/AddIslandLayer.cpp b/minecraft/Minecraft.World/net/minecraft/world/level/newbiome/layer/AddIslandLayer.cpp index 5cd12e760..441cf2057 100644 --- a/minecraft/Minecraft.World/net/minecraft/world/level/newbiome/layer/AddIslandLayer.cpp +++ b/minecraft/Minecraft.World/net/minecraft/world/level/newbiome/layer/AddIslandLayer.cpp @@ -7,14 +7,14 @@ AddIslandLayer::AddIslandLayer(int64_t seedMixup, std::shared_ptr parent) this->parent = parent; } -intArray AddIslandLayer::getArea(int xo, int yo, int w, int h) { +std::vector AddIslandLayer::getArea(int xo, int yo, int w, int h) { int px = xo - 1; int py = yo - 1; int pw = w + 2; int ph = h + 2; - intArray p = parent->getArea(px, py, pw, ph); + std::vector p = parent->getArea(px, py, pw, ph); - intArray result{static_cast(w * h)}; + std::vector result(w * h); for (int y = 0; y < h; y++) { for (int x = 0; x < w; x++) { int n1 = p[(x + 0) + (y + 0) * pw]; diff --git a/minecraft/Minecraft.World/net/minecraft/world/level/newbiome/layer/AddIslandLayer.h b/minecraft/Minecraft.World/net/minecraft/world/level/newbiome/layer/AddIslandLayer.h index 58baf28cf..16dd5f833 100644 --- a/minecraft/Minecraft.World/net/minecraft/world/level/newbiome/layer/AddIslandLayer.h +++ b/minecraft/Minecraft.World/net/minecraft/world/level/newbiome/layer/AddIslandLayer.h @@ -6,5 +6,5 @@ class AddIslandLayer : public Layer { public: AddIslandLayer(int64_t seedMixup, std::shared_ptr parent); - intArray getArea(int xo, int yo, int w, int h); + std::vector getArea(int xo, int yo, int w, int h); }; \ No newline at end of file diff --git a/minecraft/Minecraft.World/net/minecraft/world/level/newbiome/layer/AddMushroomIslandLayer.cpp b/minecraft/Minecraft.World/net/minecraft/world/level/newbiome/layer/AddMushroomIslandLayer.cpp index a7733b917..6840644b9 100644 --- a/minecraft/Minecraft.World/net/minecraft/world/level/newbiome/layer/AddMushroomIslandLayer.cpp +++ b/minecraft/Minecraft.World/net/minecraft/world/level/newbiome/layer/AddMushroomIslandLayer.cpp @@ -8,14 +8,14 @@ AddMushroomIslandLayer::AddMushroomIslandLayer(int64_t seedMixup, this->parent = parent; } -intArray AddMushroomIslandLayer::getArea(int xo, int yo, int w, int h) { +std::vector AddMushroomIslandLayer::getArea(int xo, int yo, int w, int h) { int px = xo - 1; int py = yo - 1; int pw = w + 2; int ph = h + 2; - intArray p = parent->getArea(px, py, pw, ph); + std::vector p = parent->getArea(px, py, pw, ph); - intArray result{static_cast(w * h)}; + std::vector result(w * h); for (int y = 0; y < h; y++) { for (int x = 0; x < w; x++) { int n1 = p[(x + 0) + (y + 0) * pw]; diff --git a/minecraft/Minecraft.World/net/minecraft/world/level/newbiome/layer/AddMushroomIslandLayer.h b/minecraft/Minecraft.World/net/minecraft/world/level/newbiome/layer/AddMushroomIslandLayer.h index 4de2dd53c..902d32211 100644 --- a/minecraft/Minecraft.World/net/minecraft/world/level/newbiome/layer/AddMushroomIslandLayer.h +++ b/minecraft/Minecraft.World/net/minecraft/world/level/newbiome/layer/AddMushroomIslandLayer.h @@ -4,5 +4,5 @@ class AddMushroomIslandLayer : public Layer { public: AddMushroomIslandLayer(int64_t seedMixup, std::shared_ptr parent); - virtual intArray getArea(int xo, int yo, int w, int h); + virtual std::vector getArea(int xo, int yo, int w, int h); }; \ No newline at end of file diff --git a/minecraft/Minecraft.World/net/minecraft/world/level/newbiome/layer/AddSnowLayer.cpp b/minecraft/Minecraft.World/net/minecraft/world/level/newbiome/layer/AddSnowLayer.cpp index 7726a00e7..0927dbf19 100644 --- a/minecraft/Minecraft.World/net/minecraft/world/level/newbiome/layer/AddSnowLayer.cpp +++ b/minecraft/Minecraft.World/net/minecraft/world/level/newbiome/layer/AddSnowLayer.cpp @@ -7,14 +7,14 @@ AddSnowLayer::AddSnowLayer(int64_t seedMixup, std::shared_ptr parent) this->parent = parent; } -intArray AddSnowLayer::getArea(int xo, int yo, int w, int h) { +std::vector AddSnowLayer::getArea(int xo, int yo, int w, int h) { int px = xo - 1; int py = yo - 1; int pw = w + 2; int ph = h + 2; - intArray p = parent->getArea(px, py, pw, ph); + std::vector p = parent->getArea(px, py, pw, ph); - intArray result{static_cast(w * h)}; + std::vector result(w * h); for (int y = 0; y < h; y++) { for (int x = 0; x < w; x++) { int c = p[(x + 1) + (y + 1) * pw]; diff --git a/minecraft/Minecraft.World/net/minecraft/world/level/newbiome/layer/AddSnowLayer.h b/minecraft/Minecraft.World/net/minecraft/world/level/newbiome/layer/AddSnowLayer.h index b12c514ee..4f2747e78 100644 --- a/minecraft/Minecraft.World/net/minecraft/world/level/newbiome/layer/AddSnowLayer.h +++ b/minecraft/Minecraft.World/net/minecraft/world/level/newbiome/layer/AddSnowLayer.h @@ -4,5 +4,5 @@ class AddSnowLayer : public Layer { public: AddSnowLayer(int64_t seedMixup, std::shared_ptr parent); - virtual intArray getArea(int xo, int yo, int w, int h); + virtual std::vector getArea(int xo, int yo, int w, int h); }; \ No newline at end of file diff --git a/minecraft/Minecraft.World/net/minecraft/world/level/newbiome/layer/BiomeInitLayer.cpp b/minecraft/Minecraft.World/net/minecraft/world/level/newbiome/layer/BiomeInitLayer.cpp index b9cc9be6e..8afda17b9 100644 --- a/minecraft/Minecraft.World/net/minecraft/world/level/newbiome/layer/BiomeInitLayer.cpp +++ b/minecraft/Minecraft.World/net/minecraft/world/level/newbiome/layer/BiomeInitLayer.cpp @@ -4,13 +4,15 @@ #include "../../net.minecraft.world.level.h" #include "BiomeInitLayer.h" +BiomeInitLayer::~BiomeInitLayer() {} + BiomeInitLayer::BiomeInitLayer(int64_t seed, std::shared_ptr parent, LevelType* levelType) : Layer(seed) { this->parent = parent; if (levelType == LevelType::lvl_normal_1_1) { - startBiomes = BiomeArray(6); + startBiomes = std::vector(6); startBiomes[0] = Biome::desert; startBiomes[1] = Biome::forest; startBiomes[2] = Biome::extremeHills; @@ -18,7 +20,7 @@ BiomeInitLayer::BiomeInitLayer(int64_t seed, std::shared_ptr parent, startBiomes[4] = Biome::plains; startBiomes[5] = Biome::taiga; } else { - startBiomes = BiomeArray(7); + startBiomes = std::vector(7); startBiomes[0] = Biome::desert; startBiomes[1] = Biome::forest; startBiomes[2] = Biome::extremeHills; @@ -29,12 +31,11 @@ BiomeInitLayer::BiomeInitLayer(int64_t seed, std::shared_ptr parent, } } -BiomeInitLayer::~BiomeInitLayer() { delete[] startBiomes.data; } -intArray BiomeInitLayer::getArea(int xo, int yo, int w, int h) { - intArray b = parent->getArea(xo, yo, w, h); +std::vector BiomeInitLayer::getArea(int xo, int yo, int w, int h) { + std::vector b = parent->getArea(xo, yo, w, h); - intArray result{static_cast(w * h)}; + std::vector result(w * h); for (int y = 0; y < h; y++) { for (int x = 0; x < w; x++) { initRandom(x + xo, y + yo); @@ -45,9 +46,9 @@ intArray BiomeInitLayer::getArea(int xo, int yo, int w, int h) { result[x + y * w] = old; } else if (old == 1) { result[x + y * w] = - startBiomes[nextRandom(startBiomes.length)]->id; + startBiomes[nextRandom(startBiomes.size())]->id; } else { - int isTaiga = startBiomes[nextRandom(startBiomes.length)]->id; + int isTaiga = startBiomes[nextRandom(startBiomes.size())]->id; if (isTaiga == Biome::taiga->id) { result[x + y * w] = isTaiga; } else { diff --git a/minecraft/Minecraft.World/net/minecraft/world/level/newbiome/layer/BiomeInitLayer.h b/minecraft/Minecraft.World/net/minecraft/world/level/newbiome/layer/BiomeInitLayer.h index 2fef040b9..2a335aedf 100644 --- a/minecraft/Minecraft.World/net/minecraft/world/level/newbiome/layer/BiomeInitLayer.h +++ b/minecraft/Minecraft.World/net/minecraft/world/level/newbiome/layer/BiomeInitLayer.h @@ -6,11 +6,11 @@ class LevelType; class BiomeInitLayer : public Layer { private: - BiomeArray startBiomes; + std::vector startBiomes; public: BiomeInitLayer(int64_t seed, std::shared_ptr parent, LevelType* levelType); virtual ~BiomeInitLayer(); - intArray getArea(int xo, int yo, int w, int h); + std::vector getArea(int xo, int yo, int w, int h); }; \ No newline at end of file diff --git a/minecraft/Minecraft.World/net/minecraft/world/level/newbiome/layer/BiomeOverrideLayer.cpp b/minecraft/Minecraft.World/net/minecraft/world/level/newbiome/layer/BiomeOverrideLayer.cpp index 413f2e701..d4de95d12 100644 --- a/minecraft/Minecraft.World/net/minecraft/world/level/newbiome/layer/BiomeOverrideLayer.cpp +++ b/minecraft/Minecraft.World/net/minecraft/world/level/newbiome/layer/BiomeOverrideLayer.cpp @@ -5,7 +5,7 @@ #include "BiomeOverrideLayer.h" BiomeOverrideLayer::BiomeOverrideLayer(int seedMixup) : Layer(seedMixup) { - m_biomeOverride = byteArray(width * height); + m_biomeOverride = std::vector(width * height); #if defined(_UNICODE) std::wstring path = L"GAME:\\GameRules\\biomemap.bin"; @@ -25,14 +25,14 @@ BiomeOverrideLayer::BiomeOverrideLayer(int seedMixup) : Layer(seedMixup) { // assert(false); app.DebugPrintf("Biome override not found, using plains as default\n"); - memset(m_biomeOverride.data, Biome::plains->id, m_biomeOverride.length); + memset(m_biomeOverride.data(), Biome::plains->id, m_biomeOverride.size()); } else { uint32_t bytesRead, dwFileSize = GetFileSize(file, nullptr); - if (dwFileSize > m_biomeOverride.length) { + if (dwFileSize > m_biomeOverride.size()) { app.DebugPrintf("Biomemap binary is too large!!\n"); __debugbreak(); } - bool bSuccess = ReadFile(file, m_biomeOverride.data, dwFileSize, + bool bSuccess = ReadFile(file, m_biomeOverride.data(), dwFileSize, &bytesRead, nullptr); if (bSuccess == false) { @@ -43,8 +43,8 @@ BiomeOverrideLayer::BiomeOverrideLayer(int seedMixup) : Layer(seedMixup) { } } -intArray BiomeOverrideLayer::getArea(int xo, int yo, int w, int h) { - intArray result{static_cast(w * h)}; +std::vector BiomeOverrideLayer::getArea(int xo, int yo, int w, int h) { + std::vector result(w * h); int xOrigin = xo + width / 2; int yOrigin = yo + height / 2; diff --git a/minecraft/Minecraft.World/net/minecraft/world/level/newbiome/layer/BiomeOverrideLayer.h b/minecraft/Minecraft.World/net/minecraft/world/level/newbiome/layer/BiomeOverrideLayer.h index 373d0ec59..8db0586e4 100644 --- a/minecraft/Minecraft.World/net/minecraft/world/level/newbiome/layer/BiomeOverrideLayer.h +++ b/minecraft/Minecraft.World/net/minecraft/world/level/newbiome/layer/BiomeOverrideLayer.h @@ -9,9 +9,9 @@ private: static const unsigned int width = 216; static const unsigned int height = 216; - byteArray m_biomeOverride; + std::vector m_biomeOverride; public: BiomeOverrideLayer(int seedMixup); - intArray getArea(int xo, int yo, int w, int h); + std::vector getArea(int xo, int yo, int w, int h); }; \ No newline at end of file diff --git a/minecraft/Minecraft.World/net/minecraft/world/level/newbiome/layer/DownfallLayer.cpp b/minecraft/Minecraft.World/net/minecraft/world/level/newbiome/layer/DownfallLayer.cpp index 973db7a67..6b6632a04 100644 --- a/minecraft/Minecraft.World/net/minecraft/world/level/newbiome/layer/DownfallLayer.cpp +++ b/minecraft/Minecraft.World/net/minecraft/world/level/newbiome/layer/DownfallLayer.cpp @@ -6,10 +6,10 @@ DownfallLayer::DownfallLayer(std::shared_ptr parent) : Layer(0) { this->parent = parent; } -intArray DownfallLayer::getArea(int xo, int yo, int w, int h) { - intArray b = parent->getArea(xo, yo, w, h); +std::vector DownfallLayer::getArea(int xo, int yo, int w, int h) { + std::vector b = parent->getArea(xo, yo, w, h); - intArray result{static_cast(w * h)}; + std::vector result(w * h); for (int i = 0; i < w * h; i++) { result[i] = Biome::biomes[b[i]]->getDownfallInt(); } diff --git a/minecraft/Minecraft.World/net/minecraft/world/level/newbiome/layer/DownfallLayer.h b/minecraft/Minecraft.World/net/minecraft/world/level/newbiome/layer/DownfallLayer.h index 17aa1f2a8..9eb55aa98 100644 --- a/minecraft/Minecraft.World/net/minecraft/world/level/newbiome/layer/DownfallLayer.h +++ b/minecraft/Minecraft.World/net/minecraft/world/level/newbiome/layer/DownfallLayer.h @@ -5,5 +5,5 @@ class DownfallLayer : public Layer { public: DownfallLayer(std::shared_ptr parent); - intArray getArea(int xo, int yo, int w, int h); + std::vector getArea(int xo, int yo, int w, int h); }; \ No newline at end of file diff --git a/minecraft/Minecraft.World/net/minecraft/world/level/newbiome/layer/DownfallMixerLayer.cpp b/minecraft/Minecraft.World/net/minecraft/world/level/newbiome/layer/DownfallMixerLayer.cpp index 8a3f94ce2..51c9875be 100644 --- a/minecraft/Minecraft.World/net/minecraft/world/level/newbiome/layer/DownfallMixerLayer.cpp +++ b/minecraft/Minecraft.World/net/minecraft/world/level/newbiome/layer/DownfallMixerLayer.cpp @@ -10,11 +10,11 @@ DownfallMixerLayer::DownfallMixerLayer(std::shared_ptr downfall, this->layer = layer; } -intArray DownfallMixerLayer::getArea(int xo, int yo, int w, int h) { - intArray b = parent->getArea(xo, yo, w, h); - intArray d = downfall->getArea(xo, yo, w, h); +std::vector DownfallMixerLayer::getArea(int xo, int yo, int w, int h) { + std::vector b = parent->getArea(xo, yo, w, h); + std::vector d = downfall->getArea(xo, yo, w, h); - intArray result{static_cast(w * h)}; + std::vector result(w * h); for (int i = 0; i < w * h; i++) { result[i] = d[i] + (Biome::biomes[b[i]]->getDownfallInt() - d[i]) / (layer + 1); diff --git a/minecraft/Minecraft.World/net/minecraft/world/level/newbiome/layer/DownfallMixerLayer.h b/minecraft/Minecraft.World/net/minecraft/world/level/newbiome/layer/DownfallMixerLayer.h index 04a7db0c4..e1a5ec797 100644 --- a/minecraft/Minecraft.World/net/minecraft/world/level/newbiome/layer/DownfallMixerLayer.h +++ b/minecraft/Minecraft.World/net/minecraft/world/level/newbiome/layer/DownfallMixerLayer.h @@ -10,5 +10,5 @@ private: public: DownfallMixerLayer(std::shared_ptr downfall, std::shared_ptr parent, int layer); - intArray getArea(int xo, int yo, int w, int h); + std::vector getArea(int xo, int yo, int w, int h); }; \ No newline at end of file diff --git a/minecraft/Minecraft.World/net/minecraft/world/level/newbiome/layer/FlatLayer.cpp b/minecraft/Minecraft.World/net/minecraft/world/level/newbiome/layer/FlatLayer.cpp index c87f07287..a96c73222 100644 --- a/minecraft/Minecraft.World/net/minecraft/world/level/newbiome/layer/FlatLayer.cpp +++ b/minecraft/Minecraft.World/net/minecraft/world/level/newbiome/layer/FlatLayer.cpp @@ -3,8 +3,8 @@ FlatLayer::FlatLayer(int val) : Layer(0) { this->val = val; } -intArray FlatLayer::getArea(int xo, int yo, int w, int h) { - intArray result{static_cast(w * h)}; +std::vector FlatLayer::getArea(int xo, int yo, int w, int h) { + std::vector result(w * h); for (int y = 0; y < h; y++) { for (int x = 0; x < w; x++) { result[x + y * w] = val; diff --git a/minecraft/Minecraft.World/net/minecraft/world/level/newbiome/layer/FlatLayer.h b/minecraft/Minecraft.World/net/minecraft/world/level/newbiome/layer/FlatLayer.h index 1941052d0..d5b77ac18 100644 --- a/minecraft/Minecraft.World/net/minecraft/world/level/newbiome/layer/FlatLayer.h +++ b/minecraft/Minecraft.World/net/minecraft/world/level/newbiome/layer/FlatLayer.h @@ -8,5 +8,5 @@ private: public: FlatLayer(int val); - intArray getArea(int xo, int yo, int w, int h); + std::vector getArea(int xo, int yo, int w, int h); }; \ No newline at end of file diff --git a/minecraft/Minecraft.World/net/minecraft/world/level/newbiome/layer/FuzzyZoomLayer.cpp b/minecraft/Minecraft.World/net/minecraft/world/level/newbiome/layer/FuzzyZoomLayer.cpp index 95bc9edbc..d474108d3 100644 --- a/minecraft/Minecraft.World/net/minecraft/world/level/newbiome/layer/FuzzyZoomLayer.cpp +++ b/minecraft/Minecraft.World/net/minecraft/world/level/newbiome/layer/FuzzyZoomLayer.cpp @@ -7,15 +7,15 @@ FuzzyZoomLayer::FuzzyZoomLayer(int64_t seedMixup, std::shared_ptr parent) this->parent = parent; } -intArray FuzzyZoomLayer::getArea(int xo, int yo, int w, int h) { +std::vector FuzzyZoomLayer::getArea(int xo, int yo, int w, int h) { int px = xo >> 1; int py = yo >> 1; int pw = (w >> 1) + 3; int ph = (h >> 1) + 3; - intArray p = parent->getArea(px, py, pw, ph); + std::vector p = parent->getArea(px, py, pw, ph); // 4jcraft added casts to unsigned to prevent shift of neg value - intArray tmp{static_cast(pw * ph * 4)}; + std::vector tmp(pw * ph * 4); int ww = ((unsigned int)pw << 1); for (int y = 0; y < ph - 1; y++) { int ry = (unsigned int)y << 1; @@ -37,11 +37,11 @@ intArray FuzzyZoomLayer::getArea(int xo, int yo, int w, int h) { dl = dr; } } - intArray result{static_cast(w * h)}; + std::vector result(w * h); for (int y = 0; y < h; y++) { - System::arraycopy(tmp, - (y + (yo & 1)) * ((unsigned int)pw << 1) + (xo & 1), - &result, y * w, w); + std::copy(tmp.begin() + (y + (yo & 1)) * ((unsigned int)pw << 1) + (xo & 1), + tmp.begin() + (y + (yo & 1)) * ((unsigned int)pw << 1) + (xo & 1) + w, + result.begin() + y * w); } return result; diff --git a/minecraft/Minecraft.World/net/minecraft/world/level/newbiome/layer/FuzzyZoomLayer.h b/minecraft/Minecraft.World/net/minecraft/world/level/newbiome/layer/FuzzyZoomLayer.h index 2e6ed3824..0636cae35 100644 --- a/minecraft/Minecraft.World/net/minecraft/world/level/newbiome/layer/FuzzyZoomLayer.h +++ b/minecraft/Minecraft.World/net/minecraft/world/level/newbiome/layer/FuzzyZoomLayer.h @@ -5,7 +5,7 @@ class FuzzyZoomLayer : public Layer { public: FuzzyZoomLayer(int64_t seedMixup, std::shared_ptr parent); - intArray getArea(int xo, int yo, int w, int h); + std::vector getArea(int xo, int yo, int w, int h); protected: int random(int a, int b); diff --git a/minecraft/Minecraft.World/net/minecraft/world/level/newbiome/layer/GrowMushroomIslandLayer.cpp b/minecraft/Minecraft.World/net/minecraft/world/level/newbiome/layer/GrowMushroomIslandLayer.cpp index 13d89575a..1f93dbb83 100644 --- a/minecraft/Minecraft.World/net/minecraft/world/level/newbiome/layer/GrowMushroomIslandLayer.cpp +++ b/minecraft/Minecraft.World/net/minecraft/world/level/newbiome/layer/GrowMushroomIslandLayer.cpp @@ -8,14 +8,14 @@ GrowMushroomIslandLayer::GrowMushroomIslandLayer(int64_t seedMixup, this->parent = parent; } -intArray GrowMushroomIslandLayer::getArea(int xo, int yo, int w, int h) { +std::vector GrowMushroomIslandLayer::getArea(int xo, int yo, int w, int h) { int px = xo - 1; int py = yo - 1; int pw = w + 2; int ph = h + 2; - intArray p = parent->getArea(px, py, pw, ph); + std::vector p = parent->getArea(px, py, pw, ph); - intArray result{static_cast(w * h)}; + std::vector result(w * h); for (int y = 0; y < h; y++) { for (int x = 0; x < w; x++) { int n1 = p[(x + 0) + (y + 0) * pw]; diff --git a/minecraft/Minecraft.World/net/minecraft/world/level/newbiome/layer/GrowMushroomIslandLayer.h b/minecraft/Minecraft.World/net/minecraft/world/level/newbiome/layer/GrowMushroomIslandLayer.h index 8fecb2177..95d9052af 100644 --- a/minecraft/Minecraft.World/net/minecraft/world/level/newbiome/layer/GrowMushroomIslandLayer.h +++ b/minecraft/Minecraft.World/net/minecraft/world/level/newbiome/layer/GrowMushroomIslandLayer.h @@ -4,5 +4,5 @@ class GrowMushroomIslandLayer : public Layer { public: GrowMushroomIslandLayer(int64_t seedMixup, std::shared_ptr parent); - virtual intArray getArea(int xo, int yo, int w, int h); + virtual std::vector getArea(int xo, int yo, int w, int h); }; \ No newline at end of file diff --git a/minecraft/Minecraft.World/net/minecraft/world/level/newbiome/layer/IslandLayer.cpp b/minecraft/Minecraft.World/net/minecraft/world/level/newbiome/layer/IslandLayer.cpp index 23c5b84b5..a5cb5788a 100644 --- a/minecraft/Minecraft.World/net/minecraft/world/level/newbiome/layer/IslandLayer.cpp +++ b/minecraft/Minecraft.World/net/minecraft/world/level/newbiome/layer/IslandLayer.cpp @@ -3,8 +3,8 @@ IslandLayer::IslandLayer(int64_t seedMixup) : Layer(seedMixup) {} -intArray IslandLayer::getArea(int xo, int yo, int w, int h) { - intArray result{static_cast(w * h)}; +std::vector IslandLayer::getArea(int xo, int yo, int w, int h) { + std::vector result(w * h); for (int y = 0; y < h; y++) { for (int x = 0; x < w; x++) { initRandom(xo + x, yo + y); diff --git a/minecraft/Minecraft.World/net/minecraft/world/level/newbiome/layer/IslandLayer.h b/minecraft/Minecraft.World/net/minecraft/world/level/newbiome/layer/IslandLayer.h index c878a43e6..689c66e65 100644 --- a/minecraft/Minecraft.World/net/minecraft/world/level/newbiome/layer/IslandLayer.h +++ b/minecraft/Minecraft.World/net/minecraft/world/level/newbiome/layer/IslandLayer.h @@ -6,5 +6,5 @@ class IslandLayer : public Layer { public: IslandLayer(int64_t seedMixup); - intArray getArea(int xo, int yo, int w, int h); + std::vector getArea(int xo, int yo, int w, int h); }; \ No newline at end of file diff --git a/minecraft/Minecraft.World/net/minecraft/world/level/newbiome/layer/Layer.cpp b/minecraft/Minecraft.World/net/minecraft/world/level/newbiome/layer/Layer.cpp index 46435f591..feb70e362 100644 --- a/minecraft/Minecraft.World/net/minecraft/world/level/newbiome/layer/Layer.cpp +++ b/minecraft/Minecraft.World/net/minecraft/world/level/newbiome/layer/Layer.cpp @@ -3,7 +3,7 @@ #include "../../net.minecraft.world.level.h" #include "BiomeOverrideLayer.h" -LayerArray Layer::getDefaultLayers(int64_t seed, LevelType* levelType) { +std::vector> Layer::getDefaultLayers(int64_t seed, LevelType* levelType) { // 4J - Some changes moved here from 1.2.3. Temperature & downfall layers // are no longer created & returned, and a debug layer is isn't. For // reference with regard to future merging, things NOT brought forward from @@ -107,7 +107,7 @@ LayerArray Layer::getDefaultLayers(int64_t seed, LevelType* levelType) { biomeLayer->init(seed); zoomedLayer->init(seed); - LayerArray result(3); + std::vector> result(3); result[0] = biomeLayer; result[1] = zoomedLayer; result[2] = debugLayer; diff --git a/minecraft/Minecraft.World/net/minecraft/world/level/newbiome/layer/Layer.h b/minecraft/Minecraft.World/net/minecraft/world/level/newbiome/layer/Layer.h index ade815820..1fee001ab 100644 --- a/minecraft/Minecraft.World/net/minecraft/world/level/newbiome/layer/Layer.h +++ b/minecraft/Minecraft.World/net/minecraft/world/level/newbiome/layer/Layer.h @@ -20,7 +20,7 @@ private: int64_t seedMixup; public: - static LayerArray getDefaultLayers(int64_t seed, LevelType* levelType); + static std::vector> getDefaultLayers(int64_t seed, LevelType* levelType); Layer(int64_t seedMixup); @@ -31,5 +31,5 @@ protected: int nextRandom(int max); public: - virtual intArray getArea(int xo, int yo, int w, int h) = 0; + virtual std::vector getArea(int xo, int yo, int w, int h) = 0; }; \ No newline at end of file diff --git a/minecraft/Minecraft.World/net/minecraft/world/level/newbiome/layer/RegionHillsLayer.cpp b/minecraft/Minecraft.World/net/minecraft/world/level/newbiome/layer/RegionHillsLayer.cpp index 199ddf1df..769aed71e 100644 --- a/minecraft/Minecraft.World/net/minecraft/world/level/newbiome/layer/RegionHillsLayer.cpp +++ b/minecraft/Minecraft.World/net/minecraft/world/level/newbiome/layer/RegionHillsLayer.cpp @@ -7,10 +7,10 @@ RegionHillsLayer::RegionHillsLayer(int64_t seed, std::shared_ptr parent) this->parent = parent; } -intArray RegionHillsLayer::getArea(int xo, int yo, int w, int h) { - intArray b = parent->getArea(xo - 1, yo - 1, w + 2, h + 2); +std::vector RegionHillsLayer::getArea(int xo, int yo, int w, int h) { + std::vector b = parent->getArea(xo - 1, yo - 1, w + 2, h + 2); - intArray result{static_cast(w * h)}; + std::vector result(w * h); for (int y = 0; y < h; y++) { for (int x = 0; x < w; x++) { initRandom(x + xo, y + yo); diff --git a/minecraft/Minecraft.World/net/minecraft/world/level/newbiome/layer/RegionHillsLayer.h b/minecraft/Minecraft.World/net/minecraft/world/level/newbiome/layer/RegionHillsLayer.h index 108c71824..58416459b 100644 --- a/minecraft/Minecraft.World/net/minecraft/world/level/newbiome/layer/RegionHillsLayer.h +++ b/minecraft/Minecraft.World/net/minecraft/world/level/newbiome/layer/RegionHillsLayer.h @@ -6,5 +6,5 @@ class RegionHillsLayer : public Layer { public: RegionHillsLayer(int64_t seed, std::shared_ptr parent); - intArray getArea(int xo, int yo, int w, int h); + std::vector getArea(int xo, int yo, int w, int h); }; \ No newline at end of file diff --git a/minecraft/Minecraft.World/net/minecraft/world/level/newbiome/layer/RiverInitLayer.cpp b/minecraft/Minecraft.World/net/minecraft/world/level/newbiome/layer/RiverInitLayer.cpp index d009b03d3..8d2139cdf 100644 --- a/minecraft/Minecraft.World/net/minecraft/world/level/newbiome/layer/RiverInitLayer.cpp +++ b/minecraft/Minecraft.World/net/minecraft/world/level/newbiome/layer/RiverInitLayer.cpp @@ -6,10 +6,10 @@ RiverInitLayer::RiverInitLayer(int64_t seed, std::shared_ptr parent) this->parent = parent; } -intArray RiverInitLayer::getArea(int xo, int yo, int w, int h) { - intArray b = parent->getArea(xo, yo, w, h); +std::vector RiverInitLayer::getArea(int xo, int yo, int w, int h) { + std::vector b = parent->getArea(xo, yo, w, h); - intArray result{static_cast(w * h)}; + std::vector result(w * h); for (int y = 0; y < h; y++) { for (int x = 0; x < w; x++) { initRandom(x + xo, y + yo); diff --git a/minecraft/Minecraft.World/net/minecraft/world/level/newbiome/layer/RiverInitLayer.h b/minecraft/Minecraft.World/net/minecraft/world/level/newbiome/layer/RiverInitLayer.h index 131202873..4c15a4ac3 100644 --- a/minecraft/Minecraft.World/net/minecraft/world/level/newbiome/layer/RiverInitLayer.h +++ b/minecraft/Minecraft.World/net/minecraft/world/level/newbiome/layer/RiverInitLayer.h @@ -6,5 +6,5 @@ class RiverInitLayer : public Layer { public: RiverInitLayer(int64_t seed, std::shared_ptr parent); - intArray getArea(int xo, int yo, int w, int h); + std::vector getArea(int xo, int yo, int w, int h); }; \ No newline at end of file diff --git a/minecraft/Minecraft.World/net/minecraft/world/level/newbiome/layer/RiverLayer.cpp b/minecraft/Minecraft.World/net/minecraft/world/level/newbiome/layer/RiverLayer.cpp index e690dae7a..2434a45e2 100644 --- a/minecraft/Minecraft.World/net/minecraft/world/level/newbiome/layer/RiverLayer.cpp +++ b/minecraft/Minecraft.World/net/minecraft/world/level/newbiome/layer/RiverLayer.cpp @@ -7,14 +7,14 @@ RiverLayer::RiverLayer(int64_t seedMixup, std::shared_ptr parent) this->parent = parent; } -intArray RiverLayer::getArea(int xo, int yo, int w, int h) { +std::vector RiverLayer::getArea(int xo, int yo, int w, int h) { int px = xo - 1; int py = yo - 1; int pw = w + 2; int ph = h + 2; - intArray p = parent->getArea(px, py, pw, ph); + std::vector p = parent->getArea(px, py, pw, ph); - intArray result{static_cast(w * h)}; + std::vector result(w * h); for (int y = 0; y < h; y++) { for (int x = 0; x < w; x++) { int l = p[(x + 0) + (y + 1) * pw]; diff --git a/minecraft/Minecraft.World/net/minecraft/world/level/newbiome/layer/RiverLayer.h b/minecraft/Minecraft.World/net/minecraft/world/level/newbiome/layer/RiverLayer.h index 8fc2c5fad..0fad7c474 100644 --- a/minecraft/Minecraft.World/net/minecraft/world/level/newbiome/layer/RiverLayer.h +++ b/minecraft/Minecraft.World/net/minecraft/world/level/newbiome/layer/RiverLayer.h @@ -5,5 +5,5 @@ class RiverLayer : public Layer { public: RiverLayer(int64_t seedMixup, std::shared_ptr parent); - intArray getArea(int xo, int yo, int w, int h); + std::vector getArea(int xo, int yo, int w, int h); }; \ No newline at end of file diff --git a/minecraft/Minecraft.World/net/minecraft/world/level/newbiome/layer/RiverMixerLayer.cpp b/minecraft/Minecraft.World/net/minecraft/world/level/newbiome/layer/RiverMixerLayer.cpp index 4b022dad6..1da83289b 100644 --- a/minecraft/Minecraft.World/net/minecraft/world/level/newbiome/layer/RiverMixerLayer.cpp +++ b/minecraft/Minecraft.World/net/minecraft/world/level/newbiome/layer/RiverMixerLayer.cpp @@ -15,11 +15,11 @@ void RiverMixerLayer::init(int64_t seed) { Layer::init(seed); } -intArray RiverMixerLayer::getArea(int xo, int yo, int w, int h) { - intArray b = biomes->getArea(xo, yo, w, h); - intArray r = rivers->getArea(xo, yo, w, h); +std::vector RiverMixerLayer::getArea(int xo, int yo, int w, int h) { + std::vector b = biomes->getArea(xo, yo, w, h); + std::vector r = rivers->getArea(xo, yo, w, h); - intArray result{static_cast(w * h)}; + std::vector result(w * h); for (int i = 0; i < w * h; i++) { if (b[i] == Biome::ocean->id) { result[i] = b[i]; diff --git a/minecraft/Minecraft.World/net/minecraft/world/level/newbiome/layer/RiverMixerLayer.h b/minecraft/Minecraft.World/net/minecraft/world/level/newbiome/layer/RiverMixerLayer.h index e8428ee6f..6152fd1e0 100644 --- a/minecraft/Minecraft.World/net/minecraft/world/level/newbiome/layer/RiverMixerLayer.h +++ b/minecraft/Minecraft.World/net/minecraft/world/level/newbiome/layer/RiverMixerLayer.h @@ -12,5 +12,5 @@ public: std::shared_ptr rivers); virtual void init(int64_t seed); - virtual intArray getArea(int xo, int yo, int w, int h); + virtual std::vector getArea(int xo, int yo, int w, int h); }; \ No newline at end of file diff --git a/minecraft/Minecraft.World/net/minecraft/world/level/newbiome/layer/ShoreLayer.cpp b/minecraft/Minecraft.World/net/minecraft/world/level/newbiome/layer/ShoreLayer.cpp index ca273653e..50438d20e 100644 --- a/minecraft/Minecraft.World/net/minecraft/world/level/newbiome/layer/ShoreLayer.cpp +++ b/minecraft/Minecraft.World/net/minecraft/world/level/newbiome/layer/ShoreLayer.cpp @@ -7,10 +7,10 @@ ShoreLayer::ShoreLayer(int64_t seed, std::shared_ptr parent) this->parent = parent; } -intArray ShoreLayer::getArea(int xo, int yo, int w, int h) { - intArray b = parent->getArea(xo - 1, yo - 1, w + 2, h + 2); +std::vector ShoreLayer::getArea(int xo, int yo, int w, int h) { + std::vector b = parent->getArea(xo - 1, yo - 1, w + 2, h + 2); - intArray result{static_cast(w * h)}; + std::vector result(w * h); for (int y = 0; y < h; y++) { for (int x = 0; x < w; x++) { initRandom(x + xo, y + yo); diff --git a/minecraft/Minecraft.World/net/minecraft/world/level/newbiome/layer/ShoreLayer.h b/minecraft/Minecraft.World/net/minecraft/world/level/newbiome/layer/ShoreLayer.h index 276269a46..1ca7c6159 100644 --- a/minecraft/Minecraft.World/net/minecraft/world/level/newbiome/layer/ShoreLayer.h +++ b/minecraft/Minecraft.World/net/minecraft/world/level/newbiome/layer/ShoreLayer.h @@ -4,5 +4,5 @@ class ShoreLayer : public Layer { public: ShoreLayer(int64_t seed, std::shared_ptr parent); - virtual intArray getArea(int xo, int yo, int w, int h); + virtual std::vector getArea(int xo, int yo, int w, int h); }; \ No newline at end of file diff --git a/minecraft/Minecraft.World/net/minecraft/world/level/newbiome/layer/SmoothLayer.cpp b/minecraft/Minecraft.World/net/minecraft/world/level/newbiome/layer/SmoothLayer.cpp index 976a92b27..0931c62a1 100644 --- a/minecraft/Minecraft.World/net/minecraft/world/level/newbiome/layer/SmoothLayer.cpp +++ b/minecraft/Minecraft.World/net/minecraft/world/level/newbiome/layer/SmoothLayer.cpp @@ -6,14 +6,14 @@ SmoothLayer::SmoothLayer(int64_t seedMixup, std::shared_ptr parent) this->parent = parent; } -intArray SmoothLayer::getArea(int xo, int yo, int w, int h) { +std::vector SmoothLayer::getArea(int xo, int yo, int w, int h) { int px = xo - 1; int py = yo - 1; int pw = w + 2; int ph = h + 2; - intArray p = parent->getArea(px, py, pw, ph); + std::vector p = parent->getArea(px, py, pw, ph); - intArray result{static_cast(w * h)}; + std::vector result(w * h); for (int y = 0; y < h; y++) { for (int x = 0; x < w; x++) { int l = p[(x + 0) + (y + 1) * pw]; diff --git a/minecraft/Minecraft.World/net/minecraft/world/level/newbiome/layer/SmoothLayer.h b/minecraft/Minecraft.World/net/minecraft/world/level/newbiome/layer/SmoothLayer.h index dcc353d4f..e74ab5fad 100644 --- a/minecraft/Minecraft.World/net/minecraft/world/level/newbiome/layer/SmoothLayer.h +++ b/minecraft/Minecraft.World/net/minecraft/world/level/newbiome/layer/SmoothLayer.h @@ -6,5 +6,5 @@ class SmoothLayer : public Layer { public: SmoothLayer(int64_t seedMixup, std::shared_ptr parent); - virtual intArray getArea(int xo, int yo, int w, int h); + virtual std::vector getArea(int xo, int yo, int w, int h); }; \ No newline at end of file diff --git a/minecraft/Minecraft.World/net/minecraft/world/level/newbiome/layer/SmoothZoomLayer.cpp b/minecraft/Minecraft.World/net/minecraft/world/level/newbiome/layer/SmoothZoomLayer.cpp index fbf590fa6..c8c719bff 100644 --- a/minecraft/Minecraft.World/net/minecraft/world/level/newbiome/layer/SmoothZoomLayer.cpp +++ b/minecraft/Minecraft.World/net/minecraft/world/level/newbiome/layer/SmoothZoomLayer.cpp @@ -8,14 +8,14 @@ SmoothZoomLayer::SmoothZoomLayer(int64_t seedMixup, this->parent = parent; } -intArray SmoothZoomLayer::getArea(int xo, int yo, int w, int h) { +std::vector SmoothZoomLayer::getArea(int xo, int yo, int w, int h) { int px = xo >> 1; int py = yo >> 1; int pw = (w >> 1) + 3; int ph = (h >> 1) + 3; - intArray p = parent->getArea(px, py, pw, ph); + std::vector p = parent->getArea(px, py, pw, ph); - intArray tmp{static_cast(pw * ph * 4)}; + std::vector tmp(pw * ph * 4); int ww = (pw << 1); for (int y = 0; y < ph - 1; y++) { int ry = y << 1; @@ -40,10 +40,11 @@ intArray SmoothZoomLayer::getArea(int xo, int yo, int w, int h) { dl = dr; } } - intArray result{static_cast(w * h)}; + std::vector result(w * h); for (int y = 0; y < h; y++) { - System::arraycopy(tmp, (y + (yo & 1)) * (pw << 1) + (xo & 1), &result, - y * w, w); + std::copy(tmp.begin() + (y + (yo & 1)) * (pw << 1) + (xo & 1), + tmp.begin() + (y + (yo & 1)) * (pw << 1) + (xo & 1) + w, + result.begin() + y * w); } return result; } diff --git a/minecraft/Minecraft.World/net/minecraft/world/level/newbiome/layer/SmoothZoomLayer.h b/minecraft/Minecraft.World/net/minecraft/world/level/newbiome/layer/SmoothZoomLayer.h index 82e130ba0..154010207 100644 --- a/minecraft/Minecraft.World/net/minecraft/world/level/newbiome/layer/SmoothZoomLayer.h +++ b/minecraft/Minecraft.World/net/minecraft/world/level/newbiome/layer/SmoothZoomLayer.h @@ -6,7 +6,7 @@ class SmoothZoomLayer : public Layer { public: SmoothZoomLayer(int64_t seedMixup, std::shared_ptr parent); - virtual intArray getArea(int xo, int yo, int w, int h); + virtual std::vector getArea(int xo, int yo, int w, int h); static std::shared_ptr zoom(int64_t seed, std::shared_ptr sup, int count); }; \ No newline at end of file diff --git a/minecraft/Minecraft.World/net/minecraft/world/level/newbiome/layer/SwampRiversLayer.cpp b/minecraft/Minecraft.World/net/minecraft/world/level/newbiome/layer/SwampRiversLayer.cpp index 34091ca46..c14d9393a 100644 --- a/minecraft/Minecraft.World/net/minecraft/world/level/newbiome/layer/SwampRiversLayer.cpp +++ b/minecraft/Minecraft.World/net/minecraft/world/level/newbiome/layer/SwampRiversLayer.cpp @@ -7,10 +7,10 @@ SwampRiversLayer::SwampRiversLayer(int64_t seed, std::shared_ptr parent) this->parent = parent; } -intArray SwampRiversLayer::getArea(int xo, int yo, int w, int h) { - intArray b = parent->getArea(xo - 1, yo - 1, w + 2, h + 2); +std::vector SwampRiversLayer::getArea(int xo, int yo, int w, int h) { + std::vector b = parent->getArea(xo - 1, yo - 1, w + 2, h + 2); - intArray result{static_cast(w * h)}; + std::vector result(w * h); for (int y = 0; y < h; y++) { for (int x = 0; x < w; x++) { initRandom(x + xo, y + yo); diff --git a/minecraft/Minecraft.World/net/minecraft/world/level/newbiome/layer/SwampRiversLayer.h b/minecraft/Minecraft.World/net/minecraft/world/level/newbiome/layer/SwampRiversLayer.h index e4fdcaa96..8dff449bf 100644 --- a/minecraft/Minecraft.World/net/minecraft/world/level/newbiome/layer/SwampRiversLayer.h +++ b/minecraft/Minecraft.World/net/minecraft/world/level/newbiome/layer/SwampRiversLayer.h @@ -6,5 +6,5 @@ class SwampRiversLayer : public Layer { public: SwampRiversLayer(int64_t seed, std::shared_ptr parent); - intArray getArea(int xo, int yo, int w, int h); + std::vector getArea(int xo, int yo, int w, int h); }; \ No newline at end of file diff --git a/minecraft/Minecraft.World/net/minecraft/world/level/newbiome/layer/TemperatureLayer.cpp b/minecraft/Minecraft.World/net/minecraft/world/level/newbiome/layer/TemperatureLayer.cpp index bb259eebe..20f95a1f8 100644 --- a/minecraft/Minecraft.World/net/minecraft/world/level/newbiome/layer/TemperatureLayer.cpp +++ b/minecraft/Minecraft.World/net/minecraft/world/level/newbiome/layer/TemperatureLayer.cpp @@ -6,10 +6,10 @@ TemperatureLayer::TemperatureLayer(std::shared_ptr parent) : Layer(0) { this->parent = parent; } -intArray TemperatureLayer::getArea(int xo, int yo, int w, int h) { - intArray b = parent->getArea(xo, yo, w, h); +std::vector TemperatureLayer::getArea(int xo, int yo, int w, int h) { + std::vector b = parent->getArea(xo, yo, w, h); - intArray result{static_cast(w * h)}; + std::vector result(w * h); for (int i = 0; i < w * h; i++) { result[i] = Biome::biomes[b[i]]->getTemperatureInt(); } diff --git a/minecraft/Minecraft.World/net/minecraft/world/level/newbiome/layer/TemperatureLayer.h b/minecraft/Minecraft.World/net/minecraft/world/level/newbiome/layer/TemperatureLayer.h index efe037167..f0d7cf45c 100644 --- a/minecraft/Minecraft.World/net/minecraft/world/level/newbiome/layer/TemperatureLayer.h +++ b/minecraft/Minecraft.World/net/minecraft/world/level/newbiome/layer/TemperatureLayer.h @@ -6,5 +6,5 @@ class TemperatureLayer : public Layer { public: TemperatureLayer(std::shared_ptr parent); - virtual intArray getArea(int xo, int yo, int w, int h); + virtual std::vector getArea(int xo, int yo, int w, int h); }; \ No newline at end of file diff --git a/minecraft/Minecraft.World/net/minecraft/world/level/newbiome/layer/TemperatureMixerLayer.cpp b/minecraft/Minecraft.World/net/minecraft/world/level/newbiome/layer/TemperatureMixerLayer.cpp index 793e1aa63..0c180ebe5 100644 --- a/minecraft/Minecraft.World/net/minecraft/world/level/newbiome/layer/TemperatureMixerLayer.cpp +++ b/minecraft/Minecraft.World/net/minecraft/world/level/newbiome/layer/TemperatureMixerLayer.cpp @@ -11,11 +11,11 @@ TemperatureMixerLayer::TemperatureMixerLayer(std::shared_ptr temp, this->layer = layer; } -intArray TemperatureMixerLayer::getArea(int xo, int yo, int w, int h) { - intArray b = parent->getArea(xo, yo, w, h); - intArray t = temp->getArea(xo, yo, w, h); +std::vector TemperatureMixerLayer::getArea(int xo, int yo, int w, int h) { + std::vector b = parent->getArea(xo, yo, w, h); + std::vector t = temp->getArea(xo, yo, w, h); - intArray result{static_cast(w * h)}; + std::vector result(w * h); for (int i = 0; i < w * h; i++) { result[i] = t[i] + (Biome::biomes[b[i]]->getTemperatureInt() - t[i]) / (layer * 2 + 1); diff --git a/minecraft/Minecraft.World/net/minecraft/world/level/newbiome/layer/TemperatureMixerLayer.h b/minecraft/Minecraft.World/net/minecraft/world/level/newbiome/layer/TemperatureMixerLayer.h index d1a4b4c5e..3eb67481e 100644 --- a/minecraft/Minecraft.World/net/minecraft/world/level/newbiome/layer/TemperatureMixerLayer.h +++ b/minecraft/Minecraft.World/net/minecraft/world/level/newbiome/layer/TemperatureMixerLayer.h @@ -11,5 +11,5 @@ public: TemperatureMixerLayer(std::shared_ptr temp, std::shared_ptr parent, int layer); - virtual intArray getArea(int xo, int yo, int w, int h); + virtual std::vector getArea(int xo, int yo, int w, int h); }; \ No newline at end of file diff --git a/minecraft/Minecraft.World/net/minecraft/world/level/newbiome/layer/VoronoiZoom.cpp b/minecraft/Minecraft.World/net/minecraft/world/level/newbiome/layer/VoronoiZoom.cpp index b554d3d59..f84be32c2 100644 --- a/minecraft/Minecraft.World/net/minecraft/world/level/newbiome/layer/VoronoiZoom.cpp +++ b/minecraft/Minecraft.World/net/minecraft/world/level/newbiome/layer/VoronoiZoom.cpp @@ -7,7 +7,7 @@ VoronoiZoom::VoronoiZoom(int64_t seedMixup, std::shared_ptr parent) this->parent = parent; } -intArray VoronoiZoom::getArea(int xo, int yo, int w, int h) { +std::vector VoronoiZoom::getArea(int xo, int yo, int w, int h) { xo -= 2; yo -= 2; int bits = 2; @@ -16,12 +16,12 @@ intArray VoronoiZoom::getArea(int xo, int yo, int w, int h) { int py = yo >> bits; int pw = (w >> bits) + 3; int ph = (h >> bits) + 3; - intArray p = parent->getArea(px, py, pw, ph); + std::vector p = parent->getArea(px, py, pw, ph); // 4jcraft added all those casts to unsigned int ww = (unsigned)pw << bits; int hh = (unsigned)ph << bits; - intArray tmp{static_cast(ww * hh)}; + std::vector tmp(ww * hh); for (int y = 0; y < ph - 1; y++) { int ul = p[(0 + 0) + (y + 0) * pw]; int dl = p[(0 + 0) + (y + 1) * pw]; @@ -71,12 +71,11 @@ intArray VoronoiZoom::getArea(int xo, int yo, int w, int h) { dl = dr; } } - intArray result{static_cast(w * h)}; + std::vector result(w * h); for (int y = 0; y < h; y++) { - System::arraycopy( - tmp, - (y + (yo & (ss - 1))) * ((unsigned)pw << bits) + (xo & (ss - 1)), - &result, y * w, w); + std::copy(tmp.begin() + (y + (yo & (ss - 1))) * ((unsigned)pw << bits) + (xo & (ss - 1)), + tmp.begin() + (y + (yo & (ss - 1))) * ((unsigned)pw << bits) + (xo & (ss - 1)) + w, + result.begin() + y * w); } return result; } diff --git a/minecraft/Minecraft.World/net/minecraft/world/level/newbiome/layer/VoronoiZoom.h b/minecraft/Minecraft.World/net/minecraft/world/level/newbiome/layer/VoronoiZoom.h index 9f94e2800..a7d6322cf 100644 --- a/minecraft/Minecraft.World/net/minecraft/world/level/newbiome/layer/VoronoiZoom.h +++ b/minecraft/Minecraft.World/net/minecraft/world/level/newbiome/layer/VoronoiZoom.h @@ -6,7 +6,7 @@ class VoronoiZoom : public Layer { public: VoronoiZoom(int64_t seedMixup, std::shared_ptr parent); - virtual intArray getArea(int xo, int yo, int w, int h); + virtual std::vector getArea(int xo, int yo, int w, int h); protected: int random(int a, int b); diff --git a/minecraft/Minecraft.World/net/minecraft/world/level/newbiome/layer/ZoomLayer.cpp b/minecraft/Minecraft.World/net/minecraft/world/level/newbiome/layer/ZoomLayer.cpp index 9efda1ece..9fe2d02e2 100644 --- a/minecraft/Minecraft.World/net/minecraft/world/level/newbiome/layer/ZoomLayer.cpp +++ b/minecraft/Minecraft.World/net/minecraft/world/level/newbiome/layer/ZoomLayer.cpp @@ -7,14 +7,14 @@ ZoomLayer::ZoomLayer(int64_t seedMixup, std::shared_ptr parent) this->parent = parent; } -intArray ZoomLayer::getArea(int xo, int yo, int w, int h) { +std::vector ZoomLayer::getArea(int xo, int yo, int w, int h) { int px = xo >> 1; int py = yo >> 1; int pw = (w >> 1) + 3; int ph = (h >> 1) + 3; - intArray p = parent->getArea(px, py, pw, ph); + std::vector p = parent->getArea(px, py, pw, ph); - intArray tmp{static_cast(pw * ph * 4)}; + std::vector tmp(pw * ph * 4); // 4jcraft added casts to unsigned int ww = ((unsigned int)pw << 1); for (int y = 0; y < ph - 1; y++) { @@ -37,11 +37,11 @@ intArray ZoomLayer::getArea(int xo, int yo, int w, int h) { dl = dr; } } - intArray result{static_cast(w * h)}; + std::vector result(w * h); for (int y = 0; y < h; y++) { - System::arraycopy(tmp, - (y + (yo & 1)) * (unsigned int)(pw << 1) + (xo & 1), - &result, y * w, w); + std::copy(tmp.begin() + (y + (yo & 1)) * (unsigned int)(pw << 1) + (xo & 1), + tmp.begin() + (y + (yo & 1)) * (unsigned int)(pw << 1) + (xo & 1) + w, + result.begin() + y * w); } return result; } diff --git a/minecraft/Minecraft.World/net/minecraft/world/level/newbiome/layer/ZoomLayer.h b/minecraft/Minecraft.World/net/minecraft/world/level/newbiome/layer/ZoomLayer.h index f7150d20e..3bf3518f1 100644 --- a/minecraft/Minecraft.World/net/minecraft/world/level/newbiome/layer/ZoomLayer.h +++ b/minecraft/Minecraft.World/net/minecraft/world/level/newbiome/layer/ZoomLayer.h @@ -6,7 +6,7 @@ class ZoomLayer : public Layer { public: ZoomLayer(int64_t seedMixup, std::shared_ptr parent); - virtual intArray getArea(int xo, int yo, int w, int h); + virtual std::vector getArea(int xo, int yo, int w, int h); protected: int random(int a, int b); diff --git a/minecraft/Minecraft.World/net/minecraft/world/level/pathfinder/BinaryHeap.cpp b/minecraft/Minecraft.World/net/minecraft/world/level/pathfinder/BinaryHeap.cpp index 0aff3db91..13ad2adab 100644 --- a/minecraft/Minecraft.World/net/minecraft/world/level/pathfinder/BinaryHeap.cpp +++ b/minecraft/Minecraft.World/net/minecraft/world/level/pathfinder/BinaryHeap.cpp @@ -7,25 +7,24 @@ // 4J Jev, add common ctor code. void BinaryHeap::_init() { - heap = NodeArray(1024); + heap = std::vector(1024); sizeVar = 0; } BinaryHeap::BinaryHeap() { _init(); } -BinaryHeap::~BinaryHeap() { delete[] heap.data; } +BinaryHeap::~BinaryHeap() {} Node* BinaryHeap::insert(Node* node) { /* if (node->heapIdx >=0) throw new IllegalStateException("OW KNOWS!"); 4J * Jev, removed try/catch */ // Expand if necessary. - if (sizeVar == heap.length) { - NodeArray newHeap = NodeArray(sizeVar << 1); + if (sizeVar == heap.size()) { + std::vector newHeap = std::vector(sizeVar << 1); - System::arraycopy(heap, 0, &newHeap, 0, sizeVar); + std::copy(heap.begin(), heap.begin() + sizeVar, newHeap.begin()); - delete[] heap.data; heap = newHeap; } diff --git a/minecraft/Minecraft.World/net/minecraft/world/level/pathfinder/BinaryHeap.h b/minecraft/Minecraft.World/net/minecraft/world/level/pathfinder/BinaryHeap.h index 91951c4af..726250b0e 100644 --- a/minecraft/Minecraft.World/net/minecraft/world/level/pathfinder/BinaryHeap.h +++ b/minecraft/Minecraft.World/net/minecraft/world/level/pathfinder/BinaryHeap.h @@ -6,7 +6,7 @@ class BinaryHeap { private: - NodeArray heap; + std::vector heap; int sizeVar; // 4J Jev, add common ctor code. diff --git a/minecraft/Minecraft.World/net/minecraft/world/level/pathfinder/Path.cpp b/minecraft/Minecraft.World/net/minecraft/world/level/pathfinder/Path.cpp index 224878579..6498e125f 100644 --- a/minecraft/Minecraft.World/net/minecraft/world/level/pathfinder/Path.cpp +++ b/minecraft/Minecraft.World/net/minecraft/world/level/pathfinder/Path.cpp @@ -4,26 +4,23 @@ #include "Path.h" Path::~Path() { - if (nodes.data) { - for (int i = 0; i < nodes.length; i++) delete nodes.data[i]; - delete[] nodes.data; - } + for (size_t i = 0; i < nodes.size(); i++) delete nodes[i]; } -Path::Path(NodeArray nodes) { +Path::Path(std::vector& nodes) { index = 0; - length = nodes.length; - // 4J - copying these nodes over from a NodeArray (which is an array of Node + length = nodes.size(); + // 4J - copying these nodes over from a std::vector (which is an array of Node // * references) to just a straight array of Nodes, so that this Path is no // longer dependent of Nodes allocated elsewhere and can handle its own // destruction Note: cameFrom pointer will be useless now but that isn't // used once this is just a path - this->nodes = NodeArray(length); + this->nodes = std::vector(length); for (int i = 0; i < length; i++) { - this->nodes.data[i] = new Node(); - memcpy(this->nodes.data[i], nodes[i], sizeof(Node)); + this->nodes[i] = new Node(); + memcpy(this->nodes[i], nodes[i], sizeof(Node)); } } @@ -63,8 +60,8 @@ Vec3 Path::currentPos() { bool Path::sameAs(Path* path) { if (path == nullptr) return false; - if (path->nodes.length != nodes.length) return false; - for (int i = 0; i < nodes.length; ++i) + if (path->nodes.size() != nodes.size()) return false; + for (int i = 0; i < nodes.size(); ++i) if (nodes[i]->x != path->nodes[i]->x || nodes[i]->y != path->nodes[i]->y || nodes[i]->z != path->nodes[i]->z) diff --git a/minecraft/Minecraft.World/net/minecraft/world/level/pathfinder/Path.h b/minecraft/Minecraft.World/net/minecraft/world/level/pathfinder/Path.h index ab0a013be..fc458f9e1 100644 --- a/minecraft/Minecraft.World/net/minecraft/world/level/pathfinder/Path.h +++ b/minecraft/Minecraft.World/net/minecraft/world/level/pathfinder/Path.h @@ -4,12 +4,12 @@ class Path { friend class PathFinder; private: - NodeArray nodes; + std::vector nodes; int index; int length; public: - Path(NodeArray nodes); + Path(std::vector& nodes); ~Path(); void next(); @@ -21,7 +21,7 @@ public: int getIndex(); void setIndex(int index); Vec3 getPos(std::shared_ptr e, int index); - NodeArray Getarray(); + std::vector Getarray(); Vec3 currentPos(std::shared_ptr e); Vec3 currentPos(); bool sameAs(Path* path); diff --git a/minecraft/Minecraft.World/net/minecraft/world/level/pathfinder/PathFinder.cpp b/minecraft/Minecraft.World/net/minecraft/world/level/pathfinder/PathFinder.cpp index ee5830d91..0c2a6220f 100644 --- a/minecraft/Minecraft.World/net/minecraft/world/level/pathfinder/PathFinder.cpp +++ b/minecraft/Minecraft.World/net/minecraft/world/level/pathfinder/PathFinder.cpp @@ -11,7 +11,7 @@ PathFinder::PathFinder(LevelSource* level, bool canPassDoors, bool canOpenDoors, bool avoidWater, bool canFloat) { - neighbors = new NodeArray(32); + neighbors = new std::vector(32); this->canPassDoors = canPassDoors; this->canOpenDoors = canOpenDoors; @@ -24,7 +24,6 @@ PathFinder::~PathFinder() { // All the nodes should be uniquely referenced in the nodes map, and // everything else should just be duplicate references to the same things, // so just need to destroy their containers - delete[] neighbors->data; delete neighbors; auto itEnd = nodes.end(); for (auto it = nodes.begin(); it != itEnd; it++) { @@ -101,7 +100,7 @@ Path* PathFinder::findPath(Entity* e, Node* from, Node* to, Node* size, int neighborCount = getNeighbors(e, x, size, to, maxDist); for (int i = 0; i < neighborCount; i++) { - Node* y = neighbors->data[i]; + Node* y = (*neighbors)[i]; float tentative_g_score = x->g + x->distanceToSqr(y); if (!y->inOpenSet() || tentative_g_score < y->g) { @@ -136,13 +135,13 @@ int PathFinder::getNeighbors(Entity* entity, Node* pos, Node* size, Node* s = getNode(entity, pos->x, pos->y, pos->z - 1, size, jumpSize); if (n != nullptr && !n->closed && n->distanceTo(target) < maxDist) - neighbors->data[p++] = n; + (*neighbors)[p++] = n; if (w != nullptr && !w->closed && w->distanceTo(target) < maxDist) - neighbors->data[p++] = w; + (*neighbors)[p++] = w; if (e != nullptr && !e->closed && e->distanceTo(target) < maxDist) - neighbors->data[p++] = e; + (*neighbors)[p++] = e; if (s != nullptr && !s->closed && s->distanceTo(target) < maxDist) - neighbors->data[p++] = s; + (*neighbors)[p++] = s; return p; } @@ -274,14 +273,13 @@ Path* PathFinder::reconstruct_path(Node* from, Node* to) { n = n->cameFrom; } - NodeArray nodes = NodeArray(count); + std::vector nodes = std::vector(count); n = to; - nodes.data[--count] = n; + nodes[--count] = n; while (n->cameFrom != nullptr) { n = n->cameFrom; - nodes.data[--count] = n; + nodes[--count] = n; } Path* ret = new Path(nodes); - delete[] nodes.data; return ret; } diff --git a/minecraft/Minecraft.World/net/minecraft/world/level/pathfinder/PathFinder.h b/minecraft/Minecraft.World/net/minecraft/world/level/pathfinder/PathFinder.h index 639f89369..337d99007 100644 --- a/minecraft/Minecraft.World/net/minecraft/world/level/pathfinder/PathFinder.h +++ b/minecraft/Minecraft.World/net/minecraft/world/level/pathfinder/PathFinder.h @@ -12,7 +12,7 @@ private: // 4J Jev, was a IntHashMap, thought this was close enough. std::unordered_map nodes; - NodeArray* neighbors; + std::vector* neighbors; bool canPassDoors; bool canOpenDoors; diff --git a/minecraft/Minecraft.World/net/minecraft/world/level/saveddata/MapItemSavedData.cpp b/minecraft/Minecraft.World/net/minecraft/world/level/saveddata/MapItemSavedData.cpp index fbc06b8d2..12dcac681 100644 --- a/minecraft/Minecraft.World/net/minecraft/world/level/saveddata/MapItemSavedData.cpp +++ b/minecraft/Minecraft.World/net/minecraft/world/level/saveddata/MapItemSavedData.cpp @@ -28,8 +28,8 @@ MapItemSavedData::HoldingPlayer::HoldingPlayer(std::shared_ptr player, const MapItemSavedData* parent) : parent(parent), player(player) { // inited outside of ctor - rowsDirtyMin = intArray(MapItem::IMAGE_WIDTH); - rowsDirtyMax = intArray(MapItem::IMAGE_WIDTH); + rowsDirtyMin = std::vector(MapItem::IMAGE_WIDTH); + rowsDirtyMax = std::vector(MapItem::IMAGE_WIDTH); tick = 0; sendPosTick = 0; @@ -38,22 +38,19 @@ MapItemSavedData::HoldingPlayer::HoldingPlayer(std::shared_ptr player, // java ctor // this->player = player; - for (unsigned int i = 0; i < rowsDirtyMin.length; i++) { + for (unsigned int i = 0; i < rowsDirtyMin.size(); i++) { rowsDirtyMin[i] = 0; rowsDirtyMax[i] = MapItem::IMAGE_HEIGHT - 1; } } MapItemSavedData::HoldingPlayer::~HoldingPlayer() { - delete rowsDirtyMin.data; - delete rowsDirtyMax.data; - delete lastSentDecorations.data; } -charArray MapItemSavedData::HoldingPlayer::nextUpdatePacket( +std::vector MapItemSavedData::HoldingPlayer::nextUpdatePacket( std::shared_ptr itemInstance) { if (!hasSentInitial) { - charArray data(2); + std::vector data(2); data[0] = HEADER_METADATA; data[1] = parent->scale; @@ -66,8 +63,8 @@ charArray MapItemSavedData::HoldingPlayer::nextUpdatePacket( unsigned int playerDecorationsSize = (int)parent->decorations.size(); unsigned int nonPlayerDecorationsSize = (int)parent->nonPlayerDecorations.size(); - charArray data = - charArray((playerDecorationsSize + nonPlayerDecorationsSize) * + std::vector data = + std::vector((playerDecorationsSize + nonPlayerDecorationsSize) * DEC_PACKET_BYTES + 1); data[0] = 1; @@ -112,11 +109,11 @@ charArray MapItemSavedData::HoldingPlayer::nextUpdatePacket( ++dataIndex; } bool thesame = !itemInstance->isFramed(); - if (lastSentDecorations.data == nullptr || - lastSentDecorations.length != data.length) { + if (lastSentDecorations.empty() || + lastSentDecorations.size() != data.size()) { thesame = false; } else { - for (unsigned int i = 0; i < data.length; i++) { + for (unsigned int i = 0; i < data.size(); i++) { if (data[i] != lastSentDecorations[i]) { thesame = false; break; @@ -125,16 +122,12 @@ charArray MapItemSavedData::HoldingPlayer::nextUpdatePacket( } if (!thesame) { - if (lastSentDecorations.data != nullptr) { - delete[] lastSentDecorations.data; - } // Make a copy of data, as the calling function presumes it can // destroy the returned data - lastSentDecorations = charArray(data.length); - memcpy(lastSentDecorations.data, data.data, data.length); + lastSentDecorations = std::vector(data.size()); + memcpy(lastSentDecorations.data(), data.data(), data.size()); return data; } - delete[] data.data; // 4jcraft, changed to [] } std::shared_ptr servPlayer = std::dynamic_pointer_cast(player); @@ -145,11 +138,11 @@ charArray MapItemSavedData::HoldingPlayer::nextUpdatePacket( int len = rowsDirtyMax[column] - rowsDirtyMin[column] + 1; int min = rowsDirtyMin[column]; - charArray data = charArray(len + 3); + std::vector data = std::vector(len + 3); data[0] = HEADER_COLOURS; data[1] = (char)column; data[2] = (char)min; - for (unsigned int y = 0; y < data.length - 3; y++) { + for (unsigned int y = 0; y < data.size() - 3; y++) { data[y + 3] = parent->colors[(y + min) * MapItem::IMAGE_WIDTH + column]; } @@ -158,18 +151,17 @@ charArray MapItemSavedData::HoldingPlayer::nextUpdatePacket( return data; } } - return charArray(); + return std::vector(); } MapItemSavedData::MapItemSavedData(const std::wstring& id) : SavedData(id) { x = z = 0; dimension = 0; scale = 0; - colors = byteArray(MapItem::IMAGE_WIDTH * MapItem::IMAGE_HEIGHT); + colors = std::vector(MapItem::IMAGE_WIDTH * MapItem::IMAGE_HEIGHT); } MapItemSavedData::~MapItemSavedData() { - delete colors.data; for (unsigned int i = 0; i < decorations.size(); i++) { delete decorations[i]; } @@ -188,13 +180,10 @@ void MapItemSavedData::load(CompoundTag* tag) { if (width == MapItem::IMAGE_WIDTH && height == MapItem::IMAGE_HEIGHT) { colors = tag->getByteArray(L"colors"); } else { - byteArray newColors = tag->getByteArray(L"colors"); - // 4J - if (colors.data != nullptr) { - delete[] colors.data; - } + std::vector newColors = tag->getByteArray(L"colors"); + // 4J - vector manages its own memory, no need to delete old colors // End4J - colors = byteArray(MapItem::IMAGE_WIDTH * MapItem::IMAGE_HEIGHT); + colors = std::vector(MapItem::IMAGE_WIDTH * MapItem::IMAGE_HEIGHT); int xo = (MapItem::IMAGE_WIDTH - width) / 2; int yo = (MapItem::IMAGE_HEIGHT - height) / 2; for (int y = 0; y < height; y++) { @@ -462,11 +451,11 @@ void MapItemSavedData::tickCarriedBy(std::shared_ptr player, } } -charArray MapItemSavedData::getUpdatePacket( +std::vector MapItemSavedData::getUpdatePacket( std::shared_ptr itemInstance, Level* level, std::shared_ptr player) { auto it = carriedByPlayers.find(player); - if (it == carriedByPlayers.end()) return charArray(); + if (it == carriedByPlayers.end()) return std::vector(); std::shared_ptr hp = it->second; return hp->nextUpdatePacket(itemInstance); @@ -485,11 +474,11 @@ void MapItemSavedData::setDirty(int x, int y0, int y1) { } } -void MapItemSavedData::handleComplexItemData(charArray& data) { +void MapItemSavedData::handleComplexItemData(std::vector& data) { if (data[0] == HEADER_COLOURS) { int xx = data[1] & 0xff; int yy = data[2] & 0xff; - for (unsigned int y = 0; y < data.length - 3; y++) { + for (unsigned int y = 0; y < data.size() - 3; y++) { colors[(y + yy) * MapItem::IMAGE_WIDTH + xx] = data[y + 3]; } setDirty(); @@ -499,7 +488,7 @@ void MapItemSavedData::handleComplexItemData(charArray& data) { delete decorations[i]; } decorations.clear(); - for (unsigned int i = 0; i < (data.length - 1) / DEC_PACKET_BYTES; + for (unsigned int i = 0; i < (data.size() - 1) / DEC_PACKET_BYTES; i++) { #if defined(_LARGE_WORLDS) char img = data[i * DEC_PACKET_BYTES + 1]; diff --git a/minecraft/Minecraft.World/net/minecraft/world/level/saveddata/MapItemSavedData.h b/minecraft/Minecraft.World/net/minecraft/world/level/saveddata/MapItemSavedData.h index 07eef8184..59b1a7163 100644 --- a/minecraft/Minecraft.World/net/minecraft/world/level/saveddata/MapItemSavedData.h +++ b/minecraft/Minecraft.World/net/minecraft/world/level/saveddata/MapItemSavedData.h @@ -32,13 +32,13 @@ public: class HoldingPlayer { public: const std::shared_ptr player; - intArray rowsDirtyMin; - intArray rowsDirtyMax; + std::vector rowsDirtyMin; + std::vector rowsDirtyMax; private: int tick; int sendPosTick; - charArray lastSentDecorations; + std::vector lastSentDecorations; public: int step; @@ -55,14 +55,14 @@ public: HoldingPlayer(std::shared_ptr player, const MapItemSavedData* parent); ~HoldingPlayer(); - charArray nextUpdatePacket(std::shared_ptr itemInstance); + std::vector nextUpdatePacket(std::shared_ptr itemInstance); }; public: int x, z; char dimension; uint8_t scale; - byteArray colors; + std::vector colors; std::vector > carriedBy; private: @@ -90,12 +90,12 @@ public: void tickCarriedBy(std::shared_ptr player, std::shared_ptr item); - charArray getUpdatePacket(std::shared_ptr itemInstance, + std::vector getUpdatePacket(std::shared_ptr itemInstance, Level* level, std::shared_ptr player); using SavedData::setDirty; void setDirty(int x, int y0, int y1); - void handleComplexItemData(charArray& data); + void handleComplexItemData(std::vector& data); std::shared_ptr getHoldingPlayer( std::shared_ptr player); diff --git a/minecraft/Minecraft.World/net/minecraft/world/level/storage/DirectoryLevelStorage.cpp b/minecraft/Minecraft.World/net/minecraft/world/level/storage/DirectoryLevelStorage.cpp index c4db7855f..261242e07 100644 --- a/minecraft/Minecraft.World/net/minecraft/world/level/storage/DirectoryLevelStorage.cpp +++ b/minecraft/Minecraft.World/net/minecraft/world/level/storage/DirectoryLevelStorage.cpp @@ -165,7 +165,7 @@ DirectoryLevelStorage::DirectoryLevelStorage(ConsoleSaveFile* saveFile, m_bHasLoadedMapDataMappings = false; #if defined(_LARGE_WORLDS) - m_usedMappings = byteArray(MAXIMUM_MAP_SAVE_DATA / 8); + m_usedMappings = std::vector(MAXIMUM_MAP_SAVE_DATA / 8); #endif } @@ -178,7 +178,6 @@ DirectoryLevelStorage::~DirectoryLevelStorage() { } #if defined(_LARGE_WORLDS) - delete m_usedMappings.data; #endif } @@ -239,8 +238,8 @@ LevelData* DirectoryLevelStorage::prepareLevel() { SaveFileSeekOrigin::Begin); #if defined(_LARGE_WORLDS) - byteArray data(fileEntry->getFileSize()); - getSaveFile()->readFile(fileEntry, data.data, + std::vector data(fileEntry->getFileSize()); + getSaveFile()->readFile(fileEntry, data.data(), fileEntry->getFileSize(), &NumberOfBytesRead); assert(NumberOfBytesRead == fileEntry->getFileSize()); @@ -541,7 +540,7 @@ int DirectoryLevelStorage::getAuxValueForMap(PlayerUID xuid, int dimension, } if (!foundMapping) { - for (unsigned int i = 0; i < m_usedMappings.length; ++i) { + for (unsigned int i = 0; i < m_usedMappings.size(); ++i) { if (m_usedMappings[i] < 0xFF) { unsigned int offset = 0; for (; offset < 8; ++offset) { @@ -625,7 +624,7 @@ void DirectoryLevelStorage::saveMapIdLookup() { } dos.write(m_usedMappings); m_saveFile->writeFile(fileEntry, - baos.buf.data, // data buffer + baos.buf.data(), // data buffer baos.size(), // number of bytes to write &NumberOfBytesWritten // number of bytes written ); diff --git a/minecraft/Minecraft.World/net/minecraft/world/level/storage/DirectoryLevelStorage.h b/minecraft/Minecraft.World/net/minecraft/world/level/storage/DirectoryLevelStorage.h index 4300de599..dd5c3691b 100644 --- a/minecraft/Minecraft.World/net/minecraft/world/level/storage/DirectoryLevelStorage.h +++ b/minecraft/Minecraft.World/net/minecraft/world/level/storage/DirectoryLevelStorage.h @@ -86,7 +86,7 @@ private: void readMappings(DataInputStream* dis); }; std::unordered_map m_playerMappings; - byteArray m_usedMappings; + std::vector m_usedMappings; #else MapDataMappings m_mapDataMappings; MapDataMappings m_saveableMapDataMappings; diff --git a/minecraft/Minecraft.World/net/minecraft/world/level/tile/LeafTile.cpp b/minecraft/Minecraft.World/net/minecraft/world/level/tile/LeafTile.cpp index c7a60d3f9..4de69f6e2 100644 --- a/minecraft/Minecraft.World/net/minecraft/world/level/tile/LeafTile.cpp +++ b/minecraft/Minecraft.World/net/minecraft/world/level/tile/LeafTile.cpp @@ -330,7 +330,7 @@ unsigned int LeafTile::getDescriptionId(int iData /*= -1*/) { void LeafTile::registerIcons(IconRegister* iconRegister) { for (int fancy = 0; fancy < 2; fancy++) { - // icons[fancy] = new Icon[TEXTURES[fancy].length]; + // icons[fancy] = new Icon[TEXTURES[fancy].size()]; for (int i = 0; i < 4; i++) { icons[fancy][i] = iconRegister->registerIcon(TEXTURES[fancy][i]); diff --git a/minecraft/Minecraft.World/net/minecraft/world/level/tile/Tile.cpp b/minecraft/Minecraft.World/net/minecraft/world/level/tile/Tile.cpp index 5d4f4c87e..31989b650 100644 --- a/minecraft/Minecraft.World/net/minecraft/world/level/tile/Tile.cpp +++ b/minecraft/Minecraft.World/net/minecraft/world/level/tile/Tile.cpp @@ -1679,7 +1679,7 @@ void Tile::staticCtor() { ->setDescriptionId(IDS_TILE_VINE) ->setUseDescriptionId(IDS_DESC_VINE); int idsData[3] = {IDS_TILE_SHRUB, IDS_TILE_TALL_GRASS, IDS_TILE_FERN}; - intArray ids = intArray(idsData, 3); + std::vector ids = std::vector(idsData, idsData + 3); Item::items[tallgrass_Id] = ((ColoredTileItem*)(new ColoredTileItem(Tile::tallgrass_Id - 256, true)) ->setDescriptionId(IDS_TILE_TALL_GRASS)) @@ -2383,7 +2383,7 @@ bool Tile::isSilkTouchable() { return isCubeShaped() && !_isEntityTile; } std::shared_ptr Tile::getSilkTouchItemInstance(int data) { int popData = 0; - if (id >= 0 && id < Item::items.length && + if (id >= 0 && id < Item::items.size() && Item::items[id]->isStackedByData()) { popData = data; } diff --git a/minecraft/Minecraft.World/net/minecraft/world/level/tile/entity/BrewingStandTileEntity.cpp b/minecraft/Minecraft.World/net/minecraft/world/level/tile/entity/BrewingStandTileEntity.cpp index 595be360b..c05fd32b9 100644 --- a/minecraft/Minecraft.World/net/minecraft/world/level/tile/entity/BrewingStandTileEntity.cpp +++ b/minecraft/Minecraft.World/net/minecraft/world/level/tile/entity/BrewingStandTileEntity.cpp @@ -10,17 +10,17 @@ int slotsForUp[] = {BrewingStandTileEntity::INGREDIENT_SLOT}; int slotsForOtherFaces[] = {0, 1, 2}; -intArray BrewingStandTileEntity::SLOTS_FOR_UP = intArray(slotsForUp, 1); -intArray BrewingStandTileEntity::SLOTS_FOR_OTHER_FACES = - intArray(slotsForOtherFaces, 3); +std::vector BrewingStandTileEntity::SLOTS_FOR_UP = std::vector(slotsForUp, slotsForUp + 1); +std::vector BrewingStandTileEntity::SLOTS_FOR_OTHER_FACES = + std::vector(slotsForOtherFaces, slotsForOtherFaces + 3); BrewingStandTileEntity::BrewingStandTileEntity() { brewTime = 0; - items = arrayWithLength>(4); + items = std::vector>(4); name = L""; } -BrewingStandTileEntity::~BrewingStandTileEntity() { delete[] items.data; } +BrewingStandTileEntity::~BrewingStandTileEntity() {} std::wstring BrewingStandTileEntity::getName() { return hasCustomName() ? name : app.GetString(IDS_TILE_BREWINGSTAND); @@ -36,7 +36,7 @@ void BrewingStandTileEntity::setCustomName(const std::wstring& name) { this->name = name; } -unsigned int BrewingStandTileEntity::getContainerSize() { return items.length; } +unsigned int BrewingStandTileEntity::getContainerSize() { return items.size(); } void BrewingStandTileEntity::tick() { if (brewTime > 0) { @@ -260,12 +260,11 @@ void BrewingStandTileEntity::load(CompoundTag* base) { ListTag* inventoryList = (ListTag*)base->getList(L"Items"); - delete[] items.data; - items = arrayWithLength>(getContainerSize()); + items = std::vector>(getContainerSize()); for (int i = 0; i < inventoryList->size(); i++) { CompoundTag* tag = inventoryList->get(i); int slot = tag->getByte(L"Slot"); - if (slot >= 0 && slot < items.length) + if (slot >= 0 && slot < items.size()) items[slot] = ItemInstance::fromTag(tag); } @@ -279,7 +278,7 @@ void BrewingStandTileEntity::save(CompoundTag* base) { base->putShort(L"BrewTime", (short)(brewTime)); ListTag* listTag = new ListTag(); - for (int i = 0; i < items.length; i++) { + for (int i = 0; i < items.size(); i++) { if (items[i] != nullptr) { CompoundTag* tag = new CompoundTag(); tag->putByte(L"Slot", (uint8_t)i); @@ -293,7 +292,7 @@ void BrewingStandTileEntity::save(CompoundTag* base) { std::shared_ptr BrewingStandTileEntity::getItem( unsigned int slot) { - if (slot >= 0 && slot < items.length) { + if (slot >= 0 && slot < items.size()) { return items[slot]; } return nullptr; @@ -306,7 +305,7 @@ std::shared_ptr BrewingStandTileEntity::removeItem( // slot Fix for #65373 - TU8: Content: UI: Command "Take Half" in the // Brewing Stand interface doesn't work as intended. - if (slot >= 0 && slot < items.length && items[slot] != nullptr) { + if (slot >= 0 && slot < items.size() && items[slot] != nullptr) { if (items[slot]->count <= count) { std::shared_ptr item = items[slot]; items[slot] = nullptr; @@ -328,7 +327,7 @@ std::shared_ptr BrewingStandTileEntity::removeItem( std::shared_ptr BrewingStandTileEntity::removeItemNoUpdate( int slot) { - if (slot >= 0 && slot < items.length) { + if (slot >= 0 && slot < items.size()) { std::shared_ptr item = items[slot]; items[slot] = nullptr; return item; @@ -338,7 +337,7 @@ std::shared_ptr BrewingStandTileEntity::removeItemNoUpdate( void BrewingStandTileEntity::setItem(unsigned int slot, std::shared_ptr item) { - if (slot >= 0 && slot < items.length) { + if (slot >= 0 && slot < items.size()) { items[slot] = item; } } @@ -385,7 +384,7 @@ int BrewingStandTileEntity::getPotionBits() { return newCount; } -intArray BrewingStandTileEntity::getSlotsForFace(int face) { +std::vector BrewingStandTileEntity::getSlotsForFace(int face) { if (face == Facing::UP) { return SLOTS_FOR_UP; } @@ -413,9 +412,9 @@ std::shared_ptr BrewingStandTileEntity::clone() { result->lastPotionCount = lastPotionCount; result->ingredientId = ingredientId; - for (unsigned int i = 0; i < items.length; i++) { - if (items.data[i] != nullptr) { - result->items.data[i] = ItemInstance::clone(items.data[i]); + for (unsigned int i = 0; i < items.size(); i++) { + if (items[i] != nullptr) { + result->items[i] = ItemInstance::clone(items[i]); } } return result; diff --git a/minecraft/Minecraft.World/net/minecraft/world/level/tile/entity/BrewingStandTileEntity.h b/minecraft/Minecraft.World/net/minecraft/world/level/tile/entity/BrewingStandTileEntity.h index a4cba533d..b385a4d1e 100644 --- a/minecraft/Minecraft.World/net/minecraft/world/level/tile/entity/BrewingStandTileEntity.h +++ b/minecraft/Minecraft.World/net/minecraft/world/level/tile/entity/BrewingStandTileEntity.h @@ -10,9 +10,9 @@ public: static const int INGREDIENT_SLOT = 3; private: - arrayWithLength> items; - static intArray SLOTS_FOR_UP; - static intArray SLOTS_FOR_OTHER_FACES; + std::vector> items; + static std::vector SLOTS_FOR_UP; + static std::vector SLOTS_FOR_OTHER_FACES; int brewTime; int lastPotionCount; @@ -53,7 +53,7 @@ public: virtual void setBrewTime(int value); virtual void setChanged() { TileEntity::setChanged(); } // 4J added int getPotionBits(); - virtual intArray getSlotsForFace(int face); + virtual std::vector getSlotsForFace(int face); virtual bool canPlaceItemThroughFace(int slot, std::shared_ptr item, int face); diff --git a/minecraft/Minecraft.World/net/minecraft/world/level/tile/entity/ChestTileEntity.cpp b/minecraft/Minecraft.World/net/minecraft/world/level/tile/entity/ChestTileEntity.cpp index 126d08260..57f910f91 100644 --- a/minecraft/Minecraft.World/net/minecraft/world/level/tile/entity/ChestTileEntity.cpp +++ b/minecraft/Minecraft.World/net/minecraft/world/level/tile/entity/ChestTileEntity.cpp @@ -21,7 +21,7 @@ int ChestTileEntity::getContainerType() { } void ChestTileEntity::_init(bool isBonusChest) { - items = new arrayWithLength>(9 * 4); + items = new std::vector>(9 * 4); hasCheckedNeighbors = false; this->isBonusChest = isBonusChest; @@ -48,29 +48,28 @@ ChestTileEntity::ChestTileEntity(int type, bool isBonusChest /* = false*/) } ChestTileEntity::~ChestTileEntity() { - delete[] items->data; delete items; } unsigned int ChestTileEntity::getContainerSize() { return 9 * 3; } std::shared_ptr ChestTileEntity::getItem(unsigned int slot) { - return items->data[slot]; + return (*items)[slot]; } std::shared_ptr ChestTileEntity::removeItem(unsigned int slot, int count) { - if (items->data[slot] != nullptr) { - if (items->data[slot]->count <= count) { - std::shared_ptr item = items->data[slot]; - items->data[slot] = nullptr; + if ((*items)[slot] != nullptr) { + if ((*items)[slot]->count <= count) { + std::shared_ptr item = (*items)[slot]; + (*items)[slot] = nullptr; setChanged(); // 4J Stu - Fix for duplication glitch if (item->count <= 0) return nullptr; return item; } else { - std::shared_ptr i = items->data[slot]->remove(count); - if (items->data[slot]->count == 0) items->data[slot] = nullptr; + std::shared_ptr i = (*items)[slot]->remove(count); + if ((*items)[slot]->count == 0) (*items)[slot] = nullptr; setChanged(); // 4J Stu - Fix for duplication glitch if (i->count <= 0) return nullptr; @@ -81,9 +80,9 @@ std::shared_ptr ChestTileEntity::removeItem(unsigned int slot, } std::shared_ptr ChestTileEntity::removeItemNoUpdate(int slot) { - if (items->data[slot] != nullptr) { - std::shared_ptr item = items->data[slot]; - items->data[slot] = nullptr; + if ((*items)[slot] != nullptr) { + std::shared_ptr item = (*items)[slot]; + (*items)[slot] = nullptr; return item; } return nullptr; @@ -91,7 +90,7 @@ std::shared_ptr ChestTileEntity::removeItemNoUpdate(int slot) { void ChestTileEntity::setItem(unsigned int slot, std::shared_ptr item) { - items->data[slot] = item; + (*items)[slot] = item; if (item != nullptr && item->count > getMaxStackSize()) item->count = getMaxStackSize(); this->setChanged(); @@ -116,15 +115,14 @@ void ChestTileEntity::load(CompoundTag* base) { ListTag* inventoryList = (ListTag*)base->getList(L"Items"); if (items) { - delete[] items->data; delete items; } - items = new arrayWithLength>(getContainerSize()); + items = new std::vector>(getContainerSize()); if (base->contains(L"CustomName")) name = base->getString(L"CustomName"); for (int i = 0; i < inventoryList->size(); i++) { CompoundTag* tag = inventoryList->get(i); unsigned int slot = tag->getByte(L"Slot") & 0xff; - if (slot >= 0 && slot < items->length) + if (slot >= 0 && slot < items->size()) (*items)[slot] = ItemInstance::fromTag(tag); } isBonusChest = base->getBoolean(L"bonus"); @@ -134,11 +132,11 @@ void ChestTileEntity::save(CompoundTag* base) { TileEntity::save(base); ListTag* listTag = new ListTag; - for (unsigned int i = 0; i < items->length; i++) { - if (items->data[i] != nullptr) { + for (unsigned int i = 0; i < items->size(); i++) { + if ((*items)[i] != nullptr) { CompoundTag* tag = new CompoundTag(); tag->putByte(L"Slot", (uint8_t)i); - items->data[i]->save(tag); + (*items)[i]->save(tag); listTag->add(tag); } } @@ -381,9 +379,9 @@ std::shared_ptr ChestTileEntity::clone() { std::shared_ptr(new ChestTileEntity()); TileEntity::clone(result); - for (unsigned int i = 0; i < items->length; i++) { - if (items->data[i] != nullptr) { - result->items->data[i] = ItemInstance::clone(items->data[i]); + for (unsigned int i = 0; i < items->size(); i++) { + if ((*items)[i] != nullptr) { + (*result->items)[i] = ItemInstance::clone((*items)[i]); } } return result; diff --git a/minecraft/Minecraft.World/net/minecraft/world/level/tile/entity/ChestTileEntity.h b/minecraft/Minecraft.World/net/minecraft/world/level/tile/entity/ChestTileEntity.h index a4e2e9c3d..2410e1f80 100644 --- a/minecraft/Minecraft.World/net/minecraft/world/level/tile/entity/ChestTileEntity.h +++ b/minecraft/Minecraft.World/net/minecraft/world/level/tile/entity/ChestTileEntity.h @@ -26,7 +26,7 @@ public: virtual ~ChestTileEntity(); private: - arrayWithLength>* items; + std::vector>* items; public: bool isBonusChest; // 4J added diff --git a/minecraft/Minecraft.World/net/minecraft/world/level/tile/entity/DispenserTileEntity.cpp b/minecraft/Minecraft.World/net/minecraft/world/level/tile/entity/DispenserTileEntity.cpp index 85997d6ac..ee1a73793 100644 --- a/minecraft/Minecraft.World/net/minecraft/world/level/tile/entity/DispenserTileEntity.cpp +++ b/minecraft/Minecraft.World/net/minecraft/world/level/tile/entity/DispenserTileEntity.cpp @@ -8,14 +8,12 @@ #include "DispenserTileEntity.h" DispenserTileEntity::DispenserTileEntity() : TileEntity() { - items = arrayWithLength>(9); + items = std::vector>(9); random = new Random(); name = L""; } DispenserTileEntity::~DispenserTileEntity() { - delete[] items.data; - delete random; } @@ -81,7 +79,7 @@ void DispenserTileEntity::AddItemBack(std::shared_ptr item, * @return */ bool DispenserTileEntity::removeProjectile(int itemId) { - for (unsigned int i = 0; i < items.length; i++) { + for (unsigned int i = 0; i < items.size(); i++) { if (items[i] != nullptr && items[i]->id == itemId) { std::shared_ptr removedItem = removeItem(i, 1); return removedItem != nullptr; @@ -93,7 +91,7 @@ bool DispenserTileEntity::removeProjectile(int itemId) { int DispenserTileEntity::getRandomSlot() { int replaceSlot = -1; int replaceOdds = 1; - for (unsigned int i = 0; i < items.length; i++) { + for (unsigned int i = 0; i < items.size(); i++) { if (items[i] != nullptr && random->nextInt(replaceOdds++) == 0) { replaceSlot = i; } @@ -111,7 +109,7 @@ void DispenserTileEntity::setItem(unsigned int slot, } int DispenserTileEntity::addItem(std::shared_ptr item) { - for (int i = 0; i < items.length; i++) { + for (int i = 0; i < items.size(); i++) { if (items[i] == nullptr || items[i]->id == 0) { setItem(i, item); return i; @@ -139,12 +137,11 @@ void DispenserTileEntity::load(CompoundTag* base) { TileEntity::load(base); ListTag* inventoryList = (ListTag*)base->getList(L"Items"); - delete[] items.data; - items = arrayWithLength>(getContainerSize()); + items = std::vector>(getContainerSize()); for (int i = 0; i < inventoryList->size(); i++) { CompoundTag* tag = inventoryList->get(i); unsigned int slot = tag->getByte(L"Slot") & 0xff; - if (slot >= 0 && slot < items.length) + if (slot >= 0 && slot < items.size()) items[slot] = ItemInstance::fromTag(tag); } if (base->contains(L"CustomName")) name = base->getString(L"CustomName"); @@ -154,7 +151,7 @@ void DispenserTileEntity::save(CompoundTag* base) { TileEntity::save(base); ListTag* listTag = new ListTag; - for (unsigned int i = 0; i < items.length; i++) { + for (unsigned int i = 0; i < items.size(); i++) { if (items[i] != nullptr) { CompoundTag* tag = new CompoundTag(); tag->putByte(L"Slot", (uint8_t)i); @@ -193,7 +190,7 @@ std::shared_ptr DispenserTileEntity::clone() { std::shared_ptr(new DispenserTileEntity()); TileEntity::clone(result); - for (unsigned int i = 0; i < items.length; i++) { + for (unsigned int i = 0; i < items.size(); i++) { if (items[i] != nullptr) { result->items[i] = ItemInstance::clone(items[i]); } diff --git a/minecraft/Minecraft.World/net/minecraft/world/level/tile/entity/DispenserTileEntity.h b/minecraft/Minecraft.World/net/minecraft/world/level/tile/entity/DispenserTileEntity.h index 470b7ef4f..5c3a8b823 100644 --- a/minecraft/Minecraft.World/net/minecraft/world/level/tile/entity/DispenserTileEntity.h +++ b/minecraft/Minecraft.World/net/minecraft/world/level/tile/entity/DispenserTileEntity.h @@ -17,7 +17,7 @@ public: using TileEntity::setChanged; private: - arrayWithLength> items; + std::vector> items; Random* random; protected: diff --git a/minecraft/Minecraft.World/net/minecraft/world/level/tile/entity/FurnaceTileEntity.cpp b/minecraft/Minecraft.World/net/minecraft/world/level/tile/entity/FurnaceTileEntity.cpp index 0cec50a3b..ea8b5b3a3 100644 --- a/minecraft/Minecraft.World/net/minecraft/world/level/tile/entity/FurnaceTileEntity.cpp +++ b/minecraft/Minecraft.World/net/minecraft/world/level/tile/entity/FurnaceTileEntity.cpp @@ -14,17 +14,19 @@ int furnaceSlotsForDown[] = {FurnaceTileEntity::SLOT_RESULT, FurnaceTileEntity::SLOT_FUEL}; int furnaceSlotsForSides[] = {FurnaceTileEntity::SLOT_FUEL}; -const intArray FurnaceTileEntity::SLOTS_FOR_UP = intArray(furnaceSlotsForUp, 1); -const intArray FurnaceTileEntity::SLOTS_FOR_DOWN = - intArray(furnaceSlotsForDown, 2); -const intArray FurnaceTileEntity::SLOTS_FOR_SIDES = - intArray(furnaceSlotsForSides, 1); +const std::vector FurnaceTileEntity::SLOTS_FOR_UP = std::vector(furnaceSlotsForUp, furnaceSlotsForUp + 1); +const std::vector FurnaceTileEntity::SLOTS_FOR_DOWN = + std::vector(furnaceSlotsForDown, furnaceSlotsForDown + 2); +const std::vector FurnaceTileEntity::SLOTS_FOR_SIDES = + std::vector(furnaceSlotsForSides, furnaceSlotsForSides + 1); const int FurnaceTileEntity::BURN_INTERVAL = 10 * 20; // 4J Stu - Need a ctor to initialise member variables +FurnaceTileEntity::~FurnaceTileEntity() {} + FurnaceTileEntity::FurnaceTileEntity() : TileEntity() { - items = arrayWithLength>(3); + items = std::vector>(3); litTime = 0; litDuration = 0; @@ -33,9 +35,8 @@ FurnaceTileEntity::FurnaceTileEntity() : TileEntity() { name = L""; } -FurnaceTileEntity::~FurnaceTileEntity() { delete[] items.data; } -unsigned int FurnaceTileEntity::getContainerSize() { return items.length; } +unsigned int FurnaceTileEntity::getContainerSize() { return items.size(); } std::shared_ptr FurnaceTileEntity::getItem(unsigned int slot) { return items[slot]; @@ -99,12 +100,11 @@ void FurnaceTileEntity::load(CompoundTag* base) { TileEntity::load(base); ListTag* inventoryList = (ListTag*)base->getList(L"Items"); - delete[] items.data; - items = arrayWithLength>(getContainerSize()); + items = std::vector>(getContainerSize()); for (int i = 0; i < inventoryList->size(); i++) { CompoundTag* tag = inventoryList->get(i); unsigned int slot = tag->getByte(L"Slot"); - if (slot >= 0 && slot < items.length) + if (slot >= 0 && slot < items.size()) items[slot] = ItemInstance::fromTag(tag); } @@ -121,7 +121,7 @@ void FurnaceTileEntity::save(CompoundTag* base) { base->putShort(L"CookTime", (short)(tickCount)); ListTag* listTag = new ListTag(); - for (unsigned int i = 0; i < items.length; i++) { + for (unsigned int i = 0; i < items.size(); i++) { if (items[i] != nullptr) { CompoundTag* tag = new CompoundTag(); tag->putByte(L"Slot", (uint8_t)i); @@ -305,7 +305,7 @@ bool FurnaceTileEntity::canPlaceItem(int slot, return true; } -intArray FurnaceTileEntity::getSlotsForFace(int face) { +std::vector FurnaceTileEntity::getSlotsForFace(int face) { if (face == Facing::DOWN) { return SLOTS_FOR_DOWN; } else if (face == Facing::UP) { @@ -339,7 +339,7 @@ std::shared_ptr FurnaceTileEntity::clone() { result->tickCount = tickCount; result->litDuration = litDuration; - for (unsigned int i = 0; i < items.length; i++) { + for (unsigned int i = 0; i < items.size(); i++) { if (items[i] != nullptr) { result->items[i] = ItemInstance::clone(items[i]); } diff --git a/minecraft/Minecraft.World/net/minecraft/world/level/tile/entity/FurnaceTileEntity.h b/minecraft/Minecraft.World/net/minecraft/world/level/tile/entity/FurnaceTileEntity.h index 6e01f7b2a..7e43a2886 100644 --- a/minecraft/Minecraft.World/net/minecraft/world/level/tile/entity/FurnaceTileEntity.h +++ b/minecraft/Minecraft.World/net/minecraft/world/level/tile/entity/FurnaceTileEntity.h @@ -19,12 +19,12 @@ public: static const int SLOT_RESULT = 2; private: - static const intArray SLOTS_FOR_UP; - static const intArray SLOTS_FOR_DOWN; - static const intArray SLOTS_FOR_SIDES; + static const std::vector SLOTS_FOR_UP; + static const std::vector SLOTS_FOR_DOWN; + static const std::vector SLOTS_FOR_SIDES; static const int BURN_INTERVAL; - arrayWithLength> items; + std::vector> items; // 4J-JEV: Added for 'Renewable Energy' achievement. // Should be true iff characoal was consumed whilst cooking the current @@ -79,7 +79,7 @@ public: void stopOpen(); virtual bool canPlaceItem(int slot, std::shared_ptr item); - virtual intArray getSlotsForFace(int face); + virtual std::vector getSlotsForFace(int face); virtual bool canPlaceItemThroughFace(int slot, std::shared_ptr item, int face); diff --git a/minecraft/Minecraft.World/net/minecraft/world/level/tile/entity/HopperTileEntity.cpp b/minecraft/Minecraft.World/net/minecraft/world/level/tile/entity/HopperTileEntity.cpp index 684b1976c..62456fbe4 100644 --- a/minecraft/Minecraft.World/net/minecraft/world/level/tile/entity/HopperTileEntity.cpp +++ b/minecraft/Minecraft.World/net/minecraft/world/level/tile/entity/HopperTileEntity.cpp @@ -11,26 +11,25 @@ #include "HopperTileEntity.h" HopperTileEntity::HopperTileEntity() { - items = arrayWithLength>(5); + items = std::vector>(5); name = L""; cooldownTime = -1; } -HopperTileEntity::~HopperTileEntity() { delete[] items.data; } +HopperTileEntity::~HopperTileEntity() {} void HopperTileEntity::load(CompoundTag* base) { TileEntity::load(base); ListTag* inventoryList = (ListTag*)base->getList(L"Items"); - delete[] items.data; - items = arrayWithLength>(getContainerSize()); + items = std::vector>(getContainerSize()); if (base->contains(L"CustomName")) name = base->getString(L"CustomName"); cooldownTime = base->getInt(L"TransferCooldown"); for (int i = 0; i < inventoryList->size(); i++) { CompoundTag* tag = inventoryList->get(i); int slot = tag->getByte(L"Slot"); - if (slot >= 0 && slot < items.length) + if (slot >= 0 && slot < items.size()) items[slot] = ItemInstance::fromTag(tag); } } @@ -39,7 +38,7 @@ void HopperTileEntity::save(CompoundTag* base) { TileEntity::save(base); ListTag* listTag = new ListTag(); - for (int i = 0; i < items.length; i++) { + for (int i = 0; i < items.size(); i++) { if (items[i] != nullptr) { CompoundTag* tag = new CompoundTag(); tag->putByte(L"Slot", (uint8_t)i); @@ -54,7 +53,7 @@ void HopperTileEntity::save(CompoundTag* base) { void HopperTileEntity::setChanged() { TileEntity::setChanged(); } -unsigned int HopperTileEntity::getContainerSize() { return items.length; } +unsigned int HopperTileEntity::getContainerSize() { return items.size(); } std::shared_ptr HopperTileEntity::getItem(unsigned int slot) { return items[slot]; @@ -187,9 +186,9 @@ bool HopperTileEntity::suckInItems(Hopper* hopper) { std::shared_ptr worldly = std::dynamic_pointer_cast(container); if ((worldly != nullptr) && (face > -1)) { - intArray slots = worldly->getSlotsForFace(face); + std::vector slots = worldly->getSlotsForFace(face); - for (int i = 0; i < slots.length; i++) { + for (int i = 0; i < slots.size(); i++) { if (tryTakeInItemFromSlot(hopper, container.get(), slots[i], face)) return true; @@ -259,9 +258,9 @@ std::shared_ptr HopperTileEntity::addItem( Container* container, std::shared_ptr item, int face) { if (dynamic_cast(container) != nullptr && face > -1) { WorldlyContainer* worldly = (WorldlyContainer*)container; - intArray slots = worldly->getSlotsForFace(face); + std::vector slots = worldly->getSlotsForFace(face); - for (int i = 0; i < slots.length && item != nullptr && item->count > 0; + for (int i = 0; i < slots.size() && item != nullptr && item->count > 0; i++) { item = tryMoveInItem(container, item, slots[i], face); } @@ -428,7 +427,7 @@ std::shared_ptr HopperTileEntity::clone() { result->name = name; result->cooldownTime = cooldownTime; - for (unsigned int i = 0; i < items.length; i++) { + for (unsigned int i = 0; i < items.size(); i++) { if (items[i] != nullptr) { result->items[i] = ItemInstance::clone(items[i]); } diff --git a/minecraft/Minecraft.World/net/minecraft/world/level/tile/entity/HopperTileEntity.h b/minecraft/Minecraft.World/net/minecraft/world/level/tile/entity/HopperTileEntity.h index 7ea27c8cd..34ea01306 100644 --- a/minecraft/Minecraft.World/net/minecraft/world/level/tile/entity/HopperTileEntity.h +++ b/minecraft/Minecraft.World/net/minecraft/world/level/tile/entity/HopperTileEntity.h @@ -14,7 +14,7 @@ public: static const int MOVE_ITEM_SPEED = 8; private: - arrayWithLength> items; + std::vector> items; std::wstring name; int cooldownTime; diff --git a/minecraft/java/include/java/Arrays.h b/minecraft/java/include/java/Arrays.h index c317afde3..cc0d88ba3 100644 --- a/minecraft/java/include/java/Arrays.h +++ b/minecraft/java/include/java/Arrays.h @@ -4,39 +4,39 @@ class Arrays { public: - static void fill(doubleArray arr, unsigned int from, unsigned int to, + static void fill(std::vector& arr, unsigned int from, unsigned int to, double value) { assert(from >= 0); assert(from <= to); - assert(to <= arr.length); - std::fill(arr.data + from, arr.data + to, value); + assert(to <= arr.size()); + std::fill(arr.data() + from, arr.data() + to, value); } - static void fill(floatArray arr, unsigned int from, unsigned int to, + static void fill(std::vector& arr, unsigned int from, unsigned int to, float value) { assert(from >= 0); assert(from <= to); - assert(to <= arr.length); - std::fill(arr.data + from, arr.data + to, value); + assert(to <= arr.size()); + std::fill(arr.data() + from, arr.data() + to, value); } - static void fill(BiomeArray arr, unsigned int from, unsigned int to, + static void fill(std::vector& arr, unsigned int from, unsigned int to, Biome* value) { assert(from >= 0); assert(from <= to); - assert(to <= arr.length); - std::fill(arr.data + from, arr.data + to, value); + assert(to <= arr.size()); + std::fill(arr.data() + from, arr.data() + to, value); } - static void fill(byteArray arr, unsigned int from, unsigned int to, + static void fill(std::vector& arr, unsigned int from, unsigned int to, uint8_t value) { assert(from >= 0); assert(from <= to); - assert(to <= arr.length); - std::fill(arr.data + from, arr.data + to, value); + assert(to <= arr.size()); + std::fill(arr.data() + from, arr.data() + to, value); } - static void fill(byteArray arr, uint8_t value) { - std::fill(arr.data, arr.data + arr.length, value); + static void fill(std::vector& arr, uint8_t value) { + std::fill(arr.data(), arr.data() + arr.size(), value); } }; diff --git a/minecraft/java/include/java/ByteBuffer.h b/minecraft/java/include/java/ByteBuffer.h index ab4311d42..532f466dd 100644 --- a/minecraft/java/include/java/ByteBuffer.h +++ b/minecraft/java/include/java/ByteBuffer.h @@ -20,7 +20,7 @@ public: ByteBuffer(unsigned int capacity, uint8_t* backingArray); virtual ~ByteBuffer(); - static ByteBuffer* wrap(byteArray& b); + static ByteBuffer* wrap(std::vector& b); static ByteBuffer* allocate(unsigned int capacity); void order(ByteOrder a); ByteBuffer* flip(); @@ -28,19 +28,19 @@ public: int getSize(); int getInt(); int getInt(unsigned int index); - void get(byteArray) {} // 4J - TODO + void get(std::vector) {} // 4J - TODO uint8_t get(int index); int64_t getLong(); short getShort(); - void getShortArray(shortArray& s); + void getShortArray(std::vector& s); ByteBuffer* put(int index, uint8_t b); ByteBuffer* putInt(int value); ByteBuffer* putInt(unsigned int index, int value); ByteBuffer* putShort(short value); - ByteBuffer* putShortArray(shortArray& s); + ByteBuffer* putShortArray(std::vector& s); ByteBuffer* putLong(int64_t value); - ByteBuffer* put(byteArray inputArray); - byteArray array(); + ByteBuffer* put(std::vector& inputArray); + std::vector array(); IntBuffer* asIntBuffer(); FloatBuffer* asFloatBuffer(); }; diff --git a/minecraft/java/include/java/FloatBuffer.h b/minecraft/java/include/java/FloatBuffer.h index cbe3ae1af..05e6a2b05 100644 --- a/minecraft/java/include/java/FloatBuffer.h +++ b/minecraft/java/include/java/FloatBuffer.h @@ -13,6 +13,6 @@ public: FloatBuffer* flip(); FloatBuffer* put(float f); - void get(arrayWithLength* dst); + void get(std::vector* dst); float* _getDataPointer() { return buffer; } }; \ No newline at end of file diff --git a/minecraft/java/include/java/InputOutputStream/BufferedOutputStream.h b/minecraft/java/include/java/InputOutputStream/BufferedOutputStream.h index 642711ed4..5d39bab29 100644 --- a/minecraft/java/include/java/InputOutputStream/BufferedOutputStream.h +++ b/minecraft/java/include/java/InputOutputStream/BufferedOutputStream.h @@ -8,7 +8,7 @@ private: OutputStream* stream; protected: - byteArray buf; // The internal buffer where data is stored. + std::vector buf; // The internal buffer where data is stored. unsigned int count; // The number of valid bytes in the buffer. public: @@ -17,7 +17,7 @@ public: virtual void flush(); virtual void close(); - virtual void write(byteArray b, unsigned int offset, unsigned int length); - virtual void write(byteArray b); + virtual void write(const std::vector& b, unsigned int offset, unsigned int length); + virtual void write(const std::vector& b); virtual void write(unsigned int b); }; \ No newline at end of file diff --git a/minecraft/java/include/java/InputOutputStream/ByteArrayInputStream.h b/minecraft/java/include/java/InputOutputStream/ByteArrayInputStream.h index 8b72e692b..467286eee 100644 --- a/minecraft/java/include/java/InputOutputStream/ByteArrayInputStream.h +++ b/minecraft/java/include/java/InputOutputStream/ByteArrayInputStream.h @@ -6,7 +6,7 @@ class ByteArrayInputStream : public InputStream { protected: - byteArray buf; // An array of bytes that was provided by the creator of the + std::vector buf; // An array of bytes that was provided by the creator of the // stream. unsigned int count; // The index one greater than the last valid character // in the input stream buffer. @@ -15,20 +15,20 @@ protected: // stream buffer. public: - ByteArrayInputStream(byteArray buf, unsigned int offset, + ByteArrayInputStream(std::vector& buf, unsigned int offset, unsigned int length); - ByteArrayInputStream(byteArray buf); + ByteArrayInputStream(std::vector& buf); virtual ~ByteArrayInputStream(); virtual int read(); - virtual int read(byteArray b); - virtual int read(byteArray b, unsigned int offset, unsigned int length); + virtual int read(std::vector& b); + virtual int read(std::vector& b, unsigned int offset, unsigned int length); virtual void close(); virtual int64_t skip(int64_t n); // 4J Stu Added - Sometimes we don't want to delete the data on destroying // this void reset() { - buf = byteArray(); + buf = std::vector(); count = 0; mark = 0; pos = 0; diff --git a/minecraft/java/include/java/InputOutputStream/ByteArrayOutputStream.h b/minecraft/java/include/java/InputOutputStream/ByteArrayOutputStream.h index d2c57887c..7871b34b9 100644 --- a/minecraft/java/include/java/InputOutputStream/ByteArrayOutputStream.h +++ b/minecraft/java/include/java/InputOutputStream/ByteArrayOutputStream.h @@ -4,10 +4,10 @@ #include "../../../../Minecraft.World/ConsoleHelpers/ArrayWithLength.h" // 4jcraft TODO class ByteArrayOutputStream : public OutputStream { - // Note - when actually implementing, byteArray will need to grow as data is + // Note - when actually implementing, std::vector will need to grow as data is // written public: - byteArray buf; // The buffer where data is stored. + std::vector buf; // The buffer where data is stored. protected: unsigned int count; // The number of valid bytes in the buffer. @@ -19,10 +19,10 @@ public: virtual void flush() {} virtual void write(unsigned int b); - virtual void write(byteArray b); - virtual void write(byteArray b, unsigned int offset, unsigned int length); + virtual void write(const std::vector& b); + virtual void write(const std::vector& b, unsigned int offset, unsigned int length); virtual void close(); - virtual byteArray toByteArray(); + virtual std::vector toByteArray(); void reset() { count = 0; } unsigned int size() { return count; } diff --git a/minecraft/java/include/java/InputOutputStream/DataInput.h b/minecraft/java/include/java/InputOutputStream/DataInput.h index cdc30ec87..dd7c46ca1 100644 --- a/minecraft/java/include/java/InputOutputStream/DataInput.h +++ b/minecraft/java/include/java/InputOutputStream/DataInput.h @@ -5,12 +5,12 @@ class DataInput { public: virtual int read() = 0; - virtual int read(byteArray b) = 0; - virtual int read(byteArray b, unsigned int offset, unsigned int length) = 0; + virtual int read(std::vector& b) = 0; + virtual int read(std::vector& b, unsigned int offset, unsigned int length) = 0; virtual bool readBoolean() = 0; virtual uint8_t readByte() = 0; virtual unsigned char readUnsignedByte() = 0; - virtual bool readFully(byteArray a) = 0; + virtual bool readFully(std::vector& a) = 0; virtual double readDouble() = 0; virtual float readFloat() = 0; virtual int readInt() = 0; diff --git a/minecraft/java/include/java/InputOutputStream/DataInputStream.h b/minecraft/java/include/java/InputOutputStream/DataInputStream.h index 981a10a68..c1ee1ed00 100644 --- a/minecraft/java/include/java/InputOutputStream/DataInputStream.h +++ b/minecraft/java/include/java/InputOutputStream/DataInputStream.h @@ -16,15 +16,15 @@ private: public: DataInputStream(InputStream* in); virtual int read(); - virtual int read(byteArray b); - virtual int read(byteArray b, unsigned int offset, unsigned int length); + virtual int read(std::vector& b); + virtual int read(std::vector& b, unsigned int offset, unsigned int length); virtual void close(); virtual bool readBoolean(); virtual uint8_t readByte(); virtual unsigned char readUnsignedByte(); virtual wchar_t readChar(); - virtual bool readFully(byteArray b); - virtual bool readFully(charArray b); + virtual bool readFully(std::vector& b); + virtual bool readFully(std::vector& b); virtual double readDouble(); virtual float readFloat(); virtual int readInt(); diff --git a/minecraft/java/include/java/InputOutputStream/DataOutput.h b/minecraft/java/include/java/InputOutputStream/DataOutput.h index 76973c02f..8071f4a25 100644 --- a/minecraft/java/include/java/InputOutputStream/DataOutput.h +++ b/minecraft/java/include/java/InputOutputStream/DataOutput.h @@ -5,8 +5,8 @@ class DataOutput { public: virtual void write(unsigned int b) = 0; - virtual void write(byteArray b) = 0; - virtual void write(byteArray b, unsigned int offset, + virtual void write(const std::vector& b) = 0; + virtual void write(const std::vector& b, unsigned int offset, unsigned int length) = 0; virtual void writeByte(uint8_t a) = 0; virtual void writeDouble(double a) = 0; diff --git a/minecraft/java/include/java/InputOutputStream/DataOutputStream.h b/minecraft/java/include/java/InputOutputStream/DataOutputStream.h index ccf6fc23c..6b93c7aef 100644 --- a/minecraft/java/include/java/InputOutputStream/DataOutputStream.h +++ b/minecraft/java/include/java/InputOutputStream/DataOutputStream.h @@ -25,8 +25,8 @@ public: void deleteChildStream(); virtual void write(unsigned int b); - virtual void write(byteArray b); - virtual void write(byteArray b, unsigned int offset, unsigned int length); + virtual void write(const std::vector& b); + virtual void write(const std::vector& b, unsigned int offset, unsigned int length); virtual void close(); virtual void writeByte(uint8_t a); virtual void writeDouble(double a); diff --git a/minecraft/java/include/java/InputOutputStream/FileInputStream.h b/minecraft/java/include/java/InputOutputStream/FileInputStream.h index bee8741be..7e41996ab 100644 --- a/minecraft/java/include/java/InputOutputStream/FileInputStream.h +++ b/minecraft/java/include/java/InputOutputStream/FileInputStream.h @@ -15,8 +15,8 @@ public: FileInputStream(const File& file); virtual ~FileInputStream(); virtual int read(); - virtual int read(byteArray b); - virtual int read(byteArray b, unsigned int offset, unsigned int length); + virtual int read(std::vector& b); + virtual int read(std::vector& b, unsigned int offset, unsigned int length); virtual void close(); virtual int64_t skip(int64_t n); diff --git a/minecraft/java/include/java/InputOutputStream/FileOutputStream.h b/minecraft/java/include/java/InputOutputStream/FileOutputStream.h index 7ddeab7d8..1ceb3cbc1 100644 --- a/minecraft/java/include/java/InputOutputStream/FileOutputStream.h +++ b/minecraft/java/include/java/InputOutputStream/FileOutputStream.h @@ -14,8 +14,8 @@ public: FileOutputStream(const File& file); virtual ~FileOutputStream(); virtual void write(unsigned int b); - virtual void write(byteArray b); - virtual void write(byteArray b, unsigned int offset, unsigned int length); + virtual void write(const std::vector& b); + virtual void write(const std::vector& b, unsigned int offset, unsigned int length); virtual void close(); virtual void flush(); diff --git a/minecraft/java/include/java/InputOutputStream/GZIPInputStream.h b/minecraft/java/include/java/InputOutputStream/GZIPInputStream.h index 6a75ccae9..0c5887d39 100644 --- a/minecraft/java/include/java/InputOutputStream/GZIPInputStream.h +++ b/minecraft/java/include/java/InputOutputStream/GZIPInputStream.h @@ -15,8 +15,8 @@ private: public: GZIPInputStream(InputStream* out) : stream(out) {}; virtual int read() { return stream->read(); }; - virtual int read(byteArray b) { return stream->read(b); }; - virtual int read(byteArray b, unsigned int offset, unsigned int length) { + virtual int read(std::vector& b) { return stream->read(b); }; + virtual int read(std::vector& b, unsigned int offset, unsigned int length) { return stream->read(b, offset, length); }; virtual void close() { return stream->close(); }; diff --git a/minecraft/java/include/java/InputOutputStream/GZIPOutputStream.h b/minecraft/java/include/java/InputOutputStream/GZIPOutputStream.h index 8454f492c..64bd9d814 100644 --- a/minecraft/java/include/java/InputOutputStream/GZIPOutputStream.h +++ b/minecraft/java/include/java/InputOutputStream/GZIPOutputStream.h @@ -13,8 +13,8 @@ private: public: GZIPOutputStream(OutputStream* out) : stream(out) {}; virtual void write(unsigned int b) { stream->write(b); }; - virtual void write(byteArray b) { stream->write(b); }; - virtual void write(byteArray b, unsigned int offset, unsigned int length) { + virtual void write(const std::vector& b) { stream->write(b); }; + virtual void write(const std::vector& b, unsigned int offset, unsigned int length) { stream->write(b, offset, length); }; virtual void close() { stream->close(); }; diff --git a/minecraft/java/include/java/InputOutputStream/InputStream.h b/minecraft/java/include/java/InputOutputStream/InputStream.h index a42f18e97..c10940f91 100644 --- a/minecraft/java/include/java/InputOutputStream/InputStream.h +++ b/minecraft/java/include/java/InputOutputStream/InputStream.h @@ -12,8 +12,8 @@ public: virtual ~InputStream() {} virtual int read() = 0; - virtual int read(byteArray b) = 0; - virtual int read(byteArray b, unsigned int offset, unsigned int length) = 0; + virtual int read(std::vector& b) = 0; + virtual int read(std::vector& b, unsigned int offset, unsigned int length) = 0; virtual void close() = 0; virtual int64_t skip(int64_t n) = 0; diff --git a/minecraft/java/include/java/InputOutputStream/OutputStream.h b/minecraft/java/include/java/InputOutputStream/OutputStream.h index abf8ff483..78435a7a4 100644 --- a/minecraft/java/include/java/InputOutputStream/OutputStream.h +++ b/minecraft/java/include/java/InputOutputStream/OutputStream.h @@ -9,8 +9,8 @@ public: virtual ~OutputStream() {} virtual void write(unsigned int b) = 0; - virtual void write(byteArray b) = 0; - virtual void write(byteArray b, unsigned int offset, + virtual void write(const std::vector& b) = 0; + virtual void write(const std::vector& b, unsigned int offset, unsigned int length) = 0; virtual void close() = 0; virtual void flush() = 0; diff --git a/minecraft/java/include/java/IntBuffer.h b/minecraft/java/include/java/IntBuffer.h index baed526bc..24aa80185 100644 --- a/minecraft/java/include/java/IntBuffer.h +++ b/minecraft/java/include/java/IntBuffer.h @@ -16,8 +16,8 @@ public: virtual IntBuffer* flip(); int get(unsigned int index); int* getBuffer(); - IntBuffer* put(intArray* inputArray, unsigned int offset, + IntBuffer* put(std::vector* inputArray, unsigned int offset, unsigned int length); - IntBuffer* put(intArray inputArray); + IntBuffer* put(std::vector& inputArray); IntBuffer* put(int i); }; \ No newline at end of file diff --git a/minecraft/java/include/java/System.h b/minecraft/java/include/java/System.h index f2dc95ab0..c840c9419 100644 --- a/minecraft/java/include/java/System.h +++ b/minecraft/java/include/java/System.h @@ -1,24 +1,28 @@ #pragma once #include +#include +#include +#include +#include #include "../../../Minecraft.World/ConsoleHelpers/ArrayWithLength.h" // 4jcraft TODO // 4J Jev, just thought it would be easier this way. -#define ArrayCopyFunctionDeclaration(x) \ - static void arraycopy(arrayWithLength src, unsigned int srcPos, \ - arrayWithLength* dst, unsigned int dstPos, \ +#define ArrayCopyFunctionDeclaration(x) \ + static void arraycopy(const std::vector& src, unsigned int srcPos, \ + std::vector* dst, unsigned int dstPos, \ unsigned int length); -#define ArrayCopyFunctionDefinition(x) \ - void System::arraycopy(arrayWithLength src, unsigned int srcPos, \ - arrayWithLength* dst, unsigned int dstPos, \ - unsigned int length) { \ - arraycopy(src, srcPos, dst, dstPos, length); \ +#define ArrayCopyFunctionDefinition(x) \ + void System::arraycopy(const std::vector& src, unsigned int srcPos, \ + std::vector* dst, unsigned int dstPos, \ + unsigned int length) { \ + arraycopy(src, srcPos, dst, dstPos, length); \ } class System { template - static void arraycopy(arrayWithLength src, unsigned int srcPos, - arrayWithLength* dst, unsigned int dstPos, + static void arraycopy(const std::vector& src, unsigned int srcPos, + std::vector* dst, unsigned int dstPos, unsigned int length); public: diff --git a/minecraft/java/src/ByteBuffer.cpp b/minecraft/java/src/ByteBuffer.cpp index 8151b67a0..8da4c0d3c 100644 --- a/minecraft/java/src/ByteBuffer.cpp +++ b/minecraft/java/src/ByteBuffer.cpp @@ -36,7 +36,7 @@ ByteBuffer::~ByteBuffer() { // Wraps a byte array into a buffer. // The new buffer will be backed by the given uint8_t array; that is, // modifications to the buffer will cause the array to be modified and vice -// versa. The new buffer's capacity and limit will be array.length, its position +// versa. The new buffer's capacity and limit will be array.size(), its position // will be zero, and its mark will be undefined. Its backing array will be the // given array, and its array offset will be zero. // @@ -44,8 +44,8 @@ ByteBuffer::~ByteBuffer() { // array - The array that will back this buffer // Returns: // The new byte buffer -ByteBuffer* ByteBuffer::wrap(byteArray& b) { - return new ByteBuffer(b.length, b.data); +ByteBuffer* ByteBuffer::wrap(std::vector& b) { + return new ByteBuffer(b.size(), b.data()); } // Allocates a new byte buffer. @@ -211,13 +211,13 @@ short ByteBuffer::getShort() { return value; } -void ByteBuffer::getShortArray(shortArray& s) { +void ByteBuffer::getShortArray(std::vector& s) { // TODO 4J Stu - Should this function be writing from the start of the // buffer, or from position? And should it update position? - assert(s.length >= m_limit / 2); + assert(s.size() >= m_limit / 2); // 4J Stu - Assumes big endian - memcpy(s.data, buffer, (m_limit - m_position)); + memcpy(s.data(), buffer, (m_limit - m_position)); } // Absolute put method (optional operation). @@ -320,13 +320,13 @@ ByteBuffer* ByteBuffer::putShort(short value) { return this; } -ByteBuffer* ByteBuffer::putShortArray(shortArray& s) { +ByteBuffer* ByteBuffer::putShortArray(std::vector& s) { // TODO 4J Stu - Should this function be writing from the start of the // buffer, or from position? And should it update position? - assert(s.length * 2 <= m_limit); + assert(s.size() * 2 <= m_limit); // 4J Stu - Assumes big endian - memcpy(buffer, s.data, s.length * 2); + memcpy(buffer, s.data(), s.size() * 2); return this; } @@ -371,22 +371,22 @@ ByteBuffer* ByteBuffer::putLong(int64_t value) { // this buffer. An invocation of this method of the form dst.put(a) behaves in // exactly the same way as the invocation // -// dst.put(a, 0, a.length) +// dst.put(a, 0, a.size()) // Returns: // This buffer -ByteBuffer* ByteBuffer::put(byteArray inputArray) { - if (inputArray.length > remaining()) +ByteBuffer* ByteBuffer::put(std::vector& inputArray) { + if (inputArray.size() > remaining()) assert(false); // TODO 4J Stu - Some kind of exception? - std::copy(inputArray.data, inputArray.data + inputArray.length, + std::copy(inputArray.data(), inputArray.data() + inputArray.size(), buffer + m_position); - m_position += inputArray.length; + m_position += inputArray.size(); return this; } -byteArray ByteBuffer::array() { return byteArray(buffer, m_capacity); } +std::vector ByteBuffer::array() { return std::vector(buffer, buffer + m_capacity); } // Creates a view of this byte buffer as an int buffer. // The content of the new buffer will start at this buffer's current position. diff --git a/minecraft/java/src/File.cpp b/minecraft/java/src/File.cpp index f3b54958e..d627aea4b 100644 --- a/minecraft/java/src/File.cpp +++ b/minecraft/java/src/File.cpp @@ -4,8 +4,8 @@ #include "java/FileFilter.h" #include "java/File.h" -#include "../../../Minecraft.World/ConsoleHelpers/PathHelper.h" // 4jcraft TODO -#include "../../../Minecraft.World/ConsoleHelpers/StringHelpers.h" // 4jcraft TODO +#include "../../Minecraft.World/ConsoleHelpers/PathHelper.h" // 4jcraft TODO +#include "../../Minecraft.World/ConsoleHelpers/StringHelpers.h" // 4jcraft TODO const wchar_t File::pathSeparator = L'/'; diff --git a/minecraft/java/src/FloatBuffer.cpp b/minecraft/java/src/FloatBuffer.cpp index cc827d751..4e22783df 100644 --- a/minecraft/java/src/FloatBuffer.cpp +++ b/minecraft/java/src/FloatBuffer.cpp @@ -51,11 +51,11 @@ FloatBuffer* FloatBuffer::put(float f) { // array. An invocation of this method of the form src.get(a) behaves in exactly // the same way as the invocation // -// src.get(a, 0, a.length) +// src.get(a, 0, a.size()) // Returns: // This buffer -void FloatBuffer::get(floatArray* dst) { - assert(dst->length <= m_capacity); +void FloatBuffer::get(std::vector* dst) { + assert(dst->size() <= m_capacity); - for (unsigned int i = 0; i < dst->length; i++) dst->data[i] = buffer[i]; + for (unsigned int i = 0; i < dst->size(); i++) (*dst)[i] = buffer[i]; } \ No newline at end of file diff --git a/minecraft/java/src/InputOutputStream/BufferedOutputStream.cpp b/minecraft/java/src/InputOutputStream/BufferedOutputStream.cpp index 8d22850a4..2d5657cbd 100644 --- a/minecraft/java/src/InputOutputStream/BufferedOutputStream.cpp +++ b/minecraft/java/src/InputOutputStream/BufferedOutputStream.cpp @@ -5,7 +5,7 @@ // the underlying output stream. size - the buffer size. BufferedOutputStream::BufferedOutputStream(OutputStream* out, int size) { stream = out; - buf = byteArray(size); + buf = std::vector(size); count = 0; } @@ -14,7 +14,6 @@ BufferedOutputStream::~BufferedOutputStream() { // TODO: ArrayWithLength.h doesnt have a destructor. // this wouldnt need to be done manually. // but for some reason the destructor is commented out in the source code? - delete[] buf.data; } // Flushes this buffered output stream. This forces any buffered output bytes to @@ -61,11 +60,11 @@ void BufferedOutputStream::close() { // b - the data. // off - the start offset in the data. // len - the number of bytes to write. -void BufferedOutputStream::write(byteArray b, unsigned int offset, +void BufferedOutputStream::write(const std::vector& b, unsigned int offset, unsigned int length) { // Over the length of what we can store in our buffer - just flush the // buffer and output directly - if (length >= buf.length) { + if (length >= buf.size()) { flush(); stream->write(b, offset, length); } else { @@ -75,13 +74,13 @@ void BufferedOutputStream::write(byteArray b, unsigned int offset, } } -// Writes b.length bytes to this output stream. +// Writes b.size() bytes to this output stream. // The write method of FilterOutputStream calls its write method of three -// arguments with the arguments b, 0, and b.length. +// arguments with the arguments b, 0, and b.size(). // // Note that this method does not call the one-argument write method of its // underlying stream with the single argument b. -void BufferedOutputStream::write(byteArray b) { write(b, 0, b.length); } +void BufferedOutputStream::write(const std::vector& b) { write(b, 0, b.size()); } // Writes the specified byte to this buffered output stream. // Overrides: @@ -90,7 +89,7 @@ void BufferedOutputStream::write(byteArray b) { write(b, 0, b.length); } // b - the byte to be written. void BufferedOutputStream::write(unsigned int b) { buf[count++] = (uint8_t)b; - if (count == buf.length) { + if (count == buf.size()) { flush(); } } diff --git a/minecraft/java/src/InputOutputStream/ByteArrayInputStream.cpp b/minecraft/java/src/InputOutputStream/ByteArrayInputStream.cpp index 63a49487b..9e9d833d7 100644 --- a/minecraft/java/src/InputOutputStream/ByteArrayInputStream.cpp +++ b/minecraft/java/src/InputOutputStream/ByteArrayInputStream.cpp @@ -2,21 +2,21 @@ // Creates ByteArrayInputStream that uses buf as its buffer array. The initial // value of pos is offset and the initial value of count is the minimum of -// offset+length and buf.length. The buffer array is not copied. The buffer's +// offset+length and buf.size(). The buffer array is not copied. The buffer's // mark is set to the specified offset. Parameters: buf - the input buffer. // offset - the offset in the buffer of the first byte to read. // length - the maximum number of bytes to read from the buffer. -ByteArrayInputStream::ByteArrayInputStream(byteArray buf, unsigned int offset, +ByteArrayInputStream::ByteArrayInputStream(std::vector& buf, unsigned int offset, unsigned int length) - : pos(offset), count(std::min(offset + length, buf.length)), mark(offset) { + : pos(offset), count(std::min(offset + length, (unsigned int)buf.size())), mark(offset) { this->buf = buf; } // Creates a ByteArrayInputStream so that it uses buf as its buffer array. The // buffer array is not copied. The initial value of pos is 0 and the initial // value of count is the length of buf. Parameters: buf - the input buffer. -ByteArrayInputStream::ByteArrayInputStream(byteArray buf) - : pos(0), count(buf.length), mark(0) { +ByteArrayInputStream::ByteArrayInputStream(std::vector& buf) + : pos(0), count(buf.size()), mark(0) { this->buf = buf; } @@ -43,17 +43,17 @@ int ByteArrayInputStream::read() { // The first byte read is stored into element b[0], the next one into b[1], and // so on. The number of bytes read is, at most, equal to the length of b. Let k // be the number of bytes actually read; these bytes will be stored in elements -// b[0] through b[k-1], leaving elements b[k] through b[b.length-1] unaffected. +// b[0] through b[k-1], leaving elements b[k] through b[b.size()-1] unaffected. // // The read(b) method for class InputStream has the same effect as: // -// read(b, 0, b.length) +// read(b, 0, b.size()) // Parameters: // b - the buffer into which the data is read. // Returns: // the total number of bytes read into the buffer, or -1 is there is no more // data because the end of the stream has been reached. -int ByteArrayInputStream::read(byteArray b) { return read(b, 0, b.length); } +int ByteArrayInputStream::read(std::vector& b) { return read(b, 0, b.size()); } // Reads up to len bytes of data into an array of bytes from this input stream. // If pos equals count, then -1 is returned to indicate end of file. Otherwise, @@ -68,7 +68,7 @@ int ByteArrayInputStream::read(byteArray b) { return read(b, 0, b.length); } // Returns: // the total number of bytes read into the buffer, or -1 if there is no more // data because the end of the stream has been reached. -int ByteArrayInputStream::read(byteArray b, unsigned int offset, +int ByteArrayInputStream::read(std::vector& b, unsigned int offset, unsigned int length) { if (pos == count) return -1; @@ -105,5 +105,4 @@ int64_t ByteArrayInputStream::skip(int64_t n) { } ByteArrayInputStream::~ByteArrayInputStream() { - if (buf.data != nullptr) delete[] buf.data; } diff --git a/minecraft/java/src/InputOutputStream/ByteArrayOutputStream.cpp b/minecraft/java/src/InputOutputStream/ByteArrayOutputStream.cpp index 0fe530c4a..ff19d469c 100644 --- a/minecraft/java/src/InputOutputStream/ByteArrayOutputStream.cpp +++ b/minecraft/java/src/InputOutputStream/ByteArrayOutputStream.cpp @@ -4,18 +4,17 @@ // bytes, though its size increases if necessary. ByteArrayOutputStream::ByteArrayOutputStream() { count = 0; - buf = byteArray(32); + buf = std::vector(32); } // Creates a new byte array output stream, with a buffer capacity of the // specified size, in bytes. Parameters: size - the initial size. ByteArrayOutputStream::ByteArrayOutputStream(unsigned int size) { count = 0; - buf = byteArray(size); + buf = std::vector(size); } ByteArrayOutputStream::~ByteArrayOutputStream() { - if (buf.data != nullptr) delete[] buf.data; } // Writes the specified byte to this byte array output stream. @@ -23,27 +22,27 @@ ByteArrayOutputStream::~ByteArrayOutputStream() { // b - the byte to be written. void ByteArrayOutputStream::write(unsigned int b) { // If we will fill the buffer we need to make it bigger - if (count + 1 >= buf.length) buf.resize(buf.length * 2); + if (count + 1 >= buf.size()) buf.resize(buf.size() * 2); buf[count] = (uint8_t)b; count++; } -// Writes b.length bytes from the specified byte array to this output stream. +// Writes b.size() bytes from the specified byte array to this output stream. // The general contract for write(b) is that it should have exactly the same -// effect as the call write(b, 0, b.length). -void ByteArrayOutputStream::write(byteArray b) { write(b, 0, b.length); } +// effect as the call write(b, 0, b.size()). +void ByteArrayOutputStream::write(const std::vector& b) { write(b, 0, b.size()); } // Writes len bytes from the specified byte array starting at offset off to this // byte array output stream. Parameters: b - the data. off - the start offset in // the data. len - the number of bytes to write. -void ByteArrayOutputStream::write(byteArray b, unsigned int offset, +void ByteArrayOutputStream::write(const std::vector& b, unsigned int offset, unsigned int length) { - assert(b.length >= offset + length); + assert(b.size() >= offset + length); // If we will fill the buffer we need to make it bigger - if (count + length >= buf.length) - buf.resize(std::max(count + length + 1, buf.length * 2)); + if (count + length >= buf.size()) + buf.resize(std::max(count + length + 1, (unsigned int)(buf.size() * 2))); std::memcpy(&buf[count], &b[offset], length); // std::copy( b->data+offset, b->data+offset+length, buf->data + count ); // @@ -61,8 +60,8 @@ void ByteArrayOutputStream::close() {} // output stream and the valid contents of the buffer have been copied into it. // Returns: // the current contents of this output stream, as a byte array. -byteArray ByteArrayOutputStream::toByteArray() { - byteArray out(count); - memcpy(out.data, buf.data, count); +std::vector ByteArrayOutputStream::toByteArray() { + std::vector out(count); + memcpy(out.data(), buf.data(), count); return out; } \ No newline at end of file diff --git a/minecraft/java/src/InputOutputStream/DataInputStream.cpp b/minecraft/java/src/InputOutputStream/DataInputStream.cpp index 316cfaf7a..ccf52e35c 100644 --- a/minecraft/java/src/InputOutputStream/DataInputStream.cpp +++ b/minecraft/java/src/InputOutputStream/DataInputStream.cpp @@ -36,11 +36,11 @@ int DataInputStream::read() { // The first byte read is stored into element b[0], the next one into b[1], and // so on. The number of bytes read is, at most, equal to the length of b. Let k // be the number of bytes actually read; these bytes will be stored in elements -// b[0] through b[k-1], leaving elements b[k] through b[b.length-1] unaffected. +// b[0] through b[k-1], leaving elements b[k] through b[b.size()-1] unaffected. // // The read(b) method has the same effect as: // -// read(b, 0, b.length) +// read(b, 0, b.size()) // // Overrides: // read in class FilterInputStream @@ -49,14 +49,14 @@ int DataInputStream::read() { // Returns: // the total number of bytes read into the buffer, or -1 if there is no more // data because the end of the stream has been reached. -int DataInputStream::read(byteArray b) { +int DataInputStream::read(std::vector& b) { if (stream == nullptr) { fprintf(stderr, - "DataInputStream::read(byteArray) called but underlying stream is " + "DataInputStream::read(std::vector) called but underlying stream is " "nullptr\n"); return -1; } - return read(b, 0, b.length); + return read(b, 0, b.size()); } // Reads up to len bytes of data from the contained input stream into an array @@ -77,7 +77,7 @@ int DataInputStream::read(byteArray b) { // b[off+len-1] unaffected. // // In every case, elements b[0] through b[off] and elements b[off+len] through -// b[b.length-1] are unaffected. +// b[b.size()-1] are unaffected. // // Overrides: // read in class FilterInputStream @@ -88,11 +88,11 @@ int DataInputStream::read(byteArray b) { // Returns: // the total number of bytes read into the buffer, or -1 if there is no more // data because the end of the stream has been reached. -int DataInputStream::read(byteArray b, unsigned int offset, +int DataInputStream::read(std::vector& b, unsigned int offset, unsigned int length) { if (stream == nullptr) { fprintf(stderr, - "DataInputStream::read(byteArray,offset,length) called but " + "DataInputStream::read(std::vector,offset,length) called but " "underlying stream is nullptr\n"); return -1; } @@ -168,10 +168,10 @@ wchar_t DataInputStream::readChar() { // b. The number of bytes read is equal to the length of b. This method blocks // until one of the following conditions occurs: // -// b.length bytes of input data are available, in which case a normal return is +// b.size() bytes of input data are available, in which case a normal return is // made. End of file is detected, in which case an EOFException is thrown. An // I/O error occurs, in which case an IOException other than EOFException is -// thrown. If b is null, a NullPointerException is thrown. If b.length is zero, +// thrown. If b is null, a NullPointerException is thrown. If b.size() is zero, // then no bytes are read. Otherwise, the first byte read is stored into element // b[0], the next one into b[1], and so on. If an exception is thrown from this // method, then it may be that some but not all bytes of b have been updated @@ -179,18 +179,18 @@ wchar_t DataInputStream::readChar() { // // Parameters: // b - the buffer into which the data is read. -bool DataInputStream::readFully(byteArray b) { +bool DataInputStream::readFully(std::vector& b) { // TODO 4J Stu - I am not entirely sure if this matches the implementation // of the Java library // TODO 4J Stu - Need to handle exceptions here is we throw them in other // InputStreams if (stream == nullptr) { fprintf(stderr, - "DataInputStream::readFully(byteArray) but underlying stream is " + "DataInputStream::readFully(std::vector) but underlying stream is " "nullptr\n"); return false; } - for (unsigned int i = 0; i < b.length; i++) { + for (unsigned int i = 0; i < b.size(); i++) { int byteRead = stream->read(); if (byteRead == -1) { return false; @@ -201,18 +201,18 @@ bool DataInputStream::readFully(byteArray b) { return true; } -bool DataInputStream::readFully(charArray b) { +bool DataInputStream::readFully(std::vector& b) { // TODO 4J Stu - I am not entirely sure if this matches the implementation // of the Java library // TODO 4J Stu - Need to handle exceptions here is we throw them in other // InputStreams if (stream == nullptr) { fprintf(stderr, - "DataInputStream::readFully(charArray) but underlying stream is " + "DataInputStream::readFully(std::vector) but underlying stream is " "nullptr\n"); return false; } - for (unsigned int i = 0; i < b.length; i++) { + for (unsigned int i = 0; i < b.size(); i++) { int byteRead = stream->read(); if (byteRead == -1) { return false; diff --git a/minecraft/java/src/InputOutputStream/DataOutputStream.cpp b/minecraft/java/src/InputOutputStream/DataOutputStream.cpp index 1d27b45e1..1c80338b2 100644 --- a/minecraft/java/src/InputOutputStream/DataOutputStream.cpp +++ b/minecraft/java/src/InputOutputStream/DataOutputStream.cpp @@ -40,20 +40,20 @@ void DataOutputStream::flush() { stream->flush(); } -// Writes b.length bytes from the specified byte array to this output stream. +// Writes b.size() bytes from the specified byte array to this output stream. // The general contract for write(b) is that it should have exactly the same -// effect as the call write(b, 0, b.length). Parameters: b - the data. -void DataOutputStream::write(byteArray b) { write(b, 0, b.length); } +// effect as the call write(b, 0, b.size()). Parameters: b - the data. +void DataOutputStream::write(const std::vector& b) { write(b, 0, b.size()); } // Writes len bytes from the specified byte array starting at offset off to the // underlying output stream. If no exception is thrown, the counter written is // incremented by len. Parameters: b - the data. off - the start offset in the // data. len - the number of bytes to write. -void DataOutputStream::write(byteArray b, unsigned int offset, +void DataOutputStream::write(const std::vector& b, unsigned int offset, unsigned int length) { if (stream == nullptr) { fprintf(stderr, - "DataOutputStream::write(byteArray,...) called but underlying " + "DataOutputStream::write(std::vector,...) called but underlying " "stream is nullptr\n"); return; } @@ -224,7 +224,7 @@ void DataOutputStream::writeUTF(const std::wstring& str) { // throw new UTFDataFormatException( // "encoded string too long: " + utflen + " bytes"); - byteArray bytearr(utflen + 2); + std::vector bytearr(utflen + 2); bytearr[count++] = (uint8_t)((utflen >> 8) & 0xFF); bytearr[count++] = (uint8_t)((utflen >> 0) & 0xFF); @@ -251,7 +251,6 @@ void DataOutputStream::writeUTF(const std::wstring& str) { } } write(bytearr, 0, utflen + 2); - delete[] bytearr.data; } // 4J Added diff --git a/minecraft/java/src/InputOutputStream/FileInputStream.cpp b/minecraft/java/src/InputOutputStream/FileInputStream.cpp index c4b9d7dfd..12c74e654 100644 --- a/minecraft/java/src/InputOutputStream/FileInputStream.cpp +++ b/minecraft/java/src/InputOutputStream/FileInputStream.cpp @@ -80,18 +80,18 @@ int FileInputStream::read() { return static_cast(byteRead); } -// Reads up to b.length bytes of data from this input stream into an array of +// Reads up to b.size() bytes of data from this input stream into an array of // bytes. This method blocks until some input is available. Parameters: b - the // buffer into which the data is read. Returns: the total number of bytes read // into the buffer, or -1 if there is no more data because the end of the file // has been reached. -int FileInputStream::read(byteArray b) { +int FileInputStream::read(std::vector& b) { if (m_fileHandle == nullptr) { return -1; } const size_t numberOfBytesRead = - std::fread(b.data, 1, b.length, m_fileHandle); + std::fread(b.data(), 1, b.size(), m_fileHandle); if (std::ferror(m_fileHandle) != 0) { assert(0); @@ -110,10 +110,10 @@ int FileInputStream::read(byteArray b) { // b len - the maximum number of bytes read. Returns: the total number of bytes // read into the buffer, or -1 if there is no more data because the end of the // file has been reached. -int FileInputStream::read(byteArray b, unsigned int offset, +int FileInputStream::read(std::vector& b, unsigned int offset, unsigned int length) { // 4J Stu - We don't want to read any more than the array buffer can hold - assert(length <= (b.length - offset)); + assert(length <= (b.size() - offset)); if (m_fileHandle == nullptr) { return -1; diff --git a/minecraft/java/src/InputOutputStream/FileOutputStream.cpp b/minecraft/java/src/InputOutputStream/FileOutputStream.cpp index 23294e1eb..fd986d264 100644 --- a/minecraft/java/src/InputOutputStream/FileOutputStream.cpp +++ b/minecraft/java/src/InputOutputStream/FileOutputStream.cpp @@ -58,20 +58,20 @@ void FileOutputStream::write(unsigned int b) { } } -// Writes b.length bytes from the specified byte array to this file output +// Writes b.size() bytes from the specified byte array to this file output // stream. Parameters: b - the data. -void FileOutputStream::write(byteArray b) { +void FileOutputStream::write(const std::vector& b) { if (m_fileHandle == nullptr) { return; } const size_t numberOfBytesWritten = - std::fwrite(b.data, 1, b.length, m_fileHandle); + std::fwrite(b.data(), 1, b.size(), m_fileHandle); const int result = std::ferror(m_fileHandle); if (result != 0) { // TODO 4J Stu - Some kind of error handling - } else if (numberOfBytesWritten == 0 || numberOfBytesWritten != b.length) { + } else if (numberOfBytesWritten == 0 || numberOfBytesWritten != b.size()) { // File pointer is past the end of the file } } @@ -79,10 +79,10 @@ void FileOutputStream::write(byteArray b) { // Writes len bytes from the specified byte array starting at offset off to this // file output stream. Parameters: b - the data. off - the start offset in the // data. len - the number of bytes to write. -void FileOutputStream::write(byteArray b, unsigned int offset, +void FileOutputStream::write(const std::vector& b, unsigned int offset, unsigned int length) { // 4J Stu - We don't want to write any more than the array buffer holds - assert(length <= (b.length - offset)); + assert(length <= (b.size() - offset)); if (m_fileHandle == nullptr) { return; diff --git a/minecraft/java/src/IntBuffer.cpp b/minecraft/java/src/IntBuffer.cpp index 15b90caaa..b96570be0 100644 --- a/minecraft/java/src/IntBuffer.cpp +++ b/minecraft/java/src/IntBuffer.cpp @@ -64,14 +64,14 @@ int IntBuffer::get(unsigned int index) { // except that it first checks that there is sufficient space in this buffer and // it is potentially much more efficient. Parameters: src - The array from which // ints are to be read offset - The offset within the array of the first int to -// be read; must be non-negative and no larger than array.length length - The +// be read; must be non-negative and no larger than array.size() length - The // number of ints to be read from the given array; must be non-negative and no -// larger than array.length - offset Returns: This buffer -IntBuffer* IntBuffer::put(intArray* inputArray, unsigned int offset, +// larger than array.size() - offset Returns: This buffer +IntBuffer* IntBuffer::put(std::vector* inputArray, unsigned int offset, unsigned int length) { - assert(offset + length < inputArray->length); + assert(offset + length < inputArray->size()); - std::copy(inputArray->data + offset, inputArray->data + offset + length, + std::copy(inputArray->data() + offset, inputArray->data() + offset + length, buffer + m_position); m_position += length; @@ -79,14 +79,14 @@ IntBuffer* IntBuffer::put(intArray* inputArray, unsigned int offset, return this; } -IntBuffer* IntBuffer::put(intArray inputArray) { - if (inputArray.length > remaining()) +IntBuffer* IntBuffer::put(std::vector& inputArray) { + if (inputArray.size() > remaining()) assert(false); // TODO 4J Stu - Some kind of exception? - std::copy(inputArray.data, inputArray.data + inputArray.length, + std::copy(inputArray.data(), inputArray.data() + inputArray.size(), buffer + m_position); - m_position += inputArray.length; + m_position += inputArray.size(); return this; } diff --git a/minecraft/java/src/system.cpp b/minecraft/java/src/system.cpp index 5bd9b30d0..6bd41260f 100644 --- a/minecraft/java/src/system.cpp +++ b/minecraft/java/src/system.cpp @@ -7,37 +7,37 @@ #include "java/System.h" template -void System::arraycopy(arrayWithLength src, unsigned int srcPos, - arrayWithLength* dst, unsigned int dstPos, +void System::arraycopy(const std::vector& src, unsigned int srcPos, + std::vector* dst, unsigned int dstPos, unsigned int length) { - assert(srcPos >= 0 && srcPos <= src.length); - assert(srcPos + length <= src.length); - assert(dstPos + length <= dst->length); + assert(srcPos >= 0 && srcPos <= src.size()); + assert(srcPos + length <= src.size()); + assert(dstPos + length <= dst->size()); - std::copy(src.data + srcPos, src.data + srcPos + length, - dst->data + dstPos); + std::copy(src.data() + srcPos, src.data() + srcPos + length, + dst->data() + dstPos); } ArrayCopyFunctionDefinition(Node*) ArrayCopyFunctionDefinition(Biome*) - void System::arraycopy(arrayWithLength src, unsigned int srcPos, - arrayWithLength* dst, unsigned int dstPos, + void System::arraycopy(const std::vector& src, unsigned int srcPos, + std::vector* dst, unsigned int dstPos, unsigned int length) { - assert(srcPos >= 0 && srcPos <= src.length); - assert(srcPos + length <= src.length); - assert(dstPos + length <= dst->length); + assert(srcPos >= 0 && srcPos <= src.size()); + assert(srcPos + length <= src.size()); + assert(dstPos + length <= dst->size()); - memcpy(dst->data + dstPos, src.data + srcPos, length); + memcpy(dst->data() + dstPos, src.data() + srcPos, length); } -void System::arraycopy(arrayWithLength src, unsigned int srcPos, - arrayWithLength* dst, unsigned int dstPos, +void System::arraycopy(const std::vector& src, unsigned int srcPos, + std::vector* dst, unsigned int dstPos, unsigned int length) { - assert(srcPos >= 0 && srcPos <= src.length); - assert(srcPos + length <= src.length); - assert(dstPos + length <= dst->length); + assert(srcPos >= 0 && srcPos <= src.size()); + assert(srcPos + length <= src.size()); + assert(dstPos + length <= dst->size()); - memcpy(dst->data + dstPos, src.data + srcPos, length * sizeof(int)); + memcpy(dst->data() + dstPos, src.data() + srcPos, length * sizeof(int)); } // TODO 4J Stu - These time functions may suffer from accuracy and we might have diff --git a/minecraft/nbt/include/nbt/ByteArrayTag.h b/minecraft/nbt/include/nbt/ByteArrayTag.h index 27aa6f08c..67793e8ff 100644 --- a/minecraft/nbt/include/nbt/ByteArrayTag.h +++ b/minecraft/nbt/include/nbt/ByteArrayTag.h @@ -4,29 +4,27 @@ class ByteArrayTag : public Tag { public: - byteArray data; + std::vector data; bool m_ownData; ByteArrayTag(const std::wstring& name) : Tag(name) { m_ownData = false; } - ByteArrayTag(const std::wstring& name, byteArray data, bool ownData = false) + ByteArrayTag(const std::wstring& name, std::vector& data, bool ownData = false) : Tag(name) { this->data = data; m_ownData = ownData; } // 4J - added ownData param ~ByteArrayTag() { - if (m_ownData) delete[] data.data; } void write(DataOutput* dos) { - dos->writeInt(data.length); + dos->writeInt(data.size()); dos->write(data); } void load(DataInput* dis, int tagDepth) { int length = dis->readInt(); - if (data.data) delete[] data.data; - data = byteArray(length); + data = std::vector(length); dis->readFully(data); } @@ -34,23 +32,23 @@ public: std::wstring toString() { static wchar_t buf[32]; - swprintf(buf, 32, L"[%d bytes]", data.length); + swprintf(buf, 32, L"[%d bytes]", data.size()); return std::wstring(buf); } bool equals(Tag* obj) { if (Tag::equals(obj)) { ByteArrayTag* o = (ByteArrayTag*)obj; - return ((data.data == nullptr && o->data.data == nullptr) || - (data.data != nullptr && data.length == o->data.length && - memcmp(data.data, o->data.data, data.length) == 0)); + return ((data.empty() && o->data.empty()) || + (!data.empty() && data.size() == o->data.size() && + memcmp(data.data(), o->data.data(), data.size()) == 0)); } return false; } Tag* copy() { - byteArray cp = byteArray(data.length); - System::arraycopy(data, 0, &cp, 0, data.length); + std::vector cp(data.size()); + std::copy(data.begin(), data.end(), cp.begin()); return new ByteArrayTag(getName(), cp, true); } }; \ No newline at end of file diff --git a/minecraft/nbt/include/nbt/CompoundTag.h b/minecraft/nbt/include/nbt/CompoundTag.h index 0e8587d0a..919e4c7a6 100644 --- a/minecraft/nbt/include/nbt/CompoundTag.h +++ b/minecraft/nbt/include/nbt/CompoundTag.h @@ -93,11 +93,11 @@ public: tags[name] = (new StringTag(name, value)); } - void putByteArray(const std::wstring& name, byteArray value) { + void putByteArray(const std::wstring& name, std::vector& value) { tags[name] = (new ByteArrayTag(name, value)); } - void putIntArray(const std::wstring& name, intArray value) { + void putIntArray(const std::wstring& name, std::vector& value) { tags[name] = (new IntArrayTag(name, value)); } @@ -154,13 +154,13 @@ public: return ((StringTag*)tags[name])->data; } - byteArray getByteArray(const std::wstring& name) { - if (tags.find(name) == tags.end()) return byteArray(); + std::vector getByteArray(const std::wstring& name) { + if (tags.find(name) == tags.end()) return std::vector(); return ((ByteArrayTag*)tags[name])->data; } - intArray getIntArray(const std::wstring& name) { - if (tags.find(name) == tags.end()) return intArray(); + std::vector getIntArray(const std::wstring& name) { + if (tags.find(name) == tags.end()) return std::vector(); return ((IntArrayTag*)tags[name])->data; } diff --git a/minecraft/nbt/include/nbt/IntArrayTag.h b/minecraft/nbt/include/nbt/IntArrayTag.h index 2658f399d..540fba711 100644 --- a/minecraft/nbt/include/nbt/IntArrayTag.h +++ b/minecraft/nbt/include/nbt/IntArrayTag.h @@ -5,19 +5,18 @@ class IntArrayTag : public Tag { public: - intArray data; + std::vector data; - IntArrayTag(const std::wstring& name) : Tag(name) { data = intArray(); } + IntArrayTag(const std::wstring& name) : Tag(name) { data = std::vector(); } - IntArrayTag(const std::wstring& name, intArray data) : Tag(name) { + IntArrayTag(const std::wstring& name, const std::vector& data) : Tag(name) { this->data = data; } - ~IntArrayTag() { delete[] data.data; } void write(DataOutput* dos) { - dos->writeInt(data.length); - for (unsigned int i = 0; i < data.length; i++) { + dos->writeInt(data.size()); + for (unsigned int i = 0; i < data.size(); i++) { dos->writeInt(data[i]); } } @@ -25,8 +24,7 @@ public: void load(DataInput* dis, int tagDepth) { int length = dis->readInt(); - if (data.data) delete[] data.data; - data = intArray(length); + data = std::vector(length); for (int i = 0; i < length; i++) { data[i] = dis->readInt(); } @@ -36,24 +34,24 @@ public: std::wstring toString() { static wchar_t buf[32]; - swprintf(buf, 32, L"[%d bytes]", data.length); + swprintf(buf, 32, L"[%d bytes]", data.size()); return std::wstring(buf); } bool equals(Tag* obj) { if (Tag::equals(obj)) { IntArrayTag* o = (IntArrayTag*)obj; - return ((data.data == nullptr && o->data.data == nullptr) || - (data.data != nullptr && data.length == o->data.length && - memcmp(data.data, o->data.data, - data.length * sizeof(int)) == 0)); + return ((data.empty() && o->data.empty()) || + (!data.empty() && data.size() == o->data.size() && + memcmp(data.data(), o->data.data(), + data.size() * sizeof(int)) == 0)); } return false; } Tag* copy() { - intArray cp = intArray(data.length); - System::arraycopy(data, 0, &cp, 0, data.length); + std::vector cp(data.size()); + std::copy(data.begin(), data.end(), cp.begin()); return new IntArrayTag(getName(), cp); } }; \ No newline at end of file diff --git a/minecraft/nbt/include/nbt/NbtIo.h b/minecraft/nbt/include/nbt/NbtIo.h index e335a19bc..bc9d40a83 100644 --- a/minecraft/nbt/include/nbt/NbtIo.h +++ b/minecraft/nbt/include/nbt/NbtIo.h @@ -8,8 +8,8 @@ class NbtIo { public: static CompoundTag* readCompressed(InputStream* in); static void writeCompressed(CompoundTag* tag, OutputStream* out); - static CompoundTag* decompress(byteArray buffer); - static byteArray compress(CompoundTag* tag); + static CompoundTag* decompress(std::vector buffer); + static std::vector compress(CompoundTag* tag); static CompoundTag* read(DataInput* dis); static void write(CompoundTag* tag, DataOutput* dos); }; diff --git a/minecraft/nbt/src/NbtIo.cpp b/minecraft/nbt/src/NbtIo.cpp index c26c76aa9..8ee8d0c67 100644 --- a/minecraft/nbt/src/NbtIo.cpp +++ b/minecraft/nbt/src/NbtIo.cpp @@ -25,7 +25,7 @@ void NbtIo::writeCompressed(CompoundTag* tag, OutputStream* out) { // Reads tags from a stream created from the input buffer. Doesn't free the data // in the source buffer. -CompoundTag* NbtIo::decompress(byteArray buffer) { +CompoundTag* NbtIo::decompress(std::vector buffer) { ByteArrayInputStream bais = ByteArrayInputStream(buffer); // 4J - this was using a try/finally block DataInputStream in = @@ -37,15 +37,15 @@ CompoundTag* NbtIo::decompress(byteArray buffer) { return ret; } -byteArray NbtIo::compress(CompoundTag* tag) { +std::vector NbtIo::compress(CompoundTag* tag) { // 4J - this was using a try/finally block ByteArrayOutputStream baos = ByteArrayOutputStream(); DataOutputStream dos = DataOutputStream(&baos); // 4J - was new GZIPOutputStream as well NbtIo::write(tag, &dos); - byteArray ret(baos.buf.length); - System::arraycopy(baos.buf, 0, &ret, 0, baos.buf.length); + std::vector ret(baos.buf.size()); + System::arraycopy(baos.buf, 0, &ret, 0, baos.buf.size()); dos.close(); return ret; } diff --git a/minecraft/nbt/src/Tag.cpp b/minecraft/nbt/src/Tag.cpp index ab2264f4d..e5aca594a 100644 --- a/minecraft/nbt/src/Tag.cpp +++ b/minecraft/nbt/src/Tag.cpp @@ -91,7 +91,7 @@ void Tag::writeNamedTag(Tag* tag, DataOutput* dos) { if (tag->getId() == Tag::TAG_End) return; // byte[] bytes = tag.getName().getBytes("UTF-8"); - // dos.writeShort(bytes.length); + // dos.writeShort(bytes.size()); // dos.write(bytes); dos->writeUTF(tag->getName());