Welcome, Guest. Please login or register. Did you miss your activation email?

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.

Topics - man'O'war

Pages: [1]
Graphics / Estabish a rendering order within a same entity
« on: March 02, 2017, 04:07:14 pm »

I've recently started using the Quad Tree in order to render the objects of the scene, which makes it a bit dependent on the physical location of the objects, isn't it ?
Closer objects are drawn in front and  farther object are drawn into the back side.

Beside that, i've added a Layer attribute to the objects to create a discrepancy between them. Each one on its own level. ( layer ).
This is perform by creating as many quad_tree as the total number of existent layers.
Now before exposing the problem that i am facing: here is the render call sequence 

void Scene::draw(){
    //  decl: std::vector< quad_tree* > quad_heads;

    for( int i=0; i<static_cast<int>(GoLayer::LayerCount); i++){
        gdf::kernel::GameInfo::game_info->sf::RenderWindow::draw( *(quad_heads[i]) );

Every QuadTree node's content holds a pointer to the GameObject to draw.
The QuadTree is generated when the Scene is updating all GameObject. ( Hierarchical Tree structure )
void Scene::update(sf::Time dt){
    // .......
    if( !root_.expired() ){

        for( int i=0; i<static_cast<int>(GoLayer::LayerCount); i++){
            // PS1
            quad_heads.resize( static_cast<int>(GoLayer::LayerCount) );
            quad_heads[i] = new quad_tree( AABB(sf::Vector2f(500,500), sf::Vector2f(500,500) ) );


PS1: The reason here. Is that i am deleting and recreating the quad tree structure every iteration ( I don't know if it is the right way to do it )

When update method is invoked on the GameObject (root_). It will recursively build the QuadTree based on the Layer value of the GameObject accordingly.

void GameObject::update( sf::Time dt ){
    // .....
    scene()->quad_heads[ static_cast<int>(layer_) ]->insert( QuadTreeNode<GameObject>( position, this  /*pointer_to_go*/) );


What if i want to create a specific rendering logic,
For example, within the same entity ( Entity here refers to a sub-hierarchy of game objects ).
I want to make a specific rendering order totally independent from the positioning of the sub-gameobjects.

Here is a schematic

This diagram represents the physical location of the GameObject within the scene.

This diagram is the Hierarchical Tree for the same structure ( Used for updates )

As for this one, is the QuadTree generated.

In @Diag 1, the entity here covers all the objects within the blue dashed square. having as a parent object n°1.

Now the situation is : If the logic says: object n°3 must be on top of object n°1. and somehow, the texture/sprite of the object n°3 is big enough to interlace with n°1's texture. In this case using the QuadTree rendering policy, the object n°3 will be behind the object n°1 ( due to positioning criteria ).  Same for n°1 and n°5 ( with opposite context ).

My point is, i want to make beside the QuadTree rendering policy, a relative rendering order within the same Entity.

Hope the idea was clear.

Audio / Cannot load a sf::SoundBuffer
« on: February 22, 2017, 09:49:02 pm »

I encountered some never-seen problem that, i dont know if it is an issue from my computer or not.
By creating a SoundBuffer and loading a file into it, i'll have these messages poping up.

Cannot lock down 82274202 byte memory area (Cannot allocate memory)
Cannot lock down 82274202 byte memory area (Cannot allocate memory)
Cannot use real-time scheduling (RR/5)(1: Operation not permitted)
JackClient::AcquireSelfRealTime error

i've looked up trying to restart the jack server, because at first it was telling me the jack server could not be started.

I'm running Ubuntu16.10 using SFMLv2.4.0


Window / Multiple Renderwindow support.
« on: August 22, 2016, 11:14:34 pm »

I dug a little about this and i found a non answered topic .

Knowing that we can set multiple viewport using sf::View
I was wondering if it is possible to create several non static objects of RenderWindow simultaneously. Is it safe ?

Regarding the refresh of the windows. round-robin policy can be used as starting policy.


SFML projects / GDF - GameDevFramwork
« on: August 21, 2016, 12:43:23 am »
Hello everyone,

I would like to share a framework i am currently developing which is dedicated for 2D game development


The story began when i wanted to develop a game like Secret of Grindea. great game by the way :3
As you may definitely noticed, when starting up a game for the first time, at a certain point, your code starts to become heavy in a way that, it is not flexible anymore. It works only for what you've made and any future changes, or adding new ideas requires major changes in core code. 
(click to show/hide)

This is why it is necessary to structure your code, and create some base classes to manage your game, before even creating your first asset.

I was inspired from several references, such as the SFML Game Development ebook from packtpub. It was very good to start with, but does not have a flexible structuring of code.

What i mean by flexible structuring of code, is that, The game may grasp almost any kind of new concept/idea without having to make changes in core code. (or at least very few changes)

I've also tested UDK and Unity (documentation), which they helped me a LOT to learn more about organizing things together. Especially the GameObject/Component pattern.

The GameObject/Component design makes your game entities INCREDIBLY flexible.
Will be discussed later

GameDevFramwork (GDF) is an open-source C++ framework for 2D Game development extending:
  • The SFML library 2.3.2
  • Box2D Library 2.3.1: for physics
  • Qt 5.7.0 : used for the meta-object system ( i will find a new non-qt replacement for that )
  • and more ...

More .... ?
Yes... The purpose of the project is to build a totally modular open-source framework, by providing a set of base classes ( kernel module ) to make it possible to accept and easily integrate newly created modules.

The Kernel module
The kernel is a minimum set of classes that implements the core of the framework,
Here is the class diagram of the kernel

starting by:
  • GameInfo: Class that defines the application logic, how to initialize, handle events, update and draw the object.
  • Scene: The scene class provides a way for creating and organizing items(GameObjects) in a tree structure.
  • GameObject: GameObjects are the main items for scene's nodes, every thing on the scene is a GameObject. However, GameObjects have no concrete representation on the scene, they are nothing but containers for Components
  • Component: A component is an object that defines a specific logic and is attached to certain object ( such as GameObjects ),
    • HierarchicalContainer: This class provides a multi-root tree structure in order to organize Components. And any class that inherits from this class becomes a container for Components, as it is for GameObject, Scene and GameInfo
    • Transform: A Transform is a component that provides a GameObject with a 2D Coordinate system (position, rotation, scale) and, organize it in a Tree-Structure ( Parent/Children)

The GameObject/Component pattern allows the creation of a meaningless GameObject. And its context is defined by the logic carried by its components. Components can be added and removed at will.
For example
It can be seen as, equipping your hero (GameObject) with different weapons and skills (Component).
If you give your hero a sword, a helmet and a shield, then you've made a Warrior. But if you give him a staff, and a spellbook , then you've chosen to be a Sorcerer, despite it is the same GameObject.

    GameObject* hero = GameObject::instantiate();
    // Choosing to be a Warrior

    // Choosing to be a Sorcerer
    // or ...
    Spellbook* spell_book = hero->addComponent<Spellbook>();

What if i want my Sorcerer to have not more than one Staff and one Spellbook. And cannot have a Staff without  wearing a Cape ?

Well, thanks to the KernelRules class that defines a set of rules ( dependency relationship between components ) in order to check the satisfiability of the add and the remove actions.
In other way
rule: X → A, B, C
A Component X cannot be added inside GameObject G if A, B, C Components are not available within G
A Component A cannot be removed if one or more other Components depends on it. ( herein, X )

    create_rule("Staff", "Cape");

make_singleton creates a cardinality rules, imposing the (HierarchicalContainer) or GameObject to only accept one instance of a given Component-type. Herein, "Staff", "Spellbook" are limited to one instance each.
AS for, create_rule method, it creates a dependency relationship between Staff and Cape, telling that, Staff depends on/ requires Cape to be available first in order to be created..

There are pre-defined rules applied for built-in components in order to ensure the good functioning of the kernel module

By taking advantage of these methods, and of the generic implementation of the GameInfo, any kind of component can be attached to the GameObject.

Herein above, one elementary cycle of the gameloop.
Based on timestep update. Each elementary cycle, the GameInfo
  • Handles application events
  • Performs regular updates of the Scene
  • Performs physics-related updates of the Scene
  • Performs (late) update of the Scene
  • Then proceed to rendering.

Minimal example-code
To start in with the framework,
You must create a sub-class of GameInfo and Scene. ( And also override pure methods )

Note that, i am not using too much 'getters' in my code, but accessing data members directly, this is why some instruction are too long. 

(click to show/hide)


(click to show/hide)


(click to show/hide)

(click to show/hide)

Adding a new Component: the pre-declared MoveObject
g0 had a component called "MoveObject" that makes it move in the scene. i.e
  • MoveObject is retrieving the Transform Component of g0 in order to apply a translate.
  • MoveObject requires Transform: i.e:
create_rule("MoveObject", "Transform");
  • must be defined in KernelRules
  • MoveObject is systematically initialized, updated and drawn if necessary thanks to the GameInfo & Scene.

Here is the implementation of MoveObject

(click to show/hide)

(click to show/hide)

A MonoBehavior is a Component with more features than a regular Component, it is the base class for user-components
Note that a GameObject cannot be overriden. 

Built-in Components
In addition to the kernel module, there are some built-in components used in order to create basic objects, like:
Graphics, Sounds, Animations & animator, Shaders, Physics , Colliders, Joints, Gui, Renderers, AudioListener, Cameraetc.

Modules... as addons
Creating new modules and integrating them to the framework is very simple.
What needs to be done is to
  • Define your set of Component-classes
  • Attaches them to the right Container
And they'll be fully functioning. ( as long as Component's methods are overridden and used )

I've made aside some external modules to implement new functionalities for the framework.
resource management module
Resource management module offers a set of classes in order to load, use and unload resource automatically avoiding any kind of memory leak.
  • Resource Manager: The resource manager keeps track of all loaded resources, and manages their lifetime. i.e Allocating when it is required, and deallocating resource whenever it's not needed
  • Resource is the base class for all resource.

The resource manager unloads resource in a safe manner, means that, if a resource is still being used by any object, it cannot be unloaded. This is achieved using smart pointers ( the use_count member of std::shared_ptr ) . See, documentation for implementation details

time management module
The time management module define concepts about time.
the main classes of this module are:
  • Chrono: Is a component that gives an object time properties, and become part of a timeline. ( spawn_time, lifetime etc )
  • TimeKeeper: Is a GameObject's component that records the timeline of a GameObject, i.e recording the past of the GameObject. This technique is Events-triggered rather than Time-Events ( Continuous recording )
  • TimeWinderThe TimeWinder is the core Component of this module, it manipulates the time of any GameObject. Time freeze, time reversal,  normal play with a play factor. 
  • Event Is a base class for time related events, used by the timekeeper to record the timeline, they define the type of the event it happened, the target object, the previous value before the action happened, and the new one

exec ....
When the TimeWinder is launched ( eventually from the scene ), it retrieves all the TimeKeeper Components of all GameObjects. And plays the recorded timeline of each GameObject backwards, by generating an opposite event of the one initially recorded. Thus, simulating a backward execution.
However, any property that needs to be affected by time must have a dedicated event and must be called at the right place.
  • VelocityEvent: Stores velocity data ( old, new, target, timestamp )
  • TranslationEvent: Stores translation data ( old, new, target, timestamp )
  • ValueChangedEvent: Stores changes in value ( old, new, target, timestamp )
  • ....

In the diagram above, it displays the stack's content of the timekeeper at time = ti. The stack is divided in two part:
Events from the past, and events from the future

On a normal play, the timekeeper registers time-events in the past part of the stack, as shown on 'normal play' case

When entering a time manipulation session. The timekeeper stops recording events.
- ON BACKWARD PLAY - rewind: The timekeeper pops events one by one from the past, and pushes them onto future.
- ON FORWARD PLAY: The timekeeper pops events one by one from the future, and pushes them onto the past.

This allows to go back and forth in time at will,

When the session ends, events from the future are discarded, and time keeper starts to record new events.
Similar mechanisms of time manipulation can be found in the game Braid, steam link:  http://store.steampowered.com/app/26800/.

And so on ....
As future tasks, I am willing to add and/or integrate already built modules to the framework
  • IA Algorithm: Search algorithm, Dijkstra, A* etc.
  • Complex Systems algorithms:  Artificial Neural Network, Celullar Automaton, Swarm intelligence etc
  • Parallel programming plateform - open-mpi: Can be used in combination with IA & Complex systems.
  • Interact with an Arduino Board: Makes it possible to communicate with an Arduino-board through the application,

    As a sample, Making a LED blink whenever a GameObject leaves or enter the Viewport of the Camera .
    simply by using the Renderer's callback functions 'onBecomeVisible' and onBecomeInvisible', to send a message through the serial port to the arduino. See, ArduinoTest in source code

There is not a lot of things to display right now, but i can show you a sample of the time management module. ( Time Reversal mechanisms )
c.f Attached video.

The video shows Time Reversal mechanism. The scene contains 2 (Chicken=Cockatrice) GameObjects (  c.f RPG Maker Sprite ) spawned at the same location.
One Cockatrice does not move, while the other is moving under constant velocity ( x-axis only ) for a short period of time ..

  • Whenever the user presses the left mouse's button, it teleports the cockatrice to the cursor position.
  • When Left Shift is button is held, time reversal starts, on release, time goes back to normal.

  • The Cockatrice starts moving positive x-axis due to pre-applied velocity. Then teleports several time to cursor position ( while it keeps moving )
  • After a short period of time, the Cockatrice goes to idle state ( stops moving )
  • [Time Reversal is triggered at this moment- LeftShift pressed]
  • The TimeWinder is executed causing the Cockatrice to play its TimeLine backward. Until its lifetime reaches 0. Thus, its state will be the same as it was on t=0.
  • When time reversal is canceled - Left Shift released
  • The Cockatrice will start to move again as it is its first time

Content of the Log window
What is displayed at the terminal is:
  • Current applied rules of the KernelRules class

(click to show/hide)
&#8594; means → : The forum cant draw it ?!! ( or may be it is inside 'code' block )
  • Added Components for each Object
(click to show/hide)

  • Content of the Resource Manager (loaded resource)
(click to show/hide)

  • Event recording ( Normal Play )

(click to show/hide)

  • On Time reversal ( Backward Play )

(click to show/hide)

  • Stops the time reversal ( Left Shift released )

(click to show/hide)

The framework is designed to be fully open-source and community repo,

I designed a minimal kernel to be used as a starting point for anyone who wants to develop modules from scratch.
However, built-in modules can be included at will depending on the type of the developed module.
You are welcome to:

  • Suggest Code improvements ( as i'm writing very basic things right now to get a global architecture, then i'll refine every class ) [Note that kernel is refined but incomplete (still in progress) ]
  • Suggest modifications about the kernel or an existing module.
  • Suggest your own modules. even if there is an already existing one,
    There is no better code. but one can fit better than the other, depending on the problem
  • Platform portability, { currently tested on Ubuntu 16.04. }
    But since Qt & SFML & Box2D are multi-platform, there should not be a problem.(not tested on other platforms )

Thank you for your time,
And feel free to contact me or give your opinion, your feedback is welcome.


Technical specification ( reminder )

Graphics / [SOLVED] Zoom Factor/Scale for the sf::View
« on: March 22, 2014, 11:13:03 am »

I'm wondering if it is possible to get the current zoom factor of a sf::View.
because i'm using a mouse-drag system and i need the zoom Factor/scale to fit the movement properly.


SFML projects / OCard !!
« on: March 27, 2012, 06:11:24 pm »
I'm Dr.Crow 20 years Old, newBiE prOgrammer, first Year @university ! but i have  few knowledge abOut C++/Sfml & Qt ! sO,
I was working on a game-card project recently , sO i want to present it for you !in the same time, seekIng fOr advice !
because it become hardEr and little complicated to manage! eSpecially when a bug occur il the middle of nOWhere  :P ;D
the game is nOt finished,just the basics feature for a game card ! ! nO IA Available ! ;D

Project's Information
Name: OCard !!
Style : A Card-Game TurnPerTurn (TPT)!! ( OGame style )
Version: Testing version !
Langage : C++/SFml & Qt
Link : Qt's dll ( QtGui4.dll , QtCore4.dll ) --> http://www.mediafire.com/download.php?6ob16uocetoktj1
Link : Sfml's & MinGW's dll ( sfml-graphics.dll, sfml-system.dll, sfml-window.dll + libgcc_s_dw2-1.dll , mingwm10.dll) --> http://www.mediafire.com/download.php?3xcz4ltn1c9p24d
Link ( Ressource & Exe ) ( plateForme : Windows ) --> http://www.mediafire.com/download.php?pxa912qh64cc21i
ScreenShot !:: URL
    About OCard !
    • OCard is a 2Player GameCard ( TPT )
    • Every players has a Deck which allow him to play, he can draw cards to his hand, or set as many card as he wants ( if condition of playing are true ), cards are played in the FieldZone ! which is compounded of two under-zone ,( Vessel/Fleet  Zone , and Tactic Zone )
    • Vessel/Fleet Zone : For Vessel Card, simply as Monters Card!
    • Tactic Zone For Tactics Card, simply as Magic Card !
      in addition of, that each player has ist own JunkZone ! for used and Discarded Card !
    How to play !
    Simple ! First OF all , draw a Card from your own deck and add it to your hand , then, you can Deploy a Vessel card in the your FleetZone , and / or use a tactic card ! only one Vessel Card can be deployed per turn per player Contrary to tactics card !
    FleetZone & TacticZone are Limited Zone, sO , each card player occupe one place in the Field !
    if you dont have any freeZone, you can play card of this type !
    after this, you déclare battle to your Opponent.... or not .  ;D
    Then, you Ends your turn .

    Until Now, cards are in two spicies , Vessel & Tactics, i'll add other Types later ...
    Each Player has to Collect a sum of RESSOURCES to win  ( by attacking )! ( not avaliable in this version )

      Inside Turn :
      Every turn is compounded of Steps :
      • DP : Draw Phase : The Player can Draw a card in this phase (if the deck is empty, gameOver )
      • SP: Standby phase : Phase where some cardEffect are activated ! ( not avaliable in this version )
      • M1 :Main Phase 1:this is the principal Phase of the turn, you can play VesselCard or Tactics-One ! or change Fleetcard position
      • BP: Battle Phase : in this phase, you can declare battle using your deployed Vessel  in your FleetZone to attack your opponent !
      • M2 : Main Phase 2: Similar to MAIN PHASE 1 , but just that the BattlePhase is over !  ;D
      • EP: this is the End Phase ! ( ends of turn )

      Few Fundamental notion
      • No IA avaliable, you'll play for the two player at same time  ::) :P

      • A Player can Only déploy one Vessel per turn, and use as many tactic cards ( except of a use of tactic card that allow an extra deployement of Vessel )
      • Vessels Can switch between two position, ( Offensive mode and Retreat Mode ) equivalent to ( Attack & Defense )
      • A Vessel  can change a position once per turn !
      • If A Vessel  has already attacked or just deployed during this turn, it can't change its position til next turn!
      • A Vessel can only change its position in MAIN PHASE 1 & 2
      • Each Vessel has Weapon.Point & Shell.Point respectivly ( Offensive & Retreat Mode ) , only one value is active/used during a battle, which depend on the current position of the Vessel !

      Eg :A Vessel inOffensive mode attacks a Vessel in Retreat Mode !
      Battle Calulation is applied between ( WeaponPoint of the attacked(offensive) & ShellPoint of the target(Retreat) )

      • Tactic card are in two type,
      • instant Effect : are sent to the juckZone after activating
      • continuous effect : their effect are continuous while the card is activated !

        inGUI :
        • to activate a Tactic Card, just click it from your hand ! ( none of tactic card has a effect ) !
        • to Deploye a Vessel Card, left Click the Card, then Click FleetFiledZone where you want to deploy it ! , if you want to cancel a deployement to choose an other one, right click annyWhere ! ( but before final deployment )  ;D
        • A Vessel deployement is Manual , because the game allOw to Deploy a Vessel on an other Vessel , so nOw, it forms a fleet & ( Grouped Attack notion)  ( 3 max )
        • A Fleet is a group of Vessel deployed one on the other, acting such a one card !,  the WeaponPoint or ShellPoint of the Fleet, is the sum of all its component !
        • To change the position of a Fleet, jsut click on It in the FleetZone il M1 or M2 !
        • To Move between GamePhases , click on the IconPhase to activate it !
        • In BP -BattlePhase - , to déclare battle, you must have at least one Fleet & in Offensive Mode, in that case, left click your click and maitain your clicking, then release in the target ! so that was a battle déclaring ! ( there is nO big animation or sound, this is just testing ..... )  ;D

        Check the LOGer in the middle of the Field, it indicates the information of the actual happening events ! ( in French   ::) )

          Add-Ons feature !  8)
          I'll introduce the Quantifiers of the game ! What each player dispose, and what player win in afterBattle !.
          til nOw, there is Two types :
          • RES : ( Ressource ) : this is the an mount of ressource, each player has the some quantity , and if one player reach a spécific sum, he wns, ( condition of wining or losing will be set after ) ( not avaliable in this version !)
          • HONOR : ( Honor ) : these is an optional, it allows to activate some kind of card , ( each card has a cost for activation ) you can recycle it to increase your ressources
          • After each battle, if a fleet is destroyed, a débris si formed  of metal & cristal in the zone where the battle happened ! , the amount depends on the destroyed fleet !
          EnjOy, and thank you !

          Explaining my problems , i have no experience for such a big game ! ( getting complicated each time i progress in  :-\ ) !
          I'm using a GameManger! which include players & manage the whole game in a freeThread !
          some times, sfml window does not get updated until the function is over !

          I explain : may be you've noticed that the program takes a while to load ( to be launched) ! (just few second but, in fact: this is the first draw Code ( animated style ) !
          Code: [Select]
               for ( int i = 0; i < 5; i++ )
              //each x.second, the player draw a card, until he draws 5 !then, the game continue ....
          In my program, i'm using two thread , ( the man thread, and the thread of the GameManager )
          HowEver this code is in theThread( GameManger) , and the draws ( of sprites ) are in the main Thread :??:  :o :(
          *Same Thing when j've tried to animate a drawAction ! from deck to Hand ! if the animation takes 3seconds !
          Code: [Select]
          1.When ready to draw !
          2.the window freezes ( 3 sec )
          3.then the card is directly in the hand !

          There is no animation of the sprite ! ( the moving )  :-\
          any suggestion !! ? !

          thank you & have a nice day !
          Dr.Crow !

          Pages: [1]