[Added] Service interface for cross-mod communication

Moderator: GZDoom Developers

Re: Service interface for cross-mod communication

Postby 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

There are four directories in this archive, each is meant to be loaded separately, with service directory first.
You do not have the required permissions to view the files attached to this post.
User avatar
m8f
dreamer
 
 
 
Joined: 29 Dec 2017
Location: Siberia (UTC+7)
Discord: m8f#0629
Github ID: mmaulwurff
Operating System: Debian-like Linux (Debian, Ubuntu, Mint, etc) 64-bit

Re: Service interface for cross-mod communication

Postby 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.
User avatar
Major Cooke
QZDoom Maintenance Team
 
Joined: 28 Jan 2007

Re: Service interface for cross-mod communication

Postby 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.
User avatar
Major Cooke
QZDoom Maintenance Team
 
Joined: 28 Jan 2007

Re: Service interface for cross-mod communication

Postby 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.
User avatar
Graf Zahl
Lead GZDoom+Raze Developer
Lead GZDoom+Raze Developer
 
Joined: 19 Jul 2003
Location: Germany

Re: Service interface for cross-mod communication

Postby 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.
User avatar
Rachael
Admin
 
Joined: 13 Jan 2004
Discord: Rachael#3767
Twitch ID: madamerachelle
Github ID: madame-rachelle
Operating System: Windows 10/8.1/8/201x 64-bit
OS Test Version: No (Using Stable Public Version)
Graphics Processor: nVidia with Vulkan support

Re: Service interface for cross-mod communication

Postby 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 allExpand view
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 allExpand view
class StubMaxHealthService : Service
{
   override String UiGet(String className)
   {
      if (className ~== "DoomImp")
      {
         return "1000";
      }
      else
      {
         return "none";
      }
   }
}


And that's it.
User avatar
Major Cooke
QZDoom Maintenance Team
 
Joined: 28 Jan 2007

Previous

Return to Closed Feature Suggestions

Who is online

Users browsing this forum: No registered users and 0 guests