Solving the tree problem

posted in KrisWolfe
Published May 08, 2019
Advertisement

So, I think I've designed a possible solution to my tree problem.

First off, I really like C#. My background when I was young was C++, and learning data structures and pointers was interesting. I did really well with assembly language, and enjoyed those kind of recursive things. But I never kept up with coding, and now here I am much older and way behind. Object oriented programming had just becoming a thing back when I was coding, and until a few months ago I had no idea what it was.

I started doing some coding with javascript a few years ago, and let me tell you, that's one of the worst languages to start in. Now that I know what a strongly typed language is, having the compiler interpret what you want to do leads to so many obscure bugs it's crazy. With C#, if I make an error, I know exactly where the problem is most of the time. I haven't really run into any huge logic bugs I couldn't track down.

One of my favorite parts of C# is that practically everything is a reference. Keeping track of pointers in C++ was a pain, but C# does it so naturally and intuitively. I absolutely love it.

So now we get to the solution part. I don't know if C++ had events and delegates back when I was coding, but this is a dream. Because of how they work, I don't even care about animations or sounds in the game, because I know I can just go find the method that I want a sound to play and throw in an event code and plug it into my audio, or animation. It makes things so painless.

We have quite a few objects interacting with this hierarchy tree. First off, we have the employee objects themselves, that hold all the data I need to interact with the economy. Salary, jobtype, skills, hunger, cash, so forth. When we load the screen, we have to spawn an "Employee Card", which is the visual layer for the user. The card doesn't care what the data is, it just has a "data container" for the employee...or a pointer. The Employee card is draggable. When they don't have a job assigned, their just idle, and sit on the bottom panel. There's really only two things you can do with an employee card on the hierarchy screen: Drag the card to an employee slot or the idle panel. Right now, I can drag it anywhere, but I'll cut off that hippie golbydygook user freedom later.

The next object we have going on is the employee slot, and I think this is where most of the logic is going to happen. I don't the card really cares what happens to it or where it goes. But the employee slot DOES, because on the display, I want you to be able to grow the tree...in order to do that we need empty slots spawned...and we're going to have to do it for each manager.

So if the CEO has two managers, and those managers have 4 employees each, then we're going to need the CEO to have an empty manager slot next to the two managers so you can hire a new manager, and then each manager will have an extra employee slot in order to grow their trees.

But, if I drag someone in, we're going to need to spawn another empty employee slot next to it. And it has to know where to spawn. in the opposite vein, if I drag out an employee or manager, then they're going to have to despawn the empty employee slot, since there would be two, and I only want 1. And if you drag out a manager, I want the employees to reattach themselves to a different manager.

On top of all that, I currently display things by spawning all the objects. So when I do I refresh the display? I also don't think it's wise to continuously spawn and despawn all these objects everytime something moves slightly.

So for the display, I'm going to be doing some spawning pools. The cards and slots and lines aren't unique, and this will help performance. I'll need 3 different spawning pools.

The card slots will have event listeners on them, waiting for the employee that they're holding moves. If we drag an employee to them, then we register our delegates and then attach them and then have that slot's manager spawn a new empty slot.

I think all of this will work pretty well. I can think of a few edge cases off the top of my head, but I can get most of this up and running this weekend hopefully. I think making the tree itself will likely be the hardest part of the hierarchy screen.

0 likes 0 comments

Comments

Nobody has left a comment. You can be the first!
You must log in to join the conversation.
Don't have a GameDev.net account? Sign up!
Profile
Author
Advertisement
Advertisement