[MOD 0.15.29+] Creative Mode 0.3.12 - Infinite resources

Topics and discussion about specific mods
waduk
Filter Inserter
Filter Inserter
Posts: 372
Joined: Tue Feb 10, 2015 5:44 pm
Contact:

Re: [MOD 0.15.13+] Creative Mode 0.3.7 - Old mystery solved!

Post by waduk »

Nexela wrote:It is possibly from removing the entities from blueprints for entities that are no longer valid
You probably right, after i clean-up some blueprint, the message didn't pop-up.
But that's strange because AFAIK, i never use Creative Mode entities in any of my blueprint.
Probably blueprint that comes from other players.
User avatar
Mooncat
Smart Inserter
Smart Inserter
Posts: 1196
Joined: Wed May 18, 2016 4:55 pm
Contact:

Re: [MOD 0.15.13+] Creative Mode 0.3.7 - Old mystery solved!

Post by Mooncat »

Thanks Nexela! That's why it only happens in 0.15!
I wish the popup can be more informative about where the entities are used. :)
User avatar
tzwaan
Inserter
Inserter
Posts: 42
Joined: Thu Jul 07, 2016 12:12 am
Contact:

Re: [MOD 0.15.13+] Creative Mode 0.3.7 - Old mystery solved!

Post by tzwaan »

Hey, I was thinking it would be really nice to have a randomized matter source capable of generating a random input of different specified items. Currently I'm having to do something like this to get the same result: Image
User avatar
Mooncat
Smart Inserter
Smart Inserter
Posts: 1196
Joined: Wed May 18, 2016 4:55 pm
Contact:

Re: [MOD 0.15.13+] Creative Mode 0.3.7 - Old mystery solved!

Post by Mooncat »

tzwaan wrote:Hey, I was thinking it would be really nice to have a randomized matter source capable of generating a random input of different specified items. Currently I'm having to do something like this to get the same result: Image
Nice! But why do you need that? :)
User avatar
Mooncat
Smart Inserter
Smart Inserter
Posts: 1196
Joined: Wed May 18, 2016 4:55 pm
Contact:

Re: [MOD 0.15.13+] Creative Mode 0.3.7 - Old mystery solved!

Post by Mooncat »

The old beacon doesn't look bad in modern Factorio. :P
Old beacons
User avatar
Optera
Smart Inserter
Smart Inserter
Posts: 2920
Joined: Sat Jun 11, 2016 6:41 am
Contact:

Re: [MOD 0.15.13+] Creative Mode 0.3.7 - Old mystery solved!

Post by Optera »

As soon as CM is enabled it adds a constant UPS drain of 0.15 to 0.20.
2017-06-25-07-39-42-4022404.jpg
2017-06-25-07-39-42-4022404.jpg (592.51 KiB) Viewed 14088 times
You never seem to unregister from on_tick when it's not needed.
A better way is to globally store the entities requiring on_tick update and only register to on_tick when such an entity exists.

The naive approach is to add something like this to on tick

Code: Select all

if #global.creative_chests >= 1 then 
  script.on_event(defines.events.on_tick, events.on_tick)
else 
  script.on_event(defines.events.on_tick, nil)
end
The best performance can be achieved by adding subscription to on_built and unsubcribing in on_removed/destroyed.

Code: Select all

