public void Execute(int index)
            {
                PlayerInputData playerInputData = playerInputDataArray[index];
                PlayerMoveData  playerMoveData  = playerMoveDataArray[index];

                float3 movementVector = playerMoveData.rightDirection * playerInputData.inputMovementDirection.x
                                        + playerMoveData.forwardDirection * playerInputData.inputMovementDirection.z;

                playerMoveData.position += (playerMoveData.speed * movementVector * deltaTime);

                playerMoveData.position = math.clamp(playerMoveData.position, playerMoveData.minBoundary, playerMoveData.maxBoundary);


                playerMoveDataArray[index] = playerMoveData;

                EntityInstanceRenderData entityInstanceRenderData = entityInstanceRenderDataArray[index];

                entityInstanceRenderData.position = playerMoveData.position;
                entityInstanceRenderData.forward  = playerMoveData.forwardDirection;
                entityInstanceRenderData.up       = new float3(0, 1, 0) + (playerMoveData.rightDirection * playerInputData.inputMovementDirection.x);

                entityInstanceRenderDataArray[index] = entityInstanceRenderData;


                EntityBoundCenterData entityBoundCenterData = entityBoundCenterDataArray[index];
                EntityBoundMinMaxData entityBoundMinMaxData = entityBoundMinMaxDataArray[index];

                entityBoundCenterData.centerPosition = playerMoveData.position + entityBoundOffsetDataArray[index].offset;
                entityBoundMinMaxData.min            = entityBoundCenterData.centerPosition - entityBoundExtendDataArray[index].extend;
                entityBoundMinMaxData.max            = entityBoundCenterData.centerPosition + entityBoundExtendDataArray[index].extend;


                entityBoundCenterDataArray[index] = entityBoundCenterData;
                entityBoundMinMaxDataArray[index] = entityBoundMinMaxData;
            }
            public void Execute(int index)
            {
                BoltMoveData boltMoveData = boltMoveDataArray[index];

                boltMoveData.position   += (boltMoveData.speed * boltMoveData.forwardDirection * deltaTime);
                boltMoveDataArray[index] = boltMoveData;

                EntityInstanceRenderData entityInstanceRenderData = entityInstanceRenderDataArray[index];

                entityInstanceRenderData.position = boltMoveData.position;
                entityInstanceRenderData.forward  = renderDataForward;// new float3(0, -1, 0);

                //Feedback: Burst write float3(0,0,1) here
                entityInstanceRenderData.up = -boltMoveData.forwardDirection;

                entityInstanceRenderDataArray[index] = entityInstanceRenderData;

                EntityBoundCenterData entityBoundCenterData = entityBoundCenterDataArray[index];
                EntityBoundMinMaxData entityBoundMinMaxData = entityBoundMinMaxDataArray[index];

                entityBoundCenterData.centerPosition = boltMoveData.position + entityBoundOffsetDataArray[index].offset;
                entityBoundMinMaxData.min            = entityBoundCenterData.centerPosition - entityBoundExtendDataArray[index].extend;
                entityBoundMinMaxData.max            = entityBoundCenterData.centerPosition + entityBoundExtendDataArray[index].extend;


                entityBoundCenterDataArray[index] = entityBoundCenterData;
                entityBoundMinMaxDataArray[index] = entityBoundMinMaxData;
            }
            public void Execute(int index)
            {
                AIMoveData aiMoveData = aiMoveDataArray[index];

                aiMoveData.position   += (aiMoveData.speed * aiMoveData.forwardDirection * deltaTime);
                aiMoveDataArray[index] = aiMoveData;

                EntityInstanceRenderData entityInstanceRenderData = entityInstanceRenderDataArray[index];

                entityInstanceRenderData.position = aiMoveData.position;
                entityInstanceRenderData.forward  = aiMoveData.forwardDirection;
                entityInstanceRenderData.up       = new float3(0, 1, 0);

                entityInstanceRenderDataArray[index] = entityInstanceRenderData;

                EntityBoundCenterData entityBoundCenterData = entityBoundCenterDataArray[index];
                EntityBoundMinMaxData entityBoundMinMaxData = entityBoundMinMaxDataArray[index];

                entityBoundCenterData.centerPosition = aiMoveData.position + entityBoundOffsetDataArray[index].offset;
                entityBoundMinMaxData.min            = entityBoundCenterData.centerPosition - entityBoundExtendDataArray[index].extend;
                entityBoundMinMaxData.max            = entityBoundCenterData.centerPosition + entityBoundExtendDataArray[index].extend;


                entityBoundCenterDataArray[index] = entityBoundCenterData;
                entityBoundMinMaxDataArray[index] = entityBoundMinMaxData;
            }
            public void Execute()
            {
                while (entityQueue.Count > 0)
                {
                    Entity entityToDestroy = entityQueue.Dequeue();

                    if (entityTransaction.Exists(entityToDestroy))
                    {
                        //Get the EntityTypeData component to figure out what type of entity we are deleting
                        EntityTypeData entityToDestroyTypeData = entityTransaction.GetSharedComponentData <EntityTypeData>(entityToDestroy);
                        switch (entityToDestroyTypeData.entityType)
                        {
                        case EntityTypeData.EntityType.Asteroid:
                        case EntityTypeData.EntityType.EnemyShip:
                        case EntityTypeData.EntityType.AllyShip:
                        case EntityTypeData.EntityType.PlayerShip:
                        {
                            //Those type of entity will require some additional logic after destruction,
                            //create the info needed and add it to the list
                            EntityInstanceRenderData entityToDestroyRenderData = entityTransaction.GetComponentData <EntityInstanceRenderData>(entityToDestroy);
                            InfoForLogicAfterDestroy newInfo = new InfoForLogicAfterDestroy
                            {
                                entityTypeData = entityToDestroyTypeData,
                                renderData     = entityToDestroyRenderData,
                            };
                            infoForLogic.Add(newInfo);
                        }
                        break;

                        case EntityTypeData.EntityType.Bolt:
                        {
                            //Player bolts are only destroyed when they collided with enemies or obstacle,
                            // add to the score in that case
                            BoltTypeData boltTypeData = entityTransaction.GetSharedComponentData <BoltTypeData>(entityToDestroy);
                            if (boltTypeData.boltType == BoltTypeData.BoltType.PlayerBolt)
                            {
                                UIData uiData = uiDataArray[0];
                                uiData.score  += scoreValue;
                                uiDataArray[0] = uiData;
                            }
                        }
                        break;
                        }
                        //This will remove the entity from the entity manager
                        entityTransaction.DestroyEntity(entityToDestroy);
                    }
                }
            }
