mirror of
https://github.com/SFML/SFML.git
synced 2024-11-24 20:31:05 +08:00
x
This commit is contained in:
parent
bb0f88594f
commit
1d2ffdb07f
@ -2,16 +2,110 @@
|
|||||||
"version": 3,
|
"version": 3,
|
||||||
"configurePresets": [
|
"configurePresets": [
|
||||||
{
|
{
|
||||||
"name": "dev",
|
"name": "build_base",
|
||||||
"binaryDir": "build",
|
"hidden": true,
|
||||||
"installDir": "${sourceDir}/build/install",
|
"generator": "Ninja",
|
||||||
"cacheVariables": {
|
"cacheVariables": {
|
||||||
|
"CMAKE_COLOR_DIAGNOSTICS": "ON",
|
||||||
|
"CMAKE_CXX_COMPILER_LAUNCHER": "ccache",
|
||||||
"CMAKE_CXX_EXTENSIONS": "OFF",
|
"CMAKE_CXX_EXTENSIONS": "OFF",
|
||||||
"CMAKE_EXPORT_COMPILE_COMMANDS": "ON",
|
"CMAKE_EXPORT_COMPILE_COMMANDS": "ON",
|
||||||
"SFML_BUILD_EXAMPLES": "ON",
|
"SFML_BUILD_EXAMPLES": "ON",
|
||||||
"SFML_BUILD_TEST_SUITE": "ON",
|
"SFML_BUILD_TEST_SUITE": "ON",
|
||||||
"SFML_ENABLE_STDLIB_ASSERTIONS": "ON",
|
"SFML_ENABLE_PCH": "OFF",
|
||||||
"SFML_WARNINGS_AS_ERRORS": "ON"
|
"SFML_WARNINGS_AS_ERRORS": "OFF"
|
||||||
|
},
|
||||||
|
"environment": {
|
||||||
|
"CXX_WARNINGS": "-Wall -Wextra -Wpedantic -Wno-ignored-attributes -Wno-unused-command-line-argument"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "build_base_debug",
|
||||||
|
"hidden": true,
|
||||||
|
"inherits": "build_base",
|
||||||
|
"cacheVariables": {
|
||||||
|
"CMAKE_BUILD_TYPE": "DEBUG",
|
||||||
|
"SFML_ENABLE_LIFETIME_TRACKING": "ON",
|
||||||
|
"SFML_ENABLE_STACK_TRACES": "ON",
|
||||||
|
"SFML_ENABLE_STDLIB_ASSERTIONS": "ON"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "build_base_release",
|
||||||
|
"hidden": true,
|
||||||
|
"inherits": "build_base",
|
||||||
|
"cacheVariables": {
|
||||||
|
"CMAKE_BUILD_TYPE": "RELEASE",
|
||||||
|
"SFML_ENABLE_LIFETIME_TRACKING": "OFF",
|
||||||
|
"SFML_ENABLE_STACK_TRACES": "OFF",
|
||||||
|
"SFML_ENABLE_STDLIB_ASSERTIONS": "OFF"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "vrdev_clang",
|
||||||
|
"inherits": "build_base_debug",
|
||||||
|
"binaryDir": "build_vrdev_clang",
|
||||||
|
"installDir": "${sourceDir}/build_vrdev_clang/install",
|
||||||
|
"cacheVariables": {
|
||||||
|
"CMAKE_CXX_COMPILER": "clang++",
|
||||||
|
"CMAKE_CXX_FLAGS": "-fuse-ld=lld -ftime-trace $env{CXX_WARNINGS}"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "vrdev_gcc",
|
||||||
|
"inherits": "build_base_debug",
|
||||||
|
"binaryDir": "build_vrdev_gcc",
|
||||||
|
"installDir": "${sourceDir}/build_vrdev_gcc/install",
|
||||||
|
"cacheVariables": {
|
||||||
|
"CMAKE_CXX_COMPILER": "g++",
|
||||||
|
"CMAKE_CXX_FLAGS": "-fuse-ld=lld -Wnrvo $env{CXX_WARNINGS}"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "vrdev_emcc",
|
||||||
|
"inherits": "build_base_debug",
|
||||||
|
"binaryDir": "build_vrdev_emcc",
|
||||||
|
"installDir": "${sourceDir}/build_vrdev_emcc/install",
|
||||||
|
"cacheVariables": {
|
||||||
|
"CMAKE_CROSSCOMPILING_EMULATOR": "C:/msys64/clang64/bin/node.exe",
|
||||||
|
"CMAKE_CXX_COMPILER_LAUNCHER": "",
|
||||||
|
"CMAKE_CXX_FLAGS": "$env{CXX_WARNINGS}",
|
||||||
|
"CMAKE_TOOLCHAIN_FILE": "C:/msys64/clang64/lib/emscripten/cmake/Modules/Platform/Emscripten.cmake",
|
||||||
|
"SFML_ENABLE_STACK_TRACES": "OFF",
|
||||||
|
"SFML_OPENGL_ES": "ON"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "vrdev_gcc_rel",
|
||||||
|
"inherits": "build_base_release",
|
||||||
|
"binaryDir": "build_vrdev_gcc_rel",
|
||||||
|
"installDir": "${sourceDir}/build_vrdev_gcc_rel/install",
|
||||||
|
"cacheVariables": {
|
||||||
|
"CMAKE_CXX_COMPILER": "g++",
|
||||||
|
"CMAKE_CXX_FLAGS": "-fuse-ld=lld -Wnrvo -Ofast $env{CXX_WARNINGS}"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "vrdev_clang_rel",
|
||||||
|
"inherits": "build_base_release",
|
||||||
|
"binaryDir": "build_vrdev_clang_rel",
|
||||||
|
"installDir": "${sourceDir}/build_vrdev_clang_rel/install",
|
||||||
|
"cacheVariables": {
|
||||||
|
"CMAKE_CXX_COMPILER": "clang++",
|
||||||
|
"CMAKE_CXX_FLAGS": "-fuse-ld=lld -ftime-trace -Ofast $env{CXX_WARNINGS}"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "vrdev_emcc_rel",
|
||||||
|
"inherits": "build_base_release",
|
||||||
|
"binaryDir": "build_vrdev_emcc_rel",
|
||||||
|
"installDir": "${sourceDir}/build_vrdev_emcc_rel/install",
|
||||||
|
"cacheVariables": {
|
||||||
|
"CMAKE_CROSSCOMPILING_EMULATOR": "C:/msys64/clang64/bin/node.exe",
|
||||||
|
"CMAKE_CXX_COMPILER_LAUNCHER": "",
|
||||||
|
"CMAKE_CXX_FLAGS": "-Ofast $env{CXX_WARNINGS}",
|
||||||
|
"CMAKE_TOOLCHAIN_FILE": "C:/msys64/clang64/lib/emscripten/cmake/Modules/Platform/Emscripten.cmake",
|
||||||
|
"SFML_OPENGL_ES": "ON"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
#include "SFML/Graphics/CircleShape.hpp"
|
||||||
#include "SFML/Graphics/Font.hpp"
|
#include "SFML/Graphics/Font.hpp"
|
||||||
#include "SFML/Graphics/Image.hpp"
|
#include "SFML/Graphics/Image.hpp"
|
||||||
#include "SFML/Graphics/RenderStates.hpp"
|
#include "SFML/Graphics/RenderStates.hpp"
|
||||||
@ -14,19 +15,34 @@
|
|||||||
#include <random>
|
#include <random>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
#include <cstddef>
|
#include <cstddef>
|
||||||
|
|
||||||
|
std::mt19937 rng(std::random_device{}());
|
||||||
|
|
||||||
float getRndFloat(float min, float max)
|
float getRndFloat(float min, float max)
|
||||||
{
|
{
|
||||||
static std::mt19937 rng(std::random_device{}());
|
|
||||||
return std::uniform_real_distribution<float>{min, max}(rng);
|
return std::uniform_real_distribution<float>{min, max}(rng);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
unsigned int getRndUInt(unsigned int min, unsigned int max)
|
||||||
|
{
|
||||||
|
return std::uniform_int_distribution<unsigned int>{min, max}(rng);
|
||||||
|
}
|
||||||
|
|
||||||
|
unsigned char getRndU8(unsigned char min, unsigned char max)
|
||||||
|
{
|
||||||
|
return static_cast<unsigned char>(getRndUInt(min, max));
|
||||||
|
}
|
||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
|
|
||||||
|
std::cout << sizeof(sf::Transform) << '\n';
|
||||||
|
std::cout << sizeof(sf::Transformable) << '\n';
|
||||||
|
std::cout << sizeof(sf::Sprite) << '\n';
|
||||||
|
|
||||||
//
|
//
|
||||||
//
|
//
|
||||||
// Set up window
|
// Set up window
|
||||||
@ -73,6 +89,7 @@ int main()
|
|||||||
sf::Sprite sprite;
|
sf::Sprite sprite;
|
||||||
sf::Vector2f velocity;
|
sf::Vector2f velocity;
|
||||||
float torque{};
|
float torque{};
|
||||||
|
sf::CircleShape circleShape;
|
||||||
};
|
};
|
||||||
|
|
||||||
std::vector<Entity> entities;
|
std::vector<Entity> entities;
|
||||||
@ -95,12 +112,20 @@ int main()
|
|||||||
|
|
||||||
const auto label = std::string{names[i % 6u]} + " #" + std::to_string((i / (type + 1)) + 1);
|
const auto label = std::string{names[i % 6u]} + " #" + std::to_string((i / (type + 1)) + 1);
|
||||||
|
|
||||||
|
sf::CircleShape circleShape(getRndFloat(3.f, 8.f), static_cast<std::size_t>(getRndFloat(3.f, 8.f)));
|
||||||
|
circleShape.setFillColor(
|
||||||
|
{getRndU8(0.f, 255.f), getRndU8(0.f, 255.f), getRndU8(0.f, 255.f), getRndU8(125.f, 255.f)});
|
||||||
|
circleShape.setOutlineColor(
|
||||||
|
{getRndU8(0.f, 255.f), getRndU8(0.f, 255.f), getRndU8(0.f, 255.f), getRndU8(125.f, 255.f)});
|
||||||
|
circleShape.setOutlineThickness(3.f);
|
||||||
|
|
||||||
entities.push_back({sf::Text{i % 2u == 0u ? fontTuffy : fontMouldyCheese, label},
|
entities.push_back({sf::Text{i % 2u == 0u ? fontTuffy : fontMouldyCheese, label},
|
||||||
sf::Sprite{texture},
|
sf::Sprite{texture},
|
||||||
sf::Vector2f{getRndFloat(-2.5f, 2.5f), getRndFloat(-2.5f, 2.5f)},
|
sf::Vector2f{getRndFloat(-2.5f, 2.5f), getRndFloat(-2.5f, 2.5f)},
|
||||||
getRndFloat(-0.05f, 0.05f)});
|
getRndFloat(-0.05f, 0.05f),
|
||||||
|
circleShape});
|
||||||
|
|
||||||
auto& [text, sprite, velocity, torque] = entities.back();
|
auto& [text, sprite, velocity, torque, cs] = entities.back();
|
||||||
|
|
||||||
sprite.setOrigin(sf::Vector2f(texture.getSize()) / 2.f);
|
sprite.setOrigin(sf::Vector2f(texture.getSize()) / 2.f);
|
||||||
sprite.setRotation(sf::degrees(getRndFloat(0.f, 360.f)));
|
sprite.setRotation(sf::degrees(getRndFloat(0.f, 360.f)));
|
||||||
@ -115,16 +140,18 @@ int main()
|
|||||||
text.setOutlineColor(sf::Color::White);
|
text.setOutlineColor(sf::Color::White);
|
||||||
text.setOutlineThickness(5.f);
|
text.setOutlineThickness(5.f);
|
||||||
|
|
||||||
text.setOrigin(text.getLocalBounds().size / 2.f);
|
text.setOrigin(text.getLocalBounds().getCenter());
|
||||||
|
circleShape.setOrigin(circleShape.getLocalBounds().getCenter());
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
//
|
//
|
||||||
//
|
//
|
||||||
// Set up UI elements
|
// Set up UI elements
|
||||||
bool drawSprites = true;
|
bool drawSprites = false;
|
||||||
bool drawText = true;
|
bool drawText = false;
|
||||||
int numEntities = 10000;
|
bool drawShapes = true;
|
||||||
|
int numEntities = 20000;
|
||||||
|
|
||||||
//
|
//
|
||||||
//
|
//
|
||||||
@ -186,7 +213,7 @@ int main()
|
|||||||
{
|
{
|
||||||
clock.restart();
|
clock.restart();
|
||||||
|
|
||||||
for (auto& [text, sprite, velocity, torque] : entities)
|
for (auto& [text, sprite, velocity, torque, circleShape] : entities)
|
||||||
{
|
{
|
||||||
sprite.move(velocity);
|
sprite.move(velocity);
|
||||||
sprite.rotate(sf::radians(torque));
|
sprite.rotate(sf::radians(torque));
|
||||||
@ -200,6 +227,9 @@ int main()
|
|||||||
velocity.y = -velocity.y;
|
velocity.y = -velocity.y;
|
||||||
|
|
||||||
text.setPosition(sprite.getPosition() - sf::Vector2f{0.f, 250.f * sprite.getScale().x});
|
text.setPosition(sprite.getPosition() - sf::Vector2f{0.f, 250.f * sprite.getScale().x});
|
||||||
|
|
||||||
|
circleShape.setPosition(sprite.getPosition());
|
||||||
|
circleShape.setRotation(sprite.getRotation());
|
||||||
}
|
}
|
||||||
|
|
||||||
recordUs(samplesUpdateMs, clock.getElapsedTime().asSeconds() * 1000.f);
|
recordUs(samplesUpdateMs, clock.getElapsedTime().asSeconds() * 1000.f);
|
||||||
@ -219,6 +249,9 @@ int main()
|
|||||||
|
|
||||||
if (drawText)
|
if (drawText)
|
||||||
window.draw(entity.text);
|
window.draw(entity.text);
|
||||||
|
|
||||||
|
if (drawShapes)
|
||||||
|
window.draw(entity.circleShape);
|
||||||
}
|
}
|
||||||
|
|
||||||
recordUs(samplesDrawMs, clock.getElapsedTime().asSeconds() * 1000.f);
|
recordUs(samplesDrawMs, clock.getElapsedTime().asSeconds() * 1000.f);
|
||||||
|
Loading…
Reference in New Issue
Block a user