Jump to content
  • Advertisement
mrpeed

Is it bad design for one function to call other functions?

Recommended Posts

This function detects if a gameobject has moved or has had its sprite changed. It then calls one of two functions (or none), to draw a piece of the games background over the gameobjects current location or previous location. Should functions like this be avoided? Is this good or bad design? Does it violate SRP?

Also, how would something like this be unit tested?

#clean up the display...
def blit_background_over_dirty_rects(self):
		for gameobject, data in self.relevant_data.items():
			if data['location'] != gameobject.rect.topleft: #gameobject moved...
				self._blit_background_over_gameobjects_previous_location(gameobject)
			elif data['sprite'] != gameobject.sprite_manager.current_sprite: #gameobjects sprite changed...
				self._blit_background_over_gameobjects_current_location(gameobject)

 

Share this post


Link to post
Share on other sites
Advertisement

Code calls other code all the time.  That by itself is not an issue.

However, usually code should follow commands that do a bunch of work rather than micromanage the details of the work.  In your case it is probably faster to redraw everything with a single render command rather than to check every single object for details of if it happened to move.

 

Share this post


Link to post
Share on other sites

Agreed with frob.

It's quite normal for a function to call other functions.  We build functions to accomplish specific tasks and then put them together to create more complicated things happen.  If functions didn't call other functions it would be very difficult to compose complex programs in a nice way.

