]> git.jsancho.org Git - lugaru.git/commitdiff
Game builds and runs...need more input.
authorRyan C. Gordon <icculus@icculus.org>
Fri, 5 Aug 2005 18:02:11 +0000 (18:02 +0000)
committerRyan C. Gordon <icculus@icculus.org>
Fri, 5 Aug 2005 18:02:11 +0000 (18:02 +0000)
Source/Game.h
Source/Models.cpp
Source/OpenGL_Windows.cpp
makefile

index 92bac482fa967aa2c59d64c384f70727f41d3d83..c4f033eb4c8e4cb7e81e6d74c5f563c7c1ef5960 100644 (file)
@@ -297,4 +297,9 @@ static __forceinline void swap_gl_buffers(void)
 #define LONGLONGCONST(x) (x)
 #endif
 
+extern "C" { void UndefinedSymbolToExposeStubbedCode(void); }
+//#define STUBBED(x) UndefinedSymbolToExposeStubbedCode();
+#define STUBBED(x) { static bool seen = false; if (!seen) { seen = true; fprintf(stderr, "STUBBED: %s at %s:%d\n", x, __FILE__, __LINE__); } }
+//#define STUBBED(x)
+
 #endif
index e96fe9ff9627d9f82c40d51aa168b4cfad178dff..ee55d9fbf3ef5894f269e109872d01ec43c7a3ab 100644 (file)
@@ -500,7 +500,7 @@ bool Model::load(char *filename,bool texture )
        type = normaltype;
        color=0;
 
-       tfile=fopen( filename, "rb" );
+       tfile=fopen( ConvertFileName(filename), "rb" );
        // read model settings
 
 
index dcc6c464889c49bc07e556a631d8c0871f49df28..6ac0dd89093d8a19a135ffa82ef1ff05c529b13d 100644 (file)
@@ -1,10 +1,19 @@
+
+#ifdef WIN32
 #include <vld.h>
+#endif
+
 #include "Game.h"
+#include "IL/il.h"
+#include "IL/ilu.h"
+#include "IL/ilut.h"
 
 // ADDED GWC
+#ifdef _MSC_VER
 #pragma comment(lib, "opengl32.lib")
 #pragma comment(lib, "glu32.lib")
 #pragma comment(lib, "glaux.lib")
+#endif
 
 extern bool buttons[3];
 extern float multiplier;
@@ -61,7 +70,11 @@ extern float volume;
 #include <iostream>
 #include "gamegl.h"
 #include "MacCompatibility.h"
+
+#ifdef WIN32
 #include <shellapi.h>
+#endif
+
 #include "fmod.h"
 
 #include "res/resource.h"
@@ -92,14 +105,37 @@ void CleanUp (void);
 
 
 // statics/globals (internal only) ------------------------------------------
+#ifndef WIN32
+typedef struct tagPOINT { 
+  int x;
+  int y;
+} POINT, *PPOINT; 
+#endif
+
+#if USE_SDL
+void sdlGetCursorPos(POINT *pt)
+{
+    int x, y;
+    SDL_GetMouseState(&x, &y);
+    pt->x = x;
+    pt->y = y;
+}
+#define GetCursorPos(x) sdlGetCursorPos(x)
+#define SetCursorPos(x, y) SDL_WarpMouse(x, y)
+#define ScreenToClient(x, pt)
+#define ClientToScreen(x, pt)
+#define MessageBox(hwnd,text,title,flags) STUBBED("msgbox")
+#endif
 
 Point delta;
 
+#ifdef WIN32
 static const char g_wndClassName[]={ "LUGARUWINDOWCLASS" };
-
 static HINSTANCE g_appInstance;
 static HWND g_windowHandle;
 static HGLRC hRC;
+#endif
+
 static bool g_button, fullscreen = true;
 
 
@@ -121,7 +157,6 @@ int kContextHeight;
 
 const RGBColor rgbBlack = { 0x0000, 0x0000, 0x0000 };
 
-extern HDC hDC;
 GLuint gFontList;
 char gcstrMode [256] = "";
 
