Re: [swift-users] Checking/getting custom objects from a collection

2016-04-08 Thread Adriano Ferreira via swift-users
Hi Milos, Thanks for getting back to me this quickly. Well, this part specifically was more of a curiosity based on Jens’ comment: “If Limb is a Component, then a Spider entity needs eight of them…” I also confess I’m unsure about this… so please don’t bother then. Looking forward to hearing y

Re: [swift-users] Checking/getting custom objects from a collection

2016-04-08 Thread Milos Rankovic via swift-users
> “If Limb is a Component, then a Spider entity needs eight of them…” That’s a fair question to ask. My intuition is that sporting a `Component` answers a question, “does it have this feature?” In the case of self-propelling creatures, you’d probably ask, “does it have legs”. On the other hand,

Re: [swift-users] Checking/getting custom objects from a collection

2016-04-08 Thread Adriano Ferreira via swift-users
Milos, Thanks for taking a look at it, I appreciate you suggestion. It’s protocol-oriented, quite different from the idea I was trying to emulate — the one provided by GameplayKit. Well, I tried it and it works great. Now, would you implement those methods differently? mutating func add(comp

Re: [swift-users] Checking/getting custom objects from a collection

2016-04-08 Thread Milos Rankovic via swift-users
> On 8 Apr 2016, at 15:12, Adriano Ferreira wrote: > > Milos, > > Thanks for taking a look at it, I appreciate you suggestion. > > It’s protocol-oriented, quite different from the idea I was trying to emulate > — the one provided by GameplayKit. > > Well, I tried it and it works great. Thou

Re: [swift-users] Checking/getting custom objects from a collection

2016-04-08 Thread Milos Rankovic via swift-users
My message bounced on account of size. I’m sorry if you receive multiple copies of this: > “If Limb is a Component, then a Spider entity needs eight of them…” That’s a fair question to ask. My intuition is that sporting a `Component` answers a question, “does it have this feature?” In the case

Re: [swift-users] Checking/getting custom objects from a collection

2016-04-08 Thread Milos Rankovic via swift-users
Hi Adriano, I’m glad if you are finding this useful. I’ll get back to you on `add` and `remove`, but just let me confirm with you: You actually want to allow multiple, say, `Health` components to be added to your `Character`? Most of the complication in my suggested code comes from trying to pr

Re: [swift-users] Checking/getting custom objects from a collection

2016-04-08 Thread Milos Rankovic via swift-users
A type-uniquing alternative (see my previous message): // Swift 2.2 // Entity-Component System (sketch): protocol Component { static var name: String { get } // not necessary (see comments below) } extension Component { // can be overridden with `let` by conforming types

Re: [swift-users] Checking/getting custom objects from a collection

2016-04-08 Thread Milos Rankovic via swift-users
This is just a sketch. There may be issues down the line (I’ve indicated some with `TODO`s), but it works and you can try it in the playground: // Swift 2.2 // utility: extension Array { func first (_: T.Type) -> T? { for e in self where e is T { return e as? T }

Re: [swift-users] Checking/getting custom objects from a collection

2016-04-07 Thread David Hart via swift-users
Unity, the game engine, uses a component system heavily. It uses C# and retrieves components using generic functions. And no, it doesn't force having a single instance of each component class: http://swiftlang.ng.bluemix.net/#/repl/7be36f2d70a31da3b6ab09b7b89277a4463c23b40c28e1663e56c959a1f3eca8

Re: [swift-users] Checking/getting custom objects from a collection

2016-04-07 Thread Jens Alfke via swift-users
I’m not familiar with this design pattern, but it looks like Entity would just contain an array of Component. That makes add() and remove() straightforward. I’m not sure about your get() method. It sounds as though the implication is that an entity could only contain a single component of a give

[swift-users] Checking/getting custom objects from a collection

2016-04-07 Thread Adriano Ferreira via swift-users
Hi everyone! I’m experimenting with Entity-Component Systems and I’d appreciate if you could help me working on how to check/get custom objects from a collection. The idea is to verify if an entity contains a particular component and, if s