GithubHelp home page GithubHelp logo

davidbuchanan314 / pyswargol Goto Github PK

View Code? Open in Web Editor NEW
32.0 2.0 0.0 56 KB

A rather fast Game-of-Life implementation in pure Python (plus pysdl2)

License: MIT License

Python 100.00%
cgol game-of-life game-of-life-python multithreading pysdl2 python python3 sdl2 swar

pyswargol's Introduction

pyswargol

$ python3 swargol.py --help
Usage: swargol.py [OPTIONS]

Render Conway's Game of Life via SDL2, unreasonably quickly.

Options:
  --width=INT          framebuffer width (default: 1280)
  --height=INT         framebuffer height (default: 720)
  --vsync=BOOL         enable vsync (default: True)
  --fullscreen         enable fullscreen
  --drylife=BOOL       use the non-standard "drylife" algorithm (default: True)
  --slow               use the very slow implementation (for benchmark comparisons)
  --frameskip=INT      only render 1-in-n frames to the screen (default: 1)
  --num-procs=INT      degree of parallelism (NB: number of actual threads will be 2n+1) (default: 8)
  --bench-frames=INT   render a certain number of frames and then exit (default: 0)

Other actions:
  -h, --help           Show the help

I've written an article explaining more about how and why this code works.

image

pyswargol's People

Contributors

davidbuchanan314 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

pyswargol's Issues

Exception: SDL_ConvertSurfaceFormat: Blit combination not supported

Great blog post!
I wanted to try this out, but I get this error (on Ubuntu 22.04/x86_64):

Config: LifeConfig(width=1280, height=720, vsync=True, fullscreen=False, drylife=True, slow=False, frameskip=1, num_procs=8, bench_frames=0)
Exception in thread Thread-2 (blit_thread):
Traceback (most recent call last):
  File "/home/david/tmp/pyswargol/.pixi/env/lib/python3.12/threading.py", line 1073, in _bootstrap_inner
    self.run()
  File "/home/david/tmp/pyswargol/.pixi/env/lib/python3.12/threading.py", line 1010, in run
    self._target(*self._args, **self._kwargs)
  File "/home/david/tmp/pyswargol/swargol.py", line 251, in blit_thread
    raise Exception("SDL_ConvertSurfaceFormat: " + sdl2.SDL_GetError().decode())
Exception: SDL_ConvertSurfaceFormat: Blit combination not supported
Exception in thread Thread-1 (blit_thread):
Traceback (most recent call last):
  File "/home/david/tmp/pyswargol/.pixi/env/lib/python3.12/threading.py", line 1073, in _bootstrap_inner
    self.run()
  File "/home/david/tmp/pyswargol/.pixi/env/lib/python3.12/threading.py", line 1010, in run
    self._target(*self._args, **self._kwargs)
  File "/home/david/tmp/pyswargol/swargol.py", line 251, in blit_thread
    raise Exception("SDL_ConvertSurfaceFormat: " + sdl2.SDL_GetError().decode())
Exception: SDL_ConvertSurfaceFormat: Blit combination not supported
Exception in thread Thread-3 (blit_thread):
Traceback (most recent call last):
  File "/home/david/tmp/pyswargol/.pixi/env/lib/python3.12/threading.py", line 1073, in _bootstrap_inner
    self.run()
  File "/home/david/tmp/pyswargol/.pixi/env/lib/python3.12/threading.py", line 1010, in run
    self._target(*self._args, **self._kwargs)
  File "/home/david/tmp/pyswargol/swargol.py", line 251, in blit_thread
    raise Exception("SDL_ConvertSurfaceFormat: " + sdl2.SDL_GetError().decode())
Exception: SDL_ConvertSurfaceFormat: Blit combination not supported
Exception in thread Thread-4 (blit_thread):
Traceback (most recent call last):
  File "/home/david/tmp/pyswargol/.pixi/env/lib/python3.12/threading.py", line 1073, in _bootstrap_inner
    self.run()
  File "/home/david/tmp/pyswargol/.pixi/env/lib/python3.12/threading.py", line 1010, in run
