Exemple #1
0
t_stat vid_open (DEVICE *dptr, uint32 width, uint32 height)
{
    if (!vid_active) {
        vid_active = TRUE;
        vid_width = width;
        vid_height = height;
        vid_mouse_captured = FALSE;

        vid_key_events.head = 0;
        vid_key_events.tail = 0;
        vid_key_events.count = 0;
        vid_key_events.sem = SDL_CreateSemaphore (1);
        vid_mouse_events.head = 0;
        vid_mouse_events.tail = 0;
        vid_mouse_events.count = 0;
        vid_mouse_events.sem = SDL_CreateSemaphore (1);

        vid_dev = dptr;

        vid_thread_handle = SDL_CreateThread (vid_thread, NULL);
        if (vid_thread_handle == NULL) {
            vid_close ();
            return SCPE_OPENERR;
        }

        sim_debug (SIM_VID_DBG_VIDEO|SIM_VID_DBG_KEY|SIM_VID_DBG_MOUSE, vid_dev, "vid_open() - Success\n");
    }
    return SCPE_OK;
}
Exemple #2
0
bool SoundSDL::init(long sampleRate)
{
	SDL_AudioSpec audio;
	audio.freq = sampleRate;
	audio.format = AUDIO_S16SYS;
	audio.channels = 2;
	audio.samples = 1024;
	audio.callback = soundCallback;
	audio.userdata = this;

	if(SDL_OpenAudio(&audio, NULL))
	{
		fprintf(stderr,"Failed to open audio: %s\n", SDL_GetError());
		return false;
	}

	_rbuf.reset(_delay * sampleRate * 2);

	_mutex          = SDL_CreateMutex();
#if !JS
	_semBufferFull  = SDL_CreateSemaphore (0);
	_semBufferEmpty = SDL_CreateSemaphore (1);
#endif
	_initialized    = true;

	return true;
}
Exemple #3
0
int init_worker_threads(graphics_state *state){
    state->sema_start_render = SDL_CreateSemaphore(0);
    state->sema_finish_render = SDL_CreateSemaphore(0);
    assert(state->sema_start_render != NULL);
    assert(state->sema_finish_render != NULL);
    state->num_workers = NUM_WORKER_THREADS;
    state->worker_threads = (SDL_Thread**)
        malloc(sizeof(SDL_Thread*)*state->num_workers);
    state->worker_pixel_ranges = (int*)
        malloc(sizeof(int)*4*state->num_workers);
    graphics_worker_arg *worker_args = (graphics_worker_arg*)
        malloc(sizeof(graphics_worker_arg)*state->num_workers);
    
    int i;
    for(i = 0; i < state->num_workers; i++){
        state->worker_pixel_ranges[i*4 + 0] = i*state->width/state->num_workers;
        state->worker_pixel_ranges[i*4 + 1] = 0;
        state->worker_pixel_ranges[i*4 + 2] = (i+1)*state->width/state->num_workers;
        state->worker_pixel_ranges[i*4 + 3] = state->height;
        worker_args[i] = (graphics_worker_arg){i, state};
        state->worker_threads[i] = SDL_CreateThread((int(*)(void*))graphics_worker_thread, worker_args+i);
        if(state->worker_threads[i] == NULL){
            perror("could not create worker thread");
            return -1;
        }
    }

    return 0;
}
bool SoundSDL::init(long sampleRate)
{
	SDL_AudioSpec audio;
	audio.freq = sampleRate;
	audio.format = AUDIO_S16SYS;
	audio.channels = 2;
	audio.samples = 1024;
	audio.callback = soundCallback;
	audio.userdata = this;

	if (!SDL_WasInit(SDL_INIT_AUDIO)) SDL_Init(SDL_INIT_AUDIO);

	_dev = SDL_OpenAudioDevice(NULL, 0, &audio, NULL, SDL_AUDIO_ALLOW_ANY_CHANGE);
	if(_dev < 0)
	{
		fprintf(stderr,"Failed to open audio: %s\n", SDL_GetError());
		return false;
	}

	_rbuf.reset(_delay * sampleRate * 2);

	if (!_initialized)
	{
		_mutex = SDL_CreateMutex();
		_semBufferFull  = SDL_CreateSemaphore (0);
		_semBufferEmpty = SDL_CreateSemaphore (1);
		_initialized    = true;
	}

	return true;
}
Exemple #5
0
void InitThreads (void)
{
if (gameStates.app.bMultiThreaded) {
	int	i;
	for (i = 0; i < 2; i++) {
#if MULTI_THREADED_LIGHTS
		gameData.threads.vertColor.info [i].done = SDL_CreateSemaphore (0);
		gameData.threads.vertColor.info [i].exec = SDL_CreateSemaphore (0);
		gameData.threads.vertColor.info [i].bDone =
		gameData.threads.vertColor.info [i].bExec =
		gameData.threads.vertColor.info [i].bQuit = 0;
		gameData.threads.vertColor.info [i].nId = i;
		gameData.threads.vertColor.info [i].pThread = SDL_CreateThread (VertexColorThread, &gameData.threads.vertColor.info [i].nId);
#endif
#if MULTI_THREADED_SHADOWS
		gameData.threads.clipDist.info [i].done = SDL_CreateSemaphore (0);
		gameData.threads.clipDist.info [i].exec = SDL_CreateSemaphore (0);
		gameData.threads.clipDist.info [i].nId = i;
		gameData.threads.clipDist.info [i].pThread = SDL_CreateThread (ClipDistThread, &gameData.threads.clipDist.info [i].nId);
#endif
		}
	}
gameData.render.vertColor.matAmbient[R] = 
gameData.render.vertColor.matAmbient[G] = 
gameData.render.vertColor.matAmbient[B] = AMBIENT_LIGHT;
gameData.render.vertColor.matAmbient[A] = 1.0f;
gameData.render.vertColor.matDiffuse [R] = 
gameData.render.vertColor.matDiffuse [G] = 
gameData.render.vertColor.matDiffuse [B] = DIFFUSE_LIGHT;
gameData.render.vertColor.matDiffuse [A] = 1.0f;
gameData.render.vertColor.matSpecular[R] = 
gameData.render.vertColor.matSpecular[G] = 
gameData.render.vertColor.matSpecular[B] = 0.0f;
gameData.render.vertColor.matSpecular[A] = 1.0f;
}
Exemple #6
0
int main(int argc, char** argv){
  if(!argv[1]){
    puts("No IP input found. Please initiate in the form ' ./Player <Server IP> '");
    exit(1);
  }

  //fgets from stdin to get clientname (and pass that into run, ezpz)
  printf("Please enter your name: ");

  fgets(clientname, 64, stdin);
  clientname[strlen(clientname) - 1] = '\0';

  printf("Hello %s!\n", clientname);

  strcat(clientname, " : ");
  namelen = strlen(clientname);
  ///


  SDL_Surface* screen = initScreen(); 

  //Initiate the semaphores and chatserver thread
  msgbuf_sem = SDL_CreateSemaphore(1);
  textSem = SDL_CreateSemaphore(1);
  chatserv = SDL_CreateThread(chatserver, screen);


  //Initiate the server connection
  int socket_id = server_setup(argv[1]);
    
  
  //Initiate the client's sprite
  Uint32 colorkey = SDL_MapRGB( screen->format, 255, 255, 255);
  initiate(socket_id, colorkey); 



  TTF_Init();
  run(screen, socket_id);


  //CEASE AND DESIST

  SDL_KillThread(chatserv);

  SDL_FreeSurface(screen);
  SDL_Quit();
  TTF_Quit();

  int i;
  for(i=0; i<numMessages; i++)
    if(text[i] != NULL)
      SDL_FreeSurface(text[i]);

  SDL_DestroySemaphore(msgbuf_sem);
  SDL_DestroySemaphore(textSem);

  return 1;
}
int
Android_CreateWindow(_THIS, SDL_Window * window)
{
    SDL_WindowData *data;
    
    if (Android_Window) {
        return SDL_SetError("Android only supports one window");
    }
    
    Android_PauseSem = SDL_CreateSemaphore(0);
    Android_ResumeSem = SDL_CreateSemaphore(0);

    /* Adjust the window data to match the screen */
    window->x = 0;
    window->y = 0;
    window->w = Android_ScreenWidth;
    window->h = Android_ScreenHeight;

    window->flags &= ~SDL_WINDOW_RESIZABLE;     /* window is NEVER resizeable */
    window->flags |= SDL_WINDOW_FULLSCREEN;     /* window is always fullscreen */
    window->flags &= ~SDL_WINDOW_HIDDEN;
    window->flags |= SDL_WINDOW_SHOWN;          /* only one window on Android */
    window->flags |= SDL_WINDOW_INPUT_FOCUS;    /* always has input focus */

    /* One window, it always has focus */
    SDL_SetMouseFocus(window);
    SDL_SetKeyboardFocus(window);
    
    data = (SDL_WindowData *) SDL_calloc(1, sizeof(*data));
    if (!data) {
        return SDL_OutOfMemory();
    }
    
    data->native_window = Android_JNI_GetNativeWindow();
    
    if (!data->native_window) {
        SDL_free(data);
        return SDL_SetError("Could not fetch native window");
    }

    /* Do not create EGLSurface for Vulkan window since it will then make the window
       incompatible with vkCreateAndroidSurfaceKHR */
    if ((window->flags & SDL_WINDOW_VULKAN) == 0) {
        data->egl_surface = SDL_EGL_CreateSurface(_this, (NativeWindowType) data->native_window);

        if (data->egl_surface == EGL_NO_SURFACE) {
            ANativeWindow_release(data->native_window);
            SDL_free(data);
            return SDL_SetError("Could not create GLES window surface");
        }
    }

    window->driverdata = data;
    Android_Window = window;
    
    return 0;
}
Exemple #8
0
SDL_barrier *SDL_CreateBarrier(int n) {
  struct _SDL_barrier *b = (struct _SDL_barrier*) malloc(
      sizeof(struct _SDL_barrier));
  b->count = 0;
  b->n = n;
  b->mutex = SDL_CreateMutex();
  b->turnstile = SDL_CreateSemaphore(0);
  b->turnstile2 = SDL_CreateSemaphore(0);
  return b;
}
Exemple #9
0
void rdpCreateThread()
{
  if (!rdpCommandSema) {
    rdpCommandSema = SDL_CreateSemaphore(0);
    rdpCommandCompleteSema = SDL_CreateSemaphore(0);
  }
  if (!rdpThread) {
    LOG("Creating rdp thread\n");
    rdpThread = SDL_CreateThread(rdpThreadFunc, 0);
  }
}
void rglGlutCreateThread(int recreate)
{
  if (!thread) {
    commandSem = SDL_CreateSemaphore(0);
    commandCond = SDL_CreateCond();
    commandMutex = SDL_CreateMutex();
    commandFinishedSem = SDL_CreateSemaphore(0);
    
    thread = SDL_CreateThread(rglGlutThread, 0);
  } else if (recreate)
    rglGlutPostCommand(rglGlutRecreateWindow);
}
Exemple #11
0
rt_err_t rt_mq_init(rt_mq_t mq, const char* name, void *msgpool, rt_size_t msg_size, rt_size_t pool_size, rt_uint8_t flag)
{
	size_t index;
	struct rt_mq_message* head;

	/* parameter check */
	RT_ASSERT(mq != RT_NULL);

	/* set parent flag */
	mq->flag = flag;

	for (index = 0; index < RT_NAME_MAX; index ++)
	{
		mq->name[index] = name[index];
	}

	/* append to mq list */
	SDL_mutexP(_mq_list_mutex);
	rt_list_insert_after(&(_mq_list), &(mq->list));
	SDL_mutexV(_mq_list_mutex);

	/* set message pool */
	mq->msg_pool 	= msgpool;

	/* get correct message size */
	mq->msg_size	= RT_ALIGN(msg_size,  RT_ALIGN_SIZE);
	mq->max_msgs	= pool_size / (mq->msg_size + sizeof(struct rt_mq_message));

	/* init message list */
	mq->msg_queue_head = RT_NULL;
	mq->msg_queue_tail = RT_NULL;

	/* init message empty list */
	mq->msg_queue_free = RT_NULL;

	for (index = 0; index < mq->max_msgs; index ++)
	{
		head = (struct rt_mq_message*)((rt_uint8_t*)mq->msg_pool +
			index * (mq->msg_size + sizeof(struct rt_mq_message)));
		head->next = mq->msg_queue_free;
		mq->msg_queue_free = head;
	}

	/* the initial entry is zero */
	mq->entry		= 0;

	/* init mutex */
	mq->host_mq		= (void*) malloc(sizeof(struct host_mq));
	hmq->mutex		= SDL_CreateSemaphore(1);
	hmq->msg		= SDL_CreateSemaphore(0);

	return RT_EOK;
}
Exemple #12
0
static void playback_init(void)
{
    mode = MODE_PLAY;
    if (SDL_Init(SDL_INIT_AUDIO)) {
        fprintf(stderr, "error: Can't initialize SDL: %s\n", SDL_GetError());
        exit(1);
    }
    playback_play_ind = 1;
    playback_play_pos = PLAYBACK_BUFFER_SIZE;
    playback_decode_ind = 0;
    playback_decode_pos = 0;
    playback_play_sema = SDL_CreateSemaphore(0);
    playback_decode_sema = SDL_CreateSemaphore(0);
}
void rdpCreateThread()
{
    if (!rdpCommandSema) {
        rdpCommandSema = SDL_CreateSemaphore(0);
        rdpCommandCompleteSema = SDL_CreateSemaphore(0);
    }
    if (!rdpThread) {
        LOG("Creating rdp thread\n");
#if SDL_VERSION_ATLEAST(2,0,0)
        rdpThread = SDL_CreateThread(rdpThreadFunc, "z64rdp", 0);
#else
        rdpThread = SDL_CreateThread(rdpThreadFunc, 0);
#endif
    }
}
Exemple #14
0
//main thread only
EXPORT int osal_TurnOnCamera(int cam_id,int w,int h,int fps){
	JNIEnv* env=(JNIEnv*)SDL_AndroidGetJNIEnv();
	TCamera* cam=&g_cameras[cam_id];
	jmethodID method_id;
	jvalue args[4];
	int ret;
	if((unsigned int)cam_id>=(unsigned int)MAX_CAMERAS)return 0;
	if(!cam->m_inited){
		cam->m_clazz=(*env)->FindClass(env,"com/spap/wrapper/camera");
		method_id=(*env)->GetMethodID(env,cam->m_clazz,"<init>","()V");
		cam->m_cam_object=(*env)->NewObjectA(env,cam->m_clazz,method_id,NULL);
		cam->m_cam_mutex=SDL_CreateMutex();
		cam->m_camdat_ready_event=SDL_CreateSemaphore(0);
		cam->m_inited=1;
	}
	if(cam->m_is_on)return 1;
	SDL_LockMutex(cam->m_cam_mutex);
	cam->m_is_on=1;
	method_id=(*env)->GetMethodID(env,cam->m_clazz,"turn_on","(IIII)I");
	//args[].l=cam->m_cam_object;
	args[0].i=cam_id;
	args[1].i=w;
	args[2].i=h;
	args[3].i=fps;
	ret=(*env)->CallIntMethodA(env,cam->m_cam_object,method_id,args);
	SDL_UnlockMutex(cam->m_cam_mutex);
	//__android_log_print(ANDROID_LOG_ERROR,"STDOUT","call method %p %p ret=%d",cam->m_clazz,method_id,ret);
	return ret;
}
Exemple #15
0
/*
 * Create an CSDLAudioSync for a session.  Don't alloc any buffers until
 * config is called by codec
 */
