summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLudovic Pouzenc <ludovic@pouzenc.fr>2010-10-31 15:01:06 +0000
committerLudovic Pouzenc <ludovic@pouzenc.fr>2010-10-31 15:01:06 +0000
commit95ed30a9dcbb9c9bc947899fa066479f45fc5b4b (patch)
treec1f44a7d3fc4fb703fa3c08b214049d7509979c8
parentc8469d4a7c59d864e6bc0972f23ad725c5761854 (diff)
download2010-netlemmings-95ed30a9dcbb9c9bc947899fa066479f45fc5b4b.tar.gz
2010-netlemmings-95ed30a9dcbb9c9bc947899fa066479f45fc5b4b.tar.bz2
2010-netlemmings-95ed30a9dcbb9c9bc947899fa066479f45fc5b4b.zip
fonction init() intégrée vraiment, manque à mettre les pointeurs des SDL_Surface dans un struct qui sera passé à updateGraphics()
git-svn-id: file:///var/svn/2010-netlemmings/trunk@124 077b3477-7977-48bd-8428-443f22f7bfda
-rw-r--r--src/game.c53
-rw-r--r--src/game.h4
-rw-r--r--src/netlem.c85
-rw-r--r--src/netlem.h8
-rw-r--r--src/netlem.h.in4
5 files changed, 90 insertions, 64 deletions
diff --git a/src/game.c b/src/game.c
index aa70785..d076dc3 100644
--- a/src/game.c
+++ b/src/game.c
@@ -90,59 +90,6 @@ int receiveEvent(client_t *c, event_t *e) {
return 0;
}
-int init() {
- //int result;
- /*TODO : Avoir un struct de paramètre de config (taille écran) et un struct avec tous les éléments SDL manipulés dans le jeu
-
- //Initialisation des sous-systèmes de SDL
- result = SDL_Init(SDL_INIT_AUDIO | SDL_INIT_VIDEO );
- if ( result != 0 ) {
- logs2(LOG_ERROR, "init(), SDL_Init()", SDL_GetError());
- return 1;
- }
- atexit(SDL_Quit);
-
- //Mise en place de l'écran
- screen = SDL_SetVideoMode( SCREEN_WIDTH, SCREEN_HEIGHT, 24, SDL_HWSURFACE | SDL_DOUBLEBUF );
- if( screen == NULL ) {
- logs2(LOG_ERROR, "init(), SDL_SetVideoMode()", SDL_GetError());
- return 2;
- }
-
- //Titre de la fenêtre SDL
- SDL_WM_SetCaption(WIN_CAPTION, NULL);
-
- //Désactiver le pointeur de la souris
- SDL_ShowCursor(0);
-
- // Allocation et initialisation des différents calques d'affichage et de collision
- pTerrain = SDL_CreateRGBSurface(SDL_HWSURFACE, LEVEL_WIDTH, LEVEL_HEIGHT, SCREEN_BPP,0,0,0,0);
- if( pTerrain == NULL ) {
- logs2(LOG_ERROR, "init(), SDL_CreateRGBSurface()", SDL_GetError());
- return 3;
- }
-
- pSpr_Lem = SDL_CreateRGBSurface(SDL_HWSURFACE, LEVEL_WIDTH, LEVEL_HEIGHT,SCREEN_BPP,0,0,0,0);
- if( pSpr_Lem == NULL ) {
- logs2(LOG_ERROR, "init(), SDL_CreateRGBSurface()", SDL_GetError());
- return 3;
- }
-
- pStencil = SDL_CreateRGBSurface(SDL_SWSURFACE, LEVEL_WIDTH, LEVEL_HEIGHT, SCREEN_BPP,0,0,0,0);
- if( pStencil == NULL ) {
- logs2(LOG_ERROR, "init(), SDL_CreateRGBSurface()", SDL_GetError());
- return 3;
- }
-
- pStencilFixe = SDL_CreateRGBSurface(SDL_SWSURFACE, LEVEL_WIDTH, LEVEL_HEIGHT, SCREEN_BPP,0,0,0,0);
- if( pStencil == NULL ) {
- logs2(LOG_ERROR, "init(), SDL_CreateRGBSurface()", SDL_GetError());
- return 3;
- }
-*/
- //Si tout s'est bien passé
- return 0;
-}
void play(int tick) {
if (tick%100==0) { printf("tick==%i\n",tick); }
diff --git a/src/game.h b/src/game.h
index a8b68c4..6bb1583 100644
--- a/src/game.h
+++ b/src/game.h
@@ -4,6 +4,9 @@
#define DEFAULT_LISTEN_PORT 9999
#define TICK_DURATION_MS 30
+#define LEVEL_WIDTH 1664*2
+#define LEVEL_HEIGHT 160*2
+
#include "SDL/SDL_net.h"
typedef int tick_t;
@@ -79,7 +82,6 @@ void freeNetGame(netGame_t *ng);
int sendEvent(TCPsocket sockDest, const event_t *e);
int receiveEvent(client_t *c, event_t *e);
-int init();
void play(int tick);
#endif //GAME_H
diff --git a/src/netlem.c b/src/netlem.c
index 00d0b31..01d272b 100644
--- a/src/netlem.c
+++ b/src/netlem.c
@@ -4,18 +4,33 @@
#include "SDL/SDL_net.h"
#include "SDL/SDL_thread.h"
-#include "netlem.h"
#include "src/game.h"
#include "src/events.h"
#include "src/utils.h"
+// Application version number
+#include "netlem.h"
+
+//TODO : Trucs brouillons à déplacer à terme
+typedef struct {
+ SDL_Rect screen;
+
+} gameConfig_t;
+// Fin trucs brouillon
+
+// Global variables shared between threads
int tick=0;
SDL_sem *semGameStart;
struct _networkReadProc_args { int *end; int *drift_ms; client_t *client; };
-void processLocalEvents();
+// Thread entry points
int networkReadProc(void *a);
+
+// Client-specific functions
+void loadGameConfig(gameConfig_t *conf);
+int init();
+void processLocalEvents();
int updateGraphics();
int main(int argc, char **argv) {
@@ -112,6 +127,72 @@ int main(int argc, char **argv) {
return 0;
}
+int init() {
+ int result;
+ gameConfig_t conf;
+
+ //TODO ranger ça !
+ SDL_Surface *screen, *pTerrain, *pSpr_Lem, *pStencil, *pStencilFixe;
+
+ loadGameConfig(&conf);
+ //TODO : Avoir un struct de paramètre de config (taille écran) et un struct avec tous les éléments SDL manipulés dans le jeu
+
+ //Initialisation des sous-systèmes de SDL
+ result = SDL_Init(SDL_INIT_AUDIO | SDL_INIT_VIDEO );
+ if ( result != 0 ) {
+ logs2(LOG_ERROR, "init(), SDL_Init()", SDL_GetError());
+ return 1;
+ }
+ atexit(SDL_Quit);
+
+ //Mise en place de l'écran
+ screen = SDL_SetVideoMode(conf.screen.w, conf.screen.h, SCREEN_BPP, SDL_HWSURFACE | SDL_DOUBLEBUF );
+ if( screen == NULL ) {
+ logs2(LOG_ERROR, "init(), SDL_SetVideoMode()", SDL_GetError());
+ return 2;
+ }
+
+ //Titre de la fenêtre SDL
+ SDL_WM_SetCaption(WIN_CAPTION, NULL);
+
+ //Désactiver le pointeur de la souris
+ SDL_ShowCursor(0);
+ // Allocation et initialisation des différents calques d'affichage et de collision
+ pTerrain = SDL_CreateRGBSurface(SDL_HWSURFACE, LEVEL_WIDTH, LEVEL_HEIGHT, SCREEN_BPP,0,0,0,0);
+ if( pTerrain == NULL ) {
+ logs2(LOG_ERROR, "init(), SDL_CreateRGBSurface()", SDL_GetError());
+ return 3;
+ }
+
+ pSpr_Lem = SDL_CreateRGBSurface(SDL_HWSURFACE, LEVEL_WIDTH, LEVEL_HEIGHT,SCREEN_BPP,0,0,0,0);
+ if( pSpr_Lem == NULL ) {
+ logs2(LOG_ERROR, "init(), SDL_CreateRGBSurface()", SDL_GetError());
+ return 3;
+ }
+
+ pStencil = SDL_CreateRGBSurface(SDL_SWSURFACE, LEVEL_WIDTH, LEVEL_HEIGHT, SCREEN_BPP,0,0,0,0);
+ if( pStencil == NULL ) {
+ logs2(LOG_ERROR, "init(), SDL_CreateRGBSurface()", SDL_GetError());
+ return 3;
+ }
+
+ pStencilFixe = SDL_CreateRGBSurface(SDL_SWSURFACE, LEVEL_WIDTH, LEVEL_HEIGHT, SCREEN_BPP,0,0,0,0);
+ if( pStencil == NULL ) {
+ logs2(LOG_ERROR, "init(), SDL_CreateRGBSurface()", SDL_GetError());
+ return 3;
+ }
+
+ return 0;
+}
+
+void loadGameConfig(gameConfig_t *conf) {
+ conf->screen.w=640;
+ conf->screen.h=480;
+
+ conf->screen.x=0;
+ conf->screen.y=0;
+}
+
int networkReadProc(void *a) {
int result;
event_t e;
diff --git a/src/netlem.h b/src/netlem.h
deleted file mode 100644
index f0566c5..0000000
--- a/src/netlem.h
+++ /dev/null
@@ -1,8 +0,0 @@
-#ifndef NETLEM_H
-#define NETLEM_H
-
-// the configured options and settings for NetLemmings
-#define NetLemmings_VERSION_MAJOR 0
-#define NetLemmings_VERSION_MINOR 1
-
-#endif /*NETLEM_H*/
diff --git a/src/netlem.h.in b/src/netlem.h.in
index 3da7f07..a479ed2 100644
--- a/src/netlem.h.in
+++ b/src/netlem.h.in
@@ -5,4 +5,8 @@
#define NetLemmings_VERSION_MAJOR @NetLemmings_VERSION_MAJOR@
#define NetLemmings_VERSION_MINOR @NetLemmings_VERSION_MINOR@
+#define SCREEN_BPP 24
+#define WIN_CAPTION "NetLemmings v.@NetLemmings_VERSION_MAJOR@.@NetLemmings_VERSION_MINOR@"
+
+
#endif /*NETLEM_H*/