Welcome Guest! To enable all features please Login or Register.

Notification

Icon
Error

Options
Go to last post Go to first unread
Offline Matasx  
#1 Posted : Wednesday, October 23, 2013 9:27:56 PM(UTC)
Matasx

Joined: 8/30/2013(UTC)
Posts: 43

Thanks: 11 times
Was thanked: 1 time(s) in 1 post(s)
Hi, I've got 3 questions (possibly 2 feature requests and 1 bug):
  1. Is it possible to somehow pause rendering (to truly achieve 0 FPS)?
  2. Is it possible to fix framerate e.g. to 60 FPS (vertical sync should do - but is that possible?). I'm executing some other operations sideways and I need CPU time to do it. But it is fully used to render.
  3. When I set Center property of any sprite at beginning to any position (except Vector2D.Half - it works fine) and start window with Time.IsPaused = true; - the sprite is rendered at incorrect position! After I set Time.IsPaused = false;, sprite is automatically aligned to correct position after few frames. It is my issue after updating to v. 0.9.9.7. In version 0.9.9.3 it was just fine.

Wanna join the discussion?! Login to your forum accountregister a new account. Or Connect via Facebook Twitter Google

Offline Flavio Damasco  
#2 Posted : Thursday, October 24, 2013 1:06:35 PM(UTC)
Flavio Damasco

Joined: 5/15/2013(UTC)
Posts: 45
Location: Hannover

Was thanked: 2 time(s) in 2 post(s)
Hi Matasx, I signaled your support request to one of my colleagues. They should answer soon! Cool
UserPostedImage
thanks 1 user thanked Flavio Damasco for this useful post.
Matasx on 10/24/2013(UTC)
Offline Benjamin  
#3 Posted : Thursday, October 24, 2013 7:26:05 PM(UTC)
Benjamin

Medals: Admin

Joined: 8/20/2011(UTC)
Posts: 1,421
Location: Hannover

Thanks: 18 times
Was thanked: 97 time(s) in 92 post(s)
Originally Posted by: Matasx Go to Quoted Post

Is it possible to somehow pause rendering (to truly achieve 0 FPS)?


Sure you can, basically stop the update and draw loop (e.g. Thread.Sleep(5000) would not do anything for 5 seconds), but I guess this is not what you mean. You probably want to keep rendering, but stop updating game elements. You can do that:
Code:
Time.IsPaused = true;


To unpause just set it to false again. UI controls are excluded from this check, so you can render a menu or pause button and all your game objects will not longer be updated (but still rendered, otherwise you would not see them), except for UI. This is used in Creepy Towers (and all other complex games) to pause the game.

Tutorial coming up on: http://deltaengine.net/learn/tutorials

If you want to make rendering really slow (lets say 1fps) see the next tip with LimitFramerate.

Originally Posted by: Matasx Go to Quoted Post

Is it possible to fix framerate e.g. to 60 FPS (vertical sync should do - but is that possible?). I'm executing some other operations sideways and I need CPU time to do it. But it is fully used to render.


Yes, also very easy to do. Just set the Settings.LimitFramerate to 60, best done in the Settings.xml of your app (found in My Documents\DeltaEngine\<YourAppName>\). This way each user can decide which way he wants it:
Code:
<LimitFramerate>0</LimitFramerate>

Again, Tutorial coming up on: http://deltaengine.net/learn/tutorials

Originally Posted by: Matasx Go to Quoted Post

When I set Center property of any sprite at beginning to any position (except Vector2D.Half - it works fine) and start window with Time.IsPaused = true; - the sprite is rendered at incorrect position! After I set Time.IsPaused = false;, sprite is automatically aligned to correct position after few frames. It is my issue after updating to v. 0.9.9.7. In version 0.9.9.3 it was just fine.


