Recent posts by Drakim on Kongregate

Subscribe to Recent posts by Drakim on Kongregate

avatar for Drakim Drakim 1145 posts
Flag Post

Topic: Game Programming / [AS3] Getting function arguments from an array [Solved!]

Originally posted by Elyzius:

Dynamic classes? Whoa, I’m not sure that calling their methods is any faster than calling function references.

The classes aren’t really dynamic, they are created by the compiler macro so that I don’t have to do it by hand. It could almost be compared to syntax aliases.

Whatever optimizations Haxe makes are ultimately compiled into AS3 opcodes and still utilize many built-in AS3 data structures such as arrays and function objects. If you can make components work well enough in Haxe, I can probably do the same in AS3.

You can’t inline your function calls in AS3 (well you can with Apparat but it’s much more limited). You also can’t do generics, which helps avoid a lot of casts.

I think you can make it work in AS3, but it will be much harder to keep it simple and pretty at the same time.

One good thing about component-based programming is that it opens my eyes to thinking about how classes can be made less “blobby.” How I’ve been programming until now is akin to making a world by creating roads, buildings, people, and cars, but I haven’t really put in much thought about what goes into those objects. I realize now that I should be thinking more about what components make up these things, such as carburetors, engines, and whatnot for cars. Even if I stick with building classes out of other classes at compile time and calling methods directly instead of using event-driven calls, I’ll probably be designing my classes in a more component-oriented manner.

Yup. My deeper topics only detailed my personal system, not the official way of doing components. My system takes a performance hit, but has gains in return like being fully dynamic and configurable at runtime. You could in theory load an entirely new kind of enemy over JSON or XML at runtime, which would be awesome for user created content.

 
avatar for Drakim Drakim 1145 posts
Flag Post

Topic: Game Programming / [AS3] Getting function arguments from an array [Solved!]

Originally posted by Elyzius:
I don’t understand how you can use macros to handle callbacks with your components, however. Macros aren’t real functions, so there shouldn’t be any kind of function pointer that you can store in, say, a linked list. From the way you word your pseudocode in this thread, it seems like you’re using either function pointers or Haxe callbacks. Am I right?

I don’t know if callbacks and function pointers in Haxe are eventually compiled as AS3 function objects. I guess some performance testing is in order.

In my deeper topics I purposefully avoided almost all tiny improvements and optimizations that could be done, because I wasn’t sure that I would succeed at explaining components at all.

Haxe macros can do anything that doesn’t break the language syntax. For instance, I made a macro that takes my anonymous function, and then automatically creates a new class in the Runnable pattern for this function call. It’s still work in progress though because the scope is now different, so if you aren’t careful your function code won’t work.

 
avatar for Drakim Drakim 1145 posts
Flag Post

Topic: Game Programming / [AS3] Getting function arguments from an array [Solved!]

The Runnable design pattern sounds like it might work, but wow, that would mean having an extra class for each event that each component is supposed to handle.

AS3 is really annoying at times :p

I don’t know enough of Haxe to say whether programming components with it will result in a tolerable performance hit.

Once my bullet hell test ran a few thousand objects at once at a solid 60fps, I stopped benchmarking

I’ve noticed, though, that its built-in List and FastList data structures won’t allow you to insert objects in the middle of the list. Strangely, List is a FIFO collection, but FastList is a LIFO collection. It’s little things like those that make me wonder just how good Haxe is.

The class is as lightweight as physically possible. But it’s not like there is anything magical about it, if your make your own Linked List class with more functionality it won’t suffer any downsides from being written by you.

 
avatar for Drakim Drakim 1145 posts
Flag Post

Topic: Game Programming / [AS3] Getting function arguments from an array [Solved!]

Haxe can help get around some of these issues.

As for function objects being slower, it can sometimes be worked around with the Runnable design pattern (or though Haxe macros). I’ve also found that when it comes to mass behavior (like thousands of bullets), it’s sometimes better to write components specifically crafted for performance, rather than relying on complex chaining of different components to get the behavior you want.

 
avatar for Drakim Drakim 1145 posts
Flag Post

Topic: Game Programming / Frameworks/engines, how to learn them

Since you are using Flash CS6, do you still code on the timeline? I would advice you to first of all move away from Flash CS6, over to something like Flash Develop, and start using only classes (if you aren’t already).