CSDLAudioSync::CSDLAudioSync (CPlayerSession *psptr, int volume) :
  CAudioSync(psptr)
{
  //SDL_Init(SDL_INIT_AUDIO | SDL_INIT_NOPARACHUTE);
  Our_SDL_AudioInit(getenv("SDL_AUDIODRIVER"));
  m_fill_index = m_play_index = 0;
  for (int ix = 0; ix < DECODE_BUFFERS_MAX; ix++) {
    m_buffer_filled[ix] = 0;
    m_sample_buffer[ix] = NULL;
  }
  m_buffer_size = 0;
  m_config_set = 0;
  m_audio_initialized = 0;
  m_audio_paused = 1;
  m_resync_required = 0;
  m_dont_fill = 0;
  m_consec_no_buffers = 0;
  //SDL_Init(SDL_INIT_AUDIO);
  m_audio_waiting_buffer = 0;
  m_audio_waiting = SDL_CreateSemaphore(0); //NULL; // will be set by decode thread
  m_skipped_buffers = 0;
  m_didnt_fill_buffers = 0;
  m_play_time = 0         ;
  m_buffer_latency = 0;
  m_volume = (volume * SDL_MIX_MAXVOLUME)/100;
  m_first_time = 1;
  m_first_filled = 1;
  m_buffer_offset_on = 0;
  m_buffer_ts = 0;
  m_load_audio_do_next_resync = 0;
}
Exemple #16
0
void system_init(void)
{
    SDL_sem *s;
    /* fake stack, OS manages size (and growth) */
    stackbegin = stackend = (uintptr_t*)&s;

#if (CONFIG_PLATFORM & PLATFORM_MAEMO)
    /* Make glib thread safe */
    g_thread_init(NULL);
    g_type_init();
#endif

    if (SDL_Init(SDL_INIT_TIMER))
        panicf("%s", SDL_GetError());

    s = SDL_CreateSemaphore(0); /* 0-count so it blocks */

    evt_thread = SDL_CreateThread(sdl_event_thread, s);

    /* wait for sdl_event_thread to run so that it can initialize the surfaces
     * and video subsystem needed for SDL events */
    SDL_SemWait(s);
    /* cleanup */
    SDL_DestroySemaphore(s);
}
LISPBUILDERSDLGLUE_API int SDLCALL SDL_glue_SDL_OpenAudio(SDL_AudioSpec *desired, SDL_AudioSpec *obtained) {
	buffer_fill_lock = SDL_CreateMutex();
	buffer_fill = -1;
	audio_buffer_lock = SDL_CreateSemaphore(1);
	desired->callback = SDL_glue_mixaudio;
	return SDL_OpenAudio(desired, obtained);
}
Exemple #18
0
void FlcPlayer::initAudio(Uint16 format, Uint8 channels)
{
	int err;

	err = Mix_OpenAudio(_audioData.sampleRate, format, channels, _audioFrameSize *2);
	_videoDelay = 1000 / (_audioData.sampleRate / _audioFrameSize );

	if (err)
	{
		printf("Failed to open audio (%d)\n", err);
		return;
	}

	/* Start runnable */
	_audioData.sharedLock = SDL_CreateSemaphore(1);

	_audioData.loadingBuffer = new AudioBuffer();
	_audioData.loadingBuffer->currSamplePos = 0;
	_audioData.loadingBuffer->sampleCount = 0;
	_audioData.loadingBuffer->samples = (Sint16 *)malloc(_audioFrameSize * 2);
	_audioData.loadingBuffer->sampleBufSize = _audioFrameSize * 2;

	_audioData.playingBuffer = new AudioBuffer();
	_audioData.playingBuffer->currSamplePos = 0;
	_audioData.playingBuffer->sampleCount = 0;
	_audioData.playingBuffer->samples = (Sint16 *)malloc(_audioFrameSize * 2);
	_audioData.playingBuffer->sampleBufSize = _audioFrameSize * 2;

	Mix_HookMusic(FlcPlayer::audioCallback, &_audioData);
}
Case::Case(const Case &other)
    : playerCharacterId("")
    , loadStage("")
{
    pAnimationManager = new AnimationManager(ManagerSourceCaseFile);
    pAudioManager = new AudioManager();
    pContentManager = new ContentManager();
    pDialogCharacterManager = new DialogCharacterManager();
    pDialogCutsceneManager = new DialogCutsceneManager();
    pEvidenceManager = new EvidenceManager();
    pFieldCharacterManager = new FieldCharacterManager();
    pFieldCutsceneManager = new FieldCutsceneManager();
    pFlagManager = new FlagManager();
    pPartnerManager = new PartnerManager();
    pSpriteManager = new SpriteManager(ManagerSourceCaseFile);

    isFinished = false;
    isLoadingSprites = false;
    isReady = false;
    waitUntilLoaded = true;
    wantsToLoadResources = false;

    pCurrentArea = NULL;

    pLoadStageSemaphore = SDL_CreateSemaphore(1);
}
Exemple #20
0
void CCamera::init( CameraType cameraType, float X, float Y, float Z, float Width, float Height, float Depth ){ 
    semaphore = SDL_CreateSemaphore( 1 );

    SDL_SemWait( semaphore ); 

    this->cameraType = cameraType; 

    camera_position[0] = X; camera_position[1] = Y; camera_position[2] = Z;

    x_eye=0.0;  y_eye=0.0;  z_eye=0.0;
    up_vector[0] = 0.0; up_vector[1] = 0.0; up_vector[2] = 1.0;
    axle_vector[0] = 1.0;  axle_vector[1] = 0.0; axle_vector[2] = 0.0;

    const SDL_VideoInfo* vidInfo = SDL_GetVideoInfo( ); 
    float GW = vidInfo->current_w; 
    float GH = vidInfo->current_h; 
    vp_x1 = 0.0; 	vp_x2 = GW;
    vp_y1 = 0.0; 	vp_y2 = GH;

    width = Width; 
    height = Height; 
    depth = Depth; 

    redraw = true; 

    SDL_SemPost( semaphore ); 

    return;
}
void DreamsEngine::start()
{
    // Global for the legacy refkeen code.
    gDreamsEngine = this;    
    gpRenderLock = SDL_CreateSemaphore(1);

    gKeenFiles.setupFilenames(7);

    setScreenMode(3);

    dreamsengine_datapath = const_cast<char*>(mDataPath.c_str());

    // This function extracts the embedded files. TODO: We should integrate that to our existing system
    // Load the Resources
    loadResources();

    //RefKeen_Patch_id_ca();
    //RefKeen_Patch_id_us();
    RefKeen_Patch_id_rf();
    setupObjOffset();

    // TODO: This seems to be the exe with main cycle. We need to break it into draw and logic routines.
    //InitGame();
    //DemoLoop();
    //kdreams_exe_main();

    mpScene.reset( new DreamsDosIntro );

    gGameState = INTRO_TEXT;

    mpScene->start();
}
Exemple #22
0
/* Function to scan the system for joysticks.
 * This function should set SDL_numjoysticks to the number of available
 * joysticks.  Joystick 0 should be the system default joystick.
 * It should return number of joysticks, or -1 on an unrecoverable fatal error.
 */
