static SCENEGRAPH* loadIDFOutline( const wxString& aFileName ) { LOCALESWITCH switcher; IDF3_BOARD brd( IDF3::CAD_ELEC ); IDF3_COMP_OUTLINE* outline = NULL; outline = brd.GetComponentOutline( aFileName ); if( NULL == outline ) { #ifdef DEBUG do { std::ostringstream ostr; std::cerr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n"; std::cerr << " * [INFO] Failed to read IDF data:\n"; std::cerr << brd.GetError() << "\n\n"; std::cerr << " * [INFO] no outline for file '"; std::cerr << aFileName << "'"; wxLogTrace( MASK_IDF, "%s\n", ostr.str().c_str() ); } while( 0 ); #endif return NULL; } SCENEGRAPH* data = addOutline( outline, -1, NULL ); return data; }
void Game::drawMatchAnimation( const std::vector<int>& positions ) { // Create a copy of the board for animation std::vector<int> brd(m_board->getBoard()); for (size_t i = 0; i < positions.size(); ++i) { brd[positions[i]] = 0; } int w, h, x, y; m_grid->getTileSize(w, h); float fw = (float)w; float fh = (float)h; float sizeShift = 0; while (fw > 0.1f) { m_timer->update(); sizeShift = 0.2f * m_timer->getFrameTime(); fw -= sizeShift; fh -= sizeShift; m_renderer->beginRender(); drawBoard(brd); drawScoreAndTime(); for (size_t i = 0; i < positions.size(); ++i) { m_grid->getTileCoords(positions[i], x, y); x += (w - (int)fw) / 2; y += (h - (int)fh) / 2; m_renderer->renderJewel(m_board->getBoard()[positions[i]], x, y, (int)fw, (int)fh); } m_renderer->endRender(); } }
static SCENEGRAPH* loadIDFBoard( const wxString& aFileName ) { LOCALESWITCH switcher; IDF3_BOARD brd( IDF3::CAD_ELEC ); // note: if the IDF model is defective no outline substitutes shall be made if( !brd.ReadFile( aFileName, true ) ) { #ifdef DEBUG do { std::ostringstream ostr; std::cerr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n"; std::cerr << " * [INFO] Failed to read IDF file:\n"; std::cerr << brd.GetError() << "\n\n"; std::cerr << " * [INFO] IDF file '" << aFileName.ToUTF8() << "'"; wxLogTrace( MASK_IDF, "%s\n", ostr.str().c_str() ); } while( 0 ); #endif return NULL; } IFSG_TRANSFORM tx0( true ); SGNODE* topNode = tx0.GetRawPtr(); bool noBoard = false; bool noComp = false; bool noOther = false; if( NULL == makeBoard( brd, topNode ) ) noBoard = true; if( !makeComponents( brd, topNode ) ) noComp = true; if( !makeOtherOutlines( brd, topNode ) ) noOther = true; if( noBoard && noComp && noOther ) { tx0.Destroy(); return NULL; } return (SCENEGRAPH*) topNode; }
void Game::drawSwapAnimation( int pos1, int pos2 ) { int x1, x2, y1, y2, w, h; m_grid->getTileSize(w, h); m_grid->getTileCoords(pos2, x1, y1); m_grid->getTileCoords(pos1, x2, y2); // Create a copy of the board for animation std::vector<int> brd(m_board->getBoard()); brd[pos1] = 0; brd[pos2] = 0; bool vertSwap = (x1 == x2); float distance = vertSwap ? (float)std::abs(y1 - y2) : (float)std::abs(x1 - x2); int direction = 0; if (vertSwap) { direction = (y2 > y1) ? 1 : -1; } else { direction = (x2 > x1) ? 1 : -1; } float fx1, fx2, fy1, fy2; fx1 = (float) x1; fx2 = (float) x2; fy1 = (float) y1; fy2 = (float) y2; float movement = 0; while(distance > 0) { m_timer->update(); m_renderer->beginRender(); drawBoard(brd); drawScoreAndTime(); movement = 0.2f * m_timer->getFrameTime(); distance -= movement; if (vertSwap) { fy1 += movement * direction; fy2 -= movement * direction; } else { fx1 += movement * direction; fx2 -= movement * direction; } m_renderer->renderJewel(m_board->getBoard()[pos1], (int)fx1, (int)fy1, w, h); m_renderer->renderJewel(m_board->getBoard()[pos2], (int)fx2, (int)fy2, w, h); m_renderer->endRender(); } }
int load_clip(char *filename, image *aPic) { unsigned char buf[32]; unsigned char cmap[256*3]; int hascmap; int i, j, r, c, maxc=0; int width, height, bpp; unsigned char* img; unsigned char* p; FILE *file; curlen = 0; if (!(file = fopen(filename, "r"))) return PICERR_CANTOPEN; if (!rd(file, buf, 17)) return PICERR_BADFORMAT; if (buf[15] != 0) if (!rd(file, buf + 17, 2)) return PICERR_BADFORMAT; if (buf[0] != 0x34 || buf[1] != 0x12) return PICERR_BADFORMAT; if (buf[12] != 'L' && buf[12] != 'C') fprintf(stderr, "I may not do the right thing...\n"); hascmap = buf[13] & 4; width = buf[2] + buf[3] * 256; height = buf[4] + buf[5] * 256; bpp = buf[10]; /* I'm not real sure about the bits-per-pixel, above */ /* allocation equation depends on 8 | width (| = divides) */ if (!(img = malloc(bytesleft = width * height * bpp / 8))) return PICERR_CANTALLOC; p = img; if (hascmap) { if (!rd(file, cmap, 256 * 3)) return PICERR_BADFORMAT; for (i = 0; i < 256 * 3; i++) cmap[i] *= 4; } if (!rd(file, buf, 2)) return PICERR_BADFORMAT; blocksleft = buf[0] + buf[1] * 256; while (brd(file, buf, 1)) { c = buf[0]; if (c == spec) { brd(file, buf, 1); r = buf[0]; if (r == 0) { brd(file, buf, 3); r = buf[1] * 256 + buf[0]; c = buf[2]; } else { brd(file, buf, 1); c = buf[0]; } } else { r = 1; } while (r-- > 0) { if (--bytesleft < 0) { fprintf(stderr, "file too long, ignoring extra\n"); goto dump; } *p++ = c; } if (c>maxc) maxc=c; if (bytesleft == 0) break; } if (!hascmap) { for (i = 0; i < 255 * 3; i++) cmap[i] = (255.0/maxc)*(i/3); } dump: for (i = 0; i < height / 2; i++) for (j = 0; j < width; j++) { c = img[i * width + j]; img[i * width + j] = img[((height - 1) - i) * width + j]; img[((height - 1) - i) * width + j] = c; } if (bpp == 8) { constructImage(aPic, COLORMASK | PALETTEMASK, PLANAR, width, height, bpp, img, cmap); } else { constructImage(aPic, COLORMASK, PLANAR, width, height, bpp, img, NULL); } free(img); return PICERR_NOERR; }