| 131 | }; |
| 132 | |
| 133 | void CLevel::Load_GameSpecific_CFORM(CDB::TRI* tris, const size_t count) |
| 134 | { |
| 135 | typedef xr_vector<translation_pair> ID_INDEX_PAIRS; |
| 136 | ID_INDEX_PAIRS translator; |
| 137 | translator.reserve(GMLib.CountMaterial()); |
| 138 | u16 default_id = (u16)GMLib.GetMaterialIdx("default"); |
| 139 | translator.push_back(translation_pair(u32(-1), default_id)); |
| 140 | |
| 141 | u16 index = 0, static_mtl_count = 1; |
| 142 | int max_ID = 0; |
| 143 | int max_static_ID = 0; |
| 144 | for (GameMtlIt I = GMLib.FirstMaterial(); GMLib.LastMaterial() != I; ++I, ++index) |
| 145 | { |
| 146 | if (!(*I)->Flags.test(SGameMtl::flDynamic)) |
| 147 | { |
| 148 | ++static_mtl_count; |
| 149 | translator.emplace_back((*I)->GetID(), index); |
| 150 | if ((*I)->GetID() > max_static_ID) |
| 151 | max_static_ID = (*I)->GetID(); |
| 152 | } |
| 153 | if ((*I)->GetID() > max_ID) |
| 154 | max_ID = (*I)->GetID(); |
| 155 | } |
| 156 | // Msg("* Material remapping ID: [Max:%d, StaticMax:%d]",max_ID,max_static_ID); |
| 157 | VERIFY(max_static_ID < 0xFFFF); |
| 158 | |
| 159 | if (static_mtl_count < 128) |
| 160 | { |
| 161 | CDB::TRI* I = tris; |
| 162 | CDB::TRI* E = tris + count; |
| 163 | for (; I != E; ++I) |
| 164 | { |
| 165 | ID_INDEX_PAIRS::iterator i = std::find(translator.begin(), translator.end(), (u16)(*I).material); |
| 166 | if (i != translator.end()) |
| 167 | { |
| 168 | (*I).material = (*i).m_index; |
| 169 | SGameMtl* mtl = GMLib.GetMaterialByIdx((*i).m_index); |
| 170 | (*I).suppress_shadows = mtl->Flags.is(SGameMtl::flSuppressShadows); |
| 171 | (*I).suppress_wm = mtl->Flags.is(SGameMtl::flSuppressWallmarks); |
| 172 | continue; |
| 173 | } |
| 174 | |
| 175 | Debug.fatal(DEBUG_INFO, "Game material '%d' not found", (*I).material); |
| 176 | } |
| 177 | return; |
| 178 | } |
| 179 | |
| 180 | std::sort(translator.begin(), translator.end()); |
| 181 | { |
| 182 | CDB::TRI* I = tris; |
| 183 | CDB::TRI* E = tris + count; |
| 184 | for (; I != E; ++I) |
| 185 | { |
| 186 | ID_INDEX_PAIRS::iterator i = std::lower_bound(translator.begin(), translator.end(), (u16)(*I).material); |
| 187 | if ((i != translator.end()) && ((*i).m_id == (*I).material)) |
| 188 | { |
| 189 | (*I).material = (*i).m_index; |
| 190 | SGameMtl* mtl = GMLib.GetMaterialByIdx((*i).m_index); |
no test coverage detected