Not sure why this happens, but it seems to be a bug with updating the DrawArea in the very first update tick. I guess it has already been cached and the drawing uses the cached rectangle, which is not longer updated if everything is paused. Sprite drawing has been optimized a lot in the past week, so this must be the issue. I have opened a bug for this and it will be fixed soon.
Offline Matasx  
#4 Posted : Thursday, October 24, 2013 7:49:54 PM(UTC)
Matasx

Joined: 8/30/2013(UTC)
Posts: 43

Thanks: 11 times
Was thanked: 1 time(s) in 1 post(s)
Thanks for your post.
  1. No. I know how to stop updating. I really want to stop rendering. Thread.Sleep can't solve it, because I need Application loop to be running. Basically I have WinForms application. I'm drawing something to panel using DeltaEngine and at some point I switch to code editor - another tab (panel is no longer visible) and I want it to stop rendering.
  2. That sounds great, but it is not working for some reason. I've set Settings.Current.LimitFramerate = 60;. I'm reading and displaying FPS value from GlobalTime.Current.Fps and it has still values about 700-800 FPS.
  3. Thanks.
Offline Benjamin  
#5 Posted : Thursday, October 24, 2013 9:33:24 PM(UTC)
Benjamin

Medals: Admin

Joined: 8/20/2011(UTC)
Posts: 1,421
Location: Hannover

Thanks: 18 times
Was thanked: 97 time(s) in 92 post(s)
I see, so you want to do less rendering. LimitFramerate is your friend. UpdatesPerSecond describes how many times the app is updated each second, LimitFramerate how many times it is drawn per second (1 might be the minimum, but maybe 0.0001 works as well ^^).

I will check if there is an issue with setting LimitFramerate at runtime, seems to be some code was removed some time ago. If you want you could limit it yourself (will be fixed in the next release):
- Either with Thread.Sleep, but you don't want to do that
- Or by changing AppRunner.RunTick and AppRunner.UpdateAndDrawAllEntities (still keep calling update, but leave out draw when rendering is paused)
Offline elasto  
#6 Posted : Friday, October 25, 2013 6:41:00 AM(UTC)
elasto

Joined: 8/23/2011(UTC)
Posts: 245

Thanks: 6 times
Was thanked: 12 time(s) in 11 post(s)
Originally Posted by: Matasx Go to Quoted Post
When I set Center property of any sprite at beginning to any position (except Vector2D.Half - it works fine) and start window with Time.IsPaused = true; - the sprite is rendered at incorrect position!

After I set Time.IsPaused = false;, sprite is automatically aligned to correct position after few frames.


Benjamin was right: Pausing was incorrectly stopping changes to DrawArea getting propagated through to the rendering. This is now fixed and will be included next release.

Also, you say that it takes a few frames to align to the correct position, but you don't say whether you dislike it doing that.

Just fyi, in case you're not aware, it's possible to instruct the draw area to change instantaneously rather than interpolate from the current position to the new - this also was not working correctly and is now fixed; After the line where you set the new center, simply add the line:

Code:
sprite.LastDrawArea = sprite.DrawArea;


(Of course, you may be perfectly happy seeing it interpolate :) )


Hope this helps!

- Phil

Edited by user Friday, October 25, 2013 10:13:30 AM(UTC)  | Reason: Not specified

thanks 1 user thanked elasto for this useful post.
Matasx on 10/25/2013(UTC)
Offline Matasx  
#7 Posted : Friday, October 25, 2013 9:20:12 AM(UTC)
Matasx

Joined: 8/30/2013(UTC)
Posts: 43

Thanks: 11 times
Was thanked: 1 time(s) in 1 post(s)
Amazing! Thanks for your support. :)
Using sprite.LastDrawArea = DrawArea; it works like a charm. I'm looking forward to next release. :)
Offline Benjamin  
#8 Posted : Saturday, October 26, 2013 12:49:58 AM(UTC)
Benjamin

Medals: Admin

Joined: 8/20/2011(UTC)
Posts: 1,421
Location: Hannover

Thanks: 18 times
Was thanked: 97 time(s) in 92 post(s)
Issue was fixed in v0.9.9.8, please test again. http://deltaengine.net/download/
Offline Matasx  
#9 Posted : Saturday, October 26, 2013 5:42:12 PM(UTC)
Matasx

Joined: 8/30/2013(UTC)
Posts: 43

Thanks: 11 times
Was thanked: 1 time(s) in 1 post(s)
Great job. It is working now! Thanks. ThumpUp
Offline Matasx  
#10 Posted : Tuesday, October 29, 2013 2:53:48 PM(UTC)
Matasx

Joined: 8/30/2013(UTC)
Posts: 43

Thanks: 11 times
Was thanked: 1 time(s) in 1 post(s)
It seems that I was too quick in my judgment. Blushing
I'm using defaultSettings.xml to limit framerate. In version v. 0.9.9.8 it is always targeting 60 FPS no mater what value is set in LimitFramerate property.
Setting value to Settings.Current.LimitFramerate also does not work.
Offline Benjamin  
#11 Posted : Saturday, November 2, 2013 10:18:40 AM(UTC)
Benjamin

Medals: Admin

Joined: 8/20/2011(UTC)
Posts: 1,421
Location: Hannover

Thanks: 18 times
Was thanked: 97 time(s) in 92 post(s)
Hmm, I tested it on all frameworks and the limiting of framework works (you can see the code in AppRunner.cs, it will sleep when there are too many fps). You can also limit your fps to 60 by forcing VSync with your graphics driver, maybe that helps.

If you need more help with this please send us a small project (.cs file or .exe) and we can take a look, maybe you are still referencing older versions of the DeltaEngine assemblies.
Offline Matasx  
#12 Posted : Saturday, November 2, 2013 2:30:02 PM(UTC)
Matasx

Joined: 8/30/2013(UTC)
Posts: 43

Thanks: 11 times
Was thanked: 1 time(s) in 1 post(s)
Well, it's working now. Strange. Maybe I've forgotten to rebuild whole solution.
Anyway thanks.
Offline Michael Koch  
#13 Posted : Sunday, January 26, 2014 1:44:31 AM(UTC)
Michael Koch

Joined: 12/27/2013(UTC)
Posts: 41
Location: Regensburg

Thanks: 3 times
Was thanked: 1 time(s) in 1 post(s)
I'd like to append to this thread here, as I think it is a similar topic:

Built me a "draggable window" out of several Line2D ("Borders") and FilledRects ("Backgrounds") and a FontText. By detecting mouse events and movement, I let the window follow the mouse when clicked. This is a (slowed down) screen recording of the current state: http://www.mikoweb.eu/tmp/DE_WindowDrag.wmv

As you might notice, the movement of the Line2D and FilledRects is not in sync. Although I pass the same position data to all objects, they seem to "built-in lerp" with different speed. The rects are behind a few ticks. Tried with "LastDrawArea=DrawArea", and also found the ".SetWithoutInterpolation<>". But then, the rects aren't drawn at all.

Any idea how I could get the movement synchronized? Thanks
Michael Koch attached the following image(s):
Image1.png (27kb) downloaded 10 time(s).

You cannot view/download attachments. Try to login or register.
Offline elasto  
#14 Posted : Sunday, January 26, 2014 3:01:41 AM(UTC)
elasto

Joined: 8/23/2011(UTC)
Posts: 245

Thanks: 6 times
Was thanked: 12 time(s) in 11 post(s)
Can you post your code? Also please confirm what version of DE you are using.

I recently built a draggable/resizeable windowing demo containing anchored controls made of sprites, lines and texts and did not encounter this issue.

One thing to try would be replacing the filled rect with a sprite (it's actually possible to create a sprite with no material, just a color, so it's the same as a filled rectangle). That will tell us if it's a bug with filled rectangles. Don't use those very much myself!

(I've only just pushed my demo and it still has to be merged and so on, so it may not appear in the nightly release for a little while though.)
Offline Benjamin  
#15 Posted : Sunday, January 26, 2014 12:32:08 PM(UTC)
Benjamin

Medals: Admin

Joined: 8/20/2011(UTC)
Posts: 1,421
Location: Hannover

Thanks: 18 times
Was thanked: 97 time(s) in 92 post(s)
I also guessed it is an issue with FilledRect and the interpolation. After investigating it turns out FilledRect is not interpolated at draw time (it was mostly used for debug info until now and no one really cared about having it nicely interpolated because filledrects did not move usually).

Normally lines, sprites and other most other shapes are interpolated automatically (otherwise fluid movement of the window would only be possible if you have enough updates per second). This is why PG did not have this problem (by not using FilledRect). The code from PG is now merged into the nightly builds repository and should be available next nightly release.

Anyway, I made some changes, Polygon2D now behaves more like Line2D, which allows setting it via DrawArea or even the points directly (which would allow to change the shape if wanted).
Code:

public class Polygon2D : Entity2D
{
	public Polygon2D(Rectangle drawArea, Color color)
		: base(drawArea)
	{
		Color = color;
		Add(new List<Vector2D>());
		OnDraw<DrawPolygon2D>();
	}

	public List<Vector2D> Points
	{
		get { return Get<List<Vector2D>>(); }
		set
		{
			Set(value);
			base.DrawArea = Rectangle.FromPoints(value);
		}
	}

	public override Rectangle DrawArea
	{
		get { return base.DrawArea; }
		set
		{
			var lastDrawArea = base.DrawArea;
			base.DrawArea = value;
			if (Contains<List<Vector2D>>())
				UpdatePointsAfterDrawAreaChanges(lastDrawArea, value);
		}
	}

	private void UpdatePointsAfterDrawAreaChanges(Rectangle lastDrawArea, Rectangle drawArea)
	{
		List<Vector2D> points = Points;
		for (int i = 0; i < points.Count; i++)
		{
			var relativePosition = new Vector2D(
				(points[i].X - lastDrawArea.Left) / lastDrawArea.Width,
				(points[i].Y - lastDrawArea.Top) / lastDrawArea.Height);
			points[i] = new Vector2D(drawArea.Left + relativePosition.X * drawArea.Width,
				drawArea.Top + relativePosition.Y * drawArea.Height);
		}
	}
}


The main change to make FilledRect use interpolated data is however in DrawPolygon2D:
Code:

private void AddToBatch(Entity2D entity)
{
	var points = entity.GetInterpolatedList<Vector2D>();
	//..


And finally here is the unit test used to test this issue (code and tests will be part of the next nightly release):
Code:

[Test]
public void RenderRectAndLine()
{
	var drawArea = new Rectangle(0.3f, 0.3f, 0.4f, 0.4f);
	var rect = new FilledRect(drawArea, Color.Red);
	var line = new Line2D(drawArea, Color.Yellow) { RenderLayer = 1 };
	new Command(Command.Drag, position => rect.Center = line.Center = position);
}
Offline Michael Koch  
#16 Posted : Sunday, January 26, 2014 5:32:43 PM(UTC)
Michael Koch

Joined: 12/27/2013(UTC)
Posts: 41
Location: Regensburg

Thanks: 3 times
Was thanked: 1 time(s) in 1 post(s)
Ah, ok, I see. Thanks you both.

Just for reference: I am on nightly build 1.0.0.10. This here is my "test case class" - which did also show that the problem does not happen when using sprites. Just FYI.

Code:

using DeltaEngine.Commands;
using DeltaEngine.Content;
using DeltaEngine.Datatypes;
using DeltaEngine.Input;
using DeltaEngine.Rendering2D;
using DeltaEngine.Rendering2D.Shapes;

namespace TestDEWS
{
    class Class1
    {
        //private Sprite m_Window;
        private FilledRect m_Window;
        private Rectangle  m_WindowRectScrSpace = Rectangle.Unused;
        private Line2D     m_WindowBorder;
        private bool       m_bDragging = false;
        
        public Class1 ()
	    {
            m_Window = new FilledRect(m_WindowRectScrSpace,Color.DarkGray);
            //m_Window = new Sprite("Verdana12Font", Rectangle.Unused); This works!
            m_Window.RenderLayer = 100;

            m_WindowBorder = new Line2D(Vector2D.Unused, Vector2D.Unused, Color.Yellow);
            m_WindowBorder.RenderLayer = 101;

            m_WindowRectScrSpace = new Rectangle(0.0f, 0.0f, 0.2f, 0.2f);
            RepositionWindow(new Vector2D(0.2f,0.2f));

            new Command(position => onMouseDown(position)).Add(new MouseButtonTrigger(MouseButton.Left, State.Pressing));
            new Command(position => onMouseUp(position)).Add(new MouseButtonTrigger(MouseButton.Left, State.Releasing));
            new Command(position => onMouseMove(position)).Add(new MousePositionTrigger(MouseButton.Left, State.Pressed));            
	    }

        public void RepositionWindow(Vector2D vPosition)
        {
            m_WindowRectScrSpace = new Rectangle(vPosition, m_WindowRectScrSpace.Size);
            m_Window.DrawArea = m_WindowRectScrSpace;
            //m_Window.LastDrawArea = m_Window.DrawArea; Does not work for filled rect
            m_WindowBorder.StartPoint = m_WindowRectScrSpace.TopLeft;
            m_WindowBorder.EndPoint = m_WindowRectScrSpace.BottomRight;
        }

        private void onMouseDown(Vector2D vPosition)
        {
            m_bDragging = true;
            RepositionWindow(vPosition);
        }

        private void onMouseUp(Vector2D vPosition)
        {
            m_bDragging = false;
        }

        private void onMouseMove(Vector2D vPosition)
        {
            if (!m_bDragging) return; // Todo: Only register event when in drag mode.
            RepositionWindow(vPosition);
        }
    }    
}

Offline Benjamin  
#17 Posted : Monday, January 27, 2014 5:02:11 PM(UTC)
Benjamin

Medals: Admin

Joined: 8/20/2011(UTC)
Posts: 1,421
Location: Hannover

Thanks: 18 times
Was thanked: 97 time(s) in 92 post(s)
Nightly build 1.0.0.11 fixes the problem: http://deltaengine.net/n...0.0.11+rev.c6de4c91b2a7/
Offline Michael Koch  
#18 Posted : Saturday, February 1, 2014 5:57:05 PM(UTC)
Michael Koch

Joined: 12/27/2013(UTC)
Posts: 41
Location: Regensburg

Thanks: 3 times
Was thanked: 1 time(s) in 1 post(s)
Thanks for the update.

Uhmmm... I'm on Nightly .13 now (didn't check the .11 in particular, as a newer one was available already).
Now, when running my above posted "test case class", no FilledRect is drawn at all (while the sprite variant still works).

The unit test 'RenderRectAndLine()' in FilledRectTests.cs seems to have that problem, too (didn't run the test directly, just copied over the code).
FYI.
Offline Benjamin  
#19 Posted : Monday, February 3, 2014 3:34:54 PM(UTC)
Benjamin

Medals: Admin

Joined: 8/20/2011(UTC)
Posts: 1,421
Location: Hannover

Thanks: 18 times
Was thanked: 97 time(s) in 92 post(s)
There might have been another issue with culling from last week, maybe you were unlucky and tested a version that had the culling inverted. This has been fixed since and should be fine now, if not, point us to the failing test or feature and we will check.
Rss Feed  Atom Feed
Users browsing this topic
OceanSpiders 2.0
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.

Powered by YAF.NET | YAF.NET © 2003-2023, Yet Another Forum.NET
This page was generated in 0.188 seconds.