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 (PPIO)

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

  1. KaTiON_PT

    KaTiON_PT Emperor

    Joined:
    Jan 2, 2010
    Messages:
    1,090
    Location:
    Portugal
    @Toffer90 alright I started to see if I could get that to run. I corrected a few minor things so that c++ is able to read the code but I'm getting issues with defining 'duration' and 'format'. Here's the error log (9 errrors):
    Code:
    Severity    Code    Description    Project    File    Line    Suppression State
    Error    C2734    'duration' : const object must be initialized if not extern    C2C    D:\C2C\Caveman2Cosmos\Sources\CvPlayer.cpp    6593  
    Error    C2373    'duration' : redefinition; different type modifiers    C2C    D:\C2C\Caveman2Cosmos\Sources\CvPlayer.cpp    6593  
    Error    C3861    'duration': identifier not found, even with argument-dependent lookup    C2C    D:\C2C\Caveman2Cosmos\Sources\CvPlayer.cpp    6612  
    Error    C2374    'format' : redefinition; multiple initialization    C2C    D:\C2C\Caveman2Cosmos\Sources\CvPlayer.cpp    6616  
    Error    C2734    'duration' : const object must be initialized if not extern    C2C    D:\C2C\Caveman2Cosmos\Sources\CvPlayer.cpp    6616  
    Error    C2373    'duration' : redefinition; different type modifiers    C2C    D:\C2C\Caveman2Cosmos\Sources\CvPlayer.cpp    6616  
    Error    C2086    'char buf[2048]' : redefinition    C2C    D:\C2C\Caveman2Cosmos\Sources\CvPlayer.cpp    6617  
    Error    C3861    'format': identifier not found, even with argument-dependent lookup    C2C    D:\C2C\Caveman2Cosmos\Sources\CvPlayer.cpp    6618  
    Error    C3861    'format': identifier not found, even with argument-dependent lookup    C2C    D:\C2C\Caveman2Cosmos\Sources\CvPlayer.cpp    6618  
    
    I might ask in the CIV4 modding forum about this...
     
  2. Toffer90

    Toffer90 C2C Modder

    Joined:
    Oct 16, 2011
    Messages:
    7,195
    Location:
    Norway
    @Thunderbrd : probably have some insight in what causes such errors.
    I believe it has something to do with proper initialization/declaration of new variables within the scope you are working within.

    From the first errors it looks like you declared 'duration' as a const (constant)... C2734
    const unsigned long duration;

    Did you have this twice in the code? C2374
    const char* format =​
    The second time you should just have:
    format =​
    I provided that mistake in my code example...

    I think the way the format variable is set is all wrong.
    Maybe it should be more like this:
    TCHAR szOut[2048];
    sprintf(szOut, "Dll duration: %d ms.", duration);
    gDLL->logMsg("Test.log", szOut);
    I edited the code example post I made with adjustments based on your errors.
     
    Last edited: Jan 18, 2019
    KaTiON_PT likes this.
  3. Thunderbrd

    Thunderbrd C2C War Dog

    Joined:
    Jan 2, 2010
    Messages:
    28,043
    Gender:
    Male
    Location:
    Las Vegas
    Are those errors you're getting on compile? The do sound like familiar issues that are all probably fairly easily solved syntax oopses. Show me the code and what the errors are referring to. (double click on the error line to get it to go to the line it's saying is in error)
     
  4. KaTiON_PT

    KaTiON_PT Emperor

    Joined:
    Jan 2, 2010
    Messages:
    1,090
    Location:
    Portugal
    @Toffer90 that worked. Managed to compile :) Got this while processing a turn with Vanilla:
    Code:
    [795724.500] Python duration: 0 ms.
    [795724.500] Dll duration: 0 ms.
    [795729.250] Python duration: 0 ms.
    [795729.250] Dll duration: 0 ms.
    
    EDIT: On another run I managed to get something:
    Code:
    [796480.875] Dll duration: 0 ms.
    [796480.875] Python duration: 1 ms.
    
     
    Last edited: Jan 18, 2019
  5. Toffer90

    Toffer90 C2C Modder

    Joined:
    Oct 16, 2011
    Messages:
    7,195
    Location:
    Norway
    Change the %d to a %f:
    sprintf(szOut, "Dll duration: %f ms.", duration);​
    We need float precision. ^^
     
    KaTiON_PT likes this.
  6. KaTiON_PT

    KaTiON_PT Emperor

    Joined:
    Jan 2, 2010
    Messages:
    1,090
    Location:
    Portugal
    By the way, I've been compiling the debug version, should I test with the release one?
     
  7. Toffer90

    Toffer90 C2C Modder

    Joined:
    Oct 16, 2011
    Messages:
    7,195
    Location:
    Norway
    Wouldn't that be easier for you, takes less time to test it.
     
    KaTiON_PT likes this.
  8. KaTiON_PT

    KaTiON_PT Emperor

    Joined:
    Jan 2, 2010
    Messages:
    1,090
    Location:
    Portugal
    Having a hard time making them appear in the logs. :\ I know the code runs as I see the score being updated but on the logs it's like nothing is happening.
    Code:
    [800277.000] Python duration: 0.000000 ms.
    [800277.000] Dll duration: 0.000000 ms.
    
    Tried to output %d and a (%f) in the logs.
    Code:
    [809831.125] Dll duration: 0 (0.000000) ms.
    [809831.125] Python duration: 1 (0.000000) ms.
    
    So the float isn't being written. :undecide:
     
    Last edited: Jan 18, 2019
  9. Toffer90

    Toffer90 C2C Modder

    Joined:
    Oct 16, 2011
    Messages:
    7,195
    Location:
    Norway
    Hmm, let's do a last try where we use:

    /* clock_t, clock, CLOCKS_PER_SEC comes from this include*/
    #include <time.h> \\ This needs to be somewhere in the file, probably at the top of the file.

    clock_t clocks = clock();
    ... ... ... // code
    clocks = clock() - clocks;
    TCHAR szOut[2048];
    sprintf(szOut, "Python took %d clicks (%f seconds).\n", clocks, ((float) clocks) / CLOCKS_PER_SEC);​

    CLOCKS_PER_SEC should be a built in MACRO from the time.h standard library.

    Remove all the XMLPlatformUtils stuff; I guess it isn't valid code.
    The only place I saw XMLPlatformUtils used for timing was in:
    Caveman2Cosmos\Sources\xerces-c-3.1.1-x86-windows-vc-7.1\samples\src​
    Which isn't code that is processed when playing the game as far as I understand, probably not included in the dll at all.
     
    Last edited: Jan 23, 2019
  10. KaTiON_PT

    KaTiON_PT Emperor

    Joined:
    Jan 2, 2010
    Messages:
    1,090
    Location:
    Portugal
    Alright, I got this. Can confirm equal results with VS profiler:
    Code:
       Vanilla    |     PPIO
    C++  | Python | C++  | Python
    4 ms |  0 ms  | 3 ms |  3 ms
    
    The 0 ms is because the code isn't being processed.
     
  11. Toffer90

    Toffer90 C2C Modder

    Joined:
    Oct 16, 2011
    Messages:
    7,195
    Location:
    Norway
    PPIO v0.6
    SVN rev.10384
    • Overhauled\revised the barbarian civ module.
      • That is the module/"game option" that make minor civs emerge from barbarian cities, and when they may become major cities, where new world landmasses have its own rules.
      • 2000 lines of spaghetti code got reduced to 700 lines of optimized and orderly code.
      • Should result in a noticeable improvement in turn times.
      • The rules and technical mechanics of it have changed quite a bit, will probably need later adjustments to get it tuned perfectly in.
    • Optimized some misc code here and there too.
    • The start as minor civs option will now function a bit differently if barbarian civ option is active.
      • The barbarian civ feature code does no longer discriminate between difference minor civs when deciding when they deserve to become major civs, which is based on accomplishments and a random roll every turn.
      • A civ that have been a minor civ since turn 0 can become a major civ before discovering writing, through the barbarian civ code.
      • Discovering writing will still make you a major civ right away if the "start as minor" option is active.
    Note: It is recommended to delete the whole UserSetting folder for this update, but you might get away by just deleting the revolution.ini file within it.
    P.S. This update has not been tested much, so I hope you all will keep an eye on how the barbarian civ feature is operating. Please report any oddities about it if you see one.
    I hope I managed to include all the modified files in this update.
    Awesome that you figured it out, would have been nice with an float result instead of a rounded integer though. It should be possible if the "sprintf(" formatting is done correctly.

    Since it's close to equal at the ms scale, I would suggest that we let python handle the score calculation as it makes it easier to adjust/mod later if needed.
     
    Last edited: Jan 23, 2019
    Snofru1, raxo2222 and KaTiON_PT like this.
  12. KaTiON_PT

    KaTiON_PT Emperor

    Joined:
    Jan 2, 2010
    Messages:
    1,090
    Location:
    Portugal
    I will commit that then once I deal with the rest of the [LINK=literal] you reported.
     
    Toffer90 likes this.
  13. raxo2222

    raxo2222 Time Traveller

    Joined:
    Jun 10, 2011
    Messages:
    7,791
    Location:
    Poland
    @Toffer90 compatibility with last SVN was bit short, as I updated Python file, that you touched :p

    What happened to python files, as they are 0 sized? Where code was moved?
     
  14. Toffer90

    Toffer90 C2C Modder

    Joined:
    Oct 16, 2011
    Messages:
    7,195
    Location:
    Norway
    The answer is different depending on the python file in question.
    A lot of python code was moved into CvEventManager, but some went elsewhere.
     
    Last edited: Jan 24, 2019
    raxo2222 likes this.
  15. KaTiON_PT

    KaTiON_PT Emperor

    Joined:
    Jan 2, 2010
    Messages:
    1,090
    Location:
    Portugal
    @Toffer90 I'm ready to upload the changes but there's still the issue of the score not being properly working/updated for those who don't use PPIO.
     
  16. Toffer90

    Toffer90 C2C Modder

    Joined:
    Oct 16, 2011
    Messages:
    7,195
    Location:
    Norway
    Right, I'll look at the py code in the svn and figure out why it isn't doing its job.
     
  17. KaTiON_PT

    KaTiON_PT Emperor

    Joined:
    Jan 2, 2010
    Messages:
    1,090
    Location:
    Portugal
    Here's the compiled .dll if you want to test with that.
     

    Attached Files:

  18. Toffer90

    Toffer90 C2C Modder

    Joined:
    Oct 16, 2011
    Messages:
    7,195
    Location:
    Norway
    That could help.
    When you did the test without PPIO, were you on SVN rev. 10379 or newer?
    The strange thing is that the SVN code for it is identical to the PPIO code... so I'll have to look at the framework around the code.
     
    Last edited: Jan 24, 2019
  19. KaTiON_PT

    KaTiON_PT Emperor

    Joined:
    Jan 2, 2010
    Messages:
    1,090
    Location:
    Portugal
    Yes the tests were made post 10379.
     
  20. Toffer90

    Toffer90 C2C Modder

    Joined:
    Oct 16, 2011
    Messages:
    7,195
    Location:
    Norway
    PPIO v0.6.0.1
    SVN rev.10399
    • Some minor code clean up.
     

Share This Page