Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Port to python3 and other fixes #20

Merged
merged 14 commits into from Apr 23, 2020
Merged

Port to python3 and other fixes #20

merged 14 commits into from Apr 23, 2020

Conversation

JuiP
Copy link
Member

@JuiP JuiP commented Apr 18, 2020

The activity was designed for specific pixel display, so everything was out of focus when I tested master on Sugar VM (800x600). These changes fixed it for me. I scaled the dimensions proportionately.

Please review the changes till d56b3dd @quozl @chimosky ! :)

I also took the opportunity to port the activity to python3, that is still in progress...

@JuiP
Copy link
Member Author

JuiP commented Apr 18, 2020

Update- While testing my changes in 7ad9a6c , I get this error. Just noticed that reviewing changes for Physics Activity for Port to Python3 might help. I know PyClass_Type is a Python 2 type but I'm not sure if the error as relates to PR #19 ?

ImportError: elements/box2d_64/_Box2D.so: undefined symbol: PyClass_Type

@JuiP JuiP mentioned this pull request Apr 18, 2020
@JuiP JuiP changed the title Change activity element dimensions to fit aspect ratio of 16:9 Port to python3 and other fixes Apr 18, 2020
Copy link
Member

@Saumya-Mishra9129 Saumya-Mishra9129 left a comment

Choose a reason for hiding this comment

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

Reviewed, I would suggest testing your changes once with #19 . I guess this could help in this error -

ImportError: elements/box2d_64/_Box2D.so: undefined symbol: PyClass_Type

@quozl
Copy link
Contributor

quozl commented Apr 20, 2020

Agreed. Now that #19 is merged, please rebase on new master. You may also need to install Box2D for Python 3.

@JuiP
Copy link
Member Author

JuiP commented Apr 20, 2020

While rebasing there were multiple conflicts and my local branch diverged from origin/Fixes so I preferred to cherry-pick commits to a new branch origin/Python3.... Closing this PR but still working on the issue in branch Python3

@JuiP JuiP closed this Apr 20, 2020
@chimosky
Copy link
Member

I was expecting something to go wrong as 99ae5b0 was included here when it shouldn't have been.
Let us know if we can help, you didn't have to close this PR.

@JuiP
Copy link
Member Author

JuiP commented Apr 20, 2020

While rebasing, I checked out origin/master and then git pull upstream master and git push to have my master updated with sugarlabs/master
Later while I git rebase master on my remote branch origin/Fixes the branch diverged from my remote branch as a result I faced the same problem as mentioned in https://stackoverflow.com/questions/42861353/git-pull-after-git-rebase

mistakes I made while git rebase:

  • didnot do git pull on origin/Fixes before rebasing
  • and didnot force push after resolving conflicts
    I hadn't faced this issue before, nevermind, learning new stuff the hard way.
    It was too messy and time-consuming to get that fixed so I preferred to cherry-pick my commits to a different branch

@chimosky
Copy link
Member

Firstly, you didn't have to git pull origin/Fixes. I've found out that sometimes fixing the problem isn't as time consuming as you might think.
I'm on irc #sugar right now, you can come online and ping me so we'll talk about it.

@JuiP
Copy link
Member Author

JuiP commented Apr 20, 2020

Sorry I just read your comment, will definitely like to know how to get this fixed !! It's kind of irritating to just desert the issues without finding a work-around! I will ping you when you are online tomorrow :)

@JuiP JuiP mentioned this pull request Apr 20, 2020
@quozl
Copy link
Contributor

quozl commented Apr 20, 2020

The social problem with a new pull request is that the relevant discussion on the changes is split across multiple browser pages and different notification threads in mail.

I agree with @chimosky, and will put it slightly differently; there's never a need to close a pull request in order to handle a git conflict. It is best to fix the conflicts properly. At worst you can rewrite your commits in a new branch, then git reset the pull request branch to point at the same commit as the head of the new branch. In fact you could do this now and reopen, but never mind.

