blurite / rsprot

RSProt is an all-in-one networking package for RuneScape Private Servers, primarily targeted at the OldSchool scene.
MIT License
27 stars 5 forks source link

World Entities #13

Closed Z-Kris closed 3 months ago

Z-Kris commented 3 months ago

World entities are a new concept introduced with revision 222. These are a way to make sailing function,

[!NOTE] This is all theoretical documentation as do not yet have access to see the actual implementation on OldSchools side. Furthermore, there is a very good chance the design may change in future revisions, as the current implementation is not particularly efficient.

Concept

World entities are effectively smaller variants of the root game world, backed by the instancing system. The server has the ability to allocate a specific piece of existing static map and place it into the root world. The intended use case here, with sailing, is to have maps which strictly only contain a boat - however many locs that may consist of. The server will then make an instance of that boat area and turn it into a world entity. The world entities contain properties such as the base coordinate where it exists, the coordinate where it currently is being rendered, and the map out of which it is made of. Furthermore, they support their own collection of players, NPCs, locs and much more. It effectively boils down into a smaller variant of the root world being rendered on the root world, or another world entity[^1].

World

By default, there will always exist at least one world, the "root" world. This is the normal static world covering the entire game map. World entities, however, will allocate their own sub-worlds with each world entity that is being created.

Properties

Worlds contain a large number of properties which allocate circa 5.2MB of memory per world allocated, assuming the world is 16x16 tiles in size, which is likely going to be the size of most world entities outside of the root. Below is a breakdown of all the properties which the world owns:

World Entity

A world entity is an enclosed world that has the ability to move around in the root world, or within the world of another world entity[^1].

Properties

World entities keep track of properties such as:

Possibilities & Limitations

[!NOTE] Below explanation is of dynamic world entities/worlds, and not the root!

Below is a draft of the potential of world entities, showing how they can be nested further than the concept shown by Jagex: https://media.z-kris.com/2024/05/mspaint_lI8k0DO8sr.png Edit: This does not work as the client does not render anything nested.

Pseudocode

Below is some pseudocode of how the server's side of things should look like with multi-world concept:

// Root world packets after setting active world to root: player info, npc info, zone updates

// Update sends WorldEntityInfo packet
player.worldEntityInfo.update()

// As world entity info only contains position info, we need to now build the actual world via instancing
for (world in player.worldEntityInfo.addedWorlds) {
    player.send(RebuildWorldEntity(world))
}

// Sync the state of all these non-root worlds
for (world in player.worldEntityInfo.allWorlds) {
    player.send(SetActiveWorld(world))
    // player info
    // npc info
    // zone updates
}

[^1]: World entities can only be rendered on either the root world, or the world of another world entity. It is not possible to nest this more than one level deep.