However, your specific design seems a little odd in this case.  Rather than each object updating and redrawing itself, you would more commonly update the logical position of all items (or all items within view if you've gotten far enough to be managing things off screen as well), and then redraw the entire screen with all objects in their updated positions.

Share this post


Link to post
Share on other sites

Is redrawing the entire screen every frame the common approach? Even if there are areas on the display that haven't changed? I'm using Pygame and I've read that you should only redraw the area of the screen that has been changed for performance reasons, though I'm not sure if this is unique to Pygame or even relevant to to Pygame anymore.

Share this post


Link to post
Share on other sites

OOP and Functional Programming are two different approaches to solving problems. OOP is just all the rage right now. What you are describing sounds like Functional Programming. You can read about it here:

http://www.codenewbie.org/blogs/object-oriented-programming-vs-functional-programming

I'm not a graphics expert but as far as I know most graphics APIs flip between two pieces of memory...the visible 'buffer' that is being rendered and the back 'buffer' that is redrawn all the time. When the API is done drawing on the back buffer it cycles the back buffer to the visible buffer. So point being...as long as you are redrawing the back buffer probably no issue.

Share this post


Link to post
Share on other sites
13 hours ago, mrpeed said:

Is redrawing the entire screen every frame the common approach? Even if there are areas on the display that haven't changed?

Yes.

 

13 hours ago, mrpeed said:

 I'm using Pygame and I've read that you should only redraw the area of the screen that has been changed for performance reasons

This is because Pygame is based on ancient technology that is embarrassingly out of date.

 

13 hours ago, mrpeed said:

I'm not sure if this is unique to Pygame or even relevant to to Pygame anymore

Pygame is one of the only systems that expects to draw to the screen using old technology. Pygame uses SDL 1.2.  SDL.1.2 uses DirectX 5, specifically DirectDraw for graphics. DirectX 5 is literally 20 years old, written for a time when a typical screen was 640x480 and graphics cards were esoteric add-on units.

Share this post


Link to post
Share on other sites

  • Advertisement
  • Advertisement
  • Popular Tags

  • Similar Content

    • By Hellados
      Hello guys, my name is Giorgi and i'm newbie game developer i'm learning Pixel art and after pixel art  i want learn C# and don't know how and where start i'm bad with programming language and know only HTML/CSS
    • By JoAndRoPo
      While going through a Game Design Document Template, I came across this heading - Core Game Loop & Core Mechanics Loop. 
      What's the difference? Can you provide some examples of an existing game?  Suppose if I am including these topics in a Game Design Document, how should I explain it so that my team can understand? 
    • By MelonCollie
      Hi Everyone,

      My name is Bob Pepek, I'm an audio post production engineer for film / TV. I'm looking to try my hand at Game Audio. Did you know that great sound design is rarely ever noticed but is always felt by an audience? That's where I can help.
      I've worked as the dialogue editor and sound designer for Sprout / NBC's Saturday morning cartoon Astroblast. I sound design for the web-series Channelate (hosted by Explosm / Cyanide and Happiness). Though most notably work as the go-to sound designer for the hundreds of the LEGO Star Wars / Marvel / Ninjago product animations and mini-movies.

      My past sound design clients include NBC, ESPN, LucasArts, LEGO, Sprout Network, Disney, Sci-Fi Network, Walmart,  Sesame Street, The list goes on and on! Below I've included a link to my demo reel as well as other projects I have done sound design for:

      Sound Design Reel
      https://vimeo.com/214093302

      Other Work (Channelate, Explainer Vids, Ads)
      meloncollieproductions.com/work/

      360 Sound Designs (LEGO Star Wars / Avengers: Infinity War)
      https://www.youtube.com/watch?v=-Gdss2fANPQ
      https://www.youtube.com/watch?v=mj7Leyaq780
      https://www.youtube.com/watch?v=LJzPu_tw6eY

      Recent Film Work:
      https://www.youtube.com/watch?v=hbFXobIMAgM
      https://vimeo.com/273203490
      https://vimeo.com/229448486

      If you're looking for a sound designer I'd love to help out! Feel free to reach out at bobpepek@gmail.com. 

      Cheers,
      Bob
    • By HomeBrewArcana
      Hey All,
      I'm looking to get into the gaming industry. I've skirted around the idea for a long time, always thinking that I couldn't do it. I've finally decided to take the plunge.
       
      My question is whether it's worth going to school for game design/coding etc. I've been writing content for paper games for a while, and have a good idea of story and some basic design. But I have next to no technical know how. 
       
      My instinct is that such things can be learned with a lot of practice, video tutorials, and more practice. I've also heard that a degree is not really that important, since you get hired based on your portfolio/prototypes. Why not just make the games?
      But won't a degree help with contacts and mentoring--I'm not a great networker.
       
      Of course, it'll plunge me into more debt, but...
      If anyone has advice, let me know. Also any idea of a program to start with: Game Maker, Unity, Godot, Construct, Stencyl--I've heard good things about them all, so much so that I don't know which would be best to start with!
       
      Thanks
    • By Luca Falco
      https://www.youtube.com/watch?v=UMoc52DEoC8     ABOUT THE GAME: Room54 is a first-person Horror/adventure  Videogame for pc,mac and linux users. the game is currently under development by a very small team, we put so much effort in this project and we are keep doing our best for that we are going to launch a kickstarter campaing in order to reach our ideal budget to complete the project, we hope the GameDev community can help us a lot                      STORY:   Daniel is a family father like many other, one day he decide with your wife and his daughter  to spend her winter holidays at their mountain house that they have recently buy in  mountain ,a  wonderful place surrounded by the nature of the woods,  Completely far away from the caotic city life. During their holidays Daniel and his family will understand that they are not welcome there and they will discover an  hided and disturbing part of the valley that they have never seen before                       GAMEPLAY:   You will play as Daniel, a father that will try to save his family, your gameplay will be focused on discovering secrets places around valley,investigating and trying to survive, you will find object that will help you solve enigma and to stay alive. The immersive audio and  environment will make you feel constantly follow by an high anxiety dose  during the game.                         SOCIAL PAGES:     Follow us to get the latest development news and insights     IndieDB:     http://www.indiedb.com/games/room54   Twitter:       https://twitter.com/Room54Thegame   facebook:   https://www.facebook.com/Room54/
    • By Gezu
      I'm a 3D artist with basically no music knowledge at all. I do love musics like some video games and films have. I have a Yamaha DGX-205 which wasn't used by anyone for a decade and I don't know why but this January I started to learn how to play some of the musics I like. I didn't know how to start and I ended up with trying to learn Trine Dragon Graveyard. It took me 5 month to be able to play this from the beginning to the end but I really enjoyed every second of the learning process.
      Since I was not satisfied with the piano sound of my DGX-205 I tried to connect it to my PC. It took me some time to figure out how I can make it work. The app which is mentioned in the manual is not supported anymore. I did some search and installed LMMS which absolutely did what I wanted (I mean now I have nice piano sound from my PC's speakers when I press the keys :D). After installing a program designed to make music I started to wonder if it is possible for me to create music?
      Right now I'm learning a track from Child of Light but the idea of learning how to compose is still in my mind. I know there are many experienced composer around here and I would like to ask for advice. How shall I start learning? Shall I wait and learn to play more music or is it a good idea to start right now? Where can I get good info on how to learn composing? I have no particular plan with composing I only want to do it for fun.
    • By Developer Dre Reid
      Hello fellow game devs I am seeking some answers to a somewhat simple question. Now I always thought that when a dev was going to work on a new game to publish he/she should keep some aspects secret infill time to release then he/she can give out needed information pertaining to the game to the public as a marketing tactic. However I had a discussion with other game devs who stated that my way was somewhat not right and the only reason I had such thoughts was due to me being a smaller indie dev who was afraid of having my idea stolen. 
      Therefore I would honestly like to know if my way was right or were the other devs correct. If I were to start working on a new game and give out information about it online via social media would I be risking my idea being stolen and it being made faster and better by another developer or team of developers. Am...Am I paranoid??? 
    • By shadow_archer
      hello!
      so i had this idea of a game i wanted to make that i had in mind for years and i wanted to try to execute it (at least partiality).
      problem is, i don't really know what kind of game style this game can fall under and i don't really know where to start learning sources and design wise :/ .
      i want to create a management style game and all the controls the user has are through a menu of some sort similar to this (this particular example is from a game called '911 operator' by jutsu games):

      to find more information about how i can create such a game i really want to know what's the name of this style of game, mostly GUI controlled game.
      aside from that i'm looking for a bit of advice,
      which engine would be best for such a game? i'm fluent in C++,C# and python so any game engine you can throw at me is great!
      are there any good sources to learn from before jumping into this kind of game, tutorials of some sort perhaps?
       
      thanks so much to anyone who answers, this really means a lot to me!
    • By ArzGamer
      Hey guys,
      So I’m trying to put a foot into the creative industry however, for the game tester jobs I’ve looked at they ask for you to have previous experience with quality assurance software which I don’t have. 
      [deleted by moderator]
    • By WooksMain
      Hey guys,
      I've now spent a good amount of time to finish my first Game. The software is as good as ready for a Release, however I'm not! I've come up with so many questions regarding the release of my first Game and i don't know who to ask them. My Questions/Problems are:
      1.Copyright
      Do i have to claim Copyright on my game, and if so, how do i do that?
      2.Company
      Do i have to create a Company to release the game (regarding the copyright and the taxation of the Patreon income [I'm living in Germany])
      3.Release Platform
      I'm yet not sure how i want to release my Game. As my budget is as of now limited to 0$ a free release-platform is the only way to go. I thought about Itch.io or launching an download-website just for this Game.
      I hope that you guys have some advices for me regarding these Questions. Please keep in mind that I am a 100% Rookie on this field and excuse me for all the times i sound like a complete idiot.
      I'm thankfull for any Answers!
       
      Cheers, Wooks
  • Advertisement
  • Popular Now

  • Forum Statistics

    • Total Topics
      631383
    • Total Posts
      2999688
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!