more startup profiling, removal of irrelevant calls and zeroing in textures_cache_init()
This commit is contained in:
		@@ -341,20 +341,22 @@ ERR_PACK_MANIFEST_PATH_ALLOC_FAIL:
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
static bool initialize(void) {
 | 
			
		||||
    profile_start("SDL initialization");
 | 
			
		||||
    if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_EVENTS) == -1) {
 | 
			
		||||
        CRY_SDL("SDL initialization failed.");
 | 
			
		||||
        return false;
 | 
			
		||||
    }
 | 
			
		||||
    profile_end("SDL initialization");
 | 
			
		||||
 | 
			
		||||
    /* first things first, most things here will be loaded from the config file */
 | 
			
		||||
    /* it's expected to be present in the data directory, no matter what */
 | 
			
		||||
    /* that is why PhysicsFS is initialized before anything else */
 | 
			
		||||
    toml_set_memutil(SDL_malloc, SDL_free);
 | 
			
		||||
 | 
			
		||||
    profile_start("resolve_pack_dependencies()");
 | 
			
		||||
    profile_start("pack dependency resolution");
 | 
			
		||||
    /* time to orderly resolve any dependencies present */
 | 
			
		||||
    resolve_pack_dependencies("data");
 | 
			
		||||
    profile_end("resolve_pack_dependencies()");
 | 
			
		||||
    profile_end("pack dependency resolution");
 | 
			
		||||
 | 
			
		||||
    /* load the config file into an opaque table */
 | 
			
		||||
    {
 | 
			
		||||
@@ -481,6 +483,7 @@ static bool initialize(void) {
 | 
			
		||||
        ctx.game.resolution.x = (float)ctx.base_render_width;
 | 
			
		||||
        ctx.game.resolution.y = (float)ctx.base_render_height;
 | 
			
		||||
 | 
			
		||||
        profile_start("window creation");
 | 
			
		||||
        ctx.window = SDL_CreateWindow(datum_title.u.s,
 | 
			
		||||
                                      SDL_WINDOWPOS_CENTERED,
 | 
			
		||||
                                      SDL_WINDOWPOS_CENTERED,
 | 
			
		||||
@@ -489,6 +492,7 @@ static bool initialize(void) {
 | 
			
		||||
                                      //SDL_WINDOW_ALLOW_HIGHDPI |
 | 
			
		||||
                                          SDL_WINDOW_RESIZABLE |
 | 
			
		||||
                                          SDL_WINDOW_OPENGL);
 | 
			
		||||
        profile_end("window creation");
 | 
			
		||||
 | 
			
		||||
        if (datum_title.ok)
 | 
			
		||||
            SDL_free(datum_title.u.s);
 | 
			
		||||
@@ -501,6 +505,7 @@ static bool initialize(void) {
 | 
			
		||||
        goto fail;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    profile_start("opengl context creation");
 | 
			
		||||
    ctx.gl_context = SDL_GL_CreateContext(ctx.window);
 | 
			
		||||
    if (!ctx.gl_context) {
 | 
			
		||||
        CRY_SDL("GL context creation failed.");
 | 
			
		||||
@@ -518,11 +523,12 @@ static bool initialize(void) {
 | 
			
		||||
    if (!render_init())
 | 
			
		||||
        goto fail;
 | 
			
		||||
 | 
			
		||||
    setup_viewport(0, 0, (int)ctx.base_render_width, (int)ctx.base_render_height);
 | 
			
		||||
    profile_end("opengl context creation");
 | 
			
		||||
 | 
			
		||||
    /* might need this to have multiple windows */
 | 
			
		||||
    ctx.window_id = SDL_GetWindowID(ctx.window);
 | 
			
		||||
 | 
			
		||||
    setup_viewport(0, 0, (int)ctx.base_render_width, (int)ctx.base_render_height);
 | 
			
		||||
 | 
			
		||||
    /* TODO: */
 | 
			
		||||
    // SDL_GetRendererOutputSize(ctx.renderer, &ctx.window_w, &ctx.window_h);
 | 
			
		||||
    ctx.window_dims.x = (float)ctx.base_render_width;
 | 
			
		||||
@@ -534,6 +540,10 @@ static bool initialize(void) {
 | 
			
		||||
    /* audio initialization */
 | 
			
		||||
    {
 | 
			
		||||
 | 
			
		||||
    /* TODO: try to delay it until actually used? */
 | 
			
		||||
    /*       quite a lot of programs might start with silence of resource loading of initial frame */
 | 
			
		||||
    profile_start("audio initialization");
 | 
			
		||||
 | 
			
		||||
    SDL_AudioSpec request, got;
 | 
			
		||||
    SDL_zero(request);
 | 
			
		||||
 | 
			
		||||
@@ -555,6 +565,8 @@ static bool initialize(void) {
 | 
			
		||||
 | 
			
		||||
    SDL_PauseAudioDevice(ctx.audio_device, 0);
 | 
			
		||||
 | 
			
		||||
    profile_end("audio initialization");
 | 
			
		||||
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /* random seeding */
 | 
			
		||||
@@ -645,8 +657,10 @@ static bool initialize(void) {
 | 
			
		||||
    ctx.render_queue_2d = NULL;
 | 
			
		||||
    ctx.uncolored_mesh_batches = NULL;
 | 
			
		||||
 | 
			
		||||
    profile_start("texture and text cache initialization");
 | 
			
		||||
    textures_cache_init(&ctx.texture_cache, ctx.window);
 | 
			
		||||
    text_cache_init(&ctx.text_cache);
 | 
			
		||||
    profile_end("texture and text cache initialization");
 | 
			
		||||
 | 
			
		||||
    /* input */
 | 
			
		||||
    toml_datum_t datum_keybind_slots = toml_int_in(engine, "keybind_slots");
 | 
			
		||||
@@ -661,13 +675,6 @@ static bool initialize(void) {
 | 
			
		||||
    }
 | 
			
		||||
    input_state_init(&ctx.input);
 | 
			
		||||
 | 
			
		||||
    /* scripting */
 | 
			
		||||
    /*
 | 
			
		||||
    if (!scripting_init(ctx)) {
 | 
			
		||||
        goto fail;
 | 
			
		||||
    }
 | 
			
		||||
    */
 | 
			
		||||
 | 
			
		||||
    ctx.render_double_buffered = true;
 | 
			
		||||
    ctx.window_mouse_resident = true;
 | 
			
		||||
 | 
			
		||||
@@ -684,10 +691,6 @@ fail:
 | 
			
		||||
 | 
			
		||||
/* will not be called on an abnormal exit */
 | 
			
		||||
static void clean_up(void) {
 | 
			
		||||
    /*
 | 
			
		||||
    scripting_deinit(ctx);
 | 
			
		||||
    */
 | 
			
		||||
 | 
			
		||||
    input_state_deinit(&ctx.input);
 | 
			
		||||
    text_cache_deinit(&ctx.text_cache);
 | 
			
		||||
    textures_cache_deinit(&ctx.texture_cache);
 | 
			
		||||
@@ -791,8 +794,10 @@ int enter_loop(int argc, char **argv) {
 | 
			
		||||
 | 
			
		||||
    update_viewport();
 | 
			
		||||
 | 
			
		||||
    profile_start("game object load");
 | 
			
		||||
    /* now we can actually start doing stuff */
 | 
			
		||||
    game_object_load();
 | 
			
		||||
    profile_end("game object load");
 | 
			
		||||
 | 
			
		||||
    ctx.was_successful = true;
 | 
			
		||||
    ctx.game.initialization_needed = true;
 | 
			
		||||
 
 | 
			
		||||
@@ -307,10 +307,9 @@ void textures_cache_init(TextureCache *cache, SDL_Window *window) {
 | 
			
		||||
    cache->window = window;
 | 
			
		||||
    sh_new_arena(cache->hash);
 | 
			
		||||
 | 
			
		||||
    cache->node_buffer = SDL_calloc(ctx.texture_atlas_size, sizeof *cache->node_buffer);
 | 
			
		||||
    cache->node_buffer = SDL_malloc(ctx.texture_atlas_size * sizeof *cache->node_buffer);
 | 
			
		||||
 | 
			
		||||
    add_new_atlas(cache);
 | 
			
		||||
    recreate_current_atlas_texture(cache);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user