Пример #1
0
void ClearPendingEvents()
{
	while (first)
	{
		Event *e = first->next;
		FreeEvent(first);
		first = e;
	}
}
Пример #2
0
// Free a track:
static void FreeTrack(midi_track_t *track)
{
    unsigned int        i;

    for (i = 0; i < (unsigned int)track->num_events; ++i)
        FreeEvent(&track->events[i]);

    free(track->events);
}
Пример #3
0
// Returns cycles left in timer.
u64 UnscheduleEvent(int event_type, u64 userdata)
{
	u64 result = 0;
	if (!first)
		return result;
	while(first)
	{
		if (first->type == event_type && first->userdata == userdata)
		{
			result = first->time - globalTimer;

			Event *next = first->next;
			FreeEvent(first);
			first = next;
		}
		else
		{
			break;
		}
	}
	if (!first)
		return result;
	Event *prev = first;
	Event *ptr = prev->next;
	while (ptr)
	{
		if (ptr->type == event_type && ptr->userdata == userdata)
		{
			result = ptr->time - globalTimer;

			prev->next = ptr->next;
			FreeEvent(ptr);
			ptr = prev->next;
		}
		else
		{
			prev = ptr;
			ptr = ptr->next;
		}
	}

	return result;
}
Пример #4
0
// This raise only the events required while the fifo is processing data
void ProcessFifoWaitEvents() {
    while (first) {
        if (first->time <= (s64)GetTicks()) {
            Event* evt = first;
            first = first->next;
            event_types[evt->type].callback(evt->userdata, (int)(GetTicks() - evt->time));
            FreeEvent(evt);
        } else {
            break;
        }
    }
}
Пример #5
0
void RemoveEvent(int event_type)
{
	if (!first)
		return;

	while (first)
	{
		if (first->type == event_type)
		{
			Event *next = first->next;
			FreeEvent(first);
			first = next;
		}
		else
		{
			break;
		}
	}

	if (!first)
		return;

	Event *prev = first;
	Event *ptr = prev->next;
	while (ptr)
	{
		if (ptr->type == event_type)
		{
			prev->next = ptr->next;
			FreeEvent(ptr);
			ptr = prev->next;
		}
		else
		{
			prev = ptr;
			ptr = ptr->next;
		}
	}
}
Пример #6
0
//This raise only the events required while the fifo is processing data
void ProcessFifoWaitEvents()
{
	while (first)
	{
		if (first->time <= globalTimer)
		{
//			LOG(TIMER, "[Scheduler] %s		 (%lld, %lld) ", 
//				first->name ? first->name : "?", (u64)globalTimer, (u64)first->time);
			Event* evt = first;
			first = first->next;
			event_types[evt->type].callback(evt->userdata, (int)(globalTimer - evt->time));
			FreeEvent(evt);
		}
		else
		{
			break;
		}
	}
}
Пример #7
0
void Advance()
{
	MoveEvents();

	int cyclesExecuted = slicelength - DowncountToCycles(PowerPC::ppcState.downcount);
	globalTimer += cyclesExecuted;
	lastOCFactor = SConfig::GetInstance().m_OCEnable ? SConfig::GetInstance().m_OCFactor : 1.0f;
	PowerPC::ppcState.downcount = CyclesToDowncount(slicelength);

	while (first)
	{
		if (first->time <= globalTimer)
		{
			//LOG(POWERPC, "[Scheduler] %s     (%lld, %lld) ",
			//             event_types[first->type].name ? event_types[first->type].name : "?", (u64)globalTimer, (u64)first->time);
			Event* evt = first;
			first = first->next;
			event_types[evt->type].callback(evt->userdata, (int)(globalTimer - evt->time));
			FreeEvent(evt);
		}
		else
		{
			break;
		}
	}

	if (!first)
	{
		WARN_LOG(POWERPC, "WARNING - no events in queue. Setting downcount to 10000");
		PowerPC::ppcState.downcount += CyclesToDowncount(10000);
	}
	else
	{
		slicelength = (int)(first->time - globalTimer);
		if (slicelength > maxSliceLength)
			slicelength = maxSliceLength;
		PowerPC::ppcState.downcount = CyclesToDowncount(slicelength);
	}

	if (advanceCallback)
		advanceCallback(cyclesExecuted);
}
Пример #8
0
void Advance()
{
	MoveEvents();

	int cyclesExecuted = g_slicelength - DowncountToCycles(PowerPC::ppcState.downcount);
	g_globalTimer += cyclesExecuted;
	s_lastOCFactor = SConfig::GetInstance().m_OCEnable ? SConfig::GetInstance().m_OCFactor : 1.0f;
	g_lastOCFactor_inverted = 1.0f / s_lastOCFactor;
	PowerPC::ppcState.downcount = CyclesToDowncount(g_slicelength);

	globalTimerIsSane = true;

	while (first && first->time <= g_globalTimer)
	{
		//LOG(POWERPC, "[Scheduler] %s     (%lld, %lld) ",
		//             event_types[first->type].name ? event_types[first->type].name : "?", (u64)g_globalTimer, (u64)first->time);
		Event* evt = first;
		first = first->next;
		event_types[evt->type].callback(evt->userdata, (int)(g_globalTimer - evt->time));
		FreeEvent(evt);
	}

	globalTimerIsSane = false;

	if (!first)
	{
		WARN_LOG(POWERPC, "WARNING - no events in queue. Setting downcount to 10000");
		PowerPC::ppcState.downcount += CyclesToDowncount(10000);
	}
	else
	{
		g_slicelength = (int)(first->time - g_globalTimer);
		if (g_slicelength > maxslicelength)
			g_slicelength = maxslicelength;
		PowerPC::ppcState.downcount = CyclesToDowncount(g_slicelength);
	}

	// Check for any external exceptions.
	// It's important to do this after processing events otherwise any exceptions will be delayed until the next slice:
	//        Pokemon Box refuses to boot if the first exception from the audio DMA is received late
	PowerPC::CheckExternalExceptions();
}
Пример #9
0
void Advance()
{
	MoveEvents();

	int cyclesExecuted = slicelength - downcount;
	globalTimer += cyclesExecuted;
	downcount = slicelength;

	while (first)
	{
		if (first->time <= globalTimer)
		{
//			LOG(POWERPC, "[Scheduler] %s     (%lld, %lld) ",
//				event_types[first->type].name ? event_types[first->type].name : "?", (u64)globalTimer, (u64)first->time);
			Event* evt = first;
			first = first->next;
			event_types[evt->type].callback(evt->userdata, (int)(globalTimer - evt->time));
			FreeEvent(evt);
		}
		else
		{
			break;
		}
	}

	if (!first)
	{
		WARN_LOG(POWERPC, "WARNING - no events in queue. Setting downcount to 10000");
		downcount += 10000;
	}
	else
	{
		slicelength = (int)(first->time - globalTimer);
		if (slicelength > maxSliceLength)
			slicelength = maxSliceLength;
		downcount = slicelength;
	}

	if (advanceCallback)
		advanceCallback(cyclesExecuted);
}
Пример #10
0
//This raise only the events required while the fifo is processing data
void ProcessFifoWaitEvents()
{
	MoveEvents();

	if (!first)
		return;

	while (first)
	{
		if (first->time <= globalTimer)
		{
			Event* evt = first;
			first = first->next;
			event_types[evt->type].callback(evt->userdata, (int)(globalTimer - evt->time));
			FreeEvent(evt);
		}
		else
		{
			break;
		}
	}	
}
Пример #11
0
void Advance()
{
	MoveEvents();

	int cyclesExecuted = g_slicelength - DowncountToCycles(PowerPC::ppcState.downcount);
	g_globalTimer += cyclesExecuted;
	s_lastOCFactor = SConfig::GetInstance().m_OCEnable ? SConfig::GetInstance().m_OCFactor : 1.0f;
	g_lastOCFactor_inverted = 1.0f / s_lastOCFactor;
	PowerPC::ppcState.downcount = CyclesToDowncount(g_slicelength);

	globalTimerIsSane = true;

	while (first && first->time <= g_globalTimer)
	{
		//LOG(POWERPC, "[Scheduler] %s     (%lld, %lld) ",
		//             event_types[first->type].name ? event_types[first->type].name : "?", (u64)g_globalTimer, (u64)first->time);
		Event* evt = first;
		first = first->next;
		event_types[evt->type].callback(evt->userdata, (int)(g_globalTimer - evt->time));
		FreeEvent(evt);
	}

	globalTimerIsSane = false;

	if (!first)
	{
		WARN_LOG(POWERPC, "WARNING - no events in queue. Setting downcount to 10000");
		PowerPC::ppcState.downcount += CyclesToDowncount(10000);
	}
	else
	{
		g_slicelength = (int)(first->time - g_globalTimer);
		if (g_slicelength > maxslicelength)
			g_slicelength = maxslicelength;
		PowerPC::ppcState.downcount = CyclesToDowncount(g_slicelength);
	}
}
Пример #12
0
/*
 * Load an event file into a FPPevent
 */
