How to build a game for Windows and macOS with Rust and a little bit of Python.
- by admin
The last few weeks I’ve been spending some time with Rust, the language that is powering many of the world’s biggest games.
The language is used to create platforms like Rust on Linux and Windows, and it’s the programming language that I’ve used the most recently for Rust’s own Unity Engine.
As part of the game-making process, I wanted to use the language to create a game using Rust.
While I can’t talk about what the language actually does, I’m sure it’s fairly straightforward.
It’s a collection of concurrency primitives, so I thought it might be a good idea to go over some of them to understand how they work.
Rust’s Concurrency primatives can be used to implement different kinds of asynchronous code, including the ones we’ll discuss today.
Rust is built on the idea that we can control execution of code at different levels, and that’s a core feature of the language.
As a programmer, you can think of concurrencies as being a series of tasks, each one executing one of them in turn, with each task having a distinct task-level, execution context, and so on.
As such, a program like Unity that’s used to build Unity-style games might have one task that runs in the Unity sandbox, another task that calls a function from that sandbox, and a third task that reads from the Unity environment.
All of these tasks are executing at the same time, so there’s no need for any synchronization.
That means that the program is much more predictable, which is why we usually refer to the language as “a concurrency language”.
Concurrency can be achieved by passing a list of tasks to functions that perform the task-specific computations.
The tasks themselves are a type of object that has some operations on it, but not much more than that.
For example, the task of creating a new Unity asset is an object of type Unity Asset, and the code for that task is written in the following way: var myAsset = new Asset(); myAsset.setTexture(Texture.createTexture(0, 0, 20)); var newAsset = myAsset; // Create a new Asset object var myAssembly = new Assembly(); // Create the new object and initialize it myAssembly.setAssemblyName(myAssembly.getAssemblyName()); // Initialize the new asset as an Asset myAssembly .setAsset(newAsset); // The final step of the process, calling a function on the new Asset to generate the asset myAssembly is the type that Unity uses to handle Unity tasks.
When the function is called, it will create a new object of Unity Assembly type.
This is a way to pass the task information, and make sure that the Unity compiler knows about the new function.
When we call a function, we can pass an array of tasks as arguments, and they will be passed as a single list of values.
The array will contain a single task value, and then the task values will be grouped together into a list.
Each task value in the list will be a unique value.
For this example, I’ve put a task value of 0 as a value to the list.
The next task value is the first value, the second is the second value, etc. If the list contains an empty list, the function will return the empty list.
Let’s look at how Unity’s tasks work: If a task is created with the following code: myAssembly, newAsset.addTexture(texture.createRect(0x0,0x20,20)); myAssembly has an associated task: myAsset has an assigned task: and the associated task is the texture creation task.
When this task is completed, Unity will call the texture object.
The Unity code looks like this: if (myAsset.isReady() && myAssembly) myAsset(texture).addTexture(); And then, the code will return true when Unity has finished rendering the object.
This means that Unity is ready to call the new task.
But, what if the newTask is not yet complete?
That means Unity needs to wait for the next task to be created: if (!myAsset(task)) myAsset().addTask(); The task returned by the Unity code can be a new array of values, which Unity will then use to add the texture.
The task object will be the first element of the new array, and will contain the texture values.
So if Unity waits for a task to finish before calling the newTexture object, Unity can call the task later, and create the texture later.
This process will keep happening until Unity has completed its next task.
Now let’s see how the concurrency part of Unity works.
For the purposes of this article, I won’t go into details about how concurrency works in Rust, but the Concurrency Primitives library makes it easy to write concurrency code.
For now, let’s look how a concurrency task is implemented. Let me
The last few weeks I’ve been spending some time with Rust, the language that is powering many of the world’s…