From bf539551b97190c906ce83ef5d960561734ebbef Mon Sep 17 00:00:00 2001 From: trass3r Date: Wed, 13 Jan 2010 17:42:05 +0000 Subject: [PATCH] * changed SoundStream.onStart to onSeek * made network package compilable in D2 + Vector2.max function to return the bigger member git-svn-id: https://sfml.svn.sourceforge.net/svnroot/sfml/branches/sfml2@1354 4e206d99-4929-0410-ac5d-dfc041789085 --- DSFML/import/dsfml/audio/sound.d | 4 ++-- DSFML/import/dsfml/audio/soundsource.d | 2 +- DSFML/import/dsfml/audio/soundstream.d | 14 +++++--------- DSFML/import/dsfml/network/ftp.d | 24 ++++++++++++------------ DSFML/import/dsfml/network/http.d | 12 ++++++------ DSFML/import/dsfml/network/ipaddress.d | 2 +- DSFML/import/dsfml/network/packet.d | 18 +++++++++--------- DSFML/import/dsfml/network/sockettcp.d | 16 ++++++++++++---- DSFML/import/dsfml/system/vector2.d | 5 +++++ 9 files changed, 53 insertions(+), 44 deletions(-) diff --git a/DSFML/import/dsfml/audio/sound.d b/DSFML/import/dsfml/audio/sound.d index 4608693a..36894092 100644 --- a/DSFML/import/dsfml/audio/sound.d +++ b/DSFML/import/dsfml/audio/sound.d @@ -68,8 +68,8 @@ class Sound : SoundSource!("sfSound") throw new NullParameterException("NullParameterException : SoundBuffer is null."); super(); - sfSound_SetBuffer(m_ptr, buffer.getNativePointer()); - sfSound_SetLoop(m_ptr, loop); + setBuffer(buffer); + setLoop(loop); setPitch(pitch); setVolume(volume); setPosition(x, y, z); diff --git a/DSFML/import/dsfml/audio/soundsource.d b/DSFML/import/dsfml/audio/soundsource.d index 0ad3a51b..ce71b917 100644 --- a/DSFML/import/dsfml/audio/soundsource.d +++ b/DSFML/import/dsfml/audio/soundsource.d @@ -32,7 +32,7 @@ protected : this(void* ptr) { - super(ptr, true); + super(ptr); } //////////////////////////////////////////////////////////// diff --git a/DSFML/import/dsfml/audio/soundstream.d b/DSFML/import/dsfml/audio/soundstream.d index 4ac50162..73b29b68 100644 --- a/DSFML/import/dsfml/audio/soundstream.d +++ b/DSFML/import/dsfml/audio/soundstream.d @@ -199,7 +199,7 @@ protected: m_channelsCount = channelsCount; m_sampleRate = sampleRate; - m_ptr = sfSoundStream_Create(&externalOnGetData, &externalOnSeek, channelsCount, sampleRate, &m_id); // TODO: hack + super(sfSoundStream_Create(&externalOnGetData, &externalOnSeek, channelsCount, sampleRate, &m_id)); m_mutex = new Mutex(); @@ -212,12 +212,9 @@ protected: } /** - * Called each time the stream restart - * - * Returns: - * false to abort the playback + * Called each time the stream is seeked */ - abstract bool onStart(); + abstract void onSeek(); /** * Called each time the stream needs new data. @@ -233,16 +230,15 @@ protected: private: // Called sync when user calling play() - // FIXME: this needs to be transformed from OnStart to OnSeek + // TODO: check if it's correct that way extern(C) static void externalOnSeek(float t, void* user) { int id; if ((id = *cast(int*) user) in s_instances) { SoundStream temp = s_instances[id]; - return (temp.m_flag = temp.onStart()); + return (temp.onSeek()); } -// return true; } // C Thread callback (no allocation can be done) diff --git a/DSFML/import/dsfml/network/ftp.d b/DSFML/import/dsfml/network/ftp.d index 8a43c393..b522e6f5 100644 --- a/DSFML/import/dsfml/network/ftp.d +++ b/DSFML/import/dsfml/network/ftp.d @@ -173,7 +173,7 @@ class Ftp : DSFMLObject typedef void function(void*) pf_sfFtpResponse_Destroy; typedef int function(void*) pf_sfFtpResponse_IsOk; typedef FtpStatus function(void*) pf_sfFtpResponse_GetStatus; - typedef char* function(void*) pf_sfFtpResponse_GetMessage; + typedef ichar* function(void*) pf_sfFtpResponse_GetMessage; static pf_sfFtpResponse_Destroy sfFtpResponse_Destroy; static pf_sfFtpResponse_IsOk sfFtpResponse_IsOk; @@ -222,7 +222,7 @@ class Ftp : DSFMLObject extern (C) { typedef void function(void*) pf_sfFtpDirectoryResponse_Destroy; - typedef char* function(void*) pf_sfFtpDirectoryResponse_GetDirectory; + typedef ichar* function(void*) pf_sfFtpDirectoryResponse_GetDirectory; static pf_sfFtpDirectoryResponse_Destroy sfFtpDirectoryResponse_Destroy; static pf_sfFtpDirectoryResponse_GetDirectory sfFtpDirectoryResponse_GetDirectory; @@ -301,7 +301,7 @@ class Ftp : DSFMLObject { typedef void function(void*) pf_sfFtpListingResponse_Destroy; typedef size_t function(void*) pf_sfFtpListingResponse_GetCount; - typedef char* function(void*, size_t) pf_sfFtpListingResponse_GetFilename; + typedef ichar* function(void*, size_t) pf_sfFtpListingResponse_GetFilename; static pf_sfFtpListingResponse_Destroy sfFtpListingResponse_Destroy; static pf_sfFtpListingResponse_GetCount sfFtpListingResponse_GetCount; @@ -542,19 +542,19 @@ private: typedef void function(void*) pf_sfFtp_Destroy; typedef void* function(void*, IPAddress, ushort, float) pf_sfFtp_Connect; typedef void* function(void*) pf_sfFtp_LoginAnonymous; - typedef void* function(void*, char*, char*) pf_sfFtp_Login; + typedef void* function(void*, cchar*, cchar*) pf_sfFtp_Login; typedef void* function(void*) pf_sfFtp_Disconnect; typedef void* function(void*) pf_sfFtp_KeepAlive; typedef void* function(void*) pf_sfFtp_GetWorkingDirectory; - typedef void* function(void*, char*) pf_sfFtp_GetDirectoryListing; - typedef void* function(void*, char*) pf_sfFtp_ChangeDirectory; + typedef void* function(void*, cchar*) pf_sfFtp_GetDirectoryListing; + typedef void* function(void*, cchar*) pf_sfFtp_ChangeDirectory; typedef void* function(void*) pf_sfFtp_ParentDirectory; - typedef void* function(void*, char*) pf_sfFtp_MakeDirectory; - typedef void* function(void*, char*) pf_sfFtp_DeleteDirectory; - typedef void* function(void*, char*, char*) pf_sfFtp_RenameFile; - typedef void* function(void*, char*) pf_sfFtp_DeleteFile; - typedef void* function(void*, char*, char*, FtpTransferMode) pf_sfFtp_Download; - typedef void* function(void*, char*, char*, FtpTransferMode) pf_sfFtp_Upload; + typedef void* function(void*, cchar*) pf_sfFtp_MakeDirectory; + typedef void* function(void*, cchar*) pf_sfFtp_DeleteDirectory; + typedef void* function(void*, cchar*, cchar*) pf_sfFtp_RenameFile; + typedef void* function(void*, cchar*) pf_sfFtp_DeleteFile; + typedef void* function(void*, cchar*, cchar*, FtpTransferMode) pf_sfFtp_Download; + typedef void* function(void*, cchar*, cchar*, FtpTransferMode) pf_sfFtp_Upload; static pf_sfFtp_Create sfFtp_Create; static pf_sfFtp_Destroy sfFtp_Destroy; diff --git a/DSFML/import/dsfml/network/http.d b/DSFML/import/dsfml/network/http.d index 19971d8b..f14c788b 100644 --- a/DSFML/import/dsfml/network/http.d +++ b/DSFML/import/dsfml/network/http.d @@ -162,11 +162,11 @@ class Http : DSFMLObject extern (C) { typedef void function(void*) pf_sfHttpResponse_Destroy; - typedef char* function(void*, char*) pf_sfHttpResponse_GetField; + typedef ichar* function(void*, cchar*) pf_sfHttpResponse_GetField; typedef HttpStatus function(void*) pf_sfHttpResponse_GetStatus; typedef uint function(void*) pf_sfHttpResponse_GetMajorVersion; typedef uint function(void*) pf_sfHttpResponse_GetMinorVersion; - typedef char* function(void*) pf_sfHttpResponse_GetBody; + typedef ichar* function(void*) pf_sfHttpResponse_GetBody; static pf_sfHttpResponse_Destroy sfHttpResponse_Destroy; static pf_sfHttpResponse_GetField sfHttpResponse_GetField; @@ -278,11 +278,11 @@ class Http : DSFMLObject { typedef void* function() pf_sfHttpRequest_Create; typedef void function(void*) pf_sfHttpRequest_Destroy; - typedef void function(void*, char*, char*) pf_sfHttpRequest_SetField; + typedef void function(void*, cchar*, cchar*) pf_sfHttpRequest_SetField; typedef void function(void*, HttpMethod) pf_sfHttpRequest_SetMethod; - typedef void function(void*, char*) pf_sfHttpRequest_SetURI; + typedef void function(void*, cchar*) pf_sfHttpRequest_SetURI; typedef void function(void*, uint, uint) pf_sfHttpRequest_SetHttpVersion; - typedef void function(void*, char*) pf_sfHttpRequest_SetBody; + typedef void function(void*, cchar*) pf_sfHttpRequest_SetBody; static pf_sfHttpRequest_Create sfHttpRequest_Create; static pf_sfHttpRequest_Destroy sfHttpRequest_Destroy; @@ -374,7 +374,7 @@ private: { typedef void* function() pf_sfHttp_Create; typedef void function(void*) pf_sfHttp_Destroy; - typedef void function(void*, char*, ushort) pf_sfHttp_SetHost; + typedef void function(void*, cchar*, ushort) pf_sfHttp_SetHost; typedef void* function(void*, void*) pf_sfHttp_SendRequest; static pf_sfHttp_Create sfHttp_Create; diff --git a/DSFML/import/dsfml/network/ipaddress.d b/DSFML/import/dsfml/network/ipaddress.d index cdc95100..cd679125 100644 --- a/DSFML/import/dsfml/network/ipaddress.d +++ b/DSFML/import/dsfml/network/ipaddress.d @@ -134,7 +134,7 @@ private: extern (C) { - typedef IPAddress function(char*) pf_sfIPAddress_FromString; + typedef IPAddress function(cchar*) pf_sfIPAddress_FromString; typedef IPAddress function(ubyte, ubyte, ubyte, ubyte) pf_sfIPAddress_FromBytes; typedef IPAddress function(uint) pf_sfIPAddress_FromInteger; typedef int function(IPAddress) pf_sfIPAddress_IsValid; diff --git a/DSFML/import/dsfml/network/packet.d b/DSFML/import/dsfml/network/packet.d index 8d539672..d93c26c8 100644 --- a/DSFML/import/dsfml/network/packet.d +++ b/DSFML/import/dsfml/network/packet.d @@ -130,7 +130,9 @@ class Packet : DSFMLObject byte[] getData() { if (canRead) - return sfPacket_GetData(m_ptr)[0..getDataSize]; + return sfPacket_GetData(m_ptr)[0..getDataSize()]; + else + return null; } @@ -253,20 +255,18 @@ private: } void internalGet(ref string data) { - scope string temp = new char[sfPacket_GetDataSize(m_ptr)]; + scope char[] temp = new char[sfPacket_GetDataSize(m_ptr)]; sfPacket_ReadString(m_ptr, temp.ptr); size_t l = fromStringz(temp.ptr).length; - data = new char[l]; - data[] = temp[0 .. l]; + data = cast(string) temp[0 .. l]; } void internalGet(ref wstring data) { - scope wstring temp = new wchar[sfPacket_GetDataSize(m_ptr)]; + scope wchar[] temp = new wchar[sfPacket_GetDataSize(m_ptr)]; sfPacket_ReadWideString(m_ptr, temp.ptr); size_t l = fromStringz(temp.ptr).length; - data = new wchar[l]; - data[] = temp[0 .. l]; + data = cast(wstring) temp[0 .. l]; } void internalSet(bool data) @@ -345,8 +345,8 @@ private: typedef void function(void*, uint) pf_sfPacket_WriteUint32; typedef void function(void*, float) pf_sfPacket_WriteFloat; typedef void function(void*, double) pf_sfPacket_WriteDouble; - typedef void function(void*, char*) pf_sfPacket_WriteString; - typedef void function(void*, wchar*) pf_sfPacket_WriteWideString; + typedef void function(void*, cchar*) pf_sfPacket_WriteString; + typedef void function(void*, cwchar*) pf_sfPacket_WriteWideString; static pf_sfPacket_Create sfPacket_Create; static pf_sfPacket_Destroy sfPacket_Destroy; diff --git a/DSFML/import/dsfml/network/sockettcp.d b/DSFML/import/dsfml/network/sockettcp.d index 19d12374..362e74e3 100644 --- a/DSFML/import/dsfml/network/sockettcp.d +++ b/DSFML/import/dsfml/network/sockettcp.d @@ -128,9 +128,13 @@ class SocketTCP : DSFMLObject * Status code */ SocketStatus send(byte[] data) + in { - if (data && data.length > 0) - return cast(SocketStatus)sfSocketTCP_Send(m_ptr, data.ptr, data.length); + assert(data && data.length); + } + body + { + return cast(SocketStatus)sfSocketTCP_Send(m_ptr, data.ptr, data.length); } /** @@ -149,9 +153,13 @@ class SocketTCP : DSFMLObject * */ SocketStatus receive(byte[] data, out size_t sizeReceived) + in { - if (data && data.length > 0) - return cast(SocketStatus)sfSocketTCP_Receive(m_ptr, data.ptr, data.length, &sizeReceived); + assert(data && data.length); + } + body + { + return cast(SocketStatus)sfSocketTCP_Receive(m_ptr, data.ptr, data.length, &sizeReceived); } diff --git a/DSFML/import/dsfml/system/vector2.d b/DSFML/import/dsfml/system/vector2.d index d997f285..2b4a3b38 100644 --- a/DSFML/import/dsfml/system/vector2.d +++ b/DSFML/import/dsfml/system/vector2.d @@ -103,6 +103,11 @@ struct Vector2(T) { return (x == other.x) && (y == other.y); } + + T max() + { + return (x>y) ? x : y; + } } version (UnitTest)