From 7a43531e96cd4dd537e76dbd39a2da6a6e6596b1 Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Sun, 29 Aug 2010 14:22:22 -0700 Subject: [PATCH] Fixed compiling with Visual Studio 2008 --- VisualC/SDL/SDL_VS2008.vcproj | 36 +++++++++++++++++- src/events/SDL_gesture.c | 61 ++++++++++++++++--------------- src/events/SDL_touch.c | 11 ++++-- src/haptic/nds/SDL_syshaptic.c | 3 +- src/stdlib/SDL_stdlib.c | 6 +++ src/video/win32/SDL_win32events.c | 21 ++++++----- src/video/win32/SDL_win32video.h | 8 +--- 7 files changed, 94 insertions(+), 52 deletions(-) diff --git a/VisualC/SDL/SDL_VS2008.vcproj b/VisualC/SDL/SDL_VS2008.vcproj index 439cbd1bc..75f21c3e6 100644 --- a/VisualC/SDL/SDL_VS2008.vcproj +++ b/VisualC/SDL/SDL_VS2008.vcproj @@ -76,7 +76,7 @@ /> + + + + @@ -1003,6 +1011,14 @@ RelativePath="..\..\src\file\SDL_rwops.c" > + + + + @@ -1095,6 +1111,14 @@ RelativePath="..\..\src\timer\SDL_timer_c.h" > + + + + @@ -1167,6 +1191,14 @@ RelativePath="..\..\src\video\win32\SDL_win32opengl.h" > + + + + diff --git a/src/events/SDL_gesture.c b/src/events/SDL_gesture.c index f500a9598..39ac76c2f 100644 --- a/src/events/SDL_gesture.c +++ b/src/events/SDL_gesture.c @@ -44,7 +44,6 @@ #define ENABLE_DOLLAR -//PHI = ((sqrt(5)-1)/2) #define PHI 0.618033989 typedef struct { @@ -80,7 +79,8 @@ SDL_GestureTouch *SDL_gestureTouch; int SDL_numGestureTouches = 0; SDL_bool recordAll; -void SDL_PrintPath(SDL_FloatPoint *path) { +#if 0 +static void PrintPath(SDL_FloatPoint *path) { int i; printf("Path:"); for(i=0;idollarTemplate[inTouch->numDollarTemplates]; - memcpy(templ->path,path,DOLLARNPOINTS*sizeof(SDL_FloatPoint)); + SDL_memcpy(templ->path,path,DOLLARNPOINTS*sizeof(SDL_FloatPoint)); templ->hash = SDL_HashDollar(templ->path); inTouch->numDollarTemplates++; } @@ -196,7 +197,7 @@ static int SDL_AddDollarGesture(SDL_GestureTouch* inTouch,SDL_FloatPoint* path) templ = &inTouch->dollarTemplate[inTouch->numDollarTemplates]; - memcpy(templ->path,path,DOLLARNPOINTS*sizeof(SDL_FloatPoint)); + SDL_memcpy(templ->path,path,DOLLARNPOINTS*sizeof(SDL_FloatPoint)); templ->hash = SDL_HashDollar(templ->path); inTouch->numDollarTemplates++; return inTouch->numDollarTemplates - 1; @@ -222,14 +223,14 @@ int SDL_LoadDollarTemplates(SDL_TouchID touchId, SDL_RWops *src) { DOLLARNPOINTS) break; if(touchId >= 0) { - printf("Adding loaded gesture to 1 touch\n"); + //printf("Adding loaded gesture to 1 touch\n"); if(SDL_AddDollarGesture(touch,templ.path)) loaded++; } else { - printf("Adding to: %i touches\n",SDL_numGestureTouches); + //printf("Adding to: %i touches\n",SDL_numGestureTouches); for(i = 0;i < SDL_numGestureTouches; i++) { touch = &SDL_gestureTouch[i]; - printf("Adding loaded gesture to + touches\n"); + //printf("Adding loaded gesture to + touches\n"); //TODO: What if this fails? SDL_AddDollarGesture(touch,templ.path); } @@ -247,9 +248,9 @@ float dollarDifference(SDL_FloatPoint* points,SDL_FloatPoint* templ,float ang) { SDL_FloatPoint p; int i; for(i = 0; i < DOLLARNPOINTS; i++) { - p.x = (float)(points[i].x * cos(ang) - points[i].y * sin(ang)); - p.y = (float)(points[i].x * sin(ang) + points[i].y * cos(ang)); - dist += (float)(sqrt((p.x-templ[i].x)*(p.x-templ[i].x)+ + p.x = (float)(points[i].x * SDL_cos(ang) - points[i].y * SDL_sin(ang)); + p.y = (float)(points[i].x * SDL_sin(ang) + points[i].y * SDL_cos(ang)); + dist += (float)(SDL_sqrt((p.x-templ[i].x)*(p.x-templ[i].x)+ (p.y-templ[i].y)*(p.y-templ[i].y))); } return dist/DOLLARNPOINTS; @@ -267,7 +268,7 @@ float bestDollarDifference(SDL_FloatPoint* points,SDL_FloatPoint* templ) { float f1 = dollarDifference(points,templ,x1); float x2 = (float)((1-PHI)*ta + PHI*tb); float f2 = dollarDifference(points,templ,x2); - while(fabs(ta-tb) > dt) { + while(SDL_fabs(ta-tb) > dt) { if(f1 < f2) { tb = x2; x2 = x1; @@ -310,7 +311,7 @@ int dollarNormalize(SDL_DollarPath path,SDL_FloatPoint *points) { path.p[i-1].x; float dy = path.p[i ].y - path.p[i-1].y; - path.length += (float)(sqrt(dx*dx+dy*dy)); + path.length += (float)(SDL_sqrt(dx*dx+dy*dy)); } } @@ -322,7 +323,7 @@ int dollarNormalize(SDL_DollarPath path,SDL_FloatPoint *points) { //printf("(%f,%f)\n",path.p[path.numPoints-1].x,path.p[path.numPoints-1].y); for(i = 1;i < path.numPoints;i++) { - float d = (float)(sqrt((path.p[i-1].x-path.p[i].x)*(path.p[i-1].x-path.p[i].x)+ + float d = (float)(SDL_sqrt((path.p[i-1].x-path.p[i].x)*(path.p[i-1].x-path.p[i].x)+ (path.p[i-1].y-path.p[i].y)*(path.p[i-1].y-path.p[i].y))); //printf("d = %f dist = %f/%f\n",d,dist,interval); while(dist + d > interval) { @@ -339,7 +340,7 @@ int dollarNormalize(SDL_DollarPath path,SDL_FloatPoint *points) { dist += d; } if(numPoints < DOLLARNPOINTS-1) { - printf("ERROR: NumPoints = %i\n",numPoints); + SDL_SetError("ERROR: NumPoints = %i\n",numPoints); return 0; } //copy the last point @@ -356,16 +357,16 @@ int dollarNormalize(SDL_DollarPath path,SDL_FloatPoint *points) { ymin = centroid.y; ymax = centroid.y; - ang = (float)(atan2(centroid.y - points[0].y, + ang = (float)(SDL_atan2(centroid.y - points[0].y, centroid.x - points[0].x)); for(i = 0;inumDollarTemplates;i++) { float diff = bestDollarDifference(points,touch->dollarTemplate[i].path); @@ -430,10 +431,10 @@ int SDL_GestureAddTouch(SDL_Touch* touch) { int SDL_GestureRemoveTouch(SDL_TouchID id) { int i; - for(i = 0;i < SDL_numGestureTouches; i++) { - if(SDL_gestureTouch[i].id == id) { + for (i = 0; i < SDL_numGestureTouches; i++) { + if (SDL_gestureTouch[i].id == id) { SDL_numGestureTouches--; - SDL_gestureTouch[i] = SDL_gestureTouch[SDL_numGestureTouches]; + SDL_memcpy(&SDL_gestureTouch[i], &SDL_gestureTouch[SDL_numGestureTouches], sizeof(SDL_gestureTouch[i])); return 1; } } @@ -528,7 +529,7 @@ void SDL_GestureProcessEvent(SDL_Event* event) if(inTouch->recording) { inTouch->recording = SDL_FALSE; dollarNormalize(inTouch->dollarPath,path); - //SDL_PrintPath(path); + //PrintPath(path); if(recordAll) { index = SDL_AddDollarGesture(NULL,path); for(i = 0;i < SDL_numGestureTouches; i++) @@ -579,7 +580,7 @@ void SDL_GestureProcessEvent(SDL_Event* event) (path->p[path->numPoints].x-path->p[path->numPoints-1].x); pathDy = (path->p[path->numPoints].y-path->p[path->numPoints-1].y); - path->length += (float)sqrt(pathDx*pathDx + pathDy*pathDy); + path->length += (float)SDL_sqrt(pathDx*pathDx + pathDy*pathDy); path->numPoints++; } #endif @@ -596,20 +597,20 @@ void SDL_GestureProcessEvent(SDL_Event* event) //lv = inTouch->gestureLast[j].cv; lv.x = lastP.x - lastCentroid.x; lv.y = lastP.y - lastCentroid.y; - lDist = (float)sqrt(lv.x*lv.x + lv.y*lv.y); + lDist = (float)SDL_sqrt(lv.x*lv.x + lv.y*lv.y); //printf("lDist = %f\n",lDist); v.x = x - inTouch->centroid.x; v.y = y - inTouch->centroid.y; //inTouch->gestureLast[j].cv = v; - Dist = (float)sqrt(v.x*v.x+v.y*v.y); - // cos(dTheta) = (v . lv)/(|v| * |lv|) + Dist = (float)SDL_sqrt(v.x*v.x+v.y*v.y); + // SDL_cos(dTheta) = (v . lv)/(|v| * |lv|) //Normalize Vectors to simplify angle calculation lv.x/=lDist; lv.y/=lDist; v.x/=Dist; v.y/=Dist; - dtheta = (float)atan2(lv.x*v.y - lv.y*v.x,lv.x*v.x + lv.y*v.y); + dtheta = (float)SDL_atan2(lv.x*v.y - lv.y*v.x,lv.x*v.x + lv.y*v.y); dDist = (Dist - lDist); if(lDist == 0) {dDist = 0;dtheta = 0;} //To avoid impossible values diff --git a/src/events/SDL_touch.c b/src/events/SDL_touch.c index 93513dec3..ec7b2e84a 100644 --- a/src/events/SDL_touch.c +++ b/src/events/SDL_touch.c @@ -366,7 +366,10 @@ SDL_SendFingerDown(SDL_TouchID id, SDL_FingerID fingerid, SDL_bool down, return posted; } else { - if(finger == NULL) {printf("Finger not found...\n");return 0;} + if(finger == NULL) { + SDL_SetError("Finger not found."); + return 0; + } posted = 0; if (SDL_GetEventState(SDL_FINGERUP) == SDL_ENABLE) { SDL_Event event; @@ -552,12 +555,14 @@ SDL_GetTouchName(SDL_TouchID id) } int SDL_TouchNotFoundError(SDL_TouchID id) { - int i; - printf("ERROR: Cannot send touch on non-existent device with id: %li make sure SDL_AddTouch has been called\n",id); + //int i; + SDL_SetError("ERROR: Cannot send touch on non-existent device with id: %li make sure SDL_AddTouch has been called\n",id); +#if 0 printf("ERROR: There are %i touches installed with Id's:\n",SDL_num_touch); for(i=0;i < SDL_num_touch;i++) { printf("ERROR: %li\n",SDL_touchPads[i]->id); } +#endif return 0; } /* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/haptic/nds/SDL_syshaptic.c b/src/haptic/nds/SDL_syshaptic.c index 7ba3c90e5..e903c3edb 100644 --- a/src/haptic/nds/SDL_syshaptic.c +++ b/src/haptic/nds/SDL_syshaptic.c @@ -52,8 +52,9 @@ NDS_EZF_OpenNorWrite() GBA_BUS[0x0020000] = 0x1500; GBA_BUS[0x0E20000] = 0x1500; GBA_BUS[0x0FE0000] = 0x1500; -} void +} +void NDS_EZF_CloseNorWrite() { GBA_BUS[0x0FF0000] = 0xD200; diff --git a/src/stdlib/SDL_stdlib.c b/src/stdlib/SDL_stdlib.c index 06f2174f8..93e13b3cc 100644 --- a/src/stdlib/SDL_stdlib.c +++ b/src/stdlib/SDL_stdlib.c @@ -39,6 +39,12 @@ __declspec(selectany) int _fltused = 1; #else +void +__declspec(naked) +_chkstk() +{ +} + /* Float to long */ void __declspec(naked) diff --git a/src/video/win32/SDL_win32events.c b/src/video/win32/SDL_win32events.c index dd755c5ea..ca924f31c 100644 --- a/src/video/win32/SDL_win32events.c +++ b/src/video/win32/SDL_win32events.c @@ -20,11 +20,6 @@ slouken@libsdl.org */ -#if (_WIN32_WINNT < 0x601) -#undef _WIN32_WINNT -#define _WIN32_WINNT 0x601 -#endif - #include "SDL_config.h" #include "SDL_win32video.h" @@ -35,12 +30,11 @@ -#define WMMSG_DEBUG +/*#define WMMSG_DEBUG*/ #ifdef WMMSG_DEBUG #include #include "wmmsg.h" #endif -//#include /* Masks for processing the windows KEYDOWN and KEYUP messages */ #define REPEATED_KEYMASK (1<<30) @@ -61,6 +55,12 @@ #ifndef WM_INPUT #define WM_INPUT 0x00ff #endif +#ifndef WM_GESTURE +#define WM_GESTURE 0x0119 +#endif +#ifndef WM_TOUCH +#define WM_TOUCH 0x0240 +#endif static WPARAM RemapVKEY(WPARAM wParam, LPARAM lParam) @@ -138,8 +138,8 @@ WIN_WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) fprintf(log, " -- 0x%X, 0x%X\n", wParam, lParam); fclose(log); } - #endif + if (IME_HandleMessage(hwnd, msg, wParam, &lParam, data->videodata)) return 0; @@ -522,6 +522,7 @@ WIN_WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) { //printf("Got Touch Event!\n"); +#ifdef WMMSG_DEBUG FILE *log = fopen("wmmsg.txt", "a"); fprintf(log, "Received Touch Message: %p ", hwnd); if (msg > MAX_WMMSG) { @@ -531,6 +532,7 @@ WIN_WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) } fprintf(log, "WM_TOUCH = %d -- 0x%X, 0x%X\n",msg, wParam, lParam); fclose(log); +#endif } break; @@ -538,6 +540,7 @@ WIN_WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) { //printf("Got Touch Event!\n"); +#ifdef WMMSG_DEBUG FILE *log = fopen("wmmsg.txt", "a"); fprintf(log, "Received Gesture Message: %p ", hwnd); if (msg > MAX_WMMSG) { @@ -547,7 +550,7 @@ WIN_WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) } fprintf(log, "WM_GESTURE = %d -- 0x%X, 0x%X\n",msg, wParam, lParam); fclose(log); - +#endif } break; } diff --git a/src/video/win32/SDL_win32video.h b/src/video/win32/SDL_win32video.h index 2f1f7f75b..36668c24d 100644 --- a/src/video/win32/SDL_win32video.h +++ b/src/video/win32/SDL_win32video.h @@ -32,13 +32,7 @@ #define UNICODE #endif #undef WINVER -//#define WINVER 0x500 /* Need 0x410 for AlphaBlend() and 0x500 for EnumDisplayDevices() */ -#define WINVER 0x601 /* Need 0x600 (_WIN32_WINNT_WIN7) for WM_Touch */ -#if (_WIN32_WINNT < 0x601) -#undef _WIN32_WINNT -#define _WIN32_WINNT 0x601 -#endif - +#define WINVER 0x500 /* Need 0x410 for AlphaBlend() and 0x500 for EnumDisplayDevices() */ #include