Jump to content

  • Log In with Google      Sign In   
  • Create Account

Banner advertising on our site currently available from just $5!

1. Learn about the promo. 2. Sign up for GDNet+. 3. Set up your advert!


Member Since 19 Dec 2004
Offline Last Active Apr 03 2014 10:57 PM

Topics I've Started

Short jobs and thread management

26 November 2012 - 03:54 AM

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:
  • 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.

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?

[web] Firefox and XPCOM

16 April 2006 - 01:17 PM

Sorry if this is the wrong forum, it just seemed the most appropriate. I'm tinkering with extensions in Firefox and have hit a bit of a stumbling block. What I'm trying to do right now is grab a page's DOM and then use that to add snippets of info on another page. As an example, say I'm viewing the thread list here and I wanted to put a list of the last five posters in the thread entries, instead of just the one. Things of that nature. The problem? The site I'm working with isn't XML well-formed. It's not even HTML well-formed. style elements outside the root element, forms spanning tables, et cetra. I don't run the site so there's no chance of changing this. Since it's not well-formed for XML, I can't use XmlHttpRequest(). Yes, I've looked for ways to parse flat text into an HTML DOM, but it seems either hidden or impossible to do. Plenty on parsing text into an XML DOM, though. Right now I'm tinkering with using the hidden iframe trick, but that seems to have issues in the manner I'm using it. It seems to always have an empty DOM document for it if it's created by an extension. Sooo, I've been flipping through the XPCOM reference on XUL Planet, and it certainly seems like XPCOM might offer a solution, but frankly, I'm lost. Does anyone have familiarity with XPCOM or experiences in a similar issue? Much thanks.

Code critique on a resource class

30 January 2006 - 03:18 PM

After a little work with SDL and some thought on having to make a class for managing each resource type for the various libraries (SDL, SDL_ttf, SDL_mixer), I tried my hand at creating a general resource class. I'd appreciate any critiques on the design for this - it's incredibly simple, but I was wondering if there was anything I missed or did wrong in this. It's purposefully general in use, I'll create handler classes for more advanced purposes (sprites and so forth) later on. Much thanks.
/* Resource
 * Provides a generalized approach to managing project resources
 * (SDL_Surfaces, TTF_Fonts and the ilk). User shouldn't encounter
 * this class nakedly, most usage should come as a private member
 * in helper classes.
 * Example:
 *   RscSurface Image( SDL_LoadBMP( "image.bmp" ), SDL_FreeSurface );

template < class DATA, class RESULT = void >
class Resource
		DATA* Handle;
		RESULT (*Callback)( DATA* );

		Resource( DATA*, RESULT (*)( DATA* ) );

		operator DATA*() const
		{ return Handle; }

template < class DATA, class RESULT >
Resource< DATA, RESULT >::Resource( DATA* pHandle, RESULT (*pCallback)( DATA* ) )
	: Handle( pHandle ), Callback( pCallback )

template < class DATA, class RESULT >
Resource< DATA, RESULT >::~Resource()
	if ( Callback != NULL )
		(*Callback)( Handle );

typedef Resource< SDL_Surface >	RscSurface;

Compiler complains about using-declaration

27 January 2006 - 09:51 AM

Using C++, GCC, SDL 1.2.9, Code::Blocks 1.0 RC2, Windows XP Problem After adding the class XFont to the project, I receive an error: using-declaration for non-member at class scope on compile. The odd part is that I have included the required header (map) in the accompanying CPP file. Prior to this particular class, the same process has worked fine with other classes. If I remove all inclusions of this class and drop it from the project, the project compiles fine. Adding #include <map> to the header fixes it, but then it fails to compile other class headers using the same process. Any suggestions? XFont.h
#ifndef XFONT_H
#define XFONT_H

namespace XGameLib
	class XFont
			SDL_Surface* mSurface;
			std::map< char, SDL_Rect > mClip;

			XFont( std::string, std::map< char, SDL_Rect > );


			XTexture* GetString( std::string );


#include <sdl/sdl.h>

#include <map>
#include <string>

#include "XTexture.h"
#include "XFont.h"

namespace XGameLib
	XFont::XFont( std::string font, std::map< char, SDL_Rect > clip )
		: mClip( clip )
		SDL_Surface* temp = SDL_LoadBMP( font.c_str() );

		if ( temp != NULL )
			mSurface = SDL_DisplayFormat( temp );
			SDL_FreeSurface( temp );

		if ( mSurface != NULL )
			SDL_FreeSurface( mSurface );

	XTexture* XFont::GetString( std::string message )
		SDL_Surface* output;

		for ( int i = 0; i < message.length(); ++i )


		return new XTexture( output );