Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AP_Terrain: added parameter for terrain cache size #27079

Merged
merged 1 commit into from
May 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions libraries/AP_Terrain/AP_Terrain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,14 @@ const AP_Param::GroupInfo AP_Terrain::var_info[] = {
// @Range: 0 50
// @User: Advanced
AP_GROUPINFO("OFS_MAX", 4, AP_Terrain, offset_max, 30),


// @Param: CACHE_SZ
// @DisplayName: Terrain cache size
// @Description: The number of 32x28 cache blocks to keep in memory. Each block uses about 1800 bytes of memory
// @Range: 0 128
// @User: Advanced
AP_GROUPINFO("CACHE_SZ", 5, AP_Terrain, config_cache_size, TERRAIN_GRID_BLOCK_CACHE_SIZE),

AP_GROUPEND
};

Expand Down Expand Up @@ -488,13 +495,13 @@ bool AP_Terrain::allocate(void)
if (cache != nullptr) {
return true;
}
cache = (struct grid_cache *)calloc(TERRAIN_GRID_BLOCK_CACHE_SIZE, sizeof(cache[0]));
cache = (struct grid_cache *)calloc(config_cache_size, sizeof(cache[0]));
if (cache == nullptr) {
GCS_SEND_TEXT(MAV_SEVERITY_CRITICAL, "Terrain: Allocation failed");
memory_alloc_failed = true;
return false;
}
cache_size = TERRAIN_GRID_BLOCK_CACHE_SIZE;
cache_size = config_cache_size;
return true;
}

Expand Down
3 changes: 3 additions & 0 deletions libraries/AP_Terrain/AP_Terrain.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,9 @@
#define TERRAIN_GRID_BLOCK_SIZE_Y (TERRAIN_GRID_MAVLINK_SIZE*TERRAIN_GRID_BLOCK_MUL_Y)

// number of grid_blocks in the LRU memory cache
#ifndef TERRAIN_GRID_BLOCK_CACHE_SIZE
#define TERRAIN_GRID_BLOCK_CACHE_SIZE 12
#endif

// format of grid on disk
#define TERRAIN_GRID_FORMAT_VERSION 1
Expand Down Expand Up @@ -371,6 +373,7 @@ class AP_Terrain {
AP_Int16 grid_spacing; // meters between grid points
AP_Int16 options; // option bits
AP_Float offset_max;
AP_Int16 config_cache_size;

enum class Options {
DisableDownload = (1U<<0),
Expand Down
Loading