Ejemplo n.º 1
0
bool CSound::PlaySoundClip(ESound eClipType)
{
  // first, grab the mutex
  if (SDL_mutexP(m_pMutex) == -1) return false;

  // now check to make sure we can add one more sound
  if (m_uiActiveSounds == 32)
    {
    // error - too many sounds playing!
    SDL_mutexV(m_pMutex);
    return false;
    }

  // add it to the arrays
  m_eClipType[m_uiActiveSounds] = eClipType;
  m_uiClipOffset[m_uiActiveSounds] = 0;
  m_uiActiveSounds++;

  // that's all!
  SDL_mutexV(m_pMutex);
  return true;
}
Ejemplo n.º 2
0
void CSound::StopSoundClip(ESound eClipType)
{
  // first, grab the mutex
  if (SDL_mutexP(m_pMutex) == -1) return;

  // now try to find the sound clip
  for (unsigned int ui = 0; ui < m_uiActiveSounds; ui++)
    {
    if (m_eClipType[ui] == eClipType)
      {
      // remove this sound from our lists
      memmove(m_eClipType + ui,    m_eClipType + ui + 1,    (m_uiActiveSounds - ui - 1) * sizeof(ESound));
      memmove(m_uiClipOffset + ui, m_uiClipOffset + ui + 1, (m_uiActiveSounds - ui - 1) * sizeof(unsigned int));
      m_uiActiveSounds--;
      break;
      }
    }

  // let go of the mutex
  SDL_mutexV(m_pMutex);
  return;
}
Ejemplo n.º 3
0
static int mem_read(SDL_RWops *context, void *ptr, int size, int maxnum) //maks
{
	int num;

	SDL_mutexP(multipleArchiveMutEx);

	if(!bInAMultipleFuncion && context == archive)
	{		
		current = context;

		if(context->stdioFilePosition != context->filePosition)
		{
			//Position changed by a multiple file call
			//Restore
			context->hidden.mem.here = context->hidden.mem.base + context->stdioFilePosition;
			context->filePosition = context->stdioFilePosition;			
		}
	}
	

	num = maxnum;
	if ( (context->hidden.mem.here + (num*size)) > context->hidden.mem.stop ) 
	{
		num = (context->hidden.mem.stop-context->hidden.mem.here)/size;
	}

	memcpy(ptr, context->hidden.mem.here, num*size);
	context->hidden.mem.here += num*size;

	if(!bInAMultipleFuncion)
	{
		context->filePosition += num*size;
		context->stdioFilePosition = context->filePosition;
	}

	SDL_mutexV(multipleArchiveMutEx);
	return(num);
}
Ejemplo n.º 4
0
static void
SDL_DelThread(SDL_Thread * thread)
{
    int i;

    if (!thread_lock) {
        return;
    }
    SDL_mutexP(thread_lock);
    for (i = 0; i < SDL_numthreads; ++i) {
        if (thread == SDL_Threads[i]) {
            break;
        }
    }
    if (i < SDL_numthreads) {
        if (--SDL_numthreads > 0) {
            while (i < SDL_numthreads) {
                SDL_Threads[i] = SDL_Threads[i + 1];
                ++i;
            }
        } else {
            SDL_maxthreads = 0;
            SDL_free(SDL_Threads);
            SDL_Threads = NULL;
        }
#ifdef DEBUG_THREADS
        printf("Deleting thread (%d left - %d max)\n",
               SDL_numthreads, SDL_maxthreads);
#endif
    }
    SDL_mutexV(thread_lock);

#if 0   /* There could be memory corruption if another thread is starting */
    if (SDL_Threads == NULL) {
        SDL_ThreadsQuit();
    }
#endif
}
Ejemplo n.º 5
0
/** Handle key press events
 *
 * */
