Example #1
0
        static public void _AddNewPatternSystem(EntityCommandBuffer commandBuffer, int i_patternIndex, float f_baseScale, float3 f3_localPosition, int i_lodDepth, int i_prefabIndex)
        {
            commandBuffer.CreateEntity(archetype);     // store data about composite patterns groups

            PatternComponent patternComponent = new Blocks.PatternComponent()
            {
                //i_patternIndex = random.NextInt ( 0, Pattern.PatternPrefabSystem.i_currentPrefabsCount ), // get random prefab pattern
                i_patternIndex = i_patternIndex,
                //i_patternIndex = random.NextInt ( 0, 3 )
                f_baseScale      = f_baseScale,
                f3_localPosition = f3_localPosition,
                i_lodDepth       = 0, // set default depth level
                i_prefabIndex    = i_prefabIndex
            };

            commandBuffer.AddComponent <PatternComponent> (patternComponent);
        }
            public void Execute()   // for IJob
            // public void Execute ( int i )  // for IJobParallelFor
            {
                // Iterate through patterns groups, to move its composites
                for (int i = 0; i < a_paternEntities.Length; i++)
                {
                    Entity patternEntity = a_paternEntities [i];
                    commandBuffer.AddComponent(patternEntity, new Blocks.Pattern.RequestPatternReleaseTag());

                    commandBuffer.AddComponent(patternEntity, new Blocks.Pattern.RequestPatternMainMeshSetupTag());
                    commandBuffer.RemoveComponent <Blocks.Pattern.Components.IsLodSwitchedTag> (patternEntity);

                    /*
                     * Entity spareCompositeEntity = a_sparePaternEntities [i] ;
                     *
                     * if ( a_isEntityHaveSwitchTag.Exists ( spareCompositeEntity ) )
                     * {
                     *  commandBuffer.RemoveComponent <Common.Components.IsNotAssignedTag> ( paternEntity ) ;
                     * }
                     *
                     *
                     *
                     */



                    Blocks.PatternComponent patternComponent = a_patternComponent [i];
                    patternComponent.i_prefabIndex = 1;
                    int i_compositeInPrefabIndex = 2;  // temp

                    // This composite is different type as previous composite.
                    // This composite mesh will be scaled, to overlap next composite, if the type is the same.
                    // Hence next mesh may be not required, hwen type is < 0
                    //if ( compositeInPatternPrefab.i_compositePrefabIndex >= 0 )
                    //{

                    // Assign relative references to composite
                    Blocks.CompositeComponent composite = new CompositeComponent()
                    {
                        blockEntity     = patternComponent.blockEntity, // assign grand parent entity to composite
                        patternEntity   = patternEntity,                // assign parent pattern group entity to composite
                        i_inPrefabIndex = i_compositeInPrefabIndex      // used prefab
                    };

                    Entity spareCompositeEntity = a_sparePaternCompositeEntities [i];  // index is only temp test

                    patternComponent.blockEntity = spareCompositeEntity;

                    commandBuffer.SetComponent(spareCompositeEntity, composite);

                    Unity.Rendering.MeshInstanceRenderer renderer;
                    switch (patternComponent.i_prefabIndex)
                    {
                    case 1:
                        renderer = Bootstrap.octreeCenter02;
                        break;

                    case 2:
                        renderer = Bootstrap.octreeCenter03;
                        break;

                    case 3:
                        renderer = Bootstrap.octreeCenter04;
                        break;

                    case 4:
                        renderer = Bootstrap.octreeCenter05;
                        break;

                    case 5:
                        renderer = Bootstrap.octreeCenter06;
                        break;

                    case 6:
                        renderer = Bootstrap.octreeCenter07;
                        break;

                    default:
                        renderer = Bootstrap.octreeCenter01;
                        break;
                    }

                    commandBuffer.SetSharedComponent(spareCompositeEntity, renderer);

                    // Position position = new Position () { Value = patternComponent.f3_localPosition } ;
                    //commandBuffer.SetComponent ( spareCompositeEntity, position ) ;

                    // Scale scale = new Scale () { Value = patternComponent.f_baseScale * 0.1f } ;
                    Scale scale = new Scale()
                    {
                        Value = new float3(1, 1, 1) * 0.1f * patternComponent.f_baseScale
                    };
                    commandBuffer.SetComponent(spareCompositeEntity, scale);

                    // Store composite back in
                    a_patternComponent [i] = patternComponent;

                    // Composite entity has been assigned
                    // Now is ready for rendering, or other processing
                    commandBuffer.RemoveComponent <Common.Components.IsNotAssignedTag> (spareCompositeEntity);

                    // }



                    /*
                     * // Debug.Log ( "Lod switch: " + i ) ;
                     *
                     * // Assign local position
                     * Blocks.PatternComponent patternComponent = lodPatternData.a_patternComponent [i] ;
                     *
                     * int i_newDepthLevel = 0 ; // Go default depth elvel
                     * int i_depthLevelChange = patternComponent.i_lodDepth - i_newDepthLevel ;
                     * patternComponent.i_lodDepth = i_newDepthLevel ;
                     * patternComponent.f3_localPosition += new float3 ( i_depthLevelChange * 1f, 0, 0 ) ;
                     * // patternComponent.f_localPosition = new float3 ( 1, 0, 0 ) * i ;
                     * lodPatternData.a_patternComponent [i] = patternComponent ;
                     *
                     * Entity paternEntity = lodPatternData.a_entities [i] ;
                     * commandBuffer.AddComponent ( paternEntity, new Blocks.Pattern.RequestPatternReleaseTag () ) ;
                     *
                     * // Test02.AddBlockSystem._AddBlockRequestViaCustomBufferWithEntity ( commandBuffer, paternEntity, movePattern.f3_position, new float3 (1,1,1), float3.zero, new Entity (), float4.zero ) ;
                     * // commandBuffer.AddComponent ( paternEntity, new Blocks.Pattern.Components.Lod050Tag () ) ; // test only
                     * commandBuffer.AddComponent ( paternEntity, new Blocks.Pattern.RequestPatternSetupTag () ) ;
                     *
                     * commandBuffer.RemoveComponent <Blocks.Pattern.Components.IsLodSwitchedTag> ( paternEntity ) ;
                     */
                } // for
            }     // execute
            public void Execute()   // for IJob
            // public void Execute ( int i )  // for IJobParallelFor
            {
                // Iterate through patterns groups, to move its composites
                for (int i = 0; i < lodPatternData.Length; i++)
                {
                    // Debug.Log ( "Lod switch: " + i ) ;

                    // Assign local position
                    Blocks.PatternComponent patternComponent = lodPatternData.a_patternComponent [i];

                    int i_newDepthLevel    = -1; // Go to deeper depth level, with higher details
                    int i_depthLevelChange = patternComponent.i_lodDepth - i_newDepthLevel;
                    patternComponent.i_lodDepth = i_newDepthLevel;
                    // patternComponent.f_localPosition = new float3 ( 1, 0, 0 ) * i + new float3 ( 0, 0.1f, 0 ) ;
                    patternComponent.f3_localPosition    += new float3(i_depthLevelChange * 0.1f, 0, 0);
                    lodPatternData.a_patternComponent [i] = patternComponent;

                    Entity paternEntity = lodPatternData.a_entities [i];
                    commandBuffer.AddComponent(paternEntity, new Blocks.Pattern.RequestPatternReleaseTag());

                    // Test02.AddBlockSystem._AddBlockRequestViaCustomBufferWithEntity ( commandBuffer, paternEntity, movePattern.f3_position, new float3 (1,1,1), float3.zero, new Entity (), float4.zero ) ;
                    // commandBuffer.AddComponent ( paternEntity, new Blocks.Pattern.Components.Lod050Tag () ) ; // test only
                    commandBuffer.AddComponent(paternEntity, new Blocks.Pattern.RequestPatternSetupTag());

                    commandBuffer.RemoveComponent <Blocks.Pattern.Components.IsLodSwitchedTag> (paternEntity);

                    /*
                     * // Add temp new pattern
                     * int i_randomPattern = random.NextInt ( 0, Pattern.AddPatternPrefabSystem.i_currentPrefabsCount ) ; // reandom is temp
                     * int i_patternIndex = i_randomPattern ; // reandom is temp
                     * float f_baseScale = 2f ;
                     * float3 f3_localPosition = patternComponent.f3_localPosition ; // new float3 ( 1, 0, 0 ) * i ;
                     * int i_lodDepth = 0 ;
                     *
                     * // Temp test
                     *
                     *
                     * // Check if got enugh spares pattern groups
                     * if ( a_sparePatternGroupsEntities.Length > i )
                     * {
                     *  Entity sparePatternsEntity = a_sparePatternGroupsEntities [i] ;
                     *
                     *  // patternComponent = a_sparePatternComponents [sparePatternsEntity] ;
                     *  // patternComponent = ComponentDataFromEntity <Blocks.PatternComponent> ( a_sparePatternGroupsEntities [i] ) ;
                     *  // Reuse exisiting spare pattern group
                     *  // Entity  sparePatternsData.a_entities [i] ;
                     *  // patternComponent = a_patternComponent [i] ;
                     *
                     *  Debug.Log ( "Switch: #" + i + "; sparePatternsEntity #" + sparePatternsEntity.Index ) ;
                     *  patternComponent.i_patternIndex = i_randomPattern ;
                     *  patternComponent.f_baseScale = f_baseScale ;
                     *  patternComponent.f3_localPosition = f3_localPosition ;
                     *  patternComponent.i_lodDepth = i_lodDepth ;
                     *
                     *  commandBuffer.SetComponent ( sparePatternsEntity, patternComponent ) ;
                     *  // a_sparePatternComponents [sparePatternsEntity] = patternComponent ;
                     *
                     *
                     *  //paternEntity = sparePatternsData.a_entities [i] ;
                     *  commandBuffer.AddComponent ( sparePatternsEntity, new Blocks.Pattern.RequestPatternSetupTag () ) ;
                     *  commandBuffer.RemoveComponent <Blocks.Pattern.Components.IsLodSwitchedTag> ( sparePatternsEntity ) ;
                     * }
                     * else
                     * {
                     *  Debug.Log ( "Create new #" + i ) ;
                     *
                     *  // Not enough
                     *  // Create new pattern group
                     *  InitializePatternSystem._AddNewPatternSystem ( commandBuffer, i_patternIndex, f_baseScale, f3_localPosition, i_lodDepth  ) ;
                     * }
                     */

                    // commandBuffer.AddComponent ( paternEntity, new Blocks.Pattern.RequestPatternSetupTag () ) ;

                    // commandBuffer.RemoveComponent <Blocks.Pattern.Components.IsLodSwitchedTag> ( paternEntity ) ;
                } // for
            }     // execute
