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