//////////////////////////////////////////////////////////////////////////
// onAttach
//virtual
void GaRobotComponent::onAttach( ScnEntityWeakRef Parent )
{
	Super::onAttach( Parent );

	StartPosition_ = Parent->getLocalPosition();
	TargetPosition_ = Parent->getLocalPosition();

	Canvas_ = Parent->getComponentAnyParentByType< ScnCanvasComponent >();
	Material_ = Parent->getComponentAnyParent( "DefaultCanvasMaterial_0" );
	View_ = ScnCore::pImpl()->findEntity( "CameraEntity_0" )->getComponentByType< ScnViewComponent >();

	auto spawnPart = [ & ]( const BcName PartName )
	{
		ScnEntitySpawnParams EntityParams = 
		{
			"default", PartName, BcName( PartName.getValue(), getParentEntity()->getName().getID() ),
			MaMat4d(),
			getParentEntity()
		};
		return ScnCore::pImpl()->spawnEntity( EntityParams );
	};

	Base_ = spawnPart( "RobotBase" );
	Turret_ = spawnPart( "RobotTurret" );

	MoveAngle_ = getName().getID() == 0 ? 0.0f : BcPI;
}
//////////////////////////////////////////////////////////////////////////
// update
//virtual
void GaSpeechBubbleComponent::update( BcF32 Tick )
{
	Super::update( Tick );

	if ( !FontComponent_.isValid() )
	{
		Canvas_ = ParentEntity_->getComponentAnyParentByType< ScnCanvasComponent >();
		FontComponent_ = ParentEntity_->getComponentAnyParentByType< ScnFontComponent >();
	}
	if ( !SpeechBubble_.isValid() )
	{
		SpeechBubble_ = ParentEntity_->getComponentByType<ScnSpriteComponent>( BcName( "SpeechBubbleComponent", 0 ) );
	}
	if ( SpeechBubble_.isValid() )
	{
		SpeechBubble_->setColour( RsColour( 1, 1, 1, Visible_ ? 0.8 : 0 ) );
	}
	if ( !TargetEntity_.isValid() )
	{
		// We aren't even gonna bother
		return;
	}

	MaMat4d TextScaleMatrix;
	//TextScaleMatrix.scale( MaVec4d( 0.04f, 0.04f, 1.0f, 1.0f ) );
	TextScaleMatrix.scale( MaVec4d( 1.00f, -1.00f, 1.0f, 1.0f ) );

	FontComponent_->setAlphaTestStepping( MaVec2d( 0.4f, 0.45f ) );


	if (Visible_)
	{
		TimeBeenVisible_ += Tick;
		if ( TimeBeenVisible_ > VisibleTime_ )
			Visible_ = false;
		//MaMat4d Matrix = getParentEntity()->getWorldMatrix();
		//Matrix = Canvas_->popMatrix();
		Canvas_->pushMatrix( TextScaleMatrix );
	
		MaVec2d Size;
		MaVec3d worldPos = TargetEntity_->getWorldPosition();
		MaVec2d Position( 0 , 0 );
		MaVec2d localPos  = SpeechBubble_->getPosition();
		localPos  = MaVec2d(TargetEntity_->getWorldPosition().x(), -TargetEntity_->getWorldPosition().y() ) + FontOffset_;
		SpeechBubble_->setPosition( MaVec2d( TargetEntity_->getWorldPosition().x(), TargetEntity_->getWorldPosition().y() )  + SpriteOffset_ );
		for( BcU32 Idx = 0; Idx < Text_.size(); ++Idx )
		{
			const auto& Option( Text_[ Idx ] );
			const auto Colour = RsColour::BLACK;
			Size = FontComponent_->drawCentered( Canvas_, localPos + Position, Text_[ Idx ] , Colour, 280 );
			Position += MaVec2d( 0.0f, Size.y() );
		}



		Canvas_->popMatrix();
	}
	//Canvas_->pushMatrix( Matrix );
	//Canvas_->setMatrix( Matrix );
}
Exemple #3
0
	ReEnum* GetEnum( BcName Name )
	{
		auto NameString = ( *Name );

		// If it begins with "class", "struct", or "enum", strip it.
		// NOTE: We should move this work into the demangling stuff.
		if( NameString.substr( 0, 5 ) == "enum " )
		{
			Name = BcName( NameString.substr( NameString.find( " " ) + 1, NameString.length() - 1 ) );
		}

		// Try find class.
		ReClass* FoundType = GetType( Name );
		if( FoundType == nullptr )
		{
			BcAssertMsg( BcIsGameThread(), "Reflection can only modify database on the game thread." );
			FoundType = new ReEnum( Name );
			Types_[ Name ] = FoundType;
		}

		if( FoundType->isTypeOf< ReEnum >() )
		{
			return static_cast< ReEnum* >( FoundType );
		}
		else
		{
			return nullptr;
		}
	}
