Use continous memory for loading files

This commit is contained in:
Jaby 2022-10-02 10:18:27 +02:00 committed by Jaby
parent ff11c26905
commit 359d2fdcb5
3 changed files with 23 additions and 12 deletions

View File

@ -6,22 +6,33 @@ namespace FileProcessor {
class State { class State {
private: private:
struct Reserved { struct Reserved {
uint32_t _reserved[2] = {0}; uint32_t reserved[2];
}; };
typedef bool (*ProcessRoutine)(uint32_t*, size_t, Reserved&); struct Configuration;
typedef bool (*ProcessRoutine)(Configuration&, Reserved&, size_t);
struct Configuration {
ProcessRoutine process_routine = nullptr;
const uint32_t* data_adr = nullptr;
template<typename T>
static __always_inline Configuration from(bool (*process_routine)(Configuration&, T&, size_t), const uint32_t* data_adr) {
return {reinterpret_cast<ProcessRoutine>(process_routine), data_adr};
}
};
private: private:
ProcessRoutine process_adr = nullptr; Configuration config;
Reserved reserved; Reserved reserved;
public: public:
bool process(uint32_t* data, size_t size) { bool process(size_t size) {
return (*this->process_adr)(data, size, this->reserved); return (*this->config.process_routine)(this->config, this->reserved, size);
} }
}; };
State create(const SimpleTIM& file); State create(const uint32_t* data_adr, const SimpleTIM& file);
} }
#endif // !__JABYENGINE_FILE_PROCESSOR_HPP__ #endif // !__JABYENGINE_FILE_PROCESSOR_HPP__

View File

@ -36,8 +36,8 @@ namespace GPU {
Display::enable(); Display::enable();
//For now //For now
auto state = FileProcessor::create(SimpleTIM(0, 0, 0, 0)); auto state = FileProcessor::create(nullptr, SimpleTIM(0, 0, 0, 0));
while(state.process(nullptr, 0ull)); while(state.process(0ull));
} }
void setup() { void setup() {

View File

@ -14,15 +14,15 @@ namespace FileProcessor {
}; };
static_assert(sizeof(SimpleTIMState) <= sizeof(State::Reserved)); static_assert(sizeof(SimpleTIMState) <= sizeof(State::Reserved));
static bool process(uint32_t*, size_t, SimpleTIMState &state) { static bool process(State::Configuration& config, SimpleTIMState& state, size_t size) {
printf("Dino: %i\n", state.test); printf("Dino: %i\n", state.test);
return false; return false;
} }
State create(const SimpleTIM& file) { State create(const uint32_t* data_adr, const SimpleTIM& file) {
SimpleTIMState test(123); SimpleTIMState test(123);
return State{.process_adr = reinterpret_cast<State::ProcessRoutine>(process), .reserved = test._reserved}; return State{.config = State::Configuration::from(process, data_adr), .reserved = test._reserved};
} }
} }