Exemplo n.º 1
0
Arquivo: timer.c Projeto: Zeex/sampgdk
int sampgdk_timer_set(int interval,
                      bool repeat,
                      sampgdk_timer_callback callback,
                      void *param) {
  struct _sampgdk_timer_info timer;
  int slot;
  int error;
  int timerid;

  assert(callback != NULL);

  timer.is_set   = true;
  timer.interval = interval;
  timer.repeat   = repeat;
  timer.callback = (void *)callback;
  timer.param    = param;
  timer.started  = _sampgdk_timer_now();
  timer.plugin   = sampgdk_plugin_get_handle((void *)callback);

  if (timer.started == 0) {
    return 0; /* error already logged */
  }

  slot = _sampgdk_timer_find_slot();
  if (slot >= 0) {
    sampgdk_array_set(&_sampgdk_timers, slot, &timer);
  } else {
    error = sampgdk_array_append(&_sampgdk_timers, &timer);
    if (error < 0) {
      sampgdk_log_error("Error setting timer: %s", strerror(-error));
      return 0;
    }
    slot = _sampgdk_timers.count - 1;
  }

  /* Timer IDs returned by the SA:MP's SetTimer() API begin
   * with 1, and so do they here.
   */
  timerid = slot + 1;

  sampgdk_log_debug("Created timer: ID = %d, interval = %d, repeat = %s",
      timerid, interval, repeat ? "true" : "false");

  return timerid;
}
Exemplo n.º 2
0
void sampgdk_plugin_get_filename(void *address, char *filename, size_t size) {
  HMODULE module = (HMODULE)sampgdk_plugin_get_handle(address);
  assert(address != NULL);
  assert(filename != NULL);
  GetModuleFileName(module, filename, size);
}
Exemplo n.º 3
0
SAMPGDK_API(void, sampgdk_Unload(void)) {
  void *plugin = sampgdk_plugin_get_handle(RETURN_ADDRESS());
  cleanup_plugin(plugin);
}
Exemplo n.º 4
0
SAMPGDK_API(void, sampgdk_ProcessTick(void)) {
  void *plugin = sampgdk_plugin_get_handle(RETURN_ADDRESS());
  sampgdk_timer_process_timers(plugin);
}
Exemplo n.º 5
0
SAMPGDK_API(bool, sampgdk_Load(void **ppData)) {
  void *plugin = sampgdk_plugin_get_handle(RETURN_ADDRESS());
  return init_plugin(plugin, ppData) >= 0;
}