Nazoz

u/Nazoz


r/cpp_questions•

Im having some trouble when trying to use "using namespace input::Mouse" and "using namespace input::Keyboard" in two of my classes.

Im trying to replace this, with this. Basically introducing a "using namespace" to clean up the code a bit, but i get some errors.

On line "using namespace input::Mouse" on the word namespace in class MouseButton_Event, i get a red underline with error "Expected an identifier", and on Button, Action, Modifier i get "identifier Button/Action/Modifier is undefined" in the rest of the class. And basically the same thing the the Key_Event class.

Included files: [InputEnums.h](ht

113

r/regex•

Code:

static std::vector<std::string> splitPath(const std::string& path)
{
    std::vector<std::string> components;

    std::regex delimiterSplitter("[^\\\\/]+");

    auto begin = std::sregex_iterator(path.begin(), path.end(), delimiterSplitter);
    auto end = std::sregex_iterator();

    for (auto it = begin; it != end; it++)
    components.push_back((*it).str());

    return components;
}

Paths like ../Resources and ../Resources/composition.json are split like expected into [..|Resources] and [..|Resources|composition.json] respectively.

But in addition, i would like to split the p

12

r/opengl•

Im making a game engine and im going into the territory resource management and not hardcoding stuff like indices, vertices, uv's etc. Basically i want to load generic models, and im wondering which kind of formats i should implement for a good balance between versatility and implementation time.

If there are well known individual formats for indices, vertices, uv's i would prefer using those, as i could build some kind of hierarchy for defining resources. For example i could have a directory called sprites containing the really basic indices and uv's of a square and a default debugging texture (Like a purple and black square pattern in the source engine). As a subdirectory i could have dir

512

r/cpp_questions•

I have a Position_Component and Velocity_Component that both contain a vec3f.

I want to be able to use operators on these components and similar components i will make in the future as if they are vec3f, so i've defined an implicit conversion to a vec3f for both of these types of components. When i do try to use operators on them as if they are vec3f, i get errors that the operators are not defined.

struct Position_Component : public Component<Position_Component>
{
	math::vec3f position;
	Position_Component() : position(math::vec3f{ 0.0, 0.0, 0.0 }) {}
	Position_Component(const math::vec3f& position) : position(position) {}

	operator math::vec3f() {
114

r/opengl•

So far, my process of managing textures is: genTexture, bindTexture, set parameters, and lastly pass the texture data to opengl with glTexImage2D. After this i just delete all the pixel data, and bind the texture unit whenever i want to use the texture.

​

This seems like it is too easy to be a good solution. I imagine textures staying in gpu memory until program termination, using resources that other programs might need, that my engine isnt even using at the moment. Also, what happens if i try to use more gpu memory than available?

​

Do i even have to manage this at all or is it done for me? That is, can i just create a bunch of texture units and they are moved bet

28


Im a student currently studying computer engineering in Norway, im coming close to the end of my second of three years to get a bachelor.

​

A good portion of our curriculum consists of science, specifically math, physics and chemistry, but mainly math of the three. While i do want to learn science as it is a very valuable tool, unfortunately i am not very passionate about most of it. In other words, i dont want to become a mathematican and have it be the main aspect of my job.

​

From my two years, i've gotten a decent understanding of algorithms and datastructures, modelling, some very basic networking, a good deal of website development, and of course math, physics

32

r/cpp_questions•

Here's a simpler example first to better explain what i mean.

template <typename T>
class TemplateClass
{
public:
	void print();
};

template <>
void TemplateClass<int>::print()
{
	std::cout << "T is an int!" << std::endl;
}

template <>
void TemplateClass<float>::print()
{
	std::cout << "T is a float!" << std::endl;
}

int main()
{
	TemplateClass<int> i;
	i.print();
	
	TemplateClass<float> f;
	f.print();

	system("PAUSE");
}

Here i override the print() function based on if T is int or float.

The program print

65

r/cpp_questions•

I have this code which almost works as intended, basically i want a function that creates an entity without adding any components to it, and one that creates the entity AND adds components to it. All functions are in one class EntityManager.

​

Takes no components:

Entity newEntity()
{
	Entity newEntity{ entityCounter };
	entityCount++;
	entityCounter++;

	std::cout << "Called newEntity(void)" << std::endl;

	return newEntity;
}

Takes components:

template <typename... Components>
Entity newEntity(Components... components)
{
	Entity newEntity{ entityCounter };
	entityCount++;
	entityCounter++;
317

r/cpp_questions•

Im getting this error at the static cast line

​

Error	C2440	'static_cast': cannot convert from 'ComponentType *' to 'ComponentStoreType *'

​

I get the exact same error from using dynamic_cast or reinterpret_cast, other than the cast name.

​

Any ideas?

​

template <typename ComponentType>
bool insertComponent(const Entity& entity, ComponentType& component) { 

    static_assert(std::is_base_of<ComponentStoreType, ComponentType>::value, "ComponentType must be derived from ComponentStoreType!");

    if (storesComponentType<ComponentType>())
    {
        insertComponentVirtual(ent
19

r/cpp_questions•

I've tried asking a similar question before, but dident get far.

Im about to go the dirty road, but i want to try asking again before i do.

I have a function that takes in components

void func(ComponentA* a, ComponentB* b) // Could also be references
{
    // Something
}

Somewhere else i want to call this function, but both the components are in a vector.

Of course i could just call func(vector[0], vector[1]), but the question is a bit more complicated than that.

I have multiple of these funcs, and they are actually lambdas. I basically want some kind of generic caller function that does this:

template <typename Lambd>
void caller(Lambd lambd, std::vecto
19


r/cpp_questions•

I have a class EntityManager that simplified looks like this:

class EntityManager
{
    std::vector<ComponentManagerBase*> componentManagers;
    
    template <typename... ComponentTypes>
    void each(std::function<void(ComponentTypes*... components)> lambda)
    {
         // What i need help with
    }
};

and systems that calls the each function like this:

void update(double dt) override
{
std::function func =
			[] (ComponentA& a, ComponentB& b) // Or with pointers
			{
				
			};
    entityManager->each<ComponentA, ComponentB>(func);
}

In the each function, i want to call th

32

r/cpp_questions•

I know how to unpack a parameter pack, that is, there are some actual values. But how can i unpack just the types?

Setup:

class ComponentManagerBase
{

};

template <typename ComponentType>
class ComponentManager : public ComponentManagerBase
{
    ...An array of ComponentType, a function to add/remove a component etc...
};

struct ComponentBase
{

};

struct ComponentA : public ComponentBase
{
    float x, y, z;
};

struct ComponentB : public ComponentBase
{
    int i;
    double d;
};

template <typename ComponentTypes...>
std::vector<ComponentManagerBase*> unpacker()
{
    .
35