예제 #1
0
        protected void Start()
        {
            if (mesh == null)
            {
                Debug.LogError("[SampleController] No 'mesh' provided"); return;
            }
            if (material == null)
            {
                Debug.LogError("[SampleController] No 'material' provided"); return;
            }

            //Allocate arrays
            cubeData      = new CubeData[cubeCount];
            bucketedCubes = new BucketSet <CubeData>(bucketCount: avoidanceBucketCount, maxBucketSize: avoidanceMaxBucketSize);
            renderSet     = new RenderSet(mesh, material, maxBatches: Mathf.CeilToInt(cubeCount / 1023f));

            //Create misc stuff
            int numExecutors = useMultiThreading ? (System.Environment.ProcessorCount - 1) : 0;

            Debug.Log(string.Format("[SampleController] Staring 'TaskManager' with '{0}' executors", numExecutors));
            taskManager     = new TaskManager(numExecutors);
            avoidanceHasher = new PositionHasher();
            random          = new ShiftRandomProvider();

            //Create tasks
            startTask          = new StartFrameTask();
            bucketCubeTask     = new BucketCubeTask(bucketedCubes, avoidanceHasher);
            moveCubeTask       = new MoveCubeTask(avoidanceHasher, bucketedCubes);
            respawnCubeTask    = new RespawnCubeTask(random);
            addToRenderSetTask = new AddToRenderSetTask(renderSet);

            //Setup profiler timeline
            if (profiler != null)
            {
                completeProfilerTrack       = profiler.CreateTrack <TimelineTrack>("Blocking main-thread to complete tasks");
                renderProfilerTrack         = profiler.CreateTrack <TimelineTrack>("Render instanced");
                bucketCubesProfilerTrack    = profiler.CreateTrack <TaskTimelineTrack>("Bucket cubes");
                moveCubesProfilerTrack      = profiler.CreateTrack <TaskTimelineTrack>("Move cubes");
                respawnCubesProfilerTrack   = profiler.CreateTrack <TaskTimelineTrack>("Respawn cubes");
                addToRenderSetProfilerTrack = profiler.CreateTrack <TaskTimelineTrack>("Creating render batches");
                profiler.StartTimers();
            }

            //Setup initial data
            Rect spawnArea = MathUtils.FromCenterAndSize(Vector2.zero, spawnAreaSize);

            for (int i = 0; i < cubeCount; i++)
            {
                cubeData[i] = new CubeData
                {
                    ID                = i,
                    Position          = random.Inside(spawnArea),
                    TimeNotHitTarget1 = 999f,
                    TimeNotHitTarget2 = 999f
                }
            }
            ;
        }
        protected override void ExecuteSubtask(int execID, int index)
        {
            Vector3 position = random.Inside(spawnArea);

            var entity = context.CreateEntity();

            context.SetComponent(entity, new TransformComponent(Float3x4.FromPosition(position)));
            context.SetComponent(entity, new GraphicComponent(graphicID: 1));
            context.SetComponent(entity, new ProjectileSpawnerComponent(cooldown: random.GetNext() * 5f));
        }
예제 #3
0
 public void Execute(ref CubeData data, int index, int batch)
 {
     if (data.Position.sqrMagnitude > MaxDistance * MaxDistance)
     {
         data = new CubeData
         {
             ID                = data.ID,
             Position          = random.Inside(RespawnArea),
             Velocity          = random.Direction() * RespawnForce,
             TimeNotHitTarget1 = 999f,
             TimeNotHitTarget2 = 999f
         };
     }
 }
        protected override void ExecuteSubtask(int execID, int index)
        {
            Vector3 position = random.Inside(spawnArea);
            Vector3 velocity = Vector3.forward * random.Between(10f, 15f);

            var entity = context.CreateEntity();

            context.SetComponent(entity, new TransformComponent(Float3x4.FromPosition(position)));
            context.SetComponent(entity, new VelocityComponent(velocity: velocity));
            context.SetComponent(entity, new GraphicComponent(graphicID: 0));
            context.SetComponent(entity, new AgeComponent());
            context.SetComponent(entity, new LifetimeComponent(totalLifetime: random.Between(30f, 35f)));
            context.SetComponent(entity, new ColliderComponent(size: new Vector3(3, 2, 3)));
            context.SetTag <SpaceshipTag>(entity);
        }