Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
roomforthetuna
Mar 22, 2005

I don't need to know anything about virii! My CUSTOM PROGRAM keeps me protected! It's not like they'll try to come in through the Internet or something!

Orzo posted:

The anchor is always the center of the rectangle. Thanks for the input, seems like the solution to every problem is 'convert it to local coordinates' and work from there. Any other suggestions are welcome, I suppose I'll mess around with this on paper.
Well if the anchor is the center when you're scaling as well then you won't need to get the position out from your function, because that won't change - only sx and sy will change. Probably still easiest to convert to local coordinates first to get your new sx and sy, though.

Adbot
ADBOT LOVES YOU

Orzo
Sep 3, 2004

IT! IT is confusing! Say your goddamn pronouns!
Not true, dragging one vertex moves the center towards that vertex by half the amount.

e.g. a rectangle defined by (0,0) - (4,4) with no rotation, drag (4,4) to (8,8) and the center moves from (2,2) to (4,4)

roomforthetuna
Mar 22, 2005

I don't need to know anything about virii! My CUSTOM PROGRAM keeps me protected! It's not like they'll try to come in through the Internet or something!
If that's how you choose to do it, sure. Doesn't seem like a great idea to have objects anchored by their center in every context except scaling, though.

My way, if your rectangle was (0,0) - (4,4) with no rotation, if you drag (4,4) to (8,8) then the new rectangle would be (-4,-4) - (8,8)

The downside of my way is you can't scale by a single pixel, the upside is you get a consistent interface where rotations, scalings and positionings are all based on the center. (And it's marginally less effort to code because it's consistent.)

Orzo
Sep 3, 2004

IT! IT is confusing! Say your goddamn pronouns!
I don't understand what mean by 'except scaling'. The objects are defined by a center point, two rectangle edge sizes, and a rotation. This is the way the data is stored and has nothing to do with the level editor itself.

You also seem to be suggesting that if a user drags one vertex, the opposite one moves by itself. This is exactly the behavior that I don't want, nor do I think anyone else would be happy with it.

roomforthetuna
Mar 22, 2005

I don't need to know anything about virii! My CUSTOM PROGRAM keeps me protected! It's not like they'll try to come in through the Internet or something!
By "except scaling" I mean when you rotate the thing in the editor it's going to be rotating around the center point. When you move it, you're going to be moving it by the center point. When you scale it is the only time you're going to be interacting with it as if it's not anchored on its center point.

But if you don't think your users will like it scaled from the center then don't scale it from the center, that's fine. I don't know what sort of entities you're considering - for me, I would rather game-monsters and other such moving objects scale from the center, but if I was making floors and things I'd probably want them to scale from the ... hell, I don't know, nothing really makes consistent sense for floors, because you'd want them to anchor from the other 'surface' side, while moving the surface, but that would give you no interface for thickening a piece of floor. So I wouldn't care between center or opposite-corner scaling, they'd both be equally frustrating.

Orzo
Sep 3, 2004

IT! IT is confusing! Say your goddamn pronouns!
You make a good point, but indeed this is primarily for floors, walls, etc. I want to easily be able to drag vertices and have them snap to the grid, but I don't want to change a perfectly good data model.

Pfhreak
Jan 30, 2004

Frog Blast The Vent Core!
Wow, I just discovered Unity. I had heard you guys talking about it before, but never thought to give it much of a go. I guess I was stuck in that programmer, "Pfff... I'll just write it myself" mindset. You can probably guess the number of projects I've started that ended as soon as I had to figure out how to handle things like 'animation' or 'complexity of any kind.'

I'm looking for some good resources on getting started, particularly those targeted at C# developers. The community is pretty good, but I thought I'd poke my nose in here as well.

roomforthetuna
Mar 22, 2005

I don't need to know anything about virii! My CUSTOM PROGRAM keeps me protected! It's not like they'll try to come in through the Internet or something!

Orzo posted:

You make a good point, but indeed this is primarily for floors, walls, etc. I want to easily be able to drag vertices and have them snap to the grid, but I don't want to change a perfectly good data model.
Are you really sure you don't want to make the entities arbitrary quads for that? Most often when you're making a game floor you really want to be able to skew a lot more than you want to rotate, as in the shape
code:
     ____
    /
___/ ____
    /
___/
Rotating for an angle-floor like that gives you overlap at the top and a wedge-gap at the bottom, where skewing would work fine. (But of course, again, I don't know what your maps are like, rotation will be fine if it's mostly open space.)

