Example #1
0
 __m128 Inc4(int i, int j) const
 {
     __m128 res = _mm_setr_ps(Inc(i + 0, j),
                              Inc(i + 1, j),
                              Inc(i + 2, j),
                              Inc(i + 3, j));
     return res;
 }
Example #2
0
void TMakeMissile::Move()
{
	if( Age % ShotInt == 0 ) {
		FOwner->Add(new TMissile(FOwner,FOwner->HeroPos.X,FOwner->HeroPos.Y,SetNum,MissileNum));
		Inc(MissileNum);
		FOwner->Add(new TMissile(FOwner,FOwner->HeroPos.X,FOwner->HeroPos.Y,SetNum,MissileNum));
		Inc(MissileNum);
	}

	if( Age >= (ShotInt*((MaxLock / 2) - 1)) ) {
		Die();
	}
	TOBJ::Move();
}
Example #3
0
// Start the link
void StartLink(LINK *k)
{
	PACKET_ADAPTER *pa;
	// Validate arguments
	if (k == NULL)
	{
		return;
	}

	LockLink(k);
	{
		if (k->Started || k->Halting)
		{
			UnlockLink(k);
			return;
		}
		k->Started = true;

		Inc(k->Cedar->CurrentActiveLinks);
	}
	UnlockLink(k);

	// Connect the client session
	pa = LinkGetPacketAdapter();
	pa->Param = (void *)k;
	LockLink(k);
	{
		k->ClientSession = NewClientSession(k->Cedar, k->Option, k->Auth, pa);
	}
	UnlockLink(k);
}
Example #4
0
// Add connection to Cedar
void AddConnection(CEDAR *cedar, CONNECTION *c)
{
	char tmp[MAX_SIZE];
	UINT i;
	// Validate arguments
	if (cedar == NULL || c == NULL)
	{
		return;
	}

	// Determine the name of the connection
	i = Inc(cedar->ConnectionIncrement);
	Format(tmp, sizeof(tmp), "CID-%u", i);


	Lock(c->lock);
	{
		Free(c->Name);
		c->Name = CopyStr(tmp);
	}
	Unlock(c->lock);

	LockList(cedar->ConnectionList);
	{
		Add(cedar->ConnectionList, c);
		AddRef(c->ref);
		Debug("Connection %s Inserted to Cedar.\n", c->Name);
	}
	UnlockList(cedar->ConnectionList);
}
Example #5
0
// Jump here if there is accepted connection in the TCP
void TCPAccepted(LISTENER *r, SOCK *s)
{
	TCP_ACCEPTED_PARAM *data;
	THREAD *t;
	char tmp[MAX_SIZE];
	UINT num_clients_from_this_ip = 0;
	CEDAR *cedar;
	// Validate arguments
	if (r == NULL || s == NULL)
	{
		return;
	}

	cedar = r->Cedar;

	num_clients_from_this_ip = GetNumIpClient(&s->RemoteIP);


	IPToStr(tmp, sizeof(tmp), &s->RemoteIP);

	data = ZeroMalloc(sizeof(TCP_ACCEPTED_PARAM));
	data->r = r;
	data->s = s;

	if (r->ThreadProc == TCPAcceptedThread)
	{
		Inc(cedar->AcceptingSockets);
	}

	t = NewThread(r->ThreadProc, data);
	WaitThreadInit(t);
	Free(data);
	ReleaseThread(t);
}
Example #6
0
TMisBFire::TMisBFire( TOBJList* owner, s32 sx, s32 sy, s32 _R )	: TOBJ(owner)
{
	FObjectName = "TMisBFire";
	X = sx;
	Y = sy;
	Rdeg = (_R+2048) && 0x0fff;
	FKind = kEffect;

	TSpriteEXBLT sblt;
	sblt.RBM      =  bmSubAdd; // αブレンドモード
	sblt.RColor   =  0xFFFFFFFF; // ポリゴン色
	sblt.RDDDD    =  QD;     // TDDDDの参照
	sblt.RHeight  =  20;        // 幅
	sblt.RWidth   =  20;        // 高さ
	sblt.RZ       =  19900;       // Z値

	Sprite[0] =  new TJoint(sblt);         // スプライトの生成
	Inc(numSpr,1);
	Sprite[0]->GetSpr()->AddTexture(Eff1Tex, 0, 0, 15, 15);    // テクスチャを登録
	Sprite[0]->GetSpr()->FVisible  =  true;
	Sprite[0]->GetSpr()->FCX += 10;
	Sprite[0]->GetSpr()->FCY += 10;
	Sprite[0]->GetSpr()->Move(X,Y);
	Sprite[0]->GetSpr()->SetColor(255, ctRed);
	Sprite[0]->GetSpr()->SetColor(128, ctGreen);
	Sprite[0]->GetSpr()->SetColor(64,ctAlpha);
	Sprite[0]->GetSpr()->Zoom(10,0.8);
	Sprite[0]->Move(X,Y);

}
Example #7
0
EXPORT_C TInt CFsObject::Open()
	{
	TInt count=Inc();
	(void)count;
	__THRD_PRINT2(_L("CFsObject::Open() object=0x%x count=%d"),this,count);
	__ASSERT_DEBUG(count>=1,Fault(EFsObjectOpen));
	return KErrNone;
	}
