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

Author Topic: [Resolved] Loading Specs on Client  (Read 2597 times)

TGSRofar

  • General Accounts
  • *
  • Posts: 153
    • View Profile
[Resolved] Loading Specs on Client
« on: Dec 18, 10, 10:50:54 AM »

I feel like this should be something rather straightforward but I find myself struggling to figure out how to do this.

I have a spec oracle that I need to load the spec data on the client for.  Calling requestSpecByKey should do the trick.  But here comes my first issue.  How do I know on the client what spec keys exist for a spec oracle?  Let's just assume for now that I know I have a key = 1.

Calling requestSpecByKey attempts to find that spec but since it hasn't been loaded yet, it doesn't exist and it creates it (createSpecWithKey).  At this point, the number of elements in the collection is 1 and the spec that was just created is index 1 in the collection, as expected.

The listener is added to the spec and since the spec is still not loaded, it gets set to a state of REQUESTING and requestSpecData is called.

The spec is requested from the repository and onRepositoryDataDownloaded is called.  Spec was downloaded successfully.  But at this point, the collection is now empty.  Why? what happened between the time the spec was created in requestSpecByKey and requestSpecData that removed the created spec from the collection?

So now there is no spec instance and onRepositoryDataDownloaded creates a new instance again.  However, this new instance does not have a listener so there is no notification.

Furthermore, the script goes on to create another instance from the Data downloaded.  It removes the one it just created and adds this new one. Why did it create one, add it to the collection, just to remove that and add the final one?

What am I missing here? What is the correct way to load the specs on the client? 
« Last Edit: Nov 02, 12, 08:58:32 PM by HE-Cooper »
Logged
Ron Farrell
Lead Programmer
Triad Game Studios

TGSRofar

  • General Accounts
  • *
  • Posts: 153
    • View Profile
Re: Loading Specs on Client
« Reply #1 on: Dec 18, 10, 11:48:22 AM »

I did find an issue I had which was contributing to some of the behavior so my post is mostly invalid right now.  I may end up with more or different questions regarding this though.

Okay, please disregard this post.  Problem solved.  I did not have my version of SpecOracleUtils GLOMmed to the system node.

I am still interested in how the client can know the Spec Keys for a spec oracle.
« Last Edit: Dec 18, 10, 01:47:57 PM by rfarrel »
Logged
Ron Farrell
Lead Programmer
Triad Game Studios

HE-CHRISTOPHER

  • HeroEngine
  • *****
  • Posts: 424
    • View Profile
Re: Loading Specs on Client
« Reply #2 on: Dec 19, 10, 10:22:09 AM »

I am still interested in how the client can know the Spec Keys for a spec oracle.

The most common way it knows it needs a particular spec is as a result of the replication of the SpecDerivedObject to the client (which includes the SpecKey).  

So, imagine you have items in your "inventory" that information needs to be communicated to the owning client...so you replicate it all down.  One of those items is a "sword" which has a very small amount of mutable data and its SpecKey.  When the user opens up their inventory UI and hovers over the sword Icon, you might choose to have it display a tooltip with the sword's stats (mutable and immutable data).  To do that:

  • create a UI but leave it hidden and request the spec (asynchronously) with the UI as the listener
  • the UI receives a callback, check to see if user is still expecting this tooltip (i.e. still hovering over it)
  • the UI updates its display elements to display the mutable and immutable data
  • the UI unhides itself displaying the full information to the user
It is strongly recommended that you resist the temptation to preload all of your specs, this is frankly lazy programming and will (in an MMO with thousands or tens of thousands of specifications):

  • consume a significant amount of RAM
  • increase initial load time
  • not handle dynamic updates during development.  If your UI is written to handle the async event, it'll just work if someone changes a spec...updating in real-time.

Logged
Christopher Larsen
CTO
HeroEngine

JoshHalls

  • Founding Professional
  • *****
  • Posts: 335
    • View Profile
    • The Repopulation
Re: Loading Specs on Client
« Reply #3 on: Dec 19, 10, 01:58:05 PM »

Also worth mentioning once a spec is pulled via requestSpecByKey you can then afterwards on the client call getSpecByKey as it will be cached in memory. 
Logged
Co-Owner/Programmer - The Repopulation