Skip to content

Commit

Permalink
Merge pull request #25 from pimoroni/stats
Browse files Browse the repository at this point in the history
SDK: Refactor game loop, add stats.
  • Loading branch information
Gadgetoid authored Oct 20, 2021
2 parents 5e6a0d6 + 3890e25 commit 0c7de5e
Show file tree
Hide file tree
Showing 25 changed files with 411 additions and 88 deletions.
213 changes: 213 additions & 0 deletions .flake8
Original file line number Diff line number Diff line change
@@ -0,0 +1,213 @@
[flake8]
ignore =
E501,
F405,
F403
builtins =
Buffer,
Voice,
pen,
tick,
init,
reset,
play,
clip,
blend,
target,
camera,
spritesheet,
clear,
pixel,
line,
hline,
vline,
rect,
frect,
circle,
fcircle,
ellipse,
fellipse,
poly,
fpoly,
blit,
sprite,
text,
text_width,
rgb,
hsv,
intersects,
intersection,
contains,
pressed,
button,
battery,
led,
backlight,
UP,
DOWN,
LEFT,
RIGHT,
A,
B,
X,
Y,
COPY,
ALPHA,
MASK,
CHERRY,
APPLE,
BANANA,
ORANGE,
AUBERGINE,
CARROT,
POTATO,
LEAF,
PARSNIP,
MEAT,
BEAN,
RADISH,
STRAWBERRY,
PUMPKIN,
CUCUMBER,
SALT1,
SWORD1,
SWORD2,
SWORD3,
AXE1,
DAGGER,
MACE1,
BOW,
ARROW1,
ARROW2,
ARROW3,
TRIDENT1,
SPEAR,
TRIDENT2,
MACHINEGUN,
PISTOL,
SHOTGUN,
GEM1,
GEM2,
GEM3,
GEM4,
GEM5,
GEM6,
AMULET,
FOLDER,
COIN1,
IDOL1,
IDOL2,
IDOL3,
IDOL4,
SWEETCORN,
BROCCOLI,
BISCUIT,
BERRIES,
SCEPTRE,
FIRE,
LASERGUN1,
LASERGUN2,
HELMET1,
HELMET2,
HELMET3,
HELMET4,
__1,
__2,
__3,
__4,
HEART1,
SLIME,
COIN2,
SWORD4,
SWORD5,
__5,
DYNAMITE,
MEDPACK,
GOGGLES,
HELMET5,
BOMB,
OILCAN,
SHIRT1,
SHIRT2,
SPEECH,
DREAM,
HEART2,
HEART3,
HEART4,
__6,
TORCH,
ICE,
__7,
__8,
__9,
__10,
UPARROW,
RING1,
RING2,
RING3,
RING4,
__11,
TOKEN,
VIAL1,
VIAL2,
RING5,
RING6,
BLOCK1,
BLOCK2,
BLOCK3,
BLOCK4,
BLOCK5,
BLOCK6,
BLOCK7,
BLOCK8,
BLOCK9,
SHIELD1,
SACK,
BUTTON,
VIAL3,
VIAL4,
TOOTH,
BONE,
HALFBLOCK1,
HALFBLOCK2,
HALFBLOCK3,
HALFBLOCK4,
HALFBLOCK5,
HALFBLOCK6,
HALFBLOCK7,
HALFBLOCK8,
HALFBLOCK9,
SHIELD2,
SHIELD3,
FLOWER1,
FLOWER2,
FLOWER3,
FLOWER4,
STAFF1,
STAFF2,
STAFF3,
STICK1,
SPIKEBALL,
MACE2,
AXE2,
__12,
SWORD6,
SWORD7,
SWORD8,
CROWN1,
GOLD,
GEM7,
GEM8,
GEM9,
AXE3,
MUSHROOM,
SALT2,
STICK2,
VIAL5,
VIAL6,
DOT,
HELMET6,
SWORD9,
SWORD10,
SWORD11,
CROWN2,
4 changes: 2 additions & 2 deletions .github/workflows/python.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@ jobs:
- name: Lint
shell: bash
run: |
python3 -m flake8 --ignore E501,F405,F821,F403 micropython/examples
python3 -m flake8 --ignore E501,F405,F821,F403,F401 micropython/modules_py
python3 -m flake8 micropython/examples
python3 -m flake8 --ignore E501,F405,F403,F401 micropython/modules_py
2 changes: 1 addition & 1 deletion examples/audio/audio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ void draw_dial(std::string name, int32_t x, int32_t y) {
}

