SFML 2.5.0 Update (Or how I learned to hate RenderTextures)

 

 

On May 6th, the C++ Simple and Fast Media Library (or SFML for short) was updated to stable version 2.5.0, adding various updates including more optimial iOS support, bug fixes, added functionality for Text and Audio and various optimizations. For such a big release, it made sense to upgrade and get my Vigilante Game Framework updated, and why not update Gemstone Keeper while I’m at it?

Well it took nearly a month, but I did manage it in the end. Gemstone Keeper 1.0.5 has been uploaded to Steam, both for Windows and Linux!

As the title suggest, a lot of the work had to do with the updates to the sf::RenderTexture object. However, I don’t absolutely hate them, they are extremely useful for rendering a scene to an area of the screen, or to apply post-processing effects to. However the problem lied in how I was using them, and how the fixes done in the latest update effectively broke my engine’s rendering system.

The initial update showed promise, as my most recent game worked fine, but moving onto the framework’s examples and Gemstone Keeper showed that a lot of things weren’t rendering at all.

Vigilante Framework currently renders 3D models using Modern OpenGL, and while it was working fine with SFML 2.4.2, it rendered nothing with SFML 2.5.0. The solution was embarrassingly simple despite the amount of effort put into fixing it, including implementing my own version of SFML’s glCheck function and re-writing SFML’s own OpenGL example to run with modern OpenGL. When rendering the 3D scene, I modified some of the OpenGL states, which wouldn’t be an issue before but now those OpenGL states carry over into other contexts. The solution was to simply make sure that the GL states were reset BEFORE rendering the scene using a sprite object.

 ///Render 3D scene and apply to a sprite.
 RenderTarget.resetGLStates(); //Reset the GL states to the default for SFML
 Sprite->Draw(RenderTarget); //Render the sprite.

Gemstone Keeper however uses legacy OpenGL, and while I could have updated the VFrame source code but that could take more time to fix. Regardless, I was able to get it working by rearranging other objects that define sf::RenderTexture, including the bloom post processing effect and the help popup terminal.

Gemstone Keeper’s other graphics were another story. The approached I had been using up to this point was to render text objects onto a single rendertexture, and then store the generated texture to be used as a sprite, particle or tilemap. While this was okay for the time, but it is rather inefficient and bad for graphical memory.

I wanted to do a single-texture approach, where all the graphics are rendered onto a single texture, and a rectangle area is specified when creating renderable objects, for a while but I kept putting it off. SFML’s update, causing any newly created render textures to dereference generated textures, it was time to take this approach on. The best part is that most of the work was already done by myself with the additional code of Jukka Jylänki’s MaxRectBinPacker algorithm, all that needed doing was to change how I defined renderables from setting the texture to whatever the name of the genrated texture is to the name of one texture sheet, and to get the correct rectangle from a map/dictionary, searching by string ID.

CaptureCaptureCapture

Now this doesn’t mean the entire game’s visuals are rendered from one texture. Including the 3D gemstones, any assets that use a repeated texture grabs a subsection of the main texture as a copy, same applies to the VBackdrop as well. Getting the icon was a more painful looking process of converting the entire texture sheet to an sf::Image, so I can load in a subsection to a new sf::Texture object, and then convert the new texture object to an sf::Image in order to set it to be the application icon.

sf::IntRect iconArea = TextureData::p()->GetTextureRect(TextureData::p()->GetPortalTextureName(true));
 sf::Image image = VGlobal::p()->Content->LoadTexture("TextureSheet").copyToImage();
 sf::Texture tex;
 tex.loadFromImage(image, iconArea);
 VGlobal::p()->App->setIcon(iconArea.width, iconArea.height, tex.copyToImage().getPixelsPtr());

Like I said, not pretty.

So enjoy Gemstone Keeper, the number of you who own it. Now back to doing more stuff in C++…

Advertisements

New Years Resolutions

