我对我的游戏的fps有点失望。我还处于游戏开发的初期。当我第一次开始游戏时,我得到了大约 350 fps。在我向程序添加了高度图和更多代码之后,fps 下降是否合乎逻辑。现在我得到了 39 fps。我还处于起步阶段,fps已经很低了。我想知道当我完成项目后会发生什么,我认为 fps 会太低以至于令人恼火。我知道我对程序的要求很高,高度图是个大问题。地图的面积为 200 * 200 个顶点,每个顶点都有一个高度。200 * 200 = 40000 个顶点,每帧。我正在考虑简化地图。我的想法是创建一种简化整个高度图的方法。每个 4 个顶点属于一个四边形。当相邻的两个或多个四边形在每个顶点上具有相同的高度时,它们可以合并为一个四边形。关键是应该有更少的顶点。(我认为)
我将展示我的高度图的一些示例代码。
package rgc.area;
import java.awt.Dimension;
import java.util.ArrayList;
import java.util.List;
public class HeightMap {
public int width; // Vertices (width)
public int height; // Vertices (height)
public List<Float> map = new ArrayList<Float>();
/**
*
* @param width The width of the map (x-axis)
* @param height The height of the map (z-axiz, NOT y-axis);
*/
public HeightMap(int width, int height) {
this.width = width;
this.height = height;
for(int i = 0; i < width * height; i++) {
map.add(1.0f);
}
}
public Dimension getSize() {
return new Dimension(this.width, this.height);
}
public int getWidth() {
return this.width;
}
public int getHeight() {
return this.height;
}
/**
* Set the height of a vertex of the map
*/
public void setHeight(int x, int y, float h) {
int index = x;
if(y > 0) {
index += (y - 1) * width;
}
map.set(index - 1, h);
/* DEBUG
for(int i = 0; i < map.size(); i++) {
System.out.println(i + " height: " + map.get(i));
}
*/
}
public float getHeight(int x, int y) {
int index = x;
if(y > 0) {
index += (y - 1) * width;
}
return map.get(index);
}
public float getHeight(float x, float y) {
return this.getHeight((int)x, (int)y);
}
/**
* This method simplifies the heightmap.
* It will merge seperate quads with the same vertex heights.
* This is to save memory and render faster.
*
* This method should only be called when the heightmap is changed.
* So this method should NOT be called every frame.
*/
public void simplify() {
// Don't really know how to do this.
for(int i = 0; i < width * height; i++) {
for(int w = 1; w < width - 1; w++) {
if(map.get(i) == map.get(i + w)) {
}
}
}
}
}
有没有人有这方面的经验?是否有任何想法或改进,我的做法是否正确?提前致谢。