Skip to content

Commit 096fc18

Browse files
Transfered changes
1 parent faf9607 commit 096fc18

32 files changed

Lines changed: 1002 additions & 1156 deletions

main/CMakeLists.txt

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,7 @@ idf_component_register(SRCS
1919
"examples/CollisionTest.cpp"
2020
"examples/Fire.cpp"
2121
"examples/Platformer.cpp"
22-
"examples/SpaceShooter.cpp"
2322
"examples/TextExample.cpp"
24-
"examples/LittlefsTest.cpp"
25-
"examples/TextureTest.cpp"
2623
INCLUDE_DIRS
2724
"include"
2825
"include/Shapes"

main/examples/CollisionTest.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,19 @@
88
#include "freertos/projdefs.h"
99
#include "freertos/task.h"
1010
#include <cstdio>
11+
#include <memory>
1112
#include <stdio.h>
1213

1314
void runCollisionTest() {
1415
const int width = 64;
1516
const int height = 64;
1617
Renderer renderer(width, height, Color(0, 0, 0, 1.0f));
17-
Collection *mainCollection =
18-
new Collection(ShapeParams{32, 32, Color(0, 0, 0, 1.0f), 0});
18+
auto mainCollection = std::make_shared<Collection>(
19+
ShapeParams{32, 32, Color(0, 0, 0, 1.0f), 0});
1920

20-
RegularPolygon *triangle = new RegularPolygon(
21+
auto triangle = std::make_shared<RegularPolygon>(
2122
RegularPolygonRadiusParams{32, 60, Color(0, 255, 0, 1.0f), 3, 4, true});
22-
Rectangle *enemy = new Rectangle(
23+
auto enemy = std::make_shared<Rectangle>(
2324
RectangleParams{20, 0, Color(255, 0, 0, 1.0f), 10, 10, true});
2425
triangle->addCollider();
2526
enemy->addCollider();
@@ -50,7 +51,7 @@ void runCollisionTest() {
5051
triangle->setColor(Color(0, 255, 0, 1.0f)); // Green otherwise
5152
}
5253

53-
renderer.render(pixels, std::vector<Collection *>{mainCollection},
54+
renderer.render(pixels, std::vector<std::shared_ptr<Collection>>{mainCollection},
5455
options);
5556
display.setBuffer(pixels);
5657
vTaskDelay(pdMS_TO_TICKS(100));

main/examples/LittlefsTest.cpp

Lines changed: 0 additions & 104 deletions
This file was deleted.

main/examples/Platformer.cpp

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include "freertos/projdefs.h"
1111
#include "freertos/task.h"
1212
#include <cstdint>
13+
#include <memory>
1314
#include <vector>
1415

1516
void init_input_gpio(int gpio_num) {
@@ -45,20 +46,21 @@ void runPlatformer() {
4546
return;
4647
}
4748

48-
Collection *mainCollection =
49-
new Collection(ShapeParams{0, 0, Color(0, 0, 0, 0), 0});
49+
auto mainCollection =
50+
std::make_shared<Collection>(ShapeParams{0, 0, Color(0, 0, 0, 0), 0});
5051

5152
// --- Player Setup ---
52-
Rectangle *player = new Rectangle(
53+
auto player = std::make_shared<Rectangle>(
5354
RectangleParams{10, 48, Color(255, 80, 80, 1.0f), 5, 8, true});
5455
player->addCollider();
5556
mainCollection->addShape(player);
5657

5758
// --- Platform Setup ---
58-
std::vector<Rectangle *> platforms;
59+
std::vector<std::shared_ptr<Rectangle>> platforms;
5960

6061
auto createPlatform = [&](int x, int y, int w, int h, Color c) {
61-
Rectangle *p = new Rectangle(RectangleParams{x, y, c, w, h, true});
62+
auto p =
63+
std::make_shared<Rectangle>(RectangleParams{x, y, c, w, h, true});
6264
p->addCollider();
6365
platforms.push_back(p);
6466
mainCollection->addShape(p);
@@ -112,7 +114,7 @@ void runPlatformer() {
112114
float oldPlayerY = player->getY();
113115
player->translate(0.0f, velocityY);
114116
canJump = false;
115-
for (auto *platform : platforms) {
117+
for (const auto& platform : platforms) {
116118
if (player->intersects(platform)) {
117119

118120
if (velocityY > 0 &&
@@ -139,8 +141,9 @@ void runPlatformer() {
139141

140142
// --- Rendering ---
141143
pixels.clear();
142-
renderer.render(pixels, std::vector<Collection *>{mainCollection},
143-
options);
144+
renderer.render(
145+
pixels, std::vector<std::shared_ptr<Collection>>{mainCollection},
146+
options);
144147
display.setBuffer(pixels);
145148

146149
// --- Frame Rate Control ---
@@ -152,6 +155,4 @@ void runPlatformer() {
152155
vTaskDelay(pdMS_TO_TICKS(remainingTime / 1000));
153156
}
154157
}
155-
156-
delete mainCollection;
157158
}

main/examples/SolarSystem.cpp

Lines changed: 17 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -18,47 +18,43 @@ void runSolarSystem() {
1818
const int height = 64;
1919
Renderer renderer(width, height, Color(0, 0, 0, 1.0f));
2020

21-
std::vector<Collection *> collections;
21+
std::vector<std::shared_ptr<Collection>> collections;
2222

23-
Collection *sunCollection =
24-
new Collection(ShapeParams{32, 32, Color(0, 0, 0, 1.0f), 0});
23+
auto sunCollection = std::make_shared<Collection>(
24+
ShapeParams{0, 0, Color(0, 0, 0, 1.0f), 0});
2525
sunCollection->setPivot(32.0f, 32.0f);
2626
collections.push_back(sunCollection);
2727

28-
Circle *sun =
29-
new Circle(CircleParams{32, 32, Color(255, 204, 0, 1.0f), 8, true});
28+
auto sun = std::make_shared<Circle>(
29+
CircleParams{32, 32, Color(255, 204, 0, 1.0f), 8, true});
3030
sunCollection->addShape(sun);
3131

32-
std::vector<std::pair<int, int>> polygonVertices = {
33-
{60, 60}, {63, 61}, {61, 63}};
34-
Polygon *polygon = new Polygon(
35-
PolygonParams{32, 32, Color(255, 150, 0, 1.0f), polygonVertices, true});
36-
sunCollection->addShape(polygon);
37-
38-
Collection *earthCollection =
39-
new Collection(ShapeParams{32, 32, Color(0, 0, 0, 1.0f), 1});
32+
auto earthCollection = std::make_shared<Collection>(
33+
ShapeParams{0, 0, Color(0, 0, 0, 1.0f), 1});
4034
earthCollection->setPivot(32.0f, 32.0f);
4135

42-
Circle *earth = new Circle(
36+
auto earth = std::make_shared<Circle>(
4337
CircleParams{32 + 20, 32, Color(0, 100, 255, 1.0f), 4, true});
4438
earthCollection->addShape(earth);
4539

46-
Circle *alien = new Circle(
40+
auto alien = std::make_shared<Circle>(
4741
CircleParams{32 - 20, 32, Color(0, 255, 100, 1.0f), 4, true});
4842
earthCollection->addShape(alien);
4943

50-
Collection *moonCollection =
51-
new Collection(ShapeParams{32 + 20, 32, Color(0, 0, 0, 1.0f), 1});
52-
Circle *moon = new Circle(
44+
auto moonCollection = std::make_shared<Collection>(
45+
ShapeParams{0, 0, Color(0, 0, 0, 1.0f), 1});
46+
moonCollection->setPivot(52.0f, 32.0f);
47+
48+
auto moon = std::make_shared<Circle>(
5349
CircleParams{32 + 20 + 8, 32, Color(200, 200, 200, 1.0f), 2, true});
5450
moonCollection->addShape(moon);
5551

5652
earthCollection->addShape(moonCollection);
5753
sunCollection->addShape(earthCollection);
5854

59-
Circle *earthOrbit =
60-
new Circle(CircleParams{32, 32, Color(100, 100, 100, 0.3f), 20, false});
61-
Circle *moonOrbit = new Circle(
55+
auto earthOrbit = std::make_shared<Circle>(
56+
CircleParams{32, 32, Color(100, 100, 100, 0.3f), 20, false});
57+
auto moonOrbit = std::make_shared<Circle>(
6258
CircleParams{32 + 20, 32, Color(100, 100, 100, 0.3f), 8, false});
6359
sunCollection->addShape(earthOrbit);
6460
earthCollection->addShape(moonOrbit);
@@ -121,8 +117,4 @@ void runSolarSystem() {
121117
renderTime = 0;
122118
}
123119
}
124-
// Cleanup
125-
for (auto collection : collections) {
126-
delete collection;
127-
}
128120
}

0 commit comments

Comments
 (0)