function on_created_entity(event)
  global.entities[#global.entities+1] = event.created_entity]
  if #global.entities == 1 then 
    script.on_event(defines.events.on_tick, events.on_tick)
  end
end

Code: Select all

function on_removed_entity(event)
  for i=#global.entities, -1, 1 do
    if global.entities[i].unit_number == event.entity.unit_number then
      table.remove(global.entities, i)
    end
  end
  if #global.entities == 0 then 
    script.on_event(defines.events.on_tick, nil)
  end
end
If you optimize even further you can also unsubscribe from any event except on_built after the last entity was removed.
I recently did this for LTN, Loader Redux and Inventory Sensor to improve their performance for my huge train base where on_train_changed_state fires almost every second.
While a single mod is not even noticeable, when several mods needlessly fire for events it quickly becomes noticeable micro stutter.
User avatar
Mooncat
Smart Inserter
Smart Inserter
Posts: 1196
Joined: Wed May 18, 2016 4:55 pm
Contact:

Re: [MOD 0.15.13+] Creative Mode 0.3.7 - Old mystery solved!

Post by Mooncat »

Thanks for pointing that out. CM was my first mod, and it was even my first project to write in Lua, so it started quite dirty. :P
I have a plan to rewrite the whole thing so I can make it cleaner. But I can't tell when it can be started and finished.

For now, I'm afraid there are not much I can do. Not only entities use on_tick, but some cheats also use it (auto-trash, auto-request, instant blueprint/deconstruct...). Whenever a player turns on any of those cheats, on_tick is used. So in the end, on_tick is really necessary for about 99% of the time when CM is enabled.
And for the other events, don't forget the event log system. It will be messy if I add checking all over the place.

On the other hand, I can narrow down the issue and put a hot-fix there. I have done that before (commenting out parts of events.on_tick() and found the main cause), but I forgot why I reverted it. :shock:
User avatar
Optera
Smart Inserter
Smart Inserter
Posts: 2920
Joined: Sat Jun 11, 2016 6:41 am
Contact:

Re: [MOD 0.15.13+] Creative Mode 0.3.7 - Old mystery solved!

Post by Optera »

Mooncat wrote:Thanks for pointing that out. CM was my first mod, and it was even my first project to write in Lua, so it started quite dirty. :P
I have a plan to rewrite the whole thing so I can make it cleaner. But I can't tell when it can be started and finished.
You started with something a lot bigger and more complex than me. ;)
Here's hoping you will get through refactoring without much headache. Let me know if I can help you.
For now, I'm afraid there are not much I can do. Not only entities use on_tick, but some cheats also use it (auto-trash, auto-request, instant blueprint/deconstruct...). Whenever a player turns on any of those cheats, on_tick is used. So in the end, on_tick is really necessary for about 99% of the time when CM is enabled.
And for the other events, don't forget the event log system. It will be messy if I add checking all over the place.
In that case perhaps a global counter for on_tick subscribers could work.
For every cheat enabled or entity built requiring on_tick updates increase by 1 for every cheat disabled or entity removed decrease.
The checks only need to be at 3 spots. Where settings change, when entities are built and when entities are removed.
Kormer
Inserter
Inserter
Posts: 30
Joined: Wed Nov 30, 2016 1:34 am
Contact:

Re: [MOD 0.15.13+] Creative Mode 0.3.7 - Old mystery solved!

Post by Kormer »

I'm getting an error when trying to load a save game. The save itself is 360MB, so I'm not sure I can upload it to the forums. Have you seen this error? Anything else that would help you track it down?

"Attempt to remote call outside of an event. Stack Traceback: __creative-mode__/control.lua:73:in main chunk"

Edit: Just realized there was an auto-patch and this is almost certainly the cause:

"Fixed that mods could do remote calls outside of events when the game isn't in a valid state. more"
User avatar
Mooncat
Smart Inserter
Smart Inserter
Posts: 1196
Joined: Wed May 18, 2016 4:55 pm
Contact:

Re: [MOD 0.15.13+] Creative Mode 0.3.7 - Old mystery solved!

Post by Mooncat »

Kormer wrote:I'm getting an error when trying to load a save game. The save itself is 360MB, so I'm not sure I can upload it to the forums. Have you seen this error? Anything else that would help you track it down?

"Attempt to remote call outside of an event. Stack Traceback: __creative-mode__/control.lua:73:in main chunk"

Edit: Just realized there was an auto-patch and this is almost certainly the cause:

"Fixed that mods could do remote calls outside of events when the game isn't in a valid state. more"
Thanks for the report. I will fix it ASAP.
User avatar
Mooncat
Smart Inserter
Smart Inserter
Posts: 1196
Joined: Wed May 18, 2016 4:55 pm
Contact:

Re: [MOD 0.15.13+] Creative Mode 0.3.7 - Old mystery solved!

Post by Mooncat »

I have to take a sleep first. Before I can upload a new version, here is a quick fix:

Code: Select all

require("defines")
require("util")

require("scripts.autofill-requester-chest")
require("scripts.cheats")
require("scripts.configurable-super-boiler")
require("scripts.creative-cargo-wagon")
require("scripts.creative-chest")
require("scripts.creative-chest-util")
require("scripts.creative-lab")
require("scripts.creative-provider-chest")
require("scripts.duplicating-cargo-wagon")
require("scripts.duplicating-chest")
require("scripts.duplicating-chest-util")
require("scripts.duplicating-provider-chest")
require("scripts.duplicator")
require("scripts.energy-source")
require("scripts.energy-void")
require("scripts.equipments")
require("scripts.events")
require("scripts.fluid-providers-util")
require("scripts.fluid-source")
require("scripts.fluid-void")
require("scripts.global-util")
require("scripts.gui")
require("scripts.gui-entity")
require("scripts.gui-menu-admin")
require("scripts.gui-menu-cheats")
require("scripts.gui-menu-magicwand")
require("scripts.gui-menu-modding")
require("scripts.gui-menu") -- It has to be loaded after the submenus.
require("scripts.item-providers-util")
require("scripts.item-source")
require("scripts.item-void")
require("scripts.magic-wand-creator")
require("scripts.magic-wand-healer")
require("scripts.magic-wand-modifier")
require("scripts.mod-compatibler")
require("scripts.passive-energy-source")
require("scripts.passive-energy-void")
require("scripts.remote-interface")
require("scripts.rights")
require("scripts.super-beacon")
require("scripts.super-boiler")
require("scripts.super-cooler")
require("scripts.super-radar")
require("scripts.super-roboport")
require("scripts.util")
require("scripts.void-cargo-wagon")
require("scripts.void-chest-util")
require("scripts.void-requester-chest")
require("scripts.void-storage-chest")

