This map generator is starting to look pretty good now... also, disabled loading player position from disk because map is regenerated always.

master
Perttu Ahola 2011-02-01 16:17:55 +02:00
parent 56320f7e8d
commit e92238edc8
11 changed files with 437 additions and 442 deletions

View File

@ -112,7 +112,8 @@ void Environment::step(float dtime)
{
// Apply gravity to local player
v3f speed = player->getSpeed();
speed.Y -= 9.81 * BS * dtime_part * 2;
if(player->swimming_up == false)
speed.Y -= 9.81 * BS * dtime_part * 2;
/*
Apply water resistance

View File

@ -333,6 +333,19 @@ Doing now:
* Make the generator to run in background and not blocking block
placement and transfer
* Fix the strange mineral occurences
* When the map is generated and a place is found for the player, the
first chunk is actually still volatile and will have stuff still
changed after spawning, which creates a lot of glitches.
- This is partly fixed by now allowing only 2-sector deeep
modification of volatile chunks. But it should still be fixed?
- How about checking that the neighbors are fully generated too and
generate them when the middle piece is needed
- This is very slow
- How about just enabling changed_blocks properly
- This is probably a good idea
- The server has to make sure the spawn point is not at the
changing borders of a chunk
* Add some kind of erosion and other stuff that now is possible
======================================================================
@ -2690,8 +2703,7 @@ int main(int argc, char *argv[])
}
// We want a slight delay to very little
// time consuming nodes
//float mindelay = 0.15;
float mindelay = 0.20;
float mindelay = 0.15;
if(nodig_delay_counter < mindelay)
{
nodig_delay_counter = mindelay;

File diff suppressed because it is too large Load Diff

View File

@ -100,7 +100,9 @@ public:
This is overloaded by ClientMap and ServerMap to allow
their differing fetch methods.
*/
virtual MapSector * emergeSector(v2s16 p) = 0;
virtual MapSector * emergeSector(v2s16 p){ return NULL; }
virtual MapSector * emergeSector(v2s16 p,
core::map<v3s16, MapBlock*> &changed_blocks){ return NULL; }
// Returns InvalidPositionException if not found
MapBlock * getBlockNoCreate(v3s16 p);
@ -364,22 +366,42 @@ public:
return n->getValue();
}
/*
True if the chunk and its neighbors are fully generated.
It means the chunk will not be touched in the future by the
generator. If false, generateChunk will make it true.
*/
bool chunkNonVolatile(v2s16 chunkpos)
{
/*for(s16 x=-1; x<=1; x++)
for(s16 y=-1; y<=1; y++)*/
s16 x=0;
s16 y=0;
{
v2s16 chunkpos0 = chunkpos + v2s16(x,y);
MapChunk *chunk = getChunk(chunkpos);
if(chunk == NULL)
return false;
if(chunk->getGenLevel() != GENERATED_FULLY)
return false;
}
return true;
}
/*
Generate a chunk.
All chunks touching this one can be altered also.
Doesn't update lighting.
*/
MapChunk* generateChunkRaw(v2s16 chunkpos);
MapChunk* generateChunkRaw(v2s16 chunkpos,
core::map<v3s16, MapBlock*> &changed_blocks);
/*
Generate a chunk and its neighbors so that it won't be touched
anymore.
Doesn't update lighting.
*/
MapChunk* generateChunk(v2s16 chunkpos);
MapChunk* generateChunk(v2s16 chunkpos,
core::map<v3s16, MapBlock*> &changed_blocks);
/*
Generate a sector.
@ -402,7 +424,14 @@ public:
- Check disk (loads blocks also)
- Generate chunk
*/
MapSector * emergeSector(v2s16 p);
MapSector * emergeSector(v2s16 p,
core::map<v3s16, MapBlock*> &changed_blocks);
MapSector * emergeSector(v2s16 p)
{
core::map<v3s16, MapBlock*> changed_blocks;
return emergeSector(p, changed_blocks);
}
MapBlock * generateBlock(
v3s16 p,
@ -418,7 +447,11 @@ public:
- Create blank
*/
MapBlock * createBlock(v3s16 p);
/*
only_from_disk, changed_blocks and lighting_invalidated_blocks
are not properly used by the new map generator.
*/
MapBlock * emergeBlock(
v3s16 p,
bool only_from_disk,

View File

@ -700,6 +700,9 @@ void MapBlock::updateMesh(u32 daynight_ratio)
const u16 indices[] = {0,1,2,2,3,0};
video::ITexture *texture = g_irrlicht->getTexture(f.tile.spec);
if(texture == NULL)
continue;
material.setTexture(0, texture);
if(f.tile.alpha != 255)
material.MaterialType = video::EMT_TRANSPARENT_VERTEX_ALPHA;

View File

@ -22,14 +22,21 @@ with this program; if not, write to the Free Software Foundation, Inc.,
/*
MapChunk contains map-generation-time metadata for an area of
some MapSectors. (something like 64x64)
some MapSectors. (something like 16x16)
*/
enum{
GENERATED_FULLY = 0,
GENERATED_PARTLY = 10,
GENERATED_NOT = 20
};
class MapChunk
{
public:
MapChunk():
m_is_volatile(true)
//m_is_volatile(true)
m_generation_level(GENERATED_NOT)
{
}
@ -40,11 +47,21 @@ public:
It is set to false when all the 8 neighboring chunks have
been generated.
*/
bool getIsVolatile(){ return m_is_volatile; }
void setIsVolatile(bool is){ m_is_volatile = is; }
/*bool getIsVolatile(){ return m_is_volatile; }
void setIsVolatile(bool is){ m_is_volatile = is; }*/
/*
Generation level. Possible values:
GENERATED_FULLY = 0 = fully generated
GENERATED_PARTLY = partly generated
GENERATED_NOT = not generated
*/
u16 getGenLevel(){ return m_generation_level; }
void setGenLevel(u16 lev){ m_generation_level = lev; }
private:
bool m_is_volatile;
//bool m_is_volatile;
u16 m_generation_level;
};
#endif

View File

@ -82,6 +82,9 @@ void init_mapnode(IIrrlichtWrapper *irrlicht)
i = CONTENT_TREE;
f = &g_content_features[i];
f->setAllTextures(irrlicht->getTextureId("tree.png"));
f->setTexture(0, irrlicht->getTextureId("tree_top.png"));
f->setTexture(1, irrlicht->getTextureId("tree_top.png"));
f->setInventoryTexture(irrlicht->getTextureId("tree_top.png"));
f->param_type = CPT_MINERAL;
f->is_ground_content = true;

View File

@ -428,6 +428,9 @@ void LocalPlayer::move(f32 dtime, Map &map)
void LocalPlayer::applyControl(float dtime)
{
// Clear stuff
swimming_up = false;
// Random constants
#define WALK_ACCELERATION (4.0 * BS)
#define WALKSPEED_MAX (4.0 * BS)
@ -510,6 +513,7 @@ void LocalPlayer::applyControl(float dtime)
v3f speed = getSpeed();
speed.Y = 2.0*BS;
setSpeed(speed);
swimming_up = true;
}
}

View File

@ -115,6 +115,7 @@ public:
bool touching_ground;
bool in_water;
bool swimming_up;
Inventory inventory;

View File

@ -515,9 +515,13 @@ void RemoteClient::GetNextBlocks(Server *server, float dtime,
generate = false;
}
#if 0
/*
If block is far away, don't generate it unless it is
near ground level
NOTE: We can't know the ground level this way with the
new generator.
*/
if(d > 4)
{
@ -543,6 +547,7 @@ void RemoteClient::GetNextBlocks(Server *server, float dtime,
generate = false;
}
}
#endif
/*
Don't draw if not in sight
@ -610,11 +615,13 @@ void RemoteClient::GetNextBlocks(Server *server, float dtime,
v2s16 p2d(p.X, p.Z);
ServerMap *map = (ServerMap*)(&server->m_env.getMap());
v2s16 chunkpos = map->sector_to_chunk(p2d);
MapChunk *chunk = map->getChunk(chunkpos);
if(map->chunkNonVolatile(chunkpos) == false)
block_is_invalid = true;
/*MapChunk *chunk = map->getChunk(chunkpos);
if(chunk == NULL)
block_is_invalid = true;
else if(chunk->getIsVolatile() == true)
block_is_invalid = true;
block_is_invalid = true;*/
}
/*
@ -3175,6 +3182,16 @@ Player *Server::emergePlayer(const char *name, const char *password,
{
setCreativeInventory(player);
}
/*
With new map generator the map is regenerated anyway,
so start at somewhere where you probably don't get underground
*/
player->setPosition(intToFloat(v3s16(
0,
50,
0
)));
return player;
}
@ -3206,9 +3223,17 @@ Player *Server::emergePlayer(const char *name, const char *password,
dstream<<"Server: Finding spawn place for player \""
<<player->getName()<<"\""<<std::endl;
#if 1
v2s16 nodepos;
f32 groundheight = 0;
#if 1
player->setPosition(intToFloat(v3s16(
0,
50,
0
)));
#endif
#if 0
#if 0
// Try to find a good place a few times
for(s32 i=0; i<500; i++)
{
@ -3271,6 +3296,7 @@ Player *Server::emergePlayer(const char *name, const char *password,
groundheight + 15,
nodepos.Y
)));
#endif
/*
Add player to environment

View File

@ -1474,8 +1474,11 @@ void mysrand(unsigned seed);
inline int myrand_range(int min, int max)
{
if(min >= max)
if(min > max)
{
assert(0);
return max;
}
return (myrand()%(max-min+1))+min;
}