public void loadObjects() { ByteArrayInputStream eObjIndexFile = new ByteArrayInputStream(ObjIndexFile.getContents()); ByteArrayInputStream eObjFile = new ByteArrayInputStream(ObjFile.getContents()); Objects = new ObjectDef[objectCount]; //read object index int obj = 0; while (eObjIndexFile.lengthAvailable(4) && obj < Objects.Length) { Objects[obj] = new ObjectDef(this); int offset = eObjIndexFile.readUShort(); Objects[obj].width = eObjIndexFile.readByte(); Objects[obj].height = eObjIndexFile.readByte(); eObjFile.seek(offset); Objects[obj].load(eObjFile); obj++; } }
private List <ObjectDefTile[, ]> getSlopeSections(ObjectDef d) { List <ObjectDefTile[, ]> sections = new List <ObjectDefTile[, ]>(); List <List <ObjectDefTile> > currentSection = null; foreach (List <ObjectDefTile> row in d.tiles) { if (row.Count > 0 && row[0].slopeControl) // begin new section { if (currentSection != null) { sections.Add(createSection(currentSection)); } currentSection = new List <List <ObjectDefTile> >(); } currentSection.Add(row); } if (currentSection != null) //end last section { sections.Add(createSection(currentSection)); } return(sections); }
private void RenderDiagonalObject(int[,] Dest, ObjectDef obj, int width, int height) { //empty tiles fill for (int xp = 0; xp < width; xp++) { for (int yp = 0; yp < height; yp++) { Dest[xp, yp] = -2; } } //get sections List <ObjectDefTile[, ]> sections = getSlopeSections(obj); ObjectDefTile[,] mainBlock = sections[0]; ObjectDefTile[,] subBlock = null; if (sections.Count > 1) { subBlock = sections[1]; } byte controlByte = obj.tiles[0][0].controlByte; //get direction bool goLeft = (controlByte & 1) != 0; bool goDown = (controlByte & 2) != 0; //get starting point int x = 0; int y = 0; if (!goDown) { y = height - mainBlock.GetLength(1); } if (goLeft) { x = width - mainBlock.GetLength(0); } //get increments int xi = mainBlock.GetLength(0); if (goLeft) { xi = -xi; } int yi = mainBlock.GetLength(1); if (!goDown) { yi = -yi; } //this is a strange stop condition. //Put tells if we have put a tile in the destination //When we don't put any tile in destination we are completely //out of bounds, so stop. bool put = true; while (put) { put = false; putArray(Dest, x, y, mainBlock, width, height, ref put); if (subBlock != null) { int xb = x; if (goLeft) // right align { xb = x + mainBlock.GetLength(0) - subBlock.GetLength(0); } if (goDown) { putArray(Dest, xb, y - subBlock.GetLength(1), subBlock, width, height, ref put); } else { putArray(Dest, xb, y + mainBlock.GetLength(1), subBlock, width, height, ref put); } } x += xi; y += yi; } }
public int[,] RenderObject(int ObjNum, int Width, int Height) { // First allocate an array int[,] Dest = new int[Width, Height]; // Non-existent objects can just be made out of 0s if (ObjNum >= Objects.Length || ObjNum < 0 || Objects[ObjNum] == null) { return(Dest); } ObjectDef obj = Objects[ObjNum]; if (Objects[ObjNum].tiles.Count == 0) { throw new ObjectRenderingException("Objects can't be empty."); } for (int i = 0; i < Objects[ObjNum].tiles.Count; i++) { if (Objects[ObjNum].tiles[i].Count == 0) { throw new ObjectRenderingException("Objects can't have empty rows."); } } // Diagonal objects are rendered differently if ((Objects[ObjNum].tiles[0][0].controlByte & 0x80) != 0) { RenderDiagonalObject(Dest, obj, Width, Height); } else { bool repeatFound = false; List <List <ObjectDefTile> > beforeRepeat = new List <List <ObjectDefTile> >(); List <List <ObjectDefTile> > inRepeat = new List <List <ObjectDefTile> >(); List <List <ObjectDefTile> > afterRepeat = new List <List <ObjectDefTile> >(); foreach (List <ObjectDefTile> row in obj.tiles) { if (row.Count == 0) { continue; } if ((row[0].controlByte & 2) != 0) { repeatFound = true; inRepeat.Add(row); } else { if (repeatFound) { afterRepeat.Add(row); } else { beforeRepeat.Add(row); } } } for (int y = 0; y < Height; y++) { if (inRepeat.Count == 0) //if no repeat data, just repeat all { renderStandardRow(Dest, beforeRepeat[y % beforeRepeat.Count], y, Width); } else if (y < beforeRepeat.Count) //if repeat data { renderStandardRow(Dest, beforeRepeat[y], y, Width); } else if (y > Height - afterRepeat.Count - 1) { renderStandardRow(Dest, afterRepeat[y - Height + afterRepeat.Count], y, Width); } else { renderStandardRow(Dest, inRepeat[(y - beforeRepeat.Count) % inRepeat.Count], y, Width); } } } return(Dest); }
private void RenderDiagonalObject(int[,] Dest, ObjectDef obj, int width, int height) { //empty tiles fill for (int xp = 0; xp < width; xp++) for (int yp = 0; yp < height; yp++) Dest[xp, yp] = -1; //get sections List<ObjectDefTile[,]> sections = getSlopeSections(obj); ObjectDefTile[,] mainBlock = sections[0]; ObjectDefTile[,] subBlock = null; if (sections.Count > 1) subBlock = sections[1]; byte controlByte = obj.tiles[0][0].controlByte; //get direction bool goLeft = (controlByte & 1) != 0; bool goDown = (controlByte & 2) != 0; //get starting point int x = 0; int y = 0; if (!goDown) y = height - mainBlock.GetLength(1); if (goLeft) x = width - mainBlock.GetLength(0); //get increments int xi = mainBlock.GetLength(0); if (goLeft) xi = -xi; int yi = mainBlock.GetLength(1); if (!goDown) yi = -yi; //this is a strange stop condition. //Put tells if we have put a tile in the destination //When we don't put any tile in destination we are completely //out of bounds, so stop. bool put = true; while (put) { put = false; putArray(Dest, x, y, mainBlock, width, height, ref put); if (subBlock != null) { int xb = x; if (goLeft) // right align xb = x + mainBlock.GetLength(0) - subBlock.GetLength(0); if(goDown) putArray(Dest, xb, y - subBlock.GetLength(1), subBlock, width, height, ref put); else putArray(Dest, xb, y + mainBlock.GetLength(1), subBlock, width, height, ref put); } x += xi; y += yi; } }
private List<ObjectDefTile[, ]> getSlopeSections(ObjectDef d) { List<ObjectDefTile[,]> sections = new List<ObjectDefTile[,]>(); List<List<ObjectDefTile>> currentSection = null; foreach (List<ObjectDefTile> row in d.tiles) { if (row.Count > 0 && row[0].slopeControl) // begin new section { if (currentSection != null) sections.Add(createSection(currentSection)); currentSection = new List<List<ObjectDefTile>>(); } currentSection.Add(row); } if (currentSection != null) //end last section sections.Add(createSection(currentSection)); return sections; }