Pre Point2f Nuke

Fixed drawing,
Added general optimisations
This commit is contained in:
Bram Verhulst
2024-04-16 14:08:41 +02:00
parent f50597d1a5
commit 64e96ab209
13 changed files with 228 additions and 177 deletions

View File

@@ -23,8 +23,8 @@ WorldLevel::WorldLevel(Camera* camera, Rectf viewport): Level(camera),
// The grid is 34 x 50 big, the top center is 0,0 in world coords
for (size_t x { 0 }; x < WORLD_WIDTH; ++x) {
for (size_t y { 0 }; y < WORLD_HEIGHT; ++y) {
int actualX = x - WORLD_WIDTH / 2;
auto pos = Point2f { float(actualX * TILE_WIDTH), -float(y * TILE_HEIGHT) - TILE_HEIGHT };
const int actualX = x - WORLD_WIDTH / 2;
Point2f pos = Point2f { float(actualX * TILE_WIDTH), -float(y * TILE_HEIGHT) - TILE_HEIGHT };
GroundTileType* type = Tiles::AIR;
switch (utils::randRange(0, 2)) {
case 0:
@@ -40,13 +40,12 @@ WorldLevel::WorldLevel(Camera* camera, Rectf viewport): Level(camera),
std::cout << "??" << '\n';
}
m_gridManager.SetTileAtIndex(x, y, new WorldTile { pos, Tiles::DIRT, TextureManager::GetInstance(), &m_gridManager});
m_gridManager.SetTileAtIndex(x, y, new WorldTile { pos, type, TextureManager::GetInstance(), &m_gridManager});
}
}
for (size_t x { 0 }; x < WORLD_WIDTH; ++x) {
m_gridManager.GetTileAtIndex(x, 0)->SetTileType(Tiles::AIR);
}
}
WorldLevel::~WorldLevel() {
//delete m_pTextTexture;
@@ -57,8 +56,6 @@ void WorldLevel::Update(float elapsedSec) {
SDL_GetMouseState(&mouseX, &mouseY);
m_mousePos = Point2f { float(mouseX), float(mouseY) };
m_mousePos = m_pCamera->TransformMouse(m_mousePos);
//m_player.Update(elapsedSec, *this);
for (size_t x { 0 }; x < WORLD_WIDTH; ++x) {
@@ -85,7 +82,7 @@ void WorldLevel::Update(float elapsedSec) {
if(m_pSelectedTile != nullptr) {
surroundingTiles surroundingTiles = m_gridManager.GetSurroundingTiles(m_pSelectedTile);
TileDirection direction = TileDirection::TopMiddle;
std::array<TileDirection, 8> directions = {TileDirection::TopLeft, TileDirection::TopMiddle, TileDirection::TopRight, TileDirection::MiddleLeft, TileDirection::MiddleRight, TileDirection::BottomLeft, TileDirection::BottomMiddle, TileDirection::BottomRight};
const std::array<TileDirection, 8> directions = {TileDirection::TopLeft, TileDirection::TopMiddle, TileDirection::TopRight, TileDirection::MiddleLeft, TileDirection::MiddleRight, TileDirection::BottomLeft, TileDirection::BottomMiddle, TileDirection::BottomRight};
for(int i = 0; i < 8; i++) {
direction = directions[i];
@@ -96,9 +93,8 @@ void WorldLevel::Update(float elapsedSec) {
}
}
}
//m_player.Update(elapsedSec, *this);
m_player.Update(elapsedSec, *this);
Screen* screen = m_screenManager->GetCurrentScreen();
if (screen != nullptr) {
@@ -129,17 +125,6 @@ void WorldLevel::Draw() const {
}
}
//loop over worldtiles
for (int x { 0 }; x < WORLD_WIDTH; ++x) {
for (int y { 0 }; y < WORLD_HEIGHT; ++y) {
if (*m_gridManager.GetTileAtIndex(x, y)->GetTileType() != Tiles::AIR) {
Collision::CollisionRect rect = m_gridManager.GetTileAtIndex(x, y)->GetCollisionRect().getCollisionRect();
utils::SetColor(Colors::GREEN);
utils::DrawRect(rect.pos, rect.size.x, rect.size.y);
}
}
}
utils::SetColor(Colors::MAGENTA);
utils::FillEllipse(0, 0, 5, 5);
@@ -190,8 +175,8 @@ void WorldLevel::ProcessImGui() {
ImGui::EndMenu();
}
Point2f screenPos = utils::GetMousePos();
std::string mousePos = "Mouse Pos: (" + std::to_string(screenPos.x) + ", " + std::to_string(screenPos.y) + ")";
const Point2f screenPos = utils::GetMousePos();
const std::string mousePos = "Mouse Pos: (" + std::to_string(screenPos.x) + ", " + std::to_string(screenPos.y) + ")";
if(ImGui::BeginMenu(mousePos.c_str())) {
ImGui::EndMenu();

View File

@@ -10,7 +10,7 @@ class WorldLevel : public Level
{
public:
WorldLevel(Camera* camera, Rectf viewport);
~WorldLevel() override;
virtual ~WorldLevel() override;
WorldLevel(const WorldLevel& other) = default;
WorldLevel(WorldLevel&& other) = default;
@@ -39,7 +39,7 @@ private:
WorldTile* m_pSelectedTile { nullptr };
// ImGui Vars
bool m_ShowTextureManagerWindow { true };
bool m_ShowTextureManagerWindow { false };
bool m_ShowCameraWindow { false };
bool m_ShowPlayerInfo { false };
bool m_ShowPlayerInfo { true };
};