@@ -134,7 +169,9 @@ Game * pgame = 0;
 
 void ReportError (char * strError)
 {
+#ifdef WIN32  // !!! FIXME.  --ryan.
        throw std::exception( strError);
+#endif
 
        /*      char errMsgCStr [256];
        Str255 strErr;
@@ -149,6 +186,7 @@ void ReportError (char * strError)
 
 void SetupDSpFullScreen ()
 {
+#ifdef WIN32
        LOGFUNC;
 
        if (fullscreen)
@@ -170,11 +208,13 @@ void SetupDSpFullScreen ()
        }
 
        ShowCursor(FALSE);
+#endif
 }
 
 
 void ShutdownDSp ()
 {
+#ifdef WIN32
        LOGFUNC;
 
        if (fullscreen)
@@ -183,6 +223,7 @@ void ShutdownDSp ()
        }
 
        ShowCursor(TRUE);
+#endif
 }
 
 
@@ -192,13 +233,54 @@ void ShutdownDSp ()
 
 void DrawGL (Game & game)
 {
+#ifdef WIN32
        if (hDC == 0)
                return;
+#endif
 
        game.DrawGLScene();
 }
 
 
+#if USE_SDL
+static inline int clamp_sdl_mouse_button(Uint8 button)
+{
+    if ((button >= 1) && (button <= 3))
+        return button - 1;
+    return -1;
+}
+
+static void sdlEventProc(const SDL_Event &e)
+{
+    int val;
+    switch(e.type)
+       {
+               case SDL_MOUSEBUTTONDOWN:
+                       {
+                val = clamp_sdl_mouse_button(e.button.button);
+                if (val >= 0)
+                {
+                    if (val == 0)
+                                   g_button = true;
+                               buttons[val] = true;
+                }
+                       }
+                       return;
+
+               case SDL_MOUSEBUTTONUP:
+                       {
+                val = clamp_sdl_mouse_button(e.button.button);
+                if (val >= 0)
+                {
+                    if (val == 0)
+                                   g_button = false;
+                               buttons[val] = false;
+                }
+                       }
+            return;
+    }
+}
+#endif
 
 // --------------------------------------------------------------------------
 
@@ -502,6 +584,26 @@ Boolean SetUp (Game & game)
 
        SetupDSpFullScreen();
 
+#if USE_SDL
+    if (!SDL_WasInit(SDL_INIT_VIDEO))
+    {
+        if (SDL_Init(SDL_INIT_VIDEO) == -1)
+        {
+            fprintf(stderr, "SDL_Init() failed: %s\n", SDL_GetError());
+            return false;
+        }
+    }
+
+    Uint32 sdlflags = SDL_OPENGL;
+    SDL_WM_SetCaption("Lugaru", "lugaru");
+    SDL_ShowCursor(0);
+    if (SDL_SetVideoMode(kContextWidth, kContextHeight, 0, sdlflags) == NULL)
+    {
+        fprintf(stderr, "SDL_SetVideoMode() failed: %s\n", SDL_GetError());
+        return false;
+    }
+
+#elif (defined WIN32)
        //------------------------------------------------------------------
        // create window
        int x = 0, y = 0;
@@ -541,7 +643,6 @@ Boolean SetUp (Game & game)
                return false;
        }
 
-
        //------------------------------------------------------------------
        // setup OpenGL
 
@@ -610,9 +711,10 @@ Boolean SetUp (Game & game)
 
        SetForegroundWindow(g_windowHandle);
        SetFocus(g_windowHandle);
+#endif
 
        glClear( GL_COLOR_BUFFER_BIT );
-       SwapBuffers( hDC );
+       swap_gl_buffers();
 
        // clear all states
        glDisable( GL_ALPHA_TEST);
@@ -869,6 +971,10 @@ void CleanUp (void)
 
        ilShutDown();
 
+#if USE_SDL
+    SDL_Quit();
+
+#elif (defined WIN32)
        if (hRC)
        {
                wglMakeCurrent( NULL, NULL);
@@ -891,6 +997,7 @@ void CleanUp (void)
 
        ShutdownDSp ();
        ClipCursor(NULL);
+#endif
 }
 
 // --------------------------------------------------------------------------
@@ -900,6 +1007,7 @@ static bool g_focused = true;
 
 static bool IsFocused()
 {
+#ifdef WIN32
        if (!g_focused)
                return false;
 
@@ -908,6 +1016,7 @@ static bool IsFocused()
 
        if (IsIconic( g_windowHandle))
                return false;
+#endif
 
        return true;
 }
@@ -938,6 +1047,19 @@ int main (void)
                                        gameFocused = true;
 
                                        // check windows messages
+                    #if USE_SDL
+                                       SDL_Event e;
+                                       // message pump
+                                       while( SDL_PollEvent( &e ) )
+                                       {
+                                               if( e.type == SDL_QUIT )
+                                               {
+                                                       gDone=true;
+                                                       break;
+                                               }
+                        sdlEventProc(e);
+                                       }
+                    #elif (defined WIN32)
                                        MSG msg;
                                        // message pump
                                        while( PeekMessage( &msg, NULL, 0, 0, PM_REMOVE | PM_NOYIELD ) )
@@ -953,6 +1075,7 @@ int main (void)
                                                        DispatchMessage( &msg );
                                                }
                                        }
+                    #endif
 
                                        // game
                                        DoUpdate(game);
@@ -967,6 +1090,7 @@ int main (void)
                                        }
 
                                        // game is not in focus, give CPU time to other apps by waiting for messages instead of 'peeking'
+                    #ifdef WIN32
                                        MSG msg;
                                        BOOL bRet;
                                        //if (GetMessage( &msg, g_windowHandle, 0, 0 ))
@@ -988,6 +1112,9 @@ int main (void)
                                                        DispatchMessage(&msg); 
                                                }
                                        }
+                    #else
+                    STUBBED("give up CPU but sniff the event queue");
+                    #endif
                                }
                        }
 
@@ -999,10 +1126,14 @@ int main (void)
 //             if(game.registernow){
                if(regnow)
                {
+            #ifndef WIN32
+            STUBBED("launch a web browser");
+            #else
                        char url[100];
                        sprintf(url,"http://www.wolfire.com/registerpc.html");
                        //                      LaunchURL(url);
                        ShellExecute(NULL, "open", url, NULL, NULL, SW_SHOWNORMAL);
+            #endif
                }
                return 0;
        }
@@ -1313,6 +1444,7 @@ int main (void)
        }
 
 
+#ifdef WIN32
        void ClipMouseToWindow(HWND window)
        {
                RECT wRect;
@@ -1566,6 +1698,7 @@ int main (void)
 
                return TRUE;
        }
+#endif
 
        int resolutionID(int width, int height)
        {
@@ -1667,6 +1800,7 @@ int main (void)
                return res;
        }
 
+    #ifdef WIN32
        int __stdcall WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nShowCmd)
        {
                int argc = 0;
@@ -1729,6 +1863,7 @@ int main (void)
                return TRUE;
 
        }
+    #endif
 
        extern int channels[100];
        extern FSOUND_SAMPLE * samp[100];
@@ -1875,3 +2010,4 @@ int main (void)
                free(f);
        }
 
+
index 7356dd39ae9d4331d41a31deb6dfa3bf10e57816..c672353c246a3bfadece582a04a4f511143460e2 100644 (file)
--- a/makefile
+++ b/makefile
@@ -37,6 +37,7 @@ INCLUDES := \
                        -I./OpenGL/ \
                        -I./OpenGL/GL \
                        -I$(SRCDIR) \
+                       -I$(SRCDIR)/devil/include \
 
 CFLAGS := -g -c $(OPT) $(INCLUDES) $(DEFINES) -fsigned-char
 CFLAGS += -w
@@ -49,7 +50,7 @@ ifeq ($(strip $(macosx)),true)
 else
   CFLAGS += -DPLATFORM_LINUX=1
   #CFLAGS += -msse -mmmx
-  LDFLAGS := -lSDL -lGL -lGLU -L$(RUNDIR) -lfmod
+  LDFLAGS := ./libSDL-1.2.so.0 -lGL -lGLU ./libfmod.so ./libIL.so.1 ./libILU.so.1 ./libILUT.so.1
 endif
 
 CXXFLAGS := $(CFLAGS)
@@ -83,10 +84,9 @@ SRCS := \
        DRIVER.CC \
        MD5.CC \
        SDLInput.cpp \
-
-UNUSED_SRCS := \
        OpenGL_Windows.cpp \
 
+
 OBJS := $(SRCS:.CC=.o)
 OBJS := $(OBJS:.cc=.o)
 OBJS := $(OBJS:.cpp=.o)