Skip to content

Commit

Permalink
refactor: use member initializer and uniform initializer
Browse files Browse the repository at this point in the history
  • Loading branch information
Gumichocopengin8 committed Mar 28, 2022
1 parent e092198 commit f64cdec
Show file tree
Hide file tree
Showing 18 changed files with 24 additions and 64 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
.idea
cmake-build-debug/
cmake-build-release/
.vscode/
.DS_Store
7 changes: 0 additions & 7 deletions biome/Biome.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,6 @@
#include <utility>
#include "Biome.h"

Biome::Biome(std::string id, int x, int z, BiomeType *type) {
this->id = std::move(id);
this->x = x;
this->z = z;
this->type = type;
}

float Biome::distance_to(float x, float z) const {
return pow(x - this->x, 2) + pow(z - this->z, 2);
}
5 changes: 3 additions & 2 deletions biome/Biome.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,18 @@

#include <iostream>
#include <string>
#include <utility>

#include "BiomeType.h"

class Biome {
public:
std::string id;
[[maybe_unused]] std::string id;
int x;
int z;
BiomeType *type;

explicit Biome(std::string id, int x, int z, BiomeType *type);
explicit Biome(std::string id, int x, int z, BiomeType *type) : id{std::move(id)}, x{x}, z{z}, type{type} {};

[[nodiscard]] float distance_to(float x, float z) const;
};
Expand Down
10 changes: 0 additions & 10 deletions block/Block.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,11 @@

#include "Block.h"
#include "../texture/Texture.h"
#include <iostream>
#include <cstdlib>
#import <GLUT/glut.h>

#include "../main.h"

Block::Block(int type, int x, int y, int z) {
this->type = type;
this->x = x;
this->y = y;
this->z = z;
}

void Block::render() const {

// Transforms
glPushMatrix();
glTranslated(x, y, z);
Expand Down
2 changes: 1 addition & 1 deletion block/Block.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class Block {
int z;

public:
explicit Block(int type, int x, int y, int z);
explicit Block(int type, int x, int y, int z) : type{type}, x{x}, y{y}, z{z} {};

void render() const;
};
Expand Down
13 changes: 0 additions & 13 deletions camera/Camera.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,6 @@ namespace {
constexpr float CAMERA_HEIGHT = 1.5;
}


Camera::Camera(float camera_x, float camera_y, float camera_z, float pitch, float yaw, float roll) {
this->camera_x = camera_x;
this->camera_y = camera_y;
this->camera_z = camera_z;
this->pitch = pitch;
this->yaw = yaw;
this->roll = roll;
this->x_speed = 0;
this->y_speed = 0;
this->z_speed = 0;
}

void Camera::refresh(Light light) {
// transformations update
gluLookAt(0, 0, 0, 0, 0, 1, 0, 1, 0);
Expand Down
4 changes: 3 additions & 1 deletion camera/Camera.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ class Camera {
float y_speed;
float z_speed;

explicit Camera(float camera_x, float camera_y, float camera_z, float pitch, float yaw, float roll);
explicit Camera(float camera_x, float camera_y, float camera_z, float pitch, float yaw, float roll) :
camera_x{camera_x}, camera_y{camera_y}, camera_z{camera_z}, pitch{pitch}, yaw{yaw}, roll{roll},
x_speed{0}, y_speed{0}, z_speed{0} {};

void refresh(Light light);

Expand Down
2 changes: 0 additions & 2 deletions light/Light.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
#include <GLUT/glut.h>
#include "Light.h"

Light::Light() {}

void Light::ApplyLight() {
glLightfv(GL_LIGHT0, GL_DIFFUSE, this->diffuse);
glLightfv(GL_LIGHT0, GL_AMBIENT, this->ambient);
Expand Down
2 changes: 1 addition & 1 deletion light/Light.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class Light {
public:
float position[4]{0, 0, 0, 1.0}; // TODO: getter setter

explicit Light();
explicit Light() = default;

void ApplyLight();
};
Expand Down
2 changes: 1 addition & 1 deletion main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#include "keyboard/keyboard.h"
#include "player/Player.h"
#include "window/Window.h"
#include "world/world.h"
#include "world/World.h"

#include "biome/BiomeType.h"

Expand Down
6 changes: 0 additions & 6 deletions player/Player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,6 @@
#include <cmath>


Player::Player(Camera camera) : camera(camera) {
this->walking_acceleration = 0.07;
this->running_acceleration = 0.2;
this->vertical_speed = 0.3;
}

void Player::forward(bool run) {
float speed = run ? this->running_acceleration : this->walking_acceleration;
this->camera.move_x(-speed);
Expand Down
3 changes: 2 additions & 1 deletion player/Player.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ class Player {
std::map<char, bool> keys;
Camera camera;

explicit Player(Camera camera);
explicit Player(Camera camera) : camera{camera}, walking_acceleration{0.07}, running_acceleration{0.2},
vertical_speed{0.3} {};

void takeAction();

Expand Down
2 changes: 1 addition & 1 deletion structures/Cloud.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ namespace {
}

Cloud::Cloud(int x, int y, int z, Chunk *chunk) {
int radius_cloud = MIN_RADIUS_CLOUD + this->random(MAX_RADIUS_CLOUD - MIN_RADIUS_CLOUD);
int radius_cloud = MIN_RADIUS_CLOUD + Cloud::random(MAX_RADIUS_CLOUD - MIN_RADIUS_CLOUD);

for (int i = -radius_cloud; i < radius_cloud; ++i) {
for (int j = -radius_cloud; j < radius_cloud; ++j) {
Expand Down
3 changes: 0 additions & 3 deletions structures/SnowFlake.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@
#include "SnowFlake.h"
#include <random>

SnowFlake::SnowFlake() {
this->fall_speed = 0;
}

void SnowFlake::snowGenerate(int x, int y, int z, Chunk *chunk) {
if (chunk->blocks[x][y - this->fall_speed][z] == AIR) {
Expand Down
4 changes: 2 additions & 2 deletions structures/SnowFlake.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@

class SnowFlake {
private:
int fall_speed = 0;
int fall_speed;
public:
explicit SnowFlake();
explicit SnowFlake() : fall_speed{0} {};

void snowGenerate(int x, int y, int z, Chunk *chunk);

Expand Down
12 changes: 7 additions & 5 deletions texture/Texture.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,16 @@
#define PROJECT_TEXTURE_H


#include <iostream>

class Texture {
private:
float ambient[4]{};
float diffuse[4]{};
float specular[4]{};
float shininess[4]{};
float ambient[4];
float diffuse[4];
float specular[4];
float shininess[4];
public:
explicit Texture() = default;
explicit Texture() : ambient{}, diffuse{}, specular{}, shininess{} {};

void apply();

Expand Down
7 changes: 0 additions & 7 deletions window/Window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,6 @@

#include "Window.h"

Window::Window(int default_width, int default_height) {
this->default_width = default_width;
this->width = this->default_width;

this->default_height = default_height;
this->height = this->default_height;
}

void Window::setWidth(int widthValue) {
Window::width = widthValue;
Expand Down
3 changes: 2 additions & 1 deletion window/Window.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ class Window {
int width;
int height;
public:
explicit Window(int default_width, int default_height);
explicit Window(int default_width, int default_height) : default_height{default_height}, height{default_height},
default_width{default_width}, width{default_width} {};

void setWidth(int width);

Expand Down

0 comments on commit f64cdec

Please sign in to comment.