Skip to main content

1. Learning modern c++ for gaming from benefits to learning path. ( from my perspective)

Why c++ is primary language for gaming 

1.  c++ is fast very fast.

2. c++ support multiple inheritance which is a very big plus points in many cases

    for example
    --------------


#include <iostream>
#include<vector>
using namespace std;
struct Point
{
    float x;
    float y;
};
class Actions
{
    private:
           Point point;
    public:
  
     Actions(){};
     ~Actions(){};
      void canMove(Point &_point)
      {
         point=_point;
      };
      Point getMovePosition()
      {
          return point;
      }
};
class Monster
{
    private:
   std::vector<string> bonesArray ;
    public:
       Monster(){};
      ~Monster(){};
      void addBones(std::vector<string> &_bonesArray)
      {
         bonesArray=bonesArray;
      }
      vector<string> getBones()
      {
          return bonesArray;
      }
      
};
class MonsterA:public Monster , public Actions
{
     public:
       MonsterA(){};
      ~MonsterA(){};
};
int main()
{
     //MonsterA
     MonsterA *demon=new MonsterA();
     vector<string> bones={"A","B","C"};
     demon->addBones(bones);
    Point p;
    p.x=100;
    p.y=200;
    demon->canMove(p);
    std::cout <<"x===>position="<< demon->getMovePosition().x << std::endl;
    std::cout <<"y===>position="<< demon->getMovePosition().y << std::endl;
    
    MonsterA *demon1=new MonsterA();
     demon1->addBones(bones);
    Point p1;
    p1.x=200;
    p1.y=300;
    demon1->canMove(p1);
    std::cout <<"x===>position="<< demon1->getMovePosition().x << std::endl;
    std::cout <<"y===>position="<< demon1->getMovePosition().y << std::endl;
    
    return 0;
}



for example in above scenario i can separate monster physical properties and  its action with each other.

like monster class only contain the appearance and actions class deals with its properties like movement position or scaling or RGB color value

code here



3. same repeated point why c++ is fast the reason is very simple its a static compile language and very close to assembly so its required little overhead when you compare it with other language like python.



4. memory management is always a big concern when dealing with c++. on other hand javascript which is a scripting language or python which is also a scripting language because javascript and python both used garbage collector which automatically release the memory when a variable no more required.
even memory management is objective c and swift is also easy due to ARC automatic reference counting until you are not creating a cyclic reference.
but from c++ 11 and upwards you can use smart pointers to manage memory in a better way.

more about smart pointers 

1. auto_ptr in C++

    
 2.unique_ptr

3.shared_ptr



4. std::weak_ptr




4. opengl also written in c and c++ so its really helps some time to get in deep.



5. popular physics engine for games box2d also written in c++ which can easily be configured with any game engine.


6. c++ gives you more freedom like most of the open sources gaming engine based on c++.


7. performance really matters when u deal with complex rendering with 100 of objects moving from one position to another and lots of things specially for mobile device where getting 60fps for low end mobile is really hard.

check out one of above game video where i successfully rendered 300+ particle of big size at 60pfs which 200+ box2d physics object with out at 60fps and its a iphone 6 even i am getting same performance on older android devices.

i am using cocos2dx (c++).

8. STL now this is really a benefit using c++ which contain 100 of in built algorithms  which really helps when u are dealing with a big project .
take a look and check out both links



9. lots of community help.


10. best gaming engines for game development uses c++ like cocos2dx, unreal (3d) and godot for example.



so you can start like this.

1. first week - learn basics of c++ like variable statements function classes.

2. inheritance how to connect everything with like real life example.

3. difference between pass by reference , pass by value and pass by pointer this is really important because its a part of memory managements. spend time on until you fully understand it.

4. struct, union, friend function and friends class, virtual function, overriding , operator overloading, public private protected etc.  (2 weeks)

5. bitwise operators and their use to do simple operation. memory management smart pointers.   
 
6. algorithms and data structure don't ignore it if you want to write good code
    algorithms below


    
    data structure

7. spend time with opengl and metal (apple) at least 20 days.

8. start exploring open source gaming engine like cocos2dx or godot 

at least you have to spend 2 months if you know little bit programming to start your first game.

      

Comments

Post a Comment

Popular posts from this blog

Better Memory management with PixiJS or How to manage cpu and cpu memory in PixiJS.

PixiJS is my favorite framework when i am looking for a web games specially for mobile or desktop  PixiJS is fast blazing fast and you can get a decent FPS even on older device.   so here is my optimization techniques for PixiJs 1. manage your sprites in a better way use spritesheet to reduce the draw calls create big sprite sheet which contain multiple sprites can be draw in gpu with a single draw call. use TexturePacker  https://www.codeandweb.com/texturepacker  best tool when its comes to spritesheet 2. for floating point calculation round off calculation for example let  speed = 0.75 ; let  position = 100 ; console . log ( Math . round ( speed * position )) 3. don't create very big canvas when u need a big canvas size game just try to create a small canvas and translate it. 4. its very important one managing TextureCache in memory you can get all TextureCache list by using  Object.entries(PIXI.utils.TextureCache); so even you use ap...

adding particles Effect in pixijs using https://pixijs.io/pixi-particles-editor/

adding particle in pixijs is very easy using the below tool more information can be found below https://github.com/pixijs/pixi-particles https://pixijs.io/pixi-particles-editor/ required packages  /// < reference path = "node_modules/pixi-particles/ambient.d.ts" /> import 'pixi-particles' code of particle delcare a     global variable   private emitter ?: Emitter ; const img = PIXI . Texture . from ( "./assets/images/particle.png" ); this . emitter = new Emitter ( this ,[ img ],{ "alpha" : { "start" : 0.62 , "end" : 0.39 }, "scale" : { "start" : 0.1 , "end" : 0.9 , "minimumScaleMultiplier" : 1.25 }, "color" : { "start" : "#ffff8f" , "end" : ...