Currently Online

Latest Posts

Topic: Avg. FPS available from LUA?

Tibor

Topic Opener
Joined: 2009-03-23, 23:24
Posts: 1377
Ranking
One Elder of Players
Location: Slovakia
Posted at: 2017-06-03, 21:18

From lua script we can set a speed of the game. But can we get actual average FPS from lua script ? My idea is a script that would continually tweak speed of game to keep FPS in range f.e. 15 - 18. To speed up AI testing...


Top Quote
GunChleoc
Avatar
Joined: 2013-10-07, 15:56
Posts: 3324
Ranking
One Elder of Players
Location: RenderedRect
Posted at: 2017-06-04, 09:10

Not yet, we'd have to add it. At the moment, it's calculated in InteractiveBase::draw_overlay().


Busy indexing nil values

Top Quote
Tibor

Topic Opener
Joined: 2009-03-23, 23:24
Posts: 1377
Ranking
One Elder of Players
Location: Slovakia
Posted at: 2017-06-04, 10:55

I will look at the code, it would help me...


Top Quote
Tibor

Topic Opener
Joined: 2009-03-23, 23:24
Posts: 1377
Ranking
One Elder of Players
Location: Slovakia
Posted at: 2017-06-04, 17:12

It seems to be too complicated for me :( Alternatively if there was a counter of frames and LUA could get a number of actual frame - I would calculate the rest... But it seems there is nothing like that...


Top Quote
Tibor

Topic Opener
Joined: 2009-03-23, 23:24
Posts: 1377
Ranking
One Elder of Players
Location: Slovakia
Posted at: 2017-06-04, 22:50

BTW, is there a way how could LUA script read a file? I found some examples on net, but it failed because of missing IO library. I tried 'require "io"' but no success


Top Quote
GunChleoc
Avatar
Joined: 2013-10-07, 15:56
Posts: 3324
Ranking
One Elder of Players
Location: RenderedRect
Posted at: 2017-06-05, 12:02

We route everything through C++ for security reasons, so this would have to be added to the Lua interface too.

https://bazaar.launchpad.net/~widelands-dev/widelands/trunk/view/head:/src/scripting/lua_globals.cc#L273

How about we try to finish up a branch for the new AI, and then deal with this stuff for further tweaks afterwards?

Edited: 2017-06-05, 12:02

Busy indexing nil values

Top Quote
Tibor

Topic Opener
Joined: 2009-03-23, 23:24
Posts: 1377
Ranking
One Elder of Players
Location: Slovakia
Posted at: 2017-06-05, 12:41

To have it considered ready to trunk one big thing remains:

Having AI DNA in separate files, unlike now, when it is part of *.cc file. Such files would be loadable when AI is initialized and a very conveniet would be dumping current DNA of each AI player to a file during AI initialization and DNA mutation, in a format so that it can be used for initialization next time if somebody decides that he likes the performance of the AI player.

The goal is to enable training of AI without modifying the .cc file and necessary recompilation. Editing the .cc file is complicated and requires some formatting woodoo. face-smile.png


Top Quote
Tibor

Topic Opener
Joined: 2009-03-23, 23:24
Posts: 1377
Ranking
One Elder of Players
Location: Slovakia
Posted at: 2017-06-05, 20:39

So I managed a cool hack - purely within interactive_base.cc. Auto-adjusting speed of game to keep avg fps within 13-15 fps. Very very cool and useful for testing of AI!!! face-smile.png


Top Quote
GunChleoc
Avatar
Joined: 2013-10-07, 15:56
Posts: 3324
Ranking
One Elder of Players
Location: RenderedRect
Posted at: 2017-06-06, 09:12

face-smile.png

You could use the Profile format for writing and loading the AI initializations. You can see a small code example on how it's used in the Options panel, and in logic/campaign_visibility.cc.

Using LuaTable instead would allow you to have a structure that's easier to understand, but we don't have a good writer for it. I do have a working Lua writer in a branch, but it's a bit hacky and tricky to use because I was too lazy to write a proper parser.


Busy indexing nil values

Top Quote
Tibor

Topic Opener
Joined: 2009-03-23, 23:24
Posts: 1377
Ranking
One Elder of Players
Location: Slovakia
Posted at: 2017-06-06, 09:35

GunChleoc wrote:

face-smile.png

You could use the Profile format for writing and loading the AI initializations. You can see a small code example on how it's used in the Options panel, and in logic/campaign_visibility.cc.

Using LuaTable instead would allow you to have a structure that's easier to understand, but we don't have a good writer for it. I do have a working Lua writer in a branch, but it's a bit hacky and tricky to use because I was too lazy to write a proper parser.

this probably belongs to the other thread.

I will look at it, though I am bit afraid of it face-smile.png


Top Quote