Skip to content

Commit ec3b710

Browse files
authored
Merge pull request #2 from kolyaka32/Other-libraries-test
Repair archive work, black screen after system
2 parents 44b389f + 466f5a8 commit ec3b710

20 files changed

+267
-620
lines changed

.gitignore

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,12 @@ i686-w64-mingw32/
1414
x86_64-w64-mingw32/
1515

1616
# New include libraries
17+
bin/
18+
cmake/
19+
debug/
1720
lib/
1821
include/
22+
share/
1923

2024
# Prerequisites
2125
*.d
@@ -50,7 +54,7 @@ include/
5054
*.out
5155
*.app
5256

53-
# Archieves
57+
# Archives
5458
*.7z
5559
*.zip
5660

CMakeLists.txt

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,24 @@ add_executable( base
4040
src/set.rc
4141
)
4242
# Setting static dlls
43+
4344
set(CMAKE_CXX_STANDARD_LIBRARIES "-static-libgcc -static-libstdc++ -lwsock32 -lws2_32 -mwindows ${CMAKE_CSS_STANDARD_LIBRARIES}")
44-
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-Bstatic,--whole-archive -lwinpthread -Wl,--no-whole-archive")
45+
#set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-Bstatic,--whole-archive -lwinpthread -Wl,--no-whole-archive")
46+
set(CMAKE_EXE_LINKER_FLAGS "-static-libgcc -static-libstdc++")
47+
48+
# Static?
49+
#set(STATIC_LIB lib_static)
50+
#set(SHARE_LIB lib_share)
51+
52+
#set(STATIC_OTHER_LIB lib_otherstatic)
53+
#set(SHARE_OTHER_LIB lib_othershare)
54+
55+
#set_target_properties(base PROPERTIES LINK_SEARCH_START_STATIC 1)
56+
#set_target_properties(base PROPERTIES LINK_SEARCH_END_STATIC 1)
57+
#set(CMAKE_FIND_LIBRARY_SUFFIXES ".a")
58+
59+
#add_library(${STATIC_LIB} STATIC ${STATIC_LIB}.cpp)
60+
#add_library(${SHARE_LIB} SHARED ${SHARE_LIB}.cpp)
4561

4662
# Including external libraries
4763
set(CMAKE_PREFIX_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
@@ -53,20 +69,14 @@ find_package(SDL2_image REQUIRED)
5369
find_package(SDL2_ttf REQUIRED)
5470
find_package(SDL2_mixer REQUIRED)
5571
# Including libzip
56-
set(CMAKE_PREFIX_PATH "${CMAKE_CURRENT_SOURCE_DIR}/lib/cmake")
57-
find_package(libzip REQUIRED)
72+
set(CMAKE_PREFIX_PATH "${CMAKE_CURRENT_SOURCE_DIR}/share")
73+
find_package(libzip CONFIG REQUIRED)
5874

5975
# Including external included directories
60-
target_include_directories( base
61-
PUBLIC ${SDL2_INCLUDE_DIRS}
62-
PUBLIC ${SDL2_image_INCLUDE_DIRS}
63-
PUBLIC ${SDL2_ttf_config_path}
64-
PUBLIC ${SDL2_mixer_config_path}
65-
PUBLIC &{libzip_INCLUDE_DIRS}
66-
)
76+
include_directories(${SDL2_INCLUDE_DIRS})
6777

6878
# Including linked libraries
69-
target_link_libraries(base PUBLIC ${SDL2_LIBRARIES} SDL2_image::SDL2_image mingw32)
70-
target_link_libraries(base PUBLIC ${SDL2_LIBRARIES} SDL2_ttf::SDL2_ttf mingw32)
71-
target_link_libraries(base PUBLIC ${SDL2_LIBRARIES} SDL2_mixer::SDL2_mixer mingw32)
72-
target_link_libraries(base PUBLIC ${libzip_LIBRARIES} libzip::zip)
79+
target_link_libraries(base PRIVATE ${SDL2_LIBRARIES} SDL2_image::SDL2_image mingw32)
80+
target_link_libraries(base PRIVATE SDL2_ttf::SDL2_ttf mingw32)
81+
target_link_libraries(base PRIVATE SDL2_mixer::SDL2_mixer mingw32)
82+
target_link_libraries(base PRIVATE libzip::zip)

build/img/none.png

-146 Bytes
Binary file not shown.

build/out.bmp

1.23 MB
Binary file not shown.

build/settings.ini

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
language = english
2-
music = 64
3-
effects = 64
4-
maxScore = 0
1+
language = russian
2+
music = 105
3+
effects = 71
4+
maxScore = 40
55
FPS = 60
66
width = 16
77
height = 20

src/baseHud.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
#include "baseHud.hpp"
66

77
// Function of creating font
8-
TTF_Font* createFont(int size){
8+
static TTF_Font* createFont(int size){
99
SDL_RWops* fontData = SDL_RWFromMem(fontMemory, fontSize);
1010
return TTF_OpenFontRW(fontData, 1, size);
1111
};
@@ -50,6 +50,7 @@ void dinamicText::draw(std::string text, const ALIGNMENT_types alignment, SDL_Co
5050
SDL_RenderCopy(app.renderer, Texture, NULL, &Rect);
5151
};
5252

53+
5354
// Slider class
5455
Slider::Slider(int y, IMG_names lineImage, IMG_names buttonImage){
5556
textureLine = Textures[lineImage];
@@ -76,6 +77,7 @@ int Slider::getX(){
7677
return destLine.x;
7778
};
7879

80+
7981
// Button class
8082
Button::Button(int x, int y, IMG_names textureIndex){
8183
texture = Textures[textureIndex];

src/baseHud.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ enum ALIGNMENT_types{
1212
};
1313

1414
// Function of creating font with need height
15-
TTF_Font* createFont(int size);
15+
static TTF_Font* createFont(int size);
1616

1717
// Static text on screen with drawing functions
1818
class staticText
@@ -23,7 +23,7 @@ class staticText
2323
SDL_Texture *Texture = NULL;
2424
SDL_Rect Rect;
2525
public:
26-
void set(std::string text, int size, int x, int y, ALIGNMENT_types alignment = MIDLE_text, SDL_Color color = BLACK);
26+
void set(std::string text, int size, int x, int y, ALIGNMENT_types alignment = MIDLE_text, SDL_Color color = WHITE);
2727
void draw();
2828
void clear();
2929
};

src/dataLoader.cpp

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -8,34 +8,34 @@
88
#include "dataLoader.hpp"
99

1010
// Arcieve local structs
11-
zip_t* archieve; // Archieve with all data
11+
static zip_t* archive; // Archive with all data
1212

1313
// Counters of loaded files
1414
static Uint8 loadedImages;
1515
static Uint8 loadedAnimations;
1616
static Uint8 loadedMusics;
1717
static Uint8 loadedSounds;
1818

19-
// Function of open archieve and setting base password
20-
zip_t* openArchieve(std::string archieveName){
21-
// Open archieve with need name
22-
archieve = zip_open(archieveName.std::string::c_str(), ZIP_RDONLY, NULL);
19+
// Function of open archive and setting base password
20+
zip_t* openarchive(std::string archiveName){
21+
// Open archive with need name
22+
archive = zip_open(archiveName.std::string::c_str(), ZIP_RDONLY, NULL);
2323

2424
#if PASSWORD
25-
zip_set_default_password(archieve, PASSWORD);
25+
zip_set_default_password(archive, PASSWORD);
2626
#endif
2727

28-
// Returning archieve for checking correction
29-
return archieve;
28+
// Returning archive for checking correction
29+
return archive;
3030
};
3131

32-
// Function of getting data of archieve file
33-
static inline SDL_RWops* dataFromArchieve(const char* name){
32+
// Function of getting data of archive file
33+
static inline SDL_RWops* dataFromarchive(const char* name){
3434
// Openning need file
35-
zip_file_t* file = zip_fopen_encrypted(archieve, name, 0, PASSWORD);
35+
zip_file_t* file = zip_fopen_encrypted(archive, name, 0, PASSWORD);
3636

3737
zip_stat_t st;
38-
zip_stat(archieve, name, 0, &st); // Getting data of current file
38+
zip_stat(archive, name, 0, &st); // Getting data of current file
3939
// Checking correction of file
4040
if(st.size == 0){
4141
return NULL;
@@ -56,7 +56,7 @@ static inline SDL_RWops* dataFromArchieve(const char* name){
5656
// Function of loading game icone
5757
static unsigned loadIcone(const char* name){
5858
// Getting icone data
59-
SDL_RWops* tempRW = dataFromArchieve(name);
59+
SDL_RWops* tempRW = dataFromarchive(name);
6060

6161
// Setting window icone
6262
SDL_Surface* iconeImage = IMG_LoadICO_RW(tempRW);
@@ -72,7 +72,7 @@ static unsigned loadIcone(const char* name){
7272
// Functions of loading selected image file
7373
static void loadPicture(const char* name, IMG_names number){
7474
// Getting selected picture data
75-
SDL_RWops* tempRW = dataFromArchieve(name);
75+
SDL_RWops* tempRW = dataFromarchive(name);
7676
// Creating texture from data
7777
Textures[number] = SDL_CreateTextureFromSurface(app.renderer, IMG_LoadPNG_RW(tempRW));
7878
SDL_RWclose(tempRW);
@@ -86,7 +86,7 @@ static void loadPicture(const char* name, IMG_names number){
8686
// Function of loading selected GIF animation
8787
static void loadAnimation(const char* name, ANI_names number){
8888
// Getting selected animation data
89-
SDL_RWops* tempRW = dataFromArchieve(name);
89+
SDL_RWops* tempRW = dataFromarchive(name);
9090
// Creating animation from data
9191
Animations[number] = IMG_LoadAnimation_RW(tempRW, 0);
9292
SDL_RWclose(tempRW);
@@ -100,7 +100,7 @@ static void loadAnimation(const char* name, ANI_names number){
100100
// Function of loading selected music file
101101
static void loadMusic(const char* name, MUS_names number){
102102
// Getting selected music track data
103-
SDL_RWops* tempRW = dataFromArchieve(name);
103+
SDL_RWops* tempRW = dataFromarchive(name);
104104
// Creating music track from data
105105
Musics[number] = Mix_LoadMUSType_RW(tempRW, MUS_MP3, 0);
106106
//Animations[number] = IMG_LoadAnimation_RW(tempRW, 1);
@@ -115,7 +115,7 @@ static void loadMusic(const char* name, MUS_names number){
115115
// Function of loading selected sound
116116
static void loadSound(const char* name, SND_names number){
117117
// Getting selected sound data
118-
SDL_RWops* tempRW = dataFromArchieve(name);
118+
SDL_RWops* tempRW = dataFromarchive(name);
119119
// Creating sound from data
120120
Sounds[number] = Mix_LoadWAV_RW(tempRW, 0);
121121
//Animations[number] = IMG_LoadAnimation_RW(tempRW, 1);
@@ -130,10 +130,10 @@ static void loadSound(const char* name, SND_names number){
130130
// Function of loading font
131131
static unsigned loadFont(const char* name){
132132
// Openning font file
133-
zip_file_t* file = zip_fopen_encrypted(archieve, name, 0, PASSWORD);
133+
zip_file_t* file = zip_fopen_encrypted(archive, name, 0, PASSWORD);
134134

135135
zip_stat_t st;
136-
zip_stat(archieve, name, 0, &st); // Getting data from file
136+
zip_stat(archive, name, 0, &st); // Getting data from file
137137
// Checking correction of file
138138
if(st.size == 0){
139139
return 0;
@@ -165,7 +165,6 @@ static unsigned loadAllImages(){
165165
// Game background
166166
loadPicture("img/kletka_svet.png", IMG_BACK_LIGHT);
167167
loadPicture("img/kletka_tyma.png", IMG_BACK_DARK);
168-
loadPicture("img/none.png", IMG_BACK);
169168
// Game sprites
170169
// Eatable objects
171170
loadPicture("img/Apple.png", IMG_APPLE);
@@ -215,13 +214,13 @@ static unsigned loadAllSounds(){
215214
};
216215

217216
void loadData(std::string fileName){
218-
// Opening archieve
219-
if(openArchieve(fileName) == NULL){
217+
// Opening archive
218+
if(openarchive(fileName) == NULL){
220219
printf("Can't load arcieve");
221220
exit(ERR_FIL_OPN);
222221
}
223222

224-
// Loading data from archieve
223+
// Loading data from archive
225224
if(loadIcone("img/Game.ico") != ICO_count){
226225
printf("Can't load game icone");
227226
exit(ERR_FIL_ICO);
@@ -247,7 +246,8 @@ void loadData(std::string fileName){
247246
exit(ERR_FIL_FNT);
248247
}
249248

250-
zip_close(archieve); // Closing archieve
249+
// Closing archive
250+
zip_close(archive);
251251
}
252252

253253
// Function of clearing all temporary data, loaded from arcieve

src/dataLoader.hpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ void loadData(std::string fileName);
1010
// Function of clearing all temporary data, loaded from arcieve
1111
void unloadData();
1212

13-
// Archieve values
14-
#define PASSWORD NULL // Archieve password
13+
// Archive values
14+
#define PASSWORD NULL // Archive password
1515

1616
// Used numerated numbers
1717
#define ICO_count 1 // Number of icones for better count
@@ -31,7 +31,6 @@ enum IMG_names{
3131
// Game background
3232
IMG_BACK_LIGHT,
3333
IMG_BACK_DARK,
34-
IMG_BACK,
3534
// Game sprites
3635
IMG_APPLE,
3736
IMG_POTATO,

src/define.hpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
#pragma once
22

3-
// Extra modifications for game
4-
//#define MEME_MOD true // Activate meme include mode
5-
63
// System numbers
74
#define WINDOWNAME "Snake on SDL"
85
#define GAME_WIDTH gridX * CELL_SIDE
@@ -21,7 +18,7 @@
2118
// Base game colors
2219
#define BLACK {0, 0, 0, 255}
2320
#define WHITE {255, 255, 255, 255}
24-
#define BACKGROUND_COLOR {0, 255, 0, 255}
21+
#define BACKGROUND_COLOR 0, 150, 0, 255
2522

2623
// Names of directions and they numbers
2724
enum direction{

0 commit comments

Comments
 (0)