Skip to content

Instantly share code, notes, and snippets.

Keybase proof

I hereby claim:

  • I am vitefalcon on github.
  • I am vitefalcon (https://keybase.io/vitefalcon) on keybase.
  • I have a public key whose fingerprint is 2083 9BF8 5A07 0C70 DC0B 1B51 96FD ABFB 2440 8428

To claim this, I am signing this object:

@ViteFalcon
ViteFalcon / godot-multithreaded-programming.md
Created February 11, 2018 18:59
Godot: Multithreaded Programming

Problem

I wanted to start building the GUI parts of the game, but create it in such a way that I will have a network interface that I can later replace with the actual implementation.

What I did

I created a LoginClient that provides an interface to the login server functions. This client works in an asynchronous manner. Login requests gets queued, which then gets processed by a thread. The fun part was in the details, which I will explain here.

Threads in Godot

I feel this is one of the things that has been least documented in Godot's documentation and few people in Godot's Discord channel have knowledge of how this works.

The general code to create and run a method in a thread looks like this:

@ViteFalcon
ViteFalcon / queue.gd
Created February 11, 2018 10:53
Thread-safe circular buffer queue
extends Node
var array
var size
var start = 0
var end = -1
var mutex = Mutex.new()
signal item_removed
@ViteFalcon
ViteFalcon / resources.xml
Created February 16, 2016 14:23
My data configuration
<?xml version="1.0"?>
<resources>
<location type="dir" path="C:/Users/vitefalcon/Games/WoonReloaded_Full/"/>
<location type="grf" path="C:/Users/vitefalcon/Games/WoonReloaded_Full/WRO.grf"/>
<location type="grf" path="C:/Users/vitefalcon/Games/WoonReloaded_Full/rdata.grf"/>
<location type="grf" path="C:/Users/vitefalcon/Games/WoonReloaded_Full/data.grf"/>
</resources>
@ViteFalcon
ViteFalcon / BackgroundImage.cpp
Last active September 9, 2019 07:13
OpenSceneGraph: Creating background image
// create a camera to set up the projection and model view matrices, and the subgraph to draw in the HUD
osg::ref_ptr<osg::Camera> camera = new osg::Camera();
// set the view matrix
camera->setReferenceFrame(osg::Camera::ABSOLUTE_RF);
// use identity view matrix so that children do not get (view) transformed
camera->setViewMatrix(osg::Matrix::identity());
// set the projection matrix to be of width and height of 1
camera->setProjectionMatrix(osg::Matrix::ortho2D(0, 1.0f, 0, 1.0f));
// set resize policy to fixed
namespace Component
{
extern const char* HEALTH;
extern const char* NAME;
}
template <const char* Name, typename T>
class Attribute
{
private: