Advertisement
Civilization Fanatics' Center  

Go Back   Civilization Fanatics' Forums > CIVILIZATION V > Civ5 - Creation & Customization > Civ5 - Utility Programs

Reply
 
Thread Tools
Old Nov 22, 2010, 10:26 PM   #1
AntmanMike
Chieftain
 
Join Date: Aug 2002
Posts: 9
LuaJIT for Civilization V (Faster Turns)

EDIT: Have updated for LuaJIT 2.0.1

Not entirely sure where to put this thread since it isn't quite a mod...

After reading http://forums.civfanatics.com/showthread.php?t=388670, I realized that the arguments about Lua were exactly right - an Engineer myself, Lua is a fully interpreted language and can be slow for games such as this.

I therefore took it upon myself to make a fast build of LuaJIT (no fastcall, sorry) that should be drop in compatible, as LuaJIT is ABI and API compatible with Lua. I've tested it myself, it seems marginally faster.

You will need 7zip or WinRAR to extract the archive - just overwrite your current DLL (I recommend backing it up, but you can always download a more recent, standard version from the Lua site), and you should see benefits the next time you start the game.

I also do not take credit for LuaJIT, I merely built it. I don't take much credit for this - a chimp with training can execute a compile (though I also made some changes to it so it should be marginally faster). If anyone else has already done this, sorry!

Edit: I have absolutely NO idea if Civ V has any kind of cheat protection - if it does, it may detect that the DLL is different (different checksum, obviously). Though as per the EULA they have no grounds to ban on this, it may still occur. You've been forewarned! Not entirely why they'd care if the Lua DLL is different... or even the client. It's a server-side (IE, hosting client) managed game, so you really can't "cheat"...
Attached Files
File Type: 7z lua51_Win32.7z (225.0 KB, 1782 views)

Last edited by AntmanMike; Mar 05, 2013 at 12:50 AM. Reason: Updating File (statically linked)
AntmanMike is offline   Reply With Quote
Old Nov 22, 2010, 10:55 PM   #2
Shmike
Warlord
 
Join Date: Sep 2010
Posts: 124
Definitely going to try this. Is it available through the mod browser? I'd rather get it from there.
Shmike is offline   Reply With Quote
Old Nov 22, 2010, 11:31 PM   #3
AntmanMike
Chieftain
 
Join Date: Aug 2002
Posts: 9
It's a replacement DLL for the Lua library, it's not quite a mod.
AntmanMike is offline   Reply With Quote
Old Nov 23, 2010, 01:50 AM   #4
The_J
Say No 2 Net Validations
 
The_J's Avatar
 
Join Date: Oct 2008
Location: Germany / Netherlands
Posts: 29,024
Moderator Action: Moved to C&C utilities.
I guess modders will have the best use for it .
__________________
Civ4-BtS-Mod "Mars, Now!"


Steam eats the souls of little gamers!!!
The_J is offline   Reply With Quote
Old Nov 23, 2010, 10:46 PM   #5
AntmanMike
Chieftain
 
Join Date: Aug 2002
Posts: 9
Quote:
Originally Posted by The_J View Post
Moderator Action: Moved to C&C utilities.
I guess modders will have the best use for it .
Most likely modders will have the least use of it. It's meant for the average user who wants the game to run faster. From the modders perspective, it would change nothing as LuaJIT and Lua have the same output, LuaJIT is simply faster.
AntmanMike is offline   Reply With Quote
Old Nov 24, 2010, 11:11 AM   #6
PawelS
Ancient Druid
 
PawelS's Avatar
 
