Loads a pcx bitmap to be used as a height map
| 793 | |
| 794 | // Loads a pcx bitmap to be used as a height map |
| 795 | int LoadPCXTerrain(char *filename) { |
| 796 | CFILE *infile; |
| 797 | int run = 0, i, total, j, n; |
| 798 | int16_t xmin, ymin, xmax, ymax; |
| 799 | int width, height; |
| 800 | uint8_t buf; |
| 801 | uint8_t *lando; |
| 802 | |
| 803 | if ((infile = cfopen(filename, "rb")) == NULL) |
| 804 | return (0); |
| 805 | |
| 806 | cf_ReadInt(infile); |
| 807 | xmin = cf_ReadShort(infile); |
| 808 | ymin = cf_ReadShort(infile); |
| 809 | xmax = cf_ReadShort(infile); |
| 810 | ymax = cf_ReadShort(infile); |
| 811 | |
| 812 | for (n = 0; n < 116; n++) |
| 813 | cf_ReadByte(infile); |
| 814 | |
| 815 | width = 1 + xmax - xmin; |
| 816 | height = 1 + ymax - ymin; |
| 817 | |
| 818 | total = width * height; |
| 819 | |
| 820 | lando = (uint8_t *)mem_malloc(total); |
| 821 | |
| 822 | mprintf(0, "Heightmap is %d x %d\n", width, height); |
| 823 | |
| 824 | while (run < total) { |
| 825 | buf = cf_ReadByte(infile); |
| 826 | if (buf >= 192) { |
| 827 | uint8_t tb = 0; |
| 828 | tb = cf_ReadByte(infile); |
| 829 | for (i = 0; i < (buf - 192); i++, run++) |
| 830 | lando[run] = tb; |
| 831 | } else { |
| 832 | lando[run] = buf; |
| 833 | run++; |
| 834 | } |
| 835 | } |
| 836 | |
| 837 | cfclose(infile); |
| 838 | |
| 839 | for (i = 0; i < TERRAIN_DEPTH; i++) |
| 840 | for (j = 0; j < TERRAIN_WIDTH; j++) { |
| 841 | n = (int)lando[((i % height) * width) + (j % width)]; |
| 842 | |
| 843 | Terrain_seg[((TERRAIN_WIDTH - 1) - i) * TERRAIN_WIDTH + j].ypos = n; |
| 844 | } |
| 845 | |
| 846 | mem_free(lando); |
| 847 | BuildMinMaxTerrain(); |
| 848 | BuildTerrainNormals(); |
| 849 | GenerateTerrainLight(); |
| 850 | |
| 851 | #if (defined(EDITOR) || defined(NEWEDITOR)) |
| 852 | memset(TerrainSelected, 0, TERRAIN_WIDTH * TERRAIN_DEPTH); |
no test coverage detected