mirror of
https://github.com/SFML/SFML.git
synced 2024-12-01 15:51:04 +08:00
FS#150 - SFML should use its own stream instead of std::cerr, for reporting errors
git-svn-id: https://sfml.svn.sourceforge.net/svnroot/sfml/branches/sfml2@1417 4e206d99-4929-0410-ac5d-dfc041789085
This commit is contained in:
parent
796406a15b
commit
76de05af61
@ -379,6 +379,14 @@
|
||||
RelativePath="..\..\include\SFML\System\Clock.hpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\src\SFML\System\Err.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\include\SFML\System\Err.hpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\src\SFML\System\Lock.cpp"
|
||||
>
|
||||
|
@ -31,6 +31,7 @@
|
||||
|
||||
#include <SFML/Config.hpp>
|
||||
#include <SFML/System/Clock.hpp>
|
||||
#include <SFML/System/Err.hpp>
|
||||
#include <SFML/System/Lock.hpp>
|
||||
#include <SFML/System/Mutex.hpp>
|
||||
#include <SFML/System/Randomizer.hpp>
|
||||
|
77
include/SFML/System/Err.hpp
Normal file
77
include/SFML/System/Err.hpp
Normal file
@ -0,0 +1,77 @@
|
||||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// SFML - Simple and Fast Multimedia Library
|
||||
// Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)
|
||||
//
|
||||
// This software is provided 'as-is', without any express or implied warranty.
|
||||
// In no event will the authors be held liable for any damages arising from the use of this software.
|
||||
//
|
||||
// Permission is granted to anyone to use this software for any purpose,
|
||||
// including commercial applications, and to alter it and redistribute it freely,
|
||||
// subject to the following restrictions:
|
||||
//
|
||||
// 1. The origin of this software must not be misrepresented;
|
||||
// you must not claim that you wrote the original software.
|
||||
// If you use this software in a product, an acknowledgment
|
||||
// in the product documentation would be appreciated but is not required.
|
||||
//
|
||||
// 2. Altered source versions must be plainly marked as such,
|
||||
// and must not be misrepresented as being the original software.
|
||||
//
|
||||
// 3. This notice may not be removed or altered from any source distribution.
|
||||
//
|
||||
////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef SFML_ERR_HPP
|
||||
#define SFML_ERR_HPP
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// Headers
|
||||
////////////////////////////////////////////////////////////
|
||||
#include <SFML/Config.hpp>
|
||||
#include <ostream>
|
||||
|
||||
|
||||
namespace sf
|
||||
{
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Standard stream used by SFML to output warnings and errors
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
SFML_API std::ostream& Err();
|
||||
|
||||
} // namespace sf
|
||||
|
||||
|
||||
#endif // SFML_ERR_HPP
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \fn sf::Err
|
||||
///
|
||||
/// By default, sf::Err() outputs to the same location as std::cerr,
|
||||
/// (-> the stderr descriptor) which is the console if there's
|
||||
/// one available.
|
||||
///
|
||||
/// It is a standard std::ostream instance, so it supports all the
|
||||
/// insertion operations defined by the STL
|
||||
/// (operator <<, manipulators, etc.).
|
||||
///
|
||||
/// sf::Err() can be redirected to write to another output, independantly
|
||||
/// of std::cerr, by using the rdbuf() function provided by the
|
||||
/// std::ostream class.
|
||||
///
|
||||
/// Example:
|
||||
/// \code
|
||||
/// // Redirect to a file
|
||||
/// std::ofstream file("sfml-log.txt");
|
||||
/// std::streambuf* previous = sf::Err().rdbuf(file.rdbuf());
|
||||
///
|
||||
/// // Redirect to nothing
|
||||
/// sf::Err().rdbuf(NULL);
|
||||
///
|
||||
/// // Restore the original output
|
||||
/// sf::Err().rdbuf(previous);
|
||||
/// \endcode
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
@ -27,6 +27,7 @@
|
||||
////////////////////////////////////////////////////////////
|
||||
#include <SFML/Audio/ALCheck.hpp>
|
||||
#include <SFML/Audio/AudioDevice.hpp>
|
||||
#include <SFML/System/Err.hpp>
|
||||
|
||||
|
||||
namespace sf
|
||||
@ -83,10 +84,10 @@ void ALCheckError(const std::string& file, unsigned int line)
|
||||
}
|
||||
|
||||
// Log the error
|
||||
std::cerr << "An internal OpenAL call failed in "
|
||||
<< file.substr(file.find_last_of("\\/") + 1) << " (" << line << ") : "
|
||||
<< error << ", " << description
|
||||
<< std::endl;
|
||||
Err() << "An internal OpenAL call failed in "
|
||||
<< file.substr(file.find_last_of("\\/") + 1) << " (" << line << ") : "
|
||||
<< error << ", " << description
|
||||
<< std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -28,7 +28,7 @@
|
||||
#include <SFML/Audio/AudioDevice.hpp>
|
||||
#include <SFML/Audio/ALCheck.hpp>
|
||||
#include <SFML/Audio/Listener.hpp>
|
||||
#include <iostream>
|
||||
#include <SFML/System/Err.hpp>
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
@ -62,12 +62,12 @@ AudioDevice::AudioDevice()
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cerr << "Failed to create the audio context" << std::endl;
|
||||
Err() << "Failed to create the audio context" << std::endl;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cerr << "Failed to open the audio device" << std::endl;
|
||||
Err() << "Failed to open the audio device" << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -29,8 +29,8 @@
|
||||
#include <SFML/Audio/ALCheck.hpp>
|
||||
#include <SFML/Audio/SoundFile.hpp>
|
||||
#include <SFML/System/Lock.hpp>
|
||||
#include <SFML/System/Err.hpp>
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
|
||||
|
||||
namespace sf
|
||||
@ -63,7 +63,7 @@ bool Music::OpenFromFile(const std::string& filename)
|
||||
// Create the sound file implementation, and open it in read mode
|
||||
if (!myFile->OpenRead(filename))
|
||||
{
|
||||
std::cerr << "Failed to open \"" << filename << "\" for reading" << std::endl;
|
||||
Err() << "Failed to open \"" << filename << "\" for reading" << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -89,7 +89,7 @@ bool Music::OpenFromMemory(const void* data, std::size_t sizeInBytes)
|
||||
// Create the sound file implementation, and open it in read mode
|
||||
if (!myFile->OpenRead(data, sizeInBytes))
|
||||
{
|
||||
std::cerr << "Failed to open music from memory for reading" << std::endl;
|
||||
Err() << "Failed to open music from memory for reading" << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -30,7 +30,7 @@
|
||||
#include <SFML/Audio/Sound.hpp>
|
||||
#include <SFML/Audio/AudioDevice.hpp>
|
||||
#include <SFML/Audio/ALCheck.hpp>
|
||||
#include <iostream>
|
||||
#include <SFML/System/Err.hpp>
|
||||
#include <memory>
|
||||
|
||||
|
||||
@ -152,12 +152,12 @@ bool SoundBuffer::LoadFromSamples(const Int16* samples, std::size_t samplesCount
|
||||
else
|
||||
{
|
||||
// Error...
|
||||
std::cerr << "Failed to load sound buffer from memory ("
|
||||
<< "Samples : " << samples << ", "
|
||||
<< "Samples count : " << samplesCount << ", "
|
||||
<< "Channels count : " << channelsCount << ", "
|
||||
<< "Sample rate : " << sampleRate << ")"
|
||||
<< std::endl;
|
||||
Err() << "Failed to load sound buffer from memory ("
|
||||
<< "Samples : " << samples << ", "
|
||||
<< "Samples count : " << samplesCount << ", "
|
||||
<< "Channels count : " << channelsCount << ", "
|
||||
<< "Sample rate : " << sampleRate << ")"
|
||||
<< std::endl;
|
||||
|
||||
return false;
|
||||
}
|
||||
@ -251,7 +251,7 @@ bool SoundBuffer::Update(unsigned int channelsCount, unsigned int sampleRate)
|
||||
// Check if the format is valid
|
||||
if (format == 0)
|
||||
{
|
||||
std::cerr << "Unsupported number of channels (" << channelsCount << ")" << std::endl;
|
||||
Err() << "Unsupported number of channels (" << channelsCount << ")" << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -26,7 +26,7 @@
|
||||
// Headers
|
||||
////////////////////////////////////////////////////////////
|
||||
#include <SFML/Audio/SoundFile.hpp>
|
||||
#include <iostream>
|
||||
#include <SFML/System/Err.hpp>
|
||||
#include <string.h>
|
||||
|
||||
|
||||
@ -86,7 +86,7 @@ bool SoundFile::OpenRead(const std::string& filename)
|
||||
myFile = sf_open(filename.c_str(), SFM_READ, &fileInfos);
|
||||
if (!myFile)
|
||||
{
|
||||
std::cerr << "Failed to read sound file \"" << filename << "\" (" << sf_strerror(myFile) << ")" << std::endl;
|
||||
Err() << "Failed to read sound file \"" << filename << "\" (" << sf_strerror(myFile) << ")" << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -114,7 +114,7 @@ bool SoundFile::OpenRead(const void* data, std::size_t sizeInBytes)
|
||||
myFile = sf_open_virtual(&io, SFM_READ, &fileInfos, &myMemoryIO);
|
||||
if (!myFile)
|
||||
{
|
||||
std::cerr << "Failed to read sound file from memory (" << sf_strerror(myFile) << ")" << std::endl;
|
||||
Err() << "Failed to read sound file from memory (" << sf_strerror(myFile) << ")" << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -139,7 +139,7 @@ bool SoundFile::OpenWrite(const std::string& filename, unsigned int channelsCoun
|
||||
if (format == -1)
|
||||
{
|
||||
// Error : unrecognized extension
|
||||
std::cerr << "Failed to create sound file \"" << filename << "\" (unknown format)" << std::endl;
|
||||
Err() << "Failed to create sound file \"" << filename << "\" (unknown format)" << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -153,7 +153,7 @@ bool SoundFile::OpenWrite(const std::string& filename, unsigned int channelsCoun
|
||||
myFile = sf_open(filename.c_str(), SFM_WRITE, &fileInfos);
|
||||
if (!myFile)
|
||||
{
|
||||
std::cerr << "Failed to create sound file \"" << filename << "\" (" << sf_strerror(myFile) << ")" << std::endl;
|
||||
Err() << "Failed to create sound file \"" << filename << "\" (" << sf_strerror(myFile) << ")" << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -29,7 +29,7 @@
|
||||
#include <SFML/Audio/AudioDevice.hpp>
|
||||
#include <SFML/Audio/ALCheck.hpp>
|
||||
#include <SFML/System/Sleep.hpp>
|
||||
#include <iostream>
|
||||
#include <SFML/System/Err.hpp>
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
@ -64,14 +64,14 @@ void SoundRecorder::Start(unsigned int sampleRate)
|
||||
// Check if the device can do audio capture
|
||||
if (!IsAvailable())
|
||||
{
|
||||
std::cerr << "Failed to start capture : your system cannot capture audio data (call SoundRecorder::CanCapture to check it)" << std::endl;
|
||||
Err() << "Failed to start capture : your system cannot capture audio data (call SoundRecorder::CanCapture to check it)" << std::endl;
|
||||
return;
|
||||
}
|
||||
|
||||
// Check that another capture is not already running
|
||||
if (captureDevice)
|
||||
{
|
||||
std::cerr << "Trying to start audio capture, but another capture is already running" << std::endl;
|
||||
Err() << "Trying to start audio capture, but another capture is already running" << std::endl;
|
||||
return;
|
||||
}
|
||||
|
||||
@ -79,7 +79,7 @@ void SoundRecorder::Start(unsigned int sampleRate)
|
||||
captureDevice = alcCaptureOpenDevice(NULL, sampleRate, AL_FORMAT_MONO16, sampleRate);
|
||||
if (!captureDevice)
|
||||
{
|
||||
std::cerr << "Failed to open the audio capture device" << std::endl;
|
||||
Err() << "Failed to open the audio capture device" << std::endl;
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -29,6 +29,7 @@
|
||||
#include <SFML/Audio/AudioDevice.hpp>
|
||||
#include <SFML/Audio/ALCheck.hpp>
|
||||
#include <SFML/System/Sleep.hpp>
|
||||
#include <SFML/System/Err.hpp>
|
||||
|
||||
|
||||
namespace sf
|
||||
@ -68,7 +69,7 @@ void SoundStream::Initialize(unsigned int channelsCount, unsigned int sampleRate
|
||||
{
|
||||
myChannelsCount = 0;
|
||||
mySampleRate = 0;
|
||||
std::cerr << "Unsupported number of channels (" << myChannelsCount << ")" << std::endl;
|
||||
Err() << "Unsupported number of channels (" << myChannelsCount << ")" << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
@ -79,7 +80,7 @@ void SoundStream::Play()
|
||||
// Check if the sound parameters have been set
|
||||
if (myFormat == 0)
|
||||
{
|
||||
std::cerr << "Failed to play audio stream: sound parameters have not been initialized (call Initialize first)" << std::endl;
|
||||
Err() << "Failed to play audio stream: sound parameters have not been initialized (call Initialize first)" << std::endl;
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -26,12 +26,12 @@
|
||||
// Headers
|
||||
////////////////////////////////////////////////////////////
|
||||
#include <SFML/Graphics/Font.hpp>
|
||||
#include <SFML/System/Err.hpp>
|
||||
#include <ft2build.h>
|
||||
#include FT_FREETYPE_H
|
||||
#include FT_GLYPH_H
|
||||
#include FT_OUTLINE_H
|
||||
#include FT_BITMAP_H
|
||||
#include <iostream>
|
||||
|
||||
|
||||
namespace sf
|
||||
@ -84,7 +84,7 @@ bool Font::LoadFromFile(const std::string& filename)
|
||||
FT_Library library;
|
||||
if (FT_Init_FreeType(&library) != 0)
|
||||
{
|
||||
std::cerr << "Failed to load font \"" << filename << "\" (failed to initialize FreeType)" << std::endl;
|
||||
Err() << "Failed to load font \"" << filename << "\" (failed to initialize FreeType)" << std::endl;
|
||||
return false;
|
||||
}
|
||||
myLibrary = library;
|
||||
@ -93,14 +93,14 @@ bool Font::LoadFromFile(const std::string& filename)
|
||||
FT_Face face;
|
||||
if (FT_New_Face(static_cast<FT_Library>(myLibrary), filename.c_str(), 0, &face) != 0)
|
||||
{
|
||||
std::cerr << "Failed to load font \"" << filename << "\" (failed to create the font face)" << std::endl;
|
||||
Err() << "Failed to load font \"" << filename << "\" (failed to create the font face)" << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
// Select the unicode character map
|
||||
if (FT_Select_Charmap(face, FT_ENCODING_UNICODE) != 0)
|
||||
{
|
||||
std::cerr << "Failed to load font \"" << filename << "\" (failed to set the Unicode character set)" << std::endl;
|
||||
Err() << "Failed to load font \"" << filename << "\" (failed to set the Unicode character set)" << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -124,7 +124,7 @@ bool Font::LoadFromMemory(const void* data, std::size_t sizeInBytes)
|
||||
FT_Library library;
|
||||
if (FT_Init_FreeType(&library) != 0)
|
||||
{
|
||||
std::cerr << "Failed to load font from memory (failed to initialize FreeType)" << std::endl;
|
||||
Err() << "Failed to load font from memory (failed to initialize FreeType)" << std::endl;
|
||||
return false;
|
||||
}
|
||||
myLibrary = library;
|
||||
@ -133,14 +133,14 @@ bool Font::LoadFromMemory(const void* data, std::size_t sizeInBytes)
|
||||
FT_Face face;
|
||||
if (FT_New_Memory_Face(static_cast<FT_Library>(myLibrary), reinterpret_cast<const FT_Byte*>(data), static_cast<FT_Long>(sizeInBytes), 0, &face) != 0)
|
||||
{
|
||||
std::cerr << "Failed to load font from memory (failed to create the font face)" << std::endl;
|
||||
Err() << "Failed to load font from memory (failed to create the font face)" << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
// Select the unicode character map
|
||||
if (FT_Select_Charmap(face, FT_ENCODING_UNICODE) != 0)
|
||||
{
|
||||
std::cerr << "Failed to load font from memory (failed to set the Unicode character set)" << std::endl;
|
||||
Err() << "Failed to load font from memory (failed to set the Unicode character set)" << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -460,7 +460,7 @@ IntRect Font::FindGlyphRect(Page& page, unsigned int width, unsigned int height)
|
||||
else
|
||||
{
|
||||
// Oops, we've reached the maximum texture size...
|
||||
std::cerr << "Failed to add a new character to the font: the maximum image size has been reached" << std::endl;
|
||||
Err() << "Failed to add a new character to the font: the maximum image size has been reached" << std::endl;
|
||||
return IntRect(0, 0, 2, 2);
|
||||
}
|
||||
}
|
||||
|
@ -26,7 +26,7 @@
|
||||
// Headers
|
||||
////////////////////////////////////////////////////////////
|
||||
#include <SFML/Graphics/GLCheck.hpp>
|
||||
#include <iostream>
|
||||
#include <SFML/System/Err.hpp>
|
||||
|
||||
|
||||
namespace sf
|
||||
@ -100,10 +100,10 @@ void GLCheckError(const std::string& file, unsigned int line)
|
||||
}
|
||||
|
||||
// Log the error
|
||||
std::cerr << "An internal OpenGL call failed in "
|
||||
<< file.substr(file.find_last_of("\\/") + 1) << " (" << line << ") : "
|
||||
<< error << ", " << description
|
||||
<< std::endl;
|
||||
Err() << "An internal OpenGL call failed in "
|
||||
<< file.substr(file.find_last_of("\\/") + 1) << " (" << line << ") : "
|
||||
<< error << ", " << description
|
||||
<< std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -30,8 +30,8 @@
|
||||
#include <SFML/Graphics/RenderImage.hpp>
|
||||
#include <SFML/Graphics/RenderWindow.hpp>
|
||||
#include <SFML/Graphics/GLCheck.hpp>
|
||||
#include <SFML/System/Err.hpp>
|
||||
#include <algorithm>
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
#include <string.h>
|
||||
|
||||
@ -121,7 +121,7 @@ bool Image::LoadFromMemory(const void* data, std::size_t sizeInBytes)
|
||||
// Check parameters
|
||||
if (!data || (sizeInBytes == 0))
|
||||
{
|
||||
std::cerr << "Failed to image font from memory, no data provided" << std::endl;
|
||||
Err() << "Failed to image font from memory, no data provided" << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -389,8 +389,8 @@ void Image::SetPixel(unsigned int x, unsigned int y, const Color& color)
|
||||
// Check if pixel is whithin the image bounds
|
||||
if ((x >= myWidth) || (y >= myHeight))
|
||||
{
|
||||
std::cerr << "Cannot set pixel (" << x << "," << y << ") for image "
|
||||
<< "(width = " << myWidth << ", height = " << myHeight << ")" << std::endl;
|
||||
Err() << "Cannot set pixel (" << x << "," << y << ") for image "
|
||||
<< "(width = " << myWidth << ", height = " << myHeight << ")" << std::endl;
|
||||
return;
|
||||
}
|
||||
|
||||
@ -412,8 +412,8 @@ const Color& Image::GetPixel(unsigned int x, unsigned int y) const
|
||||
// Check if pixel is whithin the image bounds
|
||||
if ((x >= myWidth) || (y >= myHeight))
|
||||
{
|
||||
std::cerr << "Cannot get pixel (" << x << "," << y << ") for image "
|
||||
<< "(width = " << myWidth << ", height = " << myHeight << ")" << std::endl;
|
||||
Err() << "Cannot get pixel (" << x << "," << y << ") for image "
|
||||
<< "(width = " << myWidth << ", height = " << myHeight << ")" << std::endl;
|
||||
return Color::Black;
|
||||
}
|
||||
|
||||
@ -437,7 +437,7 @@ const Uint8* Image::GetPixelsPtr() const
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cerr << "Trying to access the pixels of an empty image" << std::endl;
|
||||
Err() << "Trying to access the pixels of an empty image" << std::endl;
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
@ -661,10 +661,10 @@ bool Image::CreateTexture()
|
||||
unsigned int maxSize = GetMaximumSize();
|
||||
if ((myTextureWidth > maxSize) || (myTextureHeight > maxSize))
|
||||
{
|
||||
std::cerr << "Failed to create image, its internal size is too high "
|
||||
<< "(" << myTextureWidth << "x" << myTextureHeight << ", "
|
||||
<< "maximum is " << maxSize << "x" << maxSize << ")"
|
||||
<< std::endl;
|
||||
Err() << "Failed to create image, its internal size is too high "
|
||||
<< "(" << myTextureWidth << "x" << myTextureHeight << ", "
|
||||
<< "maximum is " << maxSize << "x" << maxSize << ")"
|
||||
<< std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -33,7 +33,7 @@ extern "C"
|
||||
}
|
||||
#include <SFML/Graphics/libpng/png.h>
|
||||
#include <SFML/Graphics/SOIL/SOIL.h>
|
||||
#include <iostream>
|
||||
#include <SFML/System/Err.hpp>
|
||||
|
||||
|
||||
namespace
|
||||
@ -43,7 +43,7 @@ namespace
|
||||
////////////////////////////////////////////////////////////
|
||||
void PngErrorHandler(png_structp png, png_const_charp message)
|
||||
{
|
||||
std::cerr << "Failed to write PNG image. Reason : " << message << std::endl;
|
||||
sf::Err() << "Failed to write PNG image. Reason : " << message << std::endl;
|
||||
longjmp(png->jmpbuf, 1);
|
||||
}
|
||||
}
|
||||
@ -112,7 +112,7 @@ bool ImageLoader::LoadImageFromFile(const std::string& filename, std::vector<Col
|
||||
else
|
||||
{
|
||||
// Error, failed to load the image
|
||||
std::cerr << "Failed to load image \"" << filename << "\". Reason : " << SOIL_last_result() << std::endl;
|
||||
Err() << "Failed to load image \"" << filename << "\". Reason : " << SOIL_last_result() << std::endl;
|
||||
|
||||
return false;
|
||||
}
|
||||
@ -151,7 +151,7 @@ bool ImageLoader::LoadImageFromMemory(const void* data, std::size_t sizeInBytes,
|
||||
else
|
||||
{
|
||||
// Error, failed to load the image
|
||||
std::cerr << "Failed to load image from memory. Reason : " << SOIL_last_result() << std::endl;
|
||||
Err() << "Failed to load image from memory. Reason : " << SOIL_last_result() << std::endl;
|
||||
|
||||
return false;
|
||||
}
|
||||
@ -180,7 +180,7 @@ bool ImageLoader::SaveImageToFile(const std::string& filename, const std::vector
|
||||
if (type == -1)
|
||||
{
|
||||
// Error, incompatible type
|
||||
std::cerr << "Failed to save image \"" << filename << "\". Reason: this image format is not supported" << std::endl;
|
||||
Err() << "Failed to save image \"" << filename << "\". Reason: this image format is not supported" << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -189,7 +189,7 @@ bool ImageLoader::SaveImageToFile(const std::string& filename, const std::vector
|
||||
if (!SOIL_save_image(filename.c_str(), type, static_cast<int>(width), static_cast<int>(height), 4, ptr))
|
||||
{
|
||||
// Error, failed to save the image
|
||||
std::cerr << "Failed to save image \"" << filename << "\". Reason: " << SOIL_last_result() << std::endl;
|
||||
Err() << "Failed to save image \"" << filename << "\". Reason: " << SOIL_last_result() << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -206,7 +206,7 @@ bool ImageLoader::WriteJpg(const std::string& filename, const std::vector<Color>
|
||||
FILE* file = fopen(filename.c_str(), "wb");
|
||||
if (!file)
|
||||
{
|
||||
std::cerr << "Failed to save image file \"" << filename << "\". Reason : cannot open file" << std::endl;
|
||||
Err() << "Failed to save image file \"" << filename << "\". Reason : cannot open file" << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -265,7 +265,7 @@ bool ImageLoader::WritePng(const std::string& filename, const std::vector<Color>
|
||||
FILE* file = fopen(filename.c_str(), "wb");
|
||||
if (!file)
|
||||
{
|
||||
std::cerr << "Failed to save image file \"" << filename << "\". Reason : cannot open file" << std::endl;
|
||||
Err() << "Failed to save image file \"" << filename << "\". Reason : cannot open file" << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -274,7 +274,7 @@ bool ImageLoader::WritePng(const std::string& filename, const std::vector<Color>
|
||||
if (!png)
|
||||
{
|
||||
fclose(file);
|
||||
std::cerr << "Failed to save image file \"" << filename << "\". Reason : cannot allocate PNG write structure" << std::endl;
|
||||
Err() << "Failed to save image file \"" << filename << "\". Reason : cannot allocate PNG write structure" << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -284,7 +284,7 @@ bool ImageLoader::WritePng(const std::string& filename, const std::vector<Color>
|
||||
{
|
||||
fclose(file);
|
||||
png_destroy_write_struct(&png, NULL);
|
||||
std::cerr << "Failed to save image file \"" << filename << "\". Reason : cannot allocate PNG info structure" << std::endl;
|
||||
Err() << "Failed to save image file \"" << filename << "\". Reason : cannot allocate PNG info structure" << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -28,7 +28,7 @@
|
||||
#include <SFML/Graphics/Linux/RenderImageImplPBuffer.hpp>
|
||||
#include <SFML/Graphics/GLCheck.hpp>
|
||||
#include <SFML/Window/Context.hpp>
|
||||
#include <iostream>
|
||||
#include <SFML/System/Err.hpp>
|
||||
|
||||
|
||||
namespace sf
|
||||
@ -112,7 +112,7 @@ bool RenderImageImplPBuffer::Create(unsigned int width, unsigned int height, uns
|
||||
GLXFBConfig* configs = glXChooseFBConfigSGIX(myDisplay, DefaultScreen(myDisplay), visualAttributes, &nbConfigs);
|
||||
if (!configs || !nbConfigs)
|
||||
{
|
||||
std::cerr << "Impossible to create render image (failed to find a suitable pixel format for PBuffer)" << std::endl;
|
||||
Err() << "Impossible to create render image (failed to find a suitable pixel format for PBuffer)" << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -120,7 +120,7 @@ bool RenderImageImplPBuffer::Create(unsigned int width, unsigned int height, uns
|
||||
myPBuffer = glXCreateGLXPbufferSGIX(myDisplay, configs[0], width, height, PBufferAttributes);
|
||||
if (!myPBuffer)
|
||||
{
|
||||
std::cerr << "Impossible to create render image (failed to create the OpenGL PBuffer)" << std::endl;
|
||||
Err() << "Impossible to create render image (failed to create the OpenGL PBuffer)" << std::endl;
|
||||
XFree(configs);
|
||||
return false;
|
||||
}
|
||||
@ -131,10 +131,10 @@ bool RenderImageImplPBuffer::Create(unsigned int width, unsigned int height, uns
|
||||
glXQueryGLXPbufferSGIX(myDisplay, myPBuffer, GLX_HEIGHT_SGIX, &actualHeight);
|
||||
if ((actualWidth != width) || (actualHeight != height))
|
||||
{
|
||||
std::cerr << "Impossible to create render image (failed to match the requested size). "
|
||||
<< "Size: " << actualWidth << "x" << actualHeight << " - "
|
||||
<< "Requested: " << width << "x" << height
|
||||
<< std::endl;
|
||||
Err() << "Impossible to create render image (failed to match the requested size). "
|
||||
<< "Size: " << actualWidth << "x" << actualHeight << " - "
|
||||
<< "Requested: " << width << "x" << height
|
||||
<< std::endl;
|
||||
XFree(configs);
|
||||
return false;
|
||||
}
|
||||
@ -150,7 +150,7 @@ bool RenderImageImplPBuffer::Create(unsigned int width, unsigned int height, uns
|
||||
myContext = glXCreateContext(myDisplay, visual, currentContext, true);
|
||||
if (!myContext)
|
||||
{
|
||||
std::cerr << "Impossible to create render image (failed to create the OpenGL context)" << std::endl;
|
||||
Err() << "Impossible to create render image (failed to create the OpenGL context)" << std::endl;
|
||||
XFree(configs);
|
||||
XFree(visual);
|
||||
return false;
|
||||
|
@ -28,7 +28,7 @@
|
||||
#include <SFML/Graphics/RenderImage.hpp>
|
||||
#include <SFML/Graphics/RenderImageImplFBO.hpp>
|
||||
#include <SFML/Graphics/RenderImageImplPBuffer.hpp>
|
||||
#include <iostream>
|
||||
#include <SFML/System/Err.hpp>
|
||||
|
||||
|
||||
namespace sf
|
||||
@ -54,14 +54,14 @@ bool RenderImage::Create(unsigned int width, unsigned int height, bool depthBuff
|
||||
// Make sure that render-images are supported
|
||||
if (!IsAvailable())
|
||||
{
|
||||
std::cerr << "Impossible to create render image (your system doesn't support this feature)" << std::endl;
|
||||
Err() << "Impossible to create render image (your system doesn't support this feature)" << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
// Create the image
|
||||
if (!myImage.Create(width, height))
|
||||
{
|
||||
std::cerr << "Impossible to create render image (failed to create the target image)" << std::endl;
|
||||
Err() << "Impossible to create render image (failed to create the target image)" << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -28,7 +28,7 @@
|
||||
#include <SFML/Graphics/RenderImageImplFBO.hpp>
|
||||
#include <SFML/Graphics/Image.hpp>
|
||||
#include <SFML/Graphics/GLCheck.hpp>
|
||||
#include <iostream>
|
||||
#include <SFML/System/Err.hpp>
|
||||
|
||||
|
||||
namespace sf
|
||||
@ -90,7 +90,7 @@ bool RenderImageImplFBO::Create(unsigned int width, unsigned int height, unsigne
|
||||
myFrameBuffer = static_cast<unsigned int>(frameBuffer);
|
||||
if (!myFrameBuffer)
|
||||
{
|
||||
std::cerr << "Impossible to create render image (failed to create the frame buffer object)" << std::endl;
|
||||
Err() << "Impossible to create render image (failed to create the frame buffer object)" << std::endl;
|
||||
return false;
|
||||
}
|
||||
GLCheck(glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, myFrameBuffer));
|
||||
@ -103,7 +103,7 @@ bool RenderImageImplFBO::Create(unsigned int width, unsigned int height, unsigne
|
||||
myDepthBuffer = static_cast<unsigned int>(depth);
|
||||
if (!myDepthBuffer)
|
||||
{
|
||||
std::cerr << "Impossible to create render image (failed to create the attached depth buffer)" << std::endl;
|
||||
Err() << "Impossible to create render image (failed to create the attached depth buffer)" << std::endl;
|
||||
return false;
|
||||
}
|
||||
GLCheck(glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, myDepthBuffer));
|
||||
@ -118,7 +118,7 @@ bool RenderImageImplFBO::Create(unsigned int width, unsigned int height, unsigne
|
||||
if (glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT) != GL_FRAMEBUFFER_COMPLETE_EXT)
|
||||
{
|
||||
GLCheck(glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0));
|
||||
std::cerr << "Impossible to create render image (failed to link the target image to the frame buffer)" << std::endl;
|
||||
Err() << "Impossible to create render image (failed to link the target image to the frame buffer)" << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -28,8 +28,8 @@
|
||||
////////////////////////////////////////////////////////////
|
||||
#include <SFML/Graphics/Shader.hpp>
|
||||
#include <SFML/Graphics/GLCheck.hpp>
|
||||
#include <SFML/System/Err.hpp>
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
|
||||
|
||||
@ -79,7 +79,7 @@ bool Shader::LoadFromFile(const std::string& filename)
|
||||
std::ifstream file(filename.c_str());
|
||||
if (!file)
|
||||
{
|
||||
std::cerr << "Failed to open shader file \"" << filename << "\"" << std::endl;
|
||||
Err() << "Failed to open shader file \"" << filename << "\"" << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -118,7 +118,7 @@ void Shader::SetParameter(const std::string& name, float x)
|
||||
if (location != -1)
|
||||
GLCheck(glUniform1fARB(location, x));
|
||||
else
|
||||
std::cerr << "Parameter \"" << name << "\" not found in shader" << std::endl;
|
||||
Err() << "Parameter \"" << name << "\" not found in shader" << std::endl;
|
||||
|
||||
// Disable program
|
||||
GLCheck(glUseProgramObjectARB(program));
|
||||
@ -140,7 +140,7 @@ void Shader::SetParameter(const std::string& name, float x, float y)
|
||||
if (location != -1)
|
||||
GLCheck(glUniform2fARB(location, x, y));
|
||||
else
|
||||
std::cerr << "Parameter \"" << name << "\" not found in shader" << std::endl;
|
||||
Err() << "Parameter \"" << name << "\" not found in shader" << std::endl;
|
||||
|
||||
// Disable program
|
||||
GLCheck(glUseProgramObjectARB(program));
|
||||
@ -162,7 +162,7 @@ void Shader::SetParameter(const std::string& name, float x, float y, float z)
|
||||
if (location != -1)
|
||||
GLCheck(glUniform3fARB(location, x, y, z));
|
||||
else
|
||||
std::cerr << "Parameter \"" << name << "\" not found in shader" << std::endl;
|
||||
Err() << "Parameter \"" << name << "\" not found in shader" << std::endl;
|
||||
|
||||
// Disable program
|
||||
GLCheck(glUseProgramObjectARB(program));
|
||||
@ -184,7 +184,7 @@ void Shader::SetParameter(const std::string& name, float x, float y, float z, fl
|
||||
if (location != -1)
|
||||
GLCheck(glUniform4fARB(location, x, y, z, w));
|
||||
else
|
||||
std::cerr << "Parameter \"" << name << "\" not found in shader" << std::endl;
|
||||
Err() << "Parameter \"" << name << "\" not found in shader" << std::endl;
|
||||
|
||||
// Disable program
|
||||
GLCheck(glUseProgramObjectARB(program));
|
||||
@ -214,7 +214,7 @@ void Shader::SetTexture(const std::string& name, const Image& texture)
|
||||
GLCheck(glGetIntegerv(GL_MAX_TEXTURE_COORDS_ARB, &maxUnits));
|
||||
if (myTextures.size() + 1 >= static_cast<std::size_t>(maxUnits))
|
||||
{
|
||||
std::cerr << "Impossible to use texture \"" << name << "\" for shader: all available texture units are used" << std::endl;
|
||||
Err() << "Impossible to use texture \"" << name << "\" for shader: all available texture units are used" << std::endl;
|
||||
return;
|
||||
}
|
||||
|
||||
@ -222,7 +222,7 @@ void Shader::SetTexture(const std::string& name, const Image& texture)
|
||||
int location = glGetUniformLocationARB(myShaderProgram, name.c_str());
|
||||
if (location == -1)
|
||||
{
|
||||
std::cerr << "Texture \"" << name << "\" not found in shader" << std::endl;
|
||||
Err() << "Texture \"" << name << "\" not found in shader" << std::endl;
|
||||
return;
|
||||
}
|
||||
|
||||
@ -321,8 +321,8 @@ bool Shader::CompileProgram()
|
||||
// First make sure that we can use shaders
|
||||
if (!IsAvailable())
|
||||
{
|
||||
std::cerr << "Failed to create a shader: your system doesn't support shaders "
|
||||
<< "(you should test Shader::IsAvailable() before trying to use the Shader class)" << std::endl;
|
||||
Err() << "Failed to create a shader: your system doesn't support shaders "
|
||||
<< "(you should test Shader::IsAvailable() before trying to use the Shader class)" << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -360,8 +360,8 @@ bool Shader::CompileProgram()
|
||||
{
|
||||
char log[1024];
|
||||
GLCheck(glGetInfoLogARB(vertexShader, sizeof(log), 0, log));
|
||||
std::cerr << "Failed to compile shader:" << std::endl
|
||||
<< log << std::endl;
|
||||
Err() << "Failed to compile shader:" << std::endl
|
||||
<< log << std::endl;
|
||||
GLCheck(glDeleteObjectARB(vertexShader));
|
||||
GLCheck(glDeleteObjectARB(fragmentShader));
|
||||
GLCheck(glDeleteObjectARB(myShaderProgram));
|
||||
@ -373,8 +373,8 @@ bool Shader::CompileProgram()
|
||||
{
|
||||
char log[1024];
|
||||
GLCheck(glGetInfoLogARB(fragmentShader, sizeof(log), 0, log));
|
||||
std::cerr << "Failed to compile shader:" << std::endl
|
||||
<< log << std::endl;
|
||||
Err() << "Failed to compile shader:" << std::endl
|
||||
<< log << std::endl;
|
||||
GLCheck(glDeleteObjectARB(vertexShader));
|
||||
GLCheck(glDeleteObjectARB(fragmentShader));
|
||||
GLCheck(glDeleteObjectARB(myShaderProgram));
|
||||
@ -400,8 +400,8 @@ bool Shader::CompileProgram()
|
||||
// Oops... link errors
|
||||
char log[1024];
|
||||
GLCheck(glGetInfoLogARB(myShaderProgram, sizeof(log), 0, log));
|
||||
std::cerr << "Failed to link shader:" << std::endl
|
||||
<< log << std::endl;
|
||||
Err() << "Failed to link shader:" << std::endl
|
||||
<< log << std::endl;
|
||||
GLCheck(glDeleteObjectARB(myShaderProgram));
|
||||
myShaderProgram = 0;
|
||||
return false;
|
||||
|
@ -28,7 +28,7 @@
|
||||
#include <SFML/Graphics/Win32/RenderImageImplPBuffer.hpp>
|
||||
#include <SFML/Graphics/GLCheck.hpp>
|
||||
#include <SFML/Window/Context.hpp>
|
||||
#include <iostream>
|
||||
#include <SFML/System/Err.hpp>
|
||||
|
||||
|
||||
namespace sf
|
||||
@ -117,7 +117,7 @@ bool RenderImageImplPBuffer::Create(unsigned int width, unsigned int height, uns
|
||||
// Make sure that one pixel format has been found
|
||||
if (nbFormats == 0)
|
||||
{
|
||||
std::cerr << "Impossible to create render image (failed to find a suitable pixel format for PBuffer)" << std::endl;
|
||||
Err() << "Impossible to create render image (failed to find a suitable pixel format for PBuffer)" << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -129,7 +129,7 @@ bool RenderImageImplPBuffer::Create(unsigned int width, unsigned int height, uns
|
||||
// Check errors
|
||||
if (!myPBuffer || !myDeviceContext || !myContext)
|
||||
{
|
||||
std::cerr << "Impossible to create render image (failed to create PBuffer)" << std::endl;
|
||||
Err() << "Impossible to create render image (failed to create PBuffer)" << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -139,10 +139,10 @@ bool RenderImageImplPBuffer::Create(unsigned int width, unsigned int height, uns
|
||||
wglQueryPbufferARB(myPBuffer, WGL_PBUFFER_HEIGHT_ARB, &actualHeight);
|
||||
if ((actualWidth != static_cast<int>(width)) || (actualHeight != static_cast<int>(height)))
|
||||
{
|
||||
std::cerr << "Impossible to create render image (failed to match the requested size). "
|
||||
<< "Size: " << actualWidth << "x" << actualHeight << " - "
|
||||
<< "Requested: " << width << "x" << height
|
||||
<< std::endl;
|
||||
Err() << "Impossible to create render image (failed to match the requested size). "
|
||||
<< "Size: " << actualWidth << "x" << actualHeight << " - "
|
||||
<< "Requested: " << width << "x" << height
|
||||
<< std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -29,8 +29,8 @@
|
||||
#include <SFML/Network/IPAddress.hpp>
|
||||
#include <SFML/Network/Packet.hpp>
|
||||
#include <SFML/Network/SocketHelper.hpp>
|
||||
#include <SFML/System/Err.hpp>
|
||||
#include <algorithm>
|
||||
#include <iostream>
|
||||
#include <string.h>
|
||||
|
||||
|
||||
@ -183,7 +183,7 @@ bool SocketTCP::Listen(unsigned short port)
|
||||
if (bind(mySocket, reinterpret_cast<sockaddr*>(&sockAddr), sizeof(sockAddr)) == -1)
|
||||
{
|
||||
// Not likely to happen, but...
|
||||
std::cerr << "Failed to bind socket to port " << port << std::endl;
|
||||
Err() << "Failed to bind socket to port " << port << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -191,7 +191,7 @@ bool SocketTCP::Listen(unsigned short port)
|
||||
if (listen(mySocket, 0) == -1)
|
||||
{
|
||||
// Oops, socket is deaf
|
||||
std::cerr << "Failed to listen to port " << port << std::endl;
|
||||
Err() << "Failed to listen to port " << port << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -259,7 +259,7 @@ Socket::Status SocketTCP::Send(const char* data, std::size_t sizeInBytes)
|
||||
else
|
||||
{
|
||||
// Error...
|
||||
std::cerr << "Cannot send data over the network (invalid parameters)" << std::endl;
|
||||
Err() << "Cannot send data over the network (invalid parameters)" << std::endl;
|
||||
return Socket::Error;
|
||||
}
|
||||
}
|
||||
@ -302,7 +302,7 @@ Socket::Status SocketTCP::Receive(char* data, std::size_t maxSize, std::size_t&
|
||||
else
|
||||
{
|
||||
// Error...
|
||||
std::cerr << "Cannot receive data from the network (invalid parameters)" << std::endl;
|
||||
Err() << "Cannot receive data from the network (invalid parameters)" << std::endl;
|
||||
return Socket::Error;
|
||||
}
|
||||
}
|
||||
@ -400,7 +400,7 @@ bool SocketTCP::Close()
|
||||
{
|
||||
if (!SocketHelper::Close(mySocket))
|
||||
{
|
||||
std::cerr << "Failed to close socket" << std::endl;
|
||||
Err() << "Failed to close socket" << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -482,15 +482,15 @@ void SocketTCP::Create(SocketHelper::SocketType descriptor)
|
||||
int yes = 1;
|
||||
if (setsockopt(mySocket, SOL_SOCKET, SO_REUSEADDR, reinterpret_cast<char*>(&yes), sizeof(yes)) == -1)
|
||||
{
|
||||
std::cerr << "Failed to set socket option \"SO_REUSEADDR\" ; "
|
||||
<< "binding to a same port may fail if too fast" << std::endl;
|
||||
Err() << "Failed to set socket option \"SO_REUSEADDR\" ; "
|
||||
<< "binding to a same port may fail if too fast" << std::endl;
|
||||
}
|
||||
|
||||
// Disable the Nagle algorithm (ie. removes buffering of TCP packets)
|
||||
if (setsockopt(mySocket, IPPROTO_TCP, TCP_NODELAY, reinterpret_cast<char*>(&yes), sizeof(yes)) == -1)
|
||||
{
|
||||
std::cerr << "Failed to set socket option \"TCP_NODELAY\" ; "
|
||||
<< "all your TCP packets will be buffered" << std::endl;
|
||||
Err() << "Failed to set socket option \"TCP_NODELAY\" ; "
|
||||
<< "all your TCP packets will be buffered" << std::endl;
|
||||
}
|
||||
|
||||
// Set blocking by default (should always be the case anyway)
|
||||
|
@ -28,8 +28,8 @@
|
||||
#include <SFML/Network/SocketUDP.hpp>
|
||||
#include <SFML/Network/IPAddress.hpp>
|
||||
#include <SFML/Network/Packet.hpp>
|
||||
#include <SFML/System/Err.hpp>
|
||||
#include <algorithm>
|
||||
#include <iostream>
|
||||
#include <string.h>
|
||||
|
||||
|
||||
@ -81,7 +81,7 @@ bool SocketUDP::Bind(unsigned short port)
|
||||
// Bind the socket to the port
|
||||
if (bind(mySocket, reinterpret_cast<sockaddr*>(&sockAddr), sizeof(sockAddr)) == -1)
|
||||
{
|
||||
std::cerr << "Failed to bind the socket to port " << port << std::endl;
|
||||
Err() << "Failed to bind the socket to port " << port << std::endl;
|
||||
myPort = 0;
|
||||
return false;
|
||||
}
|
||||
@ -149,7 +149,7 @@ Socket::Status SocketUDP::Send(const char* data, std::size_t sizeInBytes, const
|
||||
else
|
||||
{
|
||||
// Error...
|
||||
std::cerr << "Cannot send data over the network (invalid parameters)" << std::endl;
|
||||
Err() << "Cannot send data over the network (invalid parameters)" << std::endl;
|
||||
return Socket::Error;
|
||||
}
|
||||
}
|
||||
@ -167,7 +167,7 @@ Socket::Status SocketUDP::Receive(char* data, std::size_t maxSize, std::size_t&
|
||||
// Make sure the socket is bound to a port
|
||||
if (myPort == 0)
|
||||
{
|
||||
std::cerr << "Failed to receive data ; the UDP socket first needs to be bound to a port" << std::endl;
|
||||
Err() << "Failed to receive data ; the UDP socket first needs to be bound to a port" << std::endl;
|
||||
return Socket::Error;
|
||||
}
|
||||
|
||||
@ -207,7 +207,7 @@ Socket::Status SocketUDP::Receive(char* data, std::size_t maxSize, std::size_t&
|
||||
else
|
||||
{
|
||||
// Error...
|
||||
std::cerr << "Cannot receive data from the network (invalid parameters)" << std::endl;
|
||||
Err() << "Cannot receive data from the network (invalid parameters)" << std::endl;
|
||||
return Socket::Error;
|
||||
}
|
||||
}
|
||||
@ -313,7 +313,7 @@ bool SocketUDP::Close()
|
||||
{
|
||||
if (!SocketHelper::Close(mySocket))
|
||||
{
|
||||
std::cerr << "Failed to close socket" << std::endl;
|
||||
Err() << "Failed to close socket" << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -408,14 +408,14 @@ void SocketUDP::Create(SocketHelper::SocketType descriptor)
|
||||
int yes = 1;
|
||||
if (setsockopt(mySocket, SOL_SOCKET, SO_REUSEADDR, reinterpret_cast<char*>(&yes), sizeof(yes)) == -1)
|
||||
{
|
||||
std::cerr << "Failed to set socket option \"reuse address\" ; "
|
||||
<< "binding to a same port may fail if too fast" << std::endl;
|
||||
Err() << "Failed to set socket option \"reuse address\" ; "
|
||||
<< "binding to a same port may fail if too fast" << std::endl;
|
||||
}
|
||||
|
||||
// Enable broadcast by default
|
||||
if (setsockopt(mySocket, SOL_SOCKET, SO_BROADCAST, reinterpret_cast<char*>(&yes), sizeof(yes)) == -1)
|
||||
{
|
||||
std::cerr << "Failed to enable broadcast on UDP socket" << std::endl;
|
||||
Err() << "Failed to enable broadcast on UDP socket" << std::endl;
|
||||
}
|
||||
|
||||
// Set blocking by default (should always be the case anyway)
|
||||
|
109
src/SFML/System/Err.cpp
Normal file
109
src/SFML/System/Err.cpp
Normal file
@ -0,0 +1,109 @@
|
||||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// SFML - Simple and Fast Multimedia Library
|
||||
// Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)
|
||||
//
|
||||
// This software is provided 'as-is', without any express or implied warranty.
|
||||
// In no event will the authors be held liable for any damages arising from the use of this software.
|
||||
//
|
||||
// Permission is granted to anyone to use this software for any purpose,
|
||||
// including commercial applications, and to alter it and redistribute it freely,
|
||||
// subject to the following restrictions:
|
||||
//
|
||||
// 1. The origin of this software must not be misrepresented;
|
||||
// you must not claim that you wrote the original software.
|
||||
// If you use this software in a product, an acknowledgment
|
||||
// in the product documentation would be appreciated but is not required.
|
||||
//
|
||||
// 2. Altered source versions must be plainly marked as such,
|
||||
// and must not be misrepresented as being the original software.
|
||||
//
|
||||
// 3. This notice may not be removed or altered from any source distribution.
|
||||
//
|
||||
////////////////////////////////////////////////////////////
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// Headers
|
||||
////////////////////////////////////////////////////////////
|
||||
#include <SFML/System/Err.hpp>
|
||||
#include <streambuf>
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// Private data
|
||||
////////////////////////////////////////////////////////////
|
||||
namespace
|
||||
{
|
||||
// This class will be used as the default streambuf of sf::Err,
|
||||
// it outputs to stderr by default (to keep the default beaviour)
|
||||
class DefaultErrStreamBuf : public std::streambuf
|
||||
{
|
||||
public :
|
||||
|
||||
DefaultErrStreamBuf()
|
||||
{
|
||||
// Allocate the write buffer
|
||||
static const int size = 64;
|
||||
char* buffer = new char[size];
|
||||
setp(buffer, buffer + size);
|
||||
}
|
||||
|
||||
~DefaultErrStreamBuf()
|
||||
{
|
||||
// Synchronize
|
||||
sync();
|
||||
|
||||
// Delete the write buffer
|
||||
delete[] pbase();
|
||||
}
|
||||
|
||||
private :
|
||||
|
||||
virtual int overflow(int character)
|
||||
{
|
||||
if (character != EOF)
|
||||
{
|
||||
// Valid character: add it to the write buffer (sync() will be called if the buffer is full)
|
||||
return sputc(static_cast<char>(character));
|
||||
}
|
||||
else
|
||||
{
|
||||
// Invalid character: just synchronize output
|
||||
return sync();
|
||||
}
|
||||
}
|
||||
|
||||
virtual int sync()
|
||||
{
|
||||
// Check if there is something into the write buffer
|
||||
if (pbase() != pptr())
|
||||
{
|
||||
// Retrieve the contents of the write buffer
|
||||
int size = static_cast<int>(pptr() - pbase());
|
||||
std::string buffer(pbase(), size);
|
||||
|
||||
// Write it into the standard error output
|
||||
fprintf(stderr, "%s", buffer.c_str());
|
||||
|
||||
// Reset the pointer position to the beginning of the write buffer
|
||||
setp(pbase(), epptr());
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
namespace sf
|
||||
{
|
||||
////////////////////////////////////////////////////////////
|
||||
std::ostream& Err()
|
||||
{
|
||||
static DefaultErrStreamBuf buffer;
|
||||
static std::ostream stream(&buffer);
|
||||
|
||||
return stream;
|
||||
}
|
||||
|
||||
|
||||
} // namespace sf
|
@ -27,8 +27,8 @@
|
||||
////////////////////////////////////////////////////////////
|
||||
#include <SFML/System/Win32/ThreadImpl.hpp>
|
||||
#include <SFML/System/Thread.hpp>
|
||||
#include <SFML/System/Err.hpp>
|
||||
#include <process.h>
|
||||
#include <iostream>
|
||||
|
||||
|
||||
namespace sf
|
||||
@ -41,7 +41,7 @@ ThreadImpl::ThreadImpl(Thread* owner)
|
||||
myThread = reinterpret_cast<HANDLE>(_beginthreadex(NULL, 0, &ThreadImpl::EntryPoint, owner, 0, NULL));
|
||||
|
||||
if (!myThread)
|
||||
std::cerr << "Failed to create thread" << std::endl;
|
||||
Err() << "Failed to create thread" << std::endl;
|
||||
}
|
||||
|
||||
|
||||
|
@ -30,7 +30,7 @@
|
||||
#include <SFML/Window/Linux/WindowImplX11.hpp>
|
||||
#include <SFML/OpenGL.hpp>
|
||||
#include <SFML/Window/glext/glxext.h>
|
||||
#include <iostream>
|
||||
#include <SFML/System/Err.hpp>
|
||||
|
||||
|
||||
namespace sf
|
||||
@ -158,7 +158,7 @@ void ContextGLX::CreateContext(ContextGLX* shared, unsigned int bitsPerPixel, co
|
||||
XWindowAttributes windowAttributes;
|
||||
if (XGetWindowAttributes(myDisplay, myWindow, &windowAttributes) == 0)
|
||||
{
|
||||
std::cerr << "Failed to get the window attributes" << std::endl;
|
||||
Err() << "Failed to get the window attributes" << std::endl;
|
||||
return;
|
||||
}
|
||||
|
||||
@ -175,7 +175,7 @@ void ContextGLX::CreateContext(ContextGLX* shared, unsigned int bitsPerPixel, co
|
||||
{
|
||||
if (visuals)
|
||||
XFree(visuals);
|
||||
std::cerr << "There is no valid visual for the selected screen" << std::endl;
|
||||
Err() << "There is no valid visual for the selected screen" << std::endl;
|
||||
return;
|
||||
}
|
||||
|
||||
@ -216,7 +216,7 @@ void ContextGLX::CreateContext(ContextGLX* shared, unsigned int bitsPerPixel, co
|
||||
// Make sure that we have found a visual
|
||||
if (!bestVisual)
|
||||
{
|
||||
std::cerr << "Failed to find a suitable pixel format for the window -- cannot create OpenGL context" << std::endl;
|
||||
Err() << "Failed to find a suitable pixel format for the window -- cannot create OpenGL context" << std::endl;
|
||||
return;
|
||||
}
|
||||
|
||||
@ -267,7 +267,7 @@ void ContextGLX::CreateContext(ContextGLX* shared, unsigned int bitsPerPixel, co
|
||||
myContext = glXCreateContext(myDisplay, bestVisual, toShare, true);
|
||||
if (!myContext)
|
||||
{
|
||||
std::cerr << "Failed to create an OpenGL context for this window" << std::endl;
|
||||
Err() << "Failed to create an OpenGL context for this window" << std::endl;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
@ -26,10 +26,10 @@
|
||||
// Headers
|
||||
////////////////////////////////////////////////////////////
|
||||
#include <SFML/Window/Linux/VideoModeSupport.hpp>
|
||||
#include <SFML/System/Err.hpp>
|
||||
#include <X11/Xlib.h>
|
||||
#include <X11/extensions/Xrandr.h>
|
||||
#include <algorithm>
|
||||
#include <iostream>
|
||||
|
||||
|
||||
namespace sf
|
||||
@ -89,13 +89,13 @@ void VideoModeSupport::GetSupportedVideoModes(std::vector<VideoMode>& modes)
|
||||
else
|
||||
{
|
||||
// Failed to get the screen configuration
|
||||
std::cerr << "Failed to retrieve the screen configuration while trying to get the supported video modes" << std::endl;
|
||||
Err() << "Failed to retrieve the screen configuration while trying to get the supported video modes" << std::endl;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// XRandr extension is not supported : we cannot get the video modes
|
||||
std::cerr << "Failed to use the XRandR extension while trying to get the supported video modes" << std::endl;
|
||||
Err() << "Failed to use the XRandR extension while trying to get the supported video modes" << std::endl;
|
||||
}
|
||||
|
||||
// Close the connection with the X server
|
||||
@ -104,7 +104,7 @@ void VideoModeSupport::GetSupportedVideoModes(std::vector<VideoMode>& modes)
|
||||
else
|
||||
{
|
||||
// We couldn't connect to the X server
|
||||
std::cerr << "Failed to connect to the X server while trying to get the supported video modes" << std::endl;
|
||||
Err() << "Failed to connect to the X server while trying to get the supported video modes" << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
@ -145,13 +145,13 @@ VideoMode VideoModeSupport::GetDesktopVideoMode()
|
||||
else
|
||||
{
|
||||
// Failed to get the screen configuration
|
||||
std::cerr << "Failed to retrieve the screen configuration while trying to get the desktop video modes" << std::endl;
|
||||
Err() << "Failed to retrieve the screen configuration while trying to get the desktop video modes" << std::endl;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// XRandr extension is not supported : we cannot get the video modes
|
||||
std::cerr << "Failed to use the XRandR extension while trying to get the desktop video modes" << std::endl;
|
||||
Err() << "Failed to use the XRandR extension while trying to get the desktop video modes" << std::endl;
|
||||
}
|
||||
|
||||
// Close the connection with the X server
|
||||
@ -160,7 +160,7 @@ VideoMode VideoModeSupport::GetDesktopVideoMode()
|
||||
else
|
||||
{
|
||||
// We couldn't connect to the X server
|
||||
std::cerr << "Failed to connect to the X server while trying to get the desktop video modes" << std::endl;
|
||||
Err() << "Failed to connect to the X server while trying to get the desktop video modes" << std::endl;
|
||||
}
|
||||
|
||||
return desktopMode;
|
||||
|
@ -28,10 +28,10 @@
|
||||
#include <SFML/Window/WindowStyle.hpp> // important to be included first (conflict with None)
|
||||
#include <SFML/Window/Linux/WindowImplX11.hpp>
|
||||
#include <SFML/System/Utf.hpp>
|
||||
#include <SFML/System/Err.hpp>
|
||||
#include <X11/Xutil.h>
|
||||
#include <X11/keysym.h>
|
||||
#include <X11/extensions/Xrandr.h>
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
#include <vector>
|
||||
|
||||
@ -84,7 +84,7 @@ myKeyRepeat (true)
|
||||
XWindowAttributes windowAttributes;
|
||||
if (XGetWindowAttributes(myDisplay, myWindow, &windowAttributes) == 0)
|
||||
{
|
||||
std::cerr << "Failed to get the window attributes" << std::endl;
|
||||
Err() << "Failed to get the window attributes" << std::endl;
|
||||
return;
|
||||
}
|
||||
myWidth = windowAttributes.width;
|
||||
@ -151,7 +151,7 @@ myKeyRepeat (true)
|
||||
CWEventMask | CWOverrideRedirect, &attributes);
|
||||
if (!myWindow)
|
||||
{
|
||||
std::cerr << "Failed to create window" << std::endl;
|
||||
Err() << "Failed to create window" << std::endl;
|
||||
return;
|
||||
}
|
||||
|
||||
@ -379,7 +379,7 @@ void WindowImplX11::SetIcon(unsigned int width, unsigned int height, const Uint8
|
||||
XImage* iconImage = XCreateImage(myDisplay, defVisual, defDepth, ZPixmap, 0, (char*)iconPixels, width, height, 32, 0);
|
||||
if (!iconImage)
|
||||
{
|
||||
std::cerr << "Failed to set the window's icon" << std::endl;
|
||||
Err() << "Failed to set the window's icon" << std::endl;
|
||||
return;
|
||||
}
|
||||
Pixmap iconPixmap = XCreatePixmap(myDisplay, RootWindow(myDisplay, myScreen), width, height, defDepth);
|
||||
@ -461,13 +461,13 @@ void WindowImplX11::SwitchToFullscreen(const VideoMode& mode)
|
||||
else
|
||||
{
|
||||
// Failed to get the screen configuration
|
||||
std::cerr << "Failed to get the current screen configuration for fullscreen mode, switching to window mode" << std::endl;
|
||||
Err() << "Failed to get the current screen configuration for fullscreen mode, switching to window mode" << std::endl;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// XRandr extension is not supported : we cannot use fullscreen mode
|
||||
std::cerr << "Fullscreen is not supported, switching to window mode" << std::endl;
|
||||
Err() << "Fullscreen is not supported, switching to window mode" << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
@ -497,7 +497,7 @@ void WindowImplX11::Initialize()
|
||||
myInputContext = NULL;
|
||||
}
|
||||
if (!myInputContext)
|
||||
std::cerr << "Failed to create input context for window -- TextEntered event won't be able to return unicode" << std::endl;
|
||||
Err() << "Failed to create input context for window -- TextEntered event won't be able to return unicode" << std::endl;
|
||||
|
||||
// Show the window
|
||||
XMapWindow(myDisplay, myWindow);
|
||||
|
@ -31,7 +31,7 @@
|
||||
#include <SFML/Window/glext/wglext.h>
|
||||
#include <SFML/System/Lock.hpp>
|
||||
#include <SFML/System/Mutex.hpp>
|
||||
#include <iostream>
|
||||
#include <SFML/System/Err.hpp>
|
||||
|
||||
|
||||
namespace sf
|
||||
@ -205,7 +205,7 @@ void ContextWGL::CreateContext(ContextWGL* shared, unsigned int bitsPerPixel, co
|
||||
else
|
||||
{
|
||||
// wglChoosePixelFormatARB not supported ; disabling antialiasing
|
||||
std::cerr << "Antialiasing is not supported ; it will be disabled" << std::endl;
|
||||
Err() << "Antialiasing is not supported ; it will be disabled" << std::endl;
|
||||
mySettings.AntialiasingLevel = 0;
|
||||
}
|
||||
}
|
||||
@ -229,7 +229,7 @@ void ContextWGL::CreateContext(ContextWGL* shared, unsigned int bitsPerPixel, co
|
||||
bestFormat = ChoosePixelFormat(myDeviceContext, &descriptor);
|
||||
if (bestFormat == 0)
|
||||
{
|
||||
std::cerr << "Failed to find a suitable pixel format for device context -- cannot create OpenGL context" << std::endl;
|
||||
Err() << "Failed to find a suitable pixel format for device context -- cannot create OpenGL context" << std::endl;
|
||||
return;
|
||||
}
|
||||
}
|
||||
@ -245,7 +245,7 @@ void ContextWGL::CreateContext(ContextWGL* shared, unsigned int bitsPerPixel, co
|
||||
// Set the chosen pixel format
|
||||
if (!SetPixelFormat(myDeviceContext, bestFormat, &actualFormat))
|
||||
{
|
||||
std::cerr << "Failed to set pixel format for device context -- cannot create OpenGL context" << std::endl;
|
||||
Err() << "Failed to set pixel format for device context -- cannot create OpenGL context" << std::endl;
|
||||
return;
|
||||
}
|
||||
|
||||
@ -289,7 +289,7 @@ void ContextWGL::CreateContext(ContextWGL* shared, unsigned int bitsPerPixel, co
|
||||
myContext = wglCreateContext(myDeviceContext);
|
||||
if (!myContext)
|
||||
{
|
||||
std::cerr << "Failed to create an OpenGL context for this window" << std::endl;
|
||||
Err() << "Failed to create an OpenGL context for this window" << std::endl;
|
||||
return;
|
||||
}
|
||||
|
||||
@ -301,7 +301,7 @@ void ContextWGL::CreateContext(ContextWGL* shared, unsigned int bitsPerPixel, co
|
||||
Lock lock(mutex);
|
||||
|
||||
if (!wglShareLists(sharedContext, myContext))
|
||||
std::cerr << "Failed to share the OpenGL context" << std::endl;
|
||||
Err() << "Failed to share the OpenGL context" << std::endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -32,7 +32,7 @@
|
||||
#include <GL/gl.h>
|
||||
#include <SFML/Window/glext/wglext.h>
|
||||
#include <SFML/Window/glext/glext.h>
|
||||
#include <iostream>
|
||||
#include <SFML/System/Err.hpp>
|
||||
#include <vector>
|
||||
|
||||
// MinGW lacks the definition of some Win32 constants
|
||||
@ -309,7 +309,7 @@ void WindowImplWin32::SetIcon(unsigned int width, unsigned int height, const Uin
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cerr << "Failed to set the window's icon" << std::endl;
|
||||
Err() << "Failed to set the window's icon" << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
@ -363,7 +363,7 @@ void WindowImplWin32::SwitchToFullscreen(const VideoMode& mode)
|
||||
// Apply fullscreen mode
|
||||
if (ChangeDisplaySettings(&devMode, CDS_FULLSCREEN) != DISP_CHANGE_SUCCESSFUL)
|
||||
{
|
||||
std::cerr << "Failed to change display mode for fullscreen" << std::endl;
|
||||
Err() << "Failed to change display mode for fullscreen" << std::endl;
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -29,7 +29,7 @@
|
||||
#include <SFML/Window/ContextGL.hpp>
|
||||
#include <SFML/Window/WindowImpl.hpp>
|
||||
#include <SFML/System/Sleep.hpp>
|
||||
#include <iostream>
|
||||
#include <SFML/System/Err.hpp>
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
@ -104,7 +104,7 @@ void Window::Create(VideoMode mode, const std::string& title, unsigned long styl
|
||||
// Make sure there's not already a fullscreen window (only one is allowed)
|
||||
if (fullscreenWindow)
|
||||
{
|
||||
std::cerr << "Creating two fullscreen windows is not allowed, switching to windowed mode" << std::endl;
|
||||
Err() << "Creating two fullscreen windows is not allowed, switching to windowed mode" << std::endl;
|
||||
style &= ~Style::Fullscreen;
|
||||
}
|
||||
else
|
||||
@ -112,7 +112,7 @@ void Window::Create(VideoMode mode, const std::string& title, unsigned long styl
|
||||
// Make sure the chosen video mode is compatible
|
||||
if (!mode.IsValid())
|
||||
{
|
||||
std::cerr << "The requested video mode is not available, switching to a valid mode" << std::endl;
|
||||
Err() << "The requested video mode is not available, switching to a valid mode" << std::endl;
|
||||
mode = VideoMode::GetMode(0);
|
||||
}
|
||||
|
||||
@ -315,7 +315,7 @@ bool Window::SetActive(bool active) const
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cerr << "Failed to activate the window's context" << std::endl;
|
||||
Err() << "Failed to activate the window's context" << std::endl;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user