Join Date: Dec 2003
Location: Poland
Posts: 2,422
I installed it, and starting a new game seems to be faster (I suppose it's because the map generation uses LUA). I haven't yet checked how it affects the late game turn times.

But there is one problem: when I exit the game, it "hangs" - I can still see the game menu, but the cursor changes to the standard Windows one. Pressing Ctrl-Alt-Del, and then Cancel helps to see the Desktop again (I use Win7 64-bit). Do you have an idea why it happens?
PawelS is offline   Reply With Quote
Old Nov 24, 2010, 11:29 AM   #7
Kruelgor
Emperor
 
Kruelgor's Avatar
 
Join Date: May 2010
Location: The United States
Posts: 1,165
Quote:
Originally Posted by PawelS View Post
I installed it, and starting a new game seems to be faster (I suppose it's because the map generation uses LUA). I haven't yet checked how it affects the late game turn times.

But there is one problem: when I exit the game, it "hangs" - I can still see the game menu, but the cursor changes to the standard Windows one. Pressing Ctrl-Alt-Del, and then Cancel helps to see the Desktop again (I use Win7 64-bit). Do you have an idea why it happens?
I was going to try it, it sounds great, but the problem you're having there is a bit discouraging.
Kruelgor is offline   Reply With Quote
Old Nov 24, 2010, 11:45 AM   #8
PawelS
Ancient Druid
 
PawelS's Avatar
 
Join Date: Dec 2003
Location: Poland
Posts: 2,422
You can try it, it's nothing harmful, and possibly you won't have this problem.
PawelS is offline   Reply With Quote
Old Nov 24, 2010, 03:29 PM   #9
AntmanMike
Chieftain
 
Join Date: Aug 2002
Posts: 9
Off hand, no, but I experienced the same delay in testing and rather ignored it. When I get home from work I will pop in a debug build of LuaJIT and see where it may be hanging. For me, it did close in the end but just took longer. It sounds like the window or rendering context isn't being fully closed in time but control is shifted back to Explorer. Could also be a bug in Civ's Lua that doesn't show using Lua but shows using LuaJIT (which, given that it must output machine code, is stricter). Or vice-versa.
AntmanMike is offline   Reply With Quote
Old Nov 24, 2010, 05:00 PM   #10
The_J
Say No 2 Net Validations
 
The_J's Avatar
 
Join Date: Oct 2008
Location: Germany / Netherlands
Posts: 29,024
Quote:
Originally Posted by AntmanMike View Post
Most likely modders will have the least use of it. It's meant for the average user who wants the game to run faster. From the modders perspective, it would change nothing as LuaJIT and Lua have the same output, LuaJIT is simply faster.
With this point of view, you are sure right .
But will most users install a mod which "just" runs faster? No, they all want the additional stuff -> bigger mods are likely to incorporate this one here (unless i'm wrong here and it can't be used with mods, but then it's still right here in the utilities section).
__________________
Civ4-BtS-Mod "Mars, Now!"


Steam eats the souls of little gamers!!!
The_J is offline   Reply With Quote
Old Nov 26, 2010, 01:02 PM   #11
alpaca
King of Ungulates
 
alpaca's Avatar
 
Join Date: Aug 2006
Posts: 2,164
Quote:
Originally Posted by The_J View Post
With this point of view, you are sure right .
But will most users install a mod which "just" runs faster? No, they all want the additional stuff -> bigger mods are likely to incorporate this one here (unless i'm wrong here and it can't be used with mods, but then it's still right here in the utilities section).
Not really because it's a DLL replacement rather than something a mod can switch on. People have to install it manually, but you can sure tell them how to.
alpaca is offline   Reply With Quote
Old Mar 04, 2013, 06:32 PM   #12
AntmanMike
Chieftain
 
Join Date: Aug 2002
Posts: 9
Not sure on the policy of resurrection, but since I'm not quite resurrecting, I've updated the DLL to be LuaJIT 2.0.1. It has been built with practically all optimizations enabled, and requires an SSE2-capable CPU (as does Civilization V). The link is in the original post.
AntmanMike is offline   Reply With Quote
Old Mar 04, 2013, 10:53 PM   #13
Bobert13
Warlord
 
Bobert13's Avatar
 
Join Date: Feb 2013
Posts: 234
You should mention that the Microsoft Visual C++ 2012 Redistributable runtime is required for this to operate.

Missing msvcr110.dll is no fun to troubleshoot.

Edit: Well, installing the redistributable and restarting my pc didn't fix the issue.

Edit Edit: I copied the .dll from \System32\ to the game's root directory \Steam\steamapps\common\Sid Meier's blah blah blah\ and I got the following error instead of the missing .dll message.

---------------------------
CivilizationV_DX11.exe - Application Error
---------------------------
The application was unable to start correctly (0xc000007b). Click OK to close the application.
---------------------------
OK
---------------------------

The game runs fine if I use the original Lua51_Win32.dll

Last edited by Bobert13; Mar 04, 2013 at 11:20 PM.
Bobert13 is offline   Reply With Quote
Old Mar 05, 2013, 12:51 AM   #14
AntmanMike
Chieftain
 
Join Date: Aug 2002
Posts: 9
Quote:
Originally Posted by Bobert13 View Post
You should mention that the Microsoft Visual C++ 2012 Redistributable runtime is required for this to operate.

Missing msvcr110.dll is no fun to troubleshoot.

Edit: Well, installing the redistributable and restarting my pc didn't fix the issue.

Edit Edit: I copied the .dll from \System32\ to the game's root directory \Steam\steamapps\common\Sid Meier's blah blah blah\ and I got the following error instead of the missing .dll message.

---------------------------
CivilizationV_DX11.exe - Application Error
---------------------------
The application was unable to start correctly (0xc000007b). Click OK to close the application.
---------------------------
OK
---------------------------

The game runs fine if I use the original Lua51_Win32.dll
I've uploaded a statically-linked version which ideally should not require the MSVC11 redistributable runtimes.
AntmanMike is offline   Reply With Quote
Old Mar 05, 2013, 01:39 AM   #15
Bobert13
Warlord
 
Bobert13's Avatar
 
Join Date: Feb 2013
Posts: 234


Quote:
Originally Posted by AntmanMike View Post
I've uploaded a statically-linked version which ideally should not require the MSVC11 redistributable runtimes.
The new version works.

And Holy Crap!

From FireTuner's .lua console:
Code:
Generated Huge Map in 6.718 seconds.
With the original .dll, I was running anywhere from 18.5 to 19 seconds to generate a Huge Map with my modified version of PerfectWorld 3.


Last edited by Bobert13; Mar 05, 2013 at 01:46 AM.
Bobert13 is offline   Reply With Quote
Old Mar 05, 2013, 04:32 PM   #16
Bobert13
Warlord
 
Bobert13's Avatar
 
Join Date: Feb 2013
Posts: 234
This breaks some mods.

I know there probably isn't anything you can do about this since you just packed LuaJIT, but it's breaking some mods. I haven't really tested most of the mods I have installed but I know Reseed! v.7 doesn't play well with JIT at all. In fact, it doesn't load at all. It errors out during the loading process with the following:

Code:
 RSD_UI: 'Reseed!'... loading
 Runtime Error: [string "C:\Users\Boberto\Documents\My Games\Sid Meier..."]:6: bad argument #1 to 'unpack' (table expected, got no value)
 Runtime Error: Error loading C:\Users\Boberto\Documents\My Games\Sid Meier's Civilization 5\MODS\Reseed! (v 7)\RSD_Loader.lua.
I'm not going to pretend I know what I'm talking about with strings and XML references and whatnot, but I did find the function in RSD_Utils.lua that contains the problem and the line where RSD_Loader.lua calls said function. I'll probably try contact the author and see if he wouldn't mind taking a look.

Edit: If anybody else runs into this particular issue, adding the following line to function L() at the top of RSD_Utils.lua fixed it for me:
Code:
if arg == nil then arg = {} end
Anywhere in that function above the line that calls unpack(arg) works.

Last edited by Bobert13; Mar 05, 2013 at 10:18 PM. Reason: Found a fix.
Bobert13 is offline   Reply With Quote
Old Mar 06, 2013, 04:16 AM   #17
DonQuiche
Emperor
 
DonQuiche's Avatar
 
Join Date: May 2011
Posts: 1,115
Hello Bobert13 and thank you for your messages on Steam. I fixed the bug on my local copy and I am going to upload new versions of Reseed and IGE (both should be affected). Note that the same bug should also cause the map preview to fail in Reseed (I didn't check but it should), the new version will also fix that.

BUG DETAILS FOR OTHER DEVS (corrected)
  • Before 5.1, Lua exposed a table named "arg" to retrieve the variable arguments in a function. Ex : local firstVarArg = arg[1]
  • Starting with 5.1, the "arg" table is deprecated and one should use "..." to retrieve variable arguments. Ex : local firstVarArg= select(1, ...)
  • The standard interpreter is backward compatible and supports both forms. But LuaJIT only supports the newest form.
  • Solution for both LuaJIT and standard interpreter : uses "..." instead of "arg" everywhere.

Thanks to Whoward69's for correcting me about this (see message below).
  • Let f be a varargs function (a function with a "..." argument). Ex: function L(str, ...)
  • Now f is called at some point without any optional argument. Ex: L("abc")
  • According to the Lua specs, the "arg" parameter in f's body should be assigned with an empty table.
  • But LuaJIT instead assigns a nil value.
__________________
Reseed! Preview and regenerate map in-game.
Ingame Editor (IGE): An in-game editor for terrain, units, cities, civilizations, etc.
Lua and UI reference

Last edited by DonQuiche; Apr 09, 2013 at 10:46 AM.
DonQuiche is offline   Reply With Quote
Old Mar 08, 2013, 08:45 AM   #18
whoward69
Deity
 
Join Date: May 2011
Location: Near Portsmouth, UK
Posts: 5,573
Lua 5.1 deprecated the "arg" variable in a varargs function (see http://www.lua.org/manual/5.1/manual.html#7.1).

You should be able to get the same effect with
local arg = {...}
or
local arg = table.pack(...)
(various web sources)
__________________
All my mods (.civ5mod files) can be downloaded from http://www.picknmixmods.com/. If you want to incorporate (parts of) my mods into your own mod(s), please read this first

Logging Attach mod File attributes UI Tutorials My Changes Mod DDS Basics Custom Game DLL Tutorials My DLL Source Unit Art Files Civ XML Files
whoward69 is offline   Reply With Quote
Old Mar 08, 2013, 09:02 AM   #19
DonQuiche
Emperor
 
DonQuiche's Avatar
 
Join Date: May 2011
Posts: 1,115
Ahhh, thank you Whoward. Then I guess "arg" is not supported at all and I still have hidden bugs.

Well, I hope that the standard Lua interpreter supports both the pre-5.1 and post-5.1 ways.
__________________
Reseed! Preview and regenerate map in-game.
Ingame Editor (IGE): An in-game editor for terrain, units, cities, civilizations, etc.
Lua and UI reference
DonQuiche is offline   Reply With Quote
Old Mar 15, 2013, 09:21 AM   #20
whoward69
Deity
 
Join Date: May 2011
Location: Near Portsmouth, UK
Posts: 5,573
Quote:
Originally Posted by AntmanMike View Post
I've uploaded a statically-linked version which ideally should not require the MSVC11 redistributable runtimes.
Would it be possible to add "JIT" into the version string?

Code:
[13139.465] Initializing Lua 5.1.4 JIT
Then it's obvious in lua.log and the FireTuner console which dll is in use
__________________
All my mods (.civ5mod files) can be downloaded from http://www.picknmixmods.com/. If you want to incorporate (parts of) my mods into your own mod(s), please read this first

Logging Attach mod File attributes UI Tutorials My Changes Mod DDS Basics Custom Game DLL Tutorials My DLL Source Unit Art Files Civ XML Files
whoward69 is offline   Reply With Quote
Reply

Bookmarks

Tags
lua, luajit, speed, time, turn

Go Back Civilization Fanatics' Forums > CIVILIZATION V > Civ5 - Creation & Customization > Civ5 - Utility Programs > LuaJIT for Civilization V (Faster Turns)

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Advertisement

All times are GMT -6. The time now is 03:42 AM.


Powered by vBulletin®
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
This site is copyright Civilization Fanatics' Center.
Support CFC: Amazon.com | Amazon UK | Amazon DE | Amazon CA | Amazon FR