Exception in thread Thread-5 (blit_thread):
Traceback (most recent call last):
    self._target(*self._args, **self._kwargs)
  File "/home/david/tmp/pyswargol/swargol.py", line 251, in blit_thread
  File "/home/david/tmp/pyswargol/.pixi/env/lib/python3.12/threading.py", line 1073, in _bootstrap_inner
    raise Exception("SDL_ConvertSurfaceFormat: " + sdl2.SDL_GetError().decode())
    self.run()
  File "/home/david/tmp/pyswargol/.pixi/env/lib/python3.12/threading.py", line 1010, in run
Exception: SDL_ConvertSurfaceFormat: Blit combination not supported
Exception in thread Thread-8 (blit_thread):
Exception in thread Thread-6 (blit_thread):
Traceback (most recent call last):
  File "/home/david/tmp/pyswargol/.pixi/env/lib/python3.12/threading.py", line 1073, in _bootstrap_inner
    self._target(*self._args, **self._kwargs)
  File "/home/david/tmp/pyswargol/swargol.py", line 251, in blit_thread
Exception in thread Thread-7 (blit_thread):
Traceback (most recent call last):
  File "/home/david/tmp/pyswargol/.pixi/env/lib/python3.12/threading.py", line 1073, in _bootstrap_inner
    self.run()
    raise Exception("SDL_ConvertSurfaceFormat: " + sdl2.SDL_GetError().decode())
  File "/home/david/tmp/pyswargol/.pixi/env/lib/python3.12/threading.py", line 1010, in run
Exception: SDL_ConvertSurfaceFormat: Blit combination not supported
    self.run()
    self._target(*self._args, **self._kwargs)
  File "/home/david/tmp/pyswargol/.pixi/env/lib/python3.12/threading.py", line 1010, in run
  File "/home/david/tmp/pyswargol/swargol.py", line 251, in blit_thread
    self._target(*self._args, **self._kwargs)
  File "/home/david/tmp/pyswargol/swargol.py", line 251, in blit_thread
    raise Exception("SDL_ConvertSurfaceFormat: " + sdl2.SDL_GetError().decode())
    raise Exception("SDL_ConvertSurfaceFormat: " + sdl2.SDL_GetError().decode())
Exception: SDL_ConvertSurfaceFormat: Blit combination not supported
Exception: SDL_ConvertSurfaceFormat: Blit combination not supported
Traceback (most recent call last):
  File "/home/david/tmp/pyswargol/.pixi/env/lib/python3.12/threading.py", line 1073, in _bootstrap_inner
    self.run()
  File "/home/david/tmp/pyswargol/.pixi/env/lib/python3.12/threading.py", line 1010, in run
    self._target(*self._args, **self._kwargs)
  File "/home/david/tmp/pyswargol/swargol.py", line 251, in blit_thread
    raise Exception("SDL_ConvertSurfaceFormat: " + sdl2.SDL_GetError().decode())
Exception: SDL_ConvertSurfaceFormat: Blit combination not supported

TODO

  • Fix exit cleanup process
  • Make Ctrl+C do something sensible...
  • create config object to get passed around
  • Add CLI options
  • Fullscreen mode
  • Support non-evenly-divisible heights
  • Optimise frameskip (only serialise whole frame when needed)
  • Option to load custom patterns
  • Naive computation option (for perf comparison purposes)
  • Numpy/scipy computation option (likewise) - genuinely curious whether it's faster

SDL Issue

Hello, I installed sdl etc but when i launch the program it says me this :

Traceback (most recent call last):
File "C:\Users\nayth\PycharmProjects\pyswargol\swargol.py", line 444, in
main(cfg)
File "C:\Users\nayth\PycharmProjects\pyswargol\swargol.py", line 363, in main
raise Exception("Failed to init SDL2")
Exception: Failed to init SDL2

Do you have any idea on how to fix this ? Thank you for your help.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.