int SDL_SYS_JoystickInit(void)
{
    int i;

/*  SDL_numjoysticks = 1; */

    /* Setup input */
    sceCtrlSetSamplingCycle(0);
    sceCtrlSetSamplingMode(PSP_CTRL_MODE_ANALOG);

    /* Start thread to read data */
    if((pad_sem =  SDL_CreateSemaphore(1)) == NULL) {
        return SDL_SetError("Can't create input semaphore");
    }
    running = 1;
    if((thread = SDL_CreateThread(JoystickUpdate, "JoySitckThread",NULL)) == NULL) {
        return SDL_SetError("Can't create input thread");
    }

    /* Create an accurate map from analog inputs (0 to 255)
       to SDL joystick positions (-32768 to 32767) */
    for (i = 0; i < 128; i++)
    {
        float t = (float)i/127.0f;
        analog_map[i+128] = calc_bezier_y(t);
        analog_map[127-i] = -1 * analog_map[i+128];
    }

    return 1;
}
Exemple #23
0
void CCamera::init( CameraType cameraType, float X, float Y, float Z, float AspecRatio, float Angle_of_vision ){
    semaphore = SDL_CreateSemaphore( 1 );

    SDL_SemWait( semaphore ); 

    this->cameraType = cameraType; 

    camera_position[0] = X; camera_position[1] = Y; camera_position[2] = Z;
    radius = sqrt( camera_position[0] * camera_position[0] + camera_position[1] * camera_position[1] + camera_position[2] * camera_position[2] );

    x_eye=0.0;  y_eye=0.0;  z_eye=0.0;
    up_vector[0] = 0.0; up_vector[1] = 0.0; up_vector[2] = 1.0;
    axle_vector[0] = 1.0;  axle_vector[1] = 0.0; axle_vector[2] = 0.0;

    const SDL_VideoInfo* vidInfo = SDL_GetVideoInfo( ); 
    float GW = vidInfo->current_w; 
    float GH = vidInfo->current_h; 
    vp_x1 = 0.0; 	vp_x2 = GW;
    vp_y1 = 0.0; 	vp_y2 = GH;

    angle_of_vision = Angle_of_vision;
    this->aspecRatio=AspecRatio;

    redraw = true;

    SDL_SemPost( semaphore ); 

    return;
}
Exemple #24
0
int
SDL_TimerInit(void)
{
    SDL_TimerData *data = &SDL_timer_data;

    if (!SDL_AtomicGet(&data->active)) {
        const char *name = "SDLTimer";
        data->timermap_lock = SDL_CreateMutex();
        if (!data->timermap_lock) {
            return -1;
        }

        data->sem = SDL_CreateSemaphore(0);
        if (!data->sem) {
            SDL_DestroyMutex(data->timermap_lock);
            return -1;
        }

        SDL_AtomicSet(&data->active, 1);

        /* Timer threads use a callback into the app, so we can't set a limited stack size here. */
        data->thread = SDL_CreateThreadInternal(SDL_TimerThread, name, 0, data);
        if (!data->thread) {
            SDL_TimerQuit();
            return -1;
        }

        SDL_AtomicSet(&data->nextID, 1);
    }
    return 0;
}
Exemple #25
0
void init_mesh_build_threads(void)
{
   int i;

   int num_proc = SDL_GetCPUCount();

   init_WakeableWaiter(&manager_monitor);
   init_threadsafe_queue(&built_meshes, MAX_BUILT_MESHES, sizeof(built_queue[0]), built_queue);
   init_threadsafe_queue(&pending_meshes, MAX_TASKS, sizeof(mesh_task_queue[0]), mesh_task_queue);
   init_threadsafe_queue(&pending_gen   , MAX_TASKS, sizeof(gen_task_queue[0]), gen_task_queue);
   init_threadsafe_queue(&finished_gen, MAX_GEN_CHUNKS, sizeof(gen_queue[0]), gen_queue);
   pending_task_count = SDL_CreateSemaphore(0);

   if (num_proc > 6)
      num_mesh_workers = num_proc/2;
   else if (num_proc > 4)
      num_mesh_workers = 4;
   else 
      num_mesh_workers = num_proc-1;

   if (num_mesh_workers > MAX_MESH_WORKERS)
      num_mesh_workers = MAX_MESH_WORKERS;

   if (num_mesh_workers < 1)
      num_mesh_workers = 1;

   for (i=0; i < num_mesh_workers; ++i)
      SDL_CreateThread(mesh_worker_handler, "mesh worker", NULL);

   SDL_CreateThread(worker_manager, "thread manager thread", NULL);
}
Exemple #26
0
def_dll int sdl_semaphore::init(int d)
{
	destroy();
	_semaphore = SDL_CreateSemaphore(d);
	if(_semaphore)return 0;
	return -1;
}
Exemple #27
0
static void
TestWaitTimeout(void)
{
    Uint32 start_ticks;
    Uint32 end_ticks;
    Uint32 duration;
    int retval;

    sem = SDL_CreateSemaphore(0);
    SDL_Log("Waiting 2 seconds on semaphore\n");

    start_ticks = SDL_GetTicks();
    retval = SDL_SemWaitTimeout(sem, 2000);
    end_ticks = SDL_GetTicks();

    duration = end_ticks - start_ticks;

    /* Accept a little offset in the effective wait */
    if (duration > 1900 && duration < 2050)
        SDL_Log("Wait done.\n");
    else
        SDL_Log("Wait took %d milliseconds\n", duration);

    /* Check to make sure the return value indicates timed out */
    if (retval != SDL_MUTEX_TIMEDOUT)
        SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "SDL_SemWaitTimeout returned: %d; expected: %d\n", retval, SDL_MUTEX_TIMEDOUT);
}
int
SDL_TimerInit(void)
{
    SDL_TimerData *data = &SDL_timer_data;

    if (!data->active) {
        data->timermap_lock = SDL_CreateMutex();
        if (!data->timermap_lock) {
            return -1;
        }

        data->sem = SDL_CreateSemaphore(0);
        if (!data->sem) {
            SDL_DestroyMutex(data->timermap_lock);
            return -1;
        }

        data->active = SDL_TRUE;
        /* !!! FIXME: this is nasty. */
#if (defined(__WIN32__) && !defined(_WIN32_WCE)) && !defined(HAVE_LIBC)
#undef SDL_CreateThread
        data->thread = SDL_CreateThread(SDL_TimerThread, data, NULL, NULL);
#else
        data->thread = SDL_CreateThread(SDL_TimerThread, data);
#endif
        if (!data->thread) {
            SDL_TimerQuit();
            return -1;
        }

        SDL_AtomicSet(&data->nextID, 1);
    }
    return 0;
}
Exemple #29
0
int main(int argc, char *argv[]) {
    Main::Init();

    update_semaphore = SDL_CreateSemaphore(0);
    SDL_Thread *update_thread = SDL_CreateThread(Main::UpdateThread, "Update", NULL);

    unsigned int next_game_tick = SDL_GetTicks();
    unsigned int loops = 0;

    while (Main::running) {
        loops = 0;
        while (SDL_GetTicks() > next_game_tick && loops < MAX_FRAMESKIP) {
            Main::Event();
            Main::window->view.camera.tick();
            Main::window2->view.camera.tick();
            next_game_tick += SKIP_TICKS;
            SDL_SemPost(update_semaphore);
            loops++;
        }
        float interpolation = (SDL_GetTicks() + SKIP_TICKS - next_game_tick) / (float) SKIP_TICKS;
        Main::Render(interpolation);
    }

    SDL_SemPost(update_semaphore);
    SDL_WaitThread(update_thread, NULL);

    Main::Cleanup();

    return 0;
}
Exemple #30
0
void Threads_Glue_SemInit(void **Ptr, int Val)
{
	*Ptr = SDL_CreateSemaphore(Val);
	if( !*Ptr ) {
		Log_Warning("Threads", "Semaphore creation failed - %s", SDL_GetError());
	}
}