Finds the shell for the specified room. If the shell is found with no errors, sets the non-shell flag for those faces not in the shell. If there are errors finding the shell, all faces have the non-shell flag cleared. Assumes all portals are part of the shell and starts checking from those faces Returns the number of shell errors (unconnected edges) in the room. Writes errors to the error buffer
| 3062 | // Returns the number of shell errors (unconnected edges) in the room. |
| 3063 | // Writes errors to the error buffer |
| 3064 | int ComputeRoomShell(room *rp) { |
| 3065 | uint8_t shell_flags[MAX_FACES_PER_ROOM]; |
| 3066 | bool done = 0; |
| 3067 | int errors = 0; |
| 3068 | int f; |
| 3069 | |
| 3070 | for (f = 0; f < rp->num_faces; f++) |
| 3071 | shell_flags[f] = SHELL_NONE; |
| 3072 | |
| 3073 | // Start with the portal faces |
| 3074 | ASSERT(rp->num_portals > 0); |
| 3075 | for (int p = 0; p < rp->num_portals; p++) |
| 3076 | shell_flags[rp->portals[p].portal_face] = SHELL_UNCHECKED; |
| 3077 | |
| 3078 | // Check all the unchecked faces |
| 3079 | while (!done) { |
| 3080 | |
| 3081 | for (f = 0; f < rp->num_faces; f++) { |
| 3082 | |
| 3083 | if (shell_flags[f] == SHELL_UNCHECKED) { |
| 3084 | face *fp = &rp->faces[f]; |
| 3085 | |
| 3086 | for (int e = 0; e < fp->num_verts; e++) { |
| 3087 | |
| 3088 | int t = FindConnectedFace(rp, f, e, 0); |
| 3089 | |
| 3090 | if (t != -1) { |
| 3091 | int t2; |
| 3092 | |
| 3093 | // See if any additional faces |
| 3094 | t2 = FindConnectedFace(rp, f, e, t + 1); |
| 3095 | if (t2 != -1) { |
| 3096 | // mprintf(0,"Room %d face %d: Found second connection for edge %d (face %d)\n",ROOMNUM(rp),f,e,t); |
| 3097 | // CheckError("Room %d face %d: Found second connection for edge %d (face %d)\n",ROOMNUM(rp),f,e,t); |
| 3098 | } else { // No double-edge, so add connected face |
| 3099 | |
| 3100 | if (shell_flags[t] == SHELL_NONE) |
| 3101 | shell_flags[t] = SHELL_UNCHECKED; |
| 3102 | } |
| 3103 | } else { |
| 3104 | // mprintf(0,"Room %d face %d: No connection for edge %d\n",ROOMNUM(rp),f,e); |
| 3105 | CheckError("Room %d face %d: No connection for edge %d\n", ROOMNUM(rp), f, e); |
| 3106 | shell_flags[f] = SHELL_ERROR; |
| 3107 | errors++; |
| 3108 | } |
| 3109 | } |
| 3110 | |
| 3111 | if (shell_flags[f] == SHELL_UNCHECKED) |
| 3112 | shell_flags[f] = SHELL_CLOSED; |
| 3113 | |
| 3114 | break; |
| 3115 | } |
| 3116 | } |
| 3117 | |
| 3118 | done = (f == rp->num_faces); |
| 3119 | } |
| 3120 | |
| 3121 | // Clear flags |
no test coverage detected