summaryrefslogtreecommitdiff
path: root/src/main.c
diff options
context:
space:
mode:
authorAldrik Ramaekers <aldrikboy@gmail.com>2024-12-05 11:42:11 +0100
committerAldrik Ramaekers <aldrikboy@gmail.com>2024-12-05 11:42:11 +0100
commit0974ff30789a215a31255080251c01eaaf9a5297 (patch)
treeeda0b28d3e1aee2ca17d0f433c00574809e205d9 /src/main.c
parent190760b05d943e065cad31a0b983ef7736551feb (diff)
link with steam sdk and create bindings
Diffstat (limited to 'src/main.c')
-rw-r--r--src/main.c27
1 files changed, 27 insertions, 0 deletions
diff --git a/src/main.c b/src/main.c
index e93a4da..159dcc7 100644
--- a/src/main.c
+++ b/src/main.c
@@ -29,6 +29,8 @@ 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"
@@ -144,6 +146,19 @@ int __stdcall WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, char* ignore
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;
@@ -174,9 +189,19 @@ int main(int argc, char** argv)
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);
@@ -190,5 +215,7 @@ int main(int argc, char** argv)
settings_write_to_file();
platform_destroy();
+ STEAM_SteamAPI_Shutdown();
+
return 0;
} \ No newline at end of file