Jump to content


Member Since 28 Jul 2012
Offline Last Active Aug 21 2014 02:51 AM

#5133210 How did you learn C++?

Posted by greenpig83 on 21 February 2014 - 04:11 AM

C++ is not that hard in dos time. When I learn pascal and then move to C++, it's not that different. Because in Pascal u still can use OOP...

But things get so headache when windows release! To write a hello world app (with form) , it need 100-200 code line...No internet, only thick book, that really scare me. Sometime I just type 1-> 2 page of code then run to see what it really does. 


Now it's a lot more easy, we have tons of sample, tutorial on net, that no need to type anything at all, just build and see what happen ! 

#5131715 Why C++?

Posted by greenpig83 on 16 February 2014 - 09:02 AM

I think there arent many choice there!

If we count there are only java,C++,C#,Python, Delphi... Java is only good for their embedded type, run well on many platform. But i think they are not fast as C++ and they are not very direct (in means of directX...). I worked alot with java, for server and j2me!


I'm not a master of C#, code couple of samples... They are very good for tool, windows app... that need good UI. The code is a lot easy and clear than C++ but they still work behind something (virtual machine???) like java. But I think it's very close compare to C++.


But even other lang is good for game, C++ is still superior because of the documents/samples/tutorials on the net, most of them are on C++ ! But using engines like Unity can save us a lot of time learning langs, they can export into many platforms (web,ios,pc...). Just learn the script is sometime enough (not all the time)!

#5131678 Texture file theory question

Posted by greenpig83 on 16 February 2014 - 05:09 AM

D3DXCreateTextureFromFile Create a new texture from a file on disk for u. And load it into your GPU!

After created u can use it freely! until u release it!

It seems that u want to use it for your 2d project! with d3dxSprite. It's adviced to use texture atlas, group many sprite into 1 texture for performance!

#5129357 Setting up Direct3D Camera for 2D game

Posted by greenpig83 on 06 February 2014 - 12:00 PM

For 2D game you should use 

D3DXMatrixOrthoLH(&matOrtho,640, 480, -1000, 1000);

You dont have to worry about camera or things... Any thing u draw will be exactly its size !


because it's more simple. 

#5124246 Sprite thoery

Posted by greenpig83 on 16 January 2014 - 04:52 PM

First of all, if its D3d9sprite. You should limit to only 1 LPD3DXSPRITE at a time.

The main problem is that performance. 10 sprite is nothing, but when u have about 1000 sprite onscreen it will be the problem. Use as less sprite->begin(),sprite->end() as possible!

