From 4fd7b5ae0c17312458ac663e8ae557e21a0c811b Mon Sep 17 00:00:00 2001 From: Miklos Vajna Date: Wed, 30 Jan 2008 01:49:09 +0100 Subject: [PATCH] ifdef hasznalata a hordozhatosag novelese erdekeben Ez a patch nem torol semmi az eredeti kodbol, de javitja azt ugy, hogy Linux/GCC kornyezetben is leforduljon. --- SpaceShootGame/src/GameEngine.h | 5 ++ SpaceShootGame/src/ImageFile.cpp | 12 ++++ SpaceShootGame/src/ImageFile.h | 2 + SpaceShootGame/src/Makefile | 22 ++++++++ SpaceShootGame/src/OpenGLFramework.cpp | 8 +++ SpaceShootGame/src/OpenGLFramework.hpp | 6 ++ SpaceShootGame/src/SpaceGame.cpp | 87 ++++++++++++++++++++++++++++++++ SpaceShootGame/src/stdafx.h | 37 +++++++++++++ SpaceShootGame/src/vector.h | 2 + 9 files changed, 181 insertions(+), 0 deletions(-) create mode 100644 SpaceShootGame/src/Makefile diff --git a/SpaceShootGame/src/GameEngine.h b/SpaceShootGame/src/GameEngine.h index 5571ef0..01a18c4 100644 --- a/SpaceShootGame/src/GameEngine.h +++ b/SpaceShootGame/src/GameEngine.h @@ -107,7 +107,12 @@ public: virtual void InteractIt( GameObject * obj ) { } // párbeszéd virtual bool CollideIt( GameObject * obj, float& hit_time, Vector& hit_point ) { Sphere comb_sphere( obj->position, bounding_radius + obj->bounding_radius ); +#ifdef WIN32 Ray ray( position, velocity - obj->velocity ); +#else + Vector v = velocity - obj->velocity; + Ray ray( position, v ); +#endif if ( comb_sphere.Intersect( ray, hit_time ) ) { Vector hit_pos = position + velocity * hit_time; Vector obj_hit_pos = obj->position + obj->velocity * hit_time; diff --git a/SpaceShootGame/src/ImageFile.cpp b/SpaceShootGame/src/ImageFile.cpp index b56a95b..c0ce364 100644 --- a/SpaceShootGame/src/ImageFile.cpp +++ b/SpaceShootGame/src/ImageFile.cpp @@ -3,7 +3,11 @@ // // Szirmay-Kalos László (szirmay@iit.bme.hu). 2003. Május //******************************************************************** +#ifdef WIN32 #include +#else +#include "stdafx.h" +#endif #include "ImageFile.h" //----------------------------------------------------------------------- @@ -16,7 +20,11 @@ ImageFile :: ImageFile( char * inputfilename, int& width, int& height ) { if ( !inputfilename ) return; char path[160]; +#ifdef WIN32 sprintf(path, "images\\%s", inputfilename); // a képek az images alkönyvtárba vannak +#else + sprintf(path, "images/%s", inputfilename); // a képek az images alkönyvtárba vannak +#endif file = fopen(path, "rb"); if ( !file ) return; cerr << '\n' << path << " is loaded ..."; @@ -37,7 +45,11 @@ ImageFile :: ImageFile( char * inputfilename, int& width, int& height ) { void ImageFile :: ReadBMP( FILE * file, int& width, int& height ) { //----------------------------------------------------------------------- BITMAPFILEHEADER bitmapFileHeader; // bitmap fájlfej +#ifdef WIN32 fread(&bitmapFileHeader, sizeof(BITMAPFILEHEADER), 1, file); +#else + fread(&bitmapFileHeader, BITMAPFILEHEADER_SIZEOF, 1, file); +#endif if (bitmapFileHeader.bfType != 0x4D42 ) { // mágikus szám return; } diff --git a/SpaceShootGame/src/ImageFile.h b/SpaceShootGame/src/ImageFile.h index 030008d..ebbc09d 100644 --- a/SpaceShootGame/src/ImageFile.h +++ b/SpaceShootGame/src/ImageFile.h @@ -6,7 +6,9 @@ // 2003. Május //********************************************************************* #include +#ifdef WIN32 #include +#endif typedef unsigned char Byte; diff --git a/SpaceShootGame/src/Makefile b/SpaceShootGame/src/Makefile new file mode 100644 index 0000000..30ef490 --- /dev/null +++ b/SpaceShootGame/src/Makefile @@ -0,0 +1,22 @@ +CXXFLAGS += -g +LDFLAGS += -lGL -lglut -lm + +all: SpaceGame images models + +images: + ln -s ../images + +models: + ln -s ../models + +GameEngine.o: GameEngine.cpp GameEngine.h stdafx.h color.h vector.h \ + ImageFile.h OpenGLFramework.hpp +ImageFile.o: ImageFile.cpp stdafx.h ImageFile.h +OpenGLFramework.o: OpenGLFramework.cpp stdafx.h ../res/resource.h \ + OpenGLFramework.hpp +SpaceGame.o: SpaceGame.cpp GameEngine.h stdafx.h color.h vector.h \ + ImageFile.h OpenGLFramework.hpp +SpaceGame: GameEngine.o ImageFile.o OpenGLFramework.o SpaceGame.o + +clean: + rm -f images models SpaceGame *.o diff --git a/SpaceShootGame/src/OpenGLFramework.cpp b/SpaceShootGame/src/OpenGLFramework.cpp index d77bb37..6309570 100644 --- a/SpaceShootGame/src/OpenGLFramework.cpp +++ b/SpaceShootGame/src/OpenGLFramework.cpp @@ -3,7 +3,9 @@ // // Antal György, 2003. Május. //************************************************************************* // +#ifdef WIN32 #include +#endif #include #include "stdafx.h" #include "../res/resource.h" @@ -42,6 +44,7 @@ bool Application :: GetKeyStatus(int platformIndependentKeyCode) { return status; } +#ifdef WIN32 if (applicationType == MsWindowsApplication) { short vkeyCode; switch (platformIndependentKeyCode) { @@ -65,6 +68,7 @@ bool Application :: GetKeyStatus(int platformIndependentKeyCode) { if (status & MsWinKeyIsDown) return true; } +#endif return false; } @@ -72,7 +76,9 @@ bool Application :: GetKeyStatus(int platformIndependentKeyCode) { void Application::SwapBuffers() { // buffercsere //----------------------------------------------------------------- if (applicationType == GlutApplication) glutSwapBuffers(); +#ifdef WIN32 if (applicationType == MsWindowsApplication) ::SwapBuffers(wglGetCurrentDC()); +#endif } //----------------------------------------------------------------- @@ -224,6 +230,7 @@ int main(int argc, char * argv[]) { } +# ifdef WIN32 //----------------------------------------------------------------- // *********************************** 2. MsWindow implementáció //----------------------------------------------------------------- @@ -395,3 +402,4 @@ int WINAPI WinMain(HINSTANCE hInstance, if (gGLContext != NULL) wglDeleteContext(gGLContext); return 0; } +#endif \ No newline at end of file diff --git a/SpaceShootGame/src/OpenGLFramework.hpp b/SpaceShootGame/src/OpenGLFramework.hpp index 0ce38e1..3a60f02 100644 --- a/SpaceShootGame/src/OpenGLFramework.hpp +++ b/SpaceShootGame/src/OpenGLFramework.hpp @@ -5,9 +5,15 @@ //************************************************************************* // #pragma once +#ifdef WIN32 #include #include #include +#else +#include +#include +#include +#endif // alkalmazás típusa enum ApplicationType {UnknownApplication, GlutApplication, MsWindowsApplication}; diff --git a/SpaceShootGame/src/SpaceGame.cpp b/SpaceShootGame/src/SpaceGame.cpp index ac7a536..de5ea39 100644 --- a/SpaceShootGame/src/SpaceGame.cpp +++ b/SpaceShootGame/src/SpaceGame.cpp @@ -164,7 +164,11 @@ public: class Explosion : public ParticleSystem { // robbanás //-------------------------------------------- public: +#ifdef WIN32 Explosion( Vector pos0 ) : ParticleSystem( pos0, "explosion.bmp" ) { +#else + Explosion( Vector pos0 ) : ParticleSystem( pos0, (char*)"explosion.bmp" ) { +#endif Emit( 200 ); } @@ -186,7 +190,11 @@ public: GameObject * source; // a lövedéket kilövo játékobjektum public: PhotonRocket( Vector& pos0, Vector& shooter_velocity, GameObject * source0 ) +#ifdef WIN32 : BillBoard( pos0, 0.3f, "photon.bmp" ) { +#else + : BillBoard( pos0, 0.3f, (char*)"photon.bmp" ) { +#endif velocity = shooter_velocity + shooter_velocity.UnitVector() * 2; age = 0; source = source0; @@ -229,15 +237,27 @@ class Ship : public TexturedObject { // az ellens struct Vector2 { float u, v;} * shiptext; // textúrakoordináták int nvertex; // csúcspontok száma public: +#ifdef WIN32 Ship( Vector& pos0 ) : TexturedObject( pos0, "ship_texture.bmp" ) { +#else + Ship( Vector& pos0 ) : TexturedObject( pos0, (char*)"ship_texture.bmp" ) { +#endif mass = 0.1f; velocity = Vector( 0.1f, 0.2f, 0.1f ); ai_state = CHASE_AVATAR; last_shot = 0; +#ifdef WIN32 FILE * fgeom = fopen("models\\ship.geo","r"); +#else + FILE * fgeom = fopen("models/ship.geo","r"); +#endif if ( fgeom == NULL ) { +#ifdef WIN32 cerr << "models\\ship.geo not found\n"; +#else + cerr << "models/ship.geo not found\n"; +#endif exit( 0 ); } fscanf(fgeom,"%d", &nvertex); @@ -252,14 +272,26 @@ public: bounding_radius = sqrt(r2); fclose(fgeom); +#ifdef WIN32 FILE * ftext = fopen("models\\ship.tex","r"); +#else + FILE * ftext = fopen("models/ship.tex","r"); +#endif if ( ftext == NULL ) { +#ifdef WIN32 cerr << "models\\ship.tex not found\n"; +#else + cerr << "models/ship.tex not found\n"; +#endif exit( 0 ); } fscanf(ftext,"%d", &nvertex); shiptext = new Vector2[nvertex]; +#ifdef WIN32 for(i = 0; i < nvertex; i++) +#else + for(int i = 0; i < nvertex; i++) +#endif fscanf(ftext, "%f %f\n", &shiptext[i].u, &shiptext[i].v); fclose(ftext); } @@ -422,10 +454,18 @@ public: sprintf(buffer, "%1.0f, %1.0f, %1.0f", position.x, position.y, position.z); Message(0.55f, 0.55f, buffer); } else { +#ifdef WIN32 Message( 0.25f, 0.60f, "You have been killed"); +#else + Message( 0.25f, 0.60f, (char*)"You have been killed"); +#endif sprintf(buffer, "You still have %d lifes.", lifes); Message( 0.25f, 0.55f, buffer); +#ifdef WIN32 Message( 0.25f, 0.50f, "Press 's' to continue!"); +#else + Message( 0.25f, 0.50f, (char*)"Press 's' to continue!"); +#endif } sprintf(buffer, "FPS: %3.2f", fps); Message( 0.8f, 0.9f, buffer); @@ -443,7 +483,12 @@ public: if ( input->GetKeyStatus('a') ) rocket_force = Head() * (-ROCKET_POWER); if ( input->GetKeyStatus(' ') && last_shot > 1 ) { +#ifdef WIN32 root -> Join( new PhotonRocket(position + velocity, velocity, this) ); +#else + Vector v = position + velocity; + root -> Join( new PhotonRocket(v, velocity, this) ); +#endif last_shot = 0; } } else { @@ -470,28 +515,57 @@ public: //-------------------------------------------- public: SpaceShootGame( int window_width, int window_height ) +#ifdef WIN32 : GameEngine( "Space Shoot Game", window_width, window_height ) { } +#else + : GameEngine( (char*)"Space Shoot Game", window_width, window_height ) { } +#endif void Init( ) { // játékmotor létrehozása GameEngine :: Init(); mouseSensitivity = 0.5; +#ifdef WIN32 world = new Space( "stars.bmp" ); // az ur létrehozása +#else + world = new Space( (char*)"stars.bmp" ); // az ur létrehozása +#endif // az urhajók létrehozása +#ifdef WIN32 world -> Join( new Ship( Vector(-1, 2, 2) ) ); world -> Join( new Ship( Vector(-4, -2, 3) ) ); world -> Join( new Ship( Vector(-3, 1, 3) ) ); world -> Join( new Ship( Vector( 4, 1, 3) ) ); world -> Join( new Ship( Vector( 2, -3, -1) ) ); world -> Join( new Ship( Vector( 0, -4, -2) ) ); +#else + Vector v; + world -> Join( new Ship( v = Vector(-1, 2, 2) ) ); + world -> Join( new Ship( v = Vector(-4, -2, 3) ) ); + world -> Join( new Ship( v = Vector(-3, 1, 3) ) ); + world -> Join( new Ship( v = Vector( 4, 1, 3) ) ); + world -> Join( new Ship( v = Vector( 2, -3, -1) ) ); + world -> Join( new Ship( v = Vector( 0, -4, -2) ) ); +#endif // a bolygók létrehozása +#ifdef WIN32 Planet * sun = new Planet( Vector( 0, 0, 0 ), 3.0f, "sun.bmp" ); +#else + Planet * sun = new Planet( v = Vector( 0, 0, 0 ), 3.0f, (char*)"sun.bmp" ); +#endif world -> Join( sun ); +#ifdef WIN32 sun -> AddChild( new Planet( Vector( 6, 0, 0 ), 0.2f, "mercury.bmp" ) ); sun -> AddChild( new Planet( Vector( 7, 0, 0 ), 0.4f, "venus.bmp" ) ); Planet * earth = new Planet( Vector( 8, 0, 0 ), 0.4f, "earth.bmp", 23 ); +#else + sun -> AddChild( new Planet( v = Vector( 6, 0, 0 ), 0.2f, (char*)"mercury.bmp" ) ); + sun -> AddChild( new Planet( v = Vector( 7, 0, 0 ), 0.4f, (char*)"venus.bmp" ) ); + Planet * earth = new Planet( v = Vector( 8, 0, 0 ), 0.4f, (char*)"earth.bmp", 23 ); +#endif sun -> AddChild( earth ); +#ifdef WIN32 earth -> AddChild( new Planet( Vector( 9, 0, 0 ), 0.15f, "moon.bmp" ) ); sun -> AddChild( new Planet( Vector( 10, 0, 0 ), 0.3f, "mars.bmp", 25 ) ); @@ -503,6 +577,19 @@ public: // az avatár létrehozása avatar = new Self( Vector(0, -15, 2) ); +#else + earth -> AddChild( new Planet( v = Vector( 9, 0, 0 ), 0.15f, (char*)"moon.bmp" ) ); + + sun -> AddChild( new Planet( v = Vector( 10, 0, 0 ), 0.3f, (char*)"mars.bmp", 25 ) ); + sun -> AddChild( new Planet( v = Vector(11, 0, 0 ), 0.7f, (char*)"jupiter.bmp", 3, 0.8f, 0.9f ) ); + sun -> AddChild( new Planet( v = Vector(12, 0, 0 ), 0.6f, (char*)"saturn.bmp", 26, 0.7f, 1.2f ) ); + sun -> AddChild( new Planet( v = Vector(13, 0, 0 ), 0.5f, (char*)"uranus.bmp", 82, 0.6f, 0.8f ) ); + sun -> AddChild( new Planet( v = Vector(15, 0, 0 ), 0.5f, (char*)"neptun.bmp", 29, 0.6f, 0.8f ) ); + sun -> AddChild( new Planet( v = Vector(17, 0, 0 ), 0.2f, (char*)"pluto.bmp", 62 ) ); + + // az avatár létrehozása + avatar = new Self( v = Vector(0, -15, 2) ); +#endif world -> Join( avatar ); } }; diff --git a/SpaceShootGame/src/stdafx.h b/SpaceShootGame/src/stdafx.h index ab26682..994a3fd 100644 --- a/SpaceShootGame/src/stdafx.h +++ b/SpaceShootGame/src/stdafx.h @@ -2,14 +2,51 @@ #include #include +#ifdef WIN32 #include +#endif #include #ifndef M_PI #define M_PI 3.14158692 #endif +#ifdef WIN32 #include +#else +#include +#endif #include +#ifdef WIN32 #define WIN32_LEAN_AND_MEAN // Dobjuk ki a felesleges windows dolgokat #include +#else +using namespace std; + +#define FALSE 0 +#define TRUE 1 + +#define BITMAPFILEHEADER_SIZEOF 14 + +typedef struct tagBITMAPFILEHEADER { + short bfType; + int bfSize; + short bfReserved1; + short bfReserved2; + int bfOffBits; +} BITMAPFILEHEADER; + +typedef struct tagBITMAPINFOHEADER { + int biSize; + long biWidth; + long biHeight; + short biPlanes; + short biBitCount; + int biCompression; + int biSizeImage; + long biXPelsPerMeter; + long biYPelsPerMeter; + int biClrUsed; + int biClrImportant; +} BITMAPINFOHEADER; +#endif diff --git a/SpaceShootGame/src/vector.h b/SpaceShootGame/src/vector.h index 56e9856..9099fa1 100644 --- a/SpaceShootGame/src/vector.h +++ b/SpaceShootGame/src/vector.h @@ -114,6 +114,8 @@ class Matrix { float * GetArray() { return &m[0][0]; } }; +#ifdef WIN32 ostream& operator<<( ostream& s, Vector& v ); +#endif #endif \ No newline at end of file -- 1.5.4.rc5-dirty