Skip to content

Commit fa49cf5

Browse files
committed
makefile improvements & warnings treatment
1 parent c6b0837 commit fa49cf5

File tree

4 files changed

+41
-13
lines changed

4 files changed

+41
-13
lines changed

include/helpers.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,5 @@ void wfrRefresh();
77
void wfrTerminate();
88
void wfrClear();
99
void wfrFrameSync(unsigned int fps);
10-
static int wfrCompare(const void *a, const void *b);
10+
int wfrCompare(const void *a, const void *b);
1111
void wfrOrderPoints(wfrVec2 pts[4]);

makefile

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,19 @@
11
src := $(shell find src -name '*.c')
22
include := -Iinclude
3+
debflags := -g3 -O0 -ggdb -Wall -Wextra -Wshadow -Wformat -Wconversion -DDEBUG -fsanitize=address,undefined -fno-omit-frame-pointer
4+
disflags := -O3 -flto -funroll-loops -finline-functions -fomit-frame-pointer -fno-strict-aliasing -fno-common -fwrapv -ffast-math -fprefetch-loop-arrays -fmerge-all-constants -ffunction-sections -fdata-sections -Wl,--gc-sections -fno-exceptions -DNDEBUG
35

46
.SILENT:
57
all:
68
@echo
9+
@echo "Compiling in Debug Mode!"
10+
@echo
711

812
@mkdir -p build lib
913

1014
@for f in $(src); do \
1115
echo "[Compiling]: $$f"; \
12-
gcc -c $$f $(include) -o build/$$(basename $$f .c).o; \
16+
gcc -c $$f $(include) $(debflags) -o build/$$(basename $$f .c).o; \
1317
done
1418

1519
@echo
@@ -19,3 +23,24 @@ all:
1923
@echo
2024
@echo "Done!"
2125
@echo
26+
27+
.SILENT:
28+
dis:
29+
@echo
30+
@echo "Compiling in Distribution Mode!"
31+
@echo
32+
33+
@mkdir -p build lib
34+
35+
@for f in $(src); do \
36+
echo "[Compiling]: $$f"; \
37+
gcc -c $$f $(include) $(disflags) -o build/$$(basename $$f .c).o; \
38+
done
39+
40+
@echo
41+
echo "[Linking]: lib/libwireframe.a"
42+
ar rcs lib/libwireframe.a -lncurses build/*.o
43+
44+
@echo
45+
@echo "Done!"
46+
@echo

src/drawing/lines.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ void wfrDrawLine(wfrVec2 p1, wfrVec2 p2) {
1111
int dx = abs(x2 - x1);
1212
int dy = abs(y2 - y1);
1313

14-
int steep = dy > dx;
14+
unsigned short steep = dy > dx;
1515
if (steep) {
1616
int tmp;
1717
tmp = x1; x1 = y1; y1 = tmp;
@@ -24,14 +24,14 @@ void wfrDrawLine(wfrVec2 p1, wfrVec2 p2) {
2424
int y = y1;
2525

2626
wfrVec2* points = malloc(sizeof(wfrVec2));
27-
int size = 0;
27+
unsigned short size = 0;
2828

29-
points[size].x = steep ? y : x;
30-
points[size].y = steep ? x : y;
29+
points[size].x = (unsigned short)(steep ? y : x);
30+
points[size].y = (unsigned short)(steep ? x : y);
3131
size++;
3232

33-
int x_inc = (x2 > x1) ? 1 : -1;
34-
int y_inc = (y2 > y1) ? 1 : -1;
33+
short x_inc = (x2 > x1) ? 1 : -1;
34+
short y_inc = (y2 > y1) ? 1 : -1;
3535

3636
for (int i = 0; i < dx; i++) {
3737
if (p < 0) {
@@ -44,8 +44,8 @@ void wfrDrawLine(wfrVec2 p1, wfrVec2 p2) {
4444

4545
size++;
4646
points = realloc(points, size * sizeof(wfrVec2));
47-
points[size - 1].x = steep ? y : x;
48-
points[size - 1].y = steep ? x : y;
47+
points[size - 1].x = (unsigned short)(steep ? y : x);
48+
points[size - 1].y = (unsigned short)(steep ? x : y);
4949
}
5050

5151
for (int i = 0; i < size; i++) {

src/helpers.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ void wfrFrameSync(unsigned int fps){
4848

4949
static wfrVec2 wfrCenter;
5050

51-
static int wfrCompare(const void *a, const void *b) {
51+
int wfrCompare(const void *a, const void *b) {
5252
const wfrVec2 *p1 = a;
5353
const wfrVec2 *p2 = b;
5454

@@ -59,8 +59,11 @@ static int wfrCompare(const void *a, const void *b) {
5959
}
6060

6161
void wfrOrderPoints(wfrVec2 pts[4]) {
62-
wfrCenter.x = (pts[0].x + pts[1].x + pts[2].x + pts[3].x) / 4.0f;
63-
wfrCenter.y = (pts[0].y + pts[1].y + pts[2].y + pts[3].y) / 4.0f;
62+
float cx = ((float)pts[0].x + pts[1].x + pts[2].x + pts[3].x) / 4.0f;
63+
float cy = ((float)pts[0].y + pts[1].y + pts[2].y + pts[3].y) / 4.0f;
64+
65+
wfrCenter.x = (unsigned short)(cx + 0.5f);
66+
wfrCenter.y = (unsigned short)(cy + 0.5f);
6467

6568
qsort(pts, 4, sizeof(wfrVec2), wfrCompare);
6669
}

0 commit comments

Comments
 (0)