61 lines
2.3 KiB
C++
61 lines
2.3 KiB
C++
#pragma once
|
|
#include "../../Auxiliary/types.hpp"
|
|
#include "../cd_file_types.hpp"
|
|
|
|
namespace JabyEngine {
|
|
namespace FileProcessor {
|
|
class State {
|
|
public:
|
|
struct Reserved {
|
|
uint32_t reserved[8];
|
|
};
|
|
|
|
struct Configuration;
|
|
|
|
template<typename T>
|
|
using GenericProcessRoutine = Progress (*)(Configuration&, T&);
|
|
|
|
typedef GenericProcessRoutine<Reserved> ProcessRoutine;
|
|
|
|
// TODO: Better name!!!!
|
|
struct Configuration {
|
|
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) {
|
|
return {reinterpret_cast<ProcessRoutine>(process_routine), data_adr};
|
|
}
|
|
|
|
constexpr void processed(size_t bytes) {
|
|
this->data_adr += bytes;
|
|
this->data_bytes -= bytes;
|
|
}
|
|
};
|
|
|
|
Configuration config;
|
|
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)};
|
|
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);
|
|
}
|
|
};
|
|
|
|
// The nothing state
|
|
State create(const uint32_t* data_adr, const Nothing& nothing);
|
|
State create(const uint32_t* data_adr, const SimpleTIM& file);
|
|
State create(const uint32_t* data_adr, const TIM& file);
|
|
State create(const uint32_t* data_adr, const VAG& file);
|
|
|
|
State create_custom(const uint32_t* data_adr, const CDFileType_t& file_type, const CDFile::Payload& payload);
|
|
}
|
|
} |