Skip to content

Commit e2bfb02

Browse files
committed
Merge branch 'master' of https://github.com/odin-lang/Odin
2 parents 4d06a54 + 04ae87e commit e2bfb02

4 files changed

Lines changed: 129 additions & 30 deletions

File tree

core/math/ease/ease.odin

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -325,9 +325,9 @@ ease :: proc "contextless" (type: Ease, p: $T) -> T
325325
// in case type was invalid
326326
return 0
327327
}
328-
329328
Flux_Map :: struct($T: typeid) {
330329
values: map[^T]Flux_Tween(T),
330+
keys_to_be_deleted: [dynamic]^T,
331331
}
332332

333333
Flux_Tween :: struct($T: typeid) {
@@ -353,15 +353,17 @@ Flux_Tween :: struct($T: typeid) {
353353
}
354354

355355
// init flux map to a float type and a wanted cap
356-
flux_init :: proc($T: typeid, cap := 8) -> Flux_Map(T) where intrinsics.type_is_float(T) {
356+
flux_init :: proc($T: typeid, value_capacity := 8) -> Flux_Map(T) where intrinsics.type_is_float(T) {
357357
return {
358-
make(map[^T]Flux_Tween(T), cap),
358+
values = make(map[^T]Flux_Tween(T), value_capacity),
359+
keys_to_be_deleted = make([dynamic]^T, 0, value_capacity)
359360
}
360361
}
361362

362363
// delete map content
363364
flux_destroy :: proc(flux: Flux_Map($T)) where intrinsics.type_is_float(T) {
364365
delete(flux.values)
366+
delete(flux.keys_to_be_deleted)
365367
}
366368

367369
// clear map content, stops all animations
@@ -374,8 +376,8 @@ flux_clear :: proc(flux: ^Flux_Map($T)) where intrinsics.type_is_float(T) {
374376
// return value can be used to set callbacks
375377
flux_to :: proc(
376378
flux: ^Flux_Map($T),
377-
value: ^f32,
378-
goal: f32,
379+
value: ^T,
380+
goal: T,
379381
type: Ease = .Quadratic_Out,
380382
duration: time.Duration = time.Second,
381383
delay: f64 = 0,
@@ -413,6 +415,8 @@ flux_tween_init :: proc(tween: ^Flux_Tween($T), duration: time.Duration) where i
413415
// calls callbacks in all stages, when they're filled
414416
// deletes tween from the map after completion
415417
flux_update :: proc(flux: ^Flux_Map($T), dt: f64) where intrinsics.type_is_float(T) {
418+
clear(&flux.keys_to_be_deleted)
419+
416420
for key, tween in &flux.values {
417421
delay_remainder := f64(0)
418422

@@ -451,25 +455,33 @@ flux_update :: proc(flux: ^Flux_Map($T), dt: f64) where intrinsics.type_is_float
451455
}
452456

453457
if tween.progress >= 1 {
454-
delete_key(&flux.values, key)
458+
// append keys to array that will be deleted after the loop
459+
append(&flux.keys_to_be_deleted, key)
455460

456461
if tween.on_complete != nil {
457462
tween.on_complete(flux, tween.data)
458463
}
459464
}
460465
}
461466
}
467+
468+
// loop through keys that should be deleted from the map
469+
if len(flux.keys_to_be_deleted) != 0 {
470+
for key in flux.keys_to_be_deleted {
471+
delete_key(&flux.values, key)
472+
}
473+
}
462474
}
463475

464476
// stop a specific key inside the map
465477
// returns true when it successfully removed the key
466478
flux_stop :: proc(flux: ^Flux_Map($T), key: ^T) -> bool where intrinsics.type_is_float(T) {
467-
if key in flux.values {
468-
delete_key(&flux.values, key)
469-
return true
470-
}
479+
if key in flux.values {
480+
delete_key(&flux.values, key)
481+
return true
482+
}
471483

472-
return false
484+
return false
473485
}
474486

475487
// returns the amount of time left for the tween animation, if the key exists in the map

core/os/file_windows.odin

Lines changed: 31 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -384,21 +384,33 @@ set_current_directory :: proc(path: string) -> (err: Errno) {
384384

385385

386386

387-
change_directory :: proc(path: string) -> Errno {
387+
change_directory :: proc(path: string) -> (err: Errno) {
388388
wpath := win32.utf8_to_wstring(path, context.temp_allocator)
389-
return Errno(win32.SetCurrentDirectoryW(wpath))
389+
390+
if !win32.SetCurrentDirectoryW(wpath) {
391+
err = Errno(win32.GetLastError())
392+
}
393+
return
390394
}
391395

392-
make_directory :: proc(path: string, mode: u32 = 0) -> Errno {
396+
make_directory :: proc(path: string, mode: u32 = 0) -> (err: Errno) {
393397
// Mode is unused on Windows, but is needed on *nix
394398
wpath := win32.utf8_to_wstring(path, context.temp_allocator)
395-
return Errno(win32.CreateDirectoryW(wpath, nil))
399+
400+
if !win32.CreateDirectoryW(wpath, nil) {
401+
err = Errno(win32.GetLastError())
402+
}
403+
return
396404
}
397405

398406

399-
remove_directory :: proc(path: string) -> Errno {
407+
remove_directory :: proc(path: string) -> (err: Errno) {
400408
wpath := win32.utf8_to_wstring(path, context.temp_allocator)
401-
return Errno(win32.RemoveDirectoryW(wpath))
409+
410+
if !win32.RemoveDirectoryW(wpath) {
411+
err = Errno(win32.GetLastError())
412+
}
413+
return
402414
}
403415

404416

@@ -464,23 +476,31 @@ fix_long_path :: proc(path: string) -> string {
464476
}
465477

466478

467-
link :: proc(old_name, new_name: string) -> Errno {
479+
link :: proc(old_name, new_name: string) -> (err: Errno) {
468480
n := win32.utf8_to_wstring(fix_long_path(new_name))
469481
o := win32.utf8_to_wstring(fix_long_path(old_name))
470482
return Errno(win32.CreateHardLinkW(n, o, nil))
471483
}
472484

473-
unlink :: proc(path: string) -> Errno {
485+
unlink :: proc(path: string) -> (err: Errno) {
474486
wpath := win32.utf8_to_wstring(path, context.temp_allocator)
475-
return Errno(win32.DeleteFileW(wpath))
487+
488+
if !win32.DeleteFileW(wpath) {
489+
err = Errno(win32.GetLastError())
490+
}
491+
return
476492
}
477493

478494

479495

480-
rename :: proc(old_path, new_path: string) -> Errno {
496+
rename :: proc(old_path, new_path: string) -> (err: Errno) {
481497
from := win32.utf8_to_wstring(old_path, context.temp_allocator)
482498
to := win32.utf8_to_wstring(new_path, context.temp_allocator)
483-
return Errno(win32.MoveFileExW(from, to, win32.MOVEFILE_REPLACE_EXISTING))
499+
500+
if !win32.MoveFileExW(from, to, win32.MOVEFILE_REPLACE_EXISTING) {
501+
err = Errno(win32.GetLastError())
502+
}
503+
return
484504
}
485505

486506

core/sys/windows/types.odin

Lines changed: 73 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -196,15 +196,26 @@ OPEN_ALWAYS: DWORD : 4
196196
OPEN_EXISTING: DWORD : 3
197197
TRUNCATE_EXISTING: DWORD : 5
198198

199+
FILE_READ_DATA : DWORD : 0x00000001
200+
FILE_LIST_DIRECTORY : DWORD : 0x00000001
201+
FILE_WRITE_DATA : DWORD : 0x00000002
202+
FILE_ADD_FILE : DWORD : 0x00000002
203+
FILE_APPEND_DATA : DWORD : 0x00000004
204+
FILE_ADD_SUBDIRECTORY : DWORD : 0x00000004
205+
FILE_CREATE_PIPE_INSTANCE : DWORD : 0x00000004
206+
FILE_READ_EA : DWORD : 0x00000008
207+
FILE_WRITE_EA : DWORD : 0x00000010
208+
FILE_EXECUTE : DWORD : 0x00000020
209+
FILE_TRAVERSE : DWORD : 0x00000020
210+
FILE_DELETE_CHILD : DWORD : 0x00000040
211+
FILE_READ_ATTRIBUTES : DWORD : 0x00000080
212+
FILE_WRITE_ATTRIBUTES : DWORD : 0x00000100
213+
214+
GENERIC_READ : DWORD : 0x80000000
215+
GENERIC_WRITE : DWORD : 0x40000000
216+
GENERIC_EXECUTE : DWORD : 0x20000000
217+
GENERIC_ALL : DWORD : 0x10000000
199218

200-
201-
FILE_WRITE_DATA: DWORD : 0x00000002
202-
FILE_APPEND_DATA: DWORD : 0x00000004
203-
FILE_WRITE_EA: DWORD : 0x00000010
204-
FILE_WRITE_ATTRIBUTES: DWORD : 0x00000100
205-
FILE_READ_ATTRIBUTES: DWORD : 0x000000080
206-
GENERIC_READ: DWORD : 0x80000000
207-
GENERIC_WRITE: DWORD : 0x40000000
208219
FILE_GENERIC_WRITE: DWORD : STANDARD_RIGHTS_WRITE |
209220
FILE_WRITE_DATA |
210221
FILE_WRITE_ATTRIBUTES |
@@ -250,6 +261,9 @@ DIAGNOSTIC_REASON_SIMPLE_STRING :: 0x00000001
250261
DIAGNOSTIC_REASON_DETAILED_STRING :: 0x00000002
251262
DIAGNOSTIC_REASON_NOT_SPECIFIED :: 0x80000000
252263

264+
ENUM_CURRENT_SETTINGS : DWORD : 4294967295 // (DWORD)-1
265+
ENUM_REGISTRY_SETTINGS : DWORD : 4294967294 // (DWORD)-2
266+
253267
// Defines for power request APIs
254268

255269
POWER_REQUEST_CONTEXT_VERSION :: DIAGNOSTIC_REASON_VERSION
@@ -813,6 +827,57 @@ CREATESTRUCTW:: struct {
813827
dwExStyle: DWORD,
814828
}
815829

830+
DEVMODEW :: struct {
831+
dmDeviceName: [32]wchar_t,
832+
dmSpecVersion: WORD,
833+
dmDriverVersion: WORD,
834+
dmSize: WORD,
835+
dmDriverExtra: WORD,
836+
dmFields: DWORD,
837+
using _: struct #raw_union {
838+
// Printer only fields.
839+
using _: struct {
840+
dmOrientation: c_short,
841+
dmPaperSize: c_short,
842+
dmPaperLength: c_short,
843+
dmPaperWidth: c_short,
844+
dmScale: c_short,
845+
dmCopies: c_short,
846+
dmDefaultSource: c_short,
847+
dmPrintQuality: c_short,
848+
},
849+
// Display only fields.
850+
using _: struct {
851+
dmPosition: POINT,
852+
dmDisplayOrientation: DWORD,
853+
dmDisplayFixedOutput: DWORD,
854+
},
855+
},
856+
dmColor: c_short,
857+
dmDuplex: c_short,
858+
dmYResolution: c_short,
859+
dmTTOption: c_short,
860+
dmCollate: c_short,
861+
dmFormName: [32]wchar_t,
862+
dmLogPixels: WORD,
863+
dmBitsPerPel: DWORD,
864+
dmPelsWidth: DWORD,
865+
dmPelsHeight: DWORD,
866+
using _: struct #raw_union {
867+
dmDisplayFlags: DWORD,
868+
dmNup: DWORD,
869+
},
870+
dmDisplayFrequency: DWORD,
871+
dmICMMethod: DWORD,
872+
dmICMIntent: DWORD,
873+
dmMediaType: DWORD,
874+
dmDitherType: DWORD,
875+
dmReserved1: DWORD,
876+
dmReserved2: DWORD,
877+
dmPanningWidth: DWORD,
878+
dmPanningHeight: DWORD,
879+
}
880+
816881
// MessageBox() Flags
817882
MB_OK :: 0x00000000
818883
MB_OKCANCEL :: 0x00000001

core/sys/windows/user32.odin

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,8 @@ foreign user32 {
135135
SetCursorPos :: proc(X: c_int, Y: c_int) -> BOOL ---
136136
SetCursor :: proc(hCursor: HCURSOR) -> HCURSOR ---
137137

138+
EnumDisplaySettingsW :: proc(lpszDeviceName: LPCWSTR, iModeNum: DWORD, lpDevMode: ^DEVMODEW) -> BOOL ---
139+
138140
BroadcastSystemMessageW :: proc(
139141
flags: DWORD,
140142
lpInfo: LPDWORD,

0 commit comments

Comments
 (0)