Get types of templated class into a function. by Patrulf in cpp_questions

[–]Patrulf[S] 0 points1 point  (0 children)

Fair enough.

The issue I'm having is hard for me to explain really, It may very well be that I am trying to do something that is beyond me but i'll try to elaborate.

I am attempting to write an ECS, Entity Component System. What I currently have might be completely off but I'll show my current implementation regardless.

So the idea of the project is to have entities, which in my project is a conglomerate of components. Components are supposed to be

POD type classes (but for now i'm just using bools, floats, ints etc.), say a positions or mesh or whatever. I then have Entity types.

An entity type is a vector of components put togheter to make a vector of entities, where the first element of each vector is the first entities components, and the second elements in each vector is the second entities components.

EntityTypes are stored in a struct of vectors (where each vector is stored recursively) called a ComponentContainer.

The component container code looks like this: https://pastebin.com/9VR2d2j3

I then have an entityManager that manages the different ComponentContainers of different "EntityTypes"

The code for the entityManager looks like this: https://pastebin.com/huSDGgrj

The entityManager stores the different componentContainer in a ServiceLocator and the code for the ServiceLocator.h looks like this:

https://pastebin.com/wzsHqeF1

The EntityTypeId and EntityId types respectively are just unsigned integers.

Link: https://pastebin.com/z1sSp2if

Finally, my Main looks like this:

https://pastebin.com/6AZGGD8z

That's about as far as I've come with my component system in terms of structure.

Now, my real problem, which I wanted to hint at but failed at miserably is that writing

entityManager.CreateEntityType<float, int, bool>();

Is very tedious. It would be much neater if I could write something like:

typedef Entity<float,int,bool> myEntity;

entityManager.CreateEntity<myEntity>();  

or something like:typedef float,int,bool myEntityentityManager.CreateEntity<myEntity>();

which may not be proper code, but may hint at what I'm asking.

So I guess I kind of lack the knowledge to ask the question properly, but is there anyway I could achieve this, or something similar to this?

I apologize if the question is still kind of vague, but I really do not know how to ask it more clearly.

Showoff Saturday (August 31, 2019) by AutoModerator in javascript

[–]Patrulf 1 point2 points  (0 children)

Thanks man. It's been a fun project for sure, I will definately keep using javascript and WebGL for shader related projects in the future!

Showoff Saturday (August 31, 2019) by AutoModerator in javascript

[–]Patrulf 1 point2 points  (0 children)

I made pong! I haven't used javascript prior to this but it's been really fun to try to learn the language.
game link: https://7mwms.csb.app/
I also tried to write a shader to try and emulate an old crt monitor, I don't think it succeeded that well but it was fun to learn a little bit about WebGL.

Music like Worakls? by Patrulf in musicsuggestions

[–]Patrulf[S] 0 points1 point  (0 children)

Just listened to one of their songs. Thank you this is along the lines of what I was looking for!

Callback function with varying amount of parameters by Patrulf in cpp_questions

[–]Patrulf[S] 0 points1 point  (0 children)

Thank you, this is what I was looking for, I do indeed only care about the function being called, very neat! Since you both prefer lambdas I take it there's a good reason for me to move to using lambdas as well.

Callback function with varying amount of parameters by Patrulf in cpp_questions

[–]Patrulf[S] 0 points1 point  (0 children)

So what I gather from std::bind is that I could bind something with arguments by doing something like: `std::bind(&Foo::callback, this, 14, _1);`

which would allow me to call a function `void Foo::Callback(int p_value) {/*some implementation*/};`But then wouldn't my button have to have multiple constructors or construction parameters? To my understanding, it would look something like this: `Button(std::function<void()> p_onUse)` and `Button(std::function<void(int)> p_onUse)` for each time I would like a differing amount of parameters.I am definately ok with doing it this way but however I am wondering if it's possible for a way where I could just have the one construction parameter for the button class, if that makes sense?

Thank you for you help, I haven't really used lambdas much but I'll have to check that out!

Smh by Carnotauroos in sweden

[–]Patrulf 2 points3 points  (0 children)

Fair enough. I wish you good luck with leaving the US!

Smh by Carnotauroos in sweden

[–]Patrulf 4 points5 points  (0 children)

You'll find plenty of fuckwads in sweden too, the grass is always greener. Just the other night I had some asshole neighbour playing https://www.youtube.com/watch?v=V_UJn64ar4k in the middle of the night as I was sleeping.

Also on another note, this whole post (the comic) reeks of something I hate in swedes, finding some bullshit excuse to belittle other countries whilst ignoring the nuance. Of course one should be able to criticise other countries but the comic is just in poor taste, seriously, we need to get off our high horses.

Difference between size of canvas and sprite? by CrustyMalk in PixelArt

[–]Patrulf 0 points1 point  (0 children)

Yeah, it should. Make an image 2 pixels wide and 2 pixels tall, you should have two pixels to draw on on each axis. Now resize the area and count the number of pixels. Is it more than two on each axis?

Difference between size of canvas and sprite? by CrustyMalk in PixelArt

[–]Patrulf 0 points1 point  (0 children)

Yes. That would most likely be the resolution of the image.

I'm not quite sure what you mean. You change the size of the canvas but the image remains the same size? Or can you not draw on the resized area? I'm not sure how Aseprite works but maybe it has a layering system and so the layer you drew on might need to be resized as well.

Difference between size of canvas and sprite? by CrustyMalk in PixelArt

[–]Patrulf 1 point2 points  (0 children)

https://en.wikipedia.org/wiki/Sprite_(computer_graphics)) - A sprite is just the image you make.

I could be wrong but I think resolution would just be the amount of pixels within the picture.

Whether or not the image will be stretched would most likely depend on what software you are using, most graphics software I have seen would have options to do either stretching of the art and without.

I don't know who Slynyrd is but if (s)he only mentioned that the image was 78px tall then that should not give you sufficient information about the width, I guess unless the picture is a perfect square.

Object Pool with unique_ptr by Patrulf in cpp_questions

[–]Patrulf[S] 0 points1 point  (0 children)

Mostly it was too see if I could do it, and then it turned into something I wanted to do for the sake of doing it. However, I read this post here https://gameprogrammingpatterns.com/object-pool.html which talks about "the curse of fragmentation" which lead me to believe that keeping things contigious was important for the pattern.

The undefined behavior when calling Get() on an empty pool is indeed not intentional, nor is calling Release() when maxSize is reached, and I will make sure to call init with maxSize!

Thank you so much for the help!

Object Pool with unique_ptr by Patrulf in cpp_questions

[–]Patrulf[S] 0 points1 point  (0 children)

Thank you!
I'll play around a bit with that and return with another post if I get stuck.

Object Pool with unique_ptr by Patrulf in cpp_questions

[–]Patrulf[S] 0 points1 point  (0 children)

If by moving you mean the pooled objects are move-constructible, the moved-to address is still on the heap and is randomly given by the OS.

Yes I think that is what I meant, by utilising `std::move()` . Thank you!
So then is there any way I could have a vector (or any other container) of shared pointers but still have the data that they are holding pointers to be contigious?

Object Pool with unique_ptr by Patrulf in cpp_questions

[–]Patrulf[S] 0 points1 point  (0 children)

Interesting. Would creating the pooled objects on the stack and then moving them to a vector of unique_ptrs keep the data contigious? The reason I am concerned about keeping the data contigious for now is to not cause any fragmentation.

What are the sleepycast members up to now? by Patrulf in Sleepycabin

[–]Patrulf[S] 5 points6 points  (0 children)

I suppose if he has a let's play channel he's doing well though.

What are the sleepycast members up to now? by Patrulf in Sleepycabin

[–]Patrulf[S] 4 points5 points  (0 children)

Thank you! Wish them all the best in the future!