Skip to content

Commit

Permalink
Publish on PyPI.
Browse files Browse the repository at this point in the history
  • Loading branch information
wojciech-graj committed Nov 16, 2024
1 parent 5045c36 commit 31ed509
Show file tree
Hide file tree
Showing 8 changed files with 62 additions and 37 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@
__pycache__/
build/
cydoomgeneric/cydoomgeneric.c
dist/
3 changes: 3 additions & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
include cydoomgeneric/cydoomgeneric.pyx
include cydoomgeneric/cydoomgeneric.pxd
include doomgeneric/*.h
20 changes: 12 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,18 @@ To try it you will need a WAD file (game data). If you don't own the game, share

cyDoomGeneric should run on Linux, MacOS, and Windows.

## Installation

Either install the latest release from PyPI
```sh
pip install cydoomgeneric
```

Or run the following command to build from the repository
```sh
pip install .
```

## Porting

You must implement the `draw_frame` and `get_key` functions.
Expand Down Expand Up @@ -43,14 +55,6 @@ If any function that was passed to `cdg.init` raises an exception during the exe

Some additional documentation can be found in `cydoomgeneric/cydoomgeneric.pyx`.

## Building

To build and install cydoomgeneric, run the following command:

```sh
pip install .
```

## Demo Screenshots

#### Pyplot
Expand Down
29 changes: 6 additions & 23 deletions cydoomgeneric/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -13,41 +13,24 @@
"""

from enum import IntEnum
from typing import Callable, Optional, Sequence
from typing import Any, Callable, Literal, Optional, Sequence

import numpy as np

def init(resx: int,
resy: int,
draw_frame: Callable[[np.ndarray], None],
draw_frame: Callable[
[np.ndarray[tuple[Any, Any, Literal[4]],
np.dtype[np.uint8]]], None],
get_key: Callable[[], Optional[tuple[int, int]]],
sleep_ms: Optional[Callable[[int], None]] = None,
get_ticks_ms: Optional[Callable[[], int]] = None,
set_window_title: Optional[Callable[[str], None]] = None) -> None:
"""
Initializes the doom context.
:param resx:
:param resy:
:param draw_frame: Called every frame. Takes framebuffer as np.ndarray in
shape [resy, resx, 4]. Pixels are BGR.
:param get_key: Called multiple times every frame until input is exhausted.
Return None when input is exhausted. Otherwise, return
(is pressed ~0/1~, key).
:param sleep_ms:
:param get_ticks_ms:
:param set_window_title:
"""
...


def main(argv: Optional[Sequence[str]] = None) -> int:
"""
main(argv) -> int
Run doom. Must be called after init.
:param Optional[Sequence[str]] argv:
"""
...


class Keys(IntEnum):
Expand Down
2 changes: 1 addition & 1 deletion cydoomgeneric/cydoomgeneric.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ cdef extern from "doomgeneric.h":
void (*pDG_SleepMs)(uint32_t) noexcept,
uint32_t (*pDG_GetTicksMs)() noexcept,
int (*pDG_GetKey)(int*, unsigned char*) noexcept,
void (*pDG_SetWindowTitle)(const char*) noexcept) except *
void (*pDG_SetWindowTitle)(const char*) noexcept) noexcept
int dg_main(int argc, char **argv) noexcept


Expand Down
27 changes: 23 additions & 4 deletions cydoomgeneric/cydoomgeneric.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -79,14 +79,27 @@ cdef void __set_window_title(const char *title) noexcept:
sys.exit(1)


def init(resx: int,
resy: int,
draw_frame: Callable[[np.ndarray], None],
get_key: Callable[[int], str],
def init(int resx,
int resy,
draw_frame not None: Callable[[np.ndarray], None],
get_key not None: Callable[[int], str],
sleep_ms: Optional[Callable[[int], None]]=None,
get_ticks_ms: Optional[Callable[[], int]]=None,
set_window_title: Optional[Callable[[str], None]]=None
) -> None:
"""Initializes the doom context.

:param resx:
:param resy:
:param draw_frame: Called every frame. Takes framebuffer as np.ndarray in
shape [resy, resx, 4]. Pixels are BGR.
:param get_key: Called multiple times every frame until input is exhausted.
Return None when input is exhausted. Otherwise, return
(is pressed ~0/1~, key).
:param sleep_ms:
:param get_ticks_ms:
:param set_window_title:
"""
global __draw_frame_f
global __sleep_ms_f
global __get_ticks_ms_f
Expand All @@ -111,6 +124,12 @@ def init(resx: int,


def main(argv: Optional[Sequence[str]]=None) -> int:
"""Runs doom.

Must be called after `init`.

:param Optional[Sequence[str]] argv:
"""
if argv is None:
return cdg.dg_main(0, NULL)

Expand Down
13 changes: 13 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ build-backend = "setuptools.build_meta"
[project]
name = "cydoomgeneric"
description = "Easily portable doom for python"
readme = "README.md"
version = "0.1.0"
authors = [
{name = "Wojciech Graj"}
Expand All @@ -14,6 +15,18 @@ requires-python = ">=3.9"
dependencies = [
"numpy>=1.25"
]
classifiers=[
"Development Status :: 4 - Beta",
"Intended Audience :: Developers",
"License :: OSI Approved :: GNU General Public License v2 or later (GPLv2+)",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Programming Language :: Python :: 3.13",
"Programming Language :: Cython",
]
keywords= ["doom"]

[project.urls]
homepage = "https://github.com/wojciech-graj/cydoomgeneric"
Expand Down
4 changes: 3 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"""

import sys
from typing import Union

import numpy
from Cython.Build import cythonize
Expand Down Expand Up @@ -103,7 +104,7 @@
)

libraries: list[str] = []
define_macros: list[tuple[str, str | None]] = []
define_macros: list[tuple[str, Union[str, None]]] = []
extra_link_args: list[str] = []

if sys.platform == "win32":
Expand All @@ -124,6 +125,7 @@
extra_link_args=extra_link_args,
libraries=libraries),
],
build_dir="build",
language_level=3),
package_data={"cydoomgeneric": ["py.typed", "__init__.pyi"]},
packages=["cydoomgeneric"])

0 comments on commit 31ed509

Please sign in to comment.