Posts


Re:creation dev log. December 2016 - March 2017.


No posts in four months! And I haven’t worked on the game for the last one and a half. Is the project dead? No! Let’s pretend that nothing happened and I’ll show what I did since December and will tell about my future plans in the end.

Child-parent example

Continue reading →



Making and storing references to game objects (entities) in C++ and Lua


Table of Contents

Introduction

Ids

The problem of handling references to game objects (I’ll call them entities) comes up very often. Sometimes it’s child-parent relationship between the entities, sometimes it’s useful to store a reference to an object in event data, some task scheduling class and so on.

Sometimes a simple pointer, reference or std::reference_wrapper is enough. But the problem with raw pointers and references is that once you use them, you have to make sure that the entity which is being referenced stays alive and is not moved in memory without notifying objects which hold references. And with good design you’ll probably be able to achieve that.

But stale pointers/references give some of the worst bugs, which are difficult to track, crash your game and may not be easily identifiable. Some entities may start to occupy different addresses in memory (for example, after you reload a level and decide to create all entities from scratch). While it’s possible to manually update all pointers to previously referenced entities, it’s certainly will be better to do so automatically and without a chance of forgetting some pointers which will be stale.

Let’s see all these problems can be solved. The latest solution (about storing references to Lua) was discovered by me not long ago and it is the point of me writing the article, but I want to show some other ways of solving the problem. Let’s start!

Continue reading →



2016


Animation editor 2016 was pretty good for me. There were a lot of positive changes, I learned a lot and got some unexpected recognition for my work!

Continue reading →



Re:creation dev log. July - November 2016


The last five months were really important for the game. It finally feels like I can work on the game itself now, not just the engine and basic systems which will let me implement different stuff in the game. It’s not just abstract stuff, stuff which I do “just in case”. No, I try to be pragmatic and implement things which are needed for the game and which will let me create stuff without much restrictions.

I’m very glad to say this, but I feel like the core engine is almost done. There are still some important things which I’ll have to implement, but it still feels like I’m finally happy with the design I have. Mostly, it’s because I’ve removed lots of stuff and find lots of ways to minimize my code which in the end gives me ability to implement new stuff easier and makes the whole thing easier to expand, modify and debug.

I’m finally ready to do a lot of prototyping. I’ve already done a lot of stuff about the game, but I still have the feeling that it’s just the beginning of the “real” development! And it feels great, because I feel like I’m in total control of every aspect of the game. There are no restrictions, no boundaries. Let’s see how it goes.

One more small thing: I’ve got a new laptop! I’ve had it for two weeks now. It feels really great. I’m able to do stuff a lot quicker and without frustration (having a great mood is important to be productive)! I’ve had my previous laptop for six years and it was slowing me down a lot. It was constantly overheating, everything was running poorly, compilation took a long time, etc… And recently I’ve realized how much it hurt my working process. There were lots of distractions, because even small change could take 1-2 minutes of recompilation. This means, that fast iteration was impossible. This also means that I constantly lost flow and couldn’t debug quickly. Hours of slow progress made it all exhausting. Won’t happen anymore!

Okay, let’s begin!

Continue reading →



Using ImGui with modern C++ and STL for creating awesome game dev tools. Part 2. Some tips and tricks.


Hello, welcome to my second article about ImGui! This article is a collection of useful things, hacks and other stuff I’ve found while using ImGui. Mostly it’s focused on using modern C++ and some parts of STL with ImGui.

If you use SFML and want to learn how to use it with ImGui, use my binding and refer to this tutorial about setting it up!

ImGui widgets

Different ImGui widgets (taken from ImGui’s github page)

Continue reading →



Using ImGui with SFML for creating awesome game dev tools. Part 1.



Related article: Using ImGui with modern C++ and STL


This is the first part of tutorial about Dear ImGui (AKA ImGui) and it’ll show you how to set it up with SFML. The second part will be library agnostic and will talk about common ways of doing stuff in ImGui, some awesome widgets and some useful STL overloads.