For your interest, a rebase at the time I suggested it (7ad9a6c) can go like this;

$ git fetch origin  # fetch the new master commits
$ git fetch origin pull/20/head  # fetch commits from this pull request
$ git checkout 7ad9a6c  # position to the pull request at the time
$ git log --oneline --graph -5  # view the commits back to and including master at the time
* 7ad9a6c (HEAD) Update to sugargame version=1.3
* cdc4a07 Run 2to3
* d56b3dd Change activity elements dimensions to fit aspect ratio of 16:9
* 8204123 fix several flake8 errors and warnings
* 5209c4b (master) Port from GObject to GLib
$ git rebase origin/master  # rebase on the new master
First, rewinding head to replay your work on top of it...
Applying: Change activity elements dimensions to fit aspect ratio of 16:9
Applying: Run 2to3
Applying: Update to sugargame version=1.3
$ git log --oneline --graph -4  # view the new commits back to and including new master
* f4aac25 (HEAD) Update to sugargame version=1.3
* 0899f35 Run 2to3
* 9440e01 Change activity elements dimensions to fit aspect ratio of 16:9
* 99ae5b0 (origin/master, origin/HEAD) Replace box2d binaries with Box2D upstream

There were no conflicts this way.

@JuiP
Copy link
Member Author

JuiP commented Apr 21, 2020

As I have shifted this pr anyway, I'm going to try all sort of things to get this branch fixed too. In the process I may stumble upon new things I didn't know about git..... Just googling my way through this now, I will surely ask more specific questions if I am stuck at some point. Thankyou so much for helping! :)

@quozl
Copy link
Contributor

quozl commented Apr 21, 2020

There are some other hacks you can practice to recover from things you don't yet understand;

  • keep a complete backup of your repository using rsync or tar in some other place on your computer, so that you can restore the backup and (if you had pushed) git push --force to return the pull request to the state it was in before,
  • if you've not yet pushed changes you don't want to keep, or if you want to backtrack, note the git hash shown by the pull request, use git reset to repoint the branch at that commit, then (if you had pushed) git push --force to return the pull request to that state.

Beware of googling; some advice predates new features or defaults of git that make it easier.

@JuiP
Copy link
Member Author

JuiP commented Apr 21, 2020

I got my branch Fixes fixed with git reset HEAD@{42} and then git push -f origin Fixes. Now my branch is how it was supposed to be. However, I can not reopen this PR as it says Fixes branch was force-pushed or recreated

