Mercurial > hg > demos > krapula
comparison krapula.c @ 25:98dcf1847e75
Cleanups, add the debug mode enabling option.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Tue, 02 Oct 2012 18:17:52 +0300 |
parents | 01f3af410abb |
children | 077d08c442f7 |
comparison
equal
deleted
inserted
replaced
24:01f3af410abb | 25:98dcf1847e75 |
---|---|
1 #include "dmsimple.h" | 1 #include "dmsimple.h" |
2 #include "dmvecmat.h" | 2 #include "dmvecmat.h" |
3 | |
4 #include <math.h> | 3 #include <math.h> |
5 | |
6 | |
7 #define DM_COLORS (256) | |
8 | 4 |
9 | 5 |
10 DMOptArg optList[] = | 6 DMOptArg optList[] = |
11 { | 7 { |
12 { 0, '?', "help", "Show this help", OPT_NONE }, | 8 { 0, '?', "help", "Show this help", OPT_NONE }, |
13 { 1, 'v', "verbose", "Be more verbose", OPT_NONE }, | 9 { 1, 'v', "verbose", "Be more verbose", OPT_NONE }, |
14 { 2, 'f', "fs", "Fullscreen", OPT_NONE }, | 10 { 2, 'f', "fs", "Fullscreen", OPT_NONE }, |
11 #ifdef DM_DEBUG | |
12 { 3, 'd', "debug", "Debug mode", OPT_NONE }, | |
13 #endif | |
15 }; | 14 }; |
16 | 15 |
17 const int optListN = sizeof(optList) / sizeof(optList[0]); | 16 const int optListN = sizeof(optList) / sizeof(optList[0]); |
18 | 17 |
19 | 18 |
25 } | 24 } |
26 | 25 |
27 | 26 |
28 BOOL argHandleOpt(const int optN, char *optArg, char *currArg) | 27 BOOL argHandleOpt(const int optN, char *optArg, char *currArg) |
29 { | 28 { |
30 switch (optN) { | 29 (void) optArg; |
31 case 0: | 30 |
32 argShowHelp(); | 31 switch (optN) |
33 exit(0); | 32 { |
34 break; | 33 case 0: |
35 | 34 argShowHelp(); |
36 case 1: | 35 exit(0); |
37 dmVerbosity++; | 36 break; |
38 break; | 37 |
39 | 38 case 1: |
40 case 2: | 39 dmVerbosity++; |
41 engine.optVFlags |= SDL_FULLSCREEN; | 40 break; |
42 break; | 41 |
43 | 42 case 2: |
44 default: | 43 engine.optVFlags |= SDL_FULLSCREEN; |
45 dmError("Unknown option '%s'.\n", currArg); | 44 break; |
46 return FALSE; | 45 |
46 #ifdef DM_DEBUG | |
47 case 3: | |
48 engine.optDebug = TRUE; | |
49 break; | |
50 #endif | |
51 | |
52 default: | |
53 dmError("Unknown option '%s'.\n", currArg); | |
54 return FALSE; | |
47 } | 55 } |
48 | 56 |
49 return TRUE; | 57 return TRUE; |
50 } | 58 } |
51 | 59 |
52 | 60 |
53 | 61 #define DM_COLORS (256) |
54 | 62 |
55 void dmMakePalette(SDL_Surface *scr) | 63 void dmMakePalette(SDL_Surface *scr) |
56 { | 64 { |
57 SDL_Color pal[DM_COLORS]; | 65 SDL_Color pal[DM_COLORS]; |
58 int n; | 66 int n; |
83 pix += screen->pitch; | 91 pix += screen->pitch; |
84 } | 92 } |
85 } | 93 } |
86 | 94 |
87 | 95 |
88 void dmPerlin(SDL_Surface *screen, float f) | |
89 { | |
90 Uint8 *pix = screen->pixels; | |
91 int xc, yc; | |
92 | |
93 for (yc = 0; yc < screen->h; yc++) | |
94 { | |
95 Uint8 *dp = pix; | |
96 | |
97 for (xc = 0; xc < screen->w; xc++) | |
98 { | |
99 *dp++ = 128 + dmPerlinNoise2D(xc, yc, 0.01, 0.1, 3) / 34.0; | |
100 } | |
101 | |
102 pix += screen->pitch; | |
103 } | |
104 } | |
105 | |
106 | |
107 #define QWIDTH 256 | 96 #define QWIDTH 256 |
108 #define QHEIGHT 160 | 97 #define QHEIGHT 160 |
109 | 98 |
110 typedef Uint8 DMBlockMap[QHEIGHT][QWIDTH]; | 99 typedef Uint8 DMBlockMap[QHEIGHT][QWIDTH]; |
111 | 100 |
118 | 107 |
119 void dmMakeBumpMap(DMBlockMap map, DMFloat q, DMFloat m) | 108 void dmMakeBumpMap(DMBlockMap map, DMFloat q, DMFloat m) |
120 { | 109 { |
121 int x, y; | 110 int x, y; |
122 for (y = 0; y < QHEIGHT; y++) | 111 for (y = 0; y < QHEIGHT; y++) |
112 { | |
123 for (x = 0; x < QWIDTH; x++) | 113 for (x = 0; x < QWIDTH; x++) |
124 { | 114 { |
125 DMFloat f = 0.40f + dmPerlinNoise2D(x, y, 1.1f, q, 2); | 115 DMFloat f = 0.40f + dmPerlinNoise2D(x, y, 1.1f, q, 2); |
126 map[y][x] = (int) (dmClip(f) * m); | 116 map[y][x] = (int) (dmClip(f) * m); |
127 } | 117 } |
118 } | |
128 } | 119 } |
129 | 120 |
130 | 121 |
131 void dmShadowTraceHeightMap(DMBlockMap lightMap, DMBlockMap pheightMap, DMVector *light) | 122 void dmShadowTraceHeightMap(DMBlockMap lightMap, DMBlockMap pheightMap, DMVector *light) |
132 { | 123 { |
398 | 389 |
399 engine.optScrWidth = 640; | 390 engine.optScrWidth = 640; |
400 engine.optScrHeight = 480; | 391 engine.optScrHeight = 480; |
401 engine.optBitDepth = 32; | 392 engine.optBitDepth = 32; |
402 engine.optVFlags = SDL_SWSURFACE | SDL_HWPALETTE; | 393 engine.optVFlags = SDL_SWSURFACE | SDL_HWPALETTE; |
403 | 394 #ifdef DM_DEBUG |
395 engine.demoDuration = 150; | |
396 #endif | |
404 | 397 |
405 if (!dmArgsProcess(argc, argv, optList, optListN, | 398 if (!dmArgsProcess(argc, argv, optList, optListN, |
406 argHandleOpt, NULL, FALSE)) | 399 argHandleOpt, NULL, FALSE)) |
407 return DMERR_INIT_FAIL; | 400 return DMERR_INIT_FAIL; |
408 | 401 |
412 | 405 |
413 return DMERR_OK; | 406 return DMERR_OK; |
414 } | 407 } |
415 | 408 |
416 | 409 |
417 int demoGlobalInit() | 410 int demoInit() |
418 { | 411 { |
419 int i; | 412 int i; |
420 | 413 |
421 // Initialize effect stuff | 414 // Initialize effect stuff |
422 dmPerlinInit(); | 415 dmPerlinInit(); |
449 jmpSetModule(engine.plr, mod); | 442 jmpSetModule(engine.plr, mod); |
450 jmpPlayOrder(engine.plr, 0); | 443 jmpPlayOrder(engine.plr, 0); |
451 jvmSetGlobalVol(engine.dev, 55); | 444 jvmSetGlobalVol(engine.dev, 55); |
452 | 445 |
453 return DMERR_OK; | 446 return DMERR_OK; |
447 } | |
448 | |
449 | |
450 void demoShutdown() | |
451 { | |
452 SDL_FreeSurface(bmap); | |
453 } | |
454 | |
455 | |
456 void demoQuit() | |
457 { | |
458 dmPrint(0, "Krapulassa on kivaa.\n"); | |
454 } | 459 } |
455 | 460 |
456 | 461 |
457 int demoMainTick() | 462 int demoMainTick() |
458 { | 463 { |
733 } | 738 } |
734 } | 739 } |
735 | 740 |
736 return DMERR_OK; | 741 return DMERR_OK; |
737 } | 742 } |
738 | |
739 | |
740 void demoFinish() | |
741 { | |
742 dmPrint(0, "Krapulassa on kivaa.\n"); | |
743 } |