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iiFFFFFFEEEEEEEEEEEEEEEDD,,,,,,,,,"
35 "dddddddddddddddeeeeeeeeeeeeeeeeeefffffffffffffggggggggghhhhhhhiiiiiiFFFFFFEEEEEEEEEEEEEEEDD,,,,,,,,,"
36 "dddddddddddddddeeeeeeeeeeeeeeeeeefffffffffffffggggggggghhhhhhhiiiiiiFFFFFFEEEEEEEEEEEEEEEDDDDDDDDDDD"
37 "dddddddddddddddeeeeeeeeeeeeeeeeeefffffffffffffggggggggghhhhhhhiiiiiiFFFFFFEEEEEEEEEEEEEEEDDDDDDDDDDD"
38 "dddddddddddddddeeeeeeeeeeeeeeeeeefffffffffffffggggggggghhhhhhhiiiiiiFFFFFFEEEEEEEEEEEEEEEDDDDDDDDDDD"
39 "dddddddddddddddeeeeeeeeeeeeeeeeeefffffffffffffggggggggghhhhhhhiiiiiiFFFFFFEEEEEEEEEEEEEEEDDDDDDDDDDD"
40 "dddddddddddddddeeeeeeeeeeeeeeeeeefffffffffffffggggggggghhhhhhhiiiiiiFFFFFFEEEEEEEEEEEEEEEDDDDDDDDDDD"
41 "dddddddddddddddeeeeeeeeeeeeeeeeeefffffffffffffggggggggghhhhhhhiiiiiiFFFFFFEEEEEEEEEEEEEEEDDDDDDDDDDD"
42 "dddddddddddddddeeeeeeeeeeeeeeeeeefffffffffffffggggggggghhhhhhhiiiiiiFFFFFFEEEEEEEEEEEEEEEDDDDDDDDDDD"
43 "dddddddddddddddeeeeeeeeeeeeeeeeeefffffffffffffggggggggghhhhhhhi.....FFFFFFEEEEEEEEEEEEEEEDDDDDDDDDDD"
44 "dddddddddddddddeeeeeeeeeeeeeeeeeefffffffffffffggggggggghhh..........FFFFFFEEEEEEEEEEEEEEEDDDDDDDDDDD"
45 "dddddddddddddddeeeeeeeeeeeeeeeeeefffffffffffffggggggg...............FFFFFFEEEEEEEEEEEEEEEDDDDDDDDDDD"
46 "dddddddddddddddeeeeeeeeeeeeeeeeeefffffffffffffg.....................FFFFFFEEEEEEEEEEEEEEEDDDDDDDDDDD"
47 "dddddddddddddddeeeeeeeeeeeeeeeeeefffffffff..........................FFFFFFEEEEEEEEEEEEEEEDDDDDDDDDDD"
48 "dddddddddddddddeeeeeeeeeeeeeeeeeeffff.................................FFFFEEEEEEEEEEEEEEEDDDDDDDDDDD"
49 "dddddddddddddddeeeeeeeeeeeeeeee............................................EEEEEEEEEEEEEEDDDDDDDDDDD"
50 "dddddddddddddddeeeeeeeeeee.....................................................EEEEEEEEEEDDDDDDDDDDD"
51 "dddddddddddddddeeeeee..............................................................EEEEEEDDDDDDDDDDD"
52 "ddddddddddddddde.......................................................................EEDDDDDDDDDDD"
53 "ddddddddddd.................................................................................DDDDDDDD"
54 "ddddddd........................................................................................DDDDD";
56 static const char renderComplexExpect
[] =
57 ",,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,"
58 ",,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,DD,,,,,,,,,"
59 ",,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,EEEEEDDe,,,,,,,,"
60 ",,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,EEEEEEEEDDee,,,,,,,"
61 ",,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,EEEEEEEEEEEEEDDeee,,,,,,"
62 ",,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,FFEEEEEEEEEEEEEEEDDeeee,,,,,"
63 ",,,,,,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eeeeeeeeeeeeeeeefffffffffffffgggggg,,,,,,,,,,,,,,,,FFFFFFEEEEEEEEEEEEEEEDDeeeef,GGG"
74 "dddddddddddddddeeeeeeeeeeeeeeeeeefffffffffffffggggggggghhhhhhhiiiii,FFFFFFEEEEEEEEEEEEEEEDDeeeefGGGG"
75 "dddddddddddddddeeeeeeeeeeeeeeeeeefffffffffffffggggggggghhhhhhhiiiiiiFFFFFFEEEEEEEEEEEEEEEDDeeeefGGGG"
76 "dddddddddddddddeeeeeeeeeeeeeeeeeefffffffffffffggggggggghhhhhhhiiiiiiFFFFFFEEEEEEEEEEEEEEEDDeeeefGGGG"
77 "dddddddddddddddeeeeeeeeeeeeeeeeeefffffffffffffggggggggghhhhhhhiiiiiiFFFFFFEEEEEEEEEEEEEEEDDeeeefGGGG"
78 "dddddddddddddddeeeeeeeeeeeeeeeeeefffffffffffffggggggggghhhhhhhiiiiiiFFFFFFEEEEEEEEEEEEEEEDDeeeefGGGG"
79 "dddddddddddddddeeeeeeeeeeeeeeeeeefffffffffffffggggggggghhhhhhhiiiiiiFFFFFFEEEEEEEEEEEEEEEDDeeeefGGGG"
80 "dddddddddddddddeeeeeeeeeeeeeeeeeefffffffffffffggggggggghhhhhhhiiiiiiFFFFFFEEEEEEEEEEEEEEEDDeeeefGGGG"
81 "dddddddddddddddeeeeeeeeeeeeeeeeeefffffffffffffggggggggghhhhhhhiiiiiiFFFFFFEEEEEEEEEEEEEEEDDeeeefGGGG"
82 "dddddddddddddddeeeeeeeeeeeeeeeeeefffffffffffffggggggggghhhhhhhiiiiiiFFFFFFEEEEEEEEEEEEEEEDDeeeefGGGG"
83 "dddddddddddddddeeeeeeeeeeeeeeeeeefffffffffffffggggggggghhhhhhhiiiiiiFFFFFFEEEEEEEEEEEEEEEDDeeeefGGGG"
84 "dddddddddddddddeeeeeeeeeeeeeeeeeefffffffffffffggggggggghhhhhhhiiiiiiFFFFFFEEEEEEEEEEEEEEEDDeeeefGGGG"
85 "dddddddddddddddeeeeeeeeeeeeeeeeeefffffffffffffggggggggghhhhhhhi.....FFFFFFEEEEEEEEEEEEEEEDDeeeefGGGG"
86 "dddddddddddddddeeeeeeeeeeeeeeeeeefffffffffffffggggggggghhh..........FFFFFFEEEEEEEEEEEEEEEDDeeeefGGGG"
87 "dddddddddddddddeeeeeeeeeeeeeeeeeefffffffffffffgggggg................FFFFFFEEEEEEEEEEEEEEEDDeeeefGGGG"
88 "dddddddddddddddeeeeeeeeeeeeeeeeeefffffffffffffg.....................FFFFFFEEEEEEEEEEEEEEEDDeeeef...."
89 "dddddddddddddddeeeeeeeeeeeeeeeeeeffffffff...........................FFFFFFEEEEEEEEEEEEEEEDDeeeef...."
90 "dddddddddddddddeeeeeeeeeeeeeeeeeefff...................................FFFEEEEEEEEEEEEEEEDDeeeef...."
91 "dddddddddddddddeeeeeeeeeeeeeeee............................................EEEEEEEEEEEEEEDDeeeefFFFE"
92 "dddddddddddddddeeeeeeeeeee.....................................................EEEEEEEEEEDDeeeefFFFE"
93 "dddddddddddddddeeeee................................................................EEEEEDDeeee....E"
94 "ddddddddddddddd..........................................................................DDeee......"
95 "ddddddddddd.................................................................................e......."
96 "dddd................................................................................................";
98 RCL_Unit
testArrayFunc(int16_t x
, int16_t y
)
101 return RCL_UNITS_PER_SQUARE
* 3;
104 return -1 * RCL_UNITS_PER_SQUARE
/ 4;
106 return (x
< 0 || x
>= 10 || y
< 0 || y
>= 10) ?
107 (RCL_UNITS_PER_SQUARE
* 2) : 0;
110 int testSingleRay(RCL_Unit startX
, RCL_Unit startY
, RCL_Unit dirX
,
111 RCL_Unit dirY
, int16_t expectSquareX
, int16_t expectSquareY
,
112 int16_t expectPointX
, int16_t expectPointY
, int16_t tolerateError
)
118 r
.direction
.x
= dirX
;
119 r
.direction
.y
= dirY
;
121 printf("- casting ray:\n");
124 RCL_HitResult h
= RCL_castRay(r
,testArrayFunc
);
126 printf("- result:\n");
130 h
.square
.x
== expectSquareX
&&
131 h
.square
.y
== expectSquareY
&&
132 h
.position
.x
<= expectPointX
+ tolerateError
&&
133 h
.position
.x
>= expectPointX
- tolerateError
&&
134 h
.position
.y
<= expectPointY
+ tolerateError
&&
135 h
.position
.y
>= expectPointY
- tolerateError
;
140 printf("\nFAIL\n\n");
145 int testSingleMapping(RCL_Unit posX
, RCL_Unit posY
, RCL_Unit posZ
, uint32_t resX
,
146 uint32_t resY
, RCL_Unit camX
, RCL_Unit camY
, RCL_Unit camZ
, RCL_Unit camDir
,
147 RCL_Unit expectX
, RCL_Unit expectY
, RCL_Unit expectZ
)
155 c
.resolution
.x
= resX
;
156 c
.resolution
.y
= resY
;
159 c
.direction
= camDir
;
171 printf("- mapping pixel: %d %d %d\n",posX
,posY
,posZ
);
173 p
= RCL_mapToScreen(pos
,height
,c
);
175 printf("- result:\n");
178 result
= p
.position
.x
== expectX
&& p
.position
.y
== expectY
&&
184 printf("\nFAIL\n\n");
189 // returns milliseconds
190 long measureTime(void (*func
)(void))
193 struct timeval timecheck
;
195 gettimeofday(&timecheck
, NULL
);
196 start
= (long) timecheck
.tv_sec
* 1000 + (long) timecheck
.tv_usec
/ 1000;
200 gettimeofday(&timecheck
, NULL
);
201 end
= (long) timecheck
.tv_sec
* 1000 + (long) timecheck
.tv_usec
/ 1000;
210 r
.start
.x
= RCL_UNITS_PER_SQUARE
+ RCL_UNITS_PER_SQUARE
/ 2;
211 r
.start
.y
= 2 * RCL_UNITS_PER_SQUARE
+ RCL_UNITS_PER_SQUARE
/ 4;
213 RCL_Vector2D directions
[8];
215 for (int i
= 0; i
< 8; ++i
)
216 directions
[i
] = RCL_angleToDirection(RCL_UNITS_PER_SQUARE
/ 8 * i
);
218 for (int i
= 0; i
< 1000000; ++i
)
220 r
.direction
= directions
[i
% 8];
221 RCL_castRay(r
,testArrayFunc
);
225 void benchmarkMapping()
229 c
.resolution
.x
= 1024;
230 c
.resolution
.y
= 768;
231 c
.position
.x
= RCL_UNITS_PER_SQUARE
/ 2;
232 c
.position
.y
= RCL_UNITS_PER_SQUARE
* 2;
233 c
.direction
= RCL_UNITS_PER_SQUARE
/ 8;
241 pos
.x
= -1024 * RCL_UNITS_PER_SQUARE
;
242 pos
.y
= -512 * RCL_UNITS_PER_SQUARE
;
245 for (int i
= 0; i
< 1000000; ++i
)
247 p
= RCL_mapToScreen(pos
,height
,c
);
251 height
= (height
+ 16) % 1024;
256 uint32_t *pixelCounts
= 0;
257 RCL_Camera countCamera
;
260 #define TEST_SCREEN_RES_X 100
261 #define TEST_SCREEN_RES_Y 40
263 char testScreen
[TEST_SCREEN_RES_X
* TEST_SCREEN_RES_Y
];
265 void pixelFunc(RCL_PixelInfo
*p
)
267 if (renderMode
== 0) // count pixels
269 if (p
->position
.x
>= countCamera
.resolution
.x
|| p
->position
.x
< 0 ||
270 p
->position
.y
>= countCamera
.resolution
.y
|| p
->position
.y
< 0)
272 printf("ERROR: writing pixel outside screen at %d %d!\n",
273 p
->position
.x
,p
->position
.y
);
278 pixelCounts
[p
->position
.y
* countCamera
.resolution
.x
+ p
->position
.x
]++;
280 else if (renderMode
== 1)
290 c
= (p
->hit
.direction
% 2 ? 'a' : 'A') + p
->depth
/ 512;
292 testScreen
[p
->position
.y
* TEST_SCREEN_RES_X
+ p
->position
.x
] = c
;
296 int testPixelCount(RCL_Unit camX
, RCL_Unit camY
, RCL_Unit camZ
,
297 RCL_Unit camDir
, RCL_Unit camShear
, uint16_t camResX
, uint16_t camResY
,
300 printf("Counting rendered pixels (each should be rendered exactly once)...\n");
302 RCL_RayConstraints constraints
;
305 RCL_initRayConstraints(&constraints
);
306 constraints
.maxSteps
= 32;
311 c
.direction
= camDir
;
314 c
.resolution
.x
= camResX
;
315 c
.resolution
.y
= camResY
;
317 uint32_t pixels
[camResX
* camResY
];
319 for (int32_t i
= 0; i
< camResX
* camResY
; ++i
)
322 pixelCounts
= pixels
;
329 RCL_renderComplex(c
,testArrayFunc
,testArrayFunc
,0,constraints
);
331 RCL_renderSimple(c
,testArrayFunc
,0,0,constraints
);
333 for (uint32_t y
= 0; y
< camResY
; ++y
)
334 for (uint32_t x
= 0; x
< camResX
; ++x
)
336 uint32_t index
= y
* camResX
+ x
;
338 if (pixels
[index
] != 1)
340 printf("ERROR: pixel at %d %d written %d times!\n",x
,y
,pixels
[index
]);
348 int testRender(int8_t simple
)
350 printf("\nTesting rendering\n");
357 c
.resolution
.x
= TEST_SCREEN_RES_X
;
358 c
.resolution
.y
= TEST_SCREEN_RES_Y
;
359 c
.position
.x
= 2 * RCL_UNITS_PER_SQUARE
+ RCL_UNITS_PER_SQUARE
/ 2; // 3000;//5 * RCL_UNITS_PER_SQUARE;
360 c
.position
.y
= 5 * RCL_UNITS_PER_SQUARE
+ RCL_UNITS_PER_SQUARE
/ 2; //5000;//5 * RCL_UNITS_PER_SQUARE;
361 c
.direction
= 625;//700;
362 c
.height
= 1500;//1000;
364 RCL_RayConstraints constraints
;
365 RCL_initRayConstraints(&constraints
);
367 constraints
.maxHits
= 7;
368 constraints
.maxSteps
= 20;
372 for (uint32_t i
= 0; i
< TEST_SCREEN_RES_X
* TEST_SCREEN_RES_Y
; ++i
)
377 RCL_renderSimple(c
,testArrayFunc
,0,0,constraints
);
381 RCL_renderComplex(c
,testArrayFunc
,0,0,constraints
);
384 for (uint32_t i
= 0; i
< TEST_SCREEN_RES_X
* TEST_SCREEN_RES_Y
; ++i
)
386 if ((i
% TEST_SCREEN_RES_X
) == 0)
389 printf("%c",testScreen
[i
]);
392 const char *expect
= simple
? renderSimpleExpect
: renderComplexExpect
;
394 for (uint32_t i
= 0; i
< TEST_SCREEN_RES_X
* TEST_SCREEN_RES_Y
; ++i
)
395 if (expect
[i
] != testScreen
[i
])
397 printf("\n\nFAIL!\n");
406 void benchmarkRender()
411 c
.resolution
.x
= 640;
412 c
.resolution
.y
= 300;
418 RCL_RayConstraints constraints
;
419 RCL_initRayConstraints(&constraints
);
421 constraints
.maxHits
= 10;
422 constraints
.maxSteps
= 12;
424 renderMode
= 255; // don't write pixels
426 for (int i
= 0; i
< 100; ++i
)
427 RCL_renderComplex(c
,testArrayFunc
,testArrayFunc
,0,constraints
);
432 printf("Testing raycastlib.\n");
435 3 * RCL_UNITS_PER_SQUARE
+ RCL_UNITS_PER_SQUARE
/ 2,
436 4 * RCL_UNITS_PER_SQUARE
+ RCL_UNITS_PER_SQUARE
/ 2,
462 -4 * RCL_UNITS_PER_SQUARE
- RCL_UNITS_PER_SQUARE
/ 2,
463 7 * RCL_UNITS_PER_SQUARE
+ RCL_UNITS_PER_SQUARE
/ 3,
470 printf("testing perspective scale...\n");
472 for (RCL_Unit i
= 1; i
< 100; ++i
)
474 RCL_Unit size
= i
* 3;
475 RCL_Unit distance
= i
* 6 + 200;
477 RCL_Unit scaled
= RCL_perspectiveScaleHorizontal(size
,distance
);
478 RCL_Unit distance2
= RCL_perspectiveScaleHorizontalInverse(size
,scaled
);
480 if (RCL_absVal(distance
- distance2
> 2))
481 printf("ERROR: distance: %d, distance inverse: %d\n",distance
,distance2
);
487 RCL_UNITS_PER_SQUARE
/ 2,
488 RCL_UNITS_PER_SQUARE
/ 2,
489 RCL_UNITS_PER_SQUARE
/ 2,
498 3 * RCL_UNITS_PER_SQUARE
+ 100,
499 4 * RCL_UNITS_PER_SQUARE
+ RCL_UNITS_PER_SQUARE
/ 3,
500 RCL_UNITS_PER_SQUARE
/ 2,
509 - RCL_UNITS_PER_SQUARE
,
521 if (!testSingleMapping(
522 RCL_UNITS_PER_SQUARE
,
523 RCL_UNITS_PER_SQUARE
* 2,
527 RCL_UNITS_PER_SQUARE
/ 2,
529 RCL_UNITS_PER_SQUARE
/ 4,
530 (RCL_UNITS_PER_SQUARE
* 5) / 6,
543 printf("benchmark:\n");
546 t
= measureTime(benchCastRays
);
547 printf("cast 1000000 rays: %ld ms\n",t
);
549 t
= measureTime(benchmarkMapping
);
550 printf("map point to screen 1000000 times: %ld ms\n",t
);
552 t
= measureTime(benchmarkRender
);
553 printf("render 100 times: %ld ms\n",t
);
558 printf("\n===== all OK =====\n");