tag:blogger.com,1999:blog-3717133688018454834.post3230289584552480270..comments2024-01-05T11:00:14.227+00:00Comments on Iain Lobb: How to communicate between game objects.Unknownnoreply@blogger.comBlogger25125tag:blogger.com,1999:blog-3717133688018454834.post-85736677319742154092012-02-02T04:26:37.267+00:002012-02-02T04:26:37.267+00:00It's only matter when you want to make another...It's only matter when you want to make another game, because you want to reuse all of your classes from the other game.<br /><br />if you use the photon-storm registry approach then on the next game you need to use it again, so you don't need to change to many things.<br /><br />I wonder how other engines do this (Unreal, Havok, Frostbite, etc) ?<br /><br />or the big game development studios make their games?Artinoreply@blogger.comtag:blogger.com,1999:blog-3717133688018454834.post-88751863123834905852011-09-16T15:32:18.765+01:002011-09-16T15:32:18.765+01:00Very helpful. I still remember before AS was OOP....Very helpful. I still remember before AS was OOP. Flash is so much more comprehensive these days, and resources like your article make it much better. Cheers!Authority Manhttp://www.appealtoauthority.infonoreply@blogger.comtag:blogger.com,1999:blog-3717133688018454834.post-77361834844198916162011-03-24T00:45:17.160+00:002011-03-24T00:45:17.160+00:00I just noticed how imperative that single comment ...I just noticed how imperative that single comment block I just made looks :) maybe I should have structured it into a few more paragraphs lol.<br /><br />It really doesn't represent how I code. I'm all for OO and efficiency actually, and I always appreciate reading blogs such as this one - it really gets you thinking.<br /><br />I've just had a closer look at the registry class on Photon Storm's blog, and it seems like a good system to me.<br /><br />I'm also always changing my mind about the best ways to do things!Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-3717133688018454834.post-64134300856394192592011-03-24T00:06:42.880+00:002011-03-24T00:06:42.880+00:00Thanks for this article, there's lots of inter...Thanks for this article, there's lots of interesting points made here, and it's helping me to work on my own framework. I personally find events as a method of inter-object communication a little bit complicated for my coding style, and prefer to pass information between objects including references to object pools etc, from within my main game class, and I also make extensive use of static variables in a Globals class much like Flixel's FlxG. There really is more than one way to boil an egg, and I truly believe the only right way of doing things is the way you believe is the easiest or most becoming. We don't drive the same cars, listen to the same music or paint in the same way, so why should we all make games in one definitive pattern? Patterns can help, but only if you find them natural, and this is key. I think that we all think differently on a psychological level. We code machines, but we are human and for genetic and physiological reasons we tackle problem solving in different ways. This to me is a shortcoming of design patterns, particularly in so creative a programming outlet as games dev.Badgerhttp://barnabybyrne.blogspot.comnoreply@blogger.comtag:blogger.com,1999:blog-3717133688018454834.post-52172470274325754202011-02-17T23:27:57.689+00:002011-02-17T23:27:57.689+00:00Hey Iain,
I really would like to see an article ...Hey Iain, <br /><br />I really would like to see an article about code organization, communication and probably a simple game in a whole. I still can't make up my mind and not sure how to organize things. Till now I haven't used inheritence but only a bit of composition and you said that you have generic class Entity. What you put in that class and what is the purpose of it? Sorry, for the noobish questions.<br /><br />PlamenPlamenhttps://www.blogger.com/profile/01687216102480565737noreply@blogger.comtag:blogger.com,1999:blog-3717133688018454834.post-23998559117720490762011-02-17T23:21:56.652+00:002011-02-17T23:21:56.652+00:00I didn't go digging through the comments much,...I didn't go digging through the comments much, but I see that signals have already been mentioned. As far as refactoring an enemy who targets a player goes, I generally use a variable named TARGET, which uses my BaseEntity class. That way, any entity I create can be the enemy's target.<br /><br />I do my entity updates in an almost identical way, and I'd be curious to see what sort of setup you have for your base engine. Right now I have an Engine class, which handles all of the set up. I have the BaseEntity class, which I can extend for any object I want to add to my game, a World class which handles level/map loading, and some utility classes.<br /><br />It's still a WIP, and I think it would be cool to see the way you have it set up. I had initially gone with a more Source Engine feel to things, but then adopted FlashPunk naming conventions because of a recent experiment. <br /><br />Essentially I'm trying to make my engine easier for newer users, as I plan to do a few collaborations.Trent Sterlinghttp://trentsterling.wordpress.comnoreply@blogger.comtag:blogger.com,1999:blog-3717133688018454834.post-10227945493037776042011-02-17T23:04:16.424+00:002011-02-17T23:04:16.424+00:00This comment has been removed by the author.Plamenhttps://www.blogger.com/profile/01687216102480565737noreply@blogger.comtag:blogger.com,1999:blog-3717133688018454834.post-85864251800865342292011-02-17T16:14:19.182+00:002011-02-17T16:14:19.182+00:00@crookedspoon the Game is listening to the addEnti...@crookedspoon the Game is listening to the addEntity signal on SpaceShip, which dispatches the bullet as an argument.Iainhttps://www.blogger.com/profile/16741682155796102883noreply@blogger.comtag:blogger.com,1999:blog-3717133688018454834.post-61684192067577031292011-02-17T16:08:55.498+00:002011-02-17T16:08:55.498+00:00Ian, you wrote:
Instead, the base Entity class has...Ian, you wrote:<br /><i>Instead, the base Entity class has a function addEntity(entity:Entity) which dispatches an AS3Signal with the entity value. My game is listening for this signal, and directs the entity to its own addEntity function.</i><br />If I understand that right: Bullet extends Entity,<br />Then Game has to know Bullet before if can listen to the signal dispatch from the addEntity function inherited from Entity. Then Game might as well addEntity(bullet) immediately.<br />Or is addEntity from Entity a static function?<br /><br />crookedspoon.crookedspoonhttps://www.blogger.com/profile/02482383811506590480noreply@blogger.comtag:blogger.com,1999:blog-3717133688018454834.post-56069877232263674742011-02-17T16:05:05.417+00:002011-02-17T16:05:05.417+00:00Yeah I change my mind about this stuff all the tim...Yeah I change my mind about this stuff all the time as I learn and try out new things. A couple of years ago I was sure MVC was the way to go for games! Wrong!! Anyway, yeah, each to their own I guess. I might even come back round to the Registry approach eventually. Making everything an Entity always seems to be a good idea though.Iainhttps://www.blogger.com/profile/16741682155796102883noreply@blogger.comtag:blogger.com,1999:blog-3717133688018454834.post-36570833930717692432011-02-17T16:00:32.413+00:002011-02-17T16:00:32.413+00:00I remember ages ago posting how I do this kind of ...I remember ages ago posting how I do this kind of thing on the blog.<br />I also remember being jumped on by a lot of people for not being oop "enough" ( Iain, think you were in there mate :) ).<br /><br />Any post like this is going to be abused, as we all have our own variations of "What's right" ( It's like Monopoly, has anyone ever played that with the proper rules ? ).<br /><br />Coding has so many variations, and a really strict oop approach doesn't really have a place in Flash game dev.<br />For me the key is to steal the bits you like from other people so you're in a happy place, be that a registry singleton or public vars.Squizehttp://www.gamingyourway.comnoreply@blogger.comtag:blogger.com,1999:blog-3717133688018454834.post-63274241207876783472011-02-17T15:06:53.487+00:002011-02-17T15:06:53.487+00:00I read the original registry post over at Photon S...I read the original registry post over at Photon Storm and enjoy seeing this alternate post regarding the reference passing.<br /><br />I've been using the reference passing method for a few years now and while it works well enough I agree the main problem I've run into with it is what another commenter above mentions and that is that during development I find I have to refactor quite often and then I'm left to crawl through a lot of my class files changing or altering all the places I'm passing my references around.<br /><br />What appeals to me about the Registry idea is how it would (hopefully) greatly reduce this refactoring during rapid development. A lot of the games I work on are less than 100 hour projects to create small scope games and development speed is crucial to being able to support myself. I enjoy any design patterns that help me more or less get the code down fast enough to understand the game and keep it flexible enough to alter as I get new ideas and feedback after reaching the first playable prototype. <br /><br />I think I'm going to try the Registry on my next few games and see how it goes because that is obviously the only way I'll know if it works out for me. <br /><br />I too agree that a developer should work with the methods they are comfortable with and that there are many solutions with nothing being really "wrong" or "right." That doesn't mean I don't want to hear these kind of interesting discussions though! I learn something new every time.HybridMindhttp://hybridmind.comnoreply@blogger.comtag:blogger.com,1999:blog-3717133688018454834.post-32504802972998962462011-02-17T15:03:10.906+00:002011-02-17T15:03:10.906+00:00@Ian good that's much better than lots of inhe...@Ian good that's much better than lots of inheritance but here are two main issue with that approach. First is dependencies between components say a physics and view components where they need to share data or communicate. Quite often things end up being tightly coupled and not as reusable as they should be. Second is inter entity communications. As for defining your entities in XML well that's your choice but its good to know you can. Generally flash games are small project worked on by a single developer and the real pay off of making everything data driven come into play with large teams. One of the main advantages of making everything data driven is you can share the data between clients easily or store it and load it automatically.Unknownhttps://www.blogger.com/profile/04352981003960855999noreply@blogger.comtag:blogger.com,1999:blog-3717133688018454834.post-19833476942579147562011-02-17T14:24:12.858+00:002011-02-17T14:24:12.858+00:00@tom I have gone down some bad roads of deep inher...@tom I have gone down some bad roads of deep inheritance trees in the past, but now I limit myself to 2 levels of inheritance. There is a base Entity class, and there are the objects that extends it - Player, Enemy, FireBall etc. Rather than adding intermediate levels of object like MovableEntity etc, I do use composition of components instead. So an Entity has components for Body, Physics, View etc. What I can't get into is the data-driven approach of putting all your entities definitions into XML etc.Iainhttps://www.blogger.com/profile/16741682155796102883noreply@blogger.comtag:blogger.com,1999:blog-3717133688018454834.post-59464051511710088212011-02-17T14:20:30.845+00:002011-02-17T14:20:30.845+00:00Hmm... interesting to read the different views on ...Hmm... interesting to read the different views on this. I've used both these systems to varying degrees in the past, and really they're quite similar in a lot of ways. Iain's way is essentially making a registry out of the main Game class, and making sure everything that needs to has a reference to it. In which case, why not just give the Game class a static reference to itself which anything can just refer to? Game.instance.addBaddie()<br /><br />My own feeling is that it's easy to get too hung up on this stuff in Flash game dev stuff. In our search for acceptance as 'proper' programmers, we worry about what's 'right' and 'wrong' a bit too much. Or maybe that's just me... ;o)Mark Burvillhttp://www.antifuzz.comnoreply@blogger.comtag:blogger.com,1999:blog-3717133688018454834.post-67554882591936434762011-02-17T14:17:50.667+00:002011-02-17T14:17:50.667+00:00@Ian agree if your used to flash where everything ...@Ian agree if your used to flash where everything extends everything then its a very different way of working. Your post nicely hi-lights the issues with that form of game architecture in all but the simplest of projects. It comes down to what your familiar with but remember if your only tool is a hammer then the whole world looks like a nail.Unknownhttps://www.blogger.com/profile/04352981003960855999noreply@blogger.comtag:blogger.com,1999:blog-3717133688018454834.post-36220290186817894212011-02-17T14:01:19.229+00:002011-02-17T14:01:19.229+00:00@tom - yeah I've read up on that kind of syste...@tom - yeah I've read up on that kind of system, but for me it's just too counter-intuitive to use on a Flash game. I like working with game object classes with methods, properties etc, rather than "data".Iainhttps://www.blogger.com/profile/16741682155796102883noreply@blogger.comtag:blogger.com,1999:blog-3717133688018454834.post-7773987695984447962011-02-17T13:53:16.521+00:002011-02-17T13:53:16.521+00:00I fully agree with you that there's no right a...I fully agree with you that there's no right and wrong way to do things. If you find a method you're happy with you should use it - you'll notice that I haven't actually told anyone not to use your approach - I actually like it.<br /><br />You can call my approach dependency injection if you want, but I would just call it passing references to resources. Dependency injection to me implies using containers, mxml tags, etc.<br /><br />Re. your point (1) - a Flixel object could still dispatch an AS3Signal. Anything can dispatch them without having to extend EventDispatcher, which is their beauty. But yes, all good frameworks should have a single base GameObject/Entity class.<br /><br />Re. your point (2) It doesn't matter who came up with the name your approach (appeal to authority?), it's still just some static vars in a class. Passing reference to a game instance rather than using a static class - to me - feels more OOP - you could have any number of games running simultaneously and they wouldn't clash. Obviously people might say it's not good practice to expose so many public properties, etc etc, but I think we're both agreed that this is about what works rather than what is "correct".<br /><br />Anyway Rich, we both know what we're doing - it's new developers who I think will find this discussion most useful.Iainhttps://www.blogger.com/profile/16741682155796102883noreply@blogger.comtag:blogger.com,1999:blog-3717133688018454834.post-5337878663620863382011-02-17T13:35:36.366+00:002011-02-17T13:35:36.366+00:00Communication between entities is one of the main ...Communication between entities is one of the main issues with the traditional flash game development. Your better off using a true entity system that side steps a lot of these issues. Here my post on the subject<br />http://www.tomseysdavies.com/2011/01/23/entity-systems/Unknownhttps://www.blogger.com/profile/04352981003960855999noreply@blogger.comtag:blogger.com,1999:blog-3717133688018454834.post-41248808919506917292011-02-17T13:28:31.092+00:002011-02-17T13:28:31.092+00:00So basically you use dependency injection, without...So basically you use dependency injection, without a DI container to maintain control and do the injecting :)<br /><br />Two things:<br /><br />1) My article was written for flixel specifically. Flixel objects don't (and can't) dispatch events. Which is just fine given the hit you take with events in AS3. With regard to the update / render calls you mention, that's exactly how flixel works. The FlxObject base type being the equivalent of your Entity.<br /><br />2) To say that using a service wrapper / Registry isn't a very OO way of coding (with added irony given who devised the pattern), yet passing in a reference to an entire games is, is a bit strange imho. It's like DI gone wild.<br /><br />When the games get large enough, or for multi-game suites especially, it's easily extended out into CommonRegistry, ActorRegistry, FxRegistry, etc. Very little code (if any) resides in them. There is no single "God class". The FX class in my example had just 3 methods in it. Had I needed lots more I would have looked at an FxManager instead, rather than triggering them directly. For that game however it was sufficient.<br /><br />A true Registry is a list of pointers, nothing more. The classes themselves are responsible for house-keeping, access permissions, etc (just like they are in the DI/local reference approach).<br /><br />We've used the multi-Registry approach on large game suites quite happily. We could easily have used a single well constructed DI container too. <br /><br />That's the beauty of coding isn't it. There's never just one "true" way to skin the cat.PhotonStormhttps://www.blogger.com/profile/05617379540181658659noreply@blogger.comtag:blogger.com,1999:blog-3717133688018454834.post-19964328739074671082011-02-17T13:15:51.159+00:002011-02-17T13:15:51.159+00:00Great comments guys. I really like the Registry ap...Great comments guys. I really like the Registry approach in a lot of ways, but a reference to the game itself is even more useful, surely? Just make your useful info - player, map, enemies etc public vars.<br /><br />Anyway, I think the main take-away from this post should be the Entity stuff :)Iainhttps://www.blogger.com/profile/16741682155796102883noreply@blogger.comtag:blogger.com,1999:blog-3717133688018454834.post-73097058113787552192011-02-17T13:15:10.999+00:002011-02-17T13:15:10.999+00:00Great stuff, Iain, thanks!Great stuff, Iain, thanks!MichaelJWhttp://gamedev.michaeljameswilliams.com/noreply@blogger.comtag:blogger.com,1999:blog-3717133688018454834.post-32719578638332327852011-02-17T13:01:15.253+00:002011-02-17T13:01:15.253+00:00I used to work in a similar way, passing variables...I used to work in a similar way, passing variables to what I thought classes *would* need, ie the player into the enemy class. But *what* and enemy needs may change in the course of development. This tight coupling that is created then needs to be reworked and all related classes re factored which can be a mayor headache.<br /><br />Using a *lookup* although it is slower and sometimes feels a bit messy (in terms of OOP) allows much more flexibility which to me is becoming most important when writing the code of games.AHOLLAnoreply@blogger.comtag:blogger.com,1999:blog-3717133688018454834.post-29929355856952732122011-02-17T12:51:05.407+00:002011-02-17T12:51:05.407+00:00With regard to you not using the Registry option, ...With regard to you not using the Registry option, surely what you are doing in this case is increasing the coupling and interdependencies between all the various objects in your game. This cannot be a good thing, if something goes wrong then you are going to have a crash (via a null pointer or whatever), if the registry entry isn't there you can continue without a crash <br /><br />That said I don't think the registry system works especially well, have a look at a blackboard approach instead. Or even better you could have a map of key->value which is type independent and so you wouldn't need a whole bunch of variables to get and set them. This is possible in C++ but I'm not sure if it is in what you are using. <br /><br />You could just have something like:<br /><br />var getRegistryValue(var key)<br />void setRegistryKey(var key, var value)<br />bool hasRegistryValue(var key)<br /><br /><br />You could store whatever you want in this. Reduces code bloat and if objects are missing you can handle it appropriately. <br /><br />Just a thought :)Parrotbaithttps://www.blogger.com/profile/11064934146295859361noreply@blogger.comtag:blogger.com,1999:blog-3717133688018454834.post-6848903880062248282011-02-17T12:05:32.003+00:002011-02-17T12:05:32.003+00:00That's very helpful Iain. Thank you.That's very helpful Iain. Thank you.Tahir Ahmedhttp://tahirahmed.wordpress.comnoreply@blogger.com