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

Notification

Icon
Error

Options
Go to last post Go to first unread
Offline Alexey  
#1 Posted : Thursday, September 8, 2011 9:01:30 AM(UTC)
Alexey

Joined: 8/24/2011(UTC)
Posts: 2

Thanks: 3 times
My question is dumb (well I think so): what is a good way to make an interactive application in Delta Engine? Let me explain. The easiest way to do so in many other commercial and home-made engines is to use the render loop in one way or another. How is it done correctly in Delta engine? The easiest situation: I want to know the position of the ball in Simple2DPhysicsTest sample at any given time. How can I do this? As far as I understand Delta Engine is completely event-driven so I need to hook a delegate to any object I am potentially interested in, am I right? Thank you in advance.

P.S. Sorry for posting in this section, my mistake, I think it's more suitable in "Engine"

Edited by user Thursday, September 8, 2011 9:33:57 AM(UTC)  | Reason: Not specified

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

Offline Benjamin  
#2 Posted : Thursday, September 8, 2011 12:51: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)
Moved your question to the Engine Forum.

I am not sure what exactly the problem is to build such an interactive application. You probably want to link something up to Input events (called Input.Commands and are very easy to use in v0.8.7) or some UI (so you see the position value on a label or modify it with a slider, etc.). This is certainly possible and easy to do.

Many things are event driven, but you don't really have to do it that way. Only the Scenes (UI stuff) pretty much require you to use events (it would be possible without, but that makes zero sense). However no one forces you to use events for input. You can just ask Input.Mouse or Input.Touch or Input.Keyboard every single frame for certain button states, which sometimes seems to be easier to do, but requires you do add a lot of code later when customizing controls and testing on other platforms is hard as well (we already support 5 different types of input devices out of the box and most game programmers are probably more used to only program against one for each task (hotkeys = only keyboard, control your game = only mouse or only gamepad, etc.). This is a bad idea for a multiplatform game where you have to think a bit how to control it on different devices you want to support (even if you only want mobile touch devices, you might want to test it under windows without touch as well).

But there is no way to just attach yourself to any .NET object with events. Only objects that have certain events for certain things will do useful stuff for you, like in physics collision events, in input when something was pressed or changed, in UI when the user did something, etc.

Hope this all makes sense to you Smile
thanks 1 user thanked Benjamin for this useful post.
Alexey on 9/11/2011(UTC)
Offline modular  
#3 Posted : Thursday, September 8, 2011 5:47:53 PM(UTC)
modular

Joined: 8/25/2011(UTC)
Posts: 17

Was thanked: 1 time(s) in 1 post(s)
Regarding the gameloop...

I think that the most straight forward way to make a game loop is like this...

Code:

while (quit == false)
{
// Input
// Update
// Render
}


But it's not perfect, imagine that a good GameLoop (or MainLoop) needs a ton of other details to work properly, regarding hardware devices, configuration compatibility, frame timing, and even more subsystems setup (Graphics, Audio, Physics, e.t.c). To make it short have a look at this default code for a main loop in order to see how it works, it's the GameWindow class that you can use in a standard OpenTK application.
Code:

https://opentk.svn.sourceforge.net/svnroot/opentk/trunk/Source/OpenTK/GameWindow.cs


If you have made some WinForms applications you might remember that you can start your winforms program like this.
Code:

Application.Run(new MainForm());


In the same spirit DeltaEngine will try to hide all of the system implementation from you and let you separate your game code from the engine code.



Originally Posted by: Alexey Go to Quoted Post
The easiest situation: I want to know the position of the ball in Simple2DPhysicsTest sample at any given time. How can I do this?

See Pong game example...

Code:

Application.Start(delegate
{
// code...

// Floor and ceiling collision
if ((ballPosition.Y <= Screen.Area.Top + ballRadius &&
	ballVelocity.Y < 0f) ||
	(ballPosition.Y >= Screen.Area.Bottom - ballRadius &&
	ballVelocity.Y > 0f))
{
	ballVelocity.Y = -ballVelocity.Y;
}
// code...
}




thanks 1 user thanked modular for this useful post.
Alexey on 9/11/2011(UTC)
Offline Benjamin  
#4 Posted : Thursday, September 8, 2011 7:05:13 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)
Btw: We have a concept of separating input/update/drawing in threads in the future (some unit tests showing this are coming in v0.8.7 in the Delta.Engine.Tests project), but currently you do everything at once and the engine automatically does all input for you at the beginning and will do all the rendering in parallel on the next frame (so CPU and GPU can work side by side). You can also enable "ReduceInputLag" to render right away, but then CPU and GPU will waste some cycles and the performance is not that good.

So currently just do everything in any way you want (events, input first, then update, then drawing, or in any chaotic order you like), it will just work. In the future there will be easier ways to separate your game update ticks (which might only occur few times like 5 times per second) and the rendering and interpolation code (which runs with 60 or even thousands of frames if you like).
thanks 1 user thanked Benjamin for this useful post.
Alexey on 9/11/2011(UTC)
Offline Alexey  
#5 Posted : Sunday, September 11, 2011 9:31:27 AM(UTC)
Alexey

Joined: 8/24/2011(UTC)
Posts: 2

Thanks: 3 times
Benjamin, modular, thank you for replies!
Offline modular  
#6 Posted : Sunday, September 11, 2011 6:32:05 PM(UTC)
modular

Joined: 8/25/2011(UTC)
Posts: 17

Was thanked: 1 time(s) in 1 post(s)
Hi there I also found a way to setup a minimal DeltaEngine application like this.

Code:

using System;
using Delta.Engine;
using Delta.Rendering.Basics.Drawing;
using Delta.Utilities.Datatypes;

namespace TestDeltaEngine
{
	class Program : Application
	{
		private static void GameLoop()
		{
			Line.Draw(new Point(0, 0), new Point(1, 1), Color.Red);
			Line.Draw(new Point(1, 0), new Point(0, 1), Color.Green);
		}
		
		public static void Main(string[] args)
		{
			// Same as writing a delegate{} block
			Application.Start(Program.GameLoop);
		}
	}
}
Offline Benjamin  
#7 Posted : Sunday, September 11, 2011 6:55:37 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)
Good Tip.

In the new version you can also derive from DynamicModule and pass that to Application.Start (or use a delegate or use nothing if you already have started some module like a Scene with UI or a level or anything else).
Rss Feed  Atom Feed
Users browsing this topic
OceanSpiders 2.0
Similar Topics
Think Delta Engine (Platforms)
by Alexey 9/8/2011 9:01:30 AM(UTC)
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-2019, Yet Another Forum.NET
This page was generated in 0.302 seconds.