example: add ManyImages sample#32
Conversation
There was a problem hiding this comment.
Pull request overview
Adds a new ThorVG example program (“ManyImages”) and wires it into the Meson build so it is built alongside the other sample executables.
Changes:
- Register
ManyImages.cppinsrc/meson.build’ssource_filelist. - Add
src/ManyImages.cpp, an example that renders and randomly transforms manytvg::Pictureinstances.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| src/meson.build | Includes ManyImages.cpp in the set of example executables built by Meson. |
| src/ManyImages.cpp | New example that creates 500 images and randomizes their transforms each update tick. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
6570640 to
1de3e0a
Compare
1de3e0a to
e152433
Compare
e152433 to
ac12373
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
ac12373 to
84fe257
Compare
84fe257 to
f82dee4
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| auto p = tvg::Picture::gen(); | ||
| p->load(EXAMPLE_DIR"/image/test.png"); | ||
| p->origin(0.5f, 0.5f); | ||
| p->translate(rand() % CANVAS_SIZE, rand() % CANVAS_SIZE); | ||
| p->scale(float(10 + rand() % 90) * 0.005f); | ||
| p->rotate(float(rand() % 360)); | ||
| canvas->add(p); |
There was a problem hiding this comment.
p->load(EXAMPLE_DIR"/image/test.png") ignores the return value. Other picture examples in this repo typically fail the example early when load() fails (e.g., PicturePng.cpp:44). Consider using tvgexam::verify(...) and returning false (or skipping the picture) so the sample doesn't silently run with missing/invalid content when the asset path is wrong or the loader fails.
| { | ||
| for (auto i : canvas->paints()) { | ||
| auto p = static_cast<tvg::Picture*>(i); | ||
| p->translate(rand() % 1650, rand() % 1650); |
There was a problem hiding this comment.
update() hardcodes 1650 for the random translate bounds while the rest of the file defines CANVAS_SIZE. Please use CANVAS_SIZE here as well (or w/h if you want it to follow the window size) to avoid accidental inconsistencies if the canvas size changes later.
| p->translate(rand() % 1650, rand() % 1650); | |
| p->translate(rand() % CANVAS_SIZE, rand() % CANVAS_SIZE); |
| for (int i = 0; i < PIC_COUNT; ++i) { | ||
| auto p = tvg::Picture::gen(); | ||
| p->load(EXAMPLE_DIR"/image/test.png"); | ||
| p->origin(0.5f, 0.5f); | ||
| p->translate(rand() % CANVAS_SIZE, rand() % CANVAS_SIZE); | ||
| p->scale(float(10 + rand() % 90) * 0.005f); | ||
| p->rotate(float(rand() % 360)); | ||
| canvas->add(p); | ||
| } |
There was a problem hiding this comment.
This loads the same PNG from disk PIC_COUNT times. For an example suite this can significantly increase startup time and I/O without changing the rendering stress much. Consider loading once (or loading the file into memory once) and then creating the remaining instances via duplicate() (see Duplicate.cpp:104-115) so you still render 500 pictures but avoid repeated decoding/reads.
Summary