Help with your scripting

Vector 3

Vector 3

Postby SpiderMack » 28 Sep 2017, 22:23

Hi,

Are these maths possible in Skyline ?


Code: Select all
Vector3 v1 = newType.vec3(5,0,5);
Vector3 v2 = newType.vec3(v1) ;
v2.y = v2.y + 5 ;
v1.y = v2.y ;
User avatar
SpiderMack
Skyline Expert
 
Posts: 441
Joined: 02 Dec 2016, 09:15
Skill: Concept artist
Skill: 3D Modeller
Skill: Level Designer
Skill: Scripter

Re: Vector 3

Postby Shando » 28 Sep 2017, 22:54

Hey buddy,

Yes, they are.

newType.vec3 is a standard vector3:

Code: Select all
lastPos = newType.vec3 ( 0, 0, 0 )
currentDirection = newType.vec3 ( 0, 0, 0 )

x, y, z = entity.getPosition ( obj )

lastPos.x = x
lastPos.y = y
lastPos.z = z

-- obj moves here

entityPos = newType.vec3 ( entity.getPosition ( obj ) )

currentDirection.x = entityPos.x - lastPos.x
currentDirection.y = entityPos.y - lastPos.y
currentDirection.z = entityPos.z - lastPos.z


So, once you have the variables, you can carry out any normal Lua maths on them (Lua doesn't care whether they are a vec3 or individual variables).

HTH

Shando
Ryzen 7 4800H 16GB GTX1650 Win 11 64
Love, Hope, Strength http://www.lovehopestrength.co.uk
User avatar
Shando
Skyline Moderator
Skyline Moderator
 
Posts: 560
Joined: 06 Mar 2013, 22:35
Location: Moffat Beach, Queensland
Skill: Programmer
Skill: Scripter
Skill: Level Designer

Re: Vector 3

Postby SpiderMack » 28 Sep 2017, 23:19

Thank you.

Reading Lua Api i wonder why Vector 3 does not get some simplifications ?

For example each maths , you must explicit the x,y,z values, it's long to type :
float vector3::distance ( float vec1_X,
float vec1_Y,
float vec1_Z,
float vec2_X,
float vec2_Y,
float vec2_Z
)



Why not getting some simplification like some other 3D engines Api ?
distance = Vector3.distance(V1,V2)
distance = v1.distance(V2)
dot = v1.dotProduct(v2)
direction = V1 -V2
User avatar
SpiderMack
Skyline Expert
 
Posts: 441
Joined: 02 Dec 2016, 09:15
Skill: Concept artist
Skill: 3D Modeller
Skill: Level Designer
Skill: Scripter

Re: Vector 3

Postby SolarPortal » 29 Sep 2017, 10:36

Right, this is a little bit complicated and is the downside of lua.
Sending each component on its own is faster than sending a table which is what a vec3() actually is.
On c++ side, reading 3 integers or floats is quicker than parsing a table and doing stack operations.

If you are not happy with writing the commands each time, then write your own simplified base classes in lua that wrap the main commands and use less code to write. I started to do this a while back to make it easy to move an entity whether it has physics or not lol :P Check out: "Asset Library\Scripts\Base Classes\System Base Classes\Lua API" for more information.

When you have written your own base class, make sure the file exists in the resource lists for skyline, then just write in the top of your file:
Code: Select all
sky.include("yourfile.lua"); -- change yourfile to name of script. Best to keep the script name unique throughout the system aswell.


You can then create your own class instantiations and code like you showed above.

p.s. In the start of the v0.9.9.0, we simplied calling the lua commands from:

sky.lprint() -> lprint("");
sky.print() -> sprint("", clearDisplayState);
sky.trace() -> trace();
newType.vec2(0,0,0) -> vec2(0,0,0);
newType.vec3(0,0,0) -> vec3(0,0,0);
newType.vec4(0,0,0) -> vec4(0,0,0);

So now they exist on the global root without needing any library.

Also, once you get the hang of the API, you will find that it is not a problem :)
Skyline Game Engine - Lead Dev.
Please provide as much info as possible when asking for help.


