refactor: format code

This commit is contained in:
2021-09-19 17:33:16 +02:00
parent 52a143769e
commit 0856ca47ca
71 changed files with 1102 additions and 1110 deletions

View File

@@ -11,64 +11,64 @@
using namespace gl;
namespace GL{
namespace GL {
VertexArray::~VertexArray(){
if(m_ID != 0)
glDeleteVertexArrays(1, &m_ID);
}
VertexArray::~VertexArray() {
if (m_ID != 0)
glDeleteVertexArrays(1, &m_ID);
}
VertexArray::VertexArray(unsigned int vertexCount) : m_VertexCount(vertexCount){
glGenVertexArrays(1, &m_ID);
}
VertexArray::VertexArray(unsigned int vertexCount) : m_VertexCount(vertexCount) {
glGenVertexArrays(1, &m_ID);
}
void VertexArray::bind() const{
glBindVertexArray(m_ID);
}
void VertexArray::bind() const {
glBindVertexArray(m_ID);
}
void VertexArray::unbind() const{
glBindVertexArray(0);
}
void VertexArray::unbind() const {
glBindVertexArray(0);
}
void VertexArray::bindVertexBuffer(VertexBuffer& VertexBuffer){
VertexBuffer.bind();
VertexBuffer.bindVertexAttribs();
m_VertexBuffers.push_back(std::move(VertexBuffer));
}
void VertexArray::bindVertexBuffer(VertexBuffer& VertexBuffer) {
VertexBuffer.bind();
VertexBuffer.bindVertexAttribs();
m_VertexBuffers.push_back(std::move(VertexBuffer));
}
VertexBuffer::~VertexBuffer(){
if(m_ID != 0)
glDeleteBuffers(1, &m_ID);
}
VertexBuffer::~VertexBuffer() {
if (m_ID != 0)
glDeleteBuffers(1, &m_ID);
}
VertexBuffer::VertexBuffer(const std::vector<float>& data, unsigned int stride) : m_DataStride(stride){
glGenBuffers(1, &m_ID);
bind();
glBufferData(GL_ARRAY_BUFFER, data.size() * sizeof(float), nullptr, GL_STATIC_DRAW);
glBufferSubData(GL_ARRAY_BUFFER, 0, data.size() * sizeof(float), data.data());
unbind();
}
VertexBuffer::VertexBuffer(const std::vector<float>& data, unsigned int stride) : m_DataStride(stride) {
glGenBuffers(1, &m_ID);
bind();
glBufferData(GL_ARRAY_BUFFER, data.size() * sizeof(float), nullptr, GL_STATIC_DRAW);
glBufferSubData(GL_ARRAY_BUFFER, 0, data.size() * sizeof(float), data.data());
unbind();
}
void VertexBuffer::bind() const{
glBindBuffer(GL_ARRAY_BUFFER, m_ID);
}
void VertexBuffer::bind() const {
glBindBuffer(GL_ARRAY_BUFFER, m_ID);
}
void VertexBuffer::unbind() const{
glBindBuffer(GL_ARRAY_BUFFER, 0);
}
void VertexBuffer::unbind() const {
glBindBuffer(GL_ARRAY_BUFFER, 0);
}
void VertexBuffer::addVertexAttribPointer(unsigned int index, unsigned int coordinateSize, unsigned int offset){
VertexAttribPointer pointer;
pointer.m_Index = index;
pointer.m_Size = coordinateSize;
pointer.m_Offset = offset;
m_VertexAttribs.push_back(pointer);
}
void VertexBuffer::addVertexAttribPointer(unsigned int index, unsigned int coordinateSize, unsigned int offset) {
VertexAttribPointer pointer;
pointer.m_Index = index;
pointer.m_Size = coordinateSize;
pointer.m_Offset = offset;
m_VertexAttribs.push_back(pointer);
}
void VertexBuffer::bindVertexAttribs() const{
for(const VertexAttribPointer& pointer : m_VertexAttribs){
glEnableVertexAttribArray(pointer.m_Index);
glVertexAttribPointer(pointer.m_Index, pointer.m_Size, GL_FLOAT, false, m_DataStride * sizeof(float), (void*)(intptr_t) pointer.m_Offset);
}
void VertexBuffer::bindVertexAttribs() const {
for (const VertexAttribPointer& pointer : m_VertexAttribs) {
glEnableVertexAttribArray(pointer.m_Index);
glVertexAttribPointer(pointer.m_Index, pointer.m_Size, GL_FLOAT, false, m_DataStride * sizeof(float), (void*)(intptr_t)pointer.m_Offset);
}
}
}

View File

@@ -21,8 +21,8 @@ const unsigned int loadGLTexture(const char* fileName) {
const unsigned char* image = stbi_load(fileName, &width, &height, &comp, STBI_rgb_alpha);
if (image == nullptr) {
std::cerr << "Erreur lors du chargement de la texture !" << std::endl;
throw(std::runtime_error("Failed to load texture"));
std::cerr << "Erreur lors du chargement de la texture !" << std::endl;
throw(std::runtime_error("Failed to load texture"));
}
GLuint textureID;
@@ -34,13 +34,13 @@ const unsigned int loadGLTexture(const char* fileName) {
if (comp == 3)
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width, height, 0, GL_RGB,
GL_UNSIGNED_BYTE, image);
GL_UNSIGNED_BYTE, image);
else if (comp == 4)
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA,
GL_UNSIGNED_BYTE, image);
GL_UNSIGNED_BYTE, image);
glBindTexture(GL_TEXTURE_2D, 0);
stbi_image_free((void*) image);
stbi_image_free((void*)image);
return textureID;
}
}

