Jump to content

  • Log In with Google      Sign In   
  • Create Account


Member Since 14 Jun 2011
Offline Last Active Mar 15 2013 01:50 AM

Topics I've Started

Porting Dustforce to OS X

05 March 2012 - 02:14 AM

I've started porting our game Dustforce to OS X, and it's going pretty well so far, the debug build is actually up and running.
But as soon as I try to run the game with a release build of AngelScript I get a null pointer access on the first reference the code comes across which has been returned from the application (i.e. script classes being instantiated seem to work fine).
And if I comment that code out, the next reference it tries to access is null, and so on.

It seems to be when I enable optimisations, even the first level, if I disable optimisations in the release build it works, or enable them in the debug build it fails.

To isolate the problem, I added the array add-on to the "tutorial" sample, and put this code in the script:

array<uint> arr;

And I get a null pointer access on arr.resize(5);
I stepped in to the factory function and confirmed that it's not returning null...

I'm using Xcode 4.2.1 and I've tried AngelScript 2.22.1 and 2.22.2
I've tried building from the included Xcode project file, and also just adding the AngelScript cpp files to the Dustforce project.

I'll keep trying, but much of the internals of AngelScript are a bit over my head.
Any help would be greatly appreciated.


Compile performance notes.

15 November 2011 - 09:08 PM

First of all, thanks Andreas for your work on AngelScript! It's been great to work with.
Our game project ( Dustforce ) is getting larger (~35,000 lines of AngelScript ) and as a result has started to take a long time to compile ( ~19 seconds )
19 seconds isn't too bad, but being able to quickly make changes and test the results is important for gameplay programming.

So I had a quick look at where that time was getting spent.

More than half the time was spent in asCScriptEngine::ParseToken which didn't really surprise me.
But the line that was spending all the time did...
if( stringLength == 0 )
	stringLength = strlen(string);
I traced the source back to the script builder add-on, and there's a few places where ParseToken is called with 0 as the length which causes the length to be calculated again for every single token...

Fixing that got my compile time down to ~9 seconds which was exciting.

Another big one was asCTokenizer::IsKeyWord which I optimised away by making a std::map<string, eTokenType> from the tokenWords array and searching the map for the token starting at length of the longest element and working down ( to avoid !is missing !isTrue etc ) and also replaced all the linear searches on that array where I could.
Here's my code:
bool asCTokenizer::IsKeyWord()
	int maxLength = sourceLength > 9? 9:sourceLength;

	while( maxLength > 0 )
		char test[10];
		memcpy( test, source, maxLength );
		test[ maxLength ] = '\0';

		map<string, eTokenType>::iterator tokenI = tokenWordsMap.find( test );
		if ( tokenI != tokenWordsMap.end() )
			tokenType = tokenI->second;
			tokenLength = maxLength;
			return true;

    return false;

This cut the compile time down to ~6 seconds which is pretty good.

The remaining 6 seconds doesn't look quite as easy to cut down, but a good amout of it appears to be spent in linear searches.

I understand that compile performance isn't really a priority for AngelScript at the moment, but these small changes might be useful for people with larger projects.
The ParseToken thing in CScriptBuilder should probably be fixed, I can try to work out how to submit a patch if you'd like. Otherwise I think you can just find-replace
engine->ParseToken(&modifiedScript[pos], 0, &len);
engine->ParseToken(&modifiedScript[pos], (int)modifiedScript.length() - pos, &len);
in scriptbuilder.cpp

And if anyone has any ideas on how to improve performance further, let me know!


Entity factory

14 June 2011 - 11:16 PM

I'm re-working the level saving in the game I'm working on and I'm trying to work out how to handle entity construction when loading.

I have an entity base class and several entity types that derive from it,
Entities are currently saved by storing a type index, which is passed in to a switch statement to construct the correct type when loading.
So I was looking for a way to do this automatically, without having to add items to the switch statement for each new entity type.

I tried using function pointers to constructors, but I could only get it to work for the base class, I couldn't work out how to cast the derived constructor to the base function pointer type...
Another option is to add another context and a c++ function that calls the factory function and returns the object reference, but that seems like a kind of round about way of doing it..

So I guess my question is, is there a way to construct an object by its string name (directly from AngelScript), or by some other stored value, like a reference to the constructor?

Sorry if this has been answered, I have read the manual and done some searching.