Example #8
0
static int
fnmatch(
    const char *p, /* pattern */
    const char *s, /* string */
    int flags)
{
    const int period = !(flags & FNM_DOTMATCH);
    const int pathname = flags & FNM_PATHNAME;

    const char *ptmp = 0;
    const char *stmp = 0;

    if (pathname) {
	while (1) {
	    if (p[0] == '*' && p[1] == '*' && p[2] == '/') {
		do { p += 3; } while (p[0] == '*' && p[1] == '*' && p[2] == '/');
		ptmp = p;
		stmp = s;
	    }
	    if (fnmatch_helper(&p, &s, flags) == 0) {
		while (*s && *s != '/') Inc(s);
		if (*p && *s) {
		    p++;
		    s++;
		    continue;
		}
		if (!*p && !*s)
		    return 0;
	    }
	    /* failed : try next recursion */
	    if (ptmp && stmp && !(period && *stmp == '.')) {
		while (*stmp && *stmp != '/') Inc(stmp);
		if (*stmp) {
		    p = ptmp;
		    stmp++;
		    s = stmp;
		    continue;
		}
	    }
	    return FNM_NOMATCH;
	}
    }
    else
	return fnmatch_helper(&p, &s, flags);
}
Example #9
0
CIMOMHandle & CIMOMHandle::operator =(const CIMOMHandle & handle)
{
    if (this != &handle)
    {
        Dec(_rep);
        Inc(_rep = handle._rep);
    }
    return *this;
}
Example #10
0
CIMInstance& CIMInstance::operator=(const CIMInstance& x)
{
    if (x._rep != _rep)
    {
        Dec(_rep);
        Inc(_rep = x._rep);
    }
    return *this;
}
Example #11
0
bool ClingoPropagator::isModel(Solver& s) {
	POTASSCO_REQUIRE(prop_ == trail_.size(), "Assignment not propagated");
	if (call_->checkMode() == ClingoPropagatorCheck_t::Total) {
		Control ctrl(*this, s);
		ScopedLock(call_->lock(), call_->propagator(), Inc(epoch_))->check(ctrl);
		return addClause(s, 0u) && s.numFreeVars() == 0 && s.queueSize() == 0;
	}
	return true;
}
Example #12
0
void SortedVectorStore<V>::Inc(int32_t key, V delta) {
  size_t new_size = 0;
  bool suc = Inc(key, delta, &new_size);
  if (!suc) {
    LOG(FATAL) << "Inc failed"
               << " capacity = " << capacity_
               << " new size = " << new_size;
  }
}
Example #13
0
CIMQualifierDecl& CIMQualifierDecl::operator=(const CIMQualifierDecl& x)
{
    if (x._rep != _rep)
    {
        Dec(_rep);
        Inc(_rep = x._rep);
    }

    return *this;
}
Example #14
0
bool ClingoPropagator::propagateFixpoint(Clasp::Solver& s, Clasp::PostPropagator*) {
	POTASSCO_REQUIRE(prop_ <= trail_.size(), "Invalid propagate");
	for (Control ctrl(*this, s, state_prop); prop_ != trail_.size() || front_ < (int32)s.numAssignedVars();) {
		if (prop_ != trail_.size()) {
			// create copy because trail might change during call to user propagation
			temp_.assign(trail_.begin() + prop_, trail_.end());
			prop_ = static_cast<uint32>(trail_.size());
			ScopedLock(call_->lock(), call_->propagator(), Inc(epoch_))->propagate(ctrl, Potassco::toSpan(temp_));
		}
		else {
			registerUndo(s);
			front_ = (int32)s.numAssignedVars();
			ScopedLock(call_->lock(), call_->propagator(), Inc(epoch_))->check(ctrl);
		}
		if (!addClause(s, state_prop) || (s.queueSize() && !s.propagateUntil(this))) {
			return false;
		}
	}
	return true;
}
Example #15
0
TSmoke2::TSmoke2( TOBJList* owner, s32 sx, s32 sy, s32 _R, TOBJ* _PrevObj, s32 _misID ) : TOBJ(owner)
{
	FObjectName = "TSmoke2";
	X = sx;
	Y = sy;
	FKind = kEffect2;
	Speed = 15;
	PrevObj = _PrevObj;
	MissileID = _misID;
	Rdeg = (_R+2048) & 0x0fff;
	ZoomRate = 0.2f;

	TSpriteEXBLT sblt;
	sblt.RBM      =  bmSubAdd; // αブレンドモード
	sblt.RColor   =  0xFFFFFFFF; // ポリゴン色
	sblt.RDDDD    =  QD;     // TDDDDの参照
	sblt.RHeight  =  32;        // 幅
	sblt.RWidth   =  32;        // 高さ
	sblt.RX       =  0;        // X座標
	sblt.RY       =  0;        // Y座標
	sblt.RZ       =  3000;       // Z値

	Sprite[0] =  new TJoint(sblt);         // スプライトの生成
	Inc(numSpr,1);
	Sprite[0]->GetSpr()->AddTexture(Eff2Tex, 1, 193, 63, 255);    // テクスチャを登録
	Sprite[0]->GetSpr()->FCX += 16;
	Sprite[0]->GetSpr()->FCY += 16;
	Sprite[0]->GetSpr()->Move(X,Y);
	Sprite[0]->GetSpr()->Rotate(0);
	Sprite[0]->GetSpr()->SetColor(255,ctBlue);
	Sprite[0]->GetSpr()->SetColor(255,ctRed);
	Sprite[0]->GetSpr()->SetColor(255,ctGreen);
	Sprite[0]->GetSpr()->SetColor(235, ctAlpha);
	Sprite[0]->GetSpr()->FVisible = false;

	//IDの付与
	FID = NewID;
	Inc(NewID);


}
Example #16
0
//*****************************************************************************
// Lex::RemTermination - Terminates remarks.
// Returns : -1 if <NextLexem> must returns something, 0 otherwise.
//*****************************************************************************
int TXML_Lex::RemTermination( Lexem& /*ret*/ )
//       ~~~~~~~~~~~~~~
{
	static QString startRem = _T("<!--");
	static QString endRem   = _T("-->");
	while( isLA( startRem ) )
	{
		Inc( startRem.length() );
		while( !::_iseof( SoleChar() ) && !isLA( endRem ) )
			NextChar();
		if( ::_iseof( SoleChar() ) )
		{
			lex_err = Lex::UnterminatedComment;
			return -1;
		}
		else
			Inc( endRem.length() );
                while( IsSpaceNextChar() ) ;
	}
	return 0;
}
Example #17
0
TSmoke::TSmoke( TOBJList* owner, s32 sx, s32 sy, s32 _R, TSmoke* _prev )	: TOBJ(owner)
{
	FObjectName = "TSmoke";
	X = sx;
	Y = sy;
	FKind = kEffect;
	Speed = 13;
	Rdeg = _R+2048 & 0x0fff;
	ZoomRate = 0.2f + (f32)random(10)*0.01f;
	PersonalR = random(4095);
	IncR = random(64)-32;
	PrevSmoke = _prev;
	MotherIsDead = false;
	OriginalBGSpeed = FOwner->Speed;
	NextSmoke = NULL;

	TSpriteEXBLT sblt;
	sblt.RBM      =  bmNormal; // αブレンドモード
	sblt.RColor   =  0xFFFFFFFF; // ポリゴン色
	sblt.RDDDD    =  QD;     // TDDDDの参照
	sblt.RHeight  =  32;        // 幅
	sblt.RWidth   =  32;        // 高さ
	sblt.RX       =  0;        // X座標
	sblt.RY       =  0;        // Y座標
	sblt.RZ       =  SmokeZ;       // Z値

	Inc(SmokeZ);
	if( SmokeZ > 6000 ) SmokeZ = 3000;

	Sprite[0] =  new TJoint(sblt);         // スプライトの生成
	Inc(numSpr,1);
	Sprite[0]->GetSpr()->AddTexture(Eff8Tex, 33, 129, 64, 160);  //○
	Sprite[0]->GetSpr()->FCX += 16;
	Sprite[0]->GetSpr()->FCY += 16;
	Sprite[0]->GetSpr()->Move(X,Y);
	Sprite[0]->GetSpr()->Rotate(0);
	Sprite[0]->GetSpr()->FVisible = false;

}
void SortedVectorMapStore<V>::Inc(int32_t key, V delta) {
  size_t new_size = 0;
  bool suc = Inc(key, delta, &new_size);
  if (!suc) {
    if (new_size > capacity_) {
      Entry<V> *new_entries = new Entry<V>[new_size];
      memcpy(new_entries, entries_.get(), sizeof(Entry<V>)*num_entries_);

      entries_.reset(new_entries);
      capacity_ = new_size;

      CHECK(Inc(key, delta, &new_size));
    } else {
      CHECK_LE(new_size, capacity_);

      Entry<V> *new_entries = new Entry<V>[num_entries_];
      memcpy(new_entries, entries_.get(), sizeof(Entry<V>)*num_entries_);

      entries_.reset(new_entries);
      capacity_ = num_entries_;
    }
  }
}
Example #19
0
// Increase of the reference counter
UINT AddRef(REF *ref)
{
	UINT c;
	// Validate arguments
	if (ref == NULL)
	{
		return 0;
	}

	c = Inc(ref->c);

	// KS
	KS_INC(KS_ADDREF_COUNT);
	KS_INC(KS_CURRENT_REFED_COUNT);

	return c;
}
Example #20
0
void ClingoPropagator::undoLevel(Solver& s) {
	POTASSCO_REQUIRE(s.decisionLevel() == level_, "Invalid undo");
	uint32 beg = undo_.back();
	undo_.pop_back();
	if (prop_ > beg) {
		Potassco::LitSpan change = Potassco::toSpan(&trail_[0] + beg, prop_ - beg);
		ScopedLock(call_->lock(), call_->propagator(), Inc(epoch_))->undo(Control(*this, s), change);
		prop_ = beg;
	}
	trail_.resize(beg);
	if (front_ != INT32_MAX) {
		front_ = -1;
		--level_;
	}
	else {
		level_ = !trail_.empty() ? s.level(decodeLit(trail_.back()).var()) : 0;
	}
}
Example #21
0
void TMakeMissile2::Move()
{
	if( Age % ShotInt == 0 ) {
		for( u32 i = 0; i <= 1; i++ ) {                
			FOwner->LockOn2(SetNum,MissileNum);
			FOwner->Add(new TMissile(FOwner,FOwner->HeroPos.X,FOwner->HeroPos.Y,SetNum,MissileNum));
			Inc(MissileNum);
		}
		FOwner->Add(new TMissileFlash(FOwner,FOwner->HeroPos.X+16,FOwner->HeroPos.Y+8));
		if( CreateSE ) FOwner->SoundEffect->WavPlay(WAMissile,4);
	}

	if( Age >= (ShotInt*((MaxLock / 2) - 1)) ) {
		Dec(FOwner->RestMis,1);
		Die();
		FOwner->MissileON = false;
	}
	TOBJ::Move();

}
Example #22
0
// Create a reference counter
REF *NewRef()
{
	REF *ref;

	// Memory allocation
	ref = Malloc(sizeof(REF));

	// Create a Counter
	ref->c = NewCounter();

	// Increment only once
	Inc(ref->c);

	// KS
	KS_INC(KS_NEWREF_COUNT);
	KS_INC(KS_CURRENT_REF_COUNT);
	KS_INC(KS_ADDREF_COUNT);
	KS_INC(KS_CURRENT_REFED_COUNT);

	return ref;
}
Example #23
0
void AnimationIterator::Dec()
{ 
	if (on) {
		// If Dec() is exactly what should be done
		if (!m_circular || !goingForward) // If the iteration is linear, just do it. If it is circular, and should be iterating backwards, Dec()
		{
			if (MIN) // If at min
			{
				if (m_circular) goingForward = true; // Change direction
				else m_cycle = m_max-1; // Set to max
			}
			else
				m_cycle--; // Decrement
		}
		else if (m_circular && goingForward) // Iteration is circular, and should be iterating forward. Delegate to Inc()
		{
			Inc();
		}
	}
	else throw AnimationIteratorException("Iterator is off. Cannot decrement."); 
}
Example #24
0
/* Remove escaping backslashes */
static void
remove_backslashes(char *p)
{
    char *t = p;
    char *s = p;

    while (*p) {
	if (*p == '\\') {
	    if (t != s)
		memmove(t, s, p - s);
	    t += p - s;
	    s = ++p;
	    if (!*p) break;
	}
	Inc(p);
    }

    while (*p++);

    if (t != s)
	memmove(t, s, p - s); /* move '\0' too */
}
Example #25
0
// Layer-3 interface thread
void L3IfThread(THREAD *t, void *param)
{
	L3IF *f;
	CONNECTION *c;
	SESSION *s;
	POLICY *policy;
	char tmp[MAX_SIZE];
	char name[MAX_SIZE];
	char username[MAX_SIZE];
	// Validate arguments
	if (t == NULL || param == NULL)
	{
		return;
	}

	f = (L3IF *)param;

	StrCpy(username, sizeof(username), L3_USERNAME);
	if (f->Switch != NULL)
	{
		StrCat(username, sizeof(username), f->Switch->Name);
	}

	// Create a connection
	c = NewServerConnection(f->Switch->Cedar, NULL, t);
	c->Protocol = CONNECTION_HUB_LAYER3;

	// Create a Session
	policy = ClonePolicy(GetDefaultPolicy());
	// Not to limit the number of broadcast by policy
	policy->NoBroadcastLimiter = true;
	s = NewServerSession(f->Switch->Cedar, c, f->Hub, username, policy);
	c->Session = s;

	ReleaseConnection(c);

	// Determine the name of the session
	GetMachineHostName(tmp, sizeof(tmp));
	if (f->Switch->Cedar->Server->ServerType == SERVER_TYPE_STANDALONE)
	{
		Format(name, sizeof(name), "SID-L3-%s-%u", f->Switch->Name, Inc(f->Hub->SessionCounter));
	}
	else
	{
		Format(name, sizeof(name), "SID-L3-%s-%s-%u", tmp, f->Switch->Name, Inc(f->Hub->SessionCounter));
	}
	ConvertSafeFileName(name, sizeof(name), name);
	StrUpper(name);

	Free(s->Name);
	s->Name = CopyStr(name);

	s->L3SwitchMode = true;
	s->L3If = f;

	if (s->Username != NULL)
	{
		Free(s->Username);
	}
	s->Username = CopyStr(username);

	StrCpy(s->UserNameReal, sizeof(s->UserNameReal), username);

	f->Session = s;
	AddRef(s->ref);

	// Notify the initialization completion
	NoticeThreadInit(t);

	// Session main process
	SessionMain(s);

	// Release the session
	ReleaseSession(s);
}
Example #26
0
/*
 * Lock
 */