Orzo
Sep 3, 2004

IT! IT is confusing! Say your goddamn pronouns!
I think the data model will allow for skewing as well, it just won't play as nice with resizing and snapping to the grid during editing. I understand what you're saying about skewing, but for your example, I'd rather just use two triangles and a square in the middle (a triangle will be a quad that (A) has half transparency and (B) has an underlying intersection model that's a triangle, rather than a rectangle). Not only is this a bit easier to work with, but I feel like a skewed floor would give you uglier graphics, while dedicated 'corner' sprites for the slope would end up looking better.

roomforthetuna
Mar 22, 2005

I don't need to know anything about virii! My CUSTOM PROGRAM keeps me protected! It's not like they'll try to come in through the Internet or something!
Fair enough, good to see you've considered it, and you're right that (for steep slopes at least) dedicated shaping sprites will look a lot nicer.

ambushsabre
Sep 1, 2009

It's...it's not shutting down!

Pfhreak posted:

Wow, I just discovered Unity. I had heard you guys talking about it before, but never thought to give it much of a go. I guess I was stuck in that programmer, "Pfff... I'll just write it myself" mindset. You can probably guess the number of projects I've started that ended as soon as I had to figure out how to handle things like 'animation' or 'complexity of any kind.'

I'm looking for some good resources on getting started, particularly those targeted at C# developers. The community is pretty good, but I thought I'd poke my nose in here as well.

