Help with "Spreadsheet"
I am making a 3D game. For this game, I need an efficient way to store and access block data. I want to be able to
- find any block at specified z coord,
- get all blocks of same type,
- get average coord for block in chunk,
stuff like that. I have an idea for this, but I'm not sure if it would work for primitive types. As the title suggests, I thought of a spreadsheet. Separate columns (or lists) of each variable, and each row makes up an Object. A cell should automatically update when the row's value is changed, and the row's value should be changed when the cell is changed. I know this is easy for non-primitive types, but I am getting confused on primitives. And, if the variable is set in one of them instead of updated, it wouldn't propogate to the other and the link would be broken. (sorry if I am not using right terms, new to java). I think reflection can do this, but I have no clue how to do it. Please help?
41 Replies
⌛
This post has been reserved for your question.
Hey @The Typhothanian! Please useTIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here./close
or theClose Post
button above when your problem is solved. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.
Also, it needs to be usable for more than blocks
pls
Do you want to load all at once?
What are you referring to by "load"?
all your blocks
Like, go through them all at once?
Do you have all blocks in memory?
No, using 32^3 chunks
I would have a spreadsheet for each chunk
ok I wouldn't use spreadsheets first of all but a custom format
And I would be using these spreadsheets for other stuff
Okay
What would be a good solution?
you could e.g. use one file per chunk or store N chunks in a file together
for simplicity, assume one chunk per file
No, I have a system for storing in a file, I want a system for storing in memory
oh
just use an array of block objects?
That's why I thought of a sheet
what do you mean with spreadsheet?
Well, looking for all blocks of specific type, for example would take a while
Give me a minute I am working on smthn else rn
btw reflection doesn't help with the issues you mentioned (propagating) but setters or similar can help
Are your coordinates integers or floating point values?
i.e. can you have a block at coordinates like 1.25
ints
So, here's an example
I assume you often need to be able to find blocks by their coordinates?
yes
Why do you want to use spreadsheets?
Each row would form a Block instance, and I would need to be able to find any blocks at x=1, etc.
just use a 3D array
Like I said, I would have to iterate through up to 3072 blocks, that's inefficient on large scales
And the spreadsheet thing is just an analogy
What is the fraction of empty vs filled blocks?
Any
how sparse are your blocks typically?
Underground chunks would be full, air chunks would be empty
Density decreases as y increases
What's the fraction of underground blocks vs air?
oh so it's complete chunks that are empty typically?
something like 2 air for 1 underground
Yeah, they can either be completely full or completely empty
So, I think arrays would be inneficient for air chunks
so like 1/3 is blocks and 1/3 is airs? Then arrays are likely the best choice for storing
and you can store copies for efficient access of other things
hmm
then only use arrays for non air chunks
But what if I wanted to set all grass blocks in a chunk to stone?
without iterating through all 3072
that's what I meant with copies
Ok, I'll just go the easy way and encapsulate primitives in a wrapper class
Ok
thank you
If you are finished with your post, please close it.
If you are not, please ignore this message.
Note that you will not be able to send further messages here after this post have been closed but you will be able to create new posts.
Post Closed
This post has been closed by <@801145088830210129>.