/*
 * 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);
}
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);
}
Exemple #3
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);
}
Exemple #4
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;
}
Exemple #5
0
int mutex_unlock(Mutex* m)
{
    int ret = 0;
    

    if(!m) return -1;
    if(!m->mutex) return -2;
    if(SDL_mutexV(m->mutex)==-1)
        printf("Fehler bei unlock!\n");
    else return 0;
    /*

#ifdef _WIN32   
    ret = !ReleaseMutex(m->mutex);
#else
    ret = pthread_mutex_unlock((pthread_mutex_t*)m->mutex);
#endif
    
    //if(ret)
        //printf("capture.unlock_mutex fehler bei unlock mutex\n");
     * */
    return ret;
}
Exemple #6
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;
}
Exemple #7
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);
}
Exemple #8
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;
}
Exemple #9
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;
}
Exemple #10
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
}
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);
}
Exemple #12
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);
}
Exemple #13
0
unsigned int sdl_user::add_request(client_request rqst)
{
	unsigned int temp_val;
	if (stop_thread == false)
	{
		while (SDL_mutexP(requests_mtx) == -1) {};
		client_request *temp = new client_request;
		temp->data.rload.name = 0;
		memcpy(temp, &rqst, sizeof(rqst));
		temp->id = ++request_id;
		temp_val = request_id;
		switch (rqst.request)
		{
			case CLIENT_REQUEST_LOAD_SPRITE:
				if (rqst.data.sload.name != 0)
				{
					temp->data.sload.name = new char[strlen(rqst.data.sload.name)+1];
					strcpy(temp->data.sload.name, rqst.data.sload.name);
				}
				break;
			case CLIENT_REQUEST_LOAD_SDL_GRAPHIC:
				if (rqst.data.rload.name != 0)
				{
					temp->data.rload.name = new char[strlen(rqst.data.rload.name)+1];
					strcpy(temp->data.rload.name, rqst.data.rload.name);
				}
				break;
			case CLIENT_REQUEST_CHECK_MAP:
			case CLIENT_REQUEST_LOAD_TILE:
			default:
				break;
		}
		request_list.push_back(temp);
		SDL_mutexV(requests_mtx);
	}
	return temp_val;
}
Exemple #14
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);
}
Exemple #15
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;
}
Exemple #16
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);
}
Exemple #17
0
static void mix_buffer(SDL_AudioDevice *audio, UInt8 *buffer)
{
   if ( ! audio->paused ) {
#ifdef MACOSX
        SDL_mutexP(audio->mixer_lock);
#endif
        if ( audio->convert.needed ) {
            audio->spec.callback(audio->spec.userdata,
                    (Uint8 *)audio->convert.buf,audio->convert.len);
            SDL_ConvertAudio(&audio->convert);
            if ( audio->convert.len_cvt != audio->spec.size ) {
                /* Uh oh... probably crashes here */;
            }
            memcpy(buffer, audio->convert.buf, audio->convert.len_cvt);
        } else {
            audio->spec.callback(audio->spec.userdata, buffer, audio->spec.size);
        }
#ifdef MACOSX
        SDL_mutexV(audio->mixer_lock);
#endif
    }

    DecrementAtomic((SInt32 *) &need_to_mix);
}
extern void SDL_ANDROID_MainThreadPushMouseMotion(int x, int y)
{
    int nextEvent = getNextEventAndLock();
    if( nextEvent == -1 )
        return;

    int prevEvent = getPrevEventNoLock();
    if( prevEvent > 0 && BufferedEvents[prevEvent].type == SDL_MOUSEMOTION )
    {
        // Reuse previous mouse motion event, to prevent mouse movement lag
        BufferedEvents[prevEvent].motion.x = x;
        BufferedEvents[prevEvent].motion.y = y;
    }
    else
    {
        SDL_Event * ev = &BufferedEvents[BufferedEventsEnd];
        ev->type = SDL_MOUSEMOTION;
        ev->motion.x = x;
        ev->motion.y = y;
    }

    BufferedEventsEnd = nextEvent;
    SDL_mutexV(BufferedEventsMutex);
};
Exemple #19
0
// Runs into main thread
static int particles_free(lua_State *L)
{
	particles_type *ps = (particles_type*)auxiliar_checkclass(L, "core{particles}", 1);
	plist *l = ps->l;

//	printf("Deleting particle from main lua state %x :: %x\n", (int)ps->l, (int)ps);

	if (l && l->pt) SDL_mutexP(l->pt->lock);

	ps->alive = FALSE;
	if (l) l->ps = NULL;
	ps->l = NULL;
	SDL_DestroyMutex(ps->lock);

	if (ps->texcoords) { free(ps->texcoords); ps->texcoords = NULL; }
	if (ps->vertices) { free(ps->vertices); ps->vertices = NULL; }
	if (ps->colors) { free(ps->colors); ps->colors = NULL; }
	if (ps->particles) { free(ps->particles); ps->particles = NULL; }

	if (l && l->pt) SDL_mutexV(l->pt->lock);

	lua_pushnumber(L, 1);
	return 1;
}
void PlayerInterface::netMessageSyncState(const NetMessage* message)
{
    const PlayerStateSync *sync_mesg
        = (const PlayerStateSync *) message;
    PlayerID player_id = sync_mesg->player_state.getPlayerIndex();

    if(player_id >= max_players) {
        LOGGER.warning("Malformed MessageSyncState message");
        return;
    }
    
    SDL_mutexP(mutex);
        player_lists[player_id].setFromNetworkPlayerState(&sync_mesg->player_state);
        // XXX ALLY
        if ( player_lists[player_id].isFree() )
        {
            disconnectedPlayerAllianceCleanup(player_id);
        }
        if ( player_id == local_player_index && player_lists[player_id].isSelectingFlag() )
        {
            Desktop::setVisibility("GFlagSelectionView", true);
        }
    SDL_mutexV(mutex);
}
SDL_Surface *ANDROID_SetVideoModeMT(_THIS, SDL_Surface *current, int width, int height, int bpp, Uint32 flags)
{
	if( flags & SDL_OPENGL || flags & SDL_HWSURFACE )
	{
		return NULL;
	}
	SDL_mutexP(videoThread.mutex);
	while( ! videoThread.threadReady )
		SDL_CondWaitTimeout(videoThread.cond2, videoThread.mutex, 1000);
	videoThread.cmd = CMD_SETVIDEOMODE;
	videoThread._this = this;
	videoThread.current = current;
	videoThread.width = width;
	videoThread.height = height;
	videoThread.bpp = bpp;
	videoThread.flags = flags;
	videoThread.execute = 1;
	SDL_CondSignal(videoThread.cond);
	while( videoThread.execute )
		SDL_CondWaitTimeout(videoThread.cond2, videoThread.mutex, 1000);
	SDL_Surface * ret = videoThread.retcode2;
	SDL_mutexV(videoThread.mutex);
	return ret;
}
Exemple #22
0
/*
 * Free memory.
 */
