mirror of https://github.com/buggins/dlangui.git
miner-d fixes
This commit is contained in:
parent
ac00749665
commit
8333b1eb7d
|
@ -227,10 +227,6 @@ private:
|
|||
DiamondVisitor visitorHelper;
|
||||
}
|
||||
|
||||
interface ChunkVisitor {
|
||||
void visit(World world, SmallChunk * chunk);
|
||||
}
|
||||
|
||||
struct DiamondVisitor {
|
||||
int maxDist;
|
||||
int maxDistBits;
|
||||
|
@ -489,6 +485,9 @@ struct DiamondVisitor {
|
|||
}
|
||||
}
|
||||
|
||||
interface ChunkVisitor {
|
||||
void visit(World world, SmallChunk * chunk);
|
||||
}
|
||||
|
||||
struct VisitorCell {
|
||||
SmallChunk * chunk;
|
||||
|
@ -499,11 +498,18 @@ struct VisitorCell {
|
|||
|
||||
struct ChunkDiamondVisitor {
|
||||
World world;
|
||||
ChunkVisitor visitor;
|
||||
Vector3d pos;
|
||||
Array3d!VisitorCell cells;
|
||||
int maxDist;
|
||||
Vector3dArray oldcells;
|
||||
Vector3dArray newcells;
|
||||
void init(World world, int distance, ChunkVisitor visitor) {
|
||||
this.world = world;
|
||||
this.maxDist = (distance + 7) / 8;
|
||||
cells.reset(maxDist);
|
||||
this.visitor = visitor;
|
||||
}
|
||||
void visitCell(VisitorCell * oldCell, int x, int y, int z, Dir direction) {
|
||||
if (x < -maxDist || x > maxDist || y < -maxDist || y > maxDist || z < -maxDist || z > maxDist)
|
||||
return; // out of bounds
|
||||
|
@ -515,12 +521,10 @@ struct ChunkDiamondVisitor {
|
|||
}
|
||||
cell.dirFlags |= (1 << direction);
|
||||
}
|
||||
void visitChunks(World world, Vector3d pos, int distance) {
|
||||
this.world = world;
|
||||
void visitChunks(Vector3d pos) {
|
||||
this.pos = pos;
|
||||
this.maxDist = (distance + 7) / 8;
|
||||
cells.reset(distance);
|
||||
cells[1,2,3] = VisitorCell.init;
|
||||
cells.reset(maxDist);
|
||||
//cells[1,2,3] = VisitorCell.init;
|
||||
oldcells.clear();
|
||||
oldcells.append(Vector3d(0, 0, 0));
|
||||
for (int dist = 0; dist < maxDist * 2; dist++) {
|
||||
|
@ -561,6 +565,8 @@ struct ChunkDiamondVisitor {
|
|||
Vector3d pt = oldcells[i];
|
||||
auto cell = cells.ptr(pt.x, pt.y, pt.z);
|
||||
// TODO: call visitor
|
||||
if (cell.chunk)
|
||||
visitor.visit(world, cell.chunk);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,6 +9,7 @@ import dlangui.graphics.scene.effect;
|
|||
import dlangui.graphics.scene.model;
|
||||
import dlangui.graphics.scene.node;
|
||||
import dlangui.graphics.scene.light;
|
||||
import dlangui.graphics.scene.drawableobject;
|
||||
import dlangui.graphics.glsupport;
|
||||
import dlangui.graphics.gldrawbuf;
|
||||
import dlangui.graphics.scene.effect;
|
||||
|
@ -52,6 +53,35 @@ extern (C) int UIAppMain(string[] args) {
|
|||
return Platform.instance.enterMessageLoop();
|
||||
}
|
||||
|
||||
class MinerDrawable : MaterialDrawableObject, ChunkVisitor {
|
||||
|
||||
import dlangui.graphics.scene.node;
|
||||
World _world;
|
||||
ChunkDiamondVisitor _chunkVisitor;
|
||||
Vector3d _pos;
|
||||
private Node3d _node;
|
||||
|
||||
this(World world) {
|
||||
_world = world;
|
||||
}
|
||||
override void draw(Node3d node, bool wireframe) {
|
||||
/// override it
|
||||
_node = node;
|
||||
_chunkVisitor.init(_world, 128, this);
|
||||
_chunkVisitor.visitChunks(_pos);
|
||||
}
|
||||
void visit(World world, SmallChunk * chunk) {
|
||||
if (chunk) {
|
||||
Mesh mesh = chunk.getMesh(world);
|
||||
if (mesh) {
|
||||
_material.bind(_node, mesh, lights(_node));
|
||||
_material.drawMesh(mesh);
|
||||
_material.unbind();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class UiWidget : VerticalLayout, CellVisitor {
|
||||
this() {
|
||||
super("OpenGLView");
|
||||
|
|
|
@ -12,4 +12,5 @@ class RenderBlock {
|
|||
Rect borderWidth;
|
||||
Rect borderStyle;
|
||||
Collection!RenderBlock children;
|
||||
|
||||
}
|
|
@ -8,6 +8,7 @@ import dlangui.core.types;
|
|||
/// Reference counted DrawableObject
|
||||
alias DrawableObjectRef = Ref!DrawableObject;
|
||||
|
||||
/// base drawable object
|
||||
class DrawableObject : RefCountedObject {
|
||||
|
||||
import dlangui.graphics.scene.node;
|
||||
|
@ -18,3 +19,59 @@ class DrawableObject : RefCountedObject {
|
|||
/// override it
|
||||
}
|
||||
}
|
||||
|
||||
/// base drawable object with material
|
||||
class MaterialDrawableObject : DrawableObject {
|
||||
import dlangui.graphics.scene.node;
|
||||
import dlangui.graphics.scene.material;
|
||||
import dlangui.graphics.scene.light;
|
||||
|
||||
protected MaterialRef _material;
|
||||
protected bool _autobindLights = true;
|
||||
protected Lights _lights;
|
||||
|
||||
this() {
|
||||
}
|
||||
|
||||
this(Material material) {
|
||||
_material = material;
|
||||
}
|
||||
|
||||
@property ref MaterialRef material() { return _material; }
|
||||
|
||||
@property bool autobindLights() { return _autobindLights; }
|
||||
@property MaterialDrawableObject autobindLights(bool flg) { _autobindLights = flg; return this; }
|
||||
|
||||
MaterialDrawableObject bindLight(Light light) {
|
||||
_lights.add(light);
|
||||
return this;
|
||||
}
|
||||
|
||||
MaterialDrawableObject unbindLight(Light light) {
|
||||
_lights.remove(light);
|
||||
return this;
|
||||
}
|
||||
|
||||
protected static __gshared LightParams _lightParamsBuffer;
|
||||
@property protected LightParams * lights(Node3d node) {
|
||||
if (!node.scene)
|
||||
return null;
|
||||
if (_lights.empty) {
|
||||
if (node.scene.boundLights.empty)
|
||||
return null;
|
||||
return node.scene.boundLightsPtr;
|
||||
}
|
||||
if (node.scene.boundLights.empty) {
|
||||
_lightParamsBuffer.reset();
|
||||
_lightParamsBuffer.add(_lights);
|
||||
} else {
|
||||
_lightParamsBuffer.reset(node.scene.boundLights);
|
||||
_lightParamsBuffer.add(_lights);
|
||||
}
|
||||
return &_lightParamsBuffer;
|
||||
}
|
||||
|
||||
override void draw(Node3d node, bool wireframe) {
|
||||
/// override it
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,7 +5,7 @@ static if (ENABLE_OPENGL):
|
|||
|
||||
import dlangui.graphics.scene.drawableobject;
|
||||
|
||||
class Model : DrawableObject {
|
||||
class Model : MaterialDrawableObject {
|
||||
import dlangui.graphics.scene.mesh;
|
||||
import dlangui.graphics.scene.node;
|
||||
import dlangui.graphics.scene.material;
|
||||
|
@ -13,54 +13,18 @@ class Model : DrawableObject {
|
|||
|
||||
|
||||
|
||||
protected MaterialRef _material;
|
||||
protected MeshRef _mesh;
|
||||
protected bool _autobindLights = true;
|
||||
protected Lights _lights;
|
||||
|
||||
this() {
|
||||
}
|
||||
|
||||
this(Material material, Mesh mesh) {
|
||||
_material = material;
|
||||
super(material);
|
||||
_mesh = mesh;
|
||||
}
|
||||
|
||||
@property ref MaterialRef material() { return _material; }
|
||||
@property ref MeshRef mesh() { return _mesh; }
|
||||
|
||||
@property bool autobindLights() { return _autobindLights; }
|
||||
@property Model autobindLights(bool flg) { _autobindLights = flg; return this; }
|
||||
|
||||
Model bindLight(Light light) {
|
||||
_lights.add(light);
|
||||
return this;
|
||||
}
|
||||
|
||||
Model unbindLight(Light light) {
|
||||
_lights.remove(light);
|
||||
return this;
|
||||
}
|
||||
|
||||
protected static __gshared LightParams _lightParamsBuffer;
|
||||
@property protected LightParams * lights(Node3d node) {
|
||||
if (!node.scene)
|
||||
return null;
|
||||
if (_lights.empty) {
|
||||
if (node.scene.boundLights.empty)
|
||||
return null;
|
||||
return node.scene.boundLightsPtr;
|
||||
}
|
||||
if (node.scene.boundLights.empty) {
|
||||
_lightParamsBuffer.reset();
|
||||
_lightParamsBuffer.add(_lights);
|
||||
} else {
|
||||
_lightParamsBuffer.reset(node.scene.boundLights);
|
||||
_lightParamsBuffer.add(_lights);
|
||||
}
|
||||
return &_lightParamsBuffer;
|
||||
}
|
||||
|
||||
override void draw(Node3d node, bool wireframe) {
|
||||
/// override it
|
||||
_material.bind(node, _mesh, lights(node));
|
||||
|
|
Loading…
Reference in New Issue