diff --git a/GameLib/Audio.c b/GameLib/Audio.c index 16ce44f..dd4bb13 100644 --- a/GameLib/Audio.c +++ b/GameLib/Audio.c @@ -8,6 +8,7 @@ #include #include #include +#include "Util.h" #include "Audio.h" @@ -64,8 +65,8 @@ int Audio_Init(){ putenv("SDL_AUDIODRIVER=dsound"); #endif if(SDL_InitSubSystem(SDL_INIT_AUDIO) < 0){ - printf("Audio_Init: Failure initializing SDL Audio.\n"); - printf("\tSDL Error: %s\n",SDL_GetError()); + Print("Audio_Init: Failure initializing SDL Audio.\n"); + Print("\tSDL Error: %s\n",SDL_GetError()); return(0); } @@ -76,8 +77,8 @@ int Audio_Init(){ as.samples = 2048; as.callback = Audio_MixerCallback; if(SDL_OpenAudio(&as, &as2) < 0){ - printf("Audio_Init: Failure opening audio.\n"); - printf("\tSDL Error: %s\n",SDL_GetError()); + Print("Audio_Init: Failure opening audio.\n"); + Print("\tSDL Error: %s\n",SDL_GetError()); return(0); } @@ -86,7 +87,7 @@ int Audio_Init(){ as2.freq != 44100 || as2.channels != 2 ) { - printf("Audio_Init: Failure opening audio. (44.1Khz/16b/2c).\n"); + Print("Audio_Init: Failure opening audio. (44.1Khz/16b/2c).\n"); SDL_CloseAudio(); return(0); } @@ -222,14 +223,14 @@ AudioSnd Audio_LoadSound(char *filename){ f = fopen(filename, "rb"); if (!f) { - printf("Audio_LoadSound: Failure opening file.\n"); + Print("Audio_LoadSound: Failure opening file.\n"); return(NULL); } // Read id "RIFF" fread(id, 4, sizeof(char), f); if (strcmp(id, "RIFF")) { - printf("Audio_LoadSound: File is not RIFF.\n"); + Print("Audio_LoadSound: File is not RIFF.\n"); fclose(f); return(NULL); } @@ -240,7 +241,7 @@ AudioSnd Audio_LoadSound(char *filename){ // Read id "WAVE" fread(id, 4, sizeof(char), f); if (strcmp(id, "WAVE")) { - printf("Audio_LoadSound: File is not WAVE.\n"); + Print("Audio_LoadSound: File is not WAVE.\n"); fclose(f); return(NULL); } @@ -249,13 +250,13 @@ AudioSnd Audio_LoadSound(char *filename){ fread(id, 1, sizeof(char) * 4, f); // Read "fmt " fread(&formatLen, 1, sizeof(int), f); if (formatLen < 14) { - printf("Audio_LoadSound: File too short.\n"); + Print("Audio_LoadSound: File too short.\n"); fclose(f); return (NULL ); } fread(&formatTag, 1, sizeof(short), f); // 1=PCM if (formatTag != 1) { - printf("Audio_LoadSound: Not PCM format.\n"); + Print("Audio_LoadSound: Not PCM format.\n"); fclose(f); return (NULL ); } @@ -268,7 +269,7 @@ AudioSnd Audio_LoadSound(char *filename){ // Assert sound format if (sampleRate!=44100 || channels!=1 || bitsPerSample!=2) { - printf("Audio_LoadSound: Format not supported: " + Print("Audio_LoadSound: Format not supported: " "sampleRate:%d; channels:%d; BPB:%d\n", sampleRate, channels, bitsPerSample); fclose(f); @@ -287,7 +288,7 @@ AudioSnd Audio_LoadSound(char *filename){ } }while(1); if (strcmp(id, "data")) { - printf("Audio_LoadSound: DATA block not found\n"); + Print("Audio_LoadSound: DATA block not found\n"); fclose(f); return (NULL ); } diff --git a/GameLib/Draw.c b/GameLib/Draw.c index 757c6b4..62a09f3 100644 --- a/GameLib/Draw.c +++ b/GameLib/Draw.c @@ -153,18 +153,6 @@ GLuint Draw_UploadGLTexture(int w, int h, unsigned char *pixels); // // Initializes the game window. int Draw_Init(int width,int height,char *title,int pfps,int fps){ -#ifdef WIN32 - // Stdout on the parent console - AttachConsole(ATTACH_PARENT_PROCESS); - if(GetStdHandle(STD_OUTPUT_HANDLE)!=0){ - fclose(stdin); - fclose(stdout); - fclose(stderr); - freopen("CONIN$","r",stdin); - freopen("CONOUT$","w",stdout); - freopen("CONOUT$","w",stderr); - } -#endif // Set globals proc_t_frame=1000000/pfps; @@ -175,16 +163,16 @@ int Draw_Init(int width,int height,char *title,int pfps,int fps){ // Initialize SDL if(SDL_Init(SDL_INIT_VIDEO)<0){ - printf("Draw_Init: Failure initializing SDL.\n"); - printf("\tSDL Error: %s\n",SDL_GetError()); + Print("Draw_Init: Failure initializing SDL.\n"); + Print("\tSDL Error: %s\n",SDL_GetError()); return(0); } // Initialize video mode _screen=SDL_SetVideoMode(width,height,32,SDL_HWSURFACE|SDL_OPENGL); if( _screen == NULL){ - printf("Draw_Init: Failure initializing video mode.\n"); - printf("\tSDL Error: %s\n",SDL_GetError()); + Print("Draw_Init: Failure initializing video mode.\n"); + Print("\tSDL Error: %s\n",SDL_GetError()); return(0); } SDL_WM_SetCaption(title, NULL); @@ -310,15 +298,15 @@ int Draw_Init(int width,int height,char *title,int pfps,int fps){ // Show device information void Draw_ShowInfo(){ char *str; - printf("\n*********************************\n"); - printf("*** Draw Info\n"); + Print("\n*********************************\n"); + Print("*** Draw Info\n"); str=(char *)glGetString(GL_VENDOR); - printf(" Vendor: %s\n",str); + Print(" Vendor: %s\n",str); str=(char *)glGetString(GL_RENDERER); - printf(" Renderer: %s\n",str); + Print(" Renderer: %s\n",str); str=(char *)glGetString(GL_VERSION); - printf(" Version: %s\n",str); - printf("*********************************\n"); + Print(" Version: %s\n",str); + Print("*********************************\n"); } @@ -715,7 +703,7 @@ DrawImg Draw_LoadImage(char *filename){ (unsigned*)&image->h, filename); if(error){ - printf("Draw_LoadImage: PNG decoder error %u: %s on file %s\n", error, lodepng_error_text(error),filename); + Print("Draw_LoadImage: PNG decoder error %u: %s on file %s\n", error, lodepng_error_text(error),filename); return(NULL); } image->x=-(int)(image->w/2); @@ -725,7 +713,7 @@ DrawImg Draw_LoadImage(char *filename){ return (DrawImg)image; } - printf("Draw_LoadImage: Image type not supported: %s\n",filename); + Print("Draw_LoadImage: Image type not supported: %s\n",filename); return(NULL); } diff --git a/GameLib/GameLib.c b/GameLib/GameLib.c index 68ba50c..24e4fd5 100644 --- a/GameLib/GameLib.c +++ b/GameLib/GameLib.c @@ -392,12 +392,12 @@ void GameLib_DrawLoop(void *data, float f){ if(Input_GetKey(InputKey_DumpProfiling)==InputKey_Pressed && fproc_count>0 && fdraw_count>0) { - printf("Profiling:::::::::\n"); - printf("t_proc.....:%6lld\n",t_proc/fproc_count); - printf("t_col......:%6lld\n",t_col/fproc_count); - printf("t_over.....:%6lld\n",t_over/fproc_count); - printf("t_postproc.:%6lld\n",t_postproc/fproc_count); - printf("t_draw.....:%6lld\n",t_draw/fdraw_count); + Print("Profiling:::::::::\n"); + Print("t_proc.....:%6lld\n",t_proc/fproc_count); + Print("t_col......:%6lld\n",t_col/fproc_count); + Print("t_over.....:%6lld\n",t_over/fproc_count); + Print("t_postproc.:%6lld\n",t_postproc/fproc_count); + Print("t_draw.....:%6lld\n",t_draw/fdraw_count); t_proc=0; t_col=0; t_over=0; diff --git a/GameLib/Util.c b/GameLib/Util.c index 691a646..03768f5 100644 --- a/GameLib/Util.c +++ b/GameLib/Util.c @@ -1,8 +1,9 @@ // Copyright (C) 2011 Valeriano Alfonso Rodriguez (Kableado) -#include +#include #include #include +#include #include "Util.h" @@ -354,3 +355,23 @@ unsigned Rand_Get() { return (val); } + + +///////////////////////////// +// Print +// +// Prints the formated text +int Print(char *fmt, ...) { + va_list ap; + int n; + + // Print + va_start(ap, fmt); + n = vprintf(fmt, ap); + va_end(ap); + + // Flush + fflush(stdout); + return(n); +} + diff --git a/GameLib/Util.h b/GameLib/Util.h index bcd450d..e2ffa61 100644 --- a/GameLib/Util.h +++ b/GameLib/Util.h @@ -3,6 +3,8 @@ #ifndef _UTIL_H_ #define _UTIL_H_ +#include +#include ///////////////////////////// // SolveQuadratic @@ -88,4 +90,11 @@ unsigned Rand_Get(); #define Rand_GetFloat(x) (((float)(Rand_Get()%1048576))/1048576.0f) +///////////////////////////// +// Print +// +// Prints the formated text +int Print(char *fmt, ...); + + #endif