* Open the requested tile file. * * NetHack1.tib file is a series of * 'struct planar_tile_struct' structures, one for each * glyph tile. * * NetHack2.tib file is a series of * char arrays [TILE_Y][TILE_X] in dimensions, one for each * glyph tile. * * There is 1024 bytes (1K) of header information * at the start of each .tib file. The first glyph tile starts at * location 1024. * */
| 83 | * |
| 84 | */ |
| 85 | int |
| 86 | OpenTileFile(char *tilefilename, boolean filestyle) |
| 87 | { |
| 88 | #ifdef TILES_IN_RAM |
| 89 | int k; |
| 90 | #endif |
| 91 | if (filestyle) { |
| 92 | tilefile_O = fopen(tilefilename, "rb"); |
| 93 | if (tilefile_O == (FILE *) 0) |
| 94 | return 1; |
| 95 | } else { |
| 96 | tilefile = fopen(tilefilename, "rb"); |
| 97 | if (tilefile == (FILE *) 0) |
| 98 | return 1; |
| 99 | } |
| 100 | #ifdef TILES_IN_RAM |
| 101 | if (iflags.preload_tiles) { |
| 102 | if (filestyle) { |
| 103 | struct overview_planar_cell_struct *gp; |
| 104 | long ram_needed = |
| 105 | sizeof(struct overview_planar_cell_struct) * total_tiles_used; |
| 106 | if (fseek(tilefile_O, (long) TIBHEADER_SIZE, |
| 107 | SEEK_SET)) { /*failure*/ |
| 108 | } |
| 109 | oramtiles = |
| 110 | (struct overview_planar_cell_struct *) alloc(ram_needed); |
| 111 | /* Todo: fall back to file method here if alloc failed */ |
| 112 | gp = oramtiles; |
| 113 | for (k = 0; k < total_tiles_used; ++k) { |
| 114 | fread(gp, sizeof(struct overview_planar_cell_struct), 1, |
| 115 | tilefile_O); |
| 116 | ++gp; |
| 117 | } |
| 118 | #ifdef DEBUG_RAMTILES |
| 119 | pline("%d overview tiles read into ram.", k); |
| 120 | mark_synch(); |
| 121 | #endif |
| 122 | otiles_in_ram = TRUE; |
| 123 | } else { |
| 124 | struct planar_cell_struct *gp; |
| 125 | long ram_needed = |
| 126 | sizeof(struct planar_cell_struct) * total_tiles_used; |
| 127 | if (fseek(tilefile, (long) TIBHEADER_SIZE, |
| 128 | SEEK_SET)) { /*failure*/ |
| 129 | } |
| 130 | ramtiles = (struct planar_cell_struct *) alloc(ram_needed); |
| 131 | /* Todo: fall back to file method here if alloc failed */ |
| 132 | gp = ramtiles; |
| 133 | for (k = 0; k < total_tiles_used; ++k) { |
| 134 | fread(gp, sizeof(struct planar_cell_struct), 1, tilefile); |
| 135 | ++gp; |
| 136 | } |
| 137 | #ifdef DEBUG_RAMTILES |
| 138 | pline("%d tiles read into ram.", k); |
| 139 | mark_synch(); |
| 140 | #endif |
| 141 | tiles_in_ram = TRUE; |
| 142 | } |