glua / gm_voxelate

A module for voxel support in Garry's Mod
https://glua.io
Other
21 stars 3 forks source link

the infinite world can of worms #3

Closed SwadicalRag closed 7 years ago

SwadicalRag commented 7 years ago

seasonal greetings from glua.team!

With the hiatus gone, and development well underway on voxelate, I feel that it is important that we talk about how to tackle an arbitrary, infinite world with gm_voxelate.

In the past, we've been avoiding this due to the sheer complexity of introducing an infinite or arbitrary world system into a game like Garry's Mod that uses a static, limited world size (which, frankly, is quite tiny!).

However, now that an infinite world is definitely on our to do list, it is time to open that can of worms. So, how do we do it?

In the past we’ve seen some pure Lua implementations (and I’ve made one before too, before shortly giving up on my efforts) that divide the world into chunks and repeat a central chunk serverside and create an illusion of an infinite world clientside. This was one of our considerations for gm_voxelate, but from personal experience I heavily disagree.

The world repeater

Pros


My proposal: our own world system

Now, now it seems like packaging our own physics engine and writing the logic to a world management system may be too hard, but I feel that this is the right way to go.

Firstly and importantly, we won’t have to go through the worry of figuring out how to interface with some of gmod’s shittiest libraries. Given that we’re already including a binary module both clientside AND serverside, I think that it’s only appropriate that we use the binary module’s capabilities to its fullest and include whatever libraries we need, rather than depending on or hacking a shitty one within gmod.

So, summarised:

Pros

In the next few posts I’ll outline some concepts and ideas that we’ll have to take into account when designing this system.

-- SWAD OUT

ghost commented 7 years ago

I agree

-- FOOTSIES OUT

meepen commented 7 years ago

Have u tried not

On May 6, 2017 6:28 AM, "WansonSwanson" notifications@github.com wrote:

I agree

-- FOOTSIES OUT

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/glua/gm_voxelate/issues/3#issuecomment-299630595, or mute the thread https://github.com/notifications/unsubscribe-auth/AF5lSU_9jMREUId8f-a35jhldSLLvc-tks5r3EtpgaJpZM4NStN5 .

SwadicalRag commented 7 years ago

good night meep

SwadicalRag commented 7 years ago

we need to roll our own physics engine and after careful consideration, ReactPhysics3D seemed like the best minimal library that we could use for a voxel based world.

it uses double precision floats internally, so we shouldn't have an issue with lack of precision (according to wikipedia, we lose all decimal precision at 2^52=4,503,599,627,370,496). We can set a safe world limit of perhaps 32 million (or even 2^31 for convenience!) blocks in each direction?

Thus, we should be able to use a 3 dimensional int32 hashmap to store voxel data.

To reduce memory usage, we'll only load all the entities' current chunks and surrounding chunks (in a 1 chunk radius around the entity) into the physics engine in the form of a single mesh in a static rigid body.

As entities move around and exit chunks, unused chunk rigid bodies will be destroyed in the physics engine

SwadicalRag commented 7 years ago

see #4 for the ReactPhysics3D integration

SwadicalRag commented 7 years ago

Arbitrary units and axes

FIRST THINGS FIRST, I'M A REALIST X/Y = horizontal Z = vertical idk why minecraft chooses Y to be vertical

ReactPhysics3D doesn't really enforce any units onto us, so we can say that 1 unit in the physics engine instance will be equivalent to 1 metre. I suppose we can then designate each block to be 1m x 1m x 1m = 1m^3

Players are 0.5m x 0.5m x 1.8 m?

SwadicalRag commented 7 years ago

Should we use meshes or spam a shit tonne of boxes?

// Half extents of the box in the x, y and z directions 
const rp3d::Vector3 halfExtents(2.0, 3.0, 5.0); 

// Create the box shape 
const rp3d::BoxShape boxShape(halfExtents);
mcd1992 commented 7 years ago

Whatever has better perf.

SwadicalRag commented 7 years ago

i think generating a mesh for a million cubes would have a worse performance impact than just generating a million cubes

bmwalters commented 7 years ago

Wait, if we lose compatibility with everything that already exists in the GMod ecosystem, what's the point of building this for GMod? I think we should try to maintain as much compat as possible. I want to be able to spawn a vortigaunt in the voxel world and kill it with voxel world physics.

SwadicalRag commented 7 years ago

too hard and impractical: gmod is filled with shitty APIs, and the engine is ancient so we'll have to deal with float precision errors if we use the existing APIs

I think this project is a good opportunity to truly see what we can do with binary modules.

