Skip to content

Commit 528e3ae

Browse files
authored
Merge pull request #248 from q4a/xd_dev
Port src/Common and other stuff on Linux
2 parents c4eac4b + 6de5f04 commit 528e3ae

17 files changed

+827
-164
lines changed

Externals/cximage/ximadef.h

Lines changed: 5 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#define __ximadefs_h
33

44
#include "ximacfg.h"
5+
#include "Common/Platform.hpp"
56

67
#if defined(_AFXDLL)||defined(_USRDLL)
78
#define DLL_EXP __declspec(dllexport)
@@ -53,11 +54,11 @@
5354
#define CXIMAGE_SUPPORT_WINDOWS 0
5455
#endif
5556

56-
#ifndef min
57-
#define min(a,b) (((a)<(b))?(a):(b))
57+
#ifndef MIN
58+
#define MIN(a,b) (((a)<(b))?(a):(b))
5859
#endif
59-
#ifndef max
60-
#define max(a,b) (((a)>(b))?(a):(b))
60+
#ifndef MAX
61+
#define MAX(a,b) (((a)>(b))?(a):(b))
6162
#endif
6263

6364
#ifndef PI
@@ -94,14 +95,7 @@ typedef struct tagcomplex {
9495
#include <string.h>
9596
#include <ctype.h>
9697

97-
typedef unsigned char BYTE;
98-
typedef unsigned short WORD;
99-
typedef unsigned long DWORD;
100-
typedef unsigned int UINT;
101-
typedef const char* LPCTSTR;
102-
10398
typedef DWORD COLORREF;
104-
typedef unsigned int HANDLE;
10599
typedef void* HRGN;
106100
typedef void* HDC;
107101

@@ -126,20 +120,6 @@ typedef int boolean;
126120
#define _T
127121
#endif
128122

129-
typedef struct tagRECT
130-
{
131-
long left;
132-
long top;
133-
long right;
134-
long bottom;
135-
} RECT;
136-
137-
typedef struct tagPOINT
138-
{
139-
long x;
140-
long y;
141-
} POINT;
142-
143123
typedef struct tagRGBQUAD {
144124
BYTE rgbBlue;
145125
BYTE rgbGreen;
@@ -195,7 +175,6 @@ typedef struct tagRGBTRIPLE {
195175
#define GetRValue(rgb) ((BYTE)(rgb))
196176
#define GetGValue(rgb) ((BYTE)(((WORD)(rgb)) >> 8))
197177
#define GetBValue(rgb) ((BYTE)((rgb)>>16))
198-
#define RGB(r,g,b) ((COLORREF)(((BYTE)(r)|((WORD)((BYTE)(g))<<8))|(((DWORD)(BYTE)(b))<<16)))
199178

200179
#ifndef _COMPLEX_DEFINED
201180

Externals/cximage/ximage.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -460,7 +460,7 @@ bool CxImage::CreateFromArray(BYTE* pArray,DWORD dwWidth,DWORD dwHeight,DWORD dw
460460
src+=4;
461461
}
462462
} else {
463-
memcpy(dst,src,min(info.dwEffWidth,dwBytesperline));
463+
memcpy(dst,src,MIN(info.dwEffWidth,dwBytesperline));
464464
}
465465
}
466466
return true;
@@ -500,7 +500,7 @@ bool CxImage::CreateFromMatrix(BYTE** ppMatrix,DWORD dwWidth,DWORD dwHeight,DWOR
500500
src+=4;
501501
}
502502
} else {
503-
memcpy(dst,src,min(info.dwEffWidth,dwBytesperline));
503+
memcpy(dst,src,MIN(info.dwEffWidth,dwBytesperline));
504504
}
505505
}
506506
}

