Ejemplo n.º 1
0
	virtual void ProcessEvent( EFlowEvent event, SActivationInfo *pActInfo )
	{
		switch (event)
		{
		case eFE_Initialize:
			if (pActInfo->pGraph->GetGraphEntity(0) == 0 && pActInfo->pGraph->GetGraphEntity(1) == 0)
				m_nFaderOffset = MFX_FADER_OFFSET;
			else
				m_nFaderOffset = GAME_FADER_OFFSET;

			if (gEnv->pCryPak->GetLvlResStatus())
			{
				const string& texName = GetPortString(pActInfo, EIP_TextureName);
				if (texName.empty() == false)
				{
					ITexture* pTexture = CHUDFader::LoadTexture(texName.c_str());
					if (pTexture)
						pTexture->Release();
				}
			}

			if (m_bNeedFaderStop)
			{
				StopFader(pActInfo);
				m_bPlaying = false;
				m_bNeedFaderStop = false;
				m_ticket = 0;
			}
			pActInfo->pGraph->SetRegularlyUpdated(pActInfo->myID, false);
			break;
		case eFE_Activate:
			{
				if (IsPortActive(pActInfo, EIP_FadeIn))
				{
					StopFader(pActInfo);
					pActInfo->pGraph->SetRegularlyUpdated(pActInfo->myID, true);
					m_direction = -1;
					StartFader(pActInfo);
					m_bPlaying = true;
					m_bNeedFaderStop = true;
					m_postSerializeTrigger = 0;
				}
				if (IsPortActive(pActInfo, EIP_FadeOut))
				{
					StopFader(pActInfo);
					pActInfo->pGraph->SetRegularlyUpdated(pActInfo->myID, true);
					m_direction = 1;
					StartFader(pActInfo);
					m_bPlaying = true;
					m_bNeedFaderStop = true;
					m_postSerializeTrigger = 0;
				}
			}
			break;
		case eFE_Update:
			{
				if (m_postSerializeTrigger)
				{
					ActivateOutput(pActInfo, m_postSerializeTrigger < 0 ? EOP_FadedIn : EOP_FadedOut, true);
					m_postSerializeTrigger = 0;
					pActInfo->pGraph->SetRegularlyUpdated(pActInfo->myID, false);
					return;
				}

				CHUDFader* pFader = GetFader(pActInfo);
				if (pFader == 0 || m_bPlaying == false)
				{
					pActInfo->pGraph->SetRegularlyUpdated(pActInfo->myID, false);	
					m_bPlaying = false;
					m_ticket = 0;
					return;
				}

				ColorF col = pFader->GetCurrentColor();
				Vec3 vCol (col.r,col.g,col.b);
				ActivateOutput(pActInfo, EOP_FadeColor, vCol);
				if (pFader->IsPlaying(m_ticket) == false)
				{
					if (m_direction < 0.0f)
					{
						ActivateOutput(pActInfo, EOP_FadedIn, true);
						pActInfo->pGraph->SetRegularlyUpdated(pActInfo->myID, false);					
						m_bNeedFaderStop = false; 
					}
					else
					{
						ActivateOutput(pActInfo, EOP_FadedOut, true);
						pActInfo->pGraph->SetRegularlyUpdated(pActInfo->myID, false);	
						m_bNeedFaderStop = true; // but needs a stop, if we're faded out (fader is still active then!)
					}
					m_bPlaying = false;
					m_ticket = 0;
				}
			}
			break;
		}
	}
