| 941 | } |
| 942 | |
| 943 | void InitTerrain(void) { |
| 944 | int i, w, h, t; |
| 945 | |
| 946 | // set sky texture to unused |
| 947 | Terrain_sky.textured = 0; |
| 948 | |
| 949 | // Setup stuff for rendering |
| 950 | if (!Dedicated_server) { |
| 951 | Terrain_rotate_list = (uint16_t *)mem_malloc(TERRAIN_WIDTH * TERRAIN_DEPTH * sizeof(uint16_t)); |
| 952 | ASSERT(Terrain_rotate_list); |
| 953 | |
| 954 | World_point_buffer = (g3Point *)mem_malloc(TERRAIN_WIDTH * TERRAIN_DEPTH * sizeof(g3Point)); |
| 955 | ASSERT(World_point_buffer); |
| 956 | |
| 957 | // Allocate space for lod delta tree and unique texture IDs |
| 958 | for (i = 0; i < MAX_TERRAIN_LOD - 1; i++) { |
| 959 | w = TERRAIN_WIDTH >> ((MAX_TERRAIN_LOD - 1) - i); |
| 960 | h = TERRAIN_DEPTH >> ((MAX_TERRAIN_LOD - 1) - i); |
| 961 | |
| 962 | TerrainDeltaBlocks[i] = (float *)mem_malloc(w * h * sizeof(float)); |
| 963 | } |
| 964 | } |
| 965 | |
| 966 | // Allocate space for lod normals |
| 967 | |
| 968 | for (i = MAX_TERRAIN_LOD - 1; i < MAX_TERRAIN_LOD; i++) { |
| 969 | w = TERRAIN_WIDTH >> ((MAX_TERRAIN_LOD - 1) - i); |
| 970 | h = TERRAIN_DEPTH >> ((MAX_TERRAIN_LOD - 1) - i); |
| 971 | |
| 972 | TerrainNormals[i] = (terrain_normals *)mem_malloc(w * h * sizeof(terrain_normals)); |
| 973 | memset(TerrainNormals[i], 0, w * h * sizeof(terrain_normals)); |
| 974 | } |
| 975 | |
| 976 | // Allocate space for our min/max tables |
| 977 | for (i = 0; i < 7; i++) { |
| 978 | w = 1 << i; |
| 979 | h = 1 << i; |
| 980 | |
| 981 | // Index 1 cuts the whole thing into 4ths, index 2 into 8ths, etc |
| 982 | Terrain_min_height_int[i] = (uint8_t *)mem_malloc(w * h * sizeof(uint8_t)); |
| 983 | Terrain_max_height_int[i] = (uint8_t *)mem_malloc(w * h * sizeof(uint8_t)); |
| 984 | |
| 985 | ASSERT(Terrain_min_height_int[i] != NULL); |
| 986 | ASSERT(Terrain_max_height_int[i] != NULL); |
| 987 | } |
| 988 | |
| 989 | Terrain_sky.lightangle = 0; |
| 990 | Terrain_sky.num_satellites = 1; |
| 991 | Terrain_sky.damage_per_second = 0; |
| 992 | |
| 993 | SetupSky(SKY_RADIUS, TF_STARS | TF_SATELLITES, 1); |
| 994 | GenerateLightSource(); |
| 995 | |
| 996 | for (i = 0; i < 4; i++) { |
| 997 | TerrainLightmaps[i] = lm_AllocLightmap(128, 128); |
| 998 | ASSERT(TerrainLightmaps[i] != BAD_LM_INDEX); |
| 999 | GameLightmaps[TerrainLightmaps[i]].flags |= LF_WRAP; |
| 1000 | } |
no test coverage detected