void
mem_free(void *ptr)
{
#if MEMDEBUG
        SDL_mutexP(alloc_mutex);
        {
                assert(ptr);
                allocation *alc;
                HASH_FIND_PTR(alloc_hash, &ptr, alc);
                assert(alc != NULL);
                
                /* Update total numer of allocated bytes. */
                total_bytes -= alc->size;
                log_msg("[MEM] Free %p=%s for `%s` (total: %s)", ptr,
                        human(alc->size), alc->descr, human(total_bytes));
                
                /* Remove from hash and free allocation. */
                HASH_DEL(alloc_hash, alc);
                free(alc);
        }
        SDL_mutexV(alloc_mutex);
#endif
        free(ptr);
}
Exemple #23
0
static void
UnQueueThread (TrueThread thread)
{
	volatile TrueThread *ptr;

	SDL_mutexP (threadQueueMutex);
	ptr = &threadQueue;
	while (*ptr != thread)
	{
#ifdef DEBUG_THREADS
		if (*ptr == NULL)
		{
			// Should not happen.
			log_add (log_Debug, "Error: Trying to remove non-present thread "
					"from thread queue.");
			fflush (stderr);
			explode ();
		}
#endif  /* DEBUG_THREADS */
		ptr = &(*ptr)->next;
	}
	*ptr = (*ptr)->next;
	SDL_mutexV (threadQueueMutex);
}
void MPEGstream::insert_packet(Uint8 * Data, Uint32 Size, double timestamp)
{
    MPEGlist * newbr;

    /* Discard all packets if not enabled */
    if(!enabled) return;

    SDL_mutexP(mutex);

    preread_size += Size;

    /* Seek the last buffer */
    for(newbr = br; newbr->Next(); newbr = newbr->Next());

    /* Position ourselves at the end of the stream */
    newbr = newbr->Alloc(Size);
    if ( Size ) {
        memcpy(newbr->Buffer(), Data, Size);
    }
    newbr->TimeStamp = timestamp;

    SDL_mutexV(mutex);
    garbage_collect();
}
/*
** Put int the map cell sprite of egg
*/
void		put_eggs(int x, int y, t_sdl *sdl, SDL_Rect *pos)
{
  t_sdl_egg	*egg;
  int		cpt;

  SDL_mutexP(sdl->elem->mut_egg);
  egg = sdl->elem->egg;
  cpt = 0;
  while (egg)
    {
      if (egg->x == x && egg->y == y)
	cpt++;
      egg = egg->next;
    }
  if (cpt > 0)
    {
      sdl_sprite_egg(&sdl->egg.pos_egg, pos, 0);
      sdl_update_egg(&sdl->egg.rct_egg,
		     (cpt > 1) ? 1 : 0, 0);
      xSDL_BlitSurface(sdl->egg.sdl_egg, &sdl->egg.rct_egg,
		      sdl->screen, &sdl->egg.pos_egg);
    }
  SDL_mutexV(sdl->elem->mut_egg);
}
Exemple #26
0
int main(int, char **)
{
    fcntl(STDIN_FILENO, F_SETFL, fcntl(STDIN_FILENO, F_GETFL) & ~O_NONBLOCK);

    atexit(SDL_Quit);

    KInstance in("noatuntyler");

    finished = false;
    access_mutex = SDL_CreateMutex();

    init_renderer1();
    printf("%u\n", winID());
    fflush(stdout);
    init_renderer2();
    thread = SDL_CreateThread((int (*)(void *))renderer, NULL);

    fd_set set;
    struct timeval tv;
    while(check_finished() != 1)
    {
        FD_ZERO(&set);
        FD_SET(STDIN_FILENO, &set);
        tv.tv_sec = 0;
        tv.tv_usec = 250;
        if(0 < select(STDIN_FILENO + 1, &set, 0, 0, &tv))
        {
            SDL_mutexP(access_mutex);
            read(STDIN_FILENO, (void *)pcm_data, sizeof(short) * 2 * 512);
            SDL_mutexV(access_mutex);
        }
        usleep(5);
    }
    /*fprintf(stderr,"exiting main()\n");*/
    SDL_WaitThread(thread, NULL);
}
void PlayerInterface::disconnectPlayerCleanup( Uint16 index )
{
    PlayerState *player_state = getPlayer( index );
    if ( player_state )
    {
        PlayerAllianceUpdate allie_update;

        unsigned short disconnect_player_index;

        disconnect_player_index = index;

        SDL_mutexP(mutex);

        disconnectedPlayerAllianceCleanup(disconnect_player_index);

        player_state->setStatus( _player_state_free );

        PlayerStateSync player_state_update(player_state->getNetworkPlayerState());

        SDL_mutexV(mutex);

        SERVER->broadcastMessage(&player_state_update, sizeof(PlayerStateSync));
    }
}
Exemple #28
0
		int handle() {
			if(task->manager == NULL) {
				errors << "TaskManager::TaskHandler: invalid task with unset manager" << endl;
				return -1;
			}
			{
				Mutex::ScopedLock lock(*task->mutex);
				task->state = Task::TS_QUEUED ? Task::TS_RUNNINGQUEUED : Task::TS_RUNNING;
			}
			int ret = task->breakSignal ? -1 : task->handle();
			{
				SDL_mutexP(task->manager->mutex);
				boost::shared_ptr<Mutex> m = task->mutex;
				Mutex::ScopedLock lock(*m);
				
				if(task->queuedTask) {
					if(!task->manager->quitSignal) {
						Mutex::ScopedLock lock(*task->queuedTask->mutex);
						task->manager->runningTasks.insert(task->queuedTask);
						TaskHandler* handler = new TaskHandler();
						handler->task = task->queuedTask;
						task->queuedTask->state = Task::TS_WAITFORIMMSTART;
						threadPool->start(handler, task->queuedTask->name + " handler", true);
					}
					else
						// We were requested to quit, i.e. we should not start this queued task anymore.
						delete task->queuedTask;
				}
				
				task->manager->runningTasks.erase(task);
				SDL_CondSignal(task->manager->taskFinished);
				SDL_mutexV(task->manager->mutex);
				delete task;
			}			
			return ret;
		}
