2007-11-25 19:42:40 +00:00
|
|
|
/* copyright (c) 2007 magnus auvinen, see licence.txt for more info */
|
2007-11-08 09:11:32 +00:00
|
|
|
#include <string.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
|
2007-12-15 10:24:49 +00:00
|
|
|
#include <engine/e_system.h>
|
2008-01-19 10:57:25 +00:00
|
|
|
#include <engine/e_server_interface.h>
|
|
|
|
/*#include <engine/e_client_interface.h>*/
|
2007-12-15 10:24:49 +00:00
|
|
|
#include <engine/e_config.h>
|
2008-01-16 22:14:06 +00:00
|
|
|
#include <engine/e_console.h>
|
2007-11-08 09:11:32 +00:00
|
|
|
|
|
|
|
static char application_save_path[512] = {0};
|
|
|
|
|
|
|
|
const char *engine_savepath(const char *filename, char *buffer, int max)
|
|
|
|
{
|
2007-11-18 22:06:41 +00:00
|
|
|
sprintf(buffer, "%s/%s", application_save_path, filename);
|
2007-11-08 09:11:32 +00:00
|
|
|
return buffer;
|
|
|
|
}
|
|
|
|
|
|
|
|
void engine_init(const char *appname, int argc, char **argv)
|
|
|
|
{
|
2008-01-12 12:27:55 +00:00
|
|
|
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
|
|
|
|
|
2007-11-08 09:11:32 +00:00
|
|
|
/* 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);
|
|
|
|
}
|
|
|
|
}
|
2008-01-16 22:14:06 +00:00
|
|
|
|
|
|
|
/* init console */
|
|
|
|
console_init();
|
2007-11-08 09:11:32 +00:00
|
|
|
|
|
|
|
/* reset the config */
|
|
|
|
config_reset();
|
2008-02-02 12:38:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void engine_parse_arguments(int argc, char **argv)
|
|
|
|
{
|
2007-11-08 09:11:32 +00:00
|
|
|
/* load the configuration */
|
2008-02-02 12:38:36 +00:00
|
|
|
int i;
|
|
|
|
int abs = 0;
|
|
|
|
const char *config_filename = "default.cfg";
|
|
|
|
char buf[1024];
|
|
|
|
for(i = 1; i < argc; i++)
|
2007-11-08 09:11:32 +00:00
|
|
|
{
|
2008-02-02 12:38:36 +00:00
|
|
|
if(argv[i][0] == '-' && argv[i][1] == 'f' && argv[i][2] == 0 && argc - i > 1)
|
2007-11-08 09:11:32 +00:00
|
|
|
{
|
2008-02-02 12:38:36 +00:00
|
|
|
config_filename = argv[i+1];
|
|
|
|
abs = 1;
|
|
|
|
i++;
|
2007-11-08 09:11:32 +00:00
|
|
|
}
|
|
|
|
}
|
2008-02-02 12:38:36 +00:00
|
|
|
|
|
|
|
if(abs)
|
|
|
|
config_load(config_filename);
|
|
|
|
else
|
|
|
|
config_load(engine_savepath(config_filename, buf, sizeof(buf)));
|
2007-11-08 09:11:32 +00:00
|
|
|
|
|
|
|
/* 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)));
|
|
|
|
}
|
2007-12-16 15:33:44 +00:00
|
|
|
|
|
|
|
|
|
|
|
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()
|
|
|
|
{
|
2008-01-13 11:15:32 +00:00
|
|
|
if(!current)
|
|
|
|
return;
|
|
|
|
|
2007-12-16 16:14:05 +00:00
|
|
|
current->last_delta = time_get()-current->start;
|
|
|
|
current->total += current->last_delta;
|
2007-12-16 15:33:44 +00:00
|
|
|
|
2007-12-16 16:14:05 +00:00
|
|
|
if(current->last_delta > current->biggest)
|
|
|
|
current->biggest = current->last_delta;
|
2007-12-16 15:33:44 +00:00
|
|
|
|
|
|
|
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);
|
|
|
|
}
|