Skip to content

Commit a7c5e83

Browse files
committed
more refactoring
1 parent 6cdd7b7 commit a7c5e83

12 files changed

+1144
-959
lines changed

.ccls

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
-fPIE
2+
-lm
3+
-lSDL2

src/game-data.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ char **game_data_prayer_description;
9292

9393
int game_data_roof_count;
9494
int *game_data_roof_height;
95-
int *game_data_roof_num_vertices;
95+
int *game_data_roof_fills;
9696

9797
int game_data_model_count;
9898
int game_data_projectile_sprite;
@@ -534,14 +534,14 @@ void game_data_load_data(int8_t *buffer, int is_members) {
534534

535535
game_data_roof_count = game_data_get_unsigned_short();
536536
game_data_roof_height = malloc(game_data_roof_count * sizeof(int));
537-
game_data_roof_num_vertices = malloc(game_data_roof_count * sizeof(int));
537+
game_data_roof_fills = malloc(game_data_roof_count * sizeof(int));
538538

539539
for (i = 0; i < game_data_roof_count; i++) {
540540
game_data_roof_height[i] = game_data_get_unsigned_byte();
541541
}
542542

543543
for (i = 0; i < game_data_roof_count; i++) {
544-
game_data_roof_num_vertices[i] = game_data_get_unsigned_byte();
544+
game_data_roof_fills[i] = game_data_get_unsigned_byte();
545545
}
546546

547547
game_data_tile_count = game_data_get_unsigned_short();

src/game-data.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ extern char **game_data_prayer_description;
101101

102102
extern int game_data_roof_count;
103103
extern int *game_data_roof_height;
104-
extern int *game_data_roof_num_vertices;
104+
extern int *game_data_roof_fills;
105105

106106
extern int game_data_model_count;
107107
extern int game_data_projectile_sprite;

src/game-model.c

+5-5
Original file line numberDiff line numberDiff line change
@@ -337,15 +337,15 @@ int game_model_create_vertex(GameModel *game_model, int x, int y, int z) {
337337
}
338338

339339
int game_model_create_face(GameModel *game_model, int number, int *vertices,
340-
int front, int back) {
340+
int fill_front, int fill_back) {
341341
if (game_model->num_faces >= game_model->max_faces) {
342342
return -1;
343343
}
344344

345345
game_model->face_num_vertices[game_model->num_faces] = number;
346346
game_model->face_vertices[game_model->num_faces] = vertices;
347-
game_model->face_fill_front[game_model->num_faces] = front;
348-
game_model->face_fill_back[game_model->num_faces] = back;
347+
game_model->face_fill_front[game_model->num_faces] = fill_front;
348+
game_model->face_fill_back[game_model->num_faces] = fill_back;
349349
game_model->transform_state = 1;
350350

351351
return game_model->num_faces++;
@@ -489,9 +489,9 @@ void game_model_set_light_from6(GameModel *game_model, int gouraud,
489489
game_model_set_light_from5(game_model, ambience, diffuse, x, y, z);
490490
}
491491

492-
void game_model_set_vertex_ambience(GameModel *game_model, int v,
492+
void game_model_set_vertex_ambience(GameModel *game_model, int vertex_index,
493493
int ambience) {
494-
game_model->vertex_ambience[v] = ambience & 0xff;
494+
game_model->vertex_ambience[vertex_index] = ambience & 0xff;
495495
}
496496

497497
void game_model_rotate(GameModel *game_model, int yaw, int pitch, int roll) {

src/game-model.h

+3-2
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ void game_model_merge(GameModel *game_model, GameModel **pieces, int count,
114114
int game_model_vertex_at(GameModel *game_model, int x, int y, int z);
115115
int game_model_create_vertex(GameModel *game_model, int x, int y, int z);
116116
int game_model_create_face(GameModel *game_model, int number, int *vertices,
117-
int front, int back);
117+
int fill_front, int fill_back);
118118
void game_model_split(GameModel *game_model, GameModel **pieces, int unused1,
119119
int unused2, int piece_dx, int piece_dz, int rows,
120120
int count, int piece_max_vertices, int pickable);
@@ -125,7 +125,8 @@ void game_model_set_light_from5(GameModel *game_model, int ambience,
125125
int diffuse, int x, int y, int z);
126126
void game_model_set_light_from6(GameModel *game_model, int gouraud,
127127
int ambience, int diffuse, int x, int y, int z);
128-
void game_model_set_vertex_ambience(GameModel *game_model, int v, int ambience);
128+
void game_model_set_vertex_ambience(GameModel *game_model, int vertex_index,
129+
int ambience);
129130
void game_model_rotate(GameModel *game_model, int yaw, int pitch, int roll);
130131
void game_model_orient(GameModel *game_model, int yaw, int pitch, int roll);
131132
void game_model_translate(GameModel *game_model, int x, int y, int z);

src/panel.c

+43-43
Original file line numberDiff line numberDiff line change
@@ -209,24 +209,24 @@ void panel_draw_checkbox(Panel *panel, int control, int x, int y, int width,
209209
int height) {
210210
surface_draw_box(panel->surface, x, y, width, height, 0xffffff);
211211

212-
surface_draw_line_horiz(panel->surface, x, y, width,
213-
panel->colour_box_top_n_bottom);
212+
surface_draw_line_horizontal(panel->surface, x, y, width,
213+
panel->colour_box_top_n_bottom);
214214

215-
surface_draw_line_vert(panel->surface, x, y, height,
216-
panel->colour_box_top_n_bottom);
215+
surface_draw_line_vertical(panel->surface, x, y, height,
216+
panel->colour_box_top_n_bottom);
217217

218-
surface_draw_line_horiz(panel->surface, x, y + height - 1, width,
219-
panel->colour_box_left_n_right);
218+
surface_draw_line_horizontal(panel->surface, x, y + height - 1, width,
219+
panel->colour_box_left_n_right);
220220

221-
surface_draw_line_vert(panel->surface, x + width - 1, y, height,
222-
panel->colour_box_left_n_right);
221+
surface_draw_line_vertical(panel->surface, x + width - 1, y, height,
222+
panel->colour_box_left_n_right);
223223

224224
if (panel->control_list_entry_mouse_button_down[control] == 1) {
225225
for (int j1 = 0; j1 < height; j1++) {
226-
surface_draw_line_horiz(panel->surface, x + j1, y + j1, 1, 0);
226+
surface_draw_line_horizontal(panel->surface, x + j1, y + j1, 1, 0);
227227

228-
surface_draw_line_horiz(panel->surface, x + width - 1 - j1, y + j1,
229-
1, 0);
228+
surface_draw_line_horizontal(panel->surface, x + width - 1 - j1,
229+
y + j1, 1, 0);
230230
}
231231
}
232232
}
@@ -296,41 +296,41 @@ void panel_draw_box(Panel *panel, int x, int y, int width, int height) {
296296
panel->colour_box_left_n_right,
297297
panel->colour_box_top_n_bottom);
298298

299-
surface_draw_line_horiz(panel->surface, x, y, width,
300-
panel->colour_box_top_n_bottom);
299+
surface_draw_line_horizontal(panel->surface, x, y, width,
300+
panel->colour_box_top_n_bottom);
301301

302-
surface_draw_line_horiz(panel->surface, x + 1, y + 1, width - 2,
303-
panel->colour_box_top_n_bottom);
302+
surface_draw_line_horizontal(panel->surface, x + 1, y + 1, width - 2,
303+
panel->colour_box_top_n_bottom);
304304

305-
surface_draw_line_horiz(panel->surface, x + 2, y + 2, width - 4,
306-
panel->colour_box_top_n_bottom2);
305+
surface_draw_line_horizontal(panel->surface, x + 2, y + 2, width - 4,
306+
panel->colour_box_top_n_bottom2);
307307

308-
surface_draw_line_vert(panel->surface, x, y, height,
309-
panel->colour_box_top_n_bottom);
308+
surface_draw_line_vertical(panel->surface, x, y, height,
309+
panel->colour_box_top_n_bottom);
310310

311-
surface_draw_line_vert(panel->surface, x + 1, y + 1, height - 2,
312-
panel->colour_box_top_n_bottom);
311+
surface_draw_line_vertical(panel->surface, x + 1, y + 1, height - 2,
312+
panel->colour_box_top_n_bottom);
313313

314-
surface_draw_line_vert(panel->surface, x + 2, y + 2, height - 4,
315-
panel->colour_box_top_n_bottom2);
314+
surface_draw_line_vertical(panel->surface, x + 2, y + 2, height - 4,
315+
panel->colour_box_top_n_bottom2);
316316

317-
surface_draw_line_horiz(panel->surface, x, y + height - 1, width,
318-
panel->colour_box_left_n_right);
317+
surface_draw_line_horizontal(panel->surface, x, y + height - 1, width,
318+
panel->colour_box_left_n_right);
319319

320-
surface_draw_line_horiz(panel->surface, x + 1, y + height - 2, width - 2,
321-
panel->colour_box_left_n_right);
320+
surface_draw_line_horizontal(panel->surface, x + 1, y + height - 2,
321+
width - 2, panel->colour_box_left_n_right);
322322

323-
surface_draw_line_horiz(panel->surface, x + 2, y + height - 3, width - 4,
324-
panel->colour_box_left_n_right2);
323+
surface_draw_line_horizontal(panel->surface, x + 2, y + height - 3,
324+
width - 4, panel->colour_box_left_n_right2);
325325

326-
surface_draw_line_vert(panel->surface, x + width - 1, y, height,
327-
panel->colour_box_left_n_right);
326+
surface_draw_line_vertical(panel->surface, x + width - 1, y, height,
327+
panel->colour_box_left_n_right);
328328

329-
surface_draw_line_vert(panel->surface, x + width - 2, y + 1, height - 2,
330-
panel->colour_box_left_n_right);
329+
surface_draw_line_vertical(panel->surface, x + width - 2, y + 1, height - 2,
330+
panel->colour_box_left_n_right);
331331

332-
surface_draw_line_vert(panel->surface, x + width - 3, y + 2, height - 4,
333-
panel->colour_box_left_n_right2);
332+
surface_draw_line_vertical(panel->surface, x + width - 3, y + 2, height - 4,
333+
panel->colour_box_left_n_right2);
334334

335335
surface_reset_bounds(panel->surface);
336336
}
@@ -365,7 +365,7 @@ void panel_draw_picture(Panel *panel, int x, int y, int id) {
365365
}
366366

367367
void panel_draw_line_horiz(Panel *panel, int x, int y, int width) {
368-
surface_draw_line_horiz(panel->surface, x, y, width, 0xffffff);
368+
surface_draw_line_horizontal(panel->surface, x, y, width, 0xffffff);
369369
}
370370

371371
void panel_draw_text_list(Panel *panel, int control, int x, int y, int width,
@@ -496,8 +496,8 @@ void panel_draw_list_container(Panel *panel, int x, int y, int width,
496496
surface_draw_sprite_from3(panel->surface, x2 + 1, y + height - 12,
497497
panel_base_sprite_start + 1);
498498

499-
surface_draw_line_horiz(panel->surface, x2, y + 13, 12, 0);
500-
surface_draw_line_horiz(panel->surface, x2, y + height - 13, 12, 0);
499+
surface_draw_line_horizontal(panel->surface, x2, y + 13, 12, 0);
500+
surface_draw_line_horizontal(panel->surface, x2, y + height - 13, 12, 0);
501501

502502
surface_draw_gradient(panel->surface, x2 + 1, y + 14, 11, height - 27,
503503
panel->colour_scrollbar_top,
@@ -506,11 +506,11 @@ void panel_draw_list_container(Panel *panel, int x, int y, int width,
506506
surface_draw_box(panel->surface, x2 + 3, corner1 + y + 14, 7, corner2,
507507
panel->colour_scrollbar_handle_mid);
508508

509-
surface_draw_line_vert(panel->surface, x2 + 2, corner1 + y + 14, corner2,
510-
panel->colour_scrollbar_handle_left);
509+
surface_draw_line_vertical(panel->surface, x2 + 2, corner1 + y + 14,
510+
corner2, panel->colour_scrollbar_handle_left);
511511

512-
surface_draw_line_vert(panel->surface, x2 + 2 + 8, corner1 + y + 14,
513-
corner2, panel->colour_scrollbar_handle_right);
512+
surface_draw_line_vertical(panel->surface, x2 + 2 + 8, corner1 + y + 14,
513+
corner2, panel->colour_scrollbar_handle_right);
514514
}
515515

516516
void panel_draw_text_list_interactive(Panel *panel, int control, int x, int y,
@@ -875,7 +875,7 @@ void panel_remove_list_entry(Panel *panel, int control, char *text, int flag) {
875875

876876
void panel_update_text(Panel *panel, int control, char *text) {
877877
if (panel->control_type[control] == TEXT_INPUT) {
878-
strcpy(panel->control_text[control], text);
878+
strcpy(panel->control_text[control], text);
879879
} else {
880880
panel->control_text[control] = text;
881881
}

src/scene.c

+29-24
Original file line numberDiff line numberDiff line change
@@ -3533,47 +3533,52 @@ void scene_scroll_texture(Scene *scene, int id) {
35333533

35343534
int32_t *colours = scene->texture_pixels[id];
35353535

3536-
for (int i = 0; i < 64; i++) {
3537-
int k = i + 4032;
3538-
int l = colours[k];
3536+
for (int i = 0; i < SCROLL_TEXTURE_SIZE; i++) {
3537+
int pixel_index = i + SCROLL_TEXTURE_AREA - SCROLL_TEXTURE_SIZE;
3538+
int colour = colours[pixel_index];
35393539

3540-
for (int j1 = 0; j1 < 63; j1++) {
3541-
colours[k] = colours[k - 64];
3542-
k -= 64;
3540+
for (int j = 0; j < SCROLL_TEXTURE_SIZE - 1; j++) {
3541+
colours[pixel_index] = colours[pixel_index - SCROLL_TEXTURE_SIZE];
3542+
pixel_index -= SCROLL_TEXTURE_SIZE;
35433543
}
35443544

3545-
scene->texture_pixels[id][k] = l;
3545+
scene->texture_pixels[id][pixel_index] = colour;
35463546
}
35473547

3548-
int c = 4096;
3548+
for (int i = 0; i < SCROLL_TEXTURE_AREA; i++) {
3549+
int colour = colours[i];
35493550

3550-
for (int i1 = 0; i1 < c; i1++) {
3551-
int k1 = colours[i1];
3552-
colours[c + i1] = (k1 - (k1 >> 3)) & 0xf8f8ff;
3553-
colours[c * 2 + i1] = (k1 - (k1 >> 2)) & 0xf8f8ff;
3554-
colours[c * 3 + i1] = (k1 - (k1 >> 2) - (k1 >> 3)) & 0xf8f8ff;
3551+
colours[SCROLL_TEXTURE_AREA + i] = (colour - (colour >> 3)) & 0xf8f8ff;
3552+
3553+
colours[SCROLL_TEXTURE_AREA * 2 + i] =
3554+
(colour - (colour >> 2)) & 0xf8f8ff;
3555+
3556+
colours[SCROLL_TEXTURE_AREA * 3 + i] =
3557+
(colour - (colour >> 2) - (colour >> 3)) & 0xf8f8ff;
35553558
}
35563559
}
35573560

3558-
int scene_method302(Scene *scene, int i) {
3559-
if (i == COLOUR_TRANSPARENT) {
3561+
/* used to convert face_fill values (textures or colours) to minimap colours */
3562+
3563+
int scene_get_fill_colour(Scene *scene, int face_fill) {
3564+
if (face_fill == COLOUR_TRANSPARENT) {
35603565
return 0;
35613566
}
35623567

3563-
scene_prepare_texture(scene, i);
3568+
scene_prepare_texture(scene, face_fill);
35643569

3565-
if (i >= 0) {
3566-
return scene->texture_pixels[i][0];
3570+
if (face_fill >= 0) {
3571+
return scene->texture_pixels[face_fill][0];
35673572
}
35683573

3569-
if (i < 0) {
3570-
i = -(i + 1);
3574+
if (face_fill < 0) {
3575+
face_fill = -(face_fill + 1);
35713576

3572-
int j = (i >> 10) & 0x1f;
3573-
int k = (i >> 5) & 0x1f;
3574-
int l = i & 0x1f;
3577+
int r = (face_fill >> 10) & 0x1f;
3578+
int g = (face_fill >> 5) & 0x1f;
3579+
int b = face_fill & 0x1f;
35753580

3576-
return (j << 19) + (k << 11) + (l << 3);
3581+
return (r << 19) + (g << 11) + (b << 3);
35773582
}
35783583

35793584
return 0;

src/scene.h

+5-1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ typedef struct Scene Scene;
2626

2727
#define COLOUR_TRANSPARENT 12345678
2828

29+
/* width and height of scrollable textures */
30+
#define SCROLL_TEXTURE_SIZE 64
31+
#define SCROLL_TEXTURE_AREA (SCROLL_TEXTURE_SIZE * SCROLL_TEXTURE_SIZE)
32+
2933
extern int scene_frustum_max_x;
3034
extern int scene_frustum_min_x;
3135
extern int scene_frustum_max_y;
@@ -173,7 +177,7 @@ void scene_define_texture(Scene *scene, int id, int8_t *colour_idx,
173177
void scene_prepare_texture(Scene *scene, int id);
174178
void scene_set_texture_pixels(Scene *scene, int id);
175179
void scene_scroll_texture(Scene *scene, int id);
176-
int scene_method302(Scene *scene, int i);
180+
int scene_get_fill_colour(Scene *scene, int face_fill);
177181
void scene_set_light_from3(Scene *scene, int x, int y, int z);
178182
void scene_set_light_from5(Scene *scene, int ambience, int diffuse, int x,
179183
int y, int z);

src/surface.c

+10-10
Original file line numberDiff line numberDiff line change
@@ -388,8 +388,8 @@ void surface_draw_box(Surface *surface, int x, int y, int width, int height,
388388
}
389389
}
390390

391-
void surface_draw_line_horiz(Surface *surface, int x, int y, int width,
392-
int colour) {
391+
void surface_draw_line_horizontal(Surface *surface, int x, int y, int width,
392+
int colour) {
393393
if (y < surface->bounds_top_y || y >= surface->bounds_bottom_y) {
394394
return;
395395
}
@@ -410,8 +410,8 @@ void surface_draw_line_horiz(Surface *surface, int x, int y, int width,
410410
}
411411
}
412412

413-
void surface_draw_line_vert(Surface *surface, int x, int y, int height,
414-
int colour) {
413+
void surface_draw_line_vertical(Surface *surface, int x, int y, int height,
414+
int colour) {
415415
if (x < surface->bounds_top_x || x >= surface->bounds_bottom_x) {
416416
return;
417417
}
@@ -434,10 +434,10 @@ void surface_draw_line_vert(Surface *surface, int x, int y, int height,
434434

435435
void surface_draw_box_edge(Surface *surface, int x, int y, int width,
436436
int height, int colour) {
437-
surface_draw_line_horiz(surface, x, y, width, colour);
438-
surface_draw_line_horiz(surface, x, y + height - 1, width, colour);
439-
surface_draw_line_vert(surface, x, y, height, colour);
440-
surface_draw_line_vert(surface, x + width - 1, y, height, colour);
437+
surface_draw_line_horizontal(surface, x, y, width, colour);
438+
surface_draw_line_horizontal(surface, x, y + height - 1, width, colour);
439+
surface_draw_line_vertical(surface, x, y, height, colour);
440+
surface_draw_line_vertical(surface, x + width - 1, y, height, colour);
441441
}
442442

443443
void surface_set_pixel(Surface *surface, int x, int y, int colour) {
@@ -2558,13 +2558,13 @@ void surface_draw_tabs(Surface *surface, int x, int y, int width, int height,
25582558
surface, tabs[i], x + offset_x + (tab_width / 2), y + 16, 4, BLACK);
25592559

25602560
if (i > 0) {
2561-
surface_draw_line_vert(surface, x + offset_x, y, height, BLACK);
2561+
surface_draw_line_vertical(surface, x + offset_x, y, height, BLACK);
25622562
}
25632563

25642564
offset_x += tab_width;
25652565
}
25662566

2567-
surface_draw_line_horiz(surface, x, y + height, width, BLACK);
2567+
surface_draw_line_horizontal(surface, x, y + height, width, BLACK);
25682568
}
25692569

25702570
void surface_free_colours(Surface *surface) {

src/surface.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,9 @@ void surface_draw_gradient(Surface *surface, int x, int y, int width,
8484
int height, int colour_top, int colour_bottom);
8585
void surface_draw_box(Surface *surface, int x, int y, int width, int height,
8686
int colour);
87-
void surface_draw_line_horiz(Surface *surface, int x, int y, int width,
87+
void surface_draw_line_horizontal(Surface *surface, int x, int y, int width,
8888
int colour);
89-
void surface_draw_line_vert(Surface *surface, int x, int y, int height,
89+
void surface_draw_line_vertical(Surface *surface, int x, int y, int height,
9090
int colour);
9191
void surface_draw_box_edge(Surface *surface, int x, int y, int width,
9292
int height, int colour);

0 commit comments

Comments
 (0)