-
Notifications
You must be signed in to change notification settings - Fork 0
/
Client.swift
executable file
·68 lines (56 loc) · 1.51 KB
/
Client.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
//
// Client.swift
// Dron3r
//
// Copyright © 2019 R&F Consulting, Inc. All rights reserved.
//
// a network client, connectionless, ping/pong-less UDP, a bunch of simulated drones pseudo-flying around
import Foundation
#if DEBUG
class Client // a pass-by-reference type
{
init()
{
for index in 0 ..< Config.Debug.DroneCount
{
// a SimulatedDrone, as opposed to a Drone, allows for direct setting of location, altitude and speed
//
// WARNING: DO NOT USE IN PRODUCTION CODE
// a hardware-based drone has to be SOMEWHERE
// start in a test location
let location = Location(
coordinate: Coordinate(latitude: Config.Debug.Latitude, longitude: Config.Debug.Longitude),
altitude: Config.Debug.Altitude)
// start motionless
let speed = Speed.zero()
let drone =
// every 5th drone is broken and will cease to fly after some time
// ("Tell me this isn't a government operation." - "Apollo 13", 1995)
//
index % 5 == 0 ?
BrokenDrone(identifier: UUID.new(), address: Config.Server.Address, port: Config.Server.InPort,
location: location, speed: speed) :
SimulatedDrone(identifier: UUID.new(), address: Config.Server.Address, port: Config.Server.InPort,
location: location, speed: speed)
drones.append(drone)
}
}
func fly()
{
for drone in drones
{
drone.fly()
}
}
func halt()
{
for drone in drones
{
drone.halt()
}
}
// MARK: - private
// an aray of drones
private var drones = [SimulatedDrone]()
}
#endif // DEBUG