-- Registers callback for each events.
script.on_init(events.on_init)
script.on_load(events.on_load)
script.on_configuration_changed(events.on_configuration_changed)

-- The on_tick event is called very frequently, it is better to NOT do a name check in the generic event handler.
script.on_event(defines.events.on_tick, events.on_tick)
-- Other events.
local events_except_on_tick = {}
for _, event in pairs(defines.events) do
	if event ~= defines.events.on_tick then
		table.insert(events_except_on_tick, event)
	end
end
script.on_event(events_except_on_tick, events.on_event)

-- Create interface for lua command.
remote.add_interface(creative_mode_defines.names.interface,		remote_interface.remote_functions)
-- Exclude the alien attractors from keep last item.
--[[
remote.call("creative-mode", "exclude_from_keep_last_item", creative_mode_defines.names.items.alien_attractor_small)
remote.call("creative-mode", "exclude_from_keep_last_item", creative_mode_defines.names.items.alien_attractor_medium)
remote.call("creative-mode", "exclude_from_keep_last_item", creative_mode_defines.names.items.alien_attractor_large)
-- Also run the examples, after our interface is ready for that.
-- Example: register the remote function register_by_remote_function_example_1 to the modding UI.
remote.call("creative-mode", "register_remote_function_to_modding_ui",
	"creative-mode", --  Interface name
	"register_by_remote_function_example_1" -- Function name
)
--]]

--[[
-- Demo for subscribing and using the custom events.
script.on_event(remote.call("creative-mode", "on_enabled"), function(event)
	game.print("Test: Creative Mode enabled!")
end)
script.on_event(remote.call("creative-mode", "on_disabled"), function(event)
	game.print("Test: Creative Mode disabled!")
end)
--]]

--[[
-- Demo for excluding an item from the keep-last-item personal cheat.
remote.call("creative-mode", "exclude_from_keep_last_item", "assembling-machine-2")
--]]

--[[
-- Demo for excluding an entity from the instant-blueprint personal cheat.
remote.call("creative-mode", "exclude_from_instant_blueprint", "assembling-machine-3")
--]]

--[[
-- Demo for excluding an entity from the instant-deconstruction personal cheat.
remote.call("creative-mode", "exclude_from_instant_deconstruction", "oil-refinery")
--]]
Use this to replace control.lua.
There are some side effects but you probably won't notice. ;)
User avatar
mickael9
Fast Inserter
Fast Inserter
Posts: 112
Joined: Mon Mar 14, 2016 4:04 am
Contact:

Re: [MOD 0.15.13+] Creative Mode 0.3.7 - Old mystery solved!

Post by mickael9 »

Here's a zip with the change
Attachments
creative-mode_0.3.7.zip
(2.31 MiB) Downloaded 726 times
User avatar
Optera
Smart Inserter
Smart Inserter
Posts: 2920
Joined: Sat Jun 11, 2016 6:41 am
Contact:

Re: [MOD 0.15.13+] Creative Mode 0.3.7 - Old mystery solved!

Post by Optera »

0.15.27 broke CM ... again.

Code: Select all

Error AppManagerStates.cpp:1142: Attempt to remote call outside of an event.
stack traceback:
	__creative-mode__/control.lua:73: in main chunk
FactorioBot wrote: Fixed that mods could do remote calls outside of events when the game isn't in a valid state. (50509)
Looks like you have to move registering remote calls into on_load, on_init and on_configuration_changed.

PS:
How do you check if creative mode is loaded with the correct version to set up "exclude_from_instant_blueprint" remote calls in on_load when game.active_mods doesn't exist?
hi_impact
Inserter
Inserter
Posts: 28
Joined: Wed Jun 01, 2016 5:29 pm
Contact:

Re: [MOD 0.15.13+] Creative Mode 0.3.7 - Old mystery solved!

Post by hi_impact »

Looks like it's acting up again.

Attempt to remote call outside of an event.

__creative-mode__/control.lua:73: in main chunk