void draw_maint_map::key_press(SDL_KeyboardEvent *button)
{
	sdl_drawmode::key_press(button);
	while (SDL_mutexP(draw_mtx) == -1) {};
	if (button->type == SDL_KEYDOWN)
	{
		switch(button->keysym.sym)
		{
			case SDLK_LEFT:
				y--;
				themap->set_hotspot(mapnum, x, y);
				break;
			case SDLK_RIGHT:
				y++;
				themap->set_hotspot(mapnum, x, y);
				break;
			case SDLK_UP:
				x++;
				themap->set_hotspot(mapnum, x, y);
				break;
			case SDLK_DOWN:
				x--;
				themap->set_hotspot(mapnum, x, y);
				break;
			case SDLK_PAGEUP:
				mapnum++;
				themap->set_hotspot(mapnum, x, y);
				break;
			case SDLK_PAGEDOWN:
				mapnum--;
				themap->set_hotspot(mapnum, x, y);
				break;
			default:
				break;
		}
	}
	SDL_mutexV(draw_mtx);
}
Ejemplo n.º 6
0
void CDROM_Interface_Ioctl::dx_CDAudioCallBack(Bitu len) {
	len *= 4;       // 16 bit, stereo
	if (!len) return;
	if (!player.isPlaying || player.isPaused) {
		player.channel->AddSilence();
		return;
	}
	SDL_mutexP(player.mutex);
	while (player.bufLen < (Bits)len) {
		bool success;
		if (player.targetFrame > player.currFrame)
			success = player.cd->ReadSector(&player.buffer[player.bufLen], true, player.currFrame);
		else success = false;
		
		if (success) {
			player.currFrame++;
			player.bufLen += RAW_SECTOR_SIZE;
		} else {
			memset(&player.buffer[player.bufLen], 0, len - player.bufLen);
			player.bufLen = len;
			player.isPlaying = false;
		}
	}
	SDL_mutexV(player.mutex);
	if (player.ctrlUsed) {
		Bit16s sample0,sample1;
		Bit16s * samples=(Bit16s *)&player.buffer;
		for (Bitu pos=0;pos<len/4;pos++) {
			sample0=samples[pos*2+player.ctrlData.out[0]];
			sample1=samples[pos*2+player.ctrlData.out[1]];
			samples[pos*2+0]=(Bit16s)(sample0*player.ctrlData.vol[0]/255.0);
			samples[pos*2+1]=(Bit16s)(sample1*player.ctrlData.vol[1]/255.0);
		}
	}
	player.channel->AddSamples_s16(len/4,(Bit16s *)player.buffer);
	memmove(player.buffer, &player.buffer[len], player.bufLen - len);
	player.bufLen -= len;
}
Ejemplo n.º 7
0
/* Routines for manipulating the thread list */
static void
SDL_AddThread(SDL_Thread * thread)
{
    /* WARNING:
       If the very first threads are created simultaneously, then
       there could be a race condition causing memory corruption.
       In practice, this isn't a problem because by definition there
       is only one thread running the first time this is called.
     */
    if (!thread_lock) {
        if (SDL_ThreadsInit() < 0) {
            return;
        }
    }
    SDL_mutexP(thread_lock);

    /* Expand the list of threads, if necessary */
#ifdef DEBUG_THREADS
    printf("Adding thread (%d already - %d max)\n",
           SDL_numthreads, SDL_maxthreads);
#endif
    if (SDL_numthreads == SDL_maxthreads) {
        SDL_Thread **threads;
        threads = (SDL_Thread **) SDL_realloc(SDL_Threads,
                                              (SDL_maxthreads +
                                               ARRAY_CHUNKSIZE) *
                                              (sizeof *threads));
        if (threads == NULL) {
            SDL_OutOfMemory();
            goto done;
        }
        SDL_maxthreads += ARRAY_CHUNKSIZE;
        SDL_Threads = threads;
    }
    SDL_Threads[SDL_numthreads++] = thread;
  done:
    SDL_mutexV(thread_lock);
}
Ejemplo n.º 8
0
void SoundSDL::write(u16 * finalWave, int length)
{
	if (!_initialized)
		return;

	if (SDL_GetAudioStatus() != SDL_AUDIO_PLAYING)
		SDL_PauseAudio(0);

	SDL_mutexP(_mutex);

	unsigned int samples = length / 4;

	std::size_t avail;
	while ((avail = _rbuf.avail() / 2) < samples)
	{
		_rbuf.write(finalWave, avail * 2);

		finalWave += avail * 2;
		samples -= avail;

		// If emulating and not in speed up mode, synchronize to audio
		// by waiting till there is enough room in the buffer
		if (emulating && !speedup)
		{
			SDL_CondWait(_cond, _mutex);
		}
		else
		{
			// Drop the remaining of the audio data
			SDL_mutexV(_mutex);
			return;
		}
	}

	_rbuf.write(finalWave, samples * 2);

	SDL_mutexV(_mutex);
}
Ejemplo n.º 9
0
void set_background( image_res_t *img )
{
    int i;

    SDL_Surface* old = background;
    image_res_t *old_img = background_img;

    // hide all sprites
    for ( i = 0; i < 0x20; i ++ )
        set_sprite( i, NULL );

    SDL_mutexP(sdl_mutex);

    if ( img )
    {
        SDL_Surface* temp_surf;
        temp_surf = SDL_CreateRGBSurfaceFrom( img->data,
                        img->width, img->height, img->bpp, img->width * (img->bpp / 8),
                        0, 0, 0, 0);
        background = SDL_DisplayFormat( temp_surf );
        background_img = img;
        SDL_FreeSurface( temp_surf );
    }
    else
        background = NULL;

    if ( old )
    {
        SDL_FreeSurface( old );
        free( old_img->data );
        free( old_img );
    }

    SDL_mutexV(sdl_mutex);

    SDL_ExposeEvent expose = { SDL_VIDEOEXPOSE };
    SDL_PushEvent( &expose );
}
Ejemplo n.º 10
0
Archivo: client.c Proyecto: theZiz/hase
int push_thread_function(void* data)
{
	while (push_message >= 0 || push_thread_first)
	{
		if (push_thread_first)
		{
			pThreadData thread_data = push_thread_first;
			int i = 0;
			if (push_message != -2)
				for (; i < 3; i++)
				{
					int r = push_game(thread_data->player,thread_data->second_of_player,thread_data->data);
					if (r == 0)
						break;
					if (r == 2)
						return 1;
				}
			if (i == 3)
				printf("BIG PANIC at second %i!\n",thread_data->second_of_player);
			else
			{
				if (i != 0)
					printf("Little panic... %i\n",i);
				printf("Sent second %i!\n",thread_data->second_of_player);
				//PULL STACK
				SDL_mutexP(push_mutex);
				push_thread_first = push_thread_first->next;
				if (push_thread_first == NULL)
					push_thread_last = NULL;
				SDL_mutexV(push_mutex);
				free(thread_data);
			}
		}
		else
			spSleep(100000);//100ms
	}
	return 0;
}
Ejemplo n.º 11
0
static int pop_save_return(lua_State *L)
{
	save_queue *q = NULL;
	SDL_mutexP(main_save->lock_oqueue);
	if (main_save->oqueue_head)
	{
		q = main_save->oqueue_head;
		if (q) main_save->oqueue_head = q->next;
		if (!main_save->oqueue_head) main_save->oqueue_tail = NULL;
	}
	SDL_mutexV(main_save->lock_oqueue);

	if (q)
	{
		lua_pushstring(L, q->zfname);
		free(q->zfname);
		free(q);
	}
	else
		lua_pushnil(L);

	return 1;
}
Ejemplo n.º 12
0
Uint32 ChatState::processFailInternal() {
	_LOGDATA("entering processFail with state %s and inflights %d", STATE_WORDS[this->_state].c_str(), this->_inflightRecons);
	SDL_mutexP(this->_inflightLock);
	if (this->_inflightRecons > 0) {
		_LOGDATA("ProcessFail finds inflight already, no new task.");
		SDL_mutexV(this->_inflightLock);
		return 0;
	}
	this->_inflightRecons += 1;
	SDL_mutexV(this->_inflightLock);

	unsigned int mins = chooseRetryMins();
	this->_consecFails += 1;
	if ((this->_consecFails > RETRY_INTERVALS_LEN) && (this->_xmpp_expire_date < time(NULL))) {
		_LOGDATA("expired and at the end of all intervals... not scheduling another delayed connect");
		return 0;
	}
	srand(time(NULL));
	unsigned int jitter = rand() % 10000;
	_LOGDATA("ProcessFail after consec fail %d, launching timed chat connector with delay %d mins %d seconds of jitter", this->_consecFails, mins, jitter);

	return (60000 * mins + jitter);
}
Ejemplo n.º 13
0
void Network::skip(int len)
{
    SDL_mutexP(mMutex);
    mToSkip += len;
    if (!mInSize)
    {
        SDL_mutexV(mMutex);
        return;
    }

    if (mInSize >= mToSkip)
    {
        mInSize -= mToSkip;
        memmove(mInBuffer, mInBuffer + mToSkip, mInSize);
        mToSkip = 0;
    }
    else
    {
        mToSkip -= mInSize;
        mInSize = 0;
    }
    SDL_mutexV(mMutex);
}
Ejemplo n.º 14
0
/*
 * Clear all tasks. There may still remain one currently executing task.
 */
