Replace random() with example_random(), put definitions at start of scopes
This commit is contained in:
parent
e32d51dedc
commit
d258cd9da3
46
src/main.c
46
src/main.c
@ -3,17 +3,29 @@
|
|||||||
#ifndef unigi_flag_exception
|
#ifndef unigi_flag_exception
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
|
#ifndef min
|
||||||
#define min(x, y) ((x) < (y) ? (x) : (y))
|
#define min(x, y) ((x) < (y) ? (x) : (y))
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef max
|
||||||
#define max(x, y) ((x) > (y) ? (x) : (y))
|
#define max(x, y) ((x) > (y) ? (x) : (y))
|
||||||
|
#endif
|
||||||
|
|
||||||
|
unigi_type_uint32 seed = 1337;
|
||||||
|
unigi_type_uint32 example_random() {
|
||||||
|
seed = (seed * 1103515245 + 12345) & 0x7FFFFFFF;
|
||||||
|
return seed;
|
||||||
|
}
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
if (unigi_init() > 0) { return 1; }
|
|
||||||
if (unigi_graphics_init() > 0) { return 1; }
|
|
||||||
size_t resolution_index = 0;
|
size_t resolution_index = 0;
|
||||||
unigi_type_resolution_pixel_index smallestValidSize = 0 - 1;
|
unigi_type_resolution_pixel_index smallestValidSize = 0 - 1;
|
||||||
unigi_type_resolution smallestValidRes;
|
unigi_type_resolution smallestValidRes;
|
||||||
smallestValidRes.width = 0;
|
smallestValidRes.width = 0;
|
||||||
|
|
||||||
|
if (unigi_init() > 0) { return 1; }
|
||||||
|
if (unigi_graphics_init() > 0) { return 1; }
|
||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
unigi_type_resolution_range * range = &unigi_status_resolutions[resolution_index];
|
unigi_type_resolution_range * range = &unigi_status_resolutions[resolution_index];
|
||||||
if (
|
if (
|
||||||
@ -36,6 +48,7 @@ int main() {
|
|||||||
range->min->width <= 800 &&
|
range->min->width <= 800 &&
|
||||||
range->min->height <= 600
|
range->min->height <= 600
|
||||||
) {
|
) {
|
||||||
|
unigi_type_resolution_pixel_index size;
|
||||||
unigi_type_resolution_pixel_axis smallestWidth = min(
|
unigi_type_resolution_pixel_axis smallestWidth = min(
|
||||||
max(range->min->width,320),
|
max(range->min->width,320),
|
||||||
min(range->max->width,800)
|
min(range->max->width,800)
|
||||||
@ -48,7 +61,7 @@ int main() {
|
|||||||
|
|
||||||
printf("Found valid resolution: %ix%ix%i\n",smallestWidth,smallestHeight,range->min->depth);
|
printf("Found valid resolution: %ix%ix%i\n",smallestWidth,smallestHeight,range->min->depth);
|
||||||
|
|
||||||
unigi_type_resolution_pixel_index size = (unigi_type_resolution_pixel_index)smallestWidth * smallestHeight;
|
size = (unigi_type_resolution_pixel_index)smallestWidth * smallestHeight;
|
||||||
if (size < smallestValidSize) {
|
if (size < smallestValidSize) {
|
||||||
smallestValidRes.width = smallestWidth;
|
smallestValidRes.width = smallestWidth;
|
||||||
smallestValidRes.height = smallestHeight;
|
smallestValidRes.height = smallestHeight;
|
||||||
@ -75,6 +88,15 @@ int main() {
|
|||||||
unigi_input_init();
|
unigi_input_init();
|
||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
|
unigi_type_resolution_pixel_axis startX;
|
||||||
|
unigi_type_resolution_pixel_axis startY;
|
||||||
|
unigi_type_resolution_pixel_axis width;
|
||||||
|
unigi_type_resolution_pixel_axis height;
|
||||||
|
unigi_type_resolution_pixel_index startIndex;
|
||||||
|
unigi_type_resolution_pixel_index stopIndex;
|
||||||
|
unigi_type_resolution_pixel_index prog;
|
||||||
|
unigi_type_resolution_pixel_axis ind;
|
||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
unigi_type_event * event = unigi_event_get();
|
unigi_type_event * event = unigi_event_get();
|
||||||
if (event->id == unigi_enum_event_none) { break; }
|
if (event->id == unigi_enum_event_none) { break; }
|
||||||
@ -89,20 +111,20 @@ int main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Draw some random squares on the screen
|
// Draw some random squares on the screen
|
||||||
unigi_type_resolution_pixel_axis startX = random() % (unigi_status_resolution.width);
|
startX = example_random() % (unigi_status_resolution.width);
|
||||||
unigi_type_resolution_pixel_axis startY = random() % (unigi_status_resolution.height);
|
startY = example_random() % (unigi_status_resolution.height);
|
||||||
unigi_type_resolution_pixel_axis width = random() % (unigi_status_resolution.width - startX);
|
width = example_random() % (unigi_status_resolution.width - startX);
|
||||||
unigi_type_resolution_pixel_axis height = random() % (unigi_status_resolution.height - startY);
|
height = example_random() % (unigi_status_resolution.height - startY);
|
||||||
unigi_type_resolution_pixel_index startIndex = startX + (unigi_status_resolution.width * startY);
|
startIndex = startX + (unigi_status_resolution.width * startY);
|
||||||
unigi_type_resolution_pixel_index stopIndex = startIndex + width;
|
stopIndex = startIndex + width;
|
||||||
unigi_graphics_draw_square(startIndex,stopIndex,height,random() % 65535);
|
unigi_graphics_draw_square(startIndex,stopIndex,height,example_random() % 65535);
|
||||||
|
|
||||||
// Draw a simple test pattern, and demonstrate how to use floats
|
// Draw a simple test pattern, and demonstrate how to use floats
|
||||||
unigi_type_resolution_pixel_index prog = unigi_float_2int(unigi_float_mul(
|
prog = unigi_float_2int(unigi_float_mul(
|
||||||
unigi_float_make(unigi_status_resolution.width),
|
unigi_float_make(unigi_status_resolution.width),
|
||||||
unigi_float_div(unigi_float_make(1),unigi_float_make(40))
|
unigi_float_div(unigi_float_make(1),unigi_float_make(40))
|
||||||
));
|
));
|
||||||
unigi_type_resolution_pixel_axis ind = 0;
|
ind = 0;
|
||||||
unigi_graphics_draw_square(prog * ind,prog * (ind + 1),unigi_status_resolution.height,0xF00F);
|
unigi_graphics_draw_square(prog * ind,prog * (ind + 1),unigi_status_resolution.height,0xF00F);
|
||||||
ind++;
|
ind++;
|
||||||
unigi_graphics_draw_square(prog * ind,prog * (ind + 1),unigi_status_resolution.height,0xFF0F);
|
unigi_graphics_draw_square(prog * ind,prog * (ind + 1),unigi_status_resolution.height,0xFF0F);
|
||||||
|
Loading…
Reference in New Issue
Block a user