Skip to content

Commit 7740933

Browse files
committed
adding interface layout
1 parent 1c3dddd commit 7740933

File tree

3 files changed

+68
-17
lines changed

3 files changed

+68
-17
lines changed

.vscode/settings.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,12 @@
1212
"readyqueueelements.h": "c",
1313
"dynamic_menu.h": "c",
1414
"raygui.h": "c",
15-
"zraygui.h": "c"
15+
"zraygui.h": "c",
16+
"initializer_list": "c",
17+
"type_traits": "c",
18+
"vector": "c",
19+
"xstring": "c",
20+
"xutility": "c"
1621
},
1722
"C_Cpp.errorSquiggles": "disabled"
1823
}

src/includes/utils/algo_result.h

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ void enqueue_gantt(Gantt* ganttQueue,int t,char* processName,int quit,char** rea
1919
InstantResultNode dequeue_gantt(Gantt* ganttQueue);
2020
InstantResultNode* create_instant_result_node(int t,char* processName,int quit,char** readyQueue,int readyQueueSize);
2121
void add_metrics(AlgoResult* algoResult,float averageRotation,float averageWaiting);
22-
22+
int size_gantt(Gantt* ganttQueue);
2323

2424
Gantt* create_gantt(){
2525
Gantt* gantt = (Gantt*)malloc(sizeof(Gantt));
@@ -55,7 +55,7 @@ InstantResultNode* create_instant_result_node(int t,char* processName,int quit,c
5555

5656
void enqueue_gantt(Gantt* ganttQueue, int t,char* processName,int quit,char** readyQueue,int readyQueueSize){
5757
InstantResultNode* newInstantResultNode = create_instant_result_node(t,processName,quit,readyQueue,readyQueueSize);
58-
execution_log(*newInstantResultNode);
58+
// execution_log(*newInstantResultNode);
5959
if(is_empty_gantt(ganttQueue)){
6060
ganttQueue->front = newInstantResultNode;
6161
ganttQueue->rear = newInstantResultNode;
@@ -82,7 +82,15 @@ void add_metrics(AlgoResult* algoResult,float averageRotation,float averageWaiti
8282
algoResult->metrics.averageWaiting = averageWaiting;
8383
}
8484

85-
85+
int size_gantt(Gantt* ganttQueue){
86+
InstantResultNode* current_node = ganttQueue->front;
87+
int size=0;
88+
while(current_node != NULL){
89+
size++;
90+
current_node = current_node->next;
91+
}
92+
return size;
93+
}
8694

8795
// example :
8896
// #include<stdio.h>

src/main2.c

Lines changed: 51 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,12 @@ Font font;
1919
Algorithm* algorithms = NULL;
2020
Process* processes = NULL;
2121
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;
2428

2529
void render_job_pool(Rectangle boundry){
2630
DrawRectangleRounded(boundry,borderRadius,20,containerColor);
@@ -29,25 +33,55 @@ void render_job_pool(Rectangle boundry){
2933
void render_gantt(Rectangle boundry){
3034
DrawRectangleRounded(boundry,borderRadius,20,containerColor);
3135
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+
3253
}
3354
void render_stats(Rectangle boundry){
3455
DrawRectangleRounded(boundry,borderRadius,20,containerColor);
3556
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);
3658
}
3759
void render_menu(Rectangle boundry){
3860
DrawRectangleRounded(boundry,borderRadius,20,containerColor);
3961
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+
}
4579
}
4680
void preview_screen(void){
4781
int w = GetRenderWidth();
4882
int h = GetRenderHeight();
49-
BeginDrawing();
5083
ClearBackground(backgroundColor);
84+
BeginDrawing();
5185
Rectangle jobPoolRect = {
5286
.x = 0+padding,
5387
.y = 0+padding,
@@ -68,28 +102,32 @@ void preview_screen(void){
68102
.width = (w-2*padding-2*gap)/3,
69103
.height = 2*(h-gap)/3,
70104
};
105+
render_stats(statsRect);
71106
Rectangle ganttRect = {
72107
.x = padding,
73108
.y = 2*h/3 + gap,
74109
.width = w-2*padding,
75110
.height = (h-gap)/3 - padding,
76111
};
77-
show_gantt_stats(ganttRect,statsRect);
112+
render_gantt(ganttRect);
78113
EndDrawing();
79114

80115
}
81116
int main(void){
82117
const int screenWidth = 900;
83118
const int screenHeight = 500;
84-
119+
SetTraceLogLevel(LOG_NONE);
85120
InitWindow(screenWidth, screenHeight, "Multitasking Scheduling Algorithm Simulation System");
86121
font = LoadFont("../assets/fonts/DelaGothicOne-Regular.ttf");
87-
88122
SetTargetFPS(60);
89-
123+
124+
numberOfAlgo = get_nb_algorithms("../build/algorithms");
125+
algorithms = load_all_algorithms("../build/algorithms");
90126
while (!WindowShouldClose()){
127+
// printf("%d\n",started);
91128
preview_screen();
92-
printf("%d\n",GetFPS());
129+
currFrame++;
130+
currFrame%=60;
93131
}
94132
CloseWindow();
95133
return 0;

0 commit comments

Comments
 (0)