d3d dminer fixes

This commit is contained in:
Vadim Lopatin 2016-03-22 13:06:30 +03:00
parent 01da716a70
commit a8fb74602e
5 changed files with 80 additions and 61 deletions

View File

@ -12,6 +12,6 @@
"targetType": "executable", "targetType": "executable",
"dependencies": { "dependencies": {
"dlangui": "*", "dlangui": {"path": "../../"}
} }
} }

View File

@ -104,37 +104,42 @@ class UiWidget : VerticalLayout, CellVisitor {
_scene = new Scene3d(); _scene = new Scene3d();
_cam = new Camera(); _cam = new Camera();
_cam.translate(vec3(0, 0, -7)); _cam.translate(vec3(0, 14, -7));
_scene.activeCamera = _cam; _scene.activeCamera = _cam;
_mesh = Mesh.createCubeMesh(vec3(0, 0, 0), 0.3f); int x0 = 0;
int y0 = 11;
int z0 = 0;
_mesh = Mesh.createCubeMesh(vec3(x0+ 0, y0 + 0, z0 + 0), 0.3f);
for (int i = 0; i < 10; i++) { for (int i = 0; i < 10; i++) {
_mesh.addCubeMesh(vec3(0, 0, i * 2 + 1.0f), 0.2f, vec4(i / 12, 1, 1, 1)); _mesh.addCubeMesh(vec3(x0+ 0, y0+0, z0+ i * 2 + 1.0f), 0.2f, vec4(i / 12, 1, 1, 1));
_mesh.addCubeMesh(vec3(i * 2 + 1.0f, 0, 0), 0.2f, vec4(1, i / 12, 1, 1)); _mesh.addCubeMesh(vec3(x0+ i * 2 + 1.0f, y0+0, z0+ 0), 0.2f, vec4(1, i / 12, 1, 1));
_mesh.addCubeMesh(vec3(-i * 2 - 1.0f, 0, 0), 0.2f, vec4(1, i / 12, 1, 1)); _mesh.addCubeMesh(vec3(x0+ -i * 2 - 1.0f, y0+0, z0+ 0), 0.2f, vec4(1, i / 12, 1, 1));
_mesh.addCubeMesh(vec3(0, i * 2 + 1.0f, 0), 0.2f, vec4(1, 1, i / 12 + 0.1, 1)); _mesh.addCubeMesh(vec3(x0+ 0, y0+i * 2 + 1.0f, z0+ 0), 0.2f, vec4(1, 1, i / 12 + 0.1, 1));
_mesh.addCubeMesh(vec3(0, -i * 2 - 1.0f, 0), 0.2f, vec4(1, 1, i / 12 + 0.1, 1)); _mesh.addCubeMesh(vec3(x0+ 0, y0+-i * 2 - 1.0f, z0+ 0), 0.2f, vec4(1, 1, i / 12 + 0.1, 1));
_mesh.addCubeMesh(vec3(i * 2 + 1.0f, i * 2 + 1.0f, i * 2 + 1.0f), 0.2f, vec4(i / 12, i / 12, i / 12, 1)); _mesh.addCubeMesh(vec3(x0+ i * 2 + 1.0f, y0+i * 2 + 1.0f, z0+ i * 2 + 1.0f), 0.2f, vec4(i / 12, i / 12, i / 12, 1));
_mesh.addCubeMesh(vec3(-i * 2 + 1.0f, i * 2 + 1.0f, i * 2 + 1.0f), 0.2f, vec4(i / 12, i / 12, 1 - i / 12, 1)); _mesh.addCubeMesh(vec3(x0+ -i * 2 + 1.0f, y0+i * 2 + 1.0f, z0+ i * 2 + 1.0f), 0.2f, vec4(i / 12, i / 12, 1 - i / 12, 1));
_mesh.addCubeMesh(vec3( i * 2 + 1.0f, -i * 2 + 1.0f, i * 2 + 1.0f), 0.2f, vec4(i / 12, 1 - i / 12, i / 12, 1)); _mesh.addCubeMesh(vec3(x0+ i * 2 + 1.0f, y0+-i * 2 + 1.0f, z0+ i * 2 + 1.0f), 0.2f, vec4(i / 12, 1 - i / 12, i / 12, 1));
_mesh.addCubeMesh(vec3(-i * 2 - 1.0f, -i * 2 - 1.0f, -i * 2 - 1.0f), 0.2f, vec4(1 - i / 12, i / 12, i / 12, 1)); _mesh.addCubeMesh(vec3(x0+ -i * 2 - 1.0f, y0+-i * 2 - 1.0f, z0+ -i * 2 - 1.0f), 0.2f, vec4(1 - i / 12, i / 12, i / 12, 1));
} }
_minerMesh = new Mesh(VertexFormat(VertexElementType.POSITION, VertexElementType.NORMAL, VertexElementType.COLOR, VertexElementType.TEXCOORD0)); _minerMesh = new Mesh(VertexFormat(VertexElementType.POSITION, VertexElementType.NORMAL, VertexElementType.COLOR, VertexElementType.TEXCOORD0));
World _world = new World(); _world = new World();
for (int x = -1000; x < 1000; x++) for (int x = -1000; x < 1000; x++)
for (int z = -1000; z < 1000; z++) for (int z = -1000; z < 1000; z++)
_world.setCell(x, 10, z, 1); _world.setCell(x, 10, z, 1);
_world.setCell(0, 11, 10, 2); _world.setCell(0, 11, 10, 2);
_world.setCell(5, 11, 15, 2); _world.setCell(5, 11, 15, 2);
_world.camPosition = Position(Vector3d(0, 13, 0), Vector3d(0, 0, 1)); _world.camPosition = Position(Vector3d(0, 13, 0), Vector3d(0, 0, 1));
CellVisitor visitor = new TestVisitor(); updateMinerMesh();
Log.d("Testing cell visitor"); //CellVisitor visitor = new TestVisitor();
long ts = currentTimeMillis; //Log.d("Testing cell visitor");
_world.visitVisibleCells(_world.camPosition, visitor); //long ts = currentTimeMillis;
long duration = currentTimeMillis - ts; //_world.visitVisibleCells(_world.camPosition, visitor);
Log.d("DiamondVisitor finished in ", duration, " ms"); //long duration = currentTimeMillis - ts;
//Log.d("DiamondVisitor finished in ", duration, " ms");
//destroy(w); //destroy(w);
} }
@ -148,7 +153,7 @@ class UiWidget : VerticalLayout, CellVisitor {
long ts = currentTimeMillis; long ts = currentTimeMillis;
_world.visitVisibleCells(_world.camPosition, this); _world.visitVisibleCells(_world.camPosition, this);
long duration = currentTimeMillis - ts; long duration = currentTimeMillis - ts;
Log.d("DiamondVisitor finished in ", duration, " ms"); Log.d("DiamondVisitor finished in ", duration, " ms ", "Vertex count: ", _minerMesh.vertexCount);
} }
World _world; World _world;
@ -171,6 +176,7 @@ class UiWidget : VerticalLayout, CellVisitor {
Mesh _mesh; Mesh _mesh;
Mesh _minerMesh; Mesh _minerMesh;
GLTexture _tx; GLTexture _tx;
GLTexture _blockstx;
/// this is OpenGLDrawableDelegate implementation /// this is OpenGLDrawableDelegate implementation
@ -182,13 +188,16 @@ class UiWidget : VerticalLayout, CellVisitor {
return; return;
if (!_tx) if (!_tx)
_tx = new GLTexture("crate"); _tx = new GLTexture("crate");
if (!_tx.isValid) { if (!_blockstx)
_blockstx = new GLTexture("blocks");
if (!_tx.isValid || !_blockstx.isValid) {
Log.e("Invalid texture"); Log.e("Invalid texture");
return; return;
} }
_cam.setPerspective(rc.width, rc.height, 45.0f, 0.1f, 100.0f); _cam.setPerspective(rc.width, rc.height, 45.0f, 0.1f, 100.0f);
_cam.setIdentity(); _cam.setIdentity();
_cam.translate(vec3(0, 0, -1.1)); // - angle/1000 //_cam.translate(vec3(0, 14, -1.1)); // - angle/1000
_cam.translate(vec3(0, 14, - angle/1000)); //
_cam.rotateZ(30.0f + angle * 0.3456778); _cam.rotateZ(30.0f + angle * 0.3456778);
mat4 projectionViewMatrix = _cam.projectionViewMatrix; mat4 projectionViewMatrix = _cam.projectionViewMatrix;
@ -207,6 +216,7 @@ class UiWidget : VerticalLayout, CellVisitor {
//Log.d("matrix uniform: ", projectionViewModelMatrix.m); //Log.d("matrix uniform: ", projectionViewModelMatrix.m);
checkgl!glEnable(GL_CULL_FACE); checkgl!glEnable(GL_CULL_FACE);
//checkgl!glDisable(GL_CULL_FACE);
checkgl!glEnable(GL_DEPTH_TEST); checkgl!glEnable(GL_DEPTH_TEST);
checkgl!glCullFace(GL_BACK); checkgl!glCullFace(GL_BACK);
@ -218,6 +228,14 @@ class UiWidget : VerticalLayout, CellVisitor {
_program.draw(_mesh); _program.draw(_mesh);
_tx.texture.unbind(); _tx.texture.unbind();
_blockstx.texture.setup();
_blockstx.texture.setSamplerParams(false);
_program.draw(_minerMesh);
_blockstx.texture.unbind();
_program.unbind(); _program.unbind();
checkgl!glDisable(GL_DEPTH_TEST); checkgl!glDisable(GL_DEPTH_TEST);
checkgl!glDisable(GL_CULL_FACE); checkgl!glDisable(GL_CULL_FACE);

View File

@ -89,50 +89,50 @@ public:
// pos, normal, color, tx // pos, normal, color, tx
static const float[VERTEX_COMPONENTS * 4] face_vertices_north = static const float[VERTEX_COMPONENTS * 4] face_vertices_north =
[ [
-0.5, 0.5, -0.5, 0.0, 0.0, -1.0, 1.0, 1.0, 1.0, 1.0, 0.0, 0.0, -0.5, 0.5, -0.5, 0.0, 0.0, -1.0, 1.0, 1.0, 1.0, 1.0, 0.0, 0.0,
0.5, 0.5, -0.5, 0.0, 0.0, -1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 0.0, 0.5, 0.5, -0.5, 0.0, 0.0, -1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 0.0,
-0.5, -0.5, -0.5, 0.0, 0.0, -1.0, 1.0, 1.0, 1.0, 1.0, 0.0, 1.0, -0.5, -0.5, -0.5, 0.0, 0.0, -1.0, 1.0, 1.0, 1.0, 1.0, 0.0, 1.0,
0.5, -0.5, -0.5, 0.0, 0.0, -1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 0.5, -0.5, -0.5, 0.0, 0.0, -1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0,
]; ];
static const float[VERTEX_COMPONENTS * 4] face_vertices_south = static const float[VERTEX_COMPONENTS * 4] face_vertices_south =
[ [
-0.5, -0.5, 0.5, 0.0, 0.0, 1.0, 1.0, 1.0, 1.0, 1.0, 0.0, 0.0, -0.5, -0.5, 0.5, 0.0, 0.0, 1.0, 1.0, 1.0, 1.0, 1.0, 0.0, 0.0,
0.5, -0.5, 0.5, 0.0, 0.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 0.0, 0.5, -0.5, 0.5, 0.0, 0.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 0.0,
-0.5, 0.5, 0.5, 0.0, 0.0, 1.0, 1.0, 1.0, 1.0, 1.0, 0.0, 1.0, -0.5, 0.5, 0.5, 0.0, 0.0, 1.0, 1.0, 1.0, 1.0, 1.0, 0.0, 1.0,
0.5, 0.5, 0.5, 0.0, 0.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 0.5, 0.5, 0.5, 0.0, 0.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0,
]; ];
static const float[VERTEX_COMPONENTS * 4] face_vertices_west = static const float[VERTEX_COMPONENTS * 4] face_vertices_west =
[ [
-0.5, -0.5, -0.5, -1.0, 0.0, 0.0, 1.0, 1.0, 1.0, 1.0, 0.0, 0.0, -0.5, -0.5, -0.5, -1.0, 0.0, 0.0, 1.0, 1.0, 1.0, 1.0, 0.0, 0.0,
-0.5, -0.5, 0.5, -1.0, 0.0, 0.0, 1.0, 1.0, 1.0, 1.0, 1.0, 0.0, -0.5, -0.5, 0.5, -1.0, 0.0, 0.0, 1.0, 1.0, 1.0, 1.0, 1.0, 0.0,
-0.5, 0.5, -0.5, -1.0, 0.0, 0.0, 1.0, 1.0, 1.0, 1.0, 0.0, 1.0, -0.5, 0.5, -0.5, -1.0, 0.0, 0.0, 1.0, 1.0, 1.0, 1.0, 0.0, 1.0,
-0.5, 0.5, 0.5, -1.0, 0.0, 0.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0 -0.5, 0.5, 0.5, -1.0, 0.0, 0.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0
]; ];
static const float[VERTEX_COMPONENTS * 4] face_vertices_east = static const float[VERTEX_COMPONENTS * 4] face_vertices_east =
[ [
0.5, -0.5, 0.5, 1.0, 0.0, 0.0, 1.0, 1.0, 1.0, 1.0, 0.0, 0.0, 0.5, -0.5, 0.5, 1.0, 0.0, 0.0, 1.0, 1.0, 1.0, 1.0, 0.0, 0.0,
0.5, -0.5, -0.5, 1.0, 0.0, 0.0, 1.0, 1.0, 1.0, 1.0, 1.0, 0.0, 0.5, -0.5, -0.5, 1.0, 0.0, 0.0, 1.0, 1.0, 1.0, 1.0, 1.0, 0.0,
0.5, 0.5, 0.5, 1.0, 0.0, 0.0, 1.0, 1.0, 1.0, 1.0, 0.0, 1.0, 0.5, 0.5, 0.5, 1.0, 0.0, 0.0, 1.0, 1.0, 1.0, 1.0, 0.0, 1.0,
0.5, 0.5, -0.5, 1.0, 0.0, 0.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 0.5, 0.5, -0.5, 1.0, 0.0, 0.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0,
]; ];
static const float[VERTEX_COMPONENTS * 4] face_vertices_up = static const float[VERTEX_COMPONENTS * 4] face_vertices_up =
[ [
-0.5, 0.5, 0.5, 0.0, 1.0, 0.0, 1.0, 1.0, 1.0, 1.0, 0.0, 0.0, -0.5, 0.5, 0.5, 0.0, 1.0, 0.0, 1.0, 1.0, 1.0, 1.0, 0.0, 0.0,
0.5, 0.5, 0.5, 0.0, 1.0, 0.0, 1.0, 1.0, 1.0, 1.0, 1.0, 0.0, 0.5, 0.5, 0.5, 0.0, 1.0, 0.0, 1.0, 1.0, 1.0, 1.0, 1.0, 0.0,
-0.5, 0.5, -0.5, 0.0, 1.0, 0.0, 1.0, 1.0, 1.0, 1.0, 0.0, 1.0, -0.5, 0.5, -0.5, 0.0, 1.0, 0.0, 1.0, 1.0, 1.0, 1.0, 0.0, 1.0,
0.5, 0.5, -0.5, 0.0, 1.0, 0.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 0.5, 0.5, -0.5, 0.0, 1.0, 0.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0,
]; ];
static const float[VERTEX_COMPONENTS * 4] face_vertices_down = static const float[VERTEX_COMPONENTS * 4] face_vertices_down =
[ [
-0.5, -0.5, -0.5, 0.0, -1.0, 0.0, 1.0, 1.0, 1.0, 1.0, 0.0, 0.0, -0.5, -0.5, -0.5, 0.0, -1.0, 0.0, 1.0, 1.0, 1.0, 1.0, 0.0, 0.0,
0.5, -0.5, -0.5, 0.0, -1.0, 0.0, 1.0, 1.0, 1.0, 1.0, 1.0, 0.0, 0.5, -0.5, -0.5, 0.0, -1.0, 0.0, 1.0, 1.0, 1.0, 1.0, 1.0, 0.0,
-0.5, -0.5, 0.5, 0.0, -1.0, 0.0, 1.0, 1.0, 1.0, 1.0, 0.0, 1.0, -0.5, -0.5, 0.5, 0.0, -1.0, 0.0, 1.0, 1.0, 1.0, 1.0, 0.0, 1.0,
0.5, -0.5, 0.5, 0.0, -1.0, 0.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 0.5, -0.5, 0.5, 0.0, -1.0, 0.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0,
]; ];
static const ushort[6] face_indexes = static const ushort[6] face_indexes =
@ -146,12 +146,12 @@ static const ushort[6] face_indexes_back =
]; ];
static void fillFaceMesh(float * data, const float * src, float x0, float y0, float z0, int tileX, int tileY) { static void fillFaceMesh(float * data, const float * src, float x0, float y0, float z0, int tileX, int tileY) {
for (int i = 0; i < 4; i++) { for (int i = 0; i < 4; i++) {
const float * srcvertex = src + i * VERTEX_COMPONENTS; const float * srcvertex = src + i * VERTEX_COMPONENTS;
float * dstvertex = data + i * VERTEX_COMPONENTS; float * dstvertex = data + i * VERTEX_COMPONENTS;
for (int j = 0; j < 11; j++) { for (int j = 0; j < 11; j++) {
float v = srcvertex[j]; float v = srcvertex[j];
switch (j) { switch (j) {
default: default:
case 0: // x case 0: // x
v += x0; v += x0;
@ -168,18 +168,18 @@ static void fillFaceMesh(float * data, const float * src, float x0, float y0, fl
case 10: // tx.v case 10: // tx.v
v = (BLOCK_TEXTURE_DY - (tileY + v * BLOCK_SPRITE_SIZE)) / cast(float)BLOCK_TEXTURE_DY; v = (BLOCK_TEXTURE_DY - (tileY + v * BLOCK_SPRITE_SIZE)) / cast(float)BLOCK_TEXTURE_DY;
break; break;
} }
dstvertex[j] = v; dstvertex[j] = v;
} }
} }
} }
static void createFaceMesh(float * data, Dir face, float x0, float y0, float z0, int tileIndex) { static void createFaceMesh(float * data, Dir face, float x0, float y0, float z0, int tileIndex) {
int tileX = (tileIndex % BLOCK_TEXTURE_SPRITES_PER_LINE) * BLOCK_SPRITE_STEP + BLOCK_SPRITE_OFFSET; int tileX = (tileIndex % BLOCK_TEXTURE_SPRITES_PER_LINE) * BLOCK_SPRITE_STEP + BLOCK_SPRITE_OFFSET;
int tileY = (tileIndex / BLOCK_TEXTURE_SPRITES_PER_LINE) * BLOCK_SPRITE_STEP + BLOCK_SPRITE_OFFSET; int tileY = (tileIndex / BLOCK_TEXTURE_SPRITES_PER_LINE) * BLOCK_SPRITE_STEP + BLOCK_SPRITE_OFFSET;
// data is 11 comp * 4 vert floats // data is 11 comp * 4 vert floats
switch (face) { switch (face) {
default: default:
case NORTH: case NORTH:
fillFaceMesh(data, face_vertices_north.ptr, x0, y0, z0, tileX, tileY); fillFaceMesh(data, face_vertices_north.ptr, x0, y0, z0, tileX, tileY);
@ -199,7 +199,7 @@ static void createFaceMesh(float * data, Dir face, float x0, float y0, float z0,
case DOWN: case DOWN:
fillFaceMesh(data, face_vertices_down.ptr, x0, y0, z0, tileX, tileY); fillFaceMesh(data, face_vertices_down.ptr, x0, y0, z0, tileX, tileY);
break; break;
} }
} }

Binary file not shown.

After

Width:  |  Height:  |  Size: 22 KiB

View File

@ -3,3 +3,4 @@ res/i18n/ru.ini
res/mdpi/cr3_logo.png res/mdpi/cr3_logo.png
res/mdpi/tx_fabric.jpg res/mdpi/tx_fabric.jpg
res/mdpi/crate.png res/mdpi/crate.png
res/mdpi/blocks.png