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

Animal terrain finisher #1642

Merged
merged 22 commits into from Dec 5, 2014
Merged

Conversation

p-mcgowan
Copy link
Contributor

Adds animals to cChunkDesc entity list on chunk generation.

resolves #1595

Note: animals do not spawn, either the list does not get refreshed and sent to world, or the mobs spawn too far away and are removed shortly after.

ASSERT(!"Unhandled world dimension");
break;
}
} // switch (dimension)
Copy link
Member

Choose a reason for hiding this comment

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

Indenting is wrong inside the switch, there's a needless extra level.

@madmaxoft
Copy link
Member

Your indents are rather wrong, you'll need to check all of them.

Don't compare set size to zero, use .empty() instead.

@p-mcgowan
Copy link
Contributor Author

thanks for the feedback, should be all set. My formatter has been doing strange things.
I made the corrections suggested, and added the mycelium check for mooshroom spawning.

  • properly fixed in the next commit

@p-mcgowan
Copy link
Contributor Author

I switched all the fast randoms to noise, but I'm wondering if the pack center and offsets should be fast random. If it's just a matter of making sure there are still cows at chunk [34, -2] then the center would not be important, especially considering they will wander. It may make a noticeable difference during generation if the chunk percentage is higher.
I can edit it in this PR or make a new one for animal chunk generation optimization if it sounds like a good idea.

// cFinishGen override:
virtual void GenFinish(cChunkDesc & a_ChunkDesc) override;

// Tries to spawn a mob in the center of the pack. If successful, spawns 0-5 more.
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you use doxy-comments?
/** Tries to ... */

}
} // switch (dimension)
m_AnimalProbability = a_IniFile.GetValueSetI(SectionName, "AnimalSpawnChunkPercentage", DefaultAnimalSpawnChunkPercentage);
if (m_AnimalProbability < 0 || m_AnimalProbability > 100)
Copy link
Member

Choose a reason for hiding this comment

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

Please do use parenthesis for each individual comparison. It makes the conditions more understandable.

@madmaxoft
Copy link
Member

Sorry for making this so difficult

@p-mcgowan
Copy link
Contributor Author

That's great feedback, thanks for taking the time to look through it.
I'm still learning the formatting but I can see that it is invaluable to have it consistent throughout the code - I will format shortly.

@madmaxoft
Copy link
Member

I've just noticed your comment about fast random vs noise for pack centers.
I think consistency is more important than speed. If you randomized the pack center, it could happen that the pack won't be generated on a /regen, because the pack center would hit the terrain for that particular instance.

Don't worry about performance, the cNoise::IntNoise2DInt() and ``cNoise::IntNoise3DInt()` functions are really fast, all they do is hash the input coords and the seed together, it's just a few additions, multiplications and xors. They don't actually do any of the octaving or lerping that is normally associated with noise; these functions are only providing the values for the integral points.

@p-mcgowan
Copy link
Contributor Author

Hopefully that helps some, I'm still a bit fuzzy on one specific - should I 'doxy' 1-line comments on top of new methods, or just the new classes?

@@ -18,6 +18,8 @@
#include "ComposableGenerator.h"
#include "../Noise/Noise.h"
#include "../ProbabDistrib.h"
#include "../Mobs/Monster.h"
#include "FastRandom.h"
Copy link
Member

Choose a reason for hiding this comment

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

FastRandom should not be needed anymore, is it?

m_AnimalProbability = a_IniFile.GetValueSetI(SectionName, "AnimalSpawnChunkPercentage", DefaultAnimalSpawnChunkPercentage);
if ((m_AnimalProbability < 0) || (m_AnimalProbability > 100))
{
LOGWARNING("[Animals]: AnimalSpawnChunkPercentage is invalid, using the default of \"%d\".", DefaultAnimalSpawnChunkPercentage);
Copy link
Member

Choose a reason for hiding this comment

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

You say you're using the default, but I see no code doing that.

@p-mcgowan
Copy link
Contributor Author

I'm not sure what you mean by the comment "...using the default,... no code doing that.". Frankly, I just copied that from the function above but, as I understand it, the assertion will fail if none of the 3 vanilla dimensions are applicable. Should I add a line DefaultChance = 0 to cover that case?

For the switch, in the case of oceans and mushroom islands, the only thing in the list should be squid and mooshroom, respectively, so the break there skips the default mobs. For the ocelot, horse, and wolf, they are added to the list in addition to the default animals, chick cow etc.. Having the default animals outside the switch would add them to the list even if in an ocean or mushIsle biome, which would just incur more cases in the TrySpawnAnimals section.
If that doesn't work, I can refactor, I just thought that was the cleanest approach.

@p-mcgowan
Copy link
Contributor Author

re-read wiki, I thought animals spawned on grass in deserts on generation, but seems like only in random chunk spawning. Incorporated that into the latest build

@madmaxoft
Copy link
Member

The warning message says that you're using the default value. But there's no code that actually sets m_AnimalProbability to DefaultAnimalSpawnChunkPercentage. That's all I meant.

@madmaxoft
Copy link
Member

As for the switch, unfortunately it doesn't work that way. When there's a break missing, it falls through to the next case, and the next, and the next...
So your code will, for an ocean, add the squid, then an ocelot and a horse and then all the defaults.

I suggest you put the default mobs into a separate function so that you can call it from the individual cases that do use the defaults, and then add calls to that function and breaks to the switch.

@p-mcgowan
Copy link
Contributor Author

Of course, if only cases worked as I wish they did...

Thought about making a new function, but I did what you originally said and took the defaults outside the case. The only 2 cases where they do not get added are desert/end/nether and mushroom islands, which return out, so I figured it was easier that way.

@madmaxoft
Copy link
Member

Please merge current master into this branch, run the CheckBasicStyle.lua script to find out the bad formatting, and fix that.

Also, there's still the issue of default probability ( #1642 (comment) )

@p-mcgowan
Copy link
Contributor Author

Haha, you must have got tired of telling me to format those conditionals... I see what you mean now about the default m_prob, should be all skippy now. Thanks again for being patient!

@madmaxoft
Copy link
Member

Honestly, I just came up with a way to code the check in Lua's limited regexps, you may have been a catalyst, but certainly not the only target.

madmaxoft added a commit that referenced this pull request Dec 5, 2014
@madmaxoft madmaxoft merged commit 5712fad into cuberite:master Dec 5, 2014
@p-mcgowan p-mcgowan deleted the animalTerrainFinisher branch December 5, 2014 21:43
@madmaxoft
Copy link
Member

I've made some fixes after merging. It seems to work for me, animals are spawned properly. :)

@p-mcgowan
Copy link
Contributor Author

That's awesome. Looks like:
cEntityList ChunkEntities = a_ChunkDesc.GetEntities();
ChunkEntities.push_back(NewMob)
was the problem. It seems that I was just copying the list, adding a mob to it, then destroying the copy.
a_ChunkDesc.GetEntities().push_back(NewMob) solves that.

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

Successfully merging this pull request may close these issues.

Add a terrain finisher that populates chunks with animals
3 participants