solent-eng / solent

Free software sequencer architecture
GNU Lesser General Public License v3.0
7 stars 4 forks source link

Rename track reference function #84

Closed cratuki closed 7 years ago

cratuki commented 7 years ago

There is a kind of object called a Track. It is used to listen to the nearcast, but never to interact with it. It is useful in particular for consolidating business-logic code in a single place, whilst letting multiple cogs access it. it is also useful for only accumulating knowledge in RAM once, rather than once for each cog.

Currently we attach it to a cog like this,

class TrackSample:
    def __init__(self, orb):
        self.orb = orb
        #
        self.b_started = False
    def on_init(self):
        self.b_started = True

class CogBlah:
    def __init__(self, cog_h, orb, engine):
        ...
        #
        self.orb.reference_track(TrackSample)

It is laborious to write 'reference_track'. Let's just change it to 'track'.

cratuki commented 7 years ago

I was weighing up whether this was too trivial to justify effort. But having done it, it is clear that it is a marked improvement.

Whilst I was in there, I added in some validation to check that the user is passing in a class, rather than an instance of it. This would be a trap-for-young-players style of error. I am impementing this via inspect. Inspect is fine here, because it is not an event-loop overhead.

Previously we often had two verbose lines to create a track.

self.track_blah = self.orb.reference_track(
    construct=TrackClass)

The construct parameter was useful to reenforce to the user that we should pass in a class.

Now, we can do this with confidence,

self.track_blah = self.orb.track(TrackClass)

It has taken a while for the Track concept to become a first-class concept in solent. It now feels like it is.