1. We have added a Gift Upgrades feature that allows you to gift an account upgrade to another member, just in time for the holiday season. You can see the gift option when going to the Account Upgrades screen, or on any user profile screen.
    Dismiss Notice

Python Performance and Interface Overhaul

Discussion in 'C2C mod mods' started by Toffer90, Jul 7, 2017.

  1. Thunderbrd

    Thunderbrd C2C War Dog

    Joined:
    Jan 2, 2010
    Messages:
    24,728
    Gender:
    Male
    Location:
    Las Vegas
    I probably can. The problem is, there isn't always just one building class. So it's easier for python to query a bool function which is basically asking, is THIS building class included? So a tag like isBuildingClassPrereq(eBuildingClassIndex) would work but getPrereqBuildingClass would not because there's not just one answer.

    You should. I'll set you up with a function for that as well.
    Yeah, I figured there were some examples of that kind of logic. We'll have to do that.
    I understand what you need but got wholely lost in the python syntax you gave as an example there. lol
     
  2. Toffer90

    Toffer90 C2C Modder

    Joined:
    Oct 16, 2011
    Messages:
    5,249
    Location:
    Norway
    That's why the function would take an integer argument that indicates which of the building classes we want the eBuildingClass index for.
    If the tech has two buildingclass requirement:
    CvTechInfo.function( 0 ) would return the eBuildinClass for the first buildingclass requirement listed for the tech that CvTechInfo points to.
    CvTechInfo.function( 1 ) would return the eBuildingClass for the second buyildingclass requirment listed.
    CvTechInfo.function( 2 ) would return -1
    Spoiler Technical stuff :
    That would require the python to loop through all the building classes in the game asking the tech "IsRequiredBuilding(eLoopBuildingClass)" for every one of them.
    Is this smart if the dll can fetch the valid ones directly?
    Wouldn't the dll be faster than python even if it had to loop through all the building classes as well?

    I would really prefer that you make a function that is comparable to this one, that already exist for finding tech requirments for buildings:
    Code:
    int CvBuildingInfo::getPrereqAndTechs(int i) const
    {
        FAssertMsg(i < GC.getNUM_BUILDING_AND_TECH_PREREQS(), "Index out of bounds");
        FAssertMsg(i > -1, "Index out of bounds");
        return m_piPrereqAndTechs ? m_piPrereqAndTechs[i] : -1;
    }
    Spoiler Maybe somethig like this :
    Code:
    int  CvTechInfo::NameOfFunction(int iIndex, int eTech)
    {
             return GC.getTechInfo(eTech).getPrereqBuildingClass(iIndex).eBuildingClass
    }
    
    
    // Or perhaps it would make more sense as a global context function
    
    int  CyGlobalContext::getTechPrereqBuildingClass(int iIndex, int eTech)
    {
             return GC.getTechInfo(eTech).getPrereqBuildingClass(iIndex).eBuildingClass
    }
    
    
    // or even better, it returns what I really need:
    
    CvBuildingClassInfo*  CyGlobalContext::getTechPrereqBuildingClassInfo(int iIndex, int eTech)
    {
             return (i>=0 && i<GC.getNumBuildingClassInfos()) ? &GC.getBuildingClassInfo((BuildingClassTypes)(GC.getTechInfo(eTech).getPrereqBuildingClass(iIndex).eBuildingClass) : NULL;
    }
    
     
    Last edited: Aug 11, 2017
  3. Thunderbrd

    Thunderbrd C2C War Dog

    Joined:
    Jan 2, 2010
    Messages:
    24,728
    Gender:
    Male
    Location:
    Las Vegas
    Rather than struggling to figure out how to arrange that sort of thing, the bool is MUCH easier. (because I can envision how to whereas the others I cannot. Those appear on the surface to me to require a new declaration of a variable which would have a memory impact on the game as a whole.
     
  4. Toffer90

    Toffer90 C2C Modder

    Joined:
    Oct 16, 2011
    Messages:
    5,249
    Location:
    Norway
    Ok, you do know best, I'm happy as long as it becomes possible for the pedia to display what buildings a tech require. ^^

    Spoiler Edit :
    I'm curious about why there would need to be a new variable for what I suggested.
    What would it represent/store?
     
    Last edited: Aug 11, 2017
  5. Dancing Hoskuld

    Dancing Hoskuld Chieftain

    Joined:
    Jul 5, 2004
    Messages:
    22,867
    Gender:
    Male
    Location:
    Canberra, Australia
    Assuming that there is also a boolean test first that says if the tech requires a building or not. If the tech does then the code will have to loop through all buildings to see if it is needed.

    If there isn't a boolean indicating that a tech requires a building then you will have to loop through every building for each tech.

    edit this is a good example of why your data model in the processing area should be different to the storage data model. Basically you would have a new file Tech_Building that only contained two ids, the tech id and the building class id. It would be created at XML loading and would have its methods exposed to Python.

    Although there was a suggestion recently to do away with Building Classes in C2C since it does not have UBs in the same way that vanilla has and it would release memory for other things.
     
    Last edited: Aug 10, 2017
  6. Thunderbrd

    Thunderbrd C2C War Dog

    Joined:
    Jan 2, 2010
    Messages:
    24,728
    Gender:
    Male
    Location:
    Las Vegas
    Part of this is that you're asking for me to delve into a region of knowledge I'm not incredibly comfortable with on a theoretical level - I tend more to parrot this stuff so when there's an example, great, when not... ugh.

    I was thinking on this and I think I've figured out a way to let it run the way you're looking for it to.
     
  7. Toffer90

    Toffer90 C2C Modder

    Joined:
    Oct 16, 2011
    Messages:
    5,249
    Location:
    Norway
    If so, great !
    You never disappoint. ^^
     
  8. Thunderbrd

    Thunderbrd C2C War Dog

    Joined:
    Jan 2, 2010
    Messages:
    24,728
    Gender:
    Male
    Location:
    Las Vegas
    Ok, so you'll have to loop by calling for the tech's getNumPrereqBuildingClasses(). I'm not sure how you'd set it up in python exactly but it looks, again, like this in C++:

    for (iI=0; iI < GC.getTechInfo(eTech).getNumPrereqBuildingClasses(); iI++)
    {

    I'm exposing getNumPrereqBuildingClasses so you can define the loop count and use it to call to the following new functions:
    int getPrereqBuildingClassType(int iIndex);
    int getPrereqBuildingClassMinimumRequired(int iIndex);

    so continuing syntax use in the DLL as an example:

    Code:
    int iRequired = 0;
    for (iI=0; iI < GC.getTechInfo(eTech).getNumPrereqBuildingClasses(); iI++)
    {
              if (GC.getTechInfo(eTech).getPrereqBuildingClassType(iI) != -1)
              {
                        BuildingClassTypes eBuildingClass = (BuildingClassType)GC.getTechInfo(eTech).getPrereqBuildingClassType(iI);
                        iRequired = GC.getTechInfo(eTech).getPrereqBuildingClassMinimumRequired(iI);
                        //Then do whatever you're going to do with it.
              }
    }
    Hopefully you're code bi-lingual enough to sort that out. From previous comments, I think you are.

    aka when the tech's getNum index number is handed off to the parameter of getPrereqBuildingClassType, you will get a return of the buildingclass index # in that slot. And when you hand it off to the parameter of getPrereqBuildingClassMinimumRequired, you'll get the minimum amount of those buildings that must be built to enable the tech.

    This works the same with these tags as well:
    int getNumPrereqOrBuildingClasses() const;
    int getPrereqOrBuildingClassType(int iIndex);
    int getPrereqOrBuildingClassMinimumRequired(int iIndex);

    The new tags are purely for reporting to python for you to convert to a simpler method. It was surprisingly easy to do this - I was just overthinking things and letting my lack of comfort in this area confound my mind until I thought on it in the background for a while. I've been stuck on xml and spreadsheeting for so long that I'm starting to get a little rusty minded on coding already.

    This should be on the SVN in an hour or so once compiling is complete.
     
  9. Little Abigail

    Little Abigail Chieftain

    Joined:
    Sep 26, 2012
    Messages:
    61
    I really have to say, thanks a lot for this mod. I've found I actually use the sevopedia a whole lot more then I used to now that it doesn't take eighty years to load every time I want to check something out. I really noticed it when I forgot to re-add it after updating the version and had to immediately quit and re-add it so I could use it. 10/10 mod, would recommend.
     
  10. AIAndy

    AIAndy Chieftain

    Joined:
    Jun 8, 2011
    Messages:
    3,382
    While this is an appropriate way to do that (and it is done the same way at several other places in the code), it is actually possible to expose the vector of struct directly as a Python container (which in turn allows some nicer Python code).
    For that you expose the struct and then the vector with the vector_indexing_suite.
    See here:
    https://stackoverflow.com/questions/43107005/exposing-stdvectorstruct-with-boost-python
    http://www.boost.org/doc/libs/1_32_0/libs/python/doc/v2/indexing.html
     
  11. Toffer90

    Toffer90 C2C Modder

    Joined:
    Oct 16, 2011
    Messages:
    5,249
    Location:
    Norway
    I tested the functions and they work as expected. :cheers:
     
  12. Thunderbrd

    Thunderbrd C2C War Dog

    Joined:
    Jan 2, 2010
    Messages:
    24,728
    Gender:
    Male
    Location:
    Las Vegas
    Good to know. I'll have to research that further.

    Glad to hear it worked for you Toffer! :D
     
  13. Toffer90

    Toffer90 C2C Modder

    Joined:
    Oct 16, 2011
    Messages:
    5,249
    Location:
    Norway
    Here's another one that could be nice to have exposed to python:

    bool CvPromotionLineInfo::isBuildUp() const
    {
    return m_bBuildUp;​
    }

    I can make a build up sub category by looking at the description name, all build up names start with "Build up".
    But that function makes it a bit more flexible in case we wan't to change naming conventions for those types of promos.
     
  14. Thunderbrd

    Thunderbrd C2C War Dog

    Joined:
    Jan 2, 2010
    Messages:
    24,728
    Gender:
    Male
    Location:
    Las Vegas
  15. Toffer90

    Toffer90 C2C Modder

    Joined:
    Oct 16, 2011
    Messages:
    5,249
    Location:
    Norway
    v0.3
    • Promotions screen improvements
    • Techs now list building requirements in the requirement panel.
     
  16. raxo2222

    raxo2222 Warlord

    Joined:
    Jun 10, 2011
    Messages:
    4,769
    Location:
    Poland
    Is it possible to sort buildings (all types)/units/civics/promotions/improvements chronologically?
    If they would require 2 or more techs, then tech with highest X number should be selected, in case of same X, then Y coordination would be selected.
    You could create new category named "Chronology", where techs, buildings, units, civics, promotions and improvements are sorted by technology position in tree.

    That would be bit indirect unlike with techs - first you would need to scan tech requirements in these "unlockables", then pick farthest tech in tree and finally place it in proper position.
     
    Last edited: Aug 12, 2017
  17. Toffer90

    Toffer90 C2C Modder

    Joined:
    Oct 16, 2011
    Messages:
    5,249
    Location:
    Norway
    It is, but I won't do it.
     
  18. raxo2222

    raxo2222 Warlord

    Joined:
    Jun 10, 2011
    Messages:
    4,769
    Location:
    Poland
    why?
     
  19. Toffer90

    Toffer90 C2C Modder

    Joined:
    Oct 16, 2011
    Messages:
    5,249
    Location:
    Norway
    First of all, I have more important aspects to focus on improving in the pedia. It's a bit about what I'm motivated to work on as well.
    Additionally, there is little need for such lists, and the required code would spaghettify a lot of the pedia code reducing its readability and performance unnecessarily.

    I might look into it when I feel the pedia modmod is closer to finished.
     
  20. JosEPh_II

    JosEPh_II TBS WarLord

    Joined:
    Jun 20, 2007
    Messages:
    14,963
    Gender:
    Male
    Location:
    Western IL. cornfields
    Thank you for what you have accomplished! Good Stuff! :thumbsup::hatsoff:
     
    Toffer90 likes this.

Share This Page