121
Cute Discussion / Re: sbw2
« on: April 16, 2016, 06:41:09 PM »yeah its neat..... so right now im trying to minimize one of my classes Entity and it has kind of a bunch of crap that doesnt always get used. entity is basically my equivalent of a game maker object. position, speed, image related stuff, alarms, theres also a hash set of tags for things like collision. but nine times out of ten at least some aspect of this goes unused, and when i feel like i will be wasting resources, i climb the ladder and extend EntityBase (the parent for oddwarg and i's own entity classes) but ultimately this means i have to fill out a bunch of methods. so im making MinEntity which has position, collision support, and alarms.Okay, so not-working weekend brain here, also I don't program vidjas, and am not really thinking outside the box in regards to all of your requirements.
Objects should represent a single "thing", and should provide all of the behaviours for that; an object that does everything generally leads to how you feel, that it is a bit of a dumping ground. Try making objects around more narrow concepts (you could have a position object that carries the position and provides methods for common transforms and the like). As for the composite entities, you could have a hierarchy of more and more complex entities each provided a more specialised aspect. For instance, a simple entity that doesn't move would just have a position set on construct and no methods to provide any ability to mutate position. You can build on that with a movable entity blahblah. If the specialisation of your entities is also in logic rather than data, you can use interfaces too to add behaviours to entities, again you could have movable with means all of your entities that implement it should be movable in some way. Default methods are new too, which allows you to provide logic in these interfaces: https://docs.oracle.com/javase/tutorial/java/IandI/defaultmethods.html
I wouldn't worry about things like this from a performance standpoint. Having a few arbitrary fields isn't going to make any noticeable impact on performance*.
As for event scheduling, I would avoid solving the problem yourself, since it is one that has probably already been solved. Are you using any kind of game framework? This should provide the means to do this out of the box.
* Unless you are making many thousands and/or each field has to do a lot of work to initialise, or contains a LOT of data