Fixing the new classes
This commit is contained in:
@@ -49,53 +49,53 @@ public class PosToGenerateContainer
|
||||
nearSize--;
|
||||
}
|
||||
maxNearSize--;
|
||||
index = posToGenerate.length - farSize - 1;
|
||||
|
||||
if(farSize == 1)
|
||||
posToGenerate[index] = tempPos;
|
||||
} else //farSize == maxFarSize, the far section is full
|
||||
}
|
||||
index = posToGenerate.length - farSize;
|
||||
if (!(farSize == maxFarSize && LevelPosUtil.compareLevelAndDistance(tempPos, posToGenerate[index]) >= 0))
|
||||
{
|
||||
index = posToGenerate.length - farSize;
|
||||
//The max far pos is smaller than the one we want to insert
|
||||
if (LevelPosUtil.compareLevelAndDistance(tempPos, posToGenerate[index]) >= 0)
|
||||
while(index < posToGenerate.length - 1 && LevelPosUtil.compareLevelAndDistance(tempPos, posToGenerate[index + 1]) <= 0)
|
||||
{
|
||||
index = posToGenerate.length;
|
||||
posToGenerate[index] = posToGenerate[index + 1];
|
||||
index++;
|
||||
}
|
||||
if(index <= posToGenerate.length - 1)
|
||||
posToGenerate[index] = tempPos;
|
||||
}
|
||||
|
||||
while(index < posToGenerate.length - 1 && LevelPosUtil.compareLevelAndDistance(tempPos, posToGenerate[index + 1]) <= 0)
|
||||
{
|
||||
posToGenerate[index] = posToGenerate[index + 1];
|
||||
index++;
|
||||
}
|
||||
if(index <= posToGenerate.length - 1)
|
||||
posToGenerate[index] = tempPos;
|
||||
|
||||
} else
|
||||
{//We are introducing a position in the near array
|
||||
if (nearSize < maxNearSize)
|
||||
{
|
||||
nearSize++;
|
||||
index = nearSize - 1;
|
||||
} else //nearSize == maxNearSize, the far section is full
|
||||
{
|
||||
//The max near pos is smaller than the one we want to insert
|
||||
//We remove the max
|
||||
index = nearSize - 1;
|
||||
if (LevelPosUtil.compareDistance(tempPos, posToGenerate[index]) >= 0)
|
||||
{
|
||||
index = -1;
|
||||
}
|
||||
}
|
||||
index = nearSize - 1;
|
||||
|
||||
while(index > 0 && LevelPosUtil.compareDistance(tempPos, posToGenerate[index - 1]) <= 0)
|
||||
{
|
||||
posToGenerate[index] = posToGenerate[index - 1];
|
||||
index--;
|
||||
if(!(nearSize >= maxNearSize && LevelPosUtil.compareDistance(tempPos, posToGenerate[index]) >= 0)){
|
||||
|
||||
while(index > 0 && LevelPosUtil.compareDistance(tempPos, posToGenerate[index - 1]) <= 0)
|
||||
{
|
||||
posToGenerate[index] = posToGenerate[index - 1];
|
||||
index--;
|
||||
}
|
||||
if(index >= 0)
|
||||
posToGenerate[index] = tempPos;
|
||||
}
|
||||
if(index >= 0)
|
||||
posToGenerate[index] = tempPos;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public int getNumberOfPos()
|
||||
{
|
||||
return farSize + nearSize;
|
||||
}
|
||||
|
||||
public int[] getNthPos(int n)
|
||||
{
|
||||
int index;
|
||||
if(n > farSize * 2)
|
||||
index = n - farSize;
|
||||
else
|
||||
if (n % 2 == 0)
|
||||
index = n/2;
|
||||
else
|
||||
index = posToGenerate.length - n/2 - 1;
|
||||
return posToGenerate[index];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,31 +1,44 @@
|
||||
package com.seibel.lod.objects;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
public class PosToRenderContainer
|
||||
{
|
||||
public int playerPosX;
|
||||
public int playerPosZ;
|
||||
public int numberOfPosToRender;
|
||||
public int[][] posToRender;
|
||||
public boolean[][] posToRenderAdjacency;
|
||||
private byte minDetail;
|
||||
private int numberOfPosToRender;
|
||||
private int[][] posToRender;
|
||||
private byte[][] population;
|
||||
|
||||
public PosToRenderContainer(byte minDetail)
|
||||
{
|
||||
this.playerPosX = playerPosX;
|
||||
this.playerPosZ = playerPosZ;
|
||||
this.minDetail = minDetail;
|
||||
this.numberOfPosToRender = 0;
|
||||
posToRender = new int[1][4];
|
||||
posToRenderAdjacency = new boolean[minDetail][minDetail];
|
||||
population = new byte[minDetail][minDetail];
|
||||
}
|
||||
|
||||
public void addPosToRender(int[] levelPos)
|
||||
{
|
||||
addPosToRender(LevelPosUtil.getDetailLevel(levelPos), LevelPosUtil.getPosX(levelPos), LevelPosUtil.getPosZ(levelPos));
|
||||
if(numberOfPosToRender >= posToRender.length)
|
||||
posToRender = Arrays.copyOf(posToRender, posToRender.length*2);
|
||||
posToRender[numberOfPosToRender] = levelPos;
|
||||
numberOfPosToRender++;
|
||||
int[] newLevelPos = LevelPosUtil.convert(levelPos, minDetail);
|
||||
population[LevelPosUtil.getPosZ(newLevelPos)][LevelPosUtil.getPosZ(newLevelPos)] = (byte) (LevelPosUtil.getDetailLevel(levelPos) + 1);
|
||||
}
|
||||
|
||||
public void addPosToRender(byte detailLevel, int posX, int posZ)
|
||||
public boolean isToRender(int[] levelPos)
|
||||
{
|
||||
/*
|
||||
if(numberOfPosToRender >= posToRender.length)
|
||||
;*/
|
||||
return (population[LevelPosUtil.getPosZ(levelPos)][LevelPosUtil.getPosZ(levelPos)] == (LevelPosUtil.getDetailLevel(levelPos) + 1));
|
||||
}
|
||||
|
||||
public int getNumberOfPos()
|
||||
{
|
||||
return numberOfPosToRender;
|
||||
}
|
||||
|
||||
public int[] getNthPos(int n)
|
||||
{
|
||||
return posToRender[n];
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user