Service interface for cross-mod communication

Post a reply

Smilies
:D :) :( :o :shock: :? 8-) :lol: :x :P :oops: :cry: :evil: :twisted: :roll: :wink: :geek: :ugeek: :!: :?: :idea: :arrow: :| :mrgreen: :3: :wub: >:( :blergh:
View more smilies

BBCode is OFF
Smilies are ON

Topic review
   

Expand view Topic review: Service interface for cross-mod communication

Re: Service interface for cross-mod communication

by Caligari87 » Fri Jul 02, 2021 8:19 am

Oh whoops. I was catching up on old unread messages, just parsed the last couple comments, and thought it was still under debate :oops: My bad.

8-)

Re: Service interface for cross-mod communication

by Gez » Fri Jul 02, 2021 8:18 am

It has been implemented, as the [Added] tag in the thread title implies.

Re: Service interface for cross-mod communication

by Caligari87 » Fri Jul 02, 2021 8:09 am

I'll throw another use case on the stack since I rolled my own trying to solve a similar issue.

I have a "modular" mod pack, which I've designed so players can load the entire mod as one unified whole, or easily separate out just the parts they want. But of course this causes problems if one of these "sub-mods" depends on another one that isn't loaded.

For example, one of my modules gives the player a flashlight inventory item. Another module gives monsters some enhanced AI mechanics, including the ability to use the same flashlight item as the player. But if the AI mod is loaded and the flashlight isn't, errors occur.

So I wrote a system in the "core" submod (common routines used by all the mods) that allows the AI mod to send "intents" such as "toggle flashlight" to a global "bulletin board", and the flashlight to look for these intents and toggle accordingly.

Details spoilered since my implementation is irrelevant to the one discussed in this thread, but just for context.
Spoiler:
If this was implemented into GZDoom I could save some code and probably be more efficient. I think one main thing I like about mine is that it includes several fields like separating the intent name and payload string, sender/receiver pointers, timeouts, etc. Not sure how generically useful those might be or if they can be achieved with MC's system.

8-)

Re: Service interface for cross-mod communication

by Major Cooke » Sat May 22, 2021 9:22 am

That guess is actually 100% accurate. Here's an example.

m8f's TargetSpy modification has a service that searches for MaxHealth named services that allows overriding the display of a monster's maximum health. As his mod is doing the searching anything with MaxHealth, this is how its set up.

Code: Select all

static ui bool, int getMaxFromService(string className)
{
	ServiceIterator i = ServiceIterator.Find("MaxHealthService");

	Service s;
	if (s = i.Next())
	{
		String maxHealth = s.UiGet(className);
		if (maxHealth == "none")
		{
			return false, 0;
		}
		else
		{
			return true, maxHealth.ToInt();
		}
	}

	return false, 0;
}
Any mods that wish to make use of this just need to do something like this (note: there is a Get for Play and UIGet for UI scopes):

Code: Select all

class StubMaxHealthService : Service
{
	override String UiGet(String className)
	{
		if (className ~== "DoomImp")
		{
			return "1000";
		}
		else
		{
			return "none";
		}
	}
}
And that's it.

Re: Service interface for cross-mod communication

by Rachael » Sat May 22, 2021 8:16 am

I think the goal is to modularize addons. If there is a standard for addon-to-addon communication it makes it possible to establish a generic framework for them, or even any number of them, while making some parts of addons optional and reducing overall addon cross-dependency while increasing cross compatibility. That's just my guess, though.

Re: Service interface for cross-mod communication

by Graf Zahl » Sat May 22, 2021 8:11 am

I'm going to take your word for it. I still can't wrap my head around a potential use case.

Re: Service interface for cross-mod communication

by Major Cooke » Sat May 22, 2021 6:41 am

Alright, I gave this a thorough testing, and it seems to work as anticipated, which is very useful for cross mod messaging indeed. I hope Graf will consider merging this.

Re: Service interface for cross-mod communication

by Major Cooke » Tue Dec 15, 2020 11:34 am

I'll implement this into QZDoom soon. Sorry for not responding sooner. Just been busy with RL but things have finally settled down.

Re: Service interface for cross-mod communication

by m8f » Tue Nov 03, 2020 1:32 pm

I've changed the implementation so the service iterator accepts partial name matches too.
So, modA1 defines "HealthService_A1", modA2 defines "HealthService_A2", modB searches for "HealthService" and finds both.

I had to remove the convenience method ServiceIterator.ServiceExists(). Now the only way to know if there are no Services found is to count how many times Next() returns not NULL.

I updated the PR, and here is the standalone preview:
service-new.zip
(2.76 KiB) Downloaded 103 times
There are four directories in this archive, each is meant to be loaded separately, with service directory first.

Re: Service interface for cross-mod communication

by Major Cooke » Sun Nov 01, 2020 1:22 pm

Thank you for understanding. I look forward to what you might come up with next. This is a very powerful feature that could greatly ease plenty of stuff.

Re: Service interface for cross-mod communication

by m8f » Sun Nov 01, 2020 4:08 am

Major Cooke, you are right. I have to think about a way to service provider mods not to conflict. I'll use your idea with setting actual service name if I don't come up with something more convenient.

Re: Service interface for cross-mod communication

by Apeirogon » Sat Oct 31, 2020 5:11 pm

Eeeee.....looks like we have problems understanding each other.
Just wait for m8f, he should explain it better than me.

Re: Service interface for cross-mod communication

by Major Cooke » Sat Oct 31, 2020 5:05 pm

yes, but that's exactly the problem. If you want to make it inherit from type MaxHealthGetter defined in TargetSpy so it's taken into account, that means any mod that implements:

Code: Select all

Class D4MaxHealthGetter : MaxHealthGetter
...become reliant upon that mod being present at all times. Sure, could just inherit from Service directly, but specifying a name to search it by means it's basically going to skip over it, unless it's used for, say, 'private' service classes.That works fine for things such as libraries, sure, if that's what its intended use case is.

Re: Service interface for cross-mod communication

by Apeirogon » Sat Oct 31, 2020 5:01 pm

Inheritance from Service class I meant. It would be included in gzdoom.pack, so it would be there in any case.

Re: Service interface for cross-mod communication

by Major Cooke » Sat Oct 31, 2020 4:59 pm

Doing it by inheritance means that it relies upon the other mod being there, and that won't work at all.

Top