Split archive FS logic into its own file
This commit is contained in:
		
							parent
							
								
									6769ea92af
								
							
						
					
					
						commit
						174b16199e
					
				| @ -1,3 +1,5 @@ | |||||||
|  | const Archive = @import("./sys/Archive.zig"); | ||||||
|  | 
 | ||||||
| const ext = @cImport({ | const ext = @cImport({ | ||||||
|     @cInclude("SDL2/SDL.h"); |     @cInclude("SDL2/SDL.h"); | ||||||
| }); | }); | ||||||
| @ -148,7 +150,7 @@ pub const AppContext = opaque { | |||||||
|                 .user_path_prefix = user_path_prefix, |                 .user_path_prefix = user_path_prefix, | ||||||
| 
 | 
 | ||||||
|                 .data_file_system = .{.archive = .{ |                 .data_file_system = .{.archive = .{ | ||||||
|                     .index_cache = try FileSystem.ArchiveIndexCache.init(allocator), |                     .index_cache = try Archive.IndexCache.init(allocator), | ||||||
|                     .file_access = data_archive_file_access, |                     .file_access = data_archive_file_access, | ||||||
|                 }}, |                 }}, | ||||||
| 
 | 
 | ||||||
| @ -269,33 +271,7 @@ pub const AppContext = opaque { | |||||||
| /// | /// | ||||||
| pub const FileSystem = union(enum) { | pub const FileSystem = union(enum) { | ||||||
|     native: []const u8, |     native: []const u8, | ||||||
| 
 |     archive: Archive, | ||||||
|     archive: struct { |  | ||||||
|         file_access: ona.io.FileAccess, |  | ||||||
|         index_cache: ArchiveIndexCache, |  | ||||||
| 
 |  | ||||||
|         entry_table: [max_open_entries]ArchiveEntry = |  | ||||||
|             std.mem.zeroes([max_open_entries]ArchiveEntry), |  | ||||||
| 
 |  | ||||||
|         const max_open_entries = 16; |  | ||||||
|     }, |  | ||||||
| 
 |  | ||||||
|     /// |  | ||||||
|     /// |  | ||||||
|     /// |  | ||||||
|     const ArchiveEntry = struct { |  | ||||||
|         owner: ?*ona.io.FileAccess, |  | ||||||
|         cursor: u64, |  | ||||||
|         header: oar.Entry, |  | ||||||
|     }; |  | ||||||
| 
 |  | ||||||
|     /// |  | ||||||
|     /// |  | ||||||
|     /// |  | ||||||
|     const ArchiveIndexCache = ona.table.Hashed(oar.Path, u64, .{ |  | ||||||
|         .equals = oar.Path.equals, |  | ||||||
|         .hash = oar.Path.hash, |  | ||||||
|     }); |  | ||||||
| 
 | 
 | ||||||
|     /// |     /// | ||||||
|     /// Platform-agnostic mechanism for referencing files and directories on a [FileSystem]. |     /// Platform-agnostic mechanism for referencing files and directories on a [FileSystem]. | ||||||
| @ -379,9 +355,9 @@ pub const FileSystem = union(enum) { | |||||||
| 
 | 
 | ||||||
|                     for (archive.entry_table) |*entry| if (entry.owner == null) { |                     for (archive.entry_table) |*entry| if (entry.owner == null) { | ||||||
|                         const Implementation = struct { |                         const Implementation = struct { | ||||||
|                             fn archiveEntryCast(context: *anyopaque) *ArchiveEntry { |                             fn archiveEntryCast(context: *anyopaque) *Archive.Entry { | ||||||
|                                 return @ptrCast(*ArchiveEntry, @alignCast( |                                 return @ptrCast(*Archive.Entry, @alignCast( | ||||||
|                                     @alignOf(ArchiveEntry), context)); |                                     @alignOf(Archive.Entry), context)); | ||||||
|                             } |                             } | ||||||
| 
 | 
 | ||||||
|                             fn close(context: *anyopaque) void { |                             fn close(context: *anyopaque) void { | ||||||
|  | |||||||
							
								
								
									
										29
									
								
								src/engine/sys/Archive.zig
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										29
									
								
								src/engine/sys/Archive.zig
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,29 @@ | |||||||
|  | const oar = @import("oar"); | ||||||
|  | const ona = @import("ona"); | ||||||
|  | const std = @import("std"); | ||||||
|  | 
 | ||||||
|  | file_access: ona.io.FileAccess, | ||||||
|  | index_cache: IndexCache, | ||||||
|  | entry_table: [max_open_entries]Entry = std.mem.zeroes([max_open_entries]Entry), | ||||||
|  | 
 | ||||||
|  | /// | ||||||
|  | /// Hard limit on the maximum number of entries open at once. | ||||||
|  | /// | ||||||
|  | const max_open_entries = 16; | ||||||
|  | 
 | ||||||
|  | /// | ||||||
|  | /// Stateful extension of an [oar.Entry]. | ||||||
|  | /// | ||||||
|  | pub const Entry = struct { | ||||||
|  |     owner: ?*ona.io.FileAccess, | ||||||
|  |     cursor: u64, | ||||||
|  |     header: oar.Entry, | ||||||
|  | }; | ||||||
|  | 
 | ||||||
|  | /// | ||||||
|  | /// Table cache for associating [oar.Path] values with offsets to entries in a given file. | ||||||
|  | /// | ||||||
|  | pub const IndexCache = ona.table.Hashed(oar.Path, u64, .{ | ||||||
|  |     .equals = oar.Path.equals, | ||||||
|  |     .hash = oar.Path.hash, | ||||||
|  | }); | ||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user