ゲームの fps に少しがっかりしています。私はまだゲーム開発の初期段階にいます。最初にゲームを開始したときは、約 350 fps でした。高さマップとさらにコードをプログラムに追加した後、fps が低下するのは当然のことです。これで 39 fps になりました。私はまだ始めたばかりで、fps はすでに低くなっています。プロジェクトが終わったらどうなるのだろう、イライラするほどfpsが低くなると思います。私はプログラムの多くを求めていることを知っています.ハイトマップは大きな問題です. マップには 200 * 200 頂点の領域があり、各頂点には高さがあります。200 * 200 = 40000 頂点、各フレーム。地図を簡略化しようと考えていました。私の考えは、ハイトマップ全体を単純化するメソッドを作成することです。4 つの頂点はそれぞれクワッドに属します。各頂点の高さが同じである 2 つ以上の四角形が隣り合っている場合、それらを 1 つの四角形にマージできます。ポイントは、頂点を少なくすることです。(おもう)
ハイトマップのコード例をいくつか示します。
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)) {
}
}
}
}
}
誰もこれを経験していますか?アイデアや改善点はありますか、それは正しい方法ですか? 前もって感謝します。