Changeset 677
- Timestamp:
- Jul 29, 2015, 5:52:17 PM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
soft/giet_vm/applications/raycast/disp.c
r676 r677 14 14 // Globals 15 15 16 unsigned char buf0[FBUF_X_SIZE * FBUF_Y_SIZE] __attribute__((aligned(64)));17 unsigned char buf1[FBUF_X_SIZE * FBUF_Y_SIZE] __attribute__((aligned(64)));18 unsigned int sts0[16] __attribute__((aligned(64)));19 unsigned int sts1[16] __attribute__((aligned(64)));20 unsigned int cur_buf;16 static unsigned char buf0[FBUF_X_SIZE * FBUF_Y_SIZE] __attribute__((aligned(64))); 17 static unsigned char buf1[FBUF_X_SIZE * FBUF_Y_SIZE] __attribute__((aligned(64))); 18 static unsigned int sts0[16] __attribute__((aligned(64))); 19 static unsigned int sts1[16] __attribute__((aligned(64))); 20 static unsigned int cur_buf; 21 21 22 22 // Textures indexed by block number … … 32 32 // Local functions 33 33 34 static void dispDrawColumn(int x, int y0, int y1, unsigned char color) 35 { 36 unsigned char* buf = (cur_buf == 0 ? buf0 : buf1); 37 38 if (x < 0 || x > FBUF_X_SIZE) 39 return; 40 41 if (y0 < 0) 42 y0 = 0; 43 44 for (; y0 < y1 && y0 < FBUF_Y_SIZE; y0++) { 45 buf[y0 * FBUF_X_SIZE + x] = color; 46 } 47 } 48 49 static void dispDrawScrColumn(Game *game, int x, int height, int type, float tx) 34 static void dispDrawColumnTex(int x, int y0, int y1, unsigned char *tex, int tx) 35 { 36 unsigned char* buf = (cur_buf == 0 ? buf0 : buf1); 37 int y; 38 39 if (x < 0 || x >= FBUF_X_SIZE) 40 return; 41 42 for (y = y0; y < y1 && y < FBUF_Y_SIZE; y++) { 43 if (y < 0) 44 y = 0; 45 46 int ty = (y - y0) * TEX_SIZE / (y1 - y0); 47 48 buf[y * FBUF_X_SIZE + x] = tex[ty * TEX_SIZE + tx]; 49 } 50 } 51 52 static void dispDrawColumnSolid(int x, int y0, int y1, unsigned char color) 53 { 54 unsigned char* buf = (cur_buf == 0 ? buf0 : buf1); 55 int y; 56 57 if (x < 0 || x >= FBUF_X_SIZE) 58 return; 59 60 for (y = y0; y < y1 && y < FBUF_Y_SIZE; y++) { 61 if (y < 0) 62 y = 0; 63 64 buf[y * FBUF_X_SIZE + x] = color; 65 } 66 } 67 68 static void dispDrawSlice(Game *game, int x, int height, int type, float tx) 50 69 { 51 70 // Ceiling 52 dispDrawColumn (x,53 0,54 (FBUF_Y_SIZE - height) / 2,55 CEILING_COLOR);71 dispDrawColumnSolid(x, 72 0, 73 (FBUF_Y_SIZE - height) / 2, 74 CEILING_COLOR); 56 75 57 76 // Wall … … 60 79 if (tex) { 61 80 // Draw a texture slice 62 dispDrawColumn(x, 63 (FBUF_Y_SIZE - height) / 2, 64 (FBUF_Y_SIZE + height) / 2, 65 (x % 2 ? 0xAF : 0x7F)); 66 /*Kentec320x240x16_SSD2119TexDrawV( 67 NULL, x, 68 (FBUF_Y_SIZE - height) / 2, (FBUF_Y_SIZE + height) / 2, 69 &tex[(int)(tx * TEX_SIZE) * TEX_SIZE], TEX_SIZE 70 );*/ 81 dispDrawColumnTex(x, 82 (FBUF_Y_SIZE - height) / 2, 83 (FBUF_Y_SIZE + height) / 2, 84 tex, 85 (int)(tx * TEX_SIZE)); 71 86 } 72 87 else { 73 88 // Draw a solid color slice 74 dispDrawColumn (x,75 (FBUF_Y_SIZE - height) / 2,76 (FBUF_Y_SIZE + height) / 2,77 0xFF);89 dispDrawColumnSolid(x, 90 (FBUF_Y_SIZE - height) / 2, 91 (FBUF_Y_SIZE + height) / 2, 92 0xFF); 78 93 } 79 94 80 95 // Floor 81 dispDrawColumn (x,82 (FBUF_Y_SIZE + height) / 2,83 FBUF_Y_SIZE,84 FLOOR_COLOR);96 dispDrawColumnSolid(x, 97 (FBUF_Y_SIZE + height) / 2, 98 FBUF_Y_SIZE, 99 FLOOR_COLOR); 85 100 } 86 101 … … 157 172 } 158 173 159 unsigned char *loadTexture(char *path)174 static unsigned char *loadTexture(char *path) 160 175 { 161 176 int fd; … … 169 184 } 170 185 171 giet_fat_read(fd, g_tex[1], TEX_SIZE * TEX_SIZE);186 giet_fat_read(fd, tex, TEX_SIZE * TEX_SIZE); 172 187 giet_fat_close(fd); 173 188 giet_tty_printf("[RAYCAST] loaded tex %s\n", path); … … 191 206 g_tex[4] = loadTexture("misc/wood_32.raw"); 192 207 193 208 cur_buf = 0; 194 209 } 195 210 196 211 void dispRender(Game *game) 197 212 { 198 213 int start = giet_proctime(); 199 214 float angle = game->player.dir - FIELD_OF_VIEW / 2.f; 200 215 … … 213 228 214 229 // Draw ceiling, wall and floor 215 dispDrawS crColumn(game, i, FBUF_Y_SIZE / dist, type, tx);230 dispDrawSlice(game, i, FBUF_Y_SIZE / dist, type, tx); 216 231 217 232 angle += FIELD_OF_VIEW / FBUF_X_SIZE; 218 233 } 219 234 220 221 222 223 } 235 giet_fbf_cma_display(cur_buf); 236 cur_buf = !cur_buf; 237 giet_tty_printf("[RAYCAST] flip (took %d cycles)\n", giet_proctime() - start); 238 }
Note: See TracChangeset
for help on using the changeset viewer.