Home » MODDING HQ 1.13 » v1.13 Idea Incubation Lab  » AI Turn Speed Up Mod [1.13 MP]
AI Turn Speed Up Mod [1.13 MP][message #266463] Mon, 08 November 2010 04:51 Go to next message
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:
  1. In Utils/Timer Control.cpp, set timer event update frequency to minimum resolution of the system.
  2. Use QueryPerformanceCounter to track time, unlike timeGetTime it wont wrap around periodically
  3. Every BASETIMESLICE update the counters like we would have if we left update period alone above
  4. When the FastForwardMode is active then just update the timers 1/FAST_FORWARD_PERIOD times faster. This artificially speeds up time for everything.
  5. 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.
Re: AI Turn Speed Up Mod [1.13 MP][message #266464] Mon, 08 November 2010 07:18 Go to previous messageGo to next message
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

Re: AI Turn Speed Up Mod [1.13 MP][message #266485] Mon, 08 November 2010 17:29 Go to previous messageGo to next message
tazpn

 
Messages:99
Registered:December 2007
Location: CA, USA
I really wasn't interested in the trunk branch anymore since it seems all development is really going against the 1.13 MP branch.

Anyway, I'll post something after I get back from work for the trunk. Presumably the base exe from just compiling and then with the changes applied so that they can be compared more readily. I'll post the 1.13 MP base exe as well for comparison.

Re: AI Turn Speed Up Mod [1.13 MP][message #266498] Mon, 08 November 2010 20:18 Go to previous messageGo to next message
RoWa21

 
Messages:2046
Registered:October 2005
Location: Austria
that sounds good. does mp still work after your code changes?


Re: AI Turn Speed Up Mod [1.13 MP][message #266529] Tue, 09 November 2010 07:54 Go to previous messageGo to next message
tazpn

 
Messages:99
Registered:December 2007
Location: CA, USA
I would guess that MP does not work with the changes but not to say that it couldn't. Really what its doing is just executing the code more frequently. In the team turns code when I turn on FastForward mode it would be possible to check for something other than OUR_TEAM to turn the mode on or off.

----
Here is the trunk build using the same changes. I've not played through as much with this build.
The included patch file is for https://81.169.133.124/source/ja2/trunk/GameSource/ja2_v1.13/Build

http://www.megaupload.com/?d=V3VJWR8L
http://www.mediafire.com/?w9ge1mq8wamy2ja
http://www.sendspace.com/file/uex8zl
----
Here are the 1.13 MP branch including the base exe which was not present in original upload.
The included patch file is for https://81.169.133.124/source/ja2/branches/Wanne/JA2%201.13%20MP

http://www.megaupload.com/?d=C5PSQQ0L
http://www.sendspace.com/file/0cza71
http://www.mediafire.com/?a85skykob2s49si
Re: AI Turn Speed Up Mod [1.13 MP][message #266530] Tue, 09 November 2010 08:27 Go to previous messageGo to next message
olol

 
Messages:28
Registered:March 2009
i tried it with svn1247 and JA2_EN_3882_VS2008_FF

it's very lag, cpu usage 100% when I turn on or off FastForward mode

my cpu is AMD xp 2500

any idea ?
Re: AI Turn Speed Up Mod [1.13 MP][message #266595] Wed, 10 November 2010 06:36 Go to previous messageGo to next message
tazpn

 
Messages:99
Registered:December 2007
Location: CA, USA
Can you clarify the statement? Its it a problem when it is off not just when its on.

It does alter the way the application updates just about everything. My best guess at this point would be that I have made a mistake in the QueryPerformance counter timer code which does not exhibit problems on my Intel i7 Core. The application may not waiting the proper time between scans. Different hardware returns different values for the frequency value so they would have different problems.

If that is the case there might not be anything you can do at this point. I will try to see if I can test on my old laptop though that is still intel but definitely has a different clock speed for comparison.

Did you specify the 2 settings in the JA2_Options.ini file. They are currently in "Graphics Settings" as that is where the other speed up settings were. After checking the code it may be defaulting to the wrong value in code basically set to 0.001 instead of 0.05 which I think is a better and probably still to fast at least on my machine. This would only be an issue for when turns are actually being sped up though.

-----------------
Edit: I've started it up on my old machine and its painfully slow as suggested so I should be be able to work with it and make it function correctly and really be a speed up mod not a massive lag mod Wink Sorry about the testing as it does not happen at all on my current rig.

[Updated on: Wed, 10 November 2010 08:30] by Moderator

Re: AI Turn Speed Up Mod [1.13 MP][message #266976] Tue, 16 November 2010 20:32 Go to previous messageGo to next message
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.
Re: AI Turn Speed Up Mod [1.13 MP][message #267047] Wed, 17 November 2010 20:36 Go to previous messageGo to next message
MrGreen

 
Messages:15
Registered:December 2008
Location: Europe
+1 here!

the civilians and militia turns were so slow that i just stopped training militias...

with this patch, this will get better indeed!

well done Smile)
Re: AI Turn Speed Up Mod [1.13 MP][message #270910] Fri, 21 January 2011 20:02 Go to previous messageGo to next message
r4in
Messages:2
Registered:May 2010

I really don't have any idea of all this, but I'm very interested in speeding up the game, because it really takes ages to do one turn if there are like 40 enemies in the sector.

Is it somehow possible to integrate this thing into the newest SCI Version of Tais? (Guess that would be 4057 right now?)
Re: AI Turn Speed Up Mod [1.13 MP][message #270913] Fri, 21 January 2011 20:47 Go to previous messageGo to next message
lockie

 
Messages:3965
Registered:February 2006
Location: Scotland
There is an option to turn up enemy speed in the .ini .


Re: AI Turn Speed Up Mod [1.13 MP][message #270917] Fri, 21 January 2011 21:14 Go to previous messageGo to next message
Logisteric

 
Messages:3477
Registered:December 2008
Location: B
lockie
There is an option to turn up enemy speed in the .ini .


..., but it looks horrible
Re: AI Turn Speed Up Mod [1.13 MP][message #270918] Fri, 21 January 2011 22:00 Go to previous messageGo to next message
lockie

 
Messages:3965
Registered:February 2006
Location: Scotland
Them's the choices! Very Happy


Re: AI Turn Speed Up Mod [1.13 MP][message #270921] Fri, 21 January 2011 22:14 Go to previous messageGo to next message
RoWa21

 
Messages:2046
Registered:October 2005
Location: Austria
Of course that will be included in 1.13.


Re: AI Turn Speed Up Mod [1.13 MP][message #270922] Fri, 21 January 2011 22:15 Go to previous messageGo to next message
Logisteric

 
Messages:3477
Registered:December 2008
Location: B
? it is included
Re: AI Turn Speed Up Mod [1.13 MP][message #270924] Fri, 21 January 2011 22:19 Go to previous messageGo to next message
RoWa21

 
Messages:2046
Registered:October 2005
Location: Austria
Of course that feature will be included in 1.13.


Re: AI Turn Speed Up Mod [1.13 MP][message #271139] Tue, 25 January 2011 11:39 Go to previous messageGo to next message
RoWa21

 
Messages:2046
Registered:October 2005
Location: Austria
I tested this MOD, but the game was very, very slow in Laptop, Realtime and so on. Did I do something wrong or is this still a bug?


Re: AI Turn Speed Up Mod [1.13 MP][message #271320] Wed, 26 January 2011 16:43 Go to previous messageGo to next message
r4in
Messages:2
Registered:May 2010

I didn't have any problems like that.
Game runs like a charm with that mod, in fact its far more comfortable because you just have to wait a few secs for the next turn, not like half or even a whole minute.
Actually can't wait that this will be integrated into the newer 1.13 versions.

Not sure if this is a bug you encountered, probably your hardware is somewhat older and just too slow to handle the fast forward?
Re: AI Turn Speed Up Mod [1.13 MP][message #298634] Sat, 11 February 2012 21:15 Go to previous messageGo to next message
RoWa21

 
Messages:2046
Registered:October 2005
Location: Austria
Maybe I should give it another try...


Re: AI Turn Speed Up Mod [1.13 MP][message #298655] Sat, 11 February 2012 23:19 Go to previous messageGo to next message
tazpn

 
Messages:99
Registered:December 2007
Location: CA, USA
Reposting after putting in the wrong thread.

r4in recently requested to have this mod updated to latest 4870 build and since I regularly keep it up-to-date that was not too much extra work.


Here is the current builds for 4870 and 4941. 4870 is actually something like 4881 which includes a couple of small fixes but is just before a major update.


This mod has problems with older CPU chipsets probably due to bug in how I'm using the high-resolution timers.

The 4941 will crash nearly immediately in 4870 due to missing data files.

EXE files:
ja2_ff_mod_4870.zip [mediafire.com]
ja2_fastfwd_mod_4941.rar [mediafire.com]

Source Patches:
ja2_ff_mod_4870_patch.zip [mediafire.com]
ja2_ff_mod_4941_patch.zip [mediafire.com]

--

The mod also includes some additional code that I did not feel like removing since I use it. The primary is interrupts have been changed so mercs that are trying to interrupt another does not get there turn unless they have enough AP to make a simple shot (or other attack). This speeds up the game quite a bit as well.


The mod is enabled from the options screen on the final page. The keyboard shortcut to fastforward at any time and timings must be edited from the ja2_options.INI file.


I can try to modify the code so that it can be turned on/off with a global variable so that it doesn't break for everyone.
Re: AI Turn Speed Up Mod [1.13 MP][message #298699] Sun, 12 February 2012 07:23 Go to previous messageGo to next message
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.INI
Toggle Spoiler


Ja2_Options.INI
Toggle Spoiler


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.
Re: AI Turn Speed Up Mod [1.13 MP][message #298834] Mon, 13 February 2012 18:26 Go to previous messageGo to next message
Istrebitel

 
Messages:222
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.

Re: AI Turn Speed Up Mod [1.13 MP][message #298893] Tue, 14 February 2012 05:23 Go to previous messageGo to next message
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

Re: AI Turn Speed Up Mod [1.13 MP][message #298899] Tue, 14 February 2012 07:12 Go to previous messageGo to next message
tazpn

 
Messages:99
Registered:December 2007
Location: CA, USA

Here is another build, I dont really fix the timer but I added some new modes that may still be useful.


If HIGHSPEED_TIMER is FALSE it uses the standard timer but I can still alter the time just not very well. So I've changed the code to alter the base timer to run as fast as possible. This should be more compatible for people. I also cannot speed up time when a key is pressed like with the faster timer.

I've also added CLOCK_SPEED_PERCENT to the ja2_options.ini file which will generally speed up the base clock or slow it down. (With HIGHSPEED_TIMER = FALSE you can really only try by 10% of a percent) but still seems to work.

I find I prefer to have it set to 160 when HIGHSPEED_TIMER = TRUE. I may force it in the code so that 100 is equal to the current 160.

Binaries:
JA2_EN_4870_VS2010_FF.zip
JA2_EN_4941_VS2010_FF.zip

Source:
ja2_ff_4941_v2.zip
Re: AI Turn Speed Up Mod [1.13 MP][message #298905] Tue, 14 February 2012 08:05 Go to previous messageGo to next message
Istrebitel

 
Messages:222
Registered:December 2009
Location: Russia, Saint-Petersburg
No i didnt try the 4941 file since i have 4870 version. Tried now - it wont run, many red messages and CTD. Where do i get the new version btw, is it released somewhere?

It does of course work fine if i change that to false (no ui lag), but then it doesnt improve the speed of ai turn.

Processor is Intel Core i5-2400

Yes i'm willing to help so tell me what to do.

I tried another build and its the same. Setting timer to false and trying to speed up AI turn does nothing noticeable. Used gabbi alt+e, cant see difference.



[Updated on: Tue, 14 February 2012 08:13] by Moderator

Re: AI Turn Speed Up Mod [1.13 MP][message #298908] Tue, 14 February 2012 08:19 Go to previous messageGo to next message
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


Edit: Uploaded fixed exe which reports start parameters better

[Updated on: Tue, 14 February 2012 08:26] by Moderator

Re: AI Turn Speed Up Mod [1.13 MP][message #298925] Tue, 14 February 2012 10:23 Go to previous messageGo to next message
Istrebitel

 
Messages:222
Registered:December 2009
Location: Russia, Saint-Petersburg
Well, problem is, if i launch Ja2 and try to alttab to launch your program, it wont let me alt tab back to ja2, since its not responding. So what i had to do is launch program then launch ja2 and try to load a battle as fast as possible. I dont know how much of actual combat did the program of yours catched but here is the output it gave:

---------------------------
JA2 Timer Report
---------------------------
Counter:  	 0
QPFrequency:	 3118183
QPCounter:	 989752059939
TimeGetTime:	 317414038
JA2Micro:	 317413076568
JA2Clock:	 0
JA2NoPause:	 0
Elapsed Time:	 0

Counter:  	 624
QPFrequency:	 3118183
QPCounter:	 989783248076
TimeGetTime:	 317424040
JA2Micro:	 317413076568
JA2Clock:	 100020
JA2NoPause:	 100020
Elapsed Time:	 10002

Counter:  	 0
QPFrequency:	 3118183
QPCounter:	 989783265868
TimeGetTime:	 317424045
JA2Micro:	 317423084491
JA2Clock:	 100080
JA2NoPause:	 100080
Elapsed Time:	 0

Counter:  	 625
QPFrequency:	 3118183
QPCounter:	 989814468728
TimeGetTime:	 317434053
JA2Micro:	 317433091235
JA2Clock:	 200080
JA2NoPause:	 200080
Elapsed Time:	 10008


---------------------------
OK   
---------------------------

[Updated on: Tue, 14 February 2012 10:27] by Moderator

Re: AI Turn Speed Up Mod [1.13 MP][message #299000] Wed, 15 February 2012 05:41 Go to previous messageGo to next message
tazpn

 
Messages:99
Registered:December 2007
Location: CA, USA
Thanks. The JA2Timer tool was a standalone tool and didn't need to be run while JA2 was running. My comment on running with the setting was just an pointer for running with the older timer mode. The standalone tool basically has the same code as my build of JA2 for doing timings.

I dont see anything unexpected. Basically it looks spot on to me so I dont have an idea of what the problem could be.

What kind of graphics card do you have? Nvidia vs ATI.

Did you run in full screen mode vs windowed mode?
Re: AI Turn Speed Up Mod [1.13 MP][message #299014] Wed, 15 February 2012 10:23 Go to previous messageGo to next message
Istrebitel

 
Messages:222
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

Re: AI Turn Speed Up Mod [1.13 MP][message #299073] Wed, 15 February 2012 17:10 Go to previous messageGo to next message
tazpn

 
Messages:99
Registered:December 2007
Location: CA, USA
Ok Thanks for the feedback. I think your analysis is pretty close.

Before my change the main game loop runs in the Main Window message queue via a WM_TIMER event which runs every 10 ms or so. I cannot use that queue because it only has 1 ms resolution or so and I would like higher resolution during the fastforward events.

I run the game in basically a multithreaded mode with the rendering occuring in my thread rather than the message queue thread. Thus the Graphics card inquiry (I also run Nvidia) so I wanted to find if there was thread affinity there.

In order to protect game state I block the main window when the inner loop is running and vice versa. I'm probably over protecting the main window since not all messages can result in change of game state while the inner loop is running. I'll put together something that has no protection (which will likely cause random crashes) and one with targeted protection. I was avoid the latter since I wasn't sure it was required and I wanted to minimize my changes to the main window procedure.
Re: AI Turn Speed Up Mod [1.13 MP][message #299113] Thu, 16 February 2012 06:44 Go to previous messageGo to next message
tazpn

 
Messages:99
Registered:December 2007
Location: CA, USA
Here is some builds with various protection levels of the main message queue.

JA2_EN_4870_VS2010_FF_DebugLog.zip

  1. Safe - Existing version where every message is protected so GameLoop does not run while messages are present.
  2. Unsafe - No protections at all.
  3. SelectProtect - Only a handful of messages are protected (mostly key presses)

You can enable some debug logging via ja2.ini by setting
HIGHSPEED_TIMER_LOG = TRUE


I would not recommend enabling the logging for long periods of time while playing the game normally. Those will not probably be in the committed version.

Could you do the following:
  1. Setup a scenario just as combat begins. Save. Exit
  2. For each program with the 3 with logging enabled
    • Start saved scenario
    • Run one turn
    • Save the Profiles\UserProfile_JA2113\vfs.log as vfs_safe.log, vfs_unsafe.log or vfs_select.log
  3. Post those files to a zip somewhere I can download and inspect
Thanks in advance. I expect the logging to cause extra stuttering and slowdowns but should be enough to get an idea of where to look at next I hope.

The logging should also work with HIGHSPEED_TIMER = FALSE and could be useful to have one pass of with that just for comparison sake.
Re: AI Turn Speed Up Mod [1.13 MP][message #299153] Thu, 16 February 2012 16:29 Go to previous messageGo to next message
Istrebitel

 
Messages:222
Registered:December 2009
Location: Russia, Saint-Petersburg
Yes i will do it this evening as soon as i can

PS: From your reply from what i know about multi-threading and protecting, i think it is pretty simple - your loop is running too much, and since you block something while your loop runs - seems that is blocking input from reaching program (or program from processing input or something else).

[Updated on: Thu, 16 February 2012 16:32] by Moderator

Re: AI Turn Speed Up Mod [1.13 MP][message #299157] Thu, 16 February 2012 17:13 Go to previous messageGo to next message
Istrebitel

 
Messages:222
Registered:December 2009
Location: Russia, Saint-Petersburg
Here are your files
http://www.2shared.com/file/CAHT9Rc_/logz.html

EDIT: And, unsafe works flawlessly, AI turn is sped up and no input lag. Only problem is that portraits are sped up too, so when merc tries tosay something during enemy turn he looks very wierd. But thats minor over the major plus of having fast enemy turn.

I assume it wouldnt be a good idea to play this unsafe executable (even w/o logging), yes? I mean, can it corrupt my saves, or will it only crash randomly?

[Updated on: Thu, 16 February 2012 17:15] by Moderator

Re: AI Turn Speed Up Mod [1.13 MP][message #299204] Fri, 17 February 2012 04:56 Go to previous messageGo to next message
tazpn

 
Messages:99
Registered:December 2007
Location: CA, USA
I would use the protected one if that also works but I don't really think you have too much to worry about corrupt saves since it doesn't change the save code. I would definitely disable the logging though as that will cause a lot of issues longer term I suspect.

Random crashes are more likely which is why I put in the protections in the first place. The SelectProtect is probably the best if that actually works for you. If not I will investigate what I can do to make those routines more safe with this code.
Re: AI Turn Speed Up Mod [1.13 MP][message #299210] Fri, 17 February 2012 07:47 Go to previous messageGo to next message
Istrebitel

 
Messages:222
Registered:December 2009
Location: Russia, Saint-Petersburg
Well protected and select protect do not work (cause too much lag and unable to alt-tab to the game)
Did the log give any hints as to how to fix it?

PS: I asked about corruption because from what i know, protection in threads is neede because two threads can write and write/read a value simultaneoncely, for example, i click save when one thread is writing new enemy structure to the file, and save then saves partially filled structure and then cannot load it because there is garbage or 0's in half of the structure (like, there is no body type specified, faction with such id is unexistant etc) and then this save wont load because loader wont be able to parse such data

[Updated on: Fri, 17 February 2012 08:18] by Moderator

Re: AI Turn Speed Up Mod [1.13 MP][message #299211] Fri, 17 February 2012 08:20 Go to previous messageGo to next message
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

Re: AI Turn Speed Up Mod [1.13 MP][message #299223] Fri, 17 February 2012 12:14 Go to previous messageGo to next message
Istrebitel

 
Messages:222
Registered:December 2009
Location: Russia, Saint-Petersburg
Problem is this lag happens ALWAYS. During my turn, on strategic map. Always. Its not about moving map during enemy turn, its about not being able to play at all (well you can call that being able, but its very uncomfortable and clunky and sure isnt smooth as original 1.13).
Re: AI Turn Speed Up Mod [1.13 MP][message #299289] Sat, 18 February 2012 04:48 Go to previous messageGo to next message
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

Re: AI Turn Speed Up Mod [1.13 MP][message #299309] Sat, 18 February 2012 09:33 Go to previous messageGo to next message
Istrebitel

 
Messages:222
Registered:December 2009
Location: Russia, Saint-Petersburg
No, it doesnt occur in unsafe. In unsafe, as i said above, everything feels fine - no interface lag, and the AI turn is sped up all right. In protected/select protect, the interface lags. In this last post exe it still lags Sad

[Updated on: Sat, 18 February 2012 09:33] by Moderator

Re: AI Turn Speed Up Mod [1.13 MP][message #300266] Sat, 25 February 2012 03:17 Go to previous messageGo to previous message
Dyson

 
Messages:202
Registered:December 2008
To change Windows7 into 16bit do as following:

rightclick on desktop -> Screenresolution ( or corresponding as I am using a german OS)
click on advanced settings
select the "monitor" tab
change the color depth

Aero will be disabled in 16bit mode
Previous Topic: Snitches + Externalised morale & reputation
Next Topic: Individual Mercs' Food Preferences.
Goto Forum:
  


Current Time: Sun Aug 20 22:10:21 EEST 2017

Total time taken to generate the page: 0.01373 seconds