build
This commit is contained in:
parent
0ccb4dbdd9
commit
13132ccfea
@ -272,7 +272,7 @@ int compile_src_dir()
|
||||
#endif
|
||||
|
||||
command.push_back("-I" + INC_DIR.string());
|
||||
command.push_back("-std=c++23");
|
||||
command.push_back("-std=c++20");
|
||||
command.push_back("-Wall");
|
||||
#ifdef Wextra
|
||||
command.push_back("-Wextra");
|
||||
@ -368,7 +368,7 @@ void build_as_one()
|
||||
#endif
|
||||
|
||||
command.push_back("-I" + INC_DIR.string());
|
||||
command.push_back("-std=c++23");
|
||||
command.push_back("-std=c++20");
|
||||
command.push_back("-Wall");
|
||||
#ifdef Wextra
|
||||
command.push_back("-Wextra");
|
||||
|
@ -1,37 +0,0 @@
|
||||
#ifndef BUFFER_HPP
|
||||
#define BUFFER_HPP
|
||||
|
||||
#include <cstdint>
|
||||
#include <string>
|
||||
|
||||
class Buffer
|
||||
{
|
||||
|
||||
public:
|
||||
uint8_t *buffer = nullptr;
|
||||
size_t taken = 0;
|
||||
size_t size = 0;
|
||||
|
||||
Buffer(size_t size);
|
||||
Buffer();
|
||||
~Buffer();
|
||||
bool resize(size_t new_size);
|
||||
uint32_t add_end(uint8_t *data, size_t data_size);
|
||||
int add_middle(uint8_t *data, size_t data_size, size_t index);
|
||||
|
||||
// Removes data from buffer without checking if it's in the buffer
|
||||
void remove_fast(uint8_t *data, size_t data_size);
|
||||
|
||||
void remove(size_t index, size_t data_size);
|
||||
|
||||
size_t find(uint8_t *data, size_t data_size);
|
||||
|
||||
void remove(uint8_t *data, size_t data_size);
|
||||
|
||||
void clear() { taken = 0; }
|
||||
|
||||
bool save_to_file(std::string file_path);
|
||||
bool load_from_file(std::string file_path);
|
||||
};
|
||||
|
||||
#endif
|
@ -1,15 +0,0 @@
|
||||
#include "values/Buffer.hpp"
|
||||
|
||||
class RandBuffer
|
||||
{
|
||||
public:
|
||||
RandBuffer() = default;
|
||||
~RandBuffer() = default;
|
||||
|
||||
void reset();
|
||||
float next();
|
||||
|
||||
private:
|
||||
Buffer m_buffer;
|
||||
size_t m_pos = 0;
|
||||
};
|
@ -1,140 +0,0 @@
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <cstring>
|
||||
|
||||
#include "values/Buffer.hpp"
|
||||
|
||||
Buffer::Buffer()
|
||||
{
|
||||
buffer = nullptr;
|
||||
size = 0;
|
||||
taken = 0;
|
||||
}
|
||||
|
||||
Buffer::Buffer(size_t size)
|
||||
{
|
||||
this->size = size;
|
||||
this->buffer = new uint8_t[size];
|
||||
}
|
||||
|
||||
Buffer::~Buffer()
|
||||
{
|
||||
if (buffer)
|
||||
delete[] buffer;
|
||||
}
|
||||
|
||||
bool Buffer::resize(size_t new_size)
|
||||
{
|
||||
if (size >= new_size)
|
||||
return true;
|
||||
uint8_t *new_buffer = (uint8_t *)realloc(buffer, new_size);
|
||||
if (!new_buffer)
|
||||
{
|
||||
printf("Error resizing buffer\n");
|
||||
return false;
|
||||
}
|
||||
buffer = new_buffer;
|
||||
size = new_size;
|
||||
return true;
|
||||
}
|
||||
|
||||
uint32_t Buffer::add_end(uint8_t *data, size_t data_size)
|
||||
{
|
||||
if (taken + data_size > size)
|
||||
if (!resize((size + data_size) * 2))
|
||||
return -1;
|
||||
|
||||
memcpy(buffer + taken, data, data_size);
|
||||
taken += data_size;
|
||||
return taken - data_size;
|
||||
}
|
||||
|
||||
int Buffer::add_middle(uint8_t *data, size_t data_size, size_t index)
|
||||
{
|
||||
if (taken + data_size > size)
|
||||
if (!resize((size + data_size) * 2))
|
||||
return -1;
|
||||
memmove(buffer + index + data_size, buffer + index, taken - index);
|
||||
memcpy(buffer + index, data, data_size);
|
||||
taken += data_size;
|
||||
return index;
|
||||
}
|
||||
|
||||
void Buffer::remove_fast(uint8_t *data, size_t data_size)
|
||||
{
|
||||
size_t index = data - buffer;
|
||||
if (index < 0 || index > taken || index + data_size > taken)
|
||||
{
|
||||
printf("Error removing from buffer\n");
|
||||
return;
|
||||
}
|
||||
memmove(buffer + index, buffer + index + data_size, taken - index - data_size);
|
||||
taken -= data_size;
|
||||
}
|
||||
|
||||
void Buffer::remove(size_t index, size_t data_size)
|
||||
{
|
||||
if (index + data_size > taken)
|
||||
{
|
||||
printf("Error removing from buffer\n");
|
||||
return;
|
||||
}
|
||||
memmove(buffer + index, buffer + index + data_size, taken - index - data_size);
|
||||
taken -= data_size;
|
||||
}
|
||||
|
||||
size_t Buffer::find(uint8_t *data, size_t data_size)
|
||||
{
|
||||
for (size_t i = 0; i < taken; i++)
|
||||
if (memcmp(buffer + i, data, data_size) == 0)
|
||||
return i;
|
||||
|
||||
return SIZE_MAX;
|
||||
}
|
||||
|
||||
void Buffer::remove(uint8_t *data, size_t data_size)
|
||||
{
|
||||
size_t index = find(data, data_size);
|
||||
if (index == SIZE_MAX)
|
||||
{
|
||||
printf("Error removing from buffer\n");
|
||||
return;
|
||||
}
|
||||
remove(index, data_size);
|
||||
}
|
||||
|
||||
bool Buffer::save_to_file(std::string file_path)
|
||||
{
|
||||
std::ofstream file(file_path, std::ios::binary | std::ios::out);
|
||||
if (!file.is_open())
|
||||
{
|
||||
printf("Error saving file\n");
|
||||
return false;
|
||||
}
|
||||
file.write((char *)this->buffer, this->taken);
|
||||
file.close();
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Buffer::load_from_file(std::string file_path)
|
||||
{
|
||||
std::ifstream file(file_path, std::ios::binary | std::ios::in);
|
||||
if (!file.is_open())
|
||||
return false;
|
||||
|
||||
file.seekg(0, std::ios::end);
|
||||
|
||||
size_t file_size = file.tellg();
|
||||
resize(file_size);
|
||||
|
||||
file.seekg(0, std::ios::beg);
|
||||
file.read((char *)buffer, size);
|
||||
|
||||
if (file)
|
||||
taken = file_size;
|
||||
else
|
||||
taken = file.gcount();
|
||||
|
||||
file.close();
|
||||
return true;
|
||||
}
|
@ -1,20 +0,0 @@
|
||||
#include "values/RandBuffer.hpp"
|
||||
#include "values/mrand.hpp"
|
||||
|
||||
void RandBuffer::reset()
|
||||
{
|
||||
m_buffer.clear();
|
||||
m_pos = 0;
|
||||
}
|
||||
|
||||
float RandBuffer::next()
|
||||
{
|
||||
if (m_pos * 4 < m_buffer.taken)
|
||||
{
|
||||
return ((float *)m_buffer.buffer)[m_pos++];
|
||||
}
|
||||
float ret = mrand::getFloat();
|
||||
m_buffer.add_end((uint8_t *)&ret, sizeof(float));
|
||||
m_pos++;
|
||||
return ret;
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user