Jump to content

  • Log In with Google      Sign In   
  • Create Account

We're offering banner ads on our site from just $5!

1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


Don't forget to read Tuesday's email newsletter for your chance to win a free copy of Construct 2!


Recommended approaches to Data Handling?


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
2 replies to this topic

#1 CazHouse   Members   -  Reputation: 130

Like
0Likes
Like

Posted 07 February 2014 - 12:11 PM

My Question:

HOW do I efficiently collect data and keep it updated for later reference?

 

My Programming Background:

I am very new to programming and have chosen C# as my first language. I have been reading about it, watching tutorials, getting time behind the keyboard, and have been moving along pretty well. This has been over the last 6 months or so and I have (for the last month) been working on my first project. I am almost done with creating Pacman as my first attempt at something and it turned out better than expected. 

 

My Problem:

Looking back on my first (almost) completed project I was able to see a lot of places where my code was messy, and where data was either poorly passed or poorly maintained. I found that there are a lot of variables and values that I want to keep track of throughout my project because they are referenced deep in my code or referenced often throughout a class. Some examples are Screen Dimensions, Mouse Bounds, Player Position, etc. These values, so far, are pushed deep into the code through parameters and method calls and stored where they are needed. This seems cumbersome and poorly designed. I know that Delegates can be helpful in keeping values updated in other classes, but I am still confused as to how you get a delegate deep into a class hierarchy without having to reach all the way down and place it there just like placing the value itself to begin with. 

 

I feel like maybe having a static class that doesn't need to be passed or instantiated can help hold the data. If I keep that up to date I can just pull out those values wherever I want. I am not sure that this is practical, or ever possible the way I want to use it. I am really looking for better options or some guidance here. I have done a lot of research and have not found anything that helps me so far.

 

To make this even simpler, lets just discuss the first step; getting data from all over my project into 1 class without coupling, heavy parameter passing, and so on.

 

Say i want to make a class that displays all of my values that I am testing out on the screen. It shows mouse bounds (updated in an input class), player position (updated in an actor class), map position (updated in the level system), etc. These values that I want are scattered throughout my code. Some classes I want info from are deeply nested in other classes.


Edited by CazHouse, 07 February 2014 - 01:51 PM.


Sponsor:

#2 SeanMiddleditch   Members   -  Reputation: 6420

Like
1Likes
Like

Posted 07 February 2014 - 08:37 PM

I feel like maybe having a static class that doesn't need to be passed or instantiated can help hold the data. If I keep that up to date I can just pull out those values wherever I want. I am not sure that this is practical, or ever possible the way I want to use it. I am really looking for better options or some guidance here. I have done a lot of research and have not found anything that helps me so far.


This is actually pretty common. It's not without its problems but honestly most of those are fairly academic, especially in hobbyist game development. Plenty of big game engines have shipped with globals, which is essentially what a static class is used for.

A slightly more "proper" approach would be to use a service locator.

I'd personally go with the first approach up until you actually need something more complicated. "Keep it as simple as possible, but no simpler."

#3 CazHouse   Members   -  Reputation: 130

Like
0Likes
Like

Posted 08 February 2014 - 10:53 AM

A slightly more "proper" approach would be to use a service locator.

Awesome feedback man. I really appreciate it. This is exactly the kind of thing I was looking for. I can see though how it is a little overkill for the simplicity of the projects I am working on now, but I will start using it where I can as my projects grow larger. The hardest part for me so far in understanding it is what "services" are worth providing with this method. The article explains that to some degree but I want to make sure I don't go crazy with it and over use it either.






Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS