Jump to content

  • Log In with Google      Sign In   
  • Create Account


Garra

Member Since 18 Jan 2010
Offline Last Active Nov 30 2012 02:08 AM
-----

Topics I've Started

AI Space Pathing

24 November 2012 - 01:40 PM

I'm working on a type of space shooter for android and needed some help with enemy AI. What I'm looking for is info on how to do things such as ship formations (making multiple ships follow a path) etc. I have worked with steering behaviors before, but I don't think it's quite what i'm looking for. I think the solution is more than likely pathing. I want ships to follow a bezier type path just like you see on nearly every space shooter. I also would like to be able to implement different types of ship formations. If someone could point me to some good resources or explain some of the logic to me I would be greatful. I've been looking around the net for a few days and haven't really found what I'm looking for.

Debugging Game Deployment

02 December 2011 - 05:22 AM

I'm trying to create a setup project for my game using the Visual Studio Installer, it all goes well until I install the game and click to run it. As soon as the game runs it comes up with the error R6010 - abort() has been called and gives me the abort/retry/ignore options. When clicking on retry the Just in time debugger pops up and opens up in visual studio.. i can actually use it to step over the run-time error and once past it the game runs completely normal. The game also runs from my compiler in debug mode without any issues. The game has many.. many lines of code so what would be a way to debug such an issue?

TCP Connect function

25 November 2011 - 01:28 PM

EDIT: Issue solved

I'm working on a TCP client/server and I'm having an issue with my connect function. The connect function is giving me the error code 10014, a description of the error code is below. I'm having some issues just figuring out what I need to do to fix it, any advice would be appreciated.

[b]WSAEFAULT[/b]10014   Bad address. The system detected an invalid pointer address in attempting to use a  pointer argument of a call. This error occurs if an application passes  an invalid pointer value, or if the length of the buffer is too small.  For instance, if the length of an argument, which is a [url="http://msdn.microsoft.com/en-us/library/windows/desktop/ms740496%28v=vs.85%29.aspx"][b]sockaddr[/b][/url] structure, is smaller than the sizeof(sockaddr).


//my initialization code
bool CNetwork::InitializeTCPClient(char* szIP, int port)
{
	iResult = WSAStartup(MAKEWORD(2,2), &wsaData);

	if (iResult != 0)
		return false;

	skSocket = socket(AF_INET, SOCK_STREAM, 0);

	if (skSocket == INVALID_SOCKET)
		return false;

	//Input server information
	ZeroMemory(&ServerAddress, sizeof(ServerAddress)); // clear the struct
	ServerAddress.sin_family = AF_INET;		           // set the address family
	ServerAddress.sin_addr.s_addr = inet_addr(szIP);   // set the IP address
	ServerAddress.sin_port = htons(port);	           // set the port

	return true;
}

//connect function
bool CNetwork::Connect()
{
	fd_set write;
	FD_ZERO(&write);
	FD_SET(skSocket, &write);
	FD_ISSET(skSocket, &write);

	TIMEVAL timeVal;
	timeVal.tv_sec = 0;
	timeVal.tv_usec = 1;

	if (select(0, NULL, &write, 0, &timeVal) == SOCKET_ERROR)
	{
		WSACleanup();
		return false;
	}

	if (connect(skSocket, (struct sockaddr*)&ServerAddress, sizeof(sockaddr)) == SOCKET_ERROR)
	{
		int error = WSAGetLastError();
		WSACleanup();
		return false;
	}

	return true;
}

UDP Client/Server help

19 November 2011 - 10:15 AM

I'm working on a UDP server/client setup to add to my game. I have the client sending a structure of data representing a packet. This part is working, however I'm having issues trying to get the server to send the packet back out to all the other clients. Basically in my server loop I'm receiving packets, checking to see if the packet is a knock packet, and if it is add that address to a Client address array like below.

	while(true)
	{
		ZeroMemory(szBuffer, sizeof(szBuffer));
  		//iBytesRecv = c_Network.RecvChatPacket(szBuffer, sizeof(szBuffer)-1, 0);
		RecvPacket = c_Network.RecvPacket(RecvPacket);

		sprintf(szBuffer, "x: %f y: %f z: %f\n", RecvPacket.x, RecvPacket.y, RecvPacket.z);
		
		//int packet_size = sizeof(RecvPacket);
		//
		//if (packet_size > 0)
		//{
		//if the packet is a knock packet
		if (RecvPacket.knock)
		{
			for (int i = 0; i < 8; i++)
			{
				if (!(c_Network.ClientAddress[i].sin_family))
				{
					c_Network.ClientAddress[i] = c_Network.IncomingAddress;
					break;
				}
			}
			continue;
		}

		printf(szBuffer);

		c_Network.SendPacketToAll(RecvPacket);

	}
