-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgame.cpp
More file actions
154 lines (132 loc) · 3 KB
/
Copy pathgame.cpp
File metadata and controls
154 lines (132 loc) · 3 KB
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
#include "stdlib.h"
#include "stdio.h"
#include "string.h"
#include "assert.h"
#include "stdlib.h"
#include "stdio.h"
#include "string.h"
#include "assert.h"
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <termios.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <time.h>
#include "SDL.h"
#include "SDL_mixer.h"
#ifdef _CH_
#pragma package <opencv>
#endif
#ifndef _EiC
#include "opencv/cv.h"
#include "opencv/highgui.h"
#endif
#include <stdlib.h>
#include <stdio.h>
#include "HanukkaDisplay.h"
#include "SetupDisplay.h"
#include "MegaTreeDisplay.h"
#include "XmesGameDisplay.h"
#include "RandomDisplay.h"
#include "NewYearDisplay.h"
int main(int argc, char *argv[])
{
char* ttydev = NULL;
char* filename = NULL;
int mode = 0;
int interfaceFD = open("/tmp/interface", O_RDONLY | O_NDELAY | O_NONBLOCK);
printf("Fd %i\n", interfaceFD);
if (argc > 2)
{
mode = atoi(argv[1]);
ttydev = argv[2];
if (argc > 3)
filename = argv[3];
} else {
printf("Usage: %s mode [0=test, 1=hanukka display, 2=xmes game, 3=random display 4=newYear Display] ttyDev houseImage.jpg\n", argv[0]);
exit(1);
}
MegaTree megaTree(cvPoint(555,355), cvPoint(0,295), 12);
megaTree.setupSerial(ttydev);
IplImage *image = NULL;
if (filename)
image = cvLoadImage( filename, 1);
if (image)
{
cvNamedWindow("Test", 1);
cvMoveWindow("Test", 0, 0);
}
Display* display = NULL;
switch (mode)
{
case 0:
if (argc > 6)
display = new SetupDisplay(megaTree, atoi(argv[4]), atoi(argv[5]), atoi(argv[6]), atoi(argv[7]));
else
{
printf("Usage: %s mode [0=test] ttyDev houseImage.jpg stringId red green blue\n", argv[0]);
exit(1);
}
break;
case 1:
display = new HanukkaDisplay(megaTree, 8);
break;
case 2:
display = new XmesGameDisplay(megaTree);
break;
case 3:
display = new RandomDisplay(megaTree);
break;
case 4:
display = new NewYearDisplay(megaTree);
break;
}
// start and end times
time_t start, end;
int frameCounter = 0;
bool fireHeart = 0;
time(&start);
while(1)
{
IplImage *tmpImg = NULL;
if (image)
{
tmpImg = cvCreateImage( cvSize(image->width, image->height), image->depth, image->nChannels);
cvCopy(image, tmpImg, NULL);
}
//Draw the objects
megaTree.draw(tmpImg);
int key = -1;
if (image)
{
cvShowImage("Test", tmpImg);
key = cvWaitKey(10);
cvReleaseImage(&tmpImg);
}
if (interfaceFD != -1)
{
char cmd;
int n = read(interfaceFD, &cmd, 1);
if (n > 0)
key = cmd;
}
if (key != -1)
printf("In Key %i\n", key);
if (display)
display->process(key);
time(&end);
frameCounter++;
double sec = difftime(end, start);
double fps = frameCounter/sec;
//printf("FPS=%0.2f\n", fps);
}
if (image)
{
cvReleaseImage(&image);
cvDestroyWindow("Test");
}
return 0;
}