[squeak-dev] The Inbox: MorphicExtras-ct.260.mcz
Chris Cunningham
cunningham.cb at gmail.com
Wed Sep 4 21:27:15 UTC 2019
A nicer way to do this is to use the preamble and postscript. With your
version loaded (and changed to use DateAndTime), in the Morphic browser,
choose the Scripts button (
[image: image.png]). Then choose "edit preamble" to edit the preamble
script.
Then, add the script to the window that pops up and save it.
The script might look something like:
FrameRateMorph allInstances do: [:frm|
frm stopStepping.
frm instVarNamed: #lastDisplayTime put: DateAndTime now.
].
Then, choose scripts again and edit postscript. In that editor, add code
that start the stepping again. (Also, you'll need to remove the old
postscript - it actively fails.)
Then, save the new version and test it.
Scripts are nice for one-shot updates.
-cbc
On Wed, Sep 4, 2019 at 12:06 PM Thiede, Christoph <
Christoph.Thiede at student.hpi.uni-potsdam.de> wrote:
> Hi, thanks for feedback!
>
>
> I have no experience with upgrade scripts, how can we keep the code clean?
> Is it possible to have Metacello load a temporary version first and then
> load the final version, or are there any better patterns?
>
>
> For a temporary version, we could prepend the following code to the #step
> method:
>
>
> self updateInterval ifNil: [
> "Upgrade existing instance"
> lastDisplayTime := DateAndTime new.
> self updateInterval: 500 milliSeconds].
>
> Probably it would be a bad idea to have the method recompile itself after
> executing the upgrade part? ;)
>
> Best,
>
> Christoph
>
>
> PS: Yes, there was no special reason to use TimeStamp, except of
> [TimeStamp name size < DateAndTime name size] :)
> ------------------------------
> *Von:* Squeak-dev <squeak-dev-bounces at lists.squeakfoundation.org> im
> Auftrag von Chris Cunningham <cunningham.cb at gmail.com>
> *Gesendet:* Mittwoch, 4. September 2019 18:39:13
> *An:* The general-purpose Squeak developers list
> *Betreff:* Re: [squeak-dev] The Inbox: MorphicExtras-ct.260.mcz
>
> Hi.
>
> I like the changes (especially the switch to DateAndTime), however, if you
> have a FrameRateMorph open when updating, it raises errors and fails to
> work (the time to timestamp gives it issues).
>
> Any chance you could prescript to fix this? Maybe either update existing
> instances with DateAndTimes and stop/start stepping around the update, or
> closing all instances (although I'm not sure if that is advisable with the
> comments about 'stand-alone entity' in initializeToStandAlone, which
> implies there are embedded instances).
>
> -cbc
>
> On Wed, Sep 4, 2019 at 6:54 AM <commits at source.squeak.org> wrote:
>
>> A new version of MorphicExtras was added to project The Inbox:
>> http://source.squeak.org/inbox/MorphicExtras-ct.260.mcz
>>
>> ==================== Summary ====================
>>
>> Name: MorphicExtras-ct.260
>> Author: ct
>> Time: 4 September 2019, 3:53:54.175698 pm
>> UUID: cab65f78-e646-cc40-9d0f-c16114d1bb44
>> Ancestors: MorphicExtras-mt.259
>>
>> Refactor FrameRateMorph: Add accessors for updateInterval and expose
>> measure data. Use TimeStamp instead of Time to avoid clock wrap around.
>>
>> =============== Diff against MorphicExtras-mt.259 ===============
>>
>> Item was changed:
>> StringMorph subclass: #FrameRateMorph
>> + instanceVariableNames: 'lastDisplayTime framesSinceLastDisplay
>> updateInterval mSecsPerFrame framesPerSec'
>> - instanceVariableNames: 'lastDisplayTime framesSinceLastDisplay'
>> classVariableNames: ''
>> poolDictionaries: ''
>> category: 'MorphicExtras-Demo'!
>>
>> Item was added:
>> + ----- Method: FrameRateMorph>>framesPerSec (in category 'accessing')
>> -----
>> + framesPerSec
>> +
>> + ^ framesPerSec!
>>
>> Item was changed:
>> ----- Method: FrameRateMorph>>initialize (in category 'initialization')
>> -----
>> initialize
>> "initialize the state of the receiver"
>> super initialize.
>> ""
>> + lastDisplayTime := TimeStamp new.
>> - lastDisplayTime := 0.
>> framesSinceLastDisplay := 0.
>> + self updateInterval: 500 milliSeconds.
>> self font: (Preferences standardMenuFont emphasized: 1).
>> !
>>
>> Item was added:
>> + ----- Method: FrameRateMorph>>mSecsPerFrame (in category 'accessing')
>> -----
>> + mSecsPerFrame
>> +
>> + ^ mSecsPerFrame!
>>
>> Item was changed:
>> ----- Method: FrameRateMorph>>step (in category 'stepping and
>> presenter') -----
>> step
>> "Compute and display (every half second or so) the current
>> framerate"
>>
>> + | now timePassed newContents |
>> - | now mSecs mSecsPerFrame framesPerSec newContents |
>> framesSinceLastDisplay := framesSinceLastDisplay + 1.
>> + now := TimeStamp now.
>> + timePassed := now - lastDisplayTime.
>> + (timePassed > self updateInterval) ifTrue:
>> + [| mSecs |
>> + mSecs := timePassed asMilliSeconds.
>> + mSecsPerFrame := mSecs // framesSinceLastDisplay.
>> - now := Time millisecondClockValue.
>> - mSecs := now - lastDisplayTime.
>> - (mSecs > 500 or: [mSecs < 0 "clock wrap-around"]) ifTrue:
>> - [mSecsPerFrame := mSecs // framesSinceLastDisplay.
>> framesPerSec := (framesSinceLastDisplay * 1000) // mSecs.
>> newContents := mSecsPerFrame printString, ' mSecs (',
>> framesPerSec printString, ' frame', (framesPerSec = 1 ifTrue: [''] ifFalse:
>> ['s']), '/sec)'.
>> self contents: newContents.
>> lastDisplayTime := now.
>> framesSinceLastDisplay := 0]
>> ifFalse:
>> ["Ensure at least one pixel is drawn per frame"
>> Preferences higherPerformance ifTrue: [self invalidRect:
>> (self position extent: 1 at 1)]]!
>>
>> Item was added:
>> + ----- Method: FrameRateMorph>>updateInterval (in category 'accessing')
>> -----
>> + updateInterval
>> +
>> + ^ updateInterval!
>>
>> Item was added:
>> + ----- Method: FrameRateMorph>>updateInterval: (in category 'accessing')
>> -----
>> + updateInterval: aNumber
>> +
>> + updateInterval := aNumber!
>>
>>
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.squeakfoundation.org/pipermail/squeak-dev/attachments/20190904/fdbf7d59/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image.png
Type: image/png
Size: 1158 bytes
Desc: not available
URL: <http://lists.squeakfoundation.org/pipermail/squeak-dev/attachments/20190904/fdbf7d59/attachment.png>
More information about the Squeak-dev
mailing list
|