FPPevent* LoadEvent(char *id)
{
	FPPevent *event = NULL;
	FILE     *file;
	char      filename[1024];


	if (snprintf(filename, 1024, "%s/%s.fevt", getEventDirectory(), id) >= 1024)
	{
		LogErr(VB_EVENT, "Unable to open Event file: %s, filename too long\n",
			filename);
		return NULL;
	}

	file = fopen(filename, "r");
	if (!file)
	{
		LogErr(VB_EVENT, "Unable to open Event file %s\n", filename);
		return NULL;
	}

	event = (FPPevent*)malloc(sizeof(FPPevent));

	if (!event)
	{
		LogErr(VB_EVENT, "Unable to allocate memory for new Event %s\n", filename);
		return NULL;
	}

	bzero(event, sizeof(FPPevent));

	char     *line = NULL;
	size_t    len = 0;
	ssize_t   read;
	while ((read = getline(&line, &len, file)) != -1)
	{
		if (( ! line ) || ( ! read ) || ( read == 1 ))
			continue;

		char *token = strtok(line, "=");
		if ( ! token )
			continue;

		token = trimwhitespace(token);
		if (!strlen(token))
		{
			free(token);
			continue;
		}

		char *key = token;
		token = trimwhitespace(strtok(NULL, "="));

		if (token && strlen(token))
		{
			if (!strcmp(key, "majorID"))
			{
				int id = atoi(token);
				if (id < 1)
				{
					FreeEvent(event);
					free(token);
					free(key);
					return NULL;
				}
				event->majorID = id;
			}
			else if (!strcmp(key, "minorID"))
			{
				int id = atoi(token);
				if (id < 1)
				{
					FreeEvent(event);
					free(token);
					free(key);
					return NULL;
				}
				event->minorID = id;
			}
			else if (!strcmp(key, "name"))
			{
				if (strlen(token))
				{
					if (token[0] == '\'')
					{
						event->name = strdup(token + 1);
						if (event->name[strlen(event->name) - 1] == '\'')
							event->name[strlen(event->name) - 1] = '\0';
					}
					else
						event->name = strdup(token);
				}
			}
			else if (!strcmp(key, "effect"))
			{
				if (strlen(token) && strcmp(token, "''"))
				{
					char *c = strstr(token, ".eseq");
					if (c)
					{
						if ((c == (token + strlen(token) - 5)) ||
						    (c == (token + strlen(token) - 6)))
							*c = '\0';

						if (token[0] == '\'')
							event->effect = strdup(token + 1);
						else
							event->effect = strdup(token);
					}
				}
			}
			else if (!strcmp(key, "startChannel"))
			{
				int ch = atoi(token);
				if (ch < 1)
				{
					FreeEvent(event);
					free(token);
					free(key);
					return NULL;
				}
				event->startChannel = ch;
			}
			else if (!strcmp(key, "script"))
			{
				if (strlen(token) && strcmp(token, "''"))
				{
					if (token[0] == '\'')
					{
						event->script = strdup(token + 1);
						if (event->script[strlen(event->script) - 1] == '\'')
							event->script[strlen(event->script) - 1] = '\0';
					}
					else
						event->script = strdup(token);
				}
			}
		}

		if (token)
			free(token);
		free(key);
	}

	if (!event->effect && !event->script)
	{
		FreeEvent(event);
		return NULL;
	}

	LogDebug(VB_EVENT, "Event Loaded:\n");
	if (event->name)
		LogDebug(VB_EVENT, "Event Name  : %s\n", event->name);
	else
		LogDebug(VB_EVENT, "Event Name  : ERROR, no name defined in event file\n");

	LogDebug(VB_EVENT, "Event ID    : %d/%d\n", event->majorID, event->minorID);

	if (event->script)
		LogDebug(VB_EVENT, "Event Script: %s\n", event->script);

	if (event->effect)
	{
		LogDebug(VB_EVENT, "Event Effect: %s\n", event->effect);
		LogDebug(VB_EVENT, "Event St.Ch.: %d\n", event->startChannel);
	}

	return event;
}
Пример #13
0
/* ARGSUSED */
static void
GetClientValue(Widget w, XtPointer data, Atom *selection, Atom *type,
               XtPointer value, unsigned long *length,  int *format)
{
  Event          *event;
  ProtocolStream alloc_stream;
  ProtocolStream *stream;
  unsigned char  ident;
  unsigned char  error_code;
  char           *error_str;
  char           msg[BUFSIZ];


/* type should be checked if XT_CONVERT_FAIL */

  if (*length == 0)
    {
      return;
    }

  stream = &alloc_stream;	/* easier to think of it this way... */

  stream->current = stream->top = (unsigned char*)value;
  stream->size = HEADER_SIZE;		/* size of header. */

  /*
   * Retrieve the Header.
   */

  if (*length < HEADER_SIZE)
    {
      /* "Incorrectly formatted message from client" */
      SetMessage(global_screen_data.info_label,
		 res_labels[9],
		 "Incorrectly formatted message from client");
      return;
    }

  (void)_XEditResGet8(stream, &ident);
  if (global_client.ident != ident)
    {

#ifdef DEBUG
      if (global_resources.debug)
	{
	  printf("Incorrect ident from client.\n");
	}
#endif  /* DEBUG */

      if (!XtOwnSelection(w,
			  *selection,
			  CurrentTime,
			  ConvertCommand, 
			  LoseSelection,
			  SelectionDone))
	{
	  /* "Unable to own the Resource Editor Command Selection" */
	  SetMessage(global_screen_data.info_label,
		     res_labels[10],
		     "Unable to own the Resource Editor Command Selection");
	}

	return;

    }   /* if (global_client.ident != ident) */

    (void)_XEditResGet8(stream, &error_code);
    (void)_XEditResGet32(stream, &(stream->size));
    stream->top = stream->current;   /* reset stream to top of value.*/

    switch ((int)error_code)
      {
      case PartialSuccess:
        /*****
        if (global_client.command == LocalSendWidgetTree &&
	    global_effective_protocol_version < CURRENT_PROTOCOL_VERSION)
          {
	    ++global_effective_protocol_version;
          }
	*****/
	if ((event = BuildEvent(stream)) != NULL)
	  {
	    error_str = DispatchEvent(event);
	    FreeEvent(event);
	  }
	else
	  {
	    sprintf(msg,
		    "Unable to unpack protocol request.");
	    error_str = XtNewString(msg);
	  }
	break;   /* PartialSuccess */

      case Failure:
	error_str = GetFailureMessage(stream);
	break;   /* Failure */

      case ProtocolMismatch:
	error_str = ProtocolFailure(stream);
	--global_effective_protocol_version;
	/* normaly protocol version is reset to current during a SendWidgetTree
         * request, however, after a protocol failure this is skiped once for
         * a retry.
         */
	reset_protocol_level = False;
	SetCommand(w,
		   LocalSendWidgetTree,
		   NULL);
	break;   /* ProtocolMismatch */

	default:
		/* "Unknown Error code %s" */
		if (res_labels[11]) {
			sprintf(msg, res_labels[11], (int)error_code);
		} else {
			sprintf(msg, "Unknown Error code %i", (int)error_code);
		}
		SetMessage(global_screen_data.info_label, msg, "?res_labels[11]");
		break;    /* default */
	}   /* switch (error_code) */

    if (error_str == NULL)
      {
	WNode *top;


	if (global_tree_info == NULL)
	  {
	    return;
	  }
	
	top = global_tree_info->top_node;
	/* "Widget/Style tree for client %s (%s)" */
	if (res_labels[12])
	  {
	    sprintf(msg,
		    res_labels[12],
		    top->name,
		    top->class);
	  }
	else
	  {
Пример #14
0
/* ARGSUSED */
static void
GetClientValue(Widget w, XtPointer data, Atom *selection, Atom *type,
	       XtPointer value, unsigned long *length, int *format)
{
    Event * event;
    ProtocolStream alloc_stream, *stream;
    unsigned char ident, error_code;
    char * error_str = NULL, msg[BUFSIZ];

    if (*length == 0)
	return;

    stream = &alloc_stream;	/* easier to think of it this way... */

    stream->current = stream->top = (unsigned char *) value;
    stream->size = HEADER_SIZE;		/* size of header. */

    /*
     * Retrieve the Header.
     */

    if (*length < HEADER_SIZE) {
	SetMessage(global_screen_data.info_label,
		   res_labels[9]);
	return;
    }

    (void) _XEditResGet8(stream, &ident);
    if (global_client.ident != ident) {
#ifdef DEBUG
	if (global_resources.debug)
	    printf("Incorrect ident from client.\n");
#endif 
	if (!XtOwnSelection(w, *selection, CurrentTime, ConvertCommand, 
			    LoseSelection, SelectionDone))
	    SetMessage(global_screen_data.info_label,
		       res_labels[10]);
	return;
    }

    (void) _XEditResGet8(stream, &error_code); 
    (void) _XEditResGet32(stream, &(stream->size));
    stream->top = stream->current; /* reset stream to top of value.*/

    switch ((int) error_code) {
    case PartialSuccess:
/*****
        if (global_client.command == LocalSendWidgetTree &&
	    global_effective_protocol_version < CURRENT_PROTOCOL_VERSION)
	  ++global_effective_protocol_version;
*****/
	if ((event = BuildEvent(stream)) != NULL) {
	    error_str = DispatchEvent(event);
	    FreeEvent(event);
	}
	else {
	    sprintf(msg, "Unable to unpack protocol request.");
	    error_str = XtNewString(msg);
	}
	break;
    case Failure:
	error_str = GetFailureMessage(stream);
	break;
    case ProtocolMismatch:
	error_str = ProtocolFailure(stream);
	--global_effective_protocol_version;
	/* normaly protocol version is reset to current during a SendWidgetTree
         * request, however, after a protocol failure this is skiped once for
         * a retry.
         */
	reset_protocol_level = False;
	SetCommand(w, LocalSendWidgetTree, NULL);
	break;
    default:
	sprintf(msg, res_labels[11], (int) error_code);
	SetMessage(global_screen_data.info_label, msg);
	break;
    }

    if (error_str == NULL) {
	WNode * top;
	
	if (global_tree_info == NULL)
	    return;
	
	top = global_tree_info->top_node;
	sprintf(msg, res_labels[12], top->name, top->class);
	SetMessage(global_screen_data.info_label, msg);
	return;
    }
Пример #15
0
BOOLEAN	DequeAllGameEvents( BOOLEAN fExecute )
{
	EVENT					*pEvent;
	UINT32				uiQueueSize, cnt;
	BOOLEAN				fCompleteLoop = FALSE;
	// First dequeue all primary events


	while( EventQueueSize( PRIMARY_EVENT_QUEUE ) > 0 )
	{
		// Get Event
		if ( RemoveEvent( &pEvent, 0, PRIMARY_EVENT_QUEUE) == FALSE )
		{
			return( FALSE );
		}

		if ( fExecute )
		{
			// Check if event has a delay and add to secondary queue if so
			if ( pEvent->usDelay > 0 )
			{
				AddGameEventToQueue( pEvent->uiEvent, pEvent->usDelay, pEvent->pData, SECONDARY_EVENT_QUEUE );
			}
			else
			{
				ExecuteGameEvent( pEvent );
			}
		}

		// Delete event
		FreeEvent( pEvent );

	};

	// NOW CHECK SECONDARY QUEUE FOR ANY EXPRIED EVENTS
	// Get size of queue
	uiQueueSize = EventQueueSize( SECONDARY_EVENT_QUEUE );

	for ( cnt = 0; cnt < uiQueueSize; cnt++ )
	{
		if ( PeekEvent( &pEvent, cnt, SECONDARY_EVENT_QUEUE) == FALSE )
		{
			return( FALSE );
		}

		// Check time
		if ( ( GetJA2Clock() - pEvent->TimeStamp ) > pEvent->usDelay )
		{
			if ( fExecute )
			{
				ExecuteGameEvent( pEvent );
			}

			// FLag as expired
			pEvent->uiFlags = EVENT_EXPIRED;

		}

	}

	do
	{
		uiQueueSize = EventQueueSize( SECONDARY_EVENT_QUEUE );

		for ( cnt = 0; cnt < uiQueueSize; cnt++ )
		{
			if ( PeekEvent( &pEvent, cnt, SECONDARY_EVENT_QUEUE) == FALSE )
			{
				return( FALSE );
			}

			// Check time
			if ( pEvent->uiFlags & EVENT_EXPIRED )
			{
				RemoveEvent( &pEvent, cnt, SECONDARY_EVENT_QUEUE );
				FreeEvent( pEvent );
				// Restart loop
				break;

			}

		}

		if ( cnt == uiQueueSize )
		{
			fCompleteLoop = TRUE;
		}

	} while( fCompleteLoop == FALSE );

	return( TRUE );
}