Browse Source

Merge branch 'master' of https://github.com/odin-lang/Odin

gingerBill 3 years ago
parent
commit
e2bfb024de
4 changed files with 129 additions and 30 deletions
  1. 23 11
      core/math/ease/ease.odin
  2. 31 11
      core/os/file_windows.odin
  3. 73 8
      core/sys/windows/types.odin
  4. 2 0
      core/sys/windows/user32.odin

+ 23 - 11
core/math/ease/ease.odin

@@ -325,9 +325,9 @@ ease :: proc "contextless" (type: Ease, p: $T) -> T
 	// in case type was invalid
 	return 0
 }
-
 Flux_Map :: struct($T: typeid) {
 	values: map[^T]Flux_Tween(T),
+	keys_to_be_deleted: [dynamic]^T,
 }
 
 Flux_Tween :: struct($T: typeid) {
@@ -353,15 +353,17 @@ Flux_Tween :: struct($T: typeid) {
 }
 
 // init flux map to a float type and a wanted cap
-flux_init :: proc($T: typeid, cap := 8) -> Flux_Map(T) where intrinsics.type_is_float(T) {
+flux_init :: proc($T: typeid, value_capacity := 8) -> Flux_Map(T) where intrinsics.type_is_float(T) {
 	return {
-		make(map[^T]Flux_Tween(T), cap),
+		values = make(map[^T]Flux_Tween(T), value_capacity),
+		keys_to_be_deleted = make([dynamic]^T, 0, value_capacity)
 	}
 }
 
 // delete map content
 flux_destroy :: proc(flux: Flux_Map($T)) where intrinsics.type_is_float(T) {
 	delete(flux.values)
+	delete(flux.keys_to_be_deleted)
 }
 
 // clear map content, stops all animations
@@ -374,8 +376,8 @@ flux_clear :: proc(flux: ^Flux_Map($T)) where intrinsics.type_is_float(T) {
 // return value can be used to set callbacks
 flux_to :: proc(
 	flux: ^Flux_Map($T),
-	value: ^f32, 
-	goal: f32, 
+	value: ^T, 
+	goal: T, 
 	type: Ease = .Quadratic_Out,
 	duration: time.Duration = time.Second, 
 	delay: f64 = 0,
@@ -413,6 +415,8 @@ flux_tween_init :: proc(tween: ^Flux_Tween($T), duration: time.Duration) where i
 // calls callbacks in all stages, when they're filled
 // deletes tween from the map after completion
 flux_update :: proc(flux: ^Flux_Map($T), dt: f64) where intrinsics.type_is_float(T) {
+	clear(&flux.keys_to_be_deleted)
+
 	for key, tween in &flux.values {
 		delay_remainder := f64(0)
 
@@ -451,7 +455,8 @@ flux_update :: proc(flux: ^Flux_Map($T), dt: f64) where intrinsics.type_is_float
 			}
 
 			if tween.progress >= 1 {
-				delete_key(&flux.values, key)
+				// append keys to array that will be deleted after the loop
+				append(&flux.keys_to_be_deleted, key)
 
 				if tween.on_complete != nil {
 					tween.on_complete(flux, tween.data)
@@ -459,17 +464,24 @@ flux_update :: proc(flux: ^Flux_Map($T), dt: f64) where intrinsics.type_is_float
 			}
 		}
 	}
+	
+	// loop through keys that should be deleted from the map
+	if len(flux.keys_to_be_deleted) != 0 {
+		for key in flux.keys_to_be_deleted {
+			delete_key(&flux.values, key)
+		}
+	}
 }
 
 // stop a specific key inside the map
 // returns true when it successfully removed the key
 flux_stop :: proc(flux: ^Flux_Map($T), key: ^T) -> bool where intrinsics.type_is_float(T) {
-    if key in flux.values {
-        delete_key(&flux.values, key)
-        return true
-    }
+	if key in flux.values {
+		delete_key(&flux.values, key)
+		return true
+	}
 
-    return false
+	return false
 }
 
 // returns the amount of time left for the tween animation, if the key exists in the map

+ 31 - 11
core/os/file_windows.odin

@@ -384,21 +384,33 @@ set_current_directory :: proc(path: string) -> (err: Errno) {
 
 
 
-change_directory :: proc(path: string) -> Errno {
+change_directory :: proc(path: string) -> (err: Errno) {
 	wpath := win32.utf8_to_wstring(path, context.temp_allocator)
-	return Errno(win32.SetCurrentDirectoryW(wpath))
+
+	if !win32.SetCurrentDirectoryW(wpath) {
+		err = Errno(win32.GetLastError())
+	}
+	return
 }
 
-make_directory :: proc(path: string, mode: u32 = 0) -> Errno {
+make_directory :: proc(path: string, mode: u32 = 0) -> (err: Errno) {
 	// Mode is unused on Windows, but is needed on *nix
 	wpath := win32.utf8_to_wstring(path, context.temp_allocator)
-	return Errno(win32.CreateDirectoryW(wpath, nil))
+
+	if !win32.CreateDirectoryW(wpath, nil) {
+		err = Errno(win32.GetLastError())
+	}
+	return
 }
 
 
-remove_directory :: proc(path: string) -> Errno {
+remove_directory :: proc(path: string) -> (err: Errno) {
 	wpath := win32.utf8_to_wstring(path, context.temp_allocator)
-	return Errno(win32.RemoveDirectoryW(wpath))
+
+	if !win32.RemoveDirectoryW(wpath) {
+		err = Errno(win32.GetLastError())
+	}
+	return
 }
 
 
@@ -464,23 +476,31 @@ fix_long_path :: proc(path: string) -> string {
 }
 
 
-link :: proc(old_name, new_name: string) -> Errno {
+link :: proc(old_name, new_name: string) -> (err: Errno) {
 	n := win32.utf8_to_wstring(fix_long_path(new_name))
 	o := win32.utf8_to_wstring(fix_long_path(old_name))
 	return Errno(win32.CreateHardLinkW(n, o, nil))
 }
 
-unlink :: proc(path: string) -> Errno {
+unlink :: proc(path: string) -> (err: Errno) {
 	wpath := win32.utf8_to_wstring(path, context.temp_allocator)
-	return Errno(win32.DeleteFileW(wpath))
+
+	if !win32.DeleteFileW(wpath) {
+		err = Errno(win32.GetLastError())
+	}
+	return
 }
 
 
 
-rename :: proc(old_path, new_path: string) -> Errno {
+rename :: proc(old_path, new_path: string) -> (err: Errno) {
 	from := win32.utf8_to_wstring(old_path, context.temp_allocator)
 	to := win32.utf8_to_wstring(new_path, context.temp_allocator)
-	return Errno(win32.MoveFileExW(from, to, win32.MOVEFILE_REPLACE_EXISTING))
+
+	if !win32.MoveFileExW(from, to, win32.MOVEFILE_REPLACE_EXISTING) {
+		err = Errno(win32.GetLastError())
+	}
+	return
 }
 
 

+ 73 - 8
core/sys/windows/types.odin

@@ -196,15 +196,26 @@ OPEN_ALWAYS: DWORD : 4
 OPEN_EXISTING: DWORD : 3
 TRUNCATE_EXISTING: DWORD : 5
 
+FILE_READ_DATA            : DWORD : 0x00000001
+FILE_LIST_DIRECTORY       : DWORD : 0x00000001
+FILE_WRITE_DATA           : DWORD : 0x00000002
+FILE_ADD_FILE             : DWORD : 0x00000002
+FILE_APPEND_DATA          : DWORD : 0x00000004
+FILE_ADD_SUBDIRECTORY     : DWORD : 0x00000004
+FILE_CREATE_PIPE_INSTANCE : DWORD : 0x00000004
+FILE_READ_EA              : DWORD : 0x00000008
+FILE_WRITE_EA             : DWORD : 0x00000010
+FILE_EXECUTE              : DWORD : 0x00000020
+FILE_TRAVERSE             : DWORD : 0x00000020
+FILE_DELETE_CHILD         : DWORD : 0x00000040
+FILE_READ_ATTRIBUTES      : DWORD : 0x00000080
+FILE_WRITE_ATTRIBUTES     : DWORD : 0x00000100
+
+GENERIC_READ    : DWORD : 0x80000000
+GENERIC_WRITE   : DWORD : 0x40000000
+GENERIC_EXECUTE : DWORD : 0x20000000
+GENERIC_ALL     : DWORD : 0x10000000
 
-
-FILE_WRITE_DATA: DWORD : 0x00000002
-FILE_APPEND_DATA: DWORD : 0x00000004
-FILE_WRITE_EA: DWORD : 0x00000010
-FILE_WRITE_ATTRIBUTES: DWORD : 0x00000100
-FILE_READ_ATTRIBUTES: DWORD : 0x000000080
-GENERIC_READ: DWORD : 0x80000000
-GENERIC_WRITE: DWORD : 0x40000000
 FILE_GENERIC_WRITE: DWORD : STANDARD_RIGHTS_WRITE |
 	FILE_WRITE_DATA |
 	FILE_WRITE_ATTRIBUTES |
@@ -250,6 +261,9 @@ DIAGNOSTIC_REASON_SIMPLE_STRING   :: 0x00000001
 DIAGNOSTIC_REASON_DETAILED_STRING :: 0x00000002
 DIAGNOSTIC_REASON_NOT_SPECIFIED   :: 0x80000000
 
+ENUM_CURRENT_SETTINGS  : DWORD : 4294967295 // (DWORD)-1
+ENUM_REGISTRY_SETTINGS : DWORD : 4294967294 // (DWORD)-2
+
 // Defines for power request APIs
 
 POWER_REQUEST_CONTEXT_VERSION :: DIAGNOSTIC_REASON_VERSION
@@ -813,6 +827,57 @@ CREATESTRUCTW:: struct {
 	dwExStyle:      DWORD,
 }
 
+DEVMODEW :: struct {
+	dmDeviceName:   [32]wchar_t,
+	dmSpecVersion:   WORD,
+	dmDriverVersion: WORD,
+	dmSize:          WORD,
+	dmDriverExtra:   WORD,
+	dmFields:        DWORD,
+	using _: struct #raw_union {
+		// Printer only fields.
+		using _: struct {
+			dmOrientation:   c_short,
+			dmPaperSize:     c_short,
+			dmPaperLength:   c_short,
+			dmPaperWidth:    c_short,
+			dmScale:         c_short,
+			dmCopies:        c_short,
+			dmDefaultSource: c_short,
+			dmPrintQuality:  c_short,
+		},
+		// Display only fields.
+		using _: struct {
+			dmPosition:           POINT,
+			dmDisplayOrientation: DWORD,
+			dmDisplayFixedOutput: DWORD,
+		},
+	},
+	dmColor:       c_short,
+	dmDuplex:      c_short,
+	dmYResolution: c_short,
+	dmTTOption:    c_short,
+	dmCollate:     c_short,
+	dmFormName:    [32]wchar_t,
+	dmLogPixels:   WORD,
+	dmBitsPerPel:  DWORD,
+	dmPelsWidth:   DWORD,
+	dmPelsHeight:  DWORD,
+	using _: struct #raw_union {
+		dmDisplayFlags: DWORD,
+		dmNup:          DWORD,
+	},
+	dmDisplayFrequency: DWORD,
+	dmICMMethod:        DWORD,
+	dmICMIntent:        DWORD,
+	dmMediaType:        DWORD,
+	dmDitherType:       DWORD,
+	dmReserved1:        DWORD,
+	dmReserved2:        DWORD,
+	dmPanningWidth:     DWORD,
+	dmPanningHeight:    DWORD,
+}
+
 // MessageBox() Flags
 MB_OK                :: 0x00000000
 MB_OKCANCEL          :: 0x00000001

+ 2 - 0
core/sys/windows/user32.odin

@@ -135,6 +135,8 @@ foreign user32 {
 	SetCursorPos :: proc(X: c_int, Y: c_int) -> BOOL ---
 	SetCursor :: proc(hCursor: HCURSOR) -> HCURSOR ---
 
+	EnumDisplaySettingsW :: proc(lpszDeviceName: LPCWSTR, iModeNum: DWORD, lpDevMode: ^DEVMODEW) -> BOOL ---
+	
 	BroadcastSystemMessageW :: proc(
 		flags: DWORD,
 		lpInfo: LPDWORD,