Example #5
0
            public void Execute(int index)
            {
                AsteroidMoveData asteroidMoveData = asteroidMoveDataArray[index];

                asteroidMoveData.position += (asteroidMoveData.speed * asteroidMoveData.forwardDirection * deltaTime);

                //https://en.wikipedia.org/wiki/Rodrigues%27_rotation_formula
                float  rotationAngle = Mathf.Deg2Rad * asteroidMoveData.rotationSpeed * deltaTime;
                float  cosValue      = math.cos(rotationAngle);
                float  sinValue      = math.sin(rotationAngle);
                float3 crossVector   = math.cross(asteroidMoveData.rotationAxis, asteroidMoveData.renderForward);
                float  dotValue      = math.dot(asteroidMoveData.rotationAxis, asteroidMoveData.renderForward);



                asteroidMoveData.renderForward = (asteroidMoveData.renderForward * cosValue)
                                                 + (crossVector * sinValue)
                                                 + (asteroidMoveData.rotationAxis * dotValue * (1.0f - cosValue));


                asteroidMoveDataArray[index] = asteroidMoveData;

                EntityInstanceRenderData entityInstanceRenderData = entityInstanceRenderDataArray[index];

                entityInstanceRenderData.position = asteroidMoveData.position;
                entityInstanceRenderData.forward  = asteroidMoveData.renderForward;
                entityInstanceRenderData.up       = new float3(0, 1, 0);

                entityInstanceRenderDataArray[index] = entityInstanceRenderData;

                EntityBoundCenterData entityBoundCenterData = entityBoundCenterDataArray[index];
                EntityBoundMinMaxData entityBoundMinMaxData = entityBoundMinMaxDataArray[index];

                entityBoundCenterData.centerPosition = asteroidMoveData.position + entityBoundOffsetDataArray[index].offset;
                entityBoundMinMaxData.min            = entityBoundCenterData.centerPosition - entityBoundExtendDataArray[index].extend;
                entityBoundMinMaxData.max            = entityBoundCenterData.centerPosition + entityBoundExtendDataArray[index].extend;


                entityBoundCenterDataArray[index] = entityBoundCenterData;
                entityBoundMinMaxDataArray[index] = entityBoundMinMaxData;
            }