// draw the world
void draw() {
void draw(uint32_t tick) {
// draw top row of dials
pen(10, 12, 4);
frect(0, 60, 240, 60);
Expand Down
2 changes: 1 addition & 1 deletion examples/colour/colour.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ void draw_slider(slider_t &slider, int32_t x, int32_t y) {
frect(x + 2, y + h - sh - 2, w - 4, sh);
}

void draw() {
void draw(uint32_t tick) {
// clear the screen
pen(1, 1, 1);
clear();
Expand Down
2 changes: 1 addition & 1 deletion examples/music/music.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ void update(uint32_t tick) {
}

// draw the world
void draw() {
void draw(uint32_t tick) {
// reset the camera and clear the framebuffer
camera();
pen(1, 2, 3);
Expand Down
12 changes: 11 additions & 1 deletion examples/shapes/shapes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ void label(std::string s) {
text(s + ":", 2, 15);
}

void draw() {
void draw(uint32_t tick) {
pen(0, 0, 0);
clear();

Expand Down Expand Up @@ -147,4 +147,14 @@ void draw() {
frect(0, 0, 120, 11);
pen(0, 0, 0);
text("Shapes Test", 2, 2);

pen(0, 0, 0, 8);
frect(0, 60, 120, 60);

pen(15, 15, 15);
text("fps: " + str(stats.fps), 10, 70);
text("draw us: " + str(stats.draw_us), 10, 80);
text("update us: " + str(stats.update_us), 10, 90);
text("tick us: " + str(stats.tick_us), 10, 100);
text("idle: " + str(stats.idle) + "%", 10, 110);
}
2 changes: 1 addition & 1 deletion examples/snake/snake.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ void update(uint32_t tick) {
}

// draw the world
void draw() {
void draw(uint32_t tick) {
// clear the screen in noxious 3310 backlight green and draw everything in
// a faint blended black to get that cheap 90s LCD feel
pen(10, 12, 0);
Expand Down
2 changes: 1 addition & 1 deletion examples/sprites/sprites.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ float deg_to_rad(float d) {
}

// draw the world
void draw() {
void draw(uint32_t tick) {
// clear the background
pen(2, 3, 4);
clear();
Expand Down
2 changes: 1 addition & 1 deletion examples/text/text.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ void update(uint32_t tick) {
wrap_width = (fsin(time() / 1000.0f) * 40.0f) + 76;
}

void draw() {
void draw(uint32_t tick) {
pen(0, 0, 0);
clear();

Expand Down
5 changes: 2 additions & 3 deletions libraries/hardware.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,6 @@ namespace picosystem {
#ifndef NO_OVERCLOCK
// overclock the rp2040 to 250mhz
set_sys_clock_khz(250000, true);

#endif

// configure control io pins
Expand Down Expand Up @@ -366,7 +365,7 @@ namespace picosystem {
_screen_command(VRHS, 1, "\x12");
_screen_command(VDVS, 1, "\x20");
_screen_command(PWRCTRL1, 2, "\xA4\xA1");
_screen_command(FRCTRL2, 1, "\x0f");
_screen_command(FRCTRL2, 1, "\x15");
_screen_command(GMCTRP1, 14, "\xD0\x04\x0D\x11\x13\x2B\x3F\x54\x4C\x18\x0D\x0B\x1F\x23");
_screen_command(GMCTRN1, 14, "\xD0\x04\x0C\x11\x13\x2C\x3F\x44\x51\x2F\x1F\x1F\x20\x23");
_screen_command(INVON);
Expand Down Expand Up @@ -399,7 +398,7 @@ namespace picosystem {

// initialise dma channel for transmitting pixel data to screen
// via the screen updating pio program
dma_channel = 0; //dma_claim_unused_channel(true); // avoid MicroPython soft-reset timebomb
dma_channel = 0;
dma_channel_config config = dma_channel_get_default_config(dma_channel);
channel_config_set_bswap(&config, true);
channel_config_set_dreq(&config, pio_get_dreq(screen_pio, screen_sm, true));
Expand Down
Loading

0 comments on commit 0c7de5e

Please sign in to comment.