0
\$\begingroup\$

I am working on a voxel game similar to Minecraft. The goal would be to handle more entities but also offer a more immersive experience by the fact that the player does not need to worry about loading chunks. What is a way to handle unloaded entities? I plan to keep chunks near the player "awake" and performing a full simulation. However, I cannot do this for distant chunks, it would require too much computing power. I was thinking about discretizing some of the entity behavior, but this appears to become very complicated once there are too many possible interactions. Imagine a furnace processing ores, which in turn go into a chest, and a golem moves items from that chest into some other container. The simulation could probably be simplified the more distant from the player it is, but obviously I want to avoid anything that could lead to item duplication. Are there any elegant solutions to this problem?

\$\endgroup\$
6
  • \$\begingroup\$ You may be interested in Designing persistence in an ECS world subdivided into chunks. There are also some relevant techniques discussed in this question about Factorio-like sim games. Ultimately, the amount you can simplify these background calculations depends on the complexity of your mechanics. If your mechanics are Turing complete (a surprisingly low bar to hit in games!) then there may be no guaranteed way to achieve the same net result without simulating every tick. \$\endgroup\$ Commented Nov 28, 2023 at 18:47
  • \$\begingroup\$ @DMGregory thanks for your response. Including more complex things, I wish to reimplement redstone, which is Turing complete. \$\endgroup\$ Commented Nov 29, 2023 at 11:55
  • \$\begingroup\$ Multithreading is usually the answer when you want to avoid loading screens or hide the loading artifacts from the player \$\endgroup\$ Commented Nov 30, 2023 at 13:11
  • \$\begingroup\$ An elegant solution may not be a fast solution. That depends on how you define elegant (for example, we could ask "Elegant from whose perspective? Developer? Player?") Are you primarily concerned with performance? \$\endgroup\$ Commented Nov 30, 2023 at 22:42
  • \$\begingroup\$ @Engineer, yes fast and working well. in modded minecraft, the player is sometimes painfully reminded about the limitations when he has to choose which chunks are loaded. factorio on the other hand makes everything seamless \$\endgroup\$ Commented Dec 19, 2023 at 19:39

1 Answer 1

2
\$\begingroup\$

One technique you can use to optimize things like crop growth or furnace smelting in a Minecraft-like game is to, rather than have a loop that goes through all of them and updates them in accordance with the current time every frame, to just store the time they were created.

For example, for the furnace you can just store the items in the furnace, and the time at which the smelting started. And then, whenever the furnace is accessed next, calculate how many of the items should have been smelted by subtracting the stored start time from the current time. 0 (or close to 0) computation is required for all the intermittent time.

A similar technique can be applied to crop growth. Calculate their age on the fly as needed instead of manually updating them constantly.

\$\endgroup\$
1
  • \$\begingroup\$ @user253751 The only catch I see is how one could make the furnace use the dark texture instead of the fire one once the smelting is complete. What if I sent the current game time into the uniforms of the shader, and the creation time of the object with the quad-specific uniforms somehow, and then selected the appropriate texture in the vertex shader? No branching would be required because I could just add the boolean to the array index if I am using an array texture. Another potential advantage of that is not having to rebuild the chunk mesh every time a block 'updates' in this manner. \$\endgroup\$ Commented Dec 2, 2023 at 18:00

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.