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:
There are four directories in this archive, each is meant to be loaded separately, with service directory first.
Service interface for cross-mod communication
Moderator: GZDoom Developers
-
-
- Posts: 1446
- Joined: Fri Dec 29, 2017 4:15 am
- Preferred Pronouns: He/Him
- Operating System Version (Optional): Manjaro Linux
- Location: Siberia (UTC+7)
Re: Service interface for cross-mod communication
You do not have the required permissions to view the files attached to this post.
-
- Posts: 8192
- Joined: Sun Jan 28, 2007 3:55 pm
- Preferred Pronouns: He/Him
- Location: QZDoom Maintenance Team
Re: Service interface for cross-mod communication
I'll implement this into QZDoom soon. Sorry for not responding sooner. Just been busy with RL but things have finally settled down.
-
- Posts: 8192
- Joined: Sun Jan 28, 2007 3:55 pm
- Preferred Pronouns: He/Him
- Location: QZDoom Maintenance Team
Re: Service interface for cross-mod communication
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.
-
- Lead GZDoom+Raze Developer
- Posts: 49118
- Joined: Sat Jul 19, 2003 10:19 am
- Location: Germany
Re: Service interface for cross-mod communication
I'm going to take your word for it. I still can't wrap my head around a potential use case.
-
- Posts: 13699
- Joined: Tue Jan 13, 2004 1:31 pm
- Preferred Pronouns: She/Her
Re: Service interface for cross-mod communication
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.
-
- Posts: 8192
- Joined: Sun Jan 28, 2007 3:55 pm
- Preferred Pronouns: He/Him
- Location: QZDoom Maintenance Team
Re: Service interface for cross-mod communication
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.
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):
And that's it.
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;
}
Code: Select all
class StubMaxHealthService : Service
{
override String UiGet(String className)
{
if (className ~== "DoomImp")
{
return "1000";
}
else
{
return "none";
}
}
}
-
- Admin
- Posts: 6190
- Joined: Thu Feb 26, 2004 3:02 pm
- Preferred Pronouns: He/Him
Re: Service interface for cross-mod communication
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.
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.
-
-
- Posts: 17905
- Joined: Fri Jul 06, 2007 3:22 pm
Re: Service interface for cross-mod communication
It has been implemented, as the [Added] tag in the thread title implies.
-
- Admin
- Posts: 6190
- Joined: Thu Feb 26, 2004 3:02 pm
- Preferred Pronouns: He/Him
Re: Service interface for cross-mod communication
Oh whoops. I was catching up on old unread messages, just parsed the last couple comments, and thought it was still under debate My bad.