Skip to content

Commit

Permalink
Ensure float literals are not doubles
Browse files Browse the repository at this point in the history
  • Loading branch information
TokisanGames committed Feb 17, 2024
1 parent bbbcbb6 commit efcb0f2
Show file tree
Hide file tree
Showing 11 changed files with 86 additions and 86 deletions.
46 changes: 23 additions & 23 deletions src/geoclipmap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ Vector<RID> GeoClipMap::generate(int p_size, int p_levels) {

for (int y = 0; y < PATCH_VERT_RESOLUTION; y++) {
for (int x = 0; x < PATCH_VERT_RESOLUTION; x++) {
vertices[n++] = Vector3(x, 0, y);
vertices[n++] = Vector3(x, 0.f, y);
}
}

Expand All @@ -95,7 +95,7 @@ Vector<RID> GeoClipMap::generate(int p_size, int p_levels) {
}
}

aabb = AABB(Vector3(0, 0, 0), Vector3(PATCH_VERT_RESOLUTION, 0.1, PATCH_VERT_RESOLUTION));
aabb = AABB(Vector3(0.f, 0.f, 0.f), Vector3(PATCH_VERT_RESOLUTION, 0.1f, PATCH_VERT_RESOLUTION));
tile_mesh = _create_mesh(vertices, indices, aabb);
}

