How do I reduce lag at the beginning of scenerio.

The place to post your WML questions and answers.

Moderator: Forum Moderators

Forum rules
  • Please use [code] BBCode tags in your posts for embedding WML snippets.
  • To keep your code readable so that others can easily help you, make sure to indent it following our conventions.
Post Reply
User avatar
Luroch_Delkar
Posts: 44
Joined: August 11th, 2010, 11:15 pm
Location: Some people are in homes, some are in cars, I am in-sane.

How do I reduce lag at the beginning of scenerio.

Post by Luroch_Delkar »

When my scenario is loaded it goes to the [story] bit like normal.
After the story though there is a huge loading delay before the first turn.
I know that this is common for games that use Bob's_RPG era, but would like to at least reduce the delay a little bit.

The delay is primarily because I place many items during [event]name=start .
These items are on top of what Bob's_RPG era places.
"The Enforcer knows only one way to preserve peace. So mind your neighbors else it will descend upon you." Sword of the Stars Forever
HAPPINESS=Moderation, Variety, and Love
Current Projects: Jailbreak (RPG)(3/4 completed) , Dungeonmaster Era
Anonymissimus
Inactive Developer
Posts: 2461
Joined: August 15th, 2008, 8:46 pm
Location: Germany

Re: How do I reduce lag at the beginning of scenerio.

Post by Anonymissimus »

Don't know Bob's_RPG era, however, such lag can afaik be caused by "wml bloat". That means lots of wml code that needs to be interpreted when loading a scenario, the interpretation process is slow. Working against it is difficult. Try writing with less wml while keeping the functionality. Remember that macros get their code inserted at the target position. Use lua.
projects (BfW 1.12):
A Simple Campaign: campaign draft for wml startersPlan Your Advancements: mp mod
The Earth's Gut: sp campaignSettlers of Wesnoth: mp scenarioWesnoth Lua Pack: lua tags and utils
updated to 1.8 and handed over: A Gryphon's Tale: sp campaign
User avatar
Luroch_Delkar
Posts: 44
Joined: August 11th, 2010, 11:15 pm
Location: Some people are in homes, some are in cars, I am in-sane.

Re: How do I reduce lag at the beginning of scenerio.

Post by Luroch_Delkar »

It is definitely wml bloating, but I tried to write as little code as possible. I do have a particular macro (one that places items on the map) that I insert many times during [event]name=turn_1 .

Code: Select all

#define JB_PLACE_MATERIAL_VASE X Y MATERIAL SPEAKER MESSAGE
[item]
x={X}
y={Y}
image=items/ornate2.png
[/item]
[event]name=moveto
[filter]
x={X}
y={Y}
[/filter]
{PLAY_SOUND fist.ogg}
{PLAY_SOUND petrified.ogg}
[removeitem]
x={X}
y={Y}
image=items/ornate2.png
[/removeitem]
[message]speaker={SPEAKER}
message= _ "{MESSAGE}"
[/message]
{BOB_PLACE_MATERIAL {MATERIAL} {X} {Y}} 
[/event]
#enddef
I refer to this macro 12 times during the turn 1 event.
I also use other macros like this during the same event.

Also during that event I place several units without using macros.
Their code varies a bit but is always something like:

Code: Select all

	[unit]
		x=12
		y=59
		side=3
		type="Heavy Infantryman"	
		id="hi1"
		name= _ "Grog"	
		role=heavy_infantryman
		hitpoints=22
	[modifications]	
		{TRAIT_LOYAL}
	[/modifications]	
	[/unit]
Now that I look at it I see how the item placing code might be diminished a wee bit, but the unit code seems to be at it's minimal limit.
"The Enforcer knows only one way to preserve peace. So mind your neighbors else it will descend upon you." Sword of the Stars Forever
HAPPINESS=Moderation, Variety, and Love
Current Projects: Jailbreak (RPG)(3/4 completed) , Dungeonmaster Era
User avatar
Sapient
Inactive Developer
Posts: 4453
Joined: November 26th, 2005, 7:41 am
Contact:

Re: How do I reduce lag at the beginning of scenerio.

Post by Sapient »

You can try using the prestart event instead of the start event.
It occurs before the map is drawn, if I recall correctly, so it may cut down on redraw time.

Also you left out the definition of BOB_PLACE_MATERIAL so we have no way of knowing the total bloat from your item placement code.
http://www.wesnoth.org/wiki/User:Sapient... "Looks like your skills saved us again. Uh, well at least, they saved Soarin's apple pie."
User avatar
Luroch_Delkar
Posts: 44
Joined: August 11th, 2010, 11:15 pm
Location: Some people are in homes, some are in cars, I am in-sane.

Re: How do I reduce lag at the beginning of scenerio.

Post by Luroch_Delkar »

Wasn't sure if items could be placed during the prestart, seeing as there is no map yet to place them on. Or is that preload I am thinking of? In any case I will try it.

Also the BOB_PLACE_MATERIAL MATERIAL X Y is a macro defined in Bob's rpg era. I am not sure where he keeps the definition of that macro. Nor do I want to mess with that macro much in case I prevent the Era from working the way it should.