Good evening everyone! It’s no doubt that 2017 has been a hell of a year following what happened in 2016, but we fought through and we are still here fighting! This year has also been huge in terms of game development for me. I managed to finish SEVEN games this year, six from game jams such as #RemakeJam, PROCJam, Jamchester and Three Ludum Dares!

https://img.itch.zone/aW1hZ2UvMTYzMjc3Lzc1MjE2Ni5naWY=/315x250%23c/L0i8g2.gif  https://img.itch.zone/aW1hZ2UvMjAxMDM1LzkzOTE3OC5naWY=/315x250%23c/q5QpUK.gif

The seventh game was the nearly two year project Gemstone Keeper, which made an initial release on March 31st earlier this year and has since had numerous updates, although grouped together as four updates. The most recent of which was 1.0.4 that was announced on 21st of December. The game is currently on part of the Steam Winter Sale, and is currently 50% off!

Gemstone Keeper also had a second smaller release as it was ported to Linux, the build being available on Steam in June. I documented the progress to port the game in three blog posts (part 1, part 2 and part 3), and got a small amount of coverage from dedicated linux gaming websites as a result.

There was also an accomplishment in travel as well, 2017 was the year I went to both GDC in San Francisco and Develop in Brighton for the first time! Both events were great opportunities to meet up and socialise with fellow game developers and listen to talks from great minds such as Ken Perlin, John and Brenda Romero, Jordan Mechnar and Tim Sweeny.

As for 2018, I want to set some goals. As with many New Years Resolutions, chances are they will be forgotten and unaccomplished, but considering I managed to lose weight this year, I might pull through with a bit of committment.

First one is that I want to take part in at least one game jam a month, meaning I’d be finishing 12 games next year. I like the challenge and creativity from game jams, but this year I feel like six isn’t enough. At least spacing out the game jams to one a month will give me time to find a weekend or so to get my head down and finish something.

Second one is to get a game on console. It’s not like I haven’t bothered trying before (I’ve reached out to Nintendo about developing Gemstone Keeper for the Switch to no avail), but it would be nice to expand my work beyond desktop PCs and web development. Porting my own game to Linux should show how when I put my mind to it, building a game to another platform by hand is possible, and it would be great to show I can do that on one of the three main systems.

Thanks for reading and have a happy new year everyone!

The More You Have, the Worse It Gets

Ludum Dare 40 took place last weekend, the theme was the title above. Honestly it wasn’t the theme I was hoping for, but in the end, I took an idea I had and adjusted it slightly to work.

The idea I had was that a single level would slowly get corrupted and change, you can shoot away the corruption, but touching the corruption would kill you. This already could fit the theme quite well, the more corruption in the world means the worse it is for you. I wanted players to move around a lot, so I had the additional goal of collecting glitch boxes, which would create more corruption over time.

I used HaxeFlixel to develop the game, as it was bread-and-butter for me in game jams such as Ludum Dare, especially when there is not much time to work on an idea (I had spent the entire Saturday out with friends for winter festivities, all I did was write notes on what the idea would be, so in all I only had around 11 hours to work on a game).

b056


To get the corruption to update and move around, I used the tilemap system and updated the grid with Conway’s Game of Life algorithm, that way it gave the impression of mutating outwards or dying out depending on the numbers. Fortunately, with recent updates to HaxeFlixel, you could do collision response based on specific tiles, so it was easily possible to remove tiles and change the map when bullets collided with it. The extra artefacts also use Conway’s Game of Life. although the grid is 4 times larger than the main corruption grid.

The artwork was done in Photoshop, although it was a very simple and rushed job. The “corrupt” graphics was a multicoloured character set that I had to create and tweak by hand to fit into a 10×10 pixel grid.

The music was a combination of cgMusic and LMMS, quite a good combo to have because it meant I let one program generate a music set, then import it into LMMS as a midi file for me to set instruments (using soundfonts), effects and tweak the melodies how I like.

I managed to upload the game with around 30 minutes left before the compo deadline!

b05c

On Tuesday I fixed that timer, which appeared broken when you reached a minute because I messed up how the string was being built. It took a few uploads for those changes to appear, something that kind of frustrates me about HTML5 and how web browsers will not always clear out the cache if the content has been changed.

