From 09cc67351ec68ed37b2e664c9654f9aabd8fa33b Mon Sep 17 00:00:00 2001 From: cflip Date: Thu, 24 Mar 2022 09:16:57 -0600 Subject: Don't create a copy of the train graphics per vehicle --- src/train.cpp | 4 +++- src/train.h | 3 +-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/train.cpp b/src/train.cpp index d3ea7fb..cfbae97 100644 --- a/src/train.cpp +++ b/src/train.cpp @@ -3,6 +3,8 @@ #include "bitmap.h" #include "level.h" +static const Bitmap SPRITES("res/car.png"); + void Train::update() { if (m_next) { @@ -42,7 +44,7 @@ void Train::draw(Bitmap& bitmap, int xo, int yo) int tx = 0; if (m_dir == East || m_dir == West) tx = 24; - bitmap.blit(m_sprite, xx, yy, tx, 0, TileSize, TileSize); + bitmap.blit(SPRITES, xx, yy, tx, 0, TileSize, TileSize); } void Train::setPosition(int tx, int ty) diff --git a/src/train.h b/src/train.h index 178583f..d47818e 100644 --- a/src/train.h +++ b/src/train.h @@ -8,7 +8,7 @@ class Level; class Train { public: explicit Train(Level& level) - : m_sprite("res/car.png"), m_level(level) { } + : m_level(level) { } void update(); void draw(Bitmap&, int, int); @@ -25,7 +25,6 @@ private: Train* m_next { nullptr }; Train* m_prev { nullptr }; - Bitmap m_sprite; Level& m_level; int x { 0 }, y { 0 }; -- cgit v1.2.3