Пример #1
0
void Log::print(string message){
    if(message.empty() == true) return;
    string gtime;
    if(plaintext == true){
        gtime = GameTime() + GetSysTime() +FrameTime() + message + "\n";
    }else{
        gtime = "\n<tr><th width='8%' scope='row'><b>" + GameTime() + FrameTime() +"</b></th>\n<td width='92%'>" + message + "</td></tr>\n";
    }
    header(gtime);
}
Пример #2
0
void MULTIPLAY::UpdateStats()
{
	float remain;
	int mult;
	mult = (int) ((timeindex[0]+FrameTime()/2.0) / NETSTAT_UPDATE_FREQUENCY);
	remain = (timeindex[0] + FrameTime()/2.0) - (float)(mult * NETSTAT_UPDATE_FREQUENCY);
	if (remain < FrameTime())
	{
		tx = net.GetTxBytes();
		rx = net.GetRxBytes();
		net.ClearStats();
	}
}
Пример #3
0
void Log::Message(string msg, int player){
    if(plaintext == true){
        string m = "[" + PlayerNames[player] + "] " + GameTime() + FrameTime() +  " :: " + msg + "\n";
        header(m);
        return;
    }else{
        print("<span class='c'>" + msg + "</span>");
    }
}
Пример #4
0
	void Render(void)
	{
		gl.Clear().ColorBuffer().DepthBuffer();
		//
		oglplus::Uniform<GLfloat>(prog, "Time") = FrameTime();

		// draw 36 instances of the cube
		// the vertex shader will take care of their placement
		cube_instr.Draw(cube_indices, 36);
	}
Пример #5
0
	void Log::print(std::string message){
		if(message.empty() == true) return;
		if (!G) {
			//NLOG(message);
			return;
		}
		std::string gtime;
		gtime = GameTime() + GetSysTime() +FrameTime() + message + "\n";
		header(gtime);
	}
