heh. silly me ![]()
In debug mode:-
SM 2.0 = ~125 FPS;
SM 3.0 = ~85 FPS;
In release mode:-
SM 2.0 = ~131 FPS
SM 3.0 = ~132 FPS
Not Telling
FantasyVII hasn't added any contacts yet.
Posted by FantasyVII
on 13 April 2013 - 12:01 PM
heh. silly me ![]()
In debug mode:-
SM 2.0 = ~125 FPS;
SM 3.0 = ~85 FPS;
In release mode:-
SM 2.0 = ~131 FPS
SM 3.0 = ~132 FPS
Posted by FantasyVII
on 12 April 2013 - 06:41 PM
Hello everyone,
So I been making a pixel shader lighting system in XNA with SM 3.0. I was getting around 70FPS with 4 lights. However when I changed the SM version in the fx file from 3.0 to 2.0, I got around 120FPS !!! Why?
obviously I can't use SM 2.0 because it's very limited with the amount of arithmetic that I can do. But why is it that SM 2.0 faster than 3.0? You would think 3.0 would run much much faster !!
Also in SM 3.0 I can have an array size of 15 elements. I can use all 15 lights and I get 70FPS. If i use 1 light I get 70FPS so it doesn't really matter. However when I set the array to 16 elements in the fx file my FPS drops to 10FPS !! even if I only use 1 light. why is that?!
struct Light
{
float2 Position;
float4 Color;
float Radius;
float Intensity;
};
Light lights[15];
Posted by FantasyVII
on 21 September 2012 - 12:33 AM
Feel free to play around with this and learn how it works but this is a very basic example of writing and reading your map data from a file written in binary, I also wouldn't call myself an amazing programmer but this works.
public class MapLocation { public int TileNumber = 0; public bool Blocked = false; //if the tile itself is blocked } public class MapManager { MapLocation[,] MapData = new MapLocation[100, 100]; //create a 2d Array with our map class // //////////////////////////////////////////////////////////////////////////////////////////////////////// public int GetTileAtLocation(int X, int Y) { //check bounds if (X < 0 || X > 100 || Y < 0 || Y > 100) { return 0; } else //its in bounds of our array { return MapData[X, Y].TileNumber; } } // //////////////////////////////////////////////////////////////////////////////////////////////////////// public void SaveMap() { using (FileStream stream = new FileStream("Map.dat", FileMode.Create)) //create our file { using (BinaryWriter writer1 = new BinaryWriter(stream)) //create writer { //write header writer1.Write(1000); //File Version increment this anytime you change data below for (int x = 0; x < 100; x++) //loop through all of our tiles { for (int y = 0; y < 100; y++) { writer1.Write(MapData[x,y].TileNumber); //write tile number writer1.Write(MapData[x,y].Blocked); //write blocked flag } } } } }//End SaveMap() // //////////////////////////////////////////////////////////////////////////////////////////////////////// public void LoadMap() { if (!File.Exists("Map.dat")) { //file does not exist return Console.Write("File Does not Exist\n"); return; } using (FileStream stream = new FileStream("Map.dat", FileMode.Open)) { using (BinaryReader reader = new BinaryReader(stream)) {///------------------------------------------------------------------------------------------------------------------------ //Read Header int ThisFileVersion = reader.ReadInt32(); //pull our version from the file and make sure it matches what we think we are reading //Check our file version if (ThisFileVersion != 1000) { Console.Write("Exp File Version Mismatch\n"); return; } for (int x = 0; x < 100; x++) //loop through all of our tiles { for (int y = 0; y < 100; y++) { MapData[x,y].TileNumber = reader.ReadInt32(); MapData[x,y].Blocked = reader.ReadBoolean(); } } } } }//end LoadMap() }//end MapManager
0false 1false 2true 3false 2true etc...right?
1,1,1,1,1,1,1,1,1,1,1, 1,1,1,1,1,2,1,1,1,1,1, 1,1,1,1,1,2,1,1,1,1,1, 1,1,1,1,1,2,1,1,1,1,1, 1,1,1,1,1,2,2,2,2,2,2, 1,1,1,1,1,1,1,1,1,1,2, 1,1,1,1,1,1,1,1,1,1,2, 1,1,1,1,1,1,1,1,1,1,2, 2,2,2,2,2,2,2,2,2,2,2,
MapX = 100, MapY = 100;
TileX = 32, TileY = 32;
int[,] map = new int[100, 100];
GrassID = 1;
StoneID = 2;
for (int x = 0; x < MapX; x++)
{
for (int y = 0; y < MapY; y++)
{
TilePosition.X = (float)x * TileX;
TilePosition.Y = (float)y * TileY;
if (map[y, x] == this.GrassID)
{
spriteBatch.Draw(this.GrassTile, TilePosition + ScreenScroll.ScreenOffset, Color.White);
}
if (map[y, x] == this.StoneID)
{
spriteBatch.Draw(this.StoneTile, TilePosition + ScreenScroll.ScreenOffset, Color.White);
}
Posted by FantasyVII
on 20 September 2012 - 02:06 PM
Sure thing!
Lets review the process of getting stuff back from the 1d array to the 2d array.
Each line has 10 items. So, for the first line [index 0] you just get the first 10 items. For the second line [index 1], you will get the second group of 10 items after the first 10 items on the 1d array.
Do you follow? This translates to, the items you want to get from the 1d array, start at LineIndex * ValuesPerLine, which means Y * 10.
Ok, so, the second line starts at LineIndex * ValuesPerLine, now to get the exact column you want, you just add its index. LineIndex * ValuesPerLine + ColumnIndex
After that, you add X, the current column index. Understood?
[X, X, X, X, X, X, X, X, X, X] Becomes [X, X, X, X, X, X, X, X, X, X][X, X, X, X, X, X, X, X, X, X]
[X, X, X, X, X, X, X, X, X, X]
Posted by FantasyVII
on 20 September 2012 - 01:53 PM
Map[y, x] = strArray[y * 10 + x];
1,2,3,4,5,6,7,8,9, 10,11,12,13,14,15,16,17,18, 19,20,21,22,23,24,25,26,27, 28,29,30,31,32,33,34,35,36,
class Program
{
static void Main(string[] args)
{
string buffer;
string[] map = new string[100];
int[] mapint = new int[100];
int[,] Map = new int[10, 10];
buffer = File.ReadAllText("D:/123.txt");
buffer = buffer.Replace("\r", string.Empty).Replace(" ", string.Empty);
map = buffer.Split(',');
for (int i = 0; i < 36; i++)
mapint[i] = Convert.ToInt32(map[i]);
for (int x = 0; x < 10; x++)
for (int y = 0; y < 10; y++)
Map[y, x] = mapint[y * 10 + x];
for (int x = 0; x < 10; x++)
{
Console.WriteLine();
for (int y = 0; y < 10; y++)
{
Console.Write(Map[x, y] + " ");
}
}
Console.ReadKey();
}
}
Posted by FantasyVII
on 20 September 2012 - 01:40 PM
I always hated when someone replied to me like this, so please take this as a suggestion and not a criticism!
I think what your doing may not be the best way to save and load your map data.
But to create a 2d array you do the following:int[,] MapData = new int[100, 100];I would suggest saving your map cordinates along with the tile info, without over complicating things you could just parse the first int as X the second int as Y and the 3rd int as the tile number.
int[,] MapData = new int[100, 100];
When doing this, I store the Width and Height of the 2D map together with the 1D array, so I have everything I need when parsing it back.
Converting from 2D to 1D is easy, since you just concatenate all values. Now, when parsing back, you must know how many columns a line has. Unless all of your maps are of a fixed size, lets say, 10x10. You will have to store this data.
After that, it's easy:Map = new int[Height, Width]; for (int i = 0; i < Width; i++) for (int j = 0; j < Height; j++) Map[j, i] = strArray[j * Width + i];
If you don't store this data and all of your values are of fixed size, its even easier, just replace the values on the above example for the fixed values.
example:
You have an array like this, which is composed of 100 items. All of your maps are 10x10, so you'll always have 100 items on the 1d array. To parse this back to 2D, all you gotta do is1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10,Map = new int[10, 10]; for (int x = 0; x < 10; x++) for (int i = 0; y < 10; y++) Map[y, x] = strArray[y * 10 + x];
Find content