Procedural Chunk Generation & Bugfixes
* Fix shader making bottom faces transparent. * Change FOV to 70 * Fix chunk generation(previously was using position vector incorrectly) * Reimplement movement generation * Add username class to playermaster
parent
16ff339a2b
commit
f962ddb4b3
|
@ -16,7 +16,7 @@ uniform sampler2D tex;
|
|||
|
||||
void main() {
|
||||
vec2 texCoord = fragTex;
|
||||
vec4 color = texture(tex, texCoord) * shading;
|
||||
vec4 color = texture(tex, texCoord) * vec4(vec3(shading), 1);
|
||||
|
||||
float near = min(max(fogAlpha - 200, 0) / 100, 1);
|
||||
float far = min(max(fogAlpha - 250, 0) / 100, 1);
|
||||
|
|
|
@ -18,7 +18,7 @@ void main() {
|
|||
vec4 mvPos = view * model * vec4(pos, 1.0);
|
||||
gl_Position = projection * mvPos;
|
||||
|
||||
shading = (0.8 + abs(nor.x) * 0.15) + nor.y * 0.15 + 0.2;
|
||||
shading = (0.8 + abs(nor.x) * 0.15) + (nor.y * 0.15) + 0.2;
|
||||
fogAlpha = distance(vec3(0, 0, 0), vec3(mvPos));
|
||||
fragTex = tex;
|
||||
}
|
||||
|
|
|
@ -47,7 +47,7 @@ private:
|
|||
glm::mat4 orthographicMatrix;
|
||||
|
||||
//Perspective Matrix Properties
|
||||
float fov = 45.0f;
|
||||
float fov = 70.0f;
|
||||
float ratio;
|
||||
float nearClip = 0.1f;
|
||||
float farClip = 1000.0f;
|
||||
|
|
|
@ -37,7 +37,7 @@ void ConnectionList::removePeer(ENetPeer *eNetPeer) {
|
|||
|
||||
ServerPlayer* ConnectionList::createPlayer(ServerPeer *peer, std::string uuid) {
|
||||
printf("[INFO] Creating player %s for %x:%u.\n", uuid.c_str(), peer->peer->address.host, peer->peer->address.port);
|
||||
auto player = new ServerPlayer(peer);
|
||||
auto player = new ServerPlayer(peer, uuid);
|
||||
player->setPos(glm::vec3(0, 16, 0));
|
||||
|
||||
//Send Initialization Data
|
||||
|
|
|
@ -4,10 +4,12 @@
|
|||
|
||||
#include <cmath>
|
||||
#include "ServerPlayer.h"
|
||||
#include "../generic/helpers/ChunkVec.h"
|
||||
|
||||
ServerPlayer::ServerPlayer(ServerPeer *peer) {
|
||||
ServerPlayer::ServerPlayer(ServerPeer *peer, std::string uuid) {
|
||||
this->peer = peer;
|
||||
peer->player = this;
|
||||
this->username = std::move(uuid);
|
||||
}
|
||||
|
||||
Packet ServerPlayer::getInitPacket() {
|
||||
|
@ -28,9 +30,13 @@ glm::vec3 ServerPlayer::getChunkPos() {
|
|||
return chunkPos;
|
||||
}
|
||||
|
||||
glm::vec3 ServerPlayer::getOldPos() {
|
||||
return lastChunkPos;
|
||||
}
|
||||
|
||||
void ServerPlayer::setPos(glm::vec3 pos) {
|
||||
this->pos = pos;
|
||||
glm::vec3 newChunkPos(std::floor(this->pos.x / 16), std::floor(this->pos.y / 16), std::floor(this->pos.z / 16));
|
||||
glm::vec3 newChunkPos = ChunkVec::chunkVec(pos);
|
||||
|
||||
if (newChunkPos != chunkPos) {
|
||||
if (!changedChunks) {
|
||||
|
@ -61,4 +67,8 @@ bool ServerPlayer::isInBounds(glm::vec3 cPos, std::pair<glm::vec3, glm::vec3> &b
|
|||
&& cPos.z >= bounds.first.z && cPos.z <= bounds.second.z);
|
||||
}
|
||||
|
||||
std::string ServerPlayer::getUsername() {
|
||||
return username;
|
||||
}
|
||||
|
||||
ServerPlayer::~ServerPlayer() = default;
|
|
@ -12,9 +12,10 @@
|
|||
|
||||
class ServerPlayer {
|
||||
public:
|
||||
const static int ACTIVE_RANGE = 25;
|
||||
const static int ACTIVE_RANGE = 24;
|
||||
|
||||
explicit ServerPlayer(ServerPeer* peer);
|
||||
//TODO: Refactor instances of UUID to username, or create seperate username flag
|
||||
explicit ServerPlayer(ServerPeer* peer, std::string uuid);
|
||||
|
||||
Packet getInitPacket();
|
||||
|
||||
|
@ -22,6 +23,7 @@ public:
|
|||
void setPos(glm::vec3 pos);
|
||||
|
||||
glm::vec3 getChunkPos();
|
||||
glm::vec3 getOldPos();
|
||||
|
||||
bool changedChunks = false;
|
||||
|
||||
|
@ -30,10 +32,14 @@ public:
|
|||
|
||||
bool isInBounds(glm::vec3 pos, std::pair<glm::vec3, glm::vec3>& bounds);
|
||||
|
||||
std::string getUsername();
|
||||
|
||||
~ServerPlayer();
|
||||
|
||||
ServerPeer* peer;
|
||||
private:
|
||||
std::string username;
|
||||
|
||||
glm::vec3 chunkPos {0, 0, 0};
|
||||
glm::vec3 lastChunkPos {0, 0, 0};
|
||||
glm::vec3 pos {0, 0, 0};
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
//
|
||||
|
||||
#include <algorithm>
|
||||
#include <glm.hpp>
|
||||
#include "World.h"
|
||||
#include "../../generic/network/PacketChannel.h"
|
||||
|
||||
|
@ -15,9 +16,9 @@ void World::addPlayer(ServerPlayer *player) {
|
|||
std::vector<glm::vec3> toGenerate;
|
||||
toGenerate.reserve((unsigned long)pow(ServerPlayer::ACTIVE_RANGE, 3));
|
||||
|
||||
for (int i = (int)bounds.first.x; i < (int)bounds.second.x; i++) {
|
||||
for (int j = (int)bounds.first.x; j < (int)bounds.second.x; j++) {
|
||||
for (int k = (int) bounds.first.x; k < (int) bounds.second.x; k++) {
|
||||
for (int i = (int)bounds.first.x; i <= (int)bounds.second.x; i++) {
|
||||
for (int j = (int)bounds.first.y; j <= (int)bounds.second.y; j++) {
|
||||
for (int k = (int) bounds.first.z; k <= (int) bounds.second.z; k++) {
|
||||
toGenerate.emplace_back(i, j, k);
|
||||
}
|
||||
}
|
||||
|
@ -36,9 +37,36 @@ void World::addPlayer(ServerPlayer *player) {
|
|||
|
||||
void World::playerChangedChunks(ServerPlayer *player) {
|
||||
auto pos = player->getChunkPos();
|
||||
|
||||
auto bounds = player->getBounds();
|
||||
auto oldBounds = player->getOldBounds();
|
||||
|
||||
//TODO: Generate chunks when the player moves
|
||||
std::vector<glm::vec3> toGenerate;
|
||||
toGenerate.reserve((unsigned long)pow(ServerPlayer::ACTIVE_RANGE, 3));
|
||||
|
||||
for (int i = (int)bounds.first.x; i <= (int)bounds.second.x; i++) {
|
||||
for (int j = (int)bounds.first.y; j <= (int)bounds.second.y; j++) {
|
||||
for (int k = (int) bounds.first.z; k <= (int) bounds.second.z; k++) {
|
||||
glm::vec3 tPos(i, j, k);
|
||||
if (!player->isInBounds(tPos, oldBounds)) {
|
||||
toGenerate.push_back(tPos);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
std::sort(toGenerate.begin(), toGenerate.end(), [&](glm::vec3 a, glm::vec3 b) {
|
||||
using namespace std;
|
||||
return max(max(abs(a.x - pos.x), abs(a.y - pos.y)), abs(a.z - pos.z)) <
|
||||
max(max(abs(b.x - pos.x), abs(b.y - pos.y)), abs(b.z - pos.z));
|
||||
});
|
||||
|
||||
for (glm::vec3 tPos : toGenerate) {
|
||||
generate(tPos);
|
||||
}
|
||||
|
||||
printf("[INFO] %s moved, generating %d chunks.\n",
|
||||
player->getUsername().c_str(), (int)toGenerate.size());
|
||||
|
||||
player->changedChunks = false;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue