Exemplo n.º 1
0
//////////////////////////////////////////////////////////////////////////
// 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;
}
Exemplo n.º 2
0
//////////////////////////////////////////////////////////////////////////
// onDetach
//virtual
void ScnModelComponent::onDetach( ScnEntityWeakRef Parent )
{
	// Wait for update + upload to complete.
	UpdateFence_.wait();
	UploadFence_.wait();

	// Detach material components from parent.
	for( BcU32 Idx = 0 ; Idx < PerComponentMeshDataList_.size(); ++Idx )
	{
		auto& PerComponentMeshData( PerComponentMeshDataList_[ Idx ] );
		Parent->detach( PerComponentMeshData.MaterialComponentRef_ );
		PerComponentMeshData.MaterialComponentRef_ = nullptr;
	}

	// Destroy resources.
	for( BcU32 Idx = 0; Idx < PerComponentMeshDataList_.size(); ++Idx )
	{
		RsCore::pImpl()->destroyResource( PerComponentMeshDataList_[ Idx ].UniformBuffer_ );
	}
	
	// Delete duplicated node data.
	delete [] pNodeTransformData_;
	pNodeTransformData_ = nullptr;

	//
	Super::onDetach( Parent );
}
//////////////////////////////////////////////////////////////////////////
// onDetach
//virtual
void ScnParticleSystemComponent::onDetach( ScnEntityWeakRef Parent )
{
	Parent->detach( MaterialComponent_ );

	MaterialComponent_ = NULL;

	Super::onDetach( Parent );
}
Exemplo n.º 4
0
//////////////////////////////////////////////////////////////////////////
// GaGameComponent
//virtual
void GaGameComponent::onDetach( ScnEntityWeakRef Parent )
{
	// Null canvas reference.
	CanvasComponent_ = NULL;

	// Detach materials.
	Parent->detach( DefaultMaterial_ );
	Parent->detach( BackgroundMaterial_ );
	Parent->detach( SpriteSheetMaterials_[ 0 ] );
	Parent->detach( SpriteSheetMaterials_[ 1 ] );
	Parent->detach( HUDMaterial_ );
	Parent->detach( Font_ );

	// Unsubscribe.
	OsCore::pImpl()->unsubscribeAll( this );

	// Don't forget to detach!
	Super::onDetach( Parent );
}
//////////////////////////////////////////////////////////////////////////
// onDetach
//virtual
void ScnParticleSystemComponent::onDetach( ScnEntityWeakRef Parent )
{
	Parent->detach( MaterialComponent_ );

	MaterialComponent_ = nullptr;

	for( BcU32 Idx = 0; Idx < 2; ++Idx )
	{
		TVertexBuffer& VertexBuffer = VertexBuffers_[ Idx ];
		RsCore::pImpl()->destroyResource( VertexBuffer.pVertexBuffer_ );
		RsCore::pImpl()->destroyResource( VertexBuffer.UniformBuffer_ );
	}

	RsCore::pImpl()->destroyResource( VertexDeclaration_ );
	
	delete [] pParticleBuffer_;

	Super::onDetach( Parent );
}
Exemplo n.º 6
0
//////////////////////////////////////////////////////////////////////////
// onAttach
void GaStructureComponent::onAttach( ScnEntityWeakRef Parent )
{
	// Get canvas + font.
	Canvas_ = Parent->getComponentAnyParentByType< ScnCanvasComponent >();
	BcAssert( Canvas_ );
	Font_ = Parent->getComponentAnyParentByType< ScnFontComponent >();
	BcAssert( Font_ );
	Sprite_ = Parent->getComponentAnyParentByType< ScnSpriteComponent >();
	BcAssert( Sprite_ );
	Physics_ = getParentEntity()->getComponentByType< GaPhysicsComponent >();
	BcAssert( Physics_ );
	Game_ = getParentEntity()->getComponentAnyParentByType< GaGameComponent >();
	BcAssert( Game_ );

	// Subscribe to hotspot for pressed.
	Parent->subscribe( gaEVT_HOTSPOT_PRESSED, this,
		[ this ]( EvtID, const EvtBaseEvent& InEvent )->eEvtReturn
		{
			const auto& Event = InEvent.get< GaHotspotEvent >();

			return evtRET_PASS;
		} );

	// Begin build phase event
	Game_->getParentEntity()->subscribe( gaEVT_GAME_BEGIN_BUILD_PHASE, this, 
		[ this ]( EvtID, const EvtBaseEvent & Event )
		{
			if( StructureType_ == GaStructureType::RESOURCE )
			{
				Game_->spendResources( -CalculatedResourceRate_ );
			}
			return evtRET_PASS;
		} );

	setActive( Active_ );

	Level_ = 0;
	incLevel();
	Timer_ = BaseFireRate_;
	
	Super::onAttach( Parent );
}
//////////////////////////////////////////////////////////////////////////
// onAttach
//virtual
void ScnParticleSystemComponent::onAttach( ScnEntityWeakRef Parent )
{
	Parent->attach( MaterialComponent_ );

	Super::onAttach( Parent );
}
Exemplo n.º 8
0
////////////////////////////////////////////////////////////////////////////////
// onAttach
//virtual
void GaGameComponent::onAttach( ScnEntityWeakRef Parent )
{
	Super::onAttach( Parent );	

	Parent->attach( EmoteMaterialComponent_ );
}
Exemplo n.º 9
0
//////////////////////////////////////////////////////////////////////////
// GaGameComponent
//virtual
void GaGameComponent::onAttach( ScnEntityWeakRef Parent )
{
	// Find canvas component on parent. TODO: Make a utility function for this.
	for( BcU32 Idx = 0; Idx < Parent->getNoofComponents(); ++Idx )
	{
		CanvasComponent_ = Parent->getComponent( Idx );

		if( CanvasComponent_.isValid() )
		{
			break;
		}
	}

	// Materials.
	ScnMaterialRef Material;
	if( CsCore::pImpl()->requestResource( "game", "default", Material ) )
	{
		if( CsCore::pImpl()->createResource( BcName::INVALID, DefaultMaterial_, Material, BcErrorCode ) )
		{
			Parent->attach( DefaultMaterial_ );
		}
	}
	if( CsCore::pImpl()->requestResource( "game", "background", Material ) )
	{
		if( CsCore::pImpl()->createResource( BcName::INVALID, BackgroundMaterial_, Material, BcErrorCode ) )
		{
			Parent->attach( BackgroundMaterial_ );
		}
	}
	if( CsCore::pImpl()->requestResource( "game", "spritesheet0", Material ) )
	{
		if( CsCore::pImpl()->createResource( BcName::INVALID, SpriteSheetMaterials_[ 0 ], Material, BcErrorCode ) )
		{
			Parent->attach( SpriteSheetMaterials_[ 0 ] );
		}
	}
	if( CsCore::pImpl()->requestResource( "game", "spritesheet1", Material ) )
	{
		if( CsCore::pImpl()->createResource( BcName::INVALID, SpriteSheetMaterials_[ 1 ], Material, BcErrorCode ) )
		{
			Parent->attach( SpriteSheetMaterials_[ 1 ] );
		}
	}
	if( CsCore::pImpl()->requestResource( "game", "hud", Material ) )
	{
		if( CsCore::pImpl()->createResource( BcName::INVALID, HUDMaterial_, Material, BcErrorCode ) )
		{
			Parent->attach( HUDMaterial_ );
		}
	}

	// Font
	ScnFontRef Font;
	if( CsCore::pImpl()->requestResource( "game", "default", Font ) && CsCore::pImpl()->requestResource( "game", "font", Material ) )
	{
		if( CsCore::pImpl()->createResource( BcName::INVALID, Font_, Font, Material ) )
		{
			FontMaterial_ = Font_->getMaterialComponent();
			Parent->attach( Font_ );
		}
	}
	
	// Bind input events.
	//if( TeamID_ == 0 )
	{
		OsEventInputMouse::Delegate OnMouseEvent = OsEventInputMouse::Delegate::bind< GaGameComponent, &GaGameComponent::onMouseEvent >( this );
		OsEventInputKeyboard::Delegate OnKeyEvent = OsEventInputKeyboard::Delegate::bind< GaGameComponent, &GaGameComponent::onKeyEvent >( this );
		OsCore::pImpl()->subscribe( osEVT_INPUT_MOUSEUP, OnMouseEvent );
		OsCore::pImpl()->subscribe( osEVT_INPUT_MOUSEMOVE, OnMouseEvent );
		OsCore::pImpl()->subscribe( osEVT_INPUT_MOUSEDOWN, OnMouseEvent );
		OsCore::pImpl()->subscribe( osEVT_INPUT_KEYDOWN, OnKeyEvent );
		OsCore::pImpl()->subscribe( osEVT_INPUT_KEYUP, OnKeyEvent );
	}

	// Don't forget to attach!
	Super::onAttach( Parent );
}
Exemplo n.º 10
0
//////////////////////////////////////////////////////////////////////////
// onDetach
void GaStructureComponent::onDetach( ScnEntityWeakRef Parent )
{
	setActive( BcFalse );
	Parent->unsubscribeAll( this );
	Super::onDetach( Parent );
}