~ywang

~ywang/misc

Last active 3 years ago
View more

Recent activity

Re: Thoughts on running Advanced Trains in async environment 2 months ago

From Y. Wang to ~gpcf/advtrains-discuss

> Run all logic (i.e. path calculation, interlocking, train movement, 
> train collision) in the async environment, and every time it returns to 
> the main thread, sync the calculated results with the world (i.e. 
> spawn/move train entities, sync passive component states), perform 
> sync-only actions (e.g. detect/damage collided entities, halt trains 
> colliding with walls), and sync data back into async (i.e. apply node DB 
> changes).

Minetest currently does not support multithreading, and the async env 
should not be used for multithreading according to this comment on Github:
https://github.com/minetest/minetest/pull/14659#issuecomment-2136019562

> Honestly, the whole running the train simulation in a separate thread
> kind of calls for running the stuff in a separate process written in a

Re: [PATCH v5] De-hardcode the speed limit of 20 m/s 2 months ago

From Y. Wang to ~gpcf/advtrains-devel

(Code review only. I have not tested this myself, but I assume it works 
given that you seem to have this patch applied on your server.)

> diff --git a/advtrains/trainhud.lua b/advtrains/trainhud.lua
> index f9f4876..731ad6d 100644
> --- a/advtrains/trainhud.lua
> +++ b/advtrains/trainhud.lua

The HUD definitely needs another rework even at its current state 
(without dehardcoding the speed limit). I am not sure whether it should 
be done now or after this patch.

> diff --git a/advtrains_signals_ks/init.lua b/advtrains_signals_ks/init.lua
> index 258b868..d614069 100755

Re: [PATCH v10] Wagon iterator, lookup by id, and use them in code 2 months ago

From Y. Wang to ~gpcf/advtrains-devel

v10 looks good. Thanks for taking the time.

Re: [PATCH v1] Allow getstate() on Ks main and shunting signal 2 months ago

From Y. Wang to ~gpcf/advtrains-devel

> Adds advtrains.getstate() function to Ks main and shunting signals. Returned values are tables containing full aspect.
Usecase? LuaATC provides get_aspect(pos) that allows you to get the 
aspect of a signal.

Re: [PATCH v9] Wagon iterator, lookup by id, and use them in code 2 months ago

From Y. Wang to ~gpcf/advtrains-devel

Tested. Looks good apart from a minor issue:

> +function advtrains.next_wagon_entity_in_train(train, i)
> +	local wagon_id = train.trainparts[i + 1]
> +	if wagon_id then
> +		local wagon = advtrains.get_wagon_entity(wagon_id)
> +		if wagon then
> +			return idx, wagon
return i+1, wagon ? (idx is nil here since it is not defined)

[PATCH] Implement staticdata for trains 3 months ago

From Y. Wang to ~gpcf/advtrains-devel

This patch exposes train.staticdata that can be used by other modders to
save data in trains across restarts. It additionally exposes two new
APIs for modders where this is relevant:

* advtrains.te_register_on_couple(function(init_train, stat_train)):
  registers a callback for train coupling, where stat_train is couple
  into init_train and is subsequently removed. This callback is run
  before the actual coupling takes place; in particular, it is run
  before stat_train is removed.
* advtrains.te_register_on_decouple(function(train, newtrain, index)):
  registers a callback for train decoupling, where newtrain is created
  by splitting the train at the given index (the wagon at the index is
  part of the new train). This callback is run after decoupling takes
  place.
[message trimmed]

[PATCH v2] Address wagon aliasing issues 3 months ago

From Y. Wang to ~gpcf/advtrains-devel

As it turns out, not fully testing new features is not necessarily a
good idea ...

This patch follows up 1F616EMO's patch by
* Making get_wagon_prototype return the resolved alias,
* Handling recursive wagon alises (in particular, loops), and
* Adding (partial) unittest for the wagon aliasing system. [v2]: The
testcases are complemented a bit more to cover situations where the
alias resolution system should return nil.

[v2]: This patch should hopefully also warn about not spawning wagons.
Note that this only warns about the missing wagon entity and does _not_
actually fix the issue.
[message trimmed]

Re: [PATCH v8] Wagon iterator, lookup by id, and use them in code 4 months ago

From Y. Wang to ~gpcf/advtrains-devel

> +function advtrains.next_wagon_entity_in_train(train, i)
> +	local wagon_id = train.trainparts[i + 1]
> +	if wagon_id then
> +		local wagon = advtrains.get_wagon_entity(wagon_id)
> +		return wagon and i + 1 or nil, wagon

I don't think this is correct: if you reach wagon == nil you effectively 
end the iteration here even if wagons further down in train.trainparts 
do have luaentities.

I think we probably want something like this:

for idx = i+1, #train.trainparts do
   local wagon = advtrains.get_wagon_entity(train.trainparts[idx])

[PATCH] Address wagon aliasing issues 4 months ago

From Y. Wang to ~gpcf/advtrains-devel

As it turns out, not fully testing new features is not necessarily a
good idea ...

This patch follows up 1F616EMO's patch by
* Making get_wagon_prototype return the resolved alias,
* Handling recursive wagon alises (in particular, loops), and
* Adding (partial) unittest for the wagon aliasing system

How to test:
* In a world with both advtrains_train_subway and advtrains_train_japan
  enabled, place a subway wagon, a Japanese engine, and a regular
  Japanese wagon.
* Add the test mod to the world; do NOT remove advtrains_train_japan.
* Restart the world. Notice that the Japanese wagons still appear as
[message trimmed]

Re: [PATCH v6] Wagon iterator, lookup by id, and use them in code 4 months ago

From Y. Wang to ~gpcf/advtrains-devel

Looks good beside some minor things.

> +function advtrains.next_wagon_entity_in_train(train, i)
> +	local wagon_id = train[i + 1]

Shouldn't this be train.trainparts?

> +	if wagon_id then
> +		return i + 1, advtrains.get_wagon_entity(wagon_id)

It would IMO be better to have a nil check here since other places use 
the entity directly without nil checks.