MCPcopy Create free account
hub / github.com/RobLoach/raylib-cpp / main

Function main

examples/core/core_loading_thread.cpp:27–127  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

25static int dataProgress = 0; // Data progress accumulator
26
27int main(void)
28{
29 // Initialization
30 //--------------------------------------------------------------------------
31 const int screenWidth = 800;
32 const int screenHeight = 450;
33
34 raylib::Window window(screenWidth, screenHeight,
35 "raylib [core] example - loading thread");
36
37 std::thread threadId; // Loading data thread id
38
39 enum { STATE_WAITING, STATE_LOADING, STATE_FINISHED } state = STATE_WAITING;
40 int framesCounter = 0;
41
42 SetTargetFPS(60); // Set our game to run at 60 frames-per-second
43 //--------------------------------------------------------------------------
44
45 // Main game loop
46 while (!window.ShouldClose()) { // Detect window close button or ESC key
47 // Update
48 //----------------------------------------------------------------------
49 switch (state)
50 {
51 case STATE_WAITING:
52 if (IsKeyPressed(KEY_ENTER))
53 {
54 try {
55 threadId = std::thread(LoadDataThread);
56 TraceLog(LOG_INFO,
57 "Loading thread initialized successfully");
58 } catch (std::system_error& e) {
59 TraceLog(LOG_ERROR, "Error: %s", e.what());
60 }
61
62 state = STATE_LOADING;
63 }
64 break;
65
66 case STATE_LOADING:
67 framesCounter++;
68 if (dataLoaded.load())
69 {
70 framesCounter = 0;
71 state = STATE_FINISHED;
72 }
73 break;
74
75 case STATE_FINISHED:
76 if (IsKeyPressed(KEY_ENTER))
77 {
78 // Reset everything to launch again
79 dataLoaded = false;
80 dataProgress = 0;
81 state = STATE_WAITING;
82 }
83 break;
84

Callers

nothing calls this directly

Calls 5

IsKeyPressedFunction · 0.85
ShouldCloseMethod · 0.80
DrawTextFunction · 0.50
DrawRectangleFunction · 0.50
DrawRectangleLinesFunction · 0.50

Tested by

no test coverage detected