-
Notifications
You must be signed in to change notification settings - Fork 33
/
fix_main.patch
80 lines (76 loc) · 1.83 KB
/
fix_main.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
diff --git a/src/linux/main.cpp b/../torcs/src/linux/main.cpp
index 982a480..bd662f9 100644
--- a/src/linux/main.cpp
+++ b/../torcs/src/linux/main.cpp
@@ -27,6 +27,12 @@
#include "linuxspec.h"
#include <raceinit.h>
+#include <sys/shm.h>
+#define image_width 640
+#define image_height 480
+#include <iostream>
+#include <unistd.h>
+
extern bool bKeepModules;
static void
@@ -104,6 +110,23 @@ init_args(int argc, char **argv, const char **raceconfig)
#endif
}
+struct shared_use_st
+{
+ int written;
+ uint8_t data[image_width*image_height*3];
+ int pause;
+ int zmq_flag;
+ int save_flag;
+};
+
+int* pwritten = NULL;
+uint8_t* pdata = NULL;
+int* ppause = NULL;
+int* pzmq_flag = NULL;
+int* psave_flag = NULL;
+
+void *shm = NULL;
+
/*
* Function
* main
@@ -123,6 +146,38 @@ init_args(int argc, char **argv, const char **raceconfig)
int
main(int argc, char *argv[])
{
+
+ struct shared_use_st *shared = NULL;
+ int shmid;
+ // establish memory sharing
+ shmid = shmget((key_t)1234, sizeof(struct shared_use_st), 0666|IPC_CREAT);
+ if(shmid == -1)
+ {
+ fprintf(stderr, "shmget failed\n");
+ exit(EXIT_FAILURE);
+ }
+
+ shm = shmat(shmid, 0, 0);
+ if(shm == (void*)-1)
+ {
+ fprintf(stderr, "shmat failed\n");
+ exit(EXIT_FAILURE);
+ }
+ printf("\n********** Memory sharing started, attached at %X **********\n \n", shm);
+ // set up shared memory
+ shared = (struct shared_use_st*)shm;
+ shared->written = 0;
+ shared->pause = 0;
+ shared->zmq_flag = 0;
+ shared->save_flag = 0;
+
+
+ pwritten=&shared->written;
+ pdata=shared->data;
+ ppause=&shared->pause;
+ pzmq_flag = &shared->zmq_flag;
+ psave_flag = &shared->save_flag;
+
const char *raceconfig = "";
init_args(argc, argv, &raceconfig);