root / proj / src / proj.c @ 200
History | View | Annotate | Download (6.98 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 | 183 | up20180642 | |
27 | 144 | up20180655 | 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 | 189 | up20180655 | lcf_log_output("/home/lcom/labs/proj/output.txt");
|
34 | 144 | up20180655 | |
35 | if (lcf_start(argc, argv)) return 1; |
||
36 | |||
37 | lcf_cleanup(); |
||
38 | |||
39 | return 0; |
||
40 | } |
||
41 | 147 | up20180655 | |
42 | 149 | up20180655 | int(proj_main_loop)(int argc, char *argv[]) { |
43 | 170 | up20180642 | |
44 | int r;
|
||
45 | |||
46 | 192 | up20180642 | 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 | 170 | up20180642 | /// subscribe interrupts
|
50 | if (subscribe_all()) { return 1; } |
||
51 | |||
52 | /// initialize graphics
|
||
53 | 166 | up20180642 | 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 | 152 | up20180642 | return 1; |
57 | } |
||
58 | |||
59 | 188 | up20180642 | /// Load stuff
|
60 | 192 | up20180642 | 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 | 188 | up20180642 | { |
66 | graph_clear_screen(); |
||
67 | text_t *txt = text_ctor(consolas, "Loading...");
|
||
68 | text_draw(txt); |
||
69 | text_dtor(txt); |
||
70 | graph_draw(); |
||
71 | 192 | up20180642 | |
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 | 188 | up20180642 | } |
79 | 192 | up20180642 | |
80 | 159 | up20180642 | #ifdef DIOGO
|
81 | 188 | up20180642 | graph_clear_screen(); |
82 | 183 | up20180642 | |
83 | 188 | up20180642 | 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 | 179 | up20180642 | rectangle_set_outline_width(rect, 2);
|
89 | 188 | up20180642 | rectangle_set_outline_color(rect, WHITE); |
90 | 179 | up20180642 | rectangle_draw(rect); |
91 | |||
92 | 188 | up20180642 | text_t *txt = text_ctor(consolas, "Hello world!");
|
93 | text_set_color(txt, 0x888888);
|
||
94 | 182 | up20180642 | |
95 | 188 | up20180642 | 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 | 183 | up20180642 | text_draw(txt); |
100 | text_dtor(txt); |
||
101 | |||
102 | graph_draw(); |
||
103 | 188 | up20180642 | rectangle_dtor(rect); |
104 | 183 | up20180642 | |
105 | tickdelay(micros_to_ticks(1000000));
|
||
106 | |||
107 | 159 | up20180642 | #endif
|
108 | 152 | up20180642 | |
109 | 171 | up20180655 | #ifdef TELMO
|
110 | 192 | up20180642 | 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 | 174 | up20180642 | graph_clear_screen(); |
121 | 192 | up20180642 | ent_draw(shooter1); |
122 | sprite_draw(sp_crosshair); |
||
123 | 174 | up20180642 | graph_draw(); |
124 | 200 | up20180655 | |
125 | uint32_t refresh_count_value = sys_hz() / REFRESH_RATE; |
||
126 | 171 | up20180655 | #endif
|
127 | |||
128 | 149 | up20180655 | /// loop stuff
|
129 | 170 | up20180642 | int ipc_status;
|
130 | 149 | up20180655 | message msg; |
131 | 147 | up20180655 | int good = 1; |
132 | 168 | up20180642 | |
133 | 183 | up20180642 | #ifdef DIOGO
|
134 | good = 0;
|
||
135 | #endif
|
||
136 | |||
137 | 147 | up20180655 | 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 | 153 | up20180655 | for (uint32_t i = 0, n = 1; i < 32; i++, n <<= 1) { |
147 | if (msg.m_notify.interrupts & n) {
|
||
148 | interrupt_handler(i); |
||
149 | 167 | up20180655 | if ((scancode[0]) == ESC_BREAK_CODE) good = 0; |
150 | 171 | up20180655 | #ifdef TELMO
|
151 | 187 | up20180655 | if (i == 0) { |
152 | if (no_interrupts % refresh_count_value == 0) { |
||
153 | update_movement(shooter1); |
||
154 | 200 | up20180655 | update_scale(); |
155 | 192 | up20180642 | 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 | 187 | up20180655 | double angle = get_mouse_angle(shooter1);
|
160 | 192 | up20180642 | ent_set_angle(shooter1, angle - M_PI_2); |
161 | 187 | up20180655 | graph_clear_screen(); |
162 | 192 | up20180642 | ent_draw(shooter2); |
163 | ent_draw(shooter1); |
||
164 | sprite_draw(sp_crosshair); |
||
165 | 187 | up20180655 | graph_draw(); |
166 | } |
||
167 | 184 | up20180655 | } |
168 | 171 | up20180655 | #endif
|
169 | 153 | up20180655 | } |
170 | 147 | up20180655 | } |
171 | 187 | up20180655 | #ifdef TELMO
|
172 | if (counter_mouse_ih >= 3) { |
||
173 | struct packet pp = mouse_parse_packet(packet_mouse_ih);
|
||
174 | update_mouse_position(&pp); |
||
175 | 189 | up20180655 | //printf("X: %d Y: %d\n", get_mouse_X(), get_mouse_Y());
|
176 | 187 | up20180655 | counter_mouse_ih = 0;
|
177 | } |
||
178 | #endif
|
||
179 | 167 | up20180655 | |
180 | 147 | up20180655 | 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 | 149 | up20180655 | |
189 | 192 | up20180642 | #ifdef TELMO
|
190 | ent_dtor(shooter1); shooter1 = NULL;
|
||
191 | #endif
|
||
192 | 188 | up20180642 | |
193 | 192 | up20180642 | 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 | 153 | up20180655 | // Unsubscribe interrupts
|
199 | 155 | up20180655 | if (unsubscribe_all()) {
|
200 | if (cleanup())
|
||
201 | printf("%s: failed to cleanup.\n", __func__);
|
||
202 | 152 | up20180642 | return 1; |
203 | } |
||
204 | |||
205 | 155 | up20180655 | |
206 | if (cleanup()) {
|
||
207 | printf("%s: failed to cleanup.\n", __func__);
|
||
208 | 152 | up20180642 | return 1; |
209 | } |
||
210 | |||
211 | 149 | up20180655 | return 0; |
212 | 147 | up20180655 | } |