Page 2 of 3

Re: Random Map Generator

PostPosted: 02 Mar 2017, 05:30
by Rey
What was your FPS during that clip? Did the script have an impact or was it about the normal FPS?
It was about 25-30 FPS on my pretty good PC. Not so much ofc, but there was full map update on every tick (~0.1 sec) for 80*80 map.
When I changed it to update on every second tick - it become about 45-50 FPS, but much less smother. Normal FPS on that is about 60 for myPC.

It was a test to show how fast this operation can be. And for map generator purposes or changeing map once its fast more then enougth even for slow PCs.

Or some scripters can use it on some crazy maps, such as Magic Arena, but better for only part of the map, considering FPS :)

Re: Random Map Generator

PostPosted: 02 Mar 2017, 08:34
by thibmo
It was about 25-30 FPS for a full map update on every tick (~0.1 sec) for 80*80 map.
Not bad, I also highly doubt that scripters will generate sine-waves for actual maps, though. :P
Or some scripters can use it on some crazy maps, such as Magic Arena, but better for only part of the map, considering FPS :)
That's what I meant, but with some added logic you could even make a full RTS-RPG with this, changing lands from grass to desert, from mountains to a shore, etc. and that all with nice random or static seeds. :)

Re: Random Map Generator

PostPosted: 02 Mar 2017, 14:39
by thunder
https://youtu.be/UJ30WRNXBZ8?t=116
AS like an earthquake :mrgreen:

Re: Random Map Generator

PostPosted: 02 Mar 2017, 17:55
by Toxic
With new function I easily make sine wave on terrain from script, it took just a few milliseconds.
Good job!
So all other time it was script execution. I believe problem is that execution in pascal script is significally (may be 100 times) slower then in main game code.
How do you measure the script functions' time? Have KaM implemented this feature? When I run DiamondSquare in Matlab it will take cca 45 milisecond (including declaration of arrays, calculation with double precision and drawing plot - none of this is implemented in the function DiamondSquare()). Even though we have different PCs, dynamic scripting must be significantly slower.

Re: Random Map Generator

PostPosted: 02 Mar 2017, 19:11
by Rey
How do you measure the script functions' time? Have KaM implemented this feature?
For testing purposes I added TimeGet function, it returns unix time in milliseconds.
There are some restrictions why we did not add this function to scripts. But we could add this (and some other usefull functions, f.e. smth like OnUnitSelected/OnHouseSelected) for single player games. For MP games these functions could make game inconsistency if used unproperly.
But still there are few things that could be done with them even in MP, without any problems (f.e. Actions.ShowMsg and Log), but we are not sure can we rely on script maker's awareness or not, because it can make unpredictable script errors (which depends on some local info - time/when user selected house etc - which is not synchronised between players). Not sure if I described this problem clear, but I tried :)

Re: Random Map Generator

