Wednesday, February 22, 2012

Reasons why you should write a libRocket plugin and News!

libRocket provides something very useful, the Plugin.

Its just an interface class, you define its methods, and it works like a charm right after registering an instance with the rocket library.

It can be really useful, because you need to maintain only one instance of it, as libRocket has a global initialization nature as well.

Having a plugin you could:
  • Dynamically initialize/shutdown libRocket support
  • Keep track of all contexts alive
  • Keep track of all documents alive, and even what context they belong
  • Have a global event dispatcher, that you can bind to, and get events directly to your app
  • Register custom documents as specific tags easily
  • Maintain the loading/unloading of fonts required by each context, as they go alive or die
Parabola Engine went with this approach and its looking good so far, expect big things soon.

The first public release of the engine is near, you will be able to use it steadily, soon enough.

This means that most low-level systems are almost done, and fully documented. Things such as complex scene graphs with component systems, with skeleton animations and quad trees for rendering are planned, but will be made right after the low-level systems.

The big surprise is that the AngelScript support is looking awesome. The base for dealing with scripts is just doing great!

Its actually possible to render stuff and do other tasks by scripting right now, but they are yet tests.

As soon as i decide the public scripting API, i will implement it full power, along with a nice documentation wiki page.

Expect a series of tutorials to make games with Parabola Engine, by using ONLY scripts. Aimed at all ages!

SFML 2 libRocket Renderer

I know libRocket is quite popular, and since I use it in my engine, along with SFML 2 most recent (or almost) graphics API, I decided to share a snippet that will be able to render your documents using sf::VertexArray.

The below snippet will do the job of rendering the textured geometry of the whole rocket document, assuming you already made a few things:
 - load textures as sf::Texture in the appropriate place
 - define target as a valid SFML sf::RenderTarget, before calling Render on the context
 - return NULL in the compile geometry attempt, so the "immediate" mode is used.

Don't worry as later I will give you a lot more, if you need it now or just need help with libRocket, feel free to contact me!

Sunday, February 19, 2012

News 18/02/12

I've been burning all time I have in improving the engine and the game systems, and its going pretty good.

The utility Foundation module is pretty much done and functional, Graphics systems are pretty well too.
Animation module was refactored too, and its working nice so far. Rendering support also improved greatly. libRocket is now working very consistently, it looks like.

Just to go a little deeper on the animations, the sprite animations are working nice, they are capable of defining an evolution along the time of image frames, and updates a sprite with it! This easily makes possible to create a character with different stances.

Also, the camera animations were started, you can now have a AnimationView associated with your camera, and when you do something like viewAnimation.createEarthquake(5(seconds), 20(intensity)); the camera actually starts shaking like crazy :)

The engine is now very functional from a low level perspective. The next systems that need to be done properly / refactored / documented are:

- Kinesis ( physics )
- Scripting (internal engine commands and AngelScript exportation)
- Content managing
- Networking
- Sound improvements
- SceneGraph high-level stuff / Entity system(component-model) / Quad-Tree rendering

It won't take too much time before you have access to a free complete 2D engine, fully documented!

Saturday, February 18, 2012

Doxygen quick guide

Hello,

I really feel like I should share a quick guide on how to document your code with doxygen and I will explain why! (Doxygen just because its the one I use)

Many programmers, especially beginners, tend to not document the code at all, and use little or no comments in the code. Its not always imperative to use them, but it certainly doesn't make any harm and can be precious in many cases!

When projects start to grow bigger, the codebase starts to expand and it becomes harder and harder to maintain the complexity without proper documentation.

Most people underestimate this, but if you write a big chunk of code and leave it abandoned for some months, when you look at it, it won't even look like it was done by you. Many times, you just feel like refactoring it again, because you don't remember what was on your mind when you made it.

And remember that some projects are big enough that you are away from a "module" of your project months, just while working intensively on another module.. It gets that big often!

For maximum efficiency when working on your software projects, being them libraries, games or general applications, I recommend a lot of comments here and there and organized code. Just think that you will be needing it later, eventually.

But the purpose of this post is exactly to tell you quick and dirty how to write a nice documentation with doxygen syntax. Just follow the topics for what you want and you will be fine.

Please note that doxygen will by default parse documentation on header files only, which is where you normally make the documentation!

After you are done documenting your code, you can run the doxygen GUI application to generate the HTML automatically. Like a sir!



Documentation comment


In C++ you normally make block comments /* ... */ and line comments // ...   , doxygen will ignore these and only parse block comments as /** ... */ and line comments as /// ...

Making a series of line comments will generally work as a single block comment.

Documentation indicators

When documenting your code structures, inside the doxygen comment blocks, you usually need to denote what specific detail you are documenting.

For that, doxygen accepts a few indicators, which I will explain next, that may be started with \ and(or) @.


Document a file

