Jump to content

  • Log In with Google      Sign In   
  • Create Account


Member Since 01 Sep 2011
Offline Last Active Yesterday, 03:04 PM

Topics I've Started

Modifying entities and sending updates

04 September 2014 - 02:46 PM

I've run into an issue where I'm now creating entities on a different thread than the one that handles sending out entity network updates, which leads to concurrency issues, and I'm not sure what direction to take to fix it. Previously only the main thread ever created entities and it was also the thread that handled sending the updates out. But now the terrain generation is creating entities (trees, in this case) and the terrain generation runs on separate threads. What happens is that the update system tries to enumerate the components of the entity while the entity is still being constructed. I'm using an entity-component system by the way.

I could set up a system of locking an entity while it's being created/modified, but since creating an entity isn't a 1 step process, every place in the code where "new Entity" appears (meaning every entity "class"), I'd have to throw in some kind of a "entity.StartUpdate/EndUpdate" pair. If anyone ever forgets to do that... well that's an ugly bug just waiting to happen. I'd prefer a more centralized solution that isn't so easy to screw up.

The other option I see is to require entity creation only occur on the main thread. I'm not sure if a restriction like that is a good idea or not. I couldn't find anything useful on google, so I've no idea what the usual design is for such a system.

Pathfinding for large units

17 June 2014 - 07:52 PM

I'm not entirely sure if this is the right section for this, but here's my problem: I have a 3D voxel world, similar to minecraft, and I'm using A* to do pathfinding for the NPCs. Since the world is laid out in a grid of blocks, I use that same grid for the pathfinding nodes. When the AI follows the path, for units wider than a single grid unit, it gets stuck a lot of times.

The first issue it has is when it comes to a ledge that it needs to drop down from, as shown in my crappy drawing:
Attached File  diagram.png   11.72KB   4 downloads

The AI gets to the node above the ledge, but can't fall down to the next 3 nodes without moving forwards more.

The other issue is things like doorways, where its physically impossible for the unit to go through due to the size. It would need the pathfinder to path around and find another, larger, opening.

I've tried a bit to make the A* pathfinding work for larger units but the code quickly became a mess and each node check started to require checking a good 15 or so surrounding nodes. Is this the right way to go about it or is there a better solution? Keep in mind its a dynamic world, so precomputed solutions won't work.

Client loading entities

12 June 2014 - 12:58 PM

Suppose you have a large, seamless transition world that's not all kept loaded in memory at the same time. When a player enters a previously unloaded region, the server loads it up and then can easily send out the data to any players nearby upon completion. But how do you deal with players that move into that area after it's already loaded up. They need to have the data sent to them saying what to load and where. And you don't want to waste network bandwidth by constantly sending everyone "create X entity" messages when they already have those entities loaded. So what's the solution to this?

Packet combining

23 May 2014 - 09:05 PM

How do games usually handle having a bunch of different packets to send out in a single tick?

Suppose you have:
- 5 entities that have moved
- 3 entities that have started playing a new animation
- 6 new particle systems created (or rather 6 events that will create particle systems and sounds, etc)
- 2 new effects (as in the poison, heal, etc) applied to an entity (which is more than just a particle system, its also an icon to display on the UI)

Would any of those packets be combined into one to reduce overhead? If so, how? Do you combine all of the same type? Combine everything? Combine as many as you can until a certain size limit? What would the size limit be?

Suppose only some of those packets need to be sent to player A and some to player B (with some being sent to both). How does that affect the combining?

By the way, I'm using the lidgren networking library, in case that's important.

Issue combining matrix components

23 April 2014 - 07:59 PM

Previously I was multiplying 2 matrices together to do my bone transformations, but now I've broken the matrices down into scale, rotation, translation components. My goal is to work with the component parts so I can perform proper lerping and then combine the final result into a matrix to send off to the GPU. I'm having a problem combining things in this form though.

This is what I did previously: C = A * B. Where those are all matrices. That worked fine. Now what I'm doing is:
C.rotation = A.rotation * B.rotation;
C.translation = A.translation + B.translation;
C.scale = A.scale * B.scale;

Rotation is a quaternion, translation and scale are vector3s. When I combine these 3 components of C into a matrix again: Matrix.Scaling(Scale) * Matrix.RotationQuaternion(Rotation) * Matrix.Translation(Translation) the result is wrong, and my model looks like a collapsed blob.

I'm not sure if this matters, but the original info coming from the model file is a matrix, so I have to decompose the matrix into the 3 component parts on load, which I then store and use for these calculations.

Anyone know what I'm doing wrong here?