Deep Dives, Dots and Diagrams

Deep Dives, Dots and Diagrams

We’re going to try something a bit different this week; we’re going to do a bit of a deep dive on one of the systems I’ve been working on. It should be understandable for folks with no coding knowledge, so don’t be scared to read on! Normal blogging should resume next fortnight. I will give you a brief rundown on the last two weeks before we get into that though!

I’ve spent a lot of the last fortnight brushing up on some programming fundamentals. I was attempting to refresh myself on my entire games programming course in record time. It has been a wild ride. From the Dot Product to Path Prediction to Q-Learning, I’ve been stuffing as much information into my brain as I can.

You know what? It has been fantastic! I had forgotten the simple joy of learning things for the sake of learning. That endorphin rush when you go “OH!” and your world gets a little bit wider is addictive. I’ve loved every second.

So what of Strays? Well. I’ve been working on some less visual internal code I’m afraid. Namely the Event System. I’ve been building a flexible way of sending information to a bunch of places. Let’s take a closer look!

Deep Dive on the Event System:
There is a concept in programming called “clean code”. This amounts to writing code that is efficient, and easy to understand. It makes code easier to come back to, makes it easier for others to understand, and avoids unnecessary code bloating. It’s a huge topic that I cannot unpack in a single post! However, one of the concepts important to writing clean code is “Blackboxing”. This means making each section of your code a closed system, an isolated pocket that is independent of the rest of the codebase. For example, an Input System does not need to know about the Audio System.
There are a lot of practical reasons as to why this makes a lot of sense. The biggest one is that it avoids dependencies, and makes your code more flexible. It’s a lot easier to swap out an Input System if nothing else is relying on it being there! The problem then becomes, “Well what if I need to send another system a message?” That’s when things get complicated.

Lets take an example: When we are on the start screen of a game and press the A button to start a New Game, we need a few things to happen. We need the button to respond, to flash or give some visible cue that it has been pressed. We also would like it to make a sound, an audio cue. Most importantly, we want the game to start loading up the first level.

Ok, so let’s assume we want to do all of that from some “OnA” function. This might be a function on the button, or in the UI, or in some “Game Manager”. We’ll assume the latter for now. “OnA” will need to check the Input System every frame to see if you have pressed A. It will also need to know about the New Game button, so it can do the visual effect. Finally, it will need to know about the audio system so it can request it play a sound, and we will assume the loading happens in Game Manager. Let’s look at that:

This isn’t the worst example by any means, but you can already see, Game Manager needs to know about a lot of things, and we have arrows going in both directions. It could also be that the button controls the sound, so Buttons need to know about the Audio System and connect to the Game Manager, which might use the Audio System for background audio, and the input system detects volume changes so connects to the Audio System also and… you get the idea.

Instead, what if we had just one way of communicating between each of these systems? This is where an Event System comes in handy. The simplest method of using an event system is to have a list of Events, which could just be the text (or string, in programming) “A_Button_Pressed”, that other entities can ask to be told about. The Start Game Button, Game Manager, and Audio System will ask the Event System to tell them when the “A_Button_Pressed” event happens. Input System tells the Event System when that happens through a “Dispatch” function, then the Event System sends that message out. The Start Game Button receives that message, and flashes. Meanwhile the Game Manager and Audio System have also picked up that message, and start loading and play the correct sound respectively, all without knowledge of each other’s existence.

What’s more, thanks to a nifty coding concept called an “Interface” the Input System doesn’t even need to know that Game Manager, New Game Button and Audio System are those things; to the Input System they are just an “Event Receiver”. I won’t go into how exactly, but it is because the Event System doesn’t need to know that they are those types, it only needs to know that they can receive messages! Pretty nifty right?

Now the Input System doesn’t know about any system other than the Event System, the Event System only knows about Event Receivers, and nothing else is aware of anyone else’s existence! Our code is blackboxed, and we can still inform each system about tasks it needs to do!

So that’s basically what I’ve been working on. As you might imagine, my version is a little more complex than the above. For example, I want to package data with my event, so I need to account for data being sent around. But the principle is largely the same!

Anyway, that about does it for this post. I’m hoping to return to the more visual blogs I’ve been striving for of late soon. Until then,

Matt out.