Specs: OS: Win 10 64bit, CPU: Intel i7 4770 3.4ghz x 4 core(8 threads), GPU: Nvidia GTX 1060 6GB, Ram: 16gig DDR3, Windows on 250gb Samsung Evo 860

Twitter: @SolarPortal
Instagram: @SolarPortal
User avatar
SolarPortal
Skyline Founder
Skyline Founder
 
Posts: 3631
Joined: 29 Jul 2012, 15:56
Location: UK
Skill: 3D Modeller
Skill: 2D Artist
Skill: Programmer
Skill: Level Designer

Re: Vector 3

Postby SpiderMack » 29 Sep 2017, 11:14

I didn't know about performance , but does it matters a lot ?
Why not letting user use what he wants ? and propose two solutions , one slower and one faster to write ? :)
Code: Select all
Vec2 = Vec 1 + vec3 ;


It's faster to write gameplay with shortcuts.
Game designers or beginners don't care about getting the maximum performance, they will prefer to write fast code.

For real performance, you should propose some C# or C++ available implemenation.
User avatar
SpiderMack
Skyline Expert
 
Posts: 441
Joined: 02 Dec 2016, 09:15
Skill: Concept artist
Skill: 3D Modeller
Skill: Level Designer
Skill: Scripter

Re: Vector 3

Postby SolarPortal » 29 Sep 2017, 11:39

I think this is something we can come back to later after the release.
c# / c++ was planned, but it takes a lot of work to get them working. c# was planned to be added before c++ as that needs an SDK setup to be able to be used in that manner.
Skyline Game Engine - Lead Dev.
Please provide as much info as possible when asking for help.


Specs: OS: Win 10 64bit, CPU: Intel i7 4770 3.4ghz x 4 core(8 threads), GPU: Nvidia GTX 1060 6GB, Ram: 16gig DDR3, Windows on 250gb Samsung Evo 860

Twitter: @SolarPortal
Instagram: @SolarPortal
User avatar
SolarPortal
Skyline Founder
Skyline Founder
 
Posts: 3631
Joined: 29 Jul 2012, 15:56
Location: UK
Skill: 3D Modeller
Skill: 2D Artist
Skill: Programmer
Skill: Level Designer

Re: Vector 3

Postby SpiderMack » 29 Sep 2017, 11:44

SolarPortal wrote:I think this is something we can come back to later after the release.
c# / c++ was planned, but it takes a lot of work to get them working. c# was planned to be added before c++ as that needs an SDK setup to be able to be used in that manner.


If you plan C# , do like Unity and drop scrippting, C# is very easy enought , no need to keep Lua that would be more work.
User avatar
SpiderMack
Skyline Expert
 
Posts: 441
Joined: 02 Dec 2016, 09:15
Skill: Concept artist
Skill: 3D Modeller
Skill: Level Designer
Skill: Scripter

Re: Vector 3

Postby SolarPortal » 29 Sep 2017, 11:47

Skyline is designed for all levels of users, and lua is one of the simplest languages to get used to using. Plus a lot of users from other engines have learnt these scripting languages over full c languages.

We will keep them as its no more work as everything is wrapped engine side :)
Skyline Game Engine - Lead Dev.
Please provide as much info as possible when asking for help.


Specs: OS: Win 10 64bit, CPU: Intel i7 4770 3.4ghz x 4 core(8 threads), GPU: Nvidia GTX 1060 6GB, Ram: 16gig DDR3, Windows on 250gb Samsung Evo 860

Twitter: @SolarPortal
Instagram: @SolarPortal
User avatar
SolarPortal
Skyline Founder
Skyline Founder
 
Posts: 3631
Joined: 29 Jul 2012, 15:56
Location: UK
Skill: 3D Modeller
Skill: 2D Artist
Skill: Programmer
Skill: Level Designer

Re: Vector 3

Postby StarFire » 29 Sep 2017, 11:52

I would disagree about performance, as once you have 100,s of objects in a scene all running their scripts and the frame rates start to drop lower than 30 fps this will become an issue. Use the most optimized solution on the onset rather than being bottle-necked later in development.

