project_files/frontlib/frontlib.c
author Medo <smaxein@googlemail.com>
Tue, 19 Jun 2012 21:17:05 +0200
changeset 7234 613998625a3c
parent 7224 5143861c83bd
child 7314 6171f0bad318
permissions -rw-r--r--
frontlib: Started work on the server connection code

#include "frontlib.h"
#include "util/logging.h"
#include <SDL.h>
#include <SDL_net.h>

static int flib_initflags;

int flib_init(int flags) {
	flib_initflags = flags;

	flib_log_d("Initializing frontlib");
	if(!(flib_initflags | FRONTLIB_SDL_ALREADY_INITIALIZED)) {
		if(SDL_Init(0)==-1) {
		    flib_log_e("Error in SDL_Init: %s", SDL_GetError());
		    return -1;
		}
	}

	if(SDLNet_Init()==-1) {
		flib_log_e("Error in SDLNet_Init: %s", SDLNet_GetError());
		if(!(flib_initflags | FRONTLIB_SDL_ALREADY_INITIALIZED)) {
			SDL_Quit();
		}
		return -1;
	}

	return 0;
}

void flib_quit() {
	flib_log_d("Shutting down frontlib");
	SDLNet_Quit();
	if(!(flib_initflags | FRONTLIB_SDL_ALREADY_INITIALIZED)) {
		SDL_Quit();
	}
}