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

Creating a word Scramble game where you can drag and drop the word and create a complete word. (drag and drop word Scramble game).

Creating a word game using  phaser game engine which is a javascript based gaming engine  where u can drag and drop world like Word Scramble Game and complete a given word. your index.html file look like below < html > < head > < script src = "src/phaser.min.js" ></ script > < script src = "src/wordGame.js" ></ script > < script src = "src/main.js" ></ script > </ head > < body > </ body > </ html > 1.    <script src="src/phaser.min.js"></script> required to run the  phaser game engine. 2. rest of the two files deals with game logics      <script src="src/wordGame.js"></script>       <script src="src/main.js"></script> you can download whole project from https://github.com/manishchauhan/wordgame/tree/master just copy and paste the project in your local server and run ...

starting with three.js and react with a very simple example

 1. three.js is undoubtedly the best library to create interactive content for the web in 3d. link https://threejs.org/ a working sample of three with react can be found below https://stackblitz.com/edit/react-7n5qf9?file=src%2FApp.js why choose threejs 1. lightweight  2.fast 3.big community  https://discourse.threejs.org/ 4. even you can use unity or unreal to publish html5 content but i don't think that would be acceptable in many cases. 5. open-source project. i created a running sample with React  https://stackblitz.com/edit/react-7n5qf9?file=src%2FApp.js

A simple binary search tree with generic approach tree can store any type of data. (DFS and BFS)

 1. a binary search tree in c++ using a generic approach with both BFS and DFS approach    working tree    https://www.onlinegdb.com/edit/HkuQLdA-w code=> some properties of binary search tree-> 1. binary search tree is not always a balanced tree.  2. Inorder, traversing gives you sorted data.  3.  best is o(log n) and worst is O(n).  4. left node data is always less than root data and right node data always be greater than root data.  5. red-black tree STL map is a balanced binary search tree. *******************************************************************************/ #include <stdio.h> #include<iostream> #include<queue> using namespace std; template < typename T > class Node {   //can store any type of data private:   //genric data or store any type of data   T data;   //reference of left pointer   Node *left = nullptr;   //reference of right pointer   Node *rig...