Once you have that nailed, I would advice you to just find some of the numerous Flixel tutorials that are around and follow them.

 
avatar for Drakim Drakim 1145 posts
Flag Post

Topic: Game Programming / [solved] Multidimensional array having some single elements not being copied properly

I would recommend staying away from the “new Array()” syntax entirely. Just using [ is less verbose and more consistent here:

static public var CONNECT_NODES:Array = [
		//level 1
		[
			[7, 11],
			[7],
			[8],
			[8],
			[9], // and so on...


 
avatar for Drakim Drakim 1145 posts
Flag Post

Topic: Game Programming / Using music in my game

If you are planning to stream it, you need to find some places to host it yourself though.

 
avatar for Drakim Drakim 1145 posts
Flag Post

Topic: Game Programming / Using music in my game

For a flash game, reducing the quality of the music is usually not noticeable at all to most players, but can more than half the size of the song.

I use Audacity (it’s free) but there are many alternatives. Just google instructions and you’ll be good.

 
avatar for Drakim Drakim 1145 posts
Flag Post

Topic: Game Programming / latent controls issue

Does it happen in all browsers? Do you have a different machine to test on? Do you run debug standalone versus release in the browser?

 
avatar for Drakim Drakim 1145 posts
Flag Post

Topic: Game Programming / getters and setters in other languages

Haxe supports the AS3 getters and setters, but also has it’s own Haxe specific getters and setters that are only applied at compile time, so they don’t have the performance cost that AS3 has for function calls.

A lot of people dislike getters and setters, because it changes how properties behave. I can understand the viewpoint, and I agree that overuse of getters and setters is terrible. I do however thing that it can be reasonable for stuff like .length properties, instead of forcing a .getLength() function.

 
avatar for Drakim Drakim 1145 posts
Flag Post

Topic: Game Programming / Tile Based Game Idea

This site has some neat ideas you could look at.

 
avatar for Drakim Drakim 1145 posts
Flag Post

Topic: Game Programming / Kong API with MySQL?

SMB is also plagued by the ingame physics being dependent on the game running at a certain rate, so if you lag too much everything starts glitching out. He seems like a pretty bad programmer, to be honest.

 
avatar for Drakim Drakim 1145 posts
Flag Post

Topic: Game Programming / Kong API with MySQL?

You are problaby gonna need some server side scripting like PHP to help communicate between Unity3D and MySQL. If Unity3D was to communicate directly with MySQL, it would require the MySQL password to be embedded in the Unity3D app that gets given out to all your players, which is a very very bad idea.

 
avatar for Drakim Drakim 1145 posts
Flag Post

Topic: Game Programming / Deeper Topic (part 3): Events to the rescue!

I pretty much only use blitting, so I have little experience. Couldn’t you possibly make some sort of MovieClipHolder component?

 
avatar for Drakim Drakim 1145 posts
Flag Post

Topic: Game Programming / Deeper Topic (part 4): Examples and advanced techniques

Thanks for the kind words.

My hidden secret is that I have both :3

Though clever use of Haxe macros and abstracts, my entire .swf is almost nothing but one big Bytearray instance, powered by the specical Alchemy opcodes for read/write, and inlined function calls that disappear at compile time. I’ve implemented close to everything in this, classes, graphics, sound, the component system, etc. The only thing I cheat with is a single Bitmap to act like the screen, since Flash requires it.

If you were to decompile the .swf, you would find nothing but Ints being pushed around a few million times, with no function calls and no class instances being made. It runs like a dream. And due to the power of Haxe, my actual code still retains the visual appearance of regular classes and functions, so it’s easy to manage and edit.

 
avatar for Drakim Drakim 1145 posts
Flag Post

Topic: Game Programming / Deeper Topic (part 3): Events to the rescue!

Then way I do it (and you don’t necessarily have to mimic me) is by separating it into 3 components, Position, Velocity and Player.

Position is just .x and .y

Velocity has .xSpeed and .ySpeed and listens for ‘update’ on the entity. In the callback it adds it’s two speed properties to the position component’s x and y.

The Player component also listens for ‘update’ on the entity, and checks for keypresses. When a button is pressed, it adjusts the Velocity’s speed values to give movement in the direction that is being pressed.

Obviously this on it’s own will not do anything since nothing is triggering the ‘update’ event on the entity. You need a world class of some sort (regular class or entity, either is fine) that can hold all ingame object entities in a list. The player entity needs to be added to this list, and every frame the world class should loop over the list and call ‘update’ on each entity.

 
avatar for Drakim Drakim 1145 posts
Flag Post

Topic: Game Programming / Deeper Topic (part 3): Events to the rescue!

Hmmm, I don’t think I would personally have a separate event for every frame that your player is moving. Rather I would recommend you have a ‘update’ component on your player entity that gets invoked every frame, that checks for these keypresses.

 
avatar for Drakim Drakim 1145 posts
Flag Post

Topic: Game Programming / Deeper Topic (part 4): Examples and advanced techniques

Most remarkably, everything can be regarded as being globally accessible

This is considered an extremely bad thing. The restrictions you have from accessing anything isn’t there because of computer limitations. It’s an artificial fake limitation imposed upon you by the programming language because accessing everything globally is bad in 99.99% of all cases (including games).

Likewise, you’ll never have to make a function call simply to get a value.

If you are worried about performance in regards to things like this, you should check out Haxe, which can inline it’s function calls (meaning the function is never actually called, the code runs directly).

 
avatar for Drakim Drakim 1145 posts
Flag Post

Topic: Game Programming / Deeper Topic (part 3): Events to the rescue!

Depends on the game, I guess. If you use components to apply and remove buffs and debuffs, being able to remove them is vital (unless the components are gonna stay “sleeping” on the target forever)

 
avatar for Drakim Drakim 1145 posts
Flag Post

Topic: Game Programming / Deeper Topic (part 4): Examples and advanced techniques

Well, it’s not strikingly wrong in terms of being impossible to use, but I imagine it becomes harder and harder to maintain as your game grows larger.

 
avatar for Drakim Drakim 1145 posts
Flag Post

Topic: Game Programming / Deeper Topic (part 3): Events to the rescue!

Yeah, sorry for the unspecific method name.

While that works with an int index, it has to iterate and compare until it finds the correct event.

With a reference to a cell of a LinkedList, the removal function can be extremely lightweight at 2-3 lines, just switching some references around.

 
avatar for Drakim Drakim 1145 posts
Flag Post

Topic: Game Programming / Deeper Topic (part 3): Events to the rescue!

oh, I see, it removes all events associated with a keyword/eventCode. Careful though, that could potentially break unrelated code that doesn’t expect to have it’s event attachments removed without warning.

 
avatar for Drakim Drakim 1145 posts
Flag Post

Topic: Game Programming / Deeper Topic (part 3): Events to the rescue!

That will work, but with the downside that will make removing events more expensive, as you either leave holes in your array, or you have to call the expensive splice function. If you have a game that removes and adds events frequently it might be a net loss.

One could perhaps merge the EventCBD instance and the LinkedList’s Cell instance into one and the same to reduce the number of objects. Each event object would point to the next one like a list.

 
avatar for Drakim Drakim 1145 posts
Flag Post

Topic: Game Programming / Deeper Topic (part 3): Events to the rescue!

The only annoying thing is that getComponent() returns IComponent rather than the component class, so you have to cast components every time you retrieve them. But I think that’s unavoidable in AS3. With Haxe you can make the function return the type that you asked for.

 
avatar for Drakim Drakim 1145 posts
Flag Post

Topic: Game Programming / Deeper Topic (part 4): Examples and advanced techniques

Obviously stuff like this depends on the game, but I had a lot of success using a World Entity that represents the physical world. It has a component that lists all the ingame object entities (which gets ‘update’ and ‘draw’ called by it regularly, unless they are too far from the player focus).

One advantage of this is that the World Entity would listen for an event called ‘invokeEvent’ where it would dispatchEvent on all the ingame entities that fits a certain criteria. It is perfect for explosions and such.


WorldEntity.dispatchEvent('invokeEvent',
  {
  range: new Rectangle(x,y,w,h),
  event: 'Explode',
  eventData: {damage:5, push:30}
  }
);

Using some Haxe macros and abstracts I could eliminate most of the performance loss associated with this level of abstraction. People on AS3 can possibly use Apparat for similar optimizations.