using Drawing = System.Drawing;
using Collections = System.Collections.Generic;
using DirectX = Microsoft.DirectX;
using Direct3D = Microsoft.DirectX.Direct3D;
public class Scene
private class Batch
IndexList = new Collections.List ();
public int MinimumIndex = int.MaxValue;
public int Offset = 0;
public int Vertices = 0;
public void Initialize()
int MaximimIndex = int.MinValue;
for( int i = 0; i < IndexList.Count; i++ )
if( IndexList < MinimumIndex )
MinimumIndex = (int)IndexList;
if( IndexList > MaximimIndex )
MaximimIndex = (int)IndexList;
Vertices = ( MaximimIndex - MinimumIndex ) + 1;
public class Object
public int BufferOffset = 0;
public Graphic Graphic = null;
public uint IndexArray = null;
public Direct3D.CustomVertex.PositionTextured VertexArray = null;
public Object( Graphic GraphicReference )
Graphic = GraphicReference;
private Direct3D.IndexBuffer IndexBuffer = null;
BatchList = new Collections.Dictionary
public static DirectX.GraphicsStream GraphicsStream = null;
> ObjectList = new Collections.Dictionary
private static Collections.List
VertexList = new Collections.List ();
private static Direct3D.VertexBuffer VertexBuffer = null;
public void Add( Object ObjectReference )
if( ObjectReference == null )
else if( ( ObjectReference.Graphic == null ) || ( ObjectReference.VertexArray == null ) || ( ObjectReference.VertexArray.Length == 0 ) || ( ObjectReference.IndexArray == null ) || ( ObjectReference.IndexArray.Length == 0 ) )
else if( ObjectList.ContainsKey( ObjectReference.Graphic ) == false )
ObjectList.Add( ObjectReference.Graphic, new Collections.List
Object - This is inherited by anything that has to be added to a
scene, which is walls and floor/ceiling polygons.
BufferOffset - This is where it's vertices got added to the
VertexBuffer, used so moving sectors can be
Graphic - The texture or animation used for is object, for
IndexArray - Indices into the VertexBuffer. Each object only
needs to start as though it was from 0, the scene
builder will find and assign the actually indices
when built. These need to be in order though for
batching to work(you can't have 0,2,3,5).
VertexArray - The vertices.
Batch - This is used to store the information needed for the call to
DrawIndexedPrimitives. There is one batch for evey different
texture in a scene.
IndexList - Contains all the indices used for this batch. Used
to find the other values.
MinimumIndex - The lowest index out of all the indices that make
up this batch, for MinIndex.
Offset - The value used for BaseVertexIndex, takes the number of
vertics in the level at the start of being "built".
Vertices - The number of different vertices, for NumVertices;
Scene - The actual scene class. Inherited by each sector, but also
stores the vertex data for the whole level.
IndexBuffer - The index buffer for this sector.
MinimumIndex - List of batches, one batch per texture in the
GraphicsStream - Walls use this to add their new vertices to the
VertexBuffer when being rebuilt.
ObjectList - List of objects(walls,polygons) arranged by
VertexList - Stores the vertices before building the
VertexBuffer - Vertex buffer for the whole level.
Add - Adds an object to ObjectList if it's not in there already.
Also adds a batch based on the objects texture if one
doesn't already exist.
Build - This starts off by going through all the different
textures in the sector. The batch for that texture has
it's offset assigned to the length of VertexIndex(if the
fisrt batch of objects contains 100 vertices, then this
becomes 100 for the second batch). Then there's a loop
that goes through all the objects that have this
texture. The object's have their indices and offset into
the vertex buffer set to the proper values. Then the
object's have their vertices added to VertexList and
their indices added into the current batch.
Next after all that is done and the batches have all
their indices, a loop adds those indices to the index
buffer. Now the index buffer is arranged by texture.
BuildBuffer - This is the last functioned called before doing
any rendering, it loads all the vertices from
VertexList into VertexBuffer.
Render - Goes through all the batches in this scene, setting the
right texture and rendering based on the indices.
Putting it all together:
1. When loading a level, the sectors are loaded first, although at this
time they don't contain much information(only that of the WAD).
2. When loading the lines each checks what sector it belongs in(based on
which side falls into "the void"). The line and it's
walls(lower,middle,upper) are then added to that sector(Scene.Add).
3. Once the level has all the data from the Doom WAD file, it loops
through all the sectors calling Build.
4. After all the sectors are "built", Scene.BuildBuffer is called
That's it for now. Hopefully someone will find it somewhat usefull, it sure took a long time to write. I have tested it with some moving sectors and all the values do come out to be the right value.