Skyline Editor related tips n tricks!

Skyline Concept of an Engine Module?

Skyline Concept of an Engine Module?

Postby Olander » 04 Feb 2017, 00:52

Hi all

<=EDITED AND UPDATED FOR INFORMATION=>
To help assist as a helpful guideline of how the Module (from Bioware) is set up and used. I have left out events that are not really used from the NWN Lexicon (for others familiar with NWN1 Aurora).

Module (object oModule)
Module Variables: For Global Data and Configuration Settings
Module Events:
OnModuleLoad - Lua script that runs when the Engine Loads
OnHeartbeat - Lua Script that runs on a module cycle. Should be on 100ms intervals.
OnClientEnter - Lua script that runs when a Client Connects to the game
OnClientLeave - Lua script that runs when a Client Disconnects from the game

Subset of oModule:
--Area (object oArea) = Levels/Scenes :: References to scenes in oModule kept in an array for engine access
Area Variables: For Local Area Based Variables
Area Events:
OnEnter
OnExit
OnHeartbeat (Only active while a Client is in the Area) 100ms update rate
object oObjects = Non-Static Objects that have scripts running. Kept in a list of the oArea
Variables

Module Functions:
object GetModule();
int GetTimeYear();
int GetTimeMonth();
int GetTimeDay();
int GetTimeHour();
float GetTimeHourDecimal(); <= 12.3456789 hours of current day length
int GetTimeMinute();
int GetTimeSecond();

Area and Object Functions:
object GetEnteringObject(); Gets the object that last opened or entered the calling object.
object GetExitingObject(); Get the object that last left the calling object.
object GetArea(object oTarget); Get the area that the target is located.

General All Use Functions:
General Functions that are fabulously useful but must be designed into how the engine works. These functions work on any entity, Area, and Module. Internally I am not certain how Bioware is doing this. In Unity and UE4 I made 2 dimensional arrays and populated these when the object is initialized/instantiated...etc. My arrays were set to 1000 variables possible to keep speed up and give enough room to store enough variable data for usage. The sVarName must be Unique so that the Array is being searched the sVarName Sets/Gets the proper data.
int GetLocalInt(object oObject, string sVarName);
void SetLocalInt(object oObject, string sVarName, int nValue);
float GetLocalFloat(object oObject, string sVarName);
void SetLocalFloat(object oObject, string sVarName, float fValue);
string GetLocalString(object oObject, string sVarName);
void SetLocalString(object oObject, string sVarName, string sValue);
object GetLocalObject(object oObject, string sVarName);
void SetLocalObject(object oObject, string sVarName, object oValue);
location GetLocalLocation(object oObject, string sVarName);
void SetLocalLocation(object oObject, string sVarName, location lValue); <= location lValue = Vector3 float x, float y, float z



<=INITIAL POST=>
Ticking off items on the list for this engine I could not find something. The Engine Script...or call this...Module

Something that was incredibly important in the Bioware Aurora Engine (NWN) is called Module. This is the Engine Entity (object) that can run scripts and hold information. It cannot be set directly like other objects (meaning cannot be edited/placed in a scene) and is rather special. Its main task is at runtime in handling lots of global information and the transfer of this information to/from scene/level objects.
examples:
- Global Time
- Global Engine Configurations
- Global Data to Transfer between Scenes
- Global Heartbeats
- Global Transforms of Teleportation Waypoints

In any case. Couple of questions.
If this feature is available in Skyline already...it is not apparent in how this is created.
If this feature can be made in Lua and implement with a Do Not Destroy On Load type mechanism....this will work.

This is a very important feature to a game engine to make all scenes/levels be completely in sync with each other and not simply isolated environments.

Thank You. Cheers
Olander
Last edited by Olander on 05 Feb 2017, 19:04, edited 1 time in total.
User avatar
Olander
Skyline Apprentice
 
Posts: 35
Joined: 29 Jan 2017, 17:36
Skill: Level Designer
Skill: 3D Modeller
Skill: Scripter
Skill: Audio
Skill: Great creative

Re: Skyline Concept of an Engine Module?

Postby SolarPortal » 04 Feb 2017, 13:53

Currently there is no script or system that runs outside of scenes or global to all levels.

What we have is a per scene script which we use to maintain Per scene globals etc... This can be used by Right clicking in the scene and choosing.. "Edit Scene Script".

A module or script that would run across all levels keeping persistant data would be quite useful as you say for example the same time of day across all scenes.

For now what you can do is from the scene script is load and save a JSON file that stores this data and is very easy to setup.
Here is an example:
Code: Select all
obj = 0;
function onInit(objID)
   obj = objID;
end

