Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Radiation re-work #47

Open
igentuman opened this issue Jan 2, 2024 · 0 comments
Open

Radiation re-work #47

igentuman opened this issue Jan 2, 2024 · 0 comments
Assignees
Labels
enhancement New feature or request

Comments

@igentuman
Copy link
Owner

you only store world capability data, no data per chunk

WorldRadiation

sourceMap <long, SourceTable> - stores the data
long represents BlockPos, and SourceTable stores all sources for that pos
update() method iterates map and calls update for each RadSource
same time we need to keep updated map with calculated data for faster simulation of radiation at any coordinates, will use that to get exposure for livingentities
calculatedMap <long or BlockPos, int radiation>

SourceTable

map or list of RadSources

RadSource

sourceID - (int) will use it to fallback radiation source backend (object) from our registry
timestamp - (int) last updated time
lifetime - int how long this source exists
radiation - digital value of radiation
update() - updates radiation value by current timestamp

RadSourceBackend

int[] stages - contains vector values how source radiation changes during time
during update we split decay_time by amount of stages and apply stage value for radiation change
so for any source we can define any behavior
for example int[]{4, 2, 0, -1, -4}
means it will increase radiation faster at the beginning of decay_time, then it will slowdown and after that will decrease radiation
int initial_radioactivity
int decay_time

public class BlockPosDistanceCalculator {

    public static double distanceSquared(BlockPos pos1, BlockPos pos2) {
        double dx = pos1.getX() - pos2.getX();
        double dy = pos1.getY() - pos2.getY();
        double dz = pos1.getZ() - pos2.getZ();
        
        return dx * dx + dy * dy + dz * dz;
    }

    public static void main(String[] args) {
        BlockPos pos1 = new BlockPos(1, 2, 3);
        BlockPos pos2 = new BlockPos(4, 5, 6);

        double distanceSq = distanceSquared(pos1, pos2);
        System.out.println("Squared distance between pos1 and pos2: " + distanceSq);
        
        // If you need the actual distance, you can take the square root of the squared distance.
        double distance = Math.sqrt(distanceSq);
        System.out.println("Distance between pos1 and pos2: " + distance);
    }
}

cache closest sources by entity pos. so if player stays in one place, algorithm won't have to iterate all know sources each time
and also we don't need to simulate that every tick, as we have timestamps we can simulate every second or whatever
next approach is not to use blockpos, but something like BlockPos/2..3..4
in this case cache will be used more efficiently, as entity will be able to do small movements. good for mobs

@igentuman igentuman self-assigned this Jan 2, 2024
@igentuman igentuman added the enhancement New feature or request label Jan 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant