Hunk interp

This commit is contained in:
Daniel Mills 2021-08-02 01:12:51 -04:00
parent d826f968b5
commit 0d90c1d960
3 changed files with 93 additions and 0 deletions

View File

@ -18,6 +18,7 @@
package com.volmit.iris.engine.hunk;
import com.volmit.iris.engine.data.B;
import com.volmit.iris.engine.hunk.io.HunkIOAdapter;
import com.volmit.iris.engine.hunk.storage.*;
import com.volmit.iris.engine.hunk.view.*;
@ -42,6 +43,7 @@ import java.io.OutputStream;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.function.Predicate;
@SuppressWarnings("ALL")
@ -58,6 +60,21 @@ public interface Hunk<T> {
return new HunkView<T>(src);
}
static <A,B> Hunk<B> convertedReadView(Hunk<A> src, Function<A, B> reader)
{
return new FunctionalHunkView<A, B>(src, reader, null);
}
static <A,B> Hunk<B> convertedWriteView(Hunk<A> src, Function<B, A> writer)
{
return new FunctionalHunkView<A, B>(src, null, writer);
}
static <A,B> Hunk<B> convertedReadWriteView(Hunk<A> src, Function<A, B> reader, Function<B, A> writer)
{
return new FunctionalHunkView<A, B>(src, reader, writer);
}
static Hunk<Biome> view(BiomeGrid biome) {
return new BiomeGridHunkView(biome);
}

View File

@ -0,0 +1,75 @@
/*
* Iris is a World Generator for Minecraft Bukkit Servers
* Copyright (c) 2021 Arcane Arts (Volmit Software)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.volmit.iris.engine.hunk.view;
import com.volmit.iris.engine.hunk.Hunk;
import java.util.function.Function;
public class FunctionalHunkView<R, T> implements Hunk<T> {
private final Hunk<R> src;
private final Function<R, T> converter;
private final Function<T, R> backConverter;
public FunctionalHunkView(Hunk<R> src, Function<R, T> converter, Function<T, R> backConverter) {
this.src = src;
this.converter = converter;
this.backConverter = backConverter;
}
@Override
public void setRaw(int x, int y, int z, T t) {
if(backConverter == null)
{
throw new UnsupportedOperationException("You cannot write to this hunk (Read Only)");
}
src.setRaw(x,y,z,backConverter.apply(t));
}
@Override
public T getRaw(int x, int y, int z) {
if(converter == null)
{
throw new UnsupportedOperationException("You cannot read this hunk (Write Only)");
}
return converter.apply(src.getRaw(x, y, z));
}
@Override
public int getWidth() {
return src.getWidth();
}
@Override
public int getDepth() {
return src.getDepth();
}
@Override
public int getHeight() {
return src.getHeight();
}
@Override
public Hunk<T> getSource() {
throw new UnsupportedOperationException("You cannot read this hunk's source because it's a different type.");
}
}

View File

@ -18,6 +18,7 @@
package com.volmit.iris.engine.object;
import com.volmit.iris.engine.hunk.Hunk;
import com.volmit.iris.engine.interpolation.InterpolationMethod3D;
import com.volmit.iris.engine.interpolation.IrisInterpolation;
import com.volmit.iris.engine.object.annotations.Desc;