function onKeyDown( key )

   -- | on key one, we will serialize the table to file.
   if(key == "1")then
      lprint("#&127,127,127:Saving table to JSON...")
   
      -- | First Lets create a lua table and fill in some data to test with.
      local tempTable = {};
      tempTable["playername"] = "Joe";
      tempTable["lastName"] = "Bloggs";
      tempTable[0] = { ["a"]="Hello", [3]=200};
      tempTable[1] = "World";
     
      -- | Second: create a json object based on the table, this contains the correct
      -- | metatable for the code to write the JSON data properly.
      jsonObj = rapidjson.object(tempTable)
     
      -- | Third; Lets dump the new object into a json file.
      -- |    > The pretty at the end is to create more readable lines. Setting false will write into one line.
      -- |    > For a specific location on a Hard drive e.g. E:/myFile.json
      -- |    > You can name the extension to whatever you want ... *.tableData, *.player etc...
      rapidjson.dump(jsonObj, "myfile.json", {pretty=true});
     
      lprint("#&127,255,127:Saving table to JSON Complete!");
   end
   
   -- | on key two, we will load the files data into a table and print the data.
   if(key == "2")then
      lprint("#&127,127,127:Loading table to JSON...")
   
      -- | Load the json file into a table.
      myData = rapidjson.load("E:/myfile.json");
     
      -- | Print the data to the in game screen.
      sprint("playername = "..myData["playername"]);
      sprint("lastName = "..myData["lastName"]);
      sprint("0 = "..myData[tostring(0)]["a"]);
      sprint("0 = "..myData[tostring(0)][tostring(3)]);
      sprint("1 = "..myData[tostring(1)]);
     
      lprint("#&127,255,127:Loading table to JSON Complete!");
   end
end


If you add the load to when your scenescripts onInit is called and call the save from where you change level using a public function from the scene script, this will grab the data from the file if it exists before anything else in the engine is run.

For the public function, here is what you would call from any other script that wants to communicate with the scenescript:
Code: Select all
entity.callFn(obj, -9, "saveJSON",""); -- -9 is the scenescript as it has no entity in the scene.


And in the scene script, you would add a function saveJSON() or whatever you want to call it as long as the callfn matches.
Code: Select all
function saveJSON( arg1 )
   lprint("scene script called");   
end


Scene script onInit(), postInit(), onUpdate() are all the first functions to be called before any other entity with actions, script or modules.

If this doesnt get around it, then this is something we can build into Gen2 :)
Conceive, Quantify & Do!
Skyline Game Engine - Lead Developer.
Please provide as much information as possible when asking for help.


Specs: OS: Win 10 64bit, CPU: Intel i7 3770 3.4ghz x 4 core(8 threads), GPU: Nvidia GTX 1060 6GB, Ram: 16gig DDR3, Windows on 250gb Samsung Evo 860
User avatar
SolarPortal
Skyline Founder
Skyline Founder
 
Posts: 3133
Joined: 29 Jul 2012, 15:56
Location: UK
Skill: 3D Modeller
Skill: 2D Artist
Skill: Programmer
Skill: Level Designer

Re: Skyline Concept of an Engine Module?

Postby Olander » 04 Feb 2017, 18:06

Hi SolarPortal,

Thank you for the information. I think this would work perfectly in a single player environment. The only question would be how would this be handled in a Multiplayer environment. We are not talking about MMO in this case but simple 70 clients or so connected to the master host server/client.

Since the module is the keeper of data, so to speak, and any client connection points directly to it for any global information. From your scene script example I am not quite certain how this would work.

It might work if all scenes were initialized while loading the build then synchronized on a heartbeat or something. This would mean that the database does actually exist for the scene. And since the master server/client that is hosting the game would then have all the databases necessary. Since clients can be in several different scenes at once syncing the database become a hideous task...which is why the Module exists in the first place.

Both Unity and UE4 I had to do some crazy stuff with text files to make certain the 'Global Database' was synced on both ends. Really surprised that they both have multiplayer in their systems but no decent method to handle global data of any kind. I solved it but it is a very strange and difficult to troubleshoot data issues when they happen....and they do happen. :lol:

It would be very nice to have an Engine/Module script to run things in with a similar fetch call as your scene script. If you have another idea on how to handle the multiplayer issue then that could work as well.

Thank you, Cheers
Olander
User avatar
Olander
Skyline Apprentice
 
Posts: 35
Joined: 29 Jan 2017, 17:36
Skill: Level Designer
Skill: 3D Modeller
Skill: Scripter
Skill: Audio
Skill: Great creative

Re: Skyline Concept of an Engine Module?

Postby SolarPortal » 04 Feb 2017, 20:24

Aah, i see now :)

