Skip to content
This repository was archived by the owner on Apr 23, 2025. It is now read-only.

add Loop, NoLoop, IsLooping and FrameCount #41

Merged
merged 9 commits into from
Jan 26, 2021

Conversation

psampaz
Copy link
Contributor

@psampaz psampaz commented Jan 19, 2021

closes #32 and #39

@codecov
Copy link

codecov bot commented Jan 19, 2021

Codecov Report

Merging #41 (6ea7f0e) into main (6ea7f0e) will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff           @@
##             main      #41   +/-   ##
=======================================
  Coverage   80.59%   80.59%           
=======================================
  Files           9        9           
  Lines         567      567           
=======================================
  Hits          457      457           
  Misses         89       89           
  Partials       21       21           

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 6ea7f0e...fb788c7. Read the comment docs.

@psampaz psampaz force-pushed the noloop-framecount branch 2 times, most recently from cbd9821 to c63088e Compare January 19, 2021 21:32
@psampaz
Copy link
Contributor Author

psampaz commented Jan 19, 2021

@sbinet even if this test https://github.com/go-p5/p5/pull/41/files#diff-e65edbcd5a006378e11ec33d7b121f21a20ec2631433f0b75bfa54e11768e9caR85 passes, if you manually try to run one of the repo examples with NoLoop() the window that open has just a white background.

Is this somehow related with how Gio works?

@sbinet
Copy link
Contributor

sbinet commented Jan 19, 2021

Yes and no.

As Gio is an immediate mode toolkit, one has to redraw the background for every new frame.

That's done here:

p5/proc.go

Line 293 in 6ea7f0e

paint.Fill(ops, clr)

... in 'draw'.

I'll check tomorrow what the equivalent p5js code produces.

@sbinet
Copy link
Contributor

sbinet commented Jan 20, 2021

I've just checked with p5js.

the following:

function setup() {
  background(0,0,0);
  noLoop();
}

function draw() {
  background(255,0,0);
  text(frameCount, 10, 30);
}

produces a red canvas with the number 1 being displayed.
see on https://editor.p5js.org/.

so it would seem p5js draws at least 1 frame and then enters the "frame loop".
ie: (in pseudo-code)

proc.Setup()
// create Gio window, then draw one frame.
proc.Draw()

for evt := range events {
   // ...
   proc.Draw()
}

do you want to give it a stab?

path_test.go Outdated
},
"testdata/path_cube.png",
)
proc.NoLoop()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd move this inside the setup func.

also, I think that to test the noloop/doloop state, I'd use the value of FrameCount as I did in the little code blurb in p5js.

WDYT?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I updated the test.

if the incFrameCount is done with defer the image draws 0. I removed the defer and it is now 1 which is normal.

This does not solve the issue I have here #41 (comment)
Running the actual real example like solar-system it does not work.
The code works, it calls draw once, it increases the frame count by 1, stop the loop but the output is a white screen.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd propose to merge this in and file a new bug report regarding this behaviour.

WDYT?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll take that as a yes and proceed with merging that PR.

psampaz and others added 5 commits January 24, 2021 18:44
Co-authored-by: Sebastien Binet <binet@cern.ch>
Co-authored-by: Sebastien Binet <binet@cern.ch>
func(proc *Proc) {
proc.Text(fmt.Sprintf("%d", proc.FrameCount()), 50, 50)
},
"testdata/framecount.png",
Copy link
Contributor

@sbinet sbinet Jan 25, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

with the code as is, framecount_golden.png displays 1, as does the p5js code.
but according to the documentation of FrameCount (that returns the number of frames displayed since the program's start), some people could interpret the correct answer to be 0.

some (re)wording of the documentation could be devised (but could also be deferred to another PR) to address this 1-off effect.
I suppose it probably isn't too much a big deal however.

@sbinet sbinet merged commit 7612205 into go-p5:main Jan 26, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

p5: implement FrameCount()
2 participants