Пример #1
0
ResourceLoader::~ResourceLoader() {
    SDL_KillThread(m_loaderThread);
    SDL_DestroyMutex(m_lockIn);
    SDL_DestroyMutex(m_lockOut);
    SDL_DestroyCond(m_sigNewJob);
}
Пример #2
0
/*************************************
context_free
Deep free of a context_t struct
*************************************/
void context_free(context_t * context)
{
	context_t * ctx;

	context_lock_list();

	if( context->user_name ) {
		free(context->user_name);
	}
	context->user_name = NULL;
	context->in_game = false;
	context->connected = false;
	if( context->socket != 0) {
		SDLNet_TCP_Close(context->socket);
	}
	context->socket = 0;
	if( context->socket_data != 0) {
		SDLNet_TCP_Close(context->socket_data);
	}
	context->socket_data = 0;
	SDL_DestroyMutex(context->send_mutex);

	if( context->hostname ) {
		free(context->hostname);
	}
	context->hostname = NULL;
	if( context->character_name ) {
		free(context->character_name);
	}
	context->character_name = NULL;
	if( context->map ) {
		free(context->map);
	}
	context->map = NULL;
	if( context->type ) {
		free(context->type);
	}
	context->type = NULL;
	if( context->selection.id ) {
		free(context->selection.id);
	}
	context->selection.id = NULL;
	context->selection.map_coord[0] = -1;
	context->selection.map_coord[1] = -1;
	if( context->selection.map ) {
		free(context->selection.map);
	}
	context->selection.map = NULL;
	if( context->selection.inventory ) {
		free(context->selection.inventory);
	}
	context->selection.inventory = NULL;
	if( context->selection.equipment ) {
		free(context->selection.equipment);
	}
	context->selection.equipment = NULL;
	if( context->prev_map ) {
		free(context->prev_map);
	}
	context->prev_map = NULL;
	if( context->luaVM != NULL) {
		lua_close(context->luaVM);
	}
	if( context->cond != NULL) {
		SDL_DestroyCond(context->cond);
	}
	if( context->cond_mutex != NULL) {
		SDL_DestroyMutex(context->cond_mutex);
	}

	/* First context of the list */
	if( context->previous == NULL ) {
		context_list_start = context->next;
		if( context->next != NULL) {
			context->next->previous = NULL;
		}
	} else {
		context->previous->next = context->next;
		if( context->next != NULL) {
			context->next->previous = context->previous;
		}
	}

	/* Remove this context from other context's selection */
	ctx = context_list_start;
	while( ctx != NULL ) {
		if( context->id && ctx->selection.id ) {
			if (strcmp(context->id,ctx->selection.id)==0) {
				ctx->selection.id = NULL;
			}
		}
		ctx = ctx->next;
	}

	if( context->id ) {
		free(context->id);
	}
	context->id = NULL;

	/* Remove this context from the list */
	if( context == context_get_first() ) {
		context_list_start = context->next;
	} else {
		ctx = context_list_start;
		while( ctx != NULL ) {
			if( ctx->next == context ) {
				ctx->next = context->next;
				break;
			}
			ctx = ctx->next;
		}
	}

	free(context);

	context_unlock_list();
}
Пример #3
0
/**
**  Fill audio thread.
*/
static int FillThread(void *)
{
	while (Audio.Running == true) {
		SDL_LockMutex(Audio.Lock);
#ifdef USE_WIN32
		// This is kind of a hackfix, without this on windows audio can get sluggish
		if (SDL_CondWaitTimeout(Audio.Cond, Audio.Lock, 1000) == 0) {
#else
		if (SDL_CondWaitTimeout(Audio.Cond, Audio.Lock, 100) == 0) {
#endif
			MixIntoBuffer(Audio.Buffer, Audio.Format.samples * Audio.Format.channels);
		}
		SDL_UnlockMutex(Audio.Lock);
	}

	SDL_LockMutex(Audio.Lock);
	// Mustn't call SDL_CloseAudio here, it'll be called again from SDL_Quit
	SDL_DestroyCond(Audio.Cond);
	SDL_DestroyMutex(Audio.Lock);
	return 0;
}

/*----------------------------------------------------------------------------
--  Effects
----------------------------------------------------------------------------*/

/**
**  Check if this sound is already playing
*/
bool SampleIsPlaying(CSample *sample)
{
	for (int i = 0; i < MaxChannels; ++i) {
		if (Channels[i].Sample == sample && Channels[i].Playing) {
			return true;
		}
	}
	return false;
}

bool UnitSoundIsPlaying(Origin *origin)
{
	for (int i = 0; i < MaxChannels; ++i) {
		if (origin && Channels[i].Unit && origin->Id && Channels[i].Unit->Id
			&& origin->Id == Channels[i].Unit->Id && Channels[i].Playing) {
			return true;
		}
	}
	return false;
}

/**
**  A channel is finished playing
*/
static void ChannelFinished(int channel)
{
	if (Channels[channel].FinishedCallback) {
		Channels[channel].FinishedCallback(channel);
	}

	delete Channels[channel].Unit;
	Channels[channel].Unit = NULL;

	Channels[channel].Playing = false;
	Channels[channel].Point = NextFreeChannel;
	NextFreeChannel = channel;
}

/**
**  Put a sound request in the next free channel.
*/
static int FillChannel(CSample *sample, unsigned char volume, char stereo, Origin *origin)
{
	Assert(NextFreeChannel < MaxChannels);

	int old_free = NextFreeChannel;
	int next_free = Channels[NextFreeChannel].Point;

	Channels[NextFreeChannel].Volume = volume;
	Channels[NextFreeChannel].Point = 0;
	Channels[NextFreeChannel].Playing = true;
	Channels[NextFreeChannel].Sample = sample;
	Channels[NextFreeChannel].Stereo = stereo;
	Channels[NextFreeChannel].FinishedCallback = NULL;
	if (origin && origin->Base) {
		Origin *source = new Origin;
		source->Base = origin->Base;
		source->Id = origin->Id;
		Channels[NextFreeChannel].Unit = source;
	}
	NextFreeChannel = next_free;

	return old_free;
}
Пример #4
0
	~Work()
	{
		SDL_DestroyMutex(mutex);
		SDL_DestroyCond(stateCond);
	}
Пример #5
0
int abs_thread_cond_destroy(abs_thread_cond_t *cond) {
  SDL_DestroyCond(*cond);
  return true;
}
Пример #6
0
		void DestroyCond(Cond *cond)
		{
			SDL_DestroyCond(cond);
		}
Пример #7
0
void osd_event_free(osd_event *event)
{
	SDL_DestroyMutex(event->mutex);
	SDL_DestroyCond(event->cond);
	free(event);
}
Пример #8
0
int Runtime::runShell(const char *startupBas, int fontScale, int debugPort) {
  logEntered();

  os_graphics = 1;
  os_color_depth = 16;
  opt_interactive = true;
  opt_usevmt = 0;
  opt_file_permitted = 1;
  opt_graphics = true;
  opt_pref_bpp = 0;
  opt_nosave = true;

  _output->setTextColor(DEFAULT_FOREGROUND, DEFAULT_BACKGROUND);
  _output->setFontSize(getStartupFontSize(_window));
  _initialFontSize = _output->getFontSize();
  if (fontScale != 100) {
    _fontScale = fontScale;
    int fontSize = (_initialFontSize * _fontScale / 100);
    _output->setFontSize(fontSize);
  }

  SDL_Init(SDL_INIT_AUDIO);
  SDL_AudioSpec desiredSpec;
  desiredSpec.freq = FREQUENCY;
  desiredSpec.format = AUDIO_S16SYS;
  desiredSpec.channels = 1;
  desiredSpec.samples = 2048;
  desiredSpec.callback = audio_callback;

  SDL_AudioSpec obtainedSpec;
  SDL_OpenAudio(&desiredSpec, &obtainedSpec);
  net_init();

  if (debugPort > 0) {
    appLog("Debug active on port %d\n", debugPort);
    g_lock = SDL_CreateMutex();
    g_cond = SDL_CreateCond();
    opt_trace_on = 1;
    g_debugBreak = SDL_TRUE;
    SDL_Thread *thread =
      SDL_CreateThread(debugThread, "DBg", (void *)(intptr_t)debugPort);
    SDL_DetachThread(thread);
  }

  if (startupBas != NULL) {
    String bas = startupBas;
    if (opt_ide == IDE_INTERNAL) {
      runEdit(bas.c_str());
    } else {
      runOnce(bas.c_str());
    }
    while (_state == kRestartState) {
      _state = kActiveState;
      if (_loadPath.length() != 0) {
        bas = _loadPath;
      }
      runOnce(bas.c_str());
    }
  } else {
    runMain(MAIN_BAS);
  }

  if (debugPort > 0) {
    SDL_DestroyCond(g_cond);
    SDL_DestroyMutex(g_lock);
  }

  debugStop();
  net_close();
  SDL_CloseAudio();
  _state = kDoneState;
  logLeaving();
  return _fontScale;
}
Пример #9
0
THMoviePictureBuffer::~THMoviePictureBuffer()
{
    SDL_DestroyCond(m_pCond);
    SDL_DestroyMutex(m_pMutex);
    sws_freeContext(m_pSwsContext);
}
Пример #10
0
Condition::~Condition() {
	SDL_DestroyCond(_condition);

	if (_ownMutex)
		delete _mutex;
}
Пример #11
0
void shutdown_WakeableWaiter(WakeableWaiter *ww)
{ 
   SDL_DestroyCond(ww->cond);
   SDL_DestroyMutex(ww->lock);
}
Пример #12
0
shr::SDLAudio::~SDLAudio() {
  SDL_DestroyCond(cond);
  SDL_DestroyMutex(mut);
  SDL_Quit();
}
Пример #13
0
inline void PacketQueue_destroy(PacketQueue* const pq)
{
	SDL_DestroyMutex(pq->mutex);
	SDL_DestroyCond(pq->cond);
}
Пример #14
0
	CondV::~CondV() {
		SDL_DestroyCond(_cond);
	}
Пример #15
0
condition::~condition()
{
	SDL_DestroyCond(cond_);
}
Пример #16
0
	static void del(SDL_cond *c) { SDL_DestroyCond(c); }
Пример #17
0
SyncPoint::Util::~Util()
{
	SDL_DestroyCond(cond);
	SDL_DestroyMutex(mut);
}
Пример #18
0
Conditional::~Conditional()
{
	SDL_DestroyCond(cond);
}
Пример #19
0
Файл: mt.c Проект: yoanlcq/FATE
void fe_mt_cond_deinit   (fe_mt_cond *cond) { SDL_DestroyCond(*cond); }
Пример #20
0
signed ODE_Init()
{
	Quit = SDL_FALSE;
	dInitODE2(dInitFlagManualThreadCleanup);
	dSetMessageHandler(Error);
	dSetDebugHandler(Error);
	dSetErrorHandler(Error);

	World = dWorldCreate();
	Space = dHashSpaceCreate(0);
	Group = dJointGroupCreate(0);
	Step = 1.0/50.0;

	lua_getglobal(State, "World");
	int table = lua_gettop(State);

	if (!lua_isnil(State, table))
	{
	 lua_pushnil(State);
	 while (lua_next(State, table))
	 {
		const char *key = lua_tostring(State, -2);
		#define tointeger lua_tointeger(State, -1)
		#define toboolean lua_toboolean(State, -1)
		#define tonumber  lua_tonumber(State, -1)

		if (!SDL_strcasecmp(key, "FPS"))
		{
		 Step = 1.0/tonumber;
		}
		else
		if (!SDL_strcasecmp(key, "ERP"))
		{
		 dWorldSetERP(World, tonumber);
		}
		else
		if (!SDL_strcasecmp(key, "CFM"))
		{
		 dWorldSetCFM(World, tonumber);
		}
		else
		if (!SDL_strcasecmp(key, "LINEAR_DAMPING"))
		{
		 dWorldSetLinearDamping(World, tonumber);
		}
		else
		if (!SDL_strcasecmp(key, "LINEAR_DAMPING_THRESHOLD"))
		{
		 dWorldSetLinearDampingThreshold(World, tonumber);
		}
		else
		if (!SDL_strcasecmp(key, "ANGULAR_DAMPING"))
		{
		 dWorldSetAngularDamping(World, tonumber);
		}
		else
		if (!SDL_strcasecmp(key, "ANGULAR_DAMPING_THRESHOLD"))
		{
		 dWorldSetAngularDampingThreshold(World, tonumber);
		}
		else
		if (!SDL_strcasecmp(key, "MAX_ANGULAR_SPEED"))
		{
		 dWorldSetMaxAngularSpeed(World, tonumber);
		}
		else
		if (!SDL_strcasecmp(key, "CONTACT_MAX_CORRECTING_VELOCITY"))
		{
		 dWorldSetContactMaxCorrectingVel(World, tonumber);
		}
		else
		if (!SDL_strcasecmp(key, "CONTACT_SURFACE_LAYER"))
		{
		 dWorldSetContactSurfaceLayer(World, tonumber);
		}
		else
		if (!SDL_strcasecmp(key, "AUTO_DISABLE"))
		{
		 dWorldSetAutoDisableFlag(World, toboolean);
		}
		else
		if (!SDL_strcasecmp(key, "AUTO_DISABLE_LINEAR_THRESHOLD"))
		{
		 dWorldSetAutoDisableLinearThreshold(World, tonumber);
		}
		else
		if (!SDL_strcasecmp(key, "AUTO_DISABLE_ANGULAR_THRESHOLD"))
		{
		 dWorldSetAutoDisableAngularThreshold(World, tonumber);
		}
		else
		if (!SDL_strcasecmp(key, "AUTO_DISABLE_STEPS"))
		{
		 dWorldSetAutoDisableSteps(World, tointeger);
		}
		else
		if (!SDL_strcasecmp(key, "AUTO_DISABLE_TIME"))
		{
		 dWorldSetAutoDisableTime(World, tonumber);
		}
		else
		{
		 SDL_Log("World: %s does not match", key);
		}
		lua_pop(State, 1);
	 }
	}
	lua_pop(State, 1);

	Cond = SDL_CreateCond();
	if (!Cond)
	{
	 dWorldDestroy(World);
	 dSpaceDestroy(Space);
	 dJointGroupDestroy(Group);
	 SDL_perror("SDL_CreateCond");
	 return SDL_SetError("cannot create simulation signal");
	}
	Mutex = SDL_CreateMutex();
	if (!Mutex)
	{
	 dWorldDestroy(World);
	 dSpaceDestroy(Space);
	 dJointGroupDestroy(Group);
	 SDL_DestroyCond(Cond);
	 SDL_perror("SDL_CreateMutex");
	 return SDL_SetError("cannot create simulation mutex");
	}
	Thread = SDL_CreateThread(SimulationThread, "ODE", NULL);
	if (!Thread)
	{
	 dWorldDestroy(World);
	 dSpaceDestroy(Space);
	 dJointGroupDestroy(Group);
	 SDL_DestroyCond(Cond);
	 SDL_DestroyMutex(Mutex);
	 SDL_perror("SDL_CreateThread");
	 return SDL_SetError("cannot create simulation thread");
	}
	TimerID = SDL_AddTimer(Uint32(1000*Step), SimulationTimer, NULL);
	if (!TimerID)
	{
	 dWorldDestroy(World);
	 dSpaceDestroy(Space);
	 dJointGroupDestroy(Group);
	 SDL_DestroyCond(Cond);
	 SDL_DestroyMutex(Mutex);
	 SDL_perror("SDL_AddTimer");
	 return SDL_SetError("cannot create simulation timer");
	}
	return 0;
}
Пример #21
0
THAVPacketQueue::~THAVPacketQueue()
{
    SDL_DestroyCond(m_pCond);
    SDL_DestroyMutex(m_pMutex);
}
Пример #22
0
void cond_destroy(bor_cond *cond)
{
	SDL_DestroyCond(cond);
}