EXPORT void Lock( FastLock *lock )
{
	if ( Inc(lock) > 0 ) {
		tk_wai_sem(lock->id, 1, TMO_FEVR);
	}
}
  /*
  * Multiplies to Big ints according to Karatsuba-Ofmann
  * Bemerkung: Bigints a and b must have the same length, which must be of
    form 2^{k}. p points to a Bigint of double size - 2^{k+1} - the result
    is saved in.
  */
  void Multiply( bigintexpo k, bigint* p, const bigint* a, const bigint* b )
  {
    
    /* calculate length of a and b */
    bigintlength length = 1 << k;
    
    /*
    * if we are below the threshold, switch to school method
    * Die Wechselgrenze wurde empirisch ueber den Daumen geschaetzt
    */  
    if( k <= 5 ){
      NaivMultiplicationRestricted( k, p, a, b );
      return;
    }
    
    /***************************************/
    /* Declaration and initialization      */
    /***************************************/
    
    /* pointers to the low- and high-parts of the factors */
    const bigint *al,*ah,*bl,*bh;
    al = a;
    bl = b;
    ah = a + length/2;
    bh = b + length/2;
    
    /* Pointers to target memory */
    bigint *u1, *u2, *u3, *u4;
    u1 = p;
    u2 = p + length/2;
    u3 = p + length;
    u4 = p + length + length/2;
    
    /* Pointer to heap */
    bigint *heap = (bigint*)malloc( length * sizeof(bigint) );
    assert( heap != NULL );
    bigint *aux1, *aux2;
    aux1 = heap;
    aux2 = heap + length/2;
    
    /* Pointer to products ahbh and albl */
    bigint *ahbh = u3;
    bigint *albl = u1;
    
    /* Memory for some of the carries
    due to performance issues
    */
    bigint overflow = (bigint)0;
    
    
    /******************************/
    /* Calculations               */
    /******************************/
    
    /* Calculate middle product */
    
    /* Calculate (al + ah)(bl + bh) */
    
    /* Calculate the two sums */  
    bool carrya = false;
    bool carryb = false;
    CopyAdd( length/2, u4, al, ah, &carrya );
    CopyAdd( length/2, u1, bl, bh, &carryb );
    
    /* Multiply both */
      
    /* First recursion */  
    Multiply( k-1, aux1, u1, u4 );
    
    /* Do some additions, to calculate the high-part of the product */ 
    
    bool carryt = false;
      
    carryt = false;
    if( carryb ) Add( length/2, aux2, u4, &carryt );
    if( carryt ) overflow++;
  
    carryt = false;
    if( carrya ) Add( length/2, aux2, u1, &carryt );
    if( carryt ) overflow++;
    
    if( carrya && carryb ) overflow++;
    
    /*
    * Now the heap is (al+ah)(bl+bh)
    * We write al*bl and ah*bh directly into the target memory
    */  
    
    /* Calculate albl */
    Multiply( k-1, albl, al, bl );
    
    /* Calculate ahbh */
    Multiply( k-1, ahbh, ah, bh );
    
    /* Sub the two products from the heap */
    
    bool carrys = false;
     
    carrys = false;
    Sub( length, heap, albl, &carrys );
    if( carrys ) overflow--;
    
    carrys = false;
    Sub( length, heap, ahbh, &carrys );
    if( carrys ) overflow--;
    
    /*
    * Add the term at the heap to right place in the target
    * Evaluate the overflows
    */
    
    bool carryq = false;
    
    Add( length, u2, heap, &carryq );
    if( carryq ) overflow++;
    
    if( overflow == 1 ){
      carryq = false;
      Inc( length/2, u4, &carryq );
    }else if( overflow == 2 ){
      carryq = false;
      Inc( length/2, u4, &carryq );
      carryq = false;
      Inc( length/2, u4, &carryq );
    }
        
    /**********************************/
    /* Result is in the target memory */
    /**********************************/
    
    /* free all memory */
    free( heap );   
    
    
    /*{
      bigint* test = malloc( length*2 * sizeof(bigint) );
      NaivMultiplication( k, test, a, b );
      if( Compare( length*2, test, p ) ){
        printf( "Hauptrechnung: %d\n", length );
        OutputBigint( length, a );
        OutputBigint( length, b );
        OutputBigint( length*2, p );
        OutputBigint( length*2, test );
        assert(false);
      }
      free(test);
    }*/

  }