Lua will be staying as it is an easy "type friendly" scripting system good for people that dont want to be a coder. Note on C# it is still CLR(Common Language Runtime) and as such still has to be interperated at run time and thus slower than full compiled code, but is a more code based (structure and class) command set which is familiar to coders.
Dream the Journey, Live the Experience!
User avatar
StarFire
Skyline Founder
Skyline Founder
 
Posts: 1678
Joined: 03 Jan 2012, 18:50
Location: UK
Skill: Great creative
Skill: Programmer
Skill: 3D Modeller
Skill: 2D Artist
Skill: Level Designer

Re: Vector 3

Postby Shando » 29 Sep 2017, 13:35

@SpiderMack

For real performance, you should propose some C# or C++ available implemenation.


For the majority of things a dev would need, imho, Lua is more than adequate. Take, for example, Garry's Mod (http://gmod.facepunch.com/) of which over 10 million copies have been sold.

The list of Lua commands is massive and there are hundreds of mods that people have written (in Lua) for it.

I have seen my son play this game with well over 20 other players online at the same time, with no real lag or other issues.

You can see a list of the available Lua commands here:
http://wiki.garrysmod.com/?title=Serverside_Lua

In fact, Garry's Mod was pretty much my first introduction to Lua as my son had his own server and I had to help him fix all the issues that come with trying to get multiple mods playing nicely together ;)

Shando
Ryzen 7 4800H 16GB GTX1650 Win 11 64
Love, Hope, Strength http://www.lovehopestrength.co.uk
User avatar
Shando
Skyline Moderator
Skyline Moderator
 
Posts: 560
Joined: 06 Mar 2013, 22:35
Location: Moffat Beach, Queensland
Skill: Programmer
Skill: Scripter
Skill: Level Designer

Re: Vector 3

Postby SpiderMack » 29 Sep 2017, 15:42

StarFire wrote:I would disagree about performance, as once you have 100,s of objects in a scene all running their scripts and the frame rates start to drop lower than 30 fps this will become an issue. Use the most optimized solution on the onset rather than being bottle-necked later in development.


I agree, still 100 objects running their script is not good game design for common cases.
Objects pooling and objects deactivate/activate, or objets/zones managers is the way to go for some big level.


I guess i'll have to create my own Vector 3 functions and include them in Lua code.

I agree Lua is very easy to use and should suit most people using Skyline :D
User avatar
SpiderMack
Skyline Expert
 
Posts: 441
Joined: 02 Dec 2016, 09:15
Skill: Concept artist
Skill: 3D Modeller
Skill: Level Designer
Skill: Scripter

Re: Vector 3

Postby StarFire » 29 Sep 2017, 16:27

I guess i'll have to create my own Vector 3 functions and include them in Lua code.


That will work, we have our own scripts we include which contain some handy meta table stuff, in a way you can create classes using these tables each containing functions and its good to hide this away from the main script so that the overview of code flow is better to read.
Dream the Journey, Live the Experience!
User avatar
StarFire
Skyline Founder
Skyline Founder
 
Posts: 1678
Joined: 03 Jan 2012, 18:50
Location: UK
Skill: Great creative
Skill: Programmer
Skill: 3D Modeller
Skill: 2D Artist
Skill: Level Designer

Re: Vector 3

Postby SolarPortal » 29 Sep 2017, 16:51

Here are the commands from the vector3.library();
http://www.chi-ad.com/Skyline/API/Lua/html/classvector3.html

Will make it quicker to wrap the commands in your own class then :)
Skyline Game Engine - Lead Dev.
Please provide as much info as possible when asking for help.


Specs: OS: Win 10 64bit, CPU: Intel i7 4770 3.4ghz x 4 core(8 threads), GPU: Nvidia GTX 1060 6GB, Ram: 16gig DDR3, Windows on 250gb Samsung Evo 860

Twitter: @SolarPortal
Instagram: @SolarPortal
User avatar
SolarPortal
Skyline Founder
Skyline Founder
 
Posts: 3631
Joined: 29 Jul 2012, 15:56
Location: UK
Skill: 3D Modeller
Skill: 2D Artist
Skill: Programmer
Skill: Level Designer


Return to Lua Scripting

Who is online

Users browsing this forum: No registered users and 9 guests

cron