Jump to content

  • Log In with Google      Sign In   
  • Create Account


Member Since 08 Dec 2011
Offline Last Active Sep 27 2016 02:36 AM

#5311379 Multi thread rendering engine

Posted by on 19 September 2016 - 05:08 AM

There are literally hundreds of possible architectures. I tried to implement a multithreaded engine and here's what I almost achieved (Almost because I had to stop it for working):

What I tried:

- Client creates render queues

- The engine compile renderqueus (read as: optimized sequence of GL commands)

- The render thread execute GL commands without any locking at all (it just need to lock when swapping the pointers to renderqueues.)


- Compiling commands has little overhead, I have pretty low level abstraction, maybe a higher level abstraction allow to generate

already optimized commands, but I can grant you that I had tons of troubles to get something simple like that correctly syncrhonized anyway


- Renderthread do not block main thread

- Mainthread do not block renderthread

- Reduced lag between input and visualization (seems counterintuitive, but yes using only 2 threads gives better responsiveness even if in theory you have to wait for the queue to be processed, in reality a queue is created almost always before the last queue has finished rendering)


I think a fully real multithreaded engine is possible but would require so much work to squize only few % performance improvement (And note most low-end machines just have 2 cores anyway) that is not worth, achieve something like my solution (3 years of trial and errors and preparation to just create a proof of concept) is already too much effort, and since everyone want to make his engine there's literally no more interest in custom engines anyway.

Wait I search for my thesis slides to give you idea:

here it is:


This is a really simple solution, not really multithreaded, but gives a nice boost in performance and is already much more complex than a single threaded engine.

#5302594 Rpg Stats - Temporary Changes, Harder Than I Realised!?

Posted by on 26 July 2016 - 02:47 AM

Use memoization/DRY, so do not store the final value of the stat. Instead recompute it each time it is asked.

So each effect to a stat is:

enum class StatAffectionType{ 
    BaseStat, Buff, DeBuff

struct StrEffect{
    unsigned int amount;
    unsigned int millisecondsLeft;
    unsigned int priority; //order in wich changes are applied 
    StatAffectionType type;

class Character{

    std::vector<StrEffect> strArray;


