Thank you to anyone who has already donated - your generous donations helped make three months of treatment possible.
My brother Nate continues to fight stage IV Hodgkin's lymphoma. He's just 31, with a wife and baby girl. They have no active income (since he's been unable to return to work), no insurance, and cannot afford the treatment he needs. Nate and his family need your help. Please consider a donation, every dollar helps. Thanks.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 |
diff --git a/apps/plugin.h b/apps/plugin.h index b060104..2d8df6a 100644 void* plugin_get_buffer(size_t *buffer_size); #include "ata_idle_notify.h" #include "settings_list.h" #include "timefuncs.h" +#include "fixedpoint.h" #ifdef HAVE_ALBUMART #include "albumart.h" diff --git a/apps/plugins/chopper.c b/apps/plugins/chopper.c index f93f713..2387db0 100644 CONFIG_KEYPAD == MROBE500_PAD #define LEVEL_MODE_STEEP 1 #if LCD_HEIGHT <= 64 -#define CYCLES 100 +#define REFERENCE_CYCLES 100 static inline int SCALE(int x) { return x == 1 ? x : x >> 1; } #define SIZE 2 #else -#define CYCLES 60 +#define REFERENCE_CYCLES 60 #define SCALE(x) (x) #define SIZE 1 #endif -/* in 10 milisecond (ticks) */ -#define CYCLETIME ((CYCLES*HZ)/1000) - /* some fixed-point math for speed calculation * based on brickmania after r22882 */ -#define FIXED4(x) ((x)<<4) -#define FIXED4_MUL(x, y) ((long long)((x)*(y))>>4) -#define FIXED4_DIV(x, y) (((x)<<4)/(y)) -#define INT4(x) ((x)>>4) +#define PRECISION 8 +#define FIXED4(x) ((x)<<PRECISION) +#define FIXED4_MUL(x, y) fp_mul(x,y,PRECISION) +#define FIXED4_DIV(x, y) fp_div(x,y,PRECISION) +#define INT4(x) ((x)>>8) + +#if defined(SANSA_FUZE) || 1 +#define CHOPPER_SPEED_FACTOR 3 +#endif +#ifndef CHOPPER_SPEED_FACTOR +#define CHOPPER_SPEED_FACTOR 1 +#endif +#define CYCLES (REFERENCE_CYCLES / CHOPPER_SPEED_FACTOR) +/* in 10 milisecond (ticks) */ +#define CYCLETIME ((CYCLES*HZ)/1000) /*Chopper's local variables to track the terrain position etc*/ static int chopCounter; static int iRotorOffset; static int iScreenX; static int iScreenY; +static int iCameraPosX; +/* the next for are 24.8 fixed point numbers */ static int iPlayerPosX; static int iPlayerPosY; -static int iCameraPosX; static unsigned iPlayerSpeedX; -static unsigned iPlayerSpeedY; +static int iPlayerSpeedY; static int iLastBlockPlacedPosX; static int iGravityTimerCountdown; static int iPlayerAlive; int chopUpdateTerrainRecycling(struct CTerrain *ter) while(i < ter->iNodesCount) { - if( iCameraPosX > ter->mNodes[i].x) + if( INT4(iCameraPosX) > ter->mNodes[i].x) { chopTerrainNodeDeleteAndShift(ter,i); static int chopBlockCollideWithPlayer(struct CBlock *mBlock) static int chopBlockOffscreen(struct CBlock *mBlock) { - if(mBlock->iWorldX + mBlock->iSizeX < iCameraPosX) + if(mBlock->iWorldX + mBlock->iSizeX < INT4(iCameraPosX)) return 1; else return 0; static int chopBlockOffscreen(struct CBlock *mBlock) static int chopParticleOffscreen(struct CParticle *mParticle) { - if (mParticle->iWorldX < iCameraPosX || mParticle->iWorldY < 0 || - mParticle->iWorldY > iScreenY || mParticle->iWorldX > iCameraPosX + + if (mParticle->iWorldX < INT4(iCameraPosX) || mParticle->iWorldY < 0 || + mParticle->iWorldY > iScreenY || mParticle->iWorldX > INT4(iCameraPosX) + iScreenX) { return 1; static void chopDrawTheWorld(void) static void chopDrawParticle(struct CParticle *mParticle) { - int iPosX = (mParticle->iWorldX - iCameraPosX); + int iPosX = (mParticle->iWorldX - INT4(iCameraPosX)); int iPosY = (mParticle->iWorldY); #if LCD_DEPTH > 2 rb->lcd_set_foreground(LCD_RGBPACK(192,192,192)); static void chopDrawScene(void) rb->lcd_set_background(LCD_WHITE); #endif chopDrawTheWorld(); - chopDrawPlayer(INT4(iPlayerPosX) - iCameraPosX, INT4(iPlayerPosY)); + chopDrawPlayer(INT4(iPlayerPosX - iCameraPosX, iPlayerPosY)); - score = -20 + INT4(FIXED4_DIV(iPlayerPosX, FIXED4(3))); + score = -20 + INT4(iPlayerPosX / 3); #if LCD_DEPTH == 1 rb->lcd_set_drawmode(DRMODE_COMPLEMENT); static int chopGameLoop(void) if(iGravityTimerCountdown <= 0) { - iGravityTimerCountdown = 3; + iGravityTimerCountdown = 3*CHOPPER_SPEED_FACTOR; chopAddParticle(INT4(iPlayerPosX), INT4(iPlayerPosY)+5, 0, 0); } static int chopGameLoop(void) ) bdelay = -2; if (bdelay == 0) - iPlayerSpeedY = FIXED4(-3); + iPlayerSpeedY = FIXED4(-3) / CHOPPER_SPEED_FACTOR; break; default: static int chopGameLoop(void) ) bdelay = 3; if (bdelay == 0) - iPlayerSpeedY = FIXED4(4); + iPlayerSpeedY = FIXED4(4) / CHOPPER_SPEED_FACTOR; if (rb->default_event_handler(move_button) == SYS_USB_CONNECTED) return PLUGIN_USB_CONNECTED; static int chopGameLoop(void) last_button = move_button; if (bdelay < 0) { - iPlayerSpeedY = FIXED4(bdelay); + iPlayerSpeedY = FIXED4(bdelay) / CHOPPER_SPEED_FACTOR; bdelay++; } else if (bdelay > 0) { - iPlayerSpeedY = FIXED4(bdelay); + iPlayerSpeedY = FIXED4(bdelay) / CHOPPER_SPEED_FACTOR; bdelay--; } - iCameraPosX = INT4(iPlayerPosX) - 25; + iCameraPosX = iPlayerPosX - FIXED4(25); iPlayerPosX += iPlayerSpeedX; iPlayerPosY += iPlayerSpeedY; chopCounter++; /* increase speed as we go along */ - if (chopCounter == 100){ + if (chopCounter == 100*CHOPPER_SPEED_FACTOR*CHOPPER_SPEED_FACTOR){ iPlayerSpeedX += FIXED4(1); chopCounter=0; } static int chopGameLoop(void) static void chopDrawBlock(struct CBlock *mBlock) { - int iPosX = (mBlock->iWorldX - iCameraPosX); + int iPosX = (mBlock->iWorldX - INT4(iCameraPosX)); int iPosY = (mBlock->iWorldY); #if LCD_DEPTH > 2 rb->lcd_set_foreground(LCD_RGBPACK(100,255,100)); static void chopRenderTerrain(struct CTerrain *ter) while(i < ter->iNodesCount && oldx < iScreenX) { - int x = ter->mNodes[i-1].x - iCameraPosX; + int x = ter->mNodes[i-1].x - INT4(iCameraPosX); int y = ter->mNodes[i-1].y; - int x2 = ter->mNodes[i].x - iCameraPosX; + int x2 = ter->mNodes[i].x - INT4(iCameraPosX); int y2 = ter->mNodes[i].y; #if LCD_DEPTH > 2 rb->lcd_set_foreground(LCD_RGBPACK(100,255,100)); void chopper_load(bool newgame) } iRotorOffset = 0; iPlayerPosX = FIXED4(60); - iPlayerPosY = FIXED4_DIV(FIXED4(iScreenY << 2),FIXED4(10)); + iPlayerPosY = FIXED4(iScreenY*4) / 10; iLastBlockPlacedPosX = 0; - iGravityTimerCountdown = 2; + iGravityTimerCountdown = 2*CHOPPER_SPEED_FACTOR; chopCounter = 0; - iPlayerSpeedX = FIXED4(3); + iPlayerSpeedX = FIXED4(3) / CHOPPER_SPEED_FACTOR; iPlayerSpeedY = 0; - iCameraPosX = 30; + iCameraPosX = FIXED4(30); for (i=0; i < NUMBER_OF_PARTICLES; i++) mParticles[i].bIsActive = 0; void chopper_load(bool newgame) chopCopyTerrain(&mGround, &mRoof, 0, - ( (iScreenY * 3) / 4)); if (iLevelMode == LEVEL_MODE_NORMAL) - /* make it a bit more exciting, cause it's easy terrain... */ - iPlayerSpeedX <<= 1 ; + /* make it a bit more exciting, cause it's easy terrain... + * double the speed (safe for fp)*/ + iPlayerSpeedX += iPlayerSpeedX; } /* this is the plugin entry point */ |