• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
vanattab

SlimDX Application Design Question (Threading issues and how to avoid them?)$$REWARD$$

6 posts in this topic

NOTE: For technical reasons I need to target DX9 (not 10/11), I am offering $25 total via PayPal to any poster(s) who provide help leading to a resolution of this issue. I know that's not much but I am very poor and hopefully that is at least enough incentive to read my ridiculously long post.

I am having some trouble with figuring out how I should structure my program. I will first describe the general description of my program and then go into the things I have tried and the issues I have run into. I am not developing a game but rather a suite of computerized tests to test human vision. I am writing the program in VB.Net but converting between .Net languages is relativity trivial so if your going to post some code don't go out of your way to post it as VB if your better with C#. Even examples in other languages would be appreciated. I know the post is a little long but I want to be as clear as possible about the issues I am having. Thanks in advance!


Design: The program lunches a “Main Menu” VB.Net form that has lots of options to select different types of test and configure different options for the tests. When the user clicks the RunTest button for a specific test a TestObject representing that test is created. The TestObject constructor creates a StimulusDisplayObject(SDO) which is derived from the SlimDX RenderForm class. The job of the SDO class is to manage the SlimDX device object and render the different stimuli to the screen. It contains a list of StimulusObjects(SO) which are essentially just a DX surface that was loaded from an .bmp image and some location information that to tell the SDO class where to draw the surface on the screen. After the SDO is created the TestObject.BeginTest() method is called that is just a loop that presents a number of trials to the observer. The loop creates some SO objects and adds them to the list of SO objects of the SDO class to be displayed.

Problems: Because the stimuli I preset for the tests is fairly static and I usually only had to change the image that was displayed to the screen once every sec or two at the most, I did not have the scene rendering continually at as high of an FPS as possible. I simply had a SDO.RenderScene() that would get called from the TestObject whenever something need to be changed on the screen. This worked pretty well until I tried to handle DeviceLostExceptions and similar issues I arise from when the user ALT-TABs, CTRL-ALT-Delete, Covers the window (when in windowed mode), etc..) I have not found an effective way to handle these types of errors without having the scene continually rendering.

So I decided to try rewriting the SDO class to use SlimDXs MessagePump.Run() functionality to render the scene constantly, however this causes exceptions because The MessagePump.Run() conflicts with the MessagePump of the “Main Menu” Form (At least I think that is what this error message means: “Additional information: Starting a second message loop on a single thread is not a valid operation.”). I decided to try creating the SDO object in a new thread but then I can't communicate between the the TestObject and the SDO Object to add/remove/change the SO objects. I am not 100% sure that creating a multithreaded application is the best approach because I have read that DX and Threading leads to programing nightmares but I don't see any other solutions. I think I need to learn to use some kind of thread synchronization but I am very very new to threading and I want to make sure I am not heading down a road that is doomed to fail before I invest a long period of time learning to synchronized threads. If creating a multithreaded application is the best choice is there any DX/SlimDX threading issues I should be aware of? Any examples of simple SlimDX threaded programs that synchronize data across threads? Thanks for taking the time to read this post and I will extremely grateful to any advice you can give.
0

Share this post


Link to post
Share on other sites
Is the main menu continuing to run while the test takes place? You could potentially include the update and/or render call in the main menu's messagePump, wrapped in a boolean check to see if "test_is_running" is true?
0

Share this post


Link to post
Share on other sites
Yes it is. At least I think it is. When I am running the test one monitor and have the mainMenu form opened on the other monitor the mainMenu buttons and textboxes are still responsive. How would I go about adding the update call to the forms messagePump.
0

Share this post


Link to post
Share on other sites
There's nothing inherently wrong with only rendering when you need to. The reason games do it is because there are typical objects animating and camera movement constantly, so the changes have to be rendered anyway. If you give more information on what was going wrong with device lost scenarios, it might be a better approach to try to fix those and continue going the way you were before.

If you want to render continuously though, that's also viable. The idea is that you *replace* the Application.Run() method with MessagePump.Run(). You can run as many forms as you want on the same message loop. MessagePump.Run() internally hooks the application "Idle" event and constantly calls your provided callback whenever there are no window messages in the queue. You can put your rendering code inside that loop, and then you can add objects to be rendered to some shared list whenever you need to run one of your tests.
0

Share this post


Link to post
Share on other sites
[quote name='Mike.Popoloski' timestamp='1348674766' post='4984004']
There's nothing inherently wrong with only rendering when you need to. The reason games do it is because there are typical objects animating and camera movement constantly, so the changes have to be rendered anyway. If you give more information on what was going wrong with device lost scenarios, it might be a better approach to try to fix those and continue going the way you were before.

If you want to render continuously though, that's also viable. The idea is that you *replace* the Application.Run() method with MessagePump.Run(). You can run as many forms as you want on the same message loop. MessagePump.Run() internally hooks the application "Idle" event and constantly calls your provided callback whenever there are no window messages in the queue. You can put your rendering code inside that loop, and then you can add objects to be rendered to some shared list whenever you need to run one of your tests.
[/quote]

Thanks for the help Mike. I am working on rewritting some of the code now. I was haveing trouble trying to handle the DeviceLostExceptions when not rendering on demand. I tried to have some render code that looked something like:

[source lang="vb"]Sub RenderScene()
...Some Code
Try
device.present()
Catch e as devLostEx
DevLost = true
recover()
RenderScene()
End Try
End Sub

Sub recover()
While DevLost
Try
device.testCoop
Catch DevLostEx
'Do nothing
Catch DevNotReset
...Dispose defult pool stuff
device.reset()
recreate defult pool stuff
DevLost = false
End Try
End While
End Sub[/source]
That was with MDX9 not SlimDX. It just seemed to hang and never recover. I am not sure why. Anyway I have got a SlimDX basic class rendering contiually and handleing device lost exceptions fine. I am running it in its own thread and am just using synclock to protect data when I pass new objects to the display. I think the code would be a little slow if I need to render really fast because I synclock most of the SlimDX code but I don't think it will be a big issue for me. I am however running in to some trouble. I can't find a SlimDX replacment for the MDX9 Surface.FromImage() method. Also someone said that the DeviceEx class as some better features for passing data between threads so should I be using that class? Thanks for any help you can provide.
0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0