This question is about the proper way to architect an implementation of Craig Reynolds Boids algorithm.
I have an Agent
object like this:
struct Agent: Equatable
{
let identifier = NSProcessInfo.processInfo().globallyUniqueString
var position: CGPoint
var velocity: CGVector
init(position: CGPoint = .zero, velocity: CGVector = .zero)
{
self.position = position
self.velocity = velocity
}
}
And a Simulation
object that holds an array of agents. Each iteration of the simulation the Simulation
object updates the position
and velocity
of each Agent
in its array of Agent
s. Something like this:
class Simulation
{
private var agents: [Agent] = []
init(agents: [Agent])
{
self.agents = agents
}
func update()
{
for agent in self.agents
{
// Update agent's position and velocity
}
}
This is ok. I can run the simulation and update the Agent
models appropriately. However, I also want to draw the models on screen.
The question is whether I should create a new AgentView
class as the view representation of an Agent
model object. Or whether (1) maintaining a relationship between each Agent
model and a corresponding AgentView
is too cumbersome and (2) I should just replace the Agent
model with AgentView
entirely and let AgentView
be the sole representation of an agent (sort of blending model and view state).
Thanks in advance for your help. If you would like additional clarification just let me know.