HeroEngine Forums
Welcome, Guest. Please login or Register for HeroCloud Account.

Author Topic: [Resolved] System areas and areas in general  (Read 2607 times)

gregoberfield

  • World Owners
  • ****
  • Posts: 10
    • View Profile
[Resolved] System areas and areas in general
« on: Jul 09, 10, 10:21:35 AM »

So I've been working on system areas as part of the pre-work to storing game-specific data for future analytics and I have a couple of questions.

in E_WorldClassMethods I've added my system area to the KeepUpList function (easy enough) but that function is only called when the world boots, correct?  So the fact that I have:

Code: [Select]
KeepAreaUp( 9223372056366123504, 2 )   // Server Communication area
Won't be called right now - can I call that via an admin command and it'll still work?  Also - I set my instance number to 2 - is that going to be a problem or is the recommendation to come up a high number range to use instead for system areas?

In E_AreaClassMethods I added:

Code: [Select]
  if GetAreaNumber() == 9223372056366123504
    $WORLD._RegisterSystemArea(PLAYER)
    Debug("AreaSpinUp", "Server communication system area registered.")
  .

to the HE_PostOnAreaLoad but I'm never getting my debug message.  The area number listed is the area ID of the system area I created.  I figured that would execute but it doesn't seem to be.

Also - about areas -- I see that E_AreaClassMethods is attached to $AREA to override methods -- is there a way to have area specific scripts attached?  Or do we have to do it all in off of $AREA and then have logic to check the area ID to run area-specific functions?

Specifically I'm trying to write code for my new system area - but there's no reason for that code to be attached to $AREA since its only going to be needed by the one area.  Can I MPAC code to the area ID?
« Last Edit: Nov 03, 12, 08:45:30 PM by HE-Cooper »
Logged

HE-CHRISTOPHER

  • HeroEngine
  • *****
  • Posts: 424
    • View Profile
Re: System areas and areas in general
« Reply #1 on: Jul 09, 10, 12:11:04 PM »

in E_WorldClassMethods I've added my system area to the KeepUpList function (easy enough) but that function is only called when the world boots, correct?

Correct.


Can I call that via an admin command and it'll still work?

Yes.

I set my instance number to 2 - is that going to be a problem or is the recommendation to come up a high number range to use instead for system areas?

I generally recommend starting at 1 and go up for instances, that makes is much more predictable from code when working with system areas that utilize N play instances to balance load.

In E_AreaClassMethods I added:

Code: [Select]
  if GetAreaNumber() == 9223372056366123504
    $WORLD._RegisterSystemArea(PLAYER)
    Debug("AreaSpinUp", "Server communication system area registered.")
  .

to the HE_PostOnAreaLoad but I'm never getting my debug message.  The area number listed is the area ID of the system area I created.  I figured that would execute but it doesn't seem to be.

Did you subscribe to that channel of messaging?  I got the message as expected.

https://wiki.heroengine.com/wiki/Debug_System#Debug_System

Also - about areas -- I see that E_AreaClassMethods is attached to $AREA to override methods -- is there a way to have area specific scripts attached?  Or do we have to do it all in off of $AREA and then have logic to check the area ID to run area-specific functions?

Specifically I'm trying to write code for my new system area - but there's no reason for that code to be attached to $AREA since its only going to be needed by the one area.  Can I MPAC code to the area ID?

There are a couple of options:
  • GLOM a class onto the Area Root Node (GetRootNode())
  • Area roots have a field named "script" that stores a reference to a script in which you could call functions

Either way, you would need to modify E_AreaClassMethods to perform a call to either the script (if one is specified) or to a method on the area root node should it be implemented.

Code: [Select]
  // object oriented method using dynamic composition (GLOMming)
  area_root_node as NodeRef of Class AreaRoot = GetRootNode()
  if HasMethod( area_root_node, "E_OnAreaSpinUp" )
    area_root_node.E_OnAreaSpinUp()
  .

Code: [Select]
  // functional method using a reference to a script
  area_root_node as NodeRef of Class AreaRoot = GetRootNode()
  if area_root_node.script != NONE
    area_root_node.script:MyFunctionAreaSpinUp()
  .
Logged
Christopher Larsen
CTO
HeroEngine

gregoberfield

  • World Owners
  • ****
  • Posts: 10
    • View Profile
Re: System areas and areas in general
« Reply #2 on: Jul 09, 10, 03:48:00 PM »

Ok - so once an area is registered with the world server it will receive events.  What I'm trying to figure out (and digging through the HJ stuff now) is where/how to have the listeners tied to that area.

For example, I have an area "Server Communication" - do I just build a script ServerCommunicationClassMethods to handle the listener?  Do I put it into E_AreaClassMethods (or some other script I attach to the $AREA node)?

Basically, can you point me to the script file for, say the ChatSystem system area in HJ, or ShopSystem, or Auctions or something and I can probably back into the answers of all my other questions.

Thanks.
G
Logged

gregoberfield

  • World Owners
  • ****
  • Posts: 10
    • View Profile
Re: System areas and areas in general
« Reply #3 on: Jul 14, 10, 06:55:01 AM »

Still hoping for some direction on where to look in HJ for the system area code.  The areas are working now, and registering properly, but where do you GLOM the script code?  And how do you associate that code so it's attached to your system area?

