Beispiel #1
0
void SbTrail::Add(BtU32 colourIndex, const MtVector3 &v3Position, const MtVector3 &v3Cross)
{
	RsColour colour(RsColour::WhiteColour());

	if( v3Position.y > SeaLevel )
	{
		colour = RsColour( 0.4f, 0.4f, 0.4f, 1.0f );
	}
	else
	{
		colour = RsColour(0.4f, 0.4f, 1.0f, 1.0f);
	}

	MtVector2 v2Delta = v3Position - m_v3Last;

	if((v2Delta.GetLength() > 0.01f))
	{
		MuTrailBit *pTrailBit = m_trail.AddTail();

		pTrailBit->m_v3Position = v3Position;
		pTrailBit->m_v3Cross = v3Cross;
		pTrailBit->m_tick = 0;
		pTrailBit->m_id = 1;
		pTrailBit->m_colour = colour;

		m_v3Last = v3Position;
	}
}
//////////////////////////////////////////////////////////////////////////
// update
//virtual
void ScnParticleSystemComponent::update( BcReal Tick )
{
	///*
	// TEST CODE.
	for( BcU32 Idx = 0; Idx < 4; ++Idx )
	{
		ScnParticle* pParticle = NULL;
		if( allocParticle( pParticle ) )
		{
			pParticle->Position_ = BcVec3d( 0.0f, 0.0f, 0.0f );
			pParticle->Velocity_ = BcVec3d( BcRandom::Global.randReal() - 0.5f, BcRandom::Global.randReal() - 0.5f, BcRandom::Global.randReal() - 0.5f ).normal() * 16.0f;
			pParticle->Acceleration_ = -pParticle->Velocity_ * 0.5f;
			pParticle->RotationMultiplier_ = ( BcRandom::Global.randReal() - 0.5f ) * 4.0f;
			pParticle->MinScale_ = BcVec2d( 0.5f, 0.5f );
			pParticle->MaxScale_ = BcVec2d( 4.0f, 4.0f );
			pParticle->MinColour_ = RsColour( 1.0f, 0.0f, 1.0f, 0.1f );
			pParticle->MaxColour_ = RsColour( 0.0f, 1.0f, 1.0f, 0.0f );
			pParticle->UVBounds_ = BcVec4d( 0.0f, 0.0f, 1.0f, 1.0f );
			pParticle->CurrentTime_ = 0.0f;
			pParticle->MaxTime_ = 4.0f;
			pParticle->Alive_ = BcTrue;
		}
	}
	//*/
	

	// Allocate particles.
	updateParticles( Tick );
}
Beispiel #3
0
//////////////////////////////////////////////////////////////////////////
// getTexel
RsColour ScnTexture::getTexel( BcU32 X, BcU32 Y ) const
{
	if( pTextureData_ != NULL && X < Header_.Width_ && Y < Header_.Height_ )
	{
		BcU32* pTextureData = (BcU32*)pTextureData_;
		BcU32 Index = X + Y * Header_.Width_;
		BcU32 Texel = pTextureData[ Index ] ;
		return RsColour( Texel ); // invalid. need to fix.
	}
	
	return RsColour( 0.0f, 0.0f, 0.0f, 0.0f );
}
Beispiel #4
0
//////////////////////////////////////////////////////////////////////////
// renderHUD
void GaGameUnit::renderHUD( ScnCanvasComponentRef Canvas, BcFixed TimeFraction )
{
	if( TeamID_ > 1 )
	{
		return;
	}

	if( Behaviour_ != BEHAVIOUR_DEAD )
	{
		BcU32 TextureIdx = Desc_.Type_;
		BcFixedVec2d GamePosition( getInterpolatedPosition( TimeFraction ) );
		const BcReal ScaleFactor = 32.0f;
		BcVec2d Position( GamePosition.x(), GamePosition.y() );
		BcVec2d Size( Desc_.Size_.x(), Desc_.Size_.y() );

		Position *= ScaleFactor;
		Size *= ScaleFactor;

		// Draw range if selected.
		const BcReal MaxRangeRadius = Desc_.Range_ / ScaleFactor;
		
		
		// Draw health bar.
		BcFixed HealthFraction = Health_ / Desc_.Health_;
		BcVec2d HealthBarPosition = Position - Size * 0.5f + BcVec2d( 2.0f, -6.0f );
		BcVec2d HealthBarSize = BcVec2d( HealthFraction * ( Size.x() - 4.0f ), 2.0f );
		RsColour HealthColour = RsColour::GREEN ;

		if( HealthFraction <= 0.5f )
		{
			HealthColour = RsColour::YELLOW;
		}
		if( HealthFraction <= 0.25f )
		{
			HealthColour = RsColour::RED;
		}

		Canvas->drawSprite( HealthBarPosition, HealthBarSize, 0, HealthColour * RsColour( 1.0f, 1.0f, 1.0f, 0.75f ), 3 );

		// Draw cool down bar.
		BcFixed MaxAttackTime = BcFixed( 1.0f ) / Desc_.RateOfAttack_;
		BcFixed CoolDownFraction = BcFixed( 1.0f ) - ( AttackTimer_ / MaxAttackTime );
		BcVec2d CoolDownBarPosition = Position - Size * 0.5f + BcVec2d( 2.0f, -4.0f );
		BcVec2d CoolDownBarSize = BcVec2d( CoolDownFraction * ( Size.x() - 4.0f ), 2.0f );
		RsColour CoolDownColour = RsColour::PURPLE;

		Canvas->drawSprite( CoolDownBarPosition, CoolDownBarSize, 0, CoolDownColour * RsColour( 1.0f, 1.0f, 1.0f, 0.75f ), 3 );
	}
}
//////////////////////////////////////////////////////////////////////////
// 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 );
}
	virtual void drawContactPoint(const btVector3& PointOnB,const btVector3& normalOnB,btScalar distance,int lifeTime,const btVector3& color)
	{
		ScnDebugRenderComponent::pImpl()->drawLine(
			ScnPhysicsFromBullet( PointOnB ) - ScnPhysicsFromBullet( normalOnB ),
			ScnPhysicsFromBullet( PointOnB ) + ScnPhysicsFromBullet( normalOnB ),
			RsColour( color.x(), color.y(), color.z(), 1.0f ) );
	}
