Пример #1
0
int MULTIPLAY::WriteVector(Vamos_Geometry::Three_Vector wv, Uint8 * dest, int start)
{
	//fwrite(&wv[0], sizeof(double), 1, fout);
	
	int len = start;
	
	len = AddToData(dest, &wv[0], sizeof(double), len);
	len = AddToData(dest, &wv[1], sizeof(double), len);
	len = AddToData(dest, &wv[2], sizeof(double), len);
	
	return len;
}
Пример #2
0
int MULTIPLAY::WriteMatrix(Vamos_Geometry::Three_Matrix wv, Uint8 * dest, int start)
{
	int len = start;
	
	//fwrite(&wv[0][0], sizeof(double), 1, fout);
	//fwrite(&wv[0][1], sizeof(double), 1, fout);
	//...
	len = AddToData(dest, &wv[0][0], sizeof(double), len);
	len = AddToData(dest, &wv[0][1], sizeof(double), len);
	len = AddToData(dest, &wv[0][2], sizeof(double), len);
	
	len = AddToData(dest, &wv[1][0], sizeof(double), len);
	len = AddToData(dest, &wv[1][1], sizeof(double), len);
	len = AddToData(dest, &wv[1][2], sizeof(double), len);
	
	len = AddToData(dest, &wv[2][0], sizeof(double), len);
	len = AddToData(dest, &wv[2][1], sizeof(double), len);
	len = AddToData(dest, &wv[2][2], sizeof(double), len);
	
	return len;
}
Пример #3
0
BOOL TMonsterAIRuleInfo::CheckConditionSpecificDate()
{
	SYSTEMTIME tCurrentTime;
	GetLocalTime(&tCurrentTime);

	int iYear = tCurrentTime.wYear;
	int iMonth = tCurrentTime.wMonth;
	int iDay = tCurrentTime.wDay;
	int iDayOfWeek = tCurrentTime.wDayOfWeek;
	int iHour = tCurrentTime.wHour;
	int iMinute = tCurrentTime.wMinute;
	int iCrywolfState = -1;

	if (iDayOfWeek != m_iWeekDay && m_iWeekDay != -1)
		return false;

	SYSTEMTIME tConditionTime;
	GetLocalTime(&tConditionTime);


	if ( m_iMonth != -1 )
		tConditionTime.wMonth = m_iMonth;

	if ( m_iDay != -1 )
		tConditionTime.wDay = m_iDay;

	if ( m_iHour != -1 )
		tConditionTime.wHour = m_iHour;

	if ( m_iMinute != -1 )
		tConditionTime.wMinute = m_iMinute;

	SYSTEMTIME tTimeRange = tConditionTime;
	AddToData(tTimeRange,-1,-1,-1,-1,-1,this->m_iContinuanceTime + this->m_iWaitTime);

	if ( DataEcval(tCurrentTime,tConditionTime) == 2 || DataEcval(tCurrentTime,tTimeRange) == 1 )
		return false;
	else
		return true;

}	
Пример #4
0
void MULTIPLAY::SendState()
{
	//send a state if necessary
	
	float remain;
	int mult;
	mult = (int) ((timeindex[0]+FrameTime()/2.0) / STATE_FREQUENCY);
	remain = (timeindex[0] + FrameTime()/2.0) - (float)(mult * STATE_FREQUENCY);
	
	if (remain < FrameTime())
	{
		if (NET_DEBUG)
		{
			cout << "net:  SendState:  sending state at time " << GetCurState(0)->time << endl;
			cout << "used buffers: " << net.NumBufferedPackets() << endl;
		}
		
		//it's time to record a state
		curstates[0].fnum = fnums[0]; //set the number of funcs
		if (curstates[0].funcmem != NULL) //clear old func data
		{
			delete [] curstates[0].funcmem;
			curstates[0].funcmem = NULL;
		}
		curstates[0].funcmem = new FUNCTION_MEMORY_SYNC [fnums[0]]; //allocate func data
		int i;
		for (i = 0; i < fnums[0]; i++) //record current func data
		{
			curstates[0].funcmem[i].oldval = GetFuncMem(0)[i].oldval;
			curstates[0].funcmem[i].newval = GetFuncMem(0)[i].newval;
			curstates[0].funcmem[i].held = GetFuncMem(0)[i].held;
			curstates[0].funcmem[i].active = GetFuncMem(0)[i].active;
			curstates[0].funcmem[i].lastupdateat = GetFuncMem(0)[i].lastupdateat;
		}
		
		
		//now, send a packet
		Uint8 tp[MAX_PACKET_SIZE];
		int tplen = 0;
		Uint8 tempchar;
		tempchar = replay.Get_FuncStateInfo();
		tplen = AddToData(tp, &tempchar, sizeof(Uint8), tplen);
		tplen = AddToData(tp, &GetCurState(0)->time, sizeof(double), tplen);
		//fwrite(&time, sizeof(double), 1, fout);
		tplen = WriteVector(GetCurState(0)->chassispos, tp, tplen);
		tplen = WriteMatrix(GetCurState(0)->chassisorientation, tp, tplen);
		tplen = WriteVector(GetCurState(0)->chassisvel, tp, tplen);
		tplen = WriteVector(GetCurState(0)->chassisangvel, tp, tplen);
		
		for (i = 0; i < 4; i++)
		{
			tplen = AddToData(tp, &GetCurState(0)->suspdisp[i], sizeof(double), tplen);
			tplen = AddToData(tp, &GetCurState(0)->suspcompvel[i], sizeof(double), tplen);
			tplen = WriteVector(GetCurState(0)->whlangvel[i], tp, tplen);
			tplen = AddToData(tp, &GetCurState(0)->tirespeed[i], sizeof(double), tplen);
		}
		
		tplen = AddToData(tp, &GetCurState(0)->gear, sizeof(int), tplen);
		tplen = AddToData(tp, &GetCurState(0)->enginespeed, sizeof(double), tplen);
		tplen = AddToData(tp, &GetCurState(0)->clutchspeed, sizeof(double), tplen);
		tplen = AddToData(tp, &GetCurState(0)->enginedrag, sizeof(double), tplen);
		
		tplen = AddToData(tp, &GetCurState(0)->segment, sizeof(int), tplen);
		
		//write a function state block
		tplen = AddToData(tp, &(fnums[0]), sizeof(int), tplen);
		
		for (i = 0; i < fnums[0]; i++)
		{
			//fwrite(&(funcmem[i]), sizeof(struct FUNCTION_MEMORY_SYNC), 1, fout);
			tplen = AddToData(tp, &(GetCurState(0)->funcmem[i]), sizeof(struct FUNCTION_MEMORY_SYNC), tplen);
		}
		
		net.Send(tp, tplen);
		
		if (MP_RECORD && !MP_REMOTE_RECORD)
		{
			dbgstate[dbgnumstates].CopyFrom(curstates[0]);
			dbgnumstates++;
		}
	}
	//else cout << timeindex[0] << "," << mult << "," << remain << endl;
}
Пример #5
0
bool MULTIPLAY::ExchangeWorldInfo()
{
	char tc[32767];
	sprintf(tc, "%c%c %s\n%i\n%s\n%i\n%i", (char) (replay.Get_FuncNetControl()), (char) CONTROL_WORLDINFO, state.GetCarName(0).c_str(), state.GetCarPaint(0), state.GetTrackName().c_str(), NumConnected(), NumConnected());
	
	//encode string length into the packet
	tc[2] = (char) ((Uint8) strlen(tc));
	
	//encode function memories, starting at strlen(tc)
	int tclen = strlen(tc);
	int opos = tclen;
	
	//tc[opos] = (char)((Uint8) fnums[0]);
	opos = AddToData(tc, &(fnums[0]), sizeof(int), opos);
	int f;
	for (f = 0; f < fnums[0]; f++)
	{
		char fout[FUNCTION_CHARS];
		strcpy(fout, GetFuncMem(0)[f].func_name.c_str());
		//fwrite(fout,1,FUNCTION_CHARS, rf);
		opos = AddToData(tc, fout, FUNCTION_CHARS, opos);
	}
	
	net.Send(tc, opos);
	
	int ret = net.RecvBlock(tc, 32767, GENERIC_TIMEOUT);
	if (ret > 0)
	{
		int pos = 0;
		int err = 0;
		
		if (tc[pos] == (char) (replay.Get_FuncNetControl()))
		{
			pos++;
			if (tc[pos] == (char) (CONTROL_WORLDINFO))
			{
				pos++;
				
				//decode string section length
				int slen = tc[2];
				pos++;
				
				string car;
				string carpaint;
				string track;
				string numplayers;
				string myplayernum;
				char sc[2];
				sc[1] = '\0';
				
				while (pos < slen && tc[pos] != '\n')
				{
					sc[0] = tc[pos];
					car.append(sc);
					
					pos++;
				}
				
				pos++;
				
				while (pos < slen && tc[pos] != '\n')
				{
					sc[0] = tc[pos];
					carpaint.append(sc);
					
					pos++;
				}
				
				pos++;
				
				while (pos < slen && tc[pos] != '\n')
				{
					sc[0] = tc[pos];
					track.append(sc);
					
					pos++;
				}
				
				pos++;
				
				while (pos < slen && tc[pos] != '\n')
				{
					sc[0] = tc[pos];
					numplayers.append(sc);
					
					pos++;
				}
				
				pos++;
				
				while (pos < slen && tc[pos] != '\n')
				{
					sc[0] = tc[pos];
					myplayernum.append(sc);
					
					pos++;
				}
				
				int icarpaint = atoi(carpaint.c_str());
				int inumplayers = atoi(numplayers.c_str());
				int imyplayernum = atoi(myplayernum.c_str());
				
				if (MP_DEBUG)
				{
					/*tc[ret] = '\0';
					cout << "raw worldinfo:  " << tc << endl;*/
					cout << "worldinfo size:  " << ret << endl;
					cout << "got worldinfo:  " << car << "," << icarpaint << "," << track << "," << inumplayers << "," << imyplayernum << endl;
				}
				
				//decode function memory
				//first clear it out
				int newpnum = NumConnected();
				if (funcmems[newpnum] != NULL)
				{
					delete [] funcmems[newpnum];
					funcmems[newpnum] = NULL;
				}
				pos = slen;
				pos = GetFromData(tc, &(fnums[newpnum]), sizeof(int), pos);
				funcmems[newpnum] = new FUNCTION_MEMORY [fnums[newpnum]];
				for (f = 0; f < fnums[newpnum]; f++)
				{
					char fin[FUNCTION_CHARS];
					pos = GetFromData(tc, fin, FUNCTION_CHARS, pos);
					GetFuncMem(newpnum)[f].func_name = fin;
					GetFuncMem(newpnum)[f].oldval = 0.0;
					GetFuncMem(newpnum)[f].held = false;
					GetFuncMem(newpnum)[f].active = false;
				}
				
				if (NET_DEBUG)
				{
					cout << "got functions:  " << fnums[newpnum];
					cout << " (" << fnums[0] << " local)" << endl;
					/*cout << "function list:  ";
					for (f = 0; f < fnums[newpnum]; f++)
					{
						cout << GetFuncMem(newpnum)[f].func_name << ",";
					}
					cout << endl;*/
				}
				
				if (!Server())
				{
					state.SetTrackName(track);
					state.SetCarName(1, car);
					state.SetCarPaint(1, icarpaint);
					remote_players = inumplayers;
					remote_playernum = imyplayernum;
					
					LoadWorld();
				}
				else
				{
					state.SetCarName(1, car);
					state.SetCarPaint(1, icarpaint);
					
					SelectCar(state.GetCarName(0), true);
					/*try
					{
						int numcars = NumConnected();
						Vamos_Body::Gl_Car* car = 0;
						car = new Vamos_Body::Gl_Car (Vamos_Geometry::Three_Vector (11.0, 0.0, 0.6));
						car->read ("data/", state.GetCarName(numcars));
						car->SetPaint(state.GetCarPaint(numcars));
						car->chassis ().translate (Vamos_Geometry::Three_Vector (10.0, 0.0, 
							-car->chassis ().lowest_contact_position () + 0.5));
						car->start_engine ();
						car->set_controller(2);
						world.add_car (car);
					}
					catch (Vamos_Geometry::XML_Exception& error)
					{
					  std::cerr << error.message () << std::endl;
					  std::exit (EXIT_FAILURE);
					}*/
				}
			}
			else
				err = 2;
		}
		else
			err = 1;
		
		if (err)
		{
			//retry?
		
			//nah, just disconnect.
			net.Disconnect();
			if (MP_DEBUG)
			{
				cout << "multiplay:  Update:  error parsing world info:  error " << err << endl;
			}
			return false;
		}
	}
	else
	{
		//retry?
		
		//nah, just disconnect.
		net.Disconnect();
		if (MP_DEBUG)
		{
			cout << "multiplay:  Update:  didn't receive world info:  error " << ret << endl;
		}
		
		return false;
	}
	
	return true;
}
Пример #6
0
void MULTIPLAY::SendPacketArray()
{
	float remain;
	int mult;
	mult = (int) ((timeindex[0]+FrameTime()/2.0) / PACKET_ARRAY_FREQUENCY);
	remain = (timeindex[0] + FrameTime()/2.0) - (float)(mult * PACKET_ARRAY_FREQUENCY);
	
	if (remain < FrameTime() && timeindex[0] > FrameTime()/2.0)
	{
		if (numpackets[0] > 0)
		{
			if (NET_DEBUG)
				cout << "net:  SendPacketArray:  sending " << numpackets[0] << " packets for time " << GetPacketArrayTime(0) << " at time " << timeindex[0] << endl;
			
			Uint8 tp[MAX_PACKET_SIZE];
			int tplen = 0;
			
			Uint8 tempchar;
			tempchar = replay.Get_FuncPacketArray();
			
			tplen = AddToData(tp, &tempchar, sizeof(Uint8), tplen);
			//tplen = AddToData(tp, &ti, sizeof(double), tplen);
			tplen = AddToData(tp, &numpackets[0], sizeof(int), tplen);
			tplen = AddToData(tp, GetPacketArray(0), sizeof(REPLAY_PACKET)*numpackets[0], tplen);
			net.Send(tp, tplen);
			
			//record the packets that were sent to our local debug record
			if (MP_RECORD && !MP_REMOTE_RECORD)
			{
				int i;
				for (i = 0; i < numpackets[0]; i++)
				{
					dbgpacket[dbgnumpackets] = GetPacketArray(0)[i];
					dbgnumpackets++;
				}
			}
			
			numpackets[0] = 0;
		}
		else
		{	
			//send NOOP
			
			double ntime = ((mult-1) * PACKET_ARRAY_FREQUENCY);
			
			if (NET_DEBUG)
				cout << "net:  SendPacketArray:  sending NOOP for time " << ntime << " at time " << timeindex[0] << endl;
			
			Uint8 tempchar;
			tempchar = replay.Get_FuncNoop();
			Uint8 tp[MAX_PACKET_SIZE];
			int tplen = 0;
			
			tplen = AddToData(tp, &tempchar, sizeof(Uint8), tplen);
			tplen = AddToData(tp, &ntime, sizeof(double), tplen);
			
			net.Send(tp, tplen);
			
			numpackets[0] = 0;
		}
		
		//packetarraytime[0] += PACKET_ARRAY_FREQUENCY;
	}
}