The prestart will help though if it works. Perhaps the wait will not seem so long if all the lag occurs before you start doing anything. (Right now the lag from Bob's_rpg era happens before the objectives are shown and the lag from my scenario happens after.)

Thanks, I think I have now cleaned the code up as much as it is going to be.
"The Enforcer knows only one way to preserve peace. So mind your neighbors else it will descend upon you." Sword of the Stars Forever
HAPPINESS=Moderation, Variety, and Love
Current Projects: Jailbreak (RPG)(3/4 completed) , Dungeonmaster Era
User avatar
Bob_The_Mighty
Posts: 870
Joined: July 13th, 2006, 1:15 pm

Re: How do I reduce lag at the beginning of scenerio.

Post by Bob_The_Mighty »

In Bob's RPG Era / files / scenario_macros.cfg you will find this:

Code: Select all

#define BOB_PLACE_MATERIAL VARIABLE X Y
[store_locations]
	x={X}
	y={Y}
	variable={VARIABLE}_xy
	[or]
		find_in={VARIABLE}_xy
	[/or]
[/store_locations]
{FOREACH {VARIABLE}_xy i}
	{PLACE_IMAGE items/{VARIABLE}.png ${VARIABLE}_xy[$i].x ${VARIABLE}_xy[$i].y}
{NEXT i}
#enddef
This macro is meant to only be included once. You can add many locations in one call: {BOB_PLACE_MATERIAL ulox_rock "11,12,32" "3,46,23"}. This will place 3 ulox rocks on the hexes 11,3 12,46 and 32,23.

However, since you want a custom event with a message, etc. Better to make your own version. Something like this would work:

Code: Select all

#define JB_PLACE_MATERIAL_VASE X Y MATERIAL MESSAGE

[store_locations]
	x={X}
	y={Y}
	variable={MATERIAL}_xy
	[or]
		find_in={MATERIAL}_xy
	[/or]
[/store_locations]
{FOREACH {MATERIAL}_xy i}
	{PLACE_IMAGE items/ornate2.png ${MATERIAL}_xy[$i].x ${MATERIAL}_xy[$i].y}
{NEXT i}

[event]
name=moveto
first_time_only=no
[filter]
x={X}
y={Y}
[filter_location]
   find_in={MATERIAL}_xy
  [/filter_location]
[/filter]

{PLAY_SOUND fist.ogg}
{PLAY_SOUND petrified.ogg}

[removeitem]
	x,y=$x1,$y1
[/removeitem]

 [store_locations]
  variable={MATERIAL}_xy
  find_in={MATERIAL}_xy
  [not]
   x,y=$x1,$y1
  [/not]
 [/store_locations]

[message]
speaker=unit
message= _ "{MESSAGE}"
[/message]

[/event]
#enddef
Then all 12 macros calls could be replaced by this one: {JB_PLACE_MATERIAL_VASE "12,3,etc" "56,32,etc" ulox_rock "Hey, this rocks!"}
My current projects:
MP pirate campaign: The Altaz Mariners
RPG sequel: Return to Trent
MP stealth campaign: Den of Thieves
Anonymissimus
Inactive Developer
Posts: 2461
Joined: August 15th, 2008, 8:46 pm
Location: Germany

Re: How do I reduce lag at the beginning of scenerio.

Post by Anonymissimus »

Repeated usage of a SLF should also be avoided (if you can), especially with radius= or find_in= since SLF is not so efficiently implemented in the engine.
projects (BfW 1.12):
A Simple Campaign: campaign draft for wml startersPlan Your Advancements: mp mod
The Earth's Gut: sp campaignSettlers of Wesnoth: mp scenarioWesnoth Lua Pack: lua tags and utils
updated to 1.8 and handed over: A Gryphon's Tale: sp campaign
User avatar
Luroch_Delkar
Posts: 44
Joined: August 11th, 2010, 11:15 pm
Location: Some people are in homes, some are in cars, I am in-sane.

Re: How do I reduce lag at the beginning of scenerio.

Post by Luroch_Delkar »

Hmmm, I have never seen the find_in key before. What roughly does it do?
Oh, and what part of the code id's the item as huanti leaves/ulox rock/etc., since I want your era to recognize it and add {material} to the player's inventory rather than some item I make up myself?

I will save making my own items to later. :D

Well thanks for the info. I am currently looking up store_location, find_in= , and am browsing Bob's code for how you add items to one's inventory in your era.
"The Enforcer knows only one way to preserve peace. So mind your neighbors else it will descend upon you." Sword of the Stars Forever
HAPPINESS=Moderation, Variety, and Love
Current Projects: Jailbreak (RPG)(3/4 completed) , Dungeonmaster Era
User avatar
Bob_The_Mighty
Posts: 870
Joined: July 13th, 2006, 1:15 pm

Re: How do I reduce lag at the beginning of scenerio.

Post by Bob_The_Mighty »

ulox_rock_xy contains co-ordinates for every ulox rock on the map - the code I posted should do that. The macros in the era deal with items getting picked up and added to the inventory.

I cannot explain it further because I don't fully understand it myself. :)
My current projects:
MP pirate campaign: The Altaz Mariners
RPG sequel: Return to Trent
MP stealth campaign: Den of Thieves
User avatar
Luroch_Delkar
Posts: 44
Joined: August 11th, 2010, 11:15 pm
Location: Some people are in homes, some are in cars, I am in-sane.

Re: How do I reduce lag at the beginning of scenerio.

Post by Luroch_Delkar »

Oh, Well thanks, that was very helpful. That was my only question for now, but I will come back when I have another. (If I can't solve it myself first that is. :D )
"The Enforcer knows only one way to preserve peace. So mind your neighbors else it will descend upon you." Sword of the Stars Forever
HAPPINESS=Moderation, Variety, and Love
Current Projects: Jailbreak (RPG)(3/4 completed) , Dungeonmaster Era
Post Reply