void
texasync_clear(void)
{
        SDL_mutexP(storage_mutex);
        {
                while (finished_tasks != NULL) {
                        Task *task = finished_tasks;
                        DL_DELETE(finished_tasks, task);
                        free_task(task);
                        
                        /* Update finished task counter. */
                        assert(num_finished > 0);
                        num_finished--;
                }
                
                while (active_tasks != NULL) {
                        Task *task = active_tasks;
                        DL_DELETE(active_tasks, task);
                        free_task(task);
                }
        }
        SDL_mutexV(storage_mutex);
}
Ejemplo n.º 15
0
bool
MPEGstream:: seek_marker(MPEGstream_marker const * marker)
{
    SDL_mutexP(mutex);

    if ( marker ) {
        /* Release current buffer */
        if(br->IsLocked())
        {
            br->Unlock();
            marker->marked_buffer->Lock();
        }

        /* Reset the data positions */
        br = marker->marked_buffer;
        data = marker->marked_data;
        stop = marker->marked_stop;
    }

    SDL_mutexV(mutex);

    return(marker != 0);
}
Ejemplo n.º 16
0
bool Network::messageReady()
{
    int len = -1, msgId;

    SDL_mutexP(mMutex);
    if (mInSize >= 2)
    {
        msgId = readWord(0);
        if (msgId == SMSG_SERVER_VERSION_RESPONSE)
            len = 10;
        else
            len = packet_lengths[msgId];

        if (len == -1 && mInSize > 4)
            len = readWord(2);

    }

    bool ret = (mInSize >= static_cast<unsigned int>(len));
    SDL_mutexV(mMutex);

    return ret;
}
Ejemplo n.º 17
0
void FrameExporter::dump() {

    display.mode2D();

    glEnable(GL_TEXTURE_2D);
    glDisable(GL_BLEND);

    char* next_pixel_ptr = (pixels_shared_ptr == pixels1) ? pixels2 : pixels1;

    // copy pixels - now the right way up
    glReadPixels(0, 0, display.width, display.height,
                 GL_RGB, GL_UNSIGNED_BYTE, next_pixel_ptr);

    // wait for lock before changing the pointer to point to our new buffer
    SDL_mutexP(mutex);

    //flip buffer we are pointing at
    pixels_shared_ptr = next_pixel_ptr;
    dumper_thread_state = FRAME_EXPORTER_DUMP;

    SDL_CondSignal(cond);
    SDL_mutexV(mutex);
}
Ejemplo n.º 18
0
int
network_thread(client_thread_t *holder)
{
  int		status;

  if (holder == NULL)
    {
      ERR_RAISE(EC_NULL_PTR_DIE);
      return (ERROR);
    }
  status = CLIENT_STATE_ON;
  while (status == CLIENT_STATE_ON)
    {
      SDL_mutexP(holder->client->mutex);
      status = holder->client->state;
      SDL_mutexV(holder->client->mutex);
      SDL_Delay(NETWORK_DELAY);
    }
  holder->client->launched_threads--;
  SDL_mutexV(holder->client->mutex);
  free(holder);
  return (SUCCESS);
}
Ejemplo n.º 19
0
/*
 * @brief Wrap the user's function in our own for introspection.
 */
