Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Diamond Square Refactor & Revamp #19

Closed

Conversation

Pandapip1
Copy link
Contributor

@Pandapip1 Pandapip1 commented Jan 12, 2024

Enhanced features:

  • More configurable parameters
  • Removes redundant and inefficient code
  • Uses prismarine registry
  • Fixes bug on 1.17 (not detected as a theFlattening version)
  • Revamped world generation
    • Flowers
    • Double Grass
    • Kelp
    • Seagrass & Double Seagrass
    • Cacti
    • Sugar Cane

This should be a major version, since it breaks existing seeds.

@Pandapip1 Pandapip1 marked this pull request as draft January 12, 2024 21:17
@Pandapip1 Pandapip1 changed the title Refactor Diamond Square Diamond Square Refactor & Feature Dump Jan 12, 2024
@Pandapip1 Pandapip1 marked this pull request as ready for review January 12, 2024 22:18
@Pandapip1
Copy link
Contributor Author

CC @rom1504

@Pandapip1
Copy link
Contributor Author

I might also add trees if I have time

@Pandapip1 Pandapip1 changed the title Diamond Square Refactor & Feature Dump Diamond Square Refactor & Revamp Jan 12, 2024
Copy link

Removed dependencies detected. Learn more about Socket for GitHub ↗︎

🚮 Removed packages: diamond-square@1.5.0

@Pandapip1
Copy link
Contributor Author

So this is what the new generation looks like:

image

@Pandapip1
Copy link
Contributor Author

Now we have scuffed trees (they break at chunk borders right now):

image

...duplicateArr(['plains'], 15),
...duplicateArr(['forest'], 20),
...duplicateArr(['desert'], 10)
]

function generateSimpleChunk (chunkX, chunkZ) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This overall looks a bit messy, all the copies, temporary objects and lookups will make generation substantially slower. Can you do a benchmark before vs after?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Chunk generation when moving with an elytra is not visibly slower than the previous world gen, and uses less memory.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

perf tips based after the benchmark:

  • don't define objects (use [] or {}) inside hot loops that need to run many times (this creates lots of garbage), instead put them at the top
  • don't use long object.property.access as 3 different lookups need to happen opposed to one, avoid null checking (like x?.y) when possible
  • avoid hash maps / don't check for features inside for loops
  • use integers instead of strings when comparing things, which are also garbage that has to be copied around (js strings are by copy over reference)

@rom1504
Copy link
Member

rom1504 commented Jan 13, 2024

What scope do you want to pick for this world generator?

If you want to build something really complete, I am not sure if this is the right repo for it.
This repo is meant as a pretty simple but yet not completely ugly example of a world generator

@Pandapip1
Copy link
Contributor Author

Pandapip1 commented Jan 13, 2024

What scope do you want to pick for this world generator?

A lightweight world generator that's playable and enjoyable.

If you want to build something really complete, I am not sure if this is the right repo for it.
This repo is meant as a pretty simple but yet not completely ugly example of a world generator

Fair enough. Would you prefer for me to create a new repo and request that it be transferred to the PJS org?

@extremeheat
Copy link
Member

Did a benchmark, seems almost 2x slower (80% slower)

@extremeheat  /workspaces/diamond-square (use-prismarine-registry) $ node bench2.js 
Running "diamond-square alg perf" suite...
Progress: 100%
  Old:
    1 486 ops/s, ±11.68%   | fastest
  New:
    287 ops/s, ±33.11%     | slowest, 80.69% slower

Finished 2 cases!
  Fastest: Old
  Slowest: New
Saved to: benchmark/results/reduce.html

With code after npm i benny and npm i diamond-square-old@PrismarineJS/diamond-square:

const World = require('prismarine-world')('1.12')
const Vec3 = require('vec3').Vec3
const b = require('benny')
b.suite('diamond-square alg perf',
  b.add('Old', () => {
    const diamondSquare = require('diamond-square-old')({ version: '1.12', seed: Math.floor(Math.random() * Math.pow(2, 31)) })
    const world = new World(diamondSquare)    
    for (let i = -50; i < 50; i++) {
        world.getBlock(new Vec3(i << 4, 50, i << 4))
    }
  }, { minSamples: 50 }),
  b.add('New', () => {
    const diamondSquare = require('./diamond_square')({ version: '1.12', seed: Math.floor(Math.random() * Math.pow(2, 31)) })
    const world = new World(diamondSquare)
    for (let i = -50; i < 50; i++) {
        world.getBlock(new Vec3(i << 4, 50, i << 4))
    }
  }, { minSamples: 50 }),
  b.cycle(),
  b.complete(),
  b.save({ file: 'reduce', version: '1.0.0' }),
  b.save({ file: 'reduce', format: 'chart.html' }),
)

@rom1504 rom1504 added this to Needs triage in PR Triage Jan 14, 2024
@rom1504 rom1504 moved this from Needs triage to Waiting for user input in PR Triage Jan 14, 2024
@Pandapip1
Copy link
Contributor Author

Did a benchmark, seems almost 2x slower (80% slower)

Fair enough. I'll be forking, then.

@Pandapip1 Pandapip1 closed this Jan 16, 2024
PR Triage automation moved this from Waiting for user input to Closed Jan 16, 2024
@Pandapip1 Pandapip1 deleted the use-prismarine-registry branch January 16, 2024 16:52
@Pandapip1 Pandapip1 restored the use-prismarine-registry branch January 16, 2024 16:52
@Pandapip1 Pandapip1 deleted the use-prismarine-registry branch January 16, 2024 16:52
@zardoy
Copy link

zardoy commented Feb 5, 2024

I'll be forking, then.

@Pandapip1 Where I can find the repo with up-to-date code? would like to use it for my project, if possible. Imo it looks really good, but the most basic oregen should added as well imo

@Pandapip1 Pandapip1 restored the use-prismarine-registry branch February 19, 2024 21:22
@Pandapip1
Copy link
Contributor Author

@Pandapip1 Where I can find the repo with up-to-date code? would like to use it for my project, if possible. Imo it looks really good, but the most basic oregen should added as well imo

I've undeleted my branch. It should be available at https://github.com/Pandapip1/diamond-square/tree/use-prismarine-registry

@zardoy
Copy link

zardoy commented Feb 20, 2024

I've undeleted my branch. It should be available at Pandapip1/diamond-square@use-prismarine-registry

would you be up for improving it? I'm using it and everyone is happy because of the trees :) Trees make a huge difference

@Pandapip1
Copy link
Contributor Author

would you be up for improving it? I'm using it and everyone is happy because of the trees :) Trees make a huge difference

I've kinda abandoned it at this point. Feel free to fork!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
PR Triage
  
Closed
Development

Successfully merging this pull request may close these issues.

None yet

4 participants