Skip to content

Commit

Permalink
CSFML: Get rid of "typedef struct" c-ism
Browse files Browse the repository at this point in the history
  • Loading branch information
crumblingstatue committed Oct 24, 2024
1 parent a425cd7 commit 2fc42e9
Show file tree
Hide file tree
Showing 8 changed files with 43 additions and 62 deletions.
9 changes: 4 additions & 5 deletions CSFML/src/Audio/Music.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,10 @@
#include <SFML/Audio/Music.hpp>
#include <cstddef>

typedef struct
{
int64_t offset; ///< The beginning offset of the time range
int64_t length; ///< The length of the time range
} sfTimeSpan;
struct sfTimeSpan {
int64_t offset;
int64_t length;
};

extern "C" sf::Music *sfMusic_new() {
return new sf::Music;
Expand Down
5 changes: 2 additions & 3 deletions CSFML/src/Graphics/Color.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,11 @@

#include <cstdint>

typedef struct
{
struct sfColor {
uint8_t r;
uint8_t g;
uint8_t b;
uint8_t a;
} sfColor;
};

#endif // SFML_COLOR_H
10 changes: 4 additions & 6 deletions CSFML/src/Graphics/Font.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,11 @@
#include <SFML/Graphics/Font.hpp>
#include <cstddef>

typedef struct
{
struct sfGlyph {
float advance; ///< Offset to move horizontically to the next character
sfFloatRect bounds; ///< Bounding rectangle of the glyph, in coordinates relative to the baseline
sfIntRect textureRect; ///< Texture coordinates of the glyph inside the font's image
} sfGlyph;
};

extern "C" sf::Font *sfFont_new() {
return new sf::Font;
Expand Down Expand Up @@ -74,10 +73,9 @@ extern "C" void sfFont_setSmooth(sf::Font *font, bool smooth) {
font->setSmooth(smooth);
}

typedef struct
{
struct sfFontInfo {
const char *family;
} sfFontInfo;
};

extern "C" sfFontInfo sfFont_getInfo(const sf::Font *font) {
return {font->getInfo().family.c_str()};
Expand Down
10 changes: 4 additions & 6 deletions CSFML/src/Graphics/Rect.hpp
Original file line number Diff line number Diff line change
@@ -1,20 +1,18 @@
#ifndef SFML_RECT_H
#define SFML_RECT_H

typedef struct
{
struct sfFloatRect {
float left;
float top;
float width;
float height;
} sfFloatRect;
};

typedef struct
{
struct sfIntRect {
int left;
int top;
int width;
int height;
} sfIntRect;
};

#endif // SFML_RECT_H
40 changes: 16 additions & 24 deletions CSFML/src/Graphics/Shader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,64 +8,56 @@
typedef sfVector2f sfGlslVec2;
typedef sfVector2i sfGlslIvec2;

typedef struct
{
struct sfGlslBvec2 {
bool x;
bool y;
} sfGlslBvec2;
};

// 3D vectors
typedef sfVector3f sfGlslVec3;

typedef struct
{
struct sfGlslIvec3 {
int x;
int y;
int z;
} sfGlslIvec3;
};

typedef struct
{
struct sfGlslBvec3 {
bool x;
bool y;
bool z;
} sfGlslBvec3;
};

// 4D vectors
typedef struct
{
struct sfGlslVec4 {
float x;
float y;
float z;
float w;
} sfGlslVec4;
};

typedef struct
{
struct sfGlslIvec4 {
int x;
int y;
int z;
int w;
} sfGlslIvec4;
};

typedef struct
{
struct sfGlslBvec4 {
bool x;
bool y;
bool z;
bool w;
} sfGlslBvec4;
};

// matrices
typedef struct
{
struct sfGlslMat3 {
float array[3 * 3];
} sfGlslMat3;
};

typedef struct
{
struct sfGlslMat4 {
float array[4 * 4];
} sfGlslMat4;
};

extern "C" sf::Shader *sfShader_new() {
return new sf::Shader;
Expand Down
15 changes: 6 additions & 9 deletions CSFML/src/System/Vector2.hpp
Original file line number Diff line number Diff line change
@@ -1,22 +1,19 @@
#ifndef SFML_VECTOR2_H
#define SFML_VECTOR2_H

typedef struct
{
struct sfVector2i {
int x;
int y;
} sfVector2i;
};

typedef struct
{
struct sfVector2u {
unsigned int x;
unsigned int y;
} sfVector2u;
};

typedef struct
{
struct sfVector2f {
float x;
float y;
} sfVector2f;
};

#endif // SFML_VECTOR2_H
5 changes: 2 additions & 3 deletions CSFML/src/System/Vector3.hpp
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
#ifndef SFML_VECTOR3_H
#define SFML_VECTOR3_H

typedef struct
{
struct sfVector3f {
float x;
float y;
float z;
} sfVector3f;
};

#endif // SFML_VECTOR3_H
11 changes: 5 additions & 6 deletions CSFML/src/Window/VideoMode.hpp
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
#ifndef SFML_VIDEOMODE_H
#define SFML_VIDEOMODE_H

typedef struct
{
unsigned int width; ///< Video mode width, in pixels
unsigned int height; ///< Video mode height, in pixels
unsigned int bitsPerPixel; ///< Video mode pixel depth, in bits per pixels
} sfVideoMode;
struct sfVideoMode {
unsigned int width;
unsigned int height;
unsigned int bitsPerPixel;
};

#endif // SFML_VIDEOMODE_H

0 comments on commit 2fc42e9

Please sign in to comment.