For reference these might be useful to make my process more clear:
jui@debian:/usr/share/sugar/activities/Bridge.activity$ git reflog
2c20dcd (HEAD -> Fixes, origin/Fixes) HEAD@{0}: checkout: moving from Python3 to Fixes
44a23d8 (origin/Python3, Python3) HEAD@{1}: cherry-pick: Port lib/myelements to python3
15b9fa5 HEAD@{2}: checkout: moving from pr1 to Python3
941c6d8 (pr1) HEAD@{3}: checkout: moving from Python3 to pr1
15b9fa5 HEAD@{4}: cherry-pick: Update to sugargame version=1.3
0e00edd HEAD@{5}: cherry-pick: Run 2to3
906dd07 HEAD@{6}: cherry-pick: Change activity elements dimensions to fit aspect ratio of 16:9
99ae5b0 (upstream/master, origin/master, origin/HEAD, master) HEAD@{7}: checkout: moving from master to Python3
99ae5b0 (upstream/master, origin/master, origin/HEAD, master) HEAD@{8}: checkout: moving from Fixes to master
2c20dcd (HEAD -> Fixes, origin/Fixes) HEAD@{9}: rebase: updating HEAD
2c20dcd (HEAD -> Fixes, origin/Fixes) HEAD@{10}: rebase: updating HEAD
12733ac HEAD@{11}: commit (merge): Merge branch 'Fixes' of https://github.com/JuiP/Bridge into HEAD
d37a82d HEAD@{12}: rebase: Update to sugargame version=1.3
c8ec55b HEAD@{13}: rebase: Run 2to3
10f9f81 HEAD@{14}: rebase: Change activity elements dimensions to fit aspect ratio of 16:9
99ae5b0 (upstream/master, origin/master, origin/HEAD, master) HEAD@{15}: rebase: checkout 99ae5b0
2c20dcd (HEAD -> Fixes, origin/Fixes) HEAD@{16}: rebase: updating HEAD
2c20dcd (HEAD -> Fixes, origin/Fixes) HEAD@{17}: rebase: updating HEAD
39d5ec5 HEAD@{18}: rebase: Replace box2d binaries with Box2D upstream
7ad9a6c HEAD@{19}: rebase: checkout 7ad9a6c
2c20dcd (HEAD -> Fixes, origin/Fixes) HEAD@{20}: rebase -i (abort): updating HEAD
2c20dcd (HEAD -> Fixes, origin/Fixes) HEAD@{21}: rebase -i (abort): updating HEAD
0b73bdc HEAD@{22}: rebase -i (start): checkout 9c97683
2c20dcd (HEAD -> Fixes, origin/Fixes) HEAD@{23}: rebase -i (abort): updating HEAD
2c20dcd (HEAD -> Fixes, origin/Fixes) HEAD@{24}: rebase -i (abort): updating HEAD
613ae02 HEAD@{25}: rebase -i (pick): Replace box2d binaries with Box2D upstream
7ad9a6c HEAD@{26}: rebase -i (start): checkout 7ad9a6c
2c20dcd (HEAD -> Fixes, origin/Fixes) HEAD@{27}: commit (merge): Merge branch 'Fixes' of https://github.com/JuiP/Bridge into Fixes
0b73bdc HEAD@{28}: rebase finished: returning to refs/heads/Fixes
0b73bdc HEAD@{29}: rebase: Update to sugargame version=1.3
1e7de36 HEAD@{30}: rebase: Change activity elements dimensions to fit aspect ratio of 16:9
9c97683 HEAD@{31}: rebase: Update to sugargame version=1.3
4db9225 HEAD@{32}: rebase: Run 2to3
04154cf HEAD@{33}: rebase: Change activity elements dimensions to fit aspect ratio of 16:9
99ae5b0 (upstream/master, origin/master, origin/HEAD, master) HEAD@{34}: rebase: checkout master
8dcf476 HEAD@{35}: rebase: updating HEAD
8dcf476 HEAD@{36}: rebase: updating HEAD
7cde18b HEAD@{37}: rebase: Update to sugargame version=1.3
c2f6b69 HEAD@{38}: rebase: Run 2to3
f3d13c5 HEAD@{39}: rebase: Change activity elements dimensions to fit aspect ratio of 16:9
99ae5b0 (upstream/master, origin/master, origin/HEAD, master) HEAD@{40}: rebase: checkout master
8dcf476 HEAD@{41}: pull origin Fixes: Merge made by the 'recursive' strategy.
670c1e2 HEAD@{42}: rebase finished: returning to refs/heads/Fixes
670c1e2 HEAD@{43}: rebase: Update to sugargame version=1.3
e59d6da HEAD@{44}: rebase: Run 2to3
97ef445 HEAD@{45}: rebase: Change activity elements dimensions to fit aspect ratio of 16:9
99ae5b0 (upstream/master, origin/master, origin/HEAD, master) HEAD@{46}: rebase: checkout master
7ad9a6c HEAD@{47}: checkout: moving from master to Fixes
99ae5b0 (upstream/master, origin/master, origin/HEAD, master) HEAD@{48}: pull upstream master: Fast-forward
8204123 HEAD@{49}: checkout: moving from Fixes to master
7ad9a6c HEAD@{50}: pull origin Fixes: Fast-forward
cdc4a07 HEAD@{51}: reset: moving to HEAD
cdc4a07 HEAD@{52}: commit: Run 2to3
d56b3dd HEAD@{53}: rebase finished: returning to refs/heads/Fixes
d56b3dd HEAD@{54}: rebase: Change activity elements dimensions to fit aspect ratio of 16:9
8204123 HEAD@{55}: rebase: checkout master
becfdb4 HEAD@{56}: checkout: moving from master to Fixes
8204123 HEAD@{57}: pull upstream master: Fast-forward
5209c4b HEAD@{58}: checkout: moving from Fixes to master
becfdb4 HEAD@{59}: commit: Change activity elements dimensions to fit aspect ratio of 16:9
5209c4b HEAD@{60}: reset: moving to HEAD
5209c4b HEAD@{61}: checkout: moving from master to Fixes
5209c4b HEAD@{62}: clone: from https://github.com/JuiP/Bridge.git

