示例#1
0
void Enemy::AI(float x, float y)
{
	//SDL_LockMutex(mutex);
	//Sem Lock
	SDL_SemWait(moveLock);
	//std::cout << "AI Lock" << std::endl;

	m_dirX = 0;
	m_dirY = 0;

	if (m_x < x)
	{
		m_dirX = 1;
	}
	else if (m_x > x)
	{
		m_dirX = -1;
	}

	if (m_y < y)
	{
		m_dirY = 1;
	}
	else if (m_y > y)
	{
		m_dirY = -1;
	}

	isColliding(x,y);

	//SDL_UnlockMutex(mutex);
	SDL_SemPost(moveLock);
	//std::cout << "AI Unlock" << std::endl;
}
示例#2
0
/* Lock the semaphore */
int
SDL_mutexP(SDL_mutex * mutex)
{
#if SDL_THREADS_DISABLED
    return 0;
#else
    Uint32 this_thread;

    if (mutex == NULL) {
        SDL_SetError("Passed a NULL mutex");
        return -1;
    }

    this_thread = SDL_ThreadID();
    if (mutex->owner == this_thread) {
        ++mutex->recursive;
    } else {
        /* The order of operations is important.
           We set the locking thread id after we obtain the lock
           so unlocks from other threads will fail.
         */
        SDL_SemWait(mutex->sem);
        mutex->owner = this_thread;
        mutex->recursive = 0;
    }

    return 0;
#endif /* SDL_THREADS_DISABLED */
}
int CLoopFeederSink::ThreadMain(void)
{
	while (SDL_SemWait(m_myMsgQueueSemaphore) == 0) {
		CMsg* pMsg = m_myMsgQueue.get_message();

		if (pMsg != NULL) {
			switch (pMsg->get_value()) {
			case MSG_NODE_STOP_THREAD:
				DoStopSink();
				delete pMsg;
				return 0;
			case MSG_NODE_START:
				DoStartSink();
				break;
			case MSG_NODE_STOP:
				DoStopSink();
				break;
			case MSG_SINK_FRAME:
				uint32_t dontcare;
				DoWriteFrame((CMediaFrame*)pMsg->get_message(dontcare));
				break;
			}

			delete pMsg;
		}
	}

	return -1;
}
示例#4
0
/*
 * @brief
 */
