MCPcopy Create free account
hub / github.com/DFHack/dfhack / loadTexture

Method loadTexture

library/modules/Textures.cpp:162–196  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

160}
161
162TexposHandle Textures::loadTexture(SDL_Surface* surface, bool reserved) {
163 if (!surface || !enabler)
164 return 0; // should be some error, i guess
165 if (loading_state)
166 reserved = true; // use reserved range during loading for all textures
167
168 auto handle = reinterpret_cast<uintptr_t>(surface);
169 g_handle_to_surface.emplace(handle, surface);
170 surface->refcount++; // prevent destruct on next FreeSurface by game
171
172 if (reserved && reserved_range.is_installed) {
173 auto texpos = reserved_range.get_new_texpos();
174 if (texpos != -1) {
175 insert_texture(surface, texpos);
176 g_handle_to_reserved_texpos.emplace(handle, texpos);
177 dummy_surface->refcount--;
178 return handle;
179 }
180
181 if (loading_state) { // if we in loading state and reserved range is full -> error
182 ERR(textures).printerr("reserved range limit has been reached, use dynamic range\n");
183 return 0;
184 }
185 }
186
187 // if we here in loading state = true, then it should be dynamic range -> delay reg
188 if (loading_state) {
189 g_delayed_regs.push_back(handle);
190 } else {
191 auto texpos = add_texture(surface);
192 g_handle_to_texpos.emplace(handle, texpos);
193 }
194
195 return handle;
196}
197
198std::vector<TexposHandle> Textures::loadTileset(const std::filesystem::path file, int tile_px_w,
199 int tile_px_h, bool reserved) {

Callers

nothing calls this directly

Calls 3

insert_textureFunction · 0.85
add_textureFunction · 0.85
get_new_texposMethod · 0.80

Tested by

no test coverage detected