========================================================================== Sets or clears a flag, taking field width into account. ==========================================================================
| 78 | // |
| 79 | //========================================================================== |
| 80 | void ModActorFlag(DCoreActor *actor, FFlagDef *fd, bool set) |
| 81 | { |
| 82 | // if it's a CSTAT flag, mark it as protected so that map spawned actors do not override it. |
| 83 | if (fd->varflags & VARF_Protected) |
| 84 | { |
| 85 | static_cast<PClassActor*>(actor->GetClass())->ActorInfo()->DefaultCstat |= fd->flagbit; |
| 86 | } |
| 87 | // Little-Endian machines only need one case, because all field sizes |
| 88 | // start at the same address. (Unless the machine has unaligned access |
| 89 | // exceptions, in which case you'll need multiple cases for it too.) |
| 90 | #ifdef __BIG_ENDIAN__ |
| 91 | if (fd->fieldsize == 4) |
| 92 | #endif |
| 93 | { |
| 94 | uint32_t *flagvar = (uint32_t *)((char *)actor + fd->structoffset); |
| 95 | if (set) |
| 96 | { |
| 97 | *flagvar |= fd->flagbit; |
| 98 | } |
| 99 | else |
| 100 | { |
| 101 | *flagvar &= ~fd->flagbit; |
| 102 | } |
| 103 | } |
| 104 | #ifdef __BIG_ENDIAN__ |
| 105 | else if (fd->fieldsize == 2) |
| 106 | { |
| 107 | uint16_t *flagvar = (uint16_t *)((char *)actor + fd->structoffset); |
| 108 | if (set) |
| 109 | { |
| 110 | *flagvar |= fd->flagbit; |
| 111 | } |
| 112 | else |
| 113 | { |
| 114 | *flagvar &= ~fd->flagbit; |
| 115 | } |
| 116 | } |
| 117 | else |
| 118 | { |
| 119 | assert(fd->fieldsize == 1); |
| 120 | uint8_t *flagvar = (uint8_t *)((char *)actor + fd->structoffset); |
| 121 | if (set) |
| 122 | { |
| 123 | *flagvar |= fd->flagbit; |
| 124 | } |
| 125 | else |
| 126 | { |
| 127 | *flagvar &= ~fd->flagbit; |
| 128 | } |
| 129 | } |
| 130 | #endif |
| 131 | } |
| 132 | |
| 133 | //========================================================================== |
| 134 | // |
no test coverage detected