Using [resource] and [load_resource]

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.
User avatar
LordAwsomeness
Posts: 203
Joined: August 12th, 2013, 2:20 pm
Location: U.S.A.

Using [resource] and [load_resource]

Post by LordAwsomeness »

Once again hi all.
So I am attempting to optimize my load times and help my add-ons that rely on each other not crash wesnoth on lower end PC's, in order to attempt to do that I've been researching a lot of optimization options. One of which options would be to use the [resource] and [load_resource] tags.
While I get the overall premise behind it, I just want to understand better how to use it at the toplevel of a scenario and would like to know where I would need to put the macros and other code that would need to be loaded in the resource tags. If I'm completely off, somebody please set me straight and explain how I could potentially use it to optimize and speed up my add-ons so that people on lower end machines can still enjoy my content.
- Been playing Wesnoth since 2004 and the 1.0.x versions.
- Creator of Undead Invasion MP Scenario Pack.
- Creator of Valeria MP Adventure
- Creator of LA_RPG ERA
User avatar
Ravana
Forum Moderator
Posts: 2477
Joined: January 29th, 2012, 12:49 am
Location: Estonia
Contact:

Re: Using [resource] and [load_resource]

Post by Ravana »

[resource] is not supposed to give any performance benefit at all.
gfgtdf
General Code Maintainer
Posts: 1344
Joined: February 10th, 2013, 2:25 pm

Re: Using [resource] and [load_resource]

Post by gfgtdf »

Ravana wrote: March 3rd, 2020, 7:40 pm [resource] is not supposed to give any performance benefit at all.
well this is not complteley true, if you have one addon that for example contains many scenrios and you want to want to use a code in each of those scenarios and would otherwise do that by putting a macro in each of those scenarios, then [resource] can reduce the ram usage/paring time.

But if you talk about performance while playing a scenario (which here explicitly doesn't count wml parsing times) then yes: it doesn't give any performance boost there.
Scenario with Robots SP scenario (1.11/1.12), allows you to build your units with components, PYR No preperation turn 1.12 mp-mod that allows you to select your units immideately after the game begins.
User avatar
octalot
Developer
Posts: 534
Joined: July 17th, 2010, 7:40 pm
Location: Austria

Re: Using [resource] and [load_resource]

Post by octalot »

Two quick-and-dirty patch-ups of what gfgtdf said:
User avatar
LordAwsomeness
Posts: 203
Joined: August 12th, 2013, 2:20 pm
Location: U.S.A.

Re: Using [resource] and [load_resource]

Post by LordAwsomeness »

gfgtdf wrote: March 3rd, 2020, 8:40 pm
Ravana wrote: March 3rd, 2020, 7:40 pm [resource] is not supposed to give any performance benefit at all.
well this is not complteley true, if you have one addon that for example contains many scenrios and you want to want to use a code in each of those scenarios and would otherwise do that by putting a macro in each of those scenarios, then [resource] can reduce the ram usage/paring time.

But if you talk about performance while playing a scenario (which here explicitly doesn't count wml parsing times) then yes: it doesn't give any performance boost there.
The parsing time and lower end models running out of memory because of the engine reading the same nested macros over and over is the main issue. it runs quite well once in game if you disable autosaving. even with autosaving on it doesn't crash or have any major issues; it is just quite time consuming to have to wait. I also noticed however that when I changed the savefiles to uncompressed that it could not save. im assuming that it was just too much information for the system to handle.

But I am going to try the [resource] and [load_resource] tags as I believe this will cut back on a majority of the preprocessing redundancies; which is the major issue at hand.
octalot wrote: March 3rd, 2020, 8:47 pm Two quick-and-dirty patch-ups of what gfgtdf said:
Thank you so much for linking me with examples of the code that i will need! I have been reviewing them to try and see how to use it, however it is slightly confusing me. so am I supposed to turn everything that I need into a single custom event and fire the custom event in the prestart or something?

I have a lot of code in the core add-on that the other addons draw from, so im wondering just how exactly for the several scenarios that run the same code (causing the preprocessing redundancy overloads) would I create the simplest version for my own usage? The wiki is kind of vague. Thank you so much for your help!

EDIT: just for re-clarification: the addon does fine once it has been loaded, it is just the redundancies in the preprocessing that prevents my addon from even loading in the first place. The is the issue I would like to solve which is why I believe that the [resources] would be the proper solution. Sorry for not making that clear and causing confusion early on :oops:
- Been playing Wesnoth since 2004 and the 1.0.x versions.
- Creator of Undead Invasion MP Scenario Pack.
- Creator of Valeria MP Adventure
- Creator of LA_RPG ERA
User avatar
LordAwsomeness
Posts: 203
Joined: August 12th, 2013, 2:20 pm
Location: U.S.A.

Re: Using [resource] and [load_resource]

Post by LordAwsomeness »

I made the resource tags in the era page and dropped all of the events in it as such:

Code: Select all

	[resource]
		id=la_always_active_event
		{LA_RPG_ERA_RESOURCE_PACKAGE}

	[/resource]
this I placed in the toplevel of the era.cfg in the core addon.
next i "loaded" the resources in the scenario as such:

Code: Select all


	[load_resource]
		id=la_always_active_event
	[/load_resource]
	{LA_RPG_ERA_RESOURCE_PACKAGE}
however the set_menu_items were not working and since everything runs off of that intial set_menu_item i am not quite sure what else may have been wrong.
- Been playing Wesnoth since 2004 and the 1.0.x versions.
- Creator of Undead Invasion MP Scenario Pack.
- Creator of Valeria MP Adventure
- Creator of LA_RPG ERA
User avatar
LordAwsomeness
Posts: 203
Joined: August 12th, 2013, 2:20 pm
Location: U.S.A.

Re: Using [resource] and [load_resource]

Post by LordAwsomeness »

Okay I have tried several different ways of trying to use resource and load resource but it isn't working. Is there somebody who could potentially explain what exactly I need to put in the resource tag? I would be very grateful as with the current iteration of my era it cannot even be played with the maps because they overload the memory since the macros are being loaded over and over.

I have been trying to use the examples from Survival Xtreme collection as well as Castle of Evil Spirit however I haven't figured out exactly what code needs to be put in the resource tag.
- Been playing Wesnoth since 2004 and the 1.0.x versions.
- Creator of Undead Invasion MP Scenario Pack.
- Creator of Valeria MP Adventure
- Creator of LA_RPG ERA
gfgtdf
General Code Maintainer
Posts: 1344
Joined: February 10th, 2013, 2:25 pm

Re: Using [resource] and [load_resource]

Post by gfgtdf »

LordAwsomeness wrote: March 4th, 2020, 5:56 pm Okay I have tried several different ways of trying to use resource and load resource but it isn't working. Is there somebody who could potentially explain what exactly I need to put in the resource tag? I would be very grateful as with the current iteration of my era it cannot even be played with the maps because they overload the memory since the macros are being loaded over and over.

I have been trying to use the examples from Survival Xtreme collection as well as Castle of Evil Spirit however I haven't figured out exactly what code needs to be put in the resource tag.
as i said before, load_resource can only give improvements if you have a macro that is used in multiple scenario/era/multiplayer etc tags. So if you are just developing one era it won't help you.
Scenario with Robots SP scenario (1.11/1.12), allows you to build your units with components, PYR No preperation turn 1.12 mp-mod that allows you to select your units immideately after the game begins.
User avatar
LordAwsomeness
Posts: 203
Joined: August 12th, 2013, 2:20 pm
Location: U.S.A.

Re: Using [resource] and [load_resource]

Post by LordAwsomeness »

gfgtdf wrote: March 4th, 2020, 6:04 pm as i said before, load_resource can only give improvements if you have a macro that is used in multiple scenario/era/multiplayer etc tags. So if you are just developing one era it won't help you.
But I also said that it's macros are getting used by multiple scenarios rather than just one so it gets loaded by the preprocessor multiple times. And my current issue is my lack of understanding of what I need to put in the [resource] tag. I'm very confident after examining the other scenarios and reading their delimas that our issues are the same. So I just need somebody to explain what all I will need to put into the tag so that it will actually work.

EDIT: Below is the code that I currently put into the [resource] tag.

Code: Select all

#define LA_RPG_ERA_RESOURCE_PACKAGE

{LA_POST_ADVANCE}

#####################################
#remeber to set these in the scenario!!!!
{LA_SPOILS_SHARE}
{LA_SET_POINTS_EVENT 2}

[event]
	name=prestart
	{VARIABLE LA_RPG_Era yes}
	{VARIABLE la_turn_number 0}
[/event]

[event]
	name=new turn
	first_time_only=no
	{VARIABLE_OP la_turn_number add 1}
[/event]

{LA_MAGIC_ABILITY_EVENT_DROPBOX}
#{LA_ARCANE_SHIELD_EVENT_OLD} 


[event]
	name=side $side_number turn refresh
	first_time_only=no
[if]
{VARIABLE_CONDITIONAL la_hero[$side_number].race.dwarf.fury equals yes}
[then]
[store_unit]
[filter]
side=$side_number
canrecruit=yes
[/filter]
variable=unit_store
[/store_unit]
{VARIABLE_OP unit_store.attacks_left add 1}
[unstore_unit]
variable=unit_store
text="Dwarvish Fury"
[/unstore_unit]
{CLEAR_VARIABLE unit_store}
[/then]
[/if]
[/event]

[event]
	name=side $side_number turn
	first_time_only=no
#restore casts as well
{VARIABLE la_hero[$side_number].actions.left $la_hero[$side_number].actions.max}
{VARIABLE la_hero[$side_number].casts.left $la_hero[$side_number].casts.max}

[if]
{VARIABLE_CONDITIONAL la_hero[$side_number].magic.mana.current less_than $la_hero[$side_number].magic.mana.max}
[then]
{VARIABLE_OP la_hero[$side_number].magic.mana.current add $la_hero[$side_number].magic.mana.recovery}

[store_unit]
[filter]
side=$side_number
canrecruit=yes
[/filter]
variable=unit_store
[/store_unit]
[unstore_unit]
variable=unit_store
text="+$la_hero[$side_number].magic.mana.recovery Mana"
red,green,blue=150,200,255
[/unstore_unit]
{CLEAR_VARIABLE unit_store}
[/then]
[/if]

#yea def need to come up with a better system for adding wrath on than this current one... works when you reequip weapons tho.
#

{LA_MAGIC_EFFECTS_LIST_START}
{LA_FIREABLE_EVENTS}

{LA_MANA_OVERLOAD_CHECK}
#set vars for casting cooldowns
{LA_CASTING_COOLDOWN_LIST}

{LA_MANA_REFRESH}
[/event]

[event]
	name=side $side_number turn end
	first_time_only=no

{LA_MAGIC_EFFECTS_LIST_END}
[/event]

[event]
	name=start
	[message]
		speaker=narrator
		caption=_ "LA RPG Era"
		image=wesnoth-icon.png
		message=_ "Version 0.3.3
 
- Right-click on your unit to design your hero.

(If the game is slow at the start of each turn, disable autosaves)"
	[/message]
#	 {LA_HERO_INITIALIZE} 
	
	{LA_RACE_BASE_STATS drake 5 5 3 7}
	{LA_RACE_BASE_STATS dwarf 4 4 5 7}
	{LA_RACE_BASE_STATS elf 6 6 5 3}
	{LA_RACE_BASE_STATS goblin 6 4 7 3}
	{LA_RACE_BASE_STATS human 5 5 5 5}
	{LA_RACE_BASE_STATS orc 5 5 3 7}
	{LA_RACE_BASE_STATS saurian 7 5 7 2}
	{LA_RACE_BASE_STATS troll 4 3 6 7}
	
	{LA_RACE_BASE_STATS_UPGRADES drake 3 3 3 3}
	{LA_RACE_BASE_STATS_UPGRADES dwarf 3 3 3 2}
	{LA_RACE_BASE_STATS_UPGRADES elf 2 2 3 4}
	{LA_RACE_BASE_STATS_UPGRADES goblin 2 3 2 3}
	{LA_RACE_BASE_STATS_UPGRADES human 3 3 3 3}
	{LA_RACE_BASE_STATS_UPGRADES orc 3 3 4 4}
	{LA_RACE_BASE_STATS_UPGRADES saurian 2 3 2 4}
	{LA_RACE_BASE_STATS_UPGRADES troll 3 4 2 2}
	
	{LA_WEAPON_LIST}
	{LA_WEAPONS_CALCULATIONS}
	{LA_ARMOR_LIST}
		
	{LA_HERO_DROPBOX}
	{VARIABLE la_shop_wares 1}
	{LA_SHOP $la_shop_x $la_shop_y}
	{PLACE_IMAGE "scenery/weapons_shop.png" $la_shop_x $la_shop_y}
	
	{VARIABLE la.shop.tier1.total 0}
	{VARIABLE la.shop.tier2.total 0}
	{VARIABLE la.shop.tier3.total 0}
	{VARIABLE la.shop.tier4.total 0}
	{VARIABLE la.shop.tier5.total 0}
	{LA_SHOP_START_ITEM_VARIABLES}
	{LA_SHOP_RESTOCK_COUNTER 20 50 1}
	{LA_SHOP_RESTOCK_COUNTER 50 80 2}
	{LA_SHOP_RESTOCK_COUNTER 150 280 3}
	{LA_SHOP_RESTOCK_COUNTER 250 9999 4}


	{VARIABLE la.wrath.stacks 0}
	{VARIABLE la.wrath.stacks.total 0}
[/event]

[event]
name=moveto
first_time_only=no
[filter]
side=$la_player_sides
[filter_location]
terrain="*^V*"
[/filter_location]
[/filter]
[if]
#on the off chance i make a scenario where i dont mind players taking villages  
{VARIABLE_CONDITIONAL la_players.village_capturing equals yes}
[then]
[/then]
[else]
[capture_village]
side=0
x=$x1
y=$y1
[/capture_village]
[/else]
[/if]
[/event]
#enddef

This one below was put into the main.cfg under the #ifdef MULTIPLAYER after the macros and scenarios had been set to be loaded.

Code: Select all

	[resource]
		id=la_always_active_event
		{LA_RPG_ERA_RESOURCE_PACKAGE}

	[/resource]
In the scenario I put this after the map was loaded in the toplevel before the prestart event

Code: Select all

[load_resource]
		id=la_always_active_event
	[/load_resource]
	{LA_RPG_ERA_RESOURCE_PACKAGE}
Is this correct or am I doing something wrong? Because when I previously didn't put the LA_RPG_ERA_RESOURCE_PACKAGE macro in the scenario none of the events and variables showed up at all with the inspect tool. And when I do it this way the system still has the overload issues.
- Been playing Wesnoth since 2004 and the 1.0.x versions.
- Creator of Undead Invasion MP Scenario Pack.
- Creator of Valeria MP Adventure
- Creator of LA_RPG ERA
gfgtdf
General Code Maintainer
Posts: 1344
Joined: February 10th, 2013, 2:25 pm

Re: Using [resource] and [load_resource]

Post by gfgtdf »

LordAwsomeness wrote: March 4th, 2020, 6:34 pm Is this correct or am I doing something wrong? Because when I previously didn't put the LA_RPG_ERA_RESOURCE_PACKAGE macro in the scenario none of the events and variables showed up at all with the inspect tool. And when I do it this way the system still has the overload issues.
no, you shouldn't put the LA_RPG_ERA_RESOURCE_PACKAGE macro in the scenario, the point of [load_resoruce] is exactly that you just have to write {LA_RPG_ERA_RESOURCE_PACKAGE} once in your addon (instead of fop putting in each scenario). If it doesnt work then then there is maybe something else wrong, are you sure you reloaded the cache correctly? Did it print other erros in the errolog file?
Scenario with Robots SP scenario (1.11/1.12), allows you to build your units with components, PYR No preperation turn 1.12 mp-mod that allows you to select your units immideately after the game begins.
User avatar
LordAwsomeness
Posts: 203
Joined: August 12th, 2013, 2:20 pm
Location: U.S.A.

Re: Using [resource] and [load_resource]

Post by LordAwsomeness »

gfgtdf wrote: March 4th, 2020, 9:14 pm
no, you shouldn't put the LA_RPG_ERA_RESOURCE_PACKAGE macro in the scenario, the point of [load_resoruce] is exactly that you just have to write {LA_RPG_ERA_RESOURCE_PACKAGE} once in your addon (instead of fop putting in each scenario). If it doesnt work then then there is maybe something else wrong, are you sure you reloaded the cache correctly? Did it print other erros in the errolog file?
I checked the logs and theres a huge list of the following:

Code: Select all

20200304 18:03:58 error preprocessor: Macro/file 'LIST' is missing
at ~add-ons/LA_MP_Pack/utils/inventory/equip_macros.cfg:2191
    included from ~add-ons/LA_MP_Pack/utils/paths.cfg:12
    included from ~add-ons/LA_MP_Pack/LA_RPG_Era.cfg:77
    included from ~add-ons/LA_MP_Pack/_main.cfg:15
    included from ~add-ons/LA_MP_Pack/LA_RPG_Era.cfg:78
    included from ~add-ons/LA_MP_Pack/_main.cfg:15
but it's referring to the core macros such as: {SOUND:HIT_AND_MISS {SOUND_LIST:SWORD_SWISH} {SOUND_LIST:MISS} -100}

and because I have a lot of units the error list goes on for the entire file. however the game runs without issues. it also has the error magenta_is_team_color error but that's just a deprication warning.

The error logs do show that [load_resource] isn't work properly. what would be causing that?
20200303 20:47:44 error engine: Couldn't find [resource] with id=la_always_active_event
- Been playing Wesnoth since 2004 and the 1.0.x versions.
- Creator of Undead Invasion MP Scenario Pack.
- Creator of Valeria MP Adventure
- Creator of LA_RPG ERA
gfgtdf
General Code Maintainer
Posts: 1344
Joined: February 10th, 2013, 2:25 pm

Re: Using [resource] and [load_resource]

Post by gfgtdf »

LordAwsomeness wrote: March 5th, 2020, 1:30 am
gfgtdf wrote: March 4th, 2020, 9:14 pm
no, you shouldn't put the LA_RPG_ERA_RESOURCE_PACKAGE macro in the scenario, the point of [load_resoruce] is exactly that you just have to write {LA_RPG_ERA_RESOURCE_PACKAGE} once in your addon (instead of fop putting in each scenario). If it doesnt work then then there is maybe something else wrong, are you sure you reloaded the cache correctly? Did it print other erros in the errolog file?
I checked the logs and theres a huge list of the following:

Code: Select all

20200304 18:03:58 error preprocessor: Macro/file 'LIST' is missing
at ~add-ons/LA_MP_Pack/utils/inventory/equip_macros.cfg:2191
    included from ~add-ons/LA_MP_Pack/utils/paths.cfg:12
    included from ~add-ons/LA_MP_Pack/LA_RPG_Era.cfg:77
    included from ~add-ons/LA_MP_Pack/_main.cfg:15
    included from ~add-ons/LA_MP_Pack/LA_RPG_Era.cfg:78
    included from ~add-ons/LA_MP_Pack/_main.cfg:15
but it's referring to the core macros such as: {SOUND:HIT_AND_MISS {SOUND_LIST:SWORD_SWISH} {SOUND_LIST:MISS} -100}

and because I have a lot of units the error list goes on for the entire file. however the game runs without issues. it also has the error magenta_is_team_color error but that's just a deprication warning.

The error logs do show that [load_resource] isn't work properly. what would be causing that?
20200303 20:47:44 error engine: Couldn't find [resource] with id=la_always_active_event
You'd have to look I to your code to investigate what causes this. It the two most likely causes are

1) the resource didn't get loaded because an error during parsing (like the LIST macro error shown above)
2) you have put [resource] at the wrong location
Scenario with Robots SP scenario (1.11/1.12), allows you to build your units with components, PYR No preperation turn 1.12 mp-mod that allows you to select your units immideately after the game begins.
User avatar
Ravana
Forum Moderator
Posts: 2477
Joined: January 29th, 2012, 12:49 am
Location: Estonia
Contact:

Re: Using [resource] and [load_resource]

Post by Ravana »

When core macros are missing, most likely https://github.com/wesnoth/wesnoth/issues/1924 happened.

Code: Select all

ravana@ravana-think ~/wesnoth/wesnoth-lobby $ cat _main.cfg 
{LIST}
ravana@ravana-think ~/wesnoth/wesnoth-lobby $ wesnoth -p _main.cfg out
Battle for Wesnoth v1.14.5+dev (0122a265c42-Modified)
Started on Thu Mar  5 09:17:29 2020

Automatically found a possible data directory at /home/USER/wesnoth/wesnoth-lobby
added 1 defines.
preprocessing common macros from 'data/core' ...
acquired 1664 'data/core' defines.
preprocessing specified resource: _main.cfg ...
20200305 09:17:29 error preprocessor: Macro/file 'LIST' is missing
at _main.cfg:1
So LIST is not core macro.
User avatar
LordAwsomeness
Posts: 203
Joined: August 12th, 2013, 2:20 pm
Location: U.S.A.

Re: Using [resource] and [load_resource]

Post by LordAwsomeness »

Ravana wrote: March 5th, 2020, 7:18 am When core macros are missing, most likely https://github.com/wesnoth/wesnoth/issues/1924 happened.

Code: Select all

