Advertisement

RTS Event Manager

Started by November 16, 2021 11:44 AM
2 comments, last by Calin 3 years ago

I`m on my way to create the Event Manager for my game. It`s a wip so please don`t get upset if there is not much to comment about yet. I have a reasonable understanding of what needs to be done I think, but I need validation of my work. I will post both the collision detection and all the other events involved in a RTS. For now here is my collision detection algorithm

void CheckCollisions(arim * Top, arim * Bott, arim * Left, arim * Right, ints * Ints, arim* CollidingActors,arbm * Available,arbm* OldNewTable)
{
	int ActorCount = Ints[0].ActorCount;
	for(int m =0; m < ActorCount; m++)
	{
		for(int n =0; n < ActorCount; n++)
		{
			if((Top[0].G(m)  < Top[0].G(n)&& //11
			    Top[0].G(m) > Bott[0].G(n)&&
			   Left[0].G(m) > Left[0].G(n)&&
			   Left[0].G(m) < Right[0].G(n))
			   ||
			   (Top[0].G(m) < Top[0].G(n)&& //1
			   Top[0].G(m) > Bott[0].G(n)&&
			   Right[0].G(m) > Left[0].G(n)&&
			   Right[0].G(m) < Right[0].G(n))
			   ||
			   (Bott[0].G(m,1) < Top[0].G(n)&& //5
			   Bott[0].G(m,1) > Bott[0].G(n)&&
			   Right[0].G(m,0) > Left[0].G(n)&&
			   Right[0].G(m,0) < Right[0].G(n))
			   ||
			   (Bott[0].G(m,1) < Top[0].G(n)&& //7
			   Bott[0].G(m,1) > Bott[0].G(n)&&
			   Left[0].G(m,0) > Left[0].G(n)&&
			   Left[0].G(m,0) < Right[0].G(n)))
			{
			   SaveCollision(m,n,CollidingActors,Available,ActorCount,OldNewTable);
			}
		}
		
	}
}
void SaveCollision(int first, int second,  arim* CollidingActors, arbm * Available, int ActorCount, arbm* OldNewTable)
{
	bool collisionexists = false;

	
	for(int i = 0; i < ActorCount; i++)
	{
		if(!Available[0].G(i))
		{

			
		}
	
	}
}
void MakeCollisonOld(arbm* OldNewTable, int ActorCount)
{
	
}

My project`s facebook page is “DreamLand Page”

I figured I don`t need the corners I can just use the Top, Bottom, Left, Right data

Before I move further I`ll put things into context

HRESULT InitDevice()
{
//directx init code here

	PxPosX = new arf[1];
	PxPosZ = new arf[1];
	ActorPathX = new arim[1];
	ActorPathZ = new arim[1];
	ActorCarret = new ari[1];
	MapObstacles = new arbm[1];
	MaxTop= new arim[1];
	MaxBott= new arim[1];
	MaxLeft= new arim[1];
	MaxRight= new arim[1];
	

}

void Render()
{
//reder code here


CheckCollisions(MaxTop,MaxBott,MaxLeft,MaxRight,MyInts);
 MyInts[0].ActorCount = 2;
for(int i =0; i< MyInts[0].ActorCount; i++)
{
 MyInts[0].ActorID =i;
 MyInts[0].PathLenghtResult = PathLength[0].G(0);
//MoveActor will both update the position of the Actor on screen and update the square data used for CD MoveActor(MyInts,ActorPathX,ActorPathZ,ActorCarret,0.01f,PxPosX,PxPosZ,Cor1,
Cor5,Cor7,Cor11,MaxTop,MaxBott,MaxLeft,MaxRight);
}


}

[Edit]

I went a step further and created system that cools the raw CD output and generates the start collision and end collision events

