Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add scripting #466

Open
wants to merge 46 commits into
base: master
Choose a base branch
from
Open

Add scripting #466

wants to merge 46 commits into from

Conversation

vieiraa
Copy link
Contributor

@vieiraa vieiraa commented Feb 19, 2020

Attempt to fix #22.
I only gonna work on this in my spare time, so this should take a while.

@vieiraa vieiraa force-pushed the scripting branch 2 times, most recently from f52a5bf to a849c3a Compare February 19, 2020 21:44
@vieiraa vieiraa force-pushed the scripting branch 2 times, most recently from 18174db to a45116c Compare February 20, 2020 05:00
Console will read scripts from resources/commands

Also create Console class.
@wheybags
Copy link
Owner

I'm not sure that now is the best time for this, and there are some issues to work out with whatever scripting language we use. The primary use case for it will be scripting in mods, and mods scripts will need to be deterministic just like the rest of the game code, in order for multiplayer to work. This means they will need to use our FixedPoint class for maths. Given that, I'm not sure if we shoudl try to hack FixedPoint into an existing scriping language, or if we should just make our own simplistic langauge. In particular, since FixedPoints can be a bit slow, it would be nice to use a language that distinguished between integer and real number types, so people could only use FixedPoint operations when they actually needed them.

@wheybags
Copy link
Owner

That said, if you want to hack around and experiment with integrating FixedPoint into lua / other languages, please go ahead, but given the issues, I don't think it will be merged until we are looking adding proper mod support, probably after 1.0.

@vieiraa
Copy link
Contributor Author

vieiraa commented Feb 20, 2020

I was planning to use this to implement the quest system. As for the FixedPoint class, it is fairly easy to integrate C++ classes into Lua, and Lua would execute C++ functions when we use the class' methods inside it.

@wheybags
Copy link
Owner

The thing is, we would want lua to use that class for all of its maths. So, if a script tries to add two numbers, it should use FixedPoints internally instead of floats, which is not as simple as just adding a native binding for the class.

@vieiraa
Copy link
Contributor Author

vieiraa commented Feb 21, 2020

Added FixedType registration for use in Lua. Also added unit tests to test it.

@wheybags
Copy link
Owner

http://lua.2524044.n2.nabble.com/Fixed-point-LUA-NUMBER-td7630153.html is a good thread on the topic, and is talking more abotu what I'm getting at. We would need to bundle our own copy of lua (in the extern/ folder), and redefine it's internal number type using the LUA_NUMBER #define. The maths module will break, so we can just remove it for now. Or we could go for the other more moderate approach listed there of redefinign LUA_NUMBER to int32_t and keeping the custom fixedpoint class you've added.

@vieiraa
Copy link
Contributor Author

vieiraa commented Feb 21, 2020

Lua 5.3 added support to 64 bit integers, so I don't think it it necessary anymore.

@wheybags
Copy link
Owner

It culd still be worth trying out defining LUA_NUMBER to FixedPoint, even in 5.3, see https://github.com/lua/lua/blob/v5.3.5/luaconf.h#L457, and https://github.com/lua/lua/blob/v5.3.5/luaconf.h#L127

This might be perfect actually, as the lua interpreter will try to use normal integer operations, but fall back to FixedPoint where necessary. Of course, we would also need to compile lua as c++, so that it could use the operator overloading of the FixedPoint class.

@vieiraa
Copy link
Contributor Author

vieiraa commented Feb 23, 2020

Added FixedPoint to lua. Now all floating point operations and math functions use FixedPoint. Still need to implement some missing math functions that are not present in FixedPoint (log, exp, ...), implement the modulo (%) operator, and fix printing to stdout.

TODO: Fix printing to stdout
@vieiraa vieiraa force-pushed the scripting branch 2 times, most recently from 34189dd to 11e80ea Compare March 6, 2020 22:39
@vieiraa vieiraa marked this pull request as ready for review March 7, 2020 01:48
@vieiraa
Copy link
Contributor Author

vieiraa commented Mar 13, 2020

I'm getting "ERROR INVALID SPRITE CACHE REQUEST 1" when I try to open the console since #429 got merged.

Removed Singleton from LuaScript
git-subtree-dir: extern/LuaBridge
git-subtree-split: 24f1877f967cc138c780ed78a23e03a490a9aec9
Add some docs on how to add C++ classes to Lua.
@vieiraa
Copy link
Contributor Author

vieiraa commented Mar 27, 2020

Wtf? PR just closed on its own.

@vieiraa vieiraa reopened this Mar 27, 2020
@khanduras
Copy link

Got me all excited, it'll be fun to play with this once it's ready for an audience

@wheybags
Copy link
Owner

wheybags commented Apr 1, 2020

Just so you know, I think things are looking decent here, and I haven't forgotten about the PR, but for now it won't be merged. There will come a time in the implementation of the game when we will need a scripting engine, and at that point this will be pulled in. I'm not sure when that will be, maybe when we first start to add mods, or quests or some other point, but it will happen. For now though, there's no need to have it in the main tree before it's in use.
Thanks again for all the work!

@khanduras
Copy link

Is scripting done? Is it working? I'm assuming it's using LUA?

@wheybags
Copy link
Owner

wheybags commented Apr 1, 2020

This is a modified version of lua which is mostly ready to be integrated. Scripting being "donw" would mean that ypu can actually do something with it (like add custom lua scripts into the game), which is not yet done, and won't be for a while, as the priority is getting the base game working properly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Scripting
3 participants