mirror of https://github.com/buggins/dlangui.git
d3d dminer fixes
This commit is contained in:
parent
01da716a70
commit
a8fb74602e
|
@ -12,6 +12,6 @@
|
|||
"targetType": "executable",
|
||||
|
||||
"dependencies": {
|
||||
"dlangui": "*",
|
||||
"dlangui": {"path": "../../"}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -104,37 +104,42 @@ class UiWidget : VerticalLayout, CellVisitor {
|
|||
_scene = new Scene3d();
|
||||
|
||||
_cam = new Camera();
|
||||
_cam.translate(vec3(0, 0, -7));
|
||||
_cam.translate(vec3(0, 14, -7));
|
||||
|
||||
_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++) {
|
||||
_mesh.addCubeMesh(vec3(0, 0, 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(-i * 2 - 1.0f, 0, 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(0, -i * 2 - 1.0f, 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(-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( 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(-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+ 0, y0+0, z0+ i * 2 + 1.0f), 0.2f, vec4(i / 12, 1, 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(x0+ -i * 2 - 1.0f, y0+0, z0+ 0), 0.2f, vec4(1, i / 12, 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(x0+ 0, y0+-i * 2 - 1.0f, z0+ 0), 0.2f, vec4(1, 1, i / 12 + 0.1, 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(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(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(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));
|
||||
World _world = new World();
|
||||
_world = new World();
|
||||
for (int x = -1000; x < 1000; x++)
|
||||
for (int z = -1000; z < 1000; z++)
|
||||
_world.setCell(x, 10, z, 1);
|
||||
_world.setCell(0, 11, 10, 2);
|
||||
_world.setCell(5, 11, 15, 2);
|
||||
_world.camPosition = Position(Vector3d(0, 13, 0), Vector3d(0, 0, 1));
|
||||
CellVisitor visitor = new TestVisitor();
|
||||
Log.d("Testing cell visitor");
|
||||
long ts = currentTimeMillis;
|
||||
_world.visitVisibleCells(_world.camPosition, visitor);
|
||||
long duration = currentTimeMillis - ts;
|
||||
Log.d("DiamondVisitor finished in ", duration, " ms");
|
||||
updateMinerMesh();
|
||||
//CellVisitor visitor = new TestVisitor();
|
||||
//Log.d("Testing cell visitor");
|
||||
//long ts = currentTimeMillis;
|
||||
//_world.visitVisibleCells(_world.camPosition, visitor);
|
||||
//long duration = currentTimeMillis - ts;
|
||||
//Log.d("DiamondVisitor finished in ", duration, " ms");
|
||||
//destroy(w);
|
||||
}
|
||||
|
||||
|
@ -148,7 +153,7 @@ class UiWidget : VerticalLayout, CellVisitor {
|
|||
long ts = currentTimeMillis;
|
||||
_world.visitVisibleCells(_world.camPosition, this);
|
||||
long duration = currentTimeMillis - ts;
|
||||
Log.d("DiamondVisitor finished in ", duration, " ms");
|
||||
Log.d("DiamondVisitor finished in ", duration, " ms ", "Vertex count: ", _minerMesh.vertexCount);
|
||||
}
|
||||
|
||||
World _world;
|
||||
|
@ -171,6 +176,7 @@ class UiWidget : VerticalLayout, CellVisitor {
|
|||
Mesh _mesh;
|
||||
Mesh _minerMesh;
|
||||
GLTexture _tx;
|
||||
GLTexture _blockstx;
|
||||
|
||||
|
||||
/// this is OpenGLDrawableDelegate implementation
|
||||
|
@ -182,13 +188,16 @@ class UiWidget : VerticalLayout, CellVisitor {
|
|||
return;
|
||||
if (!_tx)
|
||||
_tx = new GLTexture("crate");
|
||||
if (!_tx.isValid) {
|
||||
if (!_blockstx)
|
||||
_blockstx = new GLTexture("blocks");
|
||||
if (!_tx.isValid || !_blockstx.isValid) {
|
||||
Log.e("Invalid texture");
|
||||
return;
|
||||
}
|
||||
_cam.setPerspective(rc.width, rc.height, 45.0f, 0.1f, 100.0f);
|
||||
_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);
|
||||
mat4 projectionViewMatrix = _cam.projectionViewMatrix;
|
||||
|
||||
|
@ -207,6 +216,7 @@ class UiWidget : VerticalLayout, CellVisitor {
|
|||
//Log.d("matrix uniform: ", projectionViewModelMatrix.m);
|
||||
|
||||
checkgl!glEnable(GL_CULL_FACE);
|
||||
//checkgl!glDisable(GL_CULL_FACE);
|
||||
checkgl!glEnable(GL_DEPTH_TEST);
|
||||
checkgl!glCullFace(GL_BACK);
|
||||
|
||||
|
@ -218,6 +228,14 @@ class UiWidget : VerticalLayout, CellVisitor {
|
|||
_program.draw(_mesh);
|
||||
|
||||
_tx.texture.unbind();
|
||||
|
||||
_blockstx.texture.setup();
|
||||
_blockstx.texture.setSamplerParams(false);
|
||||
|
||||
_program.draw(_minerMesh);
|
||||
|
||||
_blockstx.texture.unbind();
|
||||
|
||||
_program.unbind();
|
||||
checkgl!glDisable(GL_DEPTH_TEST);
|
||||
checkgl!glDisable(GL_CULL_FACE);
|
||||
|
|
|
@ -89,50 +89,50 @@ public:
|
|||
// pos, normal, color, tx
|
||||
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, 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, 1.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, 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, 1.0, 1.0,
|
||||
];
|
||||
|
||||
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, 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, 1.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, 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, 1.0, 1.0,
|
||||
];
|
||||
|
||||
static const float[VERTEX_COMPONENTS * 4] face_vertices_west =
|
||||
[
|
||||
-0.5, -0.5, -0.5,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 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 =
|
||||
[
|
||||
-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, 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, 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, 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,
|
||||
];
|
||||
|
||||
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, 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, 1.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, 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, 1.0, 1.0,
|
||||
];
|
||||
|
||||
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) {
|
||||
for (int i = 0; i < 4; i++) {
|
||||
const float * srcvertex = src + i * VERTEX_COMPONENTS;
|
||||
float * dstvertex = data + i * VERTEX_COMPONENTS;
|
||||
for (int j = 0; j < 11; j++) {
|
||||
float v = srcvertex[j];
|
||||
switch (j) {
|
||||
for (int i = 0; i < 4; i++) {
|
||||
const float * srcvertex = src + i * VERTEX_COMPONENTS;
|
||||
float * dstvertex = data + i * VERTEX_COMPONENTS;
|
||||
for (int j = 0; j < 11; j++) {
|
||||
float v = srcvertex[j];
|
||||
switch (j) {
|
||||
default:
|
||||
case 0: // x
|
||||
v += x0;
|
||||
|
@ -168,18 +168,18 @@ static void fillFaceMesh(float * data, const float * src, float x0, float y0, fl
|
|||
case 10: // tx.v
|
||||
v = (BLOCK_TEXTURE_DY - (tileY + v * BLOCK_SPRITE_SIZE)) / cast(float)BLOCK_TEXTURE_DY;
|
||||
break;
|
||||
}
|
||||
dstvertex[j] = v;
|
||||
}
|
||||
}
|
||||
}
|
||||
dstvertex[j] = v;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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 tileY = (tileIndex / BLOCK_TEXTURE_SPRITES_PER_LINE) * BLOCK_SPRITE_STEP + BLOCK_SPRITE_OFFSET;
|
||||
// data is 11 comp * 4 vert floats
|
||||
switch (face) {
|
||||
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;
|
||||
// data is 11 comp * 4 vert floats
|
||||
switch (face) {
|
||||
default:
|
||||
case NORTH:
|
||||
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:
|
||||
fillFaceMesh(data, face_vertices_down.ptr, x0, y0, z0, tileX, tileY);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
Binary file not shown.
After Width: | Height: | Size: 22 KiB |
|
@ -3,3 +3,4 @@ res/i18n/ru.ini
|
|||
res/mdpi/cr3_logo.png
|
||||
res/mdpi/tx_fabric.jpg
|
||||
res/mdpi/crate.png
|
||||
res/mdpi/blocks.png
|
||||
|
|
Loading…
Reference in New Issue