DMiner rework - optimization

This commit is contained in:
Vadim Lopatin 2016-08-17 09:19:56 +03:00
parent a2cfbf8f43
commit 13cad97c2e
7 changed files with 548 additions and 71 deletions

View File

@ -170,7 +170,7 @@ Global
{29CF2CAC-2C0C-4F17-9292-E1706AC7EBBF}.Unittest|x64.Build.0 = Release|x64 {29CF2CAC-2C0C-4F17-9292-E1706AC7EBBF}.Unittest|x64.Build.0 = Release|x64
{20722E6B-CA27-467F-8BB8-07F80106B478}.Debug|Win32.ActiveCfg = Debug|Win32 {20722E6B-CA27-467F-8BB8-07F80106B478}.Debug|Win32.ActiveCfg = Debug|Win32
{20722E6B-CA27-467F-8BB8-07F80106B478}.Debug|Win32.Build.0 = Debug|Win32 {20722E6B-CA27-467F-8BB8-07F80106B478}.Debug|Win32.Build.0 = Debug|Win32
{20722E6B-CA27-467F-8BB8-07F80106B478}.Debug|x64.ActiveCfg = Debug|Win32 {20722E6B-CA27-467F-8BB8-07F80106B478}.Debug|x64.ActiveCfg = Debug|x64
{20722E6B-CA27-467F-8BB8-07F80106B478}.Release|Win32.ActiveCfg = Release|Win32 {20722E6B-CA27-467F-8BB8-07F80106B478}.Release|Win32.ActiveCfg = Release|Win32
{20722E6B-CA27-467F-8BB8-07F80106B478}.Release|Win32.Build.0 = Release|Win32 {20722E6B-CA27-467F-8BB8-07F80106B478}.Release|Win32.Build.0 = Release|Win32
{20722E6B-CA27-467F-8BB8-07F80106B478}.Release|x64.ActiveCfg = Release|Win32 {20722E6B-CA27-467F-8BB8-07F80106B478}.Release|x64.ActiveCfg = Release|Win32
@ -180,7 +180,7 @@ Global
{20722E6B-CA27-467F-8BB8-07F80106B478}.Unittest|x64.Build.0 = Release|Win32 {20722E6B-CA27-467F-8BB8-07F80106B478}.Unittest|x64.Build.0 = Release|Win32
{5F443F6A-6612-4404-B89E-D0D0205DC8E5}.Debug|Win32.ActiveCfg = Debug|Win32 {5F443F6A-6612-4404-B89E-D0D0205DC8E5}.Debug|Win32.ActiveCfg = Debug|Win32
{5F443F6A-6612-4404-B89E-D0D0205DC8E5}.Debug|Win32.Build.0 = Debug|Win32 {5F443F6A-6612-4404-B89E-D0D0205DC8E5}.Debug|Win32.Build.0 = Debug|Win32
{5F443F6A-6612-4404-B89E-D0D0205DC8E5}.Debug|x64.ActiveCfg = Debug|Win32 {5F443F6A-6612-4404-B89E-D0D0205DC8E5}.Debug|x64.ActiveCfg = Debug|x64
{5F443F6A-6612-4404-B89E-D0D0205DC8E5}.Release|Win32.ActiveCfg = Release|Win32 {5F443F6A-6612-4404-B89E-D0D0205DC8E5}.Release|Win32.ActiveCfg = Release|Win32
{5F443F6A-6612-4404-B89E-D0D0205DC8E5}.Release|Win32.Build.0 = Release|Win32 {5F443F6A-6612-4404-B89E-D0D0205DC8E5}.Release|Win32.Build.0 = Release|Win32
{5F443F6A-6612-4404-B89E-D0D0205DC8E5}.Release|x64.ActiveCfg = Release|Win32 {5F443F6A-6612-4404-B89E-D0D0205DC8E5}.Release|x64.ActiveCfg = Release|Win32

View File

@ -337,10 +337,10 @@
<useIn>0</useIn> <useIn>0</useIn>
<useOut>0</useOut> <useOut>0</useOut>
<useArrayBounds>0</useArrayBounds> <useArrayBounds>0</useArrayBounds>
<noboundscheck>1</noboundscheck> <noboundscheck>0</noboundscheck>
<useSwitchError>0</useSwitchError> <useSwitchError>0</useSwitchError>
<useUnitTests>1</useUnitTests> <useUnitTests>1</useUnitTests>
<useInline>1</useInline> <useInline>0</useInline>
<release>0</release> <release>0</release>
<preservePaths>0</preservePaths> <preservePaths>0</preservePaths>
<warnings>1</warnings> <warnings>1</warnings>
@ -772,8 +772,8 @@
</Folder> </Folder>
<Folder name="graphics"> <Folder name="graphics">
<Folder name="domrender"> <Folder name="domrender">
<File path="src\dlangui\graphics\domrender\renderblock.d" />
<File path="src\dlangui\graphics\domrender\domrender.d" /> <File path="src\dlangui\graphics\domrender\domrender.d" />
<File path="src\dlangui\graphics\domrender\renderblock.d" />
</Folder> </Folder>
<Folder name="scene"> <Folder name="scene">
<File path="src\dlangui\graphics\scene\camera.d" /> <File path="src\dlangui\graphics\scene\camera.d" />

View File

@ -204,6 +204,210 @@
<postBuildCommand /> <postBuildCommand />
<filesToClean>*.obj;*.cmd;*.build;*.json;*.dep</filesToClean> <filesToClean>*.obj;*.cmd;*.build;*.json;*.dep</filesToClean>
</Config> </Config>
<Config name="Debug" platform="x64">
<obj>0</obj>
<link>0</link>
<lib>0</lib>
<subsystem>2</subsystem>
<multiobj>0</multiobj>
<singleFileCompilation>0</singleFileCompilation>
<oneobj>0</oneobj>
<mscoff>0</mscoff>
<trace>0</trace>
<quiet>0</quiet>
<verbose>0</verbose>
<vtls>0</vtls>
<vgc>0</vgc>
<symdebug>3</symdebug>
<optimize>0</optimize>
<cpu>0</cpu>
<isX86_64>1</isX86_64>
<isLinux>0</isLinux>
<isOSX>0</isOSX>
<isWindows>0</isWindows>
<isFreeBSD>0</isFreeBSD>
<isSolaris>0</isSolaris>
<scheduler>0</scheduler>
<useDeprecated>0</useDeprecated>
<errDeprecated>0</errDeprecated>
<useAssert>0</useAssert>
<useInvariants>0</useInvariants>
<useIn>0</useIn>
<useOut>0</useOut>
<useArrayBounds>0</useArrayBounds>
<noboundscheck>0</noboundscheck>
<useSwitchError>0</useSwitchError>
<useUnitTests>0</useUnitTests>
<useInline>0</useInline>
<release>0</release>
<preservePaths>0</preservePaths>
<warnings>0</warnings>
<infowarnings>0</infowarnings>
<checkProperty>0</checkProperty>
<genStackFrame>0</genStackFrame>
<pic>0</pic>
<cov>0</cov>
<nofloat>0</nofloat>
<Dversion>2.043</Dversion>
<ignoreUnsupportedPragmas>0</ignoreUnsupportedPragmas>
<allinst>0</allinst>
<stackStomp>0</stackStomp>
<compiler>0</compiler>
<otherDMD>0</otherDMD>
<cccmd>$(CC) -c</cccmd>
<ccTransOpt>1</ccTransOpt>
<program>$(DMDInstallDir)windows\bin\dmd.exe</program>
<imppath>$(SolutionDir)/src $(SolutionDir)/3rdparty $(SolutionDir)/deps/DerelictGL3/source $(SolutionDir)/deps/DerelictUtil/source $(SolutionDir)/deps/DerelictFT/source $(SolutionDir)/deps/DerelictSDL2/source</imppath>
<fileImppath>views views/res views/res/i18n views/res/mdpi views/res/hdpi</fileImppath>
<outdir>$(ConfigurationName)</outdir>
<objdir>$(OutDir)</objdir>
<objname />
<libname />
<doDocComments>0</doDocComments>
<docdir />
<docname />
<modules_ddoc />
<ddocfiles />
<doHdrGeneration>0</doHdrGeneration>
<hdrdir />
<hdrname />
<doXGeneration>1</doXGeneration>
<xfilename>$(IntDir)\$(TargetName).json</xfilename>
<debuglevel>0</debuglevel>
<debugids />
<versionlevel>0</versionlevel>
<versionids />
<dump_source>0</dump_source>
<mapverbosity>0</mapverbosity>
<createImplib>0</createImplib>
<defaultlibname />
<debuglibname />
<moduleDepsFile />
<run>0</run>
<runargs />
<runCv2pdb>1</runCv2pdb>
<pathCv2pdb>$(VisualDInstallDir)cv2pdb\cv2pdb.exe</pathCv2pdb>
<cv2pdbPre2043>0</cv2pdbPre2043>
<cv2pdbNoDemangle>0</cv2pdbNoDemangle>
<cv2pdbEnumType>0</cv2pdbEnumType>
<cv2pdbOptions />
<objfiles />
<linkswitches />
<libfiles>ole32.lib kernel32.lib user32.lib comctl32.lib comdlg32.lib</libfiles>
<libpaths />
<deffile />
<resfile />
<exefile>$(OutDir)\$(ProjectName).exe</exefile>
<useStdLibPath>1</useStdLibPath>
<cRuntime>2</cRuntime>
<privatePhobos>0</privatePhobos>
<additionalOptions />
<preBuildCommand />
<postBuildCommand />
<filesToClean>*.obj;*.cmd;*.build;*.json;*.dep</filesToClean>
</Config>
<Config name="Release" platform="x64">
<obj>0</obj>
<link>0</link>
<lib>0</lib>
<subsystem>2</subsystem>
<multiobj>0</multiobj>
<singleFileCompilation>0</singleFileCompilation>
<oneobj>0</oneobj>
<mscoff>0</mscoff>
<trace>0</trace>
<quiet>0</quiet>
<verbose>0</verbose>
<vtls>0</vtls>
<vgc>0</vgc>
<symdebug>0</symdebug>
<optimize>1</optimize>
<cpu>0</cpu>
<isX86_64>1</isX86_64>
<isLinux>0</isLinux>
<isOSX>0</isOSX>
<isWindows>0</isWindows>
<isFreeBSD>0</isFreeBSD>
<isSolaris>0</isSolaris>
<scheduler>0</scheduler>
<useDeprecated>0</useDeprecated>
<errDeprecated>0</errDeprecated>
<useAssert>0</useAssert>
<useInvariants>0</useInvariants>
<useIn>0</useIn>
<useOut>0</useOut>
<useArrayBounds>0</useArrayBounds>
<noboundscheck>0</noboundscheck>
<useSwitchError>0</useSwitchError>
<useUnitTests>0</useUnitTests>
<useInline>1</useInline>
<release>1</release>
<preservePaths>0</preservePaths>
<warnings>0</warnings>
<infowarnings>0</infowarnings>
<checkProperty>0</checkProperty>
<genStackFrame>0</genStackFrame>
<pic>0</pic>
<cov>0</cov>
<nofloat>0</nofloat>
<Dversion>2.043</Dversion>
<ignoreUnsupportedPragmas>0</ignoreUnsupportedPragmas>
<allinst>0</allinst>
<stackStomp>0</stackStomp>
<compiler>0</compiler>
<otherDMD>0</otherDMD>
<cccmd>$(CC) -c</cccmd>
<ccTransOpt>1</ccTransOpt>
<program>$(DMDInstallDir)windows\bin\dmd.exe</program>
<imppath>$(SolutionDir)/src $(SolutionDir)/3rdparty $(SolutionDir)/deps/DerelictGL3/source $(SolutionDir)/deps/DerelictUtil/source $(SolutionDir)/deps/DerelictFT/source $(SolutionDir)/deps/DerelictSDL2/source</imppath>
<fileImppath>views views/res views/res/i18n views/res/mdpi views/res/hdpi</fileImppath>
<outdir>$(ConfigurationName)</outdir>
<objdir>$(OutDir)</objdir>
<objname />
<libname />
<doDocComments>0</doDocComments>
<docdir />
<docname />
<modules_ddoc />
<ddocfiles />
<doHdrGeneration>0</doHdrGeneration>
<hdrdir />
<hdrname />
<doXGeneration>1</doXGeneration>
<xfilename>$(IntDir)\$(TargetName).json</xfilename>
<debuglevel>0</debuglevel>
<debugids />
<versionlevel>0</versionlevel>
<versionids />
<dump_source>0</dump_source>
<mapverbosity>0</mapverbosity>
<createImplib>0</createImplib>
<defaultlibname />
<debuglibname />
<moduleDepsFile />
<run>0</run>
<runargs />
<runCv2pdb>0</runCv2pdb>
<pathCv2pdb>$(VisualDInstallDir)cv2pdb\cv2pdb.exe</pathCv2pdb>
<cv2pdbPre2043>0</cv2pdbPre2043>
<cv2pdbNoDemangle>0</cv2pdbNoDemangle>
<cv2pdbEnumType>0</cv2pdbEnumType>
<cv2pdbOptions />
<objfiles />
<linkswitches />
<libfiles>ole32.lib kernel32.lib user32.lib comctl32.lib comdlg32.lib</libfiles>
<libpaths />
<deffile />
<resfile />
<exefile>$(OutDir)\$(ProjectName).exe</exefile>
<useStdLibPath>1</useStdLibPath>
<cRuntime>1</cRuntime>
<privatePhobos>0</privatePhobos>
<additionalOptions />
<preBuildCommand />
<postBuildCommand />
<filesToClean>*.obj;*.cmd;*.build;*.json;*.dep</filesToClean>
</Config>
<Folder name="dminer"> <Folder name="dminer">
<Folder name="src"> <Folder name="src">
<Folder name="dminer"> <Folder name="dminer">

View File

@ -17,6 +17,8 @@ immutable int CHUNKS_Z = (1 << CHUNKS_BITS_Z); // Z range: -CHUNKS_Z*8 .. CHUNKS
immutable int CHUNKS_X_MASK = (CHUNKS_X << 1) - 1; immutable int CHUNKS_X_MASK = (CHUNKS_X << 1) - 1;
immutable int CHUNKS_Z_MASK = (CHUNKS_Z << 1) - 1; immutable int CHUNKS_Z_MASK = (CHUNKS_Z << 1) - 1;
version = SmallChunksGC;
interface CellVisitor { interface CellVisitor {
//void newDirection(ref Position camPosition); //void newDirection(ref Position camPosition);
//void visitFace(World world, ref Position camPosition, Vector3d pos, cell_t cell, Dir face); //void visitFace(World world, ref Position camPosition, Vector3d pos, cell_t cell, Dir face);
@ -27,7 +29,11 @@ interface CellVisitor {
struct ChunkStack { struct ChunkStack {
protected int _minChunkY; protected int _minChunkY;
protected int _chunkCount; protected int _chunkCount;
version (SmallChunksGC) {
protected SmallChunk * [] _chunks;
} else {
protected SmallChunk ** _chunks; protected SmallChunk ** _chunks;
}
/// get chunk from stack by chunk Y index /// get chunk from stack by chunk Y index
SmallChunk * get(int chunkY) { SmallChunk * get(int chunkY) {
int idx = chunkY - _minChunkY; int idx = chunkY - _minChunkY;
@ -67,7 +73,7 @@ struct ChunkStack {
newMinY = _minChunkY; newMinY = _minChunkY;
newChunkCount = chunkY - _minChunkY + 1; newChunkCount = chunkY - _minChunkY + 1;
} }
SmallChunk ** newChunks = allocChunks(newChunkCount); SmallChunk *[] newChunks = allocChunks(newChunkCount);
// copy old data // copy old data
for(int i = 0; i < _chunkCount; i++) for(int i = 0; i < _chunkCount; i++)
newChunks[i + _minChunkY - newMinY] = _chunks[i]; newChunks[i + _minChunkY - newMinY] = _chunks[i];
@ -78,6 +84,20 @@ struct ChunkStack {
_chunks = newChunks; _chunks = newChunks;
} }
} }
version (SmallChunksGC) {
private SmallChunk* [] allocChunks(int len) {
if (len <= 0)
return null;
SmallChunk* [] res = new SmallChunk* [len];
return res;
}
private void freeChunks(ref SmallChunk *[] chunks) {
if (chunks) {
destroy(chunks);
chunks = null;
}
}
} else {
private SmallChunk ** allocChunks(int len) { private SmallChunk ** allocChunks(int len) {
if (len <= 0) if (len <= 0)
return null; return null;
@ -94,6 +114,7 @@ struct ChunkStack {
chunks = null; chunks = null;
} }
} }
}
void clear() { void clear() {
if (_chunkCount) { if (_chunkCount) {
for(int i = 0; i < _chunkCount; i++) { for(int i = 0; i < _chunkCount; i++) {
@ -128,13 +149,25 @@ struct SmallChunk {
protected Vector3d _pos; protected Vector3d _pos;
private Mesh _minerMesh; private Mesh _minerMesh;
protected bool dirty; protected bool dirty;
protected bool dirtyMesh; protected bool dirtyMesh = true;
protected bool empty; protected bool empty;
protected bool visible; protected bool visible;
protected bool dirtyVisible; protected bool dirtyVisible;
version (SmallChunksGC) {
static SmallChunk * alloc(int x, int y, int z) {
SmallChunk * res = new SmallChunk();
res._pos.x = x & (~7);
res._pos.y = y & (~7);
res._pos.z = z & (~7);
return res;
}
void release() {
destroy(this);
}
} else {
static SmallChunk * alloc(int x, int y, int z) nothrow @nogc { static SmallChunk * alloc(int x, int y, int z) nothrow @nogc {
import core.stdc.stdlib : malloc; import core.stdc.stdlib : malloc;
SmallChunk * res = cast(SmallChunk *)malloc(SmallChunk.sizeof); SmallChunk * res = cast(SmallChunk *)malloc(SmallChunk.sizeof);
@ -144,6 +177,15 @@ struct SmallChunk {
res._pos.z = z & (~7); res._pos.z = z & (~7);
return res; return res;
} }
void release() {
if (!(&this))
return;
compact();
import core.stdc.stdlib : free;
free(&this);
}
}
/// return chunk position in world (aligned to chunk origin) /// return chunk position in world (aligned to chunk origin)
@property ref const(Vector3d) position() { @property ref const(Vector3d) position() {
@ -156,20 +198,12 @@ struct SmallChunk {
generateMasks(); generateMasks();
if (dirtyVisible) { if (dirtyVisible) {
dirtyVisible = false; dirtyVisible = false;
ubyte[64] visibleFaceFlags; ubyte[64*8] visibleFaceFlags;
visible = findVisibleFaces(visibleFaceFlags) > 0; visible = findVisibleFaces(visibleFaceFlags) > 0;
} }
return visible; return visible;
} }
void release() {
if (!(&this))
return;
compact();
import core.stdc.stdlib : free;
free(&this);
}
/// destroys mesh /// destroys mesh
void compact() { void compact() {
if (_minerMesh) { if (_minerMesh) {
@ -224,7 +258,7 @@ struct SmallChunk {
generateMasks(); generateMasks();
if (empty) if (empty)
return; return;
ubyte[64] visibleFaceFlags; ubyte[64*8] visibleFaceFlags;
findVisibleFaces(visibleFaceFlags); findVisibleFaces(visibleFaceFlags);
int index = 0; int index = 0;
for (int y = 0; y < 8; y++) { for (int y = 0; y < 8; y++) {
@ -246,13 +280,15 @@ struct SmallChunk {
generateMasks(); generateMasks();
if (empty) if (empty)
return null; return null;
if (!_minerMesh) { //if (!_minerMesh) {
_minerMesh = new Mesh(VertexFormat(VertexElementType.POSITION, VertexElementType.NORMAL, VertexElementType.COLOR, VertexElementType.TEXCOORD0)); // _minerMesh = new Mesh(VertexFormat(VertexElementType.POSITION, VertexElementType.NORMAL, VertexElementType.COLOR, VertexElementType.TEXCOORD0));
dirtyMesh = true; // dirtyMesh = true;
} //}
Mesh oldMesh = _minerMesh;
if (dirtyMesh) { if (dirtyMesh) {
if (_minerMesh)
_minerMesh.reset(); _minerMesh.reset();
ubyte[64] visibleFaceFlags; ubyte[64*8] visibleFaceFlags;
findVisibleFaces(visibleFaceFlags); findVisibleFaces(visibleFaceFlags);
int index = 0; int index = 0;
for (int y = 0; y < 8; y++) { for (int y = 0; y < 8; y++) {
@ -260,6 +296,13 @@ struct SmallChunk {
for (int x = 0; x < 8; x++) { for (int x = 0; x < 8; x++) {
int visibleFaces = visibleFaceFlags[index]; int visibleFaces = visibleFaceFlags[index];
if (visibleFaces) { if (visibleFaces) {
if (!_minerMesh) {
_minerMesh = new Mesh(VertexFormat(VertexElementType.POSITION, VertexElementType.NORMAL, VertexElementType.COLOR, VertexElementType.TEXCOORD0));
import dlangui.core.logger;
//Log.d("Created mesh: ", cast(void*)_minerMesh);
}
BlockDef def = BLOCK_DEFS[cells[index]]; BlockDef def = BLOCK_DEFS[cells[index]];
def.createFaces(world, world.camPosition, Vector3d(_pos.x + x, _pos.y + y, _pos.z + z), visibleFaces, _minerMesh); def.createFaces(world, world.camPosition, Vector3d(_pos.x + x, _pos.y + y, _pos.z + z), visibleFaces, _minerMesh);
} }
@ -267,13 +310,24 @@ struct SmallChunk {
} }
} }
} }
dirtyMesh = false;
}
if (_minerMesh) {
if (_minerMesh.vertexFormat.length > 10) {
import dlangui.core.logger;
Log.d("Corrupted mesh: ", oldMesh);
}
if (oldMesh && (oldMesh !is _minerMesh)) {
import dlangui.core.logger;
Log.d("Corrupted mesh: ", oldMesh);
} }
if (!_minerMesh.vertexCount) if (!_minerMesh.vertexCount)
return null; return null;
}
return _minerMesh; return _minerMesh;
} }
private int findVisibleFaces(ref ubyte[64] visibleFaceFlags) { private int findVisibleFaces(ref ubyte[64*8] visibleFaceFlags) {
int count = 0; int count = 0;
ulong[8] visibleFacesNorth; ulong[8] visibleFacesNorth;
ulong canPass = getSideCanPassFromMask(Dir.NORTH); ulong canPass = getSideCanPassFromMask(Dir.NORTH);

View File

@ -61,14 +61,20 @@ class MinerDrawable : MaterialDrawableObject, ChunkVisitor {
Vector3d _pos; Vector3d _pos;
private Node3d _node; private Node3d _node;
this(World world) { this(World world, Material material) {
super(material);
_world = world; _world = world;
} }
override void draw(Node3d node, bool wireframe) { override void draw(Node3d node, bool wireframe) {
/// override it /// override it
_node = node; _node = node;
//Log.d("drawing Miner scene");
_chunkVisitor.init(_world, 128, this); _chunkVisitor.init(_world, 128, this);
_pos = _world.camPosition.pos;
long ts = currentTimeMillis();
_chunkVisitor.visitChunks(_pos); _chunkVisitor.visitChunks(_pos);
long duration = currentTimeMillis() - ts;
Log.d("drawing of Miner scene finished in ", duration, " ms");
} }
void visit(World world, SmallChunk * chunk) { void visit(World world, SmallChunk * chunk) {
if (chunk) { if (chunk) {
@ -82,7 +88,7 @@ class MinerDrawable : MaterialDrawableObject, ChunkVisitor {
} }
} }
class UiWidget : VerticalLayout, CellVisitor { class UiWidget : VerticalLayout { //, CellVisitor
this() { this() {
super("OpenGLView"); super("OpenGLView");
layoutWidth = FILL_PARENT; layoutWidth = FILL_PARENT;
@ -178,20 +184,23 @@ class UiWidget : VerticalLayout, CellVisitor {
//_world.setCellRange(Vector3d(-7, 11, 3), Vector3d(1, 100, 1), 8); //_world.setCellRange(Vector3d(-7, 11, 3), Vector3d(1, 100, 1), 8);
updateCamPosition(false); updateCamPosition(false);
updateMinerMesh(); //updateMinerMesh();
Material minerMaterial = new Material(EffectId("textured.vert", "textured.frag", null), "blocks"); Material minerMaterial = new Material(EffectId("textured.vert", "textured.frag", null), "blocks");
minerMaterial.ambientColor = vec3(0.1,0.1,0.1); minerMaterial.ambientColor = vec3(0.1,0.1,0.1);
minerMaterial.textureLinear = false; minerMaterial.textureLinear = false;
//minerMaterial.specular = 10; //minerMaterial.specular = 10;
Model minerDrawable = new Model(minerMaterial, _minerMesh); _minerDrawable = new MinerDrawable(_world, minerMaterial);
Node3d minerNode = new Node3d("miner", minerDrawable); //Model minerDrawable = new Model(minerMaterial, _minerMesh);
Node3d minerNode = new Node3d("miner", _minerDrawable);
_scene.addChild(minerNode); _scene.addChild(minerNode);
focusable = true; focusable = true;
} }
MinerDrawable _minerDrawable;
/// process key event, return true if event is processed. /// process key event, return true if event is processed.
override bool onMouseEvent(MouseEvent event) { override bool onMouseEvent(MouseEvent event) {
if (event.action == MouseAction.ButtonDown) { if (event.action == MouseAction.ButtonDown) {
@ -317,10 +326,10 @@ class UiWidget : VerticalLayout, CellVisitor {
Node3d dirLightNode; Node3d dirLightNode;
void visit(World world, ref Position camPosition, Vector3d pos, cell_t cell, int visibleFaces) { //void visit(World world, ref Position camPosition, Vector3d pos, cell_t cell, int visibleFaces) {
BlockDef def = BLOCK_DEFS[cell]; // BlockDef def = BLOCK_DEFS[cell];
def.createFaces(world, world.camPosition, pos, visibleFaces, _minerMesh); // def.createFaces(world, world.camPosition, pos, visibleFaces, _minerMesh);
} //}
bool flying = false; bool flying = false;
bool enableMeshUpdate = true; bool enableMeshUpdate = true;
@ -371,8 +380,8 @@ class UiWidget : VerticalLayout, CellVisitor {
dstring s = format("pos(%d,%d) h=%d %s [F]lying: %s [U]pdateMesh: %s", _world.camPosition.pos.x, _world.camPosition.pos.z, _world.camPosition.pos.y, dir, dstring s = format("pos(%d,%d) h=%d %s [F]lying: %s [U]pdateMesh: %s", _world.camPosition.pos.x, _world.camPosition.pos.z, _world.camPosition.pos.y, dir,
flying, enableMeshUpdate).toUTF32; flying, enableMeshUpdate).toUTF32;
w.text = s; w.text = s;
if (enableMeshUpdate) //if (enableMeshUpdate)
updateMinerMesh(); // updateMinerMesh();
} }
void startMoveAnimation(Vector3d direction) { void startMoveAnimation(Vector3d direction) {
@ -385,17 +394,17 @@ class UiWidget : VerticalLayout, CellVisitor {
updateCamPosition(); updateCamPosition();
} }
void updateMinerMesh() { //void updateMinerMesh() {
_minerMesh.reset(); // _minerMesh.reset();
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 ", "Vertex count: ", _minerMesh.vertexCount); // Log.d("DiamondVisitor finished in ", duration, " ms ", "Vertex count: ", _minerMesh.vertexCount);
//
invalidate(); // invalidate();
//for (int i = 0; i < 20; i++) // //for (int i = 0; i < 20; i++)
// Log.d("vertex: ", _minerMesh.vertex(i)); // // Log.d("vertex: ", _minerMesh.vertex(i));
} //}
World _world; World _world;
vec3 _position; vec3 _position;
@ -489,6 +498,8 @@ class UiWidget : VerticalLayout, CellVisitor {
checkgl!glEnable(GL_DEPTH_TEST); checkgl!glEnable(GL_DEPTH_TEST);
checkgl!glCullFace(GL_BACK); checkgl!glCullFace(GL_BACK);
Log.d("Drawing position ", _animatingPosition, " angle ", _animatingAngle);
_scene.drawScene(false); _scene.drawScene(false);
checkgl!glDisable(GL_DEPTH_TEST); checkgl!glDisable(GL_DEPTH_TEST);

View File

@ -204,6 +204,210 @@
<postBuildCommand /> <postBuildCommand />
<filesToClean>*.obj;*.cmd;*.build;*.json;*.dep</filesToClean> <filesToClean>*.obj;*.cmd;*.build;*.json;*.dep</filesToClean>
</Config> </Config>
<Config name="Debug" platform="x64">
<obj>0</obj>
<link>0</link>
<lib>0</lib>
<subsystem>2</subsystem>
<multiobj>0</multiobj>
<singleFileCompilation>0</singleFileCompilation>
<oneobj>0</oneobj>
<mscoff>0</mscoff>
<trace>0</trace>
<quiet>0</quiet>
<verbose>0</verbose>
<vtls>0</vtls>
<vgc>0</vgc>
<symdebug>3</symdebug>
<optimize>0</optimize>
<cpu>0</cpu>
<isX86_64>1</isX86_64>
<isLinux>0</isLinux>
<isOSX>0</isOSX>
<isWindows>0</isWindows>
<isFreeBSD>0</isFreeBSD>
<isSolaris>0</isSolaris>
<scheduler>0</scheduler>
<useDeprecated>0</useDeprecated>
<errDeprecated>0</errDeprecated>
<useAssert>0</useAssert>
<useInvariants>0</useInvariants>
<useIn>0</useIn>
<useOut>0</useOut>
<useArrayBounds>0</useArrayBounds>
<noboundscheck>0</noboundscheck>
<useSwitchError>0</useSwitchError>
<useUnitTests>0</useUnitTests>
<useInline>0</useInline>
<release>0</release>
<preservePaths>0</preservePaths>
<warnings>0</warnings>
<infowarnings>0</infowarnings>
<checkProperty>0</checkProperty>
<genStackFrame>0</genStackFrame>
<pic>0</pic>
<cov>0</cov>
<nofloat>0</nofloat>
<Dversion>2</Dversion>
<ignoreUnsupportedPragmas>0</ignoreUnsupportedPragmas>
<allinst>0</allinst>
<stackStomp>0</stackStomp>
<compiler>0</compiler>
<otherDMD>0</otherDMD>
<cccmd>$(CC) -c</cccmd>
<ccTransOpt>1</ccTransOpt>
<program>$(DMDInstallDir)windows\bin\dmd.exe</program>
<imppath>$(SolutionDir)/src $(SolutionDir)/3rdparty $(SolutionDir)/deps/DerelictGL3/source $(SolutionDir)/deps/DerelictUtil/source $(SolutionDir)/deps/DerelictFT/source $(SolutionDir)/deps/DerelictSDL2/source</imppath>
<fileImppath>views views/res views/res/i18n views/res/mdpi views/res/hdpi</fileImppath>
<outdir>$(ConfigurationName)</outdir>
<objdir>$(OutDir)</objdir>
<objname />
<libname />
<doDocComments>0</doDocComments>
<docdir />
<docname />
<modules_ddoc />
<ddocfiles />
<doHdrGeneration>0</doHdrGeneration>
<hdrdir />
<hdrname />
<doXGeneration>1</doXGeneration>
<xfilename>$(IntDir)\$(TargetName).json</xfilename>
<debuglevel>0</debuglevel>
<debugids />
<versionlevel>0</versionlevel>
<versionids>USE_OPENGL EmbedStandardResources ForceLogs</versionids>
<dump_source>0</dump_source>
<mapverbosity>0</mapverbosity>
<createImplib>0</createImplib>
<defaultlibname />
<debuglibname />
<moduleDepsFile />
<run>0</run>
<runargs />
<runCv2pdb>1</runCv2pdb>
<pathCv2pdb>$(VisualDInstallDir)cv2pdb\cv2pdb.exe</pathCv2pdb>
<cv2pdbPre2043>0</cv2pdbPre2043>
<cv2pdbNoDemangle>0</cv2pdbNoDemangle>
<cv2pdbEnumType>0</cv2pdbEnumType>
<cv2pdbOptions />
<objfiles />
<linkswitches />
<libfiles />
<libpaths />
<deffile />
<resfile />
<exefile>$(OutDir)\$(ProjectName).exe</exefile>
<useStdLibPath>1</useStdLibPath>
<cRuntime>2</cRuntime>
<privatePhobos>0</privatePhobos>
<additionalOptions />
<preBuildCommand />
<postBuildCommand />
<filesToClean>*.obj;*.cmd;*.build;*.json;*.dep</filesToClean>
</Config>
<Config name="Release" platform="x64">
<obj>0</obj>
<link>0</link>
<lib>0</lib>
<subsystem>0</subsystem>
<multiobj>0</multiobj>
<singleFileCompilation>0</singleFileCompilation>
<oneobj>0</oneobj>
<mscoff>0</mscoff>
<trace>0</trace>
<quiet>0</quiet>
<verbose>0</verbose>
<vtls>0</vtls>
<vgc>0</vgc>
<symdebug>0</symdebug>
<optimize>1</optimize>
<cpu>0</cpu>
<isX86_64>1</isX86_64>
<isLinux>0</isLinux>
<isOSX>0</isOSX>
<isWindows>0</isWindows>
<isFreeBSD>0</isFreeBSD>
<isSolaris>0</isSolaris>
<scheduler>0</scheduler>
<useDeprecated>0</useDeprecated>
<errDeprecated>0</errDeprecated>
<useAssert>0</useAssert>
<useInvariants>0</useInvariants>
<useIn>0</useIn>
<useOut>0</useOut>
<useArrayBounds>0</useArrayBounds>
<noboundscheck>0</noboundscheck>
<useSwitchError>0</useSwitchError>
<useUnitTests>0</useUnitTests>
<useInline>1</useInline>
<release>1</release>
<preservePaths>0</preservePaths>
<warnings>0</warnings>
<infowarnings>0</infowarnings>
<checkProperty>0</checkProperty>
<genStackFrame>0</genStackFrame>
<pic>0</pic>
<cov>0</cov>
<nofloat>0</nofloat>
<Dversion>2.043</Dversion>
<ignoreUnsupportedPragmas>0</ignoreUnsupportedPragmas>
<allinst>0</allinst>
<stackStomp>0</stackStomp>
<compiler>0</compiler>
<otherDMD>0</otherDMD>
<cccmd>$(CC) -c</cccmd>
<ccTransOpt>1</ccTransOpt>
<program>$(DMDInstallDir)windows\bin\dmd.exe</program>
<imppath />
<fileImppath />
<outdir>$(ConfigurationName)</outdir>
<objdir>$(OutDir)</objdir>
<objname />
<libname />
<doDocComments>0</doDocComments>
<docdir />
<docname />
<modules_ddoc />
<ddocfiles />
<doHdrGeneration>0</doHdrGeneration>
<hdrdir />
<hdrname />
<doXGeneration>1</doXGeneration>
<xfilename>$(IntDir)\$(TargetName).json</xfilename>
<debuglevel>0</debuglevel>
<debugids />
<versionlevel>0</versionlevel>
<versionids />
<dump_source>0</dump_source>
<mapverbosity>0</mapverbosity>
<createImplib>0</createImplib>
<defaultlibname />
<debuglibname />
<moduleDepsFile />
<run>0</run>
<runargs />
<runCv2pdb>0</runCv2pdb>
<pathCv2pdb>$(VisualDInstallDir)cv2pdb\cv2pdb.exe</pathCv2pdb>
<cv2pdbPre2043>0</cv2pdbPre2043>
<cv2pdbNoDemangle>0</cv2pdbNoDemangle>
<cv2pdbEnumType>0</cv2pdbEnumType>
<cv2pdbOptions />
<objfiles />
<linkswitches />
<libfiles />
<libpaths />
<deffile />
<resfile />
<exefile>$(OutDir)\$(ProjectName).exe</exefile>
<useStdLibPath>1</useStdLibPath>
<cRuntime>1</cRuntime>
<privatePhobos>0</privatePhobos>
<additionalOptions />
<preBuildCommand />
<postBuildCommand />
<filesToClean>*.obj;*.cmd;*.build;*.json;*.dep</filesToClean>
</Config>
<Folder name="ircclient"> <Folder name="ircclient">
<Folder name="ircclient"> <Folder name="ircclient">
<Folder name="net"> <Folder name="net">

View File

@ -348,6 +348,10 @@ class Mesh : RefCountedObject {
_vertexCount = 0; _vertexCount = 0;
_vertexData.length = 0; _vertexData.length = 0;
_dirtyVertexBuffer = true; _dirtyVertexBuffer = true;
if (_vertexBuffer) {
destroy(_vertexBuffer);
_vertexBuffer = null;
}
if (_parts.length) { if (_parts.length) {
foreach(p; _parts) foreach(p; _parts)
destroy(p); destroy(p);