Jump to content

Visual Studio Code for Leadwerks

AggrorJorn

1,489 views

I have been using Visual Studio Code for a couple of years now and it is my defacto text editor next to Notepadd++. I mainly use it however to write Lua scripts. 

 

 

Leadwerks extension

Personally I would love to see it if Visual Studio Code would be the default code editor for Leadwerks (either with 4.x or 5.x). So I got started on working on a custom Leadwerks extension.  You can download it here: https://marketplace.visualstudio.com/items?itemName=aggror.Leadwerks

Todo list:

  • Done: Leadwerks extension has a dependency on the Lua extension. So this Lua extension is automatically installed when you install the Leadwerks extension.
  • Done: Snippets. Every time you create a new script in the Leadwerks editor, you get a couple of default scripts like Function Script:Start(), UpdateWorld(), PostRender(context). Using a very simple snippet, these kind of functions can be inserted with ease.
    • prop[type] : Creates Leadwerk editor properties
    • print: Shortcut for System:Print("")
    • lescripts: Inserts all entity script functions (commented)
    • class: Creates a basic class objects with example functions
    • start: Start function of an entity script
    • updateworld: UpdateWorld function of an entity script
    • updatephysics: UpdatesPhysics function of an entity script
    • collision: Collision function of an entity script with all parameters
    • PostRender: PostRender function of an entity script with the context parameter
    • function: Creates a function for either a custom object or for the specific script
    • if
    • for
    • pair
    • ipar
  • For instance: just type 'col' followed by 1 tab and you get: 
  • function Script:Collision(entity0,entity1,position,normal,speed)
    
    end

     

  • Partially done: Supporting intellisense (sort of) with Leadwerks entities.
    • Lua is a typeless language (not a strong typed language), which makes intellisense not really possible. 
    • VS code is smart enough to recognise some functions that are available in your script, but it is not as complete as when you would work with C# or C++.
    • Done: Generate snippets for the entire Leadwerks API. 
      • Snippets are created per object and a second one without the object. For instance
        • Entity:SetPosition()
        • SetPosition()
      • TODO: Classes with parents, would require matching functions. For instance: a pivot is an entity and thus requires Pivot:SetPosition()
    • Done: parameters into placeholder slots.
    • If I can extend the intellisense so that it recognises Leadwerks entities, perhaps we could see correct variables and functions of those entities.
  • TODO: Loading in the API documentation in a split screen. 
    • The API documentation is written in an XML format which I can retrieve in VS code. I can display it in a splitscreen. 
    • I would have to play with the styling a bit but in general this should work really fast
    • API documentation can be cached if in online mode. Documentation could also be periodically fetched. Moving the API documentation to Github would help improve this process. (newer file versions etc)
  • Debugging
    • Josh stated that he is getting someone to make this for him. So fingers crossed. :)
    • The biggest issue at the moment is the lack of debugging support. Visual studio has debugging options of course, but it can't communicate with the Leadwerks editor.
    • If you have an error in your script while running from the editor, the default Lua editor is opened. :(
  • Like 9


11 Comments


Recommended Comments

Including the second API snippet that starts with “Entity:” is interesting because if you ever want to know what functions are available for that class you can just start typing “ent...”

Share this comment


Link to comment

Seeing all the API in VSCode is pretty awesome. It looks like this is your raw input from the docs:

SetRotation(number pitch, number yaw, number roll,  bool global=false)

And you will want to turn that into this:

SetRotation(&pitch, &yaw, &roll, &global)

 

Share this comment


Link to comment
7 hours ago, Josh said:

Seeing all the API in VSCode is pretty awesome. It looks like this is your raw input from the docs:


SetRotation(number pitch, number yaw, number roll,  bool global=false)

And you will want to turn that into this:


SetRotation(&pitch, &yaw, &roll, &global)

 

Yeah those parameters need some work. What do you think looks better? Your post or the thing below?

SetRotation($number_pitch, $number_yaw, $number_roll, $bool_global=false)
SetRotation($vec3_rotation, $bool_global=false)

On one hand I don't want to lose the type, but on the other hand it looks uglier. Both are just easily made so its just a matter of picking a style.

Share this comment


Link to comment

Maybe something like this would work:
 

	"Entity:SetPosition": {
		"prefix": "SetPosition",
		"body": "SetPosition($x,$y,$z,$global)",
		"description": "Entity Method\nSets the position of an entity in 3-dimensional space, using local or global coordinates.\nParameters\nx (number): X component of the position to set.\ny (number): Y component of the position to set.\nz (number): Z component of the position to set.\nglobal (boolean): uses global space if set to true, otherwise local space is used."
	},

 

Share this comment


Link to comment

The popup window can be restyled I think. I haven't tried it yet, but it is basically css so perhaps it is fairly easy to achieve a larger width.

Adding the parameter information to the description could work. This way I can also add 'cleaner' parameter names. As long as the documentation holds up to its current parameter convention, it can be easily transformed. 

type name: "number x" or "bool ignoreCollision"
type name=value: "bool global=true" or "number velocity = 1.0"

Fyi: at https://www.leadwerks.com/learn?page=API-Reference_Object_Entity_SetPosition the first syntax is missing a comma.

  • SetPosition(number x number y, number z, bool global = false)

Share this comment


Link to comment

Small update published: I have added the parameters as indexes as well. The syntax is converted from

SetRotation(number pitch, number yaw, number roll,  bool global=false)

to

SetRotation(pitch, yaw, roll, global)

The description contains the explanation of the parameters. see image below. It is not waterproof though. Sometimes the syntax parameters are missing in the description, causing the description to be empty or imcomplete. You can identify mistakes/incomplete information in the documentation easier this way.

 The biggest downside at the moment is the way Vs code scales the intellisense window. Right now that is not optimal. However there is word that they are working on that by making the styling more accessible through settings. In the image below I applied custom styling to make the width 2 x its original size.

AddForce command with 2 different versions of paramters.

image.png.fc0af2e1a73ad616c5cc8e4ae83cc962.png

image.png.5b158b75c54b8bbb534054c0ae96d8d5.png

 

  • Like 1

Share this comment


Link to comment

Why does it have ".," at the end of each line? Why does it say (Leadwerks) on the last line? :D

Share this comment


Link to comment

Because the description was written in array form I need to use comma's to specify a new line. The extension somehow included that comma. I can solve this by just cramming everything on 1 line. It is not that people would read that document anyway. Why the ' Leadwerks' is inserted is not clear to me yet. It is not comming from the code and does also not appear in the snippet file. Vs code is adding it for some reason.

Pushed a new build that fixes the comma.

Share this comment


Link to comment

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Add a comment...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Blog Entries

    • By Josh in Josh's Dev Blog 10
      Current generation graphics hardware only supports up to a 32-bit floating point depth buffer, and that isn't adequate for large-scale rendering because there isn't enough precision to make objects appear in the correct order and prevent z-fighting.

      After trying out a few different approaches I found that the best way to support large-scale rendering is to allow the user to create several cameras. The first camera should have a range of 0.1-1000 meters, the second would use the same near / far ratio and start where the first one left off, with a depth range of 1000-10,000 meters. Because the ratio of near to far ranges is what matters, not the actual distance, the numbers can get very big very fast. A third camera could be added with a range out to 100,000 kilometers!
      The trick is to set the new Camera::SetClearMode() command to make it so only the furthest-range camera clears the color buffer. Additional cameras clear the depth buffer and then render on top of the previous draw. You can use the new Camera::SetOrder() command to ensure that they are drawn in the order you want.
      auto camera1 = CreateCamera(world); camera1->SetRange(0.1,1000); camera1->SetClearMode(CLEAR_DEPTH); camera1->SetOrder(1); auto camera2 = CreateCamera(world); camera2->SetRange(1000,10000); camera2->SetClearMode(CLEAR_DEPTH); camera2->SetOrder(2); auto camera3 = CreateCamera(world); camera3->SetRange(10000,100000000); camera3->SetClearMode(CLEAR_COLOR | CLEAR_DEPTH); camera3->SetOrder(3); Using this technique I was able to render the Earth, sun, and moon to-scale. The three objects are actually sized correctly, at the correct distance. You can see that from Earth orbit the sun and moon appear roughly the same size. The sun is much bigger, but also much further away, so this is exactly what we would expect.

      You can also use these features to render several cameras in one pass to show different views. For example, we can create a rear-view mirror easily with a second camera:
      auto mirrorcam = CreateCamera(world); mirrorcam->SetParent(maincamera); mirrorcam->SetRotation(0,180,0); mirrorcam=>SetClearMode(CLEAR_COLOR | CLEAR_DEPTH); //Set the camera viewport to only render to a small rectangle at the top of the screen: mirrorcam->SetViewport(framebuffer->GetSize().x/2-200,10,400,50); This creates a "picture-in-picture" effect like what is shown in the image below:

      Want to render some 3D HUD elements on top of your scene? This can be done with an orthographic camera:
      auto uicam = CreateCamera(world); uicam=>SetClearMode(CLEAR_DEPTH); uicam->SetProjectionMode(PROJECTION_ORTHOGRAPHIC); This will make 3D elements appear on top of your scene without clearing the previous render result. You would probably want to move the UI camera far away from the scene so only your HUD elements appear in the last pass.
    • By tipforeveryone in tipforeveryone's Blog 12
      I spent a whole week for learning UE4 with cpp, yep, UE4 is a great engine for sure, but I found out that my mind could not understand the way UE4 works easily. It is too complex and made me tired. Then I returned to my Leadwerks project and felt so familiar. Soooo... sweet, everything is simple as it is
      It felt like I have had a long trip to UE city then return to my hometown. I miss Leadwerks indeed.
      Last year, I thought I could only use Leadwerks with LUA and never touch its CPP side. But I tried my best, learned Cpp for 8 months. Now I am not a cpp pro but I am confident in using this language. At least I can rewrite my whole project in CPP instead. this 3-years project helped me to understand my potential and interest in gamedev.
      I wish Josh be successful in progress of making Turbo, a new hope for much better Leadwerks.
      To all people who are using Leadwerks and help me these years, love you.
      ...
      Peace!
    • By Josh in Josh's Dev Blog 2
      Still a lot of things left to do. Now that I have very large-scale rendering working, people want to fill it up with very big terrains. A special system will be required to handle this, which adds another layer to the terrain system. Also, I want to resume work on the voxel GI system, as I feel these results are much better than the performance penalty of ray-tracing. There are a few odds and ends like AI navigation and cascaded shadow maps to finish up.
      I am planning to have the engine more or less finished in the spring, and begin work on the new editor. Our workflow isn't going to change much. The new editor is just going to be a more refined version of what we already have, although it is a complete new program written from scratch, this time in C++.
      It's kind of overwhelming but I have confidence in the whole direction and strategy of this new product.
×
×
  • Create New...