Jason Sams | 0f505e5 | 2009-10-13 17:18:35 -0700 | [diff] [blame] | 1 | #pragma version(1) |
| 2 | #pragma stateVertex(PV) |
Jason Sams | c851479 | 2009-10-29 14:27:29 -0700 | [diff] [blame] | 3 | #pragma stateFragment(PFTexNearest) |
Jason Sams | 0f505e5 | 2009-10-13 17:18:35 -0700 | [diff] [blame] | 4 | #pragma stateStore(PSIcons) |
| 5 | |
| 6 | #define PI 3.14159f |
| 7 | |
Jason Sams | 41b61c8 | 2009-10-15 15:40:54 -0700 | [diff] [blame] | 8 | int g_SpecialHWWar; |
Jason Sams | 0f505e5 | 2009-10-13 17:18:35 -0700 | [diff] [blame] | 9 | |
| 10 | // Attraction to center values from page edge to page center. |
| 11 | float g_AttractionTable[9]; |
Jason Sams | 2e19c05 | 2009-10-20 18:19:55 -0700 | [diff] [blame] | 12 | float g_FrictionTable[9]; |
Jason Sams | 0f505e5 | 2009-10-13 17:18:35 -0700 | [diff] [blame] | 13 | float g_PhysicsTableSize; |
| 14 | |
| 15 | float g_PosPage; |
| 16 | float g_PosVelocity; |
| 17 | float g_LastPositionX; |
| 18 | int g_LastTouchDown; |
| 19 | float g_DT; |
| 20 | int g_LastTime; |
| 21 | int g_PosMax; |
| 22 | float g_Zoom; |
Jason Sams | 6471c8b | 2010-01-20 14:15:22 -0800 | [diff] [blame] | 23 | float g_Animation; |
Jason Sams | 0f505e5 | 2009-10-13 17:18:35 -0700 | [diff] [blame] | 24 | float g_OldPosPage; |
| 25 | float g_OldPosVelocity; |
| 26 | float g_OldZoom; |
Jason Sams | c1c521e | 2009-10-19 14:45:45 -0700 | [diff] [blame] | 27 | float g_MoveToTotalTime; |
| 28 | float g_MoveToTime; |
| 29 | float g_MoveToOldPos; |
| 30 | |
Jason Sams | 0f505e5 | 2009-10-13 17:18:35 -0700 | [diff] [blame] | 31 | |
| 32 | // Drawing constants, should be parameters ====== |
| 33 | #define VIEW_ANGLE 1.28700222f |
| 34 | |
| 35 | int g_DrawLastFrame; |
| 36 | int lastFrame(int draw) { |
| 37 | // We draw one extra frame to work around the last frame post bug. |
| 38 | // We also need to track if we drew the last frame to deal with large DT |
| 39 | // in the physics. |
| 40 | int ret = g_DrawLastFrame | draw; |
| 41 | g_DrawLastFrame = draw; |
| 42 | return ret; // should return draw instead. |
| 43 | } |
| 44 | |
| 45 | void updateReadback() { |
| 46 | if ((g_OldPosPage != g_PosPage) || |
| 47 | (g_OldPosVelocity != g_PosVelocity) || |
| 48 | (g_OldZoom != g_Zoom)) { |
| 49 | |
| 50 | g_OldPosPage = g_PosPage; |
| 51 | g_OldPosVelocity = g_PosVelocity; |
| 52 | g_OldZoom = g_Zoom; |
| 53 | |
| 54 | int i[3]; |
| 55 | i[0] = g_PosPage * (1 << 16); |
| 56 | i[1] = g_PosVelocity * (1 << 16); |
| 57 | i[2] = g_OldZoom * (1 << 16); |
| 58 | sendToClient(&i[0], 1, 12, 1); |
| 59 | } |
| 60 | } |
| 61 | |
Jason Sams | 41b61c8 | 2009-10-15 15:40:54 -0700 | [diff] [blame] | 62 | void setColor(float r, float g, float b, float a) { |
| 63 | if (g_SpecialHWWar) { |
| 64 | color(0, 0, 0, 0.001f); |
| 65 | } else { |
| 66 | color(r, g, b, a); |
| 67 | } |
| 68 | } |
Jason Sams | 0f505e5 | 2009-10-13 17:18:35 -0700 | [diff] [blame] | 69 | |
| 70 | void init() { |
Jason Sams | 2e19c05 | 2009-10-20 18:19:55 -0700 | [diff] [blame] | 71 | g_AttractionTable[0] = 20.0f; |
| 72 | g_AttractionTable[1] = 20.0f; |
Jason Sams | c851479 | 2009-10-29 14:27:29 -0700 | [diff] [blame] | 73 | g_AttractionTable[2] = 20.0f; |
Jason Sams | 2e19c05 | 2009-10-20 18:19:55 -0700 | [diff] [blame] | 74 | g_AttractionTable[3] = 10.0f; |
| 75 | g_AttractionTable[4] = -10.0f; |
Jason Sams | c851479 | 2009-10-29 14:27:29 -0700 | [diff] [blame] | 76 | g_AttractionTable[5] = -20.0f; |
| 77 | g_AttractionTable[6] = -20.0f; |
Jason Sams | 2e19c05 | 2009-10-20 18:19:55 -0700 | [diff] [blame] | 78 | g_AttractionTable[7] = -20.0f; |
| 79 | g_AttractionTable[8] = -20.0f; // dup 7 to avoid a clamp later |
| 80 | g_FrictionTable[0] = 10.0f; |
| 81 | g_FrictionTable[1] = 10.0f; |
| 82 | g_FrictionTable[2] = 11.0f; |
| 83 | g_FrictionTable[3] = 15.0f; |
| 84 | g_FrictionTable[4] = 15.0f; |
| 85 | g_FrictionTable[5] = 11.0f; |
| 86 | g_FrictionTable[6] = 10.0f; |
| 87 | g_FrictionTable[7] = 10.0f; |
| 88 | g_FrictionTable[8] = 10.0f; // dup 7 to avoid a clamp later |
Jason Sams | 0f505e5 | 2009-10-13 17:18:35 -0700 | [diff] [blame] | 89 | g_PhysicsTableSize = 7; |
| 90 | |
| 91 | g_PosVelocity = 0; |
| 92 | g_PosPage = 0; |
| 93 | g_LastTouchDown = 0; |
| 94 | g_LastPositionX = 0; |
| 95 | g_Zoom = 0; |
Jason Sams | 41b61c8 | 2009-10-15 15:40:54 -0700 | [diff] [blame] | 96 | g_SpecialHWWar = 1; |
Jason Sams | c1c521e | 2009-10-19 14:45:45 -0700 | [diff] [blame] | 97 | g_MoveToTime = 0; |
| 98 | g_MoveToOldPos = 0; |
Mike Cleron | 7d5d746 | 2009-10-20 14:06:00 -0700 | [diff] [blame] | 99 | g_MoveToTotalTime = 0.2f; // Duration of scrolling 1 line |
Jason Sams | 41b61c8 | 2009-10-15 15:40:54 -0700 | [diff] [blame] | 100 | } |
| 101 | |
| 102 | void resetHWWar() { |
| 103 | g_SpecialHWWar = 1; |
Jason Sams | 0f505e5 | 2009-10-13 17:18:35 -0700 | [diff] [blame] | 104 | } |
| 105 | |
| 106 | void move() { |
| 107 | if (g_LastTouchDown) { |
| 108 | float dx = -(state->newPositionX - g_LastPositionX); |
| 109 | g_PosVelocity = 0; |
Jason Sams | 6ec11bc | 2010-01-19 17:56:52 -0800 | [diff] [blame] | 110 | g_PosPage += dx * 5.2f; |
Jason Sams | 0f505e5 | 2009-10-13 17:18:35 -0700 | [diff] [blame] | 111 | |
Jason Sams | c851479 | 2009-10-29 14:27:29 -0700 | [diff] [blame] | 112 | float pmin = -0.49f; |
| 113 | float pmax = g_PosMax + 0.49f; |
Jason Sams | 0f505e5 | 2009-10-13 17:18:35 -0700 | [diff] [blame] | 114 | g_PosPage = clampf(g_PosPage, pmin, pmax); |
| 115 | } |
| 116 | g_LastTouchDown = state->newTouchDown; |
| 117 | g_LastPositionX = state->newPositionX; |
Jason Sams | c1c521e | 2009-10-19 14:45:45 -0700 | [diff] [blame] | 118 | g_MoveToTime = 0; |
Jason Sams | 0f505e5 | 2009-10-13 17:18:35 -0700 | [diff] [blame] | 119 | //debugF("Move P", g_PosPage); |
| 120 | } |
| 121 | |
Jason Sams | c1c521e | 2009-10-19 14:45:45 -0700 | [diff] [blame] | 122 | void moveTo() { |
| 123 | g_MoveToTime = g_MoveToTotalTime; |
| 124 | g_PosVelocity = 0; |
| 125 | g_MoveToOldPos = g_PosPage; |
Jason Sams | 2e19c05 | 2009-10-20 18:19:55 -0700 | [diff] [blame] | 126 | |
Mike Cleron | 7d5d746 | 2009-10-20 14:06:00 -0700 | [diff] [blame] | 127 | // debugF("======= moveTo", state->targetPos); |
Jason Sams | c1c521e | 2009-10-19 14:45:45 -0700 | [diff] [blame] | 128 | } |
| 129 | |
Joe Onorato | 3a8820b | 2009-11-10 15:06:42 -0800 | [diff] [blame] | 130 | void setZoom() { |
| 131 | g_Zoom = state->zoomTarget; |
| 132 | g_DrawLastFrame = 1; |
| 133 | updateReadback(); |
| 134 | } |
| 135 | |
Jason Sams | 0f505e5 | 2009-10-13 17:18:35 -0700 | [diff] [blame] | 136 | void fling() { |
| 137 | g_LastTouchDown = 0; |
Jason Sams | 37e7c2b | 2009-10-19 12:55:43 -0700 | [diff] [blame] | 138 | g_PosVelocity = -state->flingVelocity * 4; |
Jason Sams | 0f505e5 | 2009-10-13 17:18:35 -0700 | [diff] [blame] | 139 | float av = fabsf(g_PosVelocity); |
| 140 | float minVel = 3.5f; |
| 141 | |
| 142 | minVel *= 1.f - (fabsf(fracf(g_PosPage + 0.5f) - 0.5f) * 0.45f); |
| 143 | |
| 144 | if (av < minVel && av > 0.2f) { |
| 145 | if (g_PosVelocity > 0) { |
| 146 | g_PosVelocity = minVel; |
| 147 | } else { |
| 148 | g_PosVelocity = -minVel; |
| 149 | } |
| 150 | } |
| 151 | |
| 152 | if (g_PosPage <= 0) { |
| 153 | g_PosVelocity = maxf(0, g_PosVelocity); |
| 154 | } |
| 155 | if (g_PosPage > g_PosMax) { |
| 156 | g_PosVelocity = minf(0, g_PosVelocity); |
| 157 | } |
| 158 | } |
| 159 | |
Jason Sams | 0f505e5 | 2009-10-13 17:18:35 -0700 | [diff] [blame] | 160 | float |
| 161 | modf(float x, float y) |
| 162 | { |
| 163 | return x-(y*floorf(x/y)); |
| 164 | } |
| 165 | |
Mike Cleron | 7d5d746 | 2009-10-20 14:06:00 -0700 | [diff] [blame] | 166 | |
| 167 | /* |
| 168 | * Interpolates values in the range 0..1 to a curve that eases in |
| 169 | * and out. |
| 170 | */ |
| 171 | float |
| 172 | getInterpolation(float input) { |
| 173 | return (cosf((input + 1) * PI) / 2.0f) + 0.5f; |
| 174 | } |
| 175 | |
| 176 | |
Jason Sams | 0f505e5 | 2009-10-13 17:18:35 -0700 | [diff] [blame] | 177 | void updatePos() { |
| 178 | if (g_LastTouchDown) { |
| 179 | return; |
| 180 | } |
| 181 | |
Jason Sams | 0f505e5 | 2009-10-13 17:18:35 -0700 | [diff] [blame] | 182 | float tablePosNorm = fracf(g_PosPage + 0.5f); |
| 183 | float tablePosF = tablePosNorm * g_PhysicsTableSize; |
| 184 | int tablePosI = tablePosF; |
| 185 | float tablePosFrac = tablePosF - tablePosI; |
| 186 | float accel = lerpf(g_AttractionTable[tablePosI], |
| 187 | g_AttractionTable[tablePosI + 1], |
| 188 | tablePosFrac) * g_DT; |
Jason Sams | 2e19c05 | 2009-10-20 18:19:55 -0700 | [diff] [blame] | 189 | float friction = lerpf(g_FrictionTable[tablePosI], |
| 190 | g_FrictionTable[tablePosI + 1], |
| 191 | tablePosFrac) * g_DT; |
Jason Sams | 0f505e5 | 2009-10-13 17:18:35 -0700 | [diff] [blame] | 192 | |
Jason Sams | c1c521e | 2009-10-19 14:45:45 -0700 | [diff] [blame] | 193 | if (g_MoveToTime) { |
Jason Sams | c851479 | 2009-10-29 14:27:29 -0700 | [diff] [blame] | 194 | // New position is old posiition + (total distance) * (interpolated time) |
| 195 | g_PosPage = g_MoveToOldPos + (state->targetPos - g_MoveToOldPos) * getInterpolation((g_MoveToTotalTime - g_MoveToTime) / g_MoveToTotalTime); |
Jason Sams | c1c521e | 2009-10-19 14:45:45 -0700 | [diff] [blame] | 196 | g_MoveToTime -= g_DT; |
| 197 | if (g_MoveToTime <= 0) { |
| 198 | g_MoveToTime = 0; |
| 199 | g_PosPage = state->targetPos; |
| 200 | } |
| 201 | return; |
| 202 | } |
| 203 | |
Jason Sams | 0f505e5 | 2009-10-13 17:18:35 -0700 | [diff] [blame] | 204 | // If our velocity is low OR acceleration is opposing it, apply it. |
Jason Sams | c851479 | 2009-10-29 14:27:29 -0700 | [diff] [blame] | 205 | if (fabsf(g_PosVelocity) < 4.0f || (g_PosVelocity * accel) < 0) { |
Jason Sams | 0f505e5 | 2009-10-13 17:18:35 -0700 | [diff] [blame] | 206 | g_PosVelocity += accel; |
| 207 | } |
Jason Sams | c851479 | 2009-10-29 14:27:29 -0700 | [diff] [blame] | 208 | //debugF("g_PosPage", g_PosPage); |
| 209 | //debugF(" g_PosVelocity", g_PosVelocity); |
| 210 | //debugF(" friction", friction); |
| 211 | //debugF(" accel", accel); |
Jason Sams | 0f505e5 | 2009-10-13 17:18:35 -0700 | [diff] [blame] | 212 | |
Jason Sams | c851479 | 2009-10-29 14:27:29 -0700 | [diff] [blame] | 213 | // Normal physics |
| 214 | if (g_PosVelocity > 0) { |
| 215 | g_PosVelocity -= friction; |
| 216 | g_PosVelocity = maxf(g_PosVelocity, 0); |
| 217 | } else { |
| 218 | g_PosVelocity += friction; |
| 219 | g_PosVelocity = minf(g_PosVelocity, 0); |
| 220 | } |
| 221 | |
| 222 | if ((friction > fabsf(g_PosVelocity)) && (friction > fabsf(accel))) { |
Jason Sams | 0f505e5 | 2009-10-13 17:18:35 -0700 | [diff] [blame] | 223 | // Special get back to center and overcome friction physics. |
| 224 | float t = tablePosNorm - 0.5f; |
| 225 | if (fabsf(t) < (friction * g_DT)) { |
| 226 | // really close, just snap |
| 227 | g_PosPage = roundf(g_PosPage); |
| 228 | g_PosVelocity = 0; |
| 229 | } else { |
| 230 | if (t > 0) { |
| 231 | g_PosVelocity = -friction; |
| 232 | } else { |
| 233 | g_PosVelocity = friction; |
| 234 | } |
| 235 | } |
Jason Sams | 0f505e5 | 2009-10-13 17:18:35 -0700 | [diff] [blame] | 236 | } |
Jason Sams | 0f505e5 | 2009-10-13 17:18:35 -0700 | [diff] [blame] | 237 | |
| 238 | // Check for out of boundry conditions. |
| 239 | if (g_PosPage < 0 && g_PosVelocity < 0) { |
Jason Sams | 0f505e5 | 2009-10-13 17:18:35 -0700 | [diff] [blame] | 240 | float damp = 1.0 + (g_PosPage * 4); |
| 241 | damp = clampf(damp, 0.f, 0.9f); |
| 242 | g_PosVelocity *= damp; |
| 243 | } |
| 244 | if (g_PosPage > g_PosMax && g_PosVelocity > 0) { |
Jason Sams | 0f505e5 | 2009-10-13 17:18:35 -0700 | [diff] [blame] | 245 | float damp = 1.0 - ((g_PosPage - g_PosMax) * 4); |
| 246 | damp = clampf(damp, 0.f, 0.9f); |
| 247 | g_PosVelocity *= damp; |
| 248 | } |
Jason Sams | c851479 | 2009-10-29 14:27:29 -0700 | [diff] [blame] | 249 | |
| 250 | g_PosPage += g_PosVelocity * g_DT; |
| 251 | g_PosPage = clampf(g_PosPage, -0.49, g_PosMax + 0.49); |
Jason Sams | 0f505e5 | 2009-10-13 17:18:35 -0700 | [diff] [blame] | 252 | } |
| 253 | |
Jason Sams | 0f505e5 | 2009-10-13 17:18:35 -0700 | [diff] [blame] | 254 | |
| 255 | void |
| 256 | draw_home_button() |
| 257 | { |
Jason Sams | 41b61c8 | 2009-10-15 15:40:54 -0700 | [diff] [blame] | 258 | setColor(1.0f, 1.0f, 1.0f, 1.0f); |
Jason Sams | c851479 | 2009-10-29 14:27:29 -0700 | [diff] [blame] | 259 | bindTexture(NAMED_PFTexNearest, 0, state->homeButtonId); |
Jason Sams | 96b49d8 | 2009-10-20 14:28:53 -0700 | [diff] [blame] | 260 | float x = (SCREEN_WIDTH_PX - params->homeButtonTextureWidth) / 2; |
Jason Sams | 6471c8b | 2010-01-20 14:15:22 -0800 | [diff] [blame] | 261 | float y = -g_Animation * params->homeButtonTextureHeight; |
Jason Sams | 0f505e5 | 2009-10-13 17:18:35 -0700 | [diff] [blame] | 262 | |
Jason Sams | c851479 | 2009-10-29 14:27:29 -0700 | [diff] [blame] | 263 | y -= 30; // move the house to the edge of the screen as it doesn't fill the texture. |
Jason Sams | 96b49d8 | 2009-10-20 14:28:53 -0700 | [diff] [blame] | 264 | drawSpriteScreenspace(x, y, 0, params->homeButtonTextureWidth, params->homeButtonTextureHeight); |
Jason Sams | 0f505e5 | 2009-10-13 17:18:35 -0700 | [diff] [blame] | 265 | } |
| 266 | |
Jason Sams | 09c6fc0 | 2009-10-16 17:23:23 -0700 | [diff] [blame] | 267 | void drawFrontGrid(float rowOffset, float p) |
Jason Sams | 0f505e5 | 2009-10-13 17:18:35 -0700 | [diff] [blame] | 268 | { |
| 269 | float h = getHeight(); |
| 270 | float w = getWidth(); |
| 271 | |
| 272 | int intRowOffset = rowOffset; |
| 273 | float rowFrac = rowOffset - intRowOffset; |
| 274 | float colWidth = getWidth() / 4; |
| 275 | float rowHeight = colWidth + 25.f; |
Jason Sams | b4ecab2 | 2010-01-19 16:43:26 -0800 | [diff] [blame] | 276 | float yoff = 0.5f * h + 1.5f * rowHeight; |
Jason Sams | 0f505e5 | 2009-10-13 17:18:35 -0700 | [diff] [blame] | 277 | |
| 278 | int row, col; |
Jason Sams | b4ecab2 | 2010-01-19 16:43:26 -0800 | [diff] [blame] | 279 | int iconNum = (intRowOffset - 5) * 4; |
Jason Sams | 0f505e5 | 2009-10-13 17:18:35 -0700 | [diff] [blame] | 280 | |
Jason Sams | b4ecab2 | 2010-01-19 16:43:26 -0800 | [diff] [blame] | 281 | bindProgramVertex(NAMED_PVCurve); |
| 282 | |
| 283 | storeF(ALLOC_VP_CONSTANTS, 4, p); |
| 284 | |
Jason Sams | e78ace9 | 2010-02-02 17:37:44 -0800 | [diff] [blame^] | 285 | setColor(1.0f, 1.0f, 1.0f, 1.0f); |
Jason Sams | b4ecab2 | 2010-01-19 16:43:26 -0800 | [diff] [blame] | 286 | for (row = -5; row < 15; row++) { |
Jason Sams | 0f505e5 | 2009-10-13 17:18:35 -0700 | [diff] [blame] | 287 | float y = yoff - ((-rowFrac + row) * rowHeight); |
| 288 | |
| 289 | for (col=0; col < 4; col++) { |
| 290 | if (iconNum >= state->iconCount) { |
| 291 | return; |
| 292 | } |
| 293 | |
| 294 | if (iconNum >= 0) { |
Jason Sams | b4ecab2 | 2010-01-19 16:43:26 -0800 | [diff] [blame] | 295 | float x = colWidth * col + (colWidth / 2); |
Jason Sams | b4ecab2 | 2010-01-19 16:43:26 -0800 | [diff] [blame] | 296 | storeF(ALLOC_VP_CONSTANTS, 2, x); |
Jason Sams | 1a94ee3 | 2010-01-20 13:34:30 -0800 | [diff] [blame] | 297 | |
Jason Sams | 37f262d | 2010-01-20 11:19:51 -0800 | [diff] [blame] | 298 | if (state->selectedIconIndex == iconNum && !p) { |
Jason Sams | 1a94ee3 | 2010-01-20 13:34:30 -0800 | [diff] [blame] | 299 | bindProgramFragment(NAMED_PFTexNearest); |
| 300 | bindTexture(NAMED_PFTexNearest, 0, state->selectedIconTexture); |
| 301 | storeF(ALLOC_VP_CONSTANTS, 0, SELECTION_TEXTURE_WIDTH_PX); |
| 302 | storeF(ALLOC_VP_CONSTANTS, 1, SELECTION_TEXTURE_HEIGHT_PX); |
| 303 | storeF(ALLOC_VP_CONSTANTS, 3, y - (SELECTION_TEXTURE_HEIGHT_PX - ICON_TEXTURE_HEIGHT_PX) * 0.5f); |
| 304 | drawSimpleMesh(NAMED_SMCell); |
Jason Sams | 37f262d | 2010-01-20 11:19:51 -0800 | [diff] [blame] | 305 | } |
| 306 | |
Jason Sams | 1a94ee3 | 2010-01-20 13:34:30 -0800 | [diff] [blame] | 307 | bindProgramFragment(NAMED_PFTexMip); |
| 308 | storeF(ALLOC_VP_CONSTANTS, 0, ICON_TEXTURE_WIDTH_PX); |
| 309 | storeF(ALLOC_VP_CONSTANTS, 1, ICON_TEXTURE_HEIGHT_PX); |
| 310 | storeF(ALLOC_VP_CONSTANTS, 3, y); |
Jason Sams | b4ecab2 | 2010-01-19 16:43:26 -0800 | [diff] [blame] | 311 | bindTexture(NAMED_PFTexMip, 0, loadI32(ALLOC_ICON_IDS, iconNum)); |
| 312 | drawSimpleMesh(NAMED_SMCell); |
Joe Onorato | 742d7fc | 2009-10-15 19:48:16 -0700 | [diff] [blame] | 313 | |
Jason Sams | 37f262d | 2010-01-20 11:19:51 -0800 | [diff] [blame] | 314 | bindProgramFragment(NAMED_PFTexMipAlpha); |
Jason Sams | b4ecab2 | 2010-01-19 16:43:26 -0800 | [diff] [blame] | 315 | storeF(ALLOC_VP_CONSTANTS, 0, 128.f); |
| 316 | storeF(ALLOC_VP_CONSTANTS, 1, 64.f); |
| 317 | storeF(ALLOC_VP_CONSTANTS, 3, y - 64.f); |
Jason Sams | 37f262d | 2010-01-20 11:19:51 -0800 | [diff] [blame] | 318 | bindTexture(NAMED_PFTexMipAlpha, 0, loadI32(ALLOC_LABEL_IDS, iconNum)); |
Jason Sams | b4ecab2 | 2010-01-19 16:43:26 -0800 | [diff] [blame] | 319 | drawSimpleMesh(NAMED_SMCell); |
Jason Sams | 0f505e5 | 2009-10-13 17:18:35 -0700 | [diff] [blame] | 320 | } |
| 321 | iconNum++; |
| 322 | } |
| 323 | } |
| 324 | } |
| 325 | |
Jason Sams | 0f505e5 | 2009-10-13 17:18:35 -0700 | [diff] [blame] | 326 | |
| 327 | int |
| 328 | main(int launchID) |
| 329 | { |
| 330 | // Compute dt in seconds. |
| 331 | int newTime = uptimeMillis(); |
| 332 | g_DT = (newTime - g_LastTime) / 1000.f; |
| 333 | g_LastTime = newTime; |
Jason Sams | 2e19c05 | 2009-10-20 18:19:55 -0700 | [diff] [blame] | 334 | |
Jason Sams | 0f505e5 | 2009-10-13 17:18:35 -0700 | [diff] [blame] | 335 | if (!g_DrawLastFrame) { |
| 336 | // If we stopped rendering we cannot use DT. |
| 337 | // assume 30fps in this case. |
| 338 | g_DT = 0.033f; |
| 339 | } |
Jason Sams | b52dfa0 | 2009-10-14 20:16:14 -0700 | [diff] [blame] | 340 | // physics may break if DT is large. |
| 341 | g_DT = minf(g_DT, 0.2f); |
Jason Sams | 0f505e5 | 2009-10-13 17:18:35 -0700 | [diff] [blame] | 342 | |
| 343 | if (g_Zoom != state->zoomTarget) { |
Jason Sams | 6471c8b | 2010-01-20 14:15:22 -0800 | [diff] [blame] | 344 | float dz = g_DT * 1.7f; |
| 345 | if (state->zoomTarget < 0.5f) { |
| 346 | dz = -dz; |
Jason Sams | 0f505e5 | 2009-10-13 17:18:35 -0700 | [diff] [blame] | 347 | } |
| 348 | if (fabsf(g_Zoom - state->zoomTarget) < fabsf(dz)) { |
| 349 | g_Zoom = state->zoomTarget; |
| 350 | } else { |
| 351 | g_Zoom += dz; |
| 352 | } |
Jason Sams | 6471c8b | 2010-01-20 14:15:22 -0800 | [diff] [blame] | 353 | g_Animation = powf(1-g_Zoom, 3); |
Jason Sams | 0f505e5 | 2009-10-13 17:18:35 -0700 | [diff] [blame] | 354 | updateReadback(); |
| 355 | } |
| 356 | |
| 357 | // Set clear value to dim the background based on the zoom position. |
Jason Sams | 41b61c8 | 2009-10-15 15:40:54 -0700 | [diff] [blame] | 358 | if ((g_Zoom < 0.001f) && (state->zoomTarget < 0.001f) && !g_SpecialHWWar) { |
Jason Sams | 0f505e5 | 2009-10-13 17:18:35 -0700 | [diff] [blame] | 359 | pfClearColor(0.0f, 0.0f, 0.0f, 0.0f); |
| 360 | // When we're zoomed out and not tracking motion events, reset the pos to 0. |
| 361 | if (!g_LastTouchDown) { |
| 362 | g_PosPage = 0; |
| 363 | } |
| 364 | return lastFrame(0); |
Jason Sams | 0f505e5 | 2009-10-13 17:18:35 -0700 | [diff] [blame] | 365 | } else { |
| 366 | pfClearColor(0.0f, 0.0f, 0.0f, g_Zoom); |
| 367 | } |
| 368 | |
| 369 | // icons & labels |
| 370 | int iconCount = state->iconCount; |
| 371 | g_PosMax = ((iconCount + 3) / 4) - 4; |
| 372 | if (g_PosMax < 0) g_PosMax = 0; |
| 373 | |
| 374 | updatePos(0.1f); |
| 375 | updateReadback(); |
| 376 | |
| 377 | //debugF(" draw g_PosPage", g_PosPage); |
| 378 | |
| 379 | // Draw the icons ======================================== |
Jason Sams | 6471c8b | 2010-01-20 14:15:22 -0800 | [diff] [blame] | 380 | drawFrontGrid(g_PosPage, g_Animation); |
Jason Sams | c851479 | 2009-10-29 14:27:29 -0700 | [diff] [blame] | 381 | |
| 382 | bindProgramFragment(NAMED_PFTexNearest); |
Jason Sams | b52dfa0 | 2009-10-14 20:16:14 -0700 | [diff] [blame] | 383 | draw_home_button(); |
Jason Sams | 0f505e5 | 2009-10-13 17:18:35 -0700 | [diff] [blame] | 384 | |
Jason Sams | 41b61c8 | 2009-10-15 15:40:54 -0700 | [diff] [blame] | 385 | // This is a WAR to do a rendering pass without drawing during init to |
| 386 | // force the driver to preload and compile its shaders. |
| 387 | // Without this the first animation does not appear due to the time it |
| 388 | // takes to init the driver state. |
| 389 | if (g_SpecialHWWar) { |
| 390 | g_SpecialHWWar = 0; |
| 391 | return 1; |
| 392 | } |
| 393 | |
Jason Sams | 0f505e5 | 2009-10-13 17:18:35 -0700 | [diff] [blame] | 394 | // Bug workaround where the last frame is not always displayed |
| 395 | // So we keep rendering until the bug is fixed. |
Mike Cleron | 7d5d746 | 2009-10-20 14:06:00 -0700 | [diff] [blame] | 396 | return lastFrame((g_PosVelocity != 0) || fracf(g_PosPage) || g_Zoom != state->zoomTarget || (g_MoveToTime != 0)); |
Jason Sams | 0f505e5 | 2009-10-13 17:18:35 -0700 | [diff] [blame] | 397 | } |
| 398 | |