View File

@@ -10,7 +10,7 @@ namespace render {
namespace WorldLoader {
GL::VertexArray loadMobModel(){
GL::VertexArray loadMobModel() {
std::vector<float> positions = {
-0.5, -0.5,
0.5, -0.5,
@@ -48,19 +48,19 @@ GL::VertexArray loadMobModel(){
return mobVao;
}
GL::VertexArray loadWorldModel(const td::game::World* world){
GL::VertexArray loadWorldModel(const td::game::World* world) {
std::vector<float> positions;
std::vector<float> colors;
for (const auto& chunkInfo : world->getChunks()){
for (const auto& chunkInfo : world->getChunks()) {
const td::game::ChunkCoord& coords = chunkInfo.first;
td::game::ChunkPtr chunk = chunkInfo.second;
std::int32_t chunkX = coords.first * td::game::Chunk::ChunkWidth;
std::int32_t chunkY = coords.second * td::game::Chunk::ChunkHeight;
for (int tileY = 0; tileY < td::game::Chunk::ChunkHeight; tileY++){
for (int tileX = 0; tileX < td::game::Chunk::ChunkWidth; tileX++){
for (int tileY = 0; tileY < td::game::Chunk::ChunkHeight; tileY++) {
for (int tileX = 0; tileX < td::game::Chunk::ChunkWidth; tileX++) {
int tileNumber = tileY * td::game::Chunk::ChunkWidth + tileX;
td::game::TileIndex tileIndex = chunk->getTileIndex(tileNumber);
td::game::TilePtr tile = world->getTilePtr(tileIndex);
@@ -100,7 +100,7 @@ GL::VertexArray loadWorldModel(const td::game::World* world){
const td::game::Color* tileColor = world->getTileColor(tile);
for (int i = 0; i < 6; i++){
for (int i = 0; i < 6; i++) {
int color = 255;
color |= tileColor->r << 24;
color |= tileColor->g << 16;
@@ -115,7 +115,7 @@ GL::VertexArray loadWorldModel(const td::game::World* world){
}
}
for (int spawnColor = 0; spawnColor < 2; spawnColor++){
for (int spawnColor = 0; spawnColor < 2; spawnColor++) {
const game::Spawn& spawn = world->getTeam(game::TeamColor(spawnColor)).getSpawn();
float fromX = spawn.x - 2, toX = spawn.x + 3;
float fromY = spawn.y - 2, toY = spawn.y + 3;
@@ -130,7 +130,7 @@ GL::VertexArray loadWorldModel(const td::game::World* world){
toX, fromY,
});
for (int i = 0; i < 6; i++){
for (int i = 0; i < 6; i++) {
int color = 255;
color |= world->getSpawnColor(game::TeamColor(spawnColor)).r << 24;
color |= world->getSpawnColor(game::TeamColor(spawnColor)).g << 16;
@@ -156,7 +156,7 @@ GL::VertexArray loadWorldModel(const td::game::World* world){
return worldVao;
}
GL::VertexArray loadTileSelectModel(){
GL::VertexArray loadTileSelectModel() {
std::vector<float> positions = {
0, 0,
1, 0,
@@ -170,7 +170,7 @@ GL::VertexArray loadTileSelectModel(){
int color = 255 << 24 | 255 << 16 | 255 << 8 | 150;
float colorFloat;
memcpy((std::uint8_t*) &colorFloat, &color, sizeof(float));
memcpy((std::uint8_t*)&colorFloat, &color, sizeof(float));
std::vector<float> colors(6, colorFloat);