diff options
author | Ludovic Pouzenc <ludovic@pouzenc.fr> | 2010-10-31 14:24:32 +0000 |
---|---|---|
committer | Ludovic Pouzenc <ludovic@pouzenc.fr> | 2010-10-31 14:24:32 +0000 |
commit | c8469d4a7c59d864e6bc0972f23ad725c5761854 (patch) | |
tree | 40e0214ff3a8039fc0074497a7660288e6c2b652 | |
parent | dfc039b43230da075d6e84a6019958e977163a17 (diff) | |
download | 2010-netlemmings-c8469d4a7c59d864e6bc0972f23ad725c5761854.tar.gz 2010-netlemmings-c8469d4a7c59d864e6bc0972f23ad725c5761854.tar.bz2 2010-netlemmings-c8469d4a7c59d864e6bc0972f23ad725c5761854.zip |
Youpie ça compile en CMake sous Ubuntu 10.10. J'ai ajouté des commentaires dans le code aussi.
git-svn-id: file:///var/svn/2010-netlemmings/trunk@123 077b3477-7977-48bd-8428-443f22f7bfda
-rw-r--r-- | Makefile | 257 | ||||
-rw-r--r-- | src/CMakeLists.txt | 6 | ||||
-rw-r--r-- | src/events.c | 2 | ||||
-rw-r--r-- | src/game.c | 10 | ||||
-rw-r--r-- | src/netlem.c | 46 | ||||
-rw-r--r-- | src/netlem_ds.c | 8 | ||||
-rw-r--r-- | src/utils.c | 13 |
7 files changed, 278 insertions, 64 deletions
@@ -1,43 +1,244 @@ -CC=gcc -CFLAGS=-c -g -Wall -LDFLAGS=-lSDL -lSDL_net +# CMAKE generated file: DO NOT EDIT! +# Generated by "Unix Makefiles" Generator, CMake Version 2.8 -SOURCES_COMMON=events.c game.c utils.c -SOURCES_CLIENT=netlem.c $(SOURCES_COMMON) -SOURCES_SERVER=netlem_ds.c $(SOURCES_COMMON) +# Default target executed when no arguments are given to make. +default_target: all +.PHONY : default_target -OBJECTS_CLIENT=$(SOURCES_CLIENT:.c=.o) -OBJECTS_SERVER=$(SOURCES_SERVER:.c=.o) +#============================================================================= +# Special targets provided by cmake. -DEPS=$(SOURCES_CLIENT:.c=.d) $(SOURCES_SERVER:.c=.d) +# Disable implicit rules so canoncical targets will work. +.SUFFIXES: -EXECUTABLE_CLIENT=netlem -EXECUTABLE_SERVER=netlem_ds +# Remove some rules from gmake that .SUFFIXES does not remove. +SUFFIXES = -ALLGEN=$(OBJECTS_CLIENT) $(OBJECTS_SERVER) $(EXECUTABLE_CLIENT) $(EXECUTABLE_SERVER) +.SUFFIXES: .hpux_make_needs_suffix_list -all: $(EXECUTABLE_CLIENT) $(EXECUTABLE_SERVER) +# Suppress display of executed commands. +$(VERBOSE).SILENT: -%.d: %.c - @set -e; rm -f $@; \ - $(CC) -MM $(CPPFLAGS) $< > $@.$$$$; \ - sed 's,\($*\)\.o[ :]*,\1.o $@ : ,g' < $@.$$$$ > $@; \ - rm -f $@.$$$$ +# A target that is always out of date. +cmake_force: +.PHONY : cmake_force -include $(DEPS) +#============================================================================= +# Set environment variables for the build. -$(EXECUTABLE_CLIENT): $(OBJECTS_CLIENT) - $(CC) $(LDFLAGS) $(OBJECTS_CLIENT) -o $@ +# The shell in which to execute make rules. +SHELL = /bin/sh -$(EXECUTABLE_SERVER): $(OBJECTS_SERVER) - $(CC) $(LDFLAGS) $(OBJECTS_SERVER) -o $@ +# The CMake executable. +CMAKE_COMMAND = /usr/bin/cmake -.c.o: - $(CC) $(CFLAGS) $< -o $@ +# The command to remove a file. +RM = /usr/bin/cmake -E remove -f +# The program to use to edit the cache. +CMAKE_EDIT_COMMAND = /usr/bin/ccmake + +# The top-level source directory on which CMake was run. +CMAKE_SOURCE_DIR = /home/lpouzenc/Bureau/lemmings/src + +# The top-level build directory on which CMake was run. +CMAKE_BINARY_DIR = /home/lpouzenc/Bureau/lemmings + +#============================================================================= +# Targets provided globally by CMake. + +# Special rule for the target edit_cache +edit_cache: + @$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --cyan "Running CMake cache editor..." + /usr/bin/ccmake -H$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR) +.PHONY : edit_cache + +# Special rule for the target edit_cache +edit_cache/fast: edit_cache +.PHONY : edit_cache/fast + +# Special rule for the target rebuild_cache +rebuild_cache: + @$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --cyan "Running CMake to regenerate build system..." + /usr/bin/cmake -H$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR) +.PHONY : rebuild_cache + +# Special rule for the target rebuild_cache +rebuild_cache/fast: rebuild_cache +.PHONY : rebuild_cache/fast + +# The main all target +all: cmake_check_build_system + $(CMAKE_COMMAND) -E cmake_progress_start /home/lpouzenc/Bureau/lemmings/CMakeFiles /home/lpouzenc/Bureau/lemmings/CMakeFiles/progress.marks + $(MAKE) -f CMakeFiles/Makefile2 all + $(CMAKE_COMMAND) -E cmake_progress_start /home/lpouzenc/Bureau/lemmings/CMakeFiles 0 +.PHONY : all + +# The main clean target clean: - -rm -rf $(ALLGEN) + $(MAKE) -f CMakeFiles/Makefile2 clean +.PHONY : clean + +# The main clean target +clean/fast: clean +.PHONY : clean/fast + +# Prepare targets for installation. +preinstall: all + $(MAKE) -f CMakeFiles/Makefile2 preinstall +.PHONY : preinstall + +# Prepare targets for installation. +preinstall/fast: + $(MAKE) -f CMakeFiles/Makefile2 preinstall +.PHONY : preinstall/fast + +# clear depends +depend: + $(CMAKE_COMMAND) -H$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR) --check-build-system CMakeFiles/Makefile.cmake 1 +.PHONY : depend + +#============================================================================= +# Target rules for targets named netlem + +# Build rule for target. +netlem: cmake_check_build_system + $(MAKE) -f CMakeFiles/Makefile2 netlem +.PHONY : netlem + +# fast build rule for target. +netlem/fast: + $(MAKE) -f CMakeFiles/netlem.dir/build.make CMakeFiles/netlem.dir/build +.PHONY : netlem/fast + +events.o: events.c.o +.PHONY : events.o + +# target to build an object file +events.c.o: + $(MAKE) -f CMakeFiles/netlem.dir/build.make CMakeFiles/netlem.dir/events.c.o +.PHONY : events.c.o + +events.i: events.c.i +.PHONY : events.i + +# target to preprocess a source file +events.c.i: + $(MAKE) -f CMakeFiles/netlem.dir/build.make CMakeFiles/netlem.dir/events.c.i +.PHONY : events.c.i + +events.s: events.c.s +.PHONY : events.s + +# target to generate assembly for a file +events.c.s: + $(MAKE) -f CMakeFiles/netlem.dir/build.make CMakeFiles/netlem.dir/events.c.s +.PHONY : events.c.s + +game.o: game.c.o +.PHONY : game.o + +# target to build an object file +game.c.o: + $(MAKE) -f CMakeFiles/netlem.dir/build.make CMakeFiles/netlem.dir/game.c.o +.PHONY : game.c.o + +game.i: game.c.i +.PHONY : game.i + +# target to preprocess a source file +game.c.i: + $(MAKE) -f CMakeFiles/netlem.dir/build.make CMakeFiles/netlem.dir/game.c.i +.PHONY : game.c.i + +game.s: game.c.s +.PHONY : game.s + +# target to generate assembly for a file +game.c.s: + $(MAKE) -f CMakeFiles/netlem.dir/build.make CMakeFiles/netlem.dir/game.c.s +.PHONY : game.c.s + +netlem.o: netlem.c.o +.PHONY : netlem.o + +# target to build an object file +netlem.c.o: + $(MAKE) -f CMakeFiles/netlem.dir/build.make CMakeFiles/netlem.dir/netlem.c.o +.PHONY : netlem.c.o + +netlem.i: netlem.c.i +.PHONY : netlem.i + +# target to preprocess a source file +netlem.c.i: + $(MAKE) -f CMakeFiles/netlem.dir/build.make CMakeFiles/netlem.dir/netlem.c.i +.PHONY : netlem.c.i + +netlem.s: netlem.c.s +.PHONY : netlem.s + +# target to generate assembly for a file +netlem.c.s: + $(MAKE) -f CMakeFiles/netlem.dir/build.make CMakeFiles/netlem.dir/netlem.c.s +.PHONY : netlem.c.s + +utils.o: utils.c.o +.PHONY : utils.o + +# target to build an object file +utils.c.o: + $(MAKE) -f CMakeFiles/netlem.dir/build.make CMakeFiles/netlem.dir/utils.c.o +.PHONY : utils.c.o + +utils.i: utils.c.i +.PHONY : utils.i + +# target to preprocess a source file +utils.c.i: + $(MAKE) -f CMakeFiles/netlem.dir/build.make CMakeFiles/netlem.dir/utils.c.i +.PHONY : utils.c.i + +utils.s: utils.c.s +.PHONY : utils.s + +# target to generate assembly for a file +utils.c.s: + $(MAKE) -f CMakeFiles/netlem.dir/build.make CMakeFiles/netlem.dir/utils.c.s +.PHONY : utils.c.s + +# Help Target +help: + @echo "The following are some of the valid targets for this Makefile:" + @echo "... all (the default if no target is provided)" + @echo "... clean" + @echo "... depend" + @echo "... edit_cache" + @echo "... netlem" + @echo "... rebuild_cache" + @echo "... events.o" + @echo "... events.i" + @echo "... events.s" + @echo "... game.o" + @echo "... game.i" + @echo "... game.s" + @echo "... netlem.o" + @echo "... netlem.i" + @echo "... netlem.s" + @echo "... utils.o" + @echo "... utils.i" + @echo "... utils.s" +.PHONY : help + + + +#============================================================================= +# Special targets to cleanup operation of make. -mrproper: - -rm -rf $(ALLGEN) $(DEPS) +# Special rule to run CMake to check the build system integrity. +# No rule that depends on this can have commands that come from listfiles +# because they might be regenerated. +cmake_check_build_system: + $(CMAKE_COMMAND) -H$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR) --check-build-system CMakeFiles/Makefile.cmake 0 +.PHONY : cmake_check_build_system diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 02bf57c..9a4fdf4 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,5 +1,5 @@ cmake_minimum_required (VERSION 2.6) -project (NetLemmings) +project (NetLemmings C) # The version number. set (NetLemmings_VERSION_MAJOR 0) @@ -17,10 +17,10 @@ configure_file ( ) # add the binary tree to the search path for include files -# so that we will find NetLemmingsConfig.h +# so that we will find netlem.h include_directories("${PROJECT_BINARY_DIR}") -add_executable(netlem netlem.c) +add_executable(netlem netlem.c events.c game.c utils.c) add_definitions(-Wall -Wextra -pedantic -Werror -std=c99) target_link_libraries(netlem SDL SDL_net) diff --git a/src/events.c b/src/events.c index 95be9e9..4436ed7 100644 --- a/src/events.c +++ b/src/events.c @@ -1,7 +1,7 @@ #include <stdlib.h> // calloc #include <string.h> //memcpy -#include "events.h" +#include "src/events.h" inline int eventSerializedSize() { //FIXME : A rendre portable @@ -1,10 +1,10 @@ -#include "game.h" -#include "utils.h" -#include "events.h" - #include <stdlib.h> // calloc #include <string.h> // memset +#include "src/game.h" +#include "src/utils.h" +#include "src/events.h" + inline tick_t getGameCurrentTick(Uint32 startTime_ms) { /* char buf[128]; sprintf(buf, "SDL_GetTicks()==%i, startTime_ms==%i, TICK_DURATION_MS==%i", SDL_GetTicks(), startTime_ms, TICK_DURATION_MS); @@ -91,7 +91,7 @@ int receiveEvent(client_t *c, event_t *e) { } int init() { - int result; + //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 diff --git a/src/netlem.c b/src/netlem.c index e9a4304..00d0b31 100644 --- a/src/netlem.c +++ b/src/netlem.c @@ -5,27 +5,26 @@ #include "SDL/SDL_thread.h" #include "netlem.h" -#include "game.h" -#include "events.h" -#include "utils.h" +#include "src/game.h" +#include "src/events.h" +#include "src/utils.h" int tick=0; SDL_sem *semGameStart; -struct _processNetworkEvents_args { int *end; int *drift_ms; client_t *client; }; +struct _networkReadProc_args { int *end; int *drift_ms; client_t *client; }; void processLocalEvents(); -int processNetworkEvents(void *a); +int networkReadProc(void *a); int updateGraphics(); int main(int argc, char **argv) { const event_t evReady = {0,0,0,eReady,0,0,NULL,NULL}; int end=0, drift_ms=0, timeBefore_ms, delay_ms, result, status; client_t client; - struct _processNetworkEvents_args args; + struct _networkReadProc_args args; char logMsg[128]; - // connect to localhost at port 9999 using TCP (client) IPaddress ip; if(argc!=2) { @@ -33,11 +32,14 @@ int main(int argc, char **argv) { return 1; } + // Log system initialization openLog(NULL); + // Starting log message sprintf(logMsg, "NetLemmings version %i.%i", NetLemmings_VERSION_MAJOR, NetLemmings_VERSION_MINOR); logs(LOG_INFO, logMsg); + // Server name resolution and connection if(SDLNet_ResolveHost(&ip,argv[1],9999)==-1) { logs2(LOG_ERROR, "main(), SDLNet_ResolveHost()", SDLNet_GetError()); return 2; @@ -49,24 +51,27 @@ int main(int argc, char **argv) { return 3; } + // Libraries initialization result=init(); if(result!=0) { - logs(LOG_ERROR,"main(), mySDLInit()"); + logs(LOG_ERROR,"main(), init()"); return 3; } + // Synchronization tools intialization semGameStart=SDL_CreateSemaphore(0); + // Network reader thread to process remote events and time sync args.end=&end; args.drift_ms=&drift_ms; args.client=&client; - SDL_Thread *timeSyncThread = SDL_CreateThread(processNetworkEvents, &args); - if(!timeSyncThread) { + SDL_Thread *networkReadThread = SDL_CreateThread(networkReadProc, &args); + if(!networkReadThread) { logs2(LOG_ERROR,"main(), SDL_CreateThread()", SDL_GetError()); return 4; } - //Signale au serveur que le client est pret + // Say to the server that we are ready to start the game and wait game start result=sendEvent(client.sockClient, &evReady); if (result!=0) return 6; @@ -78,19 +83,28 @@ int main(int argc, char **argv) { } logs(LOG_INFO, "Game started !"); + // Main game loop while(!end) { timeBefore_ms = SDL_GetTicks(); + // Process local player keyboard and mouse events + // (note: remote events are processed by network read thread) processLocalEvents(); + + // Make game evolve from the current state to the next time chunk (ie. frame, or tick) play(tick++); + + // Display that new game state to the local user updateGraphics(); + // Delay that we have to wait for the next frame (depends on execution time and network time drift) delay_ms=TICK_DURATION_MS-(SDL_GetTicks()-timeBefore_ms)+drift_ms; if (delay_ms>0) SDL_Delay(delay_ms); //TODO Si le client rame trop, faut décrocher la partie } + // Close communcation with the server, stop threads, close logs and go out SDLNet_TCP_Close(client.sockClient); - SDL_WaitThread(timeSyncThread, &status); + SDL_WaitThread(networkReadThread, &status); sprintf(logMsg, "TimeSync thread terminated with code %i", status); logs(LOG_DEBUG, logMsg); @@ -98,18 +112,18 @@ int main(int argc, char **argv) { return 0; } -int processNetworkEvents(void *a) { +int networkReadProc(void *a) { int result; event_t e; char logMsg[128]; - struct _processNetworkEvents_args *args = (struct _processNetworkEvents_args *)a; + struct _networkReadProc_args *args = (struct _networkReadProc_args *)a; while(! *(args->end) ) { // logs(LOG_DEBUG, "Waiting event"); result=receiveEvent(args->client,&e); if (result != 0) { - logs(LOG_WARN, "processNetworkEvents(), receiveEvents() error"); + logs(LOG_WARN, "networkReadProc(), receiveEvents() error"); *(args->end)=1; continue; //TODO : je doute que ça skipe vriament la syncrho du temps :s } @@ -137,7 +151,7 @@ int processNetworkEvents(void *a) { logs(LOG_ERROR, "serveClient(), Unknown event type"); } } - // logs(LOG_DEBUG, "processNetworkEvents() : end"); + // logs(LOG_DEBUG, "networkReadProc() : end"); return 0; } diff --git a/src/netlem_ds.c b/src/netlem_ds.c index 507b4fb..c81c850 100644 --- a/src/netlem_ds.c +++ b/src/netlem_ds.c @@ -6,10 +6,10 @@ #include "SDL/SDL_net.h" #include "SDL/SDL_thread.h" -#include "game.h" -#include "netlem_ds.h" -#include "events.h" -#include "utils.h" +#include "src/game.h" +#include "src/netlem_ds.h" +#include "src/events.h" +#include "src/utils.h" //struct _timerArgs_t { int *numClients; client_t *clients[]; }; // Comprendre pq ça chie ça struct _timerArgs_t { int *numClients; client_t **clients; }; diff --git a/src/utils.c b/src/utils.c index e2282fe..44f7ada 100644 --- a/src/utils.c +++ b/src/utils.c @@ -1,10 +1,10 @@ -#include "utils.h" - #include <stdlib.h> // exit() #include <stdio.h> // FILE * -#include <string.h> // strerror_r() +#include <string.h> // strerror() #include <errno.h> +#include "src/utils.h" + static FILE *fdLog=NULL; void openLog(char path[]) { @@ -33,9 +33,8 @@ void logs2(int level, char context[], char msg[]) { } void logp(int level, char msg[]) { - char errbuf[128]; //TODO : Pas cool la taille fixe ici - - strerror_r(errno, errbuf, 128); - fprintf(fdLog,"%i - %s : %s\n", level, msg, errbuf); + char *errMsg; + errMsg=strerror(errno); + fprintf(fdLog,"%i - %s : %s\n", level, msg, errMsg); } |