Run clang-format

This commit is contained in:
Chris Thrasher 2022-07-04 11:20:58 -05:00 committed by Lukas Dürrenberger
parent 88e9f82bee
commit 4f52793f7d
416 changed files with 9918 additions and 9447 deletions

View File

@ -4,14 +4,14 @@
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
#include <SFML/Window.hpp> #include <SFML/Window.hpp>
#include <X11/Xlib.h>
#define GLAD_GL_IMPLEMENTATION #define GLAD_GL_IMPLEMENTATION
#include <gl.h> #include <gl.h>
#include <X11/Xlib.h>
#include <array> #include <array>
#include <iostream>
#include <cmath> #include <cmath>
#include <cstdlib> #include <cstdlib>
#include <iostream>
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// Initialize OpenGL states into the specified view /// Initialize OpenGL states into the specified view
@ -171,31 +171,49 @@ int main()
XSetWindowAttributes attributes; XSetWindowAttributes attributes;
attributes.background_pixel = BlackPixel(display, screen); attributes.background_pixel = BlackPixel(display, screen);
attributes.event_mask = KeyPressMask; attributes.event_mask = KeyPressMask;
Window window = XCreateWindow(display, RootWindow(display, screen), Window window = XCreateWindow(display,
0, 0, 650, 330, 0, RootWindow(display, screen),
0,
0,
650,
330,
0,
DefaultDepth(display, screen), DefaultDepth(display, screen),
InputOutput, InputOutput,
DefaultVisual(display, screen), DefaultVisual(display, screen),
CWBackPixel | CWEventMask, &attributes); CWBackPixel | CWEventMask,
&attributes);
if (!window) if (!window)
return EXIT_FAILURE; return EXIT_FAILURE;
// Set the window's name // Set the window's name
XStoreName(display, window , "SFML Window"); XStoreName(display, window, "SFML Window");
// Let's create the windows which will serve as containers for our SFML views // Let's create the windows which will serve as containers for our SFML views
Window view1 = XCreateWindow(display, window, Window view1 = XCreateWindow(display,
10, 10, 310, 310, 0, window,
10,
10,
310,
310,
0,
DefaultDepth(display, screen), DefaultDepth(display, screen),
InputOutput, InputOutput,
DefaultVisual(display, screen), DefaultVisual(display, screen),
0, nullptr); 0,
Window view2 = XCreateWindow(display, window, nullptr);
330, 10, 310, 310, 0, Window view2 = XCreateWindow(display,
window,
330,
10,
310,
310,
0,
DefaultDepth(display, screen), DefaultDepth(display, screen),
InputOutput, InputOutput,
DefaultVisual(display, screen), DefaultVisual(display, screen),
0, nullptr); 0,
nullptr);
// Show our windows // Show our windows
XMapWindow(display, window); XMapWindow(display, window);

View File

@ -1,8 +1,8 @@
#include <SFML/Audio.hpp>
#include <SFML/Graphics.hpp>
#include <SFML/Network.hpp>
#include <SFML/System.hpp> #include <SFML/System.hpp>
#include <SFML/Window.hpp> #include <SFML/Window.hpp>
#include <SFML/Graphics.hpp>
#include <SFML/Audio.hpp>
#include <SFML/Network.hpp>
// Do we want to showcase direct JNI/NDK interaction? // Do we want to showcase direct JNI/NDK interaction?
// Undefine this to get real cross-platform code. // Undefine this to get real cross-platform code.
@ -11,8 +11,8 @@
#if defined(USE_JNI) #if defined(USE_JNI)
// These headers are only needed for direct NDK/JDK interaction // These headers are only needed for direct NDK/JDK interaction
#include <jni.h>
#include <android/native_activity.h> #include <android/native_activity.h>
#include <jni.h>
// Since we want to get the native activity from SFML, we'll have to use an // Since we want to get the native activity from SFML, we'll have to use an
// extra header here: // extra header here:
@ -22,36 +22,36 @@
int vibrate(sf::Time duration) int vibrate(sf::Time duration)
{ {
// First we'll need the native activity handle // First we'll need the native activity handle
ANativeActivity *activity = sf::getNativeActivity(); ANativeActivity* activity = sf::getNativeActivity();
// Retrieve the JVM and JNI environment // Retrieve the JVM and JNI environment
JavaVM* vm = activity->vm; JavaVM* vm = activity->vm;
JNIEnv* env = activity->env; JNIEnv* env = activity->env;
// First, attach this thread to the main thread // First, attach this thread to the main thread
JavaVMAttachArgs attachargs; JavaVMAttachArgs attachargs;
attachargs.version = JNI_VERSION_1_6; attachargs.version = JNI_VERSION_1_6;
attachargs.name = "NativeThread"; attachargs.name = "NativeThread";
attachargs.group = nullptr; attachargs.group = nullptr;
jint res = vm->AttachCurrentThread(&env, &attachargs); jint res = vm->AttachCurrentThread(&env, &attachargs);
if (res == JNI_ERR) if (res == JNI_ERR)
return EXIT_FAILURE; return EXIT_FAILURE;
// Retrieve class information // Retrieve class information
jclass natact = env->FindClass("android/app/NativeActivity"); jclass natact = env->FindClass("android/app/NativeActivity");
jclass context = env->FindClass("android/content/Context"); jclass context = env->FindClass("android/content/Context");
// Get the value of a constant // Get the value of a constant
jfieldID fid = env->GetStaticFieldID(context, "VIBRATOR_SERVICE", "Ljava/lang/String;"); jfieldID fid = env->GetStaticFieldID(context, "VIBRATOR_SERVICE", "Ljava/lang/String;");
jobject svcstr = env->GetStaticObjectField(context, fid); jobject svcstr = env->GetStaticObjectField(context, fid);
// Get the method 'getSystemService' and call it // Get the method 'getSystemService' and call it
jmethodID getss = env->GetMethodID(natact, "getSystemService", "(Ljava/lang/String;)Ljava/lang/Object;"); jmethodID getss = env->GetMethodID(natact, "getSystemService", "(Ljava/lang/String;)Ljava/lang/Object;");
jobject vib_obj = env->CallObjectMethod(activity->clazz, getss, svcstr); jobject vib_obj = env->CallObjectMethod(activity->clazz, getss, svcstr);
// Get the object's class and retrieve the member name // Get the object's class and retrieve the member name
jclass vib_cls = env->GetObjectClass(vib_obj); jclass vib_cls = env->GetObjectClass(vib_obj);
jmethodID vibrate = env->GetMethodID(vib_cls, "vibrate", "(J)V"); jmethodID vibrate = env->GetMethodID(vib_cls, "vibrate", "(J)V");
// Determine the timeframe // Determine the timeframe
@ -75,7 +75,7 @@ int vibrate(sf::Time duration)
// This is the actual Android example. You don't have to write any platform // This is the actual Android example. You don't have to write any platform
// specific code, unless you want to use things not directly exposed. // specific code, unless you want to use things not directly exposed.
// ('vibrate()' in this example; undefine 'USE_JNI' above to disable it) // ('vibrate()' in this example; undefine 'USE_JNI' above to disable it)
int main(int argc, char *argv[]) int main(int argc, char* argv[])
{ {
sf::VideoMode screen(sf::VideoMode::getDesktopMode()); sf::VideoMode screen(sf::VideoMode::getDesktopMode());
@ -83,7 +83,7 @@ int main(int argc, char *argv[])
window.setFramerateLimit(30); window.setFramerateLimit(30);
sf::Texture texture; sf::Texture texture;
if(!texture.loadFromFile("image.png")) if (!texture.loadFromFile("image.png"))
return EXIT_FAILURE; return EXIT_FAILURE;
sf::Sprite image(texture); sf::Sprite image(texture);
@ -159,7 +159,8 @@ int main(int argc, char *argv[])
window.draw(text); window.draw(text);
window.display(); window.display();
} }
else { else
{
sf::sleep(sf::milliseconds(100)); sf::sleep(sf::milliseconds(100));
} }
} }

View File

@ -23,9 +23,10 @@
// //
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
#import <Cocoa/Cocoa.h>
#import <SFML/Graphics.hpp> #import <SFML/Graphics.hpp>
#import <Cocoa/Cocoa.h>
/* /*
* NB: We need pointers for C++ objects fields in Obj-C interface ! * NB: We need pointers for C++ objects fields in Obj-C interface !
* The recommended way is to use PIMPL idiom. * The recommended way is to use PIMPL idiom.
@ -36,7 +37,7 @@
struct SFMLmainWindow; struct SFMLmainWindow;
@interface CocoaAppDelegate : NSObject <NSApplicationDelegate> @interface CocoaAppDelegate : NSObject<NSApplicationDelegate>
{ {
@private @private
NSWindow* m_window; NSWindow* m_window;
@ -48,17 +49,17 @@ struct SFMLmainWindow;
BOOL m_initialized; BOOL m_initialized;
} }
@property (retain) IBOutlet NSWindow* window; @property (retain) IBOutlet NSWindow* window;
@property (assign) IBOutlet NSView* sfmlView; @property (assign) IBOutlet NSView* sfmlView;
@property (assign) IBOutlet NSTextField* textField; @property (assign) IBOutlet NSTextField* textField;
-(IBAction)colorChanged:(NSPopUpButton*)sender; - (IBAction)colorChanged:(NSPopUpButton*)sender;
-(IBAction)rotationChanged:(NSSlider*)sender; - (IBAction)rotationChanged:(NSSlider*)sender;
-(IBAction)visibleChanged:(NSButton*)sender; - (IBAction)visibleChanged:(NSButton*)sender;
-(IBAction)textChanged:(NSTextField*)sender; - (IBAction)textChanged:(NSTextField*)sender;
-(IBAction)updateText:(NSButton*)sender; - (IBAction)updateText:(NSButton*)sender;
@end @end
@ -68,6 +69,6 @@ struct SFMLmainWindow;
*/ */
@interface SilentWindow : NSWindow @interface SilentWindow : NSWindow
-(void)keyDown:(NSEvent*)theEvent; - (void)keyDown:(NSEvent*)theEvent;
@end @end

View File

