diff --git a/build/linux/makefile b/build/linux/makefile index 1fb6eb1..b42e90a 100644 --- a/build/linux/makefile +++ b/build/linux/makefile @@ -17,23 +17,23 @@ all: release release: BUILD_TYPE = release release: CFLAGS += $(CFLAGS_RELEASE) release: pre_build $(OBJS_RELEASE) post_build - -@echo LINKING Release build + -@echo -e "\e[34mLINKING\e[0m Release build" -@$(CC) $(OBJS_RELEASE) $(LFLAGS) -o $(PROJECT_NAME) - -@echo DONE building $(PROJECT_NAME) + -@echo -e "\e[32mDONE\e[0m building $(PROJECT_NAME)" debug: BUILD_TYPE = debug debug: CFLAGS += $(CFLAGS_DEBUG) debug: pre_build $(OBJS_DEBUG) post_build - -@echo LINKING Debug build + -@echo -e "\e[34mLINKING\e[0m Debug build" -@$(CC) $(OBJS_DEBUG) $(LFLAGS) -o $(PROJECT_NAME) - -@echo DONE building $(PROJECT_NAME) + -@echo -e "\e[32mDONE\e[0m building $(PROJECT_NAME)" .release/%.o: $(SRC_DIR)/%.c - -@echo Compiling $< + -@echo -e "\e[96mCompiling $<\e[0m" -@$(CC) $(CFLAGS) -c $< -o $@ .debug/%.o: $(SRC_DIR)/%.c - -@echo Compiling $< + -@echo -e "\e[96mCompiling $<\e[0m" -@$(CC) $(CFLAGS) -c $< -o $@ pre_build: @@ -43,7 +43,7 @@ post_build: -@ln -fs /mnt/Dev/Projects/symmetry/assets assets dist: release - -@echo Creating Distribution at $(DIST_DIR)/$(PROJECT_NAME) + -@echo -e "\e[34mCreating Distribution at $(DIST_DIR)/$(PROJECT_NAME)\e[0m" -@strip $(PROJECT_NAME) -@rm -rf $(DIST_DIR)/$(PROJECT_NAME) -@mkdir -p $(DIST_DIR)/$(PROJECT_NAME) @@ -57,9 +57,11 @@ dist: release -@chmod +x $(DIST_DIR)/$(PROJECT_NAME)/Launch.sh -@cp $(PROJECT_NAME) $(DIST_DIR)/$(PROJECT_NAME) -@chmod +x $(DIST_DIR)/$(PROJECT_NAME)/$(PROJECT_NAME) - -@echo DONE creating distribution + -@echo -e "\e[32mDONE creating distribution\e[0m" clean: + -@echo -e "\e[31m" -rm -f $(PROJECT_NAME) -rm -rf .release -rm -rf .debug + -@echo -e "\e[0m" diff --git a/build/win_mingw64/makefile b/build/win_mingw64/makefile index cbe28ca..9ea60d2 100644 --- a/build/win_mingw64/makefile +++ b/build/win_mingw64/makefile @@ -16,12 +16,12 @@ all: release release: BUILD_TYPE = release release: CFLAGS += $(CFLAGS_RELEASE) release: pre_build $(OBJS_RELEASE) post_build - -@echo LINKING... + -@echo -e "\e[34mLINKING\e[0m Release build" -@$(CC) $(OBJS_RELEASE) $(LFLAGS) -o $(PROJECT_NAME) - -@echo DONE building $(PROJECT_NAME) + -@echo -e "\e[32mDONE\e[0m building $(PROJECT_NAME)" .release/%.o: $(SRC_DIR)/%.c - -@echo Compiling $< + -@echo -e "\e[96mCompiling $<\e[0m" -@$(CC) $(CFLAGS) -c $< -o $@ pre_build: @@ -33,7 +33,7 @@ post_build: -@cp $(LIB_BINARY_DIR)/OpenAL32.dll /mnt/Dev/Projects/symmetry/build/win_mingw64 dist: release - -@echo Creating Distribution at $(DIST_DIR)/$(PROJECT_DIST_NAME) + -@echo -e "\e[34mCreating Distribution at $(DIST_DIR)/$(PROJECT_NAME)\e[0m" -@mingw-strip $(PROJECT_NAME) -@rm -rf $(DIST_DIR)/$(PROJECT_DIST_NAME) -@mkdir -p $(DIST_DIR)/$(PROJECT_DIST_NAME) @@ -41,9 +41,11 @@ dist: release -@cp $(PROJECT_NAME) $(DIST_DIR)/$(PROJECT_DIST_NAME) -@cp SDL2.dll $(DIST_DIR)/$(PROJECT_DIST_NAME) -@cp OpenAL32.dll $(DIST_DIR)/$(PROJECT_DIST_NAME) - -@echo DONE creating distribution + -@echo -e "\e[32mDONE creating distribution\e[0m" clean: + -@echo -e "\e[31m" -rm -f $(PROJECT_NAME) -rm -rf .release -rm -rf .debug + -@echo -e "\e[0m" diff --git a/src/input.c b/src/input.c index b1be0e0..bbc0a6b 100644 --- a/src/input.c +++ b/src/input.c @@ -73,7 +73,7 @@ void input_cleanup(void) for(int i = 0; i < array_len(input_map_list); i++) { struct Input_Map* map = &input_map_list[i]; - log_message("Map : %s, Num keys : %d", map->name, array_len(map->keys)); + //log_message("Map : %s, Num keys : %d", map->name, array_len(map->keys)); if(map->name) free(map->name); array_free(map->keys); } @@ -354,7 +354,6 @@ void input_map_create(const char* name, struct Key_Combination* keys, int num_ke new_map->keys[i] = keys[i]; log_message("Created Input Map : %s", name); } - log_message("Map_index : %d", index); } void input_update(void) diff --git a/src/log.c b/src/log.c index 9a755f6..a0c5ee7 100644 --- a/src/log.c +++ b/src/log.c @@ -1,34 +1,113 @@ #include #include +#include +#include #include "log.h" +#include "platform.h" -void log_message(const char* message, ...) +#ifdef __linux__ + +#define COL_RED "\e[31m" +#define COL_GREEN "\e[32m" +#define COL_YELLOW "\e[33m" +#define COL_DEFAULT "\e[39m" +#define COL_CYAN "\e[36m" +#define COL_RESET "\e[0m" + +#else + +#define COL_RED "" +#define COL_GREEN "" +#define COL_YELLOW "" +#define COL_DEFAULT "" +#define COL_CYAN "" +#define COL_RESET "" + +#endif + +static FILE* log_file = NULL; + +void log_init(const char* log_file_name) +{ + char* dir = platform_user_directory_get("SS_Games", "Symmetry"); + char log_file_path[512] = {'\0'}; + snprintf(log_file_path, 512, "%s/%s", dir, log_file_name); + log_file = fopen(log_file_path, "w"); + if(!log_file) + { + log_to_stdout("ERR: (log:init): Failed to create log file at %s", dir); + } + else + { + time_t current_time; + time(¤t_time); + fprintf(log_file, "Log Initialized at %s\n", ctime(¤t_time)); + fflush(log_file); + } + if(dir) free(dir); +} + +void log_cleanup(void) +{ + if(log_file) fclose(log_file); +} + + +void log_to_stdout(const char* message, ...) { - printf("MSG : "); + printf("%sMSG : ", COL_CYAN); va_list list; va_start(list, message); vprintf(message, list); va_end(list); - printf("\n"); + printf("\n%s", COL_RESET); +} + +void log_message(const char* message, ...) +{ + printf("%sMSG : ", COL_DEFAULT); + fprintf(log_file, "MSG: "); + va_list console_list, file_list; + va_start(console_list, message); + va_copy(file_list, console_list); + vfprintf(log_file, message, file_list); + vprintf(message, console_list); + va_end(console_list); + va_end(file_list); + printf("\n%s", COL_RESET); + fprintf(log_file, "\n"); + fflush(log_file); } void log_warning(const char* message, ...) { - printf("WRN : "); - va_list list; - va_start(list, message); - vprintf(message, list); - va_end(list); + printf("%sWRN : ", COL_YELLOW); + fprintf(log_file, "WRN: "); + va_list console_list, file_list; + va_start(console_list, message); + va_copy(file_list, console_list); + vfprintf(log_file, message, file_list); + vprintf(message, console_list); + va_end(console_list); + va_end(file_list); printf("\n"); + fprintf(log_file, "\n"); + fflush(log_file); } void log_error(const char* context, const char* error, ...) { - printf("ERR (%s) : ", context); - va_list list; - va_start(list, error); - vprintf(error, list); - va_end(list); - printf("\n"); + printf("%sERR (%s) : ", COL_RED, context); + fprintf(log_file, "ERR (%s) : ", context); + va_list console_list, file_list; + va_start(console_list, error); + va_copy(file_list, console_list); + vfprintf(log_file, error, file_list); + vprintf(error, console_list); + va_end(console_list); + va_end(file_list); + printf("\n%s", COL_RESET); + fprintf(log_file, "\n"); + fflush(log_file); } diff --git a/src/log.h b/src/log.h index 50d55b9..6e95045 100644 --- a/src/log.h +++ b/src/log.h @@ -1,8 +1,11 @@ -#ifndef log_H -#define log_H +#ifndef LOG_H +#define LOG_H +void log_init(const char* log_file_name); +void log_cleanup(void); void log_message(const char* message, ...); void log_warning(const char* message, ...); void log_error(const char* context, const char* error, ...); +void log_to_stdout(const char* message, ...); /* Only use when logging is not initialized */ #endif diff --git a/src/main.c b/src/main.c index 37e9817..79f8ac9 100644 --- a/src/main.c +++ b/src/main.c @@ -17,7 +17,7 @@ void cleanup(); int main(int argc, char** args) { if(!init()) - log_error("Main:main", "Could not initialize"); + log_to_stdout("ERR:(Main) Could not initialize"); else game_init(window); @@ -30,13 +30,14 @@ int init(void) if(atexit(cleanup) != 0) { success = 0; - log_error("main:init", "Could not register cleanup func with atexit"); + log_to_stdout("ERR: (main:init) Could not register cleanup func with atexit"); } else { config_vars_init(); if(platform_init()) { + log_init("Log.txt"); success = gl_load_library(); if(!success) { @@ -87,4 +88,5 @@ void cleanup() platform_cleanup(); config_vars_cleanup(); log_message("Program exiting!"); + log_cleanup(); } diff --git a/src/platform.c b/src/platform.c index f36616b..7f90d23 100644 --- a/src/platform.c +++ b/src/platform.c @@ -180,14 +180,16 @@ int platform_init(void) if(SDL_Init(SDL_INIT_VIDEO | SDL_INIT_EVENTS | SDL_INIT_TIMER) != 0) { success = 0; - log_error("platform_init", "SDL Init failed : %s", SDL_GetError()); + if(SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "SDL Init failed", SDL_GetError(), NULL) != 0) + log_to_stdout("platform_init", "SDL Init failed : %s", SDL_GetError()); } else { platform_state = malloc(sizeof(*platform_state)); if(!platform_state) { - log_error("platform_init", "Could not create platform state, out of memory"); + if(SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "Allocation Failure", "Memory allocation failed, out of memory!", NULL) != 0) + log_to_stdout("platform_init", "Could not create platform state, out of memory"); success = 0; } else