Example #4
0
        /// <summary>
        /// Assigns composite patter, to selected entity
        /// </summary>
        /// <param name="entityWithPatern"></param>
        static private EntityCommandBuffer _AssignComposites2Pattern(EntityCommandBuffer commandBuffer, RequestPatternSetupData requestPatternSetupData, int i_patternGroupIndex, EntityArray a_spareCompositeEntities)
        {
            //Entity assignComposites2PatternEntity = assignComposite2PatternData.a_entities [i_entityWithPaternIndex] ;
            //CompositeComponent compositeComponent = assignComposite2PatternData.a_compositeEntityRelatives [i_entityWithPaternIndex] ;

            Blocks.PatternComponent pattern = requestPatternSetupData.a_compositesInPattern [i_patternGroupIndex];
            BufferArray <Common.BufferElements.EntityBuffer> a_patternsStore = requestPatternSetupData.a_entityBuffer;

            int i_patternIndex       = pattern.i_patternIndex;
            int i_patternOffsetIndex = i_patternIndex * Pattern.AddPatternPrefabSystem.i_compositesCountPerPatternGroup;

            Entity requestPatternSetupEntity = requestPatternSetupData.a_entities [i_patternGroupIndex];


            // clear store for each pattern group entity
            a_patternsStore [i_patternGroupIndex].Clear();

            int i_spareEntitiesOffsetIndex = i_patternGroupIndex * Pattern.AddPatternPrefabSystem.i_compositesCountPerPatternGroup;

            // int i_patterGroupOffsetIndex = i_componentsPatternIndex * i_compositesCountPerPatternGroup ;
            // assign composite entity to entity with pattern
            for (int i_spareEntityIndex = 0; i_spareEntityIndex < Pattern.AddPatternPrefabSystem.i_compositesCountPerPatternGroup; i_spareEntityIndex++)
            {
                // get element from patern prefab to copy into group
                int i_compositeInPrefabIndex = i_patternOffsetIndex + i_spareEntityIndex;
                Blocks.Pattern.CompositeInPatternPrefabComponent compositeInPatternPrefab = Pattern.AddPatternPrefabSystem.a_patternPrefabs [i_compositeInPrefabIndex];

                // This composite is different type as previous composite.
                // This composite mesh will be scaled, to overlap next composite, if the type is the same.
                // Hence next mesh may be not required, hwen type is < 0
                if (compositeInPatternPrefab.i_compositePrefabIndex >= 0)
                {
                    // Assign relative references to composite
                    Blocks.CompositeComponent composite = new CompositeComponent()
                    {
                        blockEntity     = pattern.blockEntity,       // assign grand parent entity to composite
                        patternEntity   = requestPatternSetupEntity, // assign parent pattern group entity to composite
                        i_inPrefabIndex = i_compositeInPrefabIndex   // used prefab
                    };

                    Entity spareCompositeEntity = a_spareCompositeEntities [i_spareEntitiesOffsetIndex + i_spareEntityIndex];

                    Common.BufferElements.EntityBuffer spareEntityBuffer = new Common.BufferElements.EntityBuffer()
                    {
                        entity = spareCompositeEntity
                    };

                    // expand buffer array if is too small
                    a_patternsStore [i_patternGroupIndex].Add(spareEntityBuffer);

                    commandBuffer.SetComponent(spareCompositeEntity, composite);

                    MeshInstanceRenderer renderer;
                    switch (compositeInPatternPrefab.i_compositePrefabIndex)
                    {
                    case 1:
                        renderer = Bootstrap.octreeCenter02;
                        break;

                    case 2:
                        renderer = Bootstrap.octreeCenter03;
                        break;

                    case 3:
                        renderer = Bootstrap.octreeCenter04;
                        break;

                    case 4:
                        renderer = Bootstrap.octreeCenter05;
                        break;

                    case 5:
                        renderer = Bootstrap.octreeCenter06;
                        break;

                    case 6:
                        renderer = Bootstrap.octreeCenter07;
                        break;

                    default:
                        renderer = Bootstrap.octreeCenter01;
                        break;
                    }

                    commandBuffer.SetSharedComponent(spareCompositeEntity, renderer);

                    Position position = new Position()
                    {
                        Value = compositeInPatternPrefab.f3_position
                    };
                    commandBuffer.SetComponent(spareCompositeEntity, position);

                    Scale scale = new Scale()
                    {
                        Value = compositeInPatternPrefab.f3_scale * pattern.f_baseScale
                    };
                    commandBuffer.SetComponent(spareCompositeEntity, scale);

                    // Store composite back in
                    //Pattern.AddPatternPrefabSystem.a_patternPrefabs [ i_compositeInPrefabIndex ] = compositeInPatternPrefab ;

                    // Composite entity has been assigned
                    // Now is ready for rendering, or other processing
                    commandBuffer.RemoveComponent <Common.Components.IsNotAssignedTag> (spareCompositeEntity);
                }
                else
                {
                    // Iteration reached composite index in the prefab store, which should be ignored.
                    // Any later index for this prefab should also be ignored, as expanded mesh took its place.
                    break;
                }
            }

            return(commandBuffer);
        }