private void PrepLayer(List <PrototypeComponents.IP_RenderComponent> bucket, ref bool dflag) { if (dflag) { SortList(bucket); dflag = false; } for (int i = 0; i < bucket.Count; i++) { if (!bucket[i].Visable) { continue; } // imagine four pixels on the edge of a cliff. rendering works the same way. //V = Viewscreen, aka the console proper. int startX = _ViewOffsetX + bucket[i].RelXCoords; //startfoo is xy of topleft of rendered object, //relative to the viewscreen's topleft spot. int startY = _ViewOffsetY + bucket[i].RelYCoords; //viewoffset is a transform. RelY is modified by object's parent's offset if (startX > _ViewSizeX || (startX + bucket[i].SizeX) < 0) { continue; //sanity check. if object is left of V's right boundry, or too far to the left to appear, its gone. } if (startY > _ViewSizeY || (startY + bucket[i].SizeY) < 0) { continue; //similar to above } int vindexX = 0; //start point for rendering onto the console int vindexY = 0; //xy coords int vLimitX = _ViewSizeX; //point where rendering really ought to stop int vLimitY = _ViewSizeY; //otherwise it starts looping text into dumb places if (startY > 0) { vindexY = startY; } //if the object is to be drawn lower on the screen, then start lower if (startX > 0) { vindexX = startX; } //if the object is drawn rightmore on the view, start more right int bucketgiX = 0; //bucket Graphic Index int bucketgiY = 0; if (startX < 0) { bucketgiX = startX * -1; } if (startY < 0) { bucketgiY = startY * -1; } if (vLimitX > bucket[i].SizeX + startX) { vLimitX = bucket[i].SizeX + startX; } //if the viewscreen is wider than the object, stop sooner if (vLimitY > bucket[i].SizeY + startY) { vLimitY = bucket[i].SizeY + startY; } //could be done differently but eh for (int y = vindexY; y < vLimitY; y++) { int bucketgi = bucketgiX + bucketgiY * bucket[i].SizeX; _MyBuffer.bufferwrite = y * _ViewSizeX + vindexX; // buffer is stored as a single value, index derived from X+Y*Width. for (int x = vindexX; x < vLimitX; x++) { if (bucket[i].Graphic[bucketgi] == P_Const.NULL_CHAR) { _MyBuffer.BufferWrite(' ', P_Const.DefaultBColor, P_Const.DefaultFColor); bucketgi++; continue; } _MyBuffer.BufferProtectedWrite(bucket[i].Graphic[bucketgi], bucket[i].BackgroundColor, bucket[i].ForegroundColor); bucketgi++; } bucketgiY++; } } }