From 357a451150c18b27f99cecd5f9d13be1ae5a9fdf Mon Sep 17 00:00:00 2001 From: Matthijs Kooijman Date: Sun, 10 Jun 2007 20:37:08 +0200 Subject: [PATCH] * Add #ifdef WIN32 to make main.cpp compile on linux. * Do singleton pointer magic with long instead of int to make it work on linux64, should still work on windows as well. --- ABM2/Engine/InputTask.h | 10 ++++++++++ ABM2/Engine/Kernel.h | 4 ++++ ABM2/Engine/VideoUpdate.cpp | 2 ++ ABM2/Engine/VideoUpdate.h | 7 ++++--- ABM2/Engine/engine.h | 1 - ABM2/Engine/misc.h | 7 +++++-- ABM2/Engine/singleton.h | 6 ++++-- ABM2/Playground.h | 8 ++++++++ ABM2/main.cpp | 28 ++++++++++++++++++++++++++-- 9 files changed, 63 insertions(+), 10 deletions(-) diff --git a/ABM2/Engine/InputTask.h b/ABM2/Engine/InputTask.h index e3363f6..337cd55 100755 --- a/ABM2/Engine/InputTask.h +++ b/ABM2/Engine/InputTask.h @@ -10,8 +10,16 @@ #endif // _MSC_VER > 1000 #include "engine.h" +#ifdef WIN32 #define DIRECTINPUT_VERSION 0x0800 #include +#endif // WIN32 + + +#ifndef WIN32 +/* HACK to make this compile */ +#define BYTE unsigned char +#endif // !WIN32 class CInputTask : public ITask { @@ -50,9 +58,11 @@ public: //static bool inline mouseStillUp(int button) { return (!curMouse(button))&&(!oldMouse(button)); } AUTO_SIZE; +#ifdef WIN32 private: LPDIRECTINPUT8 din; // the pointer to our DirectInput interface LPDIRECTINPUTDEVICE8 dinkeyboard; // the pointer to the keyboard device +#endif }; #endif // !defined(AFX_KEYBOARDTASK_H__4953EF06_7C18_4433_B590_47E045E43576__INCLUDED_) diff --git a/ABM2/Engine/Kernel.h b/ABM2/Engine/Kernel.h index 667cf7c..3cd5bf3 100755 --- a/ABM2/Engine/Kernel.h +++ b/ABM2/Engine/Kernel.h @@ -25,7 +25,11 @@ public: int Execute(); +#ifdef WIN32 bool AddTask(CMMPointer &t); +#else + bool AddTask(CMMPointer t); +#endif void SuspendTask(CMMPointer &t); void ResumeTask(CMMPointer &t); void RemoveTask(CMMPointer &t); diff --git a/ABM2/Engine/VideoUpdate.cpp b/ABM2/Engine/VideoUpdate.cpp index 8499568..9ff6db9 100755 --- a/ABM2/Engine/VideoUpdate.cpp +++ b/ABM2/Engine/VideoUpdate.cpp @@ -7,6 +7,7 @@ #include "VideoUpdate.h" // include the Direct3D Library file +#ifdef WIN32 #pragma comment (lib, "d3d9.lib") #pragma comment (lib, "d3dx9.lib") @@ -113,3 +114,4 @@ void CVideoUpdate::Stop() { // SDL_QuitSubSystem(SDL_INIT_VIDEO); } +#endif // WIN32 diff --git a/ABM2/Engine/VideoUpdate.h b/ABM2/Engine/VideoUpdate.h index b8273c5..a859bd1 100755 --- a/ABM2/Engine/VideoUpdate.h +++ b/ABM2/Engine/VideoUpdate.h @@ -9,12 +9,13 @@ #pragma once #endif // _MSC_VER > 1000 +#ifdef WIN32 #include #include #include "engine.h" extern LPDIRECT3DDEVICE9 d3ddev; // the pointer to the device class - +#endif // WIN32 class CVideoUpdate : public ITask { public: @@ -28,10 +29,10 @@ public: bool Start(); void Update(); void Stop(); - +#ifdef WIN32 private: LPDIRECT3D9 d3d; // the pointer to our Direct3D interface +#endif //WIN32 }; - #endif // !defined(AFX_VIDEOUPDATE_H__FB4B263B_4FA7_4700_BB70_EE5CB1768E83__INCLUDED_) diff --git a/ABM2/Engine/engine.h b/ABM2/Engine/engine.h index cd685fa..6a3ac35 100755 --- a/ABM2/Engine/engine.h +++ b/ABM2/Engine/engine.h @@ -3,7 +3,6 @@ #pragma warning ( disable : 4786 ) - #include #include #include diff --git a/ABM2/Engine/misc.h b/ABM2/Engine/misc.h index 843c97f..55b3f99 100755 --- a/ABM2/Engine/misc.h +++ b/ABM2/Engine/misc.h @@ -1,8 +1,11 @@ #ifndef MISC_H_INCLUDED #define MISC_H_INCLUDED - - +#ifndef WIN32 +/* HACK to get this to compile */ +#define max(a,b) (a>b?a:b) +#define min(a,b) (a*)(T*)1; - ms_singleton = (T*)((int)this + offset); + // This used to say "int" instead of long, but that breaks + // on 64 bit linux at least + long offset = (long)(T*)1 - (long)(Singleton *)(T*)1; + ms_singleton = (T*)((long)this + offset); } ~Singleton() { diff --git a/ABM2/Playground.h b/ABM2/Playground.h index 1c99ab4..bed17cc 100755 --- a/ABM2/Playground.h +++ b/ABM2/Playground.h @@ -33,19 +33,25 @@ public: int getFieldCenterX(); int getFieldCenterY(); private: +#ifdef WIN32 int x,y; LPDIRECT3DTEXTURE9 texture; +#endif // WIN32 }; class Item { public: +#ifdef WIN32 Item(LPDIRECT3DTEXTURE9 t, int texnr, int subwidth, int subheight, int colnr, int rownr); +#endif // WIN32 ~Item(); void Draw(); int col, row, tex_num, subitem_height, subitem_width; private: +#ifdef WIN32 LPDIRECT3DTEXTURE9 texture; +#endif // WIN32 }; class Playground : public ITask @@ -56,6 +62,7 @@ public: void Stop(); AUTO_SIZE; private: +#ifdef WIN32 LPDIRECT3DTEXTURE9 background; LPDIRECT3DTEXTURE9 foreground; @@ -68,4 +75,5 @@ private: void move_left(); DWORD old_counter; +#endif // WIN32 }; diff --git a/ABM2/main.cpp b/ABM2/main.cpp index 061cce2..7348a15 100755 --- a/ABM2/main.cpp +++ b/ABM2/main.cpp @@ -1,6 +1,15 @@ // include the basic windows header files and the Direct3D header file +#ifdef WIN32 #include #include +#endif + +//#ifndef WIN32 + /* HACKS */ +#define max(a,b) (a>b?a:b) +#define min(a,b) (a