Ejemplo n.º 2
0
void GameProcess::VOnInit(void)
{
    //pSkillInterface =  new SkillInterface();
    
	DialogueInterface* pDialogue = new DialogueInterface( NULL, "DialogueInterface.xml", "Dialogue.xml" );
	pDialogue->SetName( "Dialogue" );
	BaseApplication::Get()->AttachProcess( pDialogue );
	pDialogue->Release();

    Entity* pEntity = Game::CreateEntity();
    ThirdPersonCamera* pCamera = new ThirdPersonCamera();
    pCamera->SetDistanceMax( 50.0f );
    m_pCamera = pCamera;
    pEntity->AddComponent( pCamera );
    pCamera->SetClearColor( ColorF::BLACK );
    pCamera->Release();
    pCamera->SetPosition( Vector4( 2000.0f, 30.0f, 2000.0f ) );
    pCamera->SetDirection( Vector4( 0.0f, 0.0f, 1.0f ) );
    pCamera->Start();
    
    pEntity = Game::CreateEntity();
    
    
    int iWorldSize = 512;
    m_IslandData.Generate( iWorldSize, iWorldSize );
    HeightmapComponent* pComponent = new HeightmapComponent( iWorldSize, iWorldSize, m_IslandData );
    m_pHeightMapEntity = pComponent;
    //pComponent->SetTexture( "sketch.png" );
    m_IslandData.GenerateBiomes();
    ColorF* pColors = new ColorF[ iWorldSize * iWorldSize ];
    for ( int i = 0; i < iWorldSize; ++i )
    {
        for ( int j = 0; j < iWorldSize; ++j )
        {
            ColorF color;
            IslandData::Biome eBiome = m_IslandData.GetBiome( i, j );
            
            if ( eBiome == IslandData::SeaWater )
            {
                color = Color::BLUE;
            }
            
            else if ( eBiome == IslandData::FreshWater )
            {
                color = Color( 0, 191, 255 );
            }
            
            else if ( eBiome == IslandData::Grassland )
            {
                color = Color( 195, 211, 170, 255 );
            }
            
            else if ( eBiome == IslandData::Snow )
            {
                color = Color::WHITE;
            }
            
            else if ( eBiome == IslandData::Bare )
            {
                color = Color( 200, 200, 200, 255 );
            }
            
            else if ( eBiome == IslandData::Scorched )
            {
                color = Color::GREY;
            }
            
            else if ( eBiome == IslandData::Tundra )
            {
                color = Color( 220, 220, 186, 255 );
            }
            
            else if ( eBiome == IslandData::Taiga )
            {
                color = Color( 203, 211, 186, 255 );
            }
            
            else if ( eBiome == IslandData::Shrubland )
            {
                color = Color( 195, 203, 186, 255 );
            }
            
            else if ( eBiome == IslandData::TemperateDesert )
            {
                color = Color( 227, 231, 201, 255 );
            }
            
            else if ( eBiome == IslandData::TemperateRainForest )
            {
                color = Color( 163, 195, 167, 255 );
            }
            
            else if ( eBiome == IslandData::TemperateDecidousForest )
            {
                color = Color( 180, 200, 168, 255 );
            }
            
            else if ( eBiome == IslandData::TropicalRainForest )
            {
                color = Color( 155, 186, 168, 255 );
            }
            
            else if ( eBiome == IslandData::TropicalSeasonalForest )
            {
                color = Color( 168, 203, 163, 255 );
            }
            
            else if ( eBiome == IslandData::SubtropicalDesert )
            {
                color = Color( 232, 220, 198, 255 );
            }
            
            else if ( eBiome == IslandData::Unassigned )
            {
                throw "Whoops";
            }
            
            else
            {
                throw "Unhandled biome";
            }
            
            pColors[ j * iWorldSize + i ] = color;
        }
    }
    
    pComponent->GenerateHeightMap( iWorldSize, iWorldSize, m_IslandData, pColors );
    delete [] pColors;
    pEntity->AddComponent( pComponent );
    pComponent->Release();
    pComponent->Start();
    
    // Generate blend map for splatting
    unsigned int* pBlendMap = new unsigned int[ iWorldSize * iWorldSize ];
    for ( int i = 0; i < iWorldSize; ++i )
    {
        for ( int j = 0; j < iWorldSize; ++j )
        {
            Color color;
            IslandData::Biome eBiome = m_IslandData.GetBiome( i, j );
            
            if ( eBiome == IslandData::SeaWater )
            {
                color = Color::BLUE;
                color.Alpha = 0;
            }
            
            else if ( eBiome == IslandData::FreshWater )
            {
                color = Color::BLUE;
                color.Alpha = 0;
            }
            
            else if ( eBiome == IslandData::Grassland )
            {
                color = Color::GREEN;
                color.Alpha = 0;
            }
            
            else if ( eBiome == IslandData::Snow )
            {
                color = Color( 0, 0, 0, 255 );
            }
            
            else if ( eBiome == IslandData::Bare )
            {
                color = Color( 0, 0, 0 ,0 );
            }
            
            else if ( eBiome == IslandData::Scorched )
            {
                color = Color( 0, 0, 0 ,0 );
            }
            
            else if ( eBiome == IslandData::Tundra )
            {
                color = Color( 0, 0, 0 ,255 );
            }
            
            else if ( eBiome == IslandData::Taiga )
            {
                color = Color::BLACK;
                color.Alpha = 0;
            }
            
            else if ( eBiome == IslandData::Shrubland )
            {
                color = Color::BLACK;
                color.Alpha = 0;
            }
            
            else if ( eBiome == IslandData::TemperateDesert )
            {
                color = Color::RED;
                color.Alpha = 0;
            }
            
            else if ( eBiome == IslandData::TemperateRainForest )
            {
                color = Color::GREEN;
                color.Alpha = 0;
            }
            
            else if ( eBiome == IslandData::TemperateDecidousForest )
            {
                color = Color::GREEN;
                color.Alpha = 0;
            }
            
            else if ( eBiome == IslandData::TropicalRainForest )
            {
                color = Color::GREEN;
                color.Alpha = 0;
            }
            
            else if ( eBiome == IslandData::TropicalSeasonalForest )
            {
                color = Color::GREEN;
                color.Alpha = 0;
            }
            
            else if ( eBiome == IslandData::SubtropicalDesert )
            {
                color = Color::RED;
                color.Alpha = 0;
            }
            
            else if ( eBiome == IslandData::Unassigned )
            {
                throw "Whoops";
            }
            
            else
            {
                throw "Unhandled biome";
            }
            
            pBlendMap[ j * iWorldSize + i ] = color.RGBA;
        }
    }
    
    ITexture* pBlendMapTexture = IRenderer::CreateTexture();
    pBlendMapTexture->VCreate( iWorldSize, iWorldSize, 4, (char*)pBlendMap );

    delete [] pBlendMap;
    
    StructuredMaterial<Vector4>* pSplattingMaterial = new StructuredMaterial<Vector4>();
    pSplattingMaterial->GetBuffer()->VAddProperty( "u_vLightDirection", BufferProperty::BP_VECTOR3 );
    
    IShaderProgram* pProgram = IRenderer::CreateShaderProgram();
    IVertexShader* pVertexShader = IRenderer::CreateVertexShader();
    IPixelShader* pPixelShader = IRenderer::CreatePixelShader();
    
    BinaryResource* pVertexResource = AssetManager::Get().GetAsset< BinaryResource >( "Terrain.vert" );
    BinaryResource* pPixelResource = AssetManager::Get().GetAsset< BinaryResource >( "Terrain.frag" );
    
    if ( pVertexShader->VCreateFromMemory( pVertexResource->Buffer(), pVertexResource->Size() ) == false )
        throw "Error";
    
    if ( pPixelShader->VCreateFromMemory( pPixelResource->Buffer(), pPixelResource->Size() ) == false )
        throw "error";
    
    pProgram->VSetPixelShader( pPixelShader );
    pProgram->VSetVertexShader( pVertexShader );
    pVertexShader->VAddAttribute( "u_vPosition", Position_VertexData );
    pVertexShader->VAddAttribute( "u_vTexCoords", UV_VertexData );
    pVertexShader->VAddAttribute( "u_vNormal", Normal_VertexData );
    pVertexShader->VAddAttribute( "u_vColor", Color_VertexData );
    pProgram->VLink();
    
    pSplattingMaterial->SetShaderProgram( pProgram );
    pSplattingMaterial->AddTextureRegister( "Desert" );
    pSplattingMaterial->AddTextureRegister( "Grass" );
    pSplattingMaterial->AddTextureRegister( "Water" );
    pSplattingMaterial->AddTextureRegister( "Snow" );
    pSplattingMaterial->AddTextureRegister( "Rock" );
    pSplattingMaterial->AddTextureRegister( "BlendMap" );
    
    ITexture* pTexture = AssetManager::Get().GetAsset<ITexture>( "Desert.png" );
    pSplattingMaterial->SetTexture( 0, pTexture );
    
    pTexture = AssetManager::Get().GetAsset<ITexture>( "Grass.png" );
    pSplattingMaterial->SetTexture( 1, pTexture );
    
    pTexture = AssetManager::Get().GetAsset<ITexture>( "Water.png" );
    pSplattingMaterial->SetTexture( 2, pTexture );
    
    pTexture = AssetManager::Get().GetAsset<ITexture>( "Snow.png" );
    pSplattingMaterial->SetTexture( 3, pTexture );
    
    pTexture = AssetManager::Get().GetAsset<ITexture>( "Rock.png" );
    pSplattingMaterial->SetTexture( 4, pTexture );
    
    pSplattingMaterial->SetTexture( 5, pBlendMapTexture );
    
    
    
    m_pHeightMapEntity->SetMaterial( pSplattingMaterial );
    pSplattingMaterial->Release();
    pProgram->Release();
    pPixelShader->Release();
    pVertexShader->Release();
    
    
    pBlendMapTexture->Release();
    
    /*pEntity = Game::CreateEntity();
    SkyBox* pSkyBox = new SkyBox();
    pEntity->AddComponent( pSkyBox );
    pSkyBox->Start();
    pSkyBox->Release();*/
    
    
    Matrix mat;
    MeshComponent* pMeshComponent = NULL;
    Mesh* pMesh = NULL;
    
    
    pMesh = Mesh::CreateBox();
    mat.BuildScale( Vector4::ONE * 2.0f );
    mat.SetPosition( Vector4( 1900.0f, 0.0f, 1900.0f ) );
	mat.SetPosition( Vector4( 0.0f, 0.0f, 0.0f ) );
    pEntity = Game::CreateEntity( mat );
    pMeshComponent = new MeshComponent();
//    pEntity->AddComponent( pMeshComponent );
    pMeshComponent->SetMesh( pMesh );
    pMesh->Release();
    pMeshComponent->Start();
    pMeshComponent->Release();
    m_pSteering = new SteeringComponent();
    pEntity->AddComponent( m_pSteering );
    m_pSteering->SetSpeed( 15.0f );
	m_pSteering->SetHeightOffset( 1.0f );
    m_pSteering->Start();
    m_pSteering->Release();
    
    Character* pCharacter = new Character();
    XmlResource* pResource = AssetManager::Get().GetAsset<XmlResource>( "CombatAbilities.xml" );
    if ( pResource )
    {
        auto pElement = pResource->GetRoot()->FirstChildElement();
        
        while ( pElement )
        {
            CombatAbility ability;
            ability.VFromXML( pElement );
            pCharacter->AddAbility( ability );
            
            pElement = pElement->NextSiblingElement( "Ability" );
        }
    }
    
    pEntity->AddComponent( pCharacter );
    pCharacter->Release();
    
    GameHUDComponent* pGameHud = new GameHUDComponent();
    pEntity->AddComponent( pGameHud );
    pGameHud->Start();
    pGameHud->Release();
    
    m_pMrBitey = pEntity;
    
    pEntity = Game::CreateEntity();
    m_pAtmosphere = new AtmosphericScattering();
    pEntity->AddComponent( m_pAtmosphere );
    m_pAtmosphere->Start();
	m_pAtmosphere->Release();

	Transform waterPosition;
	waterPosition.SetPosition( 0.0f, 5.0f, 0.0f );
	pEntity = Game::CreateEntity( waterPosition );
	WaterPlane* pWater = new WaterPlane();
	pEntity->AddComponent( pWater );
	pWater->Start();
	pWater->Release();
}