Example #28
0
void PlayerEntity::UpdatePhysics(NewtonWorld* world, float dt)
{

    Camera* cam=PlayerEntity::camera;
    const float moveSpeed = 100.0*dt;
    const float maxAcceleration = 10.0*dt;
    const float fallAcceleration = 4.0*dt;
    const float jumpStrength = 100.0*dt;

    static bool jumpOk;

    float move = (float)( glfwGetKey('W') - glfwGetKey('S') );
    float strafe = (float)( glfwGetKey('D') - glfwGetKey('A') );

    //Desired velocity representerar den önskvärda hastigheten från input
    glm::vec3 desiredVelocity(strafe,move,0.0f);

    //Normalisera desired om man önskar att gå snett
    if(glm::dot(desiredVelocity,desiredVelocity) > 1.0f)
        desiredVelocity *= 0.70710678f; // 1/sqrt(2)

    //Skala enligt movespeed
    desiredVelocity *= moveSpeed;

    //Skapa en matris för att transformera velocity till samma koordinatsystem som desiredVel är angivet i
    glm::mat4 mat = glm::gtc::matrix_transform::rotate(glm::mat4(1.0f),-cam->dir.z,glm::vec3(0.0f,0.0f,1.0f));

    //Skapa en kopia på velocity och transformera denna.
    glm::vec4 temp(velocity,1.0f);
    temp = mat * temp;

    //Öka på temp enligt desired
    temp.x=Inc(desiredVelocity.x,temp.x,maxAcceleration);
    temp.y=Inc(desiredVelocity.y,temp.y,maxAcceleration);

    //Transformera tillbaks
    mat = glm::gtc::matrix_transform::rotate(glm::mat4(1.0f),cam->dir.z,glm::vec3(0.0f,0.0f,1.0f));
    temp = mat * temp;

    velocity.x=temp.x;
    velocity.y=temp.y;

    if(!glfwGetKey(GLFW_KEY_SPACE))
        jumpOk=true;

    if(!airborne && jumpOk && glfwGetKey(GLFW_KEY_SPACE))
    {
        velocity.z=jumpStrength;
        jumpOk=false;
    }


    velocity.z -= fallAcceleration;
    airborne=true;

    if(velocity.z<=0.0)
    {
        //AlignToGroundConvex();
    }

    matrix[3].x += velocity.x;
    matrix[3].y += velocity.y;
    matrix[3].z += velocity.z;

    NewtonBodySetMatrix(body,&matrix[0][0]);

    for(int i=0; i<5; i++)
    {
        glm::vec3 g_minBox(matrix[3]+this->minBox);
        glm::vec3 g_maxBox(matrix[3]+this->maxBox);

        minPush = maxPush = glm::vec3(0.0f);

        NewtonWorldForEachBodyInAABBDo(world,&g_minBox[0],&g_maxBox[0],BodyIterator,this);

        matrix[3].x += (minPush.x+maxPush.x);
        matrix[3].y += (minPush.y+maxPush.y);
        matrix[3].z += (minPush.z+maxPush.z);

        NewtonBodySetMatrix(body,&matrix[0][0]);

        glm::vec3 normal;
        normal = minPush + maxPush;

        if(glm::dot(normal,normal)>0.0f)
            normal = glm::normalize(normal);

        velocity = velocity - normal*glm::dot(normal,velocity);
    }

    if(!airborne)
        velocity.z = std::min(velocity.z,0.0f);
}
Example #29
0
CIMQualifierDecl::CIMQualifierDecl(const CIMQualifierDecl& x)
{
    Inc(_rep = x._rep);
}
Example #30
0
//*****************************************************************************
// TXML_Lex::NextLexem (m) - returns next extracted lexem.
// Your should define the function yourself.
//*****************************************************************************
Lexem TXML_Lex::NextLexem( void )
{
	Lexem ret;
	double *p_d;
	QString *p_s;
	ret.LexType = LEX_NONE;

	do
	{
                while( IsSpaceNextChar() ) ;
		//*** Remarks' termination ***
		if( RemTermination( ret ) == -1 )
		{
			if( ret.LexType == __LEX_eof )
			{
				ret.LexType = LEX_eof;
				PutBack();
			}
			continue;
		}

		ret.line = GetLine();
		ret.col = GetCol();
		ret.shift = GetShift();
		if( ( SoleChar().isDigit() || SoleChar() == _T('.')  || SoleChar() == _T('+') || SoleChar() == _T('-') )
			&& mode == TXML_Lex_MODE_INTAG )
		{
			static LSDigit ldigit;
			ldigit.Reset();
			ret.LexType = ldigit.Analisys( getCurrentText() );
			switch( ret.LexType )
			{
			case LSDigit::Integer:
				ret.Index = ldigit.asign * ldigit.mnt_int;
				ret.LexType = LEX_const_int;
				break;
			case LSDigit::Float:
				ret.LexType = LEX_const_real;
				ldigit.mnt_float *= pow( 10.0, (int)ldigit.power );
				ret.Smth = d_autoheap.Add2List( p_d = new double( ldigit.asign * ldigit.mnt_float ) );
				break;
			case LSDigit::FloatIEEE:
				ret.LexType = LEX_const_real;
				ldigit.mnt_float *= pow( 10.0, (int)(ldigit.power + ldigit.sign * ldigit.powerE) );
				ret.Smth = d_autoheap.Add2List( p_d = new double( ldigit.asign * ldigit.mnt_float ) );
				break;
			default:
				lex_err = Lex::BadNumericFormat;
				ret.LexType = LEX_NONE;
				ret.Smth = 0;
			}
			Inc( ldigit.GetRead() );
			continue;
		}

		if( (SoleChar() == _T('\"') || SoleChar() == _T('\'')) && mode == TXML_Lex_MODE_INTAG )
		{
			static LXMLString lstring( SoleChar() );
			lstring.Reset( SoleChar() );
			if( ( ret.LexType = lstring.Analisys( getCurrentText() ) ) != LEX_NONE )
			{
				ret.LexType = LEX_const_string;
				ret.Smth    = s_autoheap.Add2List( p_s = new QString( lstring.read_string ) );
			}
			Inc( lstring.GetRead() );
			continue;
		}

		if( (SoleChar().isLetter() || (SoleChar() == _T('_'))) && mode == TXML_Lex_MODE_INTAG )
		{
			static LXMLVar lvar;
			lvar.Reset();
			int r = lvar.Analisys( getCurrentText() );
			if( r )
			{
				if( r == LXMLVar::XML )
					ret.LexType = LEX_kw_xml;
				else if( r == LXMLVar::DOCTYPE )
					ret.LexType = LEX_kw_doctype;
				else
					ret.LexType = LEX_id;
				ret.Smth    = s_autoheap.Add2List( p_s = new QString( (lvar.getNS().length() == 0) ? 
																			lvar.getID() : 
																			(lvar.getNS() + _T(":") + lvar.getID()) ) );
				Inc( lvar.GetRead() );
			}
			else
				ret.LexType = LEX_NONE;
			continue;
		}

		if( mode == TXML_Lex_MODE_INTAG )
		{
			QChar tch = NextChar();
			switch( tch.unicode() )
			{
			case _T('<'):
				if( SoleChar() == _T('?') )
				{
					ret.LexType = LEX_begintag_q;
					NextChar();
				}
				else if( SoleChar() == _T('!') )
				{
					ret.LexType = LEX_begintag_e;
					NextChar();
				}
				else if( SoleChar() == _T('/') )
				{
					ret.LexType = LEX_begintag_s;
					NextChar();
				}
				else
					ret.LexType = LEX_begintag;
				mode = TXML_Lex_MODE_INTAG;
				break;

			case _T('>'):
				ret.LexType = LEX_endtag;
				mode = TXML_Lex_MODE_OUTTAG;
				break;

			case _T('='):
				ret.LexType = LEX_equal;
				break;

			case _T('['):
				ret.LexType = LEX_lab;
				break;

			case _T(']'):
				ret.LexType = LEX_rab;
				break;

			case EOF_ASCII_1A :
			case EOF_ASCII_NULL :
				ret.LexType = LEX_eof;
				PutBack();
				break;

			case _T('/'):
			case _T('?'):
				if( SoleChar() == _T('>') )
				{
					ret.LexType = tch == _T('/') ? LEX_endtag_s : LEX_endtag_q;
					mode = TXML_Lex_MODE_OUTTAG;
					NextChar();
				}
				else
					ret.LexType = LEX_NONE;
				break;
			}
		}
		else
		{
			switch( NextChar().unicode() )
			{
			case _T('<'):
				if( SoleChar() == _T('?') )
				{
					ret.LexType = LEX_begintag_q;
					NextChar();
				}
				else if( SoleChar() == _T('!') )
				{
					ret.LexType = LEX_begintag_e;
					NextChar();
				}
				else if( SoleChar() == _T('/') )
				{
					ret.LexType = LEX_begintag_s;
					NextChar();
				}
				else
					ret.LexType = LEX_begintag;
				mode = TXML_Lex_MODE_INTAG;
				break;
			case EOF_ASCII_1A :				// !!! eof !!!
			case EOF_ASCII_NULL :				// !!! eof !!!
				ret.LexType = LEX_eof;
				PutBack();
				break;
			default :
				{
					QChar pch;
					PutBack( 2 );
					while( SoleChar().isSpace() && !isBOF() ) PutBack();
					NextChar();
					ret.Smth    = s_autoheap.Add2List( p_s = new QString( _T("") ) );
					ret.LexType = LEX_text;
					for( pch = NextChar(); pch != QChar('<') && pch != QChar(EOF_ASCII_1A) && pch != QChar(EOF_ASCII_NULL); pch = NextChar() )
					{
						*(QString*)ret.Smth += pch;
					}
					PutBack();
				}
			}
		}
	}
	while( 0 );

	prev_lexem.LexType = ret.LexType;
	return ret;
}