Beispiel #1
0
//**************************************************************************************
//*** plSerialBufferCount
//***
//***
//*** LUA STACK IN:
//***  L1 -> handle
//*** LUA STACK OUT:
//***  number   :  <0  ->  ERROR (OVERFLOW or WHATEVER)
//***             >=0  ->  number of bytes in the receive buffer
//**************************************************************************************
static int plSerialBufferCount( lua_State *L )
{
	int ret = -1;

	if( lua_gettop(L) == 1 )
		ret = BufferCount( lua_tonumber(L,1) );

	lua_pushnumber( L, ret );

	return 1;
}
Beispiel #2
0
void	GetNextUpdateState(UpdateState* u)
// Returns the next update to be processed.  If the update buffer is empty, then
// polls the control inputs and returns their current values.
{
	// Timeout on this, to be safe?
	while (BufferCount() == 0) {
		SampleInputsAndAddToBuffer();
	}

	*u = Buffer[Rear];	// Copy sampled data.

	Rear = (Rear + 1) & BUFFER_MASK;
}
Beispiel #3
0
bool	SampleInputsAndAddToBuffer()
// Locks the input buffer, samples the control inputs, and inserts a new UpdateState
// into the buffer.
// Returns false if the buffer is full or it can't acquire a lock on the input buffer.
{
	if (BufferCount() >= 15
#ifdef LINUX
	    || pthread_mutex_trylock(&BufferMutex) == EBUSY
#else // not LINUX
	    || WaitForSingleObject(BufferMutex, 0) == WAIT_FAILED
#endif // not LINUX
		)
	{
		return false;
	}

	UpdateState*	u = &Buffer[Front];

	// Fill timer values.
	u->Ticks = Timer::GetTicks();
	u->DeltaTicks = u->Ticks - LastSampleTime;
	if (u->DeltaTicks <= 0) u->DeltaTicks = 1;	// Don't allow a 0 time delta.
	if (u->DeltaTicks > 100) u->DeltaTicks = 100;	// Limit max time delta.
	u->DeltaT = u->DeltaTicks / 1000.0f;

	// Poll user input.
	Input::GetInputState(&u->Inputs, u->DeltaT);

	// Remember when we sampled.
	LastSampleTime = u->Ticks;

	// Schedule next sample.
	NextSampleTime = u->Ticks + MIN_SAMPLE_PERIOD;

	// Commit the sample.
	Front = (Front + 1) & BUFFER_MASK;
	
	// Unlock the buffer.
#ifdef LINUX
	pthread_mutex_unlock(&BufferMutex);
#else // not LINUX
	ReleaseMutex(BufferMutex);
#endif // not LINUX

	return true;
}
Beispiel #4
0
uint16_t BufferFreeSpace(Buffer_t* buffer)
{
	return buffer->size - BufferCount(buffer);//Restituisco il complemento di BufferCount
}
Beispiel #5
0
bool	UpdatesPending()
// Returns true if there are update samples in the queue waiting to be processed.
{
	// Check buffer.
	return BufferCount() > 0;
}