Skip to content

Commit c44948e

Browse files
committed
try out precompiled headers for speed
1 parent 1a3866e commit c44948e

7 files changed

+93
-19
lines changed

build/build.sh

+1
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,7 @@ LDLIBS="$LDLIBS -lSDL2_mixer"
273273
CONFIG_H=src/cfg.hpp
274274
echo "#include \"my_cfg.hpp\"" > $CONFIG_H
275275
C_FLAGS+=" -include cfg.hpp"
276+
rm -f src/precompiled.hpp.gch
276277

277278
#
278279
# for backtraces, but it doesn't help much

src/Makefile

+12-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
include ../build/Makefile.template
2+
# CFLAGS+=-O0
23

34
NAME=yelindor
45
BUILD_DIR=../.o
@@ -33,12 +34,20 @@ $(OBJ_FILES): | $(BUILD_DIR)
3334

3435
# custom compile command for each source file needed because object file
3536
# base names don't match source files that were in src/ subdirectories
36-
$(foreach x,$(CPP_SOURCES),\
37-
$(eval $(BUILD_DIR)/$(call obj_name,$x): $x ; $(CC) $(CFLAGS) $(DEP_FLAGS) -c -o $$@ $$<))
37+
38+
PRECOMPILED_H := precompiled.hpp
39+
PRECOMPILED_H_OBJ := $(PRECOMPILED_H).gch
40+
41+
%.hpp.gch: $(PRECOMPILED_H)
42+
$(CC) $(CFLAGS) -c -o $@ $<
3843

3944
$(foreach x,$(ASM_SOURCES),\
40-
$(eval $(BUILD_DIR)/$(call obj_name,$x): $x ; $(CC) $(DEP_FLAGS) -c -o $$@ $$<))
45+
$(eval $(BUILD_DIR)/$(call obj_name,$x): $x ;\
46+
$(CC) $(CFLAGS) $(DEP_FLAGS) -c -o $$@ $$<))
4147

48+
$(foreach x,$(CPP_SOURCES),\
49+
$(eval $(BUILD_DIR)/$(call obj_name,$x): $x | $(PRECOMPILED_H_OBJ) ;\
50+
$(CC) -include $(PRECOMPILED_H) $(CFLAGS) $(DEP_FLAGS) -c -o $$@ $$<))
4251

4352
# use file list instead of wildcard for link command so we don't accidentally
4453
# link with old object files for removed source files

src/globals.cpp

-12
Original file line numberDiff line numberDiff line change
@@ -45,18 +45,6 @@ std::string g_opt_seed_name;
4545
int TILES_VISIBLE_ACROSS;
4646
int TILES_VISIBLE_DOWN;
4747

48-
//
49-
// Map size
50-
//
51-
int MAP_HEIGHT;
52-
int MAP_WIDTH;
53-
54-
//
55-
// Map room cells
56-
//
57-
int LEVEL_PH2_HEIGHT;
58-
int LEVEL_PH2_WIDTH;
59-
6048
int g_last_logged_callframes_depth;
6149

6250
void reset_globals(void)

src/main.cpp

+23
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,29 @@
2828
#include "my_tp.hpp"
2929
#include "my_wid_console.hpp"
3030

31+
#include "my_callstack.hpp"
32+
33+
#ifdef USE_THREADS
34+
#ifdef __MAIN__
35+
thread_local struct callframe callframes[ MAXCALLFRAME ];
36+
thread_local unsigned char g_callframes_depth;
37+
#else
38+
extern thread_local struct callframe callframes[ MAXCALLFRAME ];
39+
extern thread_local unsigned char g_callframes_depth;
40+
extern thread_local unsigned char g_callframes_indent;
41+
#endif
42+
#else
43+
#ifdef __MAIN__
44+
struct callframe callframes[ MAXCALLFRAME ];
45+
unsigned char g_callframes_depth;
46+
unsigned char g_callframes_indent;
47+
#else
48+
extern struct callframe callframes[ MAXCALLFRAME ];
49+
extern unsigned char g_callframes_depth;
50+
extern unsigned char g_callframes_indent;
51+
#endif
52+
#endif
53+
3154
static char **ARGV;
3255

3356
static std::string original_program_name;

src/my_ramdisk.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
#pragma once
66

77
#include <map>
8-
#include <string> // do not remove
8+
#include <string>
99

1010
using ramdisk_t = struct ramdisk_t_ {
1111
const unsigned char *data;

src/precompiled.hpp

+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
#include <SDL.h>
2+
#include <SDL_mixer.h>
3+
#include <array>
4+
#include <cstdint>
5+
#include <cstring>
6+
#include <ctime>
7+
#include <ctype.h>
8+
#include <errno.h>
9+
#include <fstream>
10+
#include <inttypes.h>
11+
#include <iomanip>
12+
#include <iostream>
13+
#include <limits.h>
14+
#include <list>
15+
#include <locale.h>
16+
#include <map>
17+
#include <math.h>
18+
#include <memory>
19+
#include <signal.h>
20+
#include <sstream>
21+
#include <stdarg.h>
22+
#include <stddef.h>
23+
#include <stdint.h>
24+
#include <stdio.h>
25+
#include <stdlib.h>
26+
#include <string.h>
27+
#include <string>
28+
#include <strings.h>
29+
#include <sys/param.h>
30+
#include <sys/prctl.h>
31+
#include <sys/stat.h>
32+
#include <sys/wait.h>
33+
#include <time.h>
34+
#include <unistd.h>
35+
#include <vector>
36+
37+
#include "my_audio.hpp"
38+
#include "my_command.hpp"
39+
#include "my_dir.hpp"
40+
#include "my_file.hpp"
41+
#include "my_font.hpp"
42+
#include "my_game.hpp"
43+
#include "my_gfx.hpp"
44+
#include "my_level.hpp"
45+
#include "my_level_data.hpp"
46+
#include "my_music.hpp"
47+
#include "my_ramdisk.hpp"
48+
#include "my_random.hpp"
49+
#include "my_sdl_proto.hpp"
50+
#include "my_sound.hpp"
51+
#include "my_thing.hpp"
52+
#include "my_thing_id.hpp"
53+
#include "my_tp.hpp"
54+
#include "my_tps.hpp"
55+
#include "my_wid_console.hpp"

src/ramdisk_read.cpp

+1-3
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,9 @@
22
// Copyright Neil McGill, goblinhack@gmail.com
33
//
44

5-
#include <string.h>
6-
75
#include "my_main.hpp"
8-
#include "my_ptrcheck.hpp"
96
#include "my_ramdisk.hpp"
7+
#include <string.h>
108

119
std::map< std::string, ramdisk_t_ > ramdisk_data;
1210

0 commit comments

Comments
 (0)