2012-03-08 16:39:45 +00:00
|
|
|
#include <glib.h>
|
|
|
|
#include <gio/gio.h>
|
2012-03-10 17:24:23 +00:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
2012-03-08 16:39:45 +00:00
|
|
|
|
2012-03-12 12:55:53 +00:00
|
|
|
#include "main.h"
|
|
|
|
#include "networking.h"
|
2012-03-13 01:22:22 +00:00
|
|
|
#include "interpreter.h"
|
2012-03-12 12:55:53 +00:00
|
|
|
|
2012-03-11 22:44:29 +00:00
|
|
|
#define MAX_RECV_LEN 1024
|
|
|
|
|
2012-03-08 16:39:45 +00:00
|
|
|
struct {
|
|
|
|
char *file;
|
|
|
|
int line;
|
|
|
|
} debug_context_loc = {NULL, 0};
|
|
|
|
|
2012-03-12 12:55:53 +00:00
|
|
|
GMainContext *game_context;
|
2012-03-12 15:42:13 +00:00
|
|
|
guint32 elapsed_seconds = 0;
|
|
|
|
guint32 elapsed_cycle = 0;
|
2012-03-14 19:19:05 +00:00
|
|
|
GRand *main_rand = NULL;
|
2012-03-08 16:39:45 +00:00
|
|
|
|
|
|
|
gboolean
|
|
|
|
rl_sec_elapsed(gpointer user_data)
|
|
|
|
{
|
2012-03-12 15:42:13 +00:00
|
|
|
elapsed_seconds++;
|
|
|
|
if (elapsed_seconds == G_MAXUINT32)
|
|
|
|
{
|
|
|
|
elapsed_seconds = 0;
|
|
|
|
elapsed_cycle++;
|
|
|
|
}
|
2012-03-13 01:21:59 +00:00
|
|
|
g_print("%d RL sec elapsed.\n", elapsed_seconds);
|
2012-03-08 16:39:45 +00:00
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2012-03-10 17:24:23 +00:00
|
|
|
#ifdef DEBUG
|
2012-03-08 16:39:45 +00:00
|
|
|
void
|
|
|
|
debug_context(char *file, int line)
|
|
|
|
{
|
|
|
|
if (debug_context_loc.file != NULL)
|
|
|
|
g_free(debug_context_loc.file);
|
|
|
|
|
|
|
|
debug_context_loc.file = g_strdup(file);
|
|
|
|
debug_context_loc.line = line;
|
|
|
|
}
|
|
|
|
#define DebugContext debug_context(__FILE__, __LINE__)
|
2012-03-10 17:24:23 +00:00
|
|
|
#else
|
|
|
|
#define DebugContext
|
|
|
|
#endif
|
2012-03-08 16:39:45 +00:00
|
|
|
|
2012-03-07 22:00:58 +00:00
|
|
|
int
|
|
|
|
main(int argc, char **argv)
|
|
|
|
{
|
2012-03-08 16:39:45 +00:00
|
|
|
GMainLoop *game_loop;
|
2012-03-12 12:55:53 +00:00
|
|
|
GSource *timeout_source;
|
2012-03-08 16:39:45 +00:00
|
|
|
guint timeout_id;
|
2012-03-11 15:50:45 +00:00
|
|
|
GSocketListener *game_listener;
|
2012-03-08 16:39:45 +00:00
|
|
|
|
2012-03-12 15:42:13 +00:00
|
|
|
g_thread_init(NULL);
|
2012-03-08 16:39:45 +00:00
|
|
|
g_type_init();
|
|
|
|
|
2012-03-11 15:50:45 +00:00
|
|
|
g_print("Starting up...\n");
|
2012-03-08 16:39:45 +00:00
|
|
|
|
2012-03-14 19:19:05 +00:00
|
|
|
main_rand = g_rand_new();
|
|
|
|
|
2012-03-08 16:39:45 +00:00
|
|
|
game_context = g_main_context_new();
|
|
|
|
game_loop = g_main_loop_new(game_context, FALSE);
|
|
|
|
|
|
|
|
timeout_source = g_timeout_source_new(1000);
|
|
|
|
g_source_set_callback(timeout_source, rl_sec_elapsed, NULL, NULL);
|
|
|
|
timeout_id = g_source_attach(timeout_source, game_context);
|
|
|
|
g_source_unref(timeout_source);
|
|
|
|
|
2012-03-11 15:50:45 +00:00
|
|
|
game_listener = g_socket_listener_new();
|
2012-03-08 16:39:45 +00:00
|
|
|
|
2012-03-13 01:22:22 +00:00
|
|
|
wmud_interpreter_init();
|
2012-03-12 12:55:53 +00:00
|
|
|
wmud_networking_init(4000);
|
2012-03-08 16:39:45 +00:00
|
|
|
|
2012-03-11 15:50:45 +00:00
|
|
|
g_print("Startup finished\n");
|
2012-03-08 16:39:45 +00:00
|
|
|
|
|
|
|
g_main_loop_run(game_loop);
|
2012-03-07 22:00:58 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|