Skip to content

Commit

Permalink
Merge pull request #248 from q4a/xd_dev
Browse files Browse the repository at this point in the history
 Port src/Common and other stuff on Linux
  • Loading branch information
Xottab-DUTY committed Oct 7, 2018
2 parents c4eac4b + 6de5f04 commit 528e3ae
Show file tree
Hide file tree
Showing 17 changed files with 827 additions and 164 deletions.
31 changes: 5 additions & 26 deletions Externals/cximage/ximadef.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#define __ximadefs_h

#include "ximacfg.h"
#include "Common/Platform.hpp"

#if defined(_AFXDLL)||defined(_USRDLL)
#define DLL_EXP __declspec(dllexport)
Expand Down Expand Up @@ -53,11 +54,11 @@
#define CXIMAGE_SUPPORT_WINDOWS 0
#endif

#ifndef min
#define min(a,b) (((a)<(b))?(a):(b))
#ifndef MIN
#define MIN(a,b) (((a)<(b))?(a):(b))
#endif
#ifndef max
#define max(a,b) (((a)>(b))?(a):(b))
#ifndef MAX
#define MAX(a,b) (((a)>(b))?(a):(b))
#endif

#ifndef PI
Expand Down Expand Up @@ -94,14 +95,7 @@ typedef struct tagcomplex {
#include <string.h>
#include <ctype.h>

typedef unsigned char BYTE;
typedef unsigned short WORD;
typedef unsigned long DWORD;
typedef unsigned int UINT;
typedef const char* LPCTSTR;

typedef DWORD COLORREF;
typedef unsigned int HANDLE;
typedef void* HRGN;
typedef void* HDC;

Expand All @@ -126,20 +120,6 @@ typedef int boolean;
#define _T
#endif

typedef struct tagRECT
{
long left;
long top;
long right;
long bottom;
} RECT;

typedef struct tagPOINT
{
long x;
long y;
} POINT;

typedef struct tagRGBQUAD {
BYTE rgbBlue;
BYTE rgbGreen;
Expand Down Expand Up @@ -195,7 +175,6 @@ typedef struct tagRGBTRIPLE {
#define GetRValue(rgb) ((BYTE)(rgb))
#define GetGValue(rgb) ((BYTE)(((WORD)(rgb)) >> 8))
#define GetBValue(rgb) ((BYTE)((rgb)>>16))
#define RGB(r,g,b) ((COLORREF)(((BYTE)(r)|((WORD)((BYTE)(g))<<8))|(((DWORD)(BYTE)(b))<<16)))

#ifndef _COMPLEX_DEFINED

Expand Down
4 changes: 2 additions & 2 deletions Externals/cximage/ximage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,7 @@ bool CxImage::CreateFromArray(BYTE* pArray,DWORD dwWidth,DWORD dwHeight,DWORD dw
src+=4;
}
} else {
memcpy(dst,src,min(info.dwEffWidth,dwBytesperline));
memcpy(dst,src,MIN(info.dwEffWidth,dwBytesperline));
}
}
return true;
Expand Down Expand Up @@ -500,7 +500,7 @@ bool CxImage::CreateFromMatrix(BYTE** ppMatrix,DWORD dwWidth,DWORD dwHeight,DWOR
src+=4;
}
} else {
memcpy(dst,src,min(info.dwEffWidth,dwBytesperline));
memcpy(dst,src,MIN(info.dwEffWidth,dwBytesperline));
}
}
}
Expand Down
8 changes: 4 additions & 4 deletions Externals/cximage/ximaint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ void CxImage::OverflowCoordinates(long &x, long &y, OverflowMethod const ofMetho
switch (ofMethod) {
case OM_REPEAT:
//clip coordinates
x=max(x,0); x=min(x, head.biWidth-1);
y=max(y,0); y=min(y, head.biHeight-1);
x=MAX(x,0); x=MIN(x, head.biWidth-1);
y=MAX(y,0); y=MIN(y, head.biHeight-1);
break;
case OM_WRAP:
//wrap coordinates
Expand Down Expand Up @@ -59,8 +59,8 @@ void CxImage::OverflowCoordinates(float &x, float &y, OverflowMethod const ofMet
switch (ofMethod) {
case OM_REPEAT:
//clip coordinates
x=max(x,0); x=min(x, head.biWidth-1);
y=max(y,0); y=min(y, head.biHeight-1);
x=MAX(x,0); x=MIN(x, head.biWidth-1);
y=MAX(y,0); y=MIN(y, head.biHeight-1);
break;
case OM_WRAP:
//wrap coordinates
Expand Down
4 changes: 2 additions & 2 deletions Externals/cximage/ximaiter.h
Original file line number Diff line number Diff line change
Expand Up @@ -140,15 +140,15 @@ inline void CImageIterator::SetY(int y)
inline void CImageIterator::SetRow(BYTE *buf, int n)
{
if (n<0) n = (int)ima->GetEffWidth();
else n = min(n,(int)ima->GetEffWidth());
else n = MIN(n,(int)ima->GetEffWidth());

if ((IterImage!=NULL)&&(buf!=NULL)&&(n>0)) memcpy(IterImage,buf,n);
}
/////////////////////////////////////////////////////////////////////
inline void CImageIterator::GetRow(BYTE *buf, int n)
{
if ((IterImage!=NULL)&&(buf!=NULL)&&(n>0))
memcpy(buf,IterImage,min(n,(int)ima->GetEffWidth()));
memcpy(buf,IterImage,MIN(n,(int)ima->GetEffWidth()));
}
/////////////////////////////////////////////////////////////////////
inline BYTE* CImageIterator::GetRow()
Expand Down
14 changes: 7 additions & 7 deletions Externals/cximage/ximapal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -398,8 +398,8 @@ void CxImage::RGBtoBGR(BYTE *buffer, int length)
{
if (buffer && (head.biClrUsed==0)){
BYTE temp;
length = min(length,(int)info.dwEffWidth);
length = min(length,(int)(3*head.biWidth));
length = MIN(length,(int)info.dwEffWidth);
length = MIN(length,(int)(3*head.biWidth));
for (int i=0;i<length;i+=3){
temp = buffer[i]; buffer[i] = buffer[i+2]; buffer[i+2] = temp;
}
Expand Down Expand Up @@ -444,7 +444,7 @@ void CxImage::SetPalette(DWORD n, BYTE *r, BYTE *g, BYTE *b)
if (!g) g = r;
if (!b) b = g;
RGBQUAD* ppal=GetPalette();
DWORD m=min(n,head.biClrUsed);
DWORD m=MIN(n,head.biClrUsed);
for (DWORD i=0; i<m;i++){
ppal[i].rgbRed=r[i];
ppal[i].rgbGreen=g[i];
Expand All @@ -457,7 +457,7 @@ void CxImage::SetPalette(rgb_color *rgb,DWORD nColors)
{
if ((!rgb)||(pDib==NULL)||(head.biClrUsed==0)) return;
RGBQUAD* ppal=GetPalette();
DWORD m=min(nColors,head.biClrUsed);
DWORD m=MIN(nColors,head.biClrUsed);
for (DWORD i=0; i<m;i++){
ppal[i].rgbRed=rgb[i].r;
ppal[i].rgbGreen=rgb[i].g;
Expand All @@ -469,7 +469,7 @@ void CxImage::SetPalette(rgb_color *rgb,DWORD nColors)
void CxImage::SetPalette(RGBQUAD* pPal,DWORD nColors)
{
if ((pPal==NULL)||(pDib==NULL)||(head.biClrUsed==0)) return;
memcpy(GetPalette(),pPal,min(GetPaletteSize(),nColors*sizeof(RGBQUAD)));
memcpy(GetPalette(),pPal,MIN(GetPaletteSize(),nColors*sizeof(RGBQUAD)));
info.last_c_isvalid = false;
}
////////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -654,10 +654,10 @@ void CxImage::SetClrImportant(DWORD ncolors)

switch(head.biBitCount){
case 1:
head.biClrImportant = min(ncolors,2);
head.biClrImportant = MIN(ncolors,2);
break;
case 4:
head.biClrImportant = min(ncolors,16);
head.biClrImportant = MIN(ncolors,16);
break;
case 8:
head.biClrImportant = ncolors;
Expand Down
50 changes: 25 additions & 25 deletions Externals/cximage/ximasel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,15 +113,15 @@ bool CxImage::SelectionAddRect(RECT r, BYTE level)
if (r.left<r.right) {r2.left=r.left; r2.right=r.right; } else {r2.left=r.right ; r2.right=r.left; }
if (r.bottom<r.top) {r2.bottom=r.bottom; r2.top=r.top; } else {r2.bottom=r.top ; r2.top=r.bottom; }

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

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

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

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

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

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

i++;
}
Expand Down Expand Up @@ -385,10 +385,10 @@ bool CxImage::SelectionAddPolygon(POINT *points, long npoints, BYTE level)
for (x=localbox.left; x<=localbox.right; x++)
if (plocal[x + yoffset]!=1) pSelection[x + yoffset]=level;
}
if (info.rSelectionBox.top <= localbox.top) info.rSelectionBox.top = min(head.biHeight,localbox.top + 1);
if (info.rSelectionBox.left > localbox.left) info.rSelectionBox.left = min(head.biWidth,localbox.left);
if (info.rSelectionBox.right <= localbox.right) info.rSelectionBox.right = min(head.biWidth,localbox.right + 1);
if (info.rSelectionBox.bottom > localbox.bottom) info.rSelectionBox.bottom = min(head.biHeight,localbox.bottom);
if (info.rSelectionBox.top <= localbox.top) info.rSelectionBox.top = MIN(head.biHeight,localbox.top + 1);
if (info.rSelectionBox.left > localbox.left) info.rSelectionBox.left = MIN(head.biWidth,localbox.left);
if (info.rSelectionBox.right <= localbox.right) info.rSelectionBox.right = MIN(head.biWidth,localbox.right + 1);
if (info.rSelectionBox.bottom > localbox.bottom) info.rSelectionBox.bottom = MIN(head.biHeight,localbox.bottom);

cxfree(plocal);//free(plocal);
cxfree(pix);//free(pix);
Expand Down
8 changes: 4 additions & 4 deletions Externals/cximage/ximath.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,10 @@ CxRect2 CxRect2::CrossSection(CxRect2 const &r2) const
*/
{
CxRect2 cs;
cs.botLeft.x=max(botLeft.x, r2.botLeft.x);
cs.botLeft.y=max(botLeft.y, r2.botLeft.y);
cs.topRight.x=min(topRight.x, r2.topRight.x);
cs.topRight.y=min(topRight.y, r2.topRight.y);
cs.botLeft.x=MAX(botLeft.x, r2.botLeft.x);
cs.botLeft.y=MAX(botLeft.y, r2.botLeft.y);
cs.topRight.x=MIN(topRight.x, r2.topRight.x);
cs.topRight.y=MIN(topRight.y, r2.topRight.y);
if (cs.botLeft.x<=cs.topRight.x && cs.botLeft.y<=cs.topRight.y) {
return cs;
} else {
Expand Down
2 changes: 1 addition & 1 deletion Externals/luabind
Submodule luabind updated 1 files
+0 −1 src/CMakeLists.txt
10 changes: 6 additions & 4 deletions src/Common/Common.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@
#include "Common/FSMacros.hpp"
#include "Include/xrAPI/xrAPI.h"

#if __has_include(<SDL.h>)
#include <SDL.h>
#if defined(WINDOWS)
#if __has_include("SDL.h")
#include "SDL.h"
#endif

#if __has_include(<SDL_syswm.h>)
#include <SDL_syswm.h>
#if __has_include("SDL_syswm.h")
#include "SDL_syswm.h"
#endif
#endif
8 changes: 8 additions & 0 deletions src/Common/FSMacros.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
#pragma once

#if defined(LINUX)
#define _DELIMITER '/' //for looking
#define DELIMITER "/" // for insert
#elif defined(WINDOWS)
#define _DELIMITER '\\' //for looking
#define DELIMITER "\\" // for insert
#endif

// game path definition
#define _game_data_ "$game_data$"
#define _game_textures_ "$game_textures$"
Expand Down
Loading

0 comments on commit 528e3ae

Please sign in to comment.