Just point at a couple of examples in HJ and we can probably figure it out.
Logged

HE-CHRISTOPHER

  • HeroEngine
  • *****
  • Posts: 424
    • View Profile
Re: System areas and areas in general
« Reply #4 on: Jul 14, 10, 04:25:28 PM »

Still hoping for some direction on where to look in HJ for the system area code.  The areas are working now, and registering properly, but where do you GLOM the script code?  And how do you associate that code so it's attached to your system area?

Just point at a couple of examples in HJ and we can probably figure it out.

For Hero's Journey, they opted to handle the registration of the areas in the $AREA game specific override class HJAreaClassMethods during the HE_PostOnAreaLoad() call.  This has some advantages in centralizing the functionality in a well known location.

For your purposes, the equivalent would be implementing the code in E_AreaClassMethods (this is ok because this class and script are in the "game" package so you are free to make any modifications you desire).

I could argue either way that placing the functionality in the override for the $AREA system node vs GLOMming a class onto the area root node (GetRootNode()) and then modifying E_AreaClassMethods to call a shared function on the area root node during the area spinup process (HE_PostOnAreaLoad() would be an acceptable point).

If we want to GLOM a class on the area root node, why use a shared function?

I'm sure you are familiar with the classic diamond pattern in inheritance, HeroScript's solution is to the problem of ambiguous method calls is to simply not allow them.  Calling a method on the area root node it may not be ambiguous, however it would be really convenient if we could notify N GLOMmed classes on the area root node that the area has just spun up allowing each to do its thing.

Shared functions may be implemented in any number of classes that make up an object, because functions are explicitly called by <script>:<function> there is never any ambiguity allow us to notify every class that makes up an object that the area has just spun up.

Code: [Select]
// in E_AreaClassMethods HE_PostOnAreaLoad()

// notify all of the classes making up the area root node that the area has just spun up
area_root_node as noderef of class AreaRoot = GetRootNode()
foreach s in QueryNodeScriptsWithFunction( area_root_node, "_AreaIsSpunUp" )
  s:_AreaIsSpunUp()
.


Code: [Select]
// in MyAreaRootNodeGLOMClassMethods
shared function _AreaIsSpunUp()
  // register me as a system area
  //   subscribe listeners
  // ETC
.
Logged
Christopher Larsen
CTO
HeroEngine

sebako

  • General Accounts
  • *
  • Posts: 6
    • View Profile
Re: System areas and areas in general
« Reply #5 on: Oct 16, 10, 08:50:23 PM »

how will the system recognize that this single area is capable of managing "groups" for example and not any other area? do i have to check in every method in the GroupClassMethods that the area is getAreaNumber() == xxxxxx ?
or how does the system know which area will manage groups?

basically what i wanna know is, i have a script FO_PlayerGroupClassMethods
and i wanna know how do i make this code working inside it:

Code: [Select]

if(inviteeAccount == 0)
  // check world server
  inviteeAccount = $WORLD._FindPlayerByName(inviteeUpper)
.


so right now i have added this code to the HE_PostOnAreaLoad in E_AreaClassMethods, is this the wrong way?
just trying to understand how it is working.

Code: [Select]

if(GetAreaNumber() == 9223372057803796481)
  $WORLD._RegisterSystemArea( "PLAYER" )
  $WORLD._RegisterSystemArea( "AREA" )
  area.Script = FO_PlayerGroupClassMethods
  Debug( "AreaSpinUp", "FO_Groups System Area registered and SpinUp.")
.


can anybody help me out here?

Cheers
« Last Edit: Oct 16, 10, 10:50:28 PM by sebako »
Logged

JoshHalls

  • Founding Professional
  • *****
  • Posts: 335
    • View Profile
    • The Repopulation
Re: System areas and areas in general
« Reply #6 on: Oct 18, 10, 01:47:51 PM »

You typically send the requests to the zone itself so there is no real way to say this is a zone for this function as the server will typically send the request to the system area that is acting as a certain function (group, auction, quest, etc) via a manual process of calling that zone and then parsing the return values if there are some or if there is a need.

That is at least what I have gleamed so far, still have a bit to learn though.
Logged
Co-Owner/Programmer - The Repopulation

HE-CHRISTOPHER

  • HeroEngine
  • *****
  • Posts: 424
    • View Profile
Re: System areas and areas in general
« Reply #7 on: Oct 26, 10, 09:15:50 AM »


Regarding forwarding calls to a system area...

Typically when I write a system node that exposes an interface to a system area I tend to structure my code like this so that it automatically forwards calls.

Code: [Select]
method GetGroupSystemAreaID() as id
  group_system_area_id as id = 1234567890
  return group_system_area_id
.

remote method AddMemberToGroup( member_id as id )
  group_system_area_id as id = me.GetGroupSystemAreaID()
  if GetAreaNumber() != group_system_area_id
     // for the sake of simplicity, I'm assuming the use of the edit instance
     //    to handle processing.
     call area me.GetGroupSystemAreaID() instance 0 $GROUPS.AddMemberToGroup( member_id )
     return
  .

  // if you get this far, you are in the group system area
 
  // TODO:  do stuff to add a member to a group
.


One of the nice things about structuring the code like this is that it keeps the interfaces cleaner making it easier to follow what is going on.

Logged
Christopher Larsen
CTO
HeroEngine