├── .editorconfig
├── .gitignore
├── README.md
├── SAT
├── include
│ ├── Application.hpp
│ ├── Collider.hpp
│ ├── Collision.hpp
│ └── Utilities.hpp
├── main.cpp
├── pch
│ ├── stpch.cpp
│ └── stpch.h
├── premake5.lua
└── src
│ ├── Application.cpp
│ ├── Collider.cpp
│ └── Collision.cpp
├── build.bat
├── images
└── preview.png
├── include
└── SFML
│ ├── Audio.hpp
│ ├── Audio
│ ├── AlResource.hpp
│ ├── Export.hpp
│ ├── InputSoundFile.hpp
│ ├── Listener.hpp
│ ├── Music.hpp
│ ├── OutputSoundFile.hpp
│ ├── Sound.hpp
│ ├── SoundBuffer.hpp
│ ├── SoundBufferRecorder.hpp
│ ├── SoundFileFactory.hpp
│ ├── SoundFileFactory.inl
│ ├── SoundFileReader.hpp
│ ├── SoundFileWriter.hpp
│ ├── SoundRecorder.hpp
│ ├── SoundSource.hpp
│ └── SoundStream.hpp
│ ├── Config.hpp
│ ├── GpuPreference.hpp
│ ├── Graphics.hpp
│ ├── Graphics
│ ├── BlendMode.hpp
│ ├── CircleShape.hpp
│ ├── Color.hpp
│ ├── Color.inl
│ ├── ConvexShape.hpp
│ ├── Drawable.hpp
│ ├── Export.hpp
│ ├── Font.hpp
│ ├── Glsl.hpp
│ ├── Glsl.inl
│ ├── Glyph.hpp
│ ├── Image.hpp
│ ├── PrimitiveType.hpp
│ ├── Rect.hpp
│ ├── Rect.inl
│ ├── RectangleShape.hpp
│ ├── RenderStates.hpp
│ ├── RenderTarget.hpp
│ ├── RenderTexture.hpp
│ ├── RenderWindow.hpp
│ ├── Shader.hpp
│ ├── Shape.hpp
│ ├── Sprite.hpp
│ ├── Text.hpp
│ ├── Texture.hpp
│ ├── Transform.hpp
│ ├── Transform.inl
│ ├── Transformable.hpp
│ ├── Vertex.hpp
│ ├── Vertex.inl
│ ├── VertexArray.hpp
│ ├── VertexBuffer.hpp
│ └── View.hpp
│ ├── Main.hpp
│ ├── Network.hpp
│ ├── Network
│ ├── Export.hpp
│ ├── Ftp.hpp
│ ├── Http.hpp
│ ├── IpAddress.hpp
│ ├── Packet.hpp
│ ├── Socket.hpp
│ ├── SocketHandle.hpp
│ ├── SocketSelector.hpp
│ ├── TcpListener.hpp
│ ├── TcpSocket.hpp
│ └── UdpSocket.hpp
│ ├── OpenGL.hpp
│ ├── System.hpp
│ ├── System
│ ├── Angle.hpp
│ ├── Angle.inl
│ ├── Clock.hpp
│ ├── Err.hpp
│ ├── Export.hpp
│ ├── FileInputStream.hpp
│ ├── InputStream.hpp
│ ├── MemoryInputStream.hpp
│ ├── NativeActivity.hpp
│ ├── Sleep.hpp
│ ├── String.hpp
│ ├── String.inl
│ ├── SuspendAwareClock.hpp
│ ├── Time.hpp
│ ├── Time.inl
│ ├── Utf.hpp
│ ├── Utf.inl
│ ├── Vector2.hpp
│ ├── Vector2.inl
│ ├── Vector3.hpp
│ └── Vector3.inl
│ ├── Window.hpp
│ └── Window
│ ├── Clipboard.hpp
│ ├── Context.hpp
│ ├── ContextSettings.hpp
│ ├── Cursor.hpp
│ ├── Event.hpp
│ ├── Export.hpp
│ ├── GlResource.hpp
│ ├── Joystick.hpp
│ ├── Keyboard.hpp
│ ├── Mouse.hpp
│ ├── Sensor.hpp
│ ├── Touch.hpp
│ ├── VideoMode.hpp
│ ├── Vulkan.hpp
│ ├── Window.hpp
│ ├── WindowBase.hpp
│ ├── WindowHandle.hpp
│ └── WindowStyle.hpp
├── libs
├── Debug
│ ├── sfml-audio-s-d.lib
│ ├── sfml-graphics-s-d.lib
│ ├── sfml-main-d.lib
│ ├── sfml-network-s-d.lib
│ ├── sfml-system-s-d.lib
│ └── sfml-window-s-d.lib
├── PDB
│ ├── sfml-audio-s-d.pdb
│ ├── sfml-audio-s.pdb
│ ├── sfml-graphics-s-d.pdb
│ ├── sfml-graphics-s.pdb
│ ├── sfml-main-d.pdb
│ ├── sfml-main-s.pdb
│ ├── sfml-network-s-d.pdb
│ ├── sfml-network-s.pdb
│ ├── sfml-system-s-d.pdb
│ ├── sfml-system-s.pdb
│ ├── sfml-window-s-d.pdb
│ └── sfml-window-s.pdb
├── Release
│ ├── sfml-audio-s.lib
│ ├── sfml-graphics-s.lib
│ ├── sfml-main.lib
│ ├── sfml-network-s.lib
│ ├── sfml-system-s.lib
│ └── sfml-window-s.lib
└── extlibs
│ ├── flac.lib
│ ├── freetype.lib
│ ├── ogg.lib
│ ├── openal32.lib
│ ├── vorbis.lib
│ ├── vorbisenc.lib
│ └── vorbisfile.lib
├── premake5.lua
└── vendor
├── license.readme
└── premake5.exe
/.editorconfig:
--------------------------------------------------------------------------------
1 | root = true
2 |
3 | [*]
4 | indent_style = tab
5 | indent_size = 4
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # Binaries
2 | **/bin/
3 |
4 | # Visual Studio files and folder
5 | .vs/
6 | **.sln
7 | **.vcxproj
8 | **.vcxproj.filters
9 | **.vcxproj.user
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # SFML Simple SAT Collision
2 |
3 | ## Preview
4 | 
5 |
6 | # How to build?
7 |
8 | Clone repository and just run `build.bat` it will build for visual studio 2022
9 | If you want any older version run `.\vendor\premake5.exe vs2019` from main folder (works at least to vs17)
--------------------------------------------------------------------------------
/SAT/include/Application.hpp:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | #include "SFML/Graphics/RenderWindow.hpp"
4 | #include "SFML/Window/Event.hpp"
5 |
6 | #include "Collider.hpp"
7 | #include "Collision.hpp"
8 |
9 | class Application {
10 | public:
11 | Application();
12 | ~Application();
13 |
14 | void Run();
15 |
16 | static Application* Instance;
17 | static float DT;
18 |
19 | sf::RenderWindow Window;
20 | sf::Event Event;
21 |
22 | private:
23 | sf::Clock m_dtClock;
24 |
25 | std::vector m_Colliders;
26 |
27 | BoxCollider m_box;
28 |
29 | void CreateColliders();
30 | void CheckCollision();
31 | void UpdateBox();
32 |
33 | void Update();
34 | void Render();
35 |
36 | void HandleEvents();
37 |
38 | void InitWindow();
39 | };
40 |
--------------------------------------------------------------------------------
/SAT/include/Collider.hpp:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | #include "SFML/Graphics/RenderTarget.hpp"
4 | #include "SFML/Graphics/Drawable.hpp"
5 | #include "SFML/System/Vector2.hpp"
6 |
7 | #include
8 |
9 | class Collision;
10 |
11 | class Collider : public sf::Drawable {
12 | public:
13 | Collider(uint32_t count);
14 | virtual ~Collider();
15 |
16 | // Modifiers
17 | void SetPosition(sf::Vector2f position);
18 | void SetOrigin (sf::Vector2f origin);
19 | void SetRotation(sf::Angle angle);
20 | void Move (sf::Vector2f offset);
21 | void Rotate (sf::Angle angle);
22 |
23 | // Accessors
24 | sf::Vector2f GetPosition() const;
25 | sf::Vector2f GetOrigin() const;
26 | sf::Angle GetRotation() const;
27 |
28 | std::function Trigger;
29 |
30 | protected:
31 | sf::Vector2f m_position;
32 | sf::Vector2f m_origin;
33 | sf::Angle m_rotation;
34 |
35 | sf::Vector2f* m_vertices;
36 | uint32_t m_verticesCount = 0;
37 |
38 | private:
39 | friend class Collision;
40 | };
41 |
42 | class BoxCollider : public Collider {
43 | public:
44 | BoxCollider();
45 | ~BoxCollider();
46 |
47 | void Create(sf::Vector2f size);
48 |
49 | private:
50 | sf::Vector2f m_size;
51 |
52 | virtual void draw(sf::RenderTarget& target, const sf::RenderStates& states) const;
53 | };
54 |
55 | class CircleCollider : public Collider {
56 | public:
57 | CircleCollider();
58 | ~CircleCollider();
59 |
60 | void Create(float radius);
61 |
62 | float GetRadius() const;
63 |
64 | private:
65 | float m_radius = 0.0f;
66 |
67 | virtual void draw(sf::RenderTarget& target, const sf::RenderStates& states) const;
68 | };
69 |
70 | class CustomCollider : public Collider {
71 | public:
72 | CustomCollider();
73 |
74 | CustomCollider(uint32_t count);
75 |
76 | ~CustomCollider();
77 |
78 | sf::Vector2f* GetVertices();
79 | sf::Vector2f& GetVertices(uint32_t index);
80 |
81 | void Create(uint32_t count);
82 |
83 | sf::Vector2f& operator[](uint32_t index);
84 |
85 | private:
86 | virtual void draw(sf::RenderTarget& target, const sf::RenderStates& states) const;
87 | };
88 |
--------------------------------------------------------------------------------
/SAT/include/Collision.hpp:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | #include "Collider.hpp"
4 |
5 | constexpr float INF = std::numeric_limits::infinity();
6 |
7 | class Collision {
8 | public:
9 | static Collision Instance;
10 |
11 | bool SATCollision(const Collider& body, const Collider& other, sf::Vector2f& MTV);
12 |
13 | bool SATCollision(const CircleCollider& body, const Collider& other, sf::Vector2f& MTV);
14 | bool SATCollision(const Collider& body, const CircleCollider& other, sf::Vector2f& MTV);
15 |
16 | bool SATCollision(const CircleCollider& body, const CircleCollider& other, sf::Vector2f& MTV);
17 |
18 | private:
19 | Collision();
20 | ~Collision();
21 |
22 | sf::Vector2f CircleAxis(sf::Vector2f* vertices, uint32_t count, sf::Vector2f center);
23 |
24 | sf::Vector2f PerpendicularAxis(sf::Vector2f* vertices, uint32_t index, uint32_t count) const;
25 |
26 | sf::Vector2f ProjectOnto(sf::Vector2f* vertices, uint32_t count, sf::Vector2f axis) const;
27 | sf::Vector2f ProjectCircle(sf::Vector2f circleCenter, float radius, sf::Vector2f axis) const;
28 |
29 | sf::Vector2f GetCenter(const Collider& body) const;
30 |
31 | float Overlap(sf::Vector2f v0, sf::Vector2f v1) const;
32 | };
--------------------------------------------------------------------------------
/SAT/include/Utilities.hpp:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | constexpr float PI = 3.14159265f;
4 |
5 | template
6 | inline float DotProduct(sf::Vector2 v0, sf::Vector2 v1) {
7 | return v0.x * v1.x + v0.y * v1.y;
8 | }
9 |
10 | template // Z coords of crossed vectors
11 | inline float CrossProduct(sf::Vector2 v0, sf::Vector2 v1) {
12 | return v0.x * v1.y - v0.y * v1.x;
13 | }
14 |
15 | template
16 | inline float Distance(sf::Vector2 v0, sf::Vector2 v1) {
17 | return sqrtf((v0 - v1).x * (v0 - v1).x + (v0 - v1).y * (v0 - v1).y);
18 | }
19 |
20 | template
21 | inline float Length(sf::Vector2 v) {
22 | return sqrtf(v.x * v.x + v.y * v.y);
23 | }
24 |
25 | template
26 | static sf::Vector2 Normalize(sf::Vector2 v) {
27 | float length = Length(v);
28 |
29 | return length ? v / length : sf::Vector2();
30 | }
31 |
32 | template
33 | static sf::Vector2 Rotate(sf::Vector2 point, sf::Vector2 center, sf::Angle angle) {
34 | float r = angle.asRadians();
35 |
36 | return sf::Vector2
37 | {
38 | cosf(r)* (point.x - center.x) - sinf(r) * (point.y - center.y) + center.x,
39 | sinf(r)* (point.x - center.x) + cosf(r) * (point.y - center.y) + center.y
40 | };
41 | }
42 |
43 | template
44 | inline sf::Vector2 VecAbs(sf::Vector2 v) {
45 | return sf::Vector2
46 | {
47 | v.x < T(0) ? -v.x : v.x,
48 | v.y < T(0) ? -v.y : v.y
49 | };
50 | }
51 |
52 | inline sf::Vector2f Lerp(sf::Vector2f x, sf::Vector2f y, float t) {
53 | return x * (1.0f - t) + y * t;
54 | }
55 |
56 | inline sf::Vector2f MousePos(const sf::RenderWindow& window = *(sf::RenderWindow*)nullptr) {
57 | return !&window ? (sf::Vector2f)sf::Mouse::getPosition() : window.mapPixelToCoords(sf::Mouse::getPosition(window));
58 | }
59 |
60 | #ifdef DEBUG
61 | template
62 | void Print(T&&... args) {
63 | (std::cout << ... << args);
64 | }
65 |
66 | #define LOG(...) Print(__VA_ARGS__)
67 |
68 | #else
69 |
70 | #define LOG(...)
71 |
72 | #endif
73 |
--------------------------------------------------------------------------------
/SAT/main.cpp:
--------------------------------------------------------------------------------
1 | #include "stpch.h"
2 |
3 | #include "Application.hpp"
4 |
5 | int main() {
6 | Application::Instance = new Application();
7 |
8 | Application::Instance->Run();
9 |
10 | delete Application::Instance;
11 |
12 | return EXIT_SUCCESS;
13 | }
14 |
--------------------------------------------------------------------------------
/SAT/pch/stpch.cpp:
--------------------------------------------------------------------------------
1 | #include "stpch.h"
--------------------------------------------------------------------------------
/SAT/pch/stpch.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | #include
4 |
5 | #include
6 |
7 | #include "Utilities.hpp"
8 |
9 | constexpr uint32_t WINDOW_WIDTH = 1600;
10 | constexpr uint32_t WINDOW_HEIGHT = 900;
11 |
12 | extern const float& dt;
13 |
--------------------------------------------------------------------------------
/SAT/premake5.lua:
--------------------------------------------------------------------------------
1 | project "SAT"
2 | kind "ConsoleApp"
3 | language "C++"
4 | cppdialect "C++17"
5 | staticruntime "on"
6 |
7 | targetdir "bin/%{cfg.buildcfg}"
8 | objdir "bin/Obj/%{cfg.buildcfg}"
9 |
10 | pchheader "stpch.h"
11 | pchsource "pch/stpch.cpp"
12 |
13 | files {
14 | "**.h",
15 | "**.hpp",
16 | "**.cpp",
17 | "*.lua",
18 | "*.dll"
19 | }
20 |
21 | includedirs {
22 | "../include",
23 | "include",
24 | "pch",
25 | }
26 |
27 | libdirs {
28 | "../libs/extlibs"
29 | }
30 |
31 | defines {
32 | "SFML_STATIC"
33 | }
34 |
35 | links {
36 | "opengl32.lib",
37 | "openal32.lib",
38 | "freetype.lib",
39 | "winmm.lib",
40 | "gdi32.lib",
41 | "flac.lib",
42 | "vorbisenc.lib",
43 | "vorbisfile.lib",
44 | "vorbis.lib",
45 | "ogg.lib",
46 | "ws2_32.lib",
47 | "legacy_stdio_definitions.lib",
48 | }
49 |
50 | filter "configurations:Debug"
51 | defines { "DEBUG" }
52 | symbols "On"
53 | libdirs {
54 | "../libs/Debug"
55 | }
56 |
57 | links {
58 | "sfml-graphics-s-d.lib",
59 | "sfml-window-s-d.lib",
60 | "sfml-system-s-d.lib",
61 | "sfml-audio-s-d.lib",
62 | "sfml-network-s-d.lib"
63 | }
64 |
65 | filter "configurations:Release"
66 | defines { "NDEBUG" }
67 | optimize "On"
68 | libdirs {
69 | "../libs/Release"
70 | }
71 |
72 | links {
73 | "sfml-graphics-s.lib",
74 | "sfml-window-s.lib",
75 | "sfml-system-s.lib",
76 | "sfml-audio-s.lib",
77 | "sfml-network-s.lib"
78 | }
79 |
--------------------------------------------------------------------------------
/SAT/src/Application.cpp:
--------------------------------------------------------------------------------
1 | #include "stpch.h"
2 | #include "Application.hpp"
3 |
4 | Application* Application::Instance = nullptr;
5 | float Application::DT = 0.0f;
6 |
7 | const float& dt = Application::DT;
8 |
9 | Application::Application() {
10 | InitWindow();
11 |
12 | CreateColliders();
13 | }
14 |
15 | Application::~Application() {
16 | for (auto& c : m_Colliders)
17 | delete c;
18 | }
19 |
20 | void Application::Run() {
21 | m_dtClock.restart();
22 |
23 | while (Window.isOpen()) {
24 | HandleEvents();
25 | Update();
26 |
27 | Window.clear(sf::Color(13, 17, 31));
28 | Render();
29 | Window.display();
30 |
31 | DT = m_dtClock.restart().asSeconds();
32 | }
33 | }
34 |
35 | void Application::CheckCollision() {
36 | for (auto& c : m_Colliders) {
37 | sf::Vector2f MTV;
38 | Collision::Instance.SATCollision(m_box, *c, MTV);
39 |
40 | m_box.Move(MTV);
41 | }
42 | }
43 |
44 | void Application::UpdateBox() {
45 | constexpr float smoothness = 16.0f;
46 |
47 | if (sf::Mouse::isButtonPressed(sf::Mouse::Left))
48 | m_box.Rotate(sf::degrees(100.0f * dt));
49 |
50 | sf::Vector2f start = m_box.GetPosition();
51 | sf::Vector2f end = MousePos(Window);
52 | sf::Vector2f pos = Lerp(start, end, smoothness * dt);
53 |
54 | m_box.SetPosition(pos);
55 | }
56 |
57 | void Application::Update() {
58 | UpdateBox();
59 | CheckCollision();
60 | }
61 |
62 | void Application::Render() {
63 | for (auto& c : m_Colliders)
64 | Window.draw(*c);
65 |
66 | Window.draw(m_box);
67 | }
68 |
69 | void Application::HandleEvents() {
70 | while (Window.pollEvent(Event)) {
71 | switch (Event.type) {
72 | case sf::Event::Closed:
73 | Window.close();
74 | }
75 | }
76 | }
77 |
78 | void Application::InitWindow() {
79 | sf::VideoMode mode;
80 | mode.width = WINDOW_WIDTH;
81 | mode.height = WINDOW_HEIGHT;
82 |
83 | sf::ContextSettings settings;
84 |
85 | Window.create(mode, "SAT Collision", sf::Style::Close, settings);
86 | Window.setFramerateLimit(144);
87 | }
88 |
89 | void Application::CreateColliders() {
90 | {
91 | m_box.Create(sf::Vector2f(100.0f, 100.0f));
92 | m_box.SetOrigin(sf::Vector2f(50.0f, 50.0f));
93 | m_box.SetPosition(MousePos(Window));
94 | }
95 |
96 | {
97 | CircleCollider* c = new CircleCollider();
98 |
99 | c->Create(100.0f);
100 |
101 | c->SetPosition(sf::Vector2f(220.0f, 220.0f));
102 |
103 | m_Colliders.push_back(c);
104 | }
105 |
106 | {
107 | CircleCollider* c = new CircleCollider();
108 |
109 | c->Create(50.0f);
110 |
111 | c->SetPosition(sf::Vector2f(920.0f, 150.0f));
112 |
113 | m_Colliders.push_back(c);
114 | }
115 |
116 | {
117 | BoxCollider* c = new BoxCollider();
118 |
119 | c->Create(sf::Vector2f(200.0f, 200.0f));
120 |
121 | c->SetPosition(sf::Vector2f(650.0f, 330.0f));
122 |
123 | c->SetRotation(sf::degrees(45.0f));
124 |
125 | m_Colliders.push_back(c);
126 | }
127 |
128 | {
129 | BoxCollider* c = new BoxCollider();
130 |
131 | c->Create(sf::Vector2f(300.0f, 200.0f));
132 |
133 | c->SetPosition(sf::Vector2f(120.0f, 560.0f));
134 |
135 | c->SetRotation(sf::degrees(25.0f));
136 |
137 | m_Colliders.push_back(c);
138 | }
139 |
140 | {
141 |
142 | CustomCollider* c = new CustomCollider(3);
143 |
144 | c->GetVertices(0) = sf::Vector2f(0.0f, 0.0f);
145 | c->GetVertices(1) = sf::Vector2f(200.0f, 200.0f);
146 | c->GetVertices(2) = sf::Vector2f(200.0f, 0.0f);
147 |
148 | c->SetPosition(sf::Vector2f(1230.0f, 80.0f));
149 |
150 | c->SetRotation(sf::degrees(15.0f));
151 |
152 | m_Colliders.push_back(c);
153 | }
154 |
155 | {
156 |
157 | CustomCollider* c = new CustomCollider(6);
158 |
159 | c->GetVertices(0) = sf::Vector2f(100.0f, 0.0f );
160 | c->GetVertices(1) = sf::Vector2f(200.0f, 0.0f );
161 | c->GetVertices(2) = sf::Vector2f(260.0f, 60.0f );
162 | c->GetVertices(3) = sf::Vector2f(160.0f, 120.0f);
163 | c->GetVertices(4) = sf::Vector2f(80.0f , 120.0f);
164 | c->GetVertices(5) = sf::Vector2f(0.0f , 50.0f );
165 |
166 | c->SetPosition(sf::Vector2f(1340.0f, 450.0f));
167 |
168 | c->SetRotation(sf::degrees(15.0f));
169 |
170 | m_Colliders.push_back(c);
171 | }
172 |
173 | {
174 |
175 | CustomCollider* c = new CustomCollider(4);
176 |
177 | c->GetVertices(0) = sf::Vector2f(0.0f , 0.0f );
178 | c->GetVertices(1) = sf::Vector2f(200.0f, 200.0f);
179 | c->GetVertices(2) = sf::Vector2f(200.0f, 0.0f );
180 | c->GetVertices(3) = sf::Vector2f(0.0f , -200.0f);
181 |
182 | c->SetPosition(sf::Vector2f(950.0f, 600.0f));
183 |
184 | c->SetRotation(sf::degrees(75.0f));
185 |
186 | m_Colliders.push_back(c);
187 | }
188 | }
189 |
--------------------------------------------------------------------------------
/SAT/src/Collider.cpp:
--------------------------------------------------------------------------------
1 | #include "stpch.h"
2 | #include "Collider.hpp"
3 |
4 | constexpr sf::Color ColliderColor(255, 255, 255);
5 |
6 | Collider::Collider(uint32_t count)
7 | : m_verticesCount(count)
8 | , m_vertices (nullptr)
9 | , m_position (0.0f, 0.0f)
10 | , m_origin (0.0f, 0.0f)
11 | , m_rotation (sf::degrees(0.0f))
12 | {
13 | if (!count)
14 | return;
15 |
16 | m_vertices = new sf::Vector2f[count];
17 | }
18 |
19 | Collider::~Collider() {
20 | delete[] m_vertices;
21 | }
22 |
23 | void Collider::SetPosition(sf::Vector2f position) {
24 | sf::Vector2f diff = position - m_position - m_origin;
25 |
26 | for (uint32_t i = 0; i < m_verticesCount; i++) {
27 | auto& v = m_vertices[i];
28 |
29 | v += diff;
30 | }
31 |
32 | m_position = position - m_origin;
33 | }
34 |
35 | void Collider::SetOrigin(sf::Vector2f origin) {
36 | m_origin = origin;
37 |
38 | SetPosition(m_position);
39 | }
40 |
41 | void Collider::SetRotation(sf::Angle angle) {
42 | sf::Angle diff = angle - m_rotation;
43 |
44 | for (uint32_t i = 0; i < m_verticesCount; i++) {
45 | auto& v = m_vertices[i];
46 |
47 | v = ::Rotate(v, m_position + m_origin, diff);
48 | }
49 |
50 | m_rotation = angle;
51 | }
52 |
53 | void Collider::Move(sf::Vector2f offset) {
54 | SetPosition(m_position + offset + m_origin);
55 | }
56 |
57 | void Collider::Rotate(sf::Angle angle) {
58 | SetRotation(m_rotation + angle);
59 | }
60 |
61 | sf::Vector2f Collider::GetPosition() const {
62 | return m_position + m_origin;
63 | }
64 |
65 | sf::Vector2f Collider::GetOrigin() const {
66 | return m_origin;
67 | }
68 |
69 | sf::Angle Collider::GetRotation() const {
70 | return m_rotation;
71 | }
72 |
73 | BoxCollider::BoxCollider()
74 | : Collider(4)
75 | {
76 |
77 | }
78 |
79 | BoxCollider::~BoxCollider() {
80 |
81 | }
82 |
83 | void BoxCollider::Create(sf::Vector2f size) {
84 | auto& v = m_vertices;
85 |
86 | sf::Vector2f pos = m_position - m_origin;
87 |
88 | v[0] = pos + sf::Vector2f(0.0f, 0.0f);
89 | v[1] = pos + sf::Vector2f(size.x, 0.0f);
90 | v[2] = pos + sf::Vector2f(size.x, size.y);
91 | v[3] = pos + sf::Vector2f(0.0f, size.y);
92 | }
93 |
94 | void BoxCollider::draw(sf::RenderTarget& target, const sf::RenderStates& states) const {
95 | static sf::Vertex v[6];
96 |
97 | for (int i = 0; i < 4; i++)
98 | v[i] = sf::Vertex(m_vertices[i], ColliderColor);
99 |
100 | v[4] = sf::Vertex(m_vertices[0], ColliderColor);
101 | v[5] = sf::Vertex(m_vertices[2], ColliderColor);
102 |
103 | target.draw(v, 6, sf::LineStrip);
104 | }
105 |
106 | CircleCollider::CircleCollider()
107 | : Collider(1)
108 | {
109 |
110 | }
111 |
112 | CircleCollider::~CircleCollider() {
113 |
114 | }
115 |
116 | void CircleCollider::Create(float radius) {
117 | m_radius = radius;
118 | }
119 |
120 | float CircleCollider::GetRadius() const {
121 | return m_radius;
122 | }
123 |
124 | void CircleCollider::draw(sf::RenderTarget& target, const sf::RenderStates& states) const {
125 | constexpr uint32_t points = 32;
126 |
127 | if (m_radius <= 0.0f)
128 | return;
129 |
130 | sf::Angle angle = sf::radians(2 * PI / (float)points);
131 |
132 | sf::Vector2f p = m_position;
133 | p.y += m_radius;
134 |
135 | static sf::Vertex v[points + 1];
136 |
137 | for (uint32_t i = 0; i <= points; i++)
138 | v[i] = sf::Vertex(::Rotate(p, m_position, angle * (float)i), ColliderColor);
139 |
140 | target.draw(v, points + 1, sf::LineStrip);
141 | target.draw(&sf::Vertex(m_position, ColliderColor), 1, sf::Points);
142 | }
143 |
144 | CustomCollider::CustomCollider()
145 | : Collider(0)
146 | {
147 |
148 | }
149 |
150 | CustomCollider::CustomCollider(uint32_t count)
151 | : Collider(count)
152 | {
153 |
154 | }
155 |
156 | CustomCollider::~CustomCollider() {
157 |
158 | }
159 |
160 | sf::Vector2f* CustomCollider::GetVertices() {
161 | return m_vertices;
162 | }
163 |
164 | sf::Vector2f& CustomCollider::GetVertices(uint32_t index) {
165 | return m_vertices[index];
166 | }
167 |
168 | void CustomCollider::Create(uint32_t count) {
169 | delete[] m_vertices;
170 |
171 | m_vertices = new sf::Vector2f[count];
172 |
173 | m_verticesCount = count;
174 | }
175 |
176 | sf::Vector2f& CustomCollider::operator[](uint32_t index) {
177 | return m_vertices[index];
178 | }
179 |
180 | void CustomCollider::draw(sf::RenderTarget& target, const sf::RenderStates& states) const {
181 | const uint32_t count = m_verticesCount + 1;
182 |
183 | sf::Vertex* v = new sf::Vertex[count];
184 |
185 | for (uint32_t i = 0; i < count - 1; i++)
186 | v[i] = sf::Vertex(m_vertices[i], ColliderColor);
187 |
188 | v[count - 1] = sf::Vertex(m_vertices[0], ColliderColor);
189 |
190 | target.draw(v, count, sf::LineStrip);
191 |
192 | delete[] v;
193 | }
194 |
--------------------------------------------------------------------------------
/build.bat:
--------------------------------------------------------------------------------
1 | xcopy /y "libs\PDB" "SAT\bin\Debug\*"
2 | .\vendor\premake5.exe vs2022
--------------------------------------------------------------------------------
/images/preview.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xSnapi/SAT-Collision/49eab4e6d67f74ba7e48d713e622bf3b915f58d4/images/preview.png
--------------------------------------------------------------------------------
/include/SFML/Audio.hpp:
--------------------------------------------------------------------------------
1 | ////////////////////////////////////////////////////////////
2 | //
3 | // SFML - Simple and Fast Multimedia Library
4 | // Copyright (C) 2007-2022 Laurent Gomila (laurent@sfml-dev.org)
5 | //
6 | // This software is provided 'as-is', without any express or implied warranty.
7 | // In no event will the authors be held liable for any damages arising from the use of this software.
8 | //
9 | // Permission is granted to anyone to use this software for any purpose,
10 | // including commercial applications, and to alter it and redistribute it freely,
11 | // subject to the following restrictions:
12 | //
13 | // 1. The origin of this software must not be misrepresented;
14 | // you must not claim that you wrote the original software.
15 | // If you use this software in a product, an acknowledgment
16 | // in the product documentation would be appreciated but is not required.
17 | //
18 | // 2. Altered source versions must be plainly marked as such,
19 | // and must not be misrepresented as being the original software.
20 | //
21 | // 3. This notice may not be removed or altered from any source distribution.
22 | //
23 | ////////////////////////////////////////////////////////////
24 |
25 | #ifndef SFML_AUDIO_HPP
26 | #define SFML_AUDIO_HPP
27 |
28 | ////////////////////////////////////////////////////////////
29 | // Headers
30 | ////////////////////////////////////////////////////////////
31 |
32 | #include
33 | #include
34 | #include
35 | #include
36 | #include
37 | #include
38 | #include
39 | #include
40 | #include
41 | #include
42 | #include
43 | #include
44 | #include
45 | #include
46 |
47 |
48 | #endif // SFML_AUDIO_HPP
49 |
50 | ////////////////////////////////////////////////////////////
51 | /// \defgroup audio Audio module
52 | ///
53 | /// Sounds, streaming (musics or custom sources), recording,
54 | /// spatialization.
55 | ///
56 | ////////////////////////////////////////////////////////////
57 |
--------------------------------------------------------------------------------
/include/SFML/Audio/AlResource.hpp:
--------------------------------------------------------------------------------
1 | ////////////////////////////////////////////////////////////
2 | //
3 | // SFML - Simple and Fast Multimedia Library
4 | // Copyright (C) 2007-2022 Laurent Gomila (laurent@sfml-dev.org)
5 | //
6 | // This software is provided 'as-is', without any express or implied warranty.
7 | // In no event will the authors be held liable for any damages arising from the use of this software.
8 | //
9 | // Permission is granted to anyone to use this software for any purpose,
10 | // including commercial applications, and to alter it and redistribute it freely,
11 | // subject to the following restrictions:
12 | //
13 | // 1. The origin of this software must not be misrepresented;
14 | // you must not claim that you wrote the original software.
15 | // If you use this software in a product, an acknowledgment
16 | // in the product documentation would be appreciated but is not required.
17 | //
18 | // 2. Altered source versions must be plainly marked as such,
19 | // and must not be misrepresented as being the original software.
20 | //
21 | // 3. This notice may not be removed or altered from any source distribution.
22 | //
23 | ////////////////////////////////////////////////////////////
24 |
25 | #ifndef SFML_ALRESOURCE_HPP
26 | #define SFML_ALRESOURCE_HPP
27 |
28 | ////////////////////////////////////////////////////////////
29 | // Headers
30 | ////////////////////////////////////////////////////////////
31 | #include
32 |
33 |
34 | namespace sf
35 | {
36 | ////////////////////////////////////////////////////////////
37 | /// \brief Base class for classes that require an OpenAL context
38 | ///
39 | ////////////////////////////////////////////////////////////
40 | class SFML_AUDIO_API AlResource
41 | {
42 | protected:
43 |
44 | ////////////////////////////////////////////////////////////
45 | /// \brief Default constructor
46 | ///
47 | ////////////////////////////////////////////////////////////
48 | AlResource();
49 |
50 | ////////////////////////////////////////////////////////////
51 | /// \brief Destructor
52 | ///
53 | ////////////////////////////////////////////////////////////
54 | ~AlResource();
55 | };
56 |
57 | } // namespace sf
58 |
59 |
60 | #endif // SFML_ALRESOURCE_HPP
61 |
62 | ////////////////////////////////////////////////////////////
63 | /// \class sf::AlResource
64 | /// \ingroup audio
65 | ///
66 | /// This class is for internal use only, it must be the base
67 | /// of every class that requires a valid OpenAL context in
68 | /// order to work.
69 | ///
70 | ////////////////////////////////////////////////////////////
71 |
--------------------------------------------------------------------------------
/include/SFML/Audio/Export.hpp:
--------------------------------------------------------------------------------
1 | ////////////////////////////////////////////////////////////
2 | //
3 | // SFML - Simple and Fast Multimedia Library
4 | // Copyright (C) 2007-2022 Laurent Gomila (laurent@sfml-dev.org)
5 | //
6 | // This software is provided 'as-is', without any express or implied warranty.
7 | // In no event will the authors be held liable for any damages arising from the use of this software.
8 | //
9 | // Permission is granted to anyone to use this software for any purpose,
10 | // including commercial applications, and to alter it and redistribute it freely,
11 | // subject to the following restrictions:
12 | //
13 | // 1. The origin of this software must not be misrepresented;
14 | // you must not claim that you wrote the original software.
15 | // If you use this software in a product, an acknowledgment
16 | // in the product documentation would be appreciated but is not required.
17 | //
18 | // 2. Altered source versions must be plainly marked as such,
19 | // and must not be misrepresented as being the original software.
20 | //
21 | // 3. This notice may not be removed or altered from any source distribution.
22 | //
23 | ////////////////////////////////////////////////////////////
24 |
25 | #ifndef SFML_AUDIO_EXPORT_HPP
26 | #define SFML_AUDIO_EXPORT_HPP
27 |
28 | ////////////////////////////////////////////////////////////
29 | // Headers
30 | ////////////////////////////////////////////////////////////
31 | #include
32 |
33 |
34 | ////////////////////////////////////////////////////////////
35 | // Define portable import / export macros
36 | ////////////////////////////////////////////////////////////
37 | #if defined(SFML_AUDIO_EXPORTS)
38 |
39 | #define SFML_AUDIO_API SFML_API_EXPORT
40 |
41 | #else
42 |
43 | #define SFML_AUDIO_API SFML_API_IMPORT
44 |
45 | #endif
46 |
47 |
48 | #endif // SFML_AUDIO_EXPORT_HPP
49 |
--------------------------------------------------------------------------------
/include/SFML/Audio/OutputSoundFile.hpp:
--------------------------------------------------------------------------------
1 | ////////////////////////////////////////////////////////////
2 | //
3 | // SFML - Simple and Fast Multimedia Library
4 | // Copyright (C) 2007-2022 Laurent Gomila (laurent@sfml-dev.org)
5 | //
6 | // This software is provided 'as-is', without any express or implied warranty.
7 | // In no event will the authors be held liable for any damages arising from the use of this software.
8 | //
9 | // Permission is granted to anyone to use this software for any purpose,
10 | // including commercial applications, and to alter it and redistribute it freely,
11 | // subject to the following restrictions:
12 | //
13 | // 1. The origin of this software must not be misrepresented;
14 | // you must not claim that you wrote the original software.
15 | // If you use this software in a product, an acknowledgment
16 | // in the product documentation would be appreciated but is not required.
17 | //
18 | // 2. Altered source versions must be plainly marked as such,
19 | // and must not be misrepresented as being the original software.
20 | //
21 | // 3. This notice may not be removed or altered from any source distribution.
22 | //
23 | ////////////////////////////////////////////////////////////
24 |
25 | #ifndef SFML_OUTPUTSOUNDFILE_HPP
26 | #define SFML_OUTPUTSOUNDFILE_HPP
27 |
28 | ////////////////////////////////////////////////////////////
29 | // Headers
30 | ////////////////////////////////////////////////////////////
31 | #include
32 | #include
33 | #include
34 | #include
35 |
36 |
37 | namespace sf
38 | {
39 | class SoundFileWriter;
40 |
41 | ////////////////////////////////////////////////////////////
42 | /// \brief Provide write access to sound files
43 | ///
44 | ////////////////////////////////////////////////////////////
45 | class SFML_AUDIO_API OutputSoundFile
46 | {
47 | public:
48 |
49 | ////////////////////////////////////////////////////////////
50 | /// \brief Default constructor
51 | ///
52 | ////////////////////////////////////////////////////////////
53 | OutputSoundFile();
54 |
55 | ////////////////////////////////////////////////////////////
56 | /// \brief Destructor
57 | ///
58 | /// Closes the file if it was still open.
59 | ///
60 | ////////////////////////////////////////////////////////////
61 | ~OutputSoundFile();
62 |
63 | ////////////////////////////////////////////////////////////
64 | /// \brief Deleted copy constructor
65 | ///
66 | ////////////////////////////////////////////////////////////
67 | OutputSoundFile(const OutputSoundFile&) = delete;
68 |
69 | ////////////////////////////////////////////////////////////
70 | /// \brief Deleted copy assignment
71 | ///
72 | ////////////////////////////////////////////////////////////
73 | OutputSoundFile& operator=(const OutputSoundFile&) = delete;
74 |
75 | ////////////////////////////////////////////////////////////
76 | /// \brief Open the sound file from the disk for writing
77 | ///
78 | /// The supported audio formats are: WAV, OGG/Vorbis, FLAC.
79 | ///
80 | /// \param filename Path of the sound file to write
81 | /// \param sampleRate Sample rate of the sound
82 | /// \param channelCount Number of channels in the sound
83 | ///
84 | /// \return True if the file was successfully opened
85 | ///
86 | ////////////////////////////////////////////////////////////
87 | [[nodiscard]] bool openFromFile(const std::filesystem::path& filename, unsigned int sampleRate, unsigned int channelCount);
88 |
89 | ////////////////////////////////////////////////////////////
90 | /// \brief Write audio samples to the file
91 | ///
92 | /// \param samples Pointer to the sample array to write
93 | /// \param count Number of samples to write
94 | ///
95 | ////////////////////////////////////////////////////////////
96 | void write(const Int16* samples, Uint64 count);
97 |
98 | ////////////////////////////////////////////////////////////
99 | /// \brief Close the current file
100 | ///
101 | ////////////////////////////////////////////////////////////
102 | void close();
103 |
104 | private:
105 |
106 | ////////////////////////////////////////////////////////////
107 | // Member data
108 | ////////////////////////////////////////////////////////////
109 | std::unique_ptr m_writer; //!< Writer that handles I/O on the file's format
110 | };
111 |
112 | } // namespace sf
113 |
114 |
115 | #endif // SFML_OUTPUTSOUNDFILE_HPP
116 |
117 |
118 | ////////////////////////////////////////////////////////////
119 | /// \class sf::OutputSoundFile
120 | /// \ingroup audio
121 | ///
122 | /// This class encodes audio samples to a sound file. It is
123 | /// used internally by higher-level classes such as sf::SoundBuffer,
124 | /// but can also be useful if you want to create audio files from
125 | /// custom data sources, like generated audio samples.
126 | ///
127 | /// Usage example:
128 | /// \code
129 | /// // Create a sound file, ogg/vorbis format, 44100 Hz, stereo
130 | /// sf::OutputSoundFile file;
131 | /// if (!file.openFromFile("music.ogg", 44100, 2))
132 | /// /* error */;
133 | ///
134 | /// while (...)
135 | /// {
136 | /// // Read or generate audio samples from your custom source
137 | /// std::vector samples = ...;
138 | ///
139 | /// // Write them to the file
140 | /// file.write(samples.data(), samples.size());
141 | /// }
142 | /// \endcode
143 | ///
144 | /// \see sf::SoundFileWriter, sf::InputSoundFile
145 | ///
146 | ////////////////////////////////////////////////////////////
147 |
--------------------------------------------------------------------------------
/include/SFML/Audio/SoundBufferRecorder.hpp:
--------------------------------------------------------------------------------
1 | ////////////////////////////////////////////////////////////
2 | //
3 | // SFML - Simple and Fast Multimedia Library
4 | // Copyright (C) 2007-2022 Laurent Gomila (laurent@sfml-dev.org)
5 | //
6 | // This software is provided 'as-is', without any express or implied warranty.
7 | // In no event will the authors be held liable for any damages arising from the use of this software.
8 | //
9 | // Permission is granted to anyone to use this software for any purpose,
10 | // including commercial applications, and to alter it and redistribute it freely,
11 | // subject to the following restrictions:
12 | //
13 | // 1. The origin of this software must not be misrepresented;
14 | // you must not claim that you wrote the original software.
15 | // If you use this software in a product, an acknowledgment
16 | // in the product documentation would be appreciated but is not required.
17 | //
18 | // 2. Altered source versions must be plainly marked as such,
19 | // and must not be misrepresented as being the original software.
20 | //
21 | // 3. This notice may not be removed or altered from any source distribution.
22 | //
23 | ////////////////////////////////////////////////////////////
24 |
25 | #ifndef SFML_SOUNDBUFFERRECORDER_HPP
26 | #define SFML_SOUNDBUFFERRECORDER_HPP
27 |
28 | ////////////////////////////////////////////////////////////
29 | // Headers
30 | ////////////////////////////////////////////////////////////
31 | #include
32 | #include
33 | #include
34 | #include
35 |
36 |
37 | namespace sf
38 | {
39 | ////////////////////////////////////////////////////////////
40 | /// \brief Specialized SoundRecorder which stores the captured
41 | /// audio data into a sound buffer
42 | ///
43 | ////////////////////////////////////////////////////////////
44 | class SFML_AUDIO_API SoundBufferRecorder : public SoundRecorder
45 | {
46 | public:
47 |
48 | ////////////////////////////////////////////////////////////
49 | /// \brief destructor
50 | ///
51 | ////////////////////////////////////////////////////////////
52 | ~SoundBufferRecorder() override;
53 |
54 | ////////////////////////////////////////////////////////////
55 | /// \brief Get the sound buffer containing the captured audio data
56 | ///
57 | /// The sound buffer is valid only after the capture has ended.
58 | /// This function provides a read-only access to the internal
59 | /// sound buffer, but it can be copied if you need to
60 | /// make any modification to it.
61 | ///
62 | /// \return Read-only access to the sound buffer
63 | ///
64 | ////////////////////////////////////////////////////////////
65 | const SoundBuffer& getBuffer() const;
66 |
67 | protected:
68 |
69 | ////////////////////////////////////////////////////////////
70 | /// \brief Start capturing audio data
71 | ///
72 | /// \return True to start the capture, or false to abort it
73 | ///
74 | ////////////////////////////////////////////////////////////
75 | [[nodiscard]] bool onStart() override;
76 |
77 | ////////////////////////////////////////////////////////////
78 | /// \brief Process a new chunk of recorded samples
79 | ///
80 | /// \param samples Pointer to the new chunk of recorded samples
81 | /// \param sampleCount Number of samples pointed by \a samples
82 | ///
83 | /// \return True to continue the capture, or false to stop it
84 | ///
85 | ////////////////////////////////////////////////////////////
86 | [[nodiscard]] bool onProcessSamples(const Int16* samples, std::size_t sampleCount) override;
87 |
88 | ////////////////////////////////////////////////////////////
89 | /// \brief Stop capturing audio data
90 | ///
91 | ////////////////////////////////////////////////////////////
92 | void onStop() override;
93 |
94 | private:
95 |
96 | ////////////////////////////////////////////////////////////
97 | // Member data
98 | ////////////////////////////////////////////////////////////
99 | std::vector m_samples; //!< Temporary sample buffer to hold the recorded data
100 | SoundBuffer m_buffer; //!< Sound buffer that will contain the recorded data
101 | };
102 |
103 | } // namespace sf
104 |
105 | #endif // SFML_SOUNDBUFFERRECORDER_HPP
106 |
107 |
108 | ////////////////////////////////////////////////////////////
109 | /// \class sf::SoundBufferRecorder
110 | /// \ingroup audio
111 | ///
112 | /// sf::SoundBufferRecorder allows to access a recorded sound
113 | /// through a sf::SoundBuffer, so that it can be played, saved
114 | /// to a file, etc.
115 | ///
116 | /// It has the same simple interface as its base class (start(), stop())
117 | /// and adds a function to retrieve the recorded sound buffer
118 | /// (getBuffer()).
119 | ///
120 | /// As usual, don't forget to call the isAvailable() function
121 | /// before using this class (see sf::SoundRecorder for more details
122 | /// about this).
123 | ///
124 | /// Usage example:
125 | /// \code
126 | /// if (sf::SoundBufferRecorder::isAvailable())
127 | /// {
128 | /// // Record some audio data
129 | /// sf::SoundBufferRecorder recorder;
130 | /// if (!recorder.start())
131 | /// {
132 | /// // Handle error...
133 | /// }
134 | /// ...
135 | /// recorder.stop();
136 | ///
137 | /// // Get the buffer containing the captured audio data
138 | /// const sf::SoundBuffer& buffer = recorder.getBuffer();
139 | ///
140 | /// // Save it to a file (for example...)
141 | /// if (!buffer.saveToFile("my_record.ogg"))
142 | /// {
143 | /// // Handle error...
144 | /// }
145 | /// }
146 | /// \endcode
147 | ///
148 | /// \see sf::SoundRecorder
149 | ///
150 | ////////////////////////////////////////////////////////////
151 |
--------------------------------------------------------------------------------
/include/SFML/Audio/SoundFileFactory.inl:
--------------------------------------------------------------------------------
1 | ////////////////////////////////////////////////////////////
2 | //
3 | // SFML - Simple and Fast Multimedia Library
4 | // Copyright (C) 2007-2022 Laurent Gomila (laurent@sfml-dev.org)
5 | //
6 | // This software is provided 'as-is', without any express or implied warranty.
7 | // In no event will the authors be held liable for any damages arising from the use of this software.
8 | //
9 | // Permission is granted to anyone to use this software for any purpose,
10 | // including commercial applications, and to alter it and redistribute it freely,
11 | // subject to the following restrictions:
12 | //
13 | // 1. The origin of this software must not be misrepresented;
14 | // you must not claim that you wrote the original software.
15 | // If you use this software in a product, an acknowledgment
16 | // in the product documentation would be appreciated but is not required.
17 | //
18 | // 2. Altered source versions must be plainly marked as such,
19 | // and must not be misrepresented as being the original software.
20 | //
21 | // 3. This notice may not be removed or altered from any source distribution.
22 | //
23 | ////////////////////////////////////////////////////////////
24 |
25 | ////////////////////////////////////////////////////////////
26 | // Headers
27 | ////////////////////////////////////////////////////////////
28 |
29 |
30 | namespace sf
31 | {
32 | namespace priv
33 | {
34 | template std::unique_ptr createReader() { return std::make_unique(); }
35 | template std::unique_ptr createWriter() { return std::make_unique(); }
36 | }
37 |
38 | ////////////////////////////////////////////////////////////
39 | template
40 | void SoundFileFactory::registerReader()
41 | {
42 | // Make sure the same class won't be registered twice
43 | unregisterReader();
44 |
45 | // Create a new factory with the functions provided by the class
46 | ReaderFactory factory;
47 | factory.check = &T::check;
48 | factory.create = &priv::createReader;
49 |
50 | // Add it
51 | s_readers.push_back(factory);
52 | }
53 |
54 |
55 | ////////////////////////////////////////////////////////////
56 | template
57 | void SoundFileFactory::unregisterReader()
58 | {
59 | // Remove the instance(s) of the reader from the array of factories
60 | for (auto it = s_readers.begin(); it != s_readers.end(); /* noop */)
61 | {
62 | if (it->create == &priv::createReader)
63 | it = s_readers.erase(it);
64 | else
65 | ++it;
66 | }
67 | }
68 |
69 | ////////////////////////////////////////////////////////////
70 | template
71 | void SoundFileFactory::registerWriter()
72 | {
73 | // Make sure the same class won't be registered twice
74 | unregisterWriter();
75 |
76 | // Create a new factory with the functions provided by the class
77 | WriterFactory factory;
78 | factory.check = &T::check;
79 | factory.create = &priv::createWriter;
80 |
81 | // Add it
82 | s_writers.push_back(factory);
83 | }
84 |
85 |
86 | ////////////////////////////////////////////////////////////
87 | template
88 | void SoundFileFactory::unregisterWriter()
89 | {
90 | // Remove the instance(s) of the writer from the array of factories
91 | for (auto it = s_writers.begin(); it != s_writers.end(); /* noop */)
92 | {
93 | if (it->create == &priv::createWriter)
94 | it = s_writers.erase(it);
95 | else
96 | ++it;
97 | }
98 | }
99 |
100 | } // namespace sf
101 |
--------------------------------------------------------------------------------
/include/SFML/Audio/SoundFileWriter.hpp:
--------------------------------------------------------------------------------
1 | ////////////////////////////////////////////////////////////
2 | //
3 | // SFML - Simple and Fast Multimedia Library
4 | // Copyright (C) 2007-2022 Laurent Gomila (laurent@sfml-dev.org)
5 | //
6 | // This software is provided 'as-is', without any express or implied warranty.
7 | // In no event will the authors be held liable for any damages arising from the use of this software.
8 | //
9 | // Permission is granted to anyone to use this software for any purpose,
10 | // including commercial applications, and to alter it and redistribute it freely,
11 | // subject to the following restrictions:
12 | //
13 | // 1. The origin of this software must not be misrepresented;
14 | // you must not claim that you wrote the original software.
15 | // If you use this software in a product, an acknowledgment
16 | // in the product documentation would be appreciated but is not required.
17 | //
18 | // 2. Altered source versions must be plainly marked as such,
19 | // and must not be misrepresented as being the original software.
20 | //
21 | // 3. This notice may not be removed or altered from any source distribution.
22 | //
23 | ////////////////////////////////////////////////////////////
24 |
25 | #ifndef SFML_SOUNDFILEWRITER_HPP
26 | #define SFML_SOUNDFILEWRITER_HPP
27 |
28 | ////////////////////////////////////////////////////////////
29 | // Headers
30 | ////////////////////////////////////////////////////////////
31 | #include
32 | #include
33 | #include
34 |
35 |
36 | namespace sf
37 | {
38 | ////////////////////////////////////////////////////////////
39 | /// \brief Abstract base class for sound file encoding
40 | ///
41 | ////////////////////////////////////////////////////////////
42 | class SFML_AUDIO_API SoundFileWriter
43 | {
44 | public:
45 |
46 | ////////////////////////////////////////////////////////////
47 | /// \brief Virtual destructor
48 | ///
49 | ////////////////////////////////////////////////////////////
50 | virtual ~SoundFileWriter() {}
51 |
52 | ////////////////////////////////////////////////////////////
53 | /// \brief Open a sound file for writing
54 | ///
55 | /// \param filename Path of the file to open
56 | /// \param sampleRate Sample rate of the sound
57 | /// \param channelCount Number of channels of the sound
58 | ///
59 | /// \return True if the file was successfully opened
60 | ///
61 | ////////////////////////////////////////////////////////////
62 | [[nodiscard]] virtual bool open(const std::filesystem::path& filename, unsigned int sampleRate, unsigned int channelCount) = 0;
63 |
64 | ////////////////////////////////////////////////////////////
65 | /// \brief Write audio samples to the open file
66 | ///
67 | /// \param samples Pointer to the sample array to write
68 | /// \param count Number of samples to write
69 | ///
70 | ////////////////////////////////////////////////////////////
71 | virtual void write(const Int16* samples, Uint64 count) = 0;
72 | };
73 |
74 | } // namespace sf
75 |
76 |
77 | #endif // SFML_SOUNDFILEWRITER_HPP
78 |
79 |
80 | ////////////////////////////////////////////////////////////
81 | /// \class sf::SoundFileWriter
82 | /// \ingroup audio
83 | ///
84 | /// This class allows users to write audio file formats not natively
85 | /// supported by SFML, and thus extend the set of supported writable
86 | /// audio formats.
87 | ///
88 | /// A valid sound file writer must override the open and write functions,
89 | /// as well as providing a static check function; the latter is used by
90 | /// SFML to find a suitable writer for a given filename.
91 | ///
92 | /// To register a new writer, use the sf::SoundFileFactory::registerWriter
93 | /// template function.
94 | ///
95 | /// Usage example:
96 | /// \code
97 | /// class MySoundFileWriter : public sf::SoundFileWriter
98 | /// {
99 | /// public:
100 | ///
101 | /// [[nodiscard]] static bool check(const std::filesystem::path& filename)
102 | /// {
103 | /// // typically, check the extension
104 | /// // return true if the writer can handle the format
105 | /// }
106 | ///
107 | /// [[nodiscard]] bool open(const std::filesystem::path& filename, unsigned int sampleRate, unsigned int channelCount) override
108 | /// {
109 | /// // open the file 'filename' for writing,
110 | /// // write the given sample rate and channel count to the file header
111 | /// // return true on success
112 | /// }
113 | ///
114 | /// void write(const sf::Int16* samples, sf::Uint64 count) override
115 | /// {
116 | /// // write 'count' samples stored at address 'samples',
117 | /// // convert them (for example to normalized float) if the format requires it
118 | /// }
119 | /// };
120 | ///
121 | /// sf::SoundFileFactory::registerWriter();
122 | /// \endcode
123 | ///
124 | /// \see sf::OutputSoundFile, sf::SoundFileFactory, sf::SoundFileReader
125 | ///
126 | ////////////////////////////////////////////////////////////
127 |
--------------------------------------------------------------------------------
/include/SFML/Config.hpp:
--------------------------------------------------------------------------------
1 | ////////////////////////////////////////////////////////////
2 | //
3 | // SFML - Simple and Fast Multimedia Library
4 | // Copyright (C) 2007-2022 Laurent Gomila (laurent@sfml-dev.org)
5 | //
6 | // This software is provided 'as-is', without any express or implied warranty.
7 | // In no event will the authors be held liable for any damages arising from the use of this software.
8 | //
9 | // Permission is granted to anyone to use this software for any purpose,
10 | // including commercial applications, and to alter it and redistribute it freely,
11 | // subject to the following restrictions:
12 | //
13 | // 1. The origin of this software must not be misrepresented;
14 | // you must not claim that you wrote the original software.
15 | // If you use this software in a product, an acknowledgment
16 | // in the product documentation would be appreciated but is not required.
17 | //
18 | // 2. Altered source versions must be plainly marked as such,
19 | // and must not be misrepresented as being the original software.
20 | //
21 | // 3. This notice may not be removed or altered from any source distribution.
22 | //
23 | ////////////////////////////////////////////////////////////
24 |
25 | #ifndef SFML_CONFIG_HPP
26 | #define SFML_CONFIG_HPP
27 |
28 |
29 | ////////////////////////////////////////////////////////////
30 | // Headers
31 | ////////////////////////////////////////////////////////////
32 | #include
33 |
34 |
35 | ////////////////////////////////////////////////////////////
36 | // Define the SFML version
37 | ////////////////////////////////////////////////////////////
38 | #define SFML_VERSION_MAJOR 3
39 | #define SFML_VERSION_MINOR 0
40 | #define SFML_VERSION_PATCH 0
41 | #define SFML_VERSION_IS_RELEASE false
42 |
43 |
44 | ////////////////////////////////////////////////////////////
45 | // Identify the operating system
46 | // see https://sourceforge.net/p/predef/wiki/Home/
47 | ////////////////////////////////////////////////////////////
48 | #if defined(_WIN32)
49 |
50 | // Windows
51 | #define SFML_SYSTEM_WINDOWS
52 | #ifndef NOMINMAX
53 | #define NOMINMAX
54 | #endif
55 |
56 | #elif defined(__APPLE__) && defined(__MACH__)
57 |
58 | // Apple platform, see which one it is
59 | #include "TargetConditionals.h"
60 |
61 | #if TARGET_OS_IPHONE || TARGET_IPHONE_SIMULATOR
62 |
63 | // iOS
64 | #define SFML_SYSTEM_IOS
65 |
66 | #elif TARGET_OS_MAC
67 |
68 | // MacOS
69 | #define SFML_SYSTEM_MACOS
70 |
71 | #else
72 |
73 | // Unsupported Apple system
74 | #error This Apple operating system is not supported by SFML library
75 |
76 | #endif
77 |
78 | #elif defined(__unix__)
79 |
80 | // UNIX system, see which one it is
81 | #if defined(__ANDROID__)
82 |
83 | // Android
84 | #define SFML_SYSTEM_ANDROID
85 |
86 | #elif defined(__linux__)
87 |
88 | // Linux
89 | #define SFML_SYSTEM_LINUX
90 |
91 | #elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
92 |
93 | // FreeBSD
94 | #define SFML_SYSTEM_FREEBSD
95 |
96 | #elif defined(__OpenBSD__)
97 |
98 | // OpenBSD
99 | #define SFML_SYSTEM_OPENBSD
100 |
101 | #elif defined(__NetBSD__)
102 |
103 | // NetBSD
104 | #define SFML_SYSTEM_NETBSD
105 |
106 | #else
107 |
108 | // Unsupported UNIX system
109 | #error This UNIX operating system is not supported by SFML library
110 |
111 | #endif
112 |
113 | #else
114 |
115 | // Unsupported system
116 | #error This operating system is not supported by SFML library
117 |
118 | #endif
119 |
120 |
121 | ////////////////////////////////////////////////////////////
122 | // Define a portable debug macro
123 | ////////////////////////////////////////////////////////////
124 | #if !defined(NDEBUG)
125 |
126 | #define SFML_DEBUG
127 |
128 | #endif
129 |
130 |
131 | ////////////////////////////////////////////////////////////
132 | // Define helpers to create portable import / export macros for each module
133 | ////////////////////////////////////////////////////////////
134 | #if !defined(SFML_STATIC)
135 |
136 | #if defined(SFML_SYSTEM_WINDOWS)
137 |
138 | // Windows compilers need specific (and different) keywords for export and import
139 | #define SFML_API_EXPORT __declspec(dllexport)
140 | #define SFML_API_IMPORT __declspec(dllimport)
141 |
142 | // For Visual C++ compilers, we also need to turn off this annoying C4251 warning
143 | #ifdef _MSC_VER
144 |
145 | #pragma warning(disable: 4251)
146 |
147 | #endif
148 |
149 | #else // Linux, FreeBSD, Mac OS X
150 |
151 | #define SFML_API_EXPORT __attribute__ ((__visibility__ ("default")))
152 | #define SFML_API_IMPORT __attribute__ ((__visibility__ ("default")))
153 |
154 | #endif
155 |
156 | #else
157 |
158 | // Static build doesn't need import/export macros
159 | #define SFML_API_EXPORT
160 | #define SFML_API_IMPORT
161 |
162 | #endif
163 |
164 |
165 | ////////////////////////////////////////////////////////////
166 | // Define portable fixed-size types
167 | ////////////////////////////////////////////////////////////
168 | namespace sf
169 | {
170 | // 8 bits integer types
171 | using Int8 = std::int8_t;
172 | using Uint8 = std::uint8_t;
173 |
174 | // 16 bits integer types
175 | using Int16 = std::int16_t;
176 | using Uint16 = std::uint16_t;
177 |
178 | // 32 bits integer types
179 | using Int32 = std::int32_t;
180 | using Uint32 = std::uint32_t;
181 |
182 | // 64 bits integer types
183 | using Int64 = std::int64_t;
184 | using Uint64 = std::uint64_t;
185 |
186 | } // namespace sf
187 |
188 |
189 | #endif // SFML_CONFIG_HPP
190 |
--------------------------------------------------------------------------------
/include/SFML/GpuPreference.hpp:
--------------------------------------------------------------------------------
1 | ////////////////////////////////////////////////////////////
2 | //
3 | // SFML - Simple and Fast Multimedia Library
4 | // Copyright (C) 2007-2022 Laurent Gomila (laurent@sfml-dev.org)
5 | //
6 | // This software is provided 'as-is', without any express or implied warranty.
7 | // In no event will the authors be held liable for any damages arising from the use of this software.
8 | //
9 | // Permission is granted to anyone to use this software for any purpose,
10 | // including commercial applications, and to alter it and redistribute it freely,
11 | // subject to the following restrictions:
12 | //
13 | // 1. The origin of this software must not be misrepresented;
14 | // you must not claim that you wrote the original software.
15 | // If you use this software in a product, an acknowledgment
16 | // in the product documentation would be appreciated but is not required.
17 | //
18 | // 2. Altered source versions must be plainly marked as such,
19 | // and must not be misrepresented as being the original software.
20 | //
21 | // 3. This notice may not be removed or altered from any source distribution.
22 | //
23 | ////////////////////////////////////////////////////////////
24 |
25 | #ifndef SFML_GPUPREFERENCE_HPP
26 | #define SFML_GPUPREFERENCE_HPP
27 |
28 |
29 | ////////////////////////////////////////////////////////////
30 | /// Headers
31 | ////////////////////////////////////////////////////////////
32 | #include
33 |
34 |
35 | ////////////////////////////////////////////////////////////
36 | /// \file
37 | ///
38 | /// \brief File containing SFML_DEFINE_DISCRETE_GPU_PREFERENCE
39 | ///
40 | ////////////////////////////////////////////////////////////
41 |
42 |
43 | ////////////////////////////////////////////////////////////
44 | /// \def SFML_DEFINE_DISCRETE_GPU_PREFERENCE
45 | ///
46 | /// \brief A macro to encourage usage of the discrete GPU
47 | ///
48 | /// In order to inform the Nvidia/AMD driver that an SFML
49 | /// application could benefit from using the more powerful
50 | /// discrete GPU, special symbols have to be publicly
51 | /// exported from the final executable.
52 | ///
53 | /// SFML defines a helper macro to easily do this.
54 | ///
55 | /// Place SFML_DEFINE_DISCRETE_GPU_PREFERENCE in the
56 | /// global scope of a source file that will be linked into
57 | /// the final executable. Typically it is best to place it
58 | /// where the main function is also defined.
59 | ///
60 | ////////////////////////////////////////////////////////////
61 | #if defined(SFML_SYSTEM_WINDOWS)
62 |
63 | #define SFML_DEFINE_DISCRETE_GPU_PREFERENCE \
64 | extern "C" __declspec(dllexport) unsigned long NvOptimusEnablement = 1; \
65 | extern "C" __declspec(dllexport) unsigned long AmdPowerXpressRequestHighPerformance = 1;
66 |
67 | #else
68 |
69 | #define SFML_DEFINE_DISCRETE_GPU_PREFERENCE
70 |
71 | #endif
72 |
73 |
74 | #endif // SFML_GPUPREFERENCE_HPP
75 |
--------------------------------------------------------------------------------
/include/SFML/Graphics.hpp:
--------------------------------------------------------------------------------
1 | ////////////////////////////////////////////////////////////
2 | //
3 | // SFML - Simple and Fast Multimedia Library
4 | // Copyright (C) 2007-2022 Laurent Gomila (laurent@sfml-dev.org)
5 | //
6 | // This software is provided 'as-is', without any express or implied warranty.
7 | // In no event will the authors be held liable for any damages arising from the use of this software.
8 | //
9 | // Permission is granted to anyone to use this software for any purpose,
10 | // including commercial applications, and to alter it and redistribute it freely,
11 | // subject to the following restrictions:
12 | //
13 | // 1. The origin of this software must not be misrepresented;
14 | // you must not claim that you wrote the original software.
15 | // If you use this software in a product, an acknowledgment
16 | // in the product documentation would be appreciated but is not required.
17 | //
18 | // 2. Altered source versions must be plainly marked as such,
19 | // and must not be misrepresented as being the original software.
20 | //
21 | // 3. This notice may not be removed or altered from any source distribution.
22 | //
23 | ////////////////////////////////////////////////////////////
24 |
25 | #ifndef SFML_GRAPHICS_HPP
26 | #define SFML_GRAPHICS_HPP
27 |
28 | ////////////////////////////////////////////////////////////
29 | // Headers
30 | ////////////////////////////////////////////////////////////
31 |
32 | #include
33 | #include
34 | #include
35 | #include
36 | #include
37 | #include
38 | #include
39 | #include
40 | #include
41 | #include
42 | #include
43 | #include
44 | #include
45 | #include
46 | #include
47 | #include
48 | #include
49 | #include
50 | #include
51 | #include
52 | #include
53 | #include
54 | #include
55 | #include
56 | #include
57 | #include
58 | #include
59 |
60 |
61 | #endif // SFML_GRAPHICS_HPP
62 |
63 | ////////////////////////////////////////////////////////////
64 | /// \defgroup graphics Graphics module
65 | ///
66 | /// 2D graphics module: sprites, text, shapes, ...
67 | ///
68 | ////////////////////////////////////////////////////////////
69 |
--------------------------------------------------------------------------------
/include/SFML/Graphics/CircleShape.hpp:
--------------------------------------------------------------------------------
1 | ////////////////////////////////////////////////////////////
2 | //
3 | // SFML - Simple and Fast Multimedia Library
4 | // Copyright (C) 2007-2022 Laurent Gomila (laurent@sfml-dev.org)
5 | //
6 | // This software is provided 'as-is', without any express or implied warranty.
7 | // In no event will the authors be held liable for any damages arising from the use of this software.
8 | //
9 | // Permission is granted to anyone to use this software for any purpose,
10 | // including commercial applications, and to alter it and redistribute it freely,
11 | // subject to the following restrictions:
12 | //
13 | // 1. The origin of this software must not be misrepresented;
14 | // you must not claim that you wrote the original software.
15 | // If you use this software in a product, an acknowledgment
16 | // in the product documentation would be appreciated but is not required.
17 | //
18 | // 2. Altered source versions must be plainly marked as such,
19 | // and must not be misrepresented as being the original software.
20 | //
21 | // 3. This notice may not be removed or altered from any source distribution.
22 | //
23 | ////////////////////////////////////////////////////////////
24 |
25 | #ifndef SFML_CIRCLESHAPE_HPP
26 | #define SFML_CIRCLESHAPE_HPP
27 |
28 | ////////////////////////////////////////////////////////////
29 | // Headers
30 | ////////////////////////////////////////////////////////////
31 | #include
32 | #include
33 |
34 |
35 | namespace sf
36 | {
37 | ////////////////////////////////////////////////////////////
38 | /// \brief Specialized shape representing a circle
39 | ///
40 | ////////////////////////////////////////////////////////////
41 | class SFML_GRAPHICS_API CircleShape : public Shape
42 | {
43 | public:
44 |
45 | ////////////////////////////////////////////////////////////
46 | /// \brief Default constructor
47 | ///
48 | /// \param radius Radius of the circle
49 | /// \param pointCount Number of points composing the circle
50 | ///
51 | ////////////////////////////////////////////////////////////
52 | explicit CircleShape(float radius = 0, std::size_t pointCount = 30);
53 |
54 | ////////////////////////////////////////////////////////////
55 | /// \brief Set the radius of the circle
56 | ///
57 | /// \param radius New radius of the circle
58 | ///
59 | /// \see getRadius
60 | ///
61 | ////////////////////////////////////////////////////////////
62 | void setRadius(float radius);
63 |
64 | ////////////////////////////////////////////////////////////
65 | /// \brief Get the radius of the circle
66 | ///
67 | /// \return Radius of the circle
68 | ///
69 | /// \see setRadius
70 | ///
71 | ////////////////////////////////////////////////////////////
72 | float getRadius() const;
73 |
74 | ////////////////////////////////////////////////////////////
75 | /// \brief Set the number of points of the circle
76 | ///
77 | /// \param count New number of points of the circle
78 | ///
79 | /// \see getPointCount
80 | ///
81 | ////////////////////////////////////////////////////////////
82 | void setPointCount(std::size_t count);
83 |
84 | ////////////////////////////////////////////////////////////
85 | /// \brief Get the number of points of the circle
86 | ///
87 | /// \return Number of points of the circle
88 | ///
89 | /// \see setPointCount
90 | ///
91 | ////////////////////////////////////////////////////////////
92 | std::size_t getPointCount() const override;
93 |
94 | ////////////////////////////////////////////////////////////
95 | /// \brief Get a point of the circle
96 | ///
97 | /// The returned point is in local coordinates, that is,
98 | /// the shape's transforms (position, rotation, scale) are
99 | /// not taken into account.
100 | /// The result is undefined if \a index is out of the valid range.
101 | ///
102 | /// \param index Index of the point to get, in range [0 .. getPointCount() - 1]
103 | ///
104 | /// \return index-th point of the shape
105 | ///
106 | ////////////////////////////////////////////////////////////
107 | Vector2f getPoint(std::size_t index) const override;
108 |
109 | private:
110 |
111 | ////////////////////////////////////////////////////////////
112 | // Member data
113 | ////////////////////////////////////////////////////////////
114 | float m_radius; //!< Radius of the circle
115 | std::size_t m_pointCount; //!< Number of points composing the circle
116 | };
117 |
118 | } // namespace sf
119 |
120 |
121 | #endif // SFML_CIRCLESHAPE_HPP
122 |
123 |
124 | ////////////////////////////////////////////////////////////
125 | /// \class sf::CircleShape
126 | /// \ingroup graphics
127 | ///
128 | /// This class inherits all the functions of sf::Transformable
129 | /// (position, rotation, scale, bounds, ...) as well as the
130 | /// functions of sf::Shape (outline, color, texture, ...).
131 | ///
132 | /// Usage example:
133 | /// \code
134 | /// sf::CircleShape circle;
135 | /// circle.setRadius(150);
136 | /// circle.setOutlineColor(sf::Color::Red);
137 | /// circle.setOutlineThickness(5);
138 | /// circle.setPosition(10, 20);
139 | /// ...
140 | /// window.draw(circle);
141 | /// \endcode
142 | ///
143 | /// Since the graphics card can't draw perfect circles, we have to
144 | /// fake them with multiple triangles connected to each other. The
145 | /// "points count" property of sf::CircleShape defines how many of these
146 | /// triangles to use, and therefore defines the quality of the circle.
147 | ///
148 | /// The number of points can also be used for another purpose; with
149 | /// small numbers you can create any regular polygon shape:
150 | /// equilateral triangle, square, pentagon, hexagon, ...
151 | ///
152 | /// \see sf::Shape, sf::RectangleShape, sf::ConvexShape
153 | ///
154 | ////////////////////////////////////////////////////////////
155 |
--------------------------------------------------------------------------------
/include/SFML/Graphics/Color.inl:
--------------------------------------------------------------------------------
1 | ////////////////////////////////////////////////////////////
2 | //
3 | // SFML - Simple and Fast Multimedia Library
4 | // Copyright (C) 2007-2022 Laurent Gomila (laurent@sfml-dev.org)
5 | //
6 | // This software is provided 'as-is', without any express or implied warranty.
7 | // In no event will the authors be held liable for any damages arising from the use of this software.
8 | //
9 | // Permission is granted to anyone to use this software for any purpose,
10 | // including commercial applications, and to alter it and redistribute it freely,
11 | // subject to the following restrictions:
12 | //
13 | // 1. The origin of this software must not be misrepresented;
14 | // you must not claim that you wrote the original software.
15 | // If you use this software in a product, an acknowledgment
16 | // in the product documentation would be appreciated but is not required.
17 | //
18 | // 2. Altered source versions must be plainly marked as such,
19 | // and must not be misrepresented as being the original software.
20 | //
21 | // 3. This notice may not be removed or altered from any source distribution.
22 | //
23 | ////////////////////////////////////////////////////////////
24 |
25 |
26 | ////////////////////////////////////////////////////////////
27 | constexpr Color::Color() :
28 | r(0),
29 | g(0),
30 | b(0),
31 | a(255)
32 | {
33 |
34 | }
35 |
36 |
37 | ////////////////////////////////////////////////////////////
38 | constexpr Color::Color(Uint8 red, Uint8 green, Uint8 blue, Uint8 alpha) :
39 | r(red),
40 | g(green),
41 | b(blue),
42 | a(alpha)
43 | {
44 |
45 | }
46 |
47 |
48 | ////////////////////////////////////////////////////////////
49 | constexpr Color::Color(Uint32 color) :
50 | r(static_cast((color & 0xff000000) >> 24)),
51 | g(static_cast((color & 0x00ff0000) >> 16)),
52 | b(static_cast((color & 0x0000ff00) >> 8)),
53 | a(static_cast(color & 0x000000ff))
54 | {
55 |
56 | }
57 |
58 |
59 | ////////////////////////////////////////////////////////////
60 | constexpr Uint32 Color::toInteger() const
61 | {
62 | return static_cast((r << 24) | (g << 16) | (b << 8) | a);
63 | }
64 |
65 |
66 | ////////////////////////////////////////////////////////////
67 | constexpr bool operator ==(const Color& left, const Color& right)
68 | {
69 | return (left.r == right.r) &&
70 | (left.g == right.g) &&
71 | (left.b == right.b) &&
72 | (left.a == right.a);
73 | }
74 |
75 |
76 | ////////////////////////////////////////////////////////////
77 | constexpr bool operator !=(const Color& left, const Color& right)
78 | {
79 | return !(left == right);
80 | }
81 |
82 |
83 | ////////////////////////////////////////////////////////////
84 | constexpr Color operator +(const Color& left, const Color& right)
85 | {
86 | const auto clampedAdd = [](Uint8 lhs, Uint8 rhs) -> Uint8
87 | {
88 | const int intResult = static_cast(lhs) + static_cast(rhs);
89 | return static_cast(intResult < 255 ? intResult : 255);
90 | };
91 |
92 | return Color(clampedAdd(left.r, right.r),
93 | clampedAdd(left.g, right.g),
94 | clampedAdd(left.b, right.b),
95 | clampedAdd(left.a, right.a));
96 | }
97 |
98 |
99 | ////////////////////////////////////////////////////////////
100 | constexpr Color operator -(const Color& left, const Color& right)
101 | {
102 | const auto clampedSub = [](Uint8 lhs, Uint8 rhs) -> Uint8
103 | {
104 | const int intResult = static_cast(lhs) - static_cast(rhs);
105 | return static_cast(intResult > 0 ? intResult : 0);
106 | };
107 |
108 | return Color(clampedSub(left.r, right.r),
109 | clampedSub(left.g, right.g),
110 | clampedSub(left.b, right.b),
111 | clampedSub(left.a, right.a));
112 | }
113 |
114 |
115 | ////////////////////////////////////////////////////////////
116 | constexpr Color operator *(const Color& left, const Color& right)
117 | {
118 | const auto scaledMul = [](Uint8 lhs, Uint8 rhs) -> Uint8
119 | {
120 | const auto uint16Result = static_cast(static_cast(lhs) * static_cast(rhs));
121 | return static_cast(uint16Result / 255u);
122 | };
123 |
124 | return Color(scaledMul(left.r, right.r),
125 | scaledMul(left.g, right.g),
126 | scaledMul(left.b, right.b),
127 | scaledMul(left.a, right.a));
128 | }
129 |
130 |
131 | ////////////////////////////////////////////////////////////
132 | constexpr Color& operator +=(Color& left, const Color& right)
133 | {
134 | return left = left + right;
135 | }
136 |
137 |
138 | ////////////////////////////////////////////////////////////
139 | constexpr Color& operator -=(Color& left, const Color& right)
140 | {
141 | return left = left - right;
142 | }
143 |
144 |
145 | ////////////////////////////////////////////////////////////
146 | constexpr Color& operator *=(Color& left, const Color& right)
147 | {
148 | return left = left * right;
149 | }
150 |
151 |
152 | ////////////////////////////////////////////////////////////
153 | // Static member data
154 | ////////////////////////////////////////////////////////////
155 |
156 | // Note: the 'inline' keyword here is technically not required, but VS2019 fails
157 | // to compile with a bogus "multiple definition" error if not explicitly used.
158 | inline constexpr Color Color::Black(0, 0, 0);
159 | inline constexpr Color Color::White(255, 255, 255);
160 | inline constexpr Color Color::Red(255, 0, 0);
161 | inline constexpr Color Color::Green(0, 255, 0);
162 | inline constexpr Color Color::Blue(0, 0, 255);
163 | inline constexpr Color Color::Yellow(255, 255, 0);
164 | inline constexpr Color Color::Magenta(255, 0, 255);
165 | inline constexpr Color Color::Cyan(0, 255, 255);
166 | inline constexpr Color Color::Transparent(0, 0, 0, 0);
167 |
--------------------------------------------------------------------------------
/include/SFML/Graphics/ConvexShape.hpp:
--------------------------------------------------------------------------------
1 | ////////////////////////////////////////////////////////////
2 | //
3 | // SFML - Simple and Fast Multimedia Library
4 | // Copyright (C) 2007-2022 Laurent Gomila (laurent@sfml-dev.org)
5 | //
6 | // This software is provided 'as-is', without any express or implied warranty.
7 | // In no event will the authors be held liable for any damages arising from the use of this software.
8 | //
9 | // Permission is granted to anyone to use this software for any purpose,
10 | // including commercial applications, and to alter it and redistribute it freely,
11 | // subject to the following restrictions:
12 | //
13 | // 1. The origin of this software must not be misrepresented;
14 | // you must not claim that you wrote the original software.
15 | // If you use this software in a product, an acknowledgment
16 | // in the product documentation would be appreciated but is not required.
17 | //
18 | // 2. Altered source versions must be plainly marked as such,
19 | // and must not be misrepresented as being the original software.
20 | //
21 | // 3. This notice may not be removed or altered from any source distribution.
22 | //
23 | ////////////////////////////////////////////////////////////
24 |
25 | #ifndef SFML_CONVEXSHAPE_HPP
26 | #define SFML_CONVEXSHAPE_HPP
27 |
28 | ////////////////////////////////////////////////////////////
29 | // Headers
30 | ////////////////////////////////////////////////////////////
31 | #include
32 | #include
33 | #include
34 |
35 |
36 | namespace sf
37 | {
38 | ////////////////////////////////////////////////////////////
39 | /// \brief Specialized shape representing a convex polygon
40 | ///
41 | ////////////////////////////////////////////////////////////
42 | class SFML_GRAPHICS_API ConvexShape : public Shape
43 | {
44 | public:
45 |
46 | ////////////////////////////////////////////////////////////
47 | /// \brief Default constructor
48 | ///
49 | /// \param pointCount Number of points of the polygon
50 | ///
51 | ////////////////////////////////////////////////////////////
52 | explicit ConvexShape(std::size_t pointCount = 0);
53 |
54 | ////////////////////////////////////////////////////////////
55 | /// \brief Set the number of points of the polygon
56 | ///
57 | /// \a count must be greater than 2 to define a valid shape.
58 | ///
59 | /// \param count New number of points of the polygon
60 | ///
61 | /// \see getPointCount
62 | ///
63 | ////////////////////////////////////////////////////////////
64 | void setPointCount(std::size_t count);
65 |
66 | ////////////////////////////////////////////////////////////
67 | /// \brief Get the number of points of the polygon
68 | ///
69 | /// \return Number of points of the polygon
70 | ///
71 | /// \see setPointCount
72 | ///
73 | ////////////////////////////////////////////////////////////
74 | std::size_t getPointCount() const override;
75 |
76 | ////////////////////////////////////////////////////////////
77 | /// \brief Set the position of a point
78 | ///
79 | /// Don't forget that the polygon must remain convex, and
80 | /// the points need to stay ordered!
81 | /// setPointCount must be called first in order to set the total
82 | /// number of points. The result is undefined if \a index is out
83 | /// of the valid range.
84 | ///
85 | /// \param index Index of the point to change, in range [0 .. getPointCount() - 1]
86 | /// \param point New position of the point
87 | ///
88 | /// \see getPoint
89 | ///
90 | ////////////////////////////////////////////////////////////
91 | void setPoint(std::size_t index, const Vector2f& point);
92 |
93 | ////////////////////////////////////////////////////////////
94 | /// \brief Get the position of a point
95 | ///
96 | /// The returned point is in local coordinates, that is,
97 | /// the shape's transforms (position, rotation, scale) are
98 | /// not taken into account.
99 | /// The result is undefined if \a index is out of the valid range.
100 | ///
101 | /// \param index Index of the point to get, in range [0 .. getPointCount() - 1]
102 | ///
103 | /// \return Position of the index-th point of the polygon
104 | ///
105 | /// \see setPoint
106 | ///
107 | ////////////////////////////////////////////////////////////
108 | Vector2f getPoint(std::size_t index) const override;
109 |
110 | private:
111 |
112 | ////////////////////////////////////////////////////////////
113 | // Member data
114 | ////////////////////////////////////////////////////////////
115 | std::vector m_points; //!< Points composing the convex polygon
116 | };
117 |
118 | } // namespace sf
119 |
120 |
121 | #endif // SFML_CONVEXSHAPE_HPP
122 |
123 |
124 | ////////////////////////////////////////////////////////////
125 | /// \class sf::ConvexShape
126 | /// \ingroup graphics
127 | ///
128 | /// This class inherits all the functions of sf::Transformable
129 | /// (position, rotation, scale, bounds, ...) as well as the
130 | /// functions of sf::Shape (outline, color, texture, ...).
131 | ///
132 | /// It is important to keep in mind that a convex shape must
133 | /// always be... convex, otherwise it may not be drawn correctly.
134 | /// Moreover, the points must be defined in order; using a random
135 | /// order would result in an incorrect shape.
136 | ///
137 | /// Usage example:
138 | /// \code
139 | /// sf::ConvexShape polygon;
140 | /// polygon.setPointCount(3);
141 | /// polygon.setPoint(0, sf::Vector2f(0, 0));
142 | /// polygon.setPoint(1, sf::Vector2f(0, 10));
143 | /// polygon.setPoint(2, sf::Vector2f(25, 5));
144 | /// polygon.setOutlineColor(sf::Color::Red);
145 | /// polygon.setOutlineThickness(5);
146 | /// polygon.setPosition(10, 20);
147 | /// ...
148 | /// window.draw(polygon);
149 | /// \endcode
150 | ///
151 | /// \see sf::Shape, sf::RectangleShape, sf::CircleShape
152 | ///
153 | ////////////////////////////////////////////////////////////
154 |
--------------------------------------------------------------------------------
/include/SFML/Graphics/Drawable.hpp:
--------------------------------------------------------------------------------
1 | ////////////////////////////////////////////////////////////
2 | //
3 | // SFML - Simple and Fast Multimedia Library
4 | // Copyright (C) 2007-2022 Laurent Gomila (laurent@sfml-dev.org)
5 | //
6 | // This software is provided 'as-is', without any express or implied warranty.
7 | // In no event will the authors be held liable for any damages arising from the use of this software.
8 | //
9 | // Permission is granted to anyone to use this software for any purpose,
10 | // including commercial applications, and to alter it and redistribute it freely,
11 | // subject to the following restrictions:
12 | //
13 | // 1. The origin of this software must not be misrepresented;
14 | // you must not claim that you wrote the original software.
15 | // If you use this software in a product, an acknowledgment
16 | // in the product documentation would be appreciated but is not required.
17 | //
18 | // 2. Altered source versions must be plainly marked as such,
19 | // and must not be misrepresented as being the original software.
20 | //
21 | // 3. This notice may not be removed or altered from any source distribution.
22 | //
23 | ////////////////////////////////////////////////////////////
24 |
25 | #ifndef SFML_DRAWABLE_HPP
26 | #define SFML_DRAWABLE_HPP
27 |
28 | ////////////////////////////////////////////////////////////
29 | // Headers
30 | ////////////////////////////////////////////////////////////
31 | #include
32 |
33 |
34 | namespace sf
35 | {
36 | class RenderTarget;
37 | class RenderStates;
38 |
39 | ////////////////////////////////////////////////////////////
40 | /// \brief Abstract base class for objects that can be drawn
41 | /// to a render target
42 | ///
43 | ////////////////////////////////////////////////////////////
44 | class SFML_GRAPHICS_API Drawable
45 | {
46 | public:
47 |
48 | ////////////////////////////////////////////////////////////
49 | /// \brief Virtual destructor
50 | ///
51 | ////////////////////////////////////////////////////////////
52 | virtual ~Drawable() {}
53 |
54 | protected:
55 |
56 | friend class RenderTarget;
57 |
58 | ////////////////////////////////////////////////////////////
59 | /// \brief Draw the object to a render target
60 | ///
61 | /// This is a pure virtual function that has to be implemented
62 | /// by the derived class to define how the drawable should be
63 | /// drawn.
64 | ///
65 | /// \param target Render target to draw to
66 | /// \param states Current render states
67 | ///
68 | ////////////////////////////////////////////////////////////
69 | virtual void draw(RenderTarget& target, const RenderStates& states) const = 0;
70 | };
71 |
72 | } // namespace sf
73 |
74 |
75 | #endif // SFML_DRAWABLE_HPP
76 |
77 |
78 | ////////////////////////////////////////////////////////////
79 | /// \class sf::Drawable
80 | /// \ingroup graphics
81 | ///
82 | /// sf::Drawable is a very simple base class that allows objects
83 | /// of derived classes to be drawn to a sf::RenderTarget.
84 | ///
85 | /// All you have to do in your derived class is to override the
86 | /// draw virtual function.
87 | ///
88 | /// Note that inheriting from sf::Drawable is not mandatory,
89 | /// but it allows this nice syntax "window.draw(object)" rather
90 | /// than "object.draw(window)", which is more consistent with other
91 | /// SFML classes.
92 | ///
93 | /// Example:
94 | /// \code
95 | /// class MyDrawable : public sf::Drawable
96 | /// {
97 | /// public:
98 | ///
99 | /// ...
100 | ///
101 | /// private:
102 | ///
103 | /// void draw(sf::RenderTarget& target, const sf::RenderStates& states) const override
104 | /// {
105 | /// // You can draw other high-level objects
106 | /// target.draw(m_sprite, states);
107 | ///
108 | /// // ... or use the low-level API
109 | /// sf::RenderStates statesCopy(states);
110 | /// statesCopy.texture = &m_texture;
111 | /// target.draw(m_vertices, statesCopy);
112 | ///
113 | /// // ... or draw with OpenGL directly
114 | /// glBegin(GL_TRIANGLES);
115 | /// ...
116 | /// glEnd();
117 | /// }
118 | ///
119 | /// sf::Sprite m_sprite;
120 | /// sf::Texture m_texture;
121 | /// sf::VertexArray m_vertices;
122 | /// };
123 | /// \endcode
124 | ///
125 | /// \see sf::RenderTarget
126 | ///
127 | ////////////////////////////////////////////////////////////
128 |
--------------------------------------------------------------------------------
/include/SFML/Graphics/Export.hpp:
--------------------------------------------------------------------------------
1 | ////////////////////////////////////////////////////////////
2 | //
3 | // SFML - Simple and Fast Multimedia Library
4 | // Copyright (C) 2007-2022 Laurent Gomila (laurent@sfml-dev.org)
5 | //
6 | // This software is provided 'as-is', without any express or implied warranty.
7 | // In no event will the authors be held liable for any damages arising from the use of this software.
8 | //
9 | // Permission is granted to anyone to use this software for any purpose,
10 | // including commercial applications, and to alter it and redistribute it freely,
11 | // subject to the following restrictions:
12 | //
13 | // 1. The origin of this software must not be misrepresented;
14 | // you must not claim that you wrote the original software.
15 | // If you use this software in a product, an acknowledgment
16 | // in the product documentation would be appreciated but is not required.
17 | //
18 | // 2. Altered source versions must be plainly marked as such,
19 | // and must not be misrepresented as being the original software.
20 | //
21 | // 3. This notice may not be removed or altered from any source distribution.
22 | //
23 | ////////////////////////////////////////////////////////////
24 |
25 | #ifndef SFML_GRAPHICS_EXPORT_HPP
26 | #define SFML_GRAPHICS_EXPORT_HPP
27 |
28 | ////////////////////////////////////////////////////////////
29 | // Headers
30 | ////////////////////////////////////////////////////////////
31 | #include
32 |
33 |
34 | ////////////////////////////////////////////////////////////
35 | // Define portable import / export macros
36 | ////////////////////////////////////////////////////////////
37 | #if defined(SFML_GRAPHICS_EXPORTS)
38 |
39 | #define SFML_GRAPHICS_API SFML_API_EXPORT
40 |
41 | #else
42 |
43 | #define SFML_GRAPHICS_API SFML_API_IMPORT
44 |
45 | #endif
46 |
47 |
48 | #endif // SFML_GRAPHICS_EXPORT_HPP
49 |
--------------------------------------------------------------------------------
/include/SFML/Graphics/Glsl.inl:
--------------------------------------------------------------------------------
1 | ////////////////////////////////////////////////////////////
2 | //
3 | // SFML - Simple and Fast Multimedia Library
4 | // Copyright (C) 2007-2022 Laurent Gomila (laurent@sfml-dev.org)
5 | //
6 | // This software is provided 'as-is', without any express or implied warranty.
7 | // In no event will the authors be held liable for any damages arising from the use of this software.
8 | //
9 | // Permission is granted to anyone to use this software for any purpose,
10 | // including commercial applications, and to alter it and redistribute it freely,
11 | // subject to the following restrictions:
12 | //
13 | // 1. The origin of this software must not be misrepresented;
14 | // you must not claim that you wrote the original software.
15 | // If you use this software in a product, an acknowledgment
16 | // in the product documentation would be appreciated but is not required.
17 | //
18 | // 2. Altered source versions must be plainly marked as such,
19 | // and must not be misrepresented as being the original software.
20 | //
21 | // 3. This notice may not be removed or altered from any source distribution.
22 | //
23 | ////////////////////////////////////////////////////////////
24 |
25 |
26 | ////////////////////////////////////////////////////////////
27 | /// \brief Helper functions to copy sf::Transform to sf::Glsl::Mat3/4
28 | ///
29 | ////////////////////////////////////////////////////////////
30 | void SFML_GRAPHICS_API copyMatrix(const Transform& source, Matrix<3, 3>& dest);
31 | void SFML_GRAPHICS_API copyMatrix(const Transform& source, Matrix<4, 4>& dest);
32 |
33 | ////////////////////////////////////////////////////////////
34 | /// \brief Copy array-based matrix with given number of elements
35 | ///
36 | /// Indirection to std::copy() to avoid inclusion of
37 | /// and MSVC's annoying 4996 warning in header
38 | ///
39 | ////////////////////////////////////////////////////////////
40 | void SFML_GRAPHICS_API copyMatrix(const float* source, std::size_t elements, float* dest);
41 |
42 | ////////////////////////////////////////////////////////////
43 | /// \brief Helper functions to copy sf::Color to sf::Glsl::Vec4/Ivec4
44 | ///
45 | ////////////////////////////////////////////////////////////
46 | void SFML_GRAPHICS_API copyVector(const Color& source, Vector4& dest);
47 | void SFML_GRAPHICS_API copyVector(const Color& source, Vector4& dest);
48 |
49 |
50 | ////////////////////////////////////////////////////////////
51 | /// \brief Matrix type, used to set uniforms in GLSL
52 | ///
53 | ////////////////////////////////////////////////////////////
54 | template
55 | struct Matrix
56 | {
57 | ////////////////////////////////////////////////////////////
58 | /// \brief Construct from raw data
59 | ///
60 | /// \param pointer Points to the beginning of an array that
61 | /// has the size of the matrix. The elements
62 | /// are copied to the instance.
63 | ///
64 | ////////////////////////////////////////////////////////////
65 | explicit Matrix(const float* pointer)
66 | {
67 | copyMatrix(pointer, Columns * Rows, array);
68 | }
69 |
70 | ////////////////////////////////////////////////////////////
71 | /// \brief Construct implicitly from SFML transform
72 | ///
73 | /// This constructor is only supported for 3x3 and 4x4
74 | /// matrices.
75 | ///
76 | /// \param transform Object containing a transform.
77 | ///
78 | ////////////////////////////////////////////////////////////
79 | Matrix(const Transform& transform)
80 | {
81 | copyMatrix(transform, *this);
82 | }
83 |
84 | float array[Columns * Rows]; //!< Array holding matrix data
85 | };
86 |
87 | ////////////////////////////////////////////////////////////
88 | /// \brief 4D vector type, used to set uniforms in GLSL
89 | ///
90 | ////////////////////////////////////////////////////////////
91 | template
92 | struct Vector4
93 | {
94 | ////////////////////////////////////////////////////////////
95 | /// \brief Default constructor, creates a zero vector
96 | ///
97 | ////////////////////////////////////////////////////////////
98 | Vector4() :
99 | x(0),
100 | y(0),
101 | z(0),
102 | w(0)
103 | {
104 | }
105 |
106 | ////////////////////////////////////////////////////////////
107 | /// \brief Construct from 4 vector components
108 | ///
109 | /// \param X Component of the 4D vector
110 | /// \param Y Component of the 4D vector
111 | /// \param Z Component of the 4D vector
112 | /// \param W Component of the 4D vector
113 | ///
114 | ////////////////////////////////////////////////////////////
115 | Vector4(T X, T Y, T Z, T W) :
116 | x(X),
117 | y(Y),
118 | z(Z),
119 | w(W)
120 | {
121 | }
122 |
123 | ////////////////////////////////////////////////////////////
124 | /// \brief Conversion constructor
125 | ///
126 | /// \param other 4D vector of different type
127 | ///
128 | ////////////////////////////////////////////////////////////
129 | template
130 | explicit Vector4(const Vector4& other) :
131 | x(static_cast(other.x)),
132 | y(static_cast(other.y)),
133 | z(static_cast(other.z)),
134 | w(static_cast(other.w))
135 | {
136 | }
137 |
138 | ////////////////////////////////////////////////////////////
139 | /// \brief Construct float vector implicitly from color
140 | ///
141 | /// \param color Color instance. Is normalized to [0, 1]
142 | /// for floats, and left as-is for ints.
143 | ///
144 | ////////////////////////////////////////////////////////////
145 | Vector4(const Color& color)
146 | // uninitialized
147 | {
148 | copyVector(color, *this);
149 | }
150 |
151 | T x; //!< 1st component (X) of the 4D vector
152 | T y; //!< 2nd component (Y) of the 4D vector
153 | T z; //!< 3rd component (Z) of the 4D vector
154 | T w; //!< 4th component (W) of the 4D vector
155 | };
156 |
--------------------------------------------------------------------------------
/include/SFML/Graphics/Glyph.hpp:
--------------------------------------------------------------------------------
1 | ////////////////////////////////////////////////////////////
2 | //
3 | // SFML - Simple and Fast Multimedia Library
4 | // Copyright (C) 2007-2022 Laurent Gomila (laurent@sfml-dev.org)
5 | //
6 | // This software is provided 'as-is', without any express or implied warranty.
7 | // In no event will the authors be held liable for any damages arising from the use of this software.
8 | //
9 | // Permission is granted to anyone to use this software for any purpose,
10 | // including commercial applications, and to alter it and redistribute it freely,
11 | // subject to the following restrictions:
12 | //
13 | // 1. The origin of this software must not be misrepresented;
14 | // you must not claim that you wrote the original software.
15 | // If you use this software in a product, an acknowledgment
16 | // in the product documentation would be appreciated but is not required.
17 | //
18 | // 2. Altered source versions must be plainly marked as such,
19 | // and must not be misrepresented as being the original software.
20 | //
21 | // 3. This notice may not be removed or altered from any source distribution.
22 | //
23 | ////////////////////////////////////////////////////////////
24 |
25 | #ifndef SFML_GLYPH_HPP
26 | #define SFML_GLYPH_HPP
27 |
28 | ////////////////////////////////////////////////////////////
29 | // Headers
30 | ////////////////////////////////////////////////////////////
31 | #include
32 | #include
33 |
34 |
35 | namespace sf
36 | {
37 | ////////////////////////////////////////////////////////////
38 | /// \brief Structure describing a glyph
39 | ///
40 | ////////////////////////////////////////////////////////////
41 | class SFML_GRAPHICS_API Glyph
42 | {
43 | public:
44 |
45 | ////////////////////////////////////////////////////////////
46 | /// \brief Default constructor
47 | ///
48 | ////////////////////////////////////////////////////////////
49 | Glyph() : advance(0), lsbDelta(0), rsbDelta(0) {}
50 |
51 | ////////////////////////////////////////////////////////////
52 | // Member data
53 | ////////////////////////////////////////////////////////////
54 | float advance; //!< Offset to move horizontally to the next character
55 | int lsbDelta; //!< Left offset after forced autohint. Internally used by getKerning()
56 | int rsbDelta; //!< Right offset after forced autohint. Internally used by getKerning()
57 | FloatRect bounds; //!< Bounding rectangle of the glyph, in coordinates relative to the baseline
58 | IntRect textureRect; //!< Texture coordinates of the glyph inside the font's texture
59 | };
60 |
61 | } // namespace sf
62 |
63 |
64 | #endif // SFML_GLYPH_HPP
65 |
66 |
67 | ////////////////////////////////////////////////////////////
68 | /// \class sf::Glyph
69 | /// \ingroup graphics
70 | ///
71 | /// A glyph is the visual representation of a character.
72 | ///
73 | /// The sf::Glyph structure provides the information needed
74 | /// to handle the glyph:
75 | /// \li its coordinates in the font's texture
76 | /// \li its bounding rectangle
77 | /// \li the offset to apply to get the starting position of the next glyph
78 | ///
79 | /// \see sf::Font
80 | ///
81 | ////////////////////////////////////////////////////////////
82 |
--------------------------------------------------------------------------------
/include/SFML/Graphics/PrimitiveType.hpp:
--------------------------------------------------------------------------------
1 | ////////////////////////////////////////////////////////////
2 | //
3 | // SFML - Simple and Fast Multimedia Library
4 | // Copyright (C) 2007-2022 Laurent Gomila (laurent@sfml-dev.org)
5 | //
6 | // This software is provided 'as-is', without any express or implied warranty.
7 | // In no event will the authors be held liable for any damages arising from the use of this software.
8 | //
9 | // Permission is granted to anyone to use this software for any purpose,
10 | // including commercial applications, and to alter it and redistribute it freely,
11 | // subject to the following restrictions:
12 | //
13 | // 1. The origin of this software must not be misrepresented;
14 | // you must not claim that you wrote the original software.
15 | // If you use this software in a product, an acknowledgment
16 | // in the product documentation would be appreciated but is not required.
17 | //
18 | // 2. Altered source versions must be plainly marked as such,
19 | // and must not be misrepresented as being the original software.
20 | //
21 | // 3. This notice may not be removed or altered from any source distribution.
22 | //
23 | ////////////////////////////////////////////////////////////
24 |
25 | #ifndef SFML_PRIMITIVETYPE_HPP
26 | #define SFML_PRIMITIVETYPE_HPP
27 |
28 | namespace sf
29 | {
30 | ////////////////////////////////////////////////////////////
31 | /// \ingroup graphics
32 | /// \brief Types of primitives that a sf::VertexArray can render
33 | ///
34 | /// Points and lines have no area, therefore their thickness
35 | /// will always be 1 pixel, regardless the current transform
36 | /// and view.
37 | ///
38 | ////////////////////////////////////////////////////////////
39 | enum PrimitiveType
40 | {
41 | Points, //!< List of individual points
42 | Lines, //!< List of individual lines
43 | LineStrip, //!< List of connected lines, a point uses the previous point to form a line
44 | Triangles, //!< List of individual triangles
45 | TriangleStrip, //!< List of connected triangles, a point uses the two previous points to form a triangle
46 | TriangleFan //!< List of connected triangles, a point uses the common center and the previous point to form a triangle
47 | };
48 |
49 | } // namespace sf
50 |
51 |
52 | #endif // SFML_PRIMITIVETYPE_HPP
53 |
--------------------------------------------------------------------------------
/include/SFML/Graphics/Rect.inl:
--------------------------------------------------------------------------------
1 | ////////////////////////////////////////////////////////////
2 | //
3 | // SFML - Simple and Fast Multimedia Library
4 | // Copyright (C) 2007-2022 Laurent Gomila (laurent@sfml-dev.org)
5 | //
6 | // This software is provided 'as-is', without any express or implied warranty.
7 | // In no event will the authors be held liable for any damages arising from the use of this software.
8 | //
9 | // Permission is granted to anyone to use this software for any purpose,
10 | // including commercial applications, and to alter it and redistribute it freely,
11 | // subject to the following restrictions:
12 | //
13 | // 1. The origin of this software must not be misrepresented;
14 | // you must not claim that you wrote the original software.
15 | // If you use this software in a product, an acknowledgment
16 | // in the product documentation would be appreciated but is not required.
17 | //
18 | // 2. Altered source versions must be plainly marked as such,
19 | // and must not be misrepresented as being the original software.
20 | //
21 | // 3. This notice may not be removed or altered from any source distribution.
22 | //
23 | ////////////////////////////////////////////////////////////
24 |
25 |
26 | ////////////////////////////////////////////////////////////
27 | template
28 | constexpr Rect::Rect() :
29 | left (0),
30 | top (0),
31 | width (0),
32 | height(0)
33 | {
34 |
35 | }
36 |
37 |
38 | ////////////////////////////////////////////////////////////
39 | template
40 | constexpr Rect::Rect(const Vector2& position, const Vector2& size) :
41 | left (position.x),
42 | top (position.y),
43 | width (size.x),
44 | height(size.y)
45 | {
46 |
47 | }
48 |
49 |
50 | ////////////////////////////////////////////////////////////
51 | template
52 | template
53 | constexpr Rect::Rect(const Rect& rectangle) :
54 | left (static_cast(rectangle.left)),
55 | top (static_cast(rectangle.top)),
56 | width (static_cast(rectangle.width)),
57 | height(static_cast(rectangle.height))
58 | {
59 | }
60 |
61 |
62 | ////////////////////////////////////////////////////////////
63 | template
64 | constexpr bool Rect::contains(const Vector2& point) const
65 | {
66 | // Not using 'std::min' and 'std::max' to avoid depending on ''
67 | const auto min = [](T a, T b){ return (a < b) ? a : b; };
68 | const auto max = [](T a, T b){ return (a < b) ? b : a; };
69 |
70 | // Rectangles with negative dimensions are allowed, so we must handle them correctly
71 |
72 | // Compute the real min and max of the rectangle on both axes
73 | const T minX = min(left, static_cast(left + width));
74 | const T maxX = max(left, static_cast(left + width));
75 | const T minY = min(top, static_cast(top + height));
76 | const T maxY = max(top, static_cast(top + height));
77 |
78 | return (point.x >= minX) && (point.x < maxX) && (point.y >= minY) && (point.y < maxY);
79 | }
80 |
81 |
82 | ////////////////////////////////////////////////////////////
83 | template
84 | constexpr std::optional> Rect::findIntersection(const Rect& rectangle) const
85 | {
86 | // Not using 'std::min' and 'std::max' to avoid depending on ''
87 | const auto min = [](T a, T b){ return (a < b) ? a : b; };
88 | const auto max = [](T a, T b){ return (a < b) ? b : a; };
89 |
90 | // Rectangles with negative dimensions are allowed, so we must handle them correctly
91 |
92 | // Compute the min and max of the first rectangle on both axes
93 | const T r1MinX = min(left, static_cast(left + width));
94 | const T r1MaxX = max(left, static_cast(left + width));
95 | const T r1MinY = min(top, static_cast(top + height));
96 | const T r1MaxY = max(top, static_cast(top + height));
97 |
98 | // Compute the min and max of the second rectangle on both axes
99 | const T r2MinX = min(rectangle.left, static_cast(rectangle.left + rectangle.width));
100 | const T r2MaxX = max(rectangle.left, static_cast(rectangle.left + rectangle.width));
101 | const T r2MinY = min(rectangle.top, static_cast(rectangle.top + rectangle.height));
102 | const T r2MaxY = max(rectangle.top, static_cast(rectangle.top + rectangle.height));
103 |
104 | // Compute the intersection boundaries
105 | const T interLeft = max(r1MinX, r2MinX);
106 | const T interTop = max(r1MinY, r2MinY);
107 | const T interRight = min(r1MaxX, r2MaxX);
108 | const T interBottom = min(r1MaxY, r2MaxY);
109 |
110 | // If the intersection is valid (positive non zero area), then there is an intersection
111 | if ((interLeft < interRight) && (interTop < interBottom))
112 | {
113 | return Rect({interLeft, interTop}, {interRight - interLeft, interBottom - interTop});
114 | }
115 | else
116 | {
117 | return std::nullopt;
118 | }
119 | }
120 |
121 |
122 | ////////////////////////////////////////////////////////////
123 | template
124 | constexpr Vector2 Rect::getPosition() const
125 | {
126 | return Vector2(left, top);
127 | }
128 |
129 |
130 | ////////////////////////////////////////////////////////////
131 | template
132 | constexpr Vector2 Rect::getSize() const
133 | {
134 | return Vector2(width, height);
135 | }
136 |
137 |
138 | ////////////////////////////////////////////////////////////
139 | template
140 | constexpr bool operator ==(const Rect& left, const Rect& right)
141 | {
142 | return (left.left == right.left) && (left.width == right.width) &&
143 | (left.top == right.top) && (left.height == right.height);
144 | }
145 |
146 |
147 | ////////////////////////////////////////////////////////////
148 | template
149 | constexpr bool operator !=(const Rect& left, const Rect& right)
150 | {
151 | return !(left == right);
152 | }
153 |
--------------------------------------------------------------------------------
/include/SFML/Graphics/RectangleShape.hpp:
--------------------------------------------------------------------------------
1 | ////////////////////////////////////////////////////////////
2 | //
3 | // SFML - Simple and Fast Multimedia Library
4 | // Copyright (C) 2007-2022 Laurent Gomila (laurent@sfml-dev.org)
5 | //
6 | // This software is provided 'as-is', without any express or implied warranty.
7 | // In no event will the authors be held liable for any damages arising from the use of this software.
8 | //
9 | // Permission is granted to anyone to use this software for any purpose,
10 | // including commercial applications, and to alter it and redistribute it freely,
11 | // subject to the following restrictions:
12 | //
13 | // 1. The origin of this software must not be misrepresented;
14 | // you must not claim that you wrote the original software.
15 | // If you use this software in a product, an acknowledgment
16 | // in the product documentation would be appreciated but is not required.
17 | //
18 | // 2. Altered source versions must be plainly marked as such,
19 | // and must not be misrepresented as being the original software.
20 | //
21 | // 3. This notice may not be removed or altered from any source distribution.
22 | //
23 | ////////////////////////////////////////////////////////////
24 |
25 | #ifndef SFML_RECTANGLESHAPE_HPP
26 | #define SFML_RECTANGLESHAPE_HPP
27 |
28 | ////////////////////////////////////////////////////////////
29 | // Headers
30 | ////////////////////////////////////////////////////////////
31 | #include
32 | #include
33 |
34 |
35 | namespace sf
36 | {
37 | ////////////////////////////////////////////////////////////
38 | /// \brief Specialized shape representing a rectangle
39 | ///
40 | ////////////////////////////////////////////////////////////
41 | class SFML_GRAPHICS_API RectangleShape : public Shape
42 | {
43 | public:
44 |
45 | ////////////////////////////////////////////////////////////
46 | /// \brief Default constructor
47 | ///
48 | /// \param size Size of the rectangle
49 | ///
50 | ////////////////////////////////////////////////////////////
51 | explicit RectangleShape(const Vector2f& size = Vector2f(0, 0));
52 |
53 | ////////////////////////////////////////////////////////////
54 | /// \brief Set the size of the rectangle
55 | ///
56 | /// \param size New size of the rectangle
57 | ///
58 | /// \see getSize
59 | ///
60 | ////////////////////////////////////////////////////////////
61 | void setSize(const Vector2f& size);
62 |
63 | ////////////////////////////////////////////////////////////
64 | /// \brief Get the size of the rectangle
65 | ///
66 | /// \return Size of the rectangle
67 | ///
68 | /// \see setSize
69 | ///
70 | ////////////////////////////////////////////////////////////
71 | const Vector2f& getSize() const;
72 |
73 | ////////////////////////////////////////////////////////////
74 | /// \brief Get the number of points defining the shape
75 | ///
76 | /// \return Number of points of the shape. For rectangle
77 | /// shapes, this number is always 4.
78 | ///
79 | ////////////////////////////////////////////////////////////
80 | std::size_t getPointCount() const override;
81 |
82 | ////////////////////////////////////////////////////////////
83 | /// \brief Get a point of the rectangle
84 | ///
85 | /// The returned point is in local coordinates, that is,
86 | /// the shape's transforms (position, rotation, scale) are
87 | /// not taken into account.
88 | /// The result is undefined if \a index is out of the valid range.
89 | ///
90 | /// \param index Index of the point to get, in range [0 .. 3]
91 | ///
92 | /// \return index-th point of the shape
93 | ///
94 | ////////////////////////////////////////////////////////////
95 | Vector2f getPoint(std::size_t index) const override;
96 |
97 | private:
98 |
99 | ////////////////////////////////////////////////////////////
100 | // Member data
101 | ////////////////////////////////////////////////////////////
102 | Vector2f m_size; //!< Size of the rectangle
103 | };
104 |
105 | } // namespace sf
106 |
107 |
108 | #endif // SFML_RECTANGLESHAPE_HPP
109 |
110 |
111 | ////////////////////////////////////////////////////////////
112 | /// \class sf::RectangleShape
113 | /// \ingroup graphics
114 | ///
115 | /// This class inherits all the functions of sf::Transformable
116 | /// (position, rotation, scale, bounds, ...) as well as the
117 | /// functions of sf::Shape (outline, color, texture, ...).
118 | ///
119 | /// Usage example:
120 | /// \code
121 | /// sf::RectangleShape rectangle;
122 | /// rectangle.setSize(sf::Vector2f(100, 50));
123 | /// rectangle.setOutlineColor(sf::Color::Red);
124 | /// rectangle.setOutlineThickness(5);
125 | /// rectangle.setPosition(10, 20);
126 | /// ...
127 | /// window.draw(rectangle);
128 | /// \endcode
129 | ///
130 | /// \see sf::Shape, sf::CircleShape, sf::ConvexShape
131 | ///
132 | ////////////////////////////////////////////////////////////
133 |
--------------------------------------------------------------------------------
/include/SFML/Graphics/Vertex.hpp:
--------------------------------------------------------------------------------
1 | ////////////////////////////////////////////////////////////
2 | //
3 | // SFML - Simple and Fast Multimedia Library
4 | // Copyright (C) 2007-2022 Laurent Gomila (laurent@sfml-dev.org)
5 | //
6 | // This software is provided 'as-is', without any express or implied warranty.
7 | // In no event will the authors be held liable for any damages arising from the use of this software.
8 | //
9 | // Permission is granted to anyone to use this software for any purpose,
10 | // including commercial applications, and to alter it and redistribute it freely,
11 | // subject to the following restrictions:
12 | //
13 | // 1. The origin of this software must not be misrepresented;
14 | // you must not claim that you wrote the original software.
15 | // If you use this software in a product, an acknowledgment
16 | // in the product documentation would be appreciated but is not required.
17 | //
18 | // 2. Altered source versions must be plainly marked as such,
19 | // and must not be misrepresented as being the original software.
20 | //
21 | // 3. This notice may not be removed or altered from any source distribution.
22 | //
23 | ////////////////////////////////////////////////////////////
24 |
25 | #ifndef SFML_VERTEX_HPP
26 | #define SFML_VERTEX_HPP
27 |
28 | ////////////////////////////////////////////////////////////
29 | // Headers
30 | ////////////////////////////////////////////////////////////
31 | #include
32 | #include
33 |
34 |
35 | namespace sf
36 | {
37 | ////////////////////////////////////////////////////////////
38 | /// \brief Define a point with color and texture coordinates
39 | ///
40 | ////////////////////////////////////////////////////////////
41 | class Vertex
42 | {
43 | public:
44 |
45 | ////////////////////////////////////////////////////////////
46 | /// \brief Default constructor
47 | ///
48 | ////////////////////////////////////////////////////////////
49 | constexpr Vertex();
50 |
51 | ////////////////////////////////////////////////////////////
52 | /// \brief Construct the vertex from its position
53 | ///
54 | /// The vertex color is white and texture coordinates are (0, 0).
55 | ///
56 | /// \param thePosition Vertex position
57 | ///
58 | ////////////////////////////////////////////////////////////
59 | constexpr Vertex(const Vector2f& thePosition);
60 |
61 | ////////////////////////////////////////////////////////////
62 | /// \brief Construct the vertex from its position and color
63 | ///
64 | /// The texture coordinates are (0, 0).
65 | ///
66 | /// \param thePosition Vertex position
67 | /// \param theColor Vertex color
68 | ///
69 | ////////////////////////////////////////////////////////////
70 | constexpr Vertex(const Vector2f& thePosition, const Color& theColor);
71 |
72 | ////////////////////////////////////////////////////////////
73 | /// \brief Construct the vertex from its position and texture coordinates
74 | ///
75 | /// The vertex color is white.
76 | ///
77 | /// \param thePosition Vertex position
78 | /// \param theTexCoords Vertex texture coordinates
79 | ///
80 | ////////////////////////////////////////////////////////////
81 | constexpr Vertex(const Vector2f& thePosition, const Vector2f& theTexCoords);
82 |
83 | ////////////////////////////////////////////////////////////
84 | /// \brief Construct the vertex from its position, color and texture coordinates
85 | ///
86 | /// \param thePosition Vertex position
87 | /// \param theColor Vertex color
88 | /// \param theTexCoords Vertex texture coordinates
89 | ///
90 | ////////////////////////////////////////////////////////////
91 | constexpr Vertex(const Vector2f& thePosition, const Color& theColor, const Vector2f& theTexCoords);
92 |
93 | ////////////////////////////////////////////////////////////
94 | // Member data
95 | ////////////////////////////////////////////////////////////
96 | Vector2f position; //!< 2D position of the vertex
97 | Color color; //!< Color of the vertex
98 | Vector2f texCoords; //!< Coordinates of the texture's pixel to map to the vertex
99 | };
100 |
101 | #include
102 |
103 | } // namespace sf
104 |
105 |
106 | #endif // SFML_VERTEX_HPP
107 |
108 |
109 | ////////////////////////////////////////////////////////////
110 | /// \class sf::Vertex
111 | /// \ingroup graphics
112 | ///
113 | /// A vertex is an improved point. It has a position and other
114 | /// extra attributes that will be used for drawing: in SFML,
115 | /// vertices also have a color and a pair of texture coordinates.
116 | ///
117 | /// The vertex is the building block of drawing. Everything which
118 | /// is visible on screen is made of vertices. They are grouped
119 | /// as 2D primitives (lines, triangles, ...), and these primitives
120 | /// are grouped to create even more complex 2D entities such as
121 | /// sprites, texts, etc.
122 | ///
123 | /// If you use the graphical entities of SFML (sprite, text, shape)
124 | /// you won't have to deal with vertices directly. But if you want
125 | /// to define your own 2D entities, such as tiled maps or particle
126 | /// systems, using vertices will allow you to get maximum performances.
127 | ///
128 | /// Example:
129 | /// \code
130 | /// // define a 100x100 square, red, with a 10x10 texture mapped on it
131 | /// sf::Vertex vertices[] =
132 | /// {
133 | /// sf::Vertex(sf::Vector2f( 0, 0), sf::Color::Red, sf::Vector2f( 0, 0)),
134 | /// sf::Vertex(sf::Vector2f( 0, 100), sf::Color::Red, sf::Vector2f( 0, 10)),
135 | /// sf::Vertex(sf::Vector2f(100, 100), sf::Color::Red, sf::Vector2f(10, 10)),
136 | /// sf::Vertex(sf::Vector2f( 0, 0), sf::Color::Red, sf::Vector2f( 0, 0)),
137 | /// sf::Vertex(sf::Vector2f(100, 100), sf::Color::Red, sf::Vector2f(10, 10)),
138 | /// sf::Vertex(sf::Vector2f(100, 0), sf::Color::Red, sf::Vector2f(10, 0))
139 | /// };
140 | ///
141 | /// // draw it
142 | /// window.draw(vertices, 6, sf::Triangles);
143 | /// \endcode
144 | ///
145 | /// Note: although texture coordinates are supposed to be an integer
146 | /// amount of pixels, their type is float because of some buggy graphics
147 | /// drivers that are not able to process integer coordinates correctly.
148 | ///
149 | /// \see sf::VertexArray
150 | ///
151 | ////////////////////////////////////////////////////////////
152 |
--------------------------------------------------------------------------------
/include/SFML/Graphics/Vertex.inl:
--------------------------------------------------------------------------------
1 | ////////////////////////////////////////////////////////////
2 | //
3 | // SFML - Simple and Fast Multimedia Library
4 | // Copyright (C) 2007-2022 Laurent Gomila (laurent@sfml-dev.org)
5 | //
6 | // This software is provided 'as-is', without any express or implied warranty.
7 | // In no event will the authors be held liable for any damages arising from the use of this software.
8 | //
9 | // Permission is granted to anyone to use this software for any purpose,
10 | // including commercial applications, and to alter it and redistribute it freely,
11 | // subject to the following restrictions:
12 | //
13 | // 1. The origin of this software must not be misrepresented;
14 | // you must not claim that you wrote the original software.
15 | // If you use this software in a product, an acknowledgment
16 | // in the product documentation would be appreciated but is not required.
17 | //
18 | // 2. Altered source versions must be plainly marked as such,
19 | // and must not be misrepresented as being the original software.
20 | //
21 | // 3. This notice may not be removed or altered from any source distribution.
22 | //
23 | ////////////////////////////////////////////////////////////
24 |
25 |
26 | ////////////////////////////////////////////////////////////
27 | constexpr Vertex::Vertex() :
28 | position (0, 0),
29 | color (255, 255, 255),
30 | texCoords(0, 0)
31 | {
32 | }
33 |
34 |
35 | ////////////////////////////////////////////////////////////
36 | constexpr Vertex::Vertex(const Vector2f& thePosition) :
37 | position (thePosition),
38 | color (255, 255, 255),
39 | texCoords(0, 0)
40 | {
41 | }
42 |
43 |
44 | ////////////////////////////////////////////////////////////
45 | constexpr Vertex::Vertex(const Vector2f& thePosition, const Color& theColor) :
46 | position (thePosition),
47 | color (theColor),
48 | texCoords(0, 0)
49 | {
50 | }
51 |
52 |
53 | ////////////////////////////////////////////////////////////
54 | constexpr Vertex::Vertex(const Vector2f& thePosition, const Vector2f& theTexCoords) :
55 | position (thePosition),
56 | color (255, 255, 255),
57 | texCoords(theTexCoords)
58 | {
59 | }
60 |
61 |
62 | ////////////////////////////////////////////////////////////
63 | constexpr Vertex::Vertex(const Vector2f& thePosition, const Color& theColor, const Vector2f& theTexCoords) :
64 | position (thePosition),
65 | color (theColor),
66 | texCoords(theTexCoords)
67 | {
68 | }
69 |
--------------------------------------------------------------------------------
/include/SFML/Main.hpp:
--------------------------------------------------------------------------------
1 | ////////////////////////////////////////////////////////////
2 | //
3 | // SFML - Simple and Fast Multimedia Library
4 | // Copyright (C) 2007-2022 Laurent Gomila (laurent@sfml-dev.org)
5 | //
6 | // This software is provided 'as-is', without any express or implied warranty.
7 | // In no event will the authors be held liable for any damages arising from the use of this software.
8 | //
9 | // Permission is granted to anyone to use this software for any purpose,
10 | // including commercial applications, and to alter it and redistribute it freely,
11 | // subject to the following restrictions:
12 | //
13 | // 1. The origin of this software must not be misrepresented;
14 | // you must not claim that you wrote the original software.
15 | // If you use this software in a product, an acknowledgment
16 | // in the product documentation would be appreciated but is not required.
17 | //
18 | // 2. Altered source versions must be plainly marked as such,
19 | // and must not be misrepresented as being the original software.
20 | //
21 | // 3. This notice may not be removed or altered from any source distribution.
22 | //
23 | ////////////////////////////////////////////////////////////
24 |
25 | #ifndef SFML_MAIN_HPP
26 | #define SFML_MAIN_HPP
27 |
28 | ////////////////////////////////////////////////////////////
29 | // Headers
30 | ////////////////////////////////////////////////////////////
31 | #include
32 |
33 |
34 | #if defined(SFML_SYSTEM_IOS)
35 |
36 | // On iOS, we have no choice but to have our own main,
37 | // so we need to rename the user one and call it later
38 | #define main sfmlMain
39 |
40 | #endif
41 |
42 |
43 | #endif // SFML_MAIN_HPP
44 |
--------------------------------------------------------------------------------
/include/SFML/Network.hpp:
--------------------------------------------------------------------------------
1 | ////////////////////////////////////////////////////////////
2 | //
3 | // SFML - Simple and Fast Multimedia Library
4 | // Copyright (C) 2007-2022 Laurent Gomila (laurent@sfml-dev.org)
5 | //
6 | // This software is provided 'as-is', without any express or implied warranty.
7 | // In no event will the authors be held liable for any damages arising from the use of this software.
8 | //
9 | // Permission is granted to anyone to use this software for any purpose,
10 | // including commercial applications, and to alter it and redistribute it freely,
11 | // subject to the following restrictions:
12 | //
13 | // 1. The origin of this software must not be misrepresented;
14 | // you must not claim that you wrote the original software.
15 | // If you use this software in a product, an acknowledgment
16 | // in the product documentation would be appreciated but is not required.
17 | //
18 | // 2. Altered source versions must be plainly marked as such,
19 | // and must not be misrepresented as being the original software.
20 | //
21 | // 3. This notice may not be removed or altered from any source distribution.
22 | //
23 | ////////////////////////////////////////////////////////////
24 |
25 | #ifndef SFML_NETWORK_HPP
26 | #define SFML_NETWORK_HPP
27 |
28 | ////////////////////////////////////////////////////////////
29 | // Headers
30 | ////////////////////////////////////////////////////////////
31 |
32 | #include
33 | #include
34 | #include
35 | #include
36 | #include
37 | #include
38 | #include
39 | #include
40 | #include
41 | #include
42 | #include
43 |
44 |
45 | #endif // SFML_NETWORK_HPP
46 |
47 | ////////////////////////////////////////////////////////////
48 | /// \defgroup network Network module
49 | ///
50 | /// Socket-based communication, utilities and higher-level
51 | /// network protocols (HTTP, FTP).
52 | ///
53 | ////////////////////////////////////////////////////////////
54 |
--------------------------------------------------------------------------------
/include/SFML/Network/Export.hpp:
--------------------------------------------------------------------------------
1 | ////////////////////////////////////////////////////////////
2 | //
3 | // SFML - Simple and Fast Multimedia Library
4 | // Copyright (C) 2007-2022 Laurent Gomila (laurent@sfml-dev.org)
5 | //
6 | // This software is provided 'as-is', without any express or implied warranty.
7 | // In no event will the authors be held liable for any damages arising from the use of this software.
8 | //
9 | // Permission is granted to anyone to use this software for any purpose,
10 | // including commercial applications, and to alter it and redistribute it freely,
11 | // subject to the following restrictions:
12 | //
13 | // 1. The origin of this software must not be misrepresented;
14 | // you must not claim that you wrote the original software.
15 | // If you use this software in a product, an acknowledgment
16 | // in the product documentation would be appreciated but is not required.
17 | //
18 | // 2. Altered source versions must be plainly marked as such,
19 | // and must not be misrepresented as being the original software.
20 | //
21 | // 3. This notice may not be removed or altered from any source distribution.
22 | //
23 | ////////////////////////////////////////////////////////////
24 |
25 | #ifndef SFML_NETWORK_EXPORT_HPP
26 | #define SFML_NETWORK_EXPORT_HPP
27 |
28 | ////////////////////////////////////////////////////////////
29 | // Headers
30 | ////////////////////////////////////////////////////////////
31 | #include
32 |
33 |
34 | ////////////////////////////////////////////////////////////
35 | // Define portable import / export macros
36 | ////////////////////////////////////////////////////////////
37 | #if defined(SFML_NETWORK_EXPORTS)
38 |
39 | #define SFML_NETWORK_API SFML_API_EXPORT
40 |
41 | #else
42 |
43 | #define SFML_NETWORK_API SFML_API_IMPORT
44 |
45 | #endif
46 |
47 |
48 | #endif // SFML_NETWORK_EXPORT_HPP
49 |
--------------------------------------------------------------------------------
/include/SFML/Network/SocketHandle.hpp:
--------------------------------------------------------------------------------
1 | ////////////////////////////////////////////////////////////
2 | //
3 | // SFML - Simple and Fast Multimedia Library
4 | // Copyright (C) 2007-2022 Laurent Gomila (laurent@sfml-dev.org)
5 | //
6 | // This software is provided 'as-is', without any express or implied warranty.
7 | // In no event will the authors be held liable for any damages arising from the use of this software.
8 | //
9 | // Permission is granted to anyone to use this software for any purpose,
10 | // including commercial applications, and to alter it and redistribute it freely,
11 | // subject to the following restrictions:
12 | //
13 | // 1. The origin of this software must not be misrepresented;
14 | // you must not claim that you wrote the original software.
15 | // If you use this software in a product, an acknowledgment
16 | // in the product documentation would be appreciated but is not required.
17 | //
18 | // 2. Altered source versions must be plainly marked as such,
19 | // and must not be misrepresented as being the original software.
20 | //
21 | // 3. This notice may not be removed or altered from any source distribution.
22 | //
23 | ////////////////////////////////////////////////////////////
24 |
25 | #ifndef SFML_SOCKETHANDLE_HPP
26 | #define SFML_SOCKETHANDLE_HPP
27 |
28 | ////////////////////////////////////////////////////////////
29 | // Headers
30 | ////////////////////////////////////////////////////////////
31 | #include
32 |
33 | #if defined(SFML_SYSTEM_WINDOWS)
34 | #include
35 | #endif
36 |
37 |
38 | namespace sf
39 | {
40 | ////////////////////////////////////////////////////////////
41 | // Define the low-level socket handle type, specific to
42 | // each platform
43 | ////////////////////////////////////////////////////////////
44 | #if defined(SFML_SYSTEM_WINDOWS)
45 |
46 | using SocketHandle = UINT_PTR;
47 |
48 | #else
49 |
50 | using SocketHandle = int;
51 |
52 | #endif
53 |
54 | } // namespace sf
55 |
56 |
57 | #endif // SFML_SOCKETHANDLE_HPP
58 |
--------------------------------------------------------------------------------
/include/SFML/Network/TcpListener.hpp:
--------------------------------------------------------------------------------
1 | ////////////////////////////////////////////////////////////
2 | //
3 | // SFML - Simple and Fast Multimedia Library
4 | // Copyright (C) 2007-2022 Laurent Gomila (laurent@sfml-dev.org)
5 | //
6 | // This software is provided 'as-is', without any express or implied warranty.
7 | // In no event will the authors be held liable for any damages arising from the use of this software.
8 | //
9 | // Permission is granted to anyone to use this software for any purpose,
10 | // including commercial applications, and to alter it and redistribute it freely,
11 | // subject to the following restrictions:
12 | //
13 | // 1. The origin of this software must not be misrepresented;
14 | // you must not claim that you wrote the original software.
15 | // If you use this software in a product, an acknowledgment
16 | // in the product documentation would be appreciated but is not required.
17 | //
18 | // 2. Altered source versions must be plainly marked as such,
19 | // and must not be misrepresented as being the original software.
20 | //
21 | // 3. This notice may not be removed or altered from any source distribution.
22 | //
23 | ////////////////////////////////////////////////////////////
24 |
25 | #ifndef SFML_TCPLISTENER_HPP
26 | #define SFML_TCPLISTENER_HPP
27 |
28 | ////////////////////////////////////////////////////////////
29 | // Headers
30 | ////////////////////////////////////////////////////////////
31 | #include
32 | #include
33 | #include
34 |
35 |
36 | namespace sf
37 | {
38 | class TcpSocket;
39 |
40 | ////////////////////////////////////////////////////////////
41 | /// \brief Socket that listens to new TCP connections
42 | ///
43 | ////////////////////////////////////////////////////////////
44 | class SFML_NETWORK_API TcpListener : public Socket
45 | {
46 | public:
47 |
48 | ////////////////////////////////////////////////////////////
49 | /// \brief Default constructor
50 | ///
51 | ////////////////////////////////////////////////////////////
52 | TcpListener();
53 |
54 | ////////////////////////////////////////////////////////////
55 | /// \brief Get the port to which the socket is bound locally
56 | ///
57 | /// If the socket is not listening to a port, this function
58 | /// returns 0.
59 | ///
60 | /// \return Port to which the socket is bound
61 | ///
62 | /// \see listen
63 | ///
64 | ////////////////////////////////////////////////////////////
65 | unsigned short getLocalPort() const;
66 |
67 | ////////////////////////////////////////////////////////////
68 | /// \brief Start listening for incoming connection attempts
69 | ///
70 | /// This function makes the socket start listening on the
71 | /// specified port, waiting for incoming connection attempts.
72 | ///
73 | /// If the socket is already listening on a port when this
74 | /// function is called, it will stop listening on the old
75 | /// port before starting to listen on the new port.
76 | ///
77 | /// When providing sf::Socket::AnyPort as port, the listener
78 | /// will request an available port from the system.
79 | /// The chosen port can be retrieved by calling getLocalPort().
80 | ///
81 | /// \param port Port to listen on for incoming connection attempts
82 | /// \param address Address of the interface to listen on
83 | ///
84 | /// \return Status code
85 | ///
86 | /// \see accept, close
87 | ///
88 | ////////////////////////////////////////////////////////////
89 | [[nodiscard]] Status listen(unsigned short port, const IpAddress& address = IpAddress::Any);
90 |
91 | ////////////////////////////////////////////////////////////
92 | /// \brief Stop listening and close the socket
93 | ///
94 | /// This function gracefully stops the listener. If the
95 | /// socket is not listening, this function has no effect.
96 | ///
97 | /// \see listen
98 | ///
99 | ////////////////////////////////////////////////////////////
100 | void close();
101 |
102 | ////////////////////////////////////////////////////////////
103 | /// \brief Accept a new connection
104 | ///
105 | /// If the socket is in blocking mode, this function will
106 | /// not return until a connection is actually received.
107 | ///
108 | /// \param socket Socket that will hold the new connection
109 | ///
110 | /// \return Status code
111 | ///
112 | /// \see listen
113 | ///
114 | ////////////////////////////////////////////////////////////
115 | [[nodiscard]] Status accept(TcpSocket& socket);
116 | };
117 |
118 |
119 | } // namespace sf
120 |
121 |
122 | #endif // SFML_TCPLISTENER_HPP
123 |
124 |
125 | ////////////////////////////////////////////////////////////
126 | /// \class sf::TcpListener
127 | /// \ingroup network
128 | ///
129 | /// A listener socket is a special type of socket that listens to
130 | /// a given port and waits for connections on that port.
131 | /// This is all it can do.
132 | ///
133 | /// When a new connection is received, you must call accept and
134 | /// the listener returns a new instance of sf::TcpSocket that
135 | /// is properly initialized and can be used to communicate with
136 | /// the new client.
137 | ///
138 | /// Listener sockets are specific to the TCP protocol,
139 | /// UDP sockets are connectionless and can therefore communicate
140 | /// directly. As a consequence, a listener socket will always
141 | /// return the new connections as sf::TcpSocket instances.
142 | ///
143 | /// A listener is automatically closed on destruction, like all
144 | /// other types of socket. However if you want to stop listening
145 | /// before the socket is destroyed, you can call its close()
146 | /// function.
147 | ///
148 | /// Usage example:
149 | /// \code
150 | /// // Create a listener socket and make it wait for new
151 | /// // connections on port 55001
152 | /// sf::TcpListener listener;
153 | /// listener.listen(55001);
154 | ///
155 | /// // Endless loop that waits for new connections
156 | /// while (running)
157 | /// {
158 | /// sf::TcpSocket client;
159 | /// if (listener.accept(client) == sf::Socket::Done)
160 | /// {
161 | /// // A new client just connected!
162 | /// std::cout << "New connection received from " << client.getRemoteAddress() << std::endl;
163 | /// doSomethingWith(client);
164 | /// }
165 | /// }
166 | /// \endcode
167 | ///
168 | /// \see sf::TcpSocket, sf::Socket
169 | ///
170 | ////////////////////////////////////////////////////////////
171 |
--------------------------------------------------------------------------------
/include/SFML/OpenGL.hpp:
--------------------------------------------------------------------------------
1 | ////////////////////////////////////////////////////////////
2 | //
3 | // SFML - Simple and Fast Multimedia Library
4 | // Copyright (C) 2007-2022 Laurent Gomila (laurent@sfml-dev.org)
5 | //
6 | // This software is provided 'as-is', without any express or implied warranty.
7 | // In no event will the authors be held liable for any damages arising from the use of this software.
8 | //
9 | // Permission is granted to anyone to use this software for any purpose,
10 | // including commercial applications, and to alter it and redistribute it freely,
11 | // subject to the following restrictions:
12 | //
13 | // 1. The origin of this software must not be misrepresented;
14 | // you must not claim that you wrote the original software.
15 | // If you use this software in a product, an acknowledgment
16 | // in the product documentation would be appreciated but is not required.
17 | //
18 | // 2. Altered source versions must be plainly marked as such,
19 | // and must not be misrepresented as being the original software.
20 | //
21 | // 3. This notice may not be removed or altered from any source distribution.
22 | //
23 | ////////////////////////////////////////////////////////////
24 |
25 | #ifndef SFML_OPENGL_HPP
26 | #define SFML_OPENGL_HPP
27 |
28 |
29 | ////////////////////////////////////////////////////////////
30 | /// Headers
31 | ////////////////////////////////////////////////////////////
32 | #include
33 |
34 |
35 | ////////////////////////////////////////////////////////////
36 | /// This file just includes the OpenGL headers,
37 | /// which have actually different paths on each system
38 | ////////////////////////////////////////////////////////////
39 | #if defined(SFML_SYSTEM_WINDOWS)
40 |
41 | // The Visual C++ version of gl.h uses WINGDIAPI and APIENTRY but doesn't define them
42 | #ifdef _MSC_VER
43 | #ifndef WIN32_LEAN_AND_MEAN
44 | #define WIN32_LEAN_AND_MEAN
45 | #endif
46 | #include
47 | #endif
48 |
49 | #include
50 |
51 | #elif defined(SFML_SYSTEM_LINUX) || defined(SFML_SYSTEM_FREEBSD) || defined(SFML_SYSTEM_OPENBSD) || defined(SFML_SYSTEM_NETBSD)
52 |
53 | #if defined(SFML_OPENGL_ES)
54 | #include
55 | #include
56 | #else
57 | #include
58 | #endif
59 |
60 | #elif defined(SFML_SYSTEM_MACOS)
61 |
62 | #include
63 |
64 | #elif defined (SFML_SYSTEM_IOS)
65 |
66 | #include
67 | #include
68 |
69 | #elif defined (SFML_SYSTEM_ANDROID)
70 |
71 | #include
72 | #include
73 |
74 | // We're not using OpenGL ES 2+ yet, but we can use the sRGB extension
75 | #include
76 | #include
77 |
78 | #endif
79 |
80 |
81 | #endif // SFML_OPENGL_HPP
82 |
--------------------------------------------------------------------------------
/include/SFML/System.hpp:
--------------------------------------------------------------------------------
1 | ////////////////////////////////////////////////////////////
2 | //
3 | // SFML - Simple and Fast Multimedia Library
4 | // Copyright (C) 2007-2022 Laurent Gomila (laurent@sfml-dev.org)
5 | //
6 | // This software is provided 'as-is', without any express or implied warranty.
7 | // In no event will the authors be held liable for any damages arising from the use of this software.
8 | //
9 | // Permission is granted to anyone to use this software for any purpose,
10 | // including commercial applications, and to alter it and redistribute it freely,
11 | // subject to the following restrictions:
12 | //
13 | // 1. The origin of this software must not be misrepresented;
14 | // you must not claim that you wrote the original software.
15 | // If you use this software in a product, an acknowledgment
16 | // in the product documentation would be appreciated but is not required.
17 | //
18 | // 2. Altered source versions must be plainly marked as such,
19 | // and must not be misrepresented as being the original software.
20 | //
21 | // 3. This notice may not be removed or altered from any source distribution.
22 | //
23 | ////////////////////////////////////////////////////////////
24 |
25 | #ifndef SFML_SYSTEM_HPP
26 | #define SFML_SYSTEM_HPP
27 |
28 | ////////////////////////////////////////////////////////////
29 | // Headers
30 | ////////////////////////////////////////////////////////////
31 |
32 | #include
33 | #include
34 | #include
35 | #include
36 | #include
37 | #include
38 | #include
39 | #include
40 | #include
41 | #include
42 | #include
43 | #include
44 | #include
45 |
46 | #endif // SFML_SYSTEM_HPP
47 |
48 | ////////////////////////////////////////////////////////////
49 | /// \defgroup system System module
50 | ///
51 | /// Base module of SFML, defining various utilities. It provides
52 | /// vector classes, Unicode strings and conversion functions,
53 | /// threads and mutexes, timing classes.
54 | ///
55 | ////////////////////////////////////////////////////////////
56 |
--------------------------------------------------------------------------------
/include/SFML/System/Clock.hpp:
--------------------------------------------------------------------------------
1 | ////////////////////////////////////////////////////////////
2 | //
3 | // SFML - Simple and Fast Multimedia Library
4 | // Copyright (C) 2007-2022 Laurent Gomila (laurent@sfml-dev.org)
5 | //
6 | // This software is provided 'as-is', without any express or implied warranty.
7 | // In no event will the authors be held liable for any damages arising from the use of this software.
8 | //
9 | // Permission is granted to anyone to use this software for any purpose,
10 | // including commercial applications, and to alter it and redistribute it freely,
11 | // subject to the following restrictions:
12 | //
13 | // 1. The origin of this software must not be misrepresented;
14 | // you must not claim that you wrote the original software.
15 | // If you use this software in a product, an acknowledgment
16 | // in the product documentation would be appreciated but is not required.
17 | //
18 | // 2. Altered source versions must be plainly marked as such,
19 | // and must not be misrepresented as being the original software.
20 | //
21 | // 3. This notice may not be removed or altered from any source distribution.
22 | //
23 | ////////////////////////////////////////////////////////////
24 |
25 | #ifndef SFML_CLOCK_HPP
26 | #define SFML_CLOCK_HPP
27 |
28 | ////////////////////////////////////////////////////////////
29 | // Headers
30 | ////////////////////////////////////////////////////////////
31 | #include
32 | #include
33 | #include
34 | #include
35 |
36 | #ifdef SFML_SYSTEM_ANDROID
37 | #include
38 | #endif
39 |
40 |
41 | namespace sf
42 | {
43 | namespace priv
44 | {
45 |
46 | ////////////////////////////////////////////////////////////
47 | /// \brief Chooses a monotonic clock of highest resolution
48 | ///
49 | /// The high_resolution_clock is usually an alias for other
50 | /// clocks: steady_clock or system_clock, whichever has a
51 | /// higher precision.
52 | ///
53 | /// sf::Clock, however, is aimed towards monotonic time
54 | /// measurements and so system_clock could never be a choice
55 | /// as its subject to discontinuous jumps in the system time
56 | /// (e.g., if the system administrator manually changes
57 | /// the clock), and by the incremental adjustments performed
58 | /// by `adjtime` and Network Time Protocol. On the other
59 | /// hand, monotonic clocks are unaffected by this behavior.
60 | ///
61 | /// Note: Linux implementation of a monotonic clock that
62 | /// takes sleep time into account is represented by
63 | /// CLOCK_BOOTTIME. Android devices can define the macro:
64 | /// SFML_ANDROID_USE_SUSPEND_AWARE_CLOCK to use a separate
65 | /// implementation of that clock, instead.
66 | ///
67 | /// For more information on Linux clocks visit:
68 | /// https://linux.die.net/man/2/clock_gettime
69 | ///
70 | ////////////////////////////////////////////////////////////
71 | #if defined(SFML_SYSTEM_ANDROID) && defined(SFML_ANDROID_USE_SUSPEND_AWARE_CLOCK)
72 | using MostSuitableClock = SuspendAwareClock;
73 | #else
74 | using MostSuitableClock = std::conditional_t<
75 | std::chrono::high_resolution_clock::is_steady,
76 | std::chrono::high_resolution_clock,
77 | std::chrono::steady_clock>;
78 | #endif
79 |
80 | } // namespace priv
81 |
82 | class Time;
83 |
84 | ////////////////////////////////////////////////////////////
85 | /// \brief Utility class that measures the elapsed time
86 | ///
87 | ////////////////////////////////////////////////////////////
88 | class SFML_SYSTEM_API Clock
89 | {
90 | public:
91 |
92 | ////////////////////////////////////////////////////////////
93 | /// \brief Default constructor
94 | ///
95 | /// The clock starts automatically after being constructed.
96 | ///
97 | ////////////////////////////////////////////////////////////
98 | Clock();
99 |
100 | ////////////////////////////////////////////////////////////
101 | /// \brief Get the elapsed time
102 | ///
103 | /// This function returns the time elapsed since the last call
104 | /// to restart() (or the construction of the instance if restart()
105 | /// has not been called).
106 | ///
107 | /// \return Time elapsed
108 | ///
109 | ////////////////////////////////////////////////////////////
110 | Time getElapsedTime() const;
111 |
112 | ////////////////////////////////////////////////////////////
113 | /// \brief Restart the clock
114 | ///
115 | /// This function puts the time counter back to zero.
116 | /// It also returns the time elapsed since the clock was started.
117 | ///
118 | /// \return Time elapsed
119 | ///
120 | ////////////////////////////////////////////////////////////
121 | Time restart();
122 |
123 | private:
124 | using ClockImpl = priv::MostSuitableClock;
125 |
126 | static_assert(ClockImpl::is_steady,
127 | "Provided implementation is not a monotonic clock");
128 | static_assert(std::ratio_less_equal::value,
129 | "Clock resolution is too low. Expecting at least a microsecond precision");
130 |
131 | ////////////////////////////////////////////////////////////
132 | /// \brief Convert clock duration to Time
133 | ///
134 | /// This function acts as a utility for converting clock
135 | /// duration type instance into sf::Time
136 | ///
137 | /// \return Time instance
138 | ///
139 | ////////////////////////////////////////////////////////////
140 | [[nodiscard]] static Time durationToTime(ClockImpl::duration duration);
141 |
142 | ////////////////////////////////////////////////////////////
143 | // Member data
144 | ////////////////////////////////////////////////////////////
145 | ClockImpl::time_point m_startTime; //!< Time of last reset
146 | };
147 |
148 | } // namespace sf
149 |
150 |
151 | #endif // SFML_CLOCK_HPP
152 |
153 |
154 | ////////////////////////////////////////////////////////////
155 | /// \class sf::Clock
156 | /// \ingroup system
157 | ///
158 | /// sf::Clock is a lightweight class for measuring time.
159 | ///
160 | /// Its provides the most precise time that the underlying
161 | /// OS can achieve (generally microseconds or nanoseconds).
162 | /// It also ensures monotonicity, which means that the returned
163 | /// time can never go backward, even if the system time is
164 | /// changed.
165 | ///
166 | /// Usage example:
167 | /// \code
168 | /// sf::Clock clock;
169 | /// ...
170 | /// Time time1 = clock.getElapsedTime();
171 | /// ...
172 | /// Time time2 = clock.restart();
173 | /// \endcode
174 | ///
175 | /// The sf::Time value returned by the clock can then be
176 | /// converted to a number of seconds, milliseconds or even
177 | /// microseconds.
178 | ///
179 | /// \see sf::Time
180 | ///
181 | ////////////////////////////////////////////////////////////
182 |
--------------------------------------------------------------------------------
/include/SFML/System/Err.hpp:
--------------------------------------------------------------------------------
1 | ////////////////////////////////////////////////////////////
2 | //
3 | // SFML - Simple and Fast Multimedia Library
4 | // Copyright (C) 2007-2022 Laurent Gomila (laurent@sfml-dev.org)
5 | //
6 | // This software is provided 'as-is', without any express or implied warranty.
7 | // In no event will the authors be held liable for any damages arising from the use of this software.
8 | //
9 | // Permission is granted to anyone to use this software for any purpose,
10 | // including commercial applications, and to alter it and redistribute it freely,
11 | // subject to the following restrictions:
12 | //
13 | // 1. The origin of this software must not be misrepresented;
14 | // you must not claim that you wrote the original software.
15 | // If you use this software in a product, an acknowledgment
16 | // in the product documentation would be appreciated but is not required.
17 | //
18 | // 2. Altered source versions must be plainly marked as such,
19 | // and must not be misrepresented as being the original software.
20 | //
21 | // 3. This notice may not be removed or altered from any source distribution.
22 | //
23 | ////////////////////////////////////////////////////////////
24 |
25 | #ifndef SFML_ERR_HPP
26 | #define SFML_ERR_HPP
27 |
28 | ////////////////////////////////////////////////////////////
29 | // Headers
30 | ////////////////////////////////////////////////////////////
31 | #include
32 | #include
33 |
34 |
35 | namespace sf
36 | {
37 | ////////////////////////////////////////////////////////////
38 | /// \brief Standard stream used by SFML to output warnings and errors
39 | ///
40 | ////////////////////////////////////////////////////////////
41 | SFML_SYSTEM_API std::ostream& err();
42 |
43 | } // namespace sf
44 |
45 |
46 | #endif // SFML_ERR_HPP
47 |
48 |
49 | ////////////////////////////////////////////////////////////
50 | /// \fn sf::err
51 | /// \ingroup system
52 | ///
53 | /// By default, sf::err() outputs to the same location as std::cerr,
54 | /// (-> the stderr descriptor) which is the console if there's
55 | /// one available.
56 | ///
57 | /// It is a standard std::ostream instance, so it supports all the
58 | /// insertion operations defined by the STL
59 | /// (operator <<, manipulators, etc.).
60 | ///
61 | /// sf::err() can be redirected to write to another output, independently
62 | /// of std::cerr, by using the rdbuf() function provided by the
63 | /// std::ostream class.
64 | ///
65 | /// Example:
66 | /// \code
67 | /// // Redirect to a file
68 | /// std::ofstream file("sfml-log.txt");
69 | /// std::streambuf* previous = sf::err().rdbuf(file.rdbuf());
70 | ///
71 | /// // Redirect to nothing
72 | /// sf::err().rdbuf(nullptr);
73 | ///
74 | /// // Restore the original output
75 | /// sf::err().rdbuf(previous);
76 | /// \endcode
77 | ///
78 | /// \return Reference to std::ostream representing the SFML error stream
79 | ///
80 | ////////////////////////////////////////////////////////////
81 |
--------------------------------------------------------------------------------
/include/SFML/System/Export.hpp:
--------------------------------------------------------------------------------
1 | ////////////////////////////////////////////////////////////
2 | //
3 | // SFML - Simple and Fast Multimedia Library
4 | // Copyright (C) 2007-2022 Laurent Gomila (laurent@sfml-dev.org)
5 | //
6 | // This software is provided 'as-is', without any express or implied warranty.
7 | // In no event will the authors be held liable for any damages arising from the use of this software.
8 | //
9 | // Permission is granted to anyone to use this software for any purpose,
10 | // including commercial applications, and to alter it and redistribute it freely,
11 | // subject to the following restrictions:
12 | //
13 | // 1. The origin of this software must not be misrepresented;
14 | // you must not claim that you wrote the original software.
15 | // If you use this software in a product, an acknowledgment
16 | // in the product documentation would be appreciated but is not required.
17 | //
18 | // 2. Altered source versions must be plainly marked as such,
19 | // and must not be misrepresented as being the original software.
20 | //
21 | // 3. This notice may not be removed or altered from any source distribution.
22 | //
23 | ////////////////////////////////////////////////////////////
24 |
25 | #ifndef SFML_SYSTEM_EXPORT_HPP
26 | #define SFML_SYSTEM_EXPORT_HPP
27 |
28 | ////////////////////////////////////////////////////////////
29 | // Headers
30 | ////////////////////////////////////////////////////////////
31 | #include
32 |
33 |
34 | ////////////////////////////////////////////////////////////
35 | // Define portable import / export macros
36 | ////////////////////////////////////////////////////////////
37 | #if defined(SFML_SYSTEM_EXPORTS)
38 |
39 | #define SFML_SYSTEM_API SFML_API_EXPORT
40 |
41 | #else
42 |
43 | #define SFML_SYSTEM_API SFML_API_IMPORT
44 |
45 | #endif
46 |
47 |
48 | #endif // SFML_SYSTEM_EXPORT_HPP
49 |
--------------------------------------------------------------------------------
/include/SFML/System/InputStream.hpp:
--------------------------------------------------------------------------------
1 | ////////////////////////////////////////////////////////////
2 | //
3 | // SFML - Simple and Fast Multimedia Library
4 | // Copyright (C) 2007-2022 Laurent Gomila (laurent@sfml-dev.org)
5 | //
6 | // This software is provided 'as-is', without any express or implied warranty.
7 | // In no event will the authors be held liable for any damages arising from the use of this software.
8 | //
9 | // Permission is granted to anyone to use this software for any purpose,
10 | // including commercial applications, and to alter it and redistribute it freely,
11 | // subject to the following restrictions:
12 | //
13 | // 1. The origin of this software must not be misrepresented;
14 | // you must not claim that you wrote the original software.
15 | // If you use this software in a product, an acknowledgment
16 | // in the product documentation would be appreciated but is not required.
17 | //
18 | // 2. Altered source versions must be plainly marked as such,
19 | // and must not be misrepresented as being the original software.
20 | //
21 | // 3. This notice may not be removed or altered from any source distribution.
22 | //
23 | ////////////////////////////////////////////////////////////
24 |
25 | #ifndef SFML_INPUTSTREAM_HPP
26 | #define SFML_INPUTSTREAM_HPP
27 |
28 | ////////////////////////////////////////////////////////////
29 | // Headers
30 | ////////////////////////////////////////////////////////////
31 | #include
32 | #include
33 |
34 |
35 | namespace sf
36 | {
37 | ////////////////////////////////////////////////////////////
38 | /// \brief Abstract class for custom file input streams
39 | ///
40 | ////////////////////////////////////////////////////////////
41 | class SFML_SYSTEM_API InputStream
42 | {
43 | public:
44 |
45 | ////////////////////////////////////////////////////////////
46 | /// \brief Virtual destructor
47 | ///
48 | ////////////////////////////////////////////////////////////
49 | virtual ~InputStream() {}
50 |
51 | ////////////////////////////////////////////////////////////
52 | /// \brief Read data from the stream
53 | ///
54 | /// After reading, the stream's reading position must be
55 | /// advanced by the amount of bytes read.
56 | ///
57 | /// \param data Buffer where to copy the read data
58 | /// \param size Desired number of bytes to read
59 | ///
60 | /// \return The number of bytes actually read, or -1 on error
61 | ///
62 | ////////////////////////////////////////////////////////////
63 | [[nodiscard]] virtual Int64 read(void* data, Int64 size) = 0;
64 |
65 | ////////////////////////////////////////////////////////////
66 | /// \brief Change the current reading position
67 | ///
68 | /// \param position The position to seek to, from the beginning
69 | ///
70 | /// \return The position actually sought to, or -1 on error
71 | ///
72 | ////////////////////////////////////////////////////////////
73 | [[nodiscard]] virtual Int64 seek(Int64 position) = 0;
74 |
75 | ////////////////////////////////////////////////////////////
76 | /// \brief Get the current reading position in the stream
77 | ///
78 | /// \return The current position, or -1 on error.
79 | ///
80 | ////////////////////////////////////////////////////////////
81 | [[nodiscard]] virtual Int64 tell() = 0;
82 |
83 | ////////////////////////////////////////////////////////////
84 | /// \brief Return the size of the stream
85 | ///
86 | /// \return The total number of bytes available in the stream, or -1 on error
87 | ///
88 | ////////////////////////////////////////////////////////////
89 | virtual Int64 getSize() = 0;
90 | };
91 |
92 | } // namespace sf
93 |
94 |
95 | #endif // SFML_INPUTSTREAM_HPP
96 |
97 |
98 | ////////////////////////////////////////////////////////////
99 | /// \class sf::InputStream
100 | /// \ingroup system
101 | ///
102 | /// This class allows users to define their own file input sources
103 | /// from which SFML can load resources.
104 | ///
105 | /// SFML resource classes like sf::Texture and
106 | /// sf::SoundBuffer provide loadFromFile and loadFromMemory functions,
107 | /// which read data from conventional sources. However, if you
108 | /// have data coming from a different source (over a network,
109 | /// embedded, encrypted, compressed, etc) you can derive your
110 | /// own class from sf::InputStream and load SFML resources with
111 | /// their loadFromStream function.
112 | ///
113 | /// Usage example:
114 | /// \code
115 | /// // custom stream class that reads from inside a zip file
116 | /// class ZipStream : public sf::InputStream
117 | /// {
118 | /// public:
119 | ///
120 | /// ZipStream(const std::string& archive);
121 | ///
122 | /// [[nodiscard]] bool open(const std::filesystem::path& filename);
123 | ///
124 | /// [[nodiscard]] Int64 read(void* data, Int64 size);
125 | ///
126 | /// [[nodiscard]] Int64 seek(Int64 position);
127 | ///
128 | /// [[nodiscard]] Int64 tell();
129 | ///
130 | /// Int64 getSize();
131 | ///
132 | /// private:
133 | ///
134 | /// ...
135 | /// };
136 | ///
137 | /// // now you can load textures...
138 | /// sf::Texture texture;
139 | /// ZipStream stream("resources.zip");
140 | ///
141 | /// if (!stream.open("images/img.png"))
142 | /// {
143 | /// // Handle error...
144 | /// }
145 | ///
146 | /// if (!texture.loadFromStream(stream))
147 | /// {
148 | /// // Handle error...
149 | /// }
150 | ///
151 | /// // musics...
152 | /// sf::Music music;
153 | /// ZipStream stream("resources.zip");
154 | ///
155 | /// if (!stream.open("musics/msc.ogg"))
156 | /// {
157 | /// // Handle error...
158 | /// }
159 | ///
160 | /// if (!music.openFromStream(stream))
161 | /// {
162 | /// // Handle error...
163 | /// }
164 | ///
165 | /// // etc.
166 | /// \endcode
167 | ///
168 | ////////////////////////////////////////////////////////////
169 |
--------------------------------------------------------------------------------
/include/SFML/System/MemoryInputStream.hpp:
--------------------------------------------------------------------------------
1 | ////////////////////////////////////////////////////////////
2 | //
3 | // SFML - Simple and Fast Multimedia Library
4 | // Copyright (C) 2007-2022 Laurent Gomila (laurent@sfml-dev.org)
5 | //
6 | // This software is provided 'as-is', without any express or implied warranty.
7 | // In no event will the authors be held liable for any damages arising from the use of this software.
8 | //
9 | // Permission is granted to anyone to use this software for any purpose,
10 | // including commercial applications, and to alter it and redistribute it freely,
11 | // subject to the following restrictions:
12 | //
13 | // 1. The origin of this software must not be misrepresented;
14 | // you must not claim that you wrote the original software.
15 | // If you use this software in a product, an acknowledgment
16 | // in the product documentation would be appreciated but is not required.
17 | //
18 | // 2. Altered source versions must be plainly marked as such,
19 | // and must not be misrepresented as being the original software.
20 | //
21 | // 3. This notice may not be removed or altered from any source distribution.
22 | //
23 | ////////////////////////////////////////////////////////////
24 |
25 | #ifndef SFML_MEMORYINPUTSTREAM_HPP
26 | #define SFML_MEMORYINPUTSTREAM_HPP
27 |
28 | ////////////////////////////////////////////////////////////
29 | // Headers
30 | ////////////////////////////////////////////////////////////
31 | #include
32 | #include