Skip to content

Commit

Permalink
Add universal sign support for index macros
Browse files Browse the repository at this point in the history
  • Loading branch information
adamscott committed Sep 1, 2024
1 parent 61598c5 commit 90141ac
Show file tree
Hide file tree
Showing 30 changed files with 183 additions and 149 deletions.
118 changes: 76 additions & 42 deletions core/error/error_macros.h

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions core/templates/bin_sorted_array.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class BinSortedArray {
}

uint64_t move(uint64_t p_idx, uint64_t p_bin) {
ERR_FAIL_UNSIGNED_INDEX_V(p_idx, array.size(), -1);
ERR_FAIL_INDEX_V(p_idx, array.size(), -1);

uint64_t current_bin = bin_limits.size() - 1;
while (p_idx > bin_limits[current_bin]) {
Expand Down Expand Up @@ -113,7 +113,7 @@ class BinSortedArray {
}

void remove_at(uint64_t p_idx) {
ERR_FAIL_UNSIGNED_INDEX(p_idx, array.size());
ERR_FAIL_INDEX(p_idx, array.size());
uint64_t new_idx = move(p_idx, 0);
uint64_t swap_idx = array.size() - 1;

Expand Down
8 changes: 4 additions & 4 deletions core/templates/local_vector.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ class LocalVector {
}

void remove_at(U p_index) {
ERR_FAIL_UNSIGNED_INDEX(p_index, count);
ERR_FAIL_INDEX(p_index, count);
count--;
for (U i = p_index; i < count; i++) {
data[i] = data[i + 1];
Expand Down Expand Up @@ -170,11 +170,11 @@ class LocalVector {
}
}
_FORCE_INLINE_ const T &operator[](U p_index) const {
CRASH_BAD_UNSIGNED_INDEX(p_index, count);
CRASH_BAD_INDEX(p_index, count);
return data[p_index];
}
_FORCE_INLINE_ T &operator[](U p_index) {
CRASH_BAD_UNSIGNED_INDEX(p_index, count);
CRASH_BAD_INDEX(p_index, count);
return data[p_index];
}

Expand Down Expand Up @@ -243,7 +243,7 @@ class LocalVector {
}

void insert(U p_pos, T p_val) {
ERR_FAIL_UNSIGNED_INDEX(p_pos, count + 1);
ERR_FAIL_INDEX(p_pos, count + 1);
if (p_pos == count) {
push_back(p_val);
} else {
Expand Down
6 changes: 3 additions & 3 deletions core/templates/paged_array.h
Original file line number Diff line number Diff line change
Expand Up @@ -166,14 +166,14 @@ class PagedArray {

public:
_FORCE_INLINE_ const T &operator[](uint64_t p_index) const {
CRASH_BAD_UNSIGNED_INDEX(p_index, count);
CRASH_BAD_INDEX(p_index, count);
uint32_t page = p_index >> page_size_shift;
uint32_t offset = p_index & page_size_mask;

return page_data[page][offset];
}
_FORCE_INLINE_ T &operator[](uint64_t p_index) {
CRASH_BAD_UNSIGNED_INDEX(p_index, count);
CRASH_BAD_INDEX(p_index, count);
uint32_t page = p_index >> page_size_shift;
uint32_t offset = p_index & page_size_mask;

Expand Down Expand Up @@ -230,7 +230,7 @@ class PagedArray {
}

void remove_at_unordered(uint64_t p_index) {
ERR_FAIL_UNSIGNED_INDEX(p_index, count);
ERR_FAIL_INDEX(p_index, count);
(*this)[p_index] = (*this)[count - 1];
pop_back();
}
Expand Down
2 changes: 1 addition & 1 deletion core/templates/pooled_list.h
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ class PooledList {
}
void free(const U &p_id) {
// should not be on free list already
ERR_FAIL_UNSIGNED_INDEX(p_id, list.size());
ERR_FAIL_INDEX(p_id, list.size());
freelist.push_back(p_id);
ERR_FAIL_COND_MSG(!_used_size, "_used_size has become out of sync, have you double freed an item?");
_used_size--;
Expand Down
20 changes: 10 additions & 10 deletions drivers/gles3/storage/light_storage.h
Original file line number Diff line number Diff line change
Expand Up @@ -824,52 +824,52 @@ class LightStorage : public RendererLightStorage {
_FORCE_INLINE_ int shadow_atlas_get_quadrant_shadows_length(RID p_atlas, uint32_t p_quadrant) {
ShadowAtlas *atlas = shadow_atlas_owner.get_or_null(p_atlas);
ERR_FAIL_NULL_V(atlas, 0);
ERR_FAIL_UNSIGNED_INDEX_V(p_quadrant, 4, 0);
ERR_FAIL_INDEX_V(p_quadrant, 4, 0);
return atlas->quadrants[p_quadrant].shadows.size();
}

_FORCE_INLINE_ uint32_t shadow_atlas_get_quadrant_shadows_allocated(RID p_atlas, uint32_t p_quadrant) {
ShadowAtlas *atlas = shadow_atlas_owner.get_or_null(p_atlas);
ERR_FAIL_NULL_V(atlas, 0);
ERR_FAIL_UNSIGNED_INDEX_V(p_quadrant, 4, 0);
ERR_FAIL_INDEX_V(p_quadrant, 4, 0);
return atlas->quadrants[p_quadrant].textures.size();
}

_FORCE_INLINE_ uint32_t shadow_atlas_get_quadrant_subdivision(RID p_atlas, uint32_t p_quadrant) {
ShadowAtlas *atlas = shadow_atlas_owner.get_or_null(p_atlas);
ERR_FAIL_NULL_V(atlas, 0);
ERR_FAIL_UNSIGNED_INDEX_V(p_quadrant, 4, 0);
ERR_FAIL_INDEX_V(p_quadrant, 4, 0);
return atlas->quadrants[p_quadrant].subdivision;
}

_FORCE_INLINE_ GLuint shadow_atlas_get_quadrant_shadow_texture(RID p_atlas, uint32_t p_quadrant, uint32_t p_shadow) {
ShadowAtlas *atlas = shadow_atlas_owner.get_or_null(p_atlas);
ERR_FAIL_NULL_V(atlas, 0);
ERR_FAIL_UNSIGNED_INDEX_V(p_quadrant, 4, 0);
ERR_FAIL_UNSIGNED_INDEX_V(p_shadow, atlas->quadrants[p_quadrant].textures.size(), 0);
ERR_FAIL_INDEX_V(p_quadrant, 4, 0);
ERR_FAIL_INDEX_V(p_shadow, atlas->quadrants[p_quadrant].textures.size(), 0);
return atlas->quadrants[p_quadrant].textures[p_shadow];
}

_FORCE_INLINE_ GLuint shadow_atlas_get_quadrant_shadow_fb(RID p_atlas, uint32_t p_quadrant, uint32_t p_shadow) {
ShadowAtlas *atlas = shadow_atlas_owner.get_or_null(p_atlas);
ERR_FAIL_NULL_V(atlas, 0);
ERR_FAIL_UNSIGNED_INDEX_V(p_quadrant, 4, 0);
ERR_FAIL_UNSIGNED_INDEX_V(p_shadow, atlas->quadrants[p_quadrant].fbos.size(), 0);
ERR_FAIL_INDEX_V(p_quadrant, 4, 0);
ERR_FAIL_INDEX_V(p_shadow, atlas->quadrants[p_quadrant].fbos.size(), 0);
return atlas->quadrants[p_quadrant].fbos[p_shadow];
}

_FORCE_INLINE_ int shadow_atlas_get_quadrant_shadow_size(RID p_atlas, uint32_t p_quadrant) {
ShadowAtlas *atlas = shadow_atlas_owner.get_or_null(p_atlas);
ERR_FAIL_NULL_V(atlas, 0);
ERR_FAIL_UNSIGNED_INDEX_V(p_quadrant, 4, 0);
ERR_FAIL_INDEX_V(p_quadrant, 4, 0);
return (atlas->size >> 1) / atlas->quadrants[p_quadrant].subdivision;
}

_FORCE_INLINE_ bool shadow_atlas_get_quadrant_shadow_is_omni(RID p_atlas, uint32_t p_quadrant, uint32_t p_shadow) {
ShadowAtlas *atlas = shadow_atlas_owner.get_or_null(p_atlas);
ERR_FAIL_NULL_V(atlas, false);
ERR_FAIL_UNSIGNED_INDEX_V(p_quadrant, 4, false);
ERR_FAIL_UNSIGNED_INDEX_V(p_shadow, (uint32_t)atlas->quadrants[p_quadrant].shadows.size(), false);
ERR_FAIL_INDEX_V(p_quadrant, 4, false);
ERR_FAIL_INDEX_V(p_shadow, (uint32_t)atlas->quadrants[p_quadrant].shadows.size(), false);
return atlas->quadrants[p_quadrant].shadows[p_shadow].owner_is_omni;
}

Expand Down
14 changes: 7 additions & 7 deletions drivers/gles3/storage/mesh_storage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -471,7 +471,7 @@ RS::BlendShapeMode MeshStorage::mesh_get_blend_shape_mode(RID p_mesh) const {
void MeshStorage::mesh_surface_update_vertex_region(RID p_mesh, int p_surface, int p_offset, const Vector<uint8_t> &p_data) {
Mesh *mesh = mesh_owner.get_or_null(p_mesh);
ERR_FAIL_NULL(mesh);
ERR_FAIL_UNSIGNED_INDEX((uint32_t)p_surface, mesh->surface_count);
ERR_FAIL_INDEX((uint32_t)p_surface, mesh->surface_count);
ERR_FAIL_COND(p_data.is_empty());

uint64_t data_size = p_data.size();
Expand All @@ -486,7 +486,7 @@ void MeshStorage::mesh_surface_update_vertex_region(RID p_mesh, int p_surface, i
void MeshStorage::mesh_surface_update_attribute_region(RID p_mesh, int p_surface, int p_offset, const Vector<uint8_t> &p_data) {
Mesh *mesh = mesh_owner.get_or_null(p_mesh);
ERR_FAIL_NULL(mesh);
ERR_FAIL_UNSIGNED_INDEX((uint32_t)p_surface, mesh->surface_count);
ERR_FAIL_INDEX((uint32_t)p_surface, mesh->surface_count);
ERR_FAIL_COND(p_data.is_empty());

uint64_t data_size = p_data.size();
Expand All @@ -501,7 +501,7 @@ void MeshStorage::mesh_surface_update_attribute_region(RID p_mesh, int p_surface
void MeshStorage::mesh_surface_update_skin_region(RID p_mesh, int p_surface, int p_offset, const Vector<uint8_t> &p_data) {
Mesh *mesh = mesh_owner.get_or_null(p_mesh);
ERR_FAIL_NULL(mesh);
ERR_FAIL_UNSIGNED_INDEX((uint32_t)p_surface, mesh->surface_count);
ERR_FAIL_INDEX((uint32_t)p_surface, mesh->surface_count);
ERR_FAIL_COND(p_data.is_empty());

uint64_t data_size = p_data.size();
Expand All @@ -516,7 +516,7 @@ void MeshStorage::mesh_surface_update_skin_region(RID p_mesh, int p_surface, int
void MeshStorage::mesh_surface_set_material(RID p_mesh, int p_surface, RID p_material) {
Mesh *mesh = mesh_owner.get_or_null(p_mesh);
ERR_FAIL_NULL(mesh);
ERR_FAIL_UNSIGNED_INDEX((uint32_t)p_surface, mesh->surface_count);
ERR_FAIL_INDEX((uint32_t)p_surface, mesh->surface_count);
mesh->surfaces[p_surface]->material = p_material;

mesh->dependency.changed_notify(Dependency::DEPENDENCY_CHANGED_MATERIAL);
Expand All @@ -526,15 +526,15 @@ void MeshStorage::mesh_surface_set_material(RID p_mesh, int p_surface, RID p_mat
RID MeshStorage::mesh_surface_get_material(RID p_mesh, int p_surface) const {
Mesh *mesh = mesh_owner.get_or_null(p_mesh);
ERR_FAIL_NULL_V(mesh, RID());
ERR_FAIL_UNSIGNED_INDEX_V((uint32_t)p_surface, mesh->surface_count, RID());
ERR_FAIL_INDEX_V((uint32_t)p_surface, mesh->surface_count, RID());

return mesh->surfaces[p_surface]->material;
}

RS::SurfaceData MeshStorage::mesh_get_surface(RID p_mesh, int p_surface) const {
Mesh *mesh = mesh_owner.get_or_null(p_mesh);
ERR_FAIL_NULL_V(mesh, RS::SurfaceData());
ERR_FAIL_UNSIGNED_INDEX_V((uint32_t)p_surface, mesh->surface_count, RS::SurfaceData());
ERR_FAIL_INDEX_V((uint32_t)p_surface, mesh->surface_count, RS::SurfaceData());

Mesh::Surface &s = *mesh->surfaces[p_surface];

Expand Down Expand Up @@ -1567,7 +1567,7 @@ void MeshStorage::_multimesh_mark_dirty(MultiMesh *multimesh, int p_index, bool
uint32_t region_index = p_index / MULTIMESH_DIRTY_REGION_SIZE;
#ifdef DEBUG_ENABLED
uint32_t data_cache_dirty_region_count = Math::division_round_up(multimesh->instances, MULTIMESH_DIRTY_REGION_SIZE);
ERR_FAIL_UNSIGNED_INDEX(region_index, data_cache_dirty_region_count); //bug
ERR_FAIL_INDEX(region_index, data_cache_dirty_region_count); //bug
#endif
if (!multimesh->data_cache_dirty_regions[region_index]) {
multimesh->data_cache_dirty_regions[region_index] = true;
Expand Down
4 changes: 2 additions & 2 deletions drivers/gles3/storage/mesh_storage.h
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ class MeshStorage : public RendererMeshStorage {
_FORCE_INLINE_ void *mesh_get_surface(RID p_mesh, uint32_t p_surface_index) {
Mesh *mesh = mesh_owner.get_or_null(p_mesh);
ERR_FAIL_NULL_V(mesh, nullptr);
ERR_FAIL_UNSIGNED_INDEX_V(p_surface_index, mesh->surface_count, nullptr);
ERR_FAIL_INDEX_V(p_surface_index, mesh->surface_count, nullptr);

return mesh->surfaces[p_surface_index];
}
Expand Down Expand Up @@ -460,7 +460,7 @@ class MeshStorage : public RendererMeshStorage {
MeshInstance *mi = mesh_instance_owner.get_or_null(p_mesh_instance);
ERR_FAIL_NULL(mi);
Mesh *mesh = mi->mesh;
ERR_FAIL_UNSIGNED_INDEX(p_surface_index, mesh->surface_count);
ERR_FAIL_INDEX(p_surface_index, mesh->surface_count);

MeshInstance::Surface *mis = &mi->surfaces[p_surface_index];
Mesh::Surface *s = mesh->surfaces[p_surface_index];
Expand Down
6 changes: 3 additions & 3 deletions drivers/gles3/storage/utilities.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -373,17 +373,17 @@ uint64_t Utilities::get_captured_timestamps_frame() const {
}

uint64_t Utilities::get_captured_timestamp_gpu_time(uint32_t p_index) const {
ERR_FAIL_UNSIGNED_INDEX_V(p_index, frames[frame].timestamp_result_count, 0);
ERR_FAIL_INDEX_V(p_index, frames[frame].timestamp_result_count, 0);
return frames[frame].timestamp_result_values[p_index];
}

uint64_t Utilities::get_captured_timestamp_cpu_time(uint32_t p_index) const {
ERR_FAIL_UNSIGNED_INDEX_V(p_index, frames[frame].timestamp_result_count, 0);
ERR_FAIL_INDEX_V(p_index, frames[frame].timestamp_result_count, 0);
return frames[frame].timestamp_cpu_result_values[p_index];
}

String Utilities::get_captured_timestamp_name(uint32_t p_index) const {
ERR_FAIL_UNSIGNED_INDEX_V(p_index, frames[frame].timestamp_result_count, String());
ERR_FAIL_INDEX_V(p_index, frames[frame].timestamp_result_count, String());
return frames[frame].timestamp_result_names[p_index];
}

Expand Down
10 changes: 5 additions & 5 deletions modules/interactive_music/audio_stream_interactive.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -249,9 +249,9 @@ PackedInt32Array AudioStreamInteractive::get_transition_list() const {
void AudioStreamInteractive::add_transition(int p_from_clip, int p_to_clip, TransitionFromTime p_from_time, TransitionToTime p_to_time, FadeMode p_fade_mode, float p_fade_beats, bool p_use_filler_flip, int p_filler_clip, bool p_hold_previous) {
ERR_FAIL_COND(p_from_clip < CLIP_ANY || p_from_clip >= clip_count);
ERR_FAIL_COND(p_to_clip < CLIP_ANY || p_to_clip >= clip_count);
ERR_FAIL_UNSIGNED_INDEX(p_from_time, TRANSITION_FROM_TIME_MAX);
ERR_FAIL_UNSIGNED_INDEX(p_to_time, TRANSITION_TO_TIME_MAX);
ERR_FAIL_UNSIGNED_INDEX(p_fade_mode, FADE_MAX);
ERR_FAIL_INDEX(p_from_time, TRANSITION_FROM_TIME_MAX);
ERR_FAIL_INDEX(p_to_time, TRANSITION_TO_TIME_MAX);
ERR_FAIL_INDEX(p_fade_mode, FADE_MAX);

Transition tr;
tr.from_time = p_from_time;
Expand Down Expand Up @@ -353,8 +353,8 @@ static void _test_and_swap(T &p_elem, uint32_t p_a, uint32_t p_b) {
}

void AudioStreamInteractive::_inspector_array_swap_clip(uint32_t p_item_a, uint32_t p_item_b) {
ERR_FAIL_UNSIGNED_INDEX(p_item_a, (uint32_t)clip_count);
ERR_FAIL_UNSIGNED_INDEX(p_item_b, (uint32_t)clip_count);
ERR_FAIL_INDEX(p_item_a, (uint32_t)clip_count);
ERR_FAIL_INDEX(p_item_b, (uint32_t)clip_count);

for (int i = 0; i < clip_count; i++) {
_test_and_swap(clips[i].auto_advance_next_clip, p_item_a, p_item_b);
Expand Down
6 changes: 3 additions & 3 deletions modules/multiplayer/multiplayer_spawner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ bool MultiplayerSpawner::_set(const StringName &p_name, const Variant &p_value)
String ns = p_name;
if (ns.begins_with("scenes/")) {
uint32_t index = ns.get_slicec('/', 1).to_int();
ERR_FAIL_UNSIGNED_INDEX_V(index, spawnable_scenes.size(), false);
ERR_FAIL_INDEX_V(index, spawnable_scenes.size(), false);
spawnable_scenes[index].path = p_value;
return true;
}
Expand All @@ -61,7 +61,7 @@ bool MultiplayerSpawner::_get(const StringName &p_name, Variant &r_ret) const {
String ns = p_name;
if (ns.begins_with("scenes/")) {
uint32_t index = ns.get_slicec('/', 1).to_int();
ERR_FAIL_UNSIGNED_INDEX_V(index, spawnable_scenes.size(), false);
ERR_FAIL_INDEX_V(index, spawnable_scenes.size(), false);
r_ret = spawnable_scenes[index].path;
return true;
}
Expand Down Expand Up @@ -296,7 +296,7 @@ const Variant MultiplayerSpawner::get_spawn_argument(const ObjectID &p_id) const

Node *MultiplayerSpawner::instantiate_scene(int p_id) {
ERR_FAIL_COND_V_MSG(spawn_limit && spawn_limit <= tracked_nodes.size(), nullptr, "Spawn limit reached!");
ERR_FAIL_UNSIGNED_INDEX_V((uint32_t)p_id, spawnable_scenes.size(), nullptr);
ERR_FAIL_INDEX_V((uint32_t)p_id, spawnable_scenes.size(), nullptr);
SpawnableScene &sc = spawnable_scenes[p_id];
if (sc.cache.is_null()) {
sc.cache = ResourceLoader::load(sc.path);
Expand Down
2 changes: 1 addition & 1 deletion modules/navigation/nav_map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -878,7 +878,7 @@ Vector3 NavMap::get_random_point(uint32_t p_navigation_layers, bool p_uniformly)
RBMap<real_t, uint32_t>::Iterator E = accessible_regions_area_map.find_closest(random_accessible_regions_area_map);
ERR_FAIL_COND_V(!E, Vector3());
uint32_t random_region_index = E->value;
ERR_FAIL_UNSIGNED_INDEX_V(random_region_index, accessible_regions.size(), Vector3());
ERR_FAIL_INDEX_V(random_region_index, accessible_regions.size(), Vector3());

const NavRegion *random_region = accessible_regions[random_region_index];
ERR_FAIL_NULL_V(random_region, Vector3());
Expand Down
4 changes: 2 additions & 2 deletions modules/navigation/nav_region.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ Vector3 NavRegion::get_random_point(uint32_t p_navigation_layers, bool p_uniform
RBMap<real_t, uint32_t>::Iterator region_E = region_area_map.find_closest(region_area_map_pos);
ERR_FAIL_COND_V(!region_E, Vector3());
uint32_t rrp_polygon_index = region_E->value;
ERR_FAIL_UNSIGNED_INDEX_V(rrp_polygon_index, region_polygons.size(), Vector3());
ERR_FAIL_INDEX_V(rrp_polygon_index, region_polygons.size(), Vector3());

const gd::Polygon &rr_polygon = region_polygons[rrp_polygon_index];

Expand All @@ -164,7 +164,7 @@ Vector3 NavRegion::get_random_point(uint32_t p_navigation_layers, bool p_uniform
RBMap<real_t, uint32_t>::Iterator polygon_E = polygon_area_map.find_closest(polygon_area_map_pos);
ERR_FAIL_COND_V(!polygon_E, Vector3());
uint32_t rrp_face_index = polygon_E->value;
ERR_FAIL_UNSIGNED_INDEX_V(rrp_face_index, rr_polygon.points.size(), Vector3());
ERR_FAIL_INDEX_V(rrp_face_index, rr_polygon.points.size(), Vector3());

const Face3 face(rr_polygon.points[0].pos, rr_polygon.points[rrp_face_index - 1].pos, rr_polygon.points[rrp_face_index].pos);

Expand Down
Loading

0 comments on commit 90141ac

Please sign in to comment.