ravana@ravana-think ~/wesnoth/wesnoth-lobby $ cat _main.cfg 
{LIST}
ravana@ravana-think ~/wesnoth/wesnoth-lobby $ wesnoth -p _main.cfg out
Battle for Wesnoth v1.14.5+dev (0122a265c42-Modified)
Started on Thu Mar  5 09:17:29 2020

Automatically found a possible data directory at /home/USER/wesnoth/wesnoth-lobby
added 1 defines.
preprocessing common macros from 'data/core' ...
acquired 1664 'data/core' defines.
preprocessing specified resource: _main.cfg ...
20200305 09:17:29 error preprocessor: Macro/file 'LIST' is missing
at _main.cfg:1
So LIST is not core macro.
I purged the cache completely and the error still persists unless I restarted wesnoth altogether.
I also searched all of my text files in my entire add-on for the macro 'LIST' and the closest thing it came up with was '{SOUND_LIST:HUMAN_DIE}'. those were the only LIST-ish files I have in there. so LIST isn't actually the problem.
- Been playing Wesnoth since 2004 and the 1.0.x versions.
- Creator of Undead Invasion MP Scenario Pack.
- Creator of Valeria MP Adventure
- Creator of LA_RPG ERA
User avatar
LordAwsomeness
Posts: 203
Joined: August 12th, 2013, 2:20 pm
Location: U.S.A.

Re: Using [resource] and [load_resource]

Post by LordAwsomeness »

gfgtdf wrote: March 5th, 2020, 4:57 am You'd have to look I to your code to investigate what causes this. It the two most likely causes are

1) the resource didn't get loaded because an error during parsing (like the LIST macro error shown above)
2) you have put [resource] at the wrong location
Attached are the files below with the [load_resource] tags and the lines where I placed them. I greatly appreciate you looking deeper into it. if they are incorrect please let me know. I also had disabled them with # so they might still be a little off with those because I couldn't remember which ones were supposed to be enabled and which weren't. however I think they should be right from the information that you guys were giving me.
Attachments
LA_RPG_Era.cfg
Lines 80-256
(5.73 KiB) Downloaded 60 times
_main.cfg
Lines 23-26
(802 Bytes) Downloaded 63 times
test_scenario.cfg
Lines 27-29
(2.88 KiB) Downloaded 56 times
- Been playing Wesnoth since 2004 and the 1.0.x versions.
- Creator of Undead Invasion MP Scenario Pack.
- Creator of Valeria MP Adventure
- Creator of LA_RPG ERA
Post Reply