+
+#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;
#include <iostream>
#include "gamegl.h"
#include "MacCompatibility.h"
+
+#ifdef WIN32
#include <shellapi.h>
+#endif
+
#include "fmod.h"
#include "res/resource.h"
// 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;
const RGBColor rgbBlack = { 0x0000, 0x0000, 0x0000 };
-extern HDC hDC;
GLuint gFontList;
char gcstrMode [256] = "";
void ReportError (char * strError)
{
+#ifdef WIN32 // !!! FIXME. --ryan.
throw std::exception( strError);
+#endif
/* char errMsgCStr [256];
Str255 strErr;
void SetupDSpFullScreen ()
{
+#ifdef WIN32
LOGFUNC;
if (fullscreen)
}
ShowCursor(FALSE);
+#endif
}
void ShutdownDSp ()
{
+#ifdef WIN32
LOGFUNC;
if (fullscreen)
}
ShowCursor(TRUE);
+#endif
}
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
// --------------------------------------------------------------------------
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;
return false;
}
-
//------------------------------------------------------------------
// setup OpenGL
SetForegroundWindow(g_windowHandle);
SetFocus(g_windowHandle);
+#endif
glClear( GL_COLOR_BUFFER_BIT );
- SwapBuffers( hDC );
+ swap_gl_buffers();
// clear all states
glDisable( GL_ALPHA_TEST);
ilShutDown();
+#if USE_SDL
+ SDL_Quit();
+
+#elif (defined WIN32)
if (hRC)
{
wglMakeCurrent( NULL, NULL);
ShutdownDSp ();
ClipCursor(NULL);
+#endif
}
// --------------------------------------------------------------------------
static bool IsFocused()
{
+#ifdef WIN32
if (!g_focused)
return false;
if (IsIconic( g_windowHandle))
return false;
+#endif
return true;
}
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 ) )
DispatchMessage( &msg );
}
}
+ #endif
// game
DoUpdate(game);
}
// 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 ))
DispatchMessage(&msg);
}
}
+ #else
+ STUBBED("give up CPU but sniff the event queue");
+ #endif
}
}
// 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;
}
}
+#ifdef WIN32
void ClipMouseToWindow(HWND window)
{
RECT wRect;
return TRUE;
}
+#endif
int resolutionID(int width, int height)
{
return res;
}
+ #ifdef WIN32
int __stdcall WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nShowCmd)
{
int argc = 0;
return TRUE;
}
+ #endif
extern int channels[100];
extern FSOUND_SAMPLE * samp[100];
free(f);
}
+