After HEAD@42,
$ git push origin my-branch
To git@github.com:itsananderson/foo.git
! [rejected] my-branch -> my-branch (non-fast-forward)
error: failed to push some refs to 'git@github.com:itsananderson/foo.git'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Integrate the remote changes (e.g.
hint: 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.

After googling, what I found was that my remote branch Fixes was different from my local branch Fixes which resulted in the above error when I tried to push. After rebasing, the reapplied commits have different hash therefore are considered as different commits. So at this step the a git push origin Fixes -f was expected but instead I did the error of git pull origin Fixes, now this resulted in fetching the HEAD of my remote branch Fixes. This fetched the remote Fixes which wasn't rebased, as a result there were conflicts as the changes in local Fixes were different from remote Fixes.
The messages I got when I tried rebasing before were exactly these https://imgur.com/a/Wcqjmo9
I went ahead with the changes and this merged my local Fixes with remote Fixes as seen in 2c20dcd. The commits from 1e7de36 are the ones due to merge conflicts between remote and local Fixes.
Alternatively, what I actually should have done was used git push origin Fixes -f after HEAD@{42}. I think, by resetting the head at this point I have successfully achieved the expected result now but can't reopen this PR. (I still need to google what can be done about reopening the PR)

I really hope I have properly understood what went wrong, could you confirm if what I stated is actually the case? @quozl

@quozl
Copy link
Contributor

quozl commented Apr 21, 2020

Ok. Please do continue to experiment, as it is good learning. I've not been in this situation with respect to not being able to reopen a pull request, but you may be able to reopen by using git reset to repoint your Fixes branch to the last git hash here (2c20dcd) and git push --force to your repository. Or perhaps not, I don't know for sure. GitHub is closed source, so we don't and can't know what it relies upon to make the "Reopen and comment" button unavailable.

Regarding the messages when you tried to rebase; that was caused by your earlier merge of the remote Fixes branch into your local Fixes branch, and;

  • if that happened to me, I would have immediately aborted the rebase because I knew that the patches I was rebasing against should have had no conflicts at all, (in turn because I would have reviewed the patches and what files they change, e.g. git log --stat, or git log --patch),
  • but anyway, could have been resolved by editing out the conflicts and markers injected by git into the source, and then continuing the rebase (for which you must use an editor that knows when file on disk has been changed),

Thanks for the git reflog. Unfortunately it does not show any steps which did not change HEAD, such as a git push, so I can't easily see what went wrong, but I do see some rebases that look to have been done with incorrect upstream or branch.

@JuiP
Copy link
Member Author

JuiP commented Apr 21, 2020

Finallyyyy!! This mess is cleaned and fixed perfectly(Perfectly.... I hope so @chimosky @quozl). The way I got this done was-

  • noted the current commit hash of my PR-branch git log --oneline -1 Fixes which was 670c1e2
  • git push -f origin 2c20dcd:Fixes (the commit here is the last commit before I closed this PR, this will fetch the HEAD for this PR)
  • Reopened the PR
  • git push -f origin 670c1e2:Fixes (commit I noted)
    And this fixed it

I found a similar issue reported by some user: https://www.bountysource.com/issues/8777850-allow-to-reopen-pull-requests-after-a-force-push
The reply on the issue by GitHub:

We're blocking the pull request reopen if the current head isn't a descendant of the stored head sha (which is what the head was when the pull request was closed). We are not allowing the reopen in that case, because there is no good way to tell what changes have happened while a pull request was closed and the head branch has changed.

I think their point is that Github tracks a reflog of every HEAD change while the PR is open (for... some reason?), but doesn't do this tracking when the pull request is closed, so they can't construct a history between what the branch's HEAD was when the PR was last open and what the HEAD of the PR's branch is now. I find that weird because when we push to the remote branch they still have the track to where the HEAD of the PR branch is! Nevermind there seems to be an issue with how they chose to disable the Reopen and comment button.
It was a good learning experience and I definitely never thought I might come across some GitHub issue! 😃

@chimosky
Copy link
Member

Yes everything is good now, thanks for sharing how you fixed it.

I think their point is that Github tracks a reflog of every HEAD change while the PR is open (for... some reason?), but doesn't do this tracking when the pull request is closed, so they can't construct a history between what the branch's HEAD was when the PR was last open and what the HEAD of the PR's branch is now.

Yes you're right, Github tracks every commit that's been made until the PR was closed that's why you had to force push 2c20dcd first to get your remote up to the last commit before you closed the PR hence making reopening the PR possible, the force push of 670c1e2 could also work as it used to be 7ad9a6c before your rebase and they now had a common parent 99ae5b0 which is HEAD at master.

@quozl
Copy link
Contributor

quozl commented Apr 22, 2020

Good to see my speculation was right. I see the branch has been rebased. Thanks.

I get a ModuleNotFoundError in lib/myelements. Do you?

@JuiP
Copy link
Member Author

JuiP commented Apr 22, 2020

Well yes! lib/myelements is not ported to python3 in this branch after rebasing which was done in Python3 branch..... I will apply the changes here! :)

