diff options
| author | Aldrik Ramaekers <aldrikboy@gmail.com> | 2025-09-12 16:35:40 +0200 |
|---|---|---|
| committer | Aldrik Ramaekers <aldrikboy@gmail.com> | 2025-09-12 16:35:40 +0200 |
| commit | abf01f657d068aa6b22ab962cbe01b88f3b5f7ea (patch) | |
| tree | 2a354a6112ef0b9ef6975613f12865831f5d4a69 /libs | |
| parent | d174d803de2296061731c3698980a6a51e6fc3ef (diff) | |
event logging
Diffstat (limited to 'libs')
| -rw-r--r-- | libs/timer_lib/.gitattributes | 22 | ||||
| -rw-r--r-- | libs/timer_lib/.gitignore | 163 | ||||
| -rw-r--r-- | libs/timer_lib/Makefile | 23 | ||||
| -rw-r--r-- | libs/timer_lib/README | 37 | ||||
| -rw-r--r-- | libs/timer_lib/test.vcxproj | 169 | ||||
| -rw-r--r-- | libs/timer_lib/timer.c | 174 | ||||
| -rw-r--r-- | libs/timer_lib/timer.h | 77 | ||||
| -rw-r--r-- | libs/timer_lib/timer.sln | 36 | ||||
| -rw-r--r-- | libs/timer_lib/timer.vcxproj | 225 |
9 files changed, 926 insertions, 0 deletions
diff --git a/libs/timer_lib/.gitattributes b/libs/timer_lib/.gitattributes new file mode 100644 index 0000000..412eeda --- /dev/null +++ b/libs/timer_lib/.gitattributes @@ -0,0 +1,22 @@ +# Auto detect text files and perform LF normalization +* text=auto + +# Custom for Visual Studio +*.cs diff=csharp +*.sln merge=union +*.csproj merge=union +*.vbproj merge=union +*.fsproj merge=union +*.dbproj merge=union + +# Standard to msysgit +*.doc diff=astextplain +*.DOC diff=astextplain +*.docx diff=astextplain +*.DOCX diff=astextplain +*.dot diff=astextplain +*.DOT diff=astextplain +*.pdf diff=astextplain +*.PDF diff=astextplain +*.rtf diff=astextplain +*.RTF diff=astextplain diff --git a/libs/timer_lib/.gitignore b/libs/timer_lib/.gitignore new file mode 100644 index 0000000..5ebd21a --- /dev/null +++ b/libs/timer_lib/.gitignore @@ -0,0 +1,163 @@ +################# +## Eclipse +################# + +*.pydevproject +.project +.metadata +bin/ +tmp/ +*.tmp +*.bak +*.swp +*~.nib +local.properties +.classpath +.settings/ +.loadpath + +# External tool builders +.externalToolBuilders/ + +# Locally stored "Eclipse launch configurations" +*.launch + +# CDT-specific +.cproject + +# PDT-specific +.buildpath + + +################# +## Visual Studio +################# + +## Ignore Visual Studio temporary files, build results, and +## files generated by popular Visual Studio add-ons. + +# User-specific files +*.suo +*.user +*.sln.docstates + +# Build results +[Dd]ebug/ +[Rr]elease/ +*_i.c +*_p.c +*.ilk +*.meta +*.obj +*.pch +*.pdb +*.pgc +*.pgd +*.rsp +*.sbr +*.tlb +*.tli +*.tlh +*.tmp +*.vspscc +.builds +*.dotCover + +## TODO: If you have NuGet Package Restore enabled, uncomment this +#packages/ + +# Visual C++ cache files +ipch/ +*.aps +*.ncb +*.opensdf +*.sdf + +# Visual Studio profiler +*.psess +*.vsp + +# ReSharper is a .NET coding add-in +_ReSharper* + +# Installshield output folder +[Ee]xpress + +# DocProject is a documentation generator add-in +DocProject/buildhelp/ +DocProject/Help/*.HxT +DocProject/Help/*.HxC +DocProject/Help/*.hhc +DocProject/Help/*.hhk +DocProject/Help/*.hhp +DocProject/Help/Html2 +DocProject/Help/html + +# Click-Once directory +publish + +# Others +[Bb]in +[Oo]bj +sql +TestResults +*.Cache +ClientBin +stylecop.* +~$* +*.dbmdl +Generated_Code #added for RIA/Silverlight projects + +# Backup & report files from converting an old project file to a newer +# Visual Studio version. Backup files are not needed, because we have git ;-) +_UpgradeReport_Files/ +Backup*/ +UpgradeLog*.XML + + + +############ +## Windows +############ + +# Windows image file caches +Thumbs.db + +# Folder config file +Desktop.ini + + +############# +## Python +############# + +*.py[co] + +# Packages +*.egg +*.egg-info +dist +build +eggs +parts +bin +var +sdist +develop-eggs +.installed.cfg + +# Installer logs +pip-log.txt + +# Unit test / coverage reports +.coverage +.tox + +#Translations +*.mo + +#Mr Developer +.mr.developer.cfg + +# Mac crap +.DS_Store diff --git a/libs/timer_lib/Makefile b/libs/timer_lib/Makefile new file mode 100644 index 0000000..3edaf73 --- /dev/null +++ b/libs/timer_lib/Makefile @@ -0,0 +1,23 @@ +SRC = timer.c +OBJ = $(SRC:.c=.o) +OUT = libtimer.a +TST = timertest +TSR = test.c +TOB = $(TSR:.c=.o) + +CFLAGS = -O3 +LDFLAGS = + +default: $(OUT) $(TST) + +.c.o: + gcc $(CFLAGS) -c $< -o $@ + +$(OUT): $(OBJ) + ar rcs $(OUT) $(OBJ) + +$(TST): $(OUT) $(TOB) + gcc $(CFLAGS) $(LDFLAGS) -o $(TST) $(TOB) $(OUT) -lrt + +clean: + rm -f $(OBJ) $(OUT) $(TOB) $(TST) diff --git a/libs/timer_lib/README b/libs/timer_lib/README new file mode 100644 index 0000000..16f604b --- /dev/null +++ b/libs/timer_lib/README @@ -0,0 +1,37 @@ +timer_lib - v1.0 - Public Domain - 2011 Mattias Jansson + +This library provides a cross-platform interface to measure +elapsed time with (at least) millisecond accuracy. The latest +source code is always available at + +https://github.com/mjansson/timer_lib + +This library is put in the public domain; you can redistribute +it and/or modify it without any restrictions. + +For a complete cross-platform application framework, look at +the foundation library available at + +https://github.com/mjansson/foundation_lib + + +VERSION HISTORY + + 0.1 (2011-03-15) Initial release + 0.2 (2011-03-20) Removed timer type (always high precision) + Fixed timer_ticks_per_second declaration + Added test application + 0.3 (2011-03-22) Removed unused error checks in POSIX code + Made timeGetTime fallback optional in Windows code (define USE_FALLBACK to 1) + Fixed check of QPC weirdness (signed issue) + 0.4 (2011-03-23) timer_lib_initialize() returns non-zero if failed (no high precision timer available) + Changed POSIX path to use CLOCK_MONOTONIC + POSIX timer_system use CLOCK_REALTIME for actual timestamp + Addded Mach-O path for MacOS X + Changed POSIX path to use nanosecond frequency as returned by clock_gettime + 0.5 (2012-10-01) Merged (cleaned up) MacOSX build fixes from Nicolas Léveillé + 0.6 (2013-01-11) Simplified API, only using tick_t type as timestamp and removing custom timer struct + Removed old legacy fallback code for Windows platform + 0.7 (2013-01-11) Using platform_lib for platform and compiler abstraction + 0.8 (2013-07-30) Made library standalone with no deps (not using deprecated platform_lib) + 1.0 (2021-12-15) Updated and cleaned up for clang 10+ and Visual Studio 2022 diff --git a/libs/timer_lib/test.vcxproj b/libs/timer_lib/test.vcxproj new file mode 100644 index 0000000..468b70e --- /dev/null +++ b/libs/timer_lib/test.vcxproj @@ -0,0 +1,169 @@ +<?xml version="1.0" encoding="utf-8"?> +<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> + <ItemGroup Label="ProjectConfigurations"> + <ProjectConfiguration Include="Debug|Win32"> + <Configuration>Debug</Configuration> + <Platform>Win32</Platform> + </ProjectConfiguration> + <ProjectConfiguration Include="Debug|x64"> + <Configuration>Debug</Configuration> + <Platform>x64</Platform> + </ProjectConfiguration> + <ProjectConfiguration Include="Release|Win32"> + <Configuration>Release</Configuration> + <Platform>Win32</Platform> + </ProjectConfiguration> + <ProjectConfiguration Include="Release|x64"> + <Configuration>Release</Configuration> + <Platform>x64</Platform> + </ProjectConfiguration> + </ItemGroup> + <PropertyGroup Label="Globals"> + <ProjectGuid>{54E95B82-7759-4825-9478-91E76F1C1C89}</ProjectGuid> + <Keyword>Win32Proj</Keyword> + <RootNamespace>test</RootNamespace> + <WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion> + </PropertyGroup> + <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" /> + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration"> + <ConfigurationType>Application</ConfigurationType> + <UseDebugLibraries>true</UseDebugLibraries> + <CharacterSet>Unicode</CharacterSet> + <PlatformToolset>v143</PlatformToolset> + </PropertyGroup> + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration"> + <ConfigurationType>Application</ConfigurationType> + <UseDebugLibraries>true</UseDebugLibraries> + <CharacterSet>Unicode</CharacterSet> + <PlatformToolset>v143</PlatformToolset> + </PropertyGroup> + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration"> + <ConfigurationType>Application</ConfigurationType> + <UseDebugLibraries>false</UseDebugLibraries> + <WholeProgramOptimization>true</WholeProgramOptimization> + <CharacterSet>Unicode</CharacterSet> + <PlatformToolset>v143</PlatformToolset> + </PropertyGroup> + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration"> + <ConfigurationType>Application</ConfigurationType> + <UseDebugLibraries>false</UseDebugLibraries> + <WholeProgramOptimization>true</WholeProgramOptimization> + <CharacterSet>Unicode</CharacterSet> + <PlatformToolset>v143</PlatformToolset> + </PropertyGroup> + <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" /> + <ImportGroup Label="ExtensionSettings"> + </ImportGroup> + <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> + <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> + </ImportGroup> + <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="PropertySheets"> + <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> + </ImportGroup> + <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> + <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> + </ImportGroup> + <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="PropertySheets"> + <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> + </ImportGroup> + <PropertyGroup Label="UserMacros" /> + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> + <LinkIncremental>true</LinkIncremental> + </PropertyGroup> + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"> + <LinkIncremental>true</LinkIncremental> + <OutDir>build\$(ProjectName)\$(Platform)\$(Configuration)\</OutDir> + <IntDir>build\$(ProjectName)\$(Platform)\$(Configuration)\</IntDir> + </PropertyGroup> + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> + <LinkIncremental>false</LinkIncremental> + </PropertyGroup> + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> + <LinkIncremental>false</LinkIncremental> + <OutDir>build\$(ProjectName)\$(Platform)\$(Configuration)\</OutDir> + <IntDir>build\$(ProjectName)\$(Platform)\$(Configuration)\</IntDir> + </PropertyGroup> + <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> + <ClCompile> + <PrecompiledHeader> + </PrecompiledHeader> + <WarningLevel>Level3</WarningLevel> + <Optimization>Disabled</Optimization> + <PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions> + <RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary> + <AdditionalIncludeDirectories>../platform_lib</AdditionalIncludeDirectories> + </ClCompile> + <Link> + <SubSystem>Console</SubSystem> + <GenerateDebugInformation>true</GenerateDebugInformation> + <AdditionalDependencies>winmm.lib;%(AdditionalDependencies)</AdditionalDependencies> + </Link> + </ItemDefinitionGroup> + <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"> + <ClCompile> + <PrecompiledHeader> + </PrecompiledHeader> + <WarningLevel>Level3</WarningLevel> + <Optimization>Disabled</Optimization> + <PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions> + <RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary> + <AdditionalIncludeDirectories>../platform_lib</AdditionalIncludeDirectories> + </ClCompile> + <Link> + <SubSystem>Console</SubSystem> + <GenerateDebugInformation>true</GenerateDebugInformation> + <AdditionalDependencies>winmm.lib;%(AdditionalDependencies)</AdditionalDependencies> + </Link> + </ItemDefinitionGroup> + <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> + <ClCompile> + <WarningLevel>Level3</WarningLevel> + <PrecompiledHeader> + </PrecompiledHeader> + <Optimization>MaxSpeed</Optimization> + <FunctionLevelLinking>true</FunctionLevelLinking> + <IntrinsicFunctions>true</IntrinsicFunctions> + <PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions> + <RuntimeLibrary>MultiThreaded</RuntimeLibrary> + <AdditionalIncludeDirectories>../platform_lib</AdditionalIncludeDirectories> + </ClCompile> + <Link> + <SubSystem>Console</SubSystem> + <GenerateDebugInformation>true</GenerateDebugInformation> + <EnableCOMDATFolding>true</EnableCOMDATFolding> + <OptimizeReferences>true</OptimizeReferences> + <AdditionalDependencies>winmm.lib;%(AdditionalDependencies)</AdditionalDependencies> + </Link> + </ItemDefinitionGroup> + <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> + <ClCompile> + <WarningLevel>Level3</WarningLevel> + <PrecompiledHeader> + </PrecompiledHeader> + <Optimization>MaxSpeed</Optimization> + <FunctionLevelLinking>true</FunctionLevelLinking> + <IntrinsicFunctions>true</IntrinsicFunctions> + <PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions> + <RuntimeLibrary>MultiThreaded</RuntimeLibrary> + <AdditionalIncludeDirectories>../platform_lib</AdditionalIncludeDirectories> + </ClCompile> + <Link> + <SubSystem>Console</SubSystem> + <GenerateDebugInformation>true</GenerateDebugInformation> + <EnableCOMDATFolding>true</EnableCOMDATFolding> + <OptimizeReferences>true</OptimizeReferences> + <AdditionalDependencies>winmm.lib;%(AdditionalDependencies)</AdditionalDependencies> + </Link> + </ItemDefinitionGroup> + <ItemGroup> + <ClCompile Include="test.c" /> + </ItemGroup> + <ItemGroup> + <ProjectReference Include="timer.vcxproj"> + <Project>{321bab92-2ede-4b3b-939d-bd0be0248c8f}</Project> + </ProjectReference> + </ItemGroup> + <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> + <ImportGroup Label="ExtensionTargets"> + </ImportGroup> +</Project>
\ No newline at end of file diff --git a/libs/timer_lib/timer.c b/libs/timer_lib/timer.c new file mode 100644 index 0000000..dd6434c --- /dev/null +++ b/libs/timer_lib/timer.c @@ -0,0 +1,174 @@ +/* timer.h - Cross-platform timer library - Public Domain - 2011 Mattias Jansson / Rampant Pixels + * + * This library provides a cross-platform interface to measure + * elapsed time with (at least) millisecond accuracy. + * + * This library is put in the public domain; you can redistribute + * it and/or modify it without any restrictions. + * + */ + +#include "timer.h" + +#define TIMER_PLATFORM_WINDOWS 0 +#define TIMER_PLATFORM_APPLE 0 +#define TIMER_PLATFORM_POSIX 0 + +#if defined( _WIN32 ) || defined( _WIN64 ) +# undef TIMER_PLATFORM_WINDOWS +# define TIMER_PLATFORM_WINDOWS 1 +# define WIN32_LEAN_AND_MEAN +# include <windows.h> +#elif defined( __APPLE__ ) +# undef TIMER_PLATFORM_APPLE +# define TIMER_PLATFORM_APPLE 1 +# include <mach/mach_time.h> +# include <string.h> +static mach_timebase_info_data_t timerlib_info; +static void absolutetime_to_nanoseconds (uint64_t mach_time, uint64_t* clock ) { *clock = mach_time * timerlib_info.numer / timerlib_info.denom; } +#else +# undef TIMER_PLATFORM_POSIX +# define TIMER_PLATFORM_POSIX 1 +# include <unistd.h> +# include <time.h> +# include <string.h> +#endif + +static tick_t timerlib_freq = 0; +static double timerlib_oofreq = 0; + + +int timer_lib_initialize( void ) +{ +#if TIMER_PLATFORM_WINDOWS + tick_t unused; + if( !QueryPerformanceFrequency( (LARGE_INTEGER*)&timerlib_freq ) || + !QueryPerformanceCounter( (LARGE_INTEGER*)&unused ) ) + return -1; +#elif TIMER_PLATFORM_APPLE + if( mach_timebase_info( &timerlib_info ) ) + return -1; + timerlib_freq = 1000000000ULL; +#elif TIMER_PLATFORM_POSIX + struct timespec ts = { .tv_sec = 0, .tv_nsec = 0 }; + if( clock_gettime( CLOCK_MONOTONIC, &ts ) ) + return -1; + timerlib_freq = 1000000000ULL; +#endif + + timerlib_oofreq = 1.0 / (double)timerlib_freq; + + return 0; +} + + +void timer_lib_shutdown( void ) +{ +} + + +tick_t timer_current( void ) +{ +#if TIMER_PLATFORM_WINDOWS + + tick_t curclock; + QueryPerformanceCounter( (LARGE_INTEGER*)&curclock ); + return curclock; + +#elif TIMER_PLATFORM_APPLE + + tick_t curclock = 0; + absolutetime_to_nanoseconds( mach_absolute_time(), &curclock ); + return curclock; + +#elif TIMER_PLATFORM_POSIX + + struct timespec ts = { .tv_sec = 0, .tv_nsec = 0 }; + clock_gettime( CLOCK_MONOTONIC, &ts ); + return ( (uint64_t)ts.tv_sec * 1000000000ULL ) + ts.tv_nsec; + +#endif +} + + +tick_t timer_ticks_per_second( void ) +{ + return timerlib_freq; +} + + +deltatime_t timer_elapsed( const tick_t t ) +{ + return (deltatime_t)( (double)timer_elapsed_ticks( t ) * timerlib_oofreq ); +} + + +tick_t timer_elapsed_ticks( const tick_t t ) +{ + tick_t dt = 0; + +#if TIMER_PLATFORM_WINDOWS + + tick_t curclock = t; + QueryPerformanceCounter( (LARGE_INTEGER*)&curclock ); + dt = curclock - t; + +#elif TIMER_PLATFORM_APPLE + + tick_t curclock = t; + absolutetime_to_nanoseconds( mach_absolute_time(), &curclock ); + dt = curclock - t; + +#elif TIMER_PLATFORM_POSIX + + tick_t curclock; + struct timespec ts = { .tv_sec = 0, .tv_nsec = 0 }; + clock_gettime( CLOCK_MONOTONIC, &ts ); + + curclock = ( (tick_t)ts.tv_sec * 1000000000ULL ) + ts.tv_nsec; + dt = curclock - t; + +#endif + + return dt; +} + + +deltatime_t timer_ticks_to_seconds( const tick_t dt ) +{ + return (deltatime_t)( (double)dt * timerlib_oofreq ); +} + + +#if TIMER_PLATFORM_WINDOWS +struct __timeb64 { + __time64_t time; + unsigned short millitm; + short timezone; + short dstflag; + }; +_CRTIMP errno_t __cdecl _ftime64_s(_Out_ struct __timeb64 * _Time); +#endif + +tick_t timer_system( void ) +{ +#if TIMER_PLATFORM_WINDOWS + + struct __timeb64 tb; + _ftime64_s( &tb ); + return ( (tick_t)tb.time * 1000ULL ) + (tick_t)tb.millitm; + +#elif TIMER_PLATFORM_APPLE + + tick_t curclock = 0; + absolutetime_to_nanoseconds( mach_absolute_time(), &curclock ); + return ( curclock / 1000000ULL ); + +#elif TIMER_PLATFORM_POSIX + + struct timespec ts = { .tv_sec = 0, .tv_nsec = 0 }; + clock_gettime( CLOCK_REALTIME, &ts ); + return ( (uint64_t)ts.tv_sec * 1000ULL ) + ( ts.tv_nsec / 1000000ULL ); + +#endif +} diff --git a/libs/timer_lib/timer.h b/libs/timer_lib/timer.h new file mode 100644 index 0000000..c7d8bba --- /dev/null +++ b/libs/timer_lib/timer.h @@ -0,0 +1,77 @@ +/* timer.h - Cross-platform timer library - Public Domain - 2011 Mattias Jansson / Rampant Pixels + * + * This library provides a cross-platform interface to measure + * elapsed time with (at least) millisecond accuracy. + * + * This library is put in the public domain; you can redistribute + * it and/or modify it without any restrictions. + * + */ + +#pragma once + +/*! \file timer.h + Time measurements */ + +#if TIMER_COMPILE +#define TIMER_API +#else +#if __cplusplus +#define TIMER_API extern "C" +#else +#define TIMER_API extern +#endif +#endif + +#if defined( _WIN32 ) || defined( _WIN64 ) + +//! Tick type +typedef unsigned __int64 tick_t; + +#else + +#include <stdint.h> +//! Tick type +typedef uint64_t tick_t; + +#endif + +//! Deltatime type (float or double) +//typedef float deltatime_t; +typedef double deltatime_t; + + +/*! Initialize timer library */ +TIMER_API int timer_lib_initialize( void ); + +/*! Shutdown timer library */ +TIMER_API void timer_lib_shutdown( void ); + +/*! Get current timestamp, in ticks of system-specific frequency (queryable with timer_ticks_per_second), measured from some system-specific base timestamp + and not in sync with other timestamps + \return Current timestamp */ +TIMER_API tick_t timer_current( void ); + +/*! Get elapsed time since given timestamp + \param t Timestamp + \return Number of seconds elapsed */ +TIMER_API deltatime_t timer_elapsed( const tick_t t ); + +/*! Get elapsed ticks since given timestamp + \param t Timestamp + \return Number of ticks elapsed */ +TIMER_API tick_t timer_elapsed_ticks( const tick_t t ); + +/*! Get timer frequency, as number of ticks per second + \return Ticks per second */ +TIMER_API tick_t timer_ticks_per_second( void ); + +/*! Get ticks as seconds (effectively calculating ticks/timer_ticks_per_second()) + \param dt Deltatime in ticks + \return Deltatime in seconds */ +TIMER_API deltatime_t timer_ticks_to_seconds( const tick_t dt ); + +/*! Get system time, in milliseconds since the epoch (UNIX time) + \return Current timestamp, in milliseconds */ +TIMER_API tick_t timer_system( void ); + diff --git a/libs/timer_lib/timer.sln b/libs/timer_lib/timer.sln new file mode 100644 index 0000000..0146411 --- /dev/null +++ b/libs/timer_lib/timer.sln @@ -0,0 +1,36 @@ + +Microsoft Visual Studio Solution File, Format Version 11.00 +# Visual Studio 2010 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "timer", "timer.vcxproj", "{321BAB92-2EDE-4B3B-939D-BD0BE0248C8F}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "test", "test.vcxproj", "{54E95B82-7759-4825-9478-91E76F1C1C89}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Win32 = Debug|Win32 + Debug|x64 = Debug|x64 + Release|Win32 = Release|Win32 + Release|x64 = Release|x64 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {321BAB92-2EDE-4B3B-939D-BD0BE0248C8F}.Debug|Win32.ActiveCfg = Debug|Win32 + {321BAB92-2EDE-4B3B-939D-BD0BE0248C8F}.Debug|Win32.Build.0 = Debug|Win32 + {321BAB92-2EDE-4B3B-939D-BD0BE0248C8F}.Debug|x64.ActiveCfg = Debug|x64 + {321BAB92-2EDE-4B3B-939D-BD0BE0248C8F}.Debug|x64.Build.0 = Debug|x64 + {321BAB92-2EDE-4B3B-939D-BD0BE0248C8F}.Release|Win32.ActiveCfg = Release|Win32 + {321BAB92-2EDE-4B3B-939D-BD0BE0248C8F}.Release|Win32.Build.0 = Release|Win32 + {321BAB92-2EDE-4B3B-939D-BD0BE0248C8F}.Release|x64.ActiveCfg = Release|x64 + {321BAB92-2EDE-4B3B-939D-BD0BE0248C8F}.Release|x64.Build.0 = Release|x64 + {54E95B82-7759-4825-9478-91E76F1C1C89}.Debug|Win32.ActiveCfg = Debug|Win32 + {54E95B82-7759-4825-9478-91E76F1C1C89}.Debug|Win32.Build.0 = Debug|Win32 + {54E95B82-7759-4825-9478-91E76F1C1C89}.Debug|x64.ActiveCfg = Debug|x64 + {54E95B82-7759-4825-9478-91E76F1C1C89}.Debug|x64.Build.0 = Debug|x64 + {54E95B82-7759-4825-9478-91E76F1C1C89}.Release|Win32.ActiveCfg = Release|Win32 + {54E95B82-7759-4825-9478-91E76F1C1C89}.Release|Win32.Build.0 = Release|Win32 + {54E95B82-7759-4825-9478-91E76F1C1C89}.Release|x64.ActiveCfg = Release|x64 + {54E95B82-7759-4825-9478-91E76F1C1C89}.Release|x64.Build.0 = Release|x64 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/libs/timer_lib/timer.vcxproj b/libs/timer_lib/timer.vcxproj new file mode 100644 index 0000000..83e5ded --- /dev/null +++ b/libs/timer_lib/timer.vcxproj @@ -0,0 +1,225 @@ +<?xml version="1.0" encoding="utf-8"?> +<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> + <ItemGroup Label="ProjectConfigurations"> + <ProjectConfiguration Include="Debug|Win32"> + <Configuration>Debug</Configuration> + <Platform>Win32</Platform> + </ProjectConfiguration> + <ProjectConfiguration Include="Debug|x64"> + <Configuration>Debug</Configuration> + <Platform>x64</Platform> + </ProjectConfiguration> + <ProjectConfiguration Include="Release|Win32"> + <Configuration>Release</Configuration> + <Platform>Win32</Platform> + </ProjectConfiguration> + <ProjectConfiguration Include="Release|x64"> + <Configuration>Release</Configuration> + <Platform>x64</Platform> + </ProjectConfiguration> + </ItemGroup> + <ItemGroup> + <ClCompile Include="timer.c" /> + </ItemGroup> + <ItemGroup> + <ClInclude Include="timer.h" /> + </ItemGroup> + <PropertyGroup Label="Globals"> + <ProjectGuid>{321BAB92-2EDE-4B3B-939D-BD0BE0248C8F}</ProjectGuid> + <Keyword>Win32Proj</Keyword> + <RootNamespace>timer</RootNamespace> + <WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion> + </PropertyGroup> + <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" /> + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration"> + <ConfigurationType>StaticLibrary</ConfigurationType> + <UseDebugLibraries>true</UseDebugLibraries> + <CharacterSet>Unicode</CharacterSet> + <PlatformToolset>v143</PlatformToolset> + </PropertyGroup> + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration"> + <ConfigurationType>StaticLibrary</ConfigurationType> + <UseDebugLibraries>true</UseDebugLibraries> + <CharacterSet>Unicode</CharacterSet> + <PlatformToolset>v143</PlatformToolset> + </PropertyGroup> + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration"> + <ConfigurationType>StaticLibrary</ConfigurationType> + <UseDebugLibraries>false</UseDebugLibraries> + <WholeProgramOptimization>true</WholeProgramOptimization> + <CharacterSet>Unicode</CharacterSet> + <PlatformToolset>v143</PlatformToolset> + </PropertyGroup> + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration"> + <ConfigurationType>StaticLibrary</ConfigurationType> + <UseDebugLibraries>false</UseDebugLibraries> + <WholeProgramOptimization>true</WholeProgramOptimization> + <CharacterSet>Unicode</CharacterSet> + <PlatformToolset>v143</PlatformToolset> + </PropertyGroup> + <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" /> + <ImportGroup Label="ExtensionSettings"> + </ImportGroup> + <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> + <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> + </ImportGroup> + <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="PropertySheets"> + <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> + </ImportGroup> + <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> + <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> + </ImportGroup> + <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="PropertySheets"> + <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> + </ImportGroup> + <PropertyGroup Label="UserMacros" /> + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> + <OutDir>$(SolutionDir)</OutDir> + <IntDir>$(Platform)\$(Configuration)\</IntDir> + <TargetName>$(ProjectName)32d</TargetName> + </PropertyGroup> + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"> + <OutDir>$(SolutionDir)</OutDir> + <IntDir>build\$(ProjectName)\$(Platform)\$(Configuration)\</IntDir> + <TargetName>$(ProjectName)64d</TargetName> + </PropertyGroup> + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> + <OutDir>$(SolutionDir)</OutDir> + <IntDir>$(Platform)\$(Configuration)\</IntDir> + <TargetName>$(ProjectName)32</TargetName> + </PropertyGroup> + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> + <OutDir>$(SolutionDir)</OutDir> + <IntDir>build\$(ProjectName)\$(Platform)\$(Configuration)\</IntDir> + <TargetName>$(ProjectName)64</TargetName> + </PropertyGroup> + <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> + <ClCompile> + <PrecompiledHeader> + </PrecompiledHeader> + <WarningLevel>Level3</WarningLevel> + <Optimization>Disabled</Optimization> + <PreprocessorDefinitions>TIMER_COMPILE;%(PreprocessorDefinitions)</PreprocessorDefinitions> + <DebugInformationFormat>ProgramDatabase</DebugInformationFormat> + <CompileAsManaged>false</CompileAsManaged> + <MultiProcessorCompilation>false</MultiProcessorCompilation> + <OmitFramePointers>false</OmitFramePointers> + <StringPooling>false</StringPooling> + <MinimalRebuild>false</MinimalRebuild> + <ExceptionHandling>false</ExceptionHandling> + <RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary> + <FunctionLevelLinking>false</FunctionLevelLinking> + <FloatingPointModel>Fast</FloatingPointModel> + <FloatingPointExceptions>false</FloatingPointExceptions> + <CreateHotpatchableImage>false</CreateHotpatchableImage> + <RuntimeTypeInfo>false</RuntimeTypeInfo> + <OpenMPSupport>false</OpenMPSupport> + <AdditionalIncludeDirectories> + </AdditionalIncludeDirectories> + </ClCompile> + <Link> + <SubSystem>Windows</SubSystem> + <GenerateDebugInformation>true</GenerateDebugInformation> + </Link> + </ItemDefinitionGroup> + <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"> + <ClCompile> + <PrecompiledHeader> + </PrecompiledHeader> + <WarningLevel>Level3</WarningLevel> + <Optimization>Disabled</Optimization> + <PreprocessorDefinitions>TIMER_COMPILE;%(PreprocessorDefinitions)</PreprocessorDefinitions> + <DebugInformationFormat>ProgramDatabase</DebugInformationFormat> + <CompileAsManaged>false</CompileAsManaged> + <MultiProcessorCompilation>false</MultiProcessorCompilation> + <OmitFramePointers>false</OmitFramePointers> + <StringPooling>false</StringPooling> + <MinimalRebuild>false</MinimalRebuild> + <ExceptionHandling>false</ExceptionHandling> + <RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary> + <FunctionLevelLinking>false</FunctionLevelLinking> + <FloatingPointModel>Fast</FloatingPointModel> + <FloatingPointExceptions>false</FloatingPointExceptions> + <CreateHotpatchableImage>false</CreateHotpatchableImage> + <RuntimeTypeInfo>false</RuntimeTypeInfo> + <OpenMPSupport>false</OpenMPSupport> + <AdditionalIncludeDirectories> + </AdditionalIncludeDirectories> + </ClCompile> + <Link> + <SubSystem>Windows</SubSystem> + <GenerateDebugInformation>true</GenerateDebugInformation> + </Link> + </ItemDefinitionGroup> + <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> + <ClCompile> + <WarningLevel>Level3</WarningLevel> + <PrecompiledHeader> + </PrecompiledHeader> + <Optimization>MaxSpeed</Optimization> + <FunctionLevelLinking>false</FunctionLevelLinking> + <IntrinsicFunctions>true</IntrinsicFunctions> + <PreprocessorDefinitions>TIMER_COMPILE;%(PreprocessorDefinitions)</PreprocessorDefinitions> + <DebugInformationFormat>ProgramDatabase</DebugInformationFormat> + <CompileAsManaged>false</CompileAsManaged> + <MultiProcessorCompilation>false</MultiProcessorCompilation> + <FavorSizeOrSpeed>Speed</FavorSizeOrSpeed> + <OmitFramePointers>false</OmitFramePointers> + <EnableFiberSafeOptimizations>true</EnableFiberSafeOptimizations> + <StringPooling>true</StringPooling> + <ExceptionHandling>false</ExceptionHandling> + <RuntimeLibrary>MultiThreaded</RuntimeLibrary> + <BufferSecurityCheck>false</BufferSecurityCheck> + <FloatingPointModel>Fast</FloatingPointModel> + <FloatingPointExceptions>false</FloatingPointExceptions> + <CreateHotpatchableImage>false</CreateHotpatchableImage> + <RuntimeTypeInfo>false</RuntimeTypeInfo> + <OpenMPSupport>false</OpenMPSupport> + <AdditionalIncludeDirectories> + </AdditionalIncludeDirectories> + </ClCompile> + <Link> + <SubSystem>Windows</SubSystem> + <GenerateDebugInformation>true</GenerateDebugInformation> + <EnableCOMDATFolding>true</EnableCOMDATFolding> + <OptimizeReferences>true</OptimizeReferences> + </Link> + </ItemDefinitionGroup> + <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> + <ClCompile> + <WarningLevel>Level3</WarningLevel> + <PrecompiledHeader> + </PrecompiledHeader> + <Optimization>MaxSpeed</Optimization> + <FunctionLevelLinking>false</FunctionLevelLinking> + <IntrinsicFunctions>true</IntrinsicFunctions> + <PreprocessorDefinitions>TIMER_COMPILE;%(PreprocessorDefinitions)</PreprocessorDefinitions> + <DebugInformationFormat>ProgramDatabase</DebugInformationFormat> + <CompileAsManaged>false</CompileAsManaged> + <MultiProcessorCompilation>false</MultiProcessorCompilation> + <FavorSizeOrSpeed>Speed</FavorSizeOrSpeed> + <OmitFramePointers>false</OmitFramePointers> + <EnableFiberSafeOptimizations>true</EnableFiberSafeOptimizations> + <StringPooling>true</StringPooling> + <ExceptionHandling>false</ExceptionHandling> + <RuntimeLibrary>MultiThreaded</RuntimeLibrary> + <BufferSecurityCheck>false</BufferSecurityCheck> + <FloatingPointModel>Fast</FloatingPointModel> + <FloatingPointExceptions>false</FloatingPointExceptions> + <CreateHotpatchableImage>false</CreateHotpatchableImage> + <RuntimeTypeInfo>false</RuntimeTypeInfo> + <OpenMPSupport>false</OpenMPSupport> + <AdditionalIncludeDirectories> + </AdditionalIncludeDirectories> + </ClCompile> + <Link> + <SubSystem>Windows</SubSystem> + <GenerateDebugInformation>true</GenerateDebugInformation> + <EnableCOMDATFolding>true</EnableCOMDATFolding> + <OptimizeReferences>true</OptimizeReferences> + </Link> + </ItemDefinitionGroup> + <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> + <ImportGroup Label="ExtensionTargets"> + </ImportGroup> +</Project>
\ No newline at end of file |