PostPosted: 02 Mar 2017, 20:19
by Toxic
But we could add this (and some other usefull functions, f.e. smth like OnUnitSelected/OnHouseSelected)...
These are actually really useful events. It should help players to understand some scripts (they don't read pdf) by uploading Overlay of specific player for example in Caravan script. I am not afraid of desynchronization - if you add note to this command it will be fine.

Re: Random Map Generator

PostPosted: 03 Mar 2017, 05:32
by Krom
(they don't read pdf) ... if you add note to this command it will be fine.
Sounds contradictory ;-)


Desync errors are very easy to introduce by mistake and it's very hard to detect their cause when a crash happens.

If possible, we would keep functions that could introduce them out of the scripting engine.

Many of the requested features (e.g. measuring time) could be done without exposing such functions.

E.g.
- timeGet can be easily replaced with BeginPeriod / EndPeriod, with the latter appending text into the log.
- OnHouseSelected could be possibly replaced with Action.TextOnHouseSelect(House.UID, text_to_show).

Re: Random Map Generator

PostPosted: 03 Mar 2017, 19:15
by Toxic
(they don't read pdf) ... if you add note to this command it will be fine.
Sounds contradictory ;-)
I don't think so - first sentense was about players and the other loghicaly about scripters.
Action.TextOnHouseSelect(House.UID, text_to_show)
This action could return true/false if player had clicked on it since last calling of this action.
Or to add aditional parameter time when this text cannot be overwriten by Actions.OverlayTextSet.

Re: Random Map Generator

PostPosted: 03 Mar 2017, 20:32
by Rey
This action could return true/false if player had clicked on it since last calling of this action.
No it can't work this way. Because you will be able to check this on every state, and when house was selected alter game state when one player clicked on smth, f.e. add wared to house, but other players will be not notified about this event (selection) so they will not add wares to that players house. Desyncronisation will occur.

So we can just simply show some text or log smth on some event, but we can't allow to know when did it happen

Re: Random Map Generator

PostPosted: 03 Mar 2017, 22:06
by thibmo
This action could return true/false if player had clicked on it since last calling of this action.
This could better work if you return an ID, then when it gets clicked perform an event eg: OnHouseWithEventClick(aEventID: Integer);

Like that you could perhaps include it into MP by sending the event trigger to all other players. (True, brings possible issues, though it's cleaner then the previously stated)
These events could perhaps even be callbacks? (Not sure how that will work out, might be used maliciously, which I would advise against.)

Re: Random Map Generator

PostPosted: 04 Mar 2017, 07:23
by Krom
(they don't read pdf) ... if you add note to this command it will be fine.
Sounds contradictory ;-)
I don't think so - first sentense was about players and the other loghicaly about scripters.
What I mean, is that placing a text anywhere in the docs does not mean it gets read or taken into account. Be it by players, or by mapmakers, or by programmers (like me). It should be at least a warning in ScriptValidator to be seen.
Action.TextOnHouseSelect(House.UID, text_to_show)
This action could return true/false if player had clicked on it since last calling of this action.
Or to add aditional parameter time when this text cannot be overwriten by Actions.OverlayTextSet.
Text management could be done from within script itself.

Re: Random Map Generator

PostPosted: 04 Mar 2017, 07:55
by Rey
Like that you could perhaps include it into MP by sending the event trigger to all other players
In that case its possible to add OnHouseSelected. But it could provide too many extra packets. Some tests should be done in that direction to be sure it will be ok.

Re: Random Map Generator

PostPosted: 04 Mar 2017, 10:20
by Krom
Like that you could perhaps include it into MP by sending the event trigger to all other players
In that case its possible to add OnHouseSelected. But it could provide too many extra packets. Some tests should be done in that direction to be sure it will be ok.
Also take into account, that if done through GIP, it will lag just like other commands.

Re: Random Map Generator

PostPosted: 08 Mar 2017, 06:43
by Lewin
Sometimes happens: "EAssertionFailed: UpdateWalkConnect failed due too many unconnected areas" in file KaM Remake\Trunk\src\KM_TerrainWalkConnect.pas, line 294.
This occurs when more than 255 separate "islands" are created on the map. As an optimisation the pathfinding code assumes there will never be more than 255 different islands (which is fine for normal maps). For example this would probably happen if you set the height of all tiles on the map to a random value since you will end up with lots of disconnected islands of 2-3 tiles.

Desynchronisation breaks singleplayer replays as well, so it's not just a multiplayer issue. As Krom said there are alternative ways to implement timing logs like BeginPeriod / EndPeriod. Desynchronisation bugs are extremely difficult to track down since they will usually occur a long time after the desynchronisation occurred in some other random place. I'm strongly against adding anything to the API which allows scripts to cause desynchronisation as it puts too much onus on the script authors to follow arbitrary guidelines, and desynchronisation crashes will make the game appear buggy and be misattributed to the game rather than the script. Right now it's basically impossible to crash the game from the script which is a great thing IMO.

PascalScript is executed as bytecode, it's not going to be nearly as fast as compiled code. If you implemented your random map generator in the native KaM Remake code your performance issues would stop being a problem, and you would also avoid having to reimplement your terrain painting functions (managing tile transitions) since we have those already. I'm happy to help you get it compiling on your machine if you are interested.

Re: Random Map Generator

PostPosted: 08 Mar 2017, 06:58
by Krom
Desynchronisation bugs are extremely difficult to track down since they will usually occur a long time after the desynchronisation occurred in some other random place. I'm strongly against adding anything to the API which allows scripts to cause desynchronisation as it puts too much onus on the script authors to follow arbitrary guidelines, and desynchronisation crashes will make the game appear buggy and be misattributed to the game rather than the script. Right now it's basically impossible to crash the game from the script which is a great thing IMO.
Well said. I fully agree.