so I wanna make a hashSet<Components> Components is the interface to store objects from classes that implement component. specifically hashSet cause I don't want 2 objects of the same class to exist together. I imagine, I would have to overwrite hashcode for every single one of those classes to return hash(class) or something. any way around this?
#set of interface instances
1 messages · Page 1 of 1 (latest)
<@&987246399047479336> please have a look, thanks.
While you are waiting for getting help, here are some tips to improve your experience:
If nobody is calling back, that usually means that your question was not well asked and hence nobody feels confident enough answering. Try to use your time to elaborate, provide details, context, more code, examples and maybe some screenshots. With enough info, someone knows the answer for sure.
Don't forget to close your thread using the command </help-thread close:1027500463647621170> when your question has been answered, thanks.
@random canopy Yeah, just have the classes hash their contents
you misunderstand hashsets
let me ask
Are components "values" - their equals is based on the contents of their fields
Or are they "objects with identity" - their equals should be the same as ==
hmmm I'm a bit confused by the question
ooh boy
package Utils.Components;
import Utils.Component;
import Utils.GameObject;
import main.GamePanel;
import java.awt.image.BufferedImage;
public class SpriteRenderer implements Component {
private BufferedImage currentSprite;
private GamePanel gamePanel;
private GameObject parentObject;
public SpriteRenderer(BufferedImage sprite, GamePanel gamePanel, GameObject parentObject) {
this.currentSprite = sprite;
this.gamePanel = gamePanel;
this.parentObject = parentObject;
}
@Override
public void start() {
}
@Override
public void update() {
this.gamePanel.drawSprite(currentSprite, parentObject.getTransform().getPosition());
}
public BufferedImage getCurrentSprite() {
return currentSprite;
}
public void setCurrentSprite(BufferedImage currentSprite) {
this.currentSprite = currentSprite;
}
}
right, I understand that hashset is meant more for values, I guess I just wanted to see if there was a collection specifically for unique classes
but yeah I'm using list now
well a HashSet would work as is
but it would not be ordered
i would suggest LinkedHashSet if you want the order of components to stay the same
right but wouldn't it let in multiple components from the same class, if they have different values?
that would still have an order like a list, but would remove the chance of accidentally adding the same components twice
Yes
If you want that I would say use
LinkedHashMap<Class<? extends Component>, Component>
so you map classes to the one component
yup, that's awesome man thanks
i was gonna say IdentityHashMap, but idk
that loses order
btw I am hard assuming that
- You are making a game
- These are "ECS" components
definitely making a game, what's ECS lol
it's possible I'm doing that rn without knowing it but yeah I'm going for a similar structure to unity gameobjects and stuff
welp for now I'm not even sure about needing order, but I'll stick to order stuff just in case
RustConf 2018 - Closing Keynote by Catherine West
When you’re just starting out in Rust, you start by building small programs. As we all know though, medium and large projects can have very different, unique kinds of problems that smaller projects never encounter. As our projects grow in size, we need to be increasingly concerned about code org...
the 2nd talk is what introduced me to the concept
"Entity Component System"
also I'd love to see your game code
if you are willing
I mostly see shitty website projects on here
ooo thanks, I'll def check those out since it's kinda my dream to actually get into game dev some day lol
ofcourse, but fair warning, haven't set up like a solid update loop yet, I have frame update set up and I'm just using that for now lol
but also I don't really have much of a game going on rn, just setting up that component system
(would be pretty funny if you watch those two videos then just use ashley)
what, like just rip the code from there or something lol
oh it's a whole ass framework nice
yeah ngl I've been intentionally trying to stay away from frameworks for this specific thing cause I wanna see how stuff works on the inside I guess
also wait here's some game code, again, not much game going on yet, so most of what I have to be proud of is the component stuff lol
I uploaded your attachments as Gist.
oh yeah, since I'm trying to remake pokemon firered, I also set up this grid class
package Utils.Components;
import Utils.Vector2;
import main.Game;
public class Grid {
private int cellWidth;
private int cellHeight;
public Grid(int cellWidth, int cellHeight) {
this.cellWidth = cellWidth * Game.PIXELS_PER_UNIT;
this.cellHeight = cellHeight * Game.PIXELS_PER_UNIT;
}
public Vector2 gridToWorldPosition(Vector2 gridPosition) {
return new Vector2(this.cellWidth * gridPosition.getX(), this.cellHeight * gridPosition.getY());
}
public Vector2 worldToGridPosition(Vector2 worldPosition) {
return new Vector2(worldPosition.getX() / this.cellWidth, worldPosition.getY() / this.cellHeight);
}
}
Detected code, here are some useful tools:
you know the firered source code is public right?
you can compile the rom yourself
change the code and make a modded version
well ok I mean it doesn't change stuff for me all that much, I just wanna make it for the sake of making it lol
oh yeah sure
but if when you are done with this if you want to do another pokemon thing
but yeah this is prolly gonna be useful as hell cause I've been beating my head against the wall trying to set up combat, since I'm not all that sure how it works on the inside
for that there is the source code
yeeee, thamks em
but also other battle systems
man ok that's great, I can actually learn something now
thanks em, I saved those, gonna be a huge help
alright well thanks again em! cya