From 5a68efb9118ba0dc6ed194ccc56aefc13c939dc3 Mon Sep 17 00:00:00 2001 From: thisiscamk <100883750+thisiscamk@users.noreply.github.com> Date: Wed, 2 Dec 2026 21:11:15 +0800 Subject: [PATCH] orchard-blocks: add touch GPU demo Package the native SDL2 falling-block game for AArch64 tablets. It provides touch and keyboard controls, automatic play, procedural audio, and an uncapped frame-rate display for exercising the OpenGL ES GPU path. Assisted-by: LLM Signed-off-by: thisiscamk <100883750+thisiscamk@users.noreply.github.com> --- CHANGELOG.md | 4 + README.md | 1 + packages/orchard-blocks/arch/PKGBUILD | 28 +++ packages/orchard-blocks/orchard-blocks.c | 216 ++++++++++++++++++ .../orchard-blocks/orchard-blocks.desktop | 9 + packages/orchard-blocks/source.json | 5 + 6 files changed, 263 insertions(+) create mode 100644 packages/orchard-blocks/arch/PKGBUILD create mode 100644 packages/orchard-blocks/orchard-blocks.c create mode 100644 packages/orchard-blocks/orchard-blocks.desktop create mode 100644 packages/orchard-blocks/source.json diff --git a/CHANGELOG.md b/CHANGELOG.md index c9b6fce..cf31dea 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,10 @@ to `main` publishes every changed version at once, so when merging, rename ## Unreleased +### orchard-blocks 0.1.0-1 + +- Adds Orchard Blocks, a touch-friendly falling-block game and uncapped GPU demonstration with automatic play and audio. + ### Updates follow releases - The kernel packages and `omarchy-a` move to a new orchard or Omarchy A diff --git a/README.md b/README.md index 6a63904..a15cba8 100644 --- a/README.md +++ b/README.md @@ -27,6 +27,7 @@ built for both. | `folio-touch` | yes | yes | Files: Folio with touch mode, from the `touch-mode` branch of [OrchardLinux/folio](https://github.com/OrchardLinux/folio), pinned to a commit until the fork tags a release newer than 0.4.0 (`v0.4.1`; its tag `a0.2.0-1` is no version tag). Provides `folio` and conflicts with upstream Omarchy's. | | `omafox` | yes | yes | Firefox follows the Omarchy theme. | | `omacalc` | - | yes | Omarchy's calculator, which upstream Omarchy publishes for 64-bit only. | +| `orchard-blocks` | yes | - | A touch-friendly falling-block game and uncapped GPU demonstration, rendered through SDL2 and OpenGL ES. | | `omarchy-a` | yes | yes | Omarchy A's own files: the touch desktop, its configuration and system defaults, from [OrchardLinux/omarchy-a](https://github.com/OrchardLinux/omarchy-a), built with its Makefile. Follows its releases; nothing is built until its first release that builds this way. Conflicts with upstream Omarchy's `omarchy`. | | `linux-orchard-apple-16k`, `linux-orchard-apple-4k` | yes | - | orchard's kernel, modules, the boards' device trees, initrd and hardware defaults for A9 and later (16 KiB pages) or A7 to A8X: an orchard release's platform layer, installed unchanged by a plain PKGBUILD and APKBUILD; orchard's installer installs this package. Its pacman hooks (apk: scripts and trigger) run orchard's `boot-entries`, which keeps the system's boot entries current and the previous kernel as a fallback. The two conflict. | | `linux-orchard-apple-armv7` | - | yes | The same for the 32-bit boards (Alpine: `armv7`). | diff --git a/packages/orchard-blocks/arch/PKGBUILD b/packages/orchard-blocks/arch/PKGBUILD new file mode 100644 index 0000000..4ed3ef7 --- /dev/null +++ b/packages/orchard-blocks/arch/PKGBUILD @@ -0,0 +1,28 @@ +pkgname=orchard-blocks +pkgver=0.1.0 +pkgrel=1 +pkgdesc='Touch-friendly falling-block game and GPU demonstration for Orchard tablets' +arch=('aarch64') +url='https://github.com/OrchardLinux/packages' +license=('GPL-2.0-or-later') +depends=('glibc' 'sdl2' 'mesa' 'vulkan-icd-loader') +makedepends=('mesa' 'pkgconf') +source=('orchard-blocks.c' 'orchard-blocks.desktop') +sha256sums=('c687ac6afedef0aef7cff8a06c90a02ee977651ecc0c52ae003745a4e0247fae' + 'f3e719b33a4bed8fbde62a25e0d149277b3dd57972c64a339beac06b4a21fa62') + +build() { + cc $CFLAGS $CPPFLAGS -Wall -Wextra orchard-blocks.c -o orchard-blocks \ + $LDFLAGS $(pkg-config --cflags --libs sdl2) -lGLESv2 +} + +check() { + file orchard-blocks | grep -q ELF + grep -q '^Exec=/usr/bin/orchard-blocks$' orchard-blocks.desktop +} + +package() { + install -Dm755 orchard-blocks "$pkgdir/usr/bin/orchard-blocks" + install -Dm644 orchard-blocks.desktop \ + "$pkgdir/usr/share/applications/orchard-blocks.desktop" +} diff --git a/packages/orchard-blocks/orchard-blocks.c b/packages/orchard-blocks/orchard-blocks.c new file mode 100644 index 0000000..45996b1 --- /dev/null +++ b/packages/orchard-blocks/orchard-blocks.c @@ -0,0 +1,216 @@ +// SPDX-License-Identifier: GPL-2.0-or-later + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +enum { BW = 10, BH = 20 }; +static const uint16_t shape[7][4] = { + {0x0f00,0x2222,0x00f0,0x4444},{0x0660,0x0660,0x0660,0x0660}, + {0x0e40,0x04c4,0x04e0,0x0464},{0x06c0,0x08c4,0x06c0,0x08c4}, + {0x0c60,0x04c8,0x0c60,0x04c8},{0x08e0,0x0644,0x0e20,0x044c}, + {0x02e0,0x0446,0x0e80,0x0c44} +}; +static const SDL_Color colors[8] = { + {13,16,28,255},{58,211,255,255},{255,210,63,255},{181,94,255,255}, + {80,240,150,255},{255,90,120,255},{94,130,255,255},{255,145,55,255} +}; +static uint8_t board[BH][BW]; +static int kind, rot, px, py, score, lines, best; +static int render_fps; +static bool paused, over, intro, auto_mode; +static uint32_t fall_at; +static char hardware_label[160] = "GPU SDL OPENGL ES"; +typedef struct { uint64_t sample; uint32_t lead_phase, bass_phase; SDL_atomic_t enabled; } Music; +static Music music; +static const int melody[32]={659,0,784,0,880,784,659,0,587,0,659,0,784,659,587,0,523,0,587,0,659,587,523,0,494,0,523,0,587,523,494,0}; +static const int bassline[8]={131,131,147,147,165,165,147,123}; + +static void music_cb(void *userdata,Uint8 *stream,int len) { + Music *m=userdata; int16_t *out=(int16_t *)stream, frames=len/(int)(2*sizeof *out); + for(int i=0;isample++) { + int step=(int)((m->sample/12000)%32), lead=melody[step], bass=bassline[(step/4)%8], v=0; + if(SDL_AtomicGet(&m->enabled)) { + if(lead) { m->lead_phase+=(uint32_t)lead; if(m->lead_phase>=48000)m->lead_phase-=48000; v+=(m->lead_phase<24000?5600:-5600); } + m->bass_phase+=(uint32_t)bass; if(m->bass_phase>=48000)m->bass_phase-=48000; v+=(m->bass_phase<24000?2400:-2400); + } + out[i*2]=(int16_t)v; out[i*2+1]=(int16_t)v; + } +} + +static bool cell(int k,int r,int x,int y) { return shape[k][r] & (1u << (15-(y*4+x))); } +static bool fits(int k,int r,int x,int y) { + for(int j=0;j<4;j++) for(int i=0;i<4;i++) if(cell(k,r,i,j)) { + int bx=x+i, by=y+j; + if(bx<0 || bx>=BW || by>=BH || (by>=0 && board[by][bx])) return false; + } + return true; +} +static void spawn(void) { + kind=rand()%7; rot=0; px=3; py=-1; + if(!fits(kind,rot,px,py)) over=true; +} +static void reset_game(void) { + for(int y=0;y=0) board[py+j][px+i]=kind+1; + int n=0; + for(int y=BH-1;y>=0;y--) { + bool full=true; for(int x=0;x0;yy--) for(int x=0;xbest) best=score; spawn(); +} +static void down(void) { if(fits(kind,rot,px,py+1)) py++; else lock_piece(); } +static void hard_drop(void) { while(fits(kind,rot,px,py+1)) { py++; score+=2; } lock_piece(); } +static void move(int dx) { if(!paused && !over && fits(kind,rot,px+dx,py)) px+=dx; } +static void turn(void) { int nr=(rot+1)&3; if(!paused&&!over && fits(kind,nr,px,py)) rot=nr; } + +static void rect(SDL_Renderer *r,int x,int y,int w,int h,SDL_Color c) { SDL_SetRenderDrawColor(r,c.r,c.g,c.b,c.a); SDL_Rect q={x,y,w,h}; SDL_RenderFillRect(r,&q); } +static const uint8_t digits[10][5]={{7,5,5,5,7},{2,6,2,2,7},{7,1,7,4,7},{7,1,7,1,7},{5,5,7,1,1},{7,4,7,1,7},{7,4,7,5,7},{7,1,1,1,1},{7,5,7,5,7},{7,5,7,1,7}}; +static const uint8_t letters[26][7]={ + {14,17,17,31,17,17,17},{30,17,17,30,17,17,30},{14,17,16,16,16,17,14},{30,17,17,17,17,17,30}, + {31,16,16,30,16,16,31},{31,16,16,30,16,16,16},{14,17,16,23,17,17,15},{17,17,17,31,17,17,17}, + {14,4,4,4,4,4,14},{7,2,2,2,18,18,12},{17,18,20,24,20,18,17},{16,16,16,16,16,16,31}, + {17,27,21,21,17,17,17},{17,25,21,19,17,17,17},{14,17,17,17,17,17,14},{30,17,17,30,16,16,16}, + {14,17,17,17,21,18,13},{30,17,17,30,20,18,17},{15,16,16,14,1,1,30},{31,4,4,4,4,4,4}, + {17,17,17,17,17,17,14},{17,17,17,17,17,10,4},{17,17,17,21,21,21,10},{17,17,10,4,10,17,17}, + {17,17,10,4,4,4,4},{31,1,2,4,8,16,31} +}; +static const uint8_t digits7[10][7]={{14,17,19,21,25,17,14},{4,12,4,4,4,4,14},{14,17,1,2,4,8,31},{30,1,1,14,1,1,30},{2,6,10,18,31,2,2},{31,16,16,30,1,1,30},{14,16,16,30,17,17,14},{31,1,2,4,8,8,8},{14,17,17,14,17,17,14},{14,17,17,15,1,1,14}}; +static void text5(SDL_Renderer*r,const char *text,int x,int y,int s,SDL_Color c) { + for(const char*p=text;*p;p++,x+=6*s) for(int yy=0;yy<7;yy++) for(int xx=0;xx<5;xx++) { + uint8_t row=(*p>='A'&&*p<='Z')?letters[*p-'A'][yy]:(*p>='0'&&*p<='9')?digits7[*p-'0'][yy]:0; + if(row&(16>>xx)) rect(r,x+xx*s,y+yy*s,s-1,s-1,c); + } +} +static int text_width(const char *p,int s) { int n=0; while(*p++){n++;} return n*6*s; } +static int number_width(int v,int s) { int n=1; while(v>=10){v/=10;n++;} return n*4*s; } +static void append_label(char *dst,size_t size,const char *src) { + size_t used=strlen(dst); + if(!src) src="UNKNOWN"; + while(*src && used+1>xx)) rect(r,x+xx*s,y+yy*s,s-1,s-1,c); } +} +static void draw(SDL_Renderer *r,int w,int h) { + SDL_Color bg={11,14,25,255}, panel={24,29,48,255}, grid={35,42,65,255}, white={225,240,255,255}; + rect(r,0,0,w,h,bg); int top=h/30, header=h/10, bottom=h/10; + int avail=h-header-top-bottom, cs=avail/BH; if(cs>w*3/40) cs=w*3/40; + int bw=cs*BW, bh=cs*BH, ox=(w-bw)/2, oy=header; + rect(r,ox-6,oy-6,bw+12,bh+12,panel); + rect(r,ox,oy,bw,bh,grid); + for(int y=0;y=0) rect(r,ox+(px+i)*cs,oy+(py+j)*cs,cs-1,cs-1,colors[kind+1]); + int s=(w/90<8?8:w/90), label_s=s/2; if(label_s<3)label_s=3; + text5(r,"SCORE",top,top,label_s,white); number(r,score,top+text_width("SCORE",label_s)+label_s,top,s,white); + SDL_Color perf=render_fps>=30?(SDL_Color){105,255,170,255}:render_fps>=15?(SDL_Color){255,210,63,255}:(SDL_Color){255,90,120,255}; + int perf_w=text_width("GPU",label_s)+label_s+number_width(render_fps,label_s)+label_s+text_width("FPS",label_s); + int perf_x=w-top-perf_w; text5(r,"GPU",perf_x,top,label_s,perf); perf_x+=text_width("GPU",label_s)+label_s; + number(r,render_fps,perf_x,top,label_s,perf); perf_x+=number_width(render_fps,label_s)+label_s; text5(r,"FPS",perf_x,top,label_s,perf); + const char *meta=hardware_label; int ms=w/360; if(ms<2)ms=2; + while(ms>1 && text_width(meta,ms)>w-2*top) ms--; + int box=9*ms, row_y=h-22*ms; SDL_Color muted={180,205,225,255}, on={105,255,170,255}; + int ax=w/4-text_width("AUTO MODE",ms)/2-box, bx=3*w/4-text_width("AUDIO",ms)/2-box; + rect(r,ax,row_y,box,box,muted); rect(r,ax+ms,row_y+ms,box-2*ms,box-2*ms,auto_mode?on:bg); text5(r,"AUTO MODE",ax+box+2*ms,row_y+ms,ms,auto_mode?on:muted); + bool audio_on=SDL_AtomicGet(&music.enabled); rect(r,bx,row_y,box,box,muted); rect(r,bx+ms,row_y+ms,box-2*ms,box-2*ms,audio_on?on:bg); text5(r,"AUDIO",bx+box+2*ms,row_y+ms,ms,audio_on?on:muted); + text5(r,meta,(w-text_width(meta,ms))/2,h-9*ms,ms,muted); + if(paused||over||intro) { + SDL_SetRenderDrawBlendMode(r,SDL_BLENDMODE_BLEND); rect(r,ox,oy,bw,bh,(SDL_Color){0,0,0,190}); + int ts=w/180, cx=ox+bw/2; if(ts<4)ts=4; + if(over) { + const char *a="GAME OVER",*b="TAP TO PLAY"; + text5(r,a,cx-text_width(a,ts)/2,oy+bh/2-10*ts,ts,(SDL_Color){255,90,120,255}); + text5(r,b,cx-text_width(b,ts)/2,oy+bh/2+4*ts,ts,white); + } else if(intro) { + const char *a="ORCHARD BLOCKS",*b="SWIPE LEFT RIGHT TO MOVE",*c="SWIPE DOWN TO DROP",*d="TAP TO ROTATE",*e="TAP TO PLAY"; + text5(r,a,cx-text_width(a,ts)/2,oy+bh/2-28*ts,ts,(SDL_Color){105,255,170,255}); + text5(r,b,cx-text_width(b,ts)/2,oy+bh/2-10*ts,ts,white); + text5(r,c,cx-text_width(c,ts)/2,oy+bh/2,ts,white); + text5(r,d,cx-text_width(d,ts)/2,oy+bh/2+10*ts,ts,white); + text5(r,e,cx-text_width(e,ts)/2,oy+bh/2+26*ts,ts,(SDL_Color){105,255,170,255}); + } + } + SDL_RenderPresent(r); +} +static void action_at(float nx,float ny) { + if(ny>0.88f) { if(nx<0.5f) auto_mode=!auto_mode; else SDL_AtomicSet(&music.enabled,!SDL_AtomicGet(&music.enabled)); return; } + if(over) { reset_game(); return; } if(intro) { intro=false; fall_at=SDL_GetTicks()+700; return; } if(ny<0.12f) { paused=!paused; return; } + (void)nx; turn(); +} +int main(void) { + setenv("MESA_LOADER_DRIVER_OVERRIDE","zink",1); + setenv("PVR_I_WANT_A_BROKEN_VULKAN_DRIVER","1",1); + srand((unsigned)time(NULL)); SDL_SetHint(SDL_HINT_RENDER_DRIVER,"opengles2"); SDL_SetHint(SDL_HINT_TOUCH_MOUSE_EVENTS,"0"); SDL_SetHint(SDL_HINT_ENABLE_SCREEN_KEYBOARD,"0"); + if(SDL_Init(SDL_INIT_VIDEO|SDL_INIT_AUDIO|SDL_INIT_TIMER)<0) return 1; + SDL_Window *win=SDL_CreateWindow("Orchard Blocks",SDL_WINDOWPOS_CENTERED,SDL_WINDOWPOS_CENTERED,900,1200,SDL_WINDOW_FULLSCREEN_DESKTOP|SDL_WINDOW_ALLOW_HIGHDPI); + if(!win) return 2; + SDL_Renderer *ren=SDL_CreateRenderer(win,-1,SDL_RENDERER_ACCELERATED); + if(!ren) { + fprintf(stderr,"gpu_renderer_error=%s; falling back to software\n",SDL_GetError()); + unsetenv("MESA_LOADER_DRIVER_OVERRIDE"); + unsetenv("PVR_I_WANT_A_BROKEN_VULKAN_DRIVER"); + ren=SDL_CreateRenderer(win,-1,SDL_RENDERER_SOFTWARE); + } + if(!ren) return 3; + SDL_RendererInfo info; + if(SDL_GetRendererInfo(ren,&info)==0) { + hardware_label[0]=0; + append_label(hardware_label,sizeof hardware_label,"GPU "); + append_label(hardware_label,sizeof hardware_label,(const char *)glGetString(GL_RENDERER)); + append_label(hardware_label,sizeof hardware_label," SDL "); + append_label(hardware_label,sizeof hardware_label,info.name); + fprintf(stderr,"renderer=%s flags=0x%x gpu=%s\n",info.name,info.flags, + glGetString(GL_RENDERER)); + } + SDL_StopTextInput(); + SDL_AtomicSet(&music.enabled,1); SDL_AudioSpec want={0},got={0}; want.freq=48000; want.format=AUDIO_S16SYS; want.channels=2; want.samples=1024; want.callback=music_cb; want.userdata=&music; + SDL_AudioDeviceID audio=SDL_OpenAudioDevice(NULL,0,&want,&got,0); if(audio) { SDL_PauseAudioDevice(audio,0); fprintf(stderr,"audio=%dHz/%dch\n",got.freq,got.channels); } else fprintf(stderr,"audio_error=%s\n",SDL_GetError()); + reset_game(); +#ifdef FPS_TEST + intro=false; auto_mode=true; +#else + intro=true; auto_mode=false; +#endif + bool run=true; float sx=0,sy=0; uint32_t st=0, draw_at=0, fps_at=SDL_GetTicks(), auto_at=SDL_GetTicks()+200; int frame_count=0; + while(run) { SDL_Event e; int event_budget=64; while(event_budget-- > 0 && SDL_PollEvent(&e)) { + if(e.type==SDL_QUIT)run=false; + else if(e.type==SDL_TEXTINPUT||e.type==SDL_TEXTEDITING) SDL_StopTextInput(); + else if(e.type==SDL_KEYDOWN) { switch(e.key.keysym.sym){case SDLK_ESCAPE:run=false;break;case SDLK_LEFT:move(-1);break;case SDLK_RIGHT:move(1);break;case SDLK_UP:turn();break;case SDLK_DOWN:down();break;case SDLK_SPACE:hard_drop();break;case SDLK_p:paused=!paused;break;case SDLK_r:reset_game();break;case SDLK_m:SDL_AtomicSet(&music.enabled,!SDL_AtomicGet(&music.enabled));break;} } + else if(e.type==SDL_FINGERDOWN){sx=e.tfinger.x;sy=e.tfinger.y;st=SDL_GetTicks();} + else if(e.type==SDL_FINGERUP){float dx=e.tfinger.x-sx,dy=e.tfinger.y-sy;if(intro||over)action_at(e.tfinger.x,e.tfinger.y);else if(abs((int)(dx*1000))>100||abs((int)(dy*1000))>100){if(abs((int)(dx*1000))>abs((int)(dy*1000)))move(dx>0?1:-1);else if(dy>0)hard_drop();else turn();}else action_at(e.tfinger.x,e.tfinger.y); (void)st;} + } + uint32_t now=SDL_GetTicks(); + if(auto_mode && now>=auto_at) { + if(over) reset_game(); + else { int action=rand()%10; if(action==0)move(-1); else if(action==1)move(1); else if(action==2)turn(); else down(); } + auto_at=now+140; + } + if(!auto_mode&&!paused&&!over&&!intro&&now>=fall_at){down();fall_at=now+(uint32_t)(700-(lines<20?lines:20)*25);} + if(now>=draw_at){int w,h;SDL_GetRendererOutputSize(ren,&w,&h);draw(ren,w,h); + draw_at=now; + frame_count++;} + if(now-fps_at>=2000){render_fps=(int)(frame_count*1000u/(now-fps_at));frame_count=0;fps_at=now; +#ifdef FPS_TEST + fprintf(stderr,"fps=%d score=%d lines=%d\n",render_fps,score,lines); +#endif + } + SDL_Delay(1); + } + if(audio) SDL_CloseAudioDevice(audio); + SDL_DestroyRenderer(ren); SDL_DestroyWindow(win); SDL_Quit(); return 0; +} diff --git a/packages/orchard-blocks/orchard-blocks.desktop b/packages/orchard-blocks/orchard-blocks.desktop new file mode 100644 index 0000000..acf09a8 --- /dev/null +++ b/packages/orchard-blocks/orchard-blocks.desktop @@ -0,0 +1,9 @@ +[Desktop Entry] +Type=Application +Name=Orchard Blocks +Comment=Touch-friendly falling-block game and GPU demonstration +Exec=/usr/bin/orchard-blocks +Icon=applications-games +Terminal=false +Categories=Game; +StartupNotify=true diff --git a/packages/orchard-blocks/source.json b/packages/orchard-blocks/source.json new file mode 100644 index 0000000..e720b04 --- /dev/null +++ b/packages/orchard-blocks/source.json @@ -0,0 +1,5 @@ +{ + "version": "0.1.0", + "file": "orchard-blocks.c", + "sha256": "c687ac6afedef0aef7cff8a06c90a02ee977651ecc0c52ae003745a4e0247fae" +}