We're obviously still using the source engine renderer but we're overhauling physics, world Management and entities

Why remain chained to old legacy APIs? WE ARE BETTER THAN THAT! Go further! Explore the true possibilities of programming!

seize the means of production!

bmwalters commented 7 years ago

maybe we could develop a compatibility layer when this gets off the ground or a recompiler or something

SwadicalRag commented 7 years ago

but it's virtually impossible, gmod uses floats for position, but we're using doubles

MDFL64 commented 7 years ago

I'm okay with going off the deep end for huge worlds, but I would like to maintain some kind of compatibility for small worlds.

SwadicalRag commented 7 years ago

Of course, we'll only just turning the Voxels entity into a World entity which has its own sub entity system

SwadicalRag commented 7 years ago

we're*

MDFL64 commented 7 years ago

Honestly I see huge issues with both methods, so I'll go ahead and post my analysis. Overall the world repeater thing should be easier to do with voxels than in vanilla gmod, IMO.

Whatever implementation we end up going with, huge worlds will break compatibility with other mods. If we eventually want to regain some amount of compatibility, your method is probably the way to go. I just want to reinforce that it's gonna be hard. Which I don't have a problem with. I attempt the impossible on a fairly regular basis, and I usually fail, but I have absolutely no problem with giving it another go.

Kefta commented 7 years ago

Source entity limit is 8192 for networked entities. Implementing your own system in this case would be a lot smarter, or making a block manager entity for groups of blocks since Source doesn't handle large amounts of entities in small clusters very well

SwadicalRag commented 7 years ago

yup, I've had personal experience with how shitty source engine handles large amounts of entities (see @xaviergmail ) and it's not pleasant

I'm still against map repeating. It's still hacky: gmod vectors use floats iirc :/

I'm more than happy designing our own entity system. This project is also a test as to how far we can take the source engine and fuck some shit up

Kefta commented 7 years ago

Source vectors do use Valve's 16-bit floats 🤢

SwadicalRag commented 7 years ago

holy shit ha ha hahaha that makes so much sense as to why my traces kept fucking up in my old infinite world implementation

Ok there is no way I'm agreeing to this

SwadicalRag commented 7 years ago

sorry :b:arakeet

Kefta commented 7 years ago

Also, vector:IsValid() in the C++ will fail if the vector goes out of world bounds (default -16000 something, +16000)

SwadicalRag commented 7 years ago

rip

MDFL64 commented 7 years ago

Source vectors do use Valve's 16-bit floats 🤢

wait what the shit

SwadicalRag commented 7 years ago

@Kefta are you sure? wikipedia says 16 bit floats lose decimal precision at 2048

Precision limitations on other decimal values

    Decimals between 2 and 4: fixed interval 2−9
    Decimals between 4 and 8: fixed interval 2−8
    Decimals between 8 and 16: fixed interval 2−7
    Decimals between 16 and 32: fixed interval 2−6
    Decimals between 32 and 64: fixed interval 2−5
    Decimals between 64 and 128: fixed interval 2−4
    Decimals between 128 and 256: fixed interval 2−3
    Decimals between 256 and 512: fixed interval 2−2
    Decimals between 512 and 1024: fixed interval 2−1
    Decimals between 1024 and 2048: fixed interval 20

Precision limitations on integer values

    Integers between 0 and 2048 can be exactly represented
    Integers between 2049 and 4096 round to a multiple of 2 (even number)
    Integers between 4097 and 8192 round to a multiple of 4
    Integers between 8193 and 16384 round to a multiple of 8
    Integers between 16385 and 32768 round to a multiple of 16
    Integers between 32769 and 65503 round to a multiple of 32
    Integers equal to or above 65504 are rounded to "infinity".[8]
Kefta commented 7 years ago

Meepen was the one who mentioned 16 bit floats a few months back somewhere -- I can't find Valve's limits.h. I just know vectors use floats.

SwadicalRag commented 7 years ago

well that's a piss poor decision by valve then :/

SpencerSharkey commented 7 years ago

scale everything else down

SwadicalRag commented 7 years ago

precision, mein friend

SwadicalRag commented 7 years ago

16 bit floats have 3-4 decimals of precision which is pathetic

SpencerSharkey commented 7 years ago

jokes. full cl-localized world is only viable option for inf worlds

how hard is it to make entity management for minecraft seriously and networking

SwadicalRag commented 7 years ago

@SpencerSharkey shouldn't be too hard now that we have a FUNCTIONAL NETWORKING SYSTEM ™️