//////////////////////////////////////////////////////////////////////////
// allocParticle
BcBool ScnParticleSystemComponent::allocParticle( ScnParticle*& pParticle )
{
	// We can't be allocating whilst we're updating.
	BcAssert( UpdateFence_.count() == 0 );

	// TODO: Perhaps a free list of indices? Reordering of dead particles?
	//       Either way I want the update to be cache friendly.
	for( BcU32 Idx = 0; Idx < NoofParticles_; ++Idx )
	{
		BcU32 RealIdx = ( Idx + PotentialFreeParticle_ ) % NoofParticles_; // Slow. If we use powers of 2, we can &.
		ScnParticle* pPotentiallyFreeParticle = &pParticleBuffer_[ RealIdx ];

		if( pPotentiallyFreeParticle->Alive_ == BcFalse )
		{
			pParticle = pPotentiallyFreeParticle;

			// Prevent it being rendered for the first frame.
			pParticle->Scale_ = MaVec2d( 0.0f, 0.0 );
			pParticle->Colour_ = RsColour( 0.0f, 0.0f, 0.0f, 0.0f );

			++PotentialFreeParticle_;
			return BcTrue;
		}
	}
	
	return BcFalse;
}
//////////////////////////////////////////////////////////////////////////
// setActive
void GaStructureComponent::setActive( BcBool Active )
{
	Active_ = Active;

	if( Active_ )
	{
		setupTopology();
		setupHotspot();		
	}

	auto Sprite = getComponentByType< ScnSpriteComponent >();
	if( Sprite )
	{
		Sprite->setColour( Active_ ? RsColour( 0.0f, 0.5f, 0.0f, 1.0f ) : RsColour( 0.5f, 0.0f, 0.0f, 1.0f ) );
	}
}
	virtual void drawLine(const btVector3& from,const btVector3& to,const btVector3& color)
	{
		ScnDebugRenderComponent::pImpl()->drawLine(
			MaVec3d( from.x(), from.y(), from.z() ),
			MaVec3d( to.x(), to.y(), to.z() ),
			RsColour( color.x(), color.y(), color.z(), 1.0f ) );
	}
