diff --git a/examples/island/Island.cpp b/examples/island/Island.cpp index 8d1bd3ea24..ee508b890f 100644 --- a/examples/island/Island.cpp +++ b/examples/island/Island.cpp @@ -273,10 +273,10 @@ float getElevation(float x, float y) for (int i = 0; i < perlinOctaves; i++) { elevation += stb_perlin_noise3( - x * perlinFrequency * std::pow(perlinFrequencyBase, i), - y * perlinFrequency * std::pow(perlinFrequencyBase, i), + x * perlinFrequency * static_cast(std::pow(perlinFrequencyBase, i)), + y * perlinFrequency * static_cast(std::pow(perlinFrequencyBase, i)), 0, 0, 0, 0 - ) * std::pow(perlinFrequencyBase, -i); + ) * static_cast(std::pow(perlinFrequencyBase, -i)); } elevation = (elevation + 1.f) / 2.f; @@ -288,6 +288,11 @@ float getElevation(float x, float y) return elevation; } +float getElevation(unsigned int x, unsigned int y) +{ + return getElevation(static_cast(x), static_cast(y)); +} + //////////////////////////////////////////////////////////// /// Get the terrain moisture at the given coordinates. @@ -307,6 +312,11 @@ float getMoisture(float x, float y) return (moisture + 1.f) / 2.f; } +float getMoisture(unsigned int x, unsigned int y) +{ + return getMoisture(static_cast(x), static_cast(y)); +} + //////////////////////////////////////////////////////////// /// Get the lowlands terrain color for the given moisture. @@ -316,11 +326,11 @@ sf::Color getLowlandsTerrainColor(float moisture) { sf::Color color = moisture < 0.27f ? sf::Color(240, 240, 180) : - moisture < 0.3f ? sf::Color(240 - 240 * (moisture - 0.27f) / 0.03f, 240 - 40 * (moisture - 0.27f) / 0.03f, 180 - 180 * (moisture - 0.27f) / 0.03f) : + moisture < 0.3f ? sf::Color(240 - static_cast(240 * (moisture - 0.27f) / 0.03f), 240 - static_cast(40 * (moisture - 0.27f) / 0.03f), 180 - static_cast(180 * (moisture - 0.27f) / 0.03f)) : moisture < 0.4f ? sf::Color(0, 200, 0) : - moisture < 0.48f ? sf::Color(0, 200 - 40 * (moisture - 0.4f) / 0.08f, 0) : + moisture < 0.48f ? sf::Color(0, 200 - static_cast(40 * (moisture - 0.4f) / 0.08f), 0) : moisture < 0.6f ? sf::Color(0, 160, 0) : - moisture < 0.7f ? sf::Color(34 * (moisture - 0.6f) / 0.1f, 160 - 60 * (moisture - 0.6f) / 0.1f, 34 * (moisture - 0.6f) / 0.1f) : + moisture < 0.7f ? sf::Color(static_cast(34 * (moisture - 0.6f) / 0.1f), 160 - static_cast(60 * (moisture - 0.6f) / 0.1f), static_cast(34 * (moisture - 0.6f) / 0.1f)) : sf::Color(34, 100, 34); return color; @@ -338,13 +348,13 @@ sf::Color getHighlandsTerrainColor(float elevation, float moisture) sf::Color color = moisture < 0.6f ? sf::Color(112, 128, 144) : - sf::Color(112 + 110 * (moisture - 0.6f) / 0.4f, 128 + 56 * (moisture - 0.6f) / 0.4f, 144 - 9 * (moisture - 0.6f) / 0.4f); + sf::Color(112 + static_cast(110 * (moisture - 0.6f) / 0.4f), 128 + static_cast(56 * (moisture - 0.6f) / 0.4f), 144 - static_cast(9 * (moisture - 0.6f) / 0.4f)); float factor = std::min((elevation - 0.4f) / 0.1f, 1.f); - color.r = lowlandsColor.r * (1.f - factor) + color.r * factor; - color.g = lowlandsColor.g * (1.f - factor) + color.g * factor; - color.b = lowlandsColor.b * (1.f - factor) + color.b * factor; + color.r = static_cast(lowlandsColor.r * (1.f - factor) + color.r * factor); + color.g = static_cast(lowlandsColor.g * (1.f - factor) + color.g * factor); + color.b = static_cast(lowlandsColor.b * (1.f - factor) + color.b * factor); return color; } @@ -363,9 +373,9 @@ sf::Color getSnowcapTerrainColor(float elevation, float moisture) float factor = std::min((elevation - snowcapHeight) / 0.05f, 1.f); - color.r = highlandsColor.r * (1.f - factor) + color.r * factor; - color.g = highlandsColor.g * (1.f - factor) + color.g * factor; - color.b = highlandsColor.b * (1.f - factor) + color.b * factor; + color.r = static_cast(highlandsColor.r * (1.f - factor) + color.r * factor); + color.g = static_cast(highlandsColor.g * (1.f - factor) + color.g * factor); + color.b = static_cast(highlandsColor.b * (1.f - factor) + color.b * factor); return color; } @@ -379,9 +389,9 @@ sf::Color getSnowcapTerrainColor(float elevation, float moisture) sf::Color getTerrainColor(float elevation, float moisture) { sf::Color color = - elevation < 0.11f ? sf::Color(0, 0, elevation / 0.11f * 74.f + 181.0f) : - elevation < 0.14f ? sf::Color(std::pow((elevation - 0.11f) / 0.03f, 0.3f) * 48.f, std::pow((elevation - 0.11f) / 0.03f, 0.3f) * 48.f, 255) : - elevation < 0.16f ? sf::Color((elevation - 0.14f) * 128.f / 0.02f + 48.f, (elevation - 0.14f) * 128.f / 0.02f + 48.f, 127.0f + (0.16f - elevation) * 128.f / 0.02f) : + elevation < 0.11f ? sf::Color(0, 0, static_cast(elevation / 0.11f * 74.f + 181.0f)) : + elevation < 0.14f ? sf::Color(static_cast(std::pow((elevation - 0.11f) / 0.03f, 0.3f) * 48.f), static_cast(std::pow((elevation - 0.11f) / 0.03f, 0.3f) * 48.f), 255) : + elevation < 0.16f ? sf::Color(static_cast((elevation - 0.14f) * 128.f / 0.02f + 48.f), static_cast((elevation - 0.14f) * 128.f / 0.02f + 48.f), static_cast(127.0f + (0.16f - elevation) * 128.f / 0.02f)) : elevation < 0.17f ? sf::Color(240, 230, 140) : elevation < 0.4f ? getLowlandsTerrainColor(moisture) : elevation < snowcapHeight ? getHighlandsTerrainColor(elevation, moisture) : @@ -397,7 +407,7 @@ sf::Color getTerrainColor(float elevation, float moisture) /// of the 4 adjacent neighbours. /// //////////////////////////////////////////////////////////// -sf::Vector2f computeNormal(int x, int y, float left, float right, float bottom, float top) +sf::Vector2f computeNormal(float left, float right, float bottom, float top) { sf::Vector3f deltaX(1, 0, (std::pow(right, heightFlatten) - std::pow(left, heightFlatten)) * heightFactor); sf::Vector3f deltaY(0, 1, (std::pow(top, heightFlatten) - std::pow(bottom, heightFlatten)) * heightFactor); @@ -455,7 +465,7 @@ void processWorkItem(std::vector& vertices, const WorkItem& workItem { vertices[arrayIndexBase + 0].position = sf::Vector2f(x * scalingFactorX, y * scalingFactorY); vertices[arrayIndexBase + 0].color = getTerrainColor(getElevation(x, y), getMoisture(x, y)); - vertices[arrayIndexBase + 0].texCoords = computeNormal(x, y, getElevation(x - 1, y), getElevation(x + 1, y), getElevation(x, y + 1), getElevation(x, y - 1)); + vertices[arrayIndexBase + 0].texCoords = computeNormal(getElevation(x - 1, y), getElevation(x + 1, y), getElevation(x, y + 1), getElevation(x, y - 1)); } // Bottom left corner (first triangle) @@ -467,13 +477,13 @@ void processWorkItem(std::vector& vertices, const WorkItem& workItem { vertices[arrayIndexBase + 1].position = sf::Vector2f(x * scalingFactorX, (y + 1) * scalingFactorY); vertices[arrayIndexBase + 1].color = getTerrainColor(getElevation(x, y + 1), getMoisture(x, y + 1)); - vertices[arrayIndexBase + 1].texCoords = computeNormal(x, y + 1, getElevation(x - 1, y + 1), getElevation(x + 1, y + 1), getElevation(x, y + 2), getElevation(x, y)); + vertices[arrayIndexBase + 1].texCoords = computeNormal(getElevation(x - 1, y + 1), getElevation(x + 1, y + 1), getElevation(x, y + 2), getElevation(x, y)); } // Bottom right corner (first triangle) vertices[arrayIndexBase + 2].position = sf::Vector2f((x + 1) * scalingFactorX, (y + 1) * scalingFactorY); vertices[arrayIndexBase + 2].color = getTerrainColor(getElevation(x + 1, y + 1), getMoisture(x + 1, y + 1)); - vertices[arrayIndexBase + 2].texCoords = computeNormal(x + 1, y + 1, getElevation(x, y + 1), getElevation(x + 2, y + 1), getElevation(x + 1, y + 2), getElevation(x + 1, y)); + vertices[arrayIndexBase + 2].texCoords = computeNormal(getElevation(x, y + 1), getElevation(x + 2, y + 1), getElevation(x + 1, y + 2), getElevation(x + 1, y)); // Top left corner (second triangle) vertices[arrayIndexBase + 3] = vertices[arrayIndexBase + 0]; @@ -490,7 +500,7 @@ void processWorkItem(std::vector& vertices, const WorkItem& workItem { vertices[arrayIndexBase + 5].position = sf::Vector2f((x + 1) * scalingFactorX, y * scalingFactorY); vertices[arrayIndexBase + 5].color = getTerrainColor(getElevation(x + 1, y), getMoisture(x + 1, y)); - vertices[arrayIndexBase + 5].texCoords = computeNormal(x + 1, y, getElevation(x, y), getElevation(x + 2, y), getElevation(x + 1, y + 1), getElevation(x + 1, y - 1)); + vertices[arrayIndexBase + 5].texCoords = computeNormal(getElevation(x, y), getElevation(x + 2, y), getElevation(x + 1, y + 1), getElevation(x + 1, y - 1)); } } } diff --git a/examples/opengl/OpenGL.cpp b/examples/opengl/OpenGL.cpp index 30a843f8ac..610bc94200 100644 --- a/examples/opengl/OpenGL.cpp +++ b/examples/opengl/OpenGL.cpp @@ -240,18 +240,18 @@ int main() glViewport(0, 0, event.size.width, event.size.height); glMatrixMode(GL_PROJECTION); glLoadIdentity(); - GLfloat ratio = static_cast(event.size.width) / event.size.height; + GLfloat newRatio = static_cast(event.size.width) / event.size.height; #ifdef SFML_OPENGL_ES - glFrustumf(-ratio, ratio, -1.f, 1.f, 1.f, 500.f); + glFrustumf(-newRatio, newRatio, -1.f, 1.f, 1.f, 500.f); #else - glFrustum(-ratio, ratio, -1.f, 1.f, 1.f, 500.f); + glFrustum(-newRatio, newRatio, -1.f, 1.f, 1.f, 500.f); #endif // Make the window no longer the active window for OpenGL calls window.setActive(false); sf::View view; - view.setSize(textureSize.x, textureSize.y); + view.setSize(sf::Vector2f(textureSize)); view.setCenter(textureSize.x/2.f, textureSize.y/2.f); window.setView(view); } diff --git a/examples/shader/Shader.cpp b/examples/shader/Shader.cpp index ed75416ad4..31257fe743 100644 --- a/examples/shader/Shader.cpp +++ b/examples/shader/Shader.cpp @@ -301,7 +301,7 @@ class Geometry : public Effect return true; } - void onUpdate(float time, float x, float y) + void onUpdate(float /*time*/, float x, float y) { // Reset our transformation matrix m_transform = sf::Transform::Identity; diff --git a/examples/vulkan/Vulkan.cpp b/examples/vulkan/Vulkan.cpp index 01c58edd65..45313dd87c 100644 --- a/examples/vulkan/Vulkan.cpp +++ b/examples/vulkan/Vulkan.cpp @@ -341,7 +341,7 @@ class VulkanExample vkWaitForFences(device, 1, &fences[i], VK_TRUE, std::numeric_limits::max()); if (commandBuffers.size()) - vkFreeCommandBuffers(device, commandPool, commandBuffers.size(), &commandBuffers[0]); + vkFreeCommandBuffers(device, commandPool, static_cast(commandBuffers.size()), &commandBuffers[0]); commandBuffers.clear(); @@ -472,9 +472,9 @@ class VulkanExample VkInstanceCreateInfo instanceCreateInfo = VkInstanceCreateInfo(); instanceCreateInfo.sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO; instanceCreateInfo.pApplicationInfo = &applicationInfo; - instanceCreateInfo.enabledLayerCount = validationLayers.size(); + instanceCreateInfo.enabledLayerCount = static_cast(validationLayers.size()); instanceCreateInfo.ppEnabledLayerNames = &validationLayers[0]; - instanceCreateInfo.enabledExtensionCount = requiredExtentions.size(); + instanceCreateInfo.enabledExtensionCount = static_cast(requiredExtentions.size()); instanceCreateInfo.ppEnabledExtensionNames = &requiredExtentions[0]; // Try to create a Vulkan instance with debug report enabled @@ -485,7 +485,7 @@ class VulkanExample { requiredExtentions.pop_back(); - instanceCreateInfo.enabledExtensionCount = requiredExtentions.size(); + instanceCreateInfo.enabledExtensionCount = static_cast(requiredExtentions.size()); instanceCreateInfo.ppEnabledExtensionNames = &requiredExtentions[0]; result = vkCreateInstance(&instanceCreateInfo, 0, &instance); @@ -665,11 +665,11 @@ class VulkanExample { VkBool32 surfaceSupported = VK_FALSE; - vkGetPhysicalDeviceSurfaceSupportKHR(gpu, i, surface, &surfaceSupported); + vkGetPhysicalDeviceSurfaceSupportKHR(gpu, static_cast(i), surface, &surfaceSupported); if ((queueFamilyProperties[i].queueFlags & VK_QUEUE_GRAPHICS_BIT) && (surfaceSupported == VK_TRUE)) { - queueFamilyIndex = i; + queueFamilyIndex = static_cast(i); break; } } diff --git a/examples/window/Window.cpp b/examples/window/Window.cpp index db7b068753..42568dd9bd 100644 --- a/examples/window/Window.cpp +++ b/examples/window/Window.cpp @@ -145,11 +145,11 @@ int main() glViewport(0, 0, event.size.width, event.size.height); glMatrixMode(GL_PROJECTION); glLoadIdentity(); - GLfloat ratio = static_cast(event.size.width) / event.size.height; + GLfloat newRatio = static_cast(event.size.width) / event.size.height; #ifdef SFML_OPENGL_ES - glFrustumf(-ratio, ratio, -1.f, 1.f, 1.f, 500.f); + glFrustumf(-newRatio, newRatio, -1.f, 1.f, 1.f, 500.f); #else - glFrustum(-ratio, ratio, -1.f, 1.f, 1.f, 500.f); + glFrustum(-newRatio, newRatio, -1.f, 1.f, 1.f, 500.f); #endif } }