project_files/frontlib/frontlib.c
author Medo <smaxein@googlemail.com>
Tue, 12 Jun 2012 11:25:05 +0200
changeset 7224 5143861c83bd
parent 7182 076aba32abd3
child 7314 6171f0bad318
permissions -rw-r--r--
Cleanup, refactoring and generally more development in the frontlib

#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();
	}
}