Skip to content

Commit 6ef9cb9

Browse files
Add SDL_time.inc
1 parent a038a91 commit 6ef9cb9

File tree

3 files changed

+350
-0
lines changed

3 files changed

+350
-0
lines changed

units/SDL3.pas

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ interface
9393
{$I SDL_clipboard.inc} // 3.2.0
9494
{$I SDL_cpuinfo.inc} // 3.2.0
9595
{$I SDL_dialog.inc} // 3.2.0
96+
{$I SDL_time.inc} // 3.2.0
9697

9798

9899
implementation

units/SDL_stdinc.inc

Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,142 @@
66
SPDX-License-Identifier: Zlib
77
}
88

9+
{*
10+
* A signed 8-bit integer type.
11+
*
12+
* \since This macro is available since SDL 3.2.0.
13+
}
14+
type
15+
ppcint8_t=^pcint8_t;
16+
pcint8_t=^cint8_t;
17+
cint8_t=cint8;
18+
const
19+
SDL_MAX_SINT8=cint8($7F); { 127 }
20+
SDL_MIN_SINT8=cint8(not ($7F)); { -128 }
21+
22+
{*
23+
* An unsigned 8-bit integer type.
24+
*
25+
* \since This macro is available since SDL 3.2.0.
26+
}
27+
type
28+
ppcuint8_t=^pcuint8_t;
29+
pcuint8_t=^cuint8_t;
30+
cuint8_t=cuint8;
31+
const
32+
SDL_MAX_UINT8=cuint8($FF); { 255 }
33+
SDL_MIN_UINT8=cuint8($00); { 0 }
34+
35+
{*
36+
* A signed 16-bit integer type.
37+
*
38+
* \since This macro is available since SDL 3.2.0.
39+
}
40+
type
41+
ppcint16_t=^pcint16_t;
42+
pcint16_t=^cint16_t;
43+
cint16_t=cint16;
44+
const
45+
SDL_MAX_SINT16=cint16($7FFF); { 32767 }
46+
SDL_MIN_SINT16=cint16(not ($7FFF)); { -32768 }
47+
48+
{*
49+
* An unsigned 16-bit integer type.
50+
*
51+
* \since This macro is available since SDL 3.2.0.
52+
}
53+
type
54+
ppcuint16_t=^pcuint16_t;
55+
pcuint16_t=^cuint16_t;
56+
cuint16_t=cuint16;
57+
const
58+
SDL_MAX_UINT16=cuint16($FFFF); { 65535 }
59+
SDL_MIN_UINT16=cuint16($0000); { 0 }
60+
61+
{*
62+
* A signed 32-bit integer type.
63+
*
64+
* \since This macro is available since SDL 3.2.0.
65+
}
66+
type
67+
ppcint32_t=^pcint32_t;
68+
pcint32_t=^cint32_t;
69+
cint32_t=cint32;
70+
const
71+
SDL_MAX_SINT32=cint32($7FFFFFFF); { 2147483647 }
72+
SDL_MIN_SINT32=cint32(not ($7FFFFFFF)); { -2147483648 }
73+
74+
{*
75+
* An unsigned 32-bit integer type.
76+
*
77+
* \since This macro is available since SDL 3.2.0.
78+
}
79+
type
80+
ppcuint32_t=^pcuint32_t;
81+
pcuint32_t=^cuint32_t;
82+
cuint32_t=cuint32;
83+
const
84+
SDL_MAX_UINT32=cuint32($FFFFFFFF); { 4294967295 }
85+
SDL_MIN_UINT32=cuint32($00000000); { 0 }
86+
87+
{*
88+
* A signed 64-bit integer type.
89+
*
90+
* \since This macro is available since SDL 3.2.0.
91+
*
92+
* \sa SDL_SINT64_C
93+
}
94+
type
95+
ppcint64_t=^pcint64_t;
96+
pcint64_t=^cint64_t;
97+
cint64_t=cint64;
98+
const
99+
{ #note : SDL3-for-Pascal:
100+
The macro SDL_SINT64_C converts the values to guarantee their size.
101+
We do this simply by converting to cint64 here. }
102+
SDL_MAX_SINT64=cint64($7FFFFFFFFFFFFFFF); { 9223372036854775807 }
103+
SDL_MIN_SINT64= not (cint64($7FFFFFFFFFFFFFFF)); { -9223372036854775808 }
104+
105+
{*
106+
* An unsigned 64-bit integer type.
107+
*
108+
* \since This macro is available since SDL 3.2.0.
109+
*
110+
* \sa SDL_UINT64_C
111+
}
112+
type
113+
ppcuint64_t=^pcuint64_t;
114+
pcuint64_t=^cuint64_t;
115+
cuint64_t=cuint64;
116+
const
117+
{ #note : SDL3-for-Pascal:
118+
The macro SDL_SUINT64_C converts the values to guarantee their size.
119+
We do this simply by converting to cuint64 here. }
120+
SDL_MAX_UINT64=cuint64($FFFFFFFFFFFFFFFF); { 18446744073709551615 }
121+
SDL_MIN_UINT64=cuint64($0000000000000000); { 0 }
122+
123+
{*
124+
* SDL times are signed, 64-bit integers representing nanoseconds since the
125+
* Unix epoch (Jan 1, 1970).
126+
*
127+
* They can be converted between POSIX time_t values with SDL_NS_TO_SECONDS()
128+
* and SDL_SECONDS_TO_NS(), and between Windows FILETIME values with
129+
* SDL_TimeToWindows() and SDL_TimeFromWindows().
130+
*
131+
* \since This macro is available since SDL 3.2.0.
132+
*
133+
* \sa SDL_MAX_SINT64
134+
* \sa SDL_MIN_SINT64
135+
}
136+
type
137+
PPSDL_Time = ^PSDL_Time;
138+
PSDL_Time = ^TSDL_Time;
139+
TSDL_Time = cint64;
140+
141+
const
142+
SDL_MAX_TIME = SDL_MAX_SINT64;
143+
SDL_MIN_TIME = SDL_MIN_SINT64;
144+
9145
{*
10146
* Epsilon constant, used for comparing floating-point numbers.
11147
*

units/SDL_time.inc

Lines changed: 213 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,213 @@
1+
{
2+
This file is part of:
3+
4+
SDL3 for Pascal
5+
(https://github.com/PascalGameDevelopment/SDL3-for-Pascal)
6+
SPDX-License-Identifier: Zlib
7+
}
8+
9+
{*
10+
* # CategoryTime
11+
*
12+
* SDL realtime clock and date/time routines.
13+
*
14+
* There are two data types that are used in this category: SDL_Time, which
15+
* represents the nanoseconds since a specific moment (an "epoch"), and
16+
* SDL_DateTime, which breaks time down into human-understandable components:
17+
* years, months, days, hours, etc.
18+
*
19+
* Much of the functionality is involved in converting those two types to
20+
* other useful forms.
21+
}
22+
{*
23+
* A structure holding a calendar date and time broken down into its
24+
* components.
25+
*
26+
* \since This struct is available since SDL 3.2.0.
27+
}
28+
type
29+
PPSDL_DateTime = ^PSDL_DateTime;
30+
PSDL_DateTime = ^TSDL_DateTime;
31+
TSDL_DateTime = record
32+
year: cint; {*< Year }
33+
month: cint; {*< Month [01-12] }
34+
day: cint; {*< Day of the month [01-31] }
35+
hour: cint; {*< Hour [0-23] }
36+
minute: cint; {*< Minute [0-59] }
37+
second: cint; {*< Seconds [0-60] }
38+
nanosecond: cint; {*< Nanoseconds [0-999999999] }
39+
day_of_week: cint; {*< Day of the week [0-6] (0 being Sunday) }
40+
utc_offset: cint; {*< Seconds east of UTC }
41+
end;
42+
43+
{*
44+
* The preferred date format of the current system locale.
45+
*
46+
* \since This enum is available since SDL 3.2.0.
47+
*
48+
* \sa SDL_GetDateTimeLocalePreferences
49+
}
50+
type
51+
PPSDL_DateFormat = ^PSDL_DateFormat;
52+
PSDL_DateFormat = ^TSDL_DateFormat;
53+
TSDL_DateFormat = type Integer;
54+
const
55+
SDL_DATE_FORMAT_YYYYMMDD = TSDL_DateFormat(0); {*< Year/Month/Day }
56+
SDL_DATE_FORMAT_DDMMYYYY = TSDL_DateFormat(1); {*< Day/Month/Year }
57+
SDL_DATE_FORMAT_MMDDYYYY = TSDL_DateFormat(2); {*< Month/Day/Year }
58+
59+
{*
60+
* The preferred time format of the current system locale.
61+
*
62+
* \since This enum is available since SDL 3.2.0.
63+
*
64+
* \sa SDL_GetDateTimeLocalePreferences
65+
}
66+
type
67+
PPSDL_TimeFormat = ^PSDL_TimeFormat;
68+
PSDL_TimeFormat = ^TSDL_TimeFormat;
69+
TSDL_TimeFormat = type Integer;
70+
const
71+
SDL_TIME_FORMAT_24HR = TSDL_TimeFormat(0); {*< 24 hour time }
72+
SDL_TIME_FORMAT_12HR = TSDL_TimeFormat(1); {*< 12 hour time }
73+
74+
{*
75+
* Gets the current preferred date and time format for the system locale.
76+
*
77+
* This might be a "slow" call that has to query the operating system. It's
78+
* best to ask for this once and save the results. However, the preferred
79+
* formats can change, usually because the user has changed a system
80+
* preference outside of your program.
81+
*
82+
* \param dateFormat a Pointer to the SDL_DateFormat to hold the returned date
83+
* format, may be nil.
84+
* \param timeFormat a Pointer to the SDL_TimeFormat to hold the returned time
85+
* format, may be nil.
86+
* \returns true on success or false on failure; call SDL_GetError() for more
87+
* information.
88+
*
89+
* \since This function is available since SDL 3.2.0.
90+
}
91+
function SDL_GetDateTimeLocalePreferences(dateFormat: PSDL_DateFormat; timeFormat: PSDL_TimeFormat): cbool; cdecl;
92+
external SDL_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_SDL_GetDateTimeLocalePreferences' {$ENDIF} {$ENDIF};
93+
94+
{*
95+
* Gets the current value of the system realtime clock in nanoseconds since
96+
* Jan 1, 1970 in Universal Coordinated Time (UTC).
97+
*
98+
* \param ticks the SDL_Time to hold the returned tick count.
99+
* \returns true on success or false on failure; call SDL_GetError() for more
100+
* information.
101+
*
102+
* \since This function is available since SDL 3.2.0.
103+
}
104+
function SDL_GetCurrentTime(ticks: PSDL_Time): cbool; cdecl;
105+
external SDL_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_SDL_GetCurrentTime' {$ENDIF} {$ENDIF};
106+
107+
{*
108+
* Converts an SDL_Time in nanoseconds since the epoch to a calendar time in
109+
* the SDL_DateTime format.
110+
*
111+
* \param ticks the SDL_Time to be converted.
112+
* \param dt the resulting SDL_DateTime.
113+
* \param localTime the resulting SDL_DateTime will be expressed in local time
114+
* if true, otherwise it will be in Universal Coordinated
115+
* Time (UTC).
116+
* \returns true on success or false on failure; call SDL_GetError() for more
117+
* information.
118+
*
119+
* \since This function is available since SDL 3.2.0.
120+
}
121+
function SDL_TimeToDateTime(ticks: TSDL_Time; dt: PSDL_DateTime; localTime: cbool): cbool; cdecl;
122+
external SDL_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_SDL_TimeToDateTime' {$ENDIF} {$ENDIF};
123+
124+
{*
125+
* Converts a calendar time to an SDL_Time in nanoseconds since the epoch.
126+
*
127+
* This function ignores the day_of_week member of the SDL_DateTime struct, so
128+
* it may remain unset.
129+
*
130+
* \param dt the source SDL_DateTime.
131+
* \param ticks the resulting SDL_Time.
132+
* \returns true on success or false on failure; call SDL_GetError() for more
133+
* information.
134+
*
135+
* \since This function is available since SDL 3.2.0.
136+
}
137+
function SDL_DateTimeToTime(dt: PSDL_DateTime; ticks: PSDL_Time): cbool; cdecl;
138+
external SDL_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_SDL_DateTimeToTime' {$ENDIF} {$ENDIF};
139+
140+
{*
141+
* Converts an SDL time into a Windows FILETIME (100-nanosecond intervals
142+
* since January 1, 1601).
143+
*
144+
* This function fills in the two 32-bit values of the FILETIME structure.
145+
*
146+
* \param ticks the time to convert.
147+
* \param dwLowDateTime a Pointer filled in with the low portion of the
148+
* Windows FILETIME value.
149+
* \param dwHighDateTime a Pointer filled in with the high portion of the
150+
* Windows FILETIME value.
151+
*
152+
* \since This function is available since SDL 3.2.0.
153+
}
154+
procedure SDL_TimeToWindows(ticks: TSDL_Time; dwLowDateTime: pcuint32; dwHighDateTime: pcuint32); cdecl;
155+
external SDL_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_SDL_TimeToWindows' {$ENDIF} {$ENDIF};
156+
157+
{*
158+
* Converts a Windows FILETIME (100-nanosecond intervals since January 1,
159+
* 1601) to an SDL time.
160+
*
161+
* This function takes the two 32-bit values of the FILETIME structure as
162+
* parameters.
163+
*
164+
* \param dwLowDateTime the low portion of the Windows FILETIME value.
165+
* \param dwHighDateTime the high portion of the Windows FILETIME value.
166+
* \returns the converted SDL time.
167+
*
168+
* \since This function is available since SDL 3.2.0.
169+
}
170+
function SDL_TimeFromWindows(dwLowDateTime: cuint32; dwHighDateTime: cuint32): TSDL_Time; cdecl;
171+
external SDL_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_SDL_TimeFromWindows' {$ENDIF} {$ENDIF};
172+
173+
{*
174+
* Get the number of days in a month for a given year.
175+
*
176+
* \param year the year.
177+
* \param month the month [1-12].
178+
* \returns the number of days in the requested month or -1 on failure; call
179+
* SDL_GetError() for more information.
180+
*
181+
* \since This function is available since SDL 3.2.0.
182+
}
183+
function SDL_GetDaysInMonth(year: cint; month: cint): cint; cdecl;
184+
external SDL_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_SDL_GetDaysInMonth' {$ENDIF} {$ENDIF};
185+
186+
{*
187+
* Get the day of year for a calendar date.
188+
*
189+
* \param year the year component of the date.
190+
* \param month the month component of the date.
191+
* \param day the day component of the date.
192+
* \returns the day of year [0-365] if the date is valid or -1 on failure;
193+
* call SDL_GetError() for more information.
194+
*
195+
* \since This function is available since SDL 3.2.0.
196+
}
197+
function SDL_GetDayOfYear(year: cint; month: cint; day: cint): cint; cdecl;
198+
external SDL_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_SDL_GetDayOfYear' {$ENDIF} {$ENDIF};
199+
200+
{*
201+
* Get the day of week for a calendar date.
202+
*
203+
* \param year the year component of the date.
204+
* \param month the month component of the date.
205+
* \param day the day component of the date.
206+
* \returns a value between 0 and 6 (0 being Sunday) if the date is valid or
207+
* -1 on failure; call SDL_GetError() for more information.
208+
*
209+
* \since This function is available since SDL 3.2.0.
210+
}
211+
function SDL_GetDayOfWeek(year: cint; month: cint; day: cint): cint; cdecl;
212+
external SDL_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_SDL_GetDayOfWeek' {$ENDIF} {$ENDIF};
213+

0 commit comments

Comments
 (0)