More clean-up
This commit is contained in:
@@ -10,21 +10,20 @@ namespace JabyEngine {
|
||||
uint32_t reserved[8];
|
||||
};
|
||||
|
||||
struct Configuration;
|
||||
struct CDDataProcessor;
|
||||
|
||||
template<typename T>
|
||||
using GenericProcessRoutine = Progress (*)(Configuration&, T&);
|
||||
using GenericProcessRoutine = Progress (*)(CDDataProcessor&, T&);
|
||||
|
||||
typedef GenericProcessRoutine<Reserved> ProcessRoutine;
|
||||
|
||||
// TODO: Better name!!!!
|
||||
struct Configuration {
|
||||
struct CDDataProcessor {
|
||||
ProcessRoutine process_routine = nullptr;
|
||||
const uint8_t* data_adr = nullptr;
|
||||
size_t data_bytes = 0ull;
|
||||
|
||||
template<typename T>
|
||||
static __always_inline Configuration from(GenericProcessRoutine<T> process_routine, const uint8_t* data_adr) {
|
||||
static __always_inline CDDataProcessor from(GenericProcessRoutine<T> process_routine, const uint8_t* data_adr) {
|
||||
return {reinterpret_cast<ProcessRoutine>(process_routine), data_adr};
|
||||
}
|
||||
|
||||
@@ -33,7 +32,7 @@ namespace JabyEngine {
|
||||
static constexpr size_t T_SIZE = sizeof(T);
|
||||
|
||||
T value = *reinterpret_cast<const T*>(this->data_adr);
|
||||
Configuration::processed(T_SIZE);
|
||||
CDDataProcessor::processed(T_SIZE);
|
||||
return value;
|
||||
}
|
||||
|
||||
@@ -43,23 +42,23 @@ namespace JabyEngine {
|
||||
}
|
||||
|
||||
constexpr void skip(size_t bytes) {
|
||||
Configuration::processed(bytes);
|
||||
CDDataProcessor::processed(bytes);
|
||||
}
|
||||
};
|
||||
|
||||
Configuration config;
|
||||
Reserved reserved;
|
||||
CDDataProcessor data_proc;
|
||||
Reserved reserved;
|
||||
|
||||
template<typename T>
|
||||
static __always_inline State from(const T& state, const uint32_t* data_adr, GenericProcessRoutine<T> process_routine) {
|
||||
return {Configuration::from(process_routine, reinterpret_cast<const uint8_t*>(data_adr)), *reinterpret_cast<const Reserved*>(&state)};
|
||||
return {CDDataProcessor::from(process_routine, reinterpret_cast<const uint8_t*>(data_adr)), *reinterpret_cast<const Reserved*>(&state)};
|
||||
static_assert(sizeof(T) <= sizeof(Reserved));
|
||||
}
|
||||
|
||||
public:
|
||||
Progress process(size_t bytes_ready) {
|
||||
this->config.data_bytes += bytes_ready;
|
||||
return (*this->config.process_routine)(this->config, this->reserved);
|
||||
this->data_proc.data_bytes += bytes_ready;
|
||||
return (*this->data_proc.process_routine)(this->data_proc, this->reserved);
|
||||
}
|
||||
};
|
||||
|
||||
|
@@ -7,9 +7,9 @@ namespace JabyEngine {
|
||||
namespace FileProcessor {
|
||||
namespace Helper {
|
||||
template<typename T>
|
||||
static Progress exchange_and_execute_process_function(State::GenericProcessRoutine<T> process_routine, State::Configuration& config, T& state) {
|
||||
config.process_routine = reinterpret_cast<State::ProcessRoutine>(process_routine);
|
||||
return process_routine(config, state);
|
||||
static Progress exchange_and_execute_process_function(State::GenericProcessRoutine<T> process_routine, State::CDDataProcessor& data_proc, T& state) {
|
||||
data_proc.process_routine = reinterpret_cast<State::ProcessRoutine>(process_routine);
|
||||
return process_routine(data_proc, state);
|
||||
}
|
||||
|
||||
namespace DMA {
|
||||
@@ -17,8 +17,8 @@ namespace JabyEngine {
|
||||
uint32_t words_to_use;
|
||||
bool is_last;
|
||||
|
||||
static constexpr WordsReady calculate(const State::Configuration& config, size_t words_left) {
|
||||
const auto config_data_words = (config.data_bytes/sizeof(uint32_t));
|
||||
static constexpr WordsReady calculate(const State::CDDataProcessor& data_proc, size_t words_left) {
|
||||
const auto config_data_words = (data_proc.data_bytes/sizeof(uint32_t));
|
||||
const auto words_to_use = (config_data_words > words_left) ? words_left : config_data_words;
|
||||
|
||||
return {
|
||||
|
Reference in New Issue
Block a user