Mercurial > hg > forks > 3x666-SDL
comparison 3x666.c @ 31:03ef1b48e380
Cleanups.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Tue, 19 Mar 2013 01:20:05 +0200 |
parents | 9f72bd464802 |
children | 21a8993f3127 |
comparison
equal
deleted
inserted
replaced
30:3b0b5d73829e | 31:03ef1b48e380 |
---|---|
49 int *ballz; | 49 int *ballz; |
50 | 50 |
51 void setpal(void); | 51 void setpal(void); |
52 | 52 |
53 | 53 |
54 static inline int dmClamp(const int v, const int min, const int max) | 54 |
55 { | 55 static void dmPrintVA(int level, const char *fmt, va_list ap) |
56 return (v < min ? min : (v > max ? max : v)); | |
57 } | |
58 | |
59 | |
60 static int engineGetTick() | |
61 { | |
62 return ((engine.frameTime - engine.startTime) * SET_DEMOHZ) / 1000; | |
63 } | |
64 | |
65 | |
66 void dmPrintVA(const char *fmt, va_list ap) | |
67 { | 56 { |
68 #ifdef __WIN32 | 57 #ifdef __WIN32 |
69 (void) fmt; | 58 (void) fmt; |
70 (void) ap; | 59 (void) ap; |
71 #else | 60 #else |
72 vfprintf(stderr, fmt, ap); | 61 vfprintf(stderr, fmt, ap); |
73 #endif | 62 #endif |
74 } | 63 } |
75 | 64 |
76 | 65 |
77 void dmPrint(const char *fmt, ...) | 66 static void dmPrint(int level, const char *fmt, ...) |
78 { | 67 { |
79 #ifdef __WIN32 | 68 #ifdef __WIN32 |
80 (void) fmt; | 69 (void) fmt; |
81 #else | 70 #else |
82 va_list ap; | 71 va_list ap; |
83 | 72 |
84 va_start(ap, fmt); | 73 va_start(ap, fmt); |
85 dmPrintVA(fmt, ap); | 74 dmPrintVA(level, fmt, ap); |
86 va_end(ap); | 75 va_end(ap); |
87 #endif | 76 #endif |
77 } | |
78 | |
79 | |
80 static inline int dmClamp(const int v, const int min, const int max) | |
81 { | |
82 return (v < min ? min : (v > max ? max : v)); | |
88 } | 83 } |
89 | 84 |
90 | 85 |
91 void dmErrorVA(const char *fmt, va_list ap) | 86 void dmErrorVA(const char *fmt, va_list ap) |
92 { | 87 { |
103 dmErrorVA(fmt, ap); | 98 dmErrorVA(fmt, ap); |
104 va_end(ap); | 99 va_end(ap); |
105 } | 100 } |
106 | 101 |
107 | 102 |
103 static int engineGetTick() | |
104 { | |
105 return ((engine.frameTime - engine.startTime) * SET_DEMOHZ) / 1000; | |
106 } | |
107 | |
108 | |
108 static BOOL engineInitializeVideo() | 109 static BOOL engineInitializeVideo() |
109 { | 110 { |
110 SDL_FreeSurface(engine.screen); | 111 SDL_FreeSurface(engine.screen); |
111 | 112 |
112 engine.screen = SDL_SetVideoMode(SET_VID_BUFW, SET_VID_BUFH, 8, engine.optVFlags); | 113 engine.screen = SDL_SetVideoMode(SET_VID_BUFW, SET_VID_BUFH, 8, engine.optVFlags); |
449 *e = drum1 = malloc(drumlgt * sizeof(int)), i, | 450 *e = drum1 = malloc(drumlgt * sizeof(int)), i, |
450 vol = 24680, dvol = 35000 / (float) drumlgt; | 451 vol = 24680, dvol = 35000 / (float) drumlgt; |
451 int o = 0, oo = 0; | 452 int o = 0, oo = 0; |
452 float a = 0, da = 386 / (float) drumlgt, dda = da / (float) drumlgt; | 453 float a = 0, da = 386 / (float) drumlgt, dda = da / (float) drumlgt; |
453 | 454 |
454 dmPrint("aCtIvATiNg 303 eMuLAtOR\n"); | 455 dmPrint(0, "aCtIvATiNg 303 eMuLAtOR\n"); |
455 | 456 |
456 for (i = drumlgt; i; i--) | 457 for (i = drumlgt; i; i--) |
457 { | 458 { |
458 o = (o >> 1) + (rand() % vol) - (rand() % vol); | 459 o = (o >> 1) + (rand() % vol) - (rand() % vol); |
459 oo = (oo * 2 + ((rand() % vol) - (rand() % vol))) / 3; | 460 oo = (oo * 2 + ((rand() % vol) - (rand() % vol))) / 3; |
583 | 584 |
584 | 585 |
585 static void engineAudioCallback(void *userdata, Uint8 *stream, int len) | 586 static void engineAudioCallback(void *userdata, Uint8 *stream, int len) |
586 { | 587 { |
587 (void) userdata; | 588 (void) userdata; |
589 | |
588 // We inherently assume mono here, as the audio code is not | 590 // We inherently assume mono here, as the audio code is not |
589 // capable of producing stereo anyway (for now, at least.) | 591 // capable of producing stereo anyway (for now, at least.) |
590 int i, need = len / sizeof(Sint16); | 592 int i, need = len / sizeof(Sint16); |
591 | 593 |
592 #if 0 | 594 // fprintf(stderr, "%p : %p @ %d -> %d\n", userdata, stream, len, need); |
595 // fflush(stderr); | |
596 | |
597 #if 1 | |
593 // The audio rendering handling is a bit silly due to the way | 598 // The audio rendering handling is a bit silly due to the way |
594 // the original code works (assumes that it can always render | 599 // the original code works (assumes that it can always render |
595 // a certain amount/duration of data, instead of being given | 600 // a certain amount/duration of data, instead of being given |
596 // the buffer duration/size to render. So we cope with that here. | 601 // the buffer duration/size to render. So we cope with that here. |
597 if (need >= engine.mixBufSize) | 602 if (need >= engine.mixBufSize) |
598 need = engine.mixBufSize; | 603 need = engine.mixBufSize; |
599 | 604 |
600 while (engine.mixFill < need && engine.mixFill < engine.mixBufSize) | 605 while (engine.mixFill < need) |
601 { | 606 { |
602 int got = engineRenderAudio(engine.mixBuf + engine.mixFill); | 607 int got = engineRenderAudio(engine.mixBuf + engine.mixFill); |
603 engine.mixFill += got; | 608 engine.mixFill += got; |
604 } | 609 } |
605 | 610 |
932 int flagz = 0, flixtim = 0; | 937 int flagz = 0, flixtim = 0; |
933 char *phiword = NULL, *dizainword = NULL; | 938 char *phiword = NULL, *dizainword = NULL; |
934 | 939 |
935 memset(&engine, 0, sizeof(engine)); | 940 memset(&engine, 0, sizeof(engine)); |
936 | 941 |
937 dmPrint( | 942 dmPrint(0, |
938 SET_PROG_NAME " by Ocsa (PWP) (c) 1998\n" | 943 SET_PROG_NAME " by Ocsa (PWP) (c) 1998\n" |
939 "libSDL port by ccr/TNSP^PWP (c) 2013\n"); | 944 "libSDL port by ccr/TNSP^PWP (c) 2013\n"); |
940 | 945 |
941 // Parse commandline options | 946 // Parse commandline options |
942 // engine.optVFlags |= SDL_FULLSCREEN; | 947 // engine.optVFlags |= SDL_FULLSCREEN; |
943 | 948 |
944 | 949 |
945 // Initialize SDL components | 950 // Initialize SDL components |
946 dmPrint("Engine initializing ..\n"); | 951 dmPrint(0, "Engine initializing ..\n"); |
947 if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_TIMER) != 0) | 952 if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_TIMER) != 0) |
948 { | 953 { |
949 dmError("Could not initialize SDL: %s\n", SDL_GetError()); | 954 dmError("Could not initialize SDL: %s\n", SDL_GetError()); |
950 goto error_exit; | 955 goto error_exit; |
951 } | 956 } |
1158 SDL_Delay(20); | 1163 SDL_Delay(20); |
1159 } | 1164 } |
1160 | 1165 |
1161 error_exit: | 1166 error_exit: |
1162 // Shutdown | 1167 // Shutdown |
1163 dmPrint("Shutting down.\n"); | 1168 dmPrint(0, "Shutting down.\n"); |
1164 dmPrint("%d frames in %d ms, %1.2f fps\n", | 1169 dmPrint(1, "%d frames in %d ms, %1.2f fps\n", |
1165 engine.frameCount, | 1170 engine.frameCount, |
1166 engine.frameTime - engine.startTime, | 1171 engine.frameTime - engine.startTime, |
1167 (float) (engine.frameCount * 1000.0f) / (float) (engine.frameTime - engine.startTime) | 1172 (float) (engine.frameCount * 1000.0f) / (float) (engine.frameTime - engine.startTime) |
1168 ); | 1173 ); |
1169 | 1174 |