Added a profiler.

This commit is contained in:
2026-08-07 12:28:18 -07:00
parent 14d87eac10
commit 47b9a9ae38
6 changed files with 207 additions and 63 deletions
+23 -6
View File
@@ -766,26 +766,36 @@ U64 __rdtsc()
}
#endif
#include "profiler.h"
int main(int argc, char *argv[])
{
struct sdl_state sdl_state;
SDL_Window *window;
int i;
memset(&sdl_state, 0, sizeof(sdl_state));
sdl_get_exe_dir_path(sdl_state.exe_dir_path, sizeof(sdl_state.exe_dir_path));
sdl_get_exe_dir_path(sdl_state.exe_dir_path,
sizeof(sdl_state.exe_dir_path));
sdl_get_dll_path(sdl_state.dll_path, sizeof(sdl_state.dll_path),
sdl_state.exe_dir_path);
if(SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_GAMEPAD)) {
if(!SDL_Init(SDL_INIT_VIDEO)) {
/* TODO: This didn't work . . . */
}
/* NOTE: It takes roughly half a second to initialize
* SDL_INIT_GAMEPAD. */
if(!SDL_InitSubSystem(SDL_INIT_GAMEPAD)) {
/* TODO: This didn't work . . . */
}
sdl_init_controllers();
/* NOTE: Create hidden window so that a blank window doesn't appear
* before everything is ready. */
* before everything is ready. */
/* TODO: SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, in non-debug
* build */
window = SDL_CreateWindow("Handmade Hero",
@@ -793,6 +803,7 @@ int main(int argc, char *argv[])
SDL_WINDOW_HIDDEN | SDL_WINDOW_RESIZABLE |
SDL_WINDOW_HIGH_PIXEL_DENSITY /*|
SDL_WINDOW_ALWAYS_ON_TOP*/);
if(window) {
const SDL_DisplayMode *display_mode;
@@ -837,7 +848,8 @@ int main(int argc, char *argv[])
memset(&temp_context, 0, sizeof(temp_context));
/* TODO: Make it a global. */
pointer_cursor = SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_DEFAULT);
pointer_cursor =
SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_DEFAULT);
SDL_SetCursor(pointer_cursor);
#if !BUILD_INTERNAL
if(SDL_ShowCursor(SDL_DISABLE) < 0) {
@@ -872,6 +884,9 @@ int main(int argc, char *argv[])
sound_output.samples_per_second / 15;
#if 0
if(!SDL_InitSubSystem(SDL_INIT_AUDIO)) {
/* TODO: This didn't work . . . */
}
sdl_init_sound(sound_output.SamplesPerSecond,
sound_output.SamplesPerSecond * sound_output.BytesPerSample /
60);
@@ -880,7 +895,8 @@ int main(int argc, char *argv[])
sound_output.Samples = calloc(sound_output.SamplesPerSecond,
sound_output.BytesPerSample);
/*sound_output.Samples = malloc(sound_output.SecondaryBufferSize);*/
/*sound_output.Samples =
malloc(sound_output.SecondaryBufferSize);*/
/* NOTE: calloc auto clears to zero */
/* sdl_clear_sound_buffer(&sound_output); */
#endif
@@ -947,7 +963,8 @@ int main(int argc, char *argv[])
game = sdl_load_game_code(sdl_state.dll_path);
SDL_ShowWindow(window); // Everything is ready; display the window.
/* Everything is ready; display the window.*/
SDL_ShowWindow(window);
fps_last_counter = sdl_get_wall_clock();