Skip to content

Commit f64cdec

Browse files
refactor: use member initializer and uniform initializer
1 parent e092198 commit f64cdec

File tree

18 files changed

+24
-64
lines changed

18 files changed

+24
-64
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
.idea
22
cmake-build-debug/
3+
cmake-build-release/
34
.vscode/
45
.DS_Store

biome/Biome.cpp

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,6 @@
66
#include <utility>
77
#include "Biome.h"
88

9-
Biome::Biome(std::string id, int x, int z, BiomeType *type) {
10-
this->id = std::move(id);
11-
this->x = x;
12-
this->z = z;
13-
this->type = type;
14-
}
15-
169
float Biome::distance_to(float x, float z) const {
1710
return pow(x - this->x, 2) + pow(z - this->z, 2);
1811
}

biome/Biome.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,18 @@
77

88
#include <iostream>
99
#include <string>
10+
#include <utility>
1011

1112
#include "BiomeType.h"
1213

1314
class Biome {
1415
public:
15-
std::string id;
16+
[[maybe_unused]] std::string id;
1617
int x;
1718
int z;
1819
BiomeType *type;
1920

20-
explicit Biome(std::string id, int x, int z, BiomeType *type);
21+
explicit Biome(std::string id, int x, int z, BiomeType *type) : id{std::move(id)}, x{x}, z{z}, type{type} {};
2122

2223
[[nodiscard]] float distance_to(float x, float z) const;
2324
};

block/Block.cpp

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,11 @@
44

55
#include "Block.h"
66
#include "../texture/Texture.h"
7-
#include <iostream>
8-
#include <cstdlib>
97
#import <GLUT/glut.h>
108

119
#include "../main.h"
1210

13-
Block::Block(int type, int x, int y, int z) {
14-
this->type = type;
15-
this->x = x;
16-
this->y = y;
17-
this->z = z;
18-
}
19-
2011
void Block::render() const {
21-
2212
// Transforms
2313
glPushMatrix();
2414
glTranslated(x, y, z);

block/Block.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class Block {
1717
int z;
1818

1919
public:
20-
explicit Block(int type, int x, int y, int z);
20+
explicit Block(int type, int x, int y, int z) : type{type}, x{x}, y{y}, z{z} {};
2121

2222
void render() const;
2323
};

camera/Camera.cpp

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,6 @@ namespace {
1818
constexpr float CAMERA_HEIGHT = 1.5;
1919
}
2020

21-
22-
Camera::Camera(float camera_x, float camera_y, float camera_z, float pitch, float yaw, float roll) {
23-
this->camera_x = camera_x;
24-
this->camera_y = camera_y;
25-
this->camera_z = camera_z;
26-
this->pitch = pitch;
27-
this->yaw = yaw;
28-
this->roll = roll;
29-
this->x_speed = 0;
30-
this->y_speed = 0;
31-
this->z_speed = 0;
32-
}
33-
3421
void Camera::refresh(Light light) {
3522
// transformations update
3623
gluLookAt(0, 0, 0, 0, 0, 1, 0, 1, 0);

camera/Camera.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@ class Camera {
2121
float y_speed;
2222
float z_speed;
2323

24-
explicit Camera(float camera_x, float camera_y, float camera_z, float pitch, float yaw, float roll);
24+
explicit Camera(float camera_x, float camera_y, float camera_z, float pitch, float yaw, float roll) :
25+
camera_x{camera_x}, camera_y{camera_y}, camera_z{camera_z}, pitch{pitch}, yaw{yaw}, roll{roll},
26+
x_speed{0}, y_speed{0}, z_speed{0} {};
2527

2628
void refresh(Light light);
2729

light/Light.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55
#include <GLUT/glut.h>
66
#include "Light.h"
77

8-
Light::Light() {}
9-
108
void Light::ApplyLight() {
119
glLightfv(GL_LIGHT0, GL_DIFFUSE, this->diffuse);
1210
glLightfv(GL_LIGHT0, GL_AMBIENT, this->ambient);

light/Light.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class Light {
1616
public:
1717
float position[4]{0, 0, 0, 1.0}; // TODO: getter setter
1818

19-
explicit Light();
19+
explicit Light() = default;
2020

2121
void ApplyLight();
2222
};

main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
#include "keyboard/keyboard.h"
1313
#include "player/Player.h"
1414
#include "window/Window.h"
15-
#include "world/world.h"
15+
#include "world/World.h"
1616

1717
#include "biome/BiomeType.h"
1818

0 commit comments

Comments
 (0)