Skip to content

Commit d96a688

Browse files
committed
Optimised project structure
Created debug flags to use/not use separate parts of project Need to not include not using parts Optimised includes, many changes in them Changed loaders structure
1 parent 4abbe49 commit d96a688

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+382
-169
lines changed

src/data/app.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@
55

66
#pragma once
77

8-
#include "libraries.hpp"
9-
#include "initFile.hpp"
108
#include "preloaded/sounds.hpp"
119
#include "preloaded/music.hpp"
1210
#include "window.hpp"
11+
#include "mouse.hpp"
12+
#include "macroses.hpp"
1313

1414

1515
// Class of whole current application

src/data/exceptions.hpp

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@ class LoadException : public std::exception {
1919
const char* message;
2020

2121
public:
22-
LoadException() : message("Unknown error\n") {}
23-
LoadException(const std::string _message) : message(_message.std::string::c_str()) {}
24-
~LoadException() {}
25-
const char* what() const noexcept override {
22+
LoadException() : LoadException("Unknown error\n") {}
23+
LoadException(const std::string _message) : message(_message.std::string::c_str()) {
2624
logImportant(message);
25+
}
26+
const char* what() const noexcept override {
2727
return message;
2828
};
2929
};
@@ -32,11 +32,8 @@ class LoadException : public std::exception {
3232
class LibararyLoadException : LoadException {
3333
public:
3434
LibararyLoadException(const std::string _library = "")
35-
: LoadException("Error with loading library: " + _library + '\n') {
36-
SDL_LogCritical(SDL_LOG_PRIORITY_CRITICAL, "%s", message);
37-
}
35+
: LoadException("Error with loading library: " + _library + '\n') {}
3836
const char* what() const noexcept override {
39-
SDL_LogCritical(SDL_LOG_PRIORITY_CRITICAL, "%s", message);
4037
return message;
4138
}
4239
};
@@ -45,11 +42,8 @@ class LibararyLoadException : LoadException {
4542
class DataLoadException : LoadException {
4643
public:
4744
DataLoadException(const std::string _dataType = "")
48-
: LoadException("Error with load file: " + _dataType + '\n') {
49-
SDL_LogError(SDL_LOG_PRIORITY_ERROR, "%s", message);
50-
}
45+
: LoadException("Error with load file: " + _dataType + '\n') {}
5146
const char* what() const noexcept override {
52-
SDL_LogError(SDL_LOG_PRIORITY_ERROR, "%s", message);
5347
return message;
5448
}
5549
};

src/data/initFile.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
#include "initFile.hpp"
77

88

9+
// Check if has initfile
10+
#if USE_SETTING_FILE
11+
912
InitFile::InitFile() {
1013
loadSettings();
1114
}
@@ -21,3 +24,5 @@ const std::string InitFile::getText(const std::string _line) const {
2124
const unsigned InitFile::getValue(const std::string _line) const {
2225
return std::stoi(_line.substr(_line.rfind('=') + 2));
2326
}
27+
28+
#endif // USE_SETTING_FILE

src/data/initFile.hpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
1010
#include "exceptions.hpp"
1111

1212

13+
// Check if has initfile
14+
#if USE_SETTING_FILE
15+
1316
// Class for load/save settings to/from game
1417
class InitFile {
1518
private:
@@ -22,3 +25,5 @@ class InitFile {
2225
void loadSettings();
2326
void saveSettings();
2427
};
28+
29+
#endif // USE_SETTING_FILE

src/data/libraries.cpp

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,24 @@
77
#include <SDL3_mixer/SDL_mixer.h>
88
#include <SDL3_ttf/SDL_ttf.h>
99
#include "libraries.hpp"
10+
#include "exceptions.hpp"
1011

1112

1213
Libraries::Libraries() {
13-
// Load depend on teting
14+
// Load depend on testing
1415
#if CHECK_CORRECTION
1516
// Initialasing main library
1617
if (!SDL_Init(SDL_INIT_AUDIO | SDL_INIT_VIDEO)) {
1718
throw LibararyLoadException("Main library: " + std::string(SDL_GetError()));
1819
}
1920
// Initialasing font library
21+
#if USE_SDL_FONT
2022
if (!TTF_Init()) {
2123
throw LibararyLoadException("Font library: " + std::string(SDL_GetError()));
2224
}
25+
#endif
2326
// Initialasing audio library
27+
#if USE_SDL_MIXER
2428
if (!Mix_Init(MIX_INIT_MP3 | MIX_INIT_WAVPACK)) {
2529
throw LibararyLoadException("Mixer library: " + std::string(SDL_GetError()));
2630
}
@@ -33,23 +37,34 @@ Libraries::Libraries() {
3337
if (!Mix_OpenAudio(audioDeviceID, NULL)) {
3438
throw LibararyLoadException("Couldn't initialase audio chanel: " + std::string(SDL_GetError()));
3539
}
40+
#endif
3641
logAdditional("Libraries load correctly");
37-
#else
42+
#else // CHECK_CORRECTION
3843
SDL_Init(SDL_INIT_AUDIO | SDL_INIT_VIDEO);
44+
#if USE_SDL_FONT
3945
TTF_Init();
46+
#endif
47+
#if USE_SDL_MIXER
4048
Mix_Init(MIX_INIT_MP3 | MIX_INIT_WAVPACK);
4149
audioDeviceID = SDL_OpenAudioDevice(SDL_AUDIO_DEVICE_DEFAULT_PLAYBACK, NULL);
4250
Mix_OpenAudio(audioDeviceID, NULL);
4351
#endif
52+
#endif // CHECK_CORRECTION
4453
}
4554

4655
Libraries::~Libraries() noexcept {
4756
// Closing audio device
57+
#if USE_SDL_MIXER
4858
Mix_CloseAudio();
4959
SDL_CloseAudioDevice(audioDeviceID);
60+
#endif
5061

5162
// Closing all library reversed
63+
#if USE_SDL_MIXER
5264
Mix_CloseAudio();
65+
#endif
66+
#if USE_SDL_FONT
5367
TTF_Quit();
68+
#endif
5469
SDL_Quit();
5570
}

src/data/libraries.hpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
#pragma once
77

88
#include <SDL3/SDL_audio.h>
9-
#include "exceptions.hpp"
109

1110

1211
// Class for load and close needed libraries

src/data/logger.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
#pragma once
77

88
#include <SDL3/SDL_log.h>
9-
#include "../testing.hpp"
9+
#include "../define.hpp"
1010

1111

1212
// Function for log important information

src/data/mouse.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55

66
#include <SDL3/SDL_mouse.h>
77
#include "mouse.hpp"
8-
#include "macroses.hpp"
98

109

1110
Mouse::Mouse() {
@@ -21,7 +20,7 @@ bool Mouse::in(SDL_FRect _rect) const {
2120
}
2221

2322
bool Mouse::near(float _x, float _y) const {
24-
return (sqr(_x-position.x)+sqr(_y-position.y)) < sqr(5);
23+
return ((_x-position.x)*(_x-position.x)+(_y-position.y)*(_y-position.y)) < 25;
2524
}
2625

2726
float Mouse::getX() const {

src/data/preloaded/fonts.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@
55

66
#include "fonts.hpp"
77

8+
// Check, if use fonts and preload it
9+
#if USE_SDL_FONT && PRELOAD_FONTS
10+
11+
#include "loader/loader.hpp"
12+
#include "../exceptions.hpp"
13+
814

915
FontsData::FontsData() {
1016
// Resetting fonts array
@@ -53,3 +59,5 @@ void FontsData::loadFont(Fonts _index, const char* _fileName) {
5359
TTF_Font* FontsData::operator[](Fonts _index) const {
5460
return fonts[unsigned(_index)];
5561
}
62+
63+
#endif // USE_SDL_FONT && PRELOAD_FONTS

src/data/preloaded/fonts.hpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,13 @@
55

66
#pragma once
77

8-
#include <SDL3_ttf/SDL_ttf.h>
9-
#include "loader/loader.hpp"
108
#include "../../fontsNames.hpp"
119

10+
// Check, if use fonts and preload it
11+
#if USE_SDL_FONT && PRELOAD_FONTS
12+
13+
#include <SDL3_ttf/SDL_ttf.h>
14+
1215

1316
// Class for get font with need height
1417
class FontsData {
@@ -21,3 +24,5 @@ class FontsData {
2124
~FontsData();
2225
TTF_Font* operator[](Fonts index) const;
2326
};
27+
28+
#endif // USE_SDL_FONT && PRELOAD_FONTS

0 commit comments

Comments
 (0)