Welcome, Guest. Please login or register. Did you miss your activation email?

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - SuperV1234

Pages: 1 ... 10 11 [12] 13
166
General / Bullet Hell performance and optimization problems
« on: June 14, 2010, 10:49:06 am »
Quote from: "Spodi"
Running the attached program, I get a constant spit-out of about: "13 ---- 2000". Runs nice and smooth.

Core 2 Duo E6750
nVidia 8800 GTS 320 MB
Windows 7 (x86-64)

You could try updating to the latest version of SFML since it looks like you are using a build from 4/4/2010. What I namely have in mind is the commit made on 4/24, where Laurent added the calling conventions for the .NET bindings, which was really killing performance with native assembly calls in some rare cases due to some expensive exception checking stuff that could come with .NET (I forget the name of that all - prefer to wipe that bad experience from my memory).

Finally, you can also try building for release and/or running the .exe directly, not through Visual Studio, just in case the debugger is doing something funky.


You mean SFML 2.0?

Anyway I'm not using the debugger since it decreases the performance a lot :)

167
General / Bullet Hell performance and optimization problems
« on: June 14, 2010, 09:55:31 am »
I have an nVidia GTX 275, my OS is Windows 7, my drivers are up-to-date.

168
General / Bullet Hell performance and optimization problems
« on: June 13, 2010, 11:48:32 pm »
Did a quick test: around 5000 8x8 sprites slow down the application.

169
General / Bullet Hell performance and optimization problems
« on: June 13, 2010, 11:15:20 pm »
Nevermind, I've measured the time using TimeSpans and DateTimes.

Update method takes 1 ms.
Draw method takes 15~18 ms.

170
General / Bullet Hell performance and optimization problems
« on: June 13, 2010, 11:03:21 pm »
Quote from: "Laurent"
Disable one, then the other, and compare performances.


If I disable Update then bullets won't be spawned, and even if I make it happen, they won't reach the end of the screen and be deleted.

I need some kind of timer that tells me how much time a method required to fully run. Is there anything like that?

171
General / Bullet Hell performance and optimization problems
« on: June 13, 2010, 10:51:41 pm »
Before I do that, is there any effective way to understand if it's either the Draw or the Update loop which causes the biggest slowdown?

172
General / Bullet Hell performance and optimization problems
« on: June 13, 2010, 10:21:43 pm »
Full source code: http://www.mediafire.com/?wgimixyjtbt


---


I'm making a bullet hell game (danmaku) using SFML.NET and C#.
My source of inspiration is Danmakufu, a game where you can create your bullet patterns, share them, play them, etc.


In Danmakufu I can easily spawn 300 bullets every frame staying at 58-60FPS all the time.
In my own game, when I spawn 300 bullets every 3 frames, the game becomes unplayable due to slowdown.


The biggest difference between my game and Danmakufu is that my game's resolution is 1024x768, Danmakufu is 800x600. But can that make an enormous difference?


---


My code for bullets is this:


Code: [Select]
public class Entity
    {
        public float X { get; set; }
        public float Y { get; set; }
        public Game Game { get; set; }
        public bool Alive { get; set; }
        public Sprite Sprite { get; set; }


        public Entity(Game game)
        {
            Game = game;
            Alive = true;
        }


        public virtual void Update()
        {
            Sprite.Position = new Vector2(X, Y);
        }
        public virtual void Draw()
        {
            Game.RenderWindow.Draw(Sprite);
        }
        public virtual void Destroy()
        {
            Alive = false;
        }
    }
Entity is the basic class for any object in the game; you can draw and update entities.


Code: [Select]
public class Bullet : Entity
    {
        private float _angle;
        public float Angle
        {
            set { _angle = Data.ANormalize(Data.ARadians(value)); }
            get { return Data.ADegrees(_angle); }
        }
        public float Speed { get; set; }


        public Bullet(Game game) : base(game)
        {
            Game.BulletManager.Entities.Add(this);
        }


        public override void Draw()
        {
            base.Draw();
        }
        public override void Update()
        {
            base.Update();


            X = X + Speed * (float)Math.Cos(_angle);
            Y = Y + Speed * (float)Math.Sin(_angle);
            Sprite.Rotation = 360-Angle;


            if(Game.Playfield.IsInPlayfield(X, Y) == false)
            {
                Destroy();
            }
        }
        public override void Destroy()
        {
            base.Destroy();
 
            Game.BulletManager.Entities.Remove(this);        
        }
    }
The Bullet class inherits from Entity. When it is spawned, it is added in the Game.BulletManager.Entities list. When it is deleted, it is removed from the same list.
If you're curious about the stuff happening in the "Angle" property, here are the related methods:
Code: [Select]
public static float ARadians(float angle)
        {
            return angle * 3.14f / 180f;
        }
        public static float ADegrees(float angle)
        {
            return angle * 180f / 3.14f;
        }
        public static float ANormalize(float angle)
        {
            if (angle > 360)
            {
                angle = angle - (360 * Convert.ToInt32((angle / 360)));
            }


            if (angle < 0)
            {
                angle = angle + (360 * Convert.ToInt32((angle / 360)));
            }


            return angle;
        }
---


Here's the code for the Manager class and the Game class:


Code: [Select]
public class Manager
    {
        public List<Entity> Entities { get; set; }


        public Manager()
        {
            Entities = new List<Entity>();
        }


        public void Update()
        {
            for (int index = 0; index < Entities.Count; index++)
            {
                Entity entity = Entities[index];
                if (entity.Alive)
                {
                    entity.Update();
                }
            }
        }


        public void Draw()
        {
            for (int index = 0; index < Entities.Count; index++)
            {
                Entity entity = Entities[index];
                if (entity.Alive)
                {
                    entity.Draw();
                }
            }
        }
    }
Pretty straightforward. Updating a manager updates all of its entities; drawing a manager draws all of its entities.


Code: [Select]
public class Game
    {
        public bool Running { get; set; }
        public RenderWindow RenderWindow { get; set; }
        public Manager BulletManager { get; set; }
        public Playfield Playfield { get; set; }
        public int Frame { get; set; }


        //DEBUG---
        public int DebugFrame { get; set; }
        private int kk = 0;
        private int ff = 1;
        private bool kkb = true;
        Image image = new Image(Environment.CurrentDirectory + @"/Data/Images/b_pellet.png");
        //--------


        public Game()
        {
            Running = true;
            RenderWindow = new RenderWindow(new VideoMode(1024,768), "Bullet Hell Test");
            RenderWindow.UseVerticalSync(true);
            RenderWindow.Show(true);
            BulletManager = new Manager();
            Playfield = new Playfield(this, 250, 50, 774, 718) {Offset = 25};
            Frame = 0;
           
            Debug();


            Run();
        }


        public void Run()
        {
            while(Running)
            {
                Update();
                Draw();
            }
        }


        public void Update()
        {
            BulletManager.Update();


            if(DebugFrame == 10)
            {
                Debug();
                DebugFrame = 0;
            }


            DebugFrame++;
            Frame++;


            Console.WriteLine("{0} --- {1}", Convert.ToInt32(RenderWindow.GetFrameTime() * 1000), BulletManager.Entities.Count);
        }
        public void Draw()
        {
            RenderWindow.Clear(Color.White);
            Playfield.DrawInside();
            BulletManager.Draw();
            Playfield.DrawOutside();
            RenderWindow.Display();
        }


        //--------------------------------------------------------------------------------------------


        public Bullet CreateBullet()
        {
            return new Bullet(this);
        }


        //--------------------------------------------------------------------------------------------


        public void Debug()
        {
            float step = 300;    


            for(int i = 0; i < step; i++)
            {
                Bullet temp = new Bullet(this);
                   
                        temp.Angle = (i*(360/step));
                        temp.Speed = 5f;
                        temp.Sprite = new Sprite(image);
                        temp.X = Playfield.GetCenter().X;
                        temp.Y = Playfield.GetCenter().Y;
            }


            if (kk < 120)
            {
                kk = kk + 5;
            }
            else
            {
                kk = 120;
            }


            ff = ff + 22;
        }
    }
This one is pretty straightforward too, ignoring the debug variables that I used before to create cool-looking patterns.
Update calls the "Debug" method every 10 frames, which spawns bullets.
Bullets aren't spawned by recycling, but instead by creating "new" bullets. I've chosen this because I haven't noticed big performance improvements recycling bullets in the past.
Draw draws bullets and the playfield, which creates the usual "shoot 'em up" borders around the playing screen.


---


So, I've created this thread to kindly ask you what am I doing wrong; why can't my game spawn the same amount of bullets as Danmakufu without slowing down?


Is it a SFML.NET limitation?

---


I have also another problem:


Game.BulletManager.Entities.Remove(this); --- this line in the Bullet -> Destroy method makes a single bullet move in a strange way while uncommented.


I think this is because the for loops skips or makes an unnecessary additional cycle.
How can I prevent this?


---

Thanks.

173
SFML projects / Bullet hell (Touhou) fangame
« on: April 09, 2010, 08:06:47 pm »
I have a performance problem. Spawning 64-128 bullets at the same time gives a big slowdown that lasts about 0.4 seconds; however after that everything is back at 60 FPS. How do I prevent this? I already "recycle" bullets (I don't create new bullets).

174
SFML projects / Bullet hell (Touhou) fangame
« on: April 06, 2010, 12:19:42 pm »
Quote from: "Sivak"
Neat.  I'm also doing a Shmup, though wanna do my own twist on things.  I'm in the process of trying to figure out a good way to get enemies to get loaded in from a file properly.  I'd like to know how you got the blue glowing effects on things.  The whole graphic side of this concerns me.


It's just a sprite with BlendMode.Add

175
SFML projects / Bullet hell (Touhou) fangame
« on: April 05, 2010, 11:21:57 pm »
Quote from: "Spidyy"
What are the strange green circle inside the bullet that appear time to time? Hitbox? :s

Looks pretty nice though!


Yes, those are the hitboxes.

Thanks! :)

176
SFML projects / Bullet hell (Touhou) fangame
« on: April 05, 2010, 11:05:15 pm »
Thanks. I made big progress today.

Successfully implemented LUA scripting. Look at these two videos (and read the first one's description).



177
SFML projects / Bullet hell (Touhou) fangame
« on: April 05, 2010, 05:03:07 pm »
I can't figure out how to do it. Can you make an example?

---

Nevermind, I found a solution.

I have another problem now: creating a large amount of bullets at the same time slows down the game a lot. After they're created however the FPS is back to 60.

What can I do to prevent this?

178
SFML projects / Bullet hell (Touhou) fangame
« on: April 05, 2010, 04:46:50 pm »
Quote from: "Spidyy"
What did you used for the white bullets? Simple image with transparency or some rendering tricks?


I used BlendMode.Add.

Anyway I have a big problem: I implemented LuaInterface to create bullet patterns, and it's working. However, I can't manage to find a way to make the program "wait" for some frames. Here's my Lua script:

Quote
luanet.load_assembly("SFMLTouhou");

for k=1,32 do
   for i=1,32 do
      CreateBullet(200, 200, 11.25 * i + k, 5);
      Wait(100);
   end
end


The "Wait" function currently does nothing. How can I make my script just wait some frames then continue, without obviously stopping the player and the rest of the game?

179
SFML projects / Bullet hell (Touhou) fangame
« on: April 05, 2010, 03:38:23 pm »
New video

180
SFML projects / Bullet hell (Touhou) fangame
« on: April 05, 2010, 02:37:44 pm »
That sounds cool! However I think I could create a 2-player mode (maybe over the internet) where a player draws danmaku with his mouse, and the other one dodges.

Or maybe a script editor that "records" your mouse movements and creates a script that does the same thing. The possibilities are endless! :p

Pages: 1 ... 10 11 [12] 13
anything