static int32_t Thread_Run(void *data) {
	thread_t *t = (thread_t *) data;

	while (thread_pool.mutex) {

		SDL_mutexP(t->mutex);

		if (t->status == THREAD_RUNNING) {
			t->Run(t->data);

			t->Run = NULL;
			t->data = NULL;

			t->status = THREAD_WAIT;
		} else {
			SDL_CondWait(t->cond, t->mutex);
		}

		SDL_mutexV(t->mutex);
	}

	return 0;
}
Ejemplo n.º 20
0
int midi_port_foreach(struct midi_provider *p, struct midi_port **cursor)
{
        int i;
        if (!midi_port_mutex) return 0;

        SDL_mutexP(midi_port_mutex);
        do {
                if (!*cursor) {
                        i = 0;
                } else {
                        i = ((*cursor)->num) + 1;
                        while (i < port_alloc && !port_top[i]) i++;
                }
                if (i >= port_alloc) {
                        *cursor = NULL;
                        SDL_mutexV(midi_port_mutex);
                        return 0;
                }
                *cursor = port_top[i];
        } while (p && (*cursor)->provider != p);
        SDL_mutexV(midi_port_mutex);
        return 1;
}
Ejemplo n.º 21
0
static int carlu_alloc_dev_mem(struct carlu *ar,
				struct frame *frame)
{
	struct _carl9170_tx_superframe *txp = (void *)frame->data;
	unsigned int len, chunks;

	len = roundup(frame->len, ar->dma_chunk_size);
	chunks = len / ar->dma_chunk_size;

	SDL_mutexP(ar->mem_lock);
	if (ar->tx_pending >= ar->dma_chunks ||
	    ar->used_dma_chunks + chunks >= ar->dma_chunks) {
		SDL_mutexV(ar->mem_lock);
		return -ENOSPC;
	}

	ar->used_dma_chunks += chunks;
	ar->tx_pending++;
	txp->s.cookie = ar->cookie++;
	SDL_mutexV(ar->mem_lock);

	return 0;
}
Ejemplo n.º 22
0
void draw_char_sel::get_login_chars()
{
	while (SDL_mutexP(draw_mtx) == -1) {};
	lin_char_info **data = owner->get_login_chars();
	sdl_animate_button **chars;
	chars = (sdl_animate_button**)&widgets[0];
	for (int i = 0; i < 4; i++)
	{
		chars[i]->set_info(data[i + (page_num*4)]);
	}
	ready = true;
	
	sdl_char_info *stuff;
	stuff = (sdl_char_info*)widgets[11];
	stuff->hand_info(chars[0]->get_info());
	cur_char_slot = 0;
	chars[0]->animate(true);
	chars[1]->animate(false);
	chars[2]->animate(false);
	chars[3]->animate(false);

	SDL_mutexV(draw_mtx);
}
Ejemplo n.º 23
0
static void AA_DirectUpdate(_THIS, int numrects, SDL_Rect *rects)
{
	int i;
	SDL_Rect *rect;

	fastscale (AA_buffer, aa_image(AA_context), AA_w, aa_imgwidth (AA_context), AA_h, aa_imgheight (AA_context));
#if 1
	aa_renderpalette(AA_context, AA_palette, AA_rparams, 0, 0, aa_scrwidth(AA_context), aa_scrheight(AA_context));
#else
	/* Render only the rectangles in the list */
	printf("Update rects : ");
	for ( i=0; i < numrects; ++i ) {
		rect = &rects[i];
		printf("(%d,%d-%d,%d)", rect->x, rect->y, rect->w, rect->h);
		aa_renderpalette(AA_context, AA_palette, AA_rparams, rect->x * AA_x_ratio, rect->y * AA_y_ratio, rect->w * AA_x_ratio, rect->h * AA_y_ratio);
	}
	printf("\n");
#endif
	SDL_mutexP(AA_mutex);
	aa_flush(AA_context);
	SDL_mutexV(AA_mutex);
	return;
}
Ejemplo n.º 24
0
static int FillHWRect(_THIS, SDL_Surface *dst, SDL_Rect *rect, Uint32 color)
{
	int dstX, dstY;
	int dstW, dstH;
	RivaBitmap *Bitmap = (RivaBitmap *)(mapped_io + BITMAP_OFFSET);

	
	if ( switched_away ) {
		return -2; 
	}
	if ( dst == this->screen ) {
		SDL_mutexP(hw_lock);
	}

	
	dstW = rect->w;
	dstH = rect->h;
	FB_dst_to_xy(this, dst, &dstX, &dstY);

	
	dstX += rect->x;
	dstY += rect->y;

	RIVA_FIFO_FREE(Bitmap, 1);
	Bitmap->Color1A = color;

	RIVA_FIFO_FREE(Bitmap, 2);
	Bitmap->UnclippedRectangle[0].TopLeft     = (dstX << 16) | dstY; 
	Bitmap->UnclippedRectangle[0].WidthHeight = (dstW << 16) | dstH;

	FB_AddBusySurface(dst);

	if ( dst == this->screen ) {
		SDL_mutexV(hw_lock);
	}
	return(0);
}
Ejemplo n.º 25
0
static int FillHWRect(_THIS, SDL_Surface *dst, SDL_Rect *rect, Uint32 color)
{
    int dstX, dstY;
    int dstW, dstH;
    RivaBitmap *Bitmap = (RivaBitmap *)(mapped_io + BITMAP_OFFSET);

    /* Don't blit to the display surface when switched away */
    if ( switched_away ) {
        return -2; /* no hardware access */
    }
    if ( dst == this->screen ) {
        SDL_mutexP(hw_lock);
    }

    /* Set up the X/Y base coordinates */
    dstW = rect->w;
    dstH = rect->h;
    FB_dst_to_xy(this, dst, &dstX, &dstY);

    /* Adjust for the current rectangle */
    dstX += rect->x;
    dstY += rect->y;

    RIVA_FIFO_FREE(Bitmap, 1);
    Bitmap->Color1A = color;

    RIVA_FIFO_FREE(Bitmap, 2);
    Bitmap->UnclippedRectangle[0].TopLeft     = (dstX << 16) | dstY;
    Bitmap->UnclippedRectangle[0].WidthHeight = (dstW << 16) | dstH;

    FB_AddBusySurface(dst);

    if ( dst == this->screen ) {
        SDL_mutexV(hw_lock);
    }
    return(0);
}
Ejemplo n.º 26
0
/* midi engines register a provider (one each!) */
struct midi_provider *midi_provider_register(const char *name,
                struct midi_driver *driver)
{
        struct midi_provider *n;

        if (!midi_mutex) return NULL;

        n = mem_alloc(sizeof(struct midi_provider));
        n->name = str_dup(name);
        n->poll = driver->poll;
        n->enable = driver->enable;
        n->disable = driver->disable;
        if (driver->flags & MIDI_PORT_CAN_SCHEDULE) {
                n->send_later = driver->send;
                n->send_now = NULL;
                n->drain = driver->drain;
        } else {
                n->send_later = NULL;
                n->send_now = driver->send;
                n->drain = NULL;
        }

        SDL_mutexP(midi_mutex);
        n->next = port_providers;
        port_providers = n;

        if (driver->thread) {
                // FIXME this cast is stupid
                n->thread = SDL_CreateThread((int (*)(void*))driver->thread, n);
        } else {
                n->thread = NULL;
        }

        SDL_mutexV(midi_mutex);

        return n;
}
Ejemplo n.º 27
0
void SDLAudio::QueueBuffer(int stream, unsigned short bits,
			int channels, short* memory, int size, int samplerate)
{
	if (stream != 0) {
		return;
	}

	assert(!MusicPlaying);

	BufferedData d;

	// convert our buffer, if necessary
	if (bits != 16 || channels != audio_channels || samplerate != audio_rate) {
		SDL_AudioCVT cvt;
		if (SDL_BuildAudioCVT(&cvt, (bits == 8 ? AUDIO_S8 : AUDIO_S16SYS), channels, samplerate,
				audio_format, audio_channels, audio_rate) == 0) {
			printMessage("SDLAudio", "Couldn't convert video stream!\ntrying to convert %d bits, %d channels, %d rate\n", RED,
				bits, channels, samplerate);
			return;
		}
		cvt.buf = (Uint8*)malloc(size*cvt.len_mult);
		memcpy(cvt.buf, memory, size);
		cvt.len = size;
		SDL_ConvertAudio(&cvt);

		d.size = cvt.len*cvt.len_ratio;
		d.buf = (char *)cvt.buf;
	} else {
		d.size = size;
		d.buf = (char *)malloc(d.size);
		memcpy(d.buf, memory, d.size);
	}

	SDL_mutexP(OurMutex);
	buffers.push_back(d);
	SDL_mutexV(OurMutex);
}
Ejemplo n.º 28
0
static int WaitForYourTurn(void)
{
    MutexElmt *currentElmt = NULL,
              *lastElmt = NULL;

    if ( !(currentElmt = malloc(sizeof(MutexElmt))) )
        return 0;

    currentElmt->next = NULL;
    if ( !(currentElmt->mutex = SDL_CreateSemaphore(0)) )
    {
        free(currentElmt);
        return 0;
    }

    if (!priorMutex)
        priorMutex = SDL_CreateMutex();
    SDL_mutexP(priorMutex);

    if (!mainMutexList)
    {
        mainMutexList = currentElmt;
        SDL_mutexV(priorMutex);
    }
    else
    {
        lastElmt = mainMutexList;
        while (lastElmt->next)
            lastElmt = lastElmt->next;
        lastElmt->next = currentElmt;

        SDL_mutexV(priorMutex);
        SDL_SemWait(currentElmt->mutex);
    }

    return 1;
}
Ejemplo n.º 29
0
void draw_maint_png::draw(SDL_Surface *display)
{
	while (SDL_mutexP(draw_mtx) == -1) {};
	SDL_FillRect(display, NULL, 0);
	sdl_drawmode::draw(display);
	char temp[27];
	sprintf(temp, "Displaying %d.png", background);
	lineage_font.draw(display, 320, 240, temp, 0x7392);
	if (extracting && (background < 65535))
	{
		char name[500];
		sprintf(name, "png/%d.bmp", background);
		if (gfx[0]->valid())
			gfx[0]->make_bmp(name);
		
		background++;
		
		if (gfx[0] != 0)
		{
			delete gfx[0];
			gfx[0] = 0;
		}
		gfx[0] = new sdl_graphic(background, 0, 0, GRAPH_PNG, owner);
	}
	else if (extracting && (background == 65535))
	{
		extracting = false;
		background = 0;
		if (gfx[0] != 0)
		{
			delete gfx[0];
			gfx[0] = 0;
		}
		gfx[0] = new sdl_graphic(background, 0, 0, GRAPH_PNG, owner);
	}
	SDL_mutexV(draw_mtx);
}
Ejemplo n.º 30
0
static int mem_getc(SDL_RWops *context)
{
	int c;

	SDL_mutexP(multipleArchiveMutEx);

	if(!bInAMultipleFuncion && context == archive)
	{		
		current = context;

		if(context->stdioFilePosition != context->filePosition)
		{
			//Position changed by a multiple file call
			//Restore
			context->hidden.mem.here = context->hidden.mem.base + context->stdioFilePosition;
			context->filePosition = context->stdioFilePosition;			
		}
	}

	if ( (context->hidden.mem.here + 1) > context->hidden.mem.stop ) 
	{
		SDL_mutexV(multipleArchiveMutEx);
		return EOF;
	}

	c = *context->hidden.mem.here;
	context->hidden.mem.here++;

	if(!bInAMultipleFuncion)
	{
		context->filePosition++;
		context->stdioFilePosition = context->filePosition;
	}

	SDL_mutexV(multipleArchiveMutEx);
	return c;
}