To describe a file you may make a doxygen comment, as stated previously, anywhere in that file, as follows:
/**
     \file header.h
      This file is all about doing.. hmmm. stuff.   
*/
Then it will appear in the file listing of the documentation page.

Document a module

.. Also called a group, it allows you to make groups with your structures, so you can easily denote what belongs where. In its simplest form, you can define a group anywhere like this:
/**
        \defgroup Graphics
        This module contains all graphics related classes.

        Cool text here to look like a mr. fancy coder.
*/

Document a class

It is a good practice to document things like a class, a variable, a method, etc by making a comment exactly before it appears in the header file. It is very desirable to follow that practice, both because it looks really neat and because in some cases doxygen will simply know what you are trying to document, without specifying it, just because it comes next. This is important.

Now the example:
/**
    \ingroup Graphics
    \class MyClassName
    \brief This is a short description, which is shown in the class list in the documentation page.

    This is a more detailed description, with a lot of details about my class.

    \author I am the author!
    \date when i made it!
    \see MyOtherClass
    @author Also works to tell who did it!
*/
class MyClassName{};

The \ingroup will make sure the class belongs to Graphics module from the previous example. You may include a class in many groups.

The \see line will make a link pointing to the other class documentation page.
I think it explains itself if you read the example, but it will become cleared as you advance the tutorial.

Document a method(function)

Something you probably will be doing a lot is to explain what your functions does, and what should be in mind when using it. Following the rule of documenting the method before it appears, check the example:

/**
     \brief Counts the child nodes of a tree node

     A more detailed description.
     \code
          A C++ suggested usage.
     \endcode

    \param recursive Whether the call is recursive and therefore counts each child's child count.
    \return an int with the count
*/
int countNodes(bool recursive);

As you may see, you can use \brief to define the "headline" of what your function is for.
Then, you may describe your function's ways. The \code ... \endcode block will force a C++ like presentation in the document page, with proper indentation and highlight of the snippet.

Document a namespace


You can give detail about each namespace you declare, just simply as:

/**
     \namespace global_namespace

     All things in the library go into this namespace.
*/
namespace global_namespace{}

Document notes and warnings


Usually when documenting something, you may want to leave a note, with more highlight, so the reader pays attention:

/// \note my note

And other times, it is really imperative that the user gets your message, so you highlight a warning:

/// \warning CAREFUL WITH THE EGGS!

Document a "to-do"


When you are documenting a function or anything else, you may suddenly remember it lacks something, or there is just a detail that needs changing, whatever, but you can't do it right now.

When that happens, you may leave a todo note, and there will be a page in the documentation with all things that are left undone, as specified by you. To leave a todo note, just do:

/// This function is very crazy
/// \todo Complete this function support for eating brains of farmers
void func();

Document a page

In the documentation HTML, you find an entrance page, that you may use to write anything you want as an introductory page. It is important to fill this in to give details about the software.You can do it:

/**
      \mainpage My Software main page

      Now you're writing content to the entrance page..

     You can add sections like:
     \section Overview Overview
   
     And now this is under a cool header title.
*/


Besides the main page, you can create other pages named as you want, which will go under Related Pages tab in the documentation HTML. It is pretty much the same, but change the indicator you use.

/**
     \page FAQ

     The most frequently asked questions and its answers.
*/

Finish


After reading this, I recommend that you do some experiments to get confortable with using it.
Just go to http://www.stack.nl/~dimitri/doxygen/ and start your journey, its a funnier task to do than you may think.

This was a really simplified guide, but if you think anything is wrong, missing or lacking, just inform me and I will change it!













Friday, February 17, 2012

C++ Tutorial: Interfaces and virtual classes, Singletons and Exclusive ownership classes

Today I will try to help some people understand a little better about object oriented programming(OOP).

I won't do really in-detail explanations of the code, but actually try to explain the concept of taking these approaches from a software design point of view.

Let me just warn you that the names I may call to these concepts may not be the official recognized names, but that is not the point of the tutorial.

To begin, I would like to explain the common knowledge concept of an Interface.

An interface is when you create a class with some functionality, but leave the implementation abstract, without being defined.

A perfect example would be an interface class IRenderer, that would have methods to initialize the graphics library, to render shapes, models and everything else a renderer needs to do.

Then, you would inherit from IRenderer and implement all the methods, to actually make it work with a specific graphics library. Making a COpenGLRenderer and a CDirectXRenderer would be logical, for example. Each would implement all methods in IRenderer, both using different API's.

A purely virtual interface is when the base class, in this case IRenderer doesn't do anything on its own and can't even be instanced. This happens if the methods are declared as "virtual <type> <name>(<params>) = 0;" and you don't define its body at all.

Otherwise, you can have a virtual class that already works and does something, but can be extended by reimplementing those methods.

Singletons


This concept is also widely known, but often applied erroneously. Sometimes you have a class that you want to ensure that it is only initialized once. There are actually different approaches to do this, but i will recommend one that I find specially effective.