I just updated to 15.27
Nexela
Smart Inserter
Smart Inserter
Posts: 1828
Joined: Wed May 25, 2016 11:09 am
Contact:

Re: [MOD 0.15.13+] Creative Mode 0.3.7 - Old mystery solved!

Post by Nexela »

Optera wrote: PS:
How do you check if creative mode is loaded with the correct version to set up "exclude_from_instant_blueprint" remote calls in on_load when game.active_mods doesn't exist?
You would use on_init and on_configuration_changed since the data is stored in creative modes global

Code: Select all

If remote.interfaces["creative-mode"] and remote.interfaces["creative_mode"].exclude_from_instant_blueprint then remote.call(....) end
User avatar
tzwaan
Inserter
Inserter
Posts: 42
Joined: Thu Jul 07, 2016 12:12 am
Contact:

Re: [MOD 0.15.13+] Creative Mode 0.3.7 - Old mystery solved!

Post by tzwaan »

Mooncat wrote:
tzwaan wrote:Hey, I was thinking it would be really nice to have a randomized matter source capable of generating a random input of different specified items. Currently I'm having to do something like this to get the same result: Image
Nice! But why do you need that? :)
I needed this when I was building the black magic splitter sorters. Basically to simulate arbitrary inputs.
User avatar
Mooncat
Smart Inserter
Smart Inserter
Posts: 1196
Joined: Wed May 18, 2016 4:55 pm
Contact:

Re: [MOD 0.15.13+] Creative Mode 0.3.7 - Old mystery solved!

Post by Mooncat »

Optera wrote:0.15.27 broke CM ... again.

Code: Select all

Error AppManagerStates.cpp:1142: Attempt to remote call outside of an event.
stack traceback:
	__creative-mode__/control.lua:73: in main chunk
FactorioBot wrote: Fixed that mods could do remote calls outside of events when the game isn't in a valid state. (50509)
Looks like you have to move registering remote calls into on_load, on_init and on_configuration_changed.

PS:
How do you check if creative mode is loaded with the correct version to set up "exclude_from_instant_blueprint" remote calls in on_load when game.active_mods doesn't exist?
hi_impact wrote:Looks like it's acting up again.

Attempt to remote call outside of an event.

__creative-mode__/control.lua:73: in main chunk

I just updated to 15.27
Please use mickael9's fix first: viewtopic.php?f=97&t=28005&start=520#p294085
I'm working on the color picker mods now.
tzwaan wrote:
Mooncat wrote:
tzwaan wrote:Hey, I was thinking it would be really nice to have a randomized matter source capable of generating a random input of different specified items. Currently I'm having to do something like this to get the same result: Image
Nice! But why do you need that? :)
I needed this when I was building the black magic splitter sorters. Basically to simulate arbitrary inputs.
Added to the todo list, but I can't promise when it will be implemented.
For now, I think it may have performance issue because it will require the random number generator work twice in every tick. Need some tests first.
ichVII
Fast Inserter
Fast Inserter
Posts: 104
Joined: Mon Feb 27, 2017 10:16 pm
Contact:

Re: [MOD 0.15.13+] Creative Mode 0.3.7 - Old mystery solved!

Post by ichVII »

I get a crash on load using your mod and a few others. The message displayed is:
Attempt to remote call outside of an event.
stack traceback:
__creative-mode__/control.lua:73: in main chunk

Looks like it is caused by creative mod on first view.
Attachments
limited.zip
save
(17.37 MiB) Downloaded 172 times
User avatar
Odhrean
Long Handed Inserter
Long Handed Inserter
Posts: 76
Joined: Mon Sep 15, 2014 7:49 am
Contact:

Re: [MOD 0.15.13+] Creative Mode 0.3.7 - Old mystery solved!

Post by Odhrean »

ichVII wrote:I get a crash on load using your mod and a few others. The message displayed is:
Attempt to remote call outside of an event.
stack traceback:
__creative-mode__/control.lua:73: in main chunk

Looks like it is caused by creative mod on first view.
Same error here.
I commented all "remote.call" in control.lua out and can run it now.
dgw
Fast Inserter
Fast Inserter
Posts: 197
Joined: Tue Apr 12, 2016 7:06 pm
Contact:

Re: [MOD 0.15.13+] Creative Mode 0.3.7 - Old mystery solved!

Post by dgw »

@ everyone posting about the crash with Factorio 0.15.27: It's known. Mooncat said it'll be fixed soon. Meanwhile, there's a fixed ZIP using hotfix code Mooncat posted HERE. Or manually replace creative-mode's control.lua if you'd rather go that route.

Sincerely, a thread subscriber who's seen all of this multiple times today.
Post Reply

Return to “Mods”