ImGui widgets

Different ImGui widgets (taken from ImGui’s github page)


Continue reading →



Improving code highlighting on blogs


Who knew that I’ll someday write about web programming, but here I am.

This advice applies to lots of languages and editors, I use C++ and Visual Studio as an example.

Lots of sites use Pygments or highlight.js as a syntax highlighter and here’s how C++ code highlighted in Pygments looks (highlight.js produces almost identical output):

bool LuaScriptManager::loadScript(const std::string& filename)
{
    int numberOrArgs = lua_gettop(L);
    auto& log = engine_system.get<LogManager>();
    if (!(luaL_loadfile(L, filename.c_str()) || lua_pcall(L, numberOrArgs, 0, 0))) {
        log(LogManager::MessageType::Lua) << "Loaded script: " << filename;
        return true;
    } else { // some error
        log(LogManager::MessageType::Lua_Exception) << "Failed to load: " << filename;
        log(LogManager::MessageType::Lua_Exception) << lua_tostring(L, -1);
        lua_pop(L, 1); // pop error message from stack
        return false;
    }
}

But here’s what you can do with Visual Studio by copying HTML markup from it and applying some CSS:

bool LuaScriptManager::loadScript(const std::string& filename)
{
    int numberOrArgs = lua_gettop(L);
    auto& log = engine_system.get<LogManager>();
    if (!(luaL_loadfile(L, filename.c_str()) || lua_pcall(L, numberOrArgs, 0, 0))) {
        log(LogManager::MessageType::Lua) << "Loaded script: " << filename;
        return true;
    } else { // some error
        log(LogManager::MessageType::Lua_Exception) << "Failed to load: " << filename;
        log(LogManager::MessageType::Lua_Exception) << lua_tostring(L, -1);
        lua_pop(L, 1); // pop error message from stack
        return false;
    }
}

That’s so much better. Let’s see how it works and why it’s much more detailed.

Continue reading →



CppCast: Talking about Lua and C++ in game development


Me on CppCast

I recently gave an interview on CppCast! Listen to it here.

Here are my some thoughts about CppCast and the episode.

Continue reading →



New blog, new articles!


Hello and welcome to my new blog! After using my old blog for several years, I’ve decided that it’s time to move on. This blog is made with Jekyll and it’s currently hosted at GitHub, though eventually I plan to register proper domain for my site once I feel that the blog is good enough.

I feel that having a minimalist blog with great customization is awesome and it will improve looks of my blog posts a lot. Just look at that beautiful code block, that’s how the code will look from now on:

In Pygments:

void Entity::addComponent(const std::string& componentName, const ScriptDataLoader& loader)
{
    auto& componentManager = engine_system.get<ComponentManager>();
    auto componentType = componentManager.getTypeIndex(componentName);
    if (hasComponent(componentType)) {
        auto& log = engine_system.get<LogManager>();
        log(LogManager::MessageType::Error) << name << ": Component with type " << componentName << "already exists.";
        return;
    }

    auto c = componentManager.createComponent(componentType);
    componentManager.loadFromLua(componentType, *c, name, loader);
    c->owner = this;
    c->init();
    addComponent(componentType, std::move(c));
}

And this is a test of HTML markup from Visual Studio!

void Entity::addComponent(const std::string& componentName, const ScriptDataLoader& loader) 
{
    auto& componentManager = engine_system.get<ComponentManager>();
    auto componentType = componentManager.getTypeIndex(componentName);
    if (hasComponent(componentType)) {
        auto& log = engine_system.get<LogManager>();
        log(LogManager::MessageType::Error) << name << ": Component with type " << componentName << "already exists.";
        return;
    }
 
    auto c = componentManager.createComponent(componentType);
    componentManager.loadFromLua(componentType, *c, name, loader);
    c->owner = this;
    c->init();
    addComponent(componentType, std::move(c));
}

There are some new articles coming soon and will be published on this blog, but first, let’s talk about it.

Continue reading →



subscribe via RSS