diff options
author | cflip <cflip@cflip.net> | 2022-03-30 21:48:07 -0600 |
---|---|---|
committer | cflip <cflip@cflip.net> | 2022-03-30 21:48:07 -0600 |
commit | 7803be09b7c0a133b1009408fea2fb1f1474e786 (patch) | |
tree | 351120df9e82973dfa5cda0f9945edbdb3936949 /src/level.h | |
parent | 2b35b393203403704b740f7627af701968c2dfcc (diff) |
Store train objects in a unique_ptr
The trains were being destructed after leaving the scope of the
addVehicle function. This change makes sure the trains stay allocated
for the entire lifetime of the level.
Fixes #2
Diffstat (limited to 'src/level.h')
-rw-r--r-- | src/level.h | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/src/level.h b/src/level.h index 7bd52e2..fa6376d 100644 --- a/src/level.h +++ b/src/level.h @@ -1,10 +1,11 @@ #pragma once -#include "bitmap.h" #include <cstdint> -#include <cstring> +#include <memory> #include <vector> +#include "bitmap.h" + #define TILE_TYPE(x) ((x)&0xf) #define TILE_DATA(x) (x >> 4 & 0xf) #define MAKE_TILE(t, d) ((((d)&0xf) << 4) + ((t)&0xf)) @@ -38,17 +39,18 @@ public: void update(); void draw(Bitmap& bitmap, int xo, int yo); - Train& addVehicle(); + void addVehicle(int x, int y); void toggleTile(int x, int y); void save() const; void load(); + private: Bitmap& m_tileSprites; int m_width, m_height; uint8_t* m_tiles; - std::vector<Train> m_vehicles; + std::vector<std::unique_ptr<Train>> m_vehicles; }; TrackDirection ChooseDirection(Level& level, int x, int y); |