@quozl
Copy link
Contributor

quozl commented Apr 22, 2020

Thanks. I did then cherry-pick 44a23d8 and test.

  • the toolbar appears but the canvas does not.

This could be related to the call to show_all in the toolbar method, which is a pattern we have seen before that may cause this. It changes the order of creation of the X11 windows.

This could be related to how physics.run calls pygame.init, which therefore displaces the initialisation done carefully by the PygameCanvas.

In short, it looks like your port to Sugargame 1.3 has not followed the new API and test activity.

@JuiP
Copy link
Member Author

JuiP commented Apr 22, 2020

@quozl made the required changes and tested, works for me.... Can you test again and merge? :)

Copy link
Member

@srevinsaju srevinsaju left a comment

Choose a reason for hiding this comment

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

Great. There are some minor changes required. I have not tested it, these changes are part of code review alone.

lib/myelements/camera.py Show resolved Hide resolved
lib/myelements/camera.py Show resolved Hide resolved
lib/myelements/drawing.py Show resolved Hide resolved
lib/myelements/elements.py Show resolved Hide resolved
@@ -593,7 +593,7 @@ def json_load(self, path, additional_vars={}):
jointDef.maxMotorTorque = joint['maxMotorTorque']
self.world.CreateJoint(jointDef)

for (k, v) in worldmodel['additional_vars'].items():
for (k, v) in list(worldmodel['additional_vars'].items()):
Copy link
Member

Choose a reason for hiding this comment

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

This change can also be omitted

Copy link
Member Author

Choose a reason for hiding this comment

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

I think, this change was made when you ran 2to3 to port lib/myelements and is a required change. .items() return a copy of the dictionary’s list of (key, value) pairs in python 2. However, in python 3 versions, items() returns iterators and never builds a list fully.