You could make all methods and variables static, which some may consider a dirty solution, since it is not the most safe solution because the unpredictable global initialization of a program. It can be avoided but normally demands extra checks that impact performance without necessity.

So, the first thing I recommend is a private constructor. A private constructor is very very useful because it will ensure that only a member function or a friend class can instantiate this class.

That means immediately you cannot do something like "MyClass object;", you will get compiler errors.
Though, you can create a pointer to it "MyClass* object". Now you need to make it valid, so you request its creation "MyClass* object = MyClass::create()".

MyClass::create is really a static method of MyClass. That is why you can call it without having an instance before. Besides that, it belongs to MyClass so it may instance it.

Here is a sample class of this lesson applied:

class MyClass{
public:
      int getNumber();

      ~MyClass(){
             myInstance = NULL;
       }

       static MyClass* instance(){
              // Could instantiate on demand..
              return myInstance;
       }

       static MyClass* create(){
              if(!myInstance) MyClass(); // create an object so it becomes the static instance
              return myInstance;
       }

private:
      int number;
      static MyClass* myInstance;

     MyClass(){
           myInstance = this;
    }

};
MyClass* MyClass::myInstance = NULL;

Hope you understand and make profit of using this!

To finish, in behalf of this understanding, you can easily create a class that can ONLY be created by specific classes. Just make the constructor protected or private so it cannot be instanced at all.

Then, any class that you want to be able to instance your exclusive creation class, just declare it as a friend class.

...
private:
     friend class ThisClassMayInstanceMe;
...

If you know what i mean!

Hope it is clear for you! Any doubts, suggestions just contact me!

Good coding.

All is going well!

Good news, the engine is going great, and is looking better than ever, the game is also improving natural just by the fact that the underlying technology is getting better !

The basic systems of graphics are pretty much working good now, libRocket support was totally refactored and it now looks amazing! Let me explain,

There is a RocketPlugin class to control libRocket completely, becoming the interface with it.
You don't need at all to refer to it on basic usage of the module, what you need to know is the RocketContext class. 

When you instance a RocketContext , you are immediately ready to load documents, update and render them.. Whats funny about it is that until you do so, libRocket is completely unused and therefore not leaving a footprint in the program performance. When a context is instanced, if library was shutdown, the RocketPlugin will ensure its proper initiliazation with all custom systems it has. When the last context is destroyed, it automatically kills the library again. I guess this works well for all cases :)

If anyone needs help on implementing libRocket feel free to contact me! I 've got mine working very good with SFML 2.

On a informative note, the Demon Eulogy Games website is for now located at: www.demoneulogy.comze.com

It is still under construction!

Sunday, February 12, 2012

Demon Eulogy

Soon or later I will need a name to publish my stuff under, so I've been thinking what could i call it...

After some thought I decided to go with the name "Demon Eulogy" for the to-be company! I think its a sticky name that I won't get bored right away.. Anyway its the first, it can always change later if required!

That said, I made a little drawing just to materialize an idea, related to the theme and you can see it below. It is a rough sketch for now, but in the line for a digital painting version of it .
I also think i will make it the "logo" of the wannabe "brand"..


It represents a etheric body of a really wicked person. It behaves and looks exactly as the person thinks in its daily routine. I called it The Judge, due to its nature. Possible spoiler: it may be included in any of my games :p


So, in the near future i need to:
 - Make a website for the company
 - Make a website for the upcoming game
 - Improve the engine's website and online documentation & release versions
 - Make a lot of blog posts about the exciting things that will happen ehh :p
 - Finish the game!

Saturday, February 11, 2012

News 10/02/2012

These days have been tiresome working both in the game and in the engine! 
At least I can say that the Foundation module is nearly finished, missing only some testing and possible tweaking/improving.

Also I started to do the same into the Graphics module now! 
I am doing all I can to publish a good software to work with! I've seen it as good before, but the more I learn, the more I improve it, being that I am really satisfied with some parts of it!

Big changes are expected soon enough..

More important: I have created a new system for the engine, which will be majorly useful when making all kinds of games! It is a little "cutscene engine" if you may call it that.. To briefly describe it, you get to write a movie in a pseudo-scripting language. You do it by controlling the movie execution step by step with a curious system that I bet you will enjoy! In the current game, it is used in the Intro screen, where a scripted cutscene plays and when it ends, advances to the next screen. The cutscene is also skippable by pressing Escape.

More about the movie system later, with possible examples, as it isn't completed yet.

The game is a little bit more evolved too, it starts on a intro screen as said before, which plays a movie. 
Then, when it ends forced or naturally, it delegates authority to the profile screen. It will try to read the game's persistent data, if it finds a "favorite" profile name, it will proceed with it before you see anything, otherwise, you are in the profile managing screen. After comes the main menu state, where you will be able to configure the game or continue your mission progress.

More info soon!