Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
B
Bandit_Manchot
Manage
Activity
Members
Plan
Wiki
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Analyze
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
benjamin.sitbon
Bandit_Manchot
Commits
25f95f13
Commit
25f95f13
authored
4 years ago
by
benjamin.sitbon
Browse files
Options
Downloads
Patches
Plain Diff
wheels spinning well
parent
cd501d38
No related branches found
No related tags found
No related merge requests found
Changes
6
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
display.c
+5
-4
5 additions, 4 deletions
display.c
game.c
+3
-3
3 additions, 3 deletions
game.c
game.h
+3
-1
3 additions, 1 deletion
game.h
one_armed_bandit.c
+4
-4
4 additions, 4 deletions
one_armed_bandit.c
wheel.c
+4
-3
4 additions, 3 deletions
wheel.c
wheel.h
+1
-1
1 addition, 1 deletion
wheel.h
with
20 additions
and
16 deletions
display.c
+
5
−
4
View file @
25f95f13
...
@@ -6,6 +6,7 @@
...
@@ -6,6 +6,7 @@
int
object_height
;
// global for convenience
int
object_height
;
// global for convenience
SDL_Window
*
init_display
(){
SDL_Window
*
init_display
(){
int
one_arm_width
,
one_arm_height
;
int
one_arm_width
,
one_arm_height
;
SDL_Window
*
window
;
SDL_Window
*
window
;
...
@@ -53,8 +54,8 @@ void display_wheel(int pixel,int offset){
...
@@ -53,8 +54,8 @@ void display_wheel(int pixel,int offset){
void
*
display_func
(
void
*
param
){
void
*
display_func
(
void
*
param
){
printf
(
"
\n
display_func"
);
SDL_Window
*
window
=
init_display
();
SDL_Window
*
window
=
init_display
();
printf
(
"
\n
display_func"
);
machine
*
mas
=
(
machine
*
)
(
param
);
machine
*
mas
=
(
machine
*
)
(
param
);
while
(
1
){
while
(
1
){
...
@@ -69,10 +70,10 @@ void *display_func(void *param){
...
@@ -69,10 +70,10 @@ void *display_func(void *param){
}
}
for
(
int
i
=
0
;
i
<
3
;
i
++
){
for
(
int
i
=
0
;
i
<
3
;
i
++
){
//
pthread_mutex_lock(&mas->wheels[i].lock);
pthread_mutex_lock
(
&
mas
->
wheels
[
i
].
lock
);
int
current_px
=
mas
->
wheels
[
i
].
current_px
;
int
current_px
=
mas
->
wheels
[
i
].
current_px
;
//
pthread_mutex_unlock(&mas->wheels[i].lock);
pthread_mutex_unlock
(
&
mas
->
wheels
[
i
].
lock
);
display_wheel
(
85
+
104
*
i
+
1
,
current_px
);
display_wheel
(
85
+
(
104
*
i
+
1
)
,
current_px
);
}
}
...
...
This diff is collapsed.
Click to expand it.
game.c
+
3
−
3
View file @
25f95f13
...
@@ -18,13 +18,13 @@ wheel create_wheel(int pixel,int speed){
...
@@ -18,13 +18,13 @@ wheel create_wheel(int pixel,int speed){
wheel
ret
;
wheel
ret
;
ret
.
current_px
=
pixel
;
ret
.
current_px
=
pixel
;
ret
.
speed
=
speed
;
ret
.
speed
=
speed
;
//
pthread_mutex_init(&ret.lock,NULL);
pthread_mutex_init
(
&
ret
.
lock
,
NULL
);
return
ret
;
return
ret
;
}
}
machine
new_machine
(
machine
mas
,
int
nb_wheels
){
void
new_machine
(
machine
*
mas
,
int
nb_wheels
){
for
(
int
i
=
0
;
i
<
nb_wheels
;
i
++
)
{
for
(
int
i
=
0
;
i
<
nb_wheels
;
i
++
)
{
mas
.
wheels
[
i
]
=
create_wheel
(
96
,
nb_wheels
-
i
);
mas
->
wheels
[
i
]
=
create_wheel
(
96
,
nb_wheels
-
i
);
}
}
}
}
This diff is collapsed.
Click to expand it.
game.h
+
3
−
1
View file @
25f95f13
...
@@ -7,6 +7,8 @@
...
@@ -7,6 +7,8 @@
#include
"wheel.h"
#include
"wheel.h"
#include
<stdlib.h>
#include
<stdlib.h>
#include
<SDL2/SDL.h>
#include
<SDL2/SDL_image.h>
typedef
struct
machine_a_sous
{
typedef
struct
machine_a_sous
{
...
@@ -19,6 +21,6 @@ int insert_coin();
...
@@ -19,6 +21,6 @@ int insert_coin();
int
set_wheel_speed
(
int
index
);
int
set_wheel_speed
(
int
index
);
int
next_wheel
();
int
next_wheel
();
wheel
create_wheel
(
int
pixel
,
int
speed
);
wheel
create_wheel
(
int
pixel
,
int
speed
);
machine
new_machine
(
machine
mas
,
int
nb_wheels
);
void
new_machine
(
machine
*
mas
,
int
nb_wheels
);
#endif
#endif
This diff is collapsed.
Click to expand it.
one_armed_bandit.c
+
4
−
4
View file @
25f95f13
...
@@ -23,13 +23,13 @@ int main()
...
@@ -23,13 +23,13 @@ int main()
pthread_t
threads
[
4
];
pthread_t
threads
[
4
];
machine
mas
;
machine
mas
;
mas
=
new_machine
(
mas
,
3
);
new_machine
(
&
mas
,
3
);
run_thread
(
&
threads
[
3
],
display_func
,
&
mas
);
for
(
int
i
=
0
;
i
<
3
;
i
++
){
for
(
int
i
=
0
;
i
<
3
;
i
++
){
run_thread
(
&
threads
[
i
],
wheel_func
,
&
mas
.
wheels
[
i
]);
run_thread
(
&
threads
[
i
],
wheel_func
,
&
mas
.
wheels
[
i
]);
}
}
run_thread
(
&
threads
[
3
],
display_func
,
&
mas
);
...
...
This diff is collapsed.
Click to expand it.
wheel.c
+
4
−
3
View file @
25f95f13
...
@@ -3,6 +3,7 @@
...
@@ -3,6 +3,7 @@
#include
"wheel.h"
#include
"wheel.h"
int
set_speed
(
int
s
){
int
set_speed
(
int
s
){
return
-
1
;
return
-
1
;
}
}
...
@@ -26,15 +27,15 @@ void *wheel_func(void *param){
...
@@ -26,15 +27,15 @@ void *wheel_func(void *param){
// wheel_spin(a,id.current_px,id.speed);
// wheel_spin(a,id.current_px,id.speed);
wheel_spin_1_tick
(
id
);
wheel_spin_1_tick
(
id
);
//
wait_until(wheel_delay_ms(*id));
wait_until
(
wheel_delay_ms
(
*
id
));
}
}
}
}
int
wheel_spin_1_tick
(
wheel
*
this
){
int
wheel_spin_1_tick
(
wheel
*
this
){
if
(
this
->
speed
)
{
if
(
this
->
speed
)
{
// mutex
pthread_mutex_lock
(
&
this
->
lock
);
this
->
current_px
=
(
this
->
current_px
+
2
)
%
896
;
this
->
current_px
=
(
this
->
current_px
+
2
)
%
896
;
// mutex
pthread_mutex_unlock
(
&
this
->
lock
);
}
}
}
}
...
...
This diff is collapsed.
Click to expand it.
wheel.h
+
1
−
1
View file @
25f95f13
...
@@ -6,7 +6,7 @@
...
@@ -6,7 +6,7 @@
typedef
struct
roue
{
typedef
struct
roue
{
int
speed
;
int
speed
;
int
current_px
;
int
current_px
;
//
pthread_mutex_t lock;
pthread_mutex_t
lock
;
}
wheel
;
}
wheel
;
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment