GIGA REFACTOR

This commit is contained in:
2022-03-02 18:51:42 +01:00
parent 553b2f6aad
commit 6df59b1487
92 changed files with 1807 additions and 1785 deletions

View File

@@ -20,17 +20,17 @@ VertexArray::VertexArray(unsigned int vertexCount) : m_VertexCount(vertexCount)
glGenVertexArrays(1, &m_ID);
}
void VertexArray::bind() const {
void VertexArray::Bind() const {
glBindVertexArray(m_ID);
}
void VertexArray::unbind() const {
void VertexArray::Unbind() const {
glBindVertexArray(0);
}
void VertexArray::bindVertexBuffer(VertexBuffer& VertexBuffer) {
VertexBuffer.bind();
VertexBuffer.bindVertexAttribs();
void VertexArray::BindVertexBuffer(VertexBuffer& VertexBuffer) {
VertexBuffer.Bind();
VertexBuffer.BindVertexAttribs();
m_VertexBuffers.push_back(std::move(VertexBuffer));
}
@@ -41,21 +41,21 @@ VertexBuffer::~VertexBuffer() {
VertexBuffer::VertexBuffer(const std::vector<float>& data, unsigned int stride) : m_DataStride(stride) {
glGenBuffers(1, &m_ID);
bind();
Bind();
glBufferData(GL_ARRAY_BUFFER, static_cast<GLsizeiptr>(data.size() * sizeof(float)), nullptr, GL_STATIC_DRAW);
glBufferSubData(GL_ARRAY_BUFFER, 0, static_cast<GLsizeiptr>(data.size() * sizeof(float)), data.data());
unbind();
Unbind();
}
void VertexBuffer::bind() const {
void VertexBuffer::Bind() const {
glBindBuffer(GL_ARRAY_BUFFER, m_ID);
}
void VertexBuffer::unbind() const {
void VertexBuffer::Unbind() const {
glBindBuffer(GL_ARRAY_BUFFER, 0);
}
void VertexBuffer::addVertexAttribPointer(unsigned int index, unsigned int coordinateSize, unsigned int offset) {
void VertexBuffer::AddVertexAttribPointer(unsigned int index, unsigned int coordinateSize, unsigned int offset) {
VertexAttribPointer pointer;
pointer.m_Index = index;
pointer.m_Size = coordinateSize;
@@ -63,7 +63,7 @@ void VertexBuffer::addVertexAttribPointer(unsigned int index, unsigned int coord
m_VertexAttribs.push_back(pointer);
}
void VertexBuffer::bindVertexAttribs() const {
void VertexBuffer::BindVertexAttribs() const {
for (const VertexAttribPointer& pointer : m_VertexAttribs) {
glEnableVertexAttribArray(pointer.m_Index);
glVertexAttribPointer(pointer.m_Index, static_cast<GLint>(pointer.m_Size), GL_FLOAT, false, m_DataStride * sizeof(float), reinterpret_cast<void*>(pointer.m_Offset));

View File

@@ -13,7 +13,7 @@
namespace TextureLoader {
unsigned int loadGLTexture(const char* fileName) {
unsigned int LoadGLTexture(const char* fileName) {
int width, height, comp;

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,
@@ -36,23 +36,23 @@ GL::VertexArray loadMobModel() {
};
GL::VertexBuffer positionVBO(positions, 2);
positionVBO.addVertexAttribPointer(0, 2, 0);
positionVBO.AddVertexAttribPointer(0, 2, 0);
GL::VertexBuffer colorVBO(colors, 1);
colorVBO.addVertexAttribPointer(1, 1, 0);
colorVBO.AddVertexAttribPointer(1, 1, 0);
GL::VertexArray mobVao(colors.size()); // each pos = 1 color
mobVao.bind();
mobVao.bindVertexBuffer(positionVBO);
mobVao.bindVertexBuffer(colorVBO);
mobVao.unbind();
mobVao.Bind();
mobVao.BindVertexBuffer(positionVBO);
mobVao.BindVertexBuffer(colorVBO);
mobVao.Unbind();
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;
@@ -62,8 +62,8 @@ GL::VertexArray loadWorldModel(const td::game::World* world) {
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);
td::game::TileIndex tileIndex = chunk->GetTileIndex(tileNumber);
td::game::TilePtr tile = world->GetTilePtr(tileIndex);
if (tile == nullptr)
continue;
@@ -78,7 +78,7 @@ GL::VertexArray loadWorldModel(const td::game::World* world) {
(float)chunkX + tileX + 1, (float)chunkY + tileY + 1,
});
const td::game::Color* tileColor = world->getTileColor(tile);
const td::game::Color* tileColor = world->GetTileColor(tile);
for (int i = 0; i < 6; i++) {
int color = 255;
@@ -96,9 +96,9 @@ GL::VertexArray loadWorldModel(const td::game::World* world) {
}
for (int spawnColor = 0; spawnColor < 2; spawnColor++) {
const game::Spawn& spawn = world->getTeam(game::TeamColor(spawnColor)).getSpawn();
float fromX = spawn.getTopLeft().getX(), toX = spawn.getBottomRight().getX();
float fromY = spawn.getTopLeft().getY(), toY = spawn.getBottomRight().getY();
const game::Spawn& spawn = world->GetTeam(game::TeamColor(spawnColor)).GetSpawn();
float fromX = spawn.GetTopLeft().GetX(), toX = spawn.GetBottomRight().GetX();
float fromY = spawn.GetTopLeft().GetY(), toY = spawn.GetBottomRight().GetY();
positions.insert(positions.end(), {
fromX, fromY,
@@ -112,9 +112,9 @@ GL::VertexArray loadWorldModel(const td::game::World* world) {
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;
color |= world->getSpawnColor(game::TeamColor(spawnColor)).b << 8;
color |= world->GetSpawnColor(game::TeamColor(spawnColor)).r << 24;
color |= world->GetSpawnColor(game::TeamColor(spawnColor)).g << 16;
color |= world->GetSpawnColor(game::TeamColor(spawnColor)).b << 8;
int newColorIndex = colors.size();
colors.push_back(0);
@@ -124,9 +124,9 @@ GL::VertexArray loadWorldModel(const td::game::World* world) {
}
for (int castleColor = 0; castleColor < 2; castleColor++) {
const game::TeamCastle& castle = world->getTeam(game::TeamColor(castleColor)).getCastle();
float fromX = castle.getTopLeft().getX(), toX = castle.getBottomRight().getX();
float fromY = castle.getTopLeft().getY(), toY = castle.getBottomRight().getY();
const game::TeamCastle& castle = world->GetTeam(game::TeamColor(castleColor)).GetCastle();
float fromX = castle.GetTopLeft().GetX(), toX = castle.GetBottomRight().GetX();
float fromY = castle.GetTopLeft().GetY(), toY = castle.GetBottomRight().GetY();
positions.insert(positions.end(), {
fromX, fromY,
@@ -140,9 +140,9 @@ GL::VertexArray loadWorldModel(const td::game::World* world) {
for (int i = 0; i < 6; i++) {
int color = 255;
color |= world->getSpawnColor(game::TeamColor(castleColor)).r << 24;
color |= world->getSpawnColor(game::TeamColor(castleColor)).g << 16;
color |= world->getSpawnColor(game::TeamColor(castleColor)).b << 8;
color |= world->GetSpawnColor(game::TeamColor(castleColor)).r << 24;
color |= world->GetSpawnColor(game::TeamColor(castleColor)).g << 16;
color |= world->GetSpawnColor(game::TeamColor(castleColor)).b << 8;
int newColorIndex = colors.size();
colors.push_back(0);
@@ -152,19 +152,19 @@ GL::VertexArray loadWorldModel(const td::game::World* world) {
}
GL::VertexBuffer positionVBO(positions, 2);
positionVBO.addVertexAttribPointer(0, 2, 0);
positionVBO.AddVertexAttribPointer(0, 2, 0);
GL::VertexBuffer colorVBO(colors, 1);
colorVBO.addVertexAttribPointer(1, 1, 0);
colorVBO.AddVertexAttribPointer(1, 1, 0);
GL::VertexArray worldVao(positions.size() / 2); // each pos = 2 vertecies
worldVao.bind();
worldVao.bindVertexBuffer(positionVBO);
worldVao.bindVertexBuffer(colorVBO);
worldVao.unbind();
worldVao.Bind();
worldVao.BindVertexBuffer(positionVBO);
worldVao.BindVertexBuffer(colorVBO);
worldVao.Unbind();
return worldVao;
}
GL::VertexArray loadTileSelectModel() {
GL::VertexArray LoadTileSelectModel() {
std::vector<float> positions = {
0, 0,
1, 0,
@@ -183,37 +183,37 @@ GL::VertexArray loadTileSelectModel() {
std::vector<float> colors(6, colorFloat);
GL::VertexBuffer positionVBO(positions, 2);
positionVBO.addVertexAttribPointer(0, 2, 0);
positionVBO.AddVertexAttribPointer(0, 2, 0);
GL::VertexBuffer colorVBO(colors, 1);
colorVBO.addVertexAttribPointer(1, 1, 0);
colorVBO.AddVertexAttribPointer(1, 1, 0);
GL::VertexArray tileSelectVao(positions.size() / 2); // each pos = 2 vertecies
tileSelectVao.bind();
tileSelectVao.bindVertexBuffer(positionVBO);
tileSelectVao.bindVertexBuffer(colorVBO);
tileSelectVao.unbind();
tileSelectVao.Bind();
tileSelectVao.BindVertexBuffer(positionVBO);
tileSelectVao.BindVertexBuffer(colorVBO);
tileSelectVao.Unbind();
return tileSelectVao;
}
RenderData loadTowerModel(game::TowerPtr tower) {
RenderData LoadTowerModel(game::TowerPtr tower) {
RenderData renderData;
float towerX, towerDX;
float towerY, towerDY;
if (tower->getSize() == game::TowerSize::Little) {
towerX = tower->getCenterX() - 1.5f;
towerDX = tower->getCenterX() + 1.5f;
if (tower->GetSize() == game::TowerSize::Little) {
towerX = tower->GetCenterX() - 1.5f;
towerDX = tower->GetCenterX() + 1.5f;
towerY = tower->getCenterY() - 1.5f;
towerDY = tower->getCenterY() + 1.5f;
towerY = tower->GetCenterY() - 1.5f;
towerDY = tower->GetCenterY() + 1.5f;
} else {
towerX = tower->getCenterX() - 2.5f;
towerDX = tower->getCenterX() + 2.5f;
towerX = tower->GetCenterX() - 2.5f;
towerDX = tower->GetCenterX() + 2.5f;
towerY = tower->getCenterY() - 2.5f;
towerDY = tower->getCenterY() + 2.5f;
towerY = tower->GetCenterY() - 2.5f;
towerDY = tower->GetCenterY() + 2.5f;
}
std::vector<float> positions = {
towerX, towerY,
@@ -227,7 +227,7 @@ RenderData loadTowerModel(game::TowerPtr tower) {
renderData.positions = positions;
std::uint8_t towerType = static_cast<std::uint8_t>(tower->getType());
std::uint8_t towerType = static_cast<std::uint8_t>(tower->GetType());
std::uint8_t r = 10 * towerType + 40, g = 5 * towerType + 30, b = 10 * towerType + 20;
float colorFloat;