Пример #1
0
/*
 * create_automaton
 *
 * Allocates the memory required for a automaton. It then fills in the state
 * and event arrays but does not fill in the transition table or use the csv
 * file at all as this is done by a separate function.
 *
 * We pass in callbacks rather than arrays so that all memory allocation
 * regarding this object is done internally to the create function, thus all
 * freeing of memory can be done in the destroy function.
 *
 * Parameters: state_callback - A callback function pointer to a function which
 *                              will create all the state objects and fill them
 *                              in.
 *             event_callback - A callback function pointer to a function which
 *                              will create all the event objects and fill them
 *                              in.
 *
 * Returns: A pointer to the newly created memory or NULL on failure.
 */
AUTOMATON *create_automaton(int (*state_callback)(AUTOMATON_STATE ***, int),
                            int (*event_callback)(AUTOMATON_EVENT ***))
{
  /*
   * Local Variables
   */
  AUTOMATON *automaton;

  /*
   * Allocate the required memory. Forcing everything to 0 means that we can
   * test against NULL when destroying the object even if it is only half
   * created.
   */
  automaton = (AUTOMATON *) DT_MALLOC(sizeof(AUTOMATON));
  memset(automaton, '\0', sizeof(AUTOMATON));

  /*
   * Make the callback to get the array of events used in this automaton.
   */
  automaton->num_events = event_callback(&(automaton->events));

  /*
   * Make the callback to get the array of states used in this automaton.
   */
  automaton->num_states = state_callback(&(automaton->states),
                                         automaton->num_events);

  return(automaton);
}
Пример #2
0
void InputHandler::pollInputs() {
    SDL_Event event;
    while (SDL_PollEvent(&event)) {
        callbacks.top()(event);
    }

    state_callback();
}
Пример #3
0
void save_manager::register_postload(save_prepost_delegate func)
{
	// check for invalid timing
	if (!m_reg_allowed)
		fatalerror("Attempt to register callback function after state registration is closed!\n");

	// scan for duplicates and push through to the end
	for (state_callback *cb = m_postload_list.first(); cb != NULL; cb = cb->next())
		if (cb->m_func == func)
			fatalerror("Duplicate save state function (%s/%s)\n", cb->m_func.name(), func.name());

	// allocate a new entry
	m_postload_list.append(*auto_alloc(machine(), state_callback(func)));
}