.

My client is able to send packets to the server with the below function, so I tried to modify the function to work with my server in order to send the packet to broadcast the packet to the rest of the clients.
void CNetwork::SendPacket(Packet packet)
{
	BYTE sendBuffer[128];

	memcpy_s(&sendBuffer, 128, &packet, sizeof(packet));

	int sent_bytes = 0;
	int attempts = 0;
	int packet_size = 0;

	while (sent_bytes < sizeof(packet) /*&& attempts < 3*/)
	{
		packet_size = sizeof(packet) - sent_bytes;

		int send_err = sendto(skSocket, (char*)&sendBuffer[sent_bytes],
			  				packet_size, 0, (sockaddr*)&ServerAddress, sizeof(sockaddr));

		sent_bytes += send_err;
	}
}

This function is ment to send the packet from the server to all clients connected. However, the sendto function always returns -1.
void CNetwork::SendPacketToAll(Packet packet)
{
	BYTE sendBuffer[128];

	memcpy_s(&sendBuffer, 128, &packet, sizeof(packet));

	int sent_bytes = 0;
	int attempts = 0;
	int packet_size = 0;

	for (int i = 0; i < 8; i++)
	{
		if (ClientAddress[i].sin_family)
		{
			while (sent_bytes < sizeof(packet))
			{
				packet_size = sizeof(packet) - sent_bytes;

				int send_err = sendto(skSocket, (char*)&sendBuffer[sent_bytes],
					  				packet_size, 0, (sockaddr*)&ClientAddress[i], sizeof(sockaddr));

   				if (send_err == SOCKET_ERROR)
				{
					printf("Unable to send to client\n");
				}

				sent_bytes += send_err;
				//attempts++;
			}
		}

		//Reset variables for use with next client address
		sent_bytes = 0;
		attempts = 0;
		packet_size = 0;
	}
}

and here is the server's receive packet function to show how IncomingAddress is being used. When the client starts up it will initialize winsock and then send the knock packet. When the server receives the knock packet it adds the IncomingAddress to the ClientAddress array.
Packet CNetwork::RecvPacket(Packet packet)
{
	BYTE recvBuffer[128];
	int recvd_bytes = 0;
	int packet_size = 0;
	int attempts = 0;
	int result;

	while (recvd_bytes < sizeof(packet))
	{
		iAddressLength = sizeof(IncomingAddress);
		packet_size = sizeof(packet) - recvd_bytes;
		result = recvfrom(skSocket, (char*)&recvBuffer[recvd_bytes], packet_size, 0, (sockaddr*)&IncomingAddress, &iAddressLength);

		if (result == SOCKET_ERROR)
		{
			
		}

		recvd_bytes += result;
	}

	if (recvd_bytes == sizeof(packet))
	{
		memcpy_s(&packet, sizeof(packet), &recvBuffer, sizeof(packet));
	}

	return packet;
}

Some AI advice needed

01 November 2011 - 09:59 PM

So I have a AI class that allows me to initialize a certain number of enemies and that's the number of enemies I have in the game. However, it doesn't allow me to do more interesting techniques with my AI such as spawning two new enemies when one enemy dies or just spawning an enemy on the fly. Basically I want to change the class to give me the ability to create new enemies at any time in the game. My current class has a initialization function that initialized the initial positions of the enemies, sets up the shader, and the enemy object itself. Most of this could be moved outside of the class, except there will be a problem with setting the enemies initial position. I thought of some other ways to do it without modifying my class since creating and destroying objects can be expensive. One of these ways is to make a pool of enemies. I could create a set number of enemies, put them in two vectors or something based on rather or not they are used and then swap the objects around. It seems like this wouldn't work in some cases since you would eventually run out of enemy objects. Does anyone have some advice to gvie me on a good method to set up creating new enemies at any time while the game is running?

PARTNERS