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.
Good blog for tutorial
ReplyDeletethx
ReplyDeleteNice one.
ReplyDelete