I dont know how LPD3DXSPRITE  work, but with 1 begin/end they are extremely fast (render 1000-1500 sprite in 1ms), with hundreds of different texture. That will be impossible if using primitive (u have to change textures so cant do batching well). However u will lack the ability to use Shader (u still can use but in limit way... I'm still studying it ). Because the speed is unchallanged so it's perfect for 2d game !


I dont know what you mean "sprite" in your question. Is that the Texture or the LPD3DXSPRITE. It seem that u worry about Many sprite using the same texture. And when u release the sprite, u release the texture, then it cause memory leak if other sprite still use that texture ? It's just a simple problem of managing resource/pointer. Never load a texture more than 1 time unless special case, it's just unlogical!

#5124025 Create texture failing

Posted by greenpig83 on 15 January 2014 - 07:20 PM

You should know to enable directx debug mode. Install directx sdk, run its config there is option for debug, break when directx error! Later there will be errors that hard to findout without debug mode help!
This post answer how to open debug mode: http://stackoverflow.com/questions/18613229/loading-textures-in-directx

#5123093 A* problem with heuristic

Posted by greenpig83 on 12 January 2014 - 12:13 PM

512x512 is quite large for A*. If u cant reach it, u will search all map! (nearly 500x500 node to be processed)

And it will be too slow. What is your test result (milisecond)  in unReachable case ?

#5119839 A* on large Map

Posted by greenpig83 on 29 December 2013 - 09:47 AM

OK here the code.
Hope it's helpful for u!
This is just a simple version, u can modify it for  min,maxRange search, source Size, goal Size.... Check goal if goal is surrounded by obstacle (so no way reach it)...
int * sOpenSet[2];
int sOpenSetSize[2];
int * sMatrixLen = NULL;
int * sMatrixFrom = NULL; //direction
//check if we can move to pos x,y
//check with your map here!
bool canMoveHere(int x,int y){
if (x==6 && y==6) return false;
return true;
const int Heading2X[9] = {  0,+1,+1,+1, 0,-1,-1,-1, 0 };
const int Heading2Y[9] = { -1,-1, 0,+1,+1,+1, 0,-1, 0 };
int HeadingFull[8]; //use for fast track back found Path
int sourceIndex;
int goalIndex;
bool processPoint2(int index,int size,int gx,int gy,int &bestLen,int &bestIndex,int leftSet ){
bool foundBest=false;
int dy=index/size;
int dx=index%size;
int curLen=sMatrixLen[index];
int newLen=curLen+1;
//numDirection is 8, choose 4 if u want !
for (int k=0;k<8;k++){
int rx=dx+Heading2X[k];
int ry=dy+Heading2Y[k];
int len=(rx-gx)*(rx-gx)+(ry-gy)*(ry-gy);
int index2=ry*size+rx;
//found the path
//we can stop and get the best Path right here
if (curLen>=0 && index2==goalIndex){
return true;
//if (mx>=0 && my>=0 && mx<Map.Info.MapWidth && my<Map.Info.MapHeight  && !iMapUnit[my][mx] )
if (canMoveHere(rx,ry )){
if (rx>=0 && ry>=0 && rx<size && ry<size && index2!=sourceIndex){
if ( newLen < sMatrixLen[index2] )
sMatrixLen[index2] = newLen;
if (sMatrixLen[index2]==0){
if (len<bestLen){
foundBest = true;
bestLen = len;
sMatrixLen[index2] = newLen;
sMatrixFrom[index2] = k;
//add new node to OpenSet
return foundBest;
//search from (sx,sy) to (gx,gy)
int mySuperSimpleSearch2(int sx, int sy, int gx, int gy){
//your map size
int size=32;
sOpenSetSize[0] = 0;
sOpenSetSize[1] = 0;
//this init only run once! can move to other place
if (sMatrixLen==NULL){
sMatrixLen = new int[size*size];
sMatrixFrom = new int[size*size];
sOpenSet[0] = new int[size*size];
sOpenSet[1] = new int[size*size];
for (int i=0;i<8;i++){
//use memset for best speed init!
memset(sMatrixLen, 0, ( size*size*sizeof(int) ));
memset(sMatrixFrom, 0, (size*size*sizeof(int) ));
sourceIndex = sy*size+sx;
int bestIndex = sourceIndex;
int bestLen=10000; //keep the bestLen to goal, so we always head for node that is close to goal!
int curOpenSet = 0;
bool haveBest = true; //if we found the node that closest to goal, we process it first!
int leftSet=1-curOpenSet;
if (sMatrixLen[goalIndex]>0 ){
//found goal get the Path;
int track=goalIndex;
int pathTotal=0;
int savePath[200];
for (int i=0;i<size*size;i++){
int dir=sMatrixFrom[track];
if (track==sourceIndex)
return pathTotal;
if (haveBest){
haveBest = processPoint2(bestIndex,size,gx,gy,bestLen,bestIndex, curOpenSet );
int nSize= sOpenSetSize[curOpenSet];
if (nSize ==0){
//no path left, unReachable;
return -1;
for (int i=0;i< nSize ;i++){
int index=sOpenSet[curOpenSet][i];
bool f1 = processPoint2(index,size,gx,gy,bestLen,bestIndex,leftSet );
if (f1) haveBest = true;
curOpenSet=leftSet; //swap Openset

#5119761 A* on large Map

Posted by greenpig83 on 28 December 2013 - 11:01 PM

Hey I'm working with path Finding, and solve a very hard problem, 1 thousand units moving through map of size 512x512 at a time (speed is crucial for me). So i think I can help u a bit !

32x32 size in normal computer will take no longer than 1ms (milisecond)  (even if it's unreachable). So ofcourse u mess up something ! download an A* sourcecode with example and test it first!

A* is overall good, but implement it take a bit problem.

I myself prefer a better way, although i think basically it's quite like A* , just different in how u program it !


I dont use openSet, closeSet. I use 2 openSet to swap. we get all node in first openSet -> process it -> put new nodes in the second Set, then swap! so we dont have to worry about openSet size,index....This way it's very easy to program.

in worst case, every pathFinding will search all nodes, so dont worry, we just need that in easy case, or normal case, we find goal as fast as possible !


in each loop, we choose a best candidate. how is it best, we calculate it length to goal (real length in cordinate : (goalX-x)^2 +(goalY-y)^2 ). if we have best candidate, we just use it, we dont use the openSet. If there is no best candidate, we come back to the openSet. The nice thing about this : we will always head to the goal, if there is a clear path from source to goal, we will reach the goal in the fastest way(no openSet used)  ! in bad case, if we have to go around, around to get to goal, it's still have the speed of other algorithm. 


If u like my idea, and want the code, i can put it here ! It's quite simple !