public void Add(int execID, byte graphicID, Float3x4 matrix, float age) { if (graphicID >= graphicBatches.Length) { throw new Exception($"[{nameof(GraphicBatch)}] {nameof(graphicID)} is out of bounds! Is the graphic setup in the {nameof(GraphicAssetLibrary)}?"); } graphicBatches[graphicID].Add(execID, matrix, age); }
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)); }
public void Add(Float3x4 matrix, float age) { if (Full) { throw new Exception($"[{nameof(GraphicBatch)}] Unable to add: Allready full"); } Matrices[Count] = matrix; Ages[Count] = age; Count++; }
protected override void Execute(int execID, EntityID entity, ref VelocityComponent velo, ref TransformComponent trans) { if (velo.Velocity == Vector3.zero) { return; } Vector3 newPos = trans.Matrix.Position + velo.Velocity * deltaTime.Value; Vector3 dir = FastNormalize(velo.Velocity); trans.Matrix = Float3x4.FromPositionAndForward(newPos, dir); }
private void FireProjectile(ref ProjectileSpawnerComponent spawner, ref TransformComponent turretTrans) { const float INVERSE_PROJECTILE_SPEED = 1f / 100f; Vector3 turretPos = turretTrans.Matrix.Position; Vector3 targetPos = context.GetComponent <TransformComponent>(spawner.Target.Value).Matrix.Position; Vector3 targetVelo = context.GetComponent <VelocityComponent>(spawner.Target.Value).Velocity; float distanceEst = ManhattanDistance(targetPos - turretPos); float flightTime = distanceEst * INVERSE_PROJECTILE_SPEED; if (flightTime <= 0f) { return; } //Aim ahead of the target to compensation for its movement Vector3 aimTarget = targetPos + targetVelo * flightTime; //Gather info about the trajectory from the turret to the aim-target Vector3 toAimTarget = aimTarget - turretPos; float toAimTargetSqrDist = toAimTarget.sqrMagnitude; float toAimTargetDist = Mathf.Sqrt(toAimTargetSqrDist); //TODO: See if we can get rid of the SquareRoot usage here Vector3 toAimTargetDir = toAimTarget * FastInvSqrRoot(toAimTargetSqrDist); //Create normalized vector aiming to toward the aim target //Speed that the projectile will be traveling at. (NOTE: Its not the same as the configured projectile speed we used //to estimate the flighttime, thats because the estimate did not compensate for the target velocity yet) float trajectorySpeed = toAimTargetDist / flightTime; //Calculate how much gravity we will encounter in the journey float gravity = ApplyGravitySystem.GRAVITY * flightTime; //Calculate the 'final' projectileVelocity and include the gravity compensation Vector3 projectileVelocity = toAimTargetDir * trajectorySpeed + Vector3.down * (gravity * .5f); //This is used to 'point' the turret, if we want to be cheap we could use the 'toAimTargetDir' but thats not //really accurate because it doesn't include the gravity compensation yet Vector3 velocityDir = FastNormalize(projectileVelocity); //Spawn the projectile entity var entity = context.CreateEntity(); context.SetComponent(entity, new TransformComponent(Float3x4.FromPosition(turretPos))); context.SetComponent(entity, new VelocityComponent(velocity: projectileVelocity)); context.SetComponent(entity, new GraphicComponent(graphicID: 2)); context.SetComponent(entity, new AgeComponent()); context.SetComponent(entity, new LifetimeComponent(totalLifetime: 3f)); context.SetTag <ProjectileTag>(entity); context.SetTag <ApplyGravityTag>(entity); //Update the turret to face the target turretTrans.Matrix = Float3x4.FromPositionAndForward(turretTrans.Matrix.Position, velocityDir); }
protected override void Execute(int execID, EntityID entity, ref TransformComponent trans) { if (trans.Matrix.Position.y <= 0f) //We've hit the ground { //Remove spaceship context.RemoveEntity(entity); //Spawn explosion EntityID explosionEntity = context.CreateEntity(); context.SetComponent(explosionEntity, new TransformComponent(Float3x4.FromPosition(trans.Matrix.Position))); context.SetComponent(explosionEntity, new GraphicComponent(graphicID: 4)); context.SetComponent(explosionEntity, new LifetimeComponent(totalLifetime: 1)); context.SetComponent(explosionEntity, new AgeComponent()); } }
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); }
protected override void Execute(int execID, EntityID entity, ref TransformComponent trans, ref VelocityComponent velo) { Vector3 pos = trans.Matrix.Position; Vector3 prevPos = pos - velo.Velocity * deltaTime.Value; Line line = new Line(prevPos, pos); EntityID target; if (colliderManager.Intersect(line, out target)) { //Remove the projectile context.RemoveEntity(entity); //Mark the target as hit context.SetTag <HitTag>(target); //Spawn a impact EntityID impactEntity = context.CreateEntity(); context.SetComponent(impactEntity, new TransformComponent(Float3x4.FromPosition(pos))); context.SetComponent(impactEntity, new GraphicComponent(graphicID: 3)); context.SetComponent(impactEntity, new LifetimeComponent(totalLifetime: .5f)); context.SetComponent(impactEntity, new AgeComponent()); } }
public TransformComponent(Float3x4 matrix) { Matrix = matrix; }
public static void Clip(Float3x4 x) => throw new InvalidExecutionContextException($"{typeof(Hlsl)}.{nameof(Clip)}({typeof(Float3x4)})");
public void Add(int execID, Float3x4 matrix, float age) { //+1 because the main-thread uses execID -1 dataPerThread[execID + 1].Add(matrix, age); }