@ -24,27 +24,26 @@
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
#import "CocoaAppDelegate.h" #import "CocoaAppDelegate.h"
#import "NSString+stdstring.h" #import "NSString+stdstring.h"
// These define are used for converting the color of the NSPopUpButton // These define are used for converting the color of the NSPopUpButton
#define BLUE @"Blue" #define BLUE @"Blue"
#define GREEN @"Green" #define GREEN @"Green"
#define RED @"Red" #define RED @"Red"
#if defined(__APPLE__) #if defined(__APPLE__)
#if defined(__clang__) #if defined(__clang__)
#pragma clang diagnostic ignored "-Wdeprecated-declarations" #pragma clang diagnostic ignored "-Wdeprecated-declarations"
#elif defined(__GNUC__) #elif defined(__GNUC__)
#pragma GCC diagnostic ignored "-Wdeprecated-declarations" #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
#endif #endif
#endif #endif
// Our PIMPL // Our PIMPL
struct SFMLmainWindow struct SFMLmainWindow
{ {
SFMLmainWindow(sf::WindowHandle win) : SFMLmainWindow(sf::WindowHandle win) : renderWindow(win), background(sf::Color::Blue)
renderWindow(win),
background(sf::Color::Blue)
{ {
std::string resPath = [[[NSBundle mainBundle] resourcePath] tostdstring]; std::string resPath = [[[NSBundle mainBundle] resourcePath] tostdstring];
if (!logo.loadFromFile(resPath + "/logo.png")) if (!logo.loadFromFile(resPath + "/logo.png"))
@ -54,7 +53,7 @@ struct SFMLmainWindow
sprite.setTexture(logo, true); sprite.setTexture(logo, true);
sf::FloatRect rect = sprite.getLocalBounds(); sf::FloatRect rect = sprite.getLocalBounds();
sf::Vector2f size(rect.width, rect.height); sf::Vector2f size(rect.width, rect.height);
sprite.setOrigin(size / 2.f); sprite.setOrigin(size / 2.f);
sprite.scale({0.3f, 0.3f}); sprite.scale({0.3f, 0.3f});
@ -69,24 +68,24 @@ struct SFMLmainWindow
text.setFont(font); text.setFont(font);
} }
sf::RenderWindow renderWindow; sf::RenderWindow renderWindow;
sf::Font font; sf::Font font;
sf::Text text; sf::Text text;
sf::Texture logo; sf::Texture logo;
sf::Sprite sprite; sf::Sprite sprite;
sf::Color background; sf::Color background;
}; };
// Private stuff // Private stuff
@interface CocoaAppDelegate () @interface CocoaAppDelegate ()
@property (assign) SFMLmainWindow* mainWindow; @property (assign) SFMLmainWindow* mainWindow;
@property (retain) NSTimer* renderTimer; @property (retain) NSTimer* renderTimer;
@property (assign) BOOL visible; @property (assign) BOOL visible;
@property (assign) BOOL initialized; @property (assign) BOOL initialized;
-(void)renderMainWindow:(NSTimer*)aTimer; - (void)renderMainWindow:(NSTimer*)aTimer;
@end @end
@ -94,15 +93,15 @@ struct SFMLmainWindow
// Finally, the implementation // Finally, the implementation
@implementation CocoaAppDelegate @implementation CocoaAppDelegate
@synthesize window = m_window; @synthesize window = m_window;
@synthesize sfmlView = m_sfmlView; @synthesize sfmlView = m_sfmlView;
@synthesize textField = m_textField; @synthesize textField = m_textField;
@synthesize mainWindow = m_mainWindow; @synthesize mainWindow = m_mainWindow;
@synthesize renderTimer = m_renderTimer; @synthesize renderTimer = m_renderTimer;
@synthesize visible = m_visible; @synthesize visible = m_visible;
@synthesize initialized = m_initialized; @synthesize initialized = m_initialized;
- (id)init - (id)init
{ {
@ -113,7 +112,7 @@ struct SFMLmainWindow
return self; return self;
} }
-(void)applicationDidFinishLaunching:(NSNotification*)aNotification - (void)applicationDidFinishLaunching:(NSNotification*)aNotification
{ {
(void)aNotification; (void)aNotification;
@ -125,15 +124,14 @@ struct SFMLmainWindow
self.visible = YES; self.visible = YES;
// Launch the timer to periodically display our stuff into the Cocoa view. // Launch the timer to periodically display our stuff into the Cocoa view.
self.renderTimer = [NSTimer timerWithTimeInterval:1.0/60.0 self.renderTimer = [NSTimer
target:self timerWithTimeInterval:1.0 / 60.0
selector:@selector(renderMainWindow:) target:self
userInfo:nil selector:@selector(renderMainWindow:)
repeats:YES]; userInfo:nil
[[NSRunLoop mainRunLoop] addTimer:self.renderTimer repeats:YES];
forMode:NSDefaultRunLoopMode]; [[NSRunLoop mainRunLoop] addTimer:self.renderTimer forMode:NSDefaultRunLoopMode];
[[NSRunLoop mainRunLoop] addTimer:self.renderTimer [[NSRunLoop mainRunLoop] addTimer:self.renderTimer forMode:NSEventTrackingRunLoopMode];
forMode:NSEventTrackingRunLoopMode];
/* /*
* This is really some ugly code but in order to have the timer fired * This is really some ugly code but in order to have the timer fired
* periodically we need to add it to the two above runloop mode. * periodically we need to add it to the two above runloop mode.
@ -147,23 +145,23 @@ struct SFMLmainWindow
} }
} }
-(void)dealloc - (void)dealloc
{ {
[self.renderTimer invalidate]; [self.renderTimer invalidate];
self.mainWindow->renderWindow.close(); self.mainWindow->renderWindow.close();
self.window = nil; self.window = nil;
self.sfmlView = nil; self.sfmlView = nil;
self.textField = nil; self.textField = nil;
delete static_cast<SFMLmainWindow*>(self.mainWindow); delete static_cast<SFMLmainWindow*>(self.mainWindow);
self.mainWindow = 0; self.mainWindow = 0;
self.renderTimer = nil; self.renderTimer = nil;
[super dealloc]; [super dealloc];
} }
-(void)renderMainWindow:(NSTimer*)aTimer - (void)renderMainWindow:(NSTimer*)aTimer
{ {
(void)aTimer; (void)aTimer;
@ -187,7 +185,7 @@ struct SFMLmainWindow
self.mainWindow->renderWindow.display(); self.mainWindow->renderWindow.display();
} }
-(IBAction)colorChanged:(NSPopUpButton*)sender - (IBAction)colorChanged:(NSPopUpButton*)sender
{ {
if (self.initialized) if (self.initialized)
{ {
@ -202,7 +200,7 @@ struct SFMLmainWindow
} }
} }
-(IBAction)rotationChanged:(NSSlider*)sender - (IBAction)rotationChanged:(NSSlider*)sender
{ {
if (self.initialized) if (self.initialized)
{ {
@ -211,13 +209,13 @@ struct SFMLmainWindow
} }
} }
-(IBAction)visibleChanged:(NSButton*)sender - (IBAction)visibleChanged:(NSButton*)sender
{ {
if (self.initialized) if (self.initialized)
self.visible = [sender state] == NSOnState; self.visible = [sender state] == NSOnState;
} }
-(IBAction)textChanged:(NSTextField*)sender - (IBAction)textChanged:(NSTextField*)sender
{ {
if (self.initialized) if (self.initialized)
self.mainWindow->text.setString([[sender stringValue] tostdwstring]); self.mainWindow->text.setString([[sender stringValue] tostdwstring]);
@ -235,7 +233,7 @@ struct SFMLmainWindow
@implementation SilentWindow @implementation SilentWindow
-(void)keyDown:(NSEvent*)theEvent - (void)keyDown:(NSEvent*)theEvent
{ {
(void)theEvent; (void)theEvent;
// Do nothing except preventing this alert. // Do nothing except preventing this alert.

View File

@ -23,17 +23,17 @@
// //
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
#import <string>
#import <Foundation/Foundation.h> #import <Foundation/Foundation.h>
#import <string>
@interface NSString (NSString_stdstring) @interface NSString (NSString_stdstring)
+(id)stringWithstdstring:(const std::string&)string; + (id)stringWithstdstring:(const std::string&)string;
+(id)stringWithstdwstring:(const std::wstring&)string; + (id)stringWithstdwstring:(const std::wstring&)string;
-(std::string)tostdstring; - (std::string)tostdstring;
-(std::wstring)tostdwstring; - (std::wstring)tostdwstring;
@end @end

View File

@ -23,38 +23,38 @@
// //
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
#import "NSString+stdstring.h"
#include <SFML/System/Utf.hpp> #include <SFML/System/Utf.hpp>
#import "NSString+stdstring.h"
@implementation NSString (NSString_stdstring) @implementation NSString (NSString_stdstring)
+(id)stringWithstdstring:(const std::string&)string + (id)stringWithstdstring:(const std::string&)string
{ {
std::string utf8; std::string utf8;
utf8.reserve(string.size() + 1); utf8.reserve(string.size() + 1);
sf::Utf8::fromAnsi(string.begin(), string.end(), std::back_inserter(utf8)); sf::Utf8::fromAnsi(string.begin(), string.end(), std::back_inserter(utf8));
NSString* str = [NSString stringWithCString:utf8.c_str() NSString* str = [NSString stringWithCString:utf8.c_str() encoding:NSUTF8StringEncoding];
encoding:NSUTF8StringEncoding];
return str; return str;
} }
+(id)stringWithstdwstring:(const std::wstring&)string + (id)stringWithstdwstring:(const std::wstring&)string
{ {
const void* data = static_cast<const void*>(string.data()); const void* data = static_cast<const void*>(string.data());
unsigned size = static_cast<unsigned>(string.size() * sizeof(wchar_t)); unsigned size = static_cast<unsigned>(string.size() * sizeof(wchar_t));
NSString* str = [[[NSString alloc] initWithBytes:data length:size NSString* str = [[[NSString alloc] initWithBytes:data length:size
encoding:NSUTF32LittleEndianStringEncoding] autorelease]; encoding:NSUTF32LittleEndianStringEncoding] autorelease];
return str; return str;
} }
-(std::string)tostdstring - (std::string)tostdstring
{ {
// Not sure about the encoding to use. Using [self UTF8String] doesn't // Not sure about the encoding to use. Using [self UTF8String] doesn't
// work for characters like é or à. // work for characters like é or à.
const char *cstr = [self cStringUsingEncoding:NSISOLatin1StringEncoding]; const char* cstr = [self cStringUsingEncoding:NSISOLatin1StringEncoding];
if (cstr != nullptr) if (cstr != nullptr)
return std::string(cstr); return std::string(cstr);
@ -62,7 +62,7 @@
return ""; return "";
} }
-(std::wstring)tostdwstring - (std::wstring)tostdwstring
{ {
// According to Wikipedia, Mac OS X is Little Endian on x86 and x86-64 // According to Wikipedia, Mac OS X is Little Endian on x86 and x86-64
// https://en.wikipedia.org/wiki/Endianness // https://en.wikipedia.org/wiki/Endianness

View File

@ -3,6 +3,7 @@
// Headers // Headers
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
#include <SFML/Network.hpp> #include <SFML/Network.hpp>
#include <fstream> #include <fstream>
#include <iostream> #include <iostream>
#include <optional> #include <optional>
@ -12,7 +13,7 @@
/// Print a FTP response into a standard output stream /// Print a FTP response into a standard output stream
/// ///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
std::ostream& operator <<(std::ostream& stream, const sf::Ftp::Response& response) std::ostream& operator<<(std::ostream& stream, const sf::Ftp::Response& response)
{ {
return stream << response.getStatus() << response.getMessage(); return stream << response.getStatus() << response.getMessage();
} }
@ -31,12 +32,11 @@ int main()
do do
{ {
std::cout << "Enter the FTP server address: "; std::cout << "Enter the FTP server address: ";
std::cin >> address; std::cin >> address;
} } while (!address.has_value());
while (!address.has_value());
// Connect to the server // Connect to the server
sf::Ftp server; sf::Ftp server;
sf::Ftp::Response connectResponse = server.connect(address.value()); sf::Ftp::Response connectResponse = server.connect(address.value());
std::cout << connectResponse << std::endl; std::cout << connectResponse << std::endl;
if (!connectResponse.isOk()) if (!connectResponse.isOk())
@ -45,9 +45,9 @@ int main()
// Ask for user name and password // Ask for user name and password
std::string user, password; std::string user, password;
std::cout << "User name: "; std::cout << "User name: ";
std::cin >> user; std::cin >> user;
std::cout << "Password: "; std::cout << "Password: ";
std::cin >> password; std::cin >> password;
// Login to the server // Login to the server
sf::Ftp::Response loginResponse = server.login(user, password); sf::Ftp::Response loginResponse = server.login(user, password);
@ -75,7 +75,7 @@ int main()
<< std::endl; << std::endl;
std::cout << "Your choice: "; std::cout << "Your choice: ";
std::cin >> choice; std::cin >> choice;
std::cout << std::endl; std::cout << std::endl;
switch (choice) switch (choice)
@ -93,8 +93,7 @@ int main()
{ {
// Print the current server directory // Print the current server directory
sf::Ftp::DirectoryResponse response = server.getWorkingDirectory(); sf::Ftp::DirectoryResponse response = server.getWorkingDirectory();
std::cout << response << '\n' std::cout << response << '\n' << "Current directory is " << response.getDirectory() << std::endl;
<< "Current directory is " << response.getDirectory() << std::endl;
break; break;
} }
@ -114,7 +113,7 @@ int main()
// Change the current directory // Change the current directory
std::string directory; std::string directory;
std::cout << "Choose a directory: "; std::cout << "Choose a directory: ";
std::cin >> directory; std::cin >> directory;
std::cout << server.changeDirectory(directory) << std::endl; std::cout << server.changeDirectory(directory) << std::endl;
break; break;
} }
@ -124,7 +123,7 @@ int main()
// Create a new directory // Create a new directory
std::string directory; std::string directory;
std::cout << "Name of the directory to create: "; std::cout << "Name of the directory to create: ";
std::cin >> directory; std::cin >> directory;
std::cout << server.createDirectory(directory) << std::endl; std::cout << server.createDirectory(directory) << std::endl;
break; break;
} }
@ -134,7 +133,7 @@ int main()
// Remove an existing directory // Remove an existing directory
std::string directory; std::string directory;
std::cout << "Name of the directory to remove: "; std::cout << "Name of the directory to remove: ";
std::cin >> directory; std::cin >> directory;
std::cout << server.deleteDirectory(directory) << std::endl; std::cout << server.deleteDirectory(directory) << std::endl;
break; break;
} }
@ -144,9 +143,9 @@ int main()
// Rename a file // Rename a file
std::string source, destination; std::string source, destination;
std::cout << "Name of the file to rename: "; std::cout << "Name of the file to rename: ";
std::cin >> source; std::cin >> source;
std::cout << "New name: "; std::cout << "New name: ";
std::cin >> destination; std::cin >> destination;
std::cout << server.renameFile(source, destination) << std::endl; std::cout << server.renameFile(source, destination) << std::endl;
break; break;
} }
@ -156,7 +155,7 @@ int main()
// Remove an existing directory // Remove an existing directory
std::string filename; std::string filename;
std::cout << "Name of the file to remove: "; std::cout << "Name of the file to remove: ";
std::cin >> filename; std::cin >> filename;
std::cout << server.deleteFile(filename) << std::endl; std::cout << server.deleteFile(filename) << std::endl;
break; break;
} }
@ -166,9 +165,9 @@ int main()
// Download a file from server // Download a file from server
std::string filename, directory; std::string filename, directory;
std::cout << "Filename of the file to download (relative to current directory): "; std::cout << "Filename of the file to download (relative to current directory): ";
std::cin >> filename; std::cin >> filename;
std::cout << "Directory to download the file to: "; std::cout << "Directory to download the file to: ";
std::cin >> directory; std::cin >> directory;
std::cout << server.download(filename, directory) << std::endl; std::cout << server.download(filename, directory) << std::endl;
break; break;
} }
@ -178,9 +177,9 @@ int main()
// Upload a file to server // Upload a file to server
std::string filename, directory; std::string filename, directory;
std::cout << "Path of the file to upload (absolute or relative to working directory): "; std::cout << "Path of the file to upload (absolute or relative to working directory): ";
std::cin >> filename; std::cin >> filename;
std::cout << "Directory to upload the file to (relative to current directory): "; std::cout << "Directory to upload the file to (relative to current directory): ";
std::cin >> directory; std::cin >> directory;
std::cout << server.upload(filename, directory) << std::endl; std::cout << server.upload(filename, directory) << std::endl;
break; break;
} }
@ -195,8 +194,7 @@ int main()
} while (choice != 0); } while (choice != 0);
// Disconnect from the server // Disconnect from the server
std::cout << "Disconnecting from server...\n" std::cout << "Disconnecting from server...\n" << server.disconnect() << '\n';
<< server.disconnect() << '\n';
// Wait until the user presses 'enter' key // Wait until the user presses 'enter' key
std::cout << "Press enter to exit..." << std::endl; std::cout << "Press enter to exit..." << std::endl;

View File

@ -2,13 +2,16 @@
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
// Headers // Headers
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
#include <SFML/Graphics.hpp>
#define STB_PERLIN_IMPLEMENTATION #define STB_PERLIN_IMPLEMENTATION
#include <stb_perlin.h> #include <stb_perlin.h>
#include <SFML/Graphics.hpp>
#include <algorithm> #include <algorithm>
#include <array> #include <array>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <deque> #include <deque>
#include <iostream> #include <iostream>
#include <mutex> #include <mutex>
@ -16,62 +19,58 @@
#include <thread> #include <thread>
#include <vector> #include <vector>
#include <cmath>
#include <cstdlib>
#include <cstring>
namespace namespace
{ {
// Width and height of the application window // Width and height of the application window
const unsigned int windowWidth = 800; const unsigned int windowWidth = 800;
const unsigned int windowHeight = 600; const unsigned int windowHeight = 600;
// Resolution of the generated terrain // Resolution of the generated terrain
const unsigned int resolutionX = 800; const unsigned int resolutionX = 800;
const unsigned int resolutionY = 600; const unsigned int resolutionY = 600;
// Thread pool parameters // Thread pool parameters
const unsigned int threadCount = 4; const unsigned int threadCount = 4;
const unsigned int blockCount = 32; const unsigned int blockCount = 32;
struct WorkItem struct WorkItem
{ {
sf::Vertex* targetBuffer; sf::Vertex* targetBuffer;
unsigned int index; unsigned int index;
}; };
std::deque<WorkItem> workQueue; std::deque<WorkItem> workQueue;
std::vector<std::thread> threads; std::vector<std::thread> threads;
int pendingWorkCount = 0; int pendingWorkCount = 0;
bool workPending = true; bool workPending = true;
bool bufferUploadPending = false; bool bufferUploadPending = false;
std::recursive_mutex workQueueMutex; std::recursive_mutex workQueueMutex;
struct Setting struct Setting
{ {
const char* name; const char* name;
float* value; float* value;
}; };
// Terrain noise parameters // Terrain noise parameters
const int perlinOctaves = 3; const int perlinOctaves = 3;
float perlinFrequency = 7.0f; float perlinFrequency = 7.0f;
float perlinFrequencyBase = 4.0f; float perlinFrequencyBase = 4.0f;
// Terrain generation parameters // Terrain generation parameters
float heightBase = 0.0f; float heightBase = 0.0f;
float edgeFactor = 0.9f; float edgeFactor = 0.9f;
float edgeDropoffExponent = 1.5f; float edgeDropoffExponent = 1.5f;
float snowcapHeight = 0.6f; float snowcapHeight = 0.6f;
// Terrain lighting parameters // Terrain lighting parameters
float heightFactor = windowHeight / 2.0f; float heightFactor = windowHeight / 2.0f;
float heightFlatten = 3.0f; float heightFlatten = 3.0f;
float lightFactor = 0.7f; float lightFactor = 0.7f;
} } // namespace
// Forward declarations of the functions we define further down // Forward declarations of the functions we define further down
@ -88,8 +87,7 @@ void generateTerrain(sf::Vertex* vertexBuffer);
int main() int main()
{ {
// Create the window of the application // Create the window of the application
sf::RenderWindow window(sf::VideoMode({windowWidth, windowHeight}), "SFML Island", sf::RenderWindow window(sf::VideoMode({windowWidth, windowHeight}), "SFML Island", sf::Style::Titlebar | sf::Style::Close);
sf::Style::Titlebar | sf::Style::Close);
window.setVerticalSyncEnabled(true); window.setVerticalSyncEnabled(true);
sf::Font font; sf::Font font;
@ -97,9 +95,9 @@ int main()
return EXIT_FAILURE; return EXIT_FAILURE;
// Create all of our graphics resources // Create all of our graphics resources
sf::Text hudText; sf::Text hudText;
sf::Text statusText; sf::Text statusText;
sf::Shader terrainShader; sf::Shader terrainShader;
sf::RenderStates terrainStates(&terrainShader); sf::RenderStates terrainStates(&terrainShader);
sf::VertexBuffer terrain(sf::Triangles, sf::VertexBuffer::Static); sf::VertexBuffer terrain(sf::Triangles, sf::VertexBuffer::Static);
@ -159,26 +157,25 @@ int main()
} }
// Center the status text // Center the status text
statusText.setPosition({(windowWidth - statusText.getLocalBounds().width) / 2.f, (windowHeight - statusText.getLocalBounds().height) / 2.f}); statusText.setPosition({(windowWidth - statusText.getLocalBounds().width) / 2.f,
(windowHeight - statusText.getLocalBounds().height) / 2.f});
// Set up an array of pointers to our settings for arrow navigation // Set up an array of pointers to our settings for arrow navigation
constexpr std::array<Setting, 9> settings = constexpr std::array<Setting, 9> settings = {
{{ {{"perlinFrequency", &perlinFrequency},
{"perlinFrequency", &perlinFrequency}, {"perlinFrequencyBase", &perlinFrequencyBase},
{"perlinFrequencyBase", &perlinFrequencyBase}, {"heightBase", &heightBase},
{"heightBase", &heightBase}, {"edgeFactor", &edgeFactor},
{"edgeFactor", &edgeFactor}, {"edgeDropoffExponent", &edgeDropoffExponent},
{"edgeDropoffExponent", &edgeDropoffExponent}, {"snowcapHeight", &snowcapHeight},
{"snowcapHeight", &snowcapHeight}, {"heightFactor", &heightFactor},
{"heightFactor", &heightFactor}, {"heightFlatten", &heightFlatten},
{"heightFlatten", &heightFlatten}, {"lightFactor", &lightFactor}}};
{"lightFactor", &lightFactor}
}};
std::size_t currentSetting = 0; std::size_t currentSetting = 0;
std::ostringstream osstr; std::ostringstream osstr;
sf::Clock clock; sf::Clock clock;
while (window.isOpen()) while (window.isOpen())
{ {
@ -187,7 +184,7 @@ int main()
{ {
// Window closed or escape key pressed: exit // Window closed or escape key pressed: exit
if ((event.type == sf::Event::Closed) || if ((event.type == sf::Event::Closed) ||
((event.type == sf::Event::KeyPressed) && (event.key.code == sf::Keyboard::Escape))) ((event.type == sf::Event::KeyPressed) && (event.key.code == sf::Keyboard::Escape)))
{ {
window.close(); window.close();
break; break;
@ -198,12 +195,23 @@ int main()
{ {
switch (event.key.code) switch (event.key.code)
{ {
case sf::Keyboard::Enter: generateTerrain(terrainStagingBuffer.data()); break; case sf::Keyboard::Enter:
case sf::Keyboard::Down: currentSetting = (currentSetting + 1) % settings.size(); break; generateTerrain(terrainStagingBuffer.data());
case sf::Keyboard::Up: currentSetting = (currentSetting + settings.size() - 1) % settings.size(); break; break;
case sf::Keyboard::Left: *(settings[currentSetting].value) -= 0.1f; break; case sf::Keyboard::Down:
case sf::Keyboard::Right: *(settings[currentSetting].value) += 0.1f; break; currentSetting = (currentSetting + 1) % settings.size();
default: break; break;
case sf::Keyboard::Up:
currentSetting = (currentSetting + settings.size() - 1) % settings.size();
break;
case sf::Keyboard::Left:
*(settings[currentSetting].value) -= 0.1f;
break;
case sf::Keyboard::Right:
*(settings[currentSetting].value) += 0.1f;
break;
default:
break;
} }
} }
} }
@ -245,7 +253,8 @@ int main()
<< "Use the arrow keys to change the values.\nUse the return key to regenerate the terrain.\n\n"; << "Use the arrow keys to change the values.\nUse the return key to regenerate the terrain.\n\n";
for (std::size_t i = 0; i < settings.size(); ++i) for (std::size_t i = 0; i < settings.size(); ++i)
osstr << ((i == currentSetting) ? ">> " : " ") << settings[i].name << ": " << *(settings[i].value) << '\n'; osstr << ((i == currentSetting) ? ">> " : " ") << settings[i].name << ": "
<< *(settings[i].value) << '\n';
hudText.setString(osstr.str()); hudText.setString(osstr.str());
@ -285,18 +294,20 @@ float getElevation(float x, float y)
for (int i = 0; i < perlinOctaves; ++i) for (int i = 0; i < perlinOctaves; ++i)
{ {
elevation += stb_perlin_noise3( elevation += stb_perlin_noise3(x * perlinFrequency * static_cast<float>(std::pow(perlinFrequencyBase, i)),
x * perlinFrequency * static_cast<float>(std::pow(perlinFrequencyBase, i)), y * perlinFrequency * static_cast<float>(std::pow(perlinFrequencyBase, i)),
y * perlinFrequency * static_cast<float>(std::pow(perlinFrequencyBase, i)), 0,
0, 0, 0, 0 0,
) * static_cast<float>(std::pow(perlinFrequencyBase, -i)); 0,
0) *
static_cast<float>(std::pow(perlinFrequencyBase, -i));
} }
elevation = (elevation + 1.f) / 2.f; elevation = (elevation + 1.f) / 2.f;
float distance = 2.0f * std::sqrt(x * x + y * y); float distance = 2.0f * std::sqrt(x * x + y * y);
elevation = (elevation + heightBase) * (1.0f - edgeFactor * std::pow(distance, edgeDropoffExponent)); elevation = (elevation + heightBase) * (1.0f - edgeFactor * std::pow(distance, edgeDropoffExponent));
elevation = std::min(std::max(elevation, 0.0f), 1.0f); elevation = std::min(std::max(elevation, 0.0f), 1.0f);
return elevation; return elevation;
} }
@ -316,11 +327,7 @@ float getMoisture(float x, float y)
x = x / resolutionX - 0.5f; x = x / resolutionX - 0.5f;
y = y / resolutionY - 0.5f; y = y / resolutionY - 0.5f;
float moisture = stb_perlin_noise3( float moisture = stb_perlin_noise3(x * 4.f + 0.5f, y * 4.f + 0.5f, 0, 0, 0, 0);
x * 4.f + 0.5f,
y * 4.f + 0.5f,
0, 0, 0, 0
);
return (moisture + 1.f) / 2.f; return (moisture + 1.f) / 2.f;
} }
@ -337,21 +344,22 @@ float getMoisture(unsigned int x, unsigned int y)
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
sf::Color colorFromFloats(float r, float g, float b) sf::Color colorFromFloats(float r, float g, float b)
{ {
return sf::Color(static_cast<sf::Uint8>(r), return sf::Color(static_cast<sf::Uint8>(r), static_cast<sf::Uint8>(g), static_cast<sf::Uint8>(b));
static_cast<sf::Uint8>(g),
static_cast<sf::Uint8>(b));
} }
sf::Color getLowlandsTerrainColor(float moisture) sf::Color getLowlandsTerrainColor(float moisture)
{ {
sf::Color color = sf::Color color = moisture < 0.27f ? colorFromFloats(240, 240, 180)
moisture < 0.27f ? colorFromFloats(240, 240, 180) : : moisture < 0.3f ? colorFromFloats(240 - (240 * (moisture - 0.27f) / 0.03f),
moisture < 0.3f ? colorFromFloats(240 - (240 * (moisture - 0.27f) / 0.03f), 240 - (40 * (moisture - 0.27f) / 0.03f), 180 - (180 * (moisture - 0.27f) / 0.03f)) : 240 - (40 * (moisture - 0.27f) / 0.03f),
moisture < 0.4f ? colorFromFloats(0, 200, 0) : 180 - (180 * (moisture - 0.27f) / 0.03f))
moisture < 0.48f ? colorFromFloats(0, 200 - (40 * (moisture - 0.4f) / 0.08f), 0) : : moisture < 0.4f ? colorFromFloats(0, 200, 0)
moisture < 0.6f ? colorFromFloats(0, 160, 0) : : moisture < 0.48f ? colorFromFloats(0, 200 - (40 * (moisture - 0.4f) / 0.08f), 0)
moisture < 0.7f ? colorFromFloats((34 * (moisture - 0.6f) / 0.1f), 160 - (60 * (moisture - 0.6f) / 0.1f), (34 * (moisture - 0.6f) / 0.1f)) : : moisture < 0.6f ? colorFromFloats(0, 160, 0)
colorFromFloats(34, 100, 34); : moisture < 0.7f ? colorFromFloats((34 * (moisture - 0.6f) / 0.1f),
160 - (60 * (moisture - 0.6f) / 0.1f),
(34 * (moisture - 0.6f) / 0.1f))
: colorFromFloats(34, 100, 34);
return color; return color;
} }
@ -366,9 +374,10 @@ sf::Color getHighlandsTerrainColor(float elevation, float moisture)
{ {
sf::Color lowlandsColor = getLowlandsTerrainColor(moisture); sf::Color lowlandsColor = getLowlandsTerrainColor(moisture);
sf::Color color = sf::Color color = moisture < 0.6f ? sf::Color(112, 128, 144)
moisture < 0.6f ? sf::Color(112, 128, 144) : : colorFromFloats(112 + (110 * (moisture - 0.6f) / 0.4f),
colorFromFloats(112 + (110 * (moisture - 0.6f) / 0.4f), 128 + (56 * (moisture - 0.6f) / 0.4f), 144 - (9 * (moisture - 0.6f) / 0.4f)); 128 + (56 * (moisture - 0.6f) / 0.4f),
144 - (9 * (moisture - 0.6f) / 0.4f));
float factor = std::min((elevation - 0.4f) / 0.1f, 1.f); float factor = std::min((elevation - 0.4f) / 0.1f, 1.f);
@ -408,16 +417,21 @@ sf::Color getSnowcapTerrainColor(float elevation, float moisture)
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
sf::Color getTerrainColor(float elevation, float moisture) sf::Color getTerrainColor(float elevation, float moisture)
{ {
sf::Color color = sf::Color color = elevation < 0.11f ? sf::Color(0, 0, static_cast<sf::Uint8>(elevation / 0.11f * 74.f + 181.0f))
elevation < 0.11f ? sf::Color(0, 0, static_cast<sf::Uint8>(elevation / 0.11f * 74.f + 181.0f)) : : elevation < 0.14f
elevation < 0.14f ? sf::Color(static_cast<sf::Uint8>(std::pow((elevation - 0.11f) / 0.03f, 0.3f) * 48.f), static_cast<sf::Uint8>(std::pow((elevation - 0.11f) / 0.03f, 0.3f) * 48.f), 255) : ? sf::Color(static_cast<sf::Uint8>(std::pow((elevation - 0.11f) / 0.03f, 0.3f) * 48.f),
elevation < 0.16f ? sf::Color(static_cast<sf::Uint8>((elevation - 0.14f) * 128.f / 0.02f + 48.f), static_cast<sf::Uint8>((elevation - 0.14f) * 128.f / 0.02f + 48.f), static_cast<sf::Uint8>(127.0f + (0.16f - elevation) * 128.f / 0.02f)) : static_cast<sf::Uint8>(std::pow((elevation - 0.11f) / 0.03f, 0.3f) * 48.f),
elevation < 0.17f ? sf::Color(240, 230, 140) : 255)
elevation < 0.4f ? getLowlandsTerrainColor(moisture) : : elevation < 0.16f
elevation < snowcapHeight ? getHighlandsTerrainColor(elevation, moisture) : ? sf::Color(static_cast<sf::Uint8>((elevation - 0.14f) * 128.f / 0.02f + 48.f),
getSnowcapTerrainColor(elevation, moisture); static_cast<sf::Uint8>((elevation - 0.14f) * 128.f / 0.02f + 48.f),
static_cast<sf::Uint8>(127.0f + (0.16f - elevation) * 128.f / 0.02f))
: elevation < 0.17f ? sf::Color(240, 230, 140)
: elevation < 0.4f ? getLowlandsTerrainColor(moisture)
: elevation < snowcapHeight ? getHighlandsTerrainColor(elevation, moisture)
: getSnowcapTerrainColor(elevation, moisture);
return color; return color;
} }
@ -432,11 +446,9 @@ sf::Vector2f computeNormal(float left, float right, float bottom, float top)
sf::Vector3f deltaX(1, 0, (std::pow(right, heightFlatten) - std::pow(left, heightFlatten)) * heightFactor); sf::Vector3f deltaX(1, 0, (std::pow(right, heightFlatten) - std::pow(left, heightFlatten)) * heightFactor);
sf::Vector3f deltaY(0, 1, (std::pow(top, heightFlatten) - std::pow(bottom, heightFlatten)) * heightFactor); sf::Vector3f deltaY(0, 1, (std::pow(top, heightFlatten) - std::pow(bottom, heightFlatten)) * heightFactor);
sf::Vector3f crossProduct( sf::Vector3f crossProduct(deltaX.y * deltaY.z - deltaX.z * deltaY.y,
deltaX.y * deltaY.z - deltaX.z * deltaY.y, deltaX.z * deltaY.x - deltaX.x * deltaY.z,
deltaX.z * deltaY.x - deltaX.x * deltaY.z, deltaX.x * deltaY.y - deltaX.y * deltaY.x);
deltaX.x * deltaY.y - deltaX.y * deltaY.x
);
// Scale cross product to make z component 1.0f so we can drop it // Scale cross product to make z component 1.0f so we can drop it
crossProduct /= crossProduct.z; crossProduct /= crossProduct.z;
@ -455,12 +467,12 @@ sf::Vector2f computeNormal(float left, float right, float bottom, float top)
void processWorkItem(std::vector<sf::Vertex>& vertices, const WorkItem& workItem) void processWorkItem(std::vector<sf::Vertex>& vertices, const WorkItem& workItem)
{ {
unsigned int rowBlockSize = (resolutionY / blockCount) + 1; unsigned int rowBlockSize = (resolutionY / blockCount) + 1;
unsigned int rowStart = rowBlockSize * workItem.index; unsigned int rowStart = rowBlockSize * workItem.index;
if (rowStart >= resolutionY) if (rowStart >= resolutionY)
return; return;
unsigned int rowEnd = std::min(rowStart + rowBlockSize, resolutionY); unsigned int rowEnd = std::min(rowStart + rowBlockSize, resolutionY);
unsigned int rowCount = rowEnd - rowStart; unsigned int rowCount = rowEnd - rowStart;
const float scalingFactorX = static_cast<float>(windowWidth) / static_cast<float>(resolutionX); const float scalingFactorX = static_cast<float>(windowWidth) / static_cast<float>(resolutionX);
@ -483,9 +495,13 @@ void processWorkItem(std::vector<sf::Vertex>& vertices, const WorkItem& workItem
} }
else else
{ {
vertices[arrayIndexBase + 0].position = sf::Vector2f(static_cast<float>(x) * scalingFactorX, static_cast<float>(y) * scalingFactorY); vertices[arrayIndexBase + 0].position = sf::Vector2f(static_cast<float>(x) * scalingFactorX,
vertices[arrayIndexBase + 0].color = getTerrainColor(getElevation(x, y), getMoisture(x, y)); static_cast<float>(y) * scalingFactorY);
vertices[arrayIndexBase + 0].texCoords = computeNormal(getElevation(x - 1, y), getElevation(x + 1, y), getElevation(x, y + 1), getElevation(x, y - 1)); vertices[arrayIndexBase + 0].color = getTerrainColor(getElevation(x, y), getMoisture(x, y));
vertices[arrayIndexBase + 0].texCoords = computeNormal(getElevation(x - 1, y),
getElevation(x + 1, y),
getElevation(x, y + 1),
getElevation(x, y - 1));
} }
// Bottom left corner (first triangle) // Bottom left corner (first triangle)
@ -495,15 +511,23 @@ void processWorkItem(std::vector<sf::Vertex>& vertices, const WorkItem& workItem
} }
else else
{ {
vertices[arrayIndexBase + 1].position = sf::Vector2f(static_cast<float>(x) * scalingFactorX, static_cast<float>(y + 1) * scalingFactorY); vertices[arrayIndexBase + 1].position = sf::Vector2f(static_cast<float>(x) * scalingFactorX,
vertices[arrayIndexBase + 1].color = getTerrainColor(getElevation(x, y + 1), getMoisture(x, y + 1)); static_cast<float>(y + 1) * scalingFactorY);
vertices[arrayIndexBase + 1].texCoords = computeNormal(getElevation(x - 1, y + 1), getElevation(x + 1, y + 1), getElevation(x, y + 2), getElevation(x, y)); vertices[arrayIndexBase + 1].color = getTerrainColor(getElevation(x, y + 1), getMoisture(x, y + 1));
vertices[arrayIndexBase + 1].texCoords = computeNormal(getElevation(x - 1, y + 1),
getElevation(x + 1, y + 1),
getElevation(x, y + 2),
getElevation(x, y));
} }
// Bottom right corner (first triangle) // Bottom right corner (first triangle)
vertices[arrayIndexBase + 2].position = sf::Vector2f(static_cast<float>(x + 1) * scalingFactorX, static_cast<float>(y + 1) * scalingFactorY); vertices[arrayIndexBase + 2].position = sf::Vector2f(static_cast<float>(x + 1) * scalingFactorX,
static_cast<float>(y + 1) * scalingFactorY);
vertices[arrayIndexBase + 2].color = getTerrainColor(getElevation(x + 1, y + 1), getMoisture(x + 1, y + 1)); vertices[arrayIndexBase + 2].color = getTerrainColor(getElevation(x + 1, y + 1), getMoisture(x + 1, y + 1));
vertices[arrayIndexBase + 2].texCoords = computeNormal(getElevation(x, y + 1), getElevation(x + 2, y + 1), getElevation(x + 1, y + 2), getElevation(x + 1, y)); vertices[arrayIndexBase + 2].texCoords = computeNormal(getElevation(x, y + 1),
getElevation(x + 2, y + 1),
getElevation(x + 1, y + 2),
getElevation(x + 1, y));
// Top left corner (second triangle) // Top left corner (second triangle)
vertices[arrayIndexBase + 3] = vertices[arrayIndexBase + 0]; vertices[arrayIndexBase + 3] = vertices[arrayIndexBase + 0];
@ -518,15 +542,21 @@ void processWorkItem(std::vector<sf::Vertex>& vertices, const WorkItem& workItem
} }
else else
{ {
vertices[arrayIndexBase + 5].position = sf::Vector2f(static_cast<float>(x + 1) * scalingFactorX, static_cast<float>(y) * scalingFactorY); vertices[arrayIndexBase + 5].position = sf::Vector2f(static_cast<float>(x + 1) * scalingFactorX,
vertices[arrayIndexBase + 5].color = getTerrainColor(getElevation(x + 1, y), getMoisture(x + 1, y)); static_cast<float>(y) * scalingFactorY);
vertices[arrayIndexBase + 5].texCoords = computeNormal(getElevation(x, y), getElevation(x + 2, y), getElevation(x + 1, y + 1), getElevation(x + 1, y - 1)); vertices[arrayIndexBase + 5].color = getTerrainColor(getElevation(x + 1, y), getMoisture(x + 1, y));
vertices[arrayIndexBase + 5].texCoords = computeNormal(getElevation(x, y),
getElevation(x + 2, y),
getElevation(x + 1, y + 1),
getElevation(x + 1, y - 1));
} }
} }
} }
// Copy the resulting geometry from our thread-local buffer into the target buffer // Copy the resulting geometry from our thread-local buffer into the target buffer
std::memcpy(workItem.targetBuffer + (resolutionX * rowStart * 6), vertices.data(), sizeof(sf::Vertex) * resolutionX * rowCount * 6); std::memcpy(workItem.targetBuffer + (resolutionX * rowStart * 6),
vertices.data(),
sizeof(sf::Vertex) * resolutionX * rowCount * 6);
} }

View File

@ -3,6 +3,7 @@
// Headers // Headers
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
#include <SFML/Graphics.hpp> #include <SFML/Graphics.hpp>
#include <algorithm> #include <algorithm>
#include <array> #include <array>
#include <sstream> #include <sstream>
@ -12,72 +13,73 @@
namespace namespace
{ {
struct JoystickObject struct JoystickObject
{
sf::Text label;
sf::Text value;
};
using Texts = std::unordered_map<std::string, JoystickObject>;
Texts texts;
std::ostringstream sstr;
float threshold = 0.1f;
// Axes labels in as C strings
constexpr std::array axislabels = {"X", "Y", "Z", "R", "U", "V", "PovX", "PovY"};
// Helper to set text entries to a specified value
template <typename T>
void set(const char* label, const T& value)
{
sstr.str("");
sstr << value;
texts[label].value.setString(sstr.str());
}
// Update joystick identification
void updateIdentification(unsigned int index)
{
sstr.str("");
sstr << "Joystick " << index << ":";
texts["ID"].label.setString(sstr.str());
texts["ID"].value.setString(sf::Joystick::getIdentification(index).name);
}
// Update joystick axes
void updateAxes(unsigned int index)
{
for (unsigned int j = 0; j < sf::Joystick::AxisCount; ++j)
{ {
sf::Text label; if (sf::Joystick::hasAxis(index, static_cast<sf::Joystick::Axis>(j)))
sf::Text value; set(axislabels[j], sf::Joystick::getAxisPosition(index, static_cast<sf::Joystick::Axis>(j)));
};
using Texts = std::unordered_map<std::string, JoystickObject>;
Texts texts;
std::ostringstream sstr;
float threshold = 0.1f;
// Axes labels in as C strings
constexpr std::array axislabels = {"X", "Y", "Z", "R", "U", "V", "PovX", "PovY"};
// Helper to set text entries to a specified value
template<typename T>
void set(const char* label, const T& value)
{
sstr.str("");
sstr << value;
texts[label].value.setString(sstr.str());
}
// Update joystick identification
void updateIdentification(unsigned int index)
{
sstr.str("");
sstr << "Joystick " << index << ":";
texts["ID"].label.setString(sstr.str());
texts["ID"].value.setString(sf::Joystick::getIdentification(index).name);
}
// Update joystick axes
void updateAxes(unsigned int index)
{
for (unsigned int j = 0; j < sf::Joystick::AxisCount; ++j)
{
if (sf::Joystick::hasAxis(index, static_cast<sf::Joystick::Axis>(j)))
set(axislabels[j], sf::Joystick::getAxisPosition(index, static_cast<sf::Joystick::Axis>(j)));
}
}
// Update joystick buttons
void updateButtons(unsigned int index)
{
for (unsigned int j = 0; j < sf::Joystick::getButtonCount(index); ++j)
{
sstr.str("");
sstr << "Button " << j;
set(sstr.str().c_str(), sf::Joystick::isButtonPressed(index, j));
}
}
// Helper to update displayed joystick values
void updateValues(unsigned int index)
{
if (sf::Joystick::isConnected(index)) {
// Update the label-value sf::Text objects based on the current joystick state
updateIdentification(index);
updateAxes(index);
updateButtons(index);
}
} }
} }
// Update joystick buttons
void updateButtons(unsigned int index)
{
for (unsigned int j = 0; j < sf::Joystick::getButtonCount(index); ++j)
{
sstr.str("");
sstr << "Button " << j;
set(sstr.str().c_str(), sf::Joystick::isButtonPressed(index, j));
}
}
// Helper to update displayed joystick values
void updateValues(unsigned int index)
{
if (sf::Joystick::isConnected(index))
{
// Update the label-value sf::Text objects based on the current joystick state
updateIdentification(index);
updateAxes(index);
updateButtons(index);
}
}
} // namespace
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// Entry point of application /// Entry point of application
@ -135,10 +137,12 @@ int main()
sstr << "Button " << i; sstr << "Button " << i;
JoystickObject& object = texts[sstr.str()]; JoystickObject& object = texts[sstr.str()];
object.label.setPosition({5.f, 5.f + (static_cast<float>(sf::Joystick::AxisCount + i + 4) * font.getLineSpacing(14))}); object.label.setPosition(
{5.f, 5.f + (static_cast<float>(sf::Joystick::AxisCount + i + 4) * font.getLineSpacing(14))});
object.label.setString(sstr.str() + ":"); object.label.setString(sstr.str() + ":");
object.value.setPosition({80.f, 5.f + (static_cast<float>(sf::Joystick::AxisCount + i + 4) * font.getLineSpacing(14))}); object.value.setPosition(
{80.f, 5.f + (static_cast<float>(sf::Joystick::AxisCount + i + 4) * font.getLineSpacing(14))});
object.value.setString("N/A"); object.value.setString("N/A");
} }
@ -170,15 +174,13 @@ int main()
{ {
// Window closed or escape key pressed: exit // Window closed or escape key pressed: exit
if ((event.type == sf::Event::Closed) || if ((event.type == sf::Event::Closed) ||
((event.type == sf::Event::KeyPressed) && (event.key.code == sf::Keyboard::Escape))) ((event.type == sf::Event::KeyPressed) && (event.key.code == sf::Keyboard::Escape)))
{ {
window.close(); window.close();
break; break;
} }
else if ((event.type == sf::Event::JoystickButtonPressed) || else if ((event.type == sf::Event::JoystickButtonPressed) || (event.type == sf::Event::JoystickButtonReleased) ||
(event.type == sf::Event::JoystickButtonReleased) || (event.type == sf::Event::JoystickMoved) || (event.type == sf::Event::JoystickConnected))
(event.type == sf::Event::JoystickMoved) ||
(event.type == sf::Event::JoystickConnected))
{ {
// Update displayed joystick values // Update displayed joystick values
updateValues(event.joystickConnect.joystickId); updateValues(event.joystickConnect.joystickId);

View File

@ -3,9 +3,10 @@
// Headers // Headers
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
#include <SFML/Graphics.hpp> #include <SFML/Graphics.hpp>
#include <array> #include <array>
#include <iostream>
#include <cstdlib> #include <cstdlib>
#include <iostream>
#define GLAD_GL_IMPLEMENTATION #define GLAD_GL_IMPLEMENTATION
#include <gl.h> #include <gl.h>
@ -42,7 +43,7 @@ int main()
{ {
// Request a 24-bits depth buffer when creating the window // Request a 24-bits depth buffer when creating the window
sf::ContextSettings contextSettings; sf::ContextSettings contextSettings;
contextSettings.depthBits = 24; contextSettings.depthBits = 24;
contextSettings.sRgbCapable = sRgb; contextSettings.sRgbCapable = sRgb;
// Create the main window // Create the main window
@ -79,7 +80,7 @@ int main()
// Attempt to generate a mipmap for our cube texture // Attempt to generate a mipmap for our cube texture
// We don't check the return value here since // We don't check the return value here since
// mipmapping is purely optional in this example // mipmapping is purely optional in this example
(void) texture.generateMipmap(); (void)texture.generateMipmap();
// Make the window the active window for OpenGL calls // Make the window the active window for OpenGL calls
if (!window.setActive(true)) if (!window.setActive(true))
@ -295,11 +296,11 @@ int main()
// We get the position of the mouse cursor (or touch), so that we can move the box accordingly // We get the position of the mouse cursor (or touch), so that we can move the box accordingly
sf::Vector2i pos; sf::Vector2i pos;
#ifdef SFML_SYSTEM_IOS #ifdef SFML_SYSTEM_IOS
pos = sf::Touch::getPosition(0); pos = sf::Touch::getPosition(0);
#else #else
pos = sf::Mouse::getPosition(window); pos = sf::Mouse::getPosition(window);
#endif #endif
float x = static_cast<float>(pos.x) * 200.f / static_cast<float>(window.getSize().x) - 100.f; float x = static_cast<float>(pos.x) * 200.f / static_cast<float>(window.getSize().x) - 100.f;
float y = -static_cast<float>(pos.y) * 200.f / static_cast<float>(window.getSize().y) + 100.f; float y = -static_cast<float>(pos.y) * 200.f / static_cast<float>(window.getSize().y) + 100.f;

View File

@ -5,6 +5,7 @@
// Headers // Headers
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
#include <SFML/Graphics.hpp> #include <SFML/Graphics.hpp>
#include <cassert> #include <cassert>
#include <string> #include <string>
@ -15,7 +16,6 @@
class Effect : public sf::Drawable class Effect : public sf::Drawable
{ {
public: public:
~Effect() override ~Effect() override
{ {
} }
@ -57,10 +57,7 @@ public:
} }
protected: protected:
Effect(const std::string& name) : m_name(name), m_isLoaded(false)
Effect(const std::string& name) :
m_name(name),
m_isLoaded(false)
{ {
} }
@ -71,16 +68,14 @@ protected:
} }
private: private:
// Virtual functions to be implemented in derived effects // Virtual functions to be implemented in derived effects
virtual bool onLoad() = 0; virtual bool onLoad() = 0;
virtual void onUpdate(float time, float x, float y) = 0; virtual void onUpdate(float time, float x, float y) = 0;
virtual void onDraw(sf::RenderTarget& target, const sf::RenderStates& states) const = 0; virtual void onDraw(sf::RenderTarget& target, const sf::RenderStates& states) const = 0;
private: private:
std::string m_name; std::string m_name;
bool m_isLoaded; bool m_isLoaded;
static const sf::Font* s_font; static const sf::Font* s_font;
}; };

View File

@ -2,16 +2,17 @@
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
// Headers // Headers
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
#include "Effect.hpp"
#include <array> #include <array>
#include <random> #include <random>
#include "Effect.hpp"
namespace namespace
{ {
std::random_device rd; std::random_device rd;
std::mt19937 rng(rd()); std::mt19937 rng(rd());
} } // namespace
const sf::Font* Effect::s_font = nullptr; const sf::Font* Effect::s_font = nullptr;
@ -21,9 +22,7 @@ const sf::Font* Effect::s_font = nullptr;
class Pixelate : public Effect class Pixelate : public Effect
{ {
public: public:
Pixelate() : Effect("Pixelate")
Pixelate() :
Effect("Pixelate")
{ {
} }
@ -55,10 +54,9 @@ public:
} }
private: private:
sf::Texture m_texture; sf::Texture m_texture;
sf::Sprite m_sprite; sf::Sprite m_sprite;
sf::Shader m_shader; sf::Shader m_shader;
}; };
@ -68,33 +66,32 @@ private:
class WaveBlur : public Effect class WaveBlur : public Effect
{ {
public: public:
WaveBlur() : Effect("Wave + Blur")
WaveBlur() :
Effect("Wave + Blur")
{ {
} }
bool onLoad() override bool onLoad() override
{ {
// Create the text // Create the text
m_text.setString("Praesent suscipit augue in velit pulvinar hendrerit varius purus aliquam.\n" m_text.setString(
"Mauris mi odio, bibendum quis fringilla a, laoreet vel orci. Proin vitae vulputate tortor.\n" "Praesent suscipit augue in velit pulvinar hendrerit varius purus aliquam.\n"
"Praesent cursus ultrices justo, ut feugiat ante vehicula quis.\n" "Mauris mi odio, bibendum quis fringilla a, laoreet vel orci. Proin vitae vulputate tortor.\n"
"Donec fringilla scelerisque mauris et viverra.\n" "Praesent cursus ultrices justo, ut feugiat ante vehicula quis.\n"
"Maecenas adipiscing ornare scelerisque. Nullam at libero elit.\n" "Donec fringilla scelerisque mauris et viverra.\n"
"Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas.\n" "Maecenas adipiscing ornare scelerisque. Nullam at libero elit.\n"
"Nullam leo urna, tincidunt id semper eget, ultricies sed mi.\n" "Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas.\n"
"Morbi mauris massa, commodo id dignissim vel, lobortis et elit.\n" "Nullam leo urna, tincidunt id semper eget, ultricies sed mi.\n"
"Fusce vel libero sed neque scelerisque venenatis.\n" "Morbi mauris massa, commodo id dignissim vel, lobortis et elit.\n"
"Integer mattis tincidunt quam vitae iaculis.\n" "Fusce vel libero sed neque scelerisque venenatis.\n"
"Vivamus fringilla sem non velit venenatis fermentum.\n" "Integer mattis tincidunt quam vitae iaculis.\n"
"Vivamus varius tincidunt nisi id vehicula.\n" "Vivamus fringilla sem non velit venenatis fermentum.\n"
"Integer ullamcorper, enim vitae euismod rutrum, massa nisl semper ipsum,\n" "Vivamus varius tincidunt nisi id vehicula.\n"
"vestibulum sodales sem ante in massa.\n" "Integer ullamcorper, enim vitae euismod rutrum, massa nisl semper ipsum,\n"
"Vestibulum in augue non felis convallis viverra.\n" "vestibulum sodales sem ante in massa.\n"
"Mauris ultricies dolor sed massa convallis sed aliquet augue fringilla.\n" "Vestibulum in augue non felis convallis viverra.\n"
"Duis erat eros, porta in accumsan in, blandit quis sem.\n" "Mauris ultricies dolor sed massa convallis sed aliquet augue fringilla.\n"
"In hac habitasse platea dictumst. Etiam fringilla est id odio dapibus sit amet semper dui laoreet.\n"); "Duis erat eros, porta in accumsan in, blandit quis sem.\n"
"In hac habitasse platea dictumst. Etiam fringilla est id odio dapibus sit amet semper dui laoreet.\n");
m_text.setFont(getFont()); m_text.setFont(getFont());
m_text.setCharacterSize(22); m_text.setCharacterSize(22);
m_text.setPosition({30.f, 20.f}); m_text.setPosition({30.f, 20.f});
@ -121,8 +118,7 @@ public:
} }
private: private:
sf::Text m_text;
sf::Text m_text;
sf::Shader m_shader; sf::Shader m_shader;
}; };
@ -133,16 +129,14 @@ private:
class StormBlink : public Effect class StormBlink : public Effect
{ {
public: public:
StormBlink() : Effect("Storm + Blink")
StormBlink() :
Effect("Storm + Blink")
{ {
} }
bool onLoad() override bool onLoad() override
{ {
std::uniform_real_distribution<float> x_distribution(0, 800); std::uniform_real_distribution<float> x_distribution(0, 800);
std::uniform_real_distribution<float> y_distribution(0, 600); std::uniform_real_distribution<float> y_distribution(0, 600);
std::uniform_int_distribution<sf::Uint16> color_distribution(0, 255); std::uniform_int_distribution<sf::Uint16> color_distribution(0, 255);
// Create the points // Create the points
@ -181,9 +175,8 @@ public:
} }
private: private:
sf::VertexArray m_points; sf::VertexArray m_points;
sf::Shader m_shader; sf::Shader m_shader;
}; };
@ -193,9 +186,7 @@ private:
class Edge : public Effect class Edge : public Effect
{ {
public: public:
Edge() : Effect("Edge Post-effect")
Edge() :
Effect("Edge Post-effect")
{ {
} }
@ -241,8 +232,10 @@ public:
for (std::size_t i = 0; i < m_entities.size(); ++i) for (std::size_t i = 0; i < m_entities.size(); ++i)
{ {
sf::Vector2f position; sf::Vector2f position;
position.x = std::cos(0.25f * (time * static_cast<float>(i) + static_cast<float>(m_entities.size() - i))) * 300 + 350; position.x = std::cos(0.25f * (time * static_cast<float>(i) + static_cast<float>(m_entities.size() - i))) * 300 +
position.y = std::sin(0.25f * (time * static_cast<float>(m_entities.size() - i) + static_cast<float>(i))) * 200 + 250; 350;
position.y = std::sin(0.25f * (time * static_cast<float>(m_entities.size() - i) + static_cast<float>(i))) * 200 +
250;
m_entities[i].setPosition(position); m_entities[i].setPosition(position);
} }
@ -262,13 +255,12 @@ public:
} }
private: private:
sf::RenderTexture m_surface;
sf::RenderTexture m_surface; sf::Texture m_backgroundTexture;
sf::Texture m_backgroundTexture; sf::Texture m_entityTexture;
sf::Texture m_entityTexture; sf::Sprite m_backgroundSprite;
sf::Sprite m_backgroundSprite;
std::vector<sf::Sprite> m_entities; std::vector<sf::Sprite> m_entities;
sf::Shader m_shader; sf::Shader m_shader;
}; };
@ -278,10 +270,7 @@ private:
class Geometry : public Effect class Geometry : public Effect
{ {
public: public:
Geometry() : Effect("Geometry Shader Billboards"), m_pointCloud(sf::Points, 10000)
Geometry() :
Effect("Geometry Shader Billboards"),
m_pointCloud(sf::Points, 10000)
{ {
} }
@ -336,8 +325,8 @@ public:
sf::RenderStates statesCopy(states); sf::RenderStates statesCopy(states);
// Prepare the render state // Prepare the render state
statesCopy.shader = &m_shader; statesCopy.shader = &m_shader;
statesCopy.texture = &m_logoTexture; statesCopy.texture = &m_logoTexture;
statesCopy.transform = m_transform; statesCopy.transform = m_transform;
// Draw the point cloud // Draw the point cloud
@ -345,10 +334,9 @@ public:
} }
private: private:
sf::Texture m_logoTexture;
sf::Texture m_logoTexture; sf::Transform m_transform;
sf::Transform m_transform; sf::Shader m_shader;
sf::Shader m_shader;
sf::VertexArray m_pointCloud; sf::VertexArray m_pointCloud;
}; };
@ -362,8 +350,7 @@ private:
int main() int main()
{ {
// Create the main window // Create the main window
sf::RenderWindow window(sf::VideoMode({800, 600}), "SFML Shader", sf::RenderWindow window(sf::VideoMode({800, 600}), "SFML Shader", sf::Style::Titlebar | sf::Style::Close);
sf::Style::Titlebar | sf::Style::Close);
window.setVerticalSyncEnabled(true); window.setVerticalSyncEnabled(true);
// Load the application font and pass it to the Effect class // Load the application font and pass it to the Effect class
@ -373,19 +360,13 @@ int main()
Effect::setFont(font); Effect::setFont(font);
// Create the effects // Create the effects
Pixelate pixelateEffect; Pixelate pixelateEffect;
WaveBlur waveBlurEffect; WaveBlur waveBlurEffect;
StormBlink stormBlinkEffect; StormBlink stormBlinkEffect;
Edge edgeEffect; Edge edgeEffect;
Geometry geometryEffect; Geometry geometryEffect;
const std::array<Effect*, 5> effects{ const std::array<Effect*, 5> effects{&pixelateEffect, &waveBlurEffect, &stormBlinkEffect, &edgeEffect, &geometryEffect};
&pixelateEffect,
&waveBlurEffect,
&stormBlinkEffect,
&edgeEffect,
&geometryEffect
};
std::size_t current = 0; std::size_t current = 0;
@ -461,9 +442,12 @@ int main()
effects[current]->update(clock.getElapsedTime().asSeconds(), x, y); effects[current]->update(clock.getElapsedTime().asSeconds(), x, y);
// Clear the window // Clear the window
if(effects[current]->getName() == "Edge Post-effect"){ if (effects[current]->getName() == "Edge Post-effect")
{
window.clear(sf::Color::White); window.clear(sf::Color::White);
} else { }
else
{
window.clear(sf::Color(50, 50, 50)); window.clear(sf::Color(50, 50, 50));
} }

View File

@ -2,8 +2,8 @@
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
// Headers // Headers
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
#include <iostream>
#include <cstdlib> #include <cstdlib>
#include <iostream>
void runTcpServer(unsigned short port); void runTcpServer(unsigned short port);
@ -26,12 +26,12 @@ int main()
// TCP, UDP or connected UDP ? // TCP, UDP or connected UDP ?
char protocol; char protocol;
std::cout << "Do you want to use TCP (t) or UDP (u)? "; std::cout << "Do you want to use TCP (t) or UDP (u)? ";
std::cin >> protocol; std::cin >> protocol;
// Client or server ? // Client or server ?
char who; char who;
std::cout << "Do you want to be a server (s) or a client (c)? "; std::cout << "Do you want to be a server (s) or a client (c)? ";
std::cin >> who; std::cin >> who;
if (protocol == 't') if (protocol == 't')
{ {

View File

@ -3,6 +3,7 @@
// Headers // Headers
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
#include <SFML/Network.hpp> #include <SFML/Network.hpp>
#include <iomanip> #include <iomanip>
#include <iostream> #include <iostream>
@ -35,7 +36,7 @@ void runTcpServer(unsigned short port)
std::cout << "Message sent to the client: " << std::quoted(out) << std::endl; std::cout << "Message sent to the client: " << std::quoted(out) << std::endl;
// Receive a message back from the client // Receive a message back from the client
char in[128]; char in[128];
std::size_t received; std::size_t received;
if (socket.receive(in, sizeof(in), received) != sf::Socket::Done) if (socket.receive(in, sizeof(in), received) != sf::Socket::Done)
return; return;
@ -55,9 +56,8 @@ void runTcpClient(unsigned short port)
do do
{ {
std::cout << "Type the address or name of the server to connect to: "; std::cout << "Type the address or name of the server to connect to: ";
std::cin >> server; std::cin >> server;
} } while (!server.has_value());
while (!server.has_value());
// Create a socket for communicating with the server // Create a socket for communicating with the server
sf::TcpSocket socket; sf::TcpSocket socket;
@ -68,7 +68,7 @@ void runTcpClient(unsigned short port)
std::cout << "Connected to server " << server.value() << std::endl; std::cout << "Connected to server " << server.value() << std::endl;
// Receive a message from the server // Receive a message from the server
char in[128]; char in[128];
std::size_t received; std::size_t received;
if (socket.receive(in, sizeof(in), received) != sf::Socket::Done) if (socket.receive(in, sizeof(in), received) != sf::Socket::Done)
return; return;

View File

@ -3,6 +3,7 @@
// Headers // Headers
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
#include <SFML/Network.hpp> #include <SFML/Network.hpp>
#include <iomanip> #include <iomanip>
#include <iostream> #include <iostream>
#include <optional> #include <optional>
@ -23,10 +24,10 @@ void runUdpServer(unsigned short port)
std::cout << "Server is listening to port " << port << ", waiting for a message... " << std::endl; std::cout << "Server is listening to port " << port << ", waiting for a message... " << std::endl;
// Wait for a message // Wait for a message
char in[128]; char in[128];
std::size_t received; std::size_t received;
std::optional<sf::IpAddress> sender; std::optional<sf::IpAddress> sender;
unsigned short senderPort; unsigned short senderPort;
if (socket.receive(in, sizeof(in), received, sender, senderPort) != sf::Socket::Done) if (socket.receive(in, sizeof(in), received, sender, senderPort) != sf::Socket::Done)
return; return;
std::cout << "Message received from client " << sender.value() << ": " << std::quoted(in) << std::endl; std::cout << "Message received from client " << sender.value() << ": " << std::quoted(in) << std::endl;
@ -50,9 +51,8 @@ void runUdpClient(unsigned short port)
do do
{ {
std::cout << "Type the address or name of the server to connect to: "; std::cout << "Type the address or name of the server to connect to: ";
std::cin >> server; std::cin >> server;
} } while (!server.has_value());
while (!server.has_value());
// Create a socket for communicating with the server // Create a socket for communicating with the server
sf::UdpSocket socket; sf::UdpSocket socket;
@ -64,10 +64,10 @@ void runUdpClient(unsigned short port)
std::cout << "Message sent to the server: " << std::quoted(out) << std::endl; std::cout << "Message sent to the server: " << std::quoted(out) << std::endl;
// Receive an answer from anyone (but most likely from the server) // Receive an answer from anyone (but most likely from the server)
char in[128]; char in[128];
std::size_t received; std::size_t received;
std::optional<sf::IpAddress> sender; std::optional<sf::IpAddress> sender;
unsigned short senderPort; unsigned short senderPort;
if (socket.receive(in, sizeof(in), received, sender, senderPort) != sf::Socket::Done) if (socket.receive(in, sizeof(in), received, sender, senderPort) != sf::Socket::Done)
return; return;
std::cout << "Message received from " << sender.value() << ": " << std::quoted(in) << std::endl; std::cout << "Message received from " << sender.value() << ": " << std::quoted(in) << std::endl;

View File

@ -3,6 +3,7 @@
// Headers // Headers
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
#include <SFML/Audio.hpp> #include <SFML/Audio.hpp>
#include <iostream> #include <iostream>
#include <string> #include <string>
@ -20,9 +21,9 @@ void playSound()
// Display sound informations // Display sound informations
std::cout << "killdeer.wav:" << '\n' std::cout << "killdeer.wav:" << '\n'
<< " " << buffer.getDuration().asSeconds() << " seconds" << '\n' << " " << buffer.getDuration().asSeconds() << " seconds" << '\n'
<< " " << buffer.getSampleRate() << " samples / sec" << '\n' << " " << buffer.getSampleRate() << " samples / sec" << '\n'
<< " " << buffer.getChannelCount() << " channels" << std::endl; << " " << buffer.getChannelCount() << " channels" << std::endl;
// Create a sound instance and play it // Create a sound instance and play it
sf::Sound sound(buffer); sf::Sound sound(buffer);
@ -55,9 +56,9 @@ void playMusic(const std::filesystem::path& filename)
// Display music informations // Display music informations
std::cout << filename << ":" << '\n' std::cout << filename << ":" << '\n'
<< " " << music.getDuration().asSeconds() << " seconds" << '\n' << " " << music.getDuration().asSeconds() << " seconds" << '\n'
<< " " << music.getSampleRate() << " samples / sec" << '\n' << " " << music.getSampleRate() << " samples / sec" << '\n'
<< " " << music.getChannelCount() << " channels" << std::endl; << " " << music.getChannelCount() << " channels" << std::endl;
// Play it // Play it
music.play(); music.play();

View File

@ -3,8 +3,9 @@
// Headers // Headers
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
#include <SFML/Audio.hpp> #include <SFML/Audio.hpp>
#include <iostream>
#include <cstdlib> #include <cstdlib>
#include <iostream>
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
@ -25,7 +26,7 @@ int main()
// Choose the sample rate // Choose the sample rate
unsigned int sampleRate; unsigned int sampleRate;
std::cout << "Please choose the sample rate for sound capture (44100 is CD quality): "; std::cout << "Please choose the sample rate for sound capture (44100 is CD quality): ";
std::cin >> sampleRate; std::cin >> sampleRate;
std::cin.ignore(10000, '\n'); std::cin.ignore(10000, '\n');
// Wait for user input... // Wait for user input...
@ -51,14 +52,14 @@ int main()
// Display captured sound informations // Display captured sound informations
std::cout << "Sound information:" << '\n' std::cout << "Sound information:" << '\n'
<< " " << buffer.getDuration().asSeconds() << " seconds" << '\n' << " " << buffer.getDuration().asSeconds() << " seconds" << '\n'
<< " " << buffer.getSampleRate() << " samples / seconds" << '\n' << " " << buffer.getSampleRate() << " samples / seconds" << '\n'
<< " " << buffer.getChannelCount() << " channels" << std::endl; << " " << buffer.getChannelCount() << " channels" << std::endl;
// Choose what to do with the recorded sound data // Choose what to do with the recorded sound data
char choice; char choice;
std::cout << "What do you want to do with captured sound (p = play, s = save) ? "; std::cout << "What do you want to do with captured sound (p = play, s = save) ? ";
std::cin >> choice; std::cin >> choice;
std::cin.ignore(10000, '\n'); std::cin.ignore(10000, '\n');
if (choice == 's') if (choice == 's')

View File

@ -2,8 +2,9 @@
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
// Headers // Headers
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
#include <SFML/Graphics.hpp>
#include <SFML/Audio.hpp> #include <SFML/Audio.hpp>
#include <SFML/Graphics.hpp>
#include <random> #include <random>
#ifdef SFML_SYSTEM_IOS #ifdef SFML_SYSTEM_IOS
@ -28,16 +29,17 @@ std::filesystem::path resourcesDir()
int main() int main()
{ {
std::random_device rd; std::random_device rd;
std::mt19937 rng(rd()); std::mt19937 rng(rd());
// Define some constants // Define some constants
const float gameWidth = 800; const float gameWidth = 800;
const float gameHeight = 600; const float gameHeight = 600;
sf::Vector2f paddleSize(25, 100); sf::Vector2f paddleSize(25, 100);
float ballRadius = 10.f; float ballRadius = 10.f;
// Create the window of the application // Create the window of the application
sf::RenderWindow window(sf::VideoMode({static_cast<unsigned int>(gameWidth), static_cast<unsigned int>(gameHeight)}, 32), "SFML Tennis", sf::RenderWindow window(sf::VideoMode({static_cast<unsigned int>(gameWidth), static_cast<unsigned int>(gameHeight)}, 32),
"SFML Tennis",
sf::Style::Titlebar | sf::Style::Close); sf::Style::Titlebar | sf::Style::Close);
window.setVerticalSyncEnabled(true); window.setVerticalSyncEnabled(true);
@ -49,7 +51,7 @@ int main()
// Create the SFML logo texture: // Create the SFML logo texture:
sf::Texture sfmlLogoTexture; sf::Texture sfmlLogoTexture;
if(!sfmlLogoTexture.loadFromFile(resourcesDir() / "sfml_logo.png")) if (!sfmlLogoTexture.loadFromFile(resourcesDir() / "sfml_logo.png"))
return EXIT_FAILURE; return EXIT_FAILURE;
sf::Sprite sfmlLogo; sf::Sprite sfmlLogo;
sfmlLogo.setTexture(sfmlLogoTexture); sfmlLogo.setTexture(sfmlLogoTexture);
@ -91,22 +93,22 @@ int main()
pauseMessage.setPosition({170.f, 200.f}); pauseMessage.setPosition({170.f, 200.f});
pauseMessage.setFillColor(sf::Color::White); pauseMessage.setFillColor(sf::Color::White);
#ifdef SFML_SYSTEM_IOS #ifdef SFML_SYSTEM_IOS
pauseMessage.setString("Welcome to SFML Tennis!\nTouch the screen to start the game."); pauseMessage.setString("Welcome to SFML Tennis!\nTouch the screen to start the game.");
#else #else
pauseMessage.setString("Welcome to SFML Tennis!\n\nPress space to start the game."); pauseMessage.setString("Welcome to SFML Tennis!\n\nPress space to start the game.");
#endif #endif
// Define the paddles properties // Define the paddles properties
sf::Clock AITimer; sf::Clock AITimer;
const sf::Time AITime = sf::seconds(0.1f); const sf::Time AITime = sf::seconds(0.1f);
const float paddleSpeed = 400.f; const float paddleSpeed = 400.f;
float rightPaddleSpeed = 0.f; float rightPaddleSpeed = 0.f;
const float ballSpeed = 400.f; const float ballSpeed = 400.f;
sf::Angle ballAngle = sf::degrees(0); // to be changed later sf::Angle ballAngle = sf::degrees(0); // to be changed later
sf::Clock clock; sf::Clock clock;
bool isPlaying = false; bool isPlaying = false;
while (window.isOpen()) while (window.isOpen())
{ {
// Handle events // Handle events
@ -114,7 +116,7 @@ int main()
{ {
// Window closed or escape key pressed: exit // Window closed or escape key pressed: exit
if ((event.type == sf::Event::Closed) || if ((event.type == sf::Event::Closed) ||
((event.type == sf::Event::KeyPressed) && (event.key.code == sf::Keyboard::Escape))) ((event.type == sf::Event::KeyPressed) && (event.key.code == sf::Keyboard::Escape)))
{ {
window.close(); window.close();
break; break;
@ -140,8 +142,7 @@ int main()
{ {
// Make sure the ball initial angle is not too much vertical // Make sure the ball initial angle is not too much vertical
ballAngle = sf::degrees(std::uniform_real_distribution<float>(0, 360)(rng)); ballAngle = sf::degrees(std::uniform_real_distribution<float>(0, 360)(rng));
} } while (std::abs(std::cos(ballAngle.asRadians())) < 0.7f);
while (std::abs(std::cos(ballAngle.asRadians())) < 0.7f);
} }
} }
@ -160,20 +161,19 @@ int main()
float deltaTime = clock.restart().asSeconds(); float deltaTime = clock.restart().asSeconds();
// Move the player's paddle // Move the player's paddle
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Up) && if (sf::Keyboard::isKeyPressed(sf::Keyboard::Up) && (leftPaddle.getPosition().y - paddleSize.y / 2 > 5.f))
(leftPaddle.getPosition().y - paddleSize.y / 2 > 5.f))
{ {
leftPaddle.move({0.f, -paddleSpeed * deltaTime}); leftPaddle.move({0.f, -paddleSpeed * deltaTime});
} }
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Down) && if (sf::Keyboard::isKeyPressed(sf::Keyboard::Down) &&
(leftPaddle.getPosition().y + paddleSize.y / 2 < gameHeight - 5.f)) (leftPaddle.getPosition().y + paddleSize.y / 2 < gameHeight - 5.f))
{ {
leftPaddle.move({0.f, paddleSpeed * deltaTime}); leftPaddle.move({0.f, paddleSpeed * deltaTime});
} }
if (sf::Touch::isDown(0)) if (sf::Touch::isDown(0))
{ {
sf::Vector2i pos = sf::Touch::getPosition(0); sf::Vector2i pos = sf::Touch::getPosition(0);
sf::Vector2f mappedPos = window.mapPixelToCoords(pos); sf::Vector2f mappedPos = window.mapPixelToCoords(pos);
leftPaddle.setPosition({leftPaddle.getPosition().x, mappedPos.y}); leftPaddle.setPosition({leftPaddle.getPosition().x, mappedPos.y});
} }
@ -200,11 +200,11 @@ int main()
// Move the ball // Move the ball
ball.move({ballSpeed * deltaTime, ballAngle}); ball.move({ballSpeed * deltaTime, ballAngle});
#ifdef SFML_SYSTEM_IOS #ifdef SFML_SYSTEM_IOS
const std::string inputString = "Touch the screen to restart."; const std::string inputString = "Touch the screen to restart.";
#else #else
const std::string inputString = "Press space to restart or\nescape to exit."; const std::string inputString = "Press space to restart or\nescape to exit.";
#endif #endif
// Check collisions between the ball and the screen // Check collisions between the ball and the screen
if (ball.getPosition().x - ballRadius < 0.f) if (ball.getPosition().x - ballRadius < 0.f)

View File

@ -4,6 +4,7 @@
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
#include <SFML/Audio.hpp> #include <SFML/Audio.hpp>
#include <SFML/Network.hpp> #include <SFML/Network.hpp>
#include <iostream> #include <iostream>
@ -18,7 +19,6 @@ const sf::Uint8 clientEndOfStream = 2;
class NetworkRecorder : public sf::SoundRecorder class NetworkRecorder : public sf::SoundRecorder
{ {
public: public:
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// Constructor /// Constructor
/// ///
@ -26,9 +26,7 @@ public:
/// \param port Port of the remote host /// \param port Port of the remote host
/// ///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
NetworkRecorder(const sf::IpAddress& host, unsigned short port) : NetworkRecorder(const sf::IpAddress& host, unsigned short port) : m_host(host), m_port(port)
m_host(host),
m_port(port)
{ {
} }
@ -45,7 +43,6 @@ public:
} }
private: private:
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \see SoundRecorder::onStart /// \see SoundRecorder::onStart
/// ///
@ -125,9 +122,8 @@ void doClient(unsigned short port)
do do
{ {
std::cout << "Type address or name of the server to connect to: "; std::cout << "Type address or name of the server to connect to: ";
std::cin >> server; std::cin >> server;
} } while (!server.has_value());
while (!server.has_value());
// Create an instance of our custom recorder // Create an instance of our custom recorder
NetworkRecorder recorder(server.value(), port); NetworkRecorder recorder(server.value(), port);

View File

@ -4,6 +4,7 @@
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
#include <SFML/Audio.hpp> #include <SFML/Audio.hpp>
#include <SFML/Network.hpp> #include <SFML/Network.hpp>
#include <cstring> #include <cstring>
#include <iostream> #include <iostream>
#include <iterator> #include <iterator>
@ -21,14 +22,11 @@ const sf::Uint8 serverEndOfStream = 2;
class NetworkAudioStream : public sf::SoundStream class NetworkAudioStream : public sf::SoundStream
{ {
public: public:
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// Default constructor /// Default constructor
/// ///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
NetworkAudioStream() : NetworkAudioStream() : m_offset(0), m_hasFinished(false)
m_offset (0),
m_hasFinished(false)
{ {
// Set the sound parameters // Set the sound parameters
initialize(1, 44100); initialize(1, 44100);
@ -66,7 +64,6 @@ public:
} }
private: private:
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// /see SoundStream::OnGetData /// /see SoundStream::OnGetData
/// ///
@ -85,7 +82,8 @@ private:
// (don't forget that we run in two separate threads) // (don't forget that we run in two separate threads)
{ {
std::scoped_lock lock(m_mutex); std::scoped_lock lock(m_mutex);
m_tempBuffer.assign(m_samples.begin() + static_cast<std::vector<sf::Int64>::difference_type>(m_offset), m_samples.end()); m_tempBuffer.assign(m_samples.begin() + static_cast<std::vector<sf::Int64>::difference_type>(m_offset),
m_samples.end());
} }
// Fill audio data to pass to the stream // Fill audio data to pass to the stream
@ -133,9 +131,11 @@ private:
// (so we protect any operation on it with the mutex) // (so we protect any operation on it with the mutex)
{ {
std::scoped_lock lock(m_mutex); std::scoped_lock lock(m_mutex);
std::size_t oldSize = m_samples.size(); std::size_t oldSize = m_samples.size();
m_samples.resize(oldSize + sampleCount); m_samples.resize(oldSize + sampleCount);
std::memcpy(&(m_samples[oldSize]), static_cast<const char*>(packet.getData()) + 1, sampleCount * sizeof(sf::Int16)); std::memcpy(&(m_samples[oldSize]),
static_cast<const char*>(packet.getData()) + 1,
sampleCount * sizeof(sf::Int16));
} }
} }
else if (id == serverEndOfStream) else if (id == serverEndOfStream)

View File

@ -2,8 +2,8 @@
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
// Headers // Headers
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
#include <iostream>
#include <cstdlib> #include <cstdlib>
#include <iostream>
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
@ -28,7 +28,7 @@ int main()
// Client or server ? // Client or server ?
char who; char who;
std::cout << "Do you want to be a server ('s') or a client ('c')? "; std::cout << "Do you want to be a server ('s') or a client ('c')? ";
std::cin >> who; std::cin >> who;
if (who == 's') if (who == 's')
{ {

File diff suppressed because it is too large Load Diff

View File

@ -6,8 +6,8 @@
#ifndef WIN32_LEAN_AND_MEAN #ifndef WIN32_LEAN_AND_MEAN
#define WIN32_LEAN_AND_MEAN #define WIN32_LEAN_AND_MEAN
#endif #endif
#include <windows.h>
#include <cmath> #include <cmath>
#include <windows.h>
HWND button; HWND button;
@ -69,14 +69,44 @@ int main()
RegisterClass(&windowClass); RegisterClass(&windowClass);
// Let's create the main window // Let's create the main window
HWND window = CreateWindow(TEXT("SFML App"), TEXT("SFML Win32"), WS_SYSMENU | WS_VISIBLE, 200, 200, 660, 520, nullptr, nullptr, instance, nullptr); HWND window = CreateWindow(TEXT("SFML App"),
TEXT("SFML Win32"),
WS_SYSMENU | WS_VISIBLE,
200,
200,
660,
520,
nullptr,
nullptr,
instance,
nullptr);
// Add a button for exiting // Add a button for exiting
button = CreateWindow(TEXT("BUTTON"), TEXT("Quit"), WS_CHILD | WS_VISIBLE, 560, 440, 80, 40, window, nullptr, instance, nullptr); button = CreateWindow(TEXT("BUTTON"), TEXT("Quit"), WS_CHILD | WS_VISIBLE, 560, 440, 80, 40, window, nullptr, instance, nullptr);
// Let's create two SFML views // Let's create two SFML views
HWND view1 = CreateWindow(TEXT("STATIC"), nullptr, WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS, 20, 20, 300, 400, window, nullptr, instance, nullptr); HWND view1 = CreateWindow(TEXT("STATIC"),
HWND view2 = CreateWindow(TEXT("STATIC"), nullptr, WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS, 340, 20, 300, 400, window, nullptr, instance, nullptr); nullptr,
WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS,
20,
20,
300,
400,
window,
nullptr,
instance,
nullptr);
HWND view2 = CreateWindow(TEXT("STATIC"),
nullptr,
WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS,
340,
20,
300,
400,
window,
nullptr,
instance,
nullptr);
sf::RenderWindow SFMLView1(view1); sf::RenderWindow SFMLView1(view1);
sf::RenderWindow SFMLView2(view2); sf::RenderWindow SFMLView2(view2);

View File

@ -2,6 +2,7 @@
// Headers // Headers
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
#include <SFML/Window.hpp> #include <SFML/Window.hpp>
#include <cstdlib> #include <cstdlib>
#define GLAD_GL_IMPLEMENTATION #define GLAD_GL_IMPLEMENTATION
@ -12,8 +13,8 @@
#endif #endif
#include <array> #include <array>
#include <iostream>
#include <cstdlib> #include <cstdlib>
#include <iostream>
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// Entry point of application /// Entry point of application

View File

@ -29,7 +29,6 @@
// Headers // Headers
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
#include <SFML/System.hpp>
#include <SFML/Audio/InputSoundFile.hpp> #include <SFML/Audio/InputSoundFile.hpp>
#include <SFML/Audio/Listener.hpp> #include <SFML/Audio/Listener.hpp>
#include <SFML/Audio/Music.hpp> #include <SFML/Audio/Music.hpp>
@ -43,6 +42,7 @@
#include <SFML/Audio/SoundRecorder.hpp> #include <SFML/Audio/SoundRecorder.hpp>
#include <SFML/Audio/SoundSource.hpp> #include <SFML/Audio/SoundSource.hpp>
#include <SFML/Audio/SoundStream.hpp> #include <SFML/Audio/SoundStream.hpp>
#include <SFML/System.hpp>
#endif // SFML_AUDIO_HPP #endif // SFML_AUDIO_HPP

View File

@ -40,7 +40,6 @@ namespace sf
class SFML_AUDIO_API AlResource class SFML_AUDIO_API AlResource
{ {
protected: protected:
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \brief Default constructor /// \brief Default constructor
/// ///

View File

@ -36,11 +36,11 @@
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
#if defined(SFML_AUDIO_EXPORTS) #if defined(SFML_AUDIO_EXPORTS)
#define SFML_AUDIO_API SFML_API_EXPORT #define SFML_AUDIO_API SFML_API_EXPORT
#else #else
#define SFML_AUDIO_API SFML_API_IMPORT #define SFML_AUDIO_API SFML_API_IMPORT
#endif #endif

View File

@ -29,10 +29,11 @@
// Headers // Headers
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
#include <SFML/Audio/Export.hpp> #include <SFML/Audio/Export.hpp>
#include <cstddef>
#include <filesystem> #include <filesystem>
#include <memory> #include <memory>
#include <string> #include <string>
#include <cstddef>
namespace sf namespace sf
@ -48,7 +49,6 @@ class SoundFileReader;
class SFML_AUDIO_API InputSoundFile class SFML_AUDIO_API InputSoundFile
{ {
public: public:
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \brief Default constructor /// \brief Default constructor
/// ///

View File

@ -29,6 +29,7 @@
// Headers // Headers
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
#include <SFML/Audio/Export.hpp> #include <SFML/Audio/Export.hpp>
#include <SFML/System/Vector3.hpp> #include <SFML/System/Vector3.hpp>
@ -42,7 +43,6 @@ namespace sf
class SFML_AUDIO_API Listener class SFML_AUDIO_API Listener
{ {
public: public:
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \brief Change the global volume of all the sounds and musics /// \brief Change the global volume of all the sounds and musics
/// ///

View File

@ -29,8 +29,10 @@
// Headers // Headers
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
#include <SFML/Audio/Export.hpp> #include <SFML/Audio/Export.hpp>
#include <SFML/Audio/SoundStream.hpp>
#include <SFML/Audio/InputSoundFile.hpp> #include <SFML/Audio/InputSoundFile.hpp>
#include <SFML/Audio/SoundStream.hpp>
#include <filesystem> #include <filesystem>
#include <string> #include <string>
#include <vector> #include <vector>
@ -48,7 +50,6 @@ class InputStream;
class SFML_AUDIO_API Music : public SoundStream class SFML_AUDIO_API Music : public SoundStream
{ {
public: public:
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \brief Structure defining a time range using the template type /// \brief Structure defining a time range using the template type
/// ///
@ -62,7 +63,6 @@ public:
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
Span() Span()
{ {
} }
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
@ -72,11 +72,8 @@ public:
/// \param len Initial Length /// \param len Initial Length
/// ///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
Span(T off, T len): Span(T off, T len) : offset(off), length(len)
offset(off),
length(len)
{ {
} }
T offset; //!< The beginning offset of the time range T offset; //!< The beginning offset of the time range
@ -211,7 +208,6 @@ public:
void setLoopPoints(TimeSpan timePoints); void setLoopPoints(TimeSpan timePoints);
protected: protected:
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \brief Request a new chunk of audio samples from the stream source /// \brief Request a new chunk of audio samples from the stream source
/// ///
@ -246,7 +242,6 @@ protected:
Int64 onLoop() override; Int64 onLoop() override;
private: private:
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \brief Initialize the internal state after loading a new music /// \brief Initialize the internal state after loading a new music
/// ///

View File

@ -29,6 +29,7 @@
// Headers // Headers
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
#include <SFML/Audio/Export.hpp> #include <SFML/Audio/Export.hpp>
#include <filesystem> #include <filesystem>
#include <memory> #include <memory>
#include <string> #include <string>
@ -45,7 +46,6 @@ class SoundFileWriter;
class SFML_AUDIO_API OutputSoundFile class SFML_AUDIO_API OutputSoundFile
{ {
public: public:
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \brief Default constructor /// \brief Default constructor
/// ///
@ -102,7 +102,6 @@ public:
void close(); void close();
private: private:
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
// Member data // Member data
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////

View File

@ -29,7 +29,9 @@
// Headers // Headers
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
#include <SFML/Audio/Export.hpp> #include <SFML/Audio/Export.hpp>
#include <SFML/Audio/SoundSource.hpp> #include <SFML/Audio/SoundSource.hpp>
#include <cstdlib> #include <cstdlib>
@ -45,7 +47,6 @@ class SoundBuffer;
class SFML_AUDIO_API Sound : public SoundSource class SFML_AUDIO_API Sound : public SoundSource
{ {
public: public:
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \brief Default constructor /// \brief Default constructor
/// ///
@ -199,7 +200,7 @@ public:
/// \return Reference to self /// \return Reference to self
/// ///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
Sound& operator =(const Sound& right); Sound& operator=(const Sound& right);
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \brief Reset the internal buffer of the sound /// \brief Reset the internal buffer of the sound
@ -213,7 +214,6 @@ public:
void resetBuffer(); void resetBuffer();
private: private:
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
// Member data // Member data
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////

View File

@ -29,12 +29,14 @@
// Headers // Headers
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
#include <SFML/Audio/Export.hpp> #include <SFML/Audio/Export.hpp>
#include <SFML/Audio/AlResource.hpp> #include <SFML/Audio/AlResource.hpp>
#include <SFML/System/Time.hpp> #include <SFML/System/Time.hpp>
#include <filesystem> #include <filesystem>
#include <string> #include <string>
#include <vector>
#include <unordered_set> #include <unordered_set>
#include <vector>
namespace sf namespace sf
@ -50,7 +52,6 @@ class InputStream;
class SFML_AUDIO_API SoundBuffer : AlResource class SFML_AUDIO_API SoundBuffer : AlResource
{ {
public: public:
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \brief Default constructor /// \brief Default constructor
/// ///
@ -222,10 +223,9 @@ public:
/// \return Reference to self /// \return Reference to self
/// ///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
SoundBuffer& operator =(const SoundBuffer& right); SoundBuffer& operator=(const SoundBuffer& right);
private: private:
friend class Sound; friend class Sound;
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
@ -268,7 +268,7 @@ private:
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
// Types // Types
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
using SoundList = std::unordered_set<Sound *>; //!< Set of unique sound instances using SoundList = std::unordered_set<Sound*>; //!< Set of unique sound instances
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
// Member data // Member data

View File

@ -29,8 +29,10 @@
// Headers // Headers
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
#include <SFML/Audio/Export.hpp> #include <SFML/Audio/Export.hpp>
#include <SFML/Audio/SoundBuffer.hpp> #include <SFML/Audio/SoundBuffer.hpp>
#include <SFML/Audio/SoundRecorder.hpp> #include <SFML/Audio/SoundRecorder.hpp>
#include <vector> #include <vector>
@ -44,7 +46,6 @@ namespace sf
class SFML_AUDIO_API SoundBufferRecorder : public SoundRecorder class SFML_AUDIO_API SoundBufferRecorder : public SoundRecorder
{ {
public: public:
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \brief destructor /// \brief destructor
/// ///
@ -65,7 +66,6 @@ public:
const SoundBuffer& getBuffer() const; const SoundBuffer& getBuffer() const;
protected: protected:
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \brief Start capturing audio data /// \brief Start capturing audio data
/// ///
@ -92,7 +92,6 @@ protected:
void onStop() override; void onStop() override;
private: private:
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
// Member data // Member data
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////

View File

@ -29,6 +29,7 @@
// Headers // Headers
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
#include <SFML/Audio/Export.hpp> #include <SFML/Audio/Export.hpp>
#include <filesystem> #include <filesystem>
#include <memory> #include <memory>
#include <string> #include <string>
@ -48,7 +49,6 @@ class SoundFileWriter;
class SFML_AUDIO_API SoundFileFactory class SFML_AUDIO_API SoundFileFactory
{ {
public: public:
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \brief Register a new reader /// \brief Register a new reader
/// ///
@ -133,7 +133,6 @@ public:
static std::unique_ptr<SoundFileWriter> createWriterFromFilename(const std::filesystem::path& filename); static std::unique_ptr<SoundFileWriter> createWriterFromFilename(const std::filesystem::path& filename);
private: private:
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
// Types // Types
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////

View File

@ -31,9 +31,17 @@ namespace sf
{ {
namespace priv namespace priv
{ {
template <typename T> std::unique_ptr<SoundFileReader> createReader() { return std::make_unique<T>(); } template <typename T>
template <typename T> std::unique_ptr<SoundFileWriter> createWriter() { return std::make_unique<T>(); } std::unique_ptr<SoundFileReader> createReader()
{
return std::make_unique<T>();
} }
template <typename T>
std::unique_ptr<SoundFileWriter> createWriter()
{
return std::make_unique<T>();
}
} // namespace priv
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
template <typename T> template <typename T>
@ -44,7 +52,7 @@ void SoundFileFactory::registerReader()
// Create a new factory with the functions provided by the class // Create a new factory with the functions provided by the class
ReaderFactory factory; ReaderFactory factory;
factory.check = &T::check; factory.check = &T::check;
factory.create = &priv::createReader<T>; factory.create = &priv::createReader<T>;
// Add it // Add it
@ -75,7 +83,7 @@ void SoundFileFactory::registerWriter()
// Create a new factory with the functions provided by the class // Create a new factory with the functions provided by the class
WriterFactory factory; WriterFactory factory;
factory.check = &T::check; factory.check = &T::check;
factory.create = &priv::createWriter<T>; factory.create = &priv::createWriter<T>;
// Add it // Add it

View File

@ -57,7 +57,9 @@ public:
/// \brief Virtual destructor /// \brief Virtual destructor
/// ///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
virtual ~SoundFileReader() {} virtual ~SoundFileReader()
{
}
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \brief Open a sound file for reading /// \brief Open a sound file for reading

View File

@ -29,6 +29,7 @@
// Headers // Headers
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
#include <SFML/Audio/Export.hpp> #include <SFML/Audio/Export.hpp>
#include <filesystem> #include <filesystem>
#include <string> #include <string>
@ -42,12 +43,13 @@ namespace sf
class SFML_AUDIO_API SoundFileWriter class SFML_AUDIO_API SoundFileWriter
{ {
public: public:
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \brief Virtual destructor /// \brief Virtual destructor
/// ///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
virtual ~SoundFileWriter() {} virtual ~SoundFileWriter()
{
}
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \brief Open a sound file for writing /// \brief Open a sound file for writing
@ -59,7 +61,9 @@ public:
/// \return True if the file was successfully opened /// \return True if the file was successfully opened
/// ///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
[[nodiscard]] virtual bool open(const std::filesystem::path& filename, unsigned int sampleRate, unsigned int channelCount) = 0; [[nodiscard]] virtual bool open(const std::filesystem::path& filename,
unsigned int sampleRate,
unsigned int channelCount) = 0;
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \brief Write audio samples to the open file /// \brief Write audio samples to the open file

View File

@ -29,11 +29,13 @@
// Headers // Headers
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
#include <SFML/Audio/Export.hpp> #include <SFML/Audio/Export.hpp>
#include <SFML/Audio/AlResource.hpp> #include <SFML/Audio/AlResource.hpp>
#include <SFML/System/Time.hpp> #include <SFML/System/Time.hpp>
#include <vector>
#include <string> #include <string>
#include <thread> #include <thread>
#include <vector>
namespace sf namespace sf
@ -45,7 +47,6 @@ namespace sf
class SFML_AUDIO_API SoundRecorder : AlResource class SFML_AUDIO_API SoundRecorder : AlResource
{ {
public: public:
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \brief destructor /// \brief destructor
/// ///
@ -186,7 +187,6 @@ public:
static bool isAvailable(); static bool isAvailable();
protected: protected:
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \brief Default constructor /// \brief Default constructor
/// ///
@ -254,7 +254,6 @@ protected:
virtual void onStop(); virtual void onStop();
private: private:
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \brief Function called as the entry point of the thread /// \brief Function called as the entry point of the thread
/// ///
@ -303,13 +302,13 @@ private:
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
// Member data // Member data
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
std::thread m_thread; //!< Thread running the background recording task std::thread m_thread; //!< Thread running the background recording task
std::vector<Int16> m_samples; //!< Buffer to store captured samples std::vector<Int16> m_samples; //!< Buffer to store captured samples
unsigned int m_sampleRate; //!< Sample rate unsigned int m_sampleRate; //!< Sample rate
Time m_processingInterval; //!< Time period between calls to onProcessSamples Time m_processingInterval; //!< Time period between calls to onProcessSamples
bool m_isCapturing; //!< Capturing state bool m_isCapturing; //!< Capturing state
std::string m_deviceName; //!< Name of the audio capture device std::string m_deviceName; //!< Name of the audio capture device
unsigned int m_channelCount; //!< Number of recording channels unsigned int m_channelCount; //!< Number of recording channels
}; };
} // namespace sf } // namespace sf

View File

@ -29,6 +29,7 @@
// Headers // Headers
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
#include <SFML/Audio/Export.hpp> #include <SFML/Audio/Export.hpp>
#include <SFML/Audio/AlResource.hpp> #include <SFML/Audio/AlResource.hpp>
#include <SFML/System/Vector3.hpp> #include <SFML/System/Vector3.hpp>
@ -42,7 +43,6 @@ namespace sf
class SFML_AUDIO_API SoundSource : AlResource class SFML_AUDIO_API SoundSource : AlResource
{ {
public: public:
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \brief Enumeration of the sound source states /// \brief Enumeration of the sound source states
/// ///
@ -232,7 +232,7 @@ public:
/// \return Reference to self /// \return Reference to self
/// ///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
SoundSource& operator =(const SoundSource& right); SoundSource& operator=(const SoundSource& right);
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \brief Start or resume playing the sound source /// \brief Start or resume playing the sound source
@ -278,7 +278,6 @@ public:
virtual Status getStatus() const; virtual Status getStatus() const;
protected: protected:
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \brief Default constructor /// \brief Default constructor
/// ///

View File

@ -29,8 +29,10 @@
// Headers // Headers
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
#include <SFML/Audio/Export.hpp> #include <SFML/Audio/Export.hpp>
#include <SFML/Audio/SoundSource.hpp> #include <SFML/Audio/SoundSource.hpp>
#include <SFML/System/Time.hpp> #include <SFML/System/Time.hpp>
#include <cstdlib> #include <cstdlib>
#include <mutex> #include <mutex>
#include <thread> #include <thread>
@ -45,7 +47,6 @@ namespace sf
class SFML_AUDIO_API SoundStream : public SoundSource class SFML_AUDIO_API SoundStream : public SoundSource
{ {
public: public:
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \brief Structure defining a chunk of audio data to stream /// \brief Structure defining a chunk of audio data to stream
/// ///
@ -179,7 +180,6 @@ public:
bool getLoop() const; bool getLoop() const;
protected: protected:
enum enum
{ {
NoLoop = -1 //!< "Invalid" endSeeks value, telling us to continue uninterrupted NoLoop = -1 //!< "Invalid" endSeeks value, telling us to continue uninterrupted
@ -266,7 +266,6 @@ protected:
void setProcessingInterval(Time interval); void setProcessingInterval(Time interval);
private: private:
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \brief Function called as the entry point of the thread /// \brief Function called as the entry point of the thread
/// ///
@ -331,25 +330,25 @@ private:
enum enum
{ {
BufferCount = 3, //!< Number of audio buffers used by the streaming loop BufferCount = 3, //!< Number of audio buffers used by the streaming loop
BufferRetries = 2 //!< Number of retries (excluding initial try) for onGetData() BufferRetries = 2 //!< Number of retries (excluding initial try) for onGetData()
}; };
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
// Member data // Member data
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
std::thread m_thread; //!< Thread running the background tasks std::thread m_thread; //!< Thread running the background tasks
mutable std::recursive_mutex m_threadMutex; //!< Thread mutex mutable std::recursive_mutex m_threadMutex; //!< Thread mutex
Status m_threadStartState; //!< State the thread starts in (Playing, Paused, Stopped) Status m_threadStartState; //!< State the thread starts in (Playing, Paused, Stopped)
bool m_isStreaming; //!< Streaming state (true = playing, false = stopped) bool m_isStreaming; //!< Streaming state (true = playing, false = stopped)
unsigned int m_buffers[BufferCount]; //!< Sound buffers used to store temporary audio data unsigned int m_buffers[BufferCount]; //!< Sound buffers used to store temporary audio data
unsigned int m_channelCount; //!< Number of channels (1 = mono, 2 = stereo, ...) unsigned int m_channelCount; //!< Number of channels (1 = mono, 2 = stereo, ...)
unsigned int m_sampleRate; //!< Frequency (samples / second) unsigned int m_sampleRate; //!< Frequency (samples / second)
Int32 m_format; //!< Format of the internal sound buffers Int32 m_format; //!< Format of the internal sound buffers
bool m_loop; //!< Loop flag (true to loop, false to play once) bool m_loop; //!< Loop flag (true to loop, false to play once)
Uint64 m_samplesProcessed; //!< Number of samples processed since beginning of the stream Uint64 m_samplesProcessed; //!< Number of samples processed since beginning of the stream
Int64 m_bufferSeeks[BufferCount]; //!< If buffer is an "end buffer", holds next seek position, else NoLoop. For play offset calculation. Int64 m_bufferSeeks[BufferCount]; //!< If buffer is an "end buffer", holds next seek position, else NoLoop. For play offset calculation.
Time m_processingInterval; //!< Interval for checking and filling the internal sound buffers. Time m_processingInterval; //!< Interval for checking and filling the internal sound buffers.
}; };
} // namespace sf } // namespace sf

View File

@ -35,9 +35,9 @@
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
// Define the SFML version // Define the SFML version
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
#define SFML_VERSION_MAJOR 3 #define SFML_VERSION_MAJOR 3
#define SFML_VERSION_MINOR 0 #define SFML_VERSION_MINOR 0
#define SFML_VERSION_PATCH 0 #define SFML_VERSION_PATCH 0
#define SFML_VERSION_IS_RELEASE false #define SFML_VERSION_IS_RELEASE false
@ -47,73 +47,73 @@
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
#if defined(_WIN32) #if defined(_WIN32)
// Windows // Windows
#define SFML_SYSTEM_WINDOWS #define SFML_SYSTEM_WINDOWS
#ifndef NOMINMAX #ifndef NOMINMAX
#define NOMINMAX #define NOMINMAX
#endif #endif
#elif defined(__APPLE__) && defined(__MACH__) #elif defined(__APPLE__) && defined(__MACH__)
// Apple platform, see which one it is // Apple platform, see which one it is
#include "TargetConditionals.h" #include "TargetConditionals.h"
#if TARGET_OS_IPHONE || TARGET_IPHONE_SIMULATOR #if TARGET_OS_IPHONE || TARGET_IPHONE_SIMULATOR
// iOS // iOS
#define SFML_SYSTEM_IOS #define SFML_SYSTEM_IOS
#elif TARGET_OS_MAC #elif TARGET_OS_MAC
// MacOS // MacOS
#define SFML_SYSTEM_MACOS #define SFML_SYSTEM_MACOS
#else
// Unsupported Apple system
#error This Apple operating system is not supported by SFML library
#endif
#elif defined(__unix__)
// UNIX system, see which one it is
#if defined(__ANDROID__)
// Android
#define SFML_SYSTEM_ANDROID
#elif defined(__linux__)
// Linux
#define SFML_SYSTEM_LINUX
#elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
// FreeBSD
#define SFML_SYSTEM_FREEBSD
#elif defined(__OpenBSD__)
// OpenBSD
#define SFML_SYSTEM_OPENBSD
#elif defined(__NetBSD__)
// NetBSD
#define SFML_SYSTEM_NETBSD
#else
// Unsupported UNIX system
#error This UNIX operating system is not supported by SFML library
#endif
#else #else
// Unsupported system // Unsupported Apple system
#error This operating system is not supported by SFML library #error This Apple operating system is not supported by SFML library
#endif
#elif defined(__unix__)
// UNIX system, see which one it is
#if defined(__ANDROID__)
// Android
#define SFML_SYSTEM_ANDROID
#elif defined(__linux__)
// Linux
#define SFML_SYSTEM_LINUX
#elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
// FreeBSD
#define SFML_SYSTEM_FREEBSD
#elif defined(__OpenBSD__)
// OpenBSD
#define SFML_SYSTEM_OPENBSD
#elif defined(__NetBSD__)
// NetBSD
#define SFML_SYSTEM_NETBSD
#else
// Unsupported UNIX system
#error This UNIX operating system is not supported by SFML library
#endif
#else
// Unsupported system
#error This operating system is not supported by SFML library
#endif #endif
@ -123,7 +123,7 @@
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
#if !defined(NDEBUG) #if !defined(NDEBUG)
#define SFML_DEBUG #define SFML_DEBUG
#endif #endif
@ -133,31 +133,31 @@
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
#if !defined(SFML_STATIC) #if !defined(SFML_STATIC)
#if defined(SFML_SYSTEM_WINDOWS) #if defined(SFML_SYSTEM_WINDOWS)
// Windows compilers need specific (and different) keywords for export and import // Windows compilers need specific (and different) keywords for export and import
#define SFML_API_EXPORT __declspec(dllexport) #define SFML_API_EXPORT __declspec(dllexport)
#define SFML_API_IMPORT __declspec(dllimport) #define SFML_API_IMPORT __declspec(dllimport)
// For Visual C++ compilers, we also need to turn off this annoying C4251 warning // For Visual C++ compilers, we also need to turn off this annoying C4251 warning
#ifdef _MSC_VER #ifdef _MSC_VER
#pragma warning(disable: 4251) #pragma warning(disable : 4251)
#endif #endif
#else // Linux, FreeBSD, Mac OS X #else // Linux, FreeBSD, Mac OS X
#define SFML_API_EXPORT __attribute__ ((__visibility__ ("default"))) #define SFML_API_EXPORT __attribute__((__visibility__("default")))
#define SFML_API_IMPORT __attribute__ ((__visibility__ ("default"))) #define SFML_API_IMPORT __attribute__((__visibility__("default")))
#endif #endif
#else #else
// Static build doesn't need import/export macros // Static build doesn't need import/export macros
#define SFML_API_EXPORT #define SFML_API_EXPORT
#define SFML_API_IMPORT #define SFML_API_IMPORT
#endif #endif
@ -167,21 +167,21 @@
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
namespace sf namespace sf
{ {
// 8 bits integer types // 8 bits integer types
using Int8 = std::int8_t; using Int8 = std::int8_t;
using Uint8 = std::uint8_t; using Uint8 = std::uint8_t;
// 16 bits integer types // 16 bits integer types
using Int16 = std::int16_t; using Int16 = std::int16_t;
using Uint16 = std::uint16_t; using Uint16 = std::uint16_t;
// 32 bits integer types // 32 bits integer types
using Int32 = std::int32_t; using Int32 = std::int32_t;
using Uint32 = std::uint32_t; using Uint32 = std::uint32_t;
// 64 bits integer types // 64 bits integer types
using Int64 = std::int64_t; using Int64 = std::int64_t;
using Uint64 = std::uint64_t; using Uint64 = std::uint64_t;
} // namespace sf } // namespace sf

View File

@ -60,13 +60,13 @@
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
#if defined(SFML_SYSTEM_WINDOWS) #if defined(SFML_SYSTEM_WINDOWS)
#define SFML_DEFINE_DISCRETE_GPU_PREFERENCE \ #define SFML_DEFINE_DISCRETE_GPU_PREFERENCE \
extern "C" __declspec(dllexport) unsigned long NvOptimusEnablement = 1; \ extern "C" __declspec(dllexport) unsigned long NvOptimusEnablement = 1; \
extern "C" __declspec(dllexport) unsigned long AmdPowerXpressRequestHighPerformance = 1; extern "C" __declspec(dllexport) unsigned long AmdPowerXpressRequestHighPerformance = 1;
#else #else
#define SFML_DEFINE_DISCRETE_GPU_PREFERENCE #define SFML_DEFINE_DISCRETE_GPU_PREFERENCE
#endif #endif

View File

@ -29,7 +29,6 @@
// Headers // Headers
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
#include <SFML/Window.hpp>
#include <SFML/Graphics/BlendMode.hpp> #include <SFML/Graphics/BlendMode.hpp>
#include <SFML/Graphics/CircleShape.hpp> #include <SFML/Graphics/CircleShape.hpp>
#include <SFML/Graphics/Color.hpp> #include <SFML/Graphics/Color.hpp>
@ -56,6 +55,7 @@
#include <SFML/Graphics/VertexArray.hpp> #include <SFML/Graphics/VertexArray.hpp>
#include <SFML/Graphics/VertexBuffer.hpp> #include <SFML/Graphics/VertexBuffer.hpp>
#include <SFML/Graphics/View.hpp> #include <SFML/Graphics/View.hpp>
#include <SFML/Window.hpp>
#endif // SFML_GRAPHICS_HPP #endif // SFML_GRAPHICS_HPP

View File

@ -107,9 +107,12 @@ struct SFML_GRAPHICS_API BlendMode
/// \param alphaBlendEquation Specifies how to combine the source and destination alphas. /// \param alphaBlendEquation Specifies how to combine the source and destination alphas.
/// ///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
BlendMode(Factor colorSourceFactor, Factor colorDestinationFactor, BlendMode(Factor colorSourceFactor,
Equation colorBlendEquation, Factor alphaSourceFactor, Factor colorDestinationFactor,
Factor alphaDestinationFactor, Equation alphaBlendEquation); Equation colorBlendEquation,
Factor alphaSourceFactor,
Factor alphaDestinationFactor,
Equation alphaBlendEquation);
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
// Member Data // Member Data
@ -132,7 +135,7 @@ struct SFML_GRAPHICS_API BlendMode
/// \return True if blending modes are equal, false if they are different /// \return True if blending modes are equal, false if they are different
/// ///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
SFML_GRAPHICS_API bool operator ==(const BlendMode& left, const BlendMode& right); SFML_GRAPHICS_API bool operator==(const BlendMode& left, const BlendMode& right);
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \relates BlendMode /// \relates BlendMode
@ -144,7 +147,7 @@ SFML_GRAPHICS_API bool operator ==(const BlendMode& left, const BlendMode& right
/// \return True if blending modes are different, false if they are equal /// \return True if blending modes are different, false if they are equal
/// ///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
SFML_GRAPHICS_API bool operator !=(const BlendMode& left, const BlendMode& right); SFML_GRAPHICS_API bool operator!=(const BlendMode& left, const BlendMode& right);
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
// Commonly used blending modes // Commonly used blending modes

View File

@ -29,6 +29,7 @@
// Headers // Headers
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
#include <SFML/Graphics/Export.hpp> #include <SFML/Graphics/Export.hpp>
#include <SFML/Graphics/Shape.hpp> #include <SFML/Graphics/Shape.hpp>
@ -41,7 +42,6 @@ namespace sf
class SFML_GRAPHICS_API CircleShape : public Shape class SFML_GRAPHICS_API CircleShape : public Shape
{ {
public: public:
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \brief Default constructor /// \brief Default constructor
/// ///
@ -107,7 +107,6 @@ public:
Vector2f getPoint(std::size_t index) const override; Vector2f getPoint(std::size_t index) const override;
private: private:
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
// Member data // Member data
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////

View File

@ -40,7 +40,6 @@ namespace sf
class Color class Color
{ {
public: public:
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \brief Default constructor /// \brief Default constructor
/// ///
@ -111,7 +110,7 @@ public:
/// \return True if colors are equal, false if they are different /// \return True if colors are equal, false if they are different
/// ///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
[[nodiscard]] constexpr bool operator ==(const Color& left, const Color& right); [[nodiscard]] constexpr bool operator==(const Color& left, const Color& right);
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \relates Color /// \relates Color
@ -125,7 +124,7 @@ public:
/// \return True if colors are different, false if they are equal /// \return True if colors are different, false if they are equal
/// ///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
[[nodiscard]] constexpr bool operator !=(const Color& left, const Color& right); [[nodiscard]] constexpr bool operator!=(const Color& left, const Color& right);
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \relates Color /// \relates Color
@ -140,7 +139,7 @@ public:
/// \return Result of \a left + \a right /// \return Result of \a left + \a right
/// ///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
[[nodiscard]] constexpr Color operator +(const Color& left, const Color& right); [[nodiscard]] constexpr Color operator+(const Color& left, const Color& right);
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \relates Color /// \relates Color
@ -155,7 +154,7 @@ public:
/// \return Result of \a left - \a right /// \return Result of \a left - \a right
/// ///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
[[nodiscard]] constexpr Color operator -(const Color& left, const Color& right); [[nodiscard]] constexpr Color operator-(const Color& left, const Color& right);
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \relates Color /// \relates Color
@ -172,7 +171,7 @@ public:
/// \return Result of \a left * \a right /// \return Result of \a left * \a right
/// ///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
[[nodiscard]] constexpr Color operator *(const Color& left, const Color& right); [[nodiscard]] constexpr Color operator*(const Color& left, const Color& right);
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \relates Color /// \relates Color
@ -188,7 +187,7 @@ public:
/// \return Reference to \a left /// \return Reference to \a left
/// ///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
constexpr Color& operator +=(Color& left, const Color& right); constexpr Color& operator+=(Color& left, const Color& right);
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \relates Color /// \relates Color
@ -204,7 +203,7 @@ constexpr Color& operator +=(Color& left, const Color& right);
/// \return Reference to \a left /// \return Reference to \a left
/// ///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
constexpr Color& operator -=(Color& left, const Color& right); constexpr Color& operator-=(Color& left, const Color& right);
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \relates Color /// \relates Color
@ -222,7 +221,7 @@ constexpr Color& operator -=(Color& left, const Color& right);
/// \return Reference to \a left /// \return Reference to \a left
/// ///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
constexpr Color& operator *=(Color& left, const Color& right); constexpr Color& operator*=(Color& left, const Color& right);
#include <SFML/Graphics/Color.inl> #include <SFML/Graphics/Color.inl>

View File

@ -24,24 +24,14 @@
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
constexpr Color::Color() : constexpr Color::Color() : r(0), g(0), b(0), a(255)
r(0),
g(0),
b(0),
a(255)
{ {
} }
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
constexpr Color::Color(Uint8 red, Uint8 green, Uint8 blue, Uint8 alpha) : constexpr Color::Color(Uint8 red, Uint8 green, Uint8 blue, Uint8 alpha) : r(red), g(green), b(blue), a(alpha)
r(red),
g(green),
b(blue),
a(alpha)
{ {
} }
@ -52,7 +42,6 @@ g(static_cast<Uint8>((color & 0x00ff0000) >> 16)),
b(static_cast<Uint8>((color & 0x0000ff00) >> 8)), b(static_cast<Uint8>((color & 0x0000ff00) >> 8)),
a(static_cast<Uint8>(color & 0x000000ff)) a(static_cast<Uint8>(color & 0x000000ff))
{ {
} }
@ -64,24 +53,21 @@ constexpr Uint32 Color::toInteger() const
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
constexpr bool operator ==(const Color& left, const Color& right) constexpr bool operator==(const Color& left, const Color& right)
{ {
return (left.r == right.r) && return (left.r == right.r) && (left.g == right.g) && (left.b == right.b) && (left.a == right.a);
(left.g == right.g) &&
(left.b == right.b) &&
(left.a == right.a);
} }
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
constexpr bool operator !=(const Color& left, const Color& right) constexpr bool operator!=(const Color& left, const Color& right)
{ {
return !(left == right); return !(left == right);
} }
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
constexpr Color operator +(const Color& left, const Color& right) constexpr Color operator+(const Color& left, const Color& right)
{ {
const auto clampedAdd = [](Uint8 lhs, Uint8 rhs) -> Uint8 const auto clampedAdd = [](Uint8 lhs, Uint8 rhs) -> Uint8
{ {
@ -97,7 +83,7 @@ constexpr Color operator +(const Color& left, const Color& right)
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
constexpr Color operator -(const Color& left, const Color& right) constexpr Color operator-(const Color& left, const Color& right)
{ {
const auto clampedSub = [](Uint8 lhs, Uint8 rhs) -> Uint8 const auto clampedSub = [](Uint8 lhs, Uint8 rhs) -> Uint8
{ {
@ -113,7 +99,7 @@ constexpr Color operator -(const Color& left, const Color& right)
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
constexpr Color operator *(const Color& left, const Color& right) constexpr Color operator*(const Color& left, const Color& right)
{ {
const auto scaledMul = [](Uint8 lhs, Uint8 rhs) -> Uint8 const auto scaledMul = [](Uint8 lhs, Uint8 rhs) -> Uint8
{ {
@ -129,21 +115,21 @@ constexpr Color operator *(const Color& left, const Color& right)
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
constexpr Color& operator +=(Color& left, const Color& right) constexpr Color& operator+=(Color& left, const Color& right)
{ {
return left = left + right; return left = left + right;
} }
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
constexpr Color& operator -=(Color& left, const Color& right) constexpr Color& operator-=(Color& left, const Color& right)
{ {
return left = left - right; return left = left - right;
} }
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
constexpr Color& operator *=(Color& left, const Color& right) constexpr Color& operator*=(Color& left, const Color& right)
{ {
return left = left * right; return left = left * right;
} }

View File

@ -29,7 +29,9 @@
// Headers // Headers
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
#include <SFML/Graphics/Export.hpp> #include <SFML/Graphics/Export.hpp>
#include <SFML/Graphics/Shape.hpp> #include <SFML/Graphics/Shape.hpp>
#include <vector> #include <vector>
@ -42,7 +44,6 @@ namespace sf
class SFML_GRAPHICS_API ConvexShape : public Shape class SFML_GRAPHICS_API ConvexShape : public Shape
{ {
public: public:
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \brief Default constructor /// \brief Default constructor
/// ///
@ -112,7 +113,6 @@ public:
Vector2f getPoint(std::size_t index) const override; Vector2f getPoint(std::size_t index) const override;
private: private:
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
// Member data // Member data
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////

View File

@ -44,15 +44,15 @@ class RenderStates;
class SFML_GRAPHICS_API Drawable class SFML_GRAPHICS_API Drawable
{ {
public: public:
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \brief Virtual destructor /// \brief Virtual destructor
/// ///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
virtual ~Drawable() {} virtual ~Drawable()
{
}
protected: protected:
friend class RenderTarget; friend class RenderTarget;
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////

View File

@ -36,11 +36,11 @@
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
#if defined(SFML_GRAPHICS_EXPORTS) #if defined(SFML_GRAPHICS_EXPORTS)
#define SFML_GRAPHICS_API SFML_API_EXPORT #define SFML_GRAPHICS_API SFML_API_EXPORT
#else #else
#define SFML_GRAPHICS_API SFML_API_IMPORT #define SFML_GRAPHICS_API SFML_API_IMPORT
#endif #endif

View File

@ -29,9 +29,11 @@
// Headers // Headers
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
#include <SFML/Graphics/Export.hpp> #include <SFML/Graphics/Export.hpp>
#include <SFML/Graphics/Glyph.hpp> #include <SFML/Graphics/Glyph.hpp>
#include <SFML/Graphics/Texture.hpp>
#include <SFML/Graphics/Rect.hpp> #include <SFML/Graphics/Rect.hpp>
#include <SFML/Graphics/Texture.hpp>
#include <memory> #include <memory>
#include <string> #include <string>
#include <unordered_map> #include <unordered_map>
@ -56,7 +58,6 @@ class InputStream;
class SFML_GRAPHICS_API Font class SFML_GRAPHICS_API Font
{ {
public: public:
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \brief Holds various information about a font /// \brief Holds various information about a font
/// ///
@ -67,7 +68,6 @@ public:
}; };
public: public:
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \brief Default constructor /// \brief Default constructor
/// ///
@ -327,17 +327,18 @@ public:
/// \return Reference to self /// \return Reference to self
/// ///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
Font& operator =(const Font& right); Font& operator=(const Font& right);
private: private:
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \brief Structure defining a row of glyphs /// \brief Structure defining a row of glyphs
/// ///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
struct Row struct Row
{ {
Row(unsigned int rowTop, unsigned int rowHeight) : width(0), top(rowTop), height(rowHeight) {} Row(unsigned int rowTop, unsigned int rowHeight) : width(0), top(rowTop), height(rowHeight)
{
}
unsigned int width; //!< Current width of the row unsigned int width; //!< Current width of the row
unsigned int top; //!< Y position of the row into the texture unsigned int top; //!< Y position of the row into the texture
@ -422,14 +423,14 @@ private:
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
// Member data // Member data
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
std::shared_ptr<FontHandles> m_fontHandles; //!< Shared information about the internal font instance std::shared_ptr<FontHandles> m_fontHandles; //!< Shared information about the internal font instance
bool m_isSmooth; //!< Status of the smooth filter bool m_isSmooth; //!< Status of the smooth filter
Info m_info; //!< Information about the font Info m_info; //!< Information about the font
mutable PageTable m_pages; //!< Table containing the glyphs pages by character size mutable PageTable m_pages; //!< Table containing the glyphs pages by character size
mutable std::vector<Uint8> m_pixelBuffer; //!< Pixel buffer holding a glyph's pixels before being written to the texture mutable std::vector<Uint8> m_pixelBuffer; //!< Pixel buffer holding a glyph's pixels before being written to the texture
#ifdef SFML_SYSTEM_ANDROID #ifdef SFML_SYSTEM_ANDROID
std::unique_ptr<priv::ResourceStream> m_stream; //!< Asset file streamer (if loaded from file) std::unique_ptr<priv::ResourceStream> m_stream; //!< Asset file streamer (if loaded from file)
#endif #endif
}; };
} // namespace sf } // namespace sf

View File

@ -28,10 +28,11 @@
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
// Headers // Headers
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
#include <SFML/Graphics/Transform.hpp>
#include <SFML/Graphics/Color.hpp> #include <SFML/Graphics/Color.hpp>
#include <SFML/Graphics/Transform.hpp>
#include <SFML/System/Vector2.hpp> #include <SFML/System/Vector2.hpp>
#include <SFML/System/Vector3.hpp> #include <SFML/System/Vector3.hpp>
#include <cstddef> #include <cstddef>
@ -39,12 +40,12 @@ namespace sf
{ {
namespace priv namespace priv
{ {
// Forward declarations // Forward declarations
template <std::size_t Columns, std::size_t Rows> template <std::size_t Columns, std::size_t Rows>
struct Matrix; struct Matrix;
template <typename T> template <typename T>
struct Vector4; struct Vector4;
#include <SFML/Graphics/Glsl.inl> #include <SFML/Graphics/Glsl.inl>
@ -58,136 +59,136 @@ namespace priv
namespace Glsl namespace Glsl
{ {
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \brief 2D float vector (\p vec2 in GLSL) /// \brief 2D float vector (\p vec2 in GLSL)
/// ///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
using Vec2 = Vector2<float>; using Vec2 = Vector2<float>;
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \brief 2D int vector (\p ivec2 in GLSL) /// \brief 2D int vector (\p ivec2 in GLSL)
/// ///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
using Ivec2 = Vector2<int>; using Ivec2 = Vector2<int>;
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \brief 2D bool vector (\p bvec2 in GLSL) /// \brief 2D bool vector (\p bvec2 in GLSL)
/// ///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
using Bvec2 = Vector2<bool>; using Bvec2 = Vector2<bool>;
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \brief 3D float vector (\p vec3 in GLSL) /// \brief 3D float vector (\p vec3 in GLSL)
/// ///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
using Vec3 = Vector3<float>; using Vec3 = Vector3<float>;
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \brief 3D int vector (\p ivec3 in GLSL) /// \brief 3D int vector (\p ivec3 in GLSL)
/// ///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
using Ivec3 = Vector3<int>; using Ivec3 = Vector3<int>;
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \brief 3D bool vector (\p bvec3 in GLSL) /// \brief 3D bool vector (\p bvec3 in GLSL)
/// ///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
using Bvec3 = Vector3<bool>; using Bvec3 = Vector3<bool>;
#ifdef SFML_DOXYGEN #ifdef SFML_DOXYGEN
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \brief 4D float vector (\p vec4 in GLSL) /// \brief 4D float vector (\p vec4 in GLSL)
/// ///
/// 4D float vectors can be implicitly converted from sf::Color /// 4D float vectors can be implicitly converted from sf::Color
/// instances. Each color channel is normalized from integers /// instances. Each color channel is normalized from integers
/// in [0, 255] to floating point values in [0, 1]. /// in [0, 255] to floating point values in [0, 1].
/// \code /// \code
/// sf::Glsl::Vec4 zeroVector; /// sf::Glsl::Vec4 zeroVector;
/// sf::Glsl::Vec4 vector(1.f, 2.f, 3.f, 4.f); /// sf::Glsl::Vec4 vector(1.f, 2.f, 3.f, 4.f);
/// sf::Glsl::Vec4 color = sf::Color::Cyan; /// sf::Glsl::Vec4 color = sf::Color::Cyan;
/// \endcode /// \endcode
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
using Vec4 = implementation-defined; using Vec4 = ImplementationDefined;
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \brief 4D int vector (\p ivec4 in GLSL) /// \brief 4D int vector (\p ivec4 in GLSL)
/// ///
/// 4D int vectors can be implicitly converted from sf::Color /// 4D int vectors can be implicitly converted from sf::Color
/// instances. Each color channel remains unchanged inside /// instances. Each color channel remains unchanged inside
/// the integer interval [0, 255]. /// the integer interval [0, 255].
/// \code /// \code
/// sf::Glsl::Ivec4 zeroVector; /// sf::Glsl::Ivec4 zeroVector;
/// sf::Glsl::Ivec4 vector(1, 2, 3, 4); /// sf::Glsl::Ivec4 vector(1, 2, 3, 4);
/// sf::Glsl::Ivec4 color = sf::Color::Cyan; /// sf::Glsl::Ivec4 color = sf::Color::Cyan;
/// \endcode /// \endcode
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
using Ivec4 = implementation-defined; using Ivec4 = ImplementationDefined;
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \brief 4D bool vector (\p bvec4 in GLSL) /// \brief 4D bool vector (\p bvec4 in GLSL)
/// ///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
using Bvec4 = implementation-defined; using Bvec4 = ImplementationDefined;
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \brief 3x3 float matrix (\p mat3 in GLSL) /// \brief 3x3 float matrix (\p mat3 in GLSL)
/// ///
/// The matrix can be constructed from an array with 3x3 /// The matrix can be constructed from an array with 3x3
/// elements, aligned in column-major order. For example, /// elements, aligned in column-major order. For example,
/// a translation by (x, y) looks as follows: /// a translation by (x, y) looks as follows:
/// \code /// \code
/// float array[9] = /// float array[9] =
/// { /// {
/// 1, 0, 0, /// 1, 0, 0,
/// 0, 1, 0, /// 0, 1, 0,
/// x, y, 1 /// x, y, 1
/// }; /// };
/// ///
/// sf::Glsl::Mat3 matrix(array); /// sf::Glsl::Mat3 matrix(array);
/// \endcode /// \endcode
/// ///
/// Mat3 can also be implicitly converted from sf::Transform: /// Mat3 can also be implicitly converted from sf::Transform:
/// \code /// \code
/// sf::Transform transform; /// sf::Transform transform;
/// sf::Glsl::Mat3 matrix = transform; /// sf::Glsl::Mat3 matrix = transform;
/// \endcode /// \endcode
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
using Mat3 = implementation-defined; using Mat3 = ImplementationDefined;
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \brief 4x4 float matrix (\p mat4 in GLSL) /// \brief 4x4 float matrix (\p mat4 in GLSL)
/// ///
/// The matrix can be constructed from an array with 4x4 /// The matrix can be constructed from an array with 4x4
/// elements, aligned in column-major order. For example, /// elements, aligned in column-major order. For example,
/// a translation by (x, y, z) looks as follows: /// a translation by (x, y, z) looks as follows:
/// \code /// \code
/// float array[16] = /// float array[16] =
/// { /// {
/// 1, 0, 0, 0, /// 1, 0, 0, 0,
/// 0, 1, 0, 0, /// 0, 1, 0, 0,
/// 0, 0, 1, 0, /// 0, 0, 1, 0,
/// x, y, z, 1 /// x, y, z, 1
/// }; /// };
/// ///
/// sf::Glsl::Mat4 matrix(array); /// sf::Glsl::Mat4 matrix(array);
/// \endcode /// \endcode
/// ///
/// Mat4 can also be implicitly converted from sf::Transform: /// Mat4 can also be implicitly converted from sf::Transform:
/// \code /// \code
/// sf::Transform transform; /// sf::Transform transform;
/// sf::Glsl::Mat4 matrix = transform; /// sf::Glsl::Mat4 matrix = transform;
/// \endcode /// \endcode
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
using Mat4 = implementation-defined; using Mat4 = ImplementationDefined;
#else // SFML_DOXYGEN #else // SFML_DOXYGEN
using Vec4 = priv::Vector4<float>; using Vec4 = priv::Vector4<float>;
using Ivec4 = priv::Vector4<int>; using Ivec4 = priv::Vector4<int>;
using Bvec4 = priv::Vector4<bool>; using Bvec4 = priv::Vector4<bool>;
using Mat3 = priv::Matrix<3, 3>; using Mat3 = priv::Matrix<3, 3>;
using Mat4 = priv::Matrix<4, 4>; using Mat4 = priv::Matrix<4, 4>;
#endif // SFML_DOXYGEN #endif // SFML_DOXYGEN

View File

@ -95,11 +95,7 @@ struct Vector4
/// \brief Default constructor, creates a zero vector /// \brief Default constructor, creates a zero vector
/// ///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
Vector4() : Vector4() : x(0), y(0), z(0), w(0)
x(0),
y(0),
z(0),
w(0)
{ {
} }
@ -112,11 +108,7 @@ struct Vector4
/// \param W Component of the 4D vector /// \param W Component of the 4D vector
/// ///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
Vector4(T X, T Y, T Z, T W) : Vector4(T X, T Y, T Z, T W) : x(X), y(Y), z(Z), w(W)
x(X),
y(Y),
z(Z),
w(W)
{ {
} }

View File

@ -29,6 +29,7 @@
// Headers // Headers
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
#include <SFML/Graphics/Export.hpp> #include <SFML/Graphics/Export.hpp>
#include <SFML/Graphics/Rect.hpp> #include <SFML/Graphics/Rect.hpp>
@ -41,12 +42,13 @@ namespace sf
class SFML_GRAPHICS_API Glyph class SFML_GRAPHICS_API Glyph
{ {
public: public:
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \brief Default constructor /// \brief Default constructor
/// ///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
Glyph() : advance(0), lsbDelta(0), rsbDelta(0) {} Glyph() : advance(0), lsbDelta(0), rsbDelta(0)
{
}
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
// Member data // Member data

View File

@ -29,8 +29,10 @@
// Headers // Headers
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
#include <SFML/Graphics/Export.hpp> #include <SFML/Graphics/Export.hpp>
#include <SFML/Graphics/Color.hpp> #include <SFML/Graphics/Color.hpp>
#include <SFML/Graphics/Rect.hpp> #include <SFML/Graphics/Rect.hpp>
#include <filesystem> #include <filesystem>
#include <string> #include <string>
#include <vector> #include <vector>
@ -47,7 +49,6 @@ class InputStream;
class SFML_GRAPHICS_API Image class SFML_GRAPHICS_API Image
{ {
public: public:
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \brief Create the image and fill it with a unique color /// \brief Create the image and fill it with a unique color
/// ///
@ -211,7 +212,10 @@ public:
/// \return True if the operation was successful, false otherwise /// \return True if the operation was successful, false otherwise
/// ///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
[[nodiscard]] bool copy(const Image& source, const Vector2u& dest, const IntRect& sourceRect = IntRect({0, 0}, {0, 0}), bool applyAlpha = false); [[nodiscard]] bool copy(const Image& source,
const Vector2u& dest,
const IntRect& sourceRect = IntRect({0, 0}, {0, 0}),
bool applyAlpha = false);
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \brief Change the color of a pixel /// \brief Change the color of a pixel
@ -272,7 +276,6 @@ public:
void flipVertically(); void flipVertically();
private: private:
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
// Member data // Member data
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////

View File

@ -43,7 +43,7 @@ enum PrimitiveType
LineStrip, //!< List of connected lines, a point uses the previous point to form a line LineStrip, //!< List of connected lines, a point uses the previous point to form a line
Triangles, //!< List of individual triangles Triangles, //!< List of individual triangles
TriangleStrip, //!< List of connected triangles, a point uses the two previous points to form a triangle TriangleStrip, //!< List of connected triangles, a point uses the two previous points to form a triangle
TriangleFan //!< List of connected triangles, a point uses the common center and the previous point to form a triangle TriangleFan //!< List of connected triangles, a point uses the common center and the previous point to form a triangle
}; };
} // namespace sf } // namespace sf

View File

@ -29,6 +29,7 @@
// Headers // Headers
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
#include <SFML/System/Vector2.hpp> #include <SFML/System/Vector2.hpp>
#include <optional> #include <optional>
@ -42,7 +43,6 @@ template <typename T>
class Rect class Rect
{ {
public: public:
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \brief Default constructor /// \brief Default constructor
/// ///
@ -147,7 +147,7 @@ public:
/// ///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
template <typename T> template <typename T>
[[nodiscard]] constexpr bool operator ==(const Rect<T>& left, const Rect<T>& right); [[nodiscard]] constexpr bool operator==(const Rect<T>& left, const Rect<T>& right);
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \relates Rect /// \relates Rect
@ -162,12 +162,12 @@ template <typename T>
/// ///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
template <typename T> template <typename T>
[[nodiscard]] constexpr bool operator !=(const Rect<T>& left, const Rect<T>& right); [[nodiscard]] constexpr bool operator!=(const Rect<T>& left, const Rect<T>& right);
#include <SFML/Graphics/Rect.inl> #include <SFML/Graphics/Rect.inl>
// Create type aliases for the most common types // Create type aliases for the most common types
using IntRect = Rect<int>; using IntRect = Rect<int>;
using FloatRect = Rect<float>; using FloatRect = Rect<float>;
} // namespace sf } // namespace sf

View File

@ -25,25 +25,19 @@
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
template <typename T> template <typename T>
constexpr Rect<T>::Rect() : constexpr Rect<T>::Rect() : left(0), top(0), width(0), height(0)
left (0),
top (0),
width (0),
height(0)
{ {
} }
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
template <typename T> template <typename T>
constexpr Rect<T>::Rect(const Vector2<T>& position, const Vector2<T>& size) : constexpr Rect<T>::Rect(const Vector2<T>& position, const Vector2<T>& size) :
left (position.x), left(position.x),
top (position.y), top(position.y),
width (size.x), width(size.x),
height(size.y) height(size.y)
{ {
} }
@ -51,9 +45,9 @@ height(size.y)
template <typename T> template <typename T>
template <typename U> template <typename U>
constexpr Rect<T>::Rect(const Rect<U>& rectangle) : constexpr Rect<T>::Rect(const Rect<U>& rectangle) :
left (static_cast<T>(rectangle.left)), left(static_cast<T>(rectangle.left)),
top (static_cast<T>(rectangle.top)), top(static_cast<T>(rectangle.top)),
width (static_cast<T>(rectangle.width)), width(static_cast<T>(rectangle.width)),
height(static_cast<T>(rectangle.height)) height(static_cast<T>(rectangle.height))
{ {
} }
@ -64,8 +58,8 @@ template <typename T>
constexpr bool Rect<T>::contains(const Vector2<T>& point) const constexpr bool Rect<T>::contains(const Vector2<T>& point) const
{ {
// Not using 'std::min' and 'std::max' to avoid depending on '<algorithm>' // Not using 'std::min' and 'std::max' to avoid depending on '<algorithm>'
const auto min = [](T a, T b){ return (a < b) ? a : b; }; const auto min = [](T a, T b) { return (a < b) ? a : b; };
const auto max = [](T a, T b){ return (a < b) ? b : a; }; const auto max = [](T a, T b) { return (a < b) ? b : a; };
// Rectangles with negative dimensions are allowed, so we must handle them correctly // Rectangles with negative dimensions are allowed, so we must handle them correctly
@ -84,8 +78,8 @@ template <typename T>
constexpr std::optional<Rect<T>> Rect<T>::findIntersection(const Rect<T>& rectangle) const constexpr std::optional<Rect<T>> Rect<T>::findIntersection(const Rect<T>& rectangle) const
{ {
// Not using 'std::min' and 'std::max' to avoid depending on '<algorithm>' // Not using 'std::min' and 'std::max' to avoid depending on '<algorithm>'
const auto min = [](T a, T b){ return (a < b) ? a : b; }; const auto min = [](T a, T b) { return (a < b) ? a : b; };
const auto max = [](T a, T b){ return (a < b) ? b : a; }; const auto max = [](T a, T b) { return (a < b) ? b : a; };
// Rectangles with negative dimensions are allowed, so we must handle them correctly // Rectangles with negative dimensions are allowed, so we must handle them correctly
@ -137,16 +131,16 @@ constexpr Vector2<T> Rect<T>::getSize() const
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
template <typename T> template <typename T>
constexpr bool operator ==(const Rect<T>& left, const Rect<T>& right) constexpr bool operator==(const Rect<T>& left, const Rect<T>& right)
{ {
return (left.left == right.left) && (left.width == right.width) && return (left.left == right.left) && (left.width == right.width) && (left.top == right.top) &&
(left.top == right.top) && (left.height == right.height); (left.height == right.height);
} }
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
template <typename T> template <typename T>
constexpr bool operator !=(const Rect<T>& left, const Rect<T>& right) constexpr bool operator!=(const Rect<T>& left, const Rect<T>& right)
{ {
return !(left == right); return !(left == right);
} }

View File

@ -29,6 +29,7 @@
// Headers // Headers
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
#include <SFML/Graphics/Export.hpp> #include <SFML/Graphics/Export.hpp>
#include <SFML/Graphics/Shape.hpp> #include <SFML/Graphics/Shape.hpp>
@ -41,7 +42,6 @@ namespace sf
class SFML_GRAPHICS_API RectangleShape : public Shape class SFML_GRAPHICS_API RectangleShape : public Shape
{ {
public: public:
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \brief Default constructor /// \brief Default constructor
/// ///
@ -95,7 +95,6 @@ public:
Vector2f getPoint(std::size_t index) const override; Vector2f getPoint(std::size_t index) const override;
private: private:
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
// Member data // Member data
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////

View File

@ -29,6 +29,7 @@
// Headers // Headers
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
#include <SFML/Graphics/Export.hpp> #include <SFML/Graphics/Export.hpp>
#include <SFML/Graphics/BlendMode.hpp> #include <SFML/Graphics/BlendMode.hpp>
#include <SFML/Graphics/Transform.hpp> #include <SFML/Graphics/Transform.hpp>
@ -45,7 +46,6 @@ class Texture;
class SFML_GRAPHICS_API RenderStates class SFML_GRAPHICS_API RenderStates
{ {
public: public:
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \brief Default constructor /// \brief Default constructor
/// ///
@ -101,8 +101,7 @@ public:
/// \param theShader Shader to use /// \param theShader Shader to use
/// ///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
RenderStates(const BlendMode& theBlendMode, const Transform& theTransform, RenderStates(const BlendMode& theBlendMode, const Transform& theTransform, const Texture* theTexture, const Shader* theShader);
const Texture* theTexture, const Shader* theShader);
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
// Static member data // Static member data

View File

@ -29,13 +29,15 @@
// Headers // Headers
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
#include <SFML/Graphics/Export.hpp> #include <SFML/Graphics/Export.hpp>
#include <SFML/Graphics/Color.hpp>
#include <SFML/Graphics/Rect.hpp>
#include <SFML/Graphics/View.hpp>
#include <SFML/Graphics/BlendMode.hpp> #include <SFML/Graphics/BlendMode.hpp>
#include <SFML/Graphics/RenderStates.hpp> #include <SFML/Graphics/Color.hpp>
#include <SFML/Graphics/PrimitiveType.hpp> #include <SFML/Graphics/PrimitiveType.hpp>
#include <SFML/Graphics/Rect.hpp>
#include <SFML/Graphics/RenderStates.hpp>
#include <SFML/Graphics/Vertex.hpp> #include <SFML/Graphics/Vertex.hpp>
#include <SFML/Graphics/View.hpp>
#include <cstddef> #include <cstddef>
@ -52,7 +54,6 @@ class Transform;
class SFML_GRAPHICS_API RenderTarget class SFML_GRAPHICS_API RenderTarget
{ {
public: public:
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \brief Destructor /// \brief Destructor
/// ///
@ -257,8 +258,10 @@ public:
/// \param states Render states to use for drawing /// \param states Render states to use for drawing
/// ///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
void draw(const Vertex* vertices, std::size_t vertexCount, void draw(const Vertex* vertices,
PrimitiveType type, const RenderStates& states = RenderStates::Default); std::size_t vertexCount,
PrimitiveType type,
const RenderStates& states = RenderStates::Default);
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \brief Draw primitives defined by a vertex buffer /// \brief Draw primitives defined by a vertex buffer
@ -278,7 +281,10 @@ public:
/// \param states Render states to use for drawing /// \param states Render states to use for drawing
/// ///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
void draw(const VertexBuffer& vertexBuffer, std::size_t firstVertex, std::size_t vertexCount, const RenderStates& states = RenderStates::Default); void draw(const VertexBuffer& vertexBuffer,
std::size_t firstVertex,
std::size_t vertexCount,
const RenderStates& states = RenderStates::Default);
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \brief Return the size of the rendering region of the target /// \brief Return the size of the rendering region of the target
@ -387,7 +393,6 @@ public:
void resetGLStates(); void resetGLStates();
protected: protected:
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \brief Default constructor /// \brief Default constructor
/// ///
@ -404,7 +409,6 @@ protected:
void initialize(); void initialize();
private: private:
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \brief Apply the current view /// \brief Apply the current view
/// ///
@ -476,15 +480,18 @@ private:
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
struct StatesCache struct StatesCache
{ {
enum {VertexCacheSize = 4}; enum
{
VertexCacheSize = 4
};
bool enable; //!< Is the cache enabled? bool enable; //!< Is the cache enabled?
bool glStatesSet; //!< Are our internal GL states set yet? bool glStatesSet; //!< Are our internal GL states set yet?
bool viewChanged; //!< Has the current view changed since last draw? bool viewChanged; //!< Has the current view changed since last draw?
BlendMode lastBlendMode; //!< Cached blending mode BlendMode lastBlendMode; //!< Cached blending mode
Uint64 lastTextureId; //!< Cached texture Uint64 lastTextureId; //!< Cached texture
bool texCoordsArrayEnabled; //!< Is GL_TEXTURE_COORD_ARRAY client state enabled? bool texCoordsArrayEnabled; //!< Is GL_TEXTURE_COORD_ARRAY client state enabled?
bool useVertexCache; //!< Did we previously use the vertex cache? bool useVertexCache; //!< Did we previously use the vertex cache?
Vertex vertexCache[VertexCacheSize]; //!< Pre-transformed vertices cache Vertex vertexCache[VertexCacheSize]; //!< Pre-transformed vertices cache
}; };

View File

@ -29,9 +29,11 @@
// Headers // Headers
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
#include <SFML/Graphics/Export.hpp> #include <SFML/Graphics/Export.hpp>
#include <SFML/Graphics/Texture.hpp>
#include <SFML/Graphics/RenderTarget.hpp> #include <SFML/Graphics/RenderTarget.hpp>
#include <SFML/Graphics/Texture.hpp>
#include <SFML/Window/ContextSettings.hpp> #include <SFML/Window/ContextSettings.hpp>
#include <memory> #include <memory>
@ -39,7 +41,7 @@ namespace sf
{ {
namespace priv namespace priv
{ {
class RenderTextureImpl; class RenderTextureImpl;
} }
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
@ -49,7 +51,6 @@ namespace priv
class SFML_GRAPHICS_API RenderTexture : public RenderTarget class SFML_GRAPHICS_API RenderTexture : public RenderTarget
{ {
public: public:
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \brief Default constructor /// \brief Default constructor
/// ///
@ -224,7 +225,6 @@ public:
const Texture& getTexture() const; const Texture& getTexture() const;
private: private:
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
// Member data // Member data
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////

View File

@ -29,6 +29,7 @@
// Headers // Headers
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
#include <SFML/Graphics/Export.hpp> #include <SFML/Graphics/Export.hpp>
#include <SFML/Graphics/RenderTarget.hpp> #include <SFML/Graphics/RenderTarget.hpp>
#include <SFML/Window/Window.hpp> #include <SFML/Window/Window.hpp>
@ -42,7 +43,6 @@ namespace sf
class SFML_GRAPHICS_API RenderWindow : public Window, public RenderTarget class SFML_GRAPHICS_API RenderWindow : public Window, public RenderTarget
{ {
public: public:
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \brief Default constructor /// \brief Default constructor
/// ///
@ -71,7 +71,10 @@ public:
/// \param settings Additional settings for the underlying OpenGL context /// \param settings Additional settings for the underlying OpenGL context
/// ///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
RenderWindow(VideoMode mode, const String& title, Uint32 style = Style::Default, const ContextSettings& settings = ContextSettings()); RenderWindow(VideoMode mode,
const String& title,
Uint32 style = Style::Default,
const ContextSettings& settings = ContextSettings());
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \brief Construct the window from an existing control /// \brief Construct the window from an existing control
@ -140,7 +143,6 @@ public:
[[nodiscard]] bool setActive(bool active = true) override; [[nodiscard]] bool setActive(bool active = true) override;
protected: protected:
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \brief Function called after the window has been created /// \brief Function called after the window has been created
/// ///
@ -161,7 +163,6 @@ protected:
void onResize() override; void onResize() override;
private: private:
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
// Member data // Member data
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////

View File

@ -29,10 +29,12 @@
// Headers // Headers
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
#include <SFML/Graphics/Export.hpp> #include <SFML/Graphics/Export.hpp>
#include <SFML/Graphics/Glsl.hpp> #include <SFML/Graphics/Glsl.hpp>
#include <SFML/Window/GlResource.hpp>
#include <SFML/System/Vector2.hpp> #include <SFML/System/Vector2.hpp>
#include <SFML/System/Vector3.hpp> #include <SFML/System/Vector3.hpp>
#include <SFML/Window/GlResource.hpp>
#include <filesystem> #include <filesystem>
#include <string> #include <string>
#include <unordered_map> #include <unordered_map>
@ -52,7 +54,6 @@ class Transform;
class SFML_GRAPHICS_API Shader : GlResource class SFML_GRAPHICS_API Shader : GlResource
{ {
public: public:
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \brief Types of shaders /// \brief Types of shaders
/// ///
@ -71,7 +72,9 @@ public:
/// \see setUniform(const std::string&, CurrentTextureType) /// \see setUniform(const std::string&, CurrentTextureType)
/// ///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
struct CurrentTextureType {}; struct CurrentTextureType
{
};
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \brief Represents the texture of the object being drawn /// \brief Represents the texture of the object being drawn
@ -82,7 +85,6 @@ public:
static CurrentTextureType CurrentTexture; static CurrentTextureType CurrentTexture;
public: public:
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \brief Default constructor /// \brief Default constructor
/// ///
@ -149,7 +151,8 @@ public:
/// \see loadFromMemory, loadFromStream /// \see loadFromMemory, loadFromStream
/// ///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
[[nodiscard]] bool loadFromFile(const std::filesystem::path& vertexShaderFilename, const std::filesystem::path& fragmentShaderFilename); [[nodiscard]] bool loadFromFile(const std::filesystem::path& vertexShaderFilename,
const std::filesystem::path& fragmentShaderFilename);
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \brief Load the vertex, geometry and fragment shaders from files /// \brief Load the vertex, geometry and fragment shaders from files
@ -171,7 +174,9 @@ public:
/// \see loadFromMemory, loadFromStream /// \see loadFromMemory, loadFromStream
/// ///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
[[nodiscard]] bool loadFromFile(const std::filesystem::path& vertexShaderFilename, const std::filesystem::path& geometryShaderFilename, const std::filesystem::path& fragmentShaderFilename); [[nodiscard]] bool loadFromFile(const std::filesystem::path& vertexShaderFilename,
const std::filesystem::path& geometryShaderFilename,
const std::filesystem::path& fragmentShaderFilename);
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \brief Load the vertex, geometry or fragment shader from a source code in memory /// \brief Load the vertex, geometry or fragment shader from a source code in memory
@ -234,7 +239,9 @@ public:
/// \see loadFromFile, loadFromStream /// \see loadFromFile, loadFromStream
/// ///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
[[nodiscard]] bool loadFromMemory(const std::string& vertexShader, const std::string& geometryShader, const std::string& fragmentShader); [[nodiscard]] bool loadFromMemory(const std::string& vertexShader,
const std::string& geometryShader,
const std::string& fragmentShader);
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \brief Load the vertex, geometry or fragment shader from a custom stream /// \brief Load the vertex, geometry or fragment shader from a custom stream
@ -297,7 +304,9 @@ public:
/// \see loadFromFile, loadFromMemory /// \see loadFromFile, loadFromMemory
/// ///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
[[nodiscard]] bool loadFromStream(InputStream& vertexShaderStream, InputStream& geometryShaderStream, InputStream& fragmentShaderStream); [[nodiscard]] bool loadFromStream(InputStream& vertexShaderStream,
InputStream& geometryShaderStream,
InputStream& fragmentShaderStream);
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \brief Specify value for \p float uniform /// \brief Specify value for \p float uniform
@ -624,7 +633,6 @@ public:
static bool isGeometryAvailable(); static bool isGeometryAvailable();
private: private:
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \brief Compile the shader(s) and create the program /// \brief Compile the shader(s) and create the program
/// ///
@ -671,7 +679,7 @@ private:
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
// Types // Types
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
using TextureTable = std::unordered_map<int, const Texture *>; using TextureTable = std::unordered_map<int, const Texture*>;
using UniformTable = std::unordered_map<std::string, int>; using UniformTable = std::unordered_map<std::string, int>;
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////

View File

@ -29,6 +29,7 @@
// Headers // Headers
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
#include <SFML/Graphics/Export.hpp> #include <SFML/Graphics/Export.hpp>
#include <SFML/Graphics/Drawable.hpp> #include <SFML/Graphics/Drawable.hpp>
#include <SFML/Graphics/Transformable.hpp> #include <SFML/Graphics/Transformable.hpp>
#include <SFML/Graphics/VertexArray.hpp> #include <SFML/Graphics/VertexArray.hpp>
@ -46,7 +47,6 @@ class Texture;
class SFML_GRAPHICS_API Shape : public Drawable, public Transformable class SFML_GRAPHICS_API Shape : public Drawable, public Transformable
{ {
public: public:
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \brief Virtual destructor /// \brief Virtual destructor
/// ///
@ -250,7 +250,6 @@ public:
FloatRect getGlobalBounds() const; FloatRect getGlobalBounds() const;
protected: protected:
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \brief Default constructor /// \brief Default constructor
/// ///
@ -268,7 +267,6 @@ protected:
void update(); void update();
private: private:
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \brief Draw the shape to a render target /// \brief Draw the shape to a render target
/// ///
@ -303,7 +301,6 @@ private:
void updateOutlineColors(); void updateOutlineColors();
private: private:
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
// Member data // Member data
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////

View File

@ -29,10 +29,11 @@
// Headers // Headers
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
#include <SFML/Graphics/Export.hpp> #include <SFML/Graphics/Export.hpp>
#include <SFML/Graphics/Drawable.hpp> #include <SFML/Graphics/Drawable.hpp>
#include <SFML/Graphics/Rect.hpp>
#include <SFML/Graphics/Transformable.hpp> #include <SFML/Graphics/Transformable.hpp>
#include <SFML/Graphics/Vertex.hpp> #include <SFML/Graphics/Vertex.hpp>
#include <SFML/Graphics/Rect.hpp>
namespace sf namespace sf
@ -47,7 +48,6 @@ class Texture;
class SFML_GRAPHICS_API Sprite : public Drawable, public Transformable class SFML_GRAPHICS_API Sprite : public Drawable, public Transformable
{ {
public: public:
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \brief Default constructor /// \brief Default constructor
/// ///
@ -190,7 +190,6 @@ public:
FloatRect getGlobalBounds() const; FloatRect getGlobalBounds() const;
private: private:
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \brief Draw the sprite to a render target /// \brief Draw the sprite to a render target
/// ///

View File

@ -29,11 +29,13 @@
// Headers // Headers
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
#include <SFML/Graphics/Export.hpp> #include <SFML/Graphics/Export.hpp>
#include <SFML/Graphics/Drawable.hpp> #include <SFML/Graphics/Drawable.hpp>
#include <SFML/Graphics/Transformable.hpp>
#include <SFML/Graphics/Rect.hpp> #include <SFML/Graphics/Rect.hpp>
#include <SFML/Graphics/Transformable.hpp>
#include <SFML/Graphics/VertexArray.hpp> #include <SFML/Graphics/VertexArray.hpp>
#include <SFML/System/String.hpp> #include <SFML/System/String.hpp>
#include <string> #include <string>
#include <vector> #include <vector>
@ -49,7 +51,6 @@ class Font;
class SFML_GRAPHICS_API Text : public Drawable, public Transformable class SFML_GRAPHICS_API Text : public Drawable, public Transformable
{ {
public: public:
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \brief Enumeration of the string drawing styles /// \brief Enumeration of the string drawing styles
/// ///
@ -406,7 +407,6 @@ public:
FloatRect getGlobalBounds() const; FloatRect getGlobalBounds() const;
private: private:
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \brief Draw the text to a render target /// \brief Draw the text to a render target
/// ///

View File

@ -29,8 +29,10 @@
// Headers // Headers
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
#include <SFML/Graphics/Export.hpp> #include <SFML/Graphics/Export.hpp>
#include <SFML/Window/GlResource.hpp>
#include <SFML/Graphics/Rect.hpp> #include <SFML/Graphics/Rect.hpp>
#include <SFML/Window/GlResource.hpp>
#include <filesystem> #include <filesystem>
@ -50,7 +52,6 @@ class Image;
class SFML_GRAPHICS_API Texture : GlResource class SFML_GRAPHICS_API Texture : GlResource
{ {
public: public:
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \brief Types of texture coordinates that can be used for rendering /// \brief Types of texture coordinates that can be used for rendering
/// ///
@ -62,7 +63,6 @@ public:
}; };
public: public:
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \brief Default constructor /// \brief Default constructor
/// ///
@ -512,7 +512,7 @@ public:
/// \return Reference to self /// \return Reference to self
/// ///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
Texture& operator =(const Texture& right); Texture& operator=(const Texture& right);
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \brief Swap the contents of this texture with those of another /// \brief Swap the contents of this texture with those of another
@ -580,7 +580,6 @@ public:
static unsigned int getMaximumSize(); static unsigned int getMaximumSize();
private: private:
friend class Text; friend class Text;
friend class RenderTexture; friend class RenderTexture;
friend class RenderTarget; friend class RenderTarget;

View File

@ -29,6 +29,7 @@
// Headers // Headers
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
#include <SFML/Graphics/Export.hpp> #include <SFML/Graphics/Export.hpp>
#include <SFML/Graphics/Rect.hpp> #include <SFML/Graphics/Rect.hpp>
#include <SFML/System/Vector2.hpp> #include <SFML/System/Vector2.hpp>
@ -44,7 +45,6 @@ class Angle;
class Transform class Transform
{ {
public: public:
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \brief Default constructor /// \brief Default constructor
/// ///
@ -67,9 +67,7 @@ public:
/// \param a22 Element (2, 2) of the matrix /// \param a22 Element (2, 2) of the matrix
/// ///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
constexpr Transform(float a00, float a01, float a02, constexpr Transform(float a00, float a01, float a02, float a10, float a11, float a12, float a20, float a21, float a22);
float a10, float a11, float a12,
float a20, float a21, float a22);
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \brief Return the transform as a 4x4 matrix /// \brief Return the transform as a 4x4 matrix
@ -264,7 +262,6 @@ public:
static const Transform Identity; //!< The identity transform (does nothing) static const Transform Identity; //!< The identity transform (does nothing)
private: private:
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
// Member data // Member data
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
@ -283,7 +280,7 @@ private:
/// \return New combined transform /// \return New combined transform
/// ///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
constexpr Transform operator *(const Transform& left, const Transform& right); constexpr Transform operator*(const Transform& left, const Transform& right);
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \relates sf::Transform /// \relates sf::Transform
@ -297,7 +294,7 @@ constexpr Transform operator *(const Transform& left, const Transform& right);
/// \return The combined transform /// \return The combined transform
/// ///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
constexpr Transform& operator *=(Transform& left, const Transform& right); constexpr Transform& operator*=(Transform& left, const Transform& right);
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \relates sf::Transform /// \relates sf::Transform
@ -311,7 +308,7 @@ constexpr Transform& operator *=(Transform& left, const Transform& right);
/// \return New transformed point /// \return New transformed point
/// ///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
constexpr Vector2f operator *(const Transform& left, const Vector2f& right); constexpr Vector2f operator*(const Transform& left, const Vector2f& right);
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \relates sf::Transform /// \relates sf::Transform
@ -326,7 +323,7 @@ constexpr Vector2f operator *(const Transform& left, const Vector2f& right);
/// \return true if the transforms are equal, false otherwise /// \return true if the transforms are equal, false otherwise
/// ///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
[[nodiscard]] constexpr bool operator ==(const Transform& left, const Transform& right); [[nodiscard]] constexpr bool operator==(const Transform& left, const Transform& right);
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \relates sf::Transform /// \relates sf::Transform
@ -340,7 +337,7 @@ constexpr Vector2f operator *(const Transform& left, const Vector2f& right);
/// \return true if the transforms are not equal, false otherwise /// \return true if the transforms are not equal, false otherwise
/// ///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
[[nodiscard]] constexpr bool operator !=(const Transform& left, const Transform& right); [[nodiscard]] constexpr bool operator!=(const Transform& left, const Transform& right);
#include <SFML/Graphics/Transform.inl> #include <SFML/Graphics/Transform.inl>

View File

@ -102,18 +102,15 @@ constexpr Vector2f Transform::transformPoint(const Vector2f& point) const
constexpr FloatRect Transform::transformRect(const FloatRect& rectangle) const constexpr FloatRect Transform::transformRect(const FloatRect& rectangle) const
{ {
// Transform the 4 corners of the rectangle // Transform the 4 corners of the rectangle
const Vector2f points[] = const Vector2f points[] = {transformPoint({rectangle.left, rectangle.top}),
{ transformPoint({rectangle.left, rectangle.top + rectangle.height}),
transformPoint({rectangle.left, rectangle.top}), transformPoint({rectangle.left + rectangle.width, rectangle.top}),
transformPoint({rectangle.left, rectangle.top + rectangle.height}), transformPoint({rectangle.left + rectangle.width, rectangle.top + rectangle.height})};
transformPoint({rectangle.left + rectangle.width, rectangle.top}),
transformPoint({rectangle.left + rectangle.width, rectangle.top + rectangle.height})
};
// Compute the bounding rectangle of the transformed points // Compute the bounding rectangle of the transformed points
float left = points[0].x; float left = points[0].x;
float top = points[0].y; float top = points[0].y;
float right = points[0].x; float right = points[0].x;
float bottom = points[0].y; float bottom = points[0].y;
for (int i = 1; i < 4; ++i) for (int i = 1; i < 4; ++i)
@ -193,28 +190,28 @@ constexpr Transform& Transform::scale(const Vector2f& factors, const Vector2f& c
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
constexpr Transform operator *(const Transform& left, const Transform& right) constexpr Transform operator*(const Transform& left, const Transform& right)
{ {
return Transform(left).combine(right); return Transform(left).combine(right);
} }
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
constexpr Transform& operator *=(Transform& left, const Transform& right) constexpr Transform& operator*=(Transform& left, const Transform& right)
{ {
return left.combine(right); return left.combine(right);
} }
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
constexpr Vector2f operator *(const Transform& left, const Vector2f& right) constexpr Vector2f operator*(const Transform& left, const Vector2f& right)
{ {
return left.transformPoint(right); return left.transformPoint(right);
} }
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
constexpr bool operator ==(const Transform& left, const Transform& right) constexpr bool operator==(const Transform& left, const Transform& right)
{ {
const float* a = left.getMatrix(); const float* a = left.getMatrix();
const float* b = right.getMatrix(); const float* b = right.getMatrix();
@ -228,7 +225,7 @@ constexpr bool operator ==(const Transform& left, const Transform& right)
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
constexpr bool operator !=(const Transform& left, const Transform& right) constexpr bool operator!=(const Transform& left, const Transform& right)
{ {
return !(left == right); return !(left == right);
} }

View File

@ -29,6 +29,7 @@
// Headers // Headers
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
#include <SFML/Graphics/Export.hpp> #include <SFML/Graphics/Export.hpp>
#include <SFML/Graphics/Transform.hpp> #include <SFML/Graphics/Transform.hpp>
#include <SFML/System/Angle.hpp> #include <SFML/System/Angle.hpp>
@ -42,7 +43,6 @@ namespace sf
class SFML_GRAPHICS_API Transformable class SFML_GRAPHICS_API Transformable
{ {
public: public:
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \brief Default constructor /// \brief Default constructor
/// ///
@ -227,7 +227,6 @@ public:
const Transform& getInverseTransform() const; const Transform& getInverseTransform() const;
private: private:
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
// Member data // Member data
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////

View File

@ -41,7 +41,6 @@ namespace sf
class Vertex class Vertex
{ {
public: public:
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \brief Default constructor /// \brief Default constructor
/// ///
@ -93,9 +92,9 @@ public:
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
// Member data // Member data
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
Vector2f position; //!< 2D position of the vertex Vector2f position; //!< 2D position of the vertex
Color color; //!< Color of the vertex Color color; //!< Color of the vertex
Vector2f texCoords; //!< Coordinates of the texture's pixel to map to the vertex Vector2f texCoords; //!< Coordinates of the texture's pixel to map to the vertex
}; };
#include <SFML/Graphics/Vertex.inl> #include <SFML/Graphics/Vertex.inl>

View File

@ -24,27 +24,21 @@
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
constexpr Vertex::Vertex() : constexpr Vertex::Vertex() : position(0, 0), color(255, 255, 255), texCoords(0, 0)
position (0, 0),
color (255, 255, 255),
texCoords(0, 0)
{ {
} }
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
constexpr Vertex::Vertex(const Vector2f& thePosition) : constexpr Vertex::Vertex(const Vector2f& thePosition) : position(thePosition), color(255, 255, 255), texCoords(0, 0)
position (thePosition),
color (255, 255, 255),
texCoords(0, 0)
{ {
} }
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
constexpr Vertex::Vertex(const Vector2f& thePosition, const Color& theColor) : constexpr Vertex::Vertex(const Vector2f& thePosition, const Color& theColor) :
position (thePosition), position(thePosition),
color (theColor), color(theColor),
texCoords(0, 0) texCoords(0, 0)
{ {
} }
@ -52,8 +46,8 @@ texCoords(0, 0)
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
constexpr Vertex::Vertex(const Vector2f& thePosition, const Vector2f& theTexCoords) : constexpr Vertex::Vertex(const Vector2f& thePosition, const Vector2f& theTexCoords) :
position (thePosition), position(thePosition),
color (255, 255, 255), color(255, 255, 255),
texCoords(theTexCoords) texCoords(theTexCoords)
{ {
} }
@ -61,8 +55,8 @@ texCoords(theTexCoords)
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
constexpr Vertex::Vertex(const Vector2f& thePosition, const Color& theColor, const Vector2f& theTexCoords) : constexpr Vertex::Vertex(const Vector2f& thePosition, const Color& theColor, const Vector2f& theTexCoords) :
position (thePosition), position(thePosition),
color (theColor), color(theColor),
texCoords(theTexCoords) texCoords(theTexCoords)
{ {
} }

View File

@ -29,10 +29,12 @@
// Headers // Headers
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
#include <SFML/Graphics/Export.hpp> #include <SFML/Graphics/Export.hpp>
#include <SFML/Graphics/Vertex.hpp>
#include <SFML/Graphics/Drawable.hpp>
#include <SFML/Graphics/PrimitiveType.hpp> #include <SFML/Graphics/PrimitiveType.hpp>
#include <SFML/Graphics/Rect.hpp> #include <SFML/Graphics/Rect.hpp>
#include <SFML/Graphics/Drawable.hpp> #include <SFML/Graphics/Vertex.hpp>
#include <vector> #include <vector>
@ -45,7 +47,6 @@ namespace sf
class SFML_GRAPHICS_API VertexArray : public Drawable class SFML_GRAPHICS_API VertexArray : public Drawable
{ {
public: public:
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \brief Default constructor /// \brief Default constructor
/// ///
@ -85,7 +86,7 @@ public:
/// \see getVertexCount /// \see getVertexCount
/// ///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
Vertex& operator [](std::size_t index); Vertex& operator[](std::size_t index);
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \brief Get a read-only access to a vertex by its index /// \brief Get a read-only access to a vertex by its index
@ -101,7 +102,7 @@ public:
/// \see getVertexCount /// \see getVertexCount
/// ///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
const Vertex& operator [](std::size_t index) const; const Vertex& operator[](std::size_t index) const;
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \brief Clear the vertex array /// \brief Clear the vertex array
@ -171,7 +172,6 @@ public:
FloatRect getBounds() const; FloatRect getBounds() const;
private: private:
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \brief Draw the vertex array to a render target /// \brief Draw the vertex array to a render target
/// ///
@ -182,7 +182,6 @@ private:
void draw(RenderTarget& target, const RenderStates& states) const override; void draw(RenderTarget& target, const RenderStates& states) const override;
private: private:
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
// Member data // Member data
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////

View File

@ -29,9 +29,11 @@
// Headers // Headers
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
#include <SFML/Graphics/Export.hpp> #include <SFML/Graphics/Export.hpp>
#include <SFML/Graphics/PrimitiveType.hpp>
#include <SFML/Graphics/Drawable.hpp> #include <SFML/Graphics/Drawable.hpp>
#include <SFML/Graphics/PrimitiveType.hpp>
#include <SFML/Window/GlResource.hpp> #include <SFML/Window/GlResource.hpp>
#include <cstddef> #include <cstddef>
@ -47,7 +49,6 @@ class Vertex;
class SFML_GRAPHICS_API VertexBuffer : public Drawable, private GlResource class SFML_GRAPHICS_API VertexBuffer : public Drawable, private GlResource
{ {
public: public:
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \brief Usage specifiers /// \brief Usage specifiers
/// ///
@ -216,7 +217,7 @@ public:
/// \return Reference to self /// \return Reference to self
/// ///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
VertexBuffer& operator =(const VertexBuffer& right); VertexBuffer& operator=(const VertexBuffer& right);
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \brief Swap the contents of this vertex buffer with those of another /// \brief Swap the contents of this vertex buffer with those of another
@ -320,7 +321,6 @@ public:
static bool isAvailable(); static bool isAvailable();
private: private:
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \brief Draw the vertex buffer to a render target /// \brief Draw the vertex buffer to a render target
/// ///
@ -331,7 +331,6 @@ private:
void draw(RenderTarget& target, const RenderStates& states) const override; void draw(RenderTarget& target, const RenderStates& states) const override;
private: private:
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
// Member data // Member data
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////

View File

@ -29,6 +29,7 @@
// Headers // Headers
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
#include <SFML/Graphics/Export.hpp> #include <SFML/Graphics/Export.hpp>
#include <SFML/Graphics/Rect.hpp> #include <SFML/Graphics/Rect.hpp>
#include <SFML/Graphics/Transform.hpp> #include <SFML/Graphics/Transform.hpp>
#include <SFML/System/Angle.hpp> #include <SFML/System/Angle.hpp>
@ -44,7 +45,6 @@ namespace sf
class SFML_GRAPHICS_API View class SFML_GRAPHICS_API View
{ {
public: public:
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \brief Default constructor /// \brief Default constructor
/// ///
@ -233,7 +233,6 @@ public:
const Transform& getInverseTransform() const; const Transform& getInverseTransform() const;
private: private:
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
// Member data // Member data
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////

View File

@ -33,9 +33,9 @@
#if defined(SFML_SYSTEM_IOS) #if defined(SFML_SYSTEM_IOS)
// On iOS, we have no choice but to have our own main, // On iOS, we have no choice but to have our own main,
// so we need to rename the user one and call it later // so we need to rename the user one and call it later
#define main sfmlMain #define main sfmlMain
#endif #endif

View File

@ -29,7 +29,6 @@
// Headers // Headers
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
#include <SFML/System.hpp>
#include <SFML/Network/Ftp.hpp> #include <SFML/Network/Ftp.hpp>
#include <SFML/Network/Http.hpp> #include <SFML/Network/Http.hpp>
#include <SFML/Network/IpAddress.hpp> #include <SFML/Network/IpAddress.hpp>
@ -40,6 +39,7 @@
#include <SFML/Network/TcpListener.hpp> #include <SFML/Network/TcpListener.hpp>
#include <SFML/Network/TcpSocket.hpp> #include <SFML/Network/TcpSocket.hpp>
#include <SFML/Network/UdpSocket.hpp> #include <SFML/Network/UdpSocket.hpp>
#include <SFML/System.hpp>
#endif // SFML_NETWORK_HPP #endif // SFML_NETWORK_HPP

View File

@ -36,11 +36,11 @@
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
#if defined(SFML_NETWORK_EXPORTS) #if defined(SFML_NETWORK_EXPORTS)
#define SFML_NETWORK_API SFML_API_EXPORT #define SFML_NETWORK_API SFML_API_EXPORT
#else #else
#define SFML_NETWORK_API SFML_API_IMPORT #define SFML_NETWORK_API SFML_API_IMPORT
#endif #endif

View File

@ -29,8 +29,10 @@
// Headers // Headers
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
#include <SFML/Network/Export.hpp> #include <SFML/Network/Export.hpp>
#include <SFML/Network/TcpSocket.hpp> #include <SFML/Network/TcpSocket.hpp>
#include <SFML/System/Time.hpp> #include <SFML/System/Time.hpp>
#include <filesystem> #include <filesystem>
#include <string> #include <string>
#include <vector> #include <vector>
@ -47,7 +49,6 @@ class IpAddress;
class SFML_NETWORK_API Ftp class SFML_NETWORK_API Ftp
{ {
public: public:
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \brief Enumeration of transfer modes /// \brief Enumeration of transfer modes
/// ///
@ -66,7 +67,6 @@ public:
class SFML_NETWORK_API Response class SFML_NETWORK_API Response
{ {
public: public:
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \brief Status codes possibly returned by a FTP response /// \brief Status codes possibly returned by a FTP response
/// ///
@ -81,13 +81,13 @@ public:
OpeningDataConnection = 150, //!< File status ok, about to open data connection OpeningDataConnection = 150, //!< File status ok, about to open data connection
// 2xx: the requested action has been successfully completed // 2xx: the requested action has been successfully completed
Ok = 200, //!< Command ok Ok = 200, //!< Command ok
PointlessCommand = 202, //!< Command not implemented PointlessCommand = 202, //!< Command not implemented
SystemStatus = 211, //!< System status, or system help reply SystemStatus = 211, //!< System status, or system help reply
DirectoryStatus = 212, //!< Directory status DirectoryStatus = 212, //!< Directory status
FileStatus = 213, //!< File status FileStatus = 213, //!< File status
HelpMessage = 214, //!< Help message HelpMessage = 214, //!< Help message
SystemType = 215, //!< NAME system type, where NAME is an official system name from the list in the Assigned Numbers document SystemType = 215, //!< NAME system type, where NAME is an official system name from the list in the Assigned Numbers document
ServiceReady = 220, //!< Service ready for new user ServiceReady = 220, //!< Service ready for new user
ClosingConnection = 221, //!< Service closing control connection ClosingConnection = 221, //!< Service closing control connection
DataConnectionOpened = 225, //!< Data connection open, no transfer in progress DataConnectionOpened = 225, //!< Data connection open, no transfer in progress
@ -110,7 +110,7 @@ public:
TransferAborted = 426, //!< Connection closed, transfer aborted TransferAborted = 426, //!< Connection closed, transfer aborted
FileActionAborted = 450, //!< Requested file action not taken FileActionAborted = 450, //!< Requested file action not taken
LocalError = 451, //!< Requested action aborted, local error in processing LocalError = 451, //!< Requested action aborted, local error in processing
InsufficientStorageSpace = 452, //!< Requested action not taken; insufficient storage space in system, file unavailable InsufficientStorageSpace = 452, //!< Requested action not taken; insufficient storage space in system, file unavailable
// 5xx: the command was not accepted and // 5xx: the command was not accepted and
// the requested action did not take place // the requested action did not take place
@ -127,10 +127,10 @@ public:
FilenameNotAllowed = 553, //!< Requested action not taken, file name not allowed FilenameNotAllowed = 553, //!< Requested action not taken, file name not allowed
// 10xx: SFML custom codes // 10xx: SFML custom codes
InvalidResponse = 1000, //!< Not part of the FTP standard, generated by SFML when a received response cannot be parsed InvalidResponse = 1000, //!< Not part of the FTP standard, generated by SFML when a received response cannot be parsed
ConnectionFailed = 1001, //!< Not part of the FTP standard, generated by SFML when the low-level socket connection with the server fails ConnectionFailed = 1001, //!< Not part of the FTP standard, generated by SFML when the low-level socket connection with the server fails
ConnectionClosed = 1002, //!< Not part of the FTP standard, generated by SFML when the low-level socket connection is unexpectedly closed ConnectionClosed = 1002, //!< Not part of the FTP standard, generated by SFML when the low-level socket connection is unexpectedly closed
InvalidFile = 1003 //!< Not part of the FTP standard, generated by SFML when a local file cannot be read or written InvalidFile = 1003 //!< Not part of the FTP standard, generated by SFML when a local file cannot be read or written
}; };
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
@ -173,7 +173,6 @@ public:
const std::string& getMessage() const; const std::string& getMessage() const;
private: private:
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
// Member data // Member data
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
@ -188,7 +187,6 @@ public:
class SFML_NETWORK_API DirectoryResponse : public Response class SFML_NETWORK_API DirectoryResponse : public Response
{ {
public: public:
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \brief Default constructor /// \brief Default constructor
/// ///
@ -206,7 +204,6 @@ public:
const std::filesystem::path& getDirectory() const; const std::filesystem::path& getDirectory() const;
private: private:
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
// Member data // Member data
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
@ -221,7 +218,6 @@ public:
class SFML_NETWORK_API ListingResponse : public Response class SFML_NETWORK_API ListingResponse : public Response
{ {
public: public:
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \brief Default constructor /// \brief Default constructor
/// ///
@ -240,7 +236,6 @@ public:
const std::vector<std::string>& getListing() const; const std::vector<std::string>& getListing() const;
private: private:
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
// Member data // Member data
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
@ -482,7 +477,9 @@ public:
/// \see upload /// \see upload
/// ///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
[[nodiscard]] Response download(const std::filesystem::path& remoteFile, const std::filesystem::path& localPath, TransferMode mode = Binary); [[nodiscard]] Response download(const std::filesystem::path& remoteFile,
const std::filesystem::path& localPath,
TransferMode mode = Binary);
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \brief Upload a file to the server /// \brief Upload a file to the server
@ -505,7 +502,10 @@ public:
/// \see download /// \see download
/// ///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
[[nodiscard]] Response upload(const std::string& localFile, const std::string& remotePath, TransferMode mode = Binary, bool append = false); [[nodiscard]] Response upload(const std::string& localFile,
const std::string& remotePath,
TransferMode mode = Binary,
bool append = false);
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \brief Send a command to the FTP server /// \brief Send a command to the FTP server
@ -526,7 +526,6 @@ public:
[[nodiscard]] Response sendCommand(const std::string& command, const std::string& parameter = ""); [[nodiscard]] Response sendCommand(const std::string& command, const std::string& parameter = "");
private: private:
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \brief Receive a response from the server /// \brief Receive a response from the server
/// ///

View File

@ -29,9 +29,11 @@
// Headers // Headers
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
#include <SFML/Network/Export.hpp> #include <SFML/Network/Export.hpp>
#include <SFML/Network/IpAddress.hpp> #include <SFML/Network/IpAddress.hpp>
#include <SFML/Network/TcpSocket.hpp> #include <SFML/Network/TcpSocket.hpp>
#include <SFML/System/Time.hpp> #include <SFML/System/Time.hpp>
#include <map> #include <map>
#include <optional> #include <optional>
#include <string> #include <string>
@ -46,7 +48,6 @@ namespace sf
class SFML_NETWORK_API Http class SFML_NETWORK_API Http
{ {
public: public:
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \brief Define a HTTP request /// \brief Define a HTTP request
/// ///
@ -54,7 +55,6 @@ public:
class SFML_NETWORK_API Request class SFML_NETWORK_API Request
{ {
public: public:
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \brief Enumerate the available HTTP methods for a request /// \brief Enumerate the available HTTP methods for a request
/// ///
@ -144,7 +144,6 @@ public:
void setBody(const std::string& body); void setBody(const std::string& body);
private: private:
friend class Http; friend class Http;
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
@ -193,7 +192,6 @@ public:
class SFML_NETWORK_API Response class SFML_NETWORK_API Response
{ {
public: public:
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \brief Enumerate all the valid status codes for a response /// \brief Enumerate all the valid status codes for a response
/// ///
@ -201,18 +199,18 @@ public:
enum Status enum Status
{ {
// 2xx: success // 2xx: success
Ok = 200, //!< Most common code returned when operation was successful Ok = 200, //!< Most common code returned when operation was successful
Created = 201, //!< The resource has successfully been created Created = 201, //!< The resource has successfully been created
Accepted = 202, //!< The request has been accepted, but will be processed later by the server Accepted = 202, //!< The request has been accepted, but will be processed later by the server
NoContent = 204, //!< The server didn't send any data in return NoContent = 204, //!< The server didn't send any data in return
ResetContent = 205, //!< The server informs the client that it should clear the view (form) that caused the request to be sent ResetContent = 205, //!< The server informs the client that it should clear the view (form) that caused the request to be sent
PartialContent = 206, //!< The server has sent a part of the resource, as a response to a partial GET request PartialContent = 206, //!< The server has sent a part of the resource, as a response to a partial GET request
// 3xx: redirection // 3xx: redirection
MultipleChoices = 300, //!< The requested page can be accessed from several locations MultipleChoices = 300, //!< The requested page can be accessed from several locations
MovedPermanently = 301, //!< The requested page has permanently moved to a new location MovedPermanently = 301, //!< The requested page has permanently moved to a new location
MovedTemporarily = 302, //!< The requested page has temporarily moved to a new location MovedTemporarily = 302, //!< The requested page has temporarily moved to a new location
NotModified = 304, //!< For conditional requests, means the requested page hasn't changed and doesn't need to be refreshed NotModified = 304, //!< For conditional requests, means the requested page hasn't changed and doesn't need to be refreshed
// 4xx: client error // 4xx: client error
BadRequest = 400, //!< The server couldn't understand the request (syntax error) BadRequest = 400, //!< The server couldn't understand the request (syntax error)
@ -304,7 +302,6 @@ public:
const std::string& getBody() const; const std::string& getBody() const;
private: private:
friend class Http; friend class Http;
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
@ -328,7 +325,7 @@ public:
/// \param in String stream containing the header values /// \param in String stream containing the header values
/// ///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
void parseFields(std::istream &in); void parseFields(std::istream& in);
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
// Types // Types
@ -417,7 +414,6 @@ public:
[[nodiscard]] Response sendRequest(const Request& request, Time timeout = Time::Zero); [[nodiscard]] Response sendRequest(const Request& request, Time timeout = Time::Zero);
private: private:
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
// Member data // Member data
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////

View File

@ -29,11 +29,13 @@
// Headers // Headers
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
#include <SFML/Network/Export.hpp> #include <SFML/Network/Export.hpp>
#include <SFML/System/Time.hpp> #include <SFML/System/Time.hpp>
#include <iosfwd> #include <iosfwd>
#include <optional> #include <optional>
#include <string_view>
#include <string> #include <string>
#include <string_view>
namespace sf namespace sf
@ -164,8 +166,7 @@ public:
static const IpAddress Broadcast; //!< The "broadcast" address (for sending UDP messages to everyone on a local network) static const IpAddress Broadcast; //!< The "broadcast" address (for sending UDP messages to everyone on a local network)
private: private:
friend SFML_NETWORK_API bool operator<(const IpAddress& left, const IpAddress& right);
friend SFML_NETWORK_API bool operator <(const IpAddress& left, const IpAddress& right);
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
// Member data // Member data
@ -182,7 +183,7 @@ private:
/// \return True if both addresses are equal /// \return True if both addresses are equal
/// ///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
SFML_NETWORK_API bool operator ==(const IpAddress& left, const IpAddress& right); SFML_NETWORK_API bool operator==(const IpAddress& left, const IpAddress& right);
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \brief Overload of != operator to compare two IP addresses /// \brief Overload of != operator to compare two IP addresses
@ -193,7 +194,7 @@ SFML_NETWORK_API bool operator ==(const IpAddress& left, const IpAddress& right)
/// \return True if both addresses are different /// \return True if both addresses are different
/// ///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
SFML_NETWORK_API bool operator !=(const IpAddress& left, const IpAddress& right); SFML_NETWORK_API bool operator!=(const IpAddress& left, const IpAddress& right);
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \brief Overload of < operator to compare two IP addresses /// \brief Overload of < operator to compare two IP addresses
@ -204,7 +205,7 @@ SFML_NETWORK_API bool operator !=(const IpAddress& left, const IpAddress& right)
/// \return True if \a left is lesser than \a right /// \return True if \a left is lesser than \a right
/// ///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
SFML_NETWORK_API bool operator <(const IpAddress& left, const IpAddress& right); SFML_NETWORK_API bool operator<(const IpAddress& left, const IpAddress& right);
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \brief Overload of > operator to compare two IP addresses /// \brief Overload of > operator to compare two IP addresses
@ -215,7 +216,7 @@ SFML_NETWORK_API bool operator <(const IpAddress& left, const IpAddress& right);
/// \return True if \a left is greater than \a right /// \return True if \a left is greater than \a right
/// ///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
SFML_NETWORK_API bool operator >(const IpAddress& left, const IpAddress& right); SFML_NETWORK_API bool operator>(const IpAddress& left, const IpAddress& right);
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \brief Overload of <= operator to compare two IP addresses /// \brief Overload of <= operator to compare two IP addresses
@ -226,7 +227,7 @@ SFML_NETWORK_API bool operator >(const IpAddress& left, const IpAddress& right);
/// \return True if \a left is lesser or equal than \a right /// \return True if \a left is lesser or equal than \a right
/// ///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
SFML_NETWORK_API bool operator <=(const IpAddress& left, const IpAddress& right); SFML_NETWORK_API bool operator<=(const IpAddress& left, const IpAddress& right);
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \brief Overload of >= operator to compare two IP addresses /// \brief Overload of >= operator to compare two IP addresses
@ -237,7 +238,7 @@ SFML_NETWORK_API bool operator <=(const IpAddress& left, const IpAddress& right)
/// \return True if \a left is greater or equal than \a right /// \return True if \a left is greater or equal than \a right
/// ///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
SFML_NETWORK_API bool operator >=(const IpAddress& left, const IpAddress& right); SFML_NETWORK_API bool operator>=(const IpAddress& left, const IpAddress& right);
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \brief Overload of >> operator to extract an IP address from an input stream /// \brief Overload of >> operator to extract an IP address from an input stream
@ -248,7 +249,7 @@ SFML_NETWORK_API bool operator >=(const IpAddress& left, const IpAddress& right)
/// \return Reference to the input stream /// \return Reference to the input stream
/// ///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
SFML_NETWORK_API std::istream& operator >>(std::istream& stream, std::optional<IpAddress>& address); SFML_NETWORK_API std::istream& operator>>(std::istream& stream, std::optional<IpAddress>& address);
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \brief Overload of << operator to print an IP address to an output stream /// \brief Overload of << operator to print an IP address to an output stream
@ -259,7 +260,7 @@ SFML_NETWORK_API std::istream& operator >>(std::istream& stream, std::optional<I
/// \return Reference to the output stream /// \return Reference to the output stream
/// ///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
SFML_NETWORK_API std::ostream& operator <<(std::ostream& stream, const IpAddress& address); SFML_NETWORK_API std::ostream& operator<<(std::ostream& stream, const IpAddress& address);
} // namespace sf } // namespace sf

View File

@ -29,9 +29,10 @@
// Headers // Headers
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
#include <SFML/Network/Export.hpp> #include <SFML/Network/Export.hpp>
#include <cstddef>
#include <string> #include <string>
#include <vector> #include <vector>
#include <cstddef>
namespace sf namespace sf
@ -48,7 +49,6 @@ class UdpSocket;
class SFML_NETWORK_API Packet class SFML_NETWORK_API Packet
{ {
public: public:
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \brief Default constructor /// \brief Default constructor
/// ///
@ -164,7 +164,6 @@ public:
bool endOfPacket() const; bool endOfPacket() const;
public: public:
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \brief Test the validity of the packet, for reading /// \brief Test the validity of the packet, for reading
/// ///
@ -209,166 +208,165 @@ public:
/// Overload of operator >> to read data from the packet /// Overload of operator >> to read data from the packet
/// ///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
Packet& operator >>(bool& data); Packet& operator>>(bool& data);
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \overload /// \overload
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
Packet& operator >>(Int8& data); Packet& operator>>(Int8& data);
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \overload /// \overload
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
Packet& operator >>(Uint8& data); Packet& operator>>(Uint8& data);
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \overload /// \overload
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
Packet& operator >>(Int16& data); Packet& operator>>(Int16& data);
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \overload /// \overload
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
Packet& operator >>(Uint16& data); Packet& operator>>(Uint16& data);
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \overload /// \overload
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
Packet& operator >>(Int32& data); Packet& operator>>(Int32& data);
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \overload /// \overload
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
Packet& operator >>(Uint32& data); Packet& operator>>(Uint32& data);
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \overload /// \overload
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
Packet& operator >>(Int64& data); Packet& operator>>(Int64& data);
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \overload /// \overload
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
Packet& operator >>(Uint64& data); Packet& operator>>(Uint64& data);
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \overload /// \overload
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
Packet& operator >>(float& data); Packet& operator>>(float& data);
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \overload /// \overload
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
Packet& operator >>(double& data); Packet& operator>>(double& data);
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \overload /// \overload
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
Packet& operator >>(char* data); Packet& operator>>(char* data);
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \overload /// \overload
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
Packet& operator >>(std::string& data); Packet& operator>>(std::string& data);
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \overload /// \overload
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
Packet& operator >>(wchar_t* data); Packet& operator>>(wchar_t* data);
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \overload /// \overload
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
Packet& operator >>(std::wstring& data); Packet& operator>>(std::wstring& data);
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \overload /// \overload
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
Packet& operator >>(String& data); Packet& operator>>(String& data);
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// Overload of operator << to write data into the packet /// Overload of operator << to write data into the packet
/// ///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
Packet& operator <<(bool data); Packet& operator<<(bool data);
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \overload /// \overload
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
Packet& operator <<(Int8 data); Packet& operator<<(Int8 data);
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \overload /// \overload
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
Packet& operator <<(Uint8 data); Packet& operator<<(Uint8 data);
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \overload /// \overload
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
Packet& operator <<(Int16 data); Packet& operator<<(Int16 data);
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \overload /// \overload
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
Packet& operator <<(Uint16 data); Packet& operator<<(Uint16 data);
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \overload /// \overload
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
Packet& operator <<(Int32 data); Packet& operator<<(Int32 data);
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \overload /// \overload
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
Packet& operator <<(Uint32 data); Packet& operator<<(Uint32 data);
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \overload /// \overload
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
Packet& operator <<(Int64 data); Packet& operator<<(Int64 data);
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \overload /// \overload
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
Packet& operator <<(Uint64 data); Packet& operator<<(Uint64 data);
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \overload /// \overload
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
Packet& operator <<(float data); Packet& operator<<(float data);
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \overload /// \overload
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
Packet& operator <<(double data); Packet& operator<<(double data);
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \overload /// \overload
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
Packet& operator <<(const char* data); Packet& operator<<(const char* data);
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \overload /// \overload
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
Packet& operator <<(const std::string& data); Packet& operator<<(const std::string& data);
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \overload /// \overload
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
Packet& operator <<(const wchar_t* data); Packet& operator<<(const wchar_t* data);
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \overload /// \overload
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
Packet& operator <<(const std::wstring& data); Packet& operator<<(const std::wstring& data);
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \overload /// \overload
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
Packet& operator <<(const String& data); Packet& operator<<(const String& data);
protected: protected:
friend class TcpSocket; friend class TcpSocket;
friend class UdpSocket; friend class UdpSocket;
@ -412,13 +410,12 @@ protected:
virtual void onReceive(const void* data, std::size_t size); virtual void onReceive(const void* data, std::size_t size);
private: private:
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// Disallow comparisons between packets /// Disallow comparisons between packets
/// ///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
bool operator ==(const Packet& right) const; bool operator==(const Packet& right) const;
bool operator !=(const Packet& right) const; bool operator!=(const Packet& right) const;
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \brief Check if the packet can extract a given number of bytes /// \brief Check if the packet can extract a given number of bytes

View File

@ -29,7 +29,9 @@
// Headers // Headers
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
#include <SFML/Network/Export.hpp> #include <SFML/Network/Export.hpp>
#include <SFML/Network/SocketHandle.hpp> #include <SFML/Network/SocketHandle.hpp>
#include <vector> #include <vector>
@ -44,7 +46,6 @@ class SocketSelector;
class SFML_NETWORK_API Socket class SFML_NETWORK_API Socket
{ {
public: public:
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \brief Status codes that may be returned by socket functions /// \brief Status codes that may be returned by socket functions
/// ///
@ -68,7 +69,6 @@ public:
}; };
public: public:
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \brief Destructor /// \brief Destructor
/// ///
@ -117,7 +117,6 @@ public:
bool isBlocking() const; bool isBlocking() const;
protected: protected:
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \brief Types of protocols that the socket can use /// \brief Types of protocols that the socket can use
/// ///
@ -178,7 +177,6 @@ protected:
void close(); void close();
private: private:
friend class SocketSelector; friend class SocketSelector;
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////

View File

@ -31,7 +31,7 @@
#include <SFML/Config.hpp> #include <SFML/Config.hpp>
#if defined(SFML_SYSTEM_WINDOWS) #if defined(SFML_SYSTEM_WINDOWS)
#include <basetsd.h> #include <basetsd.h>
#endif #endif
@ -43,11 +43,11 @@ namespace sf
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
#if defined(SFML_SYSTEM_WINDOWS) #if defined(SFML_SYSTEM_WINDOWS)
using SocketHandle = UINT_PTR; using SocketHandle = UINT_PTR;
#else #else
using SocketHandle = int; using SocketHandle = int;
#endif #endif

View File

@ -29,7 +29,9 @@
// Headers // Headers
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
#include <SFML/Network/Export.hpp> #include <SFML/Network/Export.hpp>
#include <SFML/System/Time.hpp> #include <SFML/System/Time.hpp>
#include <memory> #include <memory>
@ -44,7 +46,6 @@ class Socket;
class SFML_NETWORK_API SocketSelector class SFML_NETWORK_API SocketSelector
{ {
public: public:
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \brief Default constructor /// \brief Default constructor
/// ///
@ -150,10 +151,9 @@ public:
/// \return Reference to self /// \return Reference to self
/// ///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
SocketSelector& operator =(const SocketSelector& right); SocketSelector& operator=(const SocketSelector& right);
private: private:
struct SocketSelectorImpl; struct SocketSelectorImpl;
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////

View File

@ -29,8 +29,9 @@
// Headers // Headers
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
#include <SFML/Network/Export.hpp> #include <SFML/Network/Export.hpp>
#include <SFML/Network/Socket.hpp>
#include <SFML/Network/IpAddress.hpp> #include <SFML/Network/IpAddress.hpp>
#include <SFML/Network/Socket.hpp>
namespace sf namespace sf
@ -44,7 +45,6 @@ class TcpSocket;
class SFML_NETWORK_API TcpListener : public Socket class SFML_NETWORK_API TcpListener : public Socket
{ {
public: public:
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \brief Default constructor /// \brief Default constructor
/// ///

View File

@ -29,8 +29,10 @@
// Headers // Headers
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
#include <SFML/Network/Export.hpp> #include <SFML/Network/Export.hpp>
#include <SFML/Network/Socket.hpp> #include <SFML/Network/Socket.hpp>
#include <SFML/System/Time.hpp> #include <SFML/System/Time.hpp>
#include <optional> #include <optional>
@ -47,7 +49,6 @@ class Packet;
class SFML_NETWORK_API TcpSocket : public Socket class SFML_NETWORK_API TcpSocket : public Socket
{ {
public: public:
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \brief Default constructor /// \brief Default constructor
/// ///
@ -210,7 +211,6 @@ public:
[[nodiscard]] Status receive(Packet& packet); [[nodiscard]] Status receive(Packet& packet);
private: private:
friend class TcpListener; friend class TcpListener;
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////

View File

@ -29,8 +29,10 @@
// Headers // Headers
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
#include <SFML/Network/Export.hpp> #include <SFML/Network/Export.hpp>
#include <SFML/Network/Socket.hpp>
#include <SFML/Network/IpAddress.hpp> #include <SFML/Network/IpAddress.hpp>
#include <SFML/Network/Socket.hpp>
#include <optional> #include <optional>
#include <vector> #include <vector>
@ -46,7 +48,6 @@ class Packet;
class SFML_NETWORK_API UdpSocket : public Socket class SFML_NETWORK_API UdpSocket : public Socket
{ {
public: public:
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
// Constants // Constants
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
@ -153,7 +154,11 @@ public:
/// \see send /// \see send
/// ///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
[[nodiscard]] Status receive(void* data, std::size_t size, std::size_t& received, std::optional<IpAddress>& remoteAddress, unsigned short& remotePort); [[nodiscard]] Status receive(void* data,
std::size_t size,
std::size_t& received,
std::optional<IpAddress>& remoteAddress,
unsigned short& remotePort);
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \brief Send a formatted packet of data to a remote peer /// \brief Send a formatted packet of data to a remote peer
@ -191,7 +196,6 @@ public:
[[nodiscard]] Status receive(Packet& packet, std::optional<IpAddress>& remoteAddress, unsigned short& remotePort); [[nodiscard]] Status receive(Packet& packet, std::optional<IpAddress>& remoteAddress, unsigned short& remotePort);
private: private:
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
// Member data // Member data
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////

View File

@ -38,42 +38,43 @@
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
#if defined(SFML_SYSTEM_WINDOWS) #if defined(SFML_SYSTEM_WINDOWS)
// The Visual C++ version of gl.h uses WINGDIAPI and APIENTRY but doesn't define them // The Visual C++ version of gl.h uses WINGDIAPI and APIENTRY but doesn't define them
#ifdef _MSC_VER #ifdef _MSC_VER
#ifndef WIN32_LEAN_AND_MEAN #ifndef WIN32_LEAN_AND_MEAN
#define WIN32_LEAN_AND_MEAN #define WIN32_LEAN_AND_MEAN
#endif #endif
#include <windows.h> #include <windows.h>
#endif #endif
#include <GL/gl.h> #include <GL/gl.h>
#elif defined(SFML_SYSTEM_LINUX) || defined(SFML_SYSTEM_FREEBSD) || defined(SFML_SYSTEM_OPENBSD) || defined(SFML_SYSTEM_NETBSD) #elif defined(SFML_SYSTEM_LINUX) || defined(SFML_SYSTEM_FREEBSD) || defined(SFML_SYSTEM_OPENBSD) || \
defined(SFML_SYSTEM_NETBSD)
#if defined(SFML_OPENGL_ES) #if defined(SFML_OPENGL_ES)
#include <GLES/gl.h> #include <GLES/gl.h>
#include <GLES/glext.h> #include <GLES/glext.h>
#else #else
#include <GL/gl.h> #include <GL/gl.h>
#endif #endif
#elif defined(SFML_SYSTEM_MACOS) #elif defined(SFML_SYSTEM_MACOS)
#include <OpenGL/gl.h> #include <OpenGL/gl.h>
#elif defined (SFML_SYSTEM_IOS) #elif defined(SFML_SYSTEM_IOS)
#include <OpenGLES/ES1/gl.h> #include <OpenGLES/ES1/gl.h>
#include <OpenGLES/ES1/glext.h> #include <OpenGLES/ES1/glext.h>
#elif defined (SFML_SYSTEM_ANDROID) #elif defined(SFML_SYSTEM_ANDROID)
#include <GLES/gl.h> #include <GLES/gl.h>
#include <GLES/glext.h> #include <GLES/glext.h>
// We're not using OpenGL ES 2+ yet, but we can use the sRGB extension // We're not using OpenGL ES 2+ yet, but we can use the sRGB extension
#include <GLES2/gl2platform.h> #include <GLES2/gl2ext.h>
#include <GLES2/gl2ext.h> #include <GLES2/gl2platform.h>
#endif #endif

View File

@ -30,6 +30,7 @@
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
#include <SFML/Config.hpp> #include <SFML/Config.hpp>
#include <SFML/System/Angle.hpp> #include <SFML/System/Angle.hpp>
#include <SFML/System/Clock.hpp> #include <SFML/System/Clock.hpp>
#include <SFML/System/Err.hpp> #include <SFML/System/Err.hpp>

View File

@ -29,6 +29,7 @@
// Headers // Headers
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
#include <SFML/System/Export.hpp> #include <SFML/System/Export.hpp>
#include <cassert> #include <cassert>
@ -41,7 +42,6 @@ namespace sf
class Angle class Angle
{ {
public: public:
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \brief Default constructor /// \brief Default constructor
/// ///
@ -142,7 +142,6 @@ public:
static const Angle Zero; //!< Predefined 0 degree angle value static const Angle Zero; //!< Predefined 0 degree angle value
private: private:
friend constexpr Angle degrees(float angle); friend constexpr Angle degrees(float angle);
friend constexpr Angle radians(float angle); friend constexpr Angle radians(float angle);
@ -158,7 +157,6 @@ private:
constexpr explicit Angle(float degrees); constexpr explicit Angle(float degrees);
private: private:
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
// Member data // Member data
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
@ -199,7 +197,7 @@ private:
/// \return True if both angle values are equal /// \return True if both angle values are equal
/// ///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
[[nodiscard]] constexpr bool operator ==(Angle left, Angle right); [[nodiscard]] constexpr bool operator==(Angle left, Angle right);
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \relates Angle /// \relates Angle
@ -211,7 +209,7 @@ private:
/// \return True if both angle values are different /// \return True if both angle values are different
/// ///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
[[nodiscard]] constexpr bool operator !=(Angle left, Angle right); [[nodiscard]] constexpr bool operator!=(Angle left, Angle right);
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \relates Angle /// \relates Angle
@ -223,7 +221,7 @@ private:
/// \return True if \a left is less than \a right /// \return True if \a left is less than \a right
/// ///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
[[nodiscard]] constexpr bool operator <(Angle left, Angle right); [[nodiscard]] constexpr bool operator<(Angle left, Angle right);
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \relates Angle /// \relates Angle
@ -235,7 +233,7 @@ private:
/// \return True if \a left is greater than \a right /// \return True if \a left is greater than \a right
/// ///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
[[nodiscard]] constexpr bool operator >(Angle left, Angle right); [[nodiscard]] constexpr bool operator>(Angle left, Angle right);
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \relates Angle /// \relates Angle
@ -247,7 +245,7 @@ private:
/// \return True if \a left is less than or equal to \a right /// \return True if \a left is less than or equal to \a right
/// ///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
[[nodiscard]] constexpr bool operator <=(Angle left, Angle right); [[nodiscard]] constexpr bool operator<=(Angle left, Angle right);
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \relates Angle /// \relates Angle
@ -259,7 +257,7 @@ private:
/// \return True if \a left is greater than or equal to \a right /// \return True if \a left is greater than or equal to \a right
/// ///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
[[nodiscard]] constexpr bool operator >=(Angle left, Angle right); [[nodiscard]] constexpr bool operator>=(Angle left, Angle right);
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \relates Angle /// \relates Angle
@ -272,7 +270,7 @@ private:
/// \return Negative of the angle value /// \return Negative of the angle value
/// ///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
[[nodiscard]] constexpr Angle operator -(Angle right); [[nodiscard]] constexpr Angle operator-(Angle right);
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \relates Angle /// \relates Angle
@ -284,7 +282,7 @@ private:
/// \return Sum of the two angle values /// \return Sum of the two angle values
/// ///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
[[nodiscard]] constexpr Angle operator +(Angle left, Angle right); [[nodiscard]] constexpr Angle operator+(Angle left, Angle right);
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \relates Angle /// \relates Angle
@ -296,7 +294,7 @@ private:
/// \return Sum of the two angle values /// \return Sum of the two angle values
/// ///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
constexpr Angle& operator +=(Angle& left, Angle right); constexpr Angle& operator+=(Angle& left, Angle right);
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \relates Angle /// \relates Angle
@ -308,7 +306,7 @@ constexpr Angle& operator +=(Angle& left, Angle right);
/// \return Difference of the two angle values /// \return Difference of the two angle values
/// ///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
[[nodiscard]] constexpr Angle operator -(Angle left, Angle right); [[nodiscard]] constexpr Angle operator-(Angle left, Angle right);
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \relates Angle /// \relates Angle
@ -320,7 +318,7 @@ constexpr Angle& operator +=(Angle& left, Angle right);
/// \return Difference of the two angle values /// \return Difference of the two angle values
/// ///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
constexpr Angle& operator -=(Angle& left, Angle right); constexpr Angle& operator-=(Angle& left, Angle right);
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \relates Angle /// \relates Angle
@ -332,7 +330,7 @@ constexpr Angle& operator -=(Angle& left, Angle right);
/// \return \a left multiplied by \a right /// \return \a left multiplied by \a right
/// ///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
[[nodiscard]] constexpr Angle operator *(Angle left, float right); [[nodiscard]] constexpr Angle operator*(Angle left, float right);
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \relates Angle /// \relates Angle
@ -344,7 +342,7 @@ constexpr Angle& operator -=(Angle& left, Angle right);
/// \return \a left multiplied by \a right /// \return \a left multiplied by \a right
/// ///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
[[nodiscard]] constexpr Angle operator *(float left, Angle right); [[nodiscard]] constexpr Angle operator*(float left, Angle right);
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \relates Angle /// \relates Angle
@ -356,7 +354,7 @@ constexpr Angle& operator -=(Angle& left, Angle right);
/// \return \a left multiplied by \a right /// \return \a left multiplied by \a right
/// ///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
constexpr Angle& operator *=(Angle& left, float right); constexpr Angle& operator*=(Angle& left, float right);
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \relates Angle /// \relates Angle
@ -368,7 +366,7 @@ constexpr Angle& operator *=(Angle& left, float right);
/// \return \a left divided by \a right /// \return \a left divided by \a right
/// ///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
[[nodiscard]] constexpr Angle operator /(Angle left, float right); [[nodiscard]] constexpr Angle operator/(Angle left, float right);
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \relates Angle /// \relates Angle
@ -380,7 +378,7 @@ constexpr Angle& operator *=(Angle& left, float right);
/// \return \a left divided by \a right /// \return \a left divided by \a right
/// ///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
constexpr Angle& operator /=(Angle& left, float right); constexpr Angle& operator/=(Angle& left, float right);
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \relates Angle /// \relates Angle
@ -392,7 +390,7 @@ constexpr Angle& operator /=(Angle& left, float right);
/// \return \a left divided by \a right /// \return \a left divided by \a right
/// ///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
[[nodiscard]] constexpr float operator /(Angle left, Angle right); [[nodiscard]] constexpr float operator/(Angle left, Angle right);
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \relates Angle /// \relates Angle
@ -412,7 +410,7 @@ constexpr Angle& operator /=(Angle& left, float right);
/// \return \a left modulo \a right /// \return \a left modulo \a right
/// ///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
[[nodiscard]] constexpr Angle operator %(Angle left, Angle right); [[nodiscard]] constexpr Angle operator%(Angle left, Angle right);
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \relates Angle /// \relates Angle
@ -424,7 +422,7 @@ constexpr Angle& operator /=(Angle& left, float right);
/// \return \a left modulo \a right /// \return \a left modulo \a right
/// ///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
constexpr Angle& operator %=(Angle& left, Angle right); constexpr Angle& operator%=(Angle& left, Angle right);
namespace Literals namespace Literals
{ {
@ -438,7 +436,7 @@ namespace Literals
/// \return \a Angle /// \return \a Angle
/// ///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
[[nodiscard]] constexpr Angle operator "" _deg(long double angle); [[nodiscard]] constexpr Angle operator"" _deg(long double angle);
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \relates sf::Angle /// \relates sf::Angle
@ -449,7 +447,7 @@ namespace Literals
/// \return \a Angle /// \return \a Angle
/// ///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
[[nodiscard]] constexpr Angle operator "" _deg(unsigned long long int angle); [[nodiscard]] constexpr Angle operator"" _deg(unsigned long long int angle);
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \relates sf::Angle /// \relates sf::Angle
@ -460,7 +458,7 @@ namespace Literals
/// \return \a Angle /// \return \a Angle
/// ///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
[[nodiscard]] constexpr Angle operator "" _rad(long double angle); [[nodiscard]] constexpr Angle operator"" _rad(long double angle);
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \relates sf::Angle /// \relates sf::Angle
@ -471,7 +469,7 @@ namespace Literals
/// \return \a Angle /// \return \a Angle
/// ///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
[[nodiscard]] constexpr Angle operator "" _rad(unsigned long long int angle); [[nodiscard]] constexpr Angle operator"" _rad(unsigned long long int angle);
} // namespace Literals } // namespace Literals

View File

@ -24,23 +24,22 @@
namespace priv namespace priv
{ {
constexpr float pi = 3.141592654f; constexpr float pi = 3.141592654f;
constexpr float positiveRemainder(float a, float b) constexpr float positiveRemainder(float a, float b)
{ {
assert(b > 0.0f); assert(b > 0.0f);
const float val = a - static_cast<float>(static_cast<int>(a / b)) * b; const float val = a - static_cast<float>(static_cast<int>(a / b)) * b;
if (val >= 0.f) if (val >= 0.f)
return val; return val;
else else
return val + b; return val + b;
}
} }
} // namespace priv
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
constexpr Angle::Angle() : constexpr Angle::Angle() : m_degrees(0.0f)
m_degrees(0.0f)
{ {
} }
@ -74,8 +73,7 @@ constexpr Angle Angle::wrapUnsigned() const
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
constexpr Angle::Angle(float degrees) : constexpr Angle::Angle(float degrees) : m_degrees(degrees)
m_degrees(degrees)
{ {
} }
@ -95,133 +93,133 @@ constexpr Angle radians(float angle)
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
constexpr bool operator ==(Angle left, Angle right) constexpr bool operator==(Angle left, Angle right)
{ {
return left.asDegrees() == right.asDegrees(); return left.asDegrees() == right.asDegrees();
} }
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
constexpr bool operator !=(Angle left, Angle right) constexpr bool operator!=(Angle left, Angle right)
{ {
return left.asDegrees() != right.asDegrees(); return left.asDegrees() != right.asDegrees();
} }
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
constexpr bool operator <(Angle left, Angle right) constexpr bool operator<(Angle left, Angle right)
{ {
return left.asDegrees() < right.asDegrees(); return left.asDegrees() < right.asDegrees();
} }
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
constexpr bool operator >(Angle left, Angle right) constexpr bool operator>(Angle left, Angle right)
{ {
return left.asDegrees() > right.asDegrees(); return left.asDegrees() > right.asDegrees();
} }
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
constexpr bool operator <=(Angle left, Angle right) constexpr bool operator<=(Angle left, Angle right)
{ {
return left.asDegrees() <= right.asDegrees(); return left.asDegrees() <= right.asDegrees();
} }
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
constexpr bool operator >=(Angle left, Angle right) constexpr bool operator>=(Angle left, Angle right)
{ {
return left.asDegrees() >= right.asDegrees(); return left.asDegrees() >= right.asDegrees();
} }
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
constexpr Angle operator -(Angle right) constexpr Angle operator-(Angle right)
{ {
return degrees(-right.asDegrees()); return degrees(-right.asDegrees());
} }
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
constexpr Angle operator +(Angle left, Angle right) constexpr Angle operator+(Angle left, Angle right)
{ {
return degrees(left.asDegrees() + right.asDegrees()); return degrees(left.asDegrees() + right.asDegrees());
} }
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
constexpr Angle& operator +=(Angle& left, Angle right) constexpr Angle& operator+=(Angle& left, Angle right)
{ {
return left = left + right; return left = left + right;
} }
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
constexpr Angle operator -(Angle left, Angle right) constexpr Angle operator-(Angle left, Angle right)
{ {
return degrees(left.asDegrees() - right.asDegrees()); return degrees(left.asDegrees() - right.asDegrees());
} }
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
constexpr Angle& operator -=(Angle& left, Angle right) constexpr Angle& operator-=(Angle& left, Angle right)
{ {
return left = left - right; return left = left - right;
} }
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
constexpr Angle operator *(Angle left, float right) constexpr Angle operator*(Angle left, float right)
{ {
return degrees(left.asDegrees() * right); return degrees(left.asDegrees() * right);
} }
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
constexpr Angle operator *(float left, Angle right) constexpr Angle operator*(float left, Angle right)
{ {
return right * left; return right * left;
} }
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
constexpr Angle& operator *=(Angle& left, float right) constexpr Angle& operator*=(Angle& left, float right)
{ {
return left = left * right; return left = left * right;
} }
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
constexpr Angle operator /(Angle left, float right) constexpr Angle operator/(Angle left, float right)
{ {
return degrees(left.asDegrees() / right); return degrees(left.asDegrees() / right);
} }
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
constexpr Angle& operator /=(Angle& left, float right) constexpr Angle& operator/=(Angle& left, float right)
{ {
return left = left / right; return left = left / right;
} }
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
constexpr float operator /(Angle left, Angle right) constexpr float operator/(Angle left, Angle right)
{ {
return left.asDegrees() / right.asDegrees(); return left.asDegrees() / right.asDegrees();
} }
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
constexpr Angle operator %(Angle left, Angle right) constexpr Angle operator%(Angle left, Angle right)
{ {
return degrees(priv::positiveRemainder(left.asDegrees(), right.asDegrees())); return degrees(priv::positiveRemainder(left.asDegrees(), right.asDegrees()));
} }
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
constexpr Angle& operator %=(Angle& left, Angle right) constexpr Angle& operator%=(Angle& left, Angle right)
{ {
return left = left % right; return left = left % right;
} }
@ -230,28 +228,28 @@ namespace Literals
{ {
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
constexpr Angle operator "" _deg(long double angle) constexpr Angle operator"" _deg(long double angle)
{ {
return degrees(static_cast<float>(angle)); return degrees(static_cast<float>(angle));
} }
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
constexpr Angle operator "" _deg(unsigned long long angle) constexpr Angle operator"" _deg(unsigned long long angle)
{ {
return degrees(static_cast<float>(angle)); return degrees(static_cast<float>(angle));
} }
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
constexpr Angle operator "" _rad(long double angle) constexpr Angle operator"" _rad(long double angle)
{ {
return radians(static_cast<float>(angle)); return radians(static_cast<float>(angle));
} }
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
constexpr Angle operator "" _rad(unsigned long long angle) constexpr Angle operator"" _rad(unsigned long long angle)
{ {
return radians(static_cast<float>(angle)); return radians(static_cast<float>(angle));
} }

View File

@ -29,6 +29,7 @@
// Headers // Headers
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
#include <SFML/System/Export.hpp> #include <SFML/System/Export.hpp>
#include <chrono> #include <chrono>
#include <ratio> #include <ratio>
#include <type_traits> #include <type_traits>
@ -69,12 +70,11 @@ namespace priv
/// ///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
#if defined(SFML_SYSTEM_ANDROID) && defined(SFML_ANDROID_USE_SUSPEND_AWARE_CLOCK) #if defined(SFML_SYSTEM_ANDROID) && defined(SFML_ANDROID_USE_SUSPEND_AWARE_CLOCK)
using MostSuitableClock = SuspendAwareClock; using MostSuitableClock = SuspendAwareClock;
#else #else
using MostSuitableClock = std::conditional_t< using MostSuitableClock = std::conditional_t<std::chrono::high_resolution_clock::is_steady,
std::chrono::high_resolution_clock::is_steady, std::chrono::high_resolution_clock,
std::chrono::high_resolution_clock, std::chrono::steady_clock>;
std::chrono::steady_clock>;
#endif #endif
} // namespace priv } // namespace priv
@ -88,7 +88,6 @@ class Time;
class SFML_SYSTEM_API Clock class SFML_SYSTEM_API Clock
{ {
public: public:
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \brief Default constructor /// \brief Default constructor
/// ///
@ -123,10 +122,9 @@ public:
private: private:
using ClockImpl = priv::MostSuitableClock; using ClockImpl = priv::MostSuitableClock;
static_assert(ClockImpl::is_steady, static_assert(ClockImpl::is_steady, "Provided implementation is not a monotonic clock");
"Provided implementation is not a monotonic clock");
static_assert(std::ratio_less_equal<ClockImpl::period, std::micro>::value, static_assert(std::ratio_less_equal<ClockImpl::period, std::micro>::value,
"Clock resolution is too low. Expecting at least a microsecond precision"); "Clock resolution is too low. Expecting at least a microsecond precision");
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \brief Convert clock duration to Time /// \brief Convert clock duration to Time

View File

@ -29,6 +29,7 @@
// Headers // Headers
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
#include <SFML/System/Export.hpp> #include <SFML/System/Export.hpp>
#include <iosfwd> #include <iosfwd>

View File

@ -36,11 +36,11 @@
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
#if defined(SFML_SYSTEM_EXPORTS) #if defined(SFML_SYSTEM_EXPORTS)
#define SFML_SYSTEM_API SFML_API_EXPORT #define SFML_SYSTEM_API SFML_API_EXPORT
#else #else
#define SFML_SYSTEM_API SFML_API_IMPORT #define SFML_SYSTEM_API SFML_API_IMPORT
#endif #endif

View File

@ -29,12 +29,15 @@
// Headers // Headers
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
#include <SFML/Config.hpp> #include <SFML/Config.hpp>
#include <SFML/System/Export.hpp> #include <SFML/System/Export.hpp>
#include <SFML/System/InputStream.hpp> #include <SFML/System/InputStream.hpp>
#include <memory>
#include <string>
#include <cstdio> #include <cstdio>
#include <filesystem> #include <filesystem>
#include <memory>
#include <string>
#ifdef SFML_SYSTEM_ANDROID #ifdef SFML_SYSTEM_ANDROID
namespace sf::priv namespace sf::priv
@ -140,7 +143,6 @@ public:
Int64 getSize() override; Int64 getSize() override;
private: private:
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
// Member data // Member data
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////

View File

@ -29,6 +29,7 @@
// Headers // Headers
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
#include <SFML/Config.hpp> #include <SFML/Config.hpp>
#include <SFML/System/Export.hpp> #include <SFML/System/Export.hpp>
@ -41,12 +42,13 @@ namespace sf
class SFML_SYSTEM_API InputStream class SFML_SYSTEM_API InputStream
{ {
public: public:
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \brief Virtual destructor /// \brief Virtual destructor
/// ///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
virtual ~InputStream() {} virtual ~InputStream()
{
}
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \brief Read data from the stream /// \brief Read data from the stream

View File

@ -29,8 +29,11 @@
// Headers // Headers
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
#include <SFML/Config.hpp> #include <SFML/Config.hpp>
#include <SFML/System/InputStream.hpp>
#include <SFML/System/Export.hpp> #include <SFML/System/Export.hpp>
#include <SFML/System/InputStream.hpp>
#include <cstdlib> #include <cstdlib>
@ -43,7 +46,6 @@ namespace sf
class SFML_SYSTEM_API MemoryInputStream : public InputStream class SFML_SYSTEM_API MemoryInputStream : public InputStream
{ {
public: public:
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \brief Default constructor /// \brief Default constructor
/// ///
@ -100,7 +102,6 @@ public:
Int64 getSize() override; Int64 getSize() override;
private: private:
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
// Member data // Member data
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////

Some files were not shown because too many files have changed in this diff Show More