Expand All @@ -112,41 +112,41 @@ Vector<RID> GeoClipMap::generate(int p_size, int p_levels) {
int offset = TILE_RESOLUTION;

for (int i = 0; i < PATCH_VERT_RESOLUTION; i++) {
vertices[n] = Vector3(offset + i + 1, 0, 0);
vertices[n] = Vector3(offset + i + 1.f, 0.f, 0.f);
aabb.expand_to(vertices[n]);
n++;

vertices[n] = Vector3(offset + i + 1, 0, 1);
vertices[n] = Vector3(offset + i + 1.f, 0.f, 1.f);
aabb.expand_to(vertices[n]);
n++;
}

for (int i = 0; i < PATCH_VERT_RESOLUTION; i++) {
vertices[n] = Vector3(1, 0, offset + i + 1);
vertices[n] = Vector3(1.f, 0.f, offset + i + 1.f);
aabb.expand_to(vertices[n]);
n++;

vertices[n] = Vector3(0, 0, offset + i + 1);
vertices[n] = Vector3(0.f, 0.f, offset + i + 1.f);
aabb.expand_to(vertices[n]);
n++;
}

for (int i = 0; i < PATCH_VERT_RESOLUTION; i++) {
vertices[n] = Vector3(-real_t(offset + i), 0, 1);
vertices[n] = Vector3(-real_t(offset + i), 0.f, 1.f);
aabb.expand_to(vertices[n]);
n++;

vertices[n] = Vector3(-real_t(offset + i), 0, 0);
vertices[n] = Vector3(-real_t(offset + i), 0.f, 0.f);
aabb.expand_to(vertices[n]);
n++;
}

for (int i = 0; i < PATCH_VERT_RESOLUTION; i++) {
vertices[n] = Vector3(0, 0, -real_t(offset + i));
vertices[n] = Vector3(0.f, 0.f, -real_t(offset + i));
aabb.expand_to(vertices[n]);
n++;

vertices[n] = Vector3(1, 0, -real_t(offset + i));
vertices[n] = Vector3(1.f, 0.f, -real_t(offset + i));
aabb.expand_to(vertices[n]);
n++;
}
Expand Down Expand Up @@ -190,26 +190,26 @@ Vector<RID> GeoClipMap::generate(int p_size, int p_levels) {
indices.resize((CLIPMAP_VERT_RESOLUTION * 2 - 1) * 6);

n = 0;
Vector3 offset = Vector3(0.5f * real_t(CLIPMAP_VERT_RESOLUTION + 1), 0, 0.5f * real_t(CLIPMAP_VERT_RESOLUTION + 1));
Vector3 offset = Vector3(0.5f * real_t(CLIPMAP_VERT_RESOLUTION + 1), 0.f, 0.5f * real_t(CLIPMAP_VERT_RESOLUTION + 1));

for (int i = 0; i < CLIPMAP_VERT_RESOLUTION + 1; i++) {
vertices[n] = Vector3(0, 0, CLIPMAP_VERT_RESOLUTION - i) - offset;
vertices[n] = Vector3(0.f, 0.f, CLIPMAP_VERT_RESOLUTION - i) - offset;
aabb.expand_to(vertices[n]);
n++;

vertices[n] = Vector3(1, 0, CLIPMAP_VERT_RESOLUTION - i) - offset;
vertices[n] = Vector3(1.f, 0.f, CLIPMAP_VERT_RESOLUTION - i) - offset;
aabb.expand_to(vertices[n]);
n++;
}

int start_of_horizontal = n;

for (int i = 0; i < CLIPMAP_VERT_RESOLUTION; i++) {
vertices[n] = Vector3(i + 1, 0, 0) - offset;
vertices[n] = Vector3(i + 1.f, 0.f, 0.f) - offset;
aabb.expand_to(vertices[n]);
n++;

vertices[n] = Vector3(i + 1, 0, 1) - offset;
vertices[n] = Vector3(i + 1.f, 0.f, 1.f) - offset;
aabb.expand_to(vertices[n]);
n++;
}
Expand Down Expand Up @@ -251,23 +251,23 @@ Vector<RID> GeoClipMap::generate(int p_size, int p_levels) {
n = 0;

for (int i = 0; i < PATCH_VERT_RESOLUTION * 2; i++) {
vertices[n] = Vector3(i - real_t(TILE_RESOLUTION), 0, 0);
vertices[n] = Vector3(real_t(i - TILE_RESOLUTION), 0.f, 0.f);
aabb.expand_to(vertices[n]);
n++;

vertices[n] = Vector3(i - real_t(TILE_RESOLUTION), 0, 1);
vertices[n] = Vector3(real_t(i - TILE_RESOLUTION), 0.f, 1.f);
aabb.expand_to(vertices[n]);
n++;
}

int start_of_vertical = n;

for (int i = 0; i < PATCH_VERT_RESOLUTION * 2; i++) {
vertices[n] = Vector3(0, 0, i - real_t(TILE_RESOLUTION));
vertices[n] = Vector3(0.f, 0.f, real_t(i - TILE_RESOLUTION));
aabb.expand_to(vertices[n]);
n++;

vertices[n] = Vector3(1, 0, i - real_t(TILE_RESOLUTION));
vertices[n] = Vector3(1.f, 0.f, real_t(i - TILE_RESOLUTION));
aabb.expand_to(vertices[n]);
n++;
}
Expand Down Expand Up @@ -322,19 +322,19 @@ Vector<RID> GeoClipMap::generate(int p_size, int p_levels) {

for (int i = 0; i < CLIPMAP_VERT_RESOLUTION; i++) {
n = CLIPMAP_VERT_RESOLUTION * 0 + i;
vertices[n] = Vector3(i, 0, 0);
vertices[n] = Vector3(i, 0.f, 0.f);
aabb.expand_to(vertices[n]);

n = CLIPMAP_VERT_RESOLUTION * 1 + i;
vertices[n] = Vector3(CLIPMAP_VERT_RESOLUTION, 0, i);
vertices[n] = Vector3(CLIPMAP_VERT_RESOLUTION, 0.f, i);
aabb.expand_to(vertices[n]);

n = CLIPMAP_VERT_RESOLUTION * 2 + i;
vertices[n] = Vector3(CLIPMAP_VERT_RESOLUTION - i, 0, CLIPMAP_VERT_RESOLUTION);
vertices[n] = Vector3(CLIPMAP_VERT_RESOLUTION - i, 0.f, CLIPMAP_VERT_RESOLUTION);
aabb.expand_to(vertices[n]);

n = CLIPMAP_VERT_RESOLUTION * 3 + i;
vertices[n] = Vector3(0, 0, CLIPMAP_VERT_RESOLUTION - i);
vertices[n] = Vector3(0.f, 0.f, CLIPMAP_VERT_RESOLUTION - i);
aabb.expand_to(vertices[n]);
}

Expand Down
38 changes: 19 additions & 19 deletions src/terrain_3d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -370,23 +370,23 @@ void Terrain3D::_update_collision() {
map_data.resize(shape_size * shape_size);

Vector2i global_offset = Vector2i(_storage->get_region_offsets()[i]) * region_size;
Vector3 global_pos = Vector3(global_offset.x, 0, global_offset.y);
Vector3 global_pos = Vector3(global_offset.x, 0.f, global_offset.y);

Ref<Image> map, map_x, map_z, map_xz;
Ref<Image> cmap, cmap_x, cmap_z, cmap_xz;
map = _storage->get_map_region(Terrain3DStorage::TYPE_HEIGHT, i);
cmap = _storage->get_map_region(Terrain3DStorage::TYPE_CONTROL, i);
int region = _storage->get_region_index(Vector3(global_pos.x + region_size, 0, global_pos.z));
int region = _storage->get_region_index(Vector3(global_pos.x + region_size, 0.f, global_pos.z));
if (region >= 0) {
map_x = _storage->get_map_region(Terrain3DStorage::TYPE_HEIGHT, region);
cmap_x = _storage->get_map_region(Terrain3DStorage::TYPE_CONTROL, region);
}
region = _storage->get_region_index(Vector3(global_pos.x, 0, global_pos.z + region_size));
region = _storage->get_region_index(Vector3(global_pos.x, 0.f, global_pos.z + region_size));
if (region >= 0) {
map_z = _storage->get_map_region(Terrain3DStorage::TYPE_HEIGHT, region);
cmap_z = _storage->get_map_region(Terrain3DStorage::TYPE_CONTROL, region);
}
region = _storage->get_region_index(Vector3(global_pos.x + region_size, 0, global_pos.z + region_size));
region = _storage->get_region_index(Vector3(global_pos.x + region_size, 0.f, global_pos.z + region_size));
if (region >= 0) {
map_xz = _storage->get_map_region(Terrain3DStorage::TYPE_HEIGHT, region);
cmap_xz = _storage->get_map_region(Terrain3DStorage::TYPE_CONTROL, region);
Expand Down Expand Up @@ -429,9 +429,9 @@ void Terrain3D::_update_collision() {
// Non rotated shape for normal array index above
//Transform3D xform = Transform3D(Basis(), global_pos);
// Rotated shape Y=90 for -90 rotated array index
Transform3D xform = Transform3D(Basis(Vector3(0, 1.0, 0), Math_PI * .5),
global_pos + Vector3(region_size, 0, region_size) * .5);
xform.scale(Vector3(_mesh_vertex_spacing, 1, _mesh_vertex_spacing));
Transform3D xform = Transform3D(Basis(Vector3(0.f, 1.f, 0.f), Math_PI * .5f),
global_pos + Vector3(region_size, 0.f, region_size) * .5f);
xform.scale(Vector3(_mesh_vertex_spacing, 1.f, _mesh_vertex_spacing));

if (!_show_debug_collision) {
RID shape = PhysicsServer3D::get_singleton()->heightmap_shape_create();
Expand Down Expand Up @@ -570,7 +570,7 @@ void Terrain3D::_generate_triangles(PackedVector3Array &p_vertices, PackedVector

for (int32_t z = z_start; z < z_end; ++z) {
for (int32_t x = x_start; x < x_end; ++x) {
real_t height = _storage->get_height(Vector3(x, 0.0, z));
real_t height = _storage->get_height(Vector3(x, 0.f, z));
if (height >= p_global_aabb.position.y && height <= p_global_aabb.get_end().y) {
_generate_triangle_pair(p_vertices, p_uvs, p_lod, p_filter, p_require_nav, x, z);
}
Expand Down Expand Up @@ -816,7 +816,7 @@ void Terrain3D::snap(Vector3 p_cam_pos) {
real_t scale = real_t(1 << l) * _mesh_vertex_spacing;
Vector3 snapped_pos = (p_cam_pos / scale).floor() * scale;
Vector3 tile_size = Vector3(real_t(_mesh_size << l), 0, real_t(_mesh_size << l)) * _mesh_vertex_spacing;
Vector3 base = snapped_pos - Vector3(real_t(_mesh_size << (l + 1)), 0, real_t(_mesh_size << (l + 1))) * _mesh_vertex_spacing;
Vector3 base = snapped_pos - Vector3(real_t(_mesh_size << (l + 1)), 0.f, real_t(_mesh_size << (l + 1))) * _mesh_vertex_spacing;

// Position tiles
for (int x = 0; x < 4; x++) {
Expand All @@ -825,11 +825,11 @@ void Terrain3D::snap(Vector3 p_cam_pos) {
continue;
}

Vector3 fill = Vector3(x >= 2 ? 1 : 0, 0, y >= 2 ? 1 : 0) * scale;
Vector3 tile_tl = base + Vector3(x, 0, y) * tile_size + fill;
Vector3 fill = Vector3(x >= 2 ? 1.f : 0.f, 0.f, y >= 2 ? 1.f : 0.f) * scale;
Vector3 tile_tl = base + Vector3(x, 0.f, y) * tile_size + fill;
//Vector3 tile_br = tile_tl + tile_size;

Transform3D t = Transform3D().scaled(Vector3(scale, 1, scale));
Transform3D t = Transform3D().scaled(Vector3(scale, 1.f, scale));
t.origin = tile_tl;

RS->instance_set_transform(_data.tiles[tile], t);
Expand All @@ -838,7 +838,7 @@ void Terrain3D::snap(Vector3 p_cam_pos) {
}
}
{
Transform3D t = Transform3D().scaled(Vector3(scale, 1, scale));
Transform3D t = Transform3D().scaled(Vector3(scale, 1.f, scale));
t.origin = snapped_pos;
RS->instance_set_transform(_data.fillers[l], t);
}
Expand All @@ -849,26 +849,26 @@ void Terrain3D::snap(Vector3 p_cam_pos) {

// Position trims
{
Vector3 tile_center = snapped_pos + (Vector3(scale, 0, scale) * 0.5f);
Vector3 tile_center = snapped_pos + (Vector3(scale, 0.f, scale) * 0.5f);
Vector3 d = p_cam_pos - next_snapped_pos;

int r = 0;
r |= d.x >= scale ? 0 : 2;
r |= d.z >= scale ? 0 : 1;

real_t rotations[4] = { 0.0, 270.0, 90, 180.0 };
real_t rotations[4] = { 0.f, 270.f, 90.f, 180.f };

real_t angle = UtilityFunctions::deg_to_rad(rotations[r]);
Transform3D t = Transform3D().rotated(Vector3(0, 1, 0), -angle);
t = t.scaled(Vector3(scale, 1, scale));
Transform3D t = Transform3D().rotated(Vector3(0.f, 1.f, 0.f), -angle);
t = t.scaled(Vector3(scale, 1.f, scale));
t.origin = tile_center;
RS->instance_set_transform(_data.trims[edge], t);
}

// Position seams
{
Vector3 next_base = next_snapped_pos - Vector3(real_t(_mesh_size << (l + 1)), 0, real_t(_mesh_size << (l + 1))) * _mesh_vertex_spacing;
Transform3D t = Transform3D().scaled(Vector3(scale, 1, scale));
Vector3 next_base = next_snapped_pos - Vector3(real_t(_mesh_size << (l + 1)), 0.f, real_t(_mesh_size << (l + 1))) * _mesh_vertex_spacing;
Transform3D t = Transform3D().scaled(Vector3(scale, 1.f, scale));
t.origin = next_base;
RS->instance_set_transform(_data.seams[edge], t);
}
Expand Down
4 changes: 2 additions & 2 deletions src/terrain_3d.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class Terrain3D : public Node3D {
// Renderer settings
uint32_t _render_layers = 1 | (1 << 31); // Bit 1 and 32 for the cursor
GeometryInstance3D::ShadowCastingSetting _shadow_casting = GeometryInstance3D::SHADOW_CASTING_SETTING_ON;
real_t _cull_margin = 0.0;
real_t _cull_margin = 0.0f;

// Mouse cursor
SubViewport *_mouse_vp = nullptr;
Expand All @@ -78,7 +78,7 @@ class Terrain3D : public Node3D {
bool _show_debug_collision = false;
uint32_t _collision_layer = 1;
uint32_t _collision_mask = 1;
real_t _collision_priority = 1.0;
real_t _collision_priority = 1.0f;

void _initialize();
void __ready();
Expand Down
Loading

0 comments on commit efcb0f2

Please sign in to comment.