Skip to content
Merged
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
18 changes: 8 additions & 10 deletions examples/benchmark.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import gc
import random
Expand All @@ -26,15 +25,20 @@

MAX_ENTITIES = options.entities
if MAX_ENTITIES <= 500:
print("The number of entities must be greater than 500.")
sys.exit(1)
sys.exit("The number of entities must be greater than 500.")

if options.walltime:
print("Benchmarking wall clock time...\n")
time_query = time.time
else:
time_query = time.process_time

if options.plot:
try:
from matplotlib import pyplot as plt
except ImportError:
sys.exit("The matplotlib module is required for plotting results.")


##########################
# Simple timing decorator:
Expand Down Expand Up @@ -264,13 +268,7 @@ def dynamic_world_frame(entities_to_kill, new_entities_to_create):
if not options.plot:
print("\nRun 'benchmark.py --help' for details on plotting this benchmark.")

if options.plot:
try:
from matplotlib import pyplot as plt
except ImportError:
print("\nThe matplotlib module is required for plotting results.")
sys.exit(1)

else:
plt.figure(1)
lines = []
for num, result in results.items():
Expand Down
17 changes: 7 additions & 10 deletions examples/benchmark_cache.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import sys
import time
Expand All @@ -9,12 +8,6 @@

import esper

try:
from matplotlib import pyplot
except ImportError:
print("The matplotlib module is required for this benchmark.")
raise Exception

######################
# Commandline options:
######################
Expand All @@ -25,9 +18,13 @@
(options, arguments) = parser.parse_args()

MAX_ENTITIES = options.entities
if MAX_ENTITIES <= 50:
print("The number of entities must be greater than 500.")
sys.exit(1)
if MAX_ENTITIES <= 500:
sys.exit("The number of entities must be greater than 500.")

try:
from matplotlib import pyplot
except ImportError:
sys.exit("The matplotlib module is required for plotting results.")


##########################
Expand Down
10 changes: 7 additions & 3 deletions examples/pygame_example.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
import pygame
#!/usr/bin/env python
from pathlib import Path

import pygame
import esper


FPS = 60
RESOLUTION = 720, 480

# Parent dir of this script, to find the PNGs regardless of cwd
path = Path(__file__).parent

##################################
# Define some Components:
Expand Down Expand Up @@ -81,10 +85,10 @@ def run():
# Initialize Esper world, and create a "player" Entity with a few Components.
player = esper.create_entity()
esper.add_component(player, Velocity(x=0, y=0))
esper.add_component(player, Renderable(image=pygame.image.load("redsquare.png"), posx=100, posy=100))
esper.add_component(player, Renderable(image=pygame.image.load(path / "redsquare.png"), posx=100, posy=100))
# Another motionless Entity:
enemy = esper.create_entity()
esper.add_component(enemy, Renderable(image=pygame.image.load("bluesquare.png"), posx=400, posy=250))
esper.add_component(enemy, Renderable(image=pygame.image.load(path / "bluesquare.png"), posx=400, posy=250))

# Create some Processor instances, and asign them to be processed.
render_processor = RenderProcessor(window=window)
Expand Down
3 changes: 2 additions & 1 deletion examples/pyglet_example.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#!/usr/bin/env python
import pyglet
import esper

Expand Down Expand Up @@ -29,8 +30,8 @@ class MovementProcessor:
def __init__(self, minx, maxx, miny, maxy):
super().__init__()
self.minx = minx
self.miny = miny
self.maxx = maxx
self.miny = miny
self.maxy = maxy

def process(self, dt):
Expand Down
12 changes: 8 additions & 4 deletions examples/pysdl2_example.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
#!/usr/bin/env python
from pathlib import Path
from sdl2 import *
import sdl2.ext as ext
import esper


RESOLUTION = 720, 480

# Parent dir of this script, to find the PNGs regardless of cwd
path = Path(__file__).parent

##################################
# Define some Components:
Expand Down Expand Up @@ -66,7 +70,7 @@ def process(self):
destination.y = int(rend.y)
destination.w = rend.w
destination.h = rend.h
SDL_RenderCopy(self.renderer.renderer, rend.texture, None, destination)
SDL_RenderCopy(self.renderer.sdlrenderer, rend.texture, None, destination)
self.renderer.present()


Expand All @@ -76,7 +80,7 @@ def process(self):
def texture_from_image(renderer, image_name):
"""Create an SDL2 Texture from an image file"""
soft_surface = ext.load_image(image_name)
texture = SDL_CreateTextureFromSurface(renderer.renderer, soft_surface)
texture = SDL_CreateTextureFromSurface(renderer.sdlrenderer, soft_surface)
SDL_FreeSurface(soft_surface)
return texture

Expand All @@ -94,11 +98,11 @@ def run():
# Initialize Esper world, and create a "player" Entity with a few Components.
player = esper.create_entity()
esper.add_component(player, Velocity(x=0, y=0))
esper.add_component(player, Renderable(texture=texture_from_image(renderer, "redsquare.png"),
esper.add_component(player, Renderable(texture=texture_from_image(renderer, str(path / "redsquare.png")),
width=64, height=64, posx=100, posy=100))
# Another motionless Entity:
enemy = esper.create_entity()
esper.add_component(enemy, Renderable(texture=texture_from_image(renderer, "bluesquare.png"),
esper.add_component(enemy, Renderable(texture=texture_from_image(renderer, str(path / "bluesquare.png")),
width=64, height=64, posx=400, posy=250))

# Create some Processor instances, and asign them to be processed.
Expand Down
Loading