#and then it can automatically select the
1 messages · Page 1 of 1 (latest)
before the generics, a gridobject was basically the holder of info of 1 position on my grid. it held the struct gridposition which consits of xyz and floor data and it held a list of units currently on that position on the grid ( list so units can walk over eachother) its been a while since ive had obstacles. but i think those were assigned in the gridobjects aswell, making positions unwalkable
okay, so a GridObject is not an object on the grid
it's a list of every single unit that is on a tile
TileUnits would be a more appropriate name.
public abstract class OnGrid
{
public GridPosition gridPosition;
public GridObject gridObject;
this seems very weird to me
this means that everything that can be on the grid must have a GridObject
even if it has nothing to do with units
it would make more sense to me that the only things on the ongrid where either gridobjects ( holding all the positional data and units) or pathnodes. i tried deleting the gridpositions there but got loads of errors and just put them back
the grid position makes sense
everything on the grid must have a grid position
that's very reasonable
it's not reasonable for everything on the grid to have a GridObject
why does a path node care about grid objects?
so youre saying only things that everything on the grid should have acces to should be in the OnGrid class?
Right.
i cut that out earlier as it wasnt relevent ```cs
public abstract class OnGrid
{
public GridPosition gridPosition;
public GridObject gridObject;
public PathNode pathNode;
}``` but i added the pathnodes here aswell
you should have neither
PathNode and GridObject derive from OnGrid
public class GridObject : OnGrid {
public List<Unit> units;
}
public class PathNode : OnGrid {
public bool walkable;
}
public abstract class OnGrid {
public GridPosition gridPosition;
}
if a function uses an OnGrid, then you can give it a GridObject or a PathNode
yeah that makes more sense, i still had some misconceptions about what ongrid actually did. ill refactor it now
you should give this a read
thanks i will read them both. this generics stuff seems really usefull and i wish i understood it better
polymorphism is the interesting part
explaining generics yesterday made me realize that they aren't actually that exciting: all they do is let you skip having to cast to a specific type
System.Collections.ArrayList stores object
you have to cast back to the type you're actually using
generics let you say "I want to use this more specific type"
without generics, you could totally still make a GridSystem that works for both GridObject and PathNode
you'd just have to do this every time:
gridSystem.GetThing(somePos) as GridObject
yeah they seemed a lot more usefull for my different actions. i only have a few so far and that cleaned a lot of code. + those were really easy to implement. my gridsystem though.. not so much:p
the rule of thumb: GridSystem should never reference anything more specific than OnGrid
man im trying to read those links you send but i think i need to get back on medication before i can actually read and retain this. ill try again later