~melchizedek6809/WolkenWelten

b15f2a261696370a98a7af9646af6ae61080eb38 — Ben (X13/Arch) 9 days ago a0c9d59
Spawn locations now use normal vec's instead of deprecated ivec's
M server/src/game/character.c => server/src/game/character.c +1 -1
@@ 41,7 41,7 @@ void characterInit(character *c){

	c->rot   = vecNew(135.f,0.f,0.f);
	c->gyoff = c->yoff = 0.f;
	c->pos   = vecAdd(vecNewI(worldGetSpawnPos()),vecNew(.5f,1.f,.5f));
	c->pos   = vecAdd(worldGetSpawnPos(),vecNew(.5f,1.f,.5f));

	c->hook  = false;


M server/src/misc/lisp.c => server/src/misc/lisp.c +2 -2
@@ 432,14 432,14 @@ static lVal *wwlnfSetSpawnPos(lClosure *c, lVal *v){

	v =  getLArgV(c,v,&pos);
	if(pos.x < 0){return NULL;}
	worldSetSpawnPos(ivecNewV(pos));
	worldSetSpawnPos(pos);

	return NULL;
}

static lVal *wwlnfSpawnPos(lClosure *c, lVal *v){
	(void)c;(void)v;
	return lValVec(vecNewI(worldGetSpawnPos()));
	return lValVec(worldGetSpawnPos());
}

static lVal *wwlnfWorldgenSphere(lClosure *c, lVal *v){

M server/src/network/server.c => server/src/network/server.c +2 -2
@@ 132,7 132,7 @@ void serverParseDyingMsg(uint c,const packet *m){
}

void msgPlayerSpawnPos(uint c){
	const vec spawn = vecNewI(worldGetSpawnPos());
	const vec spawn = worldGetSpawnPos();
	const vec nrot  = vecNew(135.f,15.f,0.f);
	const vec spos  = vecAdd(spawn,vecNew(1.f,4.f,1.f));
	msgPlayerSetPos(c,spos,nrot,vecZero());


@@ 142,7 142,7 @@ void msgPlayerSpawnPos(uint c){
void serverInitClient(uint c, u64 socket){
	memset(&clients[c],0,sizeof(clients[c]));
	clients[c].socket = socket;
	const vec spawn = vecAdd(vecNewI(worldGetSpawnPos()),vecNew(1.f,4.f,1.f));
	const vec spawn = vecAdd(worldGetSpawnPos(),vecNew(1.f,4.f,1.f));
	clients[c].c                        = characterNew();
	clients[c].cl                       = lispClientClosure(c);
	clients[c].state                    = STATE_CONNECTING;

M server/src/persistence/character.c => server/src/persistence/character.c +2 -2
@@ 41,7 41,7 @@ static void characterParseDataLine(character *p, const char *line){
		p->pos = vecNew(atof(argv[1]),atof(argv[2]),atof(argv[3]));
		if(!inWorld(p->pos.x,p->pos.y,p->pos.z)){
			fprintf(stderr,"!inWorld\n");
			p->pos = vecAdd(vecNewI(worldGetSpawnPos()),vecNew(.5f,2.f,.5f));
			p->pos = vecAdd(worldGetSpawnPos(),vecNew(.5f,2.f,.5f));
		}
		return;
	}


@@ 166,7 166,7 @@ void characterSaveData(const character *p, const char *pName){
void characterLoadSendData(character *p, const char *pName, uint c){
	if(p == NULL){return;}
	if(!characterLoadData(p,pName)){
		const vec spawn = vecNewI(worldGetSpawnPos());
		const vec spawn = worldGetSpawnPos();
		p->pos = vecAdd(spawn,vecNew(.5f,2.f,.5f));
		p->rot = vecNew(135.f,15.f,0.f);
	}

M server/src/voxel/bigchungus.c => server/src/voxel/bigchungus.c +43 -29
@@ 216,21 216,27 @@ void bigchungusBoxMineSphere(bigchungus *c, int x,int y,int z, int r){
	}
}

int bigchungusTrySpawn(bigchungus *c, const ivec s){
	return((bigchungusGetB(c,s.x,s.y  ,s.z)!=0) &&
	       (bigchungusGetB(c,s.x,s.y+1,s.z)==0) &&
	       (bigchungusGetB(c,s.x,s.y+2,s.z)==0));
static int bigchungusTrySpawn(bigchungus *c, int sx, int sy, int sz){
	return((bigchungusGetB(c,sx,sy  ,sz)!=0) &&
	       (bigchungusGetB(c,sx,sy+1,sz)==0) &&
	       (bigchungusGetB(c,sx,sy+2,sz)==0));
}

void bigchungusDetermineSpawn(bigchungus *c, const ivec s){
	const ivec sp = ivecAndS(s,~0xFF);
static void bigchungusDetermineSpawn(bigchungus *c, int sx, int sy, int sz){
	const int spx = sx & ~0xFF;
	const int spy = sy & ~0xFF;
	const int spz = sz & ~0xFF;
	for(int step = CHUNGUS_SIZE; step >= 1;step/=2){
		for(int x = step/2;x<CHUNGUS_SIZE;x+=step){
		for(int y = step/2;y<CHUNGUS_SIZE;y+=step){
		for(int z = step/2;z<CHUNGUS_SIZE;z+=step){
			const ivec cp = ivecOr(sp,ivecNew(x,y,z));
			if(bigchungusTrySpawn(c,cp)){
				c->spawn = cp;
			const int cpx = spx | x;
			const int cpy = spy | y;
			const int cpz = spz | z;
			if(bigchungusTrySpawn(c,cpx,cpy,cpz)){
				c->sx = cpx;
				c->sy = cpy;
				c->sz = cpz;
				return;
			}
		}


@@ 243,18 249,21 @@ void bigchungusGenSpawn(bigchungus *c){
	for(int x=127;x<=129;x++){
	for(int y=1;y<=3;y++){
	for(int z=127;z<=129;z++){
		if(c->chungi[x][y][z] == NULL){
			c->chungi[x][y][z] = chungusNew(x,y,z);
			chungusWorldGenLoad(c->chungi[x][y][z]);
		chungus *chng = c->chungi[x][y][z];
		if(chng == NULL){
			chng = c->chungi[x][y][z] = chungusNew(x,y,z);
			chungusWorldGenLoad(chng);
		}
		if(c->chungi[x][y][z]->spawn.x >= 0){
			c->spawn = ivecAdd(c->chungi[x][y][z]->spawn,ivecMulS(ivecNew(x,y,z),CHUNGUS_SIZE));
		if(chng->sx | chng->sy | chng->sz){
			c->sx = chng->sx | (x << 8);
			c->sy = chng->sy | (y << 8);
			c->sz = chng->sz | (z << 8);
		}
	}
	}
	}
	if(!bigchungusTrySpawn(c,c->spawn)){
		bigchungusDetermineSpawn(c,c->spawn);
	if(!bigchungusTrySpawn(c,c->sx,c->sy,c->sz)){
		bigchungusDetermineSpawn(c,c->sx,c->sy,c->sz);
	}
}



@@ 262,31 271,36 @@ void bigchungusGenHugeSpawn(bigchungus *c){
	for(int x=126;x<=130;x++){
	for(int y=1;y<=32;y++){
	for(int z=126;z<=130;z++){
		if(c->chungi[x][y][z] == NULL){
			c->chungi[x][y][z] = chungusNew(x,y,z);
			chungusWorldGenLoad(c->chungi[x][y][z]);
		chungus *chng = c->chungi[x][y][z];
		if(chng == NULL){
			chng = c->chungi[x][y][z] = chungusNew(x,y,z);
			chungusWorldGenLoad(chng);
		}
		if(c->chungi[x][y][z]->spawn.x >= 0){
			c->spawn = ivecAdd(c->chungi[x][y][z]->spawn,ivecMulS(ivecNew(x,y,z),CHUNGUS_SIZE));
		if(chng->sx | chng->sy | chng->sz){
			c->sx = chng->sx | (x << 8);
			c->sy = chng->sy | (y << 8);
			c->sz = chng->sz | (z << 8);
		}
	}
	}
	}
	if(!bigchungusTrySpawn(c,c->spawn)){
		bigchungusDetermineSpawn(c,c->spawn);
	if(!bigchungusTrySpawn(c,c->sx,c->sy,c->sz)){
		bigchungusDetermineSpawn(c,c->sx,c->sy,c->sz);
	}
}

ivec bigchungusGetSpawnPos(bigchungus *c){
vec bigchungusGetSpawnPos(bigchungus *c){
	/*
	if(!bigchungusTrySpawn(c,c->spawn)){
		bigchungusDetermineSpawn(c,c->spawn);
	}*/
	return c->spawn;
	return vecNew(c->sx,c->sy,c->sz);
}

void bigchungusSetSpawnPos(bigchungus *c, ivec pos){
	c->spawn = pos;
void bigchungusSetSpawnPos(bigchungus *c, vec pos){
	c->sx = pos.x;
	c->sy = pos.y;
	c->sz = pos.z;
}

void bigchungusUpdateClient(bigchungus *c, int p){


@@ 392,10 406,10 @@ void worldBoxMine(int x, int y, int z, int w,int h,int d){
void worldBoxMineSphere(int x, int y, int z, int r){
	bigchungusBoxMineSphere(&world,x,y,z,r);
}
ivec worldGetSpawnPos(){
vec worldGetSpawnPos(){
	return bigchungusGetSpawnPos(&world);
}
void worldSetSpawnPos(ivec pos){
void worldSetSpawnPos(vec pos){
	bigchungusSetSpawnPos(&world,pos);
}
void worldSetAllUpdated(){

M server/src/voxel/bigchungus.h => server/src/voxel/bigchungus.h +5 -5
@@ 5,7 5,7 @@

struct bigchungus {
	chungus *chungi            [256][128][256];
	ivec spawn;
	u16 sx,sy,sz;
	u8 heightModifier          [256][256];
	u8 vegetationConcentration [256][256];
	u8 islandSizeModifier      [256][256];


@@ 32,8 32,8 @@ u8          bigchungusGetB              (bigchungus *c, int x, int y, int z);
bool        bigchungusSetB              (bigchungus *c, int x, int y, int z, u8 b);
void        bigchungusGenSpawn          (bigchungus *c);
void        bigchungusGenHugeSpawn      (bigchungus *c);
ivec        bigchungusGetSpawnPos       (bigchungus *c);
void        bigchungusSetSpawnPos       (bigchungus *c, ivec pos);
vec         bigchungusGetSpawnPos       (bigchungus *c);
void        bigchungusSetSpawnPos       (bigchungus *c, vec pos);
void        bigchungusUpdateClient      (bigchungus *c, int p);
void        bigchungusUnsubscribeClient (bigchungus *c, int p);
void        bigchungusDirtyChunk        (bigchungus *c, int x, int y, int z, int client);


@@ 56,6 56,6 @@ void     worldBoxMine       (int x, int y, int z, int w,int h,int d);
void     worldBoxMineSphere (int x, int y, int z, int r);
bool     worldIsLoaded      (int x, int y, int z);
bool     worldShouldBeLoaded(const vec cpos);
ivec     worldGetSpawnPos   ();
void     worldSetSpawnPos   (ivec pos);
vec      worldGetSpawnPos   ();
void     worldSetSpawnPos   (vec pos);
void     worldSetAllUpdated ();

M server/src/voxel/chungus.c => server/src/voxel/chungus.c +1 -1
@@ 95,7 95,7 @@ chungus *chungusNew(u8 x, u8 y, u8 z){
	c->z = z;
	c->nextFree = NULL;
	c->freeTimer = freeTime;
	c->spawn = ivecNOne();
	c->sx = c->sy = c->sz = 0;
	c->clientsSubscribed = (u64)1 << 63;
	c->clientsUpdated    = (u64)1 << 31;
	beingListInit(&c->bl,NULL);

M server/src/voxel/chungus.h => server/src/voxel/chungus.h +2 -2
@@ 8,7 8,7 @@

struct chungus {
	u8     x,y,z;
	ivec   spawn;
	u8     sx,sy,sz;
	u64    clientsSubscribed;
	u64    clientsUpdated;
	u64    freeTimer;


@@ 29,7 29,7 @@ void         chungusFree             (chungus *c);
void         chungusBox              (chungus *c, int x, int y, int z, int w, int h, int d, u8 block);
void         chungusBoxIfEmpty       (chungus *c, int x, int y, int z, int w, int h, int d, u8 block);
void         chungusBoxF             (chungus *c, int x, int y, int z, int w, int h, int d, u8 block);
void         chungusBoxFWG           (chungus *c, int x,int y,int z,int w,int h,int d);
void         chungusBoxFWG           (chungus *c, int x, int y, int z, int w, int h, int d);
void         chungusBoxSphere        (chungus *c, int x, int y, int z, int r, u8 block);
void         chungusFill             (chungus *c, int x, int y, int z, u8 block);
void         chungusSetB             (chungus *c, int x, int y, int z, u8 block);

M server/src/worldgen/worldgen.c => server/src/worldgen/worldgen.c +4 -2
@@ 116,12 116,14 @@ void worldgenMonolith(worldgen *wgen, int x,int y,int z){

void worldgenFindSpawn(worldgen *wgen, int x,int z,int tries){
	if(tries > 8){
		wgen->clay->spawn = ivecNOne();
		wgen->clay->sx = wgen->clay->sy = wgen->clay->sz = 0;
		return;
	}
	int y = 0;
	if(chungusGetHighestP(wgen->clay,x,&y,z)){
		wgen->clay->spawn = ivecNew(x,y,z);
		wgen->clay->sx = x & 0xFF;
		wgen->clay->sy = y & 0xFF;
		wgen->clay->sz = z & 0xFF;
	}else{
		worldgenFindSpawn(wgen,rngValMM(0,CHUNGUS_SIZE),rngValMM(0,CHUNGUS_SIZE),tries+1);
	}