Skip to content

Commit

Permalink
cleanup and general bugfixes
Browse files Browse the repository at this point in the history
  • Loading branch information
serg06 committed Dec 17, 2019
1 parent 2cbdf57 commit 6adff6a
Show file tree
Hide file tree
Showing 8 changed files with 92 additions and 179 deletions.
3 changes: 3 additions & 0 deletions src/block.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const std::unordered_map<Block::Value, std::string> Block::top_texture_names = {
{ Block::StillWater, "water_square" },
{ Block::OakWood, "tree_top" },
{ Block::OakLeaves, "leaves" },
{ Block::DiamondBlock, "blockDiamond" },
{ Block::Outline, "outline" },
};

Expand All @@ -16,6 +17,7 @@ const std::unordered_map<Block::Value, std::string> Block::bottom_texture_names
{ Block::StillWater, "water_square" },
{ Block::OakWood, "tree_top" },
{ Block::OakLeaves, "leaves" },
{ Block::DiamondBlock, "blockDiamond" },
{ Block::Outline, "outline" },
};

Expand All @@ -25,6 +27,7 @@ const std::unordered_map<Block::Value, std::string> Block::side_texture_names =
{ Block::StillWater, "water_square" },
{ Block::OakWood, "tree_side" },
{ Block::OakLeaves, "leaves" },
{ Block::DiamondBlock, "blockDiamond" },
{ Block::Outline, "outline" },
};

Expand Down
1 change: 0 additions & 1 deletion src/chunk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ inline float softmax(float v, float minv, float maxv) {
}

Chunk* gen_chunk_data(int chunkX, int chunkZ) {
char buf[256];
FastNoise fn;

// create chunk
Expand Down
11 changes: 8 additions & 3 deletions src/chunkdata.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,16 @@

using namespace vmath;

static inline ivec4 clamp_coords_to_world(ivec4 coords) {
coords[1] = std::clamp(coords[1], 0, BLOCK_MAX_HEIGHT);
return coords;

static inline ivec4 clamp_coords_to_world(const ivec4 &coords) {
return { coords[0], std::clamp(coords[1], 0, BLOCK_MAX_HEIGHT), coords[2], 0 };
}

static inline ivec3 clamp_coords_to_world(const ivec3 &coords) {
return { coords[0], std::clamp(coords[1], 0, BLOCK_MAX_HEIGHT), coords[2] };
}


// Chunk Data is always stored as width wide and depth deep
class ChunkData {
public:
Expand Down
10 changes: 2 additions & 8 deletions src/game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@
#include <vmath.h> // TODO: Upgrade version, or use better library?
#include <windows.h>

#define NUM_MESH_GEN_THREADS 1

// 1. TODO: Apply C++11 features
// 2. TODO: Apply C++14 features
// 3. TODO: Apply C++17 features
Expand All @@ -35,13 +33,12 @@ using namespace std;
using namespace vmath;

namespace {
static bool stop = new bool;
static bool stop = false;
}

// Windows main
int CALLBACK WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
stop = false;
glfwSetErrorCallback(glfw_onError);
App::app = new App();
App::app->run();
Expand Down Expand Up @@ -125,7 +122,6 @@ void App::startup() {
memset(held_keys, false, sizeof(held_keys));
glfwGetCursorPos(window, &last_mouse_x, &last_mouse_y); // reset mouse position
world = new World();
world->glInfo = &glInfo;

// prepare opengl
setup_opengl(&glInfo);
Expand Down Expand Up @@ -240,8 +236,6 @@ void App::render(float time) {

// update player's movement based on how much time has passed since we last did it
void App::update_player_movement(const float dt) {
char buf[256];

/* VELOCITY FALLOFF */

// TODO: Handle walking on blocks, in water, etc. Maybe do it based on friction.
Expand Down Expand Up @@ -584,7 +578,7 @@ void App::onMouseButton(int button, int action) {

// if we're not in the way, place it
if (result == end(intersecting_blocks)) {
world->add_block(desired_position, Block::Grass);
world->add_block(desired_position, Block::DiamondBlock);
}
}
}
Expand Down
1 change: 1 addition & 0 deletions src/game.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#define __GAME_H__

#define GPU_MAX_CHUNKS 256
#define NUM_MESH_GEN_THREADS 1

#include "chunk.h"
#include "chunkdata.h"
Expand Down
5 changes: 1 addition & 4 deletions src/render.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -302,10 +302,7 @@ namespace {

float* red = new float[16 * 16 * MAX_BLOCK_TYPES * 4];
for (int i = 0; i < 16 * 16 * MAX_BLOCK_TYPES; i++) {
red[i * 4 + 0] = 1.0f; // R
red[i * 4 + 1] = 0.0f; // G
red[i * 4 + 2] = 0.0f; // B
red[i * 4 + 3] = 1.0f; // A
((vec4*)red)[i] = { 1.0f, 0.0f, 0.0f, 1.0f };
}

// set all textures as BRIGHT RED, so we know when something's wrong
Expand Down
3 changes: 3 additions & 0 deletions src/world.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,9 @@ MiniChunkMesh* World::gen_minichunk_mesh(MiniChunk* mini) {
}
}

// TODO: rotate texture sides the correct way. (It's noticeable when placing down diamond block.)
// -> Or alternatively, can just rotate texture lmao.

// convert quads back to 3D coordinates
vector<Quad3D> quads = quads_2d_3d(quads2d, layers_idx, i, face);

Expand Down
Loading

0 comments on commit 6adff6a

Please sign in to comment.