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) { 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(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; }
void AIMove(NativeArray <AIMoveData> aiMoveDataArray, NativeArray <Position> positionArray, NativeArray <Rotation> rotationArray, NativeArray <EntityBoundCenterData> boundCenterDataArray, NativeArray <EntityBoundMinMaxData> boundMinMaxDataArray, NativeArray <EntityBoundOffsetData> boundOffsetDataArray, NativeArray <EntityBoundExtendData> boundExtendDataArray) { int dataCount = aiMoveDataArray.Length; for (int dataIndex = 0; dataIndex < dataCount; dataIndex++) { Position position = positionArray[dataIndex]; Rotation rotation = rotationArray[dataIndex]; AIMoveData aiMoveData = aiMoveDataArray[dataIndex]; float3 forwardDirection = math.forward(rotation.Value); position.Value += (aiMoveData.speed * forwardDirection * deltaTime); positionArray[dataIndex] = position; EntityBoundCenterData entityBoundCenterData = boundCenterDataArray[dataIndex]; EntityBoundMinMaxData entityBoundMinMaxData = boundMinMaxDataArray[dataIndex]; entityBoundCenterData.centerPosition = position.Value + boundOffsetDataArray[dataIndex].offset; entityBoundMinMaxData.min = entityBoundCenterData.centerPosition - boundExtendDataArray[dataIndex].extend; entityBoundMinMaxData.max = entityBoundCenterData.centerPosition + boundExtendDataArray[dataIndex].extend; boundCenterDataArray[dataIndex] = entityBoundCenterData; boundMinMaxDataArray[dataIndex] = entityBoundMinMaxData; } }
void BoltMove(NativeArray <BoltMoveData> boltMoveDataArray, NativeArray <Position> positionArray, NativeArray <Rotation> rotationArray, NativeArray <EntityBoundCenterData> boundCenterDataArray, NativeArray <EntityBoundMinMaxData> boundMinMaxDataArray, NativeArray <EntityBoundOffsetData> boundOffsetDataArray, NativeArray <EntityBoundExtendData> boundExtendDataArray) { //The array size will be equal to the amount of entity int dataCount = boltMoveDataArray.Length; for (int dataIndex = 0; dataIndex < dataCount; dataIndex++) { Position position = positionArray[dataIndex]; Rotation rotation = rotationArray[dataIndex]; BoltMoveData boltMoveData = boltMoveDataArray[dataIndex]; float3 forwardDirection = boltMoveData.forwardDirection; position.Value += (boltMoveData.speed * forwardDirection * deltaTime); positionArray[dataIndex] = position; EntityBoundCenterData entityBoundCenterData = boundCenterDataArray[dataIndex]; EntityBoundMinMaxData entityBoundMinMaxData = boundMinMaxDataArray[dataIndex]; entityBoundCenterData.centerPosition = position.Value + boundOffsetDataArray[dataIndex].offset; entityBoundMinMaxData.min = entityBoundCenterData.centerPosition - boundExtendDataArray[dataIndex].extend; entityBoundMinMaxData.max = entityBoundCenterData.centerPosition + boundExtendDataArray[dataIndex].extend; boundCenterDataArray[dataIndex] = entityBoundCenterData; boundMinMaxDataArray[dataIndex] = entityBoundMinMaxData; } }
public void Execute(int index) { Entity entityToAdd = entityArray[index]; EntityBoundMinMaxData boundMinMaxData = entityBoundMinMaxDataArray[index]; entityArrayOutput[index] = entityToAdd; entityBoundMinMaxDataArrayOutput[index] = boundMinMaxData; AddHashData(new HashMapData { entityStored = entityToAdd, minMaxData = boundMinMaxData }, cellSizes, outputCells); }
public void Execute(int chunkIndex) { ArchetypeChunk chunk = chunks[chunkIndex]; int dataCount = chunk.Count; NativeArray <PlayerInputData> playerInputDataArray = chunk.GetNativeArray(playerInputDataRO); NativeArray <PlayerMoveData> playerMoveDataArray = chunk.GetNativeArray(playerMoveDataRO); NativeArray <Position> positionDataArray = chunk.GetNativeArray(positionRW); NativeArray <Rotation> rotationDataArray = chunk.GetNativeArray(rotationRW); NativeArray <EntityBoundCenterData> boundCenterDataArray = chunk.GetNativeArray(boundCenterDataRW); NativeArray <EntityBoundMinMaxData> boundMinMaxDataArray = chunk.GetNativeArray(boundMinMaxDataRW); NativeArray <EntityBoundOffsetData> boundOffsetDataArray = chunk.GetNativeArray(boundOffsetDataRO); NativeArray <EntityBoundExtendData> boundExtendDataArray = chunk.GetNativeArray(boundExtendDataRO); for (int dataIndex = 0; dataIndex < dataCount; dataIndex++) { PlayerInputData playerInputData = playerInputDataArray[dataIndex]; PlayerMoveData playerMoveData = playerMoveDataArray[dataIndex]; Position playerPosition = positionDataArray[dataIndex]; Rotation playerRotation = rotationDataArray[dataIndex]; float3 shipUp = new float3(0, 1, 0) + (playerMoveData.rightDirection * playerInputData.inputMovementDirection.x); float3 movementVector = playerMoveData.rightDirection * playerInputData.inputMovementDirection.x + playerMoveData.forwardDirection * playerInputData.inputMovementDirection.z; playerPosition.Value += (playerMoveData.speed * movementVector * deltaTime); playerPosition.Value = math.clamp(playerPosition.Value, playerMoveData.minBoundary, playerMoveData.maxBoundary); playerRotation.Value = quaternion.LookRotation(playerMoveData.forwardDirection, shipUp); positionDataArray[dataIndex] = playerPosition; rotationDataArray[dataIndex] = playerRotation; EntityBoundCenterData entityBoundCenterData = boundCenterDataArray[dataIndex]; EntityBoundMinMaxData entityBoundMinMaxData = boundMinMaxDataArray[dataIndex]; entityBoundCenterData.centerPosition = playerPosition.Value + boundOffsetDataArray[dataIndex].offset; entityBoundMinMaxData.min = entityBoundCenterData.centerPosition - boundExtendDataArray[dataIndex].extend; entityBoundMinMaxData.max = entityBoundCenterData.centerPosition + boundExtendDataArray[dataIndex].extend; boundCenterDataArray[dataIndex] = entityBoundCenterData; boundMinMaxDataArray[dataIndex] = entityBoundMinMaxData; } }
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; }
public void Execute(int chunkIndex) { ArchetypeChunk chunk = chunks[chunkIndex]; int dataCount = chunk.Count; NativeArray <Position> positionDataArray = chunk.GetNativeArray(positionRW); NativeArray <Rotation> rotationDataArray = chunk.GetNativeArray(rotationRW); NativeArray <AsteroidMoveData> asteroidMoveDataArray = chunk.GetNativeArray(asteroidMoveDataRO); NativeArray <EntityBoundCenterData> boundCenterDataArray = chunk.GetNativeArray(boundCenterDataRW); NativeArray <EntityBoundMinMaxData> boundMinMaxDataArray = chunk.GetNativeArray(boundMinMaxDataRW); NativeArray <EntityBoundOffsetData> boundOffsetDataArray = chunk.GetNativeArray(boundOffsetDataRO); NativeArray <EntityBoundExtendData> boundExtendDataArray = chunk.GetNativeArray(boundExtendDataRO); for (int dataIndex = 0; dataIndex < dataCount; dataIndex++) { Position position = positionDataArray[dataIndex]; Rotation rotation = rotationDataArray[dataIndex]; AsteroidMoveData asteroidMoveData = asteroidMoveDataArray[dataIndex]; position.Value += (asteroidMoveData.movementSpeed * deltaTime); rotation.Value = math.mul(rotation.Value, quaternion.AxisAngle(asteroidMoveData.rotationAxis, Mathf.Deg2Rad * asteroidMoveData.rotationSpeed * deltaTime)); positionDataArray[dataIndex] = position; rotationDataArray[dataIndex] = rotation; EntityBoundCenterData entityBoundCenterData = boundCenterDataArray[dataIndex]; EntityBoundMinMaxData entityBoundMinMaxData = boundMinMaxDataArray[dataIndex]; entityBoundCenterData.centerPosition = position.Value + boundOffsetDataArray[dataIndex].offset; entityBoundMinMaxData.min = entityBoundCenterData.centerPosition - boundExtendDataArray[dataIndex].extend; entityBoundMinMaxData.max = entityBoundCenterData.centerPosition + boundExtendDataArray[dataIndex].extend; boundCenterDataArray[dataIndex] = entityBoundCenterData; boundMinMaxDataArray[dataIndex] = entityBoundMinMaxData; } }
public void Execute(int index) { Entity currentEntity = entityArray[index]; EntityBoundMinMaxData boundMinMaxData = entityBoundMinMaxData[index]; int3 minQuanta = Quantize(boundMinMaxData.min, cellSizes); int3 maxQuanta = Quantize(boundMinMaxData.max, cellSizes); int3 deltaQuanta = maxQuanta - minQuanta; bool collided = false; Entity collidedEntityFound = new Entity(); int hash; for (int i = 0; i <= deltaQuanta.x && !collided; i++) { for (int j = 0; j <= deltaQuanta.y && !collided; j++) { for (int k = 0; k <= deltaQuanta.z && !collided; k++) { hash = Hash(minQuanta + new int3(i, j, k)); HashMapData hashMapDataFound; NativeMultiHashMapIterator <int> iterator; bool found = boundCells.TryGetFirstValue(hash, out hashMapDataFound, out iterator); while (found && !collided) { //This test is not needed given that we have separate hash map for each entity type /* if(currentEntity == collidedEntity) * { * found = boundCells.TryGetNextValue(out collidedEntity, ref iterator); * continue; * }*/ EntityBoundMinMaxData boundMinMaxDataOther = hashMapDataFound.minMaxData; //axis aligned test float3 minSelf = boundMinMaxData.min; float3 minOther = boundMinMaxDataOther.min; float3 maxSelf = boundMinMaxData.max; float3 maxOther = boundMinMaxDataOther.max; if (math.all(maxSelf > minOther) && math.all(maxOther > minSelf)) { collided = true; collidedEntityFound = hashMapDataFound.entityStored; } else { found = boundCells.TryGetNextValue(out hashMapDataFound, ref iterator); } } } } } if (collided) { collidedEntityQueue.Enqueue(currentEntity); collidedEntityQueue.Enqueue(collidedEntityFound); } }