Externals/cximage/ximaint.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ void CxImage::OverflowCoordinates(long &x, long &y, OverflowMethod const ofMetho
2626
switch (ofMethod) {
2727
case OM_REPEAT:
2828
//clip coordinates
29-
x=max(x,0); x=min(x, head.biWidth-1);
30-
y=max(y,0); y=min(y, head.biHeight-1);
29+
x=MAX(x,0); x=MIN(x, head.biWidth-1);
30+
y=MAX(y,0); y=MIN(y, head.biHeight-1);
3131
break;
3232
case OM_WRAP:
3333
//wrap coordinates
@@ -59,8 +59,8 @@ void CxImage::OverflowCoordinates(float &x, float &y, OverflowMethod const ofMet
5959
switch (ofMethod) {
6060
case OM_REPEAT:
6161
//clip coordinates
62-
x=max(x,0); x=min(x, head.biWidth-1);
63-
y=max(y,0); y=min(y, head.biHeight-1);
62+
x=MAX(x,0); x=MIN(x, head.biWidth-1);
63+
y=MAX(y,0); y=MIN(y, head.biHeight-1);
6464
break;
6565
case OM_WRAP:
6666
//wrap coordinates

Externals/cximage/ximaiter.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,15 +140,15 @@ inline void CImageIterator::SetY(int y)
140140
inline void CImageIterator::SetRow(BYTE *buf, int n)
141141
{
142142
if (n<0) n = (int)ima->GetEffWidth();
143-
else n = min(n,(int)ima->GetEffWidth());
143+
else n = MIN(n,(int)ima->GetEffWidth());
144144

145145
if ((IterImage!=NULL)&&(buf!=NULL)&&(n>0)) memcpy(IterImage,buf,n);
146146
}
147147
/////////////////////////////////////////////////////////////////////
148148
inline void CImageIterator::GetRow(BYTE *buf, int n)
149149
{
150150
if ((IterImage!=NULL)&&(buf!=NULL)&&(n>0))
151-
memcpy(buf,IterImage,min(n,(int)ima->GetEffWidth()));
151+
memcpy(buf,IterImage,MIN(n,(int)ima->GetEffWidth()));
152152
}
153153
/////////////////////////////////////////////////////////////////////
154154
inline BYTE* CImageIterator::GetRow()

Externals/cximage/ximapal.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -398,8 +398,8 @@ void CxImage::RGBtoBGR(BYTE *buffer, int length)
398398
{
399399
if (buffer && (head.biClrUsed==0)){
400400
BYTE temp;
401-
length = min(length,(int)info.dwEffWidth);
402-
length = min(length,(int)(3*head.biWidth));
401+
length = MIN(length,(int)info.dwEffWidth);
402+
length = MIN(length,(int)(3*head.biWidth));
403403
for (int i=0;i<length;i+=3){
404404
temp = buffer[i]; buffer[i] = buffer[i+2]; buffer[i+2] = temp;
405405
}
@@ -444,7 +444,7 @@ void CxImage::SetPalette(DWORD n, BYTE *r, BYTE *g, BYTE *b)
444444
if (!g) g = r;
445445
if (!b) b = g;
446446
RGBQUAD* ppal=GetPalette();
447-
DWORD m=min(n,head.biClrUsed);
447+
DWORD m=MIN(n,head.biClrUsed);
448448
for (DWORD i=0; i<m;i++){
449449
ppal[i].rgbRed=r[i];
450450
ppal[i].rgbGreen=g[i];
@@ -457,7 +457,7 @@ void CxImage::SetPalette(rgb_color *rgb,DWORD nColors)
457457
{
458458
if ((!rgb)||(pDib==NULL)||(head.biClrUsed==0)) return;
459459
RGBQUAD* ppal=GetPalette();
460-
DWORD m=min(nColors,head.biClrUsed);
460+
DWORD m=MIN(nColors,head.biClrUsed);
461461
for (DWORD i=0; i<m;i++){
462462
ppal[i].rgbRed=rgb[i].r;
463463
ppal[i].rgbGreen=rgb[i].g;
@@ -469,7 +469,7 @@ void CxImage::SetPalette(rgb_color *rgb,DWORD nColors)
469469
void CxImage::SetPalette(RGBQUAD* pPal,DWORD nColors)
470470
{
471471
if ((pPal==NULL)||(pDib==NULL)||(head.biClrUsed==0)) return;
472-
memcpy(GetPalette(),pPal,min(GetPaletteSize(),nColors*sizeof(RGBQUAD)));
472+
memcpy(GetPalette(),pPal,MIN(GetPaletteSize(),nColors*sizeof(RGBQUAD)));
473473
info.last_c_isvalid = false;
474474
}
475475
////////////////////////////////////////////////////////////////////////////////
@@ -654,10 +654,10 @@ void CxImage::SetClrImportant(DWORD ncolors)
654654

655655
switch(head.biBitCount){
656656
case 1:
657-
head.biClrImportant = min(ncolors,2);
657+
head.biClrImportant = MIN(ncolors,2);
658658
break;
659659
case 4:
660-
head.biClrImportant = min(ncolors,16);
660+
head.biClrImportant = MIN(ncolors,16);
661661
break;
662662
case 8:
663663
head.biClrImportant = ncolors;

Externals/cximage/ximasel.cpp

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -113,15 +113,15 @@ bool CxImage::SelectionAddRect(RECT r, BYTE level)
113113
if (r.left<r.right) {r2.left=r.left; r2.right=r.right; } else {r2.left=r.right ; r2.right=r.left; }
114114
if (r.bottom<r.top) {r2.bottom=r.bottom; r2.top=r.top; } else {r2.bottom=r.top ; r2.top=r.bottom; }
115115

116-
if (info.rSelectionBox.top <= r2.top) info.rSelectionBox.top = max(0L,min(head.biHeight,r2.top+1));
117-
if (info.rSelectionBox.left > r2.left) info.rSelectionBox.left = max(0L,min(head.biWidth,r2.left));
118-
if (info.rSelectionBox.right <= r2.right) info.rSelectionBox.right = max(0L,min(head.biWidth,r2.right+1));
119-
if (info.rSelectionBox.bottom > r2.bottom) info.rSelectionBox.bottom = max(0L,min(head.biHeight,r2.bottom));
116+
if (info.rSelectionBox.top <= r2.top) info.rSelectionBox.top = MAX(0L,MIN(head.biHeight,r2.top+1));
117+
if (info.rSelectionBox.left > r2.left) info.rSelectionBox.left = MAX(0L,MIN(head.biWidth,r2.left));
118+
if (info.rSelectionBox.right <= r2.right) info.rSelectionBox.right = MAX(0L,MIN(head.biWidth,r2.right+1));
119+
if (info.rSelectionBox.bottom > r2.bottom) info.rSelectionBox.bottom = MAX(0L,MIN(head.biHeight,r2.bottom));
120120

121-
long ymin = max(0L,min(head.biHeight,r2.bottom));
122-
long ymax = max(0L,min(head.biHeight,r2.top+1));
123-
long xmin = max(0L,min(head.biWidth,r2.left));
124-
long xmax = max(0L,min(head.biWidth,r2.right+1));
121+
long ymin = MAX(0L,MIN(head.biHeight,r2.bottom));
122+
long ymax = MAX(0L,MIN(head.biHeight,r2.top+1));
123+
long xmin = MAX(0L,MIN(head.biWidth,r2.left));
124+
long xmax = MAX(0L,MIN(head.biWidth,r2.right+1));
125125

126126
for (long y=ymin; y<ymax; y++)
127127
memset(pSelection + xmin + y * head.biWidth, level, xmax-xmin);
@@ -144,18 +144,18 @@ bool CxImage::SelectionAddEllipse(RECT r, BYTE level)
144144
long xcenter = (r.right + r.left)/2;
145145
long ycenter = (r.top + r.bottom)/2;
146146

147-
if (info.rSelectionBox.left > (xcenter - xradius)) info.rSelectionBox.left = max(0L,min(head.biWidth,(xcenter - xradius)));
148-
if (info.rSelectionBox.right <= (xcenter + xradius)) info.rSelectionBox.right = max(0L,min(head.biWidth,(xcenter + xradius + 1)));
149-
if (info.rSelectionBox.bottom > (ycenter - yradius)) info.rSelectionBox.bottom = max(0L,min(head.biHeight,(ycenter - yradius)));
150-
if (info.rSelectionBox.top <= (ycenter + yradius)) info.rSelectionBox.top = max(0L,min(head.biHeight,(ycenter + yradius + 1)));
147+
if (info.rSelectionBox.left > (xcenter - xradius)) info.rSelectionBox.left = MAX(0L,MIN(head.biWidth,(xcenter - xradius)));
148+
if (info.rSelectionBox.right <= (xcenter + xradius)) info.rSelectionBox.right = MAX(0L,MIN(head.biWidth,(xcenter + xradius + 1)));
149+
if (info.rSelectionBox.bottom > (ycenter - yradius)) info.rSelectionBox.bottom = MAX(0L,MIN(head.biHeight,(ycenter - yradius)));
150+
if (info.rSelectionBox.top <= (ycenter + yradius)) info.rSelectionBox.top = MAX(0L,MIN(head.biHeight,(ycenter + yradius + 1)));
151151

152-
long xmin = max(0L,min(head.biWidth,xcenter - xradius));
153-
long xmax = max(0L,min(head.biWidth,xcenter + xradius + 1));
154-
long ymin = max(0L,min(head.biHeight,ycenter - yradius));
155-
long ymax = max(0L,min(head.biHeight,ycenter + yradius + 1));
152+
long xmin = MAX(0L,MIN(head.biWidth,xcenter - xradius));
153+
long xmax = MAX(0L,MIN(head.biWidth,xcenter + xradius + 1));
154+
long ymin = MAX(0L,MIN(head.biHeight,ycenter - yradius));
155+
long ymax = MAX(0L,MIN(head.biHeight,ycenter + yradius + 1));
156156

157157
long y,yo;
158-
for (y=ymin; y<min(ycenter,ymax); y++){
158+
for (y=ymin; y<MIN(ycenter,ymax); y++){
159159
for (long x=xmin; x<xmax; x++){
160160
yo = (long)(ycenter - yradius * sqrt(1-pow((float)(x - xcenter)/(float)xradius,2)));
161161
if (yo<y) pSelection[x + y * head.biWidth] = level;
@@ -268,10 +268,10 @@ bool CxImage::SelectionAddPolygon(POINT *points, long npoints, BYTE level)
268268
RECT r2;
269269
if (current->x < next->x) {r2.left=current->x; r2.right=next->x; } else {r2.left=next->x ; r2.right=current->x; }
270270
if (current->y < next->y) {r2.bottom=current->y; r2.top=next->y; } else {r2.bottom=next->y ; r2.top=current->y; }
271-
if (localbox.top < r2.top) localbox.top = max(0L,min(head.biHeight-1,r2.top+1));
272-
if (localbox.left > r2.left) localbox.left = max(0L,min(head.biWidth-1,r2.left-1));
273-
if (localbox.right < r2.right) localbox.right = max(0L,min(head.biWidth-1,r2.right+1));
274-
if (localbox.bottom > r2.bottom) localbox.bottom = max(0L,min(head.biHeight-1,r2.bottom-1));
271+
if (localbox.top < r2.top) localbox.top = MAX(0L,MIN(head.biHeight-1,r2.top+1));
272+
if (localbox.left > r2.left) localbox.left = MAX(0L,MIN(head.biWidth-1,r2.left-1));
273+
if (localbox.right < r2.right) localbox.right = MAX(0L,MIN(head.biWidth-1,r2.right+1));
274+
if (localbox.bottom > r2.bottom) localbox.bottom = MAX(0L,MIN(head.biHeight-1,r2.bottom-1));
275275

276276
i++;
277277
}
@@ -385,10 +385,10 @@ bool CxImage::SelectionAddPolygon(POINT *points, long npoints, BYTE level)
385385
for (x=localbox.left; x<=localbox.right; x++)
386386
if (plocal[x + yoffset]!=1) pSelection[x + yoffset]=level;
387387
}
388-
if (info.rSelectionBox.top <= localbox.top) info.rSelectionBox.top = min(head.biHeight,localbox.top + 1);
389-
if (info.rSelectionBox.left > localbox.left) info.rSelectionBox.left = min(head.biWidth,localbox.left);
390-
if (info.rSelectionBox.right <= localbox.right) info.rSelectionBox.right = min(head.biWidth,localbox.right + 1);
391-
if (info.rSelectionBox.bottom > localbox.bottom) info.rSelectionBox.bottom = min(head.biHeight,localbox.bottom);
388+
if (info.rSelectionBox.top <= localbox.top) info.rSelectionBox.top = MIN(head.biHeight,localbox.top + 1);
389+
if (info.rSelectionBox.left > localbox.left) info.rSelectionBox.left = MIN(head.biWidth,localbox.left);
390+
if (info.rSelectionBox.right <= localbox.right) info.rSelectionBox.right = MIN(head.biWidth,localbox.right + 1);
391+
if (info.rSelectionBox.bottom > localbox.bottom) info.rSelectionBox.bottom = MIN(head.biHeight,localbox.bottom);
392392

393393
cxfree(plocal);//free(plocal);
394394
cxfree(pix);//free(pix);

Externals/cximage/ximath.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,10 @@ CxRect2 CxRect2::CrossSection(CxRect2 const &r2) const
6464
*/
6565
{
6666
CxRect2 cs;
67-
cs.botLeft.x=max(botLeft.x, r2.botLeft.x);
68-
cs.botLeft.y=max(botLeft.y, r2.botLeft.y);
69-
cs.topRight.x=min(topRight.x, r2.topRight.x);
70-
cs.topRight.y=min(topRight.y, r2.topRight.y);
67+
cs.botLeft.x=MAX(botLeft.x, r2.botLeft.x);
68+
cs.botLeft.y=MAX(botLeft.y, r2.botLeft.y);
69+
cs.topRight.x=MIN(topRight.x, r2.topRight.x);
70+
cs.topRight.y=MIN(topRight.y, r2.topRight.y);
7171
if (cs.botLeft.x<=cs.topRight.x && cs.botLeft.y<=cs.topRight.y) {
7272
return cs;
7373
} else {

Externals/luabind

src/Common/Common.hpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,12 @@
66
#include "Common/FSMacros.hpp"
77
#include "Include/xrAPI/xrAPI.h"
88

9-
#if __has_include(<SDL.h>)
10-
#include <SDL.h>
9+
#if defined(WINDOWS)
10+
#if __has_include("SDL.h")
11+
#include "SDL.h"
1112
#endif
1213

13-
#if __has_include(<SDL_syswm.h>)
14-
#include <SDL_syswm.h>
14+
#if __has_include("SDL_syswm.h")
15+
#include "SDL_syswm.h"
16+
#endif
1517
#endif

src/Common/FSMacros.hpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
#pragma once
22

3+
#if defined(LINUX)
4+
#define _DELIMITER '/' //for looking
5+
#define DELIMITER "/" // for insert
6+
#elif defined(WINDOWS)
7+
#define _DELIMITER '\\' //for looking
8+
#define DELIMITER "\\" // for insert
9+
#endif
10+
311
// game path definition
412
#define _game_data_ "$game_data$"
513
#define _game_textures_ "$game_textures$"

0 commit comments

Comments
 (0)