GIF

Feel free to play the game on itch.io as well as rate or comment on the Ludum Dare page.


This wasn’t the only games jam I did this winter, I also took part in PROCJAM, where I built a planet generator. It’s not my best work to be honest, although I was able to work and improve my 3D OpenGL rendering in the Vigilante Framework.

Gemstone Keeper – Quest to Linux Part 3 – Gemstone Keeper

Finally, after beginning soon after the game’s Windows release on Steam, and well over a month after I initially wrote my first post about this topic, I’m finally done with porting Gemstone Keeper to Linux (for the most part) and ready to write about what I’ve learned from porting it over. Since both the Framework and Level Generator have been ported, getting the whole game to compile and run wasn’t as confusing as the last two, but that didn’t stop it being tedious.

Continue reading

Gemstone Keeper – Quest to Linux Part 2 – GenLevelTools

Last time on Quest to Linux, I went through porting the Vigilante Game Framework to Linux, but the quest isn’t over yet. The next big task is porting Gemstone Keeper’s level generator and editor, the GenLevelTools, since I need to be able to get the caverns from somewhere.

https://upload.wikimedia.org/wikipedia/commons/a/af/Tux.png

GenLevelTools, aka the Procedural Level Editor, is a tool/library set that enables proceudrally generated grid-based levels to be modified and previewed in a level and used in games, while independent from any specific game engine or renderer. It was originally developed for my University Thesis on Procedural Level Generation and I later did a talk about it at the International Roguelike Developer Conference in Nottingham. The library is written in C++, so language specific quirks like forward slashes and for loops apply, so the main challenge this time around is the level editor, which uses Allegro 5 as well as the GUI library GWEN.

Allegro 5 is a C framework, although you can still use it for C++. Fortunately like SFML, it’s easy to set up for Linux since it’s part of one of Ubuntu’s repositiories. GWEN is a GUI library that was developed by Garry Newman (of Garry’s Mod). It was the easiest to set up for Windows but I had a few problems with the Linux version, as the gmake scripts rely on finding certain libraries and ending the entire scripts if those libraries cannot be found. This is different from running the scripts for Windows, which create Visual Studio projects that you can apply the libraries yourself. After tweaking the scripts and the source files a bit, I managed to get the GWEN and GWEN Allegro Renderer to build.

Aside from the main changes that I mentioned in the last post (using correct slashes, for loops) there weren’t that many changes I needed to make. I did have to add a lot more include statements, since despite being standard library stuff, GCC doesn’t immediately know what functions like memset, modf, floorf or ceilf among others off the bat, unlike Microsoft Visual Studio. After all these changes the library was able to compile smoothly. To make absolutely sure that it works within Linux, I wanted to build and run the editor, hence why I wanted to set up Allegro and GWEN. I managed to compile it with little effort, but something went wrong…

The editor crashed almost immediately, and the only reason I was able to show the following above was because I tried running the editor without the GWEN GUI rendering in the scene. It didn’t help that Code::Blocks debugger wasn’t working initially, and the closest I got as an error was below.

Fortunately I was able to configure Code::Blocks debugger to work, and was able to find the route cause of the crash being from the GWEN Allegro Renderer being unable to load the font, which is odd because the font I used (Lucida Sans) was able to load fine in my editor code, but fortunately GWEN provides an open source font (Open Sans) that runs just fine. So now with the GUI render up and running, I can test the editor!

I’ve been able to compile the library as both a binary and static build, as well as the editor. I could also compile the unit testing and C# wrapper for it too, but since I mainly wanted to get this done for Gemstone Keeper, I’ll leave it like this for now. Time for the main course!

Gemstone Keeper – Quest to Linux Part 1 – Vigilante Framework

So with Gemstone Keeper on Steam for Windows only, I thought I’d try my hand at getting a game to build to Linux the proper way. This series of posts will hopefully document each part of porting Gemstone Keeper to run on Linux.

