i'm writing ascii game engine windows console, , 1 of classes i'm working image class, data members include width, height, , pointers dynamically allocated arrays of unsigned chars represent character , colour data image.
originally constructing of images data structs defined elsewhere in program, proved quite inefficient past first couple practice images tried create constructor read required data text file instead. format of text file is:
width
height
[chars]
[colours]
where chars , colours arrays separated whitespace of width * height size (full image file pasted below if you're interested). however, when call constructor, goes wrong - in debug mode in eclipse, nothing looks strange @ , in fact looks it's copying on character , colour arrays fine, executing program doesn't draw image screen when it's asked to.
the original version of constructor looks this:
image::image(const int w, const int h, const char *chrs, const col *cols) :width(w), height(h) { chars = new char[w * h]; colours = new col[w * h]; (int = 0; < w * h; ++i) { chars[i] = chrs[i]; colours[i] = cols[i]; } }
and called so:
image *sun_image = new image(sun.width, sun.height, sun.chars, sun.colours);
with sun struct defined this:
sun_s sun = { sunw, sunh, { 255,255,255,255,255,255,255,177,255,255,255,255,255,255,255, 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, 255,255,255,177,255,255,255,177,255,255,255,177,255,255,255, 255,255,255,255,177,255,255,255,255,255,177,255,255,255,255, 255,255,255,255,255,255,177,177,177,255,255,255,255,255,255, 255,255,255,255,255,177,178,219,178,177,255,255,255,255,255, 255,255,255,255,177,178,219,219,219,178,177,255,255,255,255, 177,255,177,255,177,219, 94,219, 94,219,177,255,177,255,177, 255,255,255,255,177,178,219,126,219,178,177,255,255,255,255, 255,255,255,255,255,177,178,219,178,177,255,255,255,255,255, 255,255,255,255,255,255,177,177,177,255,255,255,255,255,255, 255,255,255,255,177,255,255,255,255,255,177,255,255,255,255, 255,255,255,177,255,255,255,177,255,255,255,177,255,255,255, 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, 255,255,255,255,255,255,255,177,255,255,255,255,255,255,255, }, { 0, 0, 0, 0, 0, 0, 0, 62, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 62, 0, 0, 0, 62, 0, 0, 0, 62, 0, 0, 0, 0, 0, 0, 0, 62, 0, 0, 0, 0, 0, 62, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 62, 62, 62, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 62, 62, 14, 62, 62, 0, 0, 0, 0, 0, 0, 0, 0, 0, 62, 62, 14, 14, 14, 62, 62, 0, 0, 0, 0, 62, 0, 62, 0, 62, 14,224, 14,224, 14, 62, 0, 62, 0, 62, 0, 0, 0, 0, 62, 62, 14,224, 14, 62, 62, 0, 0, 0, 0, 0, 0, 0, 0, 0, 62, 62, 14, 62, 62, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 62, 62, 62, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 62, 0, 0, 0, 0, 0, 62, 0, 0, 0, 0, 0, 0, 0, 62, 0, 0, 0, 62, 0, 0, 0, 62, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 62, 0, 0, 0, 0, 0, 0, 0, } };
the attempted new version of constructor looks this:
image::image(const char *filename) { std::ifstream inputfile; inputfile.open(filename, std::ios::in); if (inputfile.is_open()) { inputfile >> width; inputfile >> height; chars = new char[width * height]; colours = new char[width * height]; int temp, i; (i = 0; < height * width; ++i) { inputfile >> temp; chars[i] = (char)temp; } (i = 0; < width * height; ++i) { inputfile >> temp; colours[i] = (char)temp; } } else { width = 0; height = 0; chars = new char[width * height]; colours = new char[width * height]; } inputfile.close(); }
with call looks like:
image *sun_image = new image("./artassets/sun.txt");
and sun.txt looks like:
15 15 255 255 255 255 255 255 255 177 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 177 255 255 255 177 255 255 255 177 255 255 255 255 255 255 255 177 255 255 255 255 255 177 255 255 255 255 255 255 255 255 255 255 177 177 177 255 255 255 255 255 255 255 255 255 255 255 177 178 219 178 177 255 255 255 255 255 255 255 255 255 177 178 219 219 219 178 177 255 255 255 255 177 255 177 255 177 219 94 219 94 219 177 255 177 255 177 255 255 255 255 177 178 219 126 219 178 177 255 255 255 255 255 255 255 255 255 177 178 219 178 177 255 255 255 255 255 255 255 255 255 255 255 177 177 177 255 255 255 255 255 255 255 255 255 255 177 255 255 255 255 255 177 255 255 255 255 255 255 255 177 255 255 255 177 255 255 255 177 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 177 255 255 255 255 255 255 255 0 0 0 0 0 0 0 62 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 62 0 0 0 62 0 0 0 62 0 0 0 0 0 0 0 62 0 0 0 0 0 62 0 0 0 0 0 0 0 0 0 0 62 62 62 0 0 0 0 0 0 0 0 0 0 0 62 62 14 62 62 0 0 0 0 0 0 0 0 0 62 62 14 14 14 62 62 0 0 0 0 62 0 62 0 62 14 224 14 224 14 62 0 62 0 62 0 0 0 0 62 62 14 224 14 62 62 0 0 0 0 0 0 0 0 0 62 62 14 62 62 0 0 0 0 0 0 0 0 0 0 0 62 62 62 0 0 0 0 0 0 0 0 0 0 62 0 0 0 0 0 62 0 0 0 0 0 0 0 62 0 0 0 62 0 0 0 62 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 62 0 0 0 0 0 0 0
can point out i'm doing wrong? 2 constructors don't different me...
edit: forgot mention, char , col both defines unsigned char.
Comments
Post a Comment