diff options
| author | Ray <[email protected]> | 2019-05-14 15:34:23 +0200 |
|---|---|---|
| committer | Ray <[email protected]> | 2019-05-14 15:34:23 +0200 |
| commit | 424d3ca8d9c5d612606444b2a2099cfad37f1888 (patch) | |
| tree | 873e8ec9dbd5965d828ed450a8c12feafe714597 /examples/core | |
| parent | 2edec8ae288ba70630021b330fe61c9005bc03d9 (diff) | |
| download | raylib-424d3ca8d9c5d612606444b2a2099cfad37f1888.tar.gz raylib-424d3ca8d9c5d612606444b2a2099cfad37f1888.zip | |
examples review
Redesigns, deletes and renames
Also noted authors propertly on contributed examples
Diffstat (limited to 'examples/core')
| -rw-r--r-- | examples/core/core_3d_camera_mode.c (renamed from examples/core/core_3d_mode.c) | 10 | ||||
| -rw-r--r-- | examples/core/core_3d_camera_mode.png (renamed from examples/core/core_3d_mode.png) | bin | 8492 -> 8492 bytes | |||
| -rw-r--r-- | examples/core/core_color_select.c | 94 | ||||
| -rw-r--r-- | examples/core/core_color_select.png | bin | 14328 -> 0 bytes | |||
| -rw-r--r-- | examples/core/core_custom_logging.c | 4 | ||||
| -rw-r--r-- | examples/core/core_input_gestures.c (renamed from examples/core/core_gestures_detection.c) | 4 | ||||
| -rw-r--r-- | examples/core/core_input_gestures.png (renamed from examples/core/core_gestures_detection.png) | bin | 19480 -> 19480 bytes | |||
| -rw-r--r-- | examples/core/core_input_mouse_wheel.c (renamed from examples/core/core_mouse_wheel.c) | 4 | ||||
| -rw-r--r-- | examples/core/core_input_mouse_wheel.png (renamed from examples/core/core_mouse_wheel.png) | bin | 15375 -> 15375 bytes | |||
| -rw-r--r-- | examples/core/core_input_multitouch.c | 4 | ||||
| -rw-r--r-- | examples/core/core_loading_thread.c | 88 | ||||
| -rw-r--r-- | examples/core/core_window_letterbox.c (renamed from examples/core/core_window_scale_letterbox.c) | 4 | ||||
| -rw-r--r-- | examples/core/core_window_letterbox.png (renamed from examples/core/core_window_scale_letterbox.png) | bin | 17967 -> 17967 bytes |
13 files changed, 67 insertions, 145 deletions
diff --git a/examples/core/core_3d_mode.c b/examples/core/core_3d_camera_mode.c index 39c0752a..a4962200 100644 --- a/examples/core/core_3d_mode.c +++ b/examples/core/core_3d_camera_mode.c @@ -1,6 +1,6 @@ /******************************************************************************************* * -* raylib [core] example - Initialize 3d mode +* raylib [core] example - Initialize 3d camera mode * * This example has been created using raylib 1.0 (www.raylib.com) * raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details) @@ -15,13 +15,13 @@ int main() { // Initialization //-------------------------------------------------------------------------------------- - int screenWidth = 800; - int screenHeight = 450; + const int screenWidth = 800; + const int screenHeight = 450; - InitWindow(screenWidth, screenHeight, "raylib [core] example - 3d mode"); + InitWindow(screenWidth, screenHeight, "raylib [core] example - 3d camera mode"); // Define the camera to look into our 3d world - Camera3D camera; + Camera3D camera = { 0 }; camera.position = (Vector3){ 0.0f, 10.0f, 10.0f }; // Camera position camera.target = (Vector3){ 0.0f, 0.0f, 0.0f }; // Camera looking at point camera.up = (Vector3){ 0.0f, 1.0f, 0.0f }; // Camera up vector (rotation towards target) diff --git a/examples/core/core_3d_mode.png b/examples/core/core_3d_camera_mode.png Binary files differindex de65daeb..de65daeb 100644 --- a/examples/core/core_3d_mode.png +++ b/examples/core/core_3d_camera_mode.png diff --git a/examples/core/core_color_select.c b/examples/core/core_color_select.c deleted file mode 100644 index 002a6931..00000000 --- a/examples/core/core_color_select.c +++ /dev/null @@ -1,94 +0,0 @@ -/******************************************************************************************* -* -* raylib [core] example - Color selection by mouse (collision detection) -* -* This example has been created using raylib 1.0 (www.raylib.com) -* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details) -* -* Copyright (c) 2014 Ramon Santamaria (@raysan5) -* -********************************************************************************************/ - -#include "raylib.h" - -int main() -{ - // Initialization - //-------------------------------------------------------------------------------------- - int screenWidth = 800; - int screenHeight = 450; - - InitWindow(screenWidth, screenHeight, "raylib [core] example - color selection (collision detection)"); - - Color colors[21] = { DARKGRAY, MAROON, ORANGE, DARKGREEN, DARKBLUE, DARKPURPLE, DARKBROWN, - GRAY, RED, GOLD, LIME, BLUE, VIOLET, BROWN, LIGHTGRAY, PINK, YELLOW, - GREEN, SKYBLUE, PURPLE, BEIGE }; - - Rectangle colorsRecs[21]; // Rectangles array - - // Fills colorsRecs data (for every rectangle) - for (int i = 0; i < 21; i++) - { - colorsRecs[i].x = 20 + 100*(i%7) + 10*(i%7); - colorsRecs[i].y = 60 + 100*(i/7) + 10*(i/7); - colorsRecs[i].width = 100; - colorsRecs[i].height = 100; - } - - bool selected[21] = { false }; // Selected rectangles indicator - - Vector2 mousePoint; - - SetTargetFPS(60); // Set our game to run at 60 frames-per-second - //-------------------------------------------------------------------------------------- - - // Main game loop - while (!WindowShouldClose()) // Detect window close button or ESC key - { - // Update - //---------------------------------------------------------------------------------- - mousePoint = GetMousePosition(); - - for (int i = 0; i < 21; i++) // Iterate along all the rectangles - { - if (CheckCollisionPointRec(mousePoint, colorsRecs[i])) - { - colors[i].a = 120; - - if (IsMouseButtonPressed(MOUSE_LEFT_BUTTON)) selected[i] = !selected[i]; - } - else colors[i].a = 255; - } - //---------------------------------------------------------------------------------- - - // Draw - //---------------------------------------------------------------------------------- - BeginDrawing(); - - ClearBackground(RAYWHITE); - - for (int i = 0; i < 21; i++) // Draw all rectangles - { - DrawRectangleRec(colorsRecs[i], colors[i]); - - // Draw four rectangles around selected rectangle - if (selected[i]) - { - DrawRectangle(colorsRecs[i].x, colorsRecs[i].y, 100, 10, RAYWHITE); // Square top rectangle - DrawRectangle(colorsRecs[i].x, colorsRecs[i].y, 10, 100, RAYWHITE); // Square left rectangle - DrawRectangle(colorsRecs[i].x + 90, colorsRecs[i].y, 10, 100, RAYWHITE); // Square right rectangle - DrawRectangle(colorsRecs[i].x, colorsRecs[i].y + 90, 100, 10, RAYWHITE); // Square bottom rectangle - } - } - - EndDrawing(); - //---------------------------------------------------------------------------------- - } - - // De-Initialization - //-------------------------------------------------------------------------------------- - CloseWindow(); // Close window and OpenGL context - //-------------------------------------------------------------------------------------- - - return 0; -}
\ No newline at end of file diff --git a/examples/core/core_color_select.png b/examples/core/core_color_select.png Binary files differdeleted file mode 100644 index 93ab83ae..00000000 --- a/examples/core/core_color_select.png +++ /dev/null diff --git a/examples/core/core_custom_logging.c b/examples/core/core_custom_logging.c index 4c4caf5d..cf1a601f 100644 --- a/examples/core/core_custom_logging.c +++ b/examples/core/core_custom_logging.c @@ -5,7 +5,9 @@ * This example has been created using raylib 2.1 (www.raylib.com) * raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details) * -* Copyright (c) 2018 Ramon Santamaria (@raysan5) and Pablo Marcos Oltra (@pamarcos) +* Example contributed by Pablo Marcos Oltra (@pamarcos) and reviewed by Ramon Santamaria (@raysan5) +* +* Copyright (c) 2018 Pablo Marcos Oltra (@pamarcos) and Ramon Santamaria (@raysan5) * ********************************************************************************************/ diff --git a/examples/core/core_gestures_detection.c b/examples/core/core_input_gestures.c index 63a1e6bd..ce2ed86c 100644 --- a/examples/core/core_gestures_detection.c +++ b/examples/core/core_input_gestures.c @@ -1,6 +1,6 @@ /******************************************************************************************* * -* raylib [core] example - Gestures Detection +* raylib [core] example - Input Gestures Detection * * This example has been created using raylib 1.4 (www.raylib.com) * raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details) @@ -21,7 +21,7 @@ int main() int screenWidth = 800; int screenHeight = 450; - InitWindow(screenWidth, screenHeight, "raylib [core] example - gestures detection"); + InitWindow(screenWidth, screenHeight, "raylib [core] example - input gestures"); Vector2 touchPosition = { 0, 0 }; Rectangle touchArea = { 220, 10, screenWidth - 230, screenHeight - 20 }; diff --git a/examples/core/core_gestures_detection.png b/examples/core/core_input_gestures.png Binary files differindex d2bbb5d7..d2bbb5d7 100644 --- a/examples/core/core_gestures_detection.png +++ b/examples/core/core_input_gestures.png diff --git a/examples/core/core_mouse_wheel.c b/examples/core/core_input_mouse_wheel.c index 6a5252ee..48cf7042 100644 --- a/examples/core/core_mouse_wheel.c +++ b/examples/core/core_input_mouse_wheel.c @@ -1,6 +1,6 @@ /******************************************************************************************* * -* raylib [core] examples - Mouse wheel +* raylib [core] examples - Mouse wheel input * * This test has been created using raylib 1.1 (www.raylib.com) * raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details) @@ -18,7 +18,7 @@ int main() int screenWidth = 800; int screenHeight = 450; - InitWindow(screenWidth, screenHeight, "raylib [core] example - mouse wheel"); + InitWindow(screenWidth, screenHeight, "raylib [core] example - input mouse wheel"); int boxPositionY = screenHeight/2 - 40; int scrollSpeed = 4; // Scrolling speed in pixels diff --git a/examples/core/core_mouse_wheel.png b/examples/core/core_input_mouse_wheel.png Binary files differindex 26a1f243..26a1f243 100644 --- a/examples/core/core_mouse_wheel.png +++ b/examples/core/core_input_mouse_wheel.png diff --git a/examples/core/core_input_multitouch.c b/examples/core/core_input_multitouch.c index ef8fa7ae..5baab271 100644 --- a/examples/core/core_input_multitouch.c +++ b/examples/core/core_input_multitouch.c @@ -5,7 +5,9 @@ * This example has been created using raylib 2.1 (www.raylib.com) * raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details) * -* Copyright (c) 2014-2019 Berni and Ramon Santamaria (@raysan5) +* Example contributed by Berni (@Berni8k) and reviewed by Ramon Santamaria (@raysan5) +* +* Copyright (c) 2019 Berni (@Berni8k) and Ramon Santamaria (@raysan5) * ********************************************************************************************/ diff --git a/examples/core/core_loading_thread.c b/examples/core/core_loading_thread.c index 4ffc9d0b..1dacd69f 100644 --- a/examples/core/core_loading_thread.c +++ b/examples/core/core_loading_thread.c @@ -15,10 +15,13 @@ #include "raylib.h" #include "pthread.h" // POSIX style threads management -#include <stdatomic.h> -#include <time.h> // Required for clock() function +#include <stdatomic.h> // C11 atomic data types +#include <time.h> // Required for: clock() + +// Using C11 atomics for synchronization +// NOTE: A plain bool (or any plain data type for that matter) can't be used for inter-thread synchronization static atomic_bool dataLoaded = ATOMIC_VAR_INIT(false); // Data Loaded completion indicator static void *LoadDataThread(void *arg); // Loading data thread function declaration @@ -48,33 +51,37 @@ int main() //---------------------------------------------------------------------------------- switch (state) { - case STATE_WAITING: - if (IsKeyPressed(KEY_ENTER)) + case STATE_WAITING: { - int error = pthread_create(&threadId, NULL, &LoadDataThread, NULL); - if (error != 0) TraceLog(LOG_ERROR, "Error creating loading thread"); - else TraceLog(LOG_INFO, "Loading thread initialized successfully"); - - state = STATE_LOADING; - } - break; - case STATE_LOADING: - framesCounter++; - if (atomic_load(&dataLoaded)) + if (IsKeyPressed(KEY_ENTER)) + { + int error = pthread_create(&threadId, NULL, &LoadDataThread, NULL); + if (error != 0) TraceLog(LOG_ERROR, "Error creating loading thread"); + else TraceLog(LOG_INFO, "Loading thread initialized successfully"); + + state = STATE_LOADING; + } + } break; + case STATE_LOADING: { - framesCounter = 0; - state = STATE_FINISHED; - } - break; - case STATE_FINISHED: - if (IsKeyPressed(KEY_ENTER)) + framesCounter++; + if (atomic_load(&dataLoaded)) + { + framesCounter = 0; + state = STATE_FINISHED; + } + } break; + case STATE_FINISHED: { - // Reset everything to launch again - atomic_store(&dataLoaded, false); - dataProgress = 0; - state = STATE_WAITING; - } - break; + if (IsKeyPressed(KEY_ENTER)) + { + // Reset everything to launch again + atomic_store(&dataLoaded, false); + dataProgress = 0; + state = STATE_WAITING; + } + } break; + default: break; } //---------------------------------------------------------------------------------- @@ -84,19 +91,22 @@ int main() ClearBackground(RAYWHITE); - switch(state) { - case STATE_WAITING: - DrawText("PRESS ENTER to START LOADING DATA", 150, 170, 20, DARKGRAY); - break; - case STATE_LOADING: - DrawRectangle(150, 200, dataProgress, 60, SKYBLUE); - if ((framesCounter/15)%2) - DrawText("LOADING DATA...", 240, 210, 40, DARKBLUE); - break; - case STATE_FINISHED: - DrawRectangle(150, 200, 500, 60, LIME); - DrawText("DATA LOADED!", 250, 210, 40, GREEN); - break; + switch (state) + { + case STATE_WAITING: DrawText("PRESS ENTER to START LOADING DATA", 150, 170, 20, DARKGRAY); break; + case STATE_LOADING: + { + DrawRectangle(150, 200, dataProgress, 60, SKYBLUE); + if ((framesCounter/15)%2) DrawText("LOADING DATA...", 240, 210, 40, DARKBLUE); + + } break; + case STATE_FINISHED: + { + DrawRectangle(150, 200, 500, 60, LIME); + DrawText("DATA LOADED!", 250, 210, 40, GREEN); + + } break; + default: break; } DrawRectangleLines(150, 200, 500, 60, DARKGRAY); diff --git a/examples/core/core_window_scale_letterbox.c b/examples/core/core_window_letterbox.c index ea4a375a..8c0843d2 100644 --- a/examples/core/core_window_scale_letterbox.c +++ b/examples/core/core_window_letterbox.c @@ -5,7 +5,9 @@ * This example has been created using raylib 2.5 (www.raylib.com) * raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details) * -* Copyright (c) 2019 Anata and Ramon Santamaria (@raysan5) +* Example contributed by Anata (@anatagawa) and reviewed by Ramon Santamaria (@raysan5) +* +* Copyright (c) 2019 Anata (@anatagawa) and Ramon Santamaria (@raysan5) * ********************************************************************************************/ diff --git a/examples/core/core_window_scale_letterbox.png b/examples/core/core_window_letterbox.png Binary files differindex 5acf2d7c..5acf2d7c 100644 --- a/examples/core/core_window_scale_letterbox.png +++ b/examples/core/core_window_letterbox.png |
