示例#1
0
bool CAI_BaseHumanoid::OnMoveBlocked( AIMoveResult_t *pResult )
{
	if ( *pResult != AIMR_BLOCKED_NPC && GetNavigator()->GetBlockingEntity() && !GetNavigator()->GetBlockingEntity()->IsNPC() )
	{
		CBaseEntity *pBlocker = GetNavigator()->GetBlockingEntity();

		float massBonus = ( IsNavigationUrgent() ) ? 40.0 : 0;

		if ( pBlocker->GetMoveType() == MOVETYPE_VPHYSICS && 
			 pBlocker != GetGroundEntity() && 
			 !pBlocker->IsNavIgnored() &&
			 !dynamic_cast<CBasePropDoor *>(pBlocker) &&
			 pBlocker->VPhysicsGetObject() && 
			 pBlocker->VPhysicsGetObject()->IsMoveable() && 
			 ( pBlocker->VPhysicsGetObject()->GetMass() <= 35.0 + massBonus + 0.1 || 
			   ( pBlocker->VPhysicsGetObject()->GetMass() <= 50.0 + massBonus + 0.1 && IsSmall( pBlocker ) ) ) )
		{
			DbgNavMsg1( this, "Setting ignore on object %s", pBlocker->GetDebugName() );
			pBlocker->SetNavIgnore( 2.5 );
		}
#if 0
		else
		{
			CPhysicsProp *pProp = dynamic_cast<CPhysicsProp*>( pBlocker );
			if ( pProp && pProp->GetHealth() && pProp->GetExplosiveDamage() == 0.0 && GetActiveWeapon() && !GetActiveWeapon()->ClassMatches( "weapon_rpg" ) )
			{
				Msg( "!\n" );
				// Destroy!
			}
		}
#endif
	}

	return BaseClass::OnMoveBlocked( pResult );
}
示例#2
0
void expM(std::complex<double> U[d3][d3], std::complex<double> A[d3][d3]) {
  // U = exp(A)
  // U = 1 + sum_i 1/i! * A^i
  const int nmax=20;
  
  std::complex<double> Atmp1[d3][d3], Atmp2[d3][d3];
  
  for (int i=0; i<d3; i++) {
    for (int j=0; j<d3; j++) {
      U[i][j] = 0;
    }
  }
  
  for (int i=0; i<d3; i++) {
    U[i][i] = 1;
    Atmp1[i][i] = 1;
  }

  double fact=1;

  int i=0;
  for (i=1; i<nmax; i++) {
    fact *= i;
    axb(Atmp2,Atmp1,A);
    aeb(Atmp1,Atmp2);
    za(Atmp2, 1.0/(double)fact, Atmp2);
    apb(U,Atmp2);
    if (IsSmall(Atmp2))
      break;
  }
}
示例#3
0
void String0::Remove(int pos, int count)
{
	ASSERT(pos >= 0 && count >= 0 && pos + count <= GetCount());
	UnShare();
	char *s = (char *)Begin();
	memmove(s + pos, s + pos + count, GetCount() - pos - count + 1);
	if(IsSmall())
		SetSLen(SLen() - count);
	else
		LLen() -= count;
}
示例#4
0
文件: sheap.cpp 项目: koz4k/soccer
bool Heap::TryRealloc(void *ptr, size_t newsize)
{
	if(!ptr) return 0;
	LLOG("GetBlockSize " << ptr);
	if(IsSmall(ptr)) {
		Page *page = GetPage(ptr);
		int k = page->klass;
		return newsize <= (size_t)Ksz(k);
	}
	return LTryRealloc(ptr, newsize);
}
示例#5
0
文件: sheap.cpp 项目: koz4k/soccer
size_t Heap::GetBlockSize(void *ptr)
{
	if(!ptr) return 0;
	LLOG("GetBlockSize " << ptr);
	if(IsSmall(ptr)) {
		Page *page = GetPage(ptr);
		int k = page->klass;
		return Ksz(k);
	}
	return LGetBlockSize(ptr);
}
示例#6
0
Ref * sysNewMethod( Ref * pc, MachineClass * vm ) {
	//	newMethod( name:String, ninputs:Small, noutputs:Small ) -> m:Method
	if ( vm->count != 3 ) throw Ginger::Mishap( "Wrong number of arguments" );
	
	Ref noutputs = vm->fastPop();
	Ref ninputs = vm->fastPop();
	Ref name = vm->fastPop();
	
	if ( !IsSmall( noutputs ) || !IsSmall( ninputs ) ) throw Ginger::Mishap( "Invalid arguments" ).culprit( "#Outputs", refToString( noutputs ) ).culprit( "Inputs", refToString( ninputs ) );
	
	CodeGen codegen = vm->codegen();
	codegen->vmiFUNCTION( 
		name == SYS_ABSENT ? std::string( EMPTY_FN_NAME ) : refToString( name ),
		SmallToLong( ninputs ), 
		SmallToLong( noutputs ) 
	);
	codegen->vmiINVOKE();
	Ref r = codegen->vmiENDFUNCTION( sysMethodKey );
	vm->fastPush( r );	//	No check needed, as stack has room for 3.
	return pc;
}
示例#7
0
文件: sheap.cpp 项目: koz4k/soccer
force_inline
void Heap::Free(void *ptr)
{
	if(!ptr) return;
	LLOG("Free " << ptr);
	if(IsSmall(ptr)) {
		Page *page = GetPage(ptr);
		Free(ptr, page, page->klass);
	}
	else
		LFree(ptr);
}
示例#8
0
void String0::Trim(int pos)
{
	ASSERT(pos >= 0 && pos <= GetCount());
	if(IsSmall()) {
		chr[pos] = 0;
		SetSLen(pos);
	}
	else {
		UnShare();
		ptr[pos] = 0;
		LLen() = pos;
	}
}
示例#9
0
/**
	setSlot( CLASS:Class, POSITION:Small, METHOD:Method )
	
	1. 	The method is inserted into the correct position in the class's
		slot array. To start with, only one method per slot will be
		permitted.
		
	2.	A call to setMethod is then made with an unsafe access function
		as the method's function. The values are passed on the stack. 
		No stack checks are needed as the size of the argument lists of
		the two functions are the same.
*/
Ref * sysSetSlot( Ref * pc, MachineClass * vm ) {
	if ( vm->count != 3 ) throw Ginger::Mishap( "Wrong number of arguments" );

	Ref method = vm->fastPop();
	Ref position = vm->fastPop();
	Ref gclass = vm->fastPop();

	if ( !IsMethod( method ) ) throw Ginger::Mishap( "Method needed" ).culprit( "Method", refToString( method ) );
	if ( !IsSmall( position ) ) throw Ginger::Mishap( "Small needed" ).culprit( "Position", refToString( position ) );
	if ( !IsClass( gclass ) ) throw Ginger::Mishap( "Class needed" ).culprit( "Class", refToString( gclass ) );
	
	long pos = SmallToLong( position );
	long nfields = SmallToLong( RefToPtr4( gclass )[ CLASS_OFFSET_NFIELDS ] );
	if ( not( 1 <= pos && pos <= nfields ) ) {
		throw 
			Ginger::Mishap( "Position out of range" ).
			culprit( "Position", pos ).
			culprit( "Number of fields", nfields )
		;
	}
	
	//	Update the class-slot.
	INDEX( INDEX( gclass, CLASS_OFFSET_SLOTS ), pos ) = method;

	//	Push onto the stack to get protection from garbage collection.
	vm->fastPush( gclass );
	vm->fastPush( method );

	//	ENDFUNCTION does not in fact cause a garbage collection, as it
	//	forces the heap to grow. However this is a more accurate way
	//	to write the code. 
	//
	//	The following block should not be in-lined but extracted as a 
	//	service function.
	{
		CodeGen codegen = vm->codegen();
		//	TODO: Supply a useful name.
		codegen->vmiFUNCTION( 1, 1 );
		codegen->vmiFIELD( pos );
		codegen->vmiSYS_RETURN();
		vm->fastPush( codegen->vmiENDFUNCTION() );
	}

	//	We do not need to modify vm->count, it's already 3.
	//	Simply chain into sysSetMethod. 
	return sysSetMethod( pc, vm );
}
示例#10
0
void String0::Cat(const char *s, int len)
{
	if(IsSmall()) {
		if(SLen() + len < 14) {
			memcpy(chr + SLen(), s, len);
			SLen() += len;
			chr[SLen()] = 0;
			return;
		}
	}
	else
		if((int)LLen() + len < LAlloc() && !IsSharedRef()) {
			memcpy(ptr + LLen(), s, len);
			LLen() += len;
			ptr[LLen()] = 0;
			return;
		}
	Insert(GetCount(), len, s);
}
示例#11
0
void String0::LCat(int c)
{
	if(IsSmall()) {
		qword *x = (qword *)MAlloc_S();
		x[0] = q[0];
		x[1] = q[1];
		LLen() = SLen();
		SLen() = 15;
		chr[KIND] = MEDIUM;
		qptr = x;
	}
	int l = LLen();
	if(IsRef() ? !IsShared() && l < (int)Ref()->alloc : l < 31) {
		ptr[l] = c;
		ptr[LLen() = l + 1] = 0;
	}
	else {
		char *s = Insert(l, 1, NULL);
		s[0] = c;
		s[1] = 0;
	}
}
示例#12
0
char *String0::Insert(int pos, int count, const char *s)
{
	ASSERT(pos >= 0 && count >= 0 && pos <= GetCount());
	int len = GetCount();
	int newlen = len + count;
	char *str = (char *)Begin();
	if(newlen < GetAlloc() && !IsSharedRef()/* && !(s >= str && s <= str + len)*/) {
		if(s >= str + pos && s <= str + len)
			s += count;
		if(pos < len)
			memmove(str + pos + count, str + pos, len - pos);
		if(IsSmall())
			SLen() = newlen;
		else
			LLen() = newlen;
		str[newlen] = 0;
		if(s)
			memcpy(str + pos, s, count);
		return str + pos;
	}
	char kind;
	char *p = Alloc(max(2 * len, newlen), kind);
	if(pos > 0)
		memcpy(p, str, pos);
	if(pos < len)
		memcpy(p + pos + count, str + pos, len - pos);
	if(s)
		memcpy(p + pos, s, count);
	p[newlen] = 0;
	Free();
	ptr = p;
	LLen() = newlen;
	SLen() = 15;
	chr[KIND] = kind;
	return ptr + pos;
}
示例#13
0
文件: cell.hpp 项目: Spicery/ginger
	bool isSmall() const { return IsSmall( this->ref ); }