Saturday, 15 August 2015

Chunk Generation Performance in C# -



Chunk Generation Performance in C# -

i'm working on game in c#, game generate new chunk (infinite) when move around. if have in list > 1000 chunks become laggy load necessary chunks on screen. tried things improve code nil new :s.

stopwatch chunkdetect = new stopwatch(); public readonly int sizechunk = 800; private void loadchunks() { chunkdetect.restart(); chunkdetect.start(); int camxch = convert.toint32(math.ceiling(-convert.todouble(camerax) / sizechunk)), camych = convert.toint32(math.ceiling(-convert.todouble(cameray) / sizechunk)); int sizex = convert.toint32(math.ceiling(convert.todouble(gamebox.width) / sizechunk)) + 4, sizey = convert.toint32(math.ceiling(convert.todouble(gamebox.height) / sizechunk)) + 4; random generation = new random(); // load chunks or create (int chunkx = 0; chunkx < sizex; chunkx++) { (int chunky = 0; chunky < sizey; chunky++) { int xchunk = chunkx + camxch - 2, ychunk = chunky + camych - 2; chunks currentchunk = allchunks.where(i => i.positionx == xchunk && i.positiony == ychunk).firstordefault(); bool isload = true; if (chunkx == 0 || chunkx == (sizex - 1) || chunky == 0 || chunky == (sizey - 1)) isload = false; if (currentchunk == null) { color colorbiome = color.fromargb(64, 233, 56); string biomename = "grass"; allchunks.add(new chunks(xchunk, ychunk, sizechunk, colorbiome, biomename, isload, 40)); } else { bool iscurrentloaded = currentchunk.isloaded; if (!isload) currentchunk.isloaded = false; else if (!iscurrentloaded) currentchunk.isloaded = true; } } } chunkdetect.stop(); }

c# performance optimization

No comments:

Post a Comment