    int GetStr(){
        int str = 0;
        bool someEffectFinished = false;
        for( auto effect: strArray){
                case StatAffectionType::BaseStat:  
                       str+= effect.amount; 

                case StatAffectionType::Buff:
                           str+= effect.amount;
                           someEffectFinished = true;

                case StatAffectionType::DeBuff:
                           str-= effect.amount;
                           someEffectFinished = true;


        return str<0? 0: str;    

You can cache the result once per frame but it should be cheap by just ask it each time. In this way you avoid all kinds of bugs, note that even Morrowind and Oblivion had tons of bugs related to temporary stats, so I would go the "slow" but safe way, and later optimize only if needed.

If you use  a sorted list you do not need to sort, (each buff will be inserted at right position), I think this is one of the few cases where sorted lists are usefull.

While I agree this can be considered a monolitic class and some purist would refactor so that each effect has its own virtual class, consider also that as long as kinds of effects are limited in number you have just one place to check regarding your Str stat, so I would consider that a dirty code, but dirty on purpose.

#5299130 Yet another 'Best engine' topic

Posted by on 05 July 2016 - 05:55 AM

Exerion, I would have suggested Unity, however they recently increased the yearly cost (just too much for me in example to make a living out of unity only games u.u) so instead I suggest you this unity-like (but opensource) project. i'm planning to make a RPG too (but isometric anyway). Anyway the official tutorials are basically there to show the great (dis)features (like missing a good way to pause mecanim animation) and not to teach you making games, the only way to make games with unity is making one simple and improve along the way, I never read books nor used the tutorials (though I have already made games with other frameworks like irrlicht) and I think you don't need them at all. Do something, when you find you are stuck search on Google or ask for help and you'll get to next step.

Unity itself is not bad, and the only downside for a simple 2D game is the package size (10MB even with no game at all), but they increased the price once, they would probably do that again, what is bad with current pricing is that small indie teams will have hard life because if they touch 100.000 revenue  exactly they start spending a lot of license, while if you are alone or on a big company this is not a problem, this is a problem for poeple that actually spreaded the unity word (so the small indie teams)

here it is, Godot engine:




#5269517 Criticism of C++

Posted by on 05 January 2016 - 06:14 PM


I seriously think someone should re-think C++ from scratch instead of driving away into another language.

A 'rethink from scratch' would just give you another language.

Anything which breaks backwards compatibility is a new language.

End of story.

And people have tried, D which was brought up earlier is this indeed incarnate, yet it has failed to catch on.

A 'rethink of C++' is no longer C++.



I think you should take my words with much more immagination. D is substantially different, C++ has different goals and try to keep them by forcing backward compability, what if C++ had to be designed nowdays from scratch? It will result in much more clean, simple and performant language with less maintenance burden both on client and compiler side.

#5269370 Criticism of C++

Posted by on 05 January 2016 - 03:53 AM

People easily complaint about C++, but barely are able to propose and argue solutions about them (especially without smashing the purpose of the language).


Especially when the solutions are not well-received or even hard to maintain tongue.png. I seriously think someone should re-think C++ from scratch instead of driving away into another language.


There should be no more attemp anymore to keep backward compability (in example "template" vs "typename"), most times keeping compability introduces ugly syntax and complexity both on compiler and client side.
The resource management should be always explicit with nice syntax to give away ownership (without resorting necessarily to smart pointers or move semantices

int *a = new int[15];

function_call( give a);

function_call( int * a ){

  // do something.

  IF( MINE(a)) //link time directive => act as a different overload of function_call when
               // "a" ownership is gave away. (when no "MINE" overload present, warn about "a" not disposed.
     delete [] a;

and get compiler warnings if a owned resource is not disposed (including allocated memory) with no GC at all, templates can be made much simpler and we could get syntax for certain features provided by SFINAE and a decend module system.

Also the language should be thinked for supporting better debuggin, exceptions (I mean no issues like DWARF vs SJLJ that force users to target 2 different binaries at least with GCC), and in general better integration with code-assist tools so that syntax completion becomes easier and faster.

Link time conditional statements could be used to avoid writing a lot of duplicated code, the optimizer will just decide if resolving into 2 different functions or just generate hidden boolean parameters (also that would allow iteratin FOR_EACH over pointers without having to passing manually the size and enable native guards to prevent buffer overflows if wanted).


Instead of writing 2 constructors it could be nice if "moved stuff" has a more usefull behaviour (moving is just copying of all values and poitners and automatic ownership transer, the object from wich we moved should just fallback do a "deafault constructed" object that allow in many cases to avoid writing a 2nd copy constructor and a 2nd copy operator).


I also want better module system even for templates. If I include "std::Vector" (I would not call it "vector" but Array or DynamicArray) I do not want to pollute my namspace with all side included headers of std::vector. The header of "std::vector" should just be a interface, not the whole implementation

Here's a possible example of missing ownership.

int main(){
  int *a = new int[15];

  function_call( a); //thanks to link-time flags compiler know "function_call" will use "a" un-initialized and is able to dispose it. 
                    //seriously no introspection needed at all, just look at dependencies flag when linking and with ability to set a 
                    //compiler flag to stop re-linking when behaviours of subroutines changes 
                   //(in example a subroutine of function_call may initialize "a" after a code change
                    // "a" but we don't want that to go unnoticed so we could examine better the situation)

  return 0;  

/*COMPILER WARNING:: "a" is not disposed (file:line), "function_call" is able to dispose it if ownership given
 or instead you must delete "a" before exiting the "main" scope. 
  COMPILER WARNING:: "a" is not initialized  when first used inside "function_call".
  Linker will now assume "main" want "a" to no be initialized inside "function_call"*/

//after a code change:

/*ERROR:: code previously compiled with the assumption that "a" is not initialized inside "function_call" may now be broken because of
    "subroutine_1" now initializing "a". You can recompile "main" or just suppress this error with "-AllowsUpwardLinkFlagPropagation" */

Example to enforce ownership transfer and no initialization

function_call ( noInit give a);

#5269162 Criticism of C++

Posted by on 04 January 2016 - 03:57 AM

I always used C++ for years, it can be used in right way, but seems "the right way" is not for most common and used libraries wich just have awful issues (that could be avoided easily), one point still holds, you can setup a cross-platform toolchain in a really easy way (just unzip something somewhere) with C++, even if having such toolchain do not avoid you to write ad-hoc source code for each target you can at least start more quickly than other tools (I had pain times setting up libGDX in example). Another bad point is standard library, it just gets even more complicated at each language version and it is not to be expected to have something like .NET framework (even in part) for C++. Still .NET framework is missing lot of funcionality and sometimes I had to write my C# piece of code anyway. No language is perfect and is hard to predict if a choice will reward or harm you on the long run. Standard library has its use but its the only one I have to continuosly check against some reference for examples (while in C# there are fewer concepts so once you get grasp of basics you are done with autocompletion, in C++ you still have to check carefully all side effects for exception safety, iterators etc.).

What I think is that C++ could be a much better language if there's much more good code around to learn from, instead people tends to stick with junky code and write junk again by copying it.

#5262317 Integrating a scripting language

Posted by on 16 November 2015 - 03:39 PM

Base it on your preferences. I tried already lua and prefer it. Angel script may be a bit easier to debug while lua has real coroutines and I think is faster (especially last lua release).
There are out there lua editors for sure, don't know about angel script.)

also consider dependencies, if you want to use lua, you want for sure to use also an additional C++ framework to automate most binding tasks, while angelscript have that feature natively


also note that based on my experience Angel script is not a full fledged OO language so if you are used to stress limits of the languages you use (in example you go heavily with templates and reflection in C# and metaprogramming in C++) then probably you will find better with lua because thanks to its "dynamicity" allow to overcome the limits of the language. Said that, you have to try both.

I think I'll try Angelscript now, I just saw it has Cmake script => easy compilation rolleyes.gif

#5261126 Inversion of control across libraries

Posted by on 09 November 2015 - 08:37 AM

You are getting that wrong. Dependency injection is one thing, Inversion of control is another thing.

first of all you have to get clear what a dependency is this depends also on the language:


CodeLevel Dependencies:


-You are dependent on headers that a class include, every header may add extra compile time and may break code because you inadvertently use some of the indirectly included headers.

-If you properly design code you increase number of dependencies => public interface, header of concrete class, implementation of concrete class



- importing is more about resolve name ambiguities (infact if you import a class, you do not need to import returned types of methods)

- no separation of implementation so if you have a interface you get only 2 files not 3 like in C++.


Class Dependencies:

The proper way to manage dependencies is to pass ALL YOU NEED to class constructors, and (most times) use some interface or abstract class to separate construction from behaviour (when you create a concrete class, you have code dependant on that concrete class, but when you pass the class around you are only dependent only on its interface).


You need to pass stuff by interface into constructors => that make the code damn easy to test (you can implement the interface with a mock and test the behaviour of the class using that interface).


Inversion of Control:

Hollywood principle, don't call us, we'll call you. When you do not have control over "main". Usually there are complex frameworks that provide a lot of functionality you have just to implement some interface and you will get called. Usually this removes a lot of control from you and most times it is hard to make such frameworks cooperate each other, usually those frameworks are something really big that do a bit of everything (Unity3D, Qt etc..)


Inversion Of Control applied to dependency injection ( aka DependencyInjection framework, aka InversionOfControlContainer)

This is especially important when you design code only around behaviour (you don't mind where a class is provided, you just assume the class is present). You will find designing code this way leads to simpler code because you have "to think less"(the first times you think much more, but after you get that everything becomes even more natural). But then how do you glue the code togheter? that's responsibility of a dependency injection framework. I think the bests are the ones that are lightweight (it is very possible to provide so much functionality in less than 2000 lines of code, i believe some have around 1500 infact).

Think to irrlicht, you have a IVideoDriver, a ISceneManager a IGUIManager. All these classes are created from a root (IDevice), since irrlicht do not use a proper framework you have to create the root from a C-style function, then you use the root to create other usefull classes, and if you look at implementation you will find that the root is creating stuff by calling constructors and passing zilliong arguments to the classes, if it has used a dependency injection framework irrlicht would not need any root, instead you just create classes that take as constructor parameter only what they need, that would have resulted in much simpler code both on engine and client sides (just most software from 10 years ago in C++ never use a proper framework but instead do Dependency injection manually in some way)

#5252334 Attribution problems on Github

Posted by on 15 September 2015 - 04:54 AM

Shouldn't be letting people believe you are the wrong author illegal?


Would that suffice?

modified MIT LICENSE:

Copyright (c) <year> <copyright holders>

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice, this permission notice and all additional

clauses shall be included in all copies or substantial portions of the Software.



Additional Clauses:

- This pemission is licensed by following Github user:


- This permission originated from following repository:



#5252322 Attribution problems on Github

Posted by on 15 September 2015 - 03:44 AM

I recently noticed a bad trending on Github projects, it is probably simpler explain with a example:


A person wich name is "XYZ"  creates a cool Github project and call it "AwesomeLibraryXYZ". That person has a Github account wich has its nickname (let be it "LazyFoo").


Now another user wich name is "Bababababa" register into github and choose as nickname "XYZ". He choose to fork AwesomeLibraryXYZ, and leave it untouched.


Then "Babababa" starts showing its portfolio where he mentions "contributed to XYZ project". While a Github user will know that project was created by person XYZ wich has "LazyFoo" as nickname (it is obvious for github users since every project will have "forked from" tag), someone extraneous to github will errouneously attribute to "Bababababa" the creation of AwesomeLibraryXYZ because the account naming is similiar to copyright notice.


However "Babababab" never explicitly told he created the project.


What should then do the original author for AwesomeLibrary XYZ?


(Also keep in mind there are mirroring services for github, like travis or biicode that just link to a repo, but not to the repo from wich it was forked and those services just allow to increase attribution confusion because they not mention original author link.).

I personally have been victim "once" of something similiar, where someone was twitting about my repo and he had a photo similiar to my avatar (I suddendly registered to twitter and started replying to all his tweets until people noticed I was the original author and the ripper stopped tweeting, note that he never told "I made that" He just linked the repo in tweets and people was thinking he was the real author, and I had hard life tweeting each of them until they understood I was the real author).


Right now I see the same trending all other github, there are "furbish" that hunt for inactive repositories, then they just fork/clone and start coding, they never mention in README "I decided to continue the work of XYZ because I liked too", they just leave copyright notice and let people attribute wrong author.


It is very possible some of them just don't want to be threated as the original authors, but I think some of them may "like" to be disguised as original authors and may just say "I did not that" only if directly asked to avoid legal issues but they are happy if people confuses them with original authors.


Is that legal? what someone can do to avoid that?

#5203513 Triangles can't keep up?

Posted by on 11 January 2015 - 12:49 PM

Use point 1 point for each particle and a geometry shader to create a quad from that point




Note that it can be a synchronization issue. There's no one that guarantee you are reading data from Frame N-1 and writing data for Frame N+1 without any synchronization primitive.


Using geometry shader you don't need synchronization (well even if data get wrong by few frames, using only 1 point, you'll never notice it ph34r.png