Reputation
610
Top tag
Next privilege 1,000 Rep.
See votes, expandable usercard
Badges
5 16
Impact
~33k people reached

  • 0 posts edited
  • 0 helpful flags
  • 57 votes cast
Jul
29
comment How to manage a vector of “Component” base class?
@Marco13 and this would cause memory invalidation when returning references (otherwise, if possible without headaches, (const) references should be preferred). If he did that it would yield extremely messy code. References shouldn't be the only thing referring to an object on the heap.
Jul
29
comment How to manage a vector of “Component” base class?
@Marco13 You need pointers for polymorphism, the smart pointers are likely there simply to alleviate the need for deleteing them in a constructor .
Jul
29
comment How to manage a vector of “Component” base class?
@Marco13 Sorry for the almost-same comment above. I accidentally deleting my original so I wrote a new one.
Jul
29
comment How to manage a vector of “Component” base class?
@Marco13 If you call a function to obtain a component, it's much better to receive a nice reference to it's original instance type without any pointer hassle. I feel like having a function to do both checking for the existence of or returning a specific component type is a bad idea. Throwing an exception is not a bad thing, it will likely crash the program, but I consider that a good, because it means you have a bug in your code. If you're going to do something nonsensical like ask for a component that you have not checked that it even exists yet, what stops you from using a null pointer?
Jul
29
comment How to manage a vector of “Component” base class?
@Marco13 But if you could've find the component, what then? Return a shared_ptr referring to a null pointer? References are much more elegant and don't promote using shared_ptr for the wrong reasons (in this case, there is no need more more than one pointer sounique_ptr should've been used, and you can't return a unique_ptr). The proper solution is the ensure the calling code should check if the component exists before calling the function to get the component. If it's called anyways, throw an exception, which is how the standard library deals with these exact situations.
Jul
29
comment How to manage a vector of “Component” base class?
I recommend researching and learning how to use RTTI. It should make understanding how to use templates for component identification much easier.
Jul
29
comment How to manage a vector of “Component” base class?
Take a look at EntityX's source code for a working example it. I haven't taken a full look at it, but I've tried it before and it uses template types. There are a few ways to do it, but with typeid you could do something like this: template<typename T> hasComponent() { for (auto comp : components) if (typeid(comp)) == typeid(T) return true; return false; } so you could simply do: if (entity_manager.doesEntityHaveComponent<SomeComponent>(id)) { .... }'.
Jul
29
revised How to manage a vector of “Component” base class?
added 160 characters in body
Jul
29
comment How to manage a vector of “Component” base class?
@Marco13 Disclaimer: I'm not a C++ expert either, usually I'm using a good language While your comment is wrong (returning a reference is the best return type for that method since a reference is all you need; that an using share_ptr was a bad choice and unique_ptr cannot be copied), if you don't know much about C++ and just like to insult languages you don't like please don't give advice for for someone programming in it.
Jul
29
answered How to manage a vector of “Component” base class?
Jul
15
comment Rendering a texture with OpenGL
Because not all devices support it. I've never had a problem with my computer drawing oddly-shaped textures, but some do. If you're making a game and want to support a wider range of computers, use power-of-two textures and simply only draw the part of the texture you want. You can also use non-power-of-two assets, then have your engine add a border to make it power-of-two and draw only the parts that were of the original texture.
Jul
15
comment Rendering a texture with OpenGL
Forgot to mention, some graphics devices support non-power-of-two textures. Some convert to power-of-two at run-time. It's just that some don't support them at all.
Jul
15
comment Rendering a texture with OpenGL
@BlackHamm3rJack They're called power-of-two textures. But they also must be squared, 128x256 is not squared. The common resolutions are 2x2, 4x4, 16x16, 32x32, 64x64, 128x128, 256x256, 512x512, 1024x1024, and 2048x2048. Not all graphics devices support larger resolutions, though.
Jun
12
awarded  Popular Question
Jun
6
awarded  Popular Question
Feb
17
awarded  Notable Question
Feb
8
awarded  Notable Question
Feb
2
comment VBO - Update Vertex data
There is no one place to put it. However, it is usually best practice to separate logic and graphics, in which case it'll be your render method.
Jan
1
comment Why not just create very high resolution graphics and use them on all screens?
It's called mipmapping. It's done for performance reasons.
Dec
13
awarded  Yearling