MCPcopy Create free account
hub / github.com/Panzerschrek/Chasm-Reverse / LoadWalls

Method LoadWalls

PanzerChasm/client/map_drawer_gl.cpp:1034–1185  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1032}
1033
1034void MapDrawerGL::LoadWalls( const MapData& map_data )
1035{
1036 std::vector<WallVertex> walls_vertices;
1037 std::vector<unsigned short> walls_indeces;
1038
1039 walls_vertices.reserve( map_data.static_walls.size() * 4u );
1040 walls_indeces.reserve( map_data.static_walls.size() * 6u );
1041
1042 for( const MapData::Wall& wall : map_data.static_walls )
1043 {
1044 if( map_data.walls_textures[ wall.texture_id ].file_path[0] == '\0' )
1045 continue; // Wall has no texture - do not draw it.
1046
1047 const unsigned int first_vertex_index= walls_vertices.size();
1048 walls_vertices.resize( walls_vertices.size() + 4u );
1049 WallVertex* const v= walls_vertices.data() + first_vertex_index;
1050
1051 v[0].xyz[0]= v[2].xyz[0]= static_cast<unsigned short>( wall.vert_pos[0].x * g_walls_coords_scale );
1052 v[0].xyz[1]= v[2].xyz[1]= static_cast<unsigned short>( wall.vert_pos[0].y * g_walls_coords_scale );
1053 v[1].xyz[0]= v[3].xyz[0]= static_cast<unsigned short>( wall.vert_pos[1].x * g_walls_coords_scale );
1054 v[1].xyz[1]= v[3].xyz[1]= static_cast<unsigned short>( wall.vert_pos[1].y * g_walls_coords_scale );
1055
1056 v[0].xyz[2]= v[1].xyz[2]= 0u;
1057 v[2].xyz[2]= v[3].xyz[2]= 2u << 8u;
1058
1059 v[0].texture_id= v[1].texture_id= v[2].texture_id= v[3].texture_id= wall.texture_id;
1060
1061 v[2].tex_coord[0]= v[0].tex_coord[0]= static_cast<short>( wall.vert_tex_coord[0] * 256.0f );
1062 v[1].tex_coord[0]= v[3].tex_coord[0]= static_cast<short>( wall.vert_tex_coord[1] * 256.0f );
1063
1064 v[0].tex_coord[1]= v[1].tex_coord[1]= 0;
1065 v[2].tex_coord[1]= v[3].tex_coord[1]= 256;
1066
1067 map_light_.GetStaticWallLightmapCoord(
1068 &wall - map_data.static_walls.data(),
1069 v[0].lightmap_coord );
1070
1071 v[2].lightmap_coord[0]= v[0].lightmap_coord[0];
1072 v[2].lightmap_coord[1]= v[0].lightmap_coord[1];
1073 v[3].lightmap_coord[0]= v[1].lightmap_coord[0]= v[0].lightmap_coord[0] + 1u;
1074 v[3].lightmap_coord[1]= v[1].lightmap_coord[1]= v[0].lightmap_coord[1];
1075
1076 m_Vec2 wall_vec=
1077 m_Vec2(float(v[0].xyz[0]), float(v[0].xyz[1])) -
1078 m_Vec2(float(v[1].xyz[0]), float(v[1].xyz[1]));
1079 wall_vec.Normalize();
1080
1081 const int normal[2]= {
1082 int( +126.5f * wall_vec.y ),
1083 int( -126.5f * wall_vec.x ) };
1084 for( unsigned int j= 0u; j < 4u; j++ )
1085 {
1086 v[j].normal[0]= normal[0];
1087 v[j].normal[1]= normal[1];
1088 }
1089
1090 const unsigned int first_index= walls_indeces.size();
1091 walls_indeces.resize( walls_indeces.size() + 6u );

Callers

nothing calls this directly

Calls 1

Tested by

no test coverage detected