Jump to content
OGXbox.com

Meerjel01

Members
  • Posts

    150
  • Joined

  • Last visited

  • Days Won

    4

Posts posted by Meerjel01

  1. On 5/2/2024 at 4:54 PM, Meerjel01 said:

    Bump*

    I haven't tested it yet on my engine but I believe it'll be more working using this method than a bunch of for-loops.

    #include <iostream>
    
    using namespace std;
    
    class CObject
    {
    public:
    	void ExecuteDeb(int num)
    	{
    		printf("Printing! %i ", num);
    	}
    };
    
    class CObjectLinker
    {
    public:
    	CObject* objs;
    	int numObjs;
    	
    	CObjectLinker(int num)
    	{
    		numObjs = num;
    		objs = new CObject[numObjs];
    	}
    	
    	void StartExecute()
    	{
    		int number = numObjs;
    		
    		keepExecuting(number);
    	}
    	
    	void keepExecuting(int& curNum)
    	{
    		objs[curNum].ExecuteDeb(curNum);
    		curNum--;
    		
    		if(curNum < 0)
    			return;
    		keepExecuting(curNum);
    	}
    };
    
    int main(int argc, char *argv[]) {
    	CObjectLinker linker(4);
    	
    	linker.StartExecute();
    }

    This was a test to see if I can execute multiple objects with a countdown method instead of the usual. If And For/While takes some speed away when used a lot so I was experimenting and came up with this. Any thoughts?

    This code ain't good apparently. It looks decent but apparently it's no good for the engine to have this in it. Guess for loops aren't too bad after all?

    • Like 1
  2. Bump*

    I haven't tested it yet on my engine but I believe it'll be more working using this method than a bunch of for-loops.

    #include <iostream>
    
    using namespace std;
    
    class CObject
    {
    public:
    	void ExecuteDeb(int num)
    	{
    		printf("Printing! %i ", num);
    	}
    };
    
    class CObjectLinker
    {
    public:
    	CObject* objs;
    	int numObjs;
    	
    	CObjectLinker(int num)
    	{
    		numObjs = num;
    		objs = new CObject[numObjs];
    	}
    	
    	void StartExecute()
    	{
    		int number = numObjs;
    		
    		keepExecuting(number);
    	}
    	
    	void keepExecuting(int& curNum)
    	{
    		objs[curNum].ExecuteDeb(curNum);
    		curNum--;
    		
    		if(curNum < 0)
    			return;
    		keepExecuting(curNum);
    	}
    };
    
    int main(int argc, char *argv[]) {
    	CObjectLinker linker(4);
    	
    	linker.StartExecute();
    }

    This was a test to see if I can execute multiple objects with a countdown method instead of the usual. If And For/While takes some speed away when used a lot so I was experimenting and came up with this. Any thoughts?

    • Like 1
  3. I'm on a Mac so I can't do a lot with the assets for now but I got the resources out from the archive. The models seems to be mdl files but I'm not sure which structure they're built from.

    I got the .ipa file from here btw. Gonna have to play the game myself to get the game's feel correct.

  4. When I was interested in a full 3D game engine for the OG Xbox, I wanted to do a simple technique that Conker Live and Reloaded did with facial expressions. The mouths where 3D, but the eyes where 2D textures with 2 stages. It's not shape group based (I think) but uses bones for the mouths and textures for eyes like the outside and the inside of them.

    There might be an 8 for this. When I finish my own skinned mesh renderer and animator then I will do this. Seems to be the best looking way to me.

     

     

    • Like 2
  5. I did some changing to the code and it seems to work a bit better now. But it's not predictable enough and it might be the node grid that I made that is not set up correctly. Gonna make a new graph and changing to other parts of the engine's code to make it easier to work with.

    • Like 1
  6. On 1/25/2024 at 2:35 PM, corona2222 said:

    maybe, (when i find a moment) wheres the latest code?

    Here.

    // Init the grid then Get A Path	
    bool GetPath(D3DXVECTOR3 start, D3DXVECTOR3 end, st_path& finalPath, float maxStartLimit, float maxEndLimit)
    	{
    		CAStarNode* startNode = &GetNearestNode(start);
    		if(Distance(startNode->position, start) > maxStartLimit)
    			return false;
    		
    		CAStarNode* endNode = &GetNearestNode(end);
    		if(Distance(endNode->position, end) > maxEndLimit)
    			return false;
    
    	
    
    		CAStarNode* openList = new CAStarNode[numNodes];
    		CAStarNode* closedList = new CAStarNode[numNodes];
    		
    
    		int currentOpenAmount = 0;
    		int currentClosedAmount = 0;
    
    
    		openList[0] = *startNode;
    		currentOpenAmount++;
    
    		while (currentOpenAmount > 0)
    		{
    
    			if(currentOpenAmount <= 0)
    				break;
    
    			CAStarNode* currentNode = &openList[currentOpenAmount - 1];
    			
    			int neighCount = currentNode->numNeighbours;
    			
    			for(int i=0; i < neighCount; i++)
    			{
    				currentNode->neighbours[i].parent = currentNode;
    				currentNode->neighbours[i].gCost = Distance(currentNode->position, currentNode->neighbours[i].position);
    				currentNode->neighbours[i].hCost = Distance(currentNode->position, endNode->position);
    				currentNode->neighbours[i].fCost = currentNode->neighbours[i].gCost + currentNode->neighbours[i].hCost;
    			}
    					
    			
    			
    			// CAStarNode* neigh = currentNode->neighbours;
    			
    			
    			
    			int ending = 0;
    			if(currentNode->id == endNode->id)
    			{
    				
    				CAStarNode* nods = new CAStarNode[numNodes];
    				int curNods = 0;
    				
    				CAStarNode* curNod = currentNode;
    				
    				bool creating = true;
    				while(creating)
    				{
    					nods[curNods] = *curNod;
    					curNods++;
    					
    					if(curNod->id != startNode->id)
    						curNod = curNod->parent;
    					else
    						creating = false;
    				}
    
    				if(curNods <= 0)
    					return false;
    				
    				st_path result;
    				result.numCorners = curNods;
    				result.corners = new D3DXVECTOR3[curNods];
    				for(int n=0; n < curNods; n++)
    				{
    					result.corners[n] = nods[n].position;
    				}
    				// finalPath = CreatePath(startNode, endNode);
    				finalPath = result;
    				
    				
    				
    				
    				return true;
    			}
    			
    			
    			
    			bool picked = false;
    			for(int i=0; i < neighCount; i++)
    			{
    				
    				int sel = 0;
    				
    				
    				for(int x=0; x < neighCount; x++)
    				{
    					
    					if(currentNode->neighbours[x].fCost < currentNode->neighbours[sel].fCost)
    					{
    						sel = x;
    					}
    				}
    				
    				if(CheckInClosedList(closedList, currentClosedAmount, currentNode->neighbours[sel]))
    				{
    					int lar = 0;
    					for(int x=0; x < neighCount; x++)
    					{
    							
    						if(currentNode->neighbours[x].fCost > currentNode->neighbours[lar].fCost)
    						{
    							lar = x;
    						}
    					}
    					
    					currentNode->neighbours[sel].fCost = currentNode->neighbours[lar].fCost + 1;
    					
    					continue;
    					/*
    					currentNode->neighbours[i].gCost = currentNode->gCost + Distance(currentNode->position, currentNode->neighbours[i].position);
    					currentNode->neighbours[i].hCost = Distance(currentNode->neighbours[i].position, endNode->position);
    					
    					
    					currentNode->neighbours[i].fCost = currentNode->neighbours[i].gCost + currentNode->neighbours[i].hCost;
    					
    					currentNode->neighbours[i].parent = currentNode;
    					
    					openList[currentOpenAmount] = currentNode->neighbours[i];
    					currentOpenAmount++;
    					*/
    				}
    				else
    				{
    					openList[currentOpenAmount] = currentNode->neighbours[sel];
    					currentOpenAmount++;
    					picked = true;
    					break;
    				}
    			}
    			
    			if(picked == false)
    			{
    				currentOpenAmount--;
    			}
    			
    			closedList[currentClosedAmount] = *currentNode;
    			currentClosedAmount++;
    			
    		}
    
    
    		
    		
    		
    		return false;
    	}
    	
    	CAStarNode GetNearestNode(D3DXVECTOR3 position)
    	{
    		CAStarNode result;
    		float dist = 1000;
    		for(int n=0; n < numNodes; n++)
    		{
    			float d = Distance(position, nodes[n].position);
    			
    			if(d < dist)
    			{
    				result = nodes[n];
    				
    				dist = d;
    			}
    		}
    		
    		return result;
    	}

    I've just come back to this.

  7. 1 hour ago, corona2222 said:

    something that helped me understand what was happening to debug and optimize my pathfinding (not A* in my games case) was to render the path points being explored / found in different colours so I could visually see the path, and changed my 'GetPath()' code to be re-entrant so the path is built over a period of time so that I could see the path gradually getting built and the choices it was making and where the (complicated set of rules )code was going wrong. this may help.

    Thanks for the info. I believe it doesn't work correctly cause of the lack of nodes but I will make a line rendering system for the engine anyway. Also need to make a node-grid file generator somehow.

  8. Alright I've finished some code.

    struct st_path
    {
    	int numCorners;
    	D3DXVECTOR3* corners;
    };
    
    class CAStarNode
    {
    public:
    	int id;
    	D3DXVECTOR3 position;
    	int numNeighbours;
    	CAStarNode* neighbours;
    	bool open;
    	bool closed;
    	CAStarNode* parent;
    	
    	float gCost, hCost, fCost;
    
    	CAStarNode()
    	{
    		id = 0;
    		gCost = 0;
    		hCost = 0;
    		fCost = 0;
    		open = false;
    		closed = false;
    		numNeighbours = 0;
    	}
    
    
    
    
    };
    
    class CAStarGrid
    {
    protected:
    	IDirect3DDevice8* directDevice;
    	CAStarNode* nodes;
    	int numNodes;
    
    	D3DXVECTOR3* lines;
    	int numLineIndices;
    public:
    
    	CAStarGrid()
    	{
    		directDevice = NULL;
    		numNodes = 0;
    		numLineIndices = 0;
    	}
    	
    	bool InitGrid(IDirect3DDevice8** device, std::ifstream& file)
    	{
    		directDevice = *device;
    
    		file >> numNodes;
    
    		nodes = new CAStarNode[numNodes];
    
    		for(int i=0; i < numNodes; i++)
    		{
    			nodes[i].id = i;
    			file >> nodes[i].position.x >> nodes[i].position.y >> nodes[i].position.z;
    			
    		}
    
    		
    
    		int numConnections = 0;
    		
    		for(int n=0; n < numNodes; n++)
    		{
    			file >> numConnections;
    			nodes[n].numNeighbours = numConnections;
    			nodes[n].neighbours = new CAStarNode[numConnections];
    			
    			for(int i=0; i < numConnections; i++)
    			{
    				int nod = 0;
    				file >> nod;
    				nodes[n].neighbours[i] = nodes[nod];
    			}
    			
    		}
    		return true;
    	}
    	
    	bool GetPath(D3DXVECTOR3 start, D3DXVECTOR3 end, st_path& finalPath, float maxStartLimit, float maxEndLimit)
    	{
    		CAStarNode startNode = GetNearestNode(start);
    		if(Distance(startNode.position, start) > maxStartLimit)
    			return false;
    		CAStarNode endNode = GetNearestNode(end);
    		if(Distance(endNode.position, end) > maxEndLimit)
    			return false;
    		
    		for(int n=0; n < numNodes; n++)
    		{
    			nodes[n].open = false;
    			nodes[n].closed = false;
    		}
    		
    		startNode.open = true;
    		
    		bool found = false;
    		while (!found)
    		{
    			CAStarNode currentNode = startNode;
    			
    			if(CheckEnd(currentNode.neighbours, currentNode.numNeighbours, endNode))
    			{
    				endNode.parent = &currentNode;
    				found = true;
    				break;
    			}
    			
    			currentNode.closed = true;
    			
    			CAStarNode* neigh = currentNode.neighbours;
    			int neighCount = currentNode.numNeighbours;
    			
    			for(int i=0; i < neighCount; i++)
    			{
    				if(neigh[i].closed)
    				{
    					continue;
    				} else {
    					float gCost = currentNode.gCost + Distance(currentNode.position, neigh[i].position);
    					float hCost = Distance(neigh[i].position, endNode.position);
    					
    					if(!neigh[i].open)
    					{
    						neigh[i].fCost = hCost + gCost;
    						neigh[i].parent = &currentNode;
    						
    						neigh[i].open = true;
    					} else {
    						float newFCost = gCost + hCost;
    						
    						if(neigh[i].fCost > newFCost)
    						{
    							neigh[i].fCost = newFCost;
    							neigh[i].parent = &currentNode;
    						}
    					}
    				}
    			}
    		}
    		
    		finalPath = CreatePath(startNode, endNode);
    		
    		return true;
    	}
    	
    	st_path CreatePath(CAStarNode start, CAStarNode end)
    	{
    		st_path result;
    		result.corners = new D3DXVECTOR3[40];
    		
    		CAStarNode currentNode = end;
    		int current = 0;
    		while(currentNode.id != start.id)
    		{
    			result.corners[current] = currentNode.position;
    			
    			currentNode = *currentNode.parent;
    			current++;
    		}
    		result.numCorners = current;
    		D3DXVECTOR3* temp = new D3DXVECTOR3[current];
    		int c = 0;
    		for(int i=current - 1; i >= 0; i--)
    		{
    			temp[i] = result.corners[c];
    			c++;
    		}
    		// std::reverse(result.corners[0], result.corners[current]);
    		result.corners = temp;
    		delete[] temp;
    
    		return result;
    	}
    	
    	CAStarNode GetNearestNode(D3DXVECTOR3 position)
    	{
    		CAStarNode result;
    		float dist = 1000;
    		for(int n=0; n < numNodes; n++)
    		{
    			float d = Distance(position, nodes[n].position);
    			
    			if(d < dist)
    			{
    				result = nodes[n];
    				dist = d;
    			}
    		}
    		
    		return result;
    	}
    	
    	bool CheckEnd(CAStarNode* neighbours, int numNeighbours, CAStarNode endTarget)
    	{
    		for(int i=0; i < numNeighbours; i++)
    		{
    			if(neighbours[i].id = endTarget.id)
    				return true;
    		}
    		return false;
    	}
    	
    };

    Gonna improve it later after I've done testing it. Any thoughts?

    • Like 2

Board Life Status


Board startup date: April 23, 2017 12:45:48
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.