• 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
tychon

Short jobs and thread management

3 posts in this topic

I'm looking for some insight into how other people would handle this or any pointers about Java's threading that I probably missed.

I have entities in the scene who update part of their state using the results of an external script. There's no upper limit (yet) on how many of these entities there can be, so in theory a scene could have five or five hundred. I say external because there is no interface for Java (or C or anything else) to the script environment. It's another process that takes in a script file and an inputs file from the terminal and creates an outputs file with the results of its processing. I can handle running the scripts and translating data back and forth just fine. However, the time it takes for each execution instance is significant enough (around 10 ms on my dev machine) that I can't iterate through every entity in the update loop without causing significant delays for a scene with more than a couple of them running. I'm working on optimizing everything I'm doing to communicate between the game and the script process, but (for this machine) there is a hard minimum of around 3 ms per execution. Hence I'm looking into how best to divvy the work.

My current ideas are something like this:[list=1]
[*]Handle as many objects in the update loop as is possible within X ms.
[*]Use a cached thread pool ExecutorService.
[*]Use a fixed thread pool ExecutorService.
[/list]

I'm not nuts about the first one because the scripts should run as close as possible to their given update rate (each script has a configurable clock rate) or things could, in theory, go awry. To explain a little, the script process is actually a Verilog synthesizer and simulator. Each "script" is a Verilog file describing some hardware component that is simulated by the process. Each component might have a clock and it helps if they run as close as possible to their expected clock rates or timing can get fussy. Obviously the scheduler doesn't allow things to happen in real time nor anywhere near the level of accuracy one would hope for from real hardware, but it's a plus if they're delayed as little as possible. Pushing script updates to the next game update is something I'm hoping to avoid. Though I will point out that I haven't tested this yet to see how much of a problem it is. Thorough testing of this will be a bit difficult, though, since this game is meant to be used by others and I have no way of knowing what sort of hardware they might be trying to simulate.

I'm going to try implementing the third idea first because it feels the most "right" to me, though I have no real justification for it at the moment. My only concern with the second one is the possibility of the game having been idle for a bit, the threads being released, and suddenly a wave of 150 update requests pops up. The cached pool says it will create threads as needed. Does this mean it would try to create 150 threads at once?

Does anyone have some experience with a situation like this, and if so, what worked for you?
0

Share this post


Link to post
Share on other sites
The process whose responsibility is execute those verilog scripts stay resident or must be executed upon each iteration ?

You have access to the Verilog Simulator's source code ? It's possible to change the simulator to take the input from a socket, a shared memory or any other IPC mecanism ? or is the simulator capable of taking the input via stdin and output the results via stdout ?

If the simulator could stay resident, accepting the input (and the output) from an IPC mecanism (or the stdin/stdout), you could create a pool of those simulators and use it from within your application. If the simulator is CPU bound, you should resist the urge to create more threads when they're being used. The optimal of threads may vary but, in theory, with a single threaded, primary CPU bounded process, should be the number of CPU cores (not sure about this last one, people with more experience in multicore programming could provide you a better insight)
1

Share this post


Link to post
Share on other sites
Unfortunately, the process wasn't at all built with this sort of use in mind, so it isn't resident and it only takes in file paths for inputs and creates a new file for each output. I have access to the source; good point that I can just rework it, though I think the way it's setup may take a little doing to make it more... general use. Not sure why I didn't just consider that first in retrospect.

I had been working with the idea of #cores (or #cores - 1) workers, hence my uncertainty about using Java's cached thread pool.

Anyway, thanks for the idea. I'll flip through their code and see if it's not too much of a headache.
0

Share this post


Link to post
Share on other sites
The update loop must finish its processing on a fixed amount of time ? If it doesn't, perhaps you could go without the thread pool.

You could create a façade, which take a batch of data that must be processed by he simulator. This façade divides the original batch into batches, each one with the size of the avaliable simulators (which can be pooled). After each one of these batches are dispatched, the façade waits for the execution of each simulation. After all batches are processed, the façade returns the results to the update loop.

Just an ideia ;)
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