mirror of
https://github.com/SFML/CSFML.git
synced 2026-10-27 21:36:13 +01:00
Added InputStream
This commit is contained in:
1 parent
56df80a7d3
commit
6e251c5415
15 files changed
+323
-33
No files matched your search
@@ -36,7 +36,6 @@
|
||||
sfMusic* sfMusic_CreateFromFile(const char* filename)
|
||||
{
|
||||
sfMusic* music = new sfMusic;
|
||||
|
||||
if (!music->This.OpenFromFile(filename))
|
||||
{
|
||||
delete music;
|
||||
@@ -53,7 +52,6 @@ sfMusic* sfMusic_CreateFromFile(const char* filename)
|
||||
sfMusic* sfMusic_CreateFromMemory(const void* data, size_t sizeInBytes)
|
||||
{
|
||||
sfMusic* music = new sfMusic;
|
||||
|
||||
if (!music->This.OpenFromMemory(data, sizeInBytes))
|
||||
{
|
||||
delete music;
|
||||
@@ -64,6 +62,25 @@ sfMusic* sfMusic_CreateFromMemory(const void* data, size_t sizeInBytes)
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Create a new music and load it from a custom stream
|
||||
////////////////////////////////////////////////////////////
|
||||
sfMusic* sfMusic_CreateFromStream(sfInputStream* stream)
|
||||
{
|
||||
CSFML_CHECK_RETURN(stream, NULL);
|
||||
|
||||
sfMusic* music = new sfMusic;
|
||||
music->Stream = CallbackStream(stream);
|
||||
if (!music->This.OpenFromStream(music->Stream))
|
||||
{
|
||||
delete music;
|
||||
music = NULL;
|
||||
}
|
||||
|
||||
return music;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Destroy an existing music
|
||||
////////////////////////////////////////////////////////////
|
||||
|
||||
@@ -29,6 +29,7 @@
|
||||
// Headers
|
||||
////////////////////////////////////////////////////////////
|
||||
#include <SFML/Audio/Music.hpp>
|
||||
#include <SFML/CallbackStream.h>
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
@@ -37,6 +38,7 @@
|
||||
struct sfMusic
|
||||
{
|
||||
sf::Music This;
|
||||
CallbackStream Stream;
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,120 @@
|
||||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// 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_CALLBACKSTREAM_H
|
||||
#define SFML_CALLBACKSTREAM_H
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// Headers
|
||||
////////////////////////////////////////////////////////////
|
||||
#include <SFML/System/InputStream.hpp>
|
||||
#include <SFML/System/InputStream.h>
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Adapts a CSFML input stream to a SFML input stream
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
class CallbackStream : public sf::InputStream
|
||||
{
|
||||
public:
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Default constructor
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
CallbackStream()
|
||||
{
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Constructor
|
||||
///
|
||||
/// \param stream CSFML input stream callbacks
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
CallbackStream(sfInputStream* stream) :
|
||||
myStream(*stream)
|
||||
{
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Read data from the stream
|
||||
///
|
||||
/// \param data Buffer where to copy the read data
|
||||
/// \param size Desired number of bytes to read
|
||||
///
|
||||
/// \return The number of bytes actually read
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
virtual sf::Int64 Read(char* data, sf::Int64 size)
|
||||
{
|
||||
return myStream.Read ? myStream.Read(data, size, myStream.UserData) : -1;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Change the current reading position
|
||||
///
|
||||
/// \param position The position to seek to, from the beginning
|
||||
///
|
||||
/// \return The position actually seeked to, or -1 on error
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
virtual sf::Int64 Seek(sf::Int64 position)
|
||||
{
|
||||
return myStream.Seek ? myStream.Seek(position, myStream.UserData) : -1;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Return the current reading position in the stream
|
||||
///
|
||||
/// \return The current position, or -1 on error.
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
virtual sf::Int64 Tell()
|
||||
{
|
||||
return myStream.Tell ? myStream.Tell(myStream.UserData) : -1;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Return the size of the stream
|
||||
///
|
||||
/// \return The total number of bytes available in the stream, or -1 on error
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
virtual sf::Int64 GetSize()
|
||||
{
|
||||
return myStream.GetSize ? myStream.GetSize(myStream.UserData) : -1;
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// Member data
|
||||
////////////////////////////////////////////////////////////
|
||||
sfInputStream myStream; ///< The source CSFML input stream
|
||||
};
|
||||
|
||||
|
||||
#endif // SFML_CALLBACKSTREAM_H
|
||||
@@ -28,6 +28,7 @@
|
||||
#include <SFML/Graphics/Font.h>
|
||||
#include <SFML/Graphics/FontStruct.h>
|
||||
#include <SFML/Internal.h>
|
||||
#include <SFML/CallbackStream.h>
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
@@ -62,6 +63,25 @@ sfFont* sfFont_CreateFromMemory(const void* data, size_t sizeInBytes)
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Create a new font from a custom stream
|
||||
////////////////////////////////////////////////////////////
|
||||
sfFont* sfFont_CreateFromStream(sfInputStream* stream)
|
||||
{
|
||||
CSFML_CHECK_RETURN(stream, NULL);
|
||||
|
||||
sfFont* font = new sfFont;
|
||||
font->Stream = CallbackStream(stream);
|
||||
if (!font->This.LoadFromStream(font->Stream))
|
||||
{
|
||||
delete font;
|
||||
font = NULL;
|
||||
}
|
||||
|
||||
return font;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Copy an existing font
|
||||
////////////////////////////////////////////////////////////
|
||||
|
||||
@@ -30,6 +30,7 @@
|
||||
////////////////////////////////////////////////////////////
|
||||
#include <SFML/Graphics/Font.hpp>
|
||||
#include <SFML/Graphics/ImageStruct.h>
|
||||
#include <SFML/CallbackStream.h>
|
||||
#include <map>
|
||||
|
||||
|
||||
@@ -40,6 +41,7 @@ struct sfFont
|
||||
{
|
||||
sf::Font This;
|
||||
std::map<unsigned int, sfImage> Images;
|
||||
CallbackStream Stream;
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -29,6 +29,7 @@
|
||||
#include <SFML/Graphics/ImageStruct.h>
|
||||
#include <SFML/Graphics/RenderWindowStruct.h>
|
||||
#include <SFML/Internal.h>
|
||||
#include <SFML/CallbackStream.h>
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
@@ -99,6 +100,26 @@ sfImage* sfImage_CreateFromMemory(const void* data, size_t sizeInBytes)
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Create a new image from a custom stream
|
||||
////////////////////////////////////////////////////////////
|
||||
sfImage* sfImage_CreateFromStream(sfInputStream* stream)
|
||||
{
|
||||
CSFML_CHECK_RETURN(stream, NULL);
|
||||
|
||||
sfImage* image = new sfImage;
|
||||
|
||||
CallbackStream sfmlStream(stream);
|
||||
if (!image->This->LoadFromStream(sfmlStream))
|
||||
{
|
||||
delete image;
|
||||
image = NULL;
|
||||
}
|
||||
|
||||
return image;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Copy an existing image
|
||||
////////////////////////////////////////////////////////////
|
||||
|
||||
@@ -29,6 +29,7 @@
|
||||
#include <SFML/Graphics/ShaderStruct.h>
|
||||
#include <SFML/Graphics/ImageStruct.h>
|
||||
#include <SFML/Internal.h>
|
||||
#include <SFML/CallbackStream.h>
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
@@ -65,6 +66,26 @@ sfShader* sfShader_CreateFromMemory(const char* effect)
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Create a new shader from a custom stream
|
||||
////////////////////////////////////////////////////////////
|
||||
sfShader* sfShader_CreateFromStream(sfInputStream* stream)
|
||||
{
|
||||
CSFML_CHECK_RETURN(stream, NULL);
|
||||
|
||||
sfShader* shader = new sfShader;
|
||||
|
||||
CallbackStream sfmlStream(stream);
|
||||
if (!shader->This.LoadFromStream(sfmlStream))
|
||||
{
|
||||
delete shader;
|
||||
shader = NULL;
|
||||
}
|
||||
|
||||
return shader;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Copy an existing clock
|
||||
////////////////////////////////////////////////////////////
|
||||
|
||||
@@ -7,6 +7,7 @@ set(SRC
|
||||
${SRCROOT}/Clock.cpp
|
||||
${SRCROOT}/ClockStruct.h
|
||||
${INCROOT}/Clock.h
|
||||
${INCROOT}/InputStream.h
|
||||
${SRCROOT}/Mutex.cpp
|
||||
${SRCROOT}/MutexStruct.h
|
||||
${INCROOT}/Mutex.h
|
||||
|
||||
Reference in new issue
Block a user