randomTick sped up with faster rand implementation
This commit is contained in:
parent
d7f2771da4
commit
6214e1a507
@ -8,6 +8,7 @@
|
|||||||
#include "../content/Content.h"
|
#include "../content/Content.h"
|
||||||
#include "../lighting/Lighting.h"
|
#include "../lighting/Lighting.h"
|
||||||
#include "../util/timeutil.h"
|
#include "../util/timeutil.h"
|
||||||
|
#include "../maths/fastmaths.h"
|
||||||
|
|
||||||
#include "scripting/scripting.h"
|
#include "scripting/scripting.h"
|
||||||
|
|
||||||
@ -86,10 +87,13 @@ void BlocksController::update(float delta) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void BlocksController::randomTick(int tickid, int parts) {
|
void BlocksController::randomTick(int tickid, int parts) {
|
||||||
// timeutil::ScopeLogTimer timer(5000+tickid);
|
timeutil::ScopeLogTimer timer(5000+tickid);
|
||||||
const int w = chunks->w;
|
const int w = chunks->w;
|
||||||
const int d = chunks->d;
|
const int d = chunks->d;
|
||||||
|
int segments = 4;
|
||||||
|
int segheight = CHUNK_H / segments;
|
||||||
auto indices = level->content->getIndices();
|
auto indices = level->content->getIndices();
|
||||||
|
|
||||||
for (uint z = padding; z < d-padding; z++){
|
for (uint z = padding; z < d-padding; z++){
|
||||||
for (uint x = padding; x < w-padding; x++){
|
for (uint x = padding; x < w-padding; x++){
|
||||||
int index = z * w + x;
|
int index = z * w + x;
|
||||||
@ -98,13 +102,11 @@ void BlocksController::randomTick(int tickid, int parts) {
|
|||||||
std::shared_ptr<Chunk> chunk = chunks->chunks[index];
|
std::shared_ptr<Chunk> chunk = chunks->chunks[index];
|
||||||
if (chunk == nullptr || !chunk->isLighted())
|
if (chunk == nullptr || !chunk->isLighted())
|
||||||
continue;
|
continue;
|
||||||
int segments = 4;
|
|
||||||
int segheight = CHUNK_H / segments;
|
|
||||||
for (int s = 0; s < segments; s++) {
|
for (int s = 0; s < segments; s++) {
|
||||||
for (int i = 0; i < 3; i++) {
|
for (int i = 0; i < 4; i++) {
|
||||||
int bx = rand() % CHUNK_W;
|
int bx = fastmaths::rand() % CHUNK_W;
|
||||||
int by = rand() % segheight + s * segheight;
|
int by = fastmaths::rand() % segheight + s * segheight;
|
||||||
int bz = rand() % CHUNK_D;
|
int bz = fastmaths::rand() % CHUNK_D;
|
||||||
const voxel& vox = chunk->voxels[(by * CHUNK_D + bz) * CHUNK_W + bx];
|
const voxel& vox = chunk->voxels[(by * CHUNK_D + bz) * CHUNK_W + bx];
|
||||||
Block* block = indices->getBlockDef(vox.id);
|
Block* block = indices->getBlockDef(vox.id);
|
||||||
if (block->rt.funcsset.randupdate) {
|
if (block->rt.funcsset.randupdate) {
|
||||||
|
|||||||
17
src/maths/fastmaths.h
Normal file
17
src/maths/fastmaths.h
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
#ifndef MATHS_FASTMATHS_H_
|
||||||
|
#define MATHS_FASTMATHS_H_
|
||||||
|
|
||||||
|
namespace fastmaths {
|
||||||
|
static unsigned int g_seed;
|
||||||
|
|
||||||
|
inline void srand(int seed) {
|
||||||
|
g_seed = seed;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline int rand(void) {
|
||||||
|
g_seed = (214013*g_seed+2531011);
|
||||||
|
return (g_seed>>16)&0x7FFF;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // MATHS_FASTMATHS_H_
|
||||||
Loading…
x
Reference in New Issue
Block a user