Beispiel #10
0
//////////////////////////////////////////////////////////////////////////
// initialise
void ScnLightComponent::initialise()
{
	Super::initialise();

	Type_ = scnLT_POINT;
	AmbientColour_ = RsColour( 0.0f, 0.0f, 0.0f, 1.0f );
	DiffuseColour_ = RsColour::WHITE;
	
	createAttenuationValues( 64.0f, 256.0f, 1024.0f );
}
RsColour RsTextureWinGL::GetPixel( BtU32 x, BtU32 y, BtU8& red, BtU8& green, BtU8& blue, BtU8 &alpha )
{
	// Cache each mipmap
	LBaMipMapFileData& mipMap = m_pMipmaps[0];

	if (m_pFileData->m_flags & (RsTF_Indexed | RsTF_IndexedAlpha))
	{
		BtU8* pAddress = mipMap.m_pTextureMemory;

		BtU32 paletteSize = 0;

		if (m_pFileData->m_flags & RsTF_Indexed)
		{
			paletteSize = 3;
			pAddress += 256 * paletteSize;
		}
		else
		{
			paletteSize = 4;
			pAddress += 256 * paletteSize;
		}

		pAddress += x + (y * mipMap.m_nPitch);

		BtU32 paletteIndex = (*pAddress) * paletteSize;

		// Get the colour from the palette
		BtU8* pPalette = mipMap.m_pTextureMemory + paletteIndex;

		alpha = *(pAddress + 3);
		blue = *(pPalette + 2);
		green = *(pPalette + 1);
		red = *(pPalette + 0);
	}
	else if (m_pFileData->m_flags & RsTF_Alpha)
	{
		BtU8* pAddress = mipMap.m_pTextureMemory + (x * 4) + (y * mipMap.m_nPitch);

		alpha = *(pAddress + 3);
		red = *(pAddress + 2);
		green = *(pAddress + 1);
		blue = *(pAddress + 0);
	}
	else
	{
		BtU8* pAddress = mipMap.m_pTextureMemory + (x * 3) + (y * mipMap.m_nPitch);

		alpha = *(pAddress + 3);
		red = *(pAddress + 2);
		green = *(pAddress + 1);
		blue = *(pAddress + 0);
	}
	return RsColour(red, green, blue, alpha);
}
void SbWaxGraph::Setup( BaArchive *pGameArchive )
{
    // Cache our model
    m_pWaxModel = pGameArchive->GetNode( "cube" );

    // Cache the main shader
    m_pShader = pGameArchive->GetShader( "shader" );
    m_pShader->SetDirectionalLight( MtVector3( 0, 0, 0 ) );
    m_pShader->SetAmbient( RsColour( 1.0f, 1.0f, 1.0f, 1.0f ) );

    m4Rotate.SetIdentity();

    for( BtU32 i=0; i<items; i++ )
    {
        v3Values[i] = MtVector3( 0, 0, 0 );
    }
}
void SbModel::Render()
{
	// Set the light direction
	MtVector3 v3LightDirection( -0.5f, 0, 0 );

	m_pShader->SetDirectionalLight( v3LightDirection );

	// Set the lights ambient level
	m_pShader->SetAmbient( RsColour( 0.8f, 0.8f, 0.8f, 0 ) );

	// Apply the shader
	m_pShader->Apply();

    for( BtU32 i=0; i<MaxControllers; i++ )
    {
        if( m_pCubes[i] )
        {
            m_pCubes[i]->Render();
        }
	}
}
void HlView::RenderMenu()
{
	BtU32 numItems = m_items.GetNumItems();

	for( BtU32 i=0; i<numItems; i++ )
	{
		// Cache each item
		HlMenuItems &item = m_items[i];

		if( item.m_isVisible )
		{
			RsColour colour( RsColour::WhiteColour() );

			colour.Alpha( item.m_fade );
			
			if( item.m_isHeld == BtTrue )
			{
				colour = RsColour( item.m_fadeWhenSelected, item.m_fadeWhenSelected, item.m_fadeWhenSelected, 1.0f );
			}

			if( ShJoystick::IsConnected() == BtTrue )
			{
				if( item.m_joystick != HlMenuJoystick_No )
				{
					// Render each item
					item.m_pSprite->Render( BtFalse, item.m_v2Position, item.m_v2Dimension, item.m_index, 0, colour, MaxSortOrders-1 );
				}
			}
			else
			{
				if( item.m_joystick != HlMenuJoystick_Yes )
				{
					// Render each item
					item.m_pSprite->Render( BtFalse, item.m_v2Position, item.m_v2Dimension, item.m_index, 0, colour, MaxSortOrders-1 );
				}
			}
		}
	}
}
Beispiel #15
0
//////////////////////////////////////////////////////////////////////////
// Ctor
ScnViewComponent::ScnViewComponent():
	X_( 0 ),
	Y_( 0 ),
	Width_( 1.0f ),
	Height_( 1.0f ),
	Near_( 0.1f ),
	Far_( 1000.0f ),
	HorizontalFOV_( 0.0f ),
	VerticalFOV_( 0.0f ),
	ClearColour_( RsColour( 0.0f, 0.0f, 0.0f, 0.0f ) ),
	EnableClearColour_( BcTrue ),
	EnableClearDepth_( BcTrue ),
	EnableClearStencil_( BcTrue ),
	RenderMask_( 0 ),
	RenderTarget_( nullptr ),
	DepthStencilTarget_( nullptr )
{
	ViewUniformBuffer_ = nullptr;
	RenderTarget_ = nullptr;
	DepthStencilTarget_ = nullptr;

	setRenderMask( 1 );
}
// virtual
void RsFlashWinGL::Render( const MtVector2& v2StartPosition, BtU32 sortOrder )
{
	MtVector2 v2Dimension( 0, 0 );

	RsTexture *pTexture = BtNull;

	cJSON *pFames = cJSON_GetObjectItem( m_pJSON, "frames" );

	cJSON *pCommands = cJSON_GetArrayItem( pFames, m_currentFrame );

	if( pCommands == BtNull )
	{
		m_currentFrameTime = 0;
		
		m_currentFrame = 0;

		pCommands = cJSON_GetArrayItem( pFames, m_currentFrame );
	}

	RsColour colour( 1.0f, 1.0f, 1.0f, 1.0f );

	BtU32 numCommands = cJSON_GetArraySize( pCommands );

	for( BtU32 command=0; command<numCommands; command=command + 2 )
	{
		// Cache the command
		cJSON *pCommand = cJSON_GetArrayItem( pCommands, command );
		BtChar *pCommandString = pCommand->valuestring;

		// Cache the object
		cJSON *pObject = cJSON_GetArrayItem( pCommands, command + 1 );

		if( BtStrCompare( pCommandString, "frameInfo" ) )
		{
			cJSON *pFrameIndex = cJSON_GetObjectItem( pObject, "frameIndex" );

			BtU32 frameIndex = pFrameIndex->valueint;
			(void)frameIndex;

			int a=0;
			a++;
		}
		else if( BtStrCompare( pCommandString, "texture" ) )
		{
			cJSON *pTextureIndex = cJSON_GetObjectItem( pObject, "textureIndex" );

			// Get the texture index
			BtU32 textureIndex = pTextureIndex->valueint - 1;

			pTexture = m_pFileData->m_pTextures[textureIndex];

			colour = RsColour( 1.0f, 1.0f, 1.0f, 1.0f );
		}
		else if( BtStrCompare( pCommandString, "colour" ) )
		{
			// Get the colour object
			cJSON *pColour = cJSON_GetObjectItem( pObject, "colourArray" );

			cJSON *pR = cJSON_GetArrayItem( pColour, 0 );
			BtFloat r = (BtFloat)pR->valuedouble;

			cJSON *pG = cJSON_GetArrayItem( pColour, 1 );
			BtFloat g = (BtFloat)pG->valuedouble;

			cJSON *pB = cJSON_GetArrayItem( pColour, 2 );
			BtFloat b = (BtFloat) pB->valuedouble;

			colour = RsColour( r, g, b, 1.0f );
		}
		else if( BtStrCompare( pCommandString, "vertex" ) )
		{
			// Get the vertex object
			cJSON *pVertex = cJSON_GetObjectItem( pObject, "vertex" );

			// Cache the number of vertex
			BtU32 numVertex = cJSON_GetArraySize( pVertex );

			// Extract the vertex
			MtVector2 coords[4];

			for( BtU32 vertexIndex=0; vertexIndex<numVertex; vertexIndex++ )
			{
				// Cache each set of coordinates
				cJSON *pCoordinates = cJSON_GetArrayItem( pVertex, vertexIndex );

				cJSON *pX = cJSON_GetObjectItem( pCoordinates, "positionx" );
				cJSON *pY = cJSON_GetObjectItem( pCoordinates, "positiony" );

				coords[vertexIndex].x = (BtFloat)pX->valueint / 20;
				coords[vertexIndex].y = (BtFloat)pY->valueint / 20;
			}

			{
				// Cache the impl
				RsImplWinGL *pImpl = (RsImplWinGL*)RsImpl::pInstance();

				// Cache the render target
				RsRenderTarget *pRenderTarget = RsRenderTarget::GetCurrent();

				// Cache the camera
				RsCamera camera = pRenderTarget->GetCamera();

				// Cache the display width and height
				BtFloat Width  = (BtFloat)camera.GetViewport().m_width;
				BtFloat Height = (BtFloat)camera.GetViewport().m_height;

				// Cache the display width and height
				BtFloat textureWidth  = (BtFloat)pTexture->GetWidth();
				BtFloat textureHeight = (BtFloat)pTexture->GetHeight();

				// Cache the display width and height
				BtFloat fScaleWidth  = 1.0f / Width;
				BtFloat fScaleHeight = 1.0f / Height;

				// Allocate vertex
				RsVertex3 *pStartVertex = pImpl->StartVertex();

				// Set the start vertex
				RsVertex3 *pVertex = pStartVertex;

				RsVertex3 *pQuad = pVertex;

				BtFloat minU = 1.0f / textureWidth;
				BtFloat minV = 1.0f / textureHeight;
				BtFloat maxU = 1.0f - minU;
				BtFloat maxV = 1.0f - minV;

				/*
				coords[0].y = Height - coords[0].y;
				coords[1].y = Height - coords[1].y;
				coords[2].y = Height - coords[2].y;
				coords[3].y = Height - coords[3].y;
				*/

				// Copy these into vertex
				pVertex->m_v3Position = MtVector3(coords[0].x, coords[0].y, 0.1f );
				pVertex->m_v2UV = MtVector2( minU, minV );
				++pVertex;

				pVertex->m_v3Position = MtVector3(coords[1].x, coords[1].y, 0.1f );
				pVertex->m_v2UV = MtVector2( maxU, minV );
				++pVertex;

				pVertex->m_v3Position = MtVector3(coords[2].x, coords[2].y, 0.1f );
				pVertex->m_v2UV = MtVector2( minU, maxV );
				++pVertex;

				pVertex->m_v3Position = MtVector3(coords[3].x, coords[3].y, 0.1f );
				pVertex->m_v2UV = MtVector2( maxU, maxV );
				++pVertex;

				v2Dimension.x = MtMax( v2Dimension.x, coords[1].x - coords[0].x );
				v2Dimension.y = MtMax( v2Dimension.y, coords[2].y - coords[0].y );

				// Scale the position to local screen space -1 to 1
				for( BtU32 i=0; i<4; i++ )
				{
					// Set the colour
					pQuad[ i ].m_colour = colour.asARGB();

					// Use the start position
					pQuad[ i ].m_v3Position.x += v2StartPosition.x;
					pQuad[ i ].m_v3Position.y += v2StartPosition.y;

					// Flip the y
					pQuad[ i ].m_v3Position.y = Height - pQuad[ i ].m_v3Position.y;

					pQuad[ i ].m_v3Position.x -= 0.5f;
					pQuad[ i ].m_v3Position.y -= 0.5f;

					// Scale from 0..width to 0..1
					pQuad[ i ].m_v3Position.x *= fScaleWidth;
					pQuad[ i ].m_v3Position.y *= fScaleHeight;

					// Scale from 0..1 to 0..2
					pQuad[ i ].m_v3Position.x *= 2.0f;
					pQuad[ i ].m_v3Position.y *= 2.0f;

					// Translate from 0..2 to -1..1
					pQuad[ i ].m_v3Position.x -= 1.0f;
					pQuad[ i ].m_v3Position.y -= 1.0f;
				}

				// Setup the primitive
				RsPrimitiveWinGL *primitive = pImpl->AddPrimitive();
				primitive->m_primitiveType = GL_TRIANGLE_STRIP;
				primitive->m_numVertex     = 4;
				primitive->m_nStartVertex  = pImpl->GetCurrentVertex();

				// End the current vertex
				pImpl->EndVertex( 4 );

				// Make a new font renderable
				RsTextureRenderable *pTextureRenderable = pImpl->AddTexture();
				pTextureRenderable->m_pTexture  = (RsTextureWinGL*)pTexture;
				pTextureRenderable->m_pVertex   = pStartVertex;
				pTextureRenderable->m_primitive = primitive;

				// Validate the shader
				BtAssert( pTextureRenderable->m_pShader != BtNull );

				// Add the font to the renderable list
				RsRenderTargetWinGL *pCurrentRenderTarget = (RsRenderTargetWinGL*)RsRenderTarget::GetCurrent();
				pCurrentRenderTarget->Add( sortOrder, pTextureRenderable );
			}
		}
	}	

	(void)v2Dimension;
	int a=0;
	a++;
}
Beispiel #17
0
////////////////////////////////////////////////////////////////////////////////
// render
//virtual
void GaGameComponent::render( ScnCanvasComponentRef Canvas )
{
	BcScopedLock< BcMutex > Lock( EmoteLock_ );

	Canvas->setMaterialComponent( EmoteMaterialComponent_ );
	pParent()->setMaterialComponentParams( EmoteMaterialComponent_, BcMat4d() );

	TEmoteList::iterator It( EmoteList_.begin() );

	while( It != EmoteList_.end() )
	{
		TEmote& Emote = (*It);
		Canvas->drawSpriteCenteredUp3D( Emote.Position_, BcVec2d( 64.0f, -64.0f ), Emote.Idx_, RsColour( 1.0f, 1.0f, 1.0f, Emote.Timeleft_ ), 10 );
		++It;
	}
}
Beispiel #18
0
//////////////////////////////////////////////////////////////////////////
// GaGameComponent
//virtual
void GaGameComponent::update( BcReal Tick )
{
	BcU32 Param = FontMaterial_->findParameter( "aAlphaTestStep" );
	FontMaterial_->setParameter( Param, BcVec2d( 0.4f, 0.5f ) );

	if( GameState_ == GS_PLAYING )
	{
		pSimulator_->tick( Tick );

		if( pSimulator_->getTimeOut() > 5.0f )
		{
			GameState_ = GS_TIMEOUT;
		}

		if( pSimulator_->getUnitCount( TeamID_ ) == 0 ||
			pSimulator_->getUnitCount( 1 - TeamID_ ) == 0 )
		{
			GameState_ = GS_OVER;
		}


		if( !Networked_ )
		{
			AITickTime_ -= Tick;

			if( AITickTime_ < 0.0f )
			{
				pSimulator_->runAI( 1 - TeamID_ );
				AITickTime_ = AITickMaxTime_;
			}
		}
	}
	
	//if( TeamID_ == 0 )
	{
		if( CanvasComponent_.isValid() )
		{
			OsClient* pClient = OsCore::pImpl()->getClient( 0 );
			BcReal HW = static_cast< BcReal >( pClient->getWidth() ) / 2.0f;
			BcReal HH = static_cast< BcReal >( pClient->getHeight() ) / 2.0f;
			BcReal AspectRatio = HW / HH;

			BcMat4d Ortho;
			Ortho.orthoProjection( -HW, HW, HH, -HH, -1.0f, 1.0f );

			// Clear canvas and push projection matrix.
			CanvasComponent_->clear();   

			CanvasComponent_->pushMatrix( Ortho );

			CanvasComponent_->setMaterialComponent( BackgroundMaterial_ );
			CanvasComponent_->drawSpriteCentered( BcVec2d( 0.0f, 0.0f ), BcVec2d( 1280.0f, 720.0f ), 0, RsColour( 1.0f, 1.0f, 1.0f, 1.0f ), 0 );

			CanvasComponent_->setMaterialComponent( SpriteSheetMaterials_[ 0 ] );
			pSimulator_->render( CanvasComponent_, 0 );
			CanvasComponent_->setMaterialComponent( SpriteSheetMaterials_[ 1 ] );
			pSimulator_->render( CanvasComponent_, 1 );

			// Find unit over mouse.
			GaGameUnitIDList SelectionList;
			if( MouseDown_ )
			{
				if( BoxSelection_ )
				{
					pSimulator_->findUnits( SelectionList, StartGameCursorPosition_, EndGameCursorPosition_, BcErrorCode, BcErrorCode );
				}
			}
			else
			{
				pSimulator_->findUnits( SelectionList, GameCursorPosition_, 0.8f, BcErrorCode, BcErrorCode );
				while( SelectionList.size() > 1 )
				{
					SelectionList.pop_back();
				}
			}

			for( BcU32 Idx = 0; Idx < UnitSelection_.size(); ++Idx )
			{
				SelectionList.push_back( UnitSelection_[ Idx ] );
			}

			CanvasComponent_->setMaterialComponent( HUDMaterial_ );
			pSimulator_->renderHUD( CanvasComponent_, SelectionList, TeamID_ );
		}

		switch( GameState_ )
		{
		case GS_PLAYING:
			{
				// Draw cursor.
				CanvasComponent_->setMaterialComponent( HUDMaterial_ );
				CanvasComponent_->drawSpriteCentered( BcVec2d( CursorPosition_.x(), CursorPosition_.y() ), BcVec2d( 64.0f, 64.0f ), 1, AttackMove_ ? RsColour::RED : RsColour::WHITE, 10 );

				// Draw selection box.
				if( MouseDown_ && BoxSelection_ ) 
				{
					BcVec2d Min = BcVec2d( StartGameCursorPosition_.x(), StartGameCursorPosition_.y() ) * 32.0f;
					BcVec2d Max = BcVec2d( GameCursorPosition_.x(), GameCursorPosition_.y() ) * 32.0f;
					CanvasComponent_->drawSprite( Min, Max - Min, 0, RsColour::GREEN * RsColour( 1.0f, 1.0f, 1.0f, 0.1f ), 11 );
				}

				std::string Text0 = TeamID_ == 0 ? "YOU ARE RED!" : "YOU ARE BLUE!";
				BcVec2d TextSize0 = Font_->draw( CanvasComponent_, BcVec2d( 0.0f, 0.0f ), Text0, RsColour::WHITE, BcTrue );
				Font_->draw( CanvasComponent_, ( -TextSize0 / 2.0f ) + BcVec2d( 0.0f, -350.0f ), Text0, TeamID_ == 0 ? RsColour::RED : RsColour::BLUE, BcFalse );

			}
			break;

		case GS_TIMEOUT:
			{
				std::string Text0 = "Connection timed out :(";
				std::string Text1 = "Press ESC to Quit.";
				BcVec2d TextSize0 = Font_->draw( CanvasComponent_, BcVec2d( 0.0f, 0.0f ), Text0, RsColour::WHITE, BcTrue );
				Font_->draw( CanvasComponent_, ( -TextSize0 / 2.0f ) + BcVec2d( 0.0f, -64.0f ), Text0, RsColour::WHITE, BcFalse );
				BcVec2d TextSize1 = Font_->draw( CanvasComponent_, BcVec2d( 0.0f, 0.0f ), Text1, RsColour::WHITE, BcTrue );
				Font_->draw( CanvasComponent_, ( -TextSize1 / 2.0f ) + BcVec2d( 0.0f, 64.0f ), Text1, RsColour::WHITE, BcFalse );
			}
			break;

		case GS_OVER:
			{
				if( pSimulator_->getUnitCount( TeamID_ ) > 0 )
				{
					std::string Text0 = "You Won! :D";
					std::string Text1 = "Press ESC to Quit.";
					BcVec2d TextSize0 = Font_->draw( CanvasComponent_, BcVec2d( 0.0f, 0.0f ), Text0, RsColour::WHITE, BcTrue );
					Font_->draw( CanvasComponent_, ( -TextSize0 / 2.0f ) + BcVec2d( 0.0f, -64.0f ), Text0, RsColour::WHITE, BcFalse );
					BcVec2d TextSize1 = Font_->draw( CanvasComponent_, BcVec2d( 0.0f, 0.0f ), Text1, RsColour::WHITE, BcTrue );
					Font_->draw( CanvasComponent_, ( -TextSize1 / 2.0f ) + BcVec2d( 0.0f, 64.0f ), Text1, RsColour::WHITE, BcFalse );
				}
				else
				{
					std::string Text0 = "You Lost! :<";
					std::string Text1 = "Press ESC to Quit.";
					BcVec2d TextSize0 = Font_->draw( CanvasComponent_, BcVec2d( 0.0f, 0.0f ), Text0, RsColour::WHITE, BcTrue );
					Font_->draw( CanvasComponent_, ( -TextSize0 / 2.0f ) + BcVec2d( 0.0f, -64.0f ), Text0, RsColour::WHITE, BcFalse );
					BcVec2d TextSize1 = Font_->draw( CanvasComponent_, BcVec2d( 0.0f, 0.0f ), Text1, RsColour::WHITE, BcTrue );
					Font_->draw( CanvasComponent_, ( -TextSize1 / 2.0f ) + BcVec2d( 0.0f, 64.0f ), Text1, RsColour::WHITE, BcFalse );
				}
			}
			break;
		}
	}


}
Beispiel #19
0
//////////////////////////////////////////////////////////////////////////
// renderSelectionHUD
void GaGameUnit::renderSelectionHUD( ScnCanvasComponentRef Canvas, BcFixed TimeFraction, BcU32 TeamID )
{
	if( Behaviour_ != BEHAVIOUR_DEAD )
	{
		BcU32 TextureIdx = Desc_.Type_;
		BcFixedVec2d GamePosition( getInterpolatedPosition( TimeFraction ) );
		const BcReal ScaleFactor = 32.0f;
		BcVec2d Position( GamePosition.x(), GamePosition.y() );
		BcVec2d Size( Desc_.Size_.x(), Desc_.Size_.y() );

		Position *= ScaleFactor;
		Size *= ScaleFactor;

		BcVec2d PositionA( Position + ( BcVec2d( -Size.x(), -Size.y() ) * 0.45f ) );
		BcVec2d PositionB( Position + ( BcVec2d(  Size.x(), -Size.y() ) * 0.45f ) );
		BcVec2d PositionC( Position + ( BcVec2d(  Size.x(),  Size.y() ) * 0.45f ) );
		BcVec2d PositionD( Position + ( BcVec2d( -Size.x(),  Size.y() ) * 0.45f ) );
		BcVec2d SizeA( BcVec2d(  16.0f,  16.0f ) );
		BcVec2d SizeB( BcVec2d( -16.0f,  16.0f ) );
		BcVec2d SizeC( BcVec2d( -16.0f, -16.0f ) );
		BcVec2d SizeD( BcVec2d(  16.0f, -16.0f ) );

		// Draw selection marker.
		RsColour MarkerColour = TeamID == TeamID_ ? ( RsColour::WHITE ) : ( RsColour::RED ) * RsColour( 1.0f, 1.0f, 1.0f, 0.75f );
		Canvas->drawSpriteCentered( PositionA, SizeA, 2, MarkerColour, 3 );
		Canvas->drawSpriteCentered( PositionB, SizeB, 2, MarkerColour, 3 );
		Canvas->drawSpriteCentered( PositionC, SizeC, 2, MarkerColour, 3 );
		Canvas->drawSpriteCentered( PositionD, SizeD, 2, MarkerColour, 3 );
	}
}
Beispiel #20
0
void HlMouse::Render( MtVector2 v2Dimension )
{
	// The dimension is passed into this function so we can render to rendertarget other than the screen
	if(UiKeyboard::pInstance()->IsPressed(UiKeyCode_F11))
	{
		return;
	}
	
	BtFloat width = RsUtil::GetDimension().x;
	BtFloat height = RsUtil::GetDimension().y;

    if( ApConfig::IsWin() )
	{
		static BtBool isReset = BtTrue;
		if( isReset )
		{
			isReset = BtFalse;

			// Render the mouse pointers
			for (BtU32 i = 0; i < MaxTouches; i++)
			{
				m_v2Position[i] = ShTouch::GetPosition(i);
				m_v2Position[i].x = m_v2Position[i].x / width  * v2Dimension.x;
				m_v2Position[i].y = m_v2Position[i].y / height * v2Dimension.y;
			}
		}

		// Render the mouse pointers
		for( BtU32 i = 0; i < MaxTouches; i++ )
		{
			if( ShTouch::IsHeld(i) )
			{
				m_isVisible[i] = BtTrue;
			}

			MtVector2 v2Position = ShTouch::GetPosition(i);
			v2Position.x = v2Position.x / width  * v2Dimension.x;
			v2Position.y = v2Position.y / height * v2Dimension.y;
			MtVector2 v2Delta = m_v2Position[i] - v2Position;

			if (v2Delta.GetLength() )
			{
				m_isVisible[i] = BtTrue;
			}
			
			if( m_isVisible[i] )
			{
				BtFloat alpha = 1.0f;

				if( ShTouch::IsHeld(i) == BtFalse )
				{
					alpha = 0.25f;
				}
				else
				{
					alpha = 1.0f;
				}

				const BtU32 sprite = 1;
				MtVector2 v2Dimension = m_pSprite->GetDimension( sprite );

				v2Position.x -= v2Dimension.x * ( 0.40f * m_scalar );
				v2Position.y -= v2Dimension.y * ( 0.15f * m_scalar );

				m_pSprite->Render( BtFalse,
					v2Position,
					v2Dimension * m_scalar,
					sprite,
					0,
					RsColour(1.0f, 1.0f, 1.0f, alpha),
					MaxSortOrders - 1 );
			}
		}
	}
}
Beispiel #21
0
void HlDebug::Render()
{
	if( !ApConfig::IsDebug() )
	{
		return;
	}

	BtU32 numItems = m_items.GetNumItems();
	
	MtVector2 v2Position( 0, 0 );
    MtVector2 v2Dimension( 0, 0 );

	for( BtU32 i=0; i<numItems; i++ )
	{
		HlItem &item = m_items[i];

		if( !IsHidden(item) )
		{
			RsColour textColour = RsColour::WhiteColour();
			if( item.m_isReadOnly )
			{
				textColour = RsColour( 0.7f, 0.7f, 0.7f, 1.0f );
			}

			BtChar text[2048];
			sprintf( text, "" );

			for(BtU32 j = 0; j < GetNumParents(&item) * 4; j++)
			{
				sprintf( text + strlen(text), " ");
			}

			if(item.m_type == HlDebugEnum )
			{
				BtU32 current = *item.m_pEnum;

				sprintf( text + strlen(text), "%s ", item.m_name );

				BtU32 index = 0;

				BtChar *pStr = item.m_pEnumString;
				while( pStr )
				{
					BtChar temp[32];
					BtStrCopy( temp, 32, pStr, BtStrLength( pStr ) );
					BtChar *eol = BtStrStr(temp, ";");
					if( eol )
					{
						*eol = 0;
						pStr = BtStrStr(pStr, ";") + 1;
					}
					else
					{
						pStr = 0;
					}
	
					if(current == index)
					{
						sprintf(text + strlen(text), "%s", temp);
					}
					++index;
				}
			}
			else if(item.m_type == HlDebugSave )
			{
				sprintf(text + strlen(text), "Save");
			}
			else if( item.m_type == HlDebugNode )
			{
				sprintf( text + strlen(text), "%s", item.m_name);

				if( item.m_isCollapsed )
				{
					sprintf( text + strlen(text), "+" );
				}
				else
				{
					sprintf(text + strlen(text), "-" );
				}
			}
			else if( item.m_type == HlDebugFloat )
			{
				BtFloat value = *item.m_pFloat;
				
				// Do the conversion
				if( item.m_unitsSystem == HLDebugKnots )
				{
					value = MtMetersPerSecondToKnots( value );
					sprintf(text + strlen(text), "%s %.2fKnts", item.m_name, value);
				}
				else
				{
					sprintf( text + strlen(text), "%s %.2f", item.m_name, value );
				}
			}
			else if( item.m_type == HlDebugInteger )
			{
				sprintf( text + strlen(text), "%s %d", item.m_name, *item.m_pInteger );
			}
			else if(item.m_type == HlDebugBool )
			{
				if( *item.m_pBool )
				{
					sprintf(text + strlen(text), "%s True", item.m_name );
				}
				else
				{
					sprintf(text + strlen(text), "%s False", item.m_name );
				}
			}
			else if( item.m_type == HlDebugVector )
			{
				sprintf(text + strlen(text), "%s %.2f %.2f %.2f", item.m_name, item.m_pVector->x, item.m_pVector->y, item.m_pVector->z );
			}
			else if( item.m_type == HlDebugColour )
			{
				sprintf(text + strlen(text), "%s %.2f %.2f %.2f", item.m_name, item.m_pColour->Red(), item.m_pColour->Green(), item.m_pColour->Blue() );
			}
			else if( item.m_type == HlDebugFPS )
			{
				sprintf( text + strlen(text), "FPS %.2f", RsUtil::GetFPS() );
			}

			if( DebugIndex == i )
			{
				sprintf( text + strlen(text), "*" );
			}
			
			MtVector2 v2FontDimension = HlFont::GetDimension( text );

			v2Dimension.x = MtMax( v2Dimension.x, v2Position.x + v2FontDimension.x + 15.0f );
			v2Dimension.y = MtMax( v2Dimension.y, v2Position.y + v2FontDimension.y + 15.0f );

			HlFont::Render(v2Position, text, textColour, MaxSortOrders - 1);
			v2Position.y += 15.0f;
		}
	}
	
	// Display the list of archives
	BtLinkedList<BaArchiveNode> archives = BaArchive::GetArchives();
	BaArchiveNode *pCurrent = archives.pHead();
	while( pCurrent )
	{
		BtChar text[2048];
		sprintf(text, pCurrent->m_pArchive->GetFilename());
		MtVector2 v2FontDimension = HlFont::GetDimension(text);
		v2Dimension.x = MtMax(v2Dimension.x, v2Position.x + v2FontDimension.x + 30.0f);
		v2Dimension.y = MtMax(v2Dimension.y, v2Position.y + v2FontDimension.y + 30.0f);
		HlFont::Render(v2Position, text, RsColour(0.7f, 0.7f, 0.7f, 1.0f), MaxSortOrders - 1);
		v2Position.y += 15.0f;
		pCurrent = pCurrent->pNext();
	}
	
	HlDraw::RenderQuad( MtVector2( 0, 0 ), v2Dimension, RsColour( 0.1f, 0.1f, 0.1f, 1.0f ), MaxSortOrders-1 );
}
Beispiel #22
0
void HlView::RenderMenu()
{
	BtU32 numItems = m_items.GetNumItems();

	for( BtU32 i=0; i<numItems; i++ )
	{
		// Cache each item
		HlMenuItems &item = m_items[i];

		if( item.m_isVisible )
		{
			// Setup the colour
			RsColour colour( RsColour::WhiteColour() );
			colour.Alpha( item.m_fade );

			if (item.m_pSprite)
			{
				// Get the index of the sprite
				BtU32 index = item.m_spriteIndex;

				if (item.m_isHeld == BtTrue)
				{
					if (item.m_selectedSpriteIndex != -1)
					{
						index = item.m_selectedSpriteIndex;
					}
					else
					{
						colour = RsColour(item.m_fadeWhenSelected, item.m_fadeWhenSelected, item.m_fadeWhenSelected, 1.0f);
					}
				}

				if (ShJoystick::IsConnected() == BtTrue)
				{
					if (item.m_joystick != HlMenuJoystick_No)
					{
						// Render each item
						item.m_pSprite->Render(BtFalse, item.m_v2Position, item.m_v2Dimension, index, 0, colour, MaxSortOrders - 1);
					}
				}
				else
				{
					if (item.m_joystick != HlMenuJoystick_Yes)
					{
						// Render each item
						item.m_pSprite->Render(BtFalse, item.m_v2Position, item.m_v2Dimension, index, 0, colour, MaxSortOrders - 1);
					}
				}
			}
			
			//if( ApConfig::IsDebug() )
			{
				RsColour light(1.0f, 1.0f, 1.0f, 0.25f);

				if( &item == m_pCurrentMenuItem)
				{
					light = RsColour(1.0f, 0.7f, 0.5f, 0.8f);
				}
				HlDraw::RenderRotatedQuad( item.m_v2Position, item.m_v2Dimension, item.m_angle, light, MaxSortOrders - 1);
			}
		}
        else
        {
            HlDraw::RenderQuad( item.m_v2Position, item.m_v2Dimension, RsColour( 1.0f, 0, 0, 0.5f), MaxSortOrders-1 );
        }
	}
}
//////////////////////////////////////////////////////////////////////////
// drawGrid
void ScnDebugRenderComponent::drawGrid( const MaVec3d& Position, const MaVec3d& Size, BcF32 StepSize, BcF32 SubDivideMultiple, BcU32 Layer )
{
	BcU32 NoofAxis = ( Size.x() > 0 ? 1 : 0  ) + ( Size.y() > 0 ? 1 : 0  ) + ( Size.z() > 0 ? 1 : 0 );
	BcAssertMsg( NoofAxis == 2, "Only supports 2 axis in the grid!" );
	
	// Determine which axis to draw along.
	MaVec3d XAxis;
	MaVec3d YAxis;
	BcF32 XSize = 0.0f;
	BcF32 YSize = 0.0f;

	if( Size.x() > 0.0f )
	{
		XAxis = MaVec3d( Size.x(), 0.0f, 0.0f );
		XSize = Size.x();
		if( Size.y() > 0.0f )
		{
			YAxis = MaVec3d( 0.0f, Size.y(), 0.0f );
			YSize = Size.y();
		}
		else
		{
			YAxis = MaVec3d( 0.0f, 0.0f, Size.z() );
			YSize = Size.z();
		}
	}
	else
	{
		XAxis = MaVec3d( 0.0f, Size.y(), 0.0f );
		YAxis = MaVec3d( 0.0f, 0.0f, Size.z() );
		XSize = Size.y();
		YSize = Size.z();
	}

	// Normalise.
	XAxis.normalise();
	YAxis.normalise();

	while( StepSize < XSize && StepSize < YSize )
	{
		// Draw grid.
		for( BcF32 X = 0.0f; X <= XSize; X += StepSize )
		{
			MaVec3d A1( Position + ( XAxis * X ) + ( YAxis *  YSize ) );
			MaVec3d B1( Position + ( XAxis * X ) + ( YAxis * -YSize ) );
			MaVec3d A2( Position + ( XAxis * -X ) + ( YAxis *  YSize ) );
			MaVec3d B2( Position + ( XAxis * -X ) + ( YAxis * -YSize ) );
			drawLine( A1, B1, RsColour( 1.0f, 1.0f, 1.0f, 0.05f ), Layer );
			drawLine( A2, B2, RsColour( 1.0f, 1.0f, 1.0f, 0.05f ), Layer );
		}

		for( BcF32 Y = 0.0f; Y <= YSize; Y += StepSize )
		{
			MaVec3d A1( Position + ( XAxis *  YSize ) + ( YAxis * Y ) );
			MaVec3d B1( Position + ( XAxis * -YSize ) + ( YAxis * Y ) );
			MaVec3d A2( Position + ( XAxis *  YSize ) + ( YAxis * -Y ) );
			MaVec3d B2( Position + ( XAxis * -YSize ) + ( YAxis * -Y ) );
			drawLine( A1, B1, RsColour( 1.0f, 1.0f, 1.0f, 0.05f ), Layer );
			drawLine( A2, B2, RsColour( 1.0f, 1.0f, 1.0f, 0.05f ), Layer );
		}

		StepSize *= SubDivideMultiple;
	}
}