pvigier's blog

computer science, programming and other ideas

Vagabond – Choosing a GUI Library

The goal of this week was to find a GUI library for the in-game interface. While making some custom widgets may seem easy, writing a general, production-ready, full-fledged GUI library is notoriously difficult. Thus there are few open-source and well-maintained GUI libraries that work with OpenGL or SFML.

In this article, I will enumerate the alternatives I considered and give some details about them. Finally, I will select one and explain my choice.

Read more ...

Tags: vagabond game-engine cpp

Vagabond – Audio Engine

After the graphics engine and the physics engine, this week, I have worked on the audio engine.

To play sounds and music I use the audio part of SFML which is really good. It is a thin wrapper around OpenAL. It supports WAV, OGG/Vorbis and FLAC. Moreover, it also supports spatialization and it is really easy to use.

There are only two things for which an audio engine is needed.

The first one is to make sure that the total number of sounds and music never exceeds 256 (which is an internal limit according to SFML documentation). To do that, the audio engine refuses to play a new sound or music if the limit has already been reached. And as soon as a sound or a music finishes, it removes its instance to be able to play a new one.

The second thing is being able to pause all sounds and music, play other sounds and music and then be able to resume all the sounds and music that have been paused. This use case happens when you are in-game and some sounds or music are playing. Then you go to the pause menu, all the game simulation is paused, so the sounds and music should be paused too. Some sounds are played by the user interface in the pause menu. Finally, when the player returns to the game, the simulation resumes and all the sounds and music should be resumed too.

To achieve that, I will use two abstractions, one for each of the two issues, respectively the audio engine and the audio scene.

Let us dive into the details of these abstractions.

Read more ...

Tags: vagabond game-engine

Vagabond – 2D Physics Engine

This week, I worked on the physics engine. It was the first time, I wrote a physics engine thus it took me a lot of time to design an algorithm that works well. In this article, I will try to share with you the issues I faced and then my current design of the physics engine.

Read more ...

Tags: vagabond game-engine

Quadtree and Collision Detection

This week was short as I was still working on the 2D light system on Monday and Tuesday. I spent the rest of my time working on a quadtree implementation.

In this article, I will share with you my implementation and my thoughts while designing it.

Firstly, I want to argue why I decided to implement a quadtree.

A Quadtree is a space partitioning data structure. Its main advantage against other data structures is its versatility. It offers good performance for insertion, removal and lookup. Thus, we can use it in a dynamic context where the data often change. Moreover, it is quite easy to understand and implement.

If you are totally new to space partitioning, I advise you to read this article by Robert Nystrom. If you want a gentler introduction to quadtrees, you can read this article or this one.

In my game, there are several places where using a quadtree is an instant win:

  • During collision detection, using a quadtree is way more efficient than the brute-force approach (testing all pairs). It is not the most efficient approach though, see this article if you want an overview of possible approaches and benchmarks. But, I will start using this in the first version of my physics engine. I may change later and use a more specialized algorithm if I need to.
  • In the scene graph, to perform culling, I can use a quadtree to find all the nodes that are visible.
  • In the light system, I can use a quadtree to find the walls that are intersecting the light visibility polygon.
  • In an AI system, I can use a quadtree to find all the objects or enemies that are close to an entity.
  • etc.

As you can notice, quadtrees are very versatile. They are a nice tool to have in your toolbox.

You can find all the code that I will show next on GitHub.

Read more ...

Tags: vagabond game-engine cpp

Vagabond – 2D Light System

This week, I have worked on a light system. It will allow me to simulate a day-night cycle and to create a nice atmosphere during night or inside dungeons and caves.

Read more ...

Tags: vagabond game-engine