bool Texture2DArray::EndLoad() { // In headless mode, do not actually load the texture, just return success if (!graphics_ || graphics_->IsDeviceLost()) return true; // If over the texture budget, see if materials can be freed to allow textures to be freed CheckTextureBudget(GetTypeStatic()); SetParameters(loadParameters_); SetLayers(loadImages_.size()); for (unsigned i = 0; i < loadImages_.size(); ++i) SetData(i, loadImages_[i]); loadImages_.clear(); loadParameters_.Reset(); return true; }
/*Returns the cyphered byte. CypherChar is the per-character cryptor. It uses the current state of the randoms to encrypt/decrypt the character. It does not alter the state of the randoms (with e.g. Next4Rands(), etc). k is the byte to use, 0-3 There are several cypher methods to choose from, the choice made through the global CypherMode. CypherModesMax can be set in randc_defs.h to limit modes available. If desired to use only one method, this can be choosen at compile time by setting CypherMode in initRandVars. Operation: The function begins by creating a sequence which will be used to select the layers to use. Then the NumLayers var is set which is the number of layers to use. The layers are selected and the cipher number calculated using the selected mothod. Then the char is encrypted using either modulo arithmetic, or XOR, as determined in InitRandVars. */ uint8_t CryptChar(uint8_t ch, uint8_t k) { int j, zerohit; uint8_t c; //Num that will be XORed with ch. uint8_t sequence[LayersMax]; //A layer sequence uint8_t ModCrypt; //Use Modulo arithmetic or XOR? GenerateLayerSequence(sequence, k, SeqMixLoops); SetLayers(&LayersPickingLayer, k, sequence); zerohit = 0; c = LayerRandByte(sequence[0], k); //Get 1st c //The following calculates the encryption number using the CypherMode //currently active to convert a series of numbers into a single byte. //Each most likey produces a different resulting byte which will be used //for the char encryption. //All modes: layers derived from sequence[]. //With CypherModesMax=1 only the 1st two will be used. The others are here //for illustration as to possibilities. switch (CypherMode) { case 0: //adding: add up all numbers, the overflow being lost. for (j=1; j<NumLayers; j++) c = c + LayerRandByte(sequence[j], k); break; case 1: //XOR: XOR all numbers together for (j=1; j<NumLayers; j++) //xor char with rand from each layer c = c ^ LayerRandByte(sequence[j], k); break; case 2: //adding, twiddle every other one (~ is bitwise complement) for (j=1; j<NumLayers; j++) if ((j & 1) == 0) c = c + LayerRandByte(sequence[j], k); else c = c + ~LayerRandByte(sequence[j], k); break; case 3: for (j=1; j<NumLayers; j++) c = c + (255-LayerRandByte(sequence[j], k)); break; case 4: break; //In the simplest case, just use the single layer's byte. //To enable this method set CypherModeMax to at least 4. //Currently disabled. default:printf("Cyphermode %u was called for.\n", CypherMode); AbortProg("Fatal error. There is no such CypherMode", ex_progerr); } //switch //If c is zero then ch remains unchanged. //Instead, find 2 layers who's sum is non-zero and use the sum. if (c == 0) { ZeroCorrects++; //Keep count. zerohit = 1; //So we can pass the hit on to debug below. j = 0; while ((c == 0) && (j < LayersMax)) { //make sure we don't enter an endless loop c = LayerRandByte(sequence[j], k) + LayerRandByte(sequence[(j+1)%LayersMax], k); j++; } //while if (c == 0) AbortProg("ERROR: A zero slipped through. Unable to find non-zero replacement.", ex_progerr); } //if c==0 if (Debug == dg_Sequ || Debug == dg_Sequ2 || Debug == dg_RandsUsed) DebugSequencing2File(SeqDebugF, sequence, Debug, k, zerohit, c); //How to apply c to the character? if (UseModuloCrypt == 255) //If 255 then select method now ModCrypt = LayerRandByte(sequence[LayersMax-1], k); else ModCrypt = UseModuloCrypt; //Else use method as selected in InitRandVars. if ((ModCrypt &1) == 0) { //if even ch = ch ^ c; //XOR the character } else { //else odd, use modulo if (operation == op_encrypt) ch = ch + c; //If encrypting, add to ch else ch = ch -c; //If decrypting, subtract from ch } if (Debug == dg_Sequ2) for (j=1; j<NumLayers; j++) { //Find the highest and lowest layer used if(sequence[j] < DebugLayLow) DebugLayLow = sequence[j]; if(sequence[j] > DebugLayHi) DebugLayHi = sequence[j]; } //for return ch; } //CryptChar()