Jump to content
  • Advertisement

lexington

Member
  • Content Count

    61
  • Joined

  • Last visited

Community Reputation

193 Neutral

About lexington

  • Rank
    Member

Personal Information

  • Interests
    |programmer|
  1. lexington

    Game Engine Questions (ECS)

    @[member='PSvils'], so im guessing each of your systems has a reference to the system manager? 
  2. lexington

    Game Engine Questions (ECS)

    @[member='PSvils'], (on question 2) So u pass what is needed by the systems to its constructor so its just stores locally. I did think that would prob be the best method.   Iv never seen systems dependent on each other, any chance you could give an example of when this might be used.   Thanks for the post was very helpful :)
  3. Hey Everyone, Iv been trying to create an engine based around the ECS architecture (first attempted so still trying to find my group). Its been going quite well but  there are around 3 problems/questions that I have come across and was wondering if I could have some advice on them.   1. The current system that i have is that the entity stores a vector of components (each component and entity has a unique ID the component one being a static int) and then for each system, i get the component I need by calling an entity function with the ID of the component I want. The function just searches through the list for the component with the requested ID and returns it.   My question is, is there a better/more efficient way of doing this. i have seen some people having a component holder with a vector of each component and the components hold a reference to its entity's ID, is this a better system?   2. My second question more relates to passing data to the systems. Currently each of my systems gets passes delta time, a bool for go that makes the main loop run (lazy for now but can be changed),  and a class called world which has the entity manager so that system can ask to create new entities (like bullets) and a spawn class that contains positions for spawns (in relation to the game i'm making with it).    I already feel that this approach is not really a good one but i don't know the best way to go about changing it. When it comes to things like the input manager and the "world" class, I could pass them to the systems in the constructor but other then this i don't see a way of making this work without global.   3. The last question i have is based around an octtree im using for collision. For my systems i have a stored link to the root node in my collision system and a component for each entity (that will have collision checks) has a link to the node the entity is in. The octtree has knowledge of the entities and each node has a vector of them (that are inside that node). each entity first makes sure its in the correct node (with its aabb) and then after that, I currently call root->update() in my collisionchecksystem.    The octtree node then checks all the collisions possible and then calls update for the other nodes (recursively) the octtree gets the obb and aabb components from the entity to do collision checking. At this point im really not sure if this is a good system. I don't think its best to do this bit recursively so it might be much better to do the collision code in the collision check system (would be a lot better for the logic after collision as well e.g. damage taken) and just get all other entries we need to check collision for from the octtree (or maybe just their id's for efficiency) but my problem with this approach is I don't see a good way of making sure the same 2 entities don't have 2 collision instances with each other (as i would be requesting all entities that could collide with the entity in question).   I would very much appreciate any advice on some of these questions. ATM i do have most of these problems working but I want to try to build a good foundation and understanding of how to go about these problems before i get to far ahead in the engine.    Thanks for your time :).
  4. lexington

    Ecs Inheritance Problem (C++)

    @[member='Kylotan'], hmm interesting. The way I have it currectly is that the octtree gets updated and places all of the entities in vectors for each node and then another system called collisionrun calls root.update which check all the collisions from the root of the octtree down to the last nodes (atm with around 200 entities just using AABB and no logic after this is taking  19ms's (debug mode) so might be something i have to look at optimising a bit better).   I also have heard that another way i can make things more efficient is to have different entity lists for different systems (as not all entities need to be checked by a system) is this a good tool?
  5. lexington

    Ecs Inheritance Problem (C++)

    @[member='Kylotan'], So your saying that i should just pass the aabb's to the octtree and then when it comes time to do collision, loop through the entities that can collide and test them agains the aabb's in the same node (as well as in the parent node)  
  6. lexington

    Ecs Inheritance Problem (C++)

    Hey guys,   I have managed to create a ECS (thanks to your help) but if its ok (and since the post has not reached the time limit yet) i was hoping i could ask one last question.   Is it ok for non systems to pull a components entity, personally i cant see a problem with this atm but I thought it be best to ask. Currently i have an oct tree class that does request the aabb and obb components of the entity (as well as other collision parameters to test the collision type) and checks for collisions. I could prob find a way to move this to a system but is it really needed?   Thanks again for the time :)
  7. lexington

    Opengl ECS performance problem

    @[member='noizex'], @[member='_Silence_'],  Thank you every much for the help guys, ill report back when hopefully the perfomance issues are fixed :)   @[member='noizex'], that part about the current VAO states sounds like a pretty kl idea, will have to give it ago later :)
  8. lexington

    Opengl ECS performance problem

    @[member='noizex'], Arr so instead of a loop to provide the BasicModelcomponent with what it needs, i should just ask the flyweight manager to provide back what is needed (and create a new object if needed) therefore i wont really even need the init system as everything can be setup when calling the entity manager to create the bullet. Did i leave anything out?
  9. lexington

    Opengl ECS performance problem

    @noizex   Ok so let me see if i understand what is being said (do have couple of questions at the end of the post :))   For the shader program, i can make a class that has already pre loaded all the the shader data needed, so that when it comes to creating a new bullet or fighter, i can just call of that program to be returned and use that.   When it comes to the VAO and VBO i would also have a class that can return the VAO to the BasicModelcomponent so that when it comes to drawing, all i have to do is glBindVertexArray then draw.   Is this correct or am i missing out something.   also in terms of my question, what do u mean about re-updating the GL resources every frame, the init system will only ever run anything if there is an object to be created.   Cheers 
  10. lexington

    Opengl ECS performance problem

    @_Silence_   I see how you could use the same program for each model as it just holds the shaders you want but i thought that the the data in the VBO could only be used for one instance of the model (then you had to add the data for the next one even though it is the same vertex data), am i wrong and you can use it for multiple of the same model, if not how would i reuse the VAO/VBO for each bullet/ship?
  11. lexington

    Opengl ECS performance problem

    @_silence_ So your saying that I should create a VAO, VBO and shader at the start for each model/entity and then just reuse them?
  12. Hey everyone,    I have been building a component entity system for my game and so far it has gone pretty well but today I have hit a problem.   Having just but it a system for creating and firing bullets. when i click to fire bullets it seems that i get some weird lag (most likely performance) that makes it seem as my ship is jolting forward. After looking at the VS time while debugging, it seems that after firing the bullet it takes around 30 ms to get back to the bullet system and most of this time is being take up by the init system (taking around 25 ms setting up VAO, VBO, shaders and textures). So my question (as someone who is still learning about opengl) is how would i decrease this time for setting all of this up. I will post the relevent code for the init systems and all other classes i use below.    Thanks for all help provided in advance :)   On a node about function times, it seems as the function "com->myshade->loadshader(com->vertexshadername.c_str(), GL_VERTEX_SHADER);" with the line "GLuint Shader = glCreateShader(type);" Is taking around 10 ms to complete which im guessing is why its taking so long but i don't really know why (the fragment call finished in less then a ms).   Init system void initsystem::update(float dt, entitymanager *mymanager, bool &go) {     std::vector<entity*> setupentites = mymanager->returnsetupent();     for (int i = 0; i < setupentites.size(); i++)     {         BasicModelcomponent *com = static_cast<BasicModelcomponent*>(setupentites[i]->getcomponent(BasicModelcomponent::TypeID));         texturecomp *textcomp = static_cast<texturecomp*>(setupentites[i]->getcomponent(texturecomp::TypeID));         vectorimage *entityvec = static_cast<vectorimage*>(setupentites[i]->getcomponent(vectorimage::TypeID));         skyboxcomp *mycomp = static_cast<skyboxcomp*>(setupentites[i]->getcomponent(skyboxcomp::TypeID));         if (com != NULL && com->setupstate == false)         {             com->vetrices = com->getdata->retuvetices();             com->normals = com->getdata->retunormals();          com->uvs = com->getdata->retutexterco();             com->myVAO = new VAO();             com->modeldata = new meshd();             com->UVdata = new meshd();             com->myshade = new shader();                      com->myVAO->genbuffer(1);             com->myVAO->bindVAO();             com->modeldata->genbuffer();             com->modeldata->addvec3buffer(com->vetrices);             com->modeldata->addvec3buffer(com->normals);             com->modeldata->bufferdatavec3(GL_STATIC_DRAW);             com->modeldata->linkdata(0, 3, 0, 0);             int test = sizeof(glm::vec3) * com->vetrices.size();             com->modeldata->linkdata(1, 3, 0, (void*)test);             test += sizeof(glm::vec3) * com->normals.size();             com->modeldata->linkdata(3, 3, 0, (void*)test);             com->UVdata->genbuffer();             com->UVdata->addvec2buffer(com->uvs);             com->UVdata->bufferdatavec2(GL_STATIC_DRAW);             com->UVdata->linkdata(2, 2, 0, 0);             if (textcomp != NULL)             {                 textcomp->mytexture->loadtexture();                 textcomp->mytexture->gentexture(1);                 textcomp->mytexture->twodtexturesetup(true);             }             com->modeldata->unbindbuffer();             com->UVdata->unbindbuffer();             com->myVAO->unbindVAO();             com->myshade->loadshader(com->vertexshadername.c_str(), GL_VERTEX_SHADER);             com->myshade->loadshader(com->fragmentshadername.c_str(), GL_FRAGMENT_SHADER);             com->myshade->linkshader();             bool linkok = com->myshade->linkcheck();             shipshaderlinks *SSLcom = static_cast<shipshaderlinks*>(setupentites[i]->getcomponent(shipshaderlinks::TypeID));             lightcomp *lightlinks = static_cast<lightcomp*>(setupentites[i]->getcomponent(lightcomp::TypeID));             if (SSLcom != NULL)             {                 SSLcom->shaderModelMatLocation = glGetUniformLocation(com->myshade->returnprogram(), "modelMat");                 SSLcom->shaderViewMatLocation = glGetUniformLocation(com->myshade->returnprogram(), "viewMat");                 SSLcom->shaderProjMatLocation = glGetUniformLocation(com->myshade->returnprogram(), "projMat");                 if (textcomp != NULL)                 {                     textcomp->texture = glGetUniformLocation(com->myshade->returnprogram(), "myTextureSampler");                     textcomp->Gamma = glGetUniformLocation(com->myshade->returnprogram(), "gamma");                 }                 if (lightlinks != NULL)                 {                     lightlinks->strenght = glGetUniformLocation(com->myshade->returnprogram(), "strength");                     lightlinks->cameralocation = glGetUniformLocation(com->myshade->returnprogram(), "camerapos");                     lightlinks->shine = glGetUniformLocation(com->myshade->returnprogram(), "shine");                 }                 com->setupstate = true;             }         }
  13. lexington

    Ecs Inheritance Problem (C++)

    @[member='EarthBanana'], The more info and knowledge the better :). Very interesting though as i was worried that having both the vector/map of components for the entity and then also a vector of components for each type of component would be very wasteful (though i could very much be wrong)
  14. lexington

    Ecs Inheritance Problem (C++)

    @[member='Juliean'], Arr thanks for the clear up. I think ill just implement the non template system first and then come back to the auto gen method and seems like a really cool system (thanks for the explanation and code for starting).   Thanks for the help everyone that posted 
  15. lexington

    Ecs Inheritance Problem (C++)

    Hey guys, Thanks for all of the help. I have not really worked with templates and static variables before so have been good to learn about them and how to use them :).     Just one more question, if i have the following structure (based of a more simple version where every struct has its own id preset) like so (just some random components) template <typename comp> struct component { public: virtual int GetType() = 0; private: }; struct positioncomp : public component<positioncomp> { private: static const int TypeID = 1; public: int GetType() { return TypeID;}; int x; int y; int z; }; struct othertest : public component<othertest> { private: static const int TypeID = 2; public: int GetType() { return TypeID; }; int g; char a; }; what would be my std::vector definition im guessing it would be along the lines of  std::vector<component<>*> mycomps; but have no idea what would be in the <>   Thanks again for the help
  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!