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

The PPB Modernization Project #690

Draft
wants to merge 3 commits into
base: canon
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 57 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,63 @@ requires = ["setuptools>=30.3.0", "wheel", "setuptools_scm"]
# Actually tell PEP517 tools to call setuptools
build-backend = "setuptools.build_meta"

[project]
dynamic = ["version"]
name = "ppb"
authors = [
{name = "Piper Thunstrom", email="[email protected]"}
]
maintainers = [
{name = "Piper Thunstrom", email="[email protected]"}
]
description = "An Event Driven Python Game Engine"
readme = "README.md"
license = { "file" = "LICENSE.txt" }
classifiers =[
"Development Status :: 4 - Beta",
"Intended Audience :: Education",
"Intended Audience :: Developers",
"License :: OSI Approved :: Artistic License",
"Natural Language :: English",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Topic :: Games/Entertainment",
"Topic :: Software Development :: Libraries",
"Operating System :: OS Independent"
]
requires-python = "> 3.8"
dependencies = [
"PySDL2",
"pysdl2-dll",
"ppb-vector ~= 1.0",
"Deprecated ~= 1.2.12"
]

[project.optional-dependencies]
docs = [
"sphinx",
"furo",
"doc-utils<0.18"
]
tests = [
"pytest",
"hypothesis",
]
upload = [
"setuptools >= 38.6.0",
"wheel >= 0.31.0",
"twine >= 1.11.0",
"pip >= 19"
]

[project.urls]
Homepage = "https://ppb.dev"
Respository = "https://github.com/ppb/pursuedpybear"
Issues = "https://github.com/ppb/pursuedpybear/issues"

[tool.setuptools_scm]
local_scheme = "dirty-tag"
4 changes: 1 addition & 3 deletions requirements-docs.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
sphinx
furo
doc-utils<0.18 # Fix for read the docs default sphinx version. If we update sphinx, test to see if we can remove this.
-e .[docs]
3 changes: 1 addition & 2 deletions requirements-tests.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
pytest
hypothesis
-e .[tests]
5 changes: 1 addition & 4 deletions requirements-upload.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1 @@
setuptools >= 38.6.0
wheel >= 0.31.0
twine >= 1.11.0
pip >= 19
-e .[upload]
5 changes: 1 addition & 4 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1 @@
PySDL2
pysdl2-dll
ppb-vector ~= 1.0
Deprecated ~= 1.2.12
-e .
45 changes: 0 additions & 45 deletions setup.cfg

This file was deleted.

File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Empty file added src/ppb/debug/__init__.py
Empty file.
File renamed without changes.
File renamed without changes.
1 change: 0 additions & 1 deletion ppb/events.py → src/ppb/events.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ def on_update(self, event: Update, signal):
'SceneStopped',
'StopScene',
'Update',

)

# Remember to define scene at the end so the pargs version of __init__() still works
Expand Down
Empty file added src/ppb/features/__init__.py
Empty file.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
4 changes: 2 additions & 2 deletions ppb/sprites.py → src/ppb/sprites.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,11 +116,11 @@ def __image__(self):
try:
klassfile = getfile(klass)
except TypeError:
prefix = Path('.')
prefix = Path('')
else:
if Path(klassfile).name != '__init__.py':
prefix = prefix.parent
if prefix == Path('.'):
if prefix == Path(''):
self.image = ppb.Image(f"{klass.__name__.lower()}.png")
else:
self.image = ppb.Image(f"{prefix!s}/{klass.__name__.lower()}.png")
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Empty file added src/ppb_core/__init__.py
Empty file.
4 changes: 2 additions & 2 deletions ppb/assetlib.py → src/ppb_core/assetlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
import threading
import weakref

import ppb.vfs as vfs
import ppb_core.vfs as vfs
import ppb.events as events
from ppb.systemslib import System
from ppb_core.systemslib import System

__all__ = (
'AssetLoadingSystem',
Expand Down
File renamed without changes.
14 changes: 7 additions & 7 deletions ppb/systems/clocks.py → src/ppb_core/clocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,26 @@

import time

import ppb
import ppb.events as events
from ppb.systemslib import System

import ppb_core.events as events
from ppb_core.systemslib import System
from ppb_core import utils

class Updater(System):

def __init__(self, time_step=0.016, **kwargs):
super().__init__(**kwargs)
self.accumulated_time = 0
self.last_tick = None
self.start_time = None
self.time_step = time_step

def __enter__(self):
self.start_time = ppb.get_time()
self.start_time = utils.get_time()

def on_idle(self, idle_event: events.Idle, signal):
if self.last_tick is None:
self.last_tick = ppb.get_time()
this_tick = ppb.get_time()
self.last_tick = utils.get_time()
this_tick = utils.get_time()
self.accumulated_time += this_tick - self.last_tick
self.last_tick = this_tick
while self.accumulated_time >= self.time_step:
Expand Down
45 changes: 21 additions & 24 deletions ppb/engine.py → src/ppb_core/engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,23 +19,19 @@
from typing import Union
import weakref

import ppb
import ppb.systemslib
from ppb import events
from ppb.assetlib import AssetLoadingSystem
from ppb.gomlib import Children, GameObject
from ppb.gomlib import walk
from ppb.errors import BadChildException
from ppb.errors import NotMyChildError
from ppb.errors import BadEventHandlerException
from ppb.scenes import Scene
from ppb.systems import EventPoller
from ppb.systems import Renderer
from ppb.systems import SoundController
from ppb.systems import Updater
from ppb.utils import LoggingMixin
from ppb.utils import camel_to_snake
from ppb.utils import get_time
# from ppb_core import events
from ppb_core.assetlib import AssetLoadingSystem
from ppb_core.gomlib import Children, GameObject
from ppb_core.gomlib import walk
from ppb_core.errors import BadChildException
from ppb_core.errors import NotMyChildError
from ppb_core.errors import BadEventHandlerException
from ppb_core.scenes import Scene
from ppb_core.clocks import Updater
from ppb_core.systemslib import System
from ppb_core.utils import LoggingMixin
from ppb_core.utils import camel_to_snake
from ppb_core.utils import get_time

_ellipsis = type(...)

Expand Down Expand Up @@ -131,9 +127,9 @@ def add(self, child: GameObject, tags: Iterable[Hashable] = ()) -> GameObject:
if isinstance(tags, (str, bytes)):
raise TypeError("You passed a string instead of an iterable, this probably isn't what you intended.\n\nTry making it a tuple.")

if isinstance(child, ppb.Scene):
if isinstance(child, Scene):
raise TypeError("Scenes must be pushed, not added. You probably want the StartScene or ReplaceScene events.")
elif isinstance(child, ppb.systemslib.System):
elif isinstance(child, System):
if self.entered:
raise RuntimeError("Systems cannot be added while the engine is running")
self._systems.add(child)
Expand All @@ -160,9 +156,9 @@ def remove(self, child: GameObject) -> GameObject:
container.remove(myObject)
"""
# Ugh, this is a copy of the implementation in Children.
if isinstance(child, ppb.Scene):
if isinstance(child, Scene):
raise TypeError("Scenes must be popped, not removed. You probably want the StopScene event.")
elif isinstance(child, ppb.systemslib.System):
elif isinstance(child, System):
if self.entered:
raise RuntimeError("Systems cannot be removed while the engine is running")
try:
Expand Down Expand Up @@ -227,6 +223,8 @@ def has_systems(self):
return bool(self._systems)


DEFAULT_SYSTEMS = [Updater, AssetLoadingSystem]

class GameEngine(GameObject, LoggingMixin):
"""
The core component of :mod:`ppb`.
Expand All @@ -237,8 +235,7 @@ class GameEngine(GameObject, LoggingMixin):
ge.run()
"""
def __init__(self, first_scene: Union[Type, Scene], *,
basic_systems=(Renderer, Updater, EventPoller, SoundController, AssetLoadingSystem),
systems=(), scene_kwargs=None, **kwargs):
systems=tuple(DEFAULT_SYSTEMS), scene_kwargs=None, **kwargs):
"""
:param first_scene: A :class:`~ppb.Scene` type.
:type first_scene: Union[Type, scenes.Scene]
Expand Down Expand Up @@ -274,7 +271,7 @@ def __init__(self, first_scene: Union[Type, Scene], *,
self._last_idle_time = None

# Systems
self.systems_classes = list(chain(basic_systems, systems))
self.systems_classes = list(systems)

@property
def current_scene(self):
Expand Down
File renamed without changes.
4 changes: 2 additions & 2 deletions ppb/gomlib.py → src/ppb_core/gomlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
from typing import Iterator
from typing import Type

from ppb.errors import BadChildException
from ppb.errors import NotMyChildError
from ppb_core.errors import BadChildException
from ppb_core.errors import NotMyChildError


class Children(Collection):
Expand Down
12 changes: 12 additions & 0 deletions src/ppb_core/scenes.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from typing import Callable

from ppb_core.gomlib import GameObject


class Scene(GameObject):

def __init__(self, *, set_up: Callable = None, **props):
super().__init__(**props)

if set_up is not None:
set_up(self)
4 changes: 2 additions & 2 deletions ppb/systemslib.py → src/ppb_core/systemslib.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
the core ppb engine.
"""

import ppb.gomlib
import ppb_core.gomlib


class System(ppb.gomlib.GameObject):
class System(ppb_core.gomlib.GameObject):

def __enter__(self):
pass
Expand Down
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion tests/test_assets.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def clean_assets():
"""
# Note that while AssetLoadingSystem cleans stuff up when it exits, this
# makes sure that the tests start fresh.
ppb.assetlib._executor = DelayedThreadExecutor()
src.ppb.assetlib._executor = DelayedThreadExecutor()


class AssetTestScene(Scene):
Expand Down