Currently, there is no multiplayer code built into skyline, but it is developing on the side and we should have some lua libraries implemented soon to handle this.

A system wide script or module would be very cool when considering what you are talking about and we can work this in when skyline gets the networking capability.
Conceive, Quantify & Do!
Skyline Game Engine - Lead Developer.
Please provide as much information as possible when asking for help.


Specs: OS: Win 10 64bit, CPU: Intel i7 3770 3.4ghz x 4 core(8 threads), GPU: Nvidia GTX 1060 6GB, Ram: 16gig DDR3, Windows on 250gb Samsung Evo 860
User avatar
SolarPortal
Skyline Founder
Skyline Founder
 
Posts: 3133
Joined: 29 Jul 2012, 15:56
Location: UK
Skill: 3D Modeller
Skill: 2D Artist
Skill: Programmer
Skill: Level Designer

Re: Skyline Concept of an Engine Module?

Postby Olander » 04 Feb 2017, 21:12

Excellent. I will set up the project then with the scene database transfer then once the Engine/Module script is implemented I can transfer the functionality over to that.

Thank you for the assistance.
Cheers
O
User avatar
Olander
Skyline Apprentice
 
Posts: 35
Joined: 29 Jan 2017, 17:36
Skill: Level Designer
Skill: 3D Modeller
Skill: Scripter
Skill: Audio
Skill: Great creative

Re: Skyline Concept of an Engine Module?

Postby SolarPortal » 04 Feb 2017, 22:59

No worries. Happy to help :)
Conceive, Quantify & Do!
Skyline Game Engine - Lead Developer.
Please provide as much information as possible when asking for help.


Specs: OS: Win 10 64bit, CPU: Intel i7 3770 3.4ghz x 4 core(8 threads), GPU: Nvidia GTX 1060 6GB, Ram: 16gig DDR3, Windows on 250gb Samsung Evo 860
User avatar
SolarPortal
Skyline Founder
Skyline Founder
 
Posts: 3133
Joined: 29 Jul 2012, 15:56
Location: UK
Skill: 3D Modeller
Skill: 2D Artist
Skill: Programmer
Skill: Level Designer

Re: Skyline Concept of an Engine Module?

Postby Olander » 05 Feb 2017, 19:11

@SolarPortal

I updated the initial posting to help as a guideline for how the Module and Areas are related as well as the most useful functions that are used with them. I also placed some very useful General Functions that are extremely handy for making game design much easier. These are very much an engine based design item since there are so many things that can use these functions from within other functions.

I would be happy to help making a nice library of utility functions in Lua for Skyline to couple with the already nice and growing library posted in the forums here.

Thank you.
Cheers
O
User avatar
Olander
Skyline Apprentice
 
Posts: 35
Joined: 29 Jan 2017, 17:36
Skill: Level Designer
Skill: 3D Modeller
Skill: Scripter
Skill: Audio
Skill: Great creative

Re: Skyline Concept of an Engine Module?

Postby SolarPortal » 05 Feb 2017, 23:52

thanks.. and wow thats quite a hook to add lol :P

It wont be a quick one to implement and it may not be started for a few months as we have some planned tasks which take us up to end of February/march.

I think its going to take some time to digest what your after but we will work towards it and plan it in on the way :)
Conceive, Quantify & Do!
Skyline Game Engine - Lead Developer.
Please provide as much information as possible when asking for help.


Specs: OS: Win 10 64bit, CPU: Intel i7 3770 3.4ghz x 4 core(8 threads), GPU: Nvidia GTX 1060 6GB, Ram: 16gig DDR3, Windows on 250gb Samsung Evo 860
User avatar
SolarPortal
Skyline Founder
Skyline Founder
 
Posts: 3133
Joined: 29 Jul 2012, 15:56
Location: UK
Skill: 3D Modeller
Skill: 2D Artist
Skill: Programmer
Skill: Level Designer

Re: Skyline Concept of an Engine Module?

Postby Olander » 07 Feb 2017, 04:06

:D Hook with some lovely yummy bait! :D

No worries at all. For single player what is there is fine with your helpful solution. For all the Set/GetLocals they can be done with what is there as well with the same array process that I had to do in Unity and UE4. I am still learning quite a lot in Skyline...and this is going to take some time. :D

None of the above is mandatory of course. It would indeed be very cool to have such integrated features at the fingertips. Thank you for even being interested in examining this.

Cheers
O
User avatar
Olander
Skyline Apprentice
 
Posts: 35
Joined: 29 Jan 2017, 17:36
Skill: Level Designer
Skill: 3D Modeller
Skill: Scripter
Skill: Audio
Skill: Great creative


Return to Skyline Editor

Who is online

Users browsing this forum: No registered users and 1 guest