// TODO: Extract inbuilt function handling into separate classes instead of creating massive if/else-monstrosity here // map<std::string(name), FunctionCodeGenerator(inbuild_type)> // can move arithmetic function transformation from semantic analyzer into generator class void CodeGenAstVisitor::Visit(FunctionCallNode *node) { if (node->Name() == FN_IF) { GenerateJumpsForIf(node); } else if (node->Name() == FN_LIST) { CreateList(node); } else if (node->Name() == FN_MAP) { CreateMapping(node); } else if (m_inbuilt_functions.count(node->Name())) { m_function->AddByteCode(ByteCode{ m_inbuilt_functions[node->Name()] }); } else { int id = m_functions[node->Name()].FunctionId(); VMObject o; o.type = VMObjectType::INTEGER; o.value.integer = id; m_function->AddByteCode(ByteCode{ Instruction::PUSH, o }); m_function->AddByteCode(ByteCode{ Instruction::CALLFUNCTION }); } }
//---------------------------------------------------------------------------- bool MapTextureToQuad::OnInitialize () { if (!WindowApplication2::OnInitialize()) { return false; } // The texture whose image will be drawn on the quadrilateral. std::string path = Environment::GetPathR("MagicianSmallReflectY.wmtf"); mTexture = Texture2D::LoadWMTF(path); // The quadrilateral to which the image is perspectively mapped. The // default is the original image rectangle (the initial mapping is the // identity). int dim0 = mTexture->GetDimension(0, 0); int dim1 = mTexture->GetDimension(1, 0); float xmax = dim0 - 1.0f; float ymax = dim1 - 1.0f; mVertex[0] = Vector2f(0.0f, 0.0f); mVertex[1] = Vector2f(xmax, 0.0f); mVertex[2] = Vector2f(xmax, ymax); mVertex[3] = Vector2f(0.0f, ymax); Vector2f offset(0.5f*(GetWidth() - dim0), 0.5f*(GetHeight() - dim1)); for (int i = 0; i < 4; ++i) { mVertex[i] += offset; } CreateMapping(); return true; }
//---------------------------------------------------------------------------- bool MapTextureToQuad::OnInitialize () { if ( !Application2::OnInitialize() ) return false; // source bitmap m_pkImage = Image::Load("butterfly.mif",false); assert( m_pkImage ); if ( !m_pkImage ) return false; // The quadrilateral to which the image is perspectively mapped. The // default is the original image rectangle (the initial mapping is the // identity). m_akVertex[0] = Vector2f(0.0f,0.0f); m_akVertex[1] = Vector2f(m_pkImage->GetWidth()-1.0f,0.0f); m_akVertex[2] = Vector2f(m_pkImage->GetWidth()-1.0f, m_pkImage->GetHeight()-1.0f); m_akVertex[3] = Vector2f(0.0f,m_pkImage->GetHeight()-1.0f); Vector2f kOffset(0.5f*(GetWidth()-m_pkImage->GetWidth()), 0.5f*(GetHeight()-m_pkImage->GetHeight())); for (int i = 0; i < 4; i++) m_akVertex[i] += kOffset; CreateMapping(); return true; }
inline TImpl(const TFile &file, OMode om, const char *dbg_name) : File_(file) , Length_(File_.GetLength()) , Mode_(om) { if (!File_.IsOpen()) { ythrow yexception() << dbg_name << ": FileMap: TFile is not open, " << LastSystemErrorText(); } CreateMapping(dbg_name); }
inline TImpl(const char *name, OMode om) : File_(name, (om & oRdWr) ? OpenExisting | RdWr : OpenExisting | RdOnly) , Length_(File_.GetLength()) , Mode_(om) { if (!File_.IsOpen()) { ythrow yexception() << name << ": FileMap: TFile is not open, " << LastSystemErrorText(); } CreateMapping(name); }
inline TImpl(FILE* f, OMode om, const char *dbg_name) : File_(Duplicate(f)) , Length_(File_.GetLength()) , Mode_(om) { if (!File_.IsOpen()) { ythrow yexception() << dbg_name << ": FileMap: FILE is not open, " << LastSystemErrorText(); } CreateMapping(dbg_name); }
void CreateBlockMapping ( ogg_int32_t (*BlockMap)[4][4], ogg_uint32_t YSuperBlocks, ogg_uint32_t UVSuperBlocks, ogg_uint32_t HFrags, ogg_uint32_t VFrags ) { ogg_uint32_t i, j; for ( i=0; i<YSuperBlocks + UVSuperBlocks * 2; i++ ){ for ( j=0; j<4; j++ ) { BlockMap[i][j][0] = -1; BlockMap[i][j][1] = -1; BlockMap[i][j][2] = -1; BlockMap[i][j][3] = -1; } } CreateMapping ( BlockMap, 0, 0, HFrags, VFrags ); CreateMapping ( BlockMap, YSuperBlocks, HFrags*VFrags, HFrags/2, VFrags/2 ); CreateMapping ( BlockMap, YSuperBlocks + UVSuperBlocks, (HFrags*VFrags*5)/4, HFrags/2, VFrags/2 ); }
/**************************************************************************** * * ROUTINE : CreateBlockMapping * * INPUTS : UINT32 image_width * UINT32 image_height * * OUTPUTS : Mapping table BlockMap[SuperBlock][MacroBlock][Block] * * RETURNS : None. * * FUNCTION : Creates mapping table between (SuperBlock, MacroBlock, Block) * triplet and corresponding Fragment Index. * * SPECIAL NOTES : None. * * * ERRORS : None. * ****************************************************************************/ void CreateBlockMapping ( INT32 (*BlockMap)[4][4], UINT32 YSuperBlocks, UINT32 UVSuperBlocks, UINT32 HFrags, UINT32 VFrags ) { UINT32 i, j; // Loop counters. // Initialise mapping array for ( i=0; i<YSuperBlocks + UVSuperBlocks * 2; i++ ) { for ( j=0; j<4; j++ ) { BlockMap[i][j][0] = -1; BlockMap[i][j][1] = -1; BlockMap[i][j][2] = -1; BlockMap[i][j][3] = -1; } } // Create mappings for each component CreateMapping ( BlockMap, 0, 0, HFrags, VFrags ); CreateMapping ( BlockMap, YSuperBlocks, HFrags*VFrags, HFrags/2, VFrags/2 ); CreateMapping ( BlockMap, YSuperBlocks + UVSuperBlocks, (HFrags*VFrags*5)/4, HFrags/2, VFrags/2 ); }
//---------------------------------------------------------------------------- void MapTextureToQuad::UpdateQuadrilateral (const Vector2f& position) { // Quadrilateral must remain convex. int prev = (mSelected > 0 ? mSelected - 1 : 3); int next = (mSelected < 3 ? mSelected + 1 : 0); Vector2f diff1 = position - mVertex[prev]; Vector2f diff2 = mVertex[next] - position; float det = diff1.X()*diff2.Y() - diff1.Y()*diff2.X(); if (det > 0.0f) { mVertex[mSelected] = position; CreateMapping(); } }
//---------------------------------------------------------------------------- void MapTextureToQuad::UpdateQuadrilateral (const Vector2f& rkPos) { // quadrilateral must remain convex int iPrev = (m_iSelected > 0 ? m_iSelected - 1 : 3); int iNext = (m_iSelected < 3 ? m_iSelected + 1 : 0); Vector2f kDiff1 = rkPos - m_akVertex[iPrev]; Vector2f kDiff2 = m_akVertex[iNext] - rkPos; float fDet = kDiff1.X()*kDiff2.Y() - kDiff1.Y()*kDiff2.X(); if ( fDet > 0.0f ) { m_akVertex[m_iSelected] = rkPos; CreateMapping(); } }