https://upload.wikimedia.org/wikipedia/commons/a/af/Tux.png

The last time I made a game with Linux support was Secret of Escape, which used the Node-webkit to run HTML5 games to desktop applications. Node-Webkit essentially was a separate, precompiled application that functioned like a limited web-browser using the Chromium engine, all Construct2 did was build a HTML5 game and structured it in a file structure that made the application run the game. This way, porting the game to Windows, Mac and Linux took very little effort. This essentially means that developing for Linux was a completely new thing for me before releasing Gemstone Keeper.

The first stage was porting the Vigilante Game Framework. This is the underlaying C++ framework that uses SFML to develop games with state management, collision, visual effects and audio effects among others. It was partially inspired by HaxeFlixel, although with some of my own approaches that rely on C++ and SFML, as well as my own features (such as circle collision, multipass post process effects and a custom text renderer). Getting this to work on Linux would help me with setting up SFML and having a good idea of how Linux development worked.

Surprisingly, getting the framework to build on Linux ended up being the easiest part, because someone else already did it! I posted the framework to GitHub, and passed around the GitHub page to Twitter and Reddit, and SirFrankalot on the /r/gamedev subreddit was able to fork it and get it to work in Linux, and provided both written notes and a pull request to carry his changes over! The details can be found here, but these are the main points I wanted to get across:

  • Using Correct Slashes: When using Windows Explorer and Visual Studio, folders or directories will usually be represented with a backwards slash (\). If you are only developing on Windows, this wouldn’t be a problem. However Linux and Mac both always use a forward slash (/), so for portability you should use that. Using forward slashes also has the advantage of not having to deal with escape sequences, since programming languages use a backwards slash (such as \n, \t and \\).
  • For-Loops: These kinds of loops are good for looping a specific number of times using a defined iterator. If that iterator is a list of object or variables, you use a foreach loop, assuming your programming language of choice has that. When using Visual Studio, I found there is a foreach loop in the form of for each (type x in y) where x is a reference to an object in the list, and y is a container like an array or vector. Turns out this way is purely a Visual Studio extension, and the portable foreach loop is for (type x : y).
  • XInput: Microsoft XInput is the API used for Xbox 360 and Xbox One controller, which means that it’s works for Windows only, at least that’s what you would assume. Linux has both libudev and linux/joystick.h, which allows some Linux OSes to access XInput functionality. This would mean a complete rewrite, so SirFrankalot simply made all XInputDevice functions return false. I later found someone wrote a Gamepad API was maintained long enough to allow Xinput Controllers to work on Windows and Linux using the same functions. I’ve since added this on as an optional feature that can be set using a preprocessor.

https://upload.wikimedia.org/wikipedia/commons/3/3f/Logo_Linux_Mint.png

Next was using an IDE, I decided to use Code::Blocks because I have used it before, although it’s still much of a change of Visual Studio. Not to mention I was using a virtual machine, a VirtualBox with Linux Mint 18.1, and for whatever reason my configuration causes it to crash with no warnings. I also had to set up a load of dependancies, although using the terminal to get them is much easier than browsing for libraries online.

 

In the end I managed to build the SFML tutorial code and a few moments later, VFrame could compile! Aside from some small issues with 3D graphics, it was running almost just like it did on Windows!

Next time, it’ll be my ramblings as I port over the library that makes Gemstone Keeper’s caverns large and random, the GenLevelTools!

Ludum Dare 38 – littleBLASTplanet

Last weekend was Ludum Dare 38, not only is it the 38th main game, as well as the 8th or 10th one I’ve taken part in (whether or not you take into account failed attempts), but it also marks the 15 Year Anniversary of the competition/jam as a whole! Not only is it celebrated with another jam, but with a brand new website. For now you can still access the old website, but game submissions are currently being handled entirely on the new site.

ldjamalpha

The theme this time around was Small World, so I (like a lot of devs) made a game either around a small game world or a tiny planet. I went with the latter and drew up a run ‘n gun shooter on a little planet.

 