Пример #6
0
double MULTIPLAY::GetPacketArrayTime(int idx)
{
	if (numpackets[idx] > 0) 
	{
		double t = GetPacketArray(idx)[0].time;
		int mult;
		double to;
		mult = (int) ((t+FrameTime()/2.0) / PACKET_ARRAY_FREQUENCY);
		to = (double)(mult * PACKET_ARRAY_FREQUENCY);
		return to;
	}
	else 
	{
		if (MP_DEBUG)
			cout << "Asked for packet array time of empty packet array." << endl;
		return 0;
	}
	
	//return packetarraytime[idx];
}
Пример #7
0
void FramerateEqualizer::notifyUpdatePre( Compound* compound, 
                                          const uint32_t frameNumber )
{
    _init();

    // find starting point of contiguous block
    const ssize_t size = static_cast< ssize_t >( _times.size( ));
    ssize_t       from = 0;
    if( size > 0 )
    {
        for( ssize_t i = size-1; i >= 0; --i )
        {
            if( _times[i].second != 0.f )
                continue;

            from = i;
            break;
        }
    }

    // find max / avg time in block
    size_t nSamples = 0;
#ifdef USE_AVERAGE
    float sumTime = 0.f;
#else
    float maxTime  = 0.f;
#endif

    for( ++from; from < size && nSamples < _nSamples; ++from )
    {
        const FrameTime& time = _times[from];
        EQASSERT( time.first > 0 );
        EQASSERT( time.second != 0.f );

        ++nSamples;
#ifdef USE_AVERAGE
        sumTime += time.second;
#else
        maxTime = EQ_MAX( maxTime, time.second );
#endif
        EQLOG( LOG_LB2 ) << "Using " << time.first << ", " << time.second
                         << "ms" << std::endl;
    }

    if( nSamples == _nSamples )       // If we have a full set
        while( from < static_cast< ssize_t >( _times.size( )))
            _times.pop_back();            //  delete all older samples

    if( isFrozen() || !compound->isRunning( ))
    {
        // always execute code above to not leak memory
        compound->setMaxFPS( std::numeric_limits< float >::max( ));
        return;
    }

    if( nSamples > 0 )
    {
        //TODO: totalTime *= 1.f - damping;
#ifdef USE_AVERAGE
        const float time = (sumTime / nSamples) * SLOWDOWN;
#else
        const float time = maxTime * SLOWDOWN;
#endif

        const float fps = 1000.f / time;
#ifdef VSYNC_CAP
        if( fps > VSYNC_CAP )
            compound->setMaxFPS( std::numeric_limits< float >::max( ));
        else
#endif
            compound->setMaxFPS( fps );

        EQLOG( LOG_LB2 ) << fps << " Hz from " << nSamples << "/" 
                        << _times.size() << " samples, " << time << "ms" 
                        << std::endl;
    }

    _times.push_front( FrameTime( frameNumber, 0.f ));
    EQASSERT( _times.size() < 210 );
}
Пример #8
0
GameEngine::GameEngine(GameRunner* runner)
	: m_is_running(true)
	, m_runner(runner)
	, m_frame_time(0)
	, m_render_pipeline(NULL)
{
	DBG_LOG("Initialising platform singleton.");
	{
		m_platform = Platform::Create();
		DBG_ASSERT(m_platform != NULL);
	}

	DBG_LOG("Performing preload.");
	{
		m_runner->Preload();
		m_config = m_runner->Get_Engine_Config();
		m_frame_time = FrameTime(m_config.target_frame_rate);
	}

	DBG_LOG("Initialising renderer.");
	{
		m_renderer = Renderer::Create();
		DBG_ASSERT(m_renderer != NULL);
	}

	DBG_LOG("Initialising display.");
	{
		m_display = Display::Create(m_config.display_title, m_config.display_width, m_config.display_height, m_config.display_fullscreen);
		DBG_ASSERT(m_display != NULL);
	}

	DBG_LOG("Binding display to renderer.");
	{
		bool result = m_renderer->Set_Display(m_display);
		DBG_ASSERT(result);
	}

	DBG_LOG("Initialising input.");
	{
		m_input = Input::Create();
		DBG_ASSERT(m_input != NULL);
	}

	DBG_LOG("Initialising rendering pipeline.");
	{
		m_render_pipeline = new RenderPipeline(m_renderer);
		DBG_ASSERT(m_render_pipeline != NULL);
	}

	DBG_LOG("Loading rendering pipeline configuration: %s", m_config.render_pipeline_file);
	{
		bool result = m_render_pipeline->Load_Config(m_config.render_pipeline_file);
		DBG_ASSERT(result);
	}
	
	DBG_LOG("Initialising audio renderer.");
	{
		m_audio_renderer = AudioRenderer::Create();
		DBG_ASSERT(m_audio_renderer != NULL);
	}

	DBG_LOG("Initialising task manager.");
	{
		m_task_manager = new TaskManager(m_config.tasks_max_workers, m_config.tasks_max_tasks);
		DBG_ASSERT(m_task_manager != NULL);
	}
		
	DBG_LOG("Loading languages.");
	{
		m_locale = Locale::Create();
		
		for (std::vector<const char*>::iterator iter = m_config.languages.begin(); iter != m_config.languages.end(); iter++)
		{
			const char* path = *iter;
			DBG_LOG("Loading language: %s", path);

			bool result = m_locale->Load_Language(path);
			DBG_ASSERT_STR(result, "Failed to load language: %s", path);
		}
	}
	
	DBG_LOG("Selecting default language: %s", m_config.language_default);
	{
		bool result = m_locale->Change_Language(m_config.language_default);
		DBG_ASSERT_STR(result, "Failed to set default language to: %s", m_config.language_default);
	}

	DBG_LOG("Setting up scene.");
	{
		m_scene = new Scene();
		DBG_ASSERT(m_scene != NULL);
	}

	DBG_LOG("Setting up UI manager.");
	{
		m_ui_manager = new UIManager();
		DBG_ASSERT(m_ui_manager != NULL);
	}
}
Пример #9
0
void MULTIPLAY::ReceiveState()
{
	//check to see if it's time for a state packet
	int i;
	float remain;
	int mult;
	mult = (int) ((timeindex[1]+FrameTime()/2.0) / STATE_FREQUENCY);
	remain = (timeindex[1] + FrameTime()/2.0) - (float)(mult * STATE_FREQUENCY);
	
	//cout << timeindex[1] << "," << mult << "," << remain << endl;
	
	bool found = false;
	
	if (remain < FrameTime())
	{
		//cout << "get state" << endl;
		//search packets for correct time
		int count = 0;
		for (i = 0; i < net.GetMaxBuffers(); i++)
		{
			if (net.GetBuffer(i)->Valid())
			{
				//ProcessPacket(net.GetBuffer(i));
				Uint8 ptype;
				GetFromData(net.GetBuffer(i)->data, &ptype, sizeof(Uint8), 0);
				double ptime;
				GetFromData(net.GetBuffer(i)->data, &ptime, sizeof(double), 1);
				if (ptype == replay.Get_FuncStateInfo())
				{
					//clean out old state packets
					if (ptime < timeindex[1] - STATE_FREQUENCY)
					{
						net.GetBuffer(i)->Clear();
						
						if (NET_DEBUG)
							cout << "net:  Update:  cleaned out old state packet with time " << ptime << endl;
					}
					
					if (ptime > timeindex[1] - FrameTime()/2.0 && ptime < timeindex[1] + FrameTime()/2.0)
					{
						//exected time
						net.GetBuffer(i)->Clear();
						
						if (NET_DEBUG)
							cout << "net:  Update:  received state with time " << ptime << endl;
						
						loadstates[1].time = ptime;
						//loadstatevalid[1] = true;
						
						ReadState(net.GetBuffer(i)->data, 1);
						loadstatenow[1] = true;

						//update funcmem from state
						for (i = 0; i < fnums[1]; i++)
						{
							GetFuncMem(1)[i].oldval = loadstates[1].funcmem[i].oldval;
							GetFuncMem(1)[i].newval = loadstates[1].funcmem[i].newval;
							GetFuncMem(1)[i].held = loadstates[1].funcmem[i].held;
							GetFuncMem(1)[i].active = loadstates[1].funcmem[i].active;
							GetFuncMem(1)[i].lastupdateat = loadstates[1].funcmem[i].lastupdateat;
						}
						
						if (MP_RECORD && MP_REMOTE_RECORD)
						{
							dbgstate[dbgnumstates].CopyFrom(loadstates[1]);
							dbgnumstates++;
						}
						
						found = true;
					}
					else
					{
						//cout << "packet " << i << ": " << ptime << "," << timeindex[1] << endl;
						
						//increment timeout counter
						count++;
					}
				}
				//else cout << "i: " << i << ", p: " << ptype << ", t: " << ptime << endl;
			}
		}
		
		/*//if the state packet is late and we have new packets waiting for us,
		// give up waiting for the old one
		if (!found && count >= STATE_TIMEOUT_COUNT)
		{
			if (NET_DEBUG)
			{
				cout << "net:  Update:  timeout waiting for state at time " << timeindex[1] << endl;
			}
			
			timeindex[1] += STATE_FREQUENCY;
		}
		else if (!found)
		{
			if (NET_DEBUG)
			{
				cout << "waiting for timeout: " << count << " states in buffer" << endl;
			}
		}*/
		
		//if we have new packets waiting for us,
		// give up waiting for the old one
		// (moved back into the if (remain < frametime) part because packets can now be timed out)
		int scount = 0;
		double highesttime = 0;
		for (i = 0; i < net.GetMaxBuffers(); i++)
		{
			if (net.GetBuffer(i)->Valid())
			{
				//ProcessPacket(net.GetBuffer(i));
				Uint8 ptype;
				GetFromData(net.GetBuffer(i)->data, &ptype, sizeof(Uint8), 0);
				double ptime;
				GetFromData(net.GetBuffer(i)->data, &ptime, sizeof(double), 1);
				if (ptype == replay.Get_FuncStateInfo())
				{
					scount++;
					
					if (ptime > highesttime)
						highesttime = ptime;
				}
			}
		}
		
		if (!found && scount >= STATE_TIMEOUT_COUNT)
		{
			double newt;
			
			newt = (double)((mult+1) * STATE_FREQUENCY);
			//newt = highesttime;
			
			if (NET_DEBUG)
			{
				cout << "net:  Update:  timeout waiting for state at time " << timeindex[1] << " skipping to " << newt << endl;
			}
			
			//timeindex[1] += STATE_FREQUENCY;
			timeindex[1] = newt;
		}
	}
}
Пример #10
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;
}
Пример #11
0
void MULTIPLAY::UpdateFuncmem(int idx)
{
	REPLAY_PACKET * nextpacket = NULL;
	if (curpackets[idx] < numpackets[idx] && GetPacketArray(idx)[curpackets[idx]].time < timeindex[idx] + FrameTime()/2.0)
		nextpacket = &(GetPacketArray(idx)[curpackets[idx]]); //GetNextPacket(timeindex + FrameTime()/2.0);
	while (nextpacket != NULL)
	{
		int fid = nextpacket->chardata[CHAR_FUNCNUM];
		//cout << "fidx: " << fid << "," << fnums[idx] << endl;
//		FUNCTION_MEMORY * tmem = GetFuncMem(idx);
		//cout << "ptc: " << tmem << endl;
		//cout << "name: " << tmem[fid].func_name << endl;
		string curfunc = GetFuncMem(idx)[fid].func_name;
		
		//cout << "UpdateFuncMem: " << nextpacket->time << ": " << curfunc << endl;
		
		//cout << "assigned." << endl;
		int funcidx = 0;
		int i;
		for (i = 0; i < fnums[idx]; i++)
		{
			if (GetFuncMem(idx)[i].func_name == curfunc)
				funcidx = i;
		}
		
		GetFuncMem(idx)[funcidx].newval = nextpacket->val;
		if (nextpacket->chardata[CHAR_STATE] == 0)
			GetFuncMem(idx)[funcidx].held = false;
		if (nextpacket->chardata[CHAR_STATE] == 1)
			GetFuncMem(idx)[funcidx].held = true;
		
		if (nextpacket->chardata[CHAR_STATE] == 2)
			GetFuncMem(idx)[funcidx].active = false;
		else
			GetFuncMem(idx)[funcidx].active = true;
		
		nextpacket = NULL;
		curpackets[idx]++;
		if (curpackets[idx] < numpackets[idx] && GetPacketArray(idx)[curpackets[idx]].time < timeindex[idx] + FrameTime()/2.0)
			nextpacket = &(GetPacketArray(idx)[curpackets[idx]]);
	}
}
Пример #12
0
void MULTIPLAY::Update(double inc)
{	
	if (MP_DBGDEEP)
		cout << "multiplay update" << endl;
	
	//create packet arrays if necessary
	int i;
	for (i = 0; i < NumConnected() + 1; i++)
	{
		if (packetarrays[i] == NULL)
		{
			packetarrays[i] = new REPLAY_PACKET [PACKET_ARRAY_SIZE];
		}
	}
	
	if (MP_DBGDEEP)
		cout << "packet mem allocated" << endl;
	
	bool oldc = Connected();
	net.Update();
	if (!oldc && Connected())
	{
		//wasn't connected before, connected now.
		if (Server())
			remote_players++;
		
		ExchangeWorldInfo();
		
		int i;
		for (i = 0; i < MAX_PLAYERS; i++)
		{
			timeindex[i] = 0.0;
			loadstates[i].time = 0.0;
			loadstatenow[i] = false;
			numpackets[i] = 0;
			
			//packetarraytime[i] = 0.0;
			
			nooptime[i] = 0;
			noopvalid[i] = false;
			tickthisframe[i] = false;
			nooptick[i] = false;
		}
		
		dbgnumstates = 0;
		dbgnumpackets = 0;
		
		mq1.Clear();
		mq1.AddMessage("A client successfully connected");
	}
	
	if (MP_DBGDEEP)
		cout << "net updated" << endl;
	
	//read incoming data
	/*if (Connected() && net.NumBufferedPackets() > 0)
	{
		int i;
		for (i = 0; i < net.GetMaxBuffers(); i++)
		{
			if (net.GetBuffer(i)->Valid())
				ProcessPacket(net.GetBuffer(i));
		}
	}*/
	if (Connected())
	{
		if (!MP_DISABLEGET)
		{		
			ReceiveState();
		
			if (MP_DBGDEEP)
				cout << "state receive" << endl;
			
			ReceivePacketArray();
			
			if (MP_DBGDEEP)
				cout << "packet array receive" << endl;
		}
		
		if (!MP_DISABLEFUNCUPDATE)
		{
			double tval = 0;
			string ticktype = "packet array";
			nooptick[1] = false;
			if (PacketArrayValid(1))
				tval = GetPacketArrayTime(1);
			if (noopvalid[1] && nooptime[1] > tval)
			{
				tval = nooptime[1];
				ticktype = "noop";
				nooptick[1] = true;
			}
			if ((noopvalid[1] || PacketArrayValid(1)) && timeindex[1] < tval + PACKET_ARRAY_FREQUENCY - FrameTime()/2.0)
			{
				tickthisframe[1] = true;
				
				/*int nextpacket = curpackets[1];
				if (nextpacket >= numpackets[1])
					nextpacket = numpackets[1] - 1;
				if (ticktype == "packet array")
					cout << "ticking " << ticktype << ": " << GetFuncMem(1)[GetPacketArray(1)[nextpacket].chardata[CHAR_FUNCNUM]].func_name << " " << curpackets[1] << "/" << numpackets[1] << " packets for " << tval << " at " << timeindex[1] << endl;
				else
					cout << "ticking " << ticktype << " for " << tval << " at " << timeindex[1] << endl;*/
				
				timeindex[1] += inc;
				
				//process packet data into the function memory (which is then given to DoOp by vamosworld)
				//if (PacketArrayValid(1))// && !(ticktype == "noop"))
				int i;
				for (i = 0; i < fnums[1]; i++)
				{
					if (!GetFuncMem(1)[i].held && GetFuncMem(1)[i].active)
						GetFuncMem(1)[i].active = false;
				}
				
				UpdateFuncmem(1);
			}
			else
			{
				tickthisframe[1] = false;
				//cout << "not ticking at " << timeindex[1] << endl;
			}
		}
		
		if (MP_DBGDEEP)
			cout << "ticked" << endl;
		
		//check to see if we need to increment		
		/*for (i = 0; i < NumConnected(); i++)
		{
			if (loadstatevalid[i+1] && timeindex[i+1] < loadstates[i+1].time + STATE_FREQUENCY + FrameTime()/2.0)
			{
				timeindex[i+1] += inc;
			}
		}*/
		//if (packetarrayvalid[1] && timeindex[1] < loadstates[1].time + STATE_FREQUENCY - FrameTime()/2.0)
	}

	//cout << "Latency: " << GetLatency(1) << " (" << timeindex[0] << "-" << timeindex[1] << ")" << endl;
	
	//disconnect if the latency is super high
	if (GetLatency(1) > CLIENT_DISCONNECT_TIMEOUT)
	{
		Disconnect();
	}
	
	//update statistics
	UpdateStats();
	
	if (MP_DBGDEEP)
			cout << "multiplay update done" << endl;
}
Пример #13
0
void MULTIPLAY::ReceivePacketArray()
{
	//check to see if it's time for a packet array
	int i;
	float remain;
	int mult;
	mult = (int) ((timeindex[1]+FrameTime()/2.0) / PACKET_ARRAY_FREQUENCY);
	remain = (timeindex[1] + FrameTime()/2.0) - (float)(mult * PACKET_ARRAY_FREQUENCY);
	
	//cout << timeindex[1] << "," << mult << "," << remain << endl;
	
	if (remain < FrameTime())
	{
		//cout << "get state" << endl;
		//search packets for correct time
		int count = 0;
		bool found = false;
		for (i = 0; i < net.GetMaxBuffers(); i++)
		{
			if (net.GetBuffer(i)->Valid())
			{
				//ProcessPacket(net.GetBuffer(i));
				Uint8 ptype;
				int pos = 0;
				pos = GetFromData(net.GetBuffer(i)->data, &ptype, sizeof(Uint8), pos);
								
				if (ptype == replay.Get_FuncPacketArray())
				{
					//check array time
					int np;
					pos = GetFromData(net.GetBuffer(i)->data, &np, sizeof(int), pos);
					REPLAY_PACKET rp;
					pos = GetFromData(net.GetBuffer(i)->data, &rp, sizeof(REPLAY_PACKET), pos);
					
					double t = rp.time;
					int mult;
					mult = (int) ((t+FrameTime()/2.0) / PACKET_ARRAY_FREQUENCY);
					double ptime = (double)(mult * PACKET_ARRAY_FREQUENCY);
					
					//clean out old packet arrays
					if (ptime < timeindex[1] - PACKET_ARRAY_FREQUENCY)
					{
						net.GetBuffer(i)->Clear();
						
						if (NET_DEBUG)
							cout << "net:  Update:  cleaned out old packet array with time " << ptime << endl;
					}
					
					if (ptime > timeindex[1] - FrameTime()/2.0 && ptime < timeindex[1] + FrameTime()/2.0)
					{
						pos = 0;
						pos = GetFromData(net.GetBuffer(i)->data, &ptype, sizeof(Uint8), pos);
						pos = GetFromData(net.GetBuffer(i)->data, &numpackets[1], sizeof(int), pos);
						pos = GetFromData(net.GetBuffer(i)->data, GetPacketArray(1), sizeof(REPLAY_PACKET)*numpackets[1], pos);
						
						//expected time
						net.GetBuffer(i)->Clear();
						
						if (NET_DEBUG)
							cout << "net:  Update:  received packet array size " << numpackets[1] << " for time " << ptime << endl;
							
						found = true;
						
						if (MP_RECORD && MP_REMOTE_RECORD)
						{
							int i;
							for (i = 0; i < numpackets[1]; i++)
							{
								dbgpacket[dbgnumpackets] = GetPacketArray(1)[i];
								dbgnumpackets++;
							}
						}
						
						curpackets[1] = 0;
					}
					else
					{
						//cout << "packet " << i << ": " << ptime << "," << timeindex[1] << endl;
						
						//increment timeout counter
						count++;
					}
				}
				//else cout << "i: " << i << ", p: " << ptype << ", t: " << ptime << endl;
				else if (ptype == replay.Get_FuncNoop())
				{
					double ptime;
					pos = GetFromData(net.GetBuffer(i)->data, &ptime, sizeof(double), pos);
					
					//clean out old packet arrays
					if (ptime < timeindex[1] - PACKET_ARRAY_FREQUENCY)
					{
						net.GetBuffer(i)->Clear();
						
						if (NET_DEBUG)
							cout << "net:  Update:  cleaned out old NOOP with time " << ptime << endl;
					}
					
					if (ptime > timeindex[1] - FrameTime()/2.0 && ptime < timeindex[1] + FrameTime()/2.0)
					{
						//exected time
						net.GetBuffer(i)->Clear();
						
						if (NET_DEBUG)
							cout << "net:  Update:  received NOOP at time " << ptime << endl;
						
						noopvalid[1] = true;
						nooptime[1] = timeindex[1];
						
						curpackets[1] = 0;
						numpackets[1] = 0;
						
						/*loadstates[1].time = ptime;
						//loadstatevalid[1] = true;
						
						ReadState(net.GetBuffer(i)->data, 1);
						loadstatenow[1] = true;*/
						
						found = true;
					}
					else
					{
						//cout << "packet " << i << ": " << ptime << "," << timeindex[1] << endl;
						
						//increment timeout counter
						count++;
					}
				}
			}
		}
		
		//if the state packet is late and we have new packets waiting for us,
		// give up waiting for the old one
		if (!found && count >= PACKET_TIMEOUT_COUNT)
		{
			if (NET_DEBUG)
			{
				cout << "net:  Update:  timeout waiting for packet array at time " << timeindex[1] << endl;
			}
			
			timeindex[1] += PACKET_ARRAY_FREQUENCY;
		}
	}
}
Пример #14
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;
	}
}
Пример #15
0
	void Log::Message(std::string msg, int player){
		std::string m = "[" + PlayerNames[player] + "] " + GameTime() + FrameTime() +  " :: " + msg + "\n";
		header(m);
		return;
	}
Пример #16
0
	/// The screenshot capture heat-up sequence start time
	virtual double HeatUpTime(void) const
	{
		return ScreenshotTime()-HeatUpFrames()*FrameTime();
	}