void CheckCollisions(arim * Top, arim * Bott, arim * Left, arim * Right, ints * Ints,arim* OldNewTable)
{
int ActorCount = Ints[0].ActorCount;
for(int m =0; m < ActorCount; m++)
{
 for(int n =0; n < ActorCount; n++)
 {
  if((Top[0].G(m)  < Top[0].G(n)&& //11
      Top[0].G(m) > Bott[0].G(n)&&
     Left[0].G(m) > Left[0].G(n)&&
     Left[0].G(m) < Right[0].G(n))
     ||
     (Top[0].G(m) < Top[0].G(n)&& //1
     Top[0].G(m) > Bott[0].G(n)&&
     Right[0].G(m) > Left[0].G(n)&&
     Right[0].G(m) < Right[0].G(n))
     ||
     (Bott[0].G(m,1) < Top[0].G(n)&& //5
     Bott[0].G(m,1) > Bott[0].G(n)&&
     Right[0].G(m,0) > Left[0].G(n)&&
     Right[0].G(m,0) < Right[0].G(n))
     ||
     (Bott[0].G(m,1) < Top[0].G(n)&& //7
     Bott[0].G(m,1) > Bott[0].G(n)&&
     Left[0].G(m,0) > Left[0].G(n)&&
     Left[0].G(m,0) < Right[0].G(n)))
  {
     SaveCollision(m,n,OldNewTable,Ints);
  }
 }
 
}
}
//OldNewTable is a 2 dimensional array of ints, x dimension has 4 fields: collison actor1 ,collison actor2
//previous frame collision, and current frame collison
void SaveCollision(int first, int second, arim* OldNewTable, ints * Ints)
{
bool collisionexists = false;

 
for(int i =0; i < Ints[0].collisiondetslots; i++)
{
 if(OldNewTable[0].G(0,i) != -1)
 {
  if(((OldNewTable[0].G(0,i) == first)&&(OldNewTable[0].G(1,i) == second))
   ||
   ((OldNewTable[0].G(0,i) == second)&&(OldNewTable[0].G(1,i) == first)))
  {
    collisionexists = true;
    OldNewTable[0].S(3,i,1);
  }
 }
}
if(!collisionexists)
{
for(int i =0; i < Ints[0].collisiondetslots; i++)
{
 if(OldNewTable[0].G(0,i) == -1)
 {
  OldNewTable[0].S(0,i,first);
  OldNewTable[0].S(1,i,second);
  OldNewTable[0].S(2,i,0);
  OldNewTable[0].S(3,i,1);
  break;
 }
}
}
}
void MakeCollisonOld(arbm* OldNewTable,ints * Ints)
{
for(int i =0; i < Ints[0].collisiondetslots; i++)
{
  if(OldNewTable[0].G(0,i) != -1)
  {
   if((OldNewTable[0].G(2,i) == 1)&&(OldNewTable[0].G(3,i) == 0))
   {
    OldNewTable[0].S(2,i,0);
    OldNewTable[0].S(0,i,-1);
   }
   
   if(OldNewTable[0].G(3,i) == 1)
   {
    OldNewTable[0].S(3,i,0);
    OldNewTable[0].S(2,i,1);
   }
  }
}
}
void ReadCollision(arbm* OldNewTable,ints * Ints)
{
for(int i =0; i < Ints[0].collisiondetslots; i++)
{
 
}
}

void Event(int type, int author1, int author2)
{

} 

[edit #2]

these days I spend some time preparing the code for a scale up to a larger number of actors (one of the changes is that I`m going to have some fat arrays), no work done to the event manager itself

My project`s facebook page is “DreamLand Page”

Advertisement

I managed to debug the collision detection algorithm. I have made some changes to make things work as they should. My next goal is to make units recover and continue after a collision. When a collision takes place both units head back to the last node they were traveling from. This is what I got the algorithm to do so far(as shown bellow). Next I`ll have the units resume their travel towards the initial destination.

void MainGameLoop()
{
if(cdfirstrun)
{
 cdfirstrun = false;
}
else
{
 CheckCollisions(MaxTop,MaxBott,MaxLeft,MaxRight,MyInts,CDoldnewtable);
 
}
 
for(int i =0; i< MyInts[0].ActorCount; i++)
{
 MyInts[0].ActorID =i;
 
 /*StringCchPrintfA(message, 1024, "path length in draw %d ",MyInts[0].PathLengthResult);
 MessageBoxA(NULL, message, "Textures.exe", MB_OK);*/
 MoveActor(MyInts,ActorPath,ActorCarret,0.01f,PxPosX,PxPosZ,MaxTop,MaxBott,MaxLeft,MaxRight);
}
ReadCollision(CDoldnewtable,MyInts);
MakeCollisonOld(CDoldnewtable,MyInts);
}
// type 0 - enter collision
// type 1 - exit collision
// type 2 - path traversal ended
void Event(int type, int author1, int author2)
{
	if(type ==0)
	{
		for(int i=0; i< MyInts[0].ActorCount;i++)
		{
			if((i == author1)||(i==author2))
			{
				int newdestx = ActorPath[0].G(ActorCarret[0].G(i),i,0);
				int newdestz = ActorPath[0].G(ActorCarret[0].G(i),i,1);
				ActorPath[0].S(ActorCarret[0].G(i) +1,i,0,newdestx);
				ActorPath[0].S(ActorCarret[0].G(i) +1,i,1,newdestz);
			}
			

		
		}
	}


	/*if(type == 0)
	{
	StringCchPrintfA(message, 1024, "enter event  %d  %d",author1,author2);
				MessageBoxA(NULL, message, "Textures.exe", MB_OK);
	}
	if(type == 1)
	{
	StringCchPrintfA(message, 1024, "exit event  %d  %d",author1,author2);
				MessageBoxA(NULL, message, "Textures.exe", MB_OK);
	}*/
}

My project`s facebook page is “DreamLand Page”

This topic is closed to new replies.

Advertisement