
#include <config.hpp>

#if defined(BUILD_CLIENT)
#include "game/engine/engine.hpp"
#include "game/audio/audio.hpp"
#endif
#if defined(BUILD_SERVER)
#include "server/server.hpp"
#endif
#include "common/logger.hpp"

int main(int argc, char** argv) {
	polygun::utils::Logger::create(false, true);

	bool start_server = false;
#if defined(BUILD_SERVER)
#if defined(BUILD_CLIENT)
	if(argc>1)
		start_server = std::string(argv[1])=="server";
#else
	start_server = true;
#endif
#endif
	if(start_server) {
#if defined(BUILD_SERVER)
		try {
			polygun::server::Server server;
			server.run();
		}
		catch(const std::string& msg) {
			LOG_ERROR("Server runtime failed: %s", msg.c_str());
		}
#endif
	}
	else {
#if defined(BUILD_CLIENT)
		polygun::audio::init();
		polygun::engine::Engine engine;
		engine.init();
		polygun::audio::cleanup();
#endif
	}
	polygun::utils::Logger::cleanup();
	return 0;
}
