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

Author Topic: How is E_playerCharacter first instantiated  (Read 2738 times)

grimcat

  • World Owner
  • ****
  • Posts: 20
    • View Profile
How is E_playerCharacter first instantiated
« on: Feb 05, 13, 10:41:19 PM »

Perhaps this is my java/C# brain trying to force an incorrect paradigm onto HSL, but I've become a bit obsessed this evening trying to figure out how the clean engine implementation knows that a player character is an E_playerCharacter.

I know that the character classes are related through inheritance, but I assumed that at some point in the character creation and selection system, the player character was instantiated as a noderef of class E_playerCharater, and I'm just not finding it when searching the code. Perhaps my eyes have sped past the line of code a dozen times tonight without me seeing it, or just as likely, maybe I'm not understanding a core concept.

I very much enjoy exploring on my own, so a gentle push down the right flight of stairs is all I ask.

- Sage
Logged

grimcat

  • World Owner
  • ****
  • Posts: 20
    • View Profile
Re: How is E_playerCharacter first instantiated
« Reply #1 on: Feb 05, 13, 11:25:24 PM »

I feel that I'm stumbling closer with this call found in E_CharacterSelectionSystem.HE_CSSUseCharacterPrototype, but my brain hasn't quite made the connection.

Code: [Select]
method HE_CSSUseCharacterPrototype( args as LookupList indexed by String of String, proto references NodeRef ) as Boolean
// Used by $CHARACTERSELECTIONSYSTEM
//
// return a reference to the prototype from which you want character nodes to be created, args lookup
//   is the args passed in the original remote call from the client GUI requesting a new character
//   be created so you could pass some data in it to specify which character prototype is appropriate
  proto = GetPrototype( "_E_CharacterPrototype" )
  return true
.

I also noted that there is a server prototype E_CharacterPrototype that is created from the E_playerCharacter class, but I'm also not making the connection between the use of _E_CharacterPrototype above and E_CharacterPrototype.

Using the /sp E_CharacterPrototype command, I have noticed that the name field is set to _E_CharacterPrototype, which is obviously significant.

I think I need to end my evening by acknowledging that I haven't fully grasped the prototype system. I'm sure that once I understand prototypes more completely, this will all come into focus.

-Sage
« Last Edit: Feb 06, 13, 12:06:02 AM by grimcat »
Logged

Thazager

  • General Accounts
  • *
  • Posts: 1160
  • Never stop learning
    • View Profile
Re: How is E_playerCharacter first instantiated
« Reply #2 on: Feb 06, 13, 04:21:13 AM »

Most of the engine is written in scripts using _<name>  and HE_<name>. The E_<name> are overrides set up to show developers how to override scripts with their own code. Some of the more important scripts like E_account and E_controller have overrides glomed onto the main _accoount and _controller.
Logged
Lead scripter for EO, Repop helper.
HSL Video tutorials:
https://community.heroengine.com/forums/index.php/topic,1719.msg36858.html#msg3685

HE-CHRISTOPHER

  • HeroEngine
  • *****
  • Posts: 424
    • View Profile
Re: How is E_playerCharacter first instantiated
« Reply #3 on: Feb 06, 13, 09:03:11 AM »


Basically, as you leave character selection to your character creation area a character node is instantiated from a prototype specified in HSL.  The prototype must be created from a class that ultimately is a child of _PlayerCharacter and may have whatever fields or additional classes added to it as needed by your game.


When you click the "Create" button, a call is sent to the server's $CHARACTERSELECTIONSYSTEM system node (_CharacterSelectionClassMethods server script) to the function Untrusted_CSSRequestCreateCharacter().  It then:

  • performs a variety of checks to decide if you can create a new character
  • creates a listener (of class obsListenerCSSSelectCharacter) to allow for asynchronous processing of those checks (if necessary)
  • the listener calls $CHARACTERSELECTIONSYSTEM._CSSCreateCharacter()
  • _CSSCreateCharacter() determines which prototype to use by calling _CSSUseCharacterPrototype(), which checks the HE_ override method to determine if you had overridden the default
  • _CSSCreateCharacter() then instantiates a new character node from the specified prototype and associates it to the account root node
  • _CSSCreateCharacter() then promotes the character node into a root node.  This process unloads the root node from memory
  • the character is then selected, causing the root node to be loaded
  • after bouncing through some additional asynchronous stuff and events to the listener, _CSSCharacterSelected() is called and the account and new character are sent to the character creation area to continue with character creation (race, outfit, etc)

http://hewiki.heroengine.com/wiki/$CHARACTERSELECTIONSYSTEM
http://hewiki.heroengine.com/wiki/$CHARACTERCREATIONSYSTEM
Logged
Christopher Larsen
CTO
HeroEngine

grimcat

  • World Owner
  • ****
  • Posts: 20
    • View Profile
Re: How is E_playerCharacter first instantiated
« Reply #4 on: Feb 06, 13, 02:23:52 PM »

Thank you Christopher. That gives me a huge leg up.
Logged