The Inbox: MorphicExtras-ct.260.mcz

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

The Inbox: MorphicExtras-ct.260.mcz

commits-2
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@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!


cbc
Reply | Threaded
Open this post in threaded view
|

Re: The Inbox: MorphicExtras-ct.260.mcz

cbc
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 <[hidden email]> 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@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!




cbc
Reply | Threaded
Open this post in threaded view
|

Re: The Inbox: MorphicExtras-ct.260.mcz

cbc
hmm. I didn't notice the use of TimeStamp.  We should stop using that subclass where possible and not include any new uses in the base image. 

On Wed, Sep 4, 2019, 09:39 Chris Cunningham <[hidden email]> wrote:
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 <[hidden email]> 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@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!




Reply | Threaded
Open this post in threaded view
|

Re: The Inbox: MorphicExtras-ct.260.mcz

Christoph Thiede
In reply to this post by cbc

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 <[hidden email]> im Auftrag von Chris Cunningham <[hidden email]>
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 <[hidden email]> 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@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!




Carpe Squeak!
cbc
Reply | Threaded
Open this post in threaded view
|

Re: The Inbox: MorphicExtras-ct.260.mcz

cbc
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.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 <[hidden email]> 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 <[hidden email]> im Auftrag von Chris Cunningham <[hidden email]>
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 <[hidden email]> 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@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!





Reply | Threaded
Open this post in threaded view
|

Re: The Inbox: MorphicExtras-ct.260.mcz

Christoph Thiede

Thank you very much for the tutorial!


I would not assume that all morphs are currently stepping. What would be the best way to pass information (a list of stopped morphs) from prescript to postscript?

A class var? SmalltalkImage? Is there any Metacello cache for things like that?


Best,

Christoph


Von: Squeak-dev <[hidden email]> im Auftrag von Chris Cunningham <[hidden email]>
Gesendet: Mittwoch, 4. September 2019 23:27:15
An: The general-purpose Squeak developers list
Betreff: Re: [squeak-dev] The Inbox: MorphicExtras-ct.260.mcz
 
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.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 <[hidden email]> 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 <[hidden email]> im Auftrag von Chris Cunningham <[hidden email]>
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 <[hidden email]> 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@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!





Carpe Squeak!
Reply | Threaded
Open this post in threaded view
|

Re: The Inbox: MorphicExtras-ct.260.mcz

marcel.taeumel
Hi Christoph,

preamble and postscript are per package. I suppose that all FrameRateMorph instances are stepping. I would rather not add a global variable to pass information between scripts.

Also, morphs do not step between code loading and postscript evaluation. So you should be fine with a single postscript:

FrameRateMorph allInstances do: [:frm|
   frm stopStepping.
   frm instVarNamed: #lastDisplayTime put: DateAndTime now.
   frm startStepping].

Best,
Marcel

Am 05.09.2019 00:42:55 schrieb Thiede, Christoph <[hidden email]>:

Thank you very much for the tutorial!


I would not assume that all morphs are currently stepping. What would be the best way to pass information (a list of stopped morphs) from prescript to postscript?

A class var? SmalltalkImage? Is there any Metacello cache for things like that?


Best,

Christoph


Von: Squeak-dev <[hidden email]> im Auftrag von Chris Cunningham <[hidden email]>
Gesendet: Mittwoch, 4. September 2019 23:27:15
An: The general-purpose Squeak developers list
Betreff: Re: [squeak-dev] The Inbox: MorphicExtras-ct.260.mcz
 
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 (
).  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 <[hidden email]> 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 <[hidden email]> im Auftrag von Chris Cunningham <[hidden email]>
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 <[hidden email]> 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@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!