Improved internal macros

This commit is contained in:
Laurent Gomila committed 2012-02-04 11:01:37 +01:00
1 parent 0c5afa3483
commit c40961bac3
18 files changed
+275 -190

No files matched your search

+12 -12
View File
@@ -56,21 +56,21 @@ void sfSound_Destroy(sfSound* sound)
////////////////////////////////////////////////////////////
void sfSound_Play(sfSound* sound)
{
CSFML_CALL(sound, Play())
CSFML_CALL(sound, Play());
}
////////////////////////////////////////////////////////////
void sfSound_Pause(sfSound* sound)
{
CSFML_CALL(sound, Pause())
CSFML_CALL(sound, Pause());
}
////////////////////////////////////////////////////////////
void sfSound_Stop(sfSound* sound)
{
CSFML_CALL(sound, Stop())
CSFML_CALL(sound, Stop());
}
@@ -79,7 +79,7 @@ void sfSound_SetBuffer(sfSound* sound, const sfSoundBuffer* buffer)
{
if (buffer)
{
CSFML_CALL(sound, SetBuffer(buffer->This))
CSFML_CALL(sound, SetBuffer(buffer->This));
sound->Buffer = buffer;
}
}
@@ -88,7 +88,7 @@ void sfSound_SetBuffer(sfSound* sound, const sfSoundBuffer* buffer)
////////////////////////////////////////////////////////////
const sfSoundBuffer* sfSound_GetBuffer(const sfSound* sound)
{
CSFML_CHECK_RETURN(sound, NULL)
CSFML_CHECK_RETURN(sound, NULL);
return sound->Buffer;
}
@@ -97,14 +97,14 @@ const sfSoundBuffer* sfSound_GetBuffer(const sfSound* sound)
////////////////////////////////////////////////////////////
void sfSound_SetLoop(sfSound* sound, sfBool loop)
{
CSFML_CALL(sound, SetLoop(loop == sfTrue))
CSFML_CALL(sound, SetLoop(loop == sfTrue));
}
////////////////////////////////////////////////////////////
sfBool sfSound_GetLoop(const sfSound* sound)
{
CSFML_CALL_RETURN(sound, GetLoop(), sfFalse)
CSFML_CALL_RETURN(sound, GetLoop(), sfFalse);
}
@@ -120,21 +120,21 @@ sfSoundStatus sfSound_GetStatus(const sfSound* sound)
////////////////////////////////////////////////////////////
void sfSound_SetPitch(sfSound* sound, float pitch)
{
CSFML_CALL(sound, SetPitch(pitch))
CSFML_CALL(sound, SetPitch(pitch));
}
////////////////////////////////////////////////////////////
void sfSound_SetVolume(sfSound* sound, float volume)
{
CSFML_CALL(sound, SetVolume(volume))
CSFML_CALL(sound, SetVolume(volume));
}
////////////////////////////////////////////////////////////
void sfSound_SetPosition(sfSound* sound, float x, float y, float z)
{
CSFML_CALL(sound, SetPosition(sf::Vector3f(x, y, z)))
CSFML_CALL(sound, SetPosition(sf::Vector3f(x, y, z)));
}
@@ -169,14 +169,14 @@ void sfSound_SetPlayingOffset(sfSound* sound, sfTime timeOffset)
////////////////////////////////////////////////////////////
float sfSound_GetPitch(const sfSound* sound)
{
CSFML_CALL_RETURN(sound, GetPitch(), 0.f)
CSFML_CALL_RETURN(sound, GetPitch(), 0.f);
}
////////////////////////////////////////////////////////////
float sfSound_GetVolume(const sfSound* sound)
{
CSFML_CALL_RETURN(sound, GetVolume(), 0.f)
CSFML_CALL_RETURN(sound, GetVolume(), 0.f);
}
+5 -5
View File
@@ -113,35 +113,35 @@ void sfSoundBuffer_Destroy(sfSoundBuffer* soundBuffer)
////////////////////////////////////////////////////////////
sfBool sfSoundBuffer_SaveToFile(const sfSoundBuffer* soundBuffer, const char* filename)
{
CSFML_CALL_RETURN(soundBuffer, SaveToFile(filename), sfFalse)
CSFML_CALL_RETURN(soundBuffer, SaveToFile(filename), sfFalse);
}
////////////////////////////////////////////////////////////
const sfInt16* sfSoundBuffer_GetSamples(const sfSoundBuffer* soundBuffer)
{
CSFML_CALL_RETURN(soundBuffer, GetSamples(), NULL)
CSFML_CALL_RETURN(soundBuffer, GetSamples(), NULL);
}
////////////////////////////////////////////////////////////
size_t sfSoundBuffer_GetSampleCount(const sfSoundBuffer* soundBuffer)
{
CSFML_CALL_RETURN(soundBuffer, GetSampleCount(), 0)
CSFML_CALL_RETURN(soundBuffer, GetSampleCount(), 0);
}
////////////////////////////////////////////////////////////
unsigned int sfSoundBuffer_GetSampleRate(const sfSoundBuffer* soundBuffer)
{
CSFML_CALL_RETURN(soundBuffer, GetSampleRate(), 0)
CSFML_CALL_RETURN(soundBuffer, GetSampleRate(), 0);
}
////////////////////////////////////////////////////////////
unsigned int sfSoundBuffer_GetChannelCount(const sfSoundBuffer* soundBuffer)
{
CSFML_CALL_RETURN(soundBuffer, GetChannelCount(), 0)
CSFML_CALL_RETURN(soundBuffer, GetChannelCount(), 0);
}
+4 -4
View File
@@ -178,7 +178,7 @@ const sfTransform* sfCircleShape_GetInverseTransform(const sfCircleShape* shape)
////////////////////////////////////////////////////////////
void sfCircleShape_SetTexture(sfCircleShape* shape, const sfTexture* texture, sfBool resetRect)
{
CSFML_CALL(shape, SetTexture(texture ? texture->This : NULL, resetRect == sfTrue))
CSFML_CALL(shape, SetTexture(texture ? texture->This : NULL, resetRect == sfTrue));
shape->Texture = texture;
}
@@ -186,7 +186,7 @@ void sfCircleShape_SetTexture(sfCircleShape* shape, const sfTexture* texture, sf
////////////////////////////////////////////////////////////
void sfCircleShape_SetTextureRect(sfCircleShape* shape, sfIntRect rect)
{
CSFML_CALL(shape, SetTextureRect(sf::IntRect(rect.Left, rect.Top, rect.Width, rect.Height)))
CSFML_CALL(shape, SetTextureRect(sf::IntRect(rect.Left, rect.Top, rect.Width, rect.Height)));
}
@@ -214,7 +214,7 @@ void sfCircleShape_SetOutlineThickness(sfCircleShape* shape, float thickness)
////////////////////////////////////////////////////////////
const sfTexture* sfCircleShape_GetTexture(const sfCircleShape* shape)
{
CSFML_CHECK_RETURN(shape, NULL)
CSFML_CHECK_RETURN(shape, NULL);
return shape->Texture;
}
@@ -224,7 +224,7 @@ const sfTexture* sfCircleShape_GetTexture(const sfCircleShape* shape)
sfIntRect sfCircleShape_GetTextureRect(const sfCircleShape* shape)
{
sfIntRect rect = {0, 0, 0, 0};
CSFML_CHECK_RETURN(sprite, rect)
CSFML_CHECK_RETURN(shape, rect);
sf::IntRect sfmlRect = shape->This.GetTextureRect();
rect.Left = sfmlRect.Left;
+4 -4
View File
@@ -175,7 +175,7 @@ const sfTransform* sfConvexShape_GetInverseTransform(const sfConvexShape* shape)
////////////////////////////////////////////////////////////
void sfConvexShape_SetTexture(sfConvexShape* shape, const sfTexture* texture, sfBool resetRect)
{
CSFML_CALL(shape, SetTexture(texture ? texture->This : NULL, resetRect == sfTrue))
CSFML_CALL(shape, SetTexture(texture ? texture->This : NULL, resetRect == sfTrue));
shape->Texture = texture;
}
@@ -183,7 +183,7 @@ void sfConvexShape_SetTexture(sfConvexShape* shape, const sfTexture* texture, sf
////////////////////////////////////////////////////////////
void sfConvexShape_SetTextureRect(sfConvexShape* shape, sfIntRect rect)
{
CSFML_CALL(shape, SetTextureRect(sf::IntRect(rect.Left, rect.Top, rect.Width, rect.Height)))
CSFML_CALL(shape, SetTextureRect(sf::IntRect(rect.Left, rect.Top, rect.Width, rect.Height)));
}
@@ -211,7 +211,7 @@ void sfConvexShape_SetOutlineThickness(sfConvexShape* shape, float thickness)
////////////////////////////////////////////////////////////
const sfTexture* sfConvexShape_GetTexture(const sfConvexShape* shape)
{
CSFML_CHECK_RETURN(shape, NULL)
CSFML_CHECK_RETURN(shape, NULL);
return shape->Texture;
}
@@ -221,7 +221,7 @@ const sfTexture* sfConvexShape_GetTexture(const sfConvexShape* shape)
sfIntRect sfConvexShape_GetTextureRect(const sfConvexShape* shape)
{
sfIntRect rect = {0, 0, 0, 0};
CSFML_CHECK_RETURN(sprite, rect)
CSFML_CHECK_RETURN(shape, rect);
sf::IntRect sfmlRect = shape->This.GetTextureRect();
rect.Left = sfmlRect.Left;
+6 -6
View File
@@ -35,12 +35,12 @@
////////////////////////////////////////////////////////////
sfBool sfFloatRect_Contains(const sfFloatRect* rect, float x, float y)
{
CSFML_CHECK_RETURN(rect, sfFalse)
CSFML_CHECK_RETURN(rect, sfFalse);
return sf::FloatRect(rect->Left, rect->Top, rect->Width, rect->Height).Contains(x, y);
}
sfBool sfIntRect_Contains(const sfIntRect* rect, int x, int y)
{
CSFML_CHECK_RETURN(rect, sfFalse)
CSFML_CHECK_RETURN(rect, sfFalse);
return sf::IntRect(rect->Left, rect->Top, rect->Width, rect->Height).Contains(x, y);
}
@@ -50,8 +50,8 @@ sfBool sfIntRect_Contains(const sfIntRect* rect, int x, int y)
////////////////////////////////////////////////////////////
sfBool sfFloatRect_Intersects(const sfFloatRect* rect1, const sfFloatRect* rect2, sfFloatRect* intersection)
{
CSFML_CHECK_RETURN(rect1, sfFalse)
CSFML_CHECK_RETURN(rect2, sfFalse)
CSFML_CHECK_RETURN(rect1, sfFalse);
CSFML_CHECK_RETURN(rect2, sfFalse);
sf::FloatRect SFMLRect1(rect1->Left, rect1->Top, rect1->Width, rect1->Height);
sf::FloatRect SFMLRect2(rect2->Left, rect2->Top, rect2->Width, rect2->Height);
@@ -75,8 +75,8 @@ sfBool sfFloatRect_Intersects(const sfFloatRect* rect1, const sfFloatRect* rect2
}
sfBool sfIntRect_Intersects(const sfIntRect* rect1, const sfIntRect* rect2, sfIntRect* intersection)
{
CSFML_CHECK_RETURN(rect1, sfFalse)
CSFML_CHECK_RETURN(rect2, sfFalse)
CSFML_CHECK_RETURN(rect1, sfFalse);
CSFML_CHECK_RETURN(rect2, sfFalse);
sf::IntRect SFMLRect1(rect1->Left, rect1->Top, rect1->Width, rect1->Height);
sf::IntRect SFMLRect2(rect2->Left, rect2->Top, rect2->Width, rect2->Height);
+4 -4
View File
@@ -175,7 +175,7 @@ const sfTransform* sfRectangleShape_GetInverseTransform(const sfRectangleShape*
////////////////////////////////////////////////////////////
void sfRectangleShape_SetTexture(sfRectangleShape* shape, const sfTexture* texture, sfBool resetRect)
{
CSFML_CALL(shape, SetTexture(texture ? texture->This : NULL, resetRect == sfTrue))
CSFML_CALL(shape, SetTexture(texture ? texture->This : NULL, resetRect == sfTrue));
shape->Texture = texture;
}
@@ -183,7 +183,7 @@ void sfRectangleShape_SetTexture(sfRectangleShape* shape, const sfTexture* textu
////////////////////////////////////////////////////////////
void sfRectangleShape_SetTextureRect(sfRectangleShape* shape, sfIntRect rect)
{
CSFML_CALL(shape, SetTextureRect(sf::IntRect(rect.Left, rect.Top, rect.Width, rect.Height)))
CSFML_CALL(shape, SetTextureRect(sf::IntRect(rect.Left, rect.Top, rect.Width, rect.Height)));
}
@@ -211,7 +211,7 @@ void sfRectangleShape_SetOutlineThickness(sfRectangleShape* shape, float thickne
////////////////////////////////////////////////////////////
const sfTexture* sfRectangleShape_GetTexture(const sfRectangleShape* shape)
{
CSFML_CHECK_RETURN(shape, NULL)
CSFML_CHECK_RETURN(shape, NULL);
return shape->Texture;
}
@@ -221,7 +221,7 @@ const sfTexture* sfRectangleShape_GetTexture(const sfRectangleShape* shape)
sfIntRect sfRectangleShape_GetTextureRect(const sfRectangleShape* shape)
{
sfIntRect rect = {0, 0, 0, 0};
CSFML_CHECK_RETURN(sprite, rect)
CSFML_CHECK_RETURN(shape, rect);
sf::IntRect sfmlRect = shape->This.GetTextureRect();
rect.Left = sfmlRect.Left;
+2 -2
View File
@@ -75,14 +75,14 @@ unsigned int sfRenderTexture_GetHeight(const sfRenderTexture* renderTexture)
////////////////////////////////////////////////////////////
sfBool sfRenderTexture_SetActive(sfRenderTexture* renderTexture, sfBool active)
{
CSFML_CALL_RETURN(renderTexture, SetActive(active == sfTrue), sfFalse)
CSFML_CALL_RETURN(renderTexture, SetActive(active == sfTrue), sfFalse);
}
////////////////////////////////////////////////////////////
void sfRenderTexture_Display(sfRenderTexture* renderTexture)
{
CSFML_CALL(renderTexture, Display())
CSFML_CALL(renderTexture, Display());
}
+4 -4
View File
@@ -206,14 +206,14 @@ void sfRenderWindow_SetPosition(sfRenderWindow* renderWindow, int left, int top)
////////////////////////////////////////////////////////////
void sfRenderWindow_SetSize(sfRenderWindow* renderWindow, unsigned int width, unsigned int height)
{
CSFML_CALL(renderWindow, SetSize(width, height))
CSFML_CALL(renderWindow, SetSize(width, height));
}
////////////////////////////////////////////////////////////
void sfRenderWindow_SetTitle(sfRenderWindow* renderWindow, const char* title)
{
CSFML_CALL(renderWindow, SetTitle(title))
CSFML_CALL(renderWindow, SetTitle(title));
}
@@ -234,14 +234,14 @@ void sfRenderWindow_EnableKeyRepeat(sfRenderWindow* renderWindow, sfBool enabled
////////////////////////////////////////////////////////////
void sfRenderWindow_SetIcon(sfRenderWindow* renderWindow, unsigned int width, unsigned int height, const sfUint8* pixels)
{
CSFML_CALL(renderWindow, SetIcon(width, height, pixels))
CSFML_CALL(renderWindow, SetIcon(width, height, pixels));
}
////////////////////////////////////////////////////////////
sfBool sfRenderWindow_SetActive(sfRenderWindow* renderWindow, sfBool active)
{
CSFML_CALL_RETURN(renderWindow, SetActive(active == sfTrue), sfFalse)
CSFML_CALL_RETURN(renderWindow, SetActive(active == sfTrue), sfFalse);
}
+10 -10
View File
@@ -149,42 +149,42 @@ void sfShader_Destroy(sfShader* shader)
////////////////////////////////////////////////////////////
void sfShader_SetFloatParameter(sfShader* shader, const char* name, float x)
{
CSFML_CALL(shader, SetParameter(name, x))
CSFML_CALL(shader, SetParameter(name, x));
}
////////////////////////////////////////////////////////////
void sfShader_SetFloat2Parameter(sfShader* shader, const char* name, float x, float y)
{
CSFML_CALL(shader, SetParameter(name, x, y))
CSFML_CALL(shader, SetParameter(name, x, y));
}
////////////////////////////////////////////////////////////
void sfShader_SetFloat3Parameter(sfShader* shader, const char* name, float x, float y, float z)
{
CSFML_CALL(shader, SetParameter(name, x, y, z))
CSFML_CALL(shader, SetParameter(name, x, y, z));
}
////////////////////////////////////////////////////////////
void sfShader_SetFloat4Parameter(sfShader* shader, const char* name, float x, float y, float z, float w)
{
CSFML_CALL(shader, SetParameter(name, x, y, z, w))
CSFML_CALL(shader, SetParameter(name, x, y, z, w));
}
////////////////////////////////////////////////////////////
void sfShader_SetColorParameter(sfShader* shader, const char* name, sfColor color)
{
CSFML_CALL(shader, SetParameter(name, sf::Color(color.r, color.g, color.b, color.a)))
CSFML_CALL(shader, SetParameter(name, sf::Color(color.r, color.g, color.b, color.a)));
}
////////////////////////////////////////////////////////////
void sfShader_SetTransformParameter(sfShader* shader, const char* name, const sfTransform* transform)
{
CSFML_CALL(shader, SetParameter(name, transform ? transform->This : sf::Transform::Identity))
CSFML_CALL(shader, SetParameter(name, transform ? transform->This : sf::Transform::Identity));
}
@@ -192,28 +192,28 @@ void sfShader_SetTransformParameter(sfShader* shader, const char* name, const sf
void sfShader_SetTextureParameter(sfShader* shader, const char* name, const sfTexture* texture)
{
CSFML_CHECK(texture);
CSFML_CALL(shader, SetParameter(name, *texture->This))
CSFML_CALL(shader, SetParameter(name, *texture->This));
}
////////////////////////////////////////////////////////////
void sfShader_SetCurrentTextureParameter(sfShader* shader, const char* name)
{
CSFML_CALL(shader, SetParameter(name, sf::Shader::CurrentTexture))
CSFML_CALL(shader, SetParameter(name, sf::Shader::CurrentTexture));
}
////////////////////////////////////////////////////////////
void sfShader_Bind(const sfShader* shader)
{
CSFML_CALL(shader, Bind())
CSFML_CALL(shader, Bind());
}
////////////////////////////////////////////////////////////
void sfShader_Unbind(const sfShader* shader)
{
CSFML_CALL(shader, Unbind())
CSFML_CALL(shader, Unbind());
}
+4 -4
View File
@@ -181,7 +181,7 @@ void sfSprite_SetTexture(sfSprite* sprite, const sfTexture* texture, sfBool rese
{
if (texture && texture->This)
{
CSFML_CALL(sprite, SetTexture(*texture->This, resetRect == sfTrue))
CSFML_CALL(sprite, SetTexture(*texture->This, resetRect == sfTrue));
sprite->Texture = texture;
}
}
@@ -190,7 +190,7 @@ void sfSprite_SetTexture(sfSprite* sprite, const sfTexture* texture, sfBool rese
////////////////////////////////////////////////////////////
void sfSprite_SetTextureRect(sfSprite* sprite, sfIntRect rectangle)
{
CSFML_CALL(sprite, SetTextureRect(sf::IntRect(rectangle.Left, rectangle.Top, rectangle.Width, rectangle.Height)))
CSFML_CALL(sprite, SetTextureRect(sf::IntRect(rectangle.Left, rectangle.Top, rectangle.Width, rectangle.Height)));
}
@@ -204,7 +204,7 @@ void sfSprite_SetColor(sfSprite* sprite, sfColor color)
////////////////////////////////////////////////////////////
const sfTexture* sfSprite_GetTexture(const sfSprite* sprite)
{
CSFML_CHECK_RETURN(sprite, NULL)
CSFML_CHECK_RETURN(sprite, NULL);
return sprite->Texture;
}
@@ -214,7 +214,7 @@ const sfTexture* sfSprite_GetTexture(const sfSprite* sprite)
sfIntRect sfSprite_GetTextureRect(const sfSprite* sprite)
{
sfIntRect rect = {0, 0, 0, 0};
CSFML_CHECK_RETURN(sprite, rect)
CSFML_CHECK_RETURN(sprite, rect);
sf::IntRect sfmlRect = sprite->This.GetTextureRect();
rect.Left = sfmlRect.Left;
+10 -10
View File
@@ -179,7 +179,7 @@ const sfTransform* sfText_GetInverseTransform(const sfText* text)
////////////////////////////////////////////////////////////
void sfText_SetString(sfText* text, const char* string)
{
CSFML_CALL(text, SetString(string))
CSFML_CALL(text, SetString(string));
}
@@ -187,7 +187,7 @@ void sfText_SetString(sfText* text, const char* string)
void sfText_SetUnicodeString(sfText* text, const sfUint32* string)
{
sf::String UTF32Text = string;
CSFML_CALL(text, SetString(UTF32Text))
CSFML_CALL(text, SetString(UTF32Text));
}
@@ -196,7 +196,7 @@ void sfText_SetFont(sfText* text, const sfFont* font)
{
CSFML_CHECK(font);
CSFML_CALL(text, SetFont(font->This))
CSFML_CALL(text, SetFont(font->This));
text->Font = font;
}
@@ -204,21 +204,21 @@ void sfText_SetFont(sfText* text, const sfFont* font)
////////////////////////////////////////////////////////////
void sfText_SetCharacterSize(sfText* text, unsigned int size)
{
CSFML_CALL(text, SetCharacterSize(size))
CSFML_CALL(text, SetCharacterSize(size));
}
////////////////////////////////////////////////////////////
void sfText_SetStyle(sfText* text, sfUint32 style)
{
CSFML_CALL(text, SetStyle(style))
CSFML_CALL(text, SetStyle(style));
}
////////////////////////////////////////////////////////////
const char* sfText_GetString(const sfText* text)
{
CSFML_CHECK_RETURN(text, NULL)
CSFML_CHECK_RETURN(text, NULL);
text->String = text->This.GetString().ToAnsiString();
@@ -229,7 +229,7 @@ const char* sfText_GetString(const sfText* text)
////////////////////////////////////////////////////////////
const sfUint32* sfText_GetUnicodeString(const sfText* text)
{
CSFML_CHECK_RETURN(text, NULL)
CSFML_CHECK_RETURN(text, NULL);
return text->This.GetString().GetData();
}
@@ -238,7 +238,7 @@ const sfUint32* sfText_GetUnicodeString(const sfText* text)
////////////////////////////////////////////////////////////
const sfFont* sfText_GetFont(const sfText* text)
{
CSFML_CHECK_RETURN(text, NULL)
CSFML_CHECK_RETURN(text, NULL);
return text->Font;
}
@@ -247,14 +247,14 @@ const sfFont* sfText_GetFont(const sfText* text)
////////////////////////////////////////////////////////////
unsigned int sfText_GetCharacterSize(const sfText* text)
{
CSFML_CALL_RETURN(text, GetCharacterSize(), 0)
CSFML_CALL_RETURN(text, GetCharacterSize(), 0);
}
////////////////////////////////////////////////////////////
sfUint32 sfText_GetStyle(const sfText* text)
{
CSFML_CALL_RETURN(text, GetStyle(), 0)
CSFML_CALL_RETURN(text, GetStyle(), 0);
}
+87 -58
View File
@@ -26,82 +26,111 @@
#define SFML_INTERNAL_H
////////////////////////////////////////////////////////////
// Define macros to check the validity of CSFML objects
// in debug run
// Define macros to check the validity of CSFML objects in debug run
////////////////////////////////////////////////////////////
#include <stdio.h>
// this macro avoids the C4127 warning on VC++ ("conditional expression is constant")
#define ASSERT_FALSE (__LINE__ == -1)
#ifndef NDEBUG
#define CSFML_CHECK(Object) \
if (Object == NULL) \
{ \
fprintf(stderr, "SFML warning : trying to use a null " #Object " object\n"); \
return; \
}
#define CSFML_CHECK(object_) \
do \
{ \
if (object_ == NULL) \
{ \
fprintf(stderr, "SFML warning: trying to use a null " #object_ " object\n"); \
return; \
} \
} \
while (ASSERT_FALSE)
#define CSFML_CALL(Object, Function) \
if (Object) \
{ \
(Object->This.Function); \
} \
else \
{ \
fprintf(stderr, "SFML warning : trying to use a null " #Object " object\n"); \
} \
#define CSFML_CALL(object_, function_) \
do \
{ \
if (object_) \
{ \
(object_->This.function_); \
} \
else \
{ \
fprintf(stderr, "SFML warning: trying to use a null " #object_ " object\n"); \
} \
} \
while (ASSERT_FALSE)
#define CSFML_CALL_PTR(Object, Function) \
if (Object) \
{ \
(Object->This->Function); \
} \
else \
{ \
fprintf(stderr, "SFML warning : trying to use a null " #Object " object\n"); \
} \
#define CSFML_CALL_PTR(object_, function_) \
do \
{ \
if (object_) \
{ \
(object_->This->function_); \
} \
else \
{ \
fprintf(stderr, "SFML warning: trying to use a null " #object_ " object\n"); \
} \
} \
while (ASSERT_FALSE)
#define CSFML_CHECK_RETURN(Object, Default) \
if (Object == NULL) \
{ \
fprintf(stderr, "SFML warning : trying to use a null " #Object " object\n"); \
return Default; \
}
#define CSFML_CHECK_RETURN(object_, default_) \
do \
{ \
if (object_ == NULL) \
{ \
fprintf(stderr, "SFML warning: trying to use a null " #object_ " object\n"); \
return default_; \
} \
} \
while (ASSERT_FALSE)
#define CSFML_CALL_RETURN(Object, Function, Default) \
if (Object) \
{ \
return (Object->This.Function); \
} \
else \
{ \
fprintf(stderr, "SFML warning : trying to use a null " #Object " object\n"); \
return Default; \
} \
#define CSFML_CALL_RETURN(object_, function_, default_) \
if (object_) \
{ \
return (object_->This.function_); \
} \
else \
{ \
fprintf(stderr, "SFML warning: trying to use a null " #object_ " object\n"); \
return default_; \
}
#define CSFML_CALL_PTR_RETURN(Object, Function, Default) \
if (Object) \
{ \
return (Object->This->Function); \
} \
else \
{ \
fprintf(stderr, "SFML warning : trying to use a null " #Object " object\n"); \
return Default; \
} \
#define CSFML_CALL_PTR_RETURN(object_, function_, default_) \
if (object_) \
{ \
return (object_->This->function_); \
} \
else \
{ \
fprintf(stderr, "SFML warning: trying to use a null " #object_ " object\n"); \
return default_; \
}
#else
#define CSFML_CHECK(Object)
#define CSFML_CHECK(object_)
#define CSFML_CALL(Object, Function) (Object->This.Function);
#define CSFML_CALL(object_, function_) \
(object_->This.function_)
#define CSFML_CALL_PTR(Object, Function) (Object->This->Function);
#define CSFML_CALL_PTR(object_, function_) \
(object_->This->function_)
#define CSFML_CHECK_RETURN(Object, Default) (void)Default;
#define CSFML_CHECK_RETURN(object_, default_) \
(void)default_;
#define CSFML_CALL_RETURN(Object, Function, Default) (void)Default; return (Object->This.Function);
#define CSFML_CALL_RETURN(object_, function_, default_) \
{ \
(void)default_; \
return (object_->This.function_); \
}
#define CSFML_CALL_PTR_RETURN(Object, Function, Default) (void)Default; return (Object->This->Function);
#define CSFML_CALL_PTR_RETURN(object_, function_, default_) \
{ \
(void)default_; \
return (object_->This->function_); \
}
#endif
+104 -48
View File
@@ -30,30 +30,6 @@
#include <SFML/Internal.h>
namespace
{
// Helper function to read a variable from a packet
template <typename T>
T PacketRead(sfPacket* packet)
{
CSFML_CHECK_RETURN(packet, 0);
T value;
packet->This >> value;
return value;
}
// Helper function to write a variable to a packet
template <typename T>
void PacketWrite(sfPacket* packet, T value)
{
CSFML_CHECK(packet);
packet->This << value;
}
}
////////////////////////////////////////////////////////////
sfPacket* sfPacket_Create(void)
{
@@ -121,44 +97,125 @@ sfBool sfPacket_CanRead(const sfPacket* packet)
////////////////////////////////////////////////////////////
sfBool sfPacket_ReadBool(sfPacket* packet) {return PacketRead<sfUint8>(packet);}
sfInt8 sfPacket_ReadInt8(sfPacket* packet) {return PacketRead<sfInt8>(packet);}
sfUint8 sfPacket_ReadUint8(sfPacket* packet) {return PacketRead<sfUint8>(packet);}
sfInt16 sfPacket_ReadInt16(sfPacket* packet) {return PacketRead<sfInt16>(packet);}
sfUint16 sfPacket_ReadUint16(sfPacket* packet) {return PacketRead<sfUint16>(packet);}
sfInt32 sfPacket_ReadInt32(sfPacket* packet) {return PacketRead<sfInt32>(packet);}
sfUint32 sfPacket_ReadUint32(sfPacket* packet) {return PacketRead<sfUint32>(packet);}
float sfPacket_ReadFloat(sfPacket* packet) {return PacketRead<float>(packet);}
double sfPacket_ReadDouble(sfPacket* packet) {return PacketRead<double>(packet);}
sfBool sfPacket_ReadBool(sfPacket* packet)
{
return sfPacket_ReadUint8(packet);
}
sfInt8 sfPacket_ReadInt8(sfPacket* packet)
{
CSFML_CHECK_RETURN(packet, sfFalse);
sfInt8 value;
packet->This >> value;
return value;
}
sfUint8 sfPacket_ReadUint8(sfPacket* packet)
{
CSFML_CHECK_RETURN(packet, sfFalse);
sfUint8 value;
packet->This >> value;
return value;
}
sfInt16 sfPacket_ReadInt16(sfPacket* packet)
{
CSFML_CHECK_RETURN(packet, sfFalse);
sfInt16 value;
packet->This >> value;
return value;
}
sfUint16 sfPacket_ReadUint16(sfPacket* packet)
{
CSFML_CHECK_RETURN(packet, sfFalse);
sfUint16 value;
packet->This >> value;
return value;
}
sfInt32 sfPacket_ReadInt32(sfPacket* packet)
{
CSFML_CHECK_RETURN(packet, sfFalse);
sfInt32 value;
packet->This >> value;
return value;
}
sfUint32 sfPacket_ReadUint32(sfPacket* packet)
{
CSFML_CHECK_RETURN(packet, sfFalse);
sfUint32 value;
packet->This >> value;
return value;
}
float sfPacket_ReadFloat(sfPacket* packet)
{
CSFML_CHECK_RETURN(packet, sfFalse);
float value;
packet->This >> value;
return value;
}
double sfPacket_ReadDouble(sfPacket* packet)
{
CSFML_CHECK_RETURN(packet, sfFalse);
double value;
packet->This >> value;
return value;
}
void sfPacket_ReadString(sfPacket* packet, char* string)
{
CSFML_CHECK(packet);
if (string)
packet->This >> string;
}
void sfPacket_ReadWideString(sfPacket* packet, wchar_t* string)
{
CSFML_CHECK(packet);
if (string)
packet->This >> string;
}
////////////////////////////////////////////////////////////
void sfPacket_WriteBool(sfPacket* packet, sfBool value) {PacketWrite(packet, static_cast<sfUint8>(value));}
void sfPacket_WriteInt8(sfPacket* packet, sfInt8 value) {PacketWrite(packet, value);}
void sfPacket_WriteUint8(sfPacket* packet, sfUint8 value) {PacketWrite(packet, value);}
void sfPacket_WriteInt16(sfPacket* packet, sfInt16 value) {PacketWrite(packet, value);}
void sfPacket_WriteUint16(sfPacket* packet, sfUint16 value) {PacketWrite(packet, value);}
void sfPacket_WriteInt32(sfPacket* packet, sfInt32 value) {PacketWrite(packet, value);}
void sfPacket_WriteUint32(sfPacket* packet, sfUint32 value) {PacketWrite(packet, value);}
void sfPacket_WriteFloat(sfPacket* packet, float value) {PacketWrite(packet, value);}
void sfPacket_WriteDouble(sfPacket* packet, double value) {PacketWrite(packet, value);}
void sfPacket_WriteBool(sfPacket* packet, sfBool value)
{
sfPacket_WriteUint8(packet, value ? 1 : 0);
}
void sfPacket_WriteInt8(sfPacket* packet, sfInt8 value)
{
CSFML_CHECK(packet);
packet->This << value;
}
void sfPacket_WriteUint8(sfPacket* packet, sfUint8 value)
{
CSFML_CHECK(packet);
packet->This << value;
}
void sfPacket_WriteInt16(sfPacket* packet, sfInt16 value)
{
CSFML_CHECK(packet);
packet->This << value;
}
void sfPacket_WriteUint16(sfPacket* packet, sfUint16 value)
{
CSFML_CHECK(packet);
packet->This << value;
}
void sfPacket_WriteInt32(sfPacket* packet, sfInt32 value)
{
CSFML_CHECK(packet);
packet->This << value;
}
void sfPacket_WriteUint32(sfPacket* packet, sfUint32 value)
{
CSFML_CHECK(packet);
packet->This << value;
}
void sfPacket_WriteFloat(sfPacket* packet, float value)
{
CSFML_CHECK(packet);
packet->This << value;
}
void sfPacket_WriteDouble(sfPacket* packet, double value)
{
CSFML_CHECK(packet);
packet->This << value;
}
void sfPacket_WriteString(sfPacket* packet, const char* string)
{
CSFML_CHECK(packet);
@@ -166,7 +223,6 @@ void sfPacket_WriteString(sfPacket* packet, const char* string)
if (string)
packet->This << string;
}
void sfPacket_WriteWideString(sfPacket* packet, const wchar_t* string)
{
CSFML_CHECK(packet);
+1 -1
View File
@@ -71,7 +71,7 @@ unsigned short sfTcpSocket_GetLocalPort(const sfTcpSocket* socket)
////////////////////////////////////////////////////////////
sfIpAddress sfTcpSocket_GetRemoteAddress(const sfTcpSocket* socket)
{
sfIpAddress result;
sfIpAddress result = sfIpAddress_None();
CSFML_CHECK_RETURN(socket, result);
sf::IpAddress address = socket->This.GetRemoteAddress();
+1 -1
View File
@@ -86,7 +86,7 @@ void sfUdpSocket_Unbind(sfUdpSocket* socket)
////////////////////////////////////////////////////////////
sfSocketStatus sfUdpSocket_Send(sfUdpSocket* socket, const char* data, size_t size, sfIpAddress address, unsigned short port)
{
CSFML_CHECK_RETURN(socket, sfSocketError)
CSFML_CHECK_RETURN(socket, sfSocketError);
// Convert the address
sf::IpAddress receiver(address.Address);
+2 -2
View File
@@ -47,12 +47,12 @@ void sfMutex_Destroy(sfMutex* mutex)
////////////////////////////////////////////////////////////
void sfMutex_Lock(sfMutex* mutex)
{
CSFML_CALL(mutex, Lock())
CSFML_CALL(mutex, Lock());
}
////////////////////////////////////////////////////////////
void sfMutex_Unlock(sfMutex* mutex)
{
CSFML_CALL(mutex, Unlock())
CSFML_CALL(mutex, Unlock());
}
+1 -1
View File
@@ -47,5 +47,5 @@ void sfContext_Destroy(sfContext* context)
////////////////////////////////////////////////////////////
void sfContext_SetActive(sfContext* context, sfBool active)
{
CSFML_CALL(context, SetActive(active == sfTrue))
CSFML_CALL(context, SetActive(active == sfTrue));
}
+14 -14
View File
@@ -101,14 +101,14 @@ sfBool sfWindow_IsOpen(const sfWindow* window)
////////////////////////////////////////////////////////////
unsigned int sfWindow_GetWidth(const sfWindow* window)
{
CSFML_CALL_RETURN(window, GetWidth(), 0)
CSFML_CALL_RETURN(window, GetWidth(), 0);
}
////////////////////////////////////////////////////////////
unsigned int sfWindow_GetHeight(const sfWindow* window)
{
CSFML_CALL_RETURN(window, GetHeight(), 0)
CSFML_CALL_RETURN(window, GetHeight(), 0);
}
@@ -174,84 +174,84 @@ sfBool sfWindow_WaitEvent(sfWindow* window, sfEvent* event)
////////////////////////////////////////////////////////////
void sfWindow_EnableVerticalSync(sfWindow* window, sfBool enabled)
{
CSFML_CALL(window, EnableVerticalSync(enabled == sfTrue))
CSFML_CALL(window, EnableVerticalSync(enabled == sfTrue));
}
////////////////////////////////////////////////////////////
void sfWindow_ShowMouseCursor(sfWindow* window, sfBool show)
{
CSFML_CALL(window, ShowMouseCursor(show == sfTrue))
CSFML_CALL(window, ShowMouseCursor(show == sfTrue));
}
////////////////////////////////////////////////////////////
void sfWindow_SetPosition(sfWindow* window, int left, int top)
{
CSFML_CALL(window, SetPosition(left, top))
CSFML_CALL(window, SetPosition(left, top));
}
////////////////////////////////////////////////////////////
void sfWindow_SetSize(sfWindow* window, unsigned int width, unsigned int height)
{
CSFML_CALL(window, SetSize(width, height))
CSFML_CALL(window, SetSize(width, height));
}
////////////////////////////////////////////////////////////
void sfWindow_SetTitle(sfWindow* window, const char* title)
{
CSFML_CALL(window, SetTitle(title))
CSFML_CALL(window, SetTitle(title));
}
////////////////////////////////////////////////////////////
void sfWindow_Show(sfWindow* window, sfBool show)
{
CSFML_CALL(window, Show(show == sfTrue))
CSFML_CALL(window, Show(show == sfTrue));
}
////////////////////////////////////////////////////////////
void sfWindow_EnableKeyRepeat(sfWindow* window, sfBool enabled)
{
CSFML_CALL(window, EnableKeyRepeat(enabled == sfTrue))
CSFML_CALL(window, EnableKeyRepeat(enabled == sfTrue));
}
////////////////////////////////////////////////////////////
void sfWindow_SetIcon(sfWindow* window, unsigned int width, unsigned int height, const sfUint8* pixels)
{
CSFML_CALL(window, SetIcon(width, height, pixels))
CSFML_CALL(window, SetIcon(width, height, pixels));
}
////////////////////////////////////////////////////////////
sfBool sfWindow_SetActive(sfWindow* window, sfBool active)
{
CSFML_CALL_RETURN(window, SetActive(active == sfTrue), sfFalse)
CSFML_CALL_RETURN(window, SetActive(active == sfTrue), sfFalse);
}
////////////////////////////////////////////////////////////
void sfWindow_Display(sfWindow* window)
{
CSFML_CALL(window, Display())
CSFML_CALL(window, Display());
}
////////////////////////////////////////////////////////////
void sfWindow_SetFramerateLimit(sfWindow* window, unsigned int limit)
{
CSFML_CALL(window, SetFramerateLimit(limit))
CSFML_CALL(window, SetFramerateLimit(limit));
}
////////////////////////////////////////////////////////////
void sfWindow_SetJoystickThreshold(sfWindow* window, float threshold)
{
CSFML_CALL(window, SetJoystickThreshold(threshold))
CSFML_CALL(window, SetJoystickThreshold(threshold));
}