Possible alternate future approach to improving scalability and performance

Koshling

Vorlon
Joined
Apr 11, 2011
Messages
9,254
This post is primarily aimed at modders, or anyone else with a software background. Anyone is welcome to chip in though, or to ask questions.

Outline

I was thinking about a possible alternative to the start-again approach of AXXXE to extending the lifetime of C2C. The following is an outline:

Suppose, instead of trying to start from scratch (AXXXE approach), we were to stick with the Civ4 engine, and seek to restructure the DLL as follows (this is a recipe of fairly [haha] mechanical steps):

1) Introduce proxy classes for all entities visible to the game engine (in much the same way as we did for maps when adding viewports). These proxies would contain no intelligence and no data apart from that required by the interface to the game engine (so basically things that are 'visible' like a unit's strength, but not internals like all its combat modifiers). Any state-modifying methods, or request for data that cannot be satisfied without calculations involving hidden variables are passed to the underlying real entity class. All external APIs go to the proxies. Python APIs also have to talk through the proxies (why will become apparent shortly).

2) Move all the data in the proxies out of those classes into flat structs with a 'dirty' flag. On read the proxy consults the dirty flag, if not set reads the data from the struct, else calls an 'update' method on the underlying class, which responds by updating the struct and clearing the dirty flag.

3) Split the DLL apart so that the actual DLL contains only the proxies, and the remainder moves into it's own EXE (which is auto-launched by the DLL). The flat structs move into shared memory. The direct calls that remain move into some sort of IPC (probably a simple command/response over a duplex named pipe, or something).

4) Change the build settings on the new EXE - multithreaded runtime, 64 bit, optimization flags set to make appropriate use of more modern CPU architectures

5) Multithread the stuff in the EXE as we see fit

Pros and cons:

Relative to the current situation:

Pros:
  • Most non-graphical memory usage is moved out of the Civ4 engine process, giving it more room to work for its graphics - less MAFs
  • Multi-threading is a bit easier because we have more complete control over the flow control
  • 64 bit process means we can scale a lot better (at least for non-graphical aspects)
  • By caching the shared data it should be possible to page in (to the Civ4 engine process) only what it needs at the time (again better memory scalability)
  • Freedom to optimize without having to worry about the runtime constraints the Civ4 EXE imparts (so can move to a modern compiler for the EXE with modern code optimization)
Cons:
  • Potential for performance issues with Python since it has to funnel everything across the IPC boundary via the proxies, so some patterns of use will potentially slow down
  • XML loading might have to stay in the DLL (certainly it will if we want to continue to use the provided parser), which implies the need for some mechanism to pass the parsed data across the IPC boundary (actually the cached version that AIAndy added might serve the purpose, so writing it is always DLL-side, but reading it is EXE side)
  • No benefit (and indeed extra overhead) for people with 32 bit OS's or less than 4G RAM

Relative to the AXXXE approach:

Pros:
  • No grey areas in regard to copyright - we are clearly still only operable under a bought CiV4
  • Full compatibility with existing assets and asset-generation techniques
  • Much easier

Cons:
  • Stuck with C++ (well, in principle you could replace the EXE part with anything, provided it could expose the right shared memory structures, but practically...)
  • Stuck with current codebase, with all its warts, and non-generic solutions (but that's also why this approach is way easier of course)
  • Stuck with limitations of the Civ4 engine for graphics - that limits scalability due to the memory-hungryness of it, and still doesn't help us with multimaps except via the viewport mechanism as we are intending now

It certainly wouldn't be a small amount of work (or one that would be certain to yield a sufficiently preformant result, so it is somewhat speculative), but I think it would be doable in something like the timeframe of 1-2 release cycles.
 
Hmm, interesting. But I wonder how much effort a proper implementation of the proxy and caching mechanism will be and the memory overhead from the duplicated information might be high.

Especially the amount of information that Python code might query both for gameplay and display purposes could cause a lot of interprocess communication.
And any access to the shared memory also requires synchronization.

If we go that way, I would also suggest to get rid of the current XML parser as it is really slow because of all the schema processing and also has some really weird behavior.

Edit: Btw, we would also need to make sure the structs are binary compatible which often but not always is the case between different compilers.
 
As usually I am stunned by you guys expertise and creativity.

One thing I don't get is why the people owning the commercial rights of civ are not seeing the opportunity to (partly) update this old game to 64bit and making it attractive for new customers with for example all the content C2C provides?

If they stopped development, they really should be glad someone is trying to do this (for free!) and at least provide an authorisation to alter the exe for said purposes?

What are they thinking - if they are thinking at all about this old game - isn't this approach in their interests? Think about it executives, nothing to lose and all to win, just give the coders the code and you will have better income. Not so hard, is it?

God, I hate the system with licenses, it really hinders progress...

sorry for my rant but can't we maybe try to get help from them is there any way possible? As I said wouldn't it be good for them to get an "update" for their engine this way?

Maybe we could write a petition that explains the idea to them and the benefits in prospect and then have a lot of people of the civ community sign it?
 
Hmm, interesting. But I wonder how much effort a proper implementation of the proxy and caching mechanism will be and the memory overhead from the duplicated information might be high.

Especially the amount of information that Python code might query both for gameplay and display purposes could cause a lot of interprocess communication.
And any access to the shared memory also requires synchronization.

If we go that way, I would also suggest to get rid of the current XML parser as it is really slow because of all the schema processing and also has some really weird behavior.

Edit: Btw, we would also need to make sure the structs are binary compatible which often but not always is the case between different compilers.

On the different compilers - that's partly why I want flat structs only. Assuming we're only talking about Microsoft compilers (for C++) [which is where I was intending to go] then a few judicious #pragma packs will usually sort things out.
 
I've often wondered if Firaxis could be persuaded to perhaps sell us rights to the exe...

I'm going to have to try to break down what you explained into something I can really understand. I'm only very vaguely able to follow what you explained, particularly since multi-threading sounds like its an added complexity that scares the hell out of me. How would this new methodology change the way we create new tags?
 
@Koshling
My programing skills are very limited but if I understand you right that seems HUGE! So if I understand you right basically graphics stay under the Civ4 exe which limits everything to 1 core and then you make a new exe that funnels everything else to it so it can access the rest of your cores (if you have them)? :eek:

@DRJ
Sadly I think their view is "Civ4 is obsolete. Go play Civ5!"
 
@Koshling
My programing skills are very limited but if I understand you right that seems HUGE! So if I understand you right basically graphics stay under the Civ4 exe which limits everything to 1 core and then you make a new exe that funnels everything else to it so it can access the rest of your cores (if you have them)? :eek:

@DRJ
Sadly I think their view is "Civ4 is obsolete. Go play Civ5!"

Yeh - they are a commercial organization. How is it in their interests to promote a competitor to their supported game. It encourages purchases of heavily discounted old versions, discourages upgrade purchases, and attaches their monikor (for advertising/reputational purposes) to something they do not control. No up-side for them.
 
I've often wondered if Firaxis could be persuaded to perhaps sell us rights to the exe...

@Koshling
@DRJ
Sadly I think their view is "Civ4 is obsolete. Go play Civ5!"

Is Fireaxis who owns Civ4? the same company owning civ5 commercial rights or are they profit-sharing for the original trademark etc?

If so, the negligence yet standing guard on the exe would be strategy to boost civ5 sales.

If not, maybe a crowdfunding would be able to collect a little money (I would gladly contribute some Euros), and the dealsealing argument could be that the improved, final multithreaded C2C would be like "DLC" 1 Euro or something and all the gains from that "special C2C" would also flow into the "community exe buy fund".
So they would have a commercial interest in selling as the more the "improved" Civ4 DLC flourishes it would also give them additional revenue over time.

Again, in short and slightly other words:

community buys exe for a small price but grants to use it only for a "C2C dlc" which then generates some income that raises the original small buying price over time (and pays the leading programmers of the multithread conversion some allowance!!!).

Even contemplating ideas to give them more profit and reward their disregard makes me headdaches and usually, I am totally against DLC and stuff but I would really give it gladly if I could see C2C flourish on intermediate-terms.

So to get them moving we would have to awaken their greed I guess.
The question would be how much greed do they have? Do they speculate on drowning Civ4 no matter what to push overpriced Civ5 stuff. Is it really the same company?
 
Pros:
  • No grey areas in regard to copyright - we are clearly still only operable under a bought CiV4
  • Full compatibility with existing assets and asset-generation techniques
  • Much easier

Cons:
  • Stuck with C++ (well, in principle you could replace the EXE part with anything, provided it could expose the right shared memory structures, but practically...)
  • Stuck with current codebase, with all its warts, and non-generic solutions (but that's also why this approach is way easier of course)
  • Stuck with limitations of the Civ4 engine for graphics - that limits scalability due to the memory-hungryness of it, and still doesn't help us with multimaps except via the viewport mechanism as we are intending now

It certainly wouldn't be a small amount of work (or one that would be certain to yield a sufficiently preformant result, so it is somewhat speculative), but I think it would be doable in something like the timeframe of 1-2 release cycles.


The main issue I have with this is that you are essentially suggesting to keep using the Civ 4 engine while making AXXXXE-like ruleset management (and technology). However this runs in to the fundamental problem that Civ 4 modding, and C2C particularily, is running on fumes technologically. And if you spend all of that effort on writing good efficent code for civ 4 scalability none of that will legally be usable if/when you want to move to a new platform. Combined with the 'patchwork quilt' setup of C2C currently (which consists of dozens of old modcomps, assets, and code, lots of which are in fact unused or poorly understood) and the sorry state of balance in many places it seems like this is to a certain extent tilting at windmills.

I personally feel (and remember that this is coming from the person who doesn't really like the way C2C is now) that starting on AXXXXE would be better and that C2C should be let to die a natural death. That would mean that we wouldn't have a good playable product for a year or so, but such an outcome is inevitable and procrastination will only delay it. However, the great benefits would be that we would have a unified generic codebase for the engine and a modern graphics backend. We could contact xanhou (who has been on the forums but not worked a whole lot on AXXXXE in the past month) and ask if we could reuse the code he has already written to get a head start on the graphics part, and also potentially use 2d graphics like in freeciv to do engine testing.

The very obvious problem with this is of course getting graphical assets. However, I think that if we were to release a proof of concept engine demo with 2d art and basic gameplay, and explain the technical promise of it and that we need art that we could get CFCers to make assets for the new engine (because many Civ 5 people hate how hard it is to make art for that platform). It is risky, but I think the only real option long-term.

Another plus would be that I'd be far more interested in working on something in C# and with a modern IDE (I absolutely love VS 2012), and with basically no pre-existing game design constraints than I am now in working on C2C.

Thoughts everyone?
 
The main issue I have with this is that you are essentially suggesting to keep using the Civ 4 engine while making AXXXXE-like ruleset management (and technology). However this runs in to the fundamental problem that Civ 4 modding, and C2C particularily, is running on fumes technologically. And if you spend all of that effort on writing good efficent code for civ 4 scalability none of that will legally be usable if/when you want to move to a new platform. Combined with the 'patchwork quilt' setup of C2C currently (which consists of dozens of old modcomps, assets, and code, lots of which are in fact unused or poorly understood) and the sorry state of balance in many places it seems like this is to a certain extent tilting at windmills.
[Snip]
Thoughts everyone?

x10^googol
 
I have thought a bit more about that and I think the only way to have this work in a good way is to move most of the Python to the other process as well so it can access the game information in a performant way.
If that works depends on how often the engine makes calls into Python.
 
I have thought a bit more about that and I think the only way to have this work in a good way is to move most of the Python to the other process as well so it can access the game information in a performant way.
If that works depends on how often the engine makes calls into Python.

I don't think that can work, because the engine itself (the Civ4 one) exposes some interfaces directly to Python without the DLL as intermediary (I believe)
 
I don't think that can work, because the engine itself (the Civ4 one) exposes some interfaces directly to Python without the DLL as intermediary (I believe)

The various Python classes related to putting thing on screen are directly connected to the .exe, and some other things too (although at least some of them end up running something in the DLL, it is called from the exe end). Some of the screen related functions, at least, are called a lot.

Classes in the Python Class Reference that mention that they are not in the DLL:
CyDiplomacyResponse
CyAudioGame
CyCamera
CyDiplomacy
CyEngine
CyFractal
CyGFlyoutMenu
CyGInterfaceScreen
CyGTabCtrl
CyGlobeLayer
CyGlobeLayerManager
CyInterface
CyMessageControl (home of the infamous "mod net message")
CyPopup
CyPopupInfo
CyPopupReturn
CyPythonMgr
CySign
CyStatistics
CyTranslator
CyUnitEntity
CyUnitSubEntity
CyUserProfile
CyVariableSystem
NiMatrix3
WidgetAnim

That's quite a few things, some of which are very important (and some of which are not actually used in any Python I have ever seen).
 
I don't think that can work, because the engine itself (the Civ4 one) exposes some interfaces directly to Python without the DLL as intermediary (I believe)
I am not suggesting completely shutting down the Python environment in the 32bit process but move most of the code (especially everything that does not have to do with UI) and whenever a use of the Python only Exe API is needed from the moved code, route it through some IPC.
 
Removing Python sounds like a way to shut people out of modding.:(

Nobody is suggesting removing Python - we're simply discussing the performance aspects of whether it would be hosted in the 64-bit environment or the 32-bit one (or both, in which case the question of how to synchronize long-lived globals between them would probably be somewhat vexing)
 
Speculative and maybe stupid post, but here it is:
If i`m understand correctly, exe after started , start dll and then dll launch python modules.
If it this way then - can dll be transformed to stub(or proxy as Koshling named it) and maximum of functionality exported to python and\or other external program with own system process.
Exported process (in other way additional program to civ engine) as stated above will have all benefits we want and only problem is communication with civ engine. In this situation DB can be used that controlled by python library and available for civ engine and for exported process transparently and concurrently. And last thing - for all this to work - as i understand in dll or using python - some sort of arbiter class \ module need to be made. Arbiter will control all data transactions between exported process and civ engine, also he will control data reading \writing.
 

Attachments

  • ??????? ??? ???????? (1).jpg
    ??????? ??? ???????? (1).jpg
    22.2 KB · Views: 112
As usually I am stunned by you guys expertise and creativity.

One thing I don't get is why the people owning the commercial rights of civ are not seeing the opportunity to (partly) update this old game to 64bit and making it attractive for new customers with for example all the content C2C provides?

If they stopped development, they really should be glad someone is trying to do this (for free!) and at least provide an authorisation to alter the exe for said purposes?

What are they thinking - if they are thinking at all about this old game - isn't this approach in their interests? Think about it executives, nothing to lose and all to win, just give the coders the code and you will have better income. Not so hard, is it?

God, I hate the system with licenses, it really hinders progress...

sorry for my rant but can't we maybe try to get help from them is there any way possible? As I said wouldn't it be good for them to get an "update" for their engine this way?

Maybe we could write a petition that explains the idea to them and the benefits in prospect and then have a lot of people of the civ community sign it?

Is Fireaxis who owns Civ4? the same company owning civ5 commercial rights or are they profit-sharing for the original trademark etc?

If so, the negligence yet standing guard on the exe would be strategy to boost civ5 sales.

If not, maybe a crowdfunding would be able to collect a little money (I would gladly contribute some Euros), and the dealsealing argument could be that the improved, final multithreaded C2C would be like "DLC" 1 Euro or something and all the gains from that "special C2C" would also flow into the "community exe buy fund".
So they would have a commercial interest in selling as the more the "improved" Civ4 DLC flourishes it would also give them additional revenue over time.

Again, in short and slightly other words:

community buys exe for a small price but grants to use it only for a "C2C dlc" which then generates some income that raises the original small buying price over time (and pays the leading programmers of the multithread conversion some allowance!!!).

Even contemplating ideas to give them more profit and reward their disregard makes me headdaches and usually, I am totally against DLC and stuff but I would really give it gladly if I could see C2C flourish on intermediate-terms.

So to get them moving we would have to awaken their greed I guess.
The question would be how much greed do they have? Do they speculate on drowning Civ4 no matter what to push overpriced Civ5 stuff. Is it really the same company?

lurker's comment: You'd need a lot of luck. This sort of thing was looked into seriously in the Civ3 community several years ago (2009), including by people with contacts in Firaxis and on their board, and the end result was that the rights/ability to make a community patch/etc. were "not for sale, at any price". Though perhaps different licensing by Firaxis would result in Civ4 being more flexible, and perhaps time will have changed things, I wouldn't count on it.

Though it would certainly be nice, even if the modification was as limited as making a 64-bit version.
 
lurker's comment: You'd need a lot of luck. This sort of thing was looked into seriously in the Civ3 community several years ago (2009), including by people with contacts in Firaxis and on their board, and the end result was that the rights/ability to make a community patch/etc. were "not for sale, at any price". Though perhaps different licensing by Firaxis would result in Civ4 being more flexible, and perhaps time will have changed things, I wouldn't count on it.

Though it would certainly be nice, even if the modification was as limited as making a 64-bit version.

This is why we probably will end up making a new game entirely at some point in the future (with modern technologies and open source to allow for evolution).
 
I haven't even played CiV.
Not cause I wasn't able - but cause I read and watched stuff about it, and it SUCKS!
Even compared to CIV, not to mention C2C...
I'm so waiting for the MODERN possibility to play C2C...
Man, IF/WHEN (sadly, yeah) we're able to actually utilize MODERN computers for it - wow,I can't even think about how long I'll stay playing, possibly overnight for sure... :lol:
 
Back
Top Bottom