MCPcopy Create free account
hub / github.com/DescentDevelopers/Descent3 / lm_AllocLightmap

Function lm_AllocLightmap

bitmap/lightmap.cpp:59–98  ·  view source on GitHub ↗

Allocs a lightmap of w x h size Returns lightmap handle if successful, -1 if otherwise

Source from the content-addressed store, hash-verified

57// Allocs a lightmap of w x h size
58// Returns lightmap handle if successful, -1 if otherwise
59int lm_AllocLightmap(int w, int h) {
60 int n; //,i;
61 if (Num_of_lightmaps == MAX_LIGHTMAPS)
62 Int3(); // Ran out of lightmaps!
63
64 n = Free_lightmap_list[Num_of_lightmaps++];
65 ASSERT(GameLightmaps[n].used == 0);
66 // If no go on the malloc, bail out with -1
67
68 memset(&GameLightmaps[n], 0, sizeof(bms_lightmap));
69 GameLightmaps[n].data = (uint16_t *)mem_malloc((w * h * 2));
70 if (!GameLightmaps[n].data) {
71 mprintf(0, "NOT ENOUGHT MEMORY FOR LIGHTMAP!\n");
72 Int3();
73 return BAD_LM_INDEX;
74 }
75
76 GameLightmaps[n].width = w;
77 GameLightmaps[n].height = h;
78 GameLightmaps[n].used = 1;
79 GameLightmaps[n].cache_slot = -1;
80 GameLightmaps[n].flags = LF_CHANGED;
81 // Figure out square size
82 // Find power of 2 number
83 int res = std::max(w, h);
84 int lightmap_res = 2;
85 for (int i = 0; i <= 7; i++) {
86 int low_num = 1 < i;
87 int hi_num = 2 << i;
88 if (res <= hi_num && res > low_num) {
89 lightmap_res = hi_num;
90 break;
91 }
92 }
93 ASSERT(lightmap_res >= 2 && lightmap_res <= 128);
94 GameLightmaps[n].square_res = lightmap_res;
95 Lightmap_mem_used += (w * h * 2);
96
97 return n;
98}
99// Given a handle, frees the lightmap memory and flags this lightmap as unused
100void lm_FreeLightmap(int handle) {
101 if (GameLightmaps[handle].used < 1)

Callers 5

SqueezeLightmapsFunction · 0.85
InitDynamicLightingFunction · 0.85
ReadNewLightmapChunkFunction · 0.85
AllocLightmapInfoFunction · 0.85
InitTerrainFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected