Mikeware / SpaceBattleArena

Space Battle Arena is a Programming Game.
GNU General Public License v2.0
15 stars 10 forks source link

Update to Python 3 #163

Open hawkerm opened 4 years ago

hawkerm commented 4 years ago

Plan:

Open Issues:

Auxiliary:

Docs:

To Test:

Started in py3 branch

hawkerm commented 4 years ago

Did quick patch on the boundaries of the network lib for compatibility with client, gets us forward for now. Network lib is oldest part, as it predates the project anyway.

Biggest known problem left is the world wrap-around, looking at that next. Otherwise, we're pretty good???

Will investigate if we can run the existing unit tests from VS Code or not.

hawkerm commented 4 years ago

Found the wrapping issue here in WorldMap: https://github.com/Mikeware/SpaceBattleArena/blob/py3/SBA_Serv/World/WorldMap.py#L222

The vector seems immutable now, but haven't found correct pattern yet.

This is also a problem in the Warp command here: https://github.com/Mikeware/SpaceBattleArena/blob/py3/SBA_Serv/World/WorldCommands.py#L317

hawkerm commented 4 years ago

Hitting this same issue with py2exe, they've changed something, so need to find new paradigm, but not sure what it is. All info around pygame and py2exe seems old.

hawkerm commented 4 years ago

Looks like py2exe is pretty old, seeing if cx_Freeze will work instead.

jaredkrinke commented 4 years ago

Wow, division changed between Python 2 and 3 🙄

http://python-future.org/compatible_idioms.html#division

I could only repro on the py3 branch (and not the master branch). I'm on Python 3.7.6 with dependencies from requirements.txt.

Repro: Use mousewheel and click to spawn a wormhole Hit "d" to turn on debug mode

Result: Crash

2020-02-13 15:16:50,335|5153|ERROR|MainThread|main|697|startGame|FATAL Error in GUI!!!
Traceback (most recent call last):
  File "C:\Users\jared\Code\SpaceBattleArena\SBA_Serv\GUI\main.py", line 274, in startGame
    obj.draw(worldsurface, flags)
  File "C:\Users\jared\Code\SpaceBattleArena\SBA_Serv\GUI\ObjWrappers\WormHoleWrapper.py", line 43, in draw
    wrapcircle(surface, c, intpos(self._worldobj.exit.body.position), self._worldobj.radius / 2, self._world.size, 2) # 'target'
  File "C:\Users\jared\Code\SpaceBattleArena\SBA_Serv\GUI\Helpers.py", line 31, in wrapcircle
    pygame.draw.circle(surface, color, pos, radius, thickness)
TypeError: integer argument expected, got float
2020-02-13 15:16:50,340|5158|ERROR|MainThread|main|698|startGame|Traceback (most recent call last):
  File "C:\Users\jared\Code\SpaceBattleArena\SBA_Serv\GUI\main.py", line 274, in startGame
    obj.draw(worldsurface, flags)
  File "C:\Users\jared\Code\SpaceBattleArena\SBA_Serv\GUI\ObjWrappers\WormHoleWrapper.py", line 43, in draw
    wrapcircle(surface, c, intpos(self._worldobj.exit.body.position), self._worldobj.radius / 2, self._world.size, 2) # 'target'
  File "C:\Users\jared\Code\SpaceBattleArena\SBA_Serv\GUI\Helpers.py", line 31, in wrapcircle
    pygame.draw.circle(surface, color, pos, radius, thickness)
TypeError: integer argument expected, got float

Log file: SBA_Serv2020-02-13_151646.log

hawkerm commented 4 years ago

@jaredkrinke started a py3-unittest branch that runs in VS 2019. Started fixing a few unit tests like the failing PlayerStat ones. Haven't looked at the above WormHole one yet, but that should be an easy fix, probably easiest to switch to // floor division to make sure there's an int.

hawkerm commented 4 years ago

The Unit Tests seem to be mostly working, they seem to have trouble running all together, but run fine individually. Timing can still be an issue... that's a whole other problem. They've at least helped identify some issues with Py3 and PyMunk5, so it's been helpful.

hawkerm commented 4 years ago

@jaredkrinke think I have a fix for the wormholewrapper I'm going to push in a minute.

Found another issue that I'm not sure about yet though:

Traceback (most recent call last):
  File "C:\code\SpaceBattleArena\SBA_Serv\GUI\main.py", line 127, in addorremove
    bgobjects[obj.id] = NebulaGUI(obj, world)
  File "C:\code\SpaceBattleArena\SBA_Serv\GUI\ObjWrappers\NebulaWrapper.py", line 13, in __init__
    super(NebulaGUI, self).__init__(nebula, world)
  File "C:\code\SpaceBattleArena\SBA_Serv\GUI\ObjWrappers\GUIEntity.py", line 20, in __init__
    self._points = self.get_world_points(self._worldobj)
  File "C:\code\SpaceBattleArena\SBA_Serv\GUI\ObjWrappers\GUIEntity.py", line 85, in get_world_points
    points += [(vertex.rotated(worldobj.body.angle) + worldobj.body.position).int_tuple]
  File "C:\code\SpaceBattleArena\SBA_Serv\env\lib\site-packages\pymunk\vec2d.py", line 481, in __get_int_xy
    return int(self.x), int(self.y)
ValueError: cannot convert float NaN to integer

Happened when deleting stuff from the world in the Server GUI.

jaredkrinke commented 4 years ago

FYI: I see that error every time I run the server (with no arguments).

jaredkrinke commented 4 years ago

I see the problem. In PhysicalEllipse.__init__, the following division should have been left as a float division (in the py3 branch, it truncates to zero so all the points in the polygon end up being the same):

    def __init__(self, size, mass, pos, segments=16):
        ...
        ang = math.pi * 2 // segments
hawkerm commented 4 years ago

Ah, thanks @jaredkrinke! That's a recent change I did, I was over-aggressive on my changes back to int division.