You can now easily move objects around, and their rotations are all handled properly.
This is part 1 of 2 in my Grand Plan to Make Rotating Boards Less Awful and Difficult. You should be seeing part two next week.
To send data between the client and server, we use packets. These are small bits of data that the game uses for communicating things like when a player has placed a component. Previously, these packets were hard-coded, meaning that whenever we wanted to add a new packet type we needed to manually register it.
A big issue with this approach is that mods were not able to add their own packet types. For this reason, I’ve made this system more expandable: instead of packets having their own hard-coded ID they will be assigned an ID when the game starts. This will be very helpful for mods, as they will be able to send and receive their own data, independent from the rest of the game.
This week I’ve also been working on optimizing the code that does all the circuit simulation, namely the clusters system and the circuit states system. The most interesting one is probably the clusters one, since it involved more thinking rather than coding.
Clusters are an internal structure we have within the simulation. A single cluster represents a group of pegs and wires all connected together. Since everything in the group will turn on and off at the same time, they can be treated as one object rather than several.
Previously the clusters that needed to be updated were stored on a simple list, which stored references to all of those clusters. This worked just fine, however it wasn’t the most efficient approach.
Since we only ever iterate through the clusters one after the other, we do not need the ability to get, for example, the fifth cluster in the list. Instead, we only really need to know which cluster is updating first, and which one is updating after it. This is very similar to the concept of a linked list, since each cluster just has to store a reference to the next cluster. This is much more efficient than using a list, since all the operations we need are O(1) (which basically means it always takes the same amount of time, no matter how many clusters there are) on a linked list.
There’s also a distinction between a doubly linked list and a singly linked list: an item in a singly linked list only stores the reference to the next item, while a doubly linked list’s item also stores a reference to the previous item. In theory we would need a singly linked list since we only ever go forward when updating, however using one would mean that we wouldn’t be able to remove an item that’s not the first or the last one (for example when you remove a component and we need to remove it from the list, it’s very likely it’s in the middle). For this reason, we need to go with a doubly linked list.
We could use C#’s generic
LinkedList class, however it could introduce more overhead with unnecessary features and end up actually being slower than our old way of doing it. For this reason, clusters will instead build their own linked list of sorts, manually storing the previous and next clusters that are updating. When we want to update all of them we simply get the first one, update it, then check which cluster is next and repeat until we’ve reached the end.
I was going to make a cool graphic diagram to demonstrate the concept, but unfortunately I’m far from a graphics designer so if you’re interested I’ve made a text document detailing what happens when you add or remove a cluster.
This should also drastically improve the performance of Relays, as those components work by creating and destroying clusters. However, we haven’t been able to get numbers on that yet.
The amazing @Marutzo – whom some of you might know as NITRO – has made a gosh darn plushie of Bobby, Logic World’s beloved protagonist and mascot.
This is pretty much the best thing ever and it has absolutely made our week!
We’ll keep releasing these weekly updates right up until the game comes out. To make sure you don’t miss them, you can sign up for our newsletter. Be sure also to wishlist Logic World on Steam and join the official Discord.
See you next Wednesday!