void FreeWinding(winding_t *w) {

	if (debug)
		SDL_SemWait(semaphores.active_windings);

	Mem_Free(w);
}
示例#5
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;
}
示例#6
0
int SDL_SemWaitTimeout(SDL_sem *sem, Uint32 timeout)
{
    int retval;

    if ( ! sem ) {
        SDL_SetError("Passed a NULL semaphore");
        return -1;
    }

    /* Try the easy cases first */
    if ( timeout == 0 ) {
        return SDL_SemTryWait(sem);
    }
    if ( timeout == SDL_MUTEX_MAXWAIT ) {
        return SDL_SemWait(sem);
    }

    /* Ack!  We have to busy wait... */
    timeout += SDL_GetTicks();
    do {
        retval = SDL_SemTryWait(sem);
        if ( retval == 0 ) {
            break;
        }
        SDL_Delay(1);
    } while ( SDL_GetTicks() < timeout );

    return retval;
}
示例#7
0
void CCamera::sidewind( int direction, float amount ) {
    SDL_SemWait( semaphore ); 

    switch( direction ) {
    	case UP :
		camera_position[2] += amount;
		z_eye += amount;
		break;

    	case DOWN :
		camera_position[2] -= amount;
		z_eye -= amount;
		break;

    	case LEFT :
		camera_position[0] -= amount;
		x_eye -= amount;
		break;

    	case RIGHT :
		camera_position[0] += amount;
		x_eye += amount;
		break;

    }
	
    redraw = true;
    SDL_SemPost( semaphore ); 

    return;
}
示例#8
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;
}
示例#9
0
void Sync_Audio::write( const sample_t* in, int remain )
{
	while ( remain )
	{
		int count = buf_size - write_pos;
		if ( count > remain )
			count = remain;
		
		sample_t* out = buf( write_buf ) + write_pos;
		if ( gain != (1L << gain_bits) )
		{
			register long gain = this->gain;
			for ( int n = count; n--; )
				*out++ = (*in++ * gain) >> gain_bits;
		}
		else
		{
			memcpy( out, in, count * sizeof (sample_t) );
			in += count;
		}
		
		write_pos += count;
		remain -= count;
		
		if ( write_pos >= buf_size )
		{
			write_pos = 0;
			write_buf = (write_buf + 1) % buf_count;
			SDL_SemWait( free_sem );
		}
	}
示例#10
0
/* Restart all threads that are waiting on the condition variable */
int SDL_CondBroadcast(SDL_cond *cond)
{
	if ( ! cond ) {
		SDL_SetError("Passed a NULL condition variable");
		return -1;
	}

	/* If there are waiting threads not already signalled, then
	   signal the condition and wait for the thread to respond.
	*/
	SDL_LockMutex(cond->lock);
	if ( cond->waiting > cond->signals ) {
		int i, num_waiting;

		num_waiting = (cond->waiting - cond->signals);
		cond->signals = cond->waiting;
		for ( i=0; i<num_waiting; ++i ) {
			SDL_SemPost(cond->wait_sem);
		}
		/* Now all released threads are blocked here, waiting for us.
		   Collect them all (and win fabulous prizes!) :-)
		 */
		SDL_UnlockMutex(cond->lock);
		for ( i=0; i<num_waiting; ++i ) {
			SDL_SemWait(cond->wait_done);
		}
	} else {
		SDL_UnlockMutex(cond->lock);
	}

	return 0;
}
示例#11
0
static void
XAUDIO2_WaitDevice(_THIS)
{
    if (this->enabled) {
        SDL_SemWait(this->hidden->semaphore);
    }
}
示例#12
0
文件: SoundSDL.cpp 项目: akerl/demos
void SoundSDL::read(u16 * stream, int length)
{
	if (!_initialized || length <= 0 || !emulating)
		return;

#if !JS
	/* since this is running in a different thread, speedup and
	 * throttle can change at any time; save the value so locks
	 * stay in sync */
	bool lock = (emulating && !speedup) ? true : false;

	if (lock)
		SDL_SemWait (_semBufferFull);

	SDL_mutexP(_mutex);
#endif

	_rbuf.read(stream, std::min(static_cast<std::size_t>(length) / 2, _rbuf.used()));

#if !JS
	SDL_mutexV(_mutex);

	SDL_SemPost (_semBufferEmpty);
#endif
}
示例#13
0
int resolverloop(void * data)
{
    resolverthread *rt = (resolverthread *)data;
    for(;;)
    {
        SDL_SemWait(resolversem);
        SDL_LockMutex(resolvermutex);
        if(resolverqueries.empty())
        {
            SDL_UnlockMutex(resolvermutex);
            continue;
        }
        rt->query = resolverqueries.pop();
        rt->starttime = lastmillis;
        SDL_UnlockMutex(resolvermutex);
        ENetAddress address = { ENET_HOST_ANY, CUBE_SERVINFO_PORT };
        enet_address_set_host(&address, rt->query);
        SDL_LockMutex(resolvermutex);
        resolverresult &rr = resolverresults.add();
        rr.query = rt->query;
        rr.address = address;
        rt->query = NULL;
        rt->starttime = 0;
        SDL_UnlockMutex(resolvermutex);
    };
    return 0;
};
示例#14
0
文件: main.c 项目: LasDesu/openbgi-hl
void display_put_wait( const char *orig_str )
{
    display_put( orig_str );

    SDLMod key_mod = SDL_GetModState();
    if ( !(key_mod & KMOD_CTRL) )
        SDL_SemWait( key_sem );
}
示例#15
0
void BXBGJob::Lock() 
{
	if (!m_bActive) 
  {
		//LOG(LOG_LEVEL_DEBUG,"PAUSE: Background job locked id = %d", GetId());
		SDL_SemWait(m_pJobLock);
	}
}
示例#16
0
/**
 * @brief
 */
void FreeNode(node_t *node) {

	if (debug) {
		SDL_SemWait(semaphores.active_nodes);
	}

	Mem_Free(node);
}
示例#17
0
void RegionViewer::incNumPainted()
{
	SDL_SemWait(m_lock);
	
	m_numPainted += 1;
	
	SDL_SemPost(m_lock);
}
示例#18
0
    int UpdateThread(void *unused) {
        while (Main::running) {
            if (SDL_SemWait(update_semaphore) == 0) {
                Main::Tick();
            }
        }

        return 0;
    }
LISPBUILDERSDLGLUE_API int SDLCALL SDL_glue_SDL_WaitUntilBufferFull(void) {
    /*	Let lispbulder-sdl know to fill the audio buffer */
	SDL_mutexP(buffer_fill_lock);
	buffer_fill = 1;
	SDL_mutexV(buffer_fill_lock);

	/*	And wait until lispbuilder-sdl has done so */
	return SDL_SemWait(audio_buffer_lock);
}
示例#20
0
void PSP_PumpEvents(_THIS)
{
    int i;
    enum PspHprmKeys keys;
    enum PspHprmKeys changed;
    static enum PspHprmKeys old_keys = 0;
    SDL_Keysym sym;

    SDL_SemWait(event_sem);
    keys = hprm;
    SDL_SemPost(event_sem);

    /* HPRM Keyboard */
    changed = old_keys ^ keys;
    old_keys = keys;
    if(changed) {
        for(i=0; i<sizeof(keymap_psp)/sizeof(keymap_psp[0]); i++) {
            if(changed & keymap_psp[i].id) {
                sym.scancode = keymap_psp[i].id;
                sym.sym = keymap_psp[i].sym;

                /* out of date
                SDL_PrivateKeyboard((keys & keymap_psp[i].id) ?
                            SDL_PRESSED : SDL_RELEASED,
                            &sym);
        */
                SDL_SendKeyboardKey((keys & keymap_psp[i].id) ?
                                    SDL_PRESSED : SDL_RELEASED, SDL_GetScancodeFromKey(keymap_psp[i].sym));
            }
        }
    }

#ifdef PSPIRKEYB
    if (irkbd_ready) {
            unsigned char buffer[255];
        int i, length, count;
        SIrKeybScanCodeData *scanData;

            if(pspIrKeybReadinput(buffer, &length) >= 0) {
                if((length % sizeof(SIrKeybScanCodeData)) == 0){
                    count = length / sizeof(SIrKeybScanCodeData);
                    for( i=0; i < count; i++ ) {
                unsigned char raw, pressed;
                        scanData=(SIrKeybScanCodeData*) buffer+i;
                        raw = scanData->raw;
                        pressed = scanData->pressed;
                sym.scancode = raw;
                sym.sym = keymap[raw];
                /* not tested */
                /* SDL_PrivateKeyboard(pressed?SDL_PRESSED:SDL_RELEASED, &sym); */
                SDL_SendKeyboardKey((keys & keymap_psp[i].id) ?
                                    SDL_PRESSED : SDL_RELEASED, SDL_GetScancodeFromKey(keymap[raw]);

                }
            }
        }
    }
示例#21
0
double CDebuggingServer::AquireBreakPointAccess(std::list<CBreakPoint>** breakPoints)
{
	int ret;
	ret = SDL_SemWait(m_BreakPointsSem);
	ENSURE(ret == 0);
	(*breakPoints) = &m_BreakPoints;
	m_BreakPointsLockID = timer_Time();
	return m_BreakPointsLockID;
}
示例#22
0
int fs_semaphore_wait(fs_semaphore *semaphore) {
#if defined(USE_PSEM)
    return sem_wait(&semaphore->semaphore);
#elif defined(USE_SDL)
    return SDL_SemWait(semaphore->semaphore);
#else
#error no thread support
#endif
}
示例#23
0
SndDrvTmpl::~SndDrvTmpl() {
	// TODO Auto-generated destructor stub
	enable = FALSE;
	if(RenderSem != NULL) {
		SDL_SemWait(RenderSem);
		SDL_DestroySemaphore(RenderSem);
		RenderSem = NULL;
	}
}
示例#24
0
void rglGlutPostCommand(rglGlutCommand_f c)
{
  command = c;
  SDL_SemPost(commandSem);
//   SDL_LockMutex(commandMutex);
//   SDL_CondSignal(commandCond);
//   SDL_UnlockMutex(commandMutex);
  SDL_SemWait(commandFinishedSem);
}
示例#25
0
void CCamera::setAspecRatio( float AspecRatio ){ 
	SDL_SemWait( semaphore ); 

	aspecRatio = AspecRatio; 

	SDL_SemPost( semaphore ); 
	
	return; 
}
示例#26
0
void CCamera::setRedrawTrue( ){
	SDL_SemWait( semaphore ); 

	redraw=true;

	SDL_SemPost( semaphore ); 

	return; 
}
示例#27
0
void NONS_Event::wait(){
#if NONS_SYS_WINDOWS
	WaitForSingleObject(this->event,INFINITE);
#elif NONS_SYS_UNIX
	while (sem_wait(&this->sem)<0 && errno==EINTR);
#elif NONS_SYS_PSP
	SDL_SemWait(this->sem);
#endif
}
示例#28
0
void CNetwork_Queue::insert( CPacketData pdata ) {
	SDL_SemWait( semaphore ); 

	queue_to_send.push_back( pdata );

	SDL_SemPost( semaphore ); 

	return;
}
bool NetworkConnectionMenu::HostingServer(const std::string& port,
                                          const std::string& game_name,
                                          const std::string& password,
                                          bool internet)
{
  bool r = false;
  int net_port;
  connection_state_t conn;

  if (!internet)
    IndexServer::GetInstance()->SetHiddenServer();

  if (internet) {
    SDL_SemWait(net_info.lock);

    conn = IndexServer::GetInstance()->Connect(Constants::WARMUX_VERSION);
    if (conn != CONNECTED) {
      DisplayNetError(conn);
      msg_box->NewMessage(_("Error: Unable to contact the index server to host a game"), c_red);
      goto out;
    }
  }

  conn = Network::ServerStart(port, game_name, password);
  if (conn != CONNECTED) {
    DisplayNetError(conn);
    goto out;
  }

  r = str2int(port, net_port);
  if (false == r) {
    DisplayNetError(CONN_BAD_PORT);
    goto out;
  }

  if (internet) {
    r = IndexServer::GetInstance()->SendServerStatus(game_name, password != "", net_port);
    if (false == r) {
      DisplayNetError(CONN_BAD_PORT);
      msg_box->NewMessage(Format(_("Error: Your server is not reachable from the internet. Check your firewall configuration: TCP Port %s must accept connections from the outside. If you are not directly connected to the internet, check your router configuration: TCP Port %s must be forwarded on your computer."), port.c_str(), port.c_str()),
                          c_red);
      goto out;
    }
  }

  if (!Network::GetInstance()->IsConnected()) {
    msg_box->NewMessage(_("Error: Unable to start the server"), c_red);
    goto out;
  }
  r = true;

 out:
  if (internet)
    SDL_SemPost(net_info.lock);
  return r;
}
示例#30
0
int CALSAAudioSource::ThreadMain(void) 
{
  debug_message("alsa start");
  while (true) {
    int rc;

    if (m_source) {
      rc = SDL_SemTryWait(m_myMsgQueueSemaphore);
    } else {
      rc = SDL_SemWait(m_myMsgQueueSemaphore);
    }

    // semaphore error
    if (rc == -1) {
      break;
    } 

    // message pending
    if (rc == 0) {
      CMsg* pMsg = m_myMsgQueue.get_message();
		
      if (pMsg != NULL) {
        switch (pMsg->get_value()) {
        case MSG_NODE_STOP_THREAD:
          DoStopCapture();	// ensure things get cleaned up
          delete pMsg;
          debug_message("alsa stop thread");
          return 0;
        case MSG_NODE_START:
          DoStartCapture();
          break;
        case MSG_NODE_STOP:
          DoStopCapture();
          break;
        }

        delete pMsg;
      }
    }

    if (m_source) {
      try {
        //debug_message("processaudio");
        ProcessAudio();
      }
      catch (...) {
        error_message("alsa stop capture");
        DoStopCapture();	
        break;
      }
    }
  }

  debug_message("alsa thread exit");
  return -1;
}