Sadly I had plans with my friends on Saturday so I didn’t start work on the game until around 8PM GMT, so development felt more rushed than a full games jam but I managed to make what I set out to design: littlePLANETblast

Similar to my past Ludum Dare projects, I used HaxeFlixel. It’s straightforward to use, multiplatform (Flash, HTML, Windows and Android maybe…) and it’s still being maintained so there have been several improvements. I’ve provided the game’s source code on Github so feel free to have a look to see how the game works.

The first problem I had to solve to make this game work is how to make a sprite orbit a planet. HaxeFlixel has a FlxVector object for vector math, so using that with a sprite’s acceleration meant having the sprite fall towards the centre of a circular planet was pretty easy, but how do you get the sprite to stop on the planet’s surface?

HaxeFlixel has no circular collision, only rectangtle collision. When I wrote my own C++ framework for Gemstone Keeper, which took inspirations from HaxeFlixel, I included Circular collision by giving each object a Radius property and writing my own circle overlap and separation functions. This would have been too much work for the time I had, so I wrote a hack method for a derived sprite class that always checked and updated the distance between a sprite’s centre and the planet’s centre, and if the distance was less than both the planet’s radius and sprite’s radius combined, then the game pushes the sprite up to the edge of the planet. This circle collision method is only applied between a sprite and the planet, and since rectangles don’t rotate then all sprites had to be perfect squares.

Bullets were one of the only sprites that weren’t built to orbit the planet, instead simply moving in an angle that combines the firing direction with the player’s current angle. I’ve had some feedback that said that the bullets should also be affected by gravity. I decided against it because it would make enemies on the planet easier to hit, while enemies in the sky would be harder to aim, not to mention the game loses a strategy element because of where bullets travel.

 

I went with three base enemy types: Rockets, Spikes and Robots.

Robots functions no differently from the player, except that it moves in a fix direction and smaller ones bounce by constantly jumping. Spikes has the same orbiting system, but it’s planet radius is much smaller to allow it to go into the planet. I use FlxTween and the FlxTimer to allow the spikes to move in sequence. Rockets simply spawn outside the screen at an angle and move towards the centre of the planet. If a rocket touches the planet then it would be destroyed, resulting in an instant game over.

I also added an escape object, which changes the planets side and makes the level a little bit more harder. This was for variety, so you wouldn’t have to stay on the same planet. If I had a bit more time I would have included more animations on the planet itself.

Speaking of the planet, that was one of the first objects I applied polished graphics to. To give it a more detailed pattern, I used the built in Cellular Automata function, and applied the pixels to the circle. Since it uses a random seed, the pattern is different on each playthrough.

The planet’s destruction is a particle effect that uses the planet sprite’s texture, a technique I used a lot in Gemstone Keeper. However one gripe was that I had to make a derived FlxEmitter class that could allow me to set how many frames I wanted based on the particle’s frame size.

Along with proper sprites, smoke was added to the spikes so that the game can provide a one second warning before spikes hit. I also added a distance check to avoid some unfair spike deaths. Finally I added a second camera mode incase the first one wasn’t interesting enough. The follow camera simply rotates with the player so they can stay in one spot while all the other objects rotated around. It did mean having to create a new Camera for UI elements, since objects can only be parallax scrolled by position.

The last elements I added were the title screen and audio. Sound effects were produced with BFXR and music with Abundent-Music’s Procedural Music Generator. Audio is one of my weakest skills so these procedural tools made that quick and simple, although I probably wouldn’t enter myself into the audio category for them.

I figured I add a smaller version of the planet in the title screen and have the player sprite on a bigger world to give a vague sense of a setting, with emphasis that the player is fighting on tiny planets and not just a giant on a regular sized planet.

And that’s basically how I made littleBLASTplanet. If I had more time I probably would have created more enemies and made proper transitions between planets. Aside from that I’m pretty happy with the results, particularly hacking the physics to getting jumping and moving around a 2D planet to be possible.

Voting for the game begins on Wednesday Friday, so if you took part in Ludum Dare, please check it out!