JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
minor rearrangements and the beginnings of a Windows port.
authorJoshua Grams <josh@qualdan.com>
Thu, 2 Feb 2006 22:38:39 +0000 (22:38 +0000)
committerJoshua Grams <josh@qualdan.com>
Thu, 2 Feb 2006 22:38:39 +0000 (22:38 +0000)
INSTALL
common.h
file.c
file.h
main.c

diff --git a/INSTALL b/INSTALL
index aa22cc8..607ea94 100644 (file)
--- a/INSTALL
+++ b/INSTALL
@@ -28,4 +28,3 @@ INSTALLING
        before building. If you change these settings in the Makefile after
        building, you'll have to "make clean" and build again before
        installing.
-
index 069f677..59268ae 100644 (file)
--- a/common.h
+++ b/common.h
@@ -1,17 +1,8 @@
 #ifndef VOR_COMMON_H
 #define VOR_COMMON_H
 
-#ifndef NULL
-#define NULL 0
-#endif
-
-#ifndef true
-#define true 1
-#endif
-
-#ifndef false
-#define false 0
-#endif
+#include <stdbool.h>
+#include <stddef.h>
 
 #ifndef max
 #define max(a, b) ((a) > (b) ? (a) : (b))
@@ -28,4 +19,8 @@
 #define CONDERROR(a) if((a)) {initerror = strdup(SDL_GetError());return 1;}
 #define NULLERROR(a) CONDERROR((a) == NULL)
 
+#ifdef WIN32
+# include <windows.h>
+#endif
+
 #endif // VOR_COMMON_H
diff --git a/file.c b/file.c
index ee14299..4b7872a 100644 (file)
--- a/file.c
+++ b/file.c
@@ -19,7 +19,9 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
-#include <sys/stat.h>
+#ifndef WIN32
+# include <sys/stat.h>
+#endif
 #include <sys/types.h>
 #include <unistd.h>
 
@@ -43,7 +45,7 @@ add_path(char *path, char *file)
        s = malloc(2+plen+flen);
        if(!s) return NULL;
        memcpy(s, path, plen);
-       s[plen] = '/';
+       s[plen] = PATH_SEPARATOR;
        memcpy(s+plen+1, file, flen+1);
        return s;
 }
@@ -54,7 +56,29 @@ add_data_path(char *filename)
        return add_path(g_data_dir, filename);
 }
 
-int
+#ifdef WIN32
+
+bool
+is_dir(char *dirname)
+{
+       WIN32_FILE_ATTRIBUTE_DATA buf;
+       if(!GetFileAttributesEx(dirname, GetFileExInfoStandard, &buf))
+               return false;
+       return buf.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY;
+}
+
+bool
+is_file(char *filename)
+{
+       WIN32_FILE_ATTRIBUTE_DATA buf;
+       if(!GetFileAttributesEx(filename, GetFileExInfoStandard, &buf))
+               return false;
+       return buf.dwFileAttributes & FILE_ATTRIBUTE_NORMAL;
+}
+
+#else /* !WIN32 */
+
+bool
 is_dir(char *dirname)
 {
        struct stat buf;
@@ -62,7 +86,7 @@ is_dir(char *dirname)
        return S_ISDIR(buf.st_mode);
 }
 
-int
+bool
 is_file(char *filename)
 {
        struct stat buf;
@@ -70,13 +94,15 @@ is_file(char *filename)
        return S_ISREG(buf.st_mode);
 }
 
-int
+#endif /* !WIN32 */
+
+bool
 find_data_dir(void)
 {
        int i;
        char *data_options[3] = {
-               "./data",
                getenv("VOR_DATA"),
+               "data",
                DATA_PREFIX
        };
 
@@ -93,7 +119,7 @@ find_data_dir(void)
        return false;
 }
 
-int
+bool
 find_score_file(void)
 {
        char *dir, *s;
@@ -110,13 +136,10 @@ find_score_file(void)
        } else return false;
 }
 
-int
+bool
 find_files(void)
 {
-       int r;
-       r = find_data_dir();
-       find_score_file();
-       return r;
+       return find_data_dir() && find_score_file();
 }
 
 FILE *
diff --git a/file.h b/file.h
index f9249e9..f376213 100644 (file)
--- a/file.h
+++ b/file.h
 #ifndef VOR_FILE_H
 #define VOR_FILE_H
 
+#include <stdbool.h>
 #include <stdio.h>
-#include <sys/types.h>
-
-extern char *g_data_dir;
-extern char *g_score_file;
-extern mode_t g_score_mode;
 
 char *add_data_path(char *filename);
-int is_dir(char *dirname);
-int is_file(char *filename);
-int find_data_dir(void);
-int find_score_file(void);
-int find_files(void);
+bool is_dir(char *dirname);
+bool is_file(char *filename);
+bool find_data_dir(void);
+bool find_score_file(void);
+bool find_files(void);
 FILE *open_score_file(char *mode);
 
+#ifdef WIN32
+# define PATH_SEPARATOR '\\'
+#else
+# define PATH_SEPARATOR '/'
+#endif
+
 #endif // VOR_FILE_H
diff --git a/main.c b/main.c
index a0b50cc..b5dc64d 100644 (file)
--- a/main.c
+++ b/main.c
@@ -329,7 +329,7 @@ init(void) {
                // Initialize SDL with audio and video
                if(SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO) != 0) {
                        opt_sound = 0;
-                       printf ("Can't open sound, starting without it\n");
+                       fputs("Can't open sound, starting without it\n", stderr);
                        atexit(SDL_Quit);
                } else {
                        atexit(SDL_Quit);
@@ -600,14 +600,10 @@ gameloop() {
 
                        new_rocks();
 
-                       // INERTIA
-                       shipx += shipdx*t_frame;
-                       shipy += shipdy*t_frame;
-
                        // SCROLLING
-                       tmp = (shipy-YSCROLLTO)/25 + (shipdy-screendy);
+                       tmp = (shipy+shipdy*t_frame-YSCROLLTO)/25 + (shipdy-screendy);
                        screendy += tmp * t_frame/12;
-                       tmp = (shipx-XSCROLLTO)/25 + (shipdx-screendx);
+                       tmp = (shipx+shipdx*t_frame-XSCROLLTO)/25 + (shipdx-screendx);
                        screendx += tmp * t_frame/12;
                        // taper off so we don't hit the barrier abruptly.
                        // (if we would hit in < 2 seconds, adjust to 2 seconds).
@@ -621,8 +617,8 @@ gameloop() {
                        xscroll = screendx * t_frame;
                        yscroll = screendy * t_frame;
 
-                       shipx -= xscroll;
-                       shipy -= yscroll;
+                       shipx += shipdx*t_frame - xscroll;
+                       shipy += shipdy*t_frame - yscroll;
 
                        // move bang center
                        bangx += bangdx*t_frame - xscroll;