Copy link
Member

Choose a reason for hiding this comment

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

As I have looked at Pippy and Physics activities, they have ported to Python3 before and we must follow those changes as they have been checked.

Copy link
Member

Choose a reason for hiding this comment

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

I think, this change was made when you ran 2to3 to port lib/myelements

Yes,

and is a required change. .items() return a copy of the dictionary’s list of (key, value) pairs in python 2. However, in python 3 versions, items() returns iterators and never builds a list fully.

No, list() operation takes a lot of CPU than returning the iterator

Run this

from timeit import timeit
# timeit is a module to return the time taken by a line to complete
timeit("from itertools import permutations, product; permutations((product([1,2,3], [1,2,3])))")
timeit("from itertools import permutations, product; list(permutations(product([1,2,3], [1,2,3])))")

@JuiP why do you think?

And what is the necessity of keeping the list() too? The for loop works without it too?

activity.py Outdated Show resolved Hide resolved
bridge.py Outdated Show resolved Hide resolved
bridge.py Outdated Show resolved Hide resolved
physics.py Show resolved Hide resolved
tools.py Outdated
@@ -344,7 +344,7 @@ def cancel(self):

def getAllTools():
this_mod = __import__(__name__)
all = [val for val in this_mod.__dict__.values() if isinstance(val, type)]
all = [val for val in list(this_mod.__dict__.values()) if isinstance(val, type)]
Copy link
Member

Choose a reason for hiding this comment

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

I guess the list() operator was not necessary. Moreover all is a built in function that changed from python2 to python3. It might be better to change all variable name to something different so that it does not shadow the builtin function

@srevinsaju
Copy link
Member

srevinsaju commented Apr 22, 2020

I tested it, works good, no errors, but something unusual happens for me. ( I can confirm this is not a part of my system configuration)
Peek 2020-04-22 08-14

As you might see, the circles which fell down of the screen in one instance, appears from the sky again on the next level. This might be because the fallen objects are not destroyed once its out of the screen boundary. Although it might not be a part of this PR, I just wanted to bring attention to it as a future issue, if its not a part of this port. (Please ignore the screen flickering, that is not the issue, the issue pointed out is the circles falling again and again)

