AI Turn Speed Up Mod [1.13 MP][message #266463]
|
Mon, 08 November 2010 04:51
|
|
tazpn |
|
Messages:99
Registered:December 2007 Location: CA, USA |
|
|
Overview:
These modifications speed up the clock during non-player turns which in effect speeds up the rate at which combat resolves. My experience is that it speeds up the player turn by about 5 times the vanilla exe and 4 times faster than with TURN_SPEED_UP_FACTOR set to 0.
Its more indiscriminant than the animation speedup factors which have separate settings for player, enemy, creature, militia, civilian turns since I really only want to speed up non-player turns and do not want to have that granularity though it could be done.
First I am aware of the *TURN_SPEED_UP_FACTOR settings in the INI file but I just never found that they really had that much of an influence in the turn speed. No offense to the developer that did it as I think its clever but not very effective in my testing anyway.
Here is an outline of the major changes:- In Utils/Timer Control.cpp, set timer event update frequency to minimum resolution of the system.
- Use QueryPerformanceCounter to track time, unlike timeGetTime it wont wrap around periodically
- Every BASETIMESLICE update the counters like we would have if we left update period alone above
- When the FastForwardMode is active then just update the timers 1/FAST_FORWARD_PERIOD times faster. This artificially speeds up time for everything.
- Disable the fast forward mode at start of team turns if its OUR_TEAM and enable if its another factions turn.
Some of the issues I had:- Using GetAsyncKeyState to test for whether keys are pressed. I prefer this than trying to hook into the keyboard handling in the rest of the system. Probably ok for this application but would not suggest using it generally.
- In sgp.cpp, I need to run GameLoop faster than the windows timer is capable (1 ms). In effect, I ended up moving the game loop out of the main thread into its own thread which could potentially introduce multithreading problems but has worked well for me.
- Hook into TeamTurns.cpp for the automatic fastfwd mode, here at the start of team turns I turn on flag if its not OUR_TEAM. Also need to turn off when our team gets an interrupt request. At the end of interrupt I reset the flag again based on whose turn it is.
- Couldn't figure out how to make the INI Editor allow Strings. It just wants numeric and boolean setting apparently.
- Now this mod in theory can effect AI ability and dumb it down by shorting it of calculation time. I've tweaked it to my computer settings and do not observe any issues with the AI.
Here are my files for the source directory for the JA2 1.13 MP mod (I also have one for the main branch but its older) as well as a build of the EXE for revision 3882 of the source code.
http://www.megaupload.com/?d=T8CTIXC3
http://www.sendspace.com/file/68km7i
http://www.mediafire.com/?gqdcqvl2jtlomyv
The actual reason I'm presenting this again is that I brought it up on the rpgwatch forum when discussing the JA2.5 Reloaded decision to go real-time. I thought that JA2 could still be improved on the turn-based side as it takes the AI a long time to resolve combat sometimes. Anyway, I've presented this previously in the discussion area but made a number of changes since then and felt this is a more relevant forum since this is closer to a mod now.
To enable:- Goto Options Screen. Select Next. Select "Auto Fast Forward AI Turns"
To enable override key:
- Edit the Ja2_Options.ini file. (Without INI Editor since it cannot handle strings.)
- Set [Graphic Settings]FAST_FORWARD_KEY to your preferred key. I used "FAST_FORWARD_KEY = SUBTRACT" to use the numpad - key.
----------------------------------
Now to try to actually backup my claims, I present my comparison of the different configurations.
Base: JA2 1.13 MP Release EXE
FF: JA2 1.13 MP Release EXE with these modifications (FF = FastForward)
Vanilla: JA2_Options.INI as committed to SVN
TURN_SPEED_UP_FACTOR=0: Set TURN_SPEED_UP_FACTOR=0 in the JA2_Options.INI file
FAST_FORWARD=On: Set "Auto Fast Forward AI Turns" in the Options when running the FF EXE.
Setup:- Create new game with base 1.13 for Urban Chaos Mod (Chosen because of large battle at beginning with lots of militia and enemies)
- Dont move. Wait for first sighting.
- Save
When I've done this most games the first turn takes about 20-40 seconds to resolve Enemy, Militia, Civilian turns normally.
Now try each variant, use a timer, start when pressing the Done button, end when player has control again (repeat 4 times and average result):
- Base, Vanilla: Average of 35 sec
- Base, TURN_SPEED_UP_FACTOR=0: Average of 29 sec
- FF, Vanilla: Average of 18 sec
- FF, TURN_SPEED_UP_FACTOR=0: Average of 15 sec
- FF, FAST_FORWARD=ON: Average of 7 sec
- FF, FAST_FORWARD=ON, TURN_SPEED_UP_FACTOR=0: Average of 6.6 sec
So to me the TURN_SPEED_UP_FACTOR really doesn't speed up the turn that much just makes it look like it does. I think my Base FF speeds things up because it is always checking if any timers have expired and if so will execute the gameloop faster if there are timers that are expiring. Also it does use more CPU when running the AI turn because its not waiting very much to execute the next time slice.
Anyway, it would be nice if this could be reviewed and rolled into the main branch but since it makes a major change to how the gameloop is processed I would understand that it needs wider review first.
Report message to a moderator
|
Corporal 1st Class
|
|
|
Re: AI Turn Speed Up Mod [1.13 MP][message #266464]
|
Mon, 08 November 2010 07:18
|
|
olol |
|
Messages:28
Registered:March 2009 |
|
|
goooooooood job.
i like this.
And can you upload 3882 exe build for Vanilla
[Updated on: Mon, 08 November 2010 07:57] by Moderator Report message to a moderator
|
Private 1st Class
|
|
|
|
|
|
|
|
Re: AI Turn Speed Up Mod [1.13 MP][message #266976]
|
Tue, 16 November 2010 20:32
|
|
thefreakish |
|
Messages:13
Registered:January 2010 Location: Germany |
|
|
This is absolutely awesome, as I've been mourning all the time how long the enemy turns take. I just tried it out, and overall it looks VERY promising; my CPU is a AMD Phenom 955 Quadcore. I guess your code just needs some polishing, as I experience heavy performance issues in some scenarios:
- During interrupts, when the shooting-cursor hovers over the foe and while the actual shooting animation is played
- Pretty much always while mouse-overing an enemy and some time afterwards
Maybe some unresolved loops? The payload on the CPU seems to be pretty high, so there is some room for optimization eventually.
I would suggest an additional option to fast-forward only the actions of non-visible enemies, because otherwise it is pretty hard to overlook the enemies' actions.
I REALLY hope you keep working on this. Personally, this is the single most important mod I am waiting for.. I pretty much always have something to read on my secondary display, because of me having such a hard time waiting for the enemies turn to pass by (and me enjoying the game with slightly bigger enemy groups (up to 60) isn't making it any better)
Please keep it up, what you've done so far is just pure awesomeness with cream and a cherry on top.
Report message to a moderator
|
Private
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Re: AI Turn Speed Up Mod [1.13 MP][message #298699]
|
Sun, 12 February 2012 07:23
|
|
tazpn |
|
Messages:99
Registered:December 2007 Location: CA, USA |
|
|
I've done another rewrite and tested on my old P4 Laptop which reproduces the performance problem that people were seeing on some CPUs. I think this one has the correct tunings to work on a wide variety of machines.
I've also modified it so that it can the timer mode is controllable from a setting in JA2.INI (because it loads before JA2_Options.ini can be used). By default it does nothing and requires the JA2.INI setting to be set for the fast forward option to be be meaningful. This is the safer option for people I would presume until it can be determined to be safe to be the default.
EXE files:
JA2_EN_4870_FastFwd.zip
JA2_EN_4941_FastFwd.zip
Source Patches
ja2_ff_4941.zip
Required Configuration Changes
JA2.INIToggle Spoiler;******************************************************************************************************************************
; Use hispeed timer which enables the fast forward mode.
;******************************************************************************************************************************
HIGHSPEED_TIMER = TRUE
Ja2_Options.INIToggle Spoiler
[Clock Settings]
;------------------------------------------------------------------------------------------------------------------------------
; Fast forward timeslice in milliseconds. The frequency that the base clock is updated.
; At normal speed the clock is updated every 10 milliseconds.
; This setting should have no effect on game mechanics
; Range: 1-10000 Default: 1000
;------------------------------------------------------------------------------------------------------------------------------
FAST_FORWARD_PERIOD = 2000
;------------------------------------------------------------------------------------------------------------------------------
; When the specified key(s) is pressed, the fast forward mode will be enabled.
; Based on the virtual key system without VK_ prefix in http://msdn.microsoft.com/en-us/library/ms645540%28VS.85%29.aspx
; Note MENU = [ALT], CONTROL = [CTRL]
; Examples (seperated by comma):
; SCROLL, CONTROL + MENU + SHIFT + S, MULTIPLY, NUMPAD9, DECIMAL, LCONTROL + RSHIFT + LALT + NUMPAD1
;------------------------------------------------------------------------------------------------------------------------------
FAST_FORWARD_KEY = SUBTRACT
The FAST_FORWARD_PERIOD controls the speed processing is done. A number closer to 10000 is slower, 1 is as fast as possible. 3000 is probably still fairly fast I tend to prefer it faster.
Report message to a moderator
|
Corporal 1st Class
|
|
|
Re: AI Turn Speed Up Mod [1.13 MP][message #298834]
|
Mon, 13 February 2012 18:26
|
|
Istrebitel |
|
Messages:212
Registered:December 2009 Location: Russia, Saint-Petersburg |
|
|
The idea is great and i'd love it to work but so far it doesnt work for me at all.
When i use the mod with any period, 500, 2000, 10000, the game is unresponsive as hell. I cannot scroll the map (have to wait like 5 seconds for scroll to commence), i have to wait like 3 seconds after i cursor over target to add aim clicks, they just wont register otherwise, if cursor becomes "leave sector" icon after scrolling to the border, it will remain like this for ~10 seconds, and the process itself is VERY resource intensive, "not responding" in task manager etc.
PS:I have win 7 64 bit, and a very good pc (3.1 ghz quad proc, 8gb ram, etc), can run like any game on highest settings w/o problems. Its a new pc too and os wasnt garbaged too much yet.
Report message to a moderator
|
Sergeant 1st Class
|
|
|
Re: AI Turn Speed Up Mod [1.13 MP][message #298893]
|
Tue, 14 February 2012 05:23
|
|
tazpn |
|
Messages:99
Registered:December 2007 Location: CA, USA |
|
|
Damn. Not what I wanted to hear about this. Did you try both of the builds I posted above as they are slightly different implementations. What kind of processor ? Intel or AMD? It may just be a tuning issue.
Does it still work if you turn off the clock in the ja2.ini file? I'm counting on that to allow us to potentially commit the changes without breaking things and then fixing the tuning issue.
Would you be willing to run an app to collect timing settings that I could use to testing with?
[Updated on: Tue, 14 February 2012 05:28] by Moderator Report message to a moderator
|
Corporal 1st Class
|
|
|
|
|
Re: AI Turn Speed Up Mod [1.13 MP][message #298908]
|
Tue, 14 February 2012 08:19
|
|
tazpn |
|
Messages:99
Registered:December 2007 Location: CA, USA |
|
|
You do have to turn on the Auto fast forward option in options dialog. I'm assuming you did that but just in case. It will speed up turns in combat only.
Thanks in advance.
Here is a small app that will collect timings. It will run twice for 10 seconds and then put up a dialog box. Use Ctrl+C on the message box to copy the report.
ja2timer.zip
Then post it back in [\Spoiler][\code] tags like this.
Toggle Spoiler
---------------------------
JA2 Timer Report
---------------------------
Counter: 0
QPFrequency: 2610712
QPCounter: 2165070797270
TimeGetTime: 829376383
JA2Micro: 829302809749
JA2Clock: 0
JA2NoPause: 0
Elapsed Time: 0
Counter: 639
QPFrequency: 2610712
QPCounter: 2165096930364
TimeGetTime: 829386393
JA2Micro: 829302809749
JA2Clock: 100090
JA2NoPause: 100090
Elapsed Time: 10010
Counter: 0
QPFrequency: 2610712
QPCounter: 2165096961157
TimeGetTime: 829386405
JA2Micro: 829312831425
JA2Clock: 100210
JA2NoPause: 100210
Elapsed Time: 0
Counter: 590
QPFrequency: 2610712
QPCounter: 2165123075113
TimeGetTime: 829396408
JA2Micro: 829322834197
JA2Clock: 200210
JA2NoPause: 200210
Elapsed Time: 10003
---------------------------
OK
---------------------------
Edit: Uploaded fixed exe which reports start parameters better
[Updated on: Tue, 14 February 2012 08:26] by Moderator Report message to a moderator
|
Corporal 1st Class
|
|
|
|
|
Re: AI Turn Speed Up Mod [1.13 MP][message #299014]
|
Wed, 15 February 2012 10:23
|
|
Istrebitel |
|
Messages:212
Registered:December 2009 Location: Russia, Saint-Petersburg |
|
|
Full screen. Unfortunately i dont know how to ever set 16bit on modern systems like win7, so i cannot try windowed for you.
Nividia gtx 560 Ti.
Well basically the game doenst take any abnormal processor time or memory, but it "does not respond" (countrary to normal ja2.exe which does respond), you cannot alt-tab back to it, and its very laggy in response to keyboard and mouse command.
I think (my humble programmer opinion) that it looks like this timer of yours somehow, increasing the ticks for AI movement, takes those ticks from the loop that queries all sorts of input. Since all the symptoms point to the lag in the input loop: queries and signals from operation system, data from keyboard, mouse, all are delayed and scrambled. Its obvious that system queries about program state are not processed correctly (hence "not repsonding"), that system command "become active window" is not responded to (hence cannot alt-tab in), that mouse states are checked like once in one or two seconds (hence the scrolling not happening at first and then being stuck for some seconds when i've already moved the mouse away from map border). The problem must somehow relate to the input loop - its either ran less often or something?
PS: This might also be a reason for your program to detect nothing suspicious. Your timer is fine, it is the fact that it makes other timers maulfunction that is the problem.
[Updated on: Wed, 15 February 2012 12:30] by Moderator Report message to a moderator
|
Sergeant 1st Class
|
|
|
|
|
|
|
|
|
Re: AI Turn Speed Up Mod [1.13 MP][message #299211]
|
Fri, 17 February 2012 08:20
|
|
tazpn |
|
Messages:99
Registered:December 2007 Location: CA, USA |
|
|
No obvious hints. The logs were very similar to mine except for number of times gameloop was called and some other things.
I'll spend some time making sure it is stable. I would just recommend not moving the camera around using keys while the fast forward operation is in progress and to save often until I can determine a good way to ensure that I don't have any data conflicts.
Edit: The basics of the threading issue is correct but I only execute the primary gameloop and that is always protected from reentrancy. The code of interest used to be the key handler which used to trigger more things while that is running however I will note that since I wrote the code 1 year ago someone rewrote the keyhandling. Those changes probably make it a lot more thread compatible (except for print screen). I also used to run the gameloop from the timer which would cause more problems but I dont do that now.
The only other code is like ScreenToClient which I think is threadsafe. There is also some debugging code which may not be threadsafe but shouldn't normally be executed. The final code is a QueueEvent which probably does need some protections. It actually rather safe all things considered as there just isn't very much overlap between the 2 threads.
[Updated on: Fri, 17 February 2012 08:36] by Moderator Report message to a moderator
|
Corporal 1st Class
|
|
|
|
Re: AI Turn Speed Up Mod [1.13 MP][message #299289]
|
Sat, 18 February 2012 04:48
|
|
tazpn |
|
Messages:99
Registered:December 2007 Location: CA, USA |
|
|
I'm confused the lag occurs even with the Unsafe version? If so then I still have problems to fix. Also did you up the CLOCK_SPEED_PERCENT to 150 or so as I find the 100% to be too slow.
I believe the unsafe version is actually pretty safe compared to what I remember from last year. I will look to add some minor protections around the event queue and I think that will be enough assuming the unsafe version worked for you as you indicated above (except for portraits).
Here is a version without the main message queue protection and some extra added around the event queue. I suspect this should be enough to handle the threading concerns that could be present.
JA2_EN_4941_VS2010_FF.zip
[Updated on: Sat, 18 February 2012 05:30] by Moderator Report message to a moderator
|
Corporal 1st Class
|
|
|
|
|