root / proj / src / proj.c @ 200
History | View | Annotate | Download (6.98 KB)
1 |
#include <lcom/lcf.h> |
---|---|
2 |
#include <lcom/proj.h> |
3 |
#include <lcom/liblm.h> |
4 |
#include <math.h> |
5 |
|
6 |
#include "proj_macros.h" |
7 |
#include "proj_func.h" |
8 |
|
9 |
#include "kbc.h" |
10 |
#include "timer.h" |
11 |
#include "keyboard.h" |
12 |
#include "mouse.h" |
13 |
#include "graph.h" |
14 |
#include "interrupts_func.h" |
15 |
|
16 |
#include "graph.h" |
17 |
#include "sprite.h" |
18 |
#include "rectangle.h" |
19 |
#include "font.h" |
20 |
#include "ent.h" |
21 |
|
22 |
#include "crosshair.h" |
23 |
#include "shooter.h" |
24 |
#include "pistol.h" |
25 |
#include "nothing.h" |
26 |
|
27 |
int main(int argc, char* argv[]) { |
28 |
|
29 |
lcf_set_language("EN-US");
|
30 |
|
31 |
//lcf_trace_calls("/home/lcom/labs/proj/trace.txt");
|
32 |
|
33 |
lcf_log_output("/home/lcom/labs/proj/output.txt");
|
34 |
|
35 |
if (lcf_start(argc, argv)) return 1; |
36 |
|
37 |
lcf_cleanup(); |
38 |
|
39 |
return 0; |
40 |
} |
41 |
|
42 |
int(proj_main_loop)(int argc, char *argv[]) { |
43 |
|
44 |
int r;
|
45 |
|
46 |
font_t *consolas = font_ctor("/home/lcom/labs/proj/font/Consolas/xpm2");
|
47 |
if(consolas == NULL){ printf("Failed to load consolas\n"); return 1; } |
48 |
|
49 |
/// subscribe interrupts
|
50 |
if (subscribe_all()) { return 1; } |
51 |
|
52 |
/// initialize graphics
|
53 |
if(graph_init(GRAPH_MODE)){
|
54 |
printf("%s: failed to initalize graphics.\n", __func__);
|
55 |
if (cleanup()) printf("%s: failed to cleanup.\n", __func__); |
56 |
return 1; |
57 |
} |
58 |
|
59 |
/// Load stuff
|
60 |
basic_sprite_t *bsp_crosshair = NULL;
|
61 |
basic_sprite_t *bsp_shooter = NULL;
|
62 |
basic_sprite_t *bsp_pistol = NULL;
|
63 |
basic_sprite_t *bsp_nothing = NULL;
|
64 |
sprite_t *sp_crosshair = NULL;
|
65 |
{ |
66 |
graph_clear_screen(); |
67 |
text_t *txt = text_ctor(consolas, "Loading...");
|
68 |
text_draw(txt); |
69 |
text_dtor(txt); |
70 |
graph_draw(); |
71 |
|
72 |
bsp_crosshair = get_crosshair(); if(bsp_crosshair == NULL) printf("Failed to get crosshair\n"); |
73 |
bsp_shooter = get_shooter (); if(bsp_shooter == NULL) printf("Failed to get shooter\n"); |
74 |
bsp_pistol = get_pistol (); if(bsp_pistol == NULL) printf("Failed to get pistol\n"); |
75 |
bsp_nothing = get_nothing (); if(bsp_nothing == NULL) printf("Failed to get nothing\n"); |
76 |
|
77 |
sp_crosshair = sprite_ctor(bsp_crosshair); if(sp_crosshair == NULL) printf("Failed to get crosshair sprite\n"); |
78 |
} |
79 |
|
80 |
#ifdef DIOGO
|
81 |
graph_clear_screen(); |
82 |
|
83 |
rectangle_t *rect = rectangle_ctor(0,0,400,100); |
84 |
rectangle_set_pos(rect, |
85 |
graph_get_XRes()/2 - rectangle_get_w(rect)/2, |
86 |
graph_get_YRes()*0.25 - rectangle_get_h(rect)/2); |
87 |
rectangle_set_fill_color(rect, BLACK); |
88 |
rectangle_set_outline_width(rect, 2);
|
89 |
rectangle_set_outline_color(rect, WHITE); |
90 |
rectangle_draw(rect); |
91 |
|
92 |
text_t *txt = text_ctor(consolas, "Hello world!");
|
93 |
text_set_color(txt, 0x888888);
|
94 |
|
95 |
text_set_pos(txt, rectangle_get_x(rect)+rectangle_get_w(rect)/2,
|
96 |
rectangle_get_y(rect)+rectangle_get_h(rect)/2);
|
97 |
text_set_valign(txt, text_valign_center); |
98 |
text_set_halign(txt, text_halign_center); |
99 |
text_draw(txt); |
100 |
text_dtor(txt); |
101 |
|
102 |
graph_draw(); |
103 |
rectangle_dtor(rect); |
104 |
|
105 |
tickdelay(micros_to_ticks(1000000));
|
106 |
|
107 |
#endif
|
108 |
|
109 |
#ifdef TELMO
|
110 |
ent_set_scale(2.0); |
111 |
|
112 |
ent_t *shooter1 = ent_ctor(bsp_shooter, bsp_pistol); if(shooter1 == NULL) printf("Failed to get shooter1\n"); |
113 |
ent_set_pos(shooter1, 0, 0); |
114 |
ent_set_origin(ent_get_x(shooter1)-ent_get_XLength()/2.0, |
115 |
ent_get_y(shooter1)-ent_get_YLength()/2.0); |
116 |
|
117 |
ent_t *shooter2 = ent_ctor(bsp_shooter, bsp_nothing); |
118 |
ent_set_pos(shooter2, -50, -50); |
119 |
|
120 |
graph_clear_screen(); |
121 |
ent_draw(shooter1); |
122 |
sprite_draw(sp_crosshair); |
123 |
graph_draw(); |
124 |
|
125 |
uint32_t refresh_count_value = sys_hz() / REFRESH_RATE; |
126 |
#endif
|
127 |
|
128 |
/// loop stuff
|
129 |
int ipc_status;
|
130 |
message msg; |
131 |
int good = 1; |
132 |
|
133 |
#ifdef DIOGO
|
134 |
good = 0;
|
135 |
#endif
|
136 |
|
137 |
while (good) {
|
138 |
/* Get a request message. */
|
139 |
if ((r = driver_receive(ANY, &msg, &ipc_status)) != 0) { |
140 |
printf("driver_receive failed with %d", r);
|
141 |
continue;
|
142 |
} |
143 |
if (is_ipc_notify(ipc_status)) { /* received notification */ |
144 |
switch (_ENDPOINT_P(msg.m_source)) {
|
145 |
case HARDWARE: /* hardware interrupt notification */ |
146 |
for (uint32_t i = 0, n = 1; i < 32; i++, n <<= 1) { |
147 |
if (msg.m_notify.interrupts & n) {
|
148 |
interrupt_handler(i); |
149 |
if ((scancode[0]) == ESC_BREAK_CODE) good = 0; |
150 |
#ifdef TELMO
|
151 |
if (i == 0) { |
152 |
if (no_interrupts % refresh_count_value == 0) { |
153 |
update_movement(shooter1); |
154 |
update_scale(); |
155 |
ent_set_origin(ent_get_x(shooter1)-ent_get_XLength()/2.0, |
156 |
ent_get_y(shooter1)-ent_get_YLength()/2.0); |
157 |
|
158 |
sprite_set_pos(sp_crosshair, get_mouse_X(), get_mouse_Y()); |
159 |
double angle = get_mouse_angle(shooter1);
|
160 |
ent_set_angle(shooter1, angle - M_PI_2); |
161 |
graph_clear_screen(); |
162 |
ent_draw(shooter2); |
163 |
ent_draw(shooter1); |
164 |
sprite_draw(sp_crosshair); |
165 |
graph_draw(); |
166 |
} |
167 |
} |
168 |
#endif
|
169 |
} |
170 |
} |
171 |
#ifdef TELMO
|
172 |
if (counter_mouse_ih >= 3) { |
173 |
struct packet pp = mouse_parse_packet(packet_mouse_ih);
|
174 |
update_mouse_position(&pp); |
175 |
//printf("X: %d Y: %d\n", get_mouse_X(), get_mouse_Y());
|
176 |
counter_mouse_ih = 0;
|
177 |
} |
178 |
#endif
|
179 |
|
180 |
break;
|
181 |
default:
|
182 |
break; /* no other notifications expected: do nothing */ |
183 |
} |
184 |
} else { /* received standart message, not a notification */ |
185 |
/* no standart message expected: do nothing */
|
186 |
} |
187 |
} |
188 |
|
189 |
#ifdef TELMO
|
190 |
ent_dtor(shooter1); shooter1 = NULL;
|
191 |
#endif
|
192 |
|
193 |
basic_sprite_dtor(bsp_crosshair); bsp_crosshair = NULL;
|
194 |
basic_sprite_dtor(bsp_shooter ); bsp_shooter = NULL;
|
195 |
sprite_dtor (sp_crosshair ); sp_crosshair = NULL;
|
196 |
font_dtor (consolas ); consolas = NULL;
|
197 |
|
198 |
// Unsubscribe interrupts
|
199 |
if (unsubscribe_all()) {
|
200 |
if (cleanup())
|
201 |
printf("%s: failed to cleanup.\n", __func__);
|
202 |
return 1; |
203 |
} |
204 |
|
205 |
|
206 |
if (cleanup()) {
|
207 |
printf("%s: failed to cleanup.\n", __func__);
|
208 |
return 1; |
209 |
} |
210 |
|
211 |
return 0; |
212 |
} |