void cBlockArea::MirrorXZNoMeta(void) { int HalfY = m_Size.y / 2; int MaxY = m_Size.y - 1; if (HasBlockTypes()) { for (int y = 0; y < HalfY; y++) { for (int z = 0; z < m_Size.z; z++) { for (int x = 0; x < m_Size.x; x++) { std::swap(m_BlockTypes[MakeIndex(x, y, z)], m_BlockTypes[MakeIndex(x, MaxY - y, z)]); } // for x } // for z } // for y } // if (HasBlockTypes) if (HasBlockMetas()) { for (int y = 0; y < HalfY; y++) { for (int z = 0; z < m_Size.z; z++) { for (int x = 0; x < m_Size.x; x++) { std::swap(m_BlockMetas[MakeIndex(x, y, z)], m_BlockMetas[MakeIndex(x, MaxY - y, z)]); } // for x } // for z } // for y } // if (HasBlockMetas) }
void cBlockArea::MirrorYZ(void) { if (!HasBlockTypes()) { LOGWARNING("cBlockArea: Cannot mirror meta without blocktypes!"); return; } if (!HasBlockMetas()) { // There are no blockmetas to mirror, just use the NoMeta function MirrorYZNoMeta(); return; } // We are guaranteed that both blocktypes and blockmetas exist; mirror both at the same time: int HalfX = m_SizeX / 2; int MaxX = m_SizeX - 1; for (int y = 0; y < m_SizeY; y++) { for (int z = 0; z < m_SizeZ; z++) { for (int x = 0; x < HalfX; x++) { int Idx1 = MakeIndex(x, y, z); int Idx2 = MakeIndex(MaxX - x, y, z); std::swap(m_BlockTypes[Idx1], m_BlockTypes[Idx2]); NIBBLETYPE Meta1 = BlockHandler(m_BlockTypes[Idx2])->MetaMirrorYZ(m_BlockMetas[Idx1]); NIBBLETYPE Meta2 = BlockHandler(m_BlockTypes[Idx1])->MetaMirrorYZ(m_BlockMetas[Idx2]); m_BlockMetas[Idx1] = Meta2; m_BlockMetas[Idx2] = Meta1; } // for x } // for z } // for y }
void cBlockArea::MirrorYZNoMeta(void) { int HalfX = m_SizeX / 2; int MaxX = m_SizeX - 1; if (HasBlockTypes()) { for (int y = 0; y < m_SizeY; y++) { for (int z = 0; z < m_SizeZ; z++) { for (int x = 0; x < HalfX; x++) { std::swap(m_BlockTypes[MakeIndex(x, y, z)], m_BlockTypes[MakeIndex(MaxX - x, y, z)]); } // for x } // for z } // for y } // if (HasBlockTypes) if (HasBlockMetas()) { for (int y = 0; y < m_SizeY; y++) { for (int z = 0; z < m_SizeZ; z++) { for (int x = 0; x < HalfX; x++) { std::swap(m_BlockMetas[MakeIndex(x, y, z)], m_BlockMetas[MakeIndex(MaxX - x, y, z)]); } // for x } // for z } // for y } // if (HasBlockMetas) }
void cBlockArea::MirrorXYNoMeta(void) { int HalfZ = m_SizeZ / 2; int MaxZ = m_SizeZ - 1; if (HasBlockTypes()) { for (int y = 0; y < m_SizeY; y++) { for (int z = 0; z < HalfZ; z++) { for (int x = 0; x < m_SizeX; x++) { std::swap(m_BlockTypes[MakeIndex(x, y, z)], m_BlockTypes[MakeIndex(x, y, MaxZ - z)]); } // for x } // for z } // for y } // if (HasBlockTypes) if (HasBlockMetas()) { for (int y = 0; y < m_SizeY; y++) { for (int z = 0; z < HalfZ; z++) { for (int x = 0; x < m_SizeX; x++) { std::swap(m_BlockMetas[MakeIndex(x, y, z)], m_BlockMetas[MakeIndex(x, y, MaxZ - z)]); } // for x } // for z } // for y } // if (HasBlockMetas) }
BOOL AsfParser::Initial() { CFile pFile; CString strFile; strFile.Format("%s.meta",filename); if( ! pFile.Open( strFile, CFile::modeRead)) { //不存在 if( !reader.Initial( filename ) ) return FALSE; if( !GetMetaData() ) return FALSE; if( !MakeIndex() ) return FALSE; if( !MakeSDP() ) return FALSE; Save(); } else { //存在 Load( &pFile ); } return TRUE; }
void HalfKP<AssociatedKing>::AppendChangedIndices( const Position& pos, Color perspective, IndexList* removed, IndexList* added) { BonaPiece* pieces; Square sq_target_k; GetPieces(pos, perspective, &pieces, &sq_target_k); const auto& dp = pos.state()->dirtyPiece; for (int i = 0; i < dp.dirty_num; ++i) { if (dp.pieceNo[i] >= PIECE_NUMBER_KING) continue; const auto old_p = static_cast<BonaPiece>( dp.changed_piece[i].old_piece.from[perspective]); removed->push_back(MakeIndex(sq_target_k, old_p)); const auto new_p = static_cast<BonaPiece>( dp.changed_piece[i].new_piece.from[perspective]); added->push_back(MakeIndex(sq_target_k, new_p)); } }
NIBBLETYPE cBlockArea::GetRelNibble(int a_RelX, int a_RelY, int a_RelZ, NIBBLETYPE * a_Array) const { if (a_Array == NULL) { LOGWARNING("cBlockArea: datatype has not been read!"); return 16; } return a_Array[MakeIndex(a_RelX, a_RelY, a_RelZ)]; }
void cBlockArea::SetRelNibble(int a_RelX, int a_RelY, int a_RelZ, NIBBLETYPE a_Value, NIBBLETYPE * a_Array) { if (a_Array == NULL) { LOGWARNING("cBlockArea: datatype has not been read!"); return; } a_Array[MakeIndex(a_RelX, a_RelY, a_RelZ)] = a_Value; }
BLOCKTYPE cBlockArea::GetRelBlockType(int a_RelX, int a_RelY, int a_RelZ) const { if (m_BlockTypes == NULL) { LOGWARNING("cBlockArea: BlockTypes have not been read!"); return E_BLOCK_AIR; } return m_BlockTypes[MakeIndex(a_RelX, a_RelY, a_RelZ)]; }
void cBlockArea::SetRelBlockType(int a_RelX, int a_RelY, int a_RelZ, BLOCKTYPE a_BlockType) { if (m_BlockTypes == NULL) { LOGWARNING("cBlockArea: BlockTypes have not been read!"); return; } m_BlockTypes[MakeIndex(a_RelX, a_RelY, a_RelZ)] = a_BlockType; }
void cBlockArea::FillRelCuboid(int a_MinRelX, int a_MaxRelX, int a_MinRelY, int a_MaxRelY, int a_MinRelZ, int a_MaxRelZ, int a_DataTypes, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta, NIBBLETYPE a_BlockLight, NIBBLETYPE a_BlockSkyLight ) { if ((a_DataTypes & GetDataTypes()) != a_DataTypes) { LOGWARNING("%s: requested datatypes that are not present in the BlockArea object, trimming those away (req 0x%x, stor 0x%x)", __FUNCTION__, a_DataTypes, GetDataTypes() ); a_DataTypes = a_DataTypes & GetDataTypes(); } if ((a_DataTypes & baTypes) != 0) { for (int y = a_MinRelY; y <= a_MaxRelY; y++) for (int z = a_MinRelZ; z <= a_MaxRelZ; z++) for (int x = a_MinRelX; x <= a_MaxRelX; x++) { m_BlockTypes[MakeIndex(x, y, z)] = a_BlockType; } // for x, z, y } if ((a_DataTypes & baMetas) != 0) { for (int y = a_MinRelY; y <= a_MaxRelY; y++) for (int z = a_MinRelZ; z <= a_MaxRelZ; z++) for (int x = a_MinRelX; x <= a_MaxRelX; x++) { m_BlockMetas[MakeIndex(x, y, z)] = a_BlockMeta; } // for x, z, y } if ((a_DataTypes & baLight) != 0) { for (int y = a_MinRelY; y <= a_MaxRelY; y++) for (int z = a_MinRelZ; z <= a_MaxRelZ; z++) for (int x = a_MinRelX; x <= a_MaxRelX; x++) { m_BlockLight[MakeIndex(x, y, z)] = a_BlockLight; } // for x, z, y } if ((a_DataTypes & baSkyLight) != 0) { for (int y = a_MinRelY; y <= a_MaxRelY; y++) for (int z = a_MinRelZ; z <= a_MaxRelZ; z++) for (int x = a_MinRelX; x <= a_MaxRelX; x++) { m_BlockSkyLight[MakeIndex(x, y, z)] = a_BlockSkyLight; } // for x, z, y } }
DFsSection *DFsScript::NewSection(const char *brace) { int n = section_hash(brace); DFsSection *newsec = new DFsSection; newsec->start_index = MakeIndex(brace); newsec->next = sections[n]; sections[n] = newsec; GC::WriteBarrier(this, newsec); return newsec; }
void HalfKP<AssociatedKing>::AppendActiveIndices( const Position& pos, Color perspective, IndexList* active) { // コンパイラの警告を回避するため、配列サイズが小さい場合は何もしない if (RawFeatures::kMaxActiveDimensions < kMaxActiveDimensions) return; BonaPiece* pieces; Square sq_target_k; GetPieces(pos, perspective, &pieces, &sq_target_k); for (PieceNumber i = PIECE_NUMBER_ZERO; i < PIECE_NUMBER_KING; ++i) { active->push_back(MakeIndex(sq_target_k, pieces[i])); } }
void cBlockArea::RotateCWNoMeta(void) { if (HasBlockTypes()) { BLOCKTYPE * NewTypes = new BLOCKTYPE[GetBlockCount()]; for (int z = 0; z < m_Size.z; z++) { int NewX = m_Size.z - z - 1; for (int x = 0; x < m_Size.x; x++) { int NewZ = x; for (int y = 0; y < m_Size.y; y++) { NewTypes[NewX + NewZ * m_Size.z + y * m_Size.x * m_Size.z] = m_BlockTypes[MakeIndex(x, y, z)]; } // for y } // for x } // for z std::swap(m_BlockTypes, NewTypes); delete[] NewTypes; } if (HasBlockMetas()) { NIBBLETYPE * NewMetas = new NIBBLETYPE[GetBlockCount()]; for (int z = 0; z < m_Size.z; z++) { int NewX = m_Size.z - z - 1; for (int x = 0; x < m_Size.x; x++) { int NewZ = x; for (int y = 0; y < m_Size.y; y++) { NewMetas[NewX + NewZ * m_Size.z + y * m_Size.x * m_Size.z] = m_BlockMetas[MakeIndex(x, y, z)]; } // for y } // for x } // for z std::swap(m_BlockMetas, NewMetas); delete[] NewMetas; } std::swap(m_Size.x, m_Size.z); }
void cBlockArea::RotateCWNoMeta(void) { if (HasBlockTypes()) { BLOCKTYPE * NewTypes = new BLOCKTYPE[m_SizeX * m_SizeY * m_SizeZ]; for (int z = 0; z < m_SizeZ; z++) { int NewX = m_SizeZ - z - 1; for (int x = 0; x < m_SizeX; x++) { int NewZ = x; for (int y = 0; y < m_SizeY; y++) { NewTypes[NewX + NewZ * m_SizeX + y * m_SizeX * m_SizeZ] = m_BlockTypes[MakeIndex(x, y, z)]; } // for y } // for x } // for z std::swap(m_BlockTypes, NewTypes); delete[] NewTypes; } if (HasBlockMetas()) { NIBBLETYPE * NewMetas = new NIBBLETYPE[m_SizeX * m_SizeY * m_SizeZ]; for (int z = 0; z < m_SizeZ; z++) { int NewX = m_SizeZ - z - 1; for (int x = 0; x < m_SizeX; x++) { int NewZ = x; for (int y = 0; y < m_SizeY; y++) { NewMetas[NewX + NewZ * m_SizeX + y * m_SizeX * m_SizeZ] = m_BlockMetas[MakeIndex(x, y, z)]; } // for y } // for x } // for z std::swap(m_BlockMetas, NewMetas); delete[] NewMetas; } std::swap(m_SizeX, m_SizeZ); }
void DFsScript::DryRunScript() { char *end = data + len; char *rover = data; // allocate space for the tokens FParser parse(this); try { while(rover < end && *rover) { rover = parse.GetTokens(rover); if(!parse.NumTokens) continue; if(parse.Section && parse.TokenType[0] == function) { if(!strcmp(parse.Tokens[0], "if")) { parse.Section->type = st_if; continue; } else if(!strcmp(parse.Tokens[0], "elseif")) // haleyjd: SoM's else code { parse.Section->type = st_elseif; continue; } else if(!strcmp(parse.Tokens[0], "else")) { parse.Section->type = st_else; continue; } else if(!strcmp(parse.Tokens[0], "while") || !strcmp(parse.Tokens[0], "for")) { parse.Section->type = st_loop; parse.Section->loop_index = MakeIndex(parse.LineStart); continue; } } } } catch (CFsError err) { parse.ErrorMessage(err.msg); } }
void cBlockArea::CropNibbles(NIBBLEARRAY & a_Array, int a_AddMinX, int a_SubMaxX, int a_AddMinY, int a_SubMaxY, int a_AddMinZ, int a_SubMaxZ) { int NewSizeX = GetSizeX() - a_AddMinX - a_SubMaxX; int NewSizeY = GetSizeY() - a_AddMinY - a_SubMaxY; int NewSizeZ = GetSizeZ() - a_AddMinZ - a_SubMaxZ; NIBBLETYPE * NewNibbles = new NIBBLETYPE[NewSizeX * NewSizeY * NewSizeZ]; int idx = 0; for (int y = 0; y < NewSizeY; y++) { for (int z = 0; z < NewSizeZ; z++) { for (int x = 0; x < NewSizeX; x++) { NewNibbles[idx++] = a_Array[MakeIndex(x + a_AddMinX, y + a_AddMinY, z + a_AddMinZ)]; } // for x } // for z } // for y delete a_Array; a_Array = NewNibbles; }
void cBlockArea::SetRelBlockTypeMeta(int a_RelX, int a_RelY, int a_RelZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta) { int idx = MakeIndex(a_RelX, a_RelY, a_RelZ); if (m_BlockTypes == NULL) { LOGWARNING("%s: BlockTypes not available but requested to be written to.", __FUNCTION__); } else { m_BlockTypes[idx] = a_BlockType; } if (m_BlockMetas == NULL) { LOGWARNING("%s: BlockMetas not available but requested to be written to.", __FUNCTION__); } else { m_BlockMetas[idx] = a_BlockMeta; } }
void cBlockArea::CropBlockTypes(int a_AddMinX, int a_SubMaxX, int a_AddMinY, int a_SubMaxY, int a_AddMinZ, int a_SubMaxZ) { int NewSizeX = GetSizeX() - a_AddMinX - a_SubMaxX; int NewSizeY = GetSizeY() - a_AddMinY - a_SubMaxY; int NewSizeZ = GetSizeZ() - a_AddMinZ - a_SubMaxZ; BLOCKTYPE * NewBlockTypes = new BLOCKTYPE[NewSizeX * NewSizeY * NewSizeZ]; int idx = 0; for (int y = 0; y < NewSizeY; y++) { for (int z = 0; z < NewSizeZ; z++) { for (int x = 0; x < NewSizeX; x++) { int OldIndex = MakeIndex(x + a_AddMinX, y + a_AddMinY, z + a_AddMinZ); NewBlockTypes[idx++] = m_BlockTypes[OldIndex]; } // for x } // for z } // for y delete m_BlockTypes; m_BlockTypes = NewBlockTypes; }
void cBlockArea::RotateCW(void) { if (!HasBlockTypes()) { LOGWARNING("cBlockArea: Cannot rotate blockmeta without blocktypes!"); return; } if (!HasBlockMetas()) { // There are no blockmetas to rotate, just use the NoMeta function RotateCWNoMeta(); return; } // We are guaranteed that both blocktypes and blockmetas exist; rotate both at the same time: BLOCKTYPE * NewTypes = new BLOCKTYPE[m_SizeX * m_SizeY * m_SizeZ]; NIBBLETYPE * NewMetas = new NIBBLETYPE[m_SizeX * m_SizeY * m_SizeZ]; for (int x = 0; x < m_SizeX; x++) { int NewZ = x; for (int z = 0; z < m_SizeZ; z++) { int NewX = m_SizeZ - z - 1; for (int y = 0; y < m_SizeY; y++) { int NewIdx = NewX + NewZ * m_SizeX + y * m_SizeX * m_SizeZ; int OldIdx = MakeIndex(x, y, z); NewTypes[NewIdx] = m_BlockTypes[OldIdx]; NewMetas[NewIdx] = BlockHandler(m_BlockTypes[OldIdx])->MetaRotateCW(m_BlockMetas[OldIdx]); } // for y } // for z } // for x std::swap(m_BlockTypes, NewTypes); std::swap(m_BlockMetas, NewMetas); delete[] NewTypes; delete[] NewMetas; std::swap(m_SizeX, m_SizeZ); }
void cBlockArea::GetRelBlockTypeMeta(int a_RelX, int a_RelY, int a_RelZ, BLOCKTYPE & a_BlockType, NIBBLETYPE & a_BlockMeta) const { int idx = MakeIndex(a_RelX, a_RelY, a_RelZ); if (m_BlockTypes == NULL) { LOGWARNING("cBlockArea: BlockTypes have not been read!"); a_BlockType = E_BLOCK_AIR; } else { a_BlockType = m_BlockTypes[idx]; } if (m_BlockMetas == NULL) { LOGWARNING("cBlockArea: BlockMetas have not been read!"); a_BlockMeta = 0; } else { a_BlockMeta = m_BlockMetas[idx]; } }
void cBlockArea::RelSetData( int a_RelX, int a_RelY, int a_RelZ, int a_DataTypes, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta, NIBBLETYPE a_BlockLight, NIBBLETYPE a_BlockSkyLight ) { int Index = MakeIndex(a_RelX, a_RelY, a_RelZ); if ((a_DataTypes & baTypes) != 0) { m_BlockTypes[Index] = a_BlockType; } if ((a_DataTypes & baMetas) != 0) { m_BlockMetas[Index] = a_BlockMeta; } if ((a_DataTypes & baLight) != 0) { m_BlockLight[Index] = a_BlockLight; } if ((a_DataTypes & baSkyLight) != 0) { m_BlockSkyLight[Index] = a_BlockSkyLight; } }
// To initialize, run MakeIndex() for all of the desired indexing routines, // and then run Initialize(), which will initialize index objects. template<class THashFunc> CAT_INLINE TableIndex *MakeIndex(const char *index_file_path, bool unique) { return MakeIndex(index_file_path, new THashFunc, unique); }
char *DFsScript::ProcessFindChar(char *datap, char find) { while(*datap) { if(*datap==find) return datap; if(*datap=='\"') // found a quote: ignore stuff in it { datap++; while(*datap && *datap != '\"') { // escape sequence ? if(*datap=='\\') datap++; datap++; } // error: end of script in a constant if(!*datap) return NULL; } // comments: blank out if(*datap=='/' && *(datap+1)=='*') // /* -- */ comment { while(*datap && (*datap != '*' || *(datap+1) != '/') ) { *datap=' '; datap++; } if(*datap) *datap = *(datap+1) = ' '; // blank the last bit else { // script terminated in comment script_error("script terminated inside comment\n"); } } if(*datap=='/' && *(datap+1)=='/') // // -- comment { while(*datap != '\n') { *datap=' '; datap++; // blank out } } /********** labels ****************/ // labels are also found during the // preprocessing. these are of the form // // label_name: // // and are used for the goto function. // goto labels are stored as variables. if(*datap==':' && scriptnum != -1) // not in global scripts { char *labelptr = datap-1; while(!isop(*labelptr)) labelptr--; FString labelname(labelptr+1, strcspn(labelptr+1, ":")); if (labelname.Len() == 0) { Printf(PRINT_BOLD,"Script %d: ':' encountrered in incorrect position!\n",scriptnum); } DFsVariable *newlabel = NewVariable(labelname, svt_label); newlabel->value.i = MakeIndex(labelptr); } if(*datap=='{') // { -- } sections: add 'em { DFsSection *newsec = NewSection(datap); newsec->type = st_empty; // find the ending } and save char * theend = ProcessFindChar(datap+1, '}'); if(!theend) { // brace not found // This is fatal because it will cause a crash later // if the game isn't terminated. I_Error("Script %d: section error: no ending brace\n", scriptnum); } newsec->end_index = MakeIndex(theend); // continue from the end of the section datap = theend; } datap++; } return NULL; }