cerus / cerus/maps

Optimizing raycasting operations

Open
#6 6 comments 0 reactions 0 assignees View on GitHub
enhancement good first issue hacktoberfest modtoberfest
Dominant language
Java
Stars
52
Forks
6
PR merge metrics
No merged PRs in 30d

Description

### Feature description

Hey,

I've been experimenting with making my own map rendering engine, and I'd like to leave some tips for just better overall performance:

There are 3 ways you can approach raycasting, it seems like you're doing method 1:

Method 1:
- Grab the start location, and add a very tiny miniscule offset, increment by that offset until you reach a frame. (It takes about 5 * 1/offset * distance operations, if your offset is 1/128, you're doing 640 iterations, measures at about 3ms / cast on my machine

Method 2 (1+):
- Grab the start location, and increment by the normalized offset, until there's a frame at the current block. Then, do a finer cast through method one (1-5 + (1/offset iterations, if there is a frame)) - About 5x better, measures at about 0.1ms / cast on my machine

Method 3:
- Grab the start location, and increment by the normalized offset. If there is a frame at the current block, estimate the frame's bounding box by grabbing the frame's center location, and shifting in the opposite direction of where the frame is looking at, you'll always end up with ceil(distance) iterations, instead of , measures at about 0.015ms / cast on my machine

Further optimizations:
- Cache the converted colors of your ColorMap, from what I've measured, mapping colors takes about 90 microseconds per color, but marginally less if cached.

### Relevant issues

_No response_

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.