-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathPushdown.c
More file actions
83 lines (67 loc) · 1.42 KB
/
Pushdown.c
File metadata and controls
83 lines (67 loc) · 1.42 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
#include <string.h>
#include <stdlib.h>
#include <SDL/SDL.h>
#include "Pushdown.h"
#include "Entity.h" //When time singleton is in a better module, include that instead
#include "Keyboard.h"
PushMessage messageQueue[5];
int queueRear = -1; //-1 means the queue is empty
/* For now, this Pushdown.h implementation uses a stupid non-circuar queue that copies everything forward.
* I hope to rewrite it later, but if I haven't I'm not too worried. Whimsy Block Go is too small of a game
* for the performance to matter and it's hidden nicely by a good interface. I get brownie points for the
* latter, right?
*/
void updatePushMessages()
{
int i;
if (queueRear < 0)
{
return;
}
if (getTimeSingleton() - messageQueue[0].startTime > 2500)
{
for (i = 0; i < queueRear; i++)
{
messageQueue[i] = messageQueue[i+1];
}
queueRear--;
if (queueRear > -1)
{
messageQueue[0].startTime = getTimeSingleton();
}
}
}
int pushNewMessage(char* text)
{
if (text == NULL)
{
return 2;
}
if (queueRear > 3)
{
return 1;
}
queueRear++;
if (strlen(text) > 31)
{
strncpy(messageQueue[queueRear].message, text, 31);
(messageQueue[queueRear].message)[31] = '\0';
}
else
{
strcpy(messageQueue[queueRear].message, text);
}
messageQueue[queueRear].startTime = getTimeSingleton();
return 0;
}
PushMessage* getCurrentMessage()
{
if (queueRear < 0)
{
return NULL;
}
else
{
return messageQueue;
}
}