Exemple #29
0
static int multiple_read(SDL_RWops *context, void *ptr, int size, int maxnum)
{
	int num = maxnum, nread;

	SDL_mutexP(multipleArchiveMutEx);
	bInAMultipleFuncion = 1;

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

	//Slow
	/*if((baseFile + context->hidden.multiple.here) != (Uint32)SDL_RWtell( archive ))
	{
		SDL_RWseek(archive, baseFile + context->hidden.multiple.here, SEEK_SET);
	}*/

	//Fast	
	if(current != context || archive->filePosition != (baseFile + context->hidden.multiple.here))
	{
		SDL_RWseek(archive, baseFile + context->hidden.multiple.here, SEEK_SET);
		archive->filePosition = baseFile + context->hidden.multiple.here;
		current = context;		
	}

	nread = SDL_RWread(archive, ptr, size, num);
	context->hidden.multiple.here += nread*size;
	archive->filePosition += nread*size;

	bInAMultipleFuncion = 0;
	SDL_mutexV(multipleArchiveMutEx);

	return nread;
}
Exemple #30
0
void CB_Room::prepareRender()
{
    CB_Tile * tile;
    for(uint32_t i = 0; i < width * height; i++)
    {
        SDL_mutexP(roomMutex);
        tile = tileMap[i];
        SDL_mutexV(roomMutex);
        if(tile == 0)
        {
            continue;
        }
        uint32_t x = i % width;
        uint32_t y = i / width;
        double xStart = (double)x * tileSize - getScreenLeft();
        double yStart = getScreenHeight() + getScreenTop() - (double)y * tileSize;
        tile->prepareRender(xStart, yStart, tileSize);
    }
    vector<CB_RenderDataRel>::iterator it;
    for(it = propsList.begin(); it < propsList.end(); it++)
    {
        CB_Renderer::listRender(*it);
    }
}