@@ -19,8 +19,12 @@ Font font;
19
19
Algorithm * algorithms = NULL ;
20
20
Process * processes = NULL ;
21
21
AlgoResult algoResult ;
22
-
23
- int started = 0 ;
22
+ InstantResultNode currNode ;
23
+ int numberOfAlgo = 0 ;
24
+ int started = 0 ;
25
+ int currFrame = 0 ;
26
+ Rectangle * ganttRectangles = NULL ;
27
+ int ganttRectanglesSize = 0 ;
24
28
25
29
void render_job_pool (Rectangle boundry ){
26
30
DrawRectangleRounded (boundry ,borderRadius ,20 ,containerColor );
@@ -29,25 +33,55 @@ void render_job_pool(Rectangle boundry){
29
33
void render_gantt (Rectangle boundry ){
30
34
DrawRectangleRounded (boundry ,borderRadius ,20 ,containerColor );
31
35
DrawTextEx (font ,"Gantt" ,(Vector2 ){boundry .x + textPadding , boundry .y + textPadding },textSize ,0 ,RED );
36
+ if (started && currFrame %60 == 0 ){
37
+ currNode = dequeue_gantt (algoResult .gantt );
38
+ ganttRectanglesSize ++ ;
39
+ ganttRectangles [ganttRectanglesSize - 1 ]= (Rectangle ){
40
+ .x = boundry .x + 100 + 60 * (ganttRectanglesSize - 1 ),
41
+ .y = boundry .y + 50 ,
42
+ .width = 50 ,
43
+ .height = 100 ,
44
+ };
45
+ if (is_empty_gantt (algoResult .gantt )){
46
+ started = 0 ;
47
+ }
48
+ }
49
+ for (int i = 0 ;i < ganttRectanglesSize ;i ++ ){
50
+ DrawRectangleRounded (ganttRectangles [i ],0.1 ,20 ,RED );
51
+ }
52
+
32
53
}
33
54
void render_stats (Rectangle boundry ){
34
55
DrawRectangleRounded (boundry ,borderRadius ,20 ,containerColor );
35
56
DrawTextEx (font ,"Stats" ,(Vector2 ){boundry .x + textPadding , boundry .y + textPadding },textSize ,0 ,RED );
57
+ DrawTextEx (font ,currNode .readyQueueSize != 0 ?currNode .readyQueue [0 ]:"" ,(Vector2 ){boundry .x + boundry .width /2 ,boundry .y + boundry .height /2 },textSize ,0 ,RED );
36
58
}
37
59
void render_menu (Rectangle boundry ){
38
60
DrawRectangleRounded (boundry ,borderRadius ,20 ,containerColor );
39
61
DrawTextEx (font ,"Menu" ,(Vector2 ){boundry .x + textPadding , boundry .y + textPadding },textSize ,0 ,RED );
40
- }
41
- void show_gantt_stats (Rectangle ganttBoundry ,Rectangle statsBoundry ){
42
- render_gantt (ganttBoundry );
43
- render_stats (statsBoundry );
44
- // sleep(1);
62
+ int isStartButtonPressed = GuiButton ((Rectangle ){boundry .x + (boundry .width )/2 ,boundry .y + (boundry .height )/2 ,100 ,100 },"Start" );
63
+ if (isStartButtonPressed && !started ){
64
+ Process processes [] = {
65
+ {"Process1" , 0 , 5 , 3 },
66
+ {"Process2" , 1 , 3 , 2 },
67
+ {"Process3" , 2 , 1 , 4 },
68
+ {"Process4" , 4 , 2 , 1 },
69
+ };
70
+ int processes_number = 4 ;
71
+ Queue * q = create_queue_from_array (processes ,processes_number );
72
+ printf ("%s\n" ,algorithms [1 ].name );
73
+ algoResult = algorithms [1 ].run (q ,processes_number ,1 );
74
+ started = 1 ;
75
+ int queueSize = size_gantt (algoResult .gantt );
76
+ printf ("%d\n" ,queueSize );
77
+ ganttRectangles = (Rectangle * ) malloc (queueSize * sizeof (Rectangle ));
78
+ }
45
79
}
46
80
void preview_screen (void ){
47
81
int w = GetRenderWidth ();
48
82
int h = GetRenderHeight ();
49
- BeginDrawing ();
50
83
ClearBackground (backgroundColor );
84
+ BeginDrawing ();
51
85
Rectangle jobPoolRect = {
52
86
.x = 0 + padding ,
53
87
.y = 0 + padding ,
@@ -68,28 +102,32 @@ void preview_screen(void){
68
102
.width = (w - 2 * padding - 2 * gap )/3 ,
69
103
.height = 2 * (h - gap )/3 ,
70
104
};
105
+ render_stats (statsRect );
71
106
Rectangle ganttRect = {
72
107
.x = padding ,
73
108
.y = 2 * h /3 + gap ,
74
109
.width = w - 2 * padding ,
75
110
.height = (h - gap )/3 - padding ,
76
111
};
77
- show_gantt_stats (ganttRect , statsRect );
112
+ render_gantt (ganttRect );
78
113
EndDrawing ();
79
114
80
115
}
81
116
int main (void ){
82
117
const int screenWidth = 900 ;
83
118
const int screenHeight = 500 ;
84
-
119
+ SetTraceLogLevel ( LOG_NONE );
85
120
InitWindow (screenWidth , screenHeight , "Multitasking Scheduling Algorithm Simulation System" );
86
121
font = LoadFont ("../assets/fonts/DelaGothicOne-Regular.ttf" );
87
-
88
122
SetTargetFPS (60 );
89
-
123
+
124
+ numberOfAlgo = get_nb_algorithms ("../build/algorithms" );
125
+ algorithms = load_all_algorithms ("../build/algorithms" );
90
126
while (!WindowShouldClose ()){
127
+ // printf("%d\n",started);
91
128
preview_screen ();
92
- printf ("%d\n" ,GetFPS ());
129
+ currFrame ++ ;
130
+ currFrame %=60 ;
93
131
}
94
132
CloseWindow ();
95
133
return 0 ;
0 commit comments