Compare commits
No commits in common. "f7e1b3eab9976cdce081e9b199b09e2e38245ad5" and "9678e8c286e9cea11de67cf7ea70391a39af14f9" have entirely different histories.
f7e1b3eab9
...
9678e8c286
4 changed files with 5 additions and 58 deletions
|
@ -27,22 +27,6 @@ else ()
|
|||
ImGui-SFML::ImGui-SFML)
|
||||
endif()
|
||||
|
||||
if(TRACE_FRAMES)
|
||||
message("Building with Tracy")
|
||||
add_compile_definitions(TRACE_FRAMES)
|
||||
|
||||
include(FetchContent)
|
||||
FetchContent_Declare(
|
||||
Tracy
|
||||
GIT_REPOSITORY https://github.com/wolfpld/tracy.git
|
||||
GIT_TAG d46ffb4e9f132fc95bdd7d04207d8d669a9d4100
|
||||
)
|
||||
FetchContent_MakeAvailable(Tracy)
|
||||
|
||||
set(LIBS ${LIBS}
|
||||
TracyClient)
|
||||
endif()
|
||||
|
||||
add_compile_options(-Wall -Wextra)
|
||||
|
||||
add_executable(raycasting
|
||||
|
|
|
@ -1,24 +0,0 @@
|
|||
//
|
||||
// Created by trotfunky on 05/02/24.
|
||||
//
|
||||
|
||||
#ifndef RAYCASTING_FRAMETRACING_H
|
||||
#define RAYCASTING_FRAMETRACING_H
|
||||
|
||||
/*
|
||||
* Basic wrapper to allow enabling and disabling frame tracing using
|
||||
* Tracy.
|
||||
* https://github.com/wolfpld/tracy
|
||||
*/
|
||||
#ifdef TRACE_FRAMES
|
||||
#include "tracy/Tracy.hpp"
|
||||
#define FTrace_FrameMark FrameMark
|
||||
#define FTrace_Scope ZoneScoped
|
||||
#define FTrace_NamedScope(name) ZoneScopedN(name)
|
||||
#else
|
||||
#define FTrace_FrameMark
|
||||
#define FTrace_Scope
|
||||
#define FTrace_NamedScope(name)
|
||||
#endif /* TRACE_FRAMES */
|
||||
|
||||
#endif //RAYCASTING_FRAMETRACING_H
|
18
World.cpp
18
World.cpp
|
@ -9,7 +9,6 @@
|
|||
#include <imgui.h>
|
||||
#include <imgui-SFML.h>
|
||||
#endif
|
||||
#include "FrameTracing.h"
|
||||
|
||||
World::World(int w, int h, sf::Color groundColor, sf::Color ceilingColor, std::vector<BlockType> worldMap) :
|
||||
player(0,0,0), w(w), h(h), map(std::move(worldMap)),
|
||||
|
@ -118,7 +117,6 @@ RaycastResult World::castRay(float originX, float originY, float orientation) co
|
|||
* built around left-handed axes (x→,y↓), so the rendered world is
|
||||
* mirrored. This also explains some weird signs for rotations.
|
||||
*/
|
||||
FTrace_Scope;
|
||||
/* Offsets to get back on the grid from the ray's origin. */
|
||||
float hOffsetX;
|
||||
float hOffsetY;
|
||||
|
@ -179,12 +177,10 @@ RaycastResult World::castRay(float originX, float originY, float orientation) co
|
|||
int i = 0;
|
||||
float hCheckX = originX + hOffsetX;
|
||||
float hCheckY = hOffsetY;
|
||||
BlockType hHitBlock = BlockType::AIR;
|
||||
/* Bounds + sanity check. */
|
||||
while (hCheckX >= 0 && hCheckX <= static_cast<float>(w) &&
|
||||
hCheckY >= 0 && hCheckY <= static_cast<float>(h) && i < h) {
|
||||
hHitBlock = getBlock(floorf(hCheckX), floorf(hCheckY) + hRound);
|
||||
if (hHitBlock == BlockType::WALL) {
|
||||
if (getBlock(floorf(hCheckX), floorf(hCheckY) + hRound) == BlockType::WALL) {
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -196,12 +192,11 @@ RaycastResult World::castRay(float originX, float originY, float orientation) co
|
|||
i = 0;
|
||||
float vCheckX = vOffsetX;
|
||||
float vCheckY = originY + vOffsetY;
|
||||
BlockType vHitBlock = BlockType::AIR;
|
||||
|
||||
/* Bounds + sanity check. */
|
||||
while (vCheckX >= 0 && vCheckX < static_cast<float>(w) &&
|
||||
vCheckY >= 0 && vCheckY < static_cast<float>(h) && i < w) {
|
||||
vHitBlock = getBlock(floorf(vCheckX) + vRound, floorf(vCheckY));
|
||||
if (vHitBlock == BlockType::WALL) {
|
||||
if (getBlock(floorf(vCheckX) + vRound, floorf(vCheckY)) == BlockType::WALL) {
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -225,13 +220,13 @@ RaycastResult World::castRay(float originX, float originY, float orientation) co
|
|||
result.distance = vDist;
|
||||
result.hitX = vCheckX;
|
||||
result.hitY = vCheckY;
|
||||
result.hitBlock = vHitBlock;
|
||||
} else {
|
||||
result.distance = hDist;
|
||||
result.hitX = hCheckX;
|
||||
result.hitY = hCheckY;
|
||||
result.hitBlock = hHitBlock;
|
||||
}
|
||||
result.hitBlock = getBlock(floorf(result.hitX) + vRound,
|
||||
floorf(result.hitY));
|
||||
|
||||
return result;
|
||||
}
|
||||
|
@ -239,7 +234,6 @@ RaycastResult World::castRay(float originX, float originY, float orientation) co
|
|||
void World::fillColumn(sf::RenderWindow& window, unsigned int column,
|
||||
float scale, sf::Color fillColor)
|
||||
{
|
||||
FTrace_Scope;
|
||||
float columnHeight = static_cast<float>(window.getSize().y)*scale;
|
||||
sf::RectangleShape& pixelColumn = renderColumns[column];
|
||||
if (pixelColumn.getSize().y != columnHeight) {
|
||||
|
@ -255,7 +249,6 @@ void World::fillColumn(sf::RenderWindow& window, unsigned int column,
|
|||
|
||||
void World::render(sf::RenderWindow& window)
|
||||
{
|
||||
FTrace_Scope;
|
||||
float windowX = static_cast<float>(window.getSize().x);
|
||||
float windowY = static_cast<float>(window.getSize().y);
|
||||
/*
|
||||
|
@ -298,7 +291,6 @@ void World::render(sf::RenderWindow& window)
|
|||
}
|
||||
|
||||
void World::step(const float& stepTime) {
|
||||
FTrace_Scope;
|
||||
player.move(player.currentMoveSpeedX*stepTime,
|
||||
player.currentMoveSpeedY*stepTime);
|
||||
/* Undo last move if the player would end up in a wall. */
|
||||
|
|
5
main.cpp
5
main.cpp
|
@ -5,7 +5,6 @@
|
|||
#include <imgui.h>
|
||||
#include <imgui-SFML.h>
|
||||
#endif
|
||||
#include "FrameTracing.h"
|
||||
|
||||
#include "World.h"
|
||||
|
||||
|
@ -38,11 +37,8 @@ int main()
|
|||
sf::Clock frameTime;
|
||||
while (window.isOpen())
|
||||
{
|
||||
FTrace_NamedScope("MainLoop");
|
||||
|
||||
while (window.pollEvent(event))
|
||||
{
|
||||
FTrace_NamedScope("EventLoop");
|
||||
if (event.type == sf::Event::Closed) {
|
||||
window.close();
|
||||
continue;
|
||||
|
@ -139,7 +135,6 @@ int main()
|
|||
#endif
|
||||
|
||||
window.display();
|
||||
FTrace_FrameMark;
|
||||
}
|
||||
|
||||
#ifdef IMGUI
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue