Lodestone.Common
Loading...
Searching...
No Matches
PalletizedStorage.h
Go to the documentation of this file.
1//
2// Created by DexrnZacAttack on 11/27/25 using zPc-i2.
3//
4#ifndef LODESTONE_PALLETIZEDSTORAGE_H
5#define LODESTONE_PALLETIZEDSTORAGE_H
7#include <cstdint>
8#include <vector>
9#include <stdexcept>
10
11#include <algorithm>
12#include <vector>
16#include <cstring>
17#include <array>
18#include <Lodestone.Threading/Threading.h>
19#include THREADING_HEADER
20
22 // thanks danil for allowing us to port your code
23 // modified slightly to allow for any arbitrary object to be stored
24 // also based off of https://www.longor.net/articles/voxel-palette-compression-reddit
25 template <typename T>
27 public:
28 struct PaletteEntry {
31 };
32
33 explicit PalletizedStorage(int capacity);
34 explicit PalletizedStorage(int capacity, T fillWith);
35
36 void setValue(int index, T value);
37 T getCopy(int index) const;
38
39 void fill(T value);
40
41 const T &getValue(int index) const;
42
43 size_t getIndicesSize() const noexcept;
44
45 // allows for getting the object reference but not write to it (since writing will modify ALL instances, because indexes will point to that one object)
46 const T &operator[](int index) const;
47
48 std::string toString() const override {
49 return std::string("PalletizedStorage{")
50 + "capacity=" + std::to_string(m_capacity)
51 + ", paletteSize=" + std::to_string(m_paletteSize)
52 + ", indiceCount=" + std::to_string(m_indices.size());
53 };
54 protected:
55 int getPaletteIndex(int index) const;
56 void setPaletteIndex(int index, int value);
57
59 void resize();
60 private:
61 // todo do we want array pool?
62 std::vector<uint8_t> m_indices;
63 std::vector<PaletteEntry> m_palette;
64
65 const int m_capacity;
67 int m_indexBits = 1;
68 };
69
71}
73#endif // LODESTONE_PALLETIZEDSTORAGE_H
int getPaletteIndex(int index) const
Definition PalletizedStorage.h:95
int m_paletteSize
Definition PalletizedStorage.h:66
void fill(T value)
Definition PalletizedStorage.h:82
const T & getValue(int index) const
Definition PalletizedStorage.h:67
size_t getIndicesSize() const noexcept
Definition PalletizedStorage.h:72
int m_indexBits
Definition PalletizedStorage.h:67
const int m_capacity
Definition PalletizedStorage.h:65
T getCopy(int index) const
Definition PalletizedStorage.h:62
int obtainPaletteEntry()
Definition PalletizedStorage.h:164
void setPaletteIndex(int index, int value)
Definition PalletizedStorage.h:121
void setValue(int index, T value)
Definition PalletizedStorage.h:21
std::vector< uint8_t > m_indices
Definition PalletizedStorage.h:62
void resize()
Definition PalletizedStorage.h:174
std::vector< PaletteEntry > m_palette
Definition PalletizedStorage.h:63
std::string toString() const override
Definition PalletizedStorage.h:48
PalletizedStorage(int capacity)
Definition PalletizedStorage.h:11
Java toString clone.
Definition StringSerializable.h:13
Definition PalletizedStorage.h:21