Woah, I think you might be me (and several other people reading these threads as well. I really want to get into Unity, but I always have trouble due to the lack of a good project or resources or something else. Maybe we could get in touch and help each-other out a little bit.

Orzo
Sep 3, 2004

IT! IT is confusing! Say your goddamn pronouns!

roomforthetuna posted:

Fair enough, good to see you've considered it, and you're right that (for steep slopes at least) dedicated shaping sprites will look a lot nicer.
You know what, the more I think about it, the more I'm considering a quad a set of 4 arbitrary vertices rather than my existing model. I don't know. I hate this part, since it's such a radical change.

Your Computer
Oct 3, 2008




Grimey Drawer

ambushsabre posted:

Woah, I think you might be me (and several other people reading these threads as well. I really want to get into Unity, but I always have trouble due to the lack of a good project or resources or something else. Maybe we could get in touch and help each-other out a little bit.

That pretty much describes me as well. Been wanting to get into Unity, but I'm completely void of any imagination at the moment so I pretty much sit down and go "okay, today I'll try making... uh.. nevermind".

I do 3D character modelling too, so I could even try whipping up some resources if that sounds interesting! :)

Pfhreak
Jan 30, 2004

Frog Blast The Vent Core!
I hesitate to start a collaborative project with goons, we know how those end... But it might be fun to all try and build a similar style of game together and share some of the pains and Aha! moments. My friend and I were going to start with a shmup, maybe with an aquatic theme because shmups are pretty basic games. So I'd invite you both to get started with one as well.

The issue I'm running into with Unity is that there doesn't seem to be a consistent user story for how to appropriately collaborate with the free version. I'm used to working with SVN, but all the resources I've found online suggest that SVN and Unity do not play well together. People have been suggesting dropbox as well, but others suggest that is a maniac idea.

The 'team' I'll be a part of is just me doing developing and my friend doing modelling and sound, so we won't be walking over each other as far as assets are concerned. Does anyone have a decent collaboration workflow for Unity out there? (Or can assuage my fears about using SVN?) Ideally the workflow will have a minimum number of steps, as my artist friend isn't necessarily as savvy to source control as I am.

Hover
Jun 14, 2003

Your post hits a tree.
The tree is an ent.
The tree is angry.

Pfhreak posted:

The issue I'm running into with Unity is that there doesn't seem to be a consistent user story for how to appropriately collaborate with the free version. I'm used to working with SVN, but all the resources I've found online suggest that SVN and Unity do not play well together. People have been suggesting dropbox as well, but others suggest that is a maniac idea.

Just dropping in quickly to give my advice regarding SVN and Unity.

I worked on a project of 7 people using Unity and SVN and the only caveat was there was a folder called "Library" that contained a bunch of weird Unity-specific files that caused some sort of mess. I didn't personally look into it so I don't know all the specifics, but we got around it apparently by zipping up the Library folder whenever we made changes that affected it and everyone could unzip it on their end. It was kind of a pain in the rear end, especially because only one person could make "library" changes at a time, but it might be a decent solution for a dynamic duo instead of a sizable team.

nibe
Feb 23, 2008
I'm trying to figure out the best way to tell my UI system what a button should do when it is clicked. Right now the button has a delegate member that is assigned during construction and called when the button is clicked. Currently the delegate has no arguments, but I want to add buttons that will need at least one parameter for the click event. This would require delegates with new signatures, some code to tell which signature to use, fields for the different possible parameter types...it feels like there should be a better way to do this. I could probably use a catch-all signature that would have nulls passed to unneeded parameters, but I still feel like I'm missing something.

POKEMAN SAM
Jul 8, 2004

nibe posted:

I'm trying to figure out the best way to tell my UI system what a button should do when it is clicked. Right now the button has a delegate member that is assigned during construction and called when the button is clicked. Currently the delegate has no arguments, but I want to add buttons that will need at least one parameter for the click event. This would require delegates with new signatures, some code to tell which signature to use, fields for the different possible parameter types...it feels like there should be a better way to do this. I could probably use a catch-all signature that would have nulls passed to unneeded parameters, but I still feel like I'm missing something.

Why would two different buttons need two different delegate patterns? Also, this is why WinForms uses the pattern where the delegates look like void MyClickHandler (object button, ClickEventArgs args) so that you can change ClickEventArgs to add new fields, etc., without having to change the delegate pattern.

nibe
Feb 23, 2008

Ugg boots posted:

Why would two different buttons need two different delegate patterns? Also, this is why WinForms uses the pattern where the delegates look like void MyClickHandler (object button, ClickEventArgs args) so that you can change ClickEventArgs to add new fields, etc., without having to change the delegate pattern.
One button might perform a simple function that doesn't need any arguments, and another button might "spawn x," where I would like to pass x to the delegate. I don't know much about delegates and how you're supposed to use them so I could be doing it wrong. I haven't used WinForms, but that pattern seems like a better version of my catch-all idea.

But maybe I just need to understand delegates better. In your example, why is the button passed in the function? In my code the definition of the delegate is in the Button class, and I create functions elsewhere that are passed to the Button on instantiation, and stored in the delegate. As I mentioned, they don't have any parameters right now. When the Button decides it was clicked, it calls its delegate. Based on what you posted, it looks like WinForms does it differently.

Bizarro Buddha
Feb 11, 2007
The best way to handle something like this depends partly on what language support you have for various things. Are you working in C#?

Madox
Oct 25, 2004
Recedite, plebes!

nibe posted:

One button might perform a simple function that doesn't need any arguments, and another button might "spawn x," where I would like to pass x to the delegate. I don't know much about delegates and how you're supposed to use them so I could be doing it wrong. I haven't used WinForms, but that pattern seems like a better version of my catch-all idea.

But maybe I just need to understand delegates better. In your example, why is the button passed in the function? In my code the definition of the delegate is in the Button class, and I create functions elsewhere that are passed to the Button on instantiation, and stored in the delegate. As I mentioned, they don't have any parameters right now. When the Button decides it was clicked, it calls its delegate. Based on what you posted, it looks like WinForms does it differently.

I've written my own UI (twice) for windows and xbox, so I can try to answer some.

Often passing the button in to the function isn't useful and you can ignore it, but sometimes you want to have different behaviour based on which button was used to trigger the delegate (maybe theres 2 or 3 buttons for the same task in various windows). Or you might want to adjust the button to display some indication that an action was recieved.

All of my widgets are set up to fire events which have an event code, and a parameter struct much like the ClickEventArgs example above. When a button is clicked, it tells a global EventManager to trigger event X, which in turns notifies anything that wants to be told about event X's (typical producer/consumer deal). This lets the widgets not really care about what object they need to be hooked up to etc.

haveblue
Aug 15, 2005



Toilet Rascal
It will also help you a lot, if you haven't done it, to give the button its own ability to do basic state changes in response to clicks (changing highlight or image, etc) and handle mousedown/tracking rect/mouseup or cancel rather than trying to handle all that in backend code.

Orzo
Sep 3, 2004

IT! IT is confusing! Say your goddamn pronouns!

nibe posted:

One button might perform a simple function that doesn't need any arguments, and another button might "spawn x," where I would like to pass x to the delegate.

If button #1 does something that doesn't need X and button #2 does something that does need X, X should be part of the scope of the code subscribing to the click event, not part of the delegate signature.

For example:
code:
Thing x = new Thing();
Button b1 = new Button();
b1.Click += delegate { Console.WriteLine("hello"); };

Button b2 = new Button();
b2.Click += delegate { x.PerformAction(); };

quote:

But maybe I just need to understand delegates better. In your example, why is the button passed in the function? In my code the definition of the delegate is in the Button class, and I create functions elsewhere that are passed to the Button on instantiation, and stored in the delegate. As I mentioned, they don't have any parameters right now. When the Button decides it was clicked, it calls its delegate. Based on what you posted, it looks like WinForms does it differently.
You're right, Winforms does do it differently, and it does it badly. There's really no reason why you ever need 'object sender' as part of the delegate signature, nor is there any reason why you need useless EventArgs that don't do anything. The delegate signature should be providing useful context about the event. For example, the MouseDown event in Winforms does have useful information, such as which button was clicked, and the X and Y coordinates where the click occured. For simple button clicks, your delegate signature should be empty, unless you want to differentiate which mouse button was clicked or what coordinate of the button was clicked, etc.

Hopefully this makes sense, I can clear it up more if you want. In general though the Winforms event handlers are poorly designed and I don't blame you for being confused about designing your own delegates when Winforms are your reference.

nibe
Feb 23, 2008

Bizarro Buddha posted:

The best way to handle something like this depends partly on what language support you have for various things. Are you working in C#?
Yeah it's C#.

Orzo posted:

Hopefully this makes sense, I can clear it up more if you want. In general though the Winforms event handlers are poorly designed and I don't blame you for being confused about designing your own delegates when Winforms are your reference.
Well as I said I've never actually used WinForms, I'm not really going on any reference since I haven't found any really good UI system design resources. I may not have been clear, but going off your code, what if I had a bunch of buttons that wanted to call x.PerformAction(); but with different things for x? In my case the function is more than one line and I want to avoid copying it for each Button that does a similar thing. So I would treat the delegate more like a normal function in that I would send some game object parameter about which type of object to spawn as opposed to click coordinates or mouse buttons. Something like this:
code:
// in a class where buttons are created
void Spawn(string type)
{
    state.Add(new Thing(type));
}

b1.Click = Spawn;
b1.clickArg = "apple";
b2.Click = Spawn;
b2.clickArg = "orange";

// in the button class
delegate ButtonAction(string arg);
ButtonAction Click;
string clickArg;
...
if (mouseOver && clickReleased)
    Click(clickArg);
This isn't exactly how my stuff works but hopefully it will indicate whether I'm on the right track or not. Now, for a Button that closes its parent window, it doesn't need that parameter of course. And for a different group of Buttons I might need a different type of parameter, which brings me back to my original question.


edit: vvv Oh, I get it now, ok. That would work.

nibe fucked around with this message at 21:30 on Jan 14, 2011

Bizarro Buddha
Feb 11, 2007
Orzo is right that lambdas are a good way to do this. That means that your delegate type will take no arguments, but you dynamically generate new functions to set as delegates on buttons.

code:
// in a class where buttons are created
void Spawn(string type)
{
    state.Add(new Thing(type));
}

b1.Click = () => { Spawn("apple"); };
b2.Click = () => { Spawn("orange"); };

// in the button class
delegate ButtonAction( );
ButtonAction Click;
...
if (mouseOver && clickReleased)
    Click();

BonoMan
Feb 20, 2002

Jade Ear Joe
I'm sure this is a typical and overdone question, but here goes.

So we want to make a game. We have plans for a larger game (still a relatively simple one, but may involve some basic 3D), but for now to get started we are making a simple War style card game. Just to get some work under our belt. The problem is we're all artists...so we have the art down, but I figured I'd give my hand at coding a simple game. I'm not a programmer, but I have some very rudimentary understanding of code so the concept itself isn't utterly foreign to me.

The War game is our proof of concept and we wanted to do it for phones/windows. I decided that XNA/App Hub was the way to go since it seems to have a decent ecosystem to learn in. I installed all the tools they offer but goddamn I just don't even know what's what. Am I utterly doomed? Is there somewhere that gives a good actual beginners walk through to this stuff?

Should I just hire actual programmers?


edit: As a further example of what I'm asking for...Channel9.com has a good video series/course about making your very first Windows Phone 7 app.

http://channel9.msdn.com/Series/Windows-Phone-7-Development-for-Absolute-Beginners/Series-Introduction

It really is for "absolute beginners" and basically treats you like a baby at first. That's what I need. I'm sure that series will help generally, but I'm looking for something a little more game related.

BonoMan fucked around with this message at 02:15 on Jan 17, 2011

iopred
Aug 14, 2005

Heli Attack!

BonoMan posted:

Should I just hire actual programmers?

As a designer what would you think if I said something like:

I have made a game, the functionality is all there but it doesn't look very pretty. I'm thinking of buying photoshop and playing around. I'm looking for some tutorials on the web that'll show me how to make some art, step by step. I think with a few months of messing around my art will be good enough.


You'd be thinking 'oh god he has no idea what is involved in making things look good', and my art would probably be garbage.

BonoMan
Feb 20, 2002

Jade Ear Joe

iopred posted:

As a designer what would you think if I said something like:

I have made a game, the functionality is all there but it doesn't look very pretty. I'm thinking of buying photoshop and playing around. I'm looking for some tutorials on the web that'll show me how to make some art, step by step. I think with a few months of messing around my art will be good enough.


You'd be thinking 'oh god he has no idea what is involved in making things look good', and my art would probably be garbage.

Yeah true. But since it wasn't completely foreign to me and something I wanted to try, I figured I'd give it a shot.

And by give it a shot I mean spend a considerable amount of time trying to learn. I'm talking year or two...not months.

Vino
Aug 11, 2010
If your goal is to make money then I think you should keep your team small. 3 people max, really. Otherwise it's tougher to communicate between multiple people who have different levels of involvement and motivation, people start fighting eventually about who owns what, drama unfolds, yadeya. If you can manage with a smaller group than that's smart and when the money comes in you'll have less mouths to feed. That ship may have already sailed for your project though.

If it's just for fun though then yeah "hire" a programmer.

BonoMan
Feb 20, 2002

Jade Ear Joe

Vino posted:

If your goal is to make money then I think you should keep your team small. 3 people max, really. Otherwise it's tougher to communicate between multiple people who have different levels of involvement and motivation, people start fighting eventually about who owns what, drama unfolds, yadeya. If you can manage with a smaller group than that's smart and when the money comes in you'll have less mouths to feed. That ship may have already sailed for your project though.

If it's just for fun though then yeah "hire" a programmer.

Yeah it's really just for fun and experience. The team is only 3 or 4 people and it's honestly just a supplemental thing to a larger (already handled) project.

brian
Sep 11, 2001
I obtained this title through beard tax.

Just use Unity3D, it's pretty easy to get into and is designed to be easy to get into, I know at least 3 different ex or current industry artists who have made their own games through it, including one who had a lot of success as an indie with an iOS title. It costs money to get iPhone or Android licenses though and a significantly larger sum to get the Pro version and the pro versions of the smartphone export stuff.

I think the idea that you need dedicated programmers for hobby projects that don't have some tech basis is rapidly becoming outdated, it just requires the people taking over that role to put in more work than someone who's heavily experienced in it. You can totally avoid a large majority of the complicated 3D math, specific API and optimisation knowledge thanks to prebuilt solutions like Unity or Shiva or even flixel/flashpunk.

BonoMan
Feb 20, 2002

Jade Ear Joe
Oh wow. Totally going to look into that. Could be just what we need! Thanks a ton!

HappyHippo
Nov 19, 2003
Do you have an Air Miles Card?
I've got a problem that seems to come up a lot. I'll explain the latest example:

So I've got a game with several player teams. Each team has some cities, and some units. And of course the game takes place on a map with tiles.

The teams keep track of which units and cities they own. The units and cities keep track of which tiles they're on.

Now let's say I have a unit, and I want to know what team its on. One solution would be to look through every unit of every team until I find a match, but that introduces performance issues. More importantly, it requires that I pass around the master list of teams to everything that's going to require this information, or some class which holds the list and can do the look up, which is just very messy and annoying. Add to this the looking up of city teams, and what units and cities are on a given tile, and it gets messy pretty fast.

Another solution would be to have every unit remember what team it's on, but that lets bugs creep in because it's possible for the program to be in a state where the unit thinks it's part of team A while team A doesn't think it owns the unit. If I'm careful this won't happen, but the possibility is there, especially with the unit - tile relationship and the units moving around and dieing.

This seems like a fairly common class of problem that I've run into. I've got four examples of it in this one program (Unit-Team, City-Team, Unit-Tile, City-Tile), and I've ran into it before, usually using one of the above two solutions. I'm thinking about some better ways to solve this with interfaces, but before I go for that I figured it would be a good idea to post about it here to see if anyone else has encountered this and how they solved it, or if they have any ideas.

ynohtna
Feb 16, 2007

backwoods compatible
Illegal Hen
Pretty much every non-trivial game engine ends up with lots of parallel data structures affording optimised lookup of entity relationships (spatial, logical, structural, behavioural, resource usage, etc).

Keeping track of these to ensure the indices/references don't get muddled is one of the inescapable challenges. Unit tests are your friend here.

Orzo
Sep 3, 2004

IT! IT is confusing! Say your goddamn pronouns!
It seems like the problem is something unit tests wouldn't be so great at covering--namely, if Team A has a reference to Unit X and some data structure elsewhere indicates that Unit X doesn't have a reference Team A, there's a bug. And it sounds like an integration bug.

Although I don't have too much experience with this type of thing, it sounds like the biggest concern is that client code might introduce an error--for example, you might transfer a unit from Team A to Team B and forget to update the additional data structures. To solve this problem, you might want to introduce some sort of manager through which ALL of these operations are performed, so that you won't (and can't) 'forget' to update the extra structures.

roomforthetuna
Mar 22, 2005

I don't need to know anything about virii! My CUSTOM PROGRAM keeps me protected! It's not like they'll try to come in through the Internet or something!

HappyHippo posted:

Another solution would be to have every unit remember what team it's on, but that lets bugs creep in because it's possible for the program to be in a state where the unit thinks it's part of team A while team A doesn't think it owns the unit. If I'm careful this won't happen, but the possibility is there, especially with the unit - tile relationship and the units moving around and dieing.
Isn't it a worse bug to have team A not think it owns the unit when it actually should, and that's the only data on the subject? If your data isn't being updated properly then bugs can creep in even if you only store the data one way.

It does give you more opportunity for bugs if every time something updates it has to be updated in five different places, but you should be boiling that update action down into one function anyway.

Also, it seems weird to me to have teams bother to remember what units are on them - when do you need to do an action on an entire team? Is it really critical that such a lookup not be a mere 6 times slower [do you have 6 teams?] It makes a lot more sense to me to have the unit store what team it's on, because that's the way round you'd be needing to check most often. (eg. when you click a unit, you'd first find the unit hopefully from some sort of location-based lookup, then you'd need to know what team it's on.)

The only reason I can think of to have the team store a list too is if there's a big performance saving during rendering by rendering all the guys with color scheme A first then all the guys with color scheme B, saving on changing a setting back and forth - and I really don't think the performance loss of just going through the whole list of units 6 (?) times, once for each color, would be that bad. (Unless you have thousands of units per team.)

ynohtna
Feb 16, 2007

backwoods compatible
Illegal Hen

Orzo posted:

It seems like the problem is something unit tests wouldn't be so great at covering--namely, if Team A has a reference to Unit X and some data structure elsewhere indicates that Unit X doesn't have a reference Team A, there's a bug. And it sounds like an integration bug.

Although I don't have too much experience with this type of thing, it sounds like the biggest concern is that client code might introduce an error--for example, you might transfer a unit from Team A to Team B and forget to update the additional data structures. To solve this problem, you might want to introduce some sort of manager through which ALL of these operations are performed, so that you won't (and can't) 'forget' to update the extra structures.
Yeah, each manipulation should be encapsulated in a single place - ::SwapTeam or whatever. Code shouldn't be directly updating data structures in multiple places otherwise, as you've noted, bugs will breed like buggery.

The unit test for that method (preferably written first a la TDD) verifies that the post-conditions of calling it are what you expect. You write unit tests against methods, not raw data structures.

Orzo
Sep 3, 2004

IT! IT is confusing! Say your goddamn pronouns!
Yes, you can write unit tests for what I suggested, I was referring to the original problem, where the updates were called all over the place.

ynohtna
Feb 16, 2007

backwoods compatible
Illegal Hen
Sorry, I got confused 'tween posters - long day.

Yeah, that's just code at high risk of bug rot over time regardless of anything else.

HappyHippo
Nov 19, 2003
Do you have an Air Miles Card?
Yeah it looks like that's what I'll have to do. It's just kind of annoying because I'll basically be coding the same pattern 4 times over (well almost, cities don't move between tiles, although they can be destroyed).

Adbot
ADBOT LOVES YOU

Orzo
Sep 3, 2004

IT! IT is confusing! Say your goddamn pronouns!
Why are you coding the same pattern 4 times? What language are you using?

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply