Skip to content

Commit 863b7e5

Browse files
committed
rebase from main + remove leaks
1 parent df3c6ce commit 863b7e5

7 files changed

Lines changed: 48 additions & 115 deletions

File tree

src/editor.cc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,9 @@ void Editor::Draw() const
243243
Sprites[deco].Draw(m_level.T[NumN].Deco[i].x, m_level.T[NumN].Deco[i].y, m_level.T[NumN].Deco[i].NumSpr);
244244
}
245245

246+
// Displays the level number
247+
//DrawNumber(740, 130, NumN + 1);
248+
246249
// Display possible sprites
247250
for (i = 0; i < LT * HT; i++) {
248251
switch (T[i]) {

src/game.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -359,10 +359,11 @@ bool Game::DrawLevel(int LevelN)
359359
#endif
360360

361361
// Displays texts for selected language
362+
m_screen.ChangeFontSize(20);
362363
m_screen.ChangeFontColor(255, 255, 0);
363364
m_screen.PrintText("Level", 740-m_screen.TextLength("Level")/2, 110);
364365
m_screen.PrintText("Score", 740-m_screen.TextLength("Score")/2, 180);
365-
m_screen.PrintText("Config", 740-m_screen.TextLength("Config")/2, 260);
366+
m_screen.PrintText("Options", 740-m_screen.TextLength("Options")/2, 260);
366367
m_screen.PrintText("Lives", 740-m_screen.TextLength("Lives")/2, 340);
367368
m_screen.ChangeFontColor(255, 255, 255);
368369

src/menu.cc

Lines changed: 25 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -646,13 +646,13 @@ eMenu Menu::SDLMain_Options()
646646

647647
switch (Pref.AudioTheme) {
648648
case mMaf:
649-
DrawString(400, 420, "MAF 464", Sprites[fmenu].Image[0]);
649+
m_screen.PrintText("MAF 464", 400, 390);
650650
break;
651651
case mZabiden:
652-
DrawString(400, 420, "ZABIDEN", Sprites[fmenu].Image[0]);
652+
m_screen.PrintText("ZABIDEN", 400, 390);
653653
break;
654654
}
655-
DrawString(350, 370, "Audio Theme", Sprites[fmenu].Image[0]);
655+
m_screen.PrintText("Audio Theme", 360, 340);
656656

657657
NumSp = (currentTime / 30) % 25;
658658
m_screen.PrintSprite(sound, NumSp, 150, 110);
@@ -1147,7 +1147,7 @@ eMenu Menu::SDLMain_HR()
11471147
}
11481148
}
11491149

1150-
// Test if Endished
1150+
// Test if finished
11511151
if (Done != -1 && Done < currentTime) {
11521152
return mGame;
11531153
}
@@ -1320,32 +1320,31 @@ eMenu Menu::SDLMain_Score(bool EditScore)
13201320
char Provi[256];
13211321
char key;
13221322

1323-
// Cherche le numéro du score à remplacer si edition des scores
1323+
// Searches the score index to edit
13241324
if (EditScore) {
1325-
for (i = 0; i < 8; i++) {
1325+
for (i = 7; i >= 0; i--) {
13261326
if (Pref.Sco[i].Score < Pref.Score) {
13271327
NEdit = i;
1328-
break;
13291328
}
13301329
}
13311330
if (NEdit == -1) {
13321331
return mMenu;
13331332
}
13341333

1335-
if (NEdit < 7) { // Si doit fair un décalage
1334+
if (NEdit < 7) { // if shifting must be done
13361335
for (i = 7; i > NEdit; i--) {
13371336
Pref.Sco[i].Score = Pref.Sco[i - 1].Score;
13381337
Pref.Sco[i].Name = Pref.Sco[i - 1].Name;
13391338
}
13401339
}
13411340

1342-
// Efface le nouveau nom et met le score
1341+
// Erase name and enter score
13431342
Pref.Sco[NEdit].Score = Pref.Score;
13441343
Pref.Sco[NEdit].Name.clear();
13451344
}
13461345

1347-
// Met la sourie sur tous l'ecran
1348-
m_mouse.Init(Menu_Py); // Initialise la sourie
1346+
// Sets mouse on entire display
1347+
m_mouse.Init(Menu_Py);
13491348
Menu_Py[0].StartX = 0;
13501349
Menu_Py[0].StartY = 0;
13511350
Menu_Py[0].EndX = 800;
@@ -1358,12 +1357,12 @@ eMenu Menu::SDLMain_Score(bool EditScore)
13581357
SDL_StartTextInput();
13591358
}
13601359

1361-
// Prend les evenements
1360+
// Fetch events
13621361
do {
1363-
// Efface le background
1362+
// Erase background
13641363
m_screen.CleanSpriteAndScreen(fmenu);
13651364
SDL_RenderClear(sdlRenderer);
1366-
// Prend l'image du background et fait l'affichage
1365+
// Set background image and build display
13671366
Sprites[background_menu].Draw(400, 300, 0, Sprites[fmenu].Image[0]);
13681367

13691368
// Draw title and commands
@@ -1394,37 +1393,42 @@ eMenu Menu::SDLMain_Score(bool EditScore)
13941393
m_screen.PrintText(Provi, 740 - m_screen.TextLength(std::string(Provi)), 120 + i * (360 / 7));
13951394
}
13961395

1397-
// Efface le background
1396+
// Erase background
13981397
SDL_Event event;
13991398
while (SDL_PollEvent(&event)) {
1400-
m_mouse.GetEvent(event, PyE); // Handle mouse
1401-
m_gamepad.GetEvent(event); // Handle gamepad
1399+
m_mouse.GetEvent(event, PyE);
1400+
m_gamepad.GetEvent(event);
14021401

14031402
switch (event.type) {
14041403
case SDL_WINDOWEVENT:
14051404
if (event.window.event == SDL_WINDOWEVENT_ENTER) {
14061405
SDL_RenderPresent(sdlRenderer);
14071406
}
14081407
break;
1409-
case SDL_KEYDOWN: // Prend un touche au clavier
1408+
case SDL_KEYDOWN: // Waits a Keyboard press
14101409
if (event.key.state == SDL_PRESSED) {
14111410
if (NEdit >= 0 && event.key.keysym.sym == SDLK_BACKSPACE && !Pref.Sco[NEdit].Name.empty()) {
14121411
Pref.Sco[NEdit].Name.pop_back();
14131412
}
14141413
m_audio.Play(sClick);
1414+
if (EditScore == false && event.key.keysym.sym != SDLK_F12) {
1415+
event.key.keysym.sym = SDLK_RETURN;
1416+
}
14151417
switch (event.key.keysym.sym) {
14161418
case SDLK_F12: // Save screenshot
14171419
if (event.key.repeat == 0) {
14181420
Utils::doScreenshot(sdlRenderer);
14191421
}
14201422
break;
1421-
case SDLK_ESCAPE: // Valide l'entrée
1423+
case SDLK_ESCAPE: // Validates entry
14221424
case SDLK_RETURN:
14231425
case SDLK_KP_ENTER:
14241426
if (EditScore) {
14251427
SDL_StopTextInput();
14261428
}
14271429
return mMenu;
1430+
default:
1431+
break;
14281432
}
14291433
}
14301434
break;
@@ -1441,7 +1445,7 @@ eMenu Menu::SDLMain_Score(bool EditScore)
14411445
}
14421446
}
14431447

1444-
// Gère les variables
1448+
// Handle variables
14451449
previousTime = currentTime;
14461450
currentTime = SDL_GetTicks();
14471451
Sleeping();
@@ -1458,7 +1462,7 @@ eMenu Menu::SDLMain_Score(bool EditScore)
14581462
m_screen.PrintSprite(arrow_right, i, 180 + textLen, 120 + NEdit * (360 / 7));
14591463
}
14601464

1461-
// Echange les buffets video
1465+
// Update render
14621466
SDL_RenderPresent(sdlRenderer);
14631467

14641468
} while (true);

src/screen.cc

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,6 @@ Screen::Screen()
5050
/******************/
5151
Screen::~Screen()
5252
{
53-
// Destroying font
54-
SDL_DestroyTexture(fontTexture);
5553
TTF_CloseFont(m_font);
5654
}
5755

@@ -83,18 +81,21 @@ void Screen::ChangeFontColor(float r, float g, float b){
8381
/**********************/
8482
void Screen::PrintText(const std::string &Text, int x, int y)
8583
{
86-
fontSurface = TTF_RenderUTF8_Blended(m_font, Text.c_str(), fColor); // Rendering text
87-
fontTexture = SDL_CreateTextureFromSurface(sdlRenderer, fontSurface); // Creating texture
84+
SDL_Texture *texture = nullptr;
85+
SDL_Surface *surf = TTF_RenderUTF8_Blended(m_font, Text.c_str(), fColor);
86+
texture = SDL_CreateTextureFromSurface(sdlRenderer, surf);
87+
SDL_FreeSurface(surf);
8888

8989
// Setting position and size
90-
SDL_Rect dst;
91-
dst.x = x;
92-
dst.y = y;
93-
dst.w = fontSurface->w;
94-
dst.h = fontSurface->h;
90+
SDL_Rect Position;
91+
SDL_QueryTexture(texture, NULL, NULL, &Position.w, &Position.h);
92+
Position.x = x;// - Position.w;
93+
Position.y = y;// - Position.h;
94+
9595

9696
// Rendering text
97-
SDL_RenderCopy(sdlRenderer, fontTexture, nullptr, &dst);
97+
SDL_RenderCopy(sdlRenderer, texture, nullptr, &Position);
98+
SDL_DestroyTexture(texture);
9899
}
99100

100101
int Screen::TextLength(std::string Text){
@@ -105,7 +106,7 @@ int Screen::TextLength(std::string Text){
105106

106107
/*** Display game settings ***/
107108
/*****************************/
108-
void Screen::PrintOptions(int NV, int NScore)
109+
void Screen::PrintOptions(int Nlives, int NScore)
109110
{
110111
int x, y;
111112

@@ -114,14 +115,14 @@ void Screen::PrintOptions(int NV, int NScore)
114115
PrintText(std::to_string(Score), 740 - TextLength(std::to_string(Score))/2, 215);
115116
ChangeFontSize(22);
116117

117-
if (NV > 10) {
118-
NV = 10; // Clamp to avoid going off screen
118+
if (Nlives > 10) {
119+
Nlives = 10; // Clamp to avoid going off screen
119120
}
120-
for (int i = 0; i < NV; ++i) { // Display lives
121+
for (int i = 0; i < Nlives; ++i) { // Display lives
121122
x = i % 2;
122123
x = x * 44 + 38 + LT * D_Case;
123124
y = i / 2;
124-
y = 394 + y * 46;
125+
y = 384 + y * 46;
125126
Sprites[logo_health].Draw(x, y, 0);
126127
}
127128
}

src/screen.h

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,9 @@
2525
#define SCREEN_DOM_
2626

2727
#include <SDL2/SDL_ttf.h>
28-
#include <SDL2/SDL_log.h>
29-
#include <SDL2/SDL_rect.h>
3028
#include <SDL2/SDL_surface.h>
31-
#include <SDL2/SDL_timer.h>
29+
#include <string>
3230
#include "preference.h"
33-
#include "string"
3431
#include "sprite.h"
3532

3633
class Screen
@@ -50,10 +47,8 @@ class Screen
5047

5148
private:
5249
int Score { -1 }; // Stores displayed score
53-
TTF_Font* m_font;
5450
SDL_Color fColor;
55-
SDL_Surface* fontSurface;
56-
SDL_Texture* fontTexture;
51+
TTF_Font *m_font;
5752
};
5853

5954
#endif

src/sprite.cc

Lines changed: 0 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -226,49 +226,6 @@ int NumberLength(int C)
226226
return l;
227227
}
228228

229-
/*** Returns the length of a string ***/
230-
/**************************************/
231-
int StringLength(char *Text)
232-
{
233-
int i = 0;
234-
int l = 0;
235-
int Le;
236-
237-
while (Text[i] != 0) {
238-
Le = (int)(Text[i]);
239-
if (TextTable[Le] != -1) {
240-
l += Sprites[letters].Dim[(TextTable[Le])].L;
241-
if (Text[i + 1] != 0) {
242-
l += GAP_BETWEEN_LETTERS;
243-
}
244-
}
245-
else {
246-
if (Le == (int)(' ')) {
247-
l += SPACE_LENGTH;
248-
}
249-
}
250-
251-
i++;
252-
}
253-
254-
return l;
255-
}
256-
257-
/*** Checks if a char exists ***/
258-
/*******************************/
259-
bool CharExist(char C)
260-
{
261-
if ((int)(C) < 0) {
262-
return false;
263-
}
264-
if (C == ' ') {
265-
return true;
266-
}
267-
if (TextTable[(int)(C)] != -1) {
268-
return true;
269-
}
270-
return false;
271-
}
272229
/*** Displays a number ***/
273230
/*************************/
274231
void DrawNumber(int x, int y, int Number, SDL_Texture *Background)
@@ -283,31 +240,6 @@ void DrawNumber(int x, int y, int Number, SDL_Texture *Background)
283240
} while (Number);
284241
}
285242

286-
/*** Display a string ***/
287-
/************************/
288-
void DrawString(int x, int y, const char *Text, SDL_Texture *background)
289-
{
290-
int i = 0;
291-
int Le;
292-
293-
// TODO Handle here unicode
294-
while (Text[i] != 0) {
295-
Le = (int)(Text[i]);
296-
297-
if (TextTable[Le] != -1) { // If known char
298-
Le = TextTable[Le];
299-
Sprites[letters].Draw(x + (Sprites[letters].Dim[Le].L / 2), y, Le, background);
300-
x += Sprites[letters].Dim[Le].L + GAP_BETWEEN_LETTERS;
301-
}
302-
else { // if there's a space
303-
if (Le == (int)(' ')) {
304-
x += SPACE_LENGTH - GAP_BETWEEN_LETTERS;
305-
}
306-
}
307-
308-
i++;
309-
}
310-
}
311243

312244
/*** Display text in a language ***/
313245
/**********************************/

src/sprite.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -177,11 +177,8 @@ bool LoadLanguage(); // Loads sprites of a language
177177
bool LoadSprites(); // Loads all sprites
178178

179179
int NumberLength(int C); // Returns the length in pixels of a number
180-
int StringLength(char *Text); // Returns the length in pixels of a string.
181-
bool CharExist(char C); // Checks if a character exists
182180

183181
void DrawNumber(int x, int y, int Number, SDL_Texture *Background = nullptr); // Displays a number
184-
void DrawString(int x, int y, const char *Text, SDL_Texture *Background = nullptr); // Displays a string
185182

186183
void DrawText(int x, int y, e_Sprite Text, SDL_Texture *Background = nullptr); // Displays a text in the language
187184

0 commit comments

Comments
 (0)