Exemple #4
0
	ReClass* GetClass( BcName Name )
	{
		auto NameString = (*Name);

		// If it begins with "class", "struct", or "enum", strip it.
		// NOTE: We should move this work into the demangling stuff.
		if( NameString.substr( 0, 6 ) == "class " ||
			NameString.substr( 0, 7 ) == "struct " ||
			NameString.substr( 0, 5 ) == "enum " )
		{
			Name = BcName( NameString.substr( NameString.find( " " ) + 1, NameString.length() - 1 ) );
		}

		// Try find class.
		ReClass* FoundType = GetType( Name );
		if( FoundType == nullptr )
		{
			BcAssertMsg( BcIsGameThread(), "Reflection can only modify database on the game thread." );
			FoundType = new ReClass( Name );
			Types_[ Name ] = FoundType;
		}

		// Use dynamic cast here instead of our internal RTTI.
		// It may still be under construction so not yet valid.
		return dynamic_cast< ReClass* >( FoundType );
	}
//////////////////////////////////////////////////////////////////////////
// fireWeaponB
void GaRobotComponent::fireWeaponB( BcF32 Radius )
{
	if( WeaponBTimer_ < 0.0f && Energy_ > WeaponBCost_ )
	{
		auto Robots = getRobots( 1 - Team_ );
		if( Robots.size() > 0 )
		{
			Energy_ -= WeaponBCost_;
			WeaponBTimer_ = WeaponBCoolDown_;
			MoveTimer_ = WeaponBCoolDown_ * 0.1f;

			// Spawn entity.
			ScnEntitySpawnParams EntityParams = 
			{
				"default", BcName( "WeaponEntity", 1 ), BcName( "WeaponEntity", 1 ),
				getParentEntity()->getLocalMatrix(),
				getParentEntity()->getParentEntity()
			};

			auto Entity = ScnCore::pImpl()->spawnEntity( EntityParams );
			BcAssert( Entity != nullptr );
			auto WeaponComponent = Entity->getComponentByType< GaWeaponComponent >();
			WeaponComponent->TargetPosition_ = Robots[ 0 ]->getParentEntity()->getLocalPosition();
			// Randomise target position slightly.
			WeaponComponent->TargetPosition_ += MaVec3d( 
				BcRandom::Global.randRealRange( -1.0f, 1.0f ),
				0.0f,
				BcRandom::Global.randRealRange( -1.0f, 1.0f ) ).normal() * Radius;

			playSound( "weaponb" );
		}
	}
	else
	{
		playSound( "fail" );
	}
}
////////////////////////////////////////////////////////////////////////////////
// spawnFoodEntity
void GaMainGameState::spawnFoodEntity( const BcVec2d& Position )
{
	ScnEntityRef Entity;

	if( CsCore::pImpl()->createResource( BcName( "FoodEntity" ), Entity ) )
	{
		GaFoodComponentRef Component;
		if( CsCore::pImpl()->createResource( BcName::INVALID, Component, Position ) )
		{
			Component->setParent( this );
			Component->setProjection( Projection_ );
			Entity->attach( Component );
			SpawnEntities_.push_back( GaGameComponentRef( Component ) );
		}
	}

	ScnCore::pImpl()->addEntity( Entity );
}
////////////////////////////////////////////////////////////////////////////////
// spawnSwarmEntity
void GaMainGameState::spawnSwarmEntity( BcU32 Level )
{
	ScnEntityRef Entity;

	if( CsCore::pImpl()->createResource( BcName( "SwarmEntity" ), Entity ) )
	{
		GaSwarmComponentRef Component;
		if( CsCore::pImpl()->createResource( BcName::INVALID, Component, Level ) )
		{
			Component->setParent( this );
			Component->setProjection( Projection_ );
			Entity->attach( Component );
			SpawnEntities_.push_back( GaGameComponentRef( Component ) );
		}
	}

	ScnCore::pImpl()->addEntity( Entity );
}
Exemple #8
0
//////////////////////////////////////////////////////////////////////////
// internalCreateResource
BcBool CsCore::internalCreateResource( const BcName& Name, const ReClass* Class, BcU32 Index, CsPackage* pPackage, ReObjectRef< CsResource >& Handle )
{
	// Generate a unique name for the resource.
	BcName UniqueName = Name.isValid() ? Name : BcName( Class->getName() ).getUnique();

	// Allocate resource with a unique name.
	Handle = allocResource( UniqueName, Class, Index, pPackage );
	
	// Put into create list.
	if( Handle.isValid() )
	{
		std::lock_guard< std::recursive_mutex > Lock( ContainerLock_ );

		PrecreateResources_.push_back( Handle );
	}
	
	return Handle.isValid();
}
Exemple #9
0
//////////////////////////////////////////////////////////////////////////
// isValidResource
BcBool CsCore::isValidResource( const BcPath& FileName ) const
{
	BcName ExtensionName = BcName( FileName.getExtension() );
	return ( ResourceFactoryInfoMap_.find( ExtensionName ) != ResourceFactoryInfoMap_.end() );
}