Skip to content

Commit

Permalink
Fix many warnings (mostly sign conversion)
Browse files Browse the repository at this point in the history
  • Loading branch information
Flamefire committed Mar 13, 2019
1 parent 8028b25 commit 0a72cb1
Show file tree
Hide file tree
Showing 14 changed files with 234 additions and 275 deletions.
4 changes: 2 additions & 2 deletions CIO/CFont.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ bool CFont::writeText(SDL_Surface* Surf_Dest, const char* string, int x, int y,
// the index for the chiffre-picture in the global::bmpArray
unsigned int chiffre_index = 0;
// pointer to the chiffres
unsigned char* chiffre = (unsigned char*)string;
auto* chiffre = (const unsigned char*)string;
// counter for the drawed pixels (cause we dont want to draw outside of the surface)
int pos_x = x;
int pos_y = y;
Expand Down Expand Up @@ -450,7 +450,7 @@ bool CFont::writeText(SDL_Surface* Surf_Dest, const char* string, int x, int y,
// if this was the last chiffre go in normal mode and write the text to the specified position
if(*chiffre == '\0')
{
chiffre = (unsigned char*)string;
chiffre = (const unsigned char*)string;

if(align == ALIGN_MIDDLE)
pos_x = x - (unsigned int)(pixel_ctr_w / 2);
Expand Down
4 changes: 2 additions & 2 deletions CSurface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ void CSurface::DrawPixel_Color(SDL_Surface* screen, int x, int y, Uint32 color)
case 2: *(Uint16*)p = color; break;

case 3:
if(SDL_BYTEORDER == SDL_LIL_ENDIAN)
if((SDL_BYTEORDER) == SDL_LIL_ENDIAN)
{
p[0] = color;
p[1] = color >> 8;
Expand Down Expand Up @@ -169,7 +169,7 @@ Uint32 CSurface::GetPixel(SDL_Surface* surface, int x, int y)
case 2: return *(Uint16*)p;

case 3:
if(SDL_BYTEORDER == SDL_BIG_ENDIAN)
if((SDL_BYTEORDER) == SDL_BIG_ENDIAN)
return p[0] << 16 | p[1] << 8 | p[2];
else
return p[0] | p[1] << 8 | p[2] << 16;
Expand Down
199 changes: 75 additions & 124 deletions SGE/sge_blib.cpp

Large diffs are not rendered by default.

17 changes: 9 additions & 8 deletions SGE/sge_bm_text.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ sge_bmpFont* sge_BF_OpenFont(char* file, Uint8 flags)
// Draws string to surface with the selected font
// Returns pos. and size of the drawn text
//==================================================================================
SDL_Rect sge_BF_textout(SDL_Surface* surface, sge_bmpFont* font, char* string, Sint16 x, Sint16 y)
SDL_Rect sge_BF_textout(SDL_Surface* surface, sge_bmpFont* font, const char* string, Sint16 x, Sint16 y)
{
SDL_Rect ret;
ret.x = 0;
Expand Down Expand Up @@ -283,7 +283,7 @@ SDL_Rect sge_BF_textout(SDL_Surface* surface, sge_bmpFont* font, char* string, S

ret.x = x;
ret.y = y;
ret.w = xdest - x + font->CharWidth;
ret.w = static_cast<Uint16>(xdest - x) + font->CharWidth;
ret.h = font->CharHeight;

if(surface)
Expand All @@ -295,7 +295,7 @@ SDL_Rect sge_BF_textout(SDL_Surface* surface, sge_bmpFont* font, char* string, S
//==================================================================================
// Returns the size (w and h) of the string (if rendered with font)
//==================================================================================
SDL_Rect sge_BF_TextSize(sge_bmpFont* font, char* string)
SDL_Rect sge_BF_TextSize(sge_bmpFont* font, const char* string)
{
return sge_BF_textout(nullptr, font, string, 0, 0);
}
Expand All @@ -305,7 +305,7 @@ SDL_Rect sge_BF_TextSize(sge_bmpFont* font, char* string)
// Returns pos. and size of the drawn text
// * just like printf(char *format, ...) *
//==================================================================================
SDL_Rect sge_BF_textoutf(SDL_Surface* surface, sge_bmpFont* font, Sint16 x, Sint16 y, char* format, ...)
SDL_Rect sge_BF_textoutf(SDL_Surface* surface, sge_bmpFont* font, Sint16 x, Sint16 y, const char* format, ...)
{
char buf[256];

Expand Down Expand Up @@ -464,7 +464,8 @@ void sge_BF_SetAlpha(sge_bmpFont* font, Uint8 alpha)
//==================================================================================
// BitmapText input
//==================================================================================
int sge_BF_inputAlpha(SDL_Surface* screen, sge_bmpFont* font, char* string, Uint8 flags, int pos, int len, Sint16 x, Sint16 y, int Alpha)
int sge_BF_inputAlpha(SDL_Surface* screen, sge_bmpFont* font, char* string, Uint8 flags, int pos, unsigned len, Sint16 x, Sint16 y,
int Alpha)
{
if(pos == 0 && len > 0)
string[0] = '\0';
Expand All @@ -481,7 +482,7 @@ int sge_BF_inputAlpha(SDL_Surface* screen, sge_bmpFont* font, char* string, Uint
return ret;
}

int sge_BF_inputAlpha_UNI(SDL_Surface* screen, sge_bmpFont* font, Uint16* string, Uint8 flags, int pos, int len, Sint16 x, Sint16 y,
int sge_BF_inputAlpha_UNI(SDL_Surface* screen, sge_bmpFont* font, Uint16* string, Uint8 flags, int pos, unsigned len, Sint16 x, Sint16 y,
int Alpha)
{
sge_TextSurface text(screen, "", x, y);
Expand All @@ -505,12 +506,12 @@ int sge_BF_inputAlpha_UNI(SDL_Surface* screen, sge_bmpFont* font, Uint16* string
return ret;
}

int sge_BF_input(SDL_Surface* screen, sge_bmpFont* font, char* string, Uint8 flags, int pos, int len, Sint16 x, Sint16 y)
int sge_BF_input(SDL_Surface* screen, sge_bmpFont* font, char* string, Uint8 flags, int pos, unsigned len, Sint16 x, Sint16 y)
{
return sge_BF_inputAlpha(screen, font, string, flags, pos, len, x, y, SDL_ALPHA_OPAQUE);
}

int sge_BF_input_UNI(SDL_Surface* screen, sge_bmpFont* font, Uint16* string, Uint8 flags, int pos, int len, Sint16 x, Sint16 y)
int sge_BF_input_UNI(SDL_Surface* screen, sge_bmpFont* font, Uint16* string, Uint8 flags, int pos, unsigned len, Sint16 x, Sint16 y)
{
return sge_BF_inputAlpha_UNI(screen, font, string, flags, pos, len, x, y, SDL_ALPHA_OPAQUE);
}
21 changes: 11 additions & 10 deletions SGE/sge_bm_text.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@
typedef struct
{
SDL_Surface* FontSurface;
Sint16 CharWidth;
Sint16 CharHeight;
Uint16 CharWidth;
Uint16 CharHeight;
Sint16* CharPos;
Sint16 yoffs;
Uint32 bcolor;
Expand All @@ -48,23 +48,24 @@ typedef struct
extern "C" {
#endif
DECLSPEC sge_bmpFont* sge_BF_CreateFont(SDL_Surface* surface, Uint8 flags);
DECLSPEC sge_bmpFont* sge_BF_OpenFont(char* file, Uint8 flags);
DECLSPEC sge_bmpFont* sge_BF_OpenFont(const char* file, Uint8 flags);
DECLSPEC void sge_BF_CloseFont(sge_bmpFont* font);
DECLSPEC void sge_BF_SetColor(sge_bmpFont* font, Uint8 R, Uint8 G, Uint8 B);
DECLSPEC void sge_BF_SetAlpha(sge_bmpFont* font, Uint8 alpha);
DECLSPEC Sint16 sge_BF_GetHeight(sge_bmpFont* font);
DECLSPEC Sint16 sge_BF_GetWidth(sge_bmpFont* font);
DECLSPEC SDL_Rect sge_BF_TextSize(sge_bmpFont* font, char* string);
DECLSPEC SDL_Rect sge_BF_TextSize(sge_bmpFont* font, const char* string);

DECLSPEC SDL_Rect sge_BF_textout(SDL_Surface* surface, sge_bmpFont* font, char* string, Sint16 x, Sint16 y);
DECLSPEC SDL_Rect sge_BF_textout(SDL_Surface* surface, sge_bmpFont* font, const char* string, Sint16 x, Sint16 y);
DECLSPEC __attribute__((format(printf, 5, 6))) SDL_Rect sge_BF_textoutf(SDL_Surface* surface, sge_bmpFont* font, Sint16 x, Sint16 y,
char* format, ...);
const char* format, ...);

DECLSPEC int sge_BF_input(SDL_Surface* screen, sge_bmpFont* font, char* string, Uint8 flags, int pos, int len, Sint16 x, Sint16 y);
DECLSPEC int sge_BF_inputAlpha(SDL_Surface* screen, sge_bmpFont* font, char* string, Uint8 flags, int pos, int len, Sint16 x, Sint16 y,
DECLSPEC int sge_BF_input(SDL_Surface* screen, sge_bmpFont* font, char* string, Uint8 flags, int pos, unsigned len, Sint16 x, Sint16 y);
DECLSPEC int sge_BF_inputAlpha(SDL_Surface* screen, sge_bmpFont* font, char* string, Uint8 flags, int pos, unsigned len, Sint16 x, Sint16 y,
int Alpha);
DECLSPEC int sge_BF_input_UNI(SDL_Surface* screen, sge_bmpFont* font, Uint16* string, Uint8 flags, int pos, int len, Sint16 x, Sint16 y);
DECLSPEC int sge_BF_inputAlpha_UNI(SDL_Surface* screen, sge_bmpFont* font, Uint16* string, Uint8 flags, int pos, int len, Sint16 x,
DECLSPEC int sge_BF_input_UNI(SDL_Surface* screen, sge_bmpFont* font, Uint16* string, Uint8 flags, int pos, unsigned len, Sint16 x,
Sint16 y);
DECLSPEC int sge_BF_inputAlpha_UNI(SDL_Surface* screen, sge_bmpFont* font, Uint16* string, Uint8 flags, int pos, unsigned len, Sint16 x,
Sint16 y, int Alpha);
#ifdef _SGE_C
}
Expand Down
21 changes: 10 additions & 11 deletions SGE/sge_collision.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ sge_cdata* sge_make_cmap(SDL_Surface* img)
sge_cdata* cdata;
Uint8* map;
Sint16 x, y;
Sint32 offs;
int i;

cdata = new(nothrow) sge_cdata;
Expand All @@ -50,7 +49,7 @@ sge_cdata* sge_make_cmap(SDL_Surface* img)
}
cdata->w = img->w;
cdata->h = img->h;
offs = (img->w * img->h) / 8;
const Uint32 offs = (Uint32)(img->w * img->h) / 8;
cdata->map = new(nothrow) Uint8[offs + 2];
if(!cdata->map)
{
Expand Down Expand Up @@ -87,10 +86,10 @@ sge_cdata* sge_make_cmap(SDL_Surface* img)
//==================================================================================
int sge_bbcheck(sge_cdata* cd1, Sint16 x1, Sint16 y1, sge_cdata* cd2, Sint16 x2, Sint16 y2)
{
Sint16 w1 = cd1->w;
Sint16 h1 = cd1->h;
Sint16 w2 = cd2->w;
Sint16 h2 = cd2->h;
const Uint16 w1 = cd1->w;
const Uint16 h1 = cd1->h;
const Uint16 w2 = cd2->w;
const Uint16 h2 = cd2->h;

if(x1 < x2)
{
Expand Down Expand Up @@ -144,7 +143,7 @@ int sge_bbcheck(sge_cdata* cd1, Sint16 x1, Sint16 y1, sge_cdata* cd2, Sint16 x2,
//==================================================================================
// Checks bounding boxes for collision: 0-no collision 1-collision
//==================================================================================
int _sge_bbcheck(Sint16 x1, Sint16 y1, Sint16 w1, Sint16 h1, Sint16 x2, Sint16 y2, Sint16 w2, Sint16 h2)
int _sge_bbcheck(Sint16 x1, Sint16 y1, Uint16 w1, Uint16 h1, Sint16 x2, Sint16 y2, Uint16 w2, Uint16 h2)
{
if(x1 < x2)
{
Expand Down Expand Up @@ -232,10 +231,10 @@ int _sge_cmcheck(sge_cdata* cd1, Sint16 x1, Sint16 y1, sge_cdata* cd2, Sint16 x2
if(!cd1->map || !cd2->map)
return 0;

Sint16 w1 = cd1->w;
Sint16 h1 = cd1->h;
Sint16 w2 = cd2->w;
Sint16 h2 = cd2->h;
const Uint16 w1 = cd1->w;
const Uint16 h1 = cd1->h;
const Uint16 w2 = cd2->w;
const Uint16 h2 = cd2->h;

// masks

Expand Down
7 changes: 7 additions & 0 deletions SGE/sge_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,13 @@
#ifdef _SGE_C_AND_CPP
#ifdef __cplusplus
#define _SGE_C /* use extern "C" on base functions */
#include <type_traits>
template<typename T>
constexpr auto absDiff(T a, T b)
{
using U = std::make_unsigned_t<T>;
return static_cast<U>(a > b ? a - b : b - a);
}
#else
#define sge_C_ONLY /* remove overloaded functions */
#define _SGE_NO_CLASSES /* no C++ classes */
Expand Down
2 changes: 1 addition & 1 deletion SGE/sge_misc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ Uint32 sge_Delay(Uint32 ticks)

while(time_left > 0)
{
time_left = ticks - (SDL_GetTicks() - start);
time_left = (Sint32)(ticks - (SDL_GetTicks() - start));
}

return SDL_GetTicks() - start;
Expand Down
Loading

0 comments on commit 0a72cb1

Please sign in to comment.