During the pause stage, If I add multiple very huge circles, and sometimes if the circles overlap with each other, this happens

  File "/run/media/ss/ARCH_DATA/git/Bridge/physics.py", line 73, in run
    self.currentTool.handleEvents(event, self.bridge)
  File "/run/media/ss/ARCH_DATA/git/Bridge/tools.py", line 101, in handleEvents
    if not super(CircleTool, self).handleEvents(event, bridge):
  File "/run/media/ss/ARCH_DATA/git/Bridge/tools.py", line 45, in handleEvents
    self.game.bridge.create_train()
  File "/run/media/ss/ARCH_DATA/git/Bridge/bridge.py", line 165, in create_train
    self.world.add.distanceJoint(
  File "lib/myelements/add_objects.py", line 578, in distanceJoint
    self.parent.world.CreateJoint(jointDef)
  File "/usr/lib/python3.8/site-packages/Box2D/Box2D.py", line 3405, in CreateJoint
    return self.__CreateJoint(defn)
AssertionError: def->bodyA != def->bodyB

And, finally a fun thing I had devised of 😄
Peek 2020-04-22 08-22

🤣 I can pass all levels of this game with 0 cost using the force function

@JuiP
Copy link
Member Author

JuiP commented Apr 22, 2020

Wow! This is hilarious!! 🤣
http://wiki.laptop.org/go/Bridge mentions:

The Circle and Grab tools are only present for debugging and playing around. They will be removed in future releases.
They were not removed and so you can pass the level with zero cost!

I guess this was not taken care of in the code even before the port

circles which fell down of the screen in one instance, appears from the sky again on the next level.
During the pause stage, If I add multiple very huge circles, and sometimes if the circles overlap with each other, traceback:

@quozl
Copy link
Contributor

quozl commented Apr 22, 2020

Yes, exactly. This is one of those activities where intentional maintenance stopped. An activity's existence in our organisation doesn't mean it should necessarily be maintained. If you can improve it and fix it so it works, great.

@srevinsaju
Copy link
Member

srevinsaju commented Apr 22, 2020

@JuiP Did you fix the screen factoring problem on 8694d00?

@JuiP
Copy link
Member Author

JuiP commented Apr 22, 2020

#20 (comment) check this out

Copy link
Member

@srevinsaju srevinsaju left a comment

Choose a reason for hiding this comment

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

Thanks @JuiP,

Now the Bridge Activity supports multiple resolutions, 8694d00 It also works on portrait mode too.

Few more important points to consider for the future:

  • Can erase the train
    The train, apparently can be erased. This helps to gain negative cost (or profit), It should be against game ideology to erase the train the gain profit and win the game.

  • Remove the hand button and circle.
    Regarding the falling circles error I mentioned in the previous review, it would be better to remove the hand and circle tool, or let it be available on the detection of a particular environment variable.

import os
if os.getenv("DEBUG"):
   # add Circle and Hand tools

or something similar.

Apart from that, this PR might be an improvement over themaster.

@JuiP
Copy link
Member Author

JuiP commented Apr 22, 2020

Remove the hand button and circle.
Regarding the falling circles error I mentioned in the previous review, it would be better to remove the hand and circle tool, or let it be available on the detection of a particular environment variable.

Though the developers intended to remove them, I think having them makes the activity a little more interesting! Have a look at this case, you can use the hand so that the train passes over the circle. What do you think @chimosky @quozl @srevinsaju ?
Screenshot from 2020-04-22 17-14-20
Screenshot from 2020-04-22 14-56-52

If we decide to keep them in further releases, the issues which need to be fixed are:

  • Destroy the falling object. I checked the code, the rectangles which are a part of the bridge are destroyed. However, the circle is not considered a part of the bridge and is not destroyed when box_deleted() is called. To confirm this, only the circle appears from the sky in the next level.

  • user should not be able to erase the train

  • Also fix negative costs. There is something weird with circles as they were developed only to experiment. Try drawing a circle, it does not increment the cost at all, but when you delete it you get a negative cost. Similar happens with the train.

  • get rid of the other PyBox2D assertion errors. (Honestly I have not been able to reproduce these errors, I tried drawing multiple cirlces even tried with larger overlapping circles)

  • Fix the grab hand such that you can't pass a train over to the other side with zero cost.

@chimosky
Copy link
Member

chimosky commented Apr 22, 2020

Though the developers intended to remove them, I think having them makes the activity a little more interesting! Have a look at this case, you can use the hand so that the train passes over the circle. What do you think @chimosky @quozl @srevinsaju ?

I think it should be left as part of the game, it's something that a child will have to figure out themselves and that happens when they use the activity. That could also teach them about bugs.

This is shown in the logs, although I can't tell how to reproduce as it happened just the first time I tested and didn't happen again.

Traceback (most recent call last):
  File "/home/ibiam/Activities/Bridge/physics.py", line 73, in run
    self.currentTool.handleEvents(event, self.bridge)
  File "/home/ibiam/Activities/Bridge/tools.py", line 304, in handleEvents
    if super(BridgeJointTool, self).handleEvents(event, bridge):
  File "/home/ibiam/Activities/Bridge/tools.py", line 51, in handleEvents
    self.game.bridge.create_train(force=True)
  File "/home/ibiam/Activities/Bridge/bridge.py", line 175, in create_train
    btrain[0], ftrain[0], backlink, frontlink)
  File "lib/myelements/add_objects.py", line 578, in distanceJoint
    self.parent.world.CreateJoint(jointDef)
  File "/usr/local/lib/python3.7/dist-packages/Box2D/Box2D.py", line 6269, in CreateJoint
    return self.__CreateJoint(defn)
  File "/usr/local/lib/python3.7/dist-packages/Box2D/Box2D.py", line 6008, in __CreateJoint
    return _Box2D.b2World___CreateJoint(self, defn)
AssertionError: def->bodyA != def->bodyB
1587566527.447753 ERROR root: Event queue full!
1587566527.479532 ERROR root: Event queue full!
1587566527.499084 ERROR root: Event queue full!
1587566527.528706 ERROR root: Event queue full!
Traceback (most recent call last):
  File "/home/ibiam/Activities/Bridge/sugargame/event.py", line 141, in _quit_cb
    pygame.event.post(pygame.event.Event(pygame.QUIT))
pygame.error: Event queue full
Traceback (most recent call last):
  File "/home/ibiam/Activities/Bridge/sugargame/event.py", line 130, in _screen_changed_cb
    self.update_display()
  File "/home/ibiam/Activities/Bridge/sugargame/event.py", line 123, in update_display
    pygame.event.post(pygame.event.Event(pygame.VIDEOEXPOSE))
pygame.error: Event queue full

Also you could change the text that shows when T is pressed as that text shows after the first press provided the train doesn't fall off, that might mean setting a limit to how many T's can be pressed while there's a train on the screen. Continuously pressing T keeps the trains coming and eventually leads to some trains forming with some parts loose.

@srevinsaju
Copy link
Member

Yes @chimosky, I was able to get the same Box2D assertion errors, and the Trains errors which caused, sometimes just wheels to come out as a result, and the rectangles of the train left out etc..

@JuiP
Copy link
Member Author

JuiP commented Apr 22, 2020

This is shown in the logs, although I can't tell how to reproduce as it happened just the first time I tested and didn't happen again.

Well I tested again, tried all sorts of things. AssertionError occured when I tried pressing T multiple times this caused what @srevinsaju and @chimosky pointed out

sometimes just wheels to come out as a result, and the rectangles of the train left out.
Also you could change the text that shows when T is pressed as that text shows after the first press provided the train doesn't fall off, that might mean setting a limit to how many T's can be pressed while there's a train on the screen. Continuously pressing T keeps the trains coming and eventually leads to some trains forming with some parts loose.

I fixed this in 697c804. Pressing T will no longer connect it to the event creating a train until the train exits.

I can pass all levels of this game with 0 cost using the force function

@srevinsaju you can no longer do this after 0a39b95 😀

@JuiP
Copy link
Member Author

JuiP commented Apr 22, 2020

I don't plan on fixing these issues in this PR, maybe will raise an issue.

  • Destroy the falling object. I checked the code, the rectangles which are a part of the bridge are destroyed. However, the circle is not considered a part of the bridge and is not destroyed when box_deleted() is called. To confirm this, only the circle appears from the sky in the next level.
  • user should not be able to erase the train

Maybe these observations may help: tokill returns False when trying to erase the Lawn rectangles as get_bodies_at_pos returns False when the given point (screen coordinates) is not inside any body. However, this is not the case for train, its clear by looking at method create_train in bridge.py. Therefore tokill is a list in case of the train objects.

@quozl @chimosky Please review and merge! :)

@quozl
Copy link
Contributor

quozl commented Apr 23, 2020

Thanks. Tested. Reviewed changes since my last review. Reviewed aggregate change. Is a substantial improvement; the activity works now, and can be used for the purpose. I agree with others there are some other improvements that can be made, but I think I'm ready to merge.

If you've suggested an improvement, raise an issue. If you wish to work on an improvement, raise a pull request, not an issue. 😁 🦘

@quozl quozl merged commit 5fda06b into sugarlabs:master Apr 23, 2020
@JuiP JuiP deleted the Fixes branch May 12, 2020 12:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants