1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
|
/* copyright (c) 2007 magnus auvinen, see licence.txt for more info */
#include <string.h>
#include <stdio.h>
#include <engine/e_system.h>
#include <engine/e_server_interface.h>
/*#include <engine/e_client_interface.h>*/
#include <engine/e_config.h>
#include <engine/e_console.h>
static void con_dbg_dumpmem(void *result, void *user_data)
{
mem_debug_dump();
}
static char application_save_path[512] = {0};
const char *engine_savepath(const char *filename, char *buffer, int max)
{
sprintf(buffer, "%s/%s", application_save_path, filename);
return buffer;
}
void engine_init(const char *appname, int argc, char **argv)
{
dbg_msg("engine", "running on %s-%s-%s", CONF_FAMILY_STRING, CONF_PLATFORM_STRING, CONF_ARCH_STRING);
#ifdef CONF_ARCH_ENDIAN_LITTLE
dbg_msg("engine", "arch is little endian");
#elif defined(CONF_ARCH_ENDIAN_BIG)
dbg_msg("engine", "arch is big endian");
#else
dbg_msg("engine", "unknown endian");
#endif
/* init the network */
net_init();
/* create storage location */
{
char path[1024] = {0};
fs_storage_path(appname, application_save_path, sizeof(application_save_path));
if(fs_makedir(application_save_path) == 0)
{
strcpy(path, application_save_path);
strcat(path, "/screenshots");
fs_makedir(path);
strcpy(path, application_save_path);
strcat(path, "/maps");
fs_makedir(path);
}
}
/* init console */
console_init();
MACRO_REGISTER_COMMAND("dbg_dumpmem", "", con_dbg_dumpmem, 0x0);
/* reset the config */
config_reset();
}
void engine_parse_arguments(int argc, char **argv)
{
/* load the configuration */
int i;
int abs = 0;
const char *config_filename = "default.cfg";
char buf[1024];
for(i = 1; i < argc; i++)
{
if(argv[i][0] == '-' && argv[i][1] == 'f' && argv[i][2] == 0 && argc - i > 1)
{
config_filename = argv[i+1];
abs = 1;
i++;
}
}
if(abs)
config_load(config_filename);
else
config_load(engine_savepath(config_filename, buf, sizeof(buf)));
/* search arguments for overrides */
{
int i;
for(i = 1; i < argc; i++)
config_set(argv[i]);
}
}
void engine_writeconfig()
{
char buf[1024];
config_save(engine_savepath("default.cfg", buf, sizeof(buf)));
}
static int perf_tick = 1;
static PERFORMACE_INFO *current = 0;
void perf_init()
{
}
void perf_next()
{
perf_tick++;
current = 0;
}
void perf_start(PERFORMACE_INFO *info)
{
if(info->tick != perf_tick)
{
info->parent = current;
info->first_child = 0;
info->next_child = 0;
if(info->parent)
{
info->next_child = info->parent->first_child;
info->parent->first_child = info;
}
info->tick = perf_tick;
info->biggest = 0;
info->total = 0;
}
current = info;
current->start = time_get();
}
void perf_end()
{
if(!current)
return;
current->last_delta = time_get()-current->start;
current->total += current->last_delta;
if(current->last_delta > current->biggest)
current->biggest = current->last_delta;
current = current->parent;
}
static void perf_dump_imp(PERFORMACE_INFO *info, int indent)
{
char buf[512] = {0};
int64 freq = time_freq();
int i;
for(i = 0; i < indent; i++)
buf[i] = ' ';
sprintf(&buf[indent], "%-20s %8.2f %8.2f", info->name, info->total*1000/(float)freq, info->biggest*1000/(float)freq);
dbg_msg("perf", "%s", buf);
info = info->first_child;
while(info)
{
perf_dump_imp(info, indent+2);
info = info->next_child;
}
}
void perf_dump(PERFORMACE_INFO *top)
{
perf_dump_imp(top, 0);
}
|