Prepare CircularBuffer

This commit is contained in:
Björn Gaier 2022-12-16 21:54:01 +01:00
parent d193856e2a
commit 53f8d43342
3 changed files with 57 additions and 1 deletions

View File

@ -0,0 +1,54 @@
#ifndef __JABYENGINE_CIRCULAR_BUFFER_HPP__
#define __JABYENGINE_CIRCULAR_BUFFER_HPP__
#include "../../stddef.h"
namespace JabyEngine {
class CircularBuffer {
private:
typedef uint32_t T;
T* start_adr = nullptr;
size_t end_idx = 0;
size_t read_idx = 0;
size_t write_idx = 0;
static size_t increment(size_t cur_idx, size_t end_idx) {
static constexpr size_t Step = 1;
cur_idx += Step;
if(cur_idx >= end_idx) {
return (end_idx - cur_idx);
}
return cur_idx;
}
public:
CircularBuffer() = default;
void setup(T* buffer_start_adr, size_t element_count) {
this->start_adr = buffer_start_adr;
this->end_idx = element_count;
this->read_idx = 0;
this->write_idx = 0;
}
T* push() {
const auto new_idx = CircularBuffer::increment(this->write_idx, this->end_idx);
if(new_idx != this->read_idx) {
auto* dst = (this->start_adr + this->write_idx);
this->write_idx = new_idx;
return dst;
}
return nullptr;
}
constexpr bool has_data() const {
return (this->read_idx != this->write_idx);
}
};
}
#endif //!__JABYENGINE_CIRCULAR_BUFFER_HPP__

View File

@ -24,6 +24,7 @@ namespace CDFileProcessor {
const auto& lba_info = overlay_lbas[file.rel_lba_idx];
state.setup(lba_info.lba, lba_info.size, file.payload);
//while(state.process());???
}
}
}

View File

@ -1 +1,2 @@
#include <PSX/File/Processor/cd_file_processor.hpp>
#include <PSX/File/Processor/cd_file_processor.hpp>