1
0
Fork 0
Commit graph

23 commits

Author SHA1 Message Date
f7e1b3eab9 World: Fix wrong block type being returned in castRay
The GetBlock() call has specific offsets that are angle and axis dependent to get the correct
square on the grid from the coordinates of a hit.
This is something that I forgot when introducing the RaycastResult struct, and just used
the first GetBlock() as a common call, returning wrong types in some cases.

As with the hit coordinates, save the type of block hit and use that depending on
the closest hit later, rather than a common and wrong GetBlock().
2024-02-05 23:04:19 +00:00
7241ed7321 Debug: Support frame tracing via Tracy
Use CMake FetchContent to pull tracy sources and build it if frame tracing is enabled.
As frame tracing requires annotations in the code, create a wrapper that replaces them
with our own defines that are empty when tracing is not enabled.
2024-02-05 13:55:27 +00:00
8199fd3449 World: Introduce a struct for raycast results
In order to implement more complexe behaviors, more information than the distance
is needed from a raycast.
Add a new struct to store and return this information, currently hit position
and hit type, and update castRay to return that instead.
2024-02-05 00:33:01 +00:00
b0c9d24787 World: Add projection correction factor
Rays are all sent from the center of the camera plane, which makes rays
with a greater angle longer than if they were properly sent perpendicularly
from the camera plane.

Correct this by projecting the ray to the look direction (which is
perpendicular to the camera plane).
2024-02-04 21:04:07 +00:00
10d0dee35d World: Re-use RectangleShapes for rendering
sf::RectangleShapes were created brand new each frame, which takes a lot of time.
Instead, keep an array of them available and update them instead of creating new ones.

This also allows a nice optimization of only updating them if needed, by checking their
previous value.

Update the available number of rects when the window resizes.
2024-01-29 00:25:57 +00:00
c875adfcbb main/debug: Make the frame timing graph a sliding window
Use memmove to shift the whole array by one measure to the left,
dropping the oldest one and adding a new one at the head.
This creates a better visual effect of a graph being produced on the right
and scrolling to the left, rather than a looping writing head that overwrites
previous data.
2024-01-29 00:21:14 +00:00
bb20d4a520 Clean-up: Change indentation to tabs 2024-01-28 22:08:35 +00:00
9c9ec45304 World/Debug: Properly check the MapEdit status
If a Dear ImGui window is collapsed or closed, ImGui::Begin returns false.
Check it properly to bypass rendering if is indeed not needed.
2024-01-28 22:05:20 +00:00
0cd421de3c World: Move the scale factor to a constant
Clear up the computation and split the result from the ray cast to the scale
factor.

Update the castRay explanations to add the issue of unmatched axes.
2024-01-28 21:58:36 +00:00
a0bdfce61a Colors: Introduce color type abstraction
SFML and Dear ImGui have incompatible color types, abstract them through
a new Color class which has conversions.

Centralize color constants in a namespace as well.
2024-01-26 23:07:25 +00:00
f25a649144 Debug: Introduce Dear ImGui interfaces
Introduce Dear ImGui to the CMakeBuild, allow building without it.

Add two debug interfaces : one FPS counter and frame time graph,
one map visualizer and editor.
2024-01-26 23:05:11 +00:00
52fdd8328f World: Rename wallColor to fillColor
As this function will get more generic, make the names more generic.

Fix some comments and indentation.
2024-01-26 21:34:13 +00:00
81aaafd26d World: make CastRay generic
Previously CastRay did the scale computation and used the player view statistics.
This makes it quite specialized, and the rest of the computations are made outside.

Move the computations in the render function and make castRay generic.
2024-01-25 22:31:39 +00:00
fa75fe4bba World: Clean warnings, optimize GetBlock
World has a lot of type conversion warnings. Take care of most of them,
for a slight performance hit ( :( ).
Re-order constructor parameters to match declaration.
Move FillColumn to a more appropriate place.

GetBlock gets called a lot : use direct memory access of the vector
rather than going through bounds checks with .at().
Introduce an integer overload to remove warnings.
2024-01-24 23:16:59 +00:00
7fe17df587 main: Clean up, handle resize
Handle window resizes by resizing the view frame as well.

Clean up the event handling to allow interleaving other code between
different checks.
Remove early first frame, handle it like the others.
2024-01-24 23:09:59 +00:00
804f0272f8 Implement moving the player
Player: Add rotation and linear speeds, as well as their current state.
Player: Allow to move in the local coordinates and compute
    world-speed equivalent.
Player: Update movement axis while rotating.

World: Add a function to advance a step.
Main: Handle key events, add world step in the main loop.
2024-01-21 22:11:46 +00:00
b359ff171f World: Implement raycaster
Implement the basic raycaster, checking every block intersection and the block
linked to that position.
Split the screen uniformally along the width.
Add data needed for camera maths in the Player class
Specify constraints on the raycast parameters.

Render the screen using the raycasts.
Call the renderer in the main loop.
2024-01-21 22:08:44 +00:00
34625a841d World: Use nicer custom colors 2024-01-21 20:41:19 +00:00
389170eefe Player: Fix rotate
Rotation wasn't handled properly at all.
Properly bound between 0 and 360, and use
a proper modulo for floats.

Switch to float to have a more fluid rotation
between frames.
2024-01-21 20:31:51 +00:00
b00365a721 License as MIT 2023-12-30 14:56:26 +01:00
c7384ba9ba Pick back up and comment
Clean placeholder code to get it running.
Add comments to clarify working, add TODOs in main,
add some references for the maths.
2023-12-30 14:50:35 +01:00
59939d182b Ajout de la fonction render au monde
Joueur déplaçable
début du cast de rayon
Trop fatigué pour faire de la trigo
2019-06-01 06:42:29 +02:00
76306196c0 First commit, world map creation 2019-05-27 13:50:49 +02:00