@@ -27,12 +27,11 @@ SOFTWARE.
27
27
#pragma once
28
28
29
29
#include < EASTL/string_view.h>
30
- #include < EASTL/vector.h>
31
30
#include < stdint.h>
32
31
33
32
#include < coroutine>
34
33
35
- #include " psyqo/gpu .hh"
34
+ #include " psyqo/buffer .hh"
36
35
#include " psyqo/iso9660-parser.hh"
37
36
#include " psyqo/task.hh"
38
37
@@ -44,7 +43,7 @@ namespace psyqo::paths {
44
43
* @details This class provides a PSYQo path to read files from the CDRom.
45
44
* The way to use it is to instantiate the class somewhere persistent, and
46
45
* then call readFile() with a callback. The callback will be called with
47
- * the data of the file, or an empty vector if the file could not be read.
46
+ * the data of the file, or an empty buffer if the file could not be read.
48
47
* This is going to allocate memory in different places. Only one file can
49
48
* be read at a time, but it is safe to call readFile() again from the
50
49
* callback. If preferred, the loader can be cascaded into another `TaskQueue`.
@@ -54,59 +53,70 @@ namespace psyqo::paths {
54
53
55
54
class CDRomLoader {
56
55
struct ReadFileAwaiter {
57
- ReadFileAwaiter (eastl::string_view path, GPU &gpu, ISO9660Parser &parser, CDRomLoader &loader)
58
- : m_path(path), m_gpu(gpu), m_parser(parser), m_loader(loader) {}
56
+ ReadFileAwaiter (eastl::string_view path, ISO9660Parser &parser, CDRomLoader &loader)
57
+ : m_path(path), m_parser(parser), m_loader(loader) {}
59
58
~ReadFileAwaiter () {}
60
59
constexpr bool await_ready () const { return false ; }
61
60
template <typename U>
62
61
void await_suspend (std::coroutine_handle<U> handle) {
63
- m_loader.readFile (m_path, m_gpu, m_parser, [handle, this ](eastl::vector <uint8_t > &&data) {
62
+ m_loader.readFile (m_path, m_parser, [handle, this ](Buffer <uint8_t > &&data) {
64
63
m_data = eastl::move (data);
65
64
handle.resume ();
66
65
});
67
66
}
68
- eastl::vector <uint8_t > await_resume () { return eastl::move (m_data); }
67
+ Buffer <uint8_t > await_resume () { return eastl::move (m_data); }
69
68
70
69
private:
71
70
eastl::string_view m_path;
72
- GPU &m_gpu;
73
71
ISO9660Parser &m_parser;
74
72
CDRomLoader &m_loader;
75
- eastl::vector <uint8_t > m_data;
73
+ Buffer <uint8_t > m_data;
76
74
};
77
75
78
76
public:
77
+ /* *
78
+ * @brief Set the Buffer object for the next read operation.
79
+ *
80
+ * @details This function sets the buffer to be used for the next read
81
+ * operation. By default, the archive manager will allocate a buffer of the
82
+ * appropriate size for the file being read. However, if the user wants to
83
+ * use an already allocated buffer, they can use this function to set the buffer
84
+ * to be used.
85
+ *
86
+ * @param buffer The buffer to be used for the next read operation.
87
+ */
88
+ void setBuffer (Buffer<uint8_t > &&buffer) { m_data = eastl::move (buffer); }
89
+
79
90
/* *
80
91
* @brief Reads a file from the CDRom.
81
92
*
82
93
* @param path The path to the file to read. The view must be persistent
83
94
* until the callback is called.
84
- * @param gpu The GPU class used by the application, in order to set timers.
85
95
* @param parser The ISO9660Parser to use for reading the file.
86
96
* @param callback The callback to call when the file is read. The callback
87
- * will be called with the data of the file, or an empty vector if the file
97
+ * will be called with the data of the file, or an empty buffer if the file
88
98
* could not be read.
89
99
*/
90
- void readFile (eastl::string_view path, GPU &gpu, ISO9660Parser &parser,
91
- eastl::function<void (eastl::vector <uint8_t > &&)> &&callback) {
92
- setupQueue (path, gpu, parser, eastl::move (callback));
100
+ void readFile (eastl::string_view path, ISO9660Parser &parser,
101
+ eastl::function<void (Buffer <uint8_t > &&)> &&callback) {
102
+ setupQueue (path, parser, eastl::move (callback));
93
103
m_queue.run ();
94
104
}
95
- psyqo::TaskQueue::Task scheduleReadFile (eastl::string_view path, GPU &gpu, ISO9660Parser &parser) {
96
- setupQueue (path, gpu, parser, {});
105
+ psyqo::TaskQueue::Task scheduleReadFile (eastl::string_view path, ISO9660Parser &parser) {
106
+ setupQueue (path, parser, {});
97
107
return m_queue.schedule ();
98
108
}
99
- ReadFileAwaiter readFile (eastl::string_view path, GPU &gpu, ISO9660Parser &parser) {
100
- return {path, gpu, parser, *this };
109
+ ReadFileAwaiter readFile (eastl::string_view path, ISO9660Parser &parser) {
110
+ return {path, parser, *this };
101
111
}
102
112
103
113
private:
104
- void setupQueue (eastl::string_view path, GPU &gpu, ISO9660Parser &parser,
105
- eastl::function<void (eastl::vector <uint8_t > &&)> &&callback);
106
- eastl::function<void (eastl::vector <uint8_t > &&)> m_callback;
114
+ void setupQueue (eastl::string_view path, ISO9660Parser &parser,
115
+ eastl::function<void (Buffer <uint8_t > &&)> &&callback);
116
+ eastl::function<void (Buffer <uint8_t > &&)> m_callback;
107
117
psyqo::TaskQueue m_queue;
108
118
ISO9660Parser::ReadRequest m_request;
109
- eastl::vector <uint8_t > m_data;
119
+ Buffer <uint8_t > m_data;
110
120
bool m_pending = false ;
111
121
};
112
122
0 commit comments