#define ASSET_FONT_COUNT 25 #define ASSET_WORKER_COUNT 4 #define ASSET_QUEUE_COUNT 150 #define ASSET_IMAGE_COUNT 100 #define ASSET_SOUND_COUNT 30 #define NUM_AUDIO_CHANNELS 8 #define GAME_VERSION "0.1" #include "../project-base/src/project_base.h" platform_window* main_window; vec4 area; float scale = 1.0f; float zoom = 1.0f; float camera_x = 0.0f; float camera_y = 0.0f; font* fnt_rd8; font* fnt_rd12; font* fnt_rd16; font* fnt_rd20; font* fnt_rd24; font* fnt_rd28; font* fnt_rd32; font* fnt_rd36; font* fnt_rd40; font* fnt_rd44; font* fnt_rd48; #define CONFIG_DIRECTORY "trucker_x" #include "include/intermediate.h" #include "include/settings.h" #include "include/ui/colors.h" #include "include/ui/animation.h" #include "include/world.h" #include "include/ui/portrait.h" #include "include/scenery.h" #include "include/data.h" #include "include/game.h" #include "include/tooltip.h" #include "include/ui/panel.h" #include "include/ui/button.h" #include "include/ui/selectors.h" #include "include/scenes/menu_scene.h" #include "include/scenes/loading_scene.h" #include "include/scenes/save_state_select.h" #include "include/scenes/world_map.h" #include "include/scenes/loading_world_scene.h" #include "include/scenes/error_scene.h" #include "include/scenes/place_detail.h" #include "include/scenes/settings_scene.h" #include "music.c" #include "world.c" #include "data.c" #include "game.c" #include "scenery.c" #include "ui/panel.c" #include "ui/button.c" #include "ui/animation.c" #include "ui/portrait.c" #include "tooltip.c" #include "scenes/menu_scene.c" #include "scenes/loading_scene.c" #include "scenes/save_state_select.c" #include "scenes/world_map.c" #include "scenes/loading_world_scene.c" #include "scenes/error_scene.c" #include "scenes/place_detail.c" #include "scenes/settings_scene.c" #include "ui/selectors.c" static void draw_debug_overlay(platform_window* window) { static bool enabled = false; if (keyboard_is_key_pressed(KEY_F1)) enabled = !enabled; if (!enabled) return; renderer->set_render_depth(20); renderer->render_rectangle(0,0,200*scale,200*scale,rgb(70,70,70)); font* fnt = FONT_REGULAR(SIZE_RD(area.w, 24)); { char deltabuf[20]; sprintf(deltabuf, "Frame: %.5f", frame_delta); renderer->render_text(fnt, 10, 10, deltabuf, rgb(255,0,0)); } { char deltabuf[20]; sprintf(deltabuf, "Game: %.5f", update_delta); renderer->render_text(fnt, 10, 10+(fnt->px_h+2)*1, deltabuf, rgb(255,0,0)); } { char deltabuf[20]; sprintf(deltabuf, "FPS: %.0f", 1.0f/frame_delta); renderer->render_text(fnt, 10, 10+(fnt->px_h+2)*2, deltabuf, rgb(255,0,0)); } if (_active_world) { char deltabuf[30]; sprintf(deltabuf, "Random event: %d", _active_world->days_since_last_random_event); renderer->render_text(fnt, 10, 10+(fnt->px_h+2)*3, deltabuf, rgb(255,0,0)); } renderer->set_render_depth(19); } void update_render_game(platform_window* window) { area = camera_get_target_rectangle(window); scale = UI_SCALE(area.w); fnt_rd8 = FONT_REGULAR(SIZE_RDF(scale, 8)); fnt_rd12 = FONT_REGULAR(SIZE_RDF(scale, 12)); fnt_rd16 = FONT_REGULAR(SIZE_RDF(scale, 16)); fnt_rd20 = FONT_REGULAR(SIZE_RDF(scale, 20)); fnt_rd24 = FONT_REGULAR(SIZE_RDF(scale, 24)); fnt_rd28 = FONT_REGULAR(SIZE_RDF(scale, 28)); fnt_rd32 = FONT_REGULAR(SIZE_RDF(scale, 32)); fnt_rd36 = FONT_REGULAR(SIZE_RDF(scale, 36)); fnt_rd40 = FONT_REGULAR(SIZE_RDF(scale, 40)); fnt_rd44 = FONT_REGULAR(SIZE_RDF(scale, 44)); fnt_rd48 = FONT_REGULAR(SIZE_RDF(scale, 48)); #ifdef MODE_DEBUG draw_debug_overlay(window); #endif game_update(window); game_render(window); update_music(); } int __stdcall WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, char* ignore, int nShowCmd) { return main(__argc, __argv); } int main(int argc, char** argv) { if (!STEAM_SteamAPI_Init()) { log_info("Failed to init steam."); return 1; } if (STEAM_SteamAPI_RestartAppIfNecessary(480)) { log_info("Game required restart from Steam."); return 1; } u64 steam_id = STEAM_SteamAPI_RequestUserStats(); log_infox("User steam ID: %llu", steam_id); platform_init(argc, argv, CONFIG_DIRECTORY); #define VALIDATE_VOLUME(_vol) if (_vol < 0.0f) _vol = 0.0f; else if (_vol > 1.0f) _vol = 1.0f; volume_global = settings_get_number_or_default("v_global", 30) / 100.0f; volume_music = settings_get_number_or_default("v_music", 100) / 100.0f; volume_sfx = settings_get_number_or_default("v_sfx", 100) / 100.0f; option_vsync = settings_get_number_or_default("vsync", 1); option_fullscreen = settings_get_number_or_default("fullscreen", 1); VALIDATE_VOLUME(volume_global); VALIDATE_VOLUME(volume_music); VALIDATE_VOLUME(volume_sfx); s32 window_w = settings_get_number_or_default("window_w", 1280); s32 window_h = settings_get_number_or_default("window_h", 720); main_window = platform_open_window("TruckerX", window_w, window_h, 9999, 9999, 960, 540 + platform_get_titlebar_height(), update_render_game, 0); platform_toggle_vsync(main_window, option_vsync); if (option_fullscreen) platform_toggle_fullscreen(main_window, option_fullscreen); data_load(); game_set_active_scene(GAME_STATE_LOADING); audio_set_mixer_volume(AUDIO_CHANNEL_SFX_1, volume_sfx*volume_global); audio_set_mixer_volume(AUDIO_CHANNEL_SFX_2, volume_sfx*volume_global); double running_time = 0.0f; while(platform_keep_running(main_window)) { STEAM_SteamAPI_RunCallbacks(); main_window->do_draw = true; platform_handle_events(); running_time += frame_delta; if (running_time > 120) { // Refresh user stats every 2 min as steam will unload stats after a while and we wont be able to set achievements. running_time = 0.0f; STEAM_SteamAPI_RequestUserStats(); log_info("Refreshed Steam user stats."); } } settings_set_number("window_w", main_window->width); settings_set_number("window_h", main_window->height + platform_get_titlebar_height()); settings_set_number("v_global", volume_global*100); settings_set_number("v_music", volume_music*100); settings_set_number("v_sfx", volume_sfx*100); settings_set_number("vsync", option_vsync); settings_set_number("fullscreen", option_fullscreen); settings_write_to_file(); platform_destroy(); STEAM_SteamAPI_Shutdown(); return 0; }