diff options
author | Bjørn Lindeijer <bjorn@lindeijer.nl> | 2005-04-14 22:17:54 +0000 |
---|---|---|
committer | Bjørn Lindeijer <bjorn@lindeijer.nl> | 2005-04-14 22:17:54 +0000 |
commit | 3f86b3120f9b9b651f099d94d92e64f682fd8f31 (patch) | |
tree | b58b30401328513d01d10a6d9eefbd6147d097cc | |
parent | 3d90f79f39e3863379ee0eb8246b10729b523fb0 (diff) | |
download | manaserv-3f86b3120f9b9b651f099d94d92e64f682fd8f31.tar.gz manaserv-3f86b3120f9b9b651f099d94d92e64f682fd8f31.tar.bz2 manaserv-3f86b3120f9b9b651f099d94d92e64f682fd8f31.tar.xz manaserv-3f86b3120f9b9b651f099d94d92e64f682fd8f31.zip |
Added check for SDL_net to configure.ac, made world clock work and made the
server handle quit message properly (had to init video for events to work).
Also reduced CPU load by about 100%, hehe.
-rw-r--r-- | configure.ac | 1 | ||||
-rw-r--r-- | src/main.cpp | 22 |
2 files changed, 20 insertions, 3 deletions
diff --git a/configure.ac b/configure.ac index cd544da6..ca5de358 100644 --- a/configure.ac +++ b/configure.ac @@ -9,6 +9,7 @@ AC_PROG_CC # Checks for libraries. AC_CHECK_LIB([physfs], [PHYSFS_init]) +AC_CHECK_LIB([SDL_net], [SDLNet_Init]) # Checks for header files. AC_HEADER_STDC diff --git a/src/main.cpp b/src/main.cpp index 22039340..454885d9 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -31,6 +31,7 @@ #define SERVER_PORT 9601 SDL_TimerID worldTimerID; /**< Timer ID of world timer */ +int worldTime = 0; /**< Current world time in 100ms ticks */ bool running = true; /**< Determines if server keeps running */ /** @@ -41,7 +42,9 @@ Uint32 worldTick(Uint32 interval, void *param) // Push the custom world tick event SDL_Event event; event.type = TMW_WORLD_TICK; - SDL_PushEvent(&event); + if (SDL_PushEvent(&event)) { + printf("Warning: couldn't push world tick into event queue!\n"); + } return interval; } @@ -51,7 +54,7 @@ Uint32 worldTick(Uint32 interval, void *param) void initialize() { // Initialize SDL - if (SDL_Init(SDL_INIT_TIMER) == -1) { + if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER) == -1) { printf("SDL_Init: %s\n", SDL_GetError()); exit(1); } @@ -100,7 +103,7 @@ int main(int argc, char *argv[]) //connectionHandler->registerHandler(C2S_LOGIN, accountHandler); printf("The Mana World Server v0.0.1\n"); - printf("Starting...\n"); + printf("Listening...\n"); session->startListen(connectionHandler, SERVER_PORT); SDL_Event event; @@ -111,6 +114,14 @@ int main(int argc, char *argv[]) { if (event.type == TMW_WORLD_TICK) { + // Move the world forward in time + worldTime++; + + // Print world time at 10 second intervals to show we're alive + if (worldTime % 100 == 0) { + printf("World time: %d\n", worldTime); + } + // - Handle all messages that are in the message queue // - Update all active objects/beings } @@ -119,8 +130,13 @@ int main(int argc, char *argv[]) running = false; } } + + // We know about only about 10 events will happen per second, so give + // the CPU a break for a while. + SDL_Delay(100); } + printf("Recieved Quit signal, closing down...\n"); session->stopListen(SERVER_PORT); deinitialize(); |