55 thoughts on “Deep Dives, Dots and Diagrams

  1. I don’t think the title of your article matches the content lol. Just kidding, mainly because I had some doubts after reading the article.

  2. Good – I should certainly pronounce, impressed with your web site. I had no trouble navigating through all the tabs and related information ended up being truly easy to do to access. I recently found what I hoped for before you know it at all. Reasonably unusual. Is likely to appreciate it for those who add forums or something, website theme . a tones way for your client to communicate. Excellent task..

  3. Can you be more specific about the content of your article? After reading it, I still have some doubts. Hope you can help me.

  4. Whats up very cool site!! Guy .. Beautiful .. Wonderful .. I’ll bookmark your blog and take the feeds alsoKI am glad to seek out so many helpful information right here within the submit, we need develop extra strategies in this regard, thanks for sharing. . . . . .

  5. Hello There. I found your weblog using msn. This is a really well written article. I will be sure to bookmark it and come back to learn more of your helpful information. Thank you for the post. I will definitely return.

  6. The other day, while I was at work, my cousin stole my iPad and tested to see if it can survive a forty foot drop, just so she can be a youtube sensation. My apple ipad is now broken and she has 83 views. I know this is totally off topic but I had to share it with someone!

  7. I like the helpful info you provide in your articles. I’ll bookmark your weblog and check again here regularly. I’m quite certain I will learn lots of new stuff right here! Best of luck for the next!

  8. Thank you for your sharing. I am worried that I lack creative ideas. It is your article that makes me full of hope. Thank you. But, I have a question, can you help me?

  9. I was very pleased to find this internet-site.I wished to thanks for your time for this glorious learn!! I undoubtedly having fun with each little little bit of it and I’ve you bookmarked to take a look at new stuff you blog post.

  10. Greetings from Florida! I’m bored to death at work so I decided to check out your blog on my iphone during lunch break. I really like the info you provide here and can’t wait to take a look when I get home. I’m amazed at how quick your blog loaded on my mobile .. I’m not even using WIFI, just 3G .. Anyhow, great blog!

  11. I was very pleased to find this web-site.I wanted to thanks for your time for this wonderful read!! I definitely enjoying every little bit of it and I have you bookmarked to check out new stuff you blog post.

  12. I wish to express my appreciation to this writer for rescuing me from such a dilemma. Because of scouting through the world-wide-web and finding basics that were not pleasant, I was thinking my entire life was done. Living without the presence of strategies to the issues you’ve solved all through this report is a serious case, and the ones which could have negatively affected my entire career if I hadn’t noticed your blog. Your personal natural talent and kindness in playing with every aspect was vital. I don’t know what I would have done if I hadn’t encountered such a stuff like this. It’s possible to at this moment look ahead to my future. Thanks a lot so much for your professional and result oriented help. I won’t hesitate to endorse the sites to anybody who wants and needs care on this issue.

  13. I’ve been exploring for a little bit for any high-quality articles or blog posts on this sort of area . Exploring in Yahoo I at last stumbled upon this web site. Reading this info So i am happy to convey that I have a very good uncanny feeling I discovered just what I needed. I most certainly will make certain to don’t forget this site and give it a glance on a constant basis.

  14. When I originally commented I clicked the -Notify me when new comments are added- checkbox and now each time a comment is added I get four emails with the same comment. Is there any way you can remove me from that service? Thanks!

  15. Fantastic site. Lots of helpful information here. I am sending it to several buddies ans also sharing in delicious. And certainly, thanks to your effort!

  16. Hey, you used to write magnificent, but the last several posts have been kinda boring?K I miss your super writings. Past few posts are just a little bit out of track! come on!

  17. I have been exploring for a little for any high quality articles or blog posts in this sort of space . Exploring in Yahoo I at last stumbled upon this website. Reading this information So i am glad to convey that I’ve an incredibly good uncanny feeling I came upon just what I needed. I so much indubitably will make sure to do not put out of your mind this site and provides it a look regularly.

  18. I happen to be commenting to let you be aware of what a really good discovery my cousin’s child developed reading through your blog. She picked up such a lot of details, which included what it’s like to possess an excellent teaching heart to let other individuals clearly comprehend chosen complex topics. You really surpassed her expectations. I appreciate you for displaying such insightful, trustworthy, explanatory not to mention cool guidance on the topic to Janet.

  19. Hi! I just wanted to ask if you ever have any problems with hackers? My last blog (wordpress) was hacked and I ended up losing a few months of hard work due to no back up. Do you have any methods to protect against hackers?

  20. hi!,I like your writing very much! share we communicate more about your post on AOL? I need a specialist on this area to solve my problem. Maybe that’s you! Looking forward to see you.

  21. An impressive share, I just given this onto a colleague who was doing a little analysis on this. And he in fact bought me breakfast because I found it for him.. smile. So let me reword that: Thnx for the treat! But yeah Thnkx for spending the time to discuss this, I feel strongly about it and love reading more on this topic. If possible, as you become expertise, would you mind updating your blog with more details? It is highly helpful for me. Big thumb up for this blog post!

  22. Explore a wide range of unique cycling gear, including jerseys, bib shorts, and custom designs. Perfect for every cyclist, from casual riders to pros. High-quality materials, standout designs, and options for personalization make it easy to find the perfect fit for you or your team. Shop now and ride in style!

  23. BWER is Iraq’s go-to provider for weighbridges, ensuring durability, accuracy, and cost-efficiency in all weighing solutions, backed by exceptional customer support and maintenance services.

  24. Im not positive the place you’re getting your info, but great topic. I needs to spend some time finding out much more or understanding more. Thank you for excellent information I used to be looking for this info for my mission.

  25. Hello! I’ve been following your web site for a long time now and finally got the bravery to go ahead and give you a shout out from Houston Tx! Just wanted to tell you keep up the great job!

  26. Great beat ! I would like to apprentice even as you amend your web site, how can i subscribe for a blog website? The account helped me a appropriate deal. I have been tiny bit acquainted of this your broadcast provided vibrant clear idea

  27. This web site is really a walk-through for all of the info you wanted about this and didn’t know who to ask